@wardic/foldkit 0.0.0-stage → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (154) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +59 -2
  3. package/THIRD_PARTY_NOTICES.md +145 -0
  4. package/dist/AnimationControls.d.ts +37 -0
  5. package/dist/AnimationControls.d.ts.map +1 -0
  6. package/dist/AnimationControls.js +37 -0
  7. package/dist/AnimationControls.js.map +1 -0
  8. package/dist/AnimationScope.d.ts +20 -0
  9. package/dist/AnimationScope.d.ts.map +1 -0
  10. package/dist/AnimationScope.js +20 -0
  11. package/dist/AnimationScope.js.map +1 -0
  12. package/dist/DragControls.d.ts +25 -0
  13. package/dist/DragControls.d.ts.map +1 -0
  14. package/dist/DragControls.js +21 -0
  15. package/dist/DragControls.js.map +1 -0
  16. package/dist/Features.d.ts +36 -0
  17. package/dist/Features.d.ts.map +1 -0
  18. package/dist/Features.js +44 -0
  19. package/dist/Features.js.map +1 -0
  20. package/dist/Ward.d.ts +301 -0
  21. package/dist/Ward.d.ts.map +1 -0
  22. package/dist/Ward.js +6 -0
  23. package/dist/Ward.js.map +1 -0
  24. package/dist/Wardic.d.ts +363 -0
  25. package/dist/Wardic.d.ts.map +1 -0
  26. package/dist/Wardic.js +85 -0
  27. package/dist/Wardic.js.map +1 -0
  28. package/dist/index.d.ts +15 -0
  29. package/dist/index.d.ts.map +1 -0
  30. package/dist/index.js +20 -0
  31. package/dist/index.js.map +1 -0
  32. package/dist/internal/builder.d.ts +8 -0
  33. package/dist/internal/builder.d.ts.map +1 -0
  34. package/dist/internal/builder.js +242 -0
  35. package/dist/internal/builder.js.map +1 -0
  36. package/dist/internal/commands.d.ts +143 -0
  37. package/dist/internal/commands.d.ts.map +1 -0
  38. package/dist/internal/commands.js +242 -0
  39. package/dist/internal/commands.js.map +1 -0
  40. package/dist/internal/delivery.d.ts +44 -0
  41. package/dist/internal/delivery.d.ts.map +1 -0
  42. package/dist/internal/delivery.js +85 -0
  43. package/dist/internal/delivery.js.map +1 -0
  44. package/dist/internal/dev.d.ts +10 -0
  45. package/dist/internal/dev.d.ts.map +1 -0
  46. package/dist/internal/dev.js +10 -0
  47. package/dist/internal/dev.js.map +1 -0
  48. package/dist/internal/dev.production.d.ts +8 -0
  49. package/dist/internal/dev.production.d.ts.map +1 -0
  50. package/dist/internal/dev.production.js +8 -0
  51. package/dist/internal/dev.production.js.map +1 -0
  52. package/dist/internal/drag.d.ts +66 -0
  53. package/dist/internal/drag.d.ts.map +1 -0
  54. package/dist/internal/drag.js +71 -0
  55. package/dist/internal/drag.js.map +1 -0
  56. package/dist/internal/element.d.ts +59 -0
  57. package/dist/internal/element.d.ts.map +1 -0
  58. package/dist/internal/element.js +582 -0
  59. package/dist/internal/element.js.map +1 -0
  60. package/dist/internal/gestures.d.ts +62 -0
  61. package/dist/internal/gestures.d.ts.map +1 -0
  62. package/dist/internal/gestures.js +109 -0
  63. package/dist/internal/gestures.js.map +1 -0
  64. package/dist/internal/hydrate.d.ts +5 -0
  65. package/dist/internal/hydrate.d.ts.map +1 -0
  66. package/dist/internal/hydrate.js +27 -0
  67. package/dist/internal/hydrate.js.map +1 -0
  68. package/dist/internal/keys.d.ts +21 -0
  69. package/dist/internal/keys.d.ts.map +1 -0
  70. package/dist/internal/keys.js +12 -0
  71. package/dist/internal/keys.js.map +1 -0
  72. package/dist/internal/layout.d.ts +29 -0
  73. package/dist/internal/layout.d.ts.map +1 -0
  74. package/dist/internal/layout.js +88 -0
  75. package/dist/internal/layout.js.map +1 -0
  76. package/dist/internal/mount.d.ts +22 -0
  77. package/dist/internal/mount.d.ts.map +1 -0
  78. package/dist/internal/mount.js +100 -0
  79. package/dist/internal/mount.js.map +1 -0
  80. package/dist/internal/presence.d.ts +33 -0
  81. package/dist/internal/presence.d.ts.map +1 -0
  82. package/dist/internal/presence.js +338 -0
  83. package/dist/internal/presence.js.map +1 -0
  84. package/dist/internal/reactivity.d.ts +15 -0
  85. package/dist/internal/reactivity.d.ts.map +1 -0
  86. package/dist/internal/reactivity.js +26 -0
  87. package/dist/internal/reactivity.js.map +1 -0
  88. package/dist/internal/reorder.d.ts +47 -0
  89. package/dist/internal/reorder.d.ts.map +1 -0
  90. package/dist/internal/reorder.js +250 -0
  91. package/dist/internal/reorder.js.map +1 -0
  92. package/dist/internal/scope.d.ts +28 -0
  93. package/dist/internal/scope.d.ts.map +1 -0
  94. package/dist/internal/scope.js +44 -0
  95. package/dist/internal/scope.js.map +1 -0
  96. package/dist/internal/server.d.ts +13 -0
  97. package/dist/internal/server.d.ts.map +1 -0
  98. package/dist/internal/server.js +13 -0
  99. package/dist/internal/server.js.map +1 -0
  100. package/dist/internal/server.node.d.ts +8 -0
  101. package/dist/internal/server.node.d.ts.map +1 -0
  102. package/dist/internal/server.node.js +8 -0
  103. package/dist/internal/server.node.js.map +1 -0
  104. package/dist/internal/services.d.ts +222 -0
  105. package/dist/internal/services.d.ts.map +1 -0
  106. package/dist/internal/services.js +338 -0
  107. package/dist/internal/services.js.map +1 -0
  108. package/dist/internal/tree.d.ts +71 -0
  109. package/dist/internal/tree.d.ts.map +1 -0
  110. package/dist/internal/tree.js +207 -0
  111. package/dist/internal/tree.js.map +1 -0
  112. package/dist/internal/variant-node.d.ts +62 -0
  113. package/dist/internal/variant-node.d.ts.map +1 -0
  114. package/dist/internal/variant-node.js +279 -0
  115. package/dist/internal/variant-node.js.map +1 -0
  116. package/dist/internal/view-transition.d.ts +10 -0
  117. package/dist/internal/view-transition.d.ts.map +1 -0
  118. package/dist/internal/view-transition.js +36 -0
  119. package/dist/internal/view-transition.js.map +1 -0
  120. package/dist/internal/walk.d.ts +26 -0
  121. package/dist/internal/walk.d.ts.map +1 -0
  122. package/dist/internal/walk.js +162 -0
  123. package/dist/internal/walk.js.map +1 -0
  124. package/package.json +99 -4
  125. package/src/AnimationControls.ts +46 -0
  126. package/src/AnimationScope.ts +19 -0
  127. package/src/DragControls.ts +27 -0
  128. package/src/Features.ts +45 -0
  129. package/src/Ward.ts +434 -0
  130. package/src/Wardic.ts +410 -0
  131. package/src/index.ts +20 -0
  132. package/src/internal/builder.ts +262 -0
  133. package/src/internal/commands.ts +359 -0
  134. package/src/internal/delivery.ts +116 -0
  135. package/src/internal/dev.production.ts +7 -0
  136. package/src/internal/dev.ts +9 -0
  137. package/src/internal/drag.ts +136 -0
  138. package/src/internal/element.ts +668 -0
  139. package/src/internal/gestures.ts +184 -0
  140. package/src/internal/hydrate.ts +29 -0
  141. package/src/internal/keys.ts +19 -0
  142. package/src/internal/layout.ts +109 -0
  143. package/src/internal/mount.ts +124 -0
  144. package/src/internal/presence.ts +362 -0
  145. package/src/internal/reactivity.ts +45 -0
  146. package/src/internal/reorder.ts +313 -0
  147. package/src/internal/scope.ts +60 -0
  148. package/src/internal/server.node.ts +7 -0
  149. package/src/internal/server.ts +12 -0
  150. package/src/internal/services.ts +486 -0
  151. package/src/internal/tree.ts +230 -0
  152. package/src/internal/variant-node.ts +352 -0
  153. package/src/internal/view-transition.ts +43 -0
  154. package/src/internal/walk.ts +211 -0
