@dxos/react-ui-table 0.6.14-staging.e15392e → 0.7.1-staging.599df14
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/_deprecated/index.mjs +1483 -0
- package/dist/lib/browser/_deprecated/index.mjs.map +7 -0
- package/dist/lib/browser/chunk-A5W4XWPD.mjs +18 -0
- package/dist/lib/browser/chunk-A5W4XWPD.mjs.map +7 -0
- package/dist/lib/browser/index.mjs +1274 -1356
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/browser/types/index.mjs +7 -0
- package/dist/lib/browser/types/index.mjs.map +7 -0
- package/dist/lib/node/_deprecated/index.cjs +1511 -0
- package/dist/lib/node/_deprecated/index.cjs.map +7 -0
- package/dist/lib/node/chunk-32IGMRME.cjs +40 -0
- package/dist/lib/node/chunk-32IGMRME.cjs.map +7 -0
- package/dist/lib/node/index.cjs +1380 -0
- package/dist/lib/node/index.cjs.map +7 -0
- package/dist/lib/node/meta.json +1 -0
- package/dist/lib/node/types/index.cjs +29 -0
- package/dist/lib/node/types/index.cjs.map +7 -0
- package/dist/lib/node-esm/_deprecated/index.mjs +1485 -0
- package/dist/lib/node-esm/_deprecated/index.mjs.map +7 -0
- package/dist/lib/node-esm/chunk-DWQ4KGLD.mjs +20 -0
- package/dist/lib/node-esm/chunk-DWQ4KGLD.mjs.map +7 -0
- package/dist/lib/node-esm/index.mjs +1399 -0
- package/dist/lib/node-esm/index.mjs.map +7 -0
- package/dist/lib/node-esm/meta.json +1 -0
- package/dist/lib/node-esm/types/index.mjs +8 -0
- package/dist/lib/node-esm/types/index.mjs.map +7 -0
- package/dist/types/src/_deprecated/components/Cell/Cell.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Cell/CellCombobox.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Cell/index.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnMenu.stories.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.d.ts.map +1 -0
- package/dist/types/src/{components → _deprecated/components}/ColumnMenu/ColumnSettings.stories.d.ts +4 -4
- package/dist/types/src/_deprecated/components/ColumnMenu/ColumnSettings.stories.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/ColumnMenu/index.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Table/Table.d.ts +20 -0
- package/dist/types/src/_deprecated/components/Table/Table.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Table/Table.stories.d.ts +116 -0
- package/dist/types/src/_deprecated/components/Table/Table.stories.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Table/TableBody.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Table/TableContext.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Table/TableHead.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Table/TableRootContext.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Table/index.d.ts +5 -0
- package/dist/types/src/_deprecated/components/Table/index.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/Table/props.d.ts.map +1 -0
- package/dist/types/src/_deprecated/components/index.d.ts +4 -0
- package/dist/types/src/_deprecated/components/index.d.ts.map +1 -0
- package/dist/types/src/_deprecated/helpers.d.ts.map +1 -0
- package/dist/types/src/_deprecated/hooks/index.d.ts +5 -0
- package/dist/types/src/_deprecated/hooks/index.d.ts.map +1 -0
- package/dist/types/src/_deprecated/hooks/useColumnSizing.d.ts.map +1 -0
- package/dist/types/src/{hooks → _deprecated/hooks}/useColumnSorting.d.ts +1 -1
- package/dist/types/src/_deprecated/hooks/useColumnSorting.d.ts.map +1 -0
- package/dist/types/src/_deprecated/hooks/usePinLastRow.d.ts.map +1 -0
- package/dist/types/src/_deprecated/hooks/useRowSelection.d.ts.map +1 -0
- package/dist/types/src/_deprecated/index.d.ts +8 -0
- package/dist/types/src/_deprecated/index.d.ts.map +1 -0
- package/dist/types/src/_deprecated/schema/Schema.stories.d.ts.map +1 -0
- package/dist/types/src/{schema → _deprecated/schema}/column-utils.d.ts +3 -0
- package/dist/types/src/_deprecated/schema/column-utils.d.ts.map +1 -0
- package/dist/types/src/_deprecated/schema/index.d.ts.map +1 -0
- package/dist/types/src/{schema → _deprecated/schema}/types.d.ts +3 -2
- package/dist/types/src/_deprecated/schema/types.d.ts.map +1 -0
- package/dist/types/src/_deprecated/theme.d.ts.map +1 -0
- package/dist/types/src/_deprecated/translations.d.ts +21 -0
- package/dist/types/src/_deprecated/translations.d.ts.map +1 -0
- package/dist/types/src/_deprecated/types.d.ts.map +1 -0
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts +8 -0
- package/dist/types/src/components/Table/ColumnActionsMenu.d.ts.map +1 -0
- package/dist/types/src/components/Table/ColumnSettings.d.ts +8 -0
- package/dist/types/src/components/Table/ColumnSettings.d.ts.map +1 -0
- package/dist/types/src/components/Table/RowActionsMenu.d.ts +8 -0
- package/dist/types/src/components/Table/RowActionsMenu.d.ts.map +1 -0
- package/dist/types/src/components/Table/Table.d.ts +13 -15
- package/dist/types/src/components/Table/Table.d.ts.map +1 -1
- package/dist/types/src/components/Table/Table.stories.d.ts +10 -113
- package/dist/types/src/components/Table/Table.stories.d.ts.map +1 -1
- package/dist/types/src/components/Table/index.d.ts +0 -3
- package/dist/types/src/components/Table/index.d.ts.map +1 -1
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts +17 -0
- package/dist/types/src/components/TableCellEditor/TableCellEditor.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts +11 -0
- package/dist/types/src/components/TableCellEditor/TableCellEditor.stories.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/extension.d.ts +12 -0
- package/dist/types/src/components/TableCellEditor/extension.d.ts.map +1 -0
- package/dist/types/src/components/TableCellEditor/index.d.ts +2 -0
- package/dist/types/src/components/TableCellEditor/index.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +21 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/common.d.ts +14 -0
- package/dist/types/src/components/Toolbar/common.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/index.d.ts +2 -0
- package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -2
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/components/testing.d.ts +97 -0
- package/dist/types/src/components/testing.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +1 -4
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useTableModel.d.ts +15 -0
- package/dist/types/src/hooks/useTableModel.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -4
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/model/index.d.ts +3 -0
- package/dist/types/src/model/index.d.ts.map +1 -0
- package/dist/types/src/model/modal-controller.d.ts +29 -0
- package/dist/types/src/model/modal-controller.d.ts.map +1 -0
- package/dist/types/src/model/selection-model.d.ts +22 -0
- package/dist/types/src/model/selection-model.d.ts.map +1 -0
- package/dist/types/src/model/table-model.d.ts +93 -0
- package/dist/types/src/model/table-model.d.ts.map +1 -0
- package/dist/types/src/model/table-model.test.d.ts +2 -0
- package/dist/types/src/model/table-model.test.d.ts.map +1 -0
- package/dist/types/src/translations.d.ts +23 -16
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/src/types/index.d.ts +2 -0
- package/dist/types/src/types/index.d.ts.map +1 -0
- package/dist/types/src/types/table.d.ts +106 -0
- package/dist/types/src/types/table.d.ts.map +1 -0
- package/dist/types/src/util/grid.d.ts +14 -0
- package/dist/types/src/util/grid.d.ts.map +1 -0
- package/dist/types/src/util/index.d.ts +5 -0
- package/dist/types/src/util/index.d.ts.map +1 -0
- package/dist/types/src/util/signals.d.ts +6 -0
- package/dist/types/src/util/signals.d.ts.map +1 -0
- package/dist/types/src/util/table-buttons.d.ts +24 -0
- package/dist/types/src/util/table-buttons.d.ts.map +1 -0
- package/dist/types/src/util/table-controls.d.ts +21 -0
- package/dist/types/src/util/table-controls.d.ts.map +1 -0
- package/dist/types/src/util/table.d.ts +8 -0
- package/dist/types/src/util/table.d.ts.map +1 -0
- package/package.json +56 -22
- package/src/{components → _deprecated/components}/ColumnMenu/ColumnMenu.stories.tsx +4 -4
- package/src/{components → _deprecated/components}/ColumnMenu/ColumnSettings.stories.tsx +9 -9
- package/src/{components → _deprecated/components}/ColumnMenu/ColumnSettings.tsx +3 -3
- package/src/_deprecated/components/Table/Table.stories.tsx +508 -0
- package/src/_deprecated/components/Table/Table.tsx +301 -0
- package/src/{components → _deprecated/components}/Table/TableHead.tsx +3 -1
- package/src/_deprecated/components/Table/index.ts +8 -0
- package/src/_deprecated/components/index.ts +7 -0
- package/src/{helpers.tsx → _deprecated/helpers.tsx} +4 -3
- package/src/_deprecated/hooks/index.ts +8 -0
- package/src/_deprecated/index.ts +12 -0
- package/src/_deprecated/schema/column-utils.ts +54 -0
- package/src/{schema → _deprecated/schema}/types.ts +3 -2
- package/src/_deprecated/translations.ts +26 -0
- package/src/components/Table/ColumnActionsMenu.tsx +60 -0
- package/src/components/Table/ColumnSettings.tsx +76 -0
- package/src/components/Table/RowActionsMenu.tsx +36 -0
- package/src/components/Table/Table.stories.tsx +197 -467
- package/src/components/Table/Table.tsx +177 -256
- package/src/components/Table/index.ts +1 -4
- package/src/components/TableCellEditor/TableCellEditor.stories.tsx +114 -0
- package/src/components/TableCellEditor/TableCellEditor.tsx +155 -0
- package/src/components/TableCellEditor/extension.ts +62 -0
- package/src/components/TableCellEditor/index.ts +5 -0
- package/src/components/Toolbar/Toolbar.tsx +87 -0
- package/src/components/Toolbar/common.tsx +71 -0
- package/src/components/Toolbar/index.ts +5 -0
- package/src/components/index.ts +2 -3
- package/src/components/testing.ts +114 -0
- package/src/hooks/index.ts +1 -4
- package/src/hooks/useTableModel.ts +52 -0
- package/src/index.ts +5 -6
- package/src/model/index.ts +6 -0
- package/src/model/modal-controller.ts +83 -0
- package/src/model/selection-model.ts +99 -0
- package/src/model/table-model.test.ts +182 -0
- package/src/model/table-model.ts +565 -0
- package/src/translations.ts +20 -13
- package/src/types/index.ts +5 -0
- package/src/types/table.ts +13 -0
- package/src/util/grid.ts +23 -0
- package/src/util/index.ts +8 -0
- package/src/util/signals.ts +9 -0
- package/src/util/table-buttons.ts +48 -0
- package/src/util/table-controls.ts +27 -0
- package/src/util/table.ts +77 -0
- package/dist/types/src/components/Cell/Cell.d.ts.map +0 -1
- package/dist/types/src/components/Cell/CellCombobox.d.ts.map +0 -1
- package/dist/types/src/components/Cell/index.d.ts.map +0 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.d.ts.map +0 -1
- package/dist/types/src/components/ColumnMenu/ColumnMenu.stories.d.ts.map +0 -1
- package/dist/types/src/components/ColumnMenu/ColumnSettings.d.ts.map +0 -1
- package/dist/types/src/components/ColumnMenu/ColumnSettings.stories.d.ts.map +0 -1
- package/dist/types/src/components/ColumnMenu/index.d.ts.map +0 -1
- package/dist/types/src/components/Table/TableBody.d.ts.map +0 -1
- package/dist/types/src/components/Table/TableContext.d.ts.map +0 -1
- package/dist/types/src/components/Table/TableHead.d.ts.map +0 -1
- package/dist/types/src/components/Table/TableRootContext.d.ts.map +0 -1
- package/dist/types/src/components/Table/props.d.ts.map +0 -1
- package/dist/types/src/helpers.d.ts.map +0 -1
- package/dist/types/src/hooks/useColumnSizing.d.ts.map +0 -1
- package/dist/types/src/hooks/useColumnSorting.d.ts.map +0 -1
- package/dist/types/src/hooks/usePinLastRow.d.ts.map +0 -1
- package/dist/types/src/hooks/useRowSelection.d.ts.map +0 -1
- package/dist/types/src/schema/Schema.stories.d.ts.map +0 -1
- package/dist/types/src/schema/column-utils.d.ts.map +0 -1
- package/dist/types/src/schema/index.d.ts.map +0 -1
- package/dist/types/src/schema/types.d.ts.map +0 -1
- package/dist/types/src/theme.d.ts.map +0 -1
- package/dist/types/src/types.d.ts.map +0 -1
- package/src/schema/column-utils.ts +0 -48
- /package/dist/types/src/{components → _deprecated/components}/Cell/Cell.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/Cell/CellCombobox.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/Cell/index.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/ColumnMenu/ColumnMenu.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/ColumnMenu/ColumnMenu.stories.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/ColumnMenu/ColumnSettings.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/ColumnMenu/index.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/Table/TableBody.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/Table/TableContext.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/Table/TableHead.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/Table/TableRootContext.d.ts +0 -0
- /package/dist/types/src/{components → _deprecated/components}/Table/props.d.ts +0 -0
- /package/dist/types/src/{helpers.d.ts → _deprecated/helpers.d.ts} +0 -0
- /package/dist/types/src/{hooks → _deprecated/hooks}/useColumnSizing.d.ts +0 -0
- /package/dist/types/src/{hooks → _deprecated/hooks}/usePinLastRow.d.ts +0 -0
- /package/dist/types/src/{hooks → _deprecated/hooks}/useRowSelection.d.ts +0 -0
- /package/dist/types/src/{schema → _deprecated/schema}/Schema.stories.d.ts +0 -0
- /package/dist/types/src/{schema → _deprecated/schema}/index.d.ts +0 -0
- /package/dist/types/src/{theme.d.ts → _deprecated/theme.d.ts} +0 -0
- /package/dist/types/src/{types.d.ts → _deprecated/types.d.ts} +0 -0
- /package/src/{components → _deprecated/components}/Cell/Cell.tsx +0 -0
- /package/src/{components → _deprecated/components}/Cell/CellCombobox.tsx +0 -0
- /package/src/{components → _deprecated/components}/Cell/index.ts +0 -0
- /package/src/{components → _deprecated/components}/ColumnMenu/ColumnMenu.tsx +0 -0
- /package/src/{components → _deprecated/components}/ColumnMenu/index.ts +0 -0
- /package/src/{components → _deprecated/components}/Table/TableBody.tsx +0 -0
- /package/src/{components → _deprecated/components}/Table/TableContext.tsx +0 -0
- /package/src/{components → _deprecated/components}/Table/TableRootContext.ts +0 -0
- /package/src/{components → _deprecated/components}/Table/props.ts +0 -0
- /package/src/{hooks → _deprecated/hooks}/useColumnSizing.ts +0 -0
- /package/src/{hooks → _deprecated/hooks}/useColumnSorting.ts +0 -0
- /package/src/{hooks → _deprecated/hooks}/usePinLastRow.ts +0 -0
- /package/src/{hooks → _deprecated/hooks}/useRowSelection.ts +0 -0
- /package/src/{schema → _deprecated/schema}/Schema.stories.tsx +0 -0
- /package/src/{schema → _deprecated/schema}/index.ts +0 -0
- /package/src/{theme.ts → _deprecated/theme.ts} +0 -0
- /package/src/{types.ts → _deprecated/types.ts} +0 -0
|
@@ -0,0 +1,1380 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __export = (target, all) => {
|
|
9
|
+
for (var name in all)
|
|
10
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
+
};
|
|
12
|
+
var __copyProps = (to, from, except, desc) => {
|
|
13
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
+
for (let key of __getOwnPropNames(from))
|
|
15
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
19
|
+
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
28
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
+
var node_exports = {};
|
|
30
|
+
__export(node_exports, {
|
|
31
|
+
Table: () => Table,
|
|
32
|
+
TableType: () => import_chunk_32IGMRME.TableType,
|
|
33
|
+
Toolbar: () => Toolbar,
|
|
34
|
+
fromGridCell: () => fromGridCell,
|
|
35
|
+
initializeTable: () => initializeTable,
|
|
36
|
+
tableButtons: () => tableButtons,
|
|
37
|
+
toGridCell: () => toGridCell,
|
|
38
|
+
touch: () => touch,
|
|
39
|
+
translations: () => translations_default,
|
|
40
|
+
useTableModel: () => useTableModel,
|
|
41
|
+
useToolbarContext: () => useToolbarContext
|
|
42
|
+
});
|
|
43
|
+
module.exports = __toCommonJS(node_exports);
|
|
44
|
+
var import_chunk_32IGMRME = require("./chunk-32IGMRME.cjs");
|
|
45
|
+
var import_react = __toESM(require("react"));
|
|
46
|
+
var import_echo_schema = require("@dxos/echo-schema");
|
|
47
|
+
var import_invariant = require("@dxos/invariant");
|
|
48
|
+
var import_echo = require("@dxos/react-client/echo");
|
|
49
|
+
var import_react_ui_attention = require("@dxos/react-ui-attention");
|
|
50
|
+
var import_react_ui_grid = require("@dxos/react-ui-grid");
|
|
51
|
+
var import_react_ui_theme = require("@dxos/react-ui-theme");
|
|
52
|
+
var import_util = require("@dxos/util");
|
|
53
|
+
var import_react2 = __toESM(require("react"));
|
|
54
|
+
var import_react_ui = require("@dxos/react-ui");
|
|
55
|
+
var import_react3 = __toESM(require("react"));
|
|
56
|
+
var import_echo2 = require("@dxos/react-client/echo");
|
|
57
|
+
var import_react_ui2 = require("@dxos/react-ui");
|
|
58
|
+
var import_react_ui_form = require("@dxos/react-ui-form");
|
|
59
|
+
var import_react4 = __toESM(require("react"));
|
|
60
|
+
var import_react_ui3 = require("@dxos/react-ui");
|
|
61
|
+
var import_react5 = __toESM(require("react"));
|
|
62
|
+
var import_echo_schema2 = require("@dxos/echo-schema");
|
|
63
|
+
var import_invariant2 = require("@dxos/invariant");
|
|
64
|
+
var import_react_ui_grid2 = require("@dxos/react-ui-grid");
|
|
65
|
+
var import_autocomplete = require("@codemirror/autocomplete");
|
|
66
|
+
var import_view = require("@codemirror/view");
|
|
67
|
+
var import_echo_schema3 = require("@dxos/echo-schema");
|
|
68
|
+
var import_log = require("@dxos/log");
|
|
69
|
+
var import_react_client = require("@dxos/react-client");
|
|
70
|
+
var import_echo3 = require("@dxos/react-client/echo");
|
|
71
|
+
var import_schema = require("@dxos/schema");
|
|
72
|
+
var import_react_context = require("@radix-ui/react-context");
|
|
73
|
+
var import_react6 = __toESM(require("react"));
|
|
74
|
+
var import_react_ui4 = require("@dxos/react-ui");
|
|
75
|
+
var import_react7 = __toESM(require("react"));
|
|
76
|
+
var import_react_ui5 = require("@dxos/react-ui");
|
|
77
|
+
var import_react8 = require("react");
|
|
78
|
+
var import_signals_core = require("@preact/signals-core");
|
|
79
|
+
var import_lodash = __toESM(require("lodash.orderby"));
|
|
80
|
+
var import_context = require("@dxos/context");
|
|
81
|
+
var import_echo_schema4 = require("@dxos/echo-schema");
|
|
82
|
+
var import_invariant3 = require("@dxos/invariant");
|
|
83
|
+
var import_react_client2 = require("@dxos/react-client");
|
|
84
|
+
var import_react_ui_form2 = require("@dxos/react-ui-form");
|
|
85
|
+
var import_react_ui_theme2 = require("@dxos/react-ui-theme");
|
|
86
|
+
var import_schema2 = require("@dxos/schema");
|
|
87
|
+
var import_signals_core2 = require("@preact/signals-core");
|
|
88
|
+
var import_signals_core3 = require("@preact/signals-core");
|
|
89
|
+
var import_context2 = require("@dxos/context");
|
|
90
|
+
var translationKey = "table";
|
|
91
|
+
var translations_default = [
|
|
92
|
+
{
|
|
93
|
+
"en-US": {
|
|
94
|
+
[translationKey]: {
|
|
95
|
+
"object placeholder": "New table",
|
|
96
|
+
"create object label": "Create table",
|
|
97
|
+
"table name placeholder": "Table name",
|
|
98
|
+
"settings title": "Table settings",
|
|
99
|
+
"table schema label": "Schema",
|
|
100
|
+
"new schema": "New schema",
|
|
101
|
+
"continue label": "Continue",
|
|
102
|
+
"create stack section label": "Create table",
|
|
103
|
+
"add row": "Add row",
|
|
104
|
+
"create comment": "Create thread",
|
|
105
|
+
"column action sort descending": "Sort Descending",
|
|
106
|
+
"column action sort ascending": "Sort Ascending",
|
|
107
|
+
"column action clear sorting": "Clear Sorting",
|
|
108
|
+
"column action settings": "Column Settings",
|
|
109
|
+
"column action delete": "Delete Column",
|
|
110
|
+
"delete row label": "Delete row",
|
|
111
|
+
"bulk delete row label": "Delete selected rows",
|
|
112
|
+
"column deleted label": "Column deleted",
|
|
113
|
+
"new column button label": "Create column"
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
];
|
|
118
|
+
var ColumnActionsMenu = ({ model }) => {
|
|
119
|
+
const { t } = (0, import_react_ui.useTranslation)(translationKey);
|
|
120
|
+
const state = model?.modalController.state.value;
|
|
121
|
+
if (!model || state?.type !== "column") {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
const currentSort = model.sorting;
|
|
125
|
+
const isCurrentColumnSorted = currentSort?.fieldId === state.fieldId;
|
|
126
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Root, {
|
|
127
|
+
modal: false,
|
|
128
|
+
open: state?.type === "column",
|
|
129
|
+
onOpenChange: model.modalController.close
|
|
130
|
+
}, /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.VirtualTrigger, {
|
|
131
|
+
virtualRef: model.modalController.trigger
|
|
132
|
+
}), /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Portal, null, /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Content, null, /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Viewport, null, (!isCurrentColumnSorted || currentSort?.direction === "asc") && /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Item, {
|
|
133
|
+
onClick: () => model.setSort(state.fieldId, "desc")
|
|
134
|
+
}, t("column action sort descending")), (!isCurrentColumnSorted || currentSort?.direction === "desc") && /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Item, {
|
|
135
|
+
onClick: () => model.setSort(state.fieldId, "asc")
|
|
136
|
+
}, t("column action sort ascending")), isCurrentColumnSorted && /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Item, {
|
|
137
|
+
onClick: () => model.clearSort()
|
|
138
|
+
}, t("column action clear sorting")), model.getColumnCount() > 1 && /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Item, {
|
|
139
|
+
onClick: () => model.deleteColumn(state.fieldId)
|
|
140
|
+
}, t("column action delete")), /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Item, {
|
|
141
|
+
onClick: () => model.modalController.openColumnSettings()
|
|
142
|
+
}, t("column action settings"))), /* @__PURE__ */ import_react2.default.createElement(import_react_ui.DropdownMenu.Arrow, null))));
|
|
143
|
+
};
|
|
144
|
+
var ColumnSettings = ({ model }) => {
|
|
145
|
+
const [newField, setNewField] = (0, import_react3.useState)();
|
|
146
|
+
const state = model?.modalController.state.value;
|
|
147
|
+
const space = (0, import_echo2.getSpace)(model?.table);
|
|
148
|
+
(0, import_react3.useEffect)(() => {
|
|
149
|
+
if (state?.type === "columnSettings" && state.mode.type === "create" && model?.projection) {
|
|
150
|
+
setNewField(model.projection.createFieldProjection());
|
|
151
|
+
} else {
|
|
152
|
+
setNewField(void 0);
|
|
153
|
+
}
|
|
154
|
+
}, [
|
|
155
|
+
model?.projection,
|
|
156
|
+
state
|
|
157
|
+
]);
|
|
158
|
+
const existingField = (0, import_react3.useMemo)(() => {
|
|
159
|
+
if (state?.type === "columnSettings") {
|
|
160
|
+
const { mode } = state;
|
|
161
|
+
if (mode.type === "edit") {
|
|
162
|
+
return model?.table?.view?.fields.find((f) => f.id === mode.fieldId);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
return void 0;
|
|
166
|
+
}, [
|
|
167
|
+
model?.table?.view?.fields,
|
|
168
|
+
state
|
|
169
|
+
]);
|
|
170
|
+
const field = existingField ?? newField;
|
|
171
|
+
const handleClose = (0, import_react3.useCallback)(() => {
|
|
172
|
+
model?.modalController.close();
|
|
173
|
+
}, [
|
|
174
|
+
model?.modalController
|
|
175
|
+
]);
|
|
176
|
+
const handleCancel = (0, import_react3.useCallback)(() => {
|
|
177
|
+
if (state?.type === "columnSettings" && state.mode.type === "create" && newField) {
|
|
178
|
+
model?.projection?.deleteFieldProjection(newField.id);
|
|
179
|
+
}
|
|
180
|
+
}, [
|
|
181
|
+
model?.projection,
|
|
182
|
+
state,
|
|
183
|
+
newField
|
|
184
|
+
]);
|
|
185
|
+
if (!model?.table?.view || !model.projection || !field) {
|
|
186
|
+
return null;
|
|
187
|
+
}
|
|
188
|
+
return /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.DropdownMenu.Root, {
|
|
189
|
+
modal: false,
|
|
190
|
+
open: state?.type === "columnSettings"
|
|
191
|
+
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.DropdownMenu.VirtualTrigger, {
|
|
192
|
+
virtualRef: model.modalController.trigger
|
|
193
|
+
}), /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.DropdownMenu.Portal, null, /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.DropdownMenu.Content, {
|
|
194
|
+
classNames: "md:is-64"
|
|
195
|
+
}, /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.DropdownMenu.Viewport, null, /* @__PURE__ */ import_react3.default.createElement(import_react_ui_form.FieldEditor, {
|
|
196
|
+
view: model.table.view,
|
|
197
|
+
projection: model.projection,
|
|
198
|
+
field,
|
|
199
|
+
registry: space?.db.schemaRegistry,
|
|
200
|
+
onClose: handleClose,
|
|
201
|
+
onCancel: handleCancel
|
|
202
|
+
})), /* @__PURE__ */ import_react3.default.createElement(import_react_ui2.DropdownMenu.Arrow, null))));
|
|
203
|
+
};
|
|
204
|
+
var RowActionsMenu = ({ model }) => {
|
|
205
|
+
const { t } = (0, import_react_ui3.useTranslation)(translationKey);
|
|
206
|
+
const state = model.modalController.state.value;
|
|
207
|
+
const hasSelection = model.selection.hasSelection.value;
|
|
208
|
+
if (state?.type !== "row") {
|
|
209
|
+
return null;
|
|
210
|
+
}
|
|
211
|
+
return /* @__PURE__ */ import_react4.default.createElement(import_react_ui3.DropdownMenu.Root, {
|
|
212
|
+
modal: false,
|
|
213
|
+
open: true,
|
|
214
|
+
onOpenChange: model.modalController.close
|
|
215
|
+
}, /* @__PURE__ */ import_react4.default.createElement(import_react_ui3.DropdownMenu.VirtualTrigger, {
|
|
216
|
+
virtualRef: model.modalController.trigger
|
|
217
|
+
}), /* @__PURE__ */ import_react4.default.createElement(import_react_ui3.DropdownMenu.Content, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui3.DropdownMenu.Viewport, null, /* @__PURE__ */ import_react4.default.createElement(import_react_ui3.DropdownMenu.Item, {
|
|
218
|
+
onClick: () => model.deleteRow(state.rowIndex)
|
|
219
|
+
}, t(hasSelection ? "bulk delete row label" : "delete row label"))), /* @__PURE__ */ import_react4.default.createElement(import_react_ui3.DropdownMenu.Arrow, null)));
|
|
220
|
+
};
|
|
221
|
+
var completion = ({ onQuery, onMatch }) => {
|
|
222
|
+
return [
|
|
223
|
+
import_view.EditorView.theme({
|
|
224
|
+
".cm-completionDialog": {
|
|
225
|
+
width: "var(--dx-gridCellWidth)"
|
|
226
|
+
}
|
|
227
|
+
}),
|
|
228
|
+
(0, import_autocomplete.autocompletion)({
|
|
229
|
+
icons: false,
|
|
230
|
+
activateOnTyping: true,
|
|
231
|
+
override: [
|
|
232
|
+
async (context) => {
|
|
233
|
+
const text = context.state.doc.toString();
|
|
234
|
+
return {
|
|
235
|
+
from: 0,
|
|
236
|
+
options: await onQuery(text)
|
|
237
|
+
};
|
|
238
|
+
}
|
|
239
|
+
],
|
|
240
|
+
// TODO(burdon): Consts from grid (to line-up with grid).
|
|
241
|
+
tooltipClass: () => "cm-completionDialog !mt-[8px] !-ml-[4px] [&>ul]:!max-h-[264px]",
|
|
242
|
+
optionClass: () => "flex h-[33px] items-center"
|
|
243
|
+
}),
|
|
244
|
+
// Check for accepted completion metadata in the transaction.
|
|
245
|
+
import_view.EditorView.updateListener.of((update) => {
|
|
246
|
+
update.transactions.forEach((tr) => {
|
|
247
|
+
const completion2 = tr.annotation(import_autocomplete.pickedCompletion);
|
|
248
|
+
if (completion2) {
|
|
249
|
+
onMatch(completion2.data);
|
|
250
|
+
}
|
|
251
|
+
});
|
|
252
|
+
})
|
|
253
|
+
];
|
|
254
|
+
};
|
|
255
|
+
var fromGridCell = ({ col, row }) => {
|
|
256
|
+
return `${col},${row}`;
|
|
257
|
+
};
|
|
258
|
+
var toGridCell = (cell) => {
|
|
259
|
+
const [col, row] = cell.split(",").map(Number);
|
|
260
|
+
return {
|
|
261
|
+
row,
|
|
262
|
+
col
|
|
263
|
+
};
|
|
264
|
+
};
|
|
265
|
+
var touch = (value) => value;
|
|
266
|
+
var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/util/table.ts";
|
|
267
|
+
var initializeTable = ({ space, table }) => {
|
|
268
|
+
import_log.log.info("initializeTable", {
|
|
269
|
+
table
|
|
270
|
+
}, {
|
|
271
|
+
F: __dxlog_file,
|
|
272
|
+
L: 26,
|
|
273
|
+
S: void 0,
|
|
274
|
+
C: (f, a) => f(...a)
|
|
275
|
+
});
|
|
276
|
+
const ContactSchema = (0, import_echo_schema3.TypedObject)({
|
|
277
|
+
typename: `example.com/type/${import_react_client.PublicKey.random().truncate()}`,
|
|
278
|
+
version: "0.1.0"
|
|
279
|
+
})({
|
|
280
|
+
name: import_echo_schema3.S.optional(import_echo_schema3.S.String).annotations({
|
|
281
|
+
[import_echo_schema3.AST.TitleAnnotationId]: "Name"
|
|
282
|
+
}),
|
|
283
|
+
email: import_echo_schema3.S.optional(import_echo_schema3.Format.Email),
|
|
284
|
+
salary: import_echo_schema3.S.optional(import_echo_schema3.Format.Currency()).annotations({
|
|
285
|
+
[import_echo_schema3.AST.TitleAnnotationId]: "Salary"
|
|
286
|
+
})
|
|
287
|
+
});
|
|
288
|
+
const contactSchema = space.db.schemaRegistry.addSchema(ContactSchema);
|
|
289
|
+
table.view = (0, import_schema.createView)({
|
|
290
|
+
name: "Test",
|
|
291
|
+
typename: contactSchema.typename,
|
|
292
|
+
jsonSchema: contactSchema.jsonSchema,
|
|
293
|
+
fields: [
|
|
294
|
+
"name",
|
|
295
|
+
"email",
|
|
296
|
+
"salary"
|
|
297
|
+
]
|
|
298
|
+
});
|
|
299
|
+
const projection = new import_schema.ViewProjection(contactSchema, table.view);
|
|
300
|
+
projection.setFieldProjection({
|
|
301
|
+
field: {
|
|
302
|
+
id: table.view.fields[2].id,
|
|
303
|
+
path: "salary",
|
|
304
|
+
size: 150
|
|
305
|
+
}
|
|
306
|
+
});
|
|
307
|
+
projection.setFieldProjection({
|
|
308
|
+
field: {
|
|
309
|
+
id: (0, import_schema.createFieldId)(),
|
|
310
|
+
path: "manager",
|
|
311
|
+
referencePath: "name"
|
|
312
|
+
},
|
|
313
|
+
props: {
|
|
314
|
+
property: "manager",
|
|
315
|
+
type: import_echo_schema3.TypeEnum.Ref,
|
|
316
|
+
format: import_echo_schema3.FormatEnum.Ref,
|
|
317
|
+
referenceSchema: contactSchema.typename,
|
|
318
|
+
title: "Manager"
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
space.db.add((0, import_echo3.create)(contactSchema, {}));
|
|
322
|
+
return contactSchema;
|
|
323
|
+
};
|
|
324
|
+
var TABLE_ATTRS = {
|
|
325
|
+
columnSettings: "data-table-column-settings-button",
|
|
326
|
+
rowMenu: "data-table-row-menu-button",
|
|
327
|
+
newColumn: "data-table-new-column-button"
|
|
328
|
+
};
|
|
329
|
+
var ICONS = {
|
|
330
|
+
columnSettings: "ph--caret-down--regular",
|
|
331
|
+
rowMenu: "ph--dots-three--regular",
|
|
332
|
+
newColumn: "ph--plus--regular"
|
|
333
|
+
};
|
|
334
|
+
var createButtonHtml = ({ button, value = "", disabled = false }) => {
|
|
335
|
+
const buttonClasses = "ch-button is-6 pli-0.5 min-bs-0 absolute inset-block-1 inline-end-2";
|
|
336
|
+
return `<button class="${buttonClasses}" ${TABLE_ATTRS[button]}="${value}" ${disabled ? "disabled" : ""}><svg><use href="/icons.svg#${ICONS[button]}"/></svg></button>`;
|
|
337
|
+
};
|
|
338
|
+
var tableButtons = {
|
|
339
|
+
columnSettings: {
|
|
340
|
+
attr: TABLE_ATTRS.columnSettings,
|
|
341
|
+
icon: ICONS.columnSettings,
|
|
342
|
+
render: ({ fieldId }) => createButtonHtml({
|
|
343
|
+
button: "columnSettings",
|
|
344
|
+
value: fieldId
|
|
345
|
+
})
|
|
346
|
+
},
|
|
347
|
+
rowMenu: {
|
|
348
|
+
attr: TABLE_ATTRS.rowMenu,
|
|
349
|
+
icon: ICONS.rowMenu,
|
|
350
|
+
render: ({ rowIndex }) => createButtonHtml({
|
|
351
|
+
button: "rowMenu",
|
|
352
|
+
value: rowIndex.toString()
|
|
353
|
+
})
|
|
354
|
+
},
|
|
355
|
+
addColumn: {
|
|
356
|
+
attr: TABLE_ATTRS.newColumn,
|
|
357
|
+
icon: ICONS.newColumn,
|
|
358
|
+
render: ({ disabled } = {}) => createButtonHtml({
|
|
359
|
+
button: "newColumn",
|
|
360
|
+
disabled
|
|
361
|
+
})
|
|
362
|
+
}
|
|
363
|
+
};
|
|
364
|
+
var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/TableCellEditor/TableCellEditor.tsx";
|
|
365
|
+
var TableCellEditor = ({ model, onEnter, onFocus, onQuery, __gridScope }) => {
|
|
366
|
+
const { editing } = (0, import_react_ui_grid2.useGridContext)("TableCellEditor", __gridScope);
|
|
367
|
+
const fieldProjection = (0, import_react5.useMemo)(() => {
|
|
368
|
+
if (!model || !editing) {
|
|
369
|
+
return;
|
|
370
|
+
}
|
|
371
|
+
const { col } = toGridCell(editing.index);
|
|
372
|
+
const field = model.projection.view.fields[col];
|
|
373
|
+
const fieldProjection2 = model.projection.getFieldProjection(field.id);
|
|
374
|
+
(0, import_invariant2.invariant)(fieldProjection2, void 0, {
|
|
375
|
+
F: __dxlog_file2,
|
|
376
|
+
L: 49,
|
|
377
|
+
S: void 0,
|
|
378
|
+
A: [
|
|
379
|
+
"fieldProjection",
|
|
380
|
+
""
|
|
381
|
+
]
|
|
382
|
+
});
|
|
383
|
+
return fieldProjection2;
|
|
384
|
+
}, [
|
|
385
|
+
model,
|
|
386
|
+
editing
|
|
387
|
+
]);
|
|
388
|
+
const handleClose = (0, import_react5.useCallback)((value, event) => {
|
|
389
|
+
if (!model || !editing || !fieldProjection) {
|
|
390
|
+
return;
|
|
391
|
+
}
|
|
392
|
+
const cell = toGridCell(editing.index);
|
|
393
|
+
onEnter?.(cell);
|
|
394
|
+
if (event && onFocus) {
|
|
395
|
+
onFocus(determineNavigationAxis(event), determineNavigationDelta(event));
|
|
396
|
+
}
|
|
397
|
+
}, [
|
|
398
|
+
model,
|
|
399
|
+
editing,
|
|
400
|
+
onFocus,
|
|
401
|
+
onEnter,
|
|
402
|
+
fieldProjection,
|
|
403
|
+
determineNavigationAxis,
|
|
404
|
+
determineNavigationDelta
|
|
405
|
+
]);
|
|
406
|
+
const handleBlur = (0, import_react5.useCallback)((value) => {
|
|
407
|
+
if (!model || !editing) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
const cell = toGridCell(editing.index);
|
|
411
|
+
if (value !== void 0) {
|
|
412
|
+
model.setCellData(cell, value);
|
|
413
|
+
}
|
|
414
|
+
}, [
|
|
415
|
+
model,
|
|
416
|
+
editing
|
|
417
|
+
]);
|
|
418
|
+
const extension = (0, import_react5.useMemo)(() => {
|
|
419
|
+
if (!fieldProjection) {
|
|
420
|
+
return [];
|
|
421
|
+
}
|
|
422
|
+
const extension2 = [
|
|
423
|
+
(0, import_react_ui_grid2.editorKeys)({
|
|
424
|
+
onClose: handleClose,
|
|
425
|
+
...editing?.initialContent && {
|
|
426
|
+
onNav: handleClose
|
|
427
|
+
}
|
|
428
|
+
})
|
|
429
|
+
];
|
|
430
|
+
if (onQuery) {
|
|
431
|
+
switch (fieldProjection.props.format) {
|
|
432
|
+
case import_echo_schema2.FormatEnum.Ref: {
|
|
433
|
+
extension2.push([
|
|
434
|
+
completion({
|
|
435
|
+
onQuery: (text) => onQuery(fieldProjection, text),
|
|
436
|
+
onMatch: (data) => {
|
|
437
|
+
if (model && editing) {
|
|
438
|
+
const cell = toGridCell(editing.index);
|
|
439
|
+
model.setCellData(cell, data);
|
|
440
|
+
onEnter?.(cell);
|
|
441
|
+
onFocus?.();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
})
|
|
445
|
+
]);
|
|
446
|
+
break;
|
|
447
|
+
}
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
return extension2;
|
|
451
|
+
}, [
|
|
452
|
+
model,
|
|
453
|
+
editing,
|
|
454
|
+
fieldProjection,
|
|
455
|
+
handleClose
|
|
456
|
+
]);
|
|
457
|
+
const getCellContent = (0, import_react5.useCallback)(() => {
|
|
458
|
+
if (model && editing) {
|
|
459
|
+
const value = model.getCellData(toGridCell(editing.index));
|
|
460
|
+
return value !== void 0 ? String(value) : "";
|
|
461
|
+
}
|
|
462
|
+
}, [
|
|
463
|
+
model,
|
|
464
|
+
editing
|
|
465
|
+
]);
|
|
466
|
+
return /* @__PURE__ */ import_react5.default.createElement(import_react_ui_grid2.GridCellEditor, {
|
|
467
|
+
extension,
|
|
468
|
+
getCellContent,
|
|
469
|
+
onBlur: handleBlur
|
|
470
|
+
});
|
|
471
|
+
};
|
|
472
|
+
var determineNavigationAxis = ({ key }) => {
|
|
473
|
+
switch (key) {
|
|
474
|
+
case "ArrowUp":
|
|
475
|
+
case "ArrowDown":
|
|
476
|
+
case "Enter": {
|
|
477
|
+
return "row";
|
|
478
|
+
}
|
|
479
|
+
case "ArrowLeft":
|
|
480
|
+
case "ArrowRight":
|
|
481
|
+
case "Tab":
|
|
482
|
+
return "col";
|
|
483
|
+
}
|
|
484
|
+
};
|
|
485
|
+
var determineNavigationDelta = ({ key, shift }) => {
|
|
486
|
+
switch (key) {
|
|
487
|
+
case "ArrowUp":
|
|
488
|
+
case "ArrowLeft":
|
|
489
|
+
return -1;
|
|
490
|
+
case "ArrowDown":
|
|
491
|
+
case "ArrowRight":
|
|
492
|
+
return 1;
|
|
493
|
+
}
|
|
494
|
+
return shift ? -1 : 1;
|
|
495
|
+
};
|
|
496
|
+
var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/components/Table/Table.tsx";
|
|
497
|
+
var inlineEndLine = "[&>.dx-grid]:relative [&>.dx-grid]:after:absolute [&>.dx-grid]:after:inset-block-0 [&>.dx-grid]:after:-inline-end-px [&>.dx-grid]:after:is-px [&>.dx-grid]:after:bg-separator";
|
|
498
|
+
var blockEndLine = "[&>.dx-grid]:before:absolute [&>.dx-grid]:before:inset-inline-0 [&>.dx-grid]:before:-block-end-px [&>.dx-grid]:before:bs-px [&>.dx-grid]:before:bg-separator";
|
|
499
|
+
var frozen = {
|
|
500
|
+
frozenRowsStart: 1,
|
|
501
|
+
frozenColsStart: 1,
|
|
502
|
+
frozenColsEnd: 1
|
|
503
|
+
};
|
|
504
|
+
var TableRoot = ({ children, role }) => {
|
|
505
|
+
return /* @__PURE__ */ import_react.default.createElement("div", {
|
|
506
|
+
role: "none",
|
|
507
|
+
className: (0, import_react_ui_theme.mx)("relative border-bs !border-separator", role === "section" ? "attention-surface overflow-hidden [&_.dx-grid]:max-is-max" : "flex flex-col [&_.dx-grid]:grow [&_.dx-grid]:max-is-max [&_.dx-grid]:bs-0 [&_.dx-grid]:max-bs-max")
|
|
508
|
+
}, children);
|
|
509
|
+
};
|
|
510
|
+
var TableMain = /* @__PURE__ */ (0, import_react.forwardRef)(({ model, ignoreAttention }, forwardedRef) => {
|
|
511
|
+
const [dxGrid, setDxGrid] = (0, import_react.useState)(null);
|
|
512
|
+
const { hasAttention } = (0, import_react_ui_attention.useAttention)(model?.table ? (0, import_echo.fullyQualifiedId)(model.table) : "table");
|
|
513
|
+
(0, import_react.useImperativeHandle)(forwardedRef, () => {
|
|
514
|
+
if (!model || !dxGrid) {
|
|
515
|
+
return {};
|
|
516
|
+
}
|
|
517
|
+
dxGrid.getCells = model.getCells.bind(model);
|
|
518
|
+
return {
|
|
519
|
+
update: (cell) => {
|
|
520
|
+
if (cell) {
|
|
521
|
+
dxGrid.updateIfWithinBounds(cell);
|
|
522
|
+
} else {
|
|
523
|
+
dxGrid.updateCells(true);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
};
|
|
527
|
+
}, [
|
|
528
|
+
model,
|
|
529
|
+
dxGrid
|
|
530
|
+
]);
|
|
531
|
+
const handleFocus = (increment, delta) => {
|
|
532
|
+
dxGrid?.refocus(increment, delta);
|
|
533
|
+
};
|
|
534
|
+
const handleEnter = (0, import_react.useCallback)((cell) => {
|
|
535
|
+
if (model && cell.row === model.getRowCount() - 1) {
|
|
536
|
+
model.insertRow(cell.row);
|
|
537
|
+
}
|
|
538
|
+
}, [
|
|
539
|
+
model
|
|
540
|
+
]);
|
|
541
|
+
const handleKeyDown = (0, import_react.useCallback)((event) => {
|
|
542
|
+
const cell = (0, import_react_ui_grid.closestCell)(event.target);
|
|
543
|
+
if (!model || !cell) {
|
|
544
|
+
return;
|
|
545
|
+
}
|
|
546
|
+
switch (event.key) {
|
|
547
|
+
case "Backspace":
|
|
548
|
+
case "Delete": {
|
|
549
|
+
model.setCellData(cell, void 0);
|
|
550
|
+
break;
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
}, [
|
|
554
|
+
model
|
|
555
|
+
]);
|
|
556
|
+
const handleAxisResize = (0, import_react.useCallback)((event) => {
|
|
557
|
+
if (event.axis === "col") {
|
|
558
|
+
const columnIndex = parseInt(event.index, 10);
|
|
559
|
+
model?.setColumnWidth(columnIndex, event.size);
|
|
560
|
+
}
|
|
561
|
+
}, [
|
|
562
|
+
model
|
|
563
|
+
]);
|
|
564
|
+
const handleWheel = (0, import_react.useCallback)((event) => {
|
|
565
|
+
if (!ignoreAttention && !hasAttention) {
|
|
566
|
+
event.stopPropagation();
|
|
567
|
+
}
|
|
568
|
+
}, [
|
|
569
|
+
hasAttention,
|
|
570
|
+
ignoreAttention
|
|
571
|
+
]);
|
|
572
|
+
const handleQuery = (0, import_react.useCallback)(async ({ field, props }, _text) => {
|
|
573
|
+
if (model && props.referenceSchema && field.referencePath) {
|
|
574
|
+
const space = (0, import_echo.getSpace)(model.table);
|
|
575
|
+
(0, import_invariant.invariant)(space, void 0, {
|
|
576
|
+
F: __dxlog_file3,
|
|
577
|
+
L: 158,
|
|
578
|
+
S: void 0,
|
|
579
|
+
A: [
|
|
580
|
+
"space",
|
|
581
|
+
""
|
|
582
|
+
]
|
|
583
|
+
});
|
|
584
|
+
const schema = space.db.schemaRegistry.getSchema(props.referenceSchema);
|
|
585
|
+
if (schema) {
|
|
586
|
+
const { objects } = await space.db.query(import_echo.Filter.schema(schema)).run();
|
|
587
|
+
return objects.map((obj) => {
|
|
588
|
+
const value = (0, import_echo_schema.getValue)(obj, field.referencePath);
|
|
589
|
+
if (!value || typeof value !== "string") {
|
|
590
|
+
return void 0;
|
|
591
|
+
}
|
|
592
|
+
return {
|
|
593
|
+
label: value,
|
|
594
|
+
data: obj
|
|
595
|
+
};
|
|
596
|
+
}).filter(import_util.isNotFalsy);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
return [];
|
|
600
|
+
}, [
|
|
601
|
+
model
|
|
602
|
+
]);
|
|
603
|
+
if (!model) {
|
|
604
|
+
return /* @__PURE__ */ import_react.default.createElement("span", {
|
|
605
|
+
role: "none",
|
|
606
|
+
className: "attention-surface"
|
|
607
|
+
});
|
|
608
|
+
}
|
|
609
|
+
return /* @__PURE__ */ import_react.default.createElement(import_react.default.Fragment, null, /* @__PURE__ */ import_react.default.createElement(import_react_ui_grid.Grid.Root, {
|
|
610
|
+
id: model.table.id ?? "table-grid"
|
|
611
|
+
}, /* @__PURE__ */ import_react.default.createElement(TableCellEditor, {
|
|
612
|
+
model,
|
|
613
|
+
onEnter: handleEnter,
|
|
614
|
+
onFocus: handleFocus,
|
|
615
|
+
onQuery: handleQuery
|
|
616
|
+
}), /* @__PURE__ */ import_react.default.createElement(import_react_ui_grid.Grid.Content, {
|
|
617
|
+
onWheelCapture: handleWheel,
|
|
618
|
+
className: (0, import_react_ui_theme.mx)("[--dx-grid-base:var(--surface-bg)]", inlineEndLine, blockEndLine),
|
|
619
|
+
frozen,
|
|
620
|
+
columns: model.columnMeta.value,
|
|
621
|
+
limitRows: model.getRowCount() ?? 0,
|
|
622
|
+
limitColumns: model.table.view?.fields?.length ?? 0,
|
|
623
|
+
onAxisResize: handleAxisResize,
|
|
624
|
+
onClick: model?.handleGridClick,
|
|
625
|
+
onKeyDown: handleKeyDown,
|
|
626
|
+
overscroll: "trap",
|
|
627
|
+
ref: setDxGrid
|
|
628
|
+
})), /* @__PURE__ */ import_react.default.createElement(RowActionsMenu, {
|
|
629
|
+
model
|
|
630
|
+
}), /* @__PURE__ */ import_react.default.createElement(ColumnActionsMenu, {
|
|
631
|
+
model
|
|
632
|
+
}), /* @__PURE__ */ import_react.default.createElement(ColumnSettings, {
|
|
633
|
+
model
|
|
634
|
+
}));
|
|
635
|
+
});
|
|
636
|
+
var Table = {
|
|
637
|
+
Root: TableRoot,
|
|
638
|
+
Main: TableMain
|
|
639
|
+
};
|
|
640
|
+
var buttonStyles = "min-bs-0 p-2";
|
|
641
|
+
var tooltipProps = {
|
|
642
|
+
side: "top",
|
|
643
|
+
classNames: "z-10"
|
|
644
|
+
};
|
|
645
|
+
var ToolbarSeparator = () => /* @__PURE__ */ import_react7.default.createElement("div", {
|
|
646
|
+
role: "separator",
|
|
647
|
+
className: "grow"
|
|
648
|
+
});
|
|
649
|
+
var ToolbarButton = ({ icon, children, ...props }) => {
|
|
650
|
+
return /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Tooltip.Root, null, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Tooltip.Trigger, {
|
|
651
|
+
asChild: true
|
|
652
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Toolbar.Button, {
|
|
653
|
+
variant: "ghost",
|
|
654
|
+
...props,
|
|
655
|
+
classNames: buttonStyles
|
|
656
|
+
}, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Icon, {
|
|
657
|
+
icon,
|
|
658
|
+
size: 5
|
|
659
|
+
}), /* @__PURE__ */ import_react7.default.createElement("span", {
|
|
660
|
+
className: "sr-only"
|
|
661
|
+
}, children))), /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Tooltip.Portal, null, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Tooltip.Content, tooltipProps, children, /* @__PURE__ */ import_react7.default.createElement(import_react_ui5.Tooltip.Arrow, null))));
|
|
662
|
+
};
|
|
663
|
+
var [ToolbarContextProvider, useToolbarContext] = (0, import_react_context.createContext)("Toolbar");
|
|
664
|
+
var ToolbarRoot = ({ classNames, children, onAction }) => {
|
|
665
|
+
return /* @__PURE__ */ import_react6.default.createElement(ToolbarContextProvider, {
|
|
666
|
+
onAction
|
|
667
|
+
}, /* @__PURE__ */ import_react6.default.createElement(import_react_ui4.Toolbar.Root, {
|
|
668
|
+
classNames: [
|
|
669
|
+
"is-full shrink-0 overflow-x-auto overflow-y-hidden p-1 attention-surface",
|
|
670
|
+
classNames
|
|
671
|
+
]
|
|
672
|
+
}, children));
|
|
673
|
+
};
|
|
674
|
+
var Editing = () => {
|
|
675
|
+
const { onAction } = useToolbarContext("Editing");
|
|
676
|
+
const { t } = (0, import_react_ui4.useTranslation)(translationKey);
|
|
677
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement(ToolbarButton, {
|
|
678
|
+
value: "add-row",
|
|
679
|
+
icon: "ph--plus--regular",
|
|
680
|
+
"data-testid": "table.toolbar.add-row",
|
|
681
|
+
onClick: () => onAction?.({
|
|
682
|
+
type: "add-row"
|
|
683
|
+
})
|
|
684
|
+
}, t("add row")));
|
|
685
|
+
};
|
|
686
|
+
var Actions = () => {
|
|
687
|
+
const { onAction } = useToolbarContext("Actions");
|
|
688
|
+
const { t } = (0, import_react_ui4.useTranslation)(translationKey);
|
|
689
|
+
return /* @__PURE__ */ import_react6.default.createElement(import_react6.default.Fragment, null, /* @__PURE__ */ import_react6.default.createElement(ToolbarButton, {
|
|
690
|
+
value: "comment",
|
|
691
|
+
icon: "ph--chat-text--regular",
|
|
692
|
+
"data-testid": "table.toolbar.comment",
|
|
693
|
+
onClick: () => onAction?.({
|
|
694
|
+
type: "comment"
|
|
695
|
+
})
|
|
696
|
+
}, t("create comment")));
|
|
697
|
+
};
|
|
698
|
+
var Toolbar = {
|
|
699
|
+
Root: ToolbarRoot,
|
|
700
|
+
Editing,
|
|
701
|
+
Actions,
|
|
702
|
+
Separator: ToolbarSeparator
|
|
703
|
+
};
|
|
704
|
+
var ModalController = class {
|
|
705
|
+
constructor() {
|
|
706
|
+
this._state = (0, import_signals_core2.signal)({
|
|
707
|
+
type: "closed"
|
|
708
|
+
});
|
|
709
|
+
this._triggerRef = {
|
|
710
|
+
current: null
|
|
711
|
+
};
|
|
712
|
+
this.handleClick = (event) => {
|
|
713
|
+
const target = event.target;
|
|
714
|
+
const rowButton = target.closest(`button[${tableButtons.rowMenu.attr}]`);
|
|
715
|
+
if (rowButton) {
|
|
716
|
+
this._triggerRef.current = rowButton;
|
|
717
|
+
this._state.value = {
|
|
718
|
+
type: "row",
|
|
719
|
+
rowIndex: Number(rowButton.getAttribute(tableButtons.rowMenu.attr))
|
|
720
|
+
};
|
|
721
|
+
return true;
|
|
722
|
+
}
|
|
723
|
+
const columnButton = target.closest(`button[${tableButtons.columnSettings.attr}]`);
|
|
724
|
+
if (columnButton) {
|
|
725
|
+
const fieldId = columnButton.getAttribute(tableButtons.columnSettings.attr);
|
|
726
|
+
this._triggerRef.current = columnButton;
|
|
727
|
+
this._state.value = {
|
|
728
|
+
type: "column",
|
|
729
|
+
fieldId
|
|
730
|
+
};
|
|
731
|
+
return true;
|
|
732
|
+
}
|
|
733
|
+
const addColumnButton = target.closest(`button[${tableButtons.addColumn.attr}]`);
|
|
734
|
+
if (addColumnButton) {
|
|
735
|
+
this._triggerRef.current = addColumnButton;
|
|
736
|
+
this._state.value = {
|
|
737
|
+
type: "columnSettings",
|
|
738
|
+
mode: {
|
|
739
|
+
type: "create"
|
|
740
|
+
}
|
|
741
|
+
};
|
|
742
|
+
return true;
|
|
743
|
+
}
|
|
744
|
+
return false;
|
|
745
|
+
};
|
|
746
|
+
this.openColumnSettings = () => {
|
|
747
|
+
if (this._state.value.type === "column") {
|
|
748
|
+
const fieldId = this._state.value.fieldId;
|
|
749
|
+
requestAnimationFrame(() => {
|
|
750
|
+
this._state.value = {
|
|
751
|
+
type: "columnSettings",
|
|
752
|
+
mode: {
|
|
753
|
+
type: "edit",
|
|
754
|
+
fieldId
|
|
755
|
+
}
|
|
756
|
+
};
|
|
757
|
+
});
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
this.close = () => {
|
|
761
|
+
this._state.value = {
|
|
762
|
+
type: "closed"
|
|
763
|
+
};
|
|
764
|
+
};
|
|
765
|
+
}
|
|
766
|
+
get state() {
|
|
767
|
+
return this._state;
|
|
768
|
+
}
|
|
769
|
+
get trigger() {
|
|
770
|
+
return this._triggerRef;
|
|
771
|
+
}
|
|
772
|
+
};
|
|
773
|
+
var SelectionModel = class extends import_context2.Resource {
|
|
774
|
+
constructor(_rows, _onSelectionChanged) {
|
|
775
|
+
super();
|
|
776
|
+
this._rows = _rows;
|
|
777
|
+
this._onSelectionChanged = _onSelectionChanged;
|
|
778
|
+
this._selection = (0, import_signals_core3.signal)(/* @__PURE__ */ new Set());
|
|
779
|
+
this._validSelectedIds = (0, import_signals_core3.computed)(() => {
|
|
780
|
+
const rows = this._rows.value;
|
|
781
|
+
if (!rows) {
|
|
782
|
+
return /* @__PURE__ */ new Set();
|
|
783
|
+
}
|
|
784
|
+
const validIds = new Set(rows.map((row) => row.id));
|
|
785
|
+
return new Set([
|
|
786
|
+
...this._selection.value
|
|
787
|
+
].filter((id) => validIds.has(id)));
|
|
788
|
+
});
|
|
789
|
+
this._hasSelection = (0, import_signals_core3.computed)(() => this._validSelectedIds.value.size > 0);
|
|
790
|
+
this._allSelected = (0, import_signals_core3.computed)(() => {
|
|
791
|
+
const rows = this._rows.value;
|
|
792
|
+
if (rows.length === 0) {
|
|
793
|
+
return false;
|
|
794
|
+
}
|
|
795
|
+
return rows.every((row) => this._selection.value.has(row.id));
|
|
796
|
+
});
|
|
797
|
+
this.getSelectedRows = () => {
|
|
798
|
+
const selectedIds = this._validSelectedIds.value;
|
|
799
|
+
return this._rows.value.filter((row) => selectedIds.has(row.id));
|
|
800
|
+
};
|
|
801
|
+
this.isRowIndexSelected = (rowIndex) => {
|
|
802
|
+
const row = this._rows.value[rowIndex];
|
|
803
|
+
return this._selection.value.has(row.id);
|
|
804
|
+
};
|
|
805
|
+
this.isObjectSelected = (object) => {
|
|
806
|
+
return this._selection.value.has(object.id);
|
|
807
|
+
};
|
|
808
|
+
this.toggleSelectionForRowIndex = (rowIndex) => {
|
|
809
|
+
const row = this._rows.value[rowIndex];
|
|
810
|
+
const newSelection = new Set(this._selection.value);
|
|
811
|
+
if (newSelection.has(row.id)) {
|
|
812
|
+
newSelection.delete(row.id);
|
|
813
|
+
} else {
|
|
814
|
+
newSelection.add(row.id);
|
|
815
|
+
}
|
|
816
|
+
this._selection.value = newSelection;
|
|
817
|
+
};
|
|
818
|
+
this.setSelection = (mode) => {
|
|
819
|
+
this._selection.value = mode === "all" ? new Set(this._rows.value.map((row) => row.id)) : /* @__PURE__ */ new Set();
|
|
820
|
+
};
|
|
821
|
+
}
|
|
822
|
+
async _open() {
|
|
823
|
+
const selectionWatcher = (0, import_signals_core3.effect)(() => {
|
|
824
|
+
touch(this._selection.value);
|
|
825
|
+
this._onSelectionChanged?.();
|
|
826
|
+
});
|
|
827
|
+
this._ctx.onDispose(selectionWatcher);
|
|
828
|
+
}
|
|
829
|
+
//
|
|
830
|
+
// Getters
|
|
831
|
+
//
|
|
832
|
+
get selection() {
|
|
833
|
+
return this._selection;
|
|
834
|
+
}
|
|
835
|
+
get hasSelection() {
|
|
836
|
+
return this._hasSelection;
|
|
837
|
+
}
|
|
838
|
+
get allRowsSeleted() {
|
|
839
|
+
return this._allSelected;
|
|
840
|
+
}
|
|
841
|
+
};
|
|
842
|
+
var checkboxAttributes = {
|
|
843
|
+
checkbox: "data-table-checkbox",
|
|
844
|
+
header: "data-table-header"
|
|
845
|
+
};
|
|
846
|
+
var renderCheckbox = ({ rowIndex, header = false, checked = false, disabled = false }) => {
|
|
847
|
+
const baseClasses = "absolute inset-block-[6px] inline-end-[6px] ch-checkbox";
|
|
848
|
+
const { attributes } = tableControls.checkbox;
|
|
849
|
+
return `<input type="checkbox" class="${baseClasses}" ${attributes.checkbox}="${rowIndex}" ${header ? attributes.header : ""} ${checked ? "checked" : ""} ${disabled ? "disabled" : ""}/>`;
|
|
850
|
+
};
|
|
851
|
+
var tableControls = {
|
|
852
|
+
checkbox: {
|
|
853
|
+
attributes: checkboxAttributes,
|
|
854
|
+
render: renderCheckbox
|
|
855
|
+
}
|
|
856
|
+
};
|
|
857
|
+
var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-table/src/model/table-model.ts";
|
|
858
|
+
var TableModel = class extends import_context.Resource {
|
|
859
|
+
constructor({ table, projection, sorting = [], pinnedRows = {
|
|
860
|
+
top: [],
|
|
861
|
+
bottom: []
|
|
862
|
+
}, onCellUpdate, onDeleteColumn, onDeleteRows, onInsertRow, onRowOrderChanged }) {
|
|
863
|
+
super();
|
|
864
|
+
this.id = `table-model-${import_react_client2.PublicKey.random().truncate()}`;
|
|
865
|
+
this._visibleRange = (0, import_signals_core.signal)({
|
|
866
|
+
start: {
|
|
867
|
+
row: 0,
|
|
868
|
+
col: 0
|
|
869
|
+
},
|
|
870
|
+
end: {
|
|
871
|
+
row: 0,
|
|
872
|
+
col: 0
|
|
873
|
+
}
|
|
874
|
+
});
|
|
875
|
+
this._displayToDataIndex = /* @__PURE__ */ new Map();
|
|
876
|
+
this._sorting = (0, import_signals_core.signal)(void 0);
|
|
877
|
+
this._rows = (0, import_signals_core.signal)([]);
|
|
878
|
+
this._modalController = new ModalController();
|
|
879
|
+
this.getCells = (range, plane) => {
|
|
880
|
+
switch (plane) {
|
|
881
|
+
case "grid": {
|
|
882
|
+
this._visibleRange.value = range;
|
|
883
|
+
return this.getMainGridCells(range);
|
|
884
|
+
}
|
|
885
|
+
case "frozenRowsStart": {
|
|
886
|
+
return this.getHeaderCells(range);
|
|
887
|
+
}
|
|
888
|
+
case "frozenColsStart": {
|
|
889
|
+
return this.getSelectionColumnCells(range);
|
|
890
|
+
}
|
|
891
|
+
case "frozenColsEnd": {
|
|
892
|
+
return this.getActionColumnCells(range);
|
|
893
|
+
}
|
|
894
|
+
case "fixedStartStart": {
|
|
895
|
+
return this.getSelectAllCell();
|
|
896
|
+
}
|
|
897
|
+
case "fixedStartEnd": {
|
|
898
|
+
return this.getNewColumnCell();
|
|
899
|
+
}
|
|
900
|
+
default: {
|
|
901
|
+
return {};
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
};
|
|
905
|
+
this.getMainGridCells = (range) => {
|
|
906
|
+
const values = {};
|
|
907
|
+
const fields = this._table.view?.fields ?? [];
|
|
908
|
+
const addCell = (obj, field, colIndex, displayIndex) => {
|
|
909
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
910
|
+
const value = {
|
|
911
|
+
get value() {
|
|
912
|
+
const value2 = (0, import_echo_schema4.getValue)(obj, field.path);
|
|
913
|
+
if (value2 == null) {
|
|
914
|
+
return "";
|
|
915
|
+
}
|
|
916
|
+
switch (props.format) {
|
|
917
|
+
case import_echo_schema4.FormatEnum.Ref: {
|
|
918
|
+
if (!field.referencePath) {
|
|
919
|
+
return "";
|
|
920
|
+
}
|
|
921
|
+
return (0, import_echo_schema4.getValue)(value2, field.referencePath);
|
|
922
|
+
}
|
|
923
|
+
default: {
|
|
924
|
+
return (0, import_react_ui_form2.formatForDisplay)({
|
|
925
|
+
type: props.type,
|
|
926
|
+
format: props.format,
|
|
927
|
+
value: value2
|
|
928
|
+
});
|
|
929
|
+
}
|
|
930
|
+
}
|
|
931
|
+
}
|
|
932
|
+
};
|
|
933
|
+
const classes = [];
|
|
934
|
+
const formatClasses = (0, import_react_ui_form2.cellClassesForFieldType)({
|
|
935
|
+
type: props.type,
|
|
936
|
+
format: props.format
|
|
937
|
+
});
|
|
938
|
+
if (formatClasses) {
|
|
939
|
+
classes.push(formatClasses);
|
|
940
|
+
}
|
|
941
|
+
const rowSelectionClasses = (0, import_react_ui_form2.cellClassesForRowSelection)(this._selection.isObjectSelected(obj));
|
|
942
|
+
if (rowSelectionClasses) {
|
|
943
|
+
classes.push(rowSelectionClasses);
|
|
944
|
+
}
|
|
945
|
+
if (classes.length > 0) {
|
|
946
|
+
value.className = (0, import_react_ui_theme2.mx)(classes.flat());
|
|
947
|
+
}
|
|
948
|
+
const idx = fromGridCell({
|
|
949
|
+
col: colIndex,
|
|
950
|
+
row: displayIndex
|
|
951
|
+
});
|
|
952
|
+
values[idx] = value;
|
|
953
|
+
};
|
|
954
|
+
for (let row = range.start.row; row <= range.end.row && row < this._sortedRows.value.length; row++) {
|
|
955
|
+
for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
|
|
956
|
+
const field = fields[col];
|
|
957
|
+
if (!field) {
|
|
958
|
+
continue;
|
|
959
|
+
}
|
|
960
|
+
addCell(this._sortedRows.value[row], field, col, row);
|
|
961
|
+
}
|
|
962
|
+
}
|
|
963
|
+
return values;
|
|
964
|
+
};
|
|
965
|
+
this.getHeaderCells = (range) => {
|
|
966
|
+
const values = {};
|
|
967
|
+
const fields = this.table.view?.fields ?? [];
|
|
968
|
+
for (let col = range.start.col; col <= range.end.col && col < fields.length; col++) {
|
|
969
|
+
const { field, props } = this._projection.getFieldProjection(fields[col].id);
|
|
970
|
+
values[fromGridCell({
|
|
971
|
+
col,
|
|
972
|
+
row: 0
|
|
973
|
+
})] = {
|
|
974
|
+
value: props.title ?? field.path,
|
|
975
|
+
readonly: true,
|
|
976
|
+
resizeHandle: "col",
|
|
977
|
+
accessoryHtml: tableButtons.columnSettings.render({
|
|
978
|
+
fieldId: field.id
|
|
979
|
+
})
|
|
980
|
+
};
|
|
981
|
+
}
|
|
982
|
+
return values;
|
|
983
|
+
};
|
|
984
|
+
this.getSelectionColumnCells = (range) => {
|
|
985
|
+
const values = {};
|
|
986
|
+
for (let row = range.start.row; row <= range.end.row && row < this._rows.value.length; row++) {
|
|
987
|
+
const isSelected = this._selection.isRowIndexSelected(row);
|
|
988
|
+
const classes = (0, import_react_ui_form2.cellClassesForRowSelection)(isSelected);
|
|
989
|
+
values[fromGridCell({
|
|
990
|
+
col: 0,
|
|
991
|
+
row
|
|
992
|
+
})] = {
|
|
993
|
+
value: "",
|
|
994
|
+
readonly: true,
|
|
995
|
+
className: classes ? (0, import_react_ui_theme2.mx)(classes) : void 0,
|
|
996
|
+
accessoryHtml: tableControls.checkbox.render({
|
|
997
|
+
rowIndex: row,
|
|
998
|
+
checked: isSelected
|
|
999
|
+
})
|
|
1000
|
+
};
|
|
1001
|
+
}
|
|
1002
|
+
return values;
|
|
1003
|
+
};
|
|
1004
|
+
this.getActionColumnCells = (range) => {
|
|
1005
|
+
const values = {};
|
|
1006
|
+
for (let row = range.start.row; row <= range.end.row && row < this._rows.value.length; row++) {
|
|
1007
|
+
const isSelected = this._selection.isRowIndexSelected(row);
|
|
1008
|
+
const classes = (0, import_react_ui_form2.cellClassesForRowSelection)(isSelected);
|
|
1009
|
+
values[fromGridCell({
|
|
1010
|
+
col: 0,
|
|
1011
|
+
row
|
|
1012
|
+
})] = {
|
|
1013
|
+
value: "",
|
|
1014
|
+
readonly: true,
|
|
1015
|
+
className: classes ? (0, import_react_ui_theme2.mx)(classes) : void 0,
|
|
1016
|
+
accessoryHtml: tableButtons.rowMenu.render({
|
|
1017
|
+
rowIndex: row
|
|
1018
|
+
})
|
|
1019
|
+
};
|
|
1020
|
+
}
|
|
1021
|
+
return values;
|
|
1022
|
+
};
|
|
1023
|
+
this.getSelectAllCell = () => {
|
|
1024
|
+
return {
|
|
1025
|
+
[fromGridCell({
|
|
1026
|
+
col: 0,
|
|
1027
|
+
row: 0
|
|
1028
|
+
})]: {
|
|
1029
|
+
value: "",
|
|
1030
|
+
accessoryHtml: tableControls.checkbox.render({
|
|
1031
|
+
rowIndex: 0,
|
|
1032
|
+
header: true,
|
|
1033
|
+
checked: this._selection.allRowsSeleted.value
|
|
1034
|
+
}),
|
|
1035
|
+
readonly: true
|
|
1036
|
+
}
|
|
1037
|
+
};
|
|
1038
|
+
};
|
|
1039
|
+
this.getNewColumnCell = () => {
|
|
1040
|
+
return {
|
|
1041
|
+
[fromGridCell({
|
|
1042
|
+
col: 0,
|
|
1043
|
+
row: 0
|
|
1044
|
+
})]: {
|
|
1045
|
+
value: "",
|
|
1046
|
+
accessoryHtml: tableButtons.addColumn.render({
|
|
1047
|
+
disabled: (this._table.view?.fields?.length ?? 0) >= import_schema2.VIEW_FIELD_LIMIT
|
|
1048
|
+
}),
|
|
1049
|
+
readonly: true
|
|
1050
|
+
}
|
|
1051
|
+
};
|
|
1052
|
+
};
|
|
1053
|
+
this.setRows = (obj) => {
|
|
1054
|
+
this._rows.value = obj;
|
|
1055
|
+
};
|
|
1056
|
+
this.getRowCount = () => this._rows.value.length;
|
|
1057
|
+
this.getColumnCount = () => this.table.view?.fields.length ?? 0;
|
|
1058
|
+
this.insertRow = (rowIndex) => {
|
|
1059
|
+
const row = rowIndex !== void 0 ? this._displayToDataIndex.get(rowIndex) ?? rowIndex : this._rows.value.length;
|
|
1060
|
+
this._onInsertRow?.(row);
|
|
1061
|
+
};
|
|
1062
|
+
this.deleteRow = (rowIndex) => {
|
|
1063
|
+
const row = this._displayToDataIndex.get(rowIndex) ?? rowIndex;
|
|
1064
|
+
const obj = this._rows.value[row];
|
|
1065
|
+
const objectsToDelete = [];
|
|
1066
|
+
if (this._selection.hasSelection.value) {
|
|
1067
|
+
const selectedRows = this._selection.getSelectedRows();
|
|
1068
|
+
objectsToDelete.push(...selectedRows);
|
|
1069
|
+
} else {
|
|
1070
|
+
objectsToDelete.push(obj);
|
|
1071
|
+
}
|
|
1072
|
+
this._onDeleteRows?.(row, objectsToDelete);
|
|
1073
|
+
};
|
|
1074
|
+
this.getCellData = ({ col, row }) => {
|
|
1075
|
+
const fields = this.table.view?.fields ?? [];
|
|
1076
|
+
if (col < 0 || col >= fields.length) {
|
|
1077
|
+
return void 0;
|
|
1078
|
+
}
|
|
1079
|
+
const field = fields[col];
|
|
1080
|
+
const dataIndex = this._displayToDataIndex.get(row) ?? row;
|
|
1081
|
+
const value = (0, import_echo_schema4.getValue)(this._rows.value[dataIndex], field.path);
|
|
1082
|
+
if (value == null) {
|
|
1083
|
+
return "";
|
|
1084
|
+
}
|
|
1085
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
1086
|
+
switch (props.format) {
|
|
1087
|
+
case import_echo_schema4.FormatEnum.Ref: {
|
|
1088
|
+
if (!field.referencePath) {
|
|
1089
|
+
return "";
|
|
1090
|
+
}
|
|
1091
|
+
return (0, import_echo_schema4.getValue)(value, field.referencePath);
|
|
1092
|
+
}
|
|
1093
|
+
default: {
|
|
1094
|
+
return (0, import_react_ui_form2.formatForEditing)({
|
|
1095
|
+
type: props.type,
|
|
1096
|
+
format: props.format,
|
|
1097
|
+
value
|
|
1098
|
+
});
|
|
1099
|
+
}
|
|
1100
|
+
}
|
|
1101
|
+
};
|
|
1102
|
+
this.setCellData = ({ col, row }, value) => {
|
|
1103
|
+
const rowIdx = this._displayToDataIndex.get(row) ?? row;
|
|
1104
|
+
const fields = this.table.view?.fields ?? [];
|
|
1105
|
+
if (col < 0 || col >= fields.length) {
|
|
1106
|
+
return;
|
|
1107
|
+
}
|
|
1108
|
+
const field = fields[col];
|
|
1109
|
+
const { props } = this._projection.getFieldProjection(field.id);
|
|
1110
|
+
switch (props.format) {
|
|
1111
|
+
case import_echo_schema4.FormatEnum.Ref: {
|
|
1112
|
+
(0, import_echo_schema4.setValue)(this._rows.value[rowIdx], field.path, value);
|
|
1113
|
+
break;
|
|
1114
|
+
}
|
|
1115
|
+
default: {
|
|
1116
|
+
(0, import_echo_schema4.setValue)(this._rows.value[rowIdx], field.path, (0, import_react_ui_form2.parseValue)({
|
|
1117
|
+
type: props.type,
|
|
1118
|
+
format: props.format,
|
|
1119
|
+
value
|
|
1120
|
+
}));
|
|
1121
|
+
break;
|
|
1122
|
+
}
|
|
1123
|
+
}
|
|
1124
|
+
};
|
|
1125
|
+
this.handleGridClick = (event) => {
|
|
1126
|
+
if (!this._modalController.handleClick(event)) {
|
|
1127
|
+
const target = event.target;
|
|
1128
|
+
const selectionCheckbox = target.closest(`input[${tableControls.checkbox.attributes.checkbox}]`);
|
|
1129
|
+
if (selectionCheckbox) {
|
|
1130
|
+
const isHeader = selectionCheckbox.hasAttribute(tableControls.checkbox.attributes.header);
|
|
1131
|
+
if (isHeader) {
|
|
1132
|
+
if (this._selection.allRowsSeleted.value) {
|
|
1133
|
+
this._selection.setSelection("none");
|
|
1134
|
+
} else {
|
|
1135
|
+
this._selection.setSelection("all");
|
|
1136
|
+
}
|
|
1137
|
+
} else {
|
|
1138
|
+
const rowIndex = Number(selectionCheckbox.getAttribute(tableControls.checkbox.attributes.checkbox));
|
|
1139
|
+
this._selection.toggleSelectionForRowIndex(rowIndex);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
this._table = table;
|
|
1145
|
+
this._projection = projection;
|
|
1146
|
+
this._sorting.value = sorting.at(0);
|
|
1147
|
+
this._pinnedRows = pinnedRows;
|
|
1148
|
+
this._onInsertRow = onInsertRow;
|
|
1149
|
+
this._onDeleteRows = onDeleteRows;
|
|
1150
|
+
this._onDeleteColumn = onDeleteColumn;
|
|
1151
|
+
this._onCellUpdate = onCellUpdate;
|
|
1152
|
+
this._onRowOrderChanged = onRowOrderChanged;
|
|
1153
|
+
}
|
|
1154
|
+
get table() {
|
|
1155
|
+
return this._table;
|
|
1156
|
+
}
|
|
1157
|
+
get projection() {
|
|
1158
|
+
return this._projection;
|
|
1159
|
+
}
|
|
1160
|
+
get pinnedRows() {
|
|
1161
|
+
return this._pinnedRows;
|
|
1162
|
+
}
|
|
1163
|
+
get columnMeta() {
|
|
1164
|
+
(0, import_invariant3.invariant)(this._columnMeta, void 0, {
|
|
1165
|
+
F: __dxlog_file4,
|
|
1166
|
+
L: 124,
|
|
1167
|
+
S: this,
|
|
1168
|
+
A: [
|
|
1169
|
+
"this._columnMeta",
|
|
1170
|
+
""
|
|
1171
|
+
]
|
|
1172
|
+
});
|
|
1173
|
+
return this._columnMeta;
|
|
1174
|
+
}
|
|
1175
|
+
get sorting() {
|
|
1176
|
+
return this._sorting.value;
|
|
1177
|
+
}
|
|
1178
|
+
get modalController() {
|
|
1179
|
+
return this._modalController;
|
|
1180
|
+
}
|
|
1181
|
+
get selection() {
|
|
1182
|
+
return this._selection;
|
|
1183
|
+
}
|
|
1184
|
+
//
|
|
1185
|
+
// Initialisation
|
|
1186
|
+
//
|
|
1187
|
+
async _open() {
|
|
1188
|
+
this.initializeColumnMeta();
|
|
1189
|
+
this.initializeSorting();
|
|
1190
|
+
this.initializeEffects();
|
|
1191
|
+
this._selection = new SelectionModel(this._sortedRows, () => this._onRowOrderChanged?.());
|
|
1192
|
+
await this._selection.open(this._ctx);
|
|
1193
|
+
}
|
|
1194
|
+
initializeColumnMeta() {
|
|
1195
|
+
this._columnMeta = (0, import_signals_core.computed)(() => {
|
|
1196
|
+
const fields = this._table.view?.fields ?? [];
|
|
1197
|
+
const meta = Object.fromEntries(fields.map((field, index) => [
|
|
1198
|
+
index,
|
|
1199
|
+
{
|
|
1200
|
+
size: field?.size ?? 256,
|
|
1201
|
+
resizeable: true
|
|
1202
|
+
}
|
|
1203
|
+
]));
|
|
1204
|
+
return {
|
|
1205
|
+
grid: meta,
|
|
1206
|
+
frozenColsStart: {
|
|
1207
|
+
0: {
|
|
1208
|
+
size: 30,
|
|
1209
|
+
resizeable: false
|
|
1210
|
+
}
|
|
1211
|
+
},
|
|
1212
|
+
frozenColsEnd: {
|
|
1213
|
+
0: {
|
|
1214
|
+
size: 40,
|
|
1215
|
+
resizeable: false
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
};
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
initializeSorting() {
|
|
1222
|
+
this._sortedRows = (0, import_signals_core.computed)(() => {
|
|
1223
|
+
this._displayToDataIndex.clear();
|
|
1224
|
+
const sort = this._sorting.value;
|
|
1225
|
+
if (!sort) {
|
|
1226
|
+
return this._rows.value;
|
|
1227
|
+
}
|
|
1228
|
+
const field = this._table.view?.fields.find((field2) => field2.id === sort.fieldId);
|
|
1229
|
+
if (!field) {
|
|
1230
|
+
return this._rows.value;
|
|
1231
|
+
}
|
|
1232
|
+
const dataWithIndices = this._rows.value.map((item, index) => {
|
|
1233
|
+
const value = (0, import_echo_schema4.getValue)(item, field.path);
|
|
1234
|
+
return {
|
|
1235
|
+
item,
|
|
1236
|
+
index,
|
|
1237
|
+
value,
|
|
1238
|
+
isEmpty: value == null || value === ""
|
|
1239
|
+
};
|
|
1240
|
+
});
|
|
1241
|
+
const sorted = (0, import_lodash.default)(dataWithIndices, [
|
|
1242
|
+
"isEmpty",
|
|
1243
|
+
"value"
|
|
1244
|
+
], [
|
|
1245
|
+
"asc",
|
|
1246
|
+
sort.direction
|
|
1247
|
+
]);
|
|
1248
|
+
for (let displayIndex = 0; displayIndex < sorted.length; displayIndex++) {
|
|
1249
|
+
const { index: dataIndex } = sorted[displayIndex];
|
|
1250
|
+
if (displayIndex !== dataIndex) {
|
|
1251
|
+
this._displayToDataIndex.set(displayIndex, dataIndex);
|
|
1252
|
+
}
|
|
1253
|
+
}
|
|
1254
|
+
return sorted.map(({ item }) => item);
|
|
1255
|
+
});
|
|
1256
|
+
}
|
|
1257
|
+
initializeEffects() {
|
|
1258
|
+
const rowOrderWatcher = (0, import_signals_core.effect)(() => {
|
|
1259
|
+
touch(this._sortedRows.value);
|
|
1260
|
+
this._onRowOrderChanged?.();
|
|
1261
|
+
});
|
|
1262
|
+
this._ctx.onDispose(rowOrderWatcher);
|
|
1263
|
+
const rowEffectManager = (0, import_signals_core.effect)(() => {
|
|
1264
|
+
const { start, end } = touch(this._visibleRange.value);
|
|
1265
|
+
const rowEffects = [];
|
|
1266
|
+
for (let row = start.row; row <= end.row; row++) {
|
|
1267
|
+
rowEffects.push((0, import_signals_core.effect)(() => {
|
|
1268
|
+
const obj = this._sortedRows.value[row];
|
|
1269
|
+
this?._table?.view?.fields.forEach((field) => touch((0, import_echo_schema4.getValue)(obj, field.path)));
|
|
1270
|
+
this._onCellUpdate?.({
|
|
1271
|
+
row,
|
|
1272
|
+
col: start.col
|
|
1273
|
+
});
|
|
1274
|
+
}));
|
|
1275
|
+
}
|
|
1276
|
+
return () => rowEffects.forEach((cleanup) => cleanup());
|
|
1277
|
+
});
|
|
1278
|
+
this._ctx.onDispose(rowEffectManager);
|
|
1279
|
+
}
|
|
1280
|
+
//
|
|
1281
|
+
// Column Operations
|
|
1282
|
+
//
|
|
1283
|
+
deleteColumn(fieldId) {
|
|
1284
|
+
if (!this.table.view) {
|
|
1285
|
+
return;
|
|
1286
|
+
}
|
|
1287
|
+
const field = this.table.view.fields.find((field2) => field2.id === fieldId);
|
|
1288
|
+
if (field && this._onDeleteColumn) {
|
|
1289
|
+
if (this._sorting.value?.fieldId === fieldId) {
|
|
1290
|
+
this.clearSort();
|
|
1291
|
+
}
|
|
1292
|
+
this._onDeleteColumn(field.id);
|
|
1293
|
+
}
|
|
1294
|
+
}
|
|
1295
|
+
//
|
|
1296
|
+
// Resize
|
|
1297
|
+
//
|
|
1298
|
+
setColumnWidth(columnIndex, width) {
|
|
1299
|
+
const fields = this.table.view?.fields ?? [];
|
|
1300
|
+
if (columnIndex < fields.length) {
|
|
1301
|
+
const newWidth = Math.max(0, width);
|
|
1302
|
+
const field = fields[columnIndex];
|
|
1303
|
+
if (field) {
|
|
1304
|
+
field.size = newWidth;
|
|
1305
|
+
}
|
|
1306
|
+
}
|
|
1307
|
+
}
|
|
1308
|
+
//
|
|
1309
|
+
// Sorting
|
|
1310
|
+
//
|
|
1311
|
+
setSort(fieldId, direction) {
|
|
1312
|
+
this._sorting.value = {
|
|
1313
|
+
fieldId,
|
|
1314
|
+
direction
|
|
1315
|
+
};
|
|
1316
|
+
}
|
|
1317
|
+
clearSort() {
|
|
1318
|
+
this._sorting.value = void 0;
|
|
1319
|
+
}
|
|
1320
|
+
//
|
|
1321
|
+
// Pinning
|
|
1322
|
+
//
|
|
1323
|
+
// TODO(burdon): Change to setPinned(on/off).
|
|
1324
|
+
pinRow(rowIndex, side) {
|
|
1325
|
+
this._pinnedRows[side].push(rowIndex);
|
|
1326
|
+
}
|
|
1327
|
+
unpinRow(rowIndex) {
|
|
1328
|
+
this._pinnedRows.top = this._pinnedRows.top.filter((index) => index !== rowIndex);
|
|
1329
|
+
this._pinnedRows.bottom = this._pinnedRows.bottom.filter((index) => index !== rowIndex);
|
|
1330
|
+
}
|
|
1331
|
+
};
|
|
1332
|
+
var useTableModel = ({ objects, table, projection, ...props }) => {
|
|
1333
|
+
const [model, setModel] = (0, import_react8.useState)();
|
|
1334
|
+
(0, import_react8.useEffect)(() => {
|
|
1335
|
+
if (!table || !projection) {
|
|
1336
|
+
return;
|
|
1337
|
+
}
|
|
1338
|
+
let model2;
|
|
1339
|
+
const t = setTimeout(async () => {
|
|
1340
|
+
model2 = new TableModel({
|
|
1341
|
+
table,
|
|
1342
|
+
projection,
|
|
1343
|
+
...props
|
|
1344
|
+
});
|
|
1345
|
+
await model2.open();
|
|
1346
|
+
setModel(model2);
|
|
1347
|
+
});
|
|
1348
|
+
return () => {
|
|
1349
|
+
clearTimeout(t);
|
|
1350
|
+
void model2?.close();
|
|
1351
|
+
};
|
|
1352
|
+
}, [
|
|
1353
|
+
table,
|
|
1354
|
+
projection
|
|
1355
|
+
]);
|
|
1356
|
+
(0, import_react8.useEffect)(() => {
|
|
1357
|
+
if (objects) {
|
|
1358
|
+
model?.setRows(objects);
|
|
1359
|
+
}
|
|
1360
|
+
}, [
|
|
1361
|
+
model,
|
|
1362
|
+
objects
|
|
1363
|
+
]);
|
|
1364
|
+
return model;
|
|
1365
|
+
};
|
|
1366
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1367
|
+
0 && (module.exports = {
|
|
1368
|
+
Table,
|
|
1369
|
+
TableType,
|
|
1370
|
+
Toolbar,
|
|
1371
|
+
fromGridCell,
|
|
1372
|
+
initializeTable,
|
|
1373
|
+
tableButtons,
|
|
1374
|
+
toGridCell,
|
|
1375
|
+
touch,
|
|
1376
|
+
translations,
|
|
1377
|
+
useTableModel,
|
|
1378
|
+
useToolbarContext
|
|
1379
|
+
});
|
|
1380
|
+
//# sourceMappingURL=index.cjs.map
|