pivotkit-react 0.1.0 → 0.2.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 (53) hide show
  1. package/CHANGELOG.md +143 -1
  2. package/README.md +48 -298
  3. package/dist/chunks/chunk-53ZMK4BH.js +177 -0
  4. package/dist/chunks/{chunk-ILHFIV2P.js → chunk-F6MVUAQD.js} +35 -78
  5. package/dist/chunks/chunk-LQCWFJBS.js +310 -0
  6. package/dist/chunks/chunk-OYY4BKIL.js +93 -0
  7. package/dist/chunks/chunk-QBD4FOBB.js +254 -0
  8. package/dist/chunks/{chunk-KKJO36W5.js → chunk-X7H7BAVT.js} +243 -324
  9. package/dist/chunks/unused-texts-YTNJCFFC.js +10 -0
  10. package/dist/chunks/unused-texts-de-SGOHV4N7.js +6 -0
  11. package/dist/echarts.js +96 -11
  12. package/dist/index.js +619 -527
  13. package/dist/labels.js +13 -4
  14. package/dist/menu-texts-de.js +6 -0
  15. package/dist/menus.js +787 -191
  16. package/dist/styles.css +113 -31
  17. package/package.json +2 -2
  18. package/types/chart-layout.d.ts +111 -0
  19. package/types/chart-types.d.ts +0 -91
  20. package/types/drill-panel.d.ts +5 -22
  21. package/types/drill-table.d.ts +71 -0
  22. package/types/drill.d.ts +0 -36
  23. package/types/help.d.ts +21 -0
  24. package/types/icons.d.ts +4 -0
  25. package/types/labels.d.ts +43 -101
  26. package/types/lazy-menus.d.ts +16 -4
  27. package/types/menu-labels-de.d.ts +2 -0
  28. package/types/menu-labels.d.ts +71 -9
  29. package/types/menu-ops.d.ts +145 -0
  30. package/types/menu-texts.d.ts +2 -0
  31. package/types/menus.d.ts +1 -1
  32. package/types/names.d.ts +19 -19
  33. package/types/overflow.d.ts +4 -1
  34. package/types/popover.d.ts +10 -6
  35. package/types/section.d.ts +7 -24
  36. package/types/sections.d.ts +2 -0
  37. package/types/share-actions.d.ts +99 -0
  38. package/types/share.d.ts +0 -9
  39. package/types/table.d.ts +9 -3
  40. package/types/templates.d.ts +7 -1
  41. package/types/tips.d.ts +9 -7
  42. package/types/toolbar-panels.d.ts +8 -5
  43. package/types/unused-load.d.ts +23 -0
  44. package/types/unused-texts-de.d.ts +2 -0
  45. package/types/unused-texts.d.ts +130 -0
  46. package/types/unused.d.ts +22 -0
  47. package/types/use-view-history.d.ts +7 -4
  48. package/types/view-history.d.ts +23 -6
  49. package/types/view-ops.d.ts +72 -123
  50. package/types/view-save.d.ts +76 -0
  51. package/types/view-store.d.ts +13 -6
  52. package/dist/chunks/chunk-C32TYSHG.js +0 -441
  53. package/dist/chunks/chunk-XYP47DJ3.js +0 -123
package/dist/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import {
2
2
  ALL_TIPS,
3
+ CHART_TYPES,
3
4
  ClearInput,
4
5
  DRILL_LIMIT,
5
6
  FIELDS_COLLAPSED,
@@ -7,6 +8,7 @@ import {
7
8
  Icon,
8
9
  InfoButton,
9
10
  LayerContext,
11
+ MAX_CATEGORIES,
10
12
  MenuButton,
11
13
  NO_EXPLANATIONS,
12
14
  Option,
@@ -18,40 +20,50 @@ import {
18
20
  activeTips,
19
21
  addField,
20
22
  allowedTips,
23
+ chartPlan,
24
+ chartTypeOf,
21
25
  cleanDismissed,
22
- copyText,
23
26
  drillRows,
24
- drillTable,
25
27
  fieldAction,
26
28
  fieldsCollapsed,
27
29
  filterZoneFields,
28
30
  filtersOf,
29
31
  groupField,
30
32
  groupingName,
33
+ headerSortState,
34
+ headerSortTarget,
31
35
  helpSwitch,
32
36
  isEmptyView,
33
37
  keptOnReset,
34
38
  layoutSummary,
39
+ linkNow,
40
+ linkParam,
41
+ loadCheck,
42
+ loadLink,
35
43
  localStore,
36
44
  moveField,
45
+ nextHeaderSort,
37
46
  numberRange,
38
47
  parseStored,
39
48
  readItem,
49
+ readLinkParam,
40
50
  readStored,
51
+ readStoredView,
41
52
  refLabel,
42
53
  removeAt,
43
54
  rootOf,
44
55
  rowFolding,
45
- safeFileName,
46
- saveBlob,
47
56
  sectionOpen,
48
57
  selectedItems,
49
58
  setChart,
50
59
  setChartDisplay,
51
60
  setCollapsed,
52
61
  setDisplay,
62
+ setSort,
53
63
  setTotal,
64
+ shareBase,
54
65
  sortOf,
66
+ sortText,
55
67
  sourceOf,
56
68
  subscribeItem,
57
69
  subscribeStored,
@@ -64,31 +76,29 @@ import {
64
76
  useModal,
65
77
  valueConditionText,
66
78
  valueLabel,
79
+ viewFromObject,
67
80
  withHostOrders,
68
81
  withSection,
69
82
  withoutFilters,
70
83
  writeDismissed,
71
84
  writeItem,
85
+ writeStoredView,
72
86
  zoneOverLimit
73
- } from "./chunks/chunk-KKJO36W5.js";
74
- import {
75
- CHART_TYPES,
76
- MAX_CATEGORIES,
77
- chartPlan,
78
- chartTypeOf
79
- } from "./chunks/chunk-XYP47DJ3.js";
87
+ } from "./chunks/chunk-X7H7BAVT.js";
80
88
  import {
81
89
  LABELS,
90
+ MENU_TEXTS,
82
91
  errorText,
83
92
  fill,
93
+ mergeLabels,
84
94
  messageOf,
85
95
  plural,
86
96
  resolveLabels
87
- } from "./chunks/chunk-ILHFIV2P.js";
97
+ } from "./chunks/chunk-F6MVUAQD.js";
88
98
 
89
99
  // src/PivotReport.jsx
90
- import React11, { useCallback as useCallback9, useEffect as useEffect10, useId as useId4, useMemo as useMemo7, useRef as useRef10, useState as useState11, useSyncExternalStore as useSyncExternalStore3 } from "react";
91
- import { computePivot, encode, normalize as normalize3, fieldLabel as fieldLabel3, findNode, suggestDateUnit, toGrid, toSeries, toViewFile, viewFields, viewFileName, viewFileText } from "pivotkit-core";
100
+ import React12, { useCallback as useCallback9, useEffect as useEffect11, useId as useId4, useMemo as useMemo8, useRef as useRef11, useState as useState12, useSyncExternalStore as useSyncExternalStore3 } from "react";
101
+ import { computePivot, emptyView as emptyView2, encode, fieldLabel as fieldLabel5, normalize as normalize2, suggestDateUnit, toGrid, toSeries, viewFields } from "pivotkit-core";
92
102
 
93
103
  // src/chart.jsx
94
104
  import React, { useEffect, useId, useRef, useState } from "react";
@@ -430,18 +440,18 @@ function PivotDnd({ labels, onDrop, onDragStart, renderOverlay, children }) {
430
440
  /* @__PURE__ */ React2.createElement(DragOverlay, { dropAnimation: reduced ? null : { duration: 160, easing: "cubic-bezier(.2,.8,.2,1)" }, zIndex: 1e3 }, active ? renderOverlay(active) : null)
431
441
  );
432
442
  }
433
- function split(listeners) {
434
- const { onKeyDown, ...pointer } = listeners ?? {};
443
+ function split(listeners2) {
444
+ const { onKeyDown, ...pointer } = listeners2 ?? {};
435
445
  return { pointer, keyboard: onKeyDown ? { onKeyDown } : {} };
436
446
  }
437
447
  function useDragSource(id, source, disabled = false) {
438
- const { setNodeRef, setActivatorNodeRef, attributes, listeners, isDragging } = useDraggable({ id, data: source, disabled });
439
- const { pointer, keyboard } = split(listeners);
448
+ const { setNodeRef, setActivatorNodeRef, attributes, listeners: listeners2, isDragging } = useDraggable({ id, data: source, disabled });
449
+ const { pointer, keyboard } = split(listeners2);
440
450
  return { setNodeRef, isDragging, itemProps: pointer, handleProps: { ref: setActivatorNodeRef, ...attributes, ...keyboard } };
441
451
  }
442
452
  function useChip(id, source) {
443
- const { setNodeRef, setActivatorNodeRef, attributes, listeners, isDragging, transform, transition } = useSortable({ id, data: source });
444
- const { pointer, keyboard } = split(listeners);
453
+ const { setNodeRef, setActivatorNodeRef, attributes, listeners: listeners2, isDragging, transform, transition } = useSortable({ id, data: source });
454
+ const { pointer, keyboard } = split(listeners2);
445
455
  const style = transform ? { transform: `translate3d(${Math.round(transform.x)}px, ${Math.round(transform.y)}px, 0)`, transition } : { transition };
446
456
  return { setNodeRef, isDragging, style, itemProps: pointer, handleProps: { ref: setActivatorNodeRef, ...attributes, ...keyboard } };
447
457
  }
@@ -625,7 +635,7 @@ function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info,
625
635
  onAdd(field.name, zone);
626
636
  }
627
637
  },
