@macrostrat/data-sheet 2.2.1 → 2.2.3

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.
Files changed (96) hide show
  1. package/CHANGELOG.md +10 -0
  2. package/dist/esm/{data-sheet.e09e2546.js → data-sheet.00353511.js} +9 -8
  3. package/dist/esm/data-sheet.00353511.js.map +1 -0
  4. package/dist/esm/data-sheet.186dcac8.js +86 -0
  5. package/dist/esm/data-sheet.186dcac8.js.map +1 -0
  6. package/dist/esm/data-sheet.410c5122.js.map +1 -1
  7. package/dist/esm/{data-sheet.1d6ac6c6.js → data-sheet.6776e250.js} +11 -23
  8. package/dist/esm/data-sheet.6776e250.js.map +1 -0
  9. package/dist/esm/data-sheet.8dbfccef.js +16 -0
  10. package/dist/esm/data-sheet.8dbfccef.js.map +1 -0
  11. package/dist/esm/{data-sheet.b5946d6b.js → data-sheet.96446cae.js} +5 -26
  12. package/dist/esm/data-sheet.96446cae.js.map +1 -0
  13. package/dist/esm/{data-sheet.ce2a3218.js → data-sheet.9b593da4.js} +4 -4
  14. package/dist/esm/{data-sheet.ce2a3218.js.map → data-sheet.9b593da4.js.map} +1 -1
  15. package/dist/esm/{data-sheet.2521a9d7.js → data-sheet.ba9a1241.js} +101 -125
  16. package/dist/esm/data-sheet.ba9a1241.js.map +1 -0
  17. package/dist/esm/{data-sheet.b4098761.js → data-sheet.c9b6b6f2.js} +66 -8
  18. package/dist/esm/data-sheet.c9b6b6f2.js.map +1 -0
  19. package/dist/esm/{data-sheet.aa2b4902.js → data-sheet.d2160988.js} +2 -1
  20. package/dist/esm/data-sheet.d2160988.js.map +1 -0
  21. package/dist/esm/index.d.ts +67 -40
  22. package/dist/esm/index.d.ts.map +1 -1
  23. package/dist/esm/index.js +7 -5
  24. package/dist/esm/index.js.map +1 -1
  25. package/dist/node/{data-sheet.22cde343.js → data-sheet.2a613259.js} +2 -2
  26. package/dist/node/data-sheet.2a613259.js.map +1 -0
  27. package/dist/node/{data-sheet.846d5f8f.js → data-sheet.648db7af.js} +2 -2
  28. package/dist/node/data-sheet.648db7af.js.map +1 -0
  29. package/dist/node/data-sheet.6a663031.js +2 -0
  30. package/dist/node/data-sheet.6a663031.js.map +1 -0
  31. package/dist/node/data-sheet.809cdb29.js +2 -0
  32. package/dist/node/data-sheet.809cdb29.js.map +1 -0
  33. package/dist/node/data-sheet.97ac1b50.js +2 -0
  34. package/dist/node/data-sheet.97ac1b50.js.map +1 -0
  35. package/dist/node/data-sheet.ae543670.js +2 -0
  36. package/dist/node/data-sheet.ae543670.js.map +1 -0
  37. package/dist/node/data-sheet.bb45401c.js +2 -0
  38. package/dist/node/data-sheet.bb45401c.js.map +1 -0
  39. package/dist/node/data-sheet.c350336f.js +2 -0
  40. package/dist/node/data-sheet.c350336f.js.map +1 -0
  41. package/dist/node/data-sheet.d971095a.js +2 -0
  42. package/dist/node/data-sheet.d971095a.js.map +1 -0
  43. package/dist/node/data-sheet.dffdda71.js +2 -0
  44. package/dist/node/data-sheet.dffdda71.js.map +1 -0
  45. package/dist/node/index.js +1 -1
  46. package/dist/node/index.js.map +1 -1
  47. package/package.json +2 -2
  48. package/src/components/editor-popup.ts +11 -24
  49. package/src/components/text-areas.ts +2 -43
  50. package/src/core.ts +132 -148
  51. package/src/index.ts +1 -0
  52. package/src/postgrest-table/data-loaders.ts +1 -0
  53. package/src/postgrest-table/index.ts +16 -13
  54. package/src/provider.ts +87 -35
  55. package/src/utils/column-spec.ts +25 -1
  56. package/src/utils/index.ts +2 -1
  57. package/src/utils/key-handling.ts +132 -0
  58. package/dist/esm/data-sheet.0adfe599.js +0 -14
  59. package/dist/esm/data-sheet.0adfe599.js.map +0 -1
  60. package/dist/esm/data-sheet.1d6ac6c6.js.map +0 -1
  61. package/dist/esm/data-sheet.2521a9d7.js.map +0 -1
  62. package/dist/esm/data-sheet.aa2b4902.js.map +0 -1
  63. package/dist/esm/data-sheet.b4098761.js.map +0 -1
  64. package/dist/esm/data-sheet.b5946d6b.js.map +0 -1
  65. package/dist/esm/data-sheet.e09e2546.js.map +0 -1
  66. package/dist/node/data-sheet.1a487c3c.js +0 -2
  67. package/dist/node/data-sheet.1a487c3c.js.map +0 -1
  68. package/dist/node/data-sheet.22cde343.js.map +0 -1
  69. package/dist/node/data-sheet.50d0742f.js +0 -2
  70. package/dist/node/data-sheet.50d0742f.js.map +0 -1
  71. package/dist/node/data-sheet.52753d1d.js +0 -2
  72. package/dist/node/data-sheet.52753d1d.js.map +0 -1
  73. package/dist/node/data-sheet.7bbad640.js +0 -2
  74. package/dist/node/data-sheet.7bbad640.js.map +0 -1
  75. package/dist/node/data-sheet.820e5bc3.js +0 -2
  76. package/dist/node/data-sheet.820e5bc3.js.map +0 -1
  77. package/dist/node/data-sheet.846d5f8f.js.map +0 -1
  78. package/dist/node/data-sheet.86550c41.js +0 -2
  79. package/dist/node/data-sheet.86550c41.js.map +0 -1
  80. package/dist/node/data-sheet.a65463ef.js +0 -2
  81. package/dist/node/data-sheet.a65463ef.js.map +0 -1
  82. package/src/__archive/base.ts +0 -56
  83. package/src/__archive/components/column-utils.ts +0 -126
  84. package/src/__archive/components/index.ts +0 -115
  85. package/src/__archive/components/toolbar.ts +0 -79
  86. package/src/__archive/editors/index.ts +0 -78
  87. package/src/__archive/editors/styles.module.scss +0 -10
  88. package/src/__archive/enhancers.ts +0 -36
  89. package/src/__archive/index.ts +0 -8
  90. package/src/__archive/main.ts +0 -180
  91. package/src/__archive/provider.ts +0 -179
  92. package/src/__archive/styles.module.scss +0 -56
  93. package/src/__archive/test-sheet/attitude-sheet.old.styl +0 -53
  94. package/src/__archive/test-sheet/attitude-sheet.scss +0 -60
  95. package/src/__archive/test-sheet/index.ts +0 -210
  96. package/src/__archive/virtualized.ts +0 -82
