@rinzai/zen 0.11.0 → 0.13.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.
Files changed (289) hide show
  1. package/README.md +37 -7
  2. package/dist/accordion/index.d.ts +41 -0
  3. package/dist/accordion/index.d.ts.map +1 -0
  4. package/dist/accordion/index.js +81 -0
  5. package/dist/animated-number/index.d.ts +3 -2
  6. package/dist/animated-number/index.d.ts.map +1 -1
  7. package/dist/animated-number/index.js +40 -38
  8. package/dist/avatar/index.d.ts +7 -2
  9. package/dist/avatar/index.d.ts.map +1 -1
  10. package/dist/avatar/index.js +17 -11
  11. package/dist/backdrop/index.d.ts +4 -4
  12. package/dist/backdrop/index.d.ts.map +1 -1
  13. package/dist/backdrop/index.js +41 -39
  14. package/dist/badge/index.d.ts +4 -2
  15. package/dist/badge/index.d.ts.map +1 -1
  16. package/dist/badge/index.js +20 -11
  17. package/dist/base.css +4 -0
  18. package/dist/breadcrumbs/index.d.ts +1 -1
  19. package/dist/breadcrumbs/index.d.ts.map +1 -1
  20. package/dist/breadcrumbs/index.js +25 -24
  21. package/dist/button/index.d.ts +3 -3
  22. package/dist/button/index.d.ts.map +1 -1
  23. package/dist/button/index.js +16 -11
  24. package/dist/button-group/index.d.ts +13 -0
  25. package/dist/button-group/index.d.ts.map +1 -0
  26. package/dist/button-group/index.js +14 -0
  27. package/dist/calendar/index.d.ts +15 -8
  28. package/dist/calendar/index.d.ts.map +1 -1
  29. package/dist/calendar/index.js +97 -91
  30. package/dist/calendar-heatmap/index.d.ts +7 -5
  31. package/dist/calendar-heatmap/index.d.ts.map +1 -1
  32. package/dist/calendar-heatmap/index.js +32 -30
  33. package/dist/canvas/geometry.js +0 -1
  34. package/dist/canvas/index.d.ts +6 -6
  35. package/dist/canvas/index.d.ts.map +1 -1
  36. package/dist/canvas/index.js +135 -133
  37. package/dist/carousel/index.d.ts +27 -0
  38. package/dist/carousel/index.d.ts.map +1 -0
  39. package/dist/carousel/index.js +162 -0
  40. package/dist/chart/index.d.ts +5 -4
  41. package/dist/chart/index.d.ts.map +1 -1
  42. package/dist/chart/index.js +137 -135
  43. package/dist/chart/palette.js +0 -1
  44. package/dist/checkbox/index.d.ts +3 -3
  45. package/dist/checkbox/index.d.ts.map +1 -1
  46. package/dist/checkbox/index.js +33 -30
  47. package/dist/chip/index.js +1 -1
  48. package/dist/code-block/index.d.ts.map +1 -1
  49. package/dist/code-block/index.js +27 -25
  50. package/dist/code-input/index.d.ts.map +1 -1
  51. package/dist/code-input/index.js +30 -24
  52. package/dist/collapse/index.d.ts +4 -3
  53. package/dist/collapse/index.d.ts.map +1 -1
  54. package/dist/collapse/index.js +42 -39
  55. package/dist/color-picker/index.d.ts +14 -7
  56. package/dist/color-picker/index.d.ts.map +1 -1
  57. package/dist/color-picker/index.js +139 -128
  58. package/dist/combobox/index.d.ts +14 -6
  59. package/dist/combobox/index.d.ts.map +1 -1
  60. package/dist/combobox/index.js +158 -146
  61. package/dist/command-palette/index.d.ts +4 -3
  62. package/dist/command-palette/index.d.ts.map +1 -1
  63. package/dist/command-palette/index.js +60 -57
  64. package/dist/confirm-dialog/index.d.ts +6 -7
  65. package/dist/confirm-dialog/index.d.ts.map +1 -1
  66. package/dist/confirm-dialog/index.js +20 -16
  67. package/dist/date-picker/index.d.ts +23 -14
  68. package/dist/date-picker/index.d.ts.map +1 -1
  69. package/dist/date-picker/index.js +109 -93
  70. package/dist/dialog/index.d.ts +3 -4
  71. package/dist/dialog/index.d.ts.map +1 -1
  72. package/dist/dialog/index.js +58 -55
  73. package/dist/disclosure/index.d.ts +8 -0
  74. package/dist/disclosure/index.d.ts.map +1 -1
  75. package/dist/disclosure/index.js +31 -32
  76. package/dist/editable-cell/index.d.ts +4 -5
  77. package/dist/editable-cell/index.d.ts.map +1 -1
  78. package/dist/editable-cell/index.js +23 -22
  79. package/dist/field/index.d.ts +8 -8
  80. package/dist/field/index.d.ts.map +1 -1
  81. package/dist/field/index.js +20 -18
  82. package/dist/filter-bar/index.d.ts +2 -2
  83. package/dist/filter-bar/index.d.ts.map +1 -1
  84. package/dist/filter-bar/index.js +38 -36
  85. package/dist/header/index.d.ts +1 -1
  86. package/dist/header/index.d.ts.map +1 -1
  87. package/dist/header/index.js +13 -11
  88. package/dist/hover-card/index.d.ts +32 -0
  89. package/dist/hover-card/index.d.ts.map +1 -0
  90. package/dist/hover-card/index.js +84 -0
  91. package/dist/icon-picker/index.d.ts +16 -5
  92. package/dist/icon-picker/index.d.ts.map +1 -1
  93. package/dist/icon-picker/index.js +42 -47
  94. package/dist/icons/micro/plus.d.ts +3 -0
  95. package/dist/icons/micro/plus.d.ts.map +1 -0
  96. package/dist/icons/micro/plus.js +17 -0
  97. package/dist/index.d.ts +37 -24
  98. package/dist/index.d.ts.map +1 -1
  99. package/dist/input/index.d.ts +5 -1
  100. package/dist/input/index.d.ts.map +1 -1
  101. package/dist/input/index.js +9 -9
  102. package/dist/input-group/index.d.ts +4 -1
  103. package/dist/input-group/index.d.ts.map +1 -1
  104. package/dist/input-group/index.js +14 -14
  105. package/dist/keypad/index.d.ts +9 -7
  106. package/dist/keypad/index.d.ts.map +1 -1
  107. package/dist/keypad/index.js +22 -19
  108. package/dist/lib.js +112 -97
  109. package/dist/load-more/index.d.ts +4 -2
  110. package/dist/load-more/index.d.ts.map +1 -1
  111. package/dist/load-more/index.js +26 -23
  112. package/dist/locale-provider/index.d.ts +23 -0
  113. package/dist/locale-provider/index.d.ts.map +1 -0
  114. package/dist/locale-provider/index.js +35 -0
  115. package/dist/menu/index.d.ts +62 -9
  116. package/dist/menu/index.d.ts.map +1 -1
  117. package/dist/menu/index.js +371 -128
  118. package/dist/meter/index.d.ts +2 -2
  119. package/dist/meter/index.d.ts.map +1 -1
  120. package/dist/meter/index.js +4 -4
  121. package/dist/money-input/index.d.ts +20 -10
  122. package/dist/money-input/index.d.ts.map +1 -1
  123. package/dist/money-input/index.js +199 -190
  124. package/dist/month-picker/index.d.ts +17 -10
  125. package/dist/month-picker/index.d.ts.map +1 -1
  126. package/dist/month-picker/index.js +97 -86
  127. package/dist/navigation-menu/index.d.ts +42 -0
  128. package/dist/navigation-menu/index.d.ts.map +1 -0
  129. package/dist/navigation-menu/index.js +144 -0
  130. package/dist/number-field/index.d.ts +34 -0
  131. package/dist/number-field/index.d.ts.map +1 -0
  132. package/dist/number-field/index.js +119 -0
  133. package/dist/page-header/index.d.ts +4 -3
  134. package/dist/page-header/index.d.ts.map +1 -1
  135. package/dist/page-header/index.js +2 -1
  136. package/dist/pagination/index.d.ts +1 -1
  137. package/dist/pagination/index.d.ts.map +1 -1
  138. package/dist/pagination/index.js +35 -33
  139. package/dist/progress-ring/index.d.ts +4 -3
  140. package/dist/progress-ring/index.d.ts.map +1 -1
  141. package/dist/progress-ring/index.js +11 -10
  142. package/dist/radio-cards/index.d.ts +9 -5
  143. package/dist/radio-cards/index.d.ts.map +1 -1
  144. package/dist/radio-cards/index.js +26 -24
  145. package/dist/radio-group/index.d.ts +9 -8
  146. package/dist/radio-group/index.d.ts.map +1 -1
  147. package/dist/radio-group/index.js +35 -34
  148. package/dist/range-slider/index.d.ts +10 -4
  149. package/dist/range-slider/index.d.ts.map +1 -1
  150. package/dist/range-slider/index.js +43 -31
  151. package/dist/repeat-picker/index.d.ts +13 -6
  152. package/dist/repeat-picker/index.d.ts.map +1 -1
  153. package/dist/repeat-picker/index.js +73 -61
  154. package/dist/resizable/index.d.ts +29 -0
  155. package/dist/resizable/index.d.ts.map +1 -0
  156. package/dist/resizable/index.js +135 -0
  157. package/dist/segmented/index.d.ts +8 -5
  158. package/dist/segmented/index.d.ts.map +1 -1
  159. package/dist/segmented/index.js +36 -34
  160. package/dist/select/index.d.ts +9 -3
  161. package/dist/select/index.d.ts.map +1 -1
  162. package/dist/select/index.js +99 -96
  163. package/dist/separator/index.d.ts +14 -0
  164. package/dist/separator/index.d.ts.map +1 -0
  165. package/dist/separator/index.js +15 -0
  166. package/dist/side-nav/index.js +1 -1
  167. package/dist/skeleton/index.d.ts +4 -4
  168. package/dist/skeleton/index.d.ts.map +1 -1
  169. package/dist/skeleton/index.js +4 -3
  170. package/dist/slider/index.d.ts +6 -3
  171. package/dist/slider/index.d.ts.map +1 -1
  172. package/dist/slider/index.js +29 -23
  173. package/dist/sortable/index.d.ts +10 -20
  174. package/dist/sortable/index.d.ts.map +1 -1
  175. package/dist/sortable/index.js +72 -134
  176. package/dist/sortable/shared.d.ts +56 -0
  177. package/dist/sortable/shared.d.ts.map +1 -0
  178. package/dist/sortable/shared.js +104 -0
  179. package/dist/sortable/tree-model.d.ts +46 -0
  180. package/dist/sortable/tree-model.d.ts.map +1 -0
  181. package/dist/sortable/tree-model.js +87 -0
  182. package/dist/sortable/tree.d.ts +31 -0
  183. package/dist/sortable/tree.d.ts.map +1 -0
  184. package/dist/sortable/tree.js +150 -0
  185. package/dist/sparkline/index.d.ts +1 -1
  186. package/dist/sparkline/index.d.ts.map +1 -1
  187. package/dist/sparkline/index.js +26 -25
  188. package/dist/spinner/index.d.ts +4 -3
  189. package/dist/spinner/index.d.ts.map +1 -1
  190. package/dist/spinner/index.js +2 -1
  191. package/dist/status-pill/index.d.ts.map +1 -1
  192. package/dist/status-pill/index.js +1 -1
  193. package/dist/stepper/index.d.ts +1 -1
  194. package/dist/stepper/index.d.ts.map +1 -1
  195. package/dist/stepper/index.js +31 -30
  196. package/dist/tab-bar/index.js +1 -1
  197. package/dist/table/index.d.ts +5 -5
  198. package/dist/table/index.d.ts.map +1 -1
  199. package/dist/table/index.js +66 -64
  200. package/dist/table/selection.d.ts +2 -2
  201. package/dist/table/selection.d.ts.map +1 -1
  202. package/dist/table/selection.js +41 -38
  203. package/dist/table/swipe.d.ts +1 -1
  204. package/dist/table/swipe.d.ts.map +1 -1
  205. package/dist/table/swipe.js +1 -1
  206. package/dist/table-of-contents/index.d.ts +4 -2
  207. package/dist/table-of-contents/index.d.ts.map +1 -1
  208. package/dist/table-of-contents/index.js +27 -25
  209. package/dist/tabs/index.d.ts.map +1 -1
  210. package/dist/tabs/index.js +90 -88
  211. package/dist/tag-input/index.d.ts +3 -1
  212. package/dist/tag-input/index.d.ts.map +1 -1
  213. package/dist/tag-input/index.js +61 -52
  214. package/dist/theme-toggle/index.d.ts +9 -8
  215. package/dist/theme-toggle/index.d.ts.map +1 -1
  216. package/dist/theme-toggle/index.js +30 -28
  217. package/dist/theme.css +90 -12
  218. package/dist/time-field/index.d.ts +31 -0
  219. package/dist/time-field/index.d.ts.map +1 -0
  220. package/dist/time-field/index.js +175 -0
  221. package/dist/timeline/index.js +1 -1
  222. package/dist/toast/index.d.ts +1 -1
  223. package/dist/toast/index.d.ts.map +1 -1
  224. package/dist/toast/index.js +127 -125
  225. package/dist/toggle/index.d.ts +2 -2
  226. package/dist/toggle/index.d.ts.map +1 -1
  227. package/dist/toggle/index.js +8 -6
  228. package/dist/toggle-group/index.d.ts +35 -0
  229. package/dist/toggle-group/index.d.ts.map +1 -0
  230. package/dist/toggle-group/index.js +53 -0
  231. package/dist/toolbar/index.d.ts +19 -0
  232. package/dist/toolbar/index.d.ts.map +1 -0
  233. package/dist/toolbar/index.js +36 -0
  234. package/dist/tooltip/index.d.ts.map +1 -1
  235. package/dist/tooltip/index.js +40 -74
  236. package/dist/tree/index.d.ts.map +1 -1
  237. package/dist/tree/index.js +105 -102
  238. package/dist/trend/index.d.ts +2 -2
  239. package/dist/trend/index.d.ts.map +1 -1
  240. package/dist/trend/index.js +20 -19
  241. package/dist/utils/color.js +0 -1
  242. package/dist/utils/cva.js +0 -1
  243. package/dist/utils/cx.js +0 -1
  244. package/dist/utils/date.d.ts +6 -0
  245. package/dist/utils/date.d.ts.map +1 -1
  246. package/dist/utils/date.js +1 -2
  247. package/dist/utils/direction.d.ts +7 -0
  248. package/dist/utils/direction.d.ts.map +1 -0
  249. package/dist/utils/direction.js +6 -0
  250. package/dist/utils/form-value.d.ts +15 -0
  251. package/dist/utils/form-value.d.ts.map +1 -0
  252. package/dist/utils/form-value.js +29 -0
  253. package/dist/utils/fx.js +0 -1
  254. package/dist/utils/merge.js +0 -1
  255. package/dist/utils/messages.d.ts +137 -0
  256. package/dist/utils/messages.d.ts.map +1 -0
  257. package/dist/utils/messages.js +133 -0
  258. package/dist/utils/money.js +0 -1
  259. package/dist/utils/month.js +0 -1
  260. package/dist/utils/motion.js +0 -1
  261. package/dist/utils/refs.d.ts +6 -0
  262. package/dist/utils/refs.d.ts.map +1 -0
  263. package/dist/utils/refs.js +13 -0
  264. package/dist/utils/repeat.d.ts +3 -1
  265. package/dist/utils/repeat.d.ts.map +1 -1
  266. package/dist/utils/repeat.js +28 -25
  267. package/dist/utils/roving.d.ts +17 -0
  268. package/dist/utils/roving.d.ts.map +1 -0
  269. package/dist/utils/roving.js +35 -0
  270. package/dist/utils/section-link.js +0 -1
  271. package/dist/utils/slot.d.ts.map +1 -1
  272. package/dist/utils/slot.js +7 -11
  273. package/dist/utils/status-icons.js +7 -7
  274. package/dist/utils/styles.d.ts +9 -2
  275. package/dist/utils/styles.d.ts.map +1 -1
  276. package/dist/utils/styles.js +6 -3
  277. package/dist/utils/theme-wave.js +0 -1
  278. package/dist/utils/theme.js +0 -1
  279. package/dist/utils/useAnchoredPopup.d.ts +7 -4
  280. package/dist/utils/useAnchoredPopup.d.ts.map +1 -1
  281. package/dist/utils/useAnchoredPopup.js +18 -11
  282. package/dist/utils/useControllable.d.ts +9 -0
  283. package/dist/utils/useControllable.d.ts.map +1 -0
  284. package/dist/utils/useControllable.js +15 -0
  285. package/dist/utils/useHoverPopup.d.ts +39 -0
  286. package/dist/utils/useHoverPopup.d.ts.map +1 -0
  287. package/dist/utils/useHoverPopup.js +64 -0
  288. package/dist/zen.css +1 -1
  289. package/package.json +1 -1
