Add overlay click to close
Browse files- src/driver.ts +7 -3
- src/hooks.ts +15 -0
- src/stage.ts +2 -2
src/driver.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
| 1 |
-
import { initEvents, destroyEvents } from "./events";
|
| 2 |
-
import { destroyHighlight, highlight } from "./highlight";
|
| 3 |
import { destroyStage } from "./stage";
|
| 4 |
-
import {
|
|
|
|
|
|
|
| 5 |
|
| 6 |
import "./style.css";
|
|
|
|
| 7 |
|
| 8 |
export type DriveStep = {
|
| 9 |
element?: string | Element;
|
|
@@ -21,6 +22,8 @@ export function driver(options: Config = {}) {
|
|
| 21 |
);
|
| 22 |
|
| 23 |
initEvents();
|
|
|
|
|
|
|
| 24 |
}
|
| 25 |
|
| 26 |
function destroy() {
|
|
@@ -32,6 +35,7 @@ export function driver(options: Config = {}) {
|
|
| 32 |
destroyEvents();
|
| 33 |
destroyHighlight();
|
| 34 |
destroyStage();
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
return {
|
|
|
|
|
|
|
|
|
|
| 1 |
import { destroyStage } from "./stage";
|
| 2 |
+
import { destroyEvents, initEvents } from "./events";
|
| 3 |
+
import { Config, configure, getConfig } from "./config";
|
| 4 |
+
import { destroyHighlight, highlight } from "./highlight";
|
| 5 |
|
| 6 |
import "./style.css";
|
| 7 |
+
import { destroyHooks, register } from "./hooks";
|
| 8 |
|
| 9 |
export type DriveStep = {
|
| 10 |
element?: string | Element;
|
|
|
|
| 22 |
);
|
| 23 |
|
| 24 |
initEvents();
|
| 25 |
+
|
| 26 |
+
register("overlayClick", destroy);
|
| 27 |
}
|
| 28 |
|
| 29 |
function destroy() {
|
|
|
|
| 35 |
destroyEvents();
|
| 36 |
destroyHighlight();
|
| 37 |
destroyStage();
|
| 38 |
+
destroyHooks();
|
| 39 |
}
|
| 40 |
|
| 41 |
return {
|
src/hooks.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
type allowedHooks = "overlayClick";
|
| 2 |
+
|
| 3 |
+
let registeredHooks: Partial<{ [key in allowedHooks]: () => void }> = {};
|
| 4 |
+
|
| 5 |
+
export function register(hook: allowedHooks, callback: () => void) {
|
| 6 |
+
registeredHooks[hook] = callback;
|
| 7 |
+
}
|
| 8 |
+
|
| 9 |
+
export function trigger(hook: allowedHooks) {
|
| 10 |
+
registeredHooks[hook]?.();
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
export function destroyHooks() {
|
| 14 |
+
registeredHooks = {};
|
| 15 |
+
}
|
src/stage.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
import { easeInOutQuad } from "./math";
|
| 2 |
import { onDriverClick } from "./events";
|
|
|
|
| 3 |
|
| 4 |
export type StageDefinition = {
|
| 5 |
x: number;
|
|
@@ -98,7 +99,6 @@ export function refreshStage() {
|
|
| 98 |
|
| 99 |
function mountStage(stagePosition: StageDefinition) {
|
| 100 |
stageSvg = createStageSvg(stagePosition);
|
| 101 |
-
|
| 102 |
document.body.appendChild(stageSvg);
|
| 103 |
|
| 104 |
onDriverClick(stageSvg, e => {
|
|
@@ -107,7 +107,7 @@ function mountStage(stagePosition: StageDefinition) {
|
|
| 107 |
return;
|
| 108 |
}
|
| 109 |
|
| 110 |
-
|
| 111 |
});
|
| 112 |
}
|
| 113 |
|
|
|
|
| 1 |
import { easeInOutQuad } from "./math";
|
| 2 |
import { onDriverClick } from "./events";
|
| 3 |
+
import { trigger } from "./hooks";
|
| 4 |
|
| 5 |
export type StageDefinition = {
|
| 6 |
x: number;
|
|
|
|
| 99 |
|
| 100 |
function mountStage(stagePosition: StageDefinition) {
|
| 101 |
stageSvg = createStageSvg(stagePosition);
|
|
|
|
| 102 |
document.body.appendChild(stageSvg);
|
| 103 |
|
| 104 |
onDriverClick(stageSvg, e => {
|
|
|
|
| 107 |
return;
|
| 108 |
}
|
| 109 |
|
| 110 |
+
trigger("overlayClick");
|
| 111 |
});
|
| 112 |
}
|
| 113 |
|