@macrostrat/data-sheet 4.0.1 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +19 -0
- package/README.md +11 -1
- package/dist/actions/column-controls.cjs +89 -0
- package/dist/actions/column-controls.cjs.map +1 -1
- package/dist/actions/column-controls.js +90 -1
- package/dist/actions/column-controls.js.map +1 -1
- package/dist/actions/selection.cjs +2 -1
- package/dist/actions/selection.cjs.map +1 -1
- package/dist/actions/selection.js +2 -1
- package/dist/actions/selection.js.map +1 -1
- package/dist/actions/table-controls.cjs +17 -0
- package/dist/actions/table-controls.cjs.map +1 -1
- package/dist/actions/table-controls.d.ts +4 -0
- package/dist/actions/table-controls.js +17 -0
- package/dist/actions/table-controls.js.map +1 -1
- package/dist/actions/toolbar.cjs +18 -2
- package/dist/actions/toolbar.cjs.map +1 -1
- package/dist/actions/toolbar.js +18 -2
- package/dist/actions/toolbar.js.map +1 -1
- package/dist/actions/types.d.ts +9 -0
- package/dist/cell-renderer.cjs +8 -6
- package/dist/cell-renderer.cjs.map +1 -1
- package/dist/cell-renderer.js +8 -6
- package/dist/cell-renderer.js.map +1 -1
- package/dist/core.cjs +59 -9
- package/dist/core.cjs.map +1 -1
- package/dist/core.d.ts +28 -1
- package/dist/core.js +60 -10
- package/dist/core.js.map +1 -1
- package/dist/index.cjs +4 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +4 -2
- package/dist/renderers/column-header-cell.cjs +14 -28
- package/dist/renderers/column-header-cell.cjs.map +1 -1
- package/dist/renderers/column-header-cell.js +15 -29
- package/dist/renderers/column-header-cell.js.map +1 -1
- package/dist/types.cjs +11 -0
- package/dist/types.cjs.map +1 -1
- package/dist/types.d.ts +45 -1
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -1
- package/dist/utils/column-spec.cjs.map +1 -1
- package/dist/utils/column-spec.d.ts +4 -0
- package/dist/utils/column-spec.js.map +1 -1
- package/dist/zustand-store.cjs +6 -3
- package/dist/zustand-store.cjs.map +1 -1
- package/dist/zustand-store.js +7 -4
- package/dist/zustand-store.js.map +1 -1
- package/package.json +1 -1
- package/src/actions/column-controls.ts +114 -0
- package/src/actions/selection.ts +1 -0
- package/src/actions/table-controls.ts +20 -0
- package/src/actions/toolbar.ts +30 -2
- package/src/actions/types.ts +10 -0
- package/src/cell-renderer.ts +17 -9
- package/src/core.ts +107 -12
- package/src/renderers/column-header-cell.ts +20 -32
- package/src/types.ts +56 -1
- package/src/utils/column-spec.ts +4 -0
- package/src/zustand-store.ts +11 -5
package/dist/types.js
CHANGED
|
@@ -3,8 +3,19 @@ var TableElementStatus = /* @__PURE__ */ ((TableElementStatus2) => {
|
|
|
3
3
|
TableElementStatus2["ADDED"] = "added";
|
|
4
4
|
return TableElementStatus2;
|
|
5
5
|
})(TableElementStatus || {});
|
|
6
|
+
const DEFAULT_ROW_STATUS_STYLES = {
|
|
7
|
+
[
|
|
8
|
+
"deleted"
|
|
9
|
+
/* DELETED */
|
|
10
|
+
]: {
|
|
11
|
+
cellStyle: { opacity: 0.5, textDecoration: "line-through" },
|
|
12
|
+
headerStyle: { opacity: 0.5, textDecoration: "line-through" },
|
|
13
|
+
intent: "danger"
|
|
14
|
+
}
|
|
15
|
+
};
|
|
6
16
|
const DS_ROW_ID = "__dsRowId";
|
|
7
17
|
export {
|
|
18
|
+
DEFAULT_ROW_STATUS_STYLES,
|
|
8
19
|
DS_ROW_ID,
|
|
9
20
|
TableElementStatus
|
|
10
21
|
};
|
package/dist/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type {\n FocusedCellCoordinates,\n Region,\n RegionCardinality,\n Table2,\n} from \"@blueprintjs/table\";\nimport { ColumnSpec, ColumnSpecOptions } from \"./utils\";\nimport { OverlayToaster } from \"@blueprintjs/core\";\nimport type { CellEdit } from \"./actions\";\n\n/** A single column sort entry for client-side sorting.\n * Defined here (rather than in actions/types) to avoid circular imports. */\nexport interface ColumnSort {\n key: string;\n ascending: boolean;\n}\n\n/** Direction of keyboard navigation between cells. */\nexport type NavDirection = \"up\" | \"down\" | \"left\" | \"right\";\n\n/**\n * A structured, revertible description of a user edit. Emitted via the\n * `onEdit` hook so a consumer can capture edits as operations (and, with the\n * controlled-overlay API, own the edited state) instead of diffing\n * `updatedData`. This is the write half of the data-sheet's read/write\n * contract — the mirror of how data flows in.\n */\nexport type EditEvent<T = any> =\n | { type: \"setCells\"; cells: CellEdit[] }\n | { type: \"deleteRows\"; rowIndices: number[] }\n | { type: \"restoreRows\"; rowIndices: number[] }\n | { type: \"addRow\"; rowIndex: number; value: Partial<T> }\n | { type: \"resetChanges\" };\n\nexport interface DataSheetCoreProps<T> {\n data: T[];\n columnSpec?: ColumnSpec[];\n editable?: boolean;\n enableColumnReordering?: boolean;\n defaultColumnWidth?: number;\n}\n\nexport enum TableElementStatus {\n DELETED = \"deleted\",\n ADDED = \"added\",\n}\n\n/** Property key holding a stable synthetic id on rows added in-table. Added\n * rows aren't in the data provider, so they need their own identity to survive\n * a provider re-fetch; it's carried on the row and preserved through edits. */\nexport const DS_ROW_ID = \"__dsRowId\";\n\n/** Proxy stored during a copy operation, enabling backend-mediated paste\n * for lazy-loaded tables where not all data is available locally. */\nexport interface ClipboardProxy {\n cardinality: RegionCardinality;\n /** Source row indices (for row/cell copies) */\n rowIndices?: number[];\n /** Source column keys (for column/cell copies) */\n columnKeys?: string[];\n /** The plain text written to the clipboard, used to verify the proxy\n * is still valid on paste (i.e., clipboard hasn't been overwritten). */\n text: string;\n}\n\nexport interface DataSheetState<T> {\n selection: Region[];\n columnSpec: ColumnSpec[];\n fillValueBaseCell: FocusedCellCoordinates | null;\n focusedCell: FocusedCellCoordinates | null;\n topLeftCell: FocusedCellCoordinates | null;\n /**\n * Set of row indices that have been added to the table,\n * but not yet committed to the underlying data array.\n *\n * This is used to track which rows should be reverted when\n * a \"reset\" action is performed.\n */\n rowStatus: TableElementStatus[];\n // Sparse data structure for updated data\n updatedData: T[];\n initialized: boolean;\n columnWidthsIndex: Map<string, number>;\n /** Active column/table filters. Keys are filter IDs, values carry the\n * filter definition and its current configuration state. */\n activeFilters: Map<string, { filter: any; state: any }>;\n /** Clipboard proxy from the last copy operation */\n clipboardProxy: ClipboardProxy | null;\n /** Visible row indices when filters are active. `null` means show all rows. */\n filteredRowIndices: number[] | null;\n /** Active column sort entries for client-side sorting. */\n columnSorts: ColumnSort[];\n /** Whether selecting a cell automatically activates its surface (opens an\n * editor/detail panel and, for editors, focuses it). `\"manual\"` opens only\n * on click. */\n cellInteraction: \"auto\" | \"manual\";\n /** Runtime override of `cellInteraction`: while `false`, auto-activation is\n * suppressed (set by pressing Escape, re-armed by clicking a cell) so the\n * keyboard prioritizes navigation. */\n autoActivateArmed: boolean;\n /** Direction of the last keyboard navigation, used to place an editor's\n * cursor on the side the user is travelling toward. `null` after a click. */\n lastNavDirection: NavDirection | null;\n /** The table's focusable holder element; editors return focus here when the\n * cursor leaves them so arrow-key navigation resumes. */\n tableElement: HTMLElement | null;\n /** Whether the focused cell's surface (editor or detail panel) is open.\n * Owned by the store — not per-popover — so navigation, clicks, and the\n * Escape handler all agree on it. */\n cellSurfaceOpen: boolean;\n /** Optional observer called for every user edit as a structured\n * `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a\n * consumer capture edits as revertible operations. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Row identity for the edit overlay — stable across a provider re-sort,\n * unlike an array index. Defaults to `(row) => row?.id`; a data provider\n * supplies its own (e.g. a PostgREST identity key). Used to re-attach edits\n * when the loader replaces `data` with a re-ordered window. */\n identity: (row: any) => string | number | null | undefined;\n /** Edits/statuses held by identity for rows not currently loaded (server\n * sources), re-attached when their row next arrives. */\n pendingOverlayById: Map<\n string | number,\n { edit?: any; status?: TableElementStatus }\n >;\n /** True when the consumer controls the `updatedData`/`rowStatus` overlay; the\n * loader-boundary identity remap is skipped (the consumer owns it). */\n controlledOverlay: boolean;\n /** Whether row deletion is available. Set from the data provider: an explicit\n * `provider` without `deleteRows` disables deletion entirely (the delete\n * affordance greys out and the delete key is a no-op). Defaults to `true`. */\n canDeleteRows: boolean;\n}\n\ntype DataSheetVals<T> = DataSheetState<T> & DataSheetCoreProps<T>;\nexport type StateUpdater<T> = T[] | ((state: T[]) => T[]);\n\nexport interface DataSheetStoreMain<T> extends DataSheetVals<T> {\n setSelection(selection: Region[]): void;\n onDragValue(event: MouseEvent): void;\n setUpdatedData(data: StateUpdater<T>): void;\n onCellEdited(rowIndex: number, columnName: string, value: any): void;\n onSelectionEdited(value: any): void;\n onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;\n onColumnWidthChanged(columnIndex: number, newWidth: number): void;\n moveFocusedCell(direction: NavDirection): void;\n /** Suppress auto-activation until the next click (Escape enters nav mode). */\n suppressAutoActivate(): void;\n /** Re-arm auto-activation (a click re-enables auto-focus). */\n armAutoActivate(): void;\n /** Open the focused cell's surface (editor or detail panel). */\n openCellSurface(): void;\n /** Close the focused cell's surface. When `suppress` is true (the default,\n * as for Escape), auto mode also enters navigation mode (auto-activation is\n * suppressed until the next click). A click-dismiss passes `suppress: false`\n * so it just closes without changing the global mode. */\n closeCellSurface(opts?: { suppress?: boolean }): void;\n deleteSelectedRows(): void;\n clearSelection(): void;\n resetChanges(): void;\n addRow(): void;\n /** Activate or update a column/table filter.\n * Filter is any object satisfying `TableFilter` from the actions module. */\n setFilter(filterId: string, filter: any, filterState: any): void;\n /** Remove a filter by ID */\n removeFilter(filterId: string): void;\n /** Remove all active filters */\n clearFilters(): void;\n /** Set or clear a column sort. Pass `null` for ascending to clear. */\n setColumnSort(key: string, ascending: boolean | null): void;\n /** Remove all active column sorts */\n clearColumnSorts(): void;\n /** Store a clipboard proxy for potential backend-mediated paste */\n setClipboardProxy(proxy: ClipboardProxy | null): void;\n initialize(props: Partial<DataSheetStoreMain<T>>): void;\n onSelection(selection: Region[]): void;\n // Internal method used for infinite scrolling\n scrollToRow(rowIndex: number): void;\n tableRef: React.MutableRefObject<Table2>;\n columnWidthsIndex: Map<string, number>;\n defaultColumnWidth: number;\n}\n\nexport type DataSheetProviderProps<T> = DataSheetCoreProps<T> & {\n children: React.ReactNode;\n columnSpecOptions?: ColumnSpecOptions<T>;\n toaster?: OverlayToaster;\n};\n\nexport interface VisibleCells {\n rowIndexStart: number;\n rowIndexEnd: number;\n}\n\nexport type DataSheetStore<T> = DataSheetStoreMain<T>;\n"],"names":["TableElementStatus"],"mappings":"AA0CO,IAAK,uCAAAA,wBAAL;AACLA,sBAAA,SAAA,IAAU;AACVA,sBAAA,OAAA,IAAQ;AAFE,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AAQL,MAAM,YAAY;"}
|
|
1
|
+
{"version":3,"file":"types.js","sources":["../src/types.ts"],"sourcesContent":["import type {\n FocusedCellCoordinates,\n Region,\n RegionCardinality,\n Table2,\n} from \"@blueprintjs/table\";\nimport { ColumnSpec, ColumnSpecOptions } from \"./utils\";\nimport { OverlayToaster } from \"@blueprintjs/core\";\nimport type { CellEdit } from \"./actions\";\n\n/** A single column sort entry for client-side sorting.\n * Defined here (rather than in actions/types) to avoid circular imports. */\nexport interface ColumnSort {\n key: string;\n ascending: boolean;\n}\n\n/** Direction of keyboard navigation between cells. */\nexport type NavDirection = \"up\" | \"down\" | \"left\" | \"right\";\n\n/**\n * A structured, revertible description of a user edit. Emitted via the\n * `onEdit` hook so a consumer can capture edits as operations (and, with the\n * controlled-overlay API, own the edited state) instead of diffing\n * `updatedData`. This is the write half of the data-sheet's read/write\n * contract — the mirror of how data flows in.\n */\nexport type EditEvent<T = any> =\n | { type: \"setCells\"; cells: CellEdit[] }\n | { type: \"deleteRows\"; rowIndices: number[] }\n | { type: \"restoreRows\"; rowIndices: number[] }\n | { type: \"addRow\"; rowIndex: number; value: Partial<T> }\n | { type: \"resetChanges\" };\n\nexport interface DataSheetCoreProps<T> {\n data: T[];\n columnSpec?: ColumnSpec[];\n editable?: boolean;\n enableColumnReordering?: boolean;\n defaultColumnWidth?: number;\n}\n\nexport enum TableElementStatus {\n DELETED = \"deleted\",\n ADDED = \"added\",\n}\n\n/** A row's status value. The built-in `TableElementStatus` members\n * (`\"deleted\"` / `\"added\"`) plus any consumer-defined status string (e.g.\n * `\"omitted\"`). The `(string & {})` keeps autocomplete for the enum members\n * while still accepting arbitrary strings. */\nexport type RowStatusValue = TableElementStatus | (string & {});\n\n/** Presentation for a row status: applied to the row's cells and its header\n * cell. Keyed by status value in `rowStatusStyles`. The library ships a\n * default for `\"deleted\"` (dimmed + struck through, danger intent); consumers\n * merge in styles for their own statuses (and may override the defaults). */\nexport interface RowStatusStyle {\n /** Style merged onto each cell in a row with this status. */\n cellStyle?: import(\"react\").CSSProperties;\n /** Style applied to the row's header cell. */\n headerStyle?: import(\"react\").CSSProperties;\n /** Blueprint intent applied to the row's cells (precedence: validation >\n * this > edited-green). */\n intent?: import(\"@blueprintjs/core\").Intent;\n}\n\nexport type RowStatusStyles = Record<string, RowStatusStyle>;\n\n/** Built-in row-status presentation. Consumers' `rowStatusStyles` are merged\n * over this, so `\"deleted\"` keeps its look unless explicitly overridden. */\nexport const DEFAULT_ROW_STATUS_STYLES: RowStatusStyles = {\n [TableElementStatus.DELETED]: {\n cellStyle: { opacity: 0.5, textDecoration: \"line-through\" },\n headerStyle: { opacity: 0.5, textDecoration: \"line-through\" },\n intent: \"danger\",\n },\n};\n\n/** Context passed to a custom `rowHeaderRenderer`, so it can label and style\n * the row header from the row's data and status (group-key labels, an\n * omit indicator, etc.). Return a node to use as the header's name, or a\n * nullish value to fall back to the default (1-based row number). */\nexport interface RowHeaderRenderContext<T = any> {\n /** Data-row index (stable under sort/filter). */\n rowIndex: number;\n /** Visible (display) row index. */\n visibleIndex: number;\n /** The row's data (base, overlaid with edits if present). */\n row: T | undefined;\n /** The row's status, if any. */\n status: RowStatusValue | undefined;\n /** Convenience: `status === TableElementStatus.DELETED`. */\n isDeleted: boolean;\n /** The default label (`\"${rowIndex + 1}\"`). */\n defaultLabel: string;\n}\n\n/** Property key holding a stable synthetic id on rows added in-table. Added\n * rows aren't in the data provider, so they need their own identity to survive\n * a provider re-fetch; it's carried on the row and preserved through edits. */\nexport const DS_ROW_ID = \"__dsRowId\";\n\n/** Proxy stored during a copy operation, enabling backend-mediated paste\n * for lazy-loaded tables where not all data is available locally. */\nexport interface ClipboardProxy {\n cardinality: RegionCardinality;\n /** Source row indices (for row/cell copies) */\n rowIndices?: number[];\n /** Source column keys (for column/cell copies) */\n columnKeys?: string[];\n /** The plain text written to the clipboard, used to verify the proxy\n * is still valid on paste (i.e., clipboard hasn't been overwritten). */\n text: string;\n}\n\nexport interface DataSheetState<T> {\n selection: Region[];\n columnSpec: ColumnSpec[];\n fillValueBaseCell: FocusedCellCoordinates | null;\n focusedCell: FocusedCellCoordinates | null;\n topLeftCell: FocusedCellCoordinates | null;\n /**\n * Set of row indices that have been added to the table,\n * but not yet committed to the underlying data array.\n *\n * This is used to track which rows should be reverted when\n * a \"reset\" action is performed.\n */\n rowStatus: RowStatusValue[];\n /** Presentation per row-status value (merged: defaults + the\n * `rowStatusStyles` prop). Read by the cell renderer and row-header renderer\n * to style rows by status. */\n rowStatusStyles: RowStatusStyles;\n // Sparse data structure for updated data\n updatedData: T[];\n initialized: boolean;\n columnWidthsIndex: Map<string, number>;\n /** Active column/table filters. Keys are filter IDs, values carry the\n * filter definition and its current configuration state. */\n activeFilters: Map<string, { filter: any; state: any }>;\n /** Clipboard proxy from the last copy operation */\n clipboardProxy: ClipboardProxy | null;\n /** Visible row indices when filters are active. `null` means show all rows. */\n filteredRowIndices: number[] | null;\n /** Active column sort entries for client-side sorting. */\n columnSorts: ColumnSort[];\n /** Whether selecting a cell automatically activates its surface (opens an\n * editor/detail panel and, for editors, focuses it). `\"manual\"` opens only\n * on click. */\n cellInteraction: \"auto\" | \"manual\";\n /** Runtime override of `cellInteraction`: while `false`, auto-activation is\n * suppressed (set by pressing Escape, re-armed by clicking a cell) so the\n * keyboard prioritizes navigation. */\n autoActivateArmed: boolean;\n /** Direction of the last keyboard navigation, used to place an editor's\n * cursor on the side the user is travelling toward. `null` after a click. */\n lastNavDirection: NavDirection | null;\n /** The table's focusable holder element; editors return focus here when the\n * cursor leaves them so arrow-key navigation resumes. */\n tableElement: HTMLElement | null;\n /** Whether the focused cell's surface (editor or detail panel) is open.\n * Owned by the store — not per-popover — so navigation, clicks, and the\n * Escape handler all agree on it. */\n cellSurfaceOpen: boolean;\n /** Optional observer called for every user edit as a structured\n * `EditEvent`, in addition to the built-in `updatedData` overlay. Lets a\n * consumer capture edits as revertible operations. */\n onEdit?: (event: EditEvent<T>) => void;\n /** Row identity for the edit overlay — stable across a provider re-sort,\n * unlike an array index. Defaults to `(row) => row?.id`; a data provider\n * supplies its own (e.g. a PostgREST identity key). Used to re-attach edits\n * when the loader replaces `data` with a re-ordered window. */\n identity: (row: any) => string | number | null | undefined;\n /** Edits/statuses held by identity for rows not currently loaded (server\n * sources), re-attached when their row next arrives. */\n pendingOverlayById: Map<\n string | number,\n { edit?: any; status?: TableElementStatus }\n >;\n /** True when the consumer controls the `updatedData`/`rowStatus` overlay; the\n * loader-boundary identity remap is skipped (the consumer owns it). */\n controlledOverlay: boolean;\n /** Whether row deletion is available. Set from the data provider: an explicit\n * `provider` without `deleteRows` disables deletion entirely (the delete\n * affordance greys out and the delete key is a no-op). Defaults to `true`. */\n canDeleteRows: boolean;\n}\n\ntype DataSheetVals<T> = DataSheetState<T> & DataSheetCoreProps<T>;\nexport type StateUpdater<T> = T[] | ((state: T[]) => T[]);\n\nexport interface DataSheetStoreMain<T> extends DataSheetVals<T> {\n setSelection(selection: Region[]): void;\n onDragValue(event: MouseEvent): void;\n setUpdatedData(data: StateUpdater<T>): void;\n onCellEdited(rowIndex: number, columnName: string, value: any): void;\n onSelectionEdited(value: any): void;\n onColumnsReordered(oldIndex: number, newIndex: number, length: number): void;\n onColumnWidthChanged(columnIndex: number, newWidth: number): void;\n moveFocusedCell(direction: NavDirection): void;\n /** Suppress auto-activation until the next click (Escape enters nav mode). */\n suppressAutoActivate(): void;\n /** Re-arm auto-activation (a click re-enables auto-focus). */\n armAutoActivate(): void;\n /** Open the focused cell's surface (editor or detail panel). */\n openCellSurface(): void;\n /** Close the focused cell's surface. When `suppress` is true (the default,\n * as for Escape), auto mode also enters navigation mode (auto-activation is\n * suppressed until the next click). A click-dismiss passes `suppress: false`\n * so it just closes without changing the global mode. */\n closeCellSurface(opts?: { suppress?: boolean }): void;\n deleteSelectedRows(): void;\n clearSelection(): void;\n resetChanges(): void;\n addRow(): void;\n /** Activate or update a column/table filter.\n * Filter is any object satisfying `TableFilter` from the actions module. */\n setFilter(filterId: string, filter: any, filterState: any): void;\n /** Remove a filter by ID */\n removeFilter(filterId: string): void;\n /** Remove all active filters */\n clearFilters(): void;\n /** Set or clear a column sort. Pass `null` for ascending to clear. */\n setColumnSort(key: string, ascending: boolean | null): void;\n /** Remove all active column sorts */\n clearColumnSorts(): void;\n /** Store a clipboard proxy for potential backend-mediated paste */\n setClipboardProxy(proxy: ClipboardProxy | null): void;\n initialize(props: Partial<DataSheetStoreMain<T>>): void;\n onSelection(selection: Region[]): void;\n // Internal method used for infinite scrolling\n scrollToRow(rowIndex: number): void;\n tableRef: React.MutableRefObject<Table2>;\n columnWidthsIndex: Map<string, number>;\n defaultColumnWidth: number;\n}\n\nexport type DataSheetProviderProps<T> = DataSheetCoreProps<T> & {\n children: React.ReactNode;\n columnSpecOptions?: ColumnSpecOptions<T>;\n toaster?: OverlayToaster;\n};\n\nexport interface VisibleCells {\n rowIndexStart: number;\n rowIndexEnd: number;\n}\n\nexport type DataSheetStore<T> = DataSheetStoreMain<T>;\n"],"names":["TableElementStatus"],"mappings":"AA0CO,IAAK,uCAAAA,wBAAL;AACLA,sBAAA,SAAA,IAAU;AACVA,sBAAA,OAAA,IAAQ;AAFE,SAAAA;AAAA,GAAA,sBAAA,CAAA,CAAA;AA6BL,MAAM,4BAA6C;AAAA,EACxD;AAAA,IAAC;AAAA;AAAA,KAA6B;AAAA,IAC5B,WAAW,EAAE,SAAS,KAAK,gBAAgB,eAAA;AAAA,IAC3C,aAAa,EAAE,SAAS,KAAK,gBAAgB,eAAA;AAAA,IAC7C,QAAQ;AAAA,EAAA;AAEZ;AAwBO,MAAM,YAAY;"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-spec.cjs","sources":["../../src/utils/column-spec.ts"],"sourcesContent":["import React from \"react\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (\n d: any,\n ctx?: CellRenderContext,\n ) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec = [];\n for (const key of keys) {\n let width = null;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: ColumnSpecOptions<T>,\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const {\n overrides = {},\n nRows = 10,\n omitColumns,\n includeColumns,\n } = options ?? {};\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n return filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n}\n"],"names":[],"mappings":";;AAEA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AAoKpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EAAA,IACjB;AAEJ,QAAM,2BAAW,IAAA;AACjB,QAAM,4BAAY,IAAA;AAElB,QA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AAAA,MAAA;AAAA,IAEnB;AAEA,UAAM,WAAY,MAAM,IAAI,GAAG,KAAK;AAKpC,UAAM,WACJ,aAAa,UACb,aAAa,YACb,aAAa,YACb,aAAa,aACb,aAAa;AAEf,SAAK,KAAK;AAAA,MACR,MAAM;AAAA,MACN;AAAA,MACA,eAAe,iBAAiB,MAAM,IAAI,GAAG,CAAC;AAAA,MAC9C;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV,YAAY;AAAA,IAAA,CACb;AAAA,EACH;AACA,SAAO;AACT;AAEO,SAAS,mBACd,MACA,SACc;AAEd,QAAM;AAAA,IACJ,YAAY,CAAA;AAAA,IACZ,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EAAA,IACE,WAAW,CAAA;AAEf,MAAI,QAAQ,KAAM,QAAO,CAAA;AAEzB,QAAM,SAAS,KAAK,IAAI,OAAO,KAAK,MAAM;AAE1C,MAAI,aAAa,0BAA0B,KAAK,MAAM,GAAG,MAAM,CAAC;AAChE,MAAI,eAAe,WAAW,OAAO,CAAC,QAAQ;AAC5C,QAAI,eAAe,QAAQ,YAAY,SAAS,IAAI,GAAG,GAAG;AACxD,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ,CAAC,eAAe,SAAS,IAAI,GAAG,GAAG;AAC/D,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AAGD,SAAO,aAAa,IAAI,CAAC,QAAQ;AAC/B,QAAI,MAAM,UAAU,IAAI,GAAG;AAC3B,QAAI,OAAO,KAAM,QAAO;AACxB,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,EAAE,GAAG,KAAK,MAAM,IAAA;AAAA,IACzB;AACA,WAAO,EAAE,GAAG,KAAK,GAAG,IAAA;AAAA,EACtB,CAAC;AACH;;;"}
|
|
1
|
+
{"version":3,"file":"column-spec.cjs","sources":["../../src/utils/column-spec.ts"],"sourcesContent":["import React from \"react\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (\n d: any,\n ctx?: CellRenderContext,\n ) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec = [];\n for (const key of keys) {\n let width = null;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: ColumnSpecOptions<T>,\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const {\n overrides = {},\n nRows = 10,\n omitColumns,\n includeColumns,\n } = options ?? {};\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n return filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n}\n"],"names":[],"mappings":";;AAEA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AAwKpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EAAA,IACjB;AAEJ,QAAM,2BAAW,IAAA;AACjB,QAAM,4BAAY,IAAA;AAElB,QAAM,mCAAmB,IAAA;AAEzB,aAAW,OAAO,MAAM;AACtB,QAAI,OAAO,KAAM;AACjB,eAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAM,MAAM,IAAI,GAAG;AACnB,WAAK,IAAI,GAAG;AAEZ,UAAI,OAAO,KAAM;AAEjB,UAAI,iBAAiB;AACnB,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I,GAAG,CAAC;AAAA,MAC9C;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV,YAAY;AAAA,IAAA,CACb;AAAA,EACH;AACA,SAAO;AACT;AAEO,SAAS,mBACd,MACA,SACc;AAEd,QAAM;AAAA,IACJ,YAAY,CAAA;AAAA,IACZ,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EAAA,IACE,WAAW,CAAA;AAEf,MAAI,QAAQ,KAAM,QAAO,CAAA;AAEzB,QAAM,SAAS,KAAK,IAAI,OAAO,KAAK,MAAM;AAE1C,MAAI,aAAa,0BAA0B,KAAK,MAAM,GAAG,MAAM,CAAC;AAChE,MAAI,eAAe,WAAW,OAAO,CAAC,QAAQ;AAC5C,QAAI,eAAe,QAAQ,YAAY,SAAS,IAAI,GAAG,GAAG;AACxD,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ,CAAC,eAAe,SAAS,IAAI,GAAG,GAAG;AAC/D,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AAGD,SAAO,aAAa,IAAI,CAAC,QAAQ;AAC/B,QAAI,MAAM,UAAU,IAAI,GAAG;AAC3B,QAAI,OAAO,KAAM,QAAO;AACxB,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,EAAE,GAAG,KAAK,MAAM,IAAA;AAAA,IACzB;AACA,WAAO,EAAE,GAAG,KAAK,GAAG,IAAA;AAAA,EACtB,CAAC;AACH;;;"}
|
|
@@ -39,6 +39,10 @@ export interface CellRenderContext<T = any> {
|
|
|
39
39
|
isEdited: boolean;
|
|
40
40
|
/** Whether this cell's row is marked for deletion. */
|
|
41
41
|
isDeleted: boolean;
|
|
42
|
+
/** The row's status value (`RowStatusValue`) — `"deleted"` / `"added"` or a
|
|
43
|
+
* consumer-defined status (e.g. `"omitted"`), or `undefined` for a normal
|
|
44
|
+
* row. Lets a renderer style by arbitrary status, not just deletion. */
|
|
45
|
+
status: string | undefined;
|
|
42
46
|
/** Validation result for this cell, or `null` when valid. Orthogonal to the
|
|
43
47
|
* edit status — a cell can be both edited and invalid. */
|
|
44
48
|
validation: CellValidation | null;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"column-spec.js","sources":["../../src/utils/column-spec.ts"],"sourcesContent":["import React from \"react\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (\n d: any,\n ctx?: CellRenderContext,\n ) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec = [];\n for (const key of keys) {\n let width = null;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: ColumnSpecOptions<T>,\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const {\n overrides = {},\n nRows = 10,\n omitColumns,\n includeColumns,\n } = options ?? {};\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n return filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n}\n"],"names":[],"mappings":"AAEA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AAoKpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EAAA,IACjB;AAEJ,QAAM,2BAAW,IAAA;AACjB,QAAM,4BAAY,IAAA;AAElB,QAAM,mCAAmB,IAAA;AAEzB,aAAW,OAAO,MAAM;AACtB,QAAI,OAAO,KAAM;AACjB,eAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAM,MAAM,IAAI,GAAG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Ef,SAAK,KAAK;AAAA,MACR,MAAM;AAAA,MACN;AAAA,MACA,eAAe,iBAAiB,MAAM,IAAI,GAAG,CAAC;AAAA,MAC9C;AAAA,MACA;AAAA,MACA,UAAU;AAAA,MACV,YAAY;AAAA,IAAA,CACb;AAAA,EACH;AACA,SAAO;AACT;AAEO,SAAS,mBACd,MACA,SACc;AAEd,QAAM;AAAA,IACJ,YAAY,CAAA;AAAA,IACZ,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EAAA,IACE,WAAW,CAAA;AAEf,MAAI,QAAQ,KAAM,QAAO,CAAA;AAEzB,QAAM,SAAS,KAAK,IAAI,OAAO,KAAK,MAAM;AAE1C,MAAI,aAAa,0BAA0B,KAAK,MAAM,GAAG,MAAM,CAAC;AAChE,MAAI,eAAe,WAAW,OAAO,CAAC,QAAQ;AAC5C,QAAI,eAAe,QAAQ,YAAY,SAAS,IAAI,GAAG,GAAG;AACxD,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ,CAAC,eAAe,SAAS,IAAI,GAAG,GAAG;AAC/D,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AAGD,SAAO,aAAa,IAAI,CAAC,QAAQ;AAC/B,QAAI,MAAM,UAAU,IAAI,GAAG;AAC3B,QAAI,OAAO,KAAM,QAAO;AACxB,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,EAAE,GAAG,KAAK,MAAM,IAAA;AAAA,IACzB;AACA,WAAO,EAAE,GAAG,KAAK,GAAG,IAAA;AAAA,EACtB,CAAC;AACH;"}
|
|
1
|
+
{"version":3,"file":"column-spec.js","sources":["../../src/utils/column-spec.ts"],"sourcesContent":["import React from \"react\";\n\nconst defaultRenderers = {\n string: (d) => d,\n number: (d) => d?.toFixed(2),\n boolean: (d) => (d ? \"T\" : \"F\"),\n object: (d) => JSON.stringify(d),\n integer: (d) => d?.toFixed(0),\n array: (d) => d?.join(\", \"),\n};\n\ninterface ColumnSpecGenerateOptions {\n calculateWidths?: boolean;\n defaultWidth?: number;\n getWidthForValue?: (value: any) => number;\n}\n\nconst defaultWidthForValue = (val) => String(val).length * 8;\n\n/** Inferred data type of a column, used to select appropriate\n * sort/filter operators. */\nexport type ColumnDataType =\n | \"text\"\n | \"string\"\n | \"number\"\n | \"integer\"\n | \"boolean\"\n | \"object\"\n | \"array\";\n\n/** Severity of a cell validation result. `warning` is soft (flagged, doesn't\n * block saving); `error` is hard (blocks saving). */\nexport type ValidationSeverity = \"warning\" | \"error\";\n\n/** The result of validating a cell. `null` means valid. */\nexport interface CellValidation {\n severity: ValidationSeverity;\n message?: string;\n}\n\n/**\n * Context handed to per-cell renderers (`valueRenderer`, and — as the\n * `cellContext` prop — a custom `cellComponent`). It lets a renderer draw\n * based on the row/column position and the cell's edit status, and, combined\n * with the editing API, write edits back for a specific cell.\n *\n * `rowIndex` is the underlying **data-row index** (the value edit methods\n * expect), so it stays stable when a sort or filter reorders the view.\n */\nexport interface CellRenderContext<T = any> {\n /** The cell's current value (the edited value if present, else the base). */\n value: any;\n /** Underlying data-row index — stable under sort/filter. */\n rowIndex: number;\n /** Column index within the active column spec. */\n colIndex: number;\n /** The full column spec for this cell's column. */\n column: ColumnSpec;\n /** The full row object backing this cell (may be undefined while loading). */\n row: T | undefined;\n /** Whether this cell has an uncommitted edit. */\n isEdited: boolean;\n /** Whether this cell's row is marked for deletion. */\n isDeleted: boolean;\n /** The row's status value (`RowStatusValue`) — `\"deleted\"` / `\"added\"` or a\n * consumer-defined status (e.g. `\"omitted\"`), or `undefined` for a normal\n * row. Lets a renderer style by arbitrary status, not just deletion. */\n status: string | undefined;\n /** Validation result for this cell, or `null` when valid. Orthogonal to the\n * edit status — a cell can be both edited and invalid. */\n validation: CellValidation | null;\n}\n\n/**\n * The editor configuration for a cell. Mirrors the static `dataEditor` /\n * `inlineEditor` column fields so a per-cell resolver (`editorForCell`) can\n * override either one for an individual cell.\n */\nexport interface CellEditors {\n dataEditor?: any;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n}\n\n/**\n * Context for a cell's detail surface (`cellDetail`). Extends the render\n * context with the edit affordances and controls a surface needs, so one\n * component can act as an editor (when `editable`) or a read-only viewer\n * (otherwise). This is the write side of the read/write contract, per-cell.\n */\nexport interface CellDetailContext<T = any> extends CellRenderContext<T> {\n /** Whether this cell is editable (column × table × not-deleted). */\n editable: boolean;\n /** Commit a new value for this cell. */\n onChange: (value: any) => void;\n /** Reset this cell (and selection) to its base value. */\n resetValue: () => void;\n /** Close the surface and return focus to the table. */\n close: () => void;\n}\n\n/** How a cell's detail surface is presented. Orthogonal to what it renders. */\nexport type DetailPresentation = \"popover\" | \"modal\" | \"inline\";\n\nexport interface ColumnSpec {\n name: string;\n key: string;\n /** When true, an empty value is an error (sugar over `validate`). */\n required?: boolean;\n /** Validate a cell's value. Return a `{ severity, message }` for a\n * warning/error, or `null` when valid. Runs after the `required` check.\n * `warning` flags the cell but allows saving; `error` blocks saving. */\n validate?: (\n value: any,\n row: any,\n ctx: { rowIndex: number },\n ) => CellValidation | null;\n /** @deprecated Prefer `validate`, which carries severity + a message.\n * A falsy result maps to an `error`. */\n isValid?: (d: any) => boolean;\n transformValue?: (d: any) => any;\n valueRenderer?: (\n d: any,\n ctx?: CellRenderContext,\n ) => string | React.ReactNode;\n headerRenderer?: (d: any) => string | React.ReactNode;\n dataEditor?: any;\n /**\n * Choose the editor for an individual cell from its render context,\n * overriding the static `dataEditor` / `inlineEditor` for that cell. Return\n * `undefined` (or omit a key) to fall back to the static configuration —\n * e.g. show a textarea only for cells whose value is long. A returned key is\n * respected even when its value is `false`/`null` (i.e. \"no editor here\").\n */\n editorForCell?: (ctx: CellRenderContext) => CellEditors | undefined;\n /**\n * Render a read-only detail panel for a cell. When set, selecting the cell\n * opens a popover with this content (following the table's `cellInteraction`\n * mode). The panel never takes keyboard focus, so arrow keys keep navigating\n * the table; Escape closes it. Mutually distinct from `dataEditor` — use this\n * for non-editable surfaces (previews, summaries, links).\n *\n * @deprecated Prefer `cellDetail`, which unifies editor and viewer.\n */\n detailRenderer?: (ctx: CellRenderContext) => React.ReactNode;\n /**\n * The unified cell surface (Workstream A): one renderer that acts as an\n * editor when `ctx.editable` and a read-only viewer otherwise, superseding\n * `dataEditor` / `detailRenderer` / `editorForCell`. Presentation is chosen\n * separately via `detailPresentation` (popover / modal / inline), so the\n * same component works in any container.\n */\n cellDetail?: (ctx: CellDetailContext) => React.ReactNode;\n /** How `cellDetail` is presented. Defaults to `\"popover\"`. */\n detailPresentation?: DetailPresentation;\n cellComponent?: any;\n category?: string;\n editable?: boolean;\n inlineEditor?: boolean | React.ComponentType<any> | string | null;\n style?: React.CSSProperties;\n width?: number;\n /** Column-specific table actions (TableAction[]). These appear in the\n * actions toolbar when this column is part of the current selection. */\n actions?: any[];\n /** Column-specific table filters (TableFilter[]). These appear in the\n * filter bar and apply to this column's values. */\n filters?: any[];\n /** Whether this column supports server-side sorting. */\n sortable?: boolean;\n /** Whether this column supports server-side filtering.\n * Set to `true` for default operators, or provide a config object\n * with a custom set of operators. */\n filterable?: boolean | { operators?: string[] };\n /** Inferred data type, used to select context-appropriate filter\n * operators when `filterable` is `true` without explicit operators. */\n dataType?: ColumnDataType;\n}\n\nexport interface ColumnSpecOptions<T> {\n overrides: Record<string, Partial<ColumnSpec> | string>;\n data?: T[]; // Data to use for type inference\n nRows?: number; // Number of rows to use for type inference\n omitColumns?: string[]; // Columns to omit. Takes precedence over includeColumns.\n includeColumns?: string[]; // Columns to include.\n}\n\nexport function generateDefaultColumnSpec<T>(\n data: Array<T>,\n options: ColumnSpecGenerateOptions = {},\n): ColumnSpec[] {\n /** Build a default column spec from a dataset based on the first n rows */\n if (data == null) return [];\n // Get the keys\n\n const {\n defaultWidth = 150,\n calculateWidths = true,\n getWidthForValue = defaultWidthForValue,\n } = options;\n\n const keys = new Set<string>();\n const types = new Map();\n\n const columnWidths = new Map<string, number>();\n\n for (const row of data) {\n if (row == null) continue;\n for (const key of Object.keys(row)) {\n const val = row[key];\n keys.add(key);\n\n if (val == null) continue;\n\n if (calculateWidths) {\n let width = getWidthForValue(val);\n if (width != null && width >= 0) {\n columnWidths.set(key, Math.max(width, columnWidths.get(key) ?? 0));\n }\n }\n\n let type: string = typeof val;\n // Special 'type' for integers\n if (Number.isInteger(val)) {\n type = \"integer\";\n }\n\n // Special 'type' for arrays of simple values\n if (\n Array.isArray(val) &&\n val.every((d) => typeof d === \"string\" || typeof d === \"number\")\n ) {\n type = \"array\";\n }\n\n // Check if it is strictly a string, if so, we can explicitly mark it as text\n if (type === \"string\") {\n type = \"text\";\n }\n\n if (types.has(key)) {\n if (types.get(key) !== type) {\n if (type === \"number\" && types.get(key) === \"integer\") {\n types.set(key, \"number\");\n }\n if (type === \"object\" && types.get(key) === \"array\") {\n types.set(key, \"object\");\n }\n\n types.set(key, \"string\");\n }\n } else {\n types.set(key, type);\n }\n }\n }\n\n // Build a column spec\n const spec = [];\n for (const key of keys) {\n let width = null;\n if (calculateWidths) {\n // If we are calculating widths, use the value lengths\n width = Math.min(\n Math.max(defaultWidth / 2, columnWidths.get(key) ?? defaultWidth),\n defaultWidth * 1.5,\n );\n }\n\n const dataType = (types.get(key) ?? \"string\") as ColumnDataType;\n\n // Auto-infer sortable/filterable based on data type.\n // Scalar types (string, number, integer, boolean) get sort/filter;\n // complex types (object, array) do not.\n const isScalar =\n dataType === \"text\" ||\n dataType === \"string\" ||\n dataType === \"number\" ||\n dataType === \"integer\" ||\n dataType === \"boolean\";\n\n spec.push({\n name: key,\n key,\n valueRenderer: defaultRenderers[types.get(key)],\n width,\n dataType,\n sortable: isScalar,\n filterable: isScalar,\n });\n }\n return spec;\n}\n\nexport function generateColumnSpec<T>(\n data: T[],\n options: ColumnSpecOptions<T>,\n): ColumnSpec[] {\n /** Generate a column spec from a dataset */\n const {\n overrides = {},\n nRows = 10,\n omitColumns,\n includeColumns,\n } = options ?? {};\n\n if (data == null) return [];\n\n const _nRows = Math.min(nRows, data.length);\n\n let columnSpec = generateDefaultColumnSpec(data.slice(0, _nRows));\n let filteredSpec = columnSpec.filter((col) => {\n if (omitColumns != null && omitColumns.includes(col.key)) {\n return false;\n }\n if (includeColumns != null && !includeColumns.includes(col.key)) {\n return false;\n }\n return true;\n });\n\n // Apply overrides\n return filteredSpec.map((col) => {\n let ovr = overrides[col.key];\n if (ovr == null) return col;\n if (typeof ovr === \"string\") {\n return { ...col, name: ovr };\n }\n return { ...col, ...ovr };\n });\n}\n"],"names":[],"mappings":"AAEA,MAAM,mBAAmB;AAAA,EACvB,QAAQ,CAAC,MAAM;AAAA,EACf,QAAQ,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC3B,SAAS,CAAC,MAAO,IAAI,MAAM;AAAA,EAC3B,QAAQ,CAAC,MAAM,KAAK,UAAU,CAAC;AAAA,EAC/B,SAAS,CAAC,MAAM,GAAG,QAAQ,CAAC;AAAA,EAC5B,OAAO,CAAC,MAAM,GAAG,KAAK,IAAI;AAC5B;AAQA,MAAM,uBAAuB,CAAC,QAAQ,OAAO,GAAG,EAAE,SAAS;AAwKpD,SAAS,0BACd,MACA,UAAqC,IACvB;AAEd,MAAI,QAAQ,KAAM,QAAO,CAAA;AAGzB,QAAM;AAAA,IACJ,eAAe;AAAA,IACf,kBAAkB;AAAA,IAClB,mBAAmB;AAAA,EAAA,IACjB;AAEJ,QAAM,2BAAW,IAAA;AACjB,QAAM,4BAAY,IAAA;AAElB,QAAM,mCAAmB,IAAA;AAEzB,aAAW,OAAO,MAAM;AACtB,QAAI,OAAO,KAAM;AACjB,eAAW,OAAO,OAAO,KAAK,GAAG,GAAG;AAClC,YAAM,MAAM,IAAI,GAAG;AACnB,WAAK,IAAI,GAAG;AAEZ,UAAI,OAAO,KAAM;AAEjB,UAAI,iBAAiB;AACnB,YAAI,QAAQ,iBAAiB,GAAG;AAChC,YAAI,SAAS,QAAQ,SAAS,GAAG;AAC/B,uBAAa,IAAI,KAAK,KAAK,IAAI,OAAO,aAAa,IAAI,GAAG,KAAK,CAAC,CAAC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AEd,QAAM;AAAA,IACJ,YAAY,CAAA;AAAA,IACZ,QAAQ;AAAA,IACR;AAAA,IACA;AAAA,EAAA,IACE,WAAW,CAAA;AAEf,MAAI,QAAQ,KAAM,QAAO,CAAA;AAEzB,QAAM,SAAS,KAAK,IAAI,OAAO,KAAK,MAAM;AAE1C,MAAI,aAAa,0BAA0B,KAAK,MAAM,GAAG,MAAM,CAAC;AAChE,MAAI,eAAe,WAAW,OAAO,CAAC,QAAQ;AAC5C,QAAI,eAAe,QAAQ,YAAY,SAAS,IAAI,GAAG,GAAG;AACxD,aAAO;AAAA,IACT;AACA,QAAI,kBAAkB,QAAQ,CAAC,eAAe,SAAS,IAAI,GAAG,GAAG;AAC/D,aAAO;AAAA,IACT;AACA,WAAO;AAAA,EACT,CAAC;AAGD,SAAO,aAAa,IAAI,CAAC,QAAQ;AAC/B,QAAI,MAAM,UAAU,IAAI,GAAG;AAC3B,QAAI,OAAO,KAAM,QAAO;AACxB,QAAI,OAAO,QAAQ,UAAU;AAC3B,aAAO,EAAE,GAAG,KAAK,MAAM,IAAA;AAAA,IACzB;AACA,WAAO,EAAE,GAAG,KAAK,GAAG,IAAA;AAAA,EACtB,CAAC;AACH;"}
|
package/dist/zustand-store.cjs
CHANGED
|
@@ -14,6 +14,7 @@ function createZustandStore(set, get) {
|
|
|
14
14
|
data: [],
|
|
15
15
|
updatedData: [],
|
|
16
16
|
rowStatus: [],
|
|
17
|
+
rowStatusStyles: types.DEFAULT_ROW_STATUS_STYLES,
|
|
17
18
|
columnSpec: [],
|
|
18
19
|
defaultColumnWidth: 150,
|
|
19
20
|
editable: false,
|
|
@@ -207,7 +208,9 @@ function createZustandStore(set, get) {
|
|
|
207
208
|
if (get().editable) {
|
|
208
209
|
get().onEdit?.({
|
|
209
210
|
type: "setCells",
|
|
210
|
-
cells: [
|
|
211
|
+
cells: [
|
|
212
|
+
{ rowIndex, column: columnName, value, row: get().data[rowIndex] }
|
|
213
|
+
]
|
|
211
214
|
});
|
|
212
215
|
}
|
|
213
216
|
},
|
|
@@ -231,7 +234,7 @@ function createZustandStore(set, get) {
|
|
|
231
234
|
const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];
|
|
232
235
|
if (currentValue != null && currentValue !== "") {
|
|
233
236
|
vals[key] = "";
|
|
234
|
-
edits.push({ rowIndex: row, column: key, value: "" });
|
|
237
|
+
edits.push({ rowIndex: row, column: key, value: "", row: data[row] });
|
|
235
238
|
}
|
|
236
239
|
}
|
|
237
240
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
@@ -286,7 +289,7 @@ function createZustandStore(set, get) {
|
|
|
286
289
|
for (const col of colRange) {
|
|
287
290
|
const key = columnSpec[col].key;
|
|
288
291
|
vals[key] = value;
|
|
289
|
-
edits.push({ rowIndex: row, column: key, value });
|
|
292
|
+
edits.push({ rowIndex: row, column: key, value, row: state.data[row] });
|
|
290
293
|
}
|
|
291
294
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
292
295
|
spec[row] = { [op]: vals };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"zustand-store.cjs","sources":["../src/zustand-store.ts"],"sourcesContent":["import {\n DataSheetState,\n DataSheetStore,\n DataSheetStoreMain,\n DS_ROW_ID,\n StateUpdater,\n TableElementStatus,\n VisibleCells,\n} from \"./types.ts\";\nimport {\n type FocusedCellCoordinates,\n type Region,\n RegionCardinality,\n} from \"@blueprintjs/table\";\nimport { range } from \"./utils\";\nimport update, { Spec } from \"immutability-helper\";\nimport {\n getSelectedColumnKeys,\n getSelectedRowIndices,\n getSelectionCardinality,\n} from \"./actions\";\n\n/** Monotonic counter for synthetic ids on in-table-added rows. */\nlet _addedRowCounter = 0;\n\nexport function createZustandStore<T>(set, get): DataSheetStoreMain<T> {\n return {\n /** All the data in the table */\n data: [],\n updatedData: [],\n rowStatus: [],\n columnSpec: [],\n defaultColumnWidth: 150,\n editable: false,\n selection: [],\n fillValueBaseCell: null,\n focusedCell: null,\n topLeftCell: null,\n initialized: false,\n tableRef: null,\n // This is a placeholder\n enableColumnReordering: false,\n activeFilters: new Map<string, { filter: any; state: any }>(),\n columnSorts: [],\n clipboardProxy: null,\n filteredRowIndices: null,\n cellInteraction: \"auto\",\n autoActivateArmed: true,\n lastNavDirection: null,\n tableElement: null,\n cellSurfaceOpen: false,\n identity: (row: any) => row?.id,\n pendingOverlayById: new Map(),\n controlledOverlay: false,\n canDeleteRows: true,\n setSelection(selection: Region[]) {\n set(updateSelection(selection));\n },\n columnWidthsIndex: new Map<string, number>(),\n suppressAutoActivate() {\n set({ autoActivateArmed: false });\n },\n armAutoActivate() {\n set({ autoActivateArmed: true });\n },\n openCellSurface() {\n set({ cellSurfaceOpen: true });\n },\n closeCellSurface(opts?: { suppress?: boolean }) {\n const suppress = opts?.suppress ?? true;\n set((state) => ({\n cellSurfaceOpen: false,\n // Escape (suppress) drops auto mode into navigation mode so surfaces\n // stop auto-opening until the next click. A click-dismiss doesn't.\n autoActivateArmed:\n suppress && state.cellInteraction === \"auto\"\n ? false\n : state.autoActivateArmed,\n }));\n },\n moveFocusedCell(direction: \"up\" | \"down\" | \"left\" | \"right\") {\n set((state) => {\n const { topLeftCell } = state;\n if (topLeftCell == null) return {};\n let { col, row } = topLeftCell;\n switch (direction) {\n case \"up\":\n row = Math.max(0, row - 1);\n break;\n case \"down\":\n row = Math.min(\n row + 1,\n Math.max(state.data.length, state.updatedData.length) - 1,\n );\n break;\n case \"left\":\n col = Math.max(0, col - 1);\n break;\n case \"right\":\n col = Math.min(col + 1, state.columnSpec.length - 1);\n break;\n }\n const region: Region = { cols: [col, col], rows: [row, row] };\n // Record the travel direction (so the next editor places its cursor on\n // the side we're moving toward) and open the new cell's surface only\n // when auto-activation is armed.\n return {\n ...updateSelection([region]),\n lastNavDirection: direction,\n cellSurfaceOpen:\n state.cellInteraction === \"auto\" && state.autoActivateArmed,\n };\n });\n },\n addRow(row: Partial<T> = {} as T) {\n /** Add a new row. If there is a selection, use the last row index to determine\n * where to insert the new row. Otherwise, append to the end of the data. */\n let newIndex = -1;\n set((state) => {\n const { updatedData, data, selection, rowStatus } = state;\n\n const lastRowIndex =\n getLastRowIndex(selection) ??\n Math.max(data.length, updatedData.length) - 1;\n // Use $set at a specific index to correctly extend the sparse array.\n // $splice fails when the target index exceeds the array length.\n newIndex = lastRowIndex + 1;\n\n // Stamp a stable synthetic id so the added row survives a provider\n // re-fetch (it has no provider row to match on). Its values live in the\n // overlay (`updatedData`), which the loader-boundary remap re-appends.\n const newRow = {\n ...(row as any),\n [DS_ROW_ID]: `__added_${_addedRowCounter++}`,\n } as T;\n\n return {\n updatedData: insertItemAtIndex(updatedData, newIndex, newRow),\n data: insertItemAtIndex(data, newIndex, newRow),\n rowStatus: insertItemAtIndex(\n rowStatus,\n newIndex,\n TableElementStatus.ADDED,\n ),\n };\n });\n get().onEdit?.({ type: \"addRow\", rowIndex: newIndex, value: row });\n },\n setUpdatedData(data: StateUpdater<T>) {\n if (Array.isArray(data)) {\n set({ updatedData: data });\n } else {\n set((state) => {\n return { updatedData: data(state.updatedData) };\n });\n }\n },\n deleteSelectedRows() {\n // Deletion is a provider capability: if the active data provider can't\n // delete (no `deleteRows`), the whole affordance is disabled.\n if (!get().canDeleteRows) return;\n // Remove selected rows from the data and updatedData arrays\n let deletedIndices: number[] = [];\n set((state) => {\n const { selection, deletedRows } = state;\n const rowIndices = getRowIndices(selection);\n deletedIndices = rowIndices;\n\n // Delete rows from both updatedData and data\n\n // If rows are in addedRows, we just delete them outright from the data and updatedData arrays\n const { addedRows } = state;\n\n const rowsNewlyDeleted = new Set(rowIndices);\n\n // We outright remove rows that have not been added to the data array\n const rowsToRemoveFromDataArrays = new Set(\n rowIndices.filter(\n (d) => state.rowStatus[d] == TableElementStatus.ADDED,\n ),\n );\n // ...otherwise we set them to 'deleted'\n const rowsToMarkAsDeleted = rowsNewlyDeleted.difference(\n rowsToRemoveFromDataArrays,\n );\n\n let data = state.data;\n let updatedData = state.updatedData;\n let rowStatus = state.rowStatus;\n if (rowsToMarkAsDeleted.size > 0) {\n let spec: Spec<TableElementStatus[]> = {};\n for (const ix of rowsToMarkAsDeleted) {\n spec[ix] = { $set: TableElementStatus.DELETED };\n }\n rowStatus = update(rowStatus, spec);\n }\n\n if (rowsToRemoveFromDataArrays.size > 0) {\n const filterFunc = (_, i) => !rowsToRemoveFromDataArrays.has(i);\n data = data.filter(filterFunc);\n updatedData = updatedData.filter(filterFunc);\n rowStatus = rowStatus.filter(filterFunc);\n }\n\n // Remove selected rows and reset selection\n return {\n selection: [],\n data,\n updatedData,\n rowStatus,\n focusedCell: null,\n topLeftCell: null,\n fillValueBaseCell: null,\n };\n });\n if (deletedIndices.length > 0) {\n get().onEdit?.({ type: \"deleteRows\", rowIndices: deletedIndices });\n }\n },\n resetChanges(regions?: Region[]) {\n // Reset the updated data to the initial data\n set((state) => resetChangesForSelection(state, regions));\n get().onEdit?.({ type: \"resetChanges\" });\n },\n onColumnWidthChanged(columnIx: number, newWidth: number) {\n set((state) => {\n const { columnSpec, columnWidthsIndex } = state;\n const colKey = columnSpec[columnIx].key;\n const newColumnWidths = new Map(columnWidthsIndex);\n newColumnWidths.set(colKey, newWidth);\n return { columnWidthsIndex: newColumnWidths };\n });\n },\n onDragValue(event: MouseEvent) {\n set((state) => {\n return { fillValueBaseCell: state.focusedCell };\n });\n event.preventDefault();\n },\n onCellEdited(rowIndex: number, columnName: string, value: any) {\n set((state) => {\n const { editable, updatedData, data } = state;\n if (!editable) return {};\n let rowSpec: any;\n\n // Check to see if the new value is meaningfully different from the old\n // one. Empty string and null/undefined are treated as equivalent, so\n // focusing (and blurring) an empty cell doesn't record a phantom edit.\n const oldValue = data[rowIndex]?.[columnName];\n if (!valuesAreEquivalent(value, oldValue)) {\n const rowOp = updatedData[rowIndex] != null ? \"$merge\" : \"$set\";\n rowSpec = { [rowOp]: { [columnName]: value } };\n } else if (updatedData[rowIndex] != null) {\n // No change — drop any prior override for this cell.\n rowSpec = { $unset: [columnName] };\n } else {\n // No change and no prior override: nothing to do. (`$unset` on an\n // absent row would throw in immutability-helper.)\n return {};\n }\n const spec: Spec<T[]> = { [rowIndex]: rowSpec };\n return { updatedData: update(updatedData, spec) };\n });\n if (get().editable) {\n get().onEdit?.({\n type: \"setCells\",\n cells: [{ rowIndex, column: columnName, value }],\n });\n }\n },\n clearSelection() {\n const edits: { rowIndex: number; column: string; value: any }[] = [];\n set((state) => {\n // Delete all selected cells\n const { selection, updatedData, columnSpec, data } = state;\n const numVisible = visibleRowCount(state);\n let spec = {};\n for (const region of selection) {\n const { cols, rows } = region;\n const rowRange = range(rows ?? [0, numVisible - 1]);\n const colRange = range(cols ?? [0, columnSpec.length - 1]);\n for (const visibleRow of rowRange) {\n // Selection indices are visible positions; map to the data row.\n const row = toDataRowIndex(state, visibleRow);\n // Don't clear row if it has been deleted\n const rowIsDeleted =\n state.rowStatus[row] === TableElementStatus.DELETED;\n if (rowIsDeleted) continue;\n let vals = {};\n for (const col of colRange) {\n const key = columnSpec[col].key;\n const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];\n if (currentValue != null && currentValue !== \"\") {\n vals[key] = \"\";\n edits.push({ rowIndex: row, column: key, value: \"\" });\n }\n }\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: vals };\n }\n }\n return {\n updatedData: update(updatedData, spec),\n };\n });\n if (edits.length > 0) {\n get().onEdit?.({ type: \"setCells\", cells: edits });\n }\n },\n onSelection(selection: Region[]) {\n set((state) => {\n if (\n selectionEquals(selection, state.selection) &&\n singleFocusedCell(selection) == null // Only if we're in a multi-cell selection mode\n ) {\n // If the selection is the same as the current selection, remove the selection.\n // In practice this only happens for whole-row and whole-column selections\n return {\n selection: [],\n focusedCell: null,\n topLeftCell: null,\n fillValueBaseCell: null,\n cellSurfaceOpen: false,\n };\n }\n\n let spec = updateSelection(selection);\n if (state.fillValueBaseCell != null) {\n spec.updatedData = fillValues(state, selection);\n }\n // A click (user selection) re-arms auto-activation and clears the\n // travel direction so the editor opens with a default cursor.\n spec.autoActivateArmed = true;\n spec.lastNavDirection = null;\n // Only open when the selection actually MOVES to a (single) cell.\n // A click on the already-selected cell leaves open-state to the\n // target's click toggle — this avoids racing the selection event\n // (which fires on mousedown, possibly more than once) and is what\n // makes both re-focus-to-open and click-to-close reliable.\n if (!selectionEquals(selection, state.selection)) {\n spec.cellSurfaceOpen = singleFocusedCell(selection) != null;\n }\n return spec;\n });\n },\n onSelectionEdited(value: any) {\n // Apply the same value to all selected cells\n const edits: { rowIndex: number; column: string; value: any }[] = [];\n set((state) => {\n const { selection, updatedData, columnSpec, editable } = state;\n if (!editable) return {};\n const numVisible = visibleRowCount(state);\n let spec = {};\n for (const region of selection) {\n const { cols, rows } = region;\n const rowRange = range(rows ?? [0, numVisible - 1]);\n const colRange = range(cols ?? [0, columnSpec.length - 1]);\n for (const visibleRow of rowRange) {\n // Selection indices are visible positions; map to the data row.\n const row = toDataRowIndex(state, visibleRow);\n let vals = {};\n for (const col of colRange) {\n const key = columnSpec[col].key;\n vals[key] = value;\n edits.push({ rowIndex: row, column: key, value });\n }\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: vals };\n }\n }\n return {\n updatedData: update(updatedData, spec),\n };\n });\n if (edits.length > 0) {\n get().onEdit?.({ type: \"setCells\", cells: edits });\n }\n },\n onColumnsReordered(oldIndex: number, newIndex: number, length: number) {\n set((state) => {\n if (!state.enableColumnReordering) return {};\n const { columnSpec } = state;\n const newSpec = [...columnSpec];\n const removed = newSpec.splice(oldIndex, length);\n newSpec.splice(newIndex, 0, ...removed);\n return { columnSpec: newSpec };\n });\n },\n scrollToRow(rowIndex: number) {\n const tableRef = get().tableRef;\n if (tableRef.current == null) return;\n tableRef.current.scrollToRegion({\n rows: [rowIndex, rowIndex],\n });\n },\n // Sort/filter state changes flow to the data provider (via the loader,\n // which reads `activeFilters`/`columnSorts` and re-fetches). The library no\n // longer computes a client-side `filteredRowIndices` view — `data` arrives\n // already ordered from the provider (in memory for a local source).\n setFilter(filterId: string, filter: any, filterState: any) {\n set((state) => {\n const newFilters = new Map<string, { filter: any; state: any }>(\n state.activeFilters,\n );\n newFilters.set(filterId, { filter, state: filterState });\n return { activeFilters: newFilters };\n });\n },\n removeFilter(filterId: string) {\n set((state) => {\n const newFilters = new Map<string, { filter: any; state: any }>(\n state.activeFilters,\n );\n newFilters.delete(filterId);\n return { activeFilters: newFilters };\n });\n },\n clearFilters() {\n set(() => ({\n activeFilters: new Map<string, { filter: any; state: any }>(),\n }));\n },\n setColumnSort(key: string, ascending: boolean | null) {\n set((state) => {\n let newSorts;\n if (ascending == null) {\n newSorts = state.columnSorts.filter((s) => s.key !== key);\n } else {\n const without = state.columnSorts.filter((s) => s.key !== key);\n newSorts = [...without, { key, ascending }];\n }\n return { columnSorts: newSorts };\n });\n },\n clearColumnSorts() {\n set(() => ({ columnSorts: [] }));\n },\n setClipboardProxy(proxy) {\n set({ clipboardProxy: proxy });\n },\n };\n}\n\nexport function updateSelection<T>(selection: Region[]) {\n const focusedCell = singleFocusedCell(selection);\n let spec: Partial<DataSheetState<T>> = {\n selection,\n focusedCell,\n topLeftCell: topLeftCell(selection),\n };\n if (focusedCell != null) {\n spec.fillValueBaseCell = null;\n }\n return spec;\n}\n\nfunction getLastRowIndex(regions: Region[]): number | null {\n /** Get the last row index from a selection of regions */\n if (regions == null || regions.length === 0) return null;\n let lastRow = -1;\n for (const region of regions) {\n const { rows } = region;\n if (rows == null || rows.length !== 2) continue;\n lastRow = Math.max(lastRow, rows[1]);\n }\n if (lastRow < 0) {\n /** If no valid rows are found, return null */\n return null;\n }\n return lastRow;\n}\n\nfunction getRowIndices(regions: Region[]): number[] {\n /** Get the row indices from a selection of regions */\n if (regions == null || regions.length === 0) return [];\n const rowIndices = new Set<number>();\n for (const region of regions) {\n const { rows } = region;\n if (rows == null || rows.length !== 2) continue;\n for (let i = rows[0]; i <= rows[1]; i++) {\n rowIndices.add(i);\n }\n }\n return Array.from(rowIndices).sort((a, b) => a - b);\n}\n\nexport function topLeftCell(\n regions: Region[],\n requireSolitaryCell: boolean = false,\n): FocusedCellCoordinates | null {\n /** Top left cell of a ranged selection */\n if (regions == null) return null;\n const [region] = regions;\n if (region == null) return null;\n const { cols, rows } = region;\n if (cols == null || rows == null) return null;\n if (requireSolitaryCell && (cols[0] !== cols[1] || rows[0] !== rows[1]))\n return null;\n return { col: cols[0], row: rows[0], focusSelectionIndex: 0 };\n}\n\nfunction selectionEquals(a: Region[], b: Region[]): boolean {\n /** Check if two selections are equal */\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n const regionA = a[i];\n const regionB = b[i];\n\n const colsA = regionA.cols ?? [];\n const colsB = regionB.cols ?? [];\n\n const rowsA = regionA.rows ?? [];\n const rowsB = regionB.rows ?? [];\n\n if (\n colsA.length !== colsB.length ||\n rowsA.length !== rowsB.length ||\n colsA[0] !== colsB[0] ||\n colsA[1] !== colsB[1] ||\n rowsA[0] !== rowsB[0] ||\n rowsA[1] !== rowsB[1]\n ) {\n return false;\n }\n }\n return true;\n}\n\nexport function singleFocusedCell(\n sel: Region[],\n): FocusedCellCoordinates | null {\n /** Derive a single focused cell from a selected region, if possible */\n if (sel?.length !== 1) return null;\n return topLeftCell(sel, true);\n}\n\nfunction fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {\n const { updatedData, columnSpec, editable, fillValueBaseCell, data } = state;\n\n // Prepare regions by unnesting columns\n let regions = selection.map((region) => {\n const { cols, rows } = region;\n // Get the first column (maybe should be the last)\n const [col] = cols;\n return { cols: [col, col], rows };\n });\n\n // Fill values downwards\n if (!editable || fillValueBaseCell == null) return updatedData;\n const { col, row: baseVisibleRow } = fillValueBaseCell;\n // The base cell and target rows are visible positions; map to data rows.\n const baseRow = toDataRowIndex(state, baseVisibleRow);\n const key = columnSpec[col].key;\n const value = updatedData[baseRow]?.[key] ?? data[baseRow]?.[key];\n const spec = {};\n for (const region of regions) {\n const { rows } = region;\n for (const visibleRow of range(rows)) {\n const row = toDataRowIndex(state, visibleRow);\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: { [key]: value } };\n }\n }\n return update(updatedData, spec);\n}\n\n/** Number of rows currently visible (post-filter/sort), or the full data\n * length when no view transform is active. Uses the max of `data` and\n * `updatedData` lengths because `updatedData` is sparse — keying off it alone\n * would stop a whole-column edit at the last already-edited row. */\nfunction visibleRowCount<T>(state: DataSheetStore<T>): number {\n const { filteredRowIndices, updatedData, data } = state;\n return filteredRowIndices != null\n ? filteredRowIndices.length\n : Math.max(data.length, updatedData.length);\n}\n\n/** Map a visible (post-filter/sort) row position to its underlying data\n * index. Edit methods receive selection indices in visible space, so they\n * must translate before writing to `updatedData`/`data`. */\nfunction toDataRowIndex<T>(\n state: DataSheetStore<T>,\n visibleRow: number,\n): number {\n const { filteredRowIndices } = state;\n if (filteredRowIndices == null) return visibleRow;\n return filteredRowIndices[visibleRow] ?? visibleRow;\n}\n\n/** Whether two cell values are equivalent for edit-tracking. Empty string and\n * null/undefined are equivalent (so clearing an empty cell is a no-op), and\n * non-blank values are compared by string form so a text editor's `\"42\"`\n * matches a numeric base `42` (otherwise the cell reads as edited when its\n * value didn't actually change). */\nfunction valuesAreEquivalent(a: any, b: any): boolean {\n if (a === b) return true;\n const aBlank = a == null || a === \"\";\n const bBlank = b == null || b === \"\";\n if (aBlank || bBlank) return aBlank && bBlank;\n return String(a) === String(b);\n}\n\nfunction resetChangesForSelection<T>(\n state: DataSheetStore<T>,\n selection: Region[],\n): Partial<DataSheetStore<T>> {\n const emptySelection = {\n selection: [],\n focusedCell: null,\n topLeftCell: null,\n fillValueBaseCell: null,\n };\n\n const { data } = state;\n const cardinality =\n getSelectionCardinality(selection ?? []) ?? RegionCardinality.FULL_TABLE;\n\n const rowStatus = [...state.rowStatus];\n const updatedData = [...state.updatedData];\n const addedRows = new Set<number>();\n\n // Global reset\n switch (cardinality) {\n case RegionCardinality.FULL_TABLE:\n for (let i = 0; i < rowStatus.length; i++) {\n if (rowStatus[i] === TableElementStatus.ADDED) {\n addedRows.add(i);\n }\n }\n\n return {\n updatedData: [],\n rowStatus: [],\n data: data.filter((_, i) => !addedRows.has(i)),\n ...emptySelection,\n };\n case RegionCardinality.FULL_COLUMNS:\n case RegionCardinality.CELLS:\n /** Columns or cells. Note, these only work the same because we don't\n * allow column deletion, only unsetting all values.\n */\n const columnKeys = getSelectedColumnKeys(selection, state.columnSpec);\n const spec: Spec<Record<string, any>[]> = {};\n const rowIndices =\n cardinality == RegionCardinality.FULL_COLUMNS\n ? Array.from({ length: updatedData.length }, (_, i) => i)\n : getSelectedRowIndices(selection);\n for (const row of rowIndices) {\n if (updatedData[row] == null) continue;\n spec[row] = { $unset: columnKeys };\n }\n // TODO: if we allow column addition/deletion, this will require more adjustment\n return {\n updatedData: update(updatedData, spec),\n ...emptySelection,\n };\n case RegionCardinality.FULL_ROWS:\n for (const row of getSelectedRowIndices(selection)) {\n updatedData[row] = undefined;\n if (state.rowStatus[row] === TableElementStatus.DELETED) {\n rowStatus[row] = undefined;\n } else if (state.rowStatus[row] === TableElementStatus.ADDED) {\n addedRows.add(row);\n }\n }\n\n const removeCandidateRows = (arr: any[]) => {\n return arr.filter((d, i) => !addedRows.has(i));\n };\n\n return {\n updatedData: removeCandidateRows(updatedData),\n data: removeCandidateRows(state.data),\n rowStatus: removeCandidateRows(rowStatus),\n ...emptySelection,\n };\n }\n}\n\nfunction insertItemAtIndex<T>(arr: T[], index: number, item: T) {\n if (arr.length < index) {\n const newArr = [...arr];\n newArr.length = index;\n newArr[index] = item;\n return newArr;\n }\n\n return [...arr.slice(0, index), item, ...arr.slice(index)];\n}\n"],"names":["selection","topLeftCell","DS_ROW_ID","TableElementStatus","update","range","col","getSelectionCardinality","RegionCardinality","getSelectedColumnKeys","getSelectedRowIndices","index"],"mappings":";;;;;;;;;AAuBA,IAAI,mBAAmB;AAEhB,SAAS,mBAAsB,KAAK,KAA4B;AACrE,SAAO;AAAA;AAAA,IAEL,MAAM,CAAA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AAChB,WAAOA,MAAK,IAAI;AAChB,WAAO;AAAA,EACT;AAEA,SAAO,CAAC,GAAG,IAAI,MAAM,GAAGA,MAAK,GAAG,MAAM,GAAG,IAAI,MAAMA,MAAK,CAAC;AAC3D;;;;;"}
|
|
1
|
+
{"version":3,"file":"zustand-store.cjs","sources":["../src/zustand-store.ts"],"sourcesContent":["import {\n DataSheetState,\n DataSheetStore,\n DataSheetStoreMain,\n DEFAULT_ROW_STATUS_STYLES,\n DS_ROW_ID,\n StateUpdater,\n TableElementStatus,\n VisibleCells,\n} from \"./types.ts\";\nimport {\n type FocusedCellCoordinates,\n type Region,\n RegionCardinality,\n} from \"@blueprintjs/table\";\nimport { range } from \"./utils\";\nimport update, { Spec } from \"immutability-helper\";\nimport {\n getSelectedColumnKeys,\n getSelectedRowIndices,\n getSelectionCardinality,\n} from \"./actions\";\n\n/** Monotonic counter for synthetic ids on in-table-added rows. */\nlet _addedRowCounter = 0;\n\nexport function createZustandStore<T>(set, get): DataSheetStoreMain<T> {\n return {\n /** All the data in the table */\n data: [],\n updatedData: [],\n rowStatus: [],\n rowStatusStyles: DEFAULT_ROW_STATUS_STYLES,\n columnSpec: [],\n defaultColumnWidth: 150,\n editable: false,\n selection: [],\n fillValueBaseCell: null,\n focusedCell: null,\n topLeftCell: null,\n initialized: false,\n tableRef: null,\n // This is a placeholder\n enableColumnReordering: false,\n activeFilters: new Map<string, { filter: any; state: any }>(),\n columnSorts: [],\n clipboardProxy: null,\n filteredRowIndices: null,\n cellInteraction: \"auto\",\n autoActivateArmed: true,\n lastNavDirection: null,\n tableElement: null,\n cellSurfaceOpen: false,\n identity: (row: any) => row?.id,\n pendingOverlayById: new Map(),\n controlledOverlay: false,\n canDeleteRows: true,\n setSelection(selection: Region[]) {\n set(updateSelection(selection));\n },\n columnWidthsIndex: new Map<string, number>(),\n suppressAutoActivate() {\n set({ autoActivateArmed: false });\n },\n armAutoActivate() {\n set({ autoActivateArmed: true });\n },\n openCellSurface() {\n set({ cellSurfaceOpen: true });\n },\n closeCellSurface(opts?: { suppress?: boolean }) {\n const suppress = opts?.suppress ?? true;\n set((state) => ({\n cellSurfaceOpen: false,\n // Escape (suppress) drops auto mode into navigation mode so surfaces\n // stop auto-opening until the next click. A click-dismiss doesn't.\n autoActivateArmed:\n suppress && state.cellInteraction === \"auto\"\n ? false\n : state.autoActivateArmed,\n }));\n },\n moveFocusedCell(direction: \"up\" | \"down\" | \"left\" | \"right\") {\n set((state) => {\n const { topLeftCell } = state;\n if (topLeftCell == null) return {};\n let { col, row } = topLeftCell;\n switch (direction) {\n case \"up\":\n row = Math.max(0, row - 1);\n break;\n case \"down\":\n row = Math.min(\n row + 1,\n Math.max(state.data.length, state.updatedData.length) - 1,\n );\n break;\n case \"left\":\n col = Math.max(0, col - 1);\n break;\n case \"right\":\n col = Math.min(col + 1, state.columnSpec.length - 1);\n break;\n }\n const region: Region = { cols: [col, col], rows: [row, row] };\n // Record the travel direction (so the next editor places its cursor on\n // the side we're moving toward) and open the new cell's surface only\n // when auto-activation is armed.\n return {\n ...updateSelection([region]),\n lastNavDirection: direction,\n cellSurfaceOpen:\n state.cellInteraction === \"auto\" && state.autoActivateArmed,\n };\n });\n },\n addRow(row: Partial<T> = {} as T) {\n /** Add a new row. If there is a selection, use the last row index to determine\n * where to insert the new row. Otherwise, append to the end of the data. */\n let newIndex = -1;\n set((state) => {\n const { updatedData, data, selection, rowStatus } = state;\n\n const lastRowIndex =\n getLastRowIndex(selection) ??\n Math.max(data.length, updatedData.length) - 1;\n // Use $set at a specific index to correctly extend the sparse array.\n // $splice fails when the target index exceeds the array length.\n newIndex = lastRowIndex + 1;\n\n // Stamp a stable synthetic id so the added row survives a provider\n // re-fetch (it has no provider row to match on). Its values live in the\n // overlay (`updatedData`), which the loader-boundary remap re-appends.\n const newRow = {\n ...(row as any),\n [DS_ROW_ID]: `__added_${_addedRowCounter++}`,\n } as T;\n\n return {\n updatedData: insertItemAtIndex(updatedData, newIndex, newRow),\n data: insertItemAtIndex(data, newIndex, newRow),\n rowStatus: insertItemAtIndex(\n rowStatus,\n newIndex,\n TableElementStatus.ADDED,\n ),\n };\n });\n get().onEdit?.({ type: \"addRow\", rowIndex: newIndex, value: row });\n },\n setUpdatedData(data: StateUpdater<T>) {\n if (Array.isArray(data)) {\n set({ updatedData: data });\n } else {\n set((state) => {\n return { updatedData: data(state.updatedData) };\n });\n }\n },\n deleteSelectedRows() {\n // Deletion is a provider capability: if the active data provider can't\n // delete (no `deleteRows`), the whole affordance is disabled.\n if (!get().canDeleteRows) return;\n // Remove selected rows from the data and updatedData arrays\n let deletedIndices: number[] = [];\n set((state) => {\n const { selection, deletedRows } = state;\n const rowIndices = getRowIndices(selection);\n deletedIndices = rowIndices;\n\n // Delete rows from both updatedData and data\n\n // If rows are in addedRows, we just delete them outright from the data and updatedData arrays\n const { addedRows } = state;\n\n const rowsNewlyDeleted = new Set(rowIndices);\n\n // We outright remove rows that have not been added to the data array\n const rowsToRemoveFromDataArrays = new Set(\n rowIndices.filter(\n (d) => state.rowStatus[d] == TableElementStatus.ADDED,\n ),\n );\n // ...otherwise we set them to 'deleted'\n const rowsToMarkAsDeleted = rowsNewlyDeleted.difference(\n rowsToRemoveFromDataArrays,\n );\n\n let data = state.data;\n let updatedData = state.updatedData;\n let rowStatus = state.rowStatus;\n if (rowsToMarkAsDeleted.size > 0) {\n let spec: Spec<TableElementStatus[]> = {};\n for (const ix of rowsToMarkAsDeleted) {\n spec[ix] = { $set: TableElementStatus.DELETED };\n }\n rowStatus = update(rowStatus, spec);\n }\n\n if (rowsToRemoveFromDataArrays.size > 0) {\n const filterFunc = (_, i) => !rowsToRemoveFromDataArrays.has(i);\n data = data.filter(filterFunc);\n updatedData = updatedData.filter(filterFunc);\n rowStatus = rowStatus.filter(filterFunc);\n }\n\n // Remove selected rows and reset selection\n return {\n selection: [],\n data,\n updatedData,\n rowStatus,\n focusedCell: null,\n topLeftCell: null,\n fillValueBaseCell: null,\n };\n });\n if (deletedIndices.length > 0) {\n get().onEdit?.({ type: \"deleteRows\", rowIndices: deletedIndices });\n }\n },\n resetChanges(regions?: Region[]) {\n // Reset the updated data to the initial data\n set((state) => resetChangesForSelection(state, regions));\n get().onEdit?.({ type: \"resetChanges\" });\n },\n onColumnWidthChanged(columnIx: number, newWidth: number) {\n set((state) => {\n const { columnSpec, columnWidthsIndex } = state;\n const colKey = columnSpec[columnIx].key;\n const newColumnWidths = new Map(columnWidthsIndex);\n newColumnWidths.set(colKey, newWidth);\n return { columnWidthsIndex: newColumnWidths };\n });\n },\n onDragValue(event: MouseEvent) {\n set((state) => {\n return { fillValueBaseCell: state.focusedCell };\n });\n event.preventDefault();\n },\n onCellEdited(rowIndex: number, columnName: string, value: any) {\n set((state) => {\n const { editable, updatedData, data } = state;\n if (!editable) return {};\n let rowSpec: any;\n\n // Check to see if the new value is meaningfully different from the old\n // one. Empty string and null/undefined are treated as equivalent, so\n // focusing (and blurring) an empty cell doesn't record a phantom edit.\n const oldValue = data[rowIndex]?.[columnName];\n if (!valuesAreEquivalent(value, oldValue)) {\n const rowOp = updatedData[rowIndex] != null ? \"$merge\" : \"$set\";\n rowSpec = { [rowOp]: { [columnName]: value } };\n } else if (updatedData[rowIndex] != null) {\n // No change — drop any prior override for this cell.\n rowSpec = { $unset: [columnName] };\n } else {\n // No change and no prior override: nothing to do. (`$unset` on an\n // absent row would throw in immutability-helper.)\n return {};\n }\n const spec: Spec<T[]> = { [rowIndex]: rowSpec };\n return { updatedData: update(updatedData, spec) };\n });\n if (get().editable) {\n get().onEdit?.({\n type: \"setCells\",\n cells: [\n { rowIndex, column: columnName, value, row: get().data[rowIndex] },\n ],\n });\n }\n },\n clearSelection() {\n const edits: { rowIndex: number; column: string; value: any; row?: any }[] =\n [];\n set((state) => {\n // Delete all selected cells\n const { selection, updatedData, columnSpec, data } = state;\n const numVisible = visibleRowCount(state);\n let spec = {};\n for (const region of selection) {\n const { cols, rows } = region;\n const rowRange = range(rows ?? [0, numVisible - 1]);\n const colRange = range(cols ?? [0, columnSpec.length - 1]);\n for (const visibleRow of rowRange) {\n // Selection indices are visible positions; map to the data row.\n const row = toDataRowIndex(state, visibleRow);\n // Don't clear row if it has been deleted\n const rowIsDeleted =\n state.rowStatus[row] === TableElementStatus.DELETED;\n if (rowIsDeleted) continue;\n let vals = {};\n for (const col of colRange) {\n const key = columnSpec[col].key;\n const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];\n if (currentValue != null && currentValue !== \"\") {\n vals[key] = \"\";\n edits.push({ rowIndex: row, column: key, value: \"\", row: data[row] });\n }\n }\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: vals };\n }\n }\n return {\n updatedData: update(updatedData, spec),\n };\n });\n if (edits.length > 0) {\n get().onEdit?.({ type: \"setCells\", cells: edits });\n }\n },\n onSelection(selection: Region[]) {\n set((state) => {\n if (\n selectionEquals(selection, state.selection) &&\n singleFocusedCell(selection) == null // Only if we're in a multi-cell selection mode\n ) {\n // If the selection is the same as the current selection, remove the selection.\n // In practice this only happens for whole-row and whole-column selections\n return {\n selection: [],\n focusedCell: null,\n topLeftCell: null,\n fillValueBaseCell: null,\n cellSurfaceOpen: false,\n };\n }\n\n let spec = updateSelection(selection);\n if (state.fillValueBaseCell != null) {\n spec.updatedData = fillValues(state, selection);\n }\n // A click (user selection) re-arms auto-activation and clears the\n // travel direction so the editor opens with a default cursor.\n spec.autoActivateArmed = true;\n spec.lastNavDirection = null;\n // Only open when the selection actually MOVES to a (single) cell.\n // A click on the already-selected cell leaves open-state to the\n // target's click toggle — this avoids racing the selection event\n // (which fires on mousedown, possibly more than once) and is what\n // makes both re-focus-to-open and click-to-close reliable.\n if (!selectionEquals(selection, state.selection)) {\n spec.cellSurfaceOpen = singleFocusedCell(selection) != null;\n }\n return spec;\n });\n },\n onSelectionEdited(value: any) {\n // Apply the same value to all selected cells\n const edits: { rowIndex: number; column: string; value: any; row?: any }[] =\n [];\n set((state) => {\n const { selection, updatedData, columnSpec, editable } = state;\n if (!editable) return {};\n const numVisible = visibleRowCount(state);\n let spec = {};\n for (const region of selection) {\n const { cols, rows } = region;\n const rowRange = range(rows ?? [0, numVisible - 1]);\n const colRange = range(cols ?? [0, columnSpec.length - 1]);\n for (const visibleRow of rowRange) {\n // Selection indices are visible positions; map to the data row.\n const row = toDataRowIndex(state, visibleRow);\n let vals = {};\n for (const col of colRange) {\n const key = columnSpec[col].key;\n vals[key] = value;\n edits.push({ rowIndex: row, column: key, value, row: state.data[row] });\n }\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: vals };\n }\n }\n return {\n updatedData: update(updatedData, spec),\n };\n });\n if (edits.length > 0) {\n get().onEdit?.({ type: \"setCells\", cells: edits });\n }\n },\n onColumnsReordered(oldIndex: number, newIndex: number, length: number) {\n set((state) => {\n if (!state.enableColumnReordering) return {};\n const { columnSpec } = state;\n const newSpec = [...columnSpec];\n const removed = newSpec.splice(oldIndex, length);\n newSpec.splice(newIndex, 0, ...removed);\n return { columnSpec: newSpec };\n });\n },\n scrollToRow(rowIndex: number) {\n const tableRef = get().tableRef;\n if (tableRef.current == null) return;\n tableRef.current.scrollToRegion({\n rows: [rowIndex, rowIndex],\n });\n },\n // Sort/filter state changes flow to the data provider (via the loader,\n // which reads `activeFilters`/`columnSorts` and re-fetches). The library no\n // longer computes a client-side `filteredRowIndices` view — `data` arrives\n // already ordered from the provider (in memory for a local source).\n setFilter(filterId: string, filter: any, filterState: any) {\n set((state) => {\n const newFilters = new Map<string, { filter: any; state: any }>(\n state.activeFilters,\n );\n newFilters.set(filterId, { filter, state: filterState });\n return { activeFilters: newFilters };\n });\n },\n removeFilter(filterId: string) {\n set((state) => {\n const newFilters = new Map<string, { filter: any; state: any }>(\n state.activeFilters,\n );\n newFilters.delete(filterId);\n return { activeFilters: newFilters };\n });\n },\n clearFilters() {\n set(() => ({\n activeFilters: new Map<string, { filter: any; state: any }>(),\n }));\n },\n setColumnSort(key: string, ascending: boolean | null) {\n set((state) => {\n let newSorts;\n if (ascending == null) {\n newSorts = state.columnSorts.filter((s) => s.key !== key);\n } else {\n const without = state.columnSorts.filter((s) => s.key !== key);\n newSorts = [...without, { key, ascending }];\n }\n return { columnSorts: newSorts };\n });\n },\n clearColumnSorts() {\n set(() => ({ columnSorts: [] }));\n },\n setClipboardProxy(proxy) {\n set({ clipboardProxy: proxy });\n },\n };\n}\n\nexport function updateSelection<T>(selection: Region[]) {\n const focusedCell = singleFocusedCell(selection);\n let spec: Partial<DataSheetState<T>> = {\n selection,\n focusedCell,\n topLeftCell: topLeftCell(selection),\n };\n if (focusedCell != null) {\n spec.fillValueBaseCell = null;\n }\n return spec;\n}\n\nfunction getLastRowIndex(regions: Region[]): number | null {\n /** Get the last row index from a selection of regions */\n if (regions == null || regions.length === 0) return null;\n let lastRow = -1;\n for (const region of regions) {\n const { rows } = region;\n if (rows == null || rows.length !== 2) continue;\n lastRow = Math.max(lastRow, rows[1]);\n }\n if (lastRow < 0) {\n /** If no valid rows are found, return null */\n return null;\n }\n return lastRow;\n}\n\nfunction getRowIndices(regions: Region[]): number[] {\n /** Get the row indices from a selection of regions */\n if (regions == null || regions.length === 0) return [];\n const rowIndices = new Set<number>();\n for (const region of regions) {\n const { rows } = region;\n if (rows == null || rows.length !== 2) continue;\n for (let i = rows[0]; i <= rows[1]; i++) {\n rowIndices.add(i);\n }\n }\n return Array.from(rowIndices).sort((a, b) => a - b);\n}\n\nexport function topLeftCell(\n regions: Region[],\n requireSolitaryCell: boolean = false,\n): FocusedCellCoordinates | null {\n /** Top left cell of a ranged selection */\n if (regions == null) return null;\n const [region] = regions;\n if (region == null) return null;\n const { cols, rows } = region;\n if (cols == null || rows == null) return null;\n if (requireSolitaryCell && (cols[0] !== cols[1] || rows[0] !== rows[1]))\n return null;\n return { col: cols[0], row: rows[0], focusSelectionIndex: 0 };\n}\n\nfunction selectionEquals(a: Region[], b: Region[]): boolean {\n /** Check if two selections are equal */\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n const regionA = a[i];\n const regionB = b[i];\n\n const colsA = regionA.cols ?? [];\n const colsB = regionB.cols ?? [];\n\n const rowsA = regionA.rows ?? [];\n const rowsB = regionB.rows ?? [];\n\n if (\n colsA.length !== colsB.length ||\n rowsA.length !== rowsB.length ||\n colsA[0] !== colsB[0] ||\n colsA[1] !== colsB[1] ||\n rowsA[0] !== rowsB[0] ||\n rowsA[1] !== rowsB[1]\n ) {\n return false;\n }\n }\n return true;\n}\n\nexport function singleFocusedCell(\n sel: Region[],\n): FocusedCellCoordinates | null {\n /** Derive a single focused cell from a selected region, if possible */\n if (sel?.length !== 1) return null;\n return topLeftCell(sel, true);\n}\n\nfunction fillValues<T>(state: DataSheetStore<T>, selection: Region[]) {\n const { updatedData, columnSpec, editable, fillValueBaseCell, data } = state;\n\n // Prepare regions by unnesting columns\n let regions = selection.map((region) => {\n const { cols, rows } = region;\n // Get the first column (maybe should be the last)\n const [col] = cols;\n return { cols: [col, col], rows };\n });\n\n // Fill values downwards\n if (!editable || fillValueBaseCell == null) return updatedData;\n const { col, row: baseVisibleRow } = fillValueBaseCell;\n // The base cell and target rows are visible positions; map to data rows.\n const baseRow = toDataRowIndex(state, baseVisibleRow);\n const key = columnSpec[col].key;\n const value = updatedData[baseRow]?.[key] ?? data[baseRow]?.[key];\n const spec = {};\n for (const region of regions) {\n const { rows } = region;\n for (const visibleRow of range(rows)) {\n const row = toDataRowIndex(state, visibleRow);\n let op = updatedData[row] == null ? \"$set\" : \"$merge\";\n spec[row] = { [op]: { [key]: value } };\n }\n }\n return update(updatedData, spec);\n}\n\n/** Number of rows currently visible (post-filter/sort), or the full data\n * length when no view transform is active. Uses the max of `data` and\n * `updatedData` lengths because `updatedData` is sparse — keying off it alone\n * would stop a whole-column edit at the last already-edited row. */\nfunction visibleRowCount<T>(state: DataSheetStore<T>): number {\n const { filteredRowIndices, updatedData, data } = state;\n return filteredRowIndices != null\n ? filteredRowIndices.length\n : Math.max(data.length, updatedData.length);\n}\n\n/** Map a visible (post-filter/sort) row position to its underlying data\n * index. Edit methods receive selection indices in visible space, so they\n * must translate before writing to `updatedData`/`data`. */\nfunction toDataRowIndex<T>(\n state: DataSheetStore<T>,\n visibleRow: number,\n): number {\n const { filteredRowIndices } = state;\n if (filteredRowIndices == null) return visibleRow;\n return filteredRowIndices[visibleRow] ?? visibleRow;\n}\n\n/** Whether two cell values are equivalent for edit-tracking. Empty string and\n * null/undefined are equivalent (so clearing an empty cell is a no-op), and\n * non-blank values are compared by string form so a text editor's `\"42\"`\n * matches a numeric base `42` (otherwise the cell reads as edited when its\n * value didn't actually change). */\nfunction valuesAreEquivalent(a: any, b: any): boolean {\n if (a === b) return true;\n const aBlank = a == null || a === \"\";\n const bBlank = b == null || b === \"\";\n if (aBlank || bBlank) return aBlank && bBlank;\n return String(a) === String(b);\n}\n\nfunction resetChangesForSelection<T>(\n state: DataSheetStore<T>,\n selection: Region[],\n): Partial<DataSheetStore<T>> {\n const emptySelection = {\n selection: [],\n focusedCell: null,\n topLeftCell: null,\n fillValueBaseCell: null,\n };\n\n const { data } = state;\n const cardinality =\n getSelectionCardinality(selection ?? []) ?? RegionCardinality.FULL_TABLE;\n\n const rowStatus = [...state.rowStatus];\n const updatedData = [...state.updatedData];\n const addedRows = new Set<number>();\n\n // Global reset\n switch (cardinality) {\n case RegionCardinality.FULL_TABLE:\n for (let i = 0; i < rowStatus.length; i++) {\n if (rowStatus[i] === TableElementStatus.ADDED) {\n addedRows.add(i);\n }\n }\n\n return {\n updatedData: [],\n rowStatus: [],\n data: data.filter((_, i) => !addedRows.has(i)),\n ...emptySelection,\n };\n case RegionCardinality.FULL_COLUMNS:\n case RegionCardinality.CELLS:\n /** Columns or cells. Note, these only work the same because we don't\n * allow column deletion, only unsetting all values.\n */\n const columnKeys = getSelectedColumnKeys(selection, state.columnSpec);\n const spec: Spec<Record<string, any>[]> = {};\n const rowIndices =\n cardinality == RegionCardinality.FULL_COLUMNS\n ? Array.from({ length: updatedData.length }, (_, i) => i)\n : getSelectedRowIndices(selection);\n for (const row of rowIndices) {\n if (updatedData[row] == null) continue;\n spec[row] = { $unset: columnKeys };\n }\n // TODO: if we allow column addition/deletion, this will require more adjustment\n return {\n updatedData: update(updatedData, spec),\n ...emptySelection,\n };\n case RegionCardinality.FULL_ROWS:\n for (const row of getSelectedRowIndices(selection)) {\n updatedData[row] = undefined;\n if (state.rowStatus[row] === TableElementStatus.DELETED) {\n rowStatus[row] = undefined;\n } else if (state.rowStatus[row] === TableElementStatus.ADDED) {\n addedRows.add(row);\n }\n }\n\n const removeCandidateRows = (arr: any[]) => {\n return arr.filter((d, i) => !addedRows.has(i));\n };\n\n return {\n updatedData: removeCandidateRows(updatedData),\n data: removeCandidateRows(state.data),\n rowStatus: removeCandidateRows(rowStatus),\n ...emptySelection,\n };\n }\n}\n\nfunction insertItemAtIndex<T>(arr: T[], index: number, item: T) {\n if (arr.length < index) {\n const newArr = [...arr];\n newArr.length = index;\n newArr[index] = item;\n return newArr;\n }\n\n return [...arr.slice(0, index), item, ...arr.slice(index)];\n}\n"],"names":["DEFAULT_ROW_STATUS_STYLES","selection","topLeftCell","DS_ROW_ID","TableElementStatus","update","range","col","getSelectionCardinality","RegionCardinality","getSelectedColumnKeys","getSelectedRowIndices","index"],"mappings":";;;;;;;;;AAwBA,IAAI,mBAAmB;AAEhB,SAAS,mBAAsB,KAAK,KAA4B;AACrE,SAAO;AAAA;AAAA,IAEL,MAAM,CAAA;AAAA,IACN,aAAa,CAAA;AAAA,IACb,WAAW,CAAA;AAAA,IACX,iBAAiBA,MAAAA;AAAAA,IACjB,YAAY,CAAA;AAAA,IACZ,oBAAoB;AAAA,IACpB,UAAU;AAAA,IACV,WAAW,CAAA;AAAA,IACX,mBAAmB;AAAA,IACnB,aAAa;AAAA,IACb,aAAa;AAAA,IACb,aAAa;AAAA,IACb,UAAU;AAAA;AAAA,IAEV,wBAAwB;AAAA,IACxB,mCAAmB,IAAA;AAAA,IACnB,aAAa,CAAA;AAAA,IACb,gBAAg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 @@
|
|
|
1
|
-
import { TableElementStatus, DS_ROW_ID } from "./types.js";
|
|
1
|
+
import { DEFAULT_ROW_STATUS_STYLES, TableElementStatus, DS_ROW_ID } from "./types.js";
|
|
2
2
|
import { RegionCardinality } from "@blueprintjs/table";
|
|
3
3
|
import { range } from "./utils/index.js";
|
|
4
4
|
import update from "immutability-helper";
|
|
@@ -10,6 +10,7 @@ function createZustandStore(set, get) {
|
|
|
10
10
|
data: [],
|
|
11
11
|
updatedData: [],
|
|
12
12
|
rowStatus: [],
|
|
13
|
+
rowStatusStyles: DEFAULT_ROW_STATUS_STYLES,
|
|
13
14
|
columnSpec: [],
|
|
14
15
|
defaultColumnWidth: 150,
|
|
15
16
|
editable: false,
|
|
@@ -203,7 +204,9 @@ function createZustandStore(set, get) {
|
|
|
203
204
|
if (get().editable) {
|
|
204
205
|
get().onEdit?.({
|
|
205
206
|
type: "setCells",
|
|
206
|
-
cells: [
|
|
207
|
+
cells: [
|
|
208
|
+
{ rowIndex, column: columnName, value, row: get().data[rowIndex] }
|
|
209
|
+
]
|
|
207
210
|
});
|
|
208
211
|
}
|
|
209
212
|
},
|
|
@@ -227,7 +230,7 @@ function createZustandStore(set, get) {
|
|
|
227
230
|
const currentValue = updatedData[row]?.[key] ?? data[row]?.[key];
|
|
228
231
|
if (currentValue != null && currentValue !== "") {
|
|
229
232
|
vals[key] = "";
|
|
230
|
-
edits.push({ rowIndex: row, column: key, value: "" });
|
|
233
|
+
edits.push({ rowIndex: row, column: key, value: "", row: data[row] });
|
|
231
234
|
}
|
|
232
235
|
}
|
|
233
236
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
@@ -282,7 +285,7 @@ function createZustandStore(set, get) {
|
|
|
282
285
|
for (const col of colRange) {
|
|
283
286
|
const key = columnSpec[col].key;
|
|
284
287
|
vals[key] = value;
|
|
285
|
-
edits.push({ rowIndex: row, column: key, value });
|
|
288
|
+
edits.push({ rowIndex: row, column: key, value, row: state.data[row] });
|
|
286
289
|
}
|
|
287
290
|
let op = updatedData[row] == null ? "$set" : "$merge";
|
|
288
291
|
spec[row] = { [op]: vals };
|