@macrostrat/data-sheet 4.1.0 → 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 (69) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/actions/column-controls.cjs +17 -5
  3. package/dist/actions/column-controls.cjs.map +1 -1
  4. package/dist/actions/column-controls.js +18 -6
  5. package/dist/actions/column-controls.js.map +1 -1
  6. package/dist/actions/column-filter.cjs +48 -25
  7. package/dist/actions/column-filter.cjs.map +1 -1
  8. package/dist/actions/column-filter.js +50 -27
  9. package/dist/actions/column-filter.js.map +1 -1
  10. package/dist/actions/table-controls.cjs +4 -0
  11. package/dist/actions/table-controls.cjs.map +1 -1
  12. package/dist/actions/table-controls.js +4 -0
  13. package/dist/actions/table-controls.js.map +1 -1
  14. package/dist/actions/toolbar.cjs +19 -5
  15. package/dist/actions/toolbar.cjs.map +1 -1
  16. package/dist/actions/toolbar.js +20 -6
  17. package/dist/actions/toolbar.js.map +1 -1
  18. package/dist/cell-renderer.cjs +1 -1
  19. package/dist/cell-renderer.cjs.map +1 -1
  20. package/dist/cell-renderer.js +1 -1
  21. package/dist/cell-renderer.js.map +1 -1
  22. package/dist/core.cjs +11 -2
  23. package/dist/core.cjs.map +1 -1
  24. package/dist/core.d.ts +4 -0
  25. package/dist/core.js +11 -2
  26. package/dist/core.js.map +1 -1
  27. package/dist/filters/operators.cjs +2 -2
  28. package/dist/filters/operators.cjs.map +1 -1
  29. package/dist/filters/operators.d.ts +1 -1
  30. package/dist/filters/operators.js +2 -2
  31. package/dist/filters/operators.js.map +1 -1
  32. package/dist/postgrest-table/data-loaders.cjs +1 -8
  33. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  34. package/dist/postgrest-table/data-loaders.js +1 -8
  35. package/dist/postgrest-table/data-loaders.js.map +1 -1
  36. package/dist/provider.cjs +9 -3
  37. package/dist/provider.cjs.map +1 -1
  38. package/dist/provider.d.ts +2 -1
  39. package/dist/provider.js +9 -3
  40. package/dist/provider.js.map +1 -1
  41. package/dist/renderers/column-header-cell.cjs +19 -4
  42. package/dist/renderers/column-header-cell.cjs.map +1 -1
  43. package/dist/renderers/column-header-cell.d.ts +1 -2
  44. package/dist/renderers/column-header-cell.js +20 -5
  45. package/dist/renderers/column-header-cell.js.map +1 -1
  46. package/dist/types.cjs.map +1 -1
  47. package/dist/types.d.ts +10 -1
  48. package/dist/types.js.map +1 -1
  49. package/dist/utils/column-spec.cjs.map +1 -1
  50. package/dist/utils/column-spec.d.ts +4 -0
  51. package/dist/utils/column-spec.js.map +1 -1
  52. package/dist/zustand-store.cjs +1 -0
  53. package/dist/zustand-store.cjs.map +1 -1
  54. package/dist/zustand-store.js +1 -0
  55. package/dist/zustand-store.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/actions/column-controls.ts +24 -7
  58. package/src/actions/column-filter.ts +59 -30
  59. package/src/actions/table-controls.ts +4 -0
  60. package/src/actions/toolbar.ts +39 -11
  61. package/src/cell-renderer.ts +6 -1
  62. package/src/core.ts +26 -3
  63. package/src/filters/operators.ts +5 -3
  64. package/src/postgrest-table/data-loaders.ts +6 -10
  65. package/src/provider.ts +22 -5
  66. package/src/renderers/column-header-cell.ts +31 -4
  67. package/src/types.ts +10 -1
  68. package/src/utils/column-spec.ts +4 -0
  69. package/src/zustand-store.ts +1 -0
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 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 { CellRendererDebugOverlay, tableHotkeysAtom } from \"./utils\";\nimport {\n ActionsToolbar,\n clearSelectionAction,\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 /** 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 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 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 add([clearSelectionAction]);\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 // 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","clearSelectionAction","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":";;;;;;;;;;;;;;;;;;;;;;;AA+DO,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;AA2G7B,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;AAA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GAAG,IAAI,IAAI,GAAG,KAAK,IAAI,SAAS,IAAI,sBAAsB;AAAA,EAAA;AAEvE,CAAC;AAED,SAAS,sBAAsB,SAA2B;AACxD,UAAQ,SAAA;AAAA,IACN,KAAK;AACH,aAAO;AAAA,QACL,WAAW;AAAA,QACX,OAAO;AAAA,UACL,2BAA2B;AAAA,UAC3B,0BAA0B;AAAA,QAAA;AAAA,MAC5B;AAAA,IAEJ,KAAK;AACH,aAAO;AAAA,QACL,WAAW;AAAA,QACX,OAAO;AAAA,UACL,2BAA2B;AAAA,UAC3B,0BAA0B;AAAA,QAAA;AAAA,MAC5B;AAAA,IAEJ,KAAK;AAAA,IACL;AACE,aAAO;AAAA,QACL,WAAW;AAAA,QACX,OAAO;AAAA,UACL,2BAA2B;AAAA,UAC3B,0BAA0B;AAAA,QAAA;AAAA,MAC5B;AAAA,EACF;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,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,MACA;AAAA,IAAA,CACD;AAAA,EAAA;AAEL;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,MAAM;AAC7D,QAAM,SAAc,CAAA;AACpB,QAAM,WAAgB,CAAA;AACtB,QAAM,WAAmC,CAAA;AACzC,WAAS,IAAI,GAAG,IAAI,GAAG,KAAK;AAC1B,QAAI,OAAO,CAAC,MAAMC,MAAAA,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AA,UACL,2BAA2B;AAAA,UAC3B,0BAA0B;AAAA,QAAA;AAAA,MAC5B;AAAA,IAEJ,KAAK;AAAA,IACL;AACE,aAAO;AAAA,QACL,WAAW;AAAA,QACX,OAAO;AAAA,UACL,2BAA2B;AAAA,UAC3B,0BAA0B;AAAA,QAAA;AAAA,MAC5B;AAAA,EACF;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;;;;"}
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
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
package/dist/core.js CHANGED
@@ -15,7 +15,6 @@ import { ActionsToolbar } from "./actions/toolbar.js";
15
15
  import { LoadProgressIndicator } from "./components/view-info.js";
