MCPcopy
hub / github.com/nilbuild/driver.js / destroy

Function destroy

src/driver.ts:317–375  ·  view source on GitHub ↗
(withOnDestroyStartedHook = true)

Source from the content-addressed store, hash-verified

315 }
316
317 function destroy(withOnDestroyStartedHook = true) {
318 const activeElement = getState("__activeElement");
319 const activeStep = getState("__activeStep");
320
321 const activeOnDestroyed = getState("__activeOnDestroyed");
322
323 const onDestroyStarted = getConfig("onDestroyStarted");
324 // `onDestroyStarted` is used to confirm the exit of tour. If we trigger
325 // the hook for when user calls `destroy`, driver will get into infinite loop
326 // not causing tour to be destroyed.
327 if (withOnDestroyStartedHook && onDestroyStarted) {
328 const isActiveDummyElement = !activeElement || activeElement?.id === "driver-dummy-element";
329 onDestroyStarted(isActiveDummyElement ? undefined : activeElement, activeStep!, {
330 config: getConfig(),
331 state: getState(),
332 driver: getCurrentDriver(),
333 });
334 return;
335 }
336
337 const onDeselected = activeStep?.onDeselected || getConfig("onDeselected");
338 const onDestroyed = getConfig("onDestroyed");
339
340 document.body.classList.remove("driver-active", "driver-fade", "driver-simple", "driver-no-scroll");
341 document.body.style.removeProperty("--driver-animation-duration");
342
343 destroyEvents();
344 destroyPopover();
345 destroyHighlight();
346 destroyOverlay();
347 destroyEmitter();
348
349 const stateBeforeDestroy = getState();
350
351 resetState();
352
353 if (activeElement && activeStep) {
354 const isActiveDummyElement = activeElement.id === "driver-dummy-element";
355 if (onDeselected) {
356 onDeselected(isActiveDummyElement ? undefined : activeElement, activeStep, {
357 config: getConfig(),
358 state: stateBeforeDestroy,
359 driver: getCurrentDriver(),
360 });
361 }
362
363 if (onDestroyed) {
364 onDestroyed(isActiveDummyElement ? undefined : activeElement, activeStep, {
365 config: getConfig(),
366 state: stateBeforeDestroy,
367 driver: getCurrentDriver(),
368 });
369 }
370 }
371
372 if (activeOnDestroyed) {
373 (activeOnDestroyed as HTMLElement).focus();
374 }

Callers 7

handleCloseFunction · 0.85
handleOverlayClickFunction · 0.85
moveNextFunction · 0.85
movePreviousFunction · 0.85
moveToFunction · 0.85
driveFunction · 0.85
driverFunction · 0.85

Calls 9

getStateFunction · 0.90
getConfigFunction · 0.90
getCurrentDriverFunction · 0.90
destroyEventsFunction · 0.90
destroyPopoverFunction · 0.90
destroyHighlightFunction · 0.90
destroyOverlayFunction · 0.90
destroyEmitterFunction · 0.90
resetStateFunction · 0.90

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…