@wardic/foldkit 0.0.0-stage → 1.3.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/LICENSE +21 -0
- package/README.md +59 -2
- package/THIRD_PARTY_NOTICES.md +145 -0
- package/dist/AnimationControls.d.ts +37 -0
- package/dist/AnimationControls.d.ts.map +1 -0
- package/dist/AnimationControls.js +37 -0
- package/dist/AnimationControls.js.map +1 -0
- package/dist/AnimationScope.d.ts +20 -0
- package/dist/AnimationScope.d.ts.map +1 -0
- package/dist/AnimationScope.js +20 -0
- package/dist/AnimationScope.js.map +1 -0
- package/dist/DragControls.d.ts +25 -0
- package/dist/DragControls.d.ts.map +1 -0
- package/dist/DragControls.js +21 -0
- package/dist/DragControls.js.map +1 -0
- package/dist/Features.d.ts +36 -0
- package/dist/Features.d.ts.map +1 -0
- package/dist/Features.js +44 -0
- package/dist/Features.js.map +1 -0
- package/dist/Ward.d.ts +301 -0
- package/dist/Ward.d.ts.map +1 -0
- package/dist/Ward.js +6 -0
- package/dist/Ward.js.map +1 -0
- package/dist/Wardic.d.ts +363 -0
- package/dist/Wardic.d.ts.map +1 -0
- package/dist/Wardic.js +85 -0
- package/dist/Wardic.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/internal/builder.d.ts +8 -0
- package/dist/internal/builder.d.ts.map +1 -0
- package/dist/internal/builder.js +242 -0
- package/dist/internal/builder.js.map +1 -0
- package/dist/internal/commands.d.ts +143 -0
- package/dist/internal/commands.d.ts.map +1 -0
- package/dist/internal/commands.js +242 -0
- package/dist/internal/commands.js.map +1 -0
- package/dist/internal/delivery.d.ts +44 -0
- package/dist/internal/delivery.d.ts.map +1 -0
- package/dist/internal/delivery.js +85 -0
- package/dist/internal/delivery.js.map +1 -0
- package/dist/internal/dev.d.ts +10 -0
- package/dist/internal/dev.d.ts.map +1 -0
- package/dist/internal/dev.js +10 -0
- package/dist/internal/dev.js.map +1 -0
- package/dist/internal/dev.production.d.ts +8 -0
- package/dist/internal/dev.production.d.ts.map +1 -0
- package/dist/internal/dev.production.js +8 -0
- package/dist/internal/dev.production.js.map +1 -0
- package/dist/internal/drag.d.ts +66 -0
- package/dist/internal/drag.d.ts.map +1 -0
- package/dist/internal/drag.js +71 -0
- package/dist/internal/drag.js.map +1 -0
- package/dist/internal/element.d.ts +59 -0
- package/dist/internal/element.d.ts.map +1 -0
- package/dist/internal/element.js +582 -0
- package/dist/internal/element.js.map +1 -0
- package/dist/internal/gestures.d.ts +62 -0
- package/dist/internal/gestures.d.ts.map +1 -0
- package/dist/internal/gestures.js +109 -0
- package/dist/internal/gestures.js.map +1 -0
- package/dist/internal/hydrate.d.ts +5 -0
- package/dist/internal/hydrate.d.ts.map +1 -0
- package/dist/internal/hydrate.js +27 -0
- package/dist/internal/hydrate.js.map +1 -0
- package/dist/internal/keys.d.ts +21 -0
- package/dist/internal/keys.d.ts.map +1 -0
- package/dist/internal/keys.js +12 -0
- package/dist/internal/keys.js.map +1 -0
- package/dist/internal/layout.d.ts +29 -0
- package/dist/internal/layout.d.ts.map +1 -0
- package/dist/internal/layout.js +88 -0
- package/dist/internal/layout.js.map +1 -0
- package/dist/internal/mount.d.ts +22 -0
- package/dist/internal/mount.d.ts.map +1 -0
- package/dist/internal/mount.js +152 -0
- package/dist/internal/mount.js.map +1 -0
- package/dist/internal/presence.d.ts +33 -0
- package/dist/internal/presence.d.ts.map +1 -0
- package/dist/internal/presence.js +338 -0
- package/dist/internal/presence.js.map +1 -0
- package/dist/internal/reactivity.d.ts +15 -0
- package/dist/internal/reactivity.d.ts.map +1 -0
- package/dist/internal/reactivity.js +26 -0
- package/dist/internal/reactivity.js.map +1 -0
- package/dist/internal/reorder.d.ts +47 -0
- package/dist/internal/reorder.d.ts.map +1 -0
- package/dist/internal/reorder.js +250 -0
- package/dist/internal/reorder.js.map +1 -0
- package/dist/internal/scope.d.ts +28 -0
- package/dist/internal/scope.d.ts.map +1 -0
- package/dist/internal/scope.js +44 -0
- package/dist/internal/scope.js.map +1 -0
- package/dist/internal/server.d.ts +13 -0
- package/dist/internal/server.d.ts.map +1 -0
- package/dist/internal/server.js +13 -0
- package/dist/internal/server.js.map +1 -0
- package/dist/internal/server.node.d.ts +8 -0
- package/dist/internal/server.node.d.ts.map +1 -0
- package/dist/internal/server.node.js +8 -0
- package/dist/internal/server.node.js.map +1 -0
- package/dist/internal/services.d.ts +231 -0
- package/dist/internal/services.d.ts.map +1 -0
- package/dist/internal/services.js +350 -0
- package/dist/internal/services.js.map +1 -0
- package/dist/internal/tree.d.ts +71 -0
- package/dist/internal/tree.d.ts.map +1 -0
- package/dist/internal/tree.js +207 -0
- package/dist/internal/tree.js.map +1 -0
- package/dist/internal/variant-node.d.ts +62 -0
- package/dist/internal/variant-node.d.ts.map +1 -0
- package/dist/internal/variant-node.js +279 -0
- package/dist/internal/variant-node.js.map +1 -0
- package/dist/internal/view-transition.d.ts +10 -0
- package/dist/internal/view-transition.d.ts.map +1 -0
- package/dist/internal/view-transition.js +36 -0
- package/dist/internal/view-transition.js.map +1 -0
- package/dist/internal/walk.d.ts +26 -0
- package/dist/internal/walk.d.ts.map +1 -0
- package/dist/internal/walk.js +162 -0
- package/dist/internal/walk.js.map +1 -0
- package/package.json +99 -4
- package/src/AnimationControls.ts +46 -0
- package/src/AnimationScope.ts +19 -0
- package/src/DragControls.ts +27 -0
- package/src/Features.ts +45 -0
- package/src/Ward.ts +434 -0
- package/src/Wardic.ts +410 -0
- package/src/index.ts +20 -0
- package/src/internal/builder.ts +262 -0
- package/src/internal/commands.ts +359 -0
- package/src/internal/delivery.ts +116 -0
- package/src/internal/dev.production.ts +7 -0
- package/src/internal/dev.ts +9 -0
- package/src/internal/drag.ts +136 -0
- package/src/internal/element.ts +668 -0
- package/src/internal/gestures.ts +184 -0
- package/src/internal/hydrate.ts +29 -0
- package/src/internal/keys.ts +19 -0
- package/src/internal/layout.ts +109 -0
- package/src/internal/mount.ts +181 -0
- package/src/internal/presence.ts +362 -0
- package/src/internal/reactivity.ts +45 -0
- package/src/internal/reorder.ts +313 -0
- package/src/internal/scope.ts +60 -0
- package/src/internal/server.node.ts +7 -0
- package/src/internal/server.ts +12 -0
- package/src/internal/services.ts +508 -0
- package/src/internal/tree.ts +230 -0
- package/src/internal/variant-node.ts +352 -0
- package/src/internal/view-transition.ts +43 -0
- package/src/internal/walk.ts +211 -0
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import type * as CoreConfig from "@wardic/core/unstable/Config";
|
|
2
|
+
import * as Spine from "@wardic/core/unstable/Spine";
|
|
3
|
+
import * as VariantTree from "@wardic/core/unstable/VariantTree";
|
|
4
|
+
import * as WardicConfigValue from "@wardic/core/unstable/WardicConfigValue";
|
|
5
|
+
import * as Style from "@wardic/dom/Style";
|
|
6
|
+
import type * as WardConfig from "@wardic/dom/unstable/WardConfig";
|
|
7
|
+
import type * as AtomRegistry from "effect/reactivity/AtomRegistry";
|
|
8
|
+
import type * as Ward from "../Ward.ts";
|
|
9
|
+
import { type Provider, type State } from "./services.ts";
|
|
10
|
+
/** An element's config as the spine reads it: what the view delivered, with its merged `style`. */
|
|
11
|
+
export type Config = Ward.Config<unknown> & WardConfig.SpineConfig;
|
|
12
|
+
/** The config delivered to an element, or none. */
|
|
13
|
+
export declare const configOf: (delivered: unknown) => Config;
|
|
14
|
+
/**
|
|
15
|
+
* The element's Starting style, rendered by the view: the user's `style` with its `initial` on top,
|
|
16
|
+
* projected together, so a transform key of each joins one `transform` (#791, Q7); a Live value at
|
|
17
|
+
* what it reads through `registry` now; its Transform template under the renderer's key (#443). What
|
|
18
|
+
* `w.*` and the bundle render in their one `h.Style`, stringified for Foldkit's style module. A Variant
|
|
19
|
+
* child's inherited `initial` comes with `inherited`, the context its ancestor provides, and a child a
|
|
20
|
+
* `w.Presence({ initial: false })` holds at its `Animate` with `held` (#134): the walk at the
|
|
21
|
+
* `w.Provider()` element's build gives both (#794, Q7), and its Mount writes them for an element with
|
|
22
|
+
* no Provider element above.
|
|
23
|
+
*/
|
|
24
|
+
export declare const startingStyleOf: (tag: string | undefined, config: Config, registry: () => AtomRegistry.AtomRegistry, inherited?: VariantTree.WardicVariantContextValue, held?: boolean) => Style.Style;
|
|
25
|
+
/** 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). */
|
|
26
|
+
export declare const startingStyleFrom: (tag: string | undefined, config: Config, registry: () => AtomRegistry.AtomRegistry, start: Spine.Start) => Style.Style;
|
|
27
|
+
/** `patch`'s values as Foldkit's style module takes them: strings. */
|
|
28
|
+
export declare const stringified: (patch: Style.Style) => Record<string, string>;
|
|
29
|
+
/** What a callback's handler becomes for the spine or a presence: a function told what the callback is. */
|
|
30
|
+
export type Dispatch = <Args extends ReadonlyArray<unknown>>(handler: Ward.Callback<unknown, Args>) => (...args: Args) => void;
|
|
31
|
+
/** A {@link Dispatch} through `offer`, a Mount's queue, silenced while DevTools replay has the view (decision 34), whose history the Messages would change. */
|
|
32
|
+
export declare const dispatchUnlessPaused: (paused: () => boolean, offer: (message: unknown) => void) => Dispatch;
|
|
33
|
+
/** What sends a callback's Message (decision 23) through `offer`: a Message as it is; a function's answer, an `Option.none()` sending nothing. */
|
|
34
|
+
export declare const dispatcherOf: (offer: (message: unknown) => void) => Dispatch;
|
|
35
|
+
/** A `viewport` as dom reads it: Foldkit's, its `root` resolved into an accessor (`viewportRootOf`). */
|
|
36
|
+
export interface ViewportResolved extends Pick<Ward.ViewportOptions, "once" | "margin" | "amount"> {
|
|
37
|
+
readonly root?: (() => Element | undefined) | undefined;
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* An element's config as its spine, its gestures and its drag read it: the delivered one, its callbacks
|
|
41
|
+
* as the spine's functions (`onUpdate` the Atom's setter, the animation and layout callbacks' Messages
|
|
42
|
+
* sent), its viewport and its drag constraints resolved.
|
|
43
|
+
*/
|
|
44
|
+
export type View = Omit<Config, "viewport" | "onUpdate" | "dragConstraints"> & Pick<CoreConfig.SpineConfig, "onUpdate"> & Pick<WardConfig.WardConfig, "onLayoutAnimationStart" | "onLayoutAnimationComplete" | "dragConstraints"> & {
|
|
45
|
+
readonly viewport?: ViewportResolved | undefined;
|
|
46
|
+
};
|
|
47
|
+
/**
|
|
48
|
+
* Mount a `w.*` element on `provider`: its spine, its gate registration, its place in the tree and its
|
|
49
|
+
* Delivery's setter. `paused` says whether DevTools replay has the view (decision 34): every animation
|
|
50
|
+
* lands at once under it. `offer` sends a callback's Message through the element's Mount Stream.
|
|
51
|
+
* `root` is the Handle's app-wide config. Under a `w.Presence` (decision 29) the element is enrolled
|
|
52
|
+
* with it and starts in the presence's next delivery, after take-overs and holds are decided; else it
|
|
53
|
+
* starts once its nearest `w.*` ancestor has, or now at the top (#848: Foldkit mounts a child before
|
|
54
|
+
* its parent, and a tree mounted by one patch starts top-down this way, its Variant children's stagger
|
|
55
|
+
* slots set with every sibling registered). Returns the release: the element's teardown, run at its
|
|
56
|
+
* Mount's destroy, before Foldkit removes it.
|
|
57
|
+
*/
|
|
58
|
+
export declare const mountElement: (provider: Provider, state: State, element: HTMLElement, paused: () => boolean, offer: (message: unknown) => void, root: WardicConfigValue.WardicConfigValue | undefined) => (() => void);
|
|
59
|
+
//# sourceMappingURL=element.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"element.d.ts","sourceRoot":"","sources":["../../src/internal/element.ts"],"names":[],"mappings":"AAcA,OAAO,KAAK,KAAK,UAAU,MAAM,8BAA8B,CAAA;AAG/D,OAAO,KAAK,KAAK,MAAM,6BAA6B,CAAA;AACpD,OAAO,KAAK,WAAW,MAAM,mCAAmC,CAAA;AAChE,OAAO,KAAK,iBAAiB,MAAM,yCAAyC,CAAA;AAG5E,OAAO,KAAK,KAAK,MAAM,mBAAmB,CAAA;AAS1C,OAAO,KAAK,KAAK,UAAU,MAAM,iCAAiC,CAAA;AASlE,OAAO,KAAK,KAAK,YAAY,MAAM,gCAAgC,CAAA;AAGnE,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAA;AASvC,OAAO,EAAoB,KAAK,QAAQ,EAAsB,KAAK,KAAK,EAAE,MAAM,eAAe,CAAA;AAI/F,mGAAmG;AACnG,MAAM,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,UAAU,CAAC,WAAW,CAAA;AAKlE,mDAAmD;AACnD,eAAO,MAAM,QAAQ,cAAe,OAAO,KAAG,MAG7C,CAAA;AAoBD;;;;;;;;;GASG;AACH,eAAO,MAAM,eAAe,QAAS,MAAM,GAAG,SAAS,UAAU,MAAM,YAAY,MAAM,YAAY,CAAC,YAAY,cAAc,WAAW,CAAC,yBAAyB,qBAAiB,KAAK,CAAC,KACpD,CAAA;AAExI,2JAA2J;AAC3J,eAAO,MAAM,iBAAiB,QAAS,MAAM,GAAG,SAAS,UAAU,MAAM,YAAY,MAAM,YAAY,CAAC,YAAY,SAAS,KAAK,CAAC,KAAK,KAAG,KAAK,CAAC,KAC6B,CAAA;AAa9K,sEAAsE;AACtE,eAAO,MAAM,WAAW,UAAW,KAAK,CAAC,KAAK,KAAG,MAAM,CAAC,MAAM,EAAE,MAAM,CAA6C,CAAA;AAyBnH,2GAA2G;AAC3G,MAAM,MAAM,QAAQ,GAAG,CAAC,IAAI,SAAS,aAAa,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,CAAC,QAAQ,CAAC,OAAO,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,IAAI,EAAE,IAAI,KAAK,IAAI,CAAA;AAE9H,+JAA+J;AAC/J,eAAO,MAAM,oBAAoB,WAAY,MAAM,OAAO,SAAS,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAAG,QAI5F,CAAA;AAEJ,kJAAkJ;AAClJ,eAAO,MAAM,YAAY,UACf,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAAG,QAapC,CAAA;AAEH,wGAAwG;AACxG,MAAM,WAAW,gBAAiB,SAAQ,IAAI,CAAC,IAAI,CAAC,eAAe,EAAE,MAAM,GAAG,QAAQ,GAAG,QAAQ,CAAC;IAChG,QAAQ,CAAC,IAAI,CAAC,EAAE,CAAC,MAAM,OAAO,GAAG,SAAS,CAAC,GAAG,SAAS,CAAA;CACxD;AAED;;;;GAIG;AACH,MAAM,MAAM,IAAI,GAAG,IAAI,CAAC,MAAM,EAAE,UAAU,GAAG,UAAU,GAAG,iBAAiB,CAAC,GAC1E,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,CAAC,GACxC,IAAI,CAAC,UAAU,CAAC,UAAU,EAAE,wBAAwB,GAAG,2BAA2B,GAAG,iBAAiB,CAAC,GAAG;IAAE,QAAQ,CAAC,QAAQ,CAAC,EAAE,gBAAgB,GAAG,SAAS,CAAA;CAAE,CAAA;AAwFhK;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,aAAc,QAAQ,SAAS,KAAK,WAAW,WAAW,UAAU,MAAM,OAAO,SAAS,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,QAAQ,iBAAiB,CAAC,iBAAiB,GAAG,SAAS,KAAG,CAAC,MAAM,IAAI,CA+WjN,CAAA"}
|
|
@@ -0,0 +1,582 @@
|
|
|
1
|
+
import * as DomRenderer from "@wardic/dom/DomRenderer";
|
|
2
|
+
import * as AnimationControls from "@wardic/core/unstable/AnimationControls";
|
|
3
|
+
import * as PresenceRecord from "@wardic/core/unstable/PresenceRecord";
|
|
4
|
+
import * as Spine from "@wardic/core/unstable/Spine";
|
|
5
|
+
import * as VariantTree from "@wardic/core/unstable/VariantTree";
|
|
6
|
+
import * as WardicConfigValue from "@wardic/core/unstable/WardicConfigValue";
|
|
7
|
+
import * as Report from "@wardic/dom/Report";
|
|
8
|
+
import * as Style from "@wardic/dom/Style";
|
|
9
|
+
import * as AppearAnimations from "@wardic/dom/unstable/AppearAnimations";
|
|
10
|
+
import * as DragDefaults from "@wardic/dom/unstable/DragDefaults";
|
|
11
|
+
import * as DragTransition from "@wardic/dom/unstable/DragTransition";
|
|
12
|
+
import * as ElementSetup from "@wardic/dom/unstable/ElementSetup";
|
|
13
|
+
import * as Feature from "@wardic/dom/unstable/Feature";
|
|
14
|
+
import * as Imperative from "@wardic/dom/unstable/Imperative";
|
|
15
|
+
import * as Keys from "@wardic/dom/unstable/features/Keys";
|
|
16
|
+
import * as LiveStyle from "@wardic/dom/unstable/LiveStyle";
|
|
17
|
+
import * as Arr from "effect/Array";
|
|
18
|
+
import * as Bool from "effect/Boolean";
|
|
19
|
+
import * as Cause from "effect/Cause";
|
|
20
|
+
import * as Equal from "effect/Equal";
|
|
21
|
+
import { constFalse, constUndefined, constVoid, identity } from "effect/Function";
|
|
22
|
+
import * as MutableRef from "effect/MutableRef";
|
|
23
|
+
import * as Option from "effect/Option";
|
|
24
|
+
import * as Predicate from "effect/Predicate";
|
|
25
|
+
import * as Rec from "effect/Record";
|
|
26
|
+
import * as UndefinedOr from "effect/UndefinedOr";
|
|
27
|
+
import { deliveredTo, hintFrameUnless, installSetter, patchTouched } from "./delivery.js";
|
|
28
|
+
import { dragOf } from "./drag.js";
|
|
29
|
+
import { gesturesOf } from "./gestures.js";
|
|
30
|
+
import { reactivity, recheck } from "./reactivity.js";
|
|
31
|
+
import { mounted as scopeMounted } from "./scope.js";
|
|
32
|
+
import { layoutOf } from "./layout.js";
|
|
33
|
+
import { nearestPresence } from "./presence.js";
|
|
34
|
+
import { groupDelivered, reorderItemOf } from "./reorder.js";
|
|
35
|
+
import { hydrationMounted, reducedMotionUnder } from "./services.js";
|
|
36
|
+
import { configValueOf, dropNode, layoutGroupOf, nodeOf, startUnder } from "./tree.js";
|
|
37
|
+
import { DEV } from "@wardic/foldkit/internal/dev";
|
|
38
|
+
/** No config: an element the view gave nothing, which rests where it is. */
|
|
39
|
+
const NO_CONFIG = {};
|
|
40
|
+
/** The config delivered to an element, or none. */
|
|
41
|
+
export const configOf = (delivered) => {
|
|
42
|
+
if (Predicate.isUndefined(delivered))
|
|
43
|
+
return NO_CONFIG;
|
|
44
|
+
return delivered;
|
|
45
|
+
};
|
|
46
|
+
/** What a Retarget throwing inside the patch is reported as: contained at the binding's edge (decision 13), the element left where it is. */
|
|
47
|
+
const RETARGET_FAILED = "wardic.retarget: a w.* element's Retarget failed; it stays where it is";
|
|
48
|
+
// Module state (#460, Q7): an id counter, only ever compared for distinctness.
|
|
49
|
+
let ids = 0;
|
|
50
|
+
/**
|
|
51
|
+
* Development's diagnostics for the spine (#746, ADR-0067 *Amendment (#746)*, decision 6): given under
|
|
52
|
+
* `DEV` alone, so a production build ships none of their code.
|
|
53
|
+
*/
|
|
54
|
+
const devDiagnostics = () => {
|
|
55
|
+
if (DEV)
|
|
56
|
+
return ElementSetup.SPINE_DIAGNOSTICS;
|
|
57
|
+
return undefined;
|
|
58
|
+
};
|
|
59
|
+
/**
|
|
60
|
+
* The element's Starting style, rendered by the view: the user's `style` with its `initial` on top,
|
|
61
|
+
* projected together, so a transform key of each joins one `transform` (#791, Q7); a Live value at
|
|
62
|
+
* what it reads through `registry` now; its Transform template under the renderer's key (#443). What
|
|
63
|
+
* `w.*` and the bundle render in their one `h.Style`, stringified for Foldkit's style module. A Variant
|
|
64
|
+
* child's inherited `initial` comes with `inherited`, the context its ancestor provides, and a child a
|
|
65
|
+
* `w.Presence({ initial: false })` holds at its `Animate` with `held` (#134): the walk at the
|
|
66
|
+
* `w.Provider()` element's build gives both (#794, Q7), and its Mount writes them for an element with
|
|
67
|
+
* no Provider element above.
|
|
68
|
+
*/
|
|
69
|
+
export const startingStyleOf = (tag, config, registry, inherited, held = false) => startingStyleFrom(tag, config, registry, Spine.startOf(AnimationControls.uncontrolledOf(config), inherited, held, reactivity.untrack));
|
|
70
|
+
/** 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). */
|
|
71
|
+
export const startingStyleFrom = (tag, config, registry, start) => Style.starting(tag, ElementSetup.drawnAtRest({ ...liveValuesOf(config.style, registry), ...start.initialValues }, false, config.transformTemplate)).style;
|
|
72
|
+
/** The user's `style` with each Live value read now (#130): what a Starting style is projected from. */
|
|
73
|
+
const liveValuesOf = (style, registry) => Rec.map(styleRecordOf(style), (value) => LiveStyle.readLive(value, registry, reactivity.untrack));
|
|
74
|
+
/** The user's `style` as a record: what `w.Style` and `h.Style` gave, merged by the builder. */
|
|
75
|
+
const styleRecordOf = (style) => {
|
|
76
|
+
if (Predicate.isUndefined(style))
|
|
77
|
+
return {};
|
|
78
|
+
if (Predicate.isString(style))
|
|
79
|
+
return {};
|
|
80
|
+
return style;
|
|
81
|
+
};
|
|
82
|
+
/** `patch`'s values as Foldkit's style module takes them: strings. */
|
|
83
|
+
export const stringified = (patch) => Rec.map(patch, (value) => String(value));
|
|
84
|
+
/**
|
|
85
|
+
* Switch the element from its Starting style to the user's, in its first commit (ADR-0034): each key the
|
|
86
|
+
* Starting style set is put back to the user's projected value, or removed, so the gate reads that as
|
|
87
|
+
* the key's own value and restores it when it lets the key go. Foldkit's style module rewrites a key
|
|
88
|
+
* only when the view changes it, so the switch holds until the view does.
|
|
89
|
+
*/
|
|
90
|
+
const switchToUserStyle = (element, tag, starting, config, registry) => {
|
|
91
|
+
const user = Style.starting(tag, liveValuesOf(config.style, registry)).style;
|
|
92
|
+
Arr.forEach(starting, (key) => {
|
|
93
|
+
UndefinedOr.match(user[key], {
|
|
94
|
+
onUndefined: () => element.style.removeProperty(key),
|
|
95
|
+
onDefined: (value) => element.style.setProperty(key, String(value)),
|
|
96
|
+
});
|
|
97
|
+
});
|
|
98
|
+
};
|
|
99
|
+
/** Write `starting` on the element now: a Variant child's inherited Starting style, inside the patch, before paint (P2). */
|
|
100
|
+
const writeStartingStyle = (element, starting) => {
|
|
101
|
+
Arr.forEach(Rec.keys(starting), (key) => {
|
|
102
|
+
element.style.setProperty(key, String(starting[key]));
|
|
103
|
+
});
|
|
104
|
+
};
|
|
105
|
+
/** A {@link Dispatch} through `offer`, a Mount's queue, silenced while DevTools replay has the view (decision 34), whose history the Messages would change. */
|
|
106
|
+
export const dispatchUnlessPaused = (paused, offer) => dispatcherOf((message) => {
|
|
107
|
+
if (paused())
|
|
108
|
+
return;
|
|
109
|
+
offer(message);
|
|
110
|
+
});
|
|
111
|
+
/** What sends a callback's Message (decision 23) through `offer`: a Message as it is; a function's answer, an `Option.none()` sending nothing. */
|
|
112
|
+
export const dispatcherOf = (offer) => (handler) => (...args) => {
|
|
113
|
+
if (Bool.not(Predicate.isFunction(handler))) {
|
|
114
|
+
offer(handler);
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
const out = handler(...args);
|
|
118
|
+
if (Option.isOption(out)) {
|
|
119
|
+
Option.match(out, { onNone: constVoid, onSome: offer });
|
|
120
|
+
return;
|
|
121
|
+
}
|
|
122
|
+
offer(out);
|
|
123
|
+
};
|
|
124
|
+
/**
|
|
125
|
+
* The element `ref` names (above): the element's parent, or the selector's first match under the
|
|
126
|
+
* `w.Provider()` element, else the document. What a viewport's `root` and a `DragConstraints` container
|
|
127
|
+
* are read as: as the recognizer starts, and at each measure.
|
|
128
|
+
*/
|
|
129
|
+
const elementUnder = (provider, element, ref) => {
|
|
130
|
+
if (ref === "parent")
|
|
131
|
+
return Option.getOrUndefined(Option.fromNullOr(element.parentElement));
|
|
132
|
+
const under = UndefinedOr.match(provider.root, { onUndefined: () => document, onDefined: identity });
|
|
133
|
+
return Option.getOrUndefined(Option.fromNullOr(under.querySelector(ref)));
|
|
134
|
+
};
|
|
135
|
+
/** `DragConstraints` as dom reads them (Q7): `"parent"` or a selector as the container's accessor; a box or `false` as they are. */
|
|
136
|
+
const dragConstraintsOf = (provider, element, constraints) => {
|
|
137
|
+
if (Predicate.isString(constraints))
|
|
138
|
+
return () => elementUnder(provider, element, constraints);
|
|
139
|
+
return constraints;
|
|
140
|
+
};
|
|
141
|
+
const spineViewOf = (config, value, dispatch, registry, provider, element) => {
|
|
142
|
+
const { viewport: given, dragConstraints: constraints, ...configured } = WardicConfigValue.withConfigTransition(config, value);
|
|
143
|
+
// Its viewport as dom reads it (#793, Q16): the root resolved as the recognizer starts.
|
|
144
|
+
const viewport = UndefinedOr.match(given, {
|
|
145
|
+
onUndefined: () => ({}),
|
|
146
|
+
onDefined: (v) => ({
|
|
147
|
+
viewport: { once: v.once, margin: v.margin, amount: v.amount, ...UndefinedOr.match(v.root, { onUndefined: () => ({}), onDefined: (root) => ({ root: () => elementUnder(provider, element, root) }) }) },
|
|
148
|
+
}),
|
|
149
|
+
});
|
|
150
|
+
const dragConstraints = UndefinedOr.match(constraints, { onUndefined: () => ({}), onDefined: (c) => ({ dragConstraints: dragConstraintsOf(provider, element, c) }) });
|
|
151
|
+
const base = { ...configured, ...viewport, ...dragConstraints };
|
|
152
|
+
const start = config.animationStart;
|
|
153
|
+
const complete = config.animationComplete;
|
|
154
|
+
const update = config.onUpdate;
|
|
155
|
+
const layoutStart = config.layoutAnimationStart;
|
|
156
|
+
const layoutComplete = config.layoutAnimationComplete;
|
|
157
|
+
if (Predicate.isUndefined(start) && Predicate.isUndefined(complete) && Predicate.isUndefined(update) && Predicate.isUndefined(layoutStart) && Predicate.isUndefined(layoutComplete))
|
|
158
|
+
return base;
|
|
159
|
+
const view = {
|
|
160
|
+
...base,
|
|
161
|
+
...UndefinedOr.match(start, { onUndefined: () => ({}), onDefined: (handler) => ({ onAnimationStart: dispatch(handler) }) }),
|
|
162
|
+
...UndefinedOr.match(complete, { onUndefined: () => ({}), onDefined: (handler) => ({ onAnimationComplete: dispatch(handler) }) }),
|
|
163
|
+
...UndefinedOr.match(update, { onUndefined: () => ({}), onDefined: (atom) => ({ onUpdate: (latest) => registry.set(atom, { ...latest }) }) }),
|
|
164
|
+
// Motion's onLayoutAnimationStart / onLayoutAnimationComplete (decision 23), as Messages, told nothing.
|
|
165
|
+
...UndefinedOr.match(layoutStart, { onUndefined: () => ({}), onDefined: (handler) => ({ onLayoutAnimationStart: () => dispatch(handler)(undefined) }) }),
|
|
166
|
+
...UndefinedOr.match(layoutComplete, { onUndefined: () => ({}), onDefined: (handler) => ({ onLayoutAnimationComplete: () => dispatch(handler)(undefined) }) }),
|
|
167
|
+
};
|
|
168
|
+
return view;
|
|
169
|
+
};
|
|
170
|
+
/** The `StartsDrag` element's listener (above): nothing on an element whose deliveries never give `startsDrag`. */
|
|
171
|
+
const startsDragOf = (element, config) => {
|
|
172
|
+
const installed = MutableRef.make(false);
|
|
173
|
+
const onDown = (event) => {
|
|
174
|
+
UndefinedOr.map(config().startsDrag, (starts) => starts.controls.start(event, starts.options));
|
|
175
|
+
};
|
|
176
|
+
return {
|
|
177
|
+
check: () => {
|
|
178
|
+
if (MutableRef.get(installed))
|
|
179
|
+
return;
|
|
180
|
+
if (Predicate.isUndefined(config().startsDrag))
|
|
181
|
+
return;
|
|
182
|
+
MutableRef.set(installed, true);
|
|
183
|
+
element.addEventListener("pointerdown", onDown);
|
|
184
|
+
},
|
|
185
|
+
dispose: () => {
|
|
186
|
+
if (MutableRef.get(installed))
|
|
187
|
+
element.removeEventListener("pointerdown", onDown);
|
|
188
|
+
},
|
|
189
|
+
};
|
|
190
|
+
};
|
|
191
|
+
/** Follow `config`'s `text` Atom on the element, writing `textContent` outside the patch (decision 16); the stop. */
|
|
192
|
+
const followText = (element, atom, registry) => {
|
|
193
|
+
if (Predicate.isUndefined(atom))
|
|
194
|
+
return constVoid;
|
|
195
|
+
return registry.subscribe(atom, (value) => {
|
|
196
|
+
element.textContent = String(value);
|
|
197
|
+
}, { immediate: true });
|
|
198
|
+
};
|
|
199
|
+
/**
|
|
200
|
+
* Mount a `w.*` element on `provider`: its spine, its gate registration, its place in the tree and its
|
|
201
|
+
* Delivery's setter. `paused` says whether DevTools replay has the view (decision 34): every animation
|
|
202
|
+
* lands at once under it. `offer` sends a callback's Message through the element's Mount Stream.
|
|
203
|
+
* `root` is the Handle's app-wide config. Under a `w.Presence` (decision 29) the element is enrolled
|
|
204
|
+
* with it and starts in the presence's next delivery, after take-overs and holds are decided; else it
|
|
205
|
+
* starts once its nearest `w.*` ancestor has, or now at the top (#848: Foldkit mounts a child before
|
|
206
|
+
* its parent, and a tree mounted by one patch starts top-down this way, its Variant children's stagger
|
|
207
|
+
* slots set with every sibling registered). Returns the release: the element's teardown, run at its
|
|
208
|
+
* Mount's destroy, before Foldkit removes it.
|
|
209
|
+
*/
|
|
210
|
+
export const mountElement = (provider, state, element, paused, offer, root) => {
|
|
211
|
+
const tag = element.localName;
|
|
212
|
+
// Its callbacks' Messages (decision 23): none under replay (decision 34), whose history they'd change.
|
|
213
|
+
const dispatch = dispatchUnlessPaused(paused, offer);
|
|
214
|
+
// Its place in the tree (decision 21): its node, made by its first child's Mount or here, and the
|
|
215
|
+
// nearest `w.Config` above it (decision 22).
|
|
216
|
+
const node = nodeOf(element);
|
|
217
|
+
const inherited = node.inherited;
|
|
218
|
+
const configValue = configValueOf(element, root);
|
|
219
|
+
const registry = provider.atoms;
|
|
220
|
+
const registryNow = () => registry;
|
|
221
|
+
const id = `wardic-foldkit-${ids++}`;
|
|
222
|
+
let config = configOf(deliveredTo(element));
|
|
223
|
+
// Its Animation controls (#433; #798, Q4): the ones it mounted with, kept; each change they make is its
|
|
224
|
+
// `animate` entry as the spine reads it, the node's configured form, its Variant children following.
|
|
225
|
+
const controls = AnimationControls.controlsOf(config.animate);
|
|
226
|
+
const viewOf = () => spineViewOf(node.configured(config), configValue, dispatch, registry, provider, element);
|
|
227
|
+
let view = viewOf();
|
|
228
|
+
const configNow = () => view;
|
|
229
|
+
// The nearest `w.Presence` above it (decision 29), told its key now, before that presence decides what it shows (#286).
|
|
230
|
+
const presence = nearestPresence(provider, state, element);
|
|
231
|
+
const context = UndefinedOr.map(presence, (p) => p.context);
|
|
232
|
+
UndefinedOr.map(context, (ctx) => UndefinedOr.map(ctx.made, (made) => made(element, config.key, Predicate.isNotUndefined(config.layoutId))));
|
|
233
|
+
const begin = () => {
|
|
234
|
+
// Its Live values in `style` (#130, ADR-0043): routed keys the spine follows through the gate.
|
|
235
|
+
const live = LiveStyle.createLiveStyle({ registry: registryNow, onDroppedTransform: droppedTransformWarning(provider, id), reactivity, ownValues: provider.valueReads.ownValues });
|
|
236
|
+
live.css(config.style);
|
|
237
|
+
// Where it starts (ADR-0003), read once: the config the view rendered it with, its inherited `initial`
|
|
238
|
+
// included (#50), at its `animate` under a presence's `initial: false` (#134).
|
|
239
|
+
const start = Spine.startOf(view, inherited, PresenceRecord.presenceBlocksInitial(context), reactivity.untrack);
|
|
240
|
+
const snapshot = Spine.snapshotOf(start);
|
|
241
|
+
// Its Transform template (#443), drawn with its first write: the one at mount, then each other one.
|
|
242
|
+
const templateAtMount = config.transformTemplate;
|
|
243
|
+
// The keys its Starting style set, switched to the user's in its first commit. A Variant child's
|
|
244
|
+
// inherited Starting style wasn't rendered by the view: written now, inside the patch (P2). So is a
|
|
245
|
+
// child of a `w.Presence({ initial: false })`: the view rendered it at its `Animate` (the walk at a
|
|
246
|
+
// Provider element's build, #794), where only the presence's first render starts it there (#134).
|
|
247
|
+
const starting = Style.starting(tag, ElementSetup.drawnAtRest(start.initialValues, false, templateAtMount)).style;
|
|
248
|
+
if (Bool.or(Predicate.isNotUndefined(inherited), UndefinedOr.match(presence, { onUndefined: constFalse, onDefined: (p) => p.holds() })))
|
|
249
|
+
writeStartingStyle(element, starting);
|
|
250
|
+
const startingKeys = Rec.keys(starting);
|
|
251
|
+
// Its Appear animation, when it hydrates one the server rendered (ADR-0044 decision 6; #794, Q10):
|
|
252
|
+
// found by the slot its inline `animation` names, which the hydration render kept, taken over by its
|
|
253
|
+
// first Retarget that starts, as far in as the CSS has got, and removed in its first commit, the
|
|
254
|
+
// Handoff. Asked at every mount, a string read: an element a client render made names no slot. One
|
|
255
|
+
// found keeps hydration's window open until that commit, so no render in between strips the slot.
|
|
256
|
+
const handoff = Option.getOrUndefined(AppearAnimations.handoffOf(element));
|
|
257
|
+
const released = hydrationMounted(state, Predicate.isNotUndefined(handoff));
|
|
258
|
+
const sink = ElementSetup.releasingAppear(Spine.withOnUpdate({
|
|
259
|
+
target: element,
|
|
260
|
+
beforeFirstCommit: () => {
|
|
261
|
+
switchToUserStyle(element, tag, startingKeys, config, registryNow);
|
|
262
|
+
released();
|
|
263
|
+
},
|
|
264
|
+
}, view.onUpdate, configNow), handoff, element);
|
|
265
|
+
const unregister = provider.gate.register(id, sink, ElementSetup.registeredValuesOf(templateAtMount));
|
|
266
|
+
// The user's style now, for its Base values (ADR-0022): the config's, as the view last delivered it.
|
|
267
|
+
const styleNow = () => config.style;
|
|
268
|
+
const links = ElementSetup.startLinksOf(element, styleNow, live);
|
|
269
|
+
// Reduced motion (ADR-0029) and skipped animations (#468) under its nearest `w.Config`, read at each Retarget.
|
|
270
|
+
const reducedMotion = reducedMotionUnder(provider, configValue);
|
|
271
|
+
const skipped = WardicConfigValue.skipAnimationsOf(configValue);
|
|
272
|
+
const skipAnimations = () => paused() || skipped();
|
|
273
|
+
// Where its drag's and its pan's points are (#793, Q9): its nearest `w.Config`'s `transformPagePoint`, read at each down.
|
|
274
|
+
const pagePoint = () => UndefinedOr.match(configValue, { onUndefined: constUndefined, onDefined: (v) => v.transformPagePoint() });
|
|
275
|
+
// Its presence record (ADR-0007): what its presence drives its exit with after Foldkit removes it,
|
|
276
|
+
// resolved from its `Exit` as it leaves; the presence owns the registration. And where it starts when
|
|
277
|
+
// it takes over from a leaver under its key (#286).
|
|
278
|
+
const exitConfig = { current: Spine.exitConfigOf(view, inherited) };
|
|
279
|
+
const record = UndefinedOr.map(context, (ctx) => {
|
|
280
|
+
const rec = Spine.presenceRecordOf(element, start, (custom, inheritedNames) => Spine.exitTargetOf(exitConfig.current, custom, snapshot, inheritedNames), links, Spine.presenceTreeOf(view), snapshot, reducedMotion, skipAnimations);
|
|
281
|
+
ctx.register(rec);
|
|
282
|
+
return rec;
|
|
283
|
+
});
|
|
284
|
+
const taken = PresenceRecord.presenceSeedOf(context, element);
|
|
285
|
+
const recordFrame = Spine.recordFrameOf(record);
|
|
286
|
+
// Its gestures (#793; decision 23): each started as a delivery wants it, its entry in the Override
|
|
287
|
+
// stack re-resolved as it flips, and its Variant children told through the port's watches (#291).
|
|
288
|
+
const gestures = gesturesOf({
|
|
289
|
+
provider,
|
|
290
|
+
element,
|
|
291
|
+
config: configNow,
|
|
292
|
+
dispatch,
|
|
293
|
+
onChange: () => {
|
|
294
|
+
retarget();
|
|
295
|
+
recheck();
|
|
296
|
+
},
|
|
297
|
+
id,
|
|
298
|
+
pagePoint,
|
|
299
|
+
// A Reorder item's keys are its Keyboard reorder's (ADR-0037): its press starts from no key.
|
|
300
|
+
keysTaken: () => Predicate.isNotUndefined(MutableRef.get(item)),
|
|
301
|
+
});
|
|
302
|
+
node.bindGestures(gestures.states);
|
|
303
|
+
// A Reorder item (decision 28): joined to the group above it, which decides its drag's axis and hears
|
|
304
|
+
// its samples; its keyboard lift turns `WhileDrag` on. Joined now, or as a load brings the Features (Q15).
|
|
305
|
+
const item = MutableRef.make(reorderItemOf(provider, element, id, () => config, dispatch, gestures.lift));
|
|
306
|
+
// Its spine's options, with what its drag writes as its track starts (ADR-0004; #793, PR 2): its
|
|
307
|
+
// axis, its track and whether it drives a layout node, which the spine reads where it uses them.
|
|
308
|
+
// The axis is seeded from the config at mount too, as Solid's: the spine registers its drag hook (a
|
|
309
|
+
// Batch member's hold, #665) at make from it, so a `Drag` a later render adds registers none.
|
|
310
|
+
const spineOptions = {
|
|
311
|
+
runtime: provider.runtime,
|
|
312
|
+
gate: provider.gate,
|
|
313
|
+
id,
|
|
314
|
+
element,
|
|
315
|
+
tag,
|
|
316
|
+
config: configNow,
|
|
317
|
+
parent: inherited,
|
|
318
|
+
canStart: node.canStart,
|
|
319
|
+
extraDelay: node.extraDelay,
|
|
320
|
+
onFrame: node.onFrame,
|
|
321
|
+
byName: node.names,
|
|
322
|
+
reducedMotion,
|
|
323
|
+
skipAnimations,
|
|
324
|
+
positionalKeys: provider.positionalKeys,
|
|
325
|
+
defaultTransition: provider.defaultTransition,
|
|
326
|
+
ownValues: provider.valueReads.ownValues,
|
|
327
|
+
measuredPairs: provider.valueReads.measuredPairs,
|
|
328
|
+
variableValues: provider.valueReads.variableValues,
|
|
329
|
+
start,
|
|
330
|
+
snapshot,
|
|
331
|
+
reuse: Spine.makeReuse(),
|
|
332
|
+
links,
|
|
333
|
+
styleNow,
|
|
334
|
+
live,
|
|
335
|
+
builtFeatures: provider.registry.built,
|
|
336
|
+
presence: record,
|
|
337
|
+
projected: false,
|
|
338
|
+
dragAxis: DragDefaults.dragAxisOf(view, { dragAxis: UndefinedOr.map(MutableRef.get(item), (joined) => joined.dragAxis) }),
|
|
339
|
+
drag: undefined,
|
|
340
|
+
handoff,
|
|
341
|
+
// Motion's onAnimationStart / onAnimationComplete (decision 23), as Messages through `dispatch`.
|
|
342
|
+
animation: Spine.animationCallbacks(provider.runtime, id),
|
|
343
|
+
diagnostics: devDiagnostics(),
|
|
344
|
+
};
|
|
345
|
+
const spine = Spine.makeElementSpine(spineOptions);
|
|
346
|
+
UndefinedOr.map(taken, (seed) => spine.seed(seed));
|
|
347
|
+
// The `StartsDrag` element (Q8): its downs start its controls' drags, from the first delivery that gives them.
|
|
348
|
+
const startsDrag = startsDragOf(element, () => config);
|
|
349
|
+
// Its Animation scope (#798, Q7 and Q9): the scope's element from now, and the animations started in it stopped at its release.
|
|
350
|
+
const releaseScope = UndefinedOr.match(config.animationScope, { onUndefined: () => constVoid, onDefined: (scope) => scopeMounted(scope, element) });
|
|
351
|
+
// Its layout (ADR-0009, ADR-0010; decision 30): one projection node for `Layout`, `LayoutId`,
|
|
352
|
+
// `LayoutScroll` or `LayoutRoot`, on the provider's layout, built at the first; and, with a layout
|
|
353
|
+
// built, its values by element, for a twin's flight to follow (ADR-0012 *Amendment (#137)*). Each
|
|
354
|
+
// joined at mount, or as a load brings the Feature (#793, Q15).
|
|
355
|
+
// Its config as dom's layout code reads it: the layout keys alone.
|
|
356
|
+
const wardConfig = () => view;
|
|
357
|
+
const builtProjection = () => Keys.projectionIn(provider.registry.built());
|
|
358
|
+
const layoutNode = MutableRef.make(undefined);
|
|
359
|
+
const unregisterValues = MutableRef.make(undefined);
|
|
360
|
+
const joinLayout = () => {
|
|
361
|
+
if (Bool.and(Predicate.isUndefined(MutableRef.get(layoutNode)), Feature.wantsLayoutNode(wardConfig()))) {
|
|
362
|
+
MutableRef.set(layoutNode, UndefinedOr.map(layoutOf(provider, state), (made) => made.projection.register(made.nodes.registrationOf(made.nodes.optionsOf({
|
|
363
|
+
id,
|
|
364
|
+
element,
|
|
365
|
+
config: wardConfig,
|
|
366
|
+
parent: inherited,
|
|
367
|
+
snapshot,
|
|
368
|
+
// What its release runs on (ADR-0016, *Amendment (#140)*; Q10): the element's drag transition, read now.
|
|
369
|
+
dragTransition: DragTransition.dragTransitionOf(view.dragElastic, view.dragTransition),
|
|
370
|
+
// Raised while dragged as a Reorder item (ADR-0020), over the rest.
|
|
371
|
+
raiseWhileDragged: Predicate.isNotUndefined(MutableRef.get(item)),
|
|
372
|
+
taken,
|
|
373
|
+
layoutGroup: layoutGroupOf(element),
|
|
374
|
+
reducedMotion,
|
|
375
|
+
skipAnimations,
|
|
376
|
+
heldTransform: ElementSetup.heldTransformFor(snapshot, templateAtMount, () => view.transformTemplate),
|
|
377
|
+
})))));
|
|
378
|
+
registerItemNode();
|
|
379
|
+
}
|
|
380
|
+
if (Predicate.isUndefined(MutableRef.get(unregisterValues)))
|
|
381
|
+
MutableRef.set(unregisterValues, UndefinedOr.map(builtProjection(), (projection) => projection.registerValues(element, () => snapshot.values)));
|
|
382
|
+
};
|
|
383
|
+
/** A Reorder item's node, registered with its group once both are there (ADR-0020): its box, its drag offset and its lift. */
|
|
384
|
+
const registerItemNode = () => {
|
|
385
|
+
UndefinedOr.map(MutableRef.get(layoutNode), (made) => UndefinedOr.map(MutableRef.get(item), (joined) => joined.onLayoutHandle(made)));
|
|
386
|
+
};
|
|
387
|
+
/** The item joined as a load brings the Features (Q15): its group made by it if its own Mount hasn't, its node registered. */
|
|
388
|
+
const joinItem = () => {
|
|
389
|
+
if (Predicate.isNotUndefined(MutableRef.get(item)))
|
|
390
|
+
return;
|
|
391
|
+
MutableRef.set(item, reorderItemOf(provider, element, id, () => config, dispatch, gestures.lift));
|
|
392
|
+
registerItemNode();
|
|
393
|
+
};
|
|
394
|
+
joinLayout();
|
|
395
|
+
// Its drag (ADR-0004; #793, PR 2): dom's track, started as a delivery wants it, driving the layout
|
|
396
|
+
// node it has then; its samples and its hold on `x`/`y` to the gestures, its release's end too.
|
|
397
|
+
const drag = dragOf({
|
|
398
|
+
provider,
|
|
399
|
+
element,
|
|
400
|
+
id,
|
|
401
|
+
config: configNow,
|
|
402
|
+
snapshot,
|
|
403
|
+
recordFrame,
|
|
404
|
+
live,
|
|
405
|
+
spine: spineOptions,
|
|
406
|
+
layoutNode: () => MutableRef.get(layoutNode),
|
|
407
|
+
// A Reorder item's axis at each gesture's start, and its samples to its group before the callbacks (ADR-0020).
|
|
408
|
+
itemAxis: () => UndefinedOr.map(MutableRef.get(item), (joined) => joined.dragAxis),
|
|
409
|
+
pagePoint,
|
|
410
|
+
skipAnimations,
|
|
411
|
+
onDragging: gestures.dragHeld,
|
|
412
|
+
onSample: (sample) => {
|
|
413
|
+
UndefinedOr.map(MutableRef.get(item), (joined) => joined.onDragSample(sample));
|
|
414
|
+
gestures.dragged(sample);
|
|
415
|
+
},
|
|
416
|
+
onReleaseEnd: gestures.released,
|
|
417
|
+
});
|
|
418
|
+
// A load's Features arriving (Q15): what the element wants of them starts then; an item joins its
|
|
419
|
+
// group first, and a `layout` from the same load makes its node before the drag's track drives it (#582).
|
|
420
|
+
const stopRechecks = provider.onFeatures(() => {
|
|
421
|
+
joinItem();
|
|
422
|
+
joinLayout();
|
|
423
|
+
drag.check();
|
|
424
|
+
gestures.check();
|
|
425
|
+
});
|
|
426
|
+
// Its `LayoutDependency`, compared per delivery as Motion's `prevProps.layoutDependency !==` is: a
|
|
427
|
+
// change asks for the node's measure, or, on an element with no node (a group's), the whole tree's.
|
|
428
|
+
let dependency = config.layoutDependency;
|
|
429
|
+
const dependencyChanged = () => {
|
|
430
|
+
const next = config.layoutDependency;
|
|
431
|
+
if (Equal.equals(dependency, next))
|
|
432
|
+
return;
|
|
433
|
+
dependency = next;
|
|
434
|
+
const ask = () => {
|
|
435
|
+
UndefinedOr.match(MutableRef.get(layoutNode), {
|
|
436
|
+
onDefined: (node) => node.notify(),
|
|
437
|
+
onUndefined: () => UndefinedOr.map(builtProjection(), (projection) => projection.notify()),
|
|
438
|
+
});
|
|
439
|
+
};
|
|
440
|
+
// A View Transition's render (decision 33): the pass it asks for is an Instant change of the layout.
|
|
441
|
+
if (state.transitioning) {
|
|
442
|
+
state.transitioning = false;
|
|
443
|
+
UndefinedOr.match(builtProjection(), { onUndefined: ask, onDefined: (projection) => projection.instant(ask) });
|
|
444
|
+
return;
|
|
445
|
+
}
|
|
446
|
+
ask();
|
|
447
|
+
};
|
|
448
|
+
// The Override stack resolved (ADR-0007), compared by value (#470): a delivery that resolves the same
|
|
449
|
+
// targets tells nothing, as a `transition` change alone doesn't in Motion; a gesture's flip
|
|
450
|
+
// re-resolves it with the entries on now.
|
|
451
|
+
let last;
|
|
452
|
+
const retarget = () => {
|
|
453
|
+
const next = Spine.resolutionOf(view, inherited, start.initialLink, gestures.active(), snapshot, node.change());
|
|
454
|
+
if (Predicate.isNotUndefined(last) && Spine.sameResolution(last, next))
|
|
455
|
+
return;
|
|
456
|
+
last = next;
|
|
457
|
+
spine.retarget(next);
|
|
458
|
+
};
|
|
459
|
+
// Its Delivery (decision 20): each render's fresh config, inside the patch, Retargets at once (#791, Q14),
|
|
460
|
+
// after the binding's hint (decision 32), so the Retarget's legs take their first step in this frame.
|
|
461
|
+
// A defect there is Foldkit's patch's otherwise, which would stop the whole app (decision 13): reported,
|
|
462
|
+
// and the element stays where it is.
|
|
463
|
+
const uninstall = installSetter(element, (delivered) => {
|
|
464
|
+
config = configOf(delivered);
|
|
465
|
+
if (DEV)
|
|
466
|
+
warnChangedControls(provider, id, controls, config);
|
|
467
|
+
view = viewOf();
|
|
468
|
+
// A Reorder group's values that changed (decision 28): its controller told, before the pass that lays the items out in them.
|
|
469
|
+
groupDelivered(element);
|
|
470
|
+
exitConfig.current = Spine.exitConfigOf(view, inherited);
|
|
471
|
+
patchTouched();
|
|
472
|
+
hintFrameUnless(provider.loop, paused);
|
|
473
|
+
try {
|
|
474
|
+
live.css(config.style);
|
|
475
|
+
dependencyChanged();
|
|
476
|
+
// A gesture this render wants starts now (ADR-0047 decision 5): a callback added later starts its recognizer, a `Drag` its track.
|
|
477
|
+
drag.check();
|
|
478
|
+
gestures.check();
|
|
479
|
+
startsDrag.check();
|
|
480
|
+
retarget();
|
|
481
|
+
}
|
|
482
|
+
catch (error) {
|
|
483
|
+
provider.runtime.runFork(Report.failure(RETARGET_FAILED, Cause.die(error)));
|
|
484
|
+
}
|
|
485
|
+
});
|
|
486
|
+
// Its Live values followed from its first routed key on (#130), its text (decision 16), and its
|
|
487
|
+
// Transform template after the one at mount (#443), which its presence record draws its exit through.
|
|
488
|
+
spine.follow({ resolved: () => UndefinedOr.match(last, { onUndefined: () => Spine.NO_VALUES, onDefined: (resolution) => resolution.resolved }), dragging: gestures.dragging });
|
|
489
|
+
const unfollowText = followText(element, config.text, registry);
|
|
490
|
+
const unfollowTemplate = UndefinedOr.match(templateAtMount, {
|
|
491
|
+
onUndefined: () => constVoid,
|
|
492
|
+
onDefined: (template) => {
|
|
493
|
+
recordFrame(ElementSetup.registeredValuesOf(template));
|
|
494
|
+
return ElementSetup.followTemplate(template, () => view.transformTemplate, reactivity.watch, (next) => {
|
|
495
|
+
provider.gate.write(id, { ...snapshot.values, [DomRenderer.TEMPLATE_KEY]: next });
|
|
496
|
+
recordFrame({ [DomRenderer.TEMPLATE_KEY]: next });
|
|
497
|
+
});
|
|
498
|
+
},
|
|
499
|
+
});
|
|
500
|
+
// Its Imperative animations (#433) go through its spine while it's mounted.
|
|
501
|
+
const unregisterAnimatable = Imperative.registerAnimatable(element, spine);
|
|
502
|
+
// What a Variant child hears without a delivery of its own (P17): the name its ancestor hands down and
|
|
503
|
+
// the gestures it hands on (#291), as one trigger key, and its `when` gate opening, re-checked once a
|
|
504
|
+
// patch, at each settle that changes a gate (decision 17) and at each gesture flip above it.
|
|
505
|
+
let unwatch = constVoid;
|
|
506
|
+
if (Predicate.isNotUndefined(node.names)) {
|
|
507
|
+
const unwatchName = UndefinedOr.match(inherited, {
|
|
508
|
+
onUndefined: () => constVoid,
|
|
509
|
+
// Its ancestor's Controls change is a trigger too (#433), even to the same name.
|
|
510
|
+
onDefined: (parentContext) => {
|
|
511
|
+
const inheritedChange = VariantTree.controlsChangeOf(undefined, parentContext);
|
|
512
|
+
return reactivity.watch(() => VariantTree.triggerKeyOf(parentContext.variant(), VariantTree.handDownFrom(parentContext), inheritedChange()), retarget);
|
|
513
|
+
},
|
|
514
|
+
});
|
|
515
|
+
const unwatchGate = reactivity.watch(node.canStart, (open) => {
|
|
516
|
+
if (Bool.and(open, Predicate.isNotUndefined(last)))
|
|
517
|
+
spine.retarget(UndefinedOr.getOrThrow(last));
|
|
518
|
+
});
|
|
519
|
+
unwatch = () => {
|
|
520
|
+
unwatchName();
|
|
521
|
+
unwatchGate();
|
|
522
|
+
};
|
|
523
|
+
}
|
|
524
|
+
// Its Animation controls reach it from its mount to its release (#798, Q4): each change sets its
|
|
525
|
+
// entry, re-resolves it on the change's override and tells the watches, its Variant children's
|
|
526
|
+
// triggers among them; their stop ends its legs where they are.
|
|
527
|
+
const unsubscribe = UndefinedOr.match(controls, {
|
|
528
|
+
onUndefined: () => constVoid,
|
|
529
|
+
onDefined: (c) => AnimationControls.subscribe(c, AnimationControls.controlledElement((change) => {
|
|
530
|
+
node.setChange(change);
|
|
531
|
+
view = viewOf();
|
|
532
|
+
retarget();
|
|
533
|
+
recheck();
|
|
534
|
+
}, { custom: () => config.custom, snapshot }, spine.stop)),
|
|
535
|
+
});
|
|
536
|
+
// Its drag and its gestures wanted at mount, then its first Retarget: from `initial` to `animate`.
|
|
537
|
+
drag.check();
|
|
538
|
+
gestures.check();
|
|
539
|
+
startsDrag.check();
|
|
540
|
+
retarget();
|
|
541
|
+
return () => {
|
|
542
|
+
unsubscribe();
|
|
543
|
+
released();
|
|
544
|
+
unwatch();
|
|
545
|
+
unfollowText();
|
|
546
|
+
unfollowTemplate();
|
|
547
|
+
unregisterAnimatable();
|
|
548
|
+
uninstall();
|
|
549
|
+
stopRechecks();
|
|
550
|
+
releaseScope();
|
|
551
|
+
startsDrag.dispose();
|
|
552
|
+
UndefinedOr.map(MutableRef.get(item), (joined) => joined.dispose());
|
|
553
|
+
drag.dispose();
|
|
554
|
+
gestures.dispose();
|
|
555
|
+
UndefinedOr.map(MutableRef.get(layoutNode), (node) => node.dispose());
|
|
556
|
+
UndefinedOr.map(MutableRef.get(unregisterValues), (unregister) => unregister());
|
|
557
|
+
spine.dispose();
|
|
558
|
+
unregister();
|
|
559
|
+
dropNode(element);
|
|
560
|
+
};
|
|
561
|
+
};
|
|
562
|
+
return UndefinedOr.match(presence, { onUndefined: () => startUnder(element, begin), onDefined: (p) => p.enroll(element, begin) });
|
|
563
|
+
};
|
|
564
|
+
/** Development's word on a render giving an element other controls, or values in their place (#798, Q17): it keeps the ones it mounted with. */
|
|
565
|
+
const CONTROLS_CHANGED = "wardic.controls: a w.* element's Animation controls are read at its mount, and a later render gave it other controls, or values in their place: it keeps the ones it mounted with. Key the element, so the new ones mount with it.";
|
|
566
|
+
/** Development's word on the reverse (the review's note): controls given to an element that mounted with none don't reach it. */
|
|
567
|
+
const CONTROLS_LATE = "wardic.controls: a w.* element mounted without Animation controls, and a later render gave it some: they don't reach it. Key the element, so they mount with it.";
|
|
568
|
+
/** Say the word, once an element, when a delivery's `animate` isn't what it mounted with: other controls, values in their place, or controls where there were none. */
|
|
569
|
+
const warnChangedControls = (provider, id, controls, config) => {
|
|
570
|
+
const word = UndefinedOr.match(controls, {
|
|
571
|
+
onUndefined: () => Bool.match(AnimationControls.isAnimationControls(config.animate), { onTrue: () => CONTROLS_LATE, onFalse: constUndefined }),
|
|
572
|
+
onDefined: (mounted) => Bool.match(config.animate === mounted, { onTrue: constUndefined, onFalse: () => CONTROLS_CHANGED }),
|
|
573
|
+
});
|
|
574
|
+
UndefinedOr.map(word, (message) => provider.registry.warnOnce(`controls:${id}`, message));
|
|
575
|
+
};
|
|
576
|
+
/** In development alone (#746), what warns once that a `transform` string gave way to `style`'s transform keys. */
|
|
577
|
+
const droppedTransformWarning = (provider, id) => {
|
|
578
|
+
if (DEV)
|
|
579
|
+
return () => ElementSetup.warnDroppedTransform(provider.runtime, id);
|
|
580
|
+
return undefined;
|
|
581
|
+
};
|
|
582
|
+
//# sourceMappingURL=element.js.map
|