@astryxdesign/core 0.7.15-canary.gf890983 → 0.7.15

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.
Files changed (91) hide show
  1. package/CHANGELOG.md +72 -2
  2. package/dist/BottomSheet/BottomSheetPanel.d.ts.map +1 -1
  3. package/dist/BottomSheet/BottomSheetPanel.js +5 -4
  4. package/dist/CheckboxInput/CheckboxInput.d.ts.map +1 -1
  5. package/dist/CheckboxInput/CheckboxInput.js +10 -23
  6. package/dist/Item/Item.js +2 -2
  7. package/dist/Layer/useTouchTrigger.d.ts +12 -1
  8. package/dist/Layer/useTouchTrigger.d.ts.map +1 -1
  9. package/dist/Layer/useTouchTrigger.js +22 -3
  10. package/dist/Outline/useScrollSpy.d.ts.map +1 -1
  11. package/dist/Outline/useScrollSpy.js +22 -18
  12. package/dist/RadioList/RadioListItem.d.ts.map +1 -1
  13. package/dist/RadioList/RadioListItem.js +6 -32
  14. package/dist/Resizable/ResizeHandle.d.ts.map +1 -1
  15. package/dist/Resizable/ResizeHandle.js +5 -10
  16. package/dist/Resizable/useResizable.d.ts.map +1 -1
  17. package/dist/Resizable/useResizable.js +6 -5
  18. package/dist/Stepper/Step.js +8 -8
  19. package/dist/Table/plugins/sortable/useTableSortableState.d.ts.map +1 -1
  20. package/dist/Table/plugins/sortable/useTableSortableState.js +8 -4
  21. package/dist/Text/TruncationTooltip.d.ts.map +1 -1
  22. package/dist/Text/TruncationTooltip.js +10 -1
  23. package/dist/Toast/ToastViewport.d.ts.map +1 -1
  24. package/dist/Toast/ToastViewport.js +31 -6
  25. package/dist/Token/Token.js +2 -2
  26. package/dist/Tooltip/useTooltip.d.ts.map +1 -1
  27. package/dist/Tooltip/useTooltip.js +1 -1
  28. package/dist/TreeList/TreeListItem.js +2 -2
  29. package/dist/gestures/GestureHost.d.ts +38 -0
  30. package/dist/gestures/GestureHost.d.ts.map +1 -1
  31. package/dist/gestures/GestureHost.js +95 -1
  32. package/dist/gestures/contextRequest.d.ts +43 -0
  33. package/dist/gestures/contextRequest.d.ts.map +1 -0
  34. package/dist/gestures/contextRequest.js +167 -0
  35. package/dist/hooks/useClickableContainer.d.ts +1 -1
  36. package/dist/hooks/useClickableContainer.d.ts.map +1 -1
  37. package/dist/hooks/useClickableContainer.js +2 -2
  38. package/dist/hooks/useCommittedRef.d.ts +20 -0
  39. package/dist/hooks/useCommittedRef.d.ts.map +1 -0
  40. package/dist/hooks/useCommittedRef.js +38 -0
  41. package/dist/hooks/useMenuPress.d.ts.map +1 -1
  42. package/dist/hooks/useMenuPress.js +23 -27
  43. package/dist/i18n/generated-locales/en.generated.d.ts.map +1 -1
  44. package/dist/i18n/generated-locales/en.generated.js +2 -1
  45. package/dist/i18n/generated-locales/pseudo.generated.d.ts.map +1 -1
  46. package/dist/i18n/generated-locales/pseudo.generated.js +2 -1
  47. package/dist/internal/committed-ref.d.ts +15 -0
  48. package/dist/internal/committed-ref.d.ts.map +1 -0
  49. package/dist/internal/committed-ref.js +15 -0
  50. package/dist/internal/touch.d.ts +2 -1
  51. package/dist/internal/touch.d.ts.map +1 -1
  52. package/dist/internal/touch.js +1 -0
  53. package/dist/keyboard/keyboardHeight.d.ts.map +1 -1
  54. package/dist/keyboard/keyboardHeight.js +13 -9
  55. package/dist/keyboard/useMobileKeyboard.d.ts.map +1 -1
  56. package/dist/keyboard/useMobileKeyboard.js +8 -7
  57. package/dist/privateAttributes/press.stylex.d.ts +40 -10
  58. package/dist/privateAttributes/press.stylex.d.ts.map +1 -1
  59. package/dist/privateAttributes/press.stylex.js +46 -10
  60. package/locales/en.json +4 -0
  61. package/locales/pseudo.json +3 -0
  62. package/package.json +10 -5
  63. package/src/BottomSheet/BottomSheetPanel.tsx +5 -4
  64. package/src/CheckboxInput/CheckboxInput.tsx +20 -60
  65. package/src/Item/Item.tsx +2 -2
  66. package/src/Layer/useTouchTrigger.ts +30 -1
  67. package/src/Outline/useScrollSpy.ts +22 -22
  68. package/src/RadioList/RadioListItem.tsx +19 -79
  69. package/src/Resizable/ResizeHandle.tsx +5 -6
  70. package/src/Resizable/useResizable.ts +5 -5
  71. package/src/Stepper/Step.tsx +6 -6
  72. package/src/Stepper/Stepper.doc.mjs +8 -2
  73. package/src/Table/plugins/sortable/useTableSortableState.tsx +10 -4
  74. package/src/Text/TruncationTooltip.tsx +16 -1
  75. package/src/Toast/ToastViewport.tsx +31 -5
  76. package/src/Token/Token.tsx +2 -2
  77. package/src/Tooltip/useTooltip.tsx +1 -0
  78. package/src/TreeList/TreeListItem.tsx +2 -2
  79. package/src/gestures/GestureHost.ts +125 -1
  80. package/src/gestures/README.md +21 -0
  81. package/src/gestures/contextRequest.ts +206 -0
  82. package/src/hooks/useClickableContainer.ts +2 -2
  83. package/src/hooks/useCommittedRef.ts +39 -0
  84. package/src/hooks/useMenuPress.ts +59 -62
  85. package/src/i18n/generated-locales/en.generated.ts +1 -0
  86. package/src/i18n/generated-locales/pseudo.generated.ts +1 -0
  87. package/src/internal/committed-ref.ts +15 -0
  88. package/src/internal/touch.ts +3 -0
  89. package/src/keyboard/keyboardHeight.ts +15 -17
  90. package/src/keyboard/useMobileKeyboard.ts +8 -7
  91. package/src/privateAttributes/press.stylex.ts +109 -10
