kamrify commited on
Commit
333d0df
·
1 Parent(s): 55c95d5

Add support for driver object in hooks

Browse files
docs/src/content/guides/configuration.mdx CHANGED
@@ -73,7 +73,7 @@ type Config = {
73
  // PopoverDOM is an object with references to
74
  // the popover DOM elements such as buttons
75
  // title, descriptions, body, container etc.
76
- onPopoverRender?: (popover: PopoverDOM, options: { config: Config; state: State }) => void;
77
 
78
  // Hooks to run before and after highlighting
79
  // each step. Each hook receives the following
@@ -82,9 +82,10 @@ type Config = {
82
  // - step: The step object configured for the step
83
  // - options.config: The current configuration options
84
  // - options.state: The current state of the driver
85
- onHighlightStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
86
- onHighlighted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
87
- onDeselected?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
 
88
 
89
  // Hooks to run before and after the driver
90
  // is destroyed. Each hook receives
@@ -93,8 +94,9 @@ type Config = {
93
  // - step: The step object configured for the currently active
94
  // - options.config: The current configuration options
95
  // - options.state: The current state of the driver
96
- onDestroyStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
97
- onDestroyed?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
 
98
 
99
  // Hooks to run on button clicks. Each hook receives
100
  // the following parameters:
@@ -102,9 +104,10 @@ type Config = {
102
  // - step: The step object configured for the step
103
  // - options.config: The current configuration options
104
  // - options.state: The current state of the driver
105
- onNextClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
106
- onPrevClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
107
- onCloseClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
 
108
  };
109
  ```
110
 
@@ -167,7 +170,7 @@ type Popover = {
167
  // Parameter is an object with references to
168
  // the popover DOM elements such as buttons
169
  // title, descriptions, body, etc.
170
- onPopoverRender?: (popover: PopoverDOM, options: { config: Config; state: State }) => void;
171
 
172
  // Callbacks for button clicks. You can use
173
  // these to add custom behavior to the buttons.
@@ -176,9 +179,10 @@ type Popover = {
176
  // - step: The step object configured for the step
177
  // - options.config: The current configuration options
178
  // - options.state: The current state of the driver
179
- onNextClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void
180
- onPrevClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void
181
- onCloseClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void
 
182
  }
183
  ```
184
 
@@ -208,9 +212,10 @@ type DriveStep = {
208
  // - step: The step object configured for the step
209
  // - options.config: The current configuration options
210
  // - options.state: The current state of the driver
211
- onDeselected?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
212
- onHighlightStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
213
- onHighlighted?: (element?: Element, step: DriveStep, options: { config: Config; state: State }) => void;
 
214
  }
215
  ```
216
 
 
73
  // PopoverDOM is an object with references to
74
  // the popover DOM elements such as buttons
75
  // title, descriptions, body, container etc.
76
+ onPopoverRender?: (popover: PopoverDOM, options: { config: Config; state: State, driver: Driver }) => void;
77
 
78
  // Hooks to run before and after highlighting
79
  // each step. Each hook receives the following
 
82
  // - step: The step object configured for the step
83
  // - options.config: The current configuration options
84
  // - options.state: The current state of the driver
85
+ // - options.driver: Current driver object
86
+ onHighlightStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
87
+ onHighlighted?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
88
+ onDeselected?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
89
 
90
  // Hooks to run before and after the driver
91
  // is destroyed. Each hook receives
 
94
  // - step: The step object configured for the currently active
95
  // - options.config: The current configuration options
96
  // - options.state: The current state of the driver
97
+ // - options.driver: Current driver object
98
+ onDestroyStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
99
+ onDestroyed?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
100
 
101
  // Hooks to run on button clicks. Each hook receives
102
  // the following parameters:
 
104
  // - step: The step object configured for the step
105
  // - options.config: The current configuration options
106
  // - options.state: The current state of the driver
107
+ // - options.driver: Current driver object
108
+ onNextClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
109
+ onPrevClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
110
+ onCloseClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
111
  };
112
  ```
113
 
 
170
  // Parameter is an object with references to
171
  // the popover DOM elements such as buttons
172
  // title, descriptions, body, etc.
173
+ onPopoverRender?: (popover: PopoverDOM, options: { config: Config; state: State, driver: Driver }) => void;
174
 
175
  // Callbacks for button clicks. You can use
176
  // these to add custom behavior to the buttons.
 
179
  // - step: The step object configured for the step
180
  // - options.config: The current configuration options
181
  // - options.state: The current state of the driver
182
+ // - options.driver: Current driver object
183
+ onNextClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void
184
+ onPrevClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void
185
+ onCloseClick?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void
186
  }
187
  ```
188
 
 
212
  // - step: The step object configured for the step
213
  // - options.config: The current configuration options
214
  // - options.state: The current state of the driver
215
+ // - options.driver: Current driver object
216
+ onDeselected?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
217
+ onHighlightStarted?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
218
+ onHighlighted?: (element?: Element, step: DriveStep, options: { config: Config; state: State, driver: Driver }) => void;
219
  }
220
  ```
221
 
index.html CHANGED
@@ -1,4 +1,4 @@
1
- <!DOCTYPE html>
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8" />
@@ -388,7 +388,7 @@ npm install driver.js</pre
388
  },
389
  },
