@macrostrat/data-sheet 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (60) hide show
  1. package/CHANGELOG.md +24 -0
  2. package/README.md +11 -1
  3. package/dist/actions/column-controls.cjs +89 -0
  4. package/dist/actions/column-controls.cjs.map +1 -1
  5. package/dist/actions/column-controls.js +90 -1
  6. package/dist/actions/column-controls.js.map +1 -1
  7. package/dist/actions/selection.cjs +13 -2
  8. package/dist/actions/selection.cjs.map +1 -1
  9. package/dist/actions/selection.js +13 -2
  10. package/dist/actions/selection.js.map +1 -1
  11. package/dist/actions/table-controls.cjs +17 -0
  12. package/dist/actions/table-controls.cjs.map +1 -1
  13. package/dist/actions/table-controls.d.ts +4 -0
  14. package/dist/actions/table-controls.js +17 -0
  15. package/dist/actions/table-controls.js.map +1 -1
  16. package/dist/actions/toolbar.cjs +18 -2
  17. package/dist/actions/toolbar.cjs.map +1 -1
  18. package/dist/actions/toolbar.js +18 -2
  19. package/dist/actions/toolbar.js.map +1 -1
  20. package/dist/actions/types.d.ts +9 -0
  21. package/dist/cell-renderer.cjs +8 -6
  22. package/dist/cell-renderer.cjs.map +1 -1
  23. package/dist/cell-renderer.js +8 -6
  24. package/dist/cell-renderer.js.map +1 -1
  25. package/dist/core.cjs +59 -9
  26. package/dist/core.cjs.map +1 -1
  27. package/dist/core.d.ts +28 -1
  28. package/dist/core.js +60 -10
  29. package/dist/core.js.map +1 -1
  30. package/dist/index.cjs +4 -2
  31. package/dist/index.cjs.map +1 -1
  32. package/dist/index.js +4 -2
  33. package/dist/renderers/column-header-cell.cjs +14 -28
  34. package/dist/renderers/column-header-cell.cjs.map +1 -1
  35. package/dist/renderers/column-header-cell.js +15 -29
  36. package/dist/renderers/column-header-cell.js.map +1 -1
  37. package/dist/types.cjs +11 -0
  38. package/dist/types.cjs.map +1 -1
  39. package/dist/types.d.ts +45 -1
  40. package/dist/types.js +11 -0
  41. package/dist/types.js.map +1 -1
  42. package/dist/utils/column-spec.cjs.map +1 -1
  43. package/dist/utils/column-spec.d.ts +4 -0
  44. package/dist/utils/column-spec.js.map +1 -1
  45. package/dist/zustand-store.cjs +6 -3
  46. package/dist/zustand-store.cjs.map +1 -1
  47. package/dist/zustand-store.js +7 -4
  48. package/dist/zustand-store.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/actions/column-controls.ts +114 -0
  51. package/src/actions/selection.ts +15 -2
  52. package/src/actions/table-controls.ts +20 -0
  53. package/src/actions/toolbar.ts +30 -2
  54. package/src/actions/types.ts +10 -0
  55. package/src/cell-renderer.ts +17 -9
  56. package/src/core.ts +107 -12
  57. package/src/renderers/column-header-cell.ts +20 -32
  58. package/src/types.ts +56 -1
  59. package/src/utils/column-spec.ts +4 -0
  60. package/src/zustand-store.ts +11 -5
@@ -3,6 +3,7 @@ Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
3
  const h = require("@macrostrat/hyper");
4
4
  const react = require("react");
5
5
  const core = require("@blueprintjs/core");
6
+ const table = require("@blueprintjs/table");
6
7
  const provider = require("../provider.cjs");
7
8
  const editActions = require("./edit-actions.cjs");
8
9
  const _interopDefault = (e) => e && e.__esModule ? e : { default: e };
@@ -29,6 +30,21 @@ function ScrollToRowControl() {
29
30
  h__default.default(core.Button, { small: true, minimal: true, icon: "arrow-right", onClick: go })
30
31
  ]);
31
32
  }
