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

Function onDriverClick

src/events.ts:81–113  ·  view source on GitHub ↗
(
  element: Element,
  listener: (pointer: MouseEvent | PointerEvent) => void,
  shouldPreventDefault?: (target: HTMLElement) => boolean
)

Source from the content-addressed store, hash-verified

79 * @param {(target: HTMLElement) => boolean} shouldPreventDefault Whether to prevent default action i.e. link clicks etc
80 */
81export function onDriverClick(
82 element: Element,
83 listener: (pointer: MouseEvent | PointerEvent) => void,
84 shouldPreventDefault?: (target: HTMLElement) => boolean
85) {
86 destroyDriverClick(element);
87
88 const handler = (e: MouseEvent | PointerEvent) => {
89 const target = e.target as HTMLElement;
90 if (!element.contains(target)) {
91 return;
92 }
93
94 if (!shouldPreventDefault || shouldPreventDefault(target)) {
95 e.preventDefault();
96 e.stopPropagation();
97 e.stopImmediatePropagation();
98 }
99
100 if (e.type === "click") {
101 listener?.(e);
102 }
103 };
104
105 // We want to be the absolute first one to hear about the event
106 const useCapture = true;
107
108 for (const type of DRIVER_CLICK_EVENTS) {
109 document.addEventListener(type, handler, useCapture);
110 }
111
112 driverClickHandlers.set(element, handler);
113}
114
115export function destroyDriverClick(element: Element) {
116 const handler = driverClickHandlers.get(element);

Callers 2

renderPopoverFunction · 0.90
mountOverlayFunction · 0.90

Calls 1

destroyDriverClickFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…