@macrostrat/data-sheet 4.1.0 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (69) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/actions/column-controls.cjs +17 -5
  3. package/dist/actions/column-controls.cjs.map +1 -1
  4. package/dist/actions/column-controls.js +18 -6
  5. package/dist/actions/column-controls.js.map +1 -1
  6. package/dist/actions/column-filter.cjs +48 -25
  7. package/dist/actions/column-filter.cjs.map +1 -1
  8. package/dist/actions/column-filter.js +50 -27
  9. package/dist/actions/column-filter.js.map +1 -1
  10. package/dist/actions/table-controls.cjs +4 -0
  11. package/dist/actions/table-controls.cjs.map +1 -1
  12. package/dist/actions/table-controls.js +4 -0
  13. package/dist/actions/table-controls.js.map +1 -1
  14. package/dist/actions/toolbar.cjs +19 -5
  15. package/dist/actions/toolbar.cjs.map +1 -1
  16. package/dist/actions/toolbar.js +20 -6
  17. package/dist/actions/toolbar.js.map +1 -1
  18. package/dist/cell-renderer.cjs +1 -1
  19. package/dist/cell-renderer.cjs.map +1 -1
  20. package/dist/cell-renderer.js +1 -1
  21. package/dist/cell-renderer.js.map +1 -1
  22. package/dist/core.cjs +11 -2
  23. package/dist/core.cjs.map +1 -1
  24. package/dist/core.d.ts +4 -0
  25. package/dist/core.js +11 -2
  26. package/dist/core.js.map +1 -1
  27. package/dist/filters/operators.cjs +2 -2
  28. package/dist/filters/operators.cjs.map +1 -1
  29. package/dist/filters/operators.d.ts +1 -1
  30. package/dist/filters/operators.js +2 -2
  31. package/dist/filters/operators.js.map +1 -1
  32. package/dist/postgrest-table/data-loaders.cjs +1 -8
  33. package/dist/postgrest-table/data-loaders.cjs.map +1 -1
  34. package/dist/postgrest-table/data-loaders.js +1 -8
  35. package/dist/postgrest-table/data-loaders.js.map +1 -1
  36. package/dist/provider.cjs +9 -3
  37. package/dist/provider.cjs.map +1 -1
  38. package/dist/provider.d.ts +2 -1
  39. package/dist/provider.js +9 -3
  40. package/dist/provider.js.map +1 -1
  41. package/dist/renderers/column-header-cell.cjs +19 -4
  42. package/dist/renderers/column-header-cell.cjs.map +1 -1
  43. package/dist/renderers/column-header-cell.d.ts +1 -2
  44. package/dist/renderers/column-header-cell.js +20 -5
  45. package/dist/renderers/column-header-cell.js.map +1 -1
  46. package/dist/types.cjs.map +1 -1
  47. package/dist/types.d.ts +10 -1
  48. package/dist/types.js.map +1 -1
  49. package/dist/utils/column-spec.cjs.map +1 -1
  50. package/dist/utils/column-spec.d.ts +4 -0
  51. package/dist/utils/column-spec.js.map +1 -1
  52. package/dist/zustand-store.cjs +1 -0
  53. package/dist/zustand-store.cjs.map +1 -1
  54. package/dist/zustand-store.js +1 -0
  55. package/dist/zustand-store.js.map +1 -1
  56. package/package.json +1 -1
  57. package/src/actions/column-controls.ts +24 -7
  58. package/src/actions/column-filter.ts +59 -30
  59. package/src/actions/table-controls.ts +4 -0
  60. package/src/actions/toolbar.ts +39 -11
  61. package/src/cell-renderer.ts +6 -1
  62. package/src/core.ts +26 -3
  63. package/src/filters/operators.ts +5 -3
  64. package/src/postgrest-table/data-loaders.ts +6 -10
  65. package/src/provider.ts +22 -5
  66. package/src/renderers/column-header-cell.ts +31 -4
  67. package/src/types.ts +10 -1
  68. package/src/utils/column-spec.ts +4 -0
  69. package/src/zustand-store.ts +1 -0
@@ -61,17 +61,31 @@ function ActionsToolbar({
61
61
  if (!toolbarIsShown) {
62
62
  return null;
63
63
  }
64
- const title = selectionTitle(ctx) ?? tableName ?? "Table";
64
+ const hasSelection = selection$1 != null && selection$1.length > 0;
65
+ const titleNode = toolbar_module.default(
66
+ core.Tag,
67
+ {
68
+ key: "title",
69
+ minimal: true,
70
+ large: true,
71
+ onRemove: hasSelection ? () => storeAPI.setState({
72
+ selection: [],
73
+ focusedCell: null,
74
+ topLeftCell: null
75
+ }) : void 0,
76
+ style: hasSelection ? void 0 : { background: "transparent" }
77
+ },
78
+ hasSelection ? selectionTitle(ctx) ?? tableName ?? "Selection" : tableName ?? "Table"
79
+ );
65
80
  const isGlobal = (a) => a.targets.includes(table.RegionCardinality.FULL_TABLE) || a.targets.includes("none");
66
81
  const contextual = shownActions.filter((a) => !isGlobal(a));
67
82
  const globalOrder = {
68
- "clear-selection": 1,
69
- "reset-changes": 2,
70
- "save-changes": 3
83
+ "reset-changes": 1,
84
+ "save-changes": 2
71
85
  };
72
86
  const globalActions = shownActions.filter(isGlobal).sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));
