@viewkitjs/views 0.2.0 → 0.3.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 (292) hide show
  1. package/CHANGELOG.md +571 -0
  2. package/README.md +5 -3
  3. package/dist/atoms/LoadMore.js +11 -1
  4. package/dist/atoms/RowMenu.js +5 -2
  5. package/dist/cells/cell-format.d.ts +3 -3
  6. package/dist/cells/cell-title.d.ts +1 -2
  7. package/dist/cells/cell-title.js +2 -2
  8. package/dist/cells/cell-values.js +6 -3
  9. package/dist/contract.d.ts +50 -9
  10. package/dist/contract.js +33 -5
  11. package/dist/display/converted.d.ts +19 -0
  12. package/dist/display/converted.js +12 -0
  13. package/dist/display/index.d.ts +1 -0
  14. package/dist/display/index.js +1 -0
  15. package/dist/display/link-click.d.ts +11 -0
  16. package/dist/display/link-click.js +3 -0
  17. package/dist/display/link.js +7 -3
  18. package/dist/display/multi-value.d.ts +1 -1
  19. package/dist/display/multi-value.js +1 -1
  20. package/dist/display/options.d.ts +7 -1
  21. package/dist/display/phone.js +3 -1
  22. package/dist/editors/ChipsEditor.d.ts +9 -4
  23. package/dist/editors/ChipsEditor.js +6 -2
  24. package/dist/editors/DateEditor.d.ts +21 -6
  25. package/dist/editors/DateEditor.js +118 -30
  26. package/dist/editors/EditorPanel.d.ts +61 -0
  27. package/dist/editors/EditorPanel.js +54 -0
  28. package/dist/editors/LocationEditor.d.ts +3 -0
  29. package/dist/editors/LocationEditor.js +14 -6
  30. package/dist/editors/NameEditor.d.ts +3 -0
  31. package/dist/editors/NameEditor.js +11 -7
  32. package/dist/editors/NumberEditor.d.ts +3 -0
  33. package/dist/editors/NumberEditor.js +6 -6
  34. package/dist/editors/RangeEditor.d.ts +16 -1
  35. package/dist/editors/RangeEditor.js +21 -5
  36. package/dist/editors/RelationEditor.d.ts +13 -28
  37. package/dist/editors/RelationEditor.js +17 -40
  38. package/dist/editors/RelationSetEditor.d.ts +53 -0
  39. package/dist/editors/RelationSetEditor.js +112 -0
  40. package/dist/editors/SelectEditor.d.ts +21 -3
  41. package/dist/editors/SelectEditor.js +55 -9
  42. package/dist/editors/TextEditor.d.ts +51 -0
  43. package/dist/editors/TextEditor.js +81 -0
  44. package/dist/editors/ValueListEditor.d.ts +3 -0
  45. package/dist/editors/ValueListEditor.js +4 -2
  46. package/dist/editors/edit-cores.d.ts +12 -9
  47. package/dist/editors/edit-cores.js +7 -6
  48. package/dist/editors/edit-session.d.ts +21 -11
  49. package/dist/editors/edit-session.js +19 -5
  50. package/dist/editors/keep-inside.d.ts +12 -0
  51. package/dist/editors/keep-inside.js +20 -0
  52. package/dist/editors/open-value.d.ts +21 -0
  53. package/dist/editors/open-value.js +36 -0
  54. package/dist/editors/open-values.d.ts +4 -0
  55. package/dist/editors/open-values.js +7 -0
  56. package/dist/editors/relation-kinds.d.ts +7 -0
  57. package/dist/editors/relation-kinds.js +21 -0
  58. package/dist/editors/relation-panel.d.ts +69 -0
  59. package/dist/editors/relation-panel.js +40 -0
  60. package/dist/field-row/FieldNoteLine.d.ts +14 -0
  61. package/dist/field-row/FieldNoteLine.js +14 -0
  62. package/dist/field-row/FieldRow.d.ts +73 -0
  63. package/dist/field-row/FieldRow.js +157 -0
  64. package/dist/field-row/FieldRowLane.d.ts +19 -0
  65. package/dist/field-row/FieldRowLane.js +11 -0
  66. package/dist/field-row/editors/RowChipsEditor.d.ts +11 -0
  67. package/dist/field-row/editors/RowChipsEditor.js +25 -0
  68. package/dist/field-row/editors/RowDateEditor.d.ts +16 -0
  69. package/dist/field-row/editors/RowDateEditor.js +18 -0
  70. package/dist/field-row/editors/RowEditor.d.ts +39 -0
  71. package/dist/field-row/editors/RowEditor.js +64 -0
  72. package/dist/field-row/editors/RowNameEditor.d.ts +4 -0
  73. package/dist/field-row/editors/RowNameEditor.js +15 -0
  74. package/dist/field-row/editors/RowNumberEditor.d.ts +12 -0
  75. package/dist/field-row/editors/RowNumberEditor.js +18 -0
  76. package/dist/field-row/editors/RowPlaceEditor.d.ts +8 -0
  77. package/dist/field-row/editors/RowPlaceEditor.js +18 -0
  78. package/dist/field-row/editors/RowRangeEditor.d.ts +4 -0
  79. package/dist/field-row/editors/RowRangeEditor.js +15 -0
  80. package/dist/field-row/editors/RowRelationEditor.d.ts +20 -0
  81. package/dist/field-row/editors/RowRelationEditor.js +77 -0
  82. package/dist/field-row/editors/RowSelectEditor.d.ts +13 -0
  83. package/dist/field-row/editors/RowSelectEditor.js +23 -0
  84. package/dist/field-row/editors/RowTextEditor.d.ts +15 -0
  85. package/dist/field-row/editors/RowTextEditor.js +16 -0
  86. package/dist/field-row/editors/RowValueListEditor.d.ts +4 -0
  87. package/dist/field-row/editors/RowValueListEditor.js +21 -0
  88. package/dist/field-row/editors/host.d.ts +59 -0
  89. package/dist/field-row/editors/host.js +1 -0
  90. package/dist/field-row/editors/row-session.d.ts +49 -0
  91. package/dist/field-row/editors/row-session.js +49 -0
  92. package/dist/field-row/index.d.ts +5 -0
  93. package/dist/field-row/index.js +5 -0
  94. package/dist/field-row/row-target.d.ts +20 -0
  95. package/dist/field-row/row-target.js +3 -0
  96. package/dist/field-row/useFieldWrite.d.ts +45 -0
  97. package/dist/field-row/useFieldWrite.js +190 -0
  98. package/dist/field-row/useRowSettlement.d.ts +33 -0
  99. package/dist/field-row/useRowSettlement.js +23 -0
  100. package/dist/fields/binding.d.ts +6 -1
  101. package/dist/fields/binding.js +13 -6
  102. package/dist/fields/edit-core-types.d.ts +9 -9
  103. package/dist/fields/edit-core-types.js +6 -6
  104. package/dist/fields/money.d.ts +5 -0
  105. package/dist/fields/money.js +10 -0
  106. package/dist/fields/number-edit.d.ts +6 -0
  107. package/dist/fields/number-edit.js +4 -0
  108. package/dist/fields/prepare-write.js +6 -1
  109. package/dist/fields/relation-source-types.d.ts +12 -0
  110. package/dist/fields/write-target.d.ts +50 -0
  111. package/dist/fields/write-target.js +10 -0
  112. package/dist/grid/chrome/GridAddColumn.js +1 -1
  113. package/dist/grid/chrome/GridAggregateMenu.d.ts +1 -1
  114. package/dist/grid/chrome/GridAggregateMenu.js +8 -6
  115. package/dist/grid/chrome/GridCellEditors.d.ts +7 -0
  116. package/dist/grid/chrome/GridCellEditors.js +87 -16
  117. package/dist/grid/chrome/GridCellOutline.d.ts +22 -43
  118. package/dist/grid/chrome/GridCellOutline.js +2 -7
  119. package/dist/grid/chrome/GridChipsEditor.d.ts +16 -6
  120. package/dist/grid/chrome/GridChipsEditor.js +21 -26
  121. package/dist/grid/chrome/GridColumnMenu.d.ts +1 -1
  122. package/dist/grid/chrome/GridColumnMenu.js +7 -3
  123. package/dist/grid/chrome/GridDateEditor.d.ts +23 -11
  124. package/dist/grid/chrome/GridDateEditor.js +13 -25
  125. package/dist/grid/chrome/GridFooter.d.ts +12 -2
  126. package/dist/grid/chrome/GridFooter.js +10 -6
  127. package/dist/grid/chrome/GridGroupMenu.js +20 -13
  128. package/dist/grid/chrome/GridHeader.d.ts +9 -4
  129. package/dist/grid/chrome/GridHeader.js +15 -10
  130. package/dist/grid/chrome/GridLongTextEditor.d.ts +28 -9
  131. package/dist/grid/chrome/GridLongTextEditor.js +16 -74
  132. package/dist/grid/chrome/GridNameEditor.d.ts +11 -6
  133. package/dist/grid/chrome/GridNameEditor.js +12 -27
  134. package/dist/grid/chrome/GridNumberEditor.d.ts +20 -6
  135. package/dist/grid/chrome/GridNumberEditor.js +46 -20
  136. package/dist/grid/chrome/GridPlaceEditor.d.ts +26 -0
  137. package/dist/grid/chrome/GridPlaceEditor.js +22 -0
  138. package/dist/grid/chrome/GridRangeEditor.d.ts +15 -5
  139. package/dist/grid/chrome/GridRangeEditor.js +16 -20
  140. package/dist/grid/chrome/GridRelationEditor.d.ts +38 -14
  141. package/dist/grid/chrome/GridRelationEditor.js +86 -24
  142. package/dist/grid/chrome/GridRow.d.ts +7 -1
  143. package/dist/grid/chrome/GridRow.js +57 -14
  144. package/dist/grid/chrome/GridRowActions.js +1 -1
  145. package/dist/grid/chrome/GridRowCells.js +18 -23
  146. package/dist/grid/chrome/GridSelectEditor.d.ts +19 -4
  147. package/dist/grid/chrome/GridSelectEditor.js +21 -27
  148. package/dist/grid/chrome/GridStructure.d.ts +9 -10
  149. package/dist/grid/chrome/GridStructure.js +10 -14
  150. package/dist/grid/chrome/GridTable.js +97 -30
  151. package/dist/grid/chrome/GridTableSurface.d.ts +39 -2
  152. package/dist/grid/chrome/GridTableSurface.js +12 -3
  153. package/dist/grid/chrome/GridTextEditor.d.ts +35 -1
  154. package/dist/grid/chrome/GridTextEditor.js +35 -37
  155. package/dist/grid/chrome/GridValueListEditor.d.ts +15 -3
  156. package/dist/grid/chrome/GridValueListEditor.js +10 -27
  157. package/dist/grid/chrome/cell-cut-off.d.ts +11 -0
  158. package/dist/grid/chrome/cell-cut-off.js +20 -0
  159. package/dist/grid/chrome/cells.js +1 -2
  160. package/dist/grid/chrome/checks.d.ts +2 -5
  161. package/dist/grid/chrome/checks.js +15 -5
  162. package/dist/grid/chrome/editors.d.ts +1 -1
  163. package/dist/grid/chrome/editors.js +1 -1
  164. package/dist/grid/chrome/grid-cell-classes.d.ts +2 -8
  165. package/dist/grid/chrome/grid-cell-classes.js +10 -8
  166. package/dist/grid/chrome/grid-cell-link.d.ts +13 -0
  167. package/dist/grid/chrome/grid-cell-link.js +9 -0
  168. package/dist/grid/chrome/grid-edit-session.d.ts +63 -0
  169. package/dist/grid/chrome/grid-edit-session.js +118 -0
  170. package/dist/grid/chrome/grid-hover.d.ts +60 -0
  171. package/dist/grid/chrome/grid-hover.js +81 -0
  172. package/dist/grid/chrome/grid-menu-focus.d.ts +43 -0
  173. package/dist/grid/chrome/grid-menu-focus.js +93 -0
  174. package/dist/grid/chrome/grid-row-menu-key.d.ts +15 -0
  175. package/dist/grid/chrome/grid-row-menu-key.js +36 -0
  176. package/dist/grid/chrome/grid-row-props.d.ts +16 -4
  177. package/dist/grid/chrome/grid-row-window.d.ts +61 -0
  178. package/dist/grid/chrome/grid-row-window.js +212 -0
  179. package/dist/grid/chrome/grid-scroll-owner.d.ts +38 -0
  180. package/dist/grid/chrome/grid-scroll-owner.js +75 -0
  181. package/dist/grid/chrome/grid-styles.d.ts +4 -1
  182. package/dist/grid/chrome/grid-styles.js +1 -0
  183. package/dist/grid/chrome/grid-table-props.d.ts +2 -3
  184. package/dist/grid/chrome/useGridFocus.d.ts +45 -0
  185. package/dist/grid/chrome/useGridFocus.js +122 -0
  186. package/dist/grid/chrome/useGridKeyboard.d.ts +21 -4
  187. package/dist/grid/chrome/useGridKeyboard.js +214 -38
  188. package/dist/grid/chrome/useGridRangeActions.d.ts +3 -1
  189. package/dist/grid/chrome/useGridRangeActions.js +17 -10
  190. package/dist/grid/chrome/useGridRangeGestures.js +68 -21
  191. package/dist/grid/chrome/useGridRowContextMenu.d.ts +4 -2
  192. package/dist/grid/chrome/useGridRowContextMenu.js +28 -2
  193. package/dist/grid/chrome/useGridScaleStyles.d.ts +3 -1
  194. package/dist/grid/chrome/useGridScaleStyles.js +6 -7
  195. package/dist/grid/chrome/useGridScrollArea.d.ts +21 -0
  196. package/dist/grid/chrome/useGridScrollArea.js +65 -0
  197. package/dist/grid/chrome/useGridTableInteractionModel.d.ts +28 -5
  198. package/dist/grid/chrome/useGridTableInteractionModel.js +66 -14
  199. package/dist/grid/chrome/useHeaderDragReorder.d.ts +2 -2
  200. package/dist/grid/core/clipboard-model.d.ts +2 -0
  201. package/dist/grid/core/clipboard-model.js +1 -1
  202. package/dist/grid/core/commit-model.d.ts +7 -0
  203. package/dist/grid/core/edge-scroll.d.ts +21 -0
  204. package/dist/grid/core/edge-scroll.js +23 -0
  205. package/dist/grid/core/editing-controller.d.ts +2 -1
  206. package/dist/grid/core/editing-controller.js +35 -9
  207. package/dist/grid/core/editing-model.d.ts +9 -0
  208. package/dist/grid/core/editing-model.js +12 -0
  209. package/dist/grid/core/flat-rows.d.ts +35 -0
  210. package/dist/grid/core/flat-rows.js +20 -0
  211. package/dist/grid/core/grid-aria.d.ts +27 -0
  212. package/dist/grid/core/grid-aria.js +39 -0
  213. package/dist/grid/core/grid-focus.d.ts +54 -0
  214. package/dist/grid/core/grid-focus.js +148 -0
  215. package/dist/grid/core/nav.d.ts +2 -2
  216. package/dist/grid/core/pending-reconciliation.d.ts +3 -0
  217. package/dist/grid/core/pending-reconciliation.js +5 -3
  218. package/dist/grid/core/row-window.d.ts +40 -0
  219. package/dist/grid/core/row-window.js +43 -0
  220. package/dist/grid/core/spreadsheet-operations.d.ts +17 -1
  221. package/dist/grid/core/spreadsheet-operations.js +33 -6
  222. package/dist/grid/core/useGridEditing.d.ts +3 -0
  223. package/dist/grid/core/useGridEditing.js +6 -3
  224. package/dist/grid/core/value-equality.d.ts +23 -1
  225. package/dist/grid/core/value-equality.js +46 -0
  226. package/dist/grid/useGridTablePrefs.d.ts +0 -1
  227. package/dist/grid/useGridTablePrefs.js +1 -3
  228. package/dist/index.d.ts +1 -0
  229. package/dist/index.js +1 -0
  230. package/dist/internal/viewport.d.ts +0 -2
  231. package/dist/internal/viewport.js +0 -14
  232. package/dist/model/column-capabilities.d.ts +2 -1
  233. package/dist/model/column-capabilities.js +28 -8
  234. package/dist/model/column-from.js +3 -0
  235. package/dist/model/column-inspect.d.ts +10 -2
  236. package/dist/model/column-inspect.js +9 -0
  237. package/dist/model/column-schema.d.ts +6 -1
  238. package/dist/model/column-types.d.ts +3 -1
  239. package/dist/model/column-types.js +1 -1
  240. package/dist/model/preferences.d.ts +0 -4
  241. package/dist/model/preferences.js +0 -1
  242. package/dist/model/prefs-buckets.d.ts +0 -1
  243. package/dist/model/prefs-buckets.js +0 -3
  244. package/dist/model/render-count.d.ts +6 -0
  245. package/dist/model/render-count.js +11 -0
  246. package/dist/provider/ViewsProvider.d.ts +5 -1
  247. package/dist/provider/ViewsProvider.js +9 -3
  248. package/dist/provider/components.d.ts +19 -1
  249. package/dist/provider/components.js +4 -2
  250. package/dist/provider/context.d.ts +5 -2
  251. package/dist/provider/desktop.d.ts +9 -0
  252. package/dist/provider/desktop.js +22 -0
  253. package/dist/provider/plain-input.d.ts +8 -0
  254. package/dist/provider/plain-input.js +5 -0
  255. package/dist/react.d.ts +2 -1
  256. package/dist/react.js +1 -0
  257. package/dist/selection/SelectCheckbox.d.ts +3 -1
  258. package/dist/selection/SelectCheckbox.js +2 -2
  259. package/dist/selection/useCheckDragSelect.js +6 -5
  260. package/docs/contract.md +93 -35
  261. package/docs/guides/atoms.md +1 -1
  262. package/docs/guides/cells.md +2 -2
  263. package/docs/guides/columns.md +3 -2
  264. package/docs/guides/display.md +1 -0
  265. package/docs/guides/editors.md +71 -13
  266. package/docs/guides/the-grid.md +32 -13
  267. package/docs/guides/the-provider.md +3 -1
  268. package/docs/index.md +3 -1
  269. package/docs/install.md +1 -1
  270. package/docs/reference/cells.md +1 -1
  271. package/docs/reference/display.md +3 -1
  272. package/docs/reference/editors-chips.md +2 -2
  273. package/docs/reference/editors-date.md +3 -3
  274. package/docs/reference/editors-location.md +1 -1
  275. package/docs/reference/editors-number.md +1 -1
  276. package/docs/reference/editors-open-values.md +1 -0
  277. package/docs/reference/editors-panel.md +12 -0
  278. package/docs/reference/editors-range.md +1 -1
  279. package/docs/reference/editors-relation.md +6 -3
  280. package/docs/reference/editors-select.md +3 -2
  281. package/docs/reference/editors-session.md +4 -2
  282. package/docs/reference/editors-text.md +9 -0
  283. package/docs/reference/editors-value-list.md +1 -1
  284. package/docs/reference/editors.md +2 -2
  285. package/docs/reference/field-row.md +16 -0
  286. package/docs/reference/grid.md +3 -3
  287. package/docs/reference/react.md +8 -5
  288. package/docs/reference/views.md +36 -15
  289. package/package.json +23 -4
  290. package/skills/views/SKILL.md +4 -4
  291. package/dist/grid/chrome/useGridScrollSync.d.ts +0 -38
  292. package/dist/grid/chrome/useGridScrollSync.js +0 -176
