@macrostrat/data-sheet 2.2.1 → 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.
Files changed (60) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/dist/esm/data-sheet.410c5122.js.map +1 -1
  3. package/dist/esm/{data-sheet.b4098761.js → data-sheet.45e8d3b0.js} +2 -2
  4. package/dist/esm/data-sheet.45e8d3b0.js.map +1 -0
  5. package/dist/esm/{data-sheet.e09e2546.js → data-sheet.a0d5d18d.js} +7 -6
  6. package/dist/esm/data-sheet.a0d5d18d.js.map +1 -0
  7. package/dist/esm/data-sheet.ae6daf58.js +14 -0
  8. package/dist/esm/data-sheet.ae6daf58.js.map +1 -0
  9. package/dist/esm/{data-sheet.2521a9d7.js → data-sheet.ce24dcf9.js} +4 -4
  10. package/dist/esm/data-sheet.ce24dcf9.js.map +1 -0
  11. package/dist/esm/index.d.ts +14 -3
  12. package/dist/esm/index.d.ts.map +1 -1
  13. package/dist/esm/index.js +6 -4
  14. package/dist/esm/index.js.map +1 -1
  15. package/dist/node/data-sheet.4a8fd8a7.js +2 -0
  16. package/dist/node/data-sheet.4a8fd8a7.js.map +1 -0
  17. package/dist/node/data-sheet.bb45401c.js +2 -0
  18. package/dist/node/data-sheet.bb45401c.js.map +1 -0
  19. package/dist/node/data-sheet.bfbba3fc.js +2 -0
  20. package/dist/node/data-sheet.bfbba3fc.js.map +1 -0
  21. package/dist/node/{data-sheet.22cde343.js → data-sheet.d40ac2ae.js} +2 -2
  22. package/dist/node/data-sheet.d40ac2ae.js.map +1 -0
  23. package/dist/node/{data-sheet.52753d1d.js → data-sheet.f3404ed5.js} +2 -2
  24. package/dist/node/{data-sheet.52753d1d.js.map → data-sheet.f3404ed5.js.map} +1 -1
  25. package/dist/node/index.js +1 -1
  26. package/dist/node/index.js.map +1 -1
  27. package/package.json +2 -2
  28. package/src/core.ts +2 -2
  29. package/src/index.ts +1 -0
  30. package/src/postgrest-table/index.ts +16 -13
  31. package/src/provider.ts +6 -26
  32. package/src/utils/column-spec.ts +25 -1
  33. package/src/utils/index.ts +1 -1
  34. package/dist/esm/data-sheet.0adfe599.js +0 -14
  35. package/dist/esm/data-sheet.0adfe599.js.map +0 -1
  36. package/dist/esm/data-sheet.2521a9d7.js.map +0 -1
  37. package/dist/esm/data-sheet.b4098761.js.map +0 -1
  38. package/dist/esm/data-sheet.e09e2546.js.map +0 -1
  39. package/dist/node/data-sheet.22cde343.js.map +0 -1
  40. package/dist/node/data-sheet.50d0742f.js +0 -2
  41. package/dist/node/data-sheet.50d0742f.js.map +0 -1
  42. package/dist/node/data-sheet.7bbad640.js +0 -2
  43. package/dist/node/data-sheet.7bbad640.js.map +0 -1
  44. package/dist/node/data-sheet.820e5bc3.js +0 -2
  45. package/dist/node/data-sheet.820e5bc3.js.map +0 -1
  46. package/src/__archive/base.ts +0 -56
  47. package/src/__archive/components/column-utils.ts +0 -126
  48. package/src/__archive/components/index.ts +0 -115
  49. package/src/__archive/components/toolbar.ts +0 -79
  50. package/src/__archive/editors/index.ts +0 -78
  51. package/src/__archive/editors/styles.module.scss +0 -10
  52. package/src/__archive/enhancers.ts +0 -36
  53. package/src/__archive/index.ts +0 -8
  54. package/src/__archive/main.ts +0 -180
  55. package/src/__archive/provider.ts +0 -179
  56. package/src/__archive/styles.module.scss +0 -56
  57. package/src/__archive/test-sheet/attitude-sheet.old.styl +0 -53
  58. package/src/__archive/test-sheet/attitude-sheet.scss +0 -60
  59. package/src/__archive/test-sheet/index.ts +0 -210
  60. package/src/__archive/virtualized.ts +0 -82