@@ -1,179 +0,0 @@
1
- import React, {
2
- createContext,
3
- useReducer,
4
- useContext,
5
- Dispatch,
6
- useEffect,
7
- } from "react";
8
- import h, { compose, C } from "@macrostrat/hyper";
9
- import { DndProvider } from "react-dnd";
10
- import { HTML5Backend } from "react-dnd-html5-backend";
11
- import update from "immutability-helper";
12
- import ReactDataSheet from "react-datasheet";
13
- import { offsetSelection } from "./virtualized";
14
- import { ColumnData, apportionWidths } from "./components/column-utils";
15
-
16
- const defaultContext = {
17
- columns: [],
18
- rowHeight: 20,
19
- containerWidth: 500,
20
- rowOffset: 0,
21
- actions: null,
22
- selection: null,
23
- columnWidths: {},
24
- dispatch: () => {},
25
- virtualized: false,
26
- };
27
-
28
- type ColumnInfo = {
29
- name: string;
30
- width: number | null;
31
- };
32
-
33
- type WidthSpec = {
34
- [key: string]: number;
35
- };
36
-
37
- interface DataSheetState {
38
- columnWidths: WidthSpec;
39
- selection: ReactDataSheet.Selection | null;
40
- rowOffset: number;
41
- columns: ColumnData[];
42
- }
43
-
44
- interface DataSheetParams {
45
- rowHeight: number;
46
- containerWidth: number;
47
- virtualized: boolean;
48
- columns: ColumnData[];
49
- }
50
-
51
- type DataSheetCtx = DataSheetState &
52
- DataSheetParams & {
53
- dispatch: Dispatch<DataSheetAction>;
54
- };
55
-
56
- type SetColumns = {
57
- type: "set-columns";
58
- value: ColumnData[];
59
- };
60
-
61
- type UpdateColumnWidth = {
62
- type: "update-column-width";
63
- key: string;
64
- value: number;
65
- };
66
-
67
- type SetSelection = {
68
- type: "set-selection";
69
- value: ReactDataSheet.Selection;
70
- };
71
-
72
- type MoveColumn = {
73
- type: "move-column";
74
- dragIndex: number;
75
- hoverIndex: number;
76
- };
77
-
78
- type SetRowOffset = {
79
- type: "set-row-offset";
80
- value: number;
81
- };
82
-
83
- type DataSheetProps = DataSheetParams & {
84
- // This is too complicated by half...
85
- desiredWidths: WidthSpec;
86
- children: React.ReactNode;
87
- };
88
-
89
- type DataSheetAction =
90
- | UpdateColumnWidth
91
- | SetSelection
92
- | SetRowOffset
93
- | SetColumns
94
- | MoveColumn;
95
-
96
- const DataSheetContext = createContext<DataSheetCtx>(defaultContext);
97
-
98
- function dataSheetReducer(state: DataSheetState, action: DataSheetAction) {
99
- switch (action.type) {
100
- case "update-column-width":
101
- return update(state, {
102
- columnWidths: { [action.key]: { $set: action.value } },
103
- });
104
- case "set-columns":
105
- return { ...state, columns: action.value };
106
- case "move-column":
107
- // Move a column in response ot a drag
108
- const { dragIndex, hoverIndex } = action;
109
- return update(state, {
110
- columns: {
111
- $splice: [
112
- [dragIndex, 1], // remove column from drag index
113
- [hoverIndex, 0, state.columns[dragIndex]], // ...and insert at hover index
114
- ],
115
- },
116
- });
117
- case "set-selection":
118
- return update(state, {
119
- selection: { $set: offsetSelection(action.value, state.rowOffset) },
120
- });
121
- case "set-row-offset":
122
- return update(state, { rowOffset: { $set: action.value } });
123
- }
124
- return state;
125
- }
126
-
127
- function DataSheetProviderBase(props: DataSheetProps) {
128
- /** This context/context provider don't do much right now, but they will
129
- take an increasing role in state management going forward */
130
- const {
131
- columns,
132
- rowHeight,
133
- children,
134
- virtualized = true,
135
- desiredWidths,
136
- containerWidth,
137
- } = props;
138
-
139
- const [state, dispatch] = useReducer(dataSheetReducer, {
140
- columnWidths: {},
141
- selection: null,
142
- rowOffset: 0,
143
- columns,
144
- });
145
-
146
- useEffect(() => {
147
- // If we don't have this we'll get an infinite loop
148
- const col = apportionWidths(columns, desiredWidths, containerWidth);
149
- dispatch({ type: "set-columns", value: col });
150
- }, [containerWidth, desiredWidths, columns]);
151
-
152
- const value = {
153
- virtualized,
154
- rowHeight,
155
- rowOffset: state.rowOffset,
156
- dispatch,
157
- containerWidth,
158
- ...state,
159
- };
160
- return h(DataSheetContext.Provider, { value }, children);
161
- }
162
-
163
- DataSheetProviderBase.defaultProps = defaultContext;
164
-
165
- const DataSheetProvider = compose(
166
- C(DndProvider, { backend: HTML5Backend }),
167
- DataSheetProviderBase,
168
- );
169
-
170
- const useDataSheet = () => useContext(DataSheetContext);
171
- const useDispatch = () => useDataSheet().dispatch;
172
-
173
- export {
174
- DataSheetContext,
175
- DataSheetProvider,
176
- ColumnInfo,
177
- useDispatch,
178
- useDataSheet,
179
- };
@@ -1,56 +0,0 @@
1
- .header-cell {
2
- position: relative;
3
- overflow: visible !important;
4
- border-right: 1px solid #888;
5
- }
6
- .header-cell .cell-content {
7
- width: 100%;
8
- }
9
-
10
- thead {
11
- position: relative;
12
- .cell-drag-handle {
13
- display: none;
14
- }
15
- &:hover .cell-drag-handle {
16
- display: block;
17
- }
18
- }
19
-
20
- .cell-drag-handle {
21
- top: 0;
22
- left: -2px;
23
- bottom: 0;
24
- width: 4px;
25
- display: block;
26
- position: absolute;
27
- background: var(--border-color);
28
- cursor: ew-resize;
29
- z-index: 50;
30
- }
31
-
32
- .virtualized-sheet {
33
- overflow-y: scroll;
34
- overflow-x: hidden;
35
- position: relative;
36
- .ui {
37
- position: sticky;
38
- top: 0px;
39
- bottom: 0px;
40
- left: 0px;
41
- right: 0px;
42
- }
43
- :global {
44
- .data-grid-container {
45
- width: 100%;
46
- height: 100%;
47
- }
48
- .data-grid {
49
- width: 100%;
50
- height: 100%;
51
- .cell.updated {
52
- background-color: inherit;
53
- }
54
- }
55
- }
56
- }
@@ -1,53 +0,0 @@
1
- tr
2
- height 20px
3
-
4
-
5
- col
6
- width: 100px
7
- &.color
8
- width 120px
9
- &.index-column
10
- width 40px
11
-
12
- .data-grid-container .data-grid .cell
13
- height 20px
14
- &> input
15
- margin 0
16
- padding 0 4px
17
- outline: none !important
18
- height: 19px
19
- width: calc(100% + 2px)
20
- &>.value-viewer
21
- padding 0 4px
22
- &[data-status="invalid"]
23
- box-shadow: inset 0 0 0 1px salmon;
24
-
25
- .neatline
26
- fill: none
27
- stroke: black
28
- stroke-width: 2px
29
-
30
- .left-panel
31
- max-width: 600px
32
-
33
- .data-area-main
34
- display: flex
35
- flex-direction row
36
- &>*
37
- margin-right 4px
38
- &:last-child
39
- margin-right 0
40
-
41
- .popover-container
42
- span.popover-target, span.bp5-popover-target
43
- display inline !important
44
- pointer-events none
45
- width 10px !important
46
- height: 10px !important
47
-
48
- .interaction-barrier
49
- pointer-events: all
50
-
51
- p.description
52
- color #aaa
53
- font-style: italic
@@ -1,60 +0,0 @@
1
- tr {
2
- height: 20px;
3
- }
4
- col {
5
- width: 100px;
6
- }
7
- col.color {
8
- width: 120px;
9
- }
10
- col.index-column {
11
- width: 40px;
12
- }
13
- .data-grid-container .data-grid .cell {
14
- height: 20px;
15
- }
16
- .data-grid-container .data-grid .cell > input {
17
- margin: 0;
18
- padding: 0 4px;
19
- outline: none !important;
20
- height: 19px;
21
- width: calc(100% + 2px);
22
- }
23
- .data-grid-container .data-grid .cell > .value-viewer {
24
- padding: 0 4px;
25
- }
26
- .data-grid-container .data-grid .cell[data-status="invalid"] {
27
- box-shadow: inset 0 0 0 1px #fa8072;
28
- }
29
- .neatline {
30
- fill: none;
31
- stroke: #000;
32
- stroke-width: 2px;
33
- }
34
- .left-panel {
35
- max-width: 600px;
36
- }
37
- .data-area-main {
38
- display: flex;
39
- flex-direction: row;
40
- }
41
- .data-area-main > * {
42
- margin-right: 4px;
43
- }
44
- .data-area-main > *:last-child {
45
- margin-right: 0;
46
- }
47
- .popover-container span.popover-target,
48
- .popover-container span.bp5-popover2-target {
49
- display: inline !important;
50
- pointer-events: none;
51
- width: 10px !important;
52
- height: 10px !important;
53
- }
54
- .interaction-barrier {
55
- pointer-events: all;
56
- }
57
- p.description {
58
- color: #aaa;
59
- font-style: italic;
60
- }
@@ -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 };