@gridkitjs/core 0.0.0-dev-20261108231420 → 0.0.0-dev-20261109124753

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -50,8 +50,10 @@ interface GridControllerOptions<Row, Node = string> extends GridOptions<Row>, Se
50
50
  *
51
51
  * Every action follows the same steps: work out the next value; stop if it
52
52
  * is the very object the slice already holds; keep it, unless the slice is
53
- * controlled; report it through the slice's callback; then call every
54
- * subscriber, synchronously. The setters (`setColumnSort` and the like) also
53
+ * controlled; report it through the slice's callback; then, if the state
54
+ * changed, call every subscriber, synchronously. A controlled slice's state
55
+ * changes only when the next `setOptions` carries the value, so an action on
56
+ * it reports without calling subscribers. The setters (`setColumnSort` and the like) also
55
57
  * stop for a value equal to the current one, so restoring what is already
56
58
  * there reports nothing.
57
59
  *
@@ -76,8 +78,9 @@ interface GridController<Row, Node = string> {
76
78
  /** What the user is looking at — see `resolveGridView`. The same object until something in it changes. */
77
79
  readonly getView: () => GridView<Row, Node>;
78
80
  /**
79
- * Calls `listener` after each action that got as far as reporting a
80
- * change. Returns the function that unsubscribes it.
81
+ * Calls `listener` after each action that changed the state, so
82
+ * `getState()` returns a new object whenever it runs. Returns the function
83
+ * that unsubscribes it.
81
84
  */
82
85
  readonly subscribe: (listener: () => void) => () => void;
83
86
  /**
@@ -85,7 +88,8 @@ interface GridController<Row, Node = string> {
85
88
  * `serializeGridState` and back through JSON. Every slice given is set as
86
89
  * its own `set*` action would set it, so each that changes fires its
87
90
  * callback and a controlled one only asks; slices left out keep their value.
88
- * Subscribers are called once, after every slice is in place, and a
91
+ * Subscribers are called once, after every slice is in place, if any
92
+ * changed, and a
89
93
  * restored pagination is kept even when the same call changed the sort,
90
94
  * filter or grouping that would otherwise send it back to the first page.
91
95
  * A slice that throws stops the restore there, after the slices before it
@@ -167,7 +171,7 @@ interface GridController<Row, Node = string> {
167
171
  /**
168
172
  * Lets go of every row, column and cell selection at once, as Escape does:
169
173
  * one change, so each selection that changes fires its callback and then
170
- * subscribers are called once.
174
+ * subscribers are called once, if the state changed.
171
175
  */
172
176
  readonly clearSelection: () => void;
173
177
  /** Replaces the selected column ids as given — see `setRowSelection`. */
@@ -576,7 +580,10 @@ interface GridMessages {
576
580
  exportSelectionJson: string;
577
581
  /** `exportSelection.xlsx` */
578
582
  exportSelectionXlsx: string;
579
- /** Announced when an export's writer fails, so no file is saved. */
583
+ /**
584
+ * Announced when an export's writer fails or the browser refuses its
585
+ * download, so no file is saved.
586
+ */
580
587
  exportFailed: string;
581
588
  /** `copy.cell` */
582
589
  copyCell: string;
@@ -590,6 +597,8 @@ interface GridMessages {
590
597
  copyFailed: string;
591
598
  /** `print` */
592
599
  print: string;
600
+ /** Announced when the browser fails to print, so nothing is printed. */
601
+ printFailed: string;
593
602
  }
594
603
  /**
595
604
  * The grid's own English, its counts printed in `locale`'s digits —
@@ -1127,8 +1136,12 @@ interface GridCommandHost {
1127
1136
  * Saves an export as a file — in a browser, a download. A promise is the
1128
1137
  * file of a writer still writing; the host waits for it, and reports a
1129
1138
  * rejected one rather than saving.
1139
+ *
1140
+ * Returns `false` for a file it drops without saving, as a host that saves
1141
+ * one file at a time does with one asked for while it waits on the last.
1142
+ * The export command that asked then did not run.
1130
1143
  */
1131
- readonly saveFile: (file: ExportFile | Promise<ExportFile>) => void;
1144
+ readonly saveFile: ((file: ExportFile | Promise<ExportFile>) => void) | ((file: ExportFile | Promise<ExportFile>) => boolean);
1132
1145
  /**
1133
1146
  * Puts a copy on the clipboard, as text and as HTML, and announces it —
1134
1147
  * `count` and `unit` say what to announce — or that the browser refused.
@@ -1196,7 +1209,12 @@ interface GridCommand<Row> {
1196
1209
  readonly isEnabled?: ((context: GridCommandContext<Row>) => boolean) | undefined;
1197
1210
  /** Present for a checkable command — drawn as a checkbox item or a toggle button — and says whether it is checked. */
1198
1211
  readonly isChecked?: ((context: GridCommandContext<Row>) => boolean) | undefined;
1199
- readonly execute: (context: GridCommandContext<Row>) => void;
1212
+ /**
1213
+ * Does what the command does. Returns `false` when it turns out to do
1214
+ * nothing after all, such as an export the host dropped, so `runCommand`
1215
+ * says it did not run and a renderer does not report it.
1216
+ */
1217
+ readonly execute: ((context: GridCommandContext<Row>) => void) | ((context: GridCommandContext<Row>) => boolean);
1200
1218
  }
1201
1219
 
1202
1220
  /** The id of every command `builtInCommands` returns. */
@@ -1891,8 +1909,11 @@ interface GridOptions<Row> {
1891
1909
  contextMenu?: boolean | GridContextMenuOptions<Row> | undefined;
1892
1910
  /**
1893
1911
  * Called when the grid's context menu opens or closes, with where. A menu
1894
- * opened in place of another reports that one closing first. The open
1895
- * state is the renderer's to keep, so no option holds it.
1912
+ * opened in place of another reports that one closing first. It also
1913
+ * reports closing when a panel opens in its place (before the command of
1914
+ * a menu item that opened it runs), when the grid unmounts and when
1915
+ * `contextMenu` is turned off while it is open. The open state is the renderer's to keep, so no
1916
+ * option holds it.
1896
1917
  */
1897
1918
  onContextMenuOpenChange?: ((event: ContextMenuOpenChangeEvent) => void) | undefined;
1898
1919
  /**
@@ -3006,7 +3027,7 @@ declare function resolveCommands<Row>(commands: readonly GridCommand<Row>[] | un
3006
3027
  * Runs `command` when it is visible and enabled on `context`'s target, and
3007
3028
  * says whether it did — so a renderer reports only a command that ran, and a
3008
3029
  * stale button or a call through the API cannot run one the grid's state no
3009
- * longer allows.
3030
+ * longer allows. A command whose `execute` returns `false` did not run.
3010
3031
  */
3011
3032
  declare function runCommand<Row>(command: GridCommand<Row>, context: GridCommandContext<Row>): boolean;
3012
3033
 
package/dist/index.js CHANGED
@@ -1872,9 +1872,11 @@ function createGridController(initial) {
1872
1872
  }
1873
1873
  }
1874
1874
  function refresh(keepPage = false) {
1875
+ const before = state;
1875
1876
  const next = followPagingInputs(resolveSlices(), keepPage);
1876
1877
  state = SLICE_KEYS.every((key) => next[key] === state[key]) ? state : next;
1877
1878
  storeShownPage();
1879
+ return state !== before;
1878
1880
  }
1879
1881
  function followPagingInputs(next, keepPage) {
1880
1882
  const inputs = pagingInputsOf(next, options);
@@ -1918,9 +1920,11 @@ function createGridController(initial) {
1918
1920
  mode.held.push(report);
1919
1921
  return;
1920
1922
  }
1921
- refresh();
1923
+ const changed = refresh();
1922
1924
  report();
1923
- notify();
1925
+ if (changed) {
1926
+ notify();
1927
+ }
1924
1928
  }
1925
1929
  function transaction(run) {
1926
1930
  if (mode.kind === "transaction") {
@@ -1937,11 +1941,11 @@ function createGridController(initial) {
1937
1941
  run();
1938
1942
  } finally {
1939
1943
  mode = IDLE;
1940
- refresh(current.pageAsked);
1944
+ const changed = refresh(current.pageAsked);
1941
1945
  for (const report of current.held) {
1942
1946
  report();
1943
1947
  }
1944
- if (current.held.length > 0) {
1948
+ if (changed) {
1945
1949
  notify();
1946
1950
  }
1947
1951
  }
@@ -3321,7 +3325,8 @@ function createDefaultMessages(locale) {
3321
3325
  copySelection: "Copy selection",
3322
3326
  copied: (count, unit) => copied(n, count, unit),
3323
3327
  copyFailed: "Copy failed",
3324
- print: "Print"
3328
+ print: "Print",
3329
+ printFailed: "Print failed"
3325
3330
  };
3326
3331
  }
3327
3332
  var defaultMessages = createDefaultMessages();
@@ -3712,9 +3717,10 @@ function exportCommand({
3712
3717
  selection ? { ...defaults, scope: "selection" } : defaults,
3713
3718
  resolveExportWriters(exportWriters)
3714
3719
  );
3715
- if (file !== null) {
3716
- context.host.saveFile(file);
3720
+ if (file === null) {
3721
+ return;
3717
3722
  }
3723
+ return context.host.saveFile(file) !== false;
3718
3724
  }
3719
3725
  };
3720
3726
  }
@@ -4018,8 +4024,7 @@ function runCommand(command, context) {
4018
4024
  if (!isCommandVisible(command, context) || !isCommandEnabled(command, context)) {
4019
4025
  return false;
4020
4026
  }
4021
- command.execute(context);
4022
- return true;
4027
+ return command.execute(context) !== false;
4023
4028
  }
4024
4029
 
4025
4030
  // src/menu/resolveMenu.ts