@@ -130,7 +130,11 @@ import {
130
130
  resolvePresented,
131
131
  watchPresentedElements,
132
132
  } from '../motion/presentation';
133
- import {UIKIT_PRESS, UIKIT_TAP} from '../motion/uikit/gestures';
133
+ import {
134
+ UIKIT_LONG_PRESS,
135
+ UIKIT_PRESS,
136
+ UIKIT_TAP,
137
+ } from '../motion/uikit/gestures';
134
138
  import {
135
139
  browserClock,
136
140
  GestureArena,
@@ -794,6 +798,13 @@ export class GestureHost {
794
798
  */
795
799
  private readonly layoutWatched = new Set<Element>();
796
800
  private layoutObserver: ResizeObserver | null = null;
801
+ /** Where and when the last pen hold the host tracked ended. */
802
+ private lastPenLift: {target: unknown; time: number} | null = null;
803
+ /**
804
+ * Arena ids of the pen contacts that left the long press's tolerance
805
+ * before its duration. No such contact is a hold.
806
+ */
807
+ private readonly driftedPens = new Set<number>();
797
808
  /** Fingers whose first uncancelable `touchmove` was already judged. */
798
809
  private readonly judgedUncancelable = new Set<number>();
799
810
  /**
@@ -1430,6 +1441,37 @@ export class GestureHost {
1430
1441
  );
1431
1442
  }
1432
1443
 
1444
+ /**
1445
+ * @internal Whether a pen that went down inside `node` is down now,
1446
+ * whichever participant keeps it. A pen's own menu event is that hold's
1447
+ * (contextRequest.ts).
1448
+ */
1449
+ isPenDownIn(node: Node): boolean {
1450
+ return this.arena.touches.some(
1451
+ touch =>
1452
+ touch.pointerType === 'pen' &&
1453
+ // A lifted pen that a recognizer still decides on is no longer down.
1454
+ touch.phase !== 'ended' &&
1455
+ touch.phase !== 'cancelled' &&
1456
+ touch.target instanceof Node &&
1457
+ containsAlongFlatTree(node, touch.target),
1458
+ );
1459
+ }
1460
+
1461
+ /**
1462
+ * @internal When a pen hold that went down inside `node` last ended, at
1463
+ * its lift or a cancel. The time is on the host's clock: negative infinity
1464
+ * when none did.
1465
+ */
1466
+ lastPenLiftIn(node: Node): number {
1467
+ const lift = this.lastPenLift;
1468
+ return lift != null &&
1469
+ lift.target instanceof Node &&
1470
+ containsAlongFlatTree(node, lift.target)
1471
+ ? lift.time
1472
+ : Number.NEGATIVE_INFINITY;
1473
+ }
1474
+
1433
1475
  private registrationFor(element: Element): Registration {
1434
1476
  this.watchPointer();
1435
1477
  let registration = this.registry.get(element);
@@ -2986,6 +3028,33 @@ export class GestureHost {
2986
3028
  };
2987
3029
  }
2988
3030
 
3031
+ /**
3032
+ * @internal Whether a press consumer that keeps its press (a hold-repeat
3033
+ * control, `keepsTouch`) sits on the path from `target` up to `boundary`,
3034
+ * both included. Such a control keeps its long press its own. Its right
3035
+ * click and Shift+F10 still reach a context request around it
3036
+ * (contextRequest.ts).
3037
+ */
3038
+ keepsPressBetween(target: unknown, boundary: Element): boolean {
3039
+ for (
3040
+ let node: Node | null = target instanceof Node ? target : null;
3041
+ node != null;
3042
+ node = parentAcrossShadow(node)
3043
+ ) {
3044
+ if (!(node instanceof Element)) {
3045
+ continue;
3046
+ }
3047
+ const consumer = this.registry.get(node)?.consumer;
3048
+ if (consumer?.keepsTouch != null && consumer.isEnabled?.() !== false) {
3049
+ return true;
3050
+ }
3051
+ if (node === boundary) {
3052
+ break;
3053
+ }
3054
+ }
3055
+ return false;
3056
+ }
3057
+
2989
3058
  /**
2990
3059
  * How many fingers are on the screen: the length of `touches` in the last
2991
3060
  * touch event the host's listeners heard (`touchstart`, `touchmove`,
@@ -3834,6 +3903,14 @@ export class GestureHost {
3834
3903
  }
3835
3904
  const id = this.pointerIds.get(event.pointerId);
3836
3905
  if (id != null) {
3906
+ if (event.pointerType === 'pen') {
3907
+ this.notePenDrift(
3908
+ id,
3909
+ event.clientX,
3910
+ event.clientY,
3911
+ eventTime(event, this.timing),
3912
+ );
3913
+ }
3837
3914
  this.arena.moved([
3838
3915
  {
3839
3916
  id,
@@ -3876,6 +3953,11 @@ export class GestureHost {
3876
3953
  this.pointerKinds.delete(event.pointerId);
3877
3954
  const hold = this.claimHolds.get(id);
3878
3955
  this.unlockSelection(id);
3956
+ const target = this.arena.getTouch(id)?.target;
3957
+ const isPenHold =
3958
+ event.pointerType === 'pen' &&
3959
+ this.isPenHold(id, eventTime(event, this.timing));
3960
+ this.driftedPens.delete(id);
3879
3961
  const dispositions = this.arena.ended([
3880
3962
  {
3881
3963
  id,
@@ -3886,6 +3968,9 @@ export class GestureHost {
3886
3968
  ]);
3887
3969
  // A selection the lift's own handlers made stays, as a click's does.
3888
3970
  hold?.keepLiftSelection();
3971
+ if (isPenHold) {
3972
+ this.lastPenLift = {target, time: this.arena.now()};
3973
+ }
3889
3974
  // A retargeted tap's own click arms the click guard for the engine's.
3890
3975
  const landed = this.retargeted.get(id);
3891
3976
  this.retargeted.delete(id);
@@ -3993,10 +4078,48 @@ export class GestureHost {
3993
4078
  this.pointerKinds.delete(event.pointerId);
3994
4079
  this.unlockSelection(id, true);
3995
4080
  this.retargeted.delete(id);
4081
+ const target = this.arena.getTouch(id)?.target;
4082
+ const isPenHold =
4083
+ event.pointerType === 'pen' &&
4084
+ this.isPenHold(id, eventTime(event, this.timing));
4085
+ this.driftedPens.delete(id);
3996
4086
  this.arena.cancelled([id], eventTime(event, this.timing));
4087
+ if (isPenHold) {
4088
+ this.lastPenLift = {target, time: this.arena.now()};
4089
+ }
3997
4090
  }
3998
4091
  };
3999
4092
 
4093
+ /**
4094
+ * Whether a pen contact is a hold: it stays within the long press's
4095
+ * tolerance for its duration. Only such a hold fires the platform's own
4096
+ * menu event, so the host notes no other pen's lift.
4097
+ */
4098
+ private isPenHold(id: number, time: number): boolean {
4099
+ const touch = this.arena.getTouch(id);
4100
+ return (
4101
+ touch != null &&
4102
+ !this.driftedPens.has(id) &&
4103
+ time - touch.startTime >= UIKIT_LONG_PRESS.minimumPressDuration.value
4104
+ );
4105
+ }
4106
+
4107
+ /**
4108
+ * A pen contact that leaves the long press's tolerance before its duration
4109
+ * is no hold, so its lift arms no menu refusal.
4110
+ */
4111
+ private notePenDrift(id: number, x: number, y: number, time: number): void {
4112
+ const touch = this.arena.getTouch(id);
4113
+ if (
4114
+ touch != null &&
4115
+ time - touch.startTime < UIKIT_LONG_PRESS.minimumPressDuration.value &&
4116
+ Math.hypot(x - touch.startX, y - touch.startY) >
4117
+ UIKIT_LONG_PRESS.allowableMovement.value
4118
+ ) {
4119
+ this.driftedPens.add(id);
4120
+ }
4121
+ }
4122
+
4000
4123
  /**
4001
4124
  * Which live finger a touch `pointercancel` is about. The pointer keeps
4002
4125
  * the target the finger landed on (implicit capture), as the Touch does;
@@ -4272,6 +4395,7 @@ export class GestureHost {
4272
4395
  }
4273
4396
  this.pointerIds.clear();
4274
4397
  this.pointerKinds.clear();
4398
+ this.driftedPens.clear();
4275
4399
  this.retargeted.clear();
4276
4400
  this.fingerPointers.clear();
4277
4401
  this.pendingPointers.clear();
@@ -560,6 +560,27 @@ the rest of that stream is the page's. A ctrl-wheel pinch keeps its stream,
560
560
  so the page never zooms for it, and a pan its lift released keeps its
561
561
  momentum latched until the stream ends.
562
562
 
563
+ ## Context requests
564
+
565
+ `attachContextRequest(element, {onRequest})` (`contextRequest.ts`, internal)
566
+ is the one request a context menu answers (`spec:AST-094` FR43): a finger or
567
+ a pen held still for UIKit's long press, a pointer's context click (a right
568
+ click, a ctrl-click on macOS, a pen's barrel button), or Shift+F10 and the
569
+ context-menu key. Each gesture makes one request, reporting its `kind`
570
+ (`hold`, `pointer`, `keyboard`), its pointer, and its point (none from
571
+ the keyboard). The hold is an arena participant, so it loses to a claim
572
+ another recognizer made on that finger first (a reorder handle's hold); the
573
+ browser's own menu that a held finger, a held pen or a key also fires is
574
+ refused, never requested again; and a mouse held still makes no request. A
575
+ control that keeps its press for a hold-repeat owns only its hold: its right
576
+ click and Shift+F10 still reach the request. A right click or a ctrl-click on macOS starts no press.
577
+ The request listens on its own element only, and only while enabled.
578
+
579
+ The hold is UIKit's long press, 500 ms and 10 px as a distance, and it
580
+ requests as it begins; `onHold` reports it committed, then ended at its lift
581
+ or cancelled. A hold disabled before it requests reports nothing, and a held
582
+ key's repeats make no request.
583
+
563
584
  ## Time
564
585
 
565
586
  Every input carries its own timestamp (`event.timeStamp`), and timers are
@@ -0,0 +1,206 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ /**
4
+ * @file contextRequest.ts
5
+ * @input An element, a request callback and the document's gesture host
6
+ * @output attachContextRequest: one shared context request from a held
7
+ * finger or pen, a pointer's context click, or Shift+F10 and the
8
+ * context-menu key
9
+ * @position Internal gesture module, never exported from the package. The
10
+ * headless context menu and row menus build on it.
11
+ */
12
+
13
+ import {lockSelection} from '../utils/selectionLock';
14
+ import {sharedWeakSet} from '../utils/sharedRealm';
15
+ import {getGestureHost, type GestureHost} from './GestureHost';
16
+ import {LongPressGestureRecognizer} from './LongPressGestureRecognizer';
17
+ import type {PointerKind} from './types';
18
+
19
+ /** What a context request reports. */
20
+ export interface ContextRequest {
21
+ /**
22
+ * What made it: a held finger or pen, a pointer's context click, or a key.
23
+ */
24
+ readonly kind: 'hold' | 'pointer' | 'keyboard';
25
+ /** The pointer that made it; null from the keyboard. */
26
+ readonly pointerType: PointerKind | null;
27
+ /** Where, in client coordinates; null from the keyboard. */
28
+ readonly point: {readonly x: number; readonly y: number} | null;
29
+ /**
30
+ * The Pointer Events id of the pointer that made it, when the host knows it.
31
+ */
32
+ readonly pointerId: number | null;
33
+ /** When, on the gesture host's clock. */
34
+ readonly time: number;
35
+ }
36
+
37
+ export interface ContextRequestOptions {
38
+ onRequest: (request: ContextRequest) => void;
39
+ /**
40
+ * Read when it attaches: a disabled request registers nothing. Read again
41
+ * at each input. @default () => true
42
+ */
43
+ isEnabled?: () => boolean;
44
+ /**
45
+ * A hold's progress. It reports `committed` when the still finger or pen
46
+ * claims its touch and the hold requests. It then reports `ended` at its
47
+ * lift, or `cancelled` if a cancel ends the touch first. A hold disabled
48
+ * before it requests reports nothing.
49
+ */
50
+ onHold?: (phase: 'committed' | 'ended' | 'cancelled') => void;
51
+ }
52
+
53
+ /**
54
+ * How long after a request key's last keydown, or a pen's lift, the browser's
55
+ * own context menu event is that input's echo, ms.
56
+ */
57
+ const MENU_ECHO_MS = 500;
58
+
59
+ /**
60
+ * Menu events and keys a request already answered: one inside nested
61
+ * requests reaches only the innermost, as a hold resolves to one winner.
62
+ * Every copy of Core shares the set, so nested requests from two copies
63
+ * still answer once.
64
+ */
65
+ const answered = sharedWeakSet<Event>('gestures/context-request/answered', 1);
66
+
67
+ const POINTER_KINDS: ReadonlySet<string> = new Set(['touch', 'mouse', 'pen']);
68
+
69
+ function pointerKindOf(event: MouseEvent): PointerKind | null {
70
+ const type = (event as Partial<PointerEvent>).pointerType;
71
+ return type != null && POINTER_KINDS.has(type) ? (type as PointerKind) : null;
72
+ }
73
+
74
+ /**
75
+ * Report context requests on `element` until the returned function runs.
76
+ * `host` is the document's gesture host; tests pass their own.
77
+ */
78
+ export function attachContextRequest(
79
+ element: Element,
80
+ options: ContextRequestOptions,
81
+ host: GestureHost = getGestureHost(element.ownerDocument),
82
+ ): () => void {
83
+ const isEnabled = () => options.isEnabled?.() !== false;
84
+ if (!isEnabled()) {
85
+ return () => {};
86
+ }
87
+ let lastRequestKeyAt = Number.NEGATIVE_INFINITY;
88
+ let held: {touchId: number; pointerType: PointerKind} | null = null;
89
+ let isHoldReported = false;
90
+
91
+ // The defaults are UIKit's plain long press.
92
+ const recognizer = new LongPressGestureRecognizer({
93
+ name: 'contextRequest',
94
+ // A mouse held still selects text and drags: a hold is a finger's or a
95
+ // pen's.
96
+ allowedPointerTypes: ['touch', 'pen'],
97
+ // A hold that opens a menu takes no selection or callout.
98
+ selectionLock: lockSelection,
99
+ shouldReceiveTouch: (_recognizer, touch) => {
100
+ if (!isEnabled() || host.keepsPressBetween(touch.target, element)) {
101
+ return false;
102
+ }
103
+ held = {touchId: touch.id, pointerType: touch.pointerType};
104
+ return true;
105
+ },
106
+ });
107
+
108
+ recognizer.addListener(() => {
109
+ const {state} = recognizer;
110
+ if (state === 'began') {
111
+ // A request disabled during the hold makes none, and its hold reports
112
+ // no phase: `committed` comes only with a request.
113
+ if (!isEnabled()) {
114
+ return;
115
+ }
116
+ isHoldReported = true;
117
+ options.onHold?.('committed');
118
+ const point = recognizer.location();
119
+ options.onRequest({
120
+ kind: 'hold',
121
+ pointerType: held?.pointerType ?? 'touch',
122
+ point: {x: point.x, y: point.y},
123
+ pointerId: held == null ? null : host.pointerIdOf(held.touchId),
124
+ time: host.arena.now(),
125
+ });
126
+ } else if (state === 'ended' || state === 'cancelled') {
127
+ if (isHoldReported) {
128
+ options.onHold?.(state);
129
+ }
130
+ isHoldReported = false;
131
+ held = null;
132
+ }
133
+ });
134
+
135
+ const onContextMenu = (event: Event): void => {
136
+ const menu = event as MouseEvent;
137
+ // A hold-repeat control inside owns only its hold: its right click
138
+ // reaches this request. A request inside already answered this event.
139
+ if (!isEnabled() || answered.has(menu)) {
140
+ return;
141
+ }
142
+ answered.add(menu);
143
+ // The browser's own menu stays off either way.
144
+ menu.preventDefault();
145
+ const time = host.arena.now();
146
+ const pointerType = pointerKindOf(menu);
147
+ // A held finger's menu is the hold's to request, or a claim refused it.
148
+ // That needs a finger down inside this element. A key's menu event is
149
+ // that key's echo.
150
+ if (
151
+ pointerType === 'touch' ||
152
+ host.isFingerDownIn(element) ||
153
+ time - lastRequestKeyAt < MENU_ECHO_MS ||
154
+ // A pen's own menu event is its hold's: during any hold of it inside
155
+ // this element, or right after its lift. The hold may be this
156
+ // request's, a stepper's, or a handle's that claimed first.
157
+ (pointerType === 'pen' &&
158
+ (host.isPenDownIn(element) ||
159
+ time - host.lastPenLiftIn(element) < MENU_ECHO_MS))
160
+ ) {
161
+ return;
162
+ }
163
+ options.onRequest({
164
+ kind: 'pointer',
165
+ pointerType: pointerType ?? 'mouse',
166
+ point: {x: menu.clientX, y: menu.clientY},
167
+ pointerId: (menu as Partial<PointerEvent>).pointerId ?? null,
168
+ time,
169
+ });
170
+ };
171
+
172
+ const onKeyDown = (event: Event): void => {
173
+ const key = event as KeyboardEvent;
174
+ const isRequestKey =
175
+ (key.key === 'F10' && key.shiftKey) || key.key === 'ContextMenu';
176
+ // A hold-repeat control inside owns only its hold: Shift+F10 on it
177
+ // reaches this request.
178
+ if (!isRequestKey || !isEnabled() || answered.has(key)) {
179
+ return;
180
+ }
181
+ answered.add(key);
182
+ key.preventDefault();
183
+ // A held key repeats its keydown. Each repeat keeps the echo window
184
+ // open, and only the first keydown requests.
185
+ lastRequestKeyAt = host.arena.now();
186
+ if (key.repeat) {
187
+ return;
188
+ }
189
+ options.onRequest({
190
+ kind: 'keyboard',
191
+ pointerType: null,
192
+ point: null,
193
+ pointerId: null,
194
+ time: lastRequestKeyAt,
195
+ });
196
+ };
197
+
198
+ const detachRecognizer = host.attach(element, recognizer);
199
+ element.addEventListener('contextmenu', onContextMenu);
200
+ element.addEventListener('keydown', onKeyDown);
201
+ return () => {
202
+ element.removeEventListener('contextmenu', onContextMenu);
203
+ element.removeEventListener('keydown', onKeyDown);
204
+ detachRecognizer();
205
+ };
206
+ }
@@ -138,7 +138,7 @@ function belongsToSomethingElse(element: Element): boolean {
138
138
  * too. A press on the container's surface or on `ownAction` is left alone.
139
139
  * Not part of the package's public API.
140
140
  */
141
- export function cancelNestedTouchPress(
141
+ export function cancelNestedPress(
142
142
  event: PointerEvent<HTMLElement>,
143
143
  container: HTMLElement | null,
144
144
  ownAction: Element | null,
@@ -377,7 +377,7 @@ export function useClickableContainerProxy({
377
377
  if (disabled) {
378
378
  return;
379
379
  }
380
- cancelNestedTouchPress(
380
+ cancelNestedPress(
381
381
  event,
382
382
  containerRef.current,
383
383
  interactiveRef?.current ?? null,
@@ -0,0 +1,39 @@
1
+ // Copyright (c) Meta Platforms, Inc. and affiliates.
2
+
3
+ 'use client';
4
+
5
+ /**
6
+ * @file useCommittedRef.ts
7
+ * @input A value from the current render: a prop or a callback
8
+ * @output Exports useCommittedRef and useCommittedRefInto
9
+ * @position Internal hooks; not in hooks/index.ts or the package entry
10
+ */
11
+
12
+ import {useInsertionEffect, useRef} from 'react';
13
+
14
+ /**
15
+ * Returns a ref whose `current` is the value of the last committed render.
16
+ * The ref object stays the same for the life of the component. Read
17
+ * `current` only in event and gesture callbacks, never during render. A
18
+ * value that selects a resource (what to subscribe to) belongs in the Effect's
19
+ * dependencies, not in a committed ref.
20
+ */
21
+ export function useCommittedRef<T>(value: T): {readonly current: T} {
22
+ const ref = useRef(value);
23
+ useCommittedRefInto(ref, value);
24
+ return ref;
25
+ }
26
+
27
+ /**
28
+ * Writes the value of each committed render into `ref`. Use this shape when
29
+ * callbacks that read the ref come before the value in the component. Create
30
+ * the ref with `useRef` first, then call this hook after the value exists.
31
+ * In all other cases, use `useCommittedRef`. The read rules are the same.
32
+ */
33
+ export function useCommittedRefInto<T>(ref: {current: T}, value: T): void {
34
+ // Stores values only. Refs to DOM nodes are not attached yet when this runs.
35
+ useInsertionEffect(() => {
36
+ // eslint-disable-next-line react-compiler/react-compiler -- the caller hands over its own ref so that this hook writes it
37
+ ref.current = value;
38
+ });
39
+ }