@wardic/dom 0.0.0-stage → 1.0.0-rc.10

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 (315) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +8 -2
  3. package/THIRD_PARTY_NOTICES.md +145 -0
  4. package/dist/Appear.d.ts +30 -0
  5. package/dist/Appear.d.ts.map +1 -0
  6. package/dist/Appear.js +31 -0
  7. package/dist/Appear.js.map +1 -0
  8. package/dist/Color.d.ts +14 -0
  9. package/dist/Color.d.ts.map +1 -0
  10. package/dist/Color.js +16 -0
  11. package/dist/Color.js.map +1 -0
  12. package/dist/DomAnnouncer.d.ts +13 -0
  13. package/dist/DomAnnouncer.d.ts.map +1 -0
  14. package/dist/DomAnnouncer.js +14 -0
  15. package/dist/DomAnnouncer.js.map +1 -0
  16. package/dist/DomBatch.d.ts +20 -0
  17. package/dist/DomBatch.d.ts.map +1 -0
  18. package/dist/DomBatch.js +23 -0
  19. package/dist/DomBatch.js.map +1 -0
  20. package/dist/DomClock.d.ts +11 -0
  21. package/dist/DomClock.d.ts.map +1 -0
  22. package/dist/DomClock.js +12 -0
  23. package/dist/DomClock.js.map +1 -0
  24. package/dist/DomDefaultTransition.d.ts +12 -0
  25. package/dist/DomDefaultTransition.d.ts.map +1 -0
  26. package/dist/DomDefaultTransition.js +13 -0
  27. package/dist/DomDefaultTransition.js.map +1 -0
  28. package/dist/DomInput.d.ts +14 -0
  29. package/dist/DomInput.d.ts.map +1 -0
  30. package/dist/DomInput.js +17 -0
  31. package/dist/DomInput.js.map +1 -0
  32. package/dist/DomInterpolators.d.ts +13 -0
  33. package/dist/DomInterpolators.d.ts.map +1 -0
  34. package/dist/DomInterpolators.js +14 -0
  35. package/dist/DomInterpolators.js.map +1 -0
  36. package/dist/DomKeyRules.d.ts +13 -0
  37. package/dist/DomKeyRules.d.ts.map +1 -0
  38. package/dist/DomKeyRules.js +14 -0
  39. package/dist/DomKeyRules.js.map +1 -0
  40. package/dist/DomPositionalKeys.d.ts +13 -0
  41. package/dist/DomPositionalKeys.d.ts.map +1 -0
  42. package/dist/DomPositionalKeys.js +14 -0
  43. package/dist/DomPositionalKeys.js.map +1 -0
  44. package/dist/DomProbe.d.ts +13 -0
  45. package/dist/DomProbe.d.ts.map +1 -0
  46. package/dist/DomProbe.js +14 -0
  47. package/dist/DomProbe.js.map +1 -0
  48. package/dist/DomProjectionSystem.d.ts +28 -0
  49. package/dist/DomProjectionSystem.d.ts.map +1 -0
  50. package/dist/DomProjectionSystem.js +41 -0
  51. package/dist/DomProjectionSystem.js.map +1 -0
  52. package/dist/DomRenderer.d.ts +13 -0
  53. package/dist/DomRenderer.d.ts.map +1 -0
  54. package/dist/DomRenderer.js +15 -0
  55. package/dist/DomRenderer.js.map +1 -0
  56. package/dist/DomScrollSource.d.ts +14 -0
  57. package/dist/DomScrollSource.d.ts.map +1 -0
  58. package/dist/DomScrollSource.js +15 -0
  59. package/dist/DomScrollSource.js.map +1 -0
  60. package/dist/FlushGate.d.ts +48 -0
  61. package/dist/FlushGate.d.ts.map +1 -0
  62. package/dist/FlushGate.js +62 -0
  63. package/dist/FlushGate.js.map +1 -0
  64. package/dist/KeyboardPress.d.ts +16 -0
  65. package/dist/KeyboardPress.d.ts.map +1 -0
  66. package/dist/KeyboardPress.js +17 -0
  67. package/dist/KeyboardPress.js.map +1 -0
  68. package/dist/MeasuredPair.d.ts +14 -0
  69. package/dist/MeasuredPair.d.ts.map +1 -0
  70. package/dist/MeasuredPair.js +16 -0
  71. package/dist/MeasuredPair.js.map +1 -0
  72. package/dist/OwnValues.d.ts +14 -0
  73. package/dist/OwnValues.d.ts.map +1 -0
  74. package/dist/OwnValues.js +15 -0
  75. package/dist/OwnValues.js.map +1 -0
  76. package/dist/ProjectionSystem.d.ts +34 -0
  77. package/dist/ProjectionSystem.d.ts.map +1 -0
  78. package/dist/ProjectionSystem.js +29 -0
  79. package/dist/ProjectionSystem.js.map +1 -0
  80. package/dist/ReorderController.d.ts +61 -0
  81. package/dist/ReorderController.d.ts.map +1 -0
  82. package/dist/ReorderController.js +78 -0
  83. package/dist/ReorderController.js.map +1 -0
  84. package/dist/Report.d.ts +12 -0
  85. package/dist/Report.d.ts.map +1 -0
  86. package/dist/Report.js +13 -0
  87. package/dist/Report.js.map +1 -0
  88. package/dist/ScrollOffset.d.ts +34 -0
  89. package/dist/ScrollOffset.d.ts.map +1 -0
  90. package/dist/ScrollOffset.js +42 -0
  91. package/dist/ScrollOffset.js.map +1 -0
  92. package/dist/Style.d.ts +15 -0
  93. package/dist/Style.d.ts.map +1 -0
  94. package/dist/Style.js +17 -0
  95. package/dist/Style.js.map +1 -0
  96. package/dist/Svg.d.ts +13 -0
  97. package/dist/Svg.d.ts.map +1 -0
  98. package/dist/Svg.js +14 -0
  99. package/dist/Svg.js.map +1 -0
  100. package/dist/Variables.d.ts +13 -0
  101. package/dist/Variables.d.ts.map +1 -0
  102. package/dist/Variables.js +14 -0
  103. package/dist/Variables.js.map +1 -0
  104. package/dist/index.d.ts +83 -0
  105. package/dist/index.d.ts.map +1 -0
  106. package/dist/index.js +71 -0
  107. package/dist/index.js.map +1 -0
  108. package/dist/internal/announcer.d.ts +50 -0
  109. package/dist/internal/announcer.d.ts.map +1 -0
  110. package/dist/internal/announcer.js +115 -0
  111. package/dist/internal/announcer.js.map +1 -0
  112. package/dist/internal/appear-slot.d.ts +23 -0
  113. package/dist/internal/appear-slot.d.ts.map +1 -0
  114. package/dist/internal/appear-slot.js +29 -0
  115. package/dist/internal/appear-slot.js.map +1 -0
  116. package/dist/internal/appear.d.ts +237 -0
  117. package/dist/internal/appear.d.ts.map +1 -0
  118. package/dist/internal/appear.js +740 -0
  119. package/dist/internal/appear.js.map +1 -0
  120. package/dist/internal/auto-scroll.d.ts +24 -0
  121. package/dist/internal/auto-scroll.d.ts.map +1 -0
  122. package/dist/internal/auto-scroll.js +124 -0
  123. package/dist/internal/auto-scroll.js.map +1 -0
  124. package/dist/internal/batch-writer.d.ts +16 -0
  125. package/dist/internal/batch-writer.d.ts.map +1 -0
  126. package/dist/internal/batch-writer.js +77 -0
  127. package/dist/internal/batch-writer.js.map +1 -0
  128. package/dist/internal/clock.d.ts +19 -0
  129. package/dist/internal/clock.d.ts.map +1 -0
  130. package/dist/internal/clock.js +39 -0
  131. package/dist/internal/clock.js.map +1 -0
  132. package/dist/internal/colors.d.ts +45 -0
  133. package/dist/internal/colors.d.ts.map +1 -0
  134. package/dist/internal/colors.js +193 -0
  135. package/dist/internal/colors.js.map +1 -0
  136. package/dist/internal/complex.d.ts +24 -0
  137. package/dist/internal/complex.d.ts.map +1 -0
  138. package/dist/internal/complex.js +28 -0
  139. package/dist/internal/complex.js.map +1 -0
  140. package/dist/internal/content-watch.d.ts +20 -0
  141. package/dist/internal/content-watch.d.ts.map +1 -0
  142. package/dist/internal/content-watch.js +76 -0
  143. package/dist/internal/content-watch.js.map +1 -0
  144. package/dist/internal/default-transition.d.ts +25 -0
  145. package/dist/internal/default-transition.d.ts.map +1 -0
  146. package/dist/internal/default-transition.js +41 -0
  147. package/dist/internal/default-transition.js.map +1 -0
  148. package/dist/internal/drag-defaults.d.ts +18 -0
  149. package/dist/internal/drag-defaults.d.ts.map +1 -0
  150. package/dist/internal/drag-defaults.js +38 -0
  151. package/dist/internal/drag-defaults.js.map +1 -0
  152. package/dist/internal/gate.d.ts +188 -0
  153. package/dist/internal/gate.d.ts.map +1 -0
  154. package/dist/internal/gate.js +458 -0
  155. package/dist/internal/gate.js.map +1 -0
  156. package/dist/internal/input.d.ts +35 -0
  157. package/dist/internal/input.d.ts.map +1 -0
  158. package/dist/internal/input.js +658 -0
  159. package/dist/internal/input.js.map +1 -0
  160. package/dist/internal/interpolators.d.ts +19 -0
  161. package/dist/internal/interpolators.d.ts.map +1 -0
  162. package/dist/internal/interpolators.js +30 -0
  163. package/dist/internal/interpolators.js.map +1 -0
  164. package/dist/internal/key-rules.d.ts +11 -0
  165. package/dist/internal/key-rules.d.ts.map +1 -0
  166. package/dist/internal/key-rules.js +244 -0
  167. package/dist/internal/key-rules.js.map +1 -0
  168. package/dist/internal/keyboard-press.d.ts +7 -0
  169. package/dist/internal/keyboard-press.d.ts.map +1 -0
  170. package/dist/internal/keyboard-press.js +45 -0
  171. package/dist/internal/keyboard-press.js.map +1 -0
  172. package/dist/internal/measure.d.ts +157 -0
  173. package/dist/internal/measure.d.ts.map +1 -0
  174. package/dist/internal/measure.js +296 -0
  175. package/dist/internal/measure.js.map +1 -0
  176. package/dist/internal/measured-pairs.d.ts +38 -0
  177. package/dist/internal/measured-pairs.d.ts.map +1 -0
  178. package/dist/internal/measured-pairs.js +251 -0
  179. package/dist/internal/measured-pairs.js.map +1 -0
  180. package/dist/internal/own-values.d.ts +35 -0
  181. package/dist/internal/own-values.d.ts.map +1 -0
  182. package/dist/internal/own-values.js +117 -0
  183. package/dist/internal/own-values.js.map +1 -0
  184. package/dist/internal/pass-ends.d.ts +21 -0
  185. package/dist/internal/pass-ends.d.ts.map +1 -0
  186. package/dist/internal/pass-ends.js +14 -0
  187. package/dist/internal/pass-ends.js.map +1 -0
  188. package/dist/internal/positional-keys.d.ts +16 -0
  189. package/dist/internal/positional-keys.d.ts.map +1 -0
  190. package/dist/internal/positional-keys.js +21 -0
  191. package/dist/internal/positional-keys.js.map +1 -0
  192. package/dist/internal/probe.d.ts +10 -0
  193. package/dist/internal/probe.d.ts.map +1 -0
  194. package/dist/internal/probe.js +116 -0
  195. package/dist/internal/probe.js.map +1 -0
  196. package/dist/internal/projection-defaults.d.ts +34 -0
  197. package/dist/internal/projection-defaults.d.ts.map +1 -0
  198. package/dist/internal/projection-defaults.js +21 -0
  199. package/dist/internal/projection-defaults.js.map +1 -0
  200. package/dist/internal/projection.d.ts +537 -0
  201. package/dist/internal/projection.d.ts.map +1 -0
  202. package/dist/internal/projection.js +5228 -0
  203. package/dist/internal/projection.js.map +1 -0
  204. package/dist/internal/renderer.d.ts +104 -0
  205. package/dist/internal/renderer.d.ts.map +1 -0
  206. package/dist/internal/renderer.js +618 -0
  207. package/dist/internal/renderer.js.map +1 -0
  208. package/dist/internal/reorder.d.ts +174 -0
  209. package/dist/internal/reorder.d.ts.map +1 -0
  210. package/dist/internal/reorder.js +466 -0
  211. package/dist/internal/reorder.js.map +1 -0
  212. package/dist/internal/report.d.ts +30 -0
  213. package/dist/internal/report.d.ts.map +1 -0
  214. package/dist/internal/report.js +60 -0
  215. package/dist/internal/report.js.map +1 -0
  216. package/dist/internal/require-global.d.ts +11 -0
  217. package/dist/internal/require-global.d.ts.map +1 -0
  218. package/dist/internal/require-global.js +31 -0
  219. package/dist/internal/require-global.js.map +1 -0
  220. package/dist/internal/reveal.d.ts +20 -0
  221. package/dist/internal/reveal.d.ts.map +1 -0
  222. package/dist/internal/reveal.js +71 -0
  223. package/dist/internal/reveal.js.map +1 -0
  224. package/dist/internal/runner.d.ts +21 -0
  225. package/dist/internal/runner.d.ts.map +1 -0
  226. package/dist/internal/runner.js +48 -0
  227. package/dist/internal/runner.js.map +1 -0
  228. package/dist/internal/scale-correction.d.ts +80 -0
  229. package/dist/internal/scale-correction.d.ts.map +1 -0
  230. package/dist/internal/scale-correction.js +227 -0
  231. package/dist/internal/scale-correction.js.map +1 -0
  232. package/dist/internal/scroll.d.ts +37 -0
  233. package/dist/internal/scroll.d.ts.map +1 -0
  234. package/dist/internal/scroll.js +279 -0
  235. package/dist/internal/scroll.js.map +1 -0
  236. package/dist/internal/scrollers.d.ts +35 -0
  237. package/dist/internal/scrollers.d.ts.map +1 -0
  238. package/dist/internal/scrollers.js +38 -0
  239. package/dist/internal/scrollers.js.map +1 -0
  240. package/dist/internal/starting-style.d.ts +141 -0
  241. package/dist/internal/starting-style.d.ts.map +1 -0
  242. package/dist/internal/starting-style.js +300 -0
  243. package/dist/internal/starting-style.js.map +1 -0
  244. package/dist/internal/svg.d.ts +60 -0
  245. package/dist/internal/svg.d.ts.map +1 -0
  246. package/dist/internal/svg.js +257 -0
  247. package/dist/internal/svg.js.map +1 -0
  248. package/dist/internal/variables.d.ts +45 -0
  249. package/dist/internal/variables.d.ts.map +1 -0
  250. package/dist/internal/variables.js +92 -0
  251. package/dist/internal/variables.js.map +1 -0
  252. package/package.json +65 -4
  253. package/src/Appear.ts +54 -0
  254. package/src/Color.ts +24 -0
  255. package/src/DomAnnouncer.ts +22 -0
  256. package/src/DomBatch.ts +22 -0
  257. package/src/DomClock.ts +13 -0
  258. package/src/DomDefaultTransition.ts +16 -0
  259. package/src/DomInput.ts +23 -0
  260. package/src/DomInterpolators.ts +16 -0
  261. package/src/DomKeyRules.ts +17 -0
  262. package/src/DomPositionalKeys.ts +16 -0
  263. package/src/DomProbe.ts +15 -0
  264. package/src/DomProjectionSystem.ts +44 -0
  265. package/src/DomRenderer.ts +26 -0
  266. package/src/DomScrollSource.ts +14 -0
  267. package/src/FlushGate.ts +81 -0
  268. package/src/KeyboardPress.ts +16 -0
  269. package/src/MeasuredPair.ts +15 -0
  270. package/src/OwnValues.ts +19 -0
  271. package/src/ProjectionSystem.ts +51 -0
  272. package/src/ReorderController.ts +122 -0
  273. package/src/Report.ts +17 -0
  274. package/src/ScrollOffset.ts +54 -0
  275. package/src/Style.ts +37 -0
  276. package/src/Svg.ts +21 -0
  277. package/src/Variables.ts +17 -0
  278. package/src/index.ts +120 -0
  279. package/src/internal/announcer.ts +132 -0
  280. package/src/internal/appear-slot.ts +32 -0
  281. package/src/internal/appear.ts +1134 -0
  282. package/src/internal/auto-scroll.ts +176 -0
  283. package/src/internal/batch-writer.ts +95 -0
  284. package/src/internal/clock.ts +45 -0
  285. package/src/internal/colors.ts +258 -0
  286. package/src/internal/complex.ts +29 -0
  287. package/src/internal/content-watch.ts +84 -0
  288. package/src/internal/culori.d.ts +58 -0
  289. package/src/internal/default-transition.ts +50 -0
  290. package/src/internal/drag-defaults.ts +54 -0
  291. package/src/internal/gate.ts +598 -0
  292. package/src/internal/input.ts +763 -0
  293. package/src/internal/interpolators.ts +33 -0
  294. package/src/internal/key-rules.ts +357 -0
  295. package/src/internal/keyboard-press.ts +45 -0
  296. package/src/internal/measure.ts +373 -0
  297. package/src/internal/measured-pairs.ts +297 -0
  298. package/src/internal/own-values.ts +166 -0
  299. package/src/internal/pass-ends.ts +23 -0
  300. package/src/internal/positional-keys.ts +24 -0
  301. package/src/internal/probe.ts +175 -0
  302. package/src/internal/projection-defaults.ts +45 -0
  303. package/src/internal/projection.ts +6233 -0
  304. package/src/internal/renderer.ts +648 -0
  305. package/src/internal/reorder.ts +650 -0
  306. package/src/internal/report.ts +69 -0
  307. package/src/internal/require-global.ts +46 -0
  308. package/src/internal/reveal.ts +75 -0
  309. package/src/internal/runner.ts +64 -0
  310. package/src/internal/scale-correction.ts +310 -0
  311. package/src/internal/scroll.ts +358 -0
  312. package/src/internal/scrollers.ts +51 -0
  313. package/src/internal/starting-style.ts +396 -0
  314. package/src/internal/svg.ts +300 -0
  315. package/src/internal/variables.ts +145 -0
