viewkitjs 0.39.0 → 0.40.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 (179) hide show
  1. package/CHANGELOG.md +65 -0
  2. package/MIGRATION.md +25 -0
  3. package/fields/dist/derived.d.ts +7 -0
  4. package/fields/dist/derived.js +4 -0
  5. package/fields/dist/index.d.ts +1 -1
  6. package/fields/dist/index.js +1 -1
  7. package/fields/dist/messages.d.ts +5 -1
  8. package/fields/dist/messages.js +3 -0
  9. package/fields/dist/query/evaluate.d.ts +7 -1
  10. package/fields/dist/query/evaluate.js +8 -5
  11. package/fields/dist/query/filter.d.ts +7 -0
  12. package/fields/dist/query/filter.js +7 -1
  13. package/fields/dist/query/kit.d.ts +3 -2
  14. package/fields/dist/query/kit.js +1 -1
  15. package/fields/dist/query/layer.d.ts +6 -0
  16. package/fields/dist/query/layer.js +3 -0
  17. package/fields/dist/query/number.d.ts +3 -2
  18. package/fields/dist/query/number.js +5 -3
  19. package/fields/dist/query/read-rule.d.ts +1 -1
  20. package/fields/dist/query/read-rule.js +3 -0
  21. package/fields/docs/guides/queries.md +28 -24
  22. package/fields/docs/reference/fields.md +1 -0
  23. package/fields/docs/reference/query.md +6 -4
  24. package/package.json +2 -4
  25. package/postgres/dist/check.js +3 -1
  26. package/postgres/dist/definitions/storage.d.ts +3 -1
  27. package/postgres/dist/definitions/storage.js +3 -1
  28. package/postgres/dist/definitions/stored.js +13 -2
  29. package/postgres/dist/map.d.ts +5 -1
  30. package/postgres/dist/map.js +4 -0
  31. package/postgres/dist/records.js +6 -1
  32. package/postgres/docs/guides/definitions.md +1 -1
  33. package/postgres/docs/guides/field-map.md +2 -2
  34. package/postgres/docs/reference/postgres.md +1 -1
  35. package/views/dist/contract.d.ts +20 -2
  36. package/views/dist/contract.js +27 -0
  37. package/views/dist/controls/avatar.css +1 -1
  38. package/views/dist/controls/customize/map-customize-body.js +1 -1
  39. package/views/dist/controls/field/field.d.ts +2 -14
  40. package/views/dist/controls/field/field.js +4 -9
  41. package/views/dist/controls/filter-editor/filter-editor.d.ts +2 -0
  42. package/views/dist/controls/filter-editor/filter-editor.js +5 -2
  43. package/views/dist/controls/filter-editor/how.d.ts +8 -0
  44. package/views/dist/controls/filter-editor/map-filter-body.d.ts +4 -2
  45. package/views/dist/controls/filter-editor/map-filter-body.js +17 -8
  46. package/views/dist/controls/filter-editor/map-rules.d.ts +4 -3
  47. package/views/dist/controls/filter-editor/map-rules.js +5 -2
  48. package/views/dist/controls/filter-editor/parts.d.ts +14 -1
  49. package/views/dist/controls/filter-editor/parts.js +14 -0
  50. package/views/dist/controls/filter-editor.css +4 -1
  51. package/views/dist/controls/index.d.ts +0 -3
  52. package/views/dist/controls/index.js +0 -3
  53. package/views/dist/controls/input.css +1 -1
  54. package/views/dist/controls/menu-list.css +1 -1
  55. package/views/dist/controls/picker/looks.d.ts +1 -1
  56. package/views/dist/controls/picker.css +2 -2
  57. package/views/dist/controls/press.css +0 -1
  58. package/views/dist/controls/radio/radio.d.ts +1 -1
  59. package/views/dist/controls/radio/radio.js +1 -16
  60. package/views/dist/controls/sheet/bottom-sheet.d.ts +2 -2
  61. package/views/dist/controls/sheet/bottom-sheet.js +31 -24
  62. package/views/dist/controls/text-editor.css +5 -3
  63. package/views/dist/controls/tokens.js +0 -6
  64. package/views/dist/controls/toolbar/toolbar.js +2 -2
  65. package/views/dist/field-row/editors/RowTextEditor.js +4 -1
  66. package/views/dist/filters/duration-bound.d.ts +7 -0
  67. package/views/dist/filters/duration-bound.js +9 -0
  68. package/views/dist/filters/filter-model.d.ts +4 -0
  69. package/views/dist/filters/number-refused.d.ts +8 -0
  70. package/views/dist/filters/number-refused.js +4 -0
  71. package/views/dist/grid/chrome/grid-table-props.d.ts +4 -1
  72. package/views/dist/grid/chrome/useGridTableInteractionModel.js +12 -2
  73. package/views/dist/grid/core/clipboard-model.js +42 -8
  74. package/views/dist/grid/core/commit-model.d.ts +3 -0
  75. package/views/dist/grid/core/editing-controller.d.ts +29 -1
  76. package/views/dist/grid/core/editing-controller.js +142 -12
  77. package/views/dist/grid/core/pending-reconciliation.d.ts +14 -0
  78. package/views/dist/grid/core/pending-reconciliation.js +20 -8
  79. package/views/dist/grid/core/save-path.d.ts +4 -2
  80. package/views/dist/grid/core/save-path.js +1 -1
  81. package/views/dist/grid/core/spreadsheet-operations.js +43 -5
  82. package/views/dist/grid/core/useGridEditing.d.ts +5 -1
  83. package/views/dist/grid/core/useGridEditing.js +4 -4
  84. package/views/dist/grid/core/written-alongside.d.ts +16 -0
  85. package/views/dist/grid/core/written-alongside.js +30 -0
  86. package/views/dist/grid/grid.css +1 -1
  87. package/views/dist/grid/index.d.ts +1 -1
  88. package/views/dist/grid/looks.d.ts +2 -2
  89. package/views/dist/internal/before-paint.d.ts +5 -0
  90. package/views/dist/internal/before-paint.js +17 -0
  91. package/views/dist/internal/field-rows.d.ts +0 -8
  92. package/views/dist/internal/field-rows.js +1 -3
  93. package/views/dist/list/bar-keys.d.ts +3 -0
  94. package/views/dist/list/bar-keys.js +1 -0
  95. package/views/dist/list/buttons/clear-save.js +6 -2
  96. package/views/dist/list/buttons/new.d.ts +1 -1
  97. package/views/dist/list/buttons/new.js +14 -2
  98. package/views/dist/list/buttons/shared.d.ts +7 -1
  99. package/views/dist/list/buttons/shared.js +8 -2
  100. package/views/dist/list/buttons/views.js +6 -4
  101. package/views/dist/list/edits.d.ts +3 -1
  102. package/views/dist/list/layer.d.ts +13 -3
  103. package/views/dist/list/layer.js +13 -3
  104. package/views/dist/list/line.d.ts +5 -2
  105. package/views/dist/list/line.js +11 -3
  106. package/views/dist/list/list.d.ts +7 -1
  107. package/views/dist/list/list.js +2 -2
  108. package/views/dist/list/panels/filter-bar.d.ts +1 -1
  109. package/views/dist/list/panels/filter-bar.js +9 -3
  110. package/views/dist/list/panels/shared.d.ts +3 -2
  111. package/views/dist/list/panels/shared.js +5 -2
  112. package/views/dist/list/root-base.d.ts +2 -1
  113. package/views/dist/list/root-base.js +5 -3
  114. package/views/dist/list/root.d.ts +1 -1
  115. package/views/dist/list/store.d.ts +10 -0
  116. package/views/dist/list/store.js +8 -1
  117. package/views/dist/list/toolbar-model.d.ts +4 -0
  118. package/views/dist/list/toolbar-model.js +19 -1
  119. package/views/dist/list/toolbar.js +2 -1
  120. package/views/dist/list/views.d.ts +1 -1
  121. package/views/dist/list/views.js +4 -1
  122. package/views/dist/looks/index.d.ts +0 -1
  123. package/views/dist/looks/index.js +0 -1
  124. package/views/dist/looks/looks.d.ts +1 -1
  125. package/views/dist/looks/pieces.js +0 -2
  126. package/views/dist/model/column-filters.js +10 -3
  127. package/views/dist/model/view-rules.js +1 -0
  128. package/views/dist/panels/filter/NumberFilterBody.js +6 -8
  129. package/views/dist/panels/labels.js +7 -2
  130. package/views/dist/panels/model.d.ts +3 -0
  131. package/views/dist/panels/react/filter/filter-body.js +5 -1
  132. package/views/dist/panels/react/toolbar/ToolbarBarSorts.js +28 -1
  133. package/views/dist/panels/react/toolbar/ToolbarButton.d.ts +1 -1
  134. package/views/dist/panels/react/toolbar/ToolbarButton.js +5 -3
  135. package/views/dist/panels/react/toolbar/context.d.ts +4 -0
  136. package/views/dist/panels/react/toolbar/context.js +1 -0
  137. package/views/dist/panels/react/toolbar/use-give-way.js +2 -2
  138. package/views/dist/panels/settings/filter-groups.js +5 -0
  139. package/views/dist/panels/settings/input.d.ts +11 -0
  140. package/views/dist/panels/settings/layout.js +26 -0
  141. package/views/dist/panels/settings/person.d.ts +15 -0
  142. package/views/dist/panels/settings/person.js +6 -0
  143. package/views/dist/panels/toolbar/page-resets.js +14 -3
  144. package/views/dist/provider/components.d.ts +12 -3
  145. package/views/dist/styles.css +16 -260
  146. package/views/dist/styles.unlayered.css +16 -260
  147. package/views/docs/contract.md +9 -7
  148. package/views/docs/controls/field.md +1 -1
  149. package/views/docs/guides/looks.md +1 -1
  150. package/views/docs/guides/the-grid.md +4 -2
  151. package/views/docs/guides/toolbar-parts.md +337 -0
  152. package/views/docs/index.md +4 -0
  153. package/views/docs/reference/controls.md +3 -41
  154. package/views/docs/reference/grid.md +4 -3
  155. package/views/docs/reference/list.md +24 -13
  156. package/views/docs/reference/looks.md +12 -15
  157. package/views/docs/reference/panels.md +1 -1
  158. package/views/docs/reference/react.md +3 -3
  159. package/views/docs/reference/views.md +1 -1
  160. package/views/dist/controls/setting-row/looks.d.ts +0 -10
  161. package/views/dist/controls/setting-row/looks.js +0 -22
  162. package/views/dist/controls/setting-row/setting-row.d.ts +0 -102
  163. package/views/dist/controls/setting-row/setting-row.js +0 -135
  164. package/views/dist/controls/setting-row/tokens.d.ts +0 -156
  165. package/views/dist/controls/setting-row/tokens.js +0 -41
  166. package/views/dist/controls/setting-row.css +0 -216
  167. package/views/dist/controls/switch-row/switch-row.d.ts +0 -1
  168. package/views/dist/controls/switch-row/switch-row.js +0 -1
  169. package/views/dist/controls/switch-row/tokens.d.ts +0 -39
  170. package/views/dist/controls/switch-row/tokens.js +0 -12
  171. package/views/dist/controls/switch-row.css +0 -35
  172. package/views/dist/controls/tag-field/tag-field.d.ts +0 -24
  173. package/views/dist/controls/tag-field/tag-field.js +0 -25
  174. package/views/dist/controls/tag-field/tokens.d.ts +0 -23
  175. package/views/dist/controls/tag-field/tokens.js +0 -8
  176. package/views/dist/controls/tag-field.css +0 -32
  177. package/views/docs/controls/setting-row.md +0 -44
  178. package/views/docs/controls/switch-row.md +0 -15
  179. package/views/docs/controls/tag-field.md +0 -11
