@viewkitjs/views 0.1.0 → 0.2.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 (246) hide show
  1. package/CHANGELOG.md +196 -1
  2. package/README.md +90 -41
  3. package/dist/atoms/Row.js +1 -1
  4. package/dist/atoms/RowMenu.d.ts +1 -1
  5. package/dist/atoms/RowMenu.js +15 -4
  6. package/dist/atoms/types.d.ts +4 -4
  7. package/dist/contract.d.ts +37 -7
  8. package/dist/contract.js +24 -5
  9. package/dist/display/format.d.ts +16 -1
  10. package/dist/display/format.js +10 -1
  11. package/dist/display/index.d.ts +1 -1
  12. package/dist/display/index.js +1 -1
  13. package/dist/display/link.js +5 -3
  14. package/dist/display/location.d.ts +4 -3
  15. package/dist/display/location.js +12 -5
  16. package/dist/display/options.d.ts +1 -1
  17. package/dist/display/percent.js +10 -3
  18. package/dist/display/phone.d.ts +2 -1
  19. package/dist/display/phone.js +8 -1
  20. package/dist/display/relation.js +1 -1
  21. package/dist/editors/ChipsEditor.js +1 -1
  22. package/dist/editors/LocationEditor.js +16 -17
  23. package/dist/editors/NameEditor.js +5 -4
  24. package/dist/editors/NumberEditor.js +2 -2
  25. package/dist/editors/RangeEditor.js +2 -2
  26. package/dist/editors/ValueListEditor.d.ts +2 -2
  27. package/dist/editors/ValueListEditor.js +8 -8
  28. package/dist/editors/edit-cores.d.ts +1 -1
  29. package/dist/fields/binding.d.ts +1 -1
  30. package/dist/fields/currency.d.ts +0 -10
  31. package/dist/fields/currency.js +0 -14
  32. package/dist/fields/money.d.ts +1 -0
  33. package/dist/fields/money.js +1 -0
  34. package/dist/filters/filter-model.d.ts +0 -1
  35. package/dist/filters/registry.d.ts +3 -36
  36. package/dist/filters/registry.js +0 -38
  37. package/dist/grid/chrome/GridAddColumn.d.ts +11 -0
  38. package/dist/grid/chrome/GridAddColumn.js +29 -0
  39. package/dist/grid/chrome/GridAggregateMenu.d.ts +31 -0
  40. package/dist/grid/chrome/GridAggregateMenu.js +27 -0
  41. package/dist/grid/chrome/GridCellEditors.d.ts +64 -0
  42. package/dist/grid/chrome/GridCellEditors.js +55 -0
  43. package/dist/grid/chrome/GridCellOutline.d.ts +70 -0
  44. package/dist/grid/chrome/GridCellOutline.js +21 -0
  45. package/dist/grid/chrome/GridChipsEditor.d.ts +28 -0
  46. package/dist/grid/chrome/GridChipsEditor.js +40 -0
  47. package/dist/grid/chrome/GridColumnColorSection.d.ts +11 -0
  48. package/dist/grid/chrome/GridColumnColorSection.js +40 -0
  49. package/dist/grid/chrome/GridColumnDateSection.d.ts +23 -0
  50. package/dist/grid/chrome/GridColumnDateSection.js +23 -0
  51. package/dist/grid/chrome/GridColumnDurationSection.d.ts +19 -0
  52. package/dist/grid/chrome/GridColumnDurationSection.js +24 -0
  53. package/dist/grid/chrome/GridColumnMenu.d.ts +101 -0
  54. package/dist/grid/chrome/GridColumnMenu.js +99 -0
  55. package/dist/grid/chrome/GridColumnNumberSection.d.ts +25 -0
  56. package/dist/grid/chrome/GridColumnNumberSection.js +27 -0
  57. package/dist/grid/chrome/GridColumnPercentSection.d.ts +15 -0
  58. package/dist/grid/chrome/GridColumnPercentSection.js +16 -0
  59. package/dist/grid/chrome/GridColumnSortSection.d.ts +18 -0
  60. package/dist/grid/chrome/GridColumnSortSection.js +16 -0
  61. package/dist/grid/chrome/GridDateEditor.d.ts +22 -0
  62. package/dist/grid/chrome/GridDateEditor.js +31 -0
  63. package/dist/grid/chrome/GridFlyout.d.ts +44 -0
  64. package/dist/grid/chrome/GridFlyout.js +80 -0
  65. package/dist/grid/chrome/GridFooter.d.ts +23 -0
  66. package/dist/grid/chrome/GridFooter.js +81 -0
  67. package/dist/grid/chrome/GridGroupMenu.d.ts +37 -0
  68. package/dist/grid/chrome/GridGroupMenu.js +57 -0
  69. package/dist/grid/chrome/GridHeader.d.ts +61 -0
  70. package/dist/grid/chrome/GridHeader.js +37 -0
  71. package/dist/grid/chrome/GridLongTextEditor.d.ts +36 -0
  72. package/dist/grid/chrome/GridLongTextEditor.js +127 -0
  73. package/dist/grid/chrome/GridMenuRow.d.ts +15 -0
  74. package/dist/grid/chrome/GridMenuRow.js +15 -0
  75. package/dist/grid/chrome/GridNameEditor.d.ts +19 -0
  76. package/dist/grid/chrome/GridNameEditor.js +36 -0
  77. package/dist/grid/chrome/GridNumberEditor.d.ts +35 -0
  78. package/dist/grid/chrome/GridNumberEditor.js +25 -0
  79. package/dist/grid/chrome/GridRangeEditor.d.ts +20 -0
  80. package/dist/grid/chrome/GridRangeEditor.js +25 -0
  81. package/dist/grid/chrome/GridRelationEditor.d.ts +21 -0
  82. package/dist/grid/chrome/GridRelationEditor.js +30 -0
  83. package/dist/grid/chrome/GridResizeHandle.d.ts +19 -0
  84. package/dist/grid/chrome/GridResizeHandle.js +19 -0
  85. package/dist/grid/chrome/GridRow.d.ts +25 -0
  86. package/dist/grid/chrome/GridRow.js +136 -0
  87. package/dist/grid/chrome/GridRowActions.d.ts +32 -0
  88. package/dist/grid/chrome/GridRowActions.js +25 -0
  89. package/dist/grid/chrome/GridRowCells.d.ts +4 -0
  90. package/dist/grid/chrome/GridRowCells.js +133 -0
  91. package/dist/grid/chrome/GridRowGlyph.d.ts +12 -0
  92. package/dist/grid/chrome/GridRowGlyph.js +13 -0
  93. package/dist/grid/chrome/GridSelectEditor.d.ts +18 -0
  94. package/dist/grid/chrome/GridSelectEditor.js +49 -0
  95. package/dist/grid/chrome/GridStructure.d.ts +48 -0
  96. package/dist/grid/chrome/GridStructure.js +45 -0
  97. package/dist/grid/chrome/GridTable.d.ts +4 -0
  98. package/dist/grid/chrome/GridTable.js +125 -0
  99. package/dist/grid/chrome/GridTableSurface.d.ts +15 -0
  100. package/dist/grid/chrome/GridTableSurface.js +6 -0
  101. package/dist/grid/chrome/GridTextEditor.d.ts +11 -0
  102. package/dist/grid/chrome/GridTextEditor.js +40 -0
  103. package/dist/grid/chrome/GridValueListEditor.d.ts +18 -0
  104. package/dist/grid/chrome/GridValueListEditor.js +36 -0
  105. package/dist/grid/chrome/StuckMarker.d.ts +16 -0
  106. package/dist/grid/chrome/StuckMarker.js +34 -0
  107. package/dist/grid/chrome/cell-clipboard.d.ts +9 -0
  108. package/dist/grid/chrome/cell-clipboard.js +28 -0
  109. package/dist/grid/chrome/cells.d.ts +21 -0
  110. package/dist/grid/chrome/cells.js +20 -0
  111. package/dist/grid/chrome/checks.d.ts +35 -0
  112. package/dist/grid/chrome/checks.js +22 -0
  113. package/dist/grid/chrome/column-glyph.d.ts +14 -0
  114. package/dist/grid/chrome/column-glyph.js +44 -0
  115. package/dist/grid/chrome/editors.d.ts +9 -0
  116. package/dist/grid/chrome/editors.js +10 -0
  117. package/dist/grid/chrome/grid-cell-classes.d.ts +59 -0
  118. package/dist/grid/chrome/grid-cell-classes.js +30 -0
  119. package/dist/grid/chrome/grid-menu-search.d.ts +7 -0
  120. package/dist/grid/chrome/grid-menu-search.js +7 -0
  121. package/dist/grid/chrome/grid-row-props.d.ts +131 -0
  122. package/dist/grid/chrome/grid-row-props.js +1 -0
  123. package/dist/grid/chrome/grid-styles.d.ts +37 -0
  124. package/dist/grid/chrome/grid-styles.js +8 -0
  125. package/dist/grid/chrome/grid-table-props.d.ts +173 -0
  126. package/dist/grid/chrome/grid-table-props.js +1 -0
  127. package/dist/grid/chrome/useGridBatchApi.d.ts +34 -0
  128. package/dist/grid/chrome/useGridBatchApi.js +35 -0
  129. package/dist/grid/chrome/useGridColumnLayout.d.ts +30 -0
  130. package/dist/grid/chrome/useGridColumnLayout.js +206 -0
  131. package/dist/grid/chrome/useGridHeaderDrag.d.ts +20 -0
  132. package/dist/grid/chrome/useGridHeaderDrag.js +37 -0
  133. package/dist/grid/chrome/useGridKeyboard.d.ts +47 -0
  134. package/dist/grid/chrome/useGridKeyboard.js +274 -0
  135. package/dist/grid/chrome/useGridPendingReconciliation.d.ts +12 -0
  136. package/dist/grid/chrome/useGridPendingReconciliation.js +32 -0
  137. package/dist/grid/chrome/useGridRailReveal.d.ts +57 -0
  138. package/dist/grid/chrome/useGridRailReveal.js +67 -0
  139. package/dist/grid/chrome/useGridRangeActions.d.ts +49 -0
  140. package/dist/grid/chrome/useGridRangeActions.js +188 -0
  141. package/dist/grid/chrome/useGridRangeGestures.d.ts +32 -0
  142. package/dist/grid/chrome/useGridRangeGestures.js +190 -0
  143. package/dist/grid/chrome/useGridRowContextMenu.d.ts +35 -0
  144. package/dist/grid/chrome/useGridRowContextMenu.js +127 -0
  145. package/dist/grid/chrome/useGridScaleStyles.d.ts +1 -0
  146. package/dist/grid/chrome/useGridScaleStyles.js +29 -0
  147. package/dist/grid/chrome/useGridScrollSync.d.ts +38 -0
  148. package/dist/grid/chrome/useGridScrollSync.js +176 -0
  149. package/dist/grid/chrome/useGridTableInteractionModel.d.ts +55 -0
  150. package/dist/grid/chrome/useGridTableInteractionModel.js +197 -0
  151. package/dist/grid/chrome/useGridTableSelection.d.ts +29 -0
  152. package/dist/grid/chrome/useGridTableSelection.js +55 -0
  153. package/dist/grid/chrome/useHeaderDragReorder.d.ts +21 -0
  154. package/dist/grid/chrome/useHeaderDragReorder.js +216 -0
  155. package/dist/grid/core/clipboard-model.d.ts +81 -0
  156. package/dist/grid/core/clipboard-model.js +291 -0
  157. package/dist/grid/core/column-values.d.ts +27 -0
  158. package/dist/grid/core/column-values.js +76 -0
  159. package/dist/grid/core/commit-model.d.ts +34 -0
  160. package/dist/grid/core/commit-model.js +3 -0
  161. package/dist/grid/core/coordinates.d.ts +48 -0
  162. package/dist/grid/core/coordinates.js +27 -0
  163. package/dist/grid/core/edit-values.d.ts +9 -0
  164. package/dist/grid/core/edit-values.js +1 -0
  165. package/dist/grid/core/editing-controller.d.ts +59 -0
  166. package/dist/grid/core/editing-controller.js +240 -0
  167. package/dist/grid/core/editing-model.d.ts +78 -0
  168. package/dist/grid/core/editing-model.js +136 -0
  169. package/dist/grid/core/grid-scale.d.ts +14 -0
  170. package/dist/grid/core/grid-scale.js +8 -0
  171. package/dist/grid/core/nav.d.ts +94 -0
  172. package/dist/grid/core/nav.js +92 -0
  173. package/dist/grid/core/pending-reconciliation.d.ts +50 -0
  174. package/dist/grid/core/pending-reconciliation.js +49 -0
  175. package/dist/grid/core/range-model.d.ts +25 -0
  176. package/dist/grid/core/range-model.js +59 -0
  177. package/dist/grid/core/spreadsheet-operations.d.ts +85 -0
  178. package/dist/grid/core/spreadsheet-operations.js +253 -0
  179. package/dist/grid/core/useGridEditing.d.ts +43 -0
  180. package/dist/grid/core/useGridEditing.js +90 -0
  181. package/dist/grid/core/useGridRange.d.ts +20 -0
  182. package/dist/grid/core/useGridRange.js +24 -0
  183. package/dist/grid/core/value-equality.d.ts +32 -0
  184. package/dist/grid/core/value-equality.js +34 -0
  185. package/dist/grid/index.d.ts +18 -0
  186. package/dist/grid/index.js +5 -0
  187. package/dist/grid/useGridTablePrefs.d.ts +50 -0
  188. package/dist/grid/useGridTablePrefs.js +101 -0
  189. package/dist/index.d.ts +0 -1
  190. package/dist/index.js +0 -1
  191. package/dist/internal/viewport.d.ts +5 -0
  192. package/dist/internal/viewport.js +29 -0
  193. package/dist/model/column-capabilities.d.ts +2 -2
  194. package/dist/model/column-state.d.ts +1 -1
  195. package/dist/model/density.js +3 -3
  196. package/dist/model/filter-capabilities.d.ts +1 -1
  197. package/dist/model/filter-capabilities.js +1 -1
  198. package/dist/model/index.d.ts +4 -6
  199. package/dist/model/index.js +0 -1
  200. package/dist/model/preferences.d.ts +7 -3
  201. package/dist/provider/ViewsProvider.d.ts +1 -1
  202. package/dist/provider/ViewsProvider.js +5 -1
  203. package/dist/provider/components.d.ts +16 -8
  204. package/dist/provider/context.d.ts +3 -2
  205. package/dist/provider/menu-groups.d.ts +8 -0
  206. package/dist/provider/menu-groups.js +38 -0
  207. package/dist/provider/ports.d.ts +22 -0
  208. package/dist/provider/ports.js +1 -0
  209. package/dist/react.d.ts +1 -1
  210. package/docs/contract.md +128 -56
  211. package/docs/getting-started.md +250 -0
  212. package/docs/guides/atoms.md +245 -0
  213. package/docs/guides/cells.md +302 -0
  214. package/docs/guides/columns.md +412 -0
  215. package/docs/guides/display.md +203 -0
  216. package/docs/guides/editors.md +404 -0
  217. package/docs/guides/ports.md +246 -0
  218. package/docs/guides/selection.md +270 -0
  219. package/docs/guides/the-grid.md +677 -0
  220. package/docs/guides/the-provider.md +446 -0
  221. package/docs/index.md +50 -0
  222. package/docs/install.md +9 -47
  223. package/docs/reference/cells.md +28 -0
  224. package/docs/reference/display.md +42 -0
  225. package/docs/reference/editors-chips.md +6 -0
  226. package/docs/reference/editors-date.md +6 -0
  227. package/docs/reference/editors-location.md +10 -0
  228. package/docs/reference/editors-name.md +6 -0
  229. package/docs/reference/editors-number.md +11 -0
  230. package/docs/reference/editors-open-values.md +9 -0
  231. package/docs/reference/editors-range.md +6 -0
  232. package/docs/reference/editors-relation.md +9 -0
  233. package/docs/reference/editors-select.md +8 -0
  234. package/docs/reference/editors-session.md +9 -0
  235. package/docs/reference/editors-value-list.md +6 -0
  236. package/docs/reference/editors.md +5 -0
  237. package/docs/reference/grid.md +39 -0
  238. package/docs/reference/react.md +86 -0
  239. package/docs/reference/selection.md +33 -0
  240. package/docs/reference/views.md +601 -0
  241. package/package.json +7 -3
  242. package/skills/views/SKILL.md +20 -5
  243. package/dist/filters/types.d.ts +0 -27
  244. package/dist/filters/types.js +0 -1
  245. package/dist/model/filter-pushdown.d.ts +0 -106
  246. package/dist/model/filter-pushdown.js +0 -147
