(isOpen, onClose, customSteps = null)
| 73 | }; |
| 74 | |
| 75 | export const useTutorial = (isOpen, onClose, customSteps = null) => { |
| 76 | const [currentStep, setCurrentStep] = useState(0); |
| 77 | const [previousStep, setPreviousStep] = useState(0); |
| 78 | const [highlightRect, setHighlightRect] = useState(null); |
| 79 | const [tooltipPosition, setTooltipPosition] = useState({ |
| 80 | x: 0, |
| 81 | y: 0, |
| 82 | width: TUTORIAL_CONFIG.TOOLTIP_WIDTH, |
| 83 | arrowDirection: "none", |
| 84 | }); |
| 85 | const [animationState, setAnimationState] = useState({ |
| 86 | isTransitioning: false, |
| 87 | contentVisible: true, |
| 88 | transitionProgress: 1, |
| 89 | }); |
| 90 | const [isInitialized, setIsInitialized] = useState(false); |
| 91 | |
| 92 | const timeoutRef = useRef(null); |
| 93 | const animationFrameRef = useRef(null); |
| 94 | const isMountedRef = useRef(true); |
| 95 | const debounceRef = useRef(null); |
| 96 | const updatePositionsRef = useRef(null); |
| 97 | const lastAnimatedStepRef = useRef(0); |
| 98 | |
| 99 | const steps = useMemo(() => { |
| 100 | return customSteps || DEFAULT_TUTORIAL_STEPS; |
| 101 | }, [customSteps]); |
| 102 | |
| 103 | const currentStepData = useMemo(() => { |
| 104 | return steps[currentStep] || steps[0]; |
| 105 | }, [steps, currentStep]); |
| 106 | |
| 107 | const _viewport = useMemo(() => { |
| 108 | if (typeof window === "undefined") { |
| 109 | return { width: 1024, height: 768, isMobile: false }; |
| 110 | } |
| 111 | const width = window.innerWidth; |
| 112 | const height = window.innerHeight; |
| 113 | return { |
| 114 | width, |
| 115 | height, |
| 116 | isMobile: width <= TUTORIAL_CONFIG.MOBILE_BREAKPOINT, |
| 117 | }; |
| 118 | }, []); |
| 119 | |
| 120 | const clearAllTimers = useCallback(() => { |
| 121 | if (timeoutRef.current) { |
| 122 | clearTimeout(timeoutRef.current); |
| 123 | timeoutRef.current = null; |
| 124 | } |
| 125 | if (animationFrameRef.current) { |
| 126 | cancelAnimationFrame(animationFrameRef.current); |
| 127 | animationFrameRef.current = null; |
| 128 | } |
| 129 | if (debounceRef.current) { |
| 130 | clearTimeout(debounceRef.current); |
| 131 | debounceRef.current = null; |
| 132 | } |
no test coverage detected