Add highlighted hook
Browse files- src/highlight.ts +18 -12
src/highlight.ts
CHANGED
@@ -66,10 +66,18 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
66 |
// the popover immediately. Otherwise, we wait for the animation
|
67 |
// to finish before showing the popover.
|
68 |
const isFirstHighlight = !fromElement || fromElement === toElement;
|
|
|
|
|
69 |
const hasNoPreviousPopover = fromStep && !fromStep.popover;
|
70 |
-
const isNextOrPrevDummyElement = toElement.id === "driver-dummy-element" || fromElement.id === "driver-dummy-element";
|
71 |
|
72 |
-
const
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
73 |
let isPopoverRendered = false;
|
74 |
|
75 |
hidePopover();
|
@@ -98,7 +106,15 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
98 |
} else {
|
99 |
trackActiveElement(toElement);
|
100 |
|
|
|
|
|
|
|
|
|
101 |
setState("transitionCallback", undefined);
|
|
|
|
|
|
|
|
|
102 |
}
|
103 |
|
104 |
window.requestAnimationFrame(animate);
|
@@ -114,16 +130,6 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
|
|
114 |
|
115 |
fromElement.classList.remove("driver-active-element");
|
116 |
toElement.classList.add("driver-active-element");
|
117 |
-
|
118 |
-
// Keep track of the previous step so that we can
|
119 |
-
// animate the transition between the two steps.
|
120 |
-
setState("previousStep", fromStep);
|
121 |
-
setState("activeStep", toStep);
|
122 |
-
|
123 |
-
// Keep track of the previous element so that we can
|
124 |
-
// animate the transition between the two elements.
|
125 |
-
setState("previousElement", fromElement);
|
126 |
-
setState("activeElement", toElement);
|
127 |
}
|
128 |
|
129 |
export function destroyHighlight() {
|
|
|
66 |
// the popover immediately. Otherwise, we wait for the animation
|
67 |
// to finish before showing the popover.
|
68 |
const isFirstHighlight = !fromElement || fromElement === toElement;
|
69 |
+
const isToDummyElement = toElement.id === "driver-dummy-element";
|
70 |
+
const isFromDummyElement = fromElement.id === "driver-dummy-element";
|
71 |
const hasNoPreviousPopover = fromStep && !fromStep.popover;
|
|
|
72 |
|
73 |
+
const highlightStartedHook = getConfig("onHighlightStarted");
|
74 |
+
const highlightedHook = getConfig("onHighlighted");
|
75 |
+
|
76 |
+
if (!isToDummyElement && highlightStartedHook) {
|
77 |
+
highlightStartedHook(toElement, toStep);
|
78 |
+
}
|
79 |
+
|
80 |
+
const hasDelayedPopover = !isFirstHighlight && (hasNoPreviousPopover || isFromDummyElement || isToDummyElement);
|
81 |
let isPopoverRendered = false;
|
82 |
|
83 |
hidePopover();
|
|
|
106 |
} else {
|
107 |
trackActiveElement(toElement);
|
108 |
|
109 |
+
if (!isToDummyElement && highlightedHook) {
|
110 |
+
highlightedHook(toElement, toStep);
|
111 |
+
}
|
112 |
+
|
113 |
setState("transitionCallback", undefined);
|
114 |
+
setState("previousStep", fromStep);
|
115 |
+
setState("previousElement", fromElement);
|
116 |
+
setState("activeStep", toStep);
|
117 |
+
setState("activeElement", toElement);
|
118 |
}
|
119 |
|
120 |
window.requestAnimationFrame(animate);
|
|
|
130 |
|
131 |
fromElement.classList.remove("driver-active-element");
|
132 |
toElement.classList.add("driver-active-element");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
133 |
}
|
134 |
|
135 |
export function destroyHighlight() {
|