@wardic/dom 1.1.1 → 1.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/ReorderController.d.ts +12 -1
- package/dist/ReorderController.d.ts.map +1 -1
- package/dist/ReorderController.js +25 -2
- package/dist/ReorderController.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +1 -1
- package/dist/internal/appear.d.ts +7 -2
- package/dist/internal/appear.d.ts.map +1 -1
- package/dist/internal/appear.js +2 -2
- package/dist/internal/appear.js.map +1 -1
- package/dist/internal/clock.d.ts +3 -0
- package/dist/internal/clock.d.ts.map +1 -1
- package/dist/internal/clock.js +3 -0
- package/dist/internal/clock.js.map +1 -1
- package/dist/internal/reorder.d.ts +3 -0
- package/dist/internal/reorder.d.ts.map +1 -1
- package/dist/internal/reorder.js +1 -1
- package/dist/internal/reorder.js.map +1 -1
- package/dist/unstable/AppearAnimations.d.ts +14 -1
- package/dist/unstable/AppearAnimations.d.ts.map +1 -1
- package/dist/unstable/AppearAnimations.js +16 -3
- package/dist/unstable/AppearAnimations.js.map +1 -1
- package/dist/unstable/DragDefaults.d.ts +6 -5
- package/dist/unstable/DragDefaults.d.ts.map +1 -1
- package/dist/unstable/DragDefaults.js +2 -6
- package/dist/unstable/DragDefaults.js.map +1 -1
- package/dist/unstable/DragTrack.d.ts +8 -0
- package/dist/unstable/DragTrack.d.ts.map +1 -1
- package/dist/unstable/DragTrack.js +17 -0
- package/dist/unstable/DragTrack.js.map +1 -1
- package/dist/unstable/ElementSetup.d.ts +8 -2
- package/dist/unstable/ElementSetup.d.ts.map +1 -1
- package/dist/unstable/ElementSetup.js +14 -2
- package/dist/unstable/ElementSetup.js.map +1 -1
- package/dist/unstable/Feature.d.ts +5 -4
- package/dist/unstable/Feature.d.ts.map +1 -1
- package/dist/unstable/Feature.js +7 -4
- package/dist/unstable/Feature.js.map +1 -1
- package/dist/unstable/GestureFeatures.d.ts +132 -3
- package/dist/unstable/GestureFeatures.d.ts.map +1 -1
- package/dist/unstable/GestureFeatures.js +189 -11
- package/dist/unstable/GestureFeatures.js.map +1 -1
- package/dist/unstable/Imperative.d.ts +11 -0
- package/dist/unstable/Imperative.d.ts.map +1 -1
- package/dist/unstable/Imperative.js +37 -7
- package/dist/unstable/Imperative.js.map +1 -1
- package/dist/unstable/InstanceFeatures.d.ts +7 -0
- package/dist/unstable/InstanceFeatures.d.ts.map +1 -0
- package/dist/unstable/InstanceFeatures.js +69 -0
- package/dist/unstable/InstanceFeatures.js.map +1 -0
- package/dist/unstable/ReorderInput.d.ts +45 -0
- package/dist/unstable/ReorderInput.d.ts.map +1 -0
- package/dist/unstable/ReorderInput.js +116 -0
- package/dist/unstable/ReorderInput.js.map +1 -0
- package/package.json +3 -3
- package/src/ReorderController.ts +34 -1
- package/src/index.ts +1 -1
- package/src/internal/appear.ts +9 -4
- package/src/internal/clock.ts +3 -0
- package/src/internal/reorder.ts +1 -1
- package/src/unstable/AppearAnimations.ts +21 -3
- package/src/unstable/DragDefaults.ts +9 -9
- package/src/unstable/DragTrack.ts +21 -0
- package/src/unstable/ElementSetup.ts +14 -1
- package/src/unstable/Feature.ts +9 -5
- package/src/unstable/GestureFeatures.ts +297 -3
- package/src/unstable/Imperative.ts +45 -13
- package/src/unstable/InstanceFeatures.ts +82 -0
- package/src/unstable/ReorderInput.ts +143 -0
- package/src/unstable/WardConfig.ts +2 -2
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A **Wardic instance**'s Features (#516, ADR-0067 *Amendment (#516)*), for every binding: what
|
|
3
|
+
* Solid's `createWardic` and Foldkit's `Wardic.make` split their list into, and what their elements take
|
|
4
|
+
* in each provider: those given at once, flattened, each once, and each load (`() => import(…)`), started
|
|
5
|
+
* once per instance the first time any provider asks, so one module's instance loads each once. In a
|
|
6
|
+
* module only the makers import, apart from the spine every page shares, so an app with no Wardic
|
|
7
|
+
* instance ships none of it (ADR-0067, *Amendment (#548)*).
|
|
8
|
+
*
|
|
9
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
10
|
+
*
|
|
11
|
+
* @module
|
|
12
|
+
*/
|
|
13
|
+
// Unstable: ADR-0071, decision 5. #793 (PR 1's review): solid's `instance-features.ts`, moved to dom for
|
|
14
|
+
// the Foldkit binding's loads (Q15).
|
|
15
|
+
import * as Arr from "effect/Array"
|
|
16
|
+
import * as Bool from "effect/Boolean"
|
|
17
|
+
import type * as Cause from "effect/Cause"
|
|
18
|
+
import { constVoid, identity } from "effect/Function"
|
|
19
|
+
import * as Predicate from "effect/Predicate"
|
|
20
|
+
import * as UndefinedOr from "effect/UndefinedOr"
|
|
21
|
+
import * as Feature from "./Feature.ts"
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* `prop`'s Features (#516): those given at once, flattened, each once, and its loads, each started once,
|
|
25
|
+
* the first time any provider asks, so one module's Wardic instance loads each once.
|
|
26
|
+
*/
|
|
27
|
+
export const instanceFeaturesOf = (prop: Feature.InstanceFeaturesProp): Feature.InstanceFeatures => {
|
|
28
|
+
const leaves = leavesOf(prop)
|
|
29
|
+
const given = Arr.dedupeWith(Arr.filter(leaves, isFeature), (a, b) => a === b)
|
|
30
|
+
const loads = Arr.map(Arr.filter(leaves, isLoad), once)
|
|
31
|
+
const owns = new WeakMap<Feature.FeatureRegistry, Feature.Own>()
|
|
32
|
+
return {
|
|
33
|
+
own: (registry, host) =>
|
|
34
|
+
UndefinedOr.match(owns.get(registry), {
|
|
35
|
+
onDefined: identity,
|
|
36
|
+
onUndefined: () => {
|
|
37
|
+
const own = ownIn(registry.build, given, loads, host.report, { reactivity: host.reactivity, server: host.server, onCleanup: registry.onEnd })
|
|
38
|
+
owns.set(registry, own)
|
|
39
|
+
return own
|
|
40
|
+
},
|
|
41
|
+
}),
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** `prop`'s Features and loads, every list flattened. */
|
|
46
|
+
const leavesOf = (prop: Feature.InstanceFeaturesProp): ReadonlyArray<Feature.Feature | Feature.FeatureLoad> =>
|
|
47
|
+
Bool.match(Array.isArray(prop), {
|
|
48
|
+
onTrue: () => Arr.flatMap(prop as ReadonlyArray<Feature.InstanceFeaturesProp>, leavesOf),
|
|
49
|
+
onFalse: () => [prop as Feature.Feature | Feature.FeatureLoad],
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const isFeature = (leaf: Feature.Feature | Feature.FeatureLoad): leaf is Feature.Feature => Predicate.hasProperty(leaf, "layer")
|
|
53
|
+
|
|
54
|
+
const isLoad = (leaf: Feature.Feature | Feature.FeatureLoad): leaf is Feature.FeatureLoad => Predicate.isFunction(leaf)
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* `load`, started at its first call, its promise kept for every call after. A failed load is forgotten,
|
|
58
|
+
* so the next provider to ask loads again, as a new `LazyWardic` does.
|
|
59
|
+
*/
|
|
60
|
+
const once = (load: Feature.FeatureLoad): Feature.FeatureLoad => {
|
|
61
|
+
let started: Promise<Feature.Features> | undefined
|
|
62
|
+
return () =>
|
|
63
|
+
UndefinedOr.match(started, {
|
|
64
|
+
onDefined: identity,
|
|
65
|
+
onUndefined: () => {
|
|
66
|
+
const loading = load()
|
|
67
|
+
started = loading
|
|
68
|
+
loading.then(constVoid, () => {
|
|
69
|
+
if (started === loading) started = undefined
|
|
70
|
+
})
|
|
71
|
+
return loading
|
|
72
|
+
},
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/** A Wardic instance's Features in one provider: those given at once, and each load's, joined. */
|
|
77
|
+
const ownIn = (build: Feature.Build, given: ReadonlyArray<Feature.Feature>, loads: ReadonlyArray<Feature.FeatureLoad>, report: (cause: Cause.Cause<unknown>) => void, host: Feature.SectionHost): Feature.Own =>
|
|
78
|
+
Arr.reduce(
|
|
79
|
+
Arr.map(loads, (load) => Feature.ownOf(build, load, report, host)),
|
|
80
|
+
Feature.ownOf(build, given, report, host),
|
|
81
|
+
Feature.joinOwns,
|
|
82
|
+
)
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A Reorder item's input (ADR-0037), for every binding (#379): its keys, blurs and presses told to its
|
|
3
|
+
* driver by watches while a Scope is open, each inside its event, with no fiber at rest. Each binding
|
|
4
|
+
* runs it in the item's watch Scope (ADR-0055, *Amendment (#379)*). A Batch Reorder group's items (#712)
|
|
5
|
+
* are heard through the feeds over them instead, with no listener per item at rest.
|
|
6
|
+
*
|
|
7
|
+
* Unstable, for Wardic's own packages: public, with no semver promise.
|
|
8
|
+
*
|
|
9
|
+
* @module
|
|
10
|
+
*/
|
|
11
|
+
// Unstable: ADR-0071, decision 5. #793 (PR 3): solid's `reorder-input.ts`, moved to dom for the Foldkit binding's items too.
|
|
12
|
+
import * as InputFeed from "@wardic/core/InputFeed"
|
|
13
|
+
import * as InputSource from "@wardic/core/InputSource"
|
|
14
|
+
import type * as ReorderController from "../ReorderController.ts"
|
|
15
|
+
import * as Report from "../Report.ts"
|
|
16
|
+
import * as Bool from "effect/Boolean"
|
|
17
|
+
import * as Effect from "effect/Effect"
|
|
18
|
+
import * as Iter from "effect/Iterable"
|
|
19
|
+
import type * as Option from "effect/Option"
|
|
20
|
+
import * as Predicate from "effect/Predicate"
|
|
21
|
+
import type * as Scope from "effect/Scope"
|
|
22
|
+
import * as UndefinedOr from "effect/UndefinedOr"
|
|
23
|
+
|
|
24
|
+
/** A Primary pointer's down: a press the driver hears. */
|
|
25
|
+
const isPress = (event: InputSource.PointerLikeEvent): boolean => Bool.and(event.type === "down", InputSource.isPrimaryPointer(event))
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Watch an item's keys, blurs and presses for its driver (ADR-0037, #379) while the Scope is open: its
|
|
29
|
+
* keys inside their dispatch, so the reorder's `handle()` (the page's `preventDefault`) counts. A blur
|
|
30
|
+
* is judged after this task's own work, one scheduler hop on (#318): a reorder can blur the node it
|
|
31
|
+
* moves and puts focus back after (the driver's `keepFocus`). So `fork` runs that hop on the provider
|
|
32
|
+
* runtime, only when a blur happens, and a blur whose judging fails is reported. A throw from the
|
|
33
|
+
* driver inside an event goes to `onDefect`.
|
|
34
|
+
*/
|
|
35
|
+
export const watchItemInput = (
|
|
36
|
+
el: HTMLElement,
|
|
37
|
+
driver: ReorderController.ItemDriver,
|
|
38
|
+
fork: (effect: Effect.Effect<void>) => void,
|
|
39
|
+
onDefect: InputFeed.OnDefect,
|
|
40
|
+
): Effect.Effect<void, never, Scope.Scope | InputSource.InputSource> => {
|
|
41
|
+
const judgeBlur = judgedBlurOf(driver)
|
|
42
|
+
return Effect.gen(function* () {
|
|
43
|
+
const input = yield* InputSource.InputSource
|
|
44
|
+
yield* InputFeed.watch(input.keyboard(el), { on: (event) => driver.onKey(event), onDefect })
|
|
45
|
+
yield* InputFeed.watch(input.focus(el), {
|
|
46
|
+
on: (event) => {
|
|
47
|
+
// The item's own blur: one inside it (#439) leaves it focused.
|
|
48
|
+
if (Bool.and(event.type === "blur", event.fromTarget !== false)) fork(judgeBlur)
|
|
49
|
+
},
|
|
50
|
+
onDefect,
|
|
51
|
+
})
|
|
52
|
+
yield* InputFeed.watch(input.pointer(el), {
|
|
53
|
+
on: (event) => {
|
|
54
|
+
if (isPress(event)) driver.onPress()
|
|
55
|
+
},
|
|
56
|
+
onDefect,
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/** A blur judged after this task's own work, one scheduler hop on (#318); a judging that fails reported. */
|
|
62
|
+
const judgedBlurOf = (driver: ReorderController.ItemDriver): Effect.Effect<void> =>
|
|
63
|
+
Effect.andThen(Effect.yieldNow, Effect.sync(() => driver.onBlur())).pipe(
|
|
64
|
+
Effect.catchCause((cause) => Report.failure("wardic.reorder: judging an item's blur failed", cause)),
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
/** An InputSource's feed over many targets, or a defect naming it. */
|
|
68
|
+
const amongOf = <A>(feed: A | undefined, name: string): Effect.Effect<A> =>
|
|
69
|
+
UndefinedOr.match(feed, {
|
|
70
|
+
onUndefined: () => Effect.die(new Error(`wardic.reorder: the Environment's InputSource has no \`${name}\`, which a Batch Reorder group's items need`)),
|
|
71
|
+
onDefined: Effect.succeed,
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
/** What a Batch Reorder group's items' input is told to: each item's driver, and its presses (#712). */
|
|
75
|
+
export interface ItemsInputHandlers {
|
|
76
|
+
/** The driver of the item a target is, `undefined` for an item gone. */
|
|
77
|
+
readonly driverOf: (target: unknown) => ReorderController.ItemDriver | undefined
|
|
78
|
+
/** A Primary pointer went down on an item, after its driver heard it: the group's grab. */
|
|
79
|
+
readonly onPress: (target: unknown) => void
|
|
80
|
+
/** That press ended, released or cancelled, wherever it was. */
|
|
81
|
+
readonly onPressEnd: (target: unknown) => void
|
|
82
|
+
/** Runs a blur's judging, one scheduler hop on. */
|
|
83
|
+
readonly fork: (effect: Effect.Effect<void>) => void
|
|
84
|
+
readonly onDefect: InputFeed.OnDefect
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** A Primary pointer's release or cancel: a press's end the group hears. */
|
|
88
|
+
const isPressEnd = (event: InputSource.PointerLikeEvent): boolean => Bool.and(Bool.or(event.type === "up", event.type === "cancel"), InputSource.isPrimaryPointer(event))
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Watch a Batch Reorder group's items' keys, blurs and presses (#712, ADR-0072 decision 7, Q28) while the
|
|
92
|
+
* Scope is open, through the feeds over them: focus heard by `focusAmong`, and a focused item's own keys
|
|
93
|
+
* from its focus to its blur, as a Batch's press watch holds them (#460); presses by `pointerAmong`. So at
|
|
94
|
+
* rest no item listens. `memberOf` names the item a node is. Blurs are judged as {@link watchItemInput}'s are.
|
|
95
|
+
*/
|
|
96
|
+
export const watchItemsInputAmong: (
|
|
97
|
+
memberOf: (node: unknown) => Option.Option<unknown>,
|
|
98
|
+
handlers: ItemsInputHandlers,
|
|
99
|
+
) => Effect.Effect<void, never, Scope.Scope | InputSource.InputSource> = Effect.fnUntraced(function* (memberOf: (node: unknown) => Option.Option<unknown>, handlers: ItemsInputHandlers) {
|
|
100
|
+
const input = yield* InputSource.InputSource
|
|
101
|
+
const focusAmong = yield* amongOf(input.focusAmong, "focusAmong")
|
|
102
|
+
const pointerAmong = yield* amongOf(input.pointerAmong, "pointerAmong")
|
|
103
|
+
const { driverOf, onDefect } = handlers
|
|
104
|
+
// The focused items' keys, each open from its focus to its blur.
|
|
105
|
+
const focusedKeys = new Map<unknown, InputFeed.Switch>()
|
|
106
|
+
const closeKeys = (target: unknown): void => {
|
|
107
|
+
UndefinedOr.map(focusedKeys.get(target), (keysNow) => keysNow.close())
|
|
108
|
+
focusedKeys.delete(target)
|
|
109
|
+
}
|
|
110
|
+
const openKeys = (target: unknown): void => {
|
|
111
|
+
if (focusedKeys.has(target)) return
|
|
112
|
+
const driver = driverOf(target)
|
|
113
|
+
if (Predicate.isUndefined(driver)) return
|
|
114
|
+
const keysNow = InputFeed.switched(input.keyboard(target), (event) => driver.onKey(event), onDefect)
|
|
115
|
+
focusedKeys.set(target, keysNow)
|
|
116
|
+
keysNow.open()
|
|
117
|
+
}
|
|
118
|
+
yield* Effect.addFinalizer(() =>
|
|
119
|
+
Effect.sync(() => {
|
|
120
|
+
Iter.forEach(focusedKeys.values(), (keysNow) => keysNow.close())
|
|
121
|
+
focusedKeys.clear()
|
|
122
|
+
})
|
|
123
|
+
)
|
|
124
|
+
yield* InputFeed.watch(focusAmong(memberOf), {
|
|
125
|
+
on: ({ target, event }) => {
|
|
126
|
+
if (event.type === "focus") return openKeys(target)
|
|
127
|
+
closeKeys(target)
|
|
128
|
+
// The item's own blur: one inside it (#439) leaves it focused.
|
|
129
|
+
if (event.fromTarget === false) return
|
|
130
|
+
UndefinedOr.map(driverOf(target), (driver) => handlers.fork(judgedBlurOf(driver)))
|
|
131
|
+
},
|
|
132
|
+
onDefect,
|
|
133
|
+
})
|
|
134
|
+
yield* InputFeed.watch(pointerAmong(memberOf), {
|
|
135
|
+
on: ({ target, event }) => {
|
|
136
|
+
if (isPressEnd(event)) return handlers.onPressEnd(target)
|
|
137
|
+
if (Bool.not(isPress(event))) return
|
|
138
|
+
UndefinedOr.map(driverOf(target), (driver) => driver.onPress())
|
|
139
|
+
handlers.onPress(target)
|
|
140
|
+
},
|
|
141
|
+
onDefect,
|
|
142
|
+
})
|
|
143
|
+
})
|
|
@@ -10,8 +10,8 @@
|
|
|
10
10
|
* @module
|
|
11
11
|
*/
|
|
12
12
|
// Unstable: ADR-0071, decision 5. #672 (the build grill's Q24 A): solid's `config.ts`, its DOM half;
|
|
13
|
-
// its other half is core's `unstable/Config`. Solid's
|
|
14
|
-
//
|
|
13
|
+
// its other half is core's `unstable/Config`. Solid's entries re-export its types from here (#777), so
|
|
14
|
+
// they didn't change.
|
|
15
15
|
import type * as Box from "@wardic/core/Box"
|
|
16
16
|
import type * as Config from "@wardic/core/unstable/Config"
|
|
17
17
|
import type * as CSS from "csstype"
|