@macrostrat/data-sheet 3.1.0 → 4.0.0-dev1
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 +5 -0
- package/dist/actions/builtin.cjs +56 -0
- package/dist/actions/builtin.cjs.map +1 -0
- package/dist/actions/builtin.d.ts +15 -0
- package/dist/actions/builtin.js +56 -0
- package/dist/actions/builtin.js.map +1 -0
- package/dist/actions/clipboard.cjs +250 -0
- package/dist/actions/clipboard.cjs.map +1 -0
- package/dist/actions/clipboard.d.ts +42 -0
- package/dist/actions/clipboard.js +250 -0
- package/dist/actions/clipboard.js.map +1 -0
- package/dist/actions/filters.cjs +123 -0
- package/dist/actions/filters.cjs.map +1 -0
- package/dist/actions/filters.d.ts +6 -0
- package/dist/actions/filters.js +123 -0
- package/dist/actions/filters.js.map +1 -0
- package/dist/actions/index.d.ts +6 -0
- package/dist/actions/selection.cjs +194 -0
- package/dist/actions/selection.cjs.map +1 -0
- package/dist/actions/selection.d.ts +40 -0
- package/dist/actions/selection.js +192 -0
- package/dist/actions/selection.js.map +1 -0
- package/dist/actions/toolbar.cjs +171 -0
- package/dist/actions/toolbar.cjs.map +1 -0
- package/dist/actions/toolbar.d.ts +10 -0
- package/dist/actions/toolbar.js +171 -0
- package/dist/actions/toolbar.js.map +1 -0
- package/dist/actions/toolbar.module.sass.cjs +22 -0
- package/dist/actions/toolbar.module.sass.cjs.map +1 -0
- package/dist/actions/toolbar.module.sass.js +20 -0
- package/dist/actions/toolbar.module.sass.js.map +1 -0
- package/dist/actions/types.d.ts +143 -0
- package/dist/cell-renderer.cjs +44 -41
- package/dist/cell-renderer.cjs.map +1 -1
- package/dist/cell-renderer.d.ts +1 -6
- package/dist/cell-renderer.js +45 -42
- package/dist/cell-renderer.js.map +1 -1
- package/dist/components/actions.module.sass.cjs +3 -3
- package/dist/components/actions.module.sass.js +2 -2
- package/dist/components/colors.cjs +20 -16
- package/dist/components/colors.cjs.map +1 -1
- package/dist/components/colors.d.ts +4 -3
- package/dist/components/colors.js +20 -16
- package/dist/components/colors.js.map +1 -1
- package/dist/components/editor-popup.cjs +4 -3
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +4 -3
- package/dist/components/editor-popup.js.map +1 -1
- package/dist/components/index.d.ts +1 -0
- package/dist/components/main.module.sass.cjs +12 -12
- package/dist/components/main.module.sass.js +11 -11
- package/dist/components/text-areas.cjs +23 -18
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.d.ts +8 -4
- package/dist/components/text-areas.js +20 -13
- package/dist/components/text-areas.js.map +1 -1
- package/dist/components/view-info.cjs +18 -0
- package/dist/components/view-info.cjs.map +1 -0
- package/dist/components/view-info.d.ts +1 -0
- package/dist/components/view-info.js +18 -0
- package/dist/components/view-info.js.map +1 -0
- package/dist/core.cjs +184 -156
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +14 -1
- package/dist/core.js +187 -157
- package/dist/core.js.map +1 -1
- package/dist/data-sheet.css +181 -43
- package/dist/index.cjs +43 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +43 -10
- package/dist/index.js.map +1 -1
- package/dist/main.module.sass.cjs +15 -14
- package/dist/main.module.sass.cjs.map +1 -1
- package/dist/main.module.sass.js +14 -13
- package/dist/main.module.sass.js.map +1 -1
- package/dist/notifications.cjs +19 -0
- package/dist/notifications.cjs.map +1 -0
- package/dist/notifications.d.ts +9 -0
- package/dist/notifications.js +19 -0
- package/dist/notifications.js.map +1 -0
- package/dist/postgrest-table/data-loaders.cjs +181 -104
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +52 -28
- package/dist/postgrest-table/data-loaders.js +181 -104
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +205 -79
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +13 -16
- package/dist/postgrest-table/index.js +186 -58
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/postgrest-table/lazy-loader-table.cjs +18 -17
- package/dist/postgrest-table/lazy-loader-table.cjs.map +1 -1
- package/dist/postgrest-table/lazy-loader-table.d.ts +1 -1
- package/dist/postgrest-table/lazy-loader-table.js +17 -14
- package/dist/postgrest-table/lazy-loader-table.js.map +1 -1
- package/dist/postgrest-table/loading-utils.cjs +16 -0
- package/dist/postgrest-table/loading-utils.cjs.map +1 -0
- package/dist/postgrest-table/loading-utils.d.ts +13 -0
- package/dist/postgrest-table/loading-utils.js +16 -0
- package/dist/postgrest-table/loading-utils.js.map +1 -0
- package/dist/postgrest-table/main.module.sass.cjs +18 -13
- package/dist/postgrest-table/main.module.sass.cjs.map +1 -1
- package/dist/postgrest-table/main.module.sass.js +18 -13
- package/dist/postgrest-table/main.module.sass.js.map +1 -1
- package/dist/provider.cjs +58 -26
- package/dist/provider.cjs.map +1 -1
- package/dist/provider.js +57 -23
- package/dist/provider.js.map +1 -1
- package/dist/renderers/column-header-cell-postgrest.cjs +216 -0
- package/dist/renderers/column-header-cell-postgrest.cjs.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.d.ts +13 -0
- package/dist/renderers/column-header-cell-postgrest.js +216 -0
- package/dist/renderers/column-header-cell-postgrest.js.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs +23 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.cjs.map +1 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.js +22 -0
- package/dist/renderers/column-header-cell-postgrest.module.sass.js.map +1 -0
- package/dist/renderers/column-header-cell.cjs +103 -0
- package/dist/renderers/column-header-cell.cjs.map +1 -0
- package/dist/renderers/column-header-cell.d.ts +30 -0
- package/dist/renderers/column-header-cell.js +101 -0
- package/dist/renderers/column-header-cell.js.map +1 -0
- package/dist/renderers/index.d.ts +2 -0
- package/dist/table-updates/data-parameter.d.ts +14 -0
- package/dist/table-updates/filter.d.ts +16 -0
- package/dist/table-updates/index.d.ts +19 -0
- package/dist/types.cjs +9 -0
- package/dist/types.cjs.map +1 -0
- package/dist/types.d.ts +58 -4
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/column-spec.cjs +9 -1
- package/dist/utils/column-spec.cjs.map +1 -1
- package/dist/utils/column-spec.d.ts +21 -0
- package/dist/utils/column-spec.js +9 -1
- package/dist/utils/column-spec.js.map +1 -1
- package/dist/utils/key-handling.cjs +141 -52
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +2 -3
- package/dist/utils/key-handling.js +142 -53
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/zustand-store.cjs +216 -51
- package/dist/zustand-store.cjs.map +1 -1
- package/dist/zustand-store.js +197 -32
- package/dist/zustand-store.js.map +1 -1
- package/package.json +3 -3
- package/src/actions/builtin.ts +65 -0
- package/src/actions/clipboard.ts +350 -0
- package/src/actions/filters.ts +150 -0
- package/src/actions/index.ts +6 -0
- package/src/actions/selection.ts +271 -0
- package/src/actions/toolbar.module.sass +30 -0
- package/src/actions/toolbar.ts +212 -0
- package/src/actions/types.ts +159 -0
- package/src/cell-renderer.ts +55 -51
- package/src/components/colors.ts +22 -19
- package/src/components/editor-popup.ts +3 -2
- package/src/components/index.ts +1 -0
- package/src/components/main.module.sass +1 -0
- package/src/components/text-areas.ts +34 -19
- package/src/components/view-info.ts +17 -0
- package/src/core.ts +243 -170
- package/src/index.ts +1 -0
- package/src/main.module.sass +14 -2
- package/src/notifications.ts +22 -0
- package/src/postgrest-table/data-loaders.ts +300 -201
- package/src/postgrest-table/index.ts +258 -84
- package/src/postgrest-table/lazy-loader-table.ts +18 -17
- package/src/postgrest-table/loading-utils.ts +49 -0
- package/src/postgrest-table/main.module.sass +16 -0
- package/src/provider.ts +63 -20
- package/src/renderers/column-header-cell-postgrest.module.sass +71 -0
- package/src/renderers/column-header-cell-postgrest.ts +282 -0
- package/src/renderers/column-header-cell.ts +388 -0
- package/src/renderers/index.ts +2 -0
- package/src/table-updates/data-parameter.ts +44 -0
- package/src/table-updates/filter.ts +124 -0
- package/src/table-updates/index.ts +239 -0
- package/src/types.ts +58 -3
- package/src/utils/column-spec.ts +47 -0
- package/src/utils/key-handling.ts +181 -72
- package/src/zustand-store.ts +241 -36
- package/dist/provider.d.ts +0 -15
package/src/core.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import {
|
|
2
2
|
Button,
|
|
3
|
-
ButtonGroup,
|
|
4
3
|
HotkeysProvider,
|
|
5
4
|
InputGroup,
|
|
6
|
-
|
|
5
|
+
OverlaysProvider,
|
|
6
|
+
useHotkeys,
|
|
7
7
|
} from "@blueprintjs/core";
|
|
8
8
|
import {
|
|
9
9
|
Column,
|
|
@@ -14,21 +14,41 @@ import {
|
|
|
14
14
|
TableProps,
|
|
15
15
|
} from "@blueprintjs/table";
|
|
16
16
|
import "@blueprintjs/table/lib/css/table.css";
|
|
17
|
-
import
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
import {
|
|
18
|
+
ReactNode,
|
|
19
|
+
useCallback,
|
|
20
|
+
useEffect,
|
|
21
|
+
useMemo,
|
|
22
|
+
useRef,
|
|
23
|
+
useState,
|
|
24
|
+
} from "react";
|
|
25
|
+
import { DataSheetAction, InfoBar } from "./components";
|
|
26
|
+
import {
|
|
27
|
+
autoFilterId,
|
|
28
|
+
renderColumnHeaderCell,
|
|
29
|
+
SortFilterBar,
|
|
30
|
+
} from "./renderers";
|
|
20
31
|
import h from "./main.module.sass";
|
|
21
32
|
import {
|
|
33
|
+
columnSpecAtom,
|
|
22
34
|
DataSheetProvider,
|
|
23
35
|
storeAtom,
|
|
24
|
-
useAtomValue,
|
|
25
36
|
useSelector,
|
|
26
37
|
useStoreAPI,
|
|
27
|
-
|
|
38
|
+
ctx,
|
|
39
|
+
tableActionsAtom,
|
|
28
40
|
} from "./provider";
|
|
29
|
-
import {
|
|
41
|
+
import { atom } from "jotai";
|
|
42
|
+
import {
|
|
43
|
+
DataSheetProviderProps,
|
|
44
|
+
TableElementStatus,
|
|
45
|
+
VisibleCells,
|
|
46
|
+
} from "./types.ts";
|
|
30
47
|
import { basicCellRenderer } from "./cell-renderer.ts";
|
|
31
|
-
import {
|
|
48
|
+
import { tableHotkeysAtom } from "./utils";
|
|
49
|
+
import { clipboardActions, TableAction, TableFilter } from "./actions";
|
|
50
|
+
import { ActionsToolbar, FilterBar } from "./actions";
|
|
51
|
+
import { useScrollHandler } from "./postgrest-table";
|
|
32
52
|
|
|
33
53
|
// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args
|
|
34
54
|
|
|
@@ -48,15 +68,29 @@ interface DataSheetInternalProps<T> extends TableProps {
|
|
|
48
68
|
onDeleteRows?: (selection: Region[]) => void;
|
|
49
69
|
verbose?: boolean;
|
|
50
70
|
enableColumnReordering?: boolean;
|
|
71
|
+
enableClipboard?: boolean;
|
|
51
72
|
enableFocusedCell?: boolean;
|
|
52
73
|
dataSheetActions?: ReactNode | null;
|
|
53
74
|
editable?: boolean;
|
|
54
75
|
autoFocusEditor?: boolean;
|
|
55
76
|
density?: DataSheetDensity;
|
|
77
|
+
/** Configurable table actions shown in a selection-aware toolbar.
|
|
78
|
+
* When provided, the actions toolbar renders alongside the existing
|
|
79
|
+
* edit toolbar. Actions are filtered by the current selection cardinality. */
|
|
80
|
+
actions?: TableAction<T>[];
|
|
81
|
+
/** Available column/table filters shown in a filter bar.
|
|
82
|
+
* Filters can also be defined per-column via `ColumnSpec.filters`. */
|
|
83
|
+
filters?: TableFilter<T>[];
|
|
84
|
+
/** Optional custom column header cell renderer, called for each column.
|
|
85
|
+
* Receives the ColumnSpec and column index; should return a React element
|
|
86
|
+
* (typically a Blueprint ColumnHeaderCell). */
|
|
87
|
+
columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;
|
|
56
88
|
}
|
|
57
89
|
|
|
58
90
|
type DataSheetProps<T> = DataSheetProviderProps<T> & DataSheetInternalProps<T>;
|
|
59
91
|
|
|
92
|
+
const emptyData: any[] = [];
|
|
93
|
+
|
|
60
94
|
export function DataSheet<T>(props: DataSheetProps<T>) {
|
|
61
95
|
const {
|
|
62
96
|
data,
|
|
@@ -66,29 +100,28 @@ export function DataSheet<T>(props: DataSheetProps<T>) {
|
|
|
66
100
|
enableColumnReordering = false,
|
|
67
101
|
enableFocusedCell = false,
|
|
68
102
|
defaultColumnWidth = 150,
|
|
103
|
+
children,
|
|
69
104
|
...rest
|
|
70
105
|
} = props;
|
|
71
106
|
|
|
72
107
|
return h(
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
}),
|
|
91
|
-
),
|
|
108
|
+
DataSheetProvider<T>,
|
|
109
|
+
{
|
|
110
|
+
data: data ?? emptyData,
|
|
111
|
+
columnSpec,
|
|
112
|
+
columnSpecOptions,
|
|
113
|
+
enableColumnReordering,
|
|
114
|
+
defaultColumnWidth,
|
|
115
|
+
editable,
|
|
116
|
+
...rest,
|
|
117
|
+
},
|
|
118
|
+
h(_DataSheet<any>, {
|
|
119
|
+
...rest,
|
|
120
|
+
children,
|
|
121
|
+
editable,
|
|
122
|
+
enableColumnReordering,
|
|
123
|
+
enableFocusedCell,
|
|
124
|
+
}),
|
|
92
125
|
);
|
|
93
126
|
}
|
|
94
127
|
|
|
@@ -106,8 +139,14 @@ function _DataSheet<T>({
|
|
|
106
139
|
dataSheetActions = null,
|
|
107
140
|
enableFocusedCell,
|
|
108
141
|
autoFocusEditor = true,
|
|
142
|
+
enableClipboard = true,
|
|
143
|
+
showInfoBar = false,
|
|
109
144
|
density = DataSheetDensity.HIGH,
|
|
110
145
|
selectionModes,
|
|
146
|
+
actions,
|
|
147
|
+
filters,
|
|
148
|
+
columnHeaderCellRenderer,
|
|
149
|
+
children,
|
|
111
150
|
...rest
|
|
112
151
|
}: DataSheetInternalProps<T>) {
|
|
113
152
|
/**
|
|
@@ -116,14 +155,34 @@ function _DataSheet<T>({
|
|
|
116
155
|
* @param columnSpecOptions: Options for generating a column spec from data
|
|
117
156
|
*/
|
|
118
157
|
|
|
158
|
+
// Turn on debug features
|
|
159
|
+
const debugMode = false;
|
|
160
|
+
|
|
161
|
+
// Sync table actions to atom
|
|
162
|
+
const _actions: TableAction[] = useMemo(() => {
|
|
163
|
+
const _actions = [];
|
|
164
|
+
if (actions != null) {
|
|
165
|
+
_actions.push(...actions);
|
|
166
|
+
}
|
|
167
|
+
if (enableClipboard) {
|
|
168
|
+
_actions.push(...clipboardActions);
|
|
169
|
+
}
|
|
170
|
+
return _actions;
|
|
171
|
+
}, [actions, enableClipboard]);
|
|
172
|
+
|
|
173
|
+
ctx.useSync(tableActionsAtom, _actions);
|
|
174
|
+
|
|
175
|
+
const hotkeysConfig = ctx.useValue(tableHotkeysAtom);
|
|
176
|
+
const { handleKeyDown, handleKeyUp } = useHotkeys(hotkeysConfig);
|
|
177
|
+
|
|
119
178
|
// For now, we only consider a single cell "focused" when we have one cell selected.
|
|
120
179
|
// Multi-cell selections have a different set of "bulk" actions.
|
|
121
|
-
const selectedRegions = useSelector<T>((state) => state.selection);
|
|
180
|
+
const selectedRegions = useSelector<T>((state) => state.selection ?? []);
|
|
122
181
|
|
|
123
182
|
const data = useSelector((state) => state.data);
|
|
124
183
|
const editable = useSelector((state) => state.editable);
|
|
125
184
|
|
|
126
|
-
const
|
|
185
|
+
const rowStatus = useSelector((state) => state.rowStatus);
|
|
127
186
|
|
|
128
187
|
const focusedCell = useSelector((state) => state.focusedCell);
|
|
129
188
|
|
|
@@ -134,45 +193,20 @@ function _DataSheet<T>({
|
|
|
134
193
|
// A sparse array to hold updates
|
|
135
194
|
// TODO: create a "changeset" concept to facilitate undo/redo
|
|
136
195
|
const updatedData = useSelector((state) => state.updatedData);
|
|
137
|
-
const setUpdatedData = useSelector((state) => state.setUpdatedData);
|
|
138
196
|
|
|
139
197
|
const onSelection = useSelector((state) => state.onSelection);
|
|
140
198
|
|
|
141
199
|
const storeAPI = useStoreAPI<T>();
|
|
142
200
|
|
|
143
|
-
const
|
|
144
|
-
if (onSaveData == null) return null;
|
|
145
|
-
return () => {
|
|
146
|
-
onSaveData(updatedData, data);
|
|
147
|
-
setUpdatedData([]);
|
|
148
|
-
};
|
|
149
|
-
}, [updatedData, data, onSaveData]);
|
|
150
|
-
|
|
151
|
-
const setVisibleCells = useSelector((state) => state.setVisibleCells);
|
|
152
|
-
|
|
201
|
+
const onScroll = useScrollHandler();
|
|
153
202
|
const _onVisibleCellsChange = useCallback(
|
|
154
203
|
(visibleCells: VisibleCells) => {
|
|
155
|
-
|
|
204
|
+
onScroll(visibleCells);
|
|
156
205
|
onVisibleCellsChange?.(visibleCells);
|
|
157
206
|
},
|
|
158
|
-
[onVisibleCellsChange,
|
|
207
|
+
[onVisibleCellsChange, onScroll],
|
|
159
208
|
);
|
|
160
209
|
|
|
161
|
-
const onAddRow = useCallback(() => {
|
|
162
|
-
setUpdatedData((updatedData: any[]): any[] => {
|
|
163
|
-
const ix = Math.max(updatedData.length, data.length);
|
|
164
|
-
const addRowSpec = { [ix]: { $set: {} } };
|
|
165
|
-
const newUpdatedData = update(updatedData, addRowSpec);
|
|
166
|
-
return newUpdatedData;
|
|
167
|
-
});
|
|
168
|
-
}, [setUpdatedData]);
|
|
169
|
-
|
|
170
|
-
const deleteSelectedRows = useSelector((state) => state.deleteSelectedRows);
|
|
171
|
-
const _onDeleteRows = useCallback(() => {
|
|
172
|
-
deleteSelectedRows();
|
|
173
|
-
onDeleteRows?.(selectedRegions);
|
|
174
|
-
}, [onDeleteRows, selectedRegions, deleteSelectedRows]);
|
|
175
|
-
|
|
176
210
|
useEffect(() => {
|
|
177
211
|
if (!verbose) return;
|
|
178
212
|
console.log("Updated data", updatedData);
|
|
@@ -187,43 +221,68 @@ function _DataSheet<T>({
|
|
|
187
221
|
console.log("Selected regions", selectedRegions);
|
|
188
222
|
}, [selectedRegions]);
|
|
189
223
|
|
|
190
|
-
const
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
224
|
+
const tableElementRef = useRef<HTMLElement>(null);
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
// Return the focus to the table
|
|
227
|
+
tableElementRef.current?.focus();
|
|
228
|
+
}, [focusedCell]);
|
|
194
229
|
|
|
195
|
-
const columnWidths =
|
|
230
|
+
const columnWidths = ctx.useValue(columnWidthsAtom);
|
|
196
231
|
|
|
197
|
-
|
|
232
|
+
// When filters are active, only show matching rows
|
|
233
|
+
const filteredRowIndices = useSelector((state) => state.filteredRowIndices);
|
|
234
|
+
const totalRows = Math.max(updatedData.length, data.length);
|
|
235
|
+
const numRows =
|
|
236
|
+
filteredRowIndices != null ? filteredRowIndices.length : totalRows;
|
|
198
237
|
|
|
199
238
|
let className = `${density}-density`;
|
|
200
239
|
|
|
201
|
-
|
|
202
|
-
let defaultColumnWidth = 150;
|
|
203
|
-
let style = {
|
|
204
|
-
"--data-sheet-row-height": "20px",
|
|
205
|
-
"--data-sheet-font-size": "12px",
|
|
206
|
-
};
|
|
207
|
-
if (density === DataSheetDensity.MEDIUM) {
|
|
208
|
-
rowHeight = 24;
|
|
209
|
-
style = {
|
|
210
|
-
"--data-sheet-row-height": "24px",
|
|
211
|
-
"--data-sheet-font-size": "14px",
|
|
212
|
-
};
|
|
213
|
-
} else if (density === DataSheetDensity.LOW) {
|
|
214
|
-
rowHeight = 30;
|
|
215
|
-
style = {
|
|
216
|
-
"--data-sheet-row-height": "30px",
|
|
217
|
-
"--data-sheet-font-size": "18px",
|
|
218
|
-
};
|
|
219
|
-
}
|
|
240
|
+
const { rowHeight, style } = styleParamsForDensity(density);
|
|
220
241
|
|
|
221
242
|
const onColumnsReordered = useSelector((state) => state.onColumnsReordered);
|
|
222
243
|
|
|
223
|
-
|
|
244
|
+
// Auto-detect if any columns have sortable/filterable set.
|
|
245
|
+
// If so and no explicit columnHeaderCellRenderer was provided,
|
|
246
|
+
// use the built-in client-side sort/filter header.
|
|
247
|
+
const hasSortableOrFilterable = useMemo(
|
|
248
|
+
() => columnSpec.some((col) => col.sortable || col.filterable),
|
|
249
|
+
[columnSpec],
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
const columnSorts = useSelector((state) => state.columnSorts);
|
|
253
|
+
const activeFilters = useSelector((state) => state.activeFilters);
|
|
254
|
+
|
|
255
|
+
const realizedColumns = useMemo(() => {
|
|
224
256
|
return columnSpec.map((col, colIndex) => {
|
|
257
|
+
let fn =
|
|
258
|
+
col.headerCellRenderer ??
|
|
259
|
+
columnHeaderCellRenderer ??
|
|
260
|
+
renderColumnHeaderCell;
|
|
261
|
+
let activeSort = null;
|
|
262
|
+
let activeFilter = null;
|
|
263
|
+
if (col.sortable) {
|
|
264
|
+
activeSort = columnSorts?.find((s) => s.key === col.key);
|
|
265
|
+
}
|
|
266
|
+
if (col.filterable) {
|
|
267
|
+
// The autoFilterID implementation is too complicated
|
|
268
|
+
activeFilter =
|
|
269
|
+
activeFilters?.get(col.key) ??
|
|
270
|
+
activeFilters?.get(autoFilterId(col.key));
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const _columnHeaderCellRenderer = (colIndex) => {
|
|
274
|
+
return fn({
|
|
275
|
+
col,
|
|
276
|
+
colIndex,
|
|
277
|
+
activeSort,
|
|
278
|
+
activeFilter,
|
|
279
|
+
});
|
|
280
|
+
};
|
|
281
|
+
|
|
225
282
|
return h(Column, {
|
|
283
|
+
id: col.key,
|
|
226
284
|
name: col.name,
|
|
285
|
+
columnHeaderCellRenderer: _columnHeaderCellRenderer,
|
|
227
286
|
cellRenderer: (rowIndex) => {
|
|
228
287
|
const state = storeAPI.getState();
|
|
229
288
|
return basicCellRenderer<T>(
|
|
@@ -232,11 +291,20 @@ function _DataSheet<T>({
|
|
|
232
291
|
col,
|
|
233
292
|
state,
|
|
234
293
|
autoFocusEditor,
|
|
294
|
+
filteredRowIndices,
|
|
235
295
|
);
|
|
236
296
|
},
|
|
237
297
|
});
|
|
238
298
|
});
|
|
239
|
-
}, [
|
|
299
|
+
}, [
|
|
300
|
+
columnSpec,
|
|
301
|
+
columnSorts,
|
|
302
|
+
activeFilters,
|
|
303
|
+
storeAPI,
|
|
304
|
+
autoFocusEditor,
|
|
305
|
+
filteredRowIndices,
|
|
306
|
+
columnHeaderCellRenderer,
|
|
307
|
+
]);
|
|
240
308
|
|
|
241
309
|
const onColumnWidthChanged = useSelector(
|
|
242
310
|
(state) => state.onColumnWidthChanged,
|
|
@@ -244,20 +312,25 @@ function _DataSheet<T>({
|
|
|
244
312
|
|
|
245
313
|
const rowHeaderCellRenderer = useCallback(
|
|
246
314
|
(rowIndex: number) => {
|
|
247
|
-
const
|
|
315
|
+
const dataRowIndex =
|
|
316
|
+
filteredRowIndices != null
|
|
317
|
+
? (filteredRowIndices[rowIndex] ?? rowIndex)
|
|
318
|
+
: rowIndex;
|
|
319
|
+
const style =
|
|
320
|
+
rowStatus[dataRowIndex] == TableElementStatus.DELETED
|
|
321
|
+
? deletedRowHeaderStyle
|
|
322
|
+
: null;
|
|
248
323
|
|
|
249
324
|
return h(RowHeaderCell, {
|
|
250
325
|
enableRowReordering: false,
|
|
251
326
|
index: rowIndex,
|
|
252
|
-
name: `${
|
|
327
|
+
name: `${dataRowIndex + 1}`,
|
|
253
328
|
style,
|
|
254
329
|
});
|
|
255
330
|
},
|
|
256
|
-
[
|
|
331
|
+
[rowStatus, filteredRowIndices],
|
|
257
332
|
);
|
|
258
333
|
|
|
259
|
-
const onKeyDown = useAtomValue(tableKeyHandlerAtom);
|
|
260
|
-
|
|
261
334
|
let _selectionModes = selectionModes;
|
|
262
335
|
if (
|
|
263
336
|
editable &&
|
|
@@ -268,15 +341,28 @@ function _DataSheet<T>({
|
|
|
268
341
|
// Ensure selection mode includes "cells"
|
|
269
342
|
}
|
|
270
343
|
|
|
344
|
+
const cellRendererDependencies = [
|
|
345
|
+
data,
|
|
346
|
+
updatedData,
|
|
347
|
+
focusedCell,
|
|
348
|
+
rowStatus,
|
|
349
|
+
filteredRowIndices,
|
|
350
|
+
];
|
|
351
|
+
|
|
271
352
|
return h("div.data-sheet-container", { className, style }, [
|
|
272
|
-
h.if(
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
}),
|
|
353
|
+
h.if(actions != null)(ActionsToolbar, { actions }),
|
|
354
|
+
h.if(filters != null && filters.length > 0)(FilterBar, { filters }),
|
|
355
|
+
h.if(hasSortableOrFilterable)(SortFilterBar),
|
|
276
356
|
dataSheetActions,
|
|
357
|
+
children,
|
|
277
358
|
h(
|
|
278
359
|
"div.data-sheet-holder",
|
|
279
|
-
{
|
|
360
|
+
{
|
|
361
|
+
tabIndex: 0,
|
|
362
|
+
onKeyDown: handleKeyDown,
|
|
363
|
+
onKeyUp: handleKeyUp,
|
|
364
|
+
ref: tableElementRef,
|
|
365
|
+
},
|
|
280
366
|
h(
|
|
281
367
|
Table,
|
|
282
368
|
{
|
|
@@ -292,40 +378,34 @@ function _DataSheet<T>({
|
|
|
292
378
|
columnWidths,
|
|
293
379
|
onColumnWidthChanged,
|
|
294
380
|
onSelection,
|
|
381
|
+
/** TODO: we could enable this, but we need a use-case first... */
|
|
295
382
|
enableRowReordering: false,
|
|
296
383
|
enableRowResizing: false,
|
|
297
384
|
// The cell renderer is memoized internally based on these data dependencies
|
|
298
|
-
cellRendererDependencies
|
|
299
|
-
data,
|
|
300
|
-
//selection,
|
|
301
|
-
updatedData,
|
|
302
|
-
focusedCell,
|
|
303
|
-
deletedRows,
|
|
304
|
-
],
|
|
385
|
+
cellRendererDependencies,
|
|
305
386
|
onVisibleCellsChange: _onVisibleCellsChange,
|
|
306
387
|
rowHeaderCellRenderer,
|
|
307
388
|
selectionModes: _selectionModes,
|
|
308
389
|
...rest,
|
|
390
|
+
getCellClipboardData: null,
|
|
309
391
|
},
|
|
310
|
-
|
|
392
|
+
realizedColumns,
|
|
311
393
|
),
|
|
312
394
|
),
|
|
395
|
+
h.if(showInfoBar)(InfoBar),
|
|
396
|
+
h.if(debugMode)(CellRendererDebugOverlay, {
|
|
397
|
+
cellRendererDependencies,
|
|
398
|
+
names: [
|
|
399
|
+
"data",
|
|
400
|
+
"updatedData",
|
|
401
|
+
"focusedCell",
|
|
402
|
+
"rowStatus",
|
|
403
|
+
"filteredRowIndices",
|
|
404
|
+
],
|
|
405
|
+
}),
|
|
313
406
|
]);
|
|
314
407
|
}
|
|
315
408
|
|
|
316
|
-
/** Atoms for efficient sub-selection of state */
|
|
317
|
-
|
|
318
|
-
const deletedRowsAtom = atom((get) => get(storeAtom).deletedRows);
|
|
319
|
-
const updatedDataAtom = atom((get) => get(storeAtom).updatedData);
|
|
320
|
-
|
|
321
|
-
const hasUpdatesAtom = atom((get) => {
|
|
322
|
-
// Readable atom to indicate whether there are any updates in the updatedData array
|
|
323
|
-
const deletedRows = get(deletedRowsAtom);
|
|
324
|
-
const updatedData = get(updatedDataAtom);
|
|
325
|
-
return updatedData.length > 0 || deletedRows.size > 0;
|
|
326
|
-
});
|
|
327
|
-
|
|
328
|
-
const columnSpecAtom = atom((get) => get(storeAtom).columnSpec);
|
|
329
409
|
const columnWidthsIndexAtom = atom((get) => get(storeAtom).columnWidthsIndex);
|
|
330
410
|
const defaultColumnWidthAtom = atom((get) => get(storeAtom).defaultColumnWidth);
|
|
331
411
|
|
|
@@ -336,50 +416,25 @@ const columnWidthsAtom = atom((get) => {
|
|
|
336
416
|
);
|
|
337
417
|
});
|
|
338
418
|
|
|
339
|
-
function
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
),
|
|
359
|
-
]),
|
|
360
|
-
h("div.spacer"),
|
|
361
|
-
h(ButtonGroup, [
|
|
362
|
-
h(
|
|
363
|
-
Button,
|
|
364
|
-
{
|
|
365
|
-
intent: Intent.WARNING,
|
|
366
|
-
disabled: !hasUpdates,
|
|
367
|
-
onClick: resetChanges,
|
|
368
|
-
},
|
|
369
|
-
"Reset",
|
|
370
|
-
),
|
|
371
|
-
h.if(onSaveData != null)(
|
|
372
|
-
Button,
|
|
373
|
-
{
|
|
374
|
-
intent: Intent.SUCCESS,
|
|
375
|
-
icon: "floppy-disk",
|
|
376
|
-
disabled: !hasUpdates,
|
|
377
|
-
onClick: onSaveData,
|
|
378
|
-
},
|
|
379
|
-
"Save",
|
|
380
|
-
),
|
|
381
|
-
]),
|
|
382
|
-
]);
|
|
419
|
+
function CellRendererDebugOverlay({ cellRendererDependencies, names }) {
|
|
420
|
+
/** Debug overlay for cell renderer dependencies */
|
|
421
|
+
const lastRenderDependencies = useRef<any[]>(cellRendererDependencies);
|
|
422
|
+
useEffect(() => {
|
|
423
|
+
let changeDepNames = [];
|
|
424
|
+
for (const [i, dep] of cellRendererDependencies.entries()) {
|
|
425
|
+
if (dep !== lastRenderDependencies.current[i]) {
|
|
426
|
+
changeDepNames.push(names[i]);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
if (changeDepNames.length > 0) {
|
|
430
|
+
console.log(
|
|
431
|
+
"Cell renderer dependencies changed:",
|
|
432
|
+
changeDepNames.join(", "),
|
|
433
|
+
);
|
|
434
|
+
}
|
|
435
|
+
lastRenderDependencies.current = cellRendererDependencies;
|
|
436
|
+
}, cellRendererDependencies);
|
|
437
|
+
return null;
|
|
383
438
|
}
|
|
384
439
|
|
|
385
440
|
export function ScrollToRowControl() {
|
|
@@ -409,16 +464,34 @@ export function ScrollToRowControl() {
|
|
|
409
464
|
]);
|
|
410
465
|
}
|
|
411
466
|
|
|
412
|
-
function
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
467
|
+
function styleParamsForDensity(density: DataSheetDensity) {
|
|
468
|
+
switch (density) {
|
|
469
|
+
case DataSheetDensity.MEDIUM:
|
|
470
|
+
return {
|
|
471
|
+
rowHeight: 24,
|
|
472
|
+
style: {
|
|
473
|
+
"--data-sheet-row-height": "24px",
|
|
474
|
+
"--data-sheet-font-size": "14px",
|
|
475
|
+
},
|
|
476
|
+
};
|
|
477
|
+
case DataSheetDensity.LOW:
|
|
478
|
+
return {
|
|
479
|
+
rowHeight: 30,
|
|
480
|
+
style: {
|
|
481
|
+
"--data-sheet-row-height": "30px",
|
|
482
|
+
"--data-sheet-font-size": "18px",
|
|
483
|
+
},
|
|
484
|
+
};
|
|
485
|
+
case DataSheetDensity.HIGH:
|
|
486
|
+
default:
|
|
487
|
+
return {
|
|
488
|
+
rowHeight: 20,
|
|
489
|
+
style: {
|
|
490
|
+
"--data-sheet-row-height": "20px",
|
|
491
|
+
"--data-sheet-font-size": "12px",
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
}
|
|
422
495
|
}
|
|
423
496
|
|
|
424
497
|
export function getRowsToDelete(selection) {
|
package/src/index.ts
CHANGED
package/src/main.module.sass
CHANGED
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
font-size: var(--data-sheet-font-size, 12px)
|
|
6
6
|
line-height: var(--data-sheet-row-height, 20px)
|
|
7
7
|
|
|
8
|
+
--data-sheet-cell-padding: 0px 8px
|
|
9
|
+
|
|
8
10
|
:global
|
|
9
11
|
.bp6-table-cell
|
|
12
|
+
padding: var(--data-sheet-cell-padding)
|
|
10
13
|
&:not([class*="bp6-intent-"]):not(.bp6-loading)
|
|
11
14
|
color: var(--text-color)
|
|
12
15
|
|
|
@@ -34,12 +37,13 @@
|
|
|
34
37
|
background-color: var(--panel-secondary-background-color)
|
|
35
38
|
|
|
36
39
|
.input-cell
|
|
37
|
-
padding: 0 2px !important
|
|
40
|
+
// padding: 0 2px !important
|
|
38
41
|
|
|
39
42
|
input
|
|
40
43
|
width: 100%
|
|
41
44
|
height: 100%
|
|
42
|
-
padding: 0
|
|
45
|
+
padding: 0
|
|
46
|
+
//padding: 0 8px
|
|
43
47
|
z-index: 0
|
|
44
48
|
position: relative
|
|
45
49
|
border: none
|
|
@@ -52,6 +56,14 @@
|
|
|
52
56
|
&:focus
|
|
53
57
|
outline: none
|
|
54
58
|
|
|
59
|
+
.value-viewer-cell
|
|
60
|
+
:global(.bp6-popover-target)
|
|
61
|
+
width: 100%
|
|
62
|
+
height: var(--data-sheet-row-height)
|
|
63
|
+
position: relative
|
|
64
|
+
padding: var(--data-sheet-cell-padding)
|
|
65
|
+
margin: calc(var(--data-sheet-cell-padding) * -1)
|
|
66
|
+
|
|
55
67
|
// Make sure popover target fills the entire cell
|
|
56
68
|
.editor-cell :global(.bp6-popover-target)
|
|
57
69
|
//pointer-events: none
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import { OverlayToaster } from "@blueprintjs/core";
|
|
2
|
+
import { atom, useAtom } from "jotai";
|
|
3
|
+
import { ctx } from "./provider";
|
|
4
|
+
import { useEffect } from "react";
|
|
5
|
+
|
|
6
|
+
/** Toaster access
|
|
7
|
+
* Atom that stores a reference to a global or contextual toaster used by the
|
|
8
|
+
* data sheet.
|
|
9
|
+
* */
|
|
10
|
+
export const toasterAtom = atom(null);
|
|
11
|
+
|
|
12
|
+
export function useToaster(toaster?: OverlayToaster): OverlayToaster {
|
|
13
|
+
const [toasterRef, setToasterRef] = ctx.use(toasterAtom);
|
|
14
|
+
useEffect(() => {
|
|
15
|
+
if (toaster != null) {
|
|
16
|
+
setToasterRef(toaster);
|
|
17
|
+
} else {
|
|
18
|
+
OverlayToaster.create().then((t) => setToasterRef(t));
|
|
19
|
+
}
|
|
20
|
+
}, [toaster]);
|
|
21
|
+
return toasterRef;
|
|
22
|
+
}
|