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,48 @@
1
+ "use client";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { usePicker } from "../picker/picker.js";
5
+ import { Sheet, SheetBody, SheetButton, SheetHead } from "../sheet/bottom-sheet.js";
6
+ import { drawnAt } from "./scroll.js";
7
+ export 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)) }));
8
+ export const dots = (x, y) => `M${x} ${y}m-1 0a1 1 0 1 0 2 0a1 1 0 1 0 -2 0`;
9
+ export const X = ["M18 6l-12 12", "M6 6l12 12"], PLUS = ["M12 5l0 14", "M5 12l14 0"], TICK = ["M5 12l5 5l10 -10"];
10
+ export const DOTS = [dots(5, 12), dots(12, 12), dots(19, 12)];
11
+ export const TRASH = ["M4 7l16 0", "M10 11l0 6", "M14 11l0 6", "M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12", "M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3"];
12
+ export const DOTS_LOOK = { radius: "md", corner: "round", edge: "none", words: "inherit", icon: "20", hover: "none", press: "card" };
13
+ export const DOTS_UP = [dots(12, 5), dots(12, 12), dots(12, 19)];
14
+ export const MORE_LOOK = { radius: "md", corner: "round", edge: "none", words: "inherit", colour: "faint", icon: "16" };
15
+ export const asSelect = (items) => items.map((i) => ({ value: i.value, label: i.label, line: i.line, disabled: i.disabled, you: i.you,
16
+ mark: i.as && "mark" in i.as ? i.as.mark : undefined, ...(i.level ? { level: asSelect(i.level) } : {}) }));
17
+ export function OnTop({ open, onOpenChange, onGone, title, picker, container, standing, words }) {
18
+ const parts = usePicker({ ...picker, form: "phone", onDone: () => onOpenChange(false) });
19
+ return (_jsxs(Sheet, { open: open, onOpenChange: (o) => onOpenChange(o), onOpenChangeComplete: (o) => { if (!o)
20
+ onGone(); }, label: title, form: "full", container: container, standing: standing, children: [_jsx(SheetHead, { title: title, ...(words ? { words } : {}), ...parts.head }), _jsx(SheetBody, { children: parts.body })] }));
21
+ }
22
+ export function useStandingRoom(root, selector, phone, again) {
23
+ const [room, setRoom] = React.useState(0);
24
+ React.useLayoutEffect(() => {
25
+ const list = root?.querySelector(selector);
26
+ if (!root || !list || phone) {
27
+ setRoom(0);
28
+ return;
29
+ }
30
+ const read = () => {
31
+ const k = drawnAt(root) || 1, pad = parseFloat(getComputedStyle(root).paddingBottom) || 0;
32
+ const over = (list.getBoundingClientRect().bottom - root.getBoundingClientRect().bottom) / k + pad;
33
+ setRoom((r) => { const next = Math.max(0, Math.ceil(over)); return r === next ? r : next; });
34
+ };
35
+ read();
36
+ const watch = new ResizeObserver(read);
37
+ watch.observe(list);
38
+ return () => watch.disconnect();
39
+ }, [root, selector, phone, ...again]);
40
+ return room;
41
+ }
42
+ export function useDecide(now, change, onDone, words = { close: "Close", save: "Save" }) {
43
+ const opened = React.useRef(null);
44
+ const place = React.useCallback((el) => { opened.current = el ? opened.current ?? now.current : null; }, [now]);
45
+ const leave = () => { const was = opened.current; if (was && JSON.stringify(was) !== JSON.stringify(now.current))
46
+ change(was); onDone?.(); };
47
+ return { place, head: { left: _jsx(SheetButton, { "aria-label": words.close, icon: glyph(X), onClick: leave }), right: _jsx(SheetButton, { kind: "primary", "aria-label": words.save, icon: glyph(TICK), onClick: () => onDone?.() }) } };
48
+ }
@@ -0,0 +1,9 @@
1
+ /** A step's opener in its editor's root: a selector, or a finder for one no selector names (a row by its words). */
2
+ export type StepOpener = string | ((root: HTMLElement) => HTMLElement | null);
3
+ /** An opener whose selector is built as the step goes, inside the frame, so nothing (CSS.escape) runs while a server draws. */
4
+ export declare const openerAt: (selector: () => string) => StepOpener;
5
+ /** On a phone, the open steps' openers, the outermost first ([] at rest and on a computer). When the list grows shorter, the
6
+ * opener of the outermost step that went takes the focus on the next frame, found again in `root` as redrawn. */
7
+ export declare function useStepReturn(root: HTMLElement | null | {
8
+ readonly current: HTMLElement | null;
9
+ }, openers: readonly StepOpener[]): void;
@@ -0,0 +1,27 @@
1
+ "use client";
2
+ import * as React from "react";
3
+ const inOwnHead = (now, root) => !!now.closest(".o-sheet-head") && !!root.closest(".o-sheet")?.contains(now);
4
+ export const openerAt = (selector) => (root) => root.querySelector(selector());
5
+ export function useStepReturn(root, openers) {
6
+ const was = React.useRef(openers);
7
+ React.useLayoutEffect(() => {
8
+ const before = was.current;
9
+ was.current = openers;
10
+ if (openers.length >= before.length)
11
+ return;
12
+ const opener = before[openers.length];
13
+ requestAnimationFrame(() => {
14
+ const el = root == null ? null : "current" in root ? root.current : root;
15
+ if (!el?.isConnected)
16
+ return;
17
+ const now = document.activeElement;
18
+ if (now && now !== document.body && now.isConnected && !now.contains(el) && !now.classList.contains("o-sheet-step") && !inOwnHead(now, el))
19
+ return;
20
+ const to = typeof opener === "string" ? el.querySelector(opener) : opener(el);
21
+ if (!to?.isConnected)
22
+ return;
23
+ to.focus({ preventScroll: true });
24
+ to.scrollIntoView?.({ block: "nearest" });
25
+ });
26
+ });
27
+ }
@@ -0,0 +1,80 @@
1
+ import * as React from "react";
2
+ import { type PickerItem } from "../picker/picker.js";
3
+ import type { SheetHeadProps } from "../sheet/bottom-sheet.js";
4
+ import { type Link, type LinkField } from "./links.js";
5
+ import { type LinksEditorWords } from "./words.js";
6
+ export type { Link, LinkField, LinkFieldKind, LinkValue } from "./links.js";
7
+ /** One link leads (a person's main company): which, a way to set it (none once nothing is linked), and its column's name. */
8
+ export interface LinksEditorLead {
9
+ value: string | null;
10
+ onLead: (value: string | null) => void;
11
+ label: string;
12
+ }
13
+ /** What a page shows standing open: a field's list on a link, or a link's fields. */
14
+ export type LinksEditorOpens = {
15
+ list: string;
16
+ link: string;
17
+ } | {
18
+ config: string;
19
+ };
20
+ export interface LinksEditorProps {
21
+ /** The field's name ("Companies"): the editor's name to a screen reader, and the Sheet's title on a phone. */
22
+ label: string;
23
+ /** One of its records ("Company"): the first column's name. */
24
+ kind: string;
25
+ /** The records that can be linked, in the list's order; each drawn with its face where it has one. */
26
+ records: PickerItem[];
27
+ /** The fields a link holds, in their columns' order. */
28
+ fields: LinkField[];
29
+ /** The links, in order. */
30
+ links: Link[];
31
+ /** Each change, as it is made: a record linked or unlinked, a field's value changed. */
32
+ onLinksChange: (links: Link[]) => void;
33
+ /** Given when one link leads. */
34
+ lead?: LinksEditorLead;
35
+ /** What the search says before anything is typed ("Search companies…"); "Search…" unless said. */
36
+ search?: string;
37
+ /** Which form; by default the phone's in a phone's window or in a PhoneHost screen, else the computer's. */
38
+ form?: "computer" | "phone";
39
+ /** The job is done and what holds it closes: ✓, or ✕ once the links are back, on a phone. */
40
+ onDone?: () => void;
41
+ /** The search takes the focus as it opens, on a computer; true unless said (a page's case says false). */
42
+ autoFocus?: boolean;
43
+ /** A page's state: what is typed in the search. */
44
+ typed?: string;
45
+ /** A page's state: a field's list standing open on a link, or a link's fields open. */
46
+ opens?: LinksEditorOpens;
47
+ /** Its words; English unless handed. */
48
+ words?: Partial<LinksEditorWords>;
49
+ /** The editor filters or fetches: every typed query is handed here, and `records` are drawn as handed, never filtered again. */
50
+ onSearch?: (query: string) => void;
51
+ /** What the list is doing besides showing its records: a first page in flight, or the last ask failed. */
52
+ doing?: "searching" | "failed";
53
+ /** Ask again after `doing: "failed"`. */
54
+ onRetry?: () => void;
55
+ /** More records are to come: called each time the list's end comes into sight. */
56
+ onMore?: () => void;
57
+ /** Rows that do something rather than link (create a record with what was typed), after the records to add. */
58
+ actions?: LinksEditorAction[];
59
+ /** Data attributes for a link's roles list, drawn outside the body (its Popover): ViewKit's map marks it as an inner level, so
60
+ * an app's popover that hears Escape first leaves it to the list. */
61
+ popupData?: Readonly<Record<`data-${string}`, string>>;
62
+ }
63
+ /** A row that does something rather than link: its key, its words, an optional mark, and what it does. */
64
+ export interface LinksEditorAction {
65
+ key: string;
66
+ label: string;
67
+ icon?: React.ReactNode;
68
+ onSelect: () => void;
69
+ }
70
+ export interface LinksEditorParts {
71
+ body: React.ReactNode;
72
+ /** On a phone, the Sheet head's ✕ and ✓, or on a step its Back (`onBack`, `close: false`); {} on a computer. */
73
+ head: Pick<SheetHeadProps, "close" | "left" | "right" | "onBack">;
74
+ /** On a phone, the Sheet's title while it stands on a step: a link's field, or a link's fields by the record's name. */
75
+ title?: string;
76
+ }
77
+ /** The Links editor's state and the parts a shell pours in. */
78
+ export declare function useLinksEditor(props: LinksEditorProps): LinksEditorParts;
79
+ /** The body alone, for a shell that holds only a body (the Popover). */
80
+ export declare function LinksEditor(props: LinksEditorProps): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,329 @@
1
+ "use client";
2
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import * as React from "react";
4
+ import { Avatar } from "../avatar/avatar.js";
5
+ import { Button } from "../button/button.js";
6
+ import { FieldRows, FieldRowsRow as FieldRow } from "../field/field.js";
7
+ import { Input, InputGroup, InputGroupAddon } from "../input/input.js";
8
+ import { DOTS, DOTS_LOOK, glyph, PLUS, useDecide, useStandingRoom, X } from "../internal/editor-parts.js";
9
+ import { Icon } from "../internal/icons.js";
10
+ import { PhoneHost, phoneMark, usePhone } from "../internal/phone.js";
11
+ import { spacingPx } from "../internal/read-token.js";
12
+ import { drawnAt, scrollInList } from "../internal/scroll.js";
13
+ import { openerAt, useStepReturn } from "../internal/step-return.js";
14
+ import { Menu } from "../menu/menu.js";
15
+ import { Picker, usePicker } from "../picker/picker.js";
16
+ import { Popover } from "../popover/popover.js";
17
+ import { Radio, RadioGroup } from "../radio/radio.js";
18
+ import { Select } from "../select/select.js";
19
+ import { Spinner } from "../spinner/spinner.js";
20
+ import { Switch } from "../switch/switch.js";
21
+ import { midWord } from "../text-editor/check.js";
22
+ import { added, found, heldOf, leadAfter, offered, removed, said, saidShort, setValue, ticked } from "./links.js";
23
+ import { linksWords } from "./words.js";
24
+ function StepList(props) {
25
+ return _jsx(_Fragment, { children: usePicker(props).body });
26
+ }
27
+ const SEARCH = ["M10 10m-7 0a7 7 0 1 0 14 0a7 7 0 1 0 -14 0", "M21 21l-6 -6"], BACK = ["M15 6l-6 6l6 6"];
28
+ const END_LOOK = { radius: "sm", corner: "round", edge: "none", words: "inherit", colour: "faint", icon: "16" };
29
+ const MORE = ["M9 6l6 6l-6 6"];
30
+ const UNLINK = ["M17 22v-2", "M9 15l6 -6", "M11 6l.463 -.536a5 5 0 0 1 7.071 7.072l-.534 .463", "M13 18l-.397 .534a5.068 5.068 0 0 1 -7.127 0a4.972 4.972 0 0 1 0 -7.071l.524 -.463", "M20 17h2", "M2 7h2", "M7 2v2"];
31
+ const CARD = { cards: "one", edge: "on", height: "56", label: "none", lines: "words" };
32
+ const ADDS = CARD;
33
+ const FIELDS = { cards: "one", edge: "on", height: "52", label: "104", lines: "words" };
34
+ function Face({ record, size }) {
35
+ const as = record.as;
36
+ const avatar = as && "avatar" in as ? as : null;
37
+ return _jsx(Avatar, { name: record.label, kind: avatar?.avatar === "person" ? "person" : "thing", id: avatar?.id, src: avatar?.src, size: size });
38
+ }
39
+ export function useLinksEditor(props) {
40
+ const { label, kind, records, fields, links, onLinksChange, lead, autoFocus = true, opens, onSearch, doing, onRetry, onMore, actions = [] } = props;
41
+ const w = linksWords(props.words), search = props.search ?? w.search;
42
+ const screen = React.useContext(PhoneHost), small = usePhone(), phone = (props.form ?? (screen || small ? "phone" : "computer")) === "phone";
43
+ const mark = phoneMark(!!screen || small);
44
+ const one = fields.length === 1 ? fields[0] : null, several = fields.length > 1;
45
+ const now = React.useRef(links);
46
+ now.current = links;
47
+ const leading = React.useRef(lead?.value ?? null);
48
+ leading.current = lead?.value ?? null;
49
+ const change = (next) => {
50
+ now.current = next;
51
+ onLinksChange(next);
52
+ if (!lead)
53
+ return;
54
+ const after = leadAfter(leading.current, next);
55
+ if (after !== leading.current) {
56
+ leading.current = after;
57
+ lead.onLead(after);
58
+ }
59
+ };
60
+ const setLead = (value) => { if (!lead || value === leading.current)
61
+ return; leading.current = value; lead.onLead(value); };
62
+ const [query, setQuery] = React.useState(props.typed ?? "");
63
+ const [lit, setLit] = React.useState(props.typed?.trim() ? 0 : null);
64
+ const { linked, rest: toAdd } = found(records, links, query, !!onSearch);
65
+ const rest = doing ? [] : toAdd;
66
+ const lights = rest.length + actions.length;
67
+ const litAt = lit == null || !lights || doing === "searching" ? null : Math.min(lit, lights - 1);
68
+ const typeQuery = (v) => { setQuery(v); onSearch?.(v); };
69
+ const asked = React.useRef(onMore);
70
+ asked.current = onMore;
71
+ const seenRef = React.useRef(null);
72
+ const moreRef = React.useCallback((el) => {
73
+ seenRef.current?.disconnect();
74
+ seenRef.current = null;
75
+ if (!el || typeof IntersectionObserver === "undefined")
76
+ return;
77
+ let was = false;
78
+ seenRef.current = new IntersectionObserver((seen) => { const now = seen.some((x) => x.isIntersecting); if (now && !was)
79
+ asked.current?.(); was = now; });
80
+ seenRef.current.observe(el);
81
+ }, []);
82
+ const more = onMore && !doing ? _jsxs("div", { ref: moreRef, className: "o-links-editor-loading", children: [_jsx(Spinner, { size: 16, label: "" }), _jsx("span", { children: w.loadingMore })] }) : null;
83
+ const doingNote = doing === "searching" ? w.searching : doing === "failed" ? _jsxs(_Fragment, { children: [w.failed, onRetry && _jsx(Button, { kind: "quiet", size: "2xs", className: "o-links-editor-retry", onClick: onRetry, children: w.retry })] }) : null;
84
+ const byValue = (value) => records.find((r) => r.value === value) ?? { value, label: links.find((l) => l.value === value)?.label ?? value };
85
+ const [root, setRoot] = React.useState(null);
86
+ const searchBox = React.useRef(null), list = React.useRef(null);
87
+ const [view, setView] = React.useState(null);
88
+ const placeList = React.useCallback((el) => { list.current = el; setView(el); }, []);
89
+ const ids = React.useId();
90
+ const [stepOpen, setStep] = React.useState(opens && "config" in opens ? opens.config : null);
91
+ const step = stepOpen && links.some((l) => l.value === stepOpen) ? stepOpen : null;
92
+ const [open, setOpen] = React.useState(null);
93
+ const shownList = opens && "list" in opens ? { link: opens.link, field: opens.list } : null;
94
+ const back = React.useRef(false), stepPressed = React.useRef(false);
95
+ React.useLayoutEffect(() => {
96
+ if (phone)
97
+ return;
98
+ if (step) {
99
+ if (stepPressed.current)
100
+ root?.querySelector(".o-links-editor-back")?.focus({ preventScroll: true });
101
+ stepPressed.current = false;
102
+ return;
103
+ }
104
+ if (autoFocus || back.current)
105
+ searchBox.current?.focus({ preventScroll: true });
106
+ back.current = false;
107
+ }, [phone, step, root]);
108
+ React.useEffect(() => { if (stepOpen && !step) {
109
+ setStep(null);
110
+ back.current = true;
111
+ } }, [stepOpen, step]);
112
+ React.useEffect(() => {
113
+ const el = view;
114
+ if (!el || !open)
115
+ return;
116
+ const hold = (e) => e.preventDefault();
117
+ el.addEventListener("wheel", hold, { passive: false });
118
+ el.addEventListener("touchmove", hold, { passive: false });
119
+ setLit(null);
120
+ return () => { el.removeEventListener("wheel", hold); el.removeEventListener("touchmove", hold); };
121
+ }, [view, open]);
122
+ const [refocus, setRefocus] = React.useState(null);
123
+ React.useLayoutEffect(() => {
124
+ if (refocus == null || !root)
125
+ return;
126
+ setRefocus(null);
127
+ const ends = root.querySelectorAll(".o-links-editor-row .o-links-editor-end > button");
128
+ (ends[refocus] ?? ends[ends.length - 1] ?? searchBox.current)?.focus({ preventScroll: true });
129
+ }, [refocus, root]);
130
+ const link = (value) => {
131
+ change(added(now.current, value));
132
+ if (query)
133
+ typeQuery("");
134
+ setLit(null);
135
+ if (!phone)
136
+ searchBox.current?.focus({ preventScroll: true });
137
+ };
138
+ const unlink = (value) => {
139
+ const at = linked.findIndex((r) => r.value === value);
140
+ root?.focus({ preventScroll: true });
141
+ change(removed(now.current, value));
142
+ if (step === value) {
143
+ setStep(null);
144
+ back.current = true;
145
+ }
146
+ else
147
+ setRefocus(at);
148
+ };
149
+ const setField = (value, field, to) => change(setValue(now.current, value, field, to));
150
+ const tickFrom = (value, field, next) => {
151
+ const held = heldOf(now.current.find((l) => l.value === value)?.values[field.id]);
152
+ const changed = next.find((v) => !held.includes(v)) ?? held.find((v) => !next.includes(v));
153
+ if (changed != null)
154
+ setField(value, field.id, ticked(held, changed));
155
+ };
156
+ const listOf = (l, f) => ({
157
+ label: f.label, items: offered(f, l.values[f.id]), multiple: f.kind === "several", search: w.searchField(f.label), firstFollows: true, words: w.picker,
158
+ value: f.kind === "several" ? heldOf(l.values[f.id]) : typeof l.values[f.id] === "string" ? l.values[f.id] : null,
159
+ onValueChange: (next) => (f.kind === "several" ? tickFrom(l.value, f, Array.isArray(next) ? next : []) : setField(l.value, f.id, typeof next === "string" ? next : null)),
160
+ });
161
+ const room = useStandingRoom(root, "[data-links-shown]", phone, [shownList?.link, shownList?.field, step]);
162
+ const [shownAt, setShownAt] = React.useState(null);
163
+ React.useLayoutEffect(() => {
164
+ if (!root || !shownList) {
165
+ setShownAt(null);
166
+ return;
167
+ }
168
+ const button = root.querySelector(`.o-links-editor-row[data-link="${CSS.escape(shownList.link)}"] .o-links-editor-short`);
169
+ if (!button) {
170
+ setShownAt(null);
171
+ return;
172
+ }
173
+ const r = root.getBoundingClientRect(), b = button.getBoundingClientRect(), k = drawnAt(root) || 1;
174
+ setShownAt({ top: (b.bottom - r.top) / k + spacingPx(1, root), left: (b.left - r.left) / k });
175
+ }, [root, shownList?.link, shownList?.field, links]);
176
+ const decideNow = React.useRef({ get current() { return { links: now.current, lead: leading.current }; } }).current;
177
+ const decide = useDecide(decideNow, (was) => {
178
+ now.current = was.links;
179
+ onLinksChange(was.links);
180
+ if (lead && was.lead !== leading.current) {
181
+ leading.current = was.lead;
182
+ lead.onLead(was.lead);
183
+ }
184
+ }, props.onDone, { close: w.close, save: w.save });
185
+ const placed = decide.place;
186
+ const typedFirst = React.useRef(props.typed ?? "");
187
+ typedFirst.current = props.typed ?? "";
188
+ const placeRoot = React.useCallback((el) => { setRoot(el); placed(el); if (!el)
189
+ setQuery(typedFirst.current); }, [placed]);
190
+ const [top, setTop] = React.useState(() => (phone && opens && "list" in opens ? { link: opens.link, field: opens.list } : null));
191
+ const [fieldsOf, setFieldsOf] = React.useState(() => (phone && opens && "config" in opens ? opens.config : null));
192
+ React.useEffect(() => {
193
+ if (top && !links.some((l) => l.value === top.link))
194
+ setTop(null);
195
+ if (fieldsOf && !links.some((l) => l.value === fieldsOf))
196
+ setFieldsOf(null);
197
+ }, [links, top, fieldsOf]);
198
+ const fieldsOpen = several && fieldsOf ? fieldsOf : null;
199
+ useStepReturn(root, phone ? [
200
+ ...(fieldsOpen ? [openerAt(() => `.o-links-editor-card[data-link="${CSS.escape(fieldsOpen)}"] .o-links-editor-config`)] : []),
201
+ ...(top ? [openerAt(() => (fieldsOpen ? `.o-links-editor-fields .o-links-editor-open[data-field="${CSS.escape(top.field)}"]`
202
+ : `.o-links-editor-card[data-link="${CSS.escape(top.link)}"] .o-links-editor-open[data-field="${CSS.escape(top.field)}"]`))] : []),
203
+ ] : []);
204
+ const [sheetRoom, setSheetRoom] = React.useState(null);
205
+ React.useLayoutEffect(() => {
206
+ const scroller = root?.parentElement?.closest(".o-sheet-body");
207
+ if (!phone || !scroller || root?.closest(".o-sheet")?.getAttribute("data-sheet-form") !== "full") {
208
+ setSheetRoom(null);
209
+ return;
210
+ }
211
+ const read = () => {
212
+ const c = getComputedStyle(scroller), topPad = parseFloat(c.paddingTop), under = parseFloat(c.paddingBottom);
213
+ setSheetRoom((was) => { const height = Math.max(0, scroller.clientHeight - topPad - under); return was && was.height === height && was.under === under ? was : { height, under }; });
214
+ };
215
+ read();
216
+ const watch = new ResizeObserver(read);
217
+ watch.observe(scroller);
218
+ return () => watch.disconnect();
219
+ }, [root, phone]);
220
+ if (phone) {
221
+ const addWords = w.addKind(kind);
222
+ const holds = (l) => fields.map((f) => (f.kind === "yes-no" ? (l.values[f.id] === true ? f.label : "") : said(f, l.values[f.id], w.yes) === "–" ? "" : said(f, l.values[f.id], w.yes)))
223
+ .filter(Boolean).join(" · ");
224
+ const rowWords = (f, v) => { const s = said(f, v, w.yes); return f.kind === "yes-no" ? (v === true ? w.yes : w.no) : s === "–" ? w.none : s; };
225
+ const openList = (value, field) => setTop({ link: value, field });
226
+ const fieldRow = (l, name, f) => (f.kind === "yes-no" ? (_jsxs(FieldRow, { className: "o-links-editor-open", "data-field": f.id, children: [_jsx("span", { className: "o-links-editor-open-name", children: f.label }), _jsx(Switch, { size: "lg", className: "o-links-editor-switch", checked: l.values[f.id] === true, "aria-label": w.fieldAt(f.label, name), onCheckedChange: (c) => setField(l.value, f.id, c) })] }, f.id)) : (_jsxs(FieldRow, { as: "button", className: "o-links-editor-open", "data-field": f.id, "aria-label": w.fieldAt(f.label, name), onClick: () => openList(l.value, f.id), children: [_jsx("span", { className: "o-links-editor-open-name", children: f.label }), _jsx("span", { className: "o-links-editor-open-value", children: rowWords(f, l.values[f.id]) }), glyph(MORE, "o-links-editor-open-mark")] }, f.id)));
227
+ const card = (r) => {
228
+ const l = links.find((x) => x.value === r.value), name = r.label, leads = lead != null && lead.value === r.value;
229
+ const said_ = holds(l);
230
+ return (_jsxs(FieldRows, { look: CARD, className: "o-links-editor-card", "data-link": r.value, role: "listitem", "aria-label": name, children: [_jsxs(FieldRow, { as: "div", className: "o-links-editor-card-head", children: [_jsx(Face, { record: r, size: 24 }), _jsxs("span", { className: "o-links-editor-card-name", children: [_jsx("span", { children: name }), leads && _jsx("span", { className: "o-links-editor-lead-word", children: lead.label })] }), !several
231
+ ? _jsx(Menu, { label: w.linkMenu(name), align: "end", entries: [...(lead && !leads ? [{ icon: _jsx(Icon, { name: "star" }), label: w.setLead(lead.label), onSelect: () => setLead(r.value) }] : []), { icon: glyph(UNLINK), label: w.unlink, danger: true, onSelect: () => unlink(r.value) }], trigger: _jsx(Button, { kind: "quiet", shape: "icon", size: "40x44", look: DOTS_LOOK, className: "o-links-editor-more", "aria-label": w.actionsFor(name), icon: glyph(DOTS) }) })
232
+ : _jsx(Button, { kind: "quiet", shape: "icon", size: "40x44", look: DOTS_LOOK, className: "o-links-editor-config", "aria-label": w.editLink(name), "aria-haspopup": "dialog", icon: _jsx(Icon, { name: "settings", size: 20 }), onClick: () => setFieldsOf(r.value) })] }), !several ? one && fieldRow(l, name, one) : _jsx("div", { className: "o-links-editor-card-line", "data-none": said_ ? undefined : "", children: said_ || w.noDetails })] }, r.value));
233
+ };
234
+ const topLink = top ? links.find((l) => l.value === top.link) : undefined, topField = top ? fields.find((f) => f.id === top.field) : undefined;
235
+ const fieldsLink = fieldsOf ? links.find((l) => l.value === fieldsOf) : undefined;
236
+ const fieldsName = fieldsOf ? byValue(fieldsOf).label : "";
237
+ const listStep = top && topLink && topField ? top : null;
238
+ const fieldsStep = several ? fieldsLink ?? null : null;
239
+ const body = (_jsx("div", { ref: placeRoot, className: "o-links-editor", "data-kit": "links-editor", ...mark, "data-links-form": "phone", "data-links-shape": "table", "data-links-fields": several ? "several" : "one", tabIndex: -1, "data-links-step": listStep ? "list" : fieldsStep ? "fields" : undefined, style: sheetRoom ? { "--links-room": `${sheetRoom.height}px`, "--links-under": `${sheetRoom.under}px` } : undefined, children: listStep && topLink && topField ? (_jsx(StepList, { ...listOf(topLink, topField), draft: "shell", form: "phone", onDone: () => setTop(null) }, `${listStep.link}-${listStep.field}`)) : fieldsStep ? _jsxs(_Fragment, { children: [_jsxs(FieldRows, { look: FIELDS, className: "o-links-editor-fields", "data-link": fieldsStep.value, children: [fields.map((f) => f.kind === "yes-no"
240
+ ? _jsx(FieldRow, { label: f.label, "data-field": f.id, children: _jsx(Switch, { size: "lg", className: "o-links-editor-switch", checked: fieldsStep.values[f.id] === true, "aria-label": w.fieldAt(f.label, fieldsName), onCheckedChange: (c) => setField(fieldsStep.value, f.id, c) }) }, f.id)
241
+ : _jsxs(FieldRow, { as: "button", label: f.label, className: "o-links-editor-open", "data-field": f.id, "aria-label": w.fieldAt(f.label, fieldsName), onClick: () => openList(fieldsStep.value, f.id), children: [_jsx("span", { className: "o-links-editor-open-value", children: rowWords(f, fieldsStep.values[f.id]) }), glyph(MORE, "o-links-editor-open-mark")] }, f.id)), lead && _jsx(FieldRow, { label: lead.label, "data-field": "lead", children: _jsx(Switch, { size: "lg", className: "o-links-editor-switch", checked: lead.value === fieldsStep.value, "aria-label": w.isLead(fieldsName, lead.label), onCheckedChange: (c) => { if (c)
242
+ setLead(fieldsStep.value); } }) })] }), _jsx(FieldRows, { look: FIELDS, className: "o-links-editor-fields-foot", children: _jsx(FieldRow, { as: "button", className: "o-links-editor-unlink", onClick: () => { const v = fieldsStep.value; setFieldsOf(null); unlink(v); }, children: w.unlink }) })] }) : _jsxs(_Fragment, { children: [linked.length > 0 && _jsx("div", { className: "o-links-editor-cards", role: "list", "aria-label": label, children: linked.map(card) }), (rest.length > 0 || actions.length > 0) && _jsxs(_Fragment, { children: [_jsx("div", { className: "o-links-editor-label", children: addWords }), _jsxs(FieldRows, { look: ADDS, className: "o-links-editor-adds", role: "list", "aria-label": addWords, children: [rest.map((r) => (_jsxs(FieldRow, { as: "button", className: "o-links-editor-add", "data-record": r.value, role: "listitem", "aria-label": w.linkName(r.label), onClick: () => link(r.value), children: [_jsx(Face, { record: r, size: 40 }), _jsx("span", { className: "o-links-editor-add-name", children: r.label }), glyph(PLUS, "o-links-editor-add-mark")] }, r.value))), actions.map((a) => (_jsxs(FieldRow, { as: "button", className: "o-links-editor-add o-links-editor-action", role: "listitem", onClick: a.onSelect, children: [a.icon != null && _jsx("span", { className: "o-links-editor-action-mark", children: a.icon }), _jsx("span", { className: "o-links-editor-add-name", children: a.label })] }, a.key)))] }), more] }), doingNote ? _jsx("div", { className: "o-links-editor-note", children: doingNote }) : _jsxs(_Fragment, { children: [!rest.length && query.trim() && !linked.length && _jsx("div", { className: "o-links-editor-note", children: w.nothingMatchesTyped(query.trim()) }), !rest.length && !query.trim() && linked.length > 0 && _jsx("div", { className: "o-links-editor-note", children: w.everythingLinked })] }), _jsx("div", { className: "o-links-editor-bar", children: _jsxs(InputGroup, { size: "lg", className: "o-links-editor-pill", children: [_jsx(InputGroupAddon, { side: "start", children: glyph(SEARCH) }), _jsx(Input, { autofill: false, ref: searchBox, className: "o-links-editor-input", placeholder: search, "aria-label": search, value: query, onValueChange: (v) => typeQuery(v) })] }) })] }) }));
243
+ if (listStep && topField)
244
+ return { body, head: { onBack: () => setTop(null), close: false }, title: topField.label };
245
+ if (fieldsStep)
246
+ return { body, head: { onBack: () => setFieldsOf(null), close: false }, title: fieldsName };
247
+ return { body, head: decide.head };
248
+ }
249
+ const stepLink = step ? links.find((l) => l.value === step) : undefined;
250
+ if (step && stepLink) {
251
+ const record = byValue(step), name = record.label;
252
+ const leave = () => { back.current = true; setStep(null); };
253
+ const control = (f) => {
254
+ const v = stepLink.values[f.id], words = w.fieldAt(f.label, name);
255
+ if (f.kind === "yes-no")
256
+ return _jsx(Switch, { size: "md", checked: v === true, "aria-label": words, onCheckedChange: (c) => setField(step, f.id, c) });
257
+ if (f.kind === "several")
258
+ return _jsx(Select, { size: "sm", multiple: true, listWidth: "rows", items: offered(f, v), value: heldOf(v), placeholder: w.none, "aria-label": words, onValueChange: (next) => tickFrom(step, f, Array.isArray(next) ? next : []) });
259
+ return _jsx(Select, { size: "sm", listWidth: "rows", items: offered(f, v), value: typeof v === "string" ? v : null, placeholder: w.none, "aria-label": words, onValueChange: (next) => setField(step, f.id, typeof next === "string" ? next : null) });
260
+ };
261
+ const body = (_jsxs("div", { ref: setRoot, className: "o-links-editor", "data-kit": "links-editor", ...mark, "data-links-form": "computer", "data-links-shape": "table", "data-links-fields": several ? "several" : "one", "data-links-step": "", role: "group", "aria-label": name, tabIndex: -1, onKeyDown: (e) => {
262
+ if (e.key !== "Escape" || e.target.closest?.("[aria-expanded='true']"))
263
+ return;
264
+ e.preventDefault();
265
+ e.stopPropagation();
266
+ leave();
267
+ }, children: [_jsxs("div", { className: "o-links-editor-step-head o-popup-line", children: [_jsx(Button, { kind: "quiet", shape: "icon", size: "2xs", className: "o-links-editor-back", "aria-label": w.backTo(label), icon: glyph(BACK), onClick: leave }), _jsx(Face, { record: record, size: 20 }), _jsx("span", { className: "o-links-editor-step-name", children: name })] }), _jsx("div", { className: "o-links-editor-fields", "data-link": step, children: fields.map((f) => (_jsxs("div", { className: "o-links-editor-field", "data-field": f.id, children: [_jsx("span", { className: "o-links-editor-field-label", children: f.label }), _jsx("span", { className: "o-links-editor-field-control", "data-kind": f.kind, children: control(f) })] }, f.id))) }), _jsx("div", { className: "o-links-editor-step-foot", children: _jsx(Button, { kind: "quiet", size: "2xs", className: "o-links-editor-unlink", onClick: () => unlink(step), children: w.unlink }) })] }));
268
+ return { body, head: {} };
269
+ }
270
+ const keepArrows = (e) => { if (e.key.startsWith("Arrow"))
271
+ e.stopPropagation(); };
272
+ const keys = (e) => {
273
+ if ((e.key === "ArrowDown" || e.key === "ArrowUp") && lights) {
274
+ e.preventDefault();
275
+ if (doing === "searching")
276
+ return;
277
+ const next = litAt == null ? (e.key === "ArrowDown" ? 0 : lights - 1) : (litAt + (e.key === "ArrowDown" ? 1 : lights - 1)) % lights;
278
+ setLit(next);
279
+ const row = list.current?.querySelector(`#${CSS.escape(`${ids}-add-${next}`)}`);
280
+ if (row)
281
+ scrollInList(row, { block: "nearest" });
282
+ }
283
+ else if (e.key === "Enter" && litAt != null && doing !== "searching" && !midWord(e.nativeEvent)) {
284
+ const r = rest[litAt], a = actions[litAt - rest.length];
285
+ if (r) {
286
+ e.preventDefault();
287
+ link(r.value);
288
+ }
289
+ else if (a) {
290
+ e.preventDefault();
291
+ a.onSelect();
292
+ }
293
+ }
294
+ };
295
+ const short = (l, name, f) => {
296
+ const words = saidShort(f, l.values[f.id], w.yes), standing = shownList?.link === l.value && shownList.field === f.id;
297
+ const button = (_jsx(Button, { kind: "quiet", size: "2xs", className: "o-links-editor-short", "data-field": f.id, "data-none": words ? undefined : "", "aria-label": w.fieldAt(f.label, name), iconEnd: _jsx(Icon, { name: "down" }), "data-popup-open": standing ? "" : undefined, children: words || f.label }));
298
+ if (standing)
299
+ return button;
300
+ return (_jsx(Popover, { trigger: button, open: open?.link === l.value && open.field === f.id, onOpenChange: (o) => setOpen(o ? { link: l.value, field: f.id } : null), side: "bottom", align: "start", className: "o-links-editor-pop", "aria-label": w.fieldAt(f.label, name), ...(props.popupData ? { popupData: props.popupData } : {}), children: _jsx(Picker, { ...listOf(l, f), form: "computer", onDone: () => setOpen(null) }) }));
301
+ };
302
+ const cell = (l, name, f) => (_jsx("span", { className: "o-links-editor-cell", "data-field": f.id, "data-kind": f.kind, onKeyDown: keepArrows, children: one && f.kind === "yes-no" ? _jsx(Switch, { size: "sm", checked: l.values[f.id] === true, "aria-label": w.fieldAt(f.label, name), onCheckedChange: (c) => setField(l.value, f.id, c) })
303
+ : one ? short(l, name, f) : said(f, l.values[f.id], w.yes) }, f.id));
304
+ const row = (r) => {
305
+ const l = links.find((x) => x.value === r.value), name = r.label;
306
+ return (_jsxs("div", { className: "o-links-editor-row", "data-link": r.value, role: "group", "aria-label": name, children: [_jsxs("span", { className: "o-links-editor-who", children: [_jsx(Face, { record: r, size: 20 }), _jsx("span", { className: "o-links-editor-name", children: name })] }), fields.map((f) => cell(l, name, f)), lead && _jsx("span", { className: "o-links-editor-lead", children: _jsx(Radio, { value: r.value, "aria-label": w.isLead(name, lead.label) }) }), _jsx("span", { className: "o-links-editor-end", onKeyDown: keepArrows, children: !several ? _jsx(Button, { kind: "quiet", shape: "icon", size: "2xs", look: END_LOOK, "aria-label": w.unlinkName(name), icon: glyph(X), onClick: () => unlink(r.value) })
307
+ : _jsx(Button, { kind: "quiet", shape: "icon", size: "2xs", look: END_LOOK, className: "o-links-editor-config", "aria-label": w.editLink(name), icon: _jsx(Icon, { name: "settings" }), onClick: () => { setOpen(null); stepPressed.current = true; setStep(r.value); } }) })] }, r.value));
308
+ };
309
+ const rows = linked.map(row);
310
+ const message = doingNote ?? (!lights && (query.trim() ? (!linked.length ? w.nothingMatches : null) : linked.length ? w.everythingLinked : null));
311
+ const shown = shownList ? (() => {
312
+ const l = links.find((x) => x.value === shownList.link), f = fields.find((x) => x.id === shownList.field);
313
+ if (!l || !f)
314
+ return null;
315
+ return (_jsx("div", { className: "o-links-editor-shown o-list o-smooth o-smooth-ease", "data-links-shown": "list", ...phoneMark(small), style: shownAt ? { top: shownAt.top, left: shownAt.left } : { visibility: "hidden" }, children: _jsx(Picker, { ...listOf(l, f), form: "computer", standing: true }) }));
316
+ })() : null;
317
+ const body = (_jsxs("div", { ref: setRoot, className: "o-links-editor", "data-kit": "links-editor", ...mark, "data-links-form": "computer", "data-links-shape": "table", "data-links-fields": several ? "several" : "one", role: "group", "aria-label": label, tabIndex: -1, style: room ? { paddingBottom: room } : undefined, children: [_jsxs("div", { className: "o-links-editor-search o-popup-line", children: [glyph(SEARCH), _jsx(Input, { chrome: "bare", autofill: false, ref: searchBox, className: "o-links-editor-input", placeholder: search, "aria-label": search, role: "combobox", "aria-expanded": lights > 0, "aria-autocomplete": "list", "aria-controls": lights ? `${ids}-add` : undefined, "aria-activedescendant": litAt != null ? `${ids}-add-${litAt}` : undefined, value: query, onValueChange: (v) => { typeQuery(v); setLit(v.trim() ? 0 : null); }, onKeyDown: keys })] }), _jsxs("div", { ref: placeList, className: "o-links-editor-list", "data-head": linked.length ? "" : undefined, "data-held": open ? "" : undefined, children: [linked.length > 0 && _jsxs(_Fragment, { children: [_jsxs("div", { className: "o-links-editor-head", "aria-hidden": "true", children: [_jsx("span", { className: "o-links-editor-who", children: kind }), fields.map((f) => _jsx("span", { className: "o-links-editor-cell", "data-field": f.id, "data-kind": f.kind, children: f.label }, f.id)), lead && _jsx("span", { className: "o-links-editor-lead", children: lead.label }), _jsx("span", { className: "o-links-editor-end" })] }), lead
318
+ ? _jsx(RadioGroup, { className: "o-links-editor-rows", "aria-label": lead.label, value: lead.value, onValueChange: (v) => setLead(v), children: rows })
319
+ : _jsx("div", { className: "o-links-editor-rows", children: rows })] }), linked.length > 0 && lights > 0 && _jsx("div", { className: "o-list-sep", role: "presentation" }), lights > 0 && _jsxs("div", { id: `${ids}-add`, role: "listbox", "aria-label": w.addTo(label), className: "o-links-editor-adds", onPointerLeave: () => setLit(query.trim() ? 0 : null), children: [linked.length > 0 && _jsx("div", { className: "o-list-heading", "aria-hidden": "true", children: w.add }), rest.map((r, i) => (_jsxs("div", { id: `${ids}-add-${i}`, role: "option", "aria-selected": i === litAt, className: "o-list-row o-smooth o-smooth-ease o-links-editor-add", "data-record": r.value, ...phoneMark(small), "data-highlighted": i === litAt ? "" : undefined, onPointerMove: () => { if (!open && doing !== "searching" && i !== litAt)
320
+ setLit(i); }, onMouseDown: (e) => e.preventDefault(), onClick: () => link(r.value), children: [_jsx(Face, { record: r, size: 20 }), _jsx("span", { className: "o-list-text", children: _jsx("span", { className: "o-list-main", children: r.label }) })] }, r.value))), actions.map((a, j) => {
321
+ const i = rest.length + j;
322
+ return (_jsxs("div", { id: `${ids}-add-${i}`, role: "option", "aria-selected": i === litAt, className: "o-list-row o-smooth o-smooth-ease o-links-editor-add o-links-editor-action", ...phoneMark(small), "data-highlighted": i === litAt ? "" : undefined, onPointerMove: () => { if (!open && doing !== "searching" && i !== litAt)
323
+ setLit(i); }, onMouseDown: (e) => e.preventDefault(), onClick: a.onSelect, children: [a.icon != null && _jsx("span", { className: "o-links-editor-action-mark", children: a.icon }), _jsx("span", { className: "o-list-text", children: _jsx("span", { className: "o-list-main", children: a.label }) })] }, a.key));
324
+ })] }), more, message && _jsx("div", { className: "o-links-editor-message", children: message })] }), shown] }));
325
+ return { body, head: {} };
326
+ }
327
+ export function LinksEditor(props) {
328
+ return _jsx(_Fragment, { children: useLinksEditor(props).body });
329
+ }
@@ -0,0 +1,62 @@
1
+ /** What a field on a link holds: several of a list (a link's roles), one of a list (since when), or yes or no (billed). */
2
+ export type LinkFieldKind = "several" | "one" | "yes-no";
3
+ /** A choice of a field's list: its value and its words; an archived one (a role since retired) is offered only on a link that holds
4
+ * it, by its words, so it can be let go. */
5
+ export interface LinkChoice {
6
+ value: string;
7
+ label: string;
8
+ archived?: boolean;
9
+ }
10
+ /** A field a link holds: its id, its name, its kind and, for a list, its choices. */
11
+ export interface LinkField {
12
+ id: string;
13
+ label: string;
14
+ kind: LinkFieldKind;
15
+ choices?: LinkChoice[];
16
+ }
17
+ /** A field's value on a link: several choices, one, yes or no, or nothing. */
18
+ export type LinkValue = string[] | string | boolean | null;
19
+ /** A link: its record's value, the label it came with (used when the list doesn't hold the record), and its fields' values. */
20
+ export interface Link {
21
+ value: string;
22
+ label?: string;
23
+ values: Record<string, LinkValue>;
24
+ }
25
+ /** What the search finds: the linked records in the links' order, each the list's own record or, where the list doesn't hold it,
26
+ * the label its link came with (its value, with none); then the records to add, in the list's order, a name that starts with
27
+ * what is typed before one that holds it inside. Case and accents folded. `handed`: the records are what the editor found for
28
+ * the query (it filters or fetches), so nothing is filtered or re-sorted again: the linked ones are those the list holds (every
29
+ * link while nothing is typed), the rest in the order handed. */
30
+ export declare function found<T extends {
31
+ value: string;
32
+ label: string;
33
+ }>(records: T[], links: Link[], query: string, handed?: boolean): {
34
+ linked: (T | {
35
+ value: string;
36
+ label: string;
37
+ })[];
38
+ rest: T[];
39
+ };
40
+ /** The links with `value` linked last, holding nothing; a record already linked is not linked again. */
41
+ export declare const added: (links: Link[], value: string) => Link[];
42
+ /** The links without `value`'s, the others in their order. */
43
+ export declare const removed: (links: Link[], value: string) => Link[];
44
+ /** Which link leads after a change: the lead while it is still linked, else the first link left; none with none left. */
45
+ export declare const leadAfter: (lead: string | null, after: Link[]) => string | null;
46
+ /** The links with `field` on `value`'s link set `to`; every other link, and every other field, as it was. */
47
+ export declare const setValue: (links: Link[], value: string, field: string, to: LinkValue) => Link[];
48
+ /** What several choices hold after one is pressed: a choice not held goes last, a held one comes out. */
49
+ export declare const ticked: (held: string[], choice: string) => string[];
50
+ /** The choices a link holds on a field, in the order held: several, or the one, or none. */
51
+ export declare const heldOf: (v: LinkValue | undefined) => string[];
52
+ /** What a field's list offers on a link: its choices, an archived one only where the link holds it, then each value the link holds
53
+ * that the field no longer offers (a role since removed), as it is, so it can still be unticked. A yes or no offers none. */
54
+ export declare function offered(field: LinkField, v: LinkValue | undefined): {
55
+ value: string;
56
+ label: string;
57
+ }[];
58
+ /** A field's value on a link in words, as its column reads it: several as their labels, one as its label, yes as "Yes", and
59
+ * nothing (none held, no, or nothing set) as a dash. */
60
+ export declare function said(field: LinkField, v: LinkValue | undefined, yes?: string): string;
61
+ /** A field's value as a short button says it: two whole, more as the first and how many follow ("Champion +3"); nothing, "". */
62
+ export declare function saidShort(field: LinkField, v: LinkValue | undefined, yes?: string): string;
@@ -0,0 +1,50 @@
1
+ import { fold } from "../picker/rows.js";
2
+ export function found(records, links, query, handed = false) {
3
+ const byValue = new Map(records.map((r) => [r.value, r]));
4
+ const held = new Set(links.map((l) => l.value));
5
+ if (handed) {
6
+ const typed = query.trim() !== "";
7
+ const linked = links.flatMap((l) => {
8
+ const r = byValue.get(l.value);
9
+ return r ? [r] : typed ? [] : [{ value: l.value, label: l.label ?? l.value }];
10
+ });
11
+ return { linked, rest: records.filter((r) => !held.has(r.value)) };
12
+ }
13
+ const q = fold(query), has = (label) => !q || fold(label).includes(q);
14
+ const linked = links.map((l) => byValue.get(l.value) ?? { value: l.value, label: l.label ?? l.value }).filter((r) => has(r.label));
15
+ const left = records.filter((r) => !held.has(r.value) && has(r.label));
16
+ const rest = q ? [...left.filter((r) => fold(r.label).startsWith(q)), ...left.filter((r) => !fold(r.label).startsWith(q))] : left;
17
+ return { linked, rest };
18
+ }
19
+ export const added = (links, value) => (links.some((l) => l.value === value) ? [...links] : [...links, { value, values: {} }]);
20
+ export const removed = (links, value) => links.filter((l) => l.value !== value);
21
+ export const leadAfter = (lead, after) => (lead != null && after.some((l) => l.value === lead) ? lead : after[0]?.value ?? null);
22
+ export const setValue = (links, value, field, to) => links.map((l) => (l.value === value ? { ...l, values: { ...l.values, [field]: to } } : l));
23
+ export const ticked = (held, choice) => (held.includes(choice) ? held.filter((c) => c !== choice) : [...held, choice]);
24
+ const labelOf = (field, value) => field.choices?.find((c) => c.value === value)?.label ?? value;
25
+ export const heldOf = (v) => (Array.isArray(v) ? v : typeof v === "string" && v ? [v] : []);
26
+ export function offered(field, v) {
27
+ const holds = new Set(heldOf(v));
28
+ const choices = (field.choices ?? []).filter((c) => !c.archived || holds.has(c.value)).map((c) => ({ value: c.value, label: c.label }));
29
+ if (field.kind === "yes-no")
30
+ return choices;
31
+ const known = new Set(choices.map((c) => c.value)), out = [...choices];
32
+ for (const x of heldOf(v))
33
+ if (!known.has(x)) {
34
+ known.add(x);
35
+ out.push({ value: x, label: x });
36
+ }
37
+ return out;
38
+ }
39
+ export function said(field, v, yes = "Yes") {
40
+ if (field.kind === "yes-no")
41
+ return v === true ? yes : "–";
42
+ const held = heldOf(v);
43
+ return held.length ? held.map((x) => labelOf(field, x)).join(", ") : "–";
44
+ }
45
+ export function saidShort(field, v, yes = "Yes") {
46
+ if (field.kind === "yes-no")
47
+ return v === true ? yes : "";
48
+ const held = heldOf(v).map((x) => labelOf(field, x));
49
+ return held.length <= 2 ? held.join(", ") : `${held[0]} +${held.length - 1}`;
50
+ }