@dxos/react-ui-table 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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 (129) hide show
  1. package/dist/lib/browser/{chunk-G7MGPBSR.mjs → chunk-I5IFW7UF.mjs} +633 -663
  2. package/dist/lib/browser/chunk-I5IFW7UF.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-OZBLY7XM.mjs +76 -0
  4. package/dist/lib/browser/chunk-OZBLY7XM.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +1131 -999
  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 +29 -41
  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-LD5JEBA6.mjs → chunk-DDJKYJFY.mjs} +633 -662
  12. package/dist/lib/node-esm/chunk-DDJKYJFY.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-WNZSKIRF.mjs +77 -0
  14. package/dist/lib/node-esm/chunk-WNZSKIRF.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +1131 -999
  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 +29 -41
  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 -2
  22. package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
  23. package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -2
  24. package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
  25. package/dist/types/src/components/Table/DynamicTable.d.ts +4 -5
  26. package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
  27. package/dist/types/src/components/Table/DynamicTable.stories.d.ts +4 -18
  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 +12 -9
  30. package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
  31. package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
  32. package/dist/types/src/components/Table/Table.d.ts +8 -8
  33. package/dist/types/src/components/Table/Table.d.ts.map +1 -1
  34. package/dist/types/src/components/Table/Table.stories.d.ts +71 -5
  35. package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
  36. package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
  37. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +10 -12
  38. package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
  39. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -7
  40. package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
  41. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +4 -4
  42. package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
  43. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +4 -4
  44. package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
  45. package/dist/types/src/components/testing.d.ts +22 -15
  46. package/dist/types/src/components/testing.d.ts.map +1 -1
  47. package/dist/types/src/hooks/index.d.ts +2 -1
  48. package/dist/types/src/hooks/index.d.ts.map +1 -1
  49. package/dist/types/src/hooks/useAddRow.d.ts +5 -6
  50. package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
  51. package/dist/types/src/hooks/useProjectionModel.d.ts +6 -0
  52. package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
  53. package/dist/types/src/hooks/useTableModel.d.ts +8 -8
  54. package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
  55. package/dist/types/src/model/modal-controller.d.ts +5 -1
  56. package/dist/types/src/model/modal-controller.d.ts.map +1 -1
  57. package/dist/types/src/model/selection-model.d.ts +17 -8
  58. package/dist/types/src/model/selection-model.d.ts.map +1 -1
  59. package/dist/types/src/model/table-model.d.ts +102 -23
  60. package/dist/types/src/model/table-model.d.ts.map +1 -1
  61. package/dist/types/src/model/table-presentation.d.ts +3 -1
  62. package/dist/types/src/model/table-presentation.d.ts.map +1 -1
  63. package/dist/types/src/playwright/TableManager.d.ts +1 -1
  64. package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
  65. package/dist/types/src/testing/useTestTableModel.d.ts +18 -15
  66. package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
  67. package/dist/types/src/translations.d.ts +4 -4
  68. package/dist/types/src/translations.d.ts.map +1 -1
  69. package/dist/types/src/types/Table.d.ts +31 -0
  70. package/dist/types/src/types/Table.d.ts.map +1 -0
  71. package/dist/types/src/types/index.d.ts +1 -1
  72. package/dist/types/src/types/index.d.ts.map +1 -1
  73. package/dist/types/src/util/dynamic-table.d.ts +13 -11
  74. package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
  75. package/dist/types/src/util/index.d.ts +2 -0
  76. package/dist/types/src/util/index.d.ts.map +1 -1
  77. package/dist/types/src/util/query-ast.d.ts +7 -0
  78. package/dist/types/src/util/query-ast.d.ts.map +1 -0
  79. package/dist/types/src/util/sort.d.ts +12 -0
  80. package/dist/types/src/util/sort.d.ts.map +1 -0
  81. package/dist/types/tsconfig.tsbuildinfo +1 -1
  82. package/package.json +53 -53
  83. package/src/components/Table/ColumnActionsMenu.tsx +10 -6
  84. package/src/components/Table/ColumnSettings.tsx +6 -6
  85. package/src/components/Table/DynamicTable.stories.tsx +12 -13
  86. package/src/components/Table/DynamicTable.tsx +21 -14
  87. package/src/components/Table/Relations.stories.tsx +35 -39
  88. package/src/components/Table/RowActionsMenu.tsx +24 -15
  89. package/src/components/Table/Table.stories.tsx +71 -75
  90. package/src/components/Table/Table.tsx +335 -305
  91. package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
  92. package/src/components/TableCellEditor/FormCellEditor.tsx +110 -133
  93. package/src/components/TableCellEditor/TableCellEditor.stories.tsx +16 -12
  94. package/src/components/TableCellEditor/TableCellEditor.tsx +31 -31
  95. package/src/components/TableToolbar/TableToolbar.tsx +44 -31
  96. package/src/components/testing.ts +38 -12
  97. package/src/hooks/index.ts +2 -1
  98. package/src/hooks/useAddRow.ts +8 -10
  99. package/src/hooks/useProjectionModel.ts +39 -0
  100. package/src/hooks/useTableModel.ts +35 -33
  101. package/src/model/modal-controller.ts +23 -12
  102. package/src/model/selection-model.ts +75 -44
  103. package/src/model/table-model.test.ts +82 -54
  104. package/src/model/table-model.ts +428 -163
  105. package/src/model/table-presentation.test.ts +59 -49
  106. package/src/model/table-presentation.ts +31 -26
  107. package/src/playwright/TableManager.ts +5 -5
  108. package/src/playwright/playwright.config.ts +1 -1
  109. package/src/playwright/smoke.spec.ts +8 -5
  110. package/src/testing/useTestTableModel.ts +44 -37
  111. package/src/translations.ts +3 -3
  112. package/src/types/Table.ts +90 -0
  113. package/src/types/index.ts +1 -1
  114. package/src/util/dynamic-table.ts +39 -27
  115. package/src/util/index.ts +2 -0
  116. package/src/util/query-ast.ts +19 -0
  117. package/src/util/sort.ts +90 -0
  118. package/dist/lib/browser/chunk-4K7JPALT.mjs +0 -66
  119. package/dist/lib/browser/chunk-4K7JPALT.mjs.map +0 -7
  120. package/dist/lib/browser/chunk-G7MGPBSR.mjs.map +0 -7
  121. package/dist/lib/node-esm/chunk-LD5JEBA6.mjs.map +0 -7
  122. package/dist/lib/node-esm/chunk-MK6OVUF6.mjs +0 -67
  123. package/dist/lib/node-esm/chunk-MK6OVUF6.mjs.map +0 -7
  124. package/dist/types/src/model/table-sorting.d.ts +0 -52
  125. package/dist/types/src/model/table-sorting.d.ts.map +0 -1
  126. package/dist/types/src/types/schema.d.ts +0 -28
  127. package/dist/types/src/types/schema.d.ts.map +0 -1
  128. package/src/model/table-sorting.ts +0 -225
  129. package/src/types/schema.ts +0 -73
