@wardic/foldkit 1.3.1 → 1.4.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.
- package/dist/AnimationControls.d.ts +2 -1
- package/dist/AnimationControls.d.ts.map +1 -1
- package/dist/AnimationControls.js +4 -1
- package/dist/AnimationControls.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/commands.d.ts +2 -4
- package/dist/internal/commands.d.ts.map +1 -1
- package/dist/internal/commands.js.map +1 -1
- package/dist/internal/element.d.ts +2 -0
- package/dist/internal/element.d.ts.map +1 -1
- package/dist/internal/element.js +377 -316
- package/dist/internal/element.js.map +1 -1
- package/dist/internal/mount.d.ts.map +1 -1
- package/dist/internal/mount.js +46 -21
- package/dist/internal/mount.js.map +1 -1
- package/dist/internal/presence.js +2 -1
- package/dist/internal/presence.js.map +1 -1
- package/dist/internal/tree.d.ts +2 -2
- package/dist/internal/tree.d.ts.map +1 -1
- package/dist/internal/tree.js +15 -26
- package/dist/internal/tree.js.map +1 -1
- package/dist/internal/variant-node.d.ts +6 -0
- package/dist/internal/variant-node.d.ts.map +1 -1
- package/dist/internal/variant-node.js +31 -8
- package/dist/internal/variant-node.js.map +1 -1
- package/package.json +4 -4
- package/src/AnimationControls.ts +4 -1
- package/src/index.ts +1 -1
- package/src/internal/commands.ts +3 -4
- package/src/internal/element.ts +386 -327
- package/src/internal/mount.ts +47 -22
- package/src/internal/presence.ts +2 -1
- package/src/internal/tree.ts +15 -24
- package/src/internal/variant-node.ts +48 -8
package/src/internal/element.ts
CHANGED
|
@@ -50,9 +50,10 @@ import { mounted as scopeMounted } from "./scope.ts"
|
|
|
50
50
|
import { layoutOf } from "./layout.ts"
|
|
51
51
|
import { nearestPresence } from "./presence.ts"
|
|
52
52
|
import { groupDelivered, reorderItemOf } from "./reorder.ts"
|
|
53
|
-
import { hydrationMounted, type Provider, reducedMotionUnder, type State } from "./services.ts"
|
|
53
|
+
import { hydrationMounted, type Provider, reducedMotionUnder, reporterOf, type State } from "./services.ts"
|
|
54
54
|
import { configValueOf, dropNode, layoutGroupOf, nodeOf, startUnder } from "./tree.ts"
|
|
55
55
|
import { DEV } from "@wardic/foldkit/internal/dev"
|
|
56
|
+
import { IS_SERVER } from "@wardic/foldkit/internal/server"
|
|
56
57
|
|
|
57
58
|
/** An element's config as the spine reads it: what the view delivered, with its merged `style`. */
|
|
58
59
|
export type Config = Ward.Config<unknown> & WardConfig.SpineConfig
|
|
@@ -69,6 +70,9 @@ export const configOf = (delivered: unknown): Config => {
|
|
|
69
70
|
/** What a Retarget throwing inside the patch is reported as: contained at the binding's edge (decision 13), the element left where it is. */
|
|
70
71
|
const RETARGET_FAILED = "wardic.retarget: a w.* element's Retarget failed; it stays where it is"
|
|
71
72
|
|
|
73
|
+
/** What a `w.*` element's Mount or start failing is reported as: contained at the binding's edge (decision 13), the element left at its Starting style. */
|
|
74
|
+
export const MOUNT_FAILED = "wardic.mount: a w.* element's mount failed; it stays at its Starting style"
|
|
75
|
+
|
|
72
76
|
// Module state (#460, Q7): an id counter, only ever compared for distinctness.
|
|
73
77
|
let ids = 0
|
|
74
78
|
|
|
@@ -94,8 +98,13 @@ const devDiagnostics = (): Spine.SpineDiagnostics | undefined => {
|
|
|
94
98
|
* `w.Provider()` element's build gives both (#794, Q7), and its Mount writes them for an element with
|
|
95
99
|
* no Provider element above.
|
|
96
100
|
*/
|
|
97
|
-
export const startingStyleOf = (tag: string | undefined, config: Config, registry: () => AtomRegistry.AtomRegistry, inherited?: VariantTree.WardicVariantContextValue, held = false): Style.Style =>
|
|
98
|
-
|
|
101
|
+
export const startingStyleOf = (tag: string | undefined, config: Config, registry: () => AtomRegistry.AtomRegistry, inherited?: VariantTree.WardicVariantContextValue, held = false): Style.Style => {
|
|
102
|
+
const start = Spine.startOf(AnimationControls.uncontrolledOf(config), inherited, held, reactivity.untrack)
|
|
103
|
+
// A server renders it once: a variant that throws is logged there, its values left out of the markup.
|
|
104
|
+
// A client's mount reports it instead, since each render resolves it again (#979).
|
|
105
|
+
if (IS_SERVER && Option.isSome(start.failure)) Spine.variantFailedOnServer(start.failure.value)
|
|
106
|
+
return startingStyleFrom(tag, config, registry, start)
|
|
107
|
+
}
|
|
99
108
|
|
|
100
109
|
/** The element's Starting style (above) drawn from `start`, its own: what the walk draws beside its Appear entry, which reads `start` too (#794, PR 2). */
|
|
101
110
|
export const startingStyleFrom = (tag: string | undefined, config: Config, registry: () => AtomRegistry.AtomRegistry, start: Spine.Start): Style.Style =>
|
|
@@ -301,344 +310,394 @@ export const mountElement = (provider: Provider, state: State, element: HTMLElem
|
|
|
301
310
|
UndefinedOr.map(context, (ctx) => UndefinedOr.map(ctx.made, (made) => made(element, config.key, Predicate.isNotUndefined(config.layoutId))))
|
|
302
311
|
|
|
303
312
|
const begin = (): (() => void) => {
|
|
304
|
-
//
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
//
|
|
325
|
-
|
|
326
|
-
const
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
313
|
+
// What its release undoes, each set as it's made, in the order the release runs them (#997, ADR-0074):
|
|
314
|
+
// a start that throws runs them on what it had made by then, its setter gone with the rest, so it stays
|
|
315
|
+
// at its Starting style and no later delivery reaches it.
|
|
316
|
+
let unsubscribe: () => void = constVoid
|
|
317
|
+
let releaseHydration: () => void = constVoid
|
|
318
|
+
let unwatch: () => void = constVoid
|
|
319
|
+
let unfollowText: () => void = constVoid
|
|
320
|
+
let unfollowTemplate: () => void = constVoid
|
|
321
|
+
let unregisterAnimatable: () => void = constVoid
|
|
322
|
+
let uninstall: () => void = constVoid
|
|
323
|
+
let stopRechecks: () => void = constVoid
|
|
324
|
+
let releaseScope: () => void = constVoid
|
|
325
|
+
let disposeStartsDrag: () => void = constVoid
|
|
326
|
+
let disposeItem: () => void = constVoid
|
|
327
|
+
let disposeDrag: () => void = constVoid
|
|
328
|
+
let disposeGestures: () => void = constVoid
|
|
329
|
+
let disposeLayoutNode: () => void = constVoid
|
|
330
|
+
let unregisterLayoutValues: () => void = constVoid
|
|
331
|
+
let disposeSpine: () => void = constVoid
|
|
332
|
+
let unregisterGate: () => void = constVoid
|
|
333
|
+
// Its presence record's, run only when its start throws: else the presence keeps it, to drive its exit.
|
|
334
|
+
let unregisterRecord: () => void = constVoid
|
|
335
|
+
const releaseMade = (): void => {
|
|
336
|
+
unsubscribe()
|
|
337
|
+
releaseHydration()
|
|
338
|
+
unwatch()
|
|
339
|
+
unfollowText()
|
|
340
|
+
unfollowTemplate()
|
|
341
|
+
unregisterAnimatable()
|
|
342
|
+
uninstall()
|
|
343
|
+
stopRechecks()
|
|
344
|
+
releaseScope()
|
|
345
|
+
disposeStartsDrag()
|
|
346
|
+
disposeItem()
|
|
347
|
+
disposeDrag()
|
|
348
|
+
disposeGestures()
|
|
349
|
+
disposeLayoutNode()
|
|
350
|
+
unregisterLayoutValues()
|
|
351
|
+
disposeSpine()
|
|
352
|
+
unregisterGate()
|
|
353
|
+
}
|
|
354
|
+
try {
|
|
355
|
+
// Its Live values in `style` (#130, ADR-0043): routed keys the spine follows through the gate.
|
|
356
|
+
const live = LiveStyle.createLiveStyle({ registry: registryNow, onDroppedTransform: droppedTransformWarning(provider, id), reactivity, ownValues: provider.valueReads.ownValues })
|
|
357
|
+
live.css(config.style)
|
|
358
|
+
// Where it starts (ADR-0003), read once: the config the view rendered it with, its inherited `initial`
|
|
359
|
+
// included (#50), at its `animate` under a presence's `initial: false` (#134).
|
|
360
|
+
const start = Spine.startOf(view, inherited, PresenceRecord.presenceBlocksInitial(context), reactivity.untrack)
|
|
361
|
+
// A variant whose resolver throws is this element's alone: reported once at its mount and once a run
|
|
362
|
+
// of throws until it resolves, the element keeping its last target, and nothing thrown into the
|
|
363
|
+
// render, which would crash the app (#979; ADR-0074). Each render's Starting style resolves it silently.
|
|
364
|
+
const variantFailures = Spine.variantFailuresOf(provider.runtime)
|
|
365
|
+
Spine.reportStart(variantFailures, start)
|
|
366
|
+
const snapshot = Spine.snapshotOf(start)
|
|
367
|
+
// Its Transform template (#443), drawn with its first write: the one at mount, then each other one.
|
|
368
|
+
const templateAtMount = config.transformTemplate
|
|
369
|
+
// The keys its Starting style set, switched to the user's in its first commit. A Variant child's
|
|
370
|
+
// inherited Starting style wasn't rendered by the view: written now, inside the patch (P2). So is a
|
|
371
|
+
// child of a `w.Presence({ initial: false })`: the view rendered it at its `Animate` (the walk at a
|
|
372
|
+
// Provider element's build, #794), where only the presence's first render starts it there (#134).
|
|
373
|
+
const starting = Style.starting(tag, ElementSetup.drawnAtRest(start.initialValues, false, templateAtMount)).style
|
|
374
|
+
if (Bool.or(Predicate.isNotUndefined(inherited), UndefinedOr.match(presence, { onUndefined: constFalse, onDefined: (p) => p.holds() }))) writeStartingStyle(element, starting)
|
|
375
|
+
const startingKeys = Rec.keys(starting)
|
|
376
|
+
// Its Appear animation, when it hydrates one the server rendered (ADR-0044 decision 6; #794, Q10):
|
|
377
|
+
// found by the slot its inline `animation` names, which the hydration render kept, taken over by its
|
|
378
|
+
// first Retarget that starts, as far in as the CSS has got, and removed in its first commit, the
|
|
379
|
+
// Handoff. Asked at every mount, a string read: an element a client render made names no slot. One
|
|
380
|
+
// found keeps hydration's window open until that commit, so no render in between strips the slot.
|
|
381
|
+
const handoff = Option.getOrUndefined(AppearAnimations.handoffOf(element))
|
|
382
|
+
releaseHydration = hydrationMounted(state, Predicate.isNotUndefined(handoff))
|
|
383
|
+
const sink: FlushGate.Sink = ElementSetup.releasingAppear(
|
|
384
|
+
Spine.withOnUpdate(
|
|
385
|
+
{
|
|
386
|
+
target: element,
|
|
387
|
+
beforeFirstCommit: () => {
|
|
388
|
+
switchToUserStyle(element, tag, startingKeys, config, registryNow)
|
|
389
|
+
releaseHydration()
|
|
390
|
+
},
|
|
334
391
|
},
|
|
392
|
+
view.onUpdate,
|
|
393
|
+
configNow,
|
|
394
|
+
),
|
|
395
|
+
handoff,
|
|
396
|
+
element,
|
|
397
|
+
)
|
|
398
|
+
unregisterGate = provider.gate.register(id, sink, ElementSetup.registeredValuesOf(templateAtMount))
|
|
399
|
+
// The user's style now, for its Base values (ADR-0022): the config's, as the view last delivered it.
|
|
400
|
+
const styleNow = (): object | string | undefined => config.style
|
|
401
|
+
const links = ElementSetup.startLinksOf(element, styleNow, live)
|
|
402
|
+
// Reduced motion (ADR-0029) and skipped animations (#468) under its nearest `w.Config`, read at each Retarget.
|
|
403
|
+
const reducedMotion = reducedMotionUnder(provider, configValue)
|
|
404
|
+
const skipped = WardicConfigValue.skipAnimationsOf(configValue)
|
|
405
|
+
const skipAnimations = (): boolean => paused() || skipped()
|
|
406
|
+
// Where its drag's and its pan's points are (#793, Q9): its nearest `w.Config`'s `transformPagePoint`, read at each down.
|
|
407
|
+
const pagePoint = (): WardConfig.WardicTransformPoint | undefined => UndefinedOr.match(configValue, { onUndefined: constUndefined, onDefined: (v) => v.transformPagePoint() })
|
|
408
|
+
// Its presence record (ADR-0007): what its presence drives its exit with after Foldkit removes it,
|
|
409
|
+
// resolved from its `Exit` as it leaves; the presence owns the registration. And where it starts when
|
|
410
|
+
// it takes over from a leaver under its key (#286).
|
|
411
|
+
const exitConfig = { current: Spine.exitConfigOf(view, inherited) }
|
|
412
|
+
const record = UndefinedOr.map(context, (ctx) => {
|
|
413
|
+
const rec = Spine.presenceRecordOf(element, start, (custom, inheritedNames) => Spine.exitTargetOf(exitConfig.current, custom, snapshot, inheritedNames), links, Spine.presenceTreeOf(view), snapshot, reducedMotion, skipAnimations)
|
|
414
|
+
unregisterRecord = ctx.register(rec)
|
|
415
|
+
return rec
|
|
416
|
+
})
|
|
417
|
+
const taken = PresenceRecord.presenceSeedOf(context, element)
|
|
418
|
+
const recordFrame = Spine.recordFrameOf(record)
|
|
419
|
+
// Its gestures (#793; decision 23): each started as a delivery wants it, its entry in the Override
|
|
420
|
+
// stack re-resolved as it flips, and its Variant children told through the port's watches (#291).
|
|
421
|
+
const gestures = gesturesOf({
|
|
422
|
+
provider,
|
|
423
|
+
element,
|
|
424
|
+
config: configNow,
|
|
425
|
+
dispatch,
|
|
426
|
+
onChange: () => {
|
|
427
|
+
retarget()
|
|
428
|
+
recheck()
|
|
335
429
|
},
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
// Batch member's hold, #665) at make from it, so a `Drag` a later render adds registers none.
|
|
387
|
-
const spineOptions: Spine.ElementSpineOptions & SpineDragOptions = {
|
|
388
|
-
runtime: provider.runtime,
|
|
389
|
-
gate: provider.gate,
|
|
390
|
-
id,
|
|
391
|
-
element,
|
|
392
|
-
tag,
|
|
393
|
-
config: configNow,
|
|
394
|
-
parent: inherited,
|
|
395
|
-
canStart: node.canStart,
|
|
396
|
-
extraDelay: node.extraDelay,
|
|
397
|
-
onFrame: node.onFrame,
|
|
398
|
-
byName: node.names,
|
|
399
|
-
reducedMotion,
|
|
400
|
-
skipAnimations,
|
|
401
|
-
positionalKeys: provider.positionalKeys,
|
|
402
|
-
defaultTransition: provider.defaultTransition,
|
|
403
|
-
ownValues: provider.valueReads.ownValues,
|
|
404
|
-
measuredPairs: provider.valueReads.measuredPairs,
|
|
405
|
-
variableValues: provider.valueReads.variableValues,
|
|
406
|
-
start,
|
|
407
|
-
snapshot,
|
|
408
|
-
reuse: Spine.makeReuse(),
|
|
409
|
-
links,
|
|
410
|
-
styleNow,
|
|
411
|
-
live,
|
|
412
|
-
builtFeatures: provider.registry.built,
|
|
413
|
-
presence: record,
|
|
414
|
-
projected: false,
|
|
415
|
-
dragAxis: DragDefaults.dragAxisOf(view, { dragAxis: UndefinedOr.map(MutableRef.get(item), (joined) => joined.dragAxis) }),
|
|
416
|
-
drag: undefined,
|
|
417
|
-
handoff,
|
|
418
|
-
// Motion's onAnimationStart / onAnimationComplete (decision 23), as Messages through `dispatch`.
|
|
419
|
-
animation: Spine.animationCallbacks(provider.runtime, id),
|
|
420
|
-
diagnostics: devDiagnostics(),
|
|
421
|
-
}
|
|
422
|
-
const spine = Spine.makeElementSpine(spineOptions)
|
|
423
|
-
UndefinedOr.map(taken, (seed) => spine.seed(seed))
|
|
424
|
-
// The `StartsDrag` element (Q8): its downs start its controls' drags, from the first delivery that gives them.
|
|
425
|
-
const startsDrag = startsDragOf(element, () => config)
|
|
426
|
-
// Its Animation scope (#798, Q7 and Q9): the scope's element from now, and the animations started in it stopped at its release.
|
|
427
|
-
const releaseScope = UndefinedOr.match(config.animationScope, { onUndefined: () => constVoid, onDefined: (scope) => scopeMounted(scope, element) })
|
|
428
|
-
// Its layout (ADR-0009, ADR-0010; decision 30): one projection node for `Layout`, `LayoutId`,
|
|
429
|
-
// `LayoutScroll` or `LayoutRoot`, on the provider's layout, built at the first; and, with a layout
|
|
430
|
-
// built, its values by element, for a twin's flight to follow (ADR-0012 *Amendment (#137)*). Each
|
|
431
|
-
// joined at mount, or as a load brings the Feature (#793, Q15).
|
|
432
|
-
// Its config as dom's layout code reads it: the layout keys alone.
|
|
433
|
-
const wardConfig = (): WardConfig.WardConfig => view as WardConfig.WardConfig
|
|
434
|
-
const builtProjection = (): ProjectionSystem.Shape | undefined => Keys.projectionIn(provider.registry.built())
|
|
435
|
-
const layoutNode = MutableRef.make<LayoutNode | undefined>(undefined)
|
|
436
|
-
const unregisterValues = MutableRef.make<(() => void) | undefined>(undefined)
|
|
437
|
-
const joinLayout = (): void => {
|
|
438
|
-
if (Bool.and(Predicate.isUndefined(MutableRef.get(layoutNode)), Feature.wantsLayoutNode(wardConfig()))) {
|
|
439
|
-
MutableRef.set(layoutNode, UndefinedOr.map(layoutOf(provider, state), (made) =>
|
|
440
|
-
made.projection.register(
|
|
441
|
-
made.nodes.registrationOf(
|
|
442
|
-
made.nodes.optionsOf({
|
|
443
|
-
id,
|
|
444
|
-
element,
|
|
445
|
-
config: wardConfig,
|
|
446
|
-
parent: inherited,
|
|
447
|
-
snapshot,
|
|
448
|
-
// What its release runs on (ADR-0016, *Amendment (#140)*; Q10): the element's drag transition, read now.
|
|
449
|
-
dragTransition: DragTransition.dragTransitionOf(view.dragElastic, view.dragTransition),
|
|
450
|
-
// Raised while dragged as a Reorder item (ADR-0020), over the rest.
|
|
451
|
-
raiseWhileDragged: Predicate.isNotUndefined(MutableRef.get(item)),
|
|
452
|
-
taken,
|
|
453
|
-
layoutGroup: layoutGroupOf(element),
|
|
454
|
-
reducedMotion,
|
|
455
|
-
skipAnimations,
|
|
456
|
-
heldTransform: ElementSetup.heldTransformFor(snapshot, templateAtMount, () => view.transformTemplate),
|
|
457
|
-
}),
|
|
458
|
-
),
|
|
459
|
-
)))
|
|
460
|
-
registerItemNode()
|
|
430
|
+
id,
|
|
431
|
+
pagePoint,
|
|
432
|
+
// A Reorder item's keys are its Keyboard reorder's (ADR-0037): its press starts from no key.
|
|
433
|
+
keysTaken: () => Predicate.isNotUndefined(MutableRef.get(item)),
|
|
434
|
+
})
|
|
435
|
+
disposeGestures = gestures.dispose
|
|
436
|
+
node.bindGestures(gestures.states)
|
|
437
|
+
node.reportsTo(variantFailures)
|
|
438
|
+
// A Reorder item (decision 28): joined to the group above it, which decides its drag's axis and hears
|
|
439
|
+
// its samples; its keyboard lift turns `WhileDrag` on. Joined now, or as a load brings the Features (Q15).
|
|
440
|
+
const item = MutableRef.make(reorderItemOf(provider, element, id, () => config, dispatch, gestures.lift))
|
|
441
|
+
disposeItem = () => UndefinedOr.map(MutableRef.get(item), (joined) => joined.dispose())
|
|
442
|
+
// Its spine's options, with what its drag writes as its track starts (ADR-0004; #793, PR 2): its
|
|
443
|
+
// axis, its track and whether it drives a layout node, which the spine reads where it uses them.
|
|
444
|
+
// The axis is seeded from the config at mount too, as Solid's: the spine registers its drag hook (a
|
|
445
|
+
// Batch member's hold, #665) at make from it, so a `Drag` a later render adds registers none.
|
|
446
|
+
const spineOptions: Spine.SubjectSpineOptions & SpineDragOptions = {
|
|
447
|
+
runtime: provider.runtime,
|
|
448
|
+
gate: provider.gate,
|
|
449
|
+
id,
|
|
450
|
+
subject: element,
|
|
451
|
+
tag,
|
|
452
|
+
config: configNow,
|
|
453
|
+
parent: inherited,
|
|
454
|
+
canStart: node.canStart,
|
|
455
|
+
extraDelay: node.extraDelay,
|
|
456
|
+
onFrame: node.onFrame,
|
|
457
|
+
byName: node.names,
|
|
458
|
+
reducedMotion,
|
|
459
|
+
skipAnimations,
|
|
460
|
+
positionalKeys: provider.positionalKeys,
|
|
461
|
+
defaultTransition: provider.defaultTransition,
|
|
462
|
+
ownValues: provider.valueReads.ownValues,
|
|
463
|
+
measuredPairs: provider.valueReads.measuredPairs,
|
|
464
|
+
variableValues: provider.valueReads.variableValues,
|
|
465
|
+
start,
|
|
466
|
+
snapshot,
|
|
467
|
+
reuse: Spine.makeReuse(),
|
|
468
|
+
links,
|
|
469
|
+
styleNow,
|
|
470
|
+
live,
|
|
471
|
+
builtFeatures: provider.registry.built,
|
|
472
|
+
presence: record,
|
|
473
|
+
projected: false,
|
|
474
|
+
dragAxis: DragDefaults.dragAxisOf(view, { dragAxis: UndefinedOr.map(MutableRef.get(item), (joined) => joined.dragAxis) }),
|
|
475
|
+
drag: undefined,
|
|
476
|
+
handoff,
|
|
477
|
+
// Motion's onAnimationStart / onAnimationComplete (decision 23), as Messages through `dispatch`.
|
|
478
|
+
animation: Spine.animationCallbacks(provider.runtime, id),
|
|
479
|
+
diagnostics: devDiagnostics(),
|
|
461
480
|
}
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
// change asks for the node's measure, or, on an element with no node (a group's), the whole tree's.
|
|
508
|
-
let dependency = config.layoutDependency
|
|
509
|
-
const dependencyChanged = (): void => {
|
|
510
|
-
const next = config.layoutDependency
|
|
511
|
-
if (Equal.equals(dependency, next)) return
|
|
512
|
-
dependency = next
|
|
513
|
-
const ask = (): void => {
|
|
514
|
-
UndefinedOr.match(MutableRef.get(layoutNode), {
|
|
515
|
-
onDefined: (node) => node.notify(),
|
|
516
|
-
onUndefined: () => UndefinedOr.map(builtProjection(), (projection) => projection.notify()),
|
|
517
|
-
})
|
|
481
|
+
const spine = Spine.makeSubjectSpine(spineOptions)
|
|
482
|
+
disposeSpine = spine.dispose
|
|
483
|
+
UndefinedOr.map(taken, (seed) => spine.seed(seed))
|
|
484
|
+
// The `StartsDrag` element (Q8): its downs start its controls' drags, from the first delivery that gives them.
|
|
485
|
+
const startsDrag = startsDragOf(element, () => config)
|
|
486
|
+
disposeStartsDrag = startsDrag.dispose
|
|
487
|
+
// Its Animation scope (#798, Q7 and Q9): the scope's element from now, and the animations started in it stopped at its release.
|
|
488
|
+
releaseScope = UndefinedOr.match(config.animationScope, { onUndefined: () => constVoid, onDefined: (scope) => scopeMounted(scope, element) })
|
|
489
|
+
// Its layout (ADR-0009, ADR-0010; decision 30): one projection node for `Layout`, `LayoutId`,
|
|
490
|
+
// `LayoutScroll` or `LayoutRoot`, on the provider's layout, built at the first; and, with a layout
|
|
491
|
+
// built, its values by element, for a twin's flight to follow (ADR-0012 *Amendment (#137)*). Each
|
|
492
|
+
// joined at mount, or as a load brings the Feature (#793, Q15).
|
|
493
|
+
// Its config as dom's layout code reads it: the layout keys alone.
|
|
494
|
+
const wardConfig = (): WardConfig.WardConfig => view as WardConfig.WardConfig
|
|
495
|
+
const builtProjection = (): ProjectionSystem.Shape | undefined => Keys.projectionIn(provider.registry.built())
|
|
496
|
+
const layoutNode = MutableRef.make<LayoutNode | undefined>(undefined)
|
|
497
|
+
const unregisterValues = MutableRef.make<(() => void) | undefined>(undefined)
|
|
498
|
+
disposeLayoutNode = () => UndefinedOr.map(MutableRef.get(layoutNode), (made) => made.dispose())
|
|
499
|
+
unregisterLayoutValues = () => UndefinedOr.map(MutableRef.get(unregisterValues), (unregisterNow) => unregisterNow())
|
|
500
|
+
const joinLayout = (): void => {
|
|
501
|
+
if (Bool.and(Predicate.isUndefined(MutableRef.get(layoutNode)), Feature.wantsLayoutNode(wardConfig()))) {
|
|
502
|
+
MutableRef.set(layoutNode, UndefinedOr.map(layoutOf(provider, state), (made) =>
|
|
503
|
+
made.projection.register(
|
|
504
|
+
made.nodes.registrationOf(
|
|
505
|
+
made.nodes.optionsOf({
|
|
506
|
+
id,
|
|
507
|
+
element,
|
|
508
|
+
config: wardConfig,
|
|
509
|
+
parent: inherited,
|
|
510
|
+
snapshot,
|
|
511
|
+
// What its release runs on (ADR-0016, *Amendment (#140)*; Q10): the element's drag transition, read now.
|
|
512
|
+
dragTransition: DragTransition.dragTransitionOf(view.dragElastic, view.dragTransition),
|
|
513
|
+
// Raised while dragged as a Reorder item (ADR-0020), over the rest.
|
|
514
|
+
raiseWhileDragged: Predicate.isNotUndefined(MutableRef.get(item)),
|
|
515
|
+
taken,
|
|
516
|
+
layoutGroup: layoutGroupOf(element),
|
|
517
|
+
reducedMotion,
|
|
518
|
+
skipAnimations,
|
|
519
|
+
heldTransform: ElementSetup.heldTransformFor(snapshot, templateAtMount, () => view.transformTemplate),
|
|
520
|
+
}),
|
|
521
|
+
),
|
|
522
|
+
)))
|
|
523
|
+
registerItemNode()
|
|
524
|
+
}
|
|
525
|
+
if (Predicate.isUndefined(MutableRef.get(unregisterValues))) MutableRef.set(unregisterValues, UndefinedOr.map(builtProjection(), (projection) => projection.registerValues(element, () => snapshot.values)))
|
|
518
526
|
}
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
UndefinedOr.match(builtProjection(), { onUndefined: ask, onDefined: (projection) => projection.instant(ask) })
|
|
523
|
-
return
|
|
527
|
+
/** A Reorder item's node, registered with its group once both are there (ADR-0020): its box, its drag offset and its lift. */
|
|
528
|
+
const registerItemNode = (): void => {
|
|
529
|
+
UndefinedOr.map(MutableRef.get(layoutNode), (made) => UndefinedOr.map(MutableRef.get(item), (joined) => joined.onLayoutHandle(made)))
|
|
524
530
|
}
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
531
|
+
/** The item joined as a load brings the Features (Q15): its group made by it if its own Mount hasn't, its node registered. */
|
|
532
|
+
const joinItem = (): void => {
|
|
533
|
+
if (Predicate.isNotUndefined(MutableRef.get(item))) return
|
|
534
|
+
MutableRef.set(item, reorderItemOf(provider, element, id, () => config, dispatch, gestures.lift))
|
|
535
|
+
registerItemNode()
|
|
536
|
+
}
|
|
537
|
+
joinLayout()
|
|
538
|
+
// Its drag (ADR-0004; #793, PR 2): dom's track, started as a delivery wants it, driving the layout
|
|
539
|
+
// node it has then; its samples and its hold on `x`/`y` to the gestures, its release's end too.
|
|
540
|
+
const drag = dragOf({
|
|
541
|
+
provider,
|
|
542
|
+
element,
|
|
543
|
+
id,
|
|
544
|
+
config: configNow,
|
|
545
|
+
snapshot,
|
|
546
|
+
recordFrame,
|
|
547
|
+
live,
|
|
548
|
+
spine: spineOptions,
|
|
549
|
+
layoutNode: () => MutableRef.get(layoutNode),
|
|
550
|
+
// A Reorder item's axis at each gesture's start, and its samples to its group before the callbacks (ADR-0020).
|
|
551
|
+
itemAxis: () => UndefinedOr.map(MutableRef.get(item), (joined) => joined.dragAxis),
|
|
552
|
+
pagePoint,
|
|
553
|
+
skipAnimations,
|
|
554
|
+
onDragging: gestures.dragHeld,
|
|
555
|
+
onSample: (sample) => {
|
|
556
|
+
UndefinedOr.map(MutableRef.get(item), (joined) => joined.onDragSample(sample))
|
|
557
|
+
gestures.dragged(sample)
|
|
558
|
+
},
|
|
559
|
+
onReleaseEnd: gestures.released,
|
|
560
|
+
})
|
|
561
|
+
disposeDrag = drag.dispose
|
|
562
|
+
// A load's Features arriving (Q15): what the element wants of them starts then; an item joins its
|
|
563
|
+
// group first, and a `layout` from the same load makes its node before the drag's track drives it (#582).
|
|
564
|
+
stopRechecks = provider.onFeatures(() => {
|
|
565
|
+
joinItem()
|
|
566
|
+
joinLayout()
|
|
554
567
|
drag.check()
|
|
555
568
|
gestures.check()
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
569
|
+
})
|
|
570
|
+
// Its `LayoutDependency`, compared per delivery as Motion's `prevProps.layoutDependency !==` is: a
|
|
571
|
+
// change asks for the node's measure, or, on an element with no node (a group's), the whole tree's.
|
|
572
|
+
let dependency = config.layoutDependency
|
|
573
|
+
const dependencyChanged = (): void => {
|
|
574
|
+
const next = config.layoutDependency
|
|
575
|
+
if (Equal.equals(dependency, next)) return
|
|
576
|
+
dependency = next
|
|
577
|
+
const ask = (): void => {
|
|
578
|
+
UndefinedOr.match(MutableRef.get(layoutNode), {
|
|
579
|
+
onDefined: (node) => node.notify(),
|
|
580
|
+
onUndefined: () => UndefinedOr.map(builtProjection(), (projection) => projection.notify()),
|
|
581
|
+
})
|
|
582
|
+
}
|
|
583
|
+
// A View Transition's render (decision 33): the pass it asks for is an Instant change of the layout.
|
|
584
|
+
if (state.transitioning) {
|
|
585
|
+
state.transitioning = false
|
|
586
|
+
UndefinedOr.match(builtProjection(), { onUndefined: ask, onDefined: (projection) => projection.instant(ask) })
|
|
587
|
+
return
|
|
588
|
+
}
|
|
589
|
+
ask()
|
|
560
590
|
}
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
591
|
+
// The Override stack resolved (ADR-0007), compared by value (#470): a delivery that resolves the same
|
|
592
|
+
// targets tells nothing, as a `transition` change alone doesn't in Motion; a gesture's flip
|
|
593
|
+
// re-resolves it with the entries on now.
|
|
594
|
+
let last: Spine.Resolution | undefined
|
|
595
|
+
const retarget = (): void => {
|
|
596
|
+
const next = Spine.keptOf(variantFailures, Spine.resolutionOf(view, inherited, start.initialLink, gestures.active(), snapshot, node.change()))
|
|
597
|
+
if (Predicate.isNotUndefined(last) && Spine.sameResolution(last, next)) return
|
|
598
|
+
last = next
|
|
599
|
+
spine.retarget(next)
|
|
600
|
+
}
|
|
601
|
+
// Its Delivery (decision 20): each render's fresh config, inside the patch, Retargets at once (#791, Q14),
|
|
602
|
+
// after the binding's hint (decision 32), so the Retarget's legs take their first step in this frame.
|
|
603
|
+
// A defect there is Foldkit's patch's otherwise, which would stop the whole app (decision 13): reported,
|
|
604
|
+
// and the element stays where it is.
|
|
605
|
+
uninstall = installSetter(element, (delivered) => {
|
|
606
|
+
config = configOf(delivered)
|
|
607
|
+
if (DEV) warnChangedControls(provider, id, controls, config)
|
|
608
|
+
view = viewOf()
|
|
609
|
+
// A Reorder group's values that changed (decision 28): its controller told, before the pass that lays the items out in them.
|
|
610
|
+
groupDelivered(element)
|
|
611
|
+
exitConfig.current = Spine.exitConfigOf(view, inherited)
|
|
612
|
+
patchTouched()
|
|
613
|
+
hintFrameUnless(provider.loop, paused)
|
|
614
|
+
try {
|
|
615
|
+
live.css(config.style)
|
|
616
|
+
dependencyChanged()
|
|
617
|
+
// A gesture this render wants starts now (ADR-0047 decision 5): a callback added later starts its recognizer, a `Drag` its track.
|
|
618
|
+
drag.check()
|
|
619
|
+
gestures.check()
|
|
620
|
+
startsDrag.check()
|
|
621
|
+
retarget()
|
|
622
|
+
} catch (error) {
|
|
623
|
+
provider.runtime.runFork(Report.failure(RETARGET_FAILED, Cause.die(error)))
|
|
624
|
+
}
|
|
625
|
+
})
|
|
626
|
+
// Its Live values followed from its first routed key on (#130), its text (decision 16), and its
|
|
627
|
+
// Transform template after the one at mount (#443), which its presence record draws its exit through.
|
|
628
|
+
spine.follow({ resolved: () => UndefinedOr.match(last, { onUndefined: () => Spine.NO_VALUES, onDefined: (resolution) => resolution.resolved }), dragging: gestures.dragging })
|
|
629
|
+
unfollowText = followText(element, config.text, registry)
|
|
630
|
+
unfollowTemplate = UndefinedOr.match(templateAtMount, {
|
|
584
631
|
onUndefined: () => constVoid,
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
632
|
+
onDefined: (template) => {
|
|
633
|
+
recordFrame(ElementSetup.registeredValuesOf(template) as Values.Values)
|
|
634
|
+
return ElementSetup.followTemplate(template, () => view.transformTemplate, reactivity.watch, (next) => {
|
|
635
|
+
provider.gate.write(id, { ...snapshot.values, [DomRenderer.TEMPLATE_KEY]: next })
|
|
636
|
+
recordFrame({ [DomRenderer.TEMPLATE_KEY]: next } as unknown as Values.Values)
|
|
637
|
+
})
|
|
589
638
|
},
|
|
590
639
|
})
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
640
|
+
// Its Imperative animations (#433) go through its spine while it's mounted.
|
|
641
|
+
unregisterAnimatable = Imperative.registerAnimatable(element, spine)
|
|
642
|
+
// What a Variant child hears without a delivery of its own (P17): the name its ancestor hands down and
|
|
643
|
+
// the gestures it hands on (#291), as one trigger key, and its `when` gate opening, re-checked once a
|
|
644
|
+
// patch, at each settle that changes a gate (decision 17) and at each gesture flip above it.
|
|
645
|
+
if (Predicate.isNotUndefined(node.names)) {
|
|
646
|
+
const unwatchName = UndefinedOr.match(inherited, {
|
|
647
|
+
onUndefined: () => constVoid,
|
|
648
|
+
// Its ancestor's Controls change is a trigger too (#433), even to the same name.
|
|
649
|
+
onDefined: (parentContext) => {
|
|
650
|
+
const inheritedChange = VariantTree.controlsChangeOf(undefined, parentContext)
|
|
651
|
+
return reactivity.watch(() => VariantTree.triggerKeyOf(parentContext.variant(), VariantTree.handDownFrom(parentContext), inheritedChange()), retarget)
|
|
652
|
+
},
|
|
653
|
+
})
|
|
654
|
+
unwatch = unwatchName
|
|
655
|
+
const unwatchGate = reactivity.watch(node.canStart, (open) => {
|
|
656
|
+
if (Bool.and(open, Predicate.isNotUndefined(last))) spine.retarget(UndefinedOr.getOrThrow(last))
|
|
657
|
+
})
|
|
658
|
+
unwatch = () => {
|
|
659
|
+
unwatchName()
|
|
660
|
+
unwatchGate()
|
|
661
|
+
}
|
|
597
662
|
}
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
663
|
+
// Its Animation controls reach it from its mount to its release (#798, Q4): each change sets its
|
|
664
|
+
// entry, re-resolves it on the change's override and tells the watches, its Variant children's
|
|
665
|
+
// triggers among them; their stop ends its legs where they are.
|
|
666
|
+
unsubscribe = UndefinedOr.match(controls, {
|
|
667
|
+
onUndefined: () => constVoid,
|
|
668
|
+
onDefined: (c) =>
|
|
669
|
+
AnimationControls.subscribe(
|
|
670
|
+
c,
|
|
671
|
+
AnimationControls.controlledSubject(
|
|
672
|
+
(change) => {
|
|
673
|
+
node.setChange(change)
|
|
674
|
+
view = viewOf()
|
|
675
|
+
retarget()
|
|
676
|
+
recheck()
|
|
677
|
+
},
|
|
678
|
+
{ custom: () => config.custom, snapshot },
|
|
679
|
+
spine.stop,
|
|
680
|
+
),
|
|
616
681
|
),
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
682
|
+
})
|
|
683
|
+
// Its drag and its gestures wanted at mount, then its first Retarget: from `initial` to `animate`.
|
|
684
|
+
drag.check()
|
|
685
|
+
gestures.check()
|
|
686
|
+
startsDrag.check()
|
|
687
|
+
retarget()
|
|
688
|
+
} catch (defect) {
|
|
689
|
+
// Its start's failure is its own (#997, ADR-0074), wherever it runs (its Mount's, its parent's, its
|
|
690
|
+
// presence's delivery): what it made released, its presence record too, reported once with its id,
|
|
691
|
+
// and never thrown on. Its node reports it settled, as its spine never will, so a parent waiting
|
|
692
|
+
// `afterChildren` goes on. Its release then drops what remains, its node in the tree.
|
|
693
|
+
releaseMade()
|
|
694
|
+
unregisterRecord()
|
|
695
|
+
node.onFrame(true)
|
|
696
|
+
reporterOf(provider, id)(MOUNT_FAILED, Cause.die(defect))
|
|
697
|
+
return () => dropNode(element)
|
|
698
|
+
}
|
|
624
699
|
return () => {
|
|
625
|
-
|
|
626
|
-
released()
|
|
627
|
-
unwatch()
|
|
628
|
-
unfollowText()
|
|
629
|
-
unfollowTemplate()
|
|
630
|
-
unregisterAnimatable()
|
|
631
|
-
uninstall()
|
|
632
|
-
stopRechecks()
|
|
633
|
-
releaseScope()
|
|
634
|
-
startsDrag.dispose()
|
|
635
|
-
UndefinedOr.map(MutableRef.get(item), (joined) => joined.dispose())
|
|
636
|
-
drag.dispose()
|
|
637
|
-
gestures.dispose()
|
|
638
|
-
UndefinedOr.map(MutableRef.get(layoutNode), (node) => node.dispose())
|
|
639
|
-
UndefinedOr.map(MutableRef.get(unregisterValues), (unregister) => unregister())
|
|
640
|
-
spine.dispose()
|
|
641
|
-
unregister()
|
|
700
|
+
releaseMade()
|
|
642
701
|
dropNode(element)
|
|
643
702
|
}
|
|
644
703
|
}
|