@@ -0,0 +1,33 @@
1
+ import type * as PresenceController from "@wardic/dom/unstable/PresenceController";
2
+ import type * as Ward from "../Ward.ts";
3
+ import { type Provider, type State } from "./services.ts";
4
+ /** A `w.Presence` element's presence: what its children register with, and what its own Mount runs. */
5
+ export interface Presence {
6
+ /** The controller's context: what a child's spine registers its record with. */
7
+ readonly context: PresenceController.PresenceContextValue;
8
+ /** A child's start, enrolled for the next delivery; returns the child's release. */
9
+ readonly enroll: (element: Element, begin: () => () => void) => () => void;
10
+ /** The presence element's own Mount runs it: the observer, the first delivery, the Messages; returns the release. */
11
+ readonly mount: (paused: () => boolean, offer: (message: unknown) => void) => () => void;
12
+ /** Whether it is a `w.Presence({ initial: false })` ({@link holdsInitial}), as its options stand now. */
13
+ readonly holds: () => boolean;
14
+ }
15
+ /**
16
+ * Whether a `w.Presence` with `options` holds the children of its first render at their `Animate`
17
+ * (`initial: false`, #134): what the walk at a provider element's build writes for them (#794), and what
18
+ * their Mounts start them at while that render is the presence's first (dom's `blocksInitial`).
19
+ */
20
+ export declare const holdsInitial: (options: Ward.PresenceOptions<unknown> | undefined) => boolean;
21
+ /**
22
+ * The presence of the nearest `w.Presence` above `element`, made at the first ask (a child's Mount, or
23
+ * the presence element's own); none with no presence above, or when the Handle lacks the Feature.
24
+ */
25
+ export declare const nearestPresence: (provider: Provider, state: State, element: Element) => Presence | undefined;
26
+ /**
27
+ * Run the presence of `element` when it carries `w.Presence` (its own Mount, after `mountElement`):
28
+ * nothing for an element without one. With its Feature on its way in a load (#793, Q15), made and run
29
+ * as it arrives: the children mounted before then started with no presence, those after enroll.
30
+ * Returns the release.
31
+ */
32
+ export declare const mountPresence: (provider: Provider, state: State, element: Element, paused: () => boolean, offer: (message: unknown) => void) => (() => void);
33
+ //# sourceMappingURL=presence.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presence.d.ts","sourceRoot":"","sources":["../../src/internal/presence.ts"],"names":[],"mappings":"AAgBA,OAAO,KAAK,KAAK,kBAAkB,MAAM,yCAAyC,CAAA;AAUlF,OAAO,KAAK,KAAK,IAAI,MAAM,YAAY,CAAA;AAKvC,OAAO,EAAgC,KAAK,QAAQ,EAAiB,KAAK,KAAK,EAAE,MAAM,eAAe,CAAA;AAUtG,uGAAuG;AACvG,MAAM,WAAW,QAAQ;IACvB,gFAAgF;IAChF,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAC,oBAAoB,CAAA;IACzD,oFAAoF;IACpF,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,MAAM,IAAI,KAAK,MAAM,IAAI,CAAA;IAC1E,qHAAqH;IACrH,QAAQ,CAAC,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,OAAO,EAAE,KAAK,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAAK,MAAM,IAAI,CAAA;IACxF,yGAAyG;IACzG,QAAQ,CAAC,KAAK,EAAE,MAAM,OAAO,CAAA;CAC9B;AAcD;;;;GAIG;AACH,eAAO,MAAM,YAAY,YAAa,IAAI,CAAC,eAAe,CAAC,OAAO,CAAC,GAAG,SAAS,KAAG,OAAiH,CAAA;AAcnM;;;GAGG;AACH,eAAO,MAAM,eAAe,aAAc,QAAQ,SAAS,KAAK,WAAW,OAAO,KAAG,QAAQ,GAAG,SACuD,CAAA;AA2BvJ;;;;;GAKG;AACH,eAAO,MAAM,aAAa,aAAc,QAAQ,SAAS,KAAK,WAAW,OAAO,UAAU,MAAM,OAAO,SAAS,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAAG,CAAC,MAAM,IAAI,CAgBvJ,CAAA"}
@@ -0,0 +1,338 @@
1
+ /**
2
+ * Presence on Foldkit (ADR-0071 decision 29; *Amendment (#791)* at slice 2): `w.Presence(options)` on
3
+ * the leavers' parent. Its element's Mount runs dom's presence controller over one `MutationObserver`
4
+ * on the element's child list. Each delivery, a microtask after Foldkit's patch (P8), or in the patch's
5
+ * task when a `w.*` element's Mount flushes it (#840), puts back each known child the patch took out,
6
+ * where it was; asks the controller what goes on the page (`shown`: under `mode="wait"` an entering
7
+ * child is held, hidden with `display: none`, until the last leaver is gone, P23); tells the controller
8
+ * what's present, which retains each leaver at Motion's place, a `popLayout` one pinned where the
9
+ * binding's snapshot measured it (#840), and plays its exit (#675's placement is P19's); and then starts
10
+ * the children mounted since the last delivery. A child under a presence starts in that delivery, not
11
+ * in its own Mount: take-overs (#286) and holds are decided in `shown`, after Foldkit has mounted the
12
+ * child and before anything of it animates.
13
+ *
14
+ * @module
15
+ */
16
+ import * as PresenceRecord from "@wardic/core/unstable/PresenceRecord";
17
+ import * as Keys from "@wardic/dom/unstable/features/Keys";
18
+ import * as Arr from "effect/Array";
19
+ import * as Bool from "effect/Boolean";
20
+ import { constFalse, constTrue, constVoid, identity } from "effect/Function";
21
+ import * as Iter from "effect/Iterable";
22
+ import * as MutableRef from "effect/MutableRef";
23
+ import * as Option from "effect/Option";
24
+ import * as Predicate from "effect/Predicate";
25
+ import * as UndefinedOr from "effect/UndefinedOr";
26
+ import { deliveredTo, hintFrameUnless } from "./delivery.js";
27
+ import { configOf, dispatcherOf } from "./element.js";
28
+ import { PresenceMaker } from "./keys.js";
29
+ import { quietLayoutIn } from "./layout.js";
30
+ import { featureIn, snapshotSpent } from "./services.js";
31
+ import { isMounted, nearestPresenceElement, releaseWaiting } from "./tree.js";
32
+ import { DEV } from "@wardic/foldkit/internal/dev";
33
+ // Module state (#460, Q7): each presence element's presence, held weakly by the element.
34
+ const presences = new WeakMap();
35
+ /** Development's word on `w.Presence` without its Feature (#792, Q9). */
36
+ const MISSING = 'wardic: w.Presence needs the `presence` Feature, which this Handle doesn\'t have. Add it: `import { Features } from "@wardic/foldkit"`, then `Wardic.make({ env, features: [Features.presence] })`.';
37
+ /** Development's word on `w.Presence` given to an element after its first render: its Mount is made once, so the presence never runs. */
38
+ const LATE = "wardic: w.Presence was added to an element already mounted, whose Mount runs without it: its children animate with no presence. Give w.Presence on the element's first render, or key the element so it's made again.";
39
+ /** No options: `w.Presence()`. */
40
+ const NO_OPTIONS = {};
41
+ /**
42
+ * Whether a `w.Presence` with `options` holds the children of its first render at their `Animate`
43
+ * (`initial: false`, #134): what the walk at a provider element's build writes for them (#794), and what
44
+ * their Mounts start them at while that render is the presence's first (dom's `blocksInitial`).
45
+ */
46
+ export const holdsInitial = (options) => UndefinedOr.match(options, { onUndefined: constFalse, onDefined: (given) => given.initial === false });
47
+ /** Whether a node is an element: what a presence's children and leavers are (text is never one). */
48
+ const isElement = (node) => node instanceof Element;
49
+ /** Whether an element has an inline style to hide it through. */
50
+ const isStyled = (node) => Bool.and(isElement(node), Predicate.hasProperty(node, "style"));
51
+ /** The elements of what the controller's `shown` returns: a node, a flat list, or none. */
52
+ const elementsOf = (shown) => Arr.filter(Arr.ensure(shown), isElement);
53
+ /**
54
+ * The presence of the nearest `w.Presence` above `element`, made at the first ask (a child's Mount, or
55
+ * the presence element's own); none with no presence above, or when the Handle lacks the Feature.
56
+ */
57
+ export const nearestPresence = (provider, state, element) => UndefinedOr.match(nearestPresenceElement(element), { onUndefined: () => undefined, onDefined: (owner) => presenceOf(provider, state, owner, false) });
58
+ /**
59
+ * `element`'s presence, it carrying `w.Presence`: the known one, else made now, by its own Mount (`own`)
60
+ * or by a child's first. None without the Feature, warned once; and none when a child asks for one on an
61
+ * element whose Mount has already run without it (a later render's `w.Presence`), warned once in
62
+ * development: the child then starts as it would with no presence above.
63
+ */
64
+ const presenceOf = (provider, state, element, own) => {
65
+ const known = presences.get(element);
66
+ if (Predicate.isNotUndefined(known))
67
+ return known;
68
+ // Its Feature may be on its way (#793, Q15): nothing said, and the element's own Mount makes it as it arrives.
69
+ const pending = provider.features.pending();
70
+ if (Bool.and(Bool.not(own), isMounted(element))) {
71
+ if (DEV && Bool.not(pending))
72
+ provider.registry.warnOnce("presence-late", LATE);
73
+ return undefined;
74
+ }
75
+ const maker = featureIn(provider, PresenceMaker);
76
+ if (Predicate.isUndefined(maker)) {
77
+ if (Bool.not(pending))
78
+ provider.registry.warnOnce("presence", MISSING);
79
+ return undefined;
80
+ }
81
+ const made = makePresence(provider, state, maker, element);
82
+ presences.set(element, made);
83
+ return made;
84
+ };
85
+ /**
86
+ * Run the presence of `element` when it carries `w.Presence` (its own Mount, after `mountElement`):
87
+ * nothing for an element without one. With its Feature on its way in a load (#793, Q15), made and run
88
+ * as it arrives: the children mounted before then started with no presence, those after enroll.
89
+ * Returns the release.
90
+ */
91
+ export const mountPresence = (provider, state, element, paused, offer) => {
92
+ if (Predicate.isUndefined(configOf(deliveredTo(element)).presence))
93
+ return constVoid;
94
+ const made = presenceOf(provider, state, element, true);
95
+ if (Predicate.isNotUndefined(made))
96
+ return made.mount(paused, offer);
97
+ if (Bool.not(provider.features.pending()))
98
+ return constVoid;
99
+ const release = MutableRef.make(constVoid);
100
+ const stopRechecks = provider.onFeatures(() => {
101
+ UndefinedOr.map(presenceOf(provider, state, element, true), (presence) => {
102
+ MutableRef.set(release, presence.mount(paused, offer));
103
+ stopRechecks();
104
+ });
105
+ });
106
+ return () => {
107
+ stopRechecks();
108
+ MutableRef.get(release)();
109
+ };
110
+ };
111
+ /** Put `node` back where Foldkit took it from (P8): before the node after it, if still a child of `parent`; else after the one before; else at the end. */
112
+ const placeBack = (parent, node, record) => {
113
+ const next = record.nextSibling;
114
+ if (Predicate.isNotNull(next) && next.parentNode === parent) {
115
+ parent.insertBefore(node, next);
116
+ return;
117
+ }
118
+ const previous = record.previousSibling;
119
+ if (Predicate.isNotNull(previous) && previous.parentNode === parent) {
120
+ parent.insertBefore(node, previous.nextSibling);
121
+ return;
122
+ }
123
+ parent.appendChild(node);
124
+ };
125
+ /** The presence of one `w.Presence` element (above). */
126
+ const makePresence = (provider, state, maker, element) => {
127
+ const optionsNow = () => UndefinedOr.match(configOf(deliveredTo(element)).presence, { onUndefined: () => NO_OPTIONS, onDefined: identity });
128
+ // What its Mount gives it when it runs, after its children's Mounts: until then, no Message leaves.
129
+ let paused = constTrue;
130
+ let offer = constVoid;
131
+ const pending = [];
132
+ // The children `wait` holds, each with the `display` it had.
133
+ const hidden = new Map();
134
+ // Foldkit's children as of the last delivery: a removed one of them is a leaver to put back.
135
+ let known = new Set();
136
+ let observer;
137
+ let torn = false;
138
+ const dispatch = dispatcherOf((message) => offer(message));
139
+ /** Whether its children's going and coming moves the `layout` elements around them (Motion's `presenceAffectsLayout`), `true` unless told otherwise. */
140
+ const affectsLayout = () => optionsNow().presenceAffectsLayout !== false;
141
+ // `onExitComplete` as a Message (decision 23), read when the last leaver has gone; none under replay (decision 34).
142
+ const exitCompleteOf = () => {
143
+ if (paused())
144
+ return undefined;
145
+ return UndefinedOr.map(optionsNow().onExitComplete, (handler) => () => dispatch(handler)(undefined));
146
+ };
147
+ const controller = maker.make({
148
+ runtime: provider.runtime,
149
+ renderer: provider.renderer,
150
+ projection: () => Keys.projectionIn(provider.registry.built()),
151
+ reducedMotion: provider.reducedMotion,
152
+ positionalKeys: provider.positionalKeys,
153
+ defaultTransition: provider.defaultTransition,
154
+ initial: () => optionsNow().initial,
155
+ events: maker.events(provider.runtime, exitCompleteOf),
156
+ mode: () => optionsNow().mode,
157
+ custom: () => optionsNow().custom,
158
+ anchorX: () => optionsNow().anchorX,
159
+ anchorY: () => optionsNow().anchorY,
160
+ presenceAffectsLayout: () => optionsNow().presenceAffectsLayout,
161
+ // The last leaver has gone: the children `wait` held go on the page, in a delivery of their own. A
162
+ // microtask later, not now: a take-over ends the last exit inside `shown` or `present` (dom's
163
+ // `leaveEnds`), where a delivery can't run; Solid's release is a signal, read later, for the same reason.
164
+ release: () => {
165
+ queueMicrotask(() => deliver([], true));
166
+ },
167
+ });
168
+ // `propagate` (Motion's): under a presence above, read once, as Solid's.
169
+ const tearDown = maker.propagateTo(UndefinedOr.map(nearestPresence(provider, state, element), (above) => above.context), optionsNow().propagate === true, controller);
170
+ const hide = (child) => {
171
+ Option.map(Option.liftPredicate(child, isStyled), (styled) => {
172
+ if (hidden.has(styled))
173
+ return;
174
+ hidden.set(styled, styled.style.display);
175
+ styled.style.display = "none";
176
+ });
177
+ };
178
+ const show = (child) => {
179
+ Option.map(Option.liftPredicate(child, isStyled), (styled) => {
180
+ UndefinedOr.map(hidden.get(styled), (was) => {
181
+ hidden.delete(styled);
182
+ styled.style.display = was;
183
+ });
184
+ });
185
+ };
186
+ /**
187
+ * The known children `records` say Foldkit took out, each put back where it was: the change's
188
+ * leavers. A held child it took out never showed: dropped, with no exit (P23's W3), not put back.
189
+ */
190
+ const takenOut = (records) => {
191
+ const leavers = new Set();
192
+ let dropped = 0;
193
+ Iter.forEach(records, (record) => {
194
+ Iter.forEach(record.removedNodes, (removed) => {
195
+ Option.map(Option.liftPredicate(removed, isElement), (node) => {
196
+ if (node.isConnected)
197
+ return;
198
+ if (isStyled(node) && hidden.has(node)) {
199
+ hidden.delete(node);
200
+ known.delete(node);
201
+ dropped++;
202
+ return;
203
+ }
204
+ if (Bool.not(known.has(node)))
205
+ return;
206
+ if (leavers.has(node))
207
+ return;
208
+ leavers.add(node);
209
+ placeBack(element, node, record);
210
+ });
211
+ });
212
+ });
213
+ return { leavers, dropped };
214
+ };
215
+ /** The children `records` say Foldkit put in, still on the page: the change's enterers (a moved child among them). */
216
+ const putIn = (records) => {
217
+ const enterers = new Set();
218
+ Iter.forEach(records, (record) => {
219
+ Iter.forEach(record.addedNodes, (added) => {
220
+ Option.map(Option.liftPredicate(added, isElement), (node) => {
221
+ if (node.isConnected)
222
+ enterers.add(node);
223
+ });
224
+ });
225
+ });
226
+ return enterers;
227
+ };
228
+ /** A child's start, now, or once `wait` shows it. */
229
+ const start = (child) => {
230
+ if (child.gone)
231
+ return;
232
+ const begun = () => {
233
+ child.cancel = undefined;
234
+ child.release = child.begin();
235
+ };
236
+ child.cancel = PresenceRecord.presenceHold(controller.context, child.element, begun);
237
+ if (Predicate.isUndefined(child.cancel))
238
+ begun();
239
+ };
240
+ /**
241
+ * What the Handle calls on it (#840): its children measured where they are, ahead of a patch, which
242
+ * `popLayout` pins the next change's leavers at; and its delivery run now, from the records its observer
243
+ * holds, ahead of a Mount, since a presence inside an entering child starts that child's elements at its
244
+ * own mount, inside the patch's task, before this presence's observer is told, and a `layoutId` twin
245
+ * starting then measures the one it takes over from, in a leaver this presence hasn't pinned yet.
246
+ * Foldkit runs a Mount in its vnode's `insert` hook, once the patch has committed, so the records a
247
+ * flush takes are the whole change's.
248
+ */
249
+ const live = {
250
+ snapshot: () => {
251
+ if (optionsNow().mode !== "popLayout")
252
+ return;
253
+ // A change not yet delivered (an earlier patch's in this task) first, its leavers pinned where they were; then the children as they stand.
254
+ live.flush();
255
+ controller.snapshot(Arr.filter(Arr.fromIterable(element.children), (child) => known.has(child)));
256
+ // Measuring an outermost `<svg>` child puts dom's filler in and out: no change of Foldkit's.
257
+ UndefinedOr.map(observer, (watching) => watching.takeRecords());
258
+ },
259
+ flush: () => {
260
+ UndefinedOr.map(observer, (watching) => {
261
+ const records = watching.takeRecords();
262
+ if (records.length === 0)
263
+ return;
264
+ deliver(records, true);
265
+ // Taking the records silences the observer's own callback for them, which would have started the
266
+ // children enrolled after this delivery: those of the patch's Mounts that come after the one
267
+ // flushing. A delivery a microtask on starts them, where the observer's would have.
268
+ queueMicrotask(() => {
269
+ if (pending.length > 0)
270
+ deliver([], true);
271
+ });
272
+ });
273
+ },
274
+ };
275
+ /** A delivery (above): after a patch, at the mount, at a flush, or as the last leaver goes. */
276
+ const deliver = (records, hint) => {
277
+ if (torn)
278
+ return;
279
+ const { leavers, dropped } = takenOut(records);
280
+ const enterers = putIn(records);
281
+ // Records of the controller's own removals alone (an exit's end, after its delivery): nothing of Foldkit's changed.
282
+ if (Bool.and(records.length > 0, Bool.and(leavers.size === 0, Bool.and(enterers.size === 0, dropped === 0))))
283
+ return;
284
+ // The exits and the starts take their first step in this frame (decision 32; #792, Q7); not at the mount, nor under replay.
285
+ if (hint)
286
+ hintFrameUnless(provider.loop, paused);
287
+ // Foldkit's children now: the known ones it kept, and the ones it put in; not a leaver the controller retains.
288
+ const current = Arr.filter(Arr.fromIterable(element.children), (child) => Bool.or(Bool.and(known.has(child), Bool.not(leavers.has(child))), enterers.has(child)));
289
+ // `shown` pins a `popLayout` leaver at the binding's snapshot and spends it (#840): the next render takes a new one.
290
+ snapshotSpent(state);
291
+ const onPage = new Set(elementsOf(controller.shown(current)));
292
+ Arr.forEach(current, (child) => Bool.match(onPage.has(child), { onTrue: () => show(child), onFalse: () => hide(child) }));
293
+ // Told not to affect layout (Motion's `presenceAffectsLayout: false`): its child list's changes make no pass either (#792, Q21).
294
+ quietLayoutIn(element, Bool.not(affectsLayout()));
295
+ controller.present(Arr.filter(current, (child) => onPage.has(child)));
296
+ // The children start once the leavers are retained and a `popLayout` one is pinned (#840): a child
297
+ // taking over a `layoutId` twin inside a leaver measures the twin as it starts, where the leaver is
298
+ // then, which before the pin is where the patch pushed it. Solid's children start after its presence
299
+ // has placed its leavers too.
300
+ Arr.forEach(pending.splice(0), start);
301
+ known = new Set(current);
302
+ // Its own moves, and the controller's, make records too: dropped, so they deliver nothing (P19).
303
+ UndefinedOr.map(observer, (watching) => watching.takeRecords());
304
+ };
305
+ return {
306
+ context: controller.context,
307
+ holds: () => holdsInitial(optionsNow()),
308
+ enroll: (child, begin) => {
309
+ const entry = { element: child, begin, release: undefined, cancel: undefined, gone: false };
310
+ pending.push(entry);
311
+ return () => {
312
+ UndefinedOr.map(entry.cancel, (cancel) => cancel());
313
+ releaseWaiting(entry);
314
+ };
315
+ },
316
+ mount: (isPaused, offerMessage) => {
317
+ paused = isPaused;
318
+ offer = offerMessage;
319
+ observer = new MutationObserver((records) => deliver(records, true));
320
+ observer.observe(element, { childList: true });
321
+ state.presences.add(live);
322
+ // The first delivery, inside the patch: every child is Foldkit's; those mounted with the presence start, and `initial: false` covers them.
323
+ known = new Set(Arr.fromIterable(element.children));
324
+ deliver([], false);
325
+ controller.mounted();
326
+ return () => {
327
+ torn = true;
328
+ state.presences.delete(live);
329
+ UndefinedOr.map(observer, (watching) => watching.disconnect());
330
+ observer = undefined;
331
+ tearDown();
332
+ quietLayoutIn(element, false);
333
+ presences.delete(element);
334
+ };
335
+ },
336
+ };
337
+ };
338
+ //# sourceMappingURL=presence.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"presence.js","sourceRoot":"","sources":["../../src/internal/presence.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,OAAO,KAAK,cAAc,MAAM,sCAAsC,CAAA;AAEtE,OAAO,KAAK,IAAI,MAAM,oCAAoC,CAAA;AAC1D,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AACnC,OAAO,KAAK,IAAI,MAAM,gBAAgB,CAAA;AACtC,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,iBAAiB,CAAA;AAC5E,OAAO,KAAK,IAAI,MAAM,i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each element received; `watch` keeps its last value and re-reads
4
+ * once per patch, in the patch's microtask (`delivery.ts`), firing on `!Equal.equals`; `untrack` is a
5
+ * plain call. One registry for every watch (P17: a child whose config is the same reference gets no
6
+ * delivery, so it hears its parent only through a global re-check).
7
+ *
8
+ * @module
9
+ */
10
+ import type * as Reactivity from "@wardic/core/unstable/Reactivity";
11
+ /** Re-read every watch, firing each whose value changed by `Equal.equals` (P17). */
12
+ export declare const recheck: () => void;
13
+ /** The port. */
14
+ export declare const reactivity: Reactivity.Reactivity;
15
+ //# sourceMappingURL=reactivity.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reactivity.d.ts","sourceRoot":"","sources":["../../src/internal/reactivity.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AACH,OAAO,KAAK,KAAK,UAAU,MAAM,kCAAkC,CAAA;AAenE,oFAAoF;AACpF,eAAO,MAAM,OAAO,QAAO,IAMvB,CAAA;AAEJ,gBAAgB;AAChB,eAAO,MAAM,UAAU,EAAE,UAAU,CAAC,UAUnC,CAAA"}
@@ -0,0 +1,26 @@
1
+ import * as Equal from "effect/Equal";
2
+ import { constVoid } from "effect/Function";
3
+ import * as Iter from "effect/Iterable";
4
+ // Module state (#460, Q7): the page's watches across providers, re-read once a patch.
5
+ const watches = new Set();
6
+ /** Re-read every watch, firing each whose value changed by `Equal.equals` (P17). */
7
+ export const recheck = () => Iter.forEach(watches, (watch) => {
8
+ const now = watch.accessor();
9
+ if (Equal.equals(watch.last, now))
10
+ return;
11
+ watch.last = now;
12
+ watch.onChange(now);
13
+ });
14
+ /** The port. */
15
+ export const reactivity = {
16
+ untrack: (fn) => fn(),
17
+ trigger: () => ({ track: constVoid, notify: recheck }),
18
+ watch: (accessor, onChange) => {
19
+ const watch = { accessor, onChange: onChange, last: accessor() };
20
+ watches.add(watch);
21
+ return () => {
22
+ watches.delete(watch);
23
+ };
24
+ },
25
+ };
26
+ //# sourceMappingURL=reactivity.js.map
@@ -0,0 +1 @@
1
+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 * Reorder on Foldkit (#793, PR 3; ADR-0020, ADR-0037; ADR-0071 decision 28): `w.ReorderGroup(options)`
3
+ * on the list element and `w.ReorderItem(value)` on each keyed item. The group is dom's controller
4
+ * (`ReorderController.make`) over the provider's projection system and the Environment's Announcer, in a
5
+ * Scope of its own: made by the first of its items to mount (Foldkit mounts a child before its parent),
6
+ * or by its own Mount, which sends its Messages and releases it; under a load, as the Features arrive
7
+ * (Q15). The order lives in the Model: each Crossover sends `onReorder`'s Message with the new order,
8
+ * which the group reads as its own until the render delivers the Model's (Q12), and a delivery whose
9
+ * values changed tells the controller, whose pass measures the new slots (Q11). Each item is a layout
10
+ * element the group's axis drags, raised while in hand, its keys, blurs and presses watched for the
11
+ * **Keyboard reorder** (dom's `ReorderInput`), a tab stop with the group's instructions in
12
+ * `aria-describedby`, written at mount (Q12), and its `touch-action` the group's axis's, under its own
13
+ * style. A group on a Handle without `layout` and `drag` is inert, warned once in development; an item
14
+ * outside a group, or on an unkeyed element, is warned too.
15
+ *
16
+ * @module
17
+ */
18
+ import type * as Drag from "@wardic/core/Drag";
19
+ import * as ReorderController from "@wardic/dom/ReorderController";
20
+ import { type Config, type Dispatch } from "./element.ts";
21
+ import { type Provider } from "./services.ts";
22
+ /** What an item adds to its element (Solid's item internals): its drag's axis at each start, its samples to the group, its node registered, and its end. */
23
+ export interface ItemInternals {
24
+ /** The axis the item's drag takes, read at each gesture's start: the group's. */
25
+ readonly dragAxis: () => true | "x" | "y";
26
+ /** Each drag sample, after the track's write: the group's Crossovers. */
27
+ readonly onDragSample: (sample: Drag.Sample) => void;
28
+ /** Its layout node, registered with the group as it's made; once. */
29
+ readonly onLayoutHandle: (handle: ReorderController.ItemHandle) => void;
30
+ /** At the element's release: its node unregistered, its watches closed, a gesture or a lift in progress ended. */
31
+ readonly dispose: () => void;
32
+ }
33
+ /**
34
+ * The group's part of its element's Mount: the group made, if its first item hasn't made it, or as its
35
+ * Features arrive (Q15); its Messages through this Mount's queue from then on; and its release, which
36
+ * ends the controller.
37
+ */
38
+ export declare const mountReorderGroup: (provider: Provider, element: HTMLElement, paused: () => boolean, offer: (message: unknown) => void) => (() => void);
39
+ /** A delivery to a group element (Q11): values that changed tell the controller, whose items the next Measure pass lays out in them. */
40
+ export declare const groupDelivered: (element: Element) => void;
41
+ /**
42
+ * The item of `element`, which carries `w.ReorderItem`, joined to the group above it; `undefined`, a
43
+ * plain element, when it carries none, has no group above it, or the group isn't there (its Features
44
+ * missing, or on their way). `onLift` hears its keyboard lift start and end: the element's `WhileDrag`.
45
+ */
46
+ export declare const reorderItemOf: (provider: Provider, element: HTMLElement, id: string, config: () => Config, dispatch: Dispatch, onLift: (lifted: boolean) => void) => ItemInternals | undefined;
47
+ //# sourceMappingURL=reorder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reorder.d.ts","sourceRoot":"","sources":["../../src/internal/reorder.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AACH,OAAO,KAAK,KAAK,IAAI,MAAM,mBAAmB,CAAA;AAI9C,OAAO,KAAK,iBAAiB,MAAM,+BAA+B,CAAA;AAqBlE,OAAO,EAAE,KAAK,MAAM,EAAY,KAAK,QAAQ,EAAwB,MAAM,cAAc,CAAA;AACzF,OAAO,EAAa,KAAK,QAAQ,EAA2B,MAAM,eAAe,CAAA;AAIjF,4JAA4J;AAC5J,MAAM,WAAW,aAAa;IAC5B,iFAAiF;IACjF,QAAQ,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,CAAA;IACzC,yEAAyE;IACzE,QAAQ,CAAC,YAAY,EAAE,CAAC,MAAM,EAAE,IAAI,CAAC,MAAM,KAAK,IAAI,CAAA;IACpD,qEAAqE;IACrE,QAAQ,CAAC,cAAc,EAAE,CAAC,MAAM,EAAE,iBAAiB,CAAC,UAAU,KAAK,IAAI,CAAA;IACvE,kHAAkH;IAClH,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAC7B;AAmND;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,aAAc,QAAQ,WAAW,WAAW,UAAU,MAAM,OAAO,SAAS,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,KAAG,CAAC,MAAM,IAAI,CAiBjJ,CAAA;AAED,wIAAwI;AACxI,eAAO,MAAM,cAAc,YAAa,OAAO,KAAG,IAEjD,CAAA;AAED;;;;GAIG;AACH,eAAO,MAAM,aAAa,aAAc,QAAQ,WAAW,WAAW,MAAM,MAAM,UAAU,MAAM,MAAM,YAAY,QAAQ,UAAU,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,KAAG,aAAa,GAAG,SAUjL,CAAA"}