@dxos/react-ui-table 0.8.2-main.f11618f → 0.8.2-main.fbd8ed0
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-YWNRUF4J.mjs → chunk-PFFO5LYM.mjs} +7 -6
- package/dist/lib/browser/chunk-PFFO5LYM.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +290 -105
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/{chunk-TGG6OZ54.cjs → chunk-VREQOYRW.cjs} +9 -8
- package/dist/lib/node/chunk-VREQOYRW.cjs.map +7 -0
- package/dist/lib/node/index.cjs +263 -81
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node/types/index.cjs +3 -3
- package/dist/lib/node/types/index.cjs.map +1 -1
- package/dist/lib/node-esm/{chunk-KKLP54L3.mjs → chunk-34JG3SDI.mjs} +7 -6
- package/dist/lib/node-esm/chunk-34JG3SDI.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +290 -105
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/lib/node-esm/types/index.mjs +1 -1
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -1
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.d.ts +3 -4
- package/dist/types/src/components/Table/DynamicTable.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 +2 -0
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +1 -0
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts +13 -0
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +3 -0
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/extension.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 +39 -39
- package/dist/types/src/components/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/modal-controller.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- 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/types/table.d.ts +44 -43
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +4 -3
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/index.d.ts +1 -0
- package/dist/types/src/util/index.d.ts.map +1 -1
- package/dist/types/src/util/schema.d.ts +12 -0
- package/dist/types/src/util/schema.d.ts.map +1 -0
- package/dist/types/src/util/signals.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/src/util/table.d.ts +2 -2
- package/dist/types/src/util/table.d.ts.map +1 -1
- package/dist/types/src/util/tag.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +34 -33
- package/src/components/Table/CreateRefPanel.tsx +3 -3
- package/src/components/Table/DynamicTable.stories.tsx +2 -2
- package/src/components/Table/DynamicTable.tsx +4 -5
- package/src/components/Table/Table.stories.tsx +65 -19
- package/src/components/Table/Table.tsx +8 -5
- package/src/components/Table/relations.stories.tsx +16 -18
- package/src/components/TableCellEditor/FormCellEditor.tsx +94 -0
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +8 -7
- package/src/components/TableCellEditor/TableCellEditor.tsx +45 -4
- package/src/components/TableToolbar/TableToolbar.tsx +10 -11
- package/src/components/testing.ts +7 -6
- package/src/model/table-model.test.ts +4 -3
- package/src/model/table-presentation.test.ts +4 -3
- package/src/model/table-presentation.ts +52 -6
- package/src/types/table.ts +15 -7
- package/src/util/dynamic-table.ts +7 -4
- package/src/util/index.ts +1 -0
- package/src/util/schema.ts +36 -0
- package/src/util/table.ts +11 -10
- package/dist/lib/browser/chunk-YWNRUF4J.mjs.map +0 -7
- package/dist/lib/node/chunk-TGG6OZ54.cjs.map +0 -7
- package/dist/lib/node-esm/chunk-KKLP54L3.mjs.map +0 -7
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TableSchema,
|
|
3
3
|
TableType
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-PFFO5LYM.mjs";
|
|
5
5
|
|
|
6
6
|
// packages/ui/react-ui-table/src/translations.ts
|
|
7
7
|
var translationKey = "table";
|
|
@@ -36,9 +36,9 @@ var translations_default = [
|
|
|
36
36
|
];
|
|
37
37
|
|
|
38
38
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
39
|
-
import
|
|
39
|
+
import React7, { forwardRef, useCallback as useCallback5, useImperativeHandle, useState as useState2, useMemo as useMemo5, useEffect as useEffect3 } from "react";
|
|
40
40
|
import { getValue as getValue4 } from "@dxos/echo-schema";
|
|
41
|
-
import { invariant as
|
|
41
|
+
import { invariant as invariant4 } from "@dxos/invariant";
|
|
42
42
|
import { Filter } from "@dxos/react-client/echo";
|
|
43
43
|
import { useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
44
44
|
import { useAttention } from "@dxos/react-ui-attention";
|
|
@@ -150,8 +150,8 @@ var ColumnSettings = ({ model, modals, onNewColumn }) => {
|
|
|
150
150
|
};
|
|
151
151
|
|
|
152
152
|
// packages/ui/react-ui-table/src/components/Table/CreateRefPanel.tsx
|
|
153
|
+
import { Schema } from "effect";
|
|
153
154
|
import React3, { useCallback as useCallback2, useMemo as useMemo2 } from "react";
|
|
154
|
-
import { S } from "@dxos/echo-schema";
|
|
155
155
|
import { live } from "@dxos/react-client/echo";
|
|
156
156
|
import { Popover } from "@dxos/react-ui";
|
|
157
157
|
import { Form } from "@dxos/react-ui-form";
|
|
@@ -168,7 +168,7 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
|
168
168
|
typename: state.typename
|
|
169
169
|
}).runSync();
|
|
170
170
|
if (schema2) {
|
|
171
|
-
const omit =
|
|
171
|
+
const omit = Schema.omit("id");
|
|
172
172
|
return omit(schema2);
|
|
173
173
|
}
|
|
174
174
|
}, [
|
|
@@ -257,7 +257,7 @@ import { computed as computed3, effect as effect2, signal as signal3 } from "@pr
|
|
|
257
257
|
import { Resource as Resource2 } from "@dxos/context";
|
|
258
258
|
import { FormatEnum as FormatEnum3, getValue as getValue2, setValue } from "@dxos/echo-schema";
|
|
259
259
|
import { invariant } from "@dxos/invariant";
|
|
260
|
-
import { isLiveObject, makeRef as
|
|
260
|
+
import { isLiveObject, makeRef as makeRef2 } from "@dxos/live-object";
|
|
261
261
|
import { formatForEditing, parseValue } from "@dxos/react-ui-form";
|
|
262
262
|
|
|
263
263
|
// packages/ui/react-ui-table/src/model/selection-model.ts
|
|
@@ -265,9 +265,10 @@ import { computed, effect, signal } from "@preact/signals-core";
|
|
|
265
265
|
import { Resource } from "@dxos/context";
|
|
266
266
|
|
|
267
267
|
// packages/ui/react-ui-table/src/util/dynamic-table.ts
|
|
268
|
+
import { getTypename, toJsonSchema } from "@dxos/echo-schema";
|
|
268
269
|
import { live as live2, makeRef } from "@dxos/live-object";
|
|
269
270
|
import { createView, getSchemaFromPropertyDefinitions, ViewProjection } from "@dxos/schema";
|
|
270
|
-
var
|
|
271
|
+
var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
271
272
|
if (typename && properties) {
|
|
272
273
|
const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
|
|
273
274
|
return {
|
|
@@ -276,8 +277,8 @@ var getBaseSchems = ({ typename, properties, jsonSchema, schema }) => {
|
|
|
276
277
|
};
|
|
277
278
|
} else if (schema) {
|
|
278
279
|
return {
|
|
279
|
-
typename: schema
|
|
280
|
-
jsonSchema: schema
|
|
280
|
+
typename: getTypename(schema),
|
|
281
|
+
jsonSchema: toJsonSchema(schema)
|
|
281
282
|
};
|
|
282
283
|
} else if (typename && jsonSchema) {
|
|
283
284
|
return {
|
|
@@ -344,9 +345,10 @@ var setProperties = (view, projection, properties) => {
|
|
|
344
345
|
var touch = (value) => value;
|
|
345
346
|
|
|
346
347
|
// packages/ui/react-ui-table/src/util/table.ts
|
|
347
|
-
import {
|
|
348
|
+
import { Schema as Schema2, SchemaAST } from "effect";
|
|
349
|
+
import { Format, FormatEnum, Ref, TypedObject, TypeEnum } from "@dxos/echo-schema";
|
|
348
350
|
import { PublicKey } from "@dxos/react-client";
|
|
349
|
-
import { live as live3
|
|
351
|
+
import { live as live3 } from "@dxos/react-client/echo";
|
|
350
352
|
import { createFieldId, createView as createView2, getSchemaProperties, ViewProjection as ViewProjection2 } from "@dxos/schema";
|
|
351
353
|
var initializeTable = async ({ client, space, table, typename, initialRow = true }) => {
|
|
352
354
|
if (typename) {
|
|
@@ -355,7 +357,7 @@ var initializeTable = async ({ client, space, table, typename, initialRow = true
|
|
|
355
357
|
throw new Error(`Schema not found: ${typename}`);
|
|
356
358
|
}
|
|
357
359
|
const fields = getSchemaProperties(schema.ast).map((prop) => prop.name);
|
|
358
|
-
table.view =
|
|
360
|
+
table.view = Ref.make(createView2({
|
|
359
361
|
// TODO(ZaymonFC): Don't hardcode name?
|
|
360
362
|
name: "View",
|
|
361
363
|
typename: schema.typename,
|
|
@@ -368,7 +370,7 @@ var initializeTable = async ({ client, space, table, typename, initialRow = true
|
|
|
368
370
|
ContactSchema
|
|
369
371
|
]);
|
|
370
372
|
const fields = ContactFields;
|
|
371
|
-
table.view =
|
|
373
|
+
table.view = Ref.make(createView2({
|
|
372
374
|
name: "View",
|
|
373
375
|
typename: schema.typename,
|
|
374
376
|
jsonSchema: schema.jsonSchema,
|
|
@@ -385,13 +387,13 @@ var ContactSchema = TypedObject({
|
|
|
385
387
|
typename: `example.com/type/${PublicKey.random().truncate()}`,
|
|
386
388
|
version: "0.1.0"
|
|
387
389
|
})({
|
|
388
|
-
name:
|
|
389
|
-
[
|
|
390
|
+
name: Schema2.optional(Schema2.String).annotations({
|
|
391
|
+
[SchemaAST.TitleAnnotationId]: "Name"
|
|
390
392
|
}),
|
|
391
|
-
active:
|
|
392
|
-
email:
|
|
393
|
-
salary:
|
|
394
|
-
[
|
|
393
|
+
active: Schema2.optional(Schema2.Boolean),
|
|
394
|
+
email: Schema2.optional(Format.Email),
|
|
395
|
+
salary: Schema2.optional(Format.Currency()).annotations({
|
|
396
|
+
[SchemaAST.TitleAnnotationId]: "Salary"
|
|
395
397
|
})
|
|
396
398
|
});
|
|
397
399
|
var ContactFields = [
|
|
@@ -582,6 +584,21 @@ var tableControls = {
|
|
|
582
584
|
}
|
|
583
585
|
};
|
|
584
586
|
|
|
587
|
+
// packages/ui/react-ui-table/src/util/schema.ts
|
|
588
|
+
import { Schema as Schema3 } from "effect";
|
|
589
|
+
import { isTypeLiteral, TypeLiteral } from "effect/SchemaAST";
|
|
590
|
+
var narrowSchema = (schema, paths) => {
|
|
591
|
+
const ast = schema?.ast;
|
|
592
|
+
if (isTypeLiteral(ast)) {
|
|
593
|
+
const propertySignatures = ast.propertySignatures.filter((signature) => paths.includes(signature.name.toString()));
|
|
594
|
+
if (propertySignatures.length > 0) {
|
|
595
|
+
const narrowType = new TypeLiteral(propertySignatures, []);
|
|
596
|
+
return Schema3.make(narrowType);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return void 0;
|
|
600
|
+
};
|
|
601
|
+
|
|
585
602
|
// packages/ui/react-ui-table/src/model/selection-model.ts
|
|
586
603
|
var SelectionModel = class extends Resource {
|
|
587
604
|
constructor(_rows, _selectionMode, _onSelectionChanged) {
|
|
@@ -950,7 +967,7 @@ var TableModel = class extends Resource2 {
|
|
|
950
967
|
switch (props.format) {
|
|
951
968
|
case FormatEnum3.Ref: {
|
|
952
969
|
if (isLiveObject(value)) {
|
|
953
|
-
setValue(this._rows.value[rowIdx], field.path,
|
|
970
|
+
setValue(this._rows.value[rowIdx], field.path, makeRef2(value));
|
|
954
971
|
}
|
|
955
972
|
break;
|
|
956
973
|
}
|
|
@@ -1274,7 +1291,8 @@ var ModalController = class {
|
|
|
1274
1291
|
|
|
1275
1292
|
// packages/ui/react-ui-table/src/model/table-presentation.ts
|
|
1276
1293
|
import { signal as signal5 } from "@preact/signals-core";
|
|
1277
|
-
import {
|
|
1294
|
+
import { isNotNullable } from "effect/Predicate";
|
|
1295
|
+
import { FormatEnum as FormatEnum4, getDXN, getValue as getValue3, TypeEnum as TypeEnum3 } from "@dxos/echo-schema";
|
|
1278
1296
|
import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
|
|
1279
1297
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
1280
1298
|
import { mx } from "@dxos/react-ui-theme";
|
|
@@ -1336,6 +1354,9 @@ var TablePresentation = class {
|
|
|
1336
1354
|
if (value == null) {
|
|
1337
1355
|
return "";
|
|
1338
1356
|
}
|
|
1357
|
+
if (props.type === "array") {
|
|
1358
|
+
return "";
|
|
1359
|
+
}
|
|
1339
1360
|
switch (props.format) {
|
|
1340
1361
|
case FormatEnum4.Boolean:
|
|
1341
1362
|
case FormatEnum4.SingleSelect:
|
|
@@ -1373,6 +1394,33 @@ var TablePresentation = class {
|
|
|
1373
1394
|
if (classes.length > 0) {
|
|
1374
1395
|
cell.className = mx(classes.flat());
|
|
1375
1396
|
}
|
|
1397
|
+
if (props.type === TypeEnum3.Array) {
|
|
1398
|
+
const targetArray = getValue3(obj, field.path);
|
|
1399
|
+
if (targetArray && Array.isArray(targetArray)) {
|
|
1400
|
+
const getLabel = (value) => {
|
|
1401
|
+
if (!value) {
|
|
1402
|
+
return void 0;
|
|
1403
|
+
}
|
|
1404
|
+
if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
|
|
1405
|
+
return String(value);
|
|
1406
|
+
}
|
|
1407
|
+
if (Array.isArray(value)) {
|
|
1408
|
+
return "Array";
|
|
1409
|
+
}
|
|
1410
|
+
if (typeof value === "object" && value.name) {
|
|
1411
|
+
return value.name;
|
|
1412
|
+
}
|
|
1413
|
+
if (typeof value === "object" && value.value) {
|
|
1414
|
+
return `${value.value}`;
|
|
1415
|
+
}
|
|
1416
|
+
return "Object";
|
|
1417
|
+
};
|
|
1418
|
+
const tags = targetArray.map(getLabel).filter(isNotNullable).map((title) => {
|
|
1419
|
+
return `<span class="dx-tag rounded-xl" data-hue="neutral">${title}</span>`;
|
|
1420
|
+
}).join("");
|
|
1421
|
+
cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
|
|
1422
|
+
}
|
|
1423
|
+
}
|
|
1376
1424
|
if (props.format === FormatEnum4.Ref && props.referenceSchema) {
|
|
1377
1425
|
const targetObj = getValue3(obj, field.path)?.target;
|
|
1378
1426
|
if (targetObj) {
|
|
@@ -1411,7 +1459,7 @@ var TablePresentation = class {
|
|
|
1411
1459
|
return null;
|
|
1412
1460
|
}).filter(Boolean).join(" ");
|
|
1413
1461
|
if (tags) {
|
|
1414
|
-
cell.accessoryHtml = tags
|
|
1462
|
+
cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1">${tags}</div>`;
|
|
1415
1463
|
}
|
|
1416
1464
|
}
|
|
1417
1465
|
}
|
|
@@ -1456,7 +1504,7 @@ var TablePresentation = class {
|
|
|
1456
1504
|
fieldId: field.id
|
|
1457
1505
|
})}
|
|
1458
1506
|
`,
|
|
1459
|
-
className: "!bg-
|
|
1507
|
+
className: "!bg-toolbarSurface"
|
|
1460
1508
|
};
|
|
1461
1509
|
}
|
|
1462
1510
|
return cells;
|
|
@@ -1507,7 +1555,7 @@ var TablePresentation = class {
|
|
|
1507
1555
|
col: 0,
|
|
1508
1556
|
row: 0
|
|
1509
1557
|
})]: {
|
|
1510
|
-
className: "!bg-
|
|
1558
|
+
className: "!bg-toolbarSurface",
|
|
1511
1559
|
readonly: true,
|
|
1512
1560
|
value: ""
|
|
1513
1561
|
}
|
|
@@ -1523,7 +1571,7 @@ var TablePresentation = class {
|
|
|
1523
1571
|
header: true,
|
|
1524
1572
|
checked: this.model.selection.allRowsSeleted.value
|
|
1525
1573
|
}),
|
|
1526
|
-
className: "!bg-
|
|
1574
|
+
className: "!bg-toolbarSurface",
|
|
1527
1575
|
readonly: true,
|
|
1528
1576
|
value: ""
|
|
1529
1577
|
}
|
|
@@ -1538,7 +1586,7 @@ var TablePresentation = class {
|
|
|
1538
1586
|
accessoryHtml: this.model.features.schemaEditable ? tableButtons.addColumn.render({
|
|
1539
1587
|
disabled: (this.model.view?.fields?.length ?? 0) >= VIEW_FIELD_LIMIT
|
|
1540
1588
|
}) : void 0,
|
|
1541
|
-
className: "!bg-
|
|
1589
|
+
className: "!bg-toolbarSurface",
|
|
1542
1590
|
readonly: true,
|
|
1543
1591
|
value: ""
|
|
1544
1592
|
}
|
|
@@ -1569,14 +1617,109 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
|
|
|
1569
1617
|
};
|
|
1570
1618
|
|
|
1571
1619
|
// packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
|
|
1572
|
-
import
|
|
1573
|
-
import { FormatEnum as FormatEnum5 } from "@dxos/echo-schema";
|
|
1574
|
-
import { invariant as
|
|
1620
|
+
import React6, { useCallback as useCallback4, useMemo as useMemo4, useRef as useRef2 } from "react";
|
|
1621
|
+
import { FormatEnum as FormatEnum5, TypeEnum as TypeEnum4 } from "@dxos/echo-schema";
|
|
1622
|
+
import { invariant as invariant3 } from "@dxos/invariant";
|
|
1575
1623
|
import { useThemeContext } from "@dxos/react-ui";
|
|
1576
1624
|
import { createMarkdownExtensions } from "@dxos/react-ui-editor";
|
|
1577
|
-
import { cellQuery, editorKeys, parseCellIndex, useGridContext as
|
|
1625
|
+
import { cellQuery, editorKeys, parseCellIndex as parseCellIndex2, useGridContext as useGridContext3, GridCellEditor } from "@dxos/react-ui-grid";
|
|
1578
1626
|
import { tagPickerExtension, createLinks } from "@dxos/react-ui-tag-picker";
|
|
1579
1627
|
|
|
1628
|
+
// packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx
|
|
1629
|
+
import React5, { useCallback as useCallback3, useEffect as useEffect2, useMemo as useMemo3, useRef } from "react";
|
|
1630
|
+
import { getSnapshot } from "@dxos/echo-schema";
|
|
1631
|
+
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1632
|
+
import { Popover as Popover2 } from "@dxos/react-ui";
|
|
1633
|
+
import { Form as Form2 } from "@dxos/react-ui-form";
|
|
1634
|
+
import { parseCellIndex, useGridContext as useGridContext2 } from "@dxos/react-ui-grid";
|
|
1635
|
+
import { getDeep, setDeep } from "@dxos/util";
|
|
1636
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/FormCellEditor.tsx";
|
|
1637
|
+
var FormCellEditor = ({ fieldProjection, model, schema, __gridScope }) => {
|
|
1638
|
+
const { editing, setEditing } = useGridContext2("ArrayEditor", __gridScope);
|
|
1639
|
+
const cellRef = useRef(null);
|
|
1640
|
+
useEffect2(() => {
|
|
1641
|
+
if (editing && editing.cellElement) {
|
|
1642
|
+
cellRef.current = editing.cellElement;
|
|
1643
|
+
}
|
|
1644
|
+
}, [
|
|
1645
|
+
editing?.cellElement
|
|
1646
|
+
]);
|
|
1647
|
+
const narrowedSchema = useMemo3(() => {
|
|
1648
|
+
if (!schema) {
|
|
1649
|
+
return void 0;
|
|
1650
|
+
}
|
|
1651
|
+
return narrowSchema(schema, [
|
|
1652
|
+
fieldProjection.field.path
|
|
1653
|
+
]);
|
|
1654
|
+
}, [
|
|
1655
|
+
JSON.stringify(schema),
|
|
1656
|
+
fieldProjection.field.path
|
|
1657
|
+
]);
|
|
1658
|
+
const originalRow = useMemo3(() => {
|
|
1659
|
+
if (model && editing) {
|
|
1660
|
+
const cell = parseCellIndex(editing.index);
|
|
1661
|
+
const row = model.getRowAt(cell.row);
|
|
1662
|
+
invariant2(row, void 0, {
|
|
1663
|
+
F: __dxlog_file3,
|
|
1664
|
+
L: 47,
|
|
1665
|
+
S: void 0,
|
|
1666
|
+
A: [
|
|
1667
|
+
"row",
|
|
1668
|
+
""
|
|
1669
|
+
]
|
|
1670
|
+
});
|
|
1671
|
+
return row;
|
|
1672
|
+
}
|
|
1673
|
+
return void 0;
|
|
1674
|
+
}, [
|
|
1675
|
+
model,
|
|
1676
|
+
editing
|
|
1677
|
+
]);
|
|
1678
|
+
const formValues = useMemo3(() => {
|
|
1679
|
+
if (originalRow) {
|
|
1680
|
+
return getSnapshot(originalRow);
|
|
1681
|
+
}
|
|
1682
|
+
}, [
|
|
1683
|
+
originalRow
|
|
1684
|
+
]);
|
|
1685
|
+
const handleSave = useCallback3((values) => {
|
|
1686
|
+
const path = fieldProjection.field.path;
|
|
1687
|
+
const value = getDeep(values, [
|
|
1688
|
+
path
|
|
1689
|
+
]);
|
|
1690
|
+
setDeep(originalRow, [
|
|
1691
|
+
path
|
|
1692
|
+
], value);
|
|
1693
|
+
setEditing(null);
|
|
1694
|
+
}, [
|
|
1695
|
+
fieldProjection.field.path,
|
|
1696
|
+
originalRow
|
|
1697
|
+
]);
|
|
1698
|
+
const handleOpenChange = useCallback3((nextOpen) => {
|
|
1699
|
+
if (nextOpen === false) {
|
|
1700
|
+
setEditing(null);
|
|
1701
|
+
}
|
|
1702
|
+
}, [
|
|
1703
|
+
setEditing
|
|
1704
|
+
]);
|
|
1705
|
+
if (!editing) {
|
|
1706
|
+
return null;
|
|
1707
|
+
}
|
|
1708
|
+
return /* @__PURE__ */ React5.createElement(Popover2.Root, {
|
|
1709
|
+
open: editing !== null,
|
|
1710
|
+
onOpenChange: handleOpenChange
|
|
1711
|
+
}, /* @__PURE__ */ React5.createElement(Popover2.VirtualTrigger, {
|
|
1712
|
+
virtualRef: cellRef
|
|
1713
|
+
}), /* @__PURE__ */ React5.createElement(Popover2.Content, {
|
|
1714
|
+
tabIndex: -1,
|
|
1715
|
+
classNames: "popover-consistent-width"
|
|
1716
|
+
}, /* @__PURE__ */ React5.createElement(Popover2.Arrow, null), /* @__PURE__ */ React5.createElement(Form2, {
|
|
1717
|
+
values: formValues,
|
|
1718
|
+
schema: narrowedSchema,
|
|
1719
|
+
onSave: handleSave
|
|
1720
|
+
})));
|
|
1721
|
+
};
|
|
1722
|
+
|
|
1580
1723
|
// packages/ui/react-ui-table/src/components/TableCellEditor/extension.ts
|
|
1581
1724
|
import { autocompletion, pickedCompletion } from "@codemirror/autocomplete";
|
|
1582
1725
|
import { EditorView } from "@codemirror/view";
|
|
@@ -1617,27 +1760,67 @@ var completion = ({ debug, onQuery, onMatch }) => {
|
|
|
1617
1760
|
};
|
|
1618
1761
|
|
|
1619
1762
|
// packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
|
|
1620
|
-
var
|
|
1763
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
|
|
1621
1764
|
var newValue = Symbol.for("newValue");
|
|
1622
1765
|
var createOption = (text) => ({
|
|
1623
1766
|
[newValue]: true,
|
|
1624
1767
|
text
|
|
1625
1768
|
});
|
|
1626
1769
|
var isCreateOption = (data) => typeof data === "object" && data[newValue];
|
|
1770
|
+
var TableValueEditor = ({ model, modals, schema, onEnter, onFocus, onQuery, __gridScope }) => {
|
|
1771
|
+
const { editing } = useGridContext3("TableValueEditor", __gridScope);
|
|
1772
|
+
const fieldProjection = useMemo4(() => {
|
|
1773
|
+
if (!model || !editing) {
|
|
1774
|
+
return;
|
|
1775
|
+
}
|
|
1776
|
+
const { col } = parseCellIndex2(editing.index);
|
|
1777
|
+
const field = model.projection.view.fields[col];
|
|
1778
|
+
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
1779
|
+
invariant3(fieldProjection2, void 0, {
|
|
1780
|
+
F: __dxlog_file4,
|
|
1781
|
+
L: 73,
|
|
1782
|
+
S: void 0,
|
|
1783
|
+
A: [
|
|
1784
|
+
"fieldProjection",
|
|
1785
|
+
""
|
|
1786
|
+
]
|
|
1787
|
+
});
|
|
1788
|
+
return fieldProjection2;
|
|
1789
|
+
}, [
|
|
1790
|
+
model,
|
|
1791
|
+
editing
|
|
1792
|
+
]);
|
|
1793
|
+
if (fieldProjection?.props.type === TypeEnum4.Array) {
|
|
1794
|
+
return /* @__PURE__ */ React6.createElement(FormCellEditor, {
|
|
1795
|
+
fieldProjection,
|
|
1796
|
+
model,
|
|
1797
|
+
schema,
|
|
1798
|
+
__gridScope
|
|
1799
|
+
});
|
|
1800
|
+
}
|
|
1801
|
+
return /* @__PURE__ */ React6.createElement(TableCellEditor, {
|
|
1802
|
+
model,
|
|
1803
|
+
modals,
|
|
1804
|
+
onEnter,
|
|
1805
|
+
onFocus,
|
|
1806
|
+
onQuery,
|
|
1807
|
+
__gridScope
|
|
1808
|
+
});
|
|
1809
|
+
};
|
|
1627
1810
|
var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }) => {
|
|
1628
|
-
const { id: gridId, editing, setEditing } =
|
|
1629
|
-
const suppressNextBlur =
|
|
1811
|
+
const { id: gridId, editing, setEditing } = useGridContext3("TableCellEditor", __gridScope);
|
|
1812
|
+
const suppressNextBlur = useRef2(false);
|
|
1630
1813
|
const { themeMode } = useThemeContext();
|
|
1631
|
-
const fieldProjection =
|
|
1814
|
+
const fieldProjection = useMemo4(() => {
|
|
1632
1815
|
if (!model || !editing) {
|
|
1633
1816
|
return;
|
|
1634
1817
|
}
|
|
1635
|
-
const { col } =
|
|
1818
|
+
const { col } = parseCellIndex2(editing.index);
|
|
1636
1819
|
const field = model.projection.view.fields[col];
|
|
1637
1820
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
1638
|
-
|
|
1639
|
-
F:
|
|
1640
|
-
L:
|
|
1821
|
+
invariant3(fieldProjection2, void 0, {
|
|
1822
|
+
F: __dxlog_file4,
|
|
1823
|
+
L: 114,
|
|
1641
1824
|
S: void 0,
|
|
1642
1825
|
A: [
|
|
1643
1826
|
"fieldProjection",
|
|
@@ -1649,11 +1832,11 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1649
1832
|
model,
|
|
1650
1833
|
editing
|
|
1651
1834
|
]);
|
|
1652
|
-
const handleEnter =
|
|
1835
|
+
const handleEnter = useCallback4((value) => {
|
|
1653
1836
|
if (!model || !editing) {
|
|
1654
1837
|
return;
|
|
1655
1838
|
}
|
|
1656
|
-
const cell =
|
|
1839
|
+
const cell = parseCellIndex2(editing.index);
|
|
1657
1840
|
model.setCellData(cell, value);
|
|
1658
1841
|
onEnter?.(cell);
|
|
1659
1842
|
onFocus?.();
|
|
@@ -1665,7 +1848,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1665
1848
|
onFocus,
|
|
1666
1849
|
setEditing
|
|
1667
1850
|
]);
|
|
1668
|
-
const handleBlur =
|
|
1851
|
+
const handleBlur = useCallback4((value) => {
|
|
1669
1852
|
if (!model || !editing) {
|
|
1670
1853
|
return;
|
|
1671
1854
|
}
|
|
@@ -1673,7 +1856,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1673
1856
|
suppressNextBlur.current = false;
|
|
1674
1857
|
return;
|
|
1675
1858
|
}
|
|
1676
|
-
const cell =
|
|
1859
|
+
const cell = parseCellIndex2(editing.index);
|
|
1677
1860
|
if (value !== void 0) {
|
|
1678
1861
|
model.setCellData(cell, value);
|
|
1679
1862
|
}
|
|
@@ -1681,11 +1864,11 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1681
1864
|
model,
|
|
1682
1865
|
editing
|
|
1683
1866
|
]);
|
|
1684
|
-
const handleClose =
|
|
1867
|
+
const handleClose = useCallback4((value, event) => {
|
|
1685
1868
|
if (!model || !editing || !fieldProjection) {
|
|
1686
1869
|
return;
|
|
1687
1870
|
}
|
|
1688
|
-
const cell =
|
|
1871
|
+
const cell = parseCellIndex2(editing.index);
|
|
1689
1872
|
onEnter?.(cell);
|
|
1690
1873
|
if (event && onFocus) {
|
|
1691
1874
|
onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
|
|
@@ -1697,7 +1880,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1697
1880
|
onEnter,
|
|
1698
1881
|
fieldProjection
|
|
1699
1882
|
]);
|
|
1700
|
-
const extension =
|
|
1883
|
+
const extension = useMemo4(() => {
|
|
1701
1884
|
if (!fieldProjection) {
|
|
1702
1885
|
return [];
|
|
1703
1886
|
}
|
|
@@ -1778,9 +1961,9 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1778
1961
|
handleClose,
|
|
1779
1962
|
themeMode
|
|
1780
1963
|
]);
|
|
1781
|
-
const getCellContent =
|
|
1964
|
+
const getCellContent = useCallback4(() => {
|
|
1782
1965
|
if (model && editing) {
|
|
1783
|
-
const cell =
|
|
1966
|
+
const cell = parseCellIndex2(editing.index);
|
|
1784
1967
|
const { col } = cell;
|
|
1785
1968
|
const field = model.projection.view.fields[col];
|
|
1786
1969
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
@@ -1824,7 +2007,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1824
2007
|
model,
|
|
1825
2008
|
editing
|
|
1826
2009
|
]);
|
|
1827
|
-
return /* @__PURE__ */
|
|
2010
|
+
return /* @__PURE__ */ React6.createElement(GridCellEditor, {
|
|
1828
2011
|
extension,
|
|
1829
2012
|
getCellContent,
|
|
1830
2013
|
onBlur: handleBlur
|
|
@@ -1856,19 +2039,19 @@ var determineNavigationDelta = ({ key, shift }) => {
|
|
|
1856
2039
|
};
|
|
1857
2040
|
|
|
1858
2041
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
1859
|
-
var
|
|
2042
|
+
var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
|
|
1860
2043
|
var TableRoot = ({ children, role }) => {
|
|
1861
|
-
return /* @__PURE__ */
|
|
2044
|
+
return /* @__PURE__ */ React7.createElement("div", {
|
|
1862
2045
|
role: "none",
|
|
1863
2046
|
className: mx2("relative !border-separator", role === "section" ? "attention-surface overflow-hidden [&_.dx-grid]:max-is-[--dx-grid-content-inline-size]" : "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:max-is-[--dx-grid-content-inline-size] [&_.dx-grid]:bs-0 [&_.dx-grid]:max-bs-[--dx-grid-content-block-size]")
|
|
1864
2047
|
}, children);
|
|
1865
2048
|
};
|
|
1866
|
-
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, onRowClick }, forwardedRef) => {
|
|
2049
|
+
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, schema, onRowClick }, forwardedRef) => {
|
|
1867
2050
|
const [dxGrid, setDxGrid] = useState2(null);
|
|
1868
2051
|
const { hasAttention } = useAttention(model?.id ?? "table");
|
|
1869
2052
|
const { t } = useTranslation3(translationKey);
|
|
1870
|
-
const modals =
|
|
1871
|
-
const frozen =
|
|
2053
|
+
const modals = useMemo5(() => new ModalController(), []);
|
|
2054
|
+
const frozen = useMemo5(() => {
|
|
1872
2055
|
const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
|
|
1873
2056
|
return {
|
|
1874
2057
|
frozenRowsStart: 1,
|
|
@@ -1878,10 +2061,10 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1878
2061
|
}, [
|
|
1879
2062
|
model
|
|
1880
2063
|
]);
|
|
1881
|
-
const getCells =
|
|
2064
|
+
const getCells = useCallback5((range, plane) => presentation?.getCells(range, plane) ?? {}, [
|
|
1882
2065
|
presentation
|
|
1883
2066
|
]);
|
|
1884
|
-
|
|
2067
|
+
useEffect3(() => {
|
|
1885
2068
|
if (!presentation || !dxGrid) {
|
|
1886
2069
|
return;
|
|
1887
2070
|
}
|
|
@@ -1909,7 +2092,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1909
2092
|
presentation,
|
|
1910
2093
|
dxGrid
|
|
1911
2094
|
]);
|
|
1912
|
-
const handleGridClick =
|
|
2095
|
+
const handleGridClick = useCallback5((event) => {
|
|
1913
2096
|
const rowIndex = safeParseInt(event.target.ariaRowIndex ?? "");
|
|
1914
2097
|
if (rowIndex != null) {
|
|
1915
2098
|
if (onRowClick) {
|
|
@@ -1984,14 +2167,14 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1984
2167
|
model,
|
|
1985
2168
|
modals
|
|
1986
2169
|
]);
|
|
1987
|
-
const handleFocus =
|
|
2170
|
+
const handleFocus = useCallback5((increment, delta) => {
|
|
1988
2171
|
if (dxGrid) {
|
|
1989
2172
|
dxGrid.refocus(increment, delta);
|
|
1990
2173
|
}
|
|
1991
2174
|
}, [
|
|
1992
2175
|
dxGrid
|
|
1993
2176
|
]);
|
|
1994
|
-
const handleEnter =
|
|
2177
|
+
const handleEnter = useCallback5((cell) => {
|
|
1995
2178
|
if (!model?.features.dataEditable) {
|
|
1996
2179
|
return;
|
|
1997
2180
|
}
|
|
@@ -2008,7 +2191,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2008
2191
|
model,
|
|
2009
2192
|
dxGrid
|
|
2010
2193
|
]);
|
|
2011
|
-
const handleKeyDown =
|
|
2194
|
+
const handleKeyDown = useCallback5((event) => {
|
|
2012
2195
|
if (!model?.features.dataEditable) {
|
|
2013
2196
|
return;
|
|
2014
2197
|
}
|
|
@@ -2026,7 +2209,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2026
2209
|
}, [
|
|
2027
2210
|
model
|
|
2028
2211
|
]);
|
|
2029
|
-
const handleAxisResize =
|
|
2212
|
+
const handleAxisResize = useCallback5((event) => {
|
|
2030
2213
|
if (event.axis === "col") {
|
|
2031
2214
|
const columnIndex = parseInt(event.index, 10);
|
|
2032
2215
|
model?.setColumnWidth(columnIndex, event.size);
|
|
@@ -2034,7 +2217,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2034
2217
|
}, [
|
|
2035
2218
|
model
|
|
2036
2219
|
]);
|
|
2037
|
-
const handleWheel =
|
|
2220
|
+
const handleWheel = useCallback5((event) => {
|
|
2038
2221
|
if (!ignoreAttention && !hasAttention) {
|
|
2039
2222
|
event.stopPropagation();
|
|
2040
2223
|
}
|
|
@@ -2042,7 +2225,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2042
2225
|
hasAttention,
|
|
2043
2226
|
ignoreAttention
|
|
2044
2227
|
]);
|
|
2045
|
-
const handleNewColumn =
|
|
2228
|
+
const handleNewColumn = useCallback5(() => {
|
|
2046
2229
|
const columns = model?.getColumnCount();
|
|
2047
2230
|
if (dxGrid && columns) {
|
|
2048
2231
|
dxGrid.scrollToColumn(columns - 1);
|
|
@@ -2051,21 +2234,21 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2051
2234
|
model,
|
|
2052
2235
|
dxGrid
|
|
2053
2236
|
]);
|
|
2054
|
-
const handleQuery =
|
|
2237
|
+
const handleQuery = useCallback5(async ({ field, props }, text) => {
|
|
2055
2238
|
if (model && props.referenceSchema && field.referencePath) {
|
|
2056
2239
|
const space = model.space;
|
|
2057
|
-
|
|
2058
|
-
F:
|
|
2059
|
-
L:
|
|
2240
|
+
invariant4(space, void 0, {
|
|
2241
|
+
F: __dxlog_file5,
|
|
2242
|
+
L: 309,
|
|
2060
2243
|
S: void 0,
|
|
2061
2244
|
A: [
|
|
2062
2245
|
"space",
|
|
2063
2246
|
""
|
|
2064
2247
|
]
|
|
2065
2248
|
});
|
|
2066
|
-
const
|
|
2067
|
-
if (
|
|
2068
|
-
const { objects } = await space.db.query(Filter.
|
|
2249
|
+
const schema2 = space.db.schemaRegistry.getSchema(props.referenceSchema);
|
|
2250
|
+
if (schema2) {
|
|
2251
|
+
const { objects } = await space.db.query(Filter.type(schema2)).run();
|
|
2069
2252
|
const options = objects.map((obj) => {
|
|
2070
2253
|
const value = getValue4(obj, field.referencePath);
|
|
2071
2254
|
if (!value || typeof value !== "string") {
|
|
@@ -2093,21 +2276,22 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2093
2276
|
t
|
|
2094
2277
|
]);
|
|
2095
2278
|
if (!model || !modals) {
|
|
2096
|
-
return /* @__PURE__ */
|
|
2279
|
+
return /* @__PURE__ */ React7.createElement("span", {
|
|
2097
2280
|
role: "none",
|
|
2098
2281
|
className: "attention-surface"
|
|
2099
2282
|
});
|
|
2100
2283
|
}
|
|
2101
|
-
return /* @__PURE__ */
|
|
2284
|
+
return /* @__PURE__ */ React7.createElement(Grid.Root, {
|
|
2102
2285
|
id: model.id ?? "table-grid"
|
|
2103
|
-
}, /* @__PURE__ */
|
|
2286
|
+
}, /* @__PURE__ */ React7.createElement(TableValueEditor, {
|
|
2104
2287
|
model,
|
|
2105
2288
|
modals,
|
|
2289
|
+
schema,
|
|
2106
2290
|
onEnter: handleEnter,
|
|
2107
2291
|
onFocus: handleFocus,
|
|
2108
2292
|
onQuery: handleQuery
|
|
2109
|
-
}), /* @__PURE__ */
|
|
2110
|
-
className: mx2("[--dx-grid-base:var(--
|
|
2293
|
+
}), /* @__PURE__ */ React7.createElement(Grid.Content, {
|
|
2294
|
+
className: mx2("[--dx-grid-base:var(--baseSurface)]", gridSeparatorInlineEnd, gridSeparatorBlockEnd),
|
|
2111
2295
|
frozen,
|
|
2112
2296
|
// getCells={getCells}
|
|
2113
2297
|
columns: model.columnMeta.value,
|
|
@@ -2119,17 +2303,17 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
2119
2303
|
onKeyDown: handleKeyDown,
|
|
2120
2304
|
onWheelCapture: handleWheel,
|
|
2121
2305
|
ref: setDxGrid
|
|
2122
|
-
}), /* @__PURE__ */
|
|
2306
|
+
}), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
|
|
2123
2307
|
model,
|
|
2124
2308
|
modals
|
|
2125
|
-
}), /* @__PURE__ */
|
|
2309
|
+
}), /* @__PURE__ */ React7.createElement(ColumnActionsMenu, {
|
|
2126
2310
|
model,
|
|
2127
2311
|
modals
|
|
2128
|
-
}), /* @__PURE__ */
|
|
2312
|
+
}), /* @__PURE__ */ React7.createElement(ColumnSettings, {
|
|
2129
2313
|
model,
|
|
2130
2314
|
modals,
|
|
2131
2315
|
onNewColumn: handleNewColumn
|
|
2132
|
-
}), /* @__PURE__ */
|
|
2316
|
+
}), /* @__PURE__ */ React7.createElement(CreateRefPanel, {
|
|
2133
2317
|
model,
|
|
2134
2318
|
modals
|
|
2135
2319
|
}));
|
|
@@ -2140,19 +2324,19 @@ var Table = {
|
|
|
2140
2324
|
};
|
|
2141
2325
|
|
|
2142
2326
|
// packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
|
|
2143
|
-
import
|
|
2327
|
+
import React8, { useRef as useRef3, useMemo as useMemo6, useCallback as useCallback6 } from "react";
|
|
2144
2328
|
import { useDefaultValue } from "@dxos/react-ui";
|
|
2145
2329
|
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
2146
2330
|
|
|
2147
2331
|
// packages/ui/react-ui-table/src/hooks/useTableModel.ts
|
|
2148
2332
|
import { effect as effect3 } from "@preact/signals-core";
|
|
2149
|
-
import { useEffect as
|
|
2333
|
+
import { useEffect as useEffect4, useState as useState3 } from "react";
|
|
2150
2334
|
import { fullyQualifiedId, getSpace } from "@dxos/react-client/echo";
|
|
2151
2335
|
import { useSelectionActions } from "@dxos/react-ui-attention";
|
|
2152
2336
|
import { isNonNullable } from "@dxos/util";
|
|
2153
2337
|
var useTableModel = ({ table, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
|
|
2154
2338
|
const [model, setModel] = useState3();
|
|
2155
|
-
|
|
2339
|
+
useEffect4(() => {
|
|
2156
2340
|
if (!table || !projection) {
|
|
2157
2341
|
return;
|
|
2158
2342
|
}
|
|
@@ -2182,7 +2366,7 @@ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectio
|
|
|
2182
2366
|
features,
|
|
2183
2367
|
rowActions
|
|
2184
2368
|
]);
|
|
2185
|
-
|
|
2369
|
+
useEffect4(() => {
|
|
2186
2370
|
if (rows) {
|
|
2187
2371
|
model?.setRows(rows);
|
|
2188
2372
|
}
|
|
@@ -2194,7 +2378,7 @@ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectio
|
|
|
2194
2378
|
table?.id,
|
|
2195
2379
|
table?.view?.target?.query.typename
|
|
2196
2380
|
].filter(isNonNullable));
|
|
2197
|
-
|
|
2381
|
+
useEffect4(() => {
|
|
2198
2382
|
if (!model) {
|
|
2199
2383
|
return;
|
|
2200
2384
|
}
|
|
@@ -2218,8 +2402,8 @@ var useTableModel = ({ table, projection, rows, rowActions, features, onSelectio
|
|
|
2218
2402
|
|
|
2219
2403
|
// packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
|
|
2220
2404
|
var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
|
|
2221
|
-
const { table, projection } =
|
|
2222
|
-
const props2 =
|
|
2405
|
+
const { table, projection } = useMemo6(() => {
|
|
2406
|
+
const props2 = getBaseSchema({
|
|
2223
2407
|
typename: name,
|
|
2224
2408
|
properties,
|
|
2225
2409
|
jsonSchema,
|
|
@@ -2235,11 +2419,11 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
2235
2419
|
schema,
|
|
2236
2420
|
jsonSchema
|
|
2237
2421
|
]);
|
|
2238
|
-
const tableRef =
|
|
2239
|
-
const handleCellUpdate =
|
|
2422
|
+
const tableRef = useRef3(null);
|
|
2423
|
+
const handleCellUpdate = useCallback6((cell) => {
|
|
2240
2424
|
tableRef.current?.update?.(cell);
|
|
2241
2425
|
}, []);
|
|
2242
|
-
const handleRowOrderChange =
|
|
2426
|
+
const handleRowOrderChange = useCallback6(() => {
|
|
2243
2427
|
tableRef.current?.update?.();
|
|
2244
2428
|
}, []);
|
|
2245
2429
|
const features = useDefaultValue(props.features, () => ({
|
|
@@ -2258,20 +2442,20 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
2258
2442
|
onRowOrderChange: handleRowOrderChange,
|
|
2259
2443
|
onRowAction
|
|
2260
2444
|
});
|
|
2261
|
-
const presentation =
|
|
2445
|
+
const presentation = useMemo6(() => {
|
|
2262
2446
|
if (model) {
|
|
2263
2447
|
return new TablePresentation(model);
|
|
2264
2448
|
}
|
|
2265
2449
|
}, [
|
|
2266
2450
|
model
|
|
2267
2451
|
]);
|
|
2268
|
-
return /* @__PURE__ */
|
|
2452
|
+
return /* @__PURE__ */ React8.createElement("div", {
|
|
2269
2453
|
role: "none",
|
|
2270
2454
|
className: mx3("is-full bs-full grow grid", classNames)
|
|
2271
|
-
}, /* @__PURE__ */
|
|
2455
|
+
}, /* @__PURE__ */ React8.createElement("div", {
|
|
2272
2456
|
role: "none",
|
|
2273
2457
|
className: "grid min-bs-0 overflow-hidden"
|
|
2274
|
-
}, /* @__PURE__ */
|
|
2458
|
+
}, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
|
|
2275
2459
|
ref: tableRef,
|
|
2276
2460
|
model,
|
|
2277
2461
|
presentation,
|
|
@@ -2281,11 +2465,11 @@ var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, prop
|
|
|
2281
2465
|
};
|
|
2282
2466
|
|
|
2283
2467
|
// packages/ui/react-ui-table/src/components/TableToolbar/TableToolbar.tsx
|
|
2284
|
-
import
|
|
2468
|
+
import React9, { useCallback as useCallback7, useMemo as useMemo7 } from "react";
|
|
2285
2469
|
import { live as live4 } from "@dxos/live-object";
|
|
2286
2470
|
import { createGapSeparator, createMenuAction, MenuProvider, ToolbarMenu, useMenuActions } from "@dxos/react-ui-menu";
|
|
2287
|
-
var createTableToolbarActions = (state) => {
|
|
2288
|
-
const add = createMenuAction("add-row", {
|
|
2471
|
+
var createTableToolbarActions = (state, onAction) => {
|
|
2472
|
+
const add = createMenuAction("add-row", () => onAction(add), {
|
|
2289
2473
|
type: "add-row",
|
|
2290
2474
|
icon: "ph--plus--regular",
|
|
2291
2475
|
label: [
|
|
@@ -2296,7 +2480,7 @@ var createTableToolbarActions = (state) => {
|
|
|
2296
2480
|
],
|
|
2297
2481
|
testId: "table.toolbar.add-row"
|
|
2298
2482
|
});
|
|
2299
|
-
const save = createMenuAction("save-view", {
|
|
2483
|
+
const save = createMenuAction("save-view", () => onAction(save), {
|
|
2300
2484
|
type: "save-view",
|
|
2301
2485
|
icon: "ph--floppy-disk--regular",
|
|
2302
2486
|
label: [
|
|
@@ -2310,7 +2494,7 @@ var createTableToolbarActions = (state) => {
|
|
|
2310
2494
|
hidden: !state.viewDirty
|
|
2311
2495
|
});
|
|
2312
2496
|
const gap = createGapSeparator();
|
|
2313
|
-
const comment = createMenuAction("comment", {
|
|
2497
|
+
const comment = createMenuAction("comment", () => onAction(comment), {
|
|
2314
2498
|
type: "comment",
|
|
2315
2499
|
icon: "ph--chat-text--regular",
|
|
2316
2500
|
label: [
|
|
@@ -2336,18 +2520,18 @@ var createTableToolbarActions = (state) => {
|
|
|
2336
2520
|
};
|
|
2337
2521
|
};
|
|
2338
2522
|
var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
|
|
2339
|
-
const state =
|
|
2523
|
+
const state = useMemo7(() => live4({
|
|
2340
2524
|
viewDirty
|
|
2341
2525
|
}), []);
|
|
2342
|
-
const actionsCreator =
|
|
2343
|
-
state
|
|
2526
|
+
const actionsCreator = useCallback7(() => createTableToolbarActions(state, onAction), [
|
|
2527
|
+
state,
|
|
2528
|
+
onAction
|
|
2344
2529
|
]);
|
|
2345
2530
|
const menu = useMenuActions(actionsCreator);
|
|
2346
|
-
return /* @__PURE__ */
|
|
2531
|
+
return /* @__PURE__ */ React9.createElement(MenuProvider, {
|
|
2347
2532
|
...menu,
|
|
2348
|
-
attendableId
|
|
2349
|
-
|
|
2350
|
-
}, /* @__PURE__ */ React8.createElement(ToolbarMenu, {
|
|
2533
|
+
attendableId
|
|
2534
|
+
}, /* @__PURE__ */ React9.createElement(ToolbarMenu, {
|
|
2351
2535
|
classNames
|
|
2352
2536
|
}));
|
|
2353
2537
|
};
|
|
@@ -2365,9 +2549,10 @@ export {
|
|
|
2365
2549
|
TableToolbar,
|
|
2366
2550
|
TableType,
|
|
2367
2551
|
cellClassesForRowSelection,
|
|
2368
|
-
|
|
2552
|
+
getBaseSchema,
|
|
2369
2553
|
initializeTable,
|
|
2370
2554
|
makeDynamicTable,
|
|
2555
|
+
narrowSchema,
|
|
2371
2556
|
tableButtons,
|
|
2372
2557
|
tableControls,
|
|
2373
2558
|
touch,
|