@dxos/react-ui-table 0.8.4-main.dedc0f3 → 0.8.4-main.e8ec1fe
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-63UUF4IG.mjs → chunk-2PFAPQL4.mjs} +7 -7
- package/dist/lib/browser/chunk-2PFAPQL4.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GPZSXPSA.mjs → chunk-GS2UNGJK.mjs} +444 -491
- package/dist/lib/browser/chunk-GS2UNGJK.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +161 -303
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +9 -7
- package/dist/lib/browser/testing/index.mjs.map +3 -3
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node-esm/{chunk-K734DJB7.mjs → chunk-6POOFFYF.mjs} +7 -7
- package/dist/lib/node-esm/chunk-6POOFFYF.mjs.map +7 -0
- package/dist/lib/node-esm/{chunk-XUD6W42C.mjs → chunk-TRR3C5NX.mjs} +444 -491
- package/dist/lib/node-esm/chunk-TRR3C5NX.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +161 -303
- 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 +9 -7
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Table/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 +3 -3
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +70 -7
- 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 +5 -6
- 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 +1 -2
- 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 -3
- package/dist/types/src/components/testing.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/useTableModel.d.ts +3 -3
- 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 +4 -4
- 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 +2 -2
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/testing/useTestTableModel.d.ts +3 -3
- package/dist/types/src/testing/useTestTableModel.d.ts.map +1 -1
- package/dist/types/src/types/schema.d.ts +6 -6
- package/dist/types/src/types/schema.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +5 -6
- 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 +52 -51
- package/src/components/Table/DynamicTable.stories.tsx +11 -10
- package/src/components/Table/DynamicTable.tsx +4 -7
- package/src/components/Table/Relations.stories.tsx +127 -18
- package/src/components/Table/RowActionsMenu.tsx +21 -13
- package/src/components/Table/Table.stories.tsx +44 -43
- package/src/components/Table/Table.tsx +13 -9
- package/src/components/TableCellEditor/FormCellEditor.tsx +51 -41
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +19 -46
- package/src/components/TableCellEditor/TableCellEditor.tsx +7 -94
- package/src/components/TableCellEditor/index.ts +1 -0
- package/src/components/TableToolbar/TableToolbar.tsx +32 -22
- package/src/components/testing.ts +2 -2
- package/src/hooks/useAddRow.ts +1 -1
- package/src/hooks/useTableModel.ts +5 -5
- package/src/model/modal-controller.ts +0 -28
- package/src/model/table-model.test.ts +17 -7
- package/src/model/table-model.ts +12 -8
- package/src/model/table-presentation.test.ts +20 -18
- package/src/model/table-presentation.ts +4 -5
- package/src/model/table-sorting.ts +9 -9
- package/src/playwright/TableManager.ts +1 -1
- package/src/playwright/smoke.spec.ts +7 -5
- package/src/testing/useTestTableModel.ts +7 -5
- package/src/types/schema.ts +8 -8
- package/src/util/dynamic-table.ts +10 -12
- package/src/util/schema.ts +4 -4
- package/dist/lib/browser/chunk-63UUF4IG.mjs.map +0 -7
- package/dist/lib/browser/chunk-GPZSXPSA.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-K734DJB7.mjs.map +0 -7
- 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/src/components/Table/CreateRefPanel.tsx +0 -103
|
@@ -15,8 +15,8 @@ import {
|
|
|
15
15
|
touch,
|
|
16
16
|
useAddRow,
|
|
17
17
|
useTableModel
|
|
18
|
-
} from "./chunk-
|
|
19
|
-
import "./chunk-
|
|
18
|
+
} from "./chunk-GS2UNGJK.mjs";
|
|
19
|
+
import "./chunk-2PFAPQL4.mjs";
|
|
20
20
|
|
|
21
21
|
// src/translations.ts
|
|
22
22
|
var translationKey = "react-ui-table";
|
|
@@ -51,8 +51,9 @@ var translations = [
|
|
|
51
51
|
];
|
|
52
52
|
|
|
53
53
|
// src/components/Table/Table.tsx
|
|
54
|
-
import { useSignals as
|
|
55
|
-
import
|
|
54
|
+
import { useSignals as _useSignals7 } from "@preact-signals/safe-react/tracking";
|
|
55
|
+
import * as String2 from "effect/String";
|
|
56
|
+
import React7, { forwardRef, useCallback as useCallback4, useEffect as useEffect3, useImperativeHandle, useMemo as useMemo4, useState as useState4 } from "react";
|
|
56
57
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
57
58
|
import { Grid, closestCell, gridSeparatorBlockEnd, gridSeparatorInlineEnd } from "@dxos/react-ui-grid";
|
|
58
59
|
import { DxEditRequest } from "@dxos/react-ui-grid";
|
|
@@ -63,11 +64,9 @@ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking"
|
|
|
63
64
|
import { EditorView } from "@codemirror/view";
|
|
64
65
|
import React3, { useCallback as useCallback2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
65
66
|
import { debounce } from "@dxos/async";
|
|
66
|
-
import { FormatEnum, TypeEnum } from "@dxos/echo
|
|
67
|
+
import { FormatEnum as FormatEnum2, TypeEnum } from "@dxos/echo/internal";
|
|
67
68
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
68
|
-
import { createMarkdownExtensions } from "@dxos/react-ui-editor";
|
|
69
69
|
import { GridCellEditor, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3 } from "@dxos/react-ui-grid";
|
|
70
|
-
import { createLinks, tagPicker } from "@dxos/react-ui-tag-picker";
|
|
71
70
|
|
|
72
71
|
// src/components/TableCellEditor/CellValidationMessage.tsx
|
|
73
72
|
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
@@ -102,16 +101,17 @@ var CellValidationMessage = ({ validationError, variant = "error", __gridScope }
|
|
|
102
101
|
|
|
103
102
|
// src/components/TableCellEditor/FormCellEditor.tsx
|
|
104
103
|
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
104
|
+
import * as Schema from "effect/Schema";
|
|
105
105
|
import React2, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
106
106
|
import { Filter, Obj } from "@dxos/echo";
|
|
107
|
-
import { Ref, getValue } from "@dxos/echo
|
|
107
|
+
import { FormatEnum, Ref, getValue } from "@dxos/echo/internal";
|
|
108
108
|
import { invariant } from "@dxos/invariant";
|
|
109
109
|
import { getSnapshot } from "@dxos/live-object";
|
|
110
110
|
import { getSpace } from "@dxos/react-client/echo";
|
|
111
111
|
import { Popover } from "@dxos/react-ui";
|
|
112
112
|
import { Form } from "@dxos/react-ui-form";
|
|
113
|
-
import {
|
|
114
|
-
import { getDeep,
|
|
113
|
+
import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
|
|
114
|
+
import { getDeep, isTruthy, setDeep } from "@dxos/util";
|
|
115
115
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
|
|
116
116
|
var createOptionLabel = [
|
|
117
117
|
"create new object label",
|
|
@@ -119,7 +119,7 @@ var createOptionLabel = [
|
|
|
119
119
|
ns: translationKey
|
|
120
120
|
}
|
|
121
121
|
];
|
|
122
|
-
var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals, __gridScope, ...formProps }) => {
|
|
122
|
+
var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals, onCreate, __gridScope, ...formProps }) => {
|
|
123
123
|
var _effect = _useSignals2();
|
|
124
124
|
try {
|
|
125
125
|
const { editing: contextEditing, setEditing, id: gridId } = useGridContext2("ArrayEditor", __gridScope);
|
|
@@ -129,7 +129,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
129
129
|
const space = getSpace(model.view);
|
|
130
130
|
invariant(space, void 0, {
|
|
131
131
|
F: __dxlog_file,
|
|
132
|
-
L:
|
|
132
|
+
L: 57,
|
|
133
133
|
S: void 0,
|
|
134
134
|
A: [
|
|
135
135
|
"space",
|
|
@@ -160,7 +160,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
160
160
|
dxn: Obj.getDXN(obj),
|
|
161
161
|
label: getValue(obj, fieldProjection.field.referencePath) || obj.id.toString()
|
|
162
162
|
};
|
|
163
|
-
}).filter(
|
|
163
|
+
}).filter(isTruthy);
|
|
164
164
|
}
|
|
165
165
|
return [];
|
|
166
166
|
}, [
|
|
@@ -174,7 +174,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
174
174
|
const draftRow = model.draftRows.value[cell.row];
|
|
175
175
|
invariant(draftRow, void 0, {
|
|
176
176
|
F: __dxlog_file,
|
|
177
|
-
L:
|
|
177
|
+
L: 98,
|
|
178
178
|
S: void 0,
|
|
179
179
|
A: [
|
|
180
180
|
"draftRow",
|
|
@@ -186,7 +186,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
186
186
|
const row = model.getRowAt(cell.row);
|
|
187
187
|
invariant(row, void 0, {
|
|
188
188
|
F: __dxlog_file,
|
|
189
|
-
L:
|
|
189
|
+
L: 102,
|
|
190
190
|
S: void 0,
|
|
191
191
|
A: [
|
|
192
192
|
"row",
|
|
@@ -219,38 +219,6 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
219
219
|
contextEditing,
|
|
220
220
|
originalRow
|
|
221
221
|
]);
|
|
222
|
-
const handleCreate = useCallback((object) => {
|
|
223
|
-
const ref = Ref.make(object);
|
|
224
|
-
const path = fieldProjection.field.path;
|
|
225
|
-
setDeep(originalRow, [
|
|
226
|
-
path
|
|
227
|
-
], ref);
|
|
228
|
-
contextEditing?.cellElement?.focus();
|
|
229
|
-
setEditing(null);
|
|
230
|
-
setLocalEditing(false);
|
|
231
|
-
onSave?.();
|
|
232
|
-
}, [
|
|
233
|
-
fieldProjection.field.path,
|
|
234
|
-
onSave,
|
|
235
|
-
contextEditing,
|
|
236
|
-
originalRow
|
|
237
|
-
]);
|
|
238
|
-
const handleCreateFromQuery = useCallback(async (typeAnnotation, query) => {
|
|
239
|
-
if (model && modals && contextEditing?.index) {
|
|
240
|
-
setLocalEditing(false);
|
|
241
|
-
modals.openCreateRef(typeAnnotation.typename, document.querySelector(cellQuery(contextEditing.index, gridId)), {
|
|
242
|
-
[fieldProjection.field.referencePath]: query
|
|
243
|
-
}, handleCreate);
|
|
244
|
-
}
|
|
245
|
-
}, [
|
|
246
|
-
model,
|
|
247
|
-
modals,
|
|
248
|
-
client,
|
|
249
|
-
contextEditing?.index,
|
|
250
|
-
gridId,
|
|
251
|
-
fieldProjection,
|
|
252
|
-
handleSave
|
|
253
|
-
]);
|
|
254
222
|
useEffect(() => {
|
|
255
223
|
if (contextEditing && contextEditing.cellElement) {
|
|
256
224
|
anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
|
|
@@ -283,6 +251,47 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
283
251
|
}
|
|
284
252
|
setLocalEditing(nextOpen);
|
|
285
253
|
}, []);
|
|
254
|
+
const refSchema = useMemo(() => {
|
|
255
|
+
if (fieldProjection.props.format === FormatEnum.Ref && fieldProjection.props.referenceSchema) {
|
|
256
|
+
const { schema: refSchema2 } = getSchema({
|
|
257
|
+
typename: fieldProjection.props.referenceSchema
|
|
258
|
+
});
|
|
259
|
+
return refSchema2;
|
|
260
|
+
}
|
|
261
|
+
return null;
|
|
262
|
+
}, [
|
|
263
|
+
fieldProjection.props.format,
|
|
264
|
+
fieldProjection.props.referenceSchema,
|
|
265
|
+
getSchema
|
|
266
|
+
]);
|
|
267
|
+
const createSchema = useMemo(() => {
|
|
268
|
+
return refSchema ? Schema.omit("id")(refSchema) : null;
|
|
269
|
+
}, [
|
|
270
|
+
refSchema
|
|
271
|
+
]);
|
|
272
|
+
const handleCreate = useCallback((values) => {
|
|
273
|
+
if (refSchema && onCreate) {
|
|
274
|
+
const objectWithId = onCreate(refSchema, values);
|
|
275
|
+
if (objectWithId) {
|
|
276
|
+
const ref = Ref.make(objectWithId);
|
|
277
|
+
const path = fieldProjection.field.path;
|
|
278
|
+
setDeep(originalRow, [
|
|
279
|
+
path
|
|
280
|
+
], ref);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
contextEditing?.cellElement?.focus();
|
|
284
|
+
setEditing(null);
|
|
285
|
+
setLocalEditing(false);
|
|
286
|
+
onSave?.();
|
|
287
|
+
}, [
|
|
288
|
+
fieldProjection.field.path,
|
|
289
|
+
onSave,
|
|
290
|
+
contextEditing,
|
|
291
|
+
originalRow,
|
|
292
|
+
refSchema,
|
|
293
|
+
onCreate
|
|
294
|
+
]);
|
|
286
295
|
if (!editing) {
|
|
287
296
|
return null;
|
|
288
297
|
}
|
|
@@ -301,9 +310,13 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
301
310
|
onSave: handleSave,
|
|
302
311
|
...formProps,
|
|
303
312
|
onQueryRefOptions: handleQueryRefOptions,
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
313
|
+
...createSchema && {
|
|
314
|
+
onCreate: handleCreate,
|
|
315
|
+
createSchema,
|
|
316
|
+
createInitialValuePath: fieldProjection.field.referencePath,
|
|
317
|
+
createOptionIcon: "ph--plus--regular",
|
|
318
|
+
createOptionLabel
|
|
319
|
+
}
|
|
307
320
|
})))));
|
|
308
321
|
} finally {
|
|
309
322
|
_effect.f();
|
|
@@ -313,7 +326,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
313
326
|
// src/components/TableCellEditor/TableCellEditor.tsx
|
|
314
327
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
|
|
315
328
|
var adaptValidationMessage = (message) => message ? message.endsWith("is missing") ? "Can\u2019t be blank" : message : null;
|
|
316
|
-
var TableValueEditor = ({ model, modals, schema, onFocus, onSave, client, __gridScope }) => {
|
|
329
|
+
var TableValueEditor = ({ model, modals, schema, onFocus, onSave, onCreate, client, __gridScope }) => {
|
|
317
330
|
var _effect = _useSignals3();
|
|
318
331
|
try {
|
|
319
332
|
const { editing } = useGridContext3("TableValueEditor", __gridScope);
|
|
@@ -338,13 +351,14 @@ var TableValueEditor = ({ model, modals, schema, onFocus, onSave, client, __grid
|
|
|
338
351
|
model,
|
|
339
352
|
editing
|
|
340
353
|
]);
|
|
341
|
-
if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format ===
|
|
354
|
+
if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === FormatEnum2.SingleSelect || fieldProjection?.props.format === FormatEnum2.Ref) {
|
|
342
355
|
return /* @__PURE__ */ React3.createElement(FormCellEditor, {
|
|
343
356
|
fieldProjection,
|
|
344
357
|
model,
|
|
345
358
|
schema,
|
|
346
359
|
__gridScope,
|
|
347
360
|
onSave,
|
|
361
|
+
onCreate,
|
|
348
362
|
client,
|
|
349
363
|
modals
|
|
350
364
|
});
|
|
@@ -381,7 +395,7 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
381
395
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
382
396
|
invariant2(fieldProjection2, void 0, {
|
|
383
397
|
F: __dxlog_file2,
|
|
384
|
-
L:
|
|
398
|
+
L: 121,
|
|
385
399
|
S: void 0,
|
|
386
400
|
A: [
|
|
387
401
|
"fieldProjection",
|
|
@@ -483,35 +497,6 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
483
497
|
}
|
|
484
498
|
})
|
|
485
499
|
];
|
|
486
|
-
const format = fieldProjection.props.format;
|
|
487
|
-
if (format === FormatEnum.SingleSelect || format === FormatEnum.MultiSelect) {
|
|
488
|
-
const options = fieldProjection.props.options || [];
|
|
489
|
-
const mode = format === FormatEnum.SingleSelect ? "single-select" : "multi-select";
|
|
490
|
-
extensions2.push(createMarkdownExtensions());
|
|
491
|
-
extensions2.push(tagPicker({
|
|
492
|
-
mode,
|
|
493
|
-
keymap: false,
|
|
494
|
-
onSearch: (text, selectedIds) => {
|
|
495
|
-
return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
|
|
496
|
-
id: option.id,
|
|
497
|
-
label: option.title,
|
|
498
|
-
hue: option.color
|
|
499
|
-
}));
|
|
500
|
-
},
|
|
501
|
-
onUpdate: (ids) => {
|
|
502
|
-
if (model && editing) {
|
|
503
|
-
if (ids.length === 0) {
|
|
504
|
-
return;
|
|
505
|
-
}
|
|
506
|
-
if (mode === "single-select") {
|
|
507
|
-
void handleEnter(ids[0]);
|
|
508
|
-
} else {
|
|
509
|
-
void handleEnter(ids);
|
|
510
|
-
}
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
}));
|
|
514
|
-
}
|
|
515
500
|
if (model && editing) {
|
|
516
501
|
extensions2.push(EditorView.updateListener.of(debounce((update) => {
|
|
517
502
|
const content = update.state.doc.toString();
|
|
@@ -537,42 +522,6 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
537
522
|
const getCellContent = useCallback2(() => {
|
|
538
523
|
if (model && editing) {
|
|
539
524
|
const cell = parseCellIndex2(editing.index);
|
|
540
|
-
const { col } = cell;
|
|
541
|
-
const field = model.projection.fields[col];
|
|
542
|
-
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
543
|
-
if (fieldProjection2?.props.format === FormatEnum.SingleSelect || fieldProjection2?.props.format === FormatEnum.MultiSelect) {
|
|
544
|
-
const value2 = model.getCellData(cell);
|
|
545
|
-
if (value2 !== void 0) {
|
|
546
|
-
const options = fieldProjection2.props.options || [];
|
|
547
|
-
if (fieldProjection2.props.format === FormatEnum.MultiSelect) {
|
|
548
|
-
const tagItems = value2.split(",").map((id) => {
|
|
549
|
-
const option = options.find((o) => o.id === id);
|
|
550
|
-
if (option) {
|
|
551
|
-
return {
|
|
552
|
-
id,
|
|
553
|
-
label: option.title,
|
|
554
|
-
hue: option.color
|
|
555
|
-
};
|
|
556
|
-
}
|
|
557
|
-
return void 0;
|
|
558
|
-
}).filter((item) => item !== void 0);
|
|
559
|
-
return createLinks(tagItems);
|
|
560
|
-
} else {
|
|
561
|
-
const option = options.find((o) => o.id === value2);
|
|
562
|
-
if (option) {
|
|
563
|
-
const tagItem = {
|
|
564
|
-
id: value2,
|
|
565
|
-
label: option.title,
|
|
566
|
-
hue: option.color
|
|
567
|
-
};
|
|
568
|
-
return createLinks([
|
|
569
|
-
tagItem
|
|
570
|
-
]);
|
|
571
|
-
}
|
|
572
|
-
}
|
|
573
|
-
}
|
|
574
|
-
return "";
|
|
575
|
-
}
|
|
576
525
|
const value = model.getCellData(cell);
|
|
577
526
|
return value !== void 0 ? String(value) : "";
|
|
578
527
|
}
|
|
@@ -732,106 +681,12 @@ var ColumnSettings = ({ registry, model, modals, onNewColumn }) => {
|
|
|
732
681
|
}
|
|
733
682
|
};
|
|
734
683
|
|
|
735
|
-
// src/components/Table/CreateRefPanel.tsx
|
|
736
|
-
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
737
|
-
import { Schema } from "effect";
|
|
738
|
-
import React6, { useCallback as useCallback4, useMemo as useMemo4 } from "react";
|
|
739
|
-
import { Type } from "@dxos/echo";
|
|
740
|
-
import { live } from "@dxos/live-object";
|
|
741
|
-
import { useClient } from "@dxos/react-client";
|
|
742
|
-
import { getSpace as getSpace2 } from "@dxos/react-client/echo";
|
|
743
|
-
import { Popover as Popover3 } from "@dxos/react-ui";
|
|
744
|
-
import { Form as Form2 } from "@dxos/react-ui-form";
|
|
745
|
-
import { useGridContext as useGridContext4 } from "@dxos/react-ui-grid";
|
|
746
|
-
var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
747
|
-
var _effect = _useSignals6();
|
|
748
|
-
try {
|
|
749
|
-
const { id: gridId } = useGridContext4("TableCellEditor", __gridScope);
|
|
750
|
-
const client = useClient();
|
|
751
|
-
const space = model && getSpace2(model?.view);
|
|
752
|
-
const state = modals.state.value;
|
|
753
|
-
const getSchema = useCallback4(() => {
|
|
754
|
-
if (!space || state?.type !== "createRefPanel") {
|
|
755
|
-
return;
|
|
756
|
-
}
|
|
757
|
-
const staticSchema = client.graph.schemaRegistry.schemas.find((schema3) => Type.getTypename(schema3) === state.typename);
|
|
758
|
-
if (staticSchema) {
|
|
759
|
-
return staticSchema;
|
|
760
|
-
}
|
|
761
|
-
const [schema2] = space.db.schemaRegistry.query({
|
|
762
|
-
typename: state.typename
|
|
763
|
-
}).runSync();
|
|
764
|
-
return schema2;
|
|
765
|
-
}, [
|
|
766
|
-
space,
|
|
767
|
-
state
|
|
768
|
-
]);
|
|
769
|
-
const schema = useMemo4(() => {
|
|
770
|
-
const schema2 = getSchema();
|
|
771
|
-
if (!schema2) {
|
|
772
|
-
return;
|
|
773
|
-
}
|
|
774
|
-
const omit = Schema.omit("id");
|
|
775
|
-
return omit(schema2);
|
|
776
|
-
}, [
|
|
777
|
-
getSchema
|
|
778
|
-
]);
|
|
779
|
-
const handleSave = useCallback4((values) => {
|
|
780
|
-
if (!model || !space || state?.type !== "createRefPanel") {
|
|
781
|
-
return;
|
|
782
|
-
}
|
|
783
|
-
const schema2 = getSchema();
|
|
784
|
-
if (schema2) {
|
|
785
|
-
const obj = space.db.add(live(schema2, values));
|
|
786
|
-
state.onCreate?.(obj);
|
|
787
|
-
}
|
|
788
|
-
void modals.close();
|
|
789
|
-
}, [
|
|
790
|
-
model,
|
|
791
|
-
modals,
|
|
792
|
-
space,
|
|
793
|
-
state
|
|
794
|
-
]);
|
|
795
|
-
const handleCancel = useCallback4(() => {
|
|
796
|
-
if (model) {
|
|
797
|
-
modals.close();
|
|
798
|
-
}
|
|
799
|
-
}, [
|
|
800
|
-
modals
|
|
801
|
-
]);
|
|
802
|
-
if (!model?.projection) {
|
|
803
|
-
return null;
|
|
804
|
-
}
|
|
805
|
-
return /* @__PURE__ */ React6.createElement(Popover3.Root, {
|
|
806
|
-
modal: false,
|
|
807
|
-
open: state?.type === "createRefPanel" && !!schema,
|
|
808
|
-
onOpenChange: (nextOpen) => {
|
|
809
|
-
if (model && !nextOpen) {
|
|
810
|
-
return modals.close();
|
|
811
|
-
}
|
|
812
|
-
}
|
|
813
|
-
}, /* @__PURE__ */ React6.createElement(Popover3.VirtualTrigger, {
|
|
814
|
-
virtualRef: modals.trigger
|
|
815
|
-
}), /* @__PURE__ */ React6.createElement(Popover3.Portal, null, /* @__PURE__ */ React6.createElement(Popover3.Content, {
|
|
816
|
-
classNames: "md:is-64",
|
|
817
|
-
"data-grid": gridId
|
|
818
|
-
}, /* @__PURE__ */ React6.createElement(Popover3.Viewport, null, state?.type === "createRefPanel" && schema && /* @__PURE__ */ React6.createElement(Form2, {
|
|
819
|
-
schema,
|
|
820
|
-
values: state.initialValues ?? {},
|
|
821
|
-
onSave: handleSave,
|
|
822
|
-
onCancel: handleCancel
|
|
823
|
-
})), /* @__PURE__ */ React6.createElement(Popover3.Arrow, null))));
|
|
824
|
-
} finally {
|
|
825
|
-
_effect.f();
|
|
826
|
-
}
|
|
827
|
-
};
|
|
828
|
-
|
|
829
684
|
// src/components/Table/RowActionsMenu.tsx
|
|
830
|
-
import { useSignals as
|
|
831
|
-
import
|
|
685
|
+
import { useSignals as _useSignals6 } from "@preact-signals/safe-react/tracking";
|
|
686
|
+
import React6 from "react";
|
|
832
687
|
import { DropdownMenu as DropdownMenu2, toLocalizedString, useTranslation as useTranslation2 } from "@dxos/react-ui";
|
|
833
688
|
var RowActionsMenu = ({ model, modals }) => {
|
|
834
|
-
var _effect =
|
|
689
|
+
var _effect = _useSignals6();
|
|
835
690
|
try {
|
|
836
691
|
const { t } = useTranslation2(translationKey);
|
|
837
692
|
const hasSelection = model.selection.hasSelection.value;
|
|
@@ -839,23 +694,23 @@ var RowActionsMenu = ({ model, modals }) => {
|
|
|
839
694
|
if (state?.type !== "row") {
|
|
840
695
|
return null;
|
|
841
696
|
}
|
|
842
|
-
return /* @__PURE__ */
|
|
697
|
+
return /* @__PURE__ */ React6.createElement(DropdownMenu2.Root, {
|
|
843
698
|
modal: false,
|
|
844
699
|
open: true,
|
|
845
700
|
onOpenChange: modals.close
|
|
846
|
-
}, /* @__PURE__ */
|
|
701
|
+
}, /* @__PURE__ */ React6.createElement(DropdownMenu2.VirtualTrigger, {
|
|
847
702
|
virtualRef: modals.trigger
|
|
848
|
-
}), /* @__PURE__ */
|
|
849
|
-
"data-testid": "row-menu-delete",
|
|
850
|
-
onClick: () => model.deleteRow(state.rowIndex)
|
|
851
|
-
}, t(hasSelection ? "bulk delete row label" : "delete row label")), model.rowActions?.map((action) => /* @__PURE__ */ React7.createElement(DropdownMenu2.Item, {
|
|
703
|
+
}), /* @__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, {
|
|
852
704
|
key: action.id,
|
|
853
705
|
"data-testid": `row-action-${action.id}`,
|
|
854
706
|
onClick: () => {
|
|
855
707
|
modals.close();
|
|
856
708
|
model.handleRowAction(action.id, state.rowIndex);
|
|
857
709
|
}
|
|
858
|
-
}, toLocalizedString(action.label, t)))), /* @__PURE__ */
|
|
710
|
+
}, toLocalizedString(action.label, t)))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Separator, null)), model.features.dataEditable !== false && /* @__PURE__ */ React6.createElement(DropdownMenu2.Item, {
|
|
711
|
+
"data-testid": "row-menu-delete",
|
|
712
|
+
onClick: () => model.deleteRow(state.rowIndex)
|
|
713
|
+
}, t(hasSelection ? "bulk delete row label" : "delete row label"))), /* @__PURE__ */ React6.createElement(DropdownMenu2.Arrow, null)));
|
|
859
714
|
} finally {
|
|
860
715
|
_effect.f();
|
|
861
716
|
}
|
|
@@ -875,9 +730,9 @@ var rowDefault = {
|
|
|
875
730
|
}
|
|
876
731
|
};
|
|
877
732
|
var TableRoot = ({ children, role = "article" }) => {
|
|
878
|
-
var _effect =
|
|
733
|
+
var _effect = _useSignals7();
|
|
879
734
|
try {
|
|
880
|
-
return /* @__PURE__ */
|
|
735
|
+
return /* @__PURE__ */ React7.createElement("div", {
|
|
881
736
|
role: "none",
|
|
882
737
|
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]", [
|
|
883
738
|
"card--popover",
|
|
@@ -892,20 +747,20 @@ var TableRoot = ({ children, role = "article" }) => {
|
|
|
892
747
|
_effect.f();
|
|
893
748
|
}
|
|
894
749
|
};
|
|
895
|
-
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, client, onRowClick }, forwardedRef) => {
|
|
896
|
-
var _effect =
|
|
750
|
+
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, client, onCreate, onRowClick, testId }, forwardedRef) => {
|
|
751
|
+
var _effect = _useSignals7();
|
|
897
752
|
try {
|
|
898
753
|
const [dxGrid, setDxGrid] = useState4(null);
|
|
899
754
|
const { hasAttention } = useAttention(model?.id ?? "table");
|
|
900
|
-
const modals =
|
|
755
|
+
const modals = useMemo4(() => new ModalController(), []);
|
|
901
756
|
const draftRowCount = model?.getDraftRowCount() ?? 0;
|
|
902
|
-
const handleSave =
|
|
757
|
+
const handleSave = useCallback4(() => {
|
|
903
758
|
dxGrid?.updateCells(true);
|
|
904
759
|
dxGrid?.requestUpdate();
|
|
905
760
|
}, [
|
|
906
761
|
dxGrid
|
|
907
762
|
]);
|
|
908
|
-
const frozen =
|
|
763
|
+
const frozen = useMemo4(() => {
|
|
909
764
|
const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
|
|
910
765
|
return {
|
|
911
766
|
frozenRowsStart: 1,
|
|
@@ -917,7 +772,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
917
772
|
model,
|
|
918
773
|
draftRowCount
|
|
919
774
|
]);
|
|
920
|
-
const getCells =
|
|
775
|
+
const getCells = useCallback4((range, plane) => presentation?.getCells(range, plane) ?? {}, [
|
|
921
776
|
presentation
|
|
922
777
|
]);
|
|
923
778
|
useEffect3(() => {
|
|
@@ -930,7 +785,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
930
785
|
dxGrid,
|
|
931
786
|
getCells
|
|
932
787
|
]);
|
|
933
|
-
const handleInsertRowResult =
|
|
788
|
+
const handleInsertRowResult = useCallback4((insertResult) => {
|
|
934
789
|
if (insertResult === "draft") {
|
|
935
790
|
requestAnimationFrame(() => {
|
|
936
791
|
dxGrid?.setFocus({
|
|
@@ -974,7 +829,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
974
829
|
dxGrid,
|
|
975
830
|
model
|
|
976
831
|
]);
|
|
977
|
-
const handleSaveDraftRow =
|
|
832
|
+
const handleSaveDraftRow = useCallback4((rowIndex = 0) => {
|
|
978
833
|
if (model && dxGrid) {
|
|
979
834
|
const didCommitSuccessfully = model.commitDraftRow(rowIndex);
|
|
980
835
|
if (didCommitSuccessfully) {
|
|
@@ -987,7 +842,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
987
842
|
model,
|
|
988
843
|
dxGrid
|
|
989
844
|
]);
|
|
990
|
-
const handleGridClick =
|
|
845
|
+
const handleGridClick = useCallback4((event) => {
|
|
991
846
|
const cell = closestCell(event.target);
|
|
992
847
|
if (cell) {
|
|
993
848
|
const { row: rowIndex, plane } = cell;
|
|
@@ -1072,9 +927,9 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1072
927
|
modals,
|
|
1073
928
|
dxGrid
|
|
1074
929
|
]);
|
|
1075
|
-
const handleFocus =
|
|
930
|
+
const handleFocus = useCallback4((increment, delta, cell) => {
|
|
1076
931
|
if (dxGrid && model) {
|
|
1077
|
-
if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1) {
|
|
932
|
+
if (cell?.plane === "grid" && cell?.row >= model.getRowCount() - 1 && increment !== "col") {
|
|
1078
933
|
handleInsertRowResult(draftRowCount < 1 ? model.insertRow() : "final");
|
|
1079
934
|
} else if (cell?.plane === "frozenRowsEnd" && increment === "row") {
|
|
1080
935
|
handleSaveDraftRow(cell.row);
|
|
@@ -1087,7 +942,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1087
942
|
dxGrid,
|
|
1088
943
|
model
|
|
1089
944
|
]);
|
|
1090
|
-
const handleKeyDown =
|
|
945
|
+
const handleKeyDown = useCallback4((event) => {
|
|
1091
946
|
if (!model?.features.dataEditable) {
|
|
1092
947
|
return;
|
|
1093
948
|
}
|
|
@@ -1112,7 +967,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1112
967
|
event.preventDefault();
|
|
1113
968
|
void navigator.clipboard.readText().then((clipboardText) => {
|
|
1114
969
|
try {
|
|
1115
|
-
model.setCellData(cell, clipboardText);
|
|
970
|
+
model.setCellData(cell, String2.trim(clipboardText).replace(/[\n\r]+/, " "));
|
|
1116
971
|
handleSave();
|
|
1117
972
|
} catch {
|
|
1118
973
|
const cellElement = event.target.closest('[data-dx-grid-action="cell"]');
|
|
@@ -1143,6 +998,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1143
998
|
try {
|
|
1144
999
|
model.setCellData(cell, void 0);
|
|
1145
1000
|
event.preventDefault();
|
|
1001
|
+
handleSave();
|
|
1146
1002
|
} catch {
|
|
1147
1003
|
}
|
|
1148
1004
|
break;
|
|
@@ -1153,7 +1009,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1153
1009
|
dxGrid,
|
|
1154
1010
|
handleSave
|
|
1155
1011
|
]);
|
|
1156
|
-
const handleAxisResize =
|
|
1012
|
+
const handleAxisResize = useCallback4((event) => {
|
|
1157
1013
|
if (event.axis === "col") {
|
|
1158
1014
|
const columnIndex = parseInt(event.index, 10);
|
|
1159
1015
|
model?.setColumnWidth(columnIndex, event.size);
|
|
@@ -1161,7 +1017,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1161
1017
|
}, [
|
|
1162
1018
|
model
|
|
1163
1019
|
]);
|
|
1164
|
-
const handleWheel =
|
|
1020
|
+
const handleWheel = useCallback4((event) => {
|
|
1165
1021
|
if (!ignoreAttention && !hasAttention) {
|
|
1166
1022
|
event.stopPropagation();
|
|
1167
1023
|
}
|
|
@@ -1169,7 +1025,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1169
1025
|
hasAttention,
|
|
1170
1026
|
ignoreAttention
|
|
1171
1027
|
]);
|
|
1172
|
-
const handleNewColumn =
|
|
1028
|
+
const handleNewColumn = useCallback4(() => {
|
|
1173
1029
|
const columns = model?.getColumnCount();
|
|
1174
1030
|
if (dxGrid && columns) {
|
|
1175
1031
|
dxGrid.scrollToColumn(columns - 1);
|
|
@@ -1179,21 +1035,22 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1179
1035
|
dxGrid
|
|
1180
1036
|
]);
|
|
1181
1037
|
if (!model || !modals) {
|
|
1182
|
-
return /* @__PURE__ */
|
|
1038
|
+
return /* @__PURE__ */ React7.createElement("span", {
|
|
1183
1039
|
role: "none",
|
|
1184
1040
|
className: "attention-surface"
|
|
1185
1041
|
});
|
|
1186
1042
|
}
|
|
1187
|
-
return /* @__PURE__ */
|
|
1043
|
+
return /* @__PURE__ */ React7.createElement(Grid.Root, {
|
|
1188
1044
|
id: model.id ?? "table-grid"
|
|
1189
|
-
}, /* @__PURE__ */
|
|
1045
|
+
}, /* @__PURE__ */ React7.createElement(TableValueEditor, {
|
|
1190
1046
|
model,
|
|
1191
1047
|
modals,
|
|
1192
1048
|
schema,
|
|
1193
1049
|
onFocus: handleFocus,
|
|
1194
1050
|
onSave: handleSave,
|
|
1051
|
+
onCreate,
|
|
1195
1052
|
client
|
|
1196
|
-
}), /* @__PURE__ */
|
|
1053
|
+
}), /* @__PURE__ */ React7.createElement(Grid.Content, {
|
|
1197
1054
|
className: mx("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
|
|
1198
1055
|
frozen,
|
|
1199
1056
|
columns: model.columnMeta.value,
|
|
@@ -1206,20 +1063,20 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1206
1063
|
onClick: handleGridClick,
|
|
1207
1064
|
onKeyDownCapture: handleKeyDown,
|
|
1208
1065
|
onWheelCapture: handleWheel,
|
|
1066
|
+
...testId && {
|
|
1067
|
+
"data-testid": testId
|
|
1068
|
+
},
|
|
1209
1069
|
ref: setDxGrid
|
|
1210
|
-
}), /* @__PURE__ */
|
|
1070
|
+
}), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
|
|
1211
1071
|
model,
|
|
1212
1072
|
modals
|
|
1213
|
-
}), /* @__PURE__ */
|
|
1073
|
+
}), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
|
|
1214
1074
|
model,
|
|
1215
1075
|
modals
|
|
1216
|
-
}), /* @__PURE__ */
|
|
1076
|
+
}), /* @__PURE__ */ React7.createElement(ColumnSettings, {
|
|
1217
1077
|
model,
|
|
1218
1078
|
modals,
|
|
1219
1079
|
onNewColumn: handleNewColumn
|
|
1220
|
-
}), /* @__PURE__ */ React8.createElement(CreateRefPanel, {
|
|
1221
|
-
model,
|
|
1222
|
-
modals
|
|
1223
1080
|
}));
|
|
1224
1081
|
} finally {
|
|
1225
1082
|
_effect.f();
|
|
@@ -1231,14 +1088,14 @@ var Table = {
|
|
|
1231
1088
|
};
|
|
1232
1089
|
|
|
1233
1090
|
// src/components/Table/DynamicTable.tsx
|
|
1234
|
-
import { useSignals as
|
|
1235
|
-
import
|
|
1091
|
+
import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking";
|
|
1092
|
+
import React8, { useCallback as useCallback5, useMemo as useMemo5, useRef as useRef3 } from "react";
|
|
1236
1093
|
import { useDefaultValue } from "@dxos/react-ui";
|
|
1237
1094
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
1238
1095
|
var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema: _jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
|
|
1239
|
-
var _effect =
|
|
1096
|
+
var _effect = _useSignals8();
|
|
1240
1097
|
try {
|
|
1241
|
-
const {
|
|
1098
|
+
const { jsonSchema } = useMemo5(() => getBaseSchema({
|
|
1242
1099
|
typename: name,
|
|
1243
1100
|
properties,
|
|
1244
1101
|
jsonSchema: _jsonSchema,
|
|
@@ -1249,20 +1106,18 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
1249
1106
|
_jsonSchema,
|
|
1250
1107
|
schema
|
|
1251
1108
|
]);
|
|
1252
|
-
const { projection, view } =
|
|
1253
|
-
typename,
|
|
1109
|
+
const { projection, view } = useMemo5(() => makeDynamicTable({
|
|
1254
1110
|
jsonSchema,
|
|
1255
1111
|
properties
|
|
1256
1112
|
}), [
|
|
1257
|
-
typename,
|
|
1258
1113
|
jsonSchema,
|
|
1259
1114
|
properties
|
|
1260
1115
|
]);
|
|
1261
1116
|
const tableRef = useRef3(null);
|
|
1262
|
-
const handleCellUpdate =
|
|
1117
|
+
const handleCellUpdate = useCallback5((cell) => {
|
|
1263
1118
|
tableRef.current?.update?.(cell);
|
|
1264
1119
|
}, []);
|
|
1265
|
-
const handleRowOrderChange =
|
|
1120
|
+
const handleRowOrderChange = useCallback5(() => {
|
|
1266
1121
|
tableRef.current?.update?.();
|
|
1267
1122
|
}, []);
|
|
1268
1123
|
const features = useDefaultValue(props.features, () => ({
|
|
@@ -1282,20 +1137,20 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
1282
1137
|
onRowOrderChange: handleRowOrderChange,
|
|
1283
1138
|
onRowAction
|
|
1284
1139
|
});
|
|
1285
|
-
const presentation =
|
|
1140
|
+
const presentation = useMemo5(() => {
|
|
1286
1141
|
if (model) {
|
|
1287
1142
|
return new TablePresentation(model);
|
|
1288
1143
|
}
|
|
1289
1144
|
}, [
|
|
1290
1145
|
model
|
|
1291
1146
|
]);
|
|
1292
|
-
return /* @__PURE__ */
|
|
1147
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
1293
1148
|
role: "none",
|
|
1294
1149
|
className: mx2("is-full bs-full grow grid", classNames)
|
|
1295
|
-
}, /* @__PURE__ */
|
|
1150
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
1296
1151
|
role: "none",
|
|
1297
1152
|
className: "grid min-bs-0 overflow-hidden"
|
|
1298
|
-
}, /* @__PURE__ */
|
|
1153
|
+
}, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
|
|
1299
1154
|
ref: tableRef,
|
|
1300
1155
|
model,
|
|
1301
1156
|
presentation,
|
|
@@ -1308,43 +1163,46 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
1308
1163
|
};
|
|
1309
1164
|
|
|
1310
1165
|
// src/components/TableToolbar/TableToolbar.tsx
|
|
1311
|
-
import { useSignals as
|
|
1312
|
-
import {
|
|
1313
|
-
import
|
|
1314
|
-
import { live
|
|
1166
|
+
import { useSignals as _useSignals9 } from "@preact-signals/safe-react/tracking";
|
|
1167
|
+
import { Atom } from "@effect-atom/atom-react";
|
|
1168
|
+
import React9, { useMemo as useMemo6 } from "react";
|
|
1169
|
+
import { live } from "@dxos/live-object";
|
|
1315
1170
|
import { MenuProvider, ToolbarMenu, createGapSeparator, createMenuAction, useMenuActions } from "@dxos/react-ui-menu";
|
|
1316
|
-
import {
|
|
1317
|
-
var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) =>
|
|
1318
|
-
const
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1326
|
-
|
|
1327
|
-
|
|
1328
|
-
|
|
1329
|
-
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
|
|
1340
|
-
|
|
1341
|
-
|
|
1171
|
+
import { atomFromSignal } from "@dxos/react-ui-menu";
|
|
1172
|
+
var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Atom.make((get) => {
|
|
1173
|
+
const nodes = [];
|
|
1174
|
+
if (onAdd) {
|
|
1175
|
+
const add = createMenuAction("add-row", onAdd, {
|
|
1176
|
+
type: "add-row",
|
|
1177
|
+
icon: "ph--plus--regular",
|
|
1178
|
+
label: [
|
|
1179
|
+
"add row",
|
|
1180
|
+
{
|
|
1181
|
+
ns: translationKey
|
|
1182
|
+
}
|
|
1183
|
+
],
|
|
1184
|
+
testId: "table.toolbar.add-row"
|
|
1185
|
+
});
|
|
1186
|
+
nodes.push(add);
|
|
1187
|
+
}
|
|
1188
|
+
if (onSave) {
|
|
1189
|
+
const save = createMenuAction("save-view", onSave, {
|
|
1190
|
+
type: "save-view",
|
|
1191
|
+
icon: "ph--floppy-disk--regular",
|
|
1192
|
+
label: [
|
|
1193
|
+
"save view label",
|
|
1194
|
+
{
|
|
1195
|
+
ns: translationKey
|
|
1196
|
+
}
|
|
1197
|
+
],
|
|
1198
|
+
testId: "table.toolbar.save-view",
|
|
1199
|
+
iconOnly: false,
|
|
1200
|
+
hidden: get(atomFromSignal(() => !state.viewDirty))
|
|
1201
|
+
});
|
|
1202
|
+
nodes.push(save);
|
|
1203
|
+
}
|
|
1342
1204
|
const gap = createGapSeparator();
|
|
1343
|
-
|
|
1344
|
-
add,
|
|
1345
|
-
save,
|
|
1346
|
-
...gap.nodes
|
|
1347
|
-
];
|
|
1205
|
+
nodes.push(...gap.nodes);
|
|
1348
1206
|
const edges = nodes.map(({ id: target }) => ({
|
|
1349
1207
|
source: "root",
|
|
1350
1208
|
target
|
|
@@ -1360,12 +1218,12 @@ var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Rx.
|
|
|
1360
1218
|
};
|
|
1361
1219
|
});
|
|
1362
1220
|
var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, customActions }) => {
|
|
1363
|
-
var _effect =
|
|
1221
|
+
var _effect = _useSignals9();
|
|
1364
1222
|
try {
|
|
1365
|
-
const state =
|
|
1223
|
+
const state = useMemo6(() => live({
|
|
1366
1224
|
viewDirty
|
|
1367
1225
|
}), []);
|
|
1368
|
-
const actionsCreator =
|
|
1226
|
+
const actionsCreator = useMemo6(() => createTableToolbarActions({
|
|
1369
1227
|
state,
|
|
1370
1228
|
onAdd,
|
|
1371
1229
|
onSave,
|
|
@@ -1377,10 +1235,10 @@ var TableToolbar = ({ classNames, viewDirty, attendableId, onAdd, onSave, custom
|
|
|
1377
1235
|
customActions
|
|
1378
1236
|
]);
|
|
1379
1237
|
const menu = useMenuActions(actionsCreator);
|
|
1380
|
-
return /* @__PURE__ */
|
|
1238
|
+
return /* @__PURE__ */ React9.createElement(MenuProvider, {
|
|
1381
1239
|
...menu,
|
|
1382
1240
|
attendableId
|
|
1383
|
-
}, /* @__PURE__ */
|
|
1241
|
+
}, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
|
|
1384
1242
|
classNames
|
|
1385
1243
|
}));
|
|
1386
1244
|
} finally {
|