@dxos/react-ui-table 0.8.4-main.7ace549 → 0.8.4-main.8360d9e660
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.
- package/dist/lib/browser/{chunk-5XWSB3JP.mjs → chunk-BF54SSNL.mjs} +27 -28
- package/dist/lib/browser/chunk-BF54SSNL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-KNC7XYT6.mjs → chunk-PTHMYAAM.mjs} +620 -652
- package/dist/lib/browser/chunk-PTHMYAAM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1154 -1036
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +20 -19
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/{chunk-CWSGS3Y2.mjs → chunk-GI72MQSG.mjs} +620 -651
- package/dist/lib/node-esm/chunk-GI72MQSG.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-MKTMOY46.mjs → chunk-SIRDIPHZ.mjs} +27 -28
- package/dist/lib/node-esm/chunk-SIRDIPHZ.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1154 -1036
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +20 -19
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +1 -2
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -2
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +7 -7
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +2 -16
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +6 -3
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +11 -11
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +6 -3
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +10 -12
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -7
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +2 -2
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +3 -3
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +22 -13
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts +5 -6
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +2 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +6 -5
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +5 -1
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +17 -8
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +100 -18
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +3 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +2 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +5 -8
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +13 -15
- package/dist/types/src/types/Table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +12 -10
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.test.d.ts +2 -0
- package/dist/types/src/util/dynamic-table.test.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +2 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/query-ast.d.ts +7 -0
- package/dist/types/src/util/query-ast.d.ts.map +1 -0
- package/dist/types/src/util/sort.d.ts +12 -0
- package/dist/types/src/util/sort.d.ts.map +1 -0
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +54 -55
- package/src/components/Table/ColumnActionsMenu.tsx +10 -6
- package/src/components/Table/ColumnSettings.tsx +8 -9
- package/src/components/Table/DynamicTable.stories.tsx +11 -11
- package/src/components/Table/DynamicTable.tsx +30 -30
- package/src/components/Table/Relations.stories.tsx +34 -31
- package/src/components/Table/RowActionsMenu.tsx +3 -2
- package/src/components/Table/Table.stories.tsx +80 -67
- package/src/components/Table/Table.tsx +324 -299
- package/src/components/TableCellEditor/CellValidationMessage.tsx +5 -5
- package/src/components/TableCellEditor/FormCellEditor.tsx +118 -135
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +10 -7
- package/src/components/TableCellEditor/TableCellEditor.tsx +27 -27
- package/src/components/TableToolbar/TableToolbar.tsx +24 -18
- package/src/components/testing.ts +37 -11
- package/src/hooks/useAddRow.ts +8 -10
- package/src/hooks/useProjectionModel.ts +29 -9
- package/src/hooks/useTableModel.ts +27 -23
- package/src/model/modal-controller.ts +23 -12
- package/src/model/selection-model.ts +75 -44
- package/src/model/table-model.test.ts +81 -53
- package/src/model/table-model.ts +410 -138
- package/src/model/table-presentation.test.ts +58 -48
- package/src/model/table-presentation.ts +34 -28
- package/src/playwright/TableManager.ts +12 -5
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +48 -4
- package/src/testing/useTestTableModel.ts +24 -25
- package/src/translations.ts +1 -1
- package/src/types/Table.ts +28 -38
- package/src/util/dynamic-table.test.ts +70 -0
- package/src/util/dynamic-table.ts +36 -19
- package/src/util/index.ts +2 -0
- package/src/util/query-ast.ts +22 -0
- package/src/util/sort.ts +90 -0
- package/src/util/table-buttons.ts +1 -1
- package/src/util/table-controls.ts +2 -2
- package/dist/lib/browser/chunk-5XWSB3JP.mjs.map +0 -7
- package/dist/lib/browser/chunk-KNC7XYT6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-CWSGS3Y2.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs.map +0 -7
- package/dist/types/src/model/table-sorting.d.ts +0 -56
- package/dist/types/src/model/table-sorting.d.ts.map +0 -1
- package/src/model/table-sorting.ts +0 -234
|
@@ -6,23 +6,24 @@ 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 { Annotation, Format, Obj, type QueryAST, Type } from '@dxos/echo';
|
|
10
|
-
import {
|
|
9
|
+
import { Annotation, type Database, Format, Obj, type QueryAST, Ref, Type } from '@dxos/echo';
|
|
10
|
+
import { View } from '@dxos/echo';
|
|
11
|
+
import { type Mutable, PropertyMetaAnnotationId } from '@dxos/echo/internal';
|
|
11
12
|
import { invariant } from '@dxos/invariant';
|
|
12
13
|
import { faker } from '@dxos/random';
|
|
13
14
|
import { PublicKey } from '@dxos/react-client';
|
|
14
|
-
import { type Space } from '@dxos/react-client/echo';
|
|
15
15
|
import { withClientProvider } from '@dxos/react-client/testing';
|
|
16
|
-
import {
|
|
16
|
+
import { Panel, ScrollArea } from '@dxos/react-ui';
|
|
17
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
17
18
|
import { ViewEditor, translations as formTranslations } from '@dxos/react-ui-form';
|
|
18
19
|
import { SyntaxHighlighter } from '@dxos/react-ui-syntax-highlighter';
|
|
19
|
-
import {
|
|
20
|
+
import { ViewModel, getSchemaFromPropertyDefinitions, getTypenameFromQuery } from '@dxos/schema';
|
|
20
21
|
import { TestSchema, createObjectFactory } from '@dxos/schema/testing';
|
|
22
|
+
import { withRegistry } from '@dxos/storybook-utils';
|
|
21
23
|
|
|
22
24
|
import { useTestTableModel } from '../../testing';
|
|
23
25
|
import { translations } from '../../translations';
|
|
24
26
|
import { Table } from '../../types';
|
|
25
|
-
import { TableToolbar } from '../TableToolbar';
|
|
26
27
|
|
|
27
28
|
import { Table as TableComponent } from './Table';
|
|
28
29
|
|
|
@@ -47,11 +48,11 @@ const Example = Schema.Struct({
|
|
|
47
48
|
}),
|
|
48
49
|
),
|
|
49
50
|
description: Schema.optional(Schema.String).annotations({ title: 'Description' }),
|
|
50
|
-
parent: Schema.optional(Schema.suspend(():
|
|
51
|
+
parent: Schema.optional(Schema.suspend((): Ref.RefSchema<Example> => Ref.Ref(Example))).annotations({
|
|
51
52
|
title: 'Parent',
|
|
52
53
|
}),
|
|
53
54
|
}).pipe(
|
|
54
|
-
Type.
|
|
55
|
+
Type.object({ typename: `com.example.type.${PublicKey.random().truncate()}`, version: '0.1.0' }),
|
|
55
56
|
Annotation.LabelAnnotation.set(['name']),
|
|
56
57
|
);
|
|
57
58
|
interface Example extends Schema.Schema.Type<typeof Example> {}
|
|
@@ -59,12 +60,12 @@ interface Example extends Schema.Schema.Type<typeof Example> {}
|
|
|
59
60
|
const StoryViewEditor = ({
|
|
60
61
|
view,
|
|
61
62
|
schema,
|
|
62
|
-
|
|
63
|
+
db,
|
|
63
64
|
handleDeleteColumn,
|
|
64
65
|
}: {
|
|
65
66
|
view?: View.View;
|
|
66
67
|
schema?: Schema.Schema.AnyNoContext;
|
|
67
|
-
|
|
68
|
+
db?: Database.Database;
|
|
68
69
|
handleDeleteColumn: (fieldId: string) => void;
|
|
69
70
|
}) => {
|
|
70
71
|
const handleQueryChanged = useCallback(
|
|
@@ -73,7 +74,9 @@ const StoryViewEditor = ({
|
|
|
73
74
|
invariant(Type.isMutable(schema));
|
|
74
75
|
schema.updateTypename(getTypenameFromQuery(newQuery));
|
|
75
76
|
invariant(view);
|
|
76
|
-
view
|
|
77
|
+
Obj.change(view, (v) => {
|
|
78
|
+
v.query.ast = newQuery as Mutable<typeof newQuery>;
|
|
79
|
+
});
|
|
77
80
|
},
|
|
78
81
|
[schema, view],
|
|
79
82
|
);
|
|
@@ -84,7 +87,7 @@ const StoryViewEditor = ({
|
|
|
84
87
|
|
|
85
88
|
return (
|
|
86
89
|
<ViewEditor
|
|
87
|
-
registry={
|
|
90
|
+
registry={db?.schemaRegistry}
|
|
88
91
|
schema={schema}
|
|
89
92
|
view={view}
|
|
90
93
|
onQueryChanged={handleQueryChanged}
|
|
@@ -98,18 +101,17 @@ const StoryViewEditor = ({
|
|
|
98
101
|
//
|
|
99
102
|
|
|
100
103
|
const DefaultStory = () => {
|
|
101
|
-
const {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
} = useTestTableModel();
|
|
104
|
+
const { db, schema, table, tableRef, model, presentation, handleInsertRow, handleSaveView, handleDeleteColumn } =
|
|
105
|
+
useTestTableModel();
|
|
106
|
+
|
|
107
|
+
const handleRowClick = useCallback(
|
|
108
|
+
(row: any) => {
|
|
109
|
+
if (model?.getDraftRowCount() === 0 && ['frozenRowsEnd', 'fixedEndStart', 'fixedEndEnd'].includes(row?.plane)) {
|
|
110
|
+
handleInsertRow();
|
|
111
|
+
}
|
|
112
|
+
},
|
|
113
|
+
[model, handleInsertRow],
|
|
114
|
+
);
|
|
113
115
|
|
|
114
116
|
if (!schema || !table?.view.target) {
|
|
115
117
|
return <div />;
|
|
@@ -117,30 +119,35 @@ const DefaultStory = () => {
|
|
|
117
119
|
|
|
118
120
|
return (
|
|
119
121
|
<div className='grow grid grid-cols-[1fr_350px]'>
|
|
120
|
-
<
|
|
121
|
-
<
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
122
|
+
<TableComponent.Root>
|
|
123
|
+
<Panel.Root>
|
|
124
|
+
<Panel.Toolbar asChild>
|
|
125
|
+
<TableComponent.Toolbar
|
|
126
|
+
classNames='border-b border-subdued-separator'
|
|
127
|
+
onAdd={handleInsertRow}
|
|
128
|
+
onSave={handleSaveView}
|
|
129
|
+
/>
|
|
130
|
+
</Panel.Toolbar>
|
|
131
|
+
<Panel.Content asChild>
|
|
132
|
+
<TableComponent.Main
|
|
133
|
+
ref={tableRef}
|
|
134
|
+
schema={schema}
|
|
135
|
+
model={model}
|
|
136
|
+
presentation={presentation}
|
|
137
|
+
onRowClick={handleRowClick}
|
|
138
|
+
ignoreAttention
|
|
139
|
+
/>
|
|
140
|
+
</Panel.Content>
|
|
141
|
+
</Panel.Root>
|
|
142
|
+
</TableComponent.Root>
|
|
143
|
+
<ScrollArea.Root orientation='vertical' classNames='border-l border-separator'>
|
|
144
|
+
<ScrollArea.Viewport>
|
|
145
|
+
<StoryViewEditor view={table.view.target} schema={schema} db={db} handleDeleteColumn={handleDeleteColumn} />
|
|
146
|
+
<SyntaxHighlighter language='json' className='text-xs'>
|
|
147
|
+
{JSON.stringify({ view: table.view.target, schema }, null, 2)}
|
|
148
|
+
</SyntaxHighlighter>
|
|
149
|
+
</ScrollArea.Viewport>
|
|
150
|
+
</ScrollArea.Root>
|
|
144
151
|
</div>
|
|
145
152
|
);
|
|
146
153
|
};
|
|
@@ -151,25 +158,29 @@ type StoryProps = { rows?: number };
|
|
|
151
158
|
// Story definitions.
|
|
152
159
|
//
|
|
153
160
|
|
|
154
|
-
// TODO(burdon): Need
|
|
161
|
+
// TODO(burdon): Need simpler story.
|
|
155
162
|
|
|
156
163
|
const meta = {
|
|
157
164
|
title: 'ui/react-ui-table/Table',
|
|
158
165
|
render: DefaultStory,
|
|
159
166
|
decorators: [
|
|
160
|
-
withTheme,
|
|
167
|
+
withTheme(),
|
|
168
|
+
withLayout({ layout: 'fullscreen' }),
|
|
169
|
+
withRegistry,
|
|
161
170
|
withClientProvider({
|
|
162
171
|
types: [View.View, Table.Table],
|
|
163
172
|
createIdentity: true,
|
|
164
173
|
createSpace: true,
|
|
165
|
-
onCreateSpace: async ({
|
|
174
|
+
onCreateSpace: async ({ space }) => {
|
|
166
175
|
const [schema] = await space.db.schemaRegistry.register([Example]);
|
|
167
|
-
const { view, jsonSchema } = await
|
|
176
|
+
const { view, jsonSchema } = await ViewModel.makeFromDatabase({ db: space.db, typename: schema.typename });
|
|
168
177
|
const table = Table.make({ view, jsonSchema });
|
|
169
|
-
view
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
178
|
+
Obj.change(view, (v) => {
|
|
179
|
+
v.projection.fields = [
|
|
180
|
+
v.projection.fields.find((field) => field.path === 'name')!,
|
|
181
|
+
...v.projection.fields.filter((field) => field.path !== 'name'),
|
|
182
|
+
];
|
|
183
|
+
});
|
|
173
184
|
|
|
174
185
|
space.db.add(table);
|
|
175
186
|
|
|
@@ -207,8 +218,11 @@ export const StaticSchema: StoryObj = {
|
|
|
207
218
|
types: [View.View, Table.Table],
|
|
208
219
|
createIdentity: true,
|
|
209
220
|
createSpace: true,
|
|
210
|
-
onCreateSpace: async ({
|
|
211
|
-
const { view, jsonSchema } = await
|
|
221
|
+
onCreateSpace: async ({ space }) => {
|
|
222
|
+
const { view, jsonSchema } = await ViewModel.makeFromDatabase({
|
|
223
|
+
db: space.db,
|
|
224
|
+
typename: TestSchema.Person.typename,
|
|
225
|
+
});
|
|
212
226
|
const table = Table.make({ view, jsonSchema });
|
|
213
227
|
space.db.add(table);
|
|
214
228
|
|
|
@@ -237,8 +251,8 @@ const ContactWithArrayOfEmails = Schema.Struct({
|
|
|
237
251
|
),
|
|
238
252
|
),
|
|
239
253
|
}).pipe(
|
|
240
|
-
Type.
|
|
241
|
-
typename: 'dxos.
|
|
254
|
+
Type.object({
|
|
255
|
+
typename: 'org.dxos.type.contact-with-array-of-emails',
|
|
242
256
|
version: '0.1.0',
|
|
243
257
|
}),
|
|
244
258
|
);
|
|
@@ -250,10 +264,9 @@ export const ArrayOfObjects: StoryObj = {
|
|
|
250
264
|
types: [View.View, Table.Table, TestSchema.Person, TestSchema.Organization, ContactWithArrayOfEmails],
|
|
251
265
|
createIdentity: true,
|
|
252
266
|
createSpace: true,
|
|
253
|
-
onCreateSpace: async ({
|
|
254
|
-
const { view, jsonSchema } = await
|
|
255
|
-
|
|
256
|
-
space,
|
|
267
|
+
onCreateSpace: async ({ space }) => {
|
|
268
|
+
const { view, jsonSchema } = await ViewModel.makeFromDatabase({
|
|
269
|
+
db: space.db,
|
|
257
270
|
typename: ContactWithArrayOfEmails.typename,
|
|
258
271
|
});
|
|
259
272
|
const table = Table.make({ view, jsonSchema });
|
|
@@ -282,9 +295,9 @@ export const Tags: Meta<StoryProps> = {
|
|
|
282
295
|
types: [View.View, Table.Table],
|
|
283
296
|
createIdentity: true,
|
|
284
297
|
createSpace: true,
|
|
285
|
-
onCreateSpace: async ({
|
|
298
|
+
onCreateSpace: async ({ space }) => {
|
|
286
299
|
// Configure schema.
|
|
287
|
-
const typename = 'example.
|
|
300
|
+
const typename = 'com.example.type.single-select';
|
|
288
301
|
const selectOptions = [
|
|
289
302
|
{ id: 'one', title: 'One', color: 'emerald' },
|
|
290
303
|
{ id: 'two', title: 'Two', color: 'blue' },
|
|
@@ -310,7 +323,7 @@ export const Tags: Meta<StoryProps> = {
|
|
|
310
323
|
const [storedSchema] = await space.db.schemaRegistry.register([schema]);
|
|
311
324
|
|
|
312
325
|
// Initialize table.
|
|
313
|
-
const { view, jsonSchema } = await
|
|
326
|
+
const { view, jsonSchema } = await ViewModel.makeFromDatabase({ db: space.db, typename });
|
|
314
327
|
const table = Table.make({ view, jsonSchema });
|
|
315
328
|
space.db.add(table);
|
|
316
329
|
|