@wardic/dom 1.4.0 → 1.5.0-next.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.
Files changed (60) hide show
  1. package/dist/Color.d.ts +2 -1
  2. package/dist/Color.d.ts.map +1 -1
  3. package/dist/Color.js +3 -1
  4. package/dist/Color.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1 -1
  8. package/dist/index.js.map +1 -1
  9. package/dist/internal/colorSpaces.d.ts +8 -0
  10. package/dist/internal/colorSpaces.d.ts.map +1 -0
  11. package/dist/internal/colorSpaces.js +26 -0
  12. package/dist/internal/colorSpaces.js.map +1 -0
  13. package/dist/internal/colors.d.ts +0 -7
  14. package/dist/internal/colors.d.ts.map +1 -1
  15. package/dist/internal/colors.js +3 -15
  16. package/dist/internal/colors.js.map +1 -1
  17. package/dist/internal/input.d.ts.map +1 -1
  18. package/dist/internal/input.js +18 -0
  19. package/dist/internal/input.js.map +1 -1
  20. package/dist/internal/layout-box.d.ts +29 -0
  21. package/dist/internal/layout-box.d.ts.map +1 -0
  22. package/dist/internal/layout-box.js +48 -0
  23. package/dist/internal/layout-box.js.map +1 -0
  24. package/dist/internal/measure.d.ts +1 -19
  25. package/dist/internal/measure.d.ts.map +1 -1
  26. package/dist/internal/measure.js +4 -47
  27. package/dist/internal/measure.js.map +1 -1
  28. package/dist/internal/projection.d.ts +5 -1
  29. package/dist/internal/projection.d.ts.map +1 -1
  30. package/dist/internal/projection.js +3 -3
  31. package/dist/internal/projection.js.map +1 -1
  32. package/dist/internal/reorder.d.ts +7 -0
  33. package/dist/internal/reorder.d.ts.map +1 -1
  34. package/dist/internal/reorder.js +41 -21
  35. package/dist/internal/reorder.js.map +1 -1
  36. package/dist/unstable/DragTrack.d.ts +1 -1
  37. package/dist/unstable/DragTrack.d.ts.map +1 -1
  38. package/dist/unstable/DragTrack.js +13 -2
  39. package/dist/unstable/DragTrack.js.map +1 -1
  40. package/dist/unstable/Feature.d.ts +3 -2
  41. package/dist/unstable/Feature.d.ts.map +1 -1
  42. package/dist/unstable/Feature.js +3 -2
  43. package/dist/unstable/Feature.js.map +1 -1
  44. package/dist/unstable/PresenceController.d.ts +36 -0
  45. package/dist/unstable/PresenceController.d.ts.map +1 -1
  46. package/dist/unstable/PresenceController.js +27 -3
  47. package/dist/unstable/PresenceController.js.map +1 -1
  48. package/package.json +3 -3
  49. package/src/Color.ts +2 -1
  50. package/src/index.ts +1 -1
  51. package/src/internal/colorSpaces.ts +27 -0
  52. package/src/internal/colors.ts +3 -36
  53. package/src/internal/input.ts +18 -0
  54. package/src/internal/layout-box.ts +57 -0
  55. package/src/internal/measure.ts +4 -47
  56. package/src/internal/projection.ts +9 -5
  57. package/src/internal/reorder.ts +51 -24
  58. package/src/unstable/DragTrack.ts +22 -3
  59. package/src/unstable/Feature.ts +4 -3
  60. package/src/unstable/PresenceController.ts +28 -5
@@ -504,6 +504,23 @@ const focusWithin = (target: unknown): boolean => {
504
504
  return (target as Node).contains(active)
505
505
  }
506
506
 
507
+ /**
508
+ * The focus on `target` now, or inside it, as its focus feed would tell it (core's `InputSource.focusNow`):
509
+ * shown as the element focus is on shows it, the target's own when it's that element. `None` while focus
510
+ * is neither on it nor inside it.
511
+ */
512
+ // Probe: hooks-first, the Reorder round's RF4. As `focusAmongOf` tells a member a focus already within it.
513
+ const focusNow = (target: unknown): Option.Option<InputSource.FocusLikeEvent> => {
514
+ if (Bool.not(focusWithin(target))) return Option.none()
515
+ const win = windowOf(target)
516
+ return Option.map(Option.fromNullOr(deepActiveOf(win.document)), (active): InputSource.FocusLikeEvent => ({
517
+ type: "focus",
518
+ timeStamp: win.performance.now(),
519
+ visible: focusVisible(active),
520
+ fromTarget: active === target,
521
+ }))
522
+ }
523
+
507
524
  // --- Feeds over many targets (#665's PR 5, Q56): a Batch's members, from one listener set ------------
