@dxos/react-ui-table 0.8.4-main.72ec0f3 → 0.8.4-main.7ace549
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/lib/browser/chunk-5XWSB3JP.mjs +71 -0
- package/dist/lib/browser/chunk-5XWSB3JP.mjs.map +7 -0
- package/dist/lib/browser/{chunk-GS2UNGJK.mjs → chunk-KNC7XYT6.mjs} +116 -108
- package/dist/lib/browser/chunk-KNC7XYT6.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +25 -13
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/testing/index.mjs +14 -27
- 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-CWSGS3Y2.mjs} +116 -108
- package/dist/lib/node-esm/chunk-CWSGS3Y2.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs +72 -0
- package/dist/lib/node-esm/chunk-MKTMOY46.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +25 -13
- 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 +14 -27
- package/dist/lib/node-esm/testing/index.mjs.map +3 -3
- package/dist/lib/node-esm/types/index.mjs +3 -3
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +2 -2
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Relations.stories.d.ts +7 -6
- package/dist/types/src/components/Table/Relations.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +67 -4
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/FormCellEditor.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +2 -2
- 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 +21 -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 +7 -6
- 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/DynamicTable.stories.tsx +7 -7
- package/src/components/Table/DynamicTable.tsx +12 -4
- package/src/components/Table/Relations.stories.tsx +9 -14
- package/src/components/Table/Table.stories.tsx +47 -42
- package/src/components/TableCellEditor/FormCellEditor.tsx +2 -2
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +5 -4
- package/src/components/TableCellEditor/TableCellEditor.tsx +4 -4
- 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 +10 -12
- package/src/model/table-model.test.ts +4 -4
- package/src/model/table-model.ts +27 -36
- 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 +3 -3
- package/src/playwright/smoke.spec.ts +1 -1
- package/src/testing/useTestTableModel.ts +32 -24
- package/src/translations.ts +2 -2
- package/src/types/Table.ts +89 -0
- package/src/types/index.ts +1 -1
- package/src/util/dynamic-table.ts +9 -12
- 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
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
|
|
2
2
|
import {
|
|
3
|
-
|
|
4
|
-
} from "./chunk-
|
|
3
|
+
Table_exports
|
|
4
|
+
} from "./chunk-MKTMOY46.mjs";
|
|
5
5
|
|
|
6
6
|
// src/util/dynamic-table.ts
|
|
7
|
-
import { Filter, Obj, Query } from "@dxos/echo";
|
|
8
|
-
import { getTypename, toJsonSchema } from "@dxos/echo/internal";
|
|
7
|
+
import { Filter, Obj, Query, Ref, Type } from "@dxos/echo";
|
|
9
8
|
import { ProjectionModel, View, getSchemaFromPropertyDefinitions } from "@dxos/schema";
|
|
10
9
|
var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
11
10
|
if (typename && properties) {
|
|
@@ -16,8 +15,8 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
|
16
15
|
};
|
|
17
16
|
} else if (schema) {
|
|
18
17
|
return {
|
|
19
|
-
typename: getTypename(schema),
|
|
20
|
-
jsonSchema: toJsonSchema(schema)
|
|
18
|
+
typename: Type.getTypename(schema),
|
|
19
|
+
jsonSchema: Type.toJsonSchema(schema)
|
|
21
20
|
};
|
|
22
21
|
} else if (typename && jsonSchema) {
|
|
23
22
|
return {
|
|
@@ -29,25 +28,25 @@ var getBaseSchema = ({ typename, properties, jsonSchema, schema }) => {
|
|
|
29
28
|
}
|
|
30
29
|
};
|
|
31
30
|
var makeDynamicTable = ({ jsonSchema, properties }) => {
|
|
32
|
-
const table = Obj.make(schema_exports.Table, {
|
|
33
|
-
sizes: {}
|
|
34
|
-
});
|
|
35
31
|
const view = View.make({
|
|
36
32
|
query: Query.select(Filter.everything()),
|
|
37
33
|
jsonSchema,
|
|
38
|
-
presentation: table,
|
|
39
34
|
...properties && {
|
|
40
35
|
fields: properties.map((property) => property.name)
|
|
41
36
|
}
|
|
42
37
|
});
|
|
38
|
+
const object = Obj.make(Table_exports.Table, {
|
|
39
|
+
view: Ref.make(view),
|
|
40
|
+
sizes: {}
|
|
41
|
+
});
|
|
43
42
|
const projection = new ProjectionModel(jsonSchema, view.projection);
|
|
44
43
|
projection.normalizeView();
|
|
45
44
|
if (properties && projection.fields) {
|
|
46
|
-
setProperties(view, projection,
|
|
45
|
+
setProperties(view, projection, object, properties);
|
|
47
46
|
}
|
|
48
47
|
return {
|
|
49
48
|
projection,
|
|
50
|
-
|
|
49
|
+
object
|
|
51
50
|
};
|
|
52
51
|
};
|
|
53
52
|
var setProperties = (view, projection, table, properties) => {
|
|
@@ -274,13 +273,13 @@ var narrowSchema = (schema, paths) => {
|
|
|
274
273
|
// src/model/table-model.ts
|
|
275
274
|
import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
|
|
276
275
|
import { Resource as Resource2 } from "@dxos/context";
|
|
277
|
-
import { Obj as Obj2, Ref } from "@dxos/echo";
|
|
278
|
-
import {
|
|
276
|
+
import { Format as Format2, Obj as Obj2, Ref as Ref2 } from "@dxos/echo";
|
|
277
|
+
import { getValue as getValue2, setValue, toEffectSchema } from "@dxos/echo/internal";
|
|
279
278
|
import { invariant } from "@dxos/invariant";
|
|
280
279
|
import { ObjectId } from "@dxos/keys";
|
|
281
280
|
import { getSnapshot, isLiveObject } from "@dxos/live-object";
|
|
282
281
|
import { formatForEditing, parseValue } from "@dxos/react-ui-form";
|
|
283
|
-
import {
|
|
282
|
+
import { validateSchema } from "@dxos/schema";
|
|
284
283
|
|
|
285
284
|
// src/util/tag.ts
|
|
286
285
|
var TAG_PATTERN_REGEX = /\[([^\]]+)\]\(([^)]+)\)/g;
|
|
@@ -395,23 +394,23 @@ var SelectionModel = class extends Resource {
|
|
|
395
394
|
// src/model/table-sorting.ts
|
|
396
395
|
import { computed as computed2, signal as signal2 } from "@preact/signals-core";
|
|
397
396
|
import orderBy from "lodash.orderby";
|
|
398
|
-
import {
|
|
397
|
+
import { Format, TypeEnum, getValue } from "@dxos/echo/internal";
|
|
399
398
|
import { formatForDisplay } from "@dxos/react-ui-form";
|
|
400
399
|
var TableSorting = class {
|
|
401
|
-
_view;
|
|
402
|
-
_projection;
|
|
403
400
|
_displayToDataIndex = /* @__PURE__ */ new Map();
|
|
404
401
|
_rows;
|
|
402
|
+
_getView;
|
|
403
|
+
_projection;
|
|
405
404
|
_localSort = signal2(void 0);
|
|
406
405
|
_isDirty;
|
|
407
406
|
sortedRows;
|
|
408
|
-
constructor(rows,
|
|
409
|
-
this._view = _view;
|
|
410
|
-
this._projection = _projection;
|
|
407
|
+
constructor({ rows, projection, getView }) {
|
|
411
408
|
this._rows = rows;
|
|
409
|
+
this._getView = getView;
|
|
410
|
+
this._projection = projection;
|
|
412
411
|
this._isDirty = computed2(() => {
|
|
413
412
|
const local = this._localSort.value;
|
|
414
|
-
const viewSort = this.
|
|
413
|
+
const viewSort = this._getView().sort?.[0];
|
|
415
414
|
if (local?.type === "cleared") {
|
|
416
415
|
return viewSort !== void 0;
|
|
417
416
|
}
|
|
@@ -437,7 +436,7 @@ var TableSorting = class {
|
|
|
437
436
|
if (local?.type === "active") {
|
|
438
437
|
return local.sort;
|
|
439
438
|
}
|
|
440
|
-
return this.
|
|
439
|
+
return this._getView().sort?.[0];
|
|
441
440
|
}
|
|
442
441
|
/**
|
|
443
442
|
* @reactive
|
|
@@ -480,12 +479,13 @@ var TableSorting = class {
|
|
|
480
479
|
}
|
|
481
480
|
save() {
|
|
482
481
|
if (this._localSort.value !== void 0) {
|
|
482
|
+
const view = this._getView();
|
|
483
483
|
if (this._localSort.value.type === "active") {
|
|
484
|
-
|
|
484
|
+
view.sort = [
|
|
485
485
|
this._localSort.value.sort
|
|
486
486
|
];
|
|
487
487
|
} else {
|
|
488
|
-
|
|
488
|
+
view.sort = [];
|
|
489
489
|
}
|
|
490
490
|
this._localSort.value = void 0;
|
|
491
491
|
}
|
|
@@ -542,7 +542,7 @@ var TableSorting = class {
|
|
|
542
542
|
if (value == null) {
|
|
543
543
|
return value;
|
|
544
544
|
}
|
|
545
|
-
if (format ===
|
|
545
|
+
if (format === Format.TypeFormat.SingleSelect) {
|
|
546
546
|
const options = props.options;
|
|
547
547
|
if (!options) {
|
|
548
548
|
return void 0;
|
|
@@ -550,7 +550,7 @@ var TableSorting = class {
|
|
|
550
550
|
const option = options.find((option2) => option2.id === value);
|
|
551
551
|
return option ? options.indexOf(option) : void 0;
|
|
552
552
|
}
|
|
553
|
-
if (format ===
|
|
553
|
+
if (format === Format.TypeFormat.Ref && field.referencePath) {
|
|
554
554
|
const refValue = getValue(value.target, field.referencePath);
|
|
555
555
|
return refValue;
|
|
556
556
|
}
|
|
@@ -573,9 +573,8 @@ var defaultFeatures = {
|
|
|
573
573
|
schemaEditable: false
|
|
574
574
|
};
|
|
575
575
|
var TableModel = class extends Resource2 {
|
|
576
|
-
|
|
576
|
+
_object;
|
|
577
577
|
_projection;
|
|
578
|
-
_table;
|
|
579
578
|
_visibleRange = signal3({
|
|
580
579
|
start: {
|
|
581
580
|
row: 0,
|
|
@@ -600,13 +599,13 @@ var TableModel = class extends Resource2 {
|
|
|
600
599
|
_pinnedRows;
|
|
601
600
|
_selection;
|
|
602
601
|
_columnMeta;
|
|
603
|
-
constructor({
|
|
602
|
+
constructor({ object, projection, features = {}, sorting = [], initialSelection = [], pinnedRows = {
|
|
604
603
|
top: [],
|
|
605
604
|
bottom: []
|
|
606
605
|
}, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
|
|
607
606
|
super();
|
|
608
|
-
this.
|
|
609
|
-
this._projection = projection
|
|
607
|
+
this._object = object;
|
|
608
|
+
this._projection = projection;
|
|
610
609
|
this._projection.normalizeView();
|
|
611
610
|
this._features = {
|
|
612
611
|
...defaultFeatures,
|
|
@@ -614,14 +613,18 @@ var TableModel = class extends Resource2 {
|
|
|
614
613
|
};
|
|
615
614
|
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
616
615
|
F: __dxlog_file,
|
|
617
|
-
L:
|
|
616
|
+
L: 137,
|
|
618
617
|
S: this,
|
|
619
618
|
A: [
|
|
620
619
|
"!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
|
|
621
620
|
"'Single selection is not compatible with editable tables.'"
|
|
622
621
|
]
|
|
623
622
|
});
|
|
624
|
-
this._sorting = new TableSorting(
|
|
623
|
+
this._sorting = new TableSorting({
|
|
624
|
+
rows: this._rows,
|
|
625
|
+
getView: () => this.view,
|
|
626
|
+
projection: this._projection
|
|
627
|
+
});
|
|
625
628
|
if (sorting.length > 0) {
|
|
626
629
|
const [sort] = sorting;
|
|
627
630
|
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
@@ -637,22 +640,23 @@ var TableModel = class extends Resource2 {
|
|
|
637
640
|
this._onRowAction = onRowAction;
|
|
638
641
|
}
|
|
639
642
|
get id() {
|
|
640
|
-
return Obj2.getDXN(this.
|
|
643
|
+
return Obj2.getDXN(this._object).toString();
|
|
641
644
|
}
|
|
642
645
|
get view() {
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
get table() {
|
|
646
|
-
invariant(this._table, "Model not initialized", {
|
|
646
|
+
const view = this._object.view.target;
|
|
647
|
+
invariant(view, "Table model not initialized", {
|
|
647
648
|
F: __dxlog_file,
|
|
648
|
-
L:
|
|
649
|
+
L: 176,
|
|
649
650
|
S: this,
|
|
650
651
|
A: [
|
|
651
|
-
"
|
|
652
|
-
"'
|
|
652
|
+
"view",
|
|
653
|
+
"'Table model not initialized'"
|
|
653
654
|
]
|
|
654
655
|
});
|
|
655
|
-
return
|
|
656
|
+
return view;
|
|
657
|
+
}
|
|
658
|
+
get table() {
|
|
659
|
+
return this._object;
|
|
656
660
|
}
|
|
657
661
|
get projection() {
|
|
658
662
|
return this._projection;
|
|
@@ -684,7 +688,7 @@ var TableModel = class extends Resource2 {
|
|
|
684
688
|
get columnMeta() {
|
|
685
689
|
invariant(this._columnMeta, void 0, {
|
|
686
690
|
F: __dxlog_file,
|
|
687
|
-
L:
|
|
691
|
+
L: 219,
|
|
688
692
|
S: this,
|
|
689
693
|
A: [
|
|
690
694
|
"this._columnMeta",
|
|
@@ -707,17 +711,7 @@ var TableModel = class extends Resource2 {
|
|
|
707
711
|
// Initialisation
|
|
708
712
|
//
|
|
709
713
|
async _open() {
|
|
710
|
-
|
|
711
|
-
invariant(Obj2.instanceOf(schema_exports.Table, presentation), void 0, {
|
|
712
|
-
F: __dxlog_file,
|
|
713
|
-
L: 248,
|
|
714
|
-
S: this,
|
|
715
|
-
A: [
|
|
716
|
-
"Obj.instanceOf(Table.Table, presentation)",
|
|
717
|
-
""
|
|
718
|
-
]
|
|
719
|
-
});
|
|
720
|
-
this._table = presentation;
|
|
714
|
+
await this._object.view.load();
|
|
721
715
|
this.initializeColumnMeta();
|
|
722
716
|
this.initializeEffects();
|
|
723
717
|
await this._selection.open(this._ctx);
|
|
@@ -914,7 +908,7 @@ var TableModel = class extends Resource2 {
|
|
|
914
908
|
}
|
|
915
909
|
const { props } = this._projection.getFieldProjection(field.id);
|
|
916
910
|
switch (props.format) {
|
|
917
|
-
case
|
|
911
|
+
case Format2.TypeFormat.Ref: {
|
|
918
912
|
if (!field.referencePath) {
|
|
919
913
|
return "";
|
|
920
914
|
}
|
|
@@ -972,7 +966,7 @@ var TableModel = class extends Resource2 {
|
|
|
972
966
|
const currentRow = this._rows.value[rowIdx];
|
|
973
967
|
invariant(currentRow, "Invalid row index", {
|
|
974
968
|
F: __dxlog_file,
|
|
975
|
-
L:
|
|
969
|
+
L: 516,
|
|
976
970
|
S: this,
|
|
977
971
|
A: [
|
|
978
972
|
"currentRow",
|
|
@@ -981,10 +975,10 @@ var TableModel = class extends Resource2 {
|
|
|
981
975
|
});
|
|
982
976
|
const snapshot = getSnapshot(currentRow);
|
|
983
977
|
setValue(snapshot, field.path, transformedValue);
|
|
984
|
-
const schema = getSchema(currentRow);
|
|
978
|
+
const schema = Obj2.getSchema(currentRow);
|
|
985
979
|
invariant(schema, void 0, {
|
|
986
980
|
F: __dxlog_file,
|
|
987
|
-
L:
|
|
981
|
+
L: 522,
|
|
988
982
|
S: this,
|
|
989
983
|
A: [
|
|
990
984
|
"schema",
|
|
@@ -996,7 +990,7 @@ var TableModel = class extends Resource2 {
|
|
|
996
990
|
const error = validationResult[0];
|
|
997
991
|
invariant(error.path === field.path, void 0, {
|
|
998
992
|
F: __dxlog_file,
|
|
999
|
-
L:
|
|
993
|
+
L: 527,
|
|
1000
994
|
S: this,
|
|
1001
995
|
A: [
|
|
1002
996
|
"error.path === field.path",
|
|
@@ -1022,7 +1016,7 @@ var TableModel = class extends Resource2 {
|
|
|
1022
1016
|
const field = fields[col];
|
|
1023
1017
|
const { props } = this._projection.getFieldProjection(field.id);
|
|
1024
1018
|
const transformedValue = editorTextToCellValue(props, value);
|
|
1025
|
-
if (props.format ===
|
|
1019
|
+
if (props.format === Format2.TypeFormat.Ref && !isLiveObject(value)) {
|
|
1026
1020
|
return;
|
|
1027
1021
|
}
|
|
1028
1022
|
if (plane === "frozenRowsEnd") {
|
|
@@ -1118,14 +1112,14 @@ var TableModel = class extends Resource2 {
|
|
|
1118
1112
|
};
|
|
1119
1113
|
var editorTextToCellValue = (props, value) => {
|
|
1120
1114
|
switch (props.format) {
|
|
1121
|
-
case
|
|
1115
|
+
case Format2.TypeFormat.Ref: {
|
|
1122
1116
|
if (isLiveObject(value)) {
|
|
1123
|
-
return
|
|
1117
|
+
return Ref2.make(value);
|
|
1124
1118
|
} else {
|
|
1125
1119
|
return value;
|
|
1126
1120
|
}
|
|
1127
1121
|
}
|
|
1128
|
-
case
|
|
1122
|
+
case Format2.TypeFormat.SingleSelect: {
|
|
1129
1123
|
const ids = extractTagIds(value);
|
|
1130
1124
|
if (ids && ids.length > 0) {
|
|
1131
1125
|
return ids[0];
|
|
@@ -1133,7 +1127,7 @@ var editorTextToCellValue = (props, value) => {
|
|
|
1133
1127
|
return value;
|
|
1134
1128
|
}
|
|
1135
1129
|
}
|
|
1136
|
-
case
|
|
1130
|
+
case Format2.TypeFormat.MultiSelect: {
|
|
1137
1131
|
const ids = extractTagIds(value);
|
|
1138
1132
|
return ids || value;
|
|
1139
1133
|
}
|
|
@@ -1217,7 +1211,7 @@ var ModalController = class {
|
|
|
1217
1211
|
import { signal as signal5 } from "@preact/signals-core";
|
|
1218
1212
|
import * as Predicate from "effect/Predicate";
|
|
1219
1213
|
import { Obj as Obj3 } from "@dxos/echo";
|
|
1220
|
-
import {
|
|
1214
|
+
import { Format as Format3, TypeEnum as TypeEnum2, getValue as getValue3 } from "@dxos/echo/internal";
|
|
1221
1215
|
import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
|
|
1222
1216
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
1223
1217
|
import { mx } from "@dxos/react-ui-theme";
|
|
@@ -1304,12 +1298,12 @@ var TablePresentation = class {
|
|
|
1304
1298
|
return "";
|
|
1305
1299
|
}
|
|
1306
1300
|
switch (props.format) {
|
|
1307
|
-
case
|
|
1308
|
-
case
|
|
1309
|
-
case
|
|
1301
|
+
case Format3.TypeFormat.Boolean:
|
|
1302
|
+
case Format3.TypeFormat.SingleSelect:
|
|
1303
|
+
case Format3.TypeFormat.MultiSelect: {
|
|
1310
1304
|
return "";
|
|
1311
1305
|
}
|
|
1312
|
-
case
|
|
1306
|
+
case Format3.TypeFormat.Ref: {
|
|
1313
1307
|
if (!field.referencePath) {
|
|
1314
1308
|
return "";
|
|
1315
1309
|
}
|
|
@@ -1362,14 +1356,14 @@ var TablePresentation = class {
|
|
|
1362
1356
|
cell.accessoryHtml = `<div role='none' class="flex flex-row gap-1 overflow-x-auto">${tags}</div>`;
|
|
1363
1357
|
}
|
|
1364
1358
|
}
|
|
1365
|
-
if (props.format ===
|
|
1359
|
+
if (props.format === Format3.TypeFormat.Ref && props.referenceSchema) {
|
|
1366
1360
|
const targetObj = getValue3(obj, field.path)?.target;
|
|
1367
1361
|
if (targetObj) {
|
|
1368
1362
|
const dxn = Obj3.getDXN(targetObj)?.toString();
|
|
1369
1363
|
cell.accessoryHtml = `<div role="none" class="absolute inline-end-0 inset-block-0 p-[--dx-grid-cell-content-padding-block]"><dx-anchor refId=${dxn} class="dx-button is-6 aspect-square min-bs-0" data-dx-grid-action="accessory"><dx-icon icon="ph--link-simple--regular"/></dx-anchor></div>`;
|
|
1370
1364
|
}
|
|
1371
1365
|
}
|
|
1372
|
-
if (props.format ===
|
|
1366
|
+
if (props.format === Format3.TypeFormat.Boolean) {
|
|
1373
1367
|
const value = getValue3(obj, field.path);
|
|
1374
1368
|
cell.accessoryHtml = tableControls.switch.render({
|
|
1375
1369
|
colIndex,
|
|
@@ -1378,7 +1372,7 @@ var TablePresentation = class {
|
|
|
1378
1372
|
});
|
|
1379
1373
|
cell.readonly = "no-text-select";
|
|
1380
1374
|
}
|
|
1381
|
-
if (props.format ===
|
|
1375
|
+
if (props.format === Format3.TypeFormat.SingleSelect) {
|
|
1382
1376
|
const value = getValue3(obj, field.path);
|
|
1383
1377
|
const options = this.model.projection.getFieldProjection(field.id).props.options;
|
|
1384
1378
|
if (options) {
|
|
@@ -1388,7 +1382,7 @@ var TablePresentation = class {
|
|
|
1388
1382
|
}
|
|
1389
1383
|
}
|
|
1390
1384
|
}
|
|
1391
|
-
if (props.format ===
|
|
1385
|
+
if (props.format === Format3.TypeFormat.MultiSelect) {
|
|
1392
1386
|
const values = getValue3(obj, field.path);
|
|
1393
1387
|
const options = this.model.projection.getFieldProjection(field.id).props.options;
|
|
1394
1388
|
if (options && values && values.length > 0) {
|
|
@@ -1647,31 +1641,65 @@ var cellClassesForRowSelection = (selected, selectionMode) => {
|
|
|
1647
1641
|
}
|
|
1648
1642
|
};
|
|
1649
1643
|
|
|
1644
|
+
// src/hooks/useAddRow.ts
|
|
1645
|
+
import { useCallback } from "react";
|
|
1646
|
+
import { Obj as Obj4 } from "@dxos/echo";
|
|
1647
|
+
var useAddRow = ({ space, schema }) => {
|
|
1648
|
+
return useCallback((data) => {
|
|
1649
|
+
if (space && schema) {
|
|
1650
|
+
try {
|
|
1651
|
+
space.db.add(Obj4.make(schema, data ?? {}));
|
|
1652
|
+
return "final";
|
|
1653
|
+
} catch (error) {
|
|
1654
|
+
return "draft";
|
|
1655
|
+
}
|
|
1656
|
+
}
|
|
1657
|
+
return "final";
|
|
1658
|
+
}, [
|
|
1659
|
+
space,
|
|
1660
|
+
schema
|
|
1661
|
+
]);
|
|
1662
|
+
};
|
|
1663
|
+
|
|
1664
|
+
// src/hooks/useProjectionModel.ts
|
|
1665
|
+
import { useMemo } from "react";
|
|
1666
|
+
import { Type as Type2 } from "@dxos/echo";
|
|
1667
|
+
import { ProjectionModel as ProjectionModel2 } from "@dxos/schema";
|
|
1668
|
+
var useProjectionModel = (schema, table) => useMemo(() => {
|
|
1669
|
+
if (schema && table?.view.target?.projection) {
|
|
1670
|
+
const projection = new ProjectionModel2(Type2.toJsonSchema(schema), table.view.target.projection);
|
|
1671
|
+
projection.normalizeView();
|
|
1672
|
+
return projection;
|
|
1673
|
+
}
|
|
1674
|
+
}, [
|
|
1675
|
+
schema,
|
|
1676
|
+
table?.view.target?.projection
|
|
1677
|
+
]);
|
|
1678
|
+
|
|
1650
1679
|
// src/hooks/useTableModel.ts
|
|
1651
1680
|
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
1652
1681
|
import { effect as effect3 } from "@preact/signals-core";
|
|
1653
1682
|
import orderBy2 from "lodash.orderby";
|
|
1654
|
-
import { useEffect, useMemo, useState } from "react";
|
|
1655
|
-
import { Obj as
|
|
1683
|
+
import { useEffect, useMemo as useMemo2, useState } from "react";
|
|
1684
|
+
import { Obj as Obj5 } from "@dxos/echo";
|
|
1656
1685
|
import { useSelected, useSelectionActions } from "@dxos/react-ui-attention";
|
|
1657
1686
|
import { isNonNullable } from "@dxos/util";
|
|
1658
|
-
var useTableModel = ({
|
|
1687
|
+
var useTableModel = ({ object, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
|
|
1659
1688
|
var _effect = _useSignals();
|
|
1660
1689
|
try {
|
|
1661
|
-
const selected = useSelected(
|
|
1662
|
-
const initialSelection =
|
|
1663
|
-
|
|
1690
|
+
const selected = useSelected(object && Obj5.getDXN(object).toString(), "multi");
|
|
1691
|
+
const initialSelection = useMemo2(() => selected, [
|
|
1692
|
+
object
|
|
1664
1693
|
]);
|
|
1665
1694
|
const [model, setModel] = useState();
|
|
1666
1695
|
useEffect(() => {
|
|
1667
|
-
if (!
|
|
1696
|
+
if (!object || !projection) {
|
|
1668
1697
|
return;
|
|
1669
1698
|
}
|
|
1670
1699
|
let model2;
|
|
1671
1700
|
const t = setTimeout(async () => {
|
|
1672
1701
|
model2 = new TableModel({
|
|
1673
|
-
|
|
1674
|
-
schema,
|
|
1702
|
+
object,
|
|
1675
1703
|
projection,
|
|
1676
1704
|
features,
|
|
1677
1705
|
rowActions,
|
|
@@ -1687,8 +1715,7 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
|
|
|
1687
1715
|
void model2?.close();
|
|
1688
1716
|
};
|
|
1689
1717
|
}, [
|
|
1690
|
-
|
|
1691
|
-
schema,
|
|
1718
|
+
object,
|
|
1692
1719
|
projection,
|
|
1693
1720
|
features,
|
|
1694
1721
|
rowActions,
|
|
@@ -1735,26 +1762,6 @@ var useTableModel = ({ view, schema, projection, rows, rowActions, features, onS
|
|
|
1735
1762
|
}
|
|
1736
1763
|
};
|
|
1737
1764
|
|
|
1738
|
-
// src/hooks/useAddRow.ts
|
|
1739
|
-
import { useCallback } from "react";
|
|
1740
|
-
import { Obj as Obj5 } from "@dxos/echo";
|
|
1741
|
-
var useAddRow = ({ space, schema }) => {
|
|
1742
|
-
return useCallback((data) => {
|
|
1743
|
-
if (space && schema) {
|
|
1744
|
-
try {
|
|
1745
|
-
space.db.add(Obj5.make(schema, data ?? {}));
|
|
1746
|
-
return "final";
|
|
1747
|
-
} catch (error) {
|
|
1748
|
-
return "draft";
|
|
1749
|
-
}
|
|
1750
|
-
}
|
|
1751
|
-
return "final";
|
|
1752
|
-
}, [
|
|
1753
|
-
space,
|
|
1754
|
-
schema
|
|
1755
|
-
]);
|
|
1756
|
-
};
|
|
1757
|
-
|
|
1758
1765
|
export {
|
|
1759
1766
|
getBaseSchema,
|
|
1760
1767
|
makeDynamicTable,
|
|
@@ -1770,7 +1777,8 @@ export {
|
|
|
1770
1777
|
ModalController,
|
|
1771
1778
|
TablePresentation,
|
|
1772
1779
|
cellClassesForRowSelection,
|
|
1773
|
-
|
|
1774
|
-
|
|
1780
|
+
useAddRow,
|
|
1781
|
+
useProjectionModel,
|
|
1782
|
+
useTableModel
|
|
1775
1783
|
};
|
|
1776
|
-
//# sourceMappingURL=chunk-
|
|
1784
|
+
//# sourceMappingURL=chunk-CWSGS3Y2.mjs.map
|