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