@macrostrat/data-sheet 4.0.1 → 4.1.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.
Files changed (83) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +11 -1
  3. package/dist/actions/column-controls.cjs +102 -1
  4. package/dist/actions/column-controls.cjs.map +1 -1
  5. package/dist/actions/column-controls.js +104 -3
  6. package/dist/actions/column-controls.js.map +1 -1
  7. package/dist/actions/column-filter.cjs +48 -25
  8. package/dist/actions/column-filter.cjs.map +1 -1
  9. package/dist/actions/column-filter.js +50 -27
  10. package/dist/actions/column-filter.js.map +1 -1
  11. package/dist/actions/selection.cjs +2 -1
  12. package/dist/actions/selection.cjs.map +1 -1
  13. package/dist/actions/selection.js +2 -1
  14. package/dist/actions/selection.js.map +1 -1
  15. package/dist/actions/table-controls.cjs +21 -0
  16. package/dist/actions/table-controls.cjs.map +1 -1
  17. package/dist/actions/table-controls.d.ts +4 -0
  18. package/dist/actions/table-controls.js +21 -0
  19. package/dist/actions/table-controls.js.map +1 -1
  20. package/dist/actions/toolbar.cjs +34 -4
  21. package/dist/actions/toolbar.cjs.map +1 -1
  22. package/dist/actions/toolbar.js +35 -5
  23. package/dist/actions/toolbar.js.map +1 -1
  24. package/dist/actions/types.d.ts +9 -0
  25. package/dist/cell-renderer.cjs +9 -7
  26. package/dist/cell-renderer.cjs.map +1 -1
  27. package/dist/cell-renderer.js +9 -7
  28. package/dist/cell-renderer.js.map +1 -1
  29. package/dist/core.cjs +68 -9
  30. package/dist/core.cjs.map +1 -1
  31. package/dist/core.d.ts +32 -1
  32. package/dist/core.js +69 -10
  33. package/dist/core.js.map +1 -1
  34. package/dist/filters/operators.cjs +2 -2
  35. package/dist/filters/operators.cjs.map +1 -1
  36. package/dist/filters/operators.d.ts +1 -1
  37. package/dist/filters/operators.js +2 -2
  38. package/dist/filters/operators.js.map +1 -1
  39. package/dist/index.cjs +4 -2
  40. package/dist/index.cjs.map +1 -1
  41. package/dist/index.js +4 -2
  42. package/dist/postgrest-table/data-loaders.cjs +1 -8
  43. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  44. package/dist/postgrest-table/data-loaders.js +1 -8
  45. package/dist/postgrest-table/data-loaders.js.map +1 -1
  46. package/dist/provider.cjs +9 -3
  47. package/dist/provider.cjs.map +1 -1
  48. package/dist/provider.d.ts +2 -1
  49. package/dist/provider.js +9 -3
  50. package/dist/provider.js.map +1 -1
  51. package/dist/renderers/column-header-cell.cjs +33 -32
  52. package/dist/renderers/column-header-cell.cjs.map +1 -1
  53. package/dist/renderers/column-header-cell.d.ts +1 -2
  54. package/dist/renderers/column-header-cell.js +34 -33
  55. package/dist/renderers/column-header-cell.js.map +1 -1
  56. package/dist/types.cjs +11 -0
  57. package/dist/types.cjs.map +1 -1
  58. package/dist/types.d.ts +55 -2
  59. package/dist/types.js +11 -0
  60. package/dist/types.js.map +1 -1
  61. package/dist/utils/column-spec.cjs.map +1 -1
  62. package/dist/utils/column-spec.d.ts +8 -0
  63. package/dist/utils/column-spec.js.map +1 -1
  64. package/dist/zustand-store.cjs +7 -3
  65. package/dist/zustand-store.cjs.map +1 -1
  66. package/dist/zustand-store.js +8 -4
  67. package/dist/zustand-store.js.map +1 -1
  68. package/package.json +1 -1
  69. package/src/actions/column-controls.ts +133 -2
  70. package/src/actions/column-filter.ts +59 -30
  71. package/src/actions/selection.ts +1 -0
  72. package/src/actions/table-controls.ts +24 -0
  73. package/src/actions/toolbar.ts +61 -5
  74. package/src/actions/types.ts +10 -0
  75. package/src/cell-renderer.ts +23 -10
  76. package/src/core.ts +131 -13
  77. package/src/filters/operators.ts +5 -3
  78. package/src/postgrest-table/data-loaders.ts +6 -10
  79. package/src/provider.ts +22 -5
  80. package/src/renderers/column-header-cell.ts +51 -36
  81. package/src/types.ts +66 -2
  82. package/src/utils/column-spec.ts +8 -0
  83. package/src/zustand-store.ts +12 -5
