@ulu/frontend-vue 0.6.33 → 0.6.35

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.
@@ -2,7 +2,7 @@ import { markRaw } from "vue";
2
2
 
3
3
  /**
4
4
  * @typedef {Object} TourStep
5
- * @property {String} [target] - The CSS selector for the target element. If omitted, step renders as a modal.
5
+ * @property {String|Function|HTMLElement} [target] - The CSS selector, DOM element, or function returning either, for the target element. If omitted or resolves to falsy, step renders as a modal.
6
6
  * @property {String} [title] - The title text for the step.
7
7
  * @property {String|Array|Object} [titleClass] - Class to apply to the title.
8
8
  * @property {String|Array|Object} [pagerClass] - Class to apply to the pager footer.
@@ -13,6 +13,7 @@ import { markRaw } from "vue";
13
13
  * @property {Boolean} [hideFooter] - If true, hides the default tour footer (Next/Back buttons).
14
14
  * @property {String} [placement] - Floating UI placement string (e.g. 'bottom', 'right').
15
15
  * @property {Boolean} [highlight] - If true, darkens the backdrop around the target element.
16
+ * @property {Boolean|Function} [skip] - If true or returns true, this step will be skipped when navigating the tour.
16
17
  * @property {Object} [modalProps] - Props to pass to the modal (if target is omitted).
17
18
  * @property {Object} [popoverProps] - Props to pass to the popover (if target is present).
18
19
  * @property {Function} [onEnter] - Async hook called before the step is rendered.
@@ -35,59 +36,116 @@ export const createApi = (state) => ({
35
36
  * @param {String|Array|Object} [tour.modalTitleClass] - Global class applied to the title of modal steps.
36
37
  * @param {String|Array|Object} [tour.popoverTitleClass] - Global class applied to the title of popover steps.
37
38
  * @param {String|Array|Object} [tour.pagerClass] - Global class applied to the pager.
39
+ * @param {Function} [tour.onStart] - Async hook called before the tour starts.
38
40
  * @param {Function} [tour.onStop] - Async hook called when the tour is closed/finished.
39
41
  */
40
42
  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;
43
+ if (state.isTransitioning) return;
44
+ state.isTransitioning = true;
45
+ try {
46
+ if (!tour?.steps?.length) return;
47
+ if (typeof tour.onStart === 'function') {
48
+ await tour.onStart();
49
+ }
50
+
51
+ let startIndex = 0;
52
+ while (startIndex < tour.steps.length) {
53
+ const step = tour.steps[startIndex];
54
+ const shouldSkip = typeof step.skip === 'function' ? await step.skip() : step.skip;
55
+ if (!shouldSkip) break;
56
+ startIndex++;
57
+ }
58
+
59
+ if (startIndex >= tour.steps.length) {
60
+ if (typeof tour.onStop === 'function') await tour.onStop();
61
+ return;
62
+ }
63
+
64
+ await this._runHooks(tour.steps[startIndex]);
65
+ state.active = markRaw(tour);
66
+ state.stepIndex = startIndex;
67
+ } finally {
68
+ state.isTransitioning = false;
69
+ }
45
70
  },
46
71
  /**
47
72
  * Advances the tour to the next step, or stops if it is the last step
48
73
  */
49
74
  async next() {
75
+ if (state.isTransitioning) return;
50
76
  const active = state.active;
51
77
  if (!active) return;
52
78
 
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();
79
+ state.isTransitioning = true;
80
+ try {
81
+ let nextIndex = state.stepIndex + 1;
82
+ while (nextIndex < active.steps.length) {
83
+ const step = active.steps[nextIndex];
84
+ const shouldSkip = typeof step.skip === 'function' ? await step.skip() : step.skip;
85
+ if (!shouldSkip) break;
86
+ nextIndex++;
87
+ }
88
+
89
+ if (nextIndex < active.steps.length) {
90
+ await this._runLeaveHook(active.steps[state.stepIndex]);
91
+ await this._runHooks(active.steps[nextIndex]);
92
+ state.stepIndex = nextIndex;
93
+ } else {
94
+ await this.stop(true);
95
+ }
96
+ } finally {
97
+ state.isTransitioning = false;
60
98
  }
61
99
  },
62
100
  /**
63
101
  * Returns the tour to the previous step
64
102
  */
65
103
  async prev() {
104
+ if (state.isTransitioning) return;
66
105
  const active = state.active;
67
106
  if (!active) return;
68
107
 
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;
108
+ state.isTransitioning = true;
109
+ try {
110
+ let prevIndex = state.stepIndex - 1;
111
+ while (prevIndex >= 0) {
112
+ const step = active.steps[prevIndex];
113
+ const shouldSkip = typeof step.skip === 'function' ? await step.skip() : step.skip;
114
+ if (!shouldSkip) break;
115
+ prevIndex--;
116
+ }
117
+
118
+ if (prevIndex >= 0) {
119
+ await this._runLeaveHook(active.steps[state.stepIndex]);
120
+ await this._runHooks(active.steps[prevIndex]);
121
+ state.stepIndex = prevIndex;
122
+ }
123
+ } finally {
124
+ state.isTransitioning = false;
74
125
  }
75
126
  },
76
127
  /**
77
128
  * Stops and closes the current tour
129
+ * @param {Boolean} [internalBypass=false] - Used internally to bypass transition check
78
130
  */
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();
131
+ async stop(internalBypass = false) {
132
+ if (!internalBypass && state.isTransitioning) return;
133
+ state.isTransitioning = true;
134
+ try {
135
+ const active = state.active;
136
+ if (active) {
137
+ if (active.steps[state.stepIndex]) {
138
+ await this._runLeaveHook(active.steps[state.stepIndex]);
139
+ }
140
+ if (typeof active.onStop === 'function') {
141
+ await active.onStop();
142
+ }
87
143
  }
144
+ state.active = null;
145
+ state.stepIndex = 0;
146
+ } finally {
147
+ state.isTransitioning = false;
88
148
  }
89
- state.active = null;
90
- state.stepIndex = 0;
91
149
  },
92
150
  /**
93
151
  * 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.35",
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": [