508
525
 
509
526
  /**
@@ -747,6 +764,7 @@ const make = Effect.gen(function* () {
747
764
  focus,
748
765
  keyboard,
749
766
  focusWithin,
767
+ focusNow,
750
768
  adoptPointer: adoptPointerIn(adopters),
751
769
  pointerAmong,
752
770
  focusAmong,
@@ -0,0 +1,57 @@
1
+ /**
2
+ * The two box readers, in a module of their own (probe: hooks-first), apart from `measure.ts`'s other
3
+ * reads. A presence's pop and a binding's `measureLayoutBox` use these in every app; the rest of
4
+ * `measure.ts` is the Projection system's alone. A bundler splits by module, not by function: with
5
+ * all of them in one module, a page that might fetch the layout Feature later carried every read in
6
+ * its first chunk.
7
+ *
8
+ * @module
9
+ */
10
+ import type * as Probe from "@wardic/core/Probe"
11
+ import { pending as appearRuns } from "./appear-slot.ts"
12
+
13
+ /**
14
+ * Read `el`'s box AS IT CURRENTLY RENDERS — a raw `getBoundingClientRect`, no
15
+ * transform reset. The projection measure pass uses this because it resets the
16
+ * whole tree's transforms in its own WRITE phase first, so by the time it reads,
17
+ * nothing is transformed (see `runMeasurePass`). A lone caller wants
18
+ * {@link measureLayoutBox} instead.
19
+ */
20
+ export const readLayoutBox = (el: HTMLElement): Probe.Bounds => {
21
+ const r = el.getBoundingClientRect()
22
+ return {
23
+ x: r.x,
24
+ y: r.y,
25
+ width: r.width,
26
+ height: r.height,
27
+ top: r.top,
28
+ right: r.right,
29
+ bottom: r.bottom,
30
+ left: r.left,
31
+ }
32
+ }
33
+
34
+ /**
35
+ * Measures `el`'s box where the layout puts it: its own `transform` is cleared for the read and put
36
+ * back, so an animation running on it doesn't move the reading. Its ancestors' transforms still
37
+ * count. The box is in the viewport: `x`, `y`, `width`, `height`, and its edges.
38
+ *
39
+ * @example
40
+ * const box = measureLayoutBox(card)
41
+ * @see https://wardic.dev/reference/solid/layout/measure-layout-box
42
+ */
43
+ // The inline transform is blanked, the rect read, and the exact prior value restored in a `finally`, so
44
+ // a throwing getBoundingClientRect can't leave the element reset. For one element only: inside a tree
45
+ // pass an ancestor's transform pollutes the reading too, and the `finally` restores before the next
46
+ // element is read, which is why the projection pass hoists the reset out to pass level instead.
47
+ export const measureLayoutBox = (el: HTMLElement): Probe.Bounds => {
48
+ const saved = el.style.transform
49
+ el.style.transform = ""
50
+ // An Appear animation not yet handed off (#245): its CSS transform beats an inline one, not an important one.
51
+ if (appearRuns(el)) el.style.setProperty("transform", "none", "important")
52
+ try {
53
+ return readLayoutBox(el)
54
+ } finally {
55
+ el.style.transform = saved
56
+ }
57
+ }
@@ -13,14 +13,13 @@
13
13
  */
14
14
  import * as Drag from "@wardic/core/Drag"
15
15
  import type * as Point from "@wardic/core/Point"
16
- import type * as Probe from "@wardic/core/Probe"
17
16
  import * as Arr from "effect/Array"
18
17
  import * as Bool from "effect/Boolean"
19
18
  import { constVoid } from "effect/Function"
20
19
  import * as Option from "effect/Option"
21
20
  import * as Predicate from "effect/Predicate"
22
21
  import * as Str from "effect/String"
23
- import { pending as appearRuns } from "./appear-slot.ts"
22
+ import { measureLayoutBox } from "./layout-box.ts"
24
23
 
