viewkitjs 0.26.0 → 0.28.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 (294) hide show
  1. package/CHANGELOG.md +95 -0
  2. package/MIGRATION.md +122 -7
  3. package/package.json +1 -1
  4. package/views/dist/cells/cell-format.d.ts +3 -1
  5. package/views/dist/cells/cell-format.js +2 -2
  6. package/views/dist/cells/use-cell-format.d.ts +8 -1
  7. package/views/dist/cells/use-cell-format.js +13 -2
  8. package/views/dist/contract.d.ts +240 -3
  9. package/views/dist/contract.js +238 -0
  10. package/views/dist/controls/alert/alert.d.ts +46 -0
  11. package/views/dist/controls/alert/alert.js +11 -0
  12. package/views/dist/controls/alert/looks.d.ts +4 -0
  13. package/views/dist/controls/alert/looks.js +19 -0
  14. package/views/dist/controls/alert/tokens.d.ts +92 -0
  15. package/views/dist/controls/alert/tokens.js +25 -0
  16. package/views/dist/controls/alert-dialog/alert-dialog.d.ts +50 -0
  17. package/views/dist/controls/alert-dialog/alert-dialog.js +67 -0
  18. package/views/dist/controls/alert-dialog/confirm.d.ts +13 -0
  19. package/views/dist/controls/alert-dialog/confirm.js +11 -0
  20. package/views/dist/controls/alert-dialog/looks.d.ts +4 -0
  21. package/views/dist/controls/alert-dialog/looks.js +17 -0
  22. package/views/dist/controls/alert-dialog/tokens.d.ts +119 -0
  23. package/views/dist/controls/alert-dialog/tokens.js +32 -0
  24. package/views/dist/controls/alert-dialog.css +95 -0
  25. package/views/dist/controls/alert.css +51 -0
  26. package/views/dist/controls/collapsible/collapsible.d.ts +39 -0
  27. package/views/dist/controls/collapsible/collapsible.js +18 -0
  28. package/views/dist/controls/collapsible/looks.d.ts +4 -0
  29. package/views/dist/controls/collapsible/looks.js +5 -0
  30. package/views/dist/controls/collapsible/map-collapse.d.ts +2 -0
  31. package/views/dist/controls/collapsible/map-collapse.js +6 -0
  32. package/views/dist/controls/collapsible/tokens.d.ts +68 -0
  33. package/views/dist/controls/collapsible/tokens.js +19 -0
  34. package/views/dist/controls/collapsible.css +83 -0
  35. package/views/dist/controls/compound-editor/map-parts-body.js +2 -1
  36. package/views/dist/controls/compound-editor/name-parts.js +10 -2
  37. package/views/dist/controls/compound-editor/place-parts.js +5 -1
  38. package/views/dist/controls/compound-editor/place.d.ts +2 -1
  39. package/views/dist/controls/compound-editor/place.js +2 -0
  40. package/views/dist/controls/controls.d.ts +17 -0
  41. package/views/dist/controls/controls.js +17 -0
  42. package/views/dist/controls/date-editor/date-editor.d.ts +2 -1
  43. package/views/dist/controls/date-editor/map-calendar.js +3 -1
  44. package/views/dist/controls/filter-editor/filter-editor.d.ts +56 -0
  45. package/views/dist/controls/filter-editor/filter-editor.js +208 -0
  46. package/views/dist/controls/filter-editor/how.d.ts +23 -0
  47. package/views/dist/controls/filter-editor/how.js +13 -0
  48. package/views/dist/controls/filter-editor/map-filter-body.d.ts +18 -0
  49. package/views/dist/controls/filter-editor/map-filter-body.js +164 -0
  50. package/views/dist/controls/filter-editor/map-rules.d.ts +85 -0
  51. package/views/dist/controls/filter-editor/map-rules.js +273 -0
  52. package/views/dist/controls/filter-editor/parts.d.ts +46 -0
  53. package/views/dist/controls/filter-editor/parts.js +75 -0
  54. package/views/dist/controls/filter-editor/rules.d.ts +104 -0
  55. package/views/dist/controls/filter-editor/rules.js +148 -0
  56. package/views/dist/controls/filter-editor/tokens.d.ts +83 -0
  57. package/views/dist/controls/filter-editor/tokens.js +23 -0
  58. package/views/dist/controls/filter-editor/words.d.ts +59 -0
  59. package/views/dist/controls/filter-editor/words.js +40 -0
  60. package/views/dist/controls/filter-editor.css +124 -0
  61. package/views/dist/controls/group-editor/group-editor.d.ts +56 -0
  62. package/views/dist/controls/group-editor/group-editor.js +126 -0
  63. package/views/dist/controls/group-editor/map-group-body.d.ts +19 -0
  64. package/views/dist/controls/group-editor/map-group-body.js +106 -0
  65. package/views/dist/controls/group-editor/rules.d.ts +48 -0
  66. package/views/dist/controls/group-editor/rules.js +41 -0
  67. package/views/dist/controls/group-editor/tokens.d.ts +15 -0
  68. package/views/dist/controls/group-editor/tokens.js +6 -0
  69. package/views/dist/controls/group-editor/words.d.ts +39 -0
  70. package/views/dist/controls/group-editor/words.js +21 -0
  71. package/views/dist/controls/group-editor.css +20 -0
  72. package/views/dist/controls/index.d.ts +35 -1
  73. package/views/dist/controls/index.js +35 -1
  74. package/views/dist/controls/internal/editor-parts.d.ts +47 -0
  75. package/views/dist/controls/internal/editor-parts.js +48 -0
  76. package/views/dist/controls/internal/step-return.d.ts +9 -0
  77. package/views/dist/controls/internal/step-return.js +27 -0
  78. package/views/dist/controls/links-editor/links-editor.d.ts +80 -0
  79. package/views/dist/controls/links-editor/links-editor.js +329 -0
  80. package/views/dist/controls/links-editor/links.d.ts +62 -0
  81. package/views/dist/controls/links-editor/links.js +50 -0
  82. package/views/dist/controls/links-editor/map-links-body.d.ts +10 -0
  83. package/views/dist/controls/links-editor/map-links-body.js +74 -0
  84. package/views/dist/controls/links-editor/tokens.d.ts +71 -0
  85. package/views/dist/controls/links-editor/tokens.js +20 -0
  86. package/views/dist/controls/links-editor/words.d.ts +56 -0
  87. package/views/dist/controls/links-editor/words.js +33 -0
  88. package/views/dist/controls/links-editor.css +132 -0
  89. package/views/dist/controls/menu-list/menu-list.d.ts +17 -2
  90. package/views/dist/controls/menu-list/menu-list.js +25 -16
  91. package/views/dist/controls/modal/looks.d.ts +4 -0
  92. package/views/dist/controls/modal/looks.js +25 -0
  93. package/views/dist/controls/modal/modal.d.ts +69 -0
  94. package/views/dist/controls/modal/modal.js +62 -0
  95. package/views/dist/controls/modal/tokens.d.ts +192 -0
  96. package/views/dist/controls/modal/tokens.js +50 -0
  97. package/views/dist/controls/modal.css +130 -0
  98. package/views/dist/controls/notice/notice.d.ts +49 -0
  99. package/views/dist/controls/notice/notice.js +35 -0
  100. package/views/dist/controls/notice/tokens.d.ts +99 -0
  101. package/views/dist/controls/notice/tokens.js +27 -0
  102. package/views/dist/controls/notice.css +100 -0
  103. package/views/dist/controls/number-editor/format.d.ts +31 -0
  104. package/views/dist/controls/number-editor/format.js +79 -0
  105. package/views/dist/controls/number-editor/looks.d.ts +14 -0
  106. package/views/dist/controls/number-editor/looks.js +17 -0
  107. package/views/dist/controls/number-editor/map-number-body.d.ts +16 -0
  108. package/views/dist/controls/number-editor/map-number-body.js +57 -0
  109. package/views/dist/controls/number-editor/number-editor.d.ts +72 -0
  110. package/views/dist/controls/number-editor/number-editor.js +202 -0
  111. package/views/dist/controls/number-editor/tokens.d.ts +28 -0
  112. package/views/dist/controls/number-editor/tokens.js +9 -0
  113. package/views/dist/controls/number-editor/words.d.ts +23 -0
  114. package/views/dist/controls/number-editor/words.js +13 -0
  115. package/views/dist/controls/number-editor.css +37 -0
  116. package/views/dist/controls/number-field/number-field.js +57 -5
  117. package/views/dist/controls/pane/looks.d.ts +4 -0
  118. package/views/dist/controls/pane/looks.js +11 -0
  119. package/views/dist/controls/pane/pane.d.ts +63 -0
  120. package/views/dist/controls/pane/pane.js +98 -0
  121. package/views/dist/controls/pane/state.d.ts +14 -0
  122. package/views/dist/controls/pane/state.js +7 -0
  123. package/views/dist/controls/pane/tokens.d.ts +79 -0
  124. package/views/dist/controls/pane/tokens.js +22 -0
  125. package/views/dist/controls/pane.css +104 -0
  126. package/views/dist/controls/picker/rows.d.ts +4 -2
  127. package/views/dist/controls/picker/rows.js +4 -3
  128. package/views/dist/controls/radio/radio.d.ts +33 -0
  129. package/views/dist/controls/radio/radio.js +19 -0
  130. package/views/dist/controls/radio/tokens.d.ts +127 -0
  131. package/views/dist/controls/radio/tokens.js +34 -0
  132. package/views/dist/controls/radio.css +104 -0
  133. package/views/dist/controls/sort-editor/map-sort-body.d.ts +9 -0
  134. package/views/dist/controls/sort-editor/map-sort-body.js +81 -0
  135. package/views/dist/controls/sort-editor/rules.d.ts +48 -0
  136. package/views/dist/controls/sort-editor/rules.js +24 -0
  137. package/views/dist/controls/sort-editor/sort-editor.d.ts +58 -0
  138. package/views/dist/controls/sort-editor/sort-editor.js +180 -0
  139. package/views/dist/controls/sort-editor/tokens.d.ts +79 -0
  140. package/views/dist/controls/sort-editor/tokens.js +22 -0
  141. package/views/dist/controls/sort-editor/words.d.ts +48 -0
  142. package/views/dist/controls/sort-editor/words.js +25 -0
  143. package/views/dist/controls/sort-editor.css +96 -0
  144. package/views/dist/controls/text-editor/phone-number.d.ts +4 -0
  145. package/views/dist/controls/text-editor/phone-number.js +20 -0
  146. package/views/dist/controls/text-editor/text-editor.js +2 -19
  147. package/views/dist/controls/toast/toast.d.ts +75 -0
  148. package/views/dist/controls/toast/toast.js +99 -0
  149. package/views/dist/controls/toast/tokens.d.ts +100 -0
  150. package/views/dist/controls/toast/tokens.js +27 -0
  151. package/views/dist/controls/toast.css +93 -0
  152. package/views/dist/controls/tokens.js +30 -0
  153. package/views/dist/controls/values-editor/looks.d.ts +16 -0
  154. package/views/dist/controls/values-editor/looks.js +19 -0
  155. package/views/dist/controls/values-editor/map-values-body.d.ts +12 -0
  156. package/views/dist/controls/values-editor/map-values-body.js +71 -0
  157. package/views/dist/controls/values-editor/tokens.d.ts +132 -0
  158. package/views/dist/controls/values-editor/tokens.js +35 -0
  159. package/views/dist/controls/values-editor/values-editor.d.ts +62 -0
  160. package/views/dist/controls/values-editor/values-editor.js +441 -0
  161. package/views/dist/controls/values-editor/values.d.ts +71 -0
  162. package/views/dist/controls/values-editor/values.js +59 -0
  163. package/views/dist/controls/values-editor/words.d.ts +50 -0
  164. package/views/dist/controls/values-editor/words.js +29 -0
  165. package/views/dist/controls/values-editor.css +207 -0
  166. package/views/dist/controls/views-list/looks.d.ts +13 -0
  167. package/views/dist/controls/views-list/looks.js +12 -0
  168. package/views/dist/controls/views-list/map-views-list-body.d.ts +19 -0
  169. package/views/dist/controls/views-list/map-views-list-body.js +65 -0
  170. package/views/dist/controls/views-list/rules.d.ts +72 -0
  171. package/views/dist/controls/views-list/rules.js +4 -0
  172. package/views/dist/controls/views-list/tokens.d.ts +11 -0
  173. package/views/dist/controls/views-list/tokens.js +5 -0
  174. package/views/dist/controls/views-list/views-list.d.ts +44 -0
  175. package/views/dist/controls/views-list/views-list.js +57 -0
  176. package/views/dist/controls/views-list/words.d.ts +22 -0
  177. package/views/dist/controls/views-list/words.js +3 -0
  178. package/views/dist/controls/views-list.css +8 -0
  179. package/views/dist/display/date.js +2 -2
  180. package/views/dist/display/format.js +10 -2
  181. package/views/dist/display/options.d.ts +3 -1
  182. package/views/dist/display/use-display-options.d.ts +3 -0
  183. package/views/dist/display/use-display-options.js +10 -2
  184. package/views/dist/display/viewer.d.ts +1 -1
  185. package/views/dist/display/viewer.js +1 -1
  186. package/views/dist/editors/DateEditor.js +11 -9
  187. package/views/dist/editors/NumberEditor.js +3 -1
  188. package/views/dist/editors/relation-panel.js +7 -1
  189. package/views/dist/editors/relation-picker.d.ts +2 -1
  190. package/views/dist/editors/relation-picker.js +4 -3
  191. package/views/dist/editors/relation-source.d.ts +4 -1
  192. package/views/dist/editors/relation-source.js +5 -2
  193. package/views/dist/field-row/editors/RowNumberEditor.js +2 -2
  194. package/views/dist/fields/number-edit.d.ts +6 -0
  195. package/views/dist/fields/number-edit.js +8 -1
  196. package/views/dist/grid/chrome/GridCellEditors.js +3 -3
  197. package/views/dist/grid/chrome/GridColumnDateSection.d.ts +4 -3
  198. package/views/dist/grid/chrome/GridColumnDateSection.js +4 -4
  199. package/views/dist/grid/chrome/GridColumnDurationSection.js +2 -2
  200. package/views/dist/grid/chrome/GridColumnMenu.js +6 -4
  201. package/views/dist/grid/chrome/GridDateEditor.d.ts +3 -1
  202. package/views/dist/grid/chrome/GridDateEditor.js +2 -1
  203. package/views/dist/grid/chrome/GridFooter.js +2 -2
  204. package/views/dist/grid/chrome/grid-column-menu-items.js +4 -2
  205. package/views/dist/grid/chrome/useGridBandFigures.js +2 -2
  206. package/views/dist/grid/chrome/useGridFittedWidths.d.ts +3 -0
  207. package/views/dist/grid/chrome/useGridFittedWidths.js +9 -3
  208. package/views/dist/grid/chrome/useGridKeyboard.d.ts +4 -1
  209. package/views/dist/grid/chrome/useGridKeyboard.js +5 -2
  210. package/views/dist/grid/chrome/useGridTableInteractionModel.js +2 -1
  211. package/views/dist/grid/core/commit-model.d.ts +7 -0
  212. package/views/dist/grid/core/commit-model.js +5 -1
  213. package/views/dist/grid/core/editing-controller.js +10 -2
  214. package/views/dist/grid/core/editing-model.js +3 -7
  215. package/views/dist/grid/core/undo-owner.d.ts +6 -0
  216. package/views/dist/grid/core/undo-owner.js +13 -0
  217. package/views/dist/grid/core/useGridEditing.d.ts +2 -0
  218. package/views/dist/grid/core/useGridEditing.js +4 -0
  219. package/views/dist/looks/index.d.ts +8 -0
  220. package/views/dist/looks/index.js +8 -0
  221. package/views/dist/looks/pieces.js +16 -0
  222. package/views/dist/panels/model.d.ts +6 -1
  223. package/views/dist/panels/react/customize-body.d.ts +4 -2
  224. package/views/dist/panels/react/customize-body.js +3 -3
  225. package/views/dist/panels/react/customize.js +4 -2
  226. package/views/dist/panels/react/filter/FilterEditor.js +2 -2
  227. package/views/dist/panels/react/filter/PhoneFilterEditor.d.ts +8 -2
  228. package/views/dist/panels/react/filter/PhoneFilterEditor.js +9 -6
  229. package/views/dist/panels/react/filter/filter-body.d.ts +8 -5
  230. package/views/dist/panels/react/filter/filter-body.js +17 -6
  231. package/views/dist/panels/react/filter/filter-part-body.d.ts +4 -1
  232. package/views/dist/panels/react/filter/filter-part-body.js +3 -1
  233. package/views/dist/panels/react/panel-sheet.d.ts +5 -1
  234. package/views/dist/panels/react/panel-sheet.js +6 -2
  235. package/views/dist/panels/react/panel-step.d.ts +12 -0
  236. package/views/dist/panels/react/panel-step.js +26 -0
  237. package/views/dist/panels/react/sort/SortEditor.d.ts +4 -0
  238. package/views/dist/panels/react/sort/SortEditor.js +5 -2
  239. package/views/dist/panels/react/toolbar/ReadyToolbar.d.ts +8 -0
  240. package/views/dist/panels/react/toolbar/ReadyToolbar.js +84 -2
  241. package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +2 -2
  242. package/views/dist/panels/react/toolbar/ToolbarFilterAdd.d.ts +16 -0
  243. package/views/dist/panels/react/toolbar/ToolbarFilterAdd.js +49 -0
  244. package/views/dist/panels/react/toolbar/ToolbarFilterSheet.js +3 -1
  245. package/views/dist/panels/react/toolbar/ToolbarFilters.d.ts +4 -1
  246. package/views/dist/panels/react/toolbar/ToolbarFilters.js +36 -21
  247. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.d.ts +4 -1
  248. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +2 -2
  249. package/views/dist/panels/react/toolbar/ToolbarSortPill.d.ts +5 -0
  250. package/views/dist/panels/react/toolbar/ToolbarSortPill.js +15 -6
  251. package/views/dist/panels/react/toolbar/panel-part.d.ts +5 -1
  252. package/views/dist/panels/react/toolbar/panel-part.js +2 -2
  253. package/views/dist/panels/react/toolbar/use-filter-add.d.ts +16 -0
  254. package/views/dist/panels/react/toolbar/use-filter-add.js +32 -0
  255. package/views/dist/panels/react.d.ts +1 -0
  256. package/views/dist/panels/react.js +1 -0
  257. package/views/dist/panels/settings/filter-groups.js +35 -1
  258. package/views/dist/panels/settings/group-buckets.js +1 -0
  259. package/views/dist/provider/ViewsProvider.d.ts +7 -1
  260. package/views/dist/provider/ViewsProvider.js +23 -3
  261. package/views/dist/provider/components.d.ts +34 -4
  262. package/views/dist/provider/moment.d.ts +6 -0
  263. package/views/dist/provider/moment.js +10 -0
  264. package/views/dist/styles.css +1276 -51
  265. package/views/dist/styles.unlayered.css +1277 -51
  266. package/views/docs/contract.md +23 -15
  267. package/views/docs/controls/alert-dialog.md +37 -0
  268. package/views/docs/controls/alert.md +30 -0
  269. package/views/docs/controls/collapsible.md +22 -0
  270. package/views/docs/controls/filter-editor.md +28 -0
  271. package/views/docs/controls/group-editor.md +11 -0
  272. package/views/docs/controls/links-editor.md +25 -0
  273. package/views/docs/controls/modal.md +55 -0
  274. package/views/docs/controls/notice.md +32 -0
  275. package/views/docs/controls/number-editor.md +12 -0
  276. package/views/docs/controls/pane.md +25 -0
  277. package/views/docs/controls/radio.md +39 -0
  278. package/views/docs/controls/sort-editor.md +27 -0
  279. package/views/docs/controls/toast.md +32 -0
  280. package/views/docs/controls/values-editor.md +40 -0
  281. package/views/docs/controls/views-list.md +8 -0
  282. package/views/docs/guides/cells.md +1 -1
  283. package/views/docs/guides/display.md +1 -1
  284. package/views/docs/guides/the-grid.md +1 -1
  285. package/views/docs/guides/the-provider.md +19 -0
  286. package/views/docs/reference/cells.md +2 -2
  287. package/views/docs/reference/controls.md +326 -8
  288. package/views/docs/reference/display.md +2 -2
  289. package/views/docs/reference/editors-relation.md +1 -1
  290. package/views/docs/reference/looks.md +20 -3
  291. package/views/docs/reference/panels-react.md +7 -6
  292. package/views/docs/reference/panels.md +1 -1
  293. package/views/docs/reference/react.md +8 -8
  294. package/views/docs/reference/views.md +1 -0
