@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.
- 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 +100 -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 +222 -0
- package/dist/internal/services.d.ts.map +1 -0
- package/dist/internal/services.js +338 -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 +124 -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 +486 -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,313 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 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 InputSource from "@wardic/core/InputSource"
|
|
20
|
+
import type * as CoreReorder from "@wardic/core/Reorder"
|
|
21
|
+
import * as DomAnnouncer from "@wardic/dom/DomAnnouncer"
|
|
22
|
+
import * as ReorderController from "@wardic/dom/ReorderController"
|
|
23
|
+
import * as Style from "@wardic/dom/Style"
|
|
24
|
+
import * as ElementSetup from "@wardic/dom/unstable/ElementSetup"
|
|
25
|
+
import * as GestureFeatures from "@wardic/dom/unstable/GestureFeatures"
|
|
26
|
+
import * as OwnerScope from "@wardic/dom/unstable/OwnerScope"
|
|
27
|
+
import * as ReorderInput from "@wardic/dom/unstable/ReorderInput"
|
|
28
|
+
import * as Keys from "@wardic/dom/unstable/features/Keys"
|
|
29
|
+
import type * as Layout from "@wardic/dom/unstable/features/Layout"
|
|
30
|
+
import * as Bool from "effect/Boolean"
|
|
31
|
+
import type * as Context from "effect/Context"
|
|
32
|
+
import * as Effect from "effect/Effect"
|
|
33
|
+
import { constUndefined, constVoid, identity } from "effect/Function"
|
|
34
|
+
import * as Iter from "effect/Iterable"
|
|
35
|
+
import * as MutableRef from "effect/MutableRef"
|
|
36
|
+
import * as Option from "effect/Option"
|
|
37
|
+
import * as Predicate from "effect/Predicate"
|
|
38
|
+
import * as Scope from "effect/Scope"
|
|
39
|
+
import * as Str from "effect/String"
|
|
40
|
+
import * as UndefinedOr from "effect/UndefinedOr"
|
|
41
|
+
import type * as Ward from "../Ward.ts"
|
|
42
|
+
import { deliveredTo } from "./delivery.ts"
|
|
43
|
+
import { type Config, configOf, type Dispatch, dispatchUnlessPaused } from "./element.ts"
|
|
44
|
+
import { featureIn, type Provider, reporterOf, warnMissing } from "./services.ts"
|
|
45
|
+
import { nearestAncestor } from "./tree.ts"
|
|
46
|
+
import { DEV } from "@wardic/foldkit/internal/dev"
|
|
47
|
+
|
|
48
|
+
/** 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. */
|
|
49
|
+
export interface ItemInternals {
|
|
50
|
+
/** The axis the item's drag takes, read at each gesture's start: the group's. */
|
|
51
|
+
readonly dragAxis: () => true | "x" | "y"
|
|
52
|
+
/** Each drag sample, after the track's write: the group's Crossovers. */
|
|
53
|
+
readonly onDragSample: (sample: Drag.Sample) => void
|
|
54
|
+
/** Its layout node, registered with the group as it's made; once. */
|
|
55
|
+
readonly onLayoutHandle: (handle: ReorderController.ItemHandle) => void
|
|
56
|
+
/** At the element's release: its node unregistered, its watches closed, a gesture or a lift in progress ended. */
|
|
57
|
+
readonly dispose: () => void
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** What an item joins its group with. */
|
|
61
|
+
interface Joining {
|
|
62
|
+
readonly element: HTMLElement
|
|
63
|
+
/** Its value in the group's `values`. */
|
|
64
|
+
readonly value: unknown
|
|
65
|
+
/** The element's id, for a report. */
|
|
66
|
+
readonly id: string
|
|
67
|
+
/** The element's config now, read at each use. */
|
|
68
|
+
readonly config: () => Config
|
|
69
|
+
/** Hears its keyboard lift start and end: the element's `WhileDrag`. */
|
|
70
|
+
readonly onLift: (lifted: boolean) => void
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/** A mounted group (above): what its items join, what its deliveries tell it, what sends its Messages, and its release. */
|
|
74
|
+
interface Group {
|
|
75
|
+
readonly join: (joining: Joining) => ItemInternals
|
|
76
|
+
/** A delivery to the group element: values that changed tell the controller. */
|
|
77
|
+
readonly delivered: () => void
|
|
78
|
+
/** What sends its Messages: its own Mount's queue once it has mounted, its first item's before; none after its release. */
|
|
79
|
+
readonly dispatch: MutableRef.MutableRef<Dispatch>
|
|
80
|
+
/** Its end: the controller's Scope closed. */
|
|
81
|
+
readonly release: () => void
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Module state (#460, Q7): each group element's group, held weakly by the element.
|
|
85
|
+
const groups = new WeakMap<Element, Group>()
|
|
86
|
+
|
|
87
|
+
/** A released group's dispatch: its queue is gone, so an item's late end goes nowhere. */
|
|
88
|
+
const NO_DISPATCH: Dispatch = () => constVoid
|
|
89
|
+
|
|
90
|
+
const CLOSE_FAILED = "wardic.reorder: a group's end failed"
|
|
91
|
+
const ITEM_CLOSE_FAILED = "wardic.reorder: an item's end failed"
|
|
92
|
+
const INPUT_FAILED = "wardic.reorder: an item's input handler failed"
|
|
93
|
+
const UNKEYED = "wardic.reorder: a w.ReorderItem is on an unkeyed element. Key it, `w.keyed(\"li\")(key, …)`, so a render reorders it by its key."
|
|
94
|
+
const NO_GROUP = "wardic.reorder: a w.ReorderItem has no w.ReorderGroup above it: it's a plain element."
|
|
95
|
+
|
|
96
|
+
/** `element`'s group options, as its last delivery gave them. */
|
|
97
|
+
const groupOptionsOf = (element: Element): Ward.ReorderGroupOptions<unknown, unknown> | undefined => configOf(deliveredTo(element)).reorderGroup
|
|
98
|
+
|
|
99
|
+
/** Whether `element` carries `w.ReorderGroup`. */
|
|
100
|
+
const isGroup = (element: Element): boolean => Predicate.isNotUndefined(groupOptionsOf(element))
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Run `run` after the frame the render of a Message would run in: Foldkit renders a changed Model in
|
|
104
|
+
* the next Refresh frame, so one more on, from the Environment's frame source (ADR-0031; `requestFrame`
|
|
105
|
+
* detached, as its contract says). Nothing with an Environment that gives none.
|
|
106
|
+
*/
|
|
107
|
+
const afterRender = (provider: Provider, run: () => void): void => {
|
|
108
|
+
UndefinedOr.map(provider.frames, ({ requestFrame }) => requestFrame(() => requestFrame(run)))
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* The group of `element`, which carries `w.ReorderGroup`, made now if nothing has: the controller over
|
|
113
|
+
* the provider's `layout` and `drag` Features, in a Scope of the group's own; `undefined`, and a word in
|
|
114
|
+
* development, without them (none while a load is on its way, which may bring them).
|
|
115
|
+
*/
|
|
116
|
+
const groupOf = (provider: Provider, element: HTMLElement, dispatch: Dispatch): Group | undefined => {
|
|
117
|
+
const known = groups.get(element)
|
|
118
|
+
if (Predicate.isNotUndefined(known)) return known
|
|
119
|
+
const built = provider.features.services()
|
|
120
|
+
if (Predicate.isUndefined(Keys.projectionIn(built))) {
|
|
121
|
+
warnMissing(provider, "layout", "A w.ReorderGroup")
|
|
122
|
+
return undefined
|
|
123
|
+
}
|
|
124
|
+
if (Predicate.isUndefined(featureIn(provider, Keys.DragGesture))) {
|
|
125
|
+
warnMissing(provider, "drag", "A w.ReorderGroup")
|
|
126
|
+
return undefined
|
|
127
|
+
}
|
|
128
|
+
// Its options at each read: the last delivery's, kept if a later render drops the attribute.
|
|
129
|
+
const last = MutableRef.make(UndefinedOr.getOrThrow(groupOptionsOf(element)))
|
|
130
|
+
const options = (): Ward.ReorderGroupOptions<unknown, unknown> =>
|
|
131
|
+
UndefinedOr.match(groupOptionsOf(element), {
|
|
132
|
+
onUndefined: () => MutableRef.get(last),
|
|
133
|
+
onDefined: (given) => {
|
|
134
|
+
MutableRef.set(last, given)
|
|
135
|
+
return given
|
|
136
|
+
},
|
|
137
|
+
})
|
|
138
|
+
const sender = MutableRef.make(dispatch)
|
|
139
|
+
/** Send `handler`'s Message for `value`, if the options give one. */
|
|
140
|
+
const tell = <A>(handler: Ward.Handler<unknown, A> | undefined, value: A): void => {
|
|
141
|
+
UndefinedOr.map(handler, (given) => MutableRef.get(sender)(given)(value))
|
|
142
|
+
}
|
|
143
|
+
// The order the group last asked for, read as its values until the Model's render delivers one (Q12):
|
|
144
|
+
// `onReorder`'s Message reaches `update` a microtask later and the render a frame later, so the
|
|
145
|
+
// controller reads the order it asked for meanwhile, as Solid's reads its synchronous render's. An app
|
|
146
|
+
// that keeps its order renders nothing, so the ask is let go once the render's frame has passed.
|
|
147
|
+
const askedOrder = MutableRef.make<ReadonlyArray<unknown> | undefined>(undefined)
|
|
148
|
+
const ask = (values: ReadonlyArray<unknown>): void => {
|
|
149
|
+
MutableRef.set(askedOrder, values)
|
|
150
|
+
afterRender(provider, () => {
|
|
151
|
+
if (MutableRef.get(askedOrder) === values) MutableRef.set(askedOrder, undefined)
|
|
152
|
+
})
|
|
153
|
+
}
|
|
154
|
+
// Its items' touch-action writers, run at each change of the axis.
|
|
155
|
+
const touchWriters = new Set<() => void>()
|
|
156
|
+
// The element of the item a Keyboard reorder has lifted (ADR-0037): focus is put back on it after a render moves it.
|
|
157
|
+
const lifted = MutableRef.make<HTMLElement | undefined>(undefined)
|
|
158
|
+
const scope = OwnerScope.open(provider.runtime)
|
|
159
|
+
const controller = provider.runtime.runSync(
|
|
160
|
+
ReorderController.make<unknown>({
|
|
161
|
+
values: () => UndefinedOr.match(MutableRef.get(askedOrder), { onUndefined: () => options().values, onDefined: identity }),
|
|
162
|
+
onReorder: (values) => {
|
|
163
|
+
ask(values)
|
|
164
|
+
tell(options().onReorder, values)
|
|
165
|
+
},
|
|
166
|
+
onReorderEnd: (end) => tell(options().onReorderEnd, end),
|
|
167
|
+
onHoldStart: (start) => tell(options().onHoldStart, start),
|
|
168
|
+
onHoldEnd: (end) => tell(options().onHoldEnd, end),
|
|
169
|
+
axis: () => Option.fromUndefinedOr(options().axis),
|
|
170
|
+
onAxis: () => Iter.forEach(touchWriters, (write) => write()),
|
|
171
|
+
keyedWith: "`w.keyed(tag)`",
|
|
172
|
+
keyboard: () => ReorderController.keyboardOn(options().keyboard),
|
|
173
|
+
announcements: () => Option.fromUndefinedOr(options().announcements),
|
|
174
|
+
}).pipe(Effect.provide(built as Context.Context<Layout.LayoutServices>), Scope.provide(scope)),
|
|
175
|
+
)
|
|
176
|
+
// No scroll anchoring under the user's style, so the browser doesn't shift the page as items move (Motion's).
|
|
177
|
+
ElementSetup.writeUnderStyle(element, ReorderController.GROUP_STYLE)
|
|
178
|
+
controller.attach(element)
|
|
179
|
+
/** Its axis: the options', else the one detected from the items' boxes. */
|
|
180
|
+
const axis = (): CoreReorder.Axis => UndefinedOr.match(options().axis, { onUndefined: controller.detect, onDefined: identity })
|
|
181
|
+
/** The values its last delivery had: a change tells the controller. */
|
|
182
|
+
const values = MutableRef.make(options().values)
|
|
183
|
+
/**
|
|
184
|
+
* Focus back on the lifted item once the render that moved it has run (ADR-0037): a node Foldkit moves
|
|
185
|
+
* is blurred, and the driver judges a blur one scheduler hop later, so focus must be on the item by
|
|
186
|
+
* then, as Solid's controller puts it back inside the key, whose render is synchronous.
|
|
187
|
+
*/
|
|
188
|
+
const refocusLifted = (): void => {
|
|
189
|
+
UndefinedOr.map(MutableRef.get(lifted), (item) => {
|
|
190
|
+
if (item.ownerDocument.activeElement === item) return
|
|
191
|
+
item.focus({ preventScroll: true })
|
|
192
|
+
})
|
|
193
|
+
}
|
|
194
|
+
const join = ({ element: item, value, id, config, onLift }: Joining): ItemInternals => {
|
|
195
|
+
// Its keyboard lift (ADR-0037): the element's `WhileDrag`, and where focus belongs.
|
|
196
|
+
const driver = controller.item(value, () => Option.some(item), (on) => {
|
|
197
|
+
MutableRef.set(lifted, Bool.match(on, { onTrue: () => item, onFalse: constUndefined }))
|
|
198
|
+
onLift(on)
|
|
199
|
+
})
|
|
200
|
+
// Its touch-action, the group's axis's (ADR-0019 *Amendment (Reorder)*), under its own style, and
|
|
201
|
+
// none when its own presses don't drag it (#431): written now, before the drag's defaults, and at each axis change.
|
|
202
|
+
const own = Bool.not(Str.isEmpty(item.style.getPropertyValue("touch-action")))
|
|
203
|
+
const writeTouch = (): void => {
|
|
204
|
+
if (own) return
|
|
205
|
+
if (config().dragListener === false) return
|
|
206
|
+
item.style.setProperty("touch-action", Style.reorderTouchAction(axis()))
|
|
207
|
+
}
|
|
208
|
+
writeTouch()
|
|
209
|
+
touchWriters.add(writeTouch)
|
|
210
|
+
// The Keyboard reorder's tab stop and instructions (ADR-0037), written at mount (Q12): the app's own kept.
|
|
211
|
+
const keyboard = ReorderController.keyboardOn(options().keyboard)
|
|
212
|
+
if (Bool.not(item.hasAttribute("tabindex"))) UndefinedOr.map(ReorderController.tabStopOf(keyboard, false), (stop) => item.setAttribute("tabindex", String(stop)))
|
|
213
|
+
const instructions = Bool.match(keyboard, {
|
|
214
|
+
onTrue: () => DomAnnouncer.instructionsId(DomAnnouncer.documentOf(item), ReorderController.instructionsOf(options().instructions)),
|
|
215
|
+
onFalse: constUndefined,
|
|
216
|
+
})
|
|
217
|
+
const ownIds = Option.getOrUndefined(Option.filter(Option.fromNullOr(item.getAttribute("aria-describedby")), Str.isNonEmpty))
|
|
218
|
+
UndefinedOr.map(ReorderController.describedByOf(ownIds, instructions), (ids) => item.setAttribute("aria-describedby", ids))
|
|
219
|
+
// Its keys, blurs and presses (ADR-0037), watched in a Scope of its own on the provider, with no fiber at rest (#379).
|
|
220
|
+
const report = reporterOf(provider, id)
|
|
221
|
+
const watching = OwnerScope.open(provider.runtime)
|
|
222
|
+
provider.runtime.runSync(
|
|
223
|
+
Effect.provideService(
|
|
224
|
+
ReorderInput.watchItemInput(item, driver, (effect) => void provider.runtime.runFork(effect), (cause) => report(INPUT_FAILED, cause)),
|
|
225
|
+
InputSource.InputSource,
|
|
226
|
+
GestureFeatures.inputIn(provider.features.services()),
|
|
227
|
+
).pipe(Scope.provide(watching)),
|
|
228
|
+
)
|
|
229
|
+
const unregister = MutableRef.make<(() => void) | undefined>(undefined)
|
|
230
|
+
return {
|
|
231
|
+
dragAxis: () => ReorderController.itemDragAxis(driver.dragAxis()),
|
|
232
|
+
onDragSample: driver.onSample,
|
|
233
|
+
onLayoutHandle: (handle) => {
|
|
234
|
+
if (Predicate.isNotUndefined(MutableRef.get(unregister))) return
|
|
235
|
+
MutableRef.set(unregister, driver.register(handle))
|
|
236
|
+
},
|
|
237
|
+
dispose: () => {
|
|
238
|
+
UndefinedOr.map(MutableRef.get(unregister), (stop) => stop())
|
|
239
|
+
touchWriters.delete(writeTouch)
|
|
240
|
+
OwnerScope.close(provider.runtime, watching, ITEM_CLOSE_FAILED)
|
|
241
|
+
// An item unmounted mid-gesture gets no end sample: its disposal ends the gesture, and a lift.
|
|
242
|
+
driver.dispose()
|
|
243
|
+
},
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
const group: Group = {
|
|
247
|
+
join,
|
|
248
|
+
delivered: () => {
|
|
249
|
+
// The Model rendered: its order is the group's from here, whether or not it took the one asked for.
|
|
250
|
+
MutableRef.set(askedOrder, undefined)
|
|
251
|
+
const next = options().values
|
|
252
|
+
if (ReorderController.sameOrder(MutableRef.get(values), next)) return
|
|
253
|
+
MutableRef.set(values, next)
|
|
254
|
+
controller.valuesChanged()
|
|
255
|
+
// The patch moves the items after this delivery, the lifted one among them: focus back on it after.
|
|
256
|
+
queueMicrotask(refocusLifted)
|
|
257
|
+
},
|
|
258
|
+
dispatch: sender,
|
|
259
|
+
release: () => {
|
|
260
|
+
groups.delete(element)
|
|
261
|
+
MutableRef.set(sender, NO_DISPATCH)
|
|
262
|
+
OwnerScope.close(provider.runtime, scope, CLOSE_FAILED)
|
|
263
|
+
},
|
|
264
|
+
}
|
|
265
|
+
groups.set(element, group)
|
|
266
|
+
return group
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
/**
|
|
270
|
+
* The group's part of its element's Mount: the group made, if its first item hasn't made it, or as its
|
|
271
|
+
* Features arrive (Q15); its Messages through this Mount's queue from then on; and its release, which
|
|
272
|
+
* ends the controller.
|
|
273
|
+
*/
|
|
274
|
+
export const mountReorderGroup = (provider: Provider, element: HTMLElement, paused: () => boolean, offer: (message: unknown) => void): (() => void) => {
|
|
275
|
+
if (Bool.not(isGroup(element))) return constVoid
|
|
276
|
+
const dispatch = dispatchUnlessPaused(paused, offer)
|
|
277
|
+
const made = MutableRef.make<Group | undefined>(undefined)
|
|
278
|
+
const take = (): void => {
|
|
279
|
+
if (Predicate.isNotUndefined(MutableRef.get(made))) return
|
|
280
|
+
UndefinedOr.map(groupOf(provider, element, dispatch), (group) => {
|
|
281
|
+
MutableRef.set(made, group)
|
|
282
|
+
MutableRef.set(group.dispatch, dispatch)
|
|
283
|
+
})
|
|
284
|
+
}
|
|
285
|
+
take()
|
|
286
|
+
const stopRechecks = Bool.match(Bool.and(Predicate.isUndefined(MutableRef.get(made)), provider.features.pending()), { onTrue: () => provider.onFeatures(take), onFalse: () => constVoid })
|
|
287
|
+
return () => {
|
|
288
|
+
stopRechecks()
|
|
289
|
+
UndefinedOr.map(MutableRef.get(made), (group) => group.release())
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
/** A delivery to a group element (Q11): values that changed tell the controller, whose items the next Measure pass lays out in them. */
|
|
294
|
+
export const groupDelivered = (element: Element): void => {
|
|
295
|
+
UndefinedOr.map(groups.get(element), (group) => group.delivered())
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* The item of `element`, which carries `w.ReorderItem`, joined to the group above it; `undefined`, a
|
|
300
|
+
* plain element, when it carries none, has no group above it, or the group isn't there (its Features
|
|
301
|
+
* missing, or on their way). `onLift` hears its keyboard lift start and end: the element's `WhileDrag`.
|
|
302
|
+
*/
|
|
303
|
+
export const reorderItemOf = (provider: Provider, element: HTMLElement, id: string, config: () => Config, dispatch: Dispatch, onLift: (lifted: boolean) => void): ItemInternals | undefined => {
|
|
304
|
+
const item = config().reorderItem
|
|
305
|
+
if (Predicate.isUndefined(item)) return undefined
|
|
306
|
+
if (DEV && Predicate.isUndefined(config().key)) provider.registry.warnOnce("reorderItemKey", UNKEYED)
|
|
307
|
+
const above = nearestAncestor(element, isGroup)
|
|
308
|
+
if (Predicate.isUndefined(above)) {
|
|
309
|
+
if (DEV) provider.registry.warnOnce("reorderItemGroup", NO_GROUP)
|
|
310
|
+
return undefined
|
|
311
|
+
}
|
|
312
|
+
return UndefinedOr.map(groupOf(provider, above as HTMLElement, dispatch), (group) => group.join({ element, value: item.value, id, config, onLift }))
|
|
313
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The **Animation scope** on Foldkit (#433, Motion's `useAnimate`'s scope; #798, Q7–Q9, Q14 and Q19): an
|
|
3
|
+
* opaque record made apart from any element, given to one `w.*` element as `w.AnimationScope(scope)`,
|
|
4
|
+
* whose Mount makes it the scope's element (the latest mount wins, as a ref's does) and whose release
|
|
5
|
+
* stops the animations started in it where they are, as a Solid component's cleanup stops its
|
|
6
|
+
* `createAnimate` scope's. A Command's `Wardic.animate(…, { scope })` looks its selectors up inside the
|
|
7
|
+
* element and tells the scope each animation's start and end (dom's `scopeOf`, whose ref and
|
|
8
|
+
* `animations` list Foldkit doesn't use: it has no refs, and no Playback controls, Q10).
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
import * as Imperative from "@wardic/dom/unstable/Imperative"
|
|
13
|
+
import * as MutableRef from "effect/MutableRef"
|
|
14
|
+
import * as UndefinedOr from "effect/UndefinedOr"
|
|
15
|
+
|
|
16
|
+
/** An Animation scope: the `w.*` element it's mounted on, while it is. */
|
|
17
|
+
export interface AnimationScope {
|
|
18
|
+
/** The element given `w.AnimationScope(scope)`, once its Mount has run; `undefined` before, and after its release. */
|
|
19
|
+
readonly element: () => Element | undefined
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** What the binding holds of a scope: its element, dom's watch over its animations, and their stop. */
|
|
23
|
+
interface Parts {
|
|
24
|
+
readonly current: MutableRef.MutableRef<Element | undefined>
|
|
25
|
+
readonly watch: Imperative.AnimationWatch
|
|
26
|
+
readonly stopAll: () => void
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Module state (#460, Q7): each scope's parts, held weakly by the scope, for its element's Mount and the Commands.
|
|
30
|
+
const parts = new WeakMap<AnimationScope, Parts>()
|
|
31
|
+
|
|
32
|
+
/** Makes an Animation scope (Motion's `useAnimate`'s): needs no element, and outlives the element given it. */
|
|
33
|
+
export const make = (): AnimationScope => {
|
|
34
|
+
const made = Imperative.scopeOf<Element>()
|
|
35
|
+
const current = MutableRef.make<Element | undefined>(undefined)
|
|
36
|
+
const scope: AnimationScope = { element: () => MutableRef.get(current) }
|
|
37
|
+
parts.set(scope, { current, watch: made.watch, stopAll: made.stopAll })
|
|
38
|
+
return scope
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** `scope`'s parts: made by {@link make}, so never missing. */
|
|
42
|
+
const partsOf = (scope: AnimationScope): Parts => UndefinedOr.getOrThrow(parts.get(scope))
|
|
43
|
+
|
|
44
|
+
/** What a Command's animation tells `scope` as it starts and ends: dom's watch over the scope's animations in flight. */
|
|
45
|
+
export const watchOf = (scope: AnimationScope): Imperative.AnimationWatch => partsOf(scope).watch
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* `element` mounted with `scope` (its Mount): the scope's element from now. Returns the release: the
|
|
49
|
+
* scope's element cleared, if it's still this one, and the animations started in the scope stopped
|
|
50
|
+
* where they are (Q9, Q19); an element another mount took the scope from stops nothing.
|
|
51
|
+
*/
|
|
52
|
+
export const mounted = (scope: AnimationScope, element: Element): (() => void) => {
|
|
53
|
+
const { current, stopAll } = partsOf(scope)
|
|
54
|
+
MutableRef.set(current, element)
|
|
55
|
+
return () => {
|
|
56
|
+
if (MutableRef.get(current) !== element) return
|
|
57
|
+
MutableRef.set(current, undefined)
|
|
58
|
+
stopAll()
|
|
59
|
+
}
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A server render: no. The package's `node`, `worker` and `deno` export conditions resolve
|
|
3
|
+
* `server.node.ts` instead (#794, Q8), as a server does, so what runs under `IS_SERVER` (Appear's
|
|
4
|
+
* sampling, the chunk the provider renders) is the server's alone, and a client build drops it. Tested
|
|
5
|
+
* in a plain `if` or `&&`, never through `Bool`, as a build-time flag is (`docs/agents/effect-first.md`,
|
|
6
|
+
* *Pitfalls*). The view's build is the only code that runs on both: Mounts never run on a server.
|
|
7
|
+
* Typed `boolean`, not the literal `DEV` is, so both halves share one declaration and a check under
|
|
8
|
+
* either never narrows the other away; a bundler folds the value, not the type.
|
|
9
|
+
*
|
|
10
|
+
* @module
|
|
11
|
+
*/
|
|
12
|
+
export const IS_SERVER: boolean = false
|