25
24
  /**
26
25
  * The document timeline's time, in ms. Inside a Refresh frame (its rAF callbacks, their microtasks,
@@ -38,51 +37,9 @@ export const frameTime = (): number => {
38
37
  return -1
39
38
  }
40
39
 
41
- /**
42
- * Read `el`'s box AS IT CURRENTLY RENDERS — a raw `getBoundingClientRect`, no
43
- * transform reset. The projection measure pass uses this because it resets the
44
- * whole tree's transforms in its own WRITE phase first, so by the time it reads,
45
- * nothing is transformed (see `runMeasurePass`). A lone caller wants
46
- * {@link measureLayoutBox} instead.
47
- */
48
- export const readLayoutBox = (el: HTMLElement): Probe.Bounds => {
49
- const r = el.getBoundingClientRect()
50
- return {
51
- x: r.x,
52
- y: r.y,
53
- width: r.width,
54
- height: r.height,
55
- top: r.top,
56
- right: r.right,
57
- bottom: r.bottom,
58
- left: r.left,
59
- }
60
- }
61
-
62
- /**
63
- * Measures `el`'s box where the layout puts it: its own `transform` is cleared for the read and put
64
- * back, so an animation running on it doesn't move the reading. Its ancestors' transforms still
65
- * count. The box is in the viewport: `x`, `y`, `width`, `height`, and its edges.
66
- *
67
- * @example
68
- * const box = measureLayoutBox(card)
69
- * @see https://wardic.dev/reference/solid/layout/measure-layout-box
70
- */
71
- // The inline transform is blanked, the rect read, and the exact prior value restored in a `finally`, so
72
- // a throwing getBoundingClientRect can't leave the element reset. For one element only: inside a tree
73
- // pass an ancestor's transform pollutes the reading too, and the `finally` restores before the next
74
- // element is read, which is why the projection pass hoists the reset out to pass level instead.
75
- export const measureLayoutBox = (el: HTMLElement): Probe.Bounds => {
76
- const saved = el.style.transform
77
- el.style.transform = ""
78
- // An Appear animation not yet handed off (#245): its CSS transform beats an inline one, not an important one.
79
- if (appearRuns(el)) el.style.setProperty("transform", "none", "important")
80
- try {
81
- return readLayoutBox(el)
82
- } finally {
83
- el.style.transform = saved
84
- }
85
- }
40
+ // The two box readers are `layout-box.ts`'s (probe: hooks-first): what every app reads, in a module
41
+ // apart from the rest here, which is the Projection system's alone.
42
+ export { measureLayoutBox, readLayoutBox } from "./layout-box.ts"
86
43
 
87
44
  /**
88
45
  * The bounds on `element`'s x/y that keep it inside `container` (Motion's element `dragConstraints`):
@@ -1106,9 +1106,13 @@ export interface ProjectionSystem extends Inspectable.Inspectable {
1106
1106
  * handleLeave} declined: each crossfades onto its other twin, following the leaver's own exit.
1107
1107
  * `onDone` once every handover has ended; the returned call drops them at once. `None` when it held
1108
1108
  * none, so presence runs its exit alone.
1109
+ *
1110
+ * `live` (probe: hooks-first): `el` is a layout node still, where a presence child's has ended by
1111
+ * now. A hook's ward outlives its place on the page and runs its own exit, so a list's row that
1112
+ * lays out is one as it leaves: the twins inside it are handed back all the same.
1109
1113
  */
1110
1114
  // ADR-0010 *Amendment (#181)*.
1111
- readonly handBackWithin: (el: HTMLElement, onDone: () => void) => Option.Option<() => void>
1115
+ readonly handBackWithin: (el: HTMLElement, onDone: () => void, live?: boolean) => Option.Option<() => void>
1112
1116
  /**
1113
1117
  * A presence child leaving with nobody to take its twins over: the twins it held as it went, inside it
1114
1118
  * or it a twin itself, stay a later twin's to take over while it's on the page, until the returned
@@ -5734,9 +5738,9 @@ export const makeProjectionSystem = (
5734
5738
  * once every one's handover has ended; the call returned drops them at once (an interrupted exit).
5735
5739
  * `undefined` when it held none.
5736
5740
  */