@@ -1,23 +1,32 @@
1
+ import { type ReactNode } from "react";
2
+ import { type TextEditorType } from "../../editors/TextEditor.js";
1
3
  /**
2
4
  * The GRID's long-text panel — reading and editing a paragraph in ONE surface.
3
5
  *
4
6
  * A `format.long` text is a paragraph, and a paragraph in a 37px cell is one
5
7
  * clipped line with no way in. So editing it does not swap the cell for a
6
8
  * one-line input: it opens a panel ON the cell (top-left on the cell's
7
- * top-left, the column's width) holding the whole value in a textarea, the
8
- * caret at the end — Attio's model. Inspection is the same panel with the
9
- * textarea read-only: the value is selectable, copyable, and never written.
9
+ * top-left, the column's width) holding the whole value in the shared
10
+ * `TextEditor` as a paragraph, the caret at the end — Attio's model.
11
+ * Inspection is the same panel read-only: the value is selectable, copyable,
12
+ * and never written.
10
13
  *
11
14
  * Anchored like the select and date editors: the cell's own content stays on
12
15
  * screen behind the popover, `useAnchoredEditSession` owns the one-answer
13
- * guard and the exit gap, and Radix owns the viewport — with no room below
14
- * the panel opens above the cell.
16
+ * guard and the exit gap, and the app's popover owns the viewport — with no
17
+ * room below the panel opens above the cell. On a phone it opens in the sheet
18
+ * instead (`EditorPanel`), titled with the column's header; the answer waits
19
+ * for the sheet to slide away, and ✓ never moves the selection.
15
20
  *
16
- * Keys are a paragraph's: Enter is a newline; ⌘-Enter commits and advances;
17
- * Tab commits and moves; Escape cancels; an outside click commits. The host
18
- * grid's click-away listener clears the cell's focus after that commit.
21
+ * It also opens a LINE whole (`paragraph={false}`): a plain text or a text
22
+ * name its cell cut off. The box wraps so all of it shows, but it is
23
+ * still a line: Enter commits and advances, and a newline is written as a space.
24
+ *
25
+ * Keys are a paragraph's: Enter is a newline; ⌘ or Ctrl Enter commits and
26
+ * advances; Tab commits and moves; Escape cancels; an outside click commits.
27
+ * The host grid's click-away listener clears the cell's focus after that commit.
19
28
  */
