@dxos/react-ui-table 0.8.4-main.5ea62a8 → 0.8.4-main.66e292d
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 +71 -0
- package/dist/lib/browser/chunk-5XWSB3JP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-RQYXNWWN.mjs → chunk-KNC7XYT6.mjs} +529 -568
- package/dist/lib/browser/chunk-KNC7XYT6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +187 -322
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +15 -25
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +3 -3
- package/dist/lib/node-esm/{chunk-QNDUGIS7.mjs → chunk-CWSGS3Y2.mjs} +529 -568
- package/dist/lib/node-esm/chunk-CWSGS3Y2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs +72 -0
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +187 -322
- 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 +15 -25
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +3 -3
- package/dist/types/src/components/Table/DynamicTable.d.ts +2 -2
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +5 -5
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +73 -9
- 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 +5 -2
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +72 -10
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +7 -5
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -3
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +3 -4
- 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/TableToolbar/TableToolbar.d.ts +2 -2
- package/dist/types/src/components/TableToolbar/TableToolbar.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +3 -5
- 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 +1 -1
- package/dist/types/src/hooks/useAddRow.d.ts.map +1 -1
- package/dist/types/src/hooks/useProjectionModel.d.ts +5 -0
- package/dist/types/src/hooks/useProjectionModel.d.ts.map +1 -0
- package/dist/types/src/hooks/useTableModel.d.ts +4 -5
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts +0 -7
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +8 -10
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +8 -5
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/playwright/TableManager.d.ts +1 -1
- package/dist/types/src/playwright/TableManager.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +21 -29
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/types/Table.d.ts +28 -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 +9 -9
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/schema.d.ts +1 -1
- package/dist/types/src/util/schema.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +53 -52
- package/src/components/Table/DynamicTable.stories.tsx +14 -13
- package/src/components/Table/DynamicTable.tsx +15 -10
- package/src/components/Table/Relations.stories.tsx +133 -29
- package/src/components/Table/RowActionsMenu.tsx +21 -13
- package/src/components/Table/Table.stories.tsx +85 -79
- package/src/components/Table/Table.tsx +13 -9
- package/src/components/TableCellEditor/FormCellEditor.tsx +51 -41
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +21 -47
- package/src/components/TableCellEditor/TableCellEditor.tsx +20 -115
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/TableToolbar/TableToolbar.tsx +32 -22
- package/src/components/testing.ts +4 -4
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useAddRow.ts +1 -1
- package/src/hooks/useProjectionModel.ts +19 -0
- package/src/hooks/useTableModel.ts +11 -13
- package/src/model/modal-controller.ts +0 -28
- package/src/model/table-model.test.ts +19 -9
- package/src/model/table-model.ts +42 -41
- package/src/model/table-presentation.test.ts +22 -20
- package/src/model/table-presentation.ts +12 -13
- package/src/model/table-sorting.ts +31 -13
- package/src/playwright/TableManager.ts +3 -3
- package/src/playwright/smoke.spec.ts +8 -6
- package/src/testing/useTestTableModel.ts +33 -22
- package/src/translations.ts +2 -2
- package/src/types/Table.ts +89 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.ts +17 -21
- package/src/util/schema.ts +4 -4
- package/dist/lib/browser/chunk-63UUF4IG.mjs +0 -66
- package/dist/lib/browser/chunk-63UUF4IG.mjs.map +0 -7
- package/dist/lib/browser/chunk-RQYXNWWN.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-QNDUGIS7.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/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/types/schema.ts +0 -73
|
@@ -15,9 +15,10 @@ import {
|
|
|
15
15
|
tableControls,
|
|
16
16
|
touch,
|
|
17
17
|
useAddRow,
|
|
18
|
+
useProjectionModel,
|
|
18
19
|
useTableModel
|
|
19
|
-
} from "./chunk-
|
|
20
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-CWSGS3Y2.mjs";
|
|
21
|
+
import "./chunk-MKTMOY46.mjs";
|
|
21
22
|
|
|
22
23
|
// src/translations.ts
|
|
23
24
|
var translationKey = "react-ui-table";
|
|
@@ -29,8 +30,8 @@ var translations = [
|
|
|
29
30
|
"create object label": "Create table",
|
|
30
31
|
"table name placeholder": "Table name",
|
|
31
32
|
"settings title": "Table settings",
|
|
32
|
-
"table schema label": "
|
|
33
|
-
"new schema": "New
|
|
33
|
+
"table schema label": "Type",
|
|
34
|
+
"new schema": "New type",
|
|
34
35
|
"continue label": "Continue",
|
|
35
36
|
"create stack section label": "Create table",
|
|
36
37
|
"add row label": "Add row",
|
|
@@ -52,8 +53,9 @@ var translations = [
|
|
|
52
53
|
];
|
|
53
54
|
|
|
54
55
|
// src/components/Table/Table.tsx
|
|
55
|
-
import { useSignals as
|
|
56
|
-
import
|
|
56
|
+
import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
|
|
57
|
+
import * as String2 from "effect/String";
|
|
58
|
+
import React7, { forwardRef, useCallback as useCallback4, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo4, useState as useState4 } from "react";
|
|
57
59
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
58
60
|
import { Grid, closestCell, gridSeparatorBlockEnd, gridSeparatorInlineEnd } from "@dxos/react-ui-grid";
|
|
59
61
|
import { DxEditRequest } from "@dxos/react-ui-grid";
|
|
@@ -64,12 +66,9 @@ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking"
|
|
|
64
66
|
import { EditorView } from "@codemirror/view";
|
|
65
67
|
import React3, { useCallback as useCallback2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
66
68
|
import { debounce } from "@dxos/async";
|
|
67
|
-
import {
|
|
69
|
+
import { Format as Format2, TypeEnum } from "@dxos/echo/internal";
|
|
68
70
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
69
|
-
import { useThemeContext } from "@dxos/react-ui";
|
|
70
|
-
import { createMarkdownExtensions } from "@dxos/react-ui-editor";
|
|
71
71
|
import { GridCellEditor, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3 } from "@dxos/react-ui-grid";
|
|
72
|
-
import { createLinks, tagPicker } from "@dxos/react-ui-tag-picker";
|
|
73
72
|
|
|
74
73
|
// src/components/TableCellEditor/CellValidationMessage.tsx
|
|
75
74
|
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
@@ -104,16 +103,17 @@ var CellValidationMessage = ({ validationError, variant = "error", __gridScope }
|
|
|
104
103
|
|
|
105
104
|
// src/components/TableCellEditor/FormCellEditor.tsx
|
|
106
105
|
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
106
|
+
import * as Schema from "effect/Schema";
|
|
107
107
|
import React2, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
108
108
|
import { Filter, Obj } from "@dxos/echo";
|
|
109
|
-
import { Ref, getValue } from "@dxos/echo
|
|
109
|
+
import { Format, Ref, getValue } from "@dxos/echo/internal";
|
|
110
110
|
import { invariant } from "@dxos/invariant";
|
|
111
111
|
import { getSnapshot } from "@dxos/live-object";
|
|
112
112
|
import { getSpace } from "@dxos/react-client/echo";
|
|
113
113
|
import { Popover } from "@dxos/react-ui";
|
|
114
114
|
import { Form } from "@dxos/react-ui-form";
|
|
115
|
-
import {
|
|
116
|
-
import { getDeep,
|
|
115
|
+
import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
|
|
116
|
+
import { getDeep, isTruthy, setDeep } from "@dxos/util";
|
|
117
117
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
|
|
118
118
|
var createOptionLabel = [
|
|
119
119
|
"create new object label",
|
|
@@ -121,7 +121,7 @@ var createOptionLabel = [
|
|
|
121
121
|
ns: translationKey
|
|
122
122
|
}
|
|
123
123
|
];
|
|
124
|
-
var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals, __gridScope, ...formProps }) => {
|
|
124
|
+
var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals, onCreate, __gridScope, ...formProps }) => {
|
|
125
125
|
var _effect = _useSignals2();
|
|
126
126
|
try {
|
|
127
127
|
const { editing: contextEditing, setEditing, id: gridId } = useGridContext2("ArrayEditor", __gridScope);
|
|
@@ -131,7 +131,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
131
131
|
const space = getSpace(model.view);
|
|
132
132
|
invariant(space, void 0, {
|
|
133
133
|
F: __dxlog_file,
|
|
134
|
-
L:
|
|
134
|
+
L: 57,
|
|
135
135
|
S: void 0,
|
|
136
136
|
A: [
|
|
137
137
|
"space",
|
|
@@ -162,7 +162,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
162
162
|
dxn: Obj.getDXN(obj),
|
|
163
163
|
label: getValue(obj, fieldProjection.field.referencePath) || obj.id.toString()
|
|
164
164
|
};
|
|
165
|
-
}).filter(
|
|
165
|
+
}).filter(isTruthy);
|
|
166
166
|
}
|
|
167
167
|
return [];
|
|
168
168
|
}, [
|
|
@@ -176,7 +176,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
176
176
|
const draftRow = model.draftRows.value[cell.row];
|
|
177
177
|
invariant(draftRow, void 0, {
|
|
178
178
|
F: __dxlog_file,
|
|
179
|
-
L:
|
|
179
|
+
L: 98,
|
|
180
180
|
S: void 0,
|
|
181
181
|
A: [
|
|
182
182
|
"draftRow",
|
|
@@ -188,7 +188,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
188
188
|
const row = model.getRowAt(cell.row);
|
|
189
189
|
invariant(row, void 0, {
|
|
190
190
|
F: __dxlog_file,
|
|
191
|
-
L:
|
|
191
|
+
L: 102,
|
|
192
192
|
S: void 0,
|
|
193
193
|
A: [
|
|
194
194
|
"row",
|
|
@@ -221,38 +221,6 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
221
221
|
contextEditing,
|
|
222
222
|
originalRow
|
|
223
223
|
]);
|
|
224
|
-
const handleCreate = useCallback((object) => {
|
|
225
|
-
const ref = Ref.make(object);
|
|
226
|
-
const path = fieldProjection.field.path;
|
|
227
|
-
setDeep(originalRow, [
|
|
228
|
-
path
|
|
229
|
-
], ref);
|
|
230
|
-
contextEditing?.cellElement?.focus();
|
|
231
|
-
setEditing(null);
|
|
232
|
-
setLocalEditing(false);
|
|
233
|
-
onSave?.();
|
|
234
|
-
}, [
|
|
235
|
-
fieldProjection.field.path,
|
|
236
|
-
onSave,
|
|
237
|
-
contextEditing,
|
|
238
|
-
originalRow
|
|
239
|
-
]);
|
|
240
|
-
const handleCreateFromQuery = useCallback(async (typeAnnotation, query) => {
|
|
241
|
-
if (model && modals && contextEditing?.index) {
|
|
242
|
-
setLocalEditing(false);
|
|
243
|
-
modals.openCreateRef(typeAnnotation.typename, document.querySelector(cellQuery(contextEditing.index, gridId)), {
|
|
244
|
-
[fieldProjection.field.referencePath]: query
|
|
245
|
-
}, handleCreate);
|
|
246
|
-
}
|
|
247
|
-
}, [
|
|
248
|
-
model,
|
|
249
|
-
modals,
|
|
250
|
-
client,
|
|
251
|
-
contextEditing?.index,
|
|
252
|
-
gridId,
|
|
253
|
-
fieldProjection,
|
|
254
|
-
handleSave
|
|
255
|
-
]);
|
|
256
224
|
useEffect(() => {
|
|
257
225
|
if (contextEditing && contextEditing.cellElement) {
|
|
258
226
|
anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
|
|
@@ -285,6 +253,47 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
285
253
|
}
|
|
286
254
|
setLocalEditing(nextOpen);
|
|
287
255
|
}, []);
|
|
256
|
+
const refSchema = useMemo(() => {
|
|
257
|
+
if (fieldProjection.props.format === Format.TypeFormat.Ref && fieldProjection.props.referenceSchema) {
|
|
258
|
+
const { schema: refSchema2 } = getSchema({
|
|
259
|
+
typename: fieldProjection.props.referenceSchema
|
|
260
|
+
});
|
|
261
|
+
return refSchema2;
|
|
262
|
+
}
|
|
263
|
+
return null;
|
|
264
|
+
}, [
|
|
265
|
+
fieldProjection.props.format,
|
|
266
|
+
fieldProjection.props.referenceSchema,
|
|
267
|
+
getSchema
|
|
268
|
+
]);
|
|
269
|
+
const createSchema = useMemo(() => {
|
|
270
|
+
return refSchema ? Schema.omit("id")(refSchema) : null;
|
|
271
|
+
}, [
|
|
272
|
+
refSchema
|
|
273
|
+
]);
|
|
274
|
+
const handleCreate = useCallback((values) => {
|
|
275
|
+
if (refSchema && onCreate) {
|
|
276
|
+
const objectWithId = onCreate(refSchema, values);
|
|
277
|
+
if (objectWithId) {
|
|
278
|
+
const ref = Ref.make(objectWithId);
|
|
279
|
+
const path = fieldProjection.field.path;
|
|
280
|
+
setDeep(originalRow, [
|
|
281
|
+
path
|
|
282
|
+
], ref);
|
|
283
|
+
}
|
|
284
|
+
}
|
|
285
|
+
contextEditing?.cellElement?.focus();
|
|
286
|
+
setEditing(null);
|
|
287
|
+
setLocalEditing(false);
|
|
288
|
+
onSave?.();
|
|
289
|
+
}, [
|
|
290
|
+
fieldProjection.field.path,
|
|
291
|
+
onSave,
|
|
292
|
+
contextEditing,
|
|
293
|
+
originalRow,
|
|
294
|
+
refSchema,
|
|
295
|
+
onCreate
|
|
296
|
+
]);
|
|
288
297
|
if (!editing) {
|
|
289
298
|
return null;
|
|
290
299
|
}
|
|
@@ -303,9 +312,13 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
303
312
|
onSave: handleSave,
|
|
304
313
|
...formProps,
|
|
305
314
|
onQueryRefOptions: handleQueryRefOptions,
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
315
|
+
...createSchema && {
|
|
316
|
+
onCreate: handleCreate,
|
|
317
|
+
createSchema,
|
|
318
|
+
createInitialValuePath: fieldProjection.field.referencePath,
|
|
319
|
+
createOptionIcon: "ph--plus--regular",
|
|
320
|
+
createOptionLabel
|
|
321
|
+
}
|
|
309
322
|
})))));
|
|
310
323
|
} finally {
|
|
311
324
|
_effect.f();
|
|
@@ -315,7 +328,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
315
328
|
// src/components/TableCellEditor/TableCellEditor.tsx
|
|
316
329
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
|
|
317
330
|
var adaptValidationMessage = (message) => message ? message.endsWith("is missing") ? "Can\u2019t be blank" : message : null;
|
|
318
|
-
var TableValueEditor = ({ model, modals, schema, onFocus, onSave, client, __gridScope }) => {
|
|
331
|
+
var TableValueEditor = ({ model, modals, schema, onFocus, onSave, onCreate, client, __gridScope }) => {
|
|
319
332
|
var _effect = _useSignals3();
|
|
320
333
|
try {
|
|
321
334
|
const { editing } = useGridContext3("TableValueEditor", __gridScope);
|
|
@@ -328,7 +341,7 @@ var TableValueEditor = ({ model, modals, schema, onFocus, onSave, client, __grid
|
|
|
328
341
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
329
342
|
invariant2(fieldProjection2, void 0, {
|
|
330
343
|
F: __dxlog_file2,
|
|
331
|
-
L:
|
|
344
|
+
L: 71,
|
|
332
345
|
S: void 0,
|
|
333
346
|
A: [
|
|
334
347
|
"fieldProjection",
|
|
@@ -340,13 +353,14 @@ var TableValueEditor = ({ model, modals, schema, onFocus, onSave, client, __grid
|
|
|
340
353
|
model,
|
|
341
354
|
editing
|
|
342
355
|
]);
|
|
343
|
-
if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format ===
|
|
356
|
+
if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === Format2.TypeFormat.SingleSelect || fieldProjection?.props.format === Format2.TypeFormat.Ref) {
|
|
344
357
|
return /* @__PURE__ */ React3.createElement(FormCellEditor, {
|
|
345
358
|
fieldProjection,
|
|
346
359
|
model,
|
|
347
360
|
schema,
|
|
348
361
|
__gridScope,
|
|
349
362
|
onSave,
|
|
363
|
+
onCreate,
|
|
350
364
|
client,
|
|
351
365
|
modals
|
|
352
366
|
});
|
|
@@ -363,16 +377,15 @@ var TableValueEditor = ({ model, modals, schema, onFocus, onSave, client, __grid
|
|
|
363
377
|
}
|
|
364
378
|
};
|
|
365
379
|
var editorSlots = {
|
|
366
|
-
|
|
380
|
+
scroll: {
|
|
367
381
|
className: "!plb-[--dx-grid-cell-editor-padding-block]"
|
|
368
382
|
}
|
|
369
383
|
};
|
|
370
384
|
var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
371
385
|
var _effect = _useSignals3();
|
|
372
386
|
try {
|
|
373
|
-
const {
|
|
387
|
+
const { editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
|
|
374
388
|
const suppressNextBlur = useRef2(false);
|
|
375
|
-
const { themeMode } = useThemeContext();
|
|
376
389
|
const [validationError, setValidationError] = useState2(null);
|
|
377
390
|
const [validationVariant, setValidationVariant] = useState2("error");
|
|
378
391
|
const fieldProjection = useMemo2(() => {
|
|
@@ -384,7 +397,7 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
384
397
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
385
398
|
invariant2(fieldProjection2, void 0, {
|
|
386
399
|
F: __dxlog_file2,
|
|
387
|
-
L:
|
|
400
|
+
L: 121,
|
|
388
401
|
S: void 0,
|
|
389
402
|
A: [
|
|
390
403
|
"fieldProjection",
|
|
@@ -474,11 +487,11 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
474
487
|
setEditing,
|
|
475
488
|
onSave
|
|
476
489
|
]);
|
|
477
|
-
const
|
|
490
|
+
const extensions = useMemo2(() => {
|
|
478
491
|
if (!fieldProjection) {
|
|
479
492
|
return [];
|
|
480
493
|
}
|
|
481
|
-
const
|
|
494
|
+
const extensions2 = [
|
|
482
495
|
editorKeys({
|
|
483
496
|
onClose: handleClose,
|
|
484
497
|
...editing?.initialContent && {
|
|
@@ -486,39 +499,8 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
486
499
|
}
|
|
487
500
|
})
|
|
488
501
|
];
|
|
489
|
-
const format = fieldProjection.props.format;
|
|
490
|
-
if (format === FormatEnum.SingleSelect || format === FormatEnum.MultiSelect) {
|
|
491
|
-
extension2.push(createMarkdownExtensions({
|
|
492
|
-
themeMode
|
|
493
|
-
}));
|
|
494
|
-
const options = fieldProjection.props.options || [];
|
|
495
|
-
const mode = format === FormatEnum.SingleSelect ? "single-select" : "multi-select";
|
|
496
|
-
extension2.push(tagPicker({
|
|
497
|
-
mode,
|
|
498
|
-
keymap: false,
|
|
499
|
-
onSearch: (text, selectedIds) => {
|
|
500
|
-
return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
|
|
501
|
-
id: option.id,
|
|
502
|
-
label: option.title,
|
|
503
|
-
hue: option.color
|
|
504
|
-
}));
|
|
505
|
-
},
|
|
506
|
-
onUpdate: (ids) => {
|
|
507
|
-
if (model && editing) {
|
|
508
|
-
if (ids.length === 0) {
|
|
509
|
-
return;
|
|
510
|
-
}
|
|
511
|
-
if (mode === "single-select") {
|
|
512
|
-
void handleEnter(ids[0]);
|
|
513
|
-
} else {
|
|
514
|
-
void handleEnter(ids);
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}));
|
|
519
|
-
}
|
|
520
502
|
if (model && editing) {
|
|
521
|
-
|
|
503
|
+
extensions2.push(EditorView.updateListener.of(debounce((update) => {
|
|
522
504
|
const content = update.state.doc.toString();
|
|
523
505
|
const cell = parseCellIndex2(editing.index);
|
|
524
506
|
void model.validateCellData(cell, content).then((result) => {
|
|
@@ -531,54 +513,17 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
531
513
|
});
|
|
532
514
|
}, 10)));
|
|
533
515
|
}
|
|
534
|
-
return
|
|
516
|
+
return extensions2;
|
|
535
517
|
}, [
|
|
536
518
|
model,
|
|
537
519
|
modals,
|
|
538
520
|
editing,
|
|
539
521
|
fieldProjection,
|
|
540
|
-
handleClose
|
|
541
|
-
themeMode
|
|
522
|
+
handleClose
|
|
542
523
|
]);
|
|
543
524
|
const getCellContent = useCallback2(() => {
|
|
544
525
|
if (model && editing) {
|
|
545
526
|
const cell = parseCellIndex2(editing.index);
|
|
546
|
-
const { col } = cell;
|
|
547
|
-
const field = model.projection.fields[col];
|
|
548
|
-
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
549
|
-
if (fieldProjection2?.props.format === FormatEnum.SingleSelect || fieldProjection2?.props.format === FormatEnum.MultiSelect) {
|
|
550
|
-
const value2 = model.getCellData(cell);
|
|
551
|
-
if (value2 !== void 0) {
|
|
552
|
-
const options = fieldProjection2.props.options || [];
|
|
553
|
-
if (fieldProjection2.props.format === FormatEnum.MultiSelect) {
|
|
554
|
-
const tagItems = value2.split(",").map((id) => {
|
|
555
|
-
const option = options.find((o) => o.id === id);
|
|
556
|
-
if (option) {
|
|
557
|
-
return {
|
|
558
|
-
id,
|
|
559
|
-
label: option.title,
|
|
560
|
-
hue: option.color
|
|
561
|
-
};
|
|
562
|
-
}
|
|
563
|
-
return void 0;
|
|
564
|
-
}).filter((item) => item !== void 0);
|
|
565
|
-
return createLinks(tagItems);
|
|
566
|
-
} else {
|
|
567
|
-
const option = options.find((o) => o.id === value2);
|
|
568
|
-
if (option) {
|
|
569
|
-
const tagItem = {
|
|
570
|
-
id: value2,
|
|
571
|
-
label: option.title,
|
|
572
|
-
hue: option.color
|
|
573
|
-
};
|
|
574
|
-
return createLinks([
|
|
575
|
-
tagItem
|
|
576
|
-
]);
|
|
577
|
-
}
|
|
578
|
-
}
|
|
579
|
-
}
|
|
580
|
-
return "";
|
|
581
|
-
}
|
|
582
527
|
const value = model.getCellData(cell);
|
|
583
528
|
return value !== void 0 ? String(value) : "";
|
|
584
529
|
}
|
|
@@ -591,7 +536,7 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
591
536
|
variant: validationVariant,
|
|
592
537
|
__gridScope
|
|
593
538
|
}), /* @__PURE__ */ React3.createElement(GridCellEditor, {
|
|
594
|
-
|
|
539
|
+
extensions,
|
|
595
540
|
getCellContent,
|
|
596
541
|
onBlur: handleBlur,
|
|
597
542
|
slots: editorSlots
|
|
@@ -738,106 +683,12 @@ var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
|
|
|
738
683
|
}
|
|
739
684
|
};
|
|
740
685
|
|
|
741
|
-
// src/components/Table/CreateRefPanel.tsx
|
|
742
|
-
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
743
|
-
import { Schema } from "effect";
|
|
744
|
-
import React6, { useCallback as useCallback4, useMemo as useMemo4 } from "react";
|
|
745
|
-
import { Type } from "@dxos/echo";
|
|
746
|
-
import { live } from "@dxos/live-object";
|
|
747
|
-
import { useClient } from "@dxos/react-client";
|
|
748
|
-
import { getSpace as getSpace2 } from "@dxos/react-client/echo";
|
|
749
|
-
import { Popover as Popover3 } from "@dxos/react-ui";
|
|
750
|
-
import { Form as Form2 } from "@dxos/react-ui-form";
|
|
751
|
-
import { useGridContext as useGridContext4 } from "@dxos/react-ui-grid";
|
|
752
|
-
var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
753
|
-
var _effect = _useSignals6();
|
|
754
|
-
try {
|
|
755
|
-
const { id: gridId } = useGridContext4("TableCellEditor", __gridScope);
|
|
756
|
-
const client = useClient();
|
|
757
|
-
const space = model && getSpace2(model?.view);
|
|
758
|
-
const state = modals.state.value;
|
|
759
|
-
const getSchema = useCallback4(() => {
|
|
760
|
-
if (!space || state?.type !== "createRefPanel") {
|
|
761
|
-
return;
|
|
762
|
-
}
|
|
763
|
-
const staticSchema = client.graph.schemaRegistry.schemas.find((schema3) => Type.getTypename(schema3) === state.typename);
|
|
764
|
-
if (staticSchema) {
|
|
765
|
-
return staticSchema;
|
|
766
|
-
}
|
|
767
|
-
const [schema2] = space.db.schemaRegistry.query({
|
|
768
|
-
typename: state.typename
|
|
769
|
-
}).runSync();
|
|
770
|
-
return schema2;
|
|
771
|
-
}, [
|
|
772
|
-
space,
|
|
773
|
-
state
|
|
774
|
-
]);
|
|
775
|
-
const schema = useMemo4(() => {
|
|
776
|
-
const schema2 = getSchema();
|
|
777
|
-
if (!schema2) {
|
|
778
|
-
return;
|
|
779
|
-
}
|
|
780
|
-
const omit = Schema.omit("id");
|
|
781
|
-
return omit(schema2);
|
|
782
|
-
}, [
|
|
783
|
-
getSchema
|
|
784
|
-
]);
|
|
785
|
-
const handleSave = useCallback4((values) => {
|
|
786
|
-
if (!model || !space || state?.type !== "createRefPanel") {
|
|
787
|
-
return;
|
|
788
|
-
}
|
|
789
|
-
const schema2 = getSchema();
|
|
790
|
-
if (schema2) {
|
|
791
|
-
const obj = space.db.add(live(schema2, values));
|
|
792
|
-
state.onCreate?.(obj);
|
|
793
|
-
}
|
|
794
|
-
void modals.close();
|
|
795
|
-
}, [
|
|
796
|
-
model,
|
|
797
|
-
modals,
|
|
798
|
-
space,
|
|
799
|
-
state
|
|
800
|
-
]);
|
|
801
|
-
const handleCancel = useCallback4(() => {
|
|
802
|
-
if (model) {
|
|
803
|
-
modals.close();
|
|
804
|
-
}
|
|
805
|
-
}, [
|
|
806
|
-
modals
|
|
807
|
-
]);
|
|
808
|
-
if (!model?.projection) {
|
|
809
|
-
return null;
|
|
810
|
-
}
|
|
811
|
-
return /* @__PURE__ */ React6.createElement(Popover3.Root, {
|
|
812
|
-
modal: false,
|
|
813
|
-
open: state?.type === "createRefPanel" && !!schema,
|
|
814
|
-
onOpenChange: (nextOpen) => {
|
|
815
|
-
if (model && !nextOpen) {
|
|
816
|
-
return modals.close();
|
|
817
|
-
}
|
|
818
|
-
}
|
|
819
|
-
}, /* @__PURE__ */ React6.createElement(Popover3.VirtualTrigger, {
|
|
820
|
-
virtualRef: modals.trigger
|
|
821
|
-
}), /* @__PURE__ */ React6.createElement(Popover3.Portal, null, /* @__PURE__ */ React6.createElement(Popover3.Content, {
|
|
822
|
-
classNames: "md:is-64",
|
|
823
|
-
"data-grid": gridId
|
|
824
|
-
}, /* @__PURE__ */ React6.createElement(Popover3.Viewport, null, state?.type === "createRefPanel" && schema && /* @__PURE__ */ React6.createElement(Form2, {
|
|
825
|
-
schema,
|
|
826
|
-
values: state.initialValues ?? {},
|
|
827
|
-
onSave: handleSave,
|
|
828
|
-
onCancel: handleCancel
|
|
829
|
-
})), /* @__PURE__ */ React6.createElement(Popover3.Arrow, null))));
|
|
830
|
-
} finally {
|
|
831
|
-
_effect.f();
|
|
832
|
-
}
|
|
833
|
-
};
|
|
834
|
-
|
|
835
686
|
// src/components/Table/RowActionsMenu.tsx
|
|
836
|
-
import { useSignals as
|
|
837
|
-
import
|
|
687
|
+
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
688
|
+
import React6 from "react";
|
|
838
689
|
import { DropdownMenu as DropdownMenu2, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
839
690
|
var RowActionsMenu = ({ model, modals }) => {
|
|
840
|
-
var _effect =
|
|
691
|
+
var _effect = _useSignals6();
|
|
841
692
|
try {
|
|
842
693
|
const { t } = useTranslation2(translationKey);
|
|
843
694
|
const hasSelection = model.selection.hasSelection.value;
|
|
@@ -845,23 +696,23 @@ var RowActionsMenu = ({ model, modals }) => {
|
|
|
845
696
|
if (state?.type !== "row") {
|
|
846
697
|
return null;
|
|
847
698
|
}
|
|
848
|
-
return /* @__PURE__ */
|
|
699
|
+
return /* @__PURE__ */ React6.createElement(DropdownMenu2.Root, {
|
|
849
700
|
modal: false,
|
|
850
701
|
open: true,
|
|
851
702
|
onOpenChange: modals.close
|
|
852
|
-
}, /* @__PURE__ */
|
|
703
|
+
}, /* @__PURE__ */ React6.createElement(DropdownMenu2.VirtualTrigger, {
|
|
853
704
|
virtualRef: modals.trigger
|
|
854
|
-
}), /* @__PURE__ */
|
|
855
|
-
"data-testid": "row-menu-delete",
|
|
856
|
-
onClick: () => model.deleteRow(state.rowIndex)
|
|
857
|
-
}, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React7.createElement(DropdownMenu2.Item, {
|
|
705
|
+
}), /* @__PURE__ */ React6.createElement(DropdownMenu2.Content, null, /* @__PURE__ */ React6.createElement(DropdownMenu2.Viewport, null, model.rowActions?.length > 0 && /* @__PURE__ */ React6.createElement(React6.Fragment, null, /* @__PURE__ */ React6.createElement(DropdownMenu2.Group, null, model.rowActions?.map((action) => /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
|
|
858
706
|
key: action.id,
|
|
859
707
|
"data-testid": `row-action-${action.id}`,
|
|
860
708
|
onClick: () => {
|
|
861
709
|
modals.close();
|
|
862
710
|
model.handleRowAction(action.id, state.rowIndex);
|
|
863
711
|
}
|
|
864
|
-
}, toLocalizedString(action.label, t)))), /* @__PURE__ */
|
|
712
|
+
}, toLocalizedString(action.label, t)))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Separator, null)), model.features.dataEditable !== false && /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
|
|
713
|
+
"data-testid": "row-menu-delete",
|
|
714
|
+
onClick: () => model.deleteRow(state.rowIndex)
|
|
715
|
+
}, t(hasSelection ? "bulk delete row label" : "delete row label"))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Arrow, null)));
|
|
865
716
|
} finally {
|
|
866
717
|
_effect.f();
|
|
867
718
|
}
|
|
@@ -881,9 +732,9 @@ var rowDefault = {
|
|
|
881
732
|
}
|
|
882
733
|
};
|
|
883
734
|
var TableRoot = ({ children, role = "article" }) => {
|
|
884
|
-
var _effect =
|
|
735
|
+
var _effect = _useSignals7();
|
|
885
736
|
try {
|
|
886
|
-
return /* @__PURE__ */
|
|
737
|
+
return /* @__PURE__ */ React7.createElement("div", {
|
|
887
738
|
role: "none",
|
|
888
739
|
className: mx("relative !border-separator [&_.dx-grid]:max-is-[--dx-grid-content-inline-size] [&_.dx-grid]:max-bs-[--dx-grid-content-block-size]", role === "card--popover" && "popover-card-height", role === "section" && "attention-surface", role === "card--intrinsic" && "[&_.dx-grid]:bs-[--dx-grid-content-block-size]", [
|
|
889
740
|
"card--popover",
|
|
@@ -898,20 +749,20 @@ var TableRoot = ({ children, role = "article" }) => {
|
|
|
898
749
|
_effect.f();
|
|
899
750
|
}
|
|
900
751
|
};
|
|
901
|
-
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, client, onRowClick }, forwardedRef) => {
|
|
902
|
-
var _effect =
|
|
752
|
+
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, client, onCreate, onRowClick, testId }, forwardedRef) => {
|
|
753
|
+
var _effect = _useSignals7();
|
|
903
754
|
try {
|
|
904
755
|
const [dxGrid, setDxGrid] = useState4(null);
|
|
905
756
|
const { hasAttention } = useAttention(model?.id ?? "table");
|
|
906
|
-
const modals =
|
|
757
|
+
const modals = useMemo4(() => new ModalController(), []);
|
|
907
758
|
const draftRowCount = model?.getDraftRowCount() ?? 0;
|
|
908
|
-
const handleSave =
|
|
759
|
+
const handleSave = useCallback4(() => {
|
|
909
760
|
dxGrid?.updateCells(true);
|
|
910
761
|
dxGrid?.requestUpdate();
|
|
911
762
|
}, [
|
|
912
763
|
dxGrid
|
|
913
764
|
]);
|
|
914
|
-
const frozen =
|
|
765
|
+
const frozen = useMemo4(() => {
|
|
915
766
|
const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
|
|
916
767
|
return {
|
|
917
768
|
frozenRowsStart: 1,
|
|
@@ -923,7 +774,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
923
774
|
model,
|
|
924
775
|
draftRowCount
|
|
925
776
|
]);
|
|
926
|
-
const getCells =
|
|
777
|
+
const getCells = useCallback4((range, plane) => presentation?.getCells(range, plane) ?? {}, [
|
|
927
778
|
presentation
|
|
928
779
|
]);
|
|
929
780
|
useEffect3(() => {
|
|
@@ -936,7 +787,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
936
787
|
dxGrid,
|
|
937
788
|
getCells
|
|
938
789
|
]);
|
|
939
|
-
const handleInsertRowResult =
|
|
790
|
+
const handleInsertRowResult = useCallback4((insertResult) => {
|
|
940
791
|
if (insertResult === "draft") {
|
|
941
792
|
requestAnimationFrame(() => {
|
|
942
793
|
dxGrid?.setFocus({
|
|
@@ -980,7 +831,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
980
831
|
dxGrid,
|
|
981
832
|
model
|
|
982
833
|
]);
|
|
983
|
-
const handleSaveDraftRow =
|
|
834
|
+
const handleSaveDraftRow = useCallback4((rowIndex = 0) => {
|
|
984
835
|
if (model && dxGrid) {
|
|
985
836
|
const didCommitSuccessfully = model.commitDraftRow(rowIndex);
|
|
986
837
|
if (didCommitSuccessfully) {
|
|
@@ -993,7 +844,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
993
844
|
model,
|
|
994
845
|
dxGrid
|
|
995
846
|
]);
|
|
996
|
-
const handleGridClick =
|
|
847
|
+
const handleGridClick = useCallback4((event) => {
|
|
997
848
|
const cell = closestCell(event.target);
|
|
998
849
|
if (cell) {
|
|
999
850
|
const { row: rowIndex, plane } = cell;
|
|
@@ -1078,9 +929,9 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1078
929
|
modals,
|
|
1079
930
|
dxGrid
|
|
1080
931
|
]);
|
|
1081
|
-
const handleFocus =
|
|
932
|
+
const handleFocus = useCallback4((increment, delta, cell) => {
|
|
1082
933
|
if (dxGrid && model) {
|
|
1083
|
-
if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1) {
|
|
934
|
+
if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1 && increment !== "col") {
|
|
1084
935
|
handleInsertRowResult(draftRowCount < 1 ? model.insertRow() : "final");
|
|
1085
936
|
} else if (cell?.plane === "frozenRowsEnd" && increment === "row") {
|
|
1086
937
|
handleSaveDraftRow(cell.row);
|
|
@@ -1093,7 +944,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1093
944
|
dxGrid,
|
|
1094
945
|
model
|
|
1095
946
|
]);
|
|
1096
|
-
const handleKeyDown =
|
|
947
|
+
const handleKeyDown = useCallback4((event) => {
|
|
1097
948
|
if (!model?.features.dataEditable) {
|
|
1098
949
|
return;
|
|
1099
950
|
}
|
|
@@ -1118,7 +969,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1118
969
|
event.preventDefault();
|
|
1119
970
|
void navigator.clipboard.readText().then((clipboardText) => {
|
|
1120
971
|
try {
|
|
1121
|
-
model.setCellData(cell, clipboardText);
|
|
972
|
+
model.setCellData(cell, String2.trim(clipboardText).replace(/[\n\r]+/, " "));
|
|
1122
973
|
handleSave();
|
|
1123
974
|
} catch {
|
|
1124
975
|
const cellElement = event.target.closest('[data-dx-grid-action="cell"]');
|
|
@@ -1149,6 +1000,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1149
1000
|
try {
|
|
1150
1001
|
model.setCellData(cell, void 0);
|
|
1151
1002
|
event.preventDefault();
|
|
1003
|
+
handleSave();
|
|
1152
1004
|
} catch {
|
|
1153
1005
|
}
|
|
1154
1006
|
break;
|
|
@@ -1159,7 +1011,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1159
1011
|
dxGrid,
|
|
1160
1012
|
handleSave
|
|
1161
1013
|
]);
|
|
1162
|
-
const handleAxisResize =
|
|
1014
|
+
const handleAxisResize = useCallback4((event) => {
|
|
1163
1015
|
if (event.axis === "col") {
|
|
1164
1016
|
const columnIndex = parseInt(event.index, 10);
|
|
1165
1017
|
model?.setColumnWidth(columnIndex, event.size);
|
|
@@ -1167,7 +1019,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1167
1019
|
}, [
|
|
1168
1020
|
model
|
|
1169
1021
|
]);
|
|
1170
|
-
const handleWheel =
|
|
1022
|
+
const handleWheel = useCallback4((event) => {
|
|
1171
1023
|
if (!ignoreAttention && !hasAttention) {
|
|
1172
1024
|
event.stopPropagation();
|
|
1173
1025
|
}
|
|
@@ -1175,7 +1027,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1175
1027
|
hasAttention,
|
|
1176
1028
|
ignoreAttention
|
|
1177
1029
|
]);
|
|
1178
|
-
const handleNewColumn =
|
|
1030
|
+
const handleNewColumn = useCallback4(() => {
|
|
1179
1031
|
const columns = model?.getColumnCount();
|
|
1180
1032
|
if (dxGrid && columns) {
|
|
1181
1033
|
dxGrid.scrollToColumn(columns - 1);
|
|
@@ -1185,21 +1037,22 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1185
1037
|
dxGrid
|
|
1186
1038
|
]);
|
|
1187
1039
|
if (!model || !modals) {
|
|
1188
|
-
return /* @__PURE__ */
|
|
1040
|
+
return /* @__PURE__ */ React7.createElement("span", {
|
|
1189
1041
|
role: "none",
|
|
1190
1042
|
className: "attention-surface"
|
|
1191
1043
|
});
|
|
1192
1044
|
}
|
|
1193
|
-
return /* @__PURE__ */
|
|
1045
|
+
return /* @__PURE__ */ React7.createElement(Grid.Root, {
|
|
1194
1046
|
id: model.id ?? "table-grid"
|
|
1195
|
-
}, /* @__PURE__ */
|
|
1047
|
+
}, /* @__PURE__ */ React7.createElement(TableValueEditor, {
|
|
1196
1048
|
model,
|
|
1197
1049
|
modals,
|
|
1198
1050
|
schema,
|
|
1199
1051
|
onFocus: handleFocus,
|
|
1200
1052
|
onSave: handleSave,
|
|
1053
|
+
onCreate,
|
|
1201
1054
|
client
|
|
1202
|
-
}), /* @__PURE__ */
|
|
1055
|
+
}), /* @__PURE__ */ React7.createElement(Grid.Content, {
|
|
1203
1056
|
className: mx("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
|
|
1204
1057
|
frozen,
|
|
1205
1058
|
columns: model.columnMeta.value,
|
|
@@ -1212,20 +1065,20 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1212
1065
|
onClick: handleGridClick,
|
|
1213
1066
|
onKeyDownCapture: handleKeyDown,
|
|
1214
1067
|
onWheelCapture: handleWheel,
|
|
1068
|
+
...testId && {
|
|
1069
|
+
"data-testid": testId
|
|
1070
|
+
},
|
|
1215
1071
|
ref: setDxGrid
|
|
1216
|
-
}), /* @__PURE__ */
|
|
1072
|
+
}), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
|
|
1217
1073
|
model,
|
|
1218
1074
|
modals
|
|
1219
|
-
}), /* @__PURE__ */
|
|
1075
|
+
}), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
|
|
1220
1076
|
model,
|
|
1221
1077
|
modals
|
|
1222
|
-
}), /* @__PURE__ */
|
|
1078
|
+
}), /* @__PURE__ */ React7.createElement(ColumnSettings, {
|
|
1223
1079
|
model,
|
|
1224
1080
|
modals,
|
|
1225
1081
|
onNewColumn: handleNewColumn
|
|
1226
|
-
}), /* @__PURE__ */ React8.createElement(CreateRefPanel, {
|
|
1227
|
-
model,
|
|
1228
|
-
modals
|
|
1229
1082
|
}));
|
|
1230
1083
|
} finally {
|
|
1231
1084
|
_effect.f();
|
|
@@ -1237,14 +1090,15 @@ var Table = {
|
|
|
1237
1090
|
};
|
|
1238
1091
|
|
|
1239
1092
|
// src/components/Table/DynamicTable.tsx
|
|
1240
|
-
import { useSignals as
|
|
1241
|
-
import
|
|
1093
|
+
import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
|
|
1094
|
+
import React8, { useCallback as useCallback5, useMemo as useMemo5, useRef as useRef3 } from "react";
|
|
1242
1095
|
import { useDefaultValue } from "@dxos/react-ui";
|
|
1243
1096
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
1097
|
+
import { ProjectionModel } from "@dxos/schema";
|
|
1244
1098
|
var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema: _jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
|
|
1245
|
-
var _effect =
|
|
1099
|
+
var _effect = _useSignals8();
|
|
1246
1100
|
try {
|
|
1247
|
-
const {
|
|
1101
|
+
const { jsonSchema } = useMemo5(() => getBaseSchema({
|
|
1248
1102
|
typename: name,
|
|
1249
1103
|
properties,
|
|
1250
1104
|
jsonSchema: _jsonSchema,
|
|
@@ -1255,20 +1109,18 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
1255
1109
|
_jsonSchema,
|
|
1256
1110
|
schema
|
|
1257
1111
|
]);
|
|
1258
|
-
const {
|
|
1259
|
-
typename,
|
|
1112
|
+
const { object, projection } = useMemo5(() => makeDynamicTable({
|
|
1260
1113
|
jsonSchema,
|
|
1261
1114
|
properties
|
|
1262
1115
|
}), [
|
|
1263
|
-
typename,
|
|
1264
1116
|
jsonSchema,
|
|
1265
1117
|
properties
|
|
1266
1118
|
]);
|
|
1267
1119
|
const tableRef = useRef3(null);
|
|
1268
|
-
const handleCellUpdate =
|
|
1120
|
+
const handleCellUpdate = useCallback5((cell) => {
|
|
1269
1121
|
tableRef.current?.update?.(cell);
|
|
1270
1122
|
}, []);
|
|
1271
|
-
const handleRowOrderChange =
|
|
1123
|
+
const handleRowOrderChange = useCallback5(() => {
|
|
1272
1124
|
tableRef.current?.update?.();
|
|
1273
1125
|
}, []);
|
|
1274
1126
|
const features = useDefaultValue(props.features, () => ({
|
|
@@ -1277,31 +1129,40 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
1277
1129
|
},
|
|
1278
1130
|
dataEditable: false
|
|
1279
1131
|
}));
|
|
1132
|
+
const projectionModel = useMemo5(() => {
|
|
1133
|
+
if (jsonSchema && projection) {
|
|
1134
|
+
const model2 = new ProjectionModel(jsonSchema, projection);
|
|
1135
|
+
model2.normalizeView();
|
|
1136
|
+
return model2;
|
|
1137
|
+
}
|
|
1138
|
+
}, [
|
|
1139
|
+
jsonSchema,
|
|
1140
|
+
projection
|
|
1141
|
+
]);
|
|
1280
1142
|
const model = useTableModel({
|
|
1281
1143
|
rows,
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
projection,
|
|
1144
|
+
object,
|
|
1145
|
+
projection: projectionModel,
|
|
1285
1146
|
features,
|
|
1286
1147
|
rowActions,
|
|
1287
1148
|
onCellUpdate: handleCellUpdate,
|
|
1288
1149
|
onRowOrderChange: handleRowOrderChange,
|
|
1289
1150
|
onRowAction
|
|
1290
1151
|
});
|
|
1291
|
-
const presentation =
|
|
1152
|
+
const presentation = useMemo5(() => {
|
|
1292
1153
|
if (model) {
|
|
1293
1154
|
return new TablePresentation(model);
|
|
1294
1155
|
}
|
|
1295
1156
|
}, [
|
|
1296
1157
|
model
|
|
1297
1158
|
]);
|
|
1298
|
-
return /* @__PURE__ */
|
|
1159
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
1299
1160
|
role: "none",
|
|
1300
1161
|
className: mx2("is-full bs-full grow grid", classNames)
|
|
1301
|
-
}, /* @__PURE__ */
|
|
1162
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
1302
1163
|
role: "none",
|
|
1303
1164
|
className: "grid min-bs-0 overflow-hidden"
|
|
1304
|
-
}, /* @__PURE__ */
|
|
1165
|
+
}, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
|
|
1305
1166
|
ref: tableRef,
|
|
1306
1167
|
model,
|
|
1307
1168
|
presentation,
|
|
@@ -1314,43 +1175,46 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
1314
1175
|
};
|
|
1315
1176
|
|
|
1316
1177
|
// src/components/TableToolbar/TableToolbar.tsx
|
|
1317
|
-
import { useSignals as
|
|
1318
|
-
import {
|
|
1319
|
-
import
|
|
1320
|
-
import { live
|
|
1178
|
+
import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
|
|
1179
|
+
import { Atom } from "@effect-atom/atom-react";
|
|
1180
|
+
import React9, { useMemo as useMemo6 } from "react";
|
|
1181
|
+
import { live } from "@dxos/live-object";
|
|
1321
1182
|
import { MenuProvider, ToolbarMenu, createGapSeparator, createMenuAction, useMenuActions } from "@dxos/react-ui-menu";
|
|
1322
|
-
import {
|
|
1323
|
-
var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) =>
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1342
|
-
|
|
1343
|
-
|
|
1344
|
-
|
|
1345
|
-
|
|
1346
|
-
|
|
1347
|
-
|
|
1183
|
+
import { atomFromSignal } from "@dxos/react-ui-menu";
|
|
1184
|
+
var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Atom.make((get) => {
|
|
1185
|
+
const nodes = [];
|
|
1186
|
+
if (onAdd) {
|
|
1187
|
+
const add = createMenuAction("add-row", onAdd, {
|
|
1188
|
+
type: "add-row",
|
|
1189
|
+
icon: "ph--plus--regular",
|
|
1190
|
+
label: [
|
|
1191
|
+
"add row label",
|
|
1192
|
+
{
|
|
1193
|
+
ns: translationKey
|
|
1194
|
+
}
|
|
1195
|
+
],
|
|
1196
|
+
testId: "table.toolbar.add-row"
|
|
1197
|
+
});
|
|
1198
|
+
nodes.push(add);
|
|
1199
|
+
}
|
|
1200
|
+
if (onSave) {
|
|
1201
|
+
const save = createMenuAction("save-view", onSave, {
|
|
1202
|
+
type: "save-view",
|
|
1203
|
+
icon: "ph--floppy-disk--regular",
|
|
1204
|
+
label: [
|
|
1205
|
+
"save view label",
|
|
1206
|
+
{
|
|
1207
|
+
ns: translationKey
|
|
1208
|
+
}
|
|
1209
|
+
],
|
|
1210
|
+
testId: "table.toolbar.save-view",
|
|
1211
|
+
iconOnly: false,
|
|
1212
|
+
hidden: get(atomFromSignal(() => !state.viewDirty))
|
|
1213
|
+
});
|
|
1214
|
+
nodes.push(save);
|
|
1215
|
+
}
|
|
1348
1216
|
const gap = createGapSeparator();
|
|
1349
|
-
|
|
1350
|
-
add,
|
|
1351
|
-
save,
|
|
1352
|
-
...gap.nodes
|
|
1353
|
-
];
|
|
1217
|
+
nodes.push(...gap.nodes);
|
|
1354
1218
|
const edges = nodes.map(({ id: target }) => ({
|
|
1355
1219
|
source: "root",
|
|
1356
1220
|
target
|
|
@@ -1366,12 +1230,12 @@ var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.
|
|
|
1366
1230
|
};
|
|
1367
1231
|
});
|
|
1368
1232
|
var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, customActions }) => {
|
|
1369
|
-
var _effect =
|
|
1233
|
+
var _effect = _useSignals9();
|
|
1370
1234
|
try {
|
|
1371
|
-
const state =
|
|
1235
|
+
const state = useMemo6(() => live({
|
|
1372
1236
|
viewDirty
|
|
1373
1237
|
}), []);
|
|
1374
|
-
const actionsCreator =
|
|
1238
|
+
const actionsCreator = useMemo6(() => createTableToolbarActions({
|
|
1375
1239
|
state,
|
|
1376
1240
|
onAdd,
|
|
1377
1241
|
onSave,
|
|
@@ -1383,10 +1247,10 @@ var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, custom
|
|
|
1383
1247
|
customActions
|
|
1384
1248
|
]);
|
|
1385
1249
|
const menu = useMenuActions(actionsCreator);
|
|
1386
|
-
return /* @__PURE__ */
|
|
1250
|
+
return /* @__PURE__ */ React9.createElement(MenuProvider, {
|
|
1387
1251
|
...menu,
|
|
1388
1252
|
attendableId
|
|
1389
|
-
}, /* @__PURE__ */
|
|
1253
|
+
}, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
|
|
1390
1254
|
classNames
|
|
1391
1255
|
}));
|
|
1392
1256
|
} finally {
|
|
@@ -1413,6 +1277,7 @@ export {
|
|
|
1413
1277
|
touch,
|
|
1414
1278
|
translations,
|
|
1415
1279
|
useAddRow,
|
|
1280
|
+
useProjectionModel,
|
|
1416
1281
|
useTableModel
|
|
1417
1282
|
};
|
|
1418
1283
|
//# sourceMappingURL=index.mjs.map
|