viewkitjs 0.29.0 → 0.30.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 (287) hide show
  1. package/CHANGELOG.md +111 -0
  2. package/MIGRATION.md +97 -8
  3. package/package.json +1 -1
  4. package/views/dist/cells/cell-format.d.ts +2 -2
  5. package/views/dist/cells/cell-values.js +0 -2
  6. package/views/dist/contract.d.ts +15 -18
  7. package/views/dist/contract.js +13 -27
  8. package/views/dist/controls/controls.d.ts +2 -4
  9. package/views/dist/controls/controls.js +2 -2
  10. package/views/dist/controls/customize/customize.d.ts +51 -0
  11. package/views/dist/controls/customize/customize.js +128 -23
  12. package/views/dist/controls/customize/map-customize-body.d.ts +0 -3
  13. package/views/dist/controls/customize/map-customize-body.js +46 -11
  14. package/views/dist/controls/customize/map-ranges.d.ts +23 -0
  15. package/views/dist/controls/customize/map-ranges.js +41 -0
  16. package/views/dist/controls/customize/rules.d.ts +17 -1
  17. package/views/dist/controls/customize/rules.js +2 -0
  18. package/views/dist/controls/customize/words.d.ts +7 -0
  19. package/views/dist/controls/customize/words.js +5 -0
  20. package/views/dist/controls/customize.css +3 -0
  21. package/views/dist/controls/filter-editor/filter-editor.d.ts +2 -0
  22. package/views/dist/controls/filter-editor/filter-editor.js +1 -0
  23. package/views/dist/controls/filter-editor/rules.d.ts +1 -2
  24. package/views/dist/controls/index.d.ts +8 -8
  25. package/views/dist/controls/index.js +8 -8
  26. package/views/dist/controls/menu-list/menu-list.d.ts +16 -1
  27. package/views/dist/controls/menu-list/menu-list.js +26 -8
  28. package/views/dist/controls/menu-list.css +8 -0
  29. package/views/dist/controls/quick-filters/map-quick-filters-body.d.ts +1 -1
  30. package/views/dist/controls/quick-filters/map-quick-filters-body.js +6 -3
  31. package/views/dist/controls/sheet/map-sheet.js +1 -1
  32. package/views/dist/controls/text-editor/map-text-body.d.ts +1 -1
  33. package/views/dist/controls/text-editor/map-text-body.js +2 -2
  34. package/views/dist/controls/text-editor/text-editor.d.ts +3 -0
  35. package/views/dist/controls/text-editor/text-editor.js +16 -2
  36. package/views/dist/controls/text-editor.css +11 -0
  37. package/views/dist/controls/values-editor/values.js +6 -2
  38. package/views/dist/display/options.d.ts +1 -1
  39. package/views/dist/display/rich-text.js +0 -1
  40. package/views/dist/editors/ChipsEditor.d.ts +4 -5
  41. package/views/dist/editors/ChipsEditor.js +12 -78
  42. package/views/dist/editors/DateEditor.d.ts +12 -16
  43. package/views/dist/editors/DateEditor.js +40 -191
  44. package/views/dist/editors/EditorPanel.d.ts +2 -6
  45. package/views/dist/editors/EditorPanel.js +2 -2
  46. package/views/dist/editors/LocationEditor.d.ts +11 -19
  47. package/views/dist/editors/LocationEditor.js +19 -211
  48. package/views/dist/editors/NameEditor.d.ts +8 -16
  49. package/views/dist/editors/NameEditor.js +11 -100
  50. package/views/dist/editors/NumberEditor.d.ts +14 -21
  51. package/views/dist/editors/NumberEditor.js +22 -49
  52. package/views/dist/editors/RangeEditor.d.ts +9 -33
  53. package/views/dist/editors/RangeEditor.js +12 -97
  54. package/views/dist/editors/RelationEditor.d.ts +6 -9
  55. package/views/dist/editors/RelationEditor.js +11 -30
  56. package/views/dist/editors/RelationSetEditor.d.ts +13 -24
  57. package/views/dist/editors/RelationSetEditor.js +33 -101
  58. package/views/dist/editors/SelectEditor.d.ts +15 -17
  59. package/views/dist/editors/SelectEditor.js +15 -94
  60. package/views/dist/editors/TextEditor.d.ts +23 -26
  61. package/views/dist/editors/TextEditor.js +11 -48
  62. package/views/dist/editors/ValueListEditor.d.ts +14 -23
  63. package/views/dist/editors/ValueListEditor.js +16 -202
  64. package/views/dist/editors/body-panel.d.ts +13 -7
  65. package/views/dist/editors/body-panel.js +3 -7
  66. package/views/dist/editors/edit-cores.d.ts +15 -15
  67. package/views/dist/editors/edit-cores.js +14 -14
  68. package/views/dist/editors/number-body.d.ts +1 -1
  69. package/views/dist/editors/number-step.d.ts +0 -34
  70. package/views/dist/editors/number-step.js +0 -37
  71. package/views/dist/editors/option-add-flow.d.ts +1 -13
  72. package/views/dist/editors/option-add-flow.js +0 -22
  73. package/views/dist/editors/relation-links-body.d.ts +2 -3
  74. package/views/dist/editors/relation-picker.d.ts +13 -3
  75. package/views/dist/editors/relation-source.d.ts +0 -22
  76. package/views/dist/editors/relation-source.js +0 -21
  77. package/views/dist/field-row/FieldRow.js +5 -6
  78. package/views/dist/field-row/FieldRowLane.js +0 -1
  79. package/views/dist/field-row/editors/RowChipsEditor.js +2 -2
  80. package/views/dist/field-row/editors/RowDateEditor.d.ts +2 -2
  81. package/views/dist/field-row/editors/RowDateEditor.js +2 -2
  82. package/views/dist/field-row/editors/RowNameEditor.d.ts +2 -5
  83. package/views/dist/field-row/editors/RowNameEditor.js +7 -12
  84. package/views/dist/field-row/editors/RowNumberEditor.d.ts +1 -1
  85. package/views/dist/field-row/editors/RowNumberEditor.js +4 -4
  86. package/views/dist/field-row/editors/RowPlaceEditor.js +3 -3
  87. package/views/dist/field-row/editors/RowRangeEditor.d.ts +2 -5
  88. package/views/dist/field-row/editors/RowRangeEditor.js +7 -14
  89. package/views/dist/field-row/editors/RowRelationEditor.js +3 -3
  90. package/views/dist/field-row/editors/RowSelectEditor.js +2 -2
  91. package/views/dist/field-row/editors/RowTextEditor.d.ts +1 -1
  92. package/views/dist/field-row/editors/RowTextEditor.js +3 -4
  93. package/views/dist/field-row/editors/RowValueListEditor.js +5 -5
  94. package/views/dist/field-row/field-row-button.d.ts +6 -9
  95. package/views/dist/field-row/field-row-button.js +1 -6
  96. package/views/dist/field-row/field-row-checkbox.d.ts +1 -1
  97. package/views/dist/field-row/row-target.d.ts +0 -7
  98. package/views/dist/field-row/row-target.js +0 -2
  99. package/views/dist/grid/chrome/GridAddColumn.d.ts +2 -1
  100. package/views/dist/grid/chrome/GridAddColumn.js +8 -66
  101. package/views/dist/grid/chrome/GridAggregateMenu.d.ts +5 -7
  102. package/views/dist/grid/chrome/GridAggregateMenu.js +20 -39
  103. package/views/dist/grid/chrome/GridCellEditors.d.ts +2 -2
  104. package/views/dist/grid/chrome/GridCellEditors.js +12 -12
  105. package/views/dist/grid/chrome/GridChipsEditor.js +3 -3
  106. package/views/dist/grid/chrome/GridColumnMenu.d.ts +11 -12
  107. package/views/dist/grid/chrome/GridColumnMenu.js +32 -93
  108. package/views/dist/grid/chrome/GridDateEditor.d.ts +6 -6
  109. package/views/dist/grid/chrome/GridDateEditor.js +3 -3
  110. package/views/dist/grid/chrome/GridGroupMenu.d.ts +4 -6
  111. package/views/dist/grid/chrome/GridGroupMenu.js +21 -62
  112. package/views/dist/grid/chrome/GridHeader.d.ts +1 -2
  113. package/views/dist/grid/chrome/GridHeader.js +2 -2
  114. package/views/dist/grid/chrome/GridLongTextEditor.d.ts +17 -38
  115. package/views/dist/grid/chrome/GridLongTextEditor.js +6 -7
  116. package/views/dist/grid/chrome/GridNameEditor.js +4 -4
  117. package/views/dist/grid/chrome/GridNumberEditor.d.ts +4 -5
  118. package/views/dist/grid/chrome/GridNumberEditor.js +3 -4
  119. package/views/dist/grid/chrome/GridPlaceEditor.d.ts +2 -5
  120. package/views/dist/grid/chrome/GridPlaceEditor.js +5 -5
  121. package/views/dist/grid/chrome/GridRangeEditor.d.ts +6 -12
  122. package/views/dist/grid/chrome/GridRangeEditor.js +7 -15
  123. package/views/dist/grid/chrome/GridRelationEditor.js +5 -5
  124. package/views/dist/grid/chrome/GridRow.js +0 -3
  125. package/views/dist/grid/chrome/GridRowActions.d.ts +1 -1
  126. package/views/dist/grid/chrome/GridRowActions.js +0 -5
  127. package/views/dist/grid/chrome/GridRowCells.js +9 -6
  128. package/views/dist/grid/chrome/GridSelectEditor.js +3 -3
  129. package/views/dist/grid/chrome/GridStructure.js +0 -1
  130. package/views/dist/grid/chrome/GridTable.js +1 -1
  131. package/views/dist/grid/chrome/GridTextEditor.d.ts +5 -7
  132. package/views/dist/grid/chrome/GridTextEditor.js +4 -17
  133. package/views/dist/grid/chrome/GridValueListEditor.js +4 -4
  134. package/views/dist/grid/chrome/grid-body-place.d.ts +2 -3
  135. package/views/dist/grid/chrome/grid-body-place.js +4 -8
  136. package/views/dist/grid/chrome/grid-button.d.ts +7 -10
  137. package/views/dist/grid/chrome/grid-button.js +1 -6
  138. package/views/dist/grid/chrome/grid-cell-classes.js +1 -1
  139. package/views/dist/grid/chrome/grid-column-menu-items.d.ts +4 -4
  140. package/views/dist/grid/chrome/grid-column-menu-items.js +10 -6
  141. package/views/dist/grid/chrome/grid-group-menu-parts.d.ts +5 -9
  142. package/views/dist/grid/chrome/grid-group-menu-parts.js +1 -3
  143. package/views/dist/grid/chrome/grid-hover.js +0 -1
  144. package/views/dist/grid/chrome/grid-menu-focus.d.ts +7 -31
  145. package/views/dist/grid/chrome/grid-menu-focus.js +7 -47
  146. package/views/dist/grid/chrome/grid-styles.d.ts +0 -3
  147. package/views/dist/grid/chrome/grid-styles.js +0 -1
  148. package/views/dist/grid/chrome/grid-table-props.d.ts +6 -10
  149. package/views/dist/grid/chrome/useGridTableInteractionModel.js +2 -4
  150. package/views/dist/grid/core/editing-controller.d.ts +2 -1
  151. package/views/dist/grid/core/editing-controller.js +10 -2
  152. package/views/dist/grid/core/refusal-sentence.d.ts +3 -0
  153. package/views/dist/grid/core/refusal-sentence.js +2 -2
  154. package/views/dist/grid/core/write-states.d.ts +3 -1
  155. package/views/dist/grid/core/write-states.js +6 -2
  156. package/views/dist/grid/grid.css +1 -1
  157. package/views/dist/model/body-frame.d.ts +0 -32
  158. package/views/dist/model/body-frame.js +1 -15
  159. package/views/dist/model/column-inspect.d.ts +5 -5
  160. package/views/dist/model/column-inspect.js +2 -2
  161. package/views/dist/panels/customize-body.d.ts +1 -10
  162. package/views/dist/panels/customize-body.js +0 -3
  163. package/views/dist/panels/filter/MenuSelect.js +0 -5
  164. package/views/dist/panels/filter/RangeFilterBody.js +0 -1
  165. package/views/dist/panels/filter/details.d.ts +1 -5
  166. package/views/dist/panels/filter/details.js +0 -13
  167. package/views/dist/panels/filter/filter-list.d.ts +0 -1
  168. package/views/dist/panels/filter/filter-list.js +1 -1
  169. package/views/dist/panels/panel-button.d.ts +10 -12
  170. package/views/dist/panels/panel-button.js +1 -6
  171. package/views/dist/panels/react/chrome.d.ts +0 -17
  172. package/views/dist/panels/react/chrome.js +0 -8
  173. package/views/dist/panels/react/customize-body.d.ts +9 -12
  174. package/views/dist/panels/react/customize-body.js +57 -11
  175. package/views/dist/panels/react/customize.d.ts +9 -12
  176. package/views/dist/panels/react/customize.js +3 -112
  177. package/views/dist/panels/react/filter/FilterEditor.d.ts +4 -18
  178. package/views/dist/panels/react/filter/FilterEditor.js +6 -330
  179. package/views/dist/panels/react/filter/FilterFieldList.d.ts +1 -1
  180. package/views/dist/panels/react/filter/FilterFieldList.js +27 -59
  181. package/views/dist/panels/react/filter/PhoneFilterEditor.d.ts +1 -11
  182. package/views/dist/panels/react/filter/PhoneFilterEditor.js +8 -144
  183. package/views/dist/panels/react/filter/editor-ctx.d.ts +1 -33
  184. package/views/dist/panels/react/filter/editor-ctx.js +5 -33
  185. package/views/dist/panels/react/filter/filter-part-body.d.ts +3 -6
  186. package/views/dist/panels/react/filter/filter-part-body.js +0 -5
  187. package/views/dist/panels/react/filter/rule-writes.d.ts +1 -26
  188. package/views/dist/panels/react/filter/rule-writes.js +4 -95
  189. package/views/dist/panels/react/order-details.d.ts +1 -26
  190. package/views/dist/panels/react/order-details.js +3 -69
  191. package/views/dist/panels/react/panel-header.js +0 -1
  192. package/views/dist/panels/react/popover.d.ts +4 -7
  193. package/views/dist/panels/react/quick/QuickFiltersPanel.d.ts +2 -4
  194. package/views/dist/panels/react/quick/QuickFiltersPanel.js +16 -137
  195. package/views/dist/panels/react/sort/SortEditor.d.ts +4 -4
  196. package/views/dist/panels/react/sort/SortEditor.js +8 -245
  197. package/views/dist/panels/react/sort/SortFieldList.d.ts +1 -1
  198. package/views/dist/panels/react/sort/SortFieldList.js +11 -25
  199. package/views/dist/panels/react/toolbar/ToolbarAdvancedFilters.js +2 -2
  200. package/views/dist/panels/react/toolbar/ToolbarBarFilter.js +4 -16
  201. package/views/dist/panels/react/toolbar/ToolbarQuickFilters.js +1 -1
  202. package/views/dist/panels/react/toolbar/ToolbarSave.js +0 -4
  203. package/views/dist/panels/react/toolbar/ToolbarSearch.js +0 -1
  204. package/views/dist/panels/react/toolbar/ToolbarSortPill.js +3 -3
  205. package/views/dist/panels/react/view-actions.js +0 -1
  206. package/views/dist/panels/react/views-row/FoldingViewRow.js +2 -5
  207. package/views/dist/panels/react/views-row/ViewCreatePill.js +0 -1
  208. package/views/dist/panels/react/views-row/ViewPicker.js +7 -43
  209. package/views/dist/panels/react/views-row/ViewPickerRow.js +0 -2
  210. package/views/dist/panels/react/views-row/menu-classes.d.ts +0 -4
  211. package/views/dist/panels/react/views-row/menu-classes.js +0 -2
  212. package/views/dist/panels/react.d.ts +5 -12
  213. package/views/dist/panels/react.js +5 -12
  214. package/views/dist/provider/ViewsProvider.d.ts +2 -46
  215. package/views/dist/provider/ViewsProvider.js +2 -22
  216. package/views/dist/provider/components.d.ts +153 -106
  217. package/views/dist/provider/context.d.ts +1 -21
  218. package/views/dist/provider/missing-slot.d.ts +3 -7
  219. package/views/dist/provider/missing-slot.js +2 -9
  220. package/views/dist/react.d.ts +1 -2
  221. package/views/dist/selection/SelectionBar.js +2 -3
  222. package/views/dist/styles.css +40 -168
  223. package/views/dist/styles.unlayered.css +40 -168
  224. package/views/docs/contract.md +99 -123
  225. package/views/docs/getting-started.md +222 -2
  226. package/views/docs/guides/cells.md +222 -2
  227. package/views/docs/guides/display.md +1 -1
  228. package/views/docs/guides/editors.md +235 -20
  229. package/views/docs/guides/ports.md +1 -1
  230. package/views/docs/guides/selection.md +1 -1
  231. package/views/docs/guides/the-grid.md +14 -16
  232. package/views/docs/guides/the-provider.md +9 -15
  233. package/views/docs/reference/cells.md +1 -1
  234. package/views/docs/reference/controls.md +26 -13
  235. package/views/docs/reference/editors-chips.md +2 -2
  236. package/views/docs/reference/editors-date.md +4 -4
  237. package/views/docs/reference/editors-location.md +4 -7
  238. package/views/docs/reference/editors-name.md +3 -5
  239. package/views/docs/reference/editors-number.md +10 -10
  240. package/views/docs/reference/editors-panel.md +3 -3
  241. package/views/docs/reference/editors-range.md +3 -5
  242. package/views/docs/reference/editors-relation.md +4 -4
  243. package/views/docs/reference/editors-select.md +3 -3
  244. package/views/docs/reference/editors-text.md +3 -4
  245. package/views/docs/reference/editors-value-list.md +3 -3
  246. package/views/docs/reference/field-row.md +1 -1
  247. package/views/docs/reference/grid.md +2 -2
  248. package/views/docs/reference/panels-react.md +20 -34
  249. package/views/docs/reference/react.md +11 -18
  250. package/views/docs/reference/views.md +5 -5
  251. package/views/skills/views/SKILL.md +1 -1
  252. package/views/dist/editors/relation-panel.d.ts +0 -69
  253. package/views/dist/editors/relation-panel.js +0 -46
  254. package/views/dist/grid/chrome/GridColumnColorSection.d.ts +0 -13
  255. package/views/dist/grid/chrome/GridColumnColorSection.js +0 -40
  256. package/views/dist/grid/chrome/GridColumnDateSection.d.ts +0 -28
  257. package/views/dist/grid/chrome/GridColumnDateSection.js +0 -23
  258. package/views/dist/grid/chrome/GridColumnDurationSection.d.ts +0 -23
  259. package/views/dist/grid/chrome/GridColumnDurationSection.js +0 -24
  260. package/views/dist/grid/chrome/GridColumnNumberSection.d.ts +0 -29
  261. package/views/dist/grid/chrome/GridColumnNumberSection.js +0 -27
  262. package/views/dist/grid/chrome/GridColumnPercentSection.d.ts +0 -16
  263. package/views/dist/grid/chrome/GridColumnPercentSection.js +0 -16
  264. package/views/dist/grid/chrome/GridColumnSortSection.d.ts +0 -38
  265. package/views/dist/grid/chrome/GridColumnSortSection.js +0 -33
  266. package/views/dist/grid/chrome/GridFlyout.d.ts +0 -44
  267. package/views/dist/grid/chrome/GridFlyout.js +0 -80
  268. package/views/dist/grid/chrome/GridMenuRow.d.ts +0 -15
  269. package/views/dist/grid/chrome/GridMenuRow.js +0 -15
  270. package/views/dist/grid/chrome/grid-menu-search.d.ts +0 -7
  271. package/views/dist/grid/chrome/grid-menu-search.js +0 -7
  272. package/views/dist/panels/react/GroupBucketsList.d.ts +0 -16
  273. package/views/dist/panels/react/GroupBucketsList.js +0 -44
  274. package/views/dist/panels/react/LayoutColumnsList.d.ts +0 -24
  275. package/views/dist/panels/react/LayoutColumnsList.js +0 -101
  276. package/views/dist/panels/react/PopoverColumnDetail.d.ts +0 -11
  277. package/views/dist/panels/react/PopoverColumnDetail.js +0 -24
  278. package/views/dist/panels/react/drag.d.ts +0 -2
  279. package/views/dist/panels/react/drag.js +0 -5
  280. package/views/dist/panels/react/layout-detail.d.ts +0 -4
  281. package/views/dist/panels/react/layout-detail.js +0 -29
  282. package/views/dist/panels/react/root-list.d.ts +0 -6
  283. package/views/dist/panels/react/root-list.js +0 -31
  284. package/views/dist/panels/react/sort/use-sort-drag.d.ts +0 -17
  285. package/views/dist/panels/react/sort/use-sort-drag.js +0 -39
  286. package/views/dist/panels/react/view-footer.d.ts +0 -20
  287. package/views/dist/panels/react/view-footer.js +0 -41