20
- export declare function GridLongTextEditor({ initial, seed, readOnly, markdown, onCommit, onCancel, onTab, onEnter, }: {
29
+ export declare function GridLongTextEditor({ initial, seed, readOnly, markdown, paragraph, type, title, refuse, onCommit, onCancel, onTab, onEnter, }: {
21
30
  /** The stored value the session opens on ("" when unset). */
22
31
  initial: string;
23
32
  /** Type-to-replace: the character that opened this editor replaces the value. */
@@ -27,10 +36,20 @@ export declare function GridLongTextEditor({ initial, seed, readOnly, markdown,
27
36
  /** Markdown keeps its first line's indent: it is tidied only at its edges
28
37
  * (`normalizeMarkdown`), where plain long text is trimmed. */
29
38
  markdown?: boolean;
39
+ /** A paragraph (default): Enter is a newline. False: a line shown whole, where Enter commits. */
40
+ paragraph?: boolean;
41
+ /** The text editor's type for a line (its keyboard on a phone). Default: rich text when
42
+ * `markdown`, else text. */
43
+ type?: TextEditorType;
44
+ /** The sheet's title on a phone: the column's header. */
45
+ title?: ReactNode;
30
46
  onCommit: (value: string) => void;
31
47
  onCancel: () => void;
32
48
  /** Commit happened via Tab — move to the next cell in reading order. */
33
49
  onTab?: (backwards: boolean) => void;
34
50
  /** Commit happened via ⌘-Enter — advance one row down. */
35
51
  onEnter?: () => void;
52
+ /** The grid's judgement of a value before it is written: its reason when it would refuse it.
53
+ * A refused value stays open in the panel with that reason. */
54
+ refuse?: (value: string) => string | null;
36
55
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,85 +1,34 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
- import { useCallback, useLayoutEffect, useRef, useState } from "react";
4
- import { useAnchoredEditSession } from "../../editors/edit-session.js";
3
+ import { useLayoutEffect, useRef, useState } from "react";
4
+ import { EditorPanel } from "../../editors/EditorPanel.js";
5
+ import { TextEditor } from "../../editors/TextEditor.js";
5
6
  import { useViews } from "../../provider/context.js";
6
7
  import { cx } from "../../internal/cx.js";
7
- import { normalizeMarkdown } from "@viewkitjs/fields";
8
+ import { useGridEditSession } from "./grid-edit-session.js";
8
9
  const MIN_W = 320;
9
10
  const MAX_W = 512;
10
- const MAX_LINES = 12;
11
- export function GridLongTextEditor({ initial, seed, readOnly = false, markdown = false, onCommit, onCancel, onTab, onEnter, }) {
12
- const { components, messages } = useViews();
13
- const { Popover } = components;
11
+ export function GridLongTextEditor({ initial, seed, readOnly = false, markdown = false, paragraph = true, type, title, refuse, onCommit, onCancel, onTab, onEnter, }) {
12
+ const { messages } = useViews();
14
13
  const anchorRef = useRef(null);
15
- const areaRef = useRef(null);
14
+ const editorRef = useRef(null);
16
15
  const [cell, setCell] = useState(null);
17
16
  useLayoutEffect(() => {
18
17
  const anchor = anchorRef.current;
19
18
  if (anchor)
20
19
  setCell(measureCell(anchor));
21
20
  }, []);
22
- const handleRef = useRef({
23
- resolveClose: (reason) => {
24
- if (readOnly)
25
- return { kind: "noop" };
26
- if (reason === "escape")
27
- return { kind: "cancel" };
28
- const tidy = markdown ? normalizeMarkdown : (text) => text.trim();
29
- const next = tidy(areaRef.current?.value ?? "");
30
- return next === tidy(initial) ? { kind: "noop" } : { kind: "commit", payload: next };
31
- },
21
+ const { session, close } = useGridEditSession({
22
+ editorRef,
23
+ refuse: refuse && ((value) => refuse(value)),
24
+ onCommit: (payload) => onCommit(payload),
25
+ onCancel,
26
+ onTab,
27
+ onEnter,
32
28
  });
33
- const viaRef = useRef(null);
34
- const { open, close } = useAnchoredEditSession({
35
- editorRef: handleRef,
36
- onDone: (resolution) => {
37
- if (resolution.kind === "commit") {
38
- onCommit(resolution.payload);
39
- if (viaRef.current === "enter")
40
- onEnter?.();
41
- if (viaRef.current === "tab")
42
- onTab?.(false);
43
- if (viaRef.current === "shift-tab")
44
- onTab?.(true);
45
- }
46
- else
47
- onCancel();
48
- },
49
- });
50
- const closeVia = (reason) => {
51
- viaRef.current = reason;
52
- close(reason);
53
- };
54
- const attach = useCallback((el) => {
55
- areaRef.current = el;
56
- if (!el)
57
- return;
58
- el.focus({ preventScroll: true });
59
- el.setSelectionRange(el.value.length, el.value.length);
60
- grow(el);
61
- }, []);
62
- const onKeyDown = (event) => {
63
- event.stopPropagation();
64
- if (event.key === "Escape") {
65
- event.preventDefault();
66
- closeVia("escape");
67
- }
68
- else if (event.key === "Enter" && (event.metaKey || event.ctrlKey)) {
69
- event.preventDefault();
70
- closeVia("enter");
71
- }
72
- else if (event.key === "Tab") {
73
- event.preventDefault();
74
- closeVia(event.shiftKey ? "shift-tab" : "tab");
75
- }
76
- };
77
29
  const width = cell ? Math.min(MAX_W, Math.max(MIN_W, cell.width)) : MIN_W;
78
30
  const padY = cell ? Math.max(0, (cell.height - cell.lineHeight) / 2 - 1) : 8;
79
- return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(Popover, { open: open, onOpenChange: (next) => {
80
- if (!next)
81
- closeVia("outside");
82
- }, anchor: anchorRef, align: "start", sideOffset: cell ? -cell.height : 0, onEscape: () => closeVia("escape"), onOutsidePress: () => closeVia("outside"), initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: cx("z-90 rounded-sm p-0", readOnly ? "border-(color:--vk-border)" : "border-(color:--vk-border-brand)"), style: { width }, children: _jsx("textarea", { ref: attach, "data-grid-editor": true, "aria-label": messages({ key: readOnly ? "views.grid.value" : "views.grid.edit-value" }), defaultValue: seed ?? initial, readOnly: readOnly, rows: 1, onKeyDown: onKeyDown, onInput: (e) => grow(e.currentTarget), style: cell
31
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(EditorPanel, { session: session, title: title ?? "", anchor: anchorRef, align: "start", sideOffset: cell ? -cell.height : 0, initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: cx("z-90 rounded-sm p-0", readOnly ? "border-(color:--vk-border)" : "border-(color:--vk-border-brand)"), style: { width }, children: (surface) => (_jsx(TextEditor, { ref: editorRef, type: type ?? (markdown ? "rich_text" : "text"), multiline: paragraph, wraps: !paragraph, initial: initial, seed: seed, readOnly: readOnly, closeOnBlur: false, label: messages({ key: readOnly ? "views.grid.value" : "views.grid.edit-value" }), boxData: { "data-grid-editor": "" }, onRequestClose: close, style: cell && surface === "popover"
83
32
  ? {
84
33
  paddingLeft: cell.paddingX,
85
34
  paddingRight: cell.paddingX,
@@ -88,7 +37,7 @@ export function GridLongTextEditor({ initial, seed, readOnly = false, markdown =
88
37
  fontSize: cell.fontSize,
89
38
  lineHeight: `${cell.lineHeight}px`,
90
39
  }
91
- : undefined, className: cx("block w-full resize-none select-text bg-transparent text-(color:--vk-fg) outline-hidden", "overflow-y-auto overscroll-contain") }) })] }));
40
+ : undefined, className: cx("block w-full resize-none select-text bg-transparent text-(color:--vk-fg) outline-hidden", "overflow-y-auto overscroll-contain", surface === "sheet" && "px-4 py-2") })) })] }));
92
41
  }
93
42
  function measureCell(anchor) {
94
43
  const box = anchor.getBoundingClientRect();
@@ -118,10 +67,3 @@ function resolveLength(host, value) {
118
67
  host.removeChild(probe);
119
68
  return px;
120
69
  }
121
- function grow(el) {
122
- el.style.height = "auto";
123
- const style = getComputedStyle(el);
124
- const line = parseFloat(style.lineHeight) || 22;
125
- const pad = (parseFloat(style.paddingTop) || 0) + (parseFloat(style.paddingBottom) || 0);
126
- el.style.height = `${Math.min(el.scrollHeight, line * MAX_LINES + pad)}px`;
127
- }
@@ -1,12 +1,17 @@
1
+ import { type ReactNode } from "react";
1
2
  import type { NameValue } from "@viewkitjs/fields";
2
3
  /**
3
- * The GRID's host around the shared `NameEditor`. Anchored, like the select and
4
- * date editors: three boxes do not fit a cell, so they open in a panel under it
5
- * while the cell's own name stays on screen. `useAnchoredEditSession` owns the
6
- * one-answer guard and the exit gap; the core's own blur ends the session,
7
- * since a blur onto another box is not a close.
4
+ * The GRID's host around the shared `NameEditor`. Anchored, like the place and
5
+ * value list editors: three boxes do not fit a cell, so they open in a panel
6
+ * under it while the cell's own name stays on screen. The edit session owns the
7
+ * one-answer guard and the exit gap; the editor panel opens the popover on a
8
+ * desktop and the sheet on a phone, titled with the column's header, where the
9
+ * boxes wear the app's field frame. A blur onto another box is not a close, and
10
+ * in the sheet no blur is one (a tap on ✕ or ✓ blurs a box first).
8
11
  */
9
- export declare function GridNameEditor({ initial, seed, allowEmpty, onCommit, onCancel, onTab, onEnter, }: {
12
+ export declare function GridNameEditor({ title, initial, seed, allowEmpty, onCommit, onCancel, onTab, onEnter, }: {
13
+ /** The field's name: the sheet's title on a phone. */
14
+ title: ReactNode;
10
15
  initial: NameValue | null;
11
16
  /** Type-to-replace: the character that opened this editor replaces the given box. */
12
17
  seed?: string;
@@ -1,36 +1,21 @@
1
1
  "use client";
2
2
  import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useRef } from "react";
4
- import { useAnchoredEditSession } from "../../editors/edit-session.js";
4
+ import { EditorPanel } from "../../editors/EditorPanel.js";
5
5
  import { NameEditor } from "../../editors/NameEditor.js";
6
- import { useViews } from "../../provider/context.js";
7
- export function GridNameEditor({ initial, seed, allowEmpty = false, onCommit, onCancel, onTab, onEnter, }) {
8
- const { Popover } = useViews().components;
6
+ import { useGridEditSession } from "./grid-edit-session.js";
7
+ export function GridNameEditor({ title, initial, seed, allowEmpty = false, onCommit, onCancel, onTab, onEnter, }) {
9
8
  const anchorRef = useRef(null);
10
9
  const editorRef = useRef(null);
11
- const viaRef = useRef(null);
12
- const { open, close } = useAnchoredEditSession({
10
+ const { session, close } = useGridEditSession({
13
11
  editorRef,
14
- onDone: (resolution) => {
15
- if (resolution.kind === "commit") {
16
- onCommit(resolution.payload);
17
- if (viaRef.current === "enter")
18
- onEnter?.();
19
- if (viaRef.current === "tab")
20
- onTab?.(false);
21
- if (viaRef.current === "shift-tab")
22
- onTab?.(true);
23
- }
24
- else
25
- onCancel();
26
- },
12
+ onCommit: (payload) => onCommit(payload),
13
+ onCancel,
14
+ onTab,
15
+ onEnter,
27
16
  });
28
- const closeVia = (reason) => {
29
- viaRef.current = reason;
30
- close(reason);
31
- };
32
- return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(Popover, { open: open, onOpenChange: (next) => {
33
- if (!next)
34
- closeVia("outside");
35
- }, anchor: anchorRef, align: "start", sideOffset: 4, onEscape: () => closeVia("escape"), onOutsidePress: () => closeVia("outside"), initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-80 p-2", children: _jsx(NameEditor, { ref: editorRef, initial: initial, seed: seed, allowEmpty: allowEmpty, onRequestClose: closeVia }) })] }));
17
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, align: "start", sideOffset: 4, initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-80 p-2", children: (surface) => {
18
+ const editor = (_jsx(NameEditor, { ref: editorRef, initial: initial, seed: seed, allowEmpty: allowEmpty, chrome: surface === "sheet" ? "field" : "bare", onRequestClose: close }));
19
+ return surface === "sheet" ? _jsx("div", { className: "px-4 pb-4", children: editor }) : editor;
20
+ } })] }));
36
21
  }
@@ -1,16 +1,22 @@
1
+ import { type ReactNode } from "react";
1
2
  import type { DurationUnit } from "@viewkitjs/fields/query";
2
3
  import type { GridNumberEditValue } from "../core/edit-values.js";
3
4
  /**
4
5
  * The GRID's host around the shared `NumberEditor` (`@viewkitjs/views/editors/number`) —
5
6
  * the typed field and its unit chip are one component across every surface;
6
- * this host owns only the grid's mechanics: WHICH close happened, the write,
7
- * and the focus move that follows it.
7
+ * the edit session owns the one-answer guard, and the editor panel decides where
8
+ * it opens. This host owns the grid's part: the write, and the focus move that
9
+ * follows it.
8
10
  *
9
- * No exit gap, unlike the anchored editors: this one is INLINE — it replaces
10
- * the cell's content rather than opening a popover over it, so there is no
11
- * animation to play out and the commit lands at once, before the focus moves.
11
+ * On a desktop it is INLINE — it replaces the cell's content rather than opening
12
+ * a panel over it, so there is no animation to play out and the commit lands at
13
+ * once, before the focus moves: the order undo depends on. On a phone it opens in
14
+ * the sheet (a cell is too small to type into under a finger), and the answer
15
+ * waits for the sheet to slide away.
12
16
  */
13
- export declare function GridNumberEditor({ initial, seed, unit, unitOptions, decimals, durationUnit, allowEmpty, unitLeft, onCommit, onCancel, onTab, onEnter, }: {
17
+ export declare function GridNumberEditor({ title, initial, seed, unit, unitOptions, code, decimals, durationUnit, allowEmpty, unitLeft, conversion, onCommit, onCancel, onTab, onEnter, refuse, }: {
18
+ /** The field's name: the sheet's title on a phone. */
19
+ title: ReactNode;
14
20
  /** Signed raw value (e.g. -47.50 for an "out" transaction in its own currency). */
15
21
  initial: number;
16
22
  /** Type-to-replace: the character that opened this editor. */
@@ -19,6 +25,8 @@ export declare function GridNumberEditor({ initial, seed, unit, unitOptions, dec
19
25
  unit?: string;
20
26
  /** Selectable units — presence makes the chip a picker. */
21
27
  unitOptions?: string[];
28
+ /** A fixed currency's code, drawn beside the amount (never committed). */
29
+ code?: string;
22
30
  /** Rounding + initial formatting precision. */
23
31
  decimals?: number;
24
32
  /** A duration column's STORED unit — the core edits it as human text. */
@@ -27,9 +35,15 @@ export declare function GridNumberEditor({ initial, seed, unit, unitOptions, dec
27
35
  /** Right-aligned columns put the chip on the LEFT so the number stays flush
28
36
  * with the column's right edge. */
29
37
  unitLeft?: boolean;
38
+ /** The figure the cell showed, when it showed the row's amount converted into another currency: named under
39
+ * the editor, which opens on the row's own amount. */
40
+ conversion?: ReactNode;
30
41
  onCommit: (payload: GridNumberEditValue) => void;
31
42
  onCancel: () => void;
32
43
  onTab?: (backwards: boolean) => void;
33
44
  /** Commit happened via Enter — advance one row down (Sheets). */
34
45
  onEnter?: () => void;
46
+ /** The grid's judgement of a value before it is written: its reason when it would refuse it.
47
+ * A refused value keeps the editor open with that reason. */
48
+ refuse?: (value: GridNumberEditValue) => string | null;
35
49
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,25 +1,51 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
3
- import { useRef } from "react";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useCallback, useLayoutEffect, useRef } from "react";
4
4
  import { NumberEditor } from "../../editors/NumberEditor.js";
5
- export function GridNumberEditor({ initial, seed, unit, unitOptions, decimals = 2, durationUnit, allowEmpty = false, unitLeft = false, onCommit, onCancel, onTab, onEnter, }) {
5
+ import { EditorPanel } from "../../editors/EditorPanel.js";
6
+ import { ConversionLine } from "../../display/converted.js";
7
+ import { useKeepInside } from "../../editors/keep-inside.js";
8
+ import { cx } from "../../internal/cx.js";
9
+ import { GRID_GROUND } from "./grid-styles.js";
10
+ import { GridRefusal, UNDER_CELL_CLASS, useGridEditSession } from "./grid-edit-session.js";
11
+ export function GridNumberEditor({ title, initial, seed, unit, unitOptions, code, decimals = 2, durationUnit, allowEmpty = false, unitLeft = false, conversion, onCommit, onCancel, onTab, onEnter, refuse, }) {
6
12
  const editorRef = useRef(null);
7
- const closedRef = useRef(false);
8
- const close = (reason) => {
9
- if (closedRef.current)
13
+ const anchorRef = useRef(null);
14
+ const { session, close } = useGridEditSession({
15
+ editorRef,
16
+ inPlace: true,
17
+ refuse: refuse && ((value) => refuse(value)),
18
+ onCommit: (payload) => onCommit(payload),
19
+ onCancel,
20
+ onTab,
21
+ onEnter,
22
+ });
23
+ const editor = (_jsx(NumberEditor, { ref: editorRef, initial: initial, seed: seed, unit: unit, unitOptions: unitOptions, code: code, decimals: decimals, durationUnit: durationUnit, allowEmpty: allowEmpty, unitLeft: unitLeft, onRequestClose: close }));
24
+ return (_jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, inPlace: true, sheetOnPhone: true, children: (surface) => surface === "sheet" ? (_jsxs("div", { className: "px-2 pb-3", children: [_jsx("div", { className: "flex h-10 min-w-0 items-center rounded-md border border-(color:--vk-border) px-2", children: editor }), conversion ? _jsx(ConversionLine, { figure: conversion, className: "pt-1.5" }) : null] })) : (_jsxs("span", { "data-slot": "vk-grid-editor", className: cx("relative flex h-full w-full min-w-0", unitLeft && "justify-end"), children: [_jsx(FittedBox, { boxRef: anchorRef, children: editor }), _jsx(GridRefusal, { reason: session.refusal }), conversion && !session.refusal ? _jsx(UnderCellConversion, { figure: conversion }) : null] })) }));
25
+ }
26
+ const FITTED_MAX_PX = 320;
27
+ function FittedBox({ boxRef, children }) {
28
+ const fit = useCallback(() => {
29
+ const box = boxRef.current;
30
+ const input = box?.querySelector("input");
31
+ if (!box || !input)
10
32
  return;
11
- closedRef.current = true;
12
- const resolution = editorRef.current?.resolveClose(reason) ?? { kind: "noop" };
13
- if (resolution.kind === "commit")
14
- onCommit(resolution.payload);
15
- else
16
- onCancel();
17
- if (reason === "enter")
18
- onEnter?.();
19
- if (reason === "tab")
20
- onTab?.(false);
21
- if (reason === "shift-tab")
22
- onTab?.(true);
23
- };
24
- return (_jsx("span", { "data-slot": "vk-grid-editor", className: "flex h-full w-full min-w-0", children: _jsx(NumberEditor, { ref: editorRef, initial: initial, seed: seed, unit: unit, unitOptions: unitOptions, decimals: decimals, durationUnit: durationUnit, allowEmpty: allowEmpty, unitLeft: unitLeft, onRequestClose: close }) }));
33
+ box.style.minWidth = "";
34
+ const over = input.scrollWidth - input.clientWidth;
35
+ const width = over > 0 ? Math.min(box.offsetWidth + over + 1, FITTED_MAX_PX) : 0;
36
+ if (width > box.offsetWidth) {
37
+ box.style.minWidth = `${width}px`;
38
+ box.dataset.grown = "";
39
+ }
40
+ else {
41
+ delete box.dataset.grown;
42
+ }
43
+ }, [boxRef]);
44
+ useLayoutEffect(fit, [fit]);
45
+ return (_jsxs("span", { ref: boxRef, onInput: fit, className: "group/fitted relative flex h-full w-full min-w-0 shrink-0 data-grown:z-2", children: [_jsx("span", { "aria-hidden": true, className: cx("pointer-events-none absolute inset-y-0 -inset-x-(--vk-px) -z-1 hidden rounded-sm border border-(color:--vk-border-brand) shadow-lg shadow-black/20 group-data-grown/fitted:block dark:shadow-black/50", GRID_GROUND) }), children] }));
46
+ }
47
+ function UnderCellConversion({ figure }) {
48
+ const ref = useRef(null);
49
+ useKeepInside(ref);
50
+ return (_jsx("span", { ref: ref, className: UNDER_CELL_CLASS, children: _jsx(ConversionLine, { figure: figure }) }));
25
51
  }
@@ -0,0 +1,26 @@
1
+ import { type ReactNode } from "react";
2
+ import type { FieldDefOf, LocationValue } from "@viewkitjs/fields";
3
+ /**
4
+ * The GRID's host around the shared `LocationEditor`. Anchored, like the name
5
+ * and value list editors: a country and its parts do not fit a cell, so they
6
+ * open in a panel under it while the cell's own place stays on screen. The edit
7
+ * session owns the one-answer guard and the exit gap; the editor panel opens the
8
+ * popover on a desktop and the sheet on a phone, titled with the column's
9
+ * header. An emptied place always reaches `refuse`, so a field that can't be
10
+ * emptied says so in the editor rather than closing on nothing. No seed: a key
11
+ * typed on a place cell opens the place as it is.
12
+ */
13
+ export declare function GridPlaceEditor({ field, title, initial, refuse, onCommit, onCancel, onTab, onEnter, }: {
14
+ field: FieldDefOf<"location">;
15
+ /** The field's name: the sheet's title on a phone. */
16
+ title: ReactNode;
17
+ initial: LocationValue | null;
18
+ /** The grid's judgement of a place before it is written, an emptied one (`null`) included: its
19
+ * reason when it would refuse it. A refused place keeps the editor open with that reason. */
20
+ refuse?: (place: LocationValue | null) => string | null;
21
+ onCommit: (place: LocationValue | null) => void;
22
+ onCancel: () => void;
23
+ onTab?: (backwards: boolean) => void;
24
+ /** Commit happened via Enter — advance one row down. */
25
+ onEnter?: () => void;
26
+ }): import("react/jsx-runtime").JSX.Element;
@@ -0,0 +1,22 @@
1
+ "use client";
2
+ import { jsx as _jsx, Fragment as _Fragment, jsxs as _jsxs } from "react/jsx-runtime";
3
+ import { useRef } from "react";
4
+ import { EditorPanel } from "../../editors/EditorPanel.js";
5
+ import { LocationEditor } from "../../editors/LocationEditor.js";
6
+ import { useGridEditSession } from "./grid-edit-session.js";
7
+ export function GridPlaceEditor({ field, title, initial, refuse, onCommit, onCancel, onTab, onEnter, }) {
8
+ const anchorRef = useRef(null);
9
+ const editorRef = useRef(null);
10
+ const { session, close } = useGridEditSession({
11
+ editorRef,
12
+ refuse: refuse && ((place) => refuse(place)),
13
+ onCommit: (place) => onCommit(place),
14
+ onCancel,
15
+ onTab,
16
+ onEnter,
17
+ });
18
+ return (_jsxs(_Fragment, { children: [_jsx("span", { ref: anchorRef, "aria-hidden": true, className: "pointer-events-none absolute inset-0" }), _jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, align: "start", sideOffset: 4, initialFocus: false, panelData: { "data-slot": "vk-grid-editor" }, onPanelClick: (e) => e.stopPropagation(), chrome: "menu", className: "z-90 w-96 p-2", children: (surface) => {
19
+ const editor = (_jsx(LocationEditor, { ref: editorRef, field: field, initial: initial, allowEmpty: true, onRequestClose: close }));
20
+ return surface === "sheet" ? _jsx("div", { className: "px-4 pb-4", children: editor }) : editor;
21
+ } })] }));
22
+ }
@@ -1,10 +1,15 @@
1
- import type { RangeValue } from "@viewkitjs/fields";
1
+ import { type ReactNode } from "react";
2
+ import type { RangePreset, RangeValue } from "@viewkitjs/fields";
2
3
  /**
3
- * The GRID's host around the shared `RangeEditor` — inline, like the number
4
- * host: the two boxes replace the cell's content, the write lands at once, and
5
- * only then does focus move.
4
+ * The GRID's host around the shared `RangeEditor` — like the number host: the
5
+ * edit session owns the one-answer guard and the editor panel decides where it
6
+ * opens. On a desktop the two boxes replace the cell's content, the write lands
7
+ * at once, and only then does focus move; on a phone they open in the sheet and
8
+ * the answer waits for the sheet to slide away.
6
9
  */
7
- export declare function GridRangeEditor({ initial, seed, decimals, allowEmpty, suffix, onCommit, onCancel, onTab, onEnter, }: {
10
+ export declare function GridRangeEditor({ title, initial, seed, decimals, allowEmpty, suffix, bands, onCommit, onCancel, onTab, onEnter, refuse, }: {
11
+ /** The field's name: the sheet's title on a phone. */
12
+ title: ReactNode;
8
13
  initial: RangeValue | null;
9
14
  /** Type-to-replace: the character that opened this editor replaces the low box. */
10
15
  seed?: string;
@@ -12,9 +17,14 @@ export declare function GridRangeEditor({ initial, seed, decimals, allowEmpty, s
12
17
  allowEmpty?: boolean;
13
18
  /** "%", a currency code — drawn after the high box. */
14
19
  suffix?: string;
20
+ /** The field's bands: a menu under the cell on the desktop, listed under the boxes in the sheet. */
21
+ bands?: readonly RangePreset[];
15
22
  onCommit: (payload: RangeValue) => void;
16
23
  onCancel: () => void;
17
24
  onTab?: (backwards: boolean) => void;
18
25
  /** Commit happened via Enter — advance one row down. */
19
26
  onEnter?: () => void;
27
+ /** The grid's judgement of a value before it is written: its reason when it would refuse it.
28
+ * A refused value keeps the editor open with that reason. */
29
+ refuse?: (value: RangeValue) => string | null;
20
30
  }): import("react/jsx-runtime").JSX.Element;
@@ -1,25 +1,21 @@
1
1
  "use client";
2
- import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
3
  import { useRef } from "react";
4
4
  import { RangeEditor } from "../../editors/RangeEditor.js";
5
- export function GridRangeEditor({ initial, seed, decimals = 0, allowEmpty = false, suffix, onCommit, onCancel, onTab, onEnter, }) {
5
+ import { EditorPanel } from "../../editors/EditorPanel.js";
6
+ import { GridRefusal, useGridEditSession } from "./grid-edit-session.js";
7
+ export function GridRangeEditor({ title, initial, seed, decimals = 0, allowEmpty = false, suffix, bands, onCommit, onCancel, onTab, onEnter, refuse, }) {
6
8
  const editorRef = useRef(null);
7
- const closedRef = useRef(false);
8
- const close = (reason) => {
9
- if (closedRef.current)
10
- return;
11
- closedRef.current = true;
12
- const resolution = editorRef.current?.resolveClose(reason) ?? { kind: "noop" };
13
- if (resolution.kind === "commit")
14
- onCommit(resolution.payload);
15
- else
16
- onCancel();
17
- if (reason === "enter")
18
- onEnter?.();
19
- if (reason === "tab")
20
- onTab?.(false);
21
- if (reason === "shift-tab")
22
- onTab?.(true);
23
- };
24
- return (_jsx("span", { "data-slot": "vk-grid-editor", className: "flex h-full w-full min-w-0", children: _jsx(RangeEditor, { ref: editorRef, initial: initial, seed: seed, decimals: decimals, allowEmpty: allowEmpty, suffix: suffix, onRequestClose: close }) }));
9
+ const anchorRef = useRef(null);
10
+ const { session, close } = useGridEditSession({
11
+ editorRef,
12
+ inPlace: true,
13
+ refuse: refuse && ((value) => refuse(value)),
14
+ onCommit: (payload) => onCommit(payload),
15
+ onCancel,
16
+ onTab,
17
+ onEnter,
18
+ });
19
+ const editor = (sheet) => (_jsx(RangeEditor, { ref: editorRef, initial: initial, seed: seed, decimals: decimals, allowEmpty: allowEmpty, suffix: suffix, bands: bands, bandsAt: sheet ? "below" : "popover", boxClassName: sheet ? "h-10 rounded-md border border-(color:--vk-border) px-2" : undefined, onRequestClose: close }));
20
+ return (_jsx(EditorPanel, { session: session, title: title, anchor: anchorRef, inPlace: true, sheetOnPhone: true, children: (surface) => surface === "sheet" ? (_jsx("div", { className: "px-2 pb-3", children: editor(true) })) : (_jsxs("span", { ref: anchorRef, "data-slot": "vk-grid-editor", className: "relative flex h-full w-full min-w-0", children: [editor(false), _jsx(GridRefusal, { reason: session.refusal })] })) }));
25
21
  }
@@ -1,21 +1,45 @@
1
- import type { RelationSource } from "../../fields/relation-source-types.js";
2
- /**
3
- * The GRID's host around the shared `RelationEditor` (`@viewkitjs/views/editors/relation`)
4
- * — the search-and-pick panel is one component across every surface; this host
5
- * owns only the grid's mechanics: anchor to the cell rect, open on mount, WHICH
6
- * close happened, the exit animation gap, and the write.
7
- *
8
- * The candidate list is the column's, not the table's: every subscription you
9
- * could link to, including ones no row currently points at — which is the whole
10
- * difference from the Filter panel's list, and the reason a table of ten rows
11
- * can still move a transaction onto any of seventy subscriptions.
12
- */
13
- export declare function GridRelationEditor({ candidates, current, clearable, onCommit, onCancel, }: {
1
+ import { type ReactNode } from "react";
2
+ import type { RelationDraftLink } from "@viewkitjs/fields";
3
+ import { type RelationSetItem } from "../../editors/RelationEditor.js";
4
+ import type { RelationCellCreate, RelationSource } from "../../fields/relation-source-types.js";
5
+ export declare function GridRelationEditor({ title, candidates, current, clearable, seed, create, refuse, onCommit, onLink, onCancel, }: {
6
+ /** The field's name: the sheet's title on a phone. */
7
+ title: ReactNode;
14
8
  candidates: RelationSource;
15
9
  /** The linked id, or null when the cell is empty. */
16
10
  current: string | null;
17
11
  /** Offer "None" — only when the column says the link is optional. */
18
12
  clearable: boolean;
19
- onCommit: (id: string | null) => void;
13
+ /** The letter typed on the cell that opened the picker: its search starts from it. */
14
+ seed?: string;
15
+ /** The app's create row, from the column. */
16
+ create?: RelationCellCreate;
17
+ /** The pick, with its kind where the candidate named one. */
18
+ onCommit: (id: string | null, kind?: string) => void;
19
+ /** The record the app's form created, to link to the cell once the editor is gone. */
20
+ onLink?: (id: string, kind?: string) => void;
21
+ onCancel: () => void;
22
+ /** The grid's judgement of a value before it is written: its reason when it would refuse it.
23
+ * A refused value keeps the editor open with that reason. */
24
+ refuse?: (value: string | null, kind?: string) => string | null;
25
+ }): import("react/jsx-runtime").JSX.Element;
26
+ /**
27
+ * The grid's host for a relation holding several records: the set is edited with the list open and
28
+ * leaves as one change, as pick many does — Tab and Shift-Tab save it and move on.
29
+ */
30
+ export declare function GridRelationSetEditor({ title, candidates, current, lead, seed, create, refuse, onCommit, onLink, onCancel, onTab, }: {
31
+ title: ReactNode;
32
+ candidates: RelationSource;
33
+ /** The linked records, in their stored order, with what each row shows. */
34
+ current: readonly RelationSetItem[];
35
+ /** The field leads by a flag. */
36
+ lead: boolean;
37
+ seed?: string;
38
+ create?: RelationCellCreate;
39
+ onCommit: (links: RelationDraftLink[]) => void;
40
+ /** The record the app's form created, added to the set saved at close (or the set as it opened). */
41
+ onLink?: (base: RelationDraftLink[], added: RelationDraftLink) => void;
20
42
  onCancel: () => void;
43
+ onTab?: (backwards: boolean) => void;
44
+ refuse?: (links: RelationDraftLink[]) => string | null;
21
45
  }): import("react/jsx-runtime").JSX.Element;