@dxos/react-ui-table 0.8.1-staging.5be625a → 0.8.1-staging.9eaf14f
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-5MKYB7NF.mjs → chunk-YWNRUF4J.mjs} +7 -3
- package/dist/lib/browser/{chunk-5MKYB7NF.mjs.map → chunk-YWNRUF4J.mjs.map} +3 -3
- package/dist/lib/browser/index.mjs +295 -97
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +1 -1
- package/dist/lib/node/{chunk-NRFKBRPV.cjs → chunk-TGG6OZ54.cjs} +10 -6
- package/dist/lib/node/{chunk-NRFKBRPV.cjs.map → chunk-TGG6OZ54.cjs.map} +3 -3
- package/dist/lib/node/index.cjs +293 -93
- package/dist/lib/node/index.cjs.map +3 -3
- 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-SU4D55KI.mjs → chunk-KKLP54L3.mjs} +7 -3
- package/dist/lib/node-esm/{chunk-SU4D55KI.mjs.map → chunk-KKLP54L3.mjs.map} +3 -3
- package/dist/lib/node-esm/index.mjs +295 -97
- package/dist/lib/node-esm/index.mjs.map +3 -3
- 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/DynamicTable.d.ts +15 -10
- package/dist/types/src/components/Table/DynamicTable.d.ts.map +1 -1
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts +10 -0
- package/dist/types/src/components/Table/DynamicTable.stories.d.ts.map +1 -0
- package/dist/types/src/components/Table/Table.d.ts +1 -1
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +2 -3
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/relations.stories.d.ts +9 -0
- package/dist/types/src/components/Table/relations.stories.d.ts.map +1 -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/testing.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +6 -10
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -1
- package/dist/types/src/model/index.d.ts +1 -0
- package/dist/types/src/model/index.d.ts.map +1 -1
- package/dist/types/src/model/selection-model.d.ts +6 -3
- package/dist/types/src/model/selection-model.d.ts.map +1 -1
- package/dist/types/src/model/table-model.d.ts +13 -14
- package/dist/types/src/model/table-model.d.ts.map +1 -1
- package/dist/types/src/model/table-presentation.d.ts +4 -4
- package/dist/types/src/model/table-presentation.d.ts.map +1 -1
- package/dist/types/src/model/table-sorting.d.ts +2 -2
- package/dist/types/src/model/table-sorting.d.ts.map +1 -1
- package/dist/types/src/types/table.d.ts +2 -1
- package/dist/types/src/types/table.d.ts.map +1 -1
- package/dist/types/src/util/dynamic-table.d.ts +21 -30
- package/dist/types/src/util/dynamic-table.d.ts.map +1 -1
- package/dist/types/src/util/table-controls.d.ts +2 -2
- package/dist/types/src/util/table-controls.d.ts.map +1 -1
- package/dist/types/src/util/table.d.ts.map +1 -1
- package/package.json +33 -32
- package/src/components/Table/DynamicTable.stories.tsx +155 -0
- package/src/components/Table/DynamicTable.tsx +46 -28
- package/src/components/Table/Table.stories.tsx +129 -125
- package/src/components/Table/Table.tsx +51 -26
- package/src/components/Table/relations.stories.tsx +113 -0
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +8 -3
- package/src/components/TableCellEditor/TableCellEditor.tsx +102 -4
- package/src/components/testing.ts +0 -1
- package/src/hooks/useTableModel.ts +11 -11
- package/src/model/index.ts +1 -0
- package/src/model/selection-model.ts +12 -2
- package/src/model/table-model.test.ts +1 -1
- package/src/model/table-model.ts +27 -18
- package/src/model/table-presentation.test.ts +1 -1
- package/src/model/table-presentation.ts +65 -11
- package/src/model/table-sorting.ts +2 -2
- package/src/playwright/smoke.spec.ts +2 -3
- package/src/types/table.ts +6 -5
- package/src/util/dynamic-table.ts +57 -25
- package/src/util/table-controls.ts +4 -4
- package/src/util/table.ts +2 -1
- package/dist/lib/browser/deprecated/index.mjs +0 -1483
- package/dist/lib/browser/deprecated/index.mjs.map +0 -7
- package/dist/lib/node/deprecated/index.cjs +0 -1511
- package/dist/lib/node/deprecated/index.cjs.map +0 -7
- package/dist/lib/node-esm/deprecated/index.mjs +0 -1485
- package/dist/lib/node-esm/deprecated/index.mjs.map +0 -7
- package/dist/types/src/deprecated/components/Cell/Cell.d.ts +0 -12
- package/dist/types/src/deprecated/components/Cell/Cell.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Cell/CellCombobox.d.ts +0 -13
- package/dist/types/src/deprecated/components/Cell/CellCombobox.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Cell/index.d.ts +0 -2
- package/dist/types/src/deprecated/components/Cell/index.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.d.ts +0 -23
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts +0 -36
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.d.ts +0 -15
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts +0 -84
- package/dist/types/src/deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/ColumnMenu/index.d.ts +0 -3
- package/dist/types/src/deprecated/components/ColumnMenu/index.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Table/Table.d.ts +0 -20
- package/dist/types/src/deprecated/components/Table/Table.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Table/Table.stories.d.ts +0 -116
- package/dist/types/src/deprecated/components/Table/Table.stories.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Table/TableBody.d.ts +0 -12
- package/dist/types/src/deprecated/components/Table/TableBody.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Table/TableContext.d.ts +0 -13
- package/dist/types/src/deprecated/components/Table/TableContext.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Table/TableHead.d.ts +0 -9
- package/dist/types/src/deprecated/components/Table/TableHead.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Table/TableRootContext.d.ts +0 -17
- package/dist/types/src/deprecated/components/Table/TableRootContext.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Table/index.d.ts +0 -5
- package/dist/types/src/deprecated/components/Table/index.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/Table/props.d.ts +0 -42
- package/dist/types/src/deprecated/components/Table/props.d.ts.map +0 -1
- package/dist/types/src/deprecated/components/index.d.ts +0 -4
- package/dist/types/src/deprecated/components/index.d.ts.map +0 -1
- package/dist/types/src/deprecated/helpers.d.ts +0 -91
- package/dist/types/src/deprecated/helpers.d.ts.map +0 -1
- package/dist/types/src/deprecated/hooks/index.d.ts +0 -5
- package/dist/types/src/deprecated/hooks/index.d.ts.map +0 -1
- package/dist/types/src/deprecated/hooks/useColumnSizing.d.ts +0 -12
- package/dist/types/src/deprecated/hooks/useColumnSizing.d.ts.map +0 -1
- package/dist/types/src/deprecated/hooks/useColumnSorting.d.ts +0 -15
- package/dist/types/src/deprecated/hooks/useColumnSorting.d.ts.map +0 -1
- package/dist/types/src/deprecated/hooks/usePinLastRow.d.ts +0 -3
- package/dist/types/src/deprecated/hooks/usePinLastRow.d.ts.map +0 -1
- package/dist/types/src/deprecated/hooks/useRowSelection.d.ts +0 -7
- package/dist/types/src/deprecated/hooks/useRowSelection.d.ts.map +0 -1
- package/dist/types/src/deprecated/index.d.ts +0 -8
- package/dist/types/src/deprecated/index.d.ts.map +0 -1
- package/dist/types/src/deprecated/schema/Schema.stories.d.ts +0 -11
- package/dist/types/src/deprecated/schema/Schema.stories.d.ts.map +0 -1
- package/dist/types/src/deprecated/schema/column-utils.d.ts +0 -7
- package/dist/types/src/deprecated/schema/column-utils.d.ts.map +0 -1
- package/dist/types/src/deprecated/schema/index.d.ts +0 -3
- package/dist/types/src/deprecated/schema/index.d.ts.map +0 -1
- package/dist/types/src/deprecated/schema/types.d.ts +0 -27
- package/dist/types/src/deprecated/schema/types.d.ts.map +0 -1
- package/dist/types/src/deprecated/theme.d.ts +0 -29
- package/dist/types/src/deprecated/theme.d.ts.map +0 -1
- package/dist/types/src/deprecated/translations.d.ts +0 -21
- package/dist/types/src/deprecated/translations.d.ts.map +0 -1
- package/dist/types/src/deprecated/types.d.ts +0 -26
- package/dist/types/src/deprecated/types.d.ts.map +0 -1
- package/src/deprecated/components/Cell/Cell.tsx +0 -88
- package/src/deprecated/components/Cell/CellCombobox.tsx +0 -103
- package/src/deprecated/components/Cell/index.ts +0 -5
- package/src/deprecated/components/ColumnMenu/ColumnMenu.stories.tsx +0 -129
- package/src/deprecated/components/ColumnMenu/ColumnMenu.tsx +0 -182
- package/src/deprecated/components/ColumnMenu/ColumnSettings.stories.tsx +0 -108
- package/src/deprecated/components/ColumnMenu/ColumnSettings.tsx +0 -207
- package/src/deprecated/components/ColumnMenu/index.ts +0 -6
- package/src/deprecated/components/Table/Table.stories.tsx +0 -508
- package/src/deprecated/components/Table/Table.tsx +0 -301
- package/src/deprecated/components/Table/TableBody.tsx +0 -82
- package/src/deprecated/components/Table/TableContext.tsx +0 -34
- package/src/deprecated/components/Table/TableHead.tsx +0 -78
- package/src/deprecated/components/Table/TableRootContext.ts +0 -39
- package/src/deprecated/components/Table/index.ts +0 -8
- package/src/deprecated/components/Table/props.ts +0 -60
- package/src/deprecated/components/index.ts +0 -7
- package/src/deprecated/helpers.tsx +0 -526
- package/src/deprecated/hooks/index.ts +0 -8
- package/src/deprecated/hooks/useColumnSizing.ts +0 -46
- package/src/deprecated/hooks/useColumnSorting.ts +0 -64
- package/src/deprecated/hooks/usePinLastRow.ts +0 -47
- package/src/deprecated/hooks/useRowSelection.ts +0 -40
- package/src/deprecated/index.ts +0 -12
- package/src/deprecated/schema/Schema.stories.tsx +0 -59
- package/src/deprecated/schema/column-utils.ts +0 -54
- package/src/deprecated/schema/index.ts +0 -6
- package/src/deprecated/schema/types.ts +0 -40
- package/src/deprecated/theme.ts +0 -82
- package/src/deprecated/translations.ts +0 -26
- package/src/deprecated/types.ts +0 -38
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {
|
|
2
2
|
TableSchema,
|
|
3
3
|
TableType
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-YWNRUF4J.mjs";
|
|
5
5
|
|
|
6
6
|
// packages/ui/react-ui-table/src/translations.ts
|
|
7
7
|
var translationKey = "table";
|
|
@@ -36,13 +36,13 @@ var translations_default = [
|
|
|
36
36
|
];
|
|
37
37
|
|
|
38
38
|
// packages/ui/react-ui-table/src/components/Table/Table.tsx
|
|
39
|
-
import React7, { forwardRef, useCallback as useCallback4, useImperativeHandle, useState as useState2, useMemo as useMemo4 } from "react";
|
|
39
|
+
import React7, { forwardRef, useCallback as useCallback4, useImperativeHandle, useState as useState2, useMemo as useMemo4, useEffect as useEffect2 } from "react";
|
|
40
40
|
import { getValue as getValue4 } from "@dxos/echo-schema";
|
|
41
41
|
import { invariant as invariant3 } 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";
|
|
45
|
-
import {
|
|
45
|
+
import { closestCell, Grid } from "@dxos/react-ui-grid";
|
|
46
46
|
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
47
47
|
import { isNotFalsy, safeParseInt } from "@dxos/util";
|
|
48
48
|
|
|
@@ -304,33 +304,60 @@ import { Resource } from "@dxos/context";
|
|
|
304
304
|
|
|
305
305
|
// packages/ui/react-ui-table/src/util/dynamic-table.ts
|
|
306
306
|
import { create as create2, makeRef } from "@dxos/live-object";
|
|
307
|
-
import { createView,
|
|
308
|
-
var
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
307
|
+
import { createView, getSchemaFromPropertyDefinitions, ViewProjection } from "@dxos/schema";
|
|
308
|
+
var getBaseSchems = ({ typename, properties, jsonSchema, schema }) => {
|
|
309
|
+
if (typename && properties) {
|
|
310
|
+
const schema2 = getSchemaFromPropertyDefinitions(typename, properties);
|
|
311
|
+
return {
|
|
312
|
+
typename: schema2.typename,
|
|
313
|
+
jsonSchema: schema2.jsonSchema
|
|
314
|
+
};
|
|
315
|
+
} else if (schema) {
|
|
316
|
+
return {
|
|
317
|
+
typename: schema.typename,
|
|
318
|
+
jsonSchema: schema.jsonSchema
|
|
319
|
+
};
|
|
320
|
+
} else if (typename && jsonSchema) {
|
|
321
|
+
return {
|
|
322
|
+
typename,
|
|
323
|
+
jsonSchema
|
|
324
|
+
};
|
|
325
|
+
} else {
|
|
326
|
+
throw new Error("invalid properties");
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
var makeDynamicTable = ({ typename, jsonSchema, properties }) => {
|
|
314
330
|
const view = createView({
|
|
315
331
|
name: "dynamic-table",
|
|
316
|
-
typename
|
|
317
|
-
jsonSchema
|
|
318
|
-
|
|
332
|
+
typename,
|
|
333
|
+
jsonSchema,
|
|
334
|
+
...properties && {
|
|
335
|
+
fields: properties.map((property) => property.name)
|
|
336
|
+
}
|
|
337
|
+
});
|
|
338
|
+
const table = create2(TableType, {
|
|
339
|
+
name: "dynamic-table",
|
|
340
|
+
view: makeRef(view)
|
|
319
341
|
});
|
|
320
|
-
|
|
321
|
-
|
|
342
|
+
const projection = new ViewProjection(jsonSchema, view);
|
|
343
|
+
if (properties && view.fields) {
|
|
344
|
+
setProperties(view, projection, properties);
|
|
345
|
+
}
|
|
346
|
+
return {
|
|
347
|
+
table,
|
|
348
|
+
projection
|
|
349
|
+
};
|
|
350
|
+
};
|
|
351
|
+
var setProperties = (view, projection, properties) => {
|
|
322
352
|
for (const property of properties) {
|
|
323
|
-
if (!view.fields) {
|
|
324
|
-
continue;
|
|
325
|
-
}
|
|
326
353
|
const field = view.fields.find((field2) => field2.path === property.name);
|
|
327
354
|
if (field) {
|
|
328
355
|
if (property.size !== void 0) {
|
|
329
356
|
field.size = property.size;
|
|
330
357
|
}
|
|
331
358
|
if (property.title !== void 0) {
|
|
332
|
-
const fieldProjection =
|
|
333
|
-
|
|
359
|
+
const fieldProjection = projection.getFieldProjection(field.id);
|
|
360
|
+
projection.setFieldProjection({
|
|
334
361
|
...fieldProjection,
|
|
335
362
|
props: {
|
|
336
363
|
...fieldProjection.props,
|
|
@@ -349,12 +376,6 @@ var makeDynamicTable = (typename, properties) => {
|
|
|
349
376
|
}
|
|
350
377
|
}
|
|
351
378
|
}
|
|
352
|
-
return {
|
|
353
|
-
table,
|
|
354
|
-
schema: echoSchema,
|
|
355
|
-
view,
|
|
356
|
-
viewProjection
|
|
357
|
-
};
|
|
358
379
|
};
|
|
359
380
|
|
|
360
381
|
// packages/ui/react-ui-table/src/util/signals.ts
|
|
@@ -418,7 +439,7 @@ var ContactFields = [
|
|
|
418
439
|
"active"
|
|
419
440
|
];
|
|
420
441
|
var createProjection = (schema, view) => {
|
|
421
|
-
const projection = new ViewProjection2(schema, view);
|
|
442
|
+
const projection = new ViewProjection2(schema.jsonSchema, view);
|
|
422
443
|
projection.setFieldProjection({
|
|
423
444
|
field: {
|
|
424
445
|
id: view.fields.find((f) => f.path === "salary").id,
|
|
@@ -581,7 +602,7 @@ var renderAttributes = (data) => {
|
|
|
581
602
|
var renderInput = (baseClass, attrs, checked = false, disabled = false, preventToggle = false, testId) => {
|
|
582
603
|
return `<input type="checkbox" class="${baseClass}" ${renderAttributes(attrs)} ${checked ? "checked" : ""} ${preventToggle ? 'onclick="return false"' : ""} ${disabled ? "disabled" : ""} data-testid="${testId}"/>`;
|
|
583
604
|
};
|
|
584
|
-
var
|
|
605
|
+
var CheckboxStory = ({ rowIndex, header = false, checked = false, disabled = false }) => {
|
|
585
606
|
const attrs = {
|
|
586
607
|
[CONTROL_IDENTIFIERS.checkbox]: "",
|
|
587
608
|
"data-row-index": rowIndex.toString(),
|
|
@@ -591,7 +612,7 @@ var renderCheckbox = ({ rowIndex, header = false, checked = false, disabled = fa
|
|
|
591
612
|
};
|
|
592
613
|
return renderInput(BASE_CLASSES.checkbox, attrs, checked, disabled, true, "table-selection");
|
|
593
614
|
};
|
|
594
|
-
var
|
|
615
|
+
var SwitchStory = ({ colIndex, rowIndex, checked = false, disabled = false }) => {
|
|
595
616
|
const attrs = {
|
|
596
617
|
[CONTROL_IDENTIFIERS.switch]: "",
|
|
597
618
|
"data-row-index": rowIndex.toString(),
|
|
@@ -602,7 +623,7 @@ var renderSwitch = ({ colIndex, rowIndex, checked = false, disabled = false }) =
|
|
|
602
623
|
var tableControls = {
|
|
603
624
|
checkbox: {
|
|
604
625
|
attr: CONTROL_IDENTIFIERS.checkbox,
|
|
605
|
-
render:
|
|
626
|
+
render: CheckboxStory,
|
|
606
627
|
getData: (el) => ({
|
|
607
628
|
type: "checkbox",
|
|
608
629
|
rowIndex: Number(el.getAttribute("data-row-index")),
|
|
@@ -611,7 +632,7 @@ var tableControls = {
|
|
|
611
632
|
},
|
|
612
633
|
switch: {
|
|
613
634
|
attr: CONTROL_IDENTIFIERS.switch,
|
|
614
|
-
render:
|
|
635
|
+
render: SwitchStory,
|
|
615
636
|
getData: (el) => ({
|
|
616
637
|
type: "switch",
|
|
617
638
|
rowIndex: Number(el.getAttribute("data-row-index")),
|
|
@@ -622,9 +643,10 @@ var tableControls = {
|
|
|
622
643
|
|
|
623
644
|
// packages/ui/react-ui-table/src/model/selection-model.ts
|
|
624
645
|
var SelectionModel = class extends Resource {
|
|
625
|
-
constructor(_rows, _onSelectionChanged) {
|
|
646
|
+
constructor(_rows, _selectionMode, _onSelectionChanged) {
|
|
626
647
|
super();
|
|
627
648
|
this._rows = _rows;
|
|
649
|
+
this._selectionMode = _selectionMode;
|
|
628
650
|
this._onSelectionChanged = _onSelectionChanged;
|
|
629
651
|
this._selection = signal(/* @__PURE__ */ new Set());
|
|
630
652
|
this._validSelectedIds = computed(() => {
|
|
@@ -662,6 +684,9 @@ var SelectionModel = class extends Resource {
|
|
|
662
684
|
if (newSelection.has(row.id)) {
|
|
663
685
|
newSelection.delete(row.id);
|
|
664
686
|
} else {
|
|
687
|
+
if (this._selectionMode === "single") {
|
|
688
|
+
newSelection.clear();
|
|
689
|
+
}
|
|
665
690
|
newSelection.add(row.id);
|
|
666
691
|
}
|
|
667
692
|
this._selection.value = newSelection;
|
|
@@ -698,6 +723,9 @@ var SelectionModel = class extends Resource {
|
|
|
698
723
|
get allRowsSeleted() {
|
|
699
724
|
return this._allSelected;
|
|
700
725
|
}
|
|
726
|
+
get selectionMode() {
|
|
727
|
+
return this._selectionMode;
|
|
728
|
+
}
|
|
701
729
|
};
|
|
702
730
|
|
|
703
731
|
// packages/ui/react-ui-table/src/model/table-sorting.ts
|
|
@@ -868,7 +896,10 @@ var TableSorting = class {
|
|
|
868
896
|
// packages/ui/react-ui-table/src/model/table-model.ts
|
|
869
897
|
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
|
|
870
898
|
var defaultFeatures = {
|
|
871
|
-
selection:
|
|
899
|
+
selection: {
|
|
900
|
+
enabled: true,
|
|
901
|
+
mode: "multiple"
|
|
902
|
+
},
|
|
872
903
|
dataEditable: false,
|
|
873
904
|
schemaEditable: false
|
|
874
905
|
};
|
|
@@ -876,7 +907,7 @@ var TableModel = class extends Resource2 {
|
|
|
876
907
|
constructor({ id, space, view, projection, features = {}, sorting = [], pinnedRows = {
|
|
877
908
|
top: [],
|
|
878
909
|
bottom: []
|
|
879
|
-
}, onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow,
|
|
910
|
+
}, rowActions = [], onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChange, onRowAction }) {
|
|
880
911
|
super();
|
|
881
912
|
this._visibleRange = signal3({
|
|
882
913
|
start: {
|
|
@@ -905,7 +936,7 @@ var TableModel = class extends Resource2 {
|
|
|
905
936
|
const row = this._sorting.getDataIndex(rowIndex);
|
|
906
937
|
const obj = this._rows.value[row];
|
|
907
938
|
const objectsToDelete = [];
|
|
908
|
-
if (this._selection.hasSelection.value) {
|
|
939
|
+
if (this.features.selection.enabled && this._selection.hasSelection.value) {
|
|
909
940
|
const selectedRows = this._selection.getSelectedRows();
|
|
910
941
|
objectsToDelete.push(...selectedRows);
|
|
911
942
|
} else {
|
|
@@ -984,18 +1015,27 @@ var TableModel = class extends Resource2 {
|
|
|
984
1015
|
...defaultFeatures,
|
|
985
1016
|
...features
|
|
986
1017
|
};
|
|
1018
|
+
invariant(!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === "single"), "Single selection is not compatible with editable tables.", {
|
|
1019
|
+
F: __dxlog_file,
|
|
1020
|
+
L: 114,
|
|
1021
|
+
S: this,
|
|
1022
|
+
A: [
|
|
1023
|
+
"!(this._features.dataEditable && this._features.selection.enabled && this._features.selection.mode === 'single')",
|
|
1024
|
+
"'Single selection is not compatible with editable tables.'"
|
|
1025
|
+
]
|
|
1026
|
+
});
|
|
987
1027
|
this._sorting = new TableSorting(this._rows, this._view, projection);
|
|
988
1028
|
if (sorting.length > 0) {
|
|
989
1029
|
const [sort] = sorting;
|
|
990
1030
|
this._sorting.setSort(sort.fieldId, sort.direction);
|
|
991
1031
|
}
|
|
992
1032
|
this._pinnedRows = pinnedRows;
|
|
1033
|
+
this._rowActions = rowActions;
|
|
993
1034
|
this._onInsertRow = onInsertRow;
|
|
994
1035
|
this._onDeleteRows = onDeleteRows;
|
|
995
1036
|
this._onDeleteColumn = onDeleteColumn;
|
|
996
1037
|
this._onCellUpdate = onCellUpdate;
|
|
997
|
-
this.
|
|
998
|
-
this._rowActions = rowActions;
|
|
1038
|
+
this._onRowOrderChange = onRowOrderChange;
|
|
999
1039
|
this._onRowAction = onRowAction;
|
|
1000
1040
|
}
|
|
1001
1041
|
get id() {
|
|
@@ -1037,7 +1077,7 @@ var TableModel = class extends Resource2 {
|
|
|
1037
1077
|
get columnMeta() {
|
|
1038
1078
|
invariant(this._columnMeta, void 0, {
|
|
1039
1079
|
F: __dxlog_file,
|
|
1040
|
-
L:
|
|
1080
|
+
L: 183,
|
|
1041
1081
|
S: this,
|
|
1042
1082
|
A: [
|
|
1043
1083
|
"this._columnMeta",
|
|
@@ -1062,7 +1102,7 @@ var TableModel = class extends Resource2 {
|
|
|
1062
1102
|
async _open() {
|
|
1063
1103
|
this.initializeColumnMeta();
|
|
1064
1104
|
this.initializeEffects();
|
|
1065
|
-
this._selection = new SelectionModel(this._sorting.sortedRows, () => this.
|
|
1105
|
+
this._selection = new SelectionModel(this._sorting.sortedRows, this._features.selection.mode ?? "multiple", () => this._onRowOrderChange?.());
|
|
1066
1106
|
await this._selection.open(this._ctx);
|
|
1067
1107
|
}
|
|
1068
1108
|
initializeColumnMeta() {
|
|
@@ -1095,7 +1135,7 @@ var TableModel = class extends Resource2 {
|
|
|
1095
1135
|
initializeEffects() {
|
|
1096
1136
|
const rowOrderWatcher = effect2(() => {
|
|
1097
1137
|
touch(this._sorting.sortedRows.value);
|
|
1098
|
-
this.
|
|
1138
|
+
this._onRowOrderChange?.();
|
|
1099
1139
|
});
|
|
1100
1140
|
this._ctx.onDispose(rowOrderWatcher);
|
|
1101
1141
|
const rowEffectManager = effect2(() => {
|
|
@@ -1264,7 +1304,7 @@ var ModalController = class {
|
|
|
1264
1304
|
// packages/ui/react-ui-table/src/model/table-presentation.ts
|
|
1265
1305
|
import { signal as signal5 } from "@preact/signals-core";
|
|
1266
1306
|
import { FormatEnum as FormatEnum4, getValue as getValue3 } from "@dxos/echo-schema";
|
|
1267
|
-
import { cellClassesForFieldType,
|
|
1307
|
+
import { cellClassesForFieldType, formatForDisplay as formatForDisplay2 } from "@dxos/react-ui-form";
|
|
1268
1308
|
import { toPlaneCellIndex } from "@dxos/react-ui-grid";
|
|
1269
1309
|
import { mx } from "@dxos/react-ui-theme";
|
|
1270
1310
|
import { VIEW_FIELD_LIMIT } from "@dxos/schema";
|
|
@@ -1309,7 +1349,7 @@ var TablePresentation = class {
|
|
|
1309
1349
|
}
|
|
1310
1350
|
if (plane === "grid" && this.model.features.dataEditable === false) {
|
|
1311
1351
|
Object.values(cells).forEach((cell) => {
|
|
1312
|
-
cell.readonly =
|
|
1352
|
+
cell.readonly = "text-select";
|
|
1313
1353
|
});
|
|
1314
1354
|
}
|
|
1315
1355
|
return cells;
|
|
@@ -1327,7 +1367,8 @@ var TablePresentation = class {
|
|
|
1327
1367
|
}
|
|
1328
1368
|
switch (props.format) {
|
|
1329
1369
|
case FormatEnum4.Boolean:
|
|
1330
|
-
case FormatEnum4.SingleSelect:
|
|
1370
|
+
case FormatEnum4.SingleSelect:
|
|
1371
|
+
case FormatEnum4.MultiSelect: {
|
|
1331
1372
|
return "";
|
|
1332
1373
|
}
|
|
1333
1374
|
case FormatEnum4.Ref: {
|
|
@@ -1354,7 +1395,7 @@ var TablePresentation = class {
|
|
|
1354
1395
|
if (formatClasses) {
|
|
1355
1396
|
classes.push(formatClasses);
|
|
1356
1397
|
}
|
|
1357
|
-
const rowSelectionClasses = cellClassesForRowSelection(this.model.selection.isObjectSelected(obj));
|
|
1398
|
+
const rowSelectionClasses = cellClassesForRowSelection(this.model.selection.isObjectSelected(obj), this.model.selection.selectionMode);
|
|
1358
1399
|
if (rowSelectionClasses) {
|
|
1359
1400
|
classes.push(rowSelectionClasses);
|
|
1360
1401
|
}
|
|
@@ -1377,7 +1418,7 @@ var TablePresentation = class {
|
|
|
1377
1418
|
rowIndex: displayIndex,
|
|
1378
1419
|
checked: value ?? false
|
|
1379
1420
|
});
|
|
1380
|
-
cell.readonly =
|
|
1421
|
+
cell.readonly = "no-text-select";
|
|
1381
1422
|
}
|
|
1382
1423
|
if (props.format === FormatEnum4.SingleSelect) {
|
|
1383
1424
|
const value = getValue3(obj, field.path);
|
|
@@ -1389,6 +1430,22 @@ var TablePresentation = class {
|
|
|
1389
1430
|
}
|
|
1390
1431
|
}
|
|
1391
1432
|
}
|
|
1433
|
+
if (props.format === FormatEnum4.MultiSelect) {
|
|
1434
|
+
const values = getValue3(obj, field.path);
|
|
1435
|
+
const options = this.model.projection.getFieldProjection(field.id).props.options;
|
|
1436
|
+
if (options && values && values.length > 0) {
|
|
1437
|
+
const tags = values.map((value) => {
|
|
1438
|
+
const option = options.find((o) => o.id === value);
|
|
1439
|
+
if (option) {
|
|
1440
|
+
return `<span class="dx-tag" data-hue="${option.color}">${option.title}</span>`;
|
|
1441
|
+
}
|
|
1442
|
+
return null;
|
|
1443
|
+
}).filter(Boolean).join(" ");
|
|
1444
|
+
if (tags) {
|
|
1445
|
+
cell.accessoryHtml = tags;
|
|
1446
|
+
}
|
|
1447
|
+
}
|
|
1448
|
+
}
|
|
1392
1449
|
const idx = toPlaneCellIndex({
|
|
1393
1450
|
col: colIndex,
|
|
1394
1451
|
row: displayIndex
|
|
@@ -1439,13 +1496,13 @@ var TablePresentation = class {
|
|
|
1439
1496
|
const cells = {};
|
|
1440
1497
|
for (let row = range.start.row; row <= range.end.row && row < this.model.getRowCount(); row++) {
|
|
1441
1498
|
const isSelected = this.model.selection.isRowIndexSelected(row);
|
|
1442
|
-
const classes = cellClassesForRowSelection(isSelected);
|
|
1499
|
+
const classes = cellClassesForRowSelection(isSelected, this.model.selection.selectionMode);
|
|
1443
1500
|
cells[toPlaneCellIndex({
|
|
1444
1501
|
col: 0,
|
|
1445
1502
|
row
|
|
1446
1503
|
})] = {
|
|
1447
1504
|
value: "",
|
|
1448
|
-
readonly:
|
|
1505
|
+
readonly: "no-text-select",
|
|
1449
1506
|
className: classes ? mx(classes) : void 0,
|
|
1450
1507
|
accessoryHtml: tableControls.checkbox.render({
|
|
1451
1508
|
rowIndex: row,
|
|
@@ -1459,7 +1516,7 @@ var TablePresentation = class {
|
|
|
1459
1516
|
const cells = {};
|
|
1460
1517
|
for (let row = range.start.row; row <= range.end.row && row < this.model.getRowCount(); row++) {
|
|
1461
1518
|
const isSelected = this.model.selection.isRowIndexSelected(row);
|
|
1462
|
-
const classes = cellClassesForRowSelection(isSelected);
|
|
1519
|
+
const classes = cellClassesForRowSelection(isSelected, this.model.selection.selectionMode);
|
|
1463
1520
|
cells[toPlaneCellIndex({
|
|
1464
1521
|
col: 0,
|
|
1465
1522
|
row
|
|
@@ -1475,6 +1532,18 @@ var TablePresentation = class {
|
|
|
1475
1532
|
return cells;
|
|
1476
1533
|
}
|
|
1477
1534
|
getSelectAllCell() {
|
|
1535
|
+
if (!this.model.features.selection.enabled || this.model.selection.selectionMode === "single") {
|
|
1536
|
+
return {
|
|
1537
|
+
[toPlaneCellIndex({
|
|
1538
|
+
col: 0,
|
|
1539
|
+
row: 0
|
|
1540
|
+
})]: {
|
|
1541
|
+
className: "!bg-gridHeader",
|
|
1542
|
+
readonly: true,
|
|
1543
|
+
value: ""
|
|
1544
|
+
}
|
|
1545
|
+
};
|
|
1546
|
+
}
|
|
1478
1547
|
return {
|
|
1479
1548
|
[toPlaneCellIndex({
|
|
1480
1549
|
col: 0,
|
|
@@ -1507,12 +1576,37 @@ var TablePresentation = class {
|
|
|
1507
1576
|
};
|
|
1508
1577
|
}
|
|
1509
1578
|
};
|
|
1579
|
+
var cellClassesForRowSelection = (selected, selectionMode) => {
|
|
1580
|
+
if (!selected) {
|
|
1581
|
+
if (selectionMode === "single") {
|
|
1582
|
+
return [
|
|
1583
|
+
"!cursor-pointer"
|
|
1584
|
+
];
|
|
1585
|
+
} else {
|
|
1586
|
+
return void 0;
|
|
1587
|
+
}
|
|
1588
|
+
}
|
|
1589
|
+
switch (selectionMode) {
|
|
1590
|
+
case "single":
|
|
1591
|
+
return [
|
|
1592
|
+
"!bg-currentRelated hover:bg-hoverSurface",
|
|
1593
|
+
"!cursor-pointer"
|
|
1594
|
+
];
|
|
1595
|
+
case "multiple":
|
|
1596
|
+
return [
|
|
1597
|
+
"!bg-gridCellSelected"
|
|
1598
|
+
];
|
|
1599
|
+
}
|
|
1600
|
+
};
|
|
1510
1601
|
|
|
1511
1602
|
// packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx
|
|
1512
1603
|
import React6, { useCallback as useCallback3, useMemo as useMemo3, useRef } from "react";
|
|
1513
1604
|
import { FormatEnum as FormatEnum5 } from "@dxos/echo-schema";
|
|
1514
1605
|
import { invariant as invariant2 } from "@dxos/invariant";
|
|
1606
|
+
import { useThemeContext } from "@dxos/react-ui";
|
|
1607
|
+
import { createMarkdownExtensions } from "@dxos/react-ui-editor";
|
|
1515
1608
|
import { cellQuery, editorKeys, parseCellIndex, useGridContext as useGridContext2, GridCellEditor } from "@dxos/react-ui-grid";
|
|
1609
|
+
import { tagPickerExtension, createLinks } from "@dxos/react-ui-tag-picker";
|
|
1516
1610
|
|
|
1517
1611
|
// packages/ui/react-ui-table/src/components/TableCellEditor/extension.ts
|
|
1518
1612
|
import { autocompletion, pickedCompletion } from "@codemirror/autocomplete";
|
|
@@ -1564,6 +1658,7 @@ var isCreateOption = (data) => typeof data === "object" && data[newValue];
|
|
|
1564
1658
|
var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }) => {
|
|
1565
1659
|
const { id: gridId, editing, setEditing } = useGridContext2("TableCellEditor", __gridScope);
|
|
1566
1660
|
const suppressNextBlur = useRef(false);
|
|
1661
|
+
const { themeMode } = useThemeContext();
|
|
1567
1662
|
const fieldProjection = useMemo3(() => {
|
|
1568
1663
|
if (!model || !editing) {
|
|
1569
1664
|
return;
|
|
@@ -1573,7 +1668,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1573
1668
|
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
1574
1669
|
invariant2(fieldProjection2, void 0, {
|
|
1575
1670
|
F: __dxlog_file3,
|
|
1576
|
-
L:
|
|
1671
|
+
L: 71,
|
|
1577
1672
|
S: void 0,
|
|
1578
1673
|
A: [
|
|
1579
1674
|
"fieldProjection",
|
|
@@ -1596,7 +1691,10 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1596
1691
|
setEditing(null);
|
|
1597
1692
|
}, [
|
|
1598
1693
|
model,
|
|
1599
|
-
editing
|
|
1694
|
+
editing,
|
|
1695
|
+
onEnter,
|
|
1696
|
+
onFocus,
|
|
1697
|
+
setEditing
|
|
1600
1698
|
]);
|
|
1601
1699
|
const handleBlur = useCallback3((value) => {
|
|
1602
1700
|
if (!model || !editing) {
|
|
@@ -1628,9 +1726,7 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1628
1726
|
editing,
|
|
1629
1727
|
onFocus,
|
|
1630
1728
|
onEnter,
|
|
1631
|
-
fieldProjection
|
|
1632
|
-
determineNavigationAxis,
|
|
1633
|
-
determineNavigationDelta
|
|
1729
|
+
fieldProjection
|
|
1634
1730
|
]);
|
|
1635
1731
|
const extension = useMemo3(() => {
|
|
1636
1732
|
if (!fieldProjection) {
|
|
@@ -1644,6 +1740,37 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1644
1740
|
}
|
|
1645
1741
|
})
|
|
1646
1742
|
];
|
|
1743
|
+
const format = fieldProjection.props.format;
|
|
1744
|
+
if (format === FormatEnum5.SingleSelect || format === FormatEnum5.MultiSelect) {
|
|
1745
|
+
extension2.push(createMarkdownExtensions({
|
|
1746
|
+
themeMode
|
|
1747
|
+
}));
|
|
1748
|
+
const options = fieldProjection.props.options || [];
|
|
1749
|
+
const mode = format === FormatEnum5.SingleSelect ? "single-select" : "multi-select";
|
|
1750
|
+
extension2.push(tagPickerExtension({
|
|
1751
|
+
mode,
|
|
1752
|
+
inGrid: true,
|
|
1753
|
+
onSearch: (text, selectedIds) => {
|
|
1754
|
+
return options.filter((option) => selectedIds.indexOf(option.id) === -1 && (text.length === 0 || option.title.toLowerCase().includes(text.toLowerCase()))).map((option) => ({
|
|
1755
|
+
id: option.id,
|
|
1756
|
+
label: option.title,
|
|
1757
|
+
hue: option.color
|
|
1758
|
+
}));
|
|
1759
|
+
},
|
|
1760
|
+
onUpdate: (ids) => {
|
|
1761
|
+
if (model && editing) {
|
|
1762
|
+
if (ids.length === 0) {
|
|
1763
|
+
return;
|
|
1764
|
+
}
|
|
1765
|
+
if (mode === "single-select") {
|
|
1766
|
+
handleEnter(ids[0]);
|
|
1767
|
+
} else {
|
|
1768
|
+
handleEnter(ids);
|
|
1769
|
+
}
|
|
1770
|
+
}
|
|
1771
|
+
}
|
|
1772
|
+
}));
|
|
1773
|
+
}
|
|
1647
1774
|
if (onQuery) {
|
|
1648
1775
|
switch (fieldProjection.props.format) {
|
|
1649
1776
|
case FormatEnum5.Ref: {
|
|
@@ -1679,11 +1806,49 @@ var TableCellEditor = ({ model, modals, onEnter, onFocus, onQuery, __gridScope }
|
|
|
1679
1806
|
modals,
|
|
1680
1807
|
editing,
|
|
1681
1808
|
fieldProjection,
|
|
1682
|
-
handleClose
|
|
1809
|
+
handleClose,
|
|
1810
|
+
themeMode
|
|
1683
1811
|
]);
|
|
1684
1812
|
const getCellContent = useCallback3(() => {
|
|
1685
1813
|
if (model && editing) {
|
|
1686
|
-
const
|
|
1814
|
+
const cell = parseCellIndex(editing.index);
|
|
1815
|
+
const { col } = cell;
|
|
1816
|
+
const field = model.projection.view.fields[col];
|
|
1817
|
+
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
1818
|
+
if (fieldProjection2?.props.format === FormatEnum5.SingleSelect || fieldProjection2?.props.format === FormatEnum5.MultiSelect) {
|
|
1819
|
+
const value2 = model.getCellData(cell);
|
|
1820
|
+
if (value2 !== void 0) {
|
|
1821
|
+
const options = fieldProjection2.props.options || [];
|
|
1822
|
+
if (fieldProjection2.props.format === FormatEnum5.MultiSelect && Array.isArray(value2)) {
|
|
1823
|
+
const tagItems = value2.map((id) => {
|
|
1824
|
+
const option = options.find((o) => o.id === id);
|
|
1825
|
+
if (option) {
|
|
1826
|
+
return {
|
|
1827
|
+
id,
|
|
1828
|
+
label: option.title,
|
|
1829
|
+
hue: option.color
|
|
1830
|
+
};
|
|
1831
|
+
}
|
|
1832
|
+
return void 0;
|
|
1833
|
+
}).filter((item) => item !== void 0);
|
|
1834
|
+
return createLinks(tagItems);
|
|
1835
|
+
} else {
|
|
1836
|
+
const option = options.find((o) => o.id === value2);
|
|
1837
|
+
if (option) {
|
|
1838
|
+
const tagItem = {
|
|
1839
|
+
id: value2,
|
|
1840
|
+
label: option.title,
|
|
1841
|
+
hue: option.color
|
|
1842
|
+
};
|
|
1843
|
+
return createLinks([
|
|
1844
|
+
tagItem
|
|
1845
|
+
]);
|
|
1846
|
+
}
|
|
1847
|
+
}
|
|
1848
|
+
}
|
|
1849
|
+
return "";
|
|
1850
|
+
}
|
|
1851
|
+
const value = model.getCellData(cell);
|
|
1687
1852
|
return value !== void 0 ? String(value) : "";
|
|
1688
1853
|
}
|
|
1689
1854
|
}, [
|
|
@@ -1728,26 +1893,37 @@ var blockEndLine = "[&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-inlin
|
|
|
1728
1893
|
var TableRoot = ({ children, role }) => {
|
|
1729
1894
|
return /* @__PURE__ */ React7.createElement("div", {
|
|
1730
1895
|
role: "none",
|
|
1731
|
-
className: mx2("relative
|
|
1896
|
+
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]")
|
|
1732
1897
|
}, children);
|
|
1733
1898
|
};
|
|
1734
|
-
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention,
|
|
1899
|
+
var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttention, onRowClick }, forwardedRef) => {
|
|
1735
1900
|
const [dxGrid, setDxGrid] = useState2(null);
|
|
1736
1901
|
const { hasAttention } = useAttention(model?.id ?? "table");
|
|
1737
1902
|
const { t } = useTranslation3(translationKey);
|
|
1738
1903
|
const modals = useMemo4(() => new ModalController(), []);
|
|
1739
|
-
const frozen = useMemo4(() =>
|
|
1740
|
-
|
|
1741
|
-
|
|
1742
|
-
|
|
1743
|
-
|
|
1904
|
+
const frozen = useMemo4(() => {
|
|
1905
|
+
const noActionColumn = model?.features.dataEditable === false && model?.features.schemaEditable === false && model.rowActions.length === 0;
|
|
1906
|
+
return {
|
|
1907
|
+
frozenRowsStart: 1,
|
|
1908
|
+
frozenColsStart: model?.features.selection.enabled ? 1 : 0,
|
|
1909
|
+
frozenColsEnd: noActionColumn ? 0 : 1
|
|
1910
|
+
};
|
|
1911
|
+
}, [
|
|
1744
1912
|
model
|
|
1745
1913
|
]);
|
|
1914
|
+
useEffect2(() => {
|
|
1915
|
+
if (!presentation || !dxGrid) {
|
|
1916
|
+
return;
|
|
1917
|
+
}
|
|
1918
|
+
dxGrid.getCells = (range, plane) => presentation.getCells(range, plane);
|
|
1919
|
+
}, [
|
|
1920
|
+
presentation,
|
|
1921
|
+
dxGrid
|
|
1922
|
+
]);
|
|
1746
1923
|
useImperativeHandle(forwardedRef, () => {
|
|
1747
1924
|
if (!presentation || !dxGrid) {
|
|
1748
1925
|
return {};
|
|
1749
1926
|
}
|
|
1750
|
-
dxGrid.getCells = (range, plane) => presentation.getCells(range, plane);
|
|
1751
1927
|
return {
|
|
1752
1928
|
update: (cell) => {
|
|
1753
1929
|
if (cell) {
|
|
@@ -1763,11 +1939,14 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1763
1939
|
dxGrid
|
|
1764
1940
|
]);
|
|
1765
1941
|
const handleGridClick = useCallback4((event) => {
|
|
1766
|
-
|
|
1767
|
-
|
|
1768
|
-
if (
|
|
1942
|
+
const rowIndex = safeParseInt(event.target.ariaRowIndex ?? "");
|
|
1943
|
+
if (rowIndex != null) {
|
|
1944
|
+
if (onRowClick) {
|
|
1769
1945
|
const row = model?.getRowAt(rowIndex);
|
|
1770
|
-
row &&
|
|
1946
|
+
row && onRowClick(row);
|
|
1947
|
+
}
|
|
1948
|
+
if (model?.features.selection.enabled && model?.selection.selectionMode === "single") {
|
|
1949
|
+
model.selection.toggleSelectionForRowIndex(rowIndex);
|
|
1771
1950
|
}
|
|
1772
1951
|
}
|
|
1773
1952
|
if (!modals) {
|
|
@@ -1910,7 +2089,7 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1910
2089
|
const space = model.space;
|
|
1911
2090
|
invariant3(space, void 0, {
|
|
1912
2091
|
F: __dxlog_file4,
|
|
1913
|
-
L:
|
|
2092
|
+
L: 312,
|
|
1914
2093
|
S: void 0,
|
|
1915
2094
|
A: [
|
|
1916
2095
|
"space",
|
|
@@ -1961,16 +2140,17 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1961
2140
|
onFocus: handleFocus,
|
|
1962
2141
|
onQuery: handleQuery
|
|
1963
2142
|
}), /* @__PURE__ */ React7.createElement(Grid.Content, {
|
|
1964
|
-
onWheelCapture: handleWheel,
|
|
1965
2143
|
className: mx2("[--dx-grid-base:var(--surface-bg)]", inlineEndLine, blockEndLine),
|
|
1966
2144
|
frozen,
|
|
2145
|
+
// getCells={getCells}
|
|
1967
2146
|
columns: model.columnMeta.value,
|
|
1968
2147
|
limitRows: model.getRowCount() ?? 0,
|
|
1969
2148
|
limitColumns: model.view?.fields?.length ?? 0,
|
|
2149
|
+
overscroll: "trap",
|
|
1970
2150
|
onAxisResize: handleAxisResize,
|
|
1971
2151
|
onClick: handleGridClick,
|
|
1972
2152
|
onKeyDown: handleKeyDown,
|
|
1973
|
-
|
|
2153
|
+
onWheelCapture: handleWheel,
|
|
1974
2154
|
ref: setDxGrid
|
|
1975
2155
|
}), /* @__PURE__ */ React7.createElement(RowActionsMenu, {
|
|
1976
2156
|
model,
|
|
@@ -1982,10 +2162,10 @@ var TableMain = /* @__PURE__ */ forwardRef(({ model, presentation, ignoreAttenti
|
|
|
1982
2162
|
model,
|
|
1983
2163
|
modals,
|
|
1984
2164
|
onNewColumn: handleNewColumn
|
|
1985
|
-
}), /* @__PURE__ */ React7.createElement(
|
|
2165
|
+
}), /* @__PURE__ */ React7.createElement(CreateRefPanel, {
|
|
1986
2166
|
model,
|
|
1987
2167
|
modals
|
|
1988
|
-
}), /* @__PURE__ */ React7.createElement(
|
|
2168
|
+
}), /* @__PURE__ */ React7.createElement(RefPanel, {
|
|
1989
2169
|
model,
|
|
1990
2170
|
modals
|
|
1991
2171
|
}));
|
|
@@ -1997,17 +2177,18 @@ var Table = {
|
|
|
1997
2177
|
|
|
1998
2178
|
// packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
|
|
1999
2179
|
import React8, { useRef as useRef2, useMemo as useMemo5, useCallback as useCallback5 } from "react";
|
|
2180
|
+
import { useDefaultValue } from "@dxos/react-ui";
|
|
2000
2181
|
import { mx as mx3 } from "@dxos/react-ui-theme";
|
|
2001
2182
|
|
|
2002
2183
|
// packages/ui/react-ui-table/src/hooks/useTableModel.ts
|
|
2003
2184
|
import { effect as effect3 } from "@preact/signals-core";
|
|
2004
|
-
import { useEffect as
|
|
2185
|
+
import { useEffect as useEffect3, useState as useState3 } from "react";
|
|
2005
2186
|
import { fullyQualifiedId, getSpace } from "@dxos/react-client/echo";
|
|
2006
2187
|
import { useSelectionActions } from "@dxos/react-ui-attention";
|
|
2007
2188
|
import { isNonNullable } from "@dxos/util";
|
|
2008
|
-
var useTableModel = ({
|
|
2189
|
+
var useTableModel = ({ table, projection, rows, rowActions, features, onSelectionChanged, onRowAction, ...props }) => {
|
|
2009
2190
|
const [model, setModel] = useState3();
|
|
2010
|
-
|
|
2191
|
+
useEffect3(() => {
|
|
2011
2192
|
if (!table || !projection) {
|
|
2012
2193
|
return;
|
|
2013
2194
|
}
|
|
@@ -2037,19 +2218,19 @@ var useTableModel = ({ objects, table, projection, features, onSelectionChanged,
|
|
|
2037
2218
|
features,
|
|
2038
2219
|
rowActions
|
|
2039
2220
|
]);
|
|
2040
|
-
|
|
2041
|
-
if (
|
|
2042
|
-
model?.setRows(
|
|
2221
|
+
useEffect3(() => {
|
|
2222
|
+
if (rows) {
|
|
2223
|
+
model?.setRows(rows);
|
|
2043
2224
|
}
|
|
2044
2225
|
}, [
|
|
2045
2226
|
model,
|
|
2046
|
-
|
|
2227
|
+
rows
|
|
2047
2228
|
]);
|
|
2048
2229
|
const { select, clear } = useSelectionActions([
|
|
2049
2230
|
table?.id,
|
|
2050
2231
|
table?.view?.target?.query.typename
|
|
2051
2232
|
].filter(isNonNullable));
|
|
2052
|
-
|
|
2233
|
+
useEffect3(() => {
|
|
2053
2234
|
if (!model) {
|
|
2054
2235
|
return;
|
|
2055
2236
|
}
|
|
@@ -2072,32 +2253,45 @@ var useTableModel = ({ objects, table, projection, features, onSelectionChanged,
|
|
|
2072
2253
|
};
|
|
2073
2254
|
|
|
2074
2255
|
// packages/ui/react-ui-table/src/components/Table/DynamicTable.tsx
|
|
2075
|
-
var DynamicTable = ({
|
|
2076
|
-
const { table,
|
|
2077
|
-
|
|
2256
|
+
var DynamicTable = ({ classNames, name = "example.com/dynamic-table", rows, properties, jsonSchema, schema, rowActions, onRowClick, onRowAction, ...props }) => {
|
|
2257
|
+
const { table, projection } = useMemo5(() => {
|
|
2258
|
+
const props2 = getBaseSchems({
|
|
2259
|
+
typename: name,
|
|
2260
|
+
properties,
|
|
2261
|
+
jsonSchema,
|
|
2262
|
+
schema
|
|
2263
|
+
});
|
|
2264
|
+
return makeDynamicTable({
|
|
2265
|
+
...props2,
|
|
2266
|
+
properties
|
|
2267
|
+
});
|
|
2078
2268
|
}, [
|
|
2079
|
-
|
|
2080
|
-
properties
|
|
2269
|
+
name,
|
|
2270
|
+
properties,
|
|
2271
|
+
schema,
|
|
2272
|
+
jsonSchema
|
|
2081
2273
|
]);
|
|
2082
2274
|
const tableRef = useRef2(null);
|
|
2083
2275
|
const handleCellUpdate = useCallback5((cell) => {
|
|
2084
2276
|
tableRef.current?.update?.(cell);
|
|
2085
2277
|
}, []);
|
|
2086
|
-
const
|
|
2278
|
+
const handleRowOrderChange = useCallback5(() => {
|
|
2087
2279
|
tableRef.current?.update?.();
|
|
2088
2280
|
}, []);
|
|
2089
|
-
const features =
|
|
2090
|
-
selection:
|
|
2281
|
+
const features = useDefaultValue(props.features, () => ({
|
|
2282
|
+
selection: {
|
|
2283
|
+
enabled: false
|
|
2284
|
+
},
|
|
2091
2285
|
dataEditable: false
|
|
2092
|
-
})
|
|
2286
|
+
}));
|
|
2093
2287
|
const model = useTableModel({
|
|
2094
2288
|
table,
|
|
2095
|
-
|
|
2096
|
-
projection
|
|
2289
|
+
rows,
|
|
2290
|
+
projection,
|
|
2097
2291
|
features,
|
|
2098
|
-
onCellUpdate: handleCellUpdate,
|
|
2099
|
-
onRowOrderChanged: handleRowOrderChanged,
|
|
2100
2292
|
rowActions,
|
|
2293
|
+
onCellUpdate: handleCellUpdate,
|
|
2294
|
+
onRowOrderChange: handleRowOrderChange,
|
|
2101
2295
|
onRowAction
|
|
2102
2296
|
});
|
|
2103
2297
|
const presentation = useMemo5(() => {
|
|
@@ -2108,15 +2302,17 @@ var DynamicTable = ({ data, properties, classNames, tableName = "com.example/dyn
|
|
|
2108
2302
|
model
|
|
2109
2303
|
]);
|
|
2110
2304
|
return /* @__PURE__ */ React8.createElement("div", {
|
|
2305
|
+
role: "none",
|
|
2111
2306
|
className: mx3("is-full bs-full grow grid", classNames)
|
|
2112
2307
|
}, /* @__PURE__ */ React8.createElement("div", {
|
|
2308
|
+
role: "none",
|
|
2113
2309
|
className: "grid min-bs-0 overflow-hidden"
|
|
2114
2310
|
}, /* @__PURE__ */ React8.createElement(Table.Root, null, /* @__PURE__ */ React8.createElement(Table.Main, {
|
|
2115
2311
|
ref: tableRef,
|
|
2116
2312
|
model,
|
|
2117
2313
|
presentation,
|
|
2118
|
-
|
|
2119
|
-
|
|
2314
|
+
ignoreAttention: true,
|
|
2315
|
+
onRowClick
|
|
2120
2316
|
}))));
|
|
2121
2317
|
};
|
|
2122
2318
|
|
|
@@ -2194,18 +2390,20 @@ var TableToolbar = ({ classNames, viewDirty, attendableId, onAction }) => {
|
|
|
2194
2390
|
export {
|
|
2195
2391
|
BUTTON_IDENTIFIERS,
|
|
2196
2392
|
CONTROL_IDENTIFIERS,
|
|
2393
|
+
CheckboxStory,
|
|
2197
2394
|
DynamicTable,
|
|
2198
2395
|
ModalController,
|
|
2396
|
+
SwitchStory,
|
|
2199
2397
|
Table,
|
|
2200
2398
|
TableModel,
|
|
2201
2399
|
TablePresentation,
|
|
2202
2400
|
TableSchema,
|
|
2203
2401
|
TableToolbar,
|
|
2204
2402
|
TableType,
|
|
2403
|
+
cellClassesForRowSelection,
|
|
2404
|
+
getBaseSchems,
|
|
2205
2405
|
initializeTable,
|
|
2206
2406
|
makeDynamicTable,
|
|
2207
|
-
renderCheckbox,
|
|
2208
|
-
renderSwitch,
|
|
2209
2407
|
tableButtons,
|
|
2210
2408
|
tableControls,
|
|
2211
2409
|
touch,
|