390
  {
391
- element: '.buttons',
392
  popover: {
393
  title: "Buttons",
394
  description: "Here are some buttons",
@@ -468,13 +468,17 @@ npm install driver.js</pre
468
  disableActiveInteraction: true,
469
  showProgress: true,
470
  progressText: "{{current}} of {{total}} done",
471
- onPopoverRender: (popover) => {
472
- popover.title.innerHTML = `${driverObj.getActiveIndex()} ${driverObj.hasNextStep() ? 'Yes' : 'No'} ${driverObj.hasPreviousStep() ? 'Yes' : 'No'}`
473
- popover.description.innerHTML = `${driverObj.isFirstStep() ? 'Yes' : 'No'} ${driverObj.isLastStep() ? 'Yes' : 'No'}`
 
 
 
 
474
 
475
  console.log(driverObj.getActiveIndex());
476
  console.log(driverObj.getActiveStep());
477
- }
478
  });
479
 
480
  driverObj.drive(4);
@@ -491,16 +495,16 @@ npm install driver.js</pre
491
  {
492
  element: "h1",
493
  popover: {
494
- description: "This is a new description"
495
- }
496
  },
497
  {
498
  element: "p",
499
  popover: {
500
- description: "This is another new description"
501
- }
502
- }
503
- ])
504
 
505
  driverObj.drive();
506
  });
@@ -517,16 +521,16 @@ npm install driver.js</pre
517
  {
518
  element: "h1",
519
  popover: {
520
- description: "This is a new description"
521
- }
522
  },
523
  {
524
  element: "p",
525
  popover: {
526
- description: "This is another new description"
527
- }
528
- }
529
- ])
530
 
531
  driverObj.drive();
532
  });
@@ -624,7 +628,7 @@ npm install driver.js</pre
624
  document.getElementById("basic-tour").addEventListener("click", () => {
625
  const driverObj = driver({
626
  showProgress: true,
627
- showButtons: ["next", 'previous', 'close'],
628
  steps: basicTourSteps,
629
  });
630
 
@@ -667,6 +671,10 @@ npm install driver.js</pre
667
  title: "Next and Close",
668
  showButtons: ["close", "next"],
669
  description: "This one only has next and close buttons, nothing else.",
 
 
 
 
670
  },
671
  });
672
  });
@@ -835,10 +843,10 @@ npm install driver.js</pre
835
  driverObj.destroy();
836
  },
837
  steps: [
838
- { popover: { title: "Some title", description: "Some description" }},
839
- { popover: { title: "Another title", description: "Some description" }},
840
- { popover: { title: "Yet another title", description: "Some description" }},
841
- ]
842
  });
843
 
844
  driverObj.drive();