16
16
  import { CellRendererDebugOverlay } from "./utils/debug-overlay.js";
17
17
  import { columnControlActions } from "./actions/column-controls.js";
18
- import { clearSelectionAction } from "./actions/table-controls.js";
19
18
  import { clipboardActions } from "./actions/clipboard.js";
20
19
  import { resetChangesAction } from "./actions/builtin.js";
21
20
  import { createSaveAction } from "./actions/edit-actions.js";
@@ -53,6 +52,7 @@ function DataSheet(props) {
53
52
  h(_DataSheet, {
54
53
  ...rest,
55
54
  data: data ?? emptyData,
55
+ columnSpec,
56
56
  children,
57
57
  editable,
58
58
  enableColumnReordering,
@@ -119,6 +119,7 @@ function _DataSheet({
119
119
  actions,
120
120
  filters,
121
121
  columnHeaderCellRenderer,
122
+ columnSpec: columnSpecProp,
122
123
  statusBar,
123
124
  rowStatusStyles,
124
125
  rowHeaderRenderer,
@@ -162,7 +163,6 @@ function _DataSheet({
162
163
  };
163
164
  if (actions != null) add(actions);
164
165
  add(columnControlActions);
165
- add([clearSelectionAction]);
166
166
  if (enableClipboard) add(clipboardActions);
167
167
  if (editable) {
168
168
  if (saveHandler != null) add([createSaveAction(saveHandler)]);
@@ -252,6 +252,15 @@ function _DataSheet({
252
252
  rowStatus: overlay.rowStatus
253
253
  });
254
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]);
255
264
  const bumpRefreshFromToken = ctx.useSet(dataRefreshTokenAtom);
256
265
  const firstRefreshToken = useRef(true);
257
266
  useEffect(() => {
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 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 { CellRendererDebugOverlay, tableHotkeysAtom } from \"./utils\";\nimport {\n ActionsToolbar,\n clearSelectionAction,\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 /** 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 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 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 add([clearSelectionAction]);\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 // 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":";;;;;;;;;;;;;;;;;;;;;AA+DO,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;AA2G7B,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;AAA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AAI,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;AAMA,eAAe,mBACb,UACAC,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,MAAM;AAC7D,QAAM,SAAc,CAAA;AACpB,QAAM,W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",
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",
@@ -1 +1 @@
1
- {"version":3,"file":"operators.cjs","sources":["../../src/filters/operators.ts"],"sourcesContent":["/**\n * The canonical column-filter operator vocabulary, shared by the client-side\n * predicate (in-memory tables) and the server-side descriptor (a provider\n * translates it to a query). Promoted to core from the PostgREST column header,\n * so there is one operator model, not two.\n */\nimport type { ColumnSpec } from \"../utils/column-spec\";\n\n/** Column-filter operators. A superset that covers both in-memory comparison\n * and common backend query operators (PostgREST maps onto these names). */\nexport type FilterOperator =\n | \"eq\"\n | \"neq\"\n | \"like\"\n | \"ilike\"\n | \"gt\"\n | \"lt\"\n | \"gte\"\n | \"lte\"\n | \"is\";\n\n/** Human-readable operator labels for menus and active-filter tags. */\nexport const OPERATOR_LABELS: Record<FilterOperator, string> = {\n eq: \"=\",\n neq: \"≠\",\n like: \"like\",\n ilike: \"contains\",\n gt: \">\",\n lt: \"<\",\n gte: \"≥\",\n lte: \"≤\",\n is: \"is\",\n};\n\nconst STRING_OPERATORS: FilterOperator[] = [\"eq\", \"neq\", \"ilike\"];\nconst NUMERIC_OPERATORS: FilterOperator[] = [\n \"eq\",\n \"neq\",\n \"gt\",\n \"lt\",\n \"gte\",\n \"lte\",\n];\nconst BOOLEAN_OPERATORS: FilterOperator[] = [\"eq\", \"neq\"];\n\n/** Fallback when the column has no type information. */\nexport const DEFAULT_FILTER_OPERATORS: FilterOperator[] = [\n \"eq\",\n \"neq\",\n \"ilike\",\n \"gt\",\n \"lt\",\n \"gte\",\n \"lte\",\n];\n\nconst OPERATORS_BY_TYPE: Record<string, FilterOperator[]> = {\n string: STRING_OPERATORS,\n number: NUMERIC_OPERATORS,\n integer: NUMERIC_OPERATORS,\n boolean: BOOLEAN_OPERATORS,\n};\n\n/** Resolve the operators offered for a column: explicit `filterable.operators`\n * first, else inferred from `dataType`, else the defaults. */\nexport function getOperatorsForColumn(col: ColumnSpec): FilterOperator[] {\n if (typeof col.filterable === \"object\" && col.filterable.operators?.length) {\n return col.filterable.operators as FilterOperator[];\n }\n if (col.dataType != null) {\n return OPERATORS_BY_TYPE[col.dataType] ?? DEFAULT_FILTER_OPERATORS;\n }\n return DEFAULT_FILTER_OPERATORS;\n}\n\nfunction looseEq(a: any, b: any): boolean {\n if (a == null) return b == null || b === \"\";\n // Compare numerically when both look numeric, else as strings.\n const an = Number(a);\n const bn = Number(b);\n if (!Number.isNaN(an) && !Number.isNaN(bn) && String(a).trim() !== \"\") {\n return an === bn;\n }\n return String(a).toLowerCase() === String(b).toLowerCase();\n}\n\n/**\n * The client-side predicate for a `{ operator, value }` column filter — the\n * in-memory equivalent of what a backend applies server-side. An empty filter\n * value is treated as \"no constraint\" (matches everything).\n */\nexport function testFilterOperator(\n cellValue: any,\n operator: FilterOperator,\n filterValue: any,\n): boolean {\n if (filterValue === \"\" || filterValue == null) return true;\n switch (operator) {\n case \"eq\":\n return looseEq(cellValue, filterValue);\n case \"neq\":\n return !looseEq(cellValue, filterValue);\n case \"gt\":\n return Number(cellValue) > Number(filterValue);\n case \"lt\":\n return Number(cellValue) < Number(filterValue);\n case \"gte\":\n return Number(cellValue) >= Number(filterValue);\n case \"lte\":\n return Number(cellValue) <= Number(filterValue);\n case \"like\":\n return String(cellValue ?? \"\").includes(String(filterValue));\n case \"ilike\":\n return String(cellValue ?? \"\")\n .toLowerCase()\n .includes(String(filterValue).toLowerCase());\n case \"is\": {\n const v = String(filterValue).toLowerCase();\n if (v === \"null\") return cellValue == null;\n if (v === \"true\") return cellValue === true;\n if (v === \"false\") return cellValue === false;\n return looseEq(cellValue, filterValue);\n }\n default:\n return true;\n }\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,kBAAkD;AAAA,EAC7D,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK;AAAA,EACL,IAAI;AACN;AAEA,MAAM,mBAAqC,CAAC,MAAM,OAAO,OAAO;AAChE,MAAM,oBAAsC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,oBAAsC,CAAC,MAAM,KAAK;AAGjD,MAAM,2BAA6C;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,oBAAsD;AAAA,EAC1D,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AACX;AAIO,SAAS,sBAAsB,KAAmC;AACvE,MAAI,OAAO,IAAI,eAAe,YAAY,IAAI,WAAW,WAAW,QAAQ;AAC1E,WAAO,IAAI,WAAW;AAAA,EACxB;AACA,MAAI,IAAI,YAAY,MAAM;AACxB,WAAO,kBAAkB,IAAI,QAAQ,KAAK;AAAA,EAC5C;AACA,SAAO;AACT;AAEA,SAAS,QAAQ,GAAQ,GAAiB;AACxC,MAAI,KAAK,KAAM,QAAO,KAAK,QAAQ,MAAM;AAEzC,QAAM,KAAK,OAAO,CAAC;AACnB,QAAM,KAAK,OAAO,CAAC;AACnB,MAAI,CAAC,OAAO,MAAM,EAAE,KAAK,CAAC,OAAO,MAAM,EAAE,KAAK,OAAO,CAAC,EAAE,KAAA,MAAW,IAAI;AACrE,WAAO,OAAO;AAAA,EAChB;AACA,SAAO,OAAO,CAAC,EAAE,YAAA,MAAkB,OAAO,CAAC,EAAE,YAAA;AAC/C;AAOO,SAAS,mBACd,WACA,UACA,aACS;AACT,MAAI,gBAAgB,MAAM,eAAe,KAAM,QAAO;AACtD,UAAQ,UAAA;AAAA,IACN,KAAK;AACH,aAAO,QAAQ,WAAW,WAAW;AAAA,IACvC,KAAK;AACH,aAAO,CAAC,QAAQ,WAAW,WAAW;AAAA,IACxC,KAAK;AACH,aAAO,OAAO,SAAS,IAAI,OAAO,WAAW;AAAA,IAC/C,KAAK;AACH,aAAO,OAAO,SAAS,IAAI,OAAO,WAAW;AAAA,IAC/C,KAAK;AACH,aAAO,OAAO,SAAS,KAAK,OAAO,WAAW;AAAA,IAChD,KAAK;AACH,aAAO,OAAO,SAAS,KAAK,OAAO,WAAW;AAAA,IAChD,KAAK;AACH,aAAO,OAAO,aAAa,EAAE,EAAE,SAAS,OAAO,WAAW,CAAC;AAAA,IAC7D,KAAK;AACH,aAAO,OAAO,aAAa,EAAE,EAC1B,YAAA,EACA,SAAS,OAAO,WAAW,EAAE,aAAa;AAAA,IAC/C,KAAK,MAAM;AACT,YAAM,IAAI,OAAO,WAAW,EAAE,YAAA;AAC9B,UAAI,MAAM,OAAQ,QAAO,aAAa;AACtC,UAAI,MAAM,OAAQ,QAAO,cAAc;AACvC,UAAI,MAAM,QAAS,QAAO,cAAc;AACxC,aAAO,QAAQ,WAAW,WAAW;AAAA,IACvC;AAAA,IACA;AACE,aAAO;AAAA,EAAA;AAEb;;;;;"}
1
+ {"version":3,"file":"operators.cjs","sources":["../../src/filters/operators.ts"],"sourcesContent":["/**\n * The canonical column-filter operator vocabulary, shared by the client-side\n * predicate (in-memory tables) and the server-side descriptor (a provider\n * translates it to a query). Promoted to core from the PostgREST column header,\n * so there is one operator model, not two.\n */\nimport type { ColumnSpec } from \"../utils/column-spec\";\n\n/** Column-filter operators. A superset that covers both in-memory comparison\n * and common backend query operators (PostgREST maps onto these names). */\nexport type FilterOperator =\n | \"eq\"\n | \"neq\"\n | \"like\"\n | \"ilike\"\n | \"gt\"\n | \"lt\"\n | \"gte\"\n | \"lte\"\n | \"is\";\n\n/** Human-readable operator labels for menus and active-filter tags. */\nexport const OPERATOR_LABELS: Record<FilterOperator, string> = {\n eq: \"=\",\n neq: \"≠\",\n like: \"like\",\n ilike: \"contains\",\n gt: \">\",\n lt: \"<\",\n gte: \"≥\",\n lte: \"≤\",\n is: \"is\",\n};\n\n// \"contains\" (`ilike`) leads for text, so it's the default operator — the most\n// common intent when filtering a string column.\nconst STRING_OPERATORS: FilterOperator[] = [\"ilike\", \"eq\", \"neq\"];\nconst NUMERIC_OPERATORS: FilterOperator[] = [\n \"eq\",\n \"neq\",\n \"gt\",\n \"lt\",\n \"gte\",\n \"lte\",\n];\nconst BOOLEAN_OPERATORS: FilterOperator[] = [\"eq\", \"neq\"];\n\n/** Fallback when the column has no type information. Leads with \"contains\". */\nexport const DEFAULT_FILTER_OPERATORS: FilterOperator[] = [\n \"ilike\",\n \"eq\",\n \"neq\",\n \"gt\",\n \"lt\",\n \"gte\",\n \"lte\",\n];\n\nconst OPERATORS_BY_TYPE: Record<string, FilterOperator[]> = {\n string: STRING_OPERATORS,\n number: NUMERIC_OPERATORS,\n integer: NUMERIC_OPERATORS,\n boolean: BOOLEAN_OPERATORS,\n};\n\n/** Resolve the operators offered for a column: explicit `filterable.operators`\n * first, else inferred from `dataType`, else the defaults. */\nexport function getOperatorsForColumn(col: ColumnSpec): FilterOperator[] {\n if (typeof col.filterable === \"object\" && col.filterable.operators?.length) {\n return col.filterable.operators as FilterOperator[];\n }\n if (col.dataType != null) {\n return OPERATORS_BY_TYPE[col.dataType] ?? DEFAULT_FILTER_OPERATORS;\n }\n return DEFAULT_FILTER_OPERATORS;\n}\n\nfunction looseEq(a: any, b: any): boolean {\n if (a == null) return b == null || b === \"\";\n // Compare numerically when both look numeric, else as strings.\n const an = Number(a);\n const bn = Number(b);\n if (!Number.isNaN(an) && !Number.isNaN(bn) && String(a).trim() !== \"\") {\n return an === bn;\n }\n return String(a).toLowerCase() === String(b).toLowerCase();\n}\n\n/**\n * The client-side predicate for a `{ operator, value }` column filter — the\n * in-memory equivalent of what a backend applies server-side. An empty filter\n * value is treated as \"no constraint\" (matches everything).\n */\nexport function testFilterOperator(\n cellValue: any,\n operator: FilterOperator,\n filterValue: any,\n): boolean {\n if (filterValue === \"\" || filterValue == null) return true;\n switch (operator) {\n case \"eq\":\n return looseEq(cellValue, filterValue);\n case \"neq\":\n return !looseEq(cellValue, filterValue);\n case \"gt\":\n return Number(cellValue) > Number(filterValue);\n case \"lt\":\n return Number(cellValue) < Number(filterValue);\n case \"gte\":\n return Number(cellValue) >= Number(filterValue);\n case \"lte\":\n return Number(cellValue) <= Number(filterValue);\n case \"like\":\n return String(cellValue ?? \"\").includes(String(filterValue));\n case \"ilike\":\n return String(cellValue ?? \"\")\n .toLowerCase()\n .includes(String(filterValue).toLowerCase());\n case \"is\": {\n const v = String(filterValue).toLowerCase();\n if (v === \"null\") return cellValue == null;\n if (v === \"true\") return cellValue === true;\n if (v === \"false\") return cellValue === false;\n return looseEq(cellValue, filterValue);\n }\n default:\n return true;\n }\n}\n"],"names":[],"mappings":";;AAsBO,MAAM,kBAAkD;AAAA,EAC7D,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK;AAAA,EACL,IAAI;AACN;AAIA,MAAM,mBAAqC,CAAC,SAAS,MAAM,KAAK;AAChE,MAAM,oBAAsC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,oBAAsC,CAAC,MAAM,KAAK;AAGjD,MAAM,2BAA6C;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,oBAAsD;AAAA,EAC1D,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AA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AACT,YAAM,IAAI,OAAO,WAAW,EAAE,YAAA;AAC9B,UAAI,MAAM,OAAQ,QAAO,aAAa;AACtC,UAAI,MAAM,OAAQ,QAAO,cAAc;AACvC,UAAI,MAAM,QAAS,QAAO,cAAc;AACxC,aAAO,QAAQ,WAAW,WAAW;AAAA,IACvC;AAAA,IACA;AACE,aAAO;AAAA,EAAA;AAEb;;;;;"}
@@ -4,7 +4,7 @@ import { ColumnSpec } from '../utils/column-spec';
4
4
  export type FilterOperator = "eq" | "neq" | "like" | "ilike" | "gt" | "lt" | "gte" | "lte" | "is";
5
5
  /** Human-readable operator labels for menus and active-filter tags. */
6
6
  export declare const OPERATOR_LABELS: Record<FilterOperator, string>;
7
- /** Fallback when the column has no type information. */
7
+ /** Fallback when the column has no type information. Leads with "contains". */
8
8
  export declare const DEFAULT_FILTER_OPERATORS: FilterOperator[];
9
9
  /** Resolve the operators offered for a column: explicit `filterable.operators`
10
10
  * first, else inferred from `dataType`, else the defaults. */
@@ -9,7 +9,7 @@ const OPERATOR_LABELS = {
9
9
  lte: "≤",
10
10
  is: "is"
11
11
  };
12
- const STRING_OPERATORS = ["eq", "neq", "ilike"];
12
+ const STRING_OPERATORS = ["ilike", "eq", "neq"];
13
13
  const NUMERIC_OPERATORS = [
14
14
  "eq",
15
15
  "neq",
@@ -20,9 +20,9 @@ const NUMERIC_OPERATORS = [
20
20
  ];
21
21
  const BOOLEAN_OPERATORS = ["eq", "neq"];
22
22
  const DEFAULT_FILTER_OPERATORS = [
23
+ "ilike",
23
24
  "eq",
24
25
  "neq",
25
- "ilike",
26
26
  "gt",
27
27
  "lt",
28
28
  "gte",
@@ -1 +1 @@
1
- {"version":3,"file":"operators.js","sources":["../../src/filters/operators.ts"],"sourcesContent":["/**\n * The canonical column-filter operator vocabulary, shared by the client-side\n * predicate (in-memory tables) and the server-side descriptor (a provider\n * translates it to a query). Promoted to core from the PostgREST column header,\n * so there is one operator model, not two.\n */\nimport type { ColumnSpec } from \"../utils/column-spec\";\n\n/** Column-filter operators. A superset that covers both in-memory comparison\n * and common backend query operators (PostgREST maps onto these names). */\nexport type FilterOperator =\n | \"eq\"\n | \"neq\"\n | \"like\"\n | \"ilike\"\n | \"gt\"\n | \"lt\"\n | \"gte\"\n | \"lte\"\n | \"is\";\n\n/** Human-readable operator labels for menus and active-filter tags. */\nexport const OPERATOR_LABELS: Record<FilterOperator, string> = {\n eq: \"=\",\n neq: \"≠\",\n like: \"like\",\n ilike: \"contains\",\n gt: \">\",\n lt: \"<\",\n gte: \"≥\",\n lte: \"≤\",\n is: \"is\",\n};\n\nconst STRING_OPERATORS: FilterOperator[] = [\"eq\", \"neq\", \"ilike\"];\nconst NUMERIC_OPERATORS: FilterOperator[] = [\n \"eq\",\n \"neq\",\n \"gt\",\n \"lt\",\n \"gte\",\n \"lte\",\n];\nconst BOOLEAN_OPERATORS: FilterOperator[] = [\"eq\", \"neq\"];\n\n/** Fallback when the column has no type information. */\nexport const DEFAULT_FILTER_OPERATORS: FilterOperator[] = [\n \"eq\",\n \"neq\",\n \"ilike\",\n \"gt\",\n \"lt\",\n \"gte\",\n \"lte\",\n];\n\nconst OPERATORS_BY_TYPE: Record<string, FilterOperator[]> = {\n string: STRING_OPERATORS,\n number: NUMERIC_OPERATORS,\n integer: NUMERIC_OPERATORS,\n boolean: BOOLEAN_OPERATORS,\n};\n\n/** Resolve the operators offered for a column: explicit `filterable.operators`\n * first, else inferred from `dataType`, else the defaults. */\nexport function getOperatorsForColumn(col: ColumnSpec): FilterOperator[] {\n if (typeof col.filterable === \"object\" && col.filterable.operators?.length) {\n return col.filterable.operators as FilterOperator[];\n }\n if (col.dataType != null) {\n return OPERATORS_BY_TYPE[col.dataType] ?? DEFAULT_FILTER_OPERATORS;\n }\n return DEFAULT_FILTER_OPERATORS;\n}\n\nfunction looseEq(a: any, b: any): boolean {\n if (a == null) return b == null || b === \"\";\n // Compare numerically when both look numeric, else as strings.\n const an = Number(a);\n const bn = Number(b);\n if (!Number.isNaN(an) && !Number.isNaN(bn) && String(a).trim() !== \"\") {\n return an === bn;\n }\n return String(a).toLowerCase() === String(b).toLowerCase();\n}\n\n/**\n * The client-side predicate for a `{ operator, value }` column filter — the\n * in-memory equivalent of what a backend applies server-side. An empty filter\n * value is treated as \"no constraint\" (matches everything).\n */\nexport function testFilterOperator(\n cellValue: any,\n operator: FilterOperator,\n filterValue: any,\n): boolean {\n if (filterValue === \"\" || filterValue == null) return true;\n switch (operator) {\n case \"eq\":\n return looseEq(cellValue, filterValue);\n case \"neq\":\n return !looseEq(cellValue, filterValue);\n case \"gt\":\n return Number(cellValue) > Number(filterValue);\n case \"lt\":\n return Number(cellValue) < Number(filterValue);\n case \"gte\":\n return Number(cellValue) >= Number(filterValue);\n case \"lte\":\n return Number(cellValue) <= Number(filterValue);\n case \"like\":\n return String(cellValue ?? \"\").includes(String(filterValue));\n case \"ilike\":\n return String(cellValue ?? \"\")\n .toLowerCase()\n .includes(String(filterValue).toLowerCase());\n case \"is\": {\n const v = String(filterValue).toLowerCase();\n if (v === \"null\") return cellValue == null;\n if (v === \"true\") return cellValue === true;\n if (v === \"false\") return cellValue === false;\n return looseEq(cellValue, filterValue);\n }\n default:\n return true;\n }\n}\n"],"names":[],"mappings":"AAsBO,MAAM,kBAAkD;AAAA,EAC7D,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK;AAAA,EACL,IAAI;AACN;AAEA,MAAM,mBAAqC,CAAC,MAAM,OAAO,OAAO;AAChE,MAAM,oBAAsC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,oBAAsC,CAAC,MAAM,KAAK;AAGjD,MAAM,2BAA6C;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM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,YAAA,EACA,SAAS,OAAO,WAAW,EAAE,aAAa;AAAA,IAC/C,KAAK,MAAM;AACT,YAAM,IAAI,OAAO,WAAW,EAAE,YAAA;AAC9B,UAAI,MAAM,OAAQ,QAAO,aAAa;AACtC,UAAI,MAAM,OAAQ,QAAO,cAAc;AACvC,UAAI,MAAM,QAAS,QAAO,cAAc;AACxC,aAAO,QAAQ,WAAW,WAAW;AAAA,IACvC;AAAA,IACA;AACE,aAAO;AAAA,EAAA;AAEb;"}
1
+ {"version":3,"file":"operators.js","sources":["../../src/filters/operators.ts"],"sourcesContent":["/**\n * The canonical column-filter operator vocabulary, shared by the client-side\n * predicate (in-memory tables) and the server-side descriptor (a provider\n * translates it to a query). Promoted to core from the PostgREST column header,\n * so there is one operator model, not two.\n */\nimport type { ColumnSpec } from \"../utils/column-spec\";\n\n/** Column-filter operators. A superset that covers both in-memory comparison\n * and common backend query operators (PostgREST maps onto these names). */\nexport type FilterOperator =\n | \"eq\"\n | \"neq\"\n | \"like\"\n | \"ilike\"\n | \"gt\"\n | \"lt\"\n | \"gte\"\n | \"lte\"\n | \"is\";\n\n/** Human-readable operator labels for menus and active-filter tags. */\nexport const OPERATOR_LABELS: Record<FilterOperator, string> = {\n eq: \"=\",\n neq: \"≠\",\n like: \"like\",\n ilike: \"contains\",\n gt: \">\",\n lt: \"<\",\n gte: \"≥\",\n lte: \"≤\",\n is: \"is\",\n};\n\n// \"contains\" (`ilike`) leads for text, so it's the default operator — the most\n// common intent when filtering a string column.\nconst STRING_OPERATORS: FilterOperator[] = [\"ilike\", \"eq\", \"neq\"];\nconst NUMERIC_OPERATORS: FilterOperator[] = [\n \"eq\",\n \"neq\",\n \"gt\",\n \"lt\",\n \"gte\",\n \"lte\",\n];\nconst BOOLEAN_OPERATORS: FilterOperator[] = [\"eq\", \"neq\"];\n\n/** Fallback when the column has no type information. Leads with \"contains\". */\nexport const DEFAULT_FILTER_OPERATORS: FilterOperator[] = [\n \"ilike\",\n \"eq\",\n \"neq\",\n \"gt\",\n \"lt\",\n \"gte\",\n \"lte\",\n];\n\nconst OPERATORS_BY_TYPE: Record<string, FilterOperator[]> = {\n string: STRING_OPERATORS,\n number: NUMERIC_OPERATORS,\n integer: NUMERIC_OPERATORS,\n boolean: BOOLEAN_OPERATORS,\n};\n\n/** Resolve the operators offered for a column: explicit `filterable.operators`\n * first, else inferred from `dataType`, else the defaults. */\nexport function getOperatorsForColumn(col: ColumnSpec): FilterOperator[] {\n if (typeof col.filterable === \"object\" && col.filterable.operators?.length) {\n return col.filterable.operators as FilterOperator[];\n }\n if (col.dataType != null) {\n return OPERATORS_BY_TYPE[col.dataType] ?? DEFAULT_FILTER_OPERATORS;\n }\n return DEFAULT_FILTER_OPERATORS;\n}\n\nfunction looseEq(a: any, b: any): boolean {\n if (a == null) return b == null || b === \"\";\n // Compare numerically when both look numeric, else as strings.\n const an = Number(a);\n const bn = Number(b);\n if (!Number.isNaN(an) && !Number.isNaN(bn) && String(a).trim() !== \"\") {\n return an === bn;\n }\n return String(a).toLowerCase() === String(b).toLowerCase();\n}\n\n/**\n * The client-side predicate for a `{ operator, value }` column filter — the\n * in-memory equivalent of what a backend applies server-side. An empty filter\n * value is treated as \"no constraint\" (matches everything).\n */\nexport function testFilterOperator(\n cellValue: any,\n operator: FilterOperator,\n filterValue: any,\n): boolean {\n if (filterValue === \"\" || filterValue == null) return true;\n switch (operator) {\n case \"eq\":\n return looseEq(cellValue, filterValue);\n case \"neq\":\n return !looseEq(cellValue, filterValue);\n case \"gt\":\n return Number(cellValue) > Number(filterValue);\n case \"lt\":\n return Number(cellValue) < Number(filterValue);\n case \"gte\":\n return Number(cellValue) >= Number(filterValue);\n case \"lte\":\n return Number(cellValue) <= Number(filterValue);\n case \"like\":\n return String(cellValue ?? \"\").includes(String(filterValue));\n case \"ilike\":\n return String(cellValue ?? \"\")\n .toLowerCase()\n .includes(String(filterValue).toLowerCase());\n case \"is\": {\n const v = String(filterValue).toLowerCase();\n if (v === \"null\") return cellValue == null;\n if (v === \"true\") return cellValue === true;\n if (v === \"false\") return cellValue === false;\n return looseEq(cellValue, filterValue);\n }\n default:\n return true;\n }\n}\n"],"names":[],"mappings":"AAsBO,MAAM,kBAAkD;AAAA,EAC7D,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AAAA,EACP,IAAI;AAAA,EACJ,IAAI;AAAA,EACJ,KAAK;AAAA,EACL,KAAK;AAAA,EACL,IAAI;AACN;AAIA,MAAM,mBAAqC,CAAC,SAAS,MAAM,KAAK;AAChE,MAAM,oBAAsC;AAAA,EAC1C;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AACA,MAAM,oBAAsC,CAAC,MAAM,KAAK;AAGjD,MAAM,2BAA6C;AAAA,EACxD;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF;AAEA,MAAM,oBAAsD;AAAA,EAC1D,QAAQ;AAAA,EACR,QAAQ;AAAA,EACR,SAAS;AAAA,EACT,SAAS;AACX;AAIO,SAAS,sBAAsB,KAAmC;AACvE,MAAI,OAAO,IAAI,eAAe,YAAY,IAAI,WAAW,WAAW,QAAQ;AAC1E,WAAO,IAAI,WAAW;AAAA,EACxB;AACA,MAAI,IAAI,YAAY,MAAM;AACxB,WAAO,kBAAkB,IAAI,QAAQ,KAAK;AAAA,EAC5C;AACA,SAAO;AACT;AAEA,SAAS,QAAQ,GAAQ,GAAiB;AACxC,MAAI,KAAK,KAAM,QAAO,KAAK,QAAQ,MAAM;AAEzC,QAAM,KAAK,OAAO,CAAC;AACnB,QAAM,KAAK,OAAO,CAAC;AACnB,MAAI,CAAC,OAAO,MAAM,EAAE,KAAK,CAAC,OAAO,MAAM,EAAE,KAAK,OAAO,CAAC,EAAE,KAAA,MAAW,IAAI;AACrE,WAAO,OAAO;AAAA,EAChB;AACA,SAAO,OAAO,CAAC,EAAE,YAAA,MAAkB,OAAO,CAAC,EAAE,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