@charcuterie/ui 4.28.1 → 4.28.2

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 +1 @@
1
- {"version":3,"file":"useBoardDrag.d.ts","sourceRoot":"","sources":["../../src/Board/useBoardDrag.ts"],"names":[],"mappings":"AAOA,OAAO,KAAK,EACV,aAAa,EACb,eAAe,EAEhB,MAAM,gBAAgB,CAAA;AAwDvB,MAAM,MAAM,eAAe,GAAG;IAC5B,SAAS,EAAE,MAAM,CAAA;IACjB,WAAW,EAAE,MAAM,CAAA;IACnB,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAED,MAAM,MAAM,cAAc,GAAG,eAAe,GAAG;IAC7C;;;;OAIG;IACH,eAAe,EAAE,MAAM,GAAG,IAAI,CAAA;IAC9B,MAAM,EAAE,eAAe,GAAG,IAAI,CAAA;CAC/B,CAAA;AAED,KAAK,YAAY,GAAG,aAAa,GAAG;IAClC,GAAG,EAAE,MAAM,CAAA;IACX,OAAO,EAAE,MAAM,CAAA;CAChB,CAAA;AAaD;;;;;;;;;GASG;AACH,eAAO,MAAM,kBAAkB,GAC7B,MAAM,YAAY,EAClB,OAAO,MAAM,KACZ,MA2BF,CAAA;AAED,eAAO,MAAM,YAAY,GAAI,2BAG1B;IACD;;;;;;;;;;;;OAYG;IACH,YAAY,CAAC,EAAE,MAAM,CAAA;IACrB,MAAM,EAAE,CACN,MAAM,EAAE,eAAe,EACvB,MAAM,EAAE,eAAe,KACpB,IAAI,CAAA;CACV,KAAG;IACF,IAAI,EAAE,cAAc,GAAG,IAAI,CAAA;IAC3B,YAAY,EAAE,CACZ,OAAO,EAAE,MAAM,KACZ,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI,KAAK,IAAI,CAAA;IAC1C,SAAS,EAAE,CACT,YAAY,EAAE;QACZ,OAAO,EAAE,MAAM,CAAA;QACf,OAAO,EAAE,MAAM,CAAA;QACf,aAAa,EAAE,WAAW,GAA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ACpC,SAAS,EAAE,MAAM,CAAA;KAClB,EACD,MAAM,EAAE,eAAe,KACpB,IAAI,CAAA;CAgSV,CAAA"}
@@ -86,6 +86,66 @@ export const getIndicatorOffset = (lane, index) => {
86
86
  return ((previous.top + previous.height + next.top) / 2 -
87
87
  listTop);
88
88
  };
89
+ /**
90
+ * Swallows the one synthetic `click` that a finished drag produces.
91
+ *
92
+ * Swallowed in the **capture** phase, so it consumes the click this
93
+ * gesture produced before the handle's own listener sees it. A
94
+ * `hasDragged` flag on the card would be the same idea with a
95
+ * lifetime nobody owns.
96
+ *
97
+ * The blocker must not outlive that click, and a drag does not
98
+ * always produce one: a touch that travelled is not a tap, and a
99
+ * `pointerup` outside the handle without pointer capture lands its
100
+ * click on an ancestor or nowhere. So it also disarms on the next
101
+ * `pointerdown` or `keydown` (a new gesture has begun, and the old
102
+ * one's click would already have arrived) and after a short timer
103
+ * (for a click with no gesture in front of it, such as a screen
104
+ * reader's activation).
105
+ *
106
+ * And it swallows only a click that could be the gesture's own: one
107
+ * on the handle (where pointer capture sends it), or on an ancestor
108
+ * of the handle (where a `pointerup` that left the handle without
109
+ * capture sends it). A click on any other control passes, so a
110
+ * bystander is never the one that pays.
111
+ */
112
+ const CLICK_BLOCK_MS = 400;
113
+ const blockNextClick = (handle) => {
114
+ const swallow = (clickEvent) => {
115
+ const { target } = clickEvent;
116
+ if (!(target instanceof Node) ||
117
+ !target.contains(handle)) {
118
+ return;
119
+ }
120
+ clickEvent.preventDefault();
121
+ clickEvent.stopPropagation();
122
+ disarm();
123
+ };
124
+ const timer = globalThis.setTimeout(() => {
125
+ disarm();
126
+ }, CLICK_BLOCK_MS);
127
+ function disarm() {
128
+ globalThis.clearTimeout(timer);
129
+ globalThis.removeEventListener("click", swallow, {
130
+ capture: true,
131
+ });
132
+ globalThis.removeEventListener("pointerdown", disarm, {
133
+ capture: true,
134
+ });
135
+ globalThis.removeEventListener("keydown", disarm, {
136
+ capture: true,
137
+ });
138
+ }
139
+ globalThis.addEventListener("click", swallow, {
140
+ capture: true,
141
+ });
142
+ globalThis.addEventListener("pointerdown", disarm, {
143
+ capture: true,
144
+ });
145
+ globalThis.addEventListener("keydown", disarm, {
146
+ capture: true,
147
+ });
148
+ };
89
149
  export const useBoardDrag = ({ itemSelector = "[data-board-card]", onDrop, }) => {
90
150
  const laneElements = useRef(new Map());
91
151
  const snapshot = useRef([]);
@@ -98,6 +158,15 @@ export const useBoardDrag = ({ itemSelector = "[data-board-card]", onDrop, }) =>
98
158
  * cannot close over `drag` itself.
99
159
  */
100
160
  const dragRef = useRef(null);
161
+ /**
162
+ * Removes the listeners of the gesture in progress, if there is
163
+ * one. Kept in a ref so an unmount can call it: the pointer
164
+ * listeners live on `globalThis`, and a component that unmounts
165
+ * mid-drag (a route change, a lane that closes) would otherwise
166
+ * leave them there, and the next `pointerup` anywhere on the page
167
+ * would commit a drop for a board that no longer exists.
168
+ */
169
+ const stopGestureRef = useRef(null);
101
170
  const setDragState = useCallback((next) => {
102
171
  dragRef.current = next;
103
172
  setDrag(next);
@@ -172,10 +241,16 @@ export const useBoardDrag = ({ itemSelector = "[data-board-card]", onDrop, }) =>
172
241
  y: moveEvent.clientY,
173
242
  });
174
243
  };
