@dxos/react-ui-table 0.8.4-main.2e9d522 → 0.8.4-main.548089c

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 (132) hide show
  1. package/dist/lib/browser/chunk-2PFAPQL4.mjs +66 -0
  2. package/dist/lib/browser/chunk-2PFAPQL4.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-5XLSHLOG.mjs → chunk-GS2UNGJK.mjs} +493 -469
  4. package/dist/lib/browser/chunk-GS2UNGJK.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +614 -696
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +14 -9
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/browser/types/index.mjs +3 -3
  11. package/dist/lib/node-esm/chunk-6POOFFYF.mjs +67 -0
  12. package/dist/lib/node-esm/chunk-6POOFFYF.mjs.map +7 -0
  13. package/dist/lib/node-esm/{chunk-Y66YLSTC.mjs → chunk-TRR3C5NX.mjs} +493 -469
  14. package/dist/lib/node-esm/chunk-TRR3C5NX.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +614 -696
  16. package/dist/lib/node-esm/index.mjs.map +4 -4
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +14 -9
  19. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  20. package/dist/lib/node-esm/types/index.mjs +3 -3
  21. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +1 -1
  22. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/ColumnSettings.d.ts +1 -1
  24. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/DynamicTable.d.ts +2 -2
  26. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +51 -3
  28. package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/Table/Relations.stories.d.ts +107 -0
  30. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -0
  31. package/dist/types/src/components/Table/RowActionsMenu.d.ts +1 -1
  32. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  33. package/dist/types/src/components/Table/Table.d.ts +8 -4
  34. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  35. package/dist/types/src/components/Table/Table.stories.d.ts +42 -4
  36. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  37. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +1 -1
  38. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +12 -6
  39. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  40. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +12 -17
  41. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  42. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +39 -4
  43. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  44. package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
  45. package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -1
  46. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +2 -2
  47. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  48. package/dist/types/src/components/testing.d.ts +3 -3
  49. package/dist/types/src/components/testing.d.ts.map +1 -1
  50. package/dist/types/src/hooks/useAddRow.d.ts +3 -2
  51. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  52. package/dist/types/src/hooks/useTableModel.d.ts +4 -4
  53. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  54. package/dist/types/src/model/modal-controller.d.ts +0 -7
  55. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  56. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  57. package/dist/types/src/model/table-model.d.ts +11 -9
  58. package/dist/types/src/model/table-model.d.ts.map +1 -1
  59. package/dist/types/src/model/table-presentation.d.ts +2 -1
  60. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  61. package/dist/types/src/model/table-sorting.d.ts +3 -4
  62. package/dist/types/src/model/table-sorting.d.ts.map +1 -1
  63. package/dist/types/src/testing/useTestTableModel.d.ts +3 -22
  64. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  65. package/dist/types/src/translations.d.ts +2 -2
  66. package/dist/types/src/types/index.d.ts +1 -1
  67. package/dist/types/src/types/index.d.ts.map +1 -1
  68. package/dist/types/src/types/schema.d.ts +25 -5
  69. package/dist/types/src/types/schema.d.ts.map +1 -1
  70. package/dist/types/src/util/dynamic-table.d.ts +5 -6
  71. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  72. package/dist/types/src/util/index.d.ts +0 -1
  73. package/dist/types/src/util/index.d.ts.map +1 -1
  74. package/dist/types/src/util/schema.d.ts +1 -1
  75. package/dist/types/src/util/schema.d.ts.map +1 -1
  76. package/dist/types/src/util/table-buttons.d.ts.map +1 -1
  77. package/dist/types/src/util/table-controls.d.ts.map +1 -1
  78. package/dist/types/tsconfig.tsbuildinfo +1 -1
  79. package/package.json +57 -51
  80. package/src/components/Table/ColumnActionsMenu.tsx +1 -1
  81. package/src/components/Table/ColumnSettings.tsx +1 -1
  82. package/src/components/Table/DynamicTable.stories.tsx +18 -14
  83. package/src/components/Table/DynamicTable.tsx +8 -10
  84. package/src/components/Table/Relations.stories.tsx +242 -0
  85. package/src/components/Table/RowActionsMenu.tsx +23 -15
  86. package/src/components/Table/Table.stories.tsx +72 -60
  87. package/src/components/Table/Table.tsx +147 -117
  88. package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
  89. package/src/components/TableCellEditor/FormCellEditor.tsx +153 -42
  90. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +25 -64
  91. package/src/components/TableCellEditor/TableCellEditor.tsx +74 -224
  92. package/src/components/TableCellEditor/index.ts +1 -0
  93. package/src/components/TableToolbar/TableToolbar.tsx +33 -23
  94. package/src/components/testing.ts +2 -2
  95. package/src/hooks/useAddRow.ts +7 -5
  96. package/src/hooks/useTableModel.ts +6 -6
  97. package/src/model/modal-controller.ts +1 -29
  98. package/src/model/selection-model.ts +3 -2
  99. package/src/model/table-model.test.ts +20 -11
  100. package/src/model/table-model.ts +46 -31
  101. package/src/model/table-presentation.test.ts +24 -22
  102. package/src/model/table-presentation.ts +74 -33
  103. package/src/model/table-sorting.ts +17 -8
  104. package/src/playwright/TableManager.ts +1 -1
  105. package/src/playwright/smoke.spec.ts +131 -37
  106. package/src/testing/useTestTableModel.ts +12 -8
  107. package/src/translations.ts +2 -2
  108. package/src/types/index.ts +1 -1
  109. package/src/types/schema.ts +63 -6
  110. package/src/util/dynamic-table.ts +16 -17
  111. package/src/util/index.ts +0 -1
  112. package/src/util/schema.ts +4 -4
  113. package/src/util/table-buttons.ts +4 -3
  114. package/src/util/table-controls.ts +4 -1
  115. package/dist/lib/browser/chunk-5XLSHLOG.mjs.map +0 -7
  116. package/dist/lib/browser/chunk-L2LSB6KV.mjs +0 -18
  117. package/dist/lib/browser/chunk-L2LSB6KV.mjs.map +0 -7
  118. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs +0 -20
  119. package/dist/lib/node-esm/chunk-NXZ4CJYX.mjs.map +0 -7
  120. package/dist/lib/node-esm/chunk-Y66YLSTC.mjs.map +0 -7
  121. package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
  122. package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
  123. package/dist/types/src/components/Table/relations.stories.d.ts +0 -9
  124. package/dist/types/src/components/Table/relations.stories.d.ts.map +0 -1
  125. package/dist/types/src/components/TableCellEditor/extension.d.ts +0 -13
  126. package/dist/types/src/components/TableCellEditor/extension.d.ts.map +0 -1
  127. package/dist/types/src/util/table.d.ts +0 -11
  128. package/dist/types/src/util/table.d.ts.map +0 -1
  129. package/src/components/Table/CreateRefPanel.tsx +0 -86
  130. package/src/components/Table/relations.stories.tsx +0 -116
  131. package/src/components/TableCellEditor/extension.ts +0 -61
  132. package/src/util/table.ts +0 -49
