@macrostrat/data-sheet 2.0.2 → 2.1.1
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 +16 -0
- package/README.md +17 -10
- package/dist/esm/{utils.5d81fe80.js → data-sheet.0adfe599.js} +2 -2
- package/dist/esm/{utils.5d81fe80.js.map → data-sheet.0adfe599.js.map} +1 -1
- package/dist/esm/{editor-popup.819ce365.js → data-sheet.1d6ac6c6.js} +28 -8
- package/dist/esm/data-sheet.1d6ac6c6.js.map +1 -0
- package/dist/esm/{core.f82b5af0.js → data-sheet.2521a9d7.js} +181 -82
- package/dist/esm/data-sheet.2521a9d7.js.map +1 -0
- package/dist/esm/{main.module.7e0903d4.js → data-sheet.37e35216.js} +16 -1
- package/dist/esm/data-sheet.37e35216.js.map +1 -0
- package/dist/esm/{column-spec.e56f4d75.js → data-sheet.410c5122.js} +20 -7
- package/dist/esm/data-sheet.410c5122.js.map +1 -0
- package/dist/esm/{main.module.83442ac4.js → data-sheet.48635112.js} +4 -1
- package/dist/esm/data-sheet.48635112.js.map +1 -0
- package/dist/esm/{data-loaders.b7de291b.js → data-sheet.4e347b27.js} +16 -8
- package/dist/esm/data-sheet.4e347b27.js.map +1 -0
- package/dist/esm/{actions.module.560a3136.js → data-sheet.54cfa8e8.js} +1 -1
- package/dist/esm/{actions.module.560a3136.js.map → data-sheet.54cfa8e8.js.map} +1 -1
- package/dist/esm/{colors.75a92ad3.js → data-sheet.6021b6c9.js} +30 -21
- package/dist/esm/data-sheet.6021b6c9.js.map +1 -0
- package/dist/esm/{actions.module.684172fa.css → data-sheet.706f955d.css} +1 -1
- package/dist/esm/{actions.module.684172fa.css.map → data-sheet.706f955d.css.map} +1 -1
- package/dist/esm/{main.module.658cf7b2.css → data-sheet.91223ec6.css} +35 -1
- package/dist/esm/data-sheet.91223ec6.css.map +1 -0
- package/dist/esm/data-sheet.98a2f363.js +194 -0
- package/dist/esm/data-sheet.98a2f363.js.map +1 -0
- package/dist/esm/{actions.065d098d.js → data-sheet.a3eb6088.js} +4 -4
- package/dist/esm/{actions.065d098d.js.map → data-sheet.a3eb6088.js.map} +1 -1
- package/dist/esm/{main.module.df43976f.css → data-sheet.b3ccc91b.css} +8 -5
- package/dist/esm/data-sheet.b3ccc91b.css.map +1 -0
- package/dist/esm/{provider.fefae4a0.js → data-sheet.b4098761.js} +154 -12
- package/dist/esm/data-sheet.b4098761.js.map +1 -0
- package/dist/esm/{text-areas.ccfcf204.js → data-sheet.b5946d6b.js} +6 -5
- package/dist/esm/data-sheet.b5946d6b.js.map +1 -0
- package/dist/esm/data-sheet.ce2a3218.js +13 -0
- package/dist/esm/data-sheet.ce2a3218.js.map +1 -0
- package/dist/esm/{main.module.bd60788c.js → data-sheet.d570ef95.js} +22 -22
- package/dist/esm/data-sheet.d570ef95.js.map +1 -0
- package/dist/esm/data-sheet.ef63e366.css +110 -0
- package/dist/esm/data-sheet.ef63e366.css.map +1 -0
- package/dist/esm/index.d.ts +88 -32
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +7 -3
- package/dist/esm/index.js.map +1 -1
- package/dist/node/data-sheet.171105c1.js +2 -0
- package/dist/node/data-sheet.171105c1.js.map +1 -0
- package/dist/node/data-sheet.1a487c3c.js +2 -0
- package/dist/node/data-sheet.1a487c3c.js.map +1 -0
- package/dist/node/data-sheet.28641e23.css +2 -0
- package/dist/node/data-sheet.28641e23.css.map +1 -0
- package/dist/node/data-sheet.2cac1a8c.js +2 -0
- package/dist/node/data-sheet.2cac1a8c.js.map +1 -0
- package/dist/node/data-sheet.2f64274d.css +2 -0
- package/dist/node/data-sheet.2f64274d.css.map +1 -0
- package/dist/node/data-sheet.3680e59d.js +2 -0
- package/dist/node/data-sheet.3680e59d.js.map +1 -0
- package/dist/node/data-sheet.427d6e1c.js +2 -0
- package/dist/node/data-sheet.427d6e1c.js.map +1 -0
- package/dist/node/data-sheet.50d0742f.js +2 -0
- package/dist/node/data-sheet.50d0742f.js.map +1 -0
- package/dist/node/data-sheet.52753d1d.js +2 -0
- package/dist/node/data-sheet.52753d1d.js.map +1 -0
- package/dist/node/data-sheet.7b95fbc1.css +2 -0
- package/dist/node/data-sheet.7b95fbc1.css.map +1 -0
- package/dist/node/data-sheet.7bbad640.js +2 -0
- package/dist/node/data-sheet.7bbad640.js.map +1 -0
- package/dist/node/data-sheet.820e5bc3.js +2 -0
- package/dist/node/data-sheet.820e5bc3.js.map +1 -0
- package/dist/node/data-sheet.86550c41.js +2 -0
- package/dist/node/data-sheet.86550c41.js.map +1 -0
- package/dist/node/data-sheet.945becc3.js +2 -0
- package/dist/node/data-sheet.945becc3.js.map +1 -0
- package/dist/node/data-sheet.a65463ef.js +2 -0
- package/dist/node/data-sheet.a65463ef.js.map +1 -0
- package/dist/node/data-sheet.cbbc8d31.js +2 -0
- package/dist/node/data-sheet.cbbc8d31.js.map +1 -0
- package/dist/node/data-sheet.ef1661d7.js +2 -0
- package/dist/node/data-sheet.ef1661d7.js.map +1 -0
- package/dist/node/data-sheet.f0223f39.js +2 -0
- package/dist/node/data-sheet.f0223f39.js.map +1 -0
- package/dist/node/{actions.module.565df529.css → data-sheet.ffaf8ac7.css} +1 -1
- package/dist/node/data-sheet.ffaf8ac7.css.map +1 -0
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +8 -6
- package/src/__archive/base.ts +1 -1
- package/src/__archive/components/column-utils.ts +1 -1
- package/src/__archive/components/index.ts +3 -3
- package/src/__archive/components/toolbar.ts +4 -4
- package/src/__archive/editors/index.ts +2 -2
- package/src/__archive/main.ts +6 -6
- package/src/__archive/provider.ts +1 -1
- package/src/__archive/test-sheet/index.ts +5 -5
- package/src/__archive/virtualized.ts +2 -2
- package/src/components/colors.ts +38 -22
- package/src/components/editor-popup.ts +28 -6
- package/src/components/index.ts +1 -0
- package/src/components/main.module.sass +33 -0
- package/src/components/text-areas.ts +2 -1
- package/src/core.ts +263 -112
- package/src/index.ts +2 -0
- package/src/main.module.sass +19 -0
- package/src/postgrest-table/data-loaders.ts +55 -18
- package/src/postgrest-table/index.ts +113 -52
- package/src/postgrest-table/main.module.sass +6 -4
- package/src/provider.ts +289 -104
- package/src/utils/column-spec.ts +44 -3
- package/dist/esm/cell-renderers.8222e82a.js +0 -31
- package/dist/esm/cell-renderers.8222e82a.js.map +0 -1
- package/dist/esm/colors.75a92ad3.js.map +0 -1
- package/dist/esm/column-spec.e56f4d75.js.map +0 -1
- package/dist/esm/components.f832ecf3.js +0 -11
- package/dist/esm/components.f832ecf3.js.map +0 -1
- package/dist/esm/core.f82b5af0.js.map +0 -1
- package/dist/esm/data-loaders.b7de291b.js.map +0 -1
- package/dist/esm/editor-popup.819ce365.js.map +0 -1
- package/dist/esm/main.module.658cf7b2.css.map +0 -1
- package/dist/esm/main.module.7e0903d4.js.map +0 -1
- package/dist/esm/main.module.83442ac4.js.map +0 -1
- package/dist/esm/main.module.b66a4bc1.css +0 -91
- package/dist/esm/main.module.b66a4bc1.css.map +0 -1
- package/dist/esm/main.module.bd60788c.js.map +0 -1
- package/dist/esm/main.module.df43976f.css.map +0 -1
- package/dist/esm/postgrest-table.d4e0260e.js +0 -173
- package/dist/esm/postgrest-table.d4e0260e.js.map +0 -1
- package/dist/esm/provider.fefae4a0.js.map +0 -1
- package/dist/esm/text-areas.ccfcf204.js.map +0 -1
- package/dist/node/actions.4dfe63d8.js +0 -2
- package/dist/node/actions.4dfe63d8.js.map +0 -1
- package/dist/node/actions.module.565df529.css.map +0 -1
- package/dist/node/actions.module.61991621.js +0 -2
- package/dist/node/actions.module.61991621.js.map +0 -1
- package/dist/node/cell-renderers.bbaaeb83.js +0 -2
- package/dist/node/cell-renderers.bbaaeb83.js.map +0 -1
- package/dist/node/colors.fee61100.js +0 -2
- package/dist/node/colors.fee61100.js.map +0 -1
- package/dist/node/column-spec.da7354f5.js +0 -2
- package/dist/node/column-spec.da7354f5.js.map +0 -1
- package/dist/node/components.213ca3fc.js +0 -2
- package/dist/node/components.213ca3fc.js.map +0 -1
- package/dist/node/core.c404e4d4.js +0 -2
- package/dist/node/core.c404e4d4.js.map +0 -1
- package/dist/node/data-loaders.50ce46a4.js +0 -2
- package/dist/node/data-loaders.50ce46a4.js.map +0 -1
- package/dist/node/editor-popup.e19a3668.js +0 -2
- package/dist/node/editor-popup.e19a3668.js.map +0 -1
- package/dist/node/main.module.0802fb12.js +0 -2
- package/dist/node/main.module.0802fb12.js.map +0 -1
- package/dist/node/main.module.273015bb.js +0 -2
- package/dist/node/main.module.273015bb.js.map +0 -1
- package/dist/node/main.module.4cad6bbb.js +0 -2
- package/dist/node/main.module.4cad6bbb.js.map +0 -1
- package/dist/node/main.module.8370d601.css +0 -2
- package/dist/node/main.module.8370d601.css.map +0 -1
- package/dist/node/main.module.a197ee6f.css +0 -2
- package/dist/node/main.module.a197ee6f.css.map +0 -1
- package/dist/node/main.module.e5354239.css +0 -2
- package/dist/node/main.module.e5354239.css.map +0 -1
- package/dist/node/postgrest-table.49926421.js +0 -2
- package/dist/node/postgrest-table.49926421.js.map +0 -1
- package/dist/node/provider.f11d5828.js +0 -2
- package/dist/node/provider.f11d5828.js.map +0 -1
- package/dist/node/text-areas.64832f7d.js +0 -2
- package/dist/node/text-areas.64832f7d.js.map +0 -1
- package/dist/node/utils.897d92e2.js +0 -2
- package/dist/node/utils.897d92e2.js.map +0 -1
- package/src/postgrest-table/cell-renderers.ts +0 -24
package/src/provider.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createContext, useContext, useEffect, useRef, useState } from "react";
|
|
2
2
|
import h from "@macrostrat/hyper";
|
|
3
3
|
import { createStore, StoreApi, useStore } from "zustand";
|
|
4
|
+
import { createComputed } from "zustand-computed";
|
|
4
5
|
import type {
|
|
5
6
|
FocusedCellCoordinates,
|
|
6
7
|
Region,
|
|
@@ -24,11 +25,12 @@ export interface ColumnSpec {
|
|
|
24
25
|
editable?: boolean;
|
|
25
26
|
inlineEditor?: boolean | React.ComponentType<any> | string | null;
|
|
26
27
|
style?: React.CSSProperties;
|
|
28
|
+
width?: number;
|
|
27
29
|
}
|
|
28
30
|
|
|
29
|
-
export interface ColumnSpecOptions {
|
|
31
|
+
export interface ColumnSpecOptions<T> {
|
|
30
32
|
overrides: Record<string, Partial<ColumnSpec> | string>;
|
|
31
|
-
data?:
|
|
33
|
+
data?: T[]; // Data to use for type inference
|
|
32
34
|
nRows?: number; // Number of rows to use for type inference
|
|
33
35
|
omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.
|
|
34
36
|
includeColumns?: string[]; // Columns to include.
|
|
@@ -38,7 +40,7 @@ export interface DataSheetCoreProps<T> {
|
|
|
38
40
|
data: T[];
|
|
39
41
|
columnSpec?: ColumnSpec[];
|
|
40
42
|
editable?: boolean;
|
|
41
|
-
enableColumnReordering
|
|
43
|
+
enableColumnReordering?: boolean;
|
|
42
44
|
}
|
|
43
45
|
|
|
44
46
|
export interface DataSheetState<T> {
|
|
@@ -47,18 +49,31 @@ export interface DataSheetState<T> {
|
|
|
47
49
|
fillValueBaseCell: FocusedCellCoordinates | null;
|
|
48
50
|
focusedCell: FocusedCellCoordinates | null;
|
|
49
51
|
topLeftCell: FocusedCellCoordinates | null;
|
|
52
|
+
deletedRows: Set<number>;
|
|
53
|
+
// Sparse data structure for updated data
|
|
50
54
|
updatedData: T[];
|
|
51
55
|
initialized: boolean;
|
|
52
56
|
}
|
|
53
57
|
|
|
58
|
+
export interface DataSheetComputedStore {
|
|
59
|
+
hasUpdates: boolean;
|
|
60
|
+
}
|
|
61
|
+
|
|
54
62
|
type DataSheetVals<T> = DataSheetState<T> & DataSheetCoreProps<T>;
|
|
55
63
|
|
|
64
|
+
type StateUpdater<T> = T[] | ((state: T[]) => T[]);
|
|
65
|
+
|
|
56
66
|
export interface DataSheetStore<T> extends DataSheetVals<T> {
|
|
57
67
|
setSelection(selection: Region[]): void;
|
|
58
68
|
onDragValue(cell: FocusedCellCoordinates | null): void;
|
|
59
|
-
setUpdatedData(data: T
|
|
69
|
+
setUpdatedData(data: StateUpdater<T>): void;
|
|
60
70
|
onCellEdited(rowIndex: number, columnName: string, value: any): void;
|
|
71
|
+
onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;
|
|
72
|
+
moveFocusedCell(direction: "up" | "down" | "left" | "right"): void;
|
|
73
|
+
deleteSelectedRows(): void;
|
|
61
74
|
clearSelection(): void;
|
|
75
|
+
resetChanges(): void;
|
|
76
|
+
addRow(): void;
|
|
62
77
|
initialize(props: DataSheetCoreProps<T>): void;
|
|
63
78
|
onSelection(selection: Region[]): void;
|
|
64
79
|
// Internal method used for infinite scrolling
|
|
@@ -69,7 +84,7 @@ export interface DataSheetStore<T> extends DataSheetVals<T> {
|
|
|
69
84
|
|
|
70
85
|
export type DataSheetProviderProps<T> = DataSheetCoreProps<T> & {
|
|
71
86
|
children: React.ReactNode;
|
|
72
|
-
columnSpecOptions?: ColumnSpecOptions
|
|
87
|
+
columnSpecOptions?: ColumnSpecOptions<T>;
|
|
73
88
|
};
|
|
74
89
|
|
|
75
90
|
const DataSheetContext = createContext<StoreApi<DataSheetStore<any>>>(null);
|
|
@@ -79,6 +94,12 @@ export interface VisibleCells {
|
|
|
79
94
|
rowIndexEnd: number;
|
|
80
95
|
}
|
|
81
96
|
|
|
97
|
+
const computed = createComputed(
|
|
98
|
+
(state: DataSheetStore<any>): DataSheetComputedStore => ({
|
|
99
|
+
hasUpdates: state.updatedData.length > 0 || state.deletedRows.size > 0,
|
|
100
|
+
}),
|
|
101
|
+
) as any;
|
|
102
|
+
|
|
82
103
|
export function DataSheetProvider<T>({
|
|
83
104
|
children,
|
|
84
105
|
data,
|
|
@@ -95,108 +116,213 @@ export function DataSheetProvider<T>({
|
|
|
95
116
|
const tableRef = useRef<Table2>(null);
|
|
96
117
|
|
|
97
118
|
const [store] = useState(() => {
|
|
98
|
-
return createStore<DataSheetStore<T>>(
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
+
return createStore<DataSheetStore<T>>(
|
|
120
|
+
computed((set): DataSheetStore<T> => {
|
|
121
|
+
return {
|
|
122
|
+
data,
|
|
123
|
+
columnSpec: columnSpec ?? generateColumnSpec(data, columnSpecOptions),
|
|
124
|
+
editable,
|
|
125
|
+
deletedRows: new Set<number>(),
|
|
126
|
+
selection: [],
|
|
127
|
+
fillValueBaseCell: null,
|
|
128
|
+
updatedData: [],
|
|
129
|
+
focusedCell: null,
|
|
130
|
+
topLeftCell: null,
|
|
131
|
+
initialized: false,
|
|
132
|
+
tableRef,
|
|
133
|
+
// This is a placeholder
|
|
134
|
+
enableColumnReordering: false,
|
|
135
|
+
setSelection(selection: Region[]) {
|
|
136
|
+
set(updateSelection(selection));
|
|
137
|
+
},
|
|
138
|
+
moveFocusedCell(direction: "up" | "down" | "left" | "right") {
|
|
139
|
+
set((state) => {
|
|
140
|
+
const { topLeftCell } = state;
|
|
141
|
+
if (topLeftCell == null) return {};
|
|
142
|
+
let { col, row } = topLeftCell;
|
|
143
|
+
switch (direction) {
|
|
144
|
+
case "up":
|
|
145
|
+
row = Math.max(0, row - 1);
|
|
146
|
+
break;
|
|
147
|
+
case "down":
|
|
148
|
+
row = Math.min(
|
|
149
|
+
row + 1,
|
|
150
|
+
Math.max(state.data.length, state.updatedData.length) - 1,
|
|
151
|
+
);
|
|
152
|
+
break;
|
|
153
|
+
case "left":
|
|
154
|
+
col = Math.max(0, col - 1);
|
|
155
|
+
break;
|
|
156
|
+
case "right":
|
|
157
|
+
col = Math.min(col + 1, state.columnSpec.length - 1);
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
const region: Region = { cols: [col, col], rows: [row, row] };
|
|
161
|
+
return updateSelection([region]);
|
|
162
|
+
});
|
|
163
|
+
},
|
|
164
|
+
addRow(row: Partial<T> = {} as T) {
|
|
165
|
+
/** Add a new row. If there is a selection, use the last row index to determine
|
|
166
|
+
* where to insert the new row. Otherwise, append to the end of the data. */
|
|
119
167
|
set((state) => {
|
|
120
|
-
|
|
168
|
+
const { updatedData, data, selection } = state;
|
|
169
|
+
const lastRowIndex =
|
|
170
|
+
getLastRowIndex(selection) ??
|
|
171
|
+
Math.max(data.length, updatedData.length) - 1;
|
|
172
|
+
// If there is a selection, insert the new row after the last selected row
|
|
173
|
+
const spec: Spec<any> = {
|
|
174
|
+
$splice: [[lastRowIndex + 1, 0, row]],
|
|
175
|
+
};
|
|
176
|
+
console.log(spec);
|
|
177
|
+
|
|
178
|
+
return {
|
|
179
|
+
updatedData: update(updatedData, spec),
|
|
180
|
+
};
|
|
121
181
|
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
// Right now we don't store this in the state
|
|
127
|
-
visibleCellsRef.current = visibleCells;
|
|
128
|
-
},
|
|
129
|
-
onDragValue(cell: FocusedCellCoordinates | null) {
|
|
130
|
-
set({ fillValueBaseCell: cell });
|
|
131
|
-
},
|
|
132
|
-
onCellEdited(rowIndex: number, columnName: string, value: any) {
|
|
133
|
-
set((state) => {
|
|
134
|
-
const { editable, updatedData, data } = state;
|
|
135
|
-
if (!editable) return {};
|
|
136
|
-
let rowSpec: any;
|
|
137
|
-
// Check to see if the new value is the same as the old one
|
|
138
|
-
if (value !== data[rowIndex]?.[columnName]) {
|
|
139
|
-
const rowOp = updatedData[rowIndex] != null ? "$merge" : "$set";
|
|
140
|
-
rowSpec = { [rowOp]: { [columnName]: value } };
|
|
182
|
+
},
|
|
183
|
+
setUpdatedData(data: StateUpdater<T>) {
|
|
184
|
+
if (Array.isArray(data)) {
|
|
185
|
+
set({ updatedData: data });
|
|
141
186
|
} else {
|
|
142
|
-
|
|
187
|
+
set((state) => {
|
|
188
|
+
return { updatedData: data(state.updatedData) };
|
|
189
|
+
});
|
|
143
190
|
}
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
191
|
+
},
|
|
192
|
+
deleteSelectedRows() {
|
|
193
|
+
// Remove selected rows from the data and updatedData arrays
|
|
194
|
+
set((state) => {
|
|
195
|
+
const { selection, deletedRows } = state;
|
|
196
|
+
const rowIndices = getRowIndices(selection);
|
|
197
|
+
|
|
198
|
+
// Delete rows from both updatedData and data
|
|
199
|
+
const newDeletedRows = new Set(deletedRows);
|
|
200
|
+
for (const rowIndex of rowIndices) {
|
|
201
|
+
newDeletedRows.add(rowIndex);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
// Remove selected rows and reset selection
|
|
205
|
+
return {
|
|
206
|
+
deletedRows: newDeletedRows,
|
|
207
|
+
selection: [],
|
|
208
|
+
focusedCell: null,
|
|
209
|
+
topLeftCell: null,
|
|
210
|
+
fillValueBaseCell: null,
|
|
211
|
+
};
|
|
212
|
+
});
|
|
213
|
+
},
|
|
214
|
+
resetChanges() {
|
|
215
|
+
// Reset the updated data to the initial data
|
|
216
|
+
set((state) => ({
|
|
217
|
+
updatedData: [],
|
|
218
|
+
deletedRows: new Set<number>(),
|
|
219
|
+
selection: [],
|
|
220
|
+
focusedCell: null,
|
|
221
|
+
topLeftCell: null,
|
|
222
|
+
fillValueBaseCell: null,
|
|
223
|
+
}));
|
|
224
|
+
},
|
|
225
|
+
setVisibleCells(visibleCells: VisibleCells) {
|
|
226
|
+
// Visible cells are used for infinite scrolling
|
|
227
|
+
// Right now we don't store this in the state
|
|
228
|
+
visibleCellsRef.current = visibleCells;
|
|
229
|
+
},
|
|
230
|
+
onDragValue(cell: FocusedCellCoordinates | null) {
|
|
231
|
+
set({ fillValueBaseCell: cell });
|
|
232
|
+
},
|
|
233
|
+
onCellEdited(rowIndex: number, columnName: string, value: any) {
|
|
234
|
+
set((state) => {
|
|
235
|
+
const { editable, updatedData, data } = state;
|
|
236
|
+
if (!editable) return {};
|
|
237
|
+
let rowSpec: any;
|
|
238
|
+
// Check to see if the new value is the same as the old one
|
|
239
|
+
if (value !== data[rowIndex]?.[columnName]) {
|
|
240
|
+
const rowOp = updatedData[rowIndex] != null ? "$merge" : "$set";
|
|
241
|
+
rowSpec = { [rowOp]: { [columnName]: value } };
|
|
242
|
+
} else {
|
|
243
|
+
rowSpec = { $unset: [columnName] };
|
|
244
|
+
}
|
|
245
|
+
const spec: Spec<T[]> = { [rowIndex]: rowSpec };
|
|
246
|
+
return { updatedData: update(updatedData, spec) };
|
|
247
|
+
});
|
|
248
|
+
},
|
|
249
|
+
initialize(props: DataSheetCoreProps<T>) {
|
|
250
|
+
set({ ...props, initialized: true });
|
|
251
|
+
},
|
|
252
|
+
clearSelection() {
|
|
253
|
+
set((state) => {
|
|
254
|
+
// Delete all selected cells
|
|
255
|
+
const { selection, updatedData, columnSpec, data } = state;
|
|
256
|
+
let spec = {};
|
|
257
|
+
for (const region of selection) {
|
|
258
|
+
const { cols, rows } = region;
|
|
259
|
+
const rowRange = range(rows ?? [0, updatedData.length - 1]);
|
|
260
|
+
const colRange = range(cols ?? [0, columnSpec.length - 1]);
|
|
261
|
+
for (const row of rowRange) {
|
|
262
|
+
let vals = {};
|
|
263
|
+
for (const col of colRange) {
|
|
264
|
+
const key = columnSpec[col].key;
|
|
265
|
+
const currentValue =
|
|
266
|
+
updatedData[row]?.[key] ?? data[row]?.[key];
|
|
267
|
+
if (currentValue != null && currentValue !== "") {
|
|
268
|
+
vals[key] = "";
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
272
|
+
spec[row] = { [op]: vals };
|
|
163
273
|
}
|
|
164
|
-
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
165
|
-
spec[row] = { [op]: vals };
|
|
166
274
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
};
|
|
171
|
-
}
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
275
|
+
return {
|
|
276
|
+
updatedData: update(updatedData, spec),
|
|
277
|
+
};
|
|
278
|
+
});
|
|
279
|
+
},
|
|
280
|
+
onSelection(selection: Region[]) {
|
|
281
|
+
set((state) => {
|
|
282
|
+
if (
|
|
283
|
+
selectionEquals(selection, state.selection) &&
|
|
284
|
+
singleFocusedCell(selection) == null // Only if we're in a multi-cell selection mode
|
|
285
|
+
) {
|
|
286
|
+
// If the selection is the same as the current selection, remove the selection.
|
|
287
|
+
// In practice this only happens for whole-row and whole-column selections
|
|
288
|
+
return {
|
|
289
|
+
selection: [],
|
|
290
|
+
focusedCell: null,
|
|
291
|
+
topLeftCell: null,
|
|
292
|
+
fillValueBaseCell: null,
|
|
293
|
+
};
|
|
294
|
+
}
|
|
295
|
+
|
|
296
|
+
let spec = updateSelection(selection);
|
|
297
|
+
if (state.fillValueBaseCell != null) {
|
|
298
|
+
spec.updatedData = fillValues(state, selection);
|
|
299
|
+
}
|
|
300
|
+
return spec;
|
|
301
|
+
});
|
|
302
|
+
},
|
|
303
|
+
onColumnsReordered(
|
|
304
|
+
oldIndex: number,
|
|
305
|
+
newIndex: number,
|
|
306
|
+
length: number,
|
|
307
|
+
) {
|
|
308
|
+
set((state) => {
|
|
309
|
+
if (!state.enableColumnReordering) return {};
|
|
310
|
+
const { columnSpec } = state;
|
|
311
|
+
const newSpec = [...columnSpec];
|
|
312
|
+
const removed = newSpec.splice(oldIndex, length);
|
|
313
|
+
newSpec.splice(newIndex, 0, ...removed);
|
|
314
|
+
return { columnSpec: newSpec };
|
|
315
|
+
});
|
|
316
|
+
},
|
|
317
|
+
scrollToRow(rowIndex: number) {
|
|
318
|
+
if (tableRef.current == null) return;
|
|
319
|
+
tableRef.current.scrollToRegion({
|
|
320
|
+
rows: [rowIndex, rowIndex],
|
|
321
|
+
});
|
|
322
|
+
},
|
|
323
|
+
};
|
|
324
|
+
}),
|
|
325
|
+
);
|
|
200
326
|
});
|
|
201
327
|
|
|
202
328
|
// Not sure how required this initialization is
|
|
@@ -222,7 +348,7 @@ export function useStoreAPI<T>(): StoreApi<DataSheetStore<T>> {
|
|
|
222
348
|
}
|
|
223
349
|
|
|
224
350
|
export function useSelector<T = any, A = any>(
|
|
225
|
-
selector: (state: DataSheetStore<T>) => A
|
|
351
|
+
selector: (state: DataSheetStore<T> & DataSheetComputedStore) => A,
|
|
226
352
|
): A {
|
|
227
353
|
const store = useStoreAPI<T>();
|
|
228
354
|
return useStore(store, selector);
|
|
@@ -241,9 +367,39 @@ function updateSelection<T>(selection: Region[]) {
|
|
|
241
367
|
return spec;
|
|
242
368
|
}
|
|
243
369
|
|
|
370
|
+
function getLastRowIndex(regions: Region[]): number | null {
|
|
371
|
+
/** Get the last row index from a selection of regions */
|
|
372
|
+
if (regions == null || regions.length === 0) return null;
|
|
373
|
+
let lastRow = -1;
|
|
374
|
+
for (const region of regions) {
|
|
375
|
+
const { rows } = region;
|
|
376
|
+
if (rows == null || rows.length !== 2) continue;
|
|
377
|
+
lastRow = Math.max(lastRow, rows[1]);
|
|
378
|
+
}
|
|
379
|
+
if (lastRow < 0) {
|
|
380
|
+
/** If no valid rows are found, return null */
|
|
381
|
+
return null;
|
|
382
|
+
}
|
|
383
|
+
return lastRow;
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
function getRowIndices(regions: Region[]): number[] {
|
|
387
|
+
/** Get the row indices from a selection of regions */
|
|
388
|
+
if (regions == null || regions.length === 0) return [];
|
|
389
|
+
const rowIndices = new Set<number>();
|
|
390
|
+
for (const region of regions) {
|
|
391
|
+
const { rows } = region;
|
|
392
|
+
if (rows == null || rows.length !== 2) continue;
|
|
393
|
+
for (let i = rows[0]; i <= rows[1]; i++) {
|
|
394
|
+
rowIndices.add(i);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
return Array.from(rowIndices).sort((a, b) => a - b);
|
|
398
|
+
}
|
|
399
|
+
|
|
244
400
|
export function topLeftCell(
|
|
245
401
|
regions: Region[],
|
|
246
|
-
requireSolitaryCell: boolean = false
|
|
402
|
+
requireSolitaryCell: boolean = false,
|
|
247
403
|
): FocusedCellCoordinates | null {
|
|
248
404
|
/** Top left cell of a ranged selection */
|
|
249
405
|
if (regions == null) return null;
|
|
@@ -256,7 +412,36 @@ export function topLeftCell(
|
|
|
256
412
|
return { col: cols[0], row: rows[0], focusSelectionIndex: 0 };
|
|
257
413
|
}
|
|
258
414
|
|
|
259
|
-
function
|
|
415
|
+
function selectionEquals(a: Region[], b: Region[]): boolean {
|
|
416
|
+
/** Check if two selections are equal */
|
|
417
|
+
if (a.length !== b.length) return false;
|
|
418
|
+
for (let i = 0; i < a.length; i++) {
|
|
419
|
+
const regionA = a[i];
|
|
420
|
+
const regionB = b[i];
|
|
421
|
+
|
|
422
|
+
const colsA = regionA.cols ?? [];
|
|
423
|
+
const colsB = regionB.cols ?? [];
|
|
424
|
+
|
|
425
|
+
const rowsA = regionA.rows ?? [];
|
|
426
|
+
const rowsB = regionB.rows ?? [];
|
|
427
|
+
|
|
428
|
+
if (
|
|
429
|
+
colsA.length !== colsB.length ||
|
|
430
|
+
rowsA.length !== rowsB.length ||
|
|
431
|
+
colsA[0] !== colsB[0] ||
|
|
432
|
+
colsA[1] !== colsB[1] ||
|
|
433
|
+
rowsA[0] !== rowsB[0] ||
|
|
434
|
+
rowsA[1] !== rowsB[1]
|
|
435
|
+
) {
|
|
436
|
+
return false;
|
|
437
|
+
}
|
|
438
|
+
}
|
|
439
|
+
return true;
|
|
440
|
+
}
|
|
441
|
+
|
|
442
|
+
export function singleFocusedCell(
|
|
443
|
+
sel: Region[],
|
|
444
|
+
): FocusedCellCoordinates | null {
|
|
260
445
|
/** Derive a single focused cell from a selected region, if possible */
|
|
261
446
|
if (sel?.length !== 1) return null;
|
|
262
447
|
return topLeftCell(sel, true);
|
package/src/utils/column-spec.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { ColumnSpec, ColumnSpecOptions } from "../provider";
|
|
2
|
+
|
|
1
3
|
const defaultRenderers = {
|
|
2
4
|
string: (d) => d,
|
|
3
5
|
number: (d) => d?.toFixed(2),
|
|
@@ -7,12 +9,33 @@ const defaultRenderers = {
|
|
|
7
9
|
array: (d) => d?.join(", "),
|
|
8
10
|
};
|
|
9
11
|
|
|
10
|
-
|
|
12
|
+
interface ColumnSpecGenerateOptions {
|
|
13
|
+
calculateWidths?: boolean;
|
|
14
|
+
defaultWidth?: number;
|
|
15
|
+
getWidthForValue?: (value: any) => number;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
const defaultWidthForValue = (val) => String(val).length * 8;
|
|
19
|
+
|
|
20
|
+
export function generateDefaultColumnSpec<T>(
|
|
21
|
+
data: Array<T>,
|
|
22
|
+
options: ColumnSpecGenerateOptions = {},
|
|
23
|
+
): ColumnSpec[] {
|
|
11
24
|
/** Build a default column spec from a dataset based on the first n rows */
|
|
12
25
|
if (data == null) return [];
|
|
13
26
|
// Get the keys
|
|
14
|
-
|
|
27
|
+
|
|
28
|
+
const {
|
|
29
|
+
defaultWidth = 150,
|
|
30
|
+
calculateWidths = true,
|
|
31
|
+
getWidthForValue = defaultWidthForValue,
|
|
32
|
+
} = options;
|
|
33
|
+
|
|
34
|
+
const keys = new Set<string>();
|
|
15
35
|
const types = new Map();
|
|
36
|
+
|
|
37
|
+
const columnWidths = new Map<string, number>();
|
|
38
|
+
|
|
16
39
|
for (const row of data) {
|
|
17
40
|
if (row == null) continue;
|
|
18
41
|
for (const key of Object.keys(row)) {
|
|
@@ -20,6 +43,14 @@ export function generateDefaultColumnSpec<T>(data: Array<T>): ColumnSpec[] {
|
|
|
20
43
|
keys.add(key);
|
|
21
44
|
|
|
22
45
|
if (val == null) continue;
|
|
46
|
+
|
|
47
|
+
if (calculateWidths) {
|
|
48
|
+
let width = getWidthForValue(val);
|
|
49
|
+
if (width != null && width >= 0) {
|
|
50
|
+
columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
23
54
|
let type: string = typeof val;
|
|
24
55
|
// Special 'type' for integers
|
|
25
56
|
if (Number.isInteger(val)) {
|
|
@@ -54,10 +85,20 @@ export function generateDefaultColumnSpec<T>(data: Array<T>): ColumnSpec[] {
|
|
|
54
85
|
// Build a column spec
|
|
55
86
|
const spec = [];
|
|
56
87
|
for (const key of keys) {
|
|
88
|
+
let width = null;
|
|
89
|
+
if (calculateWidths) {
|
|
90
|
+
// If we are calculating widths, use the value lengths
|
|
91
|
+
width = Math.min(
|
|
92
|
+
Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),
|
|
93
|
+
defaultWidth * 1.5,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
|
|
57
97
|
spec.push({
|
|
58
98
|
name: key,
|
|
59
99
|
key,
|
|
60
100
|
valueRenderer: defaultRenderers[types.get(key)],
|
|
101
|
+
width,
|
|
61
102
|
});
|
|
62
103
|
}
|
|
63
104
|
return spec;
|
|
@@ -65,7 +106,7 @@ export function generateDefaultColumnSpec<T>(data: Array<T>): ColumnSpec[] {
|
|
|
65
106
|
|
|
66
107
|
export function generateColumnSpec<T>(
|
|
67
108
|
data: T[],
|
|
68
|
-
options: ColumnSpecOptions
|
|
109
|
+
options: ColumnSpecOptions<T>,
|
|
69
110
|
): ColumnSpec[] {
|
|
70
111
|
/** Generate a column spec from a dataset */
|
|
71
112
|
const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {useInDarkMode as $iwzwH$useInDarkMode} from "@macrostrat/ui-components";
|
|
2
|
-
import $iwzwH$macrostrathyper from "@macrostrat/hyper";
|
|
3
|
-
import {Tag as $iwzwH$Tag} from "@blueprintjs/core";
|
|
4
|
-
import {asChromaColor as $iwzwH$asChromaColor} from "@macrostrat/color-utils";
|
|
5
|
-
import $iwzwH$classnames from "classnames";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function $753d4a0c461d4588$export$17064b7382e320b2({ data: data, className: className = null }) {
|
|
13
|
-
const darkMode = (0, $iwzwH$useInDarkMode)();
|
|
14
|
-
const luminance = darkMode ? 0.9 : 0.4;
|
|
15
|
-
const color = (0, $iwzwH$asChromaColor)(data.color);
|
|
16
|
-
return (0, $iwzwH$macrostrathyper)((0, $iwzwH$Tag), {
|
|
17
|
-
key: data.id,
|
|
18
|
-
className: (0, $iwzwH$classnames)("lithology-tag", className),
|
|
19
|
-
minimal: true,
|
|
20
|
-
style: {
|
|
21
|
-
color: color?.luminance(luminance).hex(),
|
|
22
|
-
backgroundColor: color?.luminance(1 - luminance).hex()
|
|
23
|
-
}
|
|
24
|
-
}, (0, $iwzwH$macrostrathyper)("span.contents", [
|
|
25
|
-
(0, $iwzwH$macrostrathyper)("span.name", data.name)
|
|
26
|
-
]));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export {$753d4a0c461d4588$export$17064b7382e320b2 as LithologyTag};
|
|
31
|
-
//# sourceMappingURL=cell-renderers.8222e82a.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;AAMO,SAAS,0CAAa,QAAE,IAAI,aAAE,YAAY,MAAM;IACrD,MAAM,WAAW,CAAA,GAAA,oBAAY;IAC7B,MAAM,YAAY,WAAW,MAAM;IACnC,MAAM,QAAQ,CAAA,GAAA,oBAAY,EAAE,KAAK,KAAK;IACtC,OAAO,CAAA,GAAA,sBAAA,EACL,CAAA,GAAA,UAAE,GACF;QACE,KAAK,KAAK,EAAE;QACZ,WAAW,CAAA,GAAA,iBAAS,EAAE,iBAAiB;QACvC,SAAS;QACT,OAAO;YACL,OAAO,OAAO,UAAU,WAAW;YACnC,iBAAiB,OAAO,UAAU,IAAI,WAAW;QACnD;IACF,GACA,CAAA,GAAA,sBAAA,EAAE,iBAAiB;QAAC,CAAA,GAAA,sBAAA,EAAE,aAAa,KAAK,IAAI;KAAE;AAElD","sources":["packages/data-sheet/src/postgrest-table/cell-renderers.ts"],"sourcesContent":["import { useInDarkMode } from \"@macrostrat/ui-components\";\nimport h from \"@macrostrat/hyper\";\nimport { Tag } from \"@blueprintjs/core\";\nimport { asChromaColor } from \"@macrostrat/color-utils\";\nimport classNames from \"classnames\";\n\nexport function LithologyTag({ data, className = null }) {\n const darkMode = useInDarkMode();\n const luminance = darkMode ? 0.9 : 0.4;\n const color = asChromaColor(data.color);\n return h(\n Tag,\n {\n key: data.id,\n className: classNames(\"lithology-tag\", className),\n minimal: true,\n style: {\n color: color?.luminance(luminance).hex(),\n backgroundColor: color?.luminance(1 - luminance).hex(),\n },\n },\n h(\"span.contents\", [h(\"span.name\", data.name)])\n );\n}\n"],"names":[],"version":3,"file":"cell-renderers.8222e82a.js.map"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":";;;;;;;;;;;;;;;;;;;;;;AASA,MAAM,0BAAI,CAAA,GAAA,sBAAI,EAAE,MAAM,CAAC,CAAA,GAAA,sEAAK;AAErB,SAAS,0CAAU,SAAE,KAAK,YAAE,QAAQ,SAAE,KAAK,UAAE,MAAM,EAAE,GAAG,MAAM;IACnE,MAAM,WAAW,CAAA,GAAA,oBAAY;IAE7B,OAAO,wBACL,CAAA,GAAA,WAAG,GACH;QACE,GAAG,IAAI;QACP,OAAO;YACL,GAAG,KAAK;YACR,GAAG,iCAAW,OAAO,SAAS;QAChC;IACF,GACA;AAEJ;AAEA,MAAM,mCAAa,CAAA,GAAA,cAAM,EAAE,CAAC,OAAO,WACjC,0CAAoB,OAAO;kBAAE;IAAS;AAGjC,SAAS,0CACd,KAAK,EACL,aAAE,YAAY,uBAAM,kBAAkB,eAAK,WAAW,OAAO,GAAG,CAAC,CAAC;IAElE,MAAM,WAAW,aAAa,WAAW,MAAM;IAE/C,6BAA6B;IAC7B,QAAQ,CAAA,GAAA,oBAAY,EAAE;IACtB,IAAI,SAAS,MAAM,OAAO,CAAC;IAC3B,OAAO;QACL,OAAO,OAAO,YAAY,UAAU;QACpC,iBAAiB,OAAO,QAAQ,iBAAiB;IACnD;AACF;AAEA,IAAA,AAAK,mEAAA;;;;;WAAA;EAAA;AAOE,SAAS,0CAAY,SAC1B,KAAK,YACL,QAAQ,QACR,cACD;IACC,MAAM,MAAM,CAAA,GAAA,aAAK,EAAE;IACnB,CAAA,GAAA,gBAAQ,EAAE;QACR,IAAI,IAAI,OAAO,IAAI,MAAM;QACzB,IAAI,OAAO,CAAC,KAAK;IACnB,GAAG,EAAE;IAEL,IAAI;IACJ,IAAI;QACF,QAAQ,CAAA,GAAA,oBAAY,EAAE,OAAO,GAAG;IAClC,EAAE,OAAM;QACN,QAAQ;IACV;IACA,OAAO,wBACL,8BACA;QACE,WAAU,GAAG;YACX,QAAQ,GAAG,CAAC;YACZ,IAAI,IAAI,GAAG,KAAK,UACd,IAAI,cAAc;QAEtB;aACA;QACA,UAAU;IACZ,GACA,wBAAE,CAAA,GAAA,qBAAa,GAAG;eAChB;QACA,UAAS,KAAK;YACZ,SAAS,CAAA,GAAA,oBAAY,EAAE,MAAM,CAAC,KAAK;QACrC;IACF;AAEJ","sources":["packages/data-sheet/src/components/colors.ts"],"sourcesContent":["import { Cell } from \"@blueprintjs/table\";\nimport { useInDarkMode } from \"@macrostrat/ui-components\";\nimport hyper from \"@macrostrat/hyper\";\nimport styles from \"./main.module.sass\";\nimport { asChromaColor } from \"@macrostrat/color-utils\";\nimport { HexColorPicker } from \"react-colorful\";\nimport { useEffect, useRef } from \"react\";\nimport { memoize } from \"underscore\";\n\nconst h = hyper.styled(styles);\n\nexport function ColorCell({ value, children, style, intent, ...rest }) {\n const darkMode = useInDarkMode();\n\n return h(\n Cell,\n {\n ...rest,\n style: {\n ...style,\n ...colorCombo(value, darkMode),\n },\n },\n children\n );\n}\n\nconst colorCombo = memoize((color, darkMode) =>\n pleasantCombination(color, { darkMode })\n);\n\nexport function pleasantCombination(\n color,\n { luminance = null, backgroundAlpha = 0.2, darkMode = false } = {}\n) {\n const brighten = luminance ?? darkMode ? 0.5 : 0.1;\n\n // Check if is a chroma color\n color = asChromaColor(color);\n if (color == null) return {};\n return {\n color: color?.luminance?.(brighten).css(),\n backgroundColor: color?.alpha?.(backgroundAlpha).css(),\n };\n}\n\nenum ColorConversionType {\n HEX = \"hex\",\n RGB = \"rgb\",\n HSL = \"hsl\",\n CSS = \"css\",\n}\n\nexport function ColorPicker({\n value,\n onChange,\n type = ColorConversionType.CSS,\n}) {\n const ref = useRef(null);\n useEffect(() => {\n if (ref.current == null) return;\n ref.current.focus();\n }, []);\n\n let color: any;\n try {\n color = asChromaColor(value).hex();\n } catch {\n color = \"#aaaaaa\";\n }\n return h(\n \"div.color-picker-container\",\n {\n onKeyDown(evt) {\n console.log(evt);\n if (evt.key === \"Escape\") {\n evt.preventDefault();\n }\n },\n ref,\n tabIndex: 0,\n },\n h(HexColorPicker, {\n color,\n onChange(color) {\n onChange(asChromaColor(color)[type]());\n },\n })\n );\n}\n"],"names":[],"version":3,"file":"colors.75a92ad3.js.map"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"AAAA,MAAM,yCAAmB;IACvB,QAAQ,CAAC,IAAM;IACf,QAAQ,CAAC,IAAM,GAAG,QAAQ;IAC1B,SAAS,CAAC,IAAO,IAAI,MAAM;IAC3B,QAAQ,CAAC,IAAM,KAAK,SAAS,CAAC;IAC9B,SAAS,CAAC,IAAM,GAAG,QAAQ;IAC3B,OAAO,CAAC,IAAM,GAAG,KAAK;AACxB;AAEO,SAAS,0CAA6B,IAAc;IACzD,yEAAyE,GACzE,IAAI,QAAQ,MAAM,OAAO,EAAE;IAC3B,eAAe;IACf,MAAM,OAAO,IAAI;IACjB,MAAM,QAAQ,IAAI;IAClB,KAAK,MAAM,OAAO,KAAM;QACtB,IAAI,OAAO,MAAM;QACjB,KAAK,MAAM,OAAO,OAAO,IAAI,CAAC,KAAM;YAClC,MAAM,MAAM,GAAG,CAAC,IAAI;YACpB,KAAK,GAAG,CAAC;YAET,IAAI,OAAO,MAAM;YACjB,IAAI,OAAe,OAAO;YAC1B,8BAA8B;YAC9B,IAAI,OAAO,SAAS,CAAC,MACnB,OAAO;YAGT,6CAA6C;YAC7C,IACE,MAAM,OAAO,CAAC,QACd,IAAI,KAAK,CAAC,CAAC,IAAM,OAAO,MAAM,YAAY,OAAO,MAAM,WAEvD,OAAO;YAGT,IAAI,MAAM,GAAG,CAAC,MACZ;gBAAA,IAAI,MAAM,GAAG,CAAC,SAAS,MAAM;oBAC3B,IAAI,SAAS,YAAY,MAAM,GAAG,CAAC,SAAS,WAC1C,MAAM,GAAG,CAAC,KAAK;oBAEjB,IAAI,SAAS,YAAY,MAAM,GAAG,CAAC,SAAS,SAC1C,MAAM,GAAG,CAAC,KAAK;oBAGjB,MAAM,GAAG,CAAC,KAAK;gBACjB;YAAA,OAEA,MAAM,GAAG,CAAC,KAAK;QAEnB;IACF;IAEA,sBAAsB;IACtB,MAAM,OAAO,EAAE;IACf,KAAK,MAAM,OAAO,KAChB,KAAK,IAAI,CAAC;QACR,MAAM;aACN;QACA,eAAe,sCAAgB,CAAC,MAAM,GAAG,CAAC,KAAK;IACjD;IAEF,OAAO;AACT;AAEO,SAAS,0CACd,IAAS,EACT,OAA0B;IAE1B,0CAA0C,GAC1C,MAAM,aAAE,YAAY,CAAC,UAAG,QAAQ,iBAAI,WAAW,kBAAE,cAAc,EAAE,GAAG;IAEpE,IAAI,QAAQ,MAAM,OAAO,EAAE;IAE3B,MAAM,SAAS,KAAK,GAAG,CAAC,OAAO,KAAK,MAAM;IAE1C,IAAI,aAAa,0CAA0B,KAAK,KAAK,CAAC,GAAG;IACzD,IAAI,eAAe,WAAW,MAAM,CAAC,CAAC;QACpC,IAAI,eAAe,QAAQ,YAAY,QAAQ,CAAC,IAAI,GAAG,GACrD,OAAO;QAET,IAAI,kBAAkB,QAAQ,CAAC,eAAe,QAAQ,CAAC,IAAI,GAAG,GAC5D,OAAO;QAET,OAAO;IACT;IAEA,kBAAkB;IAClB,OAAO,aAAa,GAAG,CAAC,CAAC;QACvB,IAAI,MAAM,SAAS,CAAC,IAAI,GAAG,CAAC;QAC5B,IAAI,OAAO,MAAM,OAAO;QACxB,IAAI,OAAO,QAAQ,UACjB,OAAO;YAAE,GAAG,GAAG;YAAE,MAAM;QAAI;QAE7B,OAAO;YAAE,GAAG,GAAG;YAAE,GAAG,GAAG;QAAC;IAC1B;AACF","sources":["packages/data-sheet/src/utils/column-spec.ts"],"sourcesContent":["const defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\nexport function generateDefaultColumnSpec<T>(data: Array<T>): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n const keys = new Set();\n const types = new Map();\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec = [];\n for (const key of keys) {\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: ColumnSpecOptions\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const { overrides = {}, nRows = 10, omitColumns, includeColumns } = options;\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n return filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n}\n"],"names":[],"version":3,"file":"column-spec.e56f4d75.js.map"}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {EditorPopup as $88e63ff6e4eea209$export$2a7e60c8443c1751} from "./editor-popup.819ce365.js";
|
|
2
|
-
import {ColorCell as $423bf54b4879ebeb$export$24aecfe8a925020d, pleasantCombination as $423bf54b4879ebeb$export$ba6491245befce5c, ColorPicker as $423bf54b4879ebeb$export$9feb1bc2e5f1ccb3} from "./colors.75a92ad3.js";
|
|
3
|
-
import {EditableTextArea as $0aa421c11d2af971$export$b8e68c321a6269f1, handleSpecialKeys as $0aa421c11d2af971$export$52c8c5a1aad17e2a} from "./text-areas.ccfcf204.js";
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
export {$88e63ff6e4eea209$export$2a7e60c8443c1751 as EditorPopup, $423bf54b4879ebeb$export$24aecfe8a925020d as ColorCell, $423bf54b4879ebeb$export$ba6491245befce5c as pleasantCombination, $423bf54b4879ebeb$export$9feb1bc2e5f1ccb3 as ColorPicker, $0aa421c11d2af971$export$b8e68c321a6269f1 as EditableTextArea, $0aa421c11d2af971$export$52c8c5a1aad17e2a as handleSpecialKeys};
|
|
11
|
-
//# sourceMappingURL=components.f832ecf3.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"mappings":"","sources":["packages/data-sheet/src/components/index.ts"],"sourcesContent":["export * from \"./editor-popup\";\nexport * from \"./colors\";\nexport * from \"./text-areas\";\n"],"names":[],"version":3,"file":"components.f832ecf3.js.map"}
|