@dxos/react-ui-table 0.8.4-main.ead640a → 0.8.4-main.effb148878
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/LICENSE +102 -5
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/chunk-KC62K4WS.mjs +1696 -0
- package/dist/lib/browser/chunk-KC62K4WS.mjs.map +7 -0
- package/dist/lib/browser/chunk-VWQWF3CP.mjs +67 -0
- package/dist/lib/browser/chunk-VWQWF3CP.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1128 -1044
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +35 -46
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/translations.mjs +36 -0
- package/dist/lib/browser/translations.mjs.map +7 -0
- package/dist/lib/browser/types/index.mjs +4 -3
- package/dist/lib/node-esm/chunk-62FOU4M7.mjs +1698 -0
- package/dist/lib/node-esm/chunk-62FOU4M7.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs +11 -0
- package/dist/lib/node-esm/chunk-HSLMI22Q.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-UBXOF64L.mjs +68 -0
- package/dist/lib/node-esm/chunk-UBXOF64L.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1128 -1044
- 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 +35 -46
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/translations.mjs +37 -0
- package/dist/lib/node-esm/translations.mjs.map +7 -0
- package/dist/lib/node-esm/types/index.mjs +4 -3
- 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 +6 -7
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +22 -37
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +85 -81
- 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 +20 -21
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +93 -26
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableContent.d.ts +18 -0
- package/dist/types/src/components/Table/TableContent.d.ts.map +1 -0
- package/dist/types/src/components/Table/TableToolbar.d.ts +21 -0
- package/dist/types/src/components/Table/TableToolbar.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts.map +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 +24 -26
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/index.d.ts +0 -1
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +22 -15
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -1
- package/dist/types/src/hooks/index.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 +6 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +9 -9
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +0 -2
- package/dist/types/src/index.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 +18 -9
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +104 -25
- 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/playwright/playwright.config.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +18 -15
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +21 -23
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/Table.d.ts +32 -0
- package/dist/types/src/types/Table.d.ts.map +1 -0
- package/dist/types/src/types/index.d.ts +1 -1
- package/dist/types/src/types/index.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +14 -11
- 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/schema.d.ts.map +1 -1
- package/dist/types/src/util/signals.d.ts.map +1 -1
- package/dist/types/src/util/sort.d.ts +12 -0
- package/dist/types/src/util/sort.d.ts.map +1 -0
- package/dist/types/src/util/table-buttons.d.ts +20 -20
- package/dist/types/src/util/table-buttons.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts +4 -4
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/src/util/tag.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +69 -78
- package/src/components/Table/ColumnActionsMenu.tsx +17 -12
- package/src/components/Table/ColumnSettings.tsx +8 -9
- package/src/components/Table/DynamicTable.stories.tsx +32 -32
- package/src/components/Table/DynamicTable.tsx +32 -33
- package/src/components/Table/Relations.stories.tsx +116 -82
- package/src/components/Table/RowActionsMenu.tsx +27 -17
- package/src/components/Table/Table.stories.tsx +129 -116
- package/src/components/Table/Table.tsx +43 -407
- package/src/components/Table/TableContent.tsx +426 -0
- package/src/components/Table/TableToolbar.tsx +111 -0
- package/src/components/TableCellEditor/CellValidationMessage.tsx +5 -6
- package/src/components/TableCellEditor/FormCellEditor.tsx +119 -135
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +29 -22
- package/src/components/TableCellEditor/TableCellEditor.tsx +35 -33
- package/src/components/index.ts +0 -1
- package/src/components/testing.ts +38 -17
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAddRow.ts +8 -10
- package/src/hooks/useProjectionModel.ts +38 -0
- package/src/hooks/useTableModel.ts +36 -34
- package/src/index.ts +0 -4
- package/src/model/modal-controller.ts +23 -12
- package/src/model/selection-model.ts +75 -44
- package/src/model/table-model.test.ts +77 -55
- package/src/model/table-model.ts +437 -171
- package/src/model/table-presentation.test.ts +54 -50
- package/src/model/table-presentation.ts +44 -40
- package/src/playwright/TableManager.ts +13 -6
- package/src/playwright/playwright.config.ts +1 -1
- package/src/playwright/smoke.spec.ts +59 -13
- package/src/testing/useTestTableModel.ts +49 -43
- package/src/translations.ts +20 -22
- package/src/types/Table.ts +81 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.test.ts +63 -0
- package/src/util/dynamic-table.ts +49 -35
- 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-4K7JPALT.mjs +0 -66
- package/dist/lib/browser/chunk-4K7JPALT.mjs.map +0 -7
- package/dist/lib/browser/chunk-OZTXLZGM.mjs +0 -1804
- package/dist/lib/browser/chunk-OZTXLZGM.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-MK6OVUF6.mjs +0 -67
- package/dist/lib/node-esm/chunk-MK6OVUF6.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-S56Z4V4X.mjs +0 -1805
- package/dist/lib/node-esm/chunk-S56Z4V4X.mjs.map +0 -7
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts +0 -21
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +0 -1
- package/dist/types/src/components/TableToolbar/index.d.ts +0 -2
- package/dist/types/src/components/TableToolbar/index.d.ts.map +0 -1
- package/dist/types/src/model/table-sorting.d.ts +0 -52
- package/dist/types/src/model/table-sorting.d.ts.map +0 -1
- package/dist/types/src/types/schema.d.ts +0 -28
- package/dist/types/src/types/schema.d.ts.map +0 -1
- package/src/components/TableToolbar/TableToolbar.tsx +0 -102
- package/src/components/TableToolbar/index.ts +0 -5
- package/src/model/table-sorting.ts +0 -225
- package/src/types/schema.ts +0 -73
|
@@ -2,54 +2,62 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import { type RefObject, useCallback, useContext, useMemo, useRef } from 'react';
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import {
|
|
12
|
-
import {
|
|
13
|
-
import { DataType, ProjectionModel, getTypenameFromQuery } from '@dxos/schema';
|
|
8
|
+
import { type Database, Filter, Type } from '@dxos/echo';
|
|
9
|
+
import { random } from '@dxos/random';
|
|
10
|
+
import { useQuery, useType } from '@dxos/react-client/echo';
|
|
11
|
+
import { useClientStory } from '@dxos/react-client/testing';
|
|
12
|
+
import { useGlobalFilteredObjects } from '@dxos/react-ui-search';
|
|
13
|
+
import { type ProjectionModel, getTypenameFromQuery } from '@dxos/schema';
|
|
14
14
|
|
|
15
15
|
import { type TableController } from '../components';
|
|
16
|
-
import { useAddRow, useTableModel } from '../hooks';
|
|
17
|
-
import { TablePresentation } from '../model';
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
import { useAddRow, useProjectionModel, useTableModel } from '../hooks';
|
|
17
|
+
import { type TableModel, TablePresentation } from '../model';
|
|
18
|
+
import { Table } from '../types';
|
|
19
|
+
|
|
20
|
+
random.seed(0); // NOTE(ZaymonFC): Required for smoke tests.
|
|
21
|
+
|
|
22
|
+
export type TestTableModel<T extends Type.AnyObj = Type.AnyObj> = {
|
|
23
|
+
schema: T | undefined;
|
|
24
|
+
table: Table.Table | undefined;
|
|
25
|
+
projection: ProjectionModel | undefined;
|
|
26
|
+
tableRef: RefObject<TableController | null>;
|
|
27
|
+
model: TableModel | undefined;
|
|
28
|
+
presentation: TablePresentation | undefined;
|
|
29
|
+
db: Database.Database | undefined;
|
|
30
|
+
handleInsertRow: () => void;
|
|
31
|
+
handleSaveView: () => void;
|
|
32
|
+
handleDeleteRows: (rowIndex: number, objects: any[]) => void;
|
|
33
|
+
handleDeleteColumn: (fieldId: string) => void;
|
|
34
|
+
};
|
|
20
35
|
|
|
21
36
|
/**
|
|
22
37
|
* Custom hook to create and manage a test table model for storybook demonstrations.
|
|
23
38
|
* Provides table data, schema, and handlers for table operations.
|
|
24
39
|
*/
|
|
25
|
-
export const useTestTableModel = () => {
|
|
26
|
-
const
|
|
27
|
-
const { space } =
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
const
|
|
31
|
-
const
|
|
32
|
-
const
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
const projection = useMemo(() => {
|
|
36
|
-
if (schema && view?.projection) {
|
|
37
|
-
const projection = new ProjectionModel(toJsonSchema(schema), view.projection);
|
|
38
|
-
projection.normalizeView();
|
|
39
|
-
return projection;
|
|
40
|
-
}
|
|
41
|
-
}, [schema, view?.projection]);
|
|
40
|
+
export const useTestTableModel = <T extends Type.AnyObj = Type.AnyObj>(): TestTableModel<T> => {
|
|
41
|
+
const registry = useContext(RegistryContext);
|
|
42
|
+
const { space } = useClientStory();
|
|
43
|
+
const db = space?.db;
|
|
44
|
+
|
|
45
|
+
const tables = useQuery(space?.db, Filter.type(Table.Table));
|
|
46
|
+
const table = tables.at(0);
|
|
47
|
+
const typename = table?.view.target?.query ? getTypenameFromQuery(table.view.target.query.ast) : undefined;
|
|
48
|
+
const schema = useType<T>(space?.db, typename);
|
|
49
|
+
const projection = useProjectionModel(schema, table, registry);
|
|
42
50
|
|
|
43
51
|
const features = useMemo(
|
|
44
52
|
() => ({
|
|
45
53
|
selection: { enabled: true, mode: 'multiple' as const },
|
|
46
54
|
dataEditable: true,
|
|
47
|
-
schemaEditable: schema &&
|
|
55
|
+
schemaEditable: schema != null && Type.getDatabase(schema) != null,
|
|
48
56
|
}),
|
|
49
57
|
[schema],
|
|
50
58
|
);
|
|
51
59
|
|
|
52
|
-
const objects = useQuery(
|
|
60
|
+
const objects = useQuery(db, schema ? Filter.type(schema) : Filter.nothing());
|
|
53
61
|
const filteredObjects = useGlobalFilteredObjects(objects);
|
|
54
62
|
|
|
55
63
|
const tableRef = useRef<TableController>(null);
|
|
@@ -61,15 +69,15 @@ export const useTestTableModel = () => {
|
|
|
61
69
|
tableRef.current?.update?.();
|
|
62
70
|
}, []);
|
|
63
71
|
|
|
64
|
-
const addRow = useAddRow({
|
|
72
|
+
const addRow = useAddRow({ db, schema });
|
|
65
73
|
|
|
66
74
|
const handleDeleteRows = useCallback(
|
|
67
75
|
(_: number, objects: any[]) => {
|
|
68
76
|
for (const object of objects) {
|
|
69
|
-
|
|
77
|
+
db?.remove(object);
|
|
70
78
|
}
|
|
71
79
|
},
|
|
72
|
-
[
|
|
80
|
+
[db],
|
|
73
81
|
);
|
|
74
82
|
|
|
75
83
|
const handleDeleteColumn = useCallback(
|
|
@@ -82,14 +90,13 @@ export const useTestTableModel = () => {
|
|
|
82
90
|
);
|
|
83
91
|
|
|
84
92
|
const model = useTableModel({
|
|
85
|
-
|
|
86
|
-
schema: jsonSchema,
|
|
93
|
+
object: table,
|
|
87
94
|
projection,
|
|
88
95
|
features,
|
|
89
96
|
rows: filteredObjects,
|
|
90
97
|
onInsertRow: addRow,
|
|
91
98
|
onDeleteRows: handleDeleteRows,
|
|
92
|
-
|
|
99
|
+
onColumnDelete: handleDeleteColumn,
|
|
93
100
|
onCellUpdate: handleCellUpdate,
|
|
94
101
|
onRowOrderChange: handleRowOrderChange,
|
|
95
102
|
});
|
|
@@ -97,7 +104,7 @@ export const useTestTableModel = () => {
|
|
|
97
104
|
const handleInsertRow = useCallback(() => {
|
|
98
105
|
const insertResult = model?.insertRow();
|
|
99
106
|
tableRef.current?.handleInsertRowResult?.(insertResult);
|
|
100
|
-
}, [model
|
|
107
|
+
}, [model]);
|
|
101
108
|
|
|
102
109
|
const handleSaveView = useCallback(() => {
|
|
103
110
|
model?.saveView();
|
|
@@ -105,19 +112,18 @@ export const useTestTableModel = () => {
|
|
|
105
112
|
|
|
106
113
|
const presentation = useMemo(() => {
|
|
107
114
|
if (model) {
|
|
108
|
-
return new TablePresentation(model);
|
|
115
|
+
return new TablePresentation(registry, model);
|
|
109
116
|
}
|
|
110
|
-
}, [model]);
|
|
117
|
+
}, [registry, model]);
|
|
111
118
|
|
|
112
119
|
return {
|
|
113
120
|
schema,
|
|
114
|
-
|
|
121
|
+
table,
|
|
115
122
|
projection,
|
|
116
123
|
tableRef,
|
|
117
124
|
model,
|
|
118
125
|
presentation,
|
|
119
|
-
|
|
120
|
-
client,
|
|
126
|
+
db,
|
|
121
127
|
handleInsertRow,
|
|
122
128
|
handleSaveView,
|
|
123
129
|
handleDeleteRows,
|
package/src/translations.ts
CHANGED
|
@@ -4,33 +4,31 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Resource } from '@dxos/react-ui';
|
|
6
6
|
|
|
7
|
-
export const translationKey = 'react-ui-table';
|
|
7
|
+
export const translationKey = '@dxos/react-ui-table';
|
|
8
8
|
|
|
9
9
|
export const translations = [
|
|
10
10
|
{
|
|
11
11
|
'en-US': {
|
|
12
12
|
[translationKey]: {
|
|
13
|
-
'object
|
|
14
|
-
'create
|
|
15
|
-
'table
|
|
16
|
-
'settings
|
|
17
|
-
'table
|
|
18
|
-
'
|
|
19
|
-
'
|
|
20
|
-
'
|
|
21
|
-
'
|
|
22
|
-
'
|
|
23
|
-
'column
|
|
24
|
-
'column
|
|
25
|
-
'column
|
|
26
|
-
'
|
|
27
|
-
'
|
|
28
|
-
'
|
|
29
|
-
'
|
|
30
|
-
'
|
|
31
|
-
'
|
|
32
|
-
'create new object label': 'Create new object “{{text}}”',
|
|
33
|
-
'save view label': 'Save changes to view',
|
|
13
|
+
'object.placeholder': 'New table',
|
|
14
|
+
'create-object.label': 'Create table',
|
|
15
|
+
'table-name.placeholder': 'Table name',
|
|
16
|
+
'settings.title': 'Table settings',
|
|
17
|
+
'table-schema.label': 'Type',
|
|
18
|
+
'continue.label': 'Continue',
|
|
19
|
+
'create-stack-section.label': 'Create table',
|
|
20
|
+
'add-row.label': 'Add row',
|
|
21
|
+
'column-action-sort-descending.menu': 'Sort Descending',
|
|
22
|
+
'column-action-sort-ascending.menu': 'Sort Ascending',
|
|
23
|
+
'column-action-clear-sorting.menu': 'Clear Sorting',
|
|
24
|
+
'column-action-settings.menu': 'Column Settings',
|
|
25
|
+
'column-action-delete.menu': 'Delete Column',
|
|
26
|
+
'delete-row.label': 'Delete row',
|
|
27
|
+
'bulk-delete-row.label': 'Delete selected rows',
|
|
28
|
+
'column-deleted.label': 'Column deleted',
|
|
29
|
+
'new-column-button.label': 'Create column',
|
|
30
|
+
'create-new-object.label': 'Create new object “{{text}}”',
|
|
31
|
+
'save-view.label': 'Save changes to view',
|
|
34
32
|
},
|
|
35
33
|
},
|
|
36
34
|
},
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import * as Match from 'effect/Match';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
7
|
+
import * as SchemaAST from 'effect/SchemaAST';
|
|
8
|
+
|
|
9
|
+
// QueryAST is referenced indirectly through `Type.InstanceType<typeof TableSchema>`
|
|
10
|
+
// (Ref.Ref(View.View) → View.View → QueryAST.Query) in the emitted .d.ts; the
|
|
11
|
+
// namespace import keeps the inferred types portable.
|
|
12
|
+
// eslint-disable-next-line unused-imports/no-unused-imports
|
|
13
|
+
import { DXN, Annotation, JsonSchema, Obj, QueryAST, Ref, Type, View } from '@dxos/echo';
|
|
14
|
+
import { FormInputAnnotation, type JsonPath, type JsonSchemaType, LabelAnnotation } from '@dxos/echo/internal';
|
|
15
|
+
import { ViewAnnotation } from '@dxos/schema';
|
|
16
|
+
|
|
17
|
+
const TableSchema = Schema.Struct({
|
|
18
|
+
name: Schema.String.pipe(Schema.optional),
|
|
19
|
+
|
|
20
|
+
view: Ref.Ref(View.View).pipe(FormInputAnnotation.set(false)),
|
|
21
|
+
|
|
22
|
+
sizes: Schema.Record({
|
|
23
|
+
// TODO(wittjosiah): Should be JsonPath.
|
|
24
|
+
key: Schema.String,
|
|
25
|
+
value: Schema.Number,
|
|
26
|
+
}).pipe(Schema.mutable, FormInputAnnotation.set(false)),
|
|
27
|
+
}).pipe(
|
|
28
|
+
LabelAnnotation.set(['name']),
|
|
29
|
+
ViewAnnotation.set(['view']),
|
|
30
|
+
Annotation.IconAnnotation.set({
|
|
31
|
+
icon: 'ph--table--regular',
|
|
32
|
+
hue: 'green',
|
|
33
|
+
}),
|
|
34
|
+
Type.makeObject(DXN.make('org.dxos.type.table', '0.1.0')),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
// TODO(wittjosiah): Try to clean up this type inference.
|
|
38
|
+
export interface Table extends Type.InstanceType<typeof TableSchema> {}
|
|
39
|
+
export const Table = TableSchema;
|
|
40
|
+
|
|
41
|
+
type MakeProps = {
|
|
42
|
+
name?: string;
|
|
43
|
+
sizes?: Record<string, number>;
|
|
44
|
+
view: View.View;
|
|
45
|
+
/** Required to auto-size columns. */
|
|
46
|
+
jsonSchema?: JsonSchemaType;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Make a table as a view of a data set.
|
|
51
|
+
*/
|
|
52
|
+
export const make = ({ name, sizes = {}, view, jsonSchema }: MakeProps): Table => {
|
|
53
|
+
const table = Obj.make(Table, { name, view: Ref.make(view), sizes } as Obj.MakeProps<typeof Table>);
|
|
54
|
+
|
|
55
|
+
// Preset sizes.
|
|
56
|
+
if (jsonSchema) {
|
|
57
|
+
const schema = JsonSchema.toEffectSchema(jsonSchema);
|
|
58
|
+
const properties = SchemaAST.getPropertySignatures(schema.ast);
|
|
59
|
+
for (const property of properties) {
|
|
60
|
+
const name = property.name.toString() as JsonPath;
|
|
61
|
+
if (sizes?.[name]) {
|
|
62
|
+
table.sizes[name] = sizes[name];
|
|
63
|
+
continue;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
Match.type<SchemaAST.AST>().pipe(
|
|
67
|
+
Match.when({ _tag: 'BooleanKeyword' }, () => {
|
|
68
|
+
table.sizes[name] = 100;
|
|
69
|
+
}),
|
|
70
|
+
Match.when({ _tag: 'NumberKeyword' }, () => {
|
|
71
|
+
table.sizes[name] = 100;
|
|
72
|
+
}),
|
|
73
|
+
Match.orElse(() => {
|
|
74
|
+
// Noop.
|
|
75
|
+
}),
|
|
76
|
+
)(property.type);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
return table;
|
|
81
|
+
};
|
package/src/types/index.ts
CHANGED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import { describe, expect, test } from 'vitest';
|
|
7
|
+
|
|
8
|
+
import { Format } from '@dxos/echo';
|
|
9
|
+
|
|
10
|
+
import { type TablePropertyDefinition, getBaseSchema, makeDynamicTable } from './dynamic-table';
|
|
11
|
+
|
|
12
|
+
describe('makeDynamicTable', () => {
|
|
13
|
+
/**
|
|
14
|
+
* Builds the Type entity from a JSON schema, then makes the table.
|
|
15
|
+
* Confirms makeDynamicTable + setProperties (title) works for the jsonSchema path.
|
|
16
|
+
*/
|
|
17
|
+
test('makeDynamicTable from a jsonSchema with properties with title does not throw', () => {
|
|
18
|
+
const registry = Registry.make();
|
|
19
|
+
const jsonSchema = {
|
|
20
|
+
typename: 'com.example.type.dynamicTablePlain',
|
|
21
|
+
version: '0.1.0',
|
|
22
|
+
type: 'object' as const,
|
|
23
|
+
properties: {
|
|
24
|
+
id: { type: 'string' as const },
|
|
25
|
+
name: { type: 'string' as const },
|
|
26
|
+
},
|
|
27
|
+
required: ['id'],
|
|
28
|
+
};
|
|
29
|
+
const properties: TablePropertyDefinition[] = [
|
|
30
|
+
{ name: 'id', format: Format.TypeFormat.String },
|
|
31
|
+
{ name: 'name', format: Format.TypeFormat.String, title: 'Name' },
|
|
32
|
+
];
|
|
33
|
+
|
|
34
|
+
expect(() => {
|
|
35
|
+
const { type } = getBaseSchema({ jsonSchema });
|
|
36
|
+
const { projection, object } = makeDynamicTable({ registry, type, properties });
|
|
37
|
+
expect(projection).toBeDefined();
|
|
38
|
+
expect(object).toBeDefined();
|
|
39
|
+
expect(projection.getFields().length).toBeGreaterThan(0);
|
|
40
|
+
}).not.toThrow();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Builds the Type entity from property definitions, then makes the table.
|
|
45
|
+
* Confirms makeDynamicTable + setProperties (title) works for the property-definitions path.
|
|
46
|
+
*/
|
|
47
|
+
test('makeDynamicTable from getBaseSchema(typename, properties) with properties with title does not throw', () => {
|
|
48
|
+
const registry = Registry.make();
|
|
49
|
+
const typename = 'com.example.type.dynamicTableTest';
|
|
50
|
+
const properties: TablePropertyDefinition[] = [
|
|
51
|
+
{ name: 'id', format: Format.TypeFormat.String },
|
|
52
|
+
{ name: 'name', format: Format.TypeFormat.String, title: 'Name' },
|
|
53
|
+
];
|
|
54
|
+
|
|
55
|
+
expect(() => {
|
|
56
|
+
const { type } = getBaseSchema({ typename, properties });
|
|
57
|
+
const { projection, object } = makeDynamicTable({ registry, type, properties });
|
|
58
|
+
expect(projection).toBeDefined();
|
|
59
|
+
expect(object).toBeDefined();
|
|
60
|
+
expect(projection.getFields().length).toBeGreaterThan(0);
|
|
61
|
+
}).not.toThrow();
|
|
62
|
+
});
|
|
63
|
+
});
|
|
@@ -2,17 +2,16 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import type
|
|
5
|
+
import { type Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import type * as Types from 'effect/Types';
|
|
6
7
|
|
|
7
|
-
import { Filter, Obj, Query } from '@dxos/echo';
|
|
8
|
-
import { getTypename, toJsonSchema } from '@dxos/echo/internal';
|
|
9
|
-
import type { JsonSchemaType } from '@dxos/echo/internal';
|
|
8
|
+
import { Filter, type JsonSchema, Obj, Order, Query, type QueryAST, Ref, Type, type View } from '@dxos/echo';
|
|
10
9
|
import {
|
|
11
|
-
type DataType,
|
|
12
10
|
ProjectionModel,
|
|
13
11
|
type SchemaPropertyDefinition,
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
ViewModel,
|
|
13
|
+
createEchoChangeCallback,
|
|
14
|
+
getSchemaFromJsonSchema,
|
|
16
15
|
getSchemaFromPropertyDefinitions,
|
|
17
16
|
} from '@dxos/schema';
|
|
18
17
|
|
|
@@ -22,7 +21,7 @@ import { Table } from '../types';
|
|
|
22
21
|
type PropertyDisplayProps = {
|
|
23
22
|
size: number;
|
|
24
23
|
title: string;
|
|
25
|
-
sort:
|
|
24
|
+
sort: QueryAST.OrderDirection;
|
|
26
25
|
};
|
|
27
26
|
|
|
28
27
|
export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<PropertyDisplayProps>;
|
|
@@ -32,63 +31,72 @@ export type TablePropertyDefinition = SchemaPropertyDefinition & Partial<Propert
|
|
|
32
31
|
*/
|
|
33
32
|
// TODO(burdon): Remove variance.
|
|
34
33
|
export const getBaseSchema = ({
|
|
34
|
+
type,
|
|
35
35
|
typename,
|
|
36
36
|
properties,
|
|
37
37
|
jsonSchema,
|
|
38
|
-
schema,
|
|
39
38
|
}: {
|
|
39
|
+
type?: Type.AnyEntity;
|
|
40
40
|
typename?: string;
|
|
41
41
|
properties?: TablePropertyDefinition[];
|
|
42
|
-
jsonSchema?:
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return { typename: getTypename(schema)!, jsonSchema: toJsonSchema(schema) };
|
|
50
|
-
} else if (typename && jsonSchema) {
|
|
51
|
-
return { typename, jsonSchema };
|
|
52
|
-
} else {
|
|
42
|
+
jsonSchema?: Types.DeepMutable<JsonSchema.JsonSchema>;
|
|
43
|
+
}): { typename: string; type: Type.AnyEntity } => {
|
|
44
|
+
const resolved =
|
|
45
|
+
typename && properties
|
|
46
|
+
? getSchemaFromPropertyDefinitions(typename, properties)
|
|
47
|
+
: (type ?? (jsonSchema ? getSchemaFromJsonSchema(jsonSchema, typename) : undefined));
|
|
48
|
+
if (!resolved) {
|
|
53
49
|
throw new Error('invalid properties');
|
|
54
50
|
}
|
|
51
|
+
|
|
52
|
+
return { typename: Type.getTypename(resolved)!, type: resolved };
|
|
55
53
|
};
|
|
56
54
|
|
|
57
55
|
export const makeDynamicTable = ({
|
|
58
|
-
|
|
56
|
+
registry,
|
|
57
|
+
type,
|
|
59
58
|
properties,
|
|
60
59
|
}: {
|
|
61
|
-
|
|
60
|
+
registry: Registry.Registry;
|
|
61
|
+
type: Type.AnyEntity;
|
|
62
62
|
properties?: TablePropertyDefinition[];
|
|
63
|
-
}): { projection: ProjectionModel;
|
|
64
|
-
const
|
|
65
|
-
const view =
|
|
63
|
+
}): { projection: ProjectionModel; object: Table.Table } => {
|
|
64
|
+
const jsonSchema = type.jsonSchema;
|
|
65
|
+
const view = ViewModel.make({
|
|
66
66
|
query: Query.select(Filter.everything()),
|
|
67
67
|
jsonSchema,
|
|
68
|
-
|
|
68
|
+
type,
|
|
69
69
|
...(properties && { fields: properties.map((property) => property.name) }),
|
|
70
70
|
});
|
|
71
|
+
const object = Obj.make(Table.Table, { view: Ref.make(view), sizes: {} });
|
|
71
72
|
|
|
72
|
-
const projection = new ProjectionModel(
|
|
73
|
+
const projection = new ProjectionModel({
|
|
74
|
+
registry,
|
|
75
|
+
view,
|
|
76
|
+
baseSchema: jsonSchema,
|
|
77
|
+
change: createEchoChangeCallback(view, type),
|
|
78
|
+
});
|
|
73
79
|
projection.normalizeView();
|
|
74
|
-
if (properties && projection.
|
|
75
|
-
setProperties(view, projection,
|
|
80
|
+
if (properties && projection.getFields()) {
|
|
81
|
+
setProperties(view, projection, object, properties);
|
|
76
82
|
}
|
|
77
83
|
|
|
78
|
-
return { projection,
|
|
84
|
+
return { projection, object };
|
|
79
85
|
};
|
|
80
86
|
|
|
81
87
|
const setProperties = (
|
|
82
|
-
view:
|
|
88
|
+
view: View.View,
|
|
83
89
|
projection: ProjectionModel,
|
|
84
90
|
table: Table.Table,
|
|
85
91
|
properties: TablePropertyDefinition[],
|
|
86
92
|
) => {
|
|
87
93
|
for (const property of properties) {
|
|
88
|
-
const field = projection.
|
|
94
|
+
const field = projection.getFields().find((field) => field.path === property.name);
|
|
89
95
|
if (field) {
|
|
90
96
|
if (property.size !== undefined) {
|
|
91
|
-
table
|
|
97
|
+
Obj.update(table, (table) => {
|
|
98
|
+
table.sizes[field.path] = property.size!;
|
|
99
|
+
});
|
|
92
100
|
}
|
|
93
101
|
|
|
94
102
|
if (property.title !== undefined) {
|
|
@@ -100,8 +108,14 @@ const setProperties = (
|
|
|
100
108
|
}
|
|
101
109
|
|
|
102
110
|
if (property.sort) {
|
|
103
|
-
|
|
104
|
-
|
|
111
|
+
// Apply sort to query instead of deprecated view.sort
|
|
112
|
+
const currentQuery = Query.fromAst(Obj.getSnapshot(view).query.ast);
|
|
113
|
+
// Use any type parameter since we're working with dynamic field paths
|
|
114
|
+
const newQuery = currentQuery.orderBy(Order.property<any>(field.path as string, property.sort));
|
|
115
|
+
Obj.update(view, (view) => {
|
|
116
|
+
// Type assertion needed because Query AST types have some variance issues.
|
|
117
|
+
view.query.ast = newQuery.ast as typeof view.query.ast;
|
|
118
|
+
});
|
|
105
119
|
}
|
|
106
120
|
}
|
|
107
121
|
}
|
package/src/util/index.ts
CHANGED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type QueryAST } from '@dxos/echo';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Extracts order clauses from a query AST.
|
|
9
|
+
* Handles nested structures (options, order, etc.).
|
|
10
|
+
*/
|
|
11
|
+
export const extractOrder = (queryAst: QueryAST.Query): readonly QueryAST.Order[] | undefined => {
|
|
12
|
+
if (queryAst.type === 'order') {
|
|
13
|
+
return queryAst.order;
|
|
14
|
+
}
|
|
15
|
+
if (queryAst.type === 'options') {
|
|
16
|
+
return extractOrder(queryAst.query);
|
|
17
|
+
}
|
|
18
|
+
if (queryAst.type === 'from') {
|
|
19
|
+
return extractOrder(queryAst.query);
|
|
20
|
+
}
|
|
21
|
+
return undefined;
|
|
22
|
+
};
|
package/src/util/sort.ts
ADDED
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { Format, type QueryAST } from '@dxos/echo';
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Gets a normalized sort value for a given value and format.
|
|
9
|
+
* This ensures consistent sorting behavior across different data types.
|
|
10
|
+
*/
|
|
11
|
+
export const getSortValue = (value: any, format: Format.TypeFormat): any => {
|
|
12
|
+
// Handle null/undefined
|
|
13
|
+
if (value === undefined || value === null) {
|
|
14
|
+
return null;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Handle dates chronologically if schema indicates date format
|
|
18
|
+
const isDateFormat = format === Format.TypeFormat.DateTime || format === Format.TypeFormat.Date;
|
|
19
|
+
if (isDateFormat) {
|
|
20
|
+
const date = new Date(value);
|
|
21
|
+
if (!isNaN(date.getTime())) {
|
|
22
|
+
return date.getTime();
|
|
23
|
+
}
|
|
24
|
+
// Fallback to string if date parsing fails
|
|
25
|
+
return String(value);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
// Handle numbers if schema indicates number format
|
|
29
|
+
if (
|
|
30
|
+
format === Format.TypeFormat.Number ||
|
|
31
|
+
format === Format.TypeFormat.Integer ||
|
|
32
|
+
format === Format.TypeFormat.Currency ||
|
|
33
|
+
format === Format.TypeFormat.Percent ||
|
|
34
|
+
format === Format.TypeFormat.Duration
|
|
35
|
+
) {
|
|
36
|
+
const num = typeof value === 'number' ? value : Number(value);
|
|
37
|
+
if (!isNaN(num)) {
|
|
38
|
+
return num;
|
|
39
|
+
}
|
|
40
|
+
// Fallback to string if number parsing fails
|
|
41
|
+
return String(value);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
// Default to string comparison
|
|
45
|
+
if (typeof value === 'string') {
|
|
46
|
+
return value;
|
|
47
|
+
}
|
|
48
|
+
if (typeof value === 'number') {
|
|
49
|
+
return value;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// Fallback to string representation
|
|
53
|
+
return String(value);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Compares two values for sorting based on the field format.
|
|
58
|
+
* Handles dates, numbers, and strings appropriately.
|
|
59
|
+
*/
|
|
60
|
+
export const compareValues = (
|
|
61
|
+
aValue: any,
|
|
62
|
+
bValue: any,
|
|
63
|
+
format: Format.TypeFormat,
|
|
64
|
+
direction: QueryAST.OrderDirection,
|
|
65
|
+
): number => {
|
|
66
|
+
// Handle null/undefined values - nulls sort to the end
|
|
67
|
+
if (aValue === undefined || aValue === null) {
|
|
68
|
+
return bValue === undefined || bValue === null ? 0 : 1;
|
|
69
|
+
}
|
|
70
|
+
if (bValue === undefined || bValue === null) {
|
|
71
|
+
return -1;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
// Get normalized sort values
|
|
75
|
+
const aSortValue = getSortValue(aValue, format);
|
|
76
|
+
const bSortValue = getSortValue(bValue, format);
|
|
77
|
+
|
|
78
|
+
// Compare based on type
|
|
79
|
+
let comparison = 0;
|
|
80
|
+
if (typeof aSortValue === 'number' && typeof bSortValue === 'number') {
|
|
81
|
+
comparison = aSortValue - bSortValue;
|
|
82
|
+
} else if (typeof aSortValue === 'string' && typeof bSortValue === 'string') {
|
|
83
|
+
comparison = aSortValue.localeCompare(bSortValue);
|
|
84
|
+
} else {
|
|
85
|
+
// Mixed types - convert both to strings
|
|
86
|
+
comparison = String(aSortValue).localeCompare(String(bSortValue));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
return direction === 'desc' ? -comparison : comparison;
|
|
90
|
+
};
|
|
@@ -39,7 +39,7 @@ const createButton = ({
|
|
|
39
39
|
.map(([k, v]) => `${k}="${v}"`)
|
|
40
40
|
.join(' ');
|
|
41
41
|
|
|
42
|
-
return `<button ${attr} data-testid="${testId}" class="dx-button
|
|
42
|
+
return `<button ${attr} data-testid="${testId}" class="dx-button w-6 aspect-square px-0.5 min-h-0" ${dataAttrs} ${disabled ? 'disabled' : ''} data-dx-grid-action="accessory"><svg data-size="4"><use href="/icons.svg#${icon}"/></svg></button>`;
|
|
43
43
|
};
|
|
44
44
|
|
|
45
45
|
const addColumnButton = {
|
|
@@ -25,8 +25,8 @@ export const CONTROL_IDENTIFIERS = {
|
|
|
25
25
|
} as const;
|
|
26
26
|
|
|
27
27
|
const BASE_CLASSES = {
|
|
28
|
-
checkbox: 'absolute inset-
|
|
29
|
-
switch: 'absolute inset-
|
|
28
|
+
checkbox: 'absolute inset-y-[.375rem] end-[.375rem] dx-checkbox',
|
|
29
|
+
switch: 'absolute inset-y-[.25rem] end-[.25rem] dx-checkbox--switch',
|
|
30
30
|
} as const;
|
|
31
31
|
|
|
32
32
|
const renderAttributes = (data: Record<string, string>) => {
|