@viewkitjs/views 0.3.0 → 0.5.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 (288) hide show
  1. package/CHANGELOG.md +641 -0
  2. package/README.md +3 -3
  3. package/dist/atoms/CommandMenu.d.ts +1 -1
  4. package/dist/atoms/CommandMenu.js +7 -3
  5. package/dist/atoms/DrillRows.d.ts +3 -0
  6. package/dist/atoms/DrillRows.js +25 -0
  7. package/dist/atoms/PanelRows.d.ts +5 -0
  8. package/dist/atoms/PanelRows.js +40 -0
  9. package/dist/atoms/PanelSearch.d.ts +2 -0
  10. package/dist/atoms/PanelSearch.js +21 -0
  11. package/dist/atoms/RelationRoles.d.ts +2 -0
  12. package/dist/atoms/RelationRoles.js +6 -0
  13. package/dist/atoms/Row.js +2 -1
  14. package/dist/atoms/RowMenu.js +2 -1
  15. package/dist/atoms/SelectionSheet.d.ts +3 -0
  16. package/dist/atoms/SelectionSheet.js +30 -0
  17. package/dist/atoms/StatusMarker.js +3 -1
  18. package/dist/atoms/Tag.js +2 -1
  19. package/dist/atoms/defaults.js +14 -0
  20. package/dist/atoms/types.d.ts +146 -8
  21. package/dist/cells/cell-values.js +4 -2
  22. package/dist/cells/relation-wrap.js +3 -1
  23. package/dist/contract.d.ts +212 -17
  24. package/dist/contract.js +208 -6
  25. package/dist/display/boolean.js +3 -1
  26. package/dist/display/date.d.ts +1 -1
  27. package/dist/display/date.js +4 -2
  28. package/dist/display/format.js +20 -4
  29. package/dist/display/link.js +4 -3
  30. package/dist/display/multi-value.js +2 -1
  31. package/dist/display/percent.js +2 -1
  32. package/dist/display/phone.js +2 -1
  33. package/dist/display/range.js +3 -13
  34. package/dist/display/relation.js +23 -8
  35. package/dist/display/rich-text.js +2 -1
  36. package/dist/editors/ChipsEditor.d.ts +5 -1
  37. package/dist/editors/ChipsEditor.js +15 -2
  38. package/dist/editors/DateEditor.d.ts +2 -0
  39. package/dist/editors/DateEditor.js +76 -10
  40. package/dist/editors/EditorPanel.d.ts +14 -4
  41. package/dist/editors/EditorPanel.js +21 -4
  42. package/dist/editors/LocationEditor.js +35 -3
  43. package/dist/editors/NumberEditor.js +3 -2
  44. package/dist/editors/RangeEditor.d.ts +8 -0
  45. package/dist/editors/RangeEditor.js +3 -2
  46. package/dist/editors/RelationEditor.d.ts +2 -0
  47. package/dist/editors/RelationEditor.js +16 -2
  48. package/dist/editors/RelationSetEditor.d.ts +4 -2
  49. package/dist/editors/RelationSetEditor.js +36 -2
  50. package/dist/editors/SelectEditor.d.ts +5 -2
  51. package/dist/editors/SelectEditor.js +31 -4
  52. package/dist/editors/TextEditor.js +3 -1
  53. package/dist/editors/ValueListEditor.d.ts +3 -0
  54. package/dist/editors/ValueListEditor.js +10 -4
  55. package/dist/editors/edit-session.d.ts +14 -2
  56. package/dist/editors/edit-session.js +13 -5
  57. package/dist/editors/escape-rule.d.ts +12 -0
  58. package/dist/editors/escape-rule.js +8 -0
  59. package/dist/editors/open-value.js +2 -1
  60. package/dist/editors/picker-slot.d.ts +25 -0
  61. package/dist/editors/picker-slot.js +37 -0
  62. package/dist/editors/relation-picker.d.ts +44 -0
  63. package/dist/editors/relation-picker.js +49 -0
  64. package/dist/editors/relation-source.d.ts +1 -0
  65. package/dist/editors/relation-source.js +7 -1
  66. package/dist/field-row/FieldNoteLine.js +2 -1
  67. package/dist/field-row/FieldRow.js +41 -6
  68. package/dist/field-row/FieldRowLane.js +3 -1
  69. package/dist/field-row/editors/RowChipsEditor.js +1 -1
  70. package/dist/field-row/editors/RowDateEditor.js +1 -1
  71. package/dist/field-row/editors/RowEditor.js +2 -1
  72. package/dist/field-row/editors/RowRangeEditor.js +2 -1
  73. package/dist/field-row/editors/RowRelationEditor.js +2 -2
  74. package/dist/field-row/editors/RowSelectEditor.d.ts +1 -1
  75. package/dist/field-row/editors/RowSelectEditor.js +2 -2
  76. package/dist/field-row/editors/RowValueListEditor.js +1 -1
  77. package/dist/field-row/editors/host.d.ts +3 -0
  78. package/dist/field-row/editors/row-session.js +4 -1
  79. package/dist/fields/menus.d.ts +2 -0
  80. package/dist/fields/range-unit.d.ts +7 -0
  81. package/dist/fields/range-unit.js +13 -0
  82. package/dist/figures.d.ts +5 -48
  83. package/dist/figures.js +1 -63
  84. package/dist/grid/chrome/GridAddColumn.d.ts +8 -0
  85. package/dist/grid/chrome/GridAddColumn.js +66 -9
  86. package/dist/grid/chrome/GridAggregateMenu.d.ts +5 -2
  87. package/dist/grid/chrome/GridAggregateMenu.js +33 -4
  88. package/dist/grid/chrome/GridCellEditors.d.ts +9 -2
  89. package/dist/grid/chrome/GridCellEditors.js +24 -5
  90. package/dist/grid/chrome/GridCellOutline.d.ts +3 -2
  91. package/dist/grid/chrome/GridCellOutline.js +11 -1
  92. package/dist/grid/chrome/GridChipsEditor.js +1 -1
  93. package/dist/grid/chrome/GridColumnColorSection.d.ts +2 -0
  94. package/dist/grid/chrome/GridColumnColorSection.js +2 -2
  95. package/dist/grid/chrome/GridColumnDateSection.d.ts +4 -0
  96. package/dist/grid/chrome/GridColumnDateSection.js +2 -2
  97. package/dist/grid/chrome/GridColumnDurationSection.d.ts +4 -0
  98. package/dist/grid/chrome/GridColumnDurationSection.js +2 -2
  99. package/dist/grid/chrome/GridColumnMenu.d.ts +10 -6
  100. package/dist/grid/chrome/GridColumnMenu.js +62 -24
  101. package/dist/grid/chrome/GridColumnNumberSection.d.ts +4 -0
  102. package/dist/grid/chrome/GridColumnNumberSection.js +2 -2
  103. package/dist/grid/chrome/GridColumnPercentSection.d.ts +1 -0
  104. package/dist/grid/chrome/GridColumnPercentSection.js +1 -1
  105. package/dist/grid/chrome/GridColumnSortSection.d.ts +3 -3
  106. package/dist/grid/chrome/GridDateEditor.js +1 -1
  107. package/dist/grid/chrome/GridFooter.js +7 -48
  108. package/dist/grid/chrome/GridGroupMenu.d.ts +11 -5
  109. package/dist/grid/chrome/GridGroupMenu.js +28 -13
  110. package/dist/grid/chrome/GridHeader.d.ts +3 -1
  111. package/dist/grid/chrome/GridHeader.js +8 -8
  112. package/dist/grid/chrome/GridNumberEditor.js +3 -24
  113. package/dist/grid/chrome/GridRangeEditor.js +3 -2
  114. package/dist/grid/chrome/GridRelationEditor.js +2 -2
  115. package/dist/grid/chrome/GridRow.d.ts +2 -1
  116. package/dist/grid/chrome/GridRow.js +13 -37
  117. package/dist/grid/chrome/GridRowActions.js +2 -1
  118. package/dist/grid/chrome/GridRowCells.js +9 -4
  119. package/dist/grid/chrome/GridSelectEditor.js +30 -20
  120. package/dist/grid/chrome/GridStructure.d.ts +11 -4
  121. package/dist/grid/chrome/GridStructure.js +19 -7
  122. package/dist/grid/chrome/GridTable.js +138 -16
  123. package/dist/grid/chrome/GridTableSurface.d.ts +25 -12
  124. package/dist/grid/chrome/GridTableSurface.js +13 -6
  125. package/dist/grid/chrome/GridTextEditor.js +3 -1
  126. package/dist/grid/chrome/GridValueListEditor.js +1 -1
  127. package/dist/grid/chrome/cell-clipboard.d.ts +1 -1
  128. package/dist/grid/chrome/cell-clipboard.js +1 -1
  129. package/dist/grid/chrome/checks.d.ts +10 -2
  130. package/dist/grid/chrome/checks.js +17 -11
  131. package/dist/grid/chrome/column-glyph.d.ts +2 -2
  132. package/dist/grid/chrome/column-glyph.js +4 -0
  133. package/dist/grid/chrome/grid-add-column-items.d.ts +13 -0
  134. package/dist/grid/chrome/grid-add-column-items.js +40 -0
  135. package/dist/grid/chrome/grid-cell-classes.d.ts +2 -0
  136. package/dist/grid/chrome/grid-cell-classes.js +10 -4
  137. package/dist/grid/chrome/grid-column-menu-items.d.ts +75 -0
  138. package/dist/grid/chrome/grid-column-menu-items.js +263 -0
  139. package/dist/grid/chrome/grid-edit-escape.d.ts +4 -0
  140. package/dist/grid/chrome/grid-edit-escape.js +12 -0
  141. package/dist/grid/chrome/grid-edit-session.d.ts +2 -1
  142. package/dist/grid/chrome/grid-edit-session.js +14 -1
  143. package/dist/grid/chrome/grid-figure-value.d.ts +25 -0
  144. package/dist/grid/chrome/grid-figure-value.js +40 -0
  145. package/dist/grid/chrome/grid-fitted-box.d.ts +15 -0
  146. package/dist/grid/chrome/grid-fitted-box.js +26 -0
  147. package/dist/grid/chrome/grid-group-menu-items.d.ts +31 -0
  148. package/dist/grid/chrome/grid-group-menu-items.js +75 -0
  149. package/dist/grid/chrome/grid-group-menu-parts.d.ts +27 -0
  150. package/dist/grid/chrome/grid-group-menu-parts.js +19 -0
  151. package/dist/grid/chrome/grid-hover.d.ts +1 -0
  152. package/dist/grid/chrome/grid-hover.js +13 -1
  153. package/dist/grid/chrome/grid-lab.d.ts +7 -0
  154. package/dist/grid/chrome/grid-lab.js +7 -0
  155. package/dist/grid/chrome/grid-menu-focus.d.ts +12 -0
  156. package/dist/grid/chrome/grid-menu-focus.js +13 -0
  157. package/dist/grid/chrome/{useGridRowContextMenu.d.ts → grid-row-menu-items.d.ts} +15 -4
  158. package/dist/grid/chrome/{useGridRowContextMenu.js → grid-row-menu-items.js} +15 -18
  159. package/dist/grid/chrome/grid-row-props.d.ts +3 -1
  160. package/dist/grid/chrome/grid-row-window.d.ts +15 -5
  161. package/dist/grid/chrome/grid-row-window.js +44 -10
  162. package/dist/grid/chrome/grid-rows-menu.d.ts +38 -0
  163. package/dist/grid/chrome/grid-rows-menu.js +83 -0
  164. package/dist/grid/chrome/grid-table-props.d.ts +53 -8
  165. package/dist/grid/chrome/useGridBandFigures.d.ts +26 -0
  166. package/dist/grid/chrome/useGridBandFigures.js +50 -0
  167. package/dist/grid/chrome/useGridBoxes.d.ts +22 -0
  168. package/dist/grid/chrome/useGridBoxes.js +22 -0
  169. package/dist/grid/chrome/useGridColumnLayout.js +29 -4
  170. package/dist/grid/chrome/useGridKeyboard.js +7 -2
  171. package/dist/grid/chrome/useGridPartColumns.d.ts +5 -0
  172. package/dist/grid/chrome/useGridPartColumns.js +9 -0
  173. package/dist/grid/chrome/useGridRangeGestures.js +2 -1
  174. package/dist/grid/chrome/useGridRecorder.d.ts +16 -0
  175. package/dist/grid/chrome/useGridRecorder.js +144 -0
  176. package/dist/grid/chrome/useGridRowOpener.d.ts +41 -0
  177. package/dist/grid/chrome/useGridRowOpener.js +83 -0
  178. package/dist/grid/chrome/useGridScrollArea.d.ts +38 -12
  179. package/dist/grid/chrome/useGridScrollArea.js +70 -17
  180. package/dist/grid/chrome/useGridTableInteractionModel.d.ts +1 -0
  181. package/dist/grid/chrome/useGridTableInteractionModel.js +67 -9
  182. package/dist/grid/core/clipboard-model.d.ts +11 -3
  183. package/dist/grid/core/clipboard-model.js +9 -4
  184. package/dist/grid/core/commit-model.d.ts +7 -0
  185. package/dist/grid/core/editing-controller.d.ts +31 -1
  186. package/dist/grid/core/editing-controller.js +65 -0
  187. package/dist/grid/core/grid-recorder.d.ts +111 -0
  188. package/dist/grid/core/grid-recorder.js +223 -0
  189. package/dist/grid/core/part-edits.d.ts +18 -0
  190. package/dist/grid/core/part-edits.js +48 -0
  191. package/dist/grid/core/pending-reconciliation.js +12 -3
  192. package/dist/grid/core/refusal-sentence.d.ts +3 -0
  193. package/dist/grid/core/refusal-sentence.js +15 -0
  194. package/dist/grid/core/row-opened-from.d.ts +21 -0
  195. package/dist/grid/core/row-opened-from.js +11 -0
  196. package/dist/grid/core/useGridEditing.d.ts +16 -2
  197. package/dist/grid/core/useGridEditing.js +10 -4
  198. package/dist/grid/core/value-equality.d.ts +19 -1
  199. package/dist/grid/core/value-equality.js +24 -0
  200. package/dist/grid/index.d.ts +4 -1
  201. package/dist/grid/index.js +1 -0
  202. package/dist/grid/useGridTablePrefs.d.ts +1 -1
  203. package/dist/grid-lab.d.ts +18 -0
  204. package/dist/grid-lab.js +16 -0
  205. package/dist/grouping/sort-groups.d.ts +6 -7
  206. package/dist/index.d.ts +1 -0
  207. package/dist/index.js +1 -0
  208. package/dist/internal/reset.d.ts +9 -0
  209. package/dist/internal/reset.js +1 -0
  210. package/dist/model/aggregates.d.ts +3 -3
  211. package/dist/model/aggregates.js +17 -71
  212. package/dist/model/column-capabilities.d.ts +29 -2
  213. package/dist/model/column-capabilities.js +27 -3
  214. package/dist/model/column-filters.js +24 -4
  215. package/dist/model/column-inspect.d.ts +2 -1
  216. package/dist/model/column-order.d.ts +2 -2
  217. package/dist/model/column-schema.d.ts +18 -7
  218. package/dist/model/column-state.d.ts +9 -20
  219. package/dist/model/column-state.js +1 -4
  220. package/dist/model/column-types.d.ts +1 -15
  221. package/dist/model/column-types.js +1 -1
  222. package/dist/model/part-columns.d.ts +17 -0
  223. package/dist/model/part-columns.js +67 -0
  224. package/dist/model/part-rows.d.ts +3 -10
  225. package/dist/model/part-rows.js +6 -11
  226. package/dist/model/part-write.d.ts +11 -0
  227. package/dist/model/part-write.js +52 -0
  228. package/dist/model/preferences.d.ts +3 -23
  229. package/dist/model/preferences.js +1 -17
  230. package/dist/model/prefs-buckets.d.ts +0 -27
  231. package/dist/model/prefs-buckets.js +1 -1
  232. package/dist/model/relation-filters.d.ts +0 -1
  233. package/dist/model/relation-filters.js +1 -1
  234. package/dist/model/row-icon.d.ts +5 -9
  235. package/dist/model/view-rules.d.ts +32 -6
  236. package/dist/model/view-rules.js +101 -21
  237. package/dist/provider/ViewsProvider.d.ts +22 -2
  238. package/dist/provider/ViewsProvider.js +21 -2
  239. package/dist/provider/components.d.ts +197 -9
  240. package/dist/provider/context.d.ts +12 -1
  241. package/dist/provider/desktop.d.ts +3 -0
  242. package/dist/provider/desktop.js +7 -4
  243. package/dist/provider/menu-groups.d.ts +3 -2
  244. package/dist/provider/menu-groups.js +13 -7
  245. package/dist/provider/missing-slot.d.ts +10 -0
  246. package/dist/provider/missing-slot.js +15 -0
  247. package/dist/provider/plain-input.d.ts +3 -2
  248. package/dist/provider/plain-input.js +3 -1
  249. package/dist/react.d.ts +3 -2
  250. package/dist/selection/SelectionBar.d.ts +18 -0
  251. package/dist/selection/SelectionBar.js +92 -0
  252. package/dist/selection/SelectionBarPhone.d.ts +3 -0
  253. package/dist/selection/SelectionBarPhone.js +14 -0
  254. package/dist/selection/bar-overflow.d.ts +12 -0
  255. package/dist/selection/bar-overflow.js +42 -0
  256. package/dist/selection/bar-parts.d.ts +15 -0
  257. package/dist/selection/bar-parts.js +17 -0
  258. package/dist/selection/index.d.ts +2 -0
  259. package/dist/selection/index.js +1 -0
  260. package/dist/selection/types.d.ts +3 -2
  261. package/dist/selection/verbs.d.ts +34 -0
  262. package/dist/selection/verbs.js +1 -0
  263. package/docs/contract.md +142 -39
  264. package/docs/getting-started.md +1 -1
  265. package/docs/guides/atoms.md +32 -4
  266. package/docs/guides/columns.md +1 -1
  267. package/docs/guides/display.md +1 -1
  268. package/docs/guides/editors.md +3 -3
  269. package/docs/guides/ports.md +1 -1
  270. package/docs/guides/selection.md +32 -20
  271. package/docs/guides/the-grid.md +43 -21
  272. package/docs/guides/the-provider.md +14 -4
  273. package/docs/index.md +2 -0
  274. package/docs/install.md +8 -1
  275. package/docs/reference/editors-date.md +2 -0
  276. package/docs/reference/editors-panel.md +4 -4
  277. package/docs/reference/editors-range.md +1 -1
  278. package/docs/reference/editors-relation.md +3 -3
  279. package/docs/reference/editors-select.md +1 -1
  280. package/docs/reference/editors-session.md +3 -2
  281. package/docs/reference/editors-value-list.md +1 -1
  282. package/docs/reference/field-row.md +2 -2
  283. package/docs/reference/grid.md +25 -6
  284. package/docs/reference/react.md +30 -8
  285. package/docs/reference/selection.md +10 -2
  286. package/docs/reference/views.md +42 -36
  287. package/package.json +22 -3
  288. package/skills/views/SKILL.md +3 -3