@@ -1,180 +0,0 @@
1
- import { DataSheetProvider } from "./provider";
2
- import { VirtualizedSheet } from "./virtualized";
3
- import { BaseSheet } from "./base";
4
- import { ErrorBoundary, useElementSize } from "@macrostrat/ui-components";
5
- import { enhanceData } from "./enhancers";
6
- import { GridElement } from "./base";
7
- import h from "@macrostrat/hyper";
8
- import { useState, useEffect, useRef } from "react";
9
- import { SheetToolbar } from "./components";
10
- import classNames from "classnames";
11
- import update from "immutability-helper";
12
-
13
- export function DataSheet(props) {
14
- const { data: baseData, columns, onSubmit, ...rest } = props;
15
- const [data, setData] = useState<any[]>(baseData);
16
- //const [edits, setEdits] = useState([]);
17
- /**
18
- * For edits, what I could do is create an array of indexes based on the row number.
19
- * And at the end I can grab the whole row and send it to the backend.
20
- */
21
-
22
- useEffect(() => {
23
- // Set data to start with the value of the initial data
24
- if (baseData == null) return;
25
- setData(baseData);
26
- }, [baseData]);
27
-
28
- const ref = useRef();
29
- const size = useElementSize(ref);
30
-
31
- const onCancel = () => {
32
- setData(baseData);
33
- };
34
-
35
- //const [columns, setDesiredWidth] = useState(columnSpec);
36
-
37
- //const desiredWidths =
38
- // initialData != null ? calculateWidths(initialData, columns) : {};
39
-
40
- // Change management
41
- // const handleUndo = () => {
42
- // setData(initialData);
43
- // setEdits([]);
44
- // };
45
- // const handleSubmit = () => {
46
- // //push method for sending data back to api
47
- // if (data.length === 0) {
48
- // return null;
49
- // }
50
- // setData(data);
51
- // const post_data = BuildEdits();
52
- // console.log(post_data);
53
- // postData(post_data);
54
- // setEdits([]);
55
- // };
56
-
57
- // function BuildEdits() {
58
- // /** Grabs the edits from the data for POST.
59
- // *
60
- // * How can I group them by rows so I don't have to send a item per cell
61
- // */
62
-
63
- // const editsList = addNecesaryFields(edits, data);
64
- // const finalEdits = combineLikeIds(editsList);
65
- // return finalEdits;
66
- // }
67
-
68
- function onCellsChanged(changes) {
69
- /** Cell change function that uses immutability-helper */
70
- const spec = {};
71
- // const edits = []; // something like what's happening with spec
72
- console.log(changes);
73
- changes.forEach(({ cell, row, col, value }) => {
74
- // Get the key that should be used to assign the value
75
- const { key } = columns[col];
76
- // Substitute empty strings for nulls
77
- const $set = value == "" ? null : value;
78
- // sets edits to the state index and the column name
79
- //setEdits((prevEdits) => [{ row, key }, ...prevEdits]);
80
- spec[row] = {
81
- ...(spec[row] || {}),
82
- [key]: { $set },
83
- };
84
- });
85
- setData(update(data, spec));
86
- }
87
-
88
- /** Builds the properties for the cell */
89
- const finalizeCellProps = (
90
- value: any,
91
- row: number,
92
- key: string,
93
- col: number,
94
- ) => {
95
- /** Need to turn off submit on click away event for cell */
96
-
97
- // Check if values is the same as the initial data key
98
- //console.log(arguments);
99
-
100
- const isChanged = value != baseData[row][key];
101
- const readOnly = !(columns[col].editable ?? true);
102
- const className = classNames(
103
- { edited: isChanged, "read-only": readOnly },
104
- "cell",
105
- "nowrap",
106
- "clip",
107
- );
108
- return {
109
- value,
110
- className,
111
- readOnly,
112
- };
113
- };
114
-
115
- /** We now build cell properties in the render function, rather than storing
116
- them using a precomputed useEffect hook. We decide what cells have changed using
117
- a direct comparison with the equivalent value of initialData. (That's the
118
- power of immutable data.)
119
-
120
- This is where the Components should be attached.
121
- */
122
-
123
- const sheetHeader = h(
124
- SheetToolbar,
125
- {
126
- onSubmit,
127
- onCancel,
128
- hasChanges: baseData != data,
129
- },
130
- //h("div.right-actions", null, h(SettingsPopup))
131
- );
132
-
133
- return h(DataSheetUI, {
134
- sheetHeader,
135
- columns,
136
- onCellsChanged,
137
- finalizeCellProps,
138
- data,
139
- ...rest,
140
- });
141
- }
142
-
143
- function DataSheetUI({
144
- columns,
145
- data,
146
- virtualized = false,
147
- sheetHeader = null,
148
- finalizeCellProps,
149
- ...rest
150
- }) {
151
- const component = virtualized ? VirtualizedSheet : BaseSheet;
152
- let newData = data.map((d) => transformData(columns, d));
153
-
154
- if (finalizeCellProps != null) {
155
- newData = newData.map((obj, row) => {
156
- return columns.map(({ key }, col) =>
157
- finalizeCellProps(obj[col].value, row, key, col),
158
- );
159
- });
160
- }
161
- return h(
162
- ErrorBoundary,
163
- null,
164
- h(
165
- DataSheetProvider,
166
- { columns },
167
- h("div.data-sheet", [
168
- sheetHeader,
169
- h(component, { ...rest, data: newData }),
170
- ]),
171
- ),
172
- );
173
- }
174
-
175
- function transformData(columns, data: object): GridElement[] {
176
- const row1 = columns.map((d) => {
177
- return { value: data[d.key] ?? null, className: "test" };
178
- });
179
- return enhanceData(row1, columns);
180
- }
@@ -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
- }