@@ -116,6 +116,10 @@ export type FilterConfigNumber = FilterConfigBase & {
116
116
  * the cell holds.
117
117
  */
118
118
  durationUnit?: "ms" | "s";
119
+ /** Why a rule here that compares a number filters nothing, in words: the column's amounts are in several
120
+ * currencies. Its operators stay offered; a rule that compares one reads this as its summary and under its box,
121
+ * and Is empty / Is not empty filter as ever (`numberRuleRefused`). Absent: every rule filters. */
122
+ refused?: string;
119
123
  };
120
124
  /** A date dimension: absolute operators, a range, or a relative window. */
121
125
  export type FilterConfigDate = FilterConfigBase & {
@@ -0,0 +1,8 @@
1
+ import { type NumberFilterOperator } from "viewkitjs/fields/query";
2
+ /** Whether a number filter's rule is refused: its column says why (`refused`) and the rule compares a number. */
3
+ export declare function numberRuleRefused(filter: {
4
+ refused?: string;
5
+ value: {
6
+ operator: NumberFilterOperator;
7
+ } | null;
8
+ }): boolean;
@@ -0,0 +1,4 @@
1
+ import { comparesNumber } from "viewkitjs/fields/query";
2
+ export function numberRuleRefused(filter) {
3
+ return filter.refused !== undefined && !!filter.value && comparesNumber(filter.value.operator);
4
+ }
@@ -14,7 +14,7 @@ import type { PercentDisplay } from "viewkitjs/fields";
14
14
  import type { ListGroupSummaryPart } from "../../model/preferences.js";
15
15
  import type { ListRowIconAccessor } from "../../model/row-icon.js";
16
16
  import type { GridRowOpenedFrom } from "../core/row-opened-from.js";
17
- import type { GridCellCommitFn, GridCellsCommitFn } from "../core/commit-model.js";
17
+ import type { GridCellCommitFn, GridCellValuesFn, GridCellsCommitFn } from "../core/commit-model.js";
18
18
  import type { GridGroupByState, GridSortState } from "./GridColumnMenu.js";
19
19
  import type { GridGroupSortOption } from "./GridGroupMenu.js";
20
20
  import type { GridGroupMenuPart } from "./grid-group-menu-parts.js";
@@ -278,6 +278,9 @@ export type GridTableProps<Row> = {
278
278
  scale?: number;
279
279
  onCellCommit?: GridCellCommitFn<Row>;
280
280
  onCellsCommit?: GridCellsCommitFn<Row>;
281
+ /** What a cell's change writes, as `gridSave` hands it (`cellValues`): every column it changes beside the edited one
282
+ * shows the new value as the save is sent, and rolls back with it. */
283
+ cellValues?: GridCellValuesFn<Row>;
281
284
  /** Per-user "Freeze identity columns" toggle: pins every column through the
282
285
  * title to the left edge while the rest scrolls under them. */
283
286
  freezeIdentity?: boolean;
@@ -5,6 +5,8 @@ import { useGridEditing } from "../core/useGridEditing.js";
5
5
  import { GridEditsSinkContext } from "../core/edits-sink.js";
6
6
  import { useGridRange } from "../core/useGridRange.js";
7
7
  import { gridRefusalSentence } from "../core/refusal-sentence.js";
8
+ import { gridWrittenAlongside } from "../core/written-alongside.js";
9
+ import { changedSinceEdit } from "../core/pending-reconciliation.js";
8
10
  import { columnEffectiveWritable, columnLabel, gridColumnLocked, gridEditRefusal, gridNormalizeWrite, } from "../../model/column-capabilities.js";
9
11
  import { gridPartWrite } from "../../model/part-write.js";
10
12
  import { foldPartEdits } from "../core/part-edits.js";
@@ -34,7 +36,16 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
34
36
  const columnById = useMemo(() => new Map([...columns, ...visibleColumns].map((column) => [column.id, column])), [columns, visibleColumns]);
35
37
  const partOfWhole = useCallback((wholeId) => [...columnById.values()].find((column) => column.partOf?.column === wholeId)?.partOf, [columnById]);
36
38
  const keepsSent = useCallback((columnId) => partOfWhole(columnId) != null, [partOfWhole]);
37
- const { focused: focusedCell, editing: editingCell, pendingByRow, pendingOf, settlementByRow, writeStateByRow, focusCell, clearFocus, dropFocus, startEdit, cancelEdit, closeEdit, commitEdit: commitEditRaw, commitBatch: commitBatchRaw, undo, redo, reconcile, canUndo: canUndoNow, canRedo: canRedoNow, saving: savingNow, hasInflight, pendingBaseline, sent, sentCells, forgetSent, isLastEdited, } = useGridEditing(props.onCellCommit, props.onCellsCommit, sayRefusal, keepsSent);
39
+ const editsSink = useContext(GridEditsSinkContext);
40
+ const more = useMemo(() => ({
41
+ alongside: gridWrittenAlongside([...columnById.values()], props.cellValues),
42
+ changedSince: (row, cell) => changedSinceEdit(columnById.get(cell.columnId), row, cell),
43
+ onChangedSince: () => {
44
+ editsSink?.changed();
45
+ ports.toast.warning(messages({ key: "views.grid.changed-since" }));
46
+ },
47
+ }), [columnById, props.cellValues, ports, messages, editsSink]);
48
+ const { focused: focusedCell, editing: editingCell, pendingByRow, pendingOf, settlementByRow, writeStateByRow, focusCell, clearFocus, dropFocus, startEdit, cancelEdit, closeEdit, commitEdit: commitEditRaw, commitBatch: commitBatchRaw, undo, redo, reconcile, canUndo: canUndoNow, canRedo: canRedoNow, saving: savingNow, hasInflight, pendingBaseline, sent, sentCells, forgetSent, isLastEdited, } = useGridEditing(props.onCellCommit, props.onCellsCommit, sayRefusal, keepsSent, more);
38
49
  const wholeStored = useCallback((rowId, wholeId, row) => {
39
50
  const part = partOfWhole(wholeId);
40
51
  const overlay = pendingOf(rowId);
@@ -295,7 +306,6 @@ export function useGridTableInteractionModel({ rootRef, props, rows, visibleRows
295
306
  finishFillRef.current = rangeActions.finishFill;
296
307
  }, [rangeActions.finishFill]);
297
308
  const editsState = useCallback(() => ({ saving: savingNow(), canUndo: canUndoNow(), canRedo: canRedoNow() }), [savingNow, canUndoNow, canRedoNow]);
298
- const editsSink = useContext(GridEditsSinkContext);
299
309
  useEffect(() => {
300
310
  editsSink?.changed();
301
311
  }, [editsSink, pendingByRow, writeStateByRow]);
@@ -79,7 +79,7 @@ function matchOption(col, text, value, offered) {
79
79
  .filter((option) => keys.includes(option.value))
80
80
  .map((option) => ({ key: option.value, label: optionLabelOf(col, option.value) }));
81
81
  const one = (found) => found.length === 0 ? undefined : found.length === 1 ? { key: found[0] } : { ambiguous: true };
82
- if (typeof value === "string" && keys.includes(value))
82
+ if (typeof value === "string" && keys.includes(value) && optionLabelOf(col, value) === text)
83
83
  return { key: value };
84
84
  const folded = text.toLowerCase();
85
85
  return (one(labelled.filter((option) => option.label === text).map((option) => option.key)) ??
@@ -87,6 +87,37 @@ function matchOption(col, text, value, offered) {
87
87
  one(labelled.filter((option) => option.label.toLowerCase() === folded).map((option) => option.key)) ??
88
88
  one(keys.filter((key) => key.toLowerCase() === folded)));
89
89
  }
90
+ function readOptionEntries(col, text, offered) {
91
+ const toKey = (entry) => {
92
+ const match = matchOption(col, entry, undefined, offered);
93
+ return match && "key" in match ? match.key : entry;
94
+ };
95
+ const whole = matchOption(col, text.trim(), undefined, offered);
96
+ if (whole && "key" in whole)
97
+ return [whole.key];
98
+ const keys = offered ?? (col.options ?? []).filter((option) => !option.archived).map((option) => option.value);
99
+ const labels = (col.options ?? [])
100
+ .filter((option) => keys.includes(option.value))
101
+ .map((option) => optionLabelOf(col, option.value))
102
+ .filter((label) => label !== "")
103
+ .sort((a, b) => b.length - a.length);
104
+ const entries = [];
105
+ let at = 0;
106
+ while (at < text.length) {
107
+ while (at < text.length && (text[at] === "," || /\s/.test(text[at])))
108
+ at++;
109
+ if (at >= text.length)
110
+ break;
111
+ const label = labels.find((each) => text.slice(at, at + each.length).toLowerCase() === each.toLowerCase() && /^\s*(,|$)/.test(text.slice(at + each.length)));
112
+ const comma = text.indexOf(",", at);
113
+ const end = label ? at + label.length : comma < 0 ? text.length : comma;
114
+ const entry = text.slice(at, end).trim();
115
+ if (entry)
116
+ entries.push(entry);
117
+ at = end;
118
+ }
119
+ return entries.map(toKey);
120
+ }
90
121
  export function parseTsvText(text) {
91
122
  const normalized = text.replace(/\r/g, "");
92
123
  if (normalized === "")
@@ -300,15 +331,18 @@ export function coercePaste(col, source, opts) {
300
331
  return { ok: true, next: matched.id, overlay };
301
332
  }
302
333
  case "list": {
303
- const pasted = Array.isArray(source.value)
334
+ const offeredKeys = opts.values ?? (col.options ?? []).filter((option) => !option.archived).map((option) => option.value);
335
+ const trusted = Array.isArray(source.value) &&
336
+ (!col.options?.length ||
337
+ (source.value.every((item) => typeof item !== "string" || offeredKeys.includes(item)) &&
338
+ cellCopyText(col, source.value) === source.text.trim()));
339
+ const single = typeof source.value === "string" ? matchOption(col, source.text.trim(), source.value, opts.values) : undefined;
340
+ const pasted = trusted
304
341
  ? source.value
305
342
  : col.options?.length
306
- ? source.text.split(",").map((raw, _index, entries) => {
307
- const entry = raw.trim();
308
- const value = entries.length === 1 ? source.value : undefined;
309
- const match = matchOption(col, entry, value, opts.values);
310
- return match && "key" in match ? match.key : entry;
311
- })
343
+ ? single && "key" in single
344
+ ? [single.key]
345
+ : readOptionEntries(col, source.text, opts.values)
312
346
  : source.text;
313
347
  const vetted = gridNormalizeWrite(col, pasted, opts.conventions, write);
314
348
  if (!vetted.ok)
@@ -63,6 +63,9 @@ export type GridCellsCommitFn<Row> = (edits: {
63
63
  value: unknown;
64
64
  context?: GridCommitContext;
65
65
  }[]) => Promise<void | GridCommitOutcome[]>;
66
+ /** One cell's change as the values its record's save sends (`gridSave`'s `values`, handed back as `cellValues`): the
67
+ * grid reads every other column over the row with them, and shows the ones they change as the save is sent. */
68
+ export type GridCellValuesFn<Row> = (row: Row, columnId: string, value: unknown, context: GridCommitContext) => Record<string, unknown>;
66
69
  /** A cell's key: its row and column ids as one JSON pair. It is read back whole (`gridCellFromKey`), never split at a
67
70
  * character, so no id can break it, whatever it holds. */
68
71
  export declare function gridCellKey(rowId: string, columnId: string): string;
@@ -1,7 +1,8 @@
1
1
  import { type GridCellCommitFn, type GridCellsCommitFn, type GridCommitRefusal } from "./commit-model.js";
2
2
  import type { GridCellPos } from "./coordinates.js";
3
- import { type GridCommitCell, type GridSettlementByRow } from "./editing-model.js";
3
+ import { type GridCommitCell, type GridEditCell, type GridSettlementByRow } from "./editing-model.js";
4
4
  import { type GridWriteStateByRow } from "./write-states.js";
5
+ import type { GridAlongside } from "./written-alongside.js";
5
6
  export type GridEditingCallbacks<Row> = {
6
7
  onCellCommit?: GridCellCommitFn<Row>;
7
8
  onCellsCommit?: GridCellsCommitFn<Row>;
@@ -11,6 +12,20 @@ export type GridEditingCallbacks<Row> = {
11
12
  /** Whether what a commit sends for a column's cells is kept for a part edit to build on (`sent`): the grid keeps
12
13
  * it only for a whole a part column builds on. Absent: every column. */
13
14
  keepsSent?: (columnId: string) => boolean;
15
+ /** The other columns a cell's save writes, with what each reads after it and before (`gridWrittenAlongside`): shown
16
+ * with the edit as it is sent, in flight with it, rolled back with it, kept until the rows show them. They carry no
17
+ * write state: a refusal is said on the edited cell. */
18
+ alongside?: GridAlongside<Row>;
19
+ /** Does the row in hand show a value in this edit's cell that is neither side of the edit: someone wrote it since?
20
+ * Asked as ⌘Z or ⌘⇧Z is pressed, only of the cells where nothing of the grid's own is still out (an overlay, a write,
21
+ * a waiting press), whose rows may lag behind it. A cell it says yes to is kept: the press leaves it as the rows show
22
+ * it and sends nothing for it, and it leaves the entry; an entry left with no cell leaves the history. */
23
+ changedSince?: (row: Row | undefined, cell: GridEditCell<Row>) => boolean;
24
+ /** Told once per press that kept any cell (`changedSince`), with those cells: the chrome says so. */
25
+ onChangedSince?: (cells: {
26
+ rowId: string;
27
+ columnId: string;
28
+ }[]) => void;
14
29
  };
15
30
  type ResolveRow<Row> = (rowId: string) => Row | undefined;
16
31
  /**
@@ -84,6 +99,12 @@ export declare class GridEditingController<Row> {
84
99
  /** A confirmed outcome that says what was `stored` lays it over the cell in place of what was
85
100
  * typed; a `requested` one keeps its overlay and marks it. Nothing else changes. */
86
101
  private settle;
102
+ /** The other columns a cell's save writes (`alongside`), as overlays of `revision` keyed by their cell, each with the
103
+ * cell's key it rides with: every one over a cell that draws an overlay now (an earlier save's, the rows not yet read
104
+ * again: this save owns the cell from here, so a refusal of the earlier one leaves its value standing), and every
105
+ * one whose value the row doesn't already read. None where the app wrote no `alongside`, or finding
106
+ * them throws; none over a cell the same write edits itself (`skip`). */
107
+ private alongsideFor;
87
108
  /** Is a write for this cell still in flight? Reconciliation asks, so it can
88
109
  * tell "the refetch hasn't caught up yet" apart from "the server disagrees". */
89
110
  hasInflight(rowId: string, columnId: string): boolean;
@@ -143,6 +164,13 @@ export declare class GridEditingController<Row> {
143
164
  private performBatch;
144
165
  private inflightFor;
145
166
  private enqueueApply;
167
+ /** Is anything of the grid's own still out on this cell: an overlay, a write, or a press that holds it? */
168
+ private ownWorkOn;
169
+ /** The cells of the entry about to be pressed that the rows show someone wrote since (`changedSince`) leave it, and
170
+ * the chrome is told once; an entry left empty leaves its stack, and the focus goes to the first cell it kept. True
171
+ * when nothing is left to press. Only a cell with an overlay is asked: one committed with none (a relation's id, a
172
+ * name's parts) holds a value no row reads back as equal. A callback that throws counts as no. */
173
+ private keepChangedSince;
146
174
  /** Takes a press's overlay off these cells where it still stands, putting back what it covered; a later press that
147
175
  * covered it covers what it covered instead. */
148
176
  private liftPress;
@@ -1,11 +1,20 @@
1
1
  import { gridCellKey, } from "./commit-model.js";
2
2
  import { applyGridPending, carryGridPutBack, createGridHistory, gridEditValue, gridOverlayValue, gridHistoryValue, gridKeptValue, gridRestoreShown, groupGridPendingByRow, groupGridPendingSettlement, keepGridPending, markGridPendingSettlement, planGridPendingAssignments, pressGridHistory, pruneGridEntry, pruneGridHistoryEntry, reconcileGridPending, recordGridHistory, revertGridHistoryPress, rollbackGridPending, } from "./editing-model.js";
3
+ import { sameListValue } from "viewkitjs/fields";
3
4
  import { setGridWriteStates } from "./write-states.js";
4
5
  import { refusalWords } from "./refusal-sentence.js";
5
6
  import { isPageClosing, onPageClose } from "../../internal/page-close.js";
6
7
  import { noteGridEdited } from "./undo-owner.js";
7
8
  import { markGridKeptValue } from "./value-equality.js";
8
9
  const confirmed = (outcome) => outcome ?? { status: "confirmed" };
10
+ const commitContext = () => (isPageClosing() ? { kind: "commit", closing: true } : { kind: "commit" });
11
+ const withAlongside = (keys, owners) => {
12
+ const all = new Set(keys);
13
+ for (const [key, owner] of owners)
14
+ if (keys.has(owner))
15
+ all.add(key);
16
+ return all;
17
+ };
9
18
  export class GridEditingController {
10
19
  callbacks;
11
20
  onPendingChange;
@@ -172,6 +181,27 @@ export class GridEditingController {
172
181
  if (next !== this.pending)
173
182
  this.publishPending(next);
174
183
  }
184
+ alongsideFor(row, rowId, columnId, value, context, revision, skip) {
185
+ const { alongside } = this.callbacks;
186
+ if (!alongside)
187
+ return [];
188
+ const owner = gridCellKey(rowId, columnId);
189
+ let written;
190
+ try {
191
+ written = alongside(row, columnId, value, context);
192
+ }
193
+ catch {
194
+ return [];
195
+ }
196
+ return written.flatMap((each) => {
197
+ const key = gridCellKey(rowId, each.columnId);
198
+ if (each.columnId === columnId || skip?.has(key))
199
+ return [];
200
+ if (!this.pending.has(key) && sameListValue(each.value, each.baseline))
201
+ return [];
202
+ return [{ assignment: { key, value: each.value, baseline: each.baseline, revision }, owner }];
203
+ });
204
+ }
175
205
  hasInflight(rowId, columnId) {
176
206
  const key = gridCellKey(rowId, columnId);
177
207
  return (this.inflight.get(key)?.size ?? 0) > 0 || this.unsentPressOn(key) != null;
@@ -352,14 +382,18 @@ export class GridEditingController {
352
382
  }
353
383
  });
354
384
  }
355
- perform(row, rowId, columnId, value, overlay, baseline, context = "commit", entryId) {
385
+ perform(row, rowId, columnId, value, overlay, baseline, context = "commit", entryId, alsoInflight = [], edited) {
356
386
  const { onCellCommit } = this.callbacks;
357
387
  if (!onCellCommit)
358
388
  return Promise.resolve({ status: "failed" });
359
389
  const key = gridCellKey(rowId, columnId);
360
390
  const sentToken = context === "commit" && entryId !== undefined ? this.noteSent({ rowId, columnId }, value, baseline, entryId) : null;
391
+ const revision = this.nextPendingRevision++;
392
+ const alongside = overlay
393
+ ? this.alongsideFor(row, rowId, columnId, value, commitContext(), revision, edited)
394
+ : [];
361
395
  const assignments = overlay
362
- ? [{ key, value: overlay.value, baseline: overlay.baseline, revision: this.nextPendingRevision++ }]
396
+ ? [{ key, value: overlay.value, baseline: overlay.baseline, revision }, ...alongside.map((each) => each.assignment)]
363
397
  : [];
364
398
  if (assignments.length > 0) {
365
399
  this.publishPending(applyGridPending(this.pending, assignments));
@@ -394,25 +428,40 @@ export class GridEditingController {
394
428
  this.settle([key], [result], assignments);
395
429
  return result;
396
430
  }, (error) => refuse({ status: "failed", error }));
397
- this.registerInflight([key], promise);
431
+ this.registerInflight([key, ...alongside.map((each) => each.assignment.key), ...alsoInflight], promise);
398
432
  this.trackWrite([{ rowId, columnId }], promise.then((result) => [result]));
399
433
  return promise;
400
434
  }
401
- performBatch(cells, side, context, entryId) {
435
+ performBatch(cells, side, context, entryId, alsoInflight = []) {
402
436
  if (cells.length === 0)
403
437
  return Promise.resolve([]);
404
438
  const { onCellsCommit } = this.callbacks;
405
439
  if (cells.length === 1 || !onCellsCommit) {
440
+ const edited = new Set(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
406
441
  return Promise.all(cells.map(({ row, cell }) => this.perform(row, cell.rowId, cell.columnId, context === "restore" ? gridHistoryValue(cell, side) : gridEditValue(cell, side), context === "restore" || !cell.overlay
407
442
  ? false
408
443
  : { value: gridOverlayValue(cell, side), baseline: gridOverlayValue(cell, side === "next" ? "prev" : "next") }, context === "restore"
409
444
  ? gridHistoryValue(cell, side === "next" ? "prev" : "next")
410
- : gridEditValue(cell, side === "next" ? "prev" : "next"), context, entryId)));
445
+ : gridEditValue(cell, side === "next" ? "prev" : "next"), context, entryId, alsoInflight, edited)));
411
446
  }
412
- const assignments = context === "restore"
413
- ? []
414
- : planGridPendingAssignments(cells, side, this.nextPendingRevision++);
447
+ const revision = this.nextPendingRevision++;
448
+ const planned = context === "restore" ? [] : planGridPendingAssignments(cells, side, revision);
415
449
  const keys = cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId));
450
+ const owners = new Map();
451
+ const alongside = new Map();
452
+ if (context === "commit") {
453
+ const edited = new Set(keys);
454
+ for (const { row, cell } of cells) {
455
+ if (!cell.overlay)
456
+ continue;
457
+ const value = gridEditValue(cell, side);
458
+ for (const { assignment, owner } of this.alongsideFor(row, cell.rowId, cell.columnId, value, commitContext(), revision, edited)) {
459
+ alongside.set(assignment.key, assignment);
460
+ owners.set(assignment.key, owner);
461
+ }
462
+ }
463
+ }
464
+ const assignments = [...planned, ...alongside.values()];
416
465
  const sentTokens = context === "commit" && entryId !== undefined
417
466
  ? cells.map(({ cell }) => this.noteSent(cell, gridEditValue(cell, side), gridEditValue(cell, side === "next" ? "prev" : "next"), entryId))
418
467
  : null;
@@ -449,7 +498,8 @@ export class GridEditingController {
449
498
  .filter((_, index) => results[index]?.status === "failed")
450
499
  .map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
451
500
  if (failedKeys.size > 0) {
452
- const failed = assignments.filter((assignment) => failedKeys.has(assignment.key));
501
+ const failedAll = withAlongside(failedKeys, owners);
502
+ const failed = assignments.filter((assignment) => failedAll.has(assignment.key));
453
503
  this.publishPending(rollbackGridPending(this.pending, failed));
454
504
  this.reviseCovered(failed, "drop");
455
505
  }
@@ -471,7 +521,8 @@ export class GridEditingController {
471
521
  .filter((_, index) => carried[index]?.status === "failed")
472
522
  .map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
473
523
  if (failedKeys.size > 0) {
474
- const failed = assignments.filter((assignment) => failedKeys.has(assignment.key));
524
+ const failedAll = withAlongside(failedKeys, owners);
525
+ const failed = assignments.filter((assignment) => failedAll.has(assignment.key));
475
526
  this.publishPending(rollbackGridPending(this.pending, failed));
476
527
  this.reviseCovered(failed, "drop");
477
528
  }
@@ -485,7 +536,7 @@ export class GridEditingController {
485
536
  }
486
537
  return cells.map(() => ({ status: "failed", error }));
487
538
  });
488
- this.registerInflight(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)), promise);
539
+ this.registerInflight([...keys, ...alongside.keys(), ...alsoInflight], promise);
489
540
  this.trackWrite(cells.map(({ cell }) => ({ rowId: cell.rowId, columnId: cell.columnId })), promise);
490
541
  return promise;
491
542
  }
@@ -499,6 +550,8 @@ export class GridEditingController {
499
550
  return [...promises];
500
551
  }
501
552
  enqueueApply(kind, resolveRow, onApply) {
553
+ if (this.keepChangedSince(kind, resolveRow, onApply))
554
+ return true;
502
555
  const pressed = pressGridHistory(this.history, kind);
503
556
  const entry = pressed.entry;
504
557
  if (!entry)
@@ -511,6 +564,7 @@ export class GridEditingController {
511
564
  written: new Map(),
512
565
  notes: [],
513
566
  laid: [],
567
+ alongsideOf: new Map(),
514
568
  covered: new Map(),
515
569
  sent: false,
516
570
  heldBack: new Set(),
@@ -545,6 +599,26 @@ export class GridEditingController {
545
599
  });
546
600
  }
547
601
  }
602
+ const own = new Set(entry.edits.map((cell) => gridCellKey(cell.rowId, cell.columnId)));
603
+ for (const cell of entry.edits) {
604
+ if (!cell.overlay)
605
+ continue;
606
+ let row;
607
+ try {
608
+ row = resolveRow(cell.rowId) ?? cell.rowSnapshot;
609
+ }
610
+ catch {
611
+ row = cell.rowSnapshot;
612
+ }
613
+ const context = { kind: "restore", expected: gridHistoryValue(cell, other) };
614
+ for (const { assignment, owner } of this.alongsideFor(row, cell.rowId, cell.columnId, gridHistoryValue(cell, side), context, revision)) {
615
+ if (own.has(assignment.key))
616
+ continue;
617
+ pin.laid = pin.laid.filter((each) => each.key !== assignment.key);
618
+ pin.laid.push(assignment);
619
+ pin.alongsideOf.set(assignment.key, owner);
620
+ }
621
+ }
548
622
  if (pin.laid.length > 0) {
549
623
  for (const { key } of pin.laid)
550
624
  pin.covered.set(key, this.pending.get(key));
@@ -562,6 +636,58 @@ export class GridEditingController {
562
636
  this.applyChain = this.applyChain.then(() => this.applyPin(pin, resolveRow));
563
637
  return true;
564
638
  }
639
+ ownWorkOn(key) {
640
+ if (this.pending.has(key) || (this.inflight.get(key)?.size ?? 0) > 0)
641
+ return true;
642
+ for (const pin of this.pins) {
643
+ if (pin.laid.some((laid) => laid.key === key))
644
+ return true;
645
+ if (pin.entry?.edits.some((cell) => gridCellKey(cell.rowId, cell.columnId) === key))
646
+ return true;
647
+ }
648
+ return false;
649
+ }
650
+ keepChangedSince(kind, resolveRow, onApply) {
651
+ const { changedSince } = this.callbacks;
652
+ if (!changedSince)
653
+ return false;
654
+ const stack = kind === "undo" ? this.history.undo : this.history.redo;
655
+ const entry = stack.at(-1);
656
+ if (!entry)
657
+ return false;
658
+ const taken = new Set(entry.edits.filter((cell) => {
659
+ if (!cell.overlay || this.ownWorkOn(gridCellKey(cell.rowId, cell.columnId)))
660
+ return false;
661
+ try {
662
+ return changedSince(resolveRow(cell.rowId), cell);
663
+ }
664
+ catch {
665
+ return false;
666
+ }
667
+ }));
668
+ if (taken.size === 0)
669
+ return false;
670
+ const rest = entry.edits.filter((cell) => !taken.has(cell));
671
+ const kept = (entries) => entries.flatMap((each) => (each.id !== entry.id ? [each] : rest.length > 0 ? [{ ...entry, edits: rest }] : []));
672
+ this.history =
673
+ kind === "undo"
674
+ ? { undo: kept(this.history.undo), redo: this.history.redo }
675
+ : { undo: this.history.undo, redo: kept(this.history.redo) };
676
+ try {
677
+ this.callbacks.onChangedSince?.([...taken].map(({ rowId, columnId }) => ({ rowId, columnId })));
678
+ }
679
+ catch {
680
+ }
681
+ if (rest.length > 0)
682
+ return false;
683
+ const first = [...taken][0];
684
+ try {
685
+ onApply?.({ rowId: first.rowId, columnId: first.columnId });
686
+ }
687
+ catch {
688
+ }
689
+ return true;
690
+ }
565
691
  liftPress(pin, keys) {
566
692
  let next = null;
567
693
  for (const key of keys) {
@@ -635,6 +761,8 @@ export class GridEditingController {
635
761
  if (results[index]?.status === "confirmed")
636
762
  kept.add(gridCellKey(cell.rowId, cell.columnId));
637
763
  });
764
+ for (const key of withAlongside(kept, pin.alongsideOf))
765
+ kept.add(key);
638
766
  this.settle(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)), results, pin.laid.filter((laid) => kept.has(laid.key)));
639
767
  const cleared = overwritten.filter((held, index) => held != null && results[index]?.status === "confirmed");
640
768
  if (cleared.length > 0)
@@ -686,7 +814,9 @@ export class GridEditingController {
686
814
  return held && !pressed.has(held.revision) ? { key, value: held.value, revision: held.revision } : null;
687
815
  });
688
816
  pin.sent = true;
689
- const results = await this.performBatch(cells, pin.kind === "undo" ? "prev" : "next", "restore");
817
+ const sentKeys = new Set(cells.map(({ cell }) => gridCellKey(cell.rowId, cell.columnId)));
818
+ const alongside = [...pin.alongsideOf].filter(([, owner]) => sentKeys.has(owner)).map(([key]) => key);
819
+ const results = await this.performBatch(cells, pin.kind === "undo" ? "prev" : "next", "restore", undefined, alongside);
690
820
  return { entry, cells, overwritten, results };
691
821
  }
692
822
  sendAtClose(pin, resolveRow) {
@@ -1,4 +1,5 @@
1
1
  import type { ListColumn } from "../../model/column-schema.js";
2
+ import { type GridEditCell } from "./editing-model.js";
2
3
  /**
3
4
  * Reconciling the optimistic overlay with what the server actually holds.
4
5
  *
@@ -51,3 +52,16 @@ export declare function findSupersededCells<Row>(rows: readonly Row[], columns:
51
52
  column: ListColumn<Row>;
52
53
  serverValue: unknown;
53
54
  }[];
55
+ /**
56
+ * Does the server hold a value that is neither ours nor the one ours replaced: somebody else's? The one question both
57
+ * the warning after a save (`findSupersededCells`) and an undo before it writes (`changedSinceEdit`) ask. Ours is
58
+ * matched by structure where the save said what it kept, loosely otherwise; a date column's two spellings of one value
59
+ * are one value.
60
+ */
61
+ export declare function isThirdValue<Row>(col: ListColumn<Row>, server: unknown, ours: unknown, baseline: unknown): boolean;
62
+ /**
63
+ * Has someone written this cell since the person's edit, as the rows the grid holds show it? A third value:
64
+ * neither side of the edit as its overlay draws them (`gridRestoreShown`), a figure's side read as the number the row
65
+ * holds (an editor's `{ value, unit }`, a clear's `""`). No column, no read or no row: nothing to compare, so no.
66
+ */
67
+ export declare function changedSinceEdit<Row>(col: ListColumn<Row> | undefined, row: Row | undefined, cell: GridEditCell<Row>): boolean;
@@ -2,6 +2,8 @@ import { gridCellKey } from "./commit-model.js";
2
2
  import { sameListValue } from "viewkitjs/fields";
3
3
  import { isEmptyValue, isGridKeptValue, looselyEqualValue, sameCalendarDay, sameInstantMinute, sameKeptValue, } from "./value-equality.js";
4
4
  import { fieldTypeOf } from "../../model/field-type-of.js";
5
+ import { gridRestoreShown } from "./editing-model.js";
6
+ import { gridFigureOf } from "./clipboard-model.js";
5
7
  const sameInstantIn = (col, a, b) => {
6
8
  const type = col == null ? undefined : fieldTypeOf(col);
7
9
  return type === "datetime" ? sameInstantMinute(a, b) : type === "date" && sameCalendarDay(a, b);
@@ -46,15 +48,25 @@ export function findSupersededCells(rows, columns, getRowId, pendingByRow, hasIn
46
48
  if (hasInflight(rowId, columnId))
47
49
  continue;
48
50
  const serverValue = read(row);
49
- if (isGridKeptValue(value) ? sameKeptValue(serverValue, value) : looselyEqualValue(serverValue, value))
50
- continue;
51
- if (sameInstantIn(col, serverValue, value))
52
- continue;
53
- const baseline = baselineOf(rowId, columnId);
54
- if (looselyEqualValue(serverValue, baseline) || sameInstantIn(col, serverValue, baseline))
55
- continue;
56
- taken.push({ rowId, columnId, column: col, serverValue });
51
+ if (isThirdValue(col, serverValue, value, baselineOf(rowId, columnId))) {
52
+ taken.push({ rowId, columnId, column: col, serverValue });
53
+ }
57
54
  }
58
55
  }
59
56
  return taken;
60
57
  }
58
+ export function isThirdValue(col, server, ours, baseline) {
59
+ if (isGridKeptValue(ours) ? sameKeptValue(server, ours) : looselyEqualValue(server, ours))
60
+ return false;
61
+ if (sameInstantIn(col, server, ours))
62
+ return false;
63
+ return !(looselyEqualValue(server, baseline) || sameInstantIn(col, server, baseline));
64
+ }
65
+ export function changedSinceEdit(col, row, cell) {
66
+ const read = col?.editAccessor ?? col?.accessor;
67
+ if (!col || !read || row === undefined)
68
+ return false;
69
+ const type = fieldTypeOf(col);
70
+ const asRead = type === "number" || type === "percent" || type === "currency" ? gridFigureOf : (value) => value;
71
+ return isThirdValue(col, read(row), asRead(gridRestoreShown(cell, "next")), asRead(gridRestoreShown(cell, "prev")));
72
+ }
@@ -1,4 +1,4 @@
1
- import type { GridCellCommitFn, GridCellsCommitFn, GridCommitContext, ListSave } from "./commit-model.js";
1
+ import type { GridCellCommitFn, GridCellValuesFn, GridCellsCommitFn, GridCommitContext, ListSave } from "./commit-model.js";
2
2
  export type GridSaveOptions<Row> = {
3
3
  /** The record's id, which `save` is sent as `id`. */
4
4
  getRowId: (row: Row) => string;
@@ -9,7 +9,8 @@ export type GridSaveOptions<Row> = {
9
9
  read?: (row: Row, columnId: string) => unknown;
10
10
  };
11
11
  /**
12
- * The grid's two commit functions over one save: every write (an edit, a paste, a fill, an undo, a redo) is one call
12
+ * The grid's two commit functions over one save, and the `values` it sends them with (`cellValues`, for `GridTable` to
13
+ * show every column a cell's save writes as it is sent): every write (an edit, a paste, a fill, an undo, a redo) is one call
13
14
  * per record, its cells' values merged, and a record has one call in flight at a time, the next waiting for it to
14
15
  * settle. When the page goes, every change still waiting is sent at once, marked `closing`, and leaves its record's
15
16
  * queue: its own answer settles it; a call already out is not sent again. A cell whose `getRowId` or `values` throws
@@ -21,4 +22,5 @@ export type GridSaveOptions<Row> = {
21
22
  export declare function gridSave<Row>(save: ListSave<Row>, options: GridSaveOptions<Row>): {
22
23
  onCellCommit: GridCellCommitFn<Row>;
23
24
  onCellsCommit: GridCellsCommitFn<Row>;
25
+ cellValues: GridCellValuesFn<Row>;
24
26
  };
@@ -118,5 +118,5 @@ export function gridSave(save, options) {
118
118
  const [outcome] = await onCellsCommit([{ row, columnId, value, ...(context ? { context } : {}) }]);
119
119
  return outcome;
120
120
  };
121
- return { onCellCommit, onCellsCommit };
121
+ return { onCellCommit, onCellsCommit, cellValues: values };
122
122
  }