Fix: onDeselected not being called for dummy element
Browse files- src/config.ts +2 -0
- src/driver.ts +10 -10
- src/events.ts +6 -0
src/config.ts
CHANGED
|
@@ -9,6 +9,8 @@ export type Config = {
|
|
| 9 |
opacity?: number;
|
| 10 |
stagePadding?: number;
|
| 11 |
stageRadius?: number;
|
|
|
|
|
|
|
| 12 |
popoverOffset?: number;
|
| 13 |
showButtons?: AllowedButtons[];
|
| 14 |
|
|
|
|
| 9 |
opacity?: number;
|
| 10 |
stagePadding?: number;
|
| 11 |
stageRadius?: number;
|
| 12 |
+
allowKeyboardControl?: boolean;
|
| 13 |
+
|
| 14 |
popoverOffset?: number;
|
| 15 |
showButtons?: AllowedButtons[];
|
| 16 |
|
src/driver.ts
CHANGED
|
@@ -21,13 +21,6 @@ export function driver(options: Config = {}) {
|
|
| 21 |
return;
|
| 22 |
}
|
| 23 |
|
| 24 |
-
const activeStep = getState("activeStep");
|
| 25 |
-
const activeElement = getState("activeElement");
|
| 26 |
-
const onDeselected = getConfig("onDeselected");
|
| 27 |
-
if (activeStep && activeElement && onDeselected) {
|
| 28 |
-
onDeselected(activeElement.id === "driver-dummy-element" ? undefined : activeElement, activeStep);
|
| 29 |
-
}
|
| 30 |
-
|
| 31 |
destroy();
|
| 32 |
}
|
| 33 |
|
|
@@ -49,6 +42,9 @@ export function driver(options: Config = {}) {
|
|
| 49 |
const activeElement = getState("activeElement");
|
| 50 |
const activeStep = getState("activeStep");
|
| 51 |
|
|
|
|
|
|
|
|
|
|
| 52 |
document.body.classList.remove("driver-active", "driver-fade", "driver-simple");
|
| 53 |
|
| 54 |
destroyEvents();
|
|
@@ -59,11 +55,15 @@ export function driver(options: Config = {}) {
|
|
| 59 |
|
| 60 |
resetState();
|
| 61 |
|
| 62 |
-
|
| 63 |
-
if (onDestroyed && activeElement && activeStep) {
|
| 64 |
const isActiveDummyElement = activeElement.id === "driver-dummy-element";
|
|
|
|
|
|
|
|
|
|
| 65 |
|
| 66 |
-
onDestroyed
|
|
|
|
|
|
|
| 67 |
}
|
| 68 |
}
|
| 69 |
|
|
|
|
| 21 |
return;
|
| 22 |
}
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
destroy();
|
| 25 |
}
|
| 26 |
|
|
|
|
| 42 |
const activeElement = getState("activeElement");
|
| 43 |
const activeStep = getState("activeStep");
|
| 44 |
|
| 45 |
+
const onDeselected = getConfig("onDeselected");
|
| 46 |
+
const onDestroyed = getConfig("onDestroyed");
|
| 47 |
+
|
| 48 |
document.body.classList.remove("driver-active", "driver-fade", "driver-simple");
|
| 49 |
|
| 50 |
destroyEvents();
|
|
|
|
| 55 |
|
| 56 |
resetState();
|
| 57 |
|
| 58 |
+
if (activeElement && activeStep) {
|
|
|
|
| 59 |
const isActiveDummyElement = activeElement.id === "driver-dummy-element";
|
| 60 |
+
if (onDeselected) {
|
| 61 |
+
onDeselected(isActiveDummyElement ? undefined : activeElement, activeStep);
|
| 62 |
+
}
|
| 63 |
|
| 64 |
+
if (onDestroyed) {
|
| 65 |
+
onDestroyed(isActiveDummyElement ? undefined : activeElement, activeStep);
|
| 66 |
+
}
|
| 67 |
}
|
| 68 |
}
|
| 69 |
|
src/events.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
import { refreshActiveHighlight } from "./highlight";
|
| 2 |
import { emit } from "./emitter";
|
| 3 |
import { getState, setState } from "./state";
|
|
|
|
| 4 |
|
| 5 |
export function requireRefresh() {
|
| 6 |
const resizeTimeout = getState("resizeTimeout");
|
|
@@ -12,6 +13,11 @@ export function requireRefresh() {
|
|
| 12 |
}
|
| 13 |
|
| 14 |
function onKeyup(e: KeyboardEvent) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
if (e.key === "Escape") {
|
| 16 |
emit("escapePress");
|
| 17 |
}
|
|
|
|
| 1 |
import { refreshActiveHighlight } from "./highlight";
|
| 2 |
import { emit } from "./emitter";
|
| 3 |
import { getState, setState } from "./state";
|
| 4 |
+
import { getConfig } from "./config";
|
| 5 |
|
| 6 |
export function requireRefresh() {
|
| 7 |
const resizeTimeout = getState("resizeTimeout");
|
|
|
|
| 13 |
}
|
| 14 |
|
| 15 |
function onKeyup(e: KeyboardEvent) {
|
| 16 |
+
const allowKeyboardControl = getConfig("allowKeyboardControl") || true;
|
| 17 |
+
if (!allowKeyboardControl) {
|
| 18 |
+
return;
|
| 19 |
+
}
|
| 20 |
+
|
| 21 |
if (e.key === "Escape") {
|
| 22 |
emit("escapePress");
|
| 23 |
}
|