33
+ const clearSelectionAction = {
34
+ id: "clear-selection",
35
+ name: "Clear selection",
36
+ icon: "cross",
37
+ requiresEditable: false,
38
+ targets: [
39
+ table.RegionCardinality.CELLS,
40
+ table.RegionCardinality.FULL_ROWS,
41
+ table.RegionCardinality.FULL_COLUMNS,
42
+ table.RegionCardinality.FULL_TABLE
43
+ ],
44
+ run(ctx) {
45
+ ctx.setState({ selection: [], focusedCell: null, topLeftCell: null });
46
+ }
47
+ };
32
48
  const scrollToRowAction = {
33
49
  id: "scroll-to-row",
34
50
  name: "Scroll to row",
@@ -37,5 +53,6 @@ const scrollToRowAction = {
37
53
  requiresEditable: false,
38
54
  render: () => h__default.default(ScrollToRowControl)
39
55
  };
56
+ exports.clearSelectionAction = clearSelectionAction;
40
57
  exports.scrollToRowAction = scrollToRowAction;
41
58
  //# sourceMappingURL=table-controls.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"table-controls.cjs","sources":["../../src/actions/table-controls.ts"],"sourcesContent":["/**\n * Table-scoped controls expressed as `TableAction`s (no special\n * `dataSheetActions` chrome). They target every cardinality, so they sit in the\n * toolbar regardless of selection — reachable from the one standard actions\n * path like everything else. Opt-in: add them to the `actions` prop.\n */\nimport h from \"@macrostrat/hyper\";\nimport { useState } from \"react\";\nimport { Button, ControlGroup, InputGroup } from \"@blueprintjs/core\";\nimport { useSelector } from \"../provider\";\nimport type { TableAction } from \"./types\";\nimport { ALL_CARDINALITIES } from \"./edit-actions\";\n\nfunction ScrollToRowControl() {\n const [value, setValue] = useState(\"\");\n const scrollToRow = useSelector((s) => s.scrollToRow);\n const go = () => {\n const r = parseInt(value, 10);\n if (!Number.isNaN(r)) scrollToRow(r - 1);\n };\n return h(ControlGroup, [\n h(InputGroup, {\n type: \"number\",\n placeholder: \"Row #\",\n value,\n small: true,\n style: { width: \"6em\" },\n onValueChange: setValue,\n onKeyDown: (e: any) => {\n if (e.key === \"Enter\") go();\n },\n }),\n h(Button, { small: true, minimal: true, icon: \"arrow-right\", onClick: go }),\n ]);\n}\n\n/** Scroll to a 1-based row number. Meaningful for large, addressable sources;\n * add it to `actions`. Present in the toolbar regardless of selection. */\nexport const scrollToRowAction: TableAction = {\n id: \"scroll-to-row\",\n name: \"Scroll to row\",\n icon: \"arrow-right\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () => h(ScrollToRowControl),\n};\n"],"names":["useState","useSelector","h","ControlGroup","InputGroup","Button","ALL_CARDINALITIES"],"mappings":";;;;;;;;;AAaA,SAAS,qBAAqB;AAC5B,QAAM,CAAC,OAAO,QAAQ,IAAIA,MAAAA,SAAS,EAAE;AACrC,QAAM,cAAcC,SAAAA,YAAY,CAAC,MAAM,EAAE,WAAW;AACpD,QAAM,KAAK,MAAM;AACf,UAAM,IAAI,SAAS,OAAO,EAAE;AAC5B,QAAI,CAAC,OAAO,MAAM,CAAC,EAAG,aAAY,IAAI,CAAC;AAAA,EACzC;AACA,SAAOC,WAAAA,QAAEC,KAAAA,cAAc;AAAA,IACrBD,WAAAA,QAAEE,KAAAA,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,aAAa;AAAA,MACb;AAAA,MACA,OAAO;AAAA,MACP,OAAO,EAAE,OAAO,MAAA;AAAA,MAChB,eAAe;AAAA,MACf,WAAW,CAAC,MAAW;AACrB,YAAI,EAAE,QAAQ,QAAS,IAAA;AAAA,MACzB;AAAA,IAAA,CACD;AAAA,IACDF,WAAAA,QAAEG,KAAAA,QAAQ,EAAE,OAAO,MAAM,SAAS,MAAM,MAAM,eAAe,SAAS,GAAA,CAAI;AAAA,EAAA,CAC3E;AACH;AAIO,MAAM,oBAAiC;AAAA,EAC5C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAASC,YAAAA;AAAAA,EACT,kBAAkB;AAAA,EAClB,QAAQ,MAAMJ,WAAAA,QAAE,kBAAkB;AACpC;;"}
1
+ {"version":3,"file":"table-controls.cjs","sources":["../../src/actions/table-controls.ts"],"sourcesContent":["/**\n * Table-scoped controls expressed as `TableAction`s (no special\n * `dataSheetActions` chrome). They target every cardinality, so they sit in the\n * toolbar regardless of selection — reachable from the one standard actions\n * path like everything else. Opt-in: add them to the `actions` prop.\n */\nimport h from \"@macrostrat/hyper\";\nimport { useState } from \"react\";\nimport { Button, ControlGroup, InputGroup } from \"@blueprintjs/core\";\nimport { RegionCardinality } from \"@blueprintjs/table\";\nimport { useSelector } from \"../provider\";\nimport type { TableAction } from \"./types\";\nimport { ALL_CARDINALITIES } from \"./edit-actions\";\n\nfunction ScrollToRowControl() {\n const [value, setValue] = useState(\"\");\n const scrollToRow = useSelector((s) => s.scrollToRow);\n const go = () => {\n const r = parseInt(value, 10);\n if (!Number.isNaN(r)) scrollToRow(r - 1);\n };\n return h(ControlGroup, [\n h(InputGroup, {\n type: \"number\",\n placeholder: \"Row #\",\n value,\n small: true,\n style: { width: \"6em\" },\n onValueChange: setValue,\n onKeyDown: (e: any) => {\n if (e.key === \"Enter\") go();\n },\n }),\n h(Button, { small: true, minimal: true, icon: \"arrow-right\", onClick: go }),\n ]);\n}\n\n/** Clear the current selection. Auto-included: appears (on the right, being a\n * general action) whenever something is selected — targets every cardinality\n * except `\"none\"`. */\nexport const clearSelectionAction: TableAction = {\n id: \"clear-selection\",\n name: \"Clear selection\",\n icon: \"cross\",\n requiresEditable: false,\n targets: [\n RegionCardinality.CELLS,\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_COLUMNS,\n RegionCardinality.FULL_TABLE,\n ],\n run(ctx) {\n ctx.setState({ selection: [], focusedCell: null, topLeftCell: null });\n },\n};\n\n/** Scroll to a 1-based row number. Meaningful for large, addressable sources;\n * add it to `actions`. Present in the toolbar regardless of selection. */\nexport const scrollToRowAction: TableAction = {\n id: \"scroll-to-row\",\n name: \"Scroll to row\",\n icon: \"arrow-right\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () => h(ScrollToRowControl),\n};\n"],"names":["useState","useSelector","h","ControlGroup","InputGroup","Button","RegionCardinality","ALL_CARDINALITIES"],"mappings":";;;;;;;;;;AAcA,SAAS,qBAAqB;AAC5B,QAAM,CAAC,OAAO,QAAQ,IAAIA,MAAAA,SAAS,EAAE;AACrC,QAAM,cAAcC,SAAAA,YAAY,CAAC,MAAM,EAAE,WAAW;AACpD,QAAM,KAAK,MAAM;AACf,UAAM,IAAI,SAAS,OAAO,EAAE;AAC5B,QAAI,CAAC,OAAO,MAAM,CAAC,EAAG,aAAY,IAAI,CAAC;AAAA,EACzC;AACA,SAAOC,WAAAA,QAAEC,KAAAA,cAAc;AAAA,IACrBD,WAAAA,QAAEE,KAAAA,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,aAAa;AAAA,MACb;AAAA,MACA,OAAO;AAAA,MACP,OAAO,EAAE,OAAO,MAAA;AAAA,MAChB,eAAe;AAAA,MACf,WAAW,CAAC,MAAW;AACrB,YAAI,EAAE,QAAQ,QAAS,IAAA;AAAA,MACzB;AAAA,IAAA,CACD;AAAA,IACDF,WAAAA,QAAEG,KAAAA,QAAQ,EAAE,OAAO,MAAM,SAAS,MAAM,MAAM,eAAe,SAAS,GAAA,CAAI;AAAA,EAAA,CAC3E;AACH;AAKO,MAAM,uBAAoC;AAAA,EAC/C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,kBAAkB;AAAA,EAClB,SAAS;AAAA,IACPC,MAAAA,kBAAkB;AAAA,IAClBA,MAAAA,kBAAkB;AAAA,IAClBA,MAAAA,kBAAkB;AAAA,IAClBA,wBAAkB;AAAA,EAAA;AAAA,EAEpB,IAAI,KAAK;AACP,QAAI,SAAS,EAAE,WAAW,CAAA,GAAI,aAAa,MAAM,aAAa,MAAM;AAAA,EACtE;AACF;AAIO,MAAM,oBAAiC;AAAA,EAC5C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAASC,YAAAA;AAAAA,EACT,kBAAkB;AAAA,EAClB,QAAQ,MAAML,WAAAA,QAAE,kBAAkB;AACpC;;;"}
@@ -1,4 +1,8 @@
1
1
  import { TableAction } from './types';
2
+ /** Clear the current selection. Auto-included: appears (on the right, being a
3
+ * general action) whenever something is selected — targets every cardinality
4
+ * except `"none"`. */
5
+ export declare const clearSelectionAction: TableAction;
2
6
  /** Scroll to a 1-based row number. Meaningful for large, addressable sources;
3
7
  * add it to `actions`. Present in the toolbar regardless of selection. */
4
8
  export declare const scrollToRowAction: TableAction;
@@ -1,6 +1,7 @@
1
1
  import h from "@macrostrat/hyper";
2
2
  import { useState } from "react";
3
3
  import { ControlGroup, InputGroup, Button } from "@blueprintjs/core";
4
+ import { RegionCardinality } from "@blueprintjs/table";
4
5
  import { useSelector } from "../provider.js";
5
6
  import { ALL_CARDINALITIES } from "./edit-actions.js";
6
7
  function ScrollToRowControl() {
@@ -25,6 +26,21 @@ function ScrollToRowControl() {
25
26
  h(Button, { small: true, minimal: true, icon: "arrow-right", onClick: go })
26
27
  ]);
27
28
  }