175
- const finish = (isCommitted) => {
244
+ const stopGesture = () => {
176
245
  globalThis.removeEventListener("pointermove", onPointerMove);
177
246
  globalThis.removeEventListener("pointerup", onUp);
178
247
  globalThis.removeEventListener("pointercancel", onCancel);
248
+ if (stopGestureRef.current === stopGesture) {
249
+ stopGestureRef.current = null;
250
+ }
251
+ };
252
+ const finish = (isCommitted) => {
253
+ stopGesture();
179
254
  const live = dragRef.current;
180
255
  setDragState(null);
181
256
  if (!live) {
@@ -188,15 +263,14 @@ export const useBoardDrag = ({ itemSelector = "[data-board-card]", onDrop, }) =>
188
263
  * every completed drag lands the card and then opens a menu
189
264
  * on top of it.
190
265
  *
191
- * Swallowed in the **capture** phase and `once`, so it
192
- * consumes exactly the synthetic click this gesture
193
- * produced and nothing after it. A `hasDragged` flag on the
194
- * card would be the same idea with a lifetime nobody owns.
266
+ * Only a `pointerup` gets the blocker. A `pointercancel`
267
+ * produces no `click` at all — the browser took the
268
+ * gesture — so a blocker installed there waits for the
269
+ * next REAL click, anywhere on the page, and eats it.
195
270
  */
196
- globalThis.addEventListener("click", (clickEvent) => {
197
- clickEvent.preventDefault();
198
- clickEvent.stopPropagation();
199
- }, { capture: true, once: true });
271
+ if (isCommitted) {
272
+ blockNextClick(handle);
273
+ }
200
274
  if (isCommitted && live.target) {
201
275
  onDrop(origin, live.target);
202
276
  }
@@ -206,9 +280,22 @@ export const useBoardDrag = ({ itemSelector = "[data-board-card]", onDrop, }) =>
206
280
  finish(true);
207
281
  }
208
282
  };
209
- const onCancel = () => {
210
- finish(false);
283
+ const onCancel = (cancelEvent) => {
284
+ if (cancelEvent.pointerId === pointerEvent.pointerId) {
285
+ finish(false);
286
+ }
211
287
  };
288
+ // A second press while a gesture is live (another finger, or
289
+ // a pointer whose `pointerup` never arrived) replaces the
290
+ // first gesture rather than stacking listeners beside it. Its
291
+ // drag state goes with it: otherwise this press, released
292
+ // without moving, would drop ITS card on the first gesture's
293
+ // target.
294
+ if (stopGestureRef.current) {
295
+ stopGestureRef.current();
296
+ setDragState(null);
297
+ }
298
+ stopGestureRef.current = stopGesture;
212
299
  globalThis.addEventListener("pointermove", onPointerMove, { passive: false });
213
300
  globalThis.addEventListener("pointerup", onUp);
214
301
  globalThis.addEventListener("pointercancel", onCancel);
@@ -220,6 +307,9 @@ export const useBoardDrag = ({ itemSelector = "[data-board-card]", onDrop, }) =>
220
307
  * component unmounts mid-drag — which is exactly what a route
221
308
  * change during a drag does.
222
309
  */
310
+ useEffect(() => () => {
311
+ stopGestureRef.current?.();
312
+ }, []);
223
313
  useEffect(() => {
224
314
  const onKeyDown = (keyEvent) => {
225
315
  if (keyEvent.key === "Escape" && dragRef.current) {
@@ -1 +1 @@
1
- {"version":3,"file":"useBoardDrag.js","sourceRoot":"","sources":["../../src/Board/useBoard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C;QACH,CAAC,CAAA;QAED,UAAU,CAAC,gBAAgB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QAEjD,OAAO,GAAG,EAAE;YACV,UAAU,CAAC,mBAAmB,CAAC,SAAS,EAAE,SAAS,CAAC,CAAA;QACtD,CAAC,CAAA;IACH,CAAC,EAAE,CAAC,YAAY,CAAC,CAAC,CAAA;IAElB,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,SAAS,EAAE,CAAA;AAC1C,CAAC,CAAA"}
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * 1. **`navigator.clipboard.writeText`.** The real API. It exists
8
8
  * only in a *secure context*, which a `devshare` URL and
9
- * `localhost` both are — and a plain `http://storeman.octen:8080`
9
+ * `localhost` both are — and a plain `http://truenas-host:8080`
10
10
  * dev server is not.
11
11
  * 2. **A hidden `<textarea>` plus `document.execCommand("copy")`.**
12
12
  * Deprecated, and kept anyway: it is the only thing that works in
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * 1. **`navigator.clipboard.writeText`.** The real API. It exists
8
8
  * only in a *secure context*, which a `devshare` URL and
9
- * `localhost` both are — and a plain `http://storeman.octen:8080`
9
+ * `localhost` both are — and a plain `http://truenas-host:8080`
10
10
  * dev server is not.
11
11
  * 2. **A hidden `<textarea>` plus `document.execCommand("copy")`.**
12
12
  * Deprecated, and kept anyway: it is the only thing that works in
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Ten repos hand-roll their page chrome and **no two of them cap
6
6
  * the column at the same width**: `max-w-5xl` (board-games,
7
- * portly), `max-w-6xl` and `max-w-3xl` mixed inside one app
7
+ * sibling-app), `max-w-6xl` and `max-w-3xl` mixed inside one app
8
8
  * (mux-magic), `max-w-7xl` (gallery-downloader, spoolbuddy),
9
9
  * `max-w-[90rem]` (mail-sifter), `80rem` (points-market), a raw
10
10
  * `1400px` in plain CSS (plex-channels), a JS-computed one
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Ten repos hand-roll their page chrome and **no two of them cap
6
6
  * the column at the same width**: `max-w-5xl` (board-games,
7
- * portly), `max-w-6xl` and `max-w-3xl` mixed inside one app
7
+ * sibling-app), `max-w-6xl` and `max-w-3xl` mixed inside one app
8
8
  * (mux-magic), `max-w-7xl` (gallery-downloader, spoolbuddy),
9
9
  * `max-w-[90rem]` (mail-sifter), `80rem` (points-market), a raw
10
10
  * `1400px` in plain CSS (plex-channels), a JS-computed one
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@charcuterie/ui",
3
- "version": "4.28.1",
3
+ "version": "4.28.2",
4
4
  "description": "The Charcuterie components. Tokens for look, @charcuterie/logic for state, ARIA that agents can actually drive.",
5
5
  "license": "MIT",
6
6
  "type": "module",
@@ -0,0 +1,395 @@
1
+ import { flushSync } from "react-dom"
2
+ import { createRoot, type Root } from "react-dom/client"
3
+ import { expect } from "storybook/test"
4
+ import { afterEach, test, vi } from "vitest"
5
+
6
+ import type { BoardDropTarget } from "./boardMove.ts"
7
+ import {
8
+ type BoardDragOrigin,
9
+ useBoardDrag,
10
+ } from "./useBoardDrag.ts"
11
+
12
+ /**
13
+ * The hook's gesture lifecycle, driven by hand.
14
+ *
15
+ * Mounted bare rather than through a story, because what is under
16
+ * test is what happens AFTER a gesture ends — a click elsewhere on
17
+ * the page, an unmount mid-drag — and neither has a story. The drag
18
+ * is started by calling `startDrag` directly with a handle whose
19
+ * `setPointerCapture` is a no-op: a dispatched `PointerEvent` has no
20
+ * active pointer behind it, and the real method would throw before
21
+ * a listener was registered.
22
+ */
23
+
24
+ const POINTER_ID = 7
25
+
26
+ type Harness = {
27
+ /** The move handle; a click on it would open the move menu. */
28
+ handle: HTMLButtonElement
29
+ host: HTMLElement
30
+ onDrop: ReturnType<typeof vi.fn>
31
+ onHandleClick: ReturnType<typeof vi.fn>
32
+ root: Root
33
+ startDrag: (
34
+ pointerId?: number,
35
+ origin?: BoardDragOrigin,
36
+ ) => void
37
+ }
38
+
39
+ let harness: Harness | null = null
40
+
41
+ afterEach(() => {
42
+ // A test that ends on a finished drag leaves its click blocker
43
+ // armed for the next test; a press is what disarms it.
44
+ globalThis.dispatchEvent(new PointerEvent("pointerdown"))
45
+
46
+ if (harness) {
47
+ harness.root.unmount()
48
+
49
+ harness.host.remove()
50
+
51
+ harness = null
52
+ }
53
+ })
54
+
55
+ const ORIGIN: BoardDragOrigin = {
56
+ fromIndex: 0,
57
+ fromLaneKey: "lane",
58
+ itemKey: "card",
59
+ }
60
+
61
+ const mountHarness = (): Harness => {
62
+ const host = document.createElement("div")
63
+
64
+ document.body.append(host)
65
+
66
+ const root = createRoot(host)
67
+
68
+ const onDrop =
69
+ vi.fn<
70
+ (
71
+ origin: BoardDragOrigin,
72
+ target: BoardDropTarget,
73
+ ) => void
74
+ >()
75
+
76
+ const onHandleClick = vi.fn()
77
+
78
+ let start: Harness["startDrag"] = () => {}
79
+
80
+ const DragHarness = () => {
81
+ const { registerLane, startDrag } = useBoardDrag({
82
+ onDrop,
83
+ })
84
+
85
+ start = (pointerId = POINTER_ID, origin = ORIGIN) => {
86
+ const handle = host.querySelector("button")
87
+
88
+ if (!handle) {
89
+ throw new Error("The harness drew no handle.")
90
+ }
91
+
92
+ startDrag(
93
+ {
94
+ clientX: 20,
95
+ clientY: 20,
96
+ currentTarget: handle,
97
+ pointerId,
98
+ },
99
+ origin,
100
+ )
101
+ }
102
+
103
+ return (
104
+ <div
105
+ ref={registerLane("lane")}
106
+ style={{ height: 200, width: 200 }}
107
+ >
108
+ <div data-board-card="" style={{ height: 40 }}>
109
+ <button
110
+ onClick={onHandleClick}
111
+ ref={(element) => {
112
+ if (element) {
113
+ element.setPointerCapture = () => {}
114
+ }
115
+ }}
116
+ type="button"
117
+ >
118
+ Move
119
+ </button>
120
+ </div>
121
+ </div>
122
+ )
123
+ }
124
+
125
+ flushSync(() => {
126
+ root.render(<DragHarness />)
127
+ })
128
+
129
+ const handle = host.querySelector("button")
130
+
131
+ if (!handle) {
132
+ throw new Error("The harness drew no handle.")
133
+ }
134
+
135
+ const created: Harness = {
136
+ handle,
137
+ host,
138
+ onDrop,
139
+ onHandleClick,
140
+ root,
141
+ startDrag: (pointerId, origin) => {
142
+ start(pointerId, origin)
143
+ },
144
+ }
145
+
146
+ harness = created
147
+
148
+ return created
149
+ }
150
+
151
+ const firePointer = (
152
+ type: "pointercancel" | "pointermove" | "pointerup",
153
+ point: { x: number; y: number },
154
+ pointerId = POINTER_ID,
155
+ ) => {
156
+ const box = harness?.host.getBoundingClientRect()
157
+
158
+ globalThis.dispatchEvent(
159
+ new PointerEvent(type, {
160
+ bubbles: true,
161
+ cancelable: true,
162
+ clientX: (box?.left ?? 0) + point.x,
163
+ clientY: (box?.top ?? 0) + point.y,
164
+ pointerId,
165
+ }),
166
+ )
167
+ }
168
+
169
+ /** A real button elsewhere on the page, and whether it heard a click. */
170
+ const mountBystander = () => {
171
+ const button = document.createElement("button")
172
+
173
+ button.textContent = "Elsewhere"
174
+
175
+ const onClick = vi.fn()
176
+
177
+ button.addEventListener("click", onClick)
178
+
179
+ harness?.host.append(button)
180
+
181
+ return { button, onClick }
182
+ }
183
+
184
+ const dragIntoLane = (activeHarness: Harness) => {
185
+ activeHarness.startDrag()
186
+
187
+ // Past the four-pixel threshold, and inside the registered lane.
188
+ flushSync(() => {
189
+ firePointer("pointermove", { x: 60, y: 100 })
190
+ })
191
+ }
192
+
193
+ const finishDrag = () => {
194
+ flushSync(() => {
195
+ firePointer("pointerup", { x: 60, y: 100 })
196
+ })
197
+ }
198
+
199
+ test("a cancelled drag leaves the next real click alone", () => {
200
+ const activeHarness = mountHarness()
201
+
202
+ dragIntoLane(activeHarness)
203
+
204
+ flushSync(() => {
205
+ firePointer("pointercancel", { x: 60, y: 100 })
206
+ })
207
+
208
+ expect(activeHarness.onDrop).not.toHaveBeenCalled()
209
+
210
+ // A cancelled gesture produces no click, so this one is real.
211
+ activeHarness.handle.click()
212
+
213
+ expect(activeHarness.onHandleClick).toHaveBeenCalledTimes(
214
+ 1,
215
+ )
216
+ })
217
+
218
+ test("a finished drag swallows its own click, and only that one", () => {
219
+ const activeHarness = mountHarness()
220
+
221
+ dragIntoLane(activeHarness)
222
+
223
+ finishDrag()
224
+
225
+ expect(activeHarness.onDrop).toHaveBeenCalledTimes(1)
226
+
227
+ // The synthetic click the gesture produced.
228
+ activeHarness.handle.click()
229
+
230
+ expect(activeHarness.onHandleClick).not.toHaveBeenCalled()
231
+
232
+ activeHarness.handle.click()
233
+
234
+ expect(activeHarness.onHandleClick).toHaveBeenCalledTimes(
235
+ 1,
236
+ )
237
+ })
238
+
239
+ test("a finished drag's click on an ancestor of the handle is swallowed too", () => {
240
+ const activeHarness = mountHarness()
241
+
242
+ const onHostClick = vi.fn()
243
+
244
+ activeHarness.host.addEventListener("click", onHostClick)
245
+
246
+ dragIntoLane(activeHarness)
247
+
248
+ finishDrag()
249
+
250
+ // Without pointer capture, a release off the handle clicks the
251
+ // nearest common ancestor.
252
+ activeHarness.host.click()
253
+
254
+ expect(onHostClick).not.toHaveBeenCalled()
255
+ })
256
+
257
+ test("a finished drag never eats a click on another control", () => {
258
+ const activeHarness = mountHarness()
259
+
260
+ const { button, onClick } = mountBystander()
261
+
262
+ dragIntoLane(activeHarness)
263
+
264
+ finishDrag()
265
+
266
+ button.click()
267
+
268
+ expect(onClick).toHaveBeenCalledTimes(1)
269
+ })
270
+
271
+ test("a finished drag with no click of its own does not eat the next press", () => {
272
+ const activeHarness = mountHarness()
273
+
274
+ dragIntoLane(activeHarness)
275
+
276
+ finishDrag()
277
+
278
+ // A touch that travelled produces no click; the next gesture
279
+ // starts with a press.
280
+ activeHarness.handle.dispatchEvent(
281
+ new PointerEvent("pointerdown", {
282
+ bubbles: true,
283
+ pointerId: POINTER_ID + 1,
284
+ }),
285
+ )
286
+
287
+ activeHarness.handle.click()
288
+
289
+ expect(activeHarness.onHandleClick).toHaveBeenCalledTimes(
290
+ 1,
291
+ )
292
+ })
293
+
294
+ test("a drag's blocker expires on its own when no click comes", () => {
295
+ vi.useFakeTimers()
296
+
297
+ try {
298
+ const activeHarness = mountHarness()
299
+
300
+ dragIntoLane(activeHarness)
301
+
302
+ finishDrag()
303
+
304
+ vi.advanceTimersByTime(1000)
305
+
306
+ activeHarness.handle.click()
307
+
308
+ expect(
309
+ activeHarness.onHandleClick,
310
+ ).toHaveBeenCalledTimes(1)
311
+ } finally {
312
+ vi.useRealTimers()
313
+ }
314
+ })
315
+
316
+ test("another pointer's cancel does not end this drag", () => {
317
+ const activeHarness = mountHarness()
318
+
319
+ dragIntoLane(activeHarness)
320
+
321
+ globalThis.dispatchEvent(
322
+ new PointerEvent("pointercancel", {
323
+ pointerId: POINTER_ID + 1,
324
+ }),
325
+ )
326
+
327
+ finishDrag()
328
+
329
+ expect(activeHarness.onDrop).toHaveBeenCalledTimes(1)
330
+ })
331
+
332
+ test("a second press replaces the drag and does not inherit its target", () => {
333
+ const activeHarness = mountHarness()
334
+
335
+ dragIntoLane(activeHarness)
336
+
337
+ const secondPointer = POINTER_ID + 1
338
+
339
+ flushSync(() => {
340
+ activeHarness.startDrag(secondPointer, {
341
+ fromIndex: 1,
342
+ fromLaneKey: "lane",
343
+ itemKey: "other-card",
344
+ })
345
+ })
346
+
347
+ // Released where it was pressed: a press, not a drag.
348
+ flushSync(() => {
349
+ firePointer(
350
+ "pointerup",
351
+ { x: 20, y: 20 },
352
+ secondPointer,
353
+ )
354
+ })
355
+
356
+ // And the first pointer's late release belongs to no gesture.
357
+ finishDrag()
358
+
359
+ expect(activeHarness.onDrop).not.toHaveBeenCalled()
360
+ })
361
+
362
+ test("unmounting mid-drag removes the pointer listeners", () => {
363
+ const activeHarness = mountHarness()
364
+
365
+ const { onDrop } = activeHarness
366
+
367
+ dragIntoLane(activeHarness)
368
+
369
+ activeHarness.root.unmount()
370
+
371
+ activeHarness.host.remove()
372
+
373
+ harness = null
374
+
375
+ firePointer("pointerup", { x: 60, y: 100 })
376
+
377
+ expect(onDrop).not.toHaveBeenCalled()
378
+
379
+ // And nothing was armed to eat the page's next click.
380
+ const button = document.createElement("button")
381
+
382
+ const onClick = vi.fn()
383
+
384
+ button.addEventListener("click", onClick)
385
+
386
+ document.body.append(button)
387
+
388
+ try {
389
+ button.click()
390
+
391
+ expect(onClick).toHaveBeenCalledTimes(1)
392
+ } finally {
393
+ button.remove()
394
+ }
395
+ })
@@ -139,6 +139,82 @@ export const getIndicatorOffset = (
139
139
  )
140
140
  }
141
141
 
142
+ /**
143
+ * Swallows the one synthetic `click` that a finished drag produces.
144
+ *
145
+ * Swallowed in the **capture** phase, so it consumes the click this
146
+ * gesture produced before the handle's own listener sees it. A
147
+ * `hasDragged` flag on the card would be the same idea with a
148
+ * lifetime nobody owns.
149
+ *
150
+ * The blocker must not outlive that click, and a drag does not
151
+ * always produce one: a touch that travelled is not a tap, and a
152
+ * `pointerup` outside the handle without pointer capture lands its
153
+ * click on an ancestor or nowhere. So it also disarms on the next
154
+ * `pointerdown` or `keydown` (a new gesture has begun, and the old
155
+ * one's click would already have arrived) and after a short timer
156
+ * (for a click with no gesture in front of it, such as a screen
157
+ * reader's activation).
158
+ *
159
+ * And it swallows only a click that could be the gesture's own: one
160
+ * on the handle (where pointer capture sends it), or on an ancestor
161
+ * of the handle (where a `pointerup` that left the handle without
162
+ * capture sends it). A click on any other control passes, so a
163
+ * bystander is never the one that pays.
164
+ */
165
+ const CLICK_BLOCK_MS = 400
166
+
167
+ const blockNextClick = (handle: Element) => {
168
+ const swallow = (clickEvent: MouseEvent) => {
169
+ const { target } = clickEvent
170
+
171
+ if (
172
+ !(target instanceof Node) ||
173
+ !target.contains(handle)
174
+ ) {
175
+ return
176
+ }
177
+
178
+ clickEvent.preventDefault()
179
+
180
+ clickEvent.stopPropagation()
181
+
182
+ disarm()
183
+ }
184
+
185
+ const timer = globalThis.setTimeout(() => {
186
+ disarm()
187
+ }, CLICK_BLOCK_MS)
188
+
189
+ function disarm() {
190
+ globalThis.clearTimeout(timer)
191
+
192
+ globalThis.removeEventListener("click", swallow, {
193
+ capture: true,
194
+ })
195
+
196
+ globalThis.removeEventListener("pointerdown", disarm, {
197
+ capture: true,
198
+ })
199
+
200
+ globalThis.removeEventListener("keydown", disarm, {
201
+ capture: true,
202
+ })
203
+ }
204
+
205
+ globalThis.addEventListener("click", swallow, {
206
+ capture: true,
207
+ })
208
+
209
+ globalThis.addEventListener("pointerdown", disarm, {
210
+ capture: true,
211
+ })
212
+
213
+ globalThis.addEventListener("keydown", disarm, {
214
+ capture: true,
215
+ })
216
+ }
217
+
142
218
  export const useBoardDrag = ({
143
219
  itemSelector = "[data-board-card]",
144
220
  onDrop,
@@ -195,6 +271,16 @@ export const useBoardDrag = ({
195
271
  */
196
272
  const dragRef = useRef<BoardDragState | null>(null)
197
273
 
274
+ /**
275
+ * Removes the listeners of the gesture in progress, if there is
276
+ * one. Kept in a ref so an unmount can call it: the pointer
277
+ * listeners live on `globalThis`, and a component that unmounts
278
+ * mid-drag (a route change, a lane that closes) would otherwise
279
+ * leave them there, and the next `pointerup` anywhere on the page
280
+ * would commit a drop for a board that no longer exists.
281
+ */
282
+ const stopGestureRef = useRef<(() => void) | null>(null)
283
+
198
284
  const setDragState = useCallback(
199
285
  (next: BoardDragState | null) => {
200
286
  dragRef.current = next
@@ -330,7 +416,7 @@ export const useBoardDrag = ({
330
416
  })
331
417
  }
332
418
 
333
- const finish = (isCommitted: boolean) => {
419
+ const stopGesture = () => {
334
420
  globalThis.removeEventListener(
335
421
  "pointermove",
336
422
  onPointerMove,
@@ -343,6 +429,14 @@ export const useBoardDrag = ({
343
429
  onCancel,
344
430
  )
345
431
 
432
+ if (stopGestureRef.current === stopGesture) {
433
+ stopGestureRef.current = null
434
+ }
435
+ }
436
+
437
+ const finish = (isCommitted: boolean) => {
438
+ stopGesture()
439
+
346
440
  const live = dragRef.current
347
441
 
348
442
  setDragState(null)
@@ -358,20 +452,14 @@ export const useBoardDrag = ({
358
452
  * every completed drag lands the card and then opens a menu
359
453
  * on top of it.
360
454
  *
361
- * Swallowed in the **capture** phase and `once`, so it
362
- * consumes exactly the synthetic click this gesture
363
- * produced and nothing after it. A `hasDragged` flag on the
364
- * card would be the same idea with a lifetime nobody owns.
455
+ * Only a `pointerup` gets the blocker. A `pointercancel`
456
+ * produces no `click` at all — the browser took the
457
+ * gesture — so a blocker installed there waits for the
458
+ * next REAL click, anywhere on the page, and eats it.
365
459
  */
366
- globalThis.addEventListener(
367
- "click",
368
- (clickEvent) => {
369
- clickEvent.preventDefault()
370
-
371
- clickEvent.stopPropagation()
372
- },
373
- { capture: true, once: true },
374
- )
460
+ if (isCommitted) {
461
+ blockNextClick(handle)
462
+ }
375
463
 
376
464
  if (isCommitted && live.target) {
377
465
  onDrop(origin, live.target)
@@ -384,10 +472,28 @@ export const useBoardDrag = ({
384
472
  }
385
473
  }
386
474
 
387
- const onCancel = () => {
388
- finish(false)
475
+ const onCancel = (cancelEvent: PointerEvent) => {
476
+ if (
477
+ cancelEvent.pointerId === pointerEvent.pointerId
478
+ ) {
479
+ finish(false)
480
+ }
481
+ }
482
+
483
+ // A second press while a gesture is live (another finger, or
484
+ // a pointer whose `pointerup` never arrived) replaces the
485
+ // first gesture rather than stacking listeners beside it. Its
486
+ // drag state goes with it: otherwise this press, released
487
+ // without moving, would drop ITS card on the first gesture's
488
+ // target.
489
+ if (stopGestureRef.current) {
490
+ stopGestureRef.current()
491
+
492
+ setDragState(null)
389
493
  }
390
494
 
495
+ stopGestureRef.current = stopGesture
496
+
391
497
  globalThis.addEventListener(
392
498
  "pointermove",
393
499
  onPointerMove,
@@ -408,6 +514,13 @@ export const useBoardDrag = ({
408
514
  * component unmounts mid-drag — which is exactly what a route
409
515
  * change during a drag does.
410
516
  */
517
+ useEffect(
518
+ () => () => {
519
+ stopGestureRef.current?.()
520
+ },
521
+ [],
522
+ )
523
+
411
524
  useEffect(() => {
412
525
  const onKeyDown = (keyEvent: KeyboardEvent) => {
413
526
  if (keyEvent.key === "Escape" && dragRef.current) {
@@ -6,7 +6,7 @@
6
6
  *
7
7
  * 1. **`navigator.clipboard.writeText`.** The real API. It exists
8
8
  * only in a *secure context*, which a `devshare` URL and
9
- * `localhost` both are — and a plain `http://storeman.octen:8080`
9
+ * `localhost` both are — and a plain `http://truenas-host:8080`
10
10
  * dev server is not.
11
11
  * 2. **A hidden `<textarea>` plus `document.execCommand("copy")`.**
12
12
  * Deprecated, and kept anyway: it is the only thing that works in
package/src/Main/Main.mdx CHANGED
@@ -23,7 +23,7 @@ The owner's complaint, verbatim:
23
23
 
24
24
  ## The width is a value, not a constant
25
25
 
26
- The cap is the least standardized number in the fleet: `max-w-5xl` (board-games, portly),
26
+ The cap is the least standardized number in the fleet: `max-w-5xl` (board-games, sibling-app),
27
27
  `max-w-6xl` *and* `max-w-3xl` mixed inside one app (mux-magic), `max-w-7xl`
28
28
  (gallery-downloader, spoolbuddy), `max-w-[90rem]` (mail-sifter), `80rem` (points-market), a
29
29
  raw `1400px` in plain CSS (plex-channels), a JS-computed one (rip-deck), and none at all in
package/src/Nav/Nav.mdx CHANGED
@@ -159,7 +159,7 @@ reason `IconButton` requires `label`.
159
159
 
160
160
  | Layout | For |
161
161
  | --- | --- |
162
- | `bar` | three to six destinations, and a grid that wants every pixel — ai-usage, folio, mux-magic, portly-controllers. Folds itself; needs no `useNavLayout`. |
162
+ | `bar` | three to six destinations, and a grid that wants every pixel — ai-usage, folio, mux-magic, sibling-app. Folds itself; needs no `useNavLayout`. |
163
163
  | `rail` / `railIcons` | seven or more, or a pipeline you read down — Docket, mail-sifter, QueuePilot |
164
164
  | `bottom` | three or four you switch between constantly, in the Narrow View only |
165
165
  | `menu` | the Narrow View of a `rail` app |
@@ -152,7 +152,7 @@ type Story = StoryObj<typeof Nav>
152
152
 
153
153
  /**
154
154
  * A header row, which is what an app with a handful of destinations
155
- * wants: ai-usage, folio, mux-magic, portly-controllers.
155
+ * wants: ai-usage, folio, mux-magic, sibling-app.
156
156
  */
157
157
  export const Playground: Story = {
158
158
  parameters: playgroundParameters,
@@ -4,7 +4,7 @@
4
4
  *
5
5
  * Ten repos hand-roll their page chrome and **no two of them cap
6
6
  * the column at the same width**: `max-w-5xl` (board-games,
7
- * portly), `max-w-6xl` and `max-w-3xl` mixed inside one app
7
+ * sibling-app), `max-w-6xl` and `max-w-3xl` mixed inside one app
8
8
  * (mux-magic), `max-w-7xl` (gallery-downloader, spoolbuddy),
9
9
  * `max-w-[90rem]` (mail-sifter), `80rem` (points-market), a raw
10
10
  * `1400px` in plain CSS (plex-channels), a JS-computed one
@@ -372,7 +372,7 @@ test("the barrel is the only place components are re-exported", async () => {
372
372
  // components: +1 → 29. The picker family adds `Listbox` (single-select)
373
373
  // and `Combobox` (searchable/virtualized): +2 → 31.
374
374
  // `Swatch` — a colour as content with a required name, the one
375
- // colour the system does not own — comes out of `portly-controllers`,
375
+ // colour the system does not own — comes out of `sibling-app`,
376
376
  // the fleet's newest consumer: +1 -> 32.
377
377
  //
378
378
  // The boolean-input family fills the gap `mux-magic`'s `BooleanField`