@ulu/frontend-vue 0.6.33 → 0.6.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -35,59 +35,88 @@ export const createApi = (state) => ({
35
35
  * @param {String|Array|Object} [tour.modalTitleClass] - Global class applied to the title of modal steps.
36
36
  * @param {String|Array|Object} [tour.popoverTitleClass] - Global class applied to the title of popover steps.
37
37
  * @param {String|Array|Object} [tour.pagerClass] - Global class applied to the pager.
38
+ * @param {Function} [tour.onStart] - Async hook called before the tour starts.
38
39
  * @param {Function} [tour.onStop] - Async hook called when the tour is closed/finished.
39
40
  */
40
41
  async start(tour) {
41
- if (!tour?.steps?.length) return;
42
- await this._runHooks(tour.steps[0]);
43
- state.active = markRaw(tour);
44
- state.stepIndex = 0;
42
+ if (state.isTransitioning) return;
43
+ state.isTransitioning = true;
44
+ try {
45
+ if (!tour?.steps?.length) return;
46
+ if (typeof tour.onStart === 'function') {
47
+ await tour.onStart();
48
+ }
49
+ await this._runHooks(tour.steps[0]);
50
+ state.active = markRaw(tour);
51
+ state.stepIndex = 0;
52
+ } finally {
53
+ state.isTransitioning = false;
54
+ }
45
55
  },
46
56
  /**
47
57
  * Advances the tour to the next step, or stops if it is the last step
48
58
  */
49
59
  async next() {
60
+ if (state.isTransitioning) return;
50
61
  const active = state.active;
51
62
  if (!active) return;
52
63
 
53
- if (state.stepIndex < active.steps.length - 1) {
54
- await this._runLeaveHook(active.steps[state.stepIndex]);
55
- const nextIndex = state.stepIndex + 1;
56
- await this._runHooks(active.steps[nextIndex]);
57
- state.stepIndex = nextIndex;
58
- } else {
59
- await this.stop();
64
+ state.isTransitioning = true;
65
+ try {
66
+ if (state.stepIndex < active.steps.length - 1) {
67
+ await this._runLeaveHook(active.steps[state.stepIndex]);
68
+ const nextIndex = state.stepIndex + 1;
69
+ await this._runHooks(active.steps[nextIndex]);
70
+ state.stepIndex = nextIndex;
71
+ } else {
72
+ await this.stop(true);
73
+ }
74
+ } finally {
75
+ state.isTransitioning = false;
60
76
  }
61
77
  },
62
78
  /**
63
79
  * Returns the tour to the previous step
64
80
  */
65
81
  async prev() {
82
+ if (state.isTransitioning) return;
66
83
  const active = state.active;
67
84
  if (!active) return;
68
85
 
69
- if (state.stepIndex > 0) {
70
- await this._runLeaveHook(active.steps[state.stepIndex]);
71
- const prevIndex = state.stepIndex - 1;
72
- await this._runHooks(active.steps[prevIndex]);
73
- state.stepIndex = prevIndex;
86
+ state.isTransitioning = true;
87
+ try {
88
+ if (state.stepIndex > 0) {
89
+ await this._runLeaveHook(active.steps[state.stepIndex]);
90
+ const prevIndex = state.stepIndex - 1;
91
+ await this._runHooks(active.steps[prevIndex]);
92
+ state.stepIndex = prevIndex;
93
+ }
94
+ } finally {
95
+ state.isTransitioning = false;
74
96
  }
75
97
  },
76
98
  /**
77
99
  * Stops and closes the current tour
100
+ * @param {Boolean} [internalBypass=false] - Used internally to bypass transition check
78
101
  */
79
- async stop() {
80
- const active = state.active;
81
- if (active) {
82
- if (active.steps[state.stepIndex]) {
83
- await this._runLeaveHook(active.steps[state.stepIndex]);
84
- }
85
- if (typeof active.onStop === 'function') {
86
- await active.onStop();
102
+ async stop(internalBypass = false) {
103
+ if (!internalBypass && state.isTransitioning) return;
104
+ state.isTransitioning = true;
105
+ try {
106
+ const active = state.active;
107
+ if (active) {
108
+ if (active.steps[state.stepIndex]) {
109
+ await this._runLeaveHook(active.steps[state.stepIndex]);
110
+ }
111
+ if (typeof active.onStop === 'function') {
112
+ await active.onStop();
113
+ }
87
114
  }
115
+ state.active = null;
116
+ state.stepIndex = 0;
117
+ } finally {
118
+ state.isTransitioning = false;
88
119
  }
89
- state.active = null;
90
- state.stepIndex = 0;
91
120
  },
92
121
  /**
93
122
  * Internal method to run asynchronous enter hooks on a step
@@ -9,7 +9,8 @@ import { useTour } from './useTour.js';
9
9
  export default function install(app) {
10
10
  const state = reactive({
11
11
  active: null,
12
- stepIndex: 0
12
+ stepIndex: 0,
13
+ isTransitioning: false
13
14
  });
14
15
 
15
16
  const api = createApi(state);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ulu/frontend-vue",
3
- "version": "0.6.33",
3
+ "version": "0.6.34",
4
4
  "description": "A modular, tree-shakeable Vue 3 component library for the Ulu Frontend theming system, plus general utilities for Vue development",
5
5
  "type": "module",
6
6
  "files": [