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