Fix animation issue with scrollable elements
Browse files- docs/package.json +1 -1
- docs/pnpm-lock.yaml +4 -4
- docs/src/content/guides/configuration.mdx +3 -0
- index.html +2 -1
- src/driver.ts +7 -7
- src/events.ts +1 -1
- src/highlight.ts +14 -8
- src/state.ts +8 -1
docs/package.json
CHANGED
@@ -17,7 +17,7 @@
|
|
17 |
"@types/react-dom": "^18.2.6",
|
18 |
"astro": "^2.7.4",
|
19 |
"astro-compress": "^1.1.49",
|
20 |
-
"driver.js": "1.
|
21 |
"react": "^18.2.0",
|
22 |
"react-dom": "^18.2.0",
|
23 |
"react-fast-marquee": "^1.6.0",
|
|
|
17 |
"@types/react-dom": "^18.2.6",
|
18 |
"astro": "^2.7.4",
|
19 |
"astro-compress": "^1.1.49",
|
20 |
+
"driver.js": "1.2.0",
|
21 |
"react": "^18.2.0",
|
22 |
"react-dom": "^18.2.0",
|
23 |
"react-fast-marquee": "^1.6.0",
|
docs/pnpm-lock.yaml
CHANGED
@@ -27,8 +27,8 @@ dependencies:
|
|
27 |
specifier: ^1.1.49
|
28 |
version: 1.1.49
|
29 |
driver.js:
|
30 |
-
specifier: 1.
|
31 |
-
version: 1.
|
32 |
react:
|
33 |
specifier: ^18.2.0
|
34 |
version: 18.2.0
|
@@ -1576,8 +1576,8 @@ packages:
|
|
1576 |
tslib: 2.6.0
|
1577 |
dev: false
|
1578 |
|
1579 |
-
/driver.js@1.
|
1580 |
-
resolution: {integrity: sha512-
|
1581 |
dev: false
|
1582 |
|
1583 |
|
|
27 |
specifier: ^1.1.49
|
28 |
version: 1.1.49
|
29 |
driver.js:
|
30 |
+
specifier: 1.2.0
|
31 |
+
version: 1.2.0
|
32 |
react:
|
33 |
specifier: ^18.2.0
|
34 |
version: 18.2.0
|
|
|
1576 |
tslib: 2.6.0
|
1577 |
dev: false
|
1578 |
|
1579 |
+
/driver.js@1.2.0:
|
1580 |
+
resolution: {integrity: sha512-kn9YCQqvMZovs82pYhEl7IKdvv5MmZ6R/OXy5aI7L0qCBK2ynRfm6oQ47pNSdOW731QtT5vySKwz8Nk5ai3LXw==}
|
1581 |
dev: false
|
1582 |
|
1583 |
docs/src/content/guides/configuration.mdx
CHANGED
@@ -41,6 +41,9 @@ type Config = {
|
|
41 |
// Whether to allow keyboard navigation. (default: true)
|
42 |
allowKeyboardControl?: boolean;
|
43 |
|
|
|
|
|
|
|
44 |
// If you want to add custom class to the popover
|
45 |
popoverClass?: string;
|
46 |
// Distance between the popover and the highlighted element. (default: 10)
|
|
|
41 |
// Whether to allow keyboard navigation. (default: true)
|
42 |
allowKeyboardControl?: boolean;
|
43 |
|
44 |
+
// Whether to disable interaction with the highlighted element. (default: false)
|
45 |
+
disableActiveInteraction?: boolean;
|
46 |
+
|
47 |
// If you want to add custom class to the popover
|
48 |
popoverClass?: string;
|
49 |
// Distance between the popover and the highlighted element. (default: 10)
|
index.html
CHANGED
@@ -471,11 +471,12 @@ npm install driver.js</pre
|
|
471 |
popover.title.innerHTML = `${driverObj.getActiveIndex()} ${driverObj.hasNextStep() ? 'Yes' : 'No'} ${driverObj.hasPreviousStep() ? 'Yes' : 'No'}`
|
472 |
popover.description.innerHTML = `${driverObj.isFirstStep() ? 'Yes' : 'No'} ${driverObj.isLastStep() ? 'Yes' : 'No'}`
|
473 |
|
|
|
474 |
console.log(driverObj.getActiveStep());
|
475 |
}
|
476 |
});
|
477 |
|
478 |
-
driverObj.drive();
|
479 |
});
|
480 |
|
481 |
document.getElementById("reconfigure-steps").addEventListener("click", () => {
|
|
|
471 |
popover.title.innerHTML = `${driverObj.getActiveIndex()} ${driverObj.hasNextStep() ? 'Yes' : 'No'} ${driverObj.hasPreviousStep() ? 'Yes' : 'No'}`
|
472 |
popover.description.innerHTML = `${driverObj.isFirstStep() ? 'Yes' : 'No'} ${driverObj.isLastStep() ? 'Yes' : 'No'}`
|
473 |
|
474 |
+
console.log(driverObj.getActiveIndex());
|
475 |
console.log(driverObj.getActiveStep());
|
476 |
}
|
477 |
});
|
478 |
|
479 |
+
driverObj.drive(4);
|
480 |
});
|
481 |
|
482 |
document.getElementById("reconfigure-steps").addEventListener("click", () => {
|
src/driver.ts
CHANGED
@@ -73,8 +73,8 @@ export function driver(options: Config = {}) {
|
|
73 |
}
|
74 |
|
75 |
const activeIndex = getState("activeIndex");
|
76 |
-
const activeStep = getState("
|
77 |
-
const activeElement = getState("
|
78 |
if (typeof activeIndex === "undefined" || typeof activeStep === "undefined") {
|
79 |
return;
|
80 |
}
|
@@ -102,8 +102,8 @@ export function driver(options: Config = {}) {
|
|
102 |
}
|
103 |
|
104 |
const activeIndex = getState("activeIndex");
|
105 |
-
const activeStep = getState("
|
106 |
-
const activeElement = getState("
|
107 |
if (typeof activeIndex === "undefined" || typeof activeStep === "undefined") {
|
108 |
return;
|
109 |
}
|
@@ -213,8 +213,8 @@ export function driver(options: Config = {}) {
|
|
213 |
}
|
214 |
|
215 |
function destroy(withOnDestroyStartedHook = true) {
|
216 |
-
const activeElement = getState("
|
217 |
-
const activeStep = getState("
|
218 |
|
219 |
const activeOnDestroyed = getState("__activeOnDestroyed");
|
220 |
|
@@ -330,4 +330,4 @@ export function driver(options: Config = {}) {
|
|
330 |
};
|
331 |
}
|
332 |
|
333 |
-
export type Driver = ReturnType<typeof driver
|
|
|
73 |
}
|
74 |
|
75 |
const activeIndex = getState("activeIndex");
|
76 |
+
const activeStep = getState("__activeStep");
|
77 |
+
const activeElement = getState("__activeElement");
|
78 |
if (typeof activeIndex === "undefined" || typeof activeStep === "undefined") {
|
79 |
return;
|
80 |
}
|
|
|
102 |
}
|
103 |
|
104 |
const activeIndex = getState("activeIndex");
|
105 |
+
const activeStep = getState("__activeStep");
|
106 |
+
const activeElement = getState("__activeElement");
|
107 |
if (typeof activeIndex === "undefined" || typeof activeStep === "undefined") {
|
108 |
return;
|
109 |
}
|
|
|
213 |
}
|
214 |
|
215 |
function destroy(withOnDestroyStartedHook = true) {
|
216 |
+
const activeElement = getState("__activeElement");
|
217 |
+
const activeStep = getState("__activeStep");
|
218 |
|
219 |
const activeOnDestroyed = getState("__activeOnDestroyed");
|
220 |
|
|
|
330 |
};
|
331 |
}
|
332 |
|
333 |
+
export type Driver = ReturnType<typeof driver>;
|
src/events.ts
CHANGED
@@ -24,7 +24,7 @@ function trapFocus(e: KeyboardEvent) {
|
|
24 |
return;
|
25 |
}
|
26 |
|
27 |
-
const activeElement = getState("
|
28 |
const popoverEl = getState("popover")?.wrapper;
|
29 |
|
30 |
const focusableEls = getFocusableElements([
|
|
|
24 |
return;
|
25 |
}
|
26 |
|
27 |
+
const activeElement = getState("__activeElement");
|
28 |
const popoverEl = getState("popover")?.wrapper;
|
29 |
|
30 |
const focusableEls = getFocusableElements([
|
src/highlight.ts
CHANGED
@@ -43,8 +43,8 @@ export function highlight(step: DriveStep) {
|
|
43 |
}
|
44 |
|
45 |
export function refreshActiveHighlight() {
|
46 |
-
const activeHighlight = getState("
|
47 |
-
const activeStep = getState("
|
48 |
|
49 |
if (!activeHighlight) {
|
50 |
return;
|
@@ -55,12 +55,13 @@ export function refreshActiveHighlight() {
|
|
55 |
repositionPopover(activeHighlight, activeStep);
|
56 |
}
|
57 |
|
|
|
58 |
function transferHighlight(toElement: Element, toStep: DriveStep) {
|
59 |
const duration = 400;
|
60 |
const start = Date.now();
|
61 |
|
62 |
-
const fromStep = getState("
|
63 |
-
const fromElement = getState("
|
64 |
|
65 |
// If it's the first time we're highlighting an element, we show
|
66 |
// the popover immediately. Otherwise, we wait for the animation
|
@@ -96,6 +97,11 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
96 |
|
97 |
hidePopover();
|
98 |
|
|
|
|
|
|
|
|
|
|
|
99 |
const animate = () => {
|
100 |
const transitionCallback = getState("__transitionCallback");
|
101 |
|
@@ -128,16 +134,16 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
128 |
}
|
129 |
|
130 |
setState("__transitionCallback", undefined);
|
|
|
|
|
|
|
|
|
131 |
}
|
132 |
|
133 |
window.requestAnimationFrame(animate);
|
134 |
};
|
135 |
|
136 |
setState("__transitionCallback", animate);
|
137 |
-
setState("previousStep", fromStep);
|
138 |
-
setState("previousElement", fromElement);
|
139 |
-
setState("activeStep", toStep);
|
140 |
-
setState("activeElement", toElement);
|
141 |
|
142 |
window.requestAnimationFrame(animate);
|
143 |
|
|
|
43 |
}
|
44 |
|
45 |
export function refreshActiveHighlight() {
|
46 |
+
const activeHighlight = getState("__activeElement");
|
47 |
+
const activeStep = getState("__activeStep")!;
|
48 |
|
49 |
if (!activeHighlight) {
|
50 |
return;
|
|
|
55 |
repositionPopover(activeHighlight, activeStep);
|
56 |
}
|
57 |
|
58 |
+
|
59 |
function transferHighlight(toElement: Element, toStep: DriveStep) {
|
60 |
const duration = 400;
|
61 |
const start = Date.now();
|
62 |
|
63 |
+
const fromStep = getState("__activeStep");
|
64 |
+
const fromElement = getState("__activeElement") || toElement;
|
65 |
|
66 |
// If it's the first time we're highlighting an element, we show
|
67 |
// the popover immediately. Otherwise, we wait for the animation
|
|
|
97 |
|
98 |
hidePopover();
|
99 |
|
100 |
+
setState("previousStep", fromStep);
|
101 |
+
setState("previousElement", fromElement);
|
102 |
+
setState("activeStep", toStep);
|
103 |
+
setState("activeElement", toElement);
|
104 |
+
|
105 |
const animate = () => {
|
106 |
const transitionCallback = getState("__transitionCallback");
|
107 |
|
|
|
134 |
}
|
135 |
|
136 |
setState("__transitionCallback", undefined);
|
137 |
+
setState("__previousStep", fromStep);
|
138 |
+
setState("__previousElement", fromElement);
|
139 |
+
setState("__activeStep", toStep);
|
140 |
+
setState("__activeElement", toElement);
|
141 |
}
|
142 |
|
143 |
window.requestAnimationFrame(animate);
|
144 |
};
|
145 |
|
146 |
setState("__transitionCallback", animate);
|
|
|
|
|
|
|
|
|
147 |
|
148 |
window.requestAnimationFrame(animate);
|
149 |
|
src/state.ts
CHANGED
@@ -8,12 +8,19 @@ export type State = {
|
|
8 |
activeIndex?: number;
|
9 |
activeElement?: Element;
|
10 |
activeStep?: DriveStep;
|
11 |
-
|
12 |
previousElement?: Element;
|
13 |
previousStep?: DriveStep;
|
14 |
|
15 |
popover?: PopoverDOM;
|
16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
__activeOnDestroyed?: Element;
|
18 |
__resizeTimeout?: number;
|
19 |
__transitionCallback?: () => void;
|
|
|
8 |
activeIndex?: number;
|
9 |
activeElement?: Element;
|
10 |
activeStep?: DriveStep;
|
|
|
11 |
previousElement?: Element;
|
12 |
previousStep?: DriveStep;
|
13 |
|
14 |
popover?: PopoverDOM;
|
15 |
|
16 |
+
// actual values considering the animation
|
17 |
+
// and delays. These are used to determine
|
18 |
+
// the positions etc.
|
19 |
+
__previousElement?: Element;
|
20 |
+
__activeElement?: Element;
|
21 |
+
__previousStep?: DriveStep;
|
22 |
+
__activeStep?: DriveStep;
|
23 |
+
|
24 |
__activeOnDestroyed?: Element;
|
25 |
__resizeTimeout?: number;
|
26 |
__transitionCallback?: () => void;
|