29
+ const clearSelectionAction = {
30
+ id: "clear-selection",
31
+ name: "Clear selection",
32
+ icon: "cross",
33
+ requiresEditable: false,
34
+ targets: [
35
+ RegionCardinality.CELLS,
36
+ RegionCardinality.FULL_ROWS,
37
+ RegionCardinality.FULL_COLUMNS,
38
+ RegionCardinality.FULL_TABLE
39
+ ],
40
+ run(ctx) {
41
+ ctx.setState({ selection: [], focusedCell: null, topLeftCell: null });
42
+ }
43
+ };
28
44
  const scrollToRowAction = {
29
45
  id: "scroll-to-row",
30
46
  name: "Scroll to row",
@@ -34,6 +50,7 @@ const scrollToRowAction = {
34
50
  render: () => h(ScrollToRowControl)
35
51
  };
36
52
  export {
53
+ clearSelectionAction,
37
54
  scrollToRowAction
38
55
  };
39
56
  //# sourceMappingURL=table-controls.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"table-controls.js","sources":["../../src/actions/table-controls.ts"],"sourcesContent":["/**\n * Table-scoped controls expressed as `TableAction`s (no special\n * `dataSheetActions` chrome). They target every cardinality, so they sit in the\n * toolbar regardless of selection — reachable from the one standard actions\n * path like everything else. Opt-in: add them to the `actions` prop.\n */\nimport h from \"@macrostrat/hyper\";\nimport { useState } from \"react\";\nimport { Button, ControlGroup, InputGroup } from \"@blueprintjs/core\";\nimport { useSelector } from \"../provider\";\nimport type { TableAction } from \"./types\";\nimport { ALL_CARDINALITIES } from \"./edit-actions\";\n\nfunction ScrollToRowControl() {\n const [value, setValue] = useState(\"\");\n const scrollToRow = useSelector((s) => s.scrollToRow);\n const go = () => {\n const r = parseInt(value, 10);\n if (!Number.isNaN(r)) scrollToRow(r - 1);\n };\n return h(ControlGroup, [\n h(InputGroup, {\n type: \"number\",\n placeholder: \"Row #\",\n value,\n small: true,\n style: { width: \"6em\" },\n onValueChange: setValue,\n onKeyDown: (e: any) => {\n if (e.key === \"Enter\") go();\n },\n }),\n h(Button, { small: true, minimal: true, icon: \"arrow-right\", onClick: go }),\n ]);\n}\n\n/** Scroll to a 1-based row number. Meaningful for large, addressable sources;\n * add it to `actions`. Present in the toolbar regardless of selection. */\nexport const scrollToRowAction: TableAction = {\n id: \"scroll-to-row\",\n name: \"Scroll to row\",\n icon: \"arrow-right\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () => h(ScrollToRowControl),\n};\n"],"names":[],"mappings":";;;;;AAaA,SAAS,qBAAqB;AAC5B,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AACrC,QAAM,cAAc,YAAY,CAAC,MAAM,EAAE,WAAW;AACpD,QAAM,KAAK,MAAM;AACf,UAAM,IAAI,SAAS,OAAO,EAAE;AAC5B,QAAI,CAAC,OAAO,MAAM,CAAC,EAAG,aAAY,IAAI,CAAC;AAAA,EACzC;AACA,SAAO,EAAE,cAAc;AAAA,IACrB,EAAE,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,aAAa;AAAA,MACb;AAAA,MACA,OAAO;AAAA,MACP,OAAO,EAAE,OAAO,MAAA;AAAA,MAChB,eAAe;AAAA,MACf,WAAW,CAAC,MAAW;AACrB,YAAI,EAAE,QAAQ,QAAS,IAAA;AAAA,MACzB;AAAA,IAAA,CACD;AAAA,IACD,EAAE,QAAQ,EAAE,OAAO,MAAM,SAAS,MAAM,MAAM,eAAe,SAAS,GAAA,CAAI;AAAA,EAAA,CAC3E;AACH;AAIO,MAAM,oBAAiC;AAAA,EAC5C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,kBAAkB;AAAA,EAClB,QAAQ,MAAM,EAAE,kBAAkB;AACpC;"}
1
+ {"version":3,"file":"table-controls.js","sources":["../../src/actions/table-controls.ts"],"sourcesContent":["/**\n * Table-scoped controls expressed as `TableAction`s (no special\n * `dataSheetActions` chrome). They target every cardinality, so they sit in the\n * toolbar regardless of selection — reachable from the one standard actions\n * path like everything else. Opt-in: add them to the `actions` prop.\n */\nimport h from \"@macrostrat/hyper\";\nimport { useState } from \"react\";\nimport { Button, ControlGroup, InputGroup } from \"@blueprintjs/core\";\nimport { RegionCardinality } from \"@blueprintjs/table\";\nimport { useSelector } from \"../provider\";\nimport type { TableAction } from \"./types\";\nimport { ALL_CARDINALITIES } from \"./edit-actions\";\n\nfunction ScrollToRowControl() {\n const [value, setValue] = useState(\"\");\n const scrollToRow = useSelector((s) => s.scrollToRow);\n const go = () => {\n const r = parseInt(value, 10);\n if (!Number.isNaN(r)) scrollToRow(r - 1);\n };\n return h(ControlGroup, [\n h(InputGroup, {\n type: \"number\",\n placeholder: \"Row #\",\n value,\n small: true,\n style: { width: \"6em\" },\n onValueChange: setValue,\n onKeyDown: (e: any) => {\n if (e.key === \"Enter\") go();\n },\n }),\n h(Button, { small: true, minimal: true, icon: \"arrow-right\", onClick: go }),\n ]);\n}\n\n/** Clear the current selection. Auto-included: appears (on the right, being a\n * general action) whenever something is selected — targets every cardinality\n * except `\"none\"`. */\nexport const clearSelectionAction: TableAction = {\n id: \"clear-selection\",\n name: \"Clear selection\",\n icon: \"cross\",\n requiresEditable: false,\n targets: [\n RegionCardinality.CELLS,\n RegionCardinality.FULL_ROWS,\n RegionCardinality.FULL_COLUMNS,\n RegionCardinality.FULL_TABLE,\n ],\n run(ctx) {\n ctx.setState({ selection: [], focusedCell: null, topLeftCell: null });\n },\n};\n\n/** Scroll to a 1-based row number. Meaningful for large, addressable sources;\n * add it to `actions`. Present in the toolbar regardless of selection. */\nexport const scrollToRowAction: TableAction = {\n id: \"scroll-to-row\",\n name: \"Scroll to row\",\n icon: \"arrow-right\",\n targets: ALL_CARDINALITIES,\n requiresEditable: false,\n render: () => h(ScrollToRowControl),\n};\n"],"names":[],"mappings":";;;;;;AAcA,SAAS,qBAAqB;AAC5B,QAAM,CAAC,OAAO,QAAQ,IAAI,SAAS,EAAE;AACrC,QAAM,cAAc,YAAY,CAAC,MAAM,EAAE,WAAW;AACpD,QAAM,KAAK,MAAM;AACf,UAAM,IAAI,SAAS,OAAO,EAAE;AAC5B,QAAI,CAAC,OAAO,MAAM,CAAC,EAAG,aAAY,IAAI,CAAC;AAAA,EACzC;AACA,SAAO,EAAE,cAAc;AAAA,IACrB,EAAE,YAAY;AAAA,MACZ,MAAM;AAAA,MACN,aAAa;AAAA,MACb;AAAA,MACA,OAAO;AAAA,MACP,OAAO,EAAE,OAAO,MAAA;AAAA,MAChB,eAAe;AAAA,MACf,WAAW,CAAC,MAAW;AACrB,YAAI,EAAE,QAAQ,QAAS,IAAA;AAAA,MACzB;AAAA,IAAA,CACD;AAAA,IACD,EAAE,QAAQ,EAAE,OAAO,MAAM,SAAS,MAAM,MAAM,eAAe,SAAS,GAAA,CAAI;AAAA,EAAA,CAC3E;AACH;AAKO,MAAM,uBAAoC;AAAA,EAC/C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,kBAAkB;AAAA,EAClB,SAAS;AAAA,IACP,kBAAkB;AAAA,IAClB,kBAAkB;AAAA,IAClB,kBAAkB;AAAA,IAClB,kBAAkB;AAAA,EAAA;AAAA,EAEpB,IAAI,KAAK;AACP,QAAI,SAAS,EAAE,WAAW,CAAA,GAAI,aAAa,MAAM,aAAa,MAAM;AAAA,EACtE;AACF;AAIO,MAAM,oBAAiC;AAAA,EAC5C,IAAI;AAAA,EACJ,MAAM;AAAA,EACN,MAAM;AAAA,EACN,SAAS;AAAA,EACT,kBAAkB;AAAA,EAClB,QAAQ,MAAM,EAAE,kBAAkB;AACpC;"}
@@ -62,12 +62,28 @@ function ActionsToolbar({
62
62
  return null;
63
63
  }
64
64
  const title = selectionTitle(ctx) ?? tableName ?? "Table";
65
+ const isGlobal = (a) => a.targets.includes(table.RegionCardinality.FULL_TABLE) || a.targets.includes("none");
66
+ const contextual = shownActions.filter((a) => !isGlobal(a));
67
+ const globalOrder = {
68
+ "clear-selection": 1,
69
+ "reset-changes": 2,
70
+ "save-changes": 3
71
+ };
72
+ const globalActions = shownActions.filter(isGlobal).sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));
65
73
  return toolbar_module.default("div.actions-toolbar", [
66
74
  toolbar_module.default("span.toolbar-title", { key: "title" }, title),
67
75
  toolbar_module.default(
68
76
  core.ButtonGroup,
69
- { key: "actions", minimal: true },
70
- shownActions.map(
77
+ { key: "contextual", minimal: true },
78
+ contextual.map(
79
+ (action) => toolbar_module.default(ActionButton, { key: action.id, action, ctx })
80
+ )
81
+ ),
82
+ toolbar_module.default("div.toolbar-spacer", { key: "spacer", style: { flex: 1 } }),
83
+ toolbar_module.default(
84
+ core.ButtonGroup,
85
+ { key: "global", minimal: true },
86
+ globalActions.map(
71
87
  (action) => toolbar_module.default(ActionButton, { key: action.id, action, ctx })
72
88
  )
73
89
  )
@@ -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 return h(\"div.actions-toolbar\", [\n h(\"span.toolbar-title\", { key: \"title\" }, title),\n h(\n ButtonGroup,\n { key: \"actions\", minimal: true },\n shownActions.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,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,QA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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,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 } 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,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,QAAE,OAAO,aAAa;AAAA,UACpB,OAAO;AAAA,UACP,UAAU;AAAA,QAAA,CACX;AAAA,QACDA,eAAAA;AAAAA,UACEI,KAAAA;AAAAA,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,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;;;"}
@@ -60,12 +60,28 @@ function ActionsToolbar({
60
60
  return null;
61
61
  }
62
62
  const title = selectionTitle(ctx) ?? tableName ?? "Table";
63
+ const isGlobal = (a) => a.targets.includes(RegionCardinality.FULL_TABLE) || a.targets.includes("none");
64
+ const contextual = shownActions.filter((a) => !isGlobal(a));
65
+ const globalOrder = {
66
+ "clear-selection": 1,
67
+ "reset-changes": 2,
68
+ "save-changes": 3
69
+ };
70
+ const globalActions = shownActions.filter(isGlobal).sort((a, b) => (globalOrder[a.id] ?? 0) - (globalOrder[b.id] ?? 0));
63
71
  return h("div.actions-toolbar", [
64
72
  h("span.toolbar-title", { key: "title" }, title),
65
73
  h(
66
74
  ButtonGroup,
67
- { key: "actions", minimal: true },
68
- shownActions.map(
75
+ { key: "contextual", minimal: true },
76
+ contextual.map(
77
+ (action) => h(ActionButton, { key: action.id, action, ctx })
78
+ )
79
+ ),
80
+ h("div.toolbar-spacer", { key: "spacer", style: { flex: 1 } }),
81
+ h(
82
+ ButtonGroup,
83
+ { key: "global", minimal: true },
84
+ globalActions.map(
69
85
  (action) => h(ActionButton, { key: action.id, action, ctx })
70
86
  )
71
87
  )
@@ -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 return h(\"div.actions-toolbar\", [\n h(\"span.toolbar-title\", { key: \"title\" }, title),\n h(\n ButtonGroup,\n { key: \"actions\", minimal: true },\n shownActions.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, {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,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 } 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,IACjB,MAAM,mBAAmB,SAAS,YAAY,S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BAA8B;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;"}
@@ -20,6 +20,9 @@ export interface CellEdit {
20
20
  rowIndex: number;
21
21
  column: string;
22
22
  value: any;
23
+ /** The underlying row (base data). Populated on emitted `onEdit` events so a
24
+ * handler can address the row (identity) without reaching into the store. */
25
+ row?: any;
23
26
  }
24
27
  /** A column filter that can be activated to hide non-matching rows.
25
28
  * Parallel to `TableAction` but with persistent state while active.
@@ -177,6 +180,12 @@ export interface TableAction<T = any, S = null> {
177
180
  * `run`, unless the control itself invokes it). This is how sort/filter/group
178
181
  * are expressed as `FULL_COLUMNS`-scoped controls in the one action system. */
179
182
  render?: (context: TableActionContext<T>) => ReactNode;
183
+ /** Menu-native rendering for a menu surface (the column-header dropdown):
184
+ * return `MenuItem`(s) — e.g. sort as a submenu, or a filter list where each
185
+ * filter is an item opening its form in a submenu. When present, the
186
+ * column-header menu uses this instead of `render` (which stays for the
187
+ * toolbar's inline/popover control). May return multiple items (a fragment).*/
188
+ renderMenuItem?: (context: TableActionContext<T>) => ReactNode;
180
189
  /** Execute the action. May be synchronous (local state manipulation)
181
190
  * or asynchronous (backend fulfillment). For lazy-loaded tables,
182
191
  * async actions are required when targeting non-loaded cells.
@@ -15,7 +15,9 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
15
15
  const dataRowIndex = filteredRowIndices != null ? filteredRowIndices[rowIndex] ?? rowIndex : rowIndex;
16
16
  const data = state.data;
17
17
  const updatedData = state.updatedData;
18
- const isDeleted = state.rowStatus[dataRowIndex] == types.TableElementStatus.DELETED;
18
+ const statusVal = state.rowStatus[dataRowIndex];
19
+ const isDeleted = statusVal == types.TableElementStatus.DELETED;
20
+ const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : void 0;
19
21
  const row = data[dataRowIndex] ?? updatedData[dataRowIndex];
20
22
  const loading = row == null;
21
23
  const col = columnSpec;
@@ -33,13 +35,13 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
33
35
  row,
34
36
  isEdited: edited,
35
37
  isDeleted,
38
+ status: statusVal,
36
39
  validation: validation$1
37
40
  };
38
41
  const _renderedValue = isEmpty ? null : col.valueRenderer?.(value, cellContext) ?? value;
39
42
  let style = { ...col.style ?? {} };
40
- if (isDeleted) {
41
- style.opacity = 0.5;
42
- style.textDecoration = "line-through";
43
+ if (statusStyle?.cellStyle != null) {
44
+ style = { ...style, ...statusStyle.cellStyle };
43
45
  }
44
46
  const editable = (col.editable ?? state.editable) && !isDeleted;
45
47
  const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
@@ -49,8 +51,8 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
49
51
  intent = "danger";
50
52
  } else if (validation$1?.severity === "warning") {
51
53
  intent = "warning";
52
- } else if (isDeleted) {
53
- intent = "danger";
54
+ } else if (statusStyle?.intent != null) {
55
+ intent = statusStyle.intent;
54
56
  } else if (edited) {
55
57
  intent = "success";
56
58
  }
@@ -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 isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;\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 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\n let style = { ...(col.style ?? {}) };\n\n if (isDeleted) {\n style.opacity = 0.5;\n style.textDecoration = \"line-through\";\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 > deleted > edited. Validation state\n // overrides the edited-green so an edited-but-invalid cell reads as invalid.\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 (isDeleted) {\n intent = \"danger\";\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,KAAKA,MAAAA,mBAAmB;AAEtE,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,IAAA,YACAD;AAAAA,EAAA;AAGF,QAAM,iBAAiB,UACnB,OACC,IAAI,gBAAgB,OAAO,WAAW,KAAK;AAGhD,MAAI,QAAQ,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AC,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 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,Q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ACAA,YAAAA,QAAE,GAAG,YAAY,qBAAqB,EAAE,UAAU;AAAA;AAAA,IAAA;AAAA,EAEpD;AAEJ;AAEA,SAAS,YAAY,OAAO;AAC1B,QAAM,EAAE,OAAO,UAAU,GAAG,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;;"}
@@ -13,7 +13,9 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
13
13
  const dataRowIndex = filteredRowIndices != null ? filteredRowIndices[rowIndex] ?? rowIndex : rowIndex;
14
14
  const data = state.data;
15
15
  const updatedData = state.updatedData;
16
- const isDeleted = state.rowStatus[dataRowIndex] == TableElementStatus.DELETED;
16
+ const statusVal = state.rowStatus[dataRowIndex];
17
+ const isDeleted = statusVal == TableElementStatus.DELETED;
18
+ const statusStyle = statusVal != null ? state.rowStatusStyles?.[statusVal] : void 0;
17
19
  const row = data[dataRowIndex] ?? updatedData[dataRowIndex];
18
20
  const loading = row == null;
19
21
  const col = columnSpec;
@@ -31,13 +33,13 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
31
33
  row,
32
34
  isEdited: edited,
33
35
  isDeleted,
36
+ status: statusVal,
34
37
  validation
35
38
  };
36
39
  const _renderedValue = isEmpty ? null : col.valueRenderer?.(value, cellContext) ?? value;
37
40
  let style = { ...col.style ?? {} };
38
- if (isDeleted) {
39
- style.opacity = 0.5;
40
- style.textDecoration = "line-through";
41
+ if (statusStyle?.cellStyle != null) {
42
+ style = { ...style, ...statusStyle.cellStyle };
41
43
  }
42
44
  const editable = (col.editable ?? state.editable) && !isDeleted;
43
45
  const topLeft = _topLeftCell?.col === colIndex && _topLeftCell?.row === rowIndex;
@@ -47,8 +49,8 @@ function basicCellRenderer(rowIndex, colIndex, columnSpec, state, filteredRowInd
47
49
  intent = "danger";
48
50
  } else if (validation?.severity === "warning") {
49
51
  intent = "warning";
50
- } else if (isDeleted) {
51
- intent = "danger";
52
+ } else if (statusStyle?.intent != null) {
53
+ intent = statusStyle.intent;
52
54
  } else if (edited) {
53
55
  intent = "success";
54
56
  }