@dxos/react-ui-table 0.8.4-main.2c6827d → 0.8.4-main.3c1ae3b
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-CJQ6T4LL.mjs +77 -0
- package/dist/lib/browser/chunk-CJQ6T4LL.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GS2UNGJK.mjs → chunk-V7A7ZA5E.mjs} +119 -111
- package/dist/lib/browser/chunk-V7A7ZA5E.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +162 -147
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +15 -31
- 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-TRR3C5NX.mjs → chunk-P73ALX3N.mjs} +119 -111
- package/dist/lib/node-esm/chunk-P73ALX3N.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-T6PXZQ6W.mjs +78 -0
- package/dist/lib/node-esm/chunk-T6PXZQ6W.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +162 -147
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/testing/index.mjs +15 -31
- 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/ColumnActionsMenu.d.ts +1 -2
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts +2 -2
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +4 -5
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +3 -17
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +10 -6
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.d.ts +8 -8
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +70 -4
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/CellValidationMessage.d.ts +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +10 -11
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +5 -7
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +3 -3
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +0 -2
- 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/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/table-model.d.ts +6 -8
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +7 -3
- 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 +19 -15
- 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/tsconfig.tsbuildinfo +1 -1
- package/package.json +38 -38
- package/src/components/Table/ColumnActionsMenu.tsx +4 -1
- package/src/components/Table/ColumnSettings.tsx +2 -3
- package/src/components/Table/DynamicTable.stories.tsx +7 -9
- package/src/components/Table/DynamicTable.tsx +18 -10
- package/src/components/Table/Relations.stories.tsx +9 -18
- package/src/components/Table/Table.stories.tsx +52 -59
- package/src/components/Table/Table.tsx +317 -304
- package/src/components/TableCellEditor/CellValidationMessage.tsx +1 -1
- package/src/components/TableCellEditor/FormCellEditor.tsx +101 -108
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +11 -8
- package/src/components/TableCellEditor/TableCellEditor.tsx +29 -29
- package/src/components/TableToolbar/TableToolbar.tsx +1 -1
- package/src/components/testing.ts +3 -3
- package/src/hooks/index.ts +2 -1
- package/src/hooks/useProjectionModel.ts +19 -0
- package/src/hooks/useTableModel.ts +11 -13
- package/src/model/table-model.test.ts +4 -4
- package/src/model/table-model.ts +29 -38
- package/src/model/table-presentation.test.ts +4 -4
- package/src/model/table-presentation.ts +9 -9
- package/src/model/table-sorting.ts +21 -12
- package/src/playwright/TableManager.ts +5 -5
- package/src/playwright/smoke.spec.ts +1 -1
- package/src/testing/useTestTableModel.ts +31 -27
- package/src/translations.ts +2 -2
- package/src/types/Table.ts +90 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.ts +11 -16
- package/dist/lib/browser/chunk-2PFAPQL4.mjs +0 -66
- package/dist/lib/browser/chunk-2PFAPQL4.mjs.map +0 -7
- package/dist/lib/browser/chunk-GS2UNGJK.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-6POOFFYF.mjs +0 -67
- package/dist/lib/node-esm/chunk-6POOFFYF.mjs.map +0 -7
- package/dist/lib/node-esm/chunk-TRR3C5NX.mjs.map +0 -7
- package/dist/types/src/types/schema.d.ts +0 -28
- package/dist/types/src/types/schema.d.ts.map +0 -1
- 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-P73ALX3N.mjs";
|
|
21
|
+
import "./chunk-T6PXZQ6W.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",
|
|
@@ -65,7 +66,7 @@ import { useSignals as _useSignals3 } from "@preact-signals/safe-react/tracking"
|
|
|
65
66
|
import { EditorView } from "@codemirror/view";
|
|
66
67
|
import React3, { useCallback as useCallback2, useMemo as useMemo2, useRef as useRef2, useState as useState2 } from "react";
|
|
67
68
|
import { debounce } from "@dxos/async";
|
|
68
|
-
import {
|
|
69
|
+
import { Format as Format2, TypeEnum } from "@dxos/echo/internal";
|
|
69
70
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
70
71
|
import { GridCellEditor, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3 } from "@dxos/react-ui-grid";
|
|
71
72
|
|
|
@@ -73,7 +74,7 @@ import { GridCellEditor, editorKeys, parseCellIndex as parseCellIndex2, useGridC
|
|
|
73
74
|
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
74
75
|
import React from "react";
|
|
75
76
|
import { useGridContext } from "@dxos/react-ui-grid";
|
|
76
|
-
var CellValidationMessage = ({ validationError, variant = "error"
|
|
77
|
+
var CellValidationMessage = ({ __gridScope, validationError, variant = "error" }) => {
|
|
77
78
|
var _effect = _useSignals();
|
|
78
79
|
try {
|
|
79
80
|
const { editing, editBox: box } = useGridContext("GridSheetCellEditor", __gridScope);
|
|
@@ -102,15 +103,14 @@ var CellValidationMessage = ({ validationError, variant = "error", __gridScope }
|
|
|
102
103
|
|
|
103
104
|
// src/components/TableCellEditor/FormCellEditor.tsx
|
|
104
105
|
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 {
|
|
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
|
-
import { Form } from "@dxos/react-ui-form";
|
|
113
|
+
import { Form, omitId } from "@dxos/react-ui-form";
|
|
114
114
|
import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
|
|
115
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";
|
|
@@ -120,53 +120,74 @@ var createOptionLabel = [
|
|
|
120
120
|
ns: translationKey
|
|
121
121
|
}
|
|
122
122
|
];
|
|
123
|
-
var FormCellEditor = ({
|
|
123
|
+
var FormCellEditor = ({ __gridScope, schema, model, fieldProjection, onSave, onCreate, ...formProps }) => {
|
|
124
124
|
var _effect = _useSignals2();
|
|
125
125
|
try {
|
|
126
|
-
const { editing: contextEditing, setEditing, id: gridId } = useGridContext2("ArrayEditor", __gridScope);
|
|
127
|
-
const [editing, setLocalEditing] = useState(false);
|
|
128
126
|
const anchorRef = useRef(null);
|
|
129
|
-
const
|
|
127
|
+
const { id: _gridId, editing: contextEditing, setEditing } = useGridContext2("ArrayEditor", __gridScope);
|
|
128
|
+
const [editing, setLocalEditing] = useState(false);
|
|
129
|
+
useEffect(() => {
|
|
130
|
+
if (contextEditing && contextEditing.cellElement) {
|
|
131
|
+
anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
|
|
132
|
+
setLocalEditing(true);
|
|
133
|
+
} else {
|
|
134
|
+
anchorRef.current = null;
|
|
135
|
+
setLocalEditing(false);
|
|
136
|
+
}
|
|
137
|
+
}, [
|
|
138
|
+
contextEditing
|
|
139
|
+
]);
|
|
140
|
+
const narrowedSchema = useMemo(() => {
|
|
141
|
+
if (!schema) {
|
|
142
|
+
return void 0;
|
|
143
|
+
}
|
|
144
|
+
return narrowSchema(schema, [
|
|
145
|
+
fieldProjection.field.path
|
|
146
|
+
]);
|
|
147
|
+
}, [
|
|
148
|
+
JSON.stringify(schema),
|
|
149
|
+
fieldProjection.field.path
|
|
150
|
+
]);
|
|
151
|
+
const getSchema = useCallback(({ typename }) => {
|
|
130
152
|
const space = getSpace(model.view);
|
|
131
153
|
invariant(space, void 0, {
|
|
132
154
|
F: __dxlog_file,
|
|
133
|
-
L:
|
|
155
|
+
L: 73,
|
|
134
156
|
S: void 0,
|
|
135
157
|
A: [
|
|
136
158
|
"space",
|
|
137
159
|
""
|
|
138
160
|
]
|
|
139
161
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
}
|
|
162
|
+
const schema2 = space.db.schemaRegistry.query({
|
|
163
|
+
typename,
|
|
164
|
+
location: [
|
|
165
|
+
"database",
|
|
166
|
+
"runtime"
|
|
167
|
+
]
|
|
168
|
+
}).runSync()[0];
|
|
147
169
|
return {
|
|
148
170
|
space,
|
|
149
171
|
schema: schema2
|
|
150
172
|
};
|
|
151
173
|
}, [
|
|
152
|
-
client,
|
|
153
174
|
model
|
|
154
175
|
]);
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
dxn: Obj.getDXN(obj),
|
|
162
|
-
label: getValue(obj, fieldProjection.field.referencePath) || obj.id.toString()
|
|
163
|
-
};
|
|
164
|
-
}).filter(isTruthy);
|
|
176
|
+
const refSchema = useMemo(() => {
|
|
177
|
+
if (fieldProjection.props.format === Format.TypeFormat.Ref && fieldProjection.props.referenceSchema) {
|
|
178
|
+
const { schema: schema2 } = getSchema({
|
|
179
|
+
typename: fieldProjection.props.referenceSchema
|
|
180
|
+
});
|
|
181
|
+
return schema2;
|
|
165
182
|
}
|
|
166
|
-
return
|
|
183
|
+
return null;
|
|
167
184
|
}, [
|
|
168
|
-
|
|
169
|
-
|
|
185
|
+
fieldProjection.props.format,
|
|
186
|
+
fieldProjection.props.referenceSchema,
|
|
187
|
+
getSchema
|
|
188
|
+
]);
|
|
189
|
+
const createSchema = useMemo(() => refSchema ? omitId(refSchema) : null, [
|
|
190
|
+
refSchema
|
|
170
191
|
]);
|
|
171
192
|
const originalRow = useMemo(() => {
|
|
172
193
|
if (model && contextEditing) {
|
|
@@ -175,7 +196,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
175
196
|
const draftRow = model.draftRows.value[cell.row];
|
|
176
197
|
invariant(draftRow, void 0, {
|
|
177
198
|
F: __dxlog_file,
|
|
178
|
-
L:
|
|
199
|
+
L: 97,
|
|
179
200
|
S: void 0,
|
|
180
201
|
A: [
|
|
181
202
|
"draftRow",
|
|
@@ -187,7 +208,7 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
187
208
|
const row = model.getRowAt(cell.row);
|
|
188
209
|
invariant(row, void 0, {
|
|
189
210
|
F: __dxlog_file,
|
|
190
|
-
L:
|
|
211
|
+
L: 101,
|
|
191
212
|
S: void 0,
|
|
192
213
|
A: [
|
|
193
214
|
"row",
|
|
@@ -202,6 +223,16 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
202
223
|
model,
|
|
203
224
|
contextEditing
|
|
204
225
|
]);
|
|
226
|
+
const formValues = useMemo(() => originalRow ? getSnapshot(originalRow) : {}, [
|
|
227
|
+
originalRow
|
|
228
|
+
]);
|
|
229
|
+
const handleOpenChange = useCallback((nextOpen) => {
|
|
230
|
+
if (nextOpen === false) {
|
|
231
|
+
setEditing(null);
|
|
232
|
+
onSave?.();
|
|
233
|
+
}
|
|
234
|
+
setLocalEditing(nextOpen);
|
|
235
|
+
}, []);
|
|
205
236
|
const handleSave = useCallback((values) => {
|
|
206
237
|
const path = fieldProjection.field.path;
|
|
207
238
|
const value = getDeep(values, [
|
|
@@ -220,56 +251,6 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
220
251
|
contextEditing,
|
|
221
252
|
originalRow
|
|
222
253
|
]);
|
|
223
|
-
useEffect(() => {
|
|
224
|
-
if (contextEditing && contextEditing.cellElement) {
|
|
225
|
-
anchorRef.current = contextEditing.cellElement.querySelector(".dx-grid__cell__content");
|
|
226
|
-
setLocalEditing(true);
|
|
227
|
-
} else {
|
|
228
|
-
anchorRef.current = null;
|
|
229
|
-
setLocalEditing(false);
|
|
230
|
-
}
|
|
231
|
-
}, [
|
|
232
|
-
contextEditing
|
|
233
|
-
]);
|
|
234
|
-
const narrowedSchema = useMemo(() => {
|
|
235
|
-
if (!schema) {
|
|
236
|
-
return void 0;
|
|
237
|
-
}
|
|
238
|
-
return narrowSchema(schema, [
|
|
239
|
-
fieldProjection.field.path
|
|
240
|
-
]);
|
|
241
|
-
}, [
|
|
242
|
-
JSON.stringify(schema),
|
|
243
|
-
fieldProjection.field.path
|
|
244
|
-
]);
|
|
245
|
-
const formValues = useMemo(() => originalRow ? getSnapshot(originalRow) : {}, [
|
|
246
|
-
originalRow
|
|
247
|
-
]);
|
|
248
|
-
const handleOpenChange = useCallback((nextOpen) => {
|
|
249
|
-
if (nextOpen === false) {
|
|
250
|
-
setEditing(null);
|
|
251
|
-
onSave?.();
|
|
252
|
-
}
|
|
253
|
-
setLocalEditing(nextOpen);
|
|
254
|
-
}, []);
|
|
255
|
-
const refSchema = useMemo(() => {
|
|
256
|
-
if (fieldProjection.props.format === FormatEnum.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
254
|
const handleCreate = useCallback((values) => {
|
|
274
255
|
if (refSchema && onCreate) {
|
|
275
256
|
const objectWithId = onCreate(refSchema, values);
|
|
@@ -293,6 +274,23 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
293
274
|
refSchema,
|
|
294
275
|
onCreate
|
|
295
276
|
]);
|
|
277
|
+
const handleQueryRefOptions = useCallback(async ({ typename }) => {
|
|
278
|
+
const { schema: schema2, space } = getSchema({
|
|
279
|
+
typename
|
|
280
|
+
});
|
|
281
|
+
if (model && schema2 && space) {
|
|
282
|
+
const objects = await space.db.query(Filter.type(schema2)).run();
|
|
283
|
+
return objects.map((obj) => {
|
|
284
|
+
return {
|
|
285
|
+
dxn: Obj.getDXN(obj),
|
|
286
|
+
label: getValue(obj, fieldProjection.field.referencePath) || obj.id.toString()
|
|
287
|
+
};
|
|
288
|
+
}).filter(isTruthy);
|
|
289
|
+
}
|
|
290
|
+
return [];
|
|
291
|
+
}, [
|
|
292
|
+
model
|
|
293
|
+
]);
|
|
296
294
|
if (!editing) {
|
|
297
295
|
return null;
|
|
298
296
|
}
|
|
@@ -304,21 +302,21 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
304
302
|
}), /* @__PURE__ */ React2.createElement(Popover.Portal, null, /* @__PURE__ */ React2.createElement(Popover.Content, {
|
|
305
303
|
tabIndex: -1,
|
|
306
304
|
classNames: "popover-card-width density-fine"
|
|
307
|
-
}, /* @__PURE__ */ React2.createElement(Popover.Arrow, null), /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(Form, {
|
|
305
|
+
}, /* @__PURE__ */ React2.createElement(Popover.Arrow, null), /* @__PURE__ */ React2.createElement(Popover.Viewport, null, /* @__PURE__ */ React2.createElement(Form.Root, {
|
|
306
|
+
...formProps,
|
|
308
307
|
autoFocus: true,
|
|
309
|
-
values: formValues,
|
|
310
308
|
schema: narrowedSchema,
|
|
309
|
+
values: formValues,
|
|
311
310
|
onSave: handleSave,
|
|
312
|
-
...formProps,
|
|
313
311
|
onQueryRefOptions: handleQueryRefOptions,
|
|
314
312
|
...createSchema && {
|
|
315
|
-
onCreate: handleCreate,
|
|
316
313
|
createSchema,
|
|
317
314
|
createInitialValuePath: fieldProjection.field.referencePath,
|
|
318
315
|
createOptionIcon: "ph--plus--regular",
|
|
319
|
-
createOptionLabel
|
|
316
|
+
createOptionLabel,
|
|
317
|
+
onCreate: handleCreate
|
|
320
318
|
}
|
|
321
|
-
})))));
|
|
319
|
+
}, /* @__PURE__ */ React2.createElement(Form.Viewport, null, /* @__PURE__ */ React2.createElement(Form.Content, null, /* @__PURE__ */ React2.createElement(Form.FieldSet, null), /* @__PURE__ */ React2.createElement(Form.Actions, null))))))));
|
|
322
320
|
} finally {
|
|
323
321
|
_effect.f();
|
|
324
322
|
}
|
|
@@ -326,8 +324,12 @@ var FormCellEditor = ({ fieldProjection, model, schema, onSave, client, modals,
|
|
|
326
324
|
|
|
327
325
|
// src/components/TableCellEditor/TableCellEditor.tsx
|
|
328
326
|
var __dxlog_file2 = "/__w/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
|
|
329
|
-
var
|
|
330
|
-
|
|
327
|
+
var editorSlots = {
|
|
328
|
+
scroll: {
|
|
329
|
+
className: "!plb-[--dx-grid-cell-editor-padding-block]"
|
|
330
|
+
}
|
|
331
|
+
};
|
|
332
|
+
var TableValueEditor = ({ __gridScope, schema, model, modals, onFocus, onSave, onCreate }) => {
|
|
331
333
|
var _effect = _useSignals3();
|
|
332
334
|
try {
|
|
333
335
|
const { editing } = useGridContext3("TableValueEditor", __gridScope);
|
|
@@ -340,7 +342,7 @@ var TableValueEditor = ({ model, modals, schema, onFocus, onSave, onCreate, clie
|
|
|
340
342
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
341
343
|
invariant2(fieldProjection2, void 0, {
|
|
342
344
|
F: __dxlog_file2,
|
|
343
|
-
L:
|
|
345
|
+
L: 73,
|
|
344
346
|
S: void 0,
|
|
345
347
|
A: [
|
|
346
348
|
"fieldProjection",
|
|
@@ -352,16 +354,15 @@ var TableValueEditor = ({ model, modals, schema, onFocus, onSave, onCreate, clie
|
|
|
352
354
|
model,
|
|
353
355
|
editing
|
|
354
356
|
]);
|
|
355
|
-
if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format ===
|
|
357
|
+
if (fieldProjection?.props.type === TypeEnum.Array || fieldProjection?.props.format === Format2.TypeFormat.SingleSelect || fieldProjection?.props.format === Format2.TypeFormat.Ref) {
|
|
356
358
|
return /* @__PURE__ */ React3.createElement(FormCellEditor, {
|
|
357
|
-
fieldProjection,
|
|
358
|
-
model,
|
|
359
|
-
schema,
|
|
360
359
|
__gridScope,
|
|
360
|
+
schema,
|
|
361
|
+
model,
|
|
362
|
+
fieldProjection,
|
|
363
|
+
modals,
|
|
361
364
|
onSave,
|
|
362
|
-
onCreate
|
|
363
|
-
client,
|
|
364
|
-
modals
|
|
365
|
+
onCreate
|
|
365
366
|
});
|
|
366
367
|
}
|
|
367
368
|
return /* @__PURE__ */ React3.createElement(TableCellEditor, {
|
|
@@ -375,12 +376,7 @@ var TableValueEditor = ({ model, modals, schema, onFocus, onSave, onCreate, clie
|
|
|
375
376
|
_effect.f();
|
|
376
377
|
}
|
|
377
378
|
};
|
|
378
|
-
var
|
|
379
|
-
scroll: {
|
|
380
|
-
className: "!plb-[--dx-grid-cell-editor-padding-block]"
|
|
381
|
-
}
|
|
382
|
-
};
|
|
383
|
-
var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
379
|
+
var TableCellEditor = ({ __gridScope, model, modals, onFocus, onSave }) => {
|
|
384
380
|
var _effect = _useSignals3();
|
|
385
381
|
try {
|
|
386
382
|
const { editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
|
|
@@ -396,7 +392,7 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
396
392
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
397
393
|
invariant2(fieldProjection2, void 0, {
|
|
398
394
|
F: __dxlog_file2,
|
|
399
|
-
L:
|
|
395
|
+
L: 120,
|
|
400
396
|
S: void 0,
|
|
401
397
|
A: [
|
|
402
398
|
"fieldProjection",
|
|
@@ -421,7 +417,7 @@ var TableCellEditor = ({ model, modals, onFocus, onSave, __gridScope }) => {
|
|
|
421
417
|
setEditing(null);
|
|
422
418
|
onSave?.();
|
|
423
419
|
} else {
|
|
424
|
-
setValidationError(
|
|
420
|
+
setValidationError(validationResult.error);
|
|
425
421
|
setValidationVariant("error");
|
|
426
422
|
}
|
|
427
423
|
}, [
|
|
@@ -748,19 +744,13 @@ var TableRoot = ({ children, role = "article" }) => {
|
|
|
748
744
|
_effect.f();
|
|
749
745
|
}
|
|
750
746
|
};
|
|
751
|
-
var
|
|
747
|
+
var TableMainInner = ({ schema, model, presentation, ignoreAttention, onCreate, onRowClick, testId }, forwardedRef) => {
|
|
752
748
|
var _effect = _useSignals7();
|
|
753
749
|
try {
|
|
754
750
|
const [dxGrid, setDxGrid] = useState4(null);
|
|
755
751
|
const { hasAttention } = useAttention(model?.id ?? "table");
|
|
756
752
|
const modals = useMemo4(() => new ModalController(), []);
|
|
757
753
|
const draftRowCount = model?.getDraftRowCount() ?? 0;
|
|
758
|
-
const handleSave = useCallback4(() => {
|
|
759
|
-
dxGrid?.updateCells(true);
|
|
760
|
-
dxGrid?.requestUpdate();
|
|
761
|
-
}, [
|
|
762
|
-
dxGrid
|
|
763
|
-
]);
|
|
764
754
|
const frozen = useMemo4(() => {
|
|
765
755
|
const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
|
|
766
756
|
return {
|
|
@@ -777,13 +767,21 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
777
767
|
presentation
|
|
778
768
|
]);
|
|
779
769
|
useEffect3(() => {
|
|
780
|
-
|
|
770
|
+
const fieldId = model?.projection?.fields?.[0]?.id;
|
|
771
|
+
if (fieldId) {
|
|
772
|
+
model.sorting.setSort(fieldId, "asc");
|
|
773
|
+
}
|
|
774
|
+
}, [
|
|
775
|
+
model
|
|
776
|
+
]);
|
|
777
|
+
useEffect3(() => {
|
|
778
|
+
if (!dxGrid || !presentation) {
|
|
781
779
|
return;
|
|
782
780
|
}
|
|
783
781
|
dxGrid.getCells = getCells;
|
|
784
782
|
}, [
|
|
785
|
-
presentation,
|
|
786
783
|
dxGrid,
|
|
784
|
+
presentation,
|
|
787
785
|
getCells
|
|
788
786
|
]);
|
|
789
787
|
const handleInsertRowResult = useCallback4((insertResult) => {
|
|
@@ -810,25 +808,11 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
810
808
|
model,
|
|
811
809
|
dxGrid
|
|
812
810
|
]);
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
}
|
|
817
|
-
return {
|
|
818
|
-
update: (cell) => {
|
|
819
|
-
if (cell) {
|
|
820
|
-
dxGrid.updateIfWithinBounds(cell, true);
|
|
821
|
-
} else {
|
|
822
|
-
dxGrid.updateCells(true);
|
|
823
|
-
dxGrid.requestUpdate();
|
|
824
|
-
}
|
|
825
|
-
},
|
|
826
|
-
handleInsertRowResult
|
|
827
|
-
};
|
|
811
|
+
const handleSave = useCallback4(() => {
|
|
812
|
+
dxGrid?.updateCells(true);
|
|
813
|
+
dxGrid?.requestUpdate();
|
|
828
814
|
}, [
|
|
829
|
-
|
|
830
|
-
dxGrid,
|
|
831
|
-
model
|
|
815
|
+
dxGrid
|
|
832
816
|
]);
|
|
833
817
|
const handleSaveDraftRow = useCallback4((rowIndex = 0) => {
|
|
834
818
|
if (model && dxGrid) {
|
|
@@ -1035,6 +1019,26 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1035
1019
|
model,
|
|
1036
1020
|
dxGrid
|
|
1037
1021
|
]);
|
|
1022
|
+
useImperativeHandle(forwardedRef, () => {
|
|
1023
|
+
if (!dxGrid || !presentation) {
|
|
1024
|
+
return {};
|
|
1025
|
+
}
|
|
1026
|
+
return {
|
|
1027
|
+
update: (cell) => {
|
|
1028
|
+
if (cell) {
|
|
1029
|
+
dxGrid.updateIfWithinBounds(cell, true);
|
|
1030
|
+
} else {
|
|
1031
|
+
dxGrid.updateCells(true);
|
|
1032
|
+
dxGrid.requestUpdate();
|
|
1033
|
+
}
|
|
1034
|
+
},
|
|
1035
|
+
handleInsertRowResult
|
|
1036
|
+
};
|
|
1037
|
+
}, [
|
|
1038
|
+
dxGrid,
|
|
1039
|
+
model,
|
|
1040
|
+
presentation
|
|
1041
|
+
]);
|
|
1038
1042
|
if (!model || !modals) {
|
|
1039
1043
|
return /* @__PURE__ */ React7.createElement("span", {
|
|
1040
1044
|
role: "none",
|
|
@@ -1049,8 +1053,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1049
1053
|
schema,
|
|
1050
1054
|
onFocus: handleFocus,
|
|
1051
1055
|
onSave: handleSave,
|
|
1052
|
-
onCreate
|
|
1053
|
-
client
|
|
1056
|
+
onCreate
|
|
1054
1057
|
}), /* @__PURE__ */ React7.createElement(Grid.Content, {
|
|
1055
1058
|
className: mx("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
|
|
1056
1059
|
frozen,
|
|
@@ -1082,7 +1085,8 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1082
1085
|
} finally {
|
|
1083
1086
|
_effect.f();
|
|
1084
1087
|
}
|
|
1085
|
-
}
|
|
1088
|
+
};
|
|
1089
|
+
var TableMain = /* @__PURE__ */ forwardRef(TableMainInner);
|
|
1086
1090
|
var Table = {
|
|
1087
1091
|
Root: TableRoot,
|
|
1088
1092
|
Main: TableMain
|
|
@@ -1093,7 +1097,8 @@ import { useSignals as _useSignals8 } from "@preact-signals/safe-react/tracking"
|
|
|
1093
1097
|
import React8, { useCallback as useCallback5, useMemo as useMemo5, useRef as useRef3 } from "react";
|
|
1094
1098
|
import { useDefaultValue } from "@dxos/react-ui";
|
|
1095
1099
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
1096
|
-
|
|
1100
|
+
import { ProjectionModel } from "@dxos/schema";
|
|
1101
|
+
var DynamicTable = ({ classNames, schema, name = "example.com/dynamic-table", rows, properties, jsonSchema: _jsonSchema, rowActions, onRowClick, onRowAction, ...props }) => {
|
|
1097
1102
|
var _effect = _useSignals8();
|
|
1098
1103
|
try {
|
|
1099
1104
|
const { jsonSchema } = useMemo5(() => getBaseSchema({
|
|
@@ -1107,7 +1112,7 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
1107
1112
|
_jsonSchema,
|
|
1108
1113
|
schema
|
|
1109
1114
|
]);
|
|
1110
|
-
const {
|
|
1115
|
+
const { object, projection } = useMemo5(() => makeDynamicTable({
|
|
1111
1116
|
jsonSchema,
|
|
1112
1117
|
properties
|
|
1113
1118
|
}), [
|
|
@@ -1127,11 +1132,20 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
1127
1132
|
},
|
|
1128
1133
|
dataEditable: false
|
|
1129
1134
|
}));
|
|
1135
|
+
const projectionModel = useMemo5(() => {
|
|
1136
|
+
if (jsonSchema && projection) {
|
|
1137
|
+
const model2 = new ProjectionModel(jsonSchema, projection);
|
|
1138
|
+
model2.normalizeView();
|
|
1139
|
+
return model2;
|
|
1140
|
+
}
|
|
1141
|
+
}, [
|
|
1142
|
+
jsonSchema,
|
|
1143
|
+
projection
|
|
1144
|
+
]);
|
|
1130
1145
|
const model = useTableModel({
|
|
1131
1146
|
rows,
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
projection,
|
|
1147
|
+
object,
|
|
1148
|
+
projection: projectionModel,
|
|
1135
1149
|
features,
|
|
1136
1150
|
rowActions,
|
|
1137
1151
|
onCellUpdate: handleCellUpdate,
|
|
@@ -1177,7 +1191,7 @@ var createTableToolbarActions = ({ state, onAdd, onSave, customActions }) => Ato
|
|
|
1177
1191
|
type: "add-row",
|
|
1178
1192
|
icon: "ph--plus--regular",
|
|
1179
1193
|
label: [
|
|
1180
|
-
"add row",
|
|
1194
|
+
"add row label",
|
|
1181
1195
|
{
|
|
1182
1196
|
ns: translationKey
|
|
1183
1197
|
}
|
|
@@ -1266,6 +1280,7 @@ export {
|
|
|
1266
1280
|
touch,
|
|
1267
1281
|
translations,
|
|
1268
1282
|
useAddRow,
|
|
1283
|
+
useProjectionModel,
|
|
1269
1284
|
useTableModel
|
|
1270
1285
|
};
|
|
1271
1286
|
//# sourceMappingURL=index.mjs.map
|