34
34
<button @click =" tour.previousStep" v-if =" !isMobile" >
35
35
{{ $t("Previous step") }}
36
36
</button >
37
- <button class =" right" @click =" alert "
37
+ <button class =" right" @click =" tour.steps[tour.currentStep].button.fn() "
38
38
v-if =" tour.steps[tour.currentStep].button" >
39
39
{{ $t(tour.steps[tour.currentStep].button.text) }}
40
40
</button >
48
48
</template >
49
49
</v-tour >
50
50
<transition name =" fade" >
51
- <div class =" tour-control-bar" >
51
+ <div class =" tour-control-bar" v-if = " isMobile " >
52
52
<button @click =" endTour()" >
53
53
{{ $t("End Tour") }}
54
54
</button >
@@ -117,17 +117,23 @@ export default defineComponent({
117
117
() => $network .consensus !== ' established' ,
118
118
);
119
119
120
- const { state : tourStore, removeTour } = useAccountStore ();
120
+ const { state : tourStore, setTour } = useAccountStore ();
121
121
122
122
let tour: VueTour .Tour | null = null ;
123
123
const steps: TourSteps <any > = useTour (tourStore .tour , context ) || {};
124
124
125
125
// Initial state
126
126
const loading = ref (true );
127
- const currentStep: Ref <TourStepIndex > = ref (8 );
127
+ const currentStep: Ref <TourStepIndex > = ref (0 );
128
128
const nSteps: Ref <number > = ref (0 );
129
129
const disableNextStep = ref (true );
130
130
131
+ let unmounted: (
132
+ (args ? : { goingForward: boolean , ending? : boolean }) => Promise <null >)
133
+ | Promise <null >
134
+ | ((args ? : { goingForward: boolean , ending? : boolean }) => null )
135
+ | null = null ;
136
+
131
137
onMounted (() => {
132
138
tourSetup ();
133
139
@@ -137,14 +143,22 @@ export default defineComponent({
137
143
});
138
144
139
145
async function tourSetup() {
146
+ await context .root .$nextTick (); // to ensure the DOM is ready
147
+
140
148
// Update state
141
149
nSteps .value = Object .keys (steps ).length ;
142
150
disableNextStep .value = currentStep .value >= nSteps .value - 1
143
- || !! steps [currentStep .value ].ui .disabledNextStep ;
151
+ || !! steps [currentStep .value ].ui .isNextStepDisabled ;
152
+
153
+ if (steps [currentStep .value ].lifecycle ?.created ) {
154
+ await steps [currentStep .value ].lifecycle ! .created !({ goToNextStep , goingForward: true });
155
+ }
144
156
145
157
_addAttributes (steps [currentStep .value ].ui , currentStep .value );
146
- // eslint-disable-next-line no-unused-expressions
147
- steps [currentStep .value ].lifecycle ?.onMountedStep ?.(goToNextStep );
158
+
159
+ if (steps [currentStep .value ].lifecycle ?.mounted ) {
160
+ unmounted = await steps [currentStep .value ].lifecycle ! .mounted !({ goToNextStep , goingForward: true });
161
+ }
148
162
149
163
if (context .root .$route .path !== steps [currentStep .value ].path ) {
150
164
context .root .$router .push (steps [currentStep .value ].path );
@@ -163,11 +177,9 @@ export default defineComponent({
163
177
const app = document .querySelector (' #app main' ) as HTMLDivElement ;
164
178
165
179
if (loading .value || disconnected .value ) {
166
- // eslint-disable-next-line no-unused-expressions
167
- app ?.setAttribute (' data-non-interactable' , ' ' );
180
+ app ! .setAttribute (' data-non-interactable' , ' ' );
168
181
} else {
169
- // eslint-disable-next-line no-unused-expressions
170
- app ?.removeAttribute (' data-non-interactable' );
182
+ app ! .removeAttribute (' data-non-interactable' );
171
183
}
172
184
});
173
185
@@ -189,19 +201,21 @@ export default defineComponent({
189
201
) {
190
202
const goingForward = futureStepIndex > currentStepIndex ;
191
203
192
- const { path : currentPage, lifecycle : currentLifecycle } = steps [currentStepIndex ];
204
+ const { path : currentPage } = steps [currentStepIndex ];
193
205
const { path : futurePage, ui : futureUI, lifecycle : futureLifecycle } = steps [futureStepIndex ];
194
206
195
207
loading .value = true ;
196
208
tour ! .stop ();
197
- await sleep (500 );
198
209
199
- // changePage
200
- if (! goingForward && currentLifecycle && currentLifecycle .prepareDOMPrevPage ) {
201
- await currentLifecycle .prepareDOMPrevPage ();
202
- } else if (goingForward && currentLifecycle && currentLifecycle .prepareDOMNextPage ) {
203
- await currentLifecycle .prepareDOMNextPage ();
204
- } else if (futurePage !== currentPage ) {
210
+ if (unmounted ) {
211
+ await (await unmounted )! ({ goingForward });
212
+ }
213
+
214
+ if (futureLifecycle ?.created ) {
215
+ await (futureLifecycle .created ! )({ goToNextStep , goingForward });
216
+ }
217
+
218
+ if (futurePage !== currentPage && context .root .$route .fullPath !== futurePage ) {
205
219
try {
206
220
// Default prepare DOM
207
221
context .root .$router .push (futurePage );
@@ -224,30 +238,32 @@ export default defineComponent({
224
238
// FIXME Instead of doing tour!.end and tour!.start, we could also use .nextStep() or previsousStep()
225
239
// The problem with this solution is that some animations glitch the UI so it needs further
226
240
// investigation
227
- // eslint-disable-next-line no-unused-expressions
228
241
// goingForward ? tour!.nextStep() : tour!.previousStep();
229
242
230
243
// onMountedStep
231
244
loading .value = false ;
232
- disableNextStep .value = futureStepIndex >= nSteps .value - 1 || !! futureUI .disabledNextStep ;
245
+ disableNextStep .value = futureStepIndex >= nSteps .value - 1 || !! futureUI .isNextStepDisabled ;
233
246
234
- // eslint-disable-next-line no-unused-expressions
235
- futureLifecycle ?.onMountedStep ?.(goToNextStep );
247
+ if (futureLifecycle ?.mounted ) {
248
+ unmounted = await futureLifecycle ! .mounted !({ goToNextStep , goingForward });
249
+ } else {
250
+ unmounted = null ;
251
+ }
236
252
237
253
currentStep .value = futureStepIndex ;
238
254
}
239
255
240
256
function _addAttributes(uiConfig : TourStep [' ui' ], stepIndex : TourStepIndex ) {
241
- const elementsWithOpacity = uiConfig .elementsWithOpacity || [];
242
- const elementsWithoutInteractivity = uiConfig .elementsWithoutInteractivity || [];
257
+ const fadedElements = uiConfig .fadedElements || [];
258
+ const disabledElements = uiConfig .disabledElements || [];
243
259
244
- elementsWithoutInteractivity .forEach ((element ) => {
260
+ disabledElements .forEach ((element ) => {
245
261
const el = document .querySelector (element );
246
262
if (! el ) return ;
247
263
el .setAttribute (' data-non-interactable' , stepIndex .toString ());
248
264
});
249
265
250
- elementsWithOpacity .forEach ((element ) => {
266
+ fadedElements .forEach ((element ) => {
251
267
const el = document .querySelector (element );
252
268
if (! el ) return ;
253
269
el .setAttribute (' data-opacified' , stepIndex .toString ());
@@ -265,14 +281,18 @@ export default defineComponent({
265
281
});
266
282
}
267
283
268
- function endTour() {
284
+ async function endTour() {
269
285
_removeAttributes (currentStep .value );
270
286
271
- // If user finalizes tour while it is loading, allow then interaction
287
+ if (unmounted ) {
288
+ await (await unmounted )! ({ ending: true , goingForward: false });
289
+ }
290
+
291
+ // If user finalizes tour while it is loading, allow interaction again
272
292
const app = document .querySelector (' #app main' ) as HTMLDivElement ;
273
293
app .removeAttribute (' data-non-interactable' );
274
294
275
- removeTour ( );
295
+ setTour ( null );
276
296
}
277
297
278
298
// TODO REMOVE ME - Simulate tx
0 commit comments