@dxos/react-ui-table 0.7.5-main.499c70c → 0.7.5-main.937ce75
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/index.mjs +158 -117
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node/index.cjs +146 -102
- package/dist/lib/node/index.cjs.map +4 -4
- package/dist/lib/node/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +158 -117
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/Table/CreateRefPanel.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +6 -15
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +48 -0
- package/dist/types/src/model/table-sorting.d.ts.map +1 -0
- package/package.json +29 -29
- package/src/components/Table/CreateRefPanel.tsx +3 -4
- package/src/model/table-model.ts +28 -86
- package/src/model/table-presentation.ts +5 -2
- package/src/model/table-sorting.ts +131 -0
- package/src/playwright/smoke.spec.ts +16 -1
|
@@ -36,7 +36,7 @@ var translations_default = [
|
|
|
36
36
|
|
|
37
37
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
38
38
|
import React7, { forwardRef, useCallback as useCallback4, useImperativeHandle, useState as useState2, useMemo as useMemo4 } from "react";
|
|
39
|
-
import { getValue as
|
|
39
|
+
import { getValue as getValue4 } from "@dxos/echo-schema";
|
|
40
40
|
import { invariant as invariant3 } from "@dxos/invariant";
|
|
41
41
|
import { Filter, getSpace as getSpace4, fullyQualifiedId } from "@dxos/react-client/echo";
|
|
42
42
|
import { useTranslation as useTranslation3 } from "@dxos/react-ui";
|
|
@@ -164,7 +164,9 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
|
164
164
|
if (!space || state?.type !== "createRefPanel") {
|
|
165
165
|
return;
|
|
166
166
|
}
|
|
167
|
-
const schema2 = space.db.schemaRegistry.
|
|
167
|
+
const [schema2] = space.db.schemaRegistry.query({
|
|
168
|
+
typename: state.typename
|
|
169
|
+
}).runSync();
|
|
168
170
|
if (schema2) {
|
|
169
171
|
const omit = S.omit("id");
|
|
170
172
|
return omit(schema2);
|
|
@@ -177,7 +179,9 @@ var CreateRefPanel = ({ model, modals, __gridScope }) => {
|
|
|
177
179
|
if (!model || !space || state?.type !== "createRefPanel") {
|
|
178
180
|
return;
|
|
179
181
|
}
|
|
180
|
-
const schema2 = space.db.schemaRegistry.
|
|
182
|
+
const [schema2] = space.db.schemaRegistry.query({
|
|
183
|
+
typename: state.typename
|
|
184
|
+
}).runSync();
|
|
181
185
|
if (schema2) {
|
|
182
186
|
const obj = space.db.add(create(schema2, values));
|
|
183
187
|
state.onCreate?.(obj);
|
|
@@ -281,14 +285,13 @@ var RowActionsMenu = ({ model, modals }) => {
|
|
|
281
285
|
};
|
|
282
286
|
|
|
283
287
|
// packages/ui/react-ui-table/src/model/table-model.ts
|
|
284
|
-
import { computed as
|
|
285
|
-
import orderBy from "lodash.orderby";
|
|
288
|
+
import { computed as computed3, effect as effect2, signal as signal3 } from "@preact/signals-core";
|
|
286
289
|
import { Resource as Resource2 } from "@dxos/context";
|
|
287
|
-
import { getValue, setValue, FormatEnum as
|
|
290
|
+
import { getValue as getValue2, setValue, FormatEnum as FormatEnum3 } from "@dxos/echo-schema";
|
|
288
291
|
import { invariant } from "@dxos/invariant";
|
|
289
292
|
import { isReactiveObject, makeRef as makeRef2 } from "@dxos/live-object";
|
|
290
293
|
import { PublicKey as PublicKey2 } from "@dxos/react-client";
|
|
291
|
-
import {
|
|
294
|
+
import { formatForEditing, parseValue } from "@dxos/react-ui-form";
|
|
292
295
|
|
|
293
296
|
// packages/ui/react-ui-table/src/model/selection-model.ts
|
|
294
297
|
import { computed, effect, signal } from "@preact/signals-core";
|
|
@@ -592,6 +595,99 @@ var SelectionModel = class extends Resource {
|
|
|
592
595
|
}
|
|
593
596
|
};
|
|
594
597
|
|
|
598
|
+
// packages/ui/react-ui-table/src/model/table-sorting.ts
|
|
599
|
+
import { computed as computed2, signal as signal2 } from "@preact/signals-core";
|
|
600
|
+
import orderBy from "lodash.orderby";
|
|
601
|
+
import { getValue, FormatEnum as FormatEnum2, TypeEnum as TypeEnum2 } from "@dxos/echo-schema";
|
|
602
|
+
import { formatForDisplay } from "@dxos/react-ui-form";
|
|
603
|
+
var TableSorting = class {
|
|
604
|
+
constructor(rows, _table, _projection) {
|
|
605
|
+
this._table = _table;
|
|
606
|
+
this._projection = _projection;
|
|
607
|
+
this._displayToDataIndex = /* @__PURE__ */ new Map();
|
|
608
|
+
this._sorting = signal2(void 0);
|
|
609
|
+
this._rows = rows;
|
|
610
|
+
this.sortedRows = this.initialiseSortedRows();
|
|
611
|
+
}
|
|
612
|
+
/**
|
|
613
|
+
* @reactive
|
|
614
|
+
*/
|
|
615
|
+
get sorting() {
|
|
616
|
+
return this._sorting.value;
|
|
617
|
+
}
|
|
618
|
+
getDataIndex(displayIndex) {
|
|
619
|
+
return this._displayToDataIndex.get(displayIndex) ?? displayIndex;
|
|
620
|
+
}
|
|
621
|
+
setSort(fieldId, direction) {
|
|
622
|
+
this._sorting.value = {
|
|
623
|
+
fieldId,
|
|
624
|
+
direction
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
//
|
|
628
|
+
// Initialisation.
|
|
629
|
+
//
|
|
630
|
+
initialiseSortedRows() {
|
|
631
|
+
return computed2(() => {
|
|
632
|
+
this._displayToDataIndex.clear();
|
|
633
|
+
const sort = this._sorting.value;
|
|
634
|
+
if (!sort) {
|
|
635
|
+
return this._rows.value;
|
|
636
|
+
}
|
|
637
|
+
const field = this._table.view?.target?.fields.find((f) => f.id === sort.fieldId);
|
|
638
|
+
if (!field) {
|
|
639
|
+
return this._rows.value;
|
|
640
|
+
}
|
|
641
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
642
|
+
const dataWithIndices = this._rows.value.map((item, index) => {
|
|
643
|
+
const sortValue = this.getSortValue(props, field, item);
|
|
644
|
+
const isEmpty = !(props.type === TypeEnum2.Boolean) && (sortValue == null || sortValue === "");
|
|
645
|
+
return {
|
|
646
|
+
item,
|
|
647
|
+
index,
|
|
648
|
+
value: sortValue,
|
|
649
|
+
isEmpty
|
|
650
|
+
};
|
|
651
|
+
});
|
|
652
|
+
const ordered = orderBy(dataWithIndices, [
|
|
653
|
+
"isEmpty",
|
|
654
|
+
"value"
|
|
655
|
+
], [
|
|
656
|
+
"asc",
|
|
657
|
+
sort.direction
|
|
658
|
+
]);
|
|
659
|
+
ordered.forEach(({ index: dataIndex }, displayIndex) => {
|
|
660
|
+
if (displayIndex !== dataIndex) {
|
|
661
|
+
this._displayToDataIndex.set(displayIndex, dataIndex);
|
|
662
|
+
}
|
|
663
|
+
});
|
|
664
|
+
return ordered.map(({ item }) => item);
|
|
665
|
+
});
|
|
666
|
+
}
|
|
667
|
+
getSortValue(props, field, item) {
|
|
668
|
+
const { type, format } = props;
|
|
669
|
+
const value = getValue(item, field.path);
|
|
670
|
+
if (type === TypeEnum2.Boolean) {
|
|
671
|
+
return !!value;
|
|
672
|
+
}
|
|
673
|
+
if (type === TypeEnum2.Number) {
|
|
674
|
+
return value;
|
|
675
|
+
}
|
|
676
|
+
if (value == null) {
|
|
677
|
+
return value;
|
|
678
|
+
}
|
|
679
|
+
if (format === FormatEnum2.Ref && field.referencePath) {
|
|
680
|
+
const refValue = getValue(value.target, field.referencePath);
|
|
681
|
+
return refValue;
|
|
682
|
+
}
|
|
683
|
+
return formatForDisplay({
|
|
684
|
+
type,
|
|
685
|
+
format,
|
|
686
|
+
value
|
|
687
|
+
});
|
|
688
|
+
}
|
|
689
|
+
};
|
|
690
|
+
|
|
595
691
|
// packages/ui/react-ui-table/src/model/table-model.ts
|
|
596
692
|
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
|
|
597
693
|
var TableModel = class extends Resource2 {
|
|
@@ -601,7 +697,7 @@ var TableModel = class extends Resource2 {
|
|
|
601
697
|
}, onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChanged }) {
|
|
602
698
|
super();
|
|
603
699
|
this.id = `table-model-${PublicKey2.random().truncate()}`;
|
|
604
|
-
this._visibleRange =
|
|
700
|
+
this._visibleRange = signal3({
|
|
605
701
|
start: {
|
|
606
702
|
row: 0,
|
|
607
703
|
col: 0
|
|
@@ -611,14 +707,7 @@ var TableModel = class extends Resource2 {
|
|
|
611
707
|
col: 0
|
|
612
708
|
}
|
|
613
709
|
});
|
|
614
|
-
|
|
615
|
-
* Maps display indices to data indices.
|
|
616
|
-
* Used for translating between sorted/displayed order and original data order.
|
|
617
|
-
* Keys are display indices, values are corresponding data indices.
|
|
618
|
-
*/
|
|
619
|
-
this._displayToDataIndex = /* @__PURE__ */ new Map();
|
|
620
|
-
this._sorting = signal2(void 0);
|
|
621
|
-
this._rows = signal2([]);
|
|
710
|
+
this._rows = signal3([]);
|
|
622
711
|
//
|
|
623
712
|
// Data
|
|
624
713
|
//
|
|
@@ -628,11 +717,11 @@ var TableModel = class extends Resource2 {
|
|
|
628
717
|
this.getRowCount = () => this._rows.value.length;
|
|
629
718
|
this.getColumnCount = () => this.table.view?.target?.fields.length ?? 0;
|
|
630
719
|
this.insertRow = (rowIndex) => {
|
|
631
|
-
const row = rowIndex !== void 0 ? this.
|
|
720
|
+
const row = rowIndex !== void 0 ? this._sorting.getDataIndex(rowIndex) : this._rows.value.length;
|
|
632
721
|
this._onInsertRow?.(row);
|
|
633
722
|
};
|
|
634
723
|
this.deleteRow = (rowIndex) => {
|
|
635
|
-
const row = this.
|
|
724
|
+
const row = this._sorting.getDataIndex(rowIndex);
|
|
636
725
|
const obj = this._rows.value[row];
|
|
637
726
|
const objectsToDelete = [];
|
|
638
727
|
if (this._selection.hasSelection.value) {
|
|
@@ -649,18 +738,18 @@ var TableModel = class extends Resource2 {
|
|
|
649
738
|
return void 0;
|
|
650
739
|
}
|
|
651
740
|
const field = fields[col];
|
|
652
|
-
const dataIndex = this.
|
|
653
|
-
const value =
|
|
741
|
+
const dataIndex = this._sorting.getDataIndex(row);
|
|
742
|
+
const value = getValue2(this._rows.value[dataIndex], field.path);
|
|
654
743
|
if (value == null) {
|
|
655
744
|
return "";
|
|
656
745
|
}
|
|
657
746
|
const { props } = this._projection.getFieldProjection(field.id);
|
|
658
747
|
switch (props.format) {
|
|
659
|
-
case
|
|
748
|
+
case FormatEnum3.Ref: {
|
|
660
749
|
if (!field.referencePath) {
|
|
661
750
|
return "";
|
|
662
751
|
}
|
|
663
|
-
return
|
|
752
|
+
return getValue2(value.target, field.referencePath);
|
|
664
753
|
}
|
|
665
754
|
default: {
|
|
666
755
|
return formatForEditing({
|
|
@@ -672,7 +761,7 @@ var TableModel = class extends Resource2 {
|
|
|
672
761
|
}
|
|
673
762
|
};
|
|
674
763
|
this.setCellData = ({ col, row }, value) => {
|
|
675
|
-
const rowIdx = this.
|
|
764
|
+
const rowIdx = this._sorting.getDataIndex(row);
|
|
676
765
|
const fields = this.table.view?.target?.fields ?? [];
|
|
677
766
|
if (col < 0 || col >= fields.length) {
|
|
678
767
|
return;
|
|
@@ -680,7 +769,7 @@ var TableModel = class extends Resource2 {
|
|
|
680
769
|
const field = fields[col];
|
|
681
770
|
const { props } = this._projection.getFieldProjection(field.id);
|
|
682
771
|
switch (props.format) {
|
|
683
|
-
case
|
|
772
|
+
case FormatEnum3.Ref: {
|
|
684
773
|
if (isReactiveObject(value)) {
|
|
685
774
|
setValue(this._rows.value[rowIdx], field.path, makeRef2(value));
|
|
686
775
|
}
|
|
@@ -698,7 +787,11 @@ var TableModel = class extends Resource2 {
|
|
|
698
787
|
};
|
|
699
788
|
this._table = table;
|
|
700
789
|
this._projection = projection;
|
|
701
|
-
this._sorting
|
|
790
|
+
this._sorting = new TableSorting(this._rows, table, projection);
|
|
791
|
+
if (sorting.length > 0) {
|
|
792
|
+
const [sort] = sorting;
|
|
793
|
+
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
794
|
+
}
|
|
702
795
|
this._pinnedRows = pinnedRows;
|
|
703
796
|
this._onInsertRow = onInsertRow;
|
|
704
797
|
this._onDeleteRows = onDeleteRows;
|
|
@@ -713,7 +806,13 @@ var TableModel = class extends Resource2 {
|
|
|
713
806
|
return this._projection;
|
|
714
807
|
}
|
|
715
808
|
get rows() {
|
|
716
|
-
return this.
|
|
809
|
+
return this._sorting.sortedRows;
|
|
810
|
+
}
|
|
811
|
+
/**
|
|
812
|
+
* @reactive
|
|
813
|
+
*/
|
|
814
|
+
get sorting() {
|
|
815
|
+
return this._sorting.sorting;
|
|
717
816
|
}
|
|
718
817
|
get pinnedRows() {
|
|
719
818
|
return this._pinnedRows;
|
|
@@ -730,9 +829,6 @@ var TableModel = class extends Resource2 {
|
|
|
730
829
|
});
|
|
731
830
|
return this._columnMeta;
|
|
732
831
|
}
|
|
733
|
-
get sorting() {
|
|
734
|
-
return this._sorting.value;
|
|
735
|
-
}
|
|
736
832
|
get selection() {
|
|
737
833
|
return this._selection;
|
|
738
834
|
}
|
|
@@ -741,13 +837,12 @@ var TableModel = class extends Resource2 {
|
|
|
741
837
|
//
|
|
742
838
|
async _open() {
|
|
743
839
|
this.initializeColumnMeta();
|
|
744
|
-
this.initializeSorting();
|
|
745
840
|
this.initializeEffects();
|
|
746
|
-
this._selection = new SelectionModel(this.
|
|
841
|
+
this._selection = new SelectionModel(this._sorting.sortedRows, () => this._onRowOrderChanged?.());
|
|
747
842
|
await this._selection.open(this._ctx);
|
|
748
843
|
}
|
|
749
844
|
initializeColumnMeta() {
|
|
750
|
-
this._columnMeta =
|
|
845
|
+
this._columnMeta = computed3(() => {
|
|
751
846
|
const fields = this._table.view?.target?.fields ?? [];
|
|
752
847
|
const meta = Object.fromEntries(fields.map((field, index) => [
|
|
753
848
|
index,
|
|
@@ -773,60 +868,9 @@ var TableModel = class extends Resource2 {
|
|
|
773
868
|
};
|
|
774
869
|
});
|
|
775
870
|
}
|
|
776
|
-
initializeSorting() {
|
|
777
|
-
this._sortedRows = computed2(() => {
|
|
778
|
-
this._displayToDataIndex.clear();
|
|
779
|
-
const sort = this._sorting.value;
|
|
780
|
-
if (!sort) {
|
|
781
|
-
return this._rows.value;
|
|
782
|
-
}
|
|
783
|
-
const field = this._table.view?.target?.fields.find((field2) => field2.id === sort.fieldId);
|
|
784
|
-
if (!field) {
|
|
785
|
-
return this._rows.value;
|
|
786
|
-
}
|
|
787
|
-
const { props } = this._projection.getFieldProjection(field.id);
|
|
788
|
-
const dataWithIndices = this._rows.value.map((item, index) => {
|
|
789
|
-
const rawValue = getValue(item, field.path);
|
|
790
|
-
let sortValue = rawValue;
|
|
791
|
-
if (props.type.startsWith("boolean")) {
|
|
792
|
-
sortValue = !!rawValue;
|
|
793
|
-
} else if (rawValue != null) {
|
|
794
|
-
if (props.format === FormatEnum2.Ref && field.referencePath) {
|
|
795
|
-
sortValue = getValue(rawValue, field.referencePath);
|
|
796
|
-
} else {
|
|
797
|
-
sortValue = formatForDisplay({
|
|
798
|
-
type: props.type,
|
|
799
|
-
format: props.format,
|
|
800
|
-
value: rawValue
|
|
801
|
-
});
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
return {
|
|
805
|
-
item,
|
|
806
|
-
index,
|
|
807
|
-
value: sortValue,
|
|
808
|
-
isEmpty: !props.type.startsWith("boolean") && (sortValue == null || sortValue === "")
|
|
809
|
-
};
|
|
810
|
-
});
|
|
811
|
-
const sorted = orderBy(dataWithIndices, [
|
|
812
|
-
"isEmpty",
|
|
813
|
-
"value"
|
|
814
|
-
], [
|
|
815
|
-
"asc",
|
|
816
|
-
sort.direction
|
|
817
|
-
]);
|
|
818
|
-
for (let displayIndex = 0; displayIndex < sorted.length; displayIndex++) {
|
|
819
|
-
const { index: dataIndex } = sorted[displayIndex];
|
|
820
|
-
if (displayIndex !== dataIndex) {
|
|
821
|
-
this._displayToDataIndex.set(displayIndex, dataIndex);
|
|
822
|
-
}
|
|
823
|
-
}
|
|
824
|
-
return sorted.map(({ item }) => item);
|
|
825
|
-
});
|
|
826
|
-
}
|
|
827
871
|
initializeEffects() {
|
|
828
872
|
const rowOrderWatcher = effect2(() => {
|
|
829
|
-
touch(this.
|
|
873
|
+
touch(this._sorting.sortedRows.value);
|
|
830
874
|
this._onRowOrderChanged?.();
|
|
831
875
|
});
|
|
832
876
|
this._ctx.onDispose(rowOrderWatcher);
|
|
@@ -835,8 +879,8 @@ var TableModel = class extends Resource2 {
|
|
|
835
879
|
const rowEffects = [];
|
|
836
880
|
for (let row = start.row; row <= end.row; row++) {
|
|
837
881
|
rowEffects.push(effect2(() => {
|
|
838
|
-
const obj = this.
|
|
839
|
-
this?._table?.view?.target?.fields.forEach((field) => touch(
|
|
882
|
+
const obj = this._sorting.sortedRows.value[row];
|
|
883
|
+
this?._table?.view?.target?.fields.forEach((field) => touch(getValue2(obj, field.path)));
|
|
840
884
|
this._onCellUpdate?.({
|
|
841
885
|
row,
|
|
842
886
|
col: start.col,
|
|
@@ -854,10 +898,10 @@ var TableModel = class extends Resource2 {
|
|
|
854
898
|
* @param {(value: any) => any} update - A function that takes the current value and returns the updated value.
|
|
855
899
|
*/
|
|
856
900
|
updateCellData({ col, row }, update) {
|
|
857
|
-
const dataRow = this.
|
|
901
|
+
const dataRow = this._sorting.getDataIndex(row);
|
|
858
902
|
const fields = this.table.view?.target?.fields ?? [];
|
|
859
903
|
const field = fields[col];
|
|
860
|
-
const value =
|
|
904
|
+
const value = getValue2(this._rows.value[dataRow], field.path);
|
|
861
905
|
const updatedValue = update(value);
|
|
862
906
|
setValue(this._rows.value[dataRow], field.path, updatedValue);
|
|
863
907
|
}
|
|
@@ -870,9 +914,6 @@ var TableModel = class extends Resource2 {
|
|
|
870
914
|
}
|
|
871
915
|
const field = this.table.view.target?.fields.find((field2) => field2.id === fieldId);
|
|
872
916
|
if (field && this._onDeleteColumn) {
|
|
873
|
-
if (this._sorting.value?.fieldId === fieldId) {
|
|
874
|
-
this.clearSort();
|
|
875
|
-
}
|
|
876
917
|
this._onDeleteColumn(field.id);
|
|
877
918
|
}
|
|
878
919
|
}
|
|
@@ -893,13 +934,10 @@ var TableModel = class extends Resource2 {
|
|
|
893
934
|
// Sorting
|
|
894
935
|
//
|
|
895
936
|
setSort(fieldId, direction) {
|
|
896
|
-
this._sorting.
|
|
897
|
-
fieldId,
|
|
898
|
-
direction
|
|
899
|
-
};
|
|
937
|
+
this._sorting.setSort(fieldId, direction);
|
|
900
938
|
}
|
|
901
939
|
clearSort() {
|
|
902
|
-
this._sorting.
|
|
940
|
+
this._sorting.setSort("", "asc");
|
|
903
941
|
}
|
|
904
942
|
//
|
|
905
943
|
// Pinning
|
|
@@ -915,12 +953,12 @@ var TableModel = class extends Resource2 {
|
|
|
915
953
|
};
|
|
916
954
|
|
|
917
955
|
// packages/ui/react-ui-table/src/model/modal-controller.ts
|
|
918
|
-
import { signal as
|
|
956
|
+
import { signal as signal4 } from "@preact/signals-core";
|
|
919
957
|
import { log as log2 } from "@dxos/log";
|
|
920
958
|
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/model/modal-controller.ts";
|
|
921
959
|
var ModalController = class {
|
|
922
960
|
constructor() {
|
|
923
|
-
this._state =
|
|
961
|
+
this._state = signal4({
|
|
924
962
|
type: "closed"
|
|
925
963
|
});
|
|
926
964
|
this._triggerRef = {
|
|
@@ -1003,14 +1041,14 @@ var ModalController = class {
|
|
|
1003
1041
|
};
|
|
1004
1042
|
|
|
1005
1043
|
// packages/ui/react-ui-table/src/model/table-presentation.ts
|
|
1006
|
-
import { signal as
|
|
1007
|
-
import { FormatEnum as
|
|
1044
|
+
import { signal as signal5 } from "@preact/signals-core";
|
|
1045
|
+
import { FormatEnum as FormatEnum4, getValue as getValue3 } from "@dxos/echo-schema";
|
|
1008
1046
|
import { cellClassesForFieldType, cellClassesForRowSelection, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
|
|
1009
1047
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
1010
1048
|
import { mx } from "@dxos/react-ui-theme";
|
|
1011
1049
|
import { VIEW_FIELD_LIMIT } from "@dxos/schema";
|
|
1012
1050
|
var TablePresentation = class {
|
|
1013
|
-
constructor(model, _visibleRange =
|
|
1051
|
+
constructor(model, _visibleRange = signal5({
|
|
1014
1052
|
start: {
|
|
1015
1053
|
row: 0,
|
|
1016
1054
|
col: 0
|
|
@@ -1049,19 +1087,19 @@ var TablePresentation = class {
|
|
|
1049
1087
|
const { props } = this.model.projection.getFieldProjection(field.id);
|
|
1050
1088
|
const cell = {
|
|
1051
1089
|
get value() {
|
|
1052
|
-
const value =
|
|
1090
|
+
const value = getValue3(obj, field.path);
|
|
1053
1091
|
if (value == null) {
|
|
1054
1092
|
return "";
|
|
1055
1093
|
}
|
|
1056
1094
|
switch (props.format) {
|
|
1057
|
-
case
|
|
1095
|
+
case FormatEnum4.Boolean: {
|
|
1058
1096
|
return "";
|
|
1059
1097
|
}
|
|
1060
|
-
case
|
|
1098
|
+
case FormatEnum4.Ref: {
|
|
1061
1099
|
if (!field.referencePath) {
|
|
1062
1100
|
return "";
|
|
1063
1101
|
}
|
|
1064
|
-
return
|
|
1102
|
+
return getValue3(value.target, field.referencePath);
|
|
1065
1103
|
}
|
|
1066
1104
|
default: {
|
|
1067
1105
|
return formatForDisplay2({
|
|
@@ -1088,8 +1126,8 @@ var TablePresentation = class {
|
|
|
1088
1126
|
if (classes.length > 0) {
|
|
1089
1127
|
cell.className = mx(classes.flat());
|
|
1090
1128
|
}
|
|
1091
|
-
if (props.format ===
|
|
1092
|
-
const targetObj =
|
|
1129
|
+
if (props.format === FormatEnum4.Ref && props.referenceSchema) {
|
|
1130
|
+
const targetObj = getValue3(obj, field.path)?.target;
|
|
1093
1131
|
if (targetObj) {
|
|
1094
1132
|
cell.accessoryHtml = tableButtons.referencedCell.render({
|
|
1095
1133
|
targetId: targetObj.id,
|
|
@@ -1097,8 +1135,8 @@ var TablePresentation = class {
|
|
|
1097
1135
|
});
|
|
1098
1136
|
}
|
|
1099
1137
|
}
|
|
1100
|
-
if (props.format ===
|
|
1101
|
-
const value =
|
|
1138
|
+
if (props.format === FormatEnum4.Boolean) {
|
|
1139
|
+
const value = getValue3(obj, field.path);
|
|
1102
1140
|
cell.accessoryHtml = tableControls.switch.render({
|
|
1103
1141
|
colIndex,
|
|
1104
1142
|
rowIndex: displayIndex,
|
|
@@ -1138,7 +1176,8 @@ var TablePresentation = class {
|
|
|
1138
1176
|
resizeHandle: "col",
|
|
1139
1177
|
accessoryHtml: tableButtons.columnSettings.render({
|
|
1140
1178
|
fieldId: field.id
|
|
1141
|
-
})
|
|
1179
|
+
}),
|
|
1180
|
+
className: "!bg-gridHeader"
|
|
1142
1181
|
};
|
|
1143
1182
|
}
|
|
1144
1183
|
return cells;
|
|
@@ -1188,13 +1227,14 @@ var TablePresentation = class {
|
|
|
1188
1227
|
col: 0,
|
|
1189
1228
|
row: 0
|
|
1190
1229
|
})]: {
|
|
1191
|
-
value: "",
|
|
1192
1230
|
accessoryHtml: tableControls.checkbox.render({
|
|
1193
1231
|
rowIndex: 0,
|
|
1194
1232
|
header: true,
|
|
1195
1233
|
checked: this.model.selection.allRowsSeleted.value
|
|
1196
1234
|
}),
|
|
1197
|
-
|
|
1235
|
+
className: "!bg-gridHeader",
|
|
1236
|
+
readonly: true,
|
|
1237
|
+
value: ""
|
|
1198
1238
|
}
|
|
1199
1239
|
};
|
|
1200
1240
|
}
|
|
@@ -1204,11 +1244,12 @@ var TablePresentation = class {
|
|
|
1204
1244
|
col: 0,
|
|
1205
1245
|
row: 0
|
|
1206
1246
|
})]: {
|
|
1207
|
-
value: "",
|
|
1208
1247
|
accessoryHtml: tableButtons.addColumn.render({
|
|
1209
1248
|
disabled: (this.model.table.view?.target?.fields?.length ?? 0) >= VIEW_FIELD_LIMIT
|
|
1210
1249
|
}),
|
|
1211
|
-
|
|
1250
|
+
className: "!bg-gridHeader",
|
|
1251
|
+
readonly: true,
|
|
1252
|
+
value: ""
|
|
1212
1253
|
}
|
|
1213
1254
|
};
|
|
1214
1255
|
}
|
|
@@ -1216,7 +1257,7 @@ var TablePresentation = class {
|
|
|
1216
1257
|
|
|
1217
1258
|
// packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
|
|
1218
1259
|
import React6, { useCallback as useCallback3, useMemo as useMemo3, useRef } from "react";
|
|
1219
|
-
import { FormatEnum as
|
|
1260
|
+
import { FormatEnum as FormatEnum5 } from "@dxos/echo-schema";
|
|
1220
1261
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1221
1262
|
import { cellQuery, editorKeys, parseCellIndex, useGridContext as useGridContext2, GridCellEditor } from "@dxos/react-ui-grid";
|
|
1222
1263
|
|
|
@@ -1352,7 +1393,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1352
1393
|
];
|
|
1353
1394
|
if (onQuery) {
|
|
1354
1395
|
switch (fieldProjection.props.format) {
|
|
1355
|
-
case
|
|
1396
|
+
case FormatEnum5.Ref: {
|
|
1356
1397
|
extension2.push([
|
|
1357
1398
|
completion({
|
|
1358
1399
|
onQuery: (text) => onQuery(fieldProjection, text),
|
|
@@ -1608,7 +1649,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1608
1649
|
if (schema) {
|
|
1609
1650
|
const { objects } = await space.db.query(Filter.schema(schema)).run();
|
|
1610
1651
|
const options = objects.map((obj) => {
|
|
1611
|
-
const value =
|
|
1652
|
+
const value = getValue4(obj, field.referencePath);
|
|
1612
1653
|
if (!value || typeof value !== "string") {
|
|
1613
1654
|
return void 0;
|
|
1614
1655
|
}
|