@wardic/dom 1.1.2 → 1.1.4
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/PagePoint.d.ts +43 -0
- package/dist/unstable/PagePoint.d.ts.map +1 -0
- package/dist/unstable/PagePoint.js +119 -0
- package/dist/unstable/PagePoint.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/PagePoint.ts +129 -0
- package/src/unstable/ReorderInput.ts +143 -0
|
@@ -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
|
+
})
|