@@ -856,10 +864,10 @@ npm install driver.js</pre
856
  });
857
  },
858
  steps: [
859
- { popover: { title: "Some title", description: "Some description" }},
860
- { popover: { title: "Another title", description: "Some description" }},
861
- { popover: { title: "Yet another title", description: "Some description" }},
862
- ]
863
  });
864
 
865
  driverObj.drive();
@@ -1103,7 +1111,7 @@ npm install driver.js</pre
1103
  document.getElementById("click-overlay-to-next").addEventListener("click", () => {
1104
  const driverObj = driver({
1105
  animate: true,
1106
- overlayClickBehavior: 'nextStep',
1107
  steps: basicTourSteps,
1108
  });
1109
 
 
1
+ <!doctype html>
2
  <html lang="en">
3
  <head>
4
  <meta charset="UTF-8" />
 
388
  },
389
  },
390
  {
391
+ element: ".buttons",
392
  popover: {
393
  title: "Buttons",
394
  description: "Here are some buttons",
 
468
  disableActiveInteraction: true,
469
  showProgress: true,
470
  progressText: "{{current}} of {{total}} done",
471
+ onPopoverRender: popover => {
472
+ popover.title.innerHTML = `${driverObj.getActiveIndex()} ${driverObj.hasNextStep() ? "Yes" : "No"} ${
473
+ driverObj.hasPreviousStep() ? "Yes" : "No"
474
+ }`;
475
+ popover.description.innerHTML = `${driverObj.isFirstStep() ? "Yes" : "No"} ${
476
+ driverObj.isLastStep() ? "Yes" : "No"
477
+ }`;
478
 
479
  console.log(driverObj.getActiveIndex());
480
  console.log(driverObj.getActiveStep());
481
+ },
482
  });
483
 
484
  driverObj.drive(4);
 
495
  {
496
  element: "h1",
497
  popover: {
498
+ description: "This is a new description",
499
+ },
500
  },
501
  {
502
  element: "p",
503
  popover: {
504
+ description: "This is another new description",
505
+ },
506
+ },
507
+ ]);
508
 
509
  driverObj.drive();
510
  });
 
521
  {
522
  element: "h1",
523
  popover: {
524
+ description: "This is a new description",
525
+ },
526
  },
527
  {
528
  element: "p",
529
  popover: {
530
+ description: "This is another new description",
531
+ },
532
+ },
533
+ ]);
534
 
535
  driverObj.drive();
536
  });
 
628
  document.getElementById("basic-tour").addEventListener("click", () => {
629
  const driverObj = driver({
630
  showProgress: true,
631
+ showButtons: ["next", "previous", "close"],
632
  steps: basicTourSteps,
633
  });
634
 
 
671
  title: "Next and Close",
672
  showButtons: ["close", "next"],
673
  description: "This one only has next and close buttons, nothing else.",
674
+ onNextClick: (step, element, opts) => {
675
+ console.log("Next Clicked", step, element, opts);
676
+ opts.driver.destroy();
677
+ },
678
  },
679
  });
680
  });
 
843
  driverObj.destroy();
844
  },
845
  steps: [
846
+ { popover: { title: "Some title", description: "Some description" } },
847
+ { popover: { title: "Another title", description: "Some description" } },
848
+ { popover: { title: "Yet another title", description: "Some description" } },
849
+ ],
850
  });
851
 
852
  driverObj.drive();
 
864
  });
865
  },
866
  steps: [
867
+ { popover: { title: "Some title", description: "Some description" } },
868
+ { popover: { title: "Another title", description: "Some description" } },
869
+ { popover: { title: "Yet another title", description: "Some description" } },
870
+ ],
871
  });
872
 
873
  driverObj.drive();
 
