@@ -38,30 +38,21 @@ const isActive = computed(() => currentIndex.value >= 0 && currentIndex.value <
3838const isFirstStep = computed (() => currentIndex .value === 0 )
3939const isLastStep = computed (() => currentIndex .value === props .steps .length - 1 )
4040
41- const getStepOptions = (step ? : StepEntity ) => {
41+ function getStepOptions(step ? : StepEntity ): VOnboardingWrapperOptions {
4242 return step ? merge ({}, mergedOptions .value , step .options ) : mergedOptions .value
4343}
4444
4545const POINTER_ATTR = ' data-v-onboarding-pointer-events'
4646
47- const blockInteraction = (element : HTMLElement | null ) => {
48- if (! element ) return
49- if (element .style .pointerEvents === ' none' ) return
47+ function setInteraction(element : HTMLElement | null , value : ' none' | ' auto' ): void {
48+ if (! element ?.style || element .style .pointerEvents === value ) return
5049 const current = element .style .pointerEvents
5150 if (current ) element .setAttribute (POINTER_ATTR , current )
52- element .style .pointerEvents = ' none '
51+ element .style .pointerEvents = value
5352}
5453
55- const allowInteraction = (element : HTMLElement | null ) => {
56- if (! element ) return
57- if (element .style .pointerEvents === ' auto' ) return
58- const current = element .style .pointerEvents
59- if (current ) element .setAttribute (POINTER_ATTR , current )
60- element .style .pointerEvents = ' auto'
61- }
62-
63- const restoreInteraction = (element : HTMLElement | null ) => {
64- if (! element ) return
54+ function restoreInteraction(element : HTMLElement | null ): void {
55+ if (! element ?.style ) return
6556 const stored = element .getAttribute (POINTER_ATTR )
6657 if (stored ) {
6758 element .style .pointerEvents = stored
@@ -71,7 +62,17 @@ const restoreInteraction = (element: HTMLElement | null) => {
7162 }
7263}
7364
74- const runSetup = (step : StepEntity , index : number , direction : Direction ) => {
65+ function createHookOptions(step : StepEntity , index : number , direction : Direction ) {
66+ return {
67+ index ,
68+ step ,
69+ direction ,
70+ isForward: direction === Direction .FORWARD ,
71+ isBackward: direction === Direction .BACKWARD ,
72+ }
73+ }
74+
75+ function runSetup(step : StepEntity , index : number , direction : Direction ) {
7576 const element = useGetElement (step .attachTo .element ) as HTMLElement
7677 const options = getStepOptions (step )
7778
@@ -80,18 +81,14 @@ const runSetup = (step: StepEntity, index: number, direction: Direction) => {
8081 }
8182
8283 if (options ?.overlay ?.preventOverlayInteraction ) {
83- blockInteraction (document .body )
84- allowInteraction (element )
84+ setInteraction (document .body , ' none ' )
85+ setInteraction (element , ' auto ' )
8586 }
8687
87- return step .on ?.beforeStep ?.({
88- index , step , direction ,
89- isForward: direction === Direction .FORWARD ,
90- isBackward: direction === Direction .BACKWARD ,
91- } as onBeforeStepOptions )
88+ return step .on ?.beforeStep ?.(createHookOptions (step , index , direction ) as onBeforeStepOptions )
9289}
9390
94- const runCleanup = (step : StepEntity , index : number , direction : Direction ) => {
91+ function runCleanup(step : StepEntity , index : number , direction : Direction ) {
9592 const element = useGetElement (step .attachTo .element ) as HTMLElement
9693 const options = getStepOptions (step )
9794
@@ -103,14 +100,10 @@ const runCleanup = (step: StepEntity, index: number, direction: Direction) => {
103100 restoreInteraction (element )
104101 }
105102
106- return step .on ?.afterStep ?.({
107- index , step , direction ,
108- isForward: direction === Direction .FORWARD ,
109- isBackward: direction === Direction .BACKWARD ,
110- } as onAfterStepOptions )
103+ return step .on ?.afterStep ?.(createHookOptions (step , index , direction ) as onAfterStepOptions )
111104}
112105
113- const goToStep = (target : number | ((current : number ) => number )) => {
106+ function goToStep(target : number | ((current : number ) => number )): void {
114107 const newIndex = typeof target === ' function' ? target (currentIndex .value ) : target
115108 const oldIndex = currentIndex .value
116109
@@ -133,9 +126,11 @@ const goToStep = (target: number | ((current: number) => number)) => {
133126 })()
134127}
135128
136- const start = () => goToStep (0 )
129+ function start(): void {
130+ goToStep (0 )
131+ }
137132
138- const finish = () => {
133+ function finish() : void {
139134 const step = props .steps [currentIndex .value ]
140135 const index = currentIndex .value
141136
@@ -146,11 +141,15 @@ const finish = () => {
146141 if (step ) runCleanup (step , index , Direction .FORWARD )
147142}
148143
149- const exit = () => emit (' exit' , currentIndex .value )
144+ function exit(): void {
145+ emit (' exit' , currentIndex .value )
146+ }
150147
151- const previous = () => goToStep (i => i - 1 )
148+ function previous(): void {
149+ goToStep (i => i - 1 )
150+ }
152151
153- const next = () => {
152+ function next() : void {
154153 if (isLastStep .value ) {
155154 finish ()
156155 } else {
0 commit comments