@@ -1,147 +1,85 @@
1
1
  "use client";
2
2
  import { cx as e } from "../utils/cx.js";
3
- import { reducedMotion as t } from "../utils/motion.js";
4
- import { createContext as n, useContext as r, useEffect as i, useLayoutEffect as a, useRef as o, useState as s } from "react";
5
- import { jsx as c, jsxs as l } from "react/jsx-runtime";
3
+ import { useMergedRefs as t } from "../utils/refs.js";
4
+ import { Slot as n } from "../utils/slot.js";
5
+ import { useMessages as r } from "../locale-provider/index.js";
6
+ import { SortableContext as i, SortableHandle as a, SortableItem as o, edgeScroll as s, scrollerOf as c, settle as l, shift as u, topsOf as d, useAnnouncer as f } from "./shared.js";
7
+ import { flattenTree as p } from "./tree-model.js";
8
+ import m from "./tree.js";
9
+ import { useEffect as h, useLayoutEffect as g, useRef as _, useState as v } from "react";
10
+ import { jsx as y, jsxs as b } from "react/jsx-runtime";
6
11
  //#region packages/sortable/index.tsx
7
- var u = typeof window > "u" ? i : a, d = {
8
- duration: 220,
9
- easing: "cubic-bezier(0.2, 0.8, 0.2, 1)"
10
- }, f = 48, p = n(null);
11
- function m(e) {
12
- let t = r(p);
13
- if (!t) throw Error(`<${e}> must be inside <SortableList>`);
14
- return t;
15
- }
16
- var h = (e, t, n) => {
12
+ var x = typeof window > "u" ? h : g, S = (e, t, n) => {
17
13
  let r = [...e];
18
14
  return r.splice(n, 0, ...r.splice(t, 1)), r;
19
15
  };
20
- function g({ value: n, onChange: r, className: i, children: a, ...m }) {
21
- let g = o(null), [_, v] = s(null), [b, x] = s(""), S = o(null), C = o(null), w = () => [...g.current?.querySelectorAll(":scope > [data-sortable-id]") ?? []], T = () => new Map(w().map((e) => [e.dataset.sortableId, e.getBoundingClientRect().top])), E = (e) => {
22
- S.current = T(), r(e);
16
+ function C({ value: a, onValueChange: o, asChild: p, className: m, children: h, ref: g, ...C }) {
17
+ let w = _(null), T = t(w, g), [E, D] = v(null), O = r(), { say: k, region: A } = f(w), j = _(null), M = _(null), N = () => [...w.current?.querySelectorAll(":scope > [data-sortable-id]") ?? []], P = (e) => {
18
+ j.current = d(N()), o(e);
23
19
  };
24
- return u(() => {
25
- let e = S.current;
26
- if (S.current = null, e) for (let n of w()) {
27
- n.style.removeProperty("translate");
28
- let r = e.get(n.dataset.sortableId), i = r === void 0 ? 0 : r - n.getBoundingClientRect().top;
29
- i && !t() && n.animate?.({ translate: [`0 ${i}px`, "0 0"] }, d);
20
+ x(() => {
21
+ let e = j.current;
22
+ j.current = null, e && l(N(), e);
23
+ }, [a]);
24
+ let F = (e, t) => {
25
+ if (e.button !== 0 || E) return;
26
+ let n = N(), r = n.findIndex((e) => e.dataset.sortableId === t), i = n[r];
27
+ if (!i) return;
28
+ e.preventDefault();
29
+ let o = e.currentTarget;
30
+ o.setPointerCapture?.(e.pointerId);
31
+ let f = c(w.current), p = f.scrollTop, m = e.clientY, h = n.map((e) => e.getBoundingClientRect()), g = h.length > 1 ? h[1].top - h[0].bottom : 0, _ = h[r].height + g, v = h.map((e) => e.top + e.height / 2), y = r, b = e.clientY;
32
+ i.dataset.dragging = "", w.current.dataset.sorting = "";
33
+ let x = () => {
34
+ let e = b - m + f.scrollTop - p;
35
+ u(i, e);
36
+ let t = v[r] + e, a = y;
37
+ for (y = r; y < n.length - 1 && t > v[y + 1];) y++;
38
+ for (; y > 0 && t < v[y - 1];) y--;
39
+ y !== a && navigator.vibrate?.(5), n.forEach((e, t) => {
40
+ if (t === r) return;
41
+ let n = r < t && t <= y ? -_ : y <= t && t < r ? _ : 0;
42
+ u(e, n);
43
+ });
44
+ }, C = s(f, x), T = (t) => {
45
+ t.pointerId === e.pointerId && (b = t.clientY, x(), C.at(b));
46
+ }, D = (t) => {
47
+ t.pointerId === e.pointerId && (o.removeEventListener("pointermove", T), o.removeEventListener("pointerup", D), o.removeEventListener("pointercancel", D), C.stop(), delete i.dataset.dragging, delete w.current?.dataset.sorting, t.type === "pointerup" && y !== r ? P(S(a, r, y)) : l(n, d(n)));
48
+ };
49
+ o.addEventListener("pointermove", T), o.addEventListener("pointerup", D), o.addEventListener("pointercancel", D);
50
+ }, I = (e, t, n) => {
51
+ let r = a.indexOf(t), i = O.place(r + 1, a.length);
52
+ if (e.key === " " || e.key === "Enter") e.preventDefault(), E === t ? (D(null), M.current = null, k(O.dropped(n, i))) : E || (D(t), M.current = a, k(O.pickedUp(n, i)));
53
+ else if (E === t && (e.key === "ArrowUp" || e.key === "ArrowDown")) {
54
+ e.preventDefault();
55
+ let t = r + (e.key === "ArrowUp" ? -1 : 1);
56
+ if (t < 0 || t >= a.length) return;
57
+ P(S(a, r, t)), k(O.movedTo(n, O.place(t + 1, a.length)));
58
+ } else if (E === t && e.key === "Escape") {
59
+ e.preventDefault();
60
+ let r = M.current ?? a;
61
+ D(null), M.current = null, r !== a && P([...r]), k(O.putBack(n, O.place(r.indexOf(t) + 1, r.length)));
30
62
  }
31
- }, [n]), /* @__PURE__ */ l(p.Provider, {
63
+ }, L = {
64
+ ...C,
65
+ ref: T
66
+ };
67
+ return /* @__PURE__ */ b(i.Provider, {
32
68
  value: {
33
- grab: (e, r) => {
34
- if (e.button !== 0 || _) return;
35
- let i = w(), a = i.findIndex((e) => e.dataset.sortableId === r), o = i[a];
36
- if (!o) return;
37
- e.preventDefault();
38
- let s = e.currentTarget;
39
- s.setPointerCapture?.(e.pointerId);
40
- let c = y(g.current), l = c.scrollTop, u = e.clientY, p = i.map((e) => e.getBoundingClientRect()), m = p.length > 1 ? p[1].top - p[0].bottom : 0, v = p[a].height + m, b = p.map((e) => e.top + e.height / 2), x = a, C = e.clientY, D = 0;
41
- o.dataset.dragging = "", g.current.dataset.sorting = "";
42
- let O = () => {
43
- let e = C - u + c.scrollTop - l;
44
- o.style.translate = `0 ${e}px`;
45
- let t = b[a] + e, n = x;
46
- for (x = a; x < i.length - 1 && t > b[x + 1];) x++;
47
- for (; x > 0 && t < b[x - 1];) x--;
48
- x !== n && navigator.vibrate?.(5), i.forEach((e, t) => {
49
- if (t === a) return;
50
- let n = a < t && t <= x ? -v : x <= t && t < a ? v : 0;
51
- e.style.translate = n ? `0 ${n}px` : "";
52
- });
53
- }, k = () => {
54
- D = 0;
55
- let e = c === document.scrollingElement ? {
56
- top: 0,
57
- bottom: innerHeight
58
- } : c.getBoundingClientRect(), t = C < e.top + f ? -(e.top + f - C) : C > e.bottom - f ? C - (e.bottom - f) : 0;
59
- t && (c.scrollTop += t / 3, O(), D = requestAnimationFrame(k));
60
- }, A = (t) => {
61
- t.pointerId === e.pointerId && (C = t.clientY, O(), D ||= requestAnimationFrame(k));
62
- }, j = (r) => {
63
- if (r.pointerId === e.pointerId) {
64
- if (s.removeEventListener("pointermove", A), s.removeEventListener("pointerup", j), s.removeEventListener("pointercancel", j), cancelAnimationFrame(D), delete o.dataset.dragging, delete g.current?.dataset.sorting, r.type === "pointerup" && x !== a) E(h(n, a, x));
65
- else {
66
- S.current = T();
67
- for (let e of i) e.style.removeProperty("translate");
68
- for (let e of i) {
69
- let n = S.current.get(e.dataset.sortableId) - e.getBoundingClientRect().top;
70
- n && !t() && e.animate?.({ translate: [`0 ${n}px`, "0 0"] }, d);
71
- }
72
- S.current = null;
73
- }
74
- }
75
- };
76
- s.addEventListener("pointermove", A), s.addEventListener("pointerup", j), s.addEventListener("pointercancel", j);
77
- },
78
- key: (e, t, r) => {
79
- let i = n.indexOf(t), a = `${i + 1} of ${n.length}`;
80
- if (e.key === " " || e.key === "Enter") e.preventDefault(), _ === t ? (v(null), C.current = null, x(`${r} dropped, ${a}.`)) : _ || (v(t), C.current = n, x(`${r} picked up, ${a}. Arrow keys move it, Space drops it, Escape puts it back.`));
81
- else if (_ === t && (e.key === "ArrowUp" || e.key === "ArrowDown")) {
82
- e.preventDefault();
83
- let t = i + (e.key === "ArrowUp" ? -1 : 1);
84
- if (t < 0 || t >= n.length) return;
85
- E(h(n, i, t)), x(`${r}, ${t + 1} of ${n.length}.`);
86
- } else if (_ === t && e.key === "Escape") {
87
- e.preventDefault();
88
- let i = C.current ?? n;
89
- v(null), C.current = null, i !== n && E([...i]), x(`${r} put back, ${i.indexOf(t) + 1} of ${i.length}.`);
90
- }
91
- },
92
- lifted: _
69
+ grab: F,
70
+ key: I,
71
+ lifted: E
93
72
  },
94
- children: [/* @__PURE__ */ c("ul", {
95
- ref: g,
96
- className: e("zen__sortable relative flex flex-col", i),
97
- ...m,
98
- children: a
99
- }), /* @__PURE__ */ c("span", {
100
- "aria-live": "assertive",
101
- className: "sr-only",
102
- children: b
103
- })]
104
- });
105
- }
106
- function _({ id: t, className: n, ...r }) {
107
- let { lifted: i } = m("SortableItem");
108
- return /* @__PURE__ */ c("li", {
109
- "data-sortable-id": t,
110
- "data-lifted": i === t || void 0,
111
- className: e("zen__sortable-item relative transition-[box-shadow,scale,background-color] duration-200 data-dragging:bg-card data-lifted:bg-card data-dragging:z-10 data-dragging:rounded-xl data-dragging:scale-[1.02] data-dragging:shadow-[0_0_0_1px_oklch(var(--tint)/0.08),0_12px_32px_-12px_oklch(0_0_0/0.6)] data-lifted:z-10 data-lifted:rounded-xl data-lifted:shadow-[0_0_0_2px_oklch(var(--primary)/0.6)]", n),
112
- ...r
73
+ children: [p ? /* @__PURE__ */ y(n, {
74
+ ...L,
75
+ className: e("zen__sortable", m),
76
+ children: h
77
+ }) : /* @__PURE__ */ y("ul", {
78
+ ...L,
79
+ className: e("zen__sortable relative flex flex-col", m),
80
+ children: h
81
+ }), A]
113
82
  });
114
83
  }
115
- function v({ id: t, label: n, className: r, children: i, ...a }) {
116
- let { grab: o, key: s, lifted: l } = m("SortableHandle");
117
- return /* @__PURE__ */ c("button", {
118
- type: "button",
119
- "aria-label": `Reorder ${n}`,
120
- "aria-pressed": l === t,
121
- onPointerDown: (e) => o(e, t),
122
- onKeyDown: (e) => s(e, t, n),
123
- className: e("text-muted-foreground hover:text-foreground focus-visible:ring-ring/50 grid size-8 shrink-0 cursor-grab touch-none place-items-center rounded-md outline-hidden select-none focus-visible:ring-2 active:cursor-grabbing", r),
124
- ...a,
125
- children: i ?? /* @__PURE__ */ c("svg", {
126
- "aria-hidden": !0,
127
- viewBox: "0 0 16 16",
128
- fill: "currentColor",
129
- className: "size-4",
130
- children: [
131
- 4,
132
- 8,
133
- 12
134
- ].flatMap((e) => [5.5, 10.5].map((t) => /* @__PURE__ */ c("circle", {
135
- cx: t,
136
- cy: e,
137
- r: "1.25"
138
- }, `${t}${e}`)))
139
- })
140
- });
141
- }
142
- function y(e) {
143
- for (let t = e.parentElement; t; t = t.parentElement) if (/auto|scroll/.test(getComputedStyle(t).overflowY) && t.scrollHeight > t.clientHeight) return t;
144
- return document.scrollingElement ?? document.documentElement;
145
- }
146
84
  //#endregion
147
- export { v as SortableHandle, _ as SortableItem, g as SortableList };
85
+ export { a as SortableHandle, o as SortableItem, C as SortableList, m as SortableTree, p as flattenTree };
@@ -0,0 +1,56 @@
1
+ import { ComponentProps, KeyboardEvent, PointerEvent, RefObject } from 'react';
2
+ export interface SortableContextValue {
3
+ grab: (e: PointerEvent<HTMLElement>, id: string) => void;
4
+ key: (e: KeyboardEvent<HTMLElement>, id: string, label: string) => void;
5
+ lifted: string | null;
6
+ }
7
+ export declare const SortableContext: import('react').Context<SortableContextValue | null>;
8
+ /** Offsets an item `dy` down (0: back in place). */
9
+ export declare function shift(el: HTMLElement, dy: number): void;
10
+ /** Each item's place on screen, by id, to move them from after a change. */
11
+ export declare const topsOf: (els: readonly HTMLElement[]) => Map<string, number>;
12
+ /** Moves each item from where it was (`was`) to where it is now, dropping any drag offset. */
13
+ export declare function settle(els: readonly HTMLElement[], was: Map<string, number>): void;
14
+ /**
15
+ * Scrolls `scroller` while the pointer (at `y`) is near its edge, calling
16
+ * `moved` as the content moves under it. Returns a function to call on each
17
+ * pointer move, and one to stop.
18
+ */
19
+ export declare function edgeScroll(scroller: HTMLElement, moved: () => void): {
20
+ at: (pointerY: number) => void;
21
+ stop: () => void;
22
+ };
23
+ /**
24
+ * Says what happens, from outside the list (a span can't go in a table), but
25
+ * inside a modal dialog it's in, or it wouldn't be heard. Also where a drag's
26
+ * drop line goes.
27
+ */
28
+ export declare function useAnnouncer(root: RefObject<HTMLElement | null>): {
29
+ say: import('react').Dispatch<import('react').SetStateAction<string>>;
30
+ region: import('react').ReactPortal | null;
31
+ host: Element | null;
32
+ };
33
+ /** One item in a SortableList or SortableTree; give it the `id` it has in the list's value. With `asChild`, your own element (a TableRow). */
34
+ export declare function SortableItem({ id, label, asChild, className, ...rest }: SortableItemProps): import('react').JSX.Element;
35
+ /**
36
+ * What an item is dragged by: a grip button. `label` names the item ("Rent");
37
+ * the button reads "Reorder Rent". It takes no scroll gestures, so dragging it
38
+ * never scrolls the page.
39
+ */
40
+ export declare function SortableHandle({ id, label, className, children, ...rest }: SortableHandleProps): import('react').JSX.Element;
41
+ /** The nearest ancestor that scrolls vertically, or the page. */
42
+ export declare function scrollerOf(el: HTMLElement): HTMLElement;
43
+ export interface SortableItemProps extends ComponentProps<'li'> {
44
+ id: string;
45
+ /** Its name, for one without a SortableHandle (a group others go into), to say "2 of 3 in Food". */
46
+ label?: string;
47
+ /** Put the item's props on your own element (the single child, e.g. a TableRow) instead of an li. */
48
+ asChild?: boolean;
49
+ }
50
+ export interface SortableHandleProps extends Omit<ComponentProps<'button'>, 'id'> {
51
+ /** The item's id, as in the list's value. */
52
+ id: string;
53
+ /** The item's name, e.g. "Rent". */
54
+ label: string;
55
+ }
56
+ //# sourceMappingURL=shared.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../packages/sortable/shared.tsx"],"names":[],"mappings":"AAIA,OAAO,EACH,cAAc,EAEd,aAAa,EACb,YAAY,EACZ,SAAS,EAIZ,MAAM,OAAO,CAAC;AAOf,MAAM,WAAW,oBAAoB;IACjC,IAAI,EAAE,CAAC,CAAC,EAAE,YAAY,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACzD,GAAG,EAAE,CAAC,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,EAAE,EAAE,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACxE,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACzB;AAED,eAAO,MAAM,eAAe,sDAAmD,CAAC;AAWhF,oDAAoD;AACpD,wBAAgB,KAAK,CAAC,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE,MAAM,QAEhD;AAKD,4EAA4E;AAC5E,eAAO,MAAM,MAAM,GAAI,KAAK,SAAS,WAAW,EAAE,wBAAkE,CAAC;AAErH,8FAA8F;AAC9F,wBAAgB,MAAM,CAAC,GAAG,EAAE,SAAS,WAAW,EAAE,EAAE,GAAG,EAAE,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC,QAU3E;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,QAAQ,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,IAAI;mBAc5C,MAAM;;EAM5B;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAC,IAAI,EAAE,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC;;;;EAe/D;AAED,8IAA8I;AAC9I,wBAAgB,YAAY,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,SAAS,EAAE,GAAG,IAAI,EAAE,EAAE,iBAAiB,+BAuBzF;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAC,EAAE,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,mBAAmB,+BA0B9F;AAED,iEAAiE;AACjE,wBAAgB,UAAU,CAAC,EAAE,EAAE,WAAW,GAAG,WAAW,CAKvD;AAED,MAAM,WAAW,iBAAkB,SAAQ,cAAc,CAAC,IAAI,CAAC;IAC3D,EAAE,EAAE,MAAM,CAAC;IACX,oGAAoG;IACpG,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qGAAqG;IACrG,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,MAAM,WAAW,mBAAoB,SAAQ,IAAI,CAAC,cAAc,CAAC,QAAQ,CAAC,EAAE,IAAI,CAAC;IAC7E,6CAA6C;IAC7C,EAAE,EAAE,MAAM,CAAC;IACX,oCAAoC;IACpC,KAAK,EAAE,MAAM,CAAC;CACjB"}
@@ -0,0 +1,104 @@
1
+ "use client";
2
+ import { cx as e } from "../utils/cx.js";
3
+ import { Slot as t } from "../utils/slot.js";
4
+ import { useMessages as n } from "../locale-provider/index.js";
5
+ import { reducedMotion as r } from "../utils/motion.js";
6
+ import { createContext as i, useContext as a, useEffect as o, useState as s } from "react";
7
+ import { jsx as c } from "react/jsx-runtime";
8
+ import { createPortal as l } from "react-dom";
9
+ //#region packages/sortable/shared.tsx
10
+ var u = {
11
+ duration: 220,
12
+ easing: "cubic-bezier(0.2, 0.8, 0.2, 1)"
13
+ }, d = 48, f = i(null);
14
+ function p(e) {
15
+ let t = a(f);
16
+ if (!t) throw Error(`<${e}> must be inside <SortableList> or <SortableTree>`);
17
+ return t;
18
+ }
19
+ var m = (e) => e instanceof HTMLTableRowElement ? [...e.cells] : [e];
20
+ function h(e, t) {
21
+ for (let n of m(e)) n.style.translate = t ? `0 ${t}px` : "";
22
+ }
23
+ var g = (e) => m(e)[0]?.getBoundingClientRect().top ?? e.getBoundingClientRect().top, _ = (e) => new Map(e.map((e) => [e.dataset.sortableId, g(e)]));
24
+ function v(e, t) {
25
+ for (let n of e) {
26
+ let e = m(n);
27
+ for (let t of e) t.style.removeProperty("translate");
28
+ for (let t of [n, ...e]) for (let e of t.getAnimations?.() ?? []) e.cancel();
29
+ let i = t.get(n.dataset.sortableId), a = i === void 0 ? 0 : i - n.getBoundingClientRect().top;
30
+ if (a && !r()) for (let t of e) t.animate?.({ translate: [`0 ${a}px`, "0 0"] }, u);
31
+ }
32
+ }
33
+ function y(e, t) {
34
+ let n = 0, r = 0, i = () => {
35
+ r = 0;
36
+ let a = e === document.scrollingElement ? {
37
+ top: 0,
38
+ bottom: innerHeight
39
+ } : e.getBoundingClientRect(), o = n < a.top + d ? -(a.top + d - n) : n > a.bottom - d ? n - (a.bottom - d) : 0;
40
+ o && (e.scrollTop += o / 3, t(), r = requestAnimationFrame(i));
41
+ };
42
+ return {
43
+ at: (e) => {
44
+ n = e, r ||= requestAnimationFrame(i);
45
+ },
46
+ stop: () => cancelAnimationFrame(r)
47
+ };
48
+ }
49
+ function b(e) {
50
+ let [t, n] = s(""), [r, i] = s(null);
51
+ return o(() => i(e.current?.closest("dialog") ?? document.body), []), {
52
+ say: n,
53
+ region: r && l(/* @__PURE__ */ c("span", {
54
+ "aria-live": "assertive",
55
+ className: "sr-only",
56
+ children: t
57
+ }), r),
58
+ host: r
59
+ };
60
+ }
61
+ function x({ id: n, label: r, asChild: i, className: a, ...o }) {
62
+ let { lifted: s } = p("SortableItem");
63
+ return /* @__PURE__ */ c(i ? t : "li", {
64
+ "data-sortable-id": n,
65
+ "data-sortable-label": r,
66
+ "data-lifted": s === n || void 0,
67
+ className: e("zen__sortable-item transition-[box-shadow,scale,background-color] duration-200 [&:not(tr)]:relative", "[&:not(tr)]:data-dragging:bg-card [&:not(tr)]:data-dragging:z-10 [&:not(tr)]:data-dragging:rounded-xl [&:not(tr)]:data-dragging:scale-[1.02] [&:not(tr)]:data-dragging:shadow-[0_0_0_1px_oklch(var(--tint)/0.08),0_12px_32px_-12px_oklch(0_0_0/0.6)]", "[&:not(tr)]:data-lifted:bg-card [&:not(tr)]:data-lifted:z-10 [&:not(tr)]:data-lifted:rounded-xl [&:not(tr)]:data-lifted:shadow-[0_0_0_2px_oklch(var(--primary)/0.6)]", "[&:not(tr)]:data-carried:z-10 [&:not(tr)]:data-carried:bg-card data-drop-target:bg-primary/[0.07] [&[data-drop-target]>td]:[background-image:linear-gradient(oklch(var(--primary)/0.09),oklch(var(--primary)/0.09))]", "[&:is([data-dragging],[data-carried])>td]:z-20 [&:is([data-dragging],[data-carried])>td]:bg-card/80 [&:is([data-dragging],[data-carried])>td]:glass-blur [&:is([data-dragging],[data-carried])>td:not(.sticky)]:relative", "[&[data-lifted]>td]:[background-image:linear-gradient(oklch(var(--primary)/0.09),oklch(var(--primary)/0.09))] [&[data-lifted]>td]:shadow-[inset_0_2px_0_oklch(var(--primary)/0.6),inset_0_-2px_0_oklch(var(--primary)/0.6)]", a),
68
+ ...o
69
+ });
70
+ }
71
+ function S({ id: t, label: r, className: i, children: a, ...o }) {
72
+ let { grab: s, key: l, lifted: u } = p("SortableHandle"), d = n();
73
+ return /* @__PURE__ */ c("button", {
74
+ type: "button",
75
+ "aria-label": d.reorder(r),
76
+ "data-sortable-label": r,
77
+ "aria-pressed": u === t,
78
+ onPointerDown: (e) => s(e, t),
79
+ onKeyDown: (e) => l(e, t, r),
80
+ className: e("text-muted-foreground hover:text-foreground grid size-8 shrink-0 cursor-grab touch-none place-items-center rounded-md outline-hidden select-none focus-ring active:cursor-grabbing", i),
81
+ ...o,
82
+ children: a ?? /* @__PURE__ */ c("svg", {
83
+ "aria-hidden": !0,
84
+ viewBox: "0 0 16 16",
85
+ fill: "currentColor",
86
+ className: "size-4",
87
+ children: [
88
+ 4,
89
+ 8,
90
+ 12
91
+ ].flatMap((e) => [5.5, 10.5].map((t) => /* @__PURE__ */ c("circle", {
92
+ cx: t,
93
+ cy: e,
94
+ r: "1.25"
95
+ }, `${t}${e}`)))
96
+ })
97
+ });
98
+ }
99
+ function C(e) {
100
+ for (let t = e.parentElement; t; t = t.parentElement) if (/auto|scroll/.test(getComputedStyle(t).overflowY) && t.scrollHeight > t.clientHeight) return t;
101
+ return document.scrollingElement ?? document.documentElement;
102
+ }
103
+ //#endregion
104
+ export { f as SortableContext, S as SortableHandle, x as SortableItem, y as edgeScroll, C as scrollerOf, v as settle, h as shift, _ as topsOf, b as useAnnouncer };
@@ -0,0 +1,46 @@
1
+ /** A node of a SortableTree's value: an id, and the nodes under it. */
2
+ export interface SortableNode {
3
+ id: string;
4
+ children?: SortableNode[];
5
+ }
6
+ /** A row as shown: how deep it is, and what it's under (null at the top). */
7
+ export interface SortableRow {
8
+ id: string;
9
+ depth: number;
10
+ parentId: string | null;
11
+ }
12
+ /** Somewhere a node can go: under `parentId` (null: the top), at `index` among its children. */
13
+ export interface TreePlace {
14
+ parentId: string | null;
15
+ index: number;
16
+ }
17
+ /** A place, as where it is among the rows: before row `gap` (after the last, at the end), `depth` deep. */
18
+ export interface TreeSlot extends TreePlace {
19
+ gap: number;
20
+ depth: number;
21
+ }
22
+ /**
23
+ * The rows to render, in order, each with its depth: a node's children follow
24
+ * it while `open(id)` says it's expanded (by default, all are).
25
+ */
26
+ export declare function flattenTree(nodes: readonly SortableNode[], open?: (id: string) => boolean, depth?: number, parentId?: string | null): SortableRow[];
27
+ /** Every node's depth, parent and place among its siblings. */
28
+ export declare function indexTree(nodes: readonly SortableNode[]): Map<string, SortableRow & {
29
+ index: number;
30
+ }>;
31
+ /** The tree without `id` (and what's under it), and that node. */
32
+ export declare function removeNode(nodes: readonly SortableNode[], id: string): [SortableNode[], SortableNode | null];
33
+ /** The tree with `node` put at `place`. */
34
+ export declare function insertNode(nodes: readonly SortableNode[], place: TreePlace, node: SortableNode): SortableNode[];
35
+ /**
36
+ * Everywhere a node can go, given the tree without it and the rows still
37
+ * shown. Between two rows it can be as deep as under the one above, or as
38
+ * shallow as the one below: it joins the group of whichever level it's at.
39
+ * `allowed` says which parents take it.
40
+ */
41
+ export declare function treeSlots(tree: readonly SortableNode[], rows: readonly {
42
+ id: string;
43
+ }[], allowed: (parentId: string | null) => boolean): TreeSlot[];
44
+ /** Of the slots at `gap`, the one nearest `depth`, the shallower on a tie. */
45
+ export declare function nearestSlot(slots: readonly TreeSlot[], gap: number, depth: number): TreeSlot | null;
46
+ //# sourceMappingURL=tree-model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree-model.d.ts","sourceRoot":"","sources":["../../packages/sortable/tree-model.ts"],"names":[],"mappings":"AAAA,uEAAuE;AACvE,MAAM,WAAW,YAAY;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,CAAC,EAAE,YAAY,EAAE,CAAC;CAC7B;AAED,6EAA6E;AAC7E,MAAM,WAAW,WAAW;IACxB,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAED,gGAAgG;AAChG,MAAM,WAAW,SAAS;IACtB,QAAQ,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB,KAAK,EAAE,MAAM,CAAC;CACjB;AAED,2GAA2G;AAC3G,MAAM,WAAW,QAAS,SAAQ,SAAS;IACvC,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,WAAW,CACvB,KAAK,EAAE,SAAS,YAAY,EAAE,EAC9B,IAAI,GAAE,CAAC,EAAE,EAAE,MAAM,KAAK,OAAoB,EAC1C,KAAK,SAAI,EACT,QAAQ,GAAE,MAAM,GAAG,IAAW,GAC/B,WAAW,EAAE,CAKf;AAED,+DAA+D;AAC/D,wBAAgB,SAAS,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE;WACD,MAAM;GAQ5D;AAED,kEAAkE;AAClE,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,YAAY,EAAE,EAAE,YAAY,GAAG,IAAI,CAAC,CAY5G;AAED,2CAA2C;AAC3C,wBAAgB,UAAU,CAAC,KAAK,EAAE,SAAS,YAAY,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,IAAI,EAAE,YAAY,GAAG,YAAY,EAAE,CAS/G;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACrB,IAAI,EAAE,SAAS,YAAY,EAAE,EAC7B,IAAI,EAAE,SAAS;IAAE,EAAE,EAAE,MAAM,CAAA;CAAE,EAAE,EAC/B,OAAO,EAAE,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,GAC9C,QAAQ,EAAE,CA0BZ;AAED,8EAA8E;AAC9E,wBAAgB,WAAW,CAAC,KAAK,EAAE,SAAS,QAAQ,EAAE,EAAE,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,QAAQ,GAAG,IAAI,CAOnG"}
@@ -0,0 +1,87 @@
1
+ //#region packages/sortable/tree-model.ts
2
+ function e(t, n = () => !0, r = 0, i = null) {
3
+ return t.flatMap((t) => [{
4
+ id: t.id,
5
+ depth: r,
6
+ parentId: i
7
+ }, ...t.children?.length && n(t.id) ? e(t.children, n, r + 1, t.id) : []]);
8
+ }
9
+ function t(e) {
10
+ let t = /* @__PURE__ */ new Map(), n = (e, r, i) => e.forEach((e, a) => {
11
+ t.set(e.id, {
12
+ id: e.id,
13
+ depth: r,
14
+ parentId: i,
15
+ index: a
16
+ }), e.children && n(e.children, r + 1, e.id);
17
+ });
18
+ return n(e, 0, null), t;
19
+ }
20
+ function n(e, t) {
21
+ let n = null, r = (e) => e.flatMap((e) => e.id === t ? (n = e, []) : e.children ? [{
22
+ ...e,
23
+ children: r(e.children)
24
+ }] : [e]);
25
+ return [r(e), n];
26
+ }
27
+ function r(e, t, n) {
28
+ return t.parentId === null ? [
29
+ ...e.slice(0, t.index),
30
+ n,
31
+ ...e.slice(t.index)
32
+ ] : e.map((e) => {
33
+ if (e.id === t.parentId) {
34
+ let r = e.children ?? [];
35
+ return {
36
+ ...e,
37
+ children: [
38
+ ...r.slice(0, t.index),
39
+ n,
40
+ ...r.slice(t.index)
41
+ ]
42
+ };
43
+ }
44
+ return e.children ? {
45
+ ...e,
46
+ children: r(e.children, t, n)
47
+ } : e;
48
+ });
49
+ }
50
+ function i(e, n, r) {
51
+ let i = t(e), a = (e, t) => {
52
+ let n = i.get(e);
53
+ for (; n.depth > t;) n = i.get(n.parentId);
54
+ return n;
55
+ }, o = [];
56
+ for (let e = 0; e <= n.length; e++) {
57
+ let t = e > 0 ? i.get(n[e - 1].id) : void 0, s = e < n.length ? i.get(n[e].id) : void 0, c = t ? t.depth + 1 : 0, l = s ? s.depth : 0;
58
+ for (let n = l; n <= c; n++) {
59
+ let i = t ? n === t.depth + 1 ? {
60
+ parentId: t.id,
61
+ index: 0
62
+ } : (() => {
63
+ let e = a(t.id, n);
64
+ return {
65
+ parentId: e.parentId,
66
+ index: e.index + 1
67
+ };
68
+ })() : {
69
+ parentId: null,
70
+ index: 0
71
+ };
72
+ r(i.parentId) && o.push({
73
+ ...i,
74
+ gap: e,
75
+ depth: n
76
+ });
77
+ }
78
+ }
79
+ return o;
80
+ }
81
+ function a(e, t, n) {
82
+ let r = null;
83
+ for (let i of e) i.gap === t && (!r || Math.abs(i.depth - n) < Math.abs(r.depth - n)) && (r = i);
84
+ return r;
85
+ }
86
+ //#endregion
87
+ export { e as flattenTree, t as indexTree, r as insertNode, a as nearestSlot, n as removeNode, i as treeSlots };
@@ -0,0 +1,31 @@
1
+ import { ComponentProps } from 'react';
2
+ import { SortableNode } from './tree-model';
3
+ /**
4
+ * Items in groups, and groups in groups, put in order by dragging: an item
5
+ * can go anywhere in its group, into another group (or one open inside it),
6
+ * or under another item. While dragging, a glowing line shows where it will
7
+ * land, set in as deep as it'll go, and the group it would join is lit; drag
8
+ * sideways to go a level in or out. From the keyboard, Space or Enter on a
9
+ * handle picks it up, the up and down arrows move it through every place it
10
+ * can go, left and right a level out or in, Space or Enter drops it and
11
+ * Escape puts it back; each step is announced.
12
+ *
13
+ * `value` is the tree of ids. Render a SortableItem for each row shown, in
14
+ * order (flattenTree lists them, with their depths): what's under a closed
15
+ * one isn't shown, and moves with it. `accepts` says which group takes which
16
+ * item. With `asChild`, your own element (a Table, its rows SortableItems with
17
+ * asChild on TableRows) instead of a ul.
18
+ */
19
+ export default function SortableTree({ value, onValueChange, accepts, indent, asChild, className, children, ref, ...rest }: SortableTreeProps): import('react').JSX.Element;
20
+ export interface SortableTreeProps extends ComponentProps<'ul'> {
21
+ /** The tree of ids, in order. */
22
+ value: readonly SortableNode[];
23
+ onValueChange: (value: SortableNode[]) => void;
24
+ /** Whether `parentId` (null: the top level) takes item `id`; by default, everything goes anywhere. */
25
+ accepts?: (id: string, parentId: string | null) => boolean;
26
+ /** How far in a level is set, in px: the drop line is set in this far, and dragging this far sideways goes a level in or out. */
27
+ indent?: number;
28
+ /** Put its props on your own element (the single child, e.g. a Table) instead of a ul. */
29
+ asChild?: boolean;
30
+ }
31
+ //# sourceMappingURL=tree.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tree.d.ts","sourceRoot":"","sources":["../../packages/sortable/tree.tsx"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAA6E,MAAM,OAAO,CAAC;AAGlH,OAAO,EAKH,KAAK,YAAY,EAIpB,MAAM,cAAc,CAAC;AAStB;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,EACjC,KAAK,EACL,aAAa,EACb,OAAO,EACP,MAAW,EACX,OAAO,EACP,SAAS,EACT,QAAQ,EACR,GAAG,EACH,GAAG,IAAI,EACV,EAAE,iBAAiB,+BA6MnB;AAuBD,MAAM,WAAW,iBAAkB,SAAQ,cAAc,CAAC,IAAI,CAAC;IAC3D,iCAAiC;IACjC,KAAK,EAAE,SAAS,YAAY,EAAE,CAAC;IAC/B,aAAa,EAAE,CAAC,KAAK,EAAE,YAAY,EAAE,KAAK,IAAI,CAAC;IAC/C,sGAAsG;IACtG,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,IAAI,KAAK,OAAO,CAAC;IAC3D,iIAAiI;IACjI,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,0FAA0F;IAC1F,OAAO,CAAC,EAAE,OAAO,CAAC;CACrB"}