@macrostrat/data-sheet 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +13 -6
- package/dist/{actions.5740e8e2.js → esm/actions.065d098d.js} +5 -5
- package/dist/{actions.5740e8e2.js.map → esm/actions.065d098d.js.map} +1 -1
- package/dist/{actions.module.ea96403b.js → esm/actions.module.560a3136.js} +1 -1
- package/dist/{actions.module.ea96403b.js.map → esm/actions.module.560a3136.js.map} +1 -1
- package/dist/{actions.module.6ec06797.css → esm/actions.module.684172fa.css} +1 -1
- package/dist/{actions.module.6ec06797.css.map → esm/actions.module.684172fa.css.map} +1 -1
- package/dist/esm/cell-renderers.8222e82a.js +31 -0
- package/dist/{cell-renderers.de70f471.js.map → esm/cell-renderers.8222e82a.js.map} +1 -1
- package/dist/{colors.41c3ed7a.js → esm/colors.75a92ad3.js} +20 -20
- package/dist/{colors.41c3ed7a.js.map → esm/colors.75a92ad3.js.map} +1 -1
- package/dist/{column-spec.4710da93.js → esm/column-spec.e56f4d75.js} +1 -1
- package/dist/{column-spec.4710da93.js.map → esm/column-spec.e56f4d75.js.map} +1 -1
- package/dist/{components.c3ad66e9.js → esm/components.f832ecf3.js} +4 -4
- package/dist/{components.c3ad66e9.js.map → esm/components.f832ecf3.js.map} +1 -1
- package/dist/{core.d8d80480.js → esm/core.c9bdeacd.js} +36 -36
- package/dist/{core.d8d80480.js.map → esm/core.c9bdeacd.js.map} +1 -1
- package/dist/{data-loaders.5302dedd.js → esm/data-loaders.b7de291b.js} +13 -13
- package/dist/{data-loaders.5302dedd.js.map → esm/data-loaders.b7de291b.js.map} +1 -1
- package/dist/{editor-popup.9259608f.js → esm/editor-popup.819ce365.js} +12 -12
- package/dist/{editor-popup.9259608f.js.map → esm/editor-popup.819ce365.js.map} +1 -1
- package/dist/{index.js → esm/index.js} +2 -2
- package/dist/{main.module.846377cd.css → esm/main.module.658cf7b2.css} +1 -1
- package/dist/{main.module.846377cd.css.map → esm/main.module.658cf7b2.css.map} +1 -1
- package/dist/{main.module.93f91ad4.js → esm/main.module.7e0903d4.js} +1 -1
- package/dist/{main.module.93f91ad4.js.map → esm/main.module.7e0903d4.js.map} +1 -1
- package/dist/{main.module.ff717a08.js → esm/main.module.83442ac4.js} +1 -1
- package/dist/{main.module.ff717a08.js.map → esm/main.module.83442ac4.js.map} +1 -1
- package/dist/{main.module.914caa19.css → esm/main.module.b66a4bc1.css} +1 -1
- package/dist/{main.module.914caa19.css.map → esm/main.module.b66a4bc1.css.map} +1 -1
- package/dist/{main.module.de002429.js → esm/main.module.bd60788c.js} +1 -1
- package/dist/{main.module.de002429.js.map → esm/main.module.bd60788c.js.map} +1 -1
- package/dist/{main.module.dc8f6293.css → esm/main.module.df43976f.css} +1 -1
- package/dist/{main.module.dc8f6293.css.map → esm/main.module.df43976f.css.map} +1 -1
- package/dist/{postgrest-table.15ded3c1.js → esm/postgrest-table.d1f8b3a4.js} +18 -18
- package/dist/{postgrest-table.15ded3c1.js.map → esm/postgrest-table.d1f8b3a4.js.map} +1 -1
- package/dist/{provider.67e982b8.js → esm/provider.7942302e.js} +20 -20
- package/dist/{provider.67e982b8.js.map → esm/provider.7942302e.js.map} +1 -1
- package/dist/{text-areas.079e8b15.js → esm/text-areas.ccfcf204.js} +10 -10
- package/dist/{text-areas.079e8b15.js.map → esm/text-areas.ccfcf204.js.map} +1 -1
- package/dist/{utils.a37ed786.js → esm/utils.5d81fe80.js} +2 -2
- package/dist/{utils.a37ed786.js.map → esm/utils.5d81fe80.js.map} +1 -1
- package/dist/node/actions.4dfe63d8.js +2 -0
- package/dist/node/actions.4dfe63d8.js.map +1 -0
- package/dist/node/actions.module.565df529.css +2 -0
- package/dist/node/actions.module.565df529.css.map +1 -0
- package/dist/node/actions.module.61991621.js +2 -0
- package/dist/node/actions.module.61991621.js.map +1 -0
- package/dist/node/cell-renderers.bbaaeb83.js +2 -0
- package/dist/node/cell-renderers.bbaaeb83.js.map +1 -0
- package/dist/node/colors.fee61100.js +2 -0
- package/dist/node/colors.fee61100.js.map +1 -0
- package/dist/node/column-spec.da7354f5.js +2 -0
- package/dist/node/column-spec.da7354f5.js.map +1 -0
- package/dist/node/components.213ca3fc.js +2 -0
- package/dist/node/components.213ca3fc.js.map +1 -0
- package/dist/node/core.c404e4d4.js +2 -0
- package/dist/node/core.c404e4d4.js.map +1 -0
- package/dist/node/data-loaders.50ce46a4.js +2 -0
- package/dist/node/data-loaders.50ce46a4.js.map +1 -0
- package/dist/node/editor-popup.e19a3668.js +2 -0
- package/dist/node/editor-popup.e19a3668.js.map +1 -0
- package/dist/node/index.js +2 -0
- package/dist/node/index.js.map +1 -0
- package/dist/node/main.module.0802fb12.js +2 -0
- package/dist/node/main.module.0802fb12.js.map +1 -0
- package/dist/node/main.module.273015bb.js +2 -0
- package/dist/node/main.module.273015bb.js.map +1 -0
- package/dist/node/main.module.4cad6bbb.js +2 -0
- package/dist/node/main.module.4cad6bbb.js.map +1 -0
- package/dist/node/main.module.8370d601.css +2 -0
- package/dist/node/main.module.8370d601.css.map +1 -0
- package/dist/node/main.module.a197ee6f.css +2 -0
- package/dist/node/main.module.a197ee6f.css.map +1 -0
- package/dist/node/main.module.e5354239.css +2 -0
- package/dist/node/main.module.e5354239.css.map +1 -0
- package/dist/node/postgrest-table.49926421.js +2 -0
- package/dist/node/postgrest-table.49926421.js.map +1 -0
- package/dist/node/provider.f11d5828.js +2 -0
- package/dist/node/provider.f11d5828.js.map +1 -0
- package/dist/node/text-areas.64832f7d.js +2 -0
- package/dist/node/text-areas.64832f7d.js.map +1 -0
- package/dist/node/utils.897d92e2.js +2 -0
- package/dist/node/utils.897d92e2.js.map +1 -0
- package/package.json +22 -13
- package/dist/cell-renderers.de70f471.js +0 -31
- /package/dist/{index.d.ts → esm/index.d.ts} +0 -0
- /package/dist/{index.d.ts.map → esm/index.d.ts.map} +0 -0
- /package/dist/{index.js.map → esm/index.js.map} +0 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"A,O,iB,C,K,O,A,O,mB,A,O,S,A,O,qB,C,I,E,W,E,C,E,E,C,E,E,E,iB,A,O,I,A,C,E,S,C,E,G,K,E,O,C,C,E,C,O,C,G,K,E,C,I,E,C,C,E,A,Q,C,C,E,C,I,E,C,G,E,Q,C,C,E,O,C,C,E,C,E,E,I,C,E,O,C,E,E,O,E,E,O,A,C,I,E,A,M,uB,E,I,O,E,I,C,mB,C,C,E,Q,C,S,C,C,C,E,C,C,E,C,C,E,E,iB,C,G,E,Q,CEAiB,AAAA,EAAA,SAAA,YAAA,CAA6C,SD0ErC,AAAA,EAA6C","sources":["<anon>","packages/data-sheet/src/provider.ts","../../../../.yarn/berry/cache/@parcel-runtime-js-npm-2.13.3-f44fec8492-10c0.zip/node_modules/@parcel/runtime-js/lib/runtime-38f0e4138577a82b.js"],"sourcesContent":["import {createContext as $lNLp4$createContext, useRef as $lNLp4$useRef, useState as $lNLp4$useState, useEffect as $lNLp4$useEffect, useContext as $lNLp4$useContext} from \"react\";\nimport $lNLp4$macrostrathyper from \"@macrostrat/hyper\";\nimport {createStore as $lNLp4$createStore, useStore as $lNLp4$useStore} from \"zustand\";\nimport $lNLp4$immutabilityhelper from \"immutability-helper\";\n\n\n var $parcel$global = globalThis;\n \nvar $parcel$modules = {};\nvar $parcel$inits = {};\n\nvar parcelRequire = $parcel$global[\"parcelRequire94c2\"];\n\nif (parcelRequire == null) {\n parcelRequire = function(id) {\n if (id in $parcel$modules) {\n return $parcel$modules[id].exports;\n }\n if (id in $parcel$inits) {\n var init = $parcel$inits[id];\n delete $parcel$inits[id];\n var module = {id: id, exports: {}};\n $parcel$modules[id] = module;\n init.call(module.exports, module, module.exports);\n return module.exports;\n }\n var err = new Error(\"Cannot find module '\" + id + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n };\n\n parcelRequire.register = function register(id, init) {\n $parcel$inits[id] = init;\n };\n\n $parcel$global[\"parcelRequire94c2\"] = parcelRequire;\n}\n\nvar parcelRegister = parcelRequire.register;\n\n\n\nvar $4ce8b14bb4497740$exports = {};\n\n$4ce8b14bb4497740$exports = (parcelRequire(\"daZiC\")).getBundleURL('lNLp4') + \"utils.897d92e2.js\";\n\n\n\nconst $7e5384423bc0f425$var$DataSheetContext = (0, $lNLp4$createContext)(null);\nfunction $7e5384423bc0f425$export$135c527978291360({ children: children, data: data, columnSpec: columnSpec, columnSpecOptions: columnSpecOptions, editable: editable, enableColumnReordering: enableColumnReordering }) {\n const visibleCellsRef = (0, $lNLp4$useRef)({\n rowIndexStart: 0,\n rowIndexEnd: 0\n });\n const tableRef = (0, $lNLp4$useRef)(null);\n const [store] = (0, $lNLp4$useState)(()=>{\n return (0, $lNLp4$createStore)((set)=>{\n return {\n data: data,\n columnSpec: columnSpec ?? (0, $4ce8b14bb4497740$exports.generateColumnSpec)(data, columnSpecOptions),\n editable: editable,\n selection: [],\n fillValueBaseCell: null,\n updatedData: [],\n focusedCell: null,\n topLeftCell: null,\n initialized: false,\n tableRef: tableRef,\n setSelection (selection) {\n set($7e5384423bc0f425$var$updateSelection(selection));\n },\n setUpdatedData (data) {\n set({\n updatedData: data\n });\n },\n setVisibleCells (visibleCells) {\n // Visible cells are used for infinite scrolling\n // Right now we don't store this in the state\n visibleCellsRef.current = visibleCells;\n },\n onDragValue (cell) {\n set({\n fillValueBaseCell: cell\n });\n },\n onCellEdited (rowIndex, columnName, value) {\n set((state)=>{\n const { editable: editable, updatedData: updatedData, data: data } = state;\n if (!editable) return {};\n let rowSpec;\n // Check to see if the new value is the same as the old one\n if (value !== data[rowIndex]?.[columnName]) {\n const rowOp = updatedData[rowIndex] != null ? \"$merge\" : \"$set\";\n rowSpec = {\n [rowOp]: {\n [columnName]: value\n }\n };\n } else rowSpec = {\n $unset: [\n columnName\n ]\n };\n const spec = {\n [rowIndex]: rowSpec\n };\n return {\n updatedData: (0, $lNLp4$immutabilityhelper)(updatedData, spec)\n };\n });\n },\n initialize (props) {\n set({\n ...props,\n initialized: true\n });\n },\n clearSelection () {\n set((state)=>{\n // Delete all selected cells\n const { selection: selection, updatedData: updatedData, columnSpec: columnSpec } = state;\n let spec = {};\n for (const region of selection){\n const { cols: cols, rows: rows } = region;\n for (const row of (0, $4ce8b14bb4497740$exports.range)(rows)){\n let vals = {};\n for (const col of (0, $4ce8b14bb4497740$exports.range)(cols)){\n const key = columnSpec[col].key;\n vals[key] = \"\";\n }\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = {\n [op]: vals\n };\n }\n }\n return {\n updatedData: (0, $lNLp4$immutabilityhelper)(updatedData, spec)\n };\n });\n },\n onSelection (selection) {\n set((state)=>{\n let spec = $7e5384423bc0f425$var$updateSelection(selection);\n if (state.fillValueBaseCell != null) spec.updatedData = $7e5384423bc0f425$var$fillValues(state, selection);\n return spec;\n });\n },\n onColumnsReordered (oldIndex, newIndex, length) {\n set((state)=>{\n if (!state.enableColumnReordering) return {};\n const { columnSpec: columnSpec } = state;\n const newSpec = [\n ...columnSpec\n ];\n const removed = newSpec.splice(oldIndex, length);\n newSpec.splice(newIndex, 0, ...removed);\n return {\n columnSpec: newSpec\n };\n });\n },\n scrollToRow (rowIndex, columnIndex) {\n if (tableRef.current == null) return;\n tableRef.current.scrollToRegion({\n rows: [\n rowIndex,\n rowIndex\n ]\n });\n }\n };\n });\n });\n // Not sure how required this initialization is\n (0, $lNLp4$useEffect)(()=>{\n const { initialize: initialize } = store.getState();\n initialize({\n data: data,\n columnSpec: columnSpec ?? (0, $4ce8b14bb4497740$exports.generateColumnSpec)(data, columnSpecOptions),\n editable: editable,\n enableColumnReordering: enableColumnReordering\n });\n }, [\n data,\n editable,\n columnSpec,\n columnSpecOptions,\n enableColumnReordering\n ]);\n return (0, $lNLp4$macrostrathyper)($7e5384423bc0f425$var$DataSheetContext.Provider, {\n value: store\n }, children);\n}\nfunction $7e5384423bc0f425$export$54fc6f5c8f914926() {\n const store = (0, $lNLp4$useContext)($7e5384423bc0f425$var$DataSheetContext);\n if (!store) throw new Error(\"Missing DataSheetProvider\");\n return store;\n}\nfunction $7e5384423bc0f425$export$2105062e25df4afe(selector) {\n const store = $7e5384423bc0f425$export$54fc6f5c8f914926();\n return (0, $lNLp4$useStore)(store, selector);\n}\nfunction $7e5384423bc0f425$var$updateSelection(selection) {\n const focusedCell = $7e5384423bc0f425$var$singleFocusedCell(selection);\n let spec = {\n selection: selection,\n focusedCell: focusedCell,\n topLeftCell: $7e5384423bc0f425$export$88b0ba8661dc41b4(selection)\n };\n if (focusedCell != null) spec.fillValueBaseCell = null;\n return spec;\n}\nfunction $7e5384423bc0f425$export$88b0ba8661dc41b4(regions, requireSolitaryCell = false) {\n /** Top left cell of a ranged selection */ if (regions == null) return null;\n const [region] = regions;\n if (region == null) return null;\n const { cols: cols, rows: rows } = region;\n if (cols == null || rows == null) return null;\n if (requireSolitaryCell && (cols[0] !== cols[1] || rows[0] !== rows[1])) return null;\n return {\n col: cols[0],\n row: rows[0],\n focusSelectionIndex: 0\n };\n}\nfunction $7e5384423bc0f425$var$singleFocusedCell(sel) {\n /** Derive a single focused cell from a selected region, if possible */ if (sel?.length !== 1) return null;\n return $7e5384423bc0f425$export$88b0ba8661dc41b4(sel, true);\n}\nfunction $7e5384423bc0f425$var$fillValues(state, selection) {\n const { updatedData: updatedData, columnSpec: columnSpec, editable: editable, fillValueBaseCell: fillValueBaseCell, data: data } = state;\n // Prepare regions by unnesting columns\n let regions = selection.map((region)=>{\n const { cols: cols, rows: rows } = region;\n // Get the first column (maybe should be the last)\n const [col] = cols;\n return {\n cols: [\n col,\n col\n ],\n rows: rows\n };\n });\n // Fill values downwards\n if (!editable || fillValueBaseCell == null) return updatedData;\n const { col: col, row: row } = fillValueBaseCell;\n const key = columnSpec[col].key;\n const value = updatedData[row]?.[key] ?? data[row][key];\n const spec = {};\n for (const region of regions){\n const { cols: cols, rows: rows } = region;\n for (const row of (0, $4ce8b14bb4497740$exports.range)(rows)){\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = {\n [op]: {\n [key]: value\n }\n };\n }\n }\n return (0, $lNLp4$immutabilityhelper)(updatedData, spec);\n}\n\n\n//# sourceMappingURL=provider.f11d5828.js.map\n","import { createContext, useContext, useEffect, useRef, useState } from \"react\";\nimport h from \"@macrostrat/hyper\";\nimport { createStore, StoreApi, useStore } from \"zustand\";\nimport type {\n FocusedCellCoordinates,\n Region,\n Table2,\n} from \"@blueprintjs/table\";\nimport { generateColumnSpec } from \"./utils\";\nimport update, { Spec } from \"immutability-helper\";\nimport { range } from \"./utils\";\nimport React from \"react\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n required?: boolean;\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n}\n\nexport interface ColumnSpecOptions {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: any[]; // 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 interface DataSheetCoreProps<T> {\n data: T[];\n columnSpec?: ColumnSpec[];\n editable?: boolean;\n enableColumnReordering: boolean;\n}\n\nexport interface DataSheetState<T> {\n selection: Region[];\n columnSpec: ColumnSpec[];\n fillValueBaseCell: FocusedCellCoordinates | null;\n focusedCell: FocusedCellCoordinates | null;\n topLeftCell: FocusedCellCoordinates | null;\n updatedData: T[];\n initialized: boolean;\n}\n\ntype DataSheetVals<T> = DataSheetState<T> & DataSheetCoreProps<T>;\n\nexport interface DataSheetStore<T> extends DataSheetVals<T> {\n setSelection(selection: Region[]): void;\n onDragValue(cell: FocusedCellCoordinates | null): void;\n setUpdatedData(data: T[]): void;\n onCellEdited(rowIndex: number, columnName: string, value: any): void;\n clearSelection(): void;\n initialize(props: DataSheetCoreProps<T>): void;\n onSelection(selection: Region[]): void;\n // Internal method used for infinite scrolling\n setVisibleCells(visibleCells: VisibleCells): void;\n scrollToRow(rowIndex: number): void;\n tableRef: React.MutableRefObject<Table2>;\n}\n\nexport type DataSheetProviderProps<T> = DataSheetCoreProps<T> & {\n children: React.ReactNode;\n columnSpecOptions?: ColumnSpecOptions;\n};\n\nconst DataSheetContext = createContext<StoreApi<DataSheetStore<any>>>(null);\n\nexport interface VisibleCells {\n rowIndexStart: number;\n rowIndexEnd: number;\n}\n\nexport function DataSheetProvider<T>({\n children,\n data,\n columnSpec,\n columnSpecOptions,\n editable,\n enableColumnReordering,\n}: DataSheetProviderProps<T>) {\n const visibleCellsRef = useRef<VisibleCells>({\n rowIndexStart: 0,\n rowIndexEnd: 0,\n });\n\n const tableRef = useRef<Table2>(null);\n\n const [store] = useState(() => {\n return createStore<DataSheetStore<T>>((set) => {\n return {\n data,\n columnSpec: columnSpec ?? generateColumnSpec(data, columnSpecOptions),\n editable,\n selection: [],\n fillValueBaseCell: null,\n updatedData: [],\n focusedCell: null,\n topLeftCell: null,\n initialized: false,\n tableRef,\n setSelection(selection: Region[]) {\n set(updateSelection(selection));\n },\n setUpdatedData(data: T[]) {\n set({ updatedData: data });\n },\n setVisibleCells(visibleCells: VisibleCells) {\n // Visible cells are used for infinite scrolling\n // Right now we don't store this in the state\n visibleCellsRef.current = visibleCells;\n },\n onDragValue(cell: FocusedCellCoordinates | null) {\n set({ fillValueBaseCell: cell });\n },\n onCellEdited(rowIndex: number, columnName: string, value: any) {\n set((state) => {\n const { editable, updatedData, data } = state;\n if (!editable) return {};\n let rowSpec: any;\n // Check to see if the new value is the same as the old one\n if (value !== data[rowIndex]?.[columnName]) {\n const rowOp = updatedData[rowIndex] != null ? \"$merge\" : \"$set\";\n rowSpec = { [rowOp]: { [columnName]: value } };\n } else {\n rowSpec = { $unset: [columnName] };\n }\n const spec: Spec<T[]> = { [rowIndex]: rowSpec };\n return { updatedData: update(updatedData, spec) };\n });\n },\n initialize(props: DataSheetCoreProps<T>) {\n set({ ...props, initialized: true });\n },\n clearSelection() {\n set((state) => {\n // Delete all selected cells\n const { selection, updatedData, columnSpec } = state;\n let spec = {};\n for (const region of selection) {\n const { cols, rows } = region;\n for (const row of range(rows)) {\n let vals = {};\n for (const col of range(cols)) {\n const key = columnSpec[col].key;\n vals[key] = \"\";\n }\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: vals };\n }\n }\n return {\n updatedData: update(updatedData, spec),\n };\n });\n },\n onSelection(selection: Region[]) {\n set((state) => {\n let spec = updateSelection(selection);\n if (state.fillValueBaseCell != null) {\n spec.updatedData = fillValues(state, selection);\n }\n return spec;\n });\n },\n onColumnsReordered(oldIndex: number, newIndex: number, length: number) {\n set((state) => {\n if (!state.enableColumnReordering) return {};\n const { columnSpec } = state;\n const newSpec = [...columnSpec];\n const removed = newSpec.splice(oldIndex, length);\n newSpec.splice(newIndex, 0, ...removed);\n return { columnSpec: newSpec };\n });\n },\n scrollToRow(rowIndex: number, columnIndex: number) {\n if (tableRef.current == null) return;\n tableRef.current.scrollToRegion({\n rows: [rowIndex, rowIndex],\n });\n },\n };\n });\n });\n\n // Not sure how required this initialization is\n useEffect(() => {\n const { initialize } = store.getState();\n initialize({\n data,\n columnSpec: columnSpec ?? generateColumnSpec(data, columnSpecOptions),\n editable,\n enableColumnReordering,\n });\n }, [data, editable, columnSpec, columnSpecOptions, enableColumnReordering]);\n\n return h(DataSheetContext.Provider, { value: store }, children);\n}\n\nexport function useStoreAPI<T>(): StoreApi<DataSheetStore<T>> {\n const store = useContext(DataSheetContext);\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>) => A\n): A {\n const store = useStoreAPI<T>();\n return useStore(store, selector);\n}\n\nfunction updateSelection(selection: Region[]) {\n const focusedCell = singleFocusedCell(selection);\n let spec: Partial<DataSheetState<T>> = {\n selection,\n focusedCell,\n topLeftCell: topLeftCell(selection),\n };\n if (focusedCell != null) {\n spec.fillValueBaseCell = null;\n }\n return spec;\n}\n\nexport function topLeftCell(\n regions: Region[],\n requireSolitaryCell: boolean = false\n): FocusedCellCoordinates | null {\n /** Top left cell of a ranged selection */\n if (regions == null) return null;\n const [region] = regions;\n if (region == null) return null;\n const { cols, rows } = region;\n if (cols == null || rows == null) return null;\n if (requireSolitaryCell && (cols[0] !== cols[1] || rows[0] !== rows[1]))\n return null;\n return { col: cols[0], row: rows[0], focusSelectionIndex: 0 };\n}\n\nfunction singleFocusedCell(sel: Region[]): FocusedCellCoordinates | null {\n /** Derive a single focused cell from a selected region, if possible */\n if (sel?.length !== 1) return null;\n return topLeftCell(sel, true);\n}\n\nfunction fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {\n const { updatedData, columnSpec, editable, fillValueBaseCell, data } = state;\n\n // Prepare regions by unnesting columns\n let regions = selection.map((region) => {\n const { cols, rows } = region;\n // Get the first column (maybe should be the last)\n const [col] = cols;\n return { cols: [col, col], rows };\n });\n\n // Fill values downwards\n if (!editable || fillValueBaseCell == null) return updatedData;\n const { col, row } = fillValueBaseCell;\n const key = columnSpec[col].key;\n const value = updatedData[row]?.[key] ?? data[row][key];\n const spec = {};\n for (const region of regions) {\n const { cols, rows } = region;\n for (const row of range(rows)) {\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: { [key]: value } };\n }\n }\n return update(updatedData, spec);\n}\n","module.exports = require('./helpers/bundle-url').getBundleURL('lNLp4') + \"utils.897d92e2.js\";"],"names":["createContext","$lNLp4$createContext","$parcel$global","globalThis","$parcel$modules","$parcel$inits","parcelRequire","id","exports","init","module","call","err","Error","code","register","getBundleURL"],"version":3,"file":"provider.f11d5828.js.map","sourceRoot":"../../../../"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
import r from"@macrostrat/hyper";import"@blueprintjs/core";import"react";var e=globalThis,t={},o={},i=e.parcelRequire94c2;null==i&&((i=function(r){if(r in t)return t[r].exports;if(r in o){var e=o[r];delete o[r];var i={id:r,exports:{}};return t[r]=i,e.call(i.exports,i,i.exports),i.exports}var a=Error("Cannot find module '"+r+"'");throw a.code="MODULE_NOT_FOUND",a}).register=function(r,e){o[r]=e},e.parcelRequire94c2=i),i.register;var a=i("9wR9f");r.styled(a&&a.__esModule?a.default:a);
|
|
2
|
+
//# sourceMappingURL=text-areas.64832f7d.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"A,O,M,mB,A,O,mB,A,O,O,C,I,E,W,E,C,E,E,C,E,E,E,iB,A,O,I,A,C,E,S,C,E,G,K,E,O,C,C,E,C,O,C,G,K,E,C,I,E,C,C,E,A,Q,C,C,E,C,I,E,C,G,E,Q,C,C,E,O,C,C,E,C,E,E,I,C,E,O,C,E,E,O,E,E,O,A,C,I,E,A,M,uB,E,I,O,E,I,C,mB,C,C,E,Q,C,S,C,C,C,E,C,C,E,C,C,E,E,iB,C,G,E,Q,C,I,E,E,SCKU,AAAA,EAAM,MAAM,C,AAAC,G,AAAA,E,U,C,AAAA,E,O,CAAA","sources":["<anon>","packages/data-sheet/src/components/text-areas.ts"],"sourcesContent":["import $1YOkn$macrostrathyper from \"@macrostrat/hyper\";\nimport {Button as $1YOkn$Button} from \"@blueprintjs/core\";\nimport {useRef as $1YOkn$useRef, useEffect as $1YOkn$useEffect} from \"react\";\n\n\nfunction $parcel$interopDefault(a) {\n return a && a.__esModule ? a.default : a;\n}\n\n var $parcel$global = globalThis;\n \nvar $parcel$modules = {};\nvar $parcel$inits = {};\n\nvar parcelRequire = $parcel$global[\"parcelRequire94c2\"];\n\nif (parcelRequire == null) {\n parcelRequire = function(id) {\n if (id in $parcel$modules) {\n return $parcel$modules[id].exports;\n }\n if (id in $parcel$inits) {\n var init = $parcel$inits[id];\n delete $parcel$inits[id];\n var module = {id: id, exports: {}};\n $parcel$modules[id] = module;\n init.call(module.exports, module, module.exports);\n return module.exports;\n }\n var err = new Error(\"Cannot find module '\" + id + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n };\n\n parcelRequire.register = function register(id, init) {\n $parcel$inits[id] = init;\n };\n\n $parcel$global[\"parcelRequire94c2\"] = parcelRequire;\n}\n\nvar parcelRegister = parcelRequire.register;\n\n\nvar $9wR9f = parcelRequire(\"9wR9f\");\n\n\nconst $1b3be825da79eb57$var$h = (0, $1YOkn$macrostrathyper).styled((0, (/*@__PURE__*/$parcel$interopDefault($9wR9f))));\nfunction $1b3be825da79eb57$export$b8e68c321a6269f1({ value: value, onChange: onChange }) {\n const ref = (0, $1YOkn$useRef)(null);\n (0, $1YOkn$useEffect)(()=>{\n if (ref.current == null) return;\n ref.current.focus();\n // Get the current value\n const val = ref.current.value;\n // Move the cursor to the end of the text\n ref.current.setSelectionRange(val.length, val.length);\n }, []);\n return $1b3be825da79eb57$var$h(\"div.editable-text-area\", [\n $1b3be825da79eb57$var$h(\"textarea.bp5-input\", {\n ref: ref,\n value: value ?? \"\",\n onChange: (evt)=>onChange(evt.target.value),\n onKeyDown: (evt)=>{\n if (evt.key === \"Enter\") {\n evt.preventDefault();\n return;\n }\n if (evt.key === \"Escape\") {\n evt.preventDefault();\n return;\n }\n const shouldPropagate = $1b3be825da79eb57$export$52c8c5a1aad17e2a(evt, evt.target);\n if (!shouldPropagate) evt.stopPropagation();\n }\n }),\n $1b3be825da79eb57$var$h(\"div.tools\", [\n $1b3be825da79eb57$var$h((0, $1YOkn$Button), {\n icon: \"key-enter\",\n minimal: true,\n small: true,\n onClick () {\n // Get cursor position\n let _value = value ?? \"\";\n const cursorPos = ref.current.selectionStart ?? _value.length;\n // Insert a newline at the cursor position\n onChange(_value.slice(0, cursorPos) + \"\\n\" + _value.slice(cursorPos));\n // Re-focus the textarea\n ref.current.focus();\n // Move the cursor to the end of the line\n ref.current.setSelectionRange(cursorPos + 1, cursorPos + 1);\n }\n })\n ])\n ]);\n}\nfunction $1b3be825da79eb57$export$52c8c5a1aad17e2a(evt, target) {\n if ((evt.key === \"ArrowLeft\" || evt.key === \"ArrowUp\" || evt.key === \"ArrowDown\") && target.selectionStart === 0) {\n target.blur();\n return true;\n }\n if ((evt.key === \"ArrowRight\" || evt.key === \"ArrowUp\" || evt.key === \"Tab\" || evt.key === \"Enter\" || evt.key === \"ArrowDown\") && target.selectionStart === evt.target.value.length) {\n target.blur();\n return true;\n }\n return false;\n}\n\n\n//# sourceMappingURL=text-areas.64832f7d.js.map\n","import hyper from \"@macrostrat/hyper\";\nimport styles from \"./main.module.sass\";\nimport { Button } from \"@blueprintjs/core\";\nimport { useEffect, useRef } from \"react\";\n\nconst h = hyper.styled(styles);\n\nexport function EditableTextArea({ value, onChange }) {\n const ref = useRef(null);\n\n useEffect(() => {\n if (ref.current == null) return;\n ref.current.focus();\n // Get the current value\n const val = ref.current.value;\n // Move the cursor to the end of the text\n ref.current.setSelectionRange(val.length, val.length);\n }, []);\n\n return h(\"div.editable-text-area\", [\n h(\"textarea.bp5-input\", {\n ref,\n value: value ?? \"\",\n onChange: (evt) => onChange(evt.target.value),\n onKeyDown: (evt) => {\n if (evt.key === \"Enter\") {\n evt.preventDefault();\n return;\n }\n\n if (evt.key === \"Escape\") {\n evt.preventDefault();\n return;\n }\n\n const shouldPropagate = handleSpecialKeys(evt, evt.target);\n if (!shouldPropagate) {\n evt.stopPropagation();\n }\n },\n }),\n h(\"div.tools\", [\n h(Button, {\n icon: \"key-enter\",\n minimal: true,\n small: true,\n onClick() {\n // Get cursor position\n let _value = value ?? \"\";\n\n const cursorPos = ref.current.selectionStart ?? _value.length;\n // Insert a newline at the cursor position\n onChange(_value.slice(0, cursorPos) + \"\\n\" + _value.slice(cursorPos));\n // Re-focus the textarea\n ref.current.focus();\n // Move the cursor to the end of the line\n ref.current.setSelectionRange(cursorPos + 1, cursorPos + 1);\n },\n }),\n ]),\n ]);\n}\n\nexport function handleSpecialKeys(evt, target): boolean {\n if (\n (evt.key === \"ArrowLeft\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === 0\n ) {\n target.blur();\n return true;\n }\n\n if (\n (evt.key === \"ArrowRight\" ||\n evt.key === \"ArrowUp\" ||\n evt.key === \"Tab\" ||\n evt.key === \"Enter\" ||\n evt.key === \"ArrowDown\") &&\n target.selectionStart === evt.target.value.length\n ) {\n target.blur();\n return true;\n }\n\n return false;\n}\n"],"names":["$1YOkn$macrostrathyper","$parcel$global","globalThis","$parcel$modules","$parcel$inits","parcelRequire","id","exports","init","module","call","err","Error","code","register","$9wR9f","styled","a","__esModule","default"],"version":3,"file":"text-areas.64832f7d.js.map","sourceRoot":"../../../../"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
var r=globalThis,e={},t={},i=r.parcelRequire94c2;null==i&&((i=function(r){if(r in e)return e[r].exports;if(r in t){var i=t[r];delete t[r];var n={id:r,exports:{}};return e[r]=n,i.call(n.exports,n,n.exports),n.exports}var o=Error("Cannot find module '"+r+"'");throw o.code="MODULE_NOT_FOUND",o}).register=function(r,e){t[r]=e},r.parcelRequire94c2=i),i.register,i("daZiC").getBundleURL("96xEg");
|
|
2
|
+
//# sourceMappingURL=utils.897d92e2.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"mappings":"A,I,E,W,E,C,E,E,C,E,E,E,iB,A,O,I,A,C,E,S,C,E,G,K,E,O,C,C,E,C,O,C,G,K,E,C,I,E,C,C,E,A,Q,C,C,E,C,I,E,C,G,E,Q,C,C,E,O,C,C,E,C,E,E,I,C,E,O,C,E,E,O,E,E,O,A,C,I,E,A,M,uB,E,I,O,E,I,C,mB,C,C,E,Q,C,S,C,C,C,E,C,C,E,C,C,E,E,iB,C,G,E,Q,CEAiB,AAAA,EAAA,SAAA,YAAA,CAA6C","sources":["<anon>","packages/data-sheet/src/utils/index.ts","../../../../.yarn/berry/cache/@parcel-runtime-js-npm-2.13.3-f44fec8492-10c0.zip/node_modules/@parcel/runtime-js/lib/runtime-27c99bdebbced7f2.js"],"sourcesContent":["\n var $parcel$global = globalThis;\n \nvar $parcel$modules = {};\nvar $parcel$inits = {};\n\nvar parcelRequire = $parcel$global[\"parcelRequire94c2\"];\n\nif (parcelRequire == null) {\n parcelRequire = function(id) {\n if (id in $parcel$modules) {\n return $parcel$modules[id].exports;\n }\n if (id in $parcel$inits) {\n var init = $parcel$inits[id];\n delete $parcel$inits[id];\n var module = {id: id, exports: {}};\n $parcel$modules[id] = module;\n init.call(module.exports, module, module.exports);\n return module.exports;\n }\n var err = new Error(\"Cannot find module '\" + id + \"'\");\n err.code = 'MODULE_NOT_FOUND';\n throw err;\n };\n\n parcelRequire.register = function register(id, init) {\n $parcel$inits[id] = init;\n };\n\n $parcel$global[\"parcelRequire94c2\"] = parcelRequire;\n}\n\nvar parcelRegister = parcelRequire.register;\nvar $880dee5e99d6c152$exports = {};\n\n$880dee5e99d6c152$exports = (parcelRequire(\"daZiC\")).getBundleURL('96xEg') + \"column-spec.da7354f5.js\";\n\n\nfunction $1d0878cf0fb6bcd8$export$d02631cccf789723(arr) {\n if (arr.length != 2) throw new Error(\"Range must have two elements\");\n const [start, end] = arr;\n return Array.from({\n length: end - start + 1\n }, (_, i)=>i + start);\n}\n\n\n//# sourceMappingURL=utils.897d92e2.js.map\n","export { generateColumnSpec } from \"./column-spec\";\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","module.exports = require('./helpers/bundle-url').getBundleURL('96xEg') + \"column-spec.da7354f5.js\";"],"names":["$parcel$global","globalThis","$parcel$modules","$parcel$inits","parcelRequire","id","exports","init","module","call","err","Error","code","register","getBundleURL"],"version":3,"file":"utils.897d92e2.js.map","sourceRoot":"../../../../"}
|
package/package.json
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@macrostrat/data-sheet",
|
|
3
|
-
"version": "2.0.
|
|
4
|
-
"description": "",
|
|
5
|
-
"source": "src/index.ts",
|
|
6
|
-
"main": "dist/index.js",
|
|
3
|
+
"version": "2.0.1",
|
|
4
|
+
"description": "Scalable data sheet with optional editing capabilities",
|
|
7
5
|
"type": "module",
|
|
8
|
-
"
|
|
6
|
+
"source": "src/index.ts",
|
|
7
|
+
"main": "dist/esm/index.js",
|
|
8
|
+
"types": "dist/esm/index.d.ts",
|
|
9
|
+
"node": "dist/node/index.js",
|
|
10
|
+
"exports": {
|
|
11
|
+
".": {
|
|
12
|
+
"source": "./src/index.ts",
|
|
13
|
+
"import": "./dist/esm/index.js",
|
|
14
|
+
"types": "./dist/esm/index.d.ts",
|
|
15
|
+
"node": "./dist/node/index.js"
|
|
16
|
+
}
|
|
17
|
+
},
|
|
18
|
+
"targets": {
|
|
19
|
+
"node": {
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=14"
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
},
|
|
9
25
|
"scripts": {
|
|
10
26
|
"build": "rm -rf dist && parcel build"
|
|
11
27
|
},
|
|
@@ -16,7 +32,7 @@
|
|
|
16
32
|
"@blueprintjs/table": "^5.1.4",
|
|
17
33
|
"@macrostrat/color-utils": "^1.0.1",
|
|
18
34
|
"@macrostrat/hyper": "^3.0.6",
|
|
19
|
-
"@macrostrat/ui-components": "^4.1.
|
|
35
|
+
"@macrostrat/ui-components": "^4.1.1",
|
|
20
36
|
"@supabase/postgrest-js": "^1.17.7",
|
|
21
37
|
"chroma-js": "^2.4.2",
|
|
22
38
|
"classnames": "^2.3.1",
|
|
@@ -27,13 +43,6 @@
|
|
|
27
43
|
"underscore": "^1.13.7",
|
|
28
44
|
"zustand": "^5.0.2"
|
|
29
45
|
},
|
|
30
|
-
"exports": {
|
|
31
|
-
".": {
|
|
32
|
-
"source": "./src/index.ts",
|
|
33
|
-
"import": "./dist/index.js",
|
|
34
|
-
"types": "./dist/index.d.ts"
|
|
35
|
-
}
|
|
36
|
-
},
|
|
37
46
|
"files": [
|
|
38
47
|
"src",
|
|
39
48
|
"dist"
|
|
@@ -1,31 +0,0 @@
|
|
|
1
|
-
import {useInDarkMode as $lIlPt$useInDarkMode} from "@macrostrat/ui-components";
|
|
2
|
-
import $lIlPt$macrostrathyper from "@macrostrat/hyper";
|
|
3
|
-
import {Tag as $lIlPt$Tag} from "@blueprintjs/core";
|
|
4
|
-
import {asChromaColor as $lIlPt$asChromaColor} from "@macrostrat/color-utils";
|
|
5
|
-
import $lIlPt$classnames from "classnames";
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
function $753d4a0c461d4588$export$17064b7382e320b2({ data: data, className: className = null }) {
|
|
13
|
-
const darkMode = (0, $lIlPt$useInDarkMode)();
|
|
14
|
-
const luminance = darkMode ? 0.9 : 0.4;
|
|
15
|
-
const color = (0, $lIlPt$asChromaColor)(data.color);
|
|
16
|
-
return (0, $lIlPt$macrostrathyper)((0, $lIlPt$Tag), {
|
|
17
|
-
key: data.id,
|
|
18
|
-
className: (0, $lIlPt$classnames)("lithology-tag", className),
|
|
19
|
-
minimal: true,
|
|
20
|
-
style: {
|
|
21
|
-
color: color?.luminance(luminance).hex(),
|
|
22
|
-
backgroundColor: color?.luminance(1 - luminance).hex()
|
|
23
|
-
}
|
|
24
|
-
}, (0, $lIlPt$macrostrathyper)("span.contents", [
|
|
25
|
-
(0, $lIlPt$macrostrathyper)("span.name", data.name)
|
|
26
|
-
]));
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
export {$753d4a0c461d4588$export$17064b7382e320b2 as LithologyTag};
|
|
31
|
-
//# sourceMappingURL=cell-renderers.de70f471.js.map
|
|
File without changes
|
|
File without changes
|
|
File without changes
|