@@ -1,11 +1,10 @@
1
1
  "use client";
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
- import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react";
3
+ import { forwardRef, useImperativeHandle, useRef, useState } from "react";
4
4
  import { relationRolesOf, } from "viewkitjs/fields";
5
5
  import { useViews } from "../provider/context.js";
6
6
  import { sameRoles, writtenRoles } from "./link-roles.js";
7
7
  import { RelationLinksBody } from "./relation-links-body.js";
8
- import { RelationPanel } from "./relation-panel.js";
9
8
  import { RelationPickerBody } from "./relation-picker.js";
10
9
  function opening(items, lead) {
11
10
  if (!lead)
@@ -30,45 +29,28 @@ function rolesOffered(links) {
30
29
  ...(role.archived ? { archived: true } : {}),
31
30
  }));
32
31
  }
33
- function highlightedIn(search) {
34
- const row = search.getAttribute("aria-activedescendant");
35
- if (!row)
36
- return undefined;
37
- return search.ownerDocument.getElementById(row)?.getAttribute("data-value") ?? undefined;
38
- }
39
32
  export const RelationSetEditor = forwardRef(function RelationSetEditor({ candidates, initial, lead = false, onRequestClose, kindGlyph, message, creates, seed, focusSearch = false, label, links, }, ref) {
40
33
  const [start] = useState(() => opening(initial, lead));
41
34
  const [draft, setDraft] = useState(start);
42
35
  const draftRef = useRef(draft);
43
36
  const [query, setQuery] = useState(seed ?? "");
44
- const searchRef = useRef(null);
45
37
  const views = useViews();
46
38
  const words = message ?? views.conventions.messages;
47
- const { Command, Button, Picker, LinksBody } = views.components;
48
- const linksBody = links !== undefined && LinksBody ? LinksBody : null;
39
+ const { Picker, LinksBody } = views.components;
49
40
  const [rolesAtOpen] = useState(() => new Map(start.map((item) => [item.id, relationRolesOf(item)])));
50
41
  const [roles, setRoles] = useState(rolesAtOpen);
51
42
  const rolesRef = useRef(roles);
52
43
  const [leadId, setLeadId] = useState(() => (lead ? (start[0]?.id ?? null) : null));
53
44
  const leadRef = useRef(leadId);
54
- const { RowContent } = views.atoms;
55
- useEffect(() => {
56
- if (focusSearch)
57
- searchRef.current?.focus({ preventScroll: true });
58
- }, []);
59
- const movedRef = useRef(false);
60
- const openedOn = start[0]?.id;
61
45
  const change = (next) => {
62
46
  const marked = lead ? next.map((item, index) => ({ ...item, primary: index === 0 })) : next;
63
47
  draftRef.current = marked;
64
48
  setDraft(marked);
65
- if (focusSearch)
66
- searchRef.current?.focus({ preventScroll: true });
67
49
  };
68
50
  const resolveClose = (reason) => {
69
51
  if (reason === "escape")
70
52
  return { kind: "cancel" };
71
- if (linksBody) {
53
+ if (links) {
72
54
  const held = draftRef.current;
73
55
  const first = held.find((item) => item.id === leadRef.current);
74
56
  const ordered = first ? [first, ...held.filter((item) => item !== first)] : held;
@@ -82,21 +64,15 @@ export const RelationSetEditor = forwardRef(function RelationSetEditor({ candida
82
64
  return same ? { kind: "noop" } : { kind: "commit", payload: linksOf(now, lead) };
83
65
  };
84
66
  useImperativeHandle(ref, () => ({ resolveClose }));
85
- const linked = new Set(draft.map((item) => item.id));
86
- const remove = (id) => change(draftRef.current.filter((item) => item.id !== id));
87
67
  const makeLead = (id) => {
88
68
  const item = draftRef.current.find((each) => each.id === id);
89
69
  if (item)
90
70
  change([item, ...draftRef.current.filter((each) => each.id !== id)]);
91
71
  };
92
- const typed = query.trim().toLowerCase();
93
- const shown = candidates.kind === "remote" && typed !== ""
94
- ? draft.filter((item) => item.label.toLowerCase().includes(typed))
95
- : draft;
96
- if (linksBody && links) {
72
+ if (links) {
97
73
  const live = new Set((links.roles ?? []).filter((role) => !role.archived).map((role) => role.value));
98
74
  const declared = new Set((links.roles ?? []).map((role) => role.value));
99
- return (_jsx(RelationLinksBody, { LinksBody: linksBody, label: label ?? words({ key: "editor.search" }), candidates: candidates, query: query, onQueryChange: setQuery, held: draft, links: draft.map((item) => ({ value: item.id, roles: roles.get(item.id) ?? [] })), onLinksChange: (next, found) => {
75
+ return (_jsx(RelationLinksBody, { LinksBody: LinksBody, label: label ?? words({ key: "editor.search" }), candidates: candidates, query: query, onQueryChange: setQuery, held: draft, links: draft.map((item) => ({ value: item.id, roles: roles.get(item.id) ?? [] })), onLinksChange: (next, found) => {
100
76
  const items = [];
101
77
  const nextRoles = new Map();
102
78
  for (const link of next) {
@@ -145,78 +121,34 @@ export const RelationSetEditor = forwardRef(function RelationSetEditor({ candida
145
121
  create.onCreate(text);
146
122
  }, kindGlyph: kindGlyph, search: words({ key: "editor.search" }), typed: seed, autoFocus: focusSearch, onRequestClose: onRequestClose }));
147
123
  }
148
- if (Picker) {
149
- return (_jsx(RelationPickerBody, { Picker: Picker, label: label ?? words({ key: "editor.search" }), candidates: candidates, query: query, onQueryChange: setQuery, held: draft, multiple: true, value: draft.map((item) => item.id), onValueChange: (next, found) => {
150
- const ids = Array.isArray(next) ? next : [];
151
- const kept = draftRef.current.filter((item) => ids.includes(item.id));
152
- const added = ids
153
- .filter((id) => !kept.some((item) => item.id === id))
154
- .flatMap((id) => {
155
- const candidate = found(id);
156
- return candidate
157
- ? [
158
- {
159
- id,
160
- label: candidate.label,
161
- ...(candidate.kind !== undefined ? { kind: candidate.kind } : {}),
162
- ...(candidate.icon != null ? { icon: candidate.icon } : {}),
163
- },
164
- ]
165
- : [];
166
- });
167
- change([...kept, ...added]);
168
- }, onDone: () => onRequestClose("pick"), creates: creates, onCreate: (create, text) => {
169
- onRequestClose("pick");
170
- create.onCreate(text);
171
- }, kindGlyph: kindGlyph, search: words({ key: "editor.search" }), lead: lead
172
- ? {
173
- value: draft[0]?.id ?? null,
174
- onLead: makeLead,
175
- label: words({ key: "relation.lead" }),
176
- makeLabel: words({ key: "relation.make-lead" }),
177
- }
178
- : undefined, onTab: (reason) => onRequestClose(reason), typed: seed, autoFocus: focusSearch }));
179
- }
180
- return (_jsx(RelationPanel, { candidates: candidates, query: query, onQueryChange: (next) => {
181
- movedRef.current = true;
182
- setQuery(next);
183
- }, searchRef: searchRef, onSearchKeyDown: (event) => {
184
- if (["ArrowDown", "ArrowUp", "Home", "End"].includes(event.key))
185
- movedRef.current = true;
186
- if (event.key === "Enter" && !movedRef.current && query === "" && openedOn !== undefined) {
187
- const now = highlightedIn(event.currentTarget);
188
- if (now === undefined || now === openedOn) {
189
- event.preventDefault();
190
- event.stopPropagation();
191
- return;
192
- }
193
- }
194
- if (event.key === " " && lead && query === "") {
195
- const now = highlightedIn(event.currentTarget);
196
- if (now !== undefined && linked.has(now)) {
197
- event.preventDefault();
198
- makeLead(now);
199
- return;
200
- }
201
- }
202
- if (event.key === "Tab") {
203
- event.preventDefault();
204
- onRequestClose(event.shiftKey ? "shift-tab" : "tab");
205
- }
206
- }, kindGlyph: kindGlyph, message: message, creates: creates, onCreate: (create, text) => {
124
+ return (_jsx(RelationPickerBody, { Picker: Picker, label: label ?? words({ key: "editor.search" }), candidates: candidates, query: query, onQueryChange: setQuery, held: draft, multiple: true, value: draft.map((item) => item.id), onValueChange: (next, found) => {
125
+ const ids = Array.isArray(next) ? next : [];
126
+ const kept = draftRef.current.filter((item) => ids.includes(item.id));
127
+ const added = ids
128
+ .filter((id) => !kept.some((item) => item.id === id))
129
+ .flatMap((id) => {
130
+ const candidate = found(id);
131
+ return candidate
132
+ ? [
133
+ {
134
+ id,
135
+ label: candidate.label,
136
+ ...(candidate.kind !== undefined ? { kind: candidate.kind } : {}),
137
+ ...(candidate.icon != null ? { icon: candidate.icon } : {}),
138
+ },
139
+ ]
140
+ : [];
141
+ });
142
+ change([...kept, ...added]);
143
+ }, onDone: () => onRequestClose("pick"), creates: creates, onCreate: (create, text) => {
207
144
  onRequestClose("pick");
208
145
  create.onCreate(text);
209
- }, labels: new Map(draft.map((item) => [item.id, item.label])), drawsBefore: shown.length > 0, hide: (id) => linked.has(id), isChosen: (id) => linked.has(id), onSelect: (candidate) => {
210
- if (linked.has(candidate.id))
211
- return remove(candidate.id);
212
- change([
213
- ...draftRef.current,
214
- {
215
- id: candidate.id,
216
- label: candidate.label,
217
- ...(candidate.kind !== undefined ? { kind: candidate.kind } : {}),
218
- ...(candidate.icon != null ? { icon: candidate.icon } : {}),
219
- },
220
- ]);
221
- }, before: ({ glyphs, glyph }) => shown.map((item) => (_jsx(Command.Item, { value: item.id, onSelect: () => remove(item.id), chosen: true, children: _jsx(RowContent, { size: "compact", leading: glyph(item.icon ?? kindGlyph), leadingLane: glyphs, label: item.label, trailing: !lead ? undefined : item.id === draft[0]?.id ? (_jsx("span", { "data-slot": "vk-relation-lead", className: "ml-2 shrink-0 text-(length:--vk-caption-text,11px) text-(color:--vk-fg-subtle)", children: words({ key: "relation.lead" }) })) : (_jsx("span", { className: "ml-2 shrink-0", onMouseDown: (event) => event.preventDefault(), onClick: (event) => event.stopPropagation(), children: _jsx(Button, { variant: "ghost", size: "sm", className: "h-6 px-1.5 text-(length:--vk-caption-text,11px)", onClick: () => makeLead(item.id), children: words({ key: "relation.make-lead" }) }) })), chosen: true, chosenTint: false }) }, item.id))) }));
146
+ }, kindGlyph: kindGlyph, search: words({ key: "editor.search" }), lead: lead
147
+ ? {
148
+ value: draft[0]?.id ?? null,
149
+ onLead: makeLead,
150
+ label: words({ key: "relation.lead" }),
151
+ makeLabel: words({ key: "relation.make-lead" }),
152
+ }
153
+ : undefined, onTab: (reason) => onRequestClose(reason), typed: seed, autoFocus: focusSearch }));
222
154
  });
@@ -2,7 +2,7 @@ import { type CategoryColor } from "viewkitjs/fields/design/category-colors";
2
2
  import type { StatusSlot } from "viewkitjs/fields/design/status-slots";
3
3
  import { type CloseReason, type CloseResolution, type FieldDefOf, type FieldMessageResolver } from "viewkitjs/fields";
4
4
  import type { ViewsStatusOption } from "../atoms/types.js";
5
- import { type OptionAdd } from "../fields/option-add.js";
5
+ import type { OptionAdd } from "../fields/option-add.js";
6
6
  /**
7
7
  * THE option-picking core — one panel, many surfaces.
8
8
  *
@@ -13,7 +13,7 @@ import { type OptionAdd } from "../fields/option-add.js";
13
13
  * select — a pick is the commit, everything else discards.
14
14
  *
15
15
  * It takes ready `PickerOption[]` rather than a field: the rows are the app's
16
- * `Row` atom with its badges; colours are resolved by the caller (the grid's
16
+ * `Picker` (the components map's), handed them as data; colours are resolved by the caller (the grid's
17
17
  * are per-user prefs), and resolving them here would drag grid state into a
18
18
  * component the whole app renders. `pickerOptionsFromField` below is the
19
19
  * mapping for a caller that HAS a field definition.
@@ -33,8 +33,8 @@ export type PickerOption = {
33
33
  /** The option's glyph (the app's own name), drawn by the app's AppIcon before its label. */
34
34
  icon?: string;
35
35
  };
36
- /** A closed list longer than this opens with a search on top; this many or fewer stay a plain list (decided
37
- * 10 Nov): a short list reads at a glance, and a search over four options is one more thing in the way. */
36
+ /** A closed list longer than this shows the Picker's search; this many or fewer stay a plain list (decided 10 Nov): a
37
+ * short list reads at a glance, and a search over four options is one more thing in the way. The Picker keeps the rule. */
38
38
  export declare const SELECT_SEARCH_PAST = 8;
39
39
  export type SelectEditorHandle = {
40
40
  /** What this close means. Synchronous, idempotent, no timer — the host
@@ -63,24 +63,22 @@ export declare const SelectEditor: import("react").ForwardRefExoticComponent<{
63
63
  * text when no option's value is it (POR-898: Enter picks the first match). Picking that row commits the
64
64
  * trimmed text. */
65
65
  creatable?: boolean;
66
- /** The text the search opens with (a letter typed on the cell that opened it), when the panel shows a search:
67
- * an open select, or a closed list past `SELECT_SEARCH_PAST` options. A plain list ignores it. */
66
+ /** The text the search opens with (a letter typed on the cell that opened it). */
68
67
  seed?: string;
69
- /** Put the caret in the search when the panel opens with one, without scrolling. Default false: a host whose
70
- * surface raises no keyboard (a phone's sheet) leaves it off. */
68
+ /** The Picker takes the focus as the panel opens, without scrolling. Default false: a host whose surface raises
69
+ * no keyboard (a phone's sheet) leaves it off. */
71
70
  focusSearch?: boolean;
72
- /** Opened from the keyboard: a plain list puts the focus on the row it holds (None when it may be emptied and
73
- * holds nothing, else its first row), so an Enter at once changes nothing; ↓ and ↑ walk its rows, round at either
74
- * end, and Enter picks the focused one. Default false: a list opened by a pointer moves no focus. A list with a
75
- * search ignores it, and `focusSearch` gives that one the keys. A card's field and a field row set it when a key
76
- * pressed their button, and a grid's cell when Enter or a typed letter opened it on a computer. Either kind of list takes Tab and Shift-Tab itself and closes with them. */
71
+ /** Opened from the keyboard: the Picker takes the focus and the row it holds is the keys' place, so an Enter at
72
+ * once changes nothing and ↓ goes on to the next option. Default false: opened by a pointer, nothing is lit until
73
+ * ↓ or ↑, which still go on from the held row. A card's field and a field row set it when a key pressed their
74
+ * button, and a grid's cell when Enter or a typed letter opened it on a computer. Tab and Shift-Tab close it. */
77
75
  focusList?: boolean;
78
76
  /** The field's name, for an app's own `Picker` (its list's accessible name). Default: the search's words. */
79
77
  label?: string;
80
- /** The app adds a typed word to the field's list: the panel always shows its search, and after the matches a row
81
- * offers + Add, which asks it; the option it returns is picked once this panel's `options` carry it. A word an
82
- * option already names (spaces, case and accents aside) picks that option instead. Handed, the typed word is
83
- * never saved as itself: no Use row, no `onCreate`. */
78
+ /** The app adds a typed word to the field's list: the Picker is handed + Add (`onAdd`, `adding`, `addRefused`),
79
+ * which asks it; the option it returns is picked once this panel's `options` carry it. A word an option already
80
+ * names (spaces, case and accents aside) picks that option instead. Handed, the typed word is never saved as
81
+ * itself: no `onCreate`. */
84
82
  addOption?: OptionAdd;
85
83
  } & import("react").RefAttributes<SelectEditorHandle>>;
86
84
  /**
@@ -1,28 +1,19 @@
1
1
  "use client";
2
- import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { forwardRef, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { forwardRef, useImperativeHandle, useMemo, useRef, useState } from "react";
4
4
  import { resolveCategoryColor } from "viewkitjs/fields/design/category-colors";
5
5
  import { optionsOf, } from "viewkitjs/fields";
6
- import { placeAmong } from "../display/status-steps.js";
7
6
  import { useViews } from "../provider/context.js";
8
7
  import { PickerFrame, pickerItemOf, typedPick, usePickerForm } from "./picker-slot.js";
9
- import { namedOption } from "../fields/option-add.js";
10
- import { AddRows, bodyAdd, useOptionAdd } from "./option-add-flow.js";
8
+ import { bodyAdd, useOptionAdd } from "./option-add-flow.js";
11
9
  export const SELECT_SEARCH_PAST = 8;
12
10
  export const SelectEditor = forwardRef(function SelectEditor({ options, steps, initial, clearable = false, onRequestClose, message, creatable = false, seed, focusSearch = false, focusList = false, label, addOption, }, ref) {
13
- const searchable = creatable || !!addOption || options.length > SELECT_SEARCH_PAST;
14
11
  const [picked, setPicked] = useState(null);
15
12
  const pickedRef = useRef(null);
16
- const [query, setQuery] = useState(searchable ? (seed ?? "") : "");
17
- const searchRef = useRef(null);
18
- const listRef = useRef(null);
19
13
  const views = useViews();
20
14
  const words = message ?? views.conventions.messages;
21
- const { List, Row, RowContent, StatusBadge, Tag } = views.atoms;
22
- const { AppIcon, Command, Picker } = views.components;
15
+ const { Picker } = views.components;
23
16
  const form = usePickerForm();
24
- const Add = views.icons.add;
25
- const glyph = (icon) => (icon ? _jsx(AppIcon, { name: icon, className: "size-3 shrink-0" }) : undefined);
26
17
  const carried = useMemo(() => options.map((option) => option.value), [options]);
27
18
  const adding = useOptionAdd({
28
19
  addOption,
@@ -44,94 +35,24 @@ export const SelectEditor = forwardRef(function SelectEditor({ options, steps, i
44
35
  return value === (initial ?? "") ? { kind: "noop" } : { kind: "commit", payload: value };
45
36
  };
46
37
  useImperativeHandle(ref, () => ({ resolveClose }));
47
- const rows = clearable
48
- ? [{ value: "", label: words({ key: "relation.none" }) }, ...options]
49
- : options;
50
- const current = picked ?? initial ?? (clearable ? "" : undefined);
51
- useEffect(() => {
52
- if (Picker)
53
- return;
54
- if (searchable) {
55
- if (focusSearch)
56
- searchRef.current?.focus({ preventScroll: true });
57
- return;
58
- }
59
- if (!focusList)
60
- return;
61
- const at = rows.findIndex((option) => option.value === current);
62
- const buttons = listButtons(listRef.current);
63
- (buttons[at] ?? buttons[0])?.focus({ preventScroll: true });
64
- }, []);
65
38
  const choose = (value) => {
66
39
  pickedRef.current = value;
67
40
  setPicked(value);
68
41
  requestClose("pick");
69
42
  };
70
- const leaveOnTab = (event) => {
71
- if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey)
72
- return false;
73
- event.preventDefault();
74
- requestClose(event.shiftKey ? "shift-tab" : "tab");
75
- return true;
43
+ const take = (value) => {
44
+ if (Array.isArray(value) || (value === null && !clearable))
45
+ return;
46
+ if (value !== null && !(creatable && !addOption) && !options.some((option) => option.value === value))
47
+ return;
48
+ adding.cancel();
49
+ pickedRef.current = value ?? "";
50
+ setPicked(pickedRef.current);
76
51
  };
77
- const badge = (option) => option.slot ? (_jsx(StatusBadge, { slot: option.slot, label: option.label, leading: glyph(option.icon), place: steps && placeAmong(steps, option.value) })) : option.color ? (_jsx(Tag, { label: option.label, color: option.color, leading: glyph(option.icon) })) : (option.label);
78
- if (Picker) {
79
- const take = (value) => {
80
- if (Array.isArray(value) || (value === null && !clearable))
81
- return;
82
- if (value !== null && !(creatable && !addOption) && !options.some((option) => option.value === value))
83
- return;
84
- adding.cancel();
85
- pickedRef.current = value ?? "";
86
- setPicked(pickedRef.current);
87
- };
88
- return (_jsx(PickerFrame, { onTab: (reason) => requestClose(reason), children: _jsx(Picker, { label: label ?? words({ key: "editor.search" }), items: options.map(pickerItemOf), value: (picked ?? initial) || null, onValueChange: take, onDone: () => requestClose("pick"), empty: clearable ? words({ key: "relation.none" }) : undefined, search: words({ key: "editor.search" }), onCreate: creatable && !addOption
89
- ? (typed) => typedPick(typed, options.map((option) => option.value), pickedRef.current ?? initial ?? "")
90
- : undefined, typed: seed, autoFocus: focusSearch || focusList, keyed: focusList, fromHeld: true, form: form, ...(steps ? { steps: steps.map((step) => step.value) } : {}), ...bodyAdd(adding, !!addOption) }) }));
91
- }
92
- if (searchable) {
93
- const typed = query.trim();
94
- const needle = typed.toLowerCase();
95
- const matches = (typed === "" ? rows : options).filter((option) => needle === "" || option.label.toLowerCase().includes(needle));
96
- const named = addOption ? namedOption(typed, options) : undefined;
97
- const shown = named ? [named, ...matches.filter((option) => option !== named)] : matches;
98
- const useTyped = !addOption && creatable && typed !== "" && !options.some((option) => option.value.toLowerCase() === needle);
99
- const addRow = addOption && typed !== "" && !named;
100
- const itemValue = (value) => (value === "" ? noneValue(options) : value);
101
- const startOn = clearable && !seed?.trim() ? itemValue(initial ?? "") : undefined;
102
- const useRow = useTyped && (_jsx(Command.Item, { value: `__use__${typed}`, onSelect: () => choose(typed), children: _jsx(RowContent, { size: "compact", tone: "muted", leading: _jsx(Add, { className: "h-3.5 w-3.5 shrink-0" }), label: words({ key: "editor.use-value", values: { value: typed } }) }) }));
103
- return (_jsxs(Command.Root, { shouldFilter: false, loop: true, defaultValue: startOn, children: [_jsx(Command.Input, { ref: searchRef, placeholder: words({ key: "editor.search" }), className: "h-9 text-(length:--vk-input-text,13px)", value: query, onValueChange: (next) => {
104
- setQuery(next);
105
- adding.clear();
106
- }, onKeyDown: leaveOnTab }), _jsxs(Command.List, { className: "max-h-72 overscroll-contain scrollbar-overlay", children: [!useTyped && !addRow && !adding.state && shown.length === 0 && (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: words({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsxs(List, { children: [shown.map((option) => (_jsx(Command.Item, { value: itemValue(option.value), onSelect: () => choose(option.value), chosen: current === option.value, children: _jsx(RowContent, { size: option.slot || option.color ? undefined : "compact", leading: option.slot || option.color ? undefined : glyph(option.icon), label: badge(option), chosen: current === option.value, chosenTint: false }) }, option.value))), useRow, addOption && _jsx(AddRows, { adding: adding, typed: addRow ? typed : "" })] }) })] })] }));
107
- }
108
- return (_jsx("div", { ref: listRef, className: "contents", onKeyDown: (event) => {
109
- if (!leaveOnTab(event))
110
- walkRows(event);
111
- }, children: _jsx(List, { className: "max-h-72 overflow-y-auto overscroll-contain scrollbar-overlay", children: rows.map((option) => (_jsx(Row, { chosen: current === option.value, chosenTint: false, size: option.slot || option.color ? undefined : "compact", leading: option.slot || option.color ? undefined : glyph(option.icon), label: badge(option), onClick: () => choose(option.value) }, option.value))) }) }));
52
+ return (_jsx(PickerFrame, { onTab: (reason) => requestClose(reason), children: _jsx(Picker, { label: label ?? words({ key: "editor.search" }), items: options.map(pickerItemOf), value: (picked ?? initial) || null, onValueChange: take, onDone: () => requestClose("pick"), empty: clearable ? words({ key: "relation.none" }) : undefined, search: words({ key: "editor.search" }), onCreate: creatable && !addOption
53
+ ? (typed) => typedPick(typed, options.map((option) => option.value), pickedRef.current ?? initial ?? "")
54
+ : undefined, typed: seed, autoFocus: focusSearch || focusList, keyed: focusList, fromHeld: true, form: form, ...(steps ? { steps: steps.map((step) => step.value) } : {}), ...bodyAdd(adding, !!addOption) }) }));
112
55
  });
113
- function listButtons(box) {
114
- return box ? [...box.querySelectorAll("button:not(:disabled)")] : [];
115
- }
116
- function walkRows(event) {
117
- if (event.key !== "ArrowDown" && event.key !== "ArrowUp")
118
- return;
119
- if (event.altKey || event.ctrlKey || event.metaKey || event.shiftKey)
120
- return;
121
- const rows = listButtons(event.currentTarget);
122
- const at = rows.indexOf(document.activeElement);
123
- if (rows.length === 0 || at < 0)
124
- return;
125
- event.preventDefault();
126
- const step = event.key === "ArrowDown" ? 1 : -1;
127
- rows[(at + step + rows.length) % rows.length].focus();
128
- }
129
- function noneValue(options) {
130
- let value = "__none__";
131
- while (options.some((option) => option.value === value))
132
- value = `_${value}`;
133
- return value;
134
- }
135
56
  export function pickerOptionsFromField(field, opts = {}) {
136
57
  const active = [...optionsOf(field)];
137
58
  const declared = new Set(active.map((o) => o.value));
@@ -1,53 +1,48 @@
1
1
  import { type CSSProperties } from "react";
2
2
  import type { CloseReason, CloseResolution } from "viewkitjs/fields";
3
3
  /**
4
- * THE TEXT EDITOR — one box for every text-like value: text, a link, an email, a phone, a domain,
5
- * long text and rich text (VK-218). It owns what every surface used to write for itself and got
6
- * different: what was typed is tidied (trimmed; rich text tidied only at its edges, so its first
7
- * line keeps its indent), an unchanged value closes as no save, each type brings its own phone
8
- * keyboard, and the keys mean the same everywhere: Escape throws the edit away, Enter closes a line
9
- * (a paragraph takes it as a newline and closes on ⌘ or Ctrl Enter), Tab and Shift-Tab close with
10
- * their reason, and leaving the box closes it unless the host says otherwise.
4
+ * THE TEXT EDITOR — one editor for every text-like value: text, a link, an email, a phone, a domain,
5
+ * long text and rich text (VK-218). It draws the app's `TextBody` (required) and keeps what every
6
+ * surface used to write for itself and got different: the draft, its tidy at the close (trimmed;
7
+ * rich text tidied only at its edges, so its first line keeps its indent), an unchanged value
8
+ * closing as no save, and the keys: Escape throws the edit away, Enter closes a line (a paragraph
9
+ * takes it as a newline and closes on ⌘ or Ctrl Enter), Tab and Shift-Tab close with their reason,
10
+ * and leaving the body closes it unless the host says otherwise.
11
11
  *
12
- * Its host (a grid cell, a field row, a card) owns where it opens, the session, and the write: a
13
- * host in a popover or a sheet passes `closeOnBlur={false}`, because there leaving the box to tap
14
- * ✕ or ✓ is not a close. A line draws through the app's `Input`; a paragraph is the package's own
15
- * textarea.
12
+ * A text shown only to be read (`readOnly`) has no body form: it keeps the editor's own textarea,
13
+ * selectable, every close a noop.
14
+ *
15
+ * Its host (a grid cell, a field row) owns where it opens, the session, and the write: a host in a
16
+ * popover or a sheet passes `closeOnBlur={false}`, because there leaving the box to tap ✕ or ✓ is
17
+ * not a close.
16
18
  */
17
19
  export type TextEditorType = "text" | "url" | "domain" | "email" | "phone" | "rich_text";
18
- /** The native input type per text type: the phone keyboard it brings. */
19
- export declare const TEXT_INPUT_TYPE: Readonly<Record<TextEditorType, "text" | "url" | "email" | "tel">>;
20
20
  export type TextEditorHandle = {
21
21
  resolveClose: (reason: CloseReason) => CloseResolution<string>;
22
22
  };
23
- export type TextEditorProps = {
23
+ export type TextEditorHostProps = {
24
24
  type: TextEditorType;
25
25
  /** The stored value ("" when unset): what the dirty check compares against. */
26
26
  initial: string;
27
27
  /** Type-to-replace: the draft opens on this instead, the caret after it. */
28
28
  seed?: string;
29
- /** A paragraph: a textarea, Enter a newline, ⌘ or Ctrl Enter closes with "enter". Default: rich text is one, the rest a line. */
29
+ /** A paragraph: Enter a newline, ⌘ or Ctrl Enter closes with "enter". Default: rich text is one, the rest a line. */
30
30
  multiline?: boolean;
31
- /** A line shown whole: a textarea that wraps and grows like a paragraph, but Enter closes and a
32
- * newline is a space. For a host that opens a cut-off line to be read in full. Default false. */
33
- wraps?: boolean;
34
- /** Shown, selectable, never written: every close resolves `noop`. */
31
+ /** Shown, selectable, never written: the editor's own textarea, every close resolves `noop`. */
35
32
  readOnly?: boolean;
36
33
  /** Whether leaving the box closes with "blur". Default true; a host inside a popover or a sheet passes false. */
37
34
  closeOnBlur?: boolean;
38
35
  label?: string;
39
- /** Handed to the app's `Input`; a line only. Default "bare". */
40
- chrome?: "bare" | "field";
41
- /** A paragraph: the rows it opens at (default 1). It grows with its text to `maxLines` (default 12),
36
+ /** Read-only: the rows the textarea opens at (default 1). It grows with its text to `maxLines` (default 12),
42
37
  * then scrolls; `maxLines` no greater than `rows` keeps it at `rows`. */
43
38
  rows?: number;
44
39
  maxLines?: number;
40
+ /** Read-only: the textarea's own class and style. */
45
41
  className?: string;
46
42
  style?: CSSProperties;
47
- /** Set on the box, over `{ "data-slot": "vk-text-editor" }`, for the host's own selectors. */
43
+ /** Read-only: set on the textarea, over `{ "data-slot": "vk-text-editor" }`, for the host's own selectors. */
48
44
  boxData?: Readonly<Record<`data-${string}`, string>>;
49
- /** The host's reading of a value: its reason, or null. Handed to a `TextBody`; unused by the editor's own box.
50
- * Default: every value reads. */
45
+ /** The host's reading of a value: its reason, or null. Handed to the `TextBody`. Default: every value reads. */
51
46
  check?: (value: string) => string | null;
52
47
  /** The record's country, where a phone typed without its code is read: handed to a `TextBody` for a phone, and
53
48
  * read by its close. */
@@ -56,6 +51,8 @@ export type TextEditorProps = {
56
51
  escapeKeeps?: boolean;
57
52
  /** Where a `TextBody` stands: `phone` in a sheet. Default `computer`. */
58
53
  form?: "computer" | "phone";
54
+ /** Where a `TextBody` stands on a computer: `cell`, a grid cell; `row`, a field row, in its flow. Default `cell`. */
55
+ place?: "cell" | "row";
59
56
  onRequestClose: (reason: CloseReason) => void;
60
57
  };
61
- export declare const TextEditor: import("react").ForwardRefExoticComponent<TextEditorProps & import("react").RefAttributes<TextEditorHandle>>;
58
+ export declare const TextEditorHost: import("react").ForwardRefExoticComponent<TextEditorHostProps & import("react").RefAttributes<TextEditorHandle>>;
@@ -6,49 +6,24 @@ import { ELEMENT_RESET } from "../internal/reset.js";
6
6
  import { useViews } from "../provider/context.js";
7
7
  import { BodyFrame } from "./BodyFrame.js";
8
8
  import { useBodyStep } from "./body-step.js";
9
- import { resolveTextBody, textChange, tidyText } from "./text-body.js";
10
- export const TEXT_INPUT_TYPE = {
11
- text: "text",
12
- url: "url",
13
- domain: "url",
14
- email: "email",
15
- phone: "tel",
16
- rich_text: "text",
17
- };
9
+ import { resolveTextBody, textChange } from "./text-body.js";
18
10
  const EVERY_VALUE_READS = () => null;
19
- export const TextEditor = forwardRef(function TextEditor({ type, initial, seed, multiline = type === "rich_text", wraps = false, readOnly = false, closeOnBlur = true, label, chrome = "bare", rows = 1, maxLines = 12, className, style, boxData, check, region, escapeKeeps = false, form = "computer", onRequestClose, }, ref) {
20
- const { Input, TextBody: AppBody } = useViews().components;
21
- const TextBody = readOnly ? undefined : AppBody;
11
+ export const TextEditorHost = forwardRef(function TextEditorHost({ type, initial, seed, multiline = type === "rich_text", readOnly = false, closeOnBlur = true, label, rows = 1, maxLines = 12, className, style, boxData, check, region, escapeKeeps = false, form = "computer", place = "cell", onRequestClose, }, ref) {
12
+ const { TextBody } = useViews().components;
22
13
  const onStepChange = useBodyStep();
23
14
  const draftRef = useRef(seed ?? initial);
24
15
  const [draft, setDraft] = useState(seed ?? initial);
25
- const boxRef = useRef(null);
26
- const area = multiline || wraps;
27
- const grows = area && maxLines > rows;
28
- const tidy = (text) => tidyText(type, wraps && !multiline, text);
29
- const resolveClose = (reason) => {
30
- if (readOnly)
31
- return { kind: "noop" };
32
- if (reason === "escape")
33
- return { kind: "cancel" };
34
- const next = tidy(boxRef.current?.value ?? seed ?? initial);
35
- return next === tidy(initial) ? { kind: "noop" } : { kind: "commit", payload: next };
36
- };
16
+ const grows = maxLines > rows;
37
17
  useImperativeHandle(ref, () => ({
38
- resolveClose: TextBody
39
- ? (reason) => resolveTextBody(reason, draftRef.current, initial, { type, paragraph: multiline, region })
40
- : resolveClose,
18
+ resolveClose: readOnly
19
+ ? () => ({ kind: "noop" })
20
+ : (reason) => resolveTextBody(reason, draftRef.current, initial, { type, paragraph: multiline, region }),
41
21
  }));
42
22
  const attach = useCallback((el) => {
43
- boxRef.current = el;
44
23
  if (!el)
45
24
  return;
46
25
  el.focus({ preventScroll: true });
47
- try {
48
- el.setSelectionRange(el.value.length, el.value.length);
49
- }
50
- catch {
51
- }
26
+ el.setSelectionRange(el.value.length, el.value.length);
52
27
  if (grows)
53
28
  grow(el, maxLines);
54
29
  }, [grows, maxLines]);
@@ -69,7 +44,7 @@ export const TextEditor = forwardRef(function TextEditor({ type, initial, seed,
69
44
  onRequestClose(event.shiftKey ? "shift-tab" : "tab");
70
45
  }
71
46
  };
72
- if (TextBody) {
47
+ if (!readOnly) {
73
48
  const drawn = draft;
74
49
  return (_jsx(BodyFrame, { slot: "vk-text-body", innerEscape: escapeKeeps, closeOnModEnter: true, closeOnBlur: closeOnBlur, inPlace: closeOnBlur, onRequestClose: onRequestClose, children: _jsx(TextBody, { label: label ?? "", kind: type, paragraph: multiline, value: draft, onValueChange: (next) => {
75
50
  const text = textChange(drawn, next);
@@ -77,21 +52,9 @@ export const TextEditor = forwardRef(function TextEditor({ type, initial, seed,
77
52
  return;
78
53
  draftRef.current = text;
79
54
  setDraft(text);
80
- }, onDone: () => onRequestClose("enter"), check: check ?? EVERY_VALUE_READS, ...(type === "phone" && region ? { region } : {}), typed: seed, autoFocus: true, form: form, ...(onStepChange && { onStepChange }) }) }));
55
+ }, onDone: () => onRequestClose("enter"), check: check ?? EVERY_VALUE_READS, ...(type === "phone" && region ? { region } : {}), typed: seed, autoFocus: true, form: form, place: place, ...(onStepChange && { onStepChange }) }) }));
81
56
  }
82
- const shared = {
83
- "data-slot": "vk-text-editor",
84
- ...boxData,
85
- "aria-label": label,
86
- defaultValue: seed ?? initial,
87
- readOnly,
88
- onKeyDown,
89
- onBlur: closeOnBlur ? () => onRequestClose("blur") : undefined,
90
- onClick: (event) => event.stopPropagation(),
91
- className,
92
- style,
93
- };
94
- return area ? (_jsx("textarea", { ...shared, className: cx(ELEMENT_RESET, className), ref: attach, rows: rows, onInput: grows ? (event) => grow(event.currentTarget, maxLines) : undefined })) : (_jsx(Input, { ...shared, ref: attach, type: TEXT_INPUT_TYPE[type], chrome: chrome }));
57
+ return (_jsx("textarea", { "data-slot": "vk-text-editor", ...boxData, "aria-label": label, defaultValue: seed ?? initial, readOnly: true, onKeyDown: onKeyDown, onBlur: closeOnBlur ? () => onRequestClose("blur") : undefined, onClick: (event) => event.stopPropagation(), className: cx(ELEMENT_RESET, className), style: style, ref: attach, rows: rows }));
95
58
  });
96
59
  function grow(el, maxLines) {
97
60
  el.style.height = "auto";