@dxos/react-ui-table 0.8.4-main.d05673bc65 → 0.8.4-main.dfabb4ec29

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 (115) hide show
  1. package/dist/lib/browser/{chunk-BF54SSNL.mjs → chunk-FBURZBPH.mjs} +7 -7
  2. package/dist/lib/browser/chunk-FBURZBPH.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
  4. package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
  5. package/dist/lib/browser/{chunk-PTHMYAAM.mjs → chunk-YGC7LZJN.mjs} +14 -70
  6. package/dist/lib/browser/chunk-YGC7LZJN.mjs.map +7 -0
  7. package/dist/lib/browser/index.mjs +205 -247
  8. package/dist/lib/browser/index.mjs.map +4 -4
  9. package/dist/lib/browser/meta.json +1 -1
  10. package/dist/lib/browser/testing/index.mjs +6 -5
  11. package/dist/lib/browser/testing/index.mjs.map +3 -3
  12. package/dist/lib/browser/translations.mjs +36 -0
  13. package/dist/lib/browser/translations.mjs.map +7 -0
  14. package/dist/lib/browser/types/index.mjs +2 -1
  15. package/dist/lib/node-esm/{chunk-SIRDIPHZ.mjs → chunk-DKKMSVKP.mjs} +7 -7
  16. package/dist/lib/node-esm/chunk-DKKMSVKP.mjs.map +7 -0
  17. package/dist/lib/node-esm/{chunk-GI72MQSG.mjs → chunk-GKIWDEZ7.mjs} +14 -70
  18. package/dist/lib/node-esm/chunk-GKIWDEZ7.mjs.map +7 -0
  19. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
  20. package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
  21. package/dist/lib/node-esm/index.mjs +205 -247
  22. package/dist/lib/node-esm/index.mjs.map +4 -4
  23. package/dist/lib/node-esm/meta.json +1 -1
  24. package/dist/lib/node-esm/testing/index.mjs +6 -5
  25. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  26. package/dist/lib/node-esm/translations.mjs +37 -0
  27. package/dist/lib/node-esm/translations.mjs.map +7 -0
  28. package/dist/lib/node-esm/types/index.mjs +2 -1
  29. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  30. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  31. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  32. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +19 -21
  33. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  34. package/dist/types/src/components/Table/Relations.stories.d.ts +82 -82
  35. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  36. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  37. package/dist/types/src/components/Table/Table.d.ts +20 -21
  38. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  39. package/dist/types/src/components/Table/Table.stories.d.ts +84 -84
  40. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  41. package/dist/types/src/components/Table/TableContent.d.ts +17 -0
  42. package/dist/types/src/components/Table/TableContent.d.ts.map +1 -0
  43. package/dist/types/src/components/Table/TableToolbar.d.ts +21 -0
  44. package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -0
  45. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  46. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  47. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  48. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +22 -24
  49. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  50. package/dist/types/src/components/index.d.ts +0 -1
  51. package/dist/types/src/components/index.d.ts.map +1 -1
  52. package/dist/types/src/components/testing.d.ts.map +1 -1
  53. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  54. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -1
  55. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  56. package/dist/types/src/index.d.ts +0 -2
  57. package/dist/types/src/index.d.ts.map +1 -1
  58. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  59. package/dist/types/src/model/selection-model.d.ts +1 -1
  60. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  61. package/dist/types/src/model/table-model.d.ts +3 -3
  62. package/dist/types/src/model/table-model.d.ts.map +1 -1
  63. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  64. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  65. package/dist/types/src/playwright/playwright.config.d.ts.map +1 -1
  66. package/dist/types/src/translations.d.ts +19 -21
  67. package/dist/types/src/translations.d.ts.map +1 -1
  68. package/dist/types/src/types/Table.d.ts.map +1 -1
  69. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  70. package/dist/types/src/util/query-ast.d.ts.map +1 -1
  71. package/dist/types/src/util/schema.d.ts.map +1 -1
  72. package/dist/types/src/util/signals.d.ts.map +1 -1
  73. package/dist/types/src/util/sort.d.ts.map +1 -1
  74. package/dist/types/src/util/table-buttons.d.ts +20 -20
  75. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  76. package/dist/types/src/util/table-controls.d.ts +4 -4
  77. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  78. package/dist/types/src/util/tag.d.ts.map +1 -1
  79. package/dist/types/tsconfig.tsbuildinfo +1 -1
  80. package/package.json +50 -59
  81. package/src/components/Table/ColumnActionsMenu.tsx +7 -6
  82. package/src/components/Table/DynamicTable.stories.tsx +13 -13
  83. package/src/components/Table/DynamicTable.tsx +5 -13
  84. package/src/components/Table/Relations.stories.tsx +71 -30
  85. package/src/components/Table/RowActionsMenu.tsx +3 -2
  86. package/src/components/Table/Table.stories.tsx +25 -27
  87. package/src/components/Table/Table.tsx +37 -426
  88. package/src/components/Table/TableContent.tsx +421 -0
  89. package/src/components/{TableToolbar → Table}/TableToolbar.tsx +34 -41
  90. package/src/components/TableCellEditor/CellValidationMessage.tsx +0 -1
  91. package/src/components/TableCellEditor/FormCellEditor.tsx +3 -2
  92. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +9 -9
  93. package/src/components/TableCellEditor/TableCellEditor.tsx +10 -8
  94. package/src/components/index.ts +0 -1
  95. package/src/components/testing.ts +9 -9
  96. package/src/index.ts +0 -4
  97. package/src/model/table-model.test.ts +0 -1
  98. package/src/model/table-model.ts +9 -9
  99. package/src/model/table-presentation.test.ts +0 -1
  100. package/src/model/table-presentation.ts +0 -1
  101. package/src/playwright/smoke.spec.ts +3 -3
  102. package/src/testing/useTestTableModel.ts +3 -3
  103. package/src/translations.ts +19 -21
  104. package/src/types/Table.ts +1 -1
  105. package/src/util/dynamic-table.test.ts +3 -3
  106. package/src/util/dynamic-table.ts +4 -4
  107. package/dist/lib/browser/chunk-BF54SSNL.mjs.map +0 -7
  108. package/dist/lib/browser/chunk-PTHMYAAM.mjs.map +0 -7
  109. package/dist/lib/node-esm/chunk-GI72MQSG.mjs.map +0 -7
  110. package/dist/lib/node-esm/chunk-SIRDIPHZ.mjs.map +0 -7
  111. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +0 -21
  112. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +0 -1
  113. package/dist/types/src/components/TableToolbar/index.d.ts +0 -2
  114. package/dist/types/src/components/TableToolbar/index.d.ts.map +0 -1
  115. package/src/components/TableToolbar/index.ts +0 -5