@@ -4,8 +4,10 @@ import { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRe
4
4
  import { COUNTRY_CODES, countryName, LOCATION_PARTS, placeFormat, sameStoredValue, } from "@viewkitjs/fields";
5
5
  import { loadRegions, regionLabel } from "@viewkitjs/fields/places";
6
6
  import { placeWordKey } from "../contract.js";
7
+ import { ELEMENT_RESET } from "../internal/reset.js";
7
8
  import { useViews } from "../provider/context.js";
8
9
  import { EDITOR_INNER_ESCAPE } from "./EditorPanel.js";
10
+ import { PickerFrame, usePickerForm } from "./picker-slot.js";
9
11
  const GENERIC = ["line1", "line2", "postalCode", "city", "region"];
10
12
  function folded(text) {
11
13
  return text.normalize("NFD").replace(/\p{M}/gu, "").toLowerCase();
@@ -28,7 +30,8 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
28
30
  const locale = (conventions ?? views.conventions).locale;
29
31
  const say = (message) => views.messages(message);
30
32
  const { List, RowContent } = views.atoms;
31
- const { Command, Input } = views.components;
33
+ const { Command, Input, Picker } = views.components;
34
+ const form = usePickerForm();
32
35
  const boxRef = useRef(null);
33
36
  const parts = field.parts ?? LOCATION_PARTS;
34
37
  const takesCountry = parts.includes("countryCode");
@@ -208,8 +211,37 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
208
211
  }
209
212
  } }));
