|
1 | 1 | <script lang="ts">
|
2 | 2 | import { driver, type Driver, type DriveStep } from 'driver.js'
|
3 | 3 | import 'driver.js/dist/driver.css'
|
4 |
| - import { createEventDispatcher } from 'svelte' |
| 4 | + import { createEventDispatcher, mount } from 'svelte' |
5 | 5 | import { updateProgress } from '$lib/tutorialUtils'
|
6 | 6 | import { ignoredTutorials } from './ignoredTutorials'
|
7 | 7 | import SkipTutorials from './SkipTutorials.svelte'
|
|
33 | 33 | if (state.activeIndex == 0) {
|
34 | 34 | const div = document.createElement('div')
|
35 | 35 |
|
36 |
| - const skipTutorials = new SkipTutorials({ |
37 |
| - target: div |
38 |
| - }) |
39 |
| -
|
40 |
| - skipTutorials.$on('skipAll', () => { |
41 |
| - dispatch('skipAll') |
42 |
| - tutorial?.destroy() |
43 |
| - }) |
44 |
| -
|
45 |
| - skipTutorials.$on('skipThis', () => { |
46 |
| - updateProgress(index) |
47 |
| - tutorial?.destroy() |
| 36 | + mount(SkipTutorials, { |
| 37 | + target: div, |
| 38 | + events: { |
| 39 | + skipAll: () => { |
| 40 | + dispatch('skipAll') |
| 41 | + tutorial?.destroy() |
| 42 | + }, |
| 43 | + skipThis: () => { |
| 44 | + updateProgress(index) |
| 45 | + tutorial?.destroy() |
| 46 | + } |
| 47 | + } |
48 | 48 | })
|
49 | 49 |
|
50 | 50 | if (popoverDescription) {
|
|
54 | 54 |
|
55 | 55 | const controls = document.createElement('div')
|
56 | 56 |
|
57 |
| - const tutorialControls = new TutorialControls({ |
| 57 | + mount(TutorialControls, { |
58 | 58 | target: controls,
|
59 | 59 | props: {
|
60 | 60 | activeIndex: state.activeIndex,
|
61 | 61 | totalSteps
|
62 |
| - } |
63 |
| - }) |
64 |
| -
|
65 |
| - tutorialControls.$on('next', () => { |
66 |
| - const step = tutorial?.getActiveStep() |
67 |
| -
|
68 |
| - if (step) { |
69 |
| - if (tutorial?.getActiveStep()?.popover?.onNextClick) { |
70 |
| - const activeElement = tutorial?.getActiveElement() |
71 |
| - tutorial?.getActiveStep()?.popover?.onNextClick?.(activeElement, step, { |
72 |
| - config, |
73 |
| - state, |
74 |
| - driver: tutorial |
75 |
| - }) |
76 |
| - } else { |
77 |
| - tutorial?.moveNext() |
78 |
| - } |
79 |
| - } |
80 |
| - }) |
81 |
| -
|
82 |
| - tutorialControls.$on('previous', () => { |
83 |
| - const step = tutorial?.getActiveStep() |
84 |
| -
|
85 |
| - if (step) { |
86 |
| - if (tutorial?.getActiveStep()?.popover?.onPrevClick) { |
87 |
| - const activeElement = tutorial?.getActiveElement() |
88 |
| - tutorial?.getActiveStep()?.popover?.onPrevClick?.(activeElement, step, { |
89 |
| - config, |
90 |
| - state, |
91 |
| - driver: tutorial |
92 |
| - }) |
93 |
| - } else { |
94 |
| - tutorial?.movePrevious() |
| 62 | + }, |
| 63 | + events: { |
| 64 | + next: () => { |
| 65 | + const step = tutorial?.getActiveStep() |
| 66 | +
|
| 67 | + if (step) { |
| 68 | + if (tutorial?.getActiveStep()?.popover?.onNextClick) { |
| 69 | + const activeElement = tutorial?.getActiveElement() |
| 70 | + tutorial?.getActiveStep()?.popover?.onNextClick?.(activeElement, step, { |
| 71 | + config, |
| 72 | + state, |
| 73 | + driver: tutorial |
| 74 | + }) |
| 75 | + } else { |
| 76 | + tutorial?.moveNext() |
| 77 | + } |
| 78 | + } |
| 79 | + }, |
| 80 | + previous: () => { |
| 81 | + const step = tutorial?.getActiveStep() |
| 82 | +
|
| 83 | + if (step) { |
| 84 | + if (tutorial?.getActiveStep()?.popover?.onPrevClick) { |
| 85 | + const activeElement = tutorial?.getActiveElement() |
| 86 | + tutorial?.getActiveStep()?.popover?.onPrevClick?.(activeElement, step, { |
| 87 | + config, |
| 88 | + state, |
| 89 | + driver: tutorial |
| 90 | + }) |
| 91 | + } else { |
| 92 | + tutorial?.movePrevious() |
| 93 | + } |
| 94 | + } |
95 | 95 | }
|
96 | 96 | }
|
97 | 97 | })
|
|
0 commit comments