1111
  document.getElementById("click-overlay-to-next").addEventListener("click", () => {
1112
  const driverObj = driver({
1113
  animate: true,
1114
+ overlayClickBehavior: "nextStep",
1115
  steps: basicTourSteps,
1116
  });
1117
 
src/config.ts CHANGED
@@ -1,8 +1,12 @@
1
- import { DriveStep } from "./driver";
2
  import { AllowedButtons, PopoverDOM } from "./popover";
3
  import { State } from "./state";
4
 
5
- export type DriverHook = (element: Element | undefined, step: DriveStep, opts: { config: Config; state: State }) => void;
 
 
 
 
6
 
7
  export type Config = {
8
  steps?: DriveStep[];
@@ -12,7 +16,7 @@ export type Config = {
12
  overlayOpacity?: number;
13
  smoothScroll?: boolean;
14
  allowClose?: boolean;
15
- overlayClickBehavior?: 'close' | 'nextStep';
16
  stagePadding?: number;
17
  stageRadius?: number;
18
 
@@ -50,12 +54,13 @@ export type Config = {
50
  };
51
 
52
  let currentConfig: Config = {};
 
53
 
54
  export function configure(config: Config = {}) {
55
  currentConfig = {
56
  animate: true,
57
  allowClose: true,
58
- overlayClickBehavior: 'close',
59
  overlayOpacity: 0.7,
60
  smoothScroll: false,
61
  disableActiveInteraction: false,
@@ -75,3 +80,11 @@ export function getConfig<K extends keyof Config>(key: K): Config[K];
75
  export function getConfig<K extends keyof Config>(key?: K) {
76
  return key ? currentConfig[key] : currentConfig;
77
  }
 
 
 
 
 
 
 
 
 
1
+ import { Driver, DriveStep } from "./driver";
2
  import { AllowedButtons, PopoverDOM } from "./popover";
3
  import { State } from "./state";
4
 
5
+ export type DriverHook = (
6
+ element: Element | undefined,
7
+ step: DriveStep,
8
+ opts: { config: Config; state: State; driver: Driver }
9
+ ) => void;
10
 
11
  export type Config = {
12
  steps?: DriveStep[];
 
16
  overlayOpacity?: number;
17
  smoothScroll?: boolean;
18
  allowClose?: boolean;
19
+ overlayClickBehavior?: "close" | "nextStep";
20
  stagePadding?: number;
21
  stageRadius?: number;
22
 
 
54
  };
55
 
56
  let currentConfig: Config = {};
57
+ let currentDriver: Driver;
58
 
59
  export function configure(config: Config = {}) {
60
  currentConfig = {
61
  animate: true,
62
  allowClose: true,
63
+ overlayClickBehavior: "close",
64
  overlayOpacity: 0.7,
65
  smoothScroll: false,
66
  disableActiveInteraction: false,
 
80
  export function getConfig<K extends keyof Config>(key?: K) {
81
  return key ? currentConfig[key] : currentConfig;
82
  }
83
+
84
+ export function setCurrentDriver(driver: Driver) {
85
+ currentDriver = driver;
86
+ }
87
+
88
+ export function getCurrentDriver() {
89
+ return currentDriver;
90
+ }
src/driver.ts CHANGED
@@ -1,7 +1,7 @@
1
  import { AllowedButtons, destroyPopover, Popover } from "./popover";
2
  import { destroyOverlay } from "./overlay";
3
  import { destroyEvents, initEvents, requireRefresh } from "./events";
4
- import { Config, configure, DriverHook, getConfig } from "./config";
5
  import { destroyHighlight, highlight } from "./highlight";
6
  import { destroyEmitter, listen } from "./emitter";
7
  import { getState, resetState, setState } from "./state";
@@ -16,7 +16,31 @@ export type DriveStep = {
16
  disableActiveInteraction?: boolean;
17
  };
18
 
19
- export function driver(options: Config = {}) {
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
  configure(options);
21
 
22
  function handleClose() {
@@ -103,6 +127,7 @@ export function driver(options: Config = {}) {
103
  return onPrevClick(activeElement, activeStep, {
104
  config: getConfig(),
105
  state: getState(),
 
106
  });
107
  }
108
 
@@ -127,6 +152,7 @@ export function driver(options: Config = {}) {
127
  return onNextClick(activeElement, activeStep, {
128
  config: getConfig(),
129
  state: getState(),
 
130
  });
131
  }
132
 
@@ -241,6 +267,7 @@ export function driver(options: Config = {}) {
241
  onDestroyStarted(isActiveDummyElement ? undefined : activeElement, activeStep!, {
242
  config: getConfig(),
243
  state: getState(),
 
244
  });
245
  return;
246
  }
@@ -264,6 +291,7 @@ export function driver(options: Config = {}) {
264
  onDeselected(isActiveDummyElement ? undefined : activeElement, activeStep, {
265
  config: getConfig(),
266
  state: getState(),
 
267
  });
268
  }
269
 
@@ -271,6 +299,7 @@ export function driver(options: Config = {}) {
271
  onDestroyed(isActiveDummyElement ? undefined : activeElement, activeStep, {
272
  config: getConfig(),
273
  state: getState(),
 
274
  });
275
  }
276
  }
@@ -280,7 +309,7 @@ export function driver(options: Config = {}) {
280
  }
281
  }
282
 
283
- return {
284
  isActive: () => getState("isInitialized") || false,
285
  refresh: requireRefresh,
286
  drive: (stepIndex: number = 0) => {
@@ -316,13 +345,13 @@ export function driver(options: Config = {}) {
316
  const steps = getConfig("steps") || [];
317
  const activeIndex = getState("activeIndex");
318
 
319
- return activeIndex !== undefined && steps[activeIndex + 1];
320
  },
321
  hasPreviousStep: () => {
322
  const steps = getConfig("steps") || [];
323
  const activeIndex = getState("activeIndex");
324
 
325
- return activeIndex !== undefined && steps[activeIndex - 1];
326
  },
327
  highlight: (step: DriveStep) => {
328
  init();
@@ -342,6 +371,8 @@ export function driver(options: Config = {}) {
342
  destroy(false);
343
  },
344
  };
345
- }
346
 
347
- export type Driver = ReturnType<typeof driver>;
 
 
 
 
1
  import { AllowedButtons, destroyPopover, Popover } from "./popover";
2
  import { destroyOverlay } from "./overlay";
3
  import { destroyEvents, initEvents, requireRefresh } from "./events";
4
+ import { Config, configure, DriverHook, getConfig, getCurrentDriver, setCurrentDriver } from "./config";
5
  import { destroyHighlight, highlight } from "./highlight";
6
  import { destroyEmitter, listen } from "./emitter";
7
  import { getState, resetState, setState } from "./state";
 
16
  disableActiveInteraction?: boolean;
17
  };
18
 
19
+ export interface Driver {
20
+ isActive: () => boolean;
21
+ refresh: () => void;
22
+ drive: (stepIndex?: number) => void;
23
+ setConfig: (config: Config) => void;
24
+ setSteps: (steps: DriveStep[]) => void;
25
+ getConfig: () => Config;
26
+ getState: (key?: string) => any;
27
+ getActiveIndex: () => number | undefined;
28
+ isFirstStep: () => boolean;
29
+ isLastStep: () => boolean;
30
+ getActiveStep: () => DriveStep | undefined;
31
+ getActiveElement: () => Element | undefined;
32
+ getPreviousElement: () => Element | undefined;
33
+ getPreviousStep: () => DriveStep | undefined;
34
+ moveNext: () => void;
35
+ movePrevious: () => void;
36
+ moveTo: (index: number) => void;
37
+ hasNextStep: () => boolean;
38
+ hasPreviousStep: () => boolean;
39
+ highlight: (step: DriveStep) => void;
40
+ destroy: () => void;
41
+ }
42
+
43
+ export function driver(options: Config = {}): Driver {
44
  configure(options);
45
 
46
  function handleClose() {
 
127
  return onPrevClick(activeElement, activeStep, {
128
  config: getConfig(),
129
  state: getState(),
130
+ driver: getCurrentDriver(),
131
  });
132
  }
133
 
 
152
  return onNextClick(activeElement, activeStep, {
153
  config: getConfig(),
154
  state: getState(),
155
+ driver: getCurrentDriver(),
156
  });
157
  }
158
 
 
267
  onDestroyStarted(isActiveDummyElement ? undefined : activeElement, activeStep!, {
268
  config: getConfig(),
269
  state: getState(),
270
+ driver: getCurrentDriver(),
271
  });
272
  return;
273
  }
 
291
  onDeselected(isActiveDummyElement ? undefined : activeElement, activeStep, {
292
  config: getConfig(),
293
  state: getState(),
294
+ driver: getCurrentDriver(),
295
  });
296
  }
297
 
 
299
  onDestroyed(isActiveDummyElement ? undefined : activeElement, activeStep, {
300
  config: getConfig(),
301
  state: getState(),
302
+ driver: getCurrentDriver(),
303
  });
304
  }
305
  }
 
309
  }
310
  }
311
 
312
+ const api: Driver = {
313
  isActive: () => getState("isInitialized") || false,
314
  refresh: requireRefresh,
315
  drive: (stepIndex: number = 0) => {
 
345
  const steps = getConfig("steps") || [];
346
  const activeIndex = getState("activeIndex");
347
 
348
+ return activeIndex !== undefined && !!steps[activeIndex + 1];
349
  },
350
  hasPreviousStep: () => {
351
  const steps = getConfig("steps") || [];
352
  const activeIndex = getState("activeIndex");
353
 
354
+ return activeIndex !== undefined && !!steps[activeIndex - 1];
355
  },
356
  highlight: (step: DriveStep) => {
357
  init();
 
371
  destroy(false);
372
  },
373
  };
 
374
 
375
+ setCurrentDriver(api);
376
+
377
+ return api;
378
+ }
src/highlight.ts CHANGED
@@ -1,6 +1,6 @@
1
  import { DriveStep } from "./driver";
2
  import { refreshOverlay, trackActiveElement, transitionStage } from "./overlay";
3
- import { getConfig } from "./config";
4
  import { hidePopover, renderPopover, repositionPopover } from "./popover";
5
  import { bringInView } from "./utils";
6
  import { getState, setState } from "./state";
@@ -56,7 +56,6 @@ export function refreshActiveHighlight() {
56
  repositionPopover(activeHighlight, activeStep);
57
  }
58
 
59
-
60
  function transferHighlight(toElement: Element, toStep: DriveStep) {
61
  const duration = 400;
62
  const start = Date.now();
@@ -83,6 +82,7 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
83
  deselectedHook(isFromDummyElement ? undefined : fromElement, fromStep!, {
84
  config,
85
  state,
 
86
  });
87
  }
88
 
@@ -90,6 +90,7 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
90
  highlightStartedHook(isToDummyElement ? undefined : toElement, toStep, {
91
  config,
92
  state,
 
93
  });
94
  }