@@ -0,0 +1,202 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Button } from "../button/button.js";
5
+ import { InputGroupButton } from "../input/input.js";
6
+ import { PhoneHost, phoneMark, usePhone, usePhoneForm } from "../internal/phone.js";
7
+ import { NumberField } from "../number-field/number-field.js";
8
+ import { Picker, usePicker } from "../picker/picker.js";
9
+ import { Popover } from "../popover/popover.js";
10
+ import { SheetButton } from "../sheet/bottom-sheet.js";
11
+ import { boxLocale, readTyped } from "./format.js";
12
+ import { NUMBER_EDITOR_ATTRS, numberEditorWornOf } from "./looks.js";
13
+ import { numberWords } from "./words.js";
14
+ const glyph = (paths, className) => (_jsx("svg", { className: className, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: 2, strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", children: paths.map((d) => _jsx("path", { d: d }, d)) }));
15
+ const X = ["M18 6l-12 12", "M6 6l12 12"], TICK = ["M5 12l5 5l10 -10"], DOWN = ["M6 9l6 6l6 -6"];
16
+ const ATTIO = numberEditorWornOf(null);
17
+ export function useNumberEditorWorn() {
18
+ const [el, setEl] = React.useState(null), [worn, setWorn] = React.useState(ATTIO);
19
+ React.useLayoutEffect(() => {
20
+ if (!el)
21
+ return;
22
+ const read = () => setWorn((now) => { const next = numberEditorWornOf(el); return Object.keys(next).every((k) => now[k] === next[k]) ? now : next; });
23
+ read();
24
+ const watch = new MutationObserver(read);
25
+ watch.observe(document.documentElement, { attributes: true, subtree: true, attributeFilter: NUMBER_EDITOR_ATTRS });
26
+ return () => watch.disconnect();
27
+ }, [el]);
28
+ return [setEl, worn];
29
+ }
30
+ const bare = (decimals) => ({ useGrouping: false, maximumFractionDigits: decimals });
31
+ const setText = typeof HTMLInputElement === "undefined" ? undefined : Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")?.set;
32
+ function useKeeping({ form, autoFocus = true }) {
33
+ const host = React.useContext(PhoneHost), small = usePhone();
34
+ const focusOnce = React.useRef(autoFocus), latest = React.useRef(null);
35
+ const box = React.useCallback((el) => {
36
+ if (!el)
37
+ return;
38
+ const asked = !!latest.current;
39
+ latest.current = el;
40
+ if (focusOnce.current && !asked)
41
+ requestAnimationFrame(() => {
42
+ if (!focusOnce.current)
43
+ return;
44
+ focusOnce.current = false;
45
+ if (latest.current?.isConnected)
46
+ latest.current.focus({ preventScroll: true });
47
+ });
48
+ }, []);
49
+ return { phone: (form ?? (host || small ? "phone" : "computer")) === "phone", box };
50
+ }
51
+ function homeOrEnd(e) {
52
+ if ((e.key !== "Home" && e.key !== "End") || e.altKey || e.ctrlKey || e.metaKey)
53
+ return false;
54
+ e.preventBaseUIHandler?.();
55
+ return true;
56
+ }
57
+ export function useNumberEditor(props) {
58
+ const { label, kind = "number", value, currency, currencies = [], unit, units = [], onValueChange, onDone, min, max, step = 1, decimals = 2, locale, decimal, align = "end", typed, popupData } = props;
59
+ const shell = props.draft === "shell";
60
+ const { phone, box } = useKeeping(props);
61
+ const settled = React.useRef(false);
62
+ const [wornAt, worn] = useNumberEditorWorn();
63
+ const money = kind === "money";
64
+ const list = money ? currencies : kind === "number" ? units : [], held = money ? currency : kind === "number" ? unit : undefined;
65
+ const [draft, setDraft] = React.useState(value), [ownCode, setCode] = React.useState(held);
66
+ const code = shell ? held : ownCode;
67
+ const [choosing, setChoosing] = React.useState(false), [chip, setChip] = React.useState(null);
68
+ const input = React.useRef(null);
69
+ const pickable = list.length > 1;
70
+ const now = list.find((c) => c.code === code) ?? list[0];
71
+ const w = numberWords(props.words);
72
+ const words = money ? { name: w.currency, find: w.findCurrency, search: w.searchCurrency } : { name: w.unit, find: w.findUnit, search: w.searchUnit };
73
+ const named = now ? w.named(words.name, now.name) : undefined;
74
+ const steps = { increase: w.increase, decrease: w.decrease, field: w.numberField };
75
+ const device = phoneMark(usePhoneForm());
76
+ const keep = () => {
77
+ settled.current = true;
78
+ if (draft !== value || code !== held)
79
+ onValueChange(draft, money || list.length ? code : undefined);
80
+ onDone?.();
81
+ };
82
+ const leave = () => { settled.current = true; setDraft(value); setCode(held); onDone?.(); };
83
+ const pick = (c) => { if (shell)
84
+ onValueChange(value, c);
85
+ else
86
+ setCode(c); };
87
+ const was = React.useRef({ value, currency: held });
88
+ React.useLayoutEffect(() => { was.current = { value, currency: held }; });
89
+ const placeRoot = React.useCallback((el) => { wornAt(el); if (!el) {
90
+ setDraft(was.current.value);
91
+ setCode(was.current.currency);
92
+ setChoosing(false);
93
+ settled.current = false;
94
+ } }, [wornAt, setDraft, setCode, setChoosing]);
95
+ const items = list.map((c) => ({ value: c.code, label: c.name, also: [c.code], ...(c.sign ? { as: { sign: c.sign } } : {}) }));
96
+ const back = () => { setChoosing(false); requestAnimationFrame(() => input.current?.focus({ preventScroll: true })); };
97
+ const picker = usePicker({ label: words.name, items, value: code ?? null, onValueChange: (c) => { if (typeof c === "string")
98
+ pick(c); }, onDone: back, search: phone ? words.search : words.find, form: phone ? "phone" : "computer", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) });
99
+ const onKeyDown = (e) => {
100
+ if (homeOrEnd(e))
101
+ return;
102
+ if (e.nativeEvent.isComposing)
103
+ return;
104
+ if (shell) {
105
+ if (e.key === "Enter") {
106
+ e.preventDefault();
107
+ onDone?.();
108
+ }
109
+ return;
110
+ }
111
+ if (e.key === "Escape") {
112
+ e.preventDefault();
113
+ leave();
114
+ }
115
+ else if (e.key === "Enter") {
116
+ e.preventDefault();
117
+ input.current?.blur();
118
+ }
119
+ };
120
+ const readChange = shell ? (e) => {
121
+ const el = input.current, t = el?.value ?? "";
122
+ if (!el || e.target !== el || !t.trim() || (/\p{Nd}/u.test(t) && /[^\x00-\x7f\s\u00a0\u202f\u2212\u2012-\u2015]/.test(t)))
123
+ return;
124
+ onValueChange(readTyped(t, decimal));
125
+ } : undefined;
126
+ const seeded = React.useRef(false), opening = React.useRef({ shell, typed });
127
+ const refs = React.useCallback((el) => {
128
+ input.current = el;
129
+ box(el);
130
+ if (!el || !opening.current.shell)
131
+ return;
132
+ const t = opening.current.typed;
133
+ if (t != null && !seeded.current && setText) {
134
+ seeded.current = true;
135
+ queueMicrotask(() => { const now = input.current; if (!now?.isConnected)
136
+ return; setText.call(now, t); now.dispatchEvent(new Event("input", { bubbles: true })); });
137
+ }
138
+ }, [box]);
139
+ const field = React.useCallback((el) => refs(inputOf(el)), [refs]);
140
+ const format = React.useMemo(() => bare(decimals), [decimals]);
141
+ const shared = {
142
+ value: shell ? (value == null || Number.isNaN(value) ? null : value) : draft,
143
+ onValueChange: (v, d) => { if (!shell)
144
+ setDraft(v);
145
+ else if (d?.reason !== "input-blur")
146
+ onValueChange(v); },
147
+ min, max, step, largeStep: step * 10, format, locale: boxLocale(locale, decimal),
148
+ onFocus: shell ? (e) => { const t = e.currentTarget, n = t.value.length; try {
149
+ t.setSelectionRange(n, n);
150
+ }
151
+ catch { } } : undefined,
152
+ };
153
+ if (phone) {
154
+ const codes = worn.units === "code", choose = () => setChoosing(true);
155
+ const enter = (e) => { if (homeOrEnd(e))
156
+ return; if (e.key === "Enter" && !e.nativeEvent.isComposing) {
157
+ e.preventDefault();
158
+ if (shell)
159
+ onDone?.();
160
+ else
161
+ keep();
162
+ } };
163
+ const sign = now?.sign ?? now?.code;
164
+ const fieldStart = now ? (pickable
165
+ ? _jsx(InputGroupButton, { "aria-label": named, iconEnd: glyph(DOWN), onClick: choose, children: codes || !now.sign ? now.code : `${now.sign} ${now.code}` })
166
+ : codes ? _jsx("span", { className: "o-number-editor-code", children: now.code }) : _jsx("span", { className: "o-number-editor-sign", children: sign })) : undefined;
167
+ const boxStart = now ? (pickable
168
+ ? _jsx(Button, { kind: "quiet", size: "sm", className: "o-number-editor-code", look: SHEET_CODE, "aria-label": named, iconEnd: glyph(DOWN), onClick: choose, children: codes || !now.sign ? now.code : `${now.sign} ${now.code}` })
169
+ : _jsx("span", { className: codes ? "o-number-editor-code" : "o-number-editor-sign", children: codes ? now.code : sign })) : undefined;
170
+ const amount = worn.sheet === "field"
171
+ ? _jsx(PhoneField, { ...shared, words: steps, label: label, before: fieldStart, after: kind === "percent" ? "%" : undefined, onKeyDown: enter, box: refs })
172
+ : _jsx(NumberField, { ref: field, size: "lg", steppers: false, words: steps, className: "o-number-editor-sheet", before: boxStart, after: kind === "percent" ? _jsx("span", { className: "o-number-editor-unit", children: "%" }) : undefined, ...shared, "aria-label": label, autofill: false, onKeyDown: enter });
173
+ const body = (_jsx("div", { ref: placeRoot, className: "o-number-editor", "data-kit": "number-editor", ...device, "data-number-form": "phone", onChange: readChange, "data-number-kind": kind, "data-number-step": choosing ? "currency" : undefined, children: choosing ? picker.body : amount }));
174
+ if (choosing)
175
+ return { body, head: { onBack: () => setChoosing(false), close: false }, title: words.name };
176
+ if (shell)
177
+ return { body, head: {} };
178
+ return { body, head: { left: _jsx(SheetButton, { "aria-label": "Close", icon: glyph(X), onClick: leave }), right: _jsx(SheetButton, { kind: "primary", "aria-label": "Save", icon: glyph(TICK), onClick: keep }) } };
179
+ }
180
+ const onBlur = (e) => {
181
+ if (shell || settled.current || choosing || (e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget)))
182
+ return;
183
+ keep();
184
+ };
185
+ const start = !now ? null : worn.units === "code"
186
+ ? (pickable ? _jsx(Button, { ref: setChip, kind: "quiet", size: "xs", className: "o-number-editor-code", "aria-label": named, "aria-expanded": choosing, iconEnd: glyph(DOWN), onClick: () => setChoosing(true), children: now.code }) : null)
187
+ : (pickable ? _jsx(Button, { ref: setChip, kind: "soft", size: "2xs", className: "o-number-editor-currency", "aria-label": named, iconEnd: glyph(DOWN), onClick: () => setChoosing(true), children: now.sign ?? now.code })
188
+ : _jsx("span", { className: "o-number-editor-sign", children: now.sign ?? now.code }));
189
+ const body = (_jsxs("div", { ref: wornAt, className: "o-number-editor", "data-kit": "number-editor", ...device, "data-number-form": "computer", "data-number-kind": kind, onChange: readChange, onBlur: onBlur, onFocus: () => { settled.current = false; }, children: [_jsx(NumberField, { ref: field, chrome: "inline", align: align, words: steps, steppers: worn.arrows === "editing" ? "arrows" : false, before: start ?? undefined, after: kind === "percent" ? _jsx("span", { className: "o-number-editor-unit", children: "%" }) : undefined, ...shared, "aria-label": label, autofill: false, onKeyDown: onKeyDown, className: "o-number-editor-field" }), pickable && chip && (_jsx(Popover, { open: choosing, onOpenChange: (o) => { if (!o)
190
+ back(); }, anchor: chip, "aria-label": words.name, popupData: popupData, children: _jsx(Picker, { label: words.name, items: items, value: code ?? null, onValueChange: (c) => { if (typeof c === "string")
191
+ pick(c); }, onDone: back, search: words.find, form: "computer", fromHeld: true, ...(w.picker ? { words: w.picker } : {}) }) }))] }));
192
+ return { body, head: {} };
193
+ }
194
+ const SHEET_CODE = { radius: "lg" };
195
+ const inputOf = (el) => el?.querySelector("input.o-input-control") ?? null;
196
+ function PhoneField({ label, before, after, onKeyDown, box, ...field }) {
197
+ const root = React.useCallback((el) => box(inputOf(el)), [box]);
198
+ return _jsx(NumberField, { ref: root, size: "lg", steppers: false, "aria-label": label, before: before, after: after, autofill: false, onKeyDown: onKeyDown, ...field });
199
+ }
200
+ export function NumberEditor(props) {
201
+ return _jsx(_Fragment, { children: useNumberEditor(props).body });
202
+ }
@@ -0,0 +1,28 @@
1
+ export declare const NUMBER_EDITOR_TOKENS: readonly [{
2
+ readonly name: "--vk-border-width";
3
+ readonly kind: "size";
4
+ readonly outright: "--border-width";
5
+ }, {
6
+ readonly name: "--vk-fg";
7
+ readonly kind: "colour";
8
+ readonly outright: "--text";
9
+ }, {
10
+ readonly name: "--vk-fg-subtle";
11
+ readonly kind: "colour";
12
+ readonly outright: "--text-subtle";
13
+ }, {
14
+ readonly name: "--vk-font-size-base";
15
+ readonly kind: "size";
16
+ readonly outright: "--text-base";
17
+ }, {
18
+ readonly name: "--vk-font-size-sm";
19
+ readonly kind: "size";
20
+ readonly outright: "--text-sm";
21
+ }, {
22
+ readonly name: "--vk-spacing";
23
+ readonly kind: "size";
24
+ readonly outright: "--spacing";
25
+ }];
26
+ /** The prefixes of the Number editor's own machinery, set and read by it alone: not public. It reads none yet; the family is
27
+ * reserved for it. */
28
+ export declare const NUMBER_EDITOR_PRIVATE: readonly ["--number-editor-"];
@@ -0,0 +1,9 @@
1
+ export const NUMBER_EDITOR_TOKENS = [
2
+ { name: "--vk-border-width", kind: "size", outright: "--border-width" },
3
+ { name: "--vk-fg", kind: "colour", outright: "--text" },
4
+ { name: "--vk-fg-subtle", kind: "colour", outright: "--text-subtle" },
5
+ { name: "--vk-font-size-base", kind: "size", outright: "--text-base" },
6
+ { name: "--vk-font-size-sm", kind: "size", outright: "--text-sm" },
7
+ { name: "--vk-spacing", kind: "size", outright: "--spacing" },
8
+ ];
9
+ export const NUMBER_EDITOR_PRIVATE = ["--number-editor-"];
@@ -0,0 +1,23 @@
1
+ import type { PickerWords } from "../picker/picker.js";
2
+ export interface NumberEditorWords {
3
+ /** Money's currencies: the list's name, its title as a phone's step, and the code button's name before the currency's. */
4
+ currency: string;
5
+ /** A number's units, the same. */
6
+ unit: string;
7
+ /** The lists' searches: on a computer (find) and on a phone (search). */
8
+ findCurrency: string;
9
+ searchCurrency: string;
10
+ findUnit: string;
11
+ searchUnit: string;
12
+ /** The code button's name: the list's name and the currency's or the unit's ("Currency: Euro"). */
13
+ named: (unit: string, name: string) => string;
14
+ /** The number field's two steps, and what a screen reader calls it. */
15
+ increase: string;
16
+ decrease: string;
17
+ numberField: string;
18
+ /** The words of its lists. */
19
+ picker?: Partial<PickerWords>;
20
+ }
21
+ export declare const NUMBER_EDITOR_WORDS: NumberEditorWords;
22
+ /** The words handed over the English. */
23
+ export declare const numberWords: (given?: Partial<NumberEditorWords>) => NumberEditorWords;
@@ -0,0 +1,13 @@
1
+ export const NUMBER_EDITOR_WORDS = {
2
+ currency: "Currency",
3
+ unit: "Unit",
4
+ findCurrency: "Find a currency",
5
+ searchCurrency: "Search for a currency",
6
+ findUnit: "Find a unit",
7
+ searchUnit: "Search for a unit",
8
+ named: (unit, name) => `${unit}: ${name}`,
9
+ increase: "Increase",
10
+ decrease: "Decrease",
11
+ numberField: "Number field",
12
+ };
13
+ export const numberWords = (given) => (given ? { ...NUMBER_EDITOR_WORDS, ...given } : NUMBER_EDITOR_WORDS);
@@ -0,0 +1,37 @@
1
+ /* The Number editor: what a person types a number into, with its unit. Every value is a public name (number-editor/tokens.ts).
2
+ Two looks (looks.ts), their options data attributes on the frame around it: Attio's where nothing is picked, Mihai's under
3
+ its options; its box, line or ring, is the inline input's. On a computer a number fills its cell, the number on the right,
4
+ money's currency at its start, a percent's % after it: in Attio's look a line of the focus colour standing over the cell, as
5
+ the Text editor's does, its up and down arrows at its end; in Mihai's the cell's ring. Its box is the number field inline, and
6
+ on a phone the number field in its quiet box, its own look, or in the Input's look (number-field.css). A range is the
7
+ Compound editor's.
8
+
9
+ The rules sit in the components layer, so a utility class still wins. */
10
+ @layer components {
11
+
12
+ /* ── A number in its cell: Attio's line of the focus colour, Mihai's ring: the kit's Number field in a cell, filling it ── */
13
+ .o-number-editor[data-number-form="computer"] { box-sizing: border-box; width: 100%; height: 100%; min-width: 0; color: var(--vk-fg); }
14
+ .o-number-editor .o-number-editor-field, .o-number-editor .o-number-editor-field > .o-inline-input-group { height: 100%; }
15
+ /* Where a shell stands it: over its cell, the cell's lines under its edge, as Attio's editor stands; in the ring, the cell. */
16
+ .o-number-editor-place { position: absolute; inset: calc(var(--vk-border-width) * -1) 0 calc(var(--vk-border-width) * -1) calc(var(--vk-border-width) * -1); }
17
+ [data-inline-input-edge="ring"] .o-number-editor-place { inset: 0; }
18
+
19
+ /* Money's currency at the box's start, a press away; a field with one currency, its sign alone. A percent's % after it. */
20
+ .o-number-editor-currency { flex: none; margin-right: auto; }
21
+ /* Attio's: the code, a quiet press away from the currencies, or the code alone where nothing can be pressed. */
22
+ .o-number-editor-code { flex: none; margin-right: auto; }
23
+ span.o-number-editor-code { color: var(--vk-fg-subtle); }
24
+ .o-number-editor-sign, .o-number-editor-unit { flex: none; color: var(--vk-fg-subtle); }
25
+ .o-number-editor[data-number-form="computer"] .o-number-editor-sign { margin-right: auto; }
26
+
27
+ /* ── On a phone: the box and what is under it ───────────────────────────────────────────────────────────────────── */
28
+ .o-number-editor[data-number-form="phone"] { display: grid; gap: calc(var(--vk-spacing) * 2); }
29
+
30
+ }
31
+
32
+ /* ── On the phone every box typed into is 16px, so iOS never zooms in: the in-cell box by itself, and the field form's the
33
+ Input's. What stands beside the value (money's code, sign and currency, a percent's %) is the value's size there, Mihai's
34
+ currency chip a step under, as it stands a step under the value on a computer. In the phone's form (`data-vk-phone`, by the
35
+ app's line). ── */
36
+ .o-number-editor :is(.o-number-editor-code, .o-number-editor-sign, .o-number-editor-unit, .o-input-addon > .o-button):where([data-vk-phone], [data-vk-phone] *) { font-size: var(--vk-font-size-base); }
37
+ .o-number-editor .o-input-addon > .o-button.o-number-editor-currency:where([data-vk-phone], [data-vk-phone] *) { font-size: var(--vk-font-size-sm); }
@@ -17,19 +17,71 @@ function pageKeys(e, on) {
17
17
  e.currentTarget.dispatchEvent(new KeyboardEvent("keydown", { key: e.key === "PageUp" ? "ArrowUp" : "ArrowDown", shiftKey: true, bubbles: true, cancelable: true }));
18
18
  }
19
19
  const UP_MARK = _jsx("svg", { viewBox: "0 0 8 5", "aria-hidden": "true", children: _jsx("path", { d: "M0 5h8l-4-5z" }) }), DOWN_MARK = _jsx("svg", { viewBox: "0 0 8 5", "aria-hidden": "true", children: _jsx("path", { d: "M0 0h8l-4 5z" }) });
20
+ const TYPED = new Set(["input-change", "input-clear"]);
21
+ function useTypedRun(hold, inputRef) {
22
+ const typing = React.useRef(false), focused = React.useRef(false), pending = React.useRef(null);
23
+ const node = React.useRef(null), write = React.useRef(null);
24
+ const flush = React.useCallback(() => {
25
+ typing.current = false;
26
+ const v = pending.current;
27
+ pending.current = null;
28
+ if (v != null)
29
+ write.current?.(v);
30
+ }, []);
31
+ const formInput = React.useCallback((el) => {
32
+ if (typeof inputRef === "function")
33
+ inputRef(el);
34
+ else if (inputRef)
35
+ inputRef.current = el;
36
+ if (el === node.current)
37
+ return;
38
+ node.current = el;
39
+ write.current = null;
40
+ pending.current = null;
41
+ if (!el)
42
+ return;
43
+ const own = Object.getOwnPropertyDescriptor(el, "value") ?? Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value");
44
+ write.current = (v) => own.set.call(el, v);
45
+ own.set.call(el, own.get.call(el));
46
+ Object.defineProperty(el, "value", {
47
+ configurable: true,
48
+ get() { return own.get.call(this); },
49
+ set(v) { if (typing.current) {
50
+ pending.current = String(v);
51
+ return;
52
+ } pending.current = null; own.set.call(this, v); },
53
+ });
54
+ }, [inputRef]);
55
+ const seen = (reason) => { if (!hold)
56
+ return; if (TYPED.has(reason) && focused.current)
57
+ typing.current = true;
58
+ else
59
+ flush(); };
60
+ const focus = () => { focused.current = true; };
61
+ const leave = () => { focused.current = false; flush(); };
62
+ const enter = (e) => { if (e.key === "Enter" && !e.nativeEvent.isComposing)
63
+ flush(); };
64
+ return { formInput, seen, focus, leave, enter };
65
+ }
20
66
  const DRAG = _jsx("svg", { viewBox: "0 0 24 24", "aria-hidden": "true", children: _jsx("path", { d: "M8 7l-5 5l5 5M16 7l5 5l-5 5M3 12h18" }) });
21
- export const NumberField = React.forwardRef(function NumberField({ size = "md", before, after, steppers, align = "start", scrub = false, placeholder, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, onKeyDown, onFocus, onBlur, autoFocus, autofill = true, look, chrome, className, style, disabled, readOnly, words, ...root }, ref) {
67
+ export const NumberField = React.forwardRef(function NumberField({ size = "md", before, after, steppers, align = "start", scrub = false, placeholder, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, onKeyDown, onFocus, onBlur, autoFocus, autofill = true, look, chrome, className, style, disabled, readOnly, words, value, onValueChange, inputRef, ...root }, ref) {
22
68
  const fill = useAutofill(), phone = usePhoneForm();
69
+ const typed = useTypedRun(root.name == null, inputRef);
70
+ const values = {
71
+ ...(value !== undefined ? { value } : {}),
72
+ onValueChange: ((next, details) => { typed.seen(details.reason); onValueChange?.(next, details); }),
73
+ inputRef: typed.formInput,
74
+ };
23
75
  const arrows = steppers === "arrows" && !readOnly;
24
76
  const stepped = steppers !== "arrows" && (steppers ?? (size !== "2xs" && size !== "xs" && !readOnly && chrome !== "inline"));
25
77
  const side = (where, what) => what == null ? null : scrub
26
78
  ? _jsxs(BaseNumberField.ScrubArea, { className: "o-number-scrub", render: (props) => _jsx(InputGroupAddon, { side: where, ...props, children: props.children }), children: [what, _jsx(BaseNumberField.ScrubAreaCursor, { className: "o-number-cursor", children: DRAG })] }, where)
27
79
  : _jsx(InputGroupAddon, { side: where, children: what }, where);
28
- const input = (_jsx(BaseNumberField.Input, { className: cx("o-input-control o-input-num", align === "end" && "o-number-end"), ...fill(autofill), placeholder: placeholder, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, autoFocus: autoFocus, ...(words?.field ? { "aria-roledescription": words.field } : {}), onKeyDown: (e) => { onKeyDown?.(e); if (!e.defaultPrevented)
29
- pageKeys(e, !disabled && !readOnly); }, onFocus: onFocus, onBlur: onBlur }));
80
+ const input = (_jsx(BaseNumberField.Input, { className: cx("o-input-control o-input-num", align === "end" && "o-number-end"), ...fill(autofill), placeholder: placeholder, "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, autoFocus: autoFocus, ...(words?.field ? { "aria-roledescription": words.field } : {}), onKeyDown: (e) => { typed.enter(e); onKeyDown?.(e); if (!e.defaultPrevented)
81
+ pageKeys(e, !disabled && !readOnly); }, onFocus: (e) => { typed.focus(); onFocus?.(e); }, onBlur: (e) => { typed.leave(); onBlur?.(e); } }));
30
82
  if (chrome === "bare")
31
- return (_jsx(BaseNumberField.Root, { ref: ref, className: cx("o-number o-number-bare", className), style: style, disabled: disabled, readOnly: readOnly, "data-kit": "number-field", ...phoneMark(phone), ...root, children: input }));
32
- return (_jsx(BaseNumberField.Root, { ref: ref, className: cx("o-number", className), style: style, disabled: disabled, readOnly: readOnly, "data-kit": "number-field", ...phoneMark(phone), ...root, children: _jsxs(BaseNumberField.Group, { render: (props) => chrome === "inline"
83
+ return (_jsx(BaseNumberField.Root, { ref: ref, className: cx("o-number o-number-bare", className), style: style, disabled: disabled, readOnly: readOnly, "data-kit": "number-field", ...phoneMark(phone), ...root, ...values, children: input }));
84
+ return (_jsx(BaseNumberField.Root, { ref: ref, className: cx("o-number", className), style: style, disabled: disabled, readOnly: readOnly, "data-kit": "number-field", ...phoneMark(phone), ...root, ...values, children: _jsxs(BaseNumberField.Group, { render: (props) => chrome === "inline"
33
85
  ? _jsx(InlineInputGroup, { ...props, children: props.children })
34
86
  : _jsx(InputGroup, { size: size, look: look, chrome: chrome === "soft" ? "soft" : undefined, ...props, children: props.children }), children: [side("start", before), input, side("end", after), stepped && (_jsxs(InputGroupAddon, { side: "end", className: "o-number-steps", children: [_jsx(BaseNumberField.Decrement, { ...(words?.decrease ? { "aria-label": words.decrease } : {}), render: _jsx(InputGroupButton, { icon: _jsx(Mark, { paths: MINUS }) }) }), _jsx(BaseNumberField.Increment, { ...(words?.increase ? { "aria-label": words.increase } : {}), render: _jsx(InputGroupButton, { icon: _jsx(Mark, { paths: PLUS }) }) })] })), arrows && (_jsxs(InputGroupAddon, { side: "end", className: "o-number-arrows", children: [_jsx(BaseNumberField.Increment, { className: "o-number-arrow", "aria-label": words?.increase ?? "Increase", children: UP_MARK }), _jsx(BaseNumberField.Decrement, { className: "o-number-arrow", "aria-label": words?.decrease ?? "Decrease", children: DOWN_MARK })] }))] }) }));
35
87
  });
@@ -0,0 +1,4 @@
1
+ import type { PieceLooks } from "../../looks/looks.js";
2
+ export type PaneOptionId = "place" | "corners" | "smoothing" | "shadow" | "edge" | "gap" | "padding";
3
+ /** The Pane's options. */
4
+ export declare const PANE_LOOKS: PieceLooks<PaneOptionId>;
@@ -0,0 +1,11 @@
1
+ const steps = (ids) => ids.map((id) => ({ id, name: id }));
2
+ const options = [
3
+ { id: "place", name: "Where it stands", device: "desktop", def: "list", values: [{ id: "list", name: "As tall as the list" }, { id: "fit", name: "Fitting what it holds" }] },
4
+ { id: "corners", name: "Corners", device: "desktop", def: "xl", kind: "steps", values: steps(["lg", "xl", "2xl"]) },
5
+ { id: "smoothing", name: "Corner smoothing", device: "desktop", def: "smooth", values: [{ id: "round", name: "Round" }, { id: "smooth", name: "Smooth" }] },
6
+ { id: "shadow", name: "Shadow", device: "desktop", def: "menu", kind: "steps", values: [{ id: "none", name: "None" }, { id: "menu", name: "Menu" }, { id: "lg", name: "Large" }, { id: "xl", name: "Extra large" }] },
7
+ { id: "edge", name: "Edge", device: "desktop", def: "outline", values: [{ id: "outline", name: "Outline" }, { id: "subtle", name: "Subtle" }, { id: "none", name: "None" }] },
8
+ { id: "gap", name: "Gap", device: "desktop", def: "8", kind: "steps", values: steps(["0", "4", "8", "12", "16"]) },
9
+ { id: "padding", name: "Padding", device: "desktop", def: "8", kind: "steps", values: steps(["0", "4", "8", "12", "16"]) },
10
+ ];
11
+ export const PANE_LOOKS = { id: "pane", name: "Pane", options, looks: [] };
@@ -0,0 +1,63 @@
1
+ import * as React from "react";
2
+ export { paneAfter, type PaneState, type PanePress } from "./state.js";
3
+ /** Why it closed, by the controls' one list of close reasons: Escape, its ✕; any other is `none`. What opened it,
4
+ * pressed again, closes it through usePane, never through onOpenChange. */
5
+ export type PaneCloseReason = "escape-key" | "close-press" | "none";
6
+ export interface PaneChangeDetails {
7
+ reason: PaneCloseReason;
8
+ /** What did it: the press, the key. */
9
+ event?: Event;
10
+ }
11
+ export interface PaneProps {
12
+ open: boolean;
13
+ /** It closes, and why: its holder sets `open` from it. */
14
+ onOpenChange: (open: boolean, details: PaneChangeDetails) => void;
15
+ /** The list's box it stands in: positioned, holding the list (which scrolls inside it) and never scrolling itself. Its portal
16
+ * takes no room there (display: contents). Until it is on the page (null), nothing is drawn. */
17
+ container: HTMLElement | null;
18
+ /** What opened it: the focus goes back to it as it closes. */
19
+ opener?: HTMLElement | null;
20
+ /** Whether the focus lands on it as it opens (the default); false where it stands open on a page that shows it, so the page
21
+ * takes no focus as it loads. */
22
+ initialFocus?: boolean;
23
+ /** What names it to a screen reader, when what stands in it has no PaneTitle. */
24
+ "aria-label"?: string;
25
+ className?: string;
26
+ /** What stands in it: a PaneHead, a PaneBody and a PaneFoot, each as it needs. */
27
+ children: React.ReactNode;
28
+ }
29
+ /** A list's panel at its right edge, the list in use beside it. */
30
+ export declare function Pane({ open, onOpenChange, container, opener, initialFocus, "aria-label": label, className, children }: PaneProps): import("react/jsx-runtime").JSX.Element | null;
31
+ type Slot = {
32
+ children: React.ReactNode;
33
+ className?: string;
34
+ };
35
+ /** Its head, which what stands in it fills: its title, its ✕. It stays at its top. */
36
+ export declare function PaneHead({ children, className }: Slot): import("react/jsx-runtime").JSX.Element;
37
+ /** What it holds, scrolling between its head and its foot. */
38
+ export declare function PaneBody({ children, className }: Slot): import("react/jsx-runtime").JSX.Element;
39
+ /** Its foot, under a line across the whole Pane, always at its foot. */
40
+ export declare function PaneFoot({ children, className }: Slot): import("react/jsx-runtime").JSX.Element;
41
+ /** Its title, which names it to a screen reader too. */
42
+ export declare function PaneTitle({ children, className }: Slot): import("react/jsx-runtime").JSX.Element;
43
+ /** What closes it from inside (a Button: `render`), with the reason close-press: what stands in it draws its own ✕. */
44
+ export declare function PaneClose({ render, children }: {
45
+ render: React.ReactElement;
46
+ children?: React.ReactNode;
47
+ }): import("react/jsx-runtime").JSX.Element;
48
+ /** A Pane's holder: what stands in it, one thing at a time, and what opened it. `opens(key)` is spread on each opener: its
49
+ * press puts its thing in the Pane, takes the place of another's, or closes its own. `pane` is spread on the Pane. `start`:
50
+ * what stands in it at first, open from the start (a page that shows it). */
51
+ export declare function usePane(start?: string | null): {
52
+ shown: string | null;
53
+ pane: {
54
+ open: boolean;
55
+ opener: HTMLElement | null;
56
+ onOpenChange: (next: boolean) => void;
57
+ };
58
+ opens: (key: string) => {
59
+ onClick: (e: React.MouseEvent<HTMLElement>) => void;
60
+ "aria-expanded": boolean;
61
+ };
62
+ close: () => void;
63
+ };
@@ -0,0 +1,98 @@
1
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import * as React from "react";
3
+ import { Dialog } from "@base-ui/react/dialog";
4
+ import { cx } from "../../internal/cx.js";
5
+ import { closeReasonOf } from "../internal/close-reason.js";
6
+ import { Scrollbar } from "../scrollbar/scrollbar.js";
7
+ import { paneAfter } from "./state.js";
8
+ export { paneAfter } from "./state.js";
9
+ const REASONS = ["escape-key", "close-press"];
10
+ const reasonOf = (reason) => { const r = closeReasonOf(reason); return REASONS.find((x) => x === r) ?? "none"; };
11
+ const POPUP = "[role='menu'], [role='listbox'], [role='dialog'], [role='alertdialog'], [role='combobox'][aria-expanded='true']";
12
+ const opened = new Set();
13
+ let count = 0;
14
+ const inSight = (el) => !el.closest("[inert]") && (el.checkVisibility?.({ visibilityProperty: true }) ?? el.getClientRects().length > 0);
15
+ const depth = (el) => { let d = 0; for (let n = el; n; n = n.parentNode)
16
+ d++; return d; };
17
+ const nearness = (at, container) => { let n = container; while (n && !n.contains(at))
18
+ n = n.parentNode; return depth(n); };
19
+ function chosen(at, may) {
20
+ const all = [...opened].filter((o) => o.popup.current && may(o));
21
+ const seen = all.filter((o) => inSight(o.popup.current));
22
+ return (seen.length ? seen : all).reduce((best, o) => {
23
+ if (!best)
24
+ return o;
25
+ const a = nearness(at, o.container), b = nearness(at, best.container);
26
+ return a > b || (a === b && o.order > best.order) ? o : best;
27
+ }, undefined);
28
+ }
29
+ export function Pane({ open, onOpenChange, container, opener, initialFocus = true, "aria-label": label, className, children }) {
30
+ const popup = React.useRef(null);
31
+ const self = React.useRef(null);
32
+ React.useEffect(() => {
33
+ if (!open || !container)
34
+ return;
35
+ const entry = { popup, container, order: ++count };
36
+ self.current = entry;
37
+ opened.add(entry);
38
+ return () => { opened.delete(entry); self.current = null; };
39
+ }, [open, container]);
40
+ const change = (next, details) => {
41
+ if (next)
42
+ return;
43
+ if (details.reason === "escape-key") {
44
+ const at = details.event?.target instanceof Node ? details.event.target : document.activeElement ?? document.body;
45
+ const other = at instanceof Element ? at.closest(POPUP) : at.parentElement?.closest(POPUP) ?? null;
46
+ const mayClose = (box, list) => !other || other === box || !!box?.contains(other) || !!list && other.contains(list);
47
+ if (!mayClose(popup.current, container))
48
+ return details.cancel();
49
+ if (!popup.current?.contains(at) && chosen(at, (o) => mayClose(o.popup.current, o.container)) !== (self.current ?? undefined))
50
+ return details.cancel();
51
+ if (details.event?.defaultPrevented)
52
+ return details.cancel();
53
+ }
54
+ onOpenChange(false, { reason: reasonOf(details.reason), event: details.event });
55
+ };
56
+ const backTo = () => {
57
+ const now = document.activeElement;
58
+ if (now && now !== document.body && !popup.current?.contains(now))
59
+ return false;
60
+ return opener?.isConnected ? opener : true;
61
+ };
62
+ if (!container)
63
+ return null;
64
+ return (_jsx(Dialog.Root, { open: open, onOpenChange: change, modal: false, disablePointerDismissal: true, children: _jsx(Dialog.Portal, { container: container, className: "o-pane-portal", children: _jsx(Dialog.Popup, { ref: popup, className: cx("o-pane", className), "data-kit": "pane", "aria-label": label, initialFocus: initialFocus ? popup : false, finalFocus: backTo, children: _jsx("div", { className: "o-pane-cut o-smooth", children: children }) }) }) }));
65
+ }
66
+ export function PaneHead({ children, className }) {
67
+ return _jsx("div", { className: cx("o-pane-head", className), children: children });
68
+ }
69
+ export function PaneBody({ children, className }) {
70
+ return _jsxs(_Fragment, { children: [_jsx("div", { className: cx("o-pane-body", className), children: children }), _jsx(Scrollbar, {})] });
71
+ }
72
+ export function PaneFoot({ children, className }) {
73
+ return _jsx("div", { className: cx("o-pane-foot", className), children: children });
74
+ }
75
+ export function PaneTitle({ children, className }) {
76
+ return _jsx(Dialog.Title, { className: cx("o-pane-title", className), children: children });
77
+ }
78
+ export function PaneClose({ render, children }) {
79
+ return _jsx(Dialog.Close, { render: render, children: children });
80
+ }
81
+ export function usePane(start = null) {
82
+ const [state, setState] = React.useState({ shown: start, opener: null });
83
+ const step = (press) => setState((now) => paneAfter(now, press));
84
+ return {
85
+ shown: state.shown,
86
+ pane: {
87
+ open: state.shown !== null,
88
+ opener: state.opener,
89
+ onOpenChange: (next) => { if (!next)
90
+ step({ close: true }); },
91
+ },
92
+ opens: (key) => ({
93
+ onClick: (e) => step({ key, at: e.currentTarget }),
94
+ "aria-expanded": state.shown === key,
95
+ }),
96
+ close: () => step({ close: true }),
97
+ };
98
+ }
@@ -0,0 +1,14 @@
1
+ /** What stands in the Pane, by its key, or nothing; and what opened it last. */
2
+ export type PaneState<E = HTMLElement> = {
3
+ shown: string | null;
4
+ opener: E | null;
5
+ };
6
+ /** A press on an opener (its thing's key, and the opener itself), or a close from inside the Pane (its ✕, Escape). */
7
+ export type PanePress<E = HTMLElement> = {
8
+ key: string;
9
+ at: E | null;
10
+ } | {
11
+ close: true;
12
+ };
13
+ /** The state after a press. */
14
+ export declare function paneAfter<E>(state: PaneState<E>, press: PanePress<E>): PaneState<E>;
@@ -0,0 +1,7 @@
1
+ export function paneAfter(state, press) {
2
+ if ("close" in press)
3
+ return { shown: null, opener: state.opener };
4
+ if (state.shown === press.key)
5
+ return { shown: null, opener: state.opener };
6
+ return { shown: press.key, opener: press.at };
7
+ }