@macrostrat/data-sheet 3.0.4 → 3.1.0
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/CHANGELOG.md +15 -1
- package/dist/cell-renderer.cjs +162 -0
- package/dist/cell-renderer.cjs.map +1 -0
- package/dist/cell-renderer.d.ts +8 -0
- package/dist/cell-renderer.js +162 -0
- package/dist/cell-renderer.js.map +1 -0
- package/dist/core.cjs +32 -159
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +4 -9
- package/dist/core.js +33 -158
- package/dist/core.js.map +1 -1
- package/dist/data-sheet.css +9 -9
- package/dist/index.cjs +13 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +13 -7
- package/dist/index.js.map +1 -1
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +1 -1
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/provider.cjs +59 -339
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.d.ts +11 -65
- package/dist/provider.js +58 -339
- package/dist/provider.js.map +1 -1
- package/dist/types.d.ts +54 -0
- package/dist/utils/key-handling.cjs +26 -1
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +3 -2
- package/dist/utils/key-handling.js +27 -2
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/zustand-store.cjs +320 -0
- package/dist/zustand-store.cjs.map +1 -0
- package/dist/zustand-store.d.ts +6 -0
- package/dist/zustand-store.js +318 -0
- package/dist/zustand-store.js.map +1 -0
- package/package.json +5 -4
- package/src/cell-renderer.ts +217 -0
- package/src/core.ts +52 -212
- package/src/index.ts +3 -0
- package/src/postgrest-table/index.ts +1 -1
- package/src/provider.ts +66 -486
- package/src/types.ts +66 -0
- package/src/utils/key-handling.ts +31 -5
- package/src/zustand-store.ts +377 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## [3.1.0] - 2026-04-10 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/data-sheet-v3.0.4...@macrostrat/data-sheet-v3.1.0)
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- New state model using Jotai scoped atoms to manage data sheet state
|
|
8
|
+
[b5119a4b](https://github.com/UW-Macrostrat/web-components/commit/b5119a4b7775286461ae67dff9f04000068810d3)
|
|
9
|
+
Removed `zustand-computed` dependency Improved lazy-loading examples
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- Updated dependencies
|
|
14
|
+
[b5119a4b](https://github.com/UW-Macrostrat/web-components/commit/b5119a4b7775286461ae67dff9f04000068810d3)
|
|
15
|
+
- @macrostrat/data-components@1.1.6
|
|
16
|
+
|
|
3
17
|
## [3.0.4] - 2026-04-05 [_changes_](https://github.com/UW-Macrostrat/web-components/compare/@macrostrat/data-sheet-v3.0.3...@macrostrat/data-sheet-v3.0.4)
|
|
4
18
|
|
|
5
19
|
### Patch Changes
|
|
@@ -7,7 +21,7 @@
|
|
|
7
21
|
- General performance improvements for rendering and infinite scrolling
|
|
8
22
|
- Use `PopoverNext` instead of popover
|
|
9
23
|
[4bd24d9f](https://github.com/UW-Macrostrat/web-components/commit/4bd24d9f65dacfdbbede3613921182858ec1e3d1)
|
|
10
|
-
|
|
24
|
+
- Re-enable column reordering
|
|
11
25
|
- Updated `@macrostrat/hyper` dependency
|
|
12
26
|
[6e9a6654](https://github.com/UW-Macrostrat/web-components/commit/6e9a665456460b31c30316a2a13d41abed94c43a)
|
|
13
27
|
- Updated dependencies
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const main_module = require("./main.module.sass.cjs");
|
|
4
|
+
const zustandStore = require("./zustand-store.cjs");
|
|
5
|
+
const table = require("@blueprintjs/table");
|
|
6
|
+
const provider = require("./provider.cjs");
|
|
7
|
+
const editorPopup = require("./components/editor-popup.cjs");
|
|
8
|
+
const keyHandling = require("./utils/key-handling.cjs");
|
|
9
|
+
function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEditor = true) {
|
|
10
|
+
const data = state.data;
|
|
11
|
+
const updatedData = state.updatedData;
|
|
12
|
+
const isDeleted = state.deletedRows.has(rowIndex);
|
|
13
|
+
const row = data[rowIndex] ?? updatedData[rowIndex];
|
|
14
|
+
const loading = row == null;
|
|
15
|
+
const col = columnSpec;
|
|
16
|
+
const _topLeftCell = state.topLeftCell;
|
|
17
|
+
const onCellEdited = state.onCellEdited;
|
|
18
|
+
const value = updatedData[rowIndex]?.[col.key] ?? data[rowIndex]?.[col.key];
|
|
19
|
+
const _renderedValue = col.valueRenderer?.(value) ?? value;
|
|
20
|
+
let style = col.style ?? {};
|
|
21
|
+
if (isDeleted) {
|
|
22
|
+
style = {
|
|
23
|
+
...style,
|
|
24
|
+
opacity: 0.5,
|
|
25
|
+
textDecoration: "line-through"
|
|
26
|
+
};
|
|
27
|
+
}
|
|
28
|
+
const editable = (col.editable ?? state.editable) && !isDeleted;
|
|
29
|
+
const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
|
|
30
|
+
if (!editable && state.editable) {
|
|
31
|
+
style.color = "var(--secondary-color)";
|
|
32
|
+
}
|
|
33
|
+
const edited = updatedData[rowIndex]?.[col.key] != null;
|
|
34
|
+
let intent = edited ? "success" : void 0;
|
|
35
|
+
if (isDeleted) {
|
|
36
|
+
intent = "danger";
|
|
37
|
+
}
|
|
38
|
+
const _Cell = col.cellComponent ?? BaseCell;
|
|
39
|
+
let inlineEditor = editable ? col.inlineEditor ?? true : false;
|
|
40
|
+
if (!topLeft) {
|
|
41
|
+
return main_module.default(
|
|
42
|
+
_Cell,
|
|
43
|
+
{
|
|
44
|
+
intent,
|
|
45
|
+
loading,
|
|
46
|
+
value,
|
|
47
|
+
style,
|
|
48
|
+
isDeleted
|
|
49
|
+
},
|
|
50
|
+
_renderedValue
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
let hiddenInput = main_module.default(EditorInput, {
|
|
54
|
+
className: "hidden-input",
|
|
55
|
+
autoFocus: true
|
|
56
|
+
});
|
|
57
|
+
let cellContents = _renderedValue;
|
|
58
|
+
let _dataEditor = null;
|
|
59
|
+
let className = null;
|
|
60
|
+
if (col.dataEditor != null) {
|
|
61
|
+
_dataEditor = main_module.default(
|
|
62
|
+
editorPopup.EditorPopup,
|
|
63
|
+
{
|
|
64
|
+
autoFocus: autoFocusEditor,
|
|
65
|
+
valueViewer: _renderedValue
|
|
66
|
+
},
|
|
67
|
+
[
|
|
68
|
+
main_module.default(col.dataEditor, {
|
|
69
|
+
value,
|
|
70
|
+
editable,
|
|
71
|
+
onChange(value2) {
|
|
72
|
+
if (!editable) return;
|
|
73
|
+
state.onSelectionEdited(value2);
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
]
|
|
77
|
+
);
|
|
78
|
+
}
|
|
79
|
+
if (!editable) {
|
|
80
|
+
if (_dataEditor != null) {
|
|
81
|
+
cellContents = _dataEditor;
|
|
82
|
+
}
|
|
83
|
+
return main_module.default(
|
|
84
|
+
_Cell,
|
|
85
|
+
{
|
|
86
|
+
intent,
|
|
87
|
+
value,
|
|
88
|
+
style
|
|
89
|
+
},
|
|
90
|
+
cellContents
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
const onChange = (e) => {
|
|
94
|
+
if (!editable) return;
|
|
95
|
+
if (value === e.target.value) return;
|
|
96
|
+
onCellEdited(rowIndex, col.key, e.target.value);
|
|
97
|
+
};
|
|
98
|
+
const isSingleCellSelection = zustandStore.singleFocusedCell(state.selection) != null;
|
|
99
|
+
let _inlineEditor = null;
|
|
100
|
+
if (typeof inlineEditor == "boolean") {
|
|
101
|
+
let _value = value;
|
|
102
|
+
if (typeof _renderedValue === "string" || typeof _renderedValue === "number" || _renderedValue == null) {
|
|
103
|
+
_value = _renderedValue;
|
|
104
|
+
}
|
|
105
|
+
_inlineEditor = main_module.default(EditorInput, {
|
|
106
|
+
className: "main-editor",
|
|
107
|
+
value: _value ?? "",
|
|
108
|
+
autoFocus: autoFocusEditor,
|
|
109
|
+
onChange
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
_inlineEditor = inlineEditor;
|
|
113
|
+
}
|
|
114
|
+
if (_dataEditor != null) {
|
|
115
|
+
className = "editor-cell";
|
|
116
|
+
cellContents = _dataEditor;
|
|
117
|
+
hiddenInput = null;
|
|
118
|
+
} else if (_inlineEditor != null) {
|
|
119
|
+
cellContents = _inlineEditor;
|
|
120
|
+
className = "input-cell";
|
|
121
|
+
hiddenInput = null;
|
|
122
|
+
}
|
|
123
|
+
return main_module.default(
|
|
124
|
+
_Cell,
|
|
125
|
+
{
|
|
126
|
+
intent,
|
|
127
|
+
value,
|
|
128
|
+
className,
|
|
129
|
+
style
|
|
130
|
+
//truncated: false,
|
|
131
|
+
},
|
|
132
|
+
[
|
|
133
|
+
cellContents,
|
|
134
|
+
main_module.default.if(editable && isSingleCellSelection)(DragHandle),
|
|
135
|
+
hiddenInput
|
|
136
|
+
]
|
|
137
|
+
);
|
|
138
|
+
}
|
|
139
|
+
function EditorInput(props) {
|
|
140
|
+
const onKeyDown = provider.useAtomValue(keyHandling.editorKeyHandlerAtom);
|
|
141
|
+
return main_module.default("input", {
|
|
142
|
+
onKeyDown,
|
|
143
|
+
...props
|
|
144
|
+
});
|
|
145
|
+
}
|
|
146
|
+
function DragHandle() {
|
|
147
|
+
const onMouseDown = provider.useSelector((state) => state.onDragValue);
|
|
148
|
+
return main_module.default("div.corner-drag-handle", { onMouseDown });
|
|
149
|
+
}
|
|
150
|
+
function BaseCell({ children, value, ...rest }) {
|
|
151
|
+
return main_module.default(
|
|
152
|
+
table.Cell,
|
|
153
|
+
{
|
|
154
|
+
interactive: true,
|
|
155
|
+
...rest
|
|
156
|
+
},
|
|
157
|
+
children
|
|
158
|
+
);
|
|
159
|
+
}
|
|
160
|
+
exports.BaseCell = BaseCell;
|
|
161
|
+
exports.basicCellRenderer = basicCellRenderer;
|
|
162
|
+
//# sourceMappingURL=cell-renderer.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell-renderer.cjs","sources":["../src/cell-renderer.ts"],"sourcesContent":["import { ColumnSpec, editorKeyHandlerAtom } from \"./utils\";\nimport { DataSheetStore } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode } from \"react\";\nimport { EditorPopup } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { useAtomValue, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n autoFocusEditor = true,\n): any {\n const data = state.data;\n const updatedData = state.updatedData;\n\n const isDeleted = state.deletedRows.has(rowIndex);\n\n const row = data[rowIndex] ?? updatedData[rowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value = updatedData[rowIndex]?.[col.key] ?? data[rowIndex]?.[col.key];\n const _renderedValue = col.valueRenderer?.(value) ?? value;\n\n let style = col.style ?? {};\n if (isDeleted) {\n style = {\n ...style,\n opacity: 0.5,\n textDecoration: \"line-through\",\n };\n }\n\n //const focused =\n // focusedCell?.col === colIndex && focusedCell?.row === rowIndex;\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // Top left cell of a ranged selection\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n if (!editable && state.editable) {\n // If the cell is not editable but the sheet is editable, we want to differentiate\n // between editable and non-editable cells.\n style.color = \"var(--secondary-color)\";\n }\n\n const edited = updatedData[rowIndex]?.[col.key] != null;\n let intent = edited ? \"success\" : undefined;\n if (isDeleted) {\n intent = \"danger\";\n }\n\n const _Cell = col.cellComponent ?? BaseCell;\n\n let inlineEditor = editable ? (col.inlineEditor ?? true) : false;\n\n if (!topLeft) {\n // This should be the case for every cell except the focused one\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n isDeleted,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Hidden input to capture key events\n let hiddenInput = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (col.dataEditor != null) {\n _dataEditor = h(\n EditorPopup,\n {\n autoFocus: autoFocusEditor,\n valueViewer: _renderedValue,\n },\n [\n h(col.dataEditor, {\n value,\n editable,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n // Most cells are not focused and don't need to be editable.\n // This will be the rendering logic for almost all cells\n\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n },\n cellContents,\n );\n // Could probably put the hidden input elsewhere,\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (value === e.target.value) return;\n onCellEdited(rowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: autoFocusEditor,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const onKeyDown = useAtomValue(editorKeyHandlerAtom);\n return h(\"input\", {\n onKeyDown,\n ...props,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n\nexport function BaseCell({ children, value, ...rest }) {\n return h(\n Cell,\n {\n interactive: true,\n ...rest,\n },\n children,\n );\n}\n"],"names":["h","EditorPopup","value","singleFocusedCell","useAtomValue","editorKeyHandlerAtom","useSelector","Cell"],"mappings":";;;;;;;;AASO,SAAS,kBACd,UACA,UACA,YACA,OACA,kBAAkB,MACb;AACL,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,YAAY,IAAI,QAAQ;AAEhD,QAAM,MAAM,KAAK,QAAQ,KAAK,YAAY,QAAQ;AAClD,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QAAQ,YAAY,QAAQ,IAAI,IAAI,GAAG,KAAK,KAAK,QAAQ,IAAI,IAAI,GAAG;AAC1E,QAAM,iBAAiB,IAAI,gBAAgB,KAAK,KAAK;AAErD,MAAI,QAAQ,IAAI,SAAS,CAAA;AACzB,MAAI,WAAW;AACb,YAAQ;AAAA,MACN,GAAG;AAAA,MACH,SAAS;AAAA,MACT,gBAAgB;AAAA,IAAA;AAAA,EAEpB;AAKA,QAAM,YAAY,IAAI,YAAY,MAAM,aAAa,CAAC;AAGtD,QAAM,UACJ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ACE,aAAa;AAAA,MACb,GAAG;AAAA,IAAA;AAAA,IAEL;AAAA,EAAA;AAEJ;;;"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { ColumnSpec } from './utils';
|
|
2
|
+
import { DataSheetStore } from './types.ts';
|
|
3
|
+
export declare function basicCellRenderer<T>(rowIndex: number, colIndex: number, columnSpec: ColumnSpec, state: DataSheetStore<T>, autoFocusEditor?: boolean): any;
|
|
4
|
+
export declare function BaseCell({ children, value, ...rest }: {
|
|
5
|
+
[x: string]: any;
|
|
6
|
+
children: any;
|
|
7
|
+
value: any;
|
|
8
|
+
}): import('react').DetailedReactHTMLElement<import('react').InputHTMLAttributes<HTMLInputElement>, HTMLInputElement>;
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
import h from "./main.module.sass.js";
|
|
2
|
+
import { singleFocusedCell } from "./zustand-store.js";
|
|
3
|
+
import { Cell } from "@blueprintjs/table";
|
|
4
|
+
import { useAtomValue, useSelector } from "./provider.js";
|
|
5
|
+
import { EditorPopup } from "./components/editor-popup.js";
|
|
6
|
+
import { editorKeyHandlerAtom } from "./utils/key-handling.js";
|
|
7
|
+
function basicCellRenderer(rowIndex, colIndex, columnSpec, state, autoFocusEditor = true) {
|
|
8
|
+
const data = state.data;
|
|
9
|
+
const updatedData = state.updatedData;
|
|
10
|
+
const isDeleted = state.deletedRows.has(rowIndex);
|
|
11
|
+
const row = data[rowIndex] ?? updatedData[rowIndex];
|
|
12
|
+
const loading = row == null;
|
|
13
|
+
const col = columnSpec;
|
|
14
|
+
const _topLeftCell = state.topLeftCell;
|
|
15
|
+
const onCellEdited = state.onCellEdited;
|
|
16
|
+
const value = updatedData[rowIndex]?.[col.key] ?? data[rowIndex]?.[col.key];
|
|
17
|
+
const _renderedValue = col.valueRenderer?.(value) ?? value;
|
|
18
|
+
let style = col.style ?? {};
|
|
19
|
+
if (isDeleted) {
|
|
20
|
+
style = {
|
|
21
|
+
...style,
|
|
22
|
+
opacity: 0.5,
|
|
23
|
+
textDecoration: "line-through"
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
const editable = (col.editable ?? state.editable) && !isDeleted;
|
|
27
|
+
const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
|
|
28
|
+
if (!editable && state.editable) {
|
|
29
|
+
style.color = "var(--secondary-color)";
|
|
30
|
+
}
|
|
31
|
+
const edited = updatedData[rowIndex]?.[col.key] != null;
|
|
32
|
+
let intent = edited ? "success" : void 0;
|
|
33
|
+
if (isDeleted) {
|
|
34
|
+
intent = "danger";
|
|
35
|
+
}
|
|
36
|
+
const _Cell = col.cellComponent ?? BaseCell;
|
|
37
|
+
let inlineEditor = editable ? col.inlineEditor ?? true : false;
|
|
38
|
+
if (!topLeft) {
|
|
39
|
+
return h(
|
|
40
|
+
_Cell,
|
|
41
|
+
{
|
|
42
|
+
intent,
|
|
43
|
+
loading,
|
|
44
|
+
value,
|
|
45
|
+
style,
|
|
46
|
+
isDeleted
|
|
47
|
+
},
|
|
48
|
+
_renderedValue
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
let hiddenInput = h(EditorInput, {
|
|
52
|
+
className: "hidden-input",
|
|
53
|
+
autoFocus: true
|
|
54
|
+
});
|
|
55
|
+
let cellContents = _renderedValue;
|
|
56
|
+
let _dataEditor = null;
|
|
57
|
+
let className = null;
|
|
58
|
+
if (col.dataEditor != null) {
|
|
59
|
+
_dataEditor = h(
|
|
60
|
+
EditorPopup,
|
|
61
|
+
{
|
|
62
|
+
autoFocus: autoFocusEditor,
|
|
63
|
+
valueViewer: _renderedValue
|
|
64
|
+
},
|
|
65
|
+
[
|
|
66
|
+
h(col.dataEditor, {
|
|
67
|
+
value,
|
|
68
|
+
editable,
|
|
69
|
+
onChange(value2) {
|
|
70
|
+
if (!editable) return;
|
|
71
|
+
state.onSelectionEdited(value2);
|
|
72
|
+
}
|
|
73
|
+
})
|
|
74
|
+
]
|
|
75
|
+
);
|
|
76
|
+
}
|
|
77
|
+
if (!editable) {
|
|
78
|
+
if (_dataEditor != null) {
|
|
79
|
+
cellContents = _dataEditor;
|
|
80
|
+
}
|
|
81
|
+
return h(
|
|
82
|
+
_Cell,
|
|
83
|
+
{
|
|
84
|
+
intent,
|
|
85
|
+
value,
|
|
86
|
+
style
|
|
87
|
+
},
|
|
88
|
+
cellContents
|
|
89
|
+
);
|
|
90
|
+
}
|
|
91
|
+
const onChange = (e) => {
|
|
92
|
+
if (!editable) return;
|
|
93
|
+
if (value === e.target.value) return;
|
|
94
|
+
onCellEdited(rowIndex, col.key, e.target.value);
|
|
95
|
+
};
|
|
96
|
+
const isSingleCellSelection = singleFocusedCell(state.selection) != null;
|
|
97
|
+
let _inlineEditor = null;
|
|
98
|
+
if (typeof inlineEditor == "boolean") {
|
|
99
|
+
let _value = value;
|
|
100
|
+
if (typeof _renderedValue === "string" || typeof _renderedValue === "number" || _renderedValue == null) {
|
|
101
|
+
_value = _renderedValue;
|
|
102
|
+
}
|
|
103
|
+
_inlineEditor = h(EditorInput, {
|
|
104
|
+
className: "main-editor",
|
|
105
|
+
value: _value ?? "",
|
|
106
|
+
autoFocus: autoFocusEditor,
|
|
107
|
+
onChange
|
|
108
|
+
});
|
|
109
|
+
} else {
|
|
110
|
+
_inlineEditor = inlineEditor;
|
|
111
|
+
}
|
|
112
|
+
if (_dataEditor != null) {
|
|
113
|
+
className = "editor-cell";
|
|
114
|
+
cellContents = _dataEditor;
|
|
115
|
+
hiddenInput = null;
|
|
116
|
+
} else if (_inlineEditor != null) {
|
|
117
|
+
cellContents = _inlineEditor;
|
|
118
|
+
className = "input-cell";
|
|
119
|
+
hiddenInput = null;
|
|
120
|
+
}
|
|
121
|
+
return h(
|
|
122
|
+
_Cell,
|
|
123
|
+
{
|
|
124
|
+
intent,
|
|
125
|
+
value,
|
|
126
|
+
className,
|
|
127
|
+
style
|
|
128
|
+
//truncated: false,
|
|
129
|
+
},
|
|
130
|
+
[
|
|
131
|
+
cellContents,
|
|
132
|
+
h.if(editable && isSingleCellSelection)(DragHandle),
|
|
133
|
+
hiddenInput
|
|
134
|
+
]
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
function EditorInput(props) {
|
|
138
|
+
const onKeyDown = useAtomValue(editorKeyHandlerAtom);
|
|
139
|
+
return h("input", {
|
|
140
|
+
onKeyDown,
|
|
141
|
+
...props
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
function DragHandle() {
|
|
145
|
+
const onMouseDown = useSelector((state) => state.onDragValue);
|
|
146
|
+
return h("div.corner-drag-handle", { onMouseDown });
|
|
147
|
+
}
|
|
148
|
+
function BaseCell({ children, value, ...rest }) {
|
|
149
|
+
return h(
|
|
150
|
+
Cell,
|
|
151
|
+
{
|
|
152
|
+
interactive: true,
|
|
153
|
+
...rest
|
|
154
|
+
},
|
|
155
|
+
children
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
export {
|
|
159
|
+
BaseCell,
|
|
160
|
+
basicCellRenderer
|
|
161
|
+
};
|
|
162
|
+
//# sourceMappingURL=cell-renderer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cell-renderer.js","sources":["../src/cell-renderer.ts"],"sourcesContent":["import { ColumnSpec, editorKeyHandlerAtom } from \"./utils\";\nimport { DataSheetStore } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode } from \"react\";\nimport { EditorPopup } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { useAtomValue, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n autoFocusEditor = true,\n): any {\n const data = state.data;\n const updatedData = state.updatedData;\n\n const isDeleted = state.deletedRows.has(rowIndex);\n\n const row = data[rowIndex] ?? updatedData[rowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value = updatedData[rowIndex]?.[col.key] ?? data[rowIndex]?.[col.key];\n const _renderedValue = col.valueRenderer?.(value) ?? value;\n\n let style = col.style ?? {};\n if (isDeleted) {\n style = {\n ...style,\n opacity: 0.5,\n textDecoration: \"line-through\",\n };\n }\n\n //const focused =\n // focusedCell?.col === colIndex && focusedCell?.row === rowIndex;\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // Top left cell of a ranged selection\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n if (!editable && state.editable) {\n // If the cell is not editable but the sheet is editable, we want to differentiate\n // between editable and non-editable cells.\n style.color = \"var(--secondary-color)\";\n }\n\n const edited = updatedData[rowIndex]?.[col.key] != null;\n let intent = edited ? \"success\" : undefined;\n if (isDeleted) {\n intent = \"danger\";\n }\n\n const _Cell = col.cellComponent ?? BaseCell;\n\n let inlineEditor = editable ? (col.inlineEditor ?? true) : false;\n\n if (!topLeft) {\n // This should be the case for every cell except the focused one\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n isDeleted,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Hidden input to capture key events\n let hiddenInput = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (col.dataEditor != null) {\n _dataEditor = h(\n EditorPopup,\n {\n autoFocus: autoFocusEditor,\n valueViewer: _renderedValue,\n },\n [\n h(col.dataEditor, {\n value,\n editable,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n // Most cells are not focused and don't need to be editable.\n // This will be the rendering logic for almost all cells\n\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n },\n cellContents,\n );\n // Could probably put the hidden input elsewhere,\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (value === e.target.value) return;\n onCellEdited(rowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: autoFocusEditor,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const onKeyDown = useAtomValue(editorKeyHandlerAtom);\n return h(\"input\", {\n onKeyDown,\n ...props,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n\nexport function BaseCell({ children, value, ...rest }) {\n return h(\n Cell,\n {\n interactive: true,\n ...rest,\n },\n children,\n );\n}\n"],"names":["value"],"mappings":";;;;;;AASO,SAAS,kBACd,UACA,UACA,YACA,OACA,kBAAkB,MACb;AACL,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,YAAY,IAAI,QAAQ;AAEhD,QAAM,MAAM,KAAK,QAAQ,KAAK,YAAY,QAAQ;AAClD,QA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AAY,aAAa,oBAAoB;AACnD,SAAO,EAAE,SAAS;AAAA,IAChB;AAAA,IACA,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAc,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAO,EAAE,0BAA0B,EAAE,aAAa;AACpD;AAEO,SAAS,SAAS,EAAE,UAAU,OAAO,GAAG,QAAQ;AACrD,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,aAAa;AAAA,MACb,GAAG;AAAA,IAAA;AAAA,IAEL;AAAA,EAAA;AAEJ;"}
|
package/dist/core.cjs
CHANGED
|
@@ -7,8 +7,10 @@ const update = require("immutability-helper");
|
|
|
7
7
|
const react = require("react");
|
|
8
8
|
const main_module = require("./main.module.sass.cjs");
|
|
9
9
|
const provider = require("./provider.cjs");
|
|
10
|
+
const cellRenderer = require("./cell-renderer.cjs");
|
|
10
11
|
const actions = require("./components/actions.cjs");
|
|
11
|
-
const
|
|
12
|
+
const keyHandling = require("./utils/key-handling.cjs");
|
|
13
|
+
const jotai = require("jotai");
|
|
12
14
|
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
13
15
|
const update__default = /* @__PURE__ */ _interopDefault(update);
|
|
14
16
|
var DataSheetDensity = /* @__PURE__ */ ((DataSheetDensity2) => {
|
|
@@ -56,7 +58,6 @@ const deletedRowHeaderStyle = {
|
|
|
56
58
|
};
|
|
57
59
|
function _DataSheet({
|
|
58
60
|
onVisibleCellsChange,
|
|
59
|
-
enableColumnReordering,
|
|
60
61
|
onSaveData,
|
|
61
62
|
onUpdateData,
|
|
62
63
|
onDeleteRows,
|
|
@@ -64,8 +65,9 @@ function _DataSheet({
|
|
|
64
65
|
dataSheetActions = null,
|
|
65
66
|
enableFocusedCell,
|
|
66
67
|
autoFocusEditor = true,
|
|
67
|
-
density = "high"
|
|
68
|
-
|
|
68
|
+
density = "high",
|
|
69
|
+
selectionModes,
|
|
70
|
+
...rest
|
|
69
71
|
}) {
|
|
70
72
|
const selectedRegions = provider.useSelector((state) => state.selection);
|
|
71
73
|
const data = provider.useSelector((state) => state.data);
|
|
@@ -121,7 +123,7 @@ function _DataSheet({
|
|
|
121
123
|
() => getRowsToDelete(selectedRegions).length,
|
|
122
124
|
[selectedRegions]
|
|
123
125
|
);
|
|
124
|
-
const columnWidths = provider.
|
|
126
|
+
const columnWidths = provider.useAtomValue(columnWidthsAtom);
|
|
125
127
|
const numRows = Math.max(updatedData.length, data.length);
|
|
126
128
|
let className = `${density}-density`;
|
|
127
129
|
let rowHeight = 20;
|
|
@@ -149,7 +151,7 @@ function _DataSheet({
|
|
|
149
151
|
name: col.name,
|
|
150
152
|
cellRenderer: (rowIndex) => {
|
|
151
153
|
const state = storeAPI.getState();
|
|
152
|
-
return basicCellRenderer(
|
|
154
|
+
return cellRenderer.basicCellRenderer(
|
|
153
155
|
rowIndex,
|
|
154
156
|
colIndex,
|
|
155
157
|
col,
|
|
@@ -175,7 +177,11 @@ function _DataSheet({
|
|
|
175
177
|
},
|
|
176
178
|
[deletedRows]
|
|
177
179
|
);
|
|
178
|
-
const onKeyDown = provider.
|
|
180
|
+
const onKeyDown = provider.useAtomValue(keyHandling.tableKeyHandlerAtom);
|
|
181
|
+
let _selectionModes = selectionModes;
|
|
182
|
+
if (editable && _selectionModes != null && !_selectionModes.includes(table.RegionCardinality.CELLS)) {
|
|
183
|
+
_selectionModes = [..._selectionModes, table.RegionCardinality.CELLS];
|
|
184
|
+
}
|
|
179
185
|
return main_module.default("div.data-sheet-container", { className, style }, [
|
|
180
186
|
main_module.default.if(editable)(DataSheetEditToolbar, {
|
|
181
187
|
onSaveData: _onSaveData,
|
|
@@ -192,7 +198,6 @@ function _DataSheet({
|
|
|
192
198
|
numRows,
|
|
193
199
|
className: "data-sheet",
|
|
194
200
|
enableFocusedCell,
|
|
195
|
-
enableColumnReordering,
|
|
196
201
|
onColumnsReordered,
|
|
197
202
|
focusedCell,
|
|
198
203
|
selectedRegions,
|
|
@@ -201,7 +206,6 @@ function _DataSheet({
|
|
|
201
206
|
columnWidths,
|
|
202
207
|
onColumnWidthChanged,
|
|
203
208
|
onSelection,
|
|
204
|
-
renderMode: "batch",
|
|
205
209
|
enableRowReordering: false,
|
|
206
210
|
enableRowResizing: false,
|
|
207
211
|
// The cell renderer is memoized internally based on these data dependencies
|
|
@@ -213,151 +217,35 @@ function _DataSheet({
|
|
|
213
217
|
deletedRows
|
|
214
218
|
],
|
|
215
219
|
onVisibleCellsChange: _onVisibleCellsChange,
|
|
216
|
-
rowHeaderCellRenderer
|
|
220
|
+
rowHeaderCellRenderer,
|
|
221
|
+
selectionModes: _selectionModes,
|
|
222
|
+
...rest
|
|
217
223
|
},
|
|
218
224
|
children
|
|
219
225
|
)
|
|
220
226
|
)
|
|
221
227
|
]);
|
|
222
228
|
}
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
const
|
|
227
|
-
const
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
...style,
|
|
238
|
-
opacity: 0.5,
|
|
239
|
-
textDecoration: "line-through"
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
const editable = (col.editable ?? state.editable) && !isDeleted;
|
|
243
|
-
const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
|
|
244
|
-
if (!editable && state.editable) {
|
|
245
|
-
style.color = "var(--secondary-color)";
|
|
246
|
-
}
|
|
247
|
-
const edited = updatedData[rowIndex]?.[col.key] != null;
|
|
248
|
-
let intent = edited ? "success" : void 0;
|
|
249
|
-
if (isDeleted) {
|
|
250
|
-
intent = "danger";
|
|
251
|
-
}
|
|
252
|
-
const _Cell = col.cellComponent ?? BaseCell;
|
|
253
|
-
let inlineEditor = editable ? col.inlineEditor ?? true : false;
|
|
254
|
-
if (!topLeft) {
|
|
255
|
-
return main_module.default(
|
|
256
|
-
_Cell,
|
|
257
|
-
{
|
|
258
|
-
intent,
|
|
259
|
-
loading,
|
|
260
|
-
value,
|
|
261
|
-
style,
|
|
262
|
-
isDeleted
|
|
263
|
-
},
|
|
264
|
-
_renderedValue
|
|
265
|
-
);
|
|
266
|
-
}
|
|
267
|
-
let hiddenInput = main_module.default("input.hidden-input", {
|
|
268
|
-
autoFocus: true,
|
|
269
|
-
onKeyDown: state.editorKeyHandler
|
|
270
|
-
});
|
|
271
|
-
let cellContents = _renderedValue;
|
|
272
|
-
let _dataEditor = null;
|
|
273
|
-
let className = null;
|
|
274
|
-
if (col.dataEditor != null) {
|
|
275
|
-
_dataEditor = main_module.default(
|
|
276
|
-
editorPopup.EditorPopup,
|
|
277
|
-
{
|
|
278
|
-
autoFocus: autoFocusEditor,
|
|
279
|
-
valueViewer: _renderedValue
|
|
280
|
-
},
|
|
281
|
-
[
|
|
282
|
-
main_module.default(col.dataEditor, {
|
|
283
|
-
value,
|
|
284
|
-
editable,
|
|
285
|
-
onChange(value2) {
|
|
286
|
-
if (!editable) return;
|
|
287
|
-
state.onSelectionEdited(value2);
|
|
288
|
-
}
|
|
289
|
-
})
|
|
290
|
-
]
|
|
291
|
-
);
|
|
292
|
-
}
|
|
293
|
-
if (!editable) {
|
|
294
|
-
if (_dataEditor != null) {
|
|
295
|
-
cellContents = _dataEditor;
|
|
296
|
-
}
|
|
297
|
-
return main_module.default(
|
|
298
|
-
_Cell,
|
|
299
|
-
{
|
|
300
|
-
intent,
|
|
301
|
-
value,
|
|
302
|
-
style
|
|
303
|
-
},
|
|
304
|
-
cellContents
|
|
305
|
-
);
|
|
306
|
-
}
|
|
307
|
-
const onChange = (e) => {
|
|
308
|
-
if (!editable) return;
|
|
309
|
-
if (value === e.target.value) return;
|
|
310
|
-
onCellEdited(rowIndex, col.key, e.target.value);
|
|
311
|
-
};
|
|
312
|
-
const isSingleCellSelection = provider.singleFocusedCell(state.selection) != null;
|
|
313
|
-
let _inlineEditor = null;
|
|
314
|
-
if (typeof inlineEditor == "boolean") {
|
|
315
|
-
let _value = value;
|
|
316
|
-
if (typeof _renderedValue === "string" || typeof _renderedValue === "number" || _renderedValue == null) {
|
|
317
|
-
_value = _renderedValue;
|
|
318
|
-
}
|
|
319
|
-
_inlineEditor = main_module.default("input.main-editor", {
|
|
320
|
-
value: _value ?? "",
|
|
321
|
-
autoFocus: autoFocusEditor,
|
|
322
|
-
onChange,
|
|
323
|
-
onKeyDown: state.editorKeyHandler
|
|
324
|
-
});
|
|
325
|
-
} else {
|
|
326
|
-
_inlineEditor = inlineEditor;
|
|
327
|
-
}
|
|
328
|
-
if (_dataEditor != null) {
|
|
329
|
-
className = "editor-cell";
|
|
330
|
-
cellContents = _dataEditor;
|
|
331
|
-
hiddenInput = null;
|
|
332
|
-
} else if (_inlineEditor != null) {
|
|
333
|
-
cellContents = _inlineEditor;
|
|
334
|
-
className = "input-cell";
|
|
335
|
-
hiddenInput = null;
|
|
336
|
-
}
|
|
337
|
-
return main_module.default(
|
|
338
|
-
_Cell,
|
|
339
|
-
{
|
|
340
|
-
intent,
|
|
341
|
-
value,
|
|
342
|
-
className,
|
|
343
|
-
style
|
|
344
|
-
//truncated: false,
|
|
345
|
-
},
|
|
346
|
-
[
|
|
347
|
-
cellContents,
|
|
348
|
-
main_module.default.if(editable && isSingleCellSelection)(DragHandle),
|
|
349
|
-
hiddenInput
|
|
350
|
-
]
|
|
229
|
+
const deletedRowsAtom = jotai.atom((get) => get(provider.storeAtom).deletedRows);
|
|
230
|
+
const updatedDataAtom = jotai.atom((get) => get(provider.storeAtom).updatedData);
|
|
231
|
+
const hasUpdatesAtom = jotai.atom((get) => {
|
|
232
|
+
const deletedRows = get(deletedRowsAtom);
|
|
233
|
+
const updatedData = get(updatedDataAtom);
|
|
234
|
+
return updatedData.length > 0 || deletedRows.size > 0;
|
|
235
|
+
});
|
|
236
|
+
const columnSpecAtom = jotai.atom((get) => get(provider.storeAtom).columnSpec);
|
|
237
|
+
const columnWidthsIndexAtom = jotai.atom((get) => get(provider.storeAtom).columnWidthsIndex);
|
|
238
|
+
const defaultColumnWidthAtom = jotai.atom((get) => get(provider.storeAtom).defaultColumnWidth);
|
|
239
|
+
const columnWidthsAtom = jotai.atom((get) => {
|
|
240
|
+
const ix = get(columnWidthsIndexAtom);
|
|
241
|
+
return get(columnSpecAtom).map(
|
|
242
|
+
(col) => ix.get(col.key) ?? col.width ?? get(defaultColumnWidthAtom)
|
|
351
243
|
);
|
|
352
|
-
}
|
|
353
|
-
function DragHandle() {
|
|
354
|
-
const onMouseDown = provider.useSelector((state) => state.onDragValue);
|
|
355
|
-
return main_module.default("div.corner-drag-handle", { onMouseDown });
|
|
356
|
-
}
|
|
244
|
+
});
|
|
357
245
|
function DataSheetEditToolbar({ onSaveData, onDeleteRows }) {
|
|
358
246
|
provider.useSelector((state) => state.selection);
|
|
359
247
|
const resetChanges = provider.useSelector((state) => state.resetChanges);
|
|
360
|
-
const hasUpdates = provider.
|
|
248
|
+
const hasUpdates = provider.useAtomValue(hasUpdatesAtom);
|
|
361
249
|
return main_module.default("div.data-sheet-toolbar", [
|
|
362
250
|
main_module.default(core.ButtonGroup, { minimal: true }, [
|
|
363
251
|
main_module.default(AddRowButton),
|
|
@@ -433,16 +321,6 @@ function AddRowButton() {
|
|
|
433
321
|
"Add row"
|
|
434
322
|
);
|
|
435
323
|
}
|
|
436
|
-
function BaseCell({ children, value, ...rest }) {
|
|
437
|
-
return main_module.default(
|
|
438
|
-
table.Cell,
|
|
439
|
-
{
|
|
440
|
-
interactive: true,
|
|
441
|
-
...rest
|
|
442
|
-
},
|
|
443
|
-
children
|
|
444
|
-
);
|
|
445
|
-
}
|
|
446
324
|
function getRowsToDelete(selection) {
|
|
447
325
|
let rowIndices = [];
|
|
448
326
|
for (const sel of selection) {
|
|
@@ -455,11 +333,6 @@ function getRowsToDelete(selection) {
|
|
|
455
333
|
}
|
|
456
334
|
return rowIndices;
|
|
457
335
|
}
|
|
458
|
-
Object.defineProperty(exports, "Cell", {
|
|
459
|
-
enumerable: true,
|
|
460
|
-
get: () => table.Cell
|
|
461
|
-
});
|
|
462
|
-
exports.BaseCell = BaseCell;
|
|
463
336
|
exports.DataSheet = DataSheet;
|
|
464
337
|
exports.DataSheetDensity = DataSheetDensity;
|
|
465
338
|
exports.ScrollToRowControl = ScrollToRowControl;
|