5737
- const doHandBackWithin = (el: HTMLElement, onDone: () => void): (() => void) | undefined => {
5741
+ const doHandBackWithin = (el: HTMLElement, onDone: () => void, live: boolean): (() => void) | undefined => {
5738
5742
  touchLeavers()
5739
- if (elementToNode.has(el)) return undefined
5743
+ if (Bool.and(Bool.not(live), elementToNode.has(el))) return undefined
5740
5744
  if (isHeldTwin(el)) return undefined
5741
5745
  const twins = reintroduceTwinsWithin(el, (held) =>
5742
5746
  UndefinedOr.map(held.chain, (chain) =>
@@ -5775,9 +5779,9 @@ export const makeProjectionSystem = (
5775
5779
  Effect.sync(() => doHandleLeave(el, onDone)).pipe(Spans.withSpan("wardic.projection.handleLeave")),
5776
5780
  )
5777
5781
 
5778
- const handBackWithin: ProjectionSystem["handBackWithin"] = (el, onDone) =>
5782
+ const handBackWithin: ProjectionSystem["handBackWithin"] = (el, onDone, live) =>
5779
5783
  runtime.runSync(
5780
- Effect.sync(() => Option.fromUndefinedOr(doHandBackWithin(el, onDone))).pipe(
5784
+ Effect.sync(() => Option.fromUndefinedOr(doHandBackWithin(el, onDone, live === true))).pipe(
5781
5785
  Spans.withSpan("wardic.projection.handBackWithin"),
5782
5786
  ),
5783
5787
  )
@@ -163,6 +163,14 @@ export interface ReorderControllerOptions<V> {
163
163
  /** Hears each **Reorder hold**'s end, once, whatever ended it; after `onReorderEnd` when it moved. */
164
164
  // #348.
165
165
  readonly onHoldEnd?: ((end: ReorderHoldEnd<V>) => void) | undefined
166
+ /**
167
+ * What makes two of the app's values one item, where its list makes them again (a refetch, a store's
168
+ * copy): the group matches by it (core's `GroupOptions.key`), and so does the controller, in an item's
169
+ * index, its element, its hold and its lift, and in its check of an order it asked for. So an item made
170
+ * again keeps its place, its drag and its keyboard lift. Left out, values match by identity.
171
+ */
172
+ // Probe: hooks-first, the Reorder round.
173
+ readonly key?: ((value: V) => unknown) | undefined
166
174
  /** The app's axis, overriding detection; `None` to detect. */
167
175
  readonly axis?: (() => Option.Option<Reorder.Axis>) | undefined
168
176
  /** Called when the detected axis changes (once the items are laid out, or {@link ReorderController.resolve}). */
@@ -274,7 +282,19 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
274
282
  let asked: ReadonlyArray<V> | undefined
275
283
  /** The app's axis, if it sets one. */
276
284
  const appAxis = (): Option.Option<Reorder.Axis> => Option.flatMap(Option.fromUndefinedOr(options.axis), (axis) => axis())
285
+ /** What an item is known by: its `key`, else the value itself. */
286
+ const idOf: (value: V) => unknown = UndefinedOr.match(options.key, { onUndefined: () => identity, onDefined: identity })
287
+ /** Whether two values are one item, as the group matches them. */
288
+ const same = (self: V, that: V): boolean => idOf(self) === idOf(that)
289
+ /** Whether two orders hold the same items in the same order, as the group matches them. */
290
+ const sameItems = Arr.makeEquivalence(same)
291
+ /**
292
+ * `value` as the app's values hold it now, for what the controller tells the app: the object made again
293
+ * under its `key`, where an item kept its first; itself without a key, or once it has left them.
294
+ */
295
+ const latest = (value: V): V => Option.getOrElse(Arr.findFirst(options.values(), (v) => same(v, value)), () => value)
277
296
  const group = Reorder.make<V>({
297
+ key: options.key,
278
298
  values: options.values,
279
299
  onReorder: (values) => {
280
300
  // A copy of what it hands on: an app that keeps that array, a store's own, may change it in place (#721).
@@ -290,6 +310,8 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
290
310
  }),
291
311
  debug,
292
312
  })
313
+ /** Whether `value` is the lifted item. */
314
+ const isLiftedValue = (value: V): boolean => Option.exists(Reorder.liftedValue(group), (lifted) => same(lifted, value))
293
315
 
294
316
  let detected: Reorder.Axis = "y"
295
317
  let reported: Reorder.Axis | undefined
@@ -302,14 +324,14 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
302
324
  if (Predicate.isNotUndefined(options.onAxis)) options.onAxis(detected)
303
325
  }
304
326
  // --- The keyboard reorder (ADR-0037) ---------------------------------------
305
- /** The lifted item's element, its handle and its `onLift`, by value, while it's registered. */
327
+ /** The lifted item's element, its handle and its `onLift`, by what it's known by (`idOf`), while it's registered. */
306
328
  interface Keyed {
307
329
  readonly element: () => Option.Option<Element>
308
330
  handle: Option.Option<ReorderItemHandle>
309
331
  readonly onLift: (lifted: boolean) => void
310
332
  }
311
- const keyed = new Map<V, Keyed>()
312
- const keyedOf = (value: V): Option.Option<Keyed> => Option.fromUndefinedOr(keyed.get(value))
333
+ const keyed = new Map<unknown, Keyed>()
334
+ const keyedOf = (value: V): Option.Option<Keyed> => Option.fromUndefinedOr(keyed.get(idOf(value)))
313
335
  const elementOf = (value: V): Option.Option<Element> => Option.flatMap(keyedOf(value), (k) => k.element())
314
336
  // The item whose new place the next layout lays out, to scroll into view then.
315
337
  const reveal = MutableRef.make(Option.none<V>())
@@ -329,40 +351,42 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
329
351
  ...(Reorder.defaultAnnouncements as Reorder.Announcements<V>),
330
352
  ...Option.getOrUndefined(Option.flatMap(Option.fromUndefinedOr(options.announcements), (announcements) => announcements())),
331
353
  })
332
- const say = (kind: keyof Reorder.Announcements<V>, value: V, placement: Reorder.Placement): string =>
333
- wording()[kind]({ value, label: labelOf(elementOf(value), value), position: placement.position, count: placement.count })
354
+ const say = (kind: keyof Reorder.Announcements<V>, value: V, placement: Reorder.Placement): string => {
355
+ const now = latest(value)
356
+ return wording()[kind]({ value: now, label: labelOf(elementOf(value), now), position: placement.position, count: placement.count })
357
+ }
334
358
 
335
359
  /** Raise the lifted item (or lower it) and tell its binding (its `whileDrag`). */
336
360
  const setLifted = (value: V, lifted: boolean): void => {
337
- const k = keyed.get(value)
361
+ const k = keyed.get(idOf(value))
338
362
  if (Predicate.isUndefined(k)) return
339
363
  if (Option.isSome(k.handle)) k.handle.value.setLifted(lifted)
340
364
  k.onLift(lifted)
341
365
  }
342
- /** `value`'s index in the app's values now. */
343
- const indexOf = (value: V): number => options.values().indexOf(value)
366
+ /** `value`'s index in the app's values now, found as the group matches its items; -1 when it isn't there. */
367
+ const indexOf = (value: V): number => Option.getOrElse(Arr.findFirstIndex(options.values(), (v) => same(v, value)), () => -1)
344
368
  /** The end of a user's reorder of `value`, begun at `from`: told when it moved (#257 item 3). */
345
369
  const ended = (value: V, from: number): void => {
346
370
  const to = indexOf(value)
347
371
  if (to === from) return
348
- UndefinedOr.map(options.onReorderEnd, (tell) => tell({ values: [...options.values()], value, from, to }))
372
+ UndefinedOr.map(options.onReorderEnd, (tell) => tell({ values: [...options.values()], value: latest(value), from, to }))
349
373
  }
350
374
  // --- Holds (#348) ------------------------------------------------------------
351
375
  /** The open **Reorder hold**: the item in hand, how it was taken, and its index then. One at a time. */
352
376
  let held: Option.Option<{ readonly value: V; readonly from: number; readonly by: "drag" | "lift" }> = Option.none()
353
377
  /** Whether `value`'s drag is the open hold: a drag a later hold took over tells nothing more. */
354
- const holdsDrag = (value: V): boolean => Option.exists(held, (h) => h.by === "drag" && h.value === value)
378
+ const holdsDrag = (value: V): boolean => Option.exists(held, (h) => h.by === "drag" && same(h.value, value))
355
379
  const holdStart = (value: V, from: number, by: "drag" | "lift"): void => {
356
380
  held = Option.some({ value, from, by })
357
- UndefinedOr.map(options.onHoldStart, (tell) => tell({ value, from }))
381
+ UndefinedOr.map(options.onHoldStart, (tell) => tell({ value: latest(value), from }))
358
382
  }
359
383
  /** End `value`'s hold, `how`: told once, and only for the open one. */
360
384
  const holdEnd = (value: V, how: ReorderHoldHow): void =>
361
- Option.match(Option.filter(held, (h) => h.value === value), {
385
+ Option.match(Option.filter(held, (h) => same(h.value, value)), {
362
386
  onNone: constVoid,
363
387
  onSome: (h) => {
364
388
  held = Option.none()
365
- UndefinedOr.map(options.onHoldEnd, (tell) => tell({ values: [...options.values()], value, from: h.from, to: indexOf(value), how }))
389
+ UndefinedOr.map(options.onHoldEnd, (tell) => tell({ values: [...options.values()], value: latest(value), from: h.from, to: indexOf(value), how }))
366
390
  },
367
391
  })
368
392
 
@@ -409,7 +433,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
409
433
  if (Bool.not(event.fromTarget)) return
410
434
  // Keys during a pointer drag are left alone.
411
435
  if (Reorder.isDragging(group)) return
412
- const lifted = Option.contains(Reorder.liftedValue(group), value)
436
+ const lifted = isLiftedValue(value)
413
437
  Option.match(Reorder.keyIntent(event.key), {
414
438
  onNone: constVoid,
415
439
  onSome: (intent) =>
@@ -514,7 +538,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
514
538
  // Its index at the drag's start, for its `onReorderEnd` (#257 item 3).
515
539
  let draggedFrom = -1
516
540
  const k: Keyed = { element: itemElement, handle: Option.none(), onLift }
517
- keyed.set(value, k)
541
+ keyed.set(idOf(value), k)
518
542
  const end = (): void => {
519
543
  inGesture = false
520
544
  Reorder.dragEnd(group, value)
@@ -536,7 +560,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
536
560
  layoutVersion: handle.layoutVersion,
537
561
  })
538
562
  k.handle = Option.some(handle)
539
- keyed.set(value, k)
563
+ keyed.set(idOf(value), k)
540
564
  return () => {
541
565
  if (Option.contains(k.handle, handle)) k.handle = Option.none()
542
566
  unregister()
@@ -571,20 +595,20 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
571
595
  },
572
596
  onKey: onKeyOf(value),
573
597
  onBlur: () => {
574
- if (Bool.not(Option.contains(Reorder.liftedValue(group), value))) return
598
+ if (Bool.not(isLiftedValue(value))) return
575
599
  // A reorder can blur the node it moves; focus was put back on it, so it's no interruption.
576
600
  if (focused(value)) return
577
601
  dropLifted()
578
602
  },
579
603
  onPress: () => {
580
- if (Option.contains(Reorder.liftedValue(group), value)) dropLifted()
604
+ if (isLiftedValue(value)) dropLifted()
581
605
  },
582
606
  dispose: () => {
583
607
  if (inGesture) end()
584
608
  // Unmounted while lifted: the lift ends, unsaid.
585
- if (Option.contains(Reorder.liftedValue(group), value)) Reorder.drop(group, value)
609
+ if (isLiftedValue(value)) Reorder.drop(group, value)
586
610
  holdEnd(value, "unmount")
587
- if (keyed.get(value) === k) keyed.delete(value)
611
+ if (keyed.get(idOf(value)) === k) keyed.delete(idOf(value))
588
612
  },
589
613
  }
590
614
  }
@@ -610,7 +634,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
610
634
  valuesChanged: () => {
611
635
  // The app changed `values` itself while an item is lifted: it's dropped at its new place. The group's
612
636
  // own order is told by its items, not its array: a binding reads a store's order as a new one (#721).
613
- if (Option.isSome(Reorder.liftedValue(group)) && Bool.not(isAsked(asked, options.values()))) dropLifted()
637
+ if (Option.isSome(Reorder.liftedValue(group)) && Bool.not(isAsked(asked, options.values(), sameItems))) dropLifted()
614
638
  wiring.layOut()
615
639
  },
616
640
  dispose: () => {
@@ -625,9 +649,12 @@ const noop = (): void => {}
625
649
  /** Whether two orders hold the same items in the same order. */
626
650
  export const sameOrder: Equivalence.Equivalence<ReadonlyArray<unknown>> = Arr.makeEquivalence(Equivalence.strictEqual())
627
651
 
628
- /** Whether `values` is the order the group last asked for (ADR-0037, *Amendment (#721)*): its items, in its order. */
629
- const isAsked = (asked: ReadonlyArray<unknown> | undefined, values: ReadonlyArray<unknown>): boolean =>
630
- UndefinedOr.match(asked, { onUndefined: constFalse, onDefined: (order) => sameOrder(order, values) })
652
+ /**
653
+ * Whether `values` is the order the group last asked for (ADR-0037, *Amendment (#721)*): its items, in its
654
+ * order, matched as the group matches them (`sameItems`: by `key` where it's given).
655
+ */
656
+ const isAsked = <V>(asked: ReadonlyArray<V> | undefined, values: ReadonlyArray<V>, sameItems: Equivalence.Equivalence<ReadonlyArray<V>>): boolean =>
657
+ UndefinedOr.match(asked, { onUndefined: constFalse, onDefined: (order) => sameItems(order, values) })
631
658
 
632
659
  /**
633
660
  * A {@link ReorderController} for a server render (ADR-0021), where there's no projection
@@ -140,7 +140,9 @@ export interface DragTrackConfig {
140
140
  * Motion's `dragListener`: `false`, the element's own presses start no drag and stop no
141
141
  * release; only its **Drag controls**' starts do. Default `true`.
142
142
  */
143
- readonly listen?: boolean | undefined
143
+ // A predicate, asked of each down (probe: behaviour-runes): an element that drags from part of itself
144
+ // alone hears a press there, and any press while it doesn't (the hooks' Grips).
145
+ readonly listen?: boolean | ((down: InputSource.PointerLikeEvent) => boolean) | undefined
144
146
  }
145
147
 
146
148
  /** The drag props a track's config is read from: an element's, its axis and its constraints resolved by the binding. */
@@ -451,6 +453,23 @@ const isGrab: Predicate.Predicate<InputSource.PointerLikeEvent> = Predicate.and(
451
453
  /** A down the element adopted from its **Drag controls** (#431). */
452
454
  const isAdopted: Predicate.Predicate<InputSource.PointerLikeEvent> = (e) => e.adopted === true
453
455
 
456
+ /** A drag's `listen`: whether it hears its own presses, or which of them. */
457
+ type Listen = boolean | ((down: InputSource.PointerLikeEvent) => boolean)
458
+
459
+ /**
460
+ * Which downs grab, by the drag's `listen` (#431): every grab, only an adopted one, or one it's asked of
461
+ * and says it hears, or adopted (probe: behaviour-runes, the hooks' Grips). Built once, at module load.
462
+ */
463
+ const grabsOf: (listen: Listen) => Predicate.Predicate<InputSource.PointerLikeEvent> = Match.type<Listen>().pipe(
464
+ Match.when(true, () => isGrab),
465
+ Match.when(false, () => Predicate.and(isGrab, isAdopted)),
466
+ Match.orElse((hears) => (e: InputSource.PointerLikeEvent): boolean => {
467
+ if (Bool.not(isGrab(e))) return false
468
+ if (hears(e)) return true
469
+ return isAdopted(e)
470
+ }),
471
+ )
472
+
454
473
  /**
455
474
  * A layout node's snap to the cursor ended with no drag (#431): its drag ended at rest, back to its
456
475
  * slot. Whether there was one. A module's, not a track's (#507): a track given no Drag controls never
@@ -828,7 +847,7 @@ export const driveDragTrack = (opts: DragTrackOptions): DragTrack => {
828
847
  onDefined: (at) => () => toDragAxis(at()),
829
848
  })
830
849
  const { propagation = false } = config
831
- const listens = config.listen !== false
850
+ const listens = UndefinedOr.match(config.listen, { onUndefined: (): Listen => true, onDefined: identity })
832
851
 
833
852
  // --- Drag controls (#431), only for an element given them (#507) ----------------------------
834
853
  const controlled = Predicate.isNotUndefined(opts.controls)
@@ -960,7 +979,7 @@ export const driveDragTrack = (opts: DragTrackOptions): DragTrack => {
960
979
  onDefect,
961
980
  })
962
981
  // A down grabs when the drag listens to it (#431): with `listen: false`, only an adopted one.
963
- const grabs = Bool.match(listens, { onTrue: () => isGrab, onFalse: () => Predicate.and(isGrab, isAdopted) })
982
+ const grabs = grabsOf(listens)
964
983
  // The adoptable feed with controls (#507), so a grab hears an adopted down; the plain one without.
965
984
  const pointerFeed = Bool.match(controlled, { onTrue: () => InputSource.adoptablePointerOf(input, element), onFalse: () => input.pointer(element) })
966
985
  yield* InputFeed.watch(pointerFeed, {
@@ -471,10 +471,11 @@ export const unreadColorIn = (values: Readonly<Record<string, unknown>>): string
471
471
 
472
472
  /**
473
473
  * Development's word on a Complete element under a `strict` section (#511, ADR-0067 decision 7,
474
- * Motion's), naming the binding's `complete` forms and the `slim` ones to use.
474
+ * Motion's), naming the binding's `complete` forms and the `slim` ones to use, and `under`, where
475
+ * its `strict` was given: by default Solid 1's, a provider or a `LazyWardic`.
475
476
  */
476
- export const strictMessage = (complete: string, slim: string): string =>
477
- `wardic: a Complete element (${complete}) is rendered under a strict WardicProvider or LazyWardic. ` +
477
+ export const strictMessage = (complete: string, slim: string, under: string = "a strict WardicProvider or LazyWardic"): string =>
478
+ `wardic: a Complete element (${complete}) is rendered under ${under}. ` +
478
479
  `It brings every Feature's code with it; render the Slim element (${slim}) instead.`
479
480
 
480
481
  /** What development's word on a missing `layout` Feature names (#511): the props that need it. */
@@ -319,7 +319,9 @@ const placedOf = (el: Element): Placed => ({
319
319
  * a right-to-left one flips). An HTML one's offsets are whole pixels, the DOM's `offsetTop`; an
320
320
  * `<svg>` root's are fractional, from rects (#744).
321
321
  */
322
- interface PopBox {
322
+ // Exported for the hooks-first probe's `show` and `wards` (probe: hooks-first): a ward that pops itself as it
323
+ // leaves measures and pins as a presence's leaver does. The presence's own use is unchanged.
324
+ export interface PopBox {
323
325
  /** The element it pins: an HTML one, or an outermost `<svg>` (#744). No other SVG element is popped (#702). */
324
326
  readonly el: HTMLElement | SVGSVGElement
325
327
  readonly width: number
@@ -340,7 +342,7 @@ export interface PopAnchors {
340
342
  * A leaver's border box's gap from its containing block's padding edge on each side, in the block's
341
343
  * own pixels (#744): what an HTML one reads from its offsets, and an `<svg>` root from rects.
342
344
  */
343
- interface EdgeGaps {
345
+ export interface EdgeGaps {
344
346
  readonly left: number
345
347
  readonly top: number
346
348
  readonly right: number
@@ -376,7 +378,7 @@ const gapsNowOf = (el: Element): EdgeGaps | undefined => {
376
378
  * With `ahead`, its gaps as a binding's snapshot measured them before its framework's change (#840), the
377
379
  * box is at those, not at the gaps the change has left it with.
378
380
  */
379
- const popBoxOf = (el: Element, anchors: PopAnchors, ahead: EdgeGaps | undefined): PopBox | undefined => {
381
+ export const popBoxOf = (el: Element, anchors: PopAnchors, ahead: EdgeGaps | undefined): PopBox | undefined => {
380
382
  if (isPopped(el)) return pinBoxOf(el, anchors, (measured) => UndefinedOr.match(ahead, { onUndefined: () => gapsNowOf(measured), onDefined: identity }))
381
383
  return undefined
382
384
  }
@@ -474,7 +476,7 @@ const svgGapsOf = (el: SVGSVGElement): EdgeGaps | undefined =>
474
476
  })
475
477
 
476
478
  /** Pin a leaver where `box` measured it, out of the flow, over any style of its own. */
477
- const pin = (box: PopBox): void => {
479
+ export const pin = (box: PopBox): void => {
478
480
  const style = box.el.style
479
481
  style.setProperty("position", "absolute", "important")
480
482
  style.setProperty("width", `${box.width}px`, "important")
@@ -924,6 +926,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
924
926
  // in-flight fiber bookkeeping. Idempotent. `completed`: its exit ended on its own (#257).
925
927
  const finishExit = (el: Element, completed = true): void => {
926
928
  exiting.delete(el)
929
+ const told = toldHooks.get(el)
927
930
  toldHooks.delete(el)
928
931
  registry.delete(el)
929
932
  draws.delete(el)
@@ -956,6 +959,26 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
956
959
  if (Bool.and(moves, affectsLayout())) projection.notify()
957
960
  // Told once the node is gone, as Motion's `onExitComplete` finds it (#257).
958
961
  leaveEnds(el, completed)
962
+ // The hooks told it left hear it has gone, its exit completed (an interrupted one's heard so already).
963
+ if (completed) UndefinedOr.map(told, (hooks) => Arr.forEach(hooks, (watch) => UndefinedOr.map(watch.ended, (ended) => ended())))
964
+ }
965
+
966
+ /**
967
+ * A hold a hook takes on a leaving child after it was told it left (its `leave`'s `hold`): one more
968
+ * part of the child's exit, ended by the release it hands back, once. Nothing for a child gone
969
+ * already, or one whose parts aren't counted (it went at once).
970
+ */
971
+ const holdLate = (el: Element, counted: boolean): (() => void) => {
972
+ if (Bool.not(counted)) return constVoid
973
+ const parts = pending.get(el)
974
+ if (Predicate.isUndefined(parts)) return constVoid
975
+ pending.set(el, parts + 1)
976
+ let released = false
977
+ return () => {
978
+ if (released) return
979
+ released = true
980
+ partDone(el)
981
+ }
959
982
  }
960
983
 
961
984
  // One of a leaving child's parts ended (#181): it goes with the last. A child already removed
@@ -1511,7 +1534,7 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
1511
1534
  partDone(el)
1512
1535
  }
1513
1536
  try {
1514
- watch.leave(custom, release)
1537
+ watch.leave(custom, release, () => holdLate(el, counted))
1515
1538
  } catch (defect) {
1516
1539
  runtime.runFork(Report.failure("wardic.presence: a usePresence callback failed", Cause.die(defect)))
1517
1540
  release()