@wardic/dom 1.4.0 → 1.5.0-next.1
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/Color.d.ts +2 -1
- package/dist/Color.d.ts.map +1 -1
- package/dist/Color.js +3 -1
- package/dist/Color.js.map +1 -1
- package/dist/Report.d.ts +1 -1
- package/dist/Report.d.ts.map +1 -1
- package/dist/Report.js +1 -1
- package/dist/Report.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/internal/colorSpaces.d.ts +8 -0
- package/dist/internal/colorSpaces.d.ts.map +1 -0
- package/dist/internal/colorSpaces.js +26 -0
- package/dist/internal/colorSpaces.js.map +1 -0
- package/dist/internal/colors.d.ts +0 -7
- package/dist/internal/colors.d.ts.map +1 -1
- package/dist/internal/colors.js +3 -15
- package/dist/internal/colors.js.map +1 -1
- package/dist/internal/diagnostic-codes.d.ts +10 -0
- package/dist/internal/diagnostic-codes.d.ts.map +1 -0
- package/dist/internal/diagnostic-codes.js +38 -0
- package/dist/internal/diagnostic-codes.js.map +1 -0
- package/dist/internal/input.d.ts.map +1 -1
- package/dist/internal/input.js +18 -0
- package/dist/internal/input.js.map +1 -1
- package/dist/internal/layout-box.d.ts +29 -0
- package/dist/internal/layout-box.d.ts.map +1 -0
- package/dist/internal/layout-box.js +48 -0
- package/dist/internal/layout-box.js.map +1 -0
- package/dist/internal/measure.d.ts +1 -19
- package/dist/internal/measure.d.ts.map +1 -1
- package/dist/internal/measure.js +4 -47
- package/dist/internal/measure.js.map +1 -1
- package/dist/internal/projection.d.ts +5 -1
- package/dist/internal/projection.d.ts.map +1 -1
- package/dist/internal/projection.js +11 -10
- package/dist/internal/projection.js.map +1 -1
- package/dist/internal/reorder.d.ts +7 -0
- package/dist/internal/reorder.d.ts.map +1 -1
- package/dist/internal/reorder.js +43 -22
- package/dist/internal/reorder.js.map +1 -1
- package/dist/internal/scroll.js +1 -1
- package/dist/internal/scroll.js.map +1 -1
- package/dist/unstable/DragTrack.d.ts +1 -1
- package/dist/unstable/DragTrack.d.ts.map +1 -1
- package/dist/unstable/DragTrack.js +15 -3
- package/dist/unstable/DragTrack.js.map +1 -1
- package/dist/unstable/ElementSetup.d.ts +4 -1
- package/dist/unstable/ElementSetup.d.ts.map +1 -1
- package/dist/unstable/ElementSetup.js +6 -2
- package/dist/unstable/ElementSetup.js.map +1 -1
- package/dist/unstable/Feature.d.ts +9 -4
- package/dist/unstable/Feature.d.ts.map +1 -1
- package/dist/unstable/Feature.js +8 -6
- package/dist/unstable/Feature.js.map +1 -1
- package/dist/unstable/PointerValues.js +1 -1
- package/dist/unstable/PointerValues.js.map +1 -1
- package/dist/unstable/PresenceController.d.ts +36 -0
- package/dist/unstable/PresenceController.d.ts.map +1 -1
- package/dist/unstable/PresenceController.js +29 -5
- package/dist/unstable/PresenceController.js.map +1 -1
- package/package.json +3 -3
- package/src/Color.ts +2 -1
- package/src/Report.ts +1 -1
- package/src/index.ts +1 -1
- package/src/internal/colorSpaces.ts +27 -0
- package/src/internal/colors.ts +3 -36
- package/src/internal/diagnostic-codes.ts +46 -0
- package/src/internal/input.ts +18 -0
- package/src/internal/layout-box.ts +57 -0
- package/src/internal/measure.ts +4 -47
- package/src/internal/projection.ts +22 -12
- package/src/internal/reorder.ts +55 -26
- package/src/internal/scroll.ts +1 -1
- package/src/unstable/DragTrack.ts +27 -4
- package/src/unstable/ElementSetup.ts +8 -3
- package/src/unstable/Feature.ts +15 -10
- package/src/unstable/PointerValues.ts +1 -1
- package/src/unstable/PresenceController.ts +30 -7
package/src/internal/measure.ts
CHANGED
|
@@ -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 {
|
|
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
|
-
|
|
43
|
-
|
|
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`):
|
|
@@ -65,6 +65,7 @@ import * as Box from "@wardic/core/Box"
|
|
|
65
65
|
import * as Clock from "@wardic/core/Clock"
|
|
66
66
|
import type * as Frame from "@wardic/core/Frame"
|
|
67
67
|
import * as FrameLoop from "@wardic/core/FrameLoop"
|
|
68
|
+
import * as Diagnostic from "@wardic/core/unstable/Diagnostic"
|
|
68
69
|
import * as FirstSteps from "@wardic/core/unstable/FirstSteps"
|
|
69
70
|
import * as Inertia from "@wardic/core/Inertia"
|
|
70
71
|
import * as Microtask from "@wardic/core/Microtask"
|
|
@@ -1106,9 +1107,13 @@ export interface ProjectionSystem extends Inspectable.Inspectable {
|
|
|
1106
1107
|
* handleLeave} declined: each crossfades onto its other twin, following the leaver's own exit.
|
|
1107
1108
|
* `onDone` once every handover has ended; the returned call drops them at once. `None` when it held
|
|
1108
1109
|
* none, so presence runs its exit alone.
|
|
1110
|
+
*
|
|
1111
|
+
* `live` (probe: hooks-first): `el` is a layout node still, where a presence child's has ended by
|
|
1112
|
+
* now. A hook's ward outlives its place on the page and runs its own exit, so a list's row that
|
|
1113
|
+
* lays out is one as it leaves: the twins inside it are handed back all the same.
|
|
1109
1114
|
*/
|
|
1110
1115
|
// ADR-0010 *Amendment (#181)*.
|
|
1111
|
-
readonly handBackWithin: (el: HTMLElement, onDone: () => void) => Option.Option<() => void>
|
|
1116
|
+
readonly handBackWithin: (el: HTMLElement, onDone: () => void, live?: boolean) => Option.Option<() => void>
|
|
1112
1117
|
/**
|
|
1113
1118
|
* A presence child leaving with nobody to take its twins over: the twins it held as it went, inside it
|
|
1114
1119
|
* or it a twin itself, stay a later twin's to take over while it's on the page, until the returned
|
|
@@ -2122,7 +2127,7 @@ export const makeProjectionSystem = (
|
|
|
2122
2127
|
}
|
|
2123
2128
|
if (failing.has(corrector)) return
|
|
2124
2129
|
failing.add(corrector)
|
|
2125
|
-
runtime.runFork(Effect.annotateLogs(Report.
|
|
2130
|
+
runtime.runFork(Effect.annotateLogs(Report.callbackFailed("wardic.projection: a scale corrector failed", Cause.die(defect)), { id: node.id, key: corrector.key }))
|
|
2126
2131
|
}
|
|
2127
2132
|
|
|
2128
2133
|
/** An app's corrector's value for `node` (#443): its own for the key, a number or a string, else its base, else none. */
|
|
@@ -3836,7 +3841,7 @@ export const makeProjectionSystem = (
|
|
|
3836
3841
|
hook()
|
|
3837
3842
|
Failing.endRunOf(node, name)
|
|
3838
3843
|
} catch (defect) {
|
|
3839
|
-
if (Failing.firstThrowOf(node, name)) runtime.runFork(Report.
|
|
3844
|
+
if (Failing.firstThrowOf(node, name)) runtime.runFork(Report.callbackFailed(`wardic.projection: an ${name} failed`, Cause.die(defect)))
|
|
3840
3845
|
}
|
|
3841
3846
|
}
|
|
3842
3847
|
|
|
@@ -3894,7 +3899,7 @@ export const makeProjectionSystem = (
|
|
|
3894
3899
|
node.lastHeld = held
|
|
3895
3900
|
if (node.heldFailing) node.heldFailing = false
|
|
3896
3901
|
} catch (defect) {
|
|
3897
|
-
if (!node.heldFailing) runtime.runFork(Effect.annotateLogs(Report.
|
|
3902
|
+
if (!node.heldFailing) runtime.runFork(Effect.annotateLogs(Report.callbackFailed("wardic.projection: a transformTemplate failed at a Measure pass", Cause.die(defect)), { id: node.id }))
|
|
3898
3903
|
node.heldFailing = true
|
|
3899
3904
|
held = node.lastHeld
|
|
3900
3905
|
}
|
|
@@ -4531,7 +4536,7 @@ export const makeProjectionSystem = (
|
|
|
4531
4536
|
try {
|
|
4532
4537
|
callback()
|
|
4533
4538
|
} catch (defect) {
|
|
4534
|
-
runtime.runFork(Report.
|
|
4539
|
+
runtime.runFork(Report.callbackFailed(`wardic.projection: ${name} failed`, Cause.die(defect)))
|
|
4535
4540
|
}
|
|
4536
4541
|
}
|
|
4537
4542
|
|
|
@@ -4549,7 +4554,7 @@ export const makeProjectionSystem = (
|
|
|
4549
4554
|
callback.value()
|
|
4550
4555
|
Failing.endRunOf(node, name)
|
|
4551
4556
|
} catch (defect) {
|
|
4552
|
-
if (Failing.firstThrowOf(node, name)) runtime.runFork(Report.
|
|
4557
|
+
if (Failing.firstThrowOf(node, name)) runtime.runFork(Report.callbackFailed(`wardic.projection: ${name} failed`, Cause.die(defect)))
|
|
4553
4558
|
}
|
|
4554
4559
|
}
|
|
4555
4560
|
|
|
@@ -4657,7 +4662,12 @@ export const makeProjectionSystem = (
|
|
|
4657
4662
|
try {
|
|
4658
4663
|
const result = fn()
|
|
4659
4664
|
if (Predicate.isPromiseLike(result)) {
|
|
4660
|
-
runtime.runFork(
|
|
4665
|
+
runtime.runFork(
|
|
4666
|
+
Diagnostic.report(
|
|
4667
|
+
"WARDIC_LAYOUT_CALLBACK_PROMISE",
|
|
4668
|
+
"animateLayout's callback returned a promise, so only what it changed before its first `await` animates. Await what you need first, then call animateLayout with a callback that makes the change at once.",
|
|
4669
|
+
),
|
|
4670
|
+
)
|
|
4661
4671
|
}
|
|
4662
4672
|
return result
|
|
4663
4673
|
} finally {
|
|
@@ -4908,7 +4918,7 @@ export const makeProjectionSystem = (
|
|
|
4908
4918
|
flight.position = timing.ease(t)
|
|
4909
4919
|
if (node.easeFailing) node.easeFailing = false
|
|
4910
4920
|
} catch (defect) {
|
|
4911
|
-
if (!node.easeFailing) runtime.runFork(Effect.annotateLogs(Report.
|
|
4921
|
+
if (!node.easeFailing) runtime.runFork(Effect.annotateLogs(Report.callbackFailed("wardic.projection: a layout animation's ease failed", Cause.die(defect)), { id: node.id }))
|
|
4912
4922
|
node.easeFailing = true
|
|
4913
4923
|
if (t >= 1) flight.position = 1
|
|
4914
4924
|
}
|
|
@@ -5734,9 +5744,9 @@ export const makeProjectionSystem = (
|
|
|
5734
5744
|
* once every one's handover has ended; the call returned drops them at once (an interrupted exit).
|
|
5735
5745
|
* `undefined` when it held none.
|
|
5736
5746
|
*/
|
|
5737
|
-
const doHandBackWithin = (el: HTMLElement, onDone: () => void): (() => void) | undefined => {
|
|
5747
|
+
const doHandBackWithin = (el: HTMLElement, onDone: () => void, live: boolean): (() => void) | undefined => {
|
|
5738
5748
|
touchLeavers()
|
|
5739
|
-
if (elementToNode.has(el)) return undefined
|
|
5749
|
+
if (Bool.and(Bool.not(live), elementToNode.has(el))) return undefined
|
|
5740
5750
|
if (isHeldTwin(el)) return undefined
|
|
5741
5751
|
const twins = reintroduceTwinsWithin(el, (held) =>
|
|
5742
5752
|
UndefinedOr.map(held.chain, (chain) =>
|
|
@@ -5775,9 +5785,9 @@ export const makeProjectionSystem = (
|
|
|
5775
5785
|
Effect.sync(() => doHandleLeave(el, onDone)).pipe(Spans.withSpan("wardic.projection.handleLeave")),
|
|
5776
5786
|
)
|
|
5777
5787
|
|
|
5778
|
-
const handBackWithin: ProjectionSystem["handBackWithin"] = (el, onDone) =>
|
|
5788
|
+
const handBackWithin: ProjectionSystem["handBackWithin"] = (el, onDone, live) =>
|
|
5779
5789
|
runtime.runSync(
|
|
5780
|
-
Effect.sync(() => Option.fromUndefinedOr(doHandBackWithin(el, onDone))).pipe(
|
|
5790
|
+
Effect.sync(() => Option.fromUndefinedOr(doHandBackWithin(el, onDone, live === true))).pipe(
|
|
5781
5791
|
Spans.withSpan("wardic.projection.handBackWithin"),
|
|
5782
5792
|
),
|
|
5783
5793
|
)
|
package/src/internal/reorder.ts
CHANGED
|
@@ -56,6 +56,7 @@ import * as Str from "effect/String"
|
|
|
56
56
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
57
57
|
import { documentOf, prepareAnnouncer } from "./announcer.ts"
|
|
58
58
|
import { type AutoScroller, makeAutoScroller } from "./auto-scroll.ts"
|
|
59
|
+
import * as Diagnostic from "@wardic/core/unstable/Diagnostic"
|
|
59
60
|
import * as Report from "@wardic/core/unstable/Report"
|
|
60
61
|
import { type Rect, revealLayoutOf, revealRectOf } from "./reveal.ts"
|
|
61
62
|
import type * as WardicServices from "@wardic/core/unstable/WardicServices"
|
|
@@ -163,6 +164,14 @@ export interface ReorderControllerOptions<V> {
|
|
|
163
164
|
/** Hears each **Reorder hold**'s end, once, whatever ended it; after `onReorderEnd` when it moved. */
|
|
164
165
|
// #348.
|
|
165
166
|
readonly onHoldEnd?: ((end: ReorderHoldEnd<V>) => void) | undefined
|
|
167
|
+
/**
|
|
168
|
+
* What makes two of the app's values one item, where its list makes them again (a refetch, a store's
|
|
169
|
+
* copy): the group matches by it (core's `GroupOptions.key`), and so does the controller, in an item's
|
|
170
|
+
* index, its element, its hold and its lift, and in its check of an order it asked for. So an item made
|
|
171
|
+
* again keeps its place, its drag and its keyboard lift. Left out, values match by identity.
|
|
172
|
+
*/
|
|
173
|
+
// Probe: hooks-first, the Reorder round.
|
|
174
|
+
readonly key?: ((value: V) => unknown) | undefined
|
|
166
175
|
/** The app's axis, overriding detection; `None` to detect. */
|
|
167
176
|
readonly axis?: (() => Option.Option<Reorder.Axis>) | undefined
|
|
168
177
|
/** Called when the detected axis changes (once the items are laid out, or {@link ReorderController.resolve}). */
|
|
@@ -274,7 +283,19 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
274
283
|
let asked: ReadonlyArray<V> | undefined
|
|
275
284
|
/** The app's axis, if it sets one. */
|
|
276
285
|
const appAxis = (): Option.Option<Reorder.Axis> => Option.flatMap(Option.fromUndefinedOr(options.axis), (axis) => axis())
|
|
286
|
+
/** What an item is known by: its `key`, else the value itself. */
|
|
287
|
+
const idOf: (value: V) => unknown = UndefinedOr.match(options.key, { onUndefined: () => identity, onDefined: identity })
|
|
288
|
+
/** Whether two values are one item, as the group matches them. */
|
|
289
|
+
const same = (self: V, that: V): boolean => idOf(self) === idOf(that)
|
|
290
|
+
/** Whether two orders hold the same items in the same order, as the group matches them. */
|
|
291
|
+
const sameItems = Arr.makeEquivalence(same)
|
|
292
|
+
/**
|
|
293
|
+
* `value` as the app's values hold it now, for what the controller tells the app: the object made again
|
|
294
|
+
* under its `key`, where an item kept its first; itself without a key, or once it has left them.
|
|
295
|
+
*/
|
|
296
|
+
const latest = (value: V): V => Option.getOrElse(Arr.findFirst(options.values(), (v) => same(v, value)), () => value)
|
|
277
297
|
const group = Reorder.make<V>({
|
|
298
|
+
key: options.key,
|
|
278
299
|
values: options.values,
|
|
279
300
|
onReorder: (values) => {
|
|
280
301
|
// 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 +311,8 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
290
311
|
}),
|
|
291
312
|
debug,
|
|
292
313
|
})
|
|
314
|
+
/** Whether `value` is the lifted item. */
|
|
315
|
+
const isLiftedValue = (value: V): boolean => Option.exists(Reorder.liftedValue(group), (lifted) => same(lifted, value))
|
|
293
316
|
|
|
294
317
|
let detected: Reorder.Axis = "y"
|
|
295
318
|
let reported: Reorder.Axis | undefined
|
|
@@ -302,14 +325,14 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
302
325
|
if (Predicate.isNotUndefined(options.onAxis)) options.onAxis(detected)
|
|
303
326
|
}
|
|
304
327
|
// --- The keyboard reorder (ADR-0037) ---------------------------------------
|
|
305
|
-
/** The lifted item's element, its handle and its `onLift`, by
|
|
328
|
+
/** The lifted item's element, its handle and its `onLift`, by what it's known by (`idOf`), while it's registered. */
|
|
306
329
|
interface Keyed {
|
|
307
330
|
readonly element: () => Option.Option<Element>
|
|
308
331
|
handle: Option.Option<ReorderItemHandle>
|
|
309
332
|
readonly onLift: (lifted: boolean) => void
|
|
310
333
|
}
|
|
311
|
-
const keyed = new Map<
|
|
312
|
-
const keyedOf = (value: V): Option.Option<Keyed> => Option.fromUndefinedOr(keyed.get(value))
|
|
334
|
+
const keyed = new Map<unknown, Keyed>()
|
|
335
|
+
const keyedOf = (value: V): Option.Option<Keyed> => Option.fromUndefinedOr(keyed.get(idOf(value)))
|
|
313
336
|
const elementOf = (value: V): Option.Option<Element> => Option.flatMap(keyedOf(value), (k) => k.element())
|
|
314
337
|
// The item whose new place the next layout lays out, to scroll into view then.
|
|
315
338
|
const reveal = MutableRef.make(Option.none<V>())
|
|
@@ -329,40 +352,42 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
329
352
|
...(Reorder.defaultAnnouncements as Reorder.Announcements<V>),
|
|
330
353
|
...Option.getOrUndefined(Option.flatMap(Option.fromUndefinedOr(options.announcements), (announcements) => announcements())),
|
|
331
354
|
})
|
|
332
|
-
const say = (kind: keyof Reorder.Announcements<V>, value: V, placement: Reorder.Placement): string =>
|
|
333
|
-
|
|
355
|
+
const say = (kind: keyof Reorder.Announcements<V>, value: V, placement: Reorder.Placement): string => {
|
|
356
|
+
const now = latest(value)
|
|
357
|
+
return wording()[kind]({ value: now, label: labelOf(elementOf(value), now), position: placement.position, count: placement.count })
|
|
358
|
+
}
|
|
334
359
|
|
|
335
360
|
/** Raise the lifted item (or lower it) and tell its binding (its `whileDrag`). */
|
|
336
361
|
const setLifted = (value: V, lifted: boolean): void => {
|
|
337
|
-
const k = keyed.get(value)
|
|
362
|
+
const k = keyed.get(idOf(value))
|
|
338
363
|
if (Predicate.isUndefined(k)) return
|
|
339
364
|
if (Option.isSome(k.handle)) k.handle.value.setLifted(lifted)
|
|
340
365
|
k.onLift(lifted)
|
|
341
366
|
}
|
|
342
|
-
/** `value`'s index in the app's values now. */
|
|
343
|
-
const indexOf = (value: V): number => options.values()
|
|
367
|
+
/** `value`'s index in the app's values now, found as the group matches its items; -1 when it isn't there. */
|
|
368
|
+
const indexOf = (value: V): number => Option.getOrElse(Arr.findFirstIndex(options.values(), (v) => same(v, value)), () => -1)
|
|
344
369
|
/** The end of a user's reorder of `value`, begun at `from`: told when it moved (#257 item 3). */
|
|
345
370
|
const ended = (value: V, from: number): void => {
|
|
346
371
|
const to = indexOf(value)
|
|
347
372
|
if (to === from) return
|
|
348
|
-
UndefinedOr.map(options.onReorderEnd, (tell) => tell({ values: [...options.values()], value, from, to }))
|
|
373
|
+
UndefinedOr.map(options.onReorderEnd, (tell) => tell({ values: [...options.values()], value: latest(value), from, to }))
|
|
349
374
|
}
|
|
350
375
|
// --- Holds (#348) ------------------------------------------------------------
|
|
351
376
|
/** The open **Reorder hold**: the item in hand, how it was taken, and its index then. One at a time. */
|
|
352
377
|
let held: Option.Option<{ readonly value: V; readonly from: number; readonly by: "drag" | "lift" }> = Option.none()
|
|
353
378
|
/** 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
|
|
379
|
+
const holdsDrag = (value: V): boolean => Option.exists(held, (h) => h.by === "drag" && same(h.value, value))
|
|
355
380
|
const holdStart = (value: V, from: number, by: "drag" | "lift"): void => {
|
|
356
381
|
held = Option.some({ value, from, by })
|
|
357
|
-
UndefinedOr.map(options.onHoldStart, (tell) => tell({ value, from }))
|
|
382
|
+
UndefinedOr.map(options.onHoldStart, (tell) => tell({ value: latest(value), from }))
|
|
358
383
|
}
|
|
359
384
|
/** End `value`'s hold, `how`: told once, and only for the open one. */
|
|
360
385
|
const holdEnd = (value: V, how: ReorderHoldHow): void =>
|
|
361
|
-
Option.match(Option.filter(held, (h) => h.value
|
|
386
|
+
Option.match(Option.filter(held, (h) => same(h.value, value)), {
|
|
362
387
|
onNone: constVoid,
|
|
363
388
|
onSome: (h) => {
|
|
364
389
|
held = Option.none()
|
|
365
|
-
UndefinedOr.map(options.onHoldEnd, (tell) => tell({ values: [...options.values()], value, from: h.from, to: indexOf(value), how }))
|
|
390
|
+
UndefinedOr.map(options.onHoldEnd, (tell) => tell({ values: [...options.values()], value: latest(value), from: h.from, to: indexOf(value), how }))
|
|
366
391
|
},
|
|
367
392
|
})
|
|
368
393
|
|
|
@@ -409,7 +434,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
409
434
|
if (Bool.not(event.fromTarget)) return
|
|
410
435
|
// Keys during a pointer drag are left alone.
|
|
411
436
|
if (Reorder.isDragging(group)) return
|
|
412
|
-
const lifted =
|
|
437
|
+
const lifted = isLiftedValue(value)
|
|
413
438
|
Option.match(Reorder.keyIntent(event.key), {
|
|
414
439
|
onNone: constVoid,
|
|
415
440
|
onSome: (intent) =>
|
|
@@ -514,7 +539,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
514
539
|
// Its index at the drag's start, for its `onReorderEnd` (#257 item 3).
|
|
515
540
|
let draggedFrom = -1
|
|
516
541
|
const k: Keyed = { element: itemElement, handle: Option.none(), onLift }
|
|
517
|
-
keyed.set(value, k)
|
|
542
|
+
keyed.set(idOf(value), k)
|
|
518
543
|
const end = (): void => {
|
|
519
544
|
inGesture = false
|
|
520
545
|
Reorder.dragEnd(group, value)
|
|
@@ -525,8 +550,9 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
525
550
|
if (!remountReported && unregisteredThisTask.has(value)) {
|
|
526
551
|
remountReported = true
|
|
527
552
|
runtime.runFork(
|
|
528
|
-
|
|
529
|
-
|
|
553
|
+
Diagnostic.report(
|
|
554
|
+
"WARDIC_REORDER_ITEM_REMOUNTED",
|
|
555
|
+
`Reorder: an item remounted with the same value in one task, \`${String(value)}\`, as a list keyed by index does when its order changes: key items with ${keyedWith}, so each value keeps its element.`,
|
|
530
556
|
).pipe(Effect.annotateLogs({ value: String(value) })),
|
|
531
557
|
)
|
|
532
558
|
}
|
|
@@ -536,7 +562,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
536
562
|
layoutVersion: handle.layoutVersion,
|
|
537
563
|
})
|
|
538
564
|
k.handle = Option.some(handle)
|
|
539
|
-
keyed.set(value, k)
|
|
565
|
+
keyed.set(idOf(value), k)
|
|
540
566
|
return () => {
|
|
541
567
|
if (Option.contains(k.handle, handle)) k.handle = Option.none()
|
|
542
568
|
unregister()
|
|
@@ -571,20 +597,20 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
571
597
|
},
|
|
572
598
|
onKey: onKeyOf(value),
|
|
573
599
|
onBlur: () => {
|
|
574
|
-
if (Bool.not(
|
|
600
|
+
if (Bool.not(isLiftedValue(value))) return
|
|
575
601
|
// A reorder can blur the node it moves; focus was put back on it, so it's no interruption.
|
|
576
602
|
if (focused(value)) return
|
|
577
603
|
dropLifted()
|
|
578
604
|
},
|
|
579
605
|
onPress: () => {
|
|
580
|
-
if (
|
|
606
|
+
if (isLiftedValue(value)) dropLifted()
|
|
581
607
|
},
|
|
582
608
|
dispose: () => {
|
|
583
609
|
if (inGesture) end()
|
|
584
610
|
// Unmounted while lifted: the lift ends, unsaid.
|
|
585
|
-
if (
|
|
611
|
+
if (isLiftedValue(value)) Reorder.drop(group, value)
|
|
586
612
|
holdEnd(value, "unmount")
|
|
587
|
-
if (keyed.get(value) === k) keyed.delete(value)
|
|
613
|
+
if (keyed.get(idOf(value)) === k) keyed.delete(idOf(value))
|
|
588
614
|
},
|
|
589
615
|
}
|
|
590
616
|
}
|
|
@@ -610,7 +636,7 @@ export const makeReorderController = <V>(wiring: ReorderControllerWiring, option
|
|
|
610
636
|
valuesChanged: () => {
|
|
611
637
|
// The app changed `values` itself while an item is lifted: it's dropped at its new place. The group's
|
|
612
638
|
// 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()
|
|
639
|
+
if (Option.isSome(Reorder.liftedValue(group)) && Bool.not(isAsked(asked, options.values(), sameItems))) dropLifted()
|
|
614
640
|
wiring.layOut()
|
|
615
641
|
},
|
|
616
642
|
dispose: () => {
|
|
@@ -625,9 +651,12 @@ const noop = (): void => {}
|
|
|
625
651
|
/** Whether two orders hold the same items in the same order. */
|
|
626
652
|
export const sameOrder: Equivalence.Equivalence<ReadonlyArray<unknown>> = Arr.makeEquivalence(Equivalence.strictEqual())
|
|
627
653
|
|
|
628
|
-
/**
|
|
629
|
-
|
|
630
|
-
|
|
654
|
+
/**
|
|
655
|
+
* Whether `values` is the order the group last asked for (ADR-0037, *Amendment (#721)*): its items, in its
|
|
656
|
+
* order, matched as the group matches them (`sameItems`: by `key` where it's given).
|
|
657
|
+
*/
|
|
658
|
+
const isAsked = <V>(asked: ReadonlyArray<V> | undefined, values: ReadonlyArray<V>, sameItems: Equivalence.Equivalence<ReadonlyArray<V>>): boolean =>
|
|
659
|
+
UndefinedOr.match(asked, { onUndefined: constFalse, onDefined: (order) => sameItems(order, values) })
|
|
631
660
|
|
|
632
661
|
/**
|
|
633
662
|
* A {@link ReorderController} for a server render (ADR-0021), where there's no projection
|
package/src/internal/scroll.ts
CHANGED
|
@@ -363,7 +363,7 @@ const readerOf = (registry: AtomRegistry.AtomRegistry, containers: (element: Ele
|
|
|
363
363
|
registry.set(atom, next)
|
|
364
364
|
if (failing) failing = false
|
|
365
365
|
} catch (defect) {
|
|
366
|
-
if (!failing) Report.
|
|
366
|
+
if (!failing) Report.callbackFailedOn(context, DEPENDENT_FAILED, Cause.die(defect))
|
|
367
367
|
failing = true
|
|
368
368
|
}
|
|
369
369
|
}
|
|
@@ -85,6 +85,7 @@ import * as Stream from "effect/Stream"
|
|
|
85
85
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
86
86
|
import type * as DragConstraints from "./DragConstraints.ts"
|
|
87
87
|
import type * as WardicServices from "@wardic/core/unstable/WardicServices"
|
|
88
|
+
import * as Diagnostic from "@wardic/core/unstable/Diagnostic"
|
|
88
89
|
import type * as WardConfig from "./WardConfig.ts"
|
|
89
90
|
import * as DragControls from "./DragControls.ts"
|
|
90
91
|
import * as DragTransition from "./DragTransition.ts"
|
|
@@ -140,7 +141,9 @@ export interface DragTrackConfig {
|
|
|
140
141
|
* Motion's `dragListener`: `false`, the element's own presses start no drag and stop no
|
|
141
142
|
* release; only its **Drag controls**' starts do. Default `true`.
|
|
142
143
|
*/
|
|
143
|
-
|
|
144
|
+
// A predicate, asked of each down (probe: behaviour-runes): an element that drags from part of itself
|
|
145
|
+
// alone hears a press there, and any press while it doesn't (the hooks' Grips).
|
|
146
|
+
readonly listen?: boolean | ((down: InputSource.PointerLikeEvent) => boolean) | undefined
|
|
144
147
|
}
|
|
145
148
|
|
|
146
149
|
/** The drag props a track's config is read from: an element's, its axis and its constraints resolved by the binding. */
|
|
@@ -451,6 +454,23 @@ const isGrab: Predicate.Predicate<InputSource.PointerLikeEvent> = Predicate.and(
|
|
|
451
454
|
/** A down the element adopted from its **Drag controls** (#431). */
|
|
452
455
|
const isAdopted: Predicate.Predicate<InputSource.PointerLikeEvent> = (e) => e.adopted === true
|
|
453
456
|
|
|
457
|
+
/** A drag's `listen`: whether it hears its own presses, or which of them. */
|
|
458
|
+
type Listen = boolean | ((down: InputSource.PointerLikeEvent) => boolean)
|
|
459
|
+
|
|
460
|
+
/**
|
|
461
|
+
* Which downs grab, by the drag's `listen` (#431): every grab, only an adopted one, or one it's asked of
|
|
462
|
+
* and says it hears, or adopted (probe: behaviour-runes, the hooks' Grips). Built once, at module load.
|
|
463
|
+
*/
|
|
464
|
+
const grabsOf: (listen: Listen) => Predicate.Predicate<InputSource.PointerLikeEvent> = Match.type<Listen>().pipe(
|
|
465
|
+
Match.when(true, () => isGrab),
|
|
466
|
+
Match.when(false, () => Predicate.and(isGrab, isAdopted)),
|
|
467
|
+
Match.orElse((hears) => (e: InputSource.PointerLikeEvent): boolean => {
|
|
468
|
+
if (Bool.not(isGrab(e))) return false
|
|
469
|
+
if (hears(e)) return true
|
|
470
|
+
return isAdopted(e)
|
|
471
|
+
}),
|
|
472
|
+
)
|
|
473
|
+
|
|
454
474
|
/**
|
|
455
475
|
* A layout node's snap to the cursor ended with no drag (#431): its drag ended at rest, back to its
|
|
456
476
|
* slot. Whether there was one. A module's, not a track's (#507): a track given no Drag controls never
|
|
@@ -803,7 +823,10 @@ export const driveDragTrack = (opts: DragTrackOptions): DragTrack => {
|
|
|
803
823
|
onTrue: () => Effect.void,
|
|
804
824
|
onFalse: () => {
|
|
805
825
|
warned = true
|
|
806
|
-
return
|
|
826
|
+
return Diagnostic.report(
|
|
827
|
+
"WARDIC_DRAG_CONTAINER_MISSING",
|
|
828
|
+
"`dragConstraints`' container isn't on the page at a drag's start, so the element drags unconstrained. Render the container before the element can be dragged, or give `dragConstraints` a box of numbers.",
|
|
829
|
+
)
|
|
807
830
|
},
|
|
808
831
|
})),
|
|
809
832
|
),
|
|
@@ -828,7 +851,7 @@ export const driveDragTrack = (opts: DragTrackOptions): DragTrack => {
|
|
|
828
851
|
onDefined: (at) => () => toDragAxis(at()),
|
|
829
852
|
})
|
|
830
853
|
const { propagation = false } = config
|
|
831
|
-
const listens = config.listen
|
|
854
|
+
const listens = UndefinedOr.match(config.listen, { onUndefined: (): Listen => true, onDefined: identity })
|
|
832
855
|
|
|
833
856
|
// --- Drag controls (#431), only for an element given them (#507) ----------------------------
|
|
834
857
|
const controlled = Predicate.isNotUndefined(opts.controls)
|
|
@@ -960,7 +983,7 @@ export const driveDragTrack = (opts: DragTrackOptions): DragTrack => {
|
|
|
960
983
|
onDefect,
|
|
961
984
|
})
|
|
962
985
|
// A down grabs when the drag listens to it (#431): with `listen: false`, only an adopted one.
|
|
963
|
-
const grabs =
|
|
986
|
+
const grabs = grabsOf(listens)
|
|
964
987
|
// The adoptable feed with controls (#507), so a grab hears an adopted down; the plain one without.
|
|
965
988
|
const pointerFeed = Bool.match(controlled, { onTrue: () => InputSource.adoptablePointerOf(input, element), onFalse: () => input.pointer(element) })
|
|
966
989
|
yield* InputFeed.watch(pointerFeed, {
|
|
@@ -14,6 +14,7 @@
|
|
|
14
14
|
// since PR 2, moved to dom for every DOM binding's elements, with the value reads its provider holds.
|
|
15
15
|
import * as BaseValue from "@wardic/core/BaseValue"
|
|
16
16
|
import * as Projection from "@wardic/core/Projection"
|
|
17
|
+
import * as Diagnostic from "@wardic/core/unstable/Diagnostic"
|
|
17
18
|
import type * as ReducedMotion from "@wardic/core/ReducedMotion"
|
|
18
19
|
import type * as Renderer from "@wardic/core/Renderer"
|
|
19
20
|
import type * as Values from "@wardic/core/Values"
|
|
@@ -288,11 +289,15 @@ export const writeUnderStyle = (element: HTMLElement, style: Readonly<Record<str
|
|
|
288
289
|
})
|
|
289
290
|
}
|
|
290
291
|
|
|
291
|
-
/**
|
|
292
|
+
/**
|
|
293
|
+
* Report, once per element, that a `transform` string gave way to the transform keys in its `style`
|
|
294
|
+
* (#130): `WARDIC_TRANSFORM_STRING_DROPPED`, on the Environment's reporter (`Diagnostic`).
|
|
295
|
+
*/
|
|
292
296
|
export const warnDroppedTransform = (runtime: WardicServices.Runner<WardicServices.WardicServices>, id: string): void => {
|
|
293
297
|
runtime.runFork(
|
|
294
|
-
|
|
295
|
-
"
|
|
298
|
+
Diagnostic.report(
|
|
299
|
+
"WARDIC_TRANSFORM_STRING_DROPPED",
|
|
300
|
+
"a `transform` string is dropped while `style` sets a transform key (x, scale, rotate…); " +
|
|
296
301
|
"the keys win, as Motion's do. Give the transform as keys, or drop them",
|
|
297
302
|
).pipe(Effect.annotateLogs({ id })),
|
|
298
303
|
)
|
package/src/unstable/Feature.ts
CHANGED
|
@@ -29,6 +29,7 @@ import * as Predicate from "effect/Predicate"
|
|
|
29
29
|
import * as UndefinedOr from "effect/UndefinedOr"
|
|
30
30
|
import * as OwnerScope from "./OwnerScope.ts"
|
|
31
31
|
import type * as WardConfig from "./WardConfig.ts"
|
|
32
|
+
import * as Diagnostic from "@wardic/core/unstable/Diagnostic"
|
|
32
33
|
import type * as Reactivity from "@wardic/core/unstable/Reactivity"
|
|
33
34
|
import type * as WardicServices from "@wardic/core/unstable/WardicServices"
|
|
34
35
|
|
|
@@ -317,8 +318,11 @@ export interface FeatureRegistry {
|
|
|
317
318
|
* that brings no Feature works with when one is there (the projection system, for a presence).
|
|
318
319
|
*/
|
|
319
320
|
readonly built: () => Context.Context<never>
|
|
320
|
-
/**
|
|
321
|
-
|
|
321
|
+
/**
|
|
322
|
+
* Logs `message` at Warning the first time `feature` is named: development's word on a missing Feature.
|
|
323
|
+
* With `code`, reports it as that coded diagnostic instead (`Diagnostic.report`, solid-next).
|
|
324
|
+
*/
|
|
325
|
+
readonly warnOnce: (feature: string, message: string, code?: Diagnostic.Code) => void
|
|
322
326
|
/** Runs `end` as the provider ends, before its Features: what a Wardic instance's loads stop by (#516). */
|
|
323
327
|
readonly onEnd: (end: () => void) => void
|
|
324
328
|
/** Ends every Feature built, the provider's runtime after (a Feature's Layer may stand on it). */
|
|
@@ -337,7 +341,7 @@ export interface InstanceHost extends Omit<SectionHost, "onCleanup"> {
|
|
|
337
341
|
* A registry's sections of exactly a list, one per list; what runs as it ends (`onEnd`, run by `end`);
|
|
338
342
|
* and its warnings, one per Feature.
|
|
339
343
|
*/
|
|
340
|
-
const sectionsAndWarnings = (build: Build, warn: (message: string) => void) => {
|
|
344
|
+
const sectionsAndWarnings = (build: Build, warn: (message: string, code: Diagnostic.Code | undefined) => void) => {
|
|
341
345
|
const sections = new WeakMap<ReadonlyArray<Feature>, FeatureSection>()
|
|
342
346
|
const ends: Array<() => void> = []
|
|
343
347
|
const warned = new Set<string>()
|
|
@@ -356,10 +360,10 @@ const sectionsAndWarnings = (build: Build, warn: (message: string) => void) => {
|
|
|
356
360
|
return section
|
|
357
361
|
},
|
|
358
362
|
}),
|
|
359
|
-
warnOnce: (feature: string, message: string): void => {
|
|
363
|
+
warnOnce: (feature: string, message: string, code?: Diagnostic.Code): void => {
|
|
360
364
|
if (warned.has(feature)) return
|
|
361
365
|
warned.add(feature)
|
|
362
|
-
warn(message)
|
|
366
|
+
warn(message, code)
|
|
363
367
|
},
|
|
364
368
|
}
|
|
365
369
|
}
|
|
@@ -411,8 +415,8 @@ export const clientRegistry = (runtime: FeatureRuntime, dispose: () => Promise<v
|
|
|
411
415
|
return services
|
|
412
416
|
},
|
|
413
417
|
})
|
|
414
|
-
const { end, ...rest } = sectionsAndWarnings(build, (message) => {
|
|
415
|
-
runtime.runFork(Effect.logWarning(message))
|
|
418
|
+
const { end, ...rest } = sectionsAndWarnings(build, (message, code) => {
|
|
419
|
+
runtime.runFork(UndefinedOr.match(code, { onUndefined: () => Effect.logWarning(message), onDefined: (given) => Diagnostic.report(given, message) }))
|
|
416
420
|
})
|
|
417
421
|
return {
|
|
418
422
|
build,
|
|
@@ -471,10 +475,11 @@ export const unreadColorIn = (values: Readonly<Record<string, unknown>>): string
|
|
|
471
475
|
|
|
472
476
|
/**
|
|
473
477
|
* 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
|
|
478
|
+
* Motion's), naming the binding's `complete` forms and the `slim` ones to use, and `under`, where
|
|
479
|
+
* its `strict` was given: by default Solid 1's, a provider or a `LazyWardic`.
|
|
475
480
|
*/
|
|
476
|
-
export const strictMessage = (complete: string, slim: string): string =>
|
|
477
|
-
`wardic: a Complete element (${complete}) is rendered under
|
|
481
|
+
export const strictMessage = (complete: string, slim: string, under: string = "a strict WardicProvider or LazyWardic"): string =>
|
|
482
|
+
`wardic: a Complete element (${complete}) is rendered under ${under}. ` +
|
|
478
483
|
`It brings every Feature's code with it; render the Slim element (${slim}) instead.`
|
|
479
484
|
|
|
480
485
|
/** What development's word on a missing `layout` Feature names (#511): the props that need it. */
|
|
@@ -96,7 +96,7 @@ export const pointer: (element: Element, options?: Options) => Effect.Effect<Poi
|
|
|
96
96
|
let eventThrew = false
|
|
97
97
|
/** The value `key`'s set threw: reported at a run's first throw. Its failure path alone. */
|
|
98
98
|
const valueFailed = (key: string, defect: unknown): void => {
|
|
99
|
-
if (Bool.not(Bool.or(eventThrew, failing))) Report.
|
|
99
|
+
if (Bool.not(Bool.or(eventThrew, failing))) Report.callbackFailedOn(context, DEPENDENT_FAILED, Cause.die(defect), { key })
|
|
100
100
|
eventThrew = true
|
|
101
101
|
}
|
|
102
102
|
const place = (event: Event): void => {
|