@dxos/react-ui-table 0.8.4-main.dedc0f3 → 0.8.4-main.dfabb4ec29
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-FBURZBPH.mjs +70 -0
- package/dist/lib/browser/chunk-FBURZBPH.mjs.map +7 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs +10 -0
- package/dist/lib/browser/chunk-J5LGTIGS.mjs.map +7 -0
- package/dist/lib/browser/chunk-YGC7LZJN.mjs +1695 -0
- package/dist/lib/browser/chunk-YGC7LZJN.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1139 -1193
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +33 -42
- 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-DKKMSVKP.mjs +71 -0
- package/dist/lib/node-esm/chunk-DKKMSVKP.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-GKIWDEZ7.mjs +1697 -0
- package/dist/lib/node-esm/chunk-GKIWDEZ7.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/index.mjs +1139 -1193
- 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 +33 -42
- 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 +7 -7
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +23 -39
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +96 -29
- 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 -18
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +96 -31
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/TableContent.d.ts +17 -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 +12 -12
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +7 -7
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +25 -28
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/index.d.ts +1 -0
- package/dist/types/src/components/TableCellEditor/index.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 +23 -16
- 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 -8
- 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 +106 -26
- 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 +26 -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 -12
- 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 +1 -1
- 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 +67 -76
- package/src/components/Table/ColumnActionsMenu.tsx +17 -12
- package/src/components/Table/ColumnSettings.tsx +8 -9
- package/src/components/Table/DynamicTable.stories.tsx +34 -33
- package/src/components/Table/DynamicTable.tsx +33 -36
- package/src/components/Table/Relations.stories.tsx +196 -48
- package/src/components/Table/RowActionsMenu.tsx +27 -17
- package/src/components/Table/Table.stories.tsx +144 -127
- package/src/components/Table/Table.tsx +43 -403
- package/src/components/Table/TableContent.tsx +421 -0
- package/src/components/Table/TableToolbar.tsx +111 -0
- package/src/components/TableCellEditor/CellValidationMessage.tsx +5 -6
- package/src/components/TableCellEditor/FormCellEditor.tsx +125 -131
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +32 -55
- package/src/components/TableCellEditor/TableCellEditor.tsx +39 -124
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/index.ts +0 -1
- package/src/components/testing.ts +44 -18
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAddRow.ts +8 -10
- package/src/hooks/useProjectionModel.ts +39 -0
- package/src/hooks/useTableModel.ts +36 -34
- package/src/index.ts +0 -4
- package/src/model/modal-controller.ts +23 -40
- package/src/model/selection-model.ts +75 -44
- package/src/model/table-model.test.ts +93 -56
- package/src/model/table-model.ts +437 -170
- package/src/model/table-presentation.test.ts +67 -56
- package/src/model/table-presentation.ts +45 -41
- 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 +48 -39
- package/src/translations.ts +20 -22
- package/src/types/Table.ts +79 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.test.ts +70 -0
- package/src/util/dynamic-table.ts +43 -31
- package/src/util/index.ts +2 -0
- package/src/util/query-ast.ts +22 -0
- package/src/util/schema.ts +4 -4
- 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-63UUF4IG.mjs +0 -66
- package/dist/lib/browser/chunk-63UUF4IG.mjs.map +0 -7
- package/dist/lib/browser/chunk-GPZSXPSA.mjs +0 -1822
- package/dist/lib/browser/chunk-GPZSXPSA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K734DJB7.mjs +0 -67
- package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-XUD6W42C.mjs +0 -1823
- package/dist/lib/node-esm/chunk-XUD6W42C.mjs.map +0 -7
- package/dist/types/src/components/Table/CreateRefPanel.d.ts +0 -9
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +0 -1
- 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/Table/CreateRefPanel.tsx +0 -103
- 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
|
@@ -4,15 +4,13 @@
|
|
|
4
4
|
|
|
5
5
|
import { type Completion } from '@codemirror/autocomplete';
|
|
6
6
|
import { EditorView } from '@codemirror/view';
|
|
7
|
-
import { type Schema } from 'effect/Schema';
|
|
8
7
|
import React, { useCallback, useMemo, useRef, useState } from 'react';
|
|
9
8
|
|
|
10
9
|
import { debounce } from '@dxos/async';
|
|
11
|
-
import type
|
|
12
|
-
import {
|
|
10
|
+
import { type Type } from '@dxos/echo';
|
|
11
|
+
import { Format, TypeEnum } from '@dxos/echo/internal';
|
|
13
12
|
import { invariant } from '@dxos/invariant';
|
|
14
13
|
import { type DxGridAxis, type DxGridPosition } from '@dxos/lit-grid';
|
|
15
|
-
import { createMarkdownExtensions } from '@dxos/react-ui-editor';
|
|
16
14
|
import {
|
|
17
15
|
type EditorBlurHandler,
|
|
18
16
|
type EditorKeyEvent,
|
|
@@ -24,40 +22,37 @@ import {
|
|
|
24
22
|
parseCellIndex,
|
|
25
23
|
useGridContext,
|
|
26
24
|
} from '@dxos/react-ui-grid';
|
|
27
|
-
import { createLinks, tagPicker } from '@dxos/react-ui-tag-picker';
|
|
28
25
|
import { type FieldProjection } from '@dxos/schema';
|
|
29
26
|
|
|
30
27
|
import { type ModalController, type TableModel } from '../../model';
|
|
31
|
-
|
|
32
28
|
import { CellValidationMessage } from './CellValidationMessage';
|
|
33
|
-
import { FormCellEditor } from './FormCellEditor';
|
|
29
|
+
import { FormCellEditor, type OnCreateHandler } from './FormCellEditor';
|
|
34
30
|
|
|
35
31
|
/**
|
|
36
32
|
* Option to create new object/value.
|
|
37
33
|
*/
|
|
38
|
-
export type QueryResult = Pick<Completion, 'label'> & {
|
|
34
|
+
export type QueryResult = Pick<Completion, 'label'> & {
|
|
35
|
+
data: any;
|
|
36
|
+
};
|
|
39
37
|
|
|
40
|
-
export type TableCellEditorProps = {
|
|
38
|
+
export type TableCellEditorProps<T extends Type.AnyEntity = Type.AnyEntity> = {
|
|
39
|
+
schema?: T;
|
|
41
40
|
model?: TableModel;
|
|
42
41
|
modals?: ModalController;
|
|
43
|
-
schema?: Schema.AnyNoContext;
|
|
44
42
|
onFocus?: (axis?: DxGridAxis, delta?: -1 | 0 | 1, cell?: DxGridPosition) => void;
|
|
43
|
+
onCreate?: OnCreateHandler;
|
|
45
44
|
onSave?: () => void;
|
|
46
|
-
client?: Client;
|
|
47
45
|
};
|
|
48
46
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
export const TableValueEditor = ({
|
|
47
|
+
export const TableValueEditor = <T extends Type.AnyEntity = Type.AnyEntity>({
|
|
48
|
+
__gridScope,
|
|
49
|
+
schema,
|
|
53
50
|
model,
|
|
54
51
|
modals,
|
|
55
|
-
schema,
|
|
56
52
|
onFocus,
|
|
57
53
|
onSave,
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
}: GridScopedProps<TableCellEditorProps>) => {
|
|
54
|
+
onCreate,
|
|
55
|
+
}: GridScopedProps<TableCellEditorProps<T>>) => {
|
|
61
56
|
const { editing } = useGridContext('TableValueEditor', __gridScope);
|
|
62
57
|
|
|
63
58
|
const fieldProjection = useMemo<FieldProjection | undefined>(() => {
|
|
@@ -66,7 +61,7 @@ export const TableValueEditor = ({
|
|
|
66
61
|
}
|
|
67
62
|
|
|
68
63
|
const { col } = parseCellIndex(editing.index);
|
|
69
|
-
const field = model.projection.
|
|
64
|
+
const field = model.projection.getFields()[col];
|
|
70
65
|
const fieldProjection = model.projection.getFieldProjection(field.id);
|
|
71
66
|
invariant(fieldProjection);
|
|
72
67
|
return fieldProjection;
|
|
@@ -74,35 +69,33 @@ export const TableValueEditor = ({
|
|
|
74
69
|
|
|
75
70
|
if (
|
|
76
71
|
fieldProjection?.props.type === TypeEnum.Array ||
|
|
77
|
-
fieldProjection?.props.format ===
|
|
78
|
-
fieldProjection?.props.format ===
|
|
79
|
-
// TODO(thure): Support `
|
|
72
|
+
fieldProjection?.props.format === Format.TypeFormat.SingleSelect ||
|
|
73
|
+
fieldProjection?.props.format === Format.TypeFormat.Ref
|
|
74
|
+
// TODO(thure): Support `Format.TypeFormat.MultiSelect`
|
|
80
75
|
) {
|
|
81
76
|
return (
|
|
82
|
-
<FormCellEditor
|
|
83
|
-
fieldProjection={fieldProjection}
|
|
84
|
-
model={model}
|
|
85
|
-
schema={schema}
|
|
77
|
+
<FormCellEditor<T>
|
|
86
78
|
__gridScope={__gridScope}
|
|
87
|
-
|
|
88
|
-
|
|
79
|
+
schema={schema}
|
|
80
|
+
model={model}
|
|
81
|
+
fieldProjection={fieldProjection}
|
|
89
82
|
modals={modals}
|
|
83
|
+
onSave={onSave}
|
|
84
|
+
onCreate={onCreate}
|
|
90
85
|
/>
|
|
91
86
|
);
|
|
92
87
|
}
|
|
93
88
|
|
|
94
|
-
// For all other types, use the existing cell editor
|
|
89
|
+
// For all other types, use the existing cell editor.
|
|
95
90
|
return <TableCellEditor model={model} modals={modals} onFocus={onFocus} onSave={onSave} __gridScope={__gridScope} />;
|
|
96
91
|
};
|
|
97
92
|
|
|
98
|
-
const editorSlots = { scroll: { className: '!plb-[--dx-grid-cell-editor-padding-block]' } };
|
|
99
|
-
|
|
100
93
|
export const TableCellEditor = ({
|
|
94
|
+
__gridScope,
|
|
101
95
|
model,
|
|
102
96
|
modals,
|
|
103
97
|
onFocus,
|
|
104
98
|
onSave,
|
|
105
|
-
__gridScope,
|
|
106
99
|
}: GridScopedProps<TableCellEditorProps>) => {
|
|
107
100
|
const { editing, setEditing } = useGridContext('TableCellEditor', __gridScope);
|
|
108
101
|
const suppressNextBlur = useRef(false);
|
|
@@ -115,12 +108,13 @@ export const TableCellEditor = ({
|
|
|
115
108
|
}
|
|
116
109
|
|
|
117
110
|
const { col } = parseCellIndex(editing.index);
|
|
118
|
-
const field = model.projection.
|
|
111
|
+
const field = model.projection.getFields()[col];
|
|
119
112
|
const fieldProjection = model.projection.getFieldProjection(field.id);
|
|
120
113
|
invariant(fieldProjection);
|
|
121
114
|
return fieldProjection;
|
|
122
115
|
}, [model, editing]);
|
|
123
116
|
|
|
117
|
+
// TOOD(burdon): Attach to event handler?
|
|
124
118
|
const handleEnter = useCallback(
|
|
125
119
|
async (value: any) => {
|
|
126
120
|
if (!model || !editing) {
|
|
@@ -137,7 +131,7 @@ export const TableCellEditor = ({
|
|
|
137
131
|
setEditing(null);
|
|
138
132
|
onSave?.();
|
|
139
133
|
} else {
|
|
140
|
-
setValidationError(
|
|
134
|
+
setValidationError(validationResult.error);
|
|
141
135
|
setValidationVariant('error');
|
|
142
136
|
}
|
|
143
137
|
},
|
|
@@ -213,48 +207,6 @@ export const TableCellEditor = ({
|
|
|
213
207
|
...(editing?.initialContent && { onNav: handleClose }),
|
|
214
208
|
}),
|
|
215
209
|
];
|
|
216
|
-
|
|
217
|
-
const format = fieldProjection.props.format;
|
|
218
|
-
if (format === FormatEnum.SingleSelect || format === FormatEnum.MultiSelect) {
|
|
219
|
-
// TODO(ZaymonFC): Reconcile this with the TagPicker component?
|
|
220
|
-
const options = fieldProjection.props.options || [];
|
|
221
|
-
const mode = format === FormatEnum.SingleSelect ? ('single-select' as const) : ('multi-select' as const);
|
|
222
|
-
|
|
223
|
-
// Add markdown extensions needed by tag picker.
|
|
224
|
-
extensions.push(createMarkdownExtensions());
|
|
225
|
-
extensions.push(
|
|
226
|
-
tagPicker({
|
|
227
|
-
mode,
|
|
228
|
-
keymap: false,
|
|
229
|
-
onSearch: (text, selectedIds) => {
|
|
230
|
-
return options
|
|
231
|
-
.filter(
|
|
232
|
-
(option) =>
|
|
233
|
-
selectedIds.indexOf(option.id) === -1 &&
|
|
234
|
-
(text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase())),
|
|
235
|
-
)
|
|
236
|
-
.map((option) => ({
|
|
237
|
-
id: option.id,
|
|
238
|
-
label: option.title,
|
|
239
|
-
hue: option.color as any,
|
|
240
|
-
}));
|
|
241
|
-
},
|
|
242
|
-
onUpdate: (ids) => {
|
|
243
|
-
if (model && editing) {
|
|
244
|
-
if (ids.length === 0) {
|
|
245
|
-
return;
|
|
246
|
-
}
|
|
247
|
-
if (mode === 'single-select') {
|
|
248
|
-
void handleEnter(ids[0]);
|
|
249
|
-
} else {
|
|
250
|
-
void handleEnter(ids);
|
|
251
|
-
}
|
|
252
|
-
}
|
|
253
|
-
},
|
|
254
|
-
}),
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
|
|
258
210
|
// Add validation extension to handle content changes.
|
|
259
211
|
if (model && editing) {
|
|
260
212
|
extensions.push(
|
|
@@ -283,52 +235,6 @@ export const TableCellEditor = ({
|
|
|
283
235
|
const getCellContent = useCallback<GridCellEditorProps['getCellContent']>(() => {
|
|
284
236
|
if (model && editing) {
|
|
285
237
|
const cell = parseCellIndex(editing.index);
|
|
286
|
-
const { col } = cell;
|
|
287
|
-
const field = model.projection.fields[col];
|
|
288
|
-
const fieldProjection = model.projection.getFieldProjection(field.id);
|
|
289
|
-
|
|
290
|
-
if (
|
|
291
|
-
fieldProjection?.props.format === FormatEnum.SingleSelect ||
|
|
292
|
-
fieldProjection?.props.format === FormatEnum.MultiSelect
|
|
293
|
-
) {
|
|
294
|
-
const value = model.getCellData(cell);
|
|
295
|
-
if (value !== undefined) {
|
|
296
|
-
const options = fieldProjection.props.options || [];
|
|
297
|
-
if (fieldProjection.props.format === FormatEnum.MultiSelect) {
|
|
298
|
-
const tagItems = value
|
|
299
|
-
.split(',')
|
|
300
|
-
.map((id: string) => {
|
|
301
|
-
const option = options.find((o) => o.id === id);
|
|
302
|
-
if (option) {
|
|
303
|
-
return {
|
|
304
|
-
id,
|
|
305
|
-
label: option.title,
|
|
306
|
-
hue: option.color as any,
|
|
307
|
-
};
|
|
308
|
-
}
|
|
309
|
-
return undefined;
|
|
310
|
-
})
|
|
311
|
-
.filter((item: any): item is { id: any; label: string; hue: any } => item !== undefined);
|
|
312
|
-
|
|
313
|
-
return createLinks(tagItems);
|
|
314
|
-
} else {
|
|
315
|
-
const option = options.find((o) => o.id === value);
|
|
316
|
-
|
|
317
|
-
if (option) {
|
|
318
|
-
const tagItem = {
|
|
319
|
-
id: value,
|
|
320
|
-
label: option.title,
|
|
321
|
-
hue: option.color as any,
|
|
322
|
-
};
|
|
323
|
-
|
|
324
|
-
return createLinks([tagItem]);
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return '';
|
|
330
|
-
}
|
|
331
|
-
|
|
332
238
|
const value = model.getCellData(cell);
|
|
333
239
|
return value !== undefined ? String(value) : '';
|
|
334
240
|
}
|
|
@@ -337,7 +243,16 @@ export const TableCellEditor = ({
|
|
|
337
243
|
return (
|
|
338
244
|
<>
|
|
339
245
|
<CellValidationMessage validationError={validationError} variant={validationVariant} __gridScope={__gridScope} />
|
|
340
|
-
<GridCellEditor
|
|
246
|
+
<GridCellEditor
|
|
247
|
+
extensions={extensions}
|
|
248
|
+
slots={{
|
|
249
|
+
content: {
|
|
250
|
+
className: '!py-(--dx-grid-cell-editor-padding-block)',
|
|
251
|
+
},
|
|
252
|
+
}}
|
|
253
|
+
getCellContent={getCellContent}
|
|
254
|
+
onBlur={handleBlur}
|
|
255
|
+
/>
|
|
341
256
|
</>
|
|
342
257
|
);
|
|
343
258
|
};
|
package/src/components/index.ts
CHANGED
|
@@ -2,33 +2,59 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { Atom } from '@effect-atom/atom-react';
|
|
6
|
+
import * as Schema from 'effect/Schema';
|
|
6
7
|
import { useEffect } from 'react';
|
|
7
8
|
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
9
|
+
import { Format, Type } from '@dxos/echo';
|
|
10
|
+
import { TypeEnum } from '@dxos/echo/internal';
|
|
11
|
+
import { setValue } from '@dxos/effect';
|
|
12
|
+
import { random } from '@dxos/random';
|
|
11
13
|
import { type ProjectionModel } from '@dxos/schema';
|
|
12
14
|
|
|
13
|
-
export const TestSchema =
|
|
14
|
-
id: ObjectId,
|
|
15
|
+
export const TestSchema = Schema.Struct({
|
|
15
16
|
name: Schema.optional(Schema.String),
|
|
16
17
|
age: Schema.optional(Schema.Number),
|
|
17
18
|
active: Schema.optional(Schema.Boolean),
|
|
18
19
|
netWorth: Schema.optional(Schema.Number),
|
|
19
|
-
})
|
|
20
|
+
}).pipe(
|
|
21
|
+
Type.object({
|
|
22
|
+
typename: 'com.example.type.test',
|
|
23
|
+
version: '0.1.0',
|
|
24
|
+
}),
|
|
25
|
+
);
|
|
20
26
|
|
|
21
|
-
export
|
|
22
|
-
|
|
27
|
+
export type TestItem = {
|
|
28
|
+
name: string;
|
|
29
|
+
age: number;
|
|
30
|
+
active: boolean;
|
|
31
|
+
netWorth: number;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Creates an Atom containing test items data.
|
|
36
|
+
*/
|
|
37
|
+
export const createItemsAtom = (n: number) => {
|
|
38
|
+
return Atom.make<{ data: TestItem[] }>({
|
|
23
39
|
data: Array.from({ length: n }, () => ({
|
|
24
|
-
name:
|
|
25
|
-
age:
|
|
26
|
-
active:
|
|
27
|
-
netWorth:
|
|
40
|
+
name: random.person.fullName(),
|
|
41
|
+
age: random.number.int({ min: 20, max: 70 }),
|
|
42
|
+
active: random.datatype.boolean(),
|
|
43
|
+
netWorth: random.number.int(),
|
|
28
44
|
})),
|
|
29
|
-
});
|
|
45
|
+
}).pipe(Atom.keepAlive);
|
|
46
|
+
};
|
|
30
47
|
|
|
31
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Creates plain test items (non-reactive).
|
|
50
|
+
*/
|
|
51
|
+
export const createItems = (n: number): TestItem[] => {
|
|
52
|
+
return Array.from({ length: n }, () => ({
|
|
53
|
+
name: random.person.fullName(),
|
|
54
|
+
age: random.number.int({ min: 20, max: 70 }),
|
|
55
|
+
active: random.datatype.boolean(),
|
|
56
|
+
netWorth: random.number.int(),
|
|
57
|
+
}));
|
|
32
58
|
};
|
|
33
59
|
|
|
34
60
|
export type SimulatorProps = {
|
|
@@ -59,7 +85,7 @@ export const useSimulator = ({ items, projection, insertInterval, updateInterval
|
|
|
59
85
|
|
|
60
86
|
const i = setInterval(() => {
|
|
61
87
|
const rowIdx = Math.floor(Math.random() * items.length);
|
|
62
|
-
const fields = projection.
|
|
88
|
+
const fields = projection.getFields() ?? [];
|
|
63
89
|
const columnIdx = Math.floor(Math.random() * fields.length);
|
|
64
90
|
const field = fields[columnIdx];
|
|
65
91
|
const item = items[rowIdx];
|
|
@@ -88,7 +114,7 @@ export const useSimulator = ({ items, projection, insertInterval, updateInterval
|
|
|
88
114
|
|
|
89
115
|
if (format) {
|
|
90
116
|
switch (format) {
|
|
91
|
-
case
|
|
117
|
+
case Format.TypeFormat.Currency: {
|
|
92
118
|
item[path] = Math.floor(Math.random() * 1000);
|
|
93
119
|
break;
|
|
94
120
|
}
|
|
@@ -98,5 +124,5 @@ export const useSimulator = ({ items, projection, insertInterval, updateInterval
|
|
|
98
124
|
}, updateInterval);
|
|
99
125
|
|
|
100
126
|
return () => clearInterval(i);
|
|
101
|
-
}, [items, projection.
|
|
127
|
+
}, [items, projection.getFields(), updateInterval]);
|
|
102
128
|
};
|
package/src/hooks/index.ts
CHANGED
package/src/hooks/useAddRow.ts
CHANGED
|
@@ -2,17 +2,15 @@
|
|
|
2
2
|
// Copyright 2025 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Schema } from 'effect';
|
|
6
5
|
import { useCallback } from 'react';
|
|
7
6
|
|
|
8
|
-
import { type
|
|
9
|
-
import { Obj } from '@dxos/echo';
|
|
7
|
+
import { type Database, Obj, type Type } from '@dxos/echo';
|
|
10
8
|
|
|
11
9
|
import { type InsertRowResult } from '../model';
|
|
12
10
|
|
|
13
|
-
export type
|
|
14
|
-
|
|
15
|
-
schema?:
|
|
11
|
+
export type UseAddRowProps = {
|
|
12
|
+
db?: Database.Database;
|
|
13
|
+
schema?: Type.AnyObj;
|
|
16
14
|
};
|
|
17
15
|
|
|
18
16
|
/**
|
|
@@ -20,12 +18,12 @@ export type UseAddRowParams = {
|
|
|
20
18
|
* Returns a callback that attempts to create an object and returns boolean success/failure.
|
|
21
19
|
* Can accept optional data to create objects with specific content (used for committing draft rows).
|
|
22
20
|
*/
|
|
23
|
-
export const useAddRow = ({
|
|
21
|
+
export const useAddRow = ({ db, schema }: UseAddRowProps) => {
|
|
24
22
|
return useCallback(
|
|
25
23
|
(data?: any): InsertRowResult => {
|
|
26
|
-
if (
|
|
24
|
+
if (db && schema) {
|
|
27
25
|
try {
|
|
28
|
-
|
|
26
|
+
db.add(Obj.make(schema, data ?? {}));
|
|
29
27
|
return 'final';
|
|
30
28
|
} catch (error) {
|
|
31
29
|
return 'draft';
|
|
@@ -33,6 +31,6 @@ export const useAddRow = ({ space, schema }: UseAddRowParams) => {
|
|
|
33
31
|
}
|
|
34
32
|
return 'final';
|
|
35
33
|
},
|
|
36
|
-
[
|
|
34
|
+
[db, schema],
|
|
37
35
|
);
|
|
38
36
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2025 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type Registry } from '@effect-atom/atom-react';
|
|
6
|
+
import { useState } from 'react';
|
|
7
|
+
|
|
8
|
+
import { JsonSchema, Type } from '@dxos/echo';
|
|
9
|
+
import { useAsyncEffect } from '@dxos/react-ui';
|
|
10
|
+
import { ProjectionModel, createEchoChangeCallback } from '@dxos/schema';
|
|
11
|
+
|
|
12
|
+
import { type Table } from '../types';
|
|
13
|
+
|
|
14
|
+
export const useProjectionModel = <S extends Type.AnyEntity>(
|
|
15
|
+
schema: S | undefined,
|
|
16
|
+
table: Table.Table | undefined,
|
|
17
|
+
registry: Registry.Registry,
|
|
18
|
+
) => {
|
|
19
|
+
const [projection, setProjection] = useState<ProjectionModel | undefined>();
|
|
20
|
+
|
|
21
|
+
useAsyncEffect(async () => {
|
|
22
|
+
if (schema && table) {
|
|
23
|
+
const view = await table.view.load();
|
|
24
|
+
// For mutable schemas (EchoSchema), use the live jsonSchema reference for reactivity.
|
|
25
|
+
// For immutable schemas, create a snapshot.
|
|
26
|
+
const jsonSchema = Type.isMutable(schema) ? schema.jsonSchema : JsonSchema.toJsonSchema(schema);
|
|
27
|
+
|
|
28
|
+
// Always use createEchoChangeCallback since the view is ECHO-backed.
|
|
29
|
+
// Pass schema only when mutable to allow schema mutations.
|
|
30
|
+
const change = createEchoChangeCallback(view, Type.isMutable(schema) ? schema : undefined);
|
|
31
|
+
|
|
32
|
+
const projection = new ProjectionModel({ registry, view, baseSchema: jsonSchema, change });
|
|
33
|
+
projection.normalizeView();
|
|
34
|
+
setProjection(projection);
|
|
35
|
+
}
|
|
36
|
+
}, [schema, table, registry]);
|
|
37
|
+
|
|
38
|
+
return projection;
|
|
39
|
+
};
|
|
@@ -2,58 +2,65 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
7
|
-
import { useEffect, useMemo, useState } from 'react';
|
|
5
|
+
import { RegistryContext } from '@effect-atom/atom-react';
|
|
6
|
+
import { useContext, useEffect, useMemo, useState } from 'react';
|
|
8
7
|
|
|
9
|
-
import { type
|
|
10
|
-
import { type Live } from '@dxos/live-object';
|
|
11
|
-
import { fullyQualifiedId } from '@dxos/react-client/echo';
|
|
8
|
+
import { type Database, Obj } from '@dxos/echo';
|
|
12
9
|
import { useSelected, useSelectionActions } from '@dxos/react-ui-attention';
|
|
13
|
-
import { type
|
|
10
|
+
import { type ProjectionModel } from '@dxos/schema';
|
|
14
11
|
import { isNonNullable } from '@dxos/util';
|
|
15
12
|
|
|
16
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
TableModel,
|
|
15
|
+
type TableModelProps,
|
|
16
|
+
type TableRow,
|
|
17
|
+
type TableRowAction,
|
|
18
|
+
createEchoChangeCallback,
|
|
19
|
+
} from '../model';
|
|
20
|
+
import { type Table } from '../types';
|
|
17
21
|
|
|
18
|
-
export type
|
|
19
|
-
|
|
20
|
-
schema?: JsonSchemaType;
|
|
22
|
+
export type UseTableModelProps<T extends TableRow = TableRow> = {
|
|
23
|
+
object?: Table.Table;
|
|
21
24
|
projection?: ProjectionModel;
|
|
22
|
-
|
|
25
|
+
db?: Database.Database;
|
|
26
|
+
rows?: T[];
|
|
23
27
|
rowActions?: TableRowAction[];
|
|
24
28
|
onSelectionChanged?: (selection: string[]) => void;
|
|
25
29
|
onRowAction?: (actionId: string, data: T) => void;
|
|
26
30
|
} & Pick<
|
|
27
31
|
TableModelProps<T>,
|
|
28
|
-
'features' | 'onInsertRow' | 'onDeleteRows' | '
|
|
32
|
+
'features' | 'onInsertRow' | 'onDeleteRows' | 'onColumnDelete' | 'onCellUpdate' | 'onRowOrderChange'
|
|
29
33
|
>;
|
|
30
34
|
|
|
31
35
|
export const useTableModel = <T extends TableRow = TableRow>({
|
|
32
|
-
|
|
33
|
-
schema,
|
|
36
|
+
object,
|
|
34
37
|
projection,
|
|
38
|
+
db,
|
|
35
39
|
rows,
|
|
36
40
|
rowActions,
|
|
37
41
|
features,
|
|
38
42
|
onSelectionChanged,
|
|
39
43
|
onRowAction,
|
|
40
44
|
...props
|
|
41
|
-
}:
|
|
42
|
-
const
|
|
43
|
-
const
|
|
45
|
+
}: UseTableModelProps<T>): TableModel<T> | undefined => {
|
|
46
|
+
const registry = useContext(RegistryContext);
|
|
47
|
+
const selected = useSelected(object && Obj.getDXN(object).toString(), 'multi');
|
|
48
|
+
const initialSelection = useMemo(() => selected, [object]);
|
|
44
49
|
|
|
45
50
|
const [model, setModel] = useState<TableModel<T>>();
|
|
46
51
|
useEffect(() => {
|
|
47
|
-
if (!
|
|
52
|
+
if (!object || !projection) {
|
|
48
53
|
return;
|
|
49
54
|
}
|
|
50
55
|
|
|
51
56
|
let model: TableModel<T> | undefined;
|
|
52
57
|
const t = setTimeout(async () => {
|
|
53
58
|
model = new TableModel<T>({
|
|
54
|
-
|
|
55
|
-
|
|
59
|
+
registry,
|
|
60
|
+
object,
|
|
56
61
|
projection,
|
|
62
|
+
db,
|
|
63
|
+
change: createEchoChangeCallback<T>(object),
|
|
57
64
|
features,
|
|
58
65
|
rowActions,
|
|
59
66
|
initialSelection,
|
|
@@ -68,18 +75,13 @@ export const useTableModel = <T extends TableRow = TableRow>({
|
|
|
68
75
|
clearTimeout(t);
|
|
69
76
|
void model?.close();
|
|
70
77
|
};
|
|
71
|
-
|
|
78
|
+
// TODO(burdon): Trigger if callbacks change?
|
|
79
|
+
}, [registry, object, projection, features, rowActions, initialSelection]);
|
|
72
80
|
|
|
73
|
-
// Update data.
|
|
81
|
+
// Update data when rows change.
|
|
74
82
|
useEffect(() => {
|
|
75
|
-
if (rows) {
|
|
76
|
-
|
|
77
|
-
/*
|
|
78
|
-
* Sort all objects by string id field as a temporary workaround for query ordering issues
|
|
79
|
-
* Reference: https://github.com/dxos/dxos/pull/9409
|
|
80
|
-
*/
|
|
81
|
-
const sortedRows = orderBy(rows, [(row) => String(row.id)], ['asc']);
|
|
82
|
-
model?.setRows(sortedRows);
|
|
83
|
+
if (rows && model) {
|
|
84
|
+
model.setRows(rows);
|
|
83
85
|
}
|
|
84
86
|
}, [model, rows]);
|
|
85
87
|
|
|
@@ -90,8 +92,8 @@ export const useTableModel = <T extends TableRow = TableRow>({
|
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
94
|
|
|
93
|
-
const unsubscribe =
|
|
94
|
-
const selectedItems = [...model.selection.selection
|
|
95
|
+
const unsubscribe = registry.subscribe(model.selection.selectionAtom, () => {
|
|
96
|
+
const selectedItems = [...model.selection.selection];
|
|
95
97
|
multiSelect(selectedItems);
|
|
96
98
|
onSelectionChanged?.(selectedItems);
|
|
97
99
|
});
|
|
@@ -101,7 +103,7 @@ export const useTableModel = <T extends TableRow = TableRow>({
|
|
|
101
103
|
clear();
|
|
102
104
|
unsubscribe();
|
|
103
105
|
};
|
|
104
|
-
}, [model, onSelectionChanged]);
|
|
106
|
+
}, [registry, model, onSelectionChanged]);
|
|
105
107
|
|
|
106
108
|
return model;
|
|
107
109
|
};
|