95
 
@@ -131,6 +132,7 @@ function transferHighlight(toElement: Element, toStep: DriveStep) {
131
  highlightedHook(isToDummyElement ? undefined : toElement, toStep, {
132
  config: getConfig(),
133
  state: getState(),
 
134
  });
135
  }
136
 
 
1
  import { DriveStep } from "./driver";
2
  import { refreshOverlay, trackActiveElement, transitionStage } from "./overlay";
3
+ import { getConfig, getCurrentDriver } from "./config";
4
  import { hidePopover, renderPopover, repositionPopover } from "./popover";
5
  import { bringInView } from "./utils";
6
  import { getState, setState } from "./state";
 
56
  repositionPopover(activeHighlight, activeStep);
57
  }
58
 
 
59
  function transferHighlight(toElement: Element, toStep: DriveStep) {
60
  const duration = 400;
61
  const start = Date.now();
 
82
  deselectedHook(isFromDummyElement ? undefined : fromElement, fromStep!, {
83
  config,
84
  state,
85
+ driver: getCurrentDriver(),
86
  });
87
  }
88
 
 
90
  highlightStartedHook(isToDummyElement ? undefined : toElement, toStep, {
91
  config,
92
  state,
93
+ driver: getCurrentDriver(),
94
  });
95
  }
