@plexui/vue 0.39.2 → 0.39.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/components/Dialog/Dialog.js +4 -1
- package/dist/es/components/Dialog/Dialog.js.map +1 -1
- package/dist/es/components/Menu/Menu.js +4 -1
- package/dist/es/components/Menu/Menu.js.map +1 -1
- package/dist/es/lib/holdEnteringPresses.js +68 -0
- package/dist/es/lib/holdEnteringPresses.js.map +1 -0
- package/dist/types/lib/holdEnteringPresses.d.ts +11 -0
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sheet, dialog or menu takes no touch while it comes in, as on iOS: a second tap that starts during the enter
|
|
3
|
+
* lands on what rises under the finger, so a double tap on a row opened a sheet and a second one over it, and a
|
|
4
|
+
* double tap on a menu button chose the first item (console 16.11). A touch that starts while a marked root still
|
|
5
|
+
* carries `data-entering` is held whole: its pointerdown, its pointerup and the click that follows. A press already
|
|
6
|
+
* under way when the root mounts (the one that opened it), a mouse or a pen (a quick second click toggles a menu
|
|
7
|
+
* on a desktop) and a key's click are left alone.
|
|
8
|
+
*/
|
|
9
|
+
export const HOLD_PRESSES_CLASS = "plexui-hold-presses";
|
|
10
|
+
const ENTERING = `.${HOLD_PRESSES_CLASS}[data-entering]`;
|
|
11
|
+
// The click of a held touch may come a moment after its pointerup
|
|
12
|
+
const CLICK_WINDOW = 500;
|
|
13
|
+
const installed = new WeakMap();
|
|
14
|
+
/** Installs the hold on a window once; returns the function that removes it. */
|
|
15
|
+
export function holdEnteringPresses(view = typeof window === "undefined" ? undefined : window) {
|
|
16
|
+
if (!view)
|
|
17
|
+
return () => { };
|
|
18
|
+
const existing = installed.get(view);
|
|
19
|
+
if (existing)
|
|
20
|
+
return existing;
|
|
21
|
+
const held = new Set();
|
|
22
|
+
let eatClick = false;
|
|
23
|
+
let clickTimer;
|
|
24
|
+
const stop = (event) => {
|
|
25
|
+
event.stopImmediatePropagation();
|
|
26
|
+
if (event.cancelable)
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
};
|
|
29
|
+
const onDown = (event) => {
|
|
30
|
+
eatClick = false;
|
|
31
|
+
if (event.pointerType !== "touch" || !view.document.querySelector(ENTERING))
|
|
32
|
+
return;
|
|
33
|
+
held.add(event.pointerId);
|
|
34
|
+
stop(event);
|
|
35
|
+
};
|
|
36
|
+
const onRelease = (event) => {
|
|
37
|
+
if (!held.delete(event.pointerId))
|
|
38
|
+
return;
|
|
39
|
+
stop(event);
|
|
40
|
+
if (event.type !== "pointerup")
|
|
41
|
+
return;
|
|
42
|
+
eatClick = true;
|
|
43
|
+
clearTimeout(clickTimer);
|
|
44
|
+
clickTimer = setTimeout(() => { eatClick = false; }, CLICK_WINDOW);
|
|
45
|
+
};
|
|
46
|
+
// Only the touch's own click: a key or an assistive click (detail 0) still acts
|
|
47
|
+
const onClick = (event) => {
|
|
48
|
+
if (!eatClick || !event.detail)
|
|
49
|
+
return;
|
|
50
|
+
eatClick = false;
|
|
51
|
+
stop(event);
|
|
52
|
+
};
|
|
53
|
+
view.addEventListener("pointerdown", onDown, true);
|
|
54
|
+
view.addEventListener("pointerup", onRelease, true);
|
|
55
|
+
view.addEventListener("pointercancel", onRelease, true);
|
|
56
|
+
view.addEventListener("click", onClick, true);
|
|
57
|
+
const dispose = () => {
|
|
58
|
+
view.removeEventListener("pointerdown", onDown, true);
|
|
59
|
+
view.removeEventListener("pointerup", onRelease, true);
|
|
60
|
+
view.removeEventListener("pointercancel", onRelease, true);
|
|
61
|
+
view.removeEventListener("click", onClick, true);
|
|
62
|
+
clearTimeout(clickTimer);
|
|
63
|
+
installed.delete(view);
|
|
64
|
+
};
|
|
65
|
+
installed.set(view, dispose);
|
|
66
|
+
return dispose;
|
|
67
|
+
}
|
|
68
|
+
//# sourceMappingURL=holdEnteringPresses.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"holdEnteringPresses.js","sourceR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AC,CAAA;QACxB,SAAS,CAAC,MAAM,CAAC,IAAI,CAAC,CAAA;IACxB,CAAC,CAAA;IACD,SAAS,CAAC,GAAG,CAAC,IAAI,EAAE,OAAO,CAAC,CAAA;IAC5B,OAAO,OAAO,CAAA;AAChB,CAAC","sourcesContent":["/**\n * A sheet, dialog or menu takes no touch while it comes in, as on iOS: a second tap that starts during the enter\n * lands on what rises under the finger, so a double tap on a row opened a sheet and a second one over it, and a\n * double tap on a menu button chose the first item (console 16.11). A touch that starts while a marked root still\n * carries `data-entering` is held whole: its pointerdown, its pointerup and the click that follows. A press already\n * under way when the root mounts (the one that opened it), a mouse or a pen (a quick second click toggles a menu\n * on a desktop) and a key's click are left alone.\n */\nexport const HOLD_PRESSES_CLASS = \"plexui-hold-presses\"\n\nconst ENTERING = `.${HOLD_PRESSES_CLASS}[data-entering]`\n// The click of a held touch may come a moment after its pointerup\nconst CLICK_WINDOW = 500\n\nconst installed = new WeakMap<Window, () => void>()\n\n/** Installs the hold on a window once; returns the function that removes it. */\nexport function holdEnteringPresses(view: Window | undefined = typeof window === \"undefined\" ? undefined : window) {\n if (!view) return () => {}\n const existing = installed.get(view)\n if (existing) return existing\n const held = new Set<number>()\n let eatClick = false\n let clickTimer: ReturnType<typeof setTimeout> | undefined\n const stop = (event: Event) => {\n event.stopImmediatePropagation()\n if (event.cancelable) event.preventDefault()\n }\n const onDown = (event: PointerEvent) => {\n eatClick = false\n if (event.pointerType !== \"touch\" || !view.document.querySelector(ENTERING)) return\n held.add(event.pointerId)\n stop(event)\n }\n const onRelease = (event: PointerEvent) => {\n if (!held.delete(event.pointerId)) return\n stop(event)\n if (event.type !== \"pointerup\") return\n eatClick = true\n clearTimeout(clickTimer)\n clickTimer = setTimeout(() => { eatClick = false }, CLICK_WINDOW)\n }\n // Only the touch's own click: a key or an assistive click (detail 0) still acts\n const onClick = (event: MouseEvent) => {\n if (!eatClick || !event.detail) return\n eatClick = false\n stop(event)\n }\n view.addEventListener(\"pointerdown\", onDown, true)\n view.addEventListener(\"pointerup\", onRelease, true)\n view.addEventListener(\"pointercancel\", onRelease, true)\n view.addEventListener(\"click\", onClick, true)\n const dispose = () => {\n view.removeEventListener(\"pointerdown\", onDown, true)\n view.removeEventListener(\"pointerup\", onRelease, true)\n view.removeEventListener(\"pointercancel\", onRelease, true)\n view.removeEventListener(\"click\", onClick, true)\n clearTimeout(clickTimer)\n installed.delete(view)\n }\n installed.set(view, dispose)\n return dispose\n}\n"]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A sheet, dialog or menu takes no touch while it comes in, as on iOS: a second tap that starts during the enter
|
|
3
|
+
* lands on what rises under the finger, so a double tap on a row opened a sheet and a second one over it, and a
|
|
4
|
+
* double tap on a menu button chose the first item (console 16.11). A touch that starts while a marked root still
|
|
5
|
+
* carries `data-entering` is held whole: its pointerdown, its pointerup and the click that follows. A press already
|
|
6
|
+
* under way when the root mounts (the one that opened it), a mouse or a pen (a quick second click toggles a menu
|
|
7
|
+
* on a desktop) and a key's click are left alone.
|
|
8
|
+
*/
|
|
9
|
+
export declare const HOLD_PRESSES_CLASS = "plexui-hold-presses";
|
|
10
|
+
/** Installs the hold on a window once; returns the function that removes it. */
|
|
11
|
+
export declare function holdEnteringPresses(view?: Window | undefined): () => void;
|