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