@@ -6,26 +6,18 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
6
6
  import * as Schema from 'effect/Schema';
7
7
  import React, { useCallback } from 'react';
8
8
 
9
- import { Obj, type QueryAST, Type } from '@dxos/echo';
10
- import {
11
- EchoObject,
12
- FormatAnnotation,
13
- FormatEnum,
14
- GeneratorAnnotation,
15
- LabelAnnotation,
16
- PropertyMetaAnnotationId,
17
- } from '@dxos/echo/internal';
18
- import { live } from '@dxos/echo/internal';
9
+ import { Annotation, type Database, Format, Obj, type QueryAST, Type } from '@dxos/echo';
10
+ import { type Mutable, PropertyMetaAnnotationId } from '@dxos/echo/internal';
19
11
  import { invariant } from '@dxos/invariant';
20
12
  import { faker } from '@dxos/random';
21
13
  import { PublicKey } from '@dxos/react-client';
22
- import { type Space } from '@dxos/react-client/echo';
23
14
  import { withClientProvider } from '@dxos/react-client/testing';
24
15
  import { withTheme } from '@dxos/react-ui/testing';
25
- import { ViewEditor } from '@dxos/react-ui-form';
16
+ import { ViewEditor, translations as formTranslations } from '@dxos/react-ui-form';
26
17
  import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
27
- import { DataType, getSchemaFromPropertyDefinitions, getTypenameFromQuery } from '@dxos/schema';
28
- import { Testing, createObjectFactory } from '@dxos/schema/testing';
18
+ import { View, getSchemaFromPropertyDefinitions, getTypenameFromQuery } from '@dxos/schema';
19
+ import { TestSchema, createObjectFactory } from '@dxos/schema/testing';
20
+ import { withRegistry } from '@dxos/storybook-utils';
29
21
 