@@ -0,0 +1,253 @@
1
+ import { cellClearPrev, cellCopyText, cellEditBaseline, cellPrevPayload, coercePaste, gridPasteOverlay, pasteUnit, rowHoldsCurrency, } from "./clipboard-model.js";
2
+ import { gridBooleanMode, columnEditRefusal, columnWritable, } from "../../model/column-capabilities.js";
3
+ import { resolveViewsMessage } from "../../contract.js";
4
+ import { gridRectIsMulti, resolveCellRect, } from "./coordinates.js";
5
+ import { resolveActiveRangeRect } from "./range-model.js";
6
+ import { fieldTypeOf } from "../../model/field-type-of.js";
7
+ function addRefusal(refusals, reason) {
8
+ const known = refusals.find((refusal) => refusal.reason === reason);
9
+ if (known)
10
+ known.count++;
11
+ else
12
+ refusals.push({ reason, count: 1 });
13
+ }
14
+ export function buildGridCopyMatrix(model, rect) {
15
+ const matrix = [];
16
+ for (let r = rect.r1; r <= rect.r2; r++) {
17
+ const entry = model.rowByKey.get(model.visibleRowIds[r]);
18
+ if (entry == null)
19
+ continue;
20
+ const { row, rowId } = entry;
21
+ const cells = [];
22
+ for (let c = rect.c1; c <= rect.c2; c++) {
23
+ const col = model.visibleColumns[c];
24
+ if (!col)
25
+ continue;
26
+ const baseline = cellEditBaseline(col, row, model.pendingByRow.get(rowId));
27
+ cells.push({
28
+ text: cellCopyText(col, baseline),
29
+ value: baseline,
30
+ type: col.type,
31
+ unit: col.editUnit?.value(row),
32
+ });
33
+ }
34
+ matrix.push(cells);
35
+ }
36
+ return matrix;
37
+ }
38
+ export function gridRectHasClearable(columns, rect) {
39
+ for (let c = rect.c1; c <= rect.c2; c++) {
40
+ const col = columns[c];
41
+ if (col && columnWritable(col) && (col.clearable || gridBooleanMode(col)))
42
+ return true;
43
+ }
44
+ return false;
45
+ }
46
+ export function planGridClear(model, rect) {
47
+ const edits = [];
48
+ for (let r = rect.r1; r <= rect.r2; r++) {
49
+ const entry = model.rowByKey.get(model.visibleRowIds[r]);
50
+ if (entry == null)
51
+ continue;
52
+ const { row, rowId } = entry;
53
+ for (let c = rect.c1; c <= rect.c2; c++) {
54
+ const col = model.visibleColumns[c];
55
+ if (!col || !columnWritable(col))
56
+ continue;
57
+ if (!col.clearable && !gridBooleanMode(col))
58
+ continue;
59
+ edits.push({
60
+ row,
61
+ rowId,
62
+ columnId: col.id,
63
+ prev: cellClearPrev(col, row, model.pendingByRow.get(rowId)),
64
+ next: "",
65
+ overlay: true,
66
+ rowSnapshot: row,
67
+ });
68
+ }
69
+ }
70
+ return edits;
71
+ }
72
+ export function planGridPaste(model, matrix, anchor, activeRect, selectValuesByColumn) {
73
+ const empty = {
74
+ edits: [],
75
+ skipped: 0,
76
+ refusals: [],
77
+ targetCount: 0,
78
+ selection: null,
79
+ };
80
+ if (matrix.length === 0 || matrix[0]?.length === 0)
81
+ return empty;
82
+ const single = matrix.length === 1 && matrix[0].length === 1;
83
+ const targets = [];
84
+ if (single && activeRect && gridRectIsMulti(activeRect)) {
85
+ for (let r = activeRect.r1; r <= activeRect.r2; r++) {
86
+ for (let c = activeRect.c1; c <= activeRect.c2; c++) {
87
+ targets.push({ r, c, source: matrix[0][0] });
88
+ }
89
+ }
90
+ }
91
+ else {
92
+ for (let i = 0; i < matrix.length; i++) {
93
+ for (let j = 0; j < matrix[i].length; j++) {
94
+ const r = anchor.rowIdx + i;
95
+ const c = anchor.colIdx + j;
96
+ if (r >= model.visibleRowIds.length || c >= model.visibleColumns.length)
97
+ continue;
98
+ targets.push({ r, c, source: matrix[i][j] });
99
+ }
100
+ }
101
+ }
102
+ const edits = [];
103
+ let skipped = 0;
104
+ const refusals = [];
105
+ let maxR = anchor.rowIdx;
106
+ let maxC = anchor.colIdx;
107
+ for (const { r, c, source } of targets) {
108
+ const entry = model.rowByKey.get(model.visibleRowIds[r]);
109
+ const row = entry?.row;
110
+ const rowId = entry?.rowId;
111
+ const col = model.visibleColumns[c];
112
+ if (row == null || !col || !columnWritable(col)) {
113
+ skipped++;
114
+ const messages = model.messages ?? resolveViewsMessage;
115
+ addRefusal(refusals, (col && columnEditRefusal(col, model.conventions, messages)) || messages({ key: "views.grid.cell-read-only" }));
116
+ continue;
117
+ }
118
+ const coerced = coercePaste(col, source, {
119
+ conventions: model.conventions,
120
+ messages: model.messages,
121
+ currentUnit: col.editUnit?.value(row),
122
+ holdsCurrency: rowHoldsCurrency(col, row),
123
+ values: selectValuesByColumn[col.id],
124
+ });
125
+ if (!coerced.ok) {
126
+ skipped++;
127
+ addRefusal(refusals, coerced.reason);
128
+ continue;
129
+ }
130
+ edits.push({
131
+ row,
132
+ rowId,
133
+ columnId: col.id,
134
+ prev: cellPrevPayload(col, cellEditBaseline(col, row, model.pendingByRow.get(rowId)), col.editUnit?.value(row)),
135
+ next: coerced.next,
136
+ overlay: coerced.overlay,
137
+ rowSnapshot: row,
138
+ });
139
+ maxR = Math.max(maxR, r);
140
+ maxC = Math.max(maxC, c);
141
+ }
142
+ const anchorRowId = model.visibleRowIds[anchor.rowIdx];
143
+ const anchorColumn = model.visibleColumns[anchor.colIdx];
144
+ const headRowId = model.visibleRowIds[maxR];
145
+ const headColumn = model.visibleColumns[maxC];
146
+ const selection = !single && edits.length > 0 && anchorRowId && anchorColumn && headRowId && headColumn
147
+ ? {
148
+ anchor: { rowId: anchorRowId, columnId: anchorColumn.id },
149
+ head: { rowId: headRowId, columnId: headColumn.id },
150
+ }
151
+ : null;
152
+ return { edits, skipped, refusals, targetCount: targets.length, selection };
153
+ }
154
+ export function extendGridFillPreview(ranges, targetRowId, visibleRowIds, visibleColIds) {
155
+ if (!targetRowId || ranges.length === 0)
156
+ return ranges;
157
+ const active = ranges[ranges.length - 1];
158
+ const rect = resolveCellRect(active.anchor, active.head, visibleRowIds, visibleColIds);
159
+ const target = visibleRowIds.indexOf(targetRowId);
160
+ if (!rect || target < 0 || (target >= rect.r1 && target <= rect.r2)) {
161
+ return ranges;
162
+ }
163
+ const down = target > rect.r2;
164
+ return [
165
+ ...ranges,
166
+ {
167
+ anchor: {
168
+ rowId: visibleRowIds[down ? rect.r2 + 1 : target],
169
+ columnId: visibleColIds[rect.c1],
170
+ },
171
+ head: {
172
+ rowId: visibleRowIds[down ? target : rect.r1 - 1],
173
+ columnId: visibleColIds[rect.c2],
174
+ },
175
+ },
176
+ ];
177
+ }
178
+ export function planGridFill(model, ranges, focused, targetRowId) {
179
+ const visibleColIds = model.visibleColumns.map((col) => col.id);
180
+ const rect = resolveActiveRangeRect(ranges, focused, model.visibleRowIds, visibleColIds);
181
+ const active = ranges[ranges.length - 1] ?? (focused ? { anchor: focused, head: focused } : null);
182
+ const target = model.visibleRowIds.indexOf(targetRowId);
183
+ if (!rect || !active || target < 0 || (target >= rect.r1 && target <= rect.r2)) {
184
+ return { edits: [], selectionHead: null, skipped: 0, refusals: [], targetCount: 0 };
185
+ }
186
+ const down = target > rect.r2;
187
+ const sourceHeight = rect.r2 - rect.r1 + 1;
188
+ const targetIndices = [];
189
+ if (down) {
190
+ for (let index = rect.r2 + 1; index <= target; index++)
191
+ targetIndices.push(index);
192
+ }
193
+ else {
194
+ for (let index = target; index < rect.r1; index++)
195
+ targetIndices.push(index);
196
+ }
197
+ const edits = [];
198
+ let skipped = 0;
199
+ const refusals = [];
200
+ for (const targetIndex of targetIndices) {
201
+ const sourceIndex = down
202
+ ? rect.r1 + ((targetIndex - rect.r2 - 1) % sourceHeight)
203
+ : rect.r2 - ((rect.r1 - targetIndex - 1) % sourceHeight);
204
+ const source = model.rowByKey.get(model.visibleRowIds[sourceIndex]);
205
+ const next_ = model.rowByKey.get(model.visibleRowIds[targetIndex]);
206
+ if (source == null || next_ == null)
207
+ continue;
208
+ const { row: sourceRow, rowId: sourceRowId } = source;
209
+ const { row: nextRow, rowId: nextRowId } = next_;
210
+ for (let c = rect.c1; c <= rect.c2; c++) {
211
+ const col = model.visibleColumns[c];
212
+ if (!col || !columnWritable(col))
213
+ continue;
214
+ const sourceBaseline = cellEditBaseline(col, sourceRow, model.pendingByRow.get(sourceRowId));
215
+ const empty = sourceBaseline == null || sourceBaseline === "";
216
+ if (empty && !col.clearable && !gridBooleanMode(col))
217
+ continue;
218
+ let next = empty && col.clearable ? "" : cellPrevPayload(col, sourceBaseline, col.editUnit?.value(sourceRow));
219
+ if (next == null)
220
+ continue;
221
+ if (!empty && fieldTypeOf(col) === "currency" && typeof next === "object") {
222
+ const payload = next;
223
+ const unit = pasteUnit(payload.unit, col.editUnit?.value(nextRow), col.editUnit?.options, rowHoldsCurrency(col, nextRow));
224
+ if ("refuse" in unit) {
225
+ skipped++;
226
+ addRefusal(refusals, (model.messages ?? resolveViewsMessage)({
227
+ key: "views.grid.paste-other-currency",
228
+ values: { currency: unit.refuse },
229
+ }));
230
+ continue;
231
+ }
232
+ next = { ...payload, unit: unit.unit };
233
+ }
234
+ const overlay = gridPasteOverlay(col);
235
+ edits.push({
236
+ row: nextRow,
237
+ rowId: nextRowId,
238
+ columnId: col.id,
239
+ prev: cellClearPrev(col, nextRow, model.pendingByRow.get(nextRowId)),
240
+ next,
241
+ overlay,
242
+ rowSnapshot: nextRow,
243
+ });
244
+ }
245
+ }
246
+ return {
247
+ edits,
248
+ selectionHead: { rowId: targetRowId, columnId: active.head.columnId },
249
+ skipped,
250
+ refusals,
251
+ targetCount: targetIndices.length * (rect.c2 - rect.c1 + 1),
252
+ };
253
+ }
@@ -0,0 +1,43 @@
1
+ import type { GridCellCommitFn, GridCellsCommitFn } from "./commit-model.js";
2
+ import { type GridCellPos } from "./coordinates.js";
3
+ import { type GridEditCell, type GridSettlementByRow } from "./editing-model.js";
4
+ export type { GridEditCell } from "./editing-model.js";
5
+ type GridEditingApi<Row> = {
6
+ focused: GridCellPos | null;
7
+ editing: GridCellPos | null;
8
+ pendingByRow: ReadonlyMap<string, Record<string, unknown>>;
9
+ /** The subset of pending cells whose write is only `requested` of its
10
+ * provider — drawn as a visible pending state (spec §11.2). */
11
+ settlementByRow: GridSettlementByRow;
12
+ focusCell: (rowId: string, columnId: string) => void;
13
+ clearFocus: () => void;
14
+ startEdit: (rowId: string, columnId: string) => void;
15
+ cancelEdit: (rowId?: string, columnId?: string) => void;
16
+ commitEdit: (row: Row, rowId: string, columnId: string, prev: unknown, next: unknown, opts?: {
17
+ overlay?: boolean;
18
+ }) => void;
19
+ /** Commit MANY cells as one user action (fill, range paste/delete, a batch
20
+ * bar verb over a row selection). One history entry — ⌘Z reverts the whole
21
+ * thing in a single step. Rows ride along per cell (`row`); prev/next in
22
+ * commit-payload shape.
23
+ *
24
+ * Resolves TRUE once every cell has landed on the server, false if any
25
+ * failed (those overlays are already rolled back by then). Callers that own
26
+ * user-facing confirmation await it; the editors ignore it, because an
27
+ * optimistic edit's feedback is the cell itself. */
28
+ commitBatch: (edits: (GridEditCell<Row> & {
29
+ row: Row;
30
+ })[]) => Promise<boolean>;
31
+ /** Undo the most recent action (⌘Z). `resolveRow` maps a rowId to the
32
+ * CURRENT row object (stored snapshot is the fallback). `onApply` fires when
33
+ * the application actually starts — the chrome scrolls the cell into view.
34
+ * Returns false when there is nothing to undo. */
35
+ undo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
36
+ redo: (resolveRow: (rowId: string) => Row | undefined, onApply?: (pos: GridCellPos) => void) => boolean;
37
+ reconcile: (matchedKeys: string[]) => void;
38
+ /** True while a write for this cell has not settled — see hasInflight. */
39
+ hasInflight: (rowId: string, columnId: string) => boolean;
40
+ /** What the cell held before its pending write — see GridPendingEntry.baseline. */
41
+ pendingBaseline: (rowId: string, columnId: string) => unknown;
42
+ };
43
+ export declare function useGridEditing<Row>(onCellCommit?: GridCellCommitFn<Row>, onCellsCommit?: GridCellsCommitFn<Row>): GridEditingApi<Row>;
@@ -0,0 +1,90 @@
1
+ import { useCallback, useEffect, useState } from "react";
2
+ import { gridRowIdFromKey } from "./coordinates.js";
3
+ import { GridEditingController } from "./editing-controller.js";
4
+ import { sameListValue } from "@viewkitjs/fields";
5
+ import { prepareGridCommitCells, } from "./editing-model.js";
6
+ export function useGridEditing(onCellCommit, onCellsCommit) {
7
+ const [focused, setFocused] = useState(null);
8
+ const [editing, setEditing] = useState(null);
9
+ const [pendingByRow, setPendingByRow] = useState(() => new Map());
10
+ const [settlementByRow, setSettlementByRow] = useState(() => new Map());
11
+ const [controller] = useState(() => new GridEditingController({ onCellCommit, onCellsCommit }, (pending, settlement) => {
12
+ setPendingByRow(pending);
13
+ setSettlementByRow(settlement);
14
+ }));
15
+ useEffect(() => {
16
+ const callbacks = { onCellCommit, onCellsCommit };
17
+ controller.setCallbacks(callbacks);
18
+ }, [controller, onCellCommit, onCellsCommit]);
19
+ const focusCell = useCallback((rowId, columnId) => {
20
+ setFocused({ rowId, columnId });
21
+ setEditing(null);
22
+ }, []);
23
+ const clearFocus = useCallback(() => {
24
+ setFocused(null);
25
+ setEditing(null);
26
+ }, []);
27
+ const startEdit = useCallback((rowId, columnId) => {
28
+ setFocused({ rowId, columnId });
29
+ setEditing({ rowId, columnId });
30
+ }, []);
31
+ const cancelEdit = useCallback((rowId, columnId) => {
32
+ setEditing((current) => rowId != null && current != null && (current.rowId !== rowId || current.columnId !== columnId)
33
+ ? current
34
+ : null);
35
+ }, []);
36
+ const commitEdit = useCallback((row, rowId, columnId, prev, next, opts) => {
37
+ setEditing((current) => current != null &&
38
+ (gridRowIdFromKey(current.rowId) !== rowId || current.columnId !== columnId)
39
+ ? current
40
+ : null);
41
+ if (sameListValue(next, prev) || !onCellCommit)
42
+ return;
43
+ controller.commit([
44
+ {
45
+ row,
46
+ cell: {
47
+ rowId,
48
+ columnId,
49
+ prev,
50
+ next,
51
+ overlay: opts?.overlay !== false,
52
+ rowSnapshot: row,
53
+ },
54
+ },
55
+ ]);
56
+ }, [controller, onCellCommit]);
57
+ const commitBatch = useCallback((edits) => controller.commit(prepareGridCommitCells(edits)), [controller]);
58
+ const applyHistory = useCallback((kind, resolveRow, onApply) => {
59
+ const reveal = (pos) => {
60
+ setFocused(pos);
61
+ setEditing(null);
62
+ onApply?.(pos);
63
+ };
64
+ return kind === "undo"
65
+ ? controller.undo(resolveRow, reveal)
66
+ : controller.redo(resolveRow, reveal);
67
+ }, [controller]);
68
+ const undo = useCallback((resolveRow, onApply) => applyHistory("undo", resolveRow, onApply), [applyHistory]);
69
+ const redo = useCallback((resolveRow, onApply) => applyHistory("redo", resolveRow, onApply), [applyHistory]);
70
+ const reconcile = useCallback((matchedKeys) => controller.reconcile(matchedKeys), [controller]);
71
+ const hasInflight = useCallback((rowId, columnId) => controller.hasInflight(rowId, columnId), [controller]);
72
+ const pendingBaseline = useCallback((rowId, columnId) => controller.pendingBaseline(rowId, columnId), [controller]);
73
+ return {
74
+ focused,
75
+ editing,
76
+ pendingByRow,
77
+ settlementByRow,
78
+ focusCell,
79
+ clearFocus,
80
+ startEdit,
81
+ cancelEdit,
82
+ commitEdit,
83
+ commitBatch,
84
+ undo,
85
+ redo,
86
+ reconcile,
87
+ hasInflight,
88
+ pendingBaseline,
89
+ };
90
+ }
@@ -0,0 +1,20 @@
1
+ import type { GridCellPos } from "./coordinates.js";
2
+ import { type GridCellRange } from "./range-model.js";
3
+ export { type GridCellRange, type GridRowRangeSpan } from "./range-model.js";
4
+ type GridRangeApi = {
5
+ ranges: GridCellRange[];
6
+ /** Replace everything with a 1-cell range (plain click / focus sync). */
7
+ setSingle: (pos: GridCellPos) => void;
8
+ /** Replace everything with one rectangle (e.g. select a pasted block). */
9
+ setRect: (anchor: GridCellPos, head: GridCellPos) => void;
10
+ /** Start a drag range at `pos` — replaces the selection, or appends when
11
+ * `additive` (⌘-drag). */
12
+ beginDrag: (pos: GridCellPos, additive: boolean) => void;
13
+ /** Update the active range's head (drag / shift-click). Seeds a new range
14
+ * from `fallbackAnchor` when the selection is empty. */
15
+ extendTo: (pos: GridCellPos, fallbackAnchor?: GridCellPos) => void;
16
+ /** Append a 1-cell range (⌘-click). */
17
+ addCell: (pos: GridCellPos) => void;
18
+ clear: () => void;
19
+ };
20
+ export declare function useGridRange(): GridRangeApi;
@@ -0,0 +1,24 @@
1
+ import { useCallback, useMemo, useState } from "react";
2
+ import { addCellRange, beginRangeDrag, extendActiveRange, setRectRange, setSingleRange, } from "./range-model.js";
3
+ export function useGridRange() {
4
+ const [ranges, setRanges] = useState([]);
5
+ const setSingle = useCallback((pos) => {
6
+ setRanges(setSingleRange(pos));
7
+ }, []);
8
+ const setRect = useCallback((anchor, head) => {
9
+ setRanges(setRectRange(anchor, head));
10
+ }, []);
11
+ const beginDrag = useCallback((pos, additive) => {
12
+ setRanges((ranges) => beginRangeDrag(ranges, pos, additive));
13
+ }, []);
14
+ const extendTo = useCallback((pos, fallbackAnchor) => {
15
+ setRanges((ranges) => extendActiveRange(ranges, pos, fallbackAnchor));
16
+ }, []);
17
+ const addCell = useCallback((pos) => {
18
+ setRanges((ranges) => addCellRange(ranges, pos));
19
+ }, []);
20
+ const clear = useCallback(() => {
21
+ setRanges((rs) => (rs.length === 0 ? rs : []));
22
+ }, []);
23
+ return useMemo(() => ({ ranges, setSingle, setRect, beginDrag, extendTo, addCell, clear }), [ranges, setSingle, setRect, beginDrag, extendTo, addCell, clear]);
24
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * HOW TWO CELL VALUES COMPARE — the one place a list of values is understood.
3
+ *
4
+ * Four questions in this subsystem are all "are these the same value", and each
5
+ * answered it with `===`: did our write land (`findGridPendingMatches`), was it
6
+ * taken from us (`findSupersededCells`), and the two no-op checks before a
7
+ * commit. Identity is the right answer for every scalar type and the wrong one
8
+ * for an array, which is never identical to the array a refetch brings back —
9
+ * so a multi-value write would hold its overlay for the life of the mount AND
10
+ * report itself as somebody else's edit at the same time.
11
+ *
12
+ * TWO functions rather than one, because the two jobs genuinely differ and
13
+ * merging them would make each worse:
14
+ *
15
+ * - `sameListValue` asks "is there anything to write". It is exact, so a
16
+ * reordering counts as a change. It lives in `@viewkitjs/fields` — the same
17
+ * question is an editing CORE's, and a core cannot reach into the grid.
18
+ * - `looselyEqualValue`, below, asks "is the difference merely a FORMAT". It
19
+ * is forgiving, so a server that stores a list in its own order has not
20
+ * overruled you and nobody is warned. That is a question about a reply, not
21
+ * about a field, so it stays here.
22
+ */
23
+ /**
24
+ * The RESHAPING CHECK: a multiset for two arrays, the scalar rule otherwise.
25
+ *
26
+ * Order-insensitive on purpose. What comes back is the server's own storage
27
+ * order, and treating that as a third party's edit would put a warning on the
28
+ * screen every time somebody tagged something — which is how a warning becomes
29
+ * noise nobody reads. Duplicates are counted rather than merely matched, so
30
+ * `["a","a"]` and `["a","b"]` stay different.
31
+ */
32
+ export declare function looselyEqualValue(a: unknown, b: unknown): boolean;
@@ -0,0 +1,34 @@
1
+ function looselyEqualScalar(a, b) {
2
+ if (Object.is(a, b))
3
+ return true;
4
+ if (a == null || b == null)
5
+ return false;
6
+ if (typeof a === "object" || typeof b === "object")
7
+ return false;
8
+ const left = String(a).trim();
9
+ const right = String(b).trim();
10
+ if (left === right)
11
+ return true;
12
+ if (left === "" || right === "")
13
+ return false;
14
+ const leftNumber = Number(left);
15
+ const rightNumber = Number(right);
16
+ return !Number.isNaN(leftNumber) && !Number.isNaN(rightNumber) && leftNumber === rightNumber;
17
+ }
18
+ export function looselyEqualValue(a, b) {
19
+ if (Array.isArray(a) || Array.isArray(b)) {
20
+ if (!Array.isArray(a) || !Array.isArray(b))
21
+ return false;
22
+ if (a.length !== b.length)
23
+ return false;
24
+ const unmatched = [...b];
25
+ for (const item of a) {
26
+ const index = unmatched.findIndex((candidate) => looselyEqualScalar(item, candidate));
27
+ if (index === -1)
28
+ return false;
29
+ unmatched.splice(index, 1);
30
+ }
31
+ return true;
32
+ }
33
+ return looselyEqualScalar(a, b);
34
+ }
@@ -0,0 +1,18 @@
1
+ /**
2
+ * THE SPREADSHEET.
3
+ *
4
+ * What a grid alone owns: the renderer and its personal prefs. What a COLUMN is
5
+ * (schema, capabilities, visibility, filters, prefs) is the views package's
6
+ * model, which every view reads: import it from `@viewkitjs/views`. The binding's helpers ride
7
+ * the same door: the commit types, the column values a filter offers, a cell's copy text and
8
+ * baseline, the title link's class.
9
+ */
10
+ export { useGridTablePrefs } from "./useGridTablePrefs.js";
11
+ export { GridTable, type GridTableProps } from "./chrome/GridTable.js";
12
+ export type { GridGroupByState, GridSortState } from "./chrome/GridColumnMenu.js";
13
+ export type { GridGroupSortOption } from "./chrome/GridGroupMenu.js";
14
+ export type { GridGroupFigure, GroupCountNoun } from "./chrome/grid-table-props.js";
15
+ export type { GridCellCommitFn, GridCellsCommitFn, GridCommitContext, GridCommitOutcome, } from "./core/commit-model.js";
16
+ export { deriveGridRelationValues, deriveGridSelectValues } from "./core/column-values.js";
17
+ export { cellCopyText, cellEditBaseline } from "./core/clipboard-model.js";
18
+ export { GRID_TITLE_LINK_CLASS } from "./chrome/grid-cell-classes.js";
@@ -0,0 +1,5 @@
1
+ export { useGridTablePrefs } from "./useGridTablePrefs.js";
2
+ export { GridTable } from "./chrome/GridTable.js";
3
+ export { deriveGridRelationValues, deriveGridSelectValues } from "./core/column-values.js";
4
+ export { cellCopyText, cellEditBaseline } from "./core/clipboard-model.js";
5
+ export { GRID_TITLE_LINK_CLASS } from "./chrome/grid-cell-classes.js";
@@ -0,0 +1,50 @@
1
+ import type { ListAggregateKind, ListColumn, ListSelectColor } from "../model/column-schema.js";
2
+ import type { ListDateStyle, ListDurationStyle, ListNumberFormatOverrides } from "../model/column-format.js";
3
+ import type { ListColumnState } from "../model/column-state.js";
4
+ import { type ListGroupSummaryPart, type ListViewPrefs } from "../model/preferences.js";
5
+ import type { PercentDisplay } from "@viewkitjs/fields";
6
+ /**
7
+ * THE standard wiring between a list's view-prefs blob and the grid: hands back
8
+ * `gridProps` to spread onto `<GridTable>` (all the per-user knobs + handlers).
9
+ * A host's layout panel is its own, built from the same handlers. Active-view
10
+ * selection and list-level filters belong to the binding.
11
+ */
12
+ export declare function useGridTablePrefs<Row>({ prefs, setPrefs, columns, viewBacked, }: {
13
+ prefs: ListViewPrefs;
14
+ setPrefs: (patch: Partial<ListViewPrefs>) => void;
15
+ /** The list's declared grid columns: the number formats read each one's money. */
16
+ columns: ListColumn<Row>[];
17
+ /** Saved views persist only field-backed column presentation. */
18
+ viewBacked?: boolean;
19
+ }): {
20
+ gridProps: {
21
+ verticalBorders: boolean;
22
+ showRowIcon: boolean;
23
+ freezeIdentity: boolean;
24
+ wrapCells: boolean;
25
+ alwaysCheckboxes: boolean;
26
+ scale: number;
27
+ optionColors: import("../model/column-schema.js").ListOptionColorOverrides;
28
+ onOptionColorChange: (key: string, value: string, color: ListSelectColor | null) => void;
29
+ dateStyles: import("../model/column-format.js").ListDateStyleOverrides;
30
+ onDateStyleChange: (key: string, style: ListDateStyle) => void;
31
+ durationStyles: import("../model/column-format.js").ListDurationStyleOverrides;
32
+ onDurationStyleChange: (key: string, style: ListDurationStyle) => void;
33
+ showTimeOverrides: import("../model/column-format.js").ListShowTimeOverrides;
34
+ onShowTimeChange: (key: string, show: boolean) => void;
35
+ percentDisplays: import("../model/column-format.js").ListPercentDisplayOverrides;
36
+ onPercentDisplayChange: (key: string, display: PercentDisplay) => void;
37
+ columnState: ListColumnState;
38
+ onColumnStateChange: (next: ListColumnState) => void;
39
+ groupSummary: ListGroupSummaryPart[];
40
+ onGroupSummaryChange: (part: ListGroupSummaryPart, next: boolean) => void;
41
+ aggregates: Record<string, ListAggregateKind>;
42
+ onAggregateChange: (columnId: string, kind: ListAggregateKind) => void;
43
+ viewBacked: boolean;
44
+ numberFormats: ListNumberFormatOverrides;
45
+ onNumberFormatChange: (key: string, patch: {
46
+ decimals?: number | null;
47
+ currency?: string;
48
+ }) => void;
49
+ };
50
+ };