@@ -0,0 +1,174 @@
1
+ import type * as Drag from "@wardic/core/Drag";
2
+ import type * as InputSource from "@wardic/core/InputSource";
3
+ import * as Reorder from "@wardic/core/Reorder";
4
+ import * as Duration from "effect/Duration";
5
+ import * as Option from "effect/Option";
6
+ import { type Rect } from "./reveal.ts";
7
+ import type { Runner } from "./runner.ts";
8
+ /**
9
+ * The group element's style: no scroll anchoring, so the browser doesn't shift the
10
+ * page as items move (Motion's Group.tsx:187-195 at 16c6122). The user's style goes
11
+ * over it.
12
+ */
13
+ export declare const REORDER_GROUP_STYLE: Readonly<{
14
+ readonly "overflow-anchor": "none";
15
+ }>;
16
+ /**
17
+ * What {@link makeReorderController} runs on: the runner it logs through, how its items are laid out
18
+ * again and when they have been, and the Environment's `Announcer`. `ReorderController.make` wires
19
+ * them to the projection system its items are nodes of (#132's PR 3, ADR-0041); `makePlaced` to a
20
+ * binding that places its items itself, a Batch Reorder group's (#712, ADR-0072).
21
+ */
22
+ export interface ReorderControllerWiring {
23
+ /** The runner the controller logs through and waits in. */
24
+ readonly runtime: Runner<never>;
25
+ /** The app changed `values`: have the items laid out in it, a Measure pass, or nothing for items the binding places itself. */
26
+ readonly layOut: () => void;
27
+ /** Speak an **Announcement**: the Environment's `Announcer`. Left out, nothing is announced. */
28
+ readonly announce?: ((message: string) => void) | undefined;
29
+ /** Hears each time the items have been laid out: a Measure pass's end (the engine's `PassEnds`), or the binding's placing. */
30
+ readonly onLaidOut: (listener: () => void) => () => void;
31
+ }
32
+ /**
33
+ * What an item registers with its group: core's `ItemSource` (its box, its drag offset, its box's
34
+ * version), how to raise it over the rest while it's lifted, and, for an item placed rather than
35
+ * measured, its place on screen, for a keyboard step's reveal. A projection handle is one.
36
+ */
37
+ export interface ReorderItemHandle extends Reorder.ItemSource {
38
+ /** Raise the item over the rest, or let it down: a keyboard lift's. */
39
+ readonly setLifted: (lifted: boolean) => void;
40
+ /**
41
+ * Its place on screen, in client coordinates, which a keyboard step reveals once the items are laid
42
+ * out. Left out, its painted box with its own transform undone, a layout node's.
43
+ */
44
+ readonly placeOnScreen?: (() => Rect) | undefined;
45
+ }
46
+ /**
47
+ * A user's reorder that changed the order, at its end: a pointer drag released, or a keyboard lift
48
+ * dropped, with the item at another index than at its start. What an app saves: the whole order, or the
49
+ * one item that moved and where.
50
+ */
51
+ export interface ReorderEnd<V> {
52
+ /** The order at the end. */
53
+ readonly values: Array<V>;
54
+ /** The item the user moved: the one dragged, or lifted. */
55
+ readonly value: V;
56
+ /** Its index at the gesture's start. */
57
+ readonly from: number;
58
+ /** Its index at the end. */
59
+ readonly to: number;
60
+ }
61
+ /** A **Reorder hold**'s start: the item taken in hand, by its drag's start or a keyboard lift, and its index then. */
62
+ export interface ReorderHoldStart<V> {
63
+ /** The item taken in hand. */
64
+ readonly value: V;
65
+ /** Its index at the start. */
66
+ readonly from: number;
67
+ }
68
+ /**
69
+ * How a **Reorder hold** ended: `"drop"`, released or dropped where it is (a pointer's release or
70
+ * cancel, a drop key, focus leaving, a press, the app's `values`, another hold); `"cancel"`, Escape, the
71
+ * order put back; `"unmount"`, its item went away.
72
+ */
73
+ export type ReorderHoldHow = "drop" | "cancel" | "unmount";
74
+ /**
75
+ * A **Reorder hold**'s end, whatever ended it, once: the order then, the item, its index at the start
76
+ * and now (`-1` once it's out of the values), and how. After `onReorderEnd`, in the same task, when the
77
+ * order changed.
78
+ */
79
+ export interface ReorderHoldEnd<V> extends ReorderEnd<V> {
80
+ /** How it ended. */
81
+ readonly how: ReorderHoldHow;
82
+ }
83
+ /** What a binding hands its group's controller. */
84
+ export interface ReorderControllerOptions<V> {
85
+ /** The app's values, in order. */
86
+ readonly values: () => ReadonlyArray<V>;
87
+ /** Receives a new order; the app sets `values` from it. */
88
+ readonly onReorder: (values: Array<V>) => void;
89
+ /**
90
+ * Hears a user's reorder that changed the order, at its end: once a gesture, not at each step, as
91
+ * `onReorder` is. Not a keyboard cancel, which puts the order back, nor `move`.
92
+ */
93
+ readonly onReorderEnd?: ((end: ReorderEnd<V>) => void) | undefined;
94
+ /** Hears each **Reorder hold**'s start: a drag of an item past its threshold, or a keyboard lift. */
95
+ readonly onHoldStart?: ((start: ReorderHoldStart<V>) => void) | undefined;
96
+ /** Hears each **Reorder hold**'s end, once, whatever ended it; after `onReorderEnd` when it moved. */
97
+ readonly onHoldEnd?: ((end: ReorderHoldEnd<V>) => void) | undefined;
98
+ /** The app's axis, overriding detection; `None` to detect. */
99
+ readonly axis?: (() => Option.Option<Reorder.Axis>) | undefined;
100
+ /** Called when the detected axis changes (once the items are laid out, or {@link ReorderController.resolve}). */
101
+ readonly onAxis?: ((axis: Reorder.Axis) => void) | undefined;
102
+ /**
103
+ * How the binding keys its items, for the warning logged once per controller when an
104
+ * item registers with a value an item of this group unregistered in the same task
105
+ * (the signature of a list keyed by index): "key items with `keyedWith`". Solid's is
106
+ * `"<For>"`; by default "their value".
107
+ */
108
+ readonly keyedWith?: string | undefined;
109
+ /** Whether the items reorder by keyboard, read at each key; `false` turns it off. On when left out. */
110
+ readonly keyboard?: (() => boolean) | undefined;
111
+ /** The group's announcements over the defaults, read at each announcement. */
112
+ readonly announcements?: (() => Option.Option<Partial<Reorder.Announcements<V>>>) | undefined;
113
+ }
114
+ /** One item of a {@link ReorderController}: its binding feeds it the item's handle, drag samples, keys, focus and presses. */
115
+ export interface ReorderItemDriver {
116
+ /** Register the item's handle, a projection node's or a placed item's, with the group; returns the unregister. */
117
+ readonly register: (handle: ReorderItemHandle) => () => void;
118
+ /** The axis the item's drag takes, read at each gesture's start. */
119
+ readonly dragAxis: () => Reorder.Axis;
120
+ /** The item's drag samples, as the drag delivers them. */
121
+ readonly onSample: (sample: Drag.Sample) => void;
122
+ /** A key at the item or inside it, inside its dispatch: a keyboard reorder's. */
123
+ readonly onKey: (event: InputSource.KeyboardLikeEvent) => void;
124
+ /** Focus left the item: a lift drops where it is, unless focus is back on the item. */
125
+ readonly onBlur: () => void;
126
+ /** A press on the item: a lift drops where it is, before any drag. */
127
+ readonly onPress: () => void;
128
+ /** The item is going away: end a gesture or a lift still in progress. */
129
+ readonly dispose: () => void;
130
+ }
131
+ /** How long a held arrow's announcements wait for the next repeat: only the last is spoken (ADR-0037, Q4). */
132
+ export declare const REPEAT_ANNOUNCE: Duration.Duration;
133
+ /**
134
+ * A Reorder item's default instructions on the web: core's keys, and focus mode. A
135
+ * screen reader in browse mode (NVDA's, JAWS's) keeps Space and the arrows for itself until its user
136
+ * switches to focus mode, and it doesn't switch by itself on a list item.
137
+ */
138
+ export declare const DEFAULT_REORDER_INSTRUCTIONS = "Press Space or Enter to pick up. Use the arrow keys to move, Space or Enter to drop, Escape to cancel. Some screen readers need focus mode for these keys.";
139
+ /** A **Reorder group** on the DOM. */
140
+ export interface ReorderController<V> {
141
+ /** Core's Reorder group (`Reorder.move(group, value, toIndex)` reorders in code). */
142
+ readonly group: Reorder.Group<V>;
143
+ /** The app's axis, else the last detected one (`"y"` before the first). */
144
+ readonly axis: () => Reorder.Axis;
145
+ /** The group's element: its `direction`, and the scroller Auto-scroll looks for from it. */
146
+ readonly attach: (element: Element) => void;
147
+ /**
148
+ * The driver for the item with `value`; `element` is its element (for Auto-scroll, its label, its
149
+ * focus and its reveal), and `onLift` hears its keyboard lift start and end (the binding's `whileDrag`).
150
+ */
151
+ readonly item: (value: V, element: () => Option.Option<Element>, onLift?: (lifted: boolean) => void) => ReorderItemDriver;
152
+ /** Move `value` to `toIndex` in code (`Reorder.move`), and announce it. */
153
+ readonly move: (value: V, toIndex: number) => void;
154
+ /**
155
+ * The axis now: the app's, else detected from the items' boxes as they are, reporting nothing. A
156
+ * binding derives its axis with it when the app's is cleared.
157
+ */
158
+ readonly detect: () => Reorder.Axis;
159
+ /** The app's values changed: its items laid out in them (a Measure pass), so they animate to their new places. */
160
+ readonly valuesChanged: () => void;
161
+ /** Stops listening for the items' layouts and ends the auto-scroll. The Scope calls it. */
162
+ readonly dispose: () => void;
163
+ }
164
+ /** Build a {@link ReorderController}: a **Reorder group** over `wiring.projection`'s nodes. */
165
+ export declare const makeReorderController: <V>(wiring: ReorderControllerWiring, options: ReorderControllerOptions<V>) => ReorderController<V>;
166
+ /**
167
+ * A {@link ReorderController} for a server render (ADR-0021), where there's no projection
168
+ * system to drive and nothing to reorder: its group has no values, so every operation on it
169
+ * does nothing, the axis is `"y"`, and an item's driver is inert too. A binding's server path hands it to its group, so code
170
+ * that reads `group`, `move` or `controller` at setup works there. Tier 2, for binding
171
+ * authors.
172
+ */
173
+ export declare const INERT_REORDER_CONTROLLER: ReorderController<never>;
174
+ //# sourceMappingURL=reorder.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"reorder.d.ts","sourceRoot":"","sources":["../../src/internal/reorder.ts"],"names":[],"mappings":"AAuCA,OAAO,KAAK,KAAK,IAAI,MAAM,mBAAmB,CAAA;AAC9C,OAAO,KAAK,KAAK,WAAW,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,OAAO,MAAM,sBAAsB,CAAA;AAG/C,OAAO,KAAK,QAAQ,MAAM,iBAAiB,CAAA;AAO3C,OAAO,K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qFAAqF;IACrF,QAAQ,CAAC,KAAK,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,CAAA;IAChC,2EAA2E;IAC3E,QAAQ,CAAC,IAAI,EAAE,MAAM,OAAO,CAAC,IAAI,CAAA;IACjC,4FAA4F;IAC5F,QAAQ,CAAC,MAAM,EAAE,CAAC,OAAO,EAAE,OAAO,KAAK,IAAI,CAAA;IAC3C;;;OAGG;IACH,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,KAAK,IAAI,KAAK,iBAAiB,CAAA;IACzH,2EAA2E;IAE3E,QAAQ,CAAC,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,MAAM,KAAK,IAAI,CAAA;IAClD;;;OAGG;IAEH,QAAQ,CAAC,MAAM,EAAE,MAAM,OAAO,CAAC,IAAI,CAAA;IACnC,kHAAkH;IAClH,QAAQ,CAAC,aAAa,EAAE,MAAM,IAAI,CAAA;IAClC,2FAA2F;IAC3F,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CAC7B;AAED,+FAA+F;AAC/F,eAAO,MAAM,qBAAqB,GAAI,CAAC,UAAU,uBAAuB,WAAW,wBAAwB,CAAC,CAAC,CAAC,KAAG,iBAAiB,CAAC,CAAC,CAyWnI,CAAA;AAWD;;;;;;GAMG;AACH,eAAO,MAAM,wBAAwB,EAAE,iBAAiB,CAAC,KAAK,CAU5D,CAAA"}
@@ -0,0 +1,466 @@
1
+ /**
2
+ * The DOM's **Reorder group** controller (ADR-0020): the framework-free half of
3
+ * `<Reorder>`, shared by every DOM binding. A binding adds only its reactivity, its
4
+ * lifecycle and its elements.
5
+ *
6
+ * It owns core's `Reorder.Group` (the **Crossover** and the new order), reads the
7
+ * group element's `direction` at each drag start, builds the group's **Auto-scroll**,
8
+ * and routes each item's drag samples: the start opens the group's gesture, each move
9
+ * runs the Crossover and Auto-scroll, the end (or the item's disposal mid-gesture)
10
+ * closes both. The items' `touch-action` needs the axis before a touch starts, so after
11
+ * the items are laid out (a Measure pass, or a placed group's placing) the controller detects the axis from the items' boxes and reports
12
+ * a change through `onAxis`; while the app sets the axis it detects nothing. Motion
13
+ * detects on every item's every measurement (Group.tsx:121-133 at 16c6122). When the app
14
+ * clears its axis, no Measure pass comes with that: a binding reads `detect()`, the axis
15
+ * from the boxes the items have now, in the computation that derives its axis, so whatever
16
+ * reads the axis follows in the same update (#257's audit: an effect that detected and
17
+ * reported it updated them a step late).
18
+ *
19
+ * It also runs each item's **Keyboard reorder** (ADR-0037), on by default: a key from the item
20
+ * itself that the page didn't take (Space or Enter lifts and drops, Escape cancels, the arrows,
21
+ * Home and End move the lifted item) goes to core's `Reorder` model, its default prevented; each
22
+ * step is an **Announcement** (a held arrow's thinned to the last), scrolls the item's new place
23
+ * into view once the items are laid out again, and keeps focus on the item; the lifted node is
24
+ * raised as a dragged one is, and the binding turns its `whileDrag` on. Focus leaving the item, a
25
+ * press on it, or the app changing `values` drops it where it is; its unmount ends the lift unsaid.
26
+ *
27
+ * Each **Reorder hold** (#348, ADR-0020 *Amendment (#348)*), an item in a user's hand from its drag's start or
28
+ * its lift, is told at its start and, once, at its end, whatever ends it: after `onReorderEnd`, when
29
+ * it moved. One at a time: a hold's start ends the open one first, and that item's later release
30
+ * tells nothing more.
31
+ * `move` announces too. Nothing is announced without an `announce`.
32
+ *
33
+ * Observability: `wardic.reorder:` debug logs through the runtime, annotated: the
34
+ * group's and Auto-scroll's events, and `axis` when the detected axis changes (cold
35
+ * path: never per sample), plus one warning per controller for a remount (below).
36
+ *
37
+ * Tier 2 (ADR-0008): for DOM binding authors.
38
+ */
39
+ import * as AutoScroll from "@wardic/core/AutoScroll";
40
+ import * as Reorder from "@wardic/core/Reorder";
41
+ import * as Arr from "effect/Array";
42
+ import * as Bool from "effect/Boolean";
43
+ import * as Duration from "effect/Duration";
44
+ import * as Effect from "effect/Effect";
45
+ import * as Equivalence from "effect/Equivalence";
46
+ import * as FiberHandle from "effect/FiberHandle";
47
+ import { constFalse, constTrue, constVoid, identity } from "effect/Function";
48
+ import * as Match from "effect/Match";
49
+ import * as MutableRef from "effect/MutableRef";
50
+ import * as Option from "effect/Option";
51
+ import * as Predicate from "effect/Predicate";
52
+ import * as Scope from "effect/Scope";
53
+ import * as Str from "effect/String";
54
+ import * as UndefinedOr from "effect/UndefinedOr";
55
+ import { documentOf, prepareAnnouncer } from "./announcer.js";
56
+ import { makeAutoScroller } from "./auto-scroll.js";
57
+ import { debugOf } from "./report.js";
58
+ import { revealLayoutOf, revealRectOf } from "./reveal.js";
59
+ /**
60
+ * The group element's style: no scroll anchoring, so the browser doesn't shift the
61
+ * page as items move (Motion's Group.tsx:187-195 at 16c6122). The user's style goes
62
+ * over it.
63
+ */
64
+ export const REORDER_GROUP_STYLE = Object.freeze({ "overflow-anchor": "none" });
65
+ /** How long a held arrow's announcements wait for the next repeat: only the last is spoken (ADR-0037, Q4). */
66
+ export const REPEAT_ANNOUNCE = Duration.millis(150);
67
+ /**
68
+ * A Reorder item's default instructions on the web: core's keys, and focus mode. A
69
+ * screen reader in browse mode (NVDA's, JAWS's) keeps Space and the arrows for itself until its user
70
+ * switches to focus mode, and it doesn't switch by itself on a list item.
71
+ */
72
+ // ADR-0037: the NVDA pass.
73
+ export const DEFAULT_REORDER_INSTRUCTIONS = `${Reorder.DEFAULT_INSTRUCTIONS} Some screen readers need focus mode for these keys.`;
74
+ /** How an item is spoken: its `aria-label`, else its text with its whitespace collapsed, else its value. */
75
+ const labelOf = (element, value) => Option.getOrElse(Option.orElse(Option.flatMap(element, (el) => nonEmpty(Option.map(Option.fromNullOr(el.getAttribute("aria-label")), Str.trim))), () => Option.flatMap(element, (el) => nonEmpty(Option.map(Option.fromNullOr(el.textContent), (text) => text.replace(/\s+/g, " ").trim())))), () => String(value));
76
+ /** A text, `None` when it's empty. */
77
+ const nonEmpty = (text) => Option.filter(text, Str.isNonEmpty);
78
+ /** Build a {@link ReorderController}: a **Reorder group** over `wiring.projection`'s nodes. */
79
+ export const makeReorderController = (wiring, options) => {
80
+ const { runtime, announce } = wiring;
81
+ const debug = debugOf(runtime, "wardic.reorder");
82
+ // Speak an Announcement, or nothing without an `announce`.
83
+ const speak = UndefinedOr.match(announce, { onUndefined: () => constVoid, onDefined: identity });
84
+ const keyboardOn = () => UndefinedOr.match(options.keyboard, { onUndefined: constTrue, onDefined: (on) => on() });
85
+ // The group's element and its Auto-scroll, once it's attached.
86
+ const element = MutableRef.make(Option.none());
87
+ const autoScroller = MutableRef.make(Option.none());
88
+ const resetAutoScroll = () => {
89
+ const scroller = MutableRef.get(autoScroller);
90
+ if (Option.isSome(scroller))
91
+ scroller.value.reset();
92
+ };
93
+ // The order the group last asked for: a `values` change to anything else is the app's own (ADR-0037).
94
+ let asked;
95
+ /** The app's axis, if it sets one. */
96
+ const appAxis = () => Option.flatMap(Option.fromUndefinedOr(options.axis), (axis) => axis());
97
+ const group = Reorder.make({
98
+ values: options.values,
99
+ onReorder: (values) => {
100
+ // A copy of what it hands on: an app that keeps that array, a store's own, may change it in place (#721).
101
+ asked = Arr.copy(values);
102
+ options.onReorder(values);
103
+ },
104
+ axis: () => appAxis(),
105
+ // Read once per drag start (Motion reads it on every sample, Group.tsx:142-147 at 16c6122).
106
+ direction: () => Bool.match(Option.exists(MutableRef.get(element), (el) => getComputedStyle(el).direction === "rtl"), {
107
+ onTrue: () => "rtl",
108
+ onFalse: () => "ltr",
109
+ }),
110
+ debug,
111
+ });
112
+ let detected = "y";
113
+ let reported;
114
+ const resolve = () => {
115
+ if (Option.isSome(appAxis()))
116
+ return;
117
+ detected = Reorder.resolveAxis(group);
118
+ if (detected === reported)
119
+ return;
120
+ reported = detected;
121
+ debug("axis", { axis: detected });
122
+ if (Predicate.isNotUndefined(options.onAxis))
123
+ options.onAxis(detected);
124
+ };
125
+ const keyed = new Map();
126
+ const keyedOf = (value) => Option.fromUndefinedOr(keyed.get(value));
127
+ const elementOf = (value) => Option.flatMap(keyedOf(value), (k) => k.element());
128
+ // The item whose new place the next layout lays out, to scroll into view then.
129
+ const reveal = MutableRef.make(Option.none());
130
+ // A held arrow's latest announcement, waiting for the next repeat (ADR-0025, *Amendment (#69)*): a
131
+ // fiber in the Scope the controller was built in, which closes it after `dispose`.
132
+ const pending = runtime.runSync(FiberHandle.make().pipe(Scope.provide(runtime.scope)));
133
+ const announceNow = (message) => {
134
+ runtime.runFork(FiberHandle.clear(pending));
135
+ speak(message);
136
+ };
137
+ /** A held arrow's step: spoken once the repeats stop for {@link REPEAT_ANNOUNCE}, only the last. */
138
+ const announceLater = (message) => {
139
+ FiberHandle.setUnsafe(pending, runtime.runFork(Effect.sleep(REPEAT_ANNOUNCE).pipe(Effect.andThen(Effect.sync(() => speak(message))))));
140
+ };
141
+ const wording = () => ({
142
+ ...Reorder.defaultAnnouncements,
143
+ ...Option.getOrUndefined(Option.flatMap(Option.fromUndefinedOr(options.announcements), (announcements) => announcements())),
144
+ });
145
+ const say = (kind, value, placement) => wording()[kind]({ value, label: labelOf(elementOf(value), value), position: placement.position, count: placement.count });
146
+ /** Raise the lifted item (or lower it) and tell its binding (its `whileDrag`). */
147
+ const setLifted = (value, lifted) => {
148
+ const k = keyed.get(value);
149
+ if (Predicate.isUndefined(k))
150
+ return;
151
+ if (Option.isSome(k.handle))
152
+ k.handle.value.setLifted(lifted);
153
+ k.onLift(lifted);
154
+ };
155
+ /** `value`'s index in the app's values now. */
156
+ const indexOf = (value) => options.values().indexOf(value);
157
+ /** The end of a user's reorder of `value`, begun at `from`: told when it moved (#257 item 3). */
158
+ const ended = (value, from) => {
159
+ const to = indexOf(value);
160
+ if (to === from)
161
+ return;
162
+ UndefinedOr.map(options.onReorderEnd, (tell) => tell({ values: [...options.values()], value, from, to }));
163
+ };
164
+ // --- Holds (#348) ------------------------------------------------------------
165
+ /** The open **Reorder hold**: the item in hand, how it was taken, and its index then. One at a time. */
166
+ let held = Option.none();
167
+ /** Whether `value`'s drag is the open hold: a drag a later hold took over tells nothing more. */
168
+ const holdsDrag = (value) => Option.exists(held, (h) => h.by === "drag" && h.value === value);
169
+ const holdStart = (value, from, by) => {
170
+ held = Option.some({ value, from, by });
171
+ UndefinedOr.map(options.onHoldStart, (tell) => tell({ value, from }));
172
+ };
173
+ /** End `value`'s hold, `how`: told once, and only for the open one. */
174
+ const holdEnd = (value, how) => Option.match(Option.filter(held, (h) => h.value === value), {
175
+ onNone: constVoid,
176
+ onSome: (h) => {
177
+ held = Option.none();
178
+ UndefinedOr.map(options.onHoldEnd, (tell) => tell({ values: [...options.values()], value, from: h.from, to: indexOf(value), how }));
179
+ },
180
+ });
181
+ /** The lifted item's index at its lift. */
182
+ let liftedFrom = -1;
183
+ /** Drop the lifted item where it is and announce it: a drop key, or an interruption. */
184
+ const dropLifted = () => Option.match(Reorder.liftedValue(group), {
185
+ onNone: constVoid,
186
+ onSome: (value) => {
187
+ Option.match(Reorder.drop(group, value), { onNone: constVoid, onSome: (placement) => announceNow(say("drop", value, placement)) });
188
+ setLifted(value, false);
189
+ ended(value, liftedFrom);
190
+ holdEnd(value, "drop");
191
+ },
192
+ });
193
+ /**
194
+ * A drag's start ends the open hold first (#348, one at a time): a lift is dropped where it is,
195
+ * and another item's drag ends, told as if released, its own release telling nothing more.
196
+ */
197
+ const endHeld = () => Option.match(held, {
198
+ onNone: constVoid,
199
+ onSome: (h) => {
200
+ if (h.by === "lift")
201
+ return dropLifted();
202
+ ended(h.value, h.from);
203
+ holdEnd(h.value, "drop");
204
+ },
205
+ });
206
+ /** Focus back on the lifted item, if a reorder took it (moving a focused node can blur it), without scrolling. */
207
+ const keepFocus = (value) => Option.match(Option.filter(elementOf(value), (el) => el.ownerDocument.activeElement !== el), {
208
+ onNone: constVoid,
209
+ onSome: (el) => el.focus({ preventScroll: true }),
210
+ });
211
+ /** Whether focus is on `value`'s element. */
212
+ const focused = (value) => Option.exists(elementOf(value), (el) => el.ownerDocument.activeElement === el);
213
+ const onKeyOf = (value) => (event) => {
214
+ if (event.type !== "down")
215
+ return;
216
+ if (Bool.not(keyboardOn()))
217
+ return;
218
+ // A key the page took, or one from inside the item (a text field), isn't the reorder's.
219
+ if (event.handled)
220
+ return;
221
+ if (Bool.not(event.fromTarget))
222
+ return;
223
+ // Keys during a pointer drag are left alone.
224
+ if (Reorder.isDragging(group))
225
+ return;
226
+ const lifted = Option.contains(Reorder.liftedValue(group), value);
227
+ Option.match(Reorder.keyIntent(event.key), {
228
+ onNone: constVoid,
229
+ onSome: (intent) => Match.value(intent).pipe(Match.tag("Toggle", () => {
230
+ event.handle();
231
+ if (event.repeat)
232
+ return;
233
+ if (lifted)
234
+ return dropLifted();
235
+ // Lifting another item drops the one lifted first.
236
+ dropLifted();
237
+ Option.match(Reorder.lift(group, value), {
238
+ onNone: constVoid,
239
+ onSome: (placement) => {
240
+ liftedFrom = indexOf(value);
241
+ // The values the lift began with are the group's own: a binding re-reading them,
242
+ // the same, mid-lift (a memo whose sources changed) isn't the app changing them (#348).
243
+ asked = options.values();
244
+ setLifted(value, true);
245
+ announceNow(say("lift", value, placement));
246
+ holdStart(value, liftedFrom, "lift");
247
+ },
248
+ });
249
+ }), Match.tag("Cancel", () => {
250
+ if (Bool.not(lifted))
251
+ return;
252
+ event.handle();
253
+ const placement = withReveal(value, () => Reorder.cancel(group, value));
254
+ Option.match(placement, {
255
+ onNone: constVoid,
256
+ onSome: (placement) => {
257
+ setLifted(value, false);
258
+ keepFocus(value);
259
+ announceNow(say("cancel", value, placement));
260
+ holdEnd(value, "cancel");
261
+ },
262
+ });
263
+ }), Match.tagsExhaustive({
264
+ Step: (step) => stepLifted(event, value, lifted, step),
265
+ End: (end) => stepLifted(event, value, lifted, end),
266
+ })),
267
+ });
268
+ };
269
+ /**
270
+ * `reorder`'s placement, `value`'s new place to be revealed once its items are laid out when it moved.
271
+ * Asked before the reorder: a binding that places its items as `onReorder` sets them (`makePlaced`'s, a
272
+ * Batch Reorder group's, #712) says they're laid out before the reorder returns. Moving nothing, the
273
+ * ask is taken back.
274
+ */
275
+ const withReveal = (value, reorder) => {
276
+ const before = MutableRef.get(reveal);
277
+ MutableRef.set(reveal, Option.some(value));
278
+ const placement = reorder();
279
+ const moved = Option.exists(placement, (p) => p.moved);
280
+ // Laid out within it, its reveal was taken: nothing to take back.
281
+ if (Bool.and(Bool.not(moved), Option.contains(MutableRef.get(reveal), value)))
282
+ MutableRef.set(reveal, before);
283
+ return placement;
284
+ };
285
+ /** An arrow, Home or End: the lifted item's step, its announcement (a held arrow's thinned), its reveal. */
286
+ const stepLifted = (event, value, lifted, intent) => {
287
+ // Not lifted, the arrows, Home and End keep their own work (scrolling the page).
288
+ if (Bool.not(lifted))
289
+ return;
290
+ event.handle();
291
+ Option.match(withReveal(value, () => Reorder.moveLifted(group, value, intent)), {
292
+ onNone: constVoid,
293
+ onSome: (placement) => {
294
+ // A repeat before the last step was laid out moved nothing: nothing to say.
295
+ if (placement.waiting)
296
+ return;
297
+ if (placement.moved)
298
+ keepFocus(value);
299
+ const message = say("step", value, placement);
300
+ Bool.match(event.repeat, { onTrue: () => announceLater(message), onFalse: () => announceNow(message) });
301
+ },
302
+ });
303
+ };
304
+ /** `value`'s element in view, connected: by its place on screen when its handle gives one, else by its layout box. */
305
+ const revealOf = (value) => {
306
+ const el = Option.filter(elementOf(value), (e) => e.isConnected);
307
+ if (Option.isNone(el))
308
+ return;
309
+ const place = Option.flatMap(Option.flatMap(keyedOf(value), (k) => k.handle), (handle) => Option.fromUndefinedOr(handle.placeOnScreen));
310
+ Option.match(place, { onNone: () => revealLayoutOf(el.value), onSome: (placeOf) => revealRectOf(el.value, placeOf()) });
311
+ };
312
+ // Every Measure pass measures every node, and a binding that places its items says when it has: either
313
+ // way the items are laid out, and a stepped item's new place with them.
314
+ const stopLaidOut = wiring.onLaidOut(() => {
315
+ resolve();
316
+ const stepped = MutableRef.get(reveal);
317
+ MutableRef.set(reveal, Option.none());
318
+ if (Option.isSome(stepped))
319
+ revealOf(stepped.value);
320
+ });
321
+ const keyedWith = UndefinedOr.match(options.keyedWith, { onUndefined: () => "their value", onDefined: identity });
322
+ // Values whose item unregistered in this task, and whether a remount was warned of.
323
+ const unregisteredThisTask = new Set();
324
+ let remountReported = false;
325
+ const item = (value, itemElement, onLift = constVoid) => {
326
+ // The gesture's axis (core's, fixed at its start), for Auto-scroll's axis.
327
+ let gestureAxis = "y";
328
+ let inGesture = false;
329
+ // Its index at the drag's start, for its `onReorderEnd` (#257 item 3).
330
+ let draggedFrom = -1;
331
+ const k = { element: itemElement, handle: Option.none(), onLift };
332
+ keyed.set(value, k);
333
+ const end = () => {
334
+ inGesture = false;
335
+ Reorder.dragEnd(group, value);
336
+ resetAutoScroll();
337
+ };
338
+ return {
339
+ register: (handle) => {
340
+ if (!remountReported && unregisteredThisTask.has(value)) {
341
+ remountReported = true;
342
+ runtime.runFork(Effect.logWarning(`wardic.reorder: an item remounted with the same value in one task (key items with ${keyedWith})`).pipe(Effect.annotateLogs({ value: String(value) })));
343
+ }
344
+ const unregister = Reorder.register(group, value, {
345
+ layoutBox: handle.layoutBox,
346
+ dragOffset: handle.dragOffset,
347
+ layoutVersion: handle.layoutVersion,
348
+ });
349
+ k.handle = Option.some(handle);
350
+ keyed.set(value, k);
351
+ return () => {
352
+ if (Option.contains(k.handle, handle))
353
+ k.handle = Option.none();
354
+ unregister();
355
+ if (unregisteredThisTask.size === 0)
356
+ queueMicrotask(() => unregisteredThisTask.clear());
357
+ unregisteredThisTask.add(value);
358
+ };
359
+ },
360
+ dragAxis: () => Reorder.resolveAxis(group),
361
+ onSample: (sample) => {
362
+ if (sample.phase === "start") {
363
+ endHeld();
364
+ inGesture = true;
365
+ draggedFrom = indexOf(value);
366
+ gestureAxis = Reorder.dragStart(group, value);
367
+ holdStart(value, draggedFrom, "drag");
368
+ return;
369
+ }
370
+ if (sample.phase === "move") {
371
+ const velocity = Reorder.dragMove(group, value, sample.velocity);
372
+ const scroller = MutableRef.get(autoScroller);
373
+ if (Option.isSome(scroller)) {
374
+ const on = AutoScroll.axis(gestureAxis, velocity);
375
+ scroller.value.update(sample.point, on, velocity[on], Option.getOrUndefined(k.element()));
376
+ }
377
+ return;
378
+ }
379
+ end();
380
+ // A drag a later hold took over ended then.
381
+ if (Bool.not(holdsDrag(value)))
382
+ return;
383
+ ended(value, draggedFrom);
384
+ holdEnd(value, "drop");
385
+ },
386
+ onKey: onKeyOf(value),
387
+ onBlur: () => {
388
+ if (Bool.not(Option.contains(Reorder.liftedValue(group), value)))
389
+ return;
390
+ // A reorder can blur the node it moves; focus was put back on it, so it's no interruption.
391
+ if (focused(value))
392
+ return;
393
+ dropLifted();
394
+ },
395
+ onPress: () => {
396
+ if (Option.contains(Reorder.liftedValue(group), value))
397
+ dropLifted();
398
+ },
399
+ dispose: () => {
400
+ if (inGesture)
401
+ end();
402
+ // Unmounted while lifted: the lift ends, unsaid.
403
+ if (Option.contains(Reorder.liftedValue(group), value))
404
+ Reorder.drop(group, value);
405
+ holdEnd(value, "unmount");
406
+ if (keyed.get(value) === k)
407
+ keyed.delete(value);
408
+ },
409
+ };
410
+ };
411
+ return {
412
+ group,
413
+ axis: () => Option.getOrElse(appAxis(), () => detected),
414
+ attach: (el) => {
415
+ MutableRef.set(element, Option.some(el));
416
+ MutableRef.set(autoScroller, Option.some(makeAutoScroller(el, debug)));
417
+ // The live region has to be in the page before the first lift (ADR-0037, Q7).
418
+ if (keyboardOn() && Predicate.isNotUndefined(announce))
419
+ prepareAnnouncer(documentOf(el));
420
+ },
421
+ item,
422
+ move: (value, toIndex) => Option.match(Reorder.move(group, value, toIndex), {
423
+ onNone: constVoid,
424
+ onSome: (placement) => {
425
+ if (placement.moved)
426
+ announceNow(say("move", value, placement));
427
+ },
428
+ }),
429
+ detect: () => Reorder.resolveAxis(group),
430
+ valuesChanged: () => {
431
+ // The app changed `values` itself while an item is lifted: it's dropped at its new place. The group's
432
+ // own order is told by its items, not its array: a binding reads a store's order as a new one (#721).
433
+ if (Option.isSome(Reorder.liftedValue(group)) && Bool.not(isAsked(asked, options.values())))
434
+ dropLifted();
435
+ wiring.layOut();
436
+ },
437
+ dispose: () => {
438
+ stopLaidOut();
439
+ resetAutoScroll();
440
+ },
441
+ };
442
+ };
443
+ const noop = () => { };
444
+ /** Whether two orders hold the same items in the same order. */
445
+ const sameOrder = Arr.makeEquivalence(Equivalence.strictEqual());
446
+ /** Whether `values` is the order the group last asked for (ADR-0037, *Amendment (#721)*): its items, in its order. */
447
+ const isAsked = (asked, values) => UndefinedOr.match(asked, { onUndefined: constFalse, onDefined: (order) => sameOrder(order, values) });
448
+ /**
449
+ * A {@link ReorderController} for a server render (ADR-0021), where there's no projection
450
+ * system to drive and nothing to reorder: its group has no values, so every operation on it
451
+ * does nothing, the axis is `"y"`, and an item's driver is inert too. A binding's server path hands it to its group, so code
452
+ * that reads `group`, `move` or `controller` at setup works there. Tier 2, for binding
453
+ * authors.
454
+ */
455
+ export const INERT_REORDER_CONTROLLER = Object.freeze({
456
+ // A group with no values: every operation on it finds nothing to do.
457
+ group: Reorder.make({ values: () => [], onReorder: noop }),
458
+ axis: () => "y",
459
+ attach: noop,
460
+ item: () => ({ register: () => noop, dragAxis: () => "y", onSample: noop, onKey: noop, onBlur: noop, onPress: noop, dispose: noop }),
461
+ move: noop,
462
+ detect: () => "y",
463
+ valuesChanged: noop,
464
+ dispose: noop,
465
+ });
466
+ //# sourceMappingURL=reorder.js.map