@charcuterie/ui 4.28.1 → 4.28.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/Avatar/Avatar.d.ts.map +1 -1
- package/dist/Avatar/Avatar.js +6 -15
- package/dist/Avatar/Avatar.js.map +1 -1
- package/dist/Board/useBoardDrag.d.ts.map +1 -1
- package/dist/Board/useBoardDrag.js +101 -11
- package/dist/Board/useBoardDrag.js.map +1 -1
- package/dist/CopyButton/copyText.d.ts +1 -1
- package/dist/CopyButton/copyText.js +1 -1
- package/dist/PortraitTiles/PortraitAvatar.d.ts +5 -0
- package/dist/PortraitTiles/PortraitAvatar.d.ts.map +1 -1
- package/dist/PortraitTiles/PortraitAvatar.js +9 -6
- package/dist/PortraitTiles/PortraitAvatar.js.map +1 -1
- package/dist/Shell/contentWidth.d.ts +1 -1
- package/dist/Shell/contentWidth.js +1 -1
- package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.d.ts +29 -0
- package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.d.ts.map +1 -0
- package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.js +38 -0
- package/dist/markdownEditorCodeMirror/finishParsing.testHelpers.js.map +1 -0
- package/dist/motion.testHelpers.d.ts +35 -0
- package/dist/motion.testHelpers.d.ts.map +1 -0
- package/dist/motion.testHelpers.js +44 -0
- package/dist/motion.testHelpers.js.map +1 -0
- package/dist/useImageFailure.d.ts +52 -0
- package/dist/useImageFailure.d.ts.map +1 -0
- package/dist/useImageFailure.js +71 -0
- package/dist/useImageFailure.js.map +1 -0
- package/dist/waitForImages.testHelpers.d.ts +33 -0
- package/dist/waitForImages.testHelpers.d.ts.map +1 -0
- package/dist/waitForImages.testHelpers.js +48 -0
- package/dist/waitForImages.testHelpers.js.map +1 -0
- package/package.json +1 -1
- package/src/Avatar/Avatar.test.tsx +54 -1
- package/src/Avatar/Avatar.tsx +7 -19
- package/src/Board/useBoardDrag.test.tsx +395 -0
- package/src/Board/useBoardDrag.ts +129 -16
- package/src/CopyButton/copyText.ts +1 -1
- package/src/GroupedList/GroupedList.test.tsx +22 -17
- package/src/Main/Main.mdx +1 -1
- package/src/Motion/useListMotion.test.tsx +21 -15
- package/src/Motion/usePresence.test.tsx +76 -24
- package/src/Motion/useValueChangeMotion.test.tsx +12 -9
- package/src/Nav/Nav.mdx +1 -1
- package/src/Nav/Nav.stories.tsx +1 -1
- package/src/Overlay/overlayReturnFocus.test.tsx +18 -20
- package/src/PortraitTiles/PortraitAvatar.tsx +10 -5
- package/src/PortraitTiles/PortraitTiles.test.tsx +219 -17
- package/src/Shell/contentWidth.ts +1 -1
- package/src/markdownEditorCodeMirror/MarkdownView.test.tsx +32 -11
- package/src/markdownEditorCodeMirror/finishParsing.testHelpers.ts +47 -0
- package/src/motion.testHelpers.ts +46 -0
- package/src/sourceRules.test.ts +1 -1
- package/src/useImageFailure.ts +93 -0
- package/src/waitForImages.testHelpers.ts +61 -0
|
@@ -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
|
|
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
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
*
|
|
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
|
-
|
|
367
|
-
|
|
368
|
-
|
|
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
|
-
|
|
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://
|
|
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
|
|
@@ -14,6 +14,10 @@ import { test } from "vitest"
|
|
|
14
14
|
import { userEvent as browserUserEvent } from "vitest/browser"
|
|
15
15
|
|
|
16
16
|
import { expectNoAxeViolations } from "../expectNoAxeViolations.testHelpers.ts"
|
|
17
|
+
import {
|
|
18
|
+
finishMotion,
|
|
19
|
+
HELD_MOTION,
|
|
20
|
+
} from "../motion.testHelpers.ts"
|
|
17
21
|
import { mountStory } from "../mountStory.testHelpers.ts"
|
|
18
22
|
import { expectAgentDrivable } from "../testing/index.ts"
|
|
19
23
|
import meta, * as stories from "./GroupedList.stories.tsx"
|
|
@@ -851,9 +855,10 @@ test("a group an action creates enters, and a group it empties leaves with its l
|
|
|
851
855
|
|
|
852
856
|
const host = document.createElement("div")
|
|
853
857
|
|
|
854
|
-
//
|
|
855
|
-
|
|
856
|
-
host.style.setProperty("--duration-
|
|
858
|
+
// Held, so the exit cannot finish first however busy the host is;
|
|
859
|
+
// see `HELD_MOTION`.
|
|
860
|
+
host.style.setProperty("--duration-fast", HELD_MOTION)
|
|
861
|
+
host.style.setProperty("--duration-normal", HELD_MOTION)
|
|
857
862
|
|
|
858
863
|
document.body.append(host)
|
|
859
864
|
|
|
@@ -912,12 +917,11 @@ test("a group an action creates enters, and a group it empties leaves with its l
|
|
|
912
917
|
expect(leaving?.textContent).toContain("Book")
|
|
913
918
|
|
|
914
919
|
// …and gone once it has.
|
|
915
|
-
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
)
|
|
920
|
+
finishMotion(leaving as HTMLElement)
|
|
921
|
+
|
|
922
|
+
await waitFor(() => {
|
|
923
|
+
expect(groupOf("Reading")).toBeUndefined()
|
|
924
|
+
})
|
|
921
925
|
} finally {
|
|
922
926
|
root.unmount()
|
|
923
927
|
|
|
@@ -938,8 +942,8 @@ const mountUnfrozen = () => {
|
|
|
938
942
|
|
|
939
943
|
const host = document.createElement("div")
|
|
940
944
|
|
|
941
|
-
host.style.setProperty("--duration-fast",
|
|
942
|
-
host.style.setProperty("--duration-normal",
|
|
945
|
+
host.style.setProperty("--duration-fast", HELD_MOTION)
|
|
946
|
+
host.style.setProperty("--duration-normal", HELD_MOTION)
|
|
943
947
|
|
|
944
948
|
document.body.append(host)
|
|
945
949
|
|
|
@@ -1049,12 +1053,13 @@ test("a group below one whose row has finished leaving slides up instead of jump
|
|
|
1049
1053
|
// The leaving row still holds its space, so nothing has moved yet.
|
|
1050
1054
|
expect(group.style.transition).toBe("")
|
|
1051
1055
|
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1056
|
+
// Only the leaving row's motion ends; the slide it starts is held,
|
|
1057
|
+
// so it is still in flight when the next line reads it.
|
|
1058
|
+
finishMotion(leaving)
|
|
1059
|
+
|
|
1060
|
+
await waitFor(() => {
|
|
1061
|
+
expect(leaving.isConnected).toBe(false)
|
|
1062
|
+
})
|
|
1058
1063
|
|
|
1059
1064
|
// Its gap closed, and the group below is sliding up into it.
|
|
1060
1065
|
expect(group.style.transition).toContain("translate")
|
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,
|
|
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
|