@@ -0,0 +1,421 @@
1
+ //
2
+ // Copyright 2024 DXOS.org
3
+ //
4
+
5
+ import { Atom, RegistryContext, useAtomValue } from '@effect-atom/atom-react';
6
+ import * as String from 'effect/String';
7
+ import React, { type MouseEvent, type WheelEvent, useCallback, useContext, useEffect, useMemo, useState } from 'react';
8
+
9
+ import { type Type } from '@dxos/echo';
10
+ import { log } from '@dxos/log';
11
+ import { useAttention } from '@dxos/react-ui-attention';
12
+ import {
13
+ type DxGridAxisMeta,
14
+ type DxGridElement,
15
+ type DxGridPlane,
16
+ type DxGridPlaneRange,
17
+ Grid,
18
+ type GridContentProps,
19
+ closestCell,
20
+ gridSeparatorBlockEnd,
21
+ gridSeparatorInlineEnd,
22
+ } from '@dxos/react-ui-grid';
23
+ import { DxEditRequest } from '@dxos/react-ui-grid';
24
+ import { composable, composableProps, mx } from '@dxos/ui-theme';
25
+
26
+ import { type InsertRowResult, ModalController, type TableModel, type TablePresentation } from '../../model';
27
+ import { tableButtons, tableControls } from '../../util';
28
+ import { type OnCreateHandler, type TableCellEditorProps, TableValueEditor } from '../TableCellEditor';
29
+ import { ColumnActionsMenu } from './ColumnActionsMenu';
30
+ import { ColumnSettings } from './ColumnSettings';
31
+ import { RowActionsMenu } from './RowActionsMenu';
32
+ import { TableController, useTableContext } from './Table';
33
+
34
+ const columnDefault = { grid: { minSize: 80, maxSize: 640 } };
35
+ const rowDefault = { frozenRowsStart: { readonly: true, focusUnfurl: false } };
36
+ const emptyColumnMeta = Atom.make<DxGridAxisMeta>({ grid: {} });
37
+ const emptyRowsAtom = Atom.make<unknown[]>([]);
38
+ const emptyCellUpdateAtom = Atom.make<number>(0);
39
+
40
+ //
41
+ // Content
42
+ //
43
+
44
+ const TABLE_CONTENT_NAME = 'Table.Content';
45
+
46
+ export type TableContentProps = {
47
+ schema?: Type.AnyEntity;
48
+ model?: TableModel;
49
+ presentation?: TablePresentation;
50
+ // TODO(burdon): Factor out attention.
51
+ ignoreAttention?: boolean;
52
+ onCreate?: OnCreateHandler;
53
+ onRowClick?: (row: any) => void;
54
+ testId?: string;
55
+ };
56
+
57
+ export const TableContent = composable<HTMLDivElement, TableContentProps>(
58
+ ({ schema, model, presentation, ignoreAttention, onCreate, onRowClick, testId, ...props }, forwardedRef) => {
59
+ const registry = useContext(RegistryContext);
60
+ const [dxGrid, setDxGrid] = useState<DxGridElement | null>(null);
61
+ const { hasAttention } = useAttention(model?.id ?? 'table');
62
+ const modals = useMemo(() => new ModalController(registry), [registry]);
63
+ const columnMeta = useAtomValue(model?.columnMeta ?? emptyColumnMeta);
64
+ // Subscribe to rows atom to trigger re-render when rows change.
65
+ const rows = useAtomValue(model?.rows ?? emptyRowsAtom);
66
+ // Subscribe to cell update counter to trigger re-render when individual cells change.
67
+ const cellUpdateCounter = useAtomValue(model?.cellUpdate ?? emptyCellUpdateAtom);
68
+ // Derive column count from columnMeta (reactive) with fallback.
69
+ const columnCount = Object.keys(columnMeta.grid).length || model?.projection.getFields().length || 0;
70
+
71
+ const draftRowCount = model?.getDraftRowCount() ?? 0;
72
+
73
+ const frozen = useMemo(() => {
74
+ const noActionColumn =
75
+ model?.features.dataEditable === false &&
76
+ model?.features.schemaEditable === false &&
77
+ model.rowActions.length === 0;
78
+
79
+ return {
80
+ frozenRowsStart: 1,
81
+ frozenRowsEnd: Math.max(1, draftRowCount),
82
+ frozenColsStart: model?.features.selection.enabled ? 1 : 0,
83
+ frozenColsEnd: noActionColumn ? 0 : 1,
84
+ };
85
+ }, [model, draftRowCount]);
86
+
87
+ const getCells = useCallback<NonNullable<GridContentProps['getCells']>>(
88
+ (range: DxGridPlaneRange, plane: DxGridPlane) => presentation?.getCells(range, plane) ?? {},
89
+ [presentation],
90
+ );
91
+
92
+ useEffect(() => {
93
+ if (!dxGrid || !presentation) {
94
+ return;
95
+ }
96
+
97
+ dxGrid.getCells = getCells;
98
+ }, [dxGrid, presentation, getCells]);
99
+
100
+ // Trigger grid update when rows or cell values change.
101
+ useEffect(() => {
102
+ if (!dxGrid) {
103
+ return;
104
+ }
105
+
106
+ dxGrid.updateCells(true);
107
+ dxGrid.requestUpdate();
108
+ }, [dxGrid, rows, cellUpdateCounter]);
109
+
110
+ const handleInsertRowResult = useCallback(
111
+ (insertResult?: InsertRowResult) => {
112
+ if (insertResult === 'draft') {
113
+ requestAnimationFrame(() => {
114
+ dxGrid?.setFocus({ plane: 'frozenRowsEnd', col: 0, row: 0 });
115
+ dxGrid?.refocus();
116
+ });
117
+ } else {
118
+ requestAnimationFrame(() => {
119
+ dxGrid?.setFocus({ plane: 'grid', col: 0, row: model ? model.getRowCount() - 1 : 0 });
120
+ dxGrid?.refocus();
121
+ });
122
+ }
123
+ },
124
+ [model, dxGrid],
125
+ );
126
+
127
+ const handleSave = useCallback(() => {
128
+ dxGrid?.updateCells(true);
129
+ dxGrid?.requestUpdate();
130
+ }, [dxGrid]);
131
+
132
+ const handleSaveDraftRow = useCallback(
133
+ (rowIndex = 0) => {
134
+ if (model && dxGrid) {
135
+ const didCommitSuccessfully = model.commitDraftRow(rowIndex);
136
+ if (didCommitSuccessfully) {
137
+ requestAnimationFrame(() => {
138
+ dxGrid.scrollToEndRow();
139
+ });
140
+ }
141
+ }
142
+ },
143
+ [model, dxGrid],
144
+ );
145
+
146
+ const handleGridClick = useCallback(
147
+ (event: MouseEvent) => {
148
+ const cell = closestCell(event.target as HTMLElement);
149
+ if (cell) {
150
+ const { row: rowIndex, plane } = cell;
151
+ if (onRowClick) {
152
+ if (plane === 'grid') {
153
+ const row = model?.getRowAt(rowIndex);
154
+ row && onRowClick(row);
155
+ } else {
156
+ onRowClick(cell);
157
+ }
158
+ }
159
+
160
+ if (model?.features.selection.enabled && model?.selection.selectionMode === 'single') {
161
+ model.selection.toggleSelectionForRowIndex(rowIndex);
162
+ }
163
+ }
164
+
165
+ if (!modals) {
166
+ return;
167
+ }
168
+
169
+ const buttonSelector = Object.values(tableButtons)
170
+ .map((button) => `button[${button.attr}]`)
171
+ .join(',');
172
+
173
+ const tableButtonElement = (event.target as HTMLElement).closest(buttonSelector) as HTMLElement;
174
+ if (tableButtonElement) {
175
+ const button = Object.values(tableButtons).find((btn) => tableButtonElement.hasAttribute(btn.attr));
176
+ if (!button) {
177
+ return;
178
+ }
179
+
180
+ modals.setTrigger(tableButtonElement);
181
+ const data = button.getData(tableButtonElement);
182
+ switch (data.type) {
183
+ case 'rowMenu': {
184
+ modals.showRowMenu(data.rowIndex);
185
+ break;
186
+ }
187
+ case 'columnSettings': {
188
+ modals.showColumnMenu(data.fieldId);
189
+ break;
190
+ }
191
+ case 'newColumn': {
192
+ modals.showColumnCreator();
193
+ break;
194
+ }
195
+ case 'sort': {
196
+ model?.toggleSort(data.fieldId);
197
+ break;
198
+ }
199
+ case 'saveDraftRow': {
200
+ handleSaveDraftRow();
201
+ break;
202
+ }
203
+ }
204
+ return;
205
+ }
206
+
207
+ const controlSelector = Object.values(tableControls)
208
+ .map((control) => `input[${control.attr}]`)
209
+ .join(',');
210
+
211
+ const controlElement = (event.target as HTMLElement).closest(controlSelector) as HTMLElement;
212
+ if (controlElement) {
213
+ const control = Object.values(tableControls).find((ctrl) => controlElement.hasAttribute(ctrl.attr));
214
+ if (!control) {
215
+ return;
216
+ }
217
+
218
+ const data = control.getData(controlElement);
219
+ switch (data.type) {
220
+ case 'checkbox': {
221
+ if (data.header) {
222
+ model?.selection.setSelection(model.selection.allRowsSelected ? 'none' : 'all');
223
+ } else {
224
+ model?.selection.toggleSelectionForRowIndex(data.rowIndex);
225
+ }
226
+ break;
227
+ }
228
+ case 'switch': {
229
+ if (model) {
230
+ model.updateCellData({ row: data.rowIndex, col: data.colIndex }, (value) => !value);
231
+ }
232
+ break;
233
+ }
234
+ }
235
+ }
236
+ },
237
+ [model, modals, dxGrid],
238
+ );
239
+
240
+ const handleFocus = useCallback<NonNullable<TableCellEditorProps['onFocus']>>(
241
+ (increment, delta, cell) => {
242
+ if (dxGrid && model) {
243
+ if (cell?.plane === 'grid' && cell?.row >= model.getRowCount() - 1 && increment !== 'col') {
244
+ handleInsertRowResult(draftRowCount < 1 ? model.insertRow() : 'final');
245
+ } else if (cell?.plane === 'frozenRowsEnd' && increment === 'row') {
246
+ handleSaveDraftRow(cell.row);
247
+ handleInsertRowResult(model.insertRow());
248
+ } else {
249
+ dxGrid.refocus(increment, delta);
250
+ }
251
+ }
252
+ },
253
+ [dxGrid, model],
254
+ );
255
+
256
+ const handleKeyDown = useCallback<NonNullable<GridContentProps['onKeyDown']>>(
257
+ (event) => {
258
+ if (!model?.features.dataEditable) {
259
+ return;
260
+ }
261
+
262
+ const cell = closestCell(event.target);
263
+ if (!model || !cell) {
264
+ return;
265
+ }
266
+
267
+ // Handle Meta+C (Copy) and Meta+V (Paste) commands
268
+ if (event.metaKey || event.ctrlKey) {
269
+ switch (event.key) {
270
+ case 'c': {
271
+ // Copy focused cell's text content to clipboard
272
+ try {
273
+ const cellData = model.getCellData(cell);
274
+ const textContent = cellData?.toString() ?? '';
275
+ void navigator.clipboard.writeText(textContent);
276
+ event.preventDefault();
277
+ } catch (error) {
278
+ log.catch(error);
279
+ }
280
+ break;
281
+ }
282
+ case 'v': {
283
+ // Paste clipboard content to focused cell
284
+ event.preventDefault();
285
+ void navigator.clipboard.readText().then((clipboardText) => {
286
+ try {
287
+ // Attempt to set the cell's content to clipboard content
288
+ model.setCellData(cell, String.trim(clipboardText).replace(/[\n\r]+/, ' '));
289
+ handleSave();
290
+ } catch {
291
+ // If validation fails, emit a DxEditRequest event with initialContent from clipboard
292
+ // TODO(thure): Should `dx-grid` expose a method like this?
293
+ const cellElement = (event.target as HTMLElement).closest(
294
+ '[data-dx-grid-action="cell"]',
295
+ ) as HTMLElement;
296
+ if (cellElement) {
297
+ const rect = cellElement.getBoundingClientRect();
298
+ const editRequest = new DxEditRequest({
299
+ cellIndex: `${cell.plane},${cell.col},${cell.row}`,
300
+ cellBox: {
301
+ insetInlineStart: rect.left,
302
+ insetBlockStart: rect.top,
303
+ inlineSize: rect.width,
304
+ blockSize: rect.height,
305
+ },
306
+ cellElement,
307
+ initialContent: clipboardText,
308
+ });
309
+ cellElement.dispatchEvent(editRequest);
310
+ }
311
+ }
312
+ });
313
+ break;
314
+ }
315
+ }
316
+ }
317
+
318
+ switch (event.key) {
319
+ case 'Backspace':
320
+ case 'Delete': {
321
+ try {
322
+ model.setCellData(cell, undefined);
323
+ event.preventDefault();
324
+ handleSave();
325
+ } catch {
326
+ // Delete results in a validation error; don’t prevent default so dx-grid can emit an edit request.
327
+ }
328
+ break;
329
+ }
330
+ }
331
+ },
332
+ [model, dxGrid, handleSave],
333
+ );
334
+
335
+ const handleAxisResize = useCallback<NonNullable<GridContentProps['onAxisResize']>>(
336
+ (event) => {
337
+ if (event.axis === 'col') {
338
+ const columnIndex = parseInt(event.index, 10);
339
+ model?.setColumnWidth(columnIndex, event.size);
340
+ }
341
+ },
342
+ [model],
343
+ );
344
+
345
+ const handleWheel = useCallback(
346
+ (event: WheelEvent) => {
347
+ if (!ignoreAttention && !hasAttention) {
348
+ event.stopPropagation();
349
+ }
350
+ },
351
+ [hasAttention, ignoreAttention],
352
+ );
353
+
354
+ const handleNewColumn = useCallback(() => {
355
+ const columns = model?.getColumnCount();
356
+ if (dxGrid && columns) {
357
+ dxGrid.scrollToColumn(columns - 1);
358
+ }
359
+ }, [model, dxGrid]);
360
+
361
+ // Publish controller to Root.
362
+ const { controllerRef } = useTableContext(TABLE_CONTENT_NAME);
363
+ controllerRef.current = useMemo<TableController>(() => {
364
+ if (!dxGrid || !presentation) {
365
+ return {};
366
+ }
367
+
368
+ return {
369
+ update: (cell) => {
370
+ if (cell) {
371
+ dxGrid.updateIfWithinBounds(cell, true);
372
+ } else {
373
+ dxGrid.updateCells(true);
374
+ dxGrid.requestUpdate();
375
+ }
376
+ },
377
+ handleInsertRowResult,
378
+ };
379
+ }, [dxGrid, model, presentation]);
380
+
381
+ if (!model || !modals) {
382
+ return <span role='none' className='dx-attention-surface' />;
383
+ }
384
+
385
+ return (
386
+ <div {...composableProps(props, { classNames: 'dx-container relative' })} ref={forwardedRef}>
387
+ <Grid.Root id={model.id ?? 'table-grid'}>
388
+ <TableValueEditor
389
+ model={model}
390
+ modals={modals}
391
+ schema={schema}
392
+ onFocus={handleFocus}
393
+ onSave={handleSave}
394
+ onCreate={onCreate}
395
+ />
396
+ <Grid.Content
397
+ className={mx('[--dx-grid-base:var(--base-surface)]', gridSeparatorInlineEnd, gridSeparatorBlockEnd)}
398
+ frozen={frozen}
399
+ columns={columnMeta}
400
+ columnDefault={columnDefault}
401
+ rowDefault={rowDefault}
402
+ limitRows={rows.length}
403
+ limitColumns={columnCount}
404
+ overscroll='trap'
405
+ onAxisResize={handleAxisResize}
406
+ onClick={handleGridClick}
407
+ onKeyDownCapture={handleKeyDown}
408
+ onWheelCapture={handleWheel}
409
+ {...(testId && { 'data-testid': testId })}
410
+ ref={setDxGrid}
411
+ />
412
+ <RowActionsMenu model={model} modals={modals} />
413
+ <ColumnActionsMenu model={model} modals={modals} />
414
+ <ColumnSettings model={model} modals={modals} onNewColumn={handleNewColumn} />
415
+ </Grid.Root>
416
+ </div>
417
+ );
418
+ },
419
+ );
420
+
421
+ TableContent.displayName = TABLE_CONTENT_NAME;
@@ -5,19 +5,20 @@
5
5
  import { Atom, RegistryContext } from '@effect-atom/atom-react';
