@macrostrat/data-sheet 4.1.1 → 4.2.0
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 +34 -0
- package/dist/actions/builtin.cjs +1 -1
- package/dist/actions/builtin.cjs.map +1 -1
- package/dist/actions/builtin.d.ts +0 -2
- package/dist/actions/builtin.js +1 -1
- package/dist/actions/builtin.js.map +1 -1
- package/dist/actions/clipboard.cjs +1 -1
- package/dist/actions/clipboard.cjs.map +1 -1
- package/dist/actions/clipboard.d.ts +3 -2
- package/dist/actions/clipboard.js +1 -1
- package/dist/actions/clipboard.js.map +1 -1
- package/dist/actions/column-controls.cjs +7 -196
- package/dist/actions/column-controls.cjs.map +1 -1
- package/dist/actions/column-controls.d.ts +1 -1
- package/dist/actions/column-controls.js +5 -194
- package/dist/actions/column-controls.js.map +1 -1
- package/dist/actions/column-filter.cjs +24 -73
- package/dist/actions/column-filter.cjs.map +1 -1
- package/dist/actions/column-filter.d.ts +6 -4
- package/dist/actions/column-filter.js +25 -74
- package/dist/actions/column-filter.js.map +1 -1
- package/dist/actions/context.cjs +147 -0
- package/dist/actions/context.cjs.map +1 -0
- package/dist/actions/context.d.ts +93 -0
- package/dist/actions/context.js +145 -0
- package/dist/actions/context.js.map +1 -0
- package/dist/actions/edit-actions.cjs.map +1 -1
- package/dist/actions/edit-actions.d.ts +3 -1
- package/dist/actions/edit-actions.js.map +1 -1
- package/dist/actions/index.d.ts +2 -3
- package/dist/actions/selection.cjs +70 -115
- package/dist/actions/selection.cjs.map +1 -1
- package/dist/actions/selection.d.ts +22 -12
- package/dist/actions/selection.js +71 -114
- package/dist/actions/selection.js.map +1 -1
- package/dist/actions/table-actions.cjs +41 -0
- package/dist/actions/table-actions.cjs.map +1 -0
- package/dist/actions/{table-controls.d.ts → table-actions.d.ts} +0 -4
- package/dist/actions/{table-controls.js → table-actions.js} +2 -23
- package/dist/actions/table-actions.js.map +1 -0
- package/dist/actions/types.d.ts +11 -89
- package/dist/components/cell-detail.cjs +6 -6
- package/dist/components/cell-detail.cjs.map +1 -1
- package/dist/components/cell-detail.js +1 -1
- package/dist/components/colors.cjs.map +1 -1
- package/dist/components/colors.js.map +1 -1
- package/dist/components/editor-popup.cjs +7 -7
- package/dist/components/editor-popup.cjs.map +1 -1
- package/dist/components/editor-popup.js +1 -1
- package/dist/components/index.d.ts +2 -1
- package/dist/components/indicators/filter-and-sort.cjs +378 -0
- package/dist/components/indicators/filter-and-sort.cjs.map +1 -0
- package/dist/components/indicators/filter-and-sort.d.ts +59 -0
- package/dist/components/indicators/filter-and-sort.js +376 -0
- package/dist/components/indicators/filter-and-sort.js.map +1 -0
- package/dist/components/indicators/filter-and-sort.module.sass.cjs +16 -0
- package/dist/components/indicators/filter-and-sort.module.sass.cjs.map +1 -0
- package/dist/components/indicators/filter-and-sort.module.sass.js +14 -0
- package/dist/components/indicators/filter-and-sort.module.sass.js.map +1 -0
- package/dist/components/indicators/index.d.ts +4 -0
- package/dist/components/indicators/selection.cjs +113 -0
- package/dist/components/indicators/selection.cjs.map +1 -0
- package/dist/components/indicators/selection.d.ts +3 -0
- package/dist/components/indicators/selection.js +111 -0
- package/dist/components/indicators/selection.js.map +1 -0
- package/dist/components/indicators/selection.module.sass.cjs +19 -0
- package/dist/components/indicators/selection.module.sass.cjs.map +1 -0
- package/dist/components/indicators/selection.module.sass.js +17 -0
- package/dist/components/indicators/selection.module.sass.js.map +1 -0
- package/dist/components/indicators/unified-filters.cjs +130 -0
- package/dist/components/indicators/unified-filters.cjs.map +1 -0
- package/dist/components/indicators/unified-filters.d.ts +10 -0
- package/dist/components/indicators/unified-filters.js +130 -0
- package/dist/components/indicators/unified-filters.js.map +1 -0
- package/dist/components/indicators/view-info.cjs +59 -0
- package/dist/components/indicators/view-info.cjs.map +1 -0
- package/dist/components/{view-info.d.ts → indicators/view-info.d.ts} +1 -0
- package/dist/components/{view-info.js → indicators/view-info.js} +17 -13
- package/dist/components/indicators/view-info.js.map +1 -0
- package/dist/components/text-areas.cjs +5 -5
- package/dist/components/text-areas.cjs.map +1 -1
- package/dist/components/text-areas.js +1 -1
- package/dist/components/toolbars/actions-toolbar.cjs +185 -0
- package/dist/components/toolbars/actions-toolbar.cjs.map +1 -0
- package/dist/{actions/toolbar.d.ts → components/toolbars/actions-toolbar.d.ts} +9 -5
- package/dist/{actions/toolbar.js → components/toolbars/actions-toolbar.js} +37 -112
- package/dist/components/toolbars/actions-toolbar.js.map +1 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.cjs +29 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.cjs.map +1 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.js +27 -0
- package/dist/components/toolbars/actions-toolbar.module.sass.js.map +1 -0
- package/dist/components/toolbars/active-filters.cjs +120 -0
- package/dist/components/toolbars/active-filters.cjs.map +1 -0
- package/dist/{actions/filters.d.ts → components/toolbars/active-filters.d.ts} +3 -3
- package/dist/components/toolbars/active-filters.js +120 -0
- package/dist/components/toolbars/active-filters.js.map +1 -0
- package/dist/components/toolbars/index.d.ts +2 -0
- package/dist/data-panel.cjs +291 -0
- package/dist/data-panel.cjs.map +1 -0
- package/dist/data-panel.d.ts +110 -0
- package/dist/data-panel.js +289 -0
- package/dist/data-panel.js.map +1 -0
- package/dist/data-panel.module.sass.cjs +40 -0
- package/dist/data-panel.module.sass.cjs.map +1 -0
- package/dist/data-panel.module.sass.js +38 -0
- package/dist/data-panel.module.sass.js.map +1 -0
- package/dist/{core.cjs → data-sheet.cjs} +123 -190
- package/dist/data-sheet.cjs.map +1 -0
- package/dist/data-sheet.css +241 -13
- package/dist/data-sheet.d.ts +16 -0
- package/dist/{core.js → data-sheet.js} +92 -159
- package/dist/data-sheet.js.map +1 -0
- package/dist/data-view.cjs +47 -0
- package/dist/data-view.cjs.map +1 -0
- package/dist/data-view.d.ts +15 -0
- package/dist/data-view.js +45 -0
- package/dist/data-view.js.map +1 -0
- package/dist/filters/operators.cjs +19 -2
- package/dist/filters/operators.cjs.map +1 -1
- package/dist/filters/operators.d.ts +4 -3
- package/dist/filters/operators.js +19 -2
- package/dist/filters/operators.js.map +1 -1
- package/dist/index.cjs +106 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -3
- package/dist/index.js +76 -17
- package/dist/index.js.map +1 -1
- package/dist/notifications.cjs +4 -4
- package/dist/notifications.cjs.map +1 -1
- package/dist/notifications.js +1 -1
- package/dist/postgrest-table/data-loaders.cjs +128 -95
- package/dist/postgrest-table/data-loaders.cjs.map +1 -1
- package/dist/postgrest-table/data-loaders.d.ts +52 -82
- package/dist/postgrest-table/data-loaders.js +109 -76
- package/dist/postgrest-table/data-loaders.js.map +1 -1
- package/dist/postgrest-table/index.cjs +18 -17
- package/dist/postgrest-table/index.cjs.map +1 -1
- package/dist/postgrest-table/index.d.ts +4 -3
- package/dist/postgrest-table/index.js +9 -8
- package/dist/postgrest-table/index.js.map +1 -1
- package/dist/{utils → provider}/column-spec.cjs +23 -9
- package/dist/provider/column-spec.cjs.map +1 -0
- package/dist/{utils → provider}/column-spec.d.ts +73 -2
- package/dist/{utils → provider}/column-spec.js +24 -10
- package/dist/provider/column-spec.js.map +1 -0
- package/dist/provider/core.cjs +382 -0
- package/dist/provider/core.cjs.map +1 -0
- package/dist/provider/core.d.ts +74 -0
- package/dist/provider/core.js +380 -0
- package/dist/provider/core.js.map +1 -0
- package/dist/provider/index.d.ts +7 -0
- package/dist/provider/interactions.cjs +128 -0
- package/dist/provider/interactions.cjs.map +1 -0
- package/dist/provider/interactions.d.ts +39 -0
- package/dist/provider/interactions.js +128 -0
- package/dist/provider/interactions.js.map +1 -0
- package/dist/provider/selection.cjs +29 -0
- package/dist/provider/selection.cjs.map +1 -0
- package/dist/provider/selection.d.ts +9 -0
- package/dist/provider/selection.js +29 -0
- package/dist/provider/selection.js.map +1 -0
- package/dist/provider/table-data.cjs +92 -0
- package/dist/provider/table-data.cjs.map +1 -0
- package/dist/provider/table-data.d.ts +81 -0
- package/dist/provider/table-data.js +92 -0
- package/dist/provider/table-data.js.map +1 -0
- package/dist/provider/types.cjs +22 -0
- package/dist/provider/types.cjs.map +1 -0
- package/dist/provider/types.d.ts +256 -0
- package/dist/provider/types.js +22 -0
- package/dist/provider/types.js.map +1 -0
- package/dist/{zustand-store.cjs → provider/zustand-store.cjs} +36 -23
- package/dist/provider/zustand-store.cjs.map +1 -0
- package/dist/{zustand-store.js → provider/zustand-store.js} +21 -8
- package/dist/provider/zustand-store.js.map +1 -0
- package/dist/{cell-renderer.cjs → renderers/cell-renderer.cjs} +67 -34
- package/dist/renderers/cell-renderer.cjs.map +1 -0
- package/dist/{cell-renderer.d.ts → renderers/cell-renderer.d.ts} +1 -2
- package/dist/{cell-renderer.js → renderers/cell-renderer.js} +65 -32
- package/dist/renderers/cell-renderer.js.map +1 -0
- package/dist/renderers/column-header-cell.cjs +21 -13
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.d.ts +3 -2
- package/dist/renderers/column-header-cell.js +20 -12
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/renderers/index.d.ts +1 -0
- package/dist/types.cjs +7 -19
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +117 -229
- package/dist/types.js +7 -19
- package/dist/types.js.map +1 -1
- package/dist/utils/atoms.cjs +24 -0
- package/dist/utils/atoms.cjs.map +1 -0
- package/dist/utils/atoms.d.ts +4 -0
- package/dist/utils/atoms.js +24 -0
- package/dist/utils/atoms.js.map +1 -0
- package/dist/utils/debug-overlay.cjs.map +1 -1
- package/dist/utils/debug-overlay.js.map +1 -1
- package/dist/utils/index.d.ts +2 -3
- package/dist/utils/key-handling.cjs +140 -139
- package/dist/utils/key-handling.cjs.map +1 -1
- package/dist/utils/key-handling.d.ts +4 -2
- package/dist/utils/key-handling.js +136 -135
- package/dist/utils/key-handling.js.map +1 -1
- package/dist/utils/validation.cjs +6 -1
- package/dist/utils/validation.cjs.map +1 -1
- package/dist/utils/validation.d.ts +1 -1
- package/dist/utils/validation.js +6 -1
- package/dist/utils/validation.js.map +1 -1
- package/package.json +4 -3
- package/src/actions/builtin.ts +1 -4
- package/src/actions/clipboard.ts +4 -3
- package/src/actions/column-controls.ts +12 -245
- package/src/actions/column-filter.ts +28 -92
- package/src/actions/context.ts +299 -0
- package/src/actions/edit-actions.ts +3 -1
- package/src/actions/index.ts +2 -3
- package/src/actions/selection.ts +109 -156
- package/src/actions/{table-controls.ts → table-actions.ts} +0 -24
- package/src/actions/types.ts +17 -101
- package/src/components/colors.ts +1 -1
- package/src/components/index.ts +2 -1
- package/src/components/indicators/filter-and-sort.module.sass +13 -0
- package/src/components/indicators/filter-and-sort.ts +478 -0
- package/src/components/indicators/index.ts +4 -0
- package/src/components/indicators/selection.module.sass +22 -0
- package/src/components/indicators/selection.ts +141 -0
- package/src/components/indicators/unified-filters.ts +161 -0
- package/src/components/{view-info.ts → indicators/view-info.ts} +16 -27
- package/src/{actions/toolbar.module.sass → components/toolbars/actions-toolbar.module.sass} +17 -4
- package/src/{actions/toolbar.ts → components/toolbars/actions-toolbar.ts} +49 -150
- package/src/components/toolbars/active-filters.ts +150 -0
- package/src/components/toolbars/index.ts +2 -0
- package/src/data-panel.module.sass +185 -0
- package/src/data-panel.ts +556 -0
- package/src/{core.ts → data-sheet.ts} +145 -330
- package/src/data-view.ts +70 -0
- package/src/filters/operators.ts +33 -3
- package/src/index.ts +4 -3
- package/src/postgrest-table/data-loaders.ts +244 -171
- package/src/postgrest-table/index.ts +10 -9
- package/src/{utils → provider}/column-spec.ts +30 -15
- package/src/provider/core.ts +585 -0
- package/src/provider/index.ts +7 -0
- package/src/provider/interactions.ts +161 -0
- package/src/provider/selection.ts +31 -0
- package/src/provider/table-data.ts +178 -0
- package/src/provider/types.ts +273 -0
- package/src/{zustand-store.ts → provider/zustand-store.ts} +35 -14
- package/src/{cell-renderer.ts → renderers/cell-renderer.ts} +140 -57
- package/src/renderers/column-header-cell.ts +21 -14
- package/src/renderers/index.ts +1 -0
- package/src/types.ts +137 -239
- package/src/utils/atoms.ts +28 -0
- package/src/utils/debug-overlay.ts +1 -1
- package/src/utils/index.ts +2 -8
- package/src/utils/key-handling.ts +170 -164
- package/src/utils/validation.ts +7 -2
- package/dist/actions/filters.cjs +0 -139
- package/dist/actions/filters.cjs.map +0 -1
- package/dist/actions/filters.js +0 -139
- package/dist/actions/filters.js.map +0 -1
- package/dist/actions/table-controls.cjs +0 -62
- package/dist/actions/table-controls.cjs.map +0 -1
- package/dist/actions/table-controls.js.map +0 -1
- package/dist/actions/toolbar.cjs +0 -260
- package/dist/actions/toolbar.cjs.map +0 -1
- package/dist/actions/toolbar.js.map +0 -1
- package/dist/actions/toolbar.module.sass.cjs +0 -27
- package/dist/actions/toolbar.module.sass.cjs.map +0 -1
- package/dist/actions/toolbar.module.sass.js +0 -25
- package/dist/actions/toolbar.module.sass.js.map +0 -1
- package/dist/cell-renderer.cjs.map +0 -1
- package/dist/cell-renderer.js.map +0 -1
- package/dist/components/view-info.cjs +0 -55
- package/dist/components/view-info.cjs.map +0 -1
- package/dist/components/view-info.js.map +0 -1
- package/dist/core.cjs.map +0 -1
- package/dist/core.d.ts +0 -117
- package/dist/core.js.map +0 -1
- package/dist/provider.cjs +0 -197
- package/dist/provider.cjs.map +0 -1
- package/dist/provider.d.ts +0 -26
- package/dist/provider.js +0 -195
- package/dist/provider.js.map +0 -1
- package/dist/table-updates/data-parameter.d.ts +0 -14
- package/dist/table-updates/filter.d.ts +0 -16
- package/dist/table-updates/index.d.ts +0 -19
- package/dist/utils/column-spec.cjs.map +0 -1
- package/dist/utils/column-spec.js.map +0 -1
- package/dist/utils/index.cjs +0 -9
- package/dist/utils/index.cjs.map +0 -1
- package/dist/utils/index.js +0 -9
- package/dist/utils/index.js.map +0 -1
- package/dist/zustand-store.cjs.map +0 -1
- package/dist/zustand-store.js.map +0 -1
- package/src/actions/filters.ts +0 -176
- package/src/components/actions.module.sass +0 -8
- package/src/provider.ts +0 -267
- package/src/table-updates/data-parameter.ts +0 -44
- package/src/table-updates/filter.ts +0 -124
- package/src/table-updates/index.ts +0 -239
- /package/dist/{zustand-store.d.ts → provider/zustand-store.d.ts} +0 -0
package/dist/provider.cjs
DELETED
|
@@ -1,197 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
const react = require("react");
|
|
4
|
-
const h = require("@macrostrat/hyper");
|
|
5
|
-
const zustand = require("zustand");
|
|
6
|
-
const dataComponents = require("@macrostrat/data-components");
|
|
7
|
-
const types = require("./types.cjs");
|
|
8
|
-
const zustandStore = require("./zustand-store.cjs");
|
|
9
|
-
const jotaiZustand = require("jotai-zustand");
|
|
10
|
-
const notifications = require("./notifications.cjs");
|
|
11
|
-
const jotai = require("jotai");
|
|
12
|
-
const columnSpec = require("./utils/column-spec.cjs");
|
|
13
|
-
const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
|
|
14
|
-
const h__default = /* @__PURE__ */ _interopDefault(h);
|
|
15
|
-
const ctx = dataComponents.createScopedStore();
|
|
16
|
-
const storeAPIAtom = jotai.atom();
|
|
17
|
-
const storeWrapperAtom = jotai.atom((get) => {
|
|
18
|
-
const _storeAPIAtom = get(storeAPIAtom);
|
|
19
|
-
if (_storeAPIAtom == null) {
|
|
20
|
-
return void 0;
|
|
21
|
-
}
|
|
22
|
-
return jotaiZustand.atomWithStore(_storeAPIAtom);
|
|
23
|
-
});
|
|
24
|
-
const storeAtom = jotai.atom(
|
|
25
|
-
(get) => {
|
|
26
|
-
const storeWrapper = get(storeWrapperAtom);
|
|
27
|
-
if (storeWrapper == null) {
|
|
28
|
-
return void 0;
|
|
29
|
-
}
|
|
30
|
-
return get(storeWrapper);
|
|
31
|
-
},
|
|
32
|
-
(get, set, action) => {
|
|
33
|
-
const storeWrapper = get(storeWrapperAtom);
|
|
34
|
-
if (storeWrapper == null) {
|
|
35
|
-
throw new Error("Missing DataSheetProvider");
|
|
36
|
-
}
|
|
37
|
-
return set(storeWrapper, action);
|
|
38
|
-
}
|
|
39
|
-
);
|
|
40
|
-
const EMPTY_SPEC = [];
|
|
41
|
-
const initializeStoreAtom = jotai.atom(
|
|
42
|
-
null,
|
|
43
|
-
(get, set, payload) => {
|
|
44
|
-
set(storeAtom, (state) => {
|
|
45
|
-
return {
|
|
46
|
-
...state,
|
|
47
|
-
...payload
|
|
48
|
-
};
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
);
|
|
52
|
-
const tableActionsAtom = jotai.atom([]);
|
|
53
|
-
function DataSheetProvider(props) {
|
|
54
|
-
const { toaster, ...rest } = props;
|
|
55
|
-
const [store] = react.useState(() => {
|
|
56
|
-
return zustand.createStore(zustandStore.createZustandStore);
|
|
57
|
-
});
|
|
58
|
-
return h__default.default(
|
|
59
|
-
ctx.Provider,
|
|
60
|
-
{
|
|
61
|
-
atoms: [
|
|
62
|
-
[storeAPIAtom, store],
|
|
63
|
-
[notifications.toasterAtom, toaster]
|
|
64
|
-
]
|
|
65
|
-
},
|
|
66
|
-
h__default.default(DataSheetProviderInner, rest)
|
|
67
|
-
);
|
|
68
|
-
}
|
|
69
|
-
function DataSheetProviderInner({
|
|
70
|
-
children,
|
|
71
|
-
data,
|
|
72
|
-
columnSpec: columnSpec$1,
|
|
73
|
-
columnSpecOptions,
|
|
74
|
-
editable,
|
|
75
|
-
enableColumnReordering,
|
|
76
|
-
defaultColumnWidth = 150
|
|
77
|
-
}) {
|
|
78
|
-
const tableRef = react.useRef(null);
|
|
79
|
-
const initializeStore = ctx.useSet(initializeStoreAtom);
|
|
80
|
-
const isFnSpec = typeof columnSpec$1 === "function";
|
|
81
|
-
const staticSpec = isFnSpec ? EMPTY_SPEC : columnSpec$1;
|
|
82
|
-
react.useEffect(() => {
|
|
83
|
-
initializeStore({
|
|
84
|
-
columnSpec: staticSpec ?? columnSpec.generateColumnSpec(data, columnSpecOptions),
|
|
85
|
-
// A function spec is derived from the loaded rows in `_DataSheet`; tell
|
|
86
|
-
// the loader not to auto-generate a plain spec from the first chunk.
|
|
87
|
-
deferColumnSpec: isFnSpec,
|
|
88
|
-
editable,
|
|
89
|
-
enableColumnReordering,
|
|
90
|
-
data,
|
|
91
|
-
defaultColumnWidth,
|
|
92
|
-
tableRef
|
|
93
|
-
});
|
|
94
|
-
}, [data, editable, staticSpec, isFnSpec, columnSpecOptions, enableColumnReordering]);
|
|
95
|
-
return children;
|
|
96
|
-
}
|
|
97
|
-
function useStoreAPI() {
|
|
98
|
-
const store = ctx.useValue(storeAPIAtom);
|
|
99
|
-
if (!store) {
|
|
100
|
-
throw new Error("Missing DataSheetProvider");
|
|
101
|
-
}
|
|
102
|
-
return store;
|
|
103
|
-
}
|
|
104
|
-
function useSelector(selector) {
|
|
105
|
-
const store = useStoreAPI();
|
|
106
|
-
return zustand.useStore(store, selector);
|
|
107
|
-
}
|
|
108
|
-
const columnSpecAtom = jotai.atom((get) => get(storeAtom)?.columnSpec ?? []);
|
|
109
|
-
const tableDataAtom = jotai.atom(
|
|
110
|
-
(get) => {
|
|
111
|
-
return get(storeAtom)?.data ?? [];
|
|
112
|
-
},
|
|
113
|
-
(get, set, newData) => {
|
|
114
|
-
set(storeAtom, (state) => {
|
|
115
|
-
let next = { ...state, data: newData };
|
|
116
|
-
if (state.data.length == 0 && newData.length > 0 && state.columnSpec.length == 0 && !state.deferColumnSpec) {
|
|
117
|
-
next.columnSpec = columnSpec.generateColumnSpec(newData, state.columnSpecOptions);
|
|
118
|
-
}
|
|
119
|
-
if (!state.controlledOverlay) {
|
|
120
|
-
const remap = remapOverlayByIdentity(state, newData);
|
|
121
|
-
next.data = remap.data;
|
|
122
|
-
next.updatedData = remap.updatedData;
|
|
123
|
-
next.rowStatus = remap.rowStatus;
|
|
124
|
-
next.pendingOverlayById = remap.pending;
|
|
125
|
-
}
|
|
126
|
-
return next;
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
);
|
|
130
|
-
function overlayIdentity(state, row) {
|
|
131
|
-
if (row == null) return void 0;
|
|
132
|
-
const added = row[types.DS_ROW_ID];
|
|
133
|
-
if (added != null) return added;
|
|
134
|
-
return state.identity(row);
|
|
135
|
-
}
|
|
136
|
-
function remapOverlayByIdentity(state, newData) {
|
|
137
|
-
const { data: oldData, updatedData, rowStatus } = state;
|
|
138
|
-
const byId = new Map(state.pendingOverlayById);
|
|
139
|
-
const n = Math.max(
|
|
140
|
-
oldData.length,
|
|
141
|
-
updatedData?.length ?? 0,
|
|
142
|
-
rowStatus?.length ?? 0
|
|
143
|
-
);
|
|
144
|
-
for (let i = 0; i < n; i++) {
|
|
145
|
-
const row = oldData[i];
|
|
146
|
-
if (row == null) continue;
|
|
147
|
-
const id = overlayIdentity(state, row);
|
|
148
|
-
if (id == null) continue;
|
|
149
|
-
const edit = updatedData?.[i];
|
|
150
|
-
const status = rowStatus?.[i];
|
|
151
|
-
if (edit != null || status != null) byId.set(id, { edit, status });
|
|
152
|
-
}
|
|
153
|
-
const resultData = newData.slice();
|
|
154
|
-
const nextUpdated = [];
|
|
155
|
-
const nextStatus = [];
|
|
156
|
-
const attached = /* @__PURE__ */ new Set();
|
|
157
|
-
for (let j = 0; j < resultData.length; j++) {
|
|
158
|
-
const row = resultData[j];
|
|
159
|
-
if (row == null) continue;
|
|
160
|
-
const id = overlayIdentity(state, row);
|
|
161
|
-
if (id == null) continue;
|
|
162
|
-
const entry = byId.get(id);
|
|
163
|
-
if (entry == null) continue;
|
|
164
|
-
if (entry.edit != null) nextUpdated[j] = entry.edit;
|
|
165
|
-
if (entry.status != null) nextStatus[j] = entry.status;
|
|
166
|
-
attached.add(id);
|
|
167
|
-
}
|
|
168
|
-
const pending = /* @__PURE__ */ new Map();
|
|
169
|
-
for (const [id, entry] of byId) {
|
|
170
|
-
if (attached.has(id)) continue;
|
|
171
|
-
if (entry.status === types.TableElementStatus.ADDED) {
|
|
172
|
-
const idx = resultData.length;
|
|
173
|
-
resultData.push(entry.edit ?? {});
|
|
174
|
-
nextUpdated[idx] = entry.edit;
|
|
175
|
-
nextStatus[idx] = entry.status;
|
|
176
|
-
} else {
|
|
177
|
-
pending.set(id, entry);
|
|
178
|
-
}
|
|
179
|
-
}
|
|
180
|
-
return {
|
|
181
|
-
data: resultData,
|
|
182
|
-
updatedData: nextUpdated,
|
|
183
|
-
rowStatus: nextStatus,
|
|
184
|
-
pending
|
|
185
|
-
};
|
|
186
|
-
}
|
|
187
|
-
exports.DataSheetProvider = DataSheetProvider;
|
|
188
|
-
exports.DataSheetProviderInner = DataSheetProviderInner;
|
|
189
|
-
exports.columnSpecAtom = columnSpecAtom;
|
|
190
|
-
exports.ctx = ctx;
|
|
191
|
-
exports.storeAPIAtom = storeAPIAtom;
|
|
192
|
-
exports.storeAtom = storeAtom;
|
|
193
|
-
exports.tableActionsAtom = tableActionsAtom;
|
|
194
|
-
exports.tableDataAtom = tableDataAtom;
|
|
195
|
-
exports.useSelector = useSelector;
|
|
196
|
-
exports.useStoreAPI = useStoreAPI;
|
|
197
|
-
//# sourceMappingURL=provider.cjs.map
|
package/dist/provider.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.cjs","sources":["../src/provider.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef, useState } from \"react\";\nimport h from \"@macrostrat/hyper\";\nimport { createStore, StoreApi, useStore } from \"zustand\";\nimport type { Table } from \"@blueprintjs/table\";\nimport { generateColumnSpec, type ColumnSpec } from \"./utils\";\nimport { createScopedStore } from \"@macrostrat/data-components\";\nimport {\n DataSheetProviderProps,\n DataSheetState,\n DataSheetStore,\n DS_ROW_ID,\n TableElementStatus,\n} from \"./types.ts\";\nimport { createZustandStore } from \"./zustand-store.ts\";\nimport { atomWithStore } from \"jotai-zustand\";\nimport { toasterAtom } from \"./notifications.ts\";\nimport { TableAction } from \"./actions\";\nimport { atom } from \"jotai\";\n\n/** Create a Jotai scoped store */\nexport const ctx = createScopedStore();\n\nexport const storeAPIAtom = atom<StoreApi<DataSheetStore<any>>>();\n\nconst storeWrapperAtom = atom((get) => {\n const _storeAPIAtom = get(storeAPIAtom);\n if (_storeAPIAtom == null) {\n return undefined;\n }\n return atomWithStore(_storeAPIAtom);\n});\n\n/** This is the basis for all other atoms that manipulate the store. */\nexport const storeAtom = atom(\n (get) => {\n const storeWrapper = get(storeWrapperAtom);\n if (storeWrapper == null) {\n return undefined;\n }\n return get(storeWrapper);\n },\n (get, set, action: SetStateAction<T>) => {\n const storeWrapper = get(storeWrapperAtom);\n if (storeWrapper == null) {\n throw new Error(\"Missing DataSheetProvider\");\n }\n return set(storeWrapper, action);\n },\n);\n\n/** Stable empty spec so a function `columnSpec` yields a constant init value\n * (see `DataSheetProviderInner`). */\nconst EMPTY_SPEC: ColumnSpec[] = [];\n\nconst initializeStoreAtom = atom(\n null,\n (get, set, payload: Partial<DataSheetStore<T>>) => {\n set(storeAtom, (state) => {\n return {\n ...state,\n ...payload,\n };\n });\n },\n);\n\nexport const tableActionsAtom = atom<TableAction[]>([]);\n\nexport function DataSheetProvider<T>(props: DataSheetProviderProps<T>) {\n const { toaster, ...rest } = props;\n const [store] = useState(() => {\n return createStore<DataSheetStore<T>>(createZustandStore);\n });\n return h(\n ctx.Provider,\n {\n atoms: [\n [storeAPIAtom, store],\n [toasterAtom, toaster],\n ],\n },\n h(DataSheetProviderInner, rest),\n );\n}\n\nexport function DataSheetProviderInner<T>({\n children,\n data,\n columnSpec,\n columnSpecOptions,\n editable,\n enableColumnReordering,\n defaultColumnWidth = 150,\n}: DataSheetProviderProps<T>) {\n const tableRef = useRef<Table>(null);\n\n const initializeStore = ctx.useSet(initializeStoreAtom);\n\n // A function `columnSpec` is derived from the loaded rows later (in\n // `_DataSheet`), not here — start it empty. Crucially it's kept OUT of the\n // init effect's deps: re-running init also resets `data`, so re-initializing\n // when the function's identity changes (e.g. a consumer hiding a column)\n // would wipe the loaded rows. `staticSpec` is a stable value in that case.\n const isFnSpec = typeof columnSpec === \"function\";\n const staticSpec = isFnSpec ? EMPTY_SPEC : columnSpec;\n\n // Not sure how required this initialization is\n useEffect(() => {\n initializeStore({\n columnSpec: staticSpec ?? generateColumnSpec(data, columnSpecOptions),\n // A function spec is derived from the loaded rows in `_DataSheet`; tell\n // the loader not to auto-generate a plain spec from the first chunk.\n deferColumnSpec: isFnSpec,\n editable,\n enableColumnReordering,\n data,\n defaultColumnWidth,\n tableRef,\n });\n }, [data, editable, staticSpec, isFnSpec, columnSpecOptions, enableColumnReordering]);\n\n return children;\n}\n\nexport function useStoreAPI<T>(): StoreApi<DataSheetStore<T>> {\n const store = ctx.useValue(storeAPIAtom);\n if (!store) {\n throw new Error(\"Missing DataSheetProvider\");\n }\n return store;\n}\n\nexport function useSelector<T = any, A = any>(\n selector: (state: DataSheetStore<T> & DataSheetComputedVals) => A,\n): A {\n const store = useStoreAPI<T>();\n return useStore(store, selector);\n}\n/** Atoms for efficient sub-selection of state */\n\nexport const columnSpecAtom = atom((get) => get(storeAtom)?.columnSpec ?? []);\n\nexport const tableDataAtom = atom(\n (get) => {\n return get(storeAtom)?.data ?? [];\n },\n (get, set, newData: any[]) => {\n set(storeAtom, (state: DataSheetState<any>): DataSheetState<any> => {\n let next: DataSheetState<any> = { ...state, data: newData };\n if (\n state.data.length == 0 &&\n newData.length > 0 &&\n state.columnSpec.length == 0 &&\n !state.deferColumnSpec\n ) {\n // No spec yet and none deferred to a function — auto-generate a plain\n // spec from the first chunk. (A function spec is derived separately.)\n next.columnSpec = generateColumnSpec(newData, state.columnSpecOptions);\n }\n\n // Re-attach the edit overlay by identity. The loader replaces `data` with\n // re-ordered windows on sort/filter, so an index-keyed overlay would\n // smear; keying by identity keeps edits (and deletes) on their rows, holds\n // edits for not-yet-loaded rows, and re-appends locally-added rows (which\n // aren't in the provider's data) after it. Skipped when the consumer\n // controls the overlay (they own reconciliation).\n if (!state.controlledOverlay) {\n const remap = remapOverlayByIdentity(state, newData);\n next.data = remap.data;\n next.updatedData = remap.updatedData;\n next.rowStatus = remap.rowStatus;\n next.pendingOverlayById = remap.pending;\n }\n\n return next;\n });\n },\n);\n\ntype OverlayEntry = { edit?: any; status?: any };\n\n/** Row identity used by the overlay: an in-table-added row's synthetic id\n * (stable across its edits), else the provider/consumer `identity`. */\nfunction overlayIdentity(\n state: DataSheetState<any>,\n row: any,\n): string | number | null | undefined {\n if (row == null) return undefined;\n const added = row[DS_ROW_ID];\n if (added != null) return added;\n return state.identity(row);\n}\n\n/** Re-project the (index-keyed) edit overlay from the old `data` order onto a\n * new one, matching rows by identity. Edits/statuses whose row is absent from\n * `newData` are held in `pending` and re-applied when the row loads; rows added\n * in-table (status `ADDED`) are re-appended after the provider data (they have\n * no provider row). Starts from the prior pending set so edits survive multiple\n * re-sorts. Returns the reconstructed data (provider rows + re-appended added\n * rows) alongside the re-aligned overlay. */\nfunction remapOverlayByIdentity(\n state: DataSheetState<any>,\n newData: any[],\n): {\n data: any[];\n updatedData: any[];\n rowStatus: any[];\n pending: Map<string | number, OverlayEntry>;\n} {\n const { data: oldData, updatedData, rowStatus } = state;\n\n // Collect current overlay entries by identity, seeded with prior pending.\n const byId = new Map<string | number, OverlayEntry>(state.pendingOverlayById);\n const n = Math.max(\n oldData.length,\n updatedData?.length ?? 0,\n rowStatus?.length ?? 0,\n );\n for (let i = 0; i < n; i++) {\n const row = oldData[i];\n if (row == null) continue;\n const id = overlayIdentity(state, row);\n if (id == null) continue;\n const edit = updatedData?.[i];\n const status = rowStatus?.[i];\n if (edit != null || status != null) byId.set(id, { edit, status });\n }\n\n // Project onto the new data order.\n const resultData = newData.slice();\n const nextUpdated: any[] = [];\n const nextStatus: any[] = [];\n const attached = new Set<string | number>();\n for (let j = 0; j < resultData.length; j++) {\n const row = resultData[j];\n if (row == null) continue;\n const id = overlayIdentity(state, row);\n if (id == null) continue;\n const entry = byId.get(id);\n if (entry == null) continue;\n if (entry.edit != null) nextUpdated[j] = entry.edit;\n if (entry.status != null) nextStatus[j] = entry.status;\n attached.add(id);\n }\n\n // Re-append in-table-added rows (not present in the provider data), then hold\n // anything still unattached (rows not currently loaded) as pending.\n const pending = new Map<string | number, OverlayEntry>();\n for (const [id, entry] of byId) {\n if (attached.has(id)) continue;\n if (entry.status === TableElementStatus.ADDED) {\n const idx = resultData.length;\n resultData.push(entry.edit ?? {});\n nextUpdated[idx] = entry.edit;\n nextStatus[idx] = entry.status;\n } else {\n pending.set(id, entry);\n }\n }\n\n return {\n data: resultData,\n updatedData: nextUpdated,\n rowStatus: nextStatus,\n pending,\n };\n}\n"],"names":["createScopedStore","atom","atomWithStore","useState","createStore","createZustandStore","h","toasterAtom","columnSpec","useRef","useEffect","generateColumnSpec","useStore","DS_ROW_ID","TableElementStatus"],"mappings":";;;;;;;;;;;;;;AAoBO,MAAM,MAAMA,eAAAA,kBAAA;AAEZ,MAAM,eAAeC,MAAAA,KAAA;AAE5B,MAAM,mBAAmBA,MAAAA,KAAK,CAAC,QAAQ;AACrC,QAAM,gBAAgB,IAAI,YAAY;AACtC,MAAI,iBAAiB,MAAM;AACzB,WAAO;AAAA,EACT;AACA,SAAOC,aAAAA,cAAc,aAAa;AACpC,CAAC;AAGM,MAAM,YAAYD,MAAAA;AAAAA,EACvB,CAAC,QAAQ;AACP,UAAM,eAAe,IAAI,gBAAgB;AACzC,QAAI,gBAAgB,MAAM;AACxB,aAAO;AAAA,IACT;AACA,WAAO,IAAI,YAAY;AAAA,EACzB;AAAA,EACA,CAAC,KAAK,KAAK,WAA8B;AACvC,UAAM,eAAe,IAAI,gBAAgB;AACzC,QAAI,gBAAgB,MAAM;AACxB,YAAM,IAAI,MAAM,2BAA2B;AAAA,IAC7C;AACA,WAAO,IAAI,cAAc,MAAM;AAAA,EACjC;AACF;AAIA,MAAM,aAA2B,CAAA;AAEjC,MAAM,sBAAsBA,MAAAA;AAAAA,EAC1B;AAAA,EACA,CAAC,KAAK,KAAK,YAAwC;AACjD,QAAI,WAAW,CAAC,UAAU;AACxB,aAAO;AAAA,QACL,GAAG;AAAA,QACH,GAAG;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StoreApi } from 'zustand';
|
|
2
|
-
import { ColumnSpec } from './utils';
|
|
3
|
-
import { DataSheetProviderProps, DataSheetStore } from './types.ts';
|
|
4
|
-
import { TableAction } from './actions';
|
|
5
|
-
/** Create a Jotai scoped store */
|
|
6
|
-
export declare const ctx: import('@macrostrat/data-components').StateIsolation;
|
|
7
|
-
export declare const storeAPIAtom: import('jotai').PrimitiveAtom<StoreApi<DataSheetStore<any>> | undefined> & {
|
|
8
|
-
init: StoreApi<DataSheetStore<any>> | undefined;
|
|
9
|
-
};
|
|
10
|
-
/** This is the basis for all other atoms that manipulate the store. */
|
|
11
|
-
export declare const storeAtom: import('jotai').WritableAtom<DataSheetStore<any> | undefined, [action: any], void>;
|
|
12
|
-
export declare const tableActionsAtom: import('jotai').PrimitiveAtom<TableAction<any, null>[]> & {
|
|
13
|
-
init: TableAction<any, null>[];
|
|
14
|
-
};
|
|
15
|
-
export declare function DataSheetProvider<T>(props: DataSheetProviderProps<T>): import('react').FunctionComponentElement<{
|
|
16
|
-
children: import('react').ReactNode;
|
|
17
|
-
atoms?: import('@macrostrat/data-components').AtomMap;
|
|
18
|
-
keepUpdated?: boolean;
|
|
19
|
-
inherit?: boolean;
|
|
20
|
-
}>;
|
|
21
|
-
export declare function DataSheetProviderInner<T>({ children, data, columnSpec, columnSpecOptions, editable, enableColumnReordering, defaultColumnWidth, }: DataSheetProviderProps<T>): import('react').ReactNode;
|
|
22
|
-
export declare function useStoreAPI<T>(): StoreApi<DataSheetStore<T>>;
|
|
23
|
-
export declare function useSelector<T = any, A = any>(selector: (state: DataSheetStore<T> & DataSheetComputedVals) => A): A;
|
|
24
|
-
/** Atoms for efficient sub-selection of state */
|
|
25
|
-
export declare const columnSpecAtom: import('jotai').Atom<ColumnSpec[]>;
|
|
26
|
-
export declare const tableDataAtom: import('jotai').WritableAtom<any[], [newData: any[]], void>;
|
package/dist/provider.js
DELETED
|
@@ -1,195 +0,0 @@
|
|
|
1
|
-
import { useState, useRef, useEffect } from "react";
|
|
2
|
-
import h from "@macrostrat/hyper";
|
|
3
|
-
import { createStore, useStore } from "zustand";
|
|
4
|
-
import { createScopedStore } from "@macrostrat/data-components";
|
|
5
|
-
import { TableElementStatus, DS_ROW_ID } from "./types.js";
|
|
6
|
-
import { createZustandStore } from "./zustand-store.js";
|
|
7
|
-
import { atomWithStore } from "jotai-zustand";
|
|
8
|
-
import { toasterAtom } from "./notifications.js";
|
|
9
|
-
import { atom } from "jotai";
|
|
10
|
-
import { generateColumnSpec } from "./utils/column-spec.js";
|
|
11
|
-
const ctx = createScopedStore();
|
|
12
|
-
const storeAPIAtom = atom();
|
|
13
|
-
const storeWrapperAtom = atom((get) => {
|
|
14
|
-
const _storeAPIAtom = get(storeAPIAtom);
|
|
15
|
-
if (_storeAPIAtom == null) {
|
|
16
|
-
return void 0;
|
|
17
|
-
}
|
|
18
|
-
return atomWithStore(_storeAPIAtom);
|
|
19
|
-
});
|
|
20
|
-
const storeAtom = atom(
|
|
21
|
-
(get) => {
|
|
22
|
-
const storeWrapper = get(storeWrapperAtom);
|
|
23
|
-
if (storeWrapper == null) {
|
|
24
|
-
return void 0;
|
|
25
|
-
}
|
|
26
|
-
return get(storeWrapper);
|
|
27
|
-
},
|
|
28
|
-
(get, set, action) => {
|
|
29
|
-
const storeWrapper = get(storeWrapperAtom);
|
|
30
|
-
if (storeWrapper == null) {
|
|
31
|
-
throw new Error("Missing DataSheetProvider");
|
|
32
|
-
}
|
|
33
|
-
return set(storeWrapper, action);
|
|
34
|
-
}
|
|
35
|
-
);
|
|
36
|
-
const EMPTY_SPEC = [];
|
|
37
|
-
const initializeStoreAtom = atom(
|
|
38
|
-
null,
|
|
39
|
-
(get, set, payload) => {
|
|
40
|
-
set(storeAtom, (state) => {
|
|
41
|
-
return {
|
|
42
|
-
...state,
|
|
43
|
-
...payload
|
|
44
|
-
};
|
|
45
|
-
});
|
|
46
|
-
}
|
|
47
|
-
);
|
|
48
|
-
const tableActionsAtom = atom([]);
|
|
49
|
-
function DataSheetProvider(props) {
|
|
50
|
-
const { toaster, ...rest } = props;
|
|
51
|
-
const [store] = useState(() => {
|
|
52
|
-
return createStore(createZustandStore);
|
|
53
|
-
});
|
|
54
|
-
return h(
|
|
55
|
-
ctx.Provider,
|
|
56
|
-
{
|
|
57
|
-
atoms: [
|
|
58
|
-
[storeAPIAtom, store],
|
|
59
|
-
[toasterAtom, toaster]
|
|
60
|
-
]
|
|
61
|
-
},
|
|
62
|
-
h(DataSheetProviderInner, rest)
|
|
63
|
-
);
|
|
64
|
-
}
|
|
65
|
-
function DataSheetProviderInner({
|
|
66
|
-
children,
|
|
67
|
-
data,
|
|
68
|
-
columnSpec,
|
|
69
|
-
columnSpecOptions,
|
|
70
|
-
editable,
|
|
71
|
-
enableColumnReordering,
|
|
72
|
-
defaultColumnWidth = 150
|
|
73
|
-
}) {
|
|
74
|
-
const tableRef = useRef(null);
|
|
75
|
-
const initializeStore = ctx.useSet(initializeStoreAtom);
|
|
76
|
-
const isFnSpec = typeof columnSpec === "function";
|
|
77
|
-
const staticSpec = isFnSpec ? EMPTY_SPEC : columnSpec;
|
|
78
|
-
useEffect(() => {
|
|
79
|
-
initializeStore({
|
|
80
|
-
columnSpec: staticSpec ?? generateColumnSpec(data, columnSpecOptions),
|
|
81
|
-
// A function spec is derived from the loaded rows in `_DataSheet`; tell
|
|
82
|
-
// the loader not to auto-generate a plain spec from the first chunk.
|
|
83
|
-
deferColumnSpec: isFnSpec,
|
|
84
|
-
editable,
|
|
85
|
-
enableColumnReordering,
|
|
86
|
-
data,
|
|
87
|
-
defaultColumnWidth,
|
|
88
|
-
tableRef
|
|
89
|
-
});
|
|
90
|
-
}, [data, editable, staticSpec, isFnSpec, columnSpecOptions, enableColumnReordering]);
|
|
91
|
-
return children;
|
|
92
|
-
}
|
|
93
|
-
function useStoreAPI() {
|
|
94
|
-
const store = ctx.useValue(storeAPIAtom);
|
|
95
|
-
if (!store) {
|
|
96
|
-
throw new Error("Missing DataSheetProvider");
|
|
97
|
-
}
|
|
98
|
-
return store;
|
|
99
|
-
}
|
|
100
|
-
function useSelector(selector) {
|
|
101
|
-
const store = useStoreAPI();
|
|
102
|
-
return useStore(store, selector);
|
|
103
|
-
}
|
|
104
|
-
const columnSpecAtom = atom((get) => get(storeAtom)?.columnSpec ?? []);
|
|
105
|
-
const tableDataAtom = atom(
|
|
106
|
-
(get) => {
|
|
107
|
-
return get(storeAtom)?.data ?? [];
|
|
108
|
-
},
|
|
109
|
-
(get, set, newData) => {
|
|
110
|
-
set(storeAtom, (state) => {
|
|
111
|
-
let next = { ...state, data: newData };
|
|
112
|
-
if (state.data.length == 0 && newData.length > 0 && state.columnSpec.length == 0 && !state.deferColumnSpec) {
|
|
113
|
-
next.columnSpec = generateColumnSpec(newData, state.columnSpecOptions);
|
|
114
|
-
}
|
|
115
|
-
if (!state.controlledOverlay) {
|
|
116
|
-
const remap = remapOverlayByIdentity(state, newData);
|
|
117
|
-
next.data = remap.data;
|
|
118
|
-
next.updatedData = remap.updatedData;
|
|
119
|
-
next.rowStatus = remap.rowStatus;
|
|
120
|
-
next.pendingOverlayById = remap.pending;
|
|
121
|
-
}
|
|
122
|
-
return next;
|
|
123
|
-
});
|
|
124
|
-
}
|
|
125
|
-
);
|
|
126
|
-
function overlayIdentity(state, row) {
|
|
127
|
-
if (row == null) return void 0;
|
|
128
|
-
const added = row[DS_ROW_ID];
|
|
129
|
-
if (added != null) return added;
|
|
130
|
-
return state.identity(row);
|
|
131
|
-
}
|
|
132
|
-
function remapOverlayByIdentity(state, newData) {
|
|
133
|
-
const { data: oldData, updatedData, rowStatus } = state;
|
|
134
|
-
const byId = new Map(state.pendingOverlayById);
|
|
135
|
-
const n = Math.max(
|
|
136
|
-
oldData.length,
|
|
137
|
-
updatedData?.length ?? 0,
|
|
138
|
-
rowStatus?.length ?? 0
|
|
139
|
-
);
|
|
140
|
-
for (let i = 0; i < n; i++) {
|
|
141
|
-
const row = oldData[i];
|
|
142
|
-
if (row == null) continue;
|
|
143
|
-
const id = overlayIdentity(state, row);
|
|
144
|
-
if (id == null) continue;
|
|
145
|
-
const edit = updatedData?.[i];
|
|
146
|
-
const status = rowStatus?.[i];
|
|
147
|
-
if (edit != null || status != null) byId.set(id, { edit, status });
|
|
148
|
-
}
|
|
149
|
-
const resultData = newData.slice();
|
|
150
|
-
const nextUpdated = [];
|
|
151
|
-
const nextStatus = [];
|
|
152
|
-
const attached = /* @__PURE__ */ new Set();
|
|
153
|
-
for (let j = 0; j < resultData.length; j++) {
|
|
154
|
-
const row = resultData[j];
|
|
155
|
-
if (row == null) continue;
|
|
156
|
-
const id = overlayIdentity(state, row);
|
|
157
|
-
if (id == null) continue;
|
|
158
|
-
const entry = byId.get(id);
|
|
159
|
-
if (entry == null) continue;
|
|
160
|
-
if (entry.edit != null) nextUpdated[j] = entry.edit;
|
|
161
|
-
if (entry.status != null) nextStatus[j] = entry.status;
|
|
162
|
-
attached.add(id);
|
|
163
|
-
}
|
|
164
|
-
const pending = /* @__PURE__ */ new Map();
|
|
165
|
-
for (const [id, entry] of byId) {
|
|
166
|
-
if (attached.has(id)) continue;
|
|
167
|
-
if (entry.status === TableElementStatus.ADDED) {
|
|
168
|
-
const idx = resultData.length;
|
|
169
|
-
resultData.push(entry.edit ?? {});
|
|
170
|
-
nextUpdated[idx] = entry.edit;
|
|
171
|
-
nextStatus[idx] = entry.status;
|
|
172
|
-
} else {
|
|
173
|
-
pending.set(id, entry);
|
|
174
|
-
}
|
|
175
|
-
}
|
|
176
|
-
return {
|
|
177
|
-
data: resultData,
|
|
178
|
-
updatedData: nextUpdated,
|
|
179
|
-
rowStatus: nextStatus,
|
|
180
|
-
pending
|
|
181
|
-
};
|
|
182
|
-
}
|
|
183
|
-
export {
|
|
184
|
-
DataSheetProvider,
|
|
185
|
-
DataSheetProviderInner,
|
|
186
|
-
columnSpecAtom,
|
|
187
|
-
ctx,
|
|
188
|
-
storeAPIAtom,
|
|
189
|
-
storeAtom,
|
|
190
|
-
tableActionsAtom,
|
|
191
|
-
tableDataAtom,
|
|
192
|
-
useSelector,
|
|
193
|
-
useStoreAPI
|
|
194
|
-
};
|
|
195
|
-
//# sourceMappingURL=provider.js.map
|
package/dist/provider.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"provider.js","sources":["../src/provider.ts"],"sourcesContent":["import { SetStateAction, useEffect, useRef, useState } from \"react\";\nimport h from \"@macrostrat/hyper\";\nimport { createStore, StoreApi, useStore } from \"zustand\";\nimport type { Table } from \"@blueprintjs/table\";\nimport { generateColumnSpec, type ColumnSpec } from \"./utils\";\nimport { createScopedStore } from \"@macrostrat/data-components\";\nimport {\n DataSheetProviderProps,\n DataSheetState,\n DataSheetStore,\n DS_ROW_ID,\n TableElementStatus,\n} from \"./types.ts\";\nimport { createZustandStore } from \"./zustand-store.ts\";\nimport { atomWithStore } from \"jotai-zustand\";\nimport { toasterAtom } from \"./notifications.ts\";\nimport { TableAction } from \"./actions\";\nimport { atom } from \"jotai\";\n\n/** Create a Jotai scoped store */\nexport const ctx = createScopedStore();\n\nexport const storeAPIAtom = atom<StoreApi<DataSheetStore<any>>>();\n\nconst storeWrapperAtom = atom((get) => {\n const _storeAPIAtom = get(storeAPIAtom);\n if (_storeAPIAtom == null) {\n return undefined;\n }\n return atomWithStore(_storeAPIAtom);\n});\n\n/** This is the basis for all other atoms that manipulate the store. */\nexport const storeAtom = atom(\n (get) => {\n const storeWrapper = get(storeWrapperAtom);\n if (storeWrapper == null) {\n return undefined;\n }\n return get(storeWrapper);\n },\n (get, set, action: SetStateAction<T>) => {\n const storeWrapper = get(storeWrapperAtom);\n if (storeWrapper == null) {\n throw new Error(\"Missing DataSheetProvider\");\n }\n return set(storeWrapper, action);\n },\n);\n\n/** Stable empty spec so a function `columnSpec` yields a constant init value\n * (see `DataSheetProviderInner`). */\nconst EMPTY_SPEC: ColumnSpec[] = [];\n\nconst initializeStoreAtom = atom(\n null,\n (get, set, payload: Partial<DataSheetStore<T>>) => {\n set(storeAtom, (state) => {\n return {\n ...state,\n ...payload,\n };\n });\n },\n);\n\nexport const tableActionsAtom = atom<TableAction[]>([]);\n\nexport function DataSheetProvider<T>(props: DataSheetProviderProps<T>) {\n const { toaster, ...rest } = props;\n const [store] = useState(() => {\n return createStore<DataSheetStore<T>>(createZustandStore);\n });\n return h(\n ctx.Provider,\n {\n atoms: [\n [storeAPIAtom, store],\n [toasterAtom, toaster],\n ],\n },\n h(DataSheetProviderInner, rest),\n );\n}\n\nexport function DataSheetProviderInner<T>({\n children,\n data,\n columnSpec,\n columnSpecOptions,\n editable,\n enableColumnReordering,\n defaultColumnWidth = 150,\n}: DataSheetProviderProps<T>) {\n const tableRef = useRef<Table>(null);\n\n const initializeStore = ctx.useSet(initializeStoreAtom);\n\n // A function `columnSpec` is derived from the loaded rows later (in\n // `_DataSheet`), not here — start it empty. Crucially it's kept OUT of the\n // init effect's deps: re-running init also resets `data`, so re-initializing\n // when the function's identity changes (e.g. a consumer hiding a column)\n // would wipe the loaded rows. `staticSpec` is a stable value in that case.\n const isFnSpec = typeof columnSpec === \"function\";\n const staticSpec = isFnSpec ? EMPTY_SPEC : columnSpec;\n\n // Not sure how required this initialization is\n useEffect(() => {\n initializeStore({\n columnSpec: staticSpec ?? generateColumnSpec(data, columnSpecOptions),\n // A function spec is derived from the loaded rows in `_DataSheet`; tell\n // the loader not to auto-generate a plain spec from the first chunk.\n deferColumnSpec: isFnSpec,\n editable,\n enableColumnReordering,\n data,\n defaultColumnWidth,\n tableRef,\n });\n }, [data, editable, staticSpec, isFnSpec, columnSpecOptions, enableColumnReordering]);\n\n return children;\n}\n\nexport function useStoreAPI<T>(): StoreApi<DataSheetStore<T>> {\n const store = ctx.useValue(storeAPIAtom);\n if (!store) {\n throw new Error(\"Missing DataSheetProvider\");\n }\n return store;\n}\n\nexport function useSelector<T = any, A = any>(\n selector: (state: DataSheetStore<T> & DataSheetComputedVals) => A,\n): A {\n const store = useStoreAPI<T>();\n return useStore(store, selector);\n}\n/** Atoms for efficient sub-selection of state */\n\nexport const columnSpecAtom = atom((get) => get(storeAtom)?.columnSpec ?? []);\n\nexport const tableDataAtom = atom(\n (get) => {\n return get(storeAtom)?.data ?? [];\n },\n (get, set, newData: any[]) => {\n set(storeAtom, (state: DataSheetState<any>): DataSheetState<any> => {\n let next: DataSheetState<any> = { ...state, data: newData };\n if (\n state.data.length == 0 &&\n newData.length > 0 &&\n state.columnSpec.length == 0 &&\n !state.deferColumnSpec\n ) {\n // No spec yet and none deferred to a function — auto-generate a plain\n // spec from the first chunk. (A function spec is derived separately.)\n next.columnSpec = generateColumnSpec(newData, state.columnSpecOptions);\n }\n\n // Re-attach the edit overlay by identity. The loader replaces `data` with\n // re-ordered windows on sort/filter, so an index-keyed overlay would\n // smear; keying by identity keeps edits (and deletes) on their rows, holds\n // edits for not-yet-loaded rows, and re-appends locally-added rows (which\n // aren't in the provider's data) after it. Skipped when the consumer\n // controls the overlay (they own reconciliation).\n if (!state.controlledOverlay) {\n const remap = remapOverlayByIdentity(state, newData);\n next.data = remap.data;\n next.updatedData = remap.updatedData;\n next.rowStatus = remap.rowStatus;\n next.pendingOverlayById = remap.pending;\n }\n\n return next;\n });\n },\n);\n\ntype OverlayEntry = { edit?: any; status?: any };\n\n/** Row identity used by the overlay: an in-table-added row's synthetic id\n * (stable across its edits), else the provider/consumer `identity`. */\nfunction overlayIdentity(\n state: DataSheetState<any>,\n row: any,\n): string | number | null | undefined {\n if (row == null) return undefined;\n const added = row[DS_ROW_ID];\n if (added != null) return added;\n return state.identity(row);\n}\n\n/** Re-project the (index-keyed) edit overlay from the old `data` order onto a\n * new one, matching rows by identity. Edits/statuses whose row is absent from\n * `newData` are held in `pending` and re-applied when the row loads; rows added\n * in-table (status `ADDED`) are re-appended after the provider data (they have\n * no provider row). Starts from the prior pending set so edits survive multiple\n * re-sorts. Returns the reconstructed data (provider rows + re-appended added\n * rows) alongside the re-aligned overlay. */\nfunction remapOverlayByIdentity(\n state: DataSheetState<any>,\n newData: any[],\n): {\n data: any[];\n updatedData: any[];\n rowStatus: any[];\n pending: Map<string | number, OverlayEntry>;\n} {\n const { data: oldData, updatedData, rowStatus } = state;\n\n // Collect current overlay entries by identity, seeded with prior pending.\n const byId = new Map<string | number, OverlayEntry>(state.pendingOverlayById);\n const n = Math.max(\n oldData.length,\n updatedData?.length ?? 0,\n rowStatus?.length ?? 0,\n );\n for (let i = 0; i < n; i++) {\n const row = oldData[i];\n if (row == null) continue;\n const id = overlayIdentity(state, row);\n if (id == null) continue;\n const edit = updatedData?.[i];\n const status = rowStatus?.[i];\n if (edit != null || status != null) byId.set(id, { edit, status });\n }\n\n // Project onto the new data order.\n const resultData = newData.slice();\n const nextUpdated: any[] = [];\n const nextStatus: any[] = [];\n const attached = new Set<string | number>();\n for (let j = 0; j < resultData.length; j++) {\n const row = resultData[j];\n if (row == null) continue;\n const id = overlayIdentity(state, row);\n if (id == null) continue;\n const entry = byId.get(id);\n if (entry == null) continue;\n if (entry.edit != null) nextUpdated[j] = entry.edit;\n if (entry.status != null) nextStatus[j] = entry.status;\n attached.add(id);\n }\n\n // Re-append in-table-added rows (not present in the provider data), then hold\n // anything still unattached (rows not currently loaded) as pending.\n const pending = new Map<string | number, OverlayEntry>();\n for (const [id, entry] of byId) {\n if (attached.has(id)) continue;\n if (entry.status === TableElementStatus.ADDED) {\n const idx = resultData.length;\n resultData.push(entry.edit ?? {});\n nextUpdated[idx] = entry.edit;\n nextStatus[idx] = entry.status;\n } else {\n pending.set(id, entry);\n }\n }\n\n return {\n data: resultData,\n updatedData: nextUpdated,\n rowStatus: nextStatus,\n pending,\n };\n}\n"],"names":[],"mappings":";;;;;;;;;;AAoBO,MAAM,MAAM,kBAAA;AAEZ,MAAM,eAAe,KAAA;AAE5B,MAAM,mBAAmB,KAAK,CAAC,QAAQ;AACrC,QAAM,gBAAgB,IAAI,YAAY;AACtC,MAAI,iBAAiB,MAAM;AACzB,WAAO;AAAA,EACT;AACA,SAAO,cAAc,aAAa;AACpC,CAAC;AAGM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AO;AAC7C,YAAM,MAAM,WAAW;AACvB,iBAAW,KAAK,MAAM,QAAQ,CAAA,CAAE;AAChC,kBAAY,GAAG,IAAI,MAAM;AACzB,iBAAW,GAAG,IAAI,MAAM;AAAA,IAC1B,OAAO;AACL,cAAQ,IAAI,IAAI,KAAK;AAAA,IACvB;AAAA,EACF;AAEA,SAAO;AAAA,IACL,MAAM;AAAA,IACN,aAAa;AAAA,IACb,WAAW;AAAA,IACX;AAAA,EAAA;AAEJ;"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { Filter } from './filter';
|
|
2
|
-
interface DataParameters {
|
|
3
|
-
group?: string;
|
|
4
|
-
select: {
|
|
5
|
-
page?: string;
|
|
6
|
-
pageSize?: string;
|
|
7
|
-
};
|
|
8
|
-
filter: {
|
|
9
|
-
[key: string]: Filter;
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
declare const cloneDataParameters: (dataParameters: DataParameters) => DataParameters;
|
|
13
|
-
export declare const isColumnActive: (dataParameters: DataParameters, column: string) => boolean;
|
|
14
|
-
export { cloneDataParameters, DataParameters };
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { ColumnOperators } from '../tables/defs';
|
|
2
|
-
export declare class Filter {
|
|
3
|
-
readonly column_name: string;
|
|
4
|
-
readonly operator: ColumnOperators | undefined;
|
|
5
|
-
readonly value: string | boolean | number | null;
|
|
6
|
-
constructor(column_name: string, operator: ColumnOperators | undefined, value: string | boolean | number | null);
|
|
7
|
-
get formattedValue(): string | number | boolean | null;
|
|
8
|
-
get urlValue(): string;
|
|
9
|
-
clone: () => Filter;
|
|
10
|
-
passes: (data: Record<string, string | boolean | number | null>) => boolean;
|
|
11
|
-
is_valid: () => boolean;
|
|
12
|
-
to_array: () => string[];
|
|
13
|
-
}
|
|
14
|
-
export declare const addFilterToURL: (url: URL, filter: Filter) => URL;
|
|
15
|
-
export declare const createFiltersKey: (filters: Filter[]) => string;
|
|
16
|
-
export declare const rowPassesFilters: (row: Record<string, string | boolean | number | null>, filters: Filter[] | undefined) => boolean;
|
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { Filter } from './filter';
|
|
2
|
-
import { DataParameters } from './data-parameter';
|
|
3
|
-
import { ProgressPopoverProps } from '#/maps/ingestion/@id/components';
|
|
4
|
-
export interface TableUpdate {
|
|
5
|
-
key?: string;
|
|
6
|
-
column: string;
|
|
7
|
-
description?: string;
|
|
8
|
-
execute: () => Promise<void>;
|
|
9
|
-
applyToCell: (currentValue: boolean | string | number | null, row: Record<string, boolean | string | number | null>, cellColumnName: string) => string;
|
|
10
|
-
}
|
|
11
|
-
export declare const applyTableUpdate: (data: Record<string, boolean | string | number | null>[], tableUpdate: TableUpdate) => Record<string, string | number | boolean | null>[];
|
|
12
|
-
export declare const applyTableUpdates: (data: Record<string, boolean | string | number | null>[], tableUpdates: TableUpdate[]) => Record<string, string | number | boolean | null>[];
|
|
13
|
-
export declare const createTableUpdateCopyColumn: (url: string, selectedColumn: string, copiedColumn: string, dataParameters: DataParameters) => TableUpdate;
|
|
14
|
-
export declare const createTableUpdate: (url: string, value: string, columnName: string, row: Record<string, boolean | string | number | null>, dataParameters: DataParameters) => TableUpdate;
|
|
15
|
-
export declare const submitChange: (url: string, value: string, columns: string[], filters: {
|
|
16
|
-
[key: string]: Filter;
|
|
17
|
-
}) => Promise<void>;
|
|
18
|
-
export declare const squashTableUpdates: (tableUpdates: TableUpdate[]) => TableUpdate[];
|
|
19
|
-
export declare const submitTableUpdates: (tableUpdates: TableUpdate[], setProgress: (p: ProgressPopoverProps) => void) => Promise<TableUpdate[]>;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"column-spec.cjs","sources":["../../src/utils/column-spec.ts"],"sourcesContent":["import React from \"react\";\n\nconst 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\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (\n d: any,\n ctx?: CellRenderContext,\n ) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n /** Whether this column may be drag-reordered. Defaults to `true`; set\n * `false` to pin a fixed/system column in place. Applied by the default\n * header renderer (requires table-level `enableColumnReordering`). */\n reorderable?: boolean;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): 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\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\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\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\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 // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\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 let width = null;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: ColumnSpecOptions<T>,\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const {\n overrides = {},\n nRows = 10,\n omitColumns,\n includeColumns,\n } = 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":[],"mappings":";;AAEA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AA4KpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EAAA,IACjB;AAEJ,QAAM,2BAAW,IAAA;AACjB,QAAM,4BAAY,IAAA;AAElB,QAAM,mCAAmB,IAAA;AAEzB,aAAW,OAAO,MAAM;AACtB,QAAI,OAAO,KAAM;AACjB,eAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAM,MAAM,IAAI,GAAG;AACnB,WAAK,IAAI,GAAG;AAEZ,UAAI,OAAO,KAAM;AAEjB,UAAI,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AiB,MAAM,IAAI,GAAG,CAAC;AAAA,MAC9C;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV,YAAY;AAAA,IAAA,CACb;AAAA,EACH;AACA,SAAO;AACT;AAEO,SAAS,mBACd,MACA,SACc;AAEd,QAAM;AAAA,IACJ,YAAY,CAAA;AAAA,IACZ,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EAAA,IACE,WAAW,CAAA;AAEf,MAAI,QAAQ,KAAM,QAAO,CAAA;AAEzB,QAAM,SAAS,KAAK,IAAI,OAAO,KAAK,MAAM;AAE1C,MAAI,aAAa,0BAA0B,KAAK,MAAM,GAAG,MAAM,CAAC;AAChE,MAAI,eAAe,WAAW,OAAO,CAAC,QAAQ;AAC5C,QAAI,eAAe,QAAQ,YAAY,SAAS,IAAI,GAAG,GAAG;AACxD,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ,CAAC,eAAe,SAAS,IAAI,GAAG,GAAG;AAC/D,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AAGD,SAAO,aAAa,IAAI,CAAC,QAAQ;AAC/B,QAAI,MAAM,UAAU,IAAI,GAAG;AAC3B,QAAI,OAAO,KAAM,QAAO;AACxB,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,EAAE,GAAG,KAAK,MAAM,IAAA;AAAA,IACzB;AACA,WAAO,EAAE,GAAG,KAAK,GAAG,IAAA;AAAA,EACtB,CAAC;AACH;;;"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"column-spec.js","sources":["../../src/utils/column-spec.ts"],"sourcesContent":["import React from \"react\";\n\nconst 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\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (\n d: any,\n ctx?: CellRenderContext,\n ) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n /** Whether this column may be drag-reordered. Defaults to `true`; set\n * `false` to pin a fixed/system column in place. Applied by the default\n * header renderer (requires table-level `enableColumnReordering`). */\n reorderable?: boolean;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): 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\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\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\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\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 // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\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 let width = null;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: ColumnSpecOptions<T>,\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const {\n overrides = {},\n nRows = 10,\n omitColumns,\n includeColumns,\n } = 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":[],"mappings":"AAEA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AA4KpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EAAA,IACjB;AAEJ,QAAM,2BAAW,IAAA;AACjB,QAAM,4BAAY,IAAA;AAElB,QAAM,mCAAmB,IAAA;AAEzB,aAAW,OAAO,MAAM;AACtB,QAAI,OAAO,KAAM;AACjB,eAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAM,MAAM,IAAI,GAAG;AACnB,WAAK,IAAI,GAAG;AAEZ,UAAI,OAAO,KAAM;AAEjB,UAAI,iBAAiB;AACnB,YAAI,QAAQ,iBAAiB,GAAG;AAChC,YAAI,SAAS,QAAQ,SAAS,GAAG;AAC/B,u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AAA,IAAA,CACb;AAAA,EACH;AACA,SAAO;AACT;AAEO,SAAS,mBACd,MACA,SACc;AAEd,QAAM;AAAA,IACJ,YAAY,CAAA;AAAA,IACZ,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EAAA,IACE,WAAW,CAAA;AAEf,MAAI,QAAQ,KAAM,QAAO,CAAA;AAEzB,QAAM,SAAS,KAAK,IAAI,OAAO,KAAK,MAAM;AAE1C,MAAI,aAAa,0BAA0B,KAAK,MAAM,GAAG,MAAM,CAAC;AAChE,MAAI,eAAe,WAAW,OAAO,CAAC,QAAQ;AAC5C,QAAI,eAAe,QAAQ,YAAY,SAAS,IAAI,GAAG,GAAG;AACxD,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ,CAAC,eAAe,SAAS,IAAI,GAAG,GAAG;AAC/D,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AAGD,SAAO,aAAa,IAAI,CAAC,QAAQ;AAC/B,QAAI,MAAM,UAAU,IAAI,GAAG;AAC3B,QAAI,OAAO,KAAM,QAAO;AACxB,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,EAAE,GAAG,KAAK,MAAM,IAAA;AAAA,IACzB;AACA,WAAO,EAAE,GAAG,KAAK,GAAG,IAAA;AAAA,EACtB,CAAC;AACH;"}
|
package/dist/utils/index.cjs
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
-
function range(arr) {
|
|
4
|
-
if (arr.length != 2) throw new Error("Range must have two elements");
|
|
5
|
-
const [start, end] = arr;
|
|
6
|
-
return Array.from({ length: end - start + 1 }, (_, i) => i + start);
|
|
7
|
-
}
|
|
8
|
-
exports.range = range;
|
|
9
|
-
//# sourceMappingURL=index.cjs.map
|
package/dist/utils/index.cjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./column-spec\";\nexport * from \"./key-handling\";\nexport * from \"./validation\";\nexport { CellRendererDebugOverlay } from \"./debug-overlay.ts\";\n\nexport function range(arr: number[]) {\n if (arr.length != 2) throw new Error(\"Range must have two elements\");\n const [start, end] = arr;\n return Array.from({ length: end - start + 1 }, (_, i) => i + start);\n}\n"],"names":[],"mappings":";;AAKO,SAAS,MAAM,KAAe;AACnC,MAAI,IAAI,UAAU,EAAG,OAAM,IAAI,MAAM,8BAA8B;AACnE,QAAM,CAAC,OAAO,GAAG,IAAI;AACrB,SAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,QAAQ,EAAA,GAAK,CAAC,GAAG,MAAM,IAAI,KAAK;AACpE;;"}
|
package/dist/utils/index.js
DELETED
package/dist/utils/index.js.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../src/utils/index.ts"],"sourcesContent":["export * from \"./column-spec\";\nexport * from \"./key-handling\";\nexport * from \"./validation\";\nexport { CellRendererDebugOverlay } from \"./debug-overlay.ts\";\n\nexport function range(arr: number[]) {\n if (arr.length != 2) throw new Error(\"Range must have two elements\");\n const [start, end] = arr;\n return Array.from({ length: end - start + 1 }, (_, i) => i + start);\n}\n"],"names":[],"mappings":"AAKO,SAAS,MAAM,KAAe;AACnC,MAAI,IAAI,UAAU,EAAG,OAAM,IAAI,MAAM,8BAA8B;AACnE,QAAM,CAAC,OAAO,GAAG,IAAI;AACrB,SAAO,MAAM,KAAK,EAAE,QAAQ,MAAM,QAAQ,EAAA,GAAK,CAAC,GAAG,MAAM,IAAI,KAAK;AACpE;"}
|