@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.
Files changed (74) hide show
  1. package/dist/ReorderController.d.ts +12 -1
  2. package/dist/ReorderController.d.ts.map +1 -1
  3. package/dist/ReorderController.js +25 -2
  4. package/dist/ReorderController.js.map +1 -1
  5. package/dist/index.d.ts +1 -1
  6. package/dist/index.js +1 -1
  7. package/dist/internal/appear.d.ts +7 -2
  8. package/dist/internal/appear.d.ts.map +1 -1
  9. package/dist/internal/appear.js +2 -2
  10. package/dist/internal/appear.js.map +1 -1
  11. package/dist/internal/clock.d.ts +3 -0
  12. package/dist/internal/clock.d.ts.map +1 -1
  13. package/dist/internal/clock.js +3 -0
  14. package/dist/internal/clock.js.map +1 -1
  15. package/dist/internal/reorder.d.ts +3 -0
  16. package/dist/internal/reorder.d.ts.map +1 -1
  17. package/dist/internal/reorder.js +1 -1
  18. package/dist/internal/reorder.js.map +1 -1
  19. package/dist/unstable/AppearAnimations.d.ts +14 -1
  20. package/dist/unstable/AppearAnimations.d.ts.map +1 -1
  21. package/dist/unstable/AppearAnimations.js +16 -3
  22. package/dist/unstable/AppearAnimations.js.map +1 -1
  23. package/dist/unstable/DragDefaults.d.ts +6 -5
  24. package/dist/unstable/DragDefaults.d.ts.map +1 -1
  25. package/dist/unstable/DragDefaults.js +2 -6
  26. package/dist/unstable/DragDefaults.js.map +1 -1
  27. package/dist/unstable/DragTrack.d.ts +8 -0
  28. package/dist/unstable/DragTrack.d.ts.map +1 -1
  29. package/dist/unstable/DragTrack.js +17 -0
  30. package/dist/unstable/DragTrack.js.map +1 -1
  31. package/dist/unstable/ElementSetup.d.ts +8 -2
  32. package/dist/unstable/ElementSetup.d.ts.map +1 -1
  33. package/dist/unstable/ElementSetup.js +14 -2
  34. package/dist/unstable/ElementSetup.js.map +1 -1
  35. package/dist/unstable/Feature.d.ts +5 -4
  36. package/dist/unstable/Feature.d.ts.map +1 -1
  37. package/dist/unstable/Feature.js +7 -4
  38. package/dist/unstable/Feature.js.map +1 -1
  39. package/dist/unstable/GestureFeatures.d.ts +132 -3
  40. package/dist/unstable/GestureFeatures.d.ts.map +1 -1
  41. package/dist/unstable/GestureFeatures.js +189 -11
  42. package/dist/unstable/GestureFeatures.js.map +1 -1
  43. package/dist/unstable/Imperative.d.ts +11 -0
  44. package/dist/unstable/Imperative.d.ts.map +1 -1
  45. package/dist/unstable/Imperative.js +37 -7
  46. package/dist/unstable/Imperative.js.map +1 -1
  47. package/dist/unstable/InstanceFeatures.d.ts +7 -0
  48. package/dist/unstable/InstanceFeatures.d.ts.map +1 -0
  49. package/dist/unstable/InstanceFeatures.js +69 -0
  50. package/dist/unstable/InstanceFeatures.js.map +1 -0
  51. package/dist/unstable/PagePoint.d.ts +43 -0
  52. package/dist/unstable/PagePoint.d.ts.map +1 -0
  53. package/dist/unstable/PagePoint.js +119 -0
  54. package/dist/unstable/PagePoint.js.map +1 -0
  55. package/dist/unstable/ReorderInput.d.ts +45 -0
  56. package/dist/unstable/ReorderInput.d.ts.map +1 -0
  57. package/dist/unstable/ReorderInput.js +116 -0
  58. package/dist/unstable/ReorderInput.js.map +1 -0
  59. package/package.json +3 -3
  60. package/src/ReorderController.ts +34 -1
  61. package/src/index.ts +1 -1
  62. package/src/internal/appear.ts +9 -4
  63. package/src/internal/clock.ts +3 -0
  64. package/src/internal/reorder.ts +1 -1
  65. package/src/unstable/AppearAnimations.ts +21 -3
  66. package/src/unstable/DragDefaults.ts +9 -9
  67. package/src/unstable/DragTrack.ts +21 -0
  68. package/src/unstable/ElementSetup.ts +14 -1
  69. package/src/unstable/Feature.ts +9 -5
  70. package/src/unstable/GestureFeatures.ts +297 -3
  71. package/src/unstable/Imperative.ts +45 -13
  72. package/src/unstable/InstanceFeatures.ts +82 -0
  73. package/src/unstable/PagePoint.ts +129 -0
  74. 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
+ })