210
213
  const list = (children) => (_jsxs(Command.List, { className: "max-h-64 overscroll-contain scrollbar-overlay", children: [children.length === 0 && (_jsx(Command.Empty, { className: "py-4 text-center text-xs text-(color:--vk-fg-subtle)", children: (conventions ?? views.conventions).messages({ key: "editor.nothing-matches" }) })), _jsx(Command.Group, { className: "p-0", children: _jsx(List, { children: children }) })] }));
214
+ const listKeys = (e) => {
215
+ if (e.key !== "Escape")
216
+ return;
217
+ e.stopPropagation();
218
+ if (choosingRegion)
219
+ setChoosingRegion(false);
220
+ else if (country)
221
+ setChoosingCountry(false);
222
+ else
223
+ onRequestClose("escape");
224
+ };
211
225
  let body;
212
- if (choosingCountry) {
226
+ if (choosingCountry && Picker) {
227
+ body = (_jsx(PickerFrame, { onTab: (reason) => onRequestClose(reason), onKey: listKeys, children: _jsx(Picker, { label: say({ key: "views.editors.place-country" }), items: countries.map(({ code, name }) => ({ value: code, label: name })), value: country, onValueChange: (code) => {
228
+ if (typeof code === "string")
229
+ pickCountry(code);
230
+ }, onDone: () => { }, search: say({ key: "views.editors.place-country-search" }), autoFocus: true, form: form }) }));
231
+ }
232
+ else if (choosingRegion && regionList && Picker) {
233
+ const keyed = regionList.map((region) => ({
234
+ region,
235
+ key: region.code ?? region.name,
236
+ label: regionLabel(region, country ?? "", locale),
237
+ }));
238
+ body = (_jsx(PickerFrame, { onTab: (reason) => onRequestClose(reason), onKey: listKeys, children: _jsx(Picker, { label: wordOf("region"), items: keyed.map(({ key, label }) => ({ value: key, label })), value: keyed.find(({ label }) => label === draft.region)?.key ?? null, onValueChange: (key) => {
239
+ const found = keyed.find((each) => each.key === key);
240
+ if (found)
241
+ pickRegion(found.region);
242
+ }, onDone: () => { }, search: say({ key: "views.editors.place-region-search" }), autoFocus: true, form: form }) }));
243
+ }
244
+ else if (choosingCountry) {
213
245
  const needle = folded(countryQuery.trim());
214
246
  const shown = countries.filter(({ code, name }) => needle === "" || folded(name).includes(needle) || code.toLowerCase() === needle);
215
247
  body = (_jsxs(Command.Root, { shouldFilter: false, loop: true, label: say({ key: "views.editors.place-country" }), children: [search(countryQuery, setCountryQuery, say({ key: "views.editors.place-country-search" })), list(shown.map(({ code, name }) => (_jsx(Command.Item, { value: code, onSelect: () => pickCountry(code), chosen: code === country, children: _jsx(RowContent, { size: "compact", label: name, chosen: code === country, chosenTint: false }) }, code))))] }));
@@ -226,7 +258,7 @@ export const LocationEditor = forwardRef(function LocationEditor({ field, initia
226
258
  else {
227
259
  const focusPart = rows[0]?.[0];
228
260
  const focus = (part) => (part === focusPart ? { "data-place-focus": "" } : {});
229
- body = (_jsxs(_Fragment, { children: [takesCountry && country && line(_jsx("button", { type: "button", "data-place-control": "", "aria-label": `${say({ key: "views.editors.place-change-country" })}: ${countryName(country, locale)}`, onClick: () => setChoosingCountry(true), onKeyDown: keys, className: `${button} font-medium`, children: countryName(country, locale) })), rows.map((row) => (_jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: row.map((part) => part === "region" && regionList ? (_jsx("button", { type: "button", "data-place-control": "", ...focus(part), ...required(part, "button"), "data-place-part": part, "aria-label": draft.region ? `${labelOf(part)}: ${draft.region}` : labelOf(part), onFocus: () => (lastFocused.current = part), onClick: () => setChoosingRegion(true), onKeyDown: keys, className: `${button} ${draft.region ? "" : "text-(color:--vk-fg-subtle)"}`, children: draft.region || labelOf(part) }, part)) : (_jsx(Input, { "data-place-control": "", ...focus(part), ...required(part, "input"), "data-place-part": part, onFocus: () => (lastFocused.current = part), value: draft[part] ?? "", "aria-label": labelOf(part), placeholder: labelOf(part), onChange: (e) => type(part, e.target.value), onKeyDown: keys, onClick: (e) => e.stopPropagation(), chrome: chrome, className: input }, part))) }, row.join(" "))))] }));
261
+ body = (_jsxs(_Fragment, { children: [takesCountry && country && line(_jsx("button", { type: "button", "data-place-control": "", "aria-label": `${say({ key: "views.editors.place-change-country" })}: ${countryName(country, locale)}`, onClick: () => setChoosingCountry(true), onKeyDown: keys, className: `${ELEMENT_RESET} ${button} font-medium`, children: countryName(country, locale) })), rows.map((row) => (_jsx("span", { className: "flex min-w-0 items-center gap-1.5", children: row.map((part) => part === "region" && regionList ? (_jsx("button", { type: "button", "data-place-control": "", ...focus(part), ...required(part, "button"), "data-place-part": part, "aria-label": draft.region ? `${labelOf(part)}: ${draft.region}` : labelOf(part), onFocus: () => (lastFocused.current = part), onClick: () => setChoosingRegion(true), onKeyDown: keys, className: `${ELEMENT_RESET} ${button} ${draft.region ? "" : "text-(color:--vk-fg-subtle)"}`, children: draft.region || labelOf(part) }, part)) : (_jsx(Input, { "data-place-control": "", ...focus(part), ...required(part, "input"), "data-place-part": part, onFocus: () => (lastFocused.current = part), value: draft[part] ?? "", "aria-label": labelOf(part), placeholder: labelOf(part), onChange: (e) => type(part, e.target.value), onKeyDown: keys, onClick: (e) => e.stopPropagation(), chrome: chrome, className: input }, part))) }, row.join(" "))))] }));
230
262
  }
231
263
  const inner = (choosingRegion && regionList !== null) || (choosingCountry && country !== null);
232
264
  return (_jsx("div", { ref: boxRef, ...(inner ? { [EDITOR_INNER_ESCAPE]: "" } : {}), onBlur: blur, onMouseDown: (e) => {
@@ -4,6 +4,7 @@ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "re
4
4
  import { formatNumberText, parseNumber, roundTo, } from "@viewkitjs/fields";
5
5
  import { durationUnitToMs, formatDurationInput, msToDurationUnit, parseDurationInput, } from "@viewkitjs/fields/query";
6
6
  import { cx } from "../internal/cx.js";
7
+ import { ELEMENT_RESET } from "../internal/reset.js";
7
8
  import { useViews } from "../provider/context.js";
8
9
  export const NumberEditor = forwardRef(function NumberEditor({ initial, seed, unit, unitOptions, code, decimals = 2, durationUnit, allowEmpty = false, unitLeft = false, align = "end", conventions, onRequestClose, }, ref) {
9
10
  const inputRef = useRef(null);
@@ -74,11 +75,11 @@ export const NumberEditor = forwardRef(function NumberEditor({ initial, seed, un
74
75
  }, onBlur: () => {
75
76
  if (!unitOpen)
76
77
  onRequestClose("blur");
77
- }, onClick: (e) => e.stopPropagation(), className: cx("h-full min-w-0 select-text bg-transparent tabular-nums text-(length:--vk-text) text-(color:--vk-fg) outline-hidden", align === "start" ? "w-40 flex-none text-left" : "w-full flex-1 text-right") }), (unit ?? code) &&
78
+ }, onClick: (e) => e.stopPropagation(), className: cx("h-full min-w-0 select-text bg-transparent tabular-nums text-(length:--vk-text) text-(color:--vk-fg) outline-hidden", align === "start" ? "w-40 flex-initial text-left" : "w-full flex-1 text-right") }), (unit ?? code) &&
78
79
  (unit && unitOptions && unitOptions.length > 0 ? (_jsxs(_Fragment, { children: [_jsx("button", { ref: chipRef, type: "button", tabIndex: -1, onMouseDown: (e) => e.preventDefault(), onClick: (e) => {
79
80
  e.stopPropagation();
80
81
  setUnitOpen((o) => !o);
81
- }, className: cx("shrink-0 text-xs font-normal text-(color:--vk-fg-subtle) transition-colors hover:text-(color:--vk-fg)", unitLeft && "order-first"), children: currentUnit }), _jsx(Popover, { open: unitOpen, onOpenChange: (next) => setUnitOpen(next), anchor: chipRef, side: "bottom", align: unitLeft ? "start" : "end", sideOffset: 6, initialFocus: false, onOutsidePress: (event) => (chipRef.current?.contains(event.target) ? false : undefined), onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "w-24", children: _jsx(List, { children: unitOptions.map((u) => (_jsx(Row, { label: u, chosen: u === currentUnit, onMouseDown: (e) => e.preventDefault(), onClick: () => {
82
+ }, className: cx(ELEMENT_RESET, "shrink-0 text-xs font-normal text-(color:--vk-fg-subtle) transition-colors hover:text-(color:--vk-fg)", unitLeft && "order-first"), children: currentUnit }), _jsx(Popover, { open: unitOpen, onOpenChange: (next) => setUnitOpen(next), anchor: chipRef, side: "bottom", align: unitLeft ? "start" : "end", sideOffset: 6, initialFocus: false, onOutsidePress: (event) => (chipRef.current?.contains(event.target) ? false : undefined), onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "w-24", children: _jsx(List, { children: unitOptions.map((u) => (_jsx(Row, { label: u, chosen: u === currentUnit, onMouseDown: (e) => e.preventDefault(), onClick: () => {
82
83
  setCurrentUnit(u);
83
84
  setUnitOpen(false);
84
85
  inputRef.current?.focus();
@@ -11,6 +11,10 @@ import { type CloseReason, type CloseResolution, type FieldConventions, type Ran
11
11
  * band writes its two ends into the boxes and closes as a pick, so the band is
12
12
  * read, compared and judged exactly as typed ends are. The boxes stay, so a value
13
13
  * between bands is still typed.
14
+ *
15
+ * With bands listed, the editor draws its host's refusal itself, between the
16
+ * boxes and the bands (atop the menu, or above the list below), so the bands
17
+ * never cover the reason or push it away from the boxes it is about.
14
18
  */
15
19
  export type RangeEditorHandle = {
16
20
  resolveClose: (reason: CloseReason) => CloseResolution<RangeValue>;
@@ -31,6 +35,10 @@ export declare const RangeEditor: import("react").ForwardRefExoticComponent<{
31
35
  * editor typed where its value stands. `below`: in the editor's own column, for an editor
32
36
  * that already sits in a sheet or a panel. */
33
37
  bandsAt?: "popover" | "below";
38
+ /** The host's reason for refusing the range typed or picked. With bands listed it is drawn here,
39
+ * between the boxes and the bands, and the host draws none of its own; without bands the editor
40
+ * draws nothing, and the host draws it as for any type-in. */
41
+ refusal?: string | null;
34
42
  /** Classes for the box that holds the two inputs: the host's frame, such as a sheet's field. */
35
43
  boxClassName?: string;
36
44
  onRequestClose: (reason: CloseReason) => void;
@@ -4,7 +4,7 @@ import { forwardRef, useEffect, useImperativeHandle, useRef, } from "react";
4
4
  import { formatNumberText, parseNumber, roundTo, } from "@viewkitjs/fields";
5
5
  import { cx } from "../internal/cx.js";
6
6
  import { useViews } from "../provider/context.js";
7
- export const RangeEditor = forwardRef(function RangeEditor({ initial, seed, decimals = 0, allowEmpty = false, suffix, align = "end", conventions, bands, bandsAt = "popover", boxClassName, onRequestClose, }, ref) {
7
+ export const RangeEditor = forwardRef(function RangeEditor({ initial, seed, decimals = 0, allowEmpty = false, suffix, align = "end", conventions, bands, bandsAt = "popover", refusal, boxClassName, onRequestClose, }, ref) {
8
8
  const views = useViews();
9
9
  const { Input, Popover } = views.components;
10
10
  const { List, Row } = views.atoms;
@@ -79,8 +79,9 @@ export const RangeEditor = forwardRef(function RangeEditor({ initial, seed, deci
79
79
  const bandList = bands && bands.length > 0 ? (_jsx(List, { children: bands.map((band) => (_jsx(Row, { label: band.label, chosen: held(band), onMouseDown: (e) => e.preventDefault(), onClick: () => pickBand(band) }, band.key))) })) : null;
80
80
  const input = cx("h-full w-16 min-w-0 shrink select-text bg-transparent tabular-nums text-(length:--vk-text) text-(color:--vk-fg) outline-hidden", align === "end" ? "text-right" : "text-left");
81
81
  const below = bandList !== null && bandsAt === "below";
82
+ const reason = bandList !== null && refusal ? (_jsx("p", { role: "alert", "data-slot": "vk-editor-refusal", className: cx("text-xs text-(color:--vk-danger)", !below && "px-2 pb-1 pt-1.5"), children: refusal })) : null;
82
83
  return (_jsxs("span", { ref: rootRef, onMouseDown: (e) => {
83
84
  if (!(e.target instanceof HTMLInputElement))
84
85
  e.preventDefault();
85
- }, className: below ? "flex w-full min-w-0 flex-col gap-1" : "contents", children: [_jsxs("span", { ref: boxRef, className: cx("flex h-full w-full min-w-0 items-center gap-1.5", align === "end" && "justify-end", boxClassName), children: [_jsx(Input, { ref: lowRef, defaultValue: seed ?? text(initial?.low), inputMode: "decimal", "aria-label": views.messages({ key: "views.editors.range-low" }), placeholder: views.messages({ key: "views.editors.range-low" }), onKeyDown: keys("low"), onBlur: blur, onClick: (e) => e.stopPropagation(), className: input }), _jsx("span", { className: "shrink-0 text-xs text-(color:--vk-fg-subtle)", children: "\u2013" }), _jsx(Input, { ref: highRef, defaultValue: text(initial?.high), inputMode: "decimal", "aria-label": views.messages({ key: "views.editors.range-high" }), placeholder: views.messages({ key: "views.editors.range-high" }), onKeyDown: keys("high"), onBlur: blur, onClick: (e) => e.stopPropagation(), className: input }), suffix && _jsx("span", { className: "shrink-0 text-xs text-(color:--vk-fg-subtlest)", children: suffix })] }), below && bandList, bandList !== null && !below && (_jsx(Popover, { open: true, onOpenChange: () => { }, anchor: boxRef, side: "bottom", align: align === "end" ? "end" : "start", sideOffset: 6, initialFocus: false, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "w-40", children: bandList }))] }));
86
+ }, className: below ? "flex w-full min-w-0 flex-col gap-1" : "contents", children: [_jsxs("span", { ref: boxRef, className: cx("flex h-full w-full min-w-0 items-center gap-1.5", align === "end" && "justify-end", boxClassName), children: [_jsx(Input, { ref: lowRef, defaultValue: seed ?? text(initial?.low), inputMode: "decimal", "aria-label": views.messages({ key: "views.editors.range-low" }), placeholder: views.messages({ key: "views.editors.range-low" }), onKeyDown: keys("low"), onBlur: blur, onClick: (e) => e.stopPropagation(), className: input }), _jsx("span", { className: "shrink-0 text-xs text-(color:--vk-fg-subtle)", children: "\u2013" }), _jsx(Input, { ref: highRef, defaultValue: text(initial?.high), inputMode: "decimal", "aria-label": views.messages({ key: "views.editors.range-high" }), placeholder: views.messages({ key: "views.editors.range-high" }), onKeyDown: keys("high"), onBlur: blur, onClick: (e) => e.stopPropagation(), className: input }), suffix && _jsx("span", { className: "shrink-0 text-xs text-(color:--vk-fg-subtlest)", children: suffix })] }), below && reason, below && bandList, bandList !== null && !below && (_jsxs(Popover, { open: true, onOpenChange: () => { }, anchor: boxRef, side: "bottom", align: align === "end" ? "end" : "start", sideOffset: 6, initialFocus: false, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "w-40", children: [reason, bandList] }))] }));
86
87
  });
@@ -47,4 +47,6 @@ export declare const RelationEditor: import("react").ForwardRefExoticComponent<{
47
47
  /** Put the caret in the search as the panel opens, without scrolling. Default false: a host whose surface puts
48
48
  * focus there itself, or never should (a phone's sheet opens with the keyboard down), leaves it off. */
49
49
  focusSearch?: boolean;
50
+ /** The field's name, for an app's own `Picker` (its list's accessible name). Default: the search's words. */
51
+ label?: string;
50
52
  } & import("react").RefAttributes<RelationEditorHandle>>;
@@ -3,16 +3,17 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react";
4
4
  import { useViews } from "../provider/context.js";
5
5
  import { RelationPanel } from "./relation-panel.js";
6
+ import { RelationPickerBody } from "./relation-picker.js";
6
7
  export { RELATION_PAGE_SIZE, RELATION_SEARCH_DEBOUNCE_MS } from "./relation-source.js";
7
8
  export { RelationSetEditor, } from "./RelationSetEditor.js";
8
- export const RelationEditor = forwardRef(function RelationEditor({ candidates, initial, clearable, onRequestClose, kindGlyph, noneLabel, message, creates, seed, focusSearch = false, }, ref) {
9
+ export const RelationEditor = forwardRef(function RelationEditor({ candidates, initial, clearable, onRequestClose, kindGlyph, noneLabel, message, creates, seed, focusSearch = false, label, }, ref) {
9
10
  const [picked, setPicked] = useState(undefined);
10
11
  const pickedRef = useRef(undefined);
11
12
  const [query, setQuery] = useState(seed ?? "");
12
13
  const searchRef = useRef(null);
13
14
  const views = useViews();
14
15
  const words = message ?? views.conventions.messages;
15
- const { Command } = views.components;
16
+ const { Command, Picker } = views.components;
16
17
  const { RowContent } = views.atoms;
17
18
  useEffect(() => {
18
19
  if (focusSearch)
@@ -34,6 +35,19 @@ export const RelationEditor = forwardRef(function RelationEditor({ candidates, i
34
35
  };
35
36
  const current = picked === undefined ? initial : picked;
36
37
  const none = clearable && (candidates.kind !== "remote" || query === "");
38
+ if (Picker) {
39
+ return (_jsx(RelationPickerBody, { Picker: Picker, label: label ?? words({ key: "editor.search" }), candidates: candidates, query: query, onQueryChange: setQuery, held: [], multiple: false, value: current ?? null, onValueChange: (id) => {
40
+ if (typeof id === "string" || id === null) {
41
+ pickedRef.current = id;
42
+ setPicked(id);
43
+ }
44
+ }, onDone: () => onRequestClose("pick"), empty: clearable ? (noneLabel ?? words({ key: "relation.none" })) : undefined, creates: creates, onCreate: (create, typed) => {
45
+ pickedRef.current = undefined;
46
+ setPicked(undefined);
47
+ onRequestClose("pick");
48
+ create.onCreate(typed);
49
+ }, kindGlyph: kindGlyph, search: words({ key: "editor.search" }), onTab: (reason) => onRequestClose(reason), typed: seed, autoFocus: focusSearch }));
50
+ }
37
51
  return (_jsx(RelationPanel, { candidates: candidates, query: query, onQueryChange: setQuery, searchRef: searchRef, kindGlyph: kindGlyph, message: message, creates: creates, onCreate: (create, typed) => {
38
52
  onRequestClose("pick");
39
53
  create.onCreate(typed);
@@ -25,8 +25,8 @@ export type RelationSetEditorHandle = {
25
25
  * a way to become it; a record added joins at the end, so the lead stays until
26
26
  * another is marked, and removing the lead passes it to the next; Space on a
27
27
  * highlighted linked record, with the search empty, makes it the lead, as its
28
- * Make lead button does. A link keeps the role it was stored with; a new one
29
- * has none.
28
+ * Make lead button does. A link keeps the role and roles it was stored with; a
29
+ * new one has neither.
30
30
  *
31
31
  * The highlight opens on the first linked record. Until it leaves that record,
32
32
  * by a key, by typing or by the pointer, an Enter does nothing, so the first
@@ -50,4 +50,6 @@ export declare const RelationSetEditor: import("react").ForwardRefExoticComponen
50
50
  seed?: string;
51
51
  /** Put the caret in the search as the panel opens, without scrolling. Default false. */
52
52
  focusSearch?: boolean;
53
+ /** The field's name, for an app's own `Picker` (its list's accessible name). Default: the search's words. */
54
+ label?: string;
53
55
  } & import("react").RefAttributes<RelationSetEditorHandle>>;
@@ -3,6 +3,7 @@ import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react";
4
4
  import { useViews } from "../provider/context.js";
5
5
  import { RelationPanel } from "./relation-panel.js";
6
+ import { RelationPickerBody } from "./relation-picker.js";
6
7
  function opening(items, lead) {
7
8
  if (!lead)
8
9
  return [...items];
@@ -16,6 +17,7 @@ function linksOf(items, lead) {
16
17
  id: item.id,
17
18
  ...(item.kind !== undefined ? { kind: item.kind } : {}),
18
19
  ...(item.role !== undefined ? { role: item.role } : {}),
20
+ ...(item.roles !== undefined ? { roles: item.roles } : {}),
19
21
  ...(lead ? { primary: index === 0 } : {}),
20
22
  }));
21
23
  }
@@ -25,7 +27,7 @@ function highlightedIn(search) {
25
27
  return undefined;
26
28
  return search.ownerDocument.getElementById(row)?.getAttribute("data-value") ?? undefined;
27
29
  }
28
- export const RelationSetEditor = forwardRef(function RelationSetEditor({ candidates, initial, lead = false, onRequestClose, kindGlyph, message, creates, seed, focusSearch = false, }, ref) {
30
+ export const RelationSetEditor = forwardRef(function RelationSetEditor({ candidates, initial, lead = false, onRequestClose, kindGlyph, message, creates, seed, focusSearch = false, label, }, ref) {
29
31
  const [start] = useState(() => opening(initial, lead));
30
32
  const [draft, setDraft] = useState(start);
31
33
  const draftRef = useRef(draft);
@@ -33,7 +35,7 @@ export const RelationSetEditor = forwardRef(function RelationSetEditor({ candida
33
35
  const searchRef = useRef(null);
34
36
  const views = useViews();
35
37
  const words = message ?? views.conventions.messages;
36
- const { Command, Button } = views.components;
38
+ const { Command, Button, Picker } = views.components;
37
39
  const { RowContent } = views.atoms;
38
40
  useEffect(() => {
39
41
  if (focusSearch)
@@ -67,6 +69,38 @@ export const RelationSetEditor = forwardRef(function RelationSetEditor({ candida
67
69
  const shown = candidates.kind === "remote" && typed !== ""
68
70
  ? draft.filter((item) => item.label.toLowerCase().includes(typed))
69
71
  : draft;
72
+ if (Picker) {
73
+ 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) => {
74
+ const ids = Array.isArray(next) ? next : [];
75
+ const kept = draftRef.current.filter((item) => ids.includes(item.id));
76
+ const added = ids
77
+ .filter((id) => !kept.some((item) => item.id === id))
78
+ .flatMap((id) => {
79
+ const candidate = found(id);
80
+ return candidate
81
+ ? [
82
+ {
83
+ id,
84
+ label: candidate.label,
85
+ ...(candidate.kind !== undefined ? { kind: candidate.kind } : {}),
86
+ ...(candidate.icon != null ? { icon: candidate.icon } : {}),
87
+ },
88
+ ]
89
+ : [];
90
+ });
91
+ change([...kept, ...added]);
92
+ }, onDone: () => onRequestClose("pick"), creates: creates, onCreate: (create, text) => {
93
+ onRequestClose("pick");
94
+ create.onCreate(text);
95
+ }, kindGlyph: kindGlyph, search: words({ key: "editor.search" }), lead: lead
96
+ ? {
97
+ value: draft[0]?.id ?? null,
98
+ onLead: makeLead,
99
+ label: words({ key: "relation.lead" }),
100
+ makeLabel: words({ key: "relation.make-lead" }),
101
+ }
102
+ : undefined, onTab: (reason) => onRequestClose(reason), typed: seed, autoFocus: focusSearch }));
103
+ }
70
104
  return (_jsx(RelationPanel, { candidates: candidates, query: query, onQueryChange: (next) => {
71
105
  movedRef.current = true;
72
106
  setQuery(next);
@@ -61,13 +61,16 @@ export declare const SelectEditor: import("react").ForwardRefExoticComponent<{
61
61
  * an open select, or a closed list past `SELECT_SEARCH_PAST` options. A plain list ignores it. */
62
62
  seed?: string;
63
63
  /** Put the caret in the search when the panel opens with one, without scrolling. Default false: a host whose
64
- * surface never moves focus (a drawer row on a desktop) leaves it off. */
64
+ * surface raises no keyboard (a phone's sheet) leaves it off. */
65
65
  focusSearch?: boolean;
66
66
  /** Opened from the keyboard: a plain list puts the focus on the row it holds (None when it may be emptied and
67
67
  * holds nothing, else its first row), so an Enter at once changes nothing; ↓ and ↑ walk its rows, round at either
68
68
  * end, and Enter picks the focused one. Default false: a list opened by a pointer moves no focus. A list with a
69
- * search ignores it, and `focusSearch` gives that one the keys. */
69
+ * search ignores it, and `focusSearch` gives that one the keys. A card's field and a field row set it when a key
70
+ * pressed their button. Either kind of list takes Tab and Shift-Tab itself and closes with them. */
70
71
  focusList?: boolean;
72
+ /** The field's name, for an app's own `Picker` (its list's accessible name). Default: the search's words. */
73
+ label?: string;
71
74
  } & import("react").RefAttributes<SelectEditorHandle>>;
72
75
  /**
73
76
  * A select field's options, dressed the way its cells are drawn — so what you
@@ -4,8 +4,9 @@ import { forwardRef, useEffect, useImperativeHandle, useRef, useState } from "re
4
4
  import { resolveCategoryColor } from "@viewkitjs/fields/design/category-colors";
5
5
  import { optionsOf, } from "@viewkitjs/fields";
6
6
  import { useViews } from "../provider/context.js";
7
+ import { PickerFrame, pickerItemOf, typedPick, usePickerForm } from "./picker-slot.js";
7
8
  export const SELECT_SEARCH_PAST = 8;
8
- export const SelectEditor = forwardRef(function SelectEditor({ options, initial, clearable = false, onRequestClose, message, creatable = false, seed, focusSearch = false, focusList = false, }, ref) {
9
+ export const SelectEditor = forwardRef(function SelectEditor({ options, initial, clearable = false, onRequestClose, message, creatable = false, seed, focusSearch = false, focusList = false, label, }, ref) {
9
10
  const searchable = creatable || options.length > SELECT_SEARCH_PAST;
10
11
  const [picked, setPicked] = useState(null);
11
12
  const pickedRef = useRef(null);
@@ -15,7 +16,8 @@ export const SelectEditor = forwardRef(function SelectEditor({ options, initial,
15
16
  const views = useViews();
16
17
  const words = message ?? views.conventions.messages;
17
18
  const { List, Row, RowContent, StatusBadge, Tag } = views.atoms;
18
- const { AppIcon, Command } = views.components;
19
+ const { AppIcon, Command, Picker } = views.components;
20
+ const form = usePickerForm();
19
21
  const Add = views.icons.add;
20
22
  const glyph = (icon) => (icon ? _jsx(AppIcon, { name: icon, className: "size-3 shrink-0" }) : undefined);
21
23
  const resolveClose = (reason) => {
@@ -32,6 +34,8 @@ export const SelectEditor = forwardRef(function SelectEditor({ options, initial,
32
34
  : options;
33
35
  const current = picked ?? initial ?? (clearable ? "" : undefined);
34
36
  useEffect(() => {
37
+ if (Picker)
38
+ return;
35
39
  if (searchable) {
36
40
  if (focusSearch)
37
41
  searchRef.current?.focus({ preventScroll: true });
@@ -48,7 +52,27 @@ export const SelectEditor = forwardRef(function SelectEditor({ options, initial,
48
52
  setPicked(value);
49
53
  onRequestClose("pick");
50
54
  };
55
+ const leaveOnTab = (event) => {
56
+ if (event.key !== "Tab" || event.altKey || event.ctrlKey || event.metaKey)
57
+ return false;
58
+ event.preventDefault();
59
+ onRequestClose(event.shiftKey ? "shift-tab" : "tab");
60
+ return true;
61
+ };
51
62
  const badge = (option) => option.slot ? (_jsx(StatusBadge, { slot: option.slot, label: option.label, leading: glyph(option.icon) })) : option.color ? (_jsx(Tag, { label: option.label, color: option.color, leading: glyph(option.icon) })) : (option.label);
63
+ if (Picker) {
64
+ const take = (value) => {
65
+ if (Array.isArray(value) || (value === null && !clearable))
66
+ return;
67
+ if (value !== null && !creatable && !options.some((option) => option.value === value))
68
+ return;
69
+ pickedRef.current = value ?? "";
70
+ setPicked(pickedRef.current);
71
+ };
72
+ return (_jsx(PickerFrame, { onTab: (reason) => onRequestClose(reason), children: _jsx(Picker, { label: label ?? words({ key: "editor.search" }), items: options.map(pickerItemOf), value: (picked ?? initial) || null, onValueChange: take, onDone: () => onRequestClose("pick"), empty: clearable ? words({ key: "relation.none" }) : undefined, search: words({ key: "editor.search" }), onCreate: creatable
73
+ ? (typed) => typedPick(typed, options.map((option) => option.value), pickedRef.current ?? initial ?? "")
74
+ : undefined, typed: seed, autoFocus: focusSearch || focusList, form: form }) }));
75
+ }
52
76
  if (searchable) {
53
77
  const typed = query.trim();
54
78
  const needle = typed.toLowerCase();
@@ -57,9 +81,12 @@ export const SelectEditor = forwardRef(function SelectEditor({ options, initial,
57
81
  const itemValue = (value) => (value === "" ? noneValue(options) : value);
58
82
  const startOn = clearable && !seed?.trim() ? itemValue(initial ?? "") : undefined;
59
83
  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 } }) }) }));
60
- 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-[13px]", value: query, onValueChange: setQuery }), _jsxs(Command.List, { className: "max-h-72 overscroll-contain scrollbar-overlay", children: [!useTyped && 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] }) })] })] }));
84
+ 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-[13px]", value: query, onValueChange: setQuery, onKeyDown: leaveOnTab }), _jsxs(Command.List, { className: "max-h-72 overscroll-contain scrollbar-overlay", children: [!useTyped && 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] }) })] })] }));
61
85
  }
62
- return (_jsx("div", { ref: listRef, className: "contents", onKeyDown: walkRows, 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))) }) }));
86
+ return (_jsx("div", { ref: listRef, className: "contents", onKeyDown: (event) => {
87
+ if (!leaveOnTab(event))
88
+ walkRows(event);
89
+ }, 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))) }) }));
63
90
  });
64
91
  function listButtons(box) {
65
92
  return box ? [...box.querySelectorAll("button:not(:disabled)")] : [];
@@ -2,6 +2,8 @@
2
2
  import { jsx as _jsx } from "react/jsx-runtime";
3
3
  import { forwardRef, useCallback, useImperativeHandle, useRef, } from "react";
4
4
  import { normalizeMarkdown } from "@viewkitjs/fields";
5
+ import { cx } from "../internal/cx.js";
6
+ import { ELEMENT_RESET } from "../internal/reset.js";
5
7
  import { useViews } from "../provider/context.js";
6
8
  export const TEXT_INPUT_TYPE = {
7
9
  text: "text",
@@ -70,7 +72,7 @@ export const TextEditor = forwardRef(function TextEditor({ type, initial, seed,
70
72
  className,
71
73
  style,
72
74
  };
73
- return area ? (_jsx("textarea", { ...shared, ref: attach, rows: rows, onInput: grows ? (event) => grow(event.currentTarget, maxLines) : undefined })) : (_jsx(Input, { ...shared, ref: attach, type: TEXT_INPUT_TYPE[type], chrome: chrome }));
75
+ 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 }));
74
76
  });
75
77
  function grow(el, maxLines) {
76
78
  el.style.height = "auto";
@@ -37,5 +37,8 @@ export declare const ValueListEditor: import("react").ForwardRefExoticComponent<
37
37
  /** Each stored value carries its open action beside it: mail, call or browse. A row typed over has none
38
38
  * until it is saved. The grid asks for it in a phone's sheet, where a tap on the cell edits it. Default false. */
39
39
  openLinks?: boolean;
40
+ /** Escape keeps the rows (the host's session keeps: `EditSession.keeps`): it checks them first, as Enter does,
41
+ * and an invalid row stays open with its error. Default false: Escape throws the edit away unchecked. */
42
+ escapeKeeps?: boolean;
40
43
  onRequestClose: (reason: CloseReason) => void;
41
44
  } & import("react").RefAttributes<ValueListEditorHandle>>;
@@ -3,14 +3,16 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { forwardRef, useEffect, useImperativeHandle, useRef, useState, } from "react";
4
4
  import { acceptFieldCommit, phoneText, valueItems, valueKey, } from "@viewkitjs/fields";
5
5
  import { cx } from "../internal/cx.js";
6
+ import { ELEMENT_RESET } from "../internal/reset.js";
6
7
  import { useViews } from "../provider/context.js";
7
8
  import { OpenValueAction, isOpenableType } from "./open-value.js";
9
+ import { EDITOR_INNER_ESCAPE } from "./EditorPanel.js";
8
10
  function textOf(value) {
9
11
  if (typeof value === "string")
10
12
  return value;
11
13
  return phoneText(value, null) || String(value);
12
14
  }
13
- export const ValueListEditor = forwardRef(function ValueListEditor({ field, initial, labels = true, allowEmpty = false, region, openLinks = false, onRequestClose }, ref) {
15
+ export const ValueListEditor = forwardRef(function ValueListEditor({ field, initial, labels = true, allowEmpty = false, region, openLinks = false, escapeKeeps = false, onRequestClose }, ref) {
14
16
  const views = useViews();
15
17
  const words = views.messages;
16
18
  const { Row } = views.atoms;
@@ -138,6 +140,8 @@ export const ValueListEditor = forwardRef(function ValueListEditor({ field, init
138
140
  const keys = (id) => (e) => {
139
141
  e.stopPropagation();
140
142
  if (e.key === "Escape") {
143
+ if (escapeKeeps && !checkAll())
144
+ return;
141
145
  onRequestClose("escape");
142
146
  }
143
147
  else if (e.key === "Enter") {
@@ -175,6 +179,8 @@ export const ValueListEditor = forwardRef(function ValueListEditor({ field, init
175
179
  const addKeys = (e) => {
176
180
  if (e.key === "Escape") {
177
181
  e.stopPropagation();
182
+ if (escapeKeeps && !checkAll())
183
+ return;
178
184
  onRequestClose("escape");
179
185
  }
180
186
  else if (e.key === "Tab") {
@@ -198,7 +204,7 @@ export const ValueListEditor = forwardRef(function ValueListEditor({ field, init
198
204
  };
199
205
  const input = "h-7 min-w-0 select-text rounded-md bg-transparent px-1.5 text-[length:var(--vk-text,0.8125rem)] text-(color:--vk-fg) outline-hidden placeholder:text-(color:--vk-fg-subtle) focus:bg-(color:--vk-hovered)";
200
206
  const iconButton = "flex size-6 shrink-0 items-center justify-center rounded-md text-(color:--vk-fg-subtle) transition-colors hover:bg-(color:--vk-hovered) hover:text-(color:--vk-fg)";
201
- return (_jsxs("div", { ref: boxRef, onMouseDown: (e) => {
207
+ return (_jsxs("div", { ref: boxRef, ...(escapeKeeps ? { [EDITOR_INNER_ESCAPE]: "" } : {}), onMouseDown: (e) => {
202
208
  if (!(e.target instanceof HTMLInputElement))
203
209
  e.preventDefault();
204
210
  }, className: "flex w-full min-w-0 flex-col gap-0.5", children: [rows.map((row) => {
@@ -208,10 +214,10 @@ export const ValueListEditor = forwardRef(function ValueListEditor({ field, init
208
214
  : words({ key: "views.editors.values-make-main", values: { value: shown } }), title: row.main ? words({ key: "views.editors.values-main" }) : undefined, onClick: (e) => {
209
215
  e.stopPropagation();
210
216
  makeMain(row.id);
211
- }, onKeyDown: (e) => buttonKeys(row.id, () => makeMain(row.id))(e), onKeyUp: noSpaceClick, onBlur: (e) => blur(row.id)(e), className: iconButton, children: _jsx("span", { className: cx("size-2.5 rounded-full border border-(color:--vk-fg-subtle)", row.main && "border-(color:--vk-fg-brand) bg-(color:--vk-fg-brand)") }) }), _jsx(Input, { "data-walk": true, "data-value": row.id, value: row.text, "aria-label": field.label, placeholder: field.label, "aria-invalid": row.error ? true : undefined, onChange: (e) => set(row.id, { text: e.target.value, error: undefined }), onKeyDown: keys(row.id), onBlur: (e) => blur(row.id)(e), onClick: (e) => e.stopPropagation(), className: cx(input, "flex-1") }), labels && (_jsx(Input, { "data-walk": true, value: row.label, "aria-label": words({ key: "views.editors.values-label" }), placeholder: words({ key: "views.editors.values-label" }), onChange: (e) => set(row.id, { label: e.target.value }), onKeyDown: keys(row.id), onBlur: (e) => blur(row.id)(e), onClick: (e) => e.stopPropagation(), className: cx(input, "w-24") })), openLinks && untouched(row) && isOpenableType(field.type) && (_jsx(OpenValueAction, { type: field.type, value: row.stored.value, label: row.text })), _jsx("button", { type: "button", "data-walk": true, "aria-label": words({ key: "views.editors.values-remove", values: { value: shown } }), onClick: (e) => {
217
+ }, onKeyDown: (e) => buttonKeys(row.id, () => makeMain(row.id))(e), onKeyUp: noSpaceClick, onBlur: (e) => blur(row.id)(e), className: cx(ELEMENT_RESET, iconButton), children: _jsx("span", { className: cx("size-2.5 rounded-full border border-(color:--vk-fg-subtle)", row.main && "border-(color:--vk-fg-brand) bg-(color:--vk-fg-brand)") }) }), _jsx(Input, { "data-walk": true, "data-value": row.id, value: row.text, "aria-label": field.label, placeholder: field.label, "aria-invalid": row.error ? true : undefined, onChange: (e) => set(row.id, { text: e.target.value, error: undefined }), onKeyDown: keys(row.id), onBlur: (e) => blur(row.id)(e), onClick: (e) => e.stopPropagation(), className: cx(input, "flex-1") }), labels && (_jsx(Input, { "data-walk": true, value: row.label, "aria-label": words({ key: "views.editors.values-label" }), placeholder: words({ key: "views.editors.values-label" }), onChange: (e) => set(row.id, { label: e.target.value }), onKeyDown: keys(row.id), onBlur: (e) => blur(row.id)(e), onClick: (e) => e.stopPropagation(), className: cx(input, "w-24") })), openLinks && untouched(row) && isOpenableType(field.type) && (_jsx(OpenValueAction, { type: field.type, value: row.stored.value, label: row.text })), _jsx("button", { type: "button", "data-walk": true, "aria-label": words({ key: "views.editors.values-remove", values: { value: shown } }), onClick: (e) => {
212
218
  e.stopPropagation();
213
219
  remove(row.id);
214
- }, onKeyDown: (e) => buttonKeys(row.id, () => remove(row.id))(e), onKeyUp: noSpaceClick, onBlur: (e) => blur(row.id)(e), className: iconButton, children: _jsx(Remove, { className: "size-3.5" }) })] }), row.error && (_jsx("p", { role: "alert", className: "px-8 pb-1 text-xs text-(color:--vk-danger)", children: row.error }))] }, row.id));
220
+ }, onKeyDown: (e) => buttonKeys(row.id, () => remove(row.id))(e), onKeyUp: noSpaceClick, onBlur: (e) => blur(row.id)(e), className: cx(ELEMENT_RESET, iconButton), children: _jsx(Remove, { className: "size-3.5" }) })] }), row.error && (_jsx("p", { role: "alert", className: "px-8 pb-1 text-xs text-(color:--vk-danger)", children: row.error }))] }, row.id));
215
221
  }), _jsx("div", { ref: addRef, onKeyDown: addKeys, onBlur: (e) => {
216
222
  if (!boxRef.current?.contains(e.relatedTarget))
217
223
  onRequestClose("blur");
@@ -1,5 +1,7 @@
1
1
  import { type RefObject } from "react";
2
2
  import type { CloseReason, CloseResolution } from "@viewkitjs/fields";
3
+ import type { EditEscape } from "./escape-rule.js";
4
+ export { useEscapeRule, type EditEscape } from "./escape-rule.js";
3
5
  /**
4
6
  * THE ANCHORED EDIT SESSION — the handshake plumbing every host that opens a
5
7
  * PANEL over a value repeats, in one place.
@@ -44,7 +46,8 @@ export declare const EDITOR_EXIT_MS = 160;
44
46
  *
45
47
  * `close(reason)` is the ONE door: Radix's dismiss, the core's own
46
48
  * `onRequestClose`, and a host's keyboard handler all land here, and only the
47
- * first counts. `close("escape")` answers a cancel without asking the editor. `mapPayload` is the host's one chance to reshape a commit
49
+ * first counts. `close("escape")` answers a cancel without asking the editor, unless the session keeps
50
+ * (`escape`). `mapPayload` is the host's one chance to reshape a commit
48
51
  * before it leaves (a select's empty string becoming `null`, a day field's
49
52
  * timestamp trimmed to its date) — applied to a commit alone, never to a cancel
50
53
  * or a noop, which carry no payload to reshape.
@@ -53,6 +56,12 @@ type AnchoredEditSessionBase<P> = {
53
56
  editorRef: RefObject<ResolvableHandle<P> | null>;
54
57
  mapPayload?: (payload: P) => unknown;
55
58
  exitMs?: number;
59
+ /** `keep`: on a desktop, Escape asks the editor as a press outside does (`"outside"`), so what was typed is
60
+ * kept, and a refusal stays open with its reason; a second Escape while it stands throws the edit away. Read
61
+ * once, when the session opens: below the desktop width
62
+ * it is the discard, so a phone's sheet keeps nothing. Default `cancel`: Escape answers a cancel without
63
+ * asking the editor. A host reads it for its field's type with `useEscapeRule`. */
64
+ escape?: EditEscape;
56
65
  };
57
66
  type DeferredResolution<P> = AnchoredEditSessionBase<P> & {
58
67
  /** Compatibility mode: the answer, including persistence, follows the exit. */
@@ -72,6 +81,10 @@ export type EditSession = {
72
81
  /** The reason the host gave for the last refused attempt, until the next attempt; `null`
73
82
  * otherwise, and always in the deferred mode. */
74
83
  refusal: string | null;
84
+ /** This session's Escape keeps what was typed: `escape: "keep"`, on a desktop when it opened. An editor that
85
+ * checks its draft before a key closes it (a value list's rows) checks it before Escape too. Optional, so a
86
+ * session an app builds by hand still fits; `useAnchoredEditSession` always sets it. */
87
+ keeps?: boolean;
75
88
  };
76
89
  type AdmittedResolution<P> = AnchoredEditSessionBase<P> & {
77
90
  /** Ask synchronously whether this answer may close. Refusal is nonterminal. */
@@ -81,4 +94,3 @@ type AdmittedResolution<P> = AnchoredEditSessionBase<P> & {
81
94
  onDone?: never;
82
95
  };
83
96
  export declare function useAnchoredEditSession<P>(args: DeferredResolution<P> | AdmittedResolution<P>): EditSession;
84
- export {};
@@ -1,11 +1,17 @@
1
1
  "use client";
2
- import { useEffect, useRef, useState } from "react";
2
+ import { useContext, useEffect, useRef, useState } from "react";
3
+ import { ViewsContext } from "../provider/context.js";
4
+ import { DEFAULT_DESKTOP_QUERY, isDesktopNow } from "../provider/desktop.js";
5
+ export { useEscapeRule } from "./escape-rule.js";
3
6
  export const EDITOR_EXIT_MS = 160;
4
7
  export function useAnchoredEditSession(args) {
5
- const { editorRef, mapPayload, exitMs = EDITOR_EXIT_MS } = args;
8
+ const { editorRef, mapPayload, exitMs = EDITOR_EXIT_MS, escape = "cancel" } = args;
9
+ const desktopQuery = useContext(ViewsContext)?.desktopQuery ?? DEFAULT_DESKTOP_QUERY;
10
+ const [keeps] = useState(() => escape === "keep" && isDesktopNow(desktopQuery));
6
11
  const [open, setOpen] = useState(true);
7
12
  const [refusal, setRefusal] = useState(null);
8
13
  const closedRef = useRef(false);
14
+ const refusedRef = useRef(false);
9
15
  const timerRef = useRef(null);
10
16
  const admitted = args.onAttempt !== undefined;
11
17
  useEffect(() => () => {
@@ -15,14 +21,15 @@ export function useAnchoredEditSession(args) {
15
21
  const close = (reason) => {
16
22
  if (closedRef.current)
17
23
  return;
18
- const resolution = reason === "escape"
24
+ const resolution = reason === "escape" && (!keeps || refusedRef.current)
19
25
  ? { kind: "cancel" }
20
- : (editorRef.current?.resolveClose(reason) ?? { kind: "noop" });
26
+ : (editorRef.current?.resolveClose(reason === "escape" ? "outside" : reason) ?? { kind: "noop" });
21
27
  const answer = resolution.kind === "commit" && mapPayload
22
28
  ? { kind: "commit", payload: mapPayload(resolution.payload) }
23
29
  : resolution;
24
30
  if (args.onAttempt) {
25
31
  setRefusal(null);
32
+ refusedRef.current = false;
26
33
  closedRef.current = true;
27
34
  let attempt;
28
35
  try {
@@ -34,6 +41,7 @@ export function useAnchoredEditSession(args) {
34
41
  }
35
42
  if (!attempt.accepted) {
36
43
  closedRef.current = false;
44
+ refusedRef.current = keeps && reason === "escape";
37
45
  setRefusal(attempt.reason ?? null);
38
46
  return;
39
47
  }
@@ -45,5 +53,5 @@ export function useAnchoredEditSession(args) {
45
53
  setOpen(false);
46
54
  timerRef.current = window.setTimeout(() => args.onDone(answer), exitMs);
47
55
  };
48
- return { open, close, refusal };
56
+ return { open, close, refusal, keeps };
49
57
  }
@@ -0,0 +1,12 @@
1
+ import type { FieldType } from "@viewkitjs/fields";
2
+ /** `cancel` throws the edit away (the default); `keep` keeps what was typed and closes, as a press outside does. */
3
+ export type EditEscape = "cancel" | "keep";
4
+ /** What Escape does per field type. A type left out throws the edit away. */
5
+ export type ViewsEscapeRules = Partial<Record<FieldType, EditEscape>>;
6
+ /**
7
+ * The field type the editor under it edits: a grid cell and a field row provide it around the editor they
8
+ * open, and their session reads the rule by it. The package's own; no entry point exports it.
9
+ */
10
+ export declare const EditFieldTypeContext: import("react").Context<FieldType | undefined>;
11
+ /** What Escape does in an editor of this type: the provider's word for it, or `cancel`. Never throws without a provider. */
12
+ export declare function useEscapeRule(type: FieldType | undefined): EditEscape;
@@ -0,0 +1,8 @@
1
+ "use client";
2
+ import { createContext, useContext } from "react";
3
+ import { ViewsContext } from "../provider/context.js";
4
+ export const EditFieldTypeContext = createContext(undefined);
5
+ export function useEscapeRule(type) {
6
+ const views = useContext(ViewsContext);
7
+ return (type && views?.escape?.[type]) || "cancel";
8
+ }