@wardic/solid 1.0.0-rc.8 → 1.0.0-rc.9
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/browser/index.js +1 -1
- package/dist/browser/layout-member.js +13 -5
- package/dist/browser/layout-member.js.map +1 -1
- package/dist/browser/presence-controller.js +96 -27
- package/dist/browser/presence-controller.js.map +1 -1
- package/dist/server/index.js +1 -1
- package/dist/server/layout-member.js +13 -5
- package/dist/server/layout-member.js.map +1 -1
- package/dist/server/presence-controller.js +96 -27
- package/dist/server/presence-controller.js.map +1 -1
- package/dist/solid/config.d.ts +6 -2
- package/dist/solid/config.d.ts.map +1 -1
- package/dist/solid/index.d.ts +1 -1
- package/dist/solid/index.js +1 -1
- package/dist/solid/layout-member.d.ts +15 -5
- package/dist/solid/layout-member.d.ts.map +1 -1
- package/dist/solid/layout-member.js +15 -5
- package/dist/solid/layout-member.js.map +1 -1
- package/dist/solid/presence-controller.d.ts.map +1 -1
- package/dist/solid/presence-controller.js +88 -21
- package/dist/solid/presence-controller.js.map +1 -1
- package/package.json +4 -4
- package/src/config.ts +8 -3
- package/src/index.ts +1 -1
- package/src/layout-member.ts +24 -9
- package/src/presence-controller.ts +95 -20
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@wardic/solid",
|
|
3
|
-
"version": "1.0.0-rc.
|
|
3
|
+
"version": "1.0.0-rc.9",
|
|
4
4
|
"description": "Motion for React's API on Solid 1 and Solid 2: Wardic's elements, gestures, layout and presence animations.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"animation",
|
|
@@ -68,8 +68,8 @@
|
|
|
68
68
|
},
|
|
69
69
|
"dependencies": {
|
|
70
70
|
"@solid-primitives/refs": "^1.1.3",
|
|
71
|
-
"@wardic/core": "1.0.0-rc.
|
|
72
|
-
"@wardic/dom": "1.0.0-rc.
|
|
71
|
+
"@wardic/core": "1.0.0-rc.9",
|
|
72
|
+
"@wardic/dom": "1.0.0-rc.9",
|
|
73
73
|
"csstype": "^3.1.0"
|
|
74
74
|
},
|
|
75
75
|
"peerDependencies": {
|
|
@@ -91,7 +91,7 @@
|
|
|
91
91
|
"@solidjs/router-2": "npm:@solidjs/router@2.0.0-next.43",
|
|
92
92
|
"@solidjs/web": "2.0.0-rc.20",
|
|
93
93
|
"@types/babel__core": "^7.20.5",
|
|
94
|
-
"@wardic/test": "1.0.0-rc.
|
|
94
|
+
"@wardic/test": "1.0.0-rc.9",
|
|
95
95
|
"babel-preset-solid": "1.9.12",
|
|
96
96
|
"effect": "4.1.1",
|
|
97
97
|
"solid-js": "^1.9.18",
|
package/src/config.ts
CHANGED
|
@@ -668,15 +668,20 @@ export interface WardConfig {
|
|
|
668
668
|
/**
|
|
669
669
|
* Marks a scrolling element that is itself a layout element, so its descendants' layout animations
|
|
670
670
|
* aren't moved by its scroll. Every other scroll, `position: sticky` included, is accounted for
|
|
671
|
-
* without it.
|
|
671
|
+
* without it. With no `layout` or `layoutId`, the element animates no layout of its own: it moves to a
|
|
672
|
+
* new place at once, as Motion's.
|
|
672
673
|
*/
|
|
673
674
|
// ADR-0012 and its Amendments (Reorder, #578). Read once at mount.
|
|
674
675
|
readonly layoutScroll?: boolean
|
|
675
676
|
/**
|
|
676
677
|
* Makes the element a root for the layout animations inside it: it never animates its own layout,
|
|
677
|
-
* and its descendants' are measured against it.
|
|
678
|
+
* and its descendants' are measured against it. With `layout` too, it stays at its new place while a
|
|
679
|
+
* parent's layout animation runs. Alone, it moves with that animation, as Motion's.
|
|
680
|
+
*
|
|
681
|
+
* @example <w.div layout layoutRoot>...</w.div>
|
|
678
682
|
*/
|
|
679
|
-
// ADR-0013: it self-snaps, bounds delta accumulation, and anchors its subtree
|
|
683
|
+
// ADR-0013: it self-snaps, bounds delta accumulation, and anchors its subtree; with no `layout` or
|
|
684
|
+
// `layoutId` it has Layout mode `false` and rides its ancestors (*Amendment (#691)*). Read once at mount.
|
|
680
685
|
readonly layoutRoot?: boolean
|
|
681
686
|
/**
|
|
682
687
|
* Where in its parent's box a layout element anchors as the parent changes size: 0 to 1 on each
|
package/src/index.ts
CHANGED
package/src/layout-member.ts
CHANGED
|
@@ -82,7 +82,11 @@ export interface CreateProjectionNodeOptions {
|
|
|
82
82
|
// ADR-0012: its scroll offset is sampled at measure and folded out of its descendants' boxes, so a
|
|
83
83
|
// scroll between triggers doesn't leak into their FLIP delta.
|
|
84
84
|
readonly layoutScroll?: boolean
|
|
85
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Its `layoutRoot`: a root for the layout animations inside it, which never animates its own. With a
|
|
87
|
+
* `layoutMode` other than `false` it stays at its new place while an ancestor's layout animation runs;
|
|
88
|
+
* with `false` it moves with it, as a `w.*` element's with no `layout` or `layoutId` does.
|
|
89
|
+
*/
|
|
86
90
|
// ADR-0013: a stable projection sub-root, self-snap, boundary and persistent relative anchor.
|
|
87
91
|
readonly layoutRoot?: boolean
|
|
88
92
|
/** Its `layoutAnchor`: where in its parent's box it anchors, 0 to 1 per axis, or `false` to measure it against the page. */
|
|
@@ -94,8 +98,12 @@ export interface CreateProjectionNodeOptions {
|
|
|
94
98
|
/** Raises it above its siblings while it's dragged, as a `<Reorder>` item is. */
|
|
95
99
|
// ADR-0016 *Amendment (Reorder)*.
|
|
96
100
|
readonly raiseWhileDragged?: boolean
|
|
97
|
-
/**
|
|
98
|
-
|
|
101
|
+
/**
|
|
102
|
+
* Its `layout` value: which part of a change it animates, read as each layout animation starts. `false`
|
|
103
|
+
* for one with no layout of its own, as a `w.*` element's with `layoutRoot` or `layoutScroll` and no
|
|
104
|
+
* `layout` or `layoutId`. Default `true`.
|
|
105
|
+
*/
|
|
106
|
+
// ADR-0009, *Amendments (#42, #691)*: its Layout mode.
|
|
99
107
|
readonly layoutMode?: () => Projection.LayoutMode
|
|
100
108
|
/** Its own `scale`, read at each handover and each frame it follows another element. */
|
|
101
109
|
// ADR-0010 *Amendment (#8)*.
|
|
@@ -201,11 +209,16 @@ const takeOverOf = (box: Box.Box | undefined, fade: number | undefined): Pick<Pr
|
|
|
201
209
|
}
|
|
202
210
|
|
|
203
211
|
/**
|
|
204
|
-
* The Layout mode a
|
|
205
|
-
* `true`
|
|
212
|
+
* The Layout mode a config gives its node (ADR-0009, *Amendment (#42)*): the mode its `layout` names,
|
|
213
|
+
* `true` for `layout` or a `layoutId`, and `false` for a node only a `layoutScroll` or a `layoutRoot` gives,
|
|
214
|
+
* which animates no layout of its own and rides its ancestors', as Motion's (#691). Statement `if`s:
|
|
215
|
+
* read each frame for a Follower.
|
|
206
216
|
*/
|
|
207
|
-
export const layoutModeOf = (layout: WardConfig["layout"]): Projection.LayoutMode =>
|
|
208
|
-
|
|
217
|
+
export const layoutModeOf = (layout: WardConfig["layout"], layoutId: string | undefined): Projection.LayoutMode => {
|
|
218
|
+
if (isModeName(layout)) return layout
|
|
219
|
+
if (layout === true) return true
|
|
220
|
+
return Predicate.isNotUndefined(layoutId)
|
|
221
|
+
}
|
|
209
222
|
|
|
210
223
|
/** Whether a `layout` prop names a Layout mode (a string), not `true` / `false`. */
|
|
211
224
|
const isModeName = (layout: WardConfig["layout"]): layout is Exclude<WardConfig["layout"], boolean | undefined> => Predicate.isString(layout)
|
|
@@ -254,8 +267,10 @@ export const layoutOptionsOf = (ward: WardLayout): CreateProjectionNodeOptions =
|
|
|
254
267
|
layoutDependency: () => config().layoutDependency,
|
|
255
268
|
transition: () => ownOrInherited(config().transition, parent),
|
|
256
269
|
dragTransition: () => dragTransition,
|
|
257
|
-
// The Layout mode, read at each layout animation's start
|
|
258
|
-
|
|
270
|
+
// The Layout mode, read at each layout animation's start, at each Measure pass for a layoutRoot
|
|
271
|
+
// until it isolates, and each frame for a Follower (ADR-0009, *Amendments (#42, #691)*); its
|
|
272
|
+
// `layoutId` is the one read at mount.
|
|
273
|
+
layoutMode: () => layoutModeOf(config().layout, c0.layoutId),
|
|
259
274
|
// The own scale the renderer draws, from the values last written (ADR-0010 *Amendment (#8)*).
|
|
260
275
|
ownScale: () => DomRenderer.ownScaleOf(snapshot.values),
|
|
261
276
|
// And its own translate, which the renderer adds to its projection's (#363).
|
|
@@ -366,8 +366,12 @@ const parentElementOf = (placed: ReadonlyArray<Placed>): Element | undefined =>
|
|
|
366
366
|
/**
|
|
367
367
|
* The children in Motion's order for a change (#486, its `AnimatePresence`, #3746 there): `now`, with
|
|
368
368
|
* each of `before`, the children as they were, leavers still exiting among them, that isn't in `now`
|
|
369
|
-
* put back
|
|
370
|
-
*
|
|
369
|
+
* put back by Motion 14.9's arithmetic (#675). Walking `before`, each staying child sets the place to
|
|
370
|
+
* just after its own index in `now`, counting every leaver put back so far, and each leaver goes in
|
|
371
|
+
* there; first, while no staying child has set it. While the staying children keep their order, that's
|
|
372
|
+
* right after the staying child it followed, after the others put back there. Under a reorder it can
|
|
373
|
+
* be after a leaver put back after another child: `[a, b, c, d]`, b and d leaving, then `[c, a]`, is
|
|
374
|
+
* `[c, a, d, b]`, where "after the child it followed" would be `[c, d, a, b]`.
|
|
371
375
|
*/
|
|
372
376
|
const orderOf = (before: ReadonlyArray<HTMLElement>, now: ReadonlyArray<HTMLElement>): ReadonlyArray<HTMLElement> => {
|
|
373
377
|
const at = new Map(Arr.map(now, (el, i) => [el, i] as const))
|
|
@@ -382,20 +386,42 @@ const orderOf = (before: ReadonlyArray<HTMLElement>, now: ReadonlyArray<HTMLElem
|
|
|
382
386
|
}
|
|
383
387
|
|
|
384
388
|
/**
|
|
385
|
-
* Where
|
|
386
|
-
* the
|
|
389
|
+
* Where a leaver goes back (#675), walking the order with a cursor: right after `cursor`, the element
|
|
390
|
+
* before it in the order, already in its place; with none before it, right before `anchor`, where the
|
|
391
|
+
* presence's children start; with neither, where it was. Each leaver is placed against one already in
|
|
392
|
+
* place, never against a leaver that isn't yet, as the nearest neighbour on the page might be (#561's
|
|
393
|
+
* P19).
|
|
387
394
|
*/
|
|
388
|
-
const backPlaceOf = (placed: Placed,
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
onSome: (el) => ({ el: placed.el, parent: Option.getOrUndefined(Option.fromNullOr(el.parentNode)), next: el }),
|
|
396
|
-
onNone: () => placed,
|
|
395
|
+
const backPlaceOf = (placed: Placed, cursor: HTMLElement | undefined, anchor: ChildNode | undefined): Placed =>
|
|
396
|
+
UndefinedOr.match(cursor, {
|
|
397
|
+
onDefined: (at) => ({ ...placedOf(at), el: placed.el }),
|
|
398
|
+
onUndefined: () =>
|
|
399
|
+
UndefinedOr.match(anchor, {
|
|
400
|
+
onDefined: (at) => ({ el: placed.el, parent: Option.getOrUndefined(Option.fromNullOr(at.parentNode)), next: at }),
|
|
401
|
+
onUndefined: () => placed,
|
|
397
402
|
}),
|
|
398
403
|
})
|
|
404
|
+
|
|
405
|
+
/**
|
|
406
|
+
* Whether a leaver from an earlier change is at its place already (#675), so a change that doesn't
|
|
407
|
+
* move it leaves it be (its focus, and anything a removal would restart): the next element after
|
|
408
|
+
* `cursor`, text between them left be; with none, the anchor itself, the first of the order on the
|
|
409
|
+
* page; with neither, on the page.
|
|
410
|
+
*/
|
|
411
|
+
const isInPlace = (el: HTMLElement, cursor: HTMLElement | undefined, anchor: ChildNode | undefined): boolean =>
|
|
412
|
+
UndefinedOr.match(cursor, {
|
|
413
|
+
onDefined: (at) => at.nextElementSibling === el,
|
|
414
|
+
onUndefined: () =>
|
|
415
|
+
UndefinedOr.match(anchor, {
|
|
416
|
+
onDefined: (at) => at === el,
|
|
417
|
+
onUndefined: () => Predicate.isNotNull(el.parentNode),
|
|
418
|
+
}),
|
|
419
|
+
})
|
|
420
|
+
|
|
421
|
+
/** Whether a node is there and on the page. */
|
|
422
|
+
const isOnPage = (node: ChildNode | undefined): node is ChildNode => {
|
|
423
|
+
if (Predicate.isUndefined(node)) return false
|
|
424
|
+
return node.isConnected
|
|
399
425
|
}
|
|
400
426
|
|
|
401
427
|
/** Put a retained node back into the parent it left: before its old next sibling while that's still there, else at the end. */
|
|
@@ -611,6 +637,9 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
|
|
|
611
637
|
// and kept until it's gone. Whether this change popped one, so the projection is told.
|
|
612
638
|
const pops = new Map<HTMLElement, PopBox>()
|
|
613
639
|
let popped = false
|
|
640
|
+
// Whether this change moved a leaver from an earlier one to its place (#675), so the projection is
|
|
641
|
+
// told: a twin leaver crossfading in the flow is drawn on its Lead from where it now is.
|
|
642
|
+
let moved = false
|
|
614
643
|
|
|
615
644
|
// Keys (#286, ADR-0048): each Wardic element made under this presence, told as it's made, so a
|
|
616
645
|
// child's key is known before what goes on the page is decided.
|
|
@@ -1107,6 +1136,51 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
|
|
|
1107
1136
|
UndefinedOr.map(placed.parent, (parent) => reinsert(placed.el, parent, placed.next))
|
|
1108
1137
|
}
|
|
1109
1138
|
|
|
1139
|
+
/**
|
|
1140
|
+
* Every leaver at its place in `order` (#675), walking it with a cursor: a child that stays is where
|
|
1141
|
+
* its framework put it, and each leaver goes right after the element before it in the order, this
|
|
1142
|
+
* change's as they leave, an earlier change's moved there. A framework moves its own nodes around a
|
|
1143
|
+
* leaver it doesn't know of: Solid's swap of `[a, c]` puts `c` before `a`'s next sibling, the leaver
|
|
1144
|
+
* between them. So each change places them all again, as Motion's presence renders every exiting child
|
|
1145
|
+
* at its place.
|
|
1146
|
+
*/
|
|
1147
|
+
const placeLeavers = (order: ReadonlyArray<HTMLElement>, kept: ReadonlySet<HTMLElement>, gone: ReadonlyMap<HTMLElement, Placed>): void => {
|
|
1148
|
+
const anchor = anchorOf(order, gone)
|
|
1149
|
+
Arr.reduce<HTMLElement, HTMLElement | undefined>(order, undefined, (cursor, el) => {
|
|
1150
|
+
UndefinedOr.match(gone.get(el), {
|
|
1151
|
+
onDefined: (placed) => left(placed, backPlaceOf(placed, cursor, anchor)),
|
|
1152
|
+
onUndefined: () => {
|
|
1153
|
+
if (Bool.not(kept.has(el))) moveBack(el, cursor, anchor)
|
|
1154
|
+
},
|
|
1155
|
+
})
|
|
1156
|
+
return Bool.match(el.isConnected, { onTrue: () => el, onFalse: () => cursor })
|
|
1157
|
+
})
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
/**
|
|
1161
|
+
* Where the presence's children start, for the leavers no element precedes in the order (#675): the
|
|
1162
|
+
* first element of the order on the page as the walk starts, a child that stays or an earlier
|
|
1163
|
+
* change's leaver. With none, where they ended: the node after one of them at its last place, still on
|
|
1164
|
+
* the page. Solid empties a list beside a sibling around its leavers, its own nodes gone, and that's
|
|
1165
|
+
* the sibling. With neither, `undefined`: nothing of theirs is left, as when Solid clears the parent.
|
|
1166
|
+
*/
|
|
1167
|
+
const anchorOf = (order: ReadonlyArray<HTMLElement>, gone: ReadonlyMap<HTMLElement, Placed>): ChildNode | undefined =>
|
|
1168
|
+
Option.getOrUndefined(Option.orElse(Arr.findFirst(order, isOnPage), () => Arr.findFirst(Arr.map(order, (el) => lastNextOf(el, gone)), isOnPage)))
|
|
1169
|
+
|
|
1170
|
+
/** The node after a child at its last place: as the last change left it, or, an earlier leaver, as it left. */
|
|
1171
|
+
const lastNextOf = (el: HTMLElement, gone: ReadonlyMap<HTMLElement, Placed>): ChildNode | undefined =>
|
|
1172
|
+
UndefinedOr.map(UndefinedOr.match(gone.get(el), { onDefined: identity, onUndefined: () => places.get(el) }), (placed) => placed.next)
|
|
1173
|
+
|
|
1174
|
+
/** A leaver from an earlier change, still retained, moved to its place in the walk (#675) unless it's there already. */
|
|
1175
|
+
const moveBack = (el: HTMLElement, cursor: HTMLElement | undefined, anchor: ChildNode | undefined): void => {
|
|
1176
|
+
if (isInPlace(el, cursor, anchor)) return
|
|
1177
|
+
UndefinedOr.map(places.get(el), (placed) => {
|
|
1178
|
+
const back = backPlaceOf(placed, cursor, anchor)
|
|
1179
|
+
UndefinedOr.map(back.parent, (parent) => reinsert(el, parent, back.next))
|
|
1180
|
+
moved = true
|
|
1181
|
+
})
|
|
1182
|
+
}
|
|
1183
|
+
|
|
1110
1184
|
/** A child that left: retained at `back` (#486), and exiting, unless it's leaving already. */
|
|
1111
1185
|
const left = (placed: Placed, back: Placed): void => {
|
|
1112
1186
|
const el = placed.el
|
|
@@ -1352,14 +1426,13 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
|
|
|
1352
1426
|
})
|
|
1353
1427
|
settleTakeovers()
|
|
1354
1428
|
}
|
|
1355
|
-
// The children that left go back in Motion's order (#486)
|
|
1356
|
-
//
|
|
1357
|
-
// Leavers from earlier changes, still exiting, keep their places in it.
|
|
1429
|
+
// The children that left go back in Motion's order (#486), and every leaver from an earlier change,
|
|
1430
|
+
// still exiting, keeps its place in it (#675), one a framework took out (a list emptied) too.
|
|
1358
1431
|
const gone = new Map(Arr.map(Arr.filter(previous, (placed) => Bool.and(Bool.not(kept.has(placed.el)), Bool.not(takenOver.has(placed.el)))), (placed) => [placed.el, placed] as const))
|
|
1359
|
-
const before = Arr.filter(rendered, (el) => Bool.or(Bool.or(kept.has(el), gone.has(el)), Bool.and(el.isConnected, Bool.not(takenOver.has(el)))))
|
|
1432
|
+
const before = Arr.filter(rendered, (el) => Bool.or(Bool.or(kept.has(el), gone.has(el)), Bool.and(Bool.or(el.isConnected, places.has(el)), Bool.not(takenOver.has(el)))))
|
|
1360
1433
|
const listed = new Set(before)
|
|
1361
1434
|
const order = orderOf(Arr.appendAll(before, Arr.filter(Arr.map(previous, (placed) => placed.el), (el) => Bool.not(listed.has(el)))), now)
|
|
1362
|
-
|
|
1435
|
+
placeLeavers(order, kept, gone)
|
|
1363
1436
|
rendered = Arr.filter(order, (el) => el.isConnected)
|
|
1364
1437
|
// A child still exiting that the framework took out since (a list emptied) goes back too.
|
|
1365
1438
|
Arr.forEach(Arr.fromIterable(places.values()), putBack)
|
|
@@ -1371,9 +1444,11 @@ export const makePresence = (options: PresenceOptions): PresenceController => {
|
|
|
1371
1444
|
Arr.forEach(Arr.fromIterable(registry.keys()), dropDetached)
|
|
1372
1445
|
Arr.forEach(Arr.fromIterable(watches), dropDetachedWatch)
|
|
1373
1446
|
// A popped leaver moved its siblings (#277), and so did a child entering (#442): a `layout` one
|
|
1374
|
-
// animates into the space, as Motion's presence re-renders its children then.
|
|
1375
|
-
|
|
1447
|
+
// animates into the space, as Motion's presence re-renders its children then. A leaver moved to its
|
|
1448
|
+
// place (#675) moved itself and them.
|
|
1449
|
+
if (Bool.and(Bool.or(Bool.or(popped, entered), moved), affectsLayout())) projection.notify()
|
|
1376
1450
|
popped = false
|
|
1451
|
+
moved = false
|
|
1377
1452
|
// The wards inside the children held until now start, the children on the page (#277). Held
|
|
1378
1453
|
// children go on together, so none is left held then. (A ward started while its child is held
|
|
1379
1454
|
// would only wait again: the check saves its re-run.)
|