motion-dom 14.9.0 → 14.10.0

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.
@@ -1,3 +1,6 @@
1
+ import { secondsToMilliseconds } from 'motion-utils';
2
+ import { cancelFrame, frame } from '../../frameloop/frame.mjs';
3
+ import { time } from '../../frameloop/sync-time.mjs';
1
4
  import { bindToScope } from '../../scope/active.mjs';
2
5
  import { isHTMLElement } from '../../utils/is-html-element.mjs';
3
6
  import { isDragActive } from '../drag/state/is-active.mjs';
@@ -16,6 +19,18 @@ function isValidPressEvent(event) {
16
19
  return isPrimaryPointer(event) && !isDragActive();
17
20
  }
18
21
  const claimedPointerDownEvents = new WeakSet();
22
+ /**
23
+ * Max distance in px between consecutive presses of a `count` sequence.
24
+ * Android's `ViewConfiguration` double tap slop is 100dp.
25
+ */
26
+ const sequenceSlop = 100;
27
+ /**
28
+ * Max distance in px a pointer can move during a held press (`hold`
29
+ * pending, or `repeat`). Android's `ViewConfiguration` touch slop is 8dp.
30
+ */
31
+ const holdSlop = 8;
32
+ const exceeds = (a, b, max) => Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY) > max;
33
+ const preventDefault = (event) => event.preventDefault();
19
34
  /**
20
35
  * Create a press gesture.
21
36
  *
@@ -33,22 +48,110 @@ const claimedPointerDownEvents = new WeakSet();
33
48
  * to be focusable for this to work, whereas a press gesture will
34
49
  * make an element focusable by default.
35
50
  *
51
+ * `onPressStart` fires on the first pointer or key down, and can return
52
+ * a function to call when the press ends, or an object of handlers for
53
+ * this press:
54
+ *
55
+ * ```js
56
+ * press(button, () => ({
57
+ * onHold: (progress) => {},
58
+ * onComplete: (event, { success }) => {},
59
+ * }), { hold: 0.5 })
60
+ * ```
61
+ *
36
62
  * @public
37
63
  */