30
22
  import { useTestTableModel } from '../../testing';
31
23
  import { translations } from '../../translations';
@@ -34,13 +26,13 @@ import { TableToolbar } from '../TableToolbar';
34
26
 
35
27
  import { Table as TableComponent } from './Table';
36
28
 
37
- const TestSchema = Schema.Struct({
29
+ const Example = Schema.Struct({
38
30
  // TODO(wittjosiah): Should be title. Currently name to work with default label.
39
31
  name: Schema.optional(Schema.String).annotations({ title: 'Title' }),
40
32
  urgent: Schema.optional(Schema.Boolean).annotations({ title: 'Urgent' }),
41
33
  status: Schema.optional(
42
34
  Schema.Literal('todo', 'in-progress', 'done')
43
- .pipe(FormatAnnotation.set(FormatEnum.SingleSelect))
35
+ .pipe(Format.FormatAnnotation.set(Format.TypeFormat.SingleSelect))
44
36
  .annotations({
45
37
  title: 'Status',
46
38
  [PropertyMetaAnnotationId]: {
@@ -55,24 +47,24 @@ const TestSchema = Schema.Struct({
55
47
  }),
56
48
  ),
57
49
  description: Schema.optional(Schema.String).annotations({ title: 'Description' }),
58
- parent: Schema.optional(Schema.suspend((): Type.Ref<TestSchema> => Type.Ref(TestSchema))).annotations({
50
+ parent: Schema.optional(Schema.suspend((): Type.Ref<Example> => Type.Ref(Example))).annotations({
59
51
  title: 'Parent',
60
52
  }),
61
53
  }).pipe(
62
- Type.Obj({ typename: `example.com/type/${PublicKey.random().truncate()}`, version: '0.1.0' }),
63
- LabelAnnotation.set(['name']),
54
+ Type.object({ typename: `example.com/type/${PublicKey.random().truncate()}`, version: '0.1.0' }),
55
+ Annotation.LabelAnnotation.set(['name']),
64
56
  );
65
- interface TestSchema extends Schema.Schema.Type<typeof TestSchema> {}
57
+ interface Example extends Schema.Schema.Type<typeof Example> {}
66
58
 
67
59
  const StoryViewEditor = ({
68
60
  view,
69
61
  schema,
70
- space,
62
+ db,
71
63
  handleDeleteColumn,
72
64
  }: {
73
- view?: DataType.View;
65
+ view?: View.View;
74
66
  schema?: Schema.Schema.AnyNoContext;
75
- space?: Space;
67
+ db?: Database.Database;
76
68
  handleDeleteColumn: (fieldId: string) => void;
77
69
  }) => {
78
70
  const handleQueryChanged = useCallback(
@@ -81,7 +73,9 @@ const StoryViewEditor = ({
81
73
  invariant(Type.isMutable(schema));
82
74
  schema.updateTypename(getTypenameFromQuery(newQuery));
83
75
  invariant(view);
84
- view.query.ast = newQuery;
76
+ Obj.change(view, (v) => {
77
+ v.query.ast = newQuery as Mutable<typeof newQuery>;
78
+ });
85
79
  },
86
80
  [schema, view],
87
81
  );
@@ -92,7 +86,7 @@ const StoryViewEditor = ({
92
86
 
93
87
  return (
94
88
  <ViewEditor
95
- registry={space?.db.schemaRegistry}
89
+ registry={db?.schemaRegistry}
96
90
  schema={schema}
97
91
  view={view}
98
92
  onQueryChanged={handleQueryChanged}
@@ -106,20 +100,10 @@ const StoryViewEditor = ({
106
100
  //
107
101
 
108
102
  const DefaultStory = () => {
109
- const {
110
- space,
111
- schema,
112
- view,
113
- tableRef,
114
- model,
115
- presentation,
116
- client,
117
- handleInsertRow,
118
- handleSaveView,
119
- handleDeleteColumn,
120
- } = useTestTableModel();
103
+ const { db, schema, table, tableRef, model, presentation, handleInsertRow, handleSaveView, handleDeleteColumn } =
104
+ useTestTableModel();
121
105
 
122
- if (!schema || !view) {
106
+ if (!schema || !table?.view.target) {
123
107
  return <div />;
124
108
  }
125
109
 
@@ -130,18 +114,17 @@ const DefaultStory = () => {
130
114
  <TableComponent.Root>
131
115
  <TableComponent.Main
132
116
  ref={tableRef}
117
+ schema={schema}
133
118
  model={model}
134
119
  presentation={presentation}
135
- schema={schema}
136
- client={client}
137
120
  ignoreAttention
138
121
  />
139
122
  </TableComponent.Root>
140
123
  </div>
141
- <div className='flex flex-col h-full border-l border-separator overflow-y-auto'>
142
- <StoryViewEditor view={view} schema={schema} space={space} handleDeleteColumn={handleDeleteColumn} />
124
+ <div className='flex flex-col bs-full border-l border-separator overflow-y-auto'>
125
+ <StoryViewEditor view={table.view.target} schema={schema} db={db} handleDeleteColumn={handleDeleteColumn} />
143
126
  <SyntaxHighlighter language='json' className='text-xs'>
144
- {JSON.stringify({ view, schema }, null, 2)}
127
+ {JSON.stringify({ view: table.view.target, schema }, null, 2)}
145
128
  </SyntaxHighlighter>
146
129
  </div>
147
130
  </div>
@@ -161,19 +144,23 @@ const meta = {
161
144
  render: DefaultStory,
162
145
  decorators: [
163
146
  withTheme,
147
+ withRegistry,
164
148
  withClientProvider({
165
- types: [DataType.View, Table.Table],
149
+ types: [View.View, Table.Table],
166
150
  createIdentity: true,
167
151
  createSpace: true,
168
- onCreateSpace: async ({ client, space }) => {
169
- const [schema] = await space.db.schemaRegistry.register([TestSchema]);
170
- const { view } = await Table.makeView({ client, space, typename: schema.typename });
171
- view.projection.fields = [
172
- view.projection.fields.find((field) => field.path === 'name')!,
173
- ...view.projection.fields.filter((field) => field.path !== 'name'),
174
- ];
152
+ onCreateSpace: async ({ space }) => {
153
+ const [schema] = await space.db.schemaRegistry.register([Example]);
154
+ const { view, jsonSchema } = await View.makeFromDatabase({ db: space.db, typename: schema.typename });
155
+ const table = Table.make({ view, jsonSchema });
156
+ Obj.change(view, (v) => {
157
+ v.projection.fields = [
158
+ v.projection.fields.find((field) => field.path === 'name')!,
159
+ ...v.projection.fields.filter((field) => field.path !== 'name'),
160
+ ];
161
+ });
175
162
 
176
- space.db.add(view);
163
+ space.db.add(table);
177
164
 
178
165
  Array.from({ length: 10 }).map(() => {
179
166
  return space.db.add(
@@ -192,7 +179,7 @@ const meta = {
192
179
  controls: {
193
180
  disable: true,
194
181
  },
195
- translations,
182
+ translations: [...translations, ...formTranslations],
196
183
  },
197
184
  } satisfies Meta<typeof TableComponent>;
198
185
 
@@ -206,29 +193,33 @@ export const StaticSchema: StoryObj = {
206
193
  render: DefaultStory,
207
194
  decorators: [
208
195
  withClientProvider({
209
- types: [DataType.View, Table.Table, Testing.Contact, Testing.Organization],
196
+ types: [View.View, Table.Table],
210
197
  createIdentity: true,
211
198
  createSpace: true,
212
- onCreateSpace: async ({ client, space }) => {
213
- const { view } = await Table.makeView({ client, space, typename: Testing.Contact.typename });
214
- space.db.add(view);
199
+ onCreateSpace: async ({ space }) => {
200
+ const { view, jsonSchema } = await View.makeFromDatabase({
201
+ db: space.db,
202
+ typename: TestSchema.Person.typename,
203
+ });
204
+ const table = Table.make({ view, jsonSchema });
205
+ space.db.add(table);
215
206
 
216
207
  const factory = createObjectFactory(space.db, faker as any);
217
208
  await factory([
218
- { type: Testing.Contact, count: 10 },
219
- // { type: Testing.Organization, count: 1 },
209
+ { type: TestSchema.Person, count: 10 },
210
+ // { type: TestSchema.Organization, count: 1 },
220
211
  ]);
221
212
  },
222
213
  }),
223
214
  ],
224
215
  parameters: {
225
216
  layout: 'fullscreen',
226
- translations,
217
+ translations: [...translations, ...formTranslations],
227
218
  },
228
219
  };
229
220
 
230
221
  const ContactWithArrayOfEmails = Schema.Struct({
231
- name: Schema.String.pipe(GeneratorAnnotation.set('person.fullName')),
222
+ name: Schema.String.pipe(Annotation.GeneratorAnnotation.set('person.fullName')),
232
223
  emails: Schema.optional(
233
224
  Schema.Array(
234
225
  Schema.Struct({
@@ -238,7 +229,7 @@ const ContactWithArrayOfEmails = Schema.Struct({
238
229
  ),
239
230
  ),
240
231
  }).pipe(
241
- EchoObject({
232
+ Type.object({
242
233
  typename: 'dxos.org/type/ContactWithArrayOfEmails',
243
234
  version: '0.1.0',
244
235
  }),
@@ -248,17 +239,21 @@ export const ArrayOfObjects: StoryObj = {
248
239
  render: DefaultStory,
249
240
  decorators: [
250
241
  withClientProvider({
251
- types: [DataType.View, Table.Table, Testing.Contact, Testing.Organization, ContactWithArrayOfEmails],
242
+ types: [View.View, Table.Table, TestSchema.Person, TestSchema.Organization, ContactWithArrayOfEmails],
252
243
  createIdentity: true,
253
244
  createSpace: true,
254
- onCreateSpace: async ({ client, space }) => {
255
- const { view } = await Table.makeView({ client, space, typename: ContactWithArrayOfEmails.typename });
256
- space.db.add(view);
245
+ onCreateSpace: async ({ space }) => {
246
+ const { view, jsonSchema } = await View.makeFromDatabase({
247
+ db: space.db,
248
+ typename: ContactWithArrayOfEmails.typename,
249
+ });
250
+ const table = Table.make({ view, jsonSchema });
251
+ space.db.add(table);
257
252
 
258
253
  const factory = createObjectFactory(space.db, faker as any);
259
254
  await factory([
260
- // { type: Testing.Contact, count: 10 },
261
- // { type: Testing.Organization, count: 1 },
255
+ // { type: TestSchema.Person, count: 10 },
256
+ // { type: TestSchema.Organization, count: 1 },
262
257
  { type: ContactWithArrayOfEmails, count: 10 },
263
258
  ]);
264
259
  },
@@ -275,10 +270,10 @@ export const Tags: Meta<StoryProps> = {
275
270
  render: DefaultStory,
276
271
  decorators: [
277
272
  withClientProvider({
278
- types: [DataType.View, Table.Table],
273
+ types: [View.View, Table.Table],
279
274
  createIdentity: true,
280
275
  createSpace: true,
281
- onCreateSpace: async ({ client, space }) => {
276
+ onCreateSpace: async ({ space }) => {
282
277
  // Configure schema.
283
278
  const typename = 'example.com/SingleSelect';
284
279
  const selectOptions = [
@@ -294,25 +289,26 @@ export const Tags: Meta<StoryProps> = {
294
289
  const schema = getSchemaFromPropertyDefinitions(typename, [
295
290
  {
296
291
  name: 'single',
297
- format: FormatEnum.SingleSelect,
292
+ format: Format.TypeFormat.SingleSelect,
298
293
  config: { options: selectOptions },
299
294
  },
300
295
  {
301
296
  name: 'multiple',
302
- format: FormatEnum.MultiSelect,
297
+ format: Format.TypeFormat.MultiSelect,
303
298
  config: { options: selectOptions },
304
299
  },
305
300
  ]);
306
301
  const [storedSchema] = await space.db.schemaRegistry.register([schema]);
307
302
 
308
303
  // Initialize table.
309
- const { view } = await Table.makeView({ client, space, typename });
310
- space.db.add(view);
304
+ const { view, jsonSchema } = await View.makeFromDatabase({ db: space.db, typename });
305
+ const table = Table.make({ view, jsonSchema });
306
+ space.db.add(table);
311
307
 
312
308
  // Populate.
313
309
  Array.from({ length: 10 }).map(() => {
314
310
  return space.db.add(
315
- live(storedSchema, {
311
+ Obj.make(storedSchema, {
316
312
  single: faker.helpers.arrayElement([...selectOptionIds, undefined]),
317
313
  multiple: faker.helpers.randomSubset(selectOptionIds),
318
314
  }),