@destyler/tour 0.2.11 → 0.2.13
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.
- package/dist/index.d.mts +9 -12
- package/dist/index.mjs +161 -170
- package/package.json +10 -10
package/dist/index.d.mts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import * as _destyler_anatomy0 from "@destyler/anatomy";
|
|
2
1
|
import { AnchorRect, Placement } from "@destyler/popper";
|
|
3
|
-
import * as _destyler_xstate0 from "@destyler/xstate";
|
|
4
2
|
import { AnyEventObject, Machine, XSend, XState } from "@destyler/xstate";
|
|
5
3
|
import { FocusOutsideEvent, InteractOutsideEvent, InteractOutsideHandlers, PointerDownOutsideEvent } from "@destyler/dismissable";
|
|
6
4
|
import { CommonProperties, DirectionProperty, NormalizeProps, PropTypes, Required, RequiredBy } from "@destyler/types";
|
|
7
|
-
|
|
8
5
|
//#region src/anatomy.d.ts
|
|
9
|
-
declare const anatomy:
|
|
6
|
+
export declare const anatomy: import("@destyler/anatomy").AnatomyInstance<"content" | "actionTrigger" | "closeTrigger" | "progressText" | "title" | "description" | "positioner" | "arrow" | "arrowTip" | "backdrop" | "spotlight">;
|
|
10
7
|
//#endregion
|
|
11
8
|
//#region src/utils/rect.d.ts
|
|
12
9
|
interface Point {
|
|
@@ -361,23 +358,23 @@ interface MachineApi<T extends PropTypes = PropTypes> {
|
|
|
361
358
|
}
|
|
362
359
|
//#endregion
|
|
363
360
|
//#region src/connect.d.ts
|
|
364
|
-
declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
361
|
+
export declare function connect<T extends PropTypes>(state: State, send: Send, normalize: NormalizeProps<T>): MachineApi<T>;
|
|
365
362
|
//#endregion
|
|
366
363
|
//#region src/machine.d.ts
|
|
367
|
-
declare function machine(userContext: UserDefinedContext):
|
|
364
|
+
export declare function machine(userContext: UserDefinedContext): import("@destyler/xstate").Machine<MachineContext, MachineState, import("@destyler/xstate").AnyEventObject>;
|
|
368
365
|
//#endregion
|
|
369
366
|
//#region src/props.d.ts
|
|
370
|
-
declare const props: ("ids" | "steps" | "stepId" | "onStepChange" | "onStatusChange" | "closeOnInteractOutside" | "closeOnEscape" | "keyboardNavigation" | "preventInteraction" | "spotlightOffset" | "spotlightRadius" | "translations" | "dir" | "id" | "getRootNode" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside")[];
|
|
371
|
-
declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "ids" | "steps" | "stepId" | "onStepChange" | "onStatusChange" | "closeOnInteractOutside" | "closeOnEscape" | "keyboardNavigation" | "preventInteraction" | "spotlightOffset" | "spotlightRadius" | "translations" | "dir" | "id" | "getRootNode" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside">];
|
|
367
|
+
export declare const props: ("ids" | "steps" | "stepId" | "onStepChange" | "onStatusChange" | "closeOnInteractOutside" | "closeOnEscape" | "keyboardNavigation" | "preventInteraction" | "spotlightOffset" | "spotlightRadius" | "translations" | "dir" | "id" | "getRootNode" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside")[];
|
|
368
|
+
export declare const splitProps: <Props extends Partial<UserDefinedContext>>(props: Props) => [Partial<UserDefinedContext>, Omit<Props, "ids" | "steps" | "stepId" | "onStepChange" | "onStatusChange" | "closeOnInteractOutside" | "closeOnEscape" | "keyboardNavigation" | "preventInteraction" | "spotlightOffset" | "spotlightRadius" | "translations" | "dir" | "id" | "getRootNode" | "onPointerDownOutside" | "onFocusOutside" | "onInteractOutside">];
|
|
372
369
|
//#endregion
|
|
373
370
|
//#region src/utils/wait.d.ts
|
|
374
|
-
interface WaitOptions {
|
|
371
|
+
export interface WaitOptions {
|
|
375
372
|
timeout: number;
|
|
376
373
|
rootNode?: Document | ShadowRoot | undefined;
|
|
377
374
|
}
|
|
378
375
|
type WaitForPromiseReturn<T> = [Promise<T>, () => void];
|
|
379
|
-
declare function waitForElement(target: () => HTMLElement, options: WaitOptions): WaitForPromiseReturn<HTMLElement>;
|
|
376
|
+
export declare function waitForElement(target: () => HTMLElement, options: WaitOptions): WaitForPromiseReturn<HTMLElement>;
|
|
380
377
|
type EditableElement = HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement;
|
|
381
|
-
declare function waitForElementValue(target: () => EditableElement | null, value: string, options: WaitOptions): WaitForPromiseReturn<void>;
|
|
378
|
+
export declare function waitForElementValue(target: () => EditableElement | null, value: string, options: WaitOptions): WaitForPromiseReturn<void>;
|
|
382
379
|
//#endregion
|
|
383
|
-
export {
|
|
380
|
+
export type { MachineApi as Api, UserDefinedContext as Context, ElementIds, FocusOutsideEvent, InteractOutsideEvent, IntlTranslations, Point, PointerDownOutsideEvent, ProgressTextDetails, Service, StatusChangeDetails, StepAction, StepActionMap, StepActionTriggerProps, StepBaseDetails, StepChangeDetails, StepDetails, StepEffectArgs, StepPlacement, StepStatus, StepType };
|
package/dist/index.mjs
CHANGED
|
@@ -7,11 +7,9 @@ import { trapFocus } from "@destyler/focus-trap";
|
|
|
7
7
|
import { trackInteractOutside } from "@destyler/interact-outside";
|
|
8
8
|
import { compact, createSplitProps, isEqual, isString, nextIndex, prevIndex } from "@destyler/utils";
|
|
9
9
|
import { createProps } from "@destyler/types";
|
|
10
|
-
|
|
11
10
|
//#region src/anatomy.ts
|
|
12
11
|
const anatomy = createAnatomy("tour").parts("content", "actionTrigger", "closeTrigger", "progressText", "title", "description", "positioner", "arrow", "arrowTip", "backdrop", "spotlight");
|
|
13
12
|
const parts = anatomy.build();
|
|
14
|
-
|
|
15
13
|
//#endregion
|
|
16
14
|
//#region src/dom.ts
|
|
17
15
|
const dom = createScope({
|
|
@@ -25,7 +23,6 @@ const dom = createScope({
|
|
|
25
23
|
getPositionerEl: (ctx) => dom.getById(ctx, dom.getPositionerId(ctx)),
|
|
26
24
|
getBackdropEl: (ctx) => dom.getById(ctx, dom.getBackdropId(ctx))
|
|
27
25
|
});
|
|
28
|
-
|
|
29
26
|
//#endregion
|
|
30
27
|
//#region src/utils/clip-path.ts
|
|
31
28
|
function getClipPath(options) {
|
|
@@ -53,7 +50,6 @@ function getClipPath(options) {
|
|
|
53
50
|
a${topRight},${topRight},0,0,0-${topRight}-${topRight}\
|
|
54
51
|
Z`;
|
|
55
52
|
}
|
|
56
|
-
|
|
57
53
|
//#endregion
|
|
58
54
|
//#region src/utils/step.ts
|
|
59
55
|
function isTooltipStep(step) {
|
|
@@ -93,7 +89,6 @@ function findStep(steps, id) {
|
|
|
93
89
|
function findStepIndex(steps, id) {
|
|
94
90
|
return id != null ? steps.findIndex((step) => step.id === id) : -1;
|
|
95
91
|
}
|
|
96
|
-
|
|
97
92
|
//#endregion
|
|
98
93
|
//#region src/connect.ts
|
|
99
94
|
function connect(state, send, normalize) {
|
|
@@ -154,31 +149,31 @@ function connect(state, send, normalize) {
|
|
|
154
149
|
hasPrevStep,
|
|
155
150
|
firstStep,
|
|
156
151
|
lastStep,
|
|
157
|
-
addStep(step
|
|
152
|
+
addStep(step) {
|
|
158
153
|
send({
|
|
159
154
|
type: "STEPS.SET",
|
|
160
|
-
value: steps.concat(step
|
|
155
|
+
value: steps.concat(step),
|
|
161
156
|
src: "addStep"
|
|
162
157
|
});
|
|
163
158
|
},
|
|
164
159
|
removeStep(id) {
|
|
165
160
|
send({
|
|
166
161
|
type: "STEPS.SET",
|
|
167
|
-
value: steps.filter((step
|
|
162
|
+
value: steps.filter((step) => step.id !== id),
|
|
168
163
|
src: "removeStep"
|
|
169
164
|
});
|
|
170
165
|
},
|
|
171
166
|
updateStep(id, stepOverrides) {
|
|
172
167
|
send({
|
|
173
168
|
type: "STEPS.SET",
|
|
174
|
-
value: steps.map((step
|
|
169
|
+
value: steps.map((step) => step.id === id ? mergeProps(step, stepOverrides) : step),
|
|
175
170
|
src: "updateStep"
|
|
176
171
|
});
|
|
177
172
|
},
|
|
178
|
-
setSteps(steps
|
|
173
|
+
setSteps(steps) {
|
|
179
174
|
send({
|
|
180
175
|
type: "STEPS.SET",
|
|
181
|
-
value: steps
|
|
176
|
+
value: steps,
|
|
182
177
|
src: "setSteps"
|
|
183
178
|
});
|
|
184
179
|
},
|
|
@@ -195,7 +190,7 @@ function connect(state, send, normalize) {
|
|
|
195
190
|
});
|
|
196
191
|
},
|
|
197
192
|
isValidStep(id) {
|
|
198
|
-
return steps.some((step
|
|
193
|
+
return steps.some((step) => step.id === id);
|
|
199
194
|
},
|
|
200
195
|
isCurrentStep(id) {
|
|
201
196
|
return Boolean(step?.id === id);
|
|
@@ -210,7 +205,7 @@ function connect(state, send, normalize) {
|
|
|
210
205
|
return stepIndex / steps.length * 100;
|
|
211
206
|
},
|
|
212
207
|
getProgressText() {
|
|
213
|
-
const effectiveSteps = steps.filter((step
|
|
208
|
+
const effectiveSteps = steps.filter((step) => step.type !== "wait");
|
|
214
209
|
const details = {
|
|
215
210
|
current: findStepIndex(effectiveSteps, step?.id),
|
|
216
211
|
total: effectiveSteps.length
|
|
@@ -306,20 +301,18 @@ function connect(state, send, normalize) {
|
|
|
306
301
|
const isRtl = state.context.dir === "rtl";
|
|
307
302
|
switch (event.key) {
|
|
308
303
|
case "ArrowRight":
|
|
309
|
-
if (!hasNextStep) return;
|
|
304
|
+
if (isRtl ? !hasPrevStep : !hasNextStep) return;
|
|
310
305
|
send({
|
|
311
306
|
type: isRtl ? "STEP.PREV" : "STEP.NEXT",
|
|
312
307
|
src: "keydown"
|
|
313
308
|
});
|
|
314
309
|
break;
|
|
315
310
|
case "ArrowLeft":
|
|
316
|
-
if (!hasPrevStep) return;
|
|
311
|
+
if (isRtl ? !hasNextStep : !hasPrevStep) return;
|
|
317
312
|
send({
|
|
318
313
|
type: isRtl ? "STEP.NEXT" : "STEP.PREV",
|
|
319
314
|
src: "keydown"
|
|
320
315
|
});
|
|
321
|
-
break;
|
|
322
|
-
default: break;
|
|
323
316
|
}
|
|
324
317
|
}
|
|
325
318
|
});
|
|
@@ -339,15 +332,16 @@ function connect(state, send, normalize) {
|
|
|
339
332
|
});
|
|
340
333
|
},
|
|
341
334
|
getCloseTriggerProps() {
|
|
342
|
-
return normalize.
|
|
335
|
+
return normalize.button({
|
|
336
|
+
"type": "button",
|
|
343
337
|
...parts.closeTrigger.attrs,
|
|
344
338
|
"data-type": step?.type,
|
|
345
339
|
"aria-label": state.context.translations.close,
|
|
346
340
|
"onClick": actionMap.dismiss
|
|
347
341
|
});
|
|
348
342
|
},
|
|
349
|
-
getActionTriggerProps(props
|
|
350
|
-
const { action, attrs } = props
|
|
343
|
+
getActionTriggerProps(props) {
|
|
344
|
+
const { action, attrs } = props.action;
|
|
351
345
|
let actionProps = {};
|
|
352
346
|
switch (action) {
|
|
353
347
|
case "next":
|
|
@@ -375,14 +369,12 @@ function connect(state, send, normalize) {
|
|
|
375
369
|
"onClick": actionMap.dismiss
|
|
376
370
|
};
|
|
377
371
|
break;
|
|
378
|
-
default:
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
};
|
|
385
|
-
break;
|
|
372
|
+
default: actionProps = {
|
|
373
|
+
"data-type": "custom",
|
|
374
|
+
onClick() {
|
|
375
|
+
if (typeof action === "function") action(actionMap);
|
|
376
|
+
}
|
|
377
|
+
};
|
|
386
378
|
}
|
|
387
379
|
return normalize.button({
|
|
388
380
|
...parts.actionTrigger.attrs,
|
|
@@ -393,7 +385,6 @@ function connect(state, send, normalize) {
|
|
|
393
385
|
}
|
|
394
386
|
};
|
|
395
387
|
}
|
|
396
|
-
|
|
397
388
|
//#endregion
|
|
398
389
|
//#region src/utils/rect.ts
|
|
399
390
|
function getFrameElement(win) {
|
|
@@ -433,7 +424,6 @@ function offset(r, i) {
|
|
|
433
424
|
height: r.height + dy + dy
|
|
434
425
|
};
|
|
435
426
|
}
|
|
436
|
-
|
|
437
427
|
//#endregion
|
|
438
428
|
//#region src/machine.ts
|
|
439
429
|
const { and } = guards;
|
|
@@ -488,13 +478,13 @@ const set = { step(ctx, idx) {
|
|
|
488
478
|
};
|
|
489
479
|
};
|
|
490
480
|
const next = () => {
|
|
491
|
-
const idx
|
|
492
|
-
ctx.stepId = ctx.steps[idx
|
|
481
|
+
const idx = nextIndex(ctx.steps, ctx.stepIndex);
|
|
482
|
+
ctx.stepId = ctx.steps[idx].id;
|
|
493
483
|
invoke.stepChange(ctx);
|
|
494
484
|
};
|
|
495
485
|
const goto = (id) => {
|
|
496
|
-
const idx
|
|
497
|
-
ctx.stepId = ctx.steps[idx
|
|
486
|
+
const idx = ctx.steps.findIndex((s) => s.id === id);
|
|
487
|
+
ctx.stepId = ctx.steps[idx].id;
|
|
498
488
|
invoke.stepChange(ctx);
|
|
499
489
|
};
|
|
500
490
|
const dismiss = () => {
|
|
@@ -558,12 +548,12 @@ function machine(userContext) {
|
|
|
558
548
|
})
|
|
559
549
|
},
|
|
560
550
|
computed: {
|
|
561
|
-
stepIndex: (ctx
|
|
562
|
-
step: (ctx
|
|
563
|
-
hasNextStep: (ctx
|
|
564
|
-
hasPrevStep: (ctx
|
|
565
|
-
isFirstStep: (ctx
|
|
566
|
-
isLastStep: (ctx
|
|
551
|
+
stepIndex: (ctx) => findStepIndex(ctx.steps, ctx.stepId),
|
|
552
|
+
step: (ctx) => findStep(ctx.steps, ctx.stepId),
|
|
553
|
+
hasNextStep: (ctx) => ctx.stepIndex < ctx.steps.length - 1,
|
|
554
|
+
hasPrevStep: (ctx) => ctx.stepIndex > 0,
|
|
555
|
+
isFirstStep: (ctx) => ctx.stepIndex === 0,
|
|
556
|
+
isLastStep: (ctx) => ctx.stepIndex === ctx.steps.length - 1
|
|
567
557
|
},
|
|
568
558
|
created: ["validateSteps"],
|
|
569
559
|
watch: { stepId: [
|
|
@@ -623,7 +613,7 @@ function machine(userContext) {
|
|
|
623
613
|
} },
|
|
624
614
|
on: { "TARGET.RESOLVED": {
|
|
625
615
|
target: "target.scrolling",
|
|
626
|
-
actions: ["setResolvedTarget"]
|
|
616
|
+
actions: ["setResolvedTarget", "syncTargetAttrs"]
|
|
627
617
|
} }
|
|
628
618
|
},
|
|
629
619
|
"target.scrolling": {
|
|
@@ -653,92 +643,98 @@ function machine(userContext) {
|
|
|
653
643
|
}, {
|
|
654
644
|
delays: { MISSING_TARGET_TIMEOUT: 3e3 },
|
|
655
645
|
guards: {
|
|
656
|
-
isLastStep: (ctx
|
|
657
|
-
isValidStep: (ctx
|
|
658
|
-
hasTarget: (ctx
|
|
659
|
-
hasResolvedTarget: (ctx
|
|
660
|
-
isWaitingStep: (ctx
|
|
646
|
+
isLastStep: (ctx) => ctx.isLastStep,
|
|
647
|
+
isValidStep: (ctx) => ctx.stepId != null,
|
|
648
|
+
hasTarget: (ctx) => ctx.step?.target != null,
|
|
649
|
+
hasResolvedTarget: (ctx) => ctx.resolvedTarget.value != null,
|
|
650
|
+
isWaitingStep: (ctx) => ctx.step?.type === "wait"
|
|
661
651
|
},
|
|
662
652
|
actions: {
|
|
663
|
-
scrollToTarget(ctx
|
|
664
|
-
ctx
|
|
653
|
+
scrollToTarget(ctx, _evt) {
|
|
654
|
+
ctx.resolvedTarget.value?.scrollIntoView({
|
|
665
655
|
behavior: "instant",
|
|
666
656
|
block: "center",
|
|
667
657
|
inline: "center"
|
|
668
658
|
});
|
|
669
659
|
},
|
|
670
|
-
setStep(ctx
|
|
671
|
-
set.step(ctx
|
|
660
|
+
setStep(ctx, evt) {
|
|
661
|
+
set.step(ctx, findStepIndex(ctx.steps, evt.value));
|
|
672
662
|
},
|
|
673
|
-
clearStep(ctx
|
|
674
|
-
ctx
|
|
663
|
+
clearStep(ctx) {
|
|
664
|
+
ctx.targetRect = ref({
|
|
675
665
|
width: 0,
|
|
676
666
|
height: 0,
|
|
677
667
|
x: 0,
|
|
678
668
|
y: 0
|
|
679
669
|
});
|
|
680
|
-
set.step(ctx
|
|
670
|
+
set.step(ctx, -1);
|
|
681
671
|
},
|
|
682
|
-
setInitialStep(ctx
|
|
683
|
-
if (ctx
|
|
672
|
+
setInitialStep(ctx, evt) {
|
|
673
|
+
if (ctx.steps.length === 0) return;
|
|
684
674
|
if (isString(evt.id)) {
|
|
685
|
-
const idx = findStepIndex(ctx
|
|
686
|
-
set.step(ctx
|
|
675
|
+
const idx = findStepIndex(ctx.steps, evt.id);
|
|
676
|
+
set.step(ctx, idx);
|
|
687
677
|
return;
|
|
688
678
|
}
|
|
689
|
-
set.step(ctx
|
|
679
|
+
set.step(ctx, 0);
|
|
690
680
|
},
|
|
691
|
-
setNextStep(ctx
|
|
692
|
-
const idx = nextIndex(ctx
|
|
693
|
-
set.step(ctx
|
|
681
|
+
setNextStep(ctx) {
|
|
682
|
+
const idx = nextIndex(ctx.steps, ctx.stepIndex);
|
|
683
|
+
set.step(ctx, idx);
|
|
694
684
|
},
|
|
695
|
-
setPrevStep(ctx
|
|
696
|
-
const idx = prevIndex(ctx
|
|
697
|
-
set.step(ctx
|
|
685
|
+
setPrevStep(ctx) {
|
|
686
|
+
const idx = prevIndex(ctx.steps, ctx.stepIndex);
|
|
687
|
+
set.step(ctx, idx);
|
|
698
688
|
},
|
|
699
|
-
invokeOnStart(ctx
|
|
700
|
-
invoke.statusChange(ctx
|
|
689
|
+
invokeOnStart(ctx) {
|
|
690
|
+
invoke.statusChange(ctx, "started");
|
|
701
691
|
},
|
|
702
|
-
invokeOnDismiss(ctx
|
|
703
|
-
invoke.statusChange(ctx
|
|
692
|
+
invokeOnDismiss(ctx) {
|
|
693
|
+
invoke.statusChange(ctx, "dismissed");
|
|
704
694
|
},
|
|
705
|
-
invokeOnComplete(ctx
|
|
706
|
-
invoke.statusChange(ctx
|
|
695
|
+
invokeOnComplete(ctx) {
|
|
696
|
+
invoke.statusChange(ctx, "completed");
|
|
707
697
|
},
|
|
708
|
-
invokeOnSkip(ctx
|
|
709
|
-
invoke.statusChange(ctx
|
|
698
|
+
invokeOnSkip(ctx) {
|
|
699
|
+
invoke.statusChange(ctx, "skipped");
|
|
710
700
|
},
|
|
711
|
-
invokeOnNotFound(ctx
|
|
712
|
-
invoke.statusChange(ctx
|
|
701
|
+
invokeOnNotFound(ctx) {
|
|
702
|
+
invoke.statusChange(ctx, "not-found");
|
|
713
703
|
},
|
|
714
704
|
raiseStepChange(_ctx, _evt, { send }) {
|
|
715
705
|
send({ type: "STEP.CHANGED" });
|
|
716
706
|
},
|
|
717
|
-
setResolvedTarget(ctx
|
|
718
|
-
const node = evt.node ?? ctx
|
|
719
|
-
ctx
|
|
707
|
+
setResolvedTarget(ctx, evt) {
|
|
708
|
+
const node = evt.node ?? ctx.step?.target?.();
|
|
709
|
+
ctx.resolvedTarget.value = node ?? null;
|
|
720
710
|
},
|
|
721
|
-
syncTargetAttrs(ctx
|
|
722
|
-
ctx
|
|
723
|
-
ctx
|
|
724
|
-
const targetEl = ctx
|
|
711
|
+
syncTargetAttrs(ctx) {
|
|
712
|
+
ctx._targetCleanup?.();
|
|
713
|
+
ctx._targetCleanup = void 0;
|
|
714
|
+
const targetEl = ctx.resolvedTarget.value;
|
|
725
715
|
if (!targetEl) return;
|
|
726
|
-
|
|
716
|
+
const preventInteraction = ctx.preventInteraction;
|
|
717
|
+
const inert = targetEl.inert;
|
|
718
|
+
const highlighted = targetEl.getAttribute("data-tour-highlighted");
|
|
719
|
+
if (preventInteraction) targetEl.inert = true;
|
|
727
720
|
targetEl.setAttribute("data-tour-highlighted", "");
|
|
728
|
-
ctx
|
|
729
|
-
if (
|
|
730
|
-
targetEl.
|
|
721
|
+
ctx._targetCleanup = () => {
|
|
722
|
+
if (preventInteraction && targetEl.inert) targetEl.inert = inert;
|
|
723
|
+
if (targetEl.getAttribute("data-tour-highlighted") === "") {
|
|
724
|
+
if (highlighted == null) targetEl.removeAttribute("data-tour-highlighted");
|
|
725
|
+
else targetEl.setAttribute("data-tour-highlighted", highlighted);
|
|
726
|
+
}
|
|
731
727
|
};
|
|
732
728
|
},
|
|
733
|
-
cleanupFns(ctx
|
|
734
|
-
ctx
|
|
735
|
-
ctx
|
|
736
|
-
ctx
|
|
737
|
-
ctx
|
|
729
|
+
cleanupFns(ctx) {
|
|
730
|
+
ctx._targetCleanup?.();
|
|
731
|
+
ctx._targetCleanup = void 0;
|
|
732
|
+
ctx._effectCleanup?.();
|
|
733
|
+
ctx._effectCleanup = void 0;
|
|
738
734
|
},
|
|
739
|
-
validateSteps(ctx
|
|
735
|
+
validateSteps(ctx) {
|
|
740
736
|
const ids = /* @__PURE__ */ new Set();
|
|
741
|
-
ctx
|
|
737
|
+
ctx.steps.forEach((step) => {
|
|
742
738
|
if (ids.has(step.id)) throw new Error(`[destyler/tour] Duplicate step id: ${step.id}`);
|
|
743
739
|
if (step.target == null && step.type == null) throw new Error(`[destyler/tour] Step ${step.id} has no target or type. At least one of those is required.`);
|
|
744
740
|
ids.add(step.id);
|
|
@@ -746,10 +742,10 @@ function machine(userContext) {
|
|
|
746
742
|
}
|
|
747
743
|
},
|
|
748
744
|
activities: {
|
|
749
|
-
waitForTarget(ctx
|
|
750
|
-
const targetEl = ctx
|
|
751
|
-
const win = dom.getWin(ctx
|
|
752
|
-
const rootNode = dom.getRootNode(ctx
|
|
745
|
+
waitForTarget(ctx, _evt, { send }) {
|
|
746
|
+
const targetEl = ctx.step?.target;
|
|
747
|
+
const win = dom.getWin(ctx);
|
|
748
|
+
const rootNode = dom.getRootNode(ctx);
|
|
753
749
|
const observer = new win.MutationObserver(() => {
|
|
754
750
|
const node = targetEl?.();
|
|
755
751
|
if (node) {
|
|
@@ -769,12 +765,12 @@ function machine(userContext) {
|
|
|
769
765
|
observer.disconnect();
|
|
770
766
|
};
|
|
771
767
|
},
|
|
772
|
-
trackBoundarySize(ctx
|
|
773
|
-
const win = dom.getWin(ctx
|
|
774
|
-
const doc = dom.getDoc(ctx
|
|
768
|
+
trackBoundarySize(ctx) {
|
|
769
|
+
const win = dom.getWin(ctx);
|
|
770
|
+
const doc = dom.getDoc(ctx);
|
|
775
771
|
const onResize = () => {
|
|
776
|
-
ctx
|
|
777
|
-
width: visualViewport?.width ?? win.innerWidth,
|
|
772
|
+
ctx.boundarySize = {
|
|
773
|
+
width: win.visualViewport?.width ?? win.innerWidth,
|
|
778
774
|
height: doc.documentElement.scrollHeight
|
|
779
775
|
};
|
|
780
776
|
};
|
|
@@ -783,9 +779,9 @@ function machine(userContext) {
|
|
|
783
779
|
viewport.addEventListener("resize", onResize);
|
|
784
780
|
return () => viewport.removeEventListener("resize", onResize);
|
|
785
781
|
},
|
|
786
|
-
trackEscapeKeydown(ctx
|
|
787
|
-
if (!ctx
|
|
788
|
-
const doc = dom.getDoc(ctx
|
|
782
|
+
trackEscapeKeydown(ctx, _evt, { send }) {
|
|
783
|
+
if (!ctx.closeOnEscape) return;
|
|
784
|
+
const doc = dom.getDoc(ctx);
|
|
789
785
|
const onKeyDown = (event) => {
|
|
790
786
|
if (event.key === "Escape") {
|
|
791
787
|
event.preventDefault();
|
|
@@ -801,28 +797,28 @@ function machine(userContext) {
|
|
|
801
797
|
doc.removeEventListener("keydown", onKeyDown, true);
|
|
802
798
|
};
|
|
803
799
|
},
|
|
804
|
-
trackInteractOutside(ctx
|
|
805
|
-
if (ctx
|
|
806
|
-
const contentEl = () => dom.getContentEl(ctx
|
|
800
|
+
trackInteractOutside(ctx, _evt, { send }) {
|
|
801
|
+
if (ctx.step == null) return;
|
|
802
|
+
const contentEl = () => dom.getContentEl(ctx);
|
|
807
803
|
return trackInteractOutside(contentEl, {
|
|
808
804
|
defer: true,
|
|
809
805
|
exclude(target) {
|
|
810
|
-
return contains(ctx
|
|
806
|
+
return contains(ctx.step?.target?.(), target);
|
|
811
807
|
},
|
|
812
808
|
onFocusOutside(event) {
|
|
813
|
-
ctx
|
|
814
|
-
if (!ctx
|
|
809
|
+
ctx.onFocusOutside?.(event);
|
|
810
|
+
if (!ctx.closeOnInteractOutside) event.preventDefault();
|
|
815
811
|
},
|
|
816
812
|
onPointerDownOutside(event) {
|
|
817
|
-
ctx
|
|
818
|
-
if (isEventInRect(ctx
|
|
813
|
+
ctx.onPointerDownOutside?.(event);
|
|
814
|
+
if (isEventInRect(ctx.targetRect, event.detail.originalEvent)) {
|
|
819
815
|
event.preventDefault();
|
|
820
816
|
return;
|
|
821
817
|
}
|
|
822
|
-
if (!ctx
|
|
818
|
+
if (!ctx.closeOnInteractOutside) event.preventDefault();
|
|
823
819
|
},
|
|
824
820
|
onInteractOutside(event) {
|
|
825
|
-
ctx
|
|
821
|
+
ctx.onInteractOutside?.(event);
|
|
826
822
|
if (event.defaultPrevented) return;
|
|
827
823
|
send({
|
|
828
824
|
type: "DISMISS",
|
|
@@ -831,13 +827,13 @@ function machine(userContext) {
|
|
|
831
827
|
}
|
|
832
828
|
});
|
|
833
829
|
},
|
|
834
|
-
trackDismissableBranch(ctx
|
|
835
|
-
if (ctx
|
|
836
|
-
const contentEl = () => dom.getContentEl(ctx
|
|
830
|
+
trackDismissableBranch(ctx) {
|
|
831
|
+
if (ctx.step == null) return;
|
|
832
|
+
const contentEl = () => dom.getContentEl(ctx);
|
|
837
833
|
return trackDismissableBranch(contentEl, { defer: !contentEl() });
|
|
838
834
|
},
|
|
839
|
-
trapFocus(ctx
|
|
840
|
-
const contentEl = () => dom.getContentEl(ctx
|
|
835
|
+
trapFocus(ctx) {
|
|
836
|
+
const contentEl = () => dom.getContentEl(ctx);
|
|
841
837
|
return trapFocus(contentEl, {
|
|
842
838
|
escapeDeactivates: false,
|
|
843
839
|
allowOutsideClick: true,
|
|
@@ -845,33 +841,32 @@ function machine(userContext) {
|
|
|
845
841
|
returnFocusOnDeactivate: false
|
|
846
842
|
});
|
|
847
843
|
},
|
|
848
|
-
trackPlacement(ctx
|
|
849
|
-
if (ctx
|
|
850
|
-
ctx
|
|
851
|
-
if (isDialogStep(ctx
|
|
852
|
-
if (!isTooltipStep(ctx
|
|
853
|
-
const positionerEl = () => dom.getPositionerEl(ctx
|
|
854
|
-
return getPlacement(ctx
|
|
844
|
+
trackPlacement(ctx) {
|
|
845
|
+
if (ctx.step == null) return;
|
|
846
|
+
ctx.currentPlacement = ctx.step.placement ?? "bottom";
|
|
847
|
+
if (isDialogStep(ctx.step)) return syncZIndex(ctx);
|
|
848
|
+
if (!isTooltipStep(ctx.step)) return;
|
|
849
|
+
const positionerEl = () => dom.getPositionerEl(ctx);
|
|
850
|
+
return getPlacement(ctx.resolvedTarget.value, positionerEl, {
|
|
855
851
|
defer: true,
|
|
856
|
-
placement: ctx
|
|
852
|
+
placement: ctx.step.placement ?? "bottom",
|
|
857
853
|
strategy: "absolute",
|
|
858
854
|
gutter: 10,
|
|
859
|
-
offset: ctx
|
|
855
|
+
offset: ctx.step.offset,
|
|
860
856
|
getAnchorRect(el) {
|
|
861
857
|
if (!isHTMLElement(el)) return null;
|
|
862
|
-
return offset(el.getBoundingClientRect(), ctx
|
|
858
|
+
return offset(el.getBoundingClientRect(), ctx.spotlightOffset);
|
|
863
859
|
},
|
|
864
860
|
onComplete(data) {
|
|
865
861
|
const { rects } = data.middlewareData;
|
|
866
|
-
ctx
|
|
867
|
-
ctx
|
|
862
|
+
ctx.currentPlacement = data.placement;
|
|
863
|
+
ctx.targetRect = rects.reference;
|
|
868
864
|
}
|
|
869
865
|
});
|
|
870
866
|
}
|
|
871
867
|
}
|
|
872
868
|
});
|
|
873
869
|
}
|
|
874
|
-
|
|
875
870
|
//#endregion
|
|
876
871
|
//#region src/props.ts
|
|
877
872
|
const props = createProps()([
|
|
@@ -895,39 +890,36 @@ const props = createProps()([
|
|
|
895
890
|
"translations"
|
|
896
891
|
]);
|
|
897
892
|
const splitProps = createSplitProps(props);
|
|
898
|
-
|
|
899
893
|
//#endregion
|
|
900
894
|
//#region src/utils/wait.ts
|
|
901
|
-
function waitForPromise(promise, controller, timeout) {
|
|
895
|
+
function waitForPromise(promise, controller, timeout, cleanup) {
|
|
902
896
|
const { signal } = controller;
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
907
|
-
|
|
897
|
+
return [new Promise((resolve, reject) => {
|
|
898
|
+
let settled = false;
|
|
899
|
+
let timeoutId;
|
|
900
|
+
let onAbort;
|
|
901
|
+
const finish = (callback) => {
|
|
902
|
+
if (settled) return;
|
|
903
|
+
settled = true;
|
|
908
904
|
clearTimeout(timeoutId);
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
}
|
|
916
|
-
})
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
}
|
|
921
|
-
});
|
|
922
|
-
});
|
|
923
|
-
const abort = () => controller.abort();
|
|
924
|
-
return [wrappedPromise, abort];
|
|
905
|
+
signal.removeEventListener("abort", onAbort);
|
|
906
|
+
cleanup();
|
|
907
|
+
callback();
|
|
908
|
+
};
|
|
909
|
+
onAbort = () => finish(() => reject(/* @__PURE__ */ new Error("Promise aborted")));
|
|
910
|
+
timeoutId = setTimeout(() => {
|
|
911
|
+
finish(() => reject(/* @__PURE__ */ new Error(`Timeout of ${timeout}ms exceeded`)));
|
|
912
|
+
}, timeout);
|
|
913
|
+
signal.addEventListener("abort", onAbort);
|
|
914
|
+
promise.then((result) => finish(() => resolve(result)), (error) => finish(() => reject(error)));
|
|
915
|
+
}), () => controller.abort()];
|
|
925
916
|
}
|
|
926
917
|
function waitForElement(target, options) {
|
|
927
918
|
const { timeout, rootNode } = options;
|
|
928
919
|
const win = getWindow(rootNode);
|
|
929
920
|
const doc = getDocument(rootNode);
|
|
930
921
|
const controller = new win.AbortController();
|
|
922
|
+
let cleanup = () => {};
|
|
931
923
|
return waitForPromise(new Promise((resolve) => {
|
|
932
924
|
const el = target();
|
|
933
925
|
if (el) {
|
|
@@ -935,34 +927,33 @@ function waitForElement(target, options) {
|
|
|
935
927
|
return;
|
|
936
928
|
}
|
|
937
929
|
const observer = new win.MutationObserver(() => {
|
|
938
|
-
const el
|
|
939
|
-
if (el
|
|
940
|
-
observer.disconnect();
|
|
941
|
-
resolve(el$1);
|
|
942
|
-
}
|
|
930
|
+
const el = target();
|
|
931
|
+
if (el) resolve(el);
|
|
943
932
|
});
|
|
944
|
-
observer.
|
|
933
|
+
cleanup = () => observer.disconnect();
|
|
934
|
+
observer.observe(rootNode ?? doc.body, {
|
|
945
935
|
childList: true,
|
|
946
936
|
subtree: true
|
|
947
937
|
});
|
|
948
|
-
}), controller, timeout);
|
|
938
|
+
}), controller, timeout, () => cleanup());
|
|
949
939
|
}
|
|
950
940
|
function waitForElementValue(target, value, options) {
|
|
951
941
|
const { timeout, rootNode } = options;
|
|
952
942
|
const controller = new (getWindow(rootNode)).AbortController();
|
|
943
|
+
let cleanup = () => {};
|
|
953
944
|
return waitForPromise(new Promise((resolve) => {
|
|
954
945
|
const el = target();
|
|
955
946
|
if (!el) return;
|
|
947
|
+
if (el.value === value) {
|
|
948
|
+
resolve();
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
956
951
|
const checkValue = () => {
|
|
957
|
-
if (el.value === value)
|
|
958
|
-
resolve();
|
|
959
|
-
el.removeEventListener("input", checkValue);
|
|
960
|
-
}
|
|
952
|
+
if (el.value === value) resolve();
|
|
961
953
|
};
|
|
962
|
-
|
|
954
|
+
cleanup = () => el.removeEventListener("input", checkValue);
|
|
963
955
|
el.addEventListener("input", checkValue, { signal: controller.signal });
|
|
964
|
-
}), controller, timeout);
|
|
956
|
+
}), controller, timeout, () => cleanup());
|
|
965
957
|
}
|
|
966
|
-
|
|
967
958
|
//#endregion
|
|
968
|
-
export { anatomy, connect, machine, props, splitProps, waitForElement, waitForElementValue };
|
|
959
|
+
export { anatomy, connect, machine, props, splitProps, waitForElement, waitForElementValue };
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@destyler/tour",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.13",
|
|
5
5
|
"description": "A guided tour that helps users understand the interface.",
|
|
6
6
|
"author": "Elone Hoo <elonehoo@gmail.com>",
|
|
7
7
|
"license": "MIT",
|
|
@@ -22,15 +22,15 @@
|
|
|
22
22
|
"dist"
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@destyler/
|
|
26
|
-
"@destyler/dismissable": "0.2.
|
|
27
|
-
"@destyler/
|
|
28
|
-
"@destyler/
|
|
29
|
-
"@destyler/
|
|
30
|
-
"@destyler/
|
|
31
|
-
"@destyler/types": "0.2.
|
|
32
|
-
"@destyler/utils": "0.2.
|
|
33
|
-
"@destyler/xstate": "0.2.
|
|
25
|
+
"@destyler/anatomy": "0.2.13",
|
|
26
|
+
"@destyler/dismissable": "0.2.13",
|
|
27
|
+
"@destyler/dom": "0.2.13",
|
|
28
|
+
"@destyler/focus-trap": "0.2.13",
|
|
29
|
+
"@destyler/interact-outside": "0.2.13",
|
|
30
|
+
"@destyler/popper": "0.2.13",
|
|
31
|
+
"@destyler/types": "0.2.13",
|
|
32
|
+
"@destyler/utils": "0.2.13",
|
|
33
|
+
"@destyler/xstate": "0.2.13"
|
|
34
34
|
},
|
|
35
35
|
"publishConfig": {
|
|
36
36
|
"access": "public"
|