@macrostrat/data-sheet 2.2.0 → 2.2.2
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 +8 -0
- package/dist/esm/data-sheet.410c5122.js.map +1 -1
- package/dist/esm/{data-sheet.b4098761.js → data-sheet.45e8d3b0.js} +2 -2
- package/dist/esm/data-sheet.45e8d3b0.js.map +1 -0
- package/dist/esm/{data-sheet.e09e2546.js → data-sheet.a0d5d18d.js} +7 -6
- package/dist/esm/data-sheet.a0d5d18d.js.map +1 -0
- package/dist/esm/data-sheet.ae6daf58.js +14 -0
- package/dist/esm/data-sheet.ae6daf58.js.map +1 -0
- package/dist/esm/{data-sheet.2521a9d7.js → data-sheet.ce24dcf9.js} +4 -4
- package/dist/esm/data-sheet.ce24dcf9.js.map +1 -0
- package/dist/esm/index.d.ts +14 -3
- package/dist/esm/index.d.ts.map +1 -1
- package/dist/esm/index.js +6 -4
- package/dist/esm/index.js.map +1 -1
- package/dist/node/data-sheet.4a8fd8a7.js +2 -0
- package/dist/node/data-sheet.4a8fd8a7.js.map +1 -0
- package/dist/node/data-sheet.bb45401c.js +2 -0
- package/dist/node/data-sheet.bb45401c.js.map +1 -0
- package/dist/node/data-sheet.bfbba3fc.js +2 -0
- package/dist/node/data-sheet.bfbba3fc.js.map +1 -0
- package/dist/node/{data-sheet.22cde343.js → data-sheet.d40ac2ae.js} +2 -2
- package/dist/node/data-sheet.d40ac2ae.js.map +1 -0
- package/dist/node/{data-sheet.52753d1d.js → data-sheet.f3404ed5.js} +2 -2
- package/dist/node/{data-sheet.52753d1d.js.map → data-sheet.f3404ed5.js.map} +1 -1
- package/dist/node/index.js +1 -1
- package/dist/node/index.js.map +1 -1
- package/package.json +4 -4
- package/src/core.ts +2 -2
- package/src/index.ts +1 -0
- package/src/postgrest-table/index.ts +19 -15
- package/src/provider.ts +6 -27
- package/src/utils/column-spec.ts +25 -1
- package/src/utils/index.ts +1 -1
- package/dist/esm/data-sheet.0adfe599.js +0 -14
- package/dist/esm/data-sheet.0adfe599.js.map +0 -1
- package/dist/esm/data-sheet.2521a9d7.js.map +0 -1
- package/dist/esm/data-sheet.b4098761.js.map +0 -1
- package/dist/esm/data-sheet.e09e2546.js.map +0 -1
- package/dist/node/data-sheet.22cde343.js.map +0 -1
- package/dist/node/data-sheet.50d0742f.js +0 -2
- package/dist/node/data-sheet.50d0742f.js.map +0 -1
- package/dist/node/data-sheet.7bbad640.js +0 -2
- package/dist/node/data-sheet.7bbad640.js.map +0 -1
- package/dist/node/data-sheet.820e5bc3.js +0 -2
- package/dist/node/data-sheet.820e5bc3.js.map +0 -1
- package/src/__archive/base.ts +0 -55
- package/src/__archive/components/column-utils.ts +0 -126
- package/src/__archive/components/index.ts +0 -115
- package/src/__archive/components/toolbar.ts +0 -79
- package/src/__archive/editors/index.ts +0 -78
- package/src/__archive/editors/styles.module.scss +0 -10
- package/src/__archive/enhancers.ts +0 -36
- package/src/__archive/index.ts +0 -8
- package/src/__archive/main.ts +0 -180
- package/src/__archive/provider.ts +0 -179
- package/src/__archive/styles.module.scss +0 -56
- package/src/__archive/test-sheet/attitude-sheet.old.styl +0 -53
- package/src/__archive/test-sheet/attitude-sheet.scss +0 -60
- package/src/__archive/test-sheet/index.ts +0 -210
- package/src/__archive/virtualized.ts +0 -82
|
@@ -1,210 +0,0 @@
|
|
|
1
|
-
import h from "@macrostrat/hyper";
|
|
2
|
-
import ReactDataSheet from "react-datasheet";
|
|
3
|
-
import "react-datasheet/lib/react-datasheet.css";
|
|
4
|
-
import update, { Spec } from "immutability-helper";
|
|
5
|
-
import { Button, ButtonGroup } from "@blueprintjs/core";
|
|
6
|
-
import { ErrorBoundary } from "@macrostrat/ui-components";
|
|
7
|
-
import "./attitude-sheet.scss";
|
|
8
|
-
import { ColorEditor } from "../editors";
|
|
9
|
-
|
|
10
|
-
//import classNames from "classnames";
|
|
11
|
-
|
|
12
|
-
type OrientationRow = Partial<Orientation> | null;
|
|
13
|
-
type OrientationData = OrientationRow[];
|
|
14
|
-
|
|
15
|
-
class OrientationDataSheet extends ReactDataSheet<GridElement, number> {}
|
|
16
|
-
type SheetContent = GridElement[][];
|
|
17
|
-
|
|
18
|
-
export interface Field<Key> {
|
|
19
|
-
name: string;
|
|
20
|
-
key: Key;
|
|
21
|
-
required?: boolean;
|
|
22
|
-
isValid?(k: any): boolean;
|
|
23
|
-
transform?(k: any): any;
|
|
24
|
-
dataEditor?: ReactDataSheet.DataEditor<ReactDataSheet.Cell<any, any>>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
type OrientationKey =
|
|
28
|
-
| "strike"
|
|
29
|
-
| "dip"
|
|
30
|
-
| "rake"
|
|
31
|
-
| "maxError"
|
|
32
|
-
| "minError"
|
|
33
|
-
| "color";
|
|
34
|
-
|
|
35
|
-
export const orientationFields: Field<OrientationKey>[] = [
|
|
36
|
-
{ name: "Strike", key: "strike" },
|
|
37
|
-
{ name: "Dip", key: "dip" },
|
|
38
|
-
{ name: "Rake", key: "rake" },
|
|
39
|
-
{ name: "Max.", key: "maxError", category: "Errors" },
|
|
40
|
-
{ name: "Min.", key: "minError", category: "Errors" },
|
|
41
|
-
{
|
|
42
|
-
name: "Color",
|
|
43
|
-
key: "color",
|
|
44
|
-
required: false,
|
|
45
|
-
isValid: (d) => true, //getColor(d) != null,
|
|
46
|
-
transform: (d) => d,
|
|
47
|
-
dataEditor: ColorEditor,
|
|
48
|
-
},
|
|
49
|
-
];
|
|
50
|
-
|
|
51
|
-
export function addEmptyRows(
|
|
52
|
-
data: SheetContent,
|
|
53
|
-
modulus: number = 10,
|
|
54
|
-
targetN = 0,
|
|
55
|
-
): SheetContent {
|
|
56
|
-
const nToAdd =
|
|
57
|
-
Math.ceil((data.length + targetN) / modulus) * modulus - data.length;
|
|
58
|
-
if (nToAdd <= 0) return data;
|
|
59
|
-
const emptyData = Array(orientationFields.length).fill({ value: null });
|
|
60
|
-
const addedRows = Array(nToAdd).fill(emptyData);
|
|
61
|
-
return [...data, ...addedRows];
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
function Columns() {
|
|
65
|
-
return h("colgroup", [
|
|
66
|
-
h("col.index-column", { key: "index" }),
|
|
67
|
-
orientationFields.map(({ key }) => {
|
|
68
|
-
return h("col", {
|
|
69
|
-
className: key,
|
|
70
|
-
key,
|
|
71
|
-
});
|
|
72
|
-
}),
|
|
73
|
-
]);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
function Row(props) {
|
|
77
|
-
const { children, row } = props;
|
|
78
|
-
return h("tr", [h("td.index-cell.cell.read-only.index", row + 1), children]);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
function Header() {
|
|
82
|
-
return h("thead", [
|
|
83
|
-
h("tr.header", [
|
|
84
|
-
h("td.index-column.cell.read-only", ""),
|
|
85
|
-
orientationFields.map((col, index) => {
|
|
86
|
-
return h(
|
|
87
|
-
"td.cell.header.read-only.header-cell",
|
|
88
|
-
{
|
|
89
|
-
key: col.key,
|
|
90
|
-
index,
|
|
91
|
-
},
|
|
92
|
-
col.name,
|
|
93
|
-
);
|
|
94
|
-
}),
|
|
95
|
-
]),
|
|
96
|
-
]);
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function Sheet({ className, children }) {
|
|
100
|
-
return h("table", { className }, [
|
|
101
|
-
h(Columns),
|
|
102
|
-
h(Header),
|
|
103
|
-
h("tbody", children),
|
|
104
|
-
]);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
export function getFieldData<K>(field: Field<K>): Field<K> {
|
|
108
|
-
const {
|
|
109
|
-
transform = (d) => parseFloat(d),
|
|
110
|
-
isValid = (d) => !isNaN(d),
|
|
111
|
-
required = true,
|
|
112
|
-
...rest
|
|
113
|
-
} = field;
|
|
114
|
-
return { ...rest, transform, isValid, required };
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
function Controls({ data, updateData, resetData }) {
|
|
118
|
-
return h("div.controls", [
|
|
119
|
-
h(ButtonGroup, [
|
|
120
|
-
h(
|
|
121
|
-
Button,
|
|
122
|
-
{
|
|
123
|
-
onClick() {
|
|
124
|
-
updateData(addEmptyRows(data, 10, 10));
|
|
125
|
-
},
|
|
126
|
-
},
|
|
127
|
-
"Add more rows",
|
|
128
|
-
),
|
|
129
|
-
h(
|
|
130
|
-
Button,
|
|
131
|
-
{
|
|
132
|
-
onClick: resetData,
|
|
133
|
-
},
|
|
134
|
-
"Reset data",
|
|
135
|
-
),
|
|
136
|
-
]),
|
|
137
|
-
]);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
function enhanceData(row: GridElement[]): any[] {
|
|
141
|
-
if (row == null) return [];
|
|
142
|
-
return row.map((cellData, i) => {
|
|
143
|
-
const { dataEditor, key } = getFieldData(orientationFields[i]);
|
|
144
|
-
|
|
145
|
-
let addedProps = {};
|
|
146
|
-
// if (key == "color") {
|
|
147
|
-
// addedProps.valueViewer = cell =>
|
|
148
|
-
// h(
|
|
149
|
-
// "span.value-viewer",
|
|
150
|
-
// { style: { color: getColor(cell.value), bacbac } },
|
|
151
|
-
// cell.value
|
|
152
|
-
// );
|
|
153
|
-
// }
|
|
154
|
-
|
|
155
|
-
return { dataEditor, ...cellData, ...addedProps };
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
function finalizeRow(row: GridElement[]) {
|
|
160
|
-
// Validation function to ensure that max angular error is always greater than min angular error
|
|
161
|
-
if (parseFloat(row[3]?.value) < parseFloat(row[4]?.value)) {
|
|
162
|
-
console.log("Row has errors");
|
|
163
|
-
let newRow = [...row];
|
|
164
|
-
newRow[3] = row[4];
|
|
165
|
-
newRow[4] = row[3];
|
|
166
|
-
return newRow;
|
|
167
|
-
}
|
|
168
|
-
return row;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
function DataSheet({ data, updateData }) {
|
|
172
|
-
return h(ReactDataSheet, {
|
|
173
|
-
data: data.map(enhanceData),
|
|
174
|
-
valueRenderer: (cell, row, col) => {
|
|
175
|
-
return cell.value;
|
|
176
|
-
},
|
|
177
|
-
rowRenderer: Row,
|
|
178
|
-
sheetRenderer: Sheet,
|
|
179
|
-
attributesRenderer(cell, row, col) {
|
|
180
|
-
if (cell.value == null || cell.value == "")
|
|
181
|
-
return { "data-status": "empty" };
|
|
182
|
-
const { isValid } = getFieldData(orientationFields[col]);
|
|
183
|
-
const status = isValid(cell.value) ? "ok" : "invalid";
|
|
184
|
-
return { "data-status": status };
|
|
185
|
-
},
|
|
186
|
-
onContextMenu: (...args) => {
|
|
187
|
-
console.log("Context menu");
|
|
188
|
-
console.log(args);
|
|
189
|
-
},
|
|
190
|
-
onCellsChanged: (changes) => {
|
|
191
|
-
let spec: Spec<SheetContent> = {};
|
|
192
|
-
changes.forEach(({ cell, row, col, value }) => {
|
|
193
|
-
if (!(row in spec)) spec[row] = {};
|
|
194
|
-
spec[row][col] = { $set: { value } };
|
|
195
|
-
});
|
|
196
|
-
updateData(update(data, spec).map(finalizeRow));
|
|
197
|
-
},
|
|
198
|
-
});
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export function DataArea({ data, updateData, resetData }) {
|
|
202
|
-
return h("div.data-area", [
|
|
203
|
-
h(
|
|
204
|
-
ErrorBoundary,
|
|
205
|
-
null,
|
|
206
|
-
h(DataSheet, { data, updateData, style: { width: 800 } }),
|
|
207
|
-
),
|
|
208
|
-
h(Controls, { data, updateData, resetData }),
|
|
209
|
-
]);
|
|
210
|
-
}
|
|
@@ -1,82 +0,0 @@
|
|
|
1
|
-
import ReactDataSheet, { DataEditor } from "react-datasheet/lib";
|
|
2
|
-
import { useDataSheet } from "./provider";
|
|
3
|
-
import { hyperStyled } from "@macrostrat/hyper";
|
|
4
|
-
import { useRef, useEffect } from "react";
|
|
5
|
-
import { useScrollOffset } from "@macrostrat/ui-components";
|
|
6
|
-
import { BaseSheet } from "./base";
|
|
7
|
-
import styles from "./styles.module.scss";
|
|
8
|
-
|
|
9
|
-
const h = hyperStyled(styles);
|
|
10
|
-
|
|
11
|
-
function VirtualizedDataEditor({ row, ...rest }) {
|
|
12
|
-
const { rowOffset } = useDataSheet();
|
|
13
|
-
return h(DataEditor, {
|
|
14
|
-
row: row + rowOffset,
|
|
15
|
-
...rest,
|
|
16
|
-
});
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
type OptionalSelection = ReactDataSheet.Selection | null;
|
|
20
|
-
|
|
21
|
-
function offsetSelection(
|
|
22
|
-
sel: OptionalSelection,
|
|
23
|
-
offset: number,
|
|
24
|
-
): OptionalSelection {
|
|
25
|
-
if (sel == null) return null;
|
|
26
|
-
const { start, end } = sel;
|
|
27
|
-
return {
|
|
28
|
-
start: { i: start.i + offset, j: start.j },
|
|
29
|
-
end: { i: end.i + offset, j: end.j },
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
function VirtualizedSheet(props) {
|
|
34
|
-
const {
|
|
35
|
-
data,
|
|
36
|
-
dataEditor,
|
|
37
|
-
onCellsChanged,
|
|
38
|
-
scrollBuffer = 50,
|
|
39
|
-
height,
|
|
40
|
-
width,
|
|
41
|
-
...rest
|
|
42
|
-
} = props;
|
|
43
|
-
|
|
44
|
-
const { rowHeight, selection, dispatch } = useDataSheet();
|
|
45
|
-
|
|
46
|
-
const ref = useRef<HTMLDivElement>();
|
|
47
|
-
|
|
48
|
-
const scrollOffset = useScrollOffset(ref);
|
|
49
|
-
const scrollerHeight = data.length * rowHeight;
|
|
50
|
-
const percentage = scrollOffset / scrollerHeight;
|
|
51
|
-
const rowsToDisplay = Math.ceil((height + scrollBuffer) / rowHeight);
|
|
52
|
-
const rowOffset = Math.floor(percentage * (data.length - rowsToDisplay + 5));
|
|
53
|
-
|
|
54
|
-
useEffect(() => {
|
|
55
|
-
dispatch({ type: "set-row-offset", value: rowOffset });
|
|
56
|
-
}, [rowOffset]);
|
|
57
|
-
|
|
58
|
-
const lastRow = Math.min(rowOffset + rowsToDisplay, data.length - 1);
|
|
59
|
-
|
|
60
|
-
return h(
|
|
61
|
-
BaseSheet,
|
|
62
|
-
{
|
|
63
|
-
ref,
|
|
64
|
-
height,
|
|
65
|
-
width,
|
|
66
|
-
className: "virtualized-sheet",
|
|
67
|
-
...rest,
|
|
68
|
-
data: data.slice(rowOffset, lastRow),
|
|
69
|
-
selected: offsetSelection(selection, -rowOffset),
|
|
70
|
-
dataEditor: VirtualizedDataEditor,
|
|
71
|
-
onCellsChanged(changes) {
|
|
72
|
-
changes.forEach((d) => (d.row += rowOffset));
|
|
73
|
-
onCellsChanged?.(changes);
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
h("div.scroll-panel", {
|
|
77
|
-
style: { height: scrollerHeight },
|
|
78
|
-
}),
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
export { VirtualizedSheet, VirtualizedDataEditor, offsetSelection };
|