38
64
  function press(targetOrSelector, onPressStart, options = {}) {
39
65
  onPressStart = bindToScope(onPressStart);
40
66
  const [targets, eventOptions, cancelEvents] = setupGesture(targetOrSelector, options);
67
+ const sequences = new WeakMap();
41
68
  const startPress = (startEvent) => {
42
69
  const target = startEvent.currentTarget;
43
70
  if (!isValidPressEvent(startEvent))
44
71
  return;
45
72
  if (claimedPointerDownEvents.has(startEvent))
46
73
  return;
47
- isPressing.add(target);
48
74
  if (options.stopPropagation) {
49
75
  claimedPointerDownEvents.add(startEvent);
50
76
  }
51
- const onPressEnd = onPressStart(target, startEvent);
77
+ /**
78
+ * Options are read per press so they can be updated between presses.
79
+ */
80
+ const { count: presses = 1, countTimeout = 0.3, hold = 0, repeat, } = options;
81
+ const downTime = time.now();
82
+ const holdTime = secondsToMilliseconds(hold);
83
+ const timeout = secondsToMilliseconds(countTimeout);
84
+ let previous = sequences.get(target);
85
+ /**
86
+ * A press during a `count` sequence continues it. If it's too late
87
+ * or too far away, the sequence is cancelled and this press starts
88
+ * a new one.
89
+ */
90
+ if (previous?.expire(exceeds(previous.event, startEvent, sequenceSlop))) {
91
+ previous = undefined;
92
+ }
93
+ else if (previous) {
94
+ cancelFrame(previous.expire);
95
+ sequences.delete(target);
96
+ }
97
+ const count = previous ? previous.count + 1 : 1;
98
+ const isFinal = count >= presses;
99
+ const isHeld = isFinal && (hold || repeat);
100
+ let isActive = !hold;
101
+ let repeats = 0;
102
+ let handlers;
103
+ isPressing.add(target);
104
+ if (previous) {
105
+ handlers = previous.handlers;
106
+ }
107
+ else {
108
+ const result = onPressStart(target, startEvent);
109
+ handlers =
110
+ typeof result === "function"
111
+ ? { onComplete: result }
112
+ : result || {};
113
+ }
114
+ isFinal && isActive && handlers.onActive?.();
115
+ /**
116
+ * While held, `onHold` reports progress from 0 to 1 over `hold`,
117
+ * then over each `repeat`. Each cycle reports exactly 1 at its end,
118
+ * then 0 on the next frame.
119
+ */
120
+ const repeatTime = secondsToMilliseconds(repeat);
121
+ let length = holdTime || repeatTime;
122
+ let cycleEnd = downTime + length;
123
+ let isCycleStart = true;
124
+ const tick = () => {
125
+ if (eventOptions.signal.aborted)
126
+ return cancelFrame(tick);
127
+ let progress = Math.min(1 - (cycleEnd - time.now()) / length, 1);
128
+ /**
129
+ * The frame after a boundary reports 0, so each cycle visibly
130
+ * restarts. Boundaries are timed from `downTime`, so this
131
+ * doesn't delay the next one. If a long frame has already
132
+ * passed the next boundary, it reports 1 instead.
133
+ */
134
+ if (isCycleStart && progress < 1)
135
+ progress = 0;
136
+ isCycleStart = false;
137
+ handlers.onHold?.(progress);
138
+ if (progress < 1)
139
+ return;
140
+ if (isActive) {
141
+ handlers.onRepeat?.(++repeats);
142
+ }
143
+ else {
144
+ isActive = true;
145
+ handlers.onActive?.();
146
+ }
147
+ if (repeat) {
148
+ isCycleStart = true;
149
+ cycleEnd += length = repeatTime;
150
+ }
151
+ else {
152
+ cancelFrame(tick);
153
+ }
154
+ };
52
155
  /**
53
156
  * End listeners run in the capture phase so a descendant calling
54
157
  * stopPropagation() in its own pointerup handler can't prevent the
@@ -59,14 +162,55 @@ function press(targetOrSelector, onPressStart, options = {}) {
59
162
  const onPointerEnd = (endEvent, success) => {
60
163
  window.removeEventListener("pointerup", onPointerUp, endEventOptions);
61
164
  window.removeEventListener("pointercancel", onPointerCancel, endEventOptions);
62
- if (isPressing.has(target)) {
63
- isPressing.delete(target);
64
- }
65
- if (!isValidPressEvent(endEvent)) {
165
+ window.removeEventListener("pointermove", onPointerMove, endEventOptions);
166
+ target.removeEventListener("contextmenu", preventDefault);
167
+ cancelFrame(tick);
168
+ isPressing.delete(target);
169
+ if (!isPrimaryPointer(endEvent))
66
170
  return;
171
+ /**
172
+ * A press that ends while a drag is active is a cancel.
173
+ */
174
+ if (isDragActive())
175
+ success = false;
176
+ if (success && !isFinal) {
177
+ /**
178
+ * Wait for the next press of the sequence, and cancel the
179
+ * gesture if it doesn't arrive in time.
180
+ */
181
+ const end = time.now();
182
+ /**
183
+ * Cancels the sequence if it's `force`d, or the interval
184
+ * has passed. Runs every frame, where `force` is frame
185
+ * data, so it's checked with `=== true`.
186
+ */
187
+ const expire = (force) => {
188
+ const isAborted = eventOptions.signal.aborted;
189
+ if (isAborted ||
190
+ force === true ||
191
+ time.now() - end > timeout) {
192
+ cancelFrame(expire);
193
+ sequences.delete(target);
194
+ isAborted ||
195
+ handlers.onComplete?.(endEvent, { success: false });
196
+ return true;
197
+ }
198
+ };
199
+ sequences.set(target, {
200
+ count,
201
+ event: startEvent,
202
+ handlers,
203
+ expire,
204
+ });
205
+ frame.update(expire, true);
67
206
  }
68
- if (typeof onPressEnd === "function") {
69
- onPressEnd(endEvent, { success });
207
+ else {
208
+ /**
209
+ * Releasing before `hold` is reached is a cancel.
210
+ */
211
+ handlers.onComplete?.(endEvent, {
212
+ success: success && isActive,
213
+ });
70
214
  }
71
215
  };
72
216
  const onPointerUp = (upEvent) => {
@@ -78,8 +222,35 @@ function press(targetOrSelector, onPressStart, options = {}) {
78
222
  const onPointerCancel = (cancelEvent) => {
79
223
  onPointerEnd(cancelEvent, false);
80
224
  };
225
+ /**
226
+ * Moving during a pending long press, or a repeating press, cancels
227
+ * it, so scrolling on touch devices doesn't trigger it. A drag
228
+ * starting during a `count` sequence cancels it.
229
+ */
230
+ const onPointerMove = (moveEvent) => {
231
+ if (isPrimaryPointer(moveEvent) &&
232
+ (((repeat || !isActive) &&
233
+ exceeds(startEvent, moveEvent, holdSlop)) ||
234
+ (presses > 1 && isDragActive()))) {
235
+ onPointerCancel(moveEvent);
236
+ }
237
+ };
81
238
  window.addEventListener("pointerup", onPointerUp, endEventOptions);
82
239
  window.addEventListener("pointercancel", onPointerCancel, endEventOptions);
240
+ if (isHeld || presses > 1) {
241
+ window.addEventListener("pointermove", onPointerMove, endEventOptions);
242
+ }
243
+ if (isHeld) {
244
+ frame.update(tick, true);
245
+ /**
246
+ * Touch devices open a context menu or callout on long press,
247
+ * which would cancel the gesture.
248
+ */
249
+ target.addEventListener("contextmenu", preventDefault, {
250
+ ...eventOptions,
251
+ passive: false,
252
+ });
253
+ }
83
254
  };
84
255
  targets.forEach((target) => {
85
256
  const pointerDownTarget = options.useGlobalTarget ? window : target;
@@ -1 +1 @@
1
- {"version":3,"file":"index.mjs","sources":["../../../../src/gestures/press/index.ts"],"sourcesContent":["import { bindToScope } from \"../../scope/active\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { ElementOrSelector } from \"../../utils/resolve-elements\"\nimport { isDragActive } from \"../drag/state/is-active\"\nimport { EventOptions } from \"../types\"\nimport { isNodeOrChild } from \"../utils/is-node-or-child\"\nimport { isPrimaryPointer } from \"../utils/is-primary-pointer\"\nimport { setupGesture } from \"../utils/setup\"\nimport { OnPressStartEvent } from \"./types\"\nimport { isElementKeyboardAccessible } from \"./utils/is-keyboard-accessible\"\nimport { enableKeyboardPress } from \"./utils/keyboard\"\nimport { isPressing } from \"./utils/state\"\n\n/**\n * Filter out events that are not primary pointer events, or are triggering\n * while a Motion gesture is active.\n */\nfunction isValidPressEvent(event: PointerEvent) {\n return isPrimaryPointer(event) && !isDragActive()\n}\n\nconst claimedPointerDownEvents = new WeakSet<Event>()\n\nexport interface PointerEventOptions extends EventOptions {\n useGlobalTarget?: boolean\n stopPropagation?: boolean\n}\n\n/**\n * Create a press gesture.\n *\n * Press is different to `\"pointerdown\"`, `\"pointerup\"` in that it\n * automatically filters out secondary pointer events like right\n * click and multitouch.\n *\n * It also adds accessibility support for keyboards, where\n * an element with a press gesture will receive focus and\n * trigger on Enter `\"keydown\"` and `\"keyup\"` events.\n *\n * This is different to a browser's `\"click\"` event, which does\n * respond to keyboards but only for the `\"click\"` itself, rather\n * than the press start and end/cancel. The element also needs\n * to be focusable for this to work, whereas a press gesture will\n * make an element focusable by default.\n *\n * @public\n */\nexport function press(\n targetOrSelector: ElementOrSelector,\n onPressStart: OnPressStartEvent,\n options: PointerEventOptions = {}\n): VoidFunction {\n onPressStart = bindToScope(onPressStart)\n\n const [targets, eventOptions, cancelEvents] = setupGesture(\n targetOrSelector,\n options\n )\n\n const startPress = (startEvent: PointerEvent) => {\n const target = startEvent.currentTarget as Element\n\n if (!isValidPressEvent(startEvent)) return\n if (claimedPointerDownEvents.has(startEvent)) return\n\n isPressing.add(target)\n\n if (options.stopPropagation) {\n claimedPointerDownEvents.add(startEvent)\n }\n\n const onPressEnd = onPressStart(target, startEvent)\n\n /**\n * End listeners run in the capture phase so a descendant calling\n * stopPropagation() in its own pointerup handler can't prevent the\n * press gesture from ending. This also keeps the gesture-end\n * ordering consistent with the drag gesture. See #2794.\n */\n const endEventOptions = { ...eventOptions, capture: true }\n\n const onPointerEnd = (endEvent: PointerEvent, success: boolean) => {\n window.removeEventListener(\n \"pointerup\",\n onPointerUp,\n endEventOptions\n )\n window.removeEventListener(\n \"pointercancel\",\n onPointerCancel,\n endEventOptions\n )\n\n if (isPressing.has(target)) {\n isPressing.delete(target)\n }\n\n if (!isValidPressEvent(endEvent)) {\n return\n }\n\n if (typeof onPressEnd === \"function\") {\n onPressEnd(endEvent, { success })\n }\n }\n\n const onPointerUp = (upEvent: PointerEvent) => {\n onPointerEnd(\n upEvent,\n (target as any) === window ||\n (target as any) === document ||\n options.useGlobalTarget ||\n isNodeOrChild(target, upEvent.target as Element)\n )\n }\n\n const onPointerCancel = (cancelEvent: PointerEvent) => {\n onPointerEnd(cancelEvent, false)\n }\n\n window.addEventListener(\"pointerup\", onPointerUp, endEventOptions)\n window.addEventListener(\n \"pointercancel\",\n onPointerCancel,\n endEventOptions\n )\n }\n\n targets.forEach((target: EventTarget) => {\n const pointerDownTarget = options.useGlobalTarget ? window : target\n pointerDownTarget.addEventListener(\n \"pointerdown\",\n startPress as EventListener,\n eventOptions\n )\n\n if (isHTMLElement(target)) {\n target.addEventListener(\n \"focus\",\n () => enableKeyboardPress(target, eventOptions),\n eventOptions\n )\n\n if (\n !isElementKeyboardAccessible(target) &&\n !target.hasAttribute(\"tabindex\")\n ) {\n target.tabIndex = 0\n }\n }\n })\n\n return cancelEvents\n}\n"],"names":[],"mappings":";;;;;;;;;;AAaA;;;AAGG;AACH,SAAS,iBAAiB,CAAC,KAAmB,EAAA;IAC1C,OAAO,gBAAgB,CA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AY;AACvB;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":["../../../../src/gestures/press/index.ts"],"sourcesContent":["import { secondsToMilliseconds } from \"motion-utils\"\nimport { cancelFrame, frame } from \"../../frameloop/frame\"\nimport { time } from \"../../frameloop/sync-time\"\nimport { bindToScope } from \"../../scope/active\"\nimport { isHTMLElement } from \"../../utils/is-html-element\"\nimport { ElementOrSelector } from \"../../utils/resolve-elements\"\nimport { isDragActive } from \"../drag/state/is-active\"\nimport { EventOptions } from \"../types\"\nimport { isNodeOrChild } from \"../utils/is-node-or-child\"\nimport { isPrimaryPointer } from \"../utils/is-primary-pointer\"\nimport { setupGesture } from \"../utils/setup\"\nimport { OnPressStartEvent, PressHandlers, PressOptions } from \"./types\"\nimport { isElementKeyboardAccessible } from \"./utils/is-keyboard-accessible\"\nimport { enableKeyboardPress } from \"./utils/keyboard\"\nimport { isPressing } from \"./utils/state\"\n\n/**\n * Filter out events that are not primary pointer events, or are triggering\n * while a Motion gesture is active.\n */\nfunction isValidPressEvent(event: PointerEvent) {\n return isPrimaryPointer(event) && !isDragActive()\n}\n\nconst claimedPointerDownEvents = new WeakSet<Event>()\n\n/**\n * Max distance in px between consecutive presses of a `count` sequence.\n * Android's `ViewConfiguration` double tap slop is 100dp.\n */\nconst sequenceSlop = 100\n\n/**\n * Max distance in px a pointer can move during a held press (`hold`\n * pending, or `repeat`). Android's `ViewConfiguration` touch slop is 8dp.\n */\nconst holdSlop = 8\n\nconst exceeds = (a: PointerEvent, b: PointerEvent, max: number) =>\n Math.hypot(a.clientX - b.clientX, a.clientY - b.clientY) > max\n\nconst preventDefault = (event: Event) => event.preventDefault()\n\n/**\n * A `count` sequence waiting for its next press.\n */\ninterface PressSequence {\n count: number\n event: PointerEvent\n handlers: PressHandlers\n expire: (force?: unknown) => true | void\n}\n\nexport interface PointerEventOptions extends EventOptions, PressOptions {\n useGlobalTarget?: boolean\n stopPropagation?: boolean\n}\n\n/**\n * Create a press gesture.\n *\n * Press is different to `\"pointerdown\"`, `\"pointerup\"` in that it\n * automatically filters out secondary pointer events like right\n * click and multitouch.\n *\n * It also adds accessibility support for keyboards, where\n * an element with a press gesture will receive focus and\n * trigger on Enter `\"keydown\"` and `\"keyup\"` events.\n *\n * This is different to a browser's `\"click\"` event, which does\n * respond to keyboards but only for the `\"click\"` itself, rather\n * than the press start and end/cancel. The element also needs\n * to be focusable for this to work, whereas a press gesture will\n * make an element focusable by default.\n *\n * `onPressStart` fires on the first pointer or key down, and can return\n * a function to call when the press ends, or an object of handlers for\n * this press:\n *\n * ```js\n * press(button, () => ({\n * onHold: (progress) => {},\n * onComplete: (event, { success }) => {},\n * }), { hold: 0.5 })\n * ```\n *\n * @public\n */\nexport function press(\n targetOrSelector: ElementOrSelector,\n onPressStart: OnPressStartEvent,\n options: PointerEventOptions = {}\n): VoidFunction {\n onPressStart = bindToScope(onPressStart)\n\n const [targets, eventOptions, cancelEvents] = setupGesture(\n targetOrSelector,\n options\n )\n\n const sequences = new WeakMap<Element, PressSequence>()\n\n const startPress = (startEvent: PointerEvent) => {\n const target = startEvent.currentTarget as Element\n\n if (!isValidPressEvent(startEvent)) return\n if (claimedPointerDownEvents.has(startEvent)) return\n\n if (options.stopPropagation) {\n claimedPointerDownEvents.add(startEvent)\n }\n\n /**\n * Options are read per press so they can be updated between presses.\n */\n const {\n count: presses = 1,\n countTimeout = 0.3,\n hold = 0,\n repeat,\n } = options\n const downTime = time.now()\n const holdTime = secondsToMilliseconds(hold)\n const timeout = secondsToMilliseconds(countTimeout)\n let previous = sequences.get(target)\n\n /**\n * A press during a `count` sequence continues it. If it's too late\n * or too far away, the sequence is cancelled and this press starts\n * a new one.\n */\n if (\n previous?.expire(exceeds(previous.event, startEvent, sequenceSlop))\n ) {\n previous = undefined\n } else if (previous) {\n cancelFrame(previous.expire)\n sequences.delete(target)\n }\n\n const count = previous ? previous.count + 1 : 1\n const isFinal = count >= presses\n const isHeld = isFinal && (hold || repeat)\n let isActive = !hold\n let repeats = 0\n let handlers: PressHandlers\n\n isPressing.add(target)\n\n if (previous) {\n handlers = previous.handlers\n } else {\n const result = onPressStart(target, startEvent)\n handlers =\n typeof result === \"function\"\n ? { onComplete: result }\n : result || {}\n }\n\n isFinal && isActive && handlers.onActive?.()\n\n /**\n * While held, `onHold` reports progress from 0 to 1 over `hold`,\n * then over each `repeat`. Each cycle reports exactly 1 at its end,\n * then 0 on the next frame.\n */\n const repeatTime = secondsToMilliseconds(repeat!)\n let length = holdTime || repeatTime\n let cycleEnd = downTime + length\n let isCycleStart = true\n\n const tick = () => {\n if (eventOptions.signal!.aborted) return cancelFrame(tick)\n\n let progress = Math.min(1 - (cycleEnd - time.now()) / length, 1)\n\n /**\n * The frame after a boundary reports 0, so each cycle visibly\n * restarts. Boundaries are timed from `downTime`, so this\n * doesn't delay the next one. If a long frame has already\n * passed the next boundary, it reports 1 instead.\n */\n if (isCycleStart && progress < 1) progress = 0\n isCycleStart = false\n handlers.onHold?.(progress)\n\n if (progress < 1) return\n\n if (isActive) {\n handlers.onRepeat?.(++repeats)\n } else {\n isActive = true\n handlers.onActive?.()\n }\n\n if (repeat) {\n isCycleStart = true\n cycleEnd += length = repeatTime\n } else {\n cancelFrame(tick)\n }\n }\n\n /**\n * End listeners run in the capture phase so a descendant calling\n * stopPropagation() in its own pointerup handler can't prevent the\n * press gesture from ending. This also keeps the gesture-end\n * ordering consistent with the drag gesture. See #2794.\n */\n const endEventOptions = { ...eventOptions, capture: true }\n\n const onPointerEnd = (endEvent: PointerEvent, success: boolean) => {\n window.removeEventListener(\n \"pointerup\",\n onPointerUp,\n endEventOptions\n )\n window.removeEventListener(\n \"pointercancel\",\n onPointerCancel,\n endEventOptions\n )\n window.removeEventListener(\n \"pointermove\",\n onPointerMove,\n endEventOptions\n )\n target.removeEventListener(\"contextmenu\", preventDefault)\n cancelFrame(tick)\n isPressing.delete(target)\n\n if (!isPrimaryPointer(endEvent)) return\n\n /**\n * A press that ends while a drag is active is a cancel.\n */\n if (isDragActive()) success = false\n\n if (success && !isFinal) {\n /**\n * Wait for the next press of the sequence, and cancel the\n * gesture if it doesn't arrive in time.\n */\n const end = time.now()\n\n /**\n * Cancels the sequence if it's `force`d, or the interval\n * has passed. Runs every frame, where `force` is frame\n * data, so it's checked with `=== true`.\n */\n const expire = (force?: unknown) => {\n const isAborted = eventOptions.signal!.aborted\n if (\n isAborted ||\n force === true ||\n time.now() - end > timeout\n ) {\n cancelFrame(expire)\n sequences.delete(target)\n isAborted ||\n handlers.onComplete?.(endEvent, { success: false })\n return true\n }\n }\n sequences.set(target, {\n count,\n event: startEvent,\n handlers,\n expire,\n })\n frame.update(expire, true)\n } else {\n /**\n * Releasing before `hold` is reached is a cancel.\n */\n handlers.onComplete?.(endEvent, {\n success: success && isActive,\n })\n }\n }\n\n const onPointerUp = (upEvent: PointerEvent) => {\n onPointerEnd(\n upEvent,\n (target as any) === window ||\n (target as any) === document ||\n options.useGlobalTarget ||\n isNodeOrChild(target, upEvent.target as Element)\n )\n }\n\n const onPointerCancel = (cancelEvent: PointerEvent) => {\n onPointerEnd(cancelEvent, false)\n }\n\n /**\n * Moving during a pending long press, or a repeating press, cancels\n * it, so scrolling on touch devices doesn't trigger it. A drag\n * starting during a `count` sequence cancels it.\n */\n const onPointerMove = (moveEvent: PointerEvent) => {\n if (\n isPrimaryPointer(moveEvent) &&\n (((repeat || !isActive) &&\n exceeds(startEvent, moveEvent, holdSlop)) ||\n (presses > 1 && isDragActive()))\n ) {\n onPointerCancel(moveEvent)\n }\n }\n\n window.addEventListener(\"pointerup\", onPointerUp, endEventOptions)\n window.addEventListener(\n \"pointercancel\",\n onPointerCancel,\n endEventOptions\n )\n\n if (isHeld || presses > 1) {\n window.addEventListener(\n \"pointermove\",\n onPointerMove,\n endEventOptions\n )\n }\n\n if (isHeld) {\n frame.update(tick, true)\n /**\n * Touch devices open a context menu or callout on long press,\n * which would cancel the gesture.\n */\n target.addEventListener(\"contextmenu\", preventDefault, {\n ...eventOptions,\n passive: false,\n })\n }\n }\n\n targets.forEach((target: EventTarget) => {\n const pointerDownTarget = options.useGlobalTarget ? window : target\n pointerDownTarget.addEventListener(\n \"pointerdown\",\n startPress as EventListener,\n eventOptions\n )\n\n if (isHTMLElement(target)) {\n target.addEventListener(\n \"focus\",\n () => enableKeyboardPress(target, eventOptions),\n eventOptions\n )\n\n if (\n !isElementKeyboardAccessible(target) &&\n !target.hasAttribute(\"tabindex\")\n ) {\n target.tabIndex = 0\n }\n }\n })\n\n return cancelEvents\n}\n"],"names":[],"mappings":";;;;;;;;;;;;;AAgBA;;;AAGG;AACH,SAAS,iBAAiB,CAAC,KAAmB,EAAA;IAC1C,OAAO,gBAAgB,CAAC,KAAK,CAAC,IAAI,CAAC,YAAY,EAAE;AACrD;AAEA,MAAM,wBAAwB,GAAG,IAAI,OAAO,EAAS;AAErD;;;AAGG;AACH,MAAM,YAAY,GAAG,GAAG;AAExB;;;AAGG;AACH,MAAM,QAAQ,GAAG,CAAC;AAElB,MAAM,OAAO,GAAG,CAAC,CAAe,EAAE,CAAe,EAAE,GAAW,KAC1D,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,EAAE,CAAC,CAAC,OAAO,GAAG,CAAC,CAAC,OAAO,CAAC,GAAG,GAAG;AAElE,MAAM,cAAc,GAAG,CAAC,KAAY,KAAK,KAAK,CAAC,cAAc,EAAE;AAiB/D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6BG;AACG,SAAU,KAAK,CACjB,gBAAmC,EACnC,YAA+B,EAC/B,UAA+B,EAAE,EAAA;AAEjC,IAAA,YAAY,GAAG,WAAW,CAAC,YAAY,CAAC;AAExC,IAAA,MAAM,CAAC,OAAO,EAAE,YAAY,EAAE,YAAY,CAAC,GAAG,YAAY,CACtD,gBAAgB,EAChB,OAAO,CACV;AAED,IAAA,MAAM,SAAS,GAAG,IAAI,OAAO,EAA0B;AAEvD,IAAA,MAAM,UAAU,GAAG,CAAC,UAAwB,KAAI;AAC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AgB,CACnB,eAAe,EACf,eAAe,EACf,eAAe,CAClB;AAED,QAAA,IAAI,MAAM,IAAI,OAAO,GAAG,CAAC,EAAE;YACvB,MAAM,CAAC,gBAAgB,CACnB,aAAa,EACb,aAAa,EACb,eAAe,CAClB;QACL;QAEA,IAAI,MAAM,EAAE;AACR,YAAA,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC;AACxB;;;AAGG;AACH,YAAA,MAAM,CAAC,gBAAgB,CAAC,aAAa,EAAE,cAAc,EAAE;AACnD,gBAAA,GAAG,YAAY;AACf,gBAAA,OAAO,EAAE,KAAK;AACjB,aAAA,CAAC;QACN;AACJ,IAAA,CAAC;AAED,IAAA,OAAO,CAAC,OAAO,CAAC,CAAC,MAAmB,KAAI;AACpC,QAAA,MAAM,iBAAiB,GAAG,OAAO,CAAC,eAAe,GAAG,MAAM,GAAG,MAAM;QACnE,iBAAiB,CAAC,gBAAgB,CAC9B,aAAa,EACb,UAA2B,EAC3B,YAAY,CACf;AAED,QAAA,IAAI,aAAa,CAAC,MAAM,CAAC,EAAE;AACvB,YAAA,MAAM,CAAC,gBAAgB,CACnB,OAAO,EACP,MAAM,mBAAmB,CAAC,MAAM,EAAE,YAAY,CAAC,EAC/C,YAAY,CACf;AAED,YAAA,IACI,CAAC,2BAA2B,CAAC,MAAM,CAAC;AACpC,gBAAA,CAAC,MAAM,CAAC,YAAY,CAAC,UAAU,CAAC,EAClC;AACE,gBAAA,MAAM,CAAC,QAAQ,GAAG,CAAC;YACvB;QACJ;AACJ,IAAA,CAAC,CAAC;AAEF,IAAA,OAAO,YAAY;AACvB;;;;"}
@@ -21,7 +21,7 @@ const enableKeyboardPress = (element, eventOptions) => {
21
21
  */
22
22
  let isKeyPressing = false;
23
23
  const handleKeydown = filterEvents(() => {
24
- if (isPressing.has(element))
24
+ if (isKeyPressing || isPressing.has(element))
25
25
  return;
26
26
  isKeyPressing = true;
27
27
  firePointerEvent(element, "down");
@@ -1 +1 @@
1
- {"version":3,"file":"keyboard.mjs","sources":["../../../../../src/gestures/press/utils/keyboard.ts"],"sourcesContent":["import { isPressing } from \"./state\"\n\n/**\n * Filter out events that are not \"Enter\" keys.\n */\nfunction filterEvents(callback: (event: KeyboardEvent) => void) {\n return (event: KeyboardEvent) => {\n if (event.key !== \"Enter\") return\n callback(event)\n }\n}\n\nfunction firePointerEvent(target: EventTarget, type: \"down\" | \"up\" | \"cancel\") {\n target.dispatchEvent(\n new PointerEvent(\"pointer\" + type, { isPrimary: true, bubbles: true })\n )\n}\n\nexport const enableKeyboardPress = (\n element: HTMLElement,\n eventOptions: AddEventListenerOptions\n) => {\n /**\n * Listeners are scoped to this focus and all released on blur, rather\n * than added per Enter press, so they can't accumulate and fire\n * duplicate pointerup/pointercancel events. See #3935.\n */\n let isKeyPressing = false\n\n const handleKeydown = filterEvents(() => {\n if (isPressing.has(element)) return\n isKeyPressing = true\n firePointerEvent(element, \"down\")\n })\n\n const handleKeyup = filterEvents(() => {\n if (!isKeyPressing) return\n isKeyPressing = false\n firePointerEvent(element, \"up\")\n })\n\n element.addEventListener(\"keydown\", handleKeydown, eventOptions)\n element.addEventListener(\"keyup\", handleKeyup, eventOptions)\n\n /**\n * On blur, remove the key listeners and cancel any keyboard press.\n */\n element.addEventListener(\n \"blur\",\n () => {\n element.removeEventListener(\"keydown\", handleKeydown)\n element.removeEventListener(\"keyup\", handleKeyup)\n if (isKeyPressing) firePointerEvent(element, \"cancel\")\n },\n { ...eventOptions, once: true }\n )\n}\n"],"names":[],"mappings":";;AAEA;;AAEG;AACH,SAAS,YAAY,CAAC,QAAwC,EAAA;IAC1D,OAAO,CAAC,KAAoB,KAAI;AAC5B,QAAA,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO;YAAE;QAC3B,QAAQ,CAAC,KAAK,CAAC;AACnB,IAAA,CAAC;AACL;AAEA,SAAS,gBAAgB,CAAC,MAAmB,EAAE,IAA8B,EAAA;IACzE,MAAM,CAAC,aAAa,CAChB,IAAI,YAAY,CAAC,SAAS,GAAG,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CACzE;AACL;MAEa,mBAAmB,GAAG,CAC/B,OAAoB,EACpB,YAAqC,KACrC;AACA;;;;AAIG;IACH,IAAI,aAAa,GAAG,KAAK;AAEzB,IAAA,MAAM,aAAa,GAAG,YAAY,CAAC,MAAK;AACpC,QAAA,IAAI,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE;QAC7B,aAAa,GAAG,IAAI;AACpB,QAAA,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;AACrC,IAAA,CAAC,CAAC;AAEF,IAAA,MAAM,WAAW,GAAG,YAAY,CAAC,MAAK;AAClC,QAAA,IAAI,CAAC,aAAa;YAAE;QACpB,aAAa,GAAG,KAAK;AACrB,QAAA,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC;AACnC,IAAA,CAAC,CAAC;IAEF,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,EAAE,YAAY,CAAC;IAChE,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC;AAE5D;;AAEG;AACH,IAAA,OAAO,CAAC,gBAAgB,CACpB,MAAM,EACN,MAAK;AACD,QAAA,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC;AACrD,QAAA,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC;AACjD,QAAA,IAAI,aAAa;AAAE,YAAA,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC1D,CAAC,EACD,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,CAClC;AACL;;;;"}
1
+ {"version":3,"file":"keyboard.mjs","sources":["../../../../../src/gestures/press/utils/keyboard.ts"],"sourcesContent":["import { isPressing } from \"./state\"\n\n/**\n * Filter out events that are not \"Enter\" keys.\n */\nfunction filterEvents(callback: (event: KeyboardEvent) => void) {\n return (event: KeyboardEvent) => {\n if (event.key !== \"Enter\") return\n callback(event)\n }\n}\n\nfunction firePointerEvent(target: EventTarget, type: \"down\" | \"up\" | \"cancel\") {\n target.dispatchEvent(\n new PointerEvent(\"pointer\" + type, { isPrimary: true, bubbles: true })\n )\n}\n\nexport const enableKeyboardPress = (\n element: HTMLElement,\n eventOptions: AddEventListenerOptions\n) => {\n /**\n * Listeners are scoped to this focus and all released on blur, rather\n * than added per Enter press, so they can't accumulate and fire\n * duplicate pointerup/pointercancel events. See #3935.\n */\n let isKeyPressing = false\n\n const handleKeydown = filterEvents(() => {\n if (isKeyPressing || isPressing.has(element)) return\n isKeyPressing = true\n firePointerEvent(element, \"down\")\n })\n\n const handleKeyup = filterEvents(() => {\n if (!isKeyPressing) return\n isKeyPressing = false\n firePointerEvent(element, \"up\")\n })\n\n element.addEventListener(\"keydown\", handleKeydown, eventOptions)\n element.addEventListener(\"keyup\", handleKeyup, eventOptions)\n\n /**\n * On blur, remove the key listeners and cancel any keyboard press.\n */\n element.addEventListener(\n \"blur\",\n () => {\n element.removeEventListener(\"keydown\", handleKeydown)\n element.removeEventListener(\"keyup\", handleKeyup)\n if (isKeyPressing) firePointerEvent(element, \"cancel\")\n },\n { ...eventOptions, once: true }\n )\n}\n"],"names":[],"mappings":";;AAEA;;AAEG;AACH,SAAS,YAAY,CAAC,QAAwC,EAAA;IAC1D,OAAO,CAAC,KAAoB,KAAI;AAC5B,QAAA,IAAI,KAAK,CAAC,GAAG,KAAK,OAAO;YAAE;QAC3B,QAAQ,CAAC,KAAK,CAAC;AACnB,IAAA,CAAC;AACL;AAEA,SAAS,gBAAgB,CAAC,MAAmB,EAAE,IAA8B,EAAA;IACzE,MAAM,CAAC,aAAa,CAChB,IAAI,YAAY,CAAC,SAAS,GAAG,IAAI,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CACzE;AACL;MAEa,mBAAmB,GAAG,CAC/B,OAAoB,EACpB,YAAqC,KACrC;AACA;;;;AAIG;IACH,IAAI,aAAa,GAAG,KAAK;AAEzB,IAAA,MAAM,aAAa,GAAG,YAAY,CAAC,MAAK;AACpC,QAAA,IAAI,aAAa,IAAI,UAAU,CAAC,GAAG,CAAC,OAAO,CAAC;YAAE;QAC9C,aAAa,GAAG,IAAI;AACpB,QAAA,gBAAgB,CAAC,OAAO,EAAE,MAAM,CAAC;AACrC,IAAA,CAAC,CAAC;AAEF,IAAA,MAAM,WAAW,GAAG,YAAY,CAAC,MAAK;AAClC,QAAA,IAAI,CAAC,aAAa;YAAE;QACpB,aAAa,GAAG,KAAK;AACrB,QAAA,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC;AACnC,IAAA,CAAC,CAAC;IAEF,OAAO,CAAC,gBAAgB,CAAC,SAAS,EAAE,aAAa,EAAE,YAAY,CAAC;IAChE,OAAO,CAAC,gBAAgB,CAAC,OAAO,EAAE,WAAW,EAAE,YAAY,CAAC;AAE5D;;AAEG;AACH,IAAA,OAAO,CAAC,gBAAgB,CACpB,MAAM,EACN,MAAK;AACD,QAAA,OAAO,CAAC,mBAAmB,CAAC,SAAS,EAAE,aAAa,CAAC;AACrD,QAAA,OAAO,CAAC,mBAAmB,CAAC,OAAO,EAAE,WAAW,CAAC;AACjD,QAAA,IAAI,aAAa;AAAE,YAAA,gBAAgB,CAAC,OAAO,EAAE,QAAQ,CAAC;IAC1D,CAAC,EACD,EAAE,GAAG,YAAY,EAAE,IAAI,EAAE,IAAI,EAAE,CAClC;AACL;;;;"}
@@ -1596,12 +1596,15 @@ function notifyLayoutUpdate(node) {
1596
1596
  let hasRelativeLayoutChanged = false;
1597
1597
  const relativeParent = node.getClosestProjectingParent();
1598
1598
  /**
1599
- * A snapshot resumed from another element is only relative to this
1600
- * node's relativeParent if it's a layoutRoot that contains both.
1599
+ * A snapshot from another element is only relative to this node's
1600
+ * relativeParent if it's a layoutRoot that contains both. A node can
1601
+ * hold one without resumeFrom, when the element it came from changed
1602
+ * layoutId but stayed mounted (see switchLayoutId), or a remix
1603
+ * layout exit cleared it (see markLayoutExit).
1601
1604
  */
1602
- if (!node.resumeFrom ||
1605
+ if (!isShared ||
1603
1606
  (relativeParent?.options.layoutRoot &&
1604
- node.resumeFrom.path.includes(relativeParent))) {
1607
+ node.resumeFrom?.path.includes(relativeParent))) {
1605
1608
  /**
1606
1609
  * If the relativeParent is itself resuming from a different element then
1607
1610
  * the relative snapshot is not relavent