96
 
 
132
  highlightedHook(isToDummyElement ? undefined : toElement, toStep, {
133
  config: getConfig(),
134
  state: getState(),
135
+ driver: getCurrentDriver(),
136
  });
137
  }
138
 
src/popover.ts CHANGED
@@ -1,7 +1,7 @@
1
  import { bringInView, getFocusableElements } from "./utils";
2
- import { Config, DriverHook, getConfig } from "./config";
3
  import { getState, setState, State } from "./state";
4
- import { DriveStep } from "./driver";
5
  import { onDriverClick } from "./events";
6
  import { emit } from "./emitter";
7
 
@@ -28,7 +28,7 @@ export type Popover = {
28
  prevBtnText?: string;
29
 
30
  // Called after the popover is rendered
31
- onPopoverRender?: (popover: PopoverDOM, opts: { config: Config; state: State }) => void;
32
 
33
  // Button callbacks
34
  onNextClick?: DriverHook;
@@ -168,6 +168,7 @@ export function renderPopover(element: Element, step: DriveStep) {
168
  return onNextClick(element, step, {
169
  config: getConfig(),
170
  state: getState(),
 
171
  });
172
  } else {
173
  return emit("nextClick");
@@ -179,6 +180,7 @@ export function renderPopover(element: Element, step: DriveStep) {
179
  return onPrevClick(element, step, {
180
  config: getConfig(),
181
  state: getState(),
 
182
  });
183
  } else {
184
  return emit("prevClick");
@@ -190,6 +192,7 @@ export function renderPopover(element: Element, step: DriveStep) {
190
  return onCloseClick(element, step, {
191
  config: getConfig(),
192
  state: getState(),
 
193
  });
194
  } else {
195
  return emit("closeClick");
@@ -204,7 +207,7 @@ export function renderPopover(element: Element, step: DriveStep) {
204
  return (
205
  !popover?.description.contains(target) &&
206
  !popover?.title.contains(target) &&
207
- typeof target.className === 'string' &&
208
  target.className.includes("driver-popover")
209
  );
210
  }
@@ -217,6 +220,7 @@ export function renderPopover(element: Element, step: DriveStep) {
217
  onPopoverRender(popover, {
218
  config: getConfig(),
219
  state: getState(),
 
220
  });
221
  }
222
 
 
1
  import { bringInView, getFocusableElements } from "./utils";
2
+ import { Config, DriverHook, getConfig, getCurrentDriver } from "./config";
3
  import { getState, setState, State } from "./state";
4
+ import { Driver, DriveStep } from "./driver";
5
  import { onDriverClick } from "./events";
6
  import { emit } from "./emitter";
7
 
 
28
  prevBtnText?: string;
29
 
30
  // Called after the popover is rendered
31
+ onPopoverRender?: (popover: PopoverDOM, opts: { config: Config; state: State; driver: Driver }) => void;
32
 
33
  // Button callbacks
34
  onNextClick?: DriverHook;
 
168
  return onNextClick(element, step, {
169
  config: getConfig(),
170
  state: getState(),
171
+ driver: getCurrentDriver(),
172
  });
173
  } else {
174
  return emit("nextClick");
 
180
  return onPrevClick(element, step, {
181
  config: getConfig(),
182
  state: getState(),
183
+ driver: getCurrentDriver(),
184
  });
185
  } else {
186
  return emit("prevClick");
 
192
  return onCloseClick(element, step, {
193
  config: getConfig(),
194
  state: getState(),
195
+ driver: getCurrentDriver(),
196
  });
197
  } else {
198
  return emit("closeClick");
 
207
  return (
208
  !popover?.description.contains(target) &&
209
  !popover?.title.contains(target) &&
210
+ typeof target.className === "string" &&
211
  target.className.includes("driver-popover")
212
  );
213
  }
 
220
  onPopoverRender(popover, {
221
  config: getConfig(),
222
  state: getState(),
223
+ driver: getCurrentDriver(),
224
  });
225
  }
226