@@ -59,6 +59,6 @@ export class TableManager {
59
59
  await this.page.getByLabel(`format ${format}`).click();
60
60
  await this.page.getByPlaceholder('Property label.').click();
61
61
  await this.page.getByPlaceholder('Property label.').fill(label);
62
- await this.page.getByRole('button', { name: 'button save' }).click();
62
+ await this.page.getByRole('button', { name: 'save button' }).click();
63
63
  }
64
64
  }
@@ -4,16 +4,20 @@
4
4
 
5
5
  import { expect, test } from '@playwright/test';
6
6
 
7
+ import { type DxGrid } from '@dxos/lit-grid';
8
+ import { faker } from '@dxos/random';
7
9
  import { setupPage, storybookUrl } from '@dxos/test-utils/playwright';
8
10
 
9
11
  import { TableManager } from './TableManager';
10
12
 
11
13
  const storyUrl = storybookUrl('ui-react-ui-table-table--default', 9004);
14
+ const relationsStoryUrl = storybookUrl('ui-react-ui-table-relations--default', 9004);
12
15
 
13
16
  // NOTE(ZaymonFC): This test suite relies on the faker seed being set to 0 in the story.
14
17
  test.describe('Table', () => {
15
18
  test('Loads', async ({ browser, browserName }) => {
16
19
  test.skip(browserName === 'webkit');
20
+ test.skip(browserName === 'firefox');
17
21
  const { page } = await setupPage(browser, { url: storyUrl });
18
22
  const table = new TableManager(page);
19
23
 
@@ -23,6 +27,7 @@ test.describe('Table', () => {
23
27
 
24
28
  test('sort', async ({ browser, browserName }) => {
25
29
  test.skip(browserName === 'webkit');
30
+ test.skip(browserName === 'firefox');
26
31
  const { page } = await setupPage(browser, { url: storyUrl });
27
32
  const table = new TableManager(page);
28
33
 
@@ -39,6 +44,7 @@ test.describe('Table', () => {
39
44
 
40
45
  test('selection', async ({ browser, browserName }) => {
41
46
  test.skip(browserName === 'webkit');
47
+ test.skip(browserName === 'firefox');
42
48
  const { page } = await setupPage(browser, { url: storyUrl });
43
49
  const table = new TableManager(page);
44
50
 
@@ -60,6 +66,7 @@ test.describe('Table', () => {
60
66
 
61
67
  test('delete row', async ({ browser, browserName }) => {
62
68
  test.skip(browserName === 'webkit');
69
+ test.skip(browserName === 'firefox');
63
70
  const { page } = await setupPage(browser, { url: storyUrl });
64
71
  const table = new TableManager(page);
65
72
 
@@ -71,6 +78,7 @@ test.describe('Table', () => {
71
78
 
72
79
  test('delete row--select all', async ({ browser, browserName }) => {
73
80
  test.skip(browserName === 'webkit');
81
+ test.skip(browserName === 'firefox');
74
82
  const { page } = await setupPage(browser, { url: storyUrl });
75
83
  const table = new TableManager(page);
76
84
 
@@ -88,6 +96,7 @@ test.describe('Table', () => {
88
96
 
89
97
  test('delete column', async ({ browser, browserName }) => {
90
98
  test.skip(browserName === 'webkit');
99
+ test.skip(browserName === 'firefox');
91
100
  const { page } = await setupPage(browser, { url: storyUrl });
92
101
  const table = new TableManager(page);
93
102
 
@@ -114,6 +123,7 @@ test.describe('Table', () => {
114
123
  // Rest of add column test remains the same as it's a more complex flow.
115
124
  test('add column', async ({ browser, browserName }) => {
116
125
  test.skip(browserName === 'webkit');
126
+ test.skip(browserName === 'firefox');
117
127
  const { page } = await setupPage(browser, { url: storyUrl });
118
128
  const table = new TableManager(page);
119
129
 
@@ -126,44 +136,9 @@ test.describe('Table', () => {
126
136
  await page.close();
127
137
  });
128
138
 
129
- test('reference > reference / create new object', async ({ browser, browserName }) => {
130
- test.skip(browserName === 'webkit');
131
- const { page } = await setupPage(browser, { url: storyUrl });
132
- const table = new TableManager(page);
133
-
134
- await table.grid.ready();
135
-
136
- // Reference existing object.
137
- // Scroll over to the manager column.
138
- await table.grid.panByWheel(10000, 0);
139
-
140
- await table.grid.cell(4, 0, 'grid').click();
141
- // TODO(wittjosiah): Surprisingly long delay needed here.
142
- await page.keyboard.press('A', { delay: 1_000 });
143
- await page.keyboard.press('u', { delay: 1_000 });
144
- await page.getByRole('option', { name: 'Aut.' }).click();
145
-
146
- // Assert that the value is shown in the cell.
147
- await expect(page.getByRole('gridcell', { name: 'Aut.' }).first()).toBeVisible();
148
-
149
- // Create new object.
150
- await table.grid.cell(4, 1, 'grid').click();
151
- // TODO(wittjosiah): Surprisingly long delay needed here.
152
- await page.keyboard.type('t', { delay: 1_000 });
153
- await page.keyboard.type('e', { delay: 1_000 });
154
- await page.keyboard.type('s', { delay: 1_000 });
155
- await page.keyboard.type('t', { delay: 1_000 });
156
- await page.getByText('Create new object', { exact: false }).click();
157
- await page.getByTestId('save-button').click();
158
-
159
- // Scroll to the left.
160
- await page.getByRole('gridcell', { name: 'test' }).first().click();
161
-
162
- await page.close();
163
- });
164
-
165
- test('test toggles', async ({ browser, browserName }) => {
139
+ test.skip('test toggles', async ({ browser, browserName }) => {
166
140
  test.skip(browserName === 'webkit');
141
+ test.skip(browserName === 'firefox');
167
142
  const { page } = await setupPage(browser, { url: storyUrl });
168
143
  const table = new TableManager(page);
169
144
 
@@ -183,4 +158,123 @@ test.describe('Table', () => {
183
158
 
184
159
  await page.close();
185
160
  });
161
+
162
+ // TODO(wittjosiah): Remove? Conflicts with story play function which is run as a unit test anyways.
163
+ test.skip('extant relations work as expected', async ({ browser, browserName }) => {
164
+ test.skip(browserName === 'webkit');
165
+ test.skip(browserName === 'firefox');
166
+ const { page } = await setupPage(browser, { url: relationsStoryUrl });
167
+
168
+ // Wait for the page to load
169
+ await page.locator('dx-grid > .dx-grid').nth(1).waitFor({ state: 'visible' });
170
+
171
+ // Find the dx-grid element for the contactModel (second table)
172
+ // The contactModel is used in the second Table.Main component in the story
173
+ const dxGrid = page.locator('dx-grid').nth(1);
174
+ await dxGrid.waitFor({ state: 'visible' });
175
+
176
+ // Scroll to the last column (column 4)
177
+ await dxGrid.evaluate(async (dxGridElement: DxGrid) => {
178
+ dxGridElement.scrollToColumn(4);
179
+ });
180
+
181
+ // Click on the cell at aria-rowindex=0 aria-colindex=4 to focus it
182
+ const targetCell = dxGrid.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="4"]');
183
+ await targetCell.click();
184
+
185
+ // Click again to engage edit mode
186
+ await page.keyboard.press('Enter');
187
+
188
+ // Click on the combobox to open options
189
+ await page.getByRole('combobox').click();
190
+ await page.pause();
191
+ await page.getByPlaceholder('Search…').focus();
192
+
193
+ // Type the first few letters of an org name.
194
+ const orgName =
195
+ (await page
196
+ .locator('dx-grid')
197
+ .nth(0)
198
+ .locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="0"] .dx-grid__cell__content')
199
+ .textContent()) ?? 'never';
200
+ await page.keyboard.type(orgName.substring(0, 4), { delay: 500 });
201
+
202
+ // Assert that there is an element with aria-selected on the page
203
+ await expect(page.locator('[role="option"][aria-selected]')).toBeVisible();
204
+
205
+ // Type the enter key
206
+ await page.keyboard.press('Enter');
207
+
208
+ // Save the result
209
+ await page.getByTestId('save-button').click();
210
+
211
+ // Assert that the cell element has the org name
212
+ await expect(targetCell).toHaveText(orgName);
213
+
214
+ await page.close();
215
+ });
216
+
217
+ // TODO(wittjosiah): Remove? Conflicts with story play function which is run as a unit test anyways.
218
+ test.skip('new relations work as expected', async ({ browser, browserName }) => {
219
+ test.skip(browserName === 'webkit');
220
+ test.skip(browserName === 'firefox');
221
+ const { page } = await setupPage(browser, { url: relationsStoryUrl });
222
+
223
+ // Wait for the page to load
224
+ await page.locator('dx-grid > .dx-grid').nth(1).waitFor({ state: 'visible' });
225
+
226
+ // Find the dx-grid element for the contactModel (second table)
227
+ // The contactModel is used in the second Table.Main component in the story
228
+ const dxGrid = page.locator('dx-grid').nth(1);
229
+ await dxGrid.waitFor({ state: 'visible' });
230
+
231
+ // Scroll to the last column (column 4)
232
+ await dxGrid.evaluate(async (dxGridElement: DxGrid) => {
233
+ dxGridElement.scrollToColumn(4);
234
+ });
235
+
236
+ // Click on the cell at aria-rowindex=0 aria-colindex=8 to focus it
237
+ const targetCell = dxGrid.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="4"]');
238
+ await targetCell.click();
239
+
240
+ // Click again to engage edit mode
241
+ await page.keyboard.press('Enter');
242
+
243
+ // Click on the combobox to open options
244
+ await page.getByRole('combobox').click();
245
+ await page.getByPlaceholder('Search…').focus();
246
+
247
+ // Type the first few letters of an org name.
248
+ const orgName = 'Sally';
249
+ await page.keyboard.type(orgName, { delay: 500 });
250
+
251
+ // Assert that there is an element with aria-selected on the page
252
+ await expect(page.locator('[role="option"][aria-selected]')).toBeVisible();
253
+
254
+ // Type the enter key
255
+ await page.keyboard.press('Enter');
256
+ await page.pause();
257
+
258
+ // Click the save button in the popover
259
+ await page.getByTestId('create-referenced-object-form').getByTestId('save-button').click();
260
+
261
+ // Assert that the cell element has the org name
262
+ await expect(targetCell).toHaveText(orgName);
263
+
264
+ // Make a change to a non-ref cell to check that populated refs don’t cause problems with snapshots or schemas.
265
+ await dxGrid.evaluate(async (dxGridElement: DxGrid) => {
266
+ dxGridElement.scrollToColumn(6);
267
+ });
268
+
269
+ const nonRefContent = faker.lorem.words(3);
270
+ const nonRefCell = dxGrid.locator('[data-dx-grid-plane="grid"] [aria-rowindex="0"][aria-colindex="6"]');
271
+ await nonRefCell.click();
272
+ await page.keyboard.press('Enter');
273
+ await page.getByTestId('grid.cell-editor').waitFor({ state: 'visible' });
274
+ await page.keyboard.type(nonRefContent, { delay: 500 });
275
+ await page.keyboard.press('Enter');
276
+ await expect(nonRefCell).toHaveText(nonRefContent);
277
+
278
+ await page.close();
279
+ });
186
280
  });
@@ -4,16 +4,16 @@
4
4
 
5
5
  import { useCallback, useMemo, useRef } from 'react';
6
6
 
7
- import { isMutable, toJsonSchema } from '@dxos/echo-schema';
7
+ import { isMutable, toJsonSchema } from '@dxos/echo/internal';
8
8
  import { useGlobalFilteredObjects } from '@dxos/plugin-search';
9
9
  import { faker } from '@dxos/random';
10
10
  import { useClient } from '@dxos/react-client';
11
11
  import { Filter, useQuery, useSchema } from '@dxos/react-client/echo';
12
12
  import { useClientProvider } from '@dxos/react-client/testing';
13
- import { DataType, ProjectionModel } from '@dxos/schema';
13
+ import { ProjectionModel, View, getTypenameFromQuery } from '@dxos/schema';
14
14
 
15
15
  import { type TableController } from '../components';
16
- import { useTableModel, useAddRow } from '../hooks';
16
+ import { useAddRow, useTableModel } from '../hooks';
17
17
  import { TablePresentation } from '../model';
18
18
 
19
19
  faker.seed(0); // NOTE(ZaymonFC): Required for smoke tests.
@@ -26,14 +26,17 @@ export const useTestTableModel = () => {
26
26
  const client = useClient();
27
27
  const { space } = useClientProvider();
28
28
 
29
- const views = useQuery(space, Filter.type(DataType.View));
29
+ const views = useQuery(space, Filter.type(View.View));
30
30
  const view = useMemo(() => views.at(0), [views]);
31
- const schema = useSchema(client, space, view?.query.typename);
31
+ const typename = view?.query ? getTypenameFromQuery(view.query.ast) : undefined;
32
+ const schema = useSchema(client, space, typename);
32
33
  const jsonSchema = useMemo(() => (schema ? toJsonSchema(schema) : undefined), [schema]);
33
34
 
34
35
  const projection = useMemo(() => {
35
36
  if (schema && view?.projection) {
36
- return new ProjectionModel(toJsonSchema(schema), view.projection);
37
+ const projection = new ProjectionModel(toJsonSchema(schema), view.projection);
38
+ projection.normalizeView();
39
+ return projection;
37
40
  }
38
41
  }, [schema, view?.projection]);
39
42
 
@@ -92,8 +95,9 @@ export const useTestTableModel = () => {
92
95
  });
93
96
 
94
97
  const handleInsertRow = useCallback(() => {
95
- model?.insertRow();
96
- }, [model]);
98
+ const insertResult = model?.insertRow();
99
+ tableRef.current?.handleInsertRowResult?.(insertResult);
100
+ }, [model, tableRef.current]);
97
101
 
98
102
  const handleSaveView = useCallback(() => {
99
103
  model?.saveView();
@@ -14,8 +14,8 @@ export const translations = [
14
14
  'create object label': 'Create table',
15
15
  'table name placeholder': 'Table name',
16
16
  'settings title': 'Table settings',
17
- 'table schema label': 'Schema',
18
- 'new schema': 'New schema',
17
+ 'table schema label': 'Record type',
18
+ 'new schema': 'New record type',
19
19
  'continue label': 'Continue',
20
20
  'create stack section label': 'Create table',
21
21
  'add row label': 'Add row',
@@ -2,4 +2,4 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- export * from './schema';
5
+ export * as Table from './schema';
@@ -2,15 +2,72 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
5
+ import * as Match from 'effect/Match';
6
+ import * as Schema from 'effect/Schema';
6
7
 
7
- import { Type } from '@dxos/echo';
8
- import { JsonPath } from '@dxos/effect';
8
+ import { Obj, Type } from '@dxos/echo';
9
+ import { JsonPath, type JsonSchemaType, toEffectSchema } from '@dxos/echo/internal';
10
+ import { ViewAnnotation } from '@dxos/echo/internal';
11
+ import { type SimpleType } from '@dxos/effect';
12
+ import { View, getSchemaProperties } from '@dxos/schema';
9
13
 
10
- export const TableView = Schema.Struct({
14
+ export const Table = Schema.Struct({
11
15
  sizes: Schema.Record({
12
16
  key: JsonPath,
13
17
  value: Schema.Number,
14
18
  }).pipe(Schema.mutable),
15
- }).pipe(Type.Obj({ typename: 'dxos.org/type/TableView', version: '0.1.0' }));
16
- export type TableView = Schema.Schema.Type<typeof TableView>;
19
+ }).pipe(
20
+ Type.Obj({
21
+ typename: 'dxos.org/type/Table',
22
+ version: '0.1.0',
23
+ }),
24
+ ViewAnnotation.set(true),
25
+ );
26
+
27
+ export type Table = Schema.Schema.Type<typeof Table>;
28
+
29
+ /**
30
+ * Make a table view.
31
+ */
32
+ export const make = (props: Partial<Obj.MakeProps<typeof Table>> = {}) => Obj.make(Table, { sizes: {}, ...props });
33
+
34
+ type MakeViewProps = Omit<View.MakeFromSpaceProps, 'presentation'> & {
35
+ sizes?: Record<string, number>;
36
+ };
37
+
38
+ export const makeView = async ({
39
+ sizes,
40
+ ...props
41
+ }: MakeViewProps): Promise<{
42
+ jsonSchema: JsonSchemaType;
43
+ view: View.View;
44
+ schema: ReturnType<typeof toEffectSchema>;
45
+ }> => {
46
+ const table = Obj.make(Table, { sizes: {} });
47
+ const { jsonSchema, view } = await View.makeFromSpace({ ...props, presentation: table });
48
+
49
+ // Preset sizes.
50
+ const schema = toEffectSchema(jsonSchema);
51
+ const shouldIncludeId = props.fields?.find((field) => field === 'id') !== undefined;
52
+ const properties = getSchemaProperties(schema.ast, {}, shouldIncludeId);
53
+ for (const property of properties) {
54
+ if (sizes?.[property.name]) {
55
+ table.sizes[property.name as JsonPath] = sizes[property.name];
56
+ continue;
57
+ }
58
+
59
+ Match.type<SimpleType>().pipe(
60
+ Match.when('boolean', () => {
61
+ table.sizes[property.name as JsonPath] = 100;
62
+ }),
63
+ Match.when('number', () => {
64
+ table.sizes[property.name as JsonPath] = 100;
65
+ }),
66
+ Match.orElse(() => {
67
+ // Noop.
68
+ }),
69
+ )(property.type);
70
+ }
71
+
72
+ return { jsonSchema, schema, view };
73
+ };
@@ -2,20 +2,20 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { type Schema } from 'effect';
5
+ import type * as Schema from 'effect/Schema';
6
6
 
7
- import { Obj } from '@dxos/echo';
8
- import { getTypename, toJsonSchema } from '@dxos/echo-schema';
9
- import type { JsonSchemaType, SortDirectionType } from '@dxos/echo-schema';
7
+ import { Filter, Obj, Query } from '@dxos/echo';
8
+ import { getTypename, toJsonSchema } from '@dxos/echo/internal';
9
+ import type { JsonSchemaType } from '@dxos/echo/internal';
10
10
  import {
11
- createView,
12
- type DataType,
13
- getSchemaFromPropertyDefinitions,
14
11
  ProjectionModel,
15
12
  type SchemaPropertyDefinition,
13
+ type SortDirectionType,
14
+ View,
15
+ getSchemaFromPropertyDefinitions,
16
16
  } from '@dxos/schema';
17
17
 
18
- import { TableView } from '../types';
18
+ import { Table } from '../types';
19
19
 
20
20
  // TODO(ZaymonFC): Upstream these extra fields to SchemaPropertyDefinition to enhance schema-tools schema creation.
21
21
  type PropertyDisplayProps = {
@@ -54,23 +54,22 @@ export const getBaseSchema = ({
54
54
  };
55
55
 
56
56
  export const makeDynamicTable = ({
57
- typename,
58
57
  jsonSchema,
59
58
  properties,
60
59
  }: {
61
- typename: string;
62
60
  jsonSchema: JsonSchemaType;
63
61
  properties?: TablePropertyDefinition[];
64
- }): { projection: ProjectionModel; view: DataType.View } => {
65
- const table = Obj.make(TableView, { sizes: {} });
66
- const view = createView({
67
- typename,
62
+ }): { projection: ProjectionModel; view: View.View } => {
63
+ const table = Obj.make(Table.Table, { sizes: {} });
64
+ const view = View.make({
65
+ query: Query.select(Filter.everything()),
68
66
  jsonSchema,
69
67
  presentation: table,
70
68
  ...(properties && { fields: properties.map((property) => property.name) }),
71
69
  });
72
70
 
73
71
  const projection = new ProjectionModel(jsonSchema, view.projection);
72
+ projection.normalizeView();
74
73
  if (properties && projection.fields) {
75
74
  setProperties(view, projection, table, properties);
76
75
  }
@@ -79,9 +78,9 @@ export const makeDynamicTable = ({
79
78
  };
80
79
 
81
80
  const setProperties = (
82
- view: DataType.View,
81
+ view: View.View,
83
82
  projection: ProjectionModel,
84
- table: TableView,
83
+ table: Table.Table,
85
84
  properties: TablePropertyDefinition[],
86
85
  ) => {
87
86
  for (const property of properties) {
@@ -101,7 +100,7 @@ const setProperties = (
101
100
 
102
101
  if (property.sort) {
103
102
  const fieldId = field.id;
104
- view.query.sort = [{ fieldId, direction: property.sort }];
103
+ view.sort = [{ fieldId, direction: property.sort }];
105
104
  }
106
105
  }
107
106
  }
package/src/util/index.ts CHANGED
@@ -4,7 +4,6 @@
4
4
 
5
5
  export * from './dynamic-table';
6
6
  export * from './signals';
7
- export * from './table';
8
7
  export * from './table-buttons';
9
8
  export * from './table-controls';
10
9
  export * from './schema';
@@ -2,8 +2,8 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Schema } from 'effect';
6
- import { isTypeLiteral, TypeLiteral } from 'effect/SchemaAST';
5
+ import * as Schema from 'effect/Schema';
6
+ import * as SchemaAST from 'effect/SchemaAST';
7
7
 
8
8
  /**
9
9
  * Creates a narrowed schema from an original schema that only includes
@@ -20,14 +20,14 @@ export const narrowSchema = <S extends Schema.Schema.AnyNoContext>(
20
20
  ): Schema.Schema<unknown, unknown> | undefined => {
21
21
  const ast = (schema as any)?.ast;
22
22
 
23
- if (isTypeLiteral(ast)) {
23
+ if (SchemaAST.isTypeLiteral(ast)) {
24
24
  // Filter property signatures that match any of the provided paths
25
25
  const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
26
26
 
27
27
  // If we found at least one matching property
28
28
  if (propertySignatures.length > 0) {
29
29
  // Create a new TypeLiteral with only the matching properties
30
- const narrowType = new TypeLiteral(propertySignatures, []);
30
+ const narrowType = new SchemaAST.TypeLiteral(propertySignatures, []);
31
31
  return Schema.make(narrowType);
32
32
  }
33
33
  }
@@ -26,7 +26,7 @@ const createButton = ({
26
26
  disabled = false,
27
27
  icon,
28
28
  testId,
29
- type = 'primary',
29
+ type: _type = 'primary',
30
30
  }: {
31
31
  attr: string;
32
32
  data: Record<string, string>;
@@ -39,8 +39,7 @@ const createButton = ({
39
39
  .map(([k, v]) => `${k}="${v}"`)
40
40
  .join(' ');
41
41
 
42
- const positionClass = type === 'primary' ? 'inline-end-2' : 'inline-end-9';
43
- return `<button ${attr} data-testid="${testId}" class="dx-button is-6 pli-0.5 min-bs-0 absolute inset-block-1 ${positionClass}" ${dataAttrs} ${disabled ? 'disabled' : ''}><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
42
+ return `<button ${attr} data-testid="${testId}" class="dx-button is-6 aspect-square pli-0.5 min-bs-0" ${dataAttrs} ${disabled ? 'disabled' : ''} data-dx-grid-action="accessory"><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
44
43
  };
45
44
 
46
45
  const addColumnButton = {
@@ -67,6 +66,7 @@ const columnSettingsButton = {
67
66
  icon: columnSettingsButton.icon,
68
67
  data: {
69
68
  'data-field-id': fieldId,
69
+ 'data-variant': 'ghost',
70
70
  },
71
71
  testId: 'table-column-settings-button',
72
72
  });
@@ -130,6 +130,7 @@ const saveDraftRowButton = {
130
130
  disabled,
131
131
  data: {
132
132
  'data-row-index': rowIndex.toString(),
133
+ 'data-variant': 'primary',
133
134
  },
134
135
  testId: 'table-save-draft-row-button',
135
136
  });
@@ -3,6 +3,8 @@
3
3
  //
4
4
 
5
5
  // Core types.
6
+ import { accessoryHandlesPointerdownAttrs } from '@dxos/lit-grid';
7
+
6
8
  export type TableControl = 'checkbox' | 'switch';
7
9
 
8
10
  export type ControlData =
@@ -41,7 +43,7 @@ const renderInput = (
41
43
  preventToggle = false,
42
44
  testId: string,
43
45
  ) => {
44
- return `<input type="checkbox" class="${baseClass}" ${renderAttributes(attrs)} ${checked ? 'checked' : ''} ${preventToggle ? 'onclick="return false"' : ''} ${disabled ? 'disabled' : ''} data-testid="${testId}"/>`;
46
+ return `<input type="checkbox" class="${baseClass}" ${renderAttributes(attrs)} ${checked ? 'checked' : ''} ${preventToggle ? 'onclick="return false"' : ''} ${disabled ? 'disabled' : ''} data-testid="${testId}" data-dx-grid-action="accessory"/>`;
45
47
  };
46
48
 
47
49
  export const CheckboxStory = ({
@@ -64,6 +66,7 @@ export const SwitchStory = ({ colIndex, rowIndex, checked = false, disabled = fa
64
66
  [CONTROL_IDENTIFIERS.switch]: '',
65
67
  'data-row-index': rowIndex.toString(),
66
68
  'data-col-index': colIndex.toString(),
69
+ ...accessoryHandlesPointerdownAttrs,
67
70
  };
68
71
 
69
72
  return renderInput(BASE_CLASSES.switch, attrs, checked, disabled, true, 'table-switch');