package/dist/core.cjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.cjs","sources":["../src/core.ts"],"sourcesContent":["import { useHotkeys } from \"@blueprintjs/core\";\nimport {\n Column,\n Region,\n RegionCardinality,\n RowHeaderCell,\n Table,\n TableProps,\n} from \"@blueprintjs/table\";\nimport \"@blueprintjs/table/lib/css/table.css\";\nimport { ReactNode, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { LoadProgressIndicator } from \"./components\";\nimport { renderColumnHeaderCell } from \"./renderers\";\nimport h from \"./main.module.sass\";\nimport {\n columnSpecAtom,\n ctx,\n DataSheetProvider,\n storeAtom,\n tableActionsAtom,\n useSelector,\n useStoreAPI,\n} from \"./provider\";\nimport { atom } from \"jotai\";\nimport {\n DataSheetProviderProps,\n EditEvent,\n TableElementStatus,\n VisibleCells,\n} from \"./types.ts\";\nimport { basicCellRenderer } from \"./cell-renderer.ts\";\nimport { CellRendererDebugOverlay, tableHotkeysAtom } from \"./utils\";\nimport {\n ActionsToolbar,\n clipboardActions,\n columnControlActions,\n createSaveAction,\n FilterBar,\n resetChangesAction,\n TableAction,\n TableActionContext,\n TableFilter,\n} from \"./actions\";\nimport {\n createLocalProvider,\n dataRefreshTokenAtom,\n FetchData,\n FetchDataOptions,\n tableFooterAtom,\n TableDataProvider,\n useScrollHandler,\n useDataLoader,\n} from \"./postgrest-table\";\n\n// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args\n\n// TODO: add a \"copy to selection\" tool (the little square in the bottom right corner of a cell)\n// This should copy the value of a cell (or a set of cells in the same row) downwards.\n\nexport enum DataSheetDensity {\n HIGH = \"high\",\n MEDIUM = \"medium\",\n LOW = \"low\",\n}\n\n/** Approximate column-header + scrollbar allowance, used to size the table to\n * its content in paged mode. */\nconst COLUMN_HEADER_HEIGHT = 34;\n\n/**\n * How selecting a cell activates its surface (an editor, or a read-only detail\n * panel):\n * - `\"auto\"` (default when `autoFocusEditor` is `true`): open the surface on\n * selection and, for editors, focus it. Editors relinquish focus at their\n * edges — arrow past the start/end of a text cell, or press Escape, and focus\n * returns to the table — so the keyboard stays operable without the mouse.\n * Pressing Escape drops into navigation mode (surfaces stop auto-opening)\n * until the next click.\n * - `\"manual\"` (default when `autoFocusEditor` is `false`): the surface stays\n * closed until the cell is clicked; arrow keys always navigate the table.\n */\nexport type CellInteraction = \"auto\" | \"manual\";\n\ninterface DataSheetInternalProps<T> extends TableProps, FetchDataOptions {\n /** In-memory rows. Internally wrapped in a local `TableDataProvider` and\n * driven through the same loader as any other source. */\n data?: T[];\n // function to fetch a chunk of data (the read side of a data provider)\n fetchData?: FetchData<T>;\n /** A data provider instantiated separately and passed in — bundles the read\n * side (`fetchData` + `identity`) and, optionally, the persistence side\n * (`saveRows` / `deleteRows` / `insertRow`) that drives the Save action. An\n * explicit alternative to the loose `data` / `fetchData` / `identity` props;\n * takes precedence when given. */\n provider?: TableDataProvider<T>;\n // An optional table name that will be used in toolbars if given\n name?: string;\n onVisibleCellsChange?: (visibleCells: VisibleCells) => void;\n onUpdateData?: (updatedData: any[], data: T[]) => void;\n /** Observer called for every user edit as a structured `EditEvent`\n * (Workstream A). Additive: the built-in `updatedData` overlay still\n * applies. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Controlled edited-cell overlay (Workstream A). When provided, it is\n * synced into the store as the source of truth for edited values — pair with\n * `onEdit` to own edit state externally (e.g. an ops model). Optimistic\n * in-table edits are superseded by the next value you pass back. */\n updatedData?: T[];\n /** Controlled row-status overlay (edited / added / deleted), the companion\n * to `updatedData`. */\n rowStatus?: TableElementStatus[];\n /** Row identity for the edit overlay — stable across a provider re-sort (a\n * data provider supplies its own; defaults to `(row) => row?.id`). Lets edits\n * survive a re-ordered re-fetch. */\n identity?: (row: T) => string | number | null | undefined;\n /** Persistence handler for the built-in Save action. When provided, a Save\n * control is added to the toolbar (always visible, disabled when there are\n * no pending changes). */\n onSave?: (ctx: TableActionContext<T>) => void | Promise<void>;\n onDeleteRows?: (selection: Region[]) => void;\n verbose?: boolean;\n enableColumnReordering?: boolean;\n enableClipboard?: boolean;\n enableFocusedCell?: boolean;\n editable?: boolean;\n /** @deprecated Prefer `cellInteraction`. `true` maps to `\"auto\"`,\n * `false` to `\"manual\"`. */\n autoFocusEditor?: boolean;\n /** How selecting a cell activates its surface (editor or detail panel).\n * Defaults from `autoFocusEditor` for backward compatibility. */\n cellInteraction?: CellInteraction;\n density?: DataSheetDensity;\n /** Configurable table actions shown in a selection-aware toolbar.\n * When provided, the actions toolbar renders alongside the existing\n * edit toolbar. Actions are filtered by the current selection cardinality. */\n actions?: TableAction<T>[];\n /** Available column/table filters shown in a filter bar.\n * Filters can also be defined per-column via `ColumnSpec.filters`. */\n filters?: TableFilter<T>[];\n /** Optional custom column header cell renderer, called for each column.\n * Receives the ColumnSpec and column index; should return a React element\n * (typically a Blueprint ColumnHeaderCell). */\n columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;\n}\n\ntype DataSheetProps<T> = DataSheetProviderProps<T> & DataSheetInternalProps<T>;\n\nconst emptyData: any[] = [];\n\nexport function DataSheet<T>(props: DataSheetProps<T>) {\n const {\n data,\n columnSpec,\n columnSpecOptions,\n editable = true,\n enableColumnReordering = false,\n enableFocusedCell = false,\n defaultColumnWidth = 150,\n children,\n ...rest\n } = props;\n\n return h(\n DataSheetProvider<T>,\n {\n data: data ?? emptyData,\n columnSpec,\n columnSpecOptions,\n enableColumnReordering,\n defaultColumnWidth,\n editable,\n ...rest,\n },\n h(_DataSheet<any>, {\n ...rest,\n data: data ?? emptyData,\n children,\n editable,\n enableColumnReordering,\n enableFocusedCell,\n }),\n );\n}\n\nconst deletedRowHeaderStyle = {\n opacity: 0.5,\n textDecoration: \"line-through\",\n};\n\n/** Persist all pending changes through a data provider: added rows via\n * `insertRow`, edited rows via `saveRows`, deleted rows via `deleteRows`\n * (addressed by `provider.identity`). Used by the built-in Save action when an\n * explicit provider owns persistence. */\nasync function persistViaProvider<T>(\n provider: TableDataProvider<T>,\n ctx: TableActionContext<T>,\n): Promise<void> {\n const base = (ctx.data ?? []) as any[];\n const updates = (ctx.updatedData ?? []) as any[];\n const status = (ctx.rowStatus ?? []) as any[];\n const n = Math.max(base.length, updates.length, status.length);\n const toSave: T[] = [];\n const toInsert: T[] = [];\n const toDelete: Array<string | number> = [];\n for (let i = 0; i < n; i++) {\n if (status[i] === TableElementStatus.DELETED) {\n const id = provider.identity(base[i]);\n if (id != null) toDelete.push(id);\n continue;\n }\n const upd = updates[i];\n const hasEdit =\n upd != null && typeof upd === \"object\" && Object.keys(upd).length > 0;\n if (status[i] === TableElementStatus.ADDED) {\n toInsert.push({ ...base[i], ...upd } as T);\n } else if (hasEdit) {\n toSave.push({ ...base[i], ...upd } as T);\n }\n }\n if (toDelete.length > 0 && provider.deleteRows != null) {\n await provider.deleteRows(toDelete);\n }\n for (const row of toInsert) {\n if (provider.insertRow != null) await provider.insertRow(row);\n }\n if (toSave.length > 0 && provider.saveRows != null) {\n await provider.saveRows(toSave);\n }\n}\n\nfunction _DataSheet<T>({\n data: sourceData,\n fetchData,\n provider,\n pageSize,\n fetchMode,\n onVisibleCellsChange,\n onUpdateData,\n onEdit,\n onSave,\n updatedData: updatedDataProp,\n rowStatus: rowStatusProp,\n identity,\n onDeleteRows,\n name,\n verbose = false,\n enableFocusedCell,\n autoFocusEditor = true,\n cellInteraction,\n enableClipboard = true,\n density = DataSheetDensity.HIGH,\n selectionModes,\n actions,\n filters,\n columnHeaderCellRenderer,\n children,\n ...rest\n}: DataSheetInternalProps<T>) {\n /**\n * @param data: The data to be displayed in the table\n * @param columnSpec: The specification for all columns in the table. If not provided, the column spec will be generated from the data.\n * @param columnSpecOptions: Options for generating a column spec from data\n */\n\n // Turn on debug features\n const debugMode = false;\n\n const editable = useSelector((state) => state.editable);\n\n // Resolve the active data provider: an explicit `provider` prop wins; else a\n // loose `fetchData` (+ identity) is wrapped as one; else in-memory `data`\n // becomes a local provider. Local and remote thus share one path, and the\n // provider is an explicit contract rather than a set of scattered props.\n const isLocalProvider = provider == null && fetchData == null;\n const activeProvider = useMemo<TableDataProvider<any> | null>(() => {\n if (provider != null) return provider;\n if (fetchData != null) {\n return { fetchData, identity: identity ?? ((r: any) => r?.id) };\n }\n if (sourceData != null && sourceData.length > 0) {\n return createLocalProvider(\n sourceData,\n identity != null ? { identity } : undefined,\n );\n }\n return null;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [provider, fetchData, sourceData, identity]);\n\n // When an explicit provider owns persistence, its methods drive the built-in\n // Save (batch: edits→saveRows, added→insertRow, deleted→deleteRows), then a\n // refresh. Otherwise the loose `onSave` handler is used.\n const bumpRefresh = ctx.useSet(dataRefreshTokenAtom);\n const providerSave = useMemo(() => {\n const p = provider;\n if (\n p == null ||\n (p.saveRows == null && p.deleteRows == null && p.insertRow == null)\n ) {\n return null;\n }\n return async (actionCtx: TableActionContext<T>) => {\n await persistViaProvider(p, actionCtx);\n bumpRefresh((v) => v + 1);\n };\n }, [provider, bumpRefresh]);\n const saveHandler = onSave ?? providerSave;\n\n // Sync table actions to atom. Consumer actions come first (they override a\n // built-in by reusing its id); the built-in column controls (sort/filter)\n // fill in the rest — so both the toolbar and the header dropdown source from\n // one registry. Built-ins self-gate (single sortable/filterable column).\n const _actions: TableAction[] = useMemo(() => {\n const _actions: TableAction[] = [];\n const add = (list: TableAction[]) => {\n for (const a of list) {\n if (!_actions.some((x) => x.id === a.id)) _actions.push(a);\n }\n };\n if (actions != null) add(actions);\n add(columnControlActions);\n if (enableClipboard) add(clipboardActions);\n // Save/reset last — they're the most significant actions — and present for\n // every cardinality (editable), so the toolbar stays mounted regardless of\n // selection.\n if (editable) {\n if (saveHandler != null) add([createSaveAction(saveHandler)]);\n add([resetChangesAction]);\n }\n return _actions;\n }, [actions, enableClipboard, editable, saveHandler]);\n\n ctx.useSync(tableActionsAtom, _actions);\n\n const hotkeysConfig = ctx.useValue(tableHotkeysAtom);\n const { handleKeyDown, handleKeyUp } = useHotkeys(hotkeysConfig);\n\n // For now, we only consider a single cell \"focused\" when we have one cell selected.\n // Multi-cell selections have a different set of \"bulk\" actions.\n const selectedRegions = useSelector<T>((state) => state.selection ?? []);\n\n const data = useSelector((state) => state.data);\n\n const rowStatus = useSelector((state) => state.rowStatus);\n\n const focusedCell = useSelector((state) => state.focusedCell);\n\n const ref = useSelector((state) => state.tableRef);\n\n const columnSpec = useSelector((state) => state.columnSpec);\n\n // A sparse array to hold updates\n // TODO: create a \"changeset\" concept to facilitate undo/redo\n const updatedData = useSelector((state) => state.updatedData);\n\n const onSelection = useSelector((state) => state.onSelection);\n\n const storeAPI = useStoreAPI<T>();\n\n const onScroll = useScrollHandler();\n const _onVisibleCellsChange = useCallback(\n (visibleCells: VisibleCells) => {\n onScroll(visibleCells);\n onVisibleCellsChange?.(visibleCells);\n },\n [onVisibleCellsChange, onScroll],\n );\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Updated data\", updatedData);\n }, [updatedData]);\n\n useEffect(() => {\n onUpdateData?.(updatedData, data);\n }, [onUpdateData, data, updatedData]);\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Selected regions\", selectedRegions);\n }, [selectedRegions]);\n\n const tableElementRef = useRef<HTMLElement>(null);\n useEffect(() => {\n // Return the focus to the table\n tableElementRef.current?.focus();\n }, [focusedCell]);\n\n const columnWidths = ctx.useValue(columnWidthsAtom);\n\n // When filters are active, only show matching rows\n const filteredRowIndices = useSelector((state) => state.filteredRowIndices);\n const totalRows = Math.max(updatedData.length, data.length);\n const numRows =\n filteredRowIndices != null ? filteredRowIndices.length : totalRows;\n\n let className = `${density}-density`;\n\n const { rowHeight, style } = styleParamsForDensity(density);\n\n // In paged mode the row count is small and fixed, so let the table size to\n // its content (header + rows) instead of filling the viewport.\n const footerInfo = ctx.useValue(tableFooterAtom);\n const holderStyle =\n footerInfo.mode === \"paged\"\n ? {\n flex: \"0 0 auto\" as const,\n height: numRows * rowHeight + COLUMN_HEADER_HEIGHT,\n }\n : undefined;\n\n const onColumnsReordered = useSelector((state) => state.onColumnsReordered);\n\n // Auto-detect if any columns have sortable/filterable set.\n // If so and no explicit columnHeaderCellRenderer was provided,\n // use the built-in client-side sort/filter header.\n const hasSortableOrFilterable = useMemo(\n () =>\n columnSpec.some(\n (col) =>\n col.sortable ||\n col.filterable ||\n (Array.isArray(col.filters) && col.filters.length > 0),\n ),\n [columnSpec],\n );\n\n const columnSorts = useSelector((state) => state.columnSorts);\n const activeFilters = useSelector((state) => state.activeFilters);\n\n // Cell activation mode, defaulting from the legacy `autoFocusEditor` boolean\n // so existing consumers are unaffected. Synced into the store so the cell\n // renderer, editors, and key handlers all read it consistently.\n const cellInteractionMode: CellInteraction =\n cellInteraction ?? (autoFocusEditor ? \"auto\" : \"manual\");\n\n const storeState = storeAPI;\n useEffect(() => {\n storeState.setState({ cellInteraction: cellInteractionMode });\n }, [storeState, cellInteractionMode]);\n\n useEffect(() => {\n // Give the store a handle to the focusable holder so editors can return\n // keyboard focus to the table when the cursor leaves them.\n storeState.setState({ tableElement: tableElementRef.current });\n }, [storeState]);\n\n useEffect(() => {\n storeState.setState({ onEdit });\n }, [storeState, onEdit]);\n\n useEffect(() => {\n // Controlled overlay: mirror the caller's edited state into the store as\n // the source of truth. Optimistic in-table edits are superseded on the\n // next render when the caller passes an updated value back. When the caller\n // controls it, the loader-boundary identity remap steps aside.\n const controlled =\n updatedDataProp !== undefined || rowStatusProp !== undefined;\n const patch: Record<string, unknown> = { controlledOverlay: controlled };\n if (updatedDataProp !== undefined) patch.updatedData = updatedDataProp;\n if (rowStatusProp !== undefined) patch.rowStatus = rowStatusProp;\n storeState.setState(patch);\n }, [storeState, updatedDataProp, rowStatusProp]);\n\n // The active provider supplies the row identity for the edit overlay.\n useEffect(() => {\n const id = activeProvider?.identity ?? identity;\n if (id != null) storeState.setState({ identity: id });\n }, [storeState, activeProvider, identity]);\n\n // Row deletion is a provider capability: an explicit `provider` without\n // `deleteRows` disables deletion entirely. (Local / loose sources keep the\n // local delete overlay.)\n useEffect(() => {\n const canDeleteRows = provider == null || provider.deleteRows != null;\n storeState.setState({ canDeleteRows });\n }, [storeState, provider]);\n\n const realizedColumns = useMemo(() => {\n return columnSpec.map((col, colIndex) => {\n let fn =\n col.headerCellRenderer ??\n columnHeaderCellRenderer ??\n renderColumnHeaderCell;\n let activeSort = null;\n let activeFilter = null;\n if (col.sortable) {\n activeSort = columnSorts?.find((s) => s.key === col.key);\n }\n // The active filter for this column is whichever active filter targets\n // it (a rich `col.filters` filter or the generic operator filter) — match\n // by columnKey rather than a fixed id.\n for (const entry of activeFilters?.values() ?? []) {\n if ((entry as any)?.filter?.columnKey === col.key) {\n activeFilter = entry;\n break;\n }\n }\n\n const _columnHeaderCellRenderer = (colIndex) => {\n return fn({\n col,\n colIndex,\n activeSort,\n activeFilter,\n });\n };\n\n return h(Column, {\n id: col.key,\n name: col.name,\n columnHeaderCellRenderer: _columnHeaderCellRenderer,\n cellRenderer: (rowIndex) => {\n const state = storeAPI.getState();\n return basicCellRenderer<T>(\n rowIndex,\n colIndex,\n col,\n state,\n filteredRowIndices,\n );\n },\n });\n });\n }, [\n columnSpec,\n columnSorts,\n activeFilters,\n storeAPI,\n filteredRowIndices,\n columnHeaderCellRenderer,\n ]);\n\n const onColumnWidthChanged = useSelector(\n (state) => state.onColumnWidthChanged,\n );\n\n const rowHeaderCellRenderer = useCallback(\n (rowIndex: number) => {\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n const style =\n rowStatus[dataRowIndex] == TableElementStatus.DELETED\n ? deletedRowHeaderStyle\n : null;\n\n return h(RowHeaderCell, {\n enableRowReordering: false,\n index: rowIndex,\n name: `${dataRowIndex + 1}`,\n style,\n });\n },\n [rowStatus, filteredRowIndices],\n );\n\n let _selectionModes = selectionModes;\n if (\n editable &&\n _selectionModes != null &&\n !_selectionModes.includes(RegionCardinality.CELLS)\n ) {\n _selectionModes = [..._selectionModes, RegionCardinality.CELLS];\n // Ensure selection mode includes \"cells\"\n }\n\n const cellRendererDependencies = [\n data,\n updatedData,\n focusedCell,\n rowStatus,\n filteredRowIndices,\n ];\n\n // Drive the table from the active provider's `fetchData`. A local (in-memory)\n // provider loads the whole array at once; a remote one uses the `pageSize` /\n // `fetchMode` props and shows load progress.\n let _showLoadProgress: boolean = false;\n let dataLoader: ReactNode = null;\n if (activeProvider != null) {\n _showLoadProgress = !isLocalProvider;\n dataLoader = h(_DataLoaderManager, {\n key: \"__data_loader\",\n fetchData: activeProvider.fetchData,\n pageSize: isLocalProvider\n ? Math.max(sourceData?.length ?? 1, 1)\n : pageSize,\n fetchMode: isLocalProvider ? undefined : fetchMode,\n });\n }\n const showFilterBar =\n (filters != null && filters.length > 0) || hasSortableOrFilterable;\n\n let filterStatus: ReactNode = null;\n if (showFilterBar) {\n filterStatus = h(FilterBar, { filters: filters ?? [] });\n }\n\n return h(\"div.data-sheet-container\", { className, style }, [\n // The actions/tools toolbar (selection-modal). Table-scoped controls like\n // scroll-to-row / full-text search live here as ordinary actions.\n h(ActionsToolbar, { actions: _actions, tableName: name }),\n dataLoader,\n children,\n h(\n \"div.data-sheet-holder\",\n {\n tabIndex: 0,\n onKeyDown: handleKeyDown,\n onKeyUp: handleKeyUp,\n ref: tableElementRef,\n style: holderStyle,\n },\n h(\n Table,\n {\n ref,\n numRows,\n className: \"data-sheet\",\n enableFocusedCell,\n onColumnsReordered,\n focusedCell,\n selectedRegions,\n defaultRowHeight: rowHeight,\n minRowHeight: rowHeight,\n columnWidths,\n onColumnWidthChanged,\n onSelection,\n /** TODO: we could enable this, but we need a use-case first... */\n enableRowReordering: false,\n enableRowResizing: false,\n // The cell renderer is memoized internally based on these data dependencies\n cellRendererDependencies,\n onVisibleCellsChange: _onVisibleCellsChange,\n rowHeaderCellRenderer,\n selectionModes: _selectionModes,\n ...rest,\n getCellClipboardData: null,\n },\n realizedColumns,\n ),\n ),\n h(\"div.status-bar\", [\n filterStatus,\n h(\"div.spacer\"),\n h.if(_showLoadProgress)(LoadProgressIndicator),\n ]),\n h.if(debugMode)(CellRendererDebugOverlay, {\n cellRendererDependencies,\n names: [\n \"data\",\n \"updatedData\",\n \"focusedCell\",\n \"rowStatus\",\n \"filteredRowIndices\",\n ],\n }),\n ]);\n}\n\nconst columnWidthsIndexAtom = atom((get) => get(storeAtom).columnWidthsIndex);\nconst defaultColumnWidthAtom = atom((get) => get(storeAtom).defaultColumnWidth);\n\nconst columnWidthsAtom = atom((get) => {\n const ix = get(columnWidthsIndexAtom);\n return get(columnSpecAtom).map(\n (col) => ix.get(col.key) ?? col.width ?? get(defaultColumnWidthAtom),\n );\n});\n\nfunction styleParamsForDensity(density: DataSheetDensity) {\n switch (density) {\n case DataSheetDensity.MEDIUM:\n return {\n rowHeight: 24,\n style: {\n \"--data-sheet-row-height\": \"24px\",\n \"--data-sheet-font-size\": \"14px\",\n },\n };\n case DataSheetDensity.LOW:\n return {\n rowHeight: 30,\n style: {\n \"--data-sheet-row-height\": \"30px\",\n \"--data-sheet-font-size\": \"18px\",\n },\n };\n case DataSheetDensity.HIGH:\n default:\n return {\n rowHeight: 20,\n style: {\n \"--data-sheet-row-height\": \"20px\",\n \"--data-sheet-font-size\": \"12px\",\n },\n };\n }\n}\n\n/** Convenience component: runs `useChunkLoader` from inside a `DataSheet`.\n * Render as a child of `DataSheet` (it renders nothing itself). */\nfunction _DataLoaderManager<T = any>({\n fetchData,\n ...rest\n}: {\n fetchData: FetchData<T>;\n} & FetchDataOptions) {\n useDataLoader(fetchData, rest);\n return null;\n}\n\nexport function getRowsToDelete(selection) {\n let rowIndices: number[] = [];\n for (const sel of selection) {\n // This isn't a full-row selection\n if (sel.cols != null) continue;\n if (sel.rows == null) continue;\n const [startIndex, endIndex] = sel.rows;\n for (let i = startIndex; i <= endIndex; i++) {\n rowIndices.push(i);\n }\n }\n return rowIndices;\n}\n"],"names":["DataSheetDensity","h","DataSheetProvider","provider","ctx","TableElementStatus","filters","useSelector","useMemo","createLocalProvider","dataRefreshTokenAtom","_actions","columnControlActions","clipboardActions","createSaveAction","resetChangesAction","tableActionsAtom","tableHotkeysAtom","useHotkeys","useStoreAPI","useScrollHandler","useCallback","useEffect","useRef","tableFooterAtom","renderColumnHeaderCell","colIndex","Column","basicCellRenderer","style","RowHeaderCell","RegionCardinality","FilterBar","ActionsToolbar","Table","LoadProgressIndicator","CellRendererDebugOverlay","atom","storeAtom","columnSpecAtom","useDataLoader"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AA2DO,IAAK,qCAAAA,sBAAL;AACLA,oBAAA,MAAA,IAAO;AACPA,oBAAA,QAAA,IAAS;AACTA,oBAAA,KAAA,IAAM;AAHI,SAAAA;AAAA,GAAA,oBAAA,CAAA,CAAA;AAQZ,MAAM,uBAAuB;AAgF7B,MAAM,YAAmB,CAAA;AAElB,SAAS,UAAa,OAA0B;AACrD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,yBAAyB;AAAA,IACzB,oBAAoB;AAAA,IACpB,qBAAqB;AAAA,IACrB;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAEJ,SAAOC,YAAAA;AAAAA,IACLC,SAAAA;AAAAA,IACA;AAAA,MACE,MAAM,QAAQ;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,IAELD,YAAAA,QAAE,YAAiB;AAAA,MACjB,GAAG;AAAA,MACH,MAAM,QAAQ;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EAAA;AAEL;AAEA,MAAM,wBAAwB;AAAA,EAC5B,SAAS;AAAA,EACT,gBAAgB;AAClB;AAMA,eAAe,mBACbE,WACAC,MACe;AACf,QAAM,OAAQA,KAAI,QAAQ,CAAA;AAC1B,QAAM,UAAWA,KAAI,eAAe,CAAA;AACpC,QAAM,SAAUA,KAAI,aAAa,CAAA;AACjC,QAAM,IAAI,KAAK,IAAI,KAAK,QAAQ,QAAQ,QAAQ,OAAO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ACF;AAEN;AAIA,SAAS,mBAA4B;AAAA,EACnC;AAAA,EACA,GAAG;AACL,GAEsB;AACpBC,cAAAA,cAAc,WAAW,IAAI;AAC7B,SAAO;AACT;AAEO,SAAS,gBAAgB,WAAW;AACzC,MAAI,aAAuB,CAAA;AAC3B,aAAW,OAAO,WAAW;AAE3B,QAAI,IAAI,QAAQ,KAAM;AACtB,QAAI,IAAI,QAAQ,KAAM;AACtB,UAAM,CAAC,YAAY,QAAQ,IAAI,IAAI;AACnC,aAAS,IAAI,YAAY,KAAK,UAAU,KAAK;AAC3C,iBAAW,KAAK,CAAC;AAAA,IACnB;AAAA,EACF;AACA,SAAO;AACT;;;;"}
1
+ {"version":3,"file":"core.cjs","sources":["../src/core.ts"],"sourcesContent":["import { useHotkeys } from \"@blueprintjs/core\";\nimport {\n Column,\n Region,\n RegionCardinality,\n RowHeaderCell,\n Table,\n TableProps,\n} from \"@blueprintjs/table\";\nimport \"@blueprintjs/table/lib/css/table.css\";\nimport { ReactNode, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { LoadProgressIndicator } from \"./components\";\nimport { renderColumnHeaderCell } from \"./renderers\";\nimport h from \"./main.module.sass\";\nimport {\n columnSpecAtom,\n ctx,\n DataSheetProvider,\n storeAtom,\n tableActionsAtom,\n useSelector,\n useStoreAPI,\n} from \"./provider\";\nimport { atom } from \"jotai\";\nimport {\n DataSheetProviderProps,\n DEFAULT_ROW_STATUS_STYLES,\n EditEvent,\n RowHeaderRenderContext,\n RowStatusStyles,\n TableElementStatus,\n VisibleCells,\n} from \"./types.ts\";\nimport { basicCellRenderer } from \"./cell-renderer.ts\";\nimport {\n CellRendererDebugOverlay,\n tableHotkeysAtom,\n type ColumnSpec,\n} from \"./utils\";\nimport {\n ActionsToolbar,\n clipboardActions,\n columnControlActions,\n createSaveAction,\n FilterBar,\n resetChangesAction,\n TableAction,\n TableActionContext,\n TableFilter,\n} from \"./actions\";\nimport {\n createLocalProvider,\n dataRefreshTokenAtom,\n FetchData,\n FetchDataOptions,\n tableFooterAtom,\n TableDataProvider,\n useScrollHandler,\n useDataLoader,\n} from \"./postgrest-table\";\n\n// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args\n\n// TODO: add a \"copy to selection\" tool (the little square in the bottom right corner of a cell)\n// This should copy the value of a cell (or a set of cells in the same row) downwards.\n\nexport enum DataSheetDensity {\n HIGH = \"high\",\n MEDIUM = \"medium\",\n LOW = \"low\",\n}\n\n/** Approximate column-header + scrollbar allowance, used to size the table to\n * its content in paged mode. */\nconst COLUMN_HEADER_HEIGHT = 34;\n\n/**\n * How selecting a cell activates its surface (an editor, or a read-only detail\n * panel):\n * - `\"auto\"` (default when `autoFocusEditor` is `true`): open the surface on\n * selection and, for editors, focus it. Editors relinquish focus at their\n * edges — arrow past the start/end of a text cell, or press Escape, and focus\n * returns to the table — so the keyboard stays operable without the mouse.\n * Pressing Escape drops into navigation mode (surfaces stop auto-opening)\n * until the next click.\n * - `\"manual\"` (default when `autoFocusEditor` is `false`): the surface stays\n * closed until the cell is clicked; arrow keys always navigate the table.\n */\nexport type CellInteraction = \"auto\" | \"manual\";\n\ninterface DataSheetInternalProps<T> extends TableProps, FetchDataOptions {\n /** In-memory rows. Internally wrapped in a local `TableDataProvider` and\n * driven through the same loader as any other source. */\n data?: T[];\n /** Passed through from the public props so a function form can be derived\n * from the loaded rows here (a static array is handled by the provider). */\n columnSpec?: ColumnSpec[] | ((rows: T[]) => ColumnSpec[]);\n // function to fetch a chunk of data (the read side of a data provider)\n fetchData?: FetchData<T>;\n /** A data provider instantiated separately and passed in — bundles the read\n * side (`fetchData` + `identity`) and, optionally, the persistence side\n * (`saveRows` / `deleteRows` / `insertRow`) that drives the Save action. An\n * explicit alternative to the loose `data` / `fetchData` / `identity` props;\n * takes precedence when given. */\n provider?: TableDataProvider<T>;\n // An optional table name that will be used in toolbars if given\n name?: string;\n onVisibleCellsChange?: (visibleCells: VisibleCells) => void;\n onUpdateData?: (updatedData: any[], data: T[]) => void;\n /** Observer called for every user edit as a structured `EditEvent`\n * (Workstream A). Additive: the built-in `updatedData` overlay still\n * applies. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Controlled edited-cell overlay (Workstream A). When provided, it is\n * synced into the store as the source of truth for edited values — pair with\n * `onEdit` to own edit state externally (e.g. an ops model). Optimistic\n * in-table edits are superseded by the next value you pass back. */\n updatedData?: T[];\n /** Controlled row-status overlay (edited / added / deleted), the companion\n * to `updatedData`. */\n rowStatus?: TableElementStatus[];\n /** Row identity for the edit overlay — stable across a provider re-sort (a\n * data provider supplies its own; defaults to `(row) => row?.id`). Lets edits\n * survive a re-ordered re-fetch. */\n identity?: (row: T) => string | number | null | undefined;\n /** Derive the controlled edit overlay from the loaded rows, *inside* the\n * sheet. For provider-backed tables whose overlay is a function of the loaded\n * data plus external edit state (e.g. an ops stack): the library owns the\n * rows, so it calls this with them and uses the result as the controlled\n * overlay, re-deriving when the rows — or this function's identity (close it\n * over your edit state) — change. Supersedes `updatedData`/`rowStatus`. */\n deriveOverlay?: (rows: T[]) => {\n updatedData: T[];\n rowStatus: TableElementStatus[];\n };\n /** Bump to force the data provider to re-fetch from scratch (e.g. after a\n * save/delete that invalidated the loaded rows). */\n refreshToken?: number | string;\n /** Persistence handler for the built-in Save action. When provided, a Save\n * control is added to the toolbar (always visible, disabled when there are\n * no pending changes). */\n onSave?: (ctx: TableActionContext<T>) => void | Promise<void>;\n onDeleteRows?: (selection: Region[]) => void;\n verbose?: boolean;\n enableColumnReordering?: boolean;\n enableClipboard?: boolean;\n enableFocusedCell?: boolean;\n editable?: boolean;\n /** @deprecated Prefer `cellInteraction`. `true` maps to `\"auto\"`,\n * `false` to `\"manual\"`. */\n autoFocusEditor?: boolean;\n /** How selecting a cell activates its surface (editor or detail panel).\n * Defaults from `autoFocusEditor` for backward compatibility. */\n cellInteraction?: CellInteraction;\n density?: DataSheetDensity;\n /** Configurable table actions shown in a selection-aware toolbar.\n * When provided, the actions toolbar renders alongside the existing\n * edit toolbar. Actions are filtered by the current selection cardinality. */\n actions?: TableAction<T>[];\n /** Available column/table filters shown in a filter bar.\n * Filters can also be defined per-column via `ColumnSpec.filters`. */\n filters?: TableFilter<T>[];\n /** Optional custom column header cell renderer, called for each column.\n * Receives the ColumnSpec and column index; should return a React element\n * (typically a Blueprint ColumnHeaderCell). */\n columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;\n /** Arbitrary nodes for the bottom status bar (left group), rendered beside\n * the active sort/filter tags — the home for view-state controls (show/hide\n * omitted rows/columns, a group-by indicator, etc.). */\n statusBar?: ReactNode;\n /** Presentation per row-status value, merged over the built-in defaults\n * (which style `\"deleted\"`). Supply styles for consumer-defined statuses\n * (e.g. `\"omitted\"`) and/or override the defaults. Each entry may set the\n * cells' style/intent and the row header's style. */\n rowStatusStyles?: RowStatusStyles;\n /** Render the content of a row's header cell (the left gutter). Receives the\n * row, its status, and the default 1-based label; return a node to use, or a\n * nullish value to keep the default. For group-key labels, omit indicators,\n * etc. Header-cell *styling* still comes from `rowStatusStyles`. */\n rowHeaderRenderer?: (ctx: RowHeaderRenderContext<T>) => ReactNode;\n}\n\ntype DataSheetProps<T> = DataSheetProviderProps<T> & DataSheetInternalProps<T>;\n\nconst emptyData: any[] = [];\n\nexport function DataSheet<T>(props: DataSheetProps<T>) {\n const {\n data,\n columnSpec,\n columnSpecOptions,\n editable = true,\n enableColumnReordering = false,\n enableFocusedCell = false,\n defaultColumnWidth = 150,\n children,\n ...rest\n } = props;\n\n return h(\n DataSheetProvider<T>,\n {\n data: data ?? emptyData,\n columnSpec,\n columnSpecOptions,\n enableColumnReordering,\n defaultColumnWidth,\n editable,\n ...rest,\n },\n h(_DataSheet<any>, {\n ...rest,\n data: data ?? emptyData,\n columnSpec,\n children,\n editable,\n enableColumnReordering,\n enableFocusedCell,\n }),\n );\n}\n\n/** Persist all pending changes through a data provider: added rows via\n * `insertRow`, edited rows via `saveRows`, deleted rows via `deleteRows`\n * (addressed by `provider.identity`). Used by the built-in Save action when an\n * explicit provider owns persistence. */\nasync function persistViaProvider<T>(\n provider: TableDataProvider<T>,\n ctx: TableActionContext<T>,\n): Promise<void> {\n const base = (ctx.data ?? []) as any[];\n const updates = (ctx.updatedData ?? []) as any[];\n const status = (ctx.rowStatus ?? []) as any[];\n const n = Math.max(base.length, updates.length, status.length);\n const toSave: T[] = [];\n const toInsert: T[] = [];\n const toDelete: Array<string | number> = [];\n for (let i = 0; i < n; i++) {\n if (status[i] === TableElementStatus.DELETED) {\n const id = provider.identity(base[i]);\n if (id != null) toDelete.push(id);\n continue;\n }\n const upd = updates[i];\n const hasEdit =\n upd != null && typeof upd === \"object\" && Object.keys(upd).length > 0;\n if (status[i] === TableElementStatus.ADDED) {\n toInsert.push({ ...base[i], ...upd } as T);\n } else if (hasEdit) {\n toSave.push({ ...base[i], ...upd } as T);\n }\n }\n if (toDelete.length > 0 && provider.deleteRows != null) {\n await provider.deleteRows(toDelete);\n }\n for (const row of toInsert) {\n if (provider.insertRow != null) await provider.insertRow(row);\n }\n if (toSave.length > 0 && provider.saveRows != null) {\n await provider.saveRows(toSave);\n }\n}\n\nfunction _DataSheet<T>({\n data: sourceData,\n fetchData,\n provider,\n pageSize,\n fetchMode,\n onVisibleCellsChange,\n onUpdateData,\n onEdit,\n onSave,\n updatedData: updatedDataProp,\n rowStatus: rowStatusProp,\n identity,\n deriveOverlay,\n refreshToken,\n onDeleteRows,\n name,\n verbose = false,\n enableFocusedCell,\n autoFocusEditor = true,\n cellInteraction,\n enableClipboard = true,\n density = DataSheetDensity.HIGH,\n selectionModes,\n actions,\n filters,\n columnHeaderCellRenderer,\n columnSpec: columnSpecProp,\n statusBar,\n rowStatusStyles,\n rowHeaderRenderer,\n children,\n ...rest\n}: DataSheetInternalProps<T>) {\n /**\n * @param data: The data to be displayed in the table\n * @param columnSpec: The specification for all columns in the table. If not provided, the column spec will be generated from the data.\n * @param columnSpecOptions: Options for generating a column spec from data\n */\n\n // Turn on debug features\n const debugMode = false;\n\n const editable = useSelector((state) => state.editable);\n\n // Resolve the active data provider: an explicit `provider` prop wins; else a\n // loose `fetchData` (+ identity) is wrapped as one; else in-memory `data`\n // becomes a local provider. Local and remote thus share one path, and the\n // provider is an explicit contract rather than a set of scattered props.\n const isLocalProvider = provider == null && fetchData == null;\n const activeProvider = useMemo<TableDataProvider<any> | null>(() => {\n if (provider != null) return provider;\n if (fetchData != null) {\n return { fetchData, identity: identity ?? ((r: any) => r?.id) };\n }\n if (sourceData != null && sourceData.length > 0) {\n return createLocalProvider(\n sourceData,\n identity != null ? { identity } : undefined,\n );\n }\n return null;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [provider, fetchData, sourceData, identity]);\n\n // When an explicit provider owns persistence, its methods drive the built-in\n // Save (batch: edits→saveRows, added→insertRow, deleted→deleteRows), then a\n // refresh. Otherwise the loose `onSave` handler is used.\n const bumpRefresh = ctx.useSet(dataRefreshTokenAtom);\n const providerSave = useMemo(() => {\n const p = provider;\n if (\n p == null ||\n (p.saveRows == null && p.deleteRows == null && p.insertRow == null)\n ) {\n return null;\n }\n return async (actionCtx: TableActionContext<T>) => {\n await persistViaProvider(p, actionCtx);\n bumpRefresh((v) => v + 1);\n };\n }, [provider, bumpRefresh]);\n const saveHandler = onSave ?? providerSave;\n\n // Sync table actions to atom. Consumer actions come first (they override a\n // built-in by reusing its id); the built-in column controls (sort/filter)\n // fill in the rest — so both the toolbar and the header dropdown source from\n // one registry. Built-ins self-gate (single sortable/filterable column).\n const _actions: TableAction[] = useMemo(() => {\n const _actions: TableAction[] = [];\n const add = (list: TableAction[]) => {\n for (const a of list) {\n if (!_actions.some((x) => x.id === a.id)) _actions.push(a);\n }\n };\n if (actions != null) add(actions);\n add(columnControlActions);\n if (enableClipboard) add(clipboardActions);\n // Save/reset last — they're the most significant actions — and present for\n // every cardinality (editable), so the toolbar stays mounted regardless of\n // selection.\n if (editable) {\n if (saveHandler != null) add([createSaveAction(saveHandler)]);\n add([resetChangesAction]);\n }\n return _actions;\n }, [actions, enableClipboard, editable, saveHandler]);\n\n ctx.useSync(tableActionsAtom, _actions);\n\n const hotkeysConfig = ctx.useValue(tableHotkeysAtom);\n const { handleKeyDown, handleKeyUp } = useHotkeys(hotkeysConfig);\n\n // For now, we only consider a single cell \"focused\" when we have one cell selected.\n // Multi-cell selections have a different set of \"bulk\" actions.\n const selectedRegions = useSelector<T>((state) => state.selection ?? []);\n\n const data = useSelector((state) => state.data);\n\n const rowStatus = useSelector((state) => state.rowStatus);\n\n const focusedCell = useSelector((state) => state.focusedCell);\n\n const ref = useSelector((state) => state.tableRef);\n\n const columnSpec = useSelector((state) => state.columnSpec);\n\n // A sparse array to hold updates\n // TODO: create a \"changeset\" concept to facilitate undo/redo\n const updatedData = useSelector((state) => state.updatedData);\n\n const onSelection = useSelector((state) => state.onSelection);\n\n const storeAPI = useStoreAPI<T>();\n\n const onScroll = useScrollHandler();\n const _onVisibleCellsChange = useCallback(\n (visibleCells: VisibleCells) => {\n onScroll(visibleCells);\n onVisibleCellsChange?.(visibleCells);\n },\n [onVisibleCellsChange, onScroll],\n );\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Updated data\", updatedData);\n }, [updatedData]);\n\n useEffect(() => {\n onUpdateData?.(updatedData, data);\n }, [onUpdateData, data, updatedData]);\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Selected regions\", selectedRegions);\n }, [selectedRegions]);\n\n const tableElementRef = useRef<HTMLElement>(null);\n useEffect(() => {\n // Return the focus to the table\n tableElementRef.current?.focus();\n }, [focusedCell]);\n\n const columnWidths = ctx.useValue(columnWidthsAtom);\n\n // When filters are active, only show matching rows\n const filteredRowIndices = useSelector((state) => state.filteredRowIndices);\n const totalRows = Math.max(updatedData.length, data.length);\n const numRows =\n filteredRowIndices != null ? filteredRowIndices.length : totalRows;\n\n let className = `${density}-density`;\n\n const { rowHeight, style } = styleParamsForDensity(density);\n\n // In paged mode the row count is small and fixed, so let the table size to\n // its content (header + rows) instead of filling the viewport.\n const footerInfo = ctx.useValue(tableFooterAtom);\n const holderStyle =\n footerInfo.mode === \"paged\"\n ? {\n flex: \"0 0 auto\" as const,\n height: numRows * rowHeight + COLUMN_HEADER_HEIGHT,\n }\n : undefined;\n\n const onColumnsReordered = useSelector((state) => state.onColumnsReordered);\n\n // Auto-detect if any columns have sortable/filterable set.\n // If so and no explicit columnHeaderCellRenderer was provided,\n // use the built-in client-side sort/filter header.\n const hasSortableOrFilterable = useMemo(\n () =>\n columnSpec.some(\n (col) =>\n col.sortable ||\n col.filterable ||\n (Array.isArray(col.filters) && col.filters.length > 0),\n ),\n [columnSpec],\n );\n\n const columnSorts = useSelector((state) => state.columnSorts);\n const activeFilters = useSelector((state) => state.activeFilters);\n\n // Cell activation mode, defaulting from the legacy `autoFocusEditor` boolean\n // so existing consumers are unaffected. Synced into the store so the cell\n // renderer, editors, and key handlers all read it consistently.\n const cellInteractionMode: CellInteraction =\n cellInteraction ?? (autoFocusEditor ? \"auto\" : \"manual\");\n\n const storeState = storeAPI;\n useEffect(() => {\n storeState.setState({ cellInteraction: cellInteractionMode });\n }, [storeState, cellInteractionMode]);\n\n useEffect(() => {\n // Give the store a handle to the focusable holder so editors can return\n // keyboard focus to the table when the cursor leaves them.\n storeState.setState({ tableElement: tableElementRef.current });\n }, [storeState]);\n\n useEffect(() => {\n storeState.setState({ onEdit });\n }, [storeState, onEdit]);\n\n useEffect(() => {\n // Controlled overlay: mirror the caller's edited state into the store as\n // the source of truth. Optimistic in-table edits are superseded on the\n // next render when the caller passes an updated value back. When the caller\n // controls it, the loader-boundary identity remap steps aside.\n const controlled =\n updatedDataProp !== undefined ||\n rowStatusProp !== undefined ||\n deriveOverlay != null;\n const patch: Record<string, unknown> = { controlledOverlay: controlled };\n if (updatedDataProp !== undefined) patch.updatedData = updatedDataProp;\n if (rowStatusProp !== undefined) patch.rowStatus = rowStatusProp;\n storeState.setState(patch);\n }, [storeState, updatedDataProp, rowStatusProp, deriveOverlay]);\n\n // Derived controlled overlay: the library owns the loaded rows, so it runs\n // the consumer's `deriveOverlay(rows)` here and pushes the result. Re-derives\n // when the rows load/change or the function's identity changes (close it over\n // your external edit state). The `controlledOverlay` flag above suppresses the\n // loader-boundary identity remap so this derivation is authoritative.\n const loadedData = useSelector((state) => state.data);\n useEffect(() => {\n if (deriveOverlay == null) return;\n const overlay = deriveOverlay(loadedData);\n storeState.setState({\n updatedData: overlay.updatedData,\n rowStatus: overlay.rowStatus,\n });\n }, [deriveOverlay, loadedData, storeState]);\n\n // Function `columnSpec`: derive the spec from the loaded rows (no separate\n // fetch of sample data). Derive once the first rows arrive, and re-derive\n // when the function's identity changes (a consumer memoizes it over its\n // own view state — hidden columns, order, overrides). Not re-run as more\n // rows page in (guarded by the function identity), so it never clobbers\n // in-store column state on scroll.\n const derivedSpecFor = useRef<unknown>(null);\n useEffect(() => {\n if (typeof columnSpecProp !== \"function\") return;\n if (derivedSpecFor.current === columnSpecProp) return;\n const rows = loadedData.filter((r) => r != null);\n if (rows.length === 0) return;\n derivedSpecFor.current = columnSpecProp;\n storeState.setState({ columnSpec: columnSpecProp(rows) });\n }, [columnSpecProp, loadedData, storeState]);\n\n // Imperative re-fetch: bump `refreshToken` to reload the provider (e.g. after\n // a save). Skips the initial mount (the loader does its own first fetch).\n const bumpRefreshFromToken = ctx.useSet(dataRefreshTokenAtom);\n const firstRefreshToken = useRef(true);\n useEffect(() => {\n if (firstRefreshToken.current) {\n firstRefreshToken.current = false;\n return;\n }\n bumpRefreshFromToken((v) => v + 1);\n }, [refreshToken, bumpRefreshFromToken]);\n\n // The active provider supplies the row identity for the edit overlay.\n useEffect(() => {\n const id = activeProvider?.identity ?? identity;\n if (id != null) storeState.setState({ identity: id });\n }, [storeState, activeProvider, identity]);\n\n // Row deletion is a provider capability: an explicit `provider` without\n // `deleteRows` disables deletion entirely. (Local / loose sources keep the\n // local delete overlay.)\n useEffect(() => {\n const canDeleteRows = provider == null || provider.deleteRows != null;\n storeState.setState({ canDeleteRows });\n }, [storeState, provider]);\n\n // Merge consumer `rowStatusStyles` over the built-in defaults and hand the\n // result to the store, where the cell renderer and row-header renderer read\n // it. Merged (not replaced) so overriding one status doesn't drop the rest.\n const mergedRowStatusStyles = useMemo<RowStatusStyles>(\n () => ({ ...DEFAULT_ROW_STATUS_STYLES, ...rowStatusStyles }),\n [rowStatusStyles],\n );\n useEffect(() => {\n storeState.setState({ rowStatusStyles: mergedRowStatusStyles });\n }, [storeState, mergedRowStatusStyles]);\n\n const realizedColumns = useMemo(() => {\n return columnSpec.map((col, colIndex) => {\n let fn =\n col.headerCellRenderer ??\n columnHeaderCellRenderer ??\n renderColumnHeaderCell;\n let activeSort = null;\n let activeFilter = null;\n if (col.sortable) {\n activeSort = columnSorts?.find((s) => s.key === col.key);\n }\n // The active filter for this column is whichever active filter targets\n // it (a rich `col.filters` filter or the generic operator filter) — match\n // by columnKey rather than a fixed id.\n for (const entry of activeFilters?.values() ?? []) {\n if ((entry as any)?.filter?.columnKey === col.key) {\n activeFilter = entry;\n break;\n }\n }\n\n const _columnHeaderCellRenderer = (colIndex) => {\n return fn({\n col,\n colIndex,\n activeSort,\n activeFilter,\n });\n };\n\n return h(Column, {\n id: col.key,\n name: col.name,\n columnHeaderCellRenderer: _columnHeaderCellRenderer,\n cellRenderer: (rowIndex) => {\n const state = storeAPI.getState();\n return basicCellRenderer<T>(\n rowIndex,\n colIndex,\n col,\n state,\n filteredRowIndices,\n );\n },\n });\n });\n }, [\n columnSpec,\n columnSorts,\n activeFilters,\n storeAPI,\n filteredRowIndices,\n columnHeaderCellRenderer,\n ]);\n\n const onColumnWidthChanged = useSelector(\n (state) => state.onColumnWidthChanged,\n );\n\n const rowHeaderCellRenderer = useCallback(\n (rowIndex: number) => {\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n const statusVal = rowStatus[dataRowIndex];\n const style =\n (statusVal != null\n ? mergedRowStatusStyles[statusVal]?.headerStyle\n : null) ?? null;\n\n const defaultLabel = `${dataRowIndex + 1}`;\n let name: ReactNode = defaultLabel;\n if (rowHeaderRenderer != null) {\n const custom = rowHeaderRenderer({\n rowIndex: dataRowIndex,\n visibleIndex: rowIndex,\n row: data[dataRowIndex] ?? updatedData[dataRowIndex],\n status: statusVal,\n isDeleted: statusVal === TableElementStatus.DELETED,\n defaultLabel,\n });\n if (custom != null) name = custom;\n }\n\n return h(RowHeaderCell, {\n enableRowReordering: false,\n index: rowIndex,\n name,\n style,\n });\n },\n [\n rowStatus,\n filteredRowIndices,\n mergedRowStatusStyles,\n rowHeaderRenderer,\n data,\n updatedData,\n ],\n );\n\n let _selectionModes = selectionModes;\n if (\n editable &&\n _selectionModes != null &&\n !_selectionModes.includes(RegionCardinality.CELLS)\n ) {\n _selectionModes = [..._selectionModes, RegionCardinality.CELLS];\n // Ensure selection mode includes \"cells\"\n }\n\n const cellRendererDependencies = [\n data,\n updatedData,\n focusedCell,\n rowStatus,\n filteredRowIndices,\n ];\n\n // Drive the table from the active provider's `fetchData`. A local (in-memory)\n // provider loads the whole array at once; a remote one uses the `pageSize` /\n // `fetchMode` props and shows load progress.\n let _showLoadProgress: boolean = false;\n let dataLoader: ReactNode = null;\n if (activeProvider != null) {\n _showLoadProgress = !isLocalProvider;\n dataLoader = h(_DataLoaderManager, {\n key: \"__data_loader\",\n fetchData: activeProvider.fetchData,\n pageSize: isLocalProvider\n ? Math.max(sourceData?.length ?? 1, 1)\n : pageSize,\n fetchMode: isLocalProvider ? undefined : fetchMode,\n });\n }\n const showFilterBar =\n (filters != null && filters.length > 0) || hasSortableOrFilterable;\n\n let filterStatus: ReactNode = null;\n if (showFilterBar) {\n filterStatus = h(FilterBar, { filters: filters ?? [] });\n }\n\n return h(\"div.data-sheet-container\", { className, style }, [\n // The actions/tools toolbar (selection-modal). Table-scoped controls like\n // scroll-to-row / full-text search live here as ordinary actions.\n h(ActionsToolbar, { actions: _actions, tableName: name }),\n dataLoader,\n children,\n h(\n \"div.data-sheet-holder\",\n {\n tabIndex: 0,\n onKeyDown: handleKeyDown,\n onKeyUp: handleKeyUp,\n ref: tableElementRef,\n style: holderStyle,\n },\n h(\n Table,\n {\n ref,\n numRows,\n className: \"data-sheet\",\n enableFocusedCell,\n onColumnsReordered,\n focusedCell,\n selectedRegions,\n defaultRowHeight: rowHeight,\n minRowHeight: rowHeight,\n columnWidths,\n onColumnWidthChanged,\n onSelection,\n /** TODO: we could enable this, but we need a use-case first... */\n enableRowReordering: false,\n enableRowResizing: false,\n // The cell renderer is memoized internally based on these data dependencies\n cellRendererDependencies,\n onVisibleCellsChange: _onVisibleCellsChange,\n rowHeaderCellRenderer,\n selectionModes: _selectionModes,\n ...rest,\n getCellClipboardData: null,\n },\n realizedColumns,\n ),\n ),\n h(\"div.status-bar\", [\n filterStatus,\n statusBar,\n h(\"div.spacer\"),\n h.if(_showLoadProgress)(LoadProgressIndicator),\n ]),\n h.if(debugMode)(CellRendererDebugOverlay, {\n cellRendererDependencies,\n names: [\n \"data\",\n \"updatedData\",\n \"focusedCell\",\n \"rowStatus\",\n \"filteredRowIndices\",\n ],\n }),\n ]);\n}\n\nconst columnWidthsIndexAtom = atom((get) => get(storeAtom).columnWidthsIndex);\nconst defaultColumnWidthAtom = atom((get) => get(storeAtom).defaultColumnWidth);\n\nconst columnWidthsAtom = atom((get) => {\n const ix = get(columnWidthsIndexAtom);\n return get(columnSpecAtom).map(\n (col) => ix.get(col.key) ?? col.width ?? get(defaultColumnWidthAtom),\n );\n});\n\nfunction styleParamsForDensity(density: DataSheetDensity) {\n switch (density) {\n case DataSheetDensity.MEDIUM:\n return {\n rowHeight: 24,\n style: {\n \"--data-sheet-row-height\": \"24px\",\n \"--data-sheet-font-size\": \"14px\",\n },\n };\n case DataSheetDensity.LOW:\n return {\n rowHeight: 30,\n style: {\n \"--data-sheet-row-height\": \"30px\",\n \"--data-sheet-font-size\": \"18px\",\n },\n };\n case DataSheetDensity.HIGH:\n default:\n return {\n rowHeight: 20,\n style: {\n \"--data-sheet-row-height\": \"20px\",\n \"--data-sheet-font-size\": \"12px\",\n },\n };\n }\n}\n\n/** Convenience component: runs `useChunkLoader` from inside a `DataSheet`.\n * Render as a child of `DataSheet` (it renders nothing itself). */\nfunction _DataLoaderManager<T = any>({\n fetchData,\n ...rest\n}: {\n fetchData: FetchData<T>;\n} & FetchDataOptions) {\n useDataLoader(fetchData, rest);\n return null;\n}\n\nexport function getRowsToDelete(selection) {\n let rowIndices: number[] = [];\n for (const sel of selection) {\n // This isn't a full-row selection\n if (sel.cols != null) continue;\n if (sel.rows == null) continue;\n const [startIndex, endIndex] = sel.rows;\n for (let i = startIndex; i <= endIndex; i++) {\n rowIndices.push(i);\n }\n }\n return rowIndices;\n}\n"],"names":["DataSheetDensity","h","DataSheetProvider","provider","ctx","TableElementStatus","filters","useSelector","useMemo","createLocalProvider","dataRefreshTokenAtom","_actions","columnControlActions","clipboardActions","createSaveAction","resetChangesAction","tableActionsAtom","tableHotkeysAtom","useHotkeys","useStoreAPI","useScrollHandler","useCallback","useEffect","useRef","tableFooterAtom","DEFAULT_ROW_STATUS_STYLES","renderColumnHeaderCell","colIndex","Column","basicCellRenderer","style","name","RowHeaderCell","RegionCardinality","FilterBar","ActionsToolbar","Table","LoadProgressIndicator","CellRendererDebugOverlay","atom","storeAtom","columnSpecAtom","useDataLoader"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAkEO,IAAK,qCAAAA,sBAAL;AACLA,oBAAA,MAAA,IAAO;AACPA,oBAAA,QAAA,IAAS;AACTA,oBAAA,KAAA,IAAM;AAHI,SAAAA;AAAA,GAAA,oBAAA,CAAA,CAAA;AAQZ,MAAM,uBAAuB;AA8G7B,MAAM,YAAmB,CAAA;AAElB,SAAS,UAAa,OAA0B;AACrD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,yBAAyB;AAAA,IACzB,oBAAoB;AAAA,IACpB,qBAAqB;AAAA,IACrB;AAAA,IACA,GAAG;AAAA,EAAA,I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I,YAAY,KAAK,UAAU,KAAK;AAC3C,iBAAW,KAAK,CAAC;AAAA,IACnB;AAAA,EACF;AACA,SAAO;AACT;;;;"}
package/dist/core.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import { Region, TableProps } from '@blueprintjs/table';
2
2
  import { ReactNode } from 'react';
3
- import { DataSheetProviderProps, EditEvent, TableElementStatus, VisibleCells } from './types.ts';
3
+ import { DataSheetProviderProps, EditEvent, RowHeaderRenderContext, RowStatusStyles, TableElementStatus, VisibleCells } from './types.ts';
4
+ import { ColumnSpec } from './utils';
4
5
  import { TableAction, TableActionContext, TableFilter } from './actions';
5
6
  import { FetchData, FetchDataOptions, TableDataProvider } from './postgrest-table';
6
7
  export declare enum DataSheetDensity {
@@ -25,6 +26,9 @@ interface DataSheetInternalProps<T> extends TableProps, FetchDataOptions {
25
26
  /** In-memory rows. Internally wrapped in a local `TableDataProvider` and
26
27
  * driven through the same loader as any other source. */
27
28
  data?: T[];
29
+ /** Passed through from the public props so a function form can be derived
30
+ * from the loaded rows here (a static array is handled by the provider). */
31
+ columnSpec?: ColumnSpec[] | ((rows: T[]) => ColumnSpec[]);
28
32
  fetchData?: FetchData<T>;
29
33
  /** A data provider instantiated separately and passed in — bundles the read
30
34
  * side (`fetchData` + `identity`) and, optionally, the persistence side
@@ -51,6 +55,19 @@ interface DataSheetInternalProps<T> extends TableProps, FetchDataOptions {
51
55
  * data provider supplies its own; defaults to `(row) => row?.id`). Lets edits
52
56
  * survive a re-ordered re-fetch. */
53
57
  identity?: (row: T) => string | number | null | undefined;
58
+ /** Derive the controlled edit overlay from the loaded rows, *inside* the
59
+ * sheet. For provider-backed tables whose overlay is a function of the loaded
60
+ * data plus external edit state (e.g. an ops stack): the library owns the
61
+ * rows, so it calls this with them and uses the result as the controlled
62
+ * overlay, re-deriving when the rows — or this function's identity (close it
63
+ * over your edit state) — change. Supersedes `updatedData`/`rowStatus`. */
64
+ deriveOverlay?: (rows: T[]) => {
65
+ updatedData: T[];
66
+ rowStatus: TableElementStatus[];
67
+ };
68
+ /** Bump to force the data provider to re-fetch from scratch (e.g. after a
69
+ * save/delete that invalidated the loaded rows). */
70
+ refreshToken?: number | string;
54
71
  /** Persistence handler for the built-in Save action. When provided, a Save
55
72
  * control is added to the toolbar (always visible, disabled when there are
56
73
  * no pending changes). */
@@ -79,6 +96,20 @@ interface DataSheetInternalProps<T> extends TableProps, FetchDataOptions {
79
96
  * Receives the ColumnSpec and column index; should return a React element
80
97
  * (typically a Blueprint ColumnHeaderCell). */
81
98
  columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;
99
+ /** Arbitrary nodes for the bottom status bar (left group), rendered beside
100
+ * the active sort/filter tags — the home for view-state controls (show/hide
101
+ * omitted rows/columns, a group-by indicator, etc.). */
102
+ statusBar?: ReactNode;
103
+ /** Presentation per row-status value, merged over the built-in defaults
104
+ * (which style `"deleted"`). Supply styles for consumer-defined statuses
105
+ * (e.g. `"omitted"`) and/or override the defaults. Each entry may set the
106
+ * cells' style/intent and the row header's style. */
107
+ rowStatusStyles?: RowStatusStyles;
108
+ /** Render the content of a row's header cell (the left gutter). Receives the
109
+ * row, its status, and the default 1-based label; return a node to use, or a
110
+ * nullish value to keep the default. For group-key labels, omit indicators,
111
+ * etc. Header-cell *styling* still comes from `rowStatusStyles`. */
112
+ rowHeaderRenderer?: (ctx: RowHeaderRenderContext<T>) => ReactNode;
82
113
  }
83
114
  type DataSheetProps<T> = DataSheetProviderProps<T> & DataSheetInternalProps<T>;
84
115
  export declare function DataSheet<T>(props: DataSheetProps<T>): import('react').FunctionComponentElement<DataSheetProviderProps<T>>;
package/dist/core.js CHANGED
@@ -5,7 +5,7 @@ import { useMemo, useCallback, useEffect, useRef } from "react";
5
5
  import h from "./main.module.sass.js";
6
6
  import { DataSheetProvider, useSelector, ctx, tableActionsAtom, useStoreAPI, columnSpecAtom, storeAtom } from "./provider.js";
7
7
  import { atom } from "jotai";
8
- import { TableElementStatus } from "./types.js";
8
+ import { DEFAULT_ROW_STATUS_STYLES, TableElementStatus } from "./types.js";
9
9
  import { basicCellRenderer } from "./cell-renderer.js";
10
10
  import { createLocalProvider, dataRefreshTokenAtom, useScrollHandler, tableFooterAtom, useDataLoader } from "./postgrest-table/data-loaders.js";
11
11
  import { tableHotkeysAtom } from "./utils/key-handling.js";
@@ -52,6 +52,7 @@ function DataSheet(props) {
52
52
  h(_DataSheet, {
53
53
  ...rest,
54
54
  data: data ?? emptyData,
55
+ columnSpec,
55
56
  children,
56
57
  editable,
57
58
  enableColumnReordering,
@@ -59,10 +60,6 @@ function DataSheet(props) {
59
60
  })
60
61
  );
61
62
  }
62
- const deletedRowHeaderStyle = {
63
- opacity: 0.5,
64
- textDecoration: "line-through"
65
- };
66
63
  async function persistViaProvider(provider, ctx2) {
67
64
  const base = ctx2.data ?? [];
68
65
  const updates = ctx2.updatedData ?? [];
@@ -108,6 +105,8 @@ function _DataSheet({
108
105
  updatedData: updatedDataProp,
109
106
  rowStatus: rowStatusProp,
110
107
  identity,
108
+ deriveOverlay,
109
+ refreshToken,
111
110
  onDeleteRows,
112
111
  name,
113
112
  verbose = false,
@@ -120,6 +119,10 @@ function _DataSheet({
120
119
  actions,
121
120
  filters,
122
121
  columnHeaderCellRenderer,
122
+ columnSpec: columnSpecProp,
123
+ statusBar,
124
+ rowStatusStyles,
125
+ rowHeaderRenderer,
123
126
  children,
124
127
  ...rest
125
128
  }) {
@@ -234,12 +237,39 @@ function _DataSheet({
234
237
  storeState.setState({ onEdit });
235
238
  }, [storeState, onEdit]);
236
239
  useEffect(() => {
237
- const controlled = updatedDataProp !== void 0 || rowStatusProp !== void 0;
240
+ const controlled = updatedDataProp !== void 0 || rowStatusProp !== void 0 || deriveOverlay != null;
238
241
  const patch = { controlledOverlay: controlled };
239
242
  if (updatedDataProp !== void 0) patch.updatedData = updatedDataProp;
240
243
  if (rowStatusProp !== void 0) patch.rowStatus = rowStatusProp;
241
244
  storeState.setState(patch);
242
- }, [storeState, updatedDataProp, rowStatusProp]);
245
+ }, [storeState, updatedDataProp, rowStatusProp, deriveOverlay]);
246
+ const loadedData = useSelector((state) => state.data);
247
+ useEffect(() => {
248
+ if (deriveOverlay == null) return;
249
+ const overlay = deriveOverlay(loadedData);
250
+ storeState.setState({
251
+ updatedData: overlay.updatedData,
252
+ rowStatus: overlay.rowStatus
253
+ });
254
+ }, [deriveOverlay, loadedData, storeState]);
255
+ const derivedSpecFor = useRef(null);
256
+ useEffect(() => {
257
+ if (typeof columnSpecProp !== "function") return;
258
+ if (derivedSpecFor.current === columnSpecProp) return;
259
+ const rows = loadedData.filter((r) => r != null);
260
+ if (rows.length === 0) return;
261
+ derivedSpecFor.current = columnSpecProp;
262
+ storeState.setState({ columnSpec: columnSpecProp(rows) });
263
+ }, [columnSpecProp, loadedData, storeState]);
264
+ const bumpRefreshFromToken = ctx.useSet(dataRefreshTokenAtom);
265
+ const firstRefreshToken = useRef(true);
266
+ useEffect(() => {
267
+ if (firstRefreshToken.current) {
268
+ firstRefreshToken.current = false;
269
+ return;
270
+ }
271
+ bumpRefreshFromToken((v) => v + 1);
272
+ }, [refreshToken, bumpRefreshFromToken]);
243
273
  useEffect(() => {
244
274
  const id = activeProvider?.identity ?? identity;
245
275
  if (id != null) storeState.setState({ identity: id });
@@ -248,6 +278,13 @@ function _DataSheet({
248
278
  const canDeleteRows = provider == null || provider.deleteRows != null;
249
279
  storeState.setState({ canDeleteRows });
250
280
  }, [storeState, provider]);
281
+ const mergedRowStatusStyles = useMemo(
282
+ () => ({ ...DEFAULT_ROW_STATUS_STYLES, ...rowStatusStyles }),
283
+ [rowStatusStyles]
284
+ );
285
+ useEffect(() => {
286
+ storeState.setState({ rowStatusStyles: mergedRowStatusStyles });
287
+ }, [storeState, mergedRowStatusStyles]);
251
288
  const realizedColumns = useMemo(() => {
252
289
  return columnSpec.map((col, colIndex) => {
253
290
  let fn = col.headerCellRenderer ?? columnHeaderCellRenderer ?? renderColumnHeaderCell;
@@ -300,15 +337,36 @@ function _DataSheet({
300
337
  const rowHeaderCellRenderer = useCallback(
301
338
  (rowIndex) => {
302
339
  const dataRowIndex = filteredRowIndices != null ? filteredRowIndices[rowIndex] ?? rowIndex : rowIndex;
303
- const style2 = rowStatus[dataRowIndex] == TableElementStatus.DELETED ? deletedRowHeaderStyle : null;
340
+ const statusVal = rowStatus[dataRowIndex];
341
+ const style2 = (statusVal != null ? mergedRowStatusStyles[statusVal]?.headerStyle : null) ?? null;
342
+ const defaultLabel = `${dataRowIndex + 1}`;
343
+ let name2 = defaultLabel;
344
+ if (rowHeaderRenderer != null) {
345
+ const custom = rowHeaderRenderer({
346
+ rowIndex: dataRowIndex,
347
+ visibleIndex: rowIndex,
348
+ row: data[dataRowIndex] ?? updatedData[dataRowIndex],
349
+ status: statusVal,
350
+ isDeleted: statusVal === TableElementStatus.DELETED,
351
+ defaultLabel
352
+ });
353
+ if (custom != null) name2 = custom;
354
+ }
304
355
  return h(RowHeaderCell, {
305
356
  enableRowReordering: false,
306
357
  index: rowIndex,
307
- name: `${dataRowIndex + 1}`,
358
+ name: name2,
308
359
  style: style2
309
360
  });
310
361
  },
311
- [rowStatus, filteredRowIndices]
362
+ [
363
+ rowStatus,
364
+ filteredRowIndices,
365
+ mergedRowStatusStyles,
366
+ rowHeaderRenderer,
367
+ data,
368
+ updatedData
369
+ ]
312
370
  );
313
371
  let _selectionModes = selectionModes;
314
372
  if (editable && _selectionModes != null && !_selectionModes.includes(RegionCardinality.CELLS)) {
@@ -383,6 +441,7 @@ function _DataSheet({
383
441
  ),
384
442
  h("div.status-bar", [
385
443
  filterStatus,
444
+ statusBar,
386
445
  h("div.spacer"),
387
446
  h.if(_showLoadProgress)(LoadProgressIndicator)
388
447
  ]),
package/dist/core.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"core.js","sources":["../src/core.ts"],"sourcesContent":["import { useHotkeys } from \"@blueprintjs/core\";\nimport {\n Column,\n Region,\n RegionCardinality,\n RowHeaderCell,\n Table,\n TableProps,\n} from \"@blueprintjs/table\";\nimport \"@blueprintjs/table/lib/css/table.css\";\nimport { ReactNode, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { LoadProgressIndicator } from \"./components\";\nimport { renderColumnHeaderCell } from \"./renderers\";\nimport h from \"./main.module.sass\";\nimport {\n columnSpecAtom,\n ctx,\n DataSheetProvider,\n storeAtom,\n tableActionsAtom,\n useSelector,\n useStoreAPI,\n} from \"./provider\";\nimport { atom } from \"jotai\";\nimport {\n DataSheetProviderProps,\n EditEvent,\n TableElementStatus,\n VisibleCells,\n} from \"./types.ts\";\nimport { basicCellRenderer } from \"./cell-renderer.ts\";\nimport { CellRendererDebugOverlay, tableHotkeysAtom } from \"./utils\";\nimport {\n ActionsToolbar,\n clipboardActions,\n columnControlActions,\n createSaveAction,\n FilterBar,\n resetChangesAction,\n TableAction,\n TableActionContext,\n TableFilter,\n} from \"./actions\";\nimport {\n createLocalProvider,\n dataRefreshTokenAtom,\n FetchData,\n FetchDataOptions,\n tableFooterAtom,\n TableDataProvider,\n useScrollHandler,\n useDataLoader,\n} from \"./postgrest-table\";\n\n// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args\n\n// TODO: add a \"copy to selection\" tool (the little square in the bottom right corner of a cell)\n// This should copy the value of a cell (or a set of cells in the same row) downwards.\n\nexport enum DataSheetDensity {\n HIGH = \"high\",\n MEDIUM = \"medium\",\n LOW = \"low\",\n}\n\n/** Approximate column-header + scrollbar allowance, used to size the table to\n * its content in paged mode. */\nconst COLUMN_HEADER_HEIGHT = 34;\n\n/**\n * How selecting a cell activates its surface (an editor, or a read-only detail\n * panel):\n * - `\"auto\"` (default when `autoFocusEditor` is `true`): open the surface on\n * selection and, for editors, focus it. Editors relinquish focus at their\n * edges — arrow past the start/end of a text cell, or press Escape, and focus\n * returns to the table — so the keyboard stays operable without the mouse.\n * Pressing Escape drops into navigation mode (surfaces stop auto-opening)\n * until the next click.\n * - `\"manual\"` (default when `autoFocusEditor` is `false`): the surface stays\n * closed until the cell is clicked; arrow keys always navigate the table.\n */\nexport type CellInteraction = \"auto\" | \"manual\";\n\ninterface DataSheetInternalProps<T> extends TableProps, FetchDataOptions {\n /** In-memory rows. Internally wrapped in a local `TableDataProvider` and\n * driven through the same loader as any other source. */\n data?: T[];\n // function to fetch a chunk of data (the read side of a data provider)\n fetchData?: FetchData<T>;\n /** A data provider instantiated separately and passed in — bundles the read\n * side (`fetchData` + `identity`) and, optionally, the persistence side\n * (`saveRows` / `deleteRows` / `insertRow`) that drives the Save action. An\n * explicit alternative to the loose `data` / `fetchData` / `identity` props;\n * takes precedence when given. */\n provider?: TableDataProvider<T>;\n // An optional table name that will be used in toolbars if given\n name?: string;\n onVisibleCellsChange?: (visibleCells: VisibleCells) => void;\n onUpdateData?: (updatedData: any[], data: T[]) => void;\n /** Observer called for every user edit as a structured `EditEvent`\n * (Workstream A). Additive: the built-in `updatedData` overlay still\n * applies. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Controlled edited-cell overlay (Workstream A). When provided, it is\n * synced into the store as the source of truth for edited values — pair with\n * `onEdit` to own edit state externally (e.g. an ops model). Optimistic\n * in-table edits are superseded by the next value you pass back. */\n updatedData?: T[];\n /** Controlled row-status overlay (edited / added / deleted), the companion\n * to `updatedData`. */\n rowStatus?: TableElementStatus[];\n /** Row identity for the edit overlay — stable across a provider re-sort (a\n * data provider supplies its own; defaults to `(row) => row?.id`). Lets edits\n * survive a re-ordered re-fetch. */\n identity?: (row: T) => string | number | null | undefined;\n /** Persistence handler for the built-in Save action. When provided, a Save\n * control is added to the toolbar (always visible, disabled when there are\n * no pending changes). */\n onSave?: (ctx: TableActionContext<T>) => void | Promise<void>;\n onDeleteRows?: (selection: Region[]) => void;\n verbose?: boolean;\n enableColumnReordering?: boolean;\n enableClipboard?: boolean;\n enableFocusedCell?: boolean;\n editable?: boolean;\n /** @deprecated Prefer `cellInteraction`. `true` maps to `\"auto\"`,\n * `false` to `\"manual\"`. */\n autoFocusEditor?: boolean;\n /** How selecting a cell activates its surface (editor or detail panel).\n * Defaults from `autoFocusEditor` for backward compatibility. */\n cellInteraction?: CellInteraction;\n density?: DataSheetDensity;\n /** Configurable table actions shown in a selection-aware toolbar.\n * When provided, the actions toolbar renders alongside the existing\n * edit toolbar. Actions are filtered by the current selection cardinality. */\n actions?: TableAction<T>[];\n /** Available column/table filters shown in a filter bar.\n * Filters can also be defined per-column via `ColumnSpec.filters`. */\n filters?: TableFilter<T>[];\n /** Optional custom column header cell renderer, called for each column.\n * Receives the ColumnSpec and column index; should return a React element\n * (typically a Blueprint ColumnHeaderCell). */\n columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;\n}\n\ntype DataSheetProps<T> = DataSheetProviderProps<T> & DataSheetInternalProps<T>;\n\nconst emptyData: any[] = [];\n\nexport function DataSheet<T>(props: DataSheetProps<T>) {\n const {\n data,\n columnSpec,\n columnSpecOptions,\n editable = true,\n enableColumnReordering = false,\n enableFocusedCell = false,\n defaultColumnWidth = 150,\n children,\n ...rest\n } = props;\n\n return h(\n DataSheetProvider<T>,\n {\n data: data ?? emptyData,\n columnSpec,\n columnSpecOptions,\n enableColumnReordering,\n defaultColumnWidth,\n editable,\n ...rest,\n },\n h(_DataSheet<any>, {\n ...rest,\n data: data ?? emptyData,\n children,\n editable,\n enableColumnReordering,\n enableFocusedCell,\n }),\n );\n}\n\nconst deletedRowHeaderStyle = {\n opacity: 0.5,\n textDecoration: \"line-through\",\n};\n\n/** Persist all pending changes through a data provider: added rows via\n * `insertRow`, edited rows via `saveRows`, deleted rows via `deleteRows`\n * (addressed by `provider.identity`). Used by the built-in Save action when an\n * explicit provider owns persistence. */\nasync function persistViaProvider<T>(\n provider: TableDataProvider<T>,\n ctx: TableActionContext<T>,\n): Promise<void> {\n const base = (ctx.data ?? []) as any[];\n const updates = (ctx.updatedData ?? []) as any[];\n const status = (ctx.rowStatus ?? []) as any[];\n const n = Math.max(base.length, updates.length, status.length);\n const toSave: T[] = [];\n const toInsert: T[] = [];\n const toDelete: Array<string | number> = [];\n for (let i = 0; i < n; i++) {\n if (status[i] === TableElementStatus.DELETED) {\n const id = provider.identity(base[i]);\n if (id != null) toDelete.push(id);\n continue;\n }\n const upd = updates[i];\n const hasEdit =\n upd != null && typeof upd === \"object\" && Object.keys(upd).length > 0;\n if (status[i] === TableElementStatus.ADDED) {\n toInsert.push({ ...base[i], ...upd } as T);\n } else if (hasEdit) {\n toSave.push({ ...base[i], ...upd } as T);\n }\n }\n if (toDelete.length > 0 && provider.deleteRows != null) {\n await provider.deleteRows(toDelete);\n }\n for (const row of toInsert) {\n if (provider.insertRow != null) await provider.insertRow(row);\n }\n if (toSave.length > 0 && provider.saveRows != null) {\n await provider.saveRows(toSave);\n }\n}\n\nfunction _DataSheet<T>({\n data: sourceData,\n fetchData,\n provider,\n pageSize,\n fetchMode,\n onVisibleCellsChange,\n onUpdateData,\n onEdit,\n onSave,\n updatedData: updatedDataProp,\n rowStatus: rowStatusProp,\n identity,\n onDeleteRows,\n name,\n verbose = false,\n enableFocusedCell,\n autoFocusEditor = true,\n cellInteraction,\n enableClipboard = true,\n density = DataSheetDensity.HIGH,\n selectionModes,\n actions,\n filters,\n columnHeaderCellRenderer,\n children,\n ...rest\n}: DataSheetInternalProps<T>) {\n /**\n * @param data: The data to be displayed in the table\n * @param columnSpec: The specification for all columns in the table. If not provided, the column spec will be generated from the data.\n * @param columnSpecOptions: Options for generating a column spec from data\n */\n\n // Turn on debug features\n const debugMode = false;\n\n const editable = useSelector((state) => state.editable);\n\n // Resolve the active data provider: an explicit `provider` prop wins; else a\n // loose `fetchData` (+ identity) is wrapped as one; else in-memory `data`\n // becomes a local provider. Local and remote thus share one path, and the\n // provider is an explicit contract rather than a set of scattered props.\n const isLocalProvider = provider == null && fetchData == null;\n const activeProvider = useMemo<TableDataProvider<any> | null>(() => {\n if (provider != null) return provider;\n if (fetchData != null) {\n return { fetchData, identity: identity ?? ((r: any) => r?.id) };\n }\n if (sourceData != null && sourceData.length > 0) {\n return createLocalProvider(\n sourceData,\n identity != null ? { identity } : undefined,\n );\n }\n return null;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [provider, fetchData, sourceData, identity]);\n\n // When an explicit provider owns persistence, its methods drive the built-in\n // Save (batch: edits→saveRows, added→insertRow, deleted→deleteRows), then a\n // refresh. Otherwise the loose `onSave` handler is used.\n const bumpRefresh = ctx.useSet(dataRefreshTokenAtom);\n const providerSave = useMemo(() => {\n const p = provider;\n if (\n p == null ||\n (p.saveRows == null && p.deleteRows == null && p.insertRow == null)\n ) {\n return null;\n }\n return async (actionCtx: TableActionContext<T>) => {\n await persistViaProvider(p, actionCtx);\n bumpRefresh((v) => v + 1);\n };\n }, [provider, bumpRefresh]);\n const saveHandler = onSave ?? providerSave;\n\n // Sync table actions to atom. Consumer actions come first (they override a\n // built-in by reusing its id); the built-in column controls (sort/filter)\n // fill in the rest — so both the toolbar and the header dropdown source from\n // one registry. Built-ins self-gate (single sortable/filterable column).\n const _actions: TableAction[] = useMemo(() => {\n const _actions: TableAction[] = [];\n const add = (list: TableAction[]) => {\n for (const a of list) {\n if (!_actions.some((x) => x.id === a.id)) _actions.push(a);\n }\n };\n if (actions != null) add(actions);\n add(columnControlActions);\n if (enableClipboard) add(clipboardActions);\n // Save/reset last — they're the most significant actions — and present for\n // every cardinality (editable), so the toolbar stays mounted regardless of\n // selection.\n if (editable) {\n if (saveHandler != null) add([createSaveAction(saveHandler)]);\n add([resetChangesAction]);\n }\n return _actions;\n }, [actions, enableClipboard, editable, saveHandler]);\n\n ctx.useSync(tableActionsAtom, _actions);\n\n const hotkeysConfig = ctx.useValue(tableHotkeysAtom);\n const { handleKeyDown, handleKeyUp } = useHotkeys(hotkeysConfig);\n\n // For now, we only consider a single cell \"focused\" when we have one cell selected.\n // Multi-cell selections have a different set of \"bulk\" actions.\n const selectedRegions = useSelector<T>((state) => state.selection ?? []);\n\n const data = useSelector((state) => state.data);\n\n const rowStatus = useSelector((state) => state.rowStatus);\n\n const focusedCell = useSelector((state) => state.focusedCell);\n\n const ref = useSelector((state) => state.tableRef);\n\n const columnSpec = useSelector((state) => state.columnSpec);\n\n // A sparse array to hold updates\n // TODO: create a \"changeset\" concept to facilitate undo/redo\n const updatedData = useSelector((state) => state.updatedData);\n\n const onSelection = useSelector((state) => state.onSelection);\n\n const storeAPI = useStoreAPI<T>();\n\n const onScroll = useScrollHandler();\n const _onVisibleCellsChange = useCallback(\n (visibleCells: VisibleCells) => {\n onScroll(visibleCells);\n onVisibleCellsChange?.(visibleCells);\n },\n [onVisibleCellsChange, onScroll],\n );\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Updated data\", updatedData);\n }, [updatedData]);\n\n useEffect(() => {\n onUpdateData?.(updatedData, data);\n }, [onUpdateData, data, updatedData]);\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Selected regions\", selectedRegions);\n }, [selectedRegions]);\n\n const tableElementRef = useRef<HTMLElement>(null);\n useEffect(() => {\n // Return the focus to the table\n tableElementRef.current?.focus();\n }, [focusedCell]);\n\n const columnWidths = ctx.useValue(columnWidthsAtom);\n\n // When filters are active, only show matching rows\n const filteredRowIndices = useSelector((state) => state.filteredRowIndices);\n const totalRows = Math.max(updatedData.length, data.length);\n const numRows =\n filteredRowIndices != null ? filteredRowIndices.length : totalRows;\n\n let className = `${density}-density`;\n\n const { rowHeight, style } = styleParamsForDensity(density);\n\n // In paged mode the row count is small and fixed, so let the table size to\n // its content (header + rows) instead of filling the viewport.\n const footerInfo = ctx.useValue(tableFooterAtom);\n const holderStyle =\n footerInfo.mode === \"paged\"\n ? {\n flex: \"0 0 auto\" as const,\n height: numRows * rowHeight + COLUMN_HEADER_HEIGHT,\n }\n : undefined;\n\n const onColumnsReordered = useSelector((state) => state.onColumnsReordered);\n\n // Auto-detect if any columns have sortable/filterable set.\n // If so and no explicit columnHeaderCellRenderer was provided,\n // use the built-in client-side sort/filter header.\n const hasSortableOrFilterable = useMemo(\n () =>\n columnSpec.some(\n (col) =>\n col.sortable ||\n col.filterable ||\n (Array.isArray(col.filters) && col.filters.length > 0),\n ),\n [columnSpec],\n );\n\n const columnSorts = useSelector((state) => state.columnSorts);\n const activeFilters = useSelector((state) => state.activeFilters);\n\n // Cell activation mode, defaulting from the legacy `autoFocusEditor` boolean\n // so existing consumers are unaffected. Synced into the store so the cell\n // renderer, editors, and key handlers all read it consistently.\n const cellInteractionMode: CellInteraction =\n cellInteraction ?? (autoFocusEditor ? \"auto\" : \"manual\");\n\n const storeState = storeAPI;\n useEffect(() => {\n storeState.setState({ cellInteraction: cellInteractionMode });\n }, [storeState, cellInteractionMode]);\n\n useEffect(() => {\n // Give the store a handle to the focusable holder so editors can return\n // keyboard focus to the table when the cursor leaves them.\n storeState.setState({ tableElement: tableElementRef.current });\n }, [storeState]);\n\n useEffect(() => {\n storeState.setState({ onEdit });\n }, [storeState, onEdit]);\n\n useEffect(() => {\n // Controlled overlay: mirror the caller's edited state into the store as\n // the source of truth. Optimistic in-table edits are superseded on the\n // next render when the caller passes an updated value back. When the caller\n // controls it, the loader-boundary identity remap steps aside.\n const controlled =\n updatedDataProp !== undefined || rowStatusProp !== undefined;\n const patch: Record<string, unknown> = { controlledOverlay: controlled };\n if (updatedDataProp !== undefined) patch.updatedData = updatedDataProp;\n if (rowStatusProp !== undefined) patch.rowStatus = rowStatusProp;\n storeState.setState(patch);\n }, [storeState, updatedDataProp, rowStatusProp]);\n\n // The active provider supplies the row identity for the edit overlay.\n useEffect(() => {\n const id = activeProvider?.identity ?? identity;\n if (id != null) storeState.setState({ identity: id });\n }, [storeState, activeProvider, identity]);\n\n // Row deletion is a provider capability: an explicit `provider` without\n // `deleteRows` disables deletion entirely. (Local / loose sources keep the\n // local delete overlay.)\n useEffect(() => {\n const canDeleteRows = provider == null || provider.deleteRows != null;\n storeState.setState({ canDeleteRows });\n }, [storeState, provider]);\n\n const realizedColumns = useMemo(() => {\n return columnSpec.map((col, colIndex) => {\n let fn =\n col.headerCellRenderer ??\n columnHeaderCellRenderer ??\n renderColumnHeaderCell;\n let activeSort = null;\n let activeFilter = null;\n if (col.sortable) {\n activeSort = columnSorts?.find((s) => s.key === col.key);\n }\n // The active filter for this column is whichever active filter targets\n // it (a rich `col.filters` filter or the generic operator filter) — match\n // by columnKey rather than a fixed id.\n for (const entry of activeFilters?.values() ?? []) {\n if ((entry as any)?.filter?.columnKey === col.key) {\n activeFilter = entry;\n break;\n }\n }\n\n const _columnHeaderCellRenderer = (colIndex) => {\n return fn({\n col,\n colIndex,\n activeSort,\n activeFilter,\n });\n };\n\n return h(Column, {\n id: col.key,\n name: col.name,\n columnHeaderCellRenderer: _columnHeaderCellRenderer,\n cellRenderer: (rowIndex) => {\n const state = storeAPI.getState();\n return basicCellRenderer<T>(\n rowIndex,\n colIndex,\n col,\n state,\n filteredRowIndices,\n );\n },\n });\n });\n }, [\n columnSpec,\n columnSorts,\n activeFilters,\n storeAPI,\n filteredRowIndices,\n columnHeaderCellRenderer,\n ]);\n\n const onColumnWidthChanged = useSelector(\n (state) => state.onColumnWidthChanged,\n );\n\n const rowHeaderCellRenderer = useCallback(\n (rowIndex: number) => {\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n const style =\n rowStatus[dataRowIndex] == TableElementStatus.DELETED\n ? deletedRowHeaderStyle\n : null;\n\n return h(RowHeaderCell, {\n enableRowReordering: false,\n index: rowIndex,\n name: `${dataRowIndex + 1}`,\n style,\n });\n },\n [rowStatus, filteredRowIndices],\n );\n\n let _selectionModes = selectionModes;\n if (\n editable &&\n _selectionModes != null &&\n !_selectionModes.includes(RegionCardinality.CELLS)\n ) {\n _selectionModes = [..._selectionModes, RegionCardinality.CELLS];\n // Ensure selection mode includes \"cells\"\n }\n\n const cellRendererDependencies = [\n data,\n updatedData,\n focusedCell,\n rowStatus,\n filteredRowIndices,\n ];\n\n // Drive the table from the active provider's `fetchData`. A local (in-memory)\n // provider loads the whole array at once; a remote one uses the `pageSize` /\n // `fetchMode` props and shows load progress.\n let _showLoadProgress: boolean = false;\n let dataLoader: ReactNode = null;\n if (activeProvider != null) {\n _showLoadProgress = !isLocalProvider;\n dataLoader = h(_DataLoaderManager, {\n key: \"__data_loader\",\n fetchData: activeProvider.fetchData,\n pageSize: isLocalProvider\n ? Math.max(sourceData?.length ?? 1, 1)\n : pageSize,\n fetchMode: isLocalProvider ? undefined : fetchMode,\n });\n }\n const showFilterBar =\n (filters != null && filters.length > 0) || hasSortableOrFilterable;\n\n let filterStatus: ReactNode = null;\n if (showFilterBar) {\n filterStatus = h(FilterBar, { filters: filters ?? [] });\n }\n\n return h(\"div.data-sheet-container\", { className, style }, [\n // The actions/tools toolbar (selection-modal). Table-scoped controls like\n // scroll-to-row / full-text search live here as ordinary actions.\n h(ActionsToolbar, { actions: _actions, tableName: name }),\n dataLoader,\n children,\n h(\n \"div.data-sheet-holder\",\n {\n tabIndex: 0,\n onKeyDown: handleKeyDown,\n onKeyUp: handleKeyUp,\n ref: tableElementRef,\n style: holderStyle,\n },\n h(\n Table,\n {\n ref,\n numRows,\n className: \"data-sheet\",\n enableFocusedCell,\n onColumnsReordered,\n focusedCell,\n selectedRegions,\n defaultRowHeight: rowHeight,\n minRowHeight: rowHeight,\n columnWidths,\n onColumnWidthChanged,\n onSelection,\n /** TODO: we could enable this, but we need a use-case first... */\n enableRowReordering: false,\n enableRowResizing: false,\n // The cell renderer is memoized internally based on these data dependencies\n cellRendererDependencies,\n onVisibleCellsChange: _onVisibleCellsChange,\n rowHeaderCellRenderer,\n selectionModes: _selectionModes,\n ...rest,\n getCellClipboardData: null,\n },\n realizedColumns,\n ),\n ),\n h(\"div.status-bar\", [\n filterStatus,\n h(\"div.spacer\"),\n h.if(_showLoadProgress)(LoadProgressIndicator),\n ]),\n h.if(debugMode)(CellRendererDebugOverlay, {\n cellRendererDependencies,\n names: [\n \"data\",\n \"updatedData\",\n \"focusedCell\",\n \"rowStatus\",\n \"filteredRowIndices\",\n ],\n }),\n ]);\n}\n\nconst columnWidthsIndexAtom = atom((get) => get(storeAtom).columnWidthsIndex);\nconst defaultColumnWidthAtom = atom((get) => get(storeAtom).defaultColumnWidth);\n\nconst columnWidthsAtom = atom((get) => {\n const ix = get(columnWidthsIndexAtom);\n return get(columnSpecAtom).map(\n (col) => ix.get(col.key) ?? col.width ?? get(defaultColumnWidthAtom),\n );\n});\n\nfunction styleParamsForDensity(density: DataSheetDensity) {\n switch (density) {\n case DataSheetDensity.MEDIUM:\n return {\n rowHeight: 24,\n style: {\n \"--data-sheet-row-height\": \"24px\",\n \"--data-sheet-font-size\": \"14px\",\n },\n };\n case DataSheetDensity.LOW:\n return {\n rowHeight: 30,\n style: {\n \"--data-sheet-row-height\": \"30px\",\n \"--data-sheet-font-size\": \"18px\",\n },\n };\n case DataSheetDensity.HIGH:\n default:\n return {\n rowHeight: 20,\n style: {\n \"--data-sheet-row-height\": \"20px\",\n \"--data-sheet-font-size\": \"12px\",\n },\n };\n }\n}\n\n/** Convenience component: runs `useChunkLoader` from inside a `DataSheet`.\n * Render as a child of `DataSheet` (it renders nothing itself). */\nfunction _DataLoaderManager<T = any>({\n fetchData,\n ...rest\n}: {\n fetchData: FetchData<T>;\n} & FetchDataOptions) {\n useDataLoader(fetchData, rest);\n return null;\n}\n\nexport function getRowsToDelete(selection) {\n let rowIndices: number[] = [];\n for (const sel of selection) {\n // This isn't a full-row selection\n if (sel.cols != null) continue;\n if (sel.rows == null) continue;\n const [startIndex, endIndex] = sel.rows;\n for (let i = startIndex; i <= endIndex; i++) {\n rowIndices.push(i);\n }\n }\n return rowIndices;\n}\n"],"names":["DataSheetDensity","ctx","_actions","colIndex","style"],"mappings":";;;;;;;;;;;;;;;;;;;;AA2DO,IAAK,qCAAAA,sBAAL;AACLA,oBAAA,MAAA,IAAO;AACPA,oBAAA,QAAA,IAAS;AACTA,oBAAA,KAAA,IAAM;AAHI,SAAAA;AAAA,GAAA,oBAAA,CAAA,CAAA;AAQZ,MAAM,uBAAuB;AAgF7B,MAAM,YAAmB,CAAA;A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UAC3B,0BAA0B;AAAA,QAAA;AAAA,MAC5B;AAAA,EACF;AAEN;AAIA,SAAS,mBAA4B;AAAA,EACnC;AAAA,EACA,GAAG;AACL,GAEsB;AACpB,gBAAc,WAAW,IAAI;AAC7B,SAAO;AACT;AAEO,SAAS,gBAAgB,WAAW;AACzC,MAAI,aAAuB,CAAA;AAC3B,aAAW,OAAO,WAAW;AAE3B,QAAI,IAAI,QAAQ,KAAM;AACtB,QAAI,IAAI,QAAQ,KAAM;AACtB,UAAM,CAAC,YAAY,QAAQ,IAAI,IAAI;AACnC,aAAS,IAAI,YAAY,KAAK,UAAU,KAAK;AAC3C,iBAAW,KAAK,CAAC;AAAA,IACnB;AAAA,EACF;AACA,SAAO;AACT;"}
1
+ {"version":3,"file":"core.js","sources":["../src/core.ts"],"sourcesContent":["import { useHotkeys } from \"@blueprintjs/core\";\nimport {\n Column,\n Region,\n RegionCardinality,\n RowHeaderCell,\n Table,\n TableProps,\n} from \"@blueprintjs/table\";\nimport \"@blueprintjs/table/lib/css/table.css\";\nimport { ReactNode, useCallback, useEffect, useMemo, useRef } from \"react\";\nimport { LoadProgressIndicator } from \"./components\";\nimport { renderColumnHeaderCell } from \"./renderers\";\nimport h from \"./main.module.sass\";\nimport {\n columnSpecAtom,\n ctx,\n DataSheetProvider,\n storeAtom,\n tableActionsAtom,\n useSelector,\n useStoreAPI,\n} from \"./provider\";\nimport { atom } from \"jotai\";\nimport {\n DataSheetProviderProps,\n DEFAULT_ROW_STATUS_STYLES,\n EditEvent,\n RowHeaderRenderContext,\n RowStatusStyles,\n TableElementStatus,\n VisibleCells,\n} from \"./types.ts\";\nimport { basicCellRenderer } from \"./cell-renderer.ts\";\nimport {\n CellRendererDebugOverlay,\n tableHotkeysAtom,\n type ColumnSpec,\n} from \"./utils\";\nimport {\n ActionsToolbar,\n clipboardActions,\n columnControlActions,\n createSaveAction,\n FilterBar,\n resetChangesAction,\n TableAction,\n TableActionContext,\n TableFilter,\n} from \"./actions\";\nimport {\n createLocalProvider,\n dataRefreshTokenAtom,\n FetchData,\n FetchDataOptions,\n tableFooterAtom,\n TableDataProvider,\n useScrollHandler,\n useDataLoader,\n} from \"./postgrest-table\";\n\n// More on component templates: https://storybook.js.org/docs/react/writing-stories/introduction#using-args\n\n// TODO: add a \"copy to selection\" tool (the little square in the bottom right corner of a cell)\n// This should copy the value of a cell (or a set of cells in the same row) downwards.\n\nexport enum DataSheetDensity {\n HIGH = \"high\",\n MEDIUM = \"medium\",\n LOW = \"low\",\n}\n\n/** Approximate column-header + scrollbar allowance, used to size the table to\n * its content in paged mode. */\nconst COLUMN_HEADER_HEIGHT = 34;\n\n/**\n * How selecting a cell activates its surface (an editor, or a read-only detail\n * panel):\n * - `\"auto\"` (default when `autoFocusEditor` is `true`): open the surface on\n * selection and, for editors, focus it. Editors relinquish focus at their\n * edges — arrow past the start/end of a text cell, or press Escape, and focus\n * returns to the table — so the keyboard stays operable without the mouse.\n * Pressing Escape drops into navigation mode (surfaces stop auto-opening)\n * until the next click.\n * - `\"manual\"` (default when `autoFocusEditor` is `false`): the surface stays\n * closed until the cell is clicked; arrow keys always navigate the table.\n */\nexport type CellInteraction = \"auto\" | \"manual\";\n\ninterface DataSheetInternalProps<T> extends TableProps, FetchDataOptions {\n /** In-memory rows. Internally wrapped in a local `TableDataProvider` and\n * driven through the same loader as any other source. */\n data?: T[];\n /** Passed through from the public props so a function form can be derived\n * from the loaded rows here (a static array is handled by the provider). */\n columnSpec?: ColumnSpec[] | ((rows: T[]) => ColumnSpec[]);\n // function to fetch a chunk of data (the read side of a data provider)\n fetchData?: FetchData<T>;\n /** A data provider instantiated separately and passed in — bundles the read\n * side (`fetchData` + `identity`) and, optionally, the persistence side\n * (`saveRows` / `deleteRows` / `insertRow`) that drives the Save action. An\n * explicit alternative to the loose `data` / `fetchData` / `identity` props;\n * takes precedence when given. */\n provider?: TableDataProvider<T>;\n // An optional table name that will be used in toolbars if given\n name?: string;\n onVisibleCellsChange?: (visibleCells: VisibleCells) => void;\n onUpdateData?: (updatedData: any[], data: T[]) => void;\n /** Observer called for every user edit as a structured `EditEvent`\n * (Workstream A). Additive: the built-in `updatedData` overlay still\n * applies. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Controlled edited-cell overlay (Workstream A). When provided, it is\n * synced into the store as the source of truth for edited values — pair with\n * `onEdit` to own edit state externally (e.g. an ops model). Optimistic\n * in-table edits are superseded by the next value you pass back. */\n updatedData?: T[];\n /** Controlled row-status overlay (edited / added / deleted), the companion\n * to `updatedData`. */\n rowStatus?: TableElementStatus[];\n /** Row identity for the edit overlay — stable across a provider re-sort (a\n * data provider supplies its own; defaults to `(row) => row?.id`). Lets edits\n * survive a re-ordered re-fetch. */\n identity?: (row: T) => string | number | null | undefined;\n /** Derive the controlled edit overlay from the loaded rows, *inside* the\n * sheet. For provider-backed tables whose overlay is a function of the loaded\n * data plus external edit state (e.g. an ops stack): the library owns the\n * rows, so it calls this with them and uses the result as the controlled\n * overlay, re-deriving when the rows — or this function's identity (close it\n * over your edit state) — change. Supersedes `updatedData`/`rowStatus`. */\n deriveOverlay?: (rows: T[]) => {\n updatedData: T[];\n rowStatus: TableElementStatus[];\n };\n /** Bump to force the data provider to re-fetch from scratch (e.g. after a\n * save/delete that invalidated the loaded rows). */\n refreshToken?: number | string;\n /** Persistence handler for the built-in Save action. When provided, a Save\n * control is added to the toolbar (always visible, disabled when there are\n * no pending changes). */\n onSave?: (ctx: TableActionContext<T>) => void | Promise<void>;\n onDeleteRows?: (selection: Region[]) => void;\n verbose?: boolean;\n enableColumnReordering?: boolean;\n enableClipboard?: boolean;\n enableFocusedCell?: boolean;\n editable?: boolean;\n /** @deprecated Prefer `cellInteraction`. `true` maps to `\"auto\"`,\n * `false` to `\"manual\"`. */\n autoFocusEditor?: boolean;\n /** How selecting a cell activates its surface (editor or detail panel).\n * Defaults from `autoFocusEditor` for backward compatibility. */\n cellInteraction?: CellInteraction;\n density?: DataSheetDensity;\n /** Configurable table actions shown in a selection-aware toolbar.\n * When provided, the actions toolbar renders alongside the existing\n * edit toolbar. Actions are filtered by the current selection cardinality. */\n actions?: TableAction<T>[];\n /** Available column/table filters shown in a filter bar.\n * Filters can also be defined per-column via `ColumnSpec.filters`. */\n filters?: TableFilter<T>[];\n /** Optional custom column header cell renderer, called for each column.\n * Receives the ColumnSpec and column index; should return a React element\n * (typically a Blueprint ColumnHeaderCell). */\n columnHeaderCellRenderer?: (col: any, colIndex: number) => ReactNode;\n /** Arbitrary nodes for the bottom status bar (left group), rendered beside\n * the active sort/filter tags — the home for view-state controls (show/hide\n * omitted rows/columns, a group-by indicator, etc.). */\n statusBar?: ReactNode;\n /** Presentation per row-status value, merged over the built-in defaults\n * (which style `\"deleted\"`). Supply styles for consumer-defined statuses\n * (e.g. `\"omitted\"`) and/or override the defaults. Each entry may set the\n * cells' style/intent and the row header's style. */\n rowStatusStyles?: RowStatusStyles;\n /** Render the content of a row's header cell (the left gutter). Receives the\n * row, its status, and the default 1-based label; return a node to use, or a\n * nullish value to keep the default. For group-key labels, omit indicators,\n * etc. Header-cell *styling* still comes from `rowStatusStyles`. */\n rowHeaderRenderer?: (ctx: RowHeaderRenderContext<T>) => ReactNode;\n}\n\ntype DataSheetProps<T> = DataSheetProviderProps<T> & DataSheetInternalProps<T>;\n\nconst emptyData: any[] = [];\n\nexport function DataSheet<T>(props: DataSheetProps<T>) {\n const {\n data,\n columnSpec,\n columnSpecOptions,\n editable = true,\n enableColumnReordering = false,\n enableFocusedCell = false,\n defaultColumnWidth = 150,\n children,\n ...rest\n } = props;\n\n return h(\n DataSheetProvider<T>,\n {\n data: data ?? emptyData,\n columnSpec,\n columnSpecOptions,\n enableColumnReordering,\n defaultColumnWidth,\n editable,\n ...rest,\n },\n h(_DataSheet<any>, {\n ...rest,\n data: data ?? emptyData,\n columnSpec,\n children,\n editable,\n enableColumnReordering,\n enableFocusedCell,\n }),\n );\n}\n\n/** Persist all pending changes through a data provider: added rows via\n * `insertRow`, edited rows via `saveRows`, deleted rows via `deleteRows`\n * (addressed by `provider.identity`). Used by the built-in Save action when an\n * explicit provider owns persistence. */\nasync function persistViaProvider<T>(\n provider: TableDataProvider<T>,\n ctx: TableActionContext<T>,\n): Promise<void> {\n const base = (ctx.data ?? []) as any[];\n const updates = (ctx.updatedData ?? []) as any[];\n const status = (ctx.rowStatus ?? []) as any[];\n const n = Math.max(base.length, updates.length, status.length);\n const toSave: T[] = [];\n const toInsert: T[] = [];\n const toDelete: Array<string | number> = [];\n for (let i = 0; i < n; i++) {\n if (status[i] === TableElementStatus.DELETED) {\n const id = provider.identity(base[i]);\n if (id != null) toDelete.push(id);\n continue;\n }\n const upd = updates[i];\n const hasEdit =\n upd != null && typeof upd === \"object\" && Object.keys(upd).length > 0;\n if (status[i] === TableElementStatus.ADDED) {\n toInsert.push({ ...base[i], ...upd } as T);\n } else if (hasEdit) {\n toSave.push({ ...base[i], ...upd } as T);\n }\n }\n if (toDelete.length > 0 && provider.deleteRows != null) {\n await provider.deleteRows(toDelete);\n }\n for (const row of toInsert) {\n if (provider.insertRow != null) await provider.insertRow(row);\n }\n if (toSave.length > 0 && provider.saveRows != null) {\n await provider.saveRows(toSave);\n }\n}\n\nfunction _DataSheet<T>({\n data: sourceData,\n fetchData,\n provider,\n pageSize,\n fetchMode,\n onVisibleCellsChange,\n onUpdateData,\n onEdit,\n onSave,\n updatedData: updatedDataProp,\n rowStatus: rowStatusProp,\n identity,\n deriveOverlay,\n refreshToken,\n onDeleteRows,\n name,\n verbose = false,\n enableFocusedCell,\n autoFocusEditor = true,\n cellInteraction,\n enableClipboard = true,\n density = DataSheetDensity.HIGH,\n selectionModes,\n actions,\n filters,\n columnHeaderCellRenderer,\n columnSpec: columnSpecProp,\n statusBar,\n rowStatusStyles,\n rowHeaderRenderer,\n children,\n ...rest\n}: DataSheetInternalProps<T>) {\n /**\n * @param data: The data to be displayed in the table\n * @param columnSpec: The specification for all columns in the table. If not provided, the column spec will be generated from the data.\n * @param columnSpecOptions: Options for generating a column spec from data\n */\n\n // Turn on debug features\n const debugMode = false;\n\n const editable = useSelector((state) => state.editable);\n\n // Resolve the active data provider: an explicit `provider` prop wins; else a\n // loose `fetchData` (+ identity) is wrapped as one; else in-memory `data`\n // becomes a local provider. Local and remote thus share one path, and the\n // provider is an explicit contract rather than a set of scattered props.\n const isLocalProvider = provider == null && fetchData == null;\n const activeProvider = useMemo<TableDataProvider<any> | null>(() => {\n if (provider != null) return provider;\n if (fetchData != null) {\n return { fetchData, identity: identity ?? ((r: any) => r?.id) };\n }\n if (sourceData != null && sourceData.length > 0) {\n return createLocalProvider(\n sourceData,\n identity != null ? { identity } : undefined,\n );\n }\n return null;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [provider, fetchData, sourceData, identity]);\n\n // When an explicit provider owns persistence, its methods drive the built-in\n // Save (batch: edits→saveRows, added→insertRow, deleted→deleteRows), then a\n // refresh. Otherwise the loose `onSave` handler is used.\n const bumpRefresh = ctx.useSet(dataRefreshTokenAtom);\n const providerSave = useMemo(() => {\n const p = provider;\n if (\n p == null ||\n (p.saveRows == null && p.deleteRows == null && p.insertRow == null)\n ) {\n return null;\n }\n return async (actionCtx: TableActionContext<T>) => {\n await persistViaProvider(p, actionCtx);\n bumpRefresh((v) => v + 1);\n };\n }, [provider, bumpRefresh]);\n const saveHandler = onSave ?? providerSave;\n\n // Sync table actions to atom. Consumer actions come first (they override a\n // built-in by reusing its id); the built-in column controls (sort/filter)\n // fill in the rest — so both the toolbar and the header dropdown source from\n // one registry. Built-ins self-gate (single sortable/filterable column).\n const _actions: TableAction[] = useMemo(() => {\n const _actions: TableAction[] = [];\n const add = (list: TableAction[]) => {\n for (const a of list) {\n if (!_actions.some((x) => x.id === a.id)) _actions.push(a);\n }\n };\n if (actions != null) add(actions);\n add(columnControlActions);\n if (enableClipboard) add(clipboardActions);\n // Save/reset last — they're the most significant actions — and present for\n // every cardinality (editable), so the toolbar stays mounted regardless of\n // selection.\n if (editable) {\n if (saveHandler != null) add([createSaveAction(saveHandler)]);\n add([resetChangesAction]);\n }\n return _actions;\n }, [actions, enableClipboard, editable, saveHandler]);\n\n ctx.useSync(tableActionsAtom, _actions);\n\n const hotkeysConfig = ctx.useValue(tableHotkeysAtom);\n const { handleKeyDown, handleKeyUp } = useHotkeys(hotkeysConfig);\n\n // For now, we only consider a single cell \"focused\" when we have one cell selected.\n // Multi-cell selections have a different set of \"bulk\" actions.\n const selectedRegions = useSelector<T>((state) => state.selection ?? []);\n\n const data = useSelector((state) => state.data);\n\n const rowStatus = useSelector((state) => state.rowStatus);\n\n const focusedCell = useSelector((state) => state.focusedCell);\n\n const ref = useSelector((state) => state.tableRef);\n\n const columnSpec = useSelector((state) => state.columnSpec);\n\n // A sparse array to hold updates\n // TODO: create a \"changeset\" concept to facilitate undo/redo\n const updatedData = useSelector((state) => state.updatedData);\n\n const onSelection = useSelector((state) => state.onSelection);\n\n const storeAPI = useStoreAPI<T>();\n\n const onScroll = useScrollHandler();\n const _onVisibleCellsChange = useCallback(\n (visibleCells: VisibleCells) => {\n onScroll(visibleCells);\n onVisibleCellsChange?.(visibleCells);\n },\n [onVisibleCellsChange, onScroll],\n );\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Updated data\", updatedData);\n }, [updatedData]);\n\n useEffect(() => {\n onUpdateData?.(updatedData, data);\n }, [onUpdateData, data, updatedData]);\n\n useEffect(() => {\n if (!verbose) return;\n console.log(\"Selected regions\", selectedRegions);\n }, [selectedRegions]);\n\n const tableElementRef = useRef<HTMLElement>(null);\n useEffect(() => {\n // Return the focus to the table\n tableElementRef.current?.focus();\n }, [focusedCell]);\n\n const columnWidths = ctx.useValue(columnWidthsAtom);\n\n // When filters are active, only show matching rows\n const filteredRowIndices = useSelector((state) => state.filteredRowIndices);\n const totalRows = Math.max(updatedData.length, data.length);\n const numRows =\n filteredRowIndices != null ? filteredRowIndices.length : totalRows;\n\n let className = `${density}-density`;\n\n const { rowHeight, style } = styleParamsForDensity(density);\n\n // In paged mode the row count is small and fixed, so let the table size to\n // its content (header + rows) instead of filling the viewport.\n const footerInfo = ctx.useValue(tableFooterAtom);\n const holderStyle =\n footerInfo.mode === \"paged\"\n ? {\n flex: \"0 0 auto\" as const,\n height: numRows * rowHeight + COLUMN_HEADER_HEIGHT,\n }\n : undefined;\n\n const onColumnsReordered = useSelector((state) => state.onColumnsReordered);\n\n // Auto-detect if any columns have sortable/filterable set.\n // If so and no explicit columnHeaderCellRenderer was provided,\n // use the built-in client-side sort/filter header.\n const hasSortableOrFilterable = useMemo(\n () =>\n columnSpec.some(\n (col) =>\n col.sortable ||\n col.filterable ||\n (Array.isArray(col.filters) && col.filters.length > 0),\n ),\n [columnSpec],\n );\n\n const columnSorts = useSelector((state) => state.columnSorts);\n const activeFilters = useSelector((state) => state.activeFilters);\n\n // Cell activation mode, defaulting from the legacy `autoFocusEditor` boolean\n // so existing consumers are unaffected. Synced into the store so the cell\n // renderer, editors, and key handlers all read it consistently.\n const cellInteractionMode: CellInteraction =\n cellInteraction ?? (autoFocusEditor ? \"auto\" : \"manual\");\n\n const storeState = storeAPI;\n useEffect(() => {\n storeState.setState({ cellInteraction: cellInteractionMode });\n }, [storeState, cellInteractionMode]);\n\n useEffect(() => {\n // Give the store a handle to the focusable holder so editors can return\n // keyboard focus to the table when the cursor leaves them.\n storeState.setState({ tableElement: tableElementRef.current });\n }, [storeState]);\n\n useEffect(() => {\n storeState.setState({ onEdit });\n }, [storeState, onEdit]);\n\n useEffect(() => {\n // Controlled overlay: mirror the caller's edited state into the store as\n // the source of truth. Optimistic in-table edits are superseded on the\n // next render when the caller passes an updated value back. When the caller\n // controls it, the loader-boundary identity remap steps aside.\n const controlled =\n updatedDataProp !== undefined ||\n rowStatusProp !== undefined ||\n deriveOverlay != null;\n const patch: Record<string, unknown> = { controlledOverlay: controlled };\n if (updatedDataProp !== undefined) patch.updatedData = updatedDataProp;\n if (rowStatusProp !== undefined) patch.rowStatus = rowStatusProp;\n storeState.setState(patch);\n }, [storeState, updatedDataProp, rowStatusProp, deriveOverlay]);\n\n // Derived controlled overlay: the library owns the loaded rows, so it runs\n // the consumer's `deriveOverlay(rows)` here and pushes the result. Re-derives\n // when the rows load/change or the function's identity changes (close it over\n // your external edit state). The `controlledOverlay` flag above suppresses the\n // loader-boundary identity remap so this derivation is authoritative.\n const loadedData = useSelector((state) => state.data);\n useEffect(() => {\n if (deriveOverlay == null) return;\n const overlay = deriveOverlay(loadedData);\n storeState.setState({\n updatedData: overlay.updatedData,\n rowStatus: overlay.rowStatus,\n });\n }, [deriveOverlay, loadedData, storeState]);\n\n // Function `columnSpec`: derive the spec from the loaded rows (no separate\n // fetch of sample data). Derive once the first rows arrive, and re-derive\n // when the function's identity changes (a consumer memoizes it over its\n // own view state — hidden columns, order, overrides). Not re-run as more\n // rows page in (guarded by the function identity), so it never clobbers\n // in-store column state on scroll.\n const derivedSpecFor = useRef<unknown>(null);\n useEffect(() => {\n if (typeof columnSpecProp !== \"function\") return;\n if (derivedSpecFor.current === columnSpecProp) return;\n const rows = loadedData.filter((r) => r != null);\n if (rows.length === 0) return;\n derivedSpecFor.current = columnSpecProp;\n storeState.setState({ columnSpec: columnSpecProp(rows) });\n }, [columnSpecProp, loadedData, storeState]);\n\n // Imperative re-fetch: bump `refreshToken` to reload the provider (e.g. after\n // a save). Skips the initial mount (the loader does its own first fetch).\n const bumpRefreshFromToken = ctx.useSet(dataRefreshTokenAtom);\n const firstRefreshToken = useRef(true);\n useEffect(() => {\n if (firstRefreshToken.current) {\n firstRefreshToken.current = false;\n return;\n }\n bumpRefreshFromToken((v) => v + 1);\n }, [refreshToken, bumpRefreshFromToken]);\n\n // The active provider supplies the row identity for the edit overlay.\n useEffect(() => {\n const id = activeProvider?.identity ?? identity;\n if (id != null) storeState.setState({ identity: id });\n }, [storeState, activeProvider, identity]);\n\n // Row deletion is a provider capability: an explicit `provider` without\n // `deleteRows` disables deletion entirely. (Local / loose sources keep the\n // local delete overlay.)\n useEffect(() => {\n const canDeleteRows = provider == null || provider.deleteRows != null;\n storeState.setState({ canDeleteRows });\n }, [storeState, provider]);\n\n // Merge consumer `rowStatusStyles` over the built-in defaults and hand the\n // result to the store, where the cell renderer and row-header renderer read\n // it. Merged (not replaced) so overriding one status doesn't drop the rest.\n const mergedRowStatusStyles = useMemo<RowStatusStyles>(\n () => ({ ...DEFAULT_ROW_STATUS_STYLES, ...rowStatusStyles }),\n [rowStatusStyles],\n );\n useEffect(() => {\n storeState.setState({ rowStatusStyles: mergedRowStatusStyles });\n }, [storeState, mergedRowStatusStyles]);\n\n const realizedColumns = useMemo(() => {\n return columnSpec.map((col, colIndex) => {\n let fn =\n col.headerCellRenderer ??\n columnHeaderCellRenderer ??\n renderColumnHeaderCell;\n let activeSort = null;\n let activeFilter = null;\n if (col.sortable) {\n activeSort = columnSorts?.find((s) => s.key === col.key);\n }\n // The active filter for this column is whichever active filter targets\n // it (a rich `col.filters` filter or the generic operator filter) — match\n // by columnKey rather than a fixed id.\n for (const entry of activeFilters?.values() ?? []) {\n if ((entry as any)?.filter?.columnKey === col.key) {\n activeFilter = entry;\n break;\n }\n }\n\n const _columnHeaderCellRenderer = (colIndex) => {\n return fn({\n col,\n colIndex,\n activeSort,\n activeFilter,\n });\n };\n\n return h(Column, {\n id: col.key,\n name: col.name,\n columnHeaderCellRenderer: _columnHeaderCellRenderer,\n cellRenderer: (rowIndex) => {\n const state = storeAPI.getState();\n return basicCellRenderer<T>(\n rowIndex,\n colIndex,\n col,\n state,\n filteredRowIndices,\n );\n },\n });\n });\n }, [\n columnSpec,\n columnSorts,\n activeFilters,\n storeAPI,\n filteredRowIndices,\n columnHeaderCellRenderer,\n ]);\n\n const onColumnWidthChanged = useSelector(\n (state) => state.onColumnWidthChanged,\n );\n\n const rowHeaderCellRenderer = useCallback(\n (rowIndex: number) => {\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n const statusVal = rowStatus[dataRowIndex];\n const style =\n (statusVal != null\n ? mergedRowStatusStyles[statusVal]?.headerStyle\n : null) ?? null;\n\n const defaultLabel = `${dataRowIndex + 1}`;\n let name: ReactNode = defaultLabel;\n if (rowHeaderRenderer != null) {\n const custom = rowHeaderRenderer({\n rowIndex: dataRowIndex,\n visibleIndex: rowIndex,\n row: data[dataRowIndex] ?? updatedData[dataRowIndex],\n status: statusVal,\n isDeleted: statusVal === TableElementStatus.DELETED,\n defaultLabel,\n });\n if (custom != null) name = custom;\n }\n\n return h(RowHeaderCell, {\n enableRowReordering: false,\n index: rowIndex,\n name,\n style,\n });\n },\n [\n rowStatus,\n filteredRowIndices,\n mergedRowStatusStyles,\n rowHeaderRenderer,\n data,\n updatedData,\n ],\n );\n\n let _selectionModes = selectionModes;\n if (\n editable &&\n _selectionModes != null &&\n !_selectionModes.includes(RegionCardinality.CELLS)\n ) {\n _selectionModes = [..._selectionModes, RegionCardinality.CELLS];\n // Ensure selection mode includes \"cells\"\n }\n\n const cellRendererDependencies = [\n data,\n updatedData,\n focusedCell,\n rowStatus,\n filteredRowIndices,\n ];\n\n // Drive the table from the active provider's `fetchData`. A local (in-memory)\n // provider loads the whole array at once; a remote one uses the `pageSize` /\n // `fetchMode` props and shows load progress.\n let _showLoadProgress: boolean = false;\n let dataLoader: ReactNode = null;\n if (activeProvider != null) {\n _showLoadProgress = !isLocalProvider;\n dataLoader = h(_DataLoaderManager, {\n key: \"__data_loader\",\n fetchData: activeProvider.fetchData,\n pageSize: isLocalProvider\n ? Math.max(sourceData?.length ?? 1, 1)\n : pageSize,\n fetchMode: isLocalProvider ? undefined : fetchMode,\n });\n }\n const showFilterBar =\n (filters != null && filters.length > 0) || hasSortableOrFilterable;\n\n let filterStatus: ReactNode = null;\n if (showFilterBar) {\n filterStatus = h(FilterBar, { filters: filters ?? [] });\n }\n\n return h(\"div.data-sheet-container\", { className, style }, [\n // The actions/tools toolbar (selection-modal). Table-scoped controls like\n // scroll-to-row / full-text search live here as ordinary actions.\n h(ActionsToolbar, { actions: _actions, tableName: name }),\n dataLoader,\n children,\n h(\n \"div.data-sheet-holder\",\n {\n tabIndex: 0,\n onKeyDown: handleKeyDown,\n onKeyUp: handleKeyUp,\n ref: tableElementRef,\n style: holderStyle,\n },\n h(\n Table,\n {\n ref,\n numRows,\n className: \"data-sheet\",\n enableFocusedCell,\n onColumnsReordered,\n focusedCell,\n selectedRegions,\n defaultRowHeight: rowHeight,\n minRowHeight: rowHeight,\n columnWidths,\n onColumnWidthChanged,\n onSelection,\n /** TODO: we could enable this, but we need a use-case first... */\n enableRowReordering: false,\n enableRowResizing: false,\n // The cell renderer is memoized internally based on these data dependencies\n cellRendererDependencies,\n onVisibleCellsChange: _onVisibleCellsChange,\n rowHeaderCellRenderer,\n selectionModes: _selectionModes,\n ...rest,\n getCellClipboardData: null,\n },\n realizedColumns,\n ),\n ),\n h(\"div.status-bar\", [\n filterStatus,\n statusBar,\n h(\"div.spacer\"),\n h.if(_showLoadProgress)(LoadProgressIndicator),\n ]),\n h.if(debugMode)(CellRendererDebugOverlay, {\n cellRendererDependencies,\n names: [\n \"data\",\n \"updatedData\",\n \"focusedCell\",\n \"rowStatus\",\n \"filteredRowIndices\",\n ],\n }),\n ]);\n}\n\nconst columnWidthsIndexAtom = atom((get) => get(storeAtom).columnWidthsIndex);\nconst defaultColumnWidthAtom = atom((get) => get(storeAtom).defaultColumnWidth);\n\nconst columnWidthsAtom = atom((get) => {\n const ix = get(columnWidthsIndexAtom);\n return get(columnSpecAtom).map(\n (col) => ix.get(col.key) ?? col.width ?? get(defaultColumnWidthAtom),\n );\n});\n\nfunction styleParamsForDensity(density: DataSheetDensity) {\n switch (density) {\n case DataSheetDensity.MEDIUM:\n return {\n rowHeight: 24,\n style: {\n \"--data-sheet-row-height\": \"24px\",\n \"--data-sheet-font-size\": \"14px\",\n },\n };\n case DataSheetDensity.LOW:\n return {\n rowHeight: 30,\n style: {\n \"--data-sheet-row-height\": \"30px\",\n \"--data-sheet-font-size\": \"18px\",\n },\n };\n case DataSheetDensity.HIGH:\n default:\n return {\n rowHeight: 20,\n style: {\n \"--data-sheet-row-height\": \"20px\",\n \"--data-sheet-font-size\": \"12px\",\n },\n };\n }\n}\n\n/** Convenience component: runs `useChunkLoader` from inside a `DataSheet`.\n * Render as a child of `DataSheet` (it renders nothing itself). */\nfunction _DataLoaderManager<T = any>({\n fetchData,\n ...rest\n}: {\n fetchData: FetchData<T>;\n} & FetchDataOptions) {\n useDataLoader(fetchData, rest);\n return null;\n}\n\nexport function getRowsToDelete(selection) {\n let rowIndices: number[] = [];\n for (const sel of selection) {\n // This isn't a full-row selection\n if (sel.cols != null) continue;\n if (sel.rows == null) continue;\n const [startIndex, endIndex] = sel.rows;\n for (let i = startIndex; i <= endIndex; i++) {\n rowIndices.push(i);\n }\n }\n return rowIndices;\n}\n"],"names":["DataSheetDensity","ctx","_actions","colIndex","style","name"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkEO,IAAK,qCAAAA,sBAAL;AACLA,oBAAA,MAAA,IAAO;AACPA,oBAAA,QAAA,IAAS;AACTA,oBAAA,KAAA,IAAM;AAHI,SAAAA;AAAA,GAAA,oBAAA,CAAA,CAAA;AAQZ,MAAM,uBAAuB;AA8G7B,MAAM,YAAmB,CAAA;AAElB,SAAS,UAAa,OAA0B;AACrD,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA,WAAW;AAAA,IACX,yBAAyB;AAAA,IACzB,oBAAoB;AAAA,IACpB,qBAAqB;AAAA,IACrB;AAAA,IACA,GAAG;AAAA,EAAA,IACD;AAEJ,SAAO;AAAA,IACL;AAAA,IACA;AAAA,MACE,MAAM,QAAQ;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA,GAAG;AAAA,IAAA;AAAA,IAEL,EAAE,YAAiB;AAAA,MACjB,GAAG;AAAA,MACH,MAAM,QAAQ;AAAA,MACd;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,IAAA,CACD;AAAA,EAAA;AAEL;AA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QAAQ,KAAM;AACtB,QAAI,IAAI,QAAQ,KAAM;AACtB,UAAM,CAAC,YAAY,QAAQ,IAAI,IAAI;AACnC,aAAS,IAAI,YAAY,KAAK,UAAU,KAAK;AAC3C,iBAAW,KAAK,CAAC;AAAA,IACnB;AAAA,EACF;AACA,SAAO;AACT;"}
@@ -11,7 +11,7 @@ const OPERATOR_LABELS = {
11
11
  lte: "≤",
12
12
  is: "is"
13
13
  };
14
- const STRING_OPERATORS = ["eq", "neq", "ilike"];
14
+ const STRING_OPERATORS = ["ilike", "eq", "neq"];
15
15
  const NUMERIC_OPERATORS = [
16
16
  "eq",
17
17
  "neq",
@@ -22,9 +22,9 @@ const NUMERIC_OPERATORS = [
22
22
  ];
23
23
  const BOOLEAN_OPERATORS = ["eq", "neq"];
24
24
  const DEFAULT_FILTER_OPERATORS = [
25
+ "ilike",
25
26
  "eq",
26
27
  "neq",
27
- "ilike",
28
28
  "gt",
29
29
  "lt",
30
30
  "gte",