6
6
  import React, { useContext, useEffect, useMemo } from 'react';
7
7
 
8
- import { type ThemedClassName } from '@dxos/react-ui';
9
8
  import {
10
9
  type ActionGraphEdges,
11
10
  type ActionGraphNodes,
12
11
  type ActionGraphProps,
13
12
  Menu,
14
13
  type MenuAction,
14
+ MenuRootProps,
15
15
  createGapSeparator,
16
16
  createMenuAction,
17
17
  useMenuActions,
18
18
  } from '@dxos/react-ui-menu';
19
+ import { composable, composableProps } from '@dxos/ui-theme';
19
20
 
20
- import { translationKey } from '../../translations';
21
+ import { translationKey } from '#translations';
21
22
 
22
23
  export type TableToolbarActionProperties = { type: TableToolbarActionType };
23
24
 
@@ -27,17 +28,6 @@ export type TableToolbarActionType = 'add-row' | 'comment' | 'save-view';
27
28
 
28
29
  type TableToolbarState = Partial<{ viewDirty: boolean }>;
29
30
 
30
- // TODO(burdon): Radix style layout.
31
-
32
- export type TableToolbarProps = ThemedClassName<
33
- TableToolbarState & {
34
- onAdd?: () => void;
35
- onSave?: () => void;
36
- attendableId?: string;
37
- customActions?: Atom.Atom<ActionGraphProps>;
38
- }
39
- >;
40
-
41
31
  const createTableToolbarActions = ({
42
32
  stateAtom,
43
33
  onAdd,
@@ -55,7 +45,7 @@ const createTableToolbarActions = ({
55
45
  const add = createMenuAction<TableToolbarActionProperties>('add-row', onAdd, {
56
46
  type: 'add-row' as const,
57
47
  icon: 'ph--plus--regular',
58
- label: ['add row label', { ns: translationKey }],
48
+ label: ['add-row.label', { ns: translationKey }],
59
49
  testId: 'table.toolbar.add-row',
60
50
  });
61
51
  nodes.push(add);
@@ -65,7 +55,7 @@ const createTableToolbarActions = ({
65
55
  const save = createMenuAction<TableToolbarActionProperties>('save-view', onSave, {
66
56
  type: 'save-view' as const,
67
57
  icon: 'ph--floppy-disk--regular',
68
- label: ['save view label', { ns: translationKey }],
58
+ label: ['save-view.label', { ns: translationKey }],
69
59
  testId: 'table.toolbar.save-view',
70
60
  iconOnly: false,
71
61
  hidden: !state.viewDirty,
@@ -87,32 +77,35 @@ const createTableToolbarActions = ({
87
77
  };
88
78
  });
89
79
 
90
- export const TableToolbar = ({
91
- classNames,
92
- viewDirty,
93
- attendableId,
94
- onAdd,
95
- onSave,
96
- customActions,
97
- ...props
98
- }: TableToolbarProps) => {
99
- const registry = useContext(RegistryContext);
100
- const stateAtom = useMemo(() => Atom.make<TableToolbarState>({ viewDirty }), []);
80
+ export type TableToolbarProps = Pick<MenuRootProps, 'attendableId'> &
81
+ TableToolbarState & {
82
+ onAdd?: () => void;
83
+ onSave?: () => void;
84
+ customActions?: Atom.Atom<ActionGraphProps>;
85
+ };
86
+
87
+ export const TableToolbar = composable<HTMLDivElement, TableToolbarProps>(
88
+ ({ attendableId, viewDirty, onAdd, onSave, customActions, ...props }, forwardedRef) => {
89
+ const registry = useContext(RegistryContext);
90
+ const stateAtom = useMemo(() => Atom.make<TableToolbarState>({ viewDirty }), []);
91
+
92
+ // Update state.viewDirty when the prop changes.
93
+ useEffect(() => {
94
+ registry.set(stateAtom, { viewDirty });
95
+ }, [registry, stateAtom, viewDirty]);
101
96
 
102
- // Update state.viewDirty when the prop changes.
103
- useEffect(() => {
104
- registry.set(stateAtom, { viewDirty });
105
- }, [registry, stateAtom, viewDirty]);
97
+ const actionsCreator = useMemo(
98
+ () => createTableToolbarActions({ stateAtom, onAdd, onSave, customActions }),
99
+ [stateAtom, onAdd, onSave, customActions],
100
+ );
101
+ const menuActions = useMenuActions(actionsCreator);
106
102
 
107
- const actionsCreator = useMemo(
108
- () => createTableToolbarActions({ stateAtom, onAdd, onSave, customActions }),
109
- [stateAtom, onAdd, onSave, customActions],
110
- );
111
- const menu = useMenuActions(actionsCreator);
103
+ return (
104
+ <Menu.Root {...menuActions} attendableId={attendableId}>
105
+ <Menu.Toolbar {...composableProps(props)} ref={forwardedRef} />
106
+ </Menu.Root>
107
+ );
108
+ },
109
+ );
112
110
 
113
- return (
114
- <Menu.Root {...menu} attendableId={attendableId}>
115
- <Menu.Toolbar {...props} classNames={classNames} />
116
- </Menu.Root>
117
- );
118
- };
111
+ TableToolbar.displayName = 'TableToolbar';
@@ -27,7 +27,6 @@ export const CellValidationMessage = ({
27
27
 
28
28
  return (
29
29
  <div
30
- role='none'
31
30
  className={`absolute ${bgClass} ${textClass} rounded-h-sm text-xs p-1`}
32
31
  style={{
33
32
  ...{ '--dx-grid-cell-width': `${box?.inlineSize ?? 200}px` },
@@ -14,11 +14,12 @@ import { parseCellIndex, useGridContext } from '@dxos/react-ui-grid';
14
14
  import { type FieldProjection } from '@dxos/schema';
15
15
  import { getDeep, isTruthy, setDeep } from '@dxos/util';
16
16
 
17
+ import { translationKey } from '#translations';
18
+
17
19
  import { type ModalController, type TableModel, type TableRow } from '../../model';
18
- import { translationKey } from '../../translations';
19
20
  import { narrowSchema } from '../../util';
20
21
 
21
- const createOptionLabel: Label = ['create new object label', { ns: translationKey }];
22
+ const createOptionLabel: Label = ['create-new-object.label', { ns: translationKey }];
22
23
 
23
24
  export type OnCreateHandler = (schema: Type.AnyEntity, values: any) => Parameters<typeof Ref.make>[0];
24
25
 
@@ -7,25 +7,25 @@ import React from 'react';
7
7
 
8
8
  import { Obj } from '@dxos/echo';
9
9
  import { View } from '@dxos/echo';
10
- import { faker } from '@dxos/random';
10
+ import { random } from '@dxos/random';
11
11
  import { withClientProvider } from '@dxos/react-client/testing';
12
- import { withLayout, withTheme } from '@dxos/react-ui/testing';
13
12
  import { Grid, type GridEditing, defaultRowSize } from '@dxos/react-ui-grid';
13
+ import { withLayout, withTheme } from '@dxos/react-ui/testing';
14
14
  import { ViewModel } from '@dxos/schema';
15
15
  import { Task } from '@dxos/types';
16
16
 
17
+ import { translations } from '#translations';
18
+
17
19
  import { useTestTableModel } from '../../testing';
18
- import { translations } from '../../translations';
19
20
  import { Table } from '../../types';
20
-
21
21
  import { TableCellEditor } from './TableCellEditor';
22
22
 
23
- type StoryProps = {
23
+ type DefaultStoryProps = {
24
24
  editing: GridEditing;
25
25
  };
26
26
 
27
27
  // TODO(burdon): Broken layout.
28
- const DefaultStory = ({ editing }: StoryProps) => {
28
+ const DefaultStory = ({ editing }: DefaultStoryProps) => {
29
29
  const { model, table } = useTestTableModel();
30
30
 
31
31
  if (!model || !table) {
@@ -59,9 +59,9 @@ const meta = {
59
59
  Array.from({ length: 10 }).forEach(() => {
60
60
  space.db.add(
61
61
  Obj.make(Task.Task, {
62
- title: faker.person.fullName(),
63
- status: faker.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
64
- description: faker.lorem.sentence(),
62
+ title: random.person.fullName(),
63
+ status: random.helpers.arrayElement(['todo', 'in-progress', 'done'] as const),
64
+ description: random.lorem.sentence(),
65
65
  }),
66
66
  );
67
67
  });
@@ -25,16 +25,9 @@ import {
25
25
  import { type FieldProjection } from '@dxos/schema';
26
26
 
27
27
  import { type ModalController, type TableModel } from '../../model';
28
-
29
28
  import { CellValidationMessage } from './CellValidationMessage';
30
29
  import { FormCellEditor, type OnCreateHandler } from './FormCellEditor';
31
30
 
32
- const editorSlots = {
33
- scroll: {
34
- className: '!py-(--dx-grid-cell-editor-padding-block)',
35
- },
36
- };
37
-
38
31
  /**
39
32
  * Option to create new object/value.
40
33
  */
@@ -250,7 +243,16 @@ export const TableCellEditor = ({
250
243
  return (
251
244
  <>
252
245
  <CellValidationMessage validationError={validationError} variant={validationVariant} __gridScope={__gridScope} />
253
- <GridCellEditor extensions={extensions} getCellContent={getCellContent} onBlur={handleBlur} slots={editorSlots} />
246
+ <GridCellEditor
247
+ extensions={extensions}
248
+ slots={{
249
+ content: {
250
+ className: '!py-(--dx-grid-cell-editor-padding-block)',
251
+ },
252
+ }}
253
+ getCellContent={getCellContent}
254
+ onBlur={handleBlur}
255
+ />
254
256
  </>
255
257
  );
256
258
  };
@@ -3,4 +3,3 @@
3
3
  //
4
4
 
5
5
  export * from './Table';
6
- export * from './TableToolbar';
@@ -9,7 +9,7 @@ import { useEffect } from 'react';
9
9
  import { Format, Type } from '@dxos/echo';
10
10
  import { TypeEnum } from '@dxos/echo/internal';
11
11
  import { setValue } from '@dxos/effect';
12
- import { faker } from '@dxos/random';
12
+ import { random } from '@dxos/random';
13
13
  import { type ProjectionModel } from '@dxos/schema';
14
14
 
15
15
  export const TestSchema = Schema.Struct({
@@ -37,10 +37,10 @@ export type TestItem = {
37
37
  export const createItemsAtom = (n: number) => {
38
38
  return Atom.make<{ data: TestItem[] }>({
39
39
  data: Array.from({ length: n }, () => ({
40
- name: faker.person.fullName(),
41
- age: faker.number.int({ min: 20, max: 70 }),
42
- active: faker.datatype.boolean(),
43
- netWorth: faker.number.int(),
40
+ name: random.person.fullName(),
41
+ age: random.number.int({ min: 20, max: 70 }),
42
+ active: random.datatype.boolean(),
43
+ netWorth: random.number.int(),
44
44
  })),
45
45
  }).pipe(Atom.keepAlive);
46
46
  };
@@ -50,10 +50,10 @@ export const createItemsAtom = (n: number) => {
50
50
  */
51
51
  export const createItems = (n: number): TestItem[] => {
52
52
  return Array.from({ length: n }, () => ({
53
- name: faker.person.fullName(),
54
- age: faker.number.int({ min: 20, max: 70 }),
55
- active: faker.datatype.boolean(),
56
- netWorth: faker.number.int(),
53
+ name: random.person.fullName(),
54
+ age: random.number.int({ min: 20, max: 70 }),
55
+ active: random.datatype.boolean(),
56
+ netWorth: random.number.int(),
57
57
  }));
58
58
  };
59
59