628
- fill(labels.addTo, { zone: labels.zones[zone] })
638
+ fill(zone === "values" && zones.includes("values") ? labels.addAgain : labels.addTo, { zone: labels.zones[zone] })
629
639
  )), zones.length === 0 && onFilter ? /* @__PURE__ */ React3.createElement(
630
640
  Option,
631
641
  {
@@ -768,9 +778,22 @@ function FieldPanel({ fields, placed, labels, onAdd, onNote, onFilter, drawer, o
768
778
 
769
779
  // src/lazy-menus.jsx
770
780
  import React4, { useEffect as useEffect3, useRef as useRef3, useState as useState4 } from "react";
781
+
782
+ // src/menu-texts.js
783
+ var MENU_TEXTS_OF = Object.freeze({ de: () => import("./menu-texts-de.js").then((m) => m.de) });
784
+
785
+ // src/lazy-menus.jsx
771
786
  var pending = null;
772
787
  var loaded = null;
773
- function loadMenus() {
788
+ var textsPending = /* @__PURE__ */ new Map();
789
+ var textsFailed = /* @__PURE__ */ new Set();
790
+ var listeners = /* @__PURE__ */ new Set();
791
+ function onMenuTexts(listener) {
792
+ listeners.add(listener);
793
+ return () => void listeners.delete(listener);
794
+ }
795
+ var wantsTexts = (lang) => Object.hasOwn(MENU_TEXTS_OF, lang) && !loaded?.hasMenuTexts(lang);
796
+ function loadMenus(lang = "en") {
774
797
  pending ??= import("./menus.js").then(
775
798
  (m) => {
776
799
  loaded = m;
@@ -781,9 +804,38 @@ function loadMenus() {
781
804
  throw error;
782
805
  }
783
806
  );
784
- return pending;
807
+ const menus = pending;
808
+ if (!wantsTexts(lang)) {
809
+ return menus;
810
+ }
811
+ let texts = textsPending.get(lang);
812
+ if (!texts) {
813
+ const done = () => listeners.forEach((f) => f());
814
+ texts = Promise.all([menus, MENU_TEXTS_OF[lang]()]).then(
815
+ ([m, t]) => {
816
+ m.addMenuTexts(lang, t);
817
+ textsFailed.delete(lang);
818
+ done();
819
+ },
820
+ () => {
821
+ textsPending.delete(lang);
822
+ textsFailed.add(lang);
823
+ done();
824
+ }
825
+ );
826
+ textsPending.set(lang, texts);
827
+ }
828
+ return texts.then(() => menus);
829
+ }
830
+ var menusNow = (lang = "en") => loaded && (!wantsTexts(lang) || textsFailed.has(lang)) ? loaded : null;
831
+ function Loading({ text }) {
832
+ const [say, setSay] = useState4(false);
833
+ useEffect3(() => {
834
+ const t = setTimeout(() => setSay(true), 0);
835
+ return () => clearTimeout(t);
836
+ }, []);
837
+ return /* @__PURE__ */ React4.createElement("p", { className: "pk-hint pk-menu-loading", role: "status" }, say ? text : null);
785
838
  }
786
- var menusNow = () => loaded;
787
839
  function focusFirst(el) {
788
840
  const popover = el.closest(".pk-popover");
789
841
  const now = activeIn(el);
@@ -796,7 +848,19 @@ function focusFirst(el) {
796
848
  }
797
849
  }
798
850
  function MenuPanel({ name, loadingText, props }) {
799
- const [mod, setMod] = useState4(loaded);
851
+ const labels = props.labels;
852
+ const lang = labels?.lang;
853
+ const [, setLoads] = useState4(0);
854
+ useEffect3(() => onMenuTexts(() => setLoads((n) => n + 1)), []);
855
+ const mod = menusNow(lang);
856
+ const current = mod && labels ? mod.menuLabels(labels) : null;
857
+ const [kept, setKept] = useState4(
858
+ /** @type {any} */
859
+ null
860
+ );
861
+ if (current && current !== kept) {
862
+ setKept(current);
863
+ }
800
864
  const [failed, setFailed] = useState4(false);
801
865
  const [attempt, setAttempt] = useState4(0);
802
866
  const box = useRef3(
@@ -804,17 +868,22 @@ function MenuPanel({ name, loadingText, props }) {
804
868
  null
805
869
  );
806
870
  const late = useRef3(false);
871
+ const tried = useRef3(
872
+ /** @type {string | undefined | null} */
873
+ null
874
+ );
807
875
  useEffect3(() => {
808
- if (mod) {
876
+ if (mod && (!wantsTexts(lang) || tried.current === lang)) {
809
877
  return void 0;
810
878
  }
811
- late.current = true;
879
+ tried.current = lang;
880
+ late.current = !mod;
812
881
  let live = true;
813
- loadMenus().then(
814
- (m) => {
882
+ loadMenus(lang).then(
883
+ () => {
815
884
  if (live) {
816
885
  setFailed(false);
817
- setMod(m);
886
+ setLoads((n) => n + 1);
818
887
  }
819
888
  },
820
889
  () => {
@@ -826,20 +895,20 @@ function MenuPanel({ name, loadingText, props }) {
826
895
  return () => {
827
896
  live = false;
828
897
  };
829
- }, [mod, attempt]);
898
+ }, [mod, attempt, lang]);
830
899
  useEffect3(() => {
831
900
  if (box.current && (mod && late.current || failed)) {
832
901
  focusFirst(box.current);
833
902
  }
834
903
  }, [mod, failed]);
835
- const Panel = mod ? (
904
+ const shown = mod ?? (kept ? menusNow() : null);
905
+ const Panel = shown ? (
836
906
  /** @type {any} */
837
- mod[name]
907
+ shown[name]
838
908
  ) : null;
839
- const labels = props.labels;
840
909
  return /* @__PURE__ */ React4.createElement("div", { className: "pk-menu-panel", ref: box }, Panel ? (
841
910
  // the menus' own texts (menu-labels.js) come with them, under the report's labels
842
- /* @__PURE__ */ React4.createElement(Panel, { ...props, labels: labels && mod ? mod.menuLabels(labels) : labels })
911
+ /* @__PURE__ */ React4.createElement(Panel, { ...props, labels: current ?? kept ?? labels })
843
912
  ) : failed && labels ? /* @__PURE__ */ React4.createElement("div", { className: "pk-menu-failed", role: "alert", "data-testid": "menu-failed" }, /* @__PURE__ */ React4.createElement("p", null, labels.menuFailed), /* @__PURE__ */ React4.createElement(
844
913
  "button",
845
914
  {
@@ -853,145 +922,7 @@ function MenuPanel({ name, loadingText, props }) {
853
922
  }
854
923
  },
855
924
  labels.tryAgain
856
- )) : loadingText ? /* @__PURE__ */ React4.createElement("p", { className: "pk-hint pk-menu-loading", role: "status" }, loadingText) : null);
857
- }
858
-
859
- // src/share.js
860
- import { VIEW_FILE_LIMITS, fromViewFile, normalize } from "pivotkit-core";
861
- var linkModule = null;
862
- var linkLoaded = null;
863
- function loadLink() {
864
- linkModule ??= import("pivotkit-core/link").then((m) => {
865
- linkLoaded = m;
866
- return m;
867
- });
868
- return linkModule;
869
- }
870
- var linkNow = () => linkLoaded;
871
- function linkParam(storageKey) {
872
- return storageKey ? `pivot-${storageKey}` : "pivot";
873
- }
874
- var entries = (fragment) => fragment ? fragment.split("&") : [];
875
- var isEntry = (entry, param) => entry.startsWith(`${encodeURIComponent(param)}=`);
876
- function readLinkParam(hash, param) {
877
- const text = typeof hash === "string" ? hash.replace(/^#/, "") : "";
878
- const entry = entries(text).find((e) => isEntry(e, param));
879
- const value = entry ? entry.slice(encodeURIComponent(param).length + 1) : "";
880
- return value ? value : null;
881
- }
882
- function withLinkParam(url, param, encoded) {
883
- const at = url.indexOf("#");
884
- const base = at === -1 ? url : url.slice(0, at);
885
- const kept = entries(at === -1 ? "" : url.slice(at + 1)).filter((e) => !isEntry(e, param));
886
- const next = encoded ? [...kept, `${encodeURIComponent(param)}=${encoded}`] : kept;
887
- return next.length ? `${base}#${next.join("&")}` : base;
888
- }
889
- function shareBase(shareLink, here2) {
890
- if (shareLink === true) {
891
- if (!here2) {
892
- return null;
893
- }
894
- try {
895
- const url = new URL(here2);
896
- return `${url.origin}${url.pathname}${url.hash}`;
897
- } catch {
898
- return null;
899
- }
900
- }
901
- return typeof shareLink === "string" && shareLink.trim() ? shareLink.trim() : null;
902
- }
903
- var viewStorageName = (key) => `pivotkit:view:${key ?? ""}`;
904
- function readStoredView(key, storage) {
905
- if (!storage) {
906
- return null;
907
- }
908
- try {
909
- return storage.getItem(viewStorageName(key));
910
- } catch {
911
- return null;
912
- }
913
- }
914
- function writeStoredView(key, storage, view) {
915
- if (!storage) {
916
- return;
917
- }
918
- try {
919
- storage.setItem(viewStorageName(key), JSON.stringify(view));
920
- } catch {
921
- }
922
- }
923
- var VIEW_TEXT_MAX = VIEW_FILE_LIMITS.text;
924
- var quoteNames = (names) => {
925
- const shown = names.slice(0, 5).map((n) => `\u201C${n.length > 60 ? `${n.slice(0, 59)}\u2026` : n}\u201D`).join(", ");
926
- return names.length > 5 ? `${shown} \u2026` : shown;
927
- };
928
- var fieldOf = (message) => /^unknown field (".*")$/.exec(message)?.[1];
929
- function issueLines(issues, labels) {
930
- const missing = [];
931
- let other = 0;
932
- for (const issue of issues) {
933
- if (issue.message === "unknown key") {
934
- continue;
935
- }
936
- const quoted = fieldOf(issue.message);
937
- let name;
938
- try {
939
- name = quoted ? JSON.parse(quoted) : null;
940
- } catch {
941
- name = null;
942
- }
943
- if (typeof name === "string") {
944
- if (!missing.includes(name)) {
945
- missing.push(name);
946
- }
947
- } else {
948
- other += 1;
949
- }
950
- }
951
- const lines = [];
952
- if (missing.length) {
953
- lines.push(fill(labels.viewMissingFields, { fields: quoteNames(missing) }));
954
- }
955
- if (other) {
956
- lines.push(fill(other === 1 ? labels.viewOtherIssue : labels.viewOtherIssues, { count: other }));
957
- }
958
- return lines;
959
- }
960
- var FAILED = Object.freeze({ newerFormat: "newer", newerView: "newer" });
961
- function viewFromText(text, encoded, options = {}) {
962
- return viewFromObject(text, encoded, options);
963
- }
964
- function viewFromObject(input, encoded, options = {}) {
965
- const file = fromViewFile(input, { data: encoded, sourceId: options.sourceId });
966
- if (file.failed || !file.view) {
967
- const failed = file.failed ?? "notView";
968
- return { view: null, issues: file.issues, failed: Object.hasOwn(FAILED, failed) ? FAILED[failed] : failed, file };
969
- }
970
- const { view, issues } = normalize(file.view, encoded, options.limits ? { limits: options.limits } : void 0);
971
- if (issues.some((i) => i.path === "version")) {
972
- return { view: null, issues, failed: "newer", file };
973
- }
974
- return { view, issues, failed: null, file };
975
- }
976
- function loadCheck(loaded2, labels, sources = []) {
977
- const fit = loaded2.file?.compatible;
978
- if (!loaded2.view || !fit || fit.ok) {
979
- return null;
980
- }
981
- const lines = [];
982
- const fileSource = loaded2.file?.source;
983
- const target = fit.source === "other" && fileSource?.id ? sources.find((s) => s && s.id === fileSource.id) : void 0;
984
- if (fit.source === "other") {
985
- const name = target?.name || fileSource?.name || fileSource?.id;
986
- lines.push(name ? fill(labels.loadCheckSource, { source: name }) : labels.loadCheckOtherSource);
987
- }
988
- if (fit.missing.length) {
989
- lines.push(fill(labels.loadCheckMissing, { fields: quoteNames(fit.missing) }));
990
- }
991
- if (fit.changed.length) {
992
- lines.push(fill(labels.loadCheckChanged, { fields: quoteNames(fit.changed.map((c) => c.name)) }));
993
- }
994
- return { lines, switchTo: target ? { id: target.id, name: target.name || target.id } : null };
925
+ )) : loadingText ? /* @__PURE__ */ React4.createElement(Loading, { text: loadingText }) : null);
995
926
  }
996
927
 
997
928
  // src/skeleton.jsx
@@ -1004,6 +935,7 @@ function Skeleton({ text, full = false }) {
1004
935
 
1005
936
  // src/table.jsx
1006
937
  import React6, { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo3, useRef as useRef4, useState as useState5 } from "react";
938
+ import { fieldLabel as fieldLabel2 } from "pivotkit-core";
1007
939
 
1008
940
  // src/virtual.js
1009
941
  var VIRTUAL_FROM = 300;
@@ -1084,16 +1016,16 @@ function firstValueCell(grid) {
1084
1016
  }
1085
1017
  return null;
1086
1018
  }
1087
- function DraggableHeader({ cell, source, children, className, style, colSpan, rowSpan, scope, description, tooltip = true }) {
1019
+ function DraggableHeader({ cell, source, children, className, style, colSpan, rowSpan, scope, description, tooltip = true, sort }) {
1088
1020
  const { setNodeRef, isDragging, itemProps } = useDragSource(`table:${source.zone}:${source.index}:${source.field ?? ""}`, source);
1089
- return /* @__PURE__ */ React6.createElement("th", { ref: setNodeRef, ...itemProps, className: `${className} pk-draggable${isDragging ? " pk-dragging" : ""}`, style, colSpan, rowSpan, scope, "data-kind": cell.kind, title: tooltip ? description : void 0, "aria-description": description }, children, /* @__PURE__ */ React6.createElement(Icon, { name: "grip", size: 12, className: "pk-th-grip" }));
1021
+ return /* @__PURE__ */ React6.createElement("th", { ref: setNodeRef, ...itemProps, className: `${className} pk-draggable${isDragging ? " pk-dragging" : ""}`, style, colSpan, rowSpan, scope, "data-kind": cell.kind, title: tooltip ? description : void 0, "aria-description": description, "aria-sort": sort ?? void 0 }, children, /* @__PURE__ */ React6.createElement(Icon, { name: "grip", size: 12, className: "pk-th-grip" }));
1090
1022
  }
1091
1023
  var toggleKey = (axis, path) => `${axis}:${JSON.stringify(path)}`;
1092
1024
  function Toggle({ toggle, text, labels, onToggle }) {
1093
1025
  const name = fill(toggle.collapsed ? labels.expand : labels.collapse, { label: text });
1094
1026
  return /* @__PURE__ */ React6.createElement("button", { type: "button", className: `pk-toggle${toggle.collapsed ? "" : " pk-open"}`, "aria-expanded": !toggle.collapsed, "aria-label": name, title: name, "data-pk-toggle": toggleKey(toggle.axis, toggle.path), onClick: () => onToggle(toggle.axis, toggle.path) }, /* @__PURE__ */ React6.createElement(Icon, { name: "chevronRight", size: 16 }));
1095
1027
  }
1096
- function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version, hintId, onRowLabel, infoOf, showInfo = true }) {
1028
+ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version, hintId, onRowLabel, infoOf, showInfo = true, typeOf = () => void 0, hostOrdered = () => false, onSort }) {
1097
1029
  const wrap = useRef4(
1098
1030
  /** @type {HTMLDivElement | null} */
1099
1031
  null
@@ -1121,6 +1053,7 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1121
1053
  null
1122
1054
  );
1123
1055
  const focusNext = useRef4(false);
1056
+ const [sortNote, setSortNote] = useState5("");
1124
1057
  const focusToggle = useRef4(
1125
1058
  /** @type {string | null} */
1126
1059
  null
@@ -1269,23 +1202,41 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1269
1202
  }
1270
1203
  }
1271
1204
  };
1205
+ const sortButton = (cell, target) => {
1206
+ const state = headerSortState(view, target);
1207
+ const next = nextHeaderSort(view, target, hostOrdered(target.field));
1208
+ const field = fieldLabel2(target.field, labels.core);
1209
+ const words = (s) => sortText(view, s ?? { by: hostOrdered(target.field) ? "custom" : "label", order: "asc" }, labels);
1210
+ const down = state.chosen ? state.order === "descending" : next?.order === "desc";
1211
+ const click = () => {
1212
+ onSort?.(target.field, next);
1213
+ setSortNote(fill(labels.headerSorted, { field, order: words(next) }));
1214
+ };
1215
+ return {
1216
+ // aria-sort only on the header whose sort was chosen (a custom order too): one at a time (WAI-ARIA APG)
1217
+ sort: state.chosen || state.order === "other" ? state.order : null,
1218
+ content: /* @__PURE__ */ React6.createElement("button", { type: "button", className: `pk-th-sort${state.chosen ? " pk-sorted" : ""}`, title: target.ref && next ? fill(next.order === "desc" ? labels.headerSortDesc : labels.headerSortAsc, { value: refLabel(view, target.ref, labels) }) : fill(labels.headerSort, { field, order: words(next) }), onClick: click }, /* @__PURE__ */ React6.createElement("span", { className: "pk-th-text" }, cell.text), /* @__PURE__ */ React6.createElement(Icon, { name: down ? "arrowDown" : "arrowUp", size: 14, className: "pk-th-arrow" }))
1219
+ };
1220
+ };
1272
1221
  const stickyStyle = (col, extra) => col < grid.rowHeaderColumns && lefts[col] !== void 0 ? { left: lefts[col], ...extra } : extra;
1273
1222
  const headerCell = (cell, r, c) => {
1274
1223
  const top = { top: tops[r] ?? r * rowHeight };
1275
1224
  const sticky = c < grid.rowHeaderColumns;
1276
1225
  const className = `pk-th pk-${cell.kind}${totalClass(cell.total)}${sticky ? " pk-sticky" : ""}`;
1277
- const content = /* @__PURE__ */ React6.createElement("span", { className: "pk-th-content" }, cell.toggle ? /* @__PURE__ */ React6.createElement(Toggle, { toggle: cell.toggle, text: cell.text, labels, onToggle }) : null, /* @__PURE__ */ React6.createElement("span", { className: "pk-th-text" }, cell.text));
1226
+ const target = onSort && r === grid.headerRows - 1 ? headerSortTarget(view, cell, typeOf) : null;
1227
+ const sorting = target ? sortButton(cell, target) : null;
1228
+ const content = /* @__PURE__ */ React6.createElement("span", { className: "pk-th-content" }, cell.toggle ? /* @__PURE__ */ React6.createElement(Toggle, { toggle: cell.toggle, text: cell.text, labels, onToggle }) : null, sorting ? sorting.content : /* @__PURE__ */ React6.createElement("span", { className: "pk-th-text" }, cell.text));
1278
1229
  const props = { className, style: stickyStyle(c, top), colSpan: cell.colSpan, rowSpan: cell.rowSpan, scope: cell.kind === "colHeader" ? "col" : void 0 };
1279
1230
  if (cell.kind === "corner" && !cell.field && !cell.text) {
1280
1231
  return /* @__PURE__ */ React6.createElement("td", { key: c, className: `${className} pk-blank`, style: props.style, colSpan: cell.colSpan, rowSpan: cell.rowSpan });
1281
1232
  }
1282
1233
  if (cell.kind === "corner" && cell.field) {
1283
1234
  const zone = view.rows.includes(cell.field) ? "rows" : "cols";
1284
- return /* @__PURE__ */ React6.createElement(DraggableHeader, { key: c, ...props, cell, source: { kind: "table", field: cell.field, zone, index: view[zone].indexOf(cell.field), label: cell.text }, description: infoOf?.(cell.field)?.description, tooltip: showInfo }, content);
1235
+ return /* @__PURE__ */ React6.createElement(DraggableHeader, { key: c, ...props, cell, source: { kind: "table", field: cell.field, zone, index: view[zone].indexOf(cell.field), label: cell.text }, description: infoOf?.(cell.field)?.description, tooltip: showInfo, sort: sorting?.sort }, content);
1285
1236
  }
1286
1237
  if (cell.kind === "colHeader" && cell.valueIndex !== void 0 && r === grid.headerRows - 1) {
1287
1238
  const spec = view.values[cell.valueIndex];
1288
- return /* @__PURE__ */ React6.createElement(DraggableHeader, { key: c, ...props, cell, source: { kind: "table", field: spec?.field ?? null, zone: "values", index: cell.valueIndex, label: cell.text }, description: spec?.field ? infoOf?.(spec.field)?.description : void 0, tooltip: showInfo }, content);
1239
+ return /* @__PURE__ */ React6.createElement(DraggableHeader, { key: c, ...props, cell, source: { kind: "table", field: spec?.field ?? null, zone: "values", index: cell.valueIndex, label: cell.text }, description: spec?.field ? infoOf?.(spec.field)?.description : void 0, tooltip: showInfo, sort: sorting?.sort }, content);
1289
1240
  }
1290
1241
  return /* @__PURE__ */ React6.createElement("th", { key: c, ...props }, content);
1291
1242
  };
@@ -1317,7 +1268,7 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1317
1268
  );
1318
1269
  };
1319
1270
  const columns = grid.columnCount;
1320
- return /* @__PURE__ */ React6.createElement("div", { className: "pk-table-wrap", ref: wrap, onScroll: virtual ? onScroll : void 0, onBlur: virtual ? onBlur : void 0, "data-testid": "pivot-table" }, /* @__PURE__ */ React6.createElement("table", { ref: table, className: `pk-table${virtual ? " pk-virtual" : ""}`, style: (
1271
+ return /* @__PURE__ */ React6.createElement("div", { className: "pk-table-wrap", ref: wrap, onScroll: virtual ? onScroll : void 0, onBlur: virtual ? onBlur : void 0, "data-testid": "pivot-table" }, onSort ? /* @__PURE__ */ React6.createElement("span", { className: "pk-sr", role: "status", "data-testid": "sort-status" }, sortNote) : null, /* @__PURE__ */ React6.createElement("table", { ref: table, className: `pk-table${virtual ? " pk-virtual" : ""}`, style: (
1321
1272
  /** @type {any} */
1322
1273
  { "--pk-row-cols": grid.rowHeaderColumns }
1323
1274
  ), onKeyDown, "aria-rowcount": grid.rows.length, "aria-label": labels.tableName, "aria-describedby": hintId }, /* @__PURE__ */ React6.createElement("thead", null, grid.rows.slice(0, grid.headerRows).map((row, r) => /* @__PURE__ */ React6.createElement("tr", { key: r }, row.map((cell, c) => cell ? headerCell(cell, r, c) : null)))), /* @__PURE__ */ React6.createElement("tbody", null, win.padTop > 0 ? /* @__PURE__ */ React6.createElement("tr", { className: "pk-spacer", "aria-hidden": "true", style: { height: win.padTop } }, /* @__PURE__ */ React6.createElement("td", { colSpan: columns })) : null, rows.map(({ index, cells }) => /* @__PURE__ */ React6.createElement("tr", { key: index, "data-r": index, "aria-rowindex": grid.headerRows + index + 1, className: totalClass(grid.bodyRows[index]?.total).trim() || void 0 }, cells.map((c) => bodyCell(c, index)))), win.padBottom > 0 ? /* @__PURE__ */ React6.createElement("tr", { className: "pk-spacer", "aria-hidden": "true", style: { height: win.padBottom } }, /* @__PURE__ */ React6.createElement("td", { colSpan: columns })) : null)));
@@ -1401,7 +1352,7 @@ function Toasts({ toasts, dismiss, pause, closeLabel }) {
1401
1352
  }
1402
1353
 
1403
1354
  // src/templates.js
1404
- import { fieldDefaultsFromSchema as fieldDefaultsFromSchema2, fromViewFile as fromViewFile2 } from "pivotkit-core";
1355
+ import { fieldDefaultsFromSchema as fieldDefaultsFromSchema2, fromViewFile } from "pivotkit-core";
1405
1356
  var warnedScope = false;
1406
1357
  function plainNames(names) {
1407
1358
  const properties = {};
@@ -1418,7 +1369,7 @@ function templateEntries(templates, stored, hostDeletes) {
1418
1369
  }
1419
1370
  let { name, view } = t;
1420
1371
  if (t.file !== void 0 && t.file !== null) {
1421
- const read = fromViewFile2(t.file);
1372
+ const read = fromViewFile(t.file);
1422
1373
  view = read.view;
1423
1374
  name = typeof name === "string" && name ? name : read.name;
1424
1375
  }
@@ -1435,7 +1386,7 @@ function templateEntries(templates, stored, hostDeletes) {
1435
1386
  const all = [...out, ...stored.map((t) => ({ name: t.name, view: t.view, scope: (
1436
1387
  /** @type {const} */
1437
1388
  "user"
1438
- ), deletable: true, at: t.at }))];
1389
+ ), deletable: true, at: t.at, ...t.sourceId ? { sourceId: t.sourceId } : {} }))];
1439
1390
  const names = plainNames(all.map((t) => t.name));
1440
1391
  return all.flatMap((t, i) => names[i] ? [{ ...t, name: (
1441
1392
  /** @type {string} */
@@ -1487,11 +1438,118 @@ function Tips({ tips, labels, onDismiss, onAction, focusFallback }) {
1487
1438
  )))) : null, /* @__PURE__ */ React8.createElement("div", { className: "pk-sr", "aria-live": "polite", "data-testid": "tips-live" }, tips.map((t) => /* @__PURE__ */ React8.createElement("p", { key: t.id }, t.text))));
1488
1439
  }
1489
1440
 
1441
+ // src/unused.jsx
1442
+ import React9, { useEffect as useEffect7, useMemo as useMemo4, useRef as useRef7, useState as useState7 } from "react";
1443
+ import { fieldLabel as fieldLabel3 } from "pivotkit-core";
1444
+
1445
+ // src/unused-load.js
1446
+ var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-SGOHV4N7.js").then((m) => m.de) });
1447
+ var pending2 = /* @__PURE__ */ new Map();
1448
+ var loaded2 = /* @__PURE__ */ new Map();
1449
+ var unusedNow = (lang) => loaded2.get(lang) ?? null;
1450
+ function loadUnused(lang) {
1451
+ let p = pending2.get(lang);
1452
+ if (!p) {
1453
+ const own2 = Object.hasOwn(UNUSED_TEXTS_OF, lang) ? UNUSED_TEXTS_OF[lang]().catch(() => null) : null;
1454
+ p = Promise.all([import("./chunks/unused-texts-YTNJCFFC.js"), own2]).then(
1455
+ ([mod, texts]) => {
1456
+ const out = { mod, lang: texts };
1457
+ loaded2.set(lang, out);
1458
+ return out;
1459
+ },
1460
+ (error) => {
1461
+ pending2.delete(lang);
1462
+ throw error;
1463
+ }
1464
+ );
1465
+ pending2.set(lang, p);
1466
+ }
1467
+ return p;
1468
+ }
1469
+ function unusedTexts(loaded3, labels) {
1470
+ const host = (
1471
+ /** @type {any} */
1472
+ labels[MENU_TEXTS]
1473
+ );
1474
+ return mergeLabels(mergeLabels(loaded3.mod.en, loaded3.lang), host && typeof host === "object" ? host.unused : void 0);
1475
+ }
1476
+
1477
+ // src/unused.jsx
1478
+ var FIRST = { narrow: 2, wide: 3 };
1479
+ var FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
1480
+ function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow, quiet }) {
1481
+ const lang = labels.lang;
1482
+ const show = notes.length > 0 && !dismissed;
1483
+ const [folded, setFolded] = useState7(
1484
+ /** @type {string | null} */
1485
+ null
1486
+ );
1487
+ const [all, setAll] = useState7(
1488
+ /** @type {string | null} */
1489
+ null
1490
+ );
1491
+ const [got, setGot] = useState7(
1492
+ /** @type {{ lang: string, value: import("./unused-load.js").UnusedLoaded } | null} */
1493
+ null
1494
+ );
1495
+ const box = useRef7(
1496
+ /** @type {HTMLDivElement | null} */
1497
+ null
1498
+ );
1499
+ const now = got?.lang === lang ? got.value : unusedNow(lang);
1500
+ const issues = useMemo4(() => (
1501
+ /** @type {Array<{ issue: import("pivotkit-core").Issue, raw: unknown }>} */
1502
+ notes.filter((n) => "issue" in n)
1503
+ ), [notes]);
1504
+ const wanted = show && issues.length > 0;
1505
+ useEffect7(() => {
1506
+ if (!wanted || now) {
1507
+ return void 0;
1508
+ }
1509
+ let live = true;
1510
+ loadUnused(lang).then(
1511
+ (value) => live && setGot({ lang, value }),
1512
+ // the core's messages stay; the next view with unused parts tries again
1513
+ () => void 0
1514
+ );
1515
+ return () => {
1516
+ live = false;
1517
+ };
1518
+ }, [wanted, now, lang, notesKey]);
1519
+ const plain = useMemo4(() => {
1520
+ if (!now || !wanted) {
1521
+ return null;
1522
+ }
1523
+ const ctx = { labels, fill, field: (name) => fieldLabel3(name, labels.core), value: (spec) => valueLabel(spec, labels) };
1524
+ return now.mod.unusedItems(issues, unusedTexts(now, labels), ctx);
1525
+ }, [now, wanted, issues, labels]);
1526
+ const title = plural(labels.unusedParts, notes.length, { lang, locale });
1527
+ const first = FIRST[narrow ? "narrow" : "wide"];
1528
+ const cut = all !== notesKey && notes.length > first + 1 ? first : notes.length;
1529
+ const dismiss = () => {
1530
+ const el = box.current;
1531
+ const root = el?.closest(".pk-root");
1532
+ const next = el && root ? [...root.querySelectorAll(FOCUSABLE)].find((c) => !el.contains(c) && el.compareDocumentPosition(c) & Node.DOCUMENT_POSITION_FOLLOWING) : null;
1533
+ onDismiss(
1534
+ /** @type {HTMLElement | null} */
1535
+ next ?? null
1536
+ );
1537
+ };
1538
+ const lineOf = new Map(plain ? issues.map((n, i) => [n, plain[i]]) : []);
1539
+ return /* @__PURE__ */ React9.createElement(React9.Fragment, null, show ? /* @__PURE__ */ React9.createElement("div", { className: "pk-note pk-issues", "data-testid": "view-issues", ref: box }, /* @__PURE__ */ React9.createElement(Icon, { name: "warn", size: 16 }), /* @__PURE__ */ React9.createElement("details", { open: folded !== notesKey, onToggle: (e) => setFolded(e.currentTarget.open ? null : notesKey) }, /* @__PURE__ */ React9.createElement("summary", { "data-testid": "unused-title" }, title), /* @__PURE__ */ React9.createElement("ul", null, notes.slice(0, cut).map((n, i) => {
1540
+ if (!("issue" in n)) {
1541
+ return /* @__PURE__ */ React9.createElement("li", { key: i }, n.text);
1542
+ }
1543
+ const line = lineOf.get(n);
1544
+ return /* @__PURE__ */ React9.createElement("li", { key: i, "data-testid": "unused-item" }, line ? /* @__PURE__ */ React9.createElement(React9.Fragment, null, line.pre, /* @__PURE__ */ React9.createElement("strong", null, line.subject), line.post) : n.issue.message, n.issue.path || line ? /* @__PURE__ */ React9.createElement("small", { className: "pk-issues-path", "data-testid": "unused-path" }, labels.unusedPath, " ", /* @__PURE__ */ React9.createElement("code", null, n.issue.path), line ? ` \xB7 ${n.issue.message}` : null) : null);
1545
+ })), notes.length > first + 1 ? /* @__PURE__ */ React9.createElement("button", { type: "button", className: "pk-btn pk-small-btn pk-issues-more", onClick: () => setAll(all === notesKey ? null : notesKey), "data-testid": "unused-more" }, cut < notes.length ? plural(labels.unusedMore, notes.length - cut, { lang, locale }) : labels.unusedFewer) : null), /* @__PURE__ */ React9.createElement("button", { type: "button", className: "pk-icon-btn pk-issues-x", "aria-label": labels.dismissIssues, title: labels.dismissIssues, onClick: dismiss, "data-testid": "dismiss-issues" }, /* @__PURE__ */ React9.createElement(Icon, { name: "x", size: 14 }))) : null, /* @__PURE__ */ React9.createElement("div", { className: "pk-sr", "aria-live": "polite", "data-testid": "unused-live" }, show && !quiet ? title : null));
1546
+ }
1547
+
1490
1548
  // src/toolbar.jsx
1491
- import React9, { useCallback as useCallback4, useEffect as useEffect7, useMemo as useMemo4, useRef as useRef7, useState as useState7 } from "react";
1549
+ import React10, { useCallback as useCallback4, useEffect as useEffect8, useMemo as useMemo5, useRef as useRef8, useState as useState8 } from "react";
1492
1550
 
1493
1551
  // src/overflow.js
1494
- var OVERFLOW_ORDER = Object.freeze(["reset", "layout", "views", "options", "chartType"]);
1552
+ var OVERFLOW_ORDER = Object.freeze(["reset", "layout", "options", "chartType", "views"]);
1495
1553
  var TOOLBAR_ROOM = Object.freeze({
1496
1554
  // measured in Chromium at the playground's font: the longer of English and German with the gap
1497
1555
  // after it, plus 2 %; a wider font still fits, as useOverflow measures as well
@@ -1558,7 +1616,7 @@ function overflowLevel(width, narrow, room = TOOLBAR_ROOM) {
1558
1616
 
1559
1617
  // src/toolbar.jsx
1560
1618
  function TextButton({ icon, label, onClick, disabled, testId, shortcut }) {
1561
- return /* @__PURE__ */ React9.createElement("button", { type: "button", className: "pk-btn", onClick, disabled, title: shortcut ? `${label} (${shortcut})` : void 0, "aria-keyshortcuts": shortcut ? shortcut.replace("\u2318", "Meta+").replace("\u21E7", "Shift+") : void 0, "data-testid": testId }, /* @__PURE__ */ React9.createElement(Icon, { name: icon }), /* @__PURE__ */ React9.createElement("span", { className: "pk-btn-text" }, label));
1619
+ return /* @__PURE__ */ React10.createElement("button", { type: "button", className: "pk-btn", onClick, disabled, title: shortcut ? `${label} (${shortcut})` : void 0, "aria-keyshortcuts": shortcut ? shortcut.replace("\u2318", "Meta+").replace("\u21E7", "Shift+") : void 0, "data-testid": testId }, /* @__PURE__ */ React10.createElement(Icon, { name: icon }), /* @__PURE__ */ React10.createElement("span", { className: "pk-btn-text" }, label));
1562
1620
  }
1563
1621
  var measuring;
1564
1622
  var fontOf = (style) => `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
@@ -1610,10 +1668,10 @@ function measuredRoom(el, texts) {
1610
1668
  return toolbarRoom(texts, measure, chrome);
1611
1669
  }
1612
1670
  function useOverflow(ref, key, narrow, max, texts) {
1613
- const [level, setLevel] = useState7(0);
1614
- const [measure, setMeasure] = useState7(0);
1615
- const [lastKey, setLastKey] = useState7(key);
1616
- const latest = useRef7(texts);
1671
+ const [level, setLevel] = useState8(0);
1672
+ const [measure, setMeasure] = useState8(0);
1673
+ const [lastKey, setLastKey] = useState8(key);
1674
+ const latest = useRef8(texts);
1617
1675
  useIsoLayoutEffect(() => {
1618
1676
  latest.current = texts;
1619
1677
  });
@@ -1659,26 +1717,26 @@ function useOverflow(ref, key, narrow, max, texts) {
1659
1717
  return level;
1660
1718
  }
1661
1719
  function Toolbar(props) {
1662
- const { view, labels, size, canUndo, canRedo, canReset, onUndo, onRedo, onReset, onDisplay, onChart, onChartDisplay, onTotal, onExpand, onCollapse, folding, templates, onLoadTemplate, templateActions, onExport, chartReady, onShowFields, layoutFolded, onLayout, zonesId, share } = props;
1720
+ const { view, labels, size, canUndo, canRedo, canReset, onUndo, onRedo, onReset, loadedView, empty, onDisplay, onChart, onChartDisplay, onTotal, onExpand, onCollapse, folding, templates, onLoadTemplate, templateActions, onExport, chartReady, onShowFields, layoutFolded, onLayout, zonesId, share } = props;
1663
1721
  const tips = { controls: props.tipsControls, on: props.tipsOn, onOn: props.onTipsOn, canReset: props.canResetTips, onReset: props.onResetTips };
1664
- const bar = useRef7(
1722
+ const bar = useRef8(
1665
1723
  /** @type {HTMLDivElement | null} */
1666
1724
  null
1667
1725
  );
1668
- const more = useRef7(
1726
+ const more = useRef8(
1669
1727
  /** @type {HTMLButtonElement | null} */
1670
1728
  null
1671
1729
  );
1672
- const viewsButton = useRef7(
1730
+ const viewsButton = useRef8(
1673
1731
  /** @type {HTMLButtonElement | null} */
1674
1732
  null
1675
1733
  );
1676
- const [panel, setPanel] = useState7(
1734
+ const [panel, setPanel] = useState8(
1677
1735
  /** @type {"options" | "views" | "chartType" | null} */
1678
1736
  null
1679
1737
  );
1680
1738
  const order = OVERFLOW_ORDER;
1681
- const texts = useMemo4(() => toolbarTexts([LABELS.en, LABELS.de, labels]), [labels]);
1739
+ const texts = useMemo5(() => toolbarTexts([LABELS.en, LABELS.de, labels]), [labels]);
1682
1740
  const level = useOverflow(bar, `${labels.lang}:${labels.undo}:${size}`, size === "narrow", order.length, texts);
1683
1741
  const hidden = new Set(order.slice(0, level));
1684
1742
  if (panel && !hidden.has(panel)) {
@@ -1686,8 +1744,8 @@ function Toolbar(props) {
1686
1744
  }
1687
1745
  const closePanel = useCallback4(() => setPanel(null), []);
1688
1746
  const request = props.viewsRequest ?? 0;
1689
- const [seenRequest, setSeenRequest] = useState7(request);
1690
- const [clickFor, setClickFor] = useState7(0);
1747
+ const [seenRequest, setSeenRequest] = useState8(request);
1748
+ const [clickFor, setClickFor] = useState8(0);
1691
1749
  if (request !== seenRequest) {
1692
1750
  setSeenRequest(request);
1693
1751
  if (hidden.has("views")) {
@@ -1696,7 +1754,7 @@ function Toolbar(props) {
1696
1754
  setClickFor(request);
1697
1755
  }
1698
1756
  }
1699
- useEffect7(() => {
1757
+ useEffect8(() => {
1700
1758
  const button = viewsButton.current;
1701
1759
  if (clickFor > 0 && button && button.getAttribute("aria-expanded") !== "true") {
1702
1760
  button.click();
@@ -1709,23 +1767,23 @@ function Toolbar(props) {
1709
1767
  const chartTypeText = fill(labels.chartTypeIs, { type: labels.chartTypes[preset] });
1710
1768
  const panels = {
1711
1769
  // the panels load with the chip menus (menus.js), on demand
1712
- options: (close) => /* @__PURE__ */ React9.createElement(MenuPanel, { name: "OptionsPanel", loadingText: labels.loadingMenu, props: { view, labels, onTotal, onExpand, onCollapse, close, tips, mod, folding, help: props.help } }),
1713
- views: (close) => /* @__PURE__ */ React9.createElement(MenuPanel, { name: "ViewsPanel", loadingText: labels.loadingMenu, props: { templates, labels, onLoad: onLoadTemplate, actions: templateActions, close, share } }),
1714
- chartType: (close) => /* @__PURE__ */ React9.createElement(MenuPanel, { name: "ChartTypePanel", loadingText: labels.loadingMenu, props: { view, plan, labels, onChart, onDisplay: onChartDisplay, close } })
1770
+ options: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "OptionsPanel", loadingText: labels.loadingMenu, props: { view, labels, onTotal, onExpand, onCollapse, close, tips, mod, folding, help: props.help } }),
1771
+ views: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ViewsPanel", loadingText: labels.loadingMenu, props: { templates, labels, onLoad: onLoadTemplate, actions: templateActions, close, share } }),
1772
+ chartType: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ChartTypePanel", loadingText: labels.loadingMenu, props: { view, plan, labels, onChart, onDisplay: onChartDisplay, close } })
1715
1773
  };
1716
1774
  const actions = {
1717
1775
  chartType: {
1718
1776
  place: "chart",
1719
- button: () => /* @__PURE__ */ React9.createElement(MenuButton, { key: "chartType", label: chartTypeText, name: chartTypeText, title: chartTypeText, icon: drawnIcon, text: labels.chartTypes[preset], role: "dialog", testId: "chart-type", popoverClass: "pk-chart-menu" }, panels.chartType),
1720
- entry: (close) => /* @__PURE__ */ React9.createElement(Option, { key: "chartType", inMenu: true, icon: drawnIcon, onSelect: () => {
1777
+ button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "chartType", label: chartTypeText, name: chartTypeText, title: chartTypeText, icon: drawnIcon, text: labels.chartTypes[preset], role: "dialog", testId: "chart-type", popoverClass: "pk-chart-menu" }, panels.chartType),
1778
+ entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "chartType", inMenu: true, icon: drawnIcon, onSelect: () => {
1721
1779
  close();
1722
1780
  setPanel("chartType");
1723
1781
  }, testId: "more-chart-type" }, `${chartTypeText}\u2026`)
1724
1782
  },
1725
1783
  reset: {
1726
1784
  place: "history",
1727
- button: () => /* @__PURE__ */ React9.createElement(TextButton, { key: "reset", icon: "reset", label: labels.reset, onClick: onReset, disabled: !canReset, testId: "reset" }),
1728
- entry: (close) => /* @__PURE__ */ React9.createElement(Option, { key: "reset", inMenu: true, icon: "reset", disabled: !canReset, onSelect: () => {
1785
+ button: () => /* @__PURE__ */ React10.createElement(TextButton, { key: "reset", icon: "reset", label: labels.reset, onClick: onReset, disabled: !canReset, testId: "reset" }),
1786
+ entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "reset", inMenu: true, icon: "reset", disabled: !canReset, onSelect: () => {
1729
1787
  close();
1730
1788
  onReset();
1731
1789
  }, testId: "more-reset" }, labels.reset)
@@ -1733,24 +1791,24 @@ function Toolbar(props) {
1733
1791
  layout: {
1734
1792
  place: "end",
1735
1793
  // a toggle of the zones: the same text, open or folded; aria-pressed says which
1736
- button: () => /* @__PURE__ */ React9.createElement("button", { key: "layout", type: "button", className: "pk-btn pk-pressable", onClick: onLayout, "aria-pressed": !layoutFolded, "aria-controls": zonesId, title: labels.showLayout, "data-testid": "layout" }, /* @__PURE__ */ React9.createElement(Icon, { name: "layout" }), /* @__PURE__ */ React9.createElement("span", { className: "pk-btn-text" }, labels.layout)),
1737
- entry: (close) => /* @__PURE__ */ React9.createElement(Option, { key: "layout", inMenu: true, icon: "layout", checked: !layoutFolded, onSelect: () => {
1794
+ button: () => /* @__PURE__ */ React10.createElement("button", { key: "layout", type: "button", className: "pk-btn pk-pressable", onClick: onLayout, "aria-pressed": !layoutFolded, "aria-controls": zonesId, title: labels.showLayout, "data-testid": "layout" }, /* @__PURE__ */ React10.createElement(Icon, { name: "layout" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-btn-text" }, labels.layout)),
1795
+ entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "layout", inMenu: true, icon: "layout", checked: !layoutFolded, onSelect: () => {
1738
1796
  close();
1739
1797
  onLayout();
1740
1798
  }, testId: "more-layout" }, labels.layout)
1741
1799
  },
1742
1800
  options: {
1743
1801
  place: "end",
1744
- button: () => /* @__PURE__ */ React9.createElement(MenuButton, { key: "options", label: labels.options, icon: "sliders", text: labels.options, role: "dialog", align: "end", testId: "options" }, panels.options),
1745
- entry: (close) => /* @__PURE__ */ React9.createElement(Option, { key: "options", inMenu: true, icon: "sliders", onSelect: () => {
1802
+ button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "options", label: labels.options, icon: "sliders", text: labels.options, role: "dialog", align: "end", testId: "options" }, panels.options),
1803
+ entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "options", inMenu: true, icon: "sliders", onSelect: () => {
1746
1804
  close();
1747
1805
  setPanel("options");
1748
1806
  }, testId: "more-options" }, `${labels.options}\u2026`)
1749
1807
  },
1750
1808
  views: {
1751
1809
  place: "end",
1752
- button: () => /* @__PURE__ */ React9.createElement(MenuButton, { key: "views", label: labels.views, icon: "bookmark", text: labels.views, role: "dialog", align: "end", testId: "views", buttonRef: viewsButton }, panels.views),
1753
- entry: (close) => /* @__PURE__ */ React9.createElement(Option, { key: "views", inMenu: true, icon: "bookmark", onSelect: () => {
1810
+ button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "views", label: labels.views, icon: "bookmark", text: labels.views, role: "dialog", align: "end", testId: "views", buttonRef: viewsButton }, panels.views),
1811
+ entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "views", inMenu: true, icon: "bookmark", onSelect: () => {
1754
1812
  close();
1755
1813
  setPanel("views");
1756
1814
  }, testId: "more-views" }, `${labels.views}\u2026`)
@@ -1758,17 +1816,36 @@ function Toolbar(props) {
1758
1816
  };
1759
1817
  const ORDER = Object.keys(actions);
1760
1818
  const buttons = (place) => ORDER.filter((id) => actions[id].place === place && !hidden.has(id)).map((id) => actions[id].button());
1761
- return /* @__PURE__ */ React9.createElement("div", { className: `pk-toolbar${level >= order.length ? " pk-wrap" : ""}`, role: "toolbar", "aria-label": labels.toolbar, ref: bar, "data-overflow": level }, size === "narrow" ? /* @__PURE__ */ React9.createElement("button", { type: "button", className: "pk-btn", onClick: onShowFields, "data-testid": "show-fields", "data-pk-opener": "fields" }, /* @__PURE__ */ React9.createElement(Icon, { name: "panel" }), /* @__PURE__ */ React9.createElement("span", { className: "pk-btn-text" }, labels.showFields)) : null, /* @__PURE__ */ React9.createElement("div", { className: "pk-segmented", role: "group", "aria-label": labels.view }, /* @__PURE__ */ React9.createElement("button", { type: "button", "aria-pressed": view.display === "table", onClick: () => onDisplay("table"), "data-testid": "show-table" }, /* @__PURE__ */ React9.createElement(Icon, { name: "table" }), /* @__PURE__ */ React9.createElement("span", null, labels.table)), /* @__PURE__ */ React9.createElement("button", { type: "button", "aria-pressed": view.display === "chart", onClick: () => onDisplay("chart"), "data-testid": "show-chart" }, /* @__PURE__ */ React9.createElement(Icon, { name: (
1819
+ const changedMark = (testId) => /* @__PURE__ */ React10.createElement("span", { className: "pk-view-changed", "data-testid": testId }, /* @__PURE__ */ React10.createElement("span", { className: "pk-sr" }, labels.unsavedChanges));
1820
+ const name = loadedView ? /* @__PURE__ */ React10.createElement(
1821
+ "button",
1822
+ {
1823
+ key: "name",
1824
+ type: "button",
1825
+ className: "pk-view-name",
1826
+ "aria-haspopup": "dialog",
1827
+ title: loadedView.changed ? `${loadedView.name} (${labels.unsavedChanges})` : loadedView.name,
1828
+ onClick: () => hidden.has("views") ? setPanel("views") : viewsButton.current?.click(),
1829
+ "data-testid": "view-name"
1830
+ },
1831
+ /* @__PURE__ */ React10.createElement("span", { className: "pk-view-name-text" }, loadedView.name),
1832
+ loadedView.changed ? changedMark("view-changed") : null
1833
+ ) : null;
1834
+ const end = buttons("end");
1835
+ const at = hidden.has("views") ? end.length : end.length - 1;
1836
+ const wrap = level >= order.length;
1837
+ return /* @__PURE__ */ React10.createElement("div", { className: `pk-toolbar${wrap ? " pk-wrap" : ""}`, role: "toolbar", "aria-label": labels.toolbar, ref: bar, "data-overflow": level }, size === "narrow" ? /* @__PURE__ */ React10.createElement("button", { type: "button", className: "pk-btn", onClick: onShowFields, "data-testid": "show-fields", "data-pk-opener": "fields" }, /* @__PURE__ */ React10.createElement(Icon, { name: "panel" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-btn-text" }, labels.showFields)) : null, /* @__PURE__ */ React10.createElement("div", { className: "pk-segmented", role: "group", "aria-label": labels.view }, /* @__PURE__ */ React10.createElement("button", { type: "button", "aria-pressed": view.display === "table", onClick: () => onDisplay("table"), "data-testid": "show-table" }, /* @__PURE__ */ React10.createElement(Icon, { name: "table" }), /* @__PURE__ */ React10.createElement("span", null, labels.table)), /* @__PURE__ */ React10.createElement("button", { type: "button", "aria-pressed": view.display === "chart", onClick: () => onDisplay("chart"), "data-testid": "show-chart" }, /* @__PURE__ */ React10.createElement(Icon, { name: (
1762
1838
  /** @type {any} */
1763
1839
  drawnIcon
1764
- ) }), /* @__PURE__ */ React9.createElement("span", null, labels.chart))), buttons("chart"), /* @__PURE__ */ React9.createElement("span", { className: "pk-sep", "aria-hidden": "true" }), /* @__PURE__ */ React9.createElement("span", { className: "pk-toolbar-pair" }, /* @__PURE__ */ React9.createElement(TextButton, { icon: "undo", label: labels.undo, onClick: onUndo, disabled: !canUndo, testId: "undo", shortcut: `${mod}Z` }), /* @__PURE__ */ React9.createElement(TextButton, { icon: "redo", label: labels.redo, onClick: onRedo, disabled: !canRedo, testId: "redo", shortcut: `${mod}\u21E7Z` })), buttons("history"), /* @__PURE__ */ React9.createElement("span", { className: "pk-grow" }), buttons("end"), /* @__PURE__ */ React9.createElement(MenuButton, { label: labels.exportLabel, icon: "download", text: labels.exportLabel, role: "dialog", align: "end", testId: "export" }, (close) => /* @__PURE__ */ React9.createElement(MenuPanel, { name: "ExportPanel", loadingText: labels.loadingMenu, props: { labels, onExport, chartReady, display: view.display, prepare: props.prepareExport, close } })), level > 0 ? /* @__PURE__ */ React9.createElement(MenuButton, { label: labels.more, icon: "more", text: labels.more, align: "end", testId: "more", buttonRef: more }, (close) => ORDER.filter((id) => hidden.has(id)).map((id) => actions[id].entry(close))) : null, panel ? /* @__PURE__ */ React9.createElement(Popover, { open: true, anchor: more, onClose: closePanel, label: panel === "chartType" ? chartTypeText : panel === "views" ? labels.views : labels.options, role: "dialog", align: "end", className: panel === "chartType" ? "pk-chart-menu" : void 0 }, panels[panel](closePanel)) : null);
1840
+ ) }), /* @__PURE__ */ React10.createElement("span", null, labels.chart))), buttons("chart"), /* @__PURE__ */ React10.createElement("span", { className: "pk-sep", "aria-hidden": "true" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-toolbar-pair" }, /* @__PURE__ */ React10.createElement(TextButton, { icon: "undo", label: labels.undo, onClick: onUndo, disabled: !canUndo, testId: "undo", shortcut: `${mod}Z` }), /* @__PURE__ */ React10.createElement(TextButton, { icon: "redo", label: labels.redo, onClick: onRedo, disabled: !canRedo, testId: "redo", shortcut: `${mod}\u21E7Z` })), buttons("history"), /* @__PURE__ */ React10.createElement("span", { className: "pk-grow" }), end.slice(0, at), wrap ? null : name, end.slice(at), /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.exportLabel, icon: "download", text: labels.exportLabel, role: "dialog", align: "end", testId: "export" }, (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ExportPanel", loadingText: labels.loadingMenu, props: { labels, onExport, chartReady, display: view.display, empty, prepare: props.prepareExport, close } })), level > 0 ? /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.more, icon: "more", text: labels.more, align: "end", testId: "more", buttonRef: more, mark: hidden.has("views") && loadedView?.changed ? changedMark("more-changed") : null }, (close) => ORDER.filter((id) => hidden.has(id)).map((id) => actions[id].entry(close))) : null, wrap ? name : null, panel ? /* @__PURE__ */ React10.createElement(Popover, { open: true, anchor: more, onClose: closePanel, label: panel === "chartType" ? chartTypeText : panel === "views" ? labels.views : labels.options, role: "dialog", align: "end", className: panel === "chartType" ? "pk-chart-menu" : void 0 }, panels[panel](closePanel)) : null);
1765
1841
  }
1766
1842
 
1767
1843
  // src/use-export.js
1768
1844
  function useExport(context) {
1769
1845
  return async (kind) => {
1770
1846
  try {
1771
- const menus = menusNow() ?? await loadMenus();
1847
+ const lang = context.labels.lang;
1848
+ const menus = menusNow(lang) ?? await loadMenus(lang);
1772
1849
  await menus.runExport(kind, context);
1773
1850
  } catch (e) {
1774
1851
  context.announce(fill(context.labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
@@ -1823,13 +1900,14 @@ function useResolvedTheme(wanted, ref) {
1823
1900
  }
1824
1901
 
1825
1902
  // src/use-view-history.js
1826
- import { useCallback as useCallback6, useMemo as useMemo5, useState as useState8 } from "react";
1827
- import { emptyView, normalize as normalize2 } from "pivotkit-core";
1903
+ import { useCallback as useCallback6, useMemo as useMemo6, useState as useState9 } from "react";
1904
+ import { emptyView, normalize } from "pivotkit-core";
1828
1905
 
1829
1906
  // src/view-history.js
1907
+ var tagFor = (tag, sourceId) => tag && tag.sourceId === sourceId ? tag : null;
1830
1908
  var HISTORY_LIMIT = 100;
1831
- function createState(schema, start, current = start) {
1832
- return { schema, start, present: current, past: [], future: [] };
1909
+ function createState(schema, start, current = start, tag = null) {
1910
+ return { schema, start, present: current, past: [], future: [], tag };
1833
1911
  }
1834
1912
  function settle(state, at) {
1835
1913
  let s = state.schema === at.schema ? state : createState(at.schema, at.start, at.shown);
@@ -1838,12 +1916,12 @@ function settle(state, at) {
1838
1916
  }
1839
1917
  return s;
1840
1918
  }
1841
- function record(state, view, note) {
1919
+ function record(state, view, note, tag = state.tag) {
1842
1920
  if (view === state.present) {
1843
- return state;
1921
+ return tag === state.tag ? state : { ...state, tag };
1844
1922
  }
1845
- const past = [...state.past, { view: state.present, note }].slice(-HISTORY_LIMIT);
1846
- return { ...state, present: view, past, future: [] };
1923
+ const past = [...state.past, { view: state.present, note, tag: state.tag }].slice(-HISTORY_LIMIT);
1924
+ return { ...state, present: view, past, future: [], tag };
1847
1925
  }
1848
1926
  function undo(state) {
1849
1927
  const last = state.past[state.past.length - 1];
@@ -1851,7 +1929,7 @@ function undo(state) {
1851
1929
  return { state, note: null };
1852
1930
  }
1853
1931
  return {
1854
- state: { ...state, present: last.view, past: state.past.slice(0, -1), future: [...state.future, { view: state.present, note: last.note }] },
1932
+ state: { ...state, present: last.view, tag: last.tag, past: state.past.slice(0, -1), future: [...state.future, { view: state.present, note: last.note, tag: state.tag }] },
1855
1933
  note: last.note
1856
1934
  };
1857
1935
  }
@@ -1861,12 +1939,12 @@ function redo(state) {
1861
1939
  return { state, note: null };
1862
1940
  }
1863
1941
  return {
1864
- state: { ...state, present: next.view, future: state.future.slice(0, -1), past: [...state.past, { view: state.present, note: next.note }] },
1942
+ state: { ...state, present: next.view, tag: next.tag, future: state.future.slice(0, -1), past: [...state.past, { view: state.present, note: next.note, tag: state.tag }] },
1865
1943
  note: next.note
1866
1944
  };
1867
1945
  }
1868
1946
  function reset(state, note) {
1869
- return record(state, state.start, note);
1947
+ return record(state, state.start, note, null);
1870
1948
  }
1871
1949
 
1872
1950
  // src/use-view-history.js
@@ -1875,30 +1953,30 @@ function schemaKeyOf(encoded) {
1875
1953
  }
1876
1954
  function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outsideNote, orderOf }) {
1877
1955
  const controlled = view !== void 0;
1878
- const schema = useMemo5(() => schemaKeyOf(encoded), [encoded]);
1956
+ const schema = useMemo6(() => schemaKeyOf(encoded), [encoded]);
1879
1957
  const json = useCallback6(
1880
1958
  (v) => {
1881
- const normalized = normalize2(v ?? emptyView(), encoded, { limits }).view;
1959
+ const normalized = normalize(v ?? emptyView(), encoded, { limits }).view;
1882
1960
  const ordered = orderOf ? withHostOrders(normalized, orderOf) : normalized;
1883
- return JSON.stringify(ordered === normalized ? normalized : normalize2(ordered, encoded, { limits }).view);
1961
+ return JSON.stringify(ordered === normalized ? normalized : normalize(ordered, encoded, { limits }).view);
1884
1962
  },
1885
1963
  [encoded, limits, orderOf]
1886
1964
  );
1887
- const [initial] = useState8(() => (controlled ? view : defaultView) ?? null);
1888
- const start = useMemo5(() => json(initial), [json, initial]);
1889
- const [state, setState] = useState8(() => createState(schema, start));
1965
+ const [initial] = useState9(() => (controlled ? view : defaultView) ?? null);
1966
+ const start = useMemo6(() => json(initial), [json, initial]);
1967
+ const [state, setState] = useState9(() => createState(schema, start));
1890
1968
  const viewKey = controlled ? JSON.stringify(view) : null;
1891
- const shown = useMemo5(() => {
1969
+ const shown = useMemo6(() => {
1892
1970
  if (viewKey !== null) {
1893
1971
  return json(JSON.parse(viewKey));
1894
1972
  }
1895
1973
  return state.schema === schema ? state.present : json(JSON.parse(state.present));
1896
1974
  }, [viewKey, json, state, schema]);
1897
- const current = useMemo5(() => (
1975
+ const current = useMemo6(() => (
1898
1976
  /** @type {import("pivotkit-core").View} */
1899
1977
  JSON.parse(shown)
1900
1978
  ), [shown]);
1901
- const live = useMemo5(() => settle(state, { schema, start, shown, outside: outsideNote }), [state, schema, start, shown, outsideNote]);
1979
+ const live = useMemo6(() => settle(state, { schema, start, shown, outside: outsideNote }), [state, schema, start, shown, outsideNote]);
1902
1980
  const apply = useCallback6(
1903
1981
  (next) => {
1904
1982
  setState(next);
@@ -1907,9 +1985,12 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
1907
1985
  [onViewChange]
1908
1986
  );
1909
1987
  const commit = useCallback6(
1910
- (next, note) => {
1911
- const s = record(live, json(next), note);
1912
- if (s === live) {
1988
+ (next, note, tag) => {
1989
+ const s = record(live, json(next), note, tag === void 0 ? live.tag : tag);
1990
+ if (s.present === live.present) {
1991
+ if (s !== live) {
1992
+ setState(s);
1993
+ }
1913
1994
  return false;
1914
1995
  }
1915
1996
  apply(s);
@@ -1917,6 +1998,7 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
1917
1998
  },
1918
1999
  [live, json, apply]
1919
2000
  );
2001
+ const setTag = useCallback6((tag) => setState((s) => ({ ...s, tag })), []);
1920
2002
  const undo2 = useCallback6(() => {
1921
2003
  const { state: s, note } = undo(live);
1922
2004
  if (note !== null) {
@@ -1934,34 +2016,36 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
1934
2016
  const reset2 = useCallback6(
1935
2017
  (note) => {
1936
2018
  const s = reset(live, note);
1937
- if (s !== live) {
2019
+ if (s.present !== live.present) {
1938
2020
  apply(s);
2021
+ } else if (s !== live) {
2022
+ setState(s);
1939
2023
  }
1940
2024
  },
1941
2025
  [live, apply]
1942
2026
  );
1943
- const restore = useCallback6((next) => apply(createState(schema, start, json(next))), [schema, start, json, apply]);
2027
+ const restore = useCallback6((next, tag = null) => apply(createState(schema, start, json(next), tag)), [schema, start, json, apply]);
1944
2028
  const canUndo = live.past.length > 0;
1945
2029
  const canRedo = live.future.length > 0;
1946
2030
  const canReset = live.present !== live.start;
1947
- return useMemo5(
1948
- () => ({ view: current, viewKey: shown, commit, undo: undo2, redo: redo2, reset: reset2, restore, canUndo, canRedo, canReset }),
1949
- [current, shown, commit, undo2, redo2, reset2, restore, canUndo, canRedo, canReset]
2031
+ return useMemo6(
2032
+ () => ({ view: current, viewKey: shown, tag: live.tag, setTag, commit, undo: undo2, redo: redo2, reset: reset2, restore, keyOf: json, canUndo, canRedo, canReset }),
2033
+ [current, shown, live.tag, setTag, commit, undo2, redo2, reset2, restore, json, canUndo, canRedo, canReset]
1950
2034
  );
1951
2035
  }
1952
2036
 
1953
2037
  // src/use-big-result.js
1954
- import { useCallback as useCallback7, useEffect as useEffect8, useRef as useRef8, useState as useState9, useSyncExternalStore as useSyncExternalStore2 } from "react";
2038
+ import { useCallback as useCallback7, useEffect as useEffect9, useRef as useRef9, useState as useState10, useSyncExternalStore as useSyncExternalStore2 } from "react";
1955
2039
  function fullScreenSupported() {
1956
2040
  return typeof document !== "undefined" && Boolean(document.fullscreenEnabled) && typeof HTMLElement !== "undefined" && typeof HTMLElement.prototype.requestFullscreen === "function";
1957
2041
  }
1958
2042
  var never = () => () => {
1959
2043
  };
1960
2044
  function useBigResult(root) {
1961
- const [enlarged, setEnlarged] = useState9(false);
1962
- const [full, setFull] = useState9(false);
2045
+ const [enlarged, setEnlarged] = useState10(false);
2046
+ const [full, setFull] = useState10(false);
1963
2047
  const fullOk = useSyncExternalStore2(never, fullScreenSupported, () => false);
1964
- useEffect8(() => {
2048
+ useEffect9(() => {
1965
2049
  const el = root.current;
1966
2050
  if (!el) {
1967
2051
  return void 0;
@@ -1992,7 +2076,7 @@ function useBigResult(root) {
1992
2076
  return { enlarged, setEnlarged, toggleEnlarged, full, fullOk, toggleFull };
1993
2077
  }
1994
2078
  function useFitHeight(root, main, grow) {
1995
- const fit = useRef8({ need: 0, open: 0, grow });
2079
+ const fit = useRef9({ need: 0, open: 0, grow });
1996
2080
  useIsoLayoutEffect(() => {
1997
2081
  fit.current.grow = grow;
1998
2082
  measureFit(root.current, main.current, fit);
@@ -2035,12 +2119,9 @@ function measureFit(el, m, fit) {
2035
2119
  }
2036
2120
  }
2037
2121
 
2038
- // src/version.js
2039
- var VERSION = true ? "0.1.0" : "0.0.0-source";
2040
-
2041
2122
  // src/zones.jsx
2042
- import React10, { useCallback as useCallback8, useEffect as useEffect9, useMemo as useMemo6, useRef as useRef9, useState as useState10 } from "react";
2043
- import { fieldItems, fieldLabel as fieldLabel2 } from "pivotkit-core";
2123
+ import React11, { useCallback as useCallback8, useEffect as useEffect10, useMemo as useMemo7, useRef as useRef10, useState as useState11 } from "react";
2124
+ import { fieldItems, fieldLabel as fieldLabel4 } from "pivotkit-core";
2044
2125
  function fieldState(view, field, encoded, locale) {
2045
2126
  const items = filtersOf(view, field, ["include", "exclude"]).filter((f) => f.type === "include" || f.items.length > 0);
2046
2127
  let summary = null;
@@ -2073,9 +2154,7 @@ function stateWords(state, view, labels, locale) {
2073
2154
  words.push(valueConditionText(view, state.condition, labels, locale));
2074
2155
  }
2075
2156
  if (state.sort) {
2076
- const desc = state.sort.order === "desc";
2077
- const order = state.sort.by === "value" ? fill(desc ? labels.sortValueDesc : labels.sortValueAsc, { value: refLabel(view, state.sort.value, labels) }) : state.sort.by === "custom" ? desc ? labels.sortCustomDesc : labels.sortCustom : desc ? labels.sortLabelDesc : labels.sortLabelAsc;
2078
- words.push(fill(labels.stateSorted, { order }));
2157
+ words.push(fill(labels.stateSorted, { order: sortText(view, state.sort, labels) }));
2079
2158
  }
2080
2159
  return words.join(", ");
2081
2160
  }
@@ -2084,35 +2163,35 @@ function Badges({ state, view, labels, locale }) {
2084
2163
  if (state.summary) {
2085
2164
  const text = fill(labels.filterSummary, { shown: state.summary.shown.toLocaleString(locale), total: state.summary.total.toLocaleString(locale) });
2086
2165
  parts.push(
2087
- /* @__PURE__ */ React10.createElement("span", { key: "filter", className: "pk-chip-badge pk-badge-text" }, /* @__PURE__ */ React10.createElement(Icon, { name: "filter", size: 12 }), text)
2166
+ /* @__PURE__ */ React11.createElement("span", { key: "filter", className: "pk-chip-badge pk-badge-text" }, /* @__PURE__ */ React11.createElement(Icon, { name: "filter", size: 12 }), text)
2088
2167
  );
2089
2168
  } else if (state.other) {
2090
- parts.push(/* @__PURE__ */ React10.createElement(Icon, { key: "filter", name: "filter", size: 12, className: "pk-chip-badge" }));
2169
+ parts.push(/* @__PURE__ */ React11.createElement(Icon, { key: "filter", name: "filter", size: 12, className: "pk-chip-badge" }));
2091
2170
  }
2092
2171
  if (state.top) {
2093
2172
  const text = fill(state.top.bottom ? labels.bottomBadge : labels.topBadge, { count: state.top.count.toLocaleString(locale) });
2094
2173
  parts.push(
2095
- /* @__PURE__ */ React10.createElement("span", { key: "top", className: "pk-chip-badge pk-badge-text", "data-testid": "top-badge" }, /* @__PURE__ */ React10.createElement(Icon, { name: "top", size: 12 }), text)
2174
+ /* @__PURE__ */ React11.createElement("span", { key: "top", className: "pk-chip-badge pk-badge-text", "data-testid": "top-badge" }, /* @__PURE__ */ React11.createElement(Icon, { name: "top", size: 12 }), text)
2096
2175
  );
2097
2176
  }
2098
2177
  if (state.condition) {
2099
2178
  const text = valueConditionText(view, state.condition, labels, locale);
2100
2179
  parts.push(
2101
- /* @__PURE__ */ React10.createElement("span", { key: "condition", className: "pk-chip-badge pk-badge-text pk-badge-condition", "data-testid": "condition-badge", title: text }, /* @__PURE__ */ React10.createElement(Icon, { name: "filter", size: 12 }), /* @__PURE__ */ React10.createElement("span", { className: "pk-badge-cut" }, text))
2180
+ /* @__PURE__ */ React11.createElement("span", { key: "condition", className: "pk-chip-badge pk-badge-text pk-badge-condition", "data-testid": "condition-badge", title: text }, /* @__PURE__ */ React11.createElement(Icon, { name: "filter", size: 12 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-badge-cut" }, text))
2102
2181
  );
2103
2182
  }
2104
2183
  if (state.sort) {
2105
2184
  const desc = state.sort.order === "desc";
2106
- parts.push(/* @__PURE__ */ React10.createElement(Icon, { key: "sort", name: desc ? "sortDesc" : "sortAsc", size: 12, className: "pk-chip-badge" }));
2185
+ parts.push(/* @__PURE__ */ React11.createElement(Icon, { key: "sort", name: desc ? "sortDesc" : "sortAsc", size: 12, className: "pk-chip-badge" }));
2107
2186
  }
2108
2187
  if (!parts.length) {
2109
2188
  return null;
2110
2189
  }
2111
- return /* @__PURE__ */ React10.createElement("span", { className: "pk-badges-inline", "aria-hidden": "true" }, parts);
2190
+ return /* @__PURE__ */ React11.createElement("span", { className: "pk-badges-inline", "aria-hidden": "true" }, parts);
2112
2191
  }
2113
2192
  function Chip({ id, zone, index, count, field, text, typeName, view, types, labels, commit, openFilter, onRemove, state, locale, defaultsOf, rangeOf, info, showInfo }) {
2114
2193
  const { setNodeRef, isDragging, style, itemProps, handleProps } = useChip(id, { kind: "chip", zone, index, count, field, label: text, type: typeName });
2115
- const chipRef = useRef9(
2194
+ const chipRef = useRef10(
2116
2195
  /** @type {HTMLElement | null} */
2117
2196
  null
2118
2197
  );
@@ -2120,18 +2199,18 @@ function Chip({ id, zone, index, count, field, text, typeName, view, types, labe
2120
2199
  chipRef.current = el;
2121
2200
  setNodeRef(el);
2122
2201
  };
2123
- const badges = state ? /* @__PURE__ */ React10.createElement(Badges, { state, view, labels, locale }) : null;
2202
+ const badges = state ? /* @__PURE__ */ React11.createElement(Badges, { state, view, labels, locale }) : null;
2124
2203
  const words = stateWords(state, view, labels, locale);
2125
2204
  const name = words ? `${text}, ${words}` : void 0;
2126
2205
  const remove = () => onRemove(zone, index, text);
2127
- return /* @__PURE__ */ React10.createElement("li", { ref, style, className: `pk-chip pk-chip-${zone}${isDragging ? " pk-dragging" : ""}`, ...itemProps, "data-chip": text }, /* @__PURE__ */ React10.createElement("span", { className: "pk-handle", ...handleProps, "aria-label": fill(labels.dragHandle, { field: text }) }, /* @__PURE__ */ React10.createElement(Icon, { name: "grip", size: 16 })), /* @__PURE__ */ React10.createElement("span", { className: `pk-type pk-type-${typeName}`, "aria-hidden": "true" }, /* @__PURE__ */ React10.createElement(Icon, { name: (
2206
+ return /* @__PURE__ */ React11.createElement("li", { ref, style, className: `pk-chip pk-chip-${zone}${isDragging ? " pk-dragging" : ""}`, ...itemProps, "data-chip": text }, /* @__PURE__ */ React11.createElement("span", { className: "pk-handle", ...handleProps, "aria-label": fill(labels.dragHandle, { field: text }) }, /* @__PURE__ */ React11.createElement(Icon, { name: "grip", size: 16 })), /* @__PURE__ */ React11.createElement("span", { className: `pk-type pk-type-${typeName}`, "aria-hidden": "true" }, /* @__PURE__ */ React11.createElement(Icon, { name: (
2128
2207
  /** @type {any} */
2129
2208
  TYPE_ICON[typeName] ?? "text"
2130
- ), size: 13 })), zone === "filters" ? /* @__PURE__ */ React10.createElement("button", { type: "button", className: "pk-chip-label", onClick: (e) => openFilter(field, e.currentTarget.closest(".pk-chip")), title: fill(labels.filterTitle, { field: text }), "aria-label": name }, /* @__PURE__ */ React10.createElement("span", { className: "pk-btn-text" }, /* @__PURE__ */ React10.createElement("span", { className: "pk-chip-name" }, text), badges)) : /* @__PURE__ */ React10.createElement(
2209
+ ), size: 13 })), zone === "filters" ? /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-chip-label", onClick: (e) => openFilter(field, e.currentTarget.closest(".pk-chip")), title: fill(labels.filterTitle, { field: text }), "aria-label": name }, /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, /* @__PURE__ */ React11.createElement("span", { className: "pk-chip-name" }, text), badges)) : /* @__PURE__ */ React11.createElement(
2131
2210
  MenuButton,
2132
2211
  {
2133
2212
  label: fill(labels.fieldMenu, { field: text }),
2134
- text: /* @__PURE__ */ React10.createElement(React10.Fragment, null, /* @__PURE__ */ React10.createElement("span", { className: "pk-chip-name" }, text), badges),
2213
+ text: /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement("span", { className: "pk-chip-name" }, text), badges),
2135
2214
  className: "pk-chip-label",
2136
2215
  name,
2137
2216
  role: "dialog",
@@ -2139,38 +2218,38 @@ function Chip({ id, zone, index, count, field, text, typeName, view, types, labe
2139
2218
  fill: true,
2140
2219
  testId: `chip-menu-${text}`
2141
2220
  },
2142
- (close) => zone === "values" ? /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ValueMenu", loadingText: labels.loadingMenu, props: { view, index, types, labels, commit, close, onRemove: remove, defaultsOf, info } }) : /* @__PURE__ */ React10.createElement(MenuPanel, { name: "AxisMenu", loadingText: labels.loadingMenu, props: { view, zone, index, field, types, labels, commit, close, openFilter, chipRef, onRemove: remove, defaultsOf, rangeOf, locale, info, state } })
2143
- ), info && showInfo ? /* @__PURE__ */ React10.createElement(InfoButton, { info, name: fieldLabel2(sourceOf(view, field), labels.core), labels, className: "pk-chip-info" }) : null, /* @__PURE__ */ React10.createElement("button", { type: "button", className: "pk-chip-x", onClick: remove, "aria-label": fill(labels.removeField, { field: text }), title: fill(labels.removeField, { field: text }) }, /* @__PURE__ */ React10.createElement(Icon, { name: "x", size: 14 })));
2221
+ (close) => zone === "values" ? /* @__PURE__ */ React11.createElement(MenuPanel, { name: "ValueMenu", loadingText: labels.loadingMenu, props: { view, index, types, labels, commit, close, onRemove: remove, defaultsOf, info } }) : /* @__PURE__ */ React11.createElement(MenuPanel, { name: "AxisMenu", loadingText: labels.loadingMenu, props: { view, zone, index, field, types, labels, commit, close, openFilter, chipRef, onRemove: remove, defaultsOf, rangeOf, locale, info, state } })
2222
+ ), info && showInfo ? /* @__PURE__ */ React11.createElement(InfoButton, { info, name: fieldLabel4(sourceOf(view, field), labels.core), labels, className: "pk-chip-info" }) : null, /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-chip-x", onClick: remove, "aria-label": fill(labels.removeField, { field: text }), title: fill(labels.removeField, { field: text }) }, /* @__PURE__ */ React11.createElement(Icon, { name: "x", size: 14 })));
2144
2223
  }
2145
- function Zone({ zone, entries: entries2, labels, children, action, explain }) {
2146
- const count = entries2.length;
2224
+ function Zone({ zone, entries, labels, children, action, explain }) {
2225
+ const count = entries.length;
2147
2226
  const { setNodeRef, isOver } = useDropTarget(`zone:${zone}`, { kind: "zone", zone, count });
2148
2227
  const active = useActiveDrag();
2149
2228
  const dragging = Boolean(active);
2150
- const [flash, setFlash] = useState10(false);
2151
- const [prev, setPrev] = useState10(count);
2229
+ const [flash, setFlash] = useState11(false);
2230
+ const [prev, setPrev] = useState11(count);
2152
2231
  if (count !== prev) {
2153
2232
  setPrev(count);
2154
2233
  if (count > prev) {
2155
2234
  setFlash(true);
2156
2235
  }
2157
2236
  }
2158
- useEffect9(() => {
2237
+ useEffect10(() => {
2159
2238
  if (!flash) {
2160
2239
  return void 0;
2161
2240
  }
2162
2241
  const t = setTimeout(() => setFlash(false), 600);
2163
2242
  return () => clearTimeout(t);
2164
2243
  }, [flash]);
2165
- return /* @__PURE__ */ React10.createElement("section", { ref: setNodeRef, tabIndex: -1, className: `pk-zone pk-zone-${zone}${isOver ? " pk-over" : ""}${dragging ? " pk-dropping" : ""}${flash ? " pk-flash" : ""}`, "aria-label": labels.zones[zone], "data-zone": zone }, /* @__PURE__ */ React10.createElement("div", { className: "pk-zone-head" }, /* @__PURE__ */ React10.createElement("h3", { className: "pk-zone-title" }, /* @__PURE__ */ React10.createElement(Icon, { name: (
2244
+ return /* @__PURE__ */ React11.createElement("section", { ref: setNodeRef, tabIndex: -1, className: `pk-zone pk-zone-${zone}${isOver ? " pk-over" : ""}${dragging ? " pk-dropping" : ""}${flash ? " pk-flash" : ""}`, "aria-label": labels.zones[zone], "data-zone": zone }, /* @__PURE__ */ React11.createElement("div", { className: "pk-zone-head" }, /* @__PURE__ */ React11.createElement("h3", { className: "pk-zone-title" }, /* @__PURE__ */ React11.createElement(Icon, { name: (
2166
2245
  /** @type {any} */
2167
2246
  ZONE_ICON[zone]
2168
- ), size: 14 }), labels.zones[zone]), explain ? /* @__PURE__ */ React10.createElement(InfoButton, { info: { description: labels.zoneInfo[zone] }, name: labels.zones[zone], labels, className: "pk-zone-info", testId: `zone-info-${zone}` }) : null, /* @__PURE__ */ React10.createElement("span", { className: "pk-grow" }), action), /* @__PURE__ */ React10.createElement(ChipList, { ids: entries2.map((e) => e.id) }, /* @__PURE__ */ React10.createElement("ul", { className: "pk-chips" }, children, count === 0 ? /* @__PURE__ */ React10.createElement("li", { className: "pk-zone-hint" }, labels.zoneHints[zone]) : null)));
2247
+ ), size: 14 }), labels.zones[zone]), explain ? /* @__PURE__ */ React11.createElement(InfoButton, { info: { description: labels.zoneInfo[zone] }, name: labels.zones[zone], labels, className: "pk-zone-info", testId: `zone-info-${zone}` }) : null, /* @__PURE__ */ React11.createElement("span", { className: "pk-grow" }), action), /* @__PURE__ */ React11.createElement(ChipList, { ids: entries.map((e) => e.id) }, /* @__PURE__ */ React11.createElement("ul", { className: "pk-chips" }, children, count === 0 ? /* @__PURE__ */ React11.createElement("li", { className: "pk-zone-hint" }, labels.zoneHints[zone]) : null)));
2169
2248
  }
2170
2249
  function zoneEntries(view, types, labels) {
2171
2250
  const typeOf = (f) => types.get(String(sourceOf(view, f)).toLowerCase()) ?? "string";
2172
2251
  const seen = /* @__PURE__ */ new Map();
2173
- const text = (f) => fieldLabel2(f, labels.core);
2252
+ const text = (f) => fieldLabel4(f, labels.core);
2174
2253
  const axis = (zone) => view[zone].map((f, i) => ({ id: `chip:${zone}:${f}`, field: f, text: text(f), type: typeOf(f), index: i }));
2175
2254
  return {
2176
2255
  filters: filterZoneFields(view).map((f, i) => ({ id: `chip:filters:${f}`, field: f, text: text(f), type: typeOf(f), index: i })),
@@ -2183,35 +2262,35 @@ function zoneEntries(view, types, labels) {
2183
2262
  })
2184
2263
  };
2185
2264
  }
2186
- function ZoneSummary({ entries: entries2, labels, id, onShow, buttonRef }) {
2187
- const parts = layoutSummary(entries2, labels);
2265
+ function ZoneSummary({ entries, labels, id, onShow, buttonRef }) {
2266
+ const parts = layoutSummary(entries, labels);
2188
2267
  const text = parts.length ? parts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
2189
- return /* @__PURE__ */ React10.createElement("button", { ref: buttonRef, type: "button", id, className: "pk-zones-summary", "aria-expanded": "false", "aria-label": `${labels.showLayout}: ${text}`, title: labels.showLayout, onClick: onShow, "data-testid": "layout-summary" }, /* @__PURE__ */ React10.createElement(Icon, { name: "chevronRight", size: 16 }), /* @__PURE__ */ React10.createElement("span", { className: "pk-zones-summary-text" }, parts.length ? parts.map((p, i) => /* @__PURE__ */ React10.createElement(React10.Fragment, { key: p.zone }, i ? /* @__PURE__ */ React10.createElement("span", { "aria-hidden": "true" }, " \xB7 ") : null, /* @__PURE__ */ React10.createElement("span", { className: "pk-zones-summary-zone" }, p.title, ":"), " ", p.fields)) : labels.layoutEmpty));
2268
+ return /* @__PURE__ */ React11.createElement("button", { ref: buttonRef, type: "button", id, className: "pk-zones-summary", "aria-expanded": "false", "aria-label": `${labels.showLayout}: ${text}`, title: labels.showLayout, onClick: onShow, "data-testid": "layout-summary" }, /* @__PURE__ */ React11.createElement(Icon, { name: "chevronRight", size: 16 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-zones-summary-text" }, parts.length ? parts.map((p, i) => /* @__PURE__ */ React11.createElement(React11.Fragment, { key: p.zone }, i ? /* @__PURE__ */ React11.createElement("span", { "aria-hidden": "true" }, " \xB7 ") : null, /* @__PURE__ */ React11.createElement("span", { className: "pk-zones-summary-zone" }, p.title, ":"), " ", p.fields)) : labels.layoutEmpty));
2190
2269
  }
2191
2270
  function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwap, id, folded, onShow, defaultsOf, infoOf, explain = false, showInfo = true }) {
2192
- const entries2 = useMemo6(() => zoneEntries(view, types, labels), [view, types, labels]);
2271
+ const entries = useMemo7(() => zoneEntries(view, types, labels), [view, types, labels]);
2193
2272
  const dragging = Boolean(useActiveDrag());
2194
- const showing = useRef9(false);
2195
- const focusInside = useRef9(false);
2196
- const summary = useRef9(
2273
+ const showing = useRef10(false);
2274
+ const focusInside = useRef10(false);
2275
+ const summary = useRef10(
2197
2276
  /** @type {HTMLButtonElement | null} */
2198
2277
  null
2199
2278
  );
2200
- const states = useMemo6(() => {
2279
+ const states = useMemo7(() => {
2201
2280
  const map = /* @__PURE__ */ new Map();
2202
2281
  for (const zone of ["filters", "cols", "rows"]) {
2203
- for (const e of entries2[zone]) {
2282
+ for (const e of entries[zone]) {
2204
2283
  map.set(e.field, fieldState(view, e.field, encoded, locale));
2205
2284
  }
2206
2285
  }
2207
2286
  return map;
2208
- }, [entries2, view, encoded, locale]);
2287
+ }, [entries, view, encoded, locale]);
2209
2288
  const rangeOf = useCallback8((field) => numberRange(encoded, field), [encoded]);
2210
- const root = useRef9(
2289
+ const root = useRef10(
2211
2290
  /** @type {HTMLDivElement | null} */
2212
2291
  null
2213
2292
  );
2214
- const focusAfter = useRef9(
2293
+ const focusAfter = useRef10(
2215
2294
  /** @type {{ zone: string, index: number } | null} */
2216
2295
  null
2217
2296
  );
@@ -2219,7 +2298,7 @@ function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwa
2219
2298
  focusAfter.current = { zone, index };
2220
2299
  commit(removeAt(view, zone, index), { step: "removed", field: text, removed: true });
2221
2300
  };
2222
- useEffect9(() => {
2301
+ useEffect10(() => {
2223
2302
  const at = focusAfter.current;
2224
2303
  if (!at || !root.current) {
2225
2304
  return;
@@ -2233,7 +2312,7 @@ function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwa
2233
2312
  );
2234
2313
  target?.focus({ preventScroll: true });
2235
2314
  });
2236
- useEffect9(() => {
2315
+ useEffect10(() => {
2237
2316
  if (showing.current && !folded) {
2238
2317
  showing.current = false;
2239
2318
  root.current?.querySelector("[data-zone]")?.focus({ preventScroll: true });
@@ -2244,10 +2323,10 @@ function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwa
2244
2323
  }
2245
2324
  }, [folded]);
2246
2325
  if (folded && !dragging) {
2247
- return /* @__PURE__ */ React10.createElement(
2326
+ return /* @__PURE__ */ React11.createElement(
2248
2327
  ZoneSummary,
2249
2328
  {
2250
- entries: entries2,
2329
+ entries,
2251
2330
  labels,
2252
2331
  id,
2253
2332
  buttonRef: summary,
@@ -2258,7 +2337,7 @@ function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwa
2258
2337
  }
2259
2338
  );
2260
2339
  }
2261
- return /* @__PURE__ */ React10.createElement(
2340
+ return /* @__PURE__ */ React11.createElement(
2262
2341
  "div",
2263
2342
  {
2264
2343
  className: "pk-zones",
@@ -2276,27 +2355,27 @@ function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwa
2276
2355
  }
2277
2356
  }
2278
2357
  },
2279
- ZONES.map((zone) => /* @__PURE__ */ React10.createElement(
2358
+ ZONES.map((zone) => /* @__PURE__ */ React11.createElement(
2280
2359
  Zone,
2281
2360
  {
2282
2361
  key: zone,
2283
2362
  zone,
2284
- entries: entries2[zone],
2363
+ entries: entries[zone],
2285
2364
  labels,
2286
2365
  explain,
2287
2366
  action: zone === "cols" ? (
2288
2367
  // the text goes when the zone is too narrow (styles.css): the title keeps it as a tooltip
2289
- /* @__PURE__ */ React10.createElement("button", { type: "button", className: "pk-link pk-swap", onClick: onSwap, disabled: view.rows.length + view.cols.length === 0, "data-testid": "swap", title: labels.swap }, /* @__PURE__ */ React10.createElement(Icon, { name: "swap", size: 14 }), /* @__PURE__ */ React10.createElement("span", { className: "pk-btn-text" }, labels.swap))
2368
+ /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-link pk-swap", onClick: onSwap, disabled: view.rows.length + view.cols.length === 0, "data-testid": "swap", title: labels.swap }, /* @__PURE__ */ React11.createElement(Icon, { name: "swap", size: 14 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, labels.swap))
2290
2369
  ) : null
2291
2370
  },
2292
- entries2[zone].map((e) => /* @__PURE__ */ React10.createElement(
2371
+ entries[zone].map((e) => /* @__PURE__ */ React11.createElement(
2293
2372
  Chip,
2294
2373
  {
2295
2374
  key: e.id,
2296
2375
  id: e.id,
2297
2376
  zone,
2298
2377
  index: e.index,
2299
- count: entries2[zone].length,
2378
+ count: entries[zone].length,
2300
2379
  field: e.field,
2301
2380
  text: e.text,
2302
2381
  typeName: e.type,
@@ -2319,6 +2398,7 @@ function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwa
2319
2398
  }
2320
2399
 
2321
2400
  // src/PivotReport.jsx
2401
+ var savedKeyOf = (t) => JSON.stringify([t.scope, t.store, t.storeSource ?? null, t.sourceId ?? null, t.name]);
2322
2402
  function sizeOf(width) {
2323
2403
  return width < 640 ? "narrow" : width < 1024 ? "medium" : "wide";
2324
2404
  }
@@ -2337,21 +2417,6 @@ function measured(name, fn) {
2337
2417
  }
2338
2418
  return out;
2339
2419
  }
2340
- function pathTitle(result, rowPath, colPath, labels) {
2341
- const parts = [];
2342
- const items = [];
2343
- const add = (axis, fields, path) => {
2344
- const node = findNode(result, axis, path);
2345
- for (let n = node; n && n.parent; n = n.parent) {
2346
- const item = result.label(axis, n, labels.core);
2347
- parts.unshift(`${fieldLabel3(fields[n.depth - 1], labels.core)}: ${item}`);
2348
- items.unshift(item);
2349
- }
2350
- };
2351
- add("cols", result.colFields, colPath);
2352
- add("rows", result.rowFields, rowPath);
2353
- return { title: parts.length ? parts.join(" \xB7 ") : labels.core.grandTotal, name: items.length ? items.join(" \u2013 ") : labels.core.grandTotal };
2354
- }
2355
2420
  function outerPaths(result) {
2356
2421
  const depth = result.rowFields.length;
2357
2422
  const out = [];
@@ -2389,11 +2454,12 @@ function optionsKey(options) {
2389
2454
  }
2390
2455
  var here = () => typeof location !== "undefined" ? { href: location.href, hash: location.hash } : void 0;
2391
2456
  var DEFER_ROWS = 1e4;
2457
+ var unusedNotes = (issues, raw) => issues.filter((i) => (i.code ?? (i.message === "unknown key" ? "unknownKey" : "")) !== "unknownKey" || !["name", "description"].includes(i.path)).map((issue) => ({ issue, raw }));
2392
2458
  function PivotReport(props) {
2393
2459
  const { loading: loading2 = false, data, encoded } = props;
2394
- const [deferred, setDeferred] = useState11(() => !encoded && Array.isArray(data) && data.length > DEFER_ROWS);
2395
- const [started, setStarted] = useState11(false);
2396
- useEffect10(() => {
2460
+ const [deferred, setDeferred] = useState12(() => !encoded && Array.isArray(data) && data.length > DEFER_ROWS);
2461
+ const [started, setStarted] = useState12(false);
2462
+ useEffect11(() => {
2397
2463
  if (!deferred) {
2398
2464
  return void 0;
2399
2465
  }
@@ -2411,19 +2477,19 @@ function PivotReport(props) {
2411
2477
  setStarted(true);
2412
2478
  }
2413
2479
  if (waiting && !started) {
2414
- return /* @__PURE__ */ React11.createElement(WaitingReport, { ...props });
2480
+ return /* @__PURE__ */ React12.createElement(WaitingReport, { ...props });
2415
2481
  }
2416
- return /* @__PURE__ */ React11.createElement(Report, { ...props });
2482
+ return /* @__PURE__ */ React12.createElement(Report, { ...props });
2417
2483
  }
2418
2484
  function WaitingReport({ locale = "en-US", labels: customLabels, theme = "auto", height = 640, className, label }) {
2419
- const root = useRef10(
2485
+ const root = useRef11(
2420
2486
  /** @type {HTMLDivElement | null} */
2421
2487
  null
2422
2488
  );
2423
2489
  const labelsKey = JSON.stringify(customLabels ?? null);
2424
- const labels = useMemo7(() => resolveLabels(locale, JSON.parse(labelsKey)), [locale, labelsKey]);
2490
+ const labels = useMemo8(() => resolveLabels(locale, JSON.parse(labelsKey)), [locale, labelsKey]);
2425
2491
  const themeName = useResolvedTheme(theme, root);
2426
- return /* @__PURE__ */ React11.createElement("div", { ref: root, className: `pk-root${className ? ` ${className}` : ""}`, "data-pk-theme": themeName, lang: labels.lang, role: "region", "aria-label": label || labels.report, style: { height } }, /* @__PURE__ */ React11.createElement(Skeleton, { full: true, text: labels.loadingReport }));
2492
+ return /* @__PURE__ */ React12.createElement("div", { ref: root, className: `pk-root${className ? ` ${className}` : ""}`, "data-pk-theme": themeName, lang: labels.lang, role: "region", "aria-label": label || labels.report, style: { height } }, /* @__PURE__ */ React12.createElement(Skeleton, { full: true, text: labels.loadingReport }));
2427
2493
  }
2428
2494
  function defaultsFor(fieldDefaults, field) {
2429
2495
  if (!fieldDefaults || typeof fieldDefaults !== "object") {
@@ -2433,7 +2499,7 @@ function defaultsFor(fieldDefaults, field) {
2433
2499
  return key === void 0 ? void 0 : fieldDefaults[key];
2434
2500
  }
2435
2501
  function EmptyState({ labels, templates, onTemplate }) {
2436
- return /* @__PURE__ */ React11.createElement("div", { className: "pk-empty", "data-testid": "empty-state" }, /* @__PURE__ */ React11.createElement("div", { className: "pk-empty-art", "aria-hidden": "true" }, /* @__PURE__ */ React11.createElement("span", { className: "pk-empty-chip pk-c1" }), /* @__PURE__ */ React11.createElement("span", { className: "pk-empty-chip pk-c2" }), /* @__PURE__ */ React11.createElement("span", { className: "pk-empty-chip pk-c3" })), /* @__PURE__ */ React11.createElement("h2", null, labels.emptyTitle), /* @__PURE__ */ React11.createElement("ol", { className: "pk-steps" }, labels.emptySteps.map((s, i) => /* @__PURE__ */ React11.createElement("li", { key: i }, /* @__PURE__ */ React11.createElement("span", { className: "pk-step-n", "aria-hidden": "true" }, i + 1), /* @__PURE__ */ React11.createElement("span", null, s)))), templates.length ? /* @__PURE__ */ React11.createElement("div", { className: "pk-empty-actions" }, templates.slice(0, 3).map((t, i) => /* @__PURE__ */ React11.createElement("button", { key: `${i}:${t.name}`, type: "button", className: "pk-btn", onClick: () => onTemplate(t) }, /* @__PURE__ */ React11.createElement(Icon, { name: "sparkle" }), /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, fill(labels.tryView, { name: t.name }))))) : null);
2502
+ return /* @__PURE__ */ React12.createElement("div", { className: "pk-empty", "data-testid": "empty-state" }, /* @__PURE__ */ React12.createElement("div", { className: "pk-empty-art", "aria-hidden": "true" }, /* @__PURE__ */ React12.createElement("span", { className: "pk-empty-chip pk-c1" }), /* @__PURE__ */ React12.createElement("span", { className: "pk-empty-chip pk-c2" }), /* @__PURE__ */ React12.createElement("span", { className: "pk-empty-chip pk-c3" })), /* @__PURE__ */ React12.createElement("h2", null, labels.emptyTitle), /* @__PURE__ */ React12.createElement("ol", { className: "pk-steps" }, labels.emptySteps.map((s, i) => /* @__PURE__ */ React12.createElement("li", { key: i }, /* @__PURE__ */ React12.createElement("span", { className: "pk-step-n", "aria-hidden": "true" }, i + 1), /* @__PURE__ */ React12.createElement("span", null, s)))), templates.length ? /* @__PURE__ */ React12.createElement("div", { className: "pk-empty-actions" }, templates.slice(0, 3).map((t, i) => /* @__PURE__ */ React12.createElement("button", { key: `${i}:${t.name}`, type: "button", className: "pk-btn", onClick: () => onTemplate(t) }, /* @__PURE__ */ React12.createElement(Icon, { name: "sparkle" }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, fill(labels.tryView, { name: t.name }))))) : null);
2437
2503
  }
2438
2504
  function Report(props) {
2439
2505
  const {
@@ -2486,69 +2552,73 @@ function Report(props) {
2486
2552
  const sourceName = typeof sourceProp?.name === "string" && sourceProp.name ? sourceProp.name : void 0;
2487
2553
  const labelsKey = JSON.stringify(customLabels ?? null);
2488
2554
  const defaultsKey = JSON.stringify(fieldDefaults ?? null);
2489
- const info = useMemo7(() => fieldInfoOf(JSON.parse(defaultsKey)), [defaultsKey]);
2490
- const baseLabels = useMemo7(() => resolveLabels(locale, JSON.parse(labelsKey)), [locale, labelsKey]);
2555
+ const info = useMemo8(() => fieldInfoOf(JSON.parse(defaultsKey)), [defaultsKey]);
2556
+ const baseLabels = useMemo8(() => resolveLabels(locale, JSON.parse(labelsKey)), [locale, labelsKey]);
2491
2557
  const typesKey = JSON.stringify(typesOf(fieldDefaults));
2492
2558
  const limitsKey = JSON.stringify(limitsProp ?? null);
2493
- const limits = useMemo7(() => JSON.parse(limitsKey) ?? void 0, [limitsKey]);
2494
- const root = useRef10(
2559
+ const limits = useMemo8(() => JSON.parse(limitsKey) ?? void 0, [limitsKey]);
2560
+ const root = useRef11(
2495
2561
  /** @type {HTMLDivElement | null} */
2496
2562
  null
2497
2563
  );
2498
2564
  const themeName = useResolvedTheme(theme, root);
2499
- const [layer, setLayer] = useState11(
2565
+ const [layer, setLayer] = useState12(
2500
2566
  /** @type {HTMLElement | null} */
2501
2567
  null
2502
2568
  );
2503
- const [size, setSize] = useState11("wide");
2504
- const [measuredShort, setMeasuredShort] = useState11(false);
2505
- const [short, setShort] = useState11(false);
2506
- const [folded, setFolded] = useState11(
2569
+ const [size, setSize] = useState12("wide");
2570
+ const [measuredShort, setMeasuredShort] = useState12(false);
2571
+ const [short, setShort] = useState12(false);
2572
+ const [folded, setFolded] = useState12(
2507
2573
  /** @type {boolean | null} */
2508
2574
  null
2509
2575
  );
2510
2576
  const layoutFolded = folded ?? short;
2511
2577
  const zonesId = useId4();
2512
- const [drawer, setDrawer] = useState11(false);
2513
- const [filterTarget, setFilterTarget] = useState11(
2578
+ const [drawer, setDrawer] = useState12(false);
2579
+ const [filterTarget, setFilterTarget] = useState12(
2514
2580
  /** @type {{ field: string, anchor: HTMLElement, base?: object } | null} */
2515
2581
  null
2516
2582
  );
2517
- const [drill, setDrill] = useState11(
2518
- /** @type {import("./drill-panel.jsx").Drill | null} */
2583
+ const [drill, setDrill] = useState12(
2584
+ /** @type {import("./drill-table.js").DrillSource | null} */
2519
2585
  null
2520
2586
  );
2521
- const [hinted, setHinted] = useState11(false);
2522
- const changesRef = useRef10(0);
2523
- const [changes, setChanges] = useState11(0);
2524
- const [dragAt, setDragAt] = useState11(
2587
+ const [hinted, setHinted] = useState12(false);
2588
+ const changesRef = useRef11(0);
2589
+ const [changes, setChanges] = useState12(0);
2590
+ const [dragAt, setDragAt] = useState12(
2525
2591
  /** @type {number | null} */
2526
2592
  null
2527
2593
  );
2528
- const [savedAt, setSavedAt] = useState11(0);
2529
- const [menus, setMenus] = useState11(
2594
+ const [savedAt, setSavedAt] = useState12(0);
2595
+ const [menus, setMenus] = useState12(
2530
2596
  /** @type {typeof import("./menus.js") | null} */
2531
2597
  null
2532
2598
  );
2533
- const [viewsRequest, setViewsRequest] = useState11(0);
2534
- const [leftOut, setLeftOut] = useState11(
2535
- /** @type {string[]} */
2599
+ const [, setTexts] = useState12(0);
2600
+ useEffect11(() => onMenuTexts(() => setTexts((n) => n + 1)), []);
2601
+ const [viewsRequest, setViewsRequest] = useState12(0);
2602
+ const [leftOut, setLeftOut] = useState12(
2603
+ /** @type {import("./unused.jsx").UnusedNote[]} */
2536
2604
  []
2537
2605
  );
2538
- const [issuesDismissed, setIssuesDismissed] = useState11(
2606
+ const [issuesDismissed, setIssuesDismissed] = useState12(
2539
2607
  /** @type {string | null} */
2540
2608
  null
2541
2609
  );
2542
- const [viewName, setViewName] = useState11(
2543
- /** @type {string | null} */
2544
- null
2610
+ const [loads, setLoads] = useState12(0);
2611
+ const [unusedSaid, setUnusedSaid] = useState12(false);
2612
+ const [savedKeys, setSavedKeys] = useState12(
2613
+ /** @type {Record<string, string>} */
2614
+ {}
2545
2615
  );
2546
- const [rowLabel, setRowLabel] = useState11(
2616
+ const [rowLabel, setRowLabel] = useState12(
2547
2617
  /** @type {string | null} */
2548
2618
  null
2549
2619
  );
2550
- const chartRef = useRef10(null);
2551
- const [chartReady, setChartReady] = useState11(false);
2620
+ const chartRef = useRef11(null);
2621
+ const [chartReady, setChartReady] = useState12(false);
2552
2622
  const hintId = useId4();
2553
2623
  const closeFilter = useCallback9(() => setFilterTarget(null), []);
2554
2624
  const { toasts, push, dismiss, pause } = useToasts();
@@ -2558,7 +2628,7 @@ function Report(props) {
2558
2628
  [push]
2559
2629
  );
2560
2630
  const dataIdentity = dataKey !== void 0 ? dataKey : data;
2561
- const source = useMemo7(() => {
2631
+ const source = useMemo8(() => {
2562
2632
  try {
2563
2633
  const types2 = JSON.parse(typesKey);
2564
2634
  const enc = encodedProp ?? measured("encode", () => encode(
@@ -2573,14 +2643,14 @@ function Report(props) {
2573
2643
  }, [encodedProp, dataIdentity, timeZone, limits, typesKey]);
2574
2644
  const encoded = source.encoded;
2575
2645
  const fieldNamesKey = encoded.schema.fields.map((f) => f.name).join("\0");
2576
- const labels = useMemo7(() => {
2646
+ const labels = useMemo8(() => {
2577
2647
  const fields2 = displayNames(info, fieldNamesKey ? fieldNamesKey.split("\0") : []);
2578
2648
  return fields2 ? { ...baseLabels, core: { ...baseLabels.core, fields: fields2 } } : baseLabels;
2579
2649
  }, [baseLabels, info, fieldNamesKey]);
2580
2650
  const ordersKey = JSON.stringify(
2581
2651
  fieldDefaults && typeof fieldDefaults === "object" ? Object.entries(fieldDefaults).filter(([, d]) => d && Array.isArray(d.order) && d.order.length > 0).map(([field, d]) => [field, d.order]) : []
2582
2652
  );
2583
- const orderOf = useMemo7(() => {
2653
+ const orderOf = useMemo8(() => {
2584
2654
  const orders = (
2585
2655
  /** @type {[string, unknown[]][]} */
2586
2656
  JSON.parse(ordersKey)
@@ -2592,8 +2662,11 @@ function Report(props) {
2592
2662
  }, [ordersKey]);
2593
2663
  const history = useViewHistory({ encoded, view: viewProp, defaultView, onViewChange, limits, outsideNote: labels.steps.outside, orderOf });
2594
2664
  const view = history.view;
2665
+ const loadedView = tagFor(history.tag, sourceId);
2666
+ const viewName = loadedView?.name ?? null;
2667
+ const unsaved = Boolean(loadedView) && savedKeys[savedKeyOf(loadedView)] !== history.viewKey;
2595
2668
  const chartOptionsKey = optionsKey(chartOptions);
2596
- const stableChartOptions = useMemo7(() => chartOptions, [chartOptionsKey]);
2669
+ const stableChartOptions = useMemo8(() => chartOptions, [chartOptionsKey]);
2597
2670
  const stepText = useCallback9(
2598
2671
  (note) => {
2599
2672
  const template = Object.hasOwn(labels.steps, note.step) ? labels.steps[note.step] : labels.steps.change;
@@ -2619,8 +2692,8 @@ function Report(props) {
2619
2692
  announce(fill(labels.toastRedone, { step: note }));
2620
2693
  }
2621
2694
  }, [history, labels, announce]);
2622
- const undoLater = useRef10(undo2);
2623
- useEffect10(() => {
2695
+ const undoLater = useRef11(undo2);
2696
+ useEffect11(() => {
2624
2697
  undoLater.current = undo2;
2625
2698
  });
2626
2699
  const reset2 = useCallback9(() => {
@@ -2628,19 +2701,19 @@ function Report(props) {
2628
2701
  announce(labels.toastReset);
2629
2702
  }, [history, labels, announce]);
2630
2703
  const param = linkParam(storageKey);
2631
- const [opening, setOpening] = useState11(false);
2632
- const appliedLink = useRef10(
2704
+ const [opening, setOpening] = useState12(false);
2705
+ const appliedLink = useRef11(
2633
2706
  /** @type {string | null} */
2634
2707
  null
2635
2708
  );
2636
- const latest = useRef10({ history, encoded, limits, labels, announce, commit: (
2709
+ const latest = useRef11({ history, encoded, limits, labels, announce, commit: (
2637
2710
  /** @type {any} */
2638
2711
  null
2639
2712
  ), sourceId, loaded: (
2640
2713
  /** @type {any} */
2641
2714
  null
2642
2715
  ), sources, onSourceSwitch });
2643
- const [linkCheck, setLinkCheck] = useState11(
2716
+ const [linkCheck, setLinkCheck] = useState12(
2644
2717
  /** @type {null | { lines: string[], quiet: boolean, load: () => void, switchTo?: { name: string, run: () => void } }} */
2645
2718
  null
2646
2719
  );
@@ -2650,23 +2723,23 @@ function Report(props) {
2650
2723
  const apply = (m) => {
2651
2724
  const { history: h, encoded: enc, limits: lim, labels: l, announce: say, sourceId: id, loaded: done, sources: list, onSourceSwitch: switchTo } = latest.current;
2652
2725
  const decoded = m.decodeViewLink(text);
2653
- const loaded2 = decoded.view ? viewFromObject(decoded.view, enc, { limits: lim, sourceId: id }) : null;
2654
- if (!loaded2 || !loaded2.view) {
2655
- say(loaded2?.failed === "newer" ? l.viewFailed.newer : l.viewFailed.badLink, { tone: "error" });
2726
+ const loaded3 = decoded.view ? viewFromObject(decoded.view, enc, { limits: lim, sourceId: id }) : null;
2727
+ if (!loaded3 || !loaded3.view) {
2728
+ say(loaded3?.failed === "newer" ? l.viewFailed.newer : l.viewFailed.badLink, { tone: "error" });
2656
2729
  return;
2657
2730
  }
2658
2731
  const open = () => {
2659
2732
  if (asStep) {
2660
- done(loaded2, { link: true });
2733
+ done(loaded3, { link: true });
2661
2734
  } else {
2662
2735
  h.restore(
2663
2736
  /** @type {object} */
2664
- loaded2.view
2737
+ loaded3.view
2665
2738
  );
2666
- done(loaded2, { link: true, restored: true });
2739
+ done(loaded3, { link: true, restored: true });
2667
2740
  }
2668
2741
  };
2669
- const check = loadCheck(loaded2, l, Array.isArray(list) ? list : []);
2742
+ const check = loadCheck(loaded3, l, Array.isArray(list) ? list : []);
2670
2743
  if (!check) {
2671
2744
  open();
2672
2745
  return;
@@ -2678,8 +2751,8 @@ function Report(props) {
2678
2751
  load: open,
2679
2752
  switchTo: target && typeof switchTo === "function" ? { name: target.name, run: () => switchTo({ source: { id: target.id, name: target.name }, view: (
2680
2753
  /** @type {Record<string, unknown>} */
2681
- loaded2.file?.view ?? loaded2.view
2682
- ), name: loaded2.file?.name || void 0 }) } : void 0
2754
+ loaded3.file?.view ?? loaded3.view
2755
+ ), name: loaded3.file?.name || void 0 }) } : void 0
2683
2756
  });
2684
2757
  };
2685
2758
  if (now) {
@@ -2707,16 +2780,16 @@ function Report(props) {
2707
2780
  const raw = readStoredView(storageKey, sessionStore());
2708
2781
  if (raw) {
2709
2782
  try {
2710
- const loaded2 = viewFromObject(JSON.parse(raw), encoded, { limits });
2711
- if (loaded2.view) {
2712
- history.restore(loaded2.view);
2783
+ const loaded3 = viewFromObject(JSON.parse(raw), encoded, { limits });
2784
+ if (loaded3.view) {
2785
+ history.restore(loaded3.view);
2713
2786
  }
2714
2787
  } catch {
2715
2788
  }
2716
2789
  }
2717
2790
  }
2718
2791
  }, []);
2719
- useEffect10(() => {
2792
+ useEffect11(() => {
2720
2793
  if (!shareLink || typeof window === "undefined") {
2721
2794
  return void 0;
2722
2795
  }
@@ -2729,20 +2802,20 @@ function Report(props) {
2729
2802
  window.addEventListener("hashchange", onHash);
2730
2803
  return () => window.removeEventListener("hashchange", onHash);
2731
2804
  }, [shareLink, param, openLink]);
2732
- useEffect10(() => {
2805
+ useEffect11(() => {
2733
2806
  if (persistView === "session") {
2734
2807
  writeStoredView(storageKey, sessionStore(), JSON.parse(history.viewKey));
2735
2808
  }
2736
2809
  }, [persistView, storageKey, history.viewKey]);
2737
2810
  const commit = useCallback9(
2738
- /** @param {object} next @param {{ step: string, removed?: boolean, field?: string, zone?: string, name?: string, display?: string, type?: string }} [note] */
2739
- (next, note = { step: "change" }) => {
2811
+ /** @param {object} next @param {{ step: string, removed?: boolean, field?: string, zone?: string, name?: string, display?: string, type?: string }} [note] @param {any} [tag] the saved view it is (history.tag) */
2812
+ (next, note = { step: "change" }, tag = void 0) => {
2740
2813
  const over = note.step === "template" ? null : zoneOverLimit(next, limits);
2741
2814
  if (over) {
2742
2815
  announce(fill(labels.zoneFull, { zone: labels.zones[over.zone], max: over.max.toLocaleString(locale) }), { tone: "error" });
2743
2816
  return;
2744
2817
  }
2745
- const changed = history.commit(next, stepText(note));
2818
+ const changed = history.commit(next, stepText(note), tag);
2746
2819
  if (changed) {
2747
2820
  changesRef.current += 1;
2748
2821
  setChanges(changesRef.current);
@@ -2754,28 +2827,36 @@ function Report(props) {
2754
2827
  },
2755
2828
  [history, stepText, labels, announce, limits, locale]
2756
2829
  );
2830
+ const remember = useCallback9((tag, key) => setSavedKeys((all) => ({ ...all, [savedKeyOf(tag)]: key })), []);
2757
2831
  const applyLoaded = useCallback9(
2758
2832
  /** @param {import("./share.js").LoadedView} loaded @param {{ link?: boolean, restored?: boolean }} [how] */
2759
- (loaded2, { link = false, restored = false } = {}) => {
2760
- if (!loaded2.view) {
2833
+ (loaded3, { link = false, restored = false } = {}) => {
2834
+ if (!loaded3.view) {
2761
2835
  return;
2762
2836
  }
2763
- if (!restored) {
2764
- commit(loaded2.view, { step: "viewLoaded" });
2837
+ const tag = loaded3.file?.name ? { name: loaded3.file.name, scope: null, store: false, sourceId: latest.current.sourceId } : null;
2838
+ if (tag) {
2839
+ remember(tag, latest.current.history.keyOf(loaded3.view));
2840
+ }
2841
+ if (restored) {
2842
+ latest.current.history.setTag(tag);
2843
+ } else {
2844
+ commit(loaded3.view, { step: "viewLoaded" }, tag);
2765
2845
  }
2766
- const lines = issueLines(loaded2.issues, labels);
2767
- setLeftOut(lines);
2846
+ const notes2 = unusedNotes(loaded3.issues, loaded3.file?.view);
2847
+ setLeftOut(notes2);
2768
2848
  setIssuesDismissed(null);
2769
- setViewName(loaded2.file?.name || null);
2770
- const text = link ? lines.length ? labels.toastLinkOpenedPartly : labels.toastLinkOpened : lines.length ? labels.toastViewLoadedPartly : labels.toastViewLoaded;
2849
+ setLoads((x) => x + 1);
2850
+ setUnusedSaid(notes2.length > 0);
2851
+ const text = link ? notes2.length ? labels.toastLinkOpenedPartly : labels.toastLinkOpened : notes2.length ? labels.toastViewLoadedPartly : labels.toastViewLoaded;
2771
2852
  announce(text, restored ? void 0 : { action: { label: labels.undo, run: () => undoLater.current() } });
2772
2853
  },
2773
- [commit, labels, announce]
2854
+ [commit, labels, announce, remember]
2774
2855
  );
2775
- useEffect10(() => {
2856
+ useEffect11(() => {
2776
2857
  latest.current = { history, encoded, limits, labels, announce, commit, sourceId, loaded: applyLoaded, sources, onSourceSwitch };
2777
2858
  });
2778
- const computed = useMemo7(() => {
2859
+ const computed = useMemo8(() => {
2779
2860
  try {
2780
2861
  return { result: measured("computePivot", () => computePivot(encoded, view, { locale, limits })), error: null };
2781
2862
  } catch (error2) {
@@ -2783,8 +2864,8 @@ function Report(props) {
2783
2864
  }
2784
2865
  }, [encoded, view, locale, limits]);
2785
2866
  const result = computed.result;
2786
- const plan = useMemo7(() => chartPlan(view, encoded), [view, encoded]);
2787
- const chartComputed = useMemo7(() => {
2867
+ const plan = useMemo8(() => chartPlan(view, encoded), [view, encoded]);
2868
+ const chartComputed = useMemo8(() => {
2788
2869
  if (!plan.swap || view.display !== "chart" || !result) {
2789
2870
  return computed;
2790
2871
  }
@@ -2796,7 +2877,7 @@ function Report(props) {
2796
2877
  }, [plan.swap, view, encoded, locale, limits, computed, result]);
2797
2878
  const chartResult = chartComputed.result;
2798
2879
  const empty = isEmptyView(view);
2799
- const gridState = useMemo7(() => {
2880
+ const gridState = useMemo8(() => {
2800
2881
  if (!result || view.display !== "table" || empty) {
2801
2882
  return { grid: null, error: null };
2802
2883
  }
@@ -2808,9 +2889,11 @@ function Report(props) {
2808
2889
  }, [result, view.display, empty, locale, labels, limits]);
2809
2890
  const error = source.error ?? computed.error ?? gridState.error ?? (view.display === "chart" ? chartComputed.error : null);
2810
2891
  const fields = encoded.schema.fields;
2811
- const types = useMemo7(() => new Map(viewFields(view, encoded).map((f) => [f.name.toLowerCase(), f.type])), [view, encoded]);
2892
+ const types = useMemo8(() => new Map(viewFields(view, encoded).map((f) => [f.name.toLowerCase(), f.type])), [view, encoded]);
2812
2893
  const typeOf = useCallback9((field) => types.get(sourceOf(view, field ?? "").toLowerCase()) ?? "string", [types, view]);
2813
- const nameOf = useCallback9((field) => fieldLabel3(field, labels.core), [labels]);
2894
+ const nameOf = useCallback9((field) => fieldLabel5(field, labels.core), [labels]);
2895
+ const hostOrdered = useCallback9((field) => sourceOf(view, field) === field && (orderOf?.(field)?.length ?? 0) > 0, [view, orderOf]);
2896
+ const sortFromHeader = useCallback9((field, sort) => commit(setSort(view, field, sort), { step: "sort", field: nameOf(field) }), [view, commit, nameOf]);
2814
2897
  const infoOf = useCallback9(
2815
2898
  (field) => {
2816
2899
  if (!field || info.size === 0) {
@@ -2821,7 +2904,7 @@ function Report(props) {
2821
2904
  },
2822
2905
  [info, view]
2823
2906
  );
2824
- const placed = useMemo7(() => {
2907
+ const placed = useMemo8(() => {
2825
2908
  const map = /* @__PURE__ */ new Map();
2826
2909
  const mark = (name, zone) => {
2827
2910
  const key = sourceOf(view, name).toLowerCase();
@@ -2837,14 +2920,22 @@ function Report(props) {
2837
2920
  filterZoneFields(view).forEach((f) => mark(f, "filters"));
2838
2921
  return map;
2839
2922
  }, [view]);
2840
- useEffect10(() => {
2923
+ const lang = labels.lang;
2924
+ useEffect11(() => {
2841
2925
  let live = true;
2842
- loadMenus().then((m) => live && setMenus(() => m), () => void 0);
2926
+ loadMenus(lang).then(
2927
+ (m) => {
2928
+ if (live) {
2929
+ setMenus(() => m);
2930
+ }
2931
+ },
2932
+ () => void 0
2933
+ );
2843
2934
  return () => {
2844
2935
  live = false;
2845
2936
  };
2846
- }, []);
2847
- const mainRef = useRef10(
2937
+ }, [lang]);
2938
+ const mainRef = useRef11(
2848
2939
  /** @type {HTMLDivElement | null} */
2849
2940
  null
2850
2941
  );
@@ -2872,7 +2963,7 @@ function Report(props) {
2872
2963
  ro.observe(el);
2873
2964
  return () => ro.disconnect();
2874
2965
  }, []);
2875
- useEffect10(() => {
2966
+ useEffect11(() => {
2876
2967
  if (measuredShort === short) {
2877
2968
  return void 0;
2878
2969
  }
@@ -2890,11 +2981,11 @@ function Report(props) {
2890
2981
  return () => mo.disconnect();
2891
2982
  }, [measuredShort, short, layer]);
2892
2983
  const drawerOpen = drawer && size === "narrow";
2893
- const panelRef = useRef10(
2984
+ const panelRef = useRef11(
2894
2985
  /** @type {HTMLDivElement | null} */
2895
2986
  null
2896
2987
  );
2897
- useEffect10(() => {
2988
+ useEffect11(() => {
2898
2989
  if (panelRef.current) {
2899
2990
  panelRef.current.inert = size === "narrow" && !drawerOpen;
2900
2991
  }
@@ -2969,110 +3060,64 @@ function Report(props) {
2969
3060
  const d = defaultsFor(fieldDefaults, name);
2970
3061
  return d ? d.drillFormat ?? d.format : void 0;
2971
3062
  };
2972
- const table = drillTable(encoded, indices, { locale: result.locale, labels: labels.core, formatOf });
2973
- const columns = table.columns.map((c) => ({ ...c, label: nameOf(c.name), description: infoOf(c.name)?.description }));
2974
- const formats = Object.fromEntries(table.columns.map((c) => [c.name, formatOf(c.name)]).filter(([, f]) => typeof f === "string"));
2975
- setDrill({ ...pathTitle(result, rowPath, colPath, labels), count, rows: table.rows, columns, indices, formats, locale: result.locale });
3063
+ setDrill({ result, rowPath, colPath, count, indices, formatOf, nameOf, infoOf });
2976
3064
  }
2977
3065
  },
2978
- [result, encodedProp, data, drillDownLimit, onCellClick, drillDown, labels, encoded, fieldDefaults, nameOf, infoOf]
3066
+ [result, encodedProp, data, drillDownLimit, onCellClick, drillDown, fieldDefaults, nameOf, infoOf]
2979
3067
  );
2980
3068
  const doExport = useExport({ fileName, result, locale, labels, limits, root, chartRef, announce, onExport });
2981
3069
  const base = shareBase(shareLink, here()?.href);
2982
- const viewFile = () => viewFileText(toViewFile(view, { name: viewName ?? "", createdAt: /* @__PURE__ */ new Date(), generator: { name: "pivotkit-react", version: VERSION }, source: { id: sourceId, name: sourceName }, data: encoded, ...schemaUrl !== void 0 ? { schemaUrl } : {} }));
2983
3070
  const share = {
2984
3071
  canLink: base !== null,
2985
3072
  prepare: base !== null ? () => void loadLink().catch(() => void 0) : void 0,
2986
- copyLink: async () => {
2987
- const target = shareBase(shareLink, here()?.href);
2988
- if (target === null) {
2989
- return;
2990
- }
2991
- let text;
2992
- try {
2993
- text = (linkNow() ?? await loadLink()).encodeViewLink(toViewFile(view, { name: viewName ?? void 0, source: { id: sourceId } }, { link: true }));
2994
- } catch (e) {
2995
- announce(e && /** @type {any} */
2996
- e.code === "LIMIT_EXCEEDED" ? labels.toastLinkTooLong : fill(labels.error, { message: String(e) }), { tone: "error" });
2997
- return;
2998
- }
2999
- const ok = await copyText(withLinkParam(target, param, text), root.current);
3000
- announce(ok ? labels.toastLinkCopied : labels.toastCopyFailed, ok ? void 0 : { tone: "error" });
3001
- },
3002
- copyJson: async () => {
3003
- const ok = await copyText(viewFile(), root.current);
3004
- announce(ok ? labels.toastJsonCopied : labels.toastCopyFailed, ok ? void 0 : { tone: "error" });
3005
- },
3006
- download: () => {
3007
- const file = viewFileName(viewName || sourceName || safeFileName(fileName));
3008
- const blob = new Blob([viewFile()], { type: "application/json" });
3009
- if (onExport?.({ kind: "json", fileName: file, blob }) === false) {
3010
- return;
3011
- }
3012
- saveBlob(blob, file, root.current?.ownerDocument ?? document);
3013
- announce(fill(labels.toastExported, { file }));
3014
- },
3015
- /**
3016
- * @param {string} text
3017
- * @returns {Promise<string | null | { lines: string[], load: () => void, switchTo?: { name: string, run: () => void } }>}
3018
- * why nothing was loaded, null when it was, or what to ask first (a view for other data)
3019
- */
3020
- loadText: async (text) => {
3021
- let loaded2 = viewFromText(text, encoded, { limits, sourceId });
3022
- if (loaded2.failed === "notJson") {
3023
- const t = text.trim();
3024
- const fromUrl = t.includes("#") ? readLinkParam(t.slice(t.indexOf("#")), param) ?? readLinkParam(t.slice(t.indexOf("#")), "pivot") : null;
3025
- const payload = fromUrl ?? (t.startsWith("1.") ? t : null);
3026
- if (!payload) {
3027
- return labels.viewFailed.notJson;
3028
- }
3029
- try {
3030
- const decoded = (linkNow() ?? await loadLink()).decodeViewLink(payload);
3031
- loaded2 = decoded.view ? viewFromObject(decoded.view, encoded, { limits, sourceId }) : { view: null, issues: [], failed: "badLink", file: null };
3032
- } catch {
3033
- return labels.viewFailed.badLink;
3034
- }
3035
- }
3036
- if (!loaded2.view) {
3037
- return labels.viewFailed[loaded2.failed ?? "notView"] ?? labels.viewFailed.notView;
3038
- }
3039
- const ready = (
3040
- /** @type {import("./share.js").LoadedView} */
3041
- loaded2
3042
- );
3043
- const check = loadCheck(ready, labels, Array.isArray(sources) ? sources : []);
3044
- if (!check) {
3045
- applyLoaded(ready);
3046
- return null;
3047
- }
3048
- const target = check.switchTo;
3049
- return {
3050
- lines: check.lines,
3051
- load: () => applyLoaded(ready),
3052
- switchTo: target && typeof onSourceSwitch === "function" ? { name: target.name, run: () => onSourceSwitch({ source: { id: target.id, name: target.name }, view: (
3053
- /** @type {Record<string, unknown>} */
3054
- ready.file?.view ?? ready.view
3055
- ), name: ready.file?.name || void 0 }) } : void 0
3056
- };
3057
- }
3073
+ view,
3074
+ viewName,
3075
+ sourceId,
3076
+ sourceName,
3077
+ schemaUrl,
3078
+ encoded,
3079
+ shareLink,
3080
+ param,
3081
+ root,
3082
+ fileName,
3083
+ onExport,
3084
+ announce,
3085
+ limits,
3086
+ sources,
3087
+ onSourceSwitch,
3088
+ applyLoaded
3058
3089
  };
3059
3090
  const loadTemplate = useCallback9(
3060
3091
  (t) => {
3061
- commit(t.view, { step: "template", name: t.name });
3062
- setViewName(typeof t.name === "string" ? t.name : null);
3092
+ const tag = { name: t.name, scope: t.scope === "user" ? "user" : "shared", store: t.at !== void 0, storeSource: t.sourceId ?? null, sourceId };
3093
+ remember(tag, history.keyOf(t.view));
3094
+ commit(t.view, { step: "template", name: t.name }, tag);
3063
3095
  const over = zoneOverLimit(t.view, limits);
3064
- setLeftOut(over ? [fill(labels.viewTrimmed, { name: t.name, zone: labels.zones[over.zone], max: over.max.toLocaleString(locale) })] : []);
3096
+ const issues = normalize2(t.view, encoded, { limits }).issues.filter((i) => !over || i.code !== "tooMany");
3097
+ setLeftOut([...over ? [{ text: fill(labels.viewTrimmed, { name: t.name, zone: labels.zones[over.zone], max: over.max.toLocaleString(locale) }) }] : [], ...unusedNotes(issues, t.view)]);
3065
3098
  setIssuesDismissed(null);
3099
+ setLoads((x) => x + 1);
3100
+ setUnusedSaid(false);
3066
3101
  announce(fill(labels.toastLoaded, { name: t.name }));
3067
3102
  },
3068
- [commit, labels, announce, limits, locale]
3103
+ [commit, labels, announce, limits, locale, history, remember, sourceId, encoded]
3069
3104
  );
3105
+ const newReport = () => {
3106
+ if (empty) {
3107
+ return;
3108
+ }
3109
+ commit(emptyView2(), { step: "new" }, null);
3110
+ setLeftOut([]);
3111
+ setLoads((x) => x + 1);
3112
+ setUnusedSaid(false);
3113
+ announce(labels.newEmpty, { action: { label: labels.undo, run: () => undoLater.current() } });
3114
+ };
3070
3115
  const viewStore = templateStore === "browser";
3071
3116
  const storeName = viewsName(storageKey);
3072
3117
  const subscribeViews = useCallback9((callback) => viewStore ? subscribeItem(storeName, callback) : () => {
3073
3118
  }, [viewStore, storeName]);
3074
3119
  const viewsText = useSyncExternalStore3(subscribeViews, () => viewStore ? readItem(storeName, localStore()) : null, () => null);
3075
- const entries2 = useMemo7(() => templateEntries(templates, viewStore && menus ? menus.storedViews(viewsText, sourceId) : [], Boolean(onDeleteTemplate)), [templates, viewStore, menus, viewsText, sourceId, onDeleteTemplate]);
3120
+ const entries = useMemo8(() => templateEntries(templates, viewStore && menus ? menus.storedViews(viewsText, sourceId) : [], Boolean(onDeleteTemplate)), [templates, viewStore, menus, viewsText, sourceId, onDeleteTemplate]);
3076
3121
  const templateActions = {
3077
3122
  view,
3078
3123
  announce,
@@ -3084,9 +3129,29 @@ function Report(props) {
3084
3129
  onSave: onSaveTemplate,
3085
3130
  onDelete: onDeleteTemplate,
3086
3131
  onPublish: canPublish ? onPublishTemplate : void 0,
3087
- // a view leaves the report checked against the data, never as it was stored
3088
- normalized: (v) => normalize3(v, encoded, { limits }).view,
3089
- onSaved: () => setSavedAt(changesRef.current)
3132
+ // a view leaves the report checked against the data, never as it was stored, and in the form a
3133
+ // save hands over (the view as shown: normalized, with the host's orders), so Publish and
3134
+ // Save send the same view
3135
+ normalized: (v) => JSON.parse(history.keyOf(v)),
3136
+ loaded: loadedView,
3137
+ empty,
3138
+ /**
3139
+ * A save kept: the view as it was when the save was clicked (`key`) is that saved view now. The
3140
+ * view shown takes its name only while it is still that view: a slow host may answer after
3141
+ * New, another view loaded or a change, and none of those may become the saved view.
3142
+ */
3143
+ onSaved: (saved, key) => {
3144
+ setSavedAt(changesRef.current);
3145
+ const tag = { ...saved, sourceId };
3146
+ remember(tag, key);
3147
+ const now = latest.current.history;
3148
+ if (now.viewKey === key) {
3149
+ now.setTag(tag);
3150
+ }
3151
+ },
3152
+ viewKey: history.viewKey,
3153
+ onNew: newReport,
3154
+ canNew: !empty
3090
3155
  };
3091
3156
  const onKeyDown = (e) => {
3092
3157
  const target = (
@@ -3114,27 +3179,27 @@ function Report(props) {
3114
3179
  redo2();
3115
3180
  }
3116
3181
  };
3117
- const layerValue = useMemo7(() => ({ layer, size }), [layer, size]);
3118
- const renderOverlay = (src) => /* @__PURE__ */ React11.createElement("div", { className: "pk-chip pk-overlay" }, /* @__PURE__ */ React11.createElement(Icon, { name: "grip", size: 14 }), /* @__PURE__ */ React11.createElement("span", { className: `pk-type pk-type-${src.type ?? typeOf(src.field)}` }, /* @__PURE__ */ React11.createElement(Icon, { name: (
3182
+ const layerValue = useMemo8(() => ({ layer, size }), [layer, size]);
3183
+ const renderOverlay = (src) => /* @__PURE__ */ React12.createElement("div", { className: "pk-chip pk-overlay" }, /* @__PURE__ */ React12.createElement(Icon, { name: "grip", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: `pk-type pk-type-${src.type ?? typeOf(src.field)}` }, /* @__PURE__ */ React12.createElement(Icon, { name: (
3119
3184
  /** @type {any} */
3120
3185
  TYPE_ICON[src.type ?? typeOf(src.field)] ?? "text"
3121
- ), size: 13 })), /* @__PURE__ */ React11.createElement("span", { className: "pk-chip-text" }, src.label ?? src.field));
3186
+ ), size: 13 })), /* @__PURE__ */ React12.createElement("span", { className: "pk-chip-text" }, src.label ?? src.field));
3122
3187
  const showTable = !error && !(empty && view.display === "table") && view.display !== "chart" && gridState.grid;
3123
- const outer = useMemo7(() => result ? outerPaths(result) : [], [result]);
3188
+ const outer = useMemo8(() => result ? outerPaths(result) : [], [result]);
3124
3189
  const folding = rowFolding(view, outer);
3125
- const expandAll = () => {
3190
+ const expandAll = (texts) => {
3126
3191
  const count = view.collapsed.rows.length;
3127
3192
  commit(setCollapsed(view, "rows", null), { step: "collapse" });
3128
- announce(plural(labels.groupsExpanded, count, { lang: labels.lang, locale }));
3193
+ announce(plural(texts.groupsExpanded, count, { lang: labels.lang, locale }));
3129
3194
  };
3130
- const collapseAll = () => {
3195
+ const collapseAll = (texts) => {
3131
3196
  if (!result) {
3132
3197
  return;
3133
3198
  }
3134
3199
  commit(setCollapsed(view, "rows", outer), { step: "collapse" });
3135
- announce(plural(labels.groupsCollapsed, folding.open, { lang: labels.lang, locale }));
3200
+ announce(plural(texts.groupsCollapsed, folding.open, { lang: labels.lang, locale }));
3136
3201
  };
3137
- const series = useMemo7(() => {
3202
+ const series = useMemo8(() => {
3138
3203
  if (!chartResult || view.display !== "chart" || view.values.length === 0) {
3139
3204
  return null;
3140
3205
  }
@@ -3145,17 +3210,17 @@ function Report(props) {
3145
3210
  }
3146
3211
  }, [chartResult, view.display, view.values.length, labels]);
3147
3212
  const allowedKey = JSON.stringify(allowedTips(tipsProp));
3148
- const allowed = useMemo7(() => JSON.parse(allowedKey), [allowedKey]);
3213
+ const allowed = useMemo8(() => JSON.parse(allowedKey), [allowedKey]);
3149
3214
  const dismissedKey = JSON.stringify(cleanDismissed(dismissedTips));
3150
- const [own2, setOwn] = useState11(() => cleanDismissed(JSON.parse(dismissedKey)));
3151
- const [lastDismissedKey, setLastDismissedKey] = useState11(dismissedKey);
3215
+ const [own2, setOwn] = useState12(() => cleanDismissed(JSON.parse(dismissedKey)));
3216
+ const [lastDismissedKey, setLastDismissedKey] = useState12(dismissedKey);
3152
3217
  if (dismissedKey !== lastDismissedKey) {
3153
3218
  setLastDismissedKey(dismissedKey);
3154
3219
  setOwn(JSON.parse(dismissedKey));
3155
3220
  }
3156
3221
  const subscribe = useCallback9((callback) => subscribeStored(storageKey, callback), [storageKey]);
3157
3222
  const storedRaw = useSyncExternalStore3(subscribe, () => readStored(storageKey, localStore()), () => null);
3158
- const dismissed = useMemo7(() => cleanDismissed([...own2, ...parseStored(storedRaw)]), [own2, storedRaw]);
3223
+ const dismissed = useMemo8(() => cleanDismissed([...own2, ...parseStored(storedRaw)]), [own2, storedRaw]);
3159
3224
  const changeDismissed = useCallback9(
3160
3225
  (next, id) => {
3161
3226
  setOwn(next);
@@ -3170,21 +3235,30 @@ function Report(props) {
3170
3235
  const zoneSwitch = helpSwitch(zoneInfoProp, dismissed);
3171
3236
  const settingSwitch = helpSwitch(settingInfoProp, dismissed);
3172
3237
  const explainUser = settingSwitch.user || zoneSwitch.user || describedFields && fieldSwitch.user;
3173
- const help = useMemo7(
3238
+ const ready = menus ? menusNow(labels.lang) : null;
3239
+ const withTexts = ready ? ready.menuLabels(labels) : null;
3240
+ const [keptTexts, setKeptTexts] = useState12(
3241
+ /** @type {any} */
3242
+ null
3243
+ );
3244
+ if (withTexts && withTexts !== keptTexts) {
3245
+ setKeptTexts(withTexts);
3246
+ }
3247
+ const helpLabels = withTexts ?? keptTexts ?? labels;
3248
+ const help = useMemo8(
3174
3249
  () => ({
3175
3250
  explain: settingSwitch.on,
3176
- // with the menus' texts once they are loaded: the explanations are among them
3177
- labels: menus ? menus.menuLabels(labels) : labels,
3251
+ labels: helpLabels,
3178
3252
  isOpen: (id) => sectionOpen(id, dismissed),
3179
3253
  setOpen: (id, open) => changeDismissed(withSection(dismissed, id, open), null)
3180
3254
  }),
3181
- [settingSwitch.on, labels, menus, dismissed, changeDismissed]
3255
+ [settingSwitch.on, helpLabels, dismissed, changeDismissed]
3182
3256
  );
3183
- const [fieldsSession, setFieldsSession] = useState11(
3257
+ const [fieldsSession, setFieldsSession] = useState12(
3184
3258
  /** @type {boolean | null} */
3185
3259
  null
3186
3260
  );
3187
- useEffect10(() => {
3261
+ useEffect11(() => {
3188
3262
  if (fieldList !== void 0 && fieldList !== "open" && fieldList !== "collapsed") {
3189
3263
  warnOnce(`pivotkit: fieldList ${JSON.stringify(String(fieldList)).slice(0, 40)} is neither "open" nor "collapsed"; the user's choice decides`);
3190
3264
  }
@@ -3228,11 +3302,11 @@ function Report(props) {
3228
3302
  appliedLink.current = null;
3229
3303
  setLinkCheck(null);
3230
3304
  };
3231
- const notes = [...leftOut.map((text) => ({ path: "", text })), ...result && !empty ? result.issues.slice(0, 20).map((i) => ({ path: i.path, text: i.message })) : []];
3232
- const notesKey = JSON.stringify(notes);
3305
+ const notes = useMemo8(() => [...leftOut, ...result && !empty ? result.issues.slice(0, 20).map((issue) => ({ issue, raw: view })) : []], [leftOut, result, empty, view]);
3306
+ const notesKey = useMemo8(() => JSON.stringify([loads, ...notes.map((n) => "issue" in n ? [n.issue.path, n.issue.message] : n.text)]), [notes, loads]);
3233
3307
  const summaryParts = big.enlarged ? layoutSummary(zoneEntries(view, types, labels), labels) : [];
3234
3308
  const summaryText = summaryParts.length ? summaryParts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
3235
- return /* @__PURE__ */ React11.createElement(
3309
+ return /* @__PURE__ */ React12.createElement(
3236
3310
  "div",
3237
3311
  {
3238
3312
  ref: root,
@@ -3250,7 +3324,7 @@ function Report(props) {
3250
3324
  tabIndex: -1,
3251
3325
  onKeyDown
3252
3326
  },
3253
- /* @__PURE__ */ React11.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React11.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React11.createElement(
3327
+ /* @__PURE__ */ React12.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React12.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React12.createElement(
3254
3328
  PivotDnd,
3255
3329
  {
3256
3330
  labels,
@@ -3262,7 +3336,7 @@ function Report(props) {
3262
3336
  }
3263
3337
  }
3264
3338
  },
3265
- /* @__PURE__ */ React11.createElement("div", { className: `pk-layout${drawerOpen ? " pk-drawer-open" : ""}` }, /* @__PURE__ */ React11.createElement("div", { className: "pk-panel-slot", ref: panelRef }, /* @__PURE__ */ React11.createElement(
3339
+ /* @__PURE__ */ React12.createElement("div", { className: `pk-layout${drawerOpen ? " pk-drawer-open" : ""}` }, /* @__PURE__ */ React12.createElement("div", { className: "pk-panel-slot", ref: panelRef }, /* @__PURE__ */ React12.createElement(
3266
3340
  FieldPanel,
3267
3341
  {
3268
3342
  fields,
@@ -3289,7 +3363,7 @@ function Report(props) {
3289
3363
  root.current?.querySelector(".pk-toolbar button:not([disabled])")?.focus()
3290
3364
  )
3291
3365
  }
3292
- )), drawerOpen ? /* @__PURE__ */ React11.createElement("div", { className: "pk-scrim pk-drawer-scrim", onClick: () => setDrawer(false), "aria-hidden": "true" }) : null, /* @__PURE__ */ React11.createElement("div", { className: "pk-main", ref: mainRef }, /* @__PURE__ */ React11.createElement(
3366
+ )), drawerOpen ? /* @__PURE__ */ React12.createElement("div", { className: "pk-scrim pk-drawer-scrim", onClick: () => setDrawer(false), "aria-hidden": "true" }) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-main", ref: mainRef }, /* @__PURE__ */ React12.createElement(
3293
3367
  Toolbar,
3294
3368
  {
3295
3369
  view,
@@ -3302,6 +3376,7 @@ function Report(props) {
3302
3376
  onUndo: undo2,
3303
3377
  onRedo: redo2,
3304
3378
  onReset: reset2,
3379
+ loadedView: loadedView ? { name: loadedView.name, changed: unsaved } : null,
3305
3380
  onDisplay: (d) => commit(setDisplay(view, d), { step: "display", display: d }),
3306
3381
  onChart: (p) => commit(setChart(view, p), { step: "chart", type: p }),
3307
3382
  onChartDisplay: (patch) => commit(setChartDisplay(view, patch), { step: "chartDisplay" }),
@@ -3310,12 +3385,13 @@ function Report(props) {
3310
3385
  onCollapse: collapseAll,
3311
3386
  folding,
3312
3387
  share,
3313
- templates: entries2,
3388
+ templates: entries,
3314
3389
  onLoadTemplate: loadTemplate,
3315
3390
  templateActions,
3316
3391
  onExport: doExport,
3317
3392
  prepareExport: prepareExporters,
3318
3393
  chartReady: view.display === "chart" && chartReady,
3394
+ empty,
3319
3395
  onShowFields: () => setDrawer(true),
3320
3396
  layoutFolded,
3321
3397
  onLayout: () => setFolded(!layoutFolded),
@@ -3326,11 +3402,13 @@ function Report(props) {
3326
3402
  canResetTips: dismissed.some((id) => !keptOnReset(id)),
3327
3403
  onResetTips: () => changeDismissed(dismissed.filter(keptOnReset), null),
3328
3404
  help: {
3329
- explanations: explainUser ? { on: !dismissed.includes(NO_EXPLANATIONS), set: (on) => toggle(NO_EXPLANATIONS, on) } : null
3405
+ explanations: explainUser ? { on: !dismissed.includes(NO_EXPLANATIONS), set: (on) => toggle(NO_EXPLANATIONS, on) } : null,
3406
+ // the list with the sections' states, for "Reset menu sections" (the menus do the rest)
3407
+ sections: [dismissed, changeDismissed]
3330
3408
  },
3331
3409
  viewsRequest
3332
3410
  }
3333
- ), /* @__PURE__ */ React11.createElement(
3411
+ ), /* @__PURE__ */ React12.createElement(
3334
3412
  Zones,
3335
3413
  {
3336
3414
  view,
@@ -3349,11 +3427,25 @@ function Report(props) {
3349
3427
  explain: zoneSwitch.on,
3350
3428
  showInfo: fieldSwitch.on
3351
3429
  }
3352
- ), linkCheck ? /* @__PURE__ */ React11.createElement("div", { className: "pk-link-check", "data-testid": "link-check" }, /* @__PURE__ */ React11.createElement(MenuPanel, { name: "LoadCheck", props: { check: linkCheck, labels, title: labels.linkCheckTitle, quiet: linkCheck.quiet, close: () => setLinkCheck(null), onCancel: cancelLink } })) : null, notes.length > 0 && issuesDismissed !== notesKey ? (
3353
- // what a loaded view left out and what the view asks for that this data has not:
3354
- // it stays (the status note goes by itself) until it is dismissed
3355
- /* @__PURE__ */ React11.createElement("div", { className: "pk-issues", "data-testid": "view-issues" }, /* @__PURE__ */ React11.createElement("details", null, /* @__PURE__ */ React11.createElement("summary", null, /* @__PURE__ */ React11.createElement(Icon, { name: "info" }), " ", labels.issues, " ", notes.length), /* @__PURE__ */ React11.createElement("ul", null, notes.map((n, k) => /* @__PURE__ */ React11.createElement("li", { key: k }, n.path ? /* @__PURE__ */ React11.createElement("code", null, n.path) : null, " ", n.text)))), /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-icon-btn pk-issues-x", "aria-label": labels.dismissIssues, title: labels.dismissIssues, onClick: () => setIssuesDismissed(notesKey), "data-testid": "dismiss-issues" }, /* @__PURE__ */ React11.createElement(Icon, { name: "x", size: 14 })))
3356
- ) : null, /* @__PURE__ */ React11.createElement(
3430
+ ), linkCheck ? /* @__PURE__ */ React12.createElement("div", { className: "pk-link-check", "data-testid": "link-check" }, /* @__PURE__ */ React12.createElement(MenuPanel, { name: "LoadCheck", props: { check: linkCheck, labels, title: labels.linkCheckTitle, quiet: linkCheck.quiet, close: () => setLinkCheck(null), onCancel: cancelLink } })) : null, /* @__PURE__ */ React12.createElement(
3431
+ Unused,
3432
+ {
3433
+ notes,
3434
+ notesKey,
3435
+ dismissed: issuesDismissed === notesKey,
3436
+ onDismiss: (next) => {
3437
+ setIssuesDismissed(notesKey);
3438
+ next?.focus({ preventScroll: true });
3439
+ if (!next || activeIn(next) !== next) {
3440
+ root.current?.focus({ preventScroll: true });
3441
+ }
3442
+ },
3443
+ labels,
3444
+ locale,
3445
+ narrow: size === "narrow",
3446
+ quiet: unusedSaid
3447
+ }
3448
+ ), /* @__PURE__ */ React12.createElement(
3357
3449
  Tips,
3358
3450
  {
3359
3451
  tips: shownTips,
@@ -3362,7 +3454,7 @@ function Report(props) {
3362
3454
  onAction: runTip,
3363
3455
  focusFallback: () => root.current?.focus({ preventScroll: true })
3364
3456
  }
3365
- ), showTable && view.values.length ? /* @__PURE__ */ React11.createElement("p", { id: hintId, className: "pk-sr", "data-testid": "cell-hint" }, labels.tips.cells) : null, /* @__PURE__ */ React11.createElement("div", { className: "pk-result-head" }, big.enlarged ? /* @__PURE__ */ React11.createElement("p", { className: "pk-enlarged-fields", "data-testid": "enlarged-fields" }, summaryText) : null, /* @__PURE__ */ React11.createElement("span", { className: "pk-grow" }), /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "data-pk-on": big.enlarged ? "" : void 0, onClick: big.toggleEnlarged, "data-testid": "enlarge" }, /* @__PURE__ */ React11.createElement(Icon, { name: "enlarge", size: 14 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, big.enlarged ? labels.reduce : labels.enlarge)), big.fullOk ? /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "aria-pressed": big.full, onClick: big.toggleFull, "data-testid": "full-screen" }, /* @__PURE__ */ React11.createElement(Icon, { name: "fullScreen", size: 14 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, labels.fullScreen)) : null), /* @__PURE__ */ React11.createElement("section", { className: "pk-result", "aria-label": view.display === "chart" ? labels.chart : labels.table }, loading2 || opening ? /* @__PURE__ */ React11.createElement(Skeleton, { text: labels.loadingReport }) : error ? /* @__PURE__ */ React11.createElement("div", { className: "pk-message pk-error", role: "alert" }, /* @__PURE__ */ React11.createElement(Icon, { name: "info" }), /* @__PURE__ */ React11.createElement("p", null, errorText(error, labels, locale))) : empty && view.display === "table" ? /* @__PURE__ */ React11.createElement(EmptyState, { labels, templates: entries2, onTemplate: loadTemplate }) : view.display === "chart" && chartResult ? /* @__PURE__ */ React11.createElement(
3457
+ ), showTable && view.values.length ? /* @__PURE__ */ React12.createElement("p", { id: hintId, className: "pk-sr", "data-testid": "cell-hint" }, labels.tips.cells) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-result-head" }, big.enlarged ? /* @__PURE__ */ React12.createElement("p", { className: "pk-enlarged-fields", "data-testid": "enlarged-fields" }, summaryText) : null, /* @__PURE__ */ React12.createElement("span", { className: "pk-grow" }), /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "data-pk-on": big.enlarged ? "" : void 0, onClick: big.toggleEnlarged, "data-testid": "enlarge" }, /* @__PURE__ */ React12.createElement(Icon, { name: "enlarge", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, big.enlarged ? labels.reduce : labels.enlarge)), big.fullOk ? /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "aria-pressed": big.full, onClick: big.toggleFull, "data-testid": "full-screen" }, /* @__PURE__ */ React12.createElement(Icon, { name: "fullScreen", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, labels.fullScreen)) : null), /* @__PURE__ */ React12.createElement("section", { className: "pk-result", "aria-label": view.display === "chart" ? labels.chart : labels.table }, loading2 || opening ? /* @__PURE__ */ React12.createElement(Skeleton, { text: labels.loadingReport }) : error ? /* @__PURE__ */ React12.createElement("div", { className: "pk-message pk-error", role: "alert" }, /* @__PURE__ */ React12.createElement(Icon, { name: "info" }), /* @__PURE__ */ React12.createElement("p", null, errorText(error, labels, locale))) : empty && view.display === "table" ? /* @__PURE__ */ React12.createElement(EmptyState, { labels, templates: entries, onTemplate: loadTemplate }) : view.display === "chart" && chartResult ? /* @__PURE__ */ React12.createElement(
3366
3458
  PivotChart,
3367
3459
  {
3368
3460
  result: chartResult,
@@ -3380,9 +3472,9 @@ function Report(props) {
3380
3472
  },
3381
3473
  onPoint: (p) => openCell({ rowPath: plan.swap ? p.colPath : p.rowPath, colPath: plan.swap ? p.rowPath : p.colPath, value: p.value, valueIndex: p.valueIndex, text: String(p.value ?? "") })
3382
3474
  }
3383
- ) : gridState.grid ? /* @__PURE__ */ React11.createElement(PivotTable, { grid: gridState.grid, view, labels, version: history.viewKey, hintId: view.values.length ? hintId : void 0, onRowLabel: setRowLabel, infoOf, showInfo: fieldSwitch.on, onToggle: (axis, path) => commit(toggleCollapsed(view, axis, path), { step: "collapse" }), onCell: (cell) => openCell(cell) }) : null), /* @__PURE__ */ React11.createElement("div", { className: "pk-status" }, /* @__PURE__ */ React11.createElement("span", { "data-testid": "row-count" }, result ? plural(labels.rowsCount, result.rows.length, { lang: labels.lang, locale }) : ""), rowLabel && showTable ? /* @__PURE__ */ React11.createElement("span", { className: "pk-row-label", "data-testid": "row-label" }, fill(labels.rowLabel, { label: rowLabel })) : null), /* @__PURE__ */ React11.createElement("div", { className: "pk-toast-dock" }, /* @__PURE__ */ React11.createElement(Toasts, { toasts, dismiss, pause, closeLabel: labels.close }))), drill ? /* @__PURE__ */ React11.createElement(MenuPanel, { name: "DrillPanel", props: { drill, onClose: () => setDrill(null), labels, locale, exportContext: { encoded, onExport, announce, root } } }) : null),
3384
- filterTarget ? /* @__PURE__ */ React11.createElement(MenuPanel, { name: "FilterPopover", props: { target: filterTarget, onClose: closeFilter, view, encoded, locale, labels, commit } }) : null
3385
- ), /* @__PURE__ */ React11.createElement("div", { className: "pk-layer", ref: setLayer }, /* @__PURE__ */ React11.createElement("span", { className: "pk-origin", "aria-hidden": "true" }))))
3475
+ ) : gridState.grid ? /* @__PURE__ */ React12.createElement(PivotTable, { grid: gridState.grid, view, labels, version: history.viewKey, hintId: view.values.length ? hintId : void 0, onRowLabel: setRowLabel, infoOf, showInfo: fieldSwitch.on, typeOf, hostOrdered, onSort: sortFromHeader, onToggle: (axis, path) => commit(toggleCollapsed(view, axis, path), { step: "collapse" }), onCell: (cell) => openCell(cell) }) : null), /* @__PURE__ */ React12.createElement("div", { className: "pk-status" }, /* @__PURE__ */ React12.createElement("span", { "data-testid": "row-count" }, result ? plural(labels.rowsCount, result.rows.length, { lang: labels.lang, locale }) : ""), rowLabel && showTable ? /* @__PURE__ */ React12.createElement("span", { className: "pk-row-label", "data-testid": "row-label" }, fill(labels.rowLabel, { label: rowLabel })) : null), /* @__PURE__ */ React12.createElement("div", { className: "pk-toast-dock" }, /* @__PURE__ */ React12.createElement(Toasts, { toasts, dismiss, pause, closeLabel: labels.close }))), drill ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "DrillPanel", props: { drill, onClose: () => setDrill(null), labels, locale, exportContext: { encoded, onExport, announce, root } } }) : null),
3476
+ filterTarget ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "FilterPopover", props: { target: filterTarget, onClose: closeFilter, view, encoded, locale, labels, commit } }) : null
3477
+ ), /* @__PURE__ */ React12.createElement("div", { className: "pk-layer", ref: setLayer }, /* @__PURE__ */ React12.createElement("span", { className: "pk-origin", "aria-hidden": "true" }))))
3386
3478
  );
3387
3479
  }
3388
3480
  export {