73
87
  return toolbar_module.default("div.actions-toolbar", [
74
- toolbar_module.default("span.toolbar-title", { key: "title" }, title),
88
+ titleNode,
75
89
  toolbar_module.default(
76
90
  core.ButtonGroup,
77
91
  { key: "contextual", minimal: true },
@@ -1 +1 @@
1
- {"version":3,"file":"toolbar.cjs","sources":["../../src/actions/toolbar.ts"],"sourcesContent":["import { Button, ButtonGroup, PopoverNext } from \"@blueprintjs/core\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport h from \"./toolbar.module.sass\";\nimport { useSelector, useStoreAPI } from \"../provider\";\nimport {\n buildActionContext,\n getApplicableActions,\n getSelectionCardinality,\n mergeColumnActions,\n} from \"./selection\";\nimport type { TableAction, TableActionContext } from \"./types\";\nimport { RegionCardinality } from \"@blueprintjs/table\";\nimport { useToaster } from \"../notifications.ts\";\nimport { DataSheetStore } from \"../types.ts\";\nimport { ColumnSpec } from \"../utils\";\n\n/** A short title describing the current selection (its shape), shown as the\n * toolbar's leading label — no icon. */\nfunction selectionTitle<T>(ctx: TableActionContext<T>): string | null {\n const sh = ctx.selectionShape;\n switch (sh.cardinality) {\n case RegionCardinality.FULL_COLUMNS: {\n if (ctx.columnKey != null) {\n const col = ctx.columnSpec.find((c) => c.key === ctx.columnKey);\n return col?.name ?? \"Column\";\n }\n return `${sh.columns} columns`;\n }\n case RegionCardinality.FULL_ROWS:\n return ctx.rowIndex != null ? \"1 row\" : `${sh.rows} rows`;\n case RegionCardinality.CELLS:\n return ctx.cell != null ? \"Cell\" : `${sh.columns}×${sh.rows} cells`;\n case RegionCardinality.FULL_TABLE:\n return null;\n default:\n return null;\n }\n}\n\n/** Toolbar that renders the actions/controls applicable to the current\n * selection cardinality (modal by selection) and edit mode. Actions with a\n * `render` show their live control; others show a button (with an optional\n * `detailsForm` popover). Column-specific actions from `ColumnSpec.actions`\n * are merged when their columns are selected. A capsule on the left shows the\n * current selection polarity. */\nexport function ActionsToolbar<T>({\n actions,\n tableName,\n}: {\n actions: TableAction<T>[];\n tableName?: string;\n}) {\n const selection = useSelector((state) => state.selection);\n const editable = useSelector((state) => state.editable);\n const columnSpec = useSelector((state) => state.columnSpec);\n const storeAPI = useStoreAPI();\n\n const cardinality = useMemo(\n () => getSelectionCardinality(selection) ?? RegionCardinality.FULL_TABLE,\n [selection],\n );\n\n // Merge global actions with column-specific actions from the selection\n const allActions = useMemo(\n () => mergeColumnActions(actions, columnSpec, selection),\n [actions, columnSpec, selection],\n );\n\n const applicableActions = useMemo(\n () => getApplicableActions(allActions, cardinality, editable),\n [allActions, cardinality, editable],\n );\n\n // Context for `render`-style controls (they subscribe to the store\n // themselves; this resolves the selected column/rows).\n const ctx = buildActionContext(\n storeAPI.getState(),\n storeAPI.setState,\n ) as TableActionContext<T>;\n\n // The toolbar is for actions that AREN'T keyboard-accessible: any action\n // with a `hotkey` (copy/cut/paste, etc.) is reachable from the keyboard and\n // is omitted here (it still works via its shortcut). Then refine by selection\n // shape beyond cardinality (e.g. single column only).\n const shownActions = applicableActions.filter(\n (action) => action.hotkey == null && (action.appliesTo?.(ctx) ?? true),\n );\n\n const toolbarIsShown = useMemo(\n () => hasAnyDisplayableActions(actions, columnSpec),\n [actions, columnSpec],\n );\n\n if (!toolbarIsShown) {\n return null;\n }\n\n // The toolbar is always mounted if actions are available, so it can't flicker\n // in/out as the selection or action set changes — the container is stable;\n // only its contents (title + buttons) change. Avoids layout jank.\n const title = selectionTitle(ctx) ?? tableName ?? \"Table\";\n\n // Order left→right by generality: actions applicable to the whole table (or\n // no selection) are \"global\" and sit after a spacer on the right (Save /\n // Reset / Clear-selection); everything else is contextual and stays on the\n // left. So the left edge tracks the selection and the right edge is constant.\n const isGlobal = (a: TableAction<T>) =>\n a.targets.includes(RegionCardinality.FULL_TABLE) ||\n a.targets.includes(\"none\" as any);\n const contextual = shownActions.filter((a) => !isGlobal(a));\n // Order the built-in global actions least→most impactful, left→right:\n // clear selection, reset changes, save. Any other global actions keep their\n // natural order to the left of these (stable sort, rank 0).\n const globalOrder: Record<string, number> = {\n \"clear-selection\": 1,\n \"reset-changes\": 2,\n \"save-changes\": 3,\n };\n const globalActions = shownActions\n .filter(isGlobal)\n .sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));\n\n return h(\"div.actions-toolbar\", [\n h(\"span.toolbar-title\", { key: \"title\" }, title),\n h(\n ButtonGroup,\n { key: \"contextual\", minimal: true },\n contextual.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n h(\"div.toolbar-spacer\", { key: \"spacer\", style: { flex: 1 } }),\n h(\n ButtonGroup,\n { key: \"global\", minimal: true },\n globalActions.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n ]);\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nfunction isActionDisabled(action: TableAction, state: any): boolean {\n if (typeof action.disabled === \"boolean\") return action.disabled;\n if (typeof action.disabled === \"function\") {\n return action.disabled(state);\n }\n return false;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n state: DataSheetStore<any>,\n setState: (state: Partial<DataSheetStore<any>>) => void,\n toaster: any,\n configState: any = undefined,\n) {\n const ctx = buildActionContext(state, setState) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\n/** Dispatcher: a live control (`action.render`) or a run/detailsForm button.\n * Kept hook-free so the two paths don't share a hook order. */\nfunction ActionButton<T>({\n action,\n ctx,\n}: {\n action: TableAction<T>;\n ctx: TableActionContext<T>;\n}) {\n if (action.render != null) {\n return action.render(ctx) as any;\n }\n return h(RunActionButton, { action });\n}\n\n/** A run/detailsForm action rendered as a button. */\nfunction RunActionButton<T>({ action }: { action: TableAction<T> }) {\n const storeAPI = useStoreAPI();\n const toaster = useToaster();\n\n // Reactive disabled check — re-renders when relevant state changes\n const isDisabled = useSelector((state) => {\n return isActionDisabled(action, state);\n });\n\n const runAction = useCallback(\n (configState?: any) => {\n runActionWrapper(\n action,\n storeAPI.getState(),\n storeAPI.setState,\n toaster,\n configState,\n );\n },\n [storeAPI, action, toaster],\n );\n\n if (action.detailsForm != null) {\n return h(ActionButtonWithForm, { action, runAction, isDisabled });\n }\n\n return h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick() {\n runAction();\n },\n },\n action.name,\n );\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n\n/** Action button that opens a popover for pre-run configuration. */\nfunction ActionButtonWithForm<T, S>({\n action,\n runAction,\n isDisabled,\n}: {\n action: TableAction<T, S>;\n runAction: (configState?: S) => void;\n isDisabled: boolean;\n}) {\n const [configState, setConfigState] = useState<S>(\n action.defaultState ?? (null as S),\n );\n const [isOpen, setIsOpen] = useState(false);\n\n let ready = true;\n if (action.isReady != null) {\n ready = action.isReady(configState);\n }\n\n return h(\n PopoverNext,\n {\n isOpen,\n onClose: () => setIsOpen(false),\n content: h(\"div.action-popover-content\", [\n h.if(action.description != null)(\"p.description\", action.description),\n h(action.detailsForm, {\n state: configState,\n setState: setConfigState,\n }),\n h(\n Button,\n {\n className: \"run-button\",\n intent: action.intent ?? \"primary\",\n icon: \"play\",\n disabled: !ready,\n fill: true,\n onClick() {\n runAction(configState);\n setIsOpen(false);\n },\n },\n \"Run\",\n ),\n ]),\n placement: \"bottom-start\",\n enforceFocus: false,\n autoFocus: false,\n },\n h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick: () => setIsOpen(!isOpen),\n },\n action.name,\n ),\n );\n}\n\nfunction hasAnyDisplayableActions(\n actions: TableAction[],\n columnSpec: ColumnSpec[],\n) {\n /** Check whether there are any actions that can be displayed in the toolbar.\n * for the entire table. This is used to determine whether the toolbar should\n * be rendered. If any actions are available, the toolbar is rendered in ALL\n * selection modes to avoid flickering\n */\n const allActions = [\n ...actions,\n ...columnSpec.flatMap((c) => c.actions ?? []),\n ];\n\n if (allActions.length === 0) {\n return false;\n }\n // Check whether any action doesn't have hotkey and is not disabled\n return allActions.some(\n (action) => action.hotkey == null && !isActionDisabled(action, {}),\n );\n}\n"],"names":["RegionCardinality","selection","useSelector","useStoreAPI","useMemo","getSelectionCardinality","mergeColumnActions","getApplicableActions","buildActionContext","h","ButtonGroup","useToaster","useCallback","Button","useState","PopoverNext"],"mappings":";;;;;;;;;AAkBA,SAAS,eAAkB,KAA2C;AACpE,QAAM,KAAK,IAAI;AACf,UAAQ,GAAG,aAAA;AAAA,IACT,KAAKA,MAAAA,kBAAkB,cAAc;AACnC,UAAI,IAAI,aAAa,MAAM;AACzB,cAAM,MAAM,IAAI,WAAW,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,SAAS;AAC9D,eAAO,KAAK,QAAQ;AAAA,MACtB;AACA,aAAO,GAAG,GAAG,OAAO;AAAA,IACtB;AAAA,IACA,KAAKA,MAAAA,kBAAkB;AACrB,aAAO,IAAI,YAAY,OAAO,UAAU,GAAG,GAAG,IAAI;AAAA,IACpD,K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AK;AAAA,YACjB;AAAA,UAAA;AAAA,UAEF;AAAA,QAAA;AAAA,MACF,CACD;AAAA,MACD,WAAW;AAAA,MACX,cAAc;AAAA,MACd,WAAW;AAAA,IAAA;AAAA,IAEbJ,eAAAA;AAAAA,MACEI,KAAAA;AAAAA,MACA;AAAA,QACE,MAAM,OAAO;AAAA,QACb,QAAQ,OAAO;AAAA,QACf,UAAU;AAAA,QACV,SAAS,MAAM,UAAU,CAAC,MAAM;AAAA,MAAA;AAAA,MAElC,OAAO;AAAA,IAAA;AAAA,EACT;AAEJ;AAEA,SAAS,yBACP,SACA,YACA;AAMA,QAAM,aAAa;AAAA,IACjB,GAAG;AAAA,IACH,GAAG,WAAW,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA,CAAE;AAAA,EAAA;AAG9C,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO,WAAW;AAAA,IAChB,CAAC,WAAW,OAAO,UAAU,QAAQ,CAAC,iBAAiB,QAAQ,CAAA,CAAE;AAAA,EAAA;AAErE;;;"}
1
+ {"version":3,"file":"toolbar.cjs","sources":["../../src/actions/toolbar.ts"],"sourcesContent":["import { Button, ButtonGroup, PopoverNext, Tag } from \"@blueprintjs/core\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport h from \"./toolbar.module.sass\";\nimport { useSelector, useStoreAPI } from \"../provider\";\nimport {\n buildActionContext,\n getApplicableActions,\n getSelectionCardinality,\n mergeColumnActions,\n} from \"./selection\";\nimport type { TableAction, TableActionContext } from \"./types\";\nimport { RegionCardinality } from \"@blueprintjs/table\";\nimport { useToaster } from \"../notifications.ts\";\nimport { DataSheetStore } from \"../types.ts\";\nimport { ColumnSpec } from \"../utils\";\n\n/** A short title describing the current selection (its shape), shown as the\n * toolbar's leading label — no icon. */\nfunction selectionTitle<T>(ctx: TableActionContext<T>): string | null {\n const sh = ctx.selectionShape;\n switch (sh.cardinality) {\n case RegionCardinality.FULL_COLUMNS: {\n if (ctx.columnKey != null) {\n const col = ctx.columnSpec.find((c) => c.key === ctx.columnKey);\n return col?.name ?? \"Column\";\n }\n return `${sh.columns} columns`;\n }\n case RegionCardinality.FULL_ROWS:\n return ctx.rowIndex != null ? \"1 row\" : `${sh.rows} rows`;\n case RegionCardinality.CELLS:\n return ctx.cell != null ? \"Cell\" : `${sh.columns}×${sh.rows} cells`;\n case RegionCardinality.FULL_TABLE:\n return null;\n default:\n return null;\n }\n}\n\n/** Toolbar that renders the actions/controls applicable to the current\n * selection cardinality (modal by selection) and edit mode. Actions with a\n * `render` show their live control; others show a button (with an optional\n * `detailsForm` popover). Column-specific actions from `ColumnSpec.actions`\n * are merged when their columns are selected. A capsule on the left shows the\n * current selection polarity. */\nexport function ActionsToolbar<T>({\n actions,\n tableName,\n}: {\n actions: TableAction<T>[];\n tableName?: string;\n}) {\n const selection = useSelector((state) => state.selection);\n const editable = useSelector((state) => state.editable);\n const columnSpec = useSelector((state) => state.columnSpec);\n const storeAPI = useStoreAPI();\n\n const cardinality = useMemo(\n () => getSelectionCardinality(selection) ?? RegionCardinality.FULL_TABLE,\n [selection],\n );\n\n // Merge global actions with column-specific actions from the selection\n const allActions = useMemo(\n () => mergeColumnActions(actions, columnSpec, selection),\n [actions, columnSpec, selection],\n );\n\n const applicableActions = useMemo(\n () => getApplicableActions(allActions, cardinality, editable),\n [allActions, cardinality, editable],\n );\n\n // Context for `render`-style controls (they subscribe to the store\n // themselves; this resolves the selected column/rows).\n const ctx = buildActionContext(\n storeAPI.getState(),\n storeAPI.setState,\n ) as TableActionContext<T>;\n\n // The toolbar is for actions that AREN'T keyboard-accessible: any action\n // with a `hotkey` (copy/cut/paste, etc.) is reachable from the keyboard and\n // is omitted here (it still works via its shortcut). Then refine by selection\n // shape beyond cardinality (e.g. single column only).\n const shownActions = applicableActions.filter(\n (action) => action.hotkey == null && (action.appliesTo?.(ctx) ?? true),\n );\n\n const toolbarIsShown = useMemo(\n () => hasAnyDisplayableActions(actions, columnSpec),\n [actions, columnSpec],\n );\n\n if (!toolbarIsShown) {\n return null;\n }\n\n // The toolbar is always mounted if actions are available, so it can't flicker\n // in/out as the selection or action set changes — the container is stable;\n // only its contents (title + buttons) change. Avoids layout jank.\n //\n // The leading title doubles as the clear-selection affordance: with an active\n // selection it renders as a dismissible tag (its ✕ clears the selection),\n // which ties \"clear\" to the selection it acts on and frees toolbar space.\n // With no selection it's a plain label (table name).\n // Both states render as a `large` `Tag` so the title keeps a constant font\n // and height; only the selected one has a filled background + a ✕ (which\n // clears the selection). The unselected label is a transparent, non-removable\n // tag — visually a plain title, but the same box.\n const hasSelection = selection != null && selection.length > 0;\n const titleNode = h(\n Tag,\n {\n key: \"title\",\n minimal: true,\n large: true,\n onRemove: hasSelection\n ? () =>\n storeAPI.setState({\n selection: [],\n focusedCell: null,\n topLeftCell: null,\n })\n : undefined,\n style: hasSelection ? undefined : { background: \"transparent\" },\n },\n hasSelection\n ? (selectionTitle(ctx) ?? tableName ?? \"Selection\")\n : (tableName ?? \"Table\"),\n );\n\n // Order left→right by generality: actions applicable to the whole table (or\n // no selection) are \"global\" and sit after a spacer on the right (Save /\n // Reset); everything else is contextual and stays on the left. So the left\n // edge tracks the selection and the right edge is constant.\n const isGlobal = (a: TableAction<T>) =>\n a.targets.includes(RegionCardinality.FULL_TABLE) ||\n a.targets.includes(\"none\" as any);\n const contextual = shownActions.filter((a) => !isGlobal(a));\n // Order the built-in global actions least→most impactful, left→right: reset\n // changes, then save. Any other global actions keep their natural order to\n // the left of these (stable sort, rank 0).\n const globalOrder: Record<string, number> = {\n \"reset-changes\": 1,\n \"save-changes\": 2,\n };\n const globalActions = shownActions\n .filter(isGlobal)\n .sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));\n\n return h(\"div.actions-toolbar\", [\n titleNode,\n h(\n ButtonGroup,\n { key: \"contextual\", minimal: true },\n contextual.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n h(\"div.toolbar-spacer\", { key: \"spacer\", style: { flex: 1 } }),\n h(\n ButtonGroup,\n { key: \"global\", minimal: true },\n globalActions.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n ]);\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nfunction isActionDisabled(action: TableAction, state: any): boolean {\n if (typeof action.disabled === \"boolean\") return action.disabled;\n if (typeof action.disabled === \"function\") {\n return action.disabled(state);\n }\n return false;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n state: DataSheetStore<any>,\n setState: (state: Partial<DataSheetStore<any>>) => void,\n toaster: any,\n configState: any = undefined,\n) {\n const ctx = buildActionContext(state, setState) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\n/** Dispatcher: a live control (`action.render`) or a run/detailsForm button.\n * Kept hook-free so the two paths don't share a hook order. */\nfunction ActionButton<T>({\n action,\n ctx,\n}: {\n action: TableAction<T>;\n ctx: TableActionContext<T>;\n}) {\n if (action.render != null) {\n return action.render(ctx) as any;\n }\n return h(RunActionButton, { action });\n}\n\n/** A run/detailsForm action rendered as a button. */\nfunction RunActionButton<T>({ action }: { action: TableAction<T> }) {\n const storeAPI = useStoreAPI();\n const toaster = useToaster();\n\n // Reactive disabled check — re-renders when relevant state changes\n const isDisabled = useSelector((state) => {\n return isActionDisabled(action, state);\n });\n\n const runAction = useCallback(\n (configState?: any) => {\n runActionWrapper(\n action,\n storeAPI.getState(),\n storeAPI.setState,\n toaster,\n configState,\n );\n },\n [storeAPI, action, toaster],\n );\n\n if (action.detailsForm != null) {\n return h(ActionButtonWithForm, { action, runAction, isDisabled });\n }\n\n return h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick() {\n runAction();\n },\n },\n action.name,\n );\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n\n/** Action button that opens a popover for pre-run configuration. */\nfunction ActionButtonWithForm<T, S>({\n action,\n runAction,\n isDisabled,\n}: {\n action: TableAction<T, S>;\n runAction: (configState?: S) => void;\n isDisabled: boolean;\n}) {\n const [configState, setConfigState] = useState<S>(\n action.defaultState ?? (null as S),\n );\n const [isOpen, setIsOpen] = useState(false);\n\n let ready = true;\n if (action.isReady != null) {\n ready = action.isReady(configState);\n }\n\n return h(\n PopoverNext,\n {\n isOpen,\n onClose: () => setIsOpen(false),\n content: h(\"div.action-popover-content\", [\n h.if(action.description != null)(\"p.description\", action.description),\n h(action.detailsForm, {\n state: configState,\n setState: setConfigState,\n }),\n h(\n Button,\n {\n className: \"run-button\",\n intent: action.intent ?? \"primary\",\n icon: \"play\",\n disabled: !ready,\n fill: true,\n onClick() {\n runAction(configState);\n setIsOpen(false);\n },\n },\n \"Run\",\n ),\n ]),\n placement: \"bottom-start\",\n enforceFocus: false,\n autoFocus: false,\n },\n h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick: () => setIsOpen(!isOpen),\n },\n action.name,\n ),\n );\n}\n\nfunction hasAnyDisplayableActions(\n actions: TableAction[],\n columnSpec: ColumnSpec[],\n) {\n /** Check whether there are any actions that can be displayed in the toolbar.\n * for the entire table. This is used to determine whether the toolbar should\n * be rendered. If any actions are available, the toolbar is rendered in ALL\n * selection modes to avoid flickering\n */\n const allActions = [\n ...actions,\n ...columnSpec.flatMap((c) => c.actions ?? []),\n ];\n\n if (allActions.length === 0) {\n return false;\n }\n // Check whether any action doesn't have hotkey and is not disabled\n return allActions.some(\n (action) => action.hotkey == null && !isActionDisabled(action, {}),\n );\n}\n"],"names":["RegionCardinality","selection","useSelector","useStoreAPI","useMemo","getSelectionCardinality","mergeColumnActions","getApplicableActions","buildActionContext","h","Tag","ButtonGroup","useToaster","useCallback","Button","useState","PopoverNext"],"mappings":";;;;;;;;;AAkBA,SAAS,eAAkB,KAA2C;AACpE,QAAM,KAAK,IAAI;AACf,UAAQ,GAAG,aAAA;AAAA,IACT,KAAKA,MAAAA,kBAAkB,cAAc;AACnC,UAAI,IAAI,aAAa,MAAM;AACzB,cAAM,MAAM,IAAI,WAAW,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,SAAS;AAC9D,eAAO,KAAK,QAAQ;AAAA,MACtB;AACA,aAAO,GAAG,GAAG,OAAO;AAAA,IACtB;AAAA,IACA,KAAKA,MAAAA,kBAAkB;AACrB,aAAO,IAAI,YAAY,OAAO,UAAU,GAAG,GAAG,IAAI;AAAA,IACpD,KAAKA,MAAAA,kBAAkB;AACrB,aAAO,IAAI,QAAQ,OAAO,SAAS,GAAG,GAAG,OAAO,IAAI,GAAG,IAAI;AAAA,IAC7D,KAAKA,MAAAA,kBAAkB;AACrB,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EAAA;AAEb;AAQO,SAAS,eAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAGG;AACD,QAAMC,cAAYC,SAAAA,YAAY,CAAC,UAAU,MAAM,SAAS;AACxD,QAAM,WAAWA,SAAAA,YAAY,CAAC,UAAU,MAAM,QAAQ;AACtD,QAAM,aAAaA,SAAAA,YAAY,CAAC,UAAU,MAAM,UAAU;AAC1D,QAAM,WAAWC,SAAAA,YAAA;AAEjB,QAAM,cAAcC,MAAAA;AAAAA,IAClB,MAAMC,kCAAwBJ,WAAS,KAAKD,MAAAA,kBAAkB;AAAA,IAC9D,CAACC,WAAS;AAAA,EAAA;AAIZ,QAAM,aAAaG,MAAAA;AAAAA,IACjB,MAAME,6BAAmB,SAAS,YAAYL,WAAS;A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BACP,SACA,YACA;AAMA,QAAM,aAAa;AAAA,IACjB,GAAG;AAAA,IACH,GAAG,WAAW,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA,CAAE;AAAA,EAAA;AAG9C,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO,WAAW;AAAA,IAChB,CAAC,WAAW,OAAO,UAAU,QAAQ,CAAC,iBAAiB,QAAQ,CAAA,CAAE;AAAA,EAAA;AAErE;;;"}
@@ -1,4 +1,4 @@
1
- import { ButtonGroup, Button, PopoverNext } from "@blueprintjs/core";
1
+ import { Tag, ButtonGroup, Button, PopoverNext } from "@blueprintjs/core";
2
2
  import { useMemo, useCallback, useState } from "react";
3
3
  import h from "./toolbar.module.sass.js";
4
4
  import { useSelector, useStoreAPI } from "../provider.js";
@@ -59,17 +59,31 @@ function ActionsToolbar({
59
59
  if (!toolbarIsShown) {
60
60
  return null;
61
61
  }
62
- const title = selectionTitle(ctx) ?? tableName ?? "Table";
62
+ const hasSelection = selection != null && selection.length > 0;
63
+ const titleNode = h(
64
+ Tag,
65
+ {
66
+ key: "title",
67
+ minimal: true,
68
+ large: true,
69
+ onRemove: hasSelection ? () => storeAPI.setState({
70
+ selection: [],
71
+ focusedCell: null,
72
+ topLeftCell: null
73
+ }) : void 0,
74
+ style: hasSelection ? void 0 : { background: "transparent" }
75
+ },
76
+ hasSelection ? selectionTitle(ctx) ?? tableName ?? "Selection" : tableName ?? "Table"
77
+ );
63
78
  const isGlobal = (a) => a.targets.includes(RegionCardinality.FULL_TABLE) || a.targets.includes("none");
64
79
  const contextual = shownActions.filter((a) => !isGlobal(a));
65
80
  const globalOrder = {
66
- "clear-selection": 1,
67
- "reset-changes": 2,
68
- "save-changes": 3
81
+ "reset-changes": 1,
82
+ "save-changes": 2
69
83
  };
70
84
  const globalActions = shownActions.filter(isGlobal).sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));
71
85
  return h("div.actions-toolbar", [
72
- h("span.toolbar-title", { key: "title" }, title),
86
+ titleNode,
73
87
  h(
74
88
  ButtonGroup,
75
89
  { key: "contextual", minimal: true },
@@ -1 +1 @@
1
- {"version":3,"file":"toolbar.js","sources":["../../src/actions/toolbar.ts"],"sourcesContent":["import { Button, ButtonGroup, PopoverNext } from \"@blueprintjs/core\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport h from \"./toolbar.module.sass\";\nimport { useSelector, useStoreAPI } from \"../provider\";\nimport {\n buildActionContext,\n getApplicableActions,\n getSelectionCardinality,\n mergeColumnActions,\n} from \"./selection\";\nimport type { TableAction, TableActionContext } from \"./types\";\nimport { RegionCardinality } from \"@blueprintjs/table\";\nimport { useToaster } from \"../notifications.ts\";\nimport { DataSheetStore } from \"../types.ts\";\nimport { ColumnSpec } from \"../utils\";\n\n/** A short title describing the current selection (its shape), shown as the\n * toolbar's leading label — no icon. */\nfunction selectionTitle<T>(ctx: TableActionContext<T>): string | null {\n const sh = ctx.selectionShape;\n switch (sh.cardinality) {\n case RegionCardinality.FULL_COLUMNS: {\n if (ctx.columnKey != null) {\n const col = ctx.columnSpec.find((c) => c.key === ctx.columnKey);\n return col?.name ?? \"Column\";\n }\n return `${sh.columns} columns`;\n }\n case RegionCardinality.FULL_ROWS:\n return ctx.rowIndex != null ? \"1 row\" : `${sh.rows} rows`;\n case RegionCardinality.CELLS:\n return ctx.cell != null ? \"Cell\" : `${sh.columns}×${sh.rows} cells`;\n case RegionCardinality.FULL_TABLE:\n return null;\n default:\n return null;\n }\n}\n\n/** Toolbar that renders the actions/controls applicable to the current\n * selection cardinality (modal by selection) and edit mode. Actions with a\n * `render` show their live control; others show a button (with an optional\n * `detailsForm` popover). Column-specific actions from `ColumnSpec.actions`\n * are merged when their columns are selected. A capsule on the left shows the\n * current selection polarity. */\nexport function ActionsToolbar<T>({\n actions,\n tableName,\n}: {\n actions: TableAction<T>[];\n tableName?: string;\n}) {\n const selection = useSelector((state) => state.selection);\n const editable = useSelector((state) => state.editable);\n const columnSpec = useSelector((state) => state.columnSpec);\n const storeAPI = useStoreAPI();\n\n const cardinality = useMemo(\n () => getSelectionCardinality(selection) ?? RegionCardinality.FULL_TABLE,\n [selection],\n );\n\n // Merge global actions with column-specific actions from the selection\n const allActions = useMemo(\n () => mergeColumnActions(actions, columnSpec, selection),\n [actions, columnSpec, selection],\n );\n\n const applicableActions = useMemo(\n () => getApplicableActions(allActions, cardinality, editable),\n [allActions, cardinality, editable],\n );\n\n // Context for `render`-style controls (they subscribe to the store\n // themselves; this resolves the selected column/rows).\n const ctx = buildActionContext(\n storeAPI.getState(),\n storeAPI.setState,\n ) as TableActionContext<T>;\n\n // The toolbar is for actions that AREN'T keyboard-accessible: any action\n // with a `hotkey` (copy/cut/paste, etc.) is reachable from the keyboard and\n // is omitted here (it still works via its shortcut). Then refine by selection\n // shape beyond cardinality (e.g. single column only).\n const shownActions = applicableActions.filter(\n (action) => action.hotkey == null && (action.appliesTo?.(ctx) ?? true),\n );\n\n const toolbarIsShown = useMemo(\n () => hasAnyDisplayableActions(actions, columnSpec),\n [actions, columnSpec],\n );\n\n if (!toolbarIsShown) {\n return null;\n }\n\n // The toolbar is always mounted if actions are available, so it can't flicker\n // in/out as the selection or action set changes — the container is stable;\n // only its contents (title + buttons) change. Avoids layout jank.\n const title = selectionTitle(ctx) ?? tableName ?? \"Table\";\n\n // Order left→right by generality: actions applicable to the whole table (or\n // no selection) are \"global\" and sit after a spacer on the right (Save /\n // Reset / Clear-selection); everything else is contextual and stays on the\n // left. So the left edge tracks the selection and the right edge is constant.\n const isGlobal = (a: TableAction<T>) =>\n a.targets.includes(RegionCardinality.FULL_TABLE) ||\n a.targets.includes(\"none\" as any);\n const contextual = shownActions.filter((a) => !isGlobal(a));\n // Order the built-in global actions least→most impactful, left→right:\n // clear selection, reset changes, save. Any other global actions keep their\n // natural order to the left of these (stable sort, rank 0).\n const globalOrder: Record<string, number> = {\n \"clear-selection\": 1,\n \"reset-changes\": 2,\n \"save-changes\": 3,\n };\n const globalActions = shownActions\n .filter(isGlobal)\n .sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));\n\n return h(\"div.actions-toolbar\", [\n h(\"span.toolbar-title\", { key: \"title\" }, title),\n h(\n ButtonGroup,\n { key: \"contextual\", minimal: true },\n contextual.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n h(\"div.toolbar-spacer\", { key: \"spacer\", style: { flex: 1 } }),\n h(\n ButtonGroup,\n { key: \"global\", minimal: true },\n globalActions.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n ]);\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nfunction isActionDisabled(action: TableAction, state: any): boolean {\n if (typeof action.disabled === \"boolean\") return action.disabled;\n if (typeof action.disabled === \"function\") {\n return action.disabled(state);\n }\n return false;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n state: DataSheetStore<any>,\n setState: (state: Partial<DataSheetStore<any>>) => void,\n toaster: any,\n configState: any = undefined,\n) {\n const ctx = buildActionContext(state, setState) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\n/** Dispatcher: a live control (`action.render`) or a run/detailsForm button.\n * Kept hook-free so the two paths don't share a hook order. */\nfunction ActionButton<T>({\n action,\n ctx,\n}: {\n action: TableAction<T>;\n ctx: TableActionContext<T>;\n}) {\n if (action.render != null) {\n return action.render(ctx) as any;\n }\n return h(RunActionButton, { action });\n}\n\n/** A run/detailsForm action rendered as a button. */\nfunction RunActionButton<T>({ action }: { action: TableAction<T> }) {\n const storeAPI = useStoreAPI();\n const toaster = useToaster();\n\n // Reactive disabled check — re-renders when relevant state changes\n const isDisabled = useSelector((state) => {\n return isActionDisabled(action, state);\n });\n\n const runAction = useCallback(\n (configState?: any) => {\n runActionWrapper(\n action,\n storeAPI.getState(),\n storeAPI.setState,\n toaster,\n configState,\n );\n },\n [storeAPI, action, toaster],\n );\n\n if (action.detailsForm != null) {\n return h(ActionButtonWithForm, { action, runAction, isDisabled });\n }\n\n return h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick() {\n runAction();\n },\n },\n action.name,\n );\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n\n/** Action button that opens a popover for pre-run configuration. */\nfunction ActionButtonWithForm<T, S>({\n action,\n runAction,\n isDisabled,\n}: {\n action: TableAction<T, S>;\n runAction: (configState?: S) => void;\n isDisabled: boolean;\n}) {\n const [configState, setConfigState] = useState<S>(\n action.defaultState ?? (null as S),\n );\n const [isOpen, setIsOpen] = useState(false);\n\n let ready = true;\n if (action.isReady != null) {\n ready = action.isReady(configState);\n }\n\n return h(\n PopoverNext,\n {\n isOpen,\n onClose: () => setIsOpen(false),\n content: h(\"div.action-popover-content\", [\n h.if(action.description != null)(\"p.description\", action.description),\n h(action.detailsForm, {\n state: configState,\n setState: setConfigState,\n }),\n h(\n Button,\n {\n className: \"run-button\",\n intent: action.intent ?? \"primary\",\n icon: \"play\",\n disabled: !ready,\n fill: true,\n onClick() {\n runAction(configState);\n setIsOpen(false);\n },\n },\n \"Run\",\n ),\n ]),\n placement: \"bottom-start\",\n enforceFocus: false,\n autoFocus: false,\n },\n h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick: () => setIsOpen(!isOpen),\n },\n action.name,\n ),\n );\n}\n\nfunction hasAnyDisplayableActions(\n actions: TableAction[],\n columnSpec: ColumnSpec[],\n) {\n /** Check whether there are any actions that can be displayed in the toolbar.\n * for the entire table. This is used to determine whether the toolbar should\n * be rendered. If any actions are available, the toolbar is rendered in ALL\n * selection modes to avoid flickering\n */\n const allActions = [\n ...actions,\n ...columnSpec.flatMap((c) => c.actions ?? []),\n ];\n\n if (allActions.length === 0) {\n return false;\n }\n // Check whether any action doesn't have hotkey and is not disabled\n return allActions.some(\n (action) => action.hotkey == null && !isActionDisabled(action, {}),\n );\n}\n"],"names":[],"mappings":";;;;;;;AAkBA,SAAS,eAAkB,KAA2C;AACpE,QAAM,KAAK,IAAI;AACf,UAAQ,GAAG,aAAA;AAAA,IACT,KAAK,kBAAkB,cAAc;AACnC,UAAI,IAAI,aAAa,MAAM;AACzB,cAAM,MAAM,IAAI,WAAW,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,SAAS;AAC9D,eAAO,KAAK,QAAQ;AAAA,MACtB;AACA,aAAO,GAAG,GAAG,OAAO;AAAA,IACtB;AAAA,IACA,KAAK,kBAAkB;AACrB,aAAO,IAAI,YAAY,OAAO,UAAU,GAAG,GAAG,IAAI;AAAA,IACpD,KAAK,kBAAkB;AACrB,aAAO,IAAI,QAAQ,OAAO,SAAS,GAAG,GAAG,OAAO,IAAI,GAAG,IAAI;AAAA,IAC7D,KAAK,kBAAkB;AACrB,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EAAA;AAEb;AAQO,SAAS,eAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAGG;AACD,QAAM,YAAY,YAAY,CAAC,UAAU,MAAM,SAAS;AACxD,QAAM,WAAW,YAAY,CAAC,UAAU,MAAM,QAAQ;AACtD,QAAM,aAAa,YAAY,CAAC,UAAU,MAAM,UAAU;AAC1D,QAAM,WAAW,YAAA;AAEjB,QAAM,cAAc;AAAA,IAClB,MAAM,wBAAwB,SAAS,KAAK,kBAAkB;AAAA,IAC9D,CAAC,SAAS;AAAA,EAAA;AAIZ,QAAM,aAAa;AAAA,IACj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AK;AAAA,MAC9B,SAAS,EAAE,8BAA8B;AAAA,QACvC,EAAE,GAAG,OAAO,eAAe,IAAI,EAAE,iBAAiB,OAAO,WAAW;AAAA,QACpE,EAAE,OAAO,aAAa;AAAA,UACpB,OAAO;AAAA,UACP,UAAU;AAAA,QAAA,CACX;AAAA,QACD;AAAA,UACE;AAAA,UACA;AAAA,YACE,WAAW;AAAA,YACX,QAAQ,OAAO,UAAU;AAAA,YACzB,MAAM;AAAA,YACN,UAAU,CAAC;AAAA,YACX,MAAM;AAAA,YACN,UAAU;AACR,wBAAU,WAAW;AACrB,wBAAU,KAAK;AAAA,YACjB;AAAA,UAAA;AAAA,UAEF;AAAA,QAAA;AAAA,MACF,CACD;AAAA,MACD,WAAW;AAAA,MACX,cAAc;AAAA,MACd,WAAW;AAAA,IAAA;AAAA,IAEb;AAAA,MACE;AAAA,MACA;AAAA,QACE,MAAM,OAAO;AAAA,QACb,QAAQ,OAAO;AAAA,QACf,UAAU;AAAA,QACV,SAAS,MAAM,UAAU,CAAC,MAAM;AAAA,MAAA;AAAA,MAElC,OAAO;AAAA,IAAA;AAAA,EACT;AAEJ;AAEA,SAAS,yBACP,SACA,YACA;AAMA,QAAM,aAAa;AAAA,IACjB,GAAG;AAAA,IACH,GAAG,WAAW,QAAQ,CAAC,MAAM,EAAE,WAAW,CAAA,CAAE;AAAA,EAAA;AAG9C,MAAI,WAAW,WAAW,GAAG;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO,WAAW;AAAA,IAChB,CAAC,WAAW,OAAO,UAAU,QAAQ,CAAC,iBAAiB,QAAQ,CAAA,CAAE;AAAA,EAAA;AAErE;"}
1
+ {"version":3,"file":"toolbar.js","sources":["../../src/actions/toolbar.ts"],"sourcesContent":["import { Button, ButtonGroup, PopoverNext, Tag } from \"@blueprintjs/core\";\nimport { useCallback, useMemo, useState } from \"react\";\nimport h from \"./toolbar.module.sass\";\nimport { useSelector, useStoreAPI } from \"../provider\";\nimport {\n buildActionContext,\n getApplicableActions,\n getSelectionCardinality,\n mergeColumnActions,\n} from \"./selection\";\nimport type { TableAction, TableActionContext } from \"./types\";\nimport { RegionCardinality } from \"@blueprintjs/table\";\nimport { useToaster } from \"../notifications.ts\";\nimport { DataSheetStore } from \"../types.ts\";\nimport { ColumnSpec } from \"../utils\";\n\n/** A short title describing the current selection (its shape), shown as the\n * toolbar's leading label — no icon. */\nfunction selectionTitle<T>(ctx: TableActionContext<T>): string | null {\n const sh = ctx.selectionShape;\n switch (sh.cardinality) {\n case RegionCardinality.FULL_COLUMNS: {\n if (ctx.columnKey != null) {\n const col = ctx.columnSpec.find((c) => c.key === ctx.columnKey);\n return col?.name ?? \"Column\";\n }\n return `${sh.columns} columns`;\n }\n case RegionCardinality.FULL_ROWS:\n return ctx.rowIndex != null ? \"1 row\" : `${sh.rows} rows`;\n case RegionCardinality.CELLS:\n return ctx.cell != null ? \"Cell\" : `${sh.columns}×${sh.rows} cells`;\n case RegionCardinality.FULL_TABLE:\n return null;\n default:\n return null;\n }\n}\n\n/** Toolbar that renders the actions/controls applicable to the current\n * selection cardinality (modal by selection) and edit mode. Actions with a\n * `render` show their live control; others show a button (with an optional\n * `detailsForm` popover). Column-specific actions from `ColumnSpec.actions`\n * are merged when their columns are selected. A capsule on the left shows the\n * current selection polarity. */\nexport function ActionsToolbar<T>({\n actions,\n tableName,\n}: {\n actions: TableAction<T>[];\n tableName?: string;\n}) {\n const selection = useSelector((state) => state.selection);\n const editable = useSelector((state) => state.editable);\n const columnSpec = useSelector((state) => state.columnSpec);\n const storeAPI = useStoreAPI();\n\n const cardinality = useMemo(\n () => getSelectionCardinality(selection) ?? RegionCardinality.FULL_TABLE,\n [selection],\n );\n\n // Merge global actions with column-specific actions from the selection\n const allActions = useMemo(\n () => mergeColumnActions(actions, columnSpec, selection),\n [actions, columnSpec, selection],\n );\n\n const applicableActions = useMemo(\n () => getApplicableActions(allActions, cardinality, editable),\n [allActions, cardinality, editable],\n );\n\n // Context for `render`-style controls (they subscribe to the store\n // themselves; this resolves the selected column/rows).\n const ctx = buildActionContext(\n storeAPI.getState(),\n storeAPI.setState,\n ) as TableActionContext<T>;\n\n // The toolbar is for actions that AREN'T keyboard-accessible: any action\n // with a `hotkey` (copy/cut/paste, etc.) is reachable from the keyboard and\n // is omitted here (it still works via its shortcut). Then refine by selection\n // shape beyond cardinality (e.g. single column only).\n const shownActions = applicableActions.filter(\n (action) => action.hotkey == null && (action.appliesTo?.(ctx) ?? true),\n );\n\n const toolbarIsShown = useMemo(\n () => hasAnyDisplayableActions(actions, columnSpec),\n [actions, columnSpec],\n );\n\n if (!toolbarIsShown) {\n return null;\n }\n\n // The toolbar is always mounted if actions are available, so it can't flicker\n // in/out as the selection or action set changes — the container is stable;\n // only its contents (title + buttons) change. Avoids layout jank.\n //\n // The leading title doubles as the clear-selection affordance: with an active\n // selection it renders as a dismissible tag (its ✕ clears the selection),\n // which ties \"clear\" to the selection it acts on and frees toolbar space.\n // With no selection it's a plain label (table name).\n // Both states render as a `large` `Tag` so the title keeps a constant font\n // and height; only the selected one has a filled background + a ✕ (which\n // clears the selection). The unselected label is a transparent, non-removable\n // tag — visually a plain title, but the same box.\n const hasSelection = selection != null && selection.length > 0;\n const titleNode = h(\n Tag,\n {\n key: \"title\",\n minimal: true,\n large: true,\n onRemove: hasSelection\n ? () =>\n storeAPI.setState({\n selection: [],\n focusedCell: null,\n topLeftCell: null,\n })\n : undefined,\n style: hasSelection ? undefined : { background: \"transparent\" },\n },\n hasSelection\n ? (selectionTitle(ctx) ?? tableName ?? \"Selection\")\n : (tableName ?? \"Table\"),\n );\n\n // Order left→right by generality: actions applicable to the whole table (or\n // no selection) are \"global\" and sit after a spacer on the right (Save /\n // Reset); everything else is contextual and stays on the left. So the left\n // edge tracks the selection and the right edge is constant.\n const isGlobal = (a: TableAction<T>) =>\n a.targets.includes(RegionCardinality.FULL_TABLE) ||\n a.targets.includes(\"none\" as any);\n const contextual = shownActions.filter((a) => !isGlobal(a));\n // Order the built-in global actions least→most impactful, left→right: reset\n // changes, then save. Any other global actions keep their natural order to\n // the left of these (stable sort, rank 0).\n const globalOrder: Record<string, number> = {\n \"reset-changes\": 1,\n \"save-changes\": 2,\n };\n const globalActions = shownActions\n .filter(isGlobal)\n .sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));\n\n return h(\"div.actions-toolbar\", [\n titleNode,\n h(\n ButtonGroup,\n { key: \"contextual\", minimal: true },\n contextual.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n h(\"div.toolbar-spacer\", { key: \"spacer\", style: { flex: 1 } }),\n h(\n ButtonGroup,\n { key: \"global\", minimal: true },\n globalActions.map((action) =>\n h(ActionButton, { key: action.id, action, ctx }),\n ),\n ),\n ]);\n}\n\nfunction getMessageForError(e: any) {\n if (e instanceof Error) return e.message;\n if (typeof e === \"string\") return e;\n if (e instanceof Object) return JSON.stringify(e);\n return null;\n}\n\nfunction isActionDisabled(action: TableAction, state: any): boolean {\n if (typeof action.disabled === \"boolean\") return action.disabled;\n if (typeof action.disabled === \"function\") {\n return action.disabled(state);\n }\n return false;\n}\n\nexport function runActionWrapper<T>(\n action: TableAction<T>,\n state: DataSheetStore<any>,\n setState: (state: Partial<DataSheetStore<any>>) => void,\n toaster: any,\n configState: any = undefined,\n) {\n const ctx = buildActionContext(state, setState) as TableActionContext<T>;\n if (action.disabled instanceof Function) {\n if (action.disabled(ctx)) {\n return;\n }\n } else if (action.disabled) {\n return;\n }\n try {\n const res = action.run?.(ctx, configState);\n if (res instanceof Promise) {\n res\n .then(() => {})\n .catch((e) => {\n displayErrorForAction(action, e, toaster);\n });\n }\n } catch (e) {\n displayErrorForAction(action, e, toaster);\n }\n}\n\n/** Dispatcher: a live control (`action.render`) or a run/detailsForm button.\n * Kept hook-free so the two paths don't share a hook order. */\nfunction ActionButton<T>({\n action,\n ctx,\n}: {\n action: TableAction<T>;\n ctx: TableActionContext<T>;\n}) {\n if (action.render != null) {\n return action.render(ctx) as any;\n }\n return h(RunActionButton, { action });\n}\n\n/** A run/detailsForm action rendered as a button. */\nfunction RunActionButton<T>({ action }: { action: TableAction<T> }) {\n const storeAPI = useStoreAPI();\n const toaster = useToaster();\n\n // Reactive disabled check — re-renders when relevant state changes\n const isDisabled = useSelector((state) => {\n return isActionDisabled(action, state);\n });\n\n const runAction = useCallback(\n (configState?: any) => {\n runActionWrapper(\n action,\n storeAPI.getState(),\n storeAPI.setState,\n toaster,\n configState,\n );\n },\n [storeAPI, action, toaster],\n );\n\n if (action.detailsForm != null) {\n return h(ActionButtonWithForm, { action, runAction, isDisabled });\n }\n\n return h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick() {\n runAction();\n },\n },\n action.name,\n );\n}\n\nfunction displayErrorForAction(action: TableAction, error: any, toaster: any) {\n const message =\n getMessageForError(error) ?? action.errorMessage ?? \"Action failed\";\n toaster.show({\n message,\n intent: \"danger\",\n });\n}\n\n/** Action button that opens a popover for pre-run configuration. */\nfunction ActionButtonWithForm<T, S>({\n action,\n runAction,\n isDisabled,\n}: {\n action: TableAction<T, S>;\n runAction: (configState?: S) => void;\n isDisabled: boolean;\n}) {\n const [configState, setConfigState] = useState<S>(\n action.defaultState ?? (null as S),\n );\n const [isOpen, setIsOpen] = useState(false);\n\n let ready = true;\n if (action.isReady != null) {\n ready = action.isReady(configState);\n }\n\n return h(\n PopoverNext,\n {\n isOpen,\n onClose: () => setIsOpen(false),\n content: h(\"div.action-popover-content\", [\n h.if(action.description != null)(\"p.description\", action.description),\n h(action.detailsForm, {\n state: configState,\n setState: setConfigState,\n }),\n h(\n Button,\n {\n className: \"run-button\",\n intent: action.intent ?? \"primary\",\n icon: \"play\",\n disabled: !ready,\n fill: true,\n onClick() {\n runAction(configState);\n setIsOpen(false);\n },\n },\n \"Run\",\n ),\n ]),\n placement: \"bottom-start\",\n enforceFocus: false,\n autoFocus: false,\n },\n h(\n Button,\n {\n icon: action.icon,\n intent: action.intent,\n disabled: isDisabled,\n onClick: () => setIsOpen(!isOpen),\n },\n action.name,\n ),\n );\n}\n\nfunction hasAnyDisplayableActions(\n actions: TableAction[],\n columnSpec: ColumnSpec[],\n) {\n /** Check whether there are any actions that can be displayed in the toolbar.\n * for the entire table. This is used to determine whether the toolbar should\n * be rendered. If any actions are available, the toolbar is rendered in ALL\n * selection modes to avoid flickering\n */\n const allActions = [\n ...actions,\n ...columnSpec.flatMap((c) => c.actions ?? []),\n ];\n\n if (allActions.length === 0) {\n return false;\n }\n // Check whether any action doesn't have hotkey and is not disabled\n return allActions.some(\n (action) => action.hotkey == null && !isActionDisabled(action, {}),\n );\n}\n"],"names":[],"mappings":";;;;;;;AAkBA,SAAS,eAAkB,KAA2C;AACpE,QAAM,KAAK,IAAI;AACf,UAAQ,GAAG,aAAA;AAAA,IACT,KAAK,kBAAkB,cAAc;AACnC,UAAI,IAAI,aAAa,MAAM;AACzB,cAAM,MAAM,IAAI,WAAW,KAAK,CAAC,MAAM,EAAE,QAAQ,IAAI,SAAS;AAC9D,eAAO,KAAK,QAAQ;AAAA,MACtB;AACA,aAAO,GAAG,GAAG,OAAO;AAAA,IACtB;AAAA,IACA,KAAK,kBAAkB;AACrB,aAAO,IAAI,YAAY,OAAO,UAAU,GAAG,GAAG,IAAI;AAAA,IACpD,KAAK,kBAAkB;AACrB,aAAO,IAAI,QAAQ,OAAO,SAAS,GAAG,GAAG,OAAO,IAAI,GAAG,IAAI;AAAA,IAC7D,KAAK,kBAAkB;AACrB,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EAAA;AAEb;AAQO,SAAS,eAAkB;AAAA,EAChC;AAAA,EACA;AACF,GAGG;AACD,QAAM,YAAY,YAAY,CAAC,UAAU,MAAM,SAAS;AACxD,QAAM,WAAW,YAAY,CAAC,UAAU,MAAM,QAAQ;AACtD,QAAM,aAAa,YAAY,CAAC,UAAU,MAAM,UAAU;AAC1D,QAAM,WAAW,YAAA;AAEjB,QAAM,cAAc;AAAA,IAClB,MAAM,wBAA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AAG;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO,WAAW;AAAA,IAChB,CAAC,WAAW,OAAO,UAAU,QAAQ,CAAC,iBAAiB,QAAQ,CAAA,CAAE;AAAA,EAAA;AAErE;"}
@@ -191,7 +191,7 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
191
191
  isEdited: edited,
192
192
  onChange(value2) {
193
193
  if (!editable) return;
194
- state.onSelectionEdited(value2);
194
+ state.onCellEdited(dataRowIndex, col.key, value2);
195
195
  },
196
196
  resetValue() {
197
197
  state.resetChanges();
@@ -1 +1 @@
1
- {"version":3,"file":"cell-renderer.cjs","sources":["../src/cell-renderer.ts"],"sourcesContent":["import {\n ColumnSpec,\n CellRenderContext,\n CellDetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const statusVal = state.rowStatus[dataRowIndex];\n const isDeleted = statusVal == TableElementStatus.DELETED;\n // Presentation for this row's status (deleted, or a consumer-defined status\n // like \"omitted\"), from the merged `rowStatusStyles`.\n const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : undefined;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n status: statusVal,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object, then layer\n // the row-status presentation (deleted → dimmed/struck-through by default;\n // consumer statuses supply their own `cellStyle`).\n let style = { ...(col.style ?? {}) };\n\n if (statusStyle?.cellStyle != null) {\n style = { ...style, ...statusStyle.cellStyle };\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > row-status intent > edited. Validation\n // state overrides the edited-green so an edited-but-invalid cell reads as\n // invalid. A row's status intent (e.g. deleted → danger) outranks the\n // edited-green so status reads through even on an edited row.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (statusStyle?.intent != null) {\n intent = statusStyle.intent;\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["TableElementStatus","validation","validateCell","Cell","h","CellDetailModal","EditorPopup","value","className","singleFocusedCell","ctx","editorKeyHandlerAtom","useSelector","useRef","useState","useEffect"],"mappings":";;;;;;;;;;;;AAeO,SAAS,kBACd,UACA,UACA,YACA,OACA,oBACK;AAOL,QAAM,cAAc,MAAM;AAG1B,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY;AAC9C,QAAM,YAAY,aAAaA,MAAAA,mBAAmB;AAGlD,QAAM,cAAc,aAAa,OAAO,MAAM,kBAAkB,SAAS,IAAI;AAE7E,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,KAAK,YAAY,IAAI,IAAI,GAAG;AACtE,QAAM,UAAU,SAAS,QAAQ,UAAU;AAE3C,QAAM,SACJ,YAAY,YAAY,IAAI,I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AG,SAAS;AACrC,QAAM,YAAYM,SAAAA,IAAI,SAASC,gCAAoB;AACnD,QAAM,eAAeC,SAAAA,YAAY,CAAC,MAAM,EAAE,gBAAgB;AAC1D,QAAM,cAAcA,SAAAA,YAAY,CAAC,MAAM,EAAE,eAAe;AACxD,QAAM,WAAWC,MAAAA,OAAyB,IAAI;AAC9C,QAAM,CAAC,QAAQ,QAAQ,IAAIC,MAAAA,SAAS,KAAK;AACzCC,QAAAA,UAAU,MAAM;AACd,aAAS,KAAK;AAAA,EAChB,GAAG,CAAC,KAAK,CAAC;AACVA,QAAAA,UAAU,MAAM;AAId,UAAM,KAAK,SAAS;AACpB,QAAI,MAAM,QAAQ,CAAC,YAAa;AAChC,OAAG,MAAA;AACH,UAAM,UAAU,iBAAiB,QAAQ,iBAAiB;AAC1D,UAAM,MAAM,UAAU,IAAK,GAAG,OAAO,UAAU;AAC/C,OAAG,kBAAkB,KAAK,GAAG;AAAA,EAE/B,GAAG,CAAC,WAAW,CAAC;AAChB,SAAOX,YAAAA,QAAE,SAAS;AAAA,IAChB,KAAK;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAcQ,SAAAA,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAOR,oBAAE,0BAA0B,EAAE,aAAa;AACpD;;"}
1
+ {"version":3,"file":"cell-renderer.cjs","sources":["../src/cell-renderer.ts"],"sourcesContent":["import {\n ColumnSpec,\n CellRenderContext,\n CellDetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const statusVal = state.rowStatus[dataRowIndex];\n const isDeleted = statusVal == TableElementStatus.DELETED;\n // Presentation for this row's status (deleted, or a consumer-defined status\n // like \"omitted\"), from the merged `rowStatusStyles`.\n const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : undefined;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n status: statusVal,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object, then layer\n // the row-status presentation (deleted → dimmed/struck-through by default;\n // consumer statuses supply their own `cellStyle`).\n let style = { ...(col.style ?? {}) };\n\n if (statusStyle?.cellStyle != null) {\n style = { ...style, ...statusStyle.cellStyle };\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > row-status intent > edited. Validation\n // state overrides the edited-green so an edited-but-invalid cell reads as\n // invalid. A row's status intent (e.g. deleted → danger) outranks the\n // edited-green so status reads through even on an edited row.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (statusStyle?.intent != null) {\n intent = statusStyle.intent;\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n // Commit to THIS cell — not the live selection. The editor can\n // commit (e.g. on blur) after the selection has moved to another\n // cell or a whole column; `onSelectionEdited` would then write the\n // value to the wrong target (emptying it). `onCellEdited` addresses\n // the editor's own data cell.\n state.onCellEdited(dataRowIndex, col.key, value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["TableElementStatus","validation","validateCell","Cell","h","CellDetailModal","EditorPopup","value","className","singleFocusedCell","ctx","editorKeyHandlerAtom","useSelector","useRef","useState","useEffect"],"mappings":";;;;;;;;;;;;AAeO,SAAS,kBACd,UACA,UACA,YACA,OACA,oBACK;AAOL,QAAM,cAAc,MAAM;AAG1B,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY;AAC9C,QAAM,YAAY,aAAaA,MAAAA,mBAAmB;AAGlD,QAAM,cAAc,aAAa,OAAO,MAAM,kBAAkB,SAAS,IAAI;AAE7E,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,MAAM;AAC3B,QAAM,eAAe,MAAM;AAE3B,QAAM,QACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,KAAK,YAAY,IAAI,IAAI,GAAG;AACtE,QAAM,UAAU,SAAS,QAAQ,UAAU;AAE3C,QAAM,SACJ,YAAY,YAAY,IAAI,IAAI,GAAG,KAAK,QACxC,MAAM,UAAU,YAAY,MAAMA,MAAAA,mBAAmB;AAGvD,QAAMC,eAAa,YAAY,OAAOC,WAAAA,aAAa,KAAK,OAAO,KAAK,YAAY;AAKhF,QAAM,cAAoC;AAAA,IACxC;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,IACR;AAAA,IACA,UAAU;AAAA,IACV;AAAA,IACA,QAAQ;AAAA,IAAA,YACRD;AAAAA,EAAA;AAGF,QAAM,iBAAiB,UACnB,OACC,IAAI,gBAAgB,OAAO,WAAW,KAAK;AAKhD,MAAI,QAAQ,EAAE,GAAI,IAAI,SAAS,CAAA,EAAC;AAEhC,MAAI,aAAa,aAAa,MAAM;AAClC,YAAQ,EAAE,GAAG,OAAO,GAAG,YAAY,UAAA;AAAA,EACrC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AAC1D,UAAM,MAAM,UAAU,IAAK,GAAG,OAAO,UAAU;AAC/C,OAAG,kBAAkB,KAAK,GAAG;AAAA,EAE/B,GAAG,CAAC,WAAW,CAAC;AAChB,SAAOX,YAAAA,QAAE,SAAS;AAAA,IAChB,KAAK;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAcQ,SAAAA,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAOR,oBAAE,0BAA0B,EAAE,aAAa;AACpD;;"}
@@ -189,7 +189,7 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
189
189
  isEdited: edited,
190
190
  onChange(value2) {
191
191
  if (!editable) return;
192
- state.onSelectionEdited(value2);
192
+ state.onCellEdited(dataRowIndex, col.key, value2);
193
193
  },
194
194
  resetValue() {
195
195
  state.resetChanges();
@@ -1 +1 @@
1
- {"version":3,"file":"cell-renderer.js","sources":["../src/cell-renderer.ts"],"sourcesContent":["import {\n ColumnSpec,\n CellRenderContext,\n CellDetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const statusVal = state.rowStatus[dataRowIndex];\n const isDeleted = statusVal == TableElementStatus.DELETED;\n // Presentation for this row's status (deleted, or a consumer-defined status\n // like \"omitted\"), from the merged `rowStatusStyles`.\n const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : undefined;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n status: statusVal,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object, then layer\n // the row-status presentation (deleted → dimmed/struck-through by default;\n // consumer statuses supply their own `cellStyle`).\n let style = { ...(col.style ?? {}) };\n\n if (statusStyle?.cellStyle != null) {\n style = { ...style, ...statusStyle.cellStyle };\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > row-status intent > edited. Validation\n // state overrides the edited-green so an edited-but-invalid cell reads as\n // invalid. A row's status intent (e.g. deleted → danger) outranks the\n // edited-green so status reads through even on an edited row.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (statusStyle?.intent != null) {\n intent = statusStyle.intent;\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n state.onSelectionEdited(value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["value","className"],"mappings":";;;;;;;;;;AAeO,SAAS,kBACd,UACA,UACA,YACA,OACA,oBACK;AAOL,QAAM,cAAc,MAAM;AAG1B,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ,KAAK,WACjC;AAEN,QAAM,OAAO,MAAM;AACnB,QAAM,cAAc,MAAM;AAE1B,QAAM,YAAY,MAAM,UAAU,YAAY;AAC9C,QAAM,YAAY,aAAa,mBAAmB;AAGlD,QAAM,cAAc,aAAa,OAAO,MAAM,kBAAkB,SAAS,IAAI;AAE7E,QAAM,MAAM,KAAK,YAAY,KAAK,YAAY,YAAY;AAC1D,QAAM,UAAU,OAAO;AACvB,QAAM,MAAM;AAEZ,QAAM,eAAe,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SAAS,oBAAoB;AACnD,QAAM,eAAe,YAAY,CAAC,MAAM,EAAE,gBAAgB;AAC1D,QAAM,cAAc,YAAY,CAAC,MAAM,EAAE,eAAe;AACxD,QAAM,WAAW,OAAyB,IAAI;AAC9C,QAAM,CAAC,QAAQ,QAAQ,IAAI,SAAS,KAAK;AACzC,YAAU,MAAM;AACd,aAAS,KAAK;AAAA,EAChB,GAAG,CAAC,KAAK,CAAC;AACV,YAAU,MAAM;AAId,UAAM,KAAK,SAAS;AACpB,QAAI,MAAM,QAAQ,CAAC,YAAa;AAChC,OAAG,MAAA;AACH,UAAM,UAAU,iBAAiB,QAAQ,iBAAiB;AAC1D,UAAM,MAAM,UAAU,IAAK,GAAG,OAAO,UAAU;AAC/C,OAAG,kBAAkB,KAAK,GAAG;AAAA,EAE/B,GAAG,CAAC,WAAW,CAAC;AAChB,SAAO,EAAE,SAAS;AAAA,IAChB,KAAK;AAAA,IACL;AAAA,IACA,QAAQ;AAAA,IACR,OAAO,UAAU;AAAA,IACjB,UAAU,CAAC,MAAM,SAAS,EAAE,OAAO,KAAK;AAAA,IACxC,GAAG;AAAA,EAAA,CACJ;AACH;AAEA,SAAS,aAAa;AAGpB,QAAM,cAAc,YAAY,CAAC,UAAU,MAAM,WAAW;AAC5D,SAAO,EAAE,0BAA0B,EAAE,aAAa;AACpD;"}
1
+ {"version":3,"file":"cell-renderer.js","sources":["../src/cell-renderer.ts"],"sourcesContent":["import {\n ColumnSpec,\n CellRenderContext,\n CellDetailContext,\n editorKeyHandlerAtom,\n validateCell,\n} from \"./utils\";\nimport { DataSheetStore, TableElementStatus } from \"./types.ts\";\nimport h from \"./main.module.sass\";\nimport { ReactNode, useEffect, useRef, useState } from \"react\";\nimport { EditorPopup, CellDetailModal } from \"./components\";\nimport { singleFocusedCell } from \"./zustand-store.ts\";\nimport { Cell } from \"@blueprintjs/table\";\nimport { ctx, useSelector } from \"./provider.ts\";\n\nexport function basicCellRenderer<T>(\n rowIndex: number,\n colIndex: number,\n columnSpec: ColumnSpec,\n state: DataSheetStore<T>,\n filteredRowIndices?: number[] | null,\n): any {\n // Auto-activation is on when the mode is \"auto\" and it hasn't been suppressed\n // (Escape enters navigation mode until the next click).\n // Whether the inline editor grabs focus. It follows the store-owned surface\n // open state, so it focuses on selection in auto mode and on click in manual\n // mode, and not at all in navigation mode. The popover surfaces read the\n // same state directly.\n const focusOnOpen = state.cellSurfaceOpen;\n // When filters are active, `rowIndex` is the visible row position.\n // Map it to the actual data index for data access.\n const dataRowIndex =\n filteredRowIndices != null\n ? (filteredRowIndices[rowIndex] ?? rowIndex)\n : rowIndex;\n\n const data = state.data;\n const updatedData = state.updatedData;\n\n const statusVal = state.rowStatus[dataRowIndex];\n const isDeleted = statusVal == TableElementStatus.DELETED;\n // Presentation for this row's status (deleted, or a consumer-defined status\n // like \"omitted\"), from the merged `rowStatusStyles`.\n const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : undefined;\n\n const row = data[dataRowIndex] ?? updatedData[dataRowIndex];\n const loading = row == null;\n const col = columnSpec;\n\n const _topLeftCell = state.topLeftCell;\n const onCellEdited = state.onCellEdited;\n\n const value: T | undefined =\n updatedData[dataRowIndex]?.[col.key] ?? data[dataRowIndex]?.[col.key];\n const isEmpty = value == null || value === \"\";\n\n const edited =\n updatedData[dataRowIndex]?.[col.key] != null ||\n state.rowStatus[dataRowIndex] === TableElementStatus.ADDED;\n\n // Validate the cell (skipped for deleted rows). Orthogonal to edit status.\n const validation = isDeleted ? null : validateCell(col, value, row, dataRowIndex);\n\n // Context passed to custom renderers so they can render based on the\n // row/column position and cell status (and, with the editing API, write\n // edits back). `rowIndex` is the data-row index, stable under sort/filter.\n const cellContext: CellRenderContext<T> = {\n value,\n rowIndex: dataRowIndex,\n colIndex,\n column: col,\n row,\n isEdited: edited,\n isDeleted,\n status: statusVal,\n validation,\n };\n\n const _renderedValue = isEmpty\n ? null\n : (col.valueRenderer?.(value, cellContext) ?? value);\n\n // Clone so we never mutate the caller's column-spec style object, then layer\n // the row-status presentation (deleted → dimmed/struck-through by default;\n // consumer statuses supply their own `cellStyle`).\n let style = { ...(col.style ?? {}) };\n\n if (statusStyle?.cellStyle != null) {\n style = { ...style, ...statusStyle.cellStyle };\n }\n\n const editable = (col.editable ?? state.editable) && !isDeleted;\n\n // topLeftCell stores visible row indices, so compare with the visible rowIndex\n const topLeft =\n _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;\n\n const tableIsEditable = state.editable;\n\n // Intent precedence: error > warning > row-status intent > edited. Validation\n // state overrides the edited-green so an edited-but-invalid cell reads as\n // invalid. A row's status intent (e.g. deleted → danger) outranks the\n // edited-green so status reads through even on an edited row.\n let intent: string | undefined;\n if (validation?.severity === \"error\") {\n intent = \"danger\";\n } else if (validation?.severity === \"warning\") {\n intent = \"warning\";\n } else if (statusStyle?.intent != null) {\n intent = statusStyle.intent;\n } else if (edited) {\n intent = \"success\";\n }\n\n const _Cell = col.cellComponent ?? Cell;\n\n // Only forward the render context to a custom cell component; the default\n // Blueprint Cell would spread unknown props onto the DOM.\n const cellComponentProps =\n col.cellComponent != null ? { cellContext } : {};\n\n // Allow a column to pick the editor per-cell (e.g. textarea only when the\n // value is long). A returned key overrides the static column field even\n // when its value is false/null, so use `in` rather than nullish-coalesce.\n const perCellEditors = col.editorForCell?.(cellContext);\n const dataEditorSpec =\n perCellEditors != null && \"dataEditor\" in perCellEditors\n ? perCellEditors.dataEditor\n : col.dataEditor;\n const inlineEditorSpec =\n perCellEditors != null && \"inlineEditor\" in perCellEditors\n ? perCellEditors.inlineEditor\n : col.inlineEditor;\n\n let inlineEditor = editable ? (inlineEditorSpec ?? true) : false;\n\n // Build the detail context for the unified `cellDetail` surface.\n const makeDetailCtx = (editableFlag: boolean): CellDetailContext<T> => ({\n ...cellContext,\n editable: editableFlag,\n onChange(v: any) {\n if (editableFlag) onCellEdited(dataRowIndex, col.key, v);\n },\n resetValue() {\n state.resetChanges();\n },\n close() {\n state.closeCellSurface();\n state.tableElement?.focus?.();\n },\n });\n const detailPresentation =\n col.cellDetail != null ? (col.detailPresentation ?? \"popover\") : null;\n\n if (!topLeft) {\n // An inline surface is a persistent in-cell renderer, so it draws on every\n // cell (read-only when not the focused/editing cell).\n if (detailPresentation === \"inline\") {\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n col.cellDetail!(makeDetailCtx(false)),\n );\n }\n return h(\n _Cell,\n {\n intent,\n loading,\n value,\n style,\n disabled: tableIsEditable && !editable,\n interactive: false,\n ...cellComponentProps,\n },\n _renderedValue,\n );\n }\n\n // The rest is for the top-left cell of a selection or the focused cell\n\n // Unified cell surface: one renderer that acts as editor (when editable) or\n // viewer (otherwise), presented as a popover / modal / inline. Supersedes\n // dataEditor / detailRenderer / editorForCell.\n if (col.cellDetail != null) {\n const content = col.cellDetail(makeDetailCtx(editable));\n\n if (detailPresentation === \"inline\") {\n // Persistent in-cell surface (editable on the focused cell). No popover.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: editable ? \"input-cell\" : \"value-viewer-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n content,\n );\n }\n\n if (detailPresentation === \"modal\") {\n // CellDetailModal subscribes to the store so the dialog closes reactively.\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"value-viewer-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n h(\n CellDetailModal,\n { title: col.name, valueViewer: _renderedValue },\n content,\n ),\n );\n }\n\n // Default: popover (same open/close machinery as editors and panels).\n const panel = h(EditorPopup, { valueViewer: _renderedValue }, content);\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className: \"editor-cell\",\n interactive: editable,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n // Read-only detail panel: a surface that opens on selection (auto) or click,\n // shows arbitrary content, and never takes keyboard focus — so arrow keys\n // keep navigating the table. Uses the same open/close machinery as editors.\n if (col.detailRenderer != null) {\n const panel = h(\n EditorPopup,\n { valueViewer: _renderedValue },\n col.detailRenderer(cellContext),\n );\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n // Use the editor-cell popover layout so the target fills the cell\n // without the double-padding offset of `value-viewer-cell`.\n className: \"editor-cell\",\n interactive: false,\n ...cellComponentProps,\n },\n panel,\n );\n }\n\n let cellContents: ReactNode = _renderedValue;\n\n let _dataEditor = null;\n let className = null;\n\n if (dataEditorSpec != null) {\n _dataEditor = h(\n EditorPopup,\n {\n valueViewer: _renderedValue,\n },\n [\n h(dataEditorSpec, {\n value,\n editable,\n isEdited: edited,\n onChange(value) {\n if (!editable) return;\n // Commit to THIS cell — not the live selection. The editor can\n // commit (e.g. on blur) after the selection has moved to another\n // cell or a whole column; `onSelectionEdited` would then write the\n // value to the wrong target (emptying it). `onCellEdited` addresses\n // the editor's own data cell.\n state.onCellEdited(dataRowIndex, col.key, value);\n },\n resetValue() {\n state.resetChanges();\n },\n }),\n ],\n );\n }\n\n if (!editable) {\n if (_dataEditor != null) {\n cellContents = _dataEditor;\n }\n const className = \"value-viewer-cell\";\n\n return h(\n _Cell,\n {\n intent,\n value,\n style,\n className,\n interactive: false,\n ...cellComponentProps,\n },\n cellContents,\n );\n }\n\n /* The remaining logic covers cells that are focused and editable */\n\n const onChange = (e) => {\n if (!editable) return;\n if (_renderedValue === e.target.value) return;\n // Use dataRowIndex for the actual data mutation\n onCellEdited(dataRowIndex, col.key, e.target.value);\n };\n\n const isSingleCellSelection = singleFocusedCell(state.selection) != null;\n\n let _inlineEditor: ReactNode = null;\n if (typeof inlineEditor == \"boolean\") {\n let _value = value;\n if (\n typeof _renderedValue === \"string\" ||\n typeof _renderedValue === \"number\" ||\n _renderedValue == null\n ) {\n _value = _renderedValue;\n }\n _inlineEditor = h(EditorInput, {\n className: \"main-editor\",\n value: _value ?? \"\",\n autoFocus: focusOnOpen,\n onChange,\n });\n } else {\n // If inlineEditor is a ReactNode, we use it directly\n _inlineEditor = inlineEditor as ReactNode;\n }\n\n let hiddenInput: React.ReactNode = h(EditorInput, {\n className: \"hidden-input\",\n autoFocus: true,\n });\n\n if (_dataEditor != null) {\n className = \"editor-cell\";\n cellContents = _dataEditor;\n hiddenInput = null;\n } else if (_inlineEditor != null) {\n cellContents = _inlineEditor;\n className = \"input-cell\";\n hiddenInput = null;\n }\n\n // Hidden html input\n return h(\n _Cell,\n {\n intent,\n value,\n className,\n style,\n interactive: true,\n ...cellComponentProps,\n //truncated: false,\n },\n [\n cellContents,\n h.if(editable && isSingleCellSelection)(DragHandle),\n //hiddenInput,\n ],\n );\n}\n\nfunction EditorInput(props) {\n const { value, onChange, ...rest } = props;\n const onKeyDown = ctx.useValue(editorKeyHandlerAtom);\n const navDirection = useSelector((s) => s.lastNavDirection);\n const surfaceOpen = useSelector((s) => s.cellSurfaceOpen);\n const inputRef = useRef<HTMLInputElement>(null);\n const [_value, setValue] = useState(value);\n useEffect(() => {\n setValue(value);\n }, [value]);\n useEffect(() => {\n // Focus when the cell's surface is open (on mount, and when reopened via\n // click/F2 while already mounted), placing the cursor on the side we're\n // travelling toward so another arrow in that direction leaves the cell.\n const el = inputRef.current;\n if (el == null || !surfaceOpen) return;\n el.focus();\n const atStart = navDirection === \"up\" || navDirection === \"left\";\n const pos = atStart ? 0 : (el.value?.length ?? 0);\n el.setSelectionRange(pos, pos);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [surfaceOpen]);\n return h(\"input\", {\n ref: inputRef,\n onKeyDown,\n onBlur: onChange,\n value: _value ?? value,\n onChange: (e) => setValue(e.target.value),\n ...rest,\n });\n}\n\nfunction DragHandle() {\n // TODO: we might want to drag multiple columns in some cases\n // This should be on the last cell of a selection\n const onMouseDown = useSelector((state) => state.onDragValue);\n return h(\"div.corner-drag-handle\", { onMouseDown });\n}\n"],"names":["value","className"],"mappings":";;;;;;;;;;AAeO,SAAS,kBACd,UACA,UACA,YACA,OACA,oBACK;AAOL,QAAM,cAAc,MAAM;AAG1B,QAAM,eACJ,sBAAsB,OACjB,mBAAmB,QAAQ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components/view-info.cjs");
18
18
  const debugOverlay = require("./utils/debug-overlay.cjs");
19
19
  const columnControls = require("./actions/column-controls.cjs");
20
- const tableControls = require("./actions/table-controls.cjs");
21
20
  const clipboard = require("./actions/clipboard.cjs");
22
21
  const builtin = require("./actions/builtin.cjs");
23
22
  const editActions = require("./actions/edit-actions.cjs");
@@ -55,6 +54,7 @@ function DataSheet(props) {
55
54
  main_module.default(_DataSheet, {
56
55
  ...rest,
57
56
  data: data ?? emptyData,
57
+ columnSpec,
58
58
  children,
59
59
  editable,
60
60
  enableColumnReordering,
@@ -121,6 +121,7 @@ function _DataSheet({
121
121
  actions,
122
122
  filters: filters$1,
123
123
  columnHeaderCellRenderer,
124
+ columnSpec: columnSpecProp,
124
125
  statusBar,
125
126
  rowStatusStyles,
126
127
  rowHeaderRenderer,
@@ -164,7 +165,6 @@ function _DataSheet({
164
165
  };
165
166
  if (actions != null) add(actions);
166
167
  add(columnControls.columnControlActions);
167
- add([tableControls.clearSelectionAction]);
168
168
  if (enableClipboard) add(clipboard.clipboardActions);
169
169
  if (editable) {
170
170
  if (saveHandler != null) add([editActions.createSaveAction(saveHandler)]);
@@ -254,6 +254,15 @@ function _DataSheet({
254
254
  rowStatus: overlay.rowStatus
255
255
  });
256
256
  }, [deriveOverlay, loadedData, storeState]);
257
+ const derivedSpecFor = react.useRef(null);
258
+ react.useEffect(() => {
259
+ if (typeof columnSpecProp !== "function") return;
260
+ if (derivedSpecFor.current === columnSpecProp) return;
261
+ const rows = loadedData.filter((r) => r != null);
262
+ if (rows.length === 0) return;
263
+ derivedSpecFor.current = columnSpecProp;
264
+ storeState.setState({ columnSpec: columnSpecProp(rows) });
265
+ }, [columnSpecProp, loadedData, storeState]);
257
266
  const bumpRefreshFromToken = provider.ctx.useSet(dataLoaders.dataRefreshTokenAtom);
258
267
  const firstRefreshToken = react.useRef(true);
259
268
  react.useEffect(() => {