pivotkit-react 0.2.0 → 0.4.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 (64) hide show
  1. package/CHANGELOG.md +284 -1
  2. package/README.md +1 -1
  3. package/dist/chunks/{chunk-F6MVUAQD.js → chunk-6MDAL3IO.js} +51 -3
  4. package/dist/chunks/{chunk-53ZMK4BH.js → chunk-EM23V5GH.js} +6 -0
  5. package/dist/chunks/{chunk-LQCWFJBS.js → chunk-LEN5RPBM.js} +147 -26
  6. package/dist/chunks/{chunk-OYY4BKIL.js → chunk-RWYHJRQO.js} +6 -0
  7. package/dist/chunks/{chunk-QBD4FOBB.js → chunk-WB4GKWFQ.js} +124 -18
  8. package/dist/chunks/chunk-XN55BQ4M.js +618 -0
  9. package/dist/chunks/{chunk-X7H7BAVT.js → chunk-YITKWZ4L.js} +312 -628
  10. package/dist/chunks/chunk-ZYEYZSYL.js +187 -0
  11. package/dist/chunks/{unused-texts-YTNJCFFC.js → unused-texts-K3VFH65P.js} +1 -1
  12. package/dist/chunks/{unused-texts-de-SGOHV4N7.js → unused-texts-de-OW4TGIVX.js} +1 -1
  13. package/dist/import-ui.js +769 -0
  14. package/dist/import-worker.js +20 -0
  15. package/dist/index.js +653 -227
  16. package/dist/labels.js +14 -10
  17. package/dist/menu-texts-de.js +1 -1
  18. package/dist/menus.js +2499 -676
  19. package/dist/styles.css +673 -125
  20. package/package.json +3 -2
  21. package/types/chip-menus.d.ts +20 -4
  22. package/types/data-history.d.ts +85 -0
  23. package/types/data-keep.d.ts +51 -0
  24. package/types/data-menu.d.ts +11 -0
  25. package/types/dnd.d.ts +8 -4
  26. package/types/dom.d.ts +40 -7
  27. package/types/field-info.d.ts +32 -0
  28. package/types/filter-level.d.ts +16 -0
  29. package/types/filter.d.ts +31 -0
  30. package/types/help.d.ts +0 -7
  31. package/types/import-host.d.ts +53 -0
  32. package/types/import-labels.d.ts +360 -0
  33. package/types/import-module.d.ts +2 -0
  34. package/types/import-run.d.ts +73 -0
  35. package/types/import-source.d.ts +32 -0
  36. package/types/import-steps.d.ts +121 -0
  37. package/types/import-ui.d.ts +108 -0
  38. package/types/import-worker.d.ts +1 -0
  39. package/types/index.d.ts +56 -4
  40. package/types/labels.d.ts +97 -2
  41. package/types/lazy-import.d.ts +4 -0
  42. package/types/lazy-menus.d.ts +2 -2
  43. package/types/levels.d.ts +106 -0
  44. package/types/menu-fields.d.ts +80 -0
  45. package/types/menu-labels.d.ts +214 -22
  46. package/types/menu-ops.d.ts +150 -9
  47. package/types/menu-topics.d.ts +291 -0
  48. package/types/menus.d.ts +2 -1
  49. package/types/names.d.ts +141 -1
  50. package/types/overflow.d.ts +29 -17
  51. package/types/place.d.ts +44 -0
  52. package/types/popover.d.ts +47 -5
  53. package/types/section.d.ts +8 -11
  54. package/types/tips.d.ts +1 -36
  55. package/types/toasts.d.ts +1 -1
  56. package/types/toolbar-panels.d.ts +17 -9
  57. package/types/unused-keep.d.ts +20 -0
  58. package/types/unused-texts.d.ts +6 -0
  59. package/types/unused.d.ts +1 -0
  60. package/types/use-view-history.d.ts +13 -4
  61. package/types/view-ops.d.ts +12 -0
  62. package/types/virtual.d.ts +15 -0
  63. package/types/zones.d.ts +5 -4
  64. package/types/sections.d.ts +0 -2
package/dist/index.js CHANGED
@@ -5,24 +5,17 @@ import {
5
5
  DRILL_LIMIT,
6
6
  FIELDS_COLLAPSED,
7
7
  HelpContext,
8
- Icon,
9
8
  InfoButton,
10
- LayerContext,
11
9
  MAX_CATEGORIES,
12
- MenuButton,
13
10
  NO_EXPLANATIONS,
14
- Option,
15
- Popover,
16
- TYPE_ICON,
17
11
  ZONES,
18
- ZONE_ICON,
19
- activeIn,
20
12
  activeTips,
21
13
  addField,
22
14
  allowedTips,
23
15
  chartPlan,
24
16
  chartTypeOf,
25
17
  cleanDismissed,
18
+ dateSpan,
26
19
  drillRows,
27
20
  fieldAction,
28
21
  fieldsCollapsed,
@@ -33,12 +26,15 @@ import {
33
26
  headerSortState,
34
27
  headerSortTarget,
35
28
  helpSwitch,
29
+ importNow,
36
30
  isEmptyView,
31
+ itemRuleText,
37
32
  keptOnReset,
38
33
  layoutSummary,
39
34
  linkNow,
40
35
  linkParam,
41
36
  loadCheck,
37
+ loadImport,
42
38
  loadLink,
43
39
  localStore,
44
40
  moveField,
@@ -51,9 +47,7 @@ import {
51
47
  readStoredView,
52
48
  refLabel,
53
49
  removeAt,
54
- rootOf,
55
50
  rowFolding,
56
- sectionOpen,
57
51
  selectedItems,
58
52
  setChart,
59
53
  setChartDisplay,
@@ -72,21 +66,33 @@ import {
72
66
  tipContext,
73
67
  tipText,
74
68
  toggleCollapsed,
75
- useIsoLayoutEffect,
76
- useModal,
77
69
  valueConditionText,
78
70
  valueLabel,
79
71
  viewFromObject,
80
72
  withHostOrders,
81
- withSection,
82
73
  withoutFilters,
83
74
  writeDismissed,
84
75
  writeItem,
85
76
  writeStoredView,
86
77
  zoneOverLimit
87
- } from "./chunks/chunk-X7H7BAVT.js";
78
+ } from "./chunks/chunk-YITKWZ4L.js";
79
+ import {
80
+ FormNameContext,
81
+ Group,
82
+ Icon,
83
+ LayerContext,
84
+ MenuButton,
85
+ Option,
86
+ Popover,
87
+ TYPE_ICON,
88
+ ZONE_ICON,
89
+ activeIn,
90
+ rootOf,
91
+ tabStops,
92
+ useIsoLayoutEffect,
93
+ useModal
94
+ } from "./chunks/chunk-XN55BQ4M.js";
88
95
  import {
89
- LABELS,
90
96
  MENU_TEXTS,
91
97
  errorText,
92
98
  fill,
@@ -94,10 +100,11 @@ import {
94
100
  messageOf,
95
101
  plural,
96
102
  resolveLabels
97
- } from "./chunks/chunk-F6MVUAQD.js";
103
+ } from "./chunks/chunk-6MDAL3IO.js";
98
104
 
99
105
  // src/PivotReport.jsx
100
106
  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";
107
+ import { flushSync } from "react-dom";
101
108
  import { computePivot, emptyView as emptyView2, encode, fieldLabel as fieldLabel5, normalize as normalize2, suggestDateUnit, toGrid, toSeries, viewFields } from "pivotkit-core";
102
109
 
103
110
  // src/chart.jsx
@@ -440,9 +447,18 @@ function PivotDnd({ labels, onDrop, onDragStart, renderOverlay, children }) {
440
447
  /* @__PURE__ */ React2.createElement(DragOverlay, { dropAnimation: reduced ? null : { duration: 160, easing: "cubic-bezier(.2,.8,.2,1)" }, zIndex: 1e3 }, active ? renderOverlay(active) : null)
441
448
  );
442
449
  }
450
+ function ownEventsOnly(listener) {
451
+ return (event) => {
452
+ if (event.currentTarget instanceof Node && event.target instanceof Node && !event.currentTarget.contains(event.target)) {
453
+ return;
454
+ }
455
+ listener(event);
456
+ };
457
+ }
443
458
  function split(listeners2) {
444
- const { onKeyDown, ...pointer } = listeners2 ?? {};
445
- return { pointer, keyboard: onKeyDown ? { onKeyDown } : {} };
459
+ const own2 = Object.fromEntries(Object.entries(listeners2 ?? {}).map(([name, listener]) => [name, ownEventsOnly(listener)]));
460
+ const { onKeyDown, ...pointer } = own2;
461
+ return { pointer, keyboard: listeners2?.onKeyDown ? { onKeyDown } : {} };
446
462
  }
447
463
  function useDragSource(id, source, disabled = false) {
448
464
  const { setNodeRef, setActivatorNodeRef, attributes, listeners: listeners2, isDragging } = useDraggable({ id, data: source, disabled });
@@ -551,6 +567,43 @@ function fieldMatches(field, query, info) {
551
567
  }
552
568
  return [field, info?.label, info?.description].some((t) => typeof t === "string" && t.toLowerCase().includes(query));
553
569
  }
570
+ var IDENTIFIER_WORDS = Object.freeze(["id", "nr", "no", "number", "key", "#"]);
571
+ function isIdentifierName(name) {
572
+ const words = String(name).replace(/(\s*\([^()]*\))+\s*$/, "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Za-z])(\d)/g, "$1 $2").replace(/#/g, " # ").split(/[\s_.\-/:()]+/).filter(Boolean);
573
+ while (words.length > 1 && /^\d+$/.test(words[words.length - 1])) {
574
+ words.pop();
575
+ }
576
+ const last = words[words.length - 1];
577
+ return last !== void 0 && IDENTIFIER_WORDS.includes(last.toLowerCase());
578
+ }
579
+ var identifierColumns = /* @__PURE__ */ new WeakMap();
580
+ function isIdentifier(column) {
581
+ if (!column || column.type !== "number" || column.derived || !isIdentifierName(column.name)) {
582
+ return false;
583
+ }
584
+ const known = identifierColumns.get(column);
585
+ if (known !== void 0) {
586
+ return known;
587
+ }
588
+ let whole = true;
589
+ for (let i = 0; i < column.dict.length && whole; i++) {
590
+ whole = Number.isInteger(column.dict[i]);
591
+ }
592
+ identifierColumns.set(column, whole);
593
+ return whole;
594
+ }
595
+ function fieldDefaultsFor(fieldDefaults, field, column) {
596
+ const key = isObject(fieldDefaults) ? Object.keys(
597
+ /** @type {object} */
598
+ fieldDefaults
599
+ ).find((k) => k.toLowerCase() === String(field).toLowerCase()) : void 0;
600
+ const host = key === void 0 ? void 0 : own(fieldDefaults, key);
601
+ const set = ["agg", "format", "drillFormat"].some((k) => own(host, k) !== void 0);
602
+ if (set || !isIdentifier(column)) {
603
+ return isObject(host) ? host : void 0;
604
+ }
605
+ return { ...isObject(host) ? host : {}, agg: "count", drillFormat: "text" };
606
+ }
554
607
 
555
608
  // src/fields.jsx
556
609
  import React3, { useCallback, useEffect as useEffect2, useId as useId2, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
@@ -620,7 +673,7 @@ function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info,
620
673
  "aria-description": info ? void 0 : action.description || void 0,
621
674
  "aria-describedby": info ? describedBy : void 0
622
675
  },
623
- /* @__PURE__ */ React3.createElement("span", { className: "pk-field-title", title: name }, name)
676
+ /* @__PURE__ */ React3.createElement("span", { className: "pk-field-title", title: name }, wordsOf(name))
624
677
  ), info ? /* @__PURE__ */ React3.createElement("span", { id: describedBy, className: "pk-sr" }, [action.description, info.description].filter(Boolean).join(". ")) : null, zones.length ? /* @__PURE__ */ React3.createElement("span", { className: "pk-badges", "aria-hidden": "true" }, zones.map((z) => /* @__PURE__ */ React3.createElement("span", { key: z, className: `pk-badge pk-badge-${z}`, "aria-hidden": "true", title: fill(labels.inZone, { zone: labels.zones[z] }) }, /* @__PURE__ */ React3.createElement(Icon, { name: (
625
678
  /** @type {any} */
626
679
  ZONE_ICON[z]
@@ -650,6 +703,9 @@ function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info,
650
703
  labels.filter
651
704
  ) : null)));
652
705
  }
706
+ function wordsOf(name) {
707
+ return name.split(/(\s+)/).map((part, i) => i % 2 === 1 ? " " : part ? /* @__PURE__ */ React3.createElement("span", { key: i, className: "pk-word" }, part) : null);
708
+ }
653
709
  function FieldPanel({ fields, placed, labels, onAdd, onNote, onFilter, drawer, open, onClose, nameOf, info, showInfo = true, onSkip, collapsed = false, onCollapse }) {
654
710
  const [query, setQuery] = useState3("");
655
711
  const active = useActiveDrag();
@@ -854,11 +910,11 @@ function MenuPanel({ name, loadingText, props }) {
854
910
  useEffect3(() => onMenuTexts(() => setLoads((n) => n + 1)), []);
855
911
  const mod = menusNow(lang);
856
912
  const current = mod && labels ? mod.menuLabels(labels) : null;
857
- const [kept, setKept] = useState4(
913
+ const [kept2, setKept] = useState4(
858
914
  /** @type {any} */
859
915
  null
860
916
  );
861
- if (current && current !== kept) {
917
+ if (current && current !== kept2) {
862
918
  setKept(current);
863
919
  }
864
920
  const [failed, setFailed] = useState4(false);
@@ -901,14 +957,14 @@ function MenuPanel({ name, loadingText, props }) {
901
957
  focusFirst(box.current);
902
958
  }
903
959
  }, [mod, failed]);
904
- const shown = mod ?? (kept ? menusNow() : null);
960
+ const shown = mod ?? (kept2 ? menusNow() : null);
905
961
  const Panel = shown ? (
906
962
  /** @type {any} */
907
963
  shown[name]
908
964
  ) : null;
909
965
  return /* @__PURE__ */ React4.createElement("div", { className: "pk-menu-panel", ref: box }, Panel ? (
910
966
  // the menus' own texts (menu-labels.js) come with them, under the report's labels
911
- /* @__PURE__ */ React4.createElement(Panel, { ...props, labels: current ?? kept ?? labels })
967
+ /* @__PURE__ */ React4.createElement(Panel, { ...props, labels: current ?? kept2 ?? labels })
912
968
  ) : 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(
913
969
  "button",
914
970
  {
@@ -985,9 +1041,72 @@ function rowLabelOf(grid, r) {
985
1041
  }
986
1042
  return texts.join(" / ");
987
1043
  }
1044
+ function longestLabels(grid, col, n) {
1045
+ const out = [];
1046
+ if (n < 1) {
1047
+ return out;
1048
+ }
1049
+ for (let r = grid.headerRows; r < grid.rows.length; r++) {
1050
+ const cell = grid.rows[r][col];
1051
+ if (!cell || cell.kind !== "rowHeader" || !cell.text || (cell.colSpan ?? 1) > 1) {
1052
+ continue;
1053
+ }
1054
+ if (out.length === n && cell.text.length <= out[n - 1].text.length) {
1055
+ continue;
1056
+ }
1057
+ const entry = { text: cell.text, toggle: Boolean(cell.toggle), total: Boolean(cell.total) };
1058
+ let at = out.length;
1059
+ while (at > 0 && out[at - 1].text.length < entry.text.length) {
1060
+ at--;
1061
+ }
1062
+ out.splice(at, 0, entry);
1063
+ if (out.length > n) {
1064
+ out.pop();
1065
+ }
1066
+ }
1067
+ return out;
1068
+ }
988
1069
 
989
1070
  // src/table.jsx
990
1071
  var totalClass = (t) => t === 2 ? " pk-grand" : t === 1 ? " pk-sub" : "";
1072
+ var MEASURED_LABELS = 50;
1073
+ var LABEL_MAX_EM = 28;
1074
+ var LABEL_SLACK = 2;
1075
+ function labelWidths(grid, table) {
1076
+ const text = table.querySelector("tbody th.pk-rowHeader .pk-th-text");
1077
+ const content = text?.parentElement;
1078
+ if (!text || !content) {
1079
+ return null;
1080
+ }
1081
+ const probe = table.ownerDocument.createElement("span");
1082
+ probe.className = "pk-th-text";
1083
+ probe.setAttribute("aria-hidden", "true");
1084
+ Object.assign(probe.style, { position: "absolute", visibility: "hidden", whiteSpace: "pre", width: "auto", minWidth: "0", maxWidth: "none", overflow: "visible" });
1085
+ content.append(probe);
1086
+ try {
1087
+ const widthOf = (l) => {
1088
+ probe.style.fontWeight = l.total ? "700" : "";
1089
+ probe.textContent = l.text;
1090
+ return probe.getBoundingClientRect().width;
1091
+ };
1092
+ const em = parseFloat(getComputedStyle(text).fontSize) || 14;
1093
+ const toggle = table.querySelector(".pk-toggle");
1094
+ const gap = parseFloat(getComputedStyle(content).columnGap) || 0;
1095
+ const toggleWidth = (toggle ? toggle.getBoundingClientRect().width : em * 1.7) + gap;
1096
+ const widths = [];
1097
+ for (let c = 0; c < grid.rowHeaderColumns; c++) {
1098
+ const most = Math.max(0, ...longestLabels(grid, c, MEASURED_LABELS).map((l) => widthOf(l) + (l.toggle ? toggleWidth : 0)));
1099
+ widths.push(Math.min(Math.ceil(most) + LABEL_SLACK, LABEL_MAX_EM * em));
1100
+ }
1101
+ return widths;
1102
+ } finally {
1103
+ probe.remove();
1104
+ }
1105
+ }
1106
+ var fontOf = (table) => {
1107
+ const s = getComputedStyle(table);
1108
+ return `${s.fontFamily}|${s.fontSize}|${s.fontWeight}`;
1109
+ };
991
1110
  function conditionalStyle(cell) {
992
1111
  const s = cell.style;
993
1112
  if (!s) {
@@ -1052,6 +1171,12 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1052
1171
  /** @type {{ r: number, c: number } | null} */
1053
1172
  null
1054
1173
  );
1174
+ const [labelsWide, setLabelsWide] = useState5(
1175
+ /** @type {{ grid: unknown, font: string, fonts: number, widths: number[] } | null} */
1176
+ null
1177
+ );
1178
+ const [fontsLoaded, setFontsLoaded] = useState5(0);
1179
+ const fixedWidths = virtual && labelsWide?.grid === grid ? labelsWide.widths : null;
1055
1180
  const focusNext = useRef4(false);
1056
1181
  const [sortNote, setSortNote] = useState5("");
1057
1182
  const focusToggle = useRef4(
@@ -1065,6 +1190,35 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1065
1190
  },
1066
1191
  [toggleGroup]
1067
1192
  );
1193
+ useIsoLayoutEffect(() => {
1194
+ const t = table.current;
1195
+ if (!virtual || !t) {
1196
+ return;
1197
+ }
1198
+ const font = fontOf(t);
1199
+ if (labelsWide?.grid !== grid || labelsWide.font !== font || labelsWide.fonts !== fontsLoaded) {
1200
+ const widths = labelWidths(grid, t);
1201
+ if (widths) {
1202
+ setLabelsWide({ grid, font, fonts: fontsLoaded, widths });
1203
+ }
1204
+ }
1205
+ });
1206
+ useEffect4(() => {
1207
+ const fonts = virtual ? table.current?.ownerDocument.fonts : void 0;
1208
+ if (!fonts) {
1209
+ return void 0;
1210
+ }
1211
+ let live = true;
1212
+ const loaded3 = () => live && setFontsLoaded((n) => n + 1);
1213
+ fonts.addEventListener?.("loadingdone", loaded3);
1214
+ if (fonts.status === "loading") {
1215
+ fonts.ready.then(loaded3, () => void 0);
1216
+ }
1217
+ return () => {
1218
+ live = false;
1219
+ fonts.removeEventListener?.("loadingdone", loaded3);
1220
+ };
1221
+ }, [virtual]);
1068
1222
  useIsoLayoutEffect(() => {
1069
1223
  const t = table.current;
1070
1224
  if (!t) {
@@ -1089,7 +1243,7 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1089
1243
  }
1090
1244
  setLefts((old) => old.length === xs.length && old.every((v, i) => Math.abs(v - xs[i]) < 0.5) ? old : xs);
1091
1245
  }
1092
- }, [grid, version, width]);
1246
+ }, [grid, version, width, fixedWidths]);
1093
1247
  useEffect4(() => {
1094
1248
  const el = wrap.current;
1095
1249
  if (!el) {
@@ -1102,6 +1256,9 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1102
1256
  update();
1103
1257
  const ro = typeof ResizeObserver === "function" ? new ResizeObserver(update) : null;
1104
1258
  ro?.observe(el);
1259
+ if (table.current) {
1260
+ ro?.observe(table.current);
1261
+ }
1105
1262
  return () => ro?.disconnect();
1106
1263
  }, []);
1107
1264
  const head = headHeight || rowHeight * grid.headerRows;
@@ -1242,7 +1399,7 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1242
1399
  };
1243
1400
  const bodyCell = ({ cell, col, rowSpan, colSpan }, r) => {
1244
1401
  if (cell.kind === "rowHeader") {
1245
- return /* @__PURE__ */ React6.createElement("th", { key: col, scope: "row", className: `pk-th pk-rowHeader pk-sticky${totalClass(cell.total)}${rowSpan > 1 ? " pk-span" : ""}`, style: stickyStyle(col), rowSpan: rowSpan > 1 ? rowSpan : void 0, colSpan: colSpan > 1 ? colSpan : void 0, title: virtual ? cell.text : void 0, onClick: showRowLabel ? () => showRowLabel(r, rowSpan) : void 0 }, /* @__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)));
1402
+ return /* @__PURE__ */ React6.createElement("th", { key: col, scope: "row", className: `pk-th pk-rowHeader pk-sticky${totalClass(cell.total)}${rowSpan > 1 ? " pk-span" : ""}`, style: stickyStyle(col), rowSpan: rowSpan > 1 ? rowSpan : void 0, colSpan: colSpan > 1 ? colSpan : void 0, title: virtual ? cell.text : void 0, onClick: showRowLabel ? () => showRowLabel(r, rowSpan) : void 0 }, /* @__PURE__ */ React6.createElement("span", { className: "pk-th-content", style: fixedWidths && colSpan <= 1 && fixedWidths[col] !== void 0 ? { width: fixedWidths[col] } : void 0 }, 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)));
1246
1403
  }
1247
1404
  const isValue = cell.valueIndex !== void 0;
1248
1405
  const clickable = isValue && drillable(cell);
@@ -1305,6 +1462,7 @@ function useToasts() {
1305
1462
  if (toast.tone !== "error" && !paused.current) {
1306
1463
  arm(id);
1307
1464
  }
1465
+ return id;
1308
1466
  },
1309
1467
  [arm]
1310
1468
  );
@@ -1443,7 +1601,7 @@ import React9, { useEffect as useEffect7, useMemo as useMemo4, useRef as useRef7
1443
1601
  import { fieldLabel as fieldLabel3 } from "pivotkit-core";
1444
1602
 
1445
1603
  // src/unused-load.js
1446
- var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-SGOHV4N7.js").then((m) => m.de) });
1604
+ var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-OW4TGIVX.js").then((m) => m.de) });
1447
1605
  var pending2 = /* @__PURE__ */ new Map();
1448
1606
  var loaded2 = /* @__PURE__ */ new Map();
1449
1607
  var unusedNow = (lang) => loaded2.get(lang) ?? null;
@@ -1451,7 +1609,7 @@ function loadUnused(lang) {
1451
1609
  let p = pending2.get(lang);
1452
1610
  if (!p) {
1453
1611
  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(
1612
+ p = Promise.all([import("./chunks/unused-texts-K3VFH65P.js"), own2]).then(
1455
1613
  ([mod, texts]) => {
1456
1614
  const out = { mod, lang: texts };
1457
1615
  loaded2.set(lang, out);
@@ -1476,7 +1634,6 @@ function unusedTexts(loaded3, labels) {
1476
1634
 
1477
1635
  // src/unused.jsx
1478
1636
  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
1637
  function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow, quiet }) {
1481
1638
  const lang = labels.lang;
1482
1639
  const show = notes.length > 0 && !dismissed;
@@ -1529,7 +1686,7 @@ function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow,
1529
1686
  const dismiss = () => {
1530
1687
  const el = box.current;
1531
1688
  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;
1689
+ const next = el && root ? tabStops(root).find((c) => !el.contains(c) && el.compareDocumentPosition(c) & Node.DOCUMENT_POSITION_FOLLOWING) : null;
1533
1690
  onDismiss(
1534
1691
  /** @type {HTMLElement | null} */
1535
1692
  next ?? null
@@ -1545,49 +1702,87 @@ function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow,
1545
1702
  })), 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
1703
  }
1547
1704
 
1705
+ // src/unused-keep.js
1706
+ var PATH = /^([A-Za-z]+)(?:\[(\d+)\])?(?:\.([A-Za-z]+))?/;
1707
+ var lower = (v) => typeof v === "string" ? v.toLowerCase() : v;
1708
+ var isObject2 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
1709
+ function partOf(path, raw, view) {
1710
+ const m = PATH.exec(path ?? "");
1711
+ if (!m) {
1712
+ return JSON.stringify(view);
1713
+ }
1714
+ const [, key, index, sub] = m;
1715
+ const section = Object.hasOwn(view, key) ? view[key] : void 0;
1716
+ if (key === "values" && index !== void 0 && Array.isArray(section)) {
1717
+ const given = isObject2(raw) && Array.isArray(
1718
+ /** @type {any} */
1719
+ raw.values
1720
+ ) ? (
1721
+ /** @type {any} */
1722
+ raw.values[Number(index)]
1723
+ ) : void 0;
1724
+ const match = isObject2(given) ? section.find((v) => lower(v.field ?? null) === lower(given.field ?? null) && lower(v.agg) === lower(given.agg)) : void 0;
1725
+ if (match) {
1726
+ return JSON.stringify(match);
1727
+ }
1728
+ }
1729
+ if (sub !== void 0 && isObject2(section)) {
1730
+ return JSON.stringify(Object.hasOwn(section, sub) ? section[sub] : void 0);
1731
+ }
1732
+ return JSON.stringify(section);
1733
+ }
1734
+ function stillApplies(note, loaded3, shown) {
1735
+ if (!loaded3) {
1736
+ return true;
1737
+ }
1738
+ if ("issue" in note) {
1739
+ return partOf(note.issue.path, note.raw, loaded3) === partOf(note.issue.path, note.raw, shown);
1740
+ }
1741
+ return note.path === void 0 || partOf(note.path, null, loaded3) === partOf(note.path, null, shown);
1742
+ }
1743
+
1548
1744
  // src/toolbar.jsx
1549
1745
  import React10, { useCallback as useCallback4, useEffect as useEffect8, useMemo as useMemo5, useRef as useRef8, useState as useState8 } from "react";
1550
1746
 
1551
1747
  // src/overflow.js
1552
- var OVERFLOW_ORDER = Object.freeze(["reset", "layout", "options", "chartType", "views"]);
1748
+ var OVERFLOW_ORDER = Object.freeze(["layout", "options", "chartType", "data", "startOver", "views"]);
1749
+ var MORE_GROUPS = Object.freeze([Object.freeze(["startOver"]), Object.freeze(["layout", "chartType", "options"]), Object.freeze(["data"]), Object.freeze(["views"])]);
1553
1750
  var TOOLBAR_ROOM = Object.freeze({
1554
- // measured in Chromium at the playground's font: the longer of English and German with the gap
1555
- // after it, plus 2 %; a wider font still fits, as useOverflow measures as well
1556
1751
  fields: 6.4,
1557
1752
  display: 15.3,
1558
1753
  chartType: 12.9,
1559
1754
  sep: 1,
1560
1755
  undo: 8.75,
1561
1756
  redo: 9.15,
1562
- reset: 9.65,
1757
+ startOver: 10.9,
1563
1758
  layout: 8.4,
1564
1759
  options: 8.75,
1760
+ data: 7.4,
1565
1761
  views: 9.1,
1566
1762
  export: 7.5,
1567
1763
  more: 7.2
1568
1764
  });
1569
- var TEXT_BUTTONS = Object.freeze(["fields", "undo", "redo", "reset", "layout"]);
1570
- var MENU_BUTTONS = Object.freeze(["chartType", "options", "views", "export", "more"]);
1571
- function toolbarTexts(sets) {
1572
- const out = (
1765
+ var TEXT_BUTTONS = Object.freeze(["fields", "undo", "redo", "layout"]);
1766
+ var MENU_BUTTONS = Object.freeze(["chartType", "startOver", "options", "data", "views", "export", "more"]);
1767
+ function toolbarTexts(labels) {
1768
+ const text = (v) => typeof v === "string" ? v : "";
1769
+ return (
1573
1770
  /** @type {any} */
1574
- { fields: [], undo: [], redo: [], reset: [], layout: [], chartType: [], options: [], views: [], export: [], more: [], display: [] }
1771
+ {
1772
+ fields: [text(labels.showFields)],
1773
+ undo: [text(labels.undo)],
1774
+ redo: [text(labels.redo)],
1775
+ startOver: [text(labels.startOver)],
1776
+ layout: [text(labels.layout)],
1777
+ options: [text(labels.options)],
1778
+ views: [text(labels.views)],
1779
+ data: [text(labels.data)],
1780
+ export: [text(labels.exportLabel)],
1781
+ more: [text(labels.more)],
1782
+ chartType: Object.values(labels.chartTypes ?? {}).map(text),
1783
+ display: [[text(labels.table), text(labels.chart)]]
1784
+ }
1575
1785
  );
1576
- const text = (v) => typeof v === "string" ? v : "";
1577
- for (const l of sets) {
1578
- out.fields.push(text(l.showFields));
1579
- out.undo.push(text(l.undo));
1580
- out.redo.push(text(l.redo));
1581
- out.reset.push(text(l.reset));
1582
- out.layout.push(text(l.layout));
1583
- out.options.push(text(l.options));
1584
- out.views.push(text(l.views));
1585
- out.export.push(text(l.exportLabel));
1586
- out.more.push(text(l.more));
1587
- out.chartType.push(...Object.values(l.chartTypes ?? {}).map(text));
1588
- out.display.push([text(l.table), text(l.chart)]);
1589
- }
1590
- return out;
1591
1786
  }
1592
1787
  function toolbarRoom(texts, measure, chrome) {
1593
1788
  const widest = (list, kind = "button") => Math.max(0, ...list.map((t) => measure(t, kind)));
@@ -1604,14 +1799,22 @@ function toolbarRoom(texts, measure, chrome) {
1604
1799
  room.display = chrome.display + Math.max(0, ...texts.display.map(([a, b]) => measure(a, "display") + measure(b, "display"))) + chrome.gap;
1605
1800
  return room;
1606
1801
  }
1607
- function overflowLevel(width, narrow, room = TOOLBAR_ROOM) {
1802
+ function overflowHidden(width, narrow, present, room = TOOLBAR_ROOM) {
1608
1803
  const fixed = (narrow ? room.fields : 0) + room.display + room.sep + room.undo + room.redo + room.export;
1609
- let level = 0;
1610
- const need = (n) => fixed + OVERFLOW_ORDER.slice(n).reduce((sum, id) => sum + room[id], 0) + (n > 0 ? room.more : 0);
1611
- while (level < OVERFLOW_ORDER.length && need(level) > width) {
1612
- level += 1;
1804
+ const order = OVERFLOW_ORDER.filter((id) => present.includes(id));
1805
+ const need = (shown2) => fixed + shown2.reduce((sum, id) => sum + (room[id] ?? 0), 0) + (shown2.length < order.length ? room.more : 0);
1806
+ let shown = order;
1807
+ while (shown.length && need(shown) > width) {
1808
+ shown = shown.slice(1);
1809
+ }
1810
+ const gone = order.filter((id) => !shown.includes(id));
1811
+ for (const id of gone.reverse()) {
1812
+ const next = order.filter((o) => o === id || shown.includes(o));
1813
+ if (need(next) <= width) {
1814
+ shown = next;
1815
+ }
1613
1816
  }
1614
- return level;
1817
+ return order.filter((id) => !shown.includes(id));
1615
1818
  }
1616
1819
 
1617
1820
  // src/toolbar.jsx
@@ -1619,7 +1822,7 @@ function TextButton({ icon, label, onClick, disabled, testId, shortcut }) {
1619
1822
  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));
1620
1823
  }
1621
1824
  var measuring;
1622
- var fontOf = (style) => `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
1825
+ var fontOf2 = (style) => `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
1623
1826
  function measuredRoom(el, texts) {
1624
1827
  const doc = el.ownerDocument;
1625
1828
  if (measuring === void 0) {
@@ -1641,10 +1844,10 @@ function measuredRoom(el, texts) {
1641
1844
  if (!view) {
1642
1845
  return null;
1643
1846
  }
1644
- const fonts = { button: fontOf(view.getComputedStyle(
1847
+ const fonts = { button: fontOf2(view.getComputedStyle(
1645
1848
  /** @type {Element} */
1646
1849
  textOf(undo2)
1647
- )), display: fontOf(view.getComputedStyle(
1850
+ )), display: fontOf2(view.getComputedStyle(
1648
1851
  /** @type {Element} */
1649
1852
  textOf(display)
1650
1853
  )) };
@@ -1667,14 +1870,20 @@ function measuredRoom(el, texts) {
1667
1870
  };
1668
1871
  return toolbarRoom(texts, measure, chrome);
1669
1872
  }
1670
- function useOverflow(ref, key, narrow, max, texts) {
1671
- const [level, setLevel] = useState8(0);
1873
+ function useOverflow(ref, key, narrow, present, texts) {
1874
+ const [decided, setDecided] = useState8(
1875
+ /** @type {string[]} */
1876
+ []
1877
+ );
1878
+ const [extra, setExtra] = useState8(0);
1672
1879
  const [measure, setMeasure] = useState8(0);
1673
1880
  const [lastKey, setLastKey] = useState8(key);
1674
- const latest = useRef8(texts);
1881
+ const latest = useRef8({ texts, present });
1882
+ const waiting = useRef8(false);
1675
1883
  useIsoLayoutEffect(() => {
1676
- latest.current = texts;
1884
+ latest.current = { texts, present };
1677
1885
  });
1886
+ const isOpen = (el) => Boolean(el.querySelector('[aria-expanded="true"]'));
1678
1887
  if (key !== lastKey) {
1679
1888
  setLastKey(key);
1680
1889
  setMeasure((m) => m + 1);
@@ -1686,9 +1895,16 @@ function useOverflow(ref, key, narrow, max, texts) {
1686
1895
  }
1687
1896
  let width = -1;
1688
1897
  const decide = () => {
1898
+ if (isOpen(el)) {
1899
+ waiting.current = true;
1900
+ return;
1901
+ }
1902
+ waiting.current = false;
1689
1903
  const em = parseFloat(getComputedStyle(el).fontSize) || 14;
1690
- const room = measuredRoom(el, latest.current);
1691
- setLevel(room ? overflowLevel(width, narrow, room) : overflowLevel(width / em, narrow));
1904
+ const room = measuredRoom(el, latest.current.texts);
1905
+ const own2 = latest.current.present;
1906
+ setDecided(room ? overflowHidden(width, narrow, own2, room) : overflowHidden(width / em, narrow, own2));
1907
+ setExtra(0);
1692
1908
  setMeasure((m) => m + 1);
1693
1909
  };
1694
1910
  const ro = new ResizeObserver(([entry]) => {
@@ -1701,23 +1917,29 @@ function useOverflow(ref, key, narrow, max, texts) {
1701
1917
  width = Math.round(el.getBoundingClientRect().width);
1702
1918
  decide();
1703
1919
  ro.observe(el);
1920
+ const mo = typeof MutationObserver === "function" ? new MutationObserver(() => waiting.current && decide()) : null;
1921
+ mo?.observe(el, { subtree: true, attributes: true, attributeFilter: ["aria-expanded"] });
1704
1922
  let live = true;
1705
1923
  el.ownerDocument.fonts?.ready.then(() => live && width >= 0 && decide(), () => void 0);
1706
1924
  return () => {
1707
1925
  live = false;
1708
1926
  ro.disconnect();
1927
+ mo?.disconnect();
1709
1928
  };
1710
1929
  }, [ref, narrow, key]);
1930
+ const order = OVERFLOW_ORDER.filter((id) => present.includes(id));
1931
+ const shown = order.filter((id) => !decided.includes(id));
1932
+ const more = shown.slice(0, extra);
1711
1933
  useIsoLayoutEffect(() => {
1712
1934
  const el = ref.current;
1713
- if (el && el.scrollWidth > el.clientWidth + 1 && level < max) {
1714
- setLevel(level + 1);
1935
+ if (el && !isOpen(el) && el.scrollWidth > el.clientWidth + 1 && extra < shown.length) {
1936
+ setExtra(extra + 1);
1715
1937
  }
1716
- }, [ref, level, measure, key, max]);
1717
- return level;
1938
+ }, [ref, extra, measure, key, shown.length]);
1939
+ return order.filter((id) => decided.includes(id) || more.includes(id));
1718
1940
  }
1719
1941
  function Toolbar(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;
1942
+ const { view, labels, size, canUndo, canRedo, canReset, startEmpty, canNew, onUndo, onRedo, onReset, onNew, loadedView, empty, onDisplay, onChart, onChartDisplay, onTotal, onExpand, onCollapse, folding, templates, onLoadTemplate, templateActions, onExport, chartReady, onShowFields, layoutFolded, onLayout, zonesId, share } = props;
1721
1943
  const tips = { controls: props.tipsControls, on: props.tipsOn, onOn: props.onTipsOn, canReset: props.canResetTips, onReset: props.onResetTips };
1722
1944
  const bar = useRef8(
1723
1945
  /** @type {HTMLDivElement | null} */
@@ -1732,34 +1954,11 @@ function Toolbar(props) {
1732
1954
  null
1733
1955
  );
1734
1956
  const [panel, setPanel] = useState8(
1735
- /** @type {"options" | "views" | "chartType" | null} */
1957
+ /** @type {"options" | "views" | "chartType" | "data" | null} */
1736
1958
  null
1737
1959
  );
1738
- const order = OVERFLOW_ORDER;
1739
- const texts = useMemo5(() => toolbarTexts([LABELS.en, LABELS.de, labels]), [labels]);
1740
- const level = useOverflow(bar, `${labels.lang}:${labels.undo}:${size}`, size === "narrow", order.length, texts);
1741
- const hidden = new Set(order.slice(0, level));
1742
- if (panel && !hidden.has(panel)) {
1743
- setPanel(null);
1744
- }
1745
- const closePanel = useCallback4(() => setPanel(null), []);
1746
- const request = props.viewsRequest ?? 0;
1747
- const [seenRequest, setSeenRequest] = useState8(request);
1748
- const [clickFor, setClickFor] = useState8(0);
1749
- if (request !== seenRequest) {
1750
- setSeenRequest(request);
1751
- if (hidden.has("views")) {
1752
- setPanel("views");
1753
- } else {
1754
- setClickFor(request);
1755
- }
1756
- }
1757
- useEffect8(() => {
1758
- const button = viewsButton.current;
1759
- if (clickFor > 0 && button && button.getAttribute("aria-expanded") !== "true") {
1760
- button.click();
1761
- }
1762
- }, [clickFor]);
1960
+ const data = props.data;
1961
+ const texts = useMemo5(() => toolbarTexts(labels), [labels]);
1763
1962
  const plan = props.chartPlan ?? { name: chartTypeOf(view.chart), auto: false };
1764
1963
  const preset = plan.auto ? "auto" : plan.name;
1765
1964
  const drawnIcon = CHART_TYPES[plan.name].icon;
@@ -1769,8 +1968,21 @@ function Toolbar(props) {
1769
1968
  // the panels load with the chip menus (menus.js), on demand
1770
1969
  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
1970
  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 } })
1971
+ chartType: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ChartTypePanel", loadingText: labels.loadingMenu, props: { view, plan, labels, onChart, onDisplay: onChartDisplay, close } }),
1972
+ data: (close) => data?.panel(close)
1773
1973
  };
1974
+ const loadedMark = (testId) => data?.loaded ? dot(testId, labels.dataLoaded) : null;
1975
+ const resetWhy = !canReset ? labels.resetAlready : startEmpty ? labels.resetStartEmpty : void 0;
1976
+ const startOverItems = (close, prefix) => [
1977
+ /* @__PURE__ */ React10.createElement(Option, { key: "reset", inMenu: true, icon: "reset", hint: labels.resetHint, disabled: Boolean(resetWhy), reason: resetWhy, onSelect: () => {
1978
+ close();
1979
+ onReset();
1980
+ }, testId: `${prefix}reset` }, labels.reset),
1981
+ /* @__PURE__ */ React10.createElement(Option, { key: "new", inMenu: true, icon: "newFile", hint: labels.newHint, disabled: !canNew, reason: labels.newAlready, onSelect: () => {
1982
+ close();
1983
+ onNew();
1984
+ }, testId: `${prefix}new-report` }, labels.newEmpty)
1985
+ ];
1774
1986
  const actions = {
1775
1987
  chartType: {
1776
1988
  place: "chart",
@@ -1780,19 +1992,16 @@ function Toolbar(props) {
1780
1992
  setPanel("chartType");
1781
1993
  }, testId: "more-chart-type" }, `${chartTypeText}\u2026`)
1782
1994
  },
1783
- reset: {
1995
+ startOver: {
1784
1996
  place: "history",
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: () => {
1787
- close();
1788
- onReset();
1789
- }, testId: "more-reset" }, labels.reset)
1997
+ button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "startOver", label: labels.startOver, icon: "reset", text: labels.startOver, testId: "start-over", arrowOpens: true, off: resetWhy && !canNew ? labels.newAlready : void 0 }, (close) => startOverItems(close, "")),
1998
+ entry: (close) => startOverItems(close, "more-")
1790
1999
  },
1791
2000
  layout: {
1792
2001
  place: "end",
1793
2002
  // a toggle of the zones: the same text, open or folded; aria-pressed says which
1794
2003
  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: () => {
2004
+ entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "layout", inMenu: true, checkbox: true, icon: "layout", checked: !layoutFolded, onSelect: () => {
1796
2005
  close();
1797
2006
  onLayout();
1798
2007
  }, testId: "more-layout" }, labels.layout)
@@ -1805,6 +2014,19 @@ function Toolbar(props) {
1805
2014
  setPanel("options");
1806
2015
  }, testId: "more-options" }, `${labels.options}\u2026`)
1807
2016
  },
2017
+ ...data ? {
2018
+ data: {
2019
+ place: (
2020
+ /** @type {const} */
2021
+ "end"
2022
+ ),
2023
+ button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "data", label: labels.data, icon: "file", text: labels.data, role: "dialog", align: "end", testId: "data", mark: loadedMark("data-loaded") }, panels.data),
2024
+ entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "data", inMenu: true, icon: "file", onSelect: () => {
2025
+ close();
2026
+ setPanel("data");
2027
+ }, testId: "more-data" }, `${labels.data}\u2026`, loadedMark("more-data-loaded"))
2028
+ }
2029
+ } : {},
1808
2030
  views: {
1809
2031
  place: "end",
1810
2032
  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),
@@ -1815,8 +2037,33 @@ function Toolbar(props) {
1815
2037
  }
1816
2038
  };
1817
2039
  const ORDER = Object.keys(actions);
2040
+ const present = OVERFLOW_ORDER.filter((id) => ORDER.includes(id));
2041
+ const hiddenList = useOverflow(bar, `${labels.lang}:${labels.undo}:${size}:${present.join()}`, size === "narrow", present, texts);
2042
+ const hidden = new Set(hiddenList);
2043
+ if (panel && !hidden.has(panel)) {
2044
+ setPanel(null);
2045
+ }
2046
+ const closePanel = useCallback4(() => setPanel(null), []);
2047
+ const request = props.viewsRequest ?? 0;
2048
+ const [seenRequest, setSeenRequest] = useState8(request);
2049
+ const [clickFor, setClickFor] = useState8(0);
2050
+ if (request !== seenRequest) {
2051
+ setSeenRequest(request);
2052
+ if (hidden.has("views")) {
2053
+ setPanel("views");
2054
+ } else {
2055
+ setClickFor(request);
2056
+ }
2057
+ }
2058
+ useEffect8(() => {
2059
+ const button = viewsButton.current;
2060
+ if (clickFor > 0 && button && button.getAttribute("aria-expanded") !== "true") {
2061
+ button.click();
2062
+ }
2063
+ }, [clickFor]);
1818
2064
  const buttons = (place) => ORDER.filter((id) => actions[id].place === place && !hidden.has(id)).map((id) => actions[id].button());
1819
- const changedMark = (testId) => /* @__PURE__ */ React10.createElement("span", { className: "pk-view-changed", "data-testid": testId }, /* @__PURE__ */ React10.createElement("span", { className: "pk-sr" }, labels.unsavedChanges));
2065
+ const dot = (testId, text) => /* @__PURE__ */ React10.createElement("span", { className: "pk-view-changed", "data-testid": testId }, /* @__PURE__ */ React10.createElement("span", { className: "pk-sr" }, text));
2066
+ const changedMark = (testId) => dot(testId, labels.unsavedChanges);
1820
2067
  const name = loadedView ? /* @__PURE__ */ React10.createElement(
1821
2068
  "button",
1822
2069
  {
@@ -1833,11 +2080,16 @@ function Toolbar(props) {
1833
2080
  ) : null;
1834
2081
  const end = buttons("end");
1835
2082
  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: (
2083
+ const wrap = hidden.size > 0 && hidden.size >= present.length;
2084
+ const moreGroups = (close) => MORE_GROUPS.map((group) => group.filter((id) => hidden.has(id))).flatMap(
2085
+ (ids) => ids.length ? [
2086
+ /* @__PURE__ */ React10.createElement(Group, { key: ids[0], menu: true, label: ids[0] === "startOver" ? labels.startOver : void 0 }, ids.map((id) => actions[id].entry(close)))
2087
+ ] : []
2088
+ );
2089
+ return /* @__PURE__ */ React10.createElement("div", { className: `pk-toolbar${wrap ? " pk-wrap" : ""}`, role: "toolbar", "aria-label": labels.toolbar, ref: bar, "data-overflow": hidden.size }, 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: (
1838
2090
  /** @type {any} */
1839
2091
  drawnIcon
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);
2092
+ ) }), /* @__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 } })), hidden.size > 0 ? /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.more, icon: "more", text: labels.more, align: "end", testId: "more", buttonRef: more, arrowOpens: true, mark: hidden.has("views") && loadedView?.changed ? changedMark("more-changed") : hidden.has("data") ? loadedMark("more-loaded") : null }, moreGroups) : null, wrap ? name : null, panel ? /* @__PURE__ */ React10.createElement(Popover, { open: true, anchor: more, onClose: closePanel, label: panel === "chartType" ? chartTypeText : panel === "views" ? labels.views : panel === "data" ? labels.data : labels.options, role: "dialog", align: "end", className: panel === "chartType" ? "pk-chart-menu" : void 0 }, panels[panel](closePanel)) : null);
1841
2093
  }
1842
2094
 
1843
2095
  // src/use-export.js
@@ -1951,9 +2203,9 @@ function reset(state, note) {
1951
2203
  function schemaKeyOf(encoded) {
1952
2204
  return JSON.stringify(encoded.schema.fields.map((f) => [f.name, f.type]));
1953
2205
  }
1954
- function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outsideNote, orderOf }) {
2206
+ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outsideNote, orderOf, dataKey = 0, initial: initialState = null }) {
1955
2207
  const controlled = view !== void 0;
1956
- const schema = useMemo6(() => schemaKeyOf(encoded), [encoded]);
2208
+ const schema = useMemo6(() => `${dataKey}|${schemaKeyOf(encoded)}`, [encoded, dataKey]);
1957
2209
  const json = useCallback6(
1958
2210
  (v) => {
1959
2211
  const normalized = normalize(v ?? emptyView(), encoded, { limits }).view;
@@ -1964,8 +2216,12 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
1964
2216
  );
1965
2217
  const [initial] = useState9(() => (controlled ? view : defaultView) ?? null);
1966
2218
  const start = useMemo6(() => json(initial), [json, initial]);
1967
- const [state, setState] = useState9(() => createState(schema, start));
2219
+ const [state, setState] = useState9(() => initialState ?? createState(schema, start));
1968
2220
  const viewKey = controlled ? JSON.stringify(view) : null;
2221
+ const [toldOver, setToldOver] = useState9(() => initialState ? viewKey : null);
2222
+ if (toldOver !== null && toldOver !== viewKey) {
2223
+ setToldOver(null);
2224
+ }
1969
2225
  const shown = useMemo6(() => {
1970
2226
  if (viewKey !== null) {
1971
2227
  return json(JSON.parse(viewKey));
@@ -1980,9 +2236,10 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
1980
2236
  const apply = useCallback6(
1981
2237
  (next) => {
1982
2238
  setState(next);
2239
+ setToldOver(viewKey);
1983
2240
  onViewChange?.(JSON.parse(next.present));
1984
2241
  },
1985
- [onViewChange]
2242
+ [onViewChange, viewKey]
1986
2243
  );
1987
2244
  const commit = useCallback6(
1988
2245
  (next, note, tag) => {
@@ -2025,15 +2282,43 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
2025
2282
  [live, apply]
2026
2283
  );
2027
2284
  const restore = useCallback6((next, tag = null) => apply(createState(schema, start, json(next), tag)), [schema, start, json, apply]);
2285
+ const waiting = viewKey !== null && viewKey === toldOver && state.schema === schema;
2286
+ const made = waiting ? state : live;
2287
+ const snapshot = useCallback6(() => made, [made]);
2288
+ const earlier = useCallback6(() => live.past.map((p) => JSON.parse(p.view)), [live.past]);
2028
2289
  const canUndo = live.past.length > 0;
2029
2290
  const canRedo = live.future.length > 0;
2030
2291
  const canReset = live.present !== live.start;
2292
+ const emptyKey = useMemo6(() => json(null), [json]);
2293
+ const startEmpty = live.start === emptyKey;
2031
2294
  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]
2295
+ () => ({ view: current, viewKey: shown, tag: live.tag, setTag, commit, undo: undo2, redo: redo2, reset: reset2, restore, keyOf: json, earlier, canUndo, canRedo, canReset, startEmpty, snapshot, replace: apply }),
2296
+ [current, shown, live.tag, setTag, commit, undo2, redo2, reset2, restore, json, earlier, canUndo, canRedo, canReset, startEmpty, snapshot, apply]
2034
2297
  );
2035
2298
  }
2036
2299
 
2300
+ // src/data-keep.js
2301
+ var KEPT_REPORTS = 4;
2302
+ var kept = /* @__PURE__ */ new Map();
2303
+ var hostIdentity = ({ dataKey, sourceId, schemaKey }) => JSON.stringify([sourceId ?? null, dataKey !== void 0 ? ["key", String(dataKey)] : ["columns", schemaKey]]);
2304
+ function keepData(key, entry) {
2305
+ kept.delete(key);
2306
+ kept.set(key, entry);
2307
+ while (kept.size > KEPT_REPORTS) {
2308
+ kept.delete(
2309
+ /** @type {string} */
2310
+ kept.keys().next().value
2311
+ );
2312
+ }
2313
+ }
2314
+ function forgetData(key) {
2315
+ kept.delete(key);
2316
+ }
2317
+ function keptData(key, host) {
2318
+ const entry = kept.get(key);
2319
+ return entry && entry.host === host ? entry : null;
2320
+ }
2321
+
2037
2322
  // src/use-big-result.js
2038
2323
  import { useCallback as useCallback7, useEffect as useEffect9, useRef as useRef9, useState as useState10, useSyncExternalStore as useSyncExternalStore2 } from "react";
2039
2324
  function fullScreenSupported() {
@@ -2122,20 +2407,22 @@ function measureFit(el, m, fit) {
2122
2407
  // src/zones.jsx
2123
2408
  import React11, { useCallback as useCallback8, useEffect as useEffect10, useMemo as useMemo7, useRef as useRef10, useState as useState11 } from "react";
2124
2409
  import { fieldItems, fieldLabel as fieldLabel4 } from "pivotkit-core";
2125
- function fieldState(view, field, encoded, locale) {
2410
+ function fieldState(view, field, encoded, locale, labels, sourceType) {
2126
2411
  const items = filtersOf(view, field, ["include", "exclude"]).filter((f) => f.type === "include" || f.items.length > 0);
2412
+ const compared = filtersOf(view, field, ["compare"]);
2413
+ const info = items.length || compared.length ? fieldItems(encoded, field, { view, locale }) : null;
2127
2414
  let summary = null;
2128
- if (items.length) {
2129
- const info = fieldItems(encoded, field, { view, locale });
2130
- if (info) {
2131
- const all = info.items.map((i) => i.value);
2132
- summary = { shown: selectedItems(view, field, all).length, total: all.length };
2133
- }
2134
- }
2415
+ if (items.length && info) {
2416
+ const all = info.items.map((i) => i.value);
2417
+ summary = { shown: selectedItems(view, field, all).length, total: all.length };
2418
+ }
2419
+ const labelOf = (v) => info?.items.find((i) => i.value === v)?.label;
2420
+ const date = sourceType === "date";
2421
+ const span = date ? dateSpan(encoded, sourceOf(view, field)) : null;
2422
+ const rules = filtersOf(view, field, ["relative", "compare", "label"]).map((f) => itemRuleText(f, labels, locale, { timeZone: encoded.timeZone, date, labelOf, span }));
2135
2423
  const top = filtersOf(view, field, ["top"])[0] ?? null;
2136
2424
  const condition = filtersOf(view, field, ["value"])[0] ?? null;
2137
- const other = filtersOf(view, field, ["label"]).length > 0;
2138
- return { summary, top, condition, other, sort: sortOf(view, field) };
2425
+ return { summary, rules, top, condition, sort: sortOf(view, field) };
2139
2426
  }
2140
2427
  function stateWords(state, view, labels, locale) {
2141
2428
  if (!state) {
@@ -2144,9 +2431,8 @@ function stateWords(state, view, labels, locale) {
2144
2431
  const words = [];
2145
2432
  if (state.summary) {
2146
2433
  words.push(`${labels.stateFiltered} ${fill(labels.filterSummary, { shown: state.summary.shown.toLocaleString(locale), total: state.summary.total.toLocaleString(locale) })}`);
2147
- } else if (state.other) {
2148
- words.push(labels.stateFiltered);
2149
2434
  }
2435
+ words.push(...state.rules);
2150
2436
  if (state.top) {
2151
2437
  words.push(fill(state.top.bottom ? labels.bottomBadge : labels.topBadge, { count: state.top.count.toLocaleString(locale) }));
2152
2438
  }
@@ -2163,62 +2449,56 @@ function Badges({ state, view, labels, locale }) {
2163
2449
  if (state.summary) {
2164
2450
  const text = fill(labels.filterSummary, { shown: state.summary.shown.toLocaleString(locale), total: state.summary.total.toLocaleString(locale) });
2165
2451
  parts.push(
2166
- /* @__PURE__ */ React11.createElement("span", { key: "filter", className: "pk-chip-badge pk-badge-text" }, /* @__PURE__ */ React11.createElement(Icon, { name: "filter", size: 12 }), text)
2452
+ /* @__PURE__ */ React11.createElement("span", { key: "filter", className: "pk-chip-badge pk-badge-text", "aria-hidden": "true" }, /* @__PURE__ */ React11.createElement(Icon, { name: "filter", size: 12 }), text)
2453
+ );
2454
+ }
2455
+ if (state.rules.length) {
2456
+ const more = state.rules.length - 1;
2457
+ parts.push(
2458
+ /* @__PURE__ */ React11.createElement("span", { key: "rules", className: "pk-chip-badge pk-badge-text pk-badge-condition", "data-testid": "rule-badge", "aria-hidden": "true" }, state.summary ? null : /* @__PURE__ */ React11.createElement(Icon, { name: "filter", size: 12 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-badge-cut" }, state.rules[0]), more ? /* @__PURE__ */ React11.createElement("span", null, ` +${more.toLocaleString(locale)}`) : null)
2167
2459
  );
2168
- } else if (state.other) {
2169
- parts.push(/* @__PURE__ */ React11.createElement(Icon, { key: "filter", name: "filter", size: 12, className: "pk-chip-badge" }));
2170
2460
  }
2171
2461
  if (state.top) {
2172
2462
  const text = fill(state.top.bottom ? labels.bottomBadge : labels.topBadge, { count: state.top.count.toLocaleString(locale) });
2173
2463
  parts.push(
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)
2464
+ /* @__PURE__ */ React11.createElement("span", { key: "top", className: "pk-chip-badge pk-badge-text", "data-testid": "top-badge", "aria-hidden": "true" }, /* @__PURE__ */ React11.createElement(Icon, { name: "top", size: 12 }), text)
2175
2465
  );
2176
2466
  }
2177
2467
  if (state.condition) {
2178
2468
  const text = valueConditionText(view, state.condition, labels, locale);
2179
2469
  parts.push(
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))
2470
+ /* @__PURE__ */ React11.createElement("span", { key: "condition", className: "pk-chip-badge pk-badge-text pk-badge-condition", "data-testid": "condition-badge", "aria-hidden": "true" }, /* @__PURE__ */ React11.createElement(Icon, { name: "filter", size: 12 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-badge-cut" }, text))
2181
2471
  );
2182
2472
  }
2183
2473
  if (state.sort) {
2184
2474
  const desc = state.sort.order === "desc";
2185
2475
  parts.push(/* @__PURE__ */ React11.createElement(Icon, { key: "sort", name: desc ? "sortDesc" : "sortAsc", size: 12, className: "pk-chip-badge" }));
2186
2476
  }
2187
- if (!parts.length) {
2188
- return null;
2189
- }
2190
- return /* @__PURE__ */ React11.createElement("span", { className: "pk-badges-inline", "aria-hidden": "true" }, parts);
2477
+ return parts.length ? /* @__PURE__ */ React11.createElement(React11.Fragment, null, parts) : null;
2191
2478
  }
2192
- function Chip({ id, zone, index, count, field, text, typeName, view, types, labels, commit, openFilter, onRemove, state, locale, defaultsOf, rangeOf, info, showInfo }) {
2479
+ function Chip({ id, zone, index, count, field, text, typeName, view, types, labels, commit, onRemove, state, locale, defaultsOf, earlier, rangeOf, info, showInfo, encoded }) {
2193
2480
  const { setNodeRef, isDragging, style, itemProps, handleProps } = useChip(id, { kind: "chip", zone, index, count, field, label: text, type: typeName });
2194
- const chipRef = useRef10(
2195
- /** @type {HTMLElement | null} */
2196
- null
2197
- );
2198
- const ref = (el) => {
2199
- chipRef.current = el;
2200
- setNodeRef(el);
2201
- };
2202
2481
  const badges = state ? /* @__PURE__ */ React11.createElement(Badges, { state, view, labels, locale }) : null;
2203
2482
  const words = stateWords(state, view, labels, locale);
2204
2483
  const name = words ? `${text}, ${words}` : void 0;
2205
2484
  const remove = () => onRemove(zone, index, text);
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: (
2485
+ return /* @__PURE__ */ React11.createElement("li", { ref: setNodeRef, 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: (
2207
2486
  /** @type {any} */
2208
2487
  TYPE_ICON[typeName] ?? "text"
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(
2488
+ ), size: 13 })), /* @__PURE__ */ React11.createElement(
2210
2489
  MenuButton,
2211
2490
  {
2212
2491
  label: fill(labels.fieldMenu, { field: text }),
2213
2492
  text: /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement("span", { className: "pk-chip-name" }, text), badges),
2214
2493
  className: "pk-chip-label",
2215
2494
  name,
2495
+ title: name ?? text,
2216
2496
  role: "dialog",
2217
2497
  popoverClass: "pk-chip-menu",
2218
2498
  fill: true,
2219
2499
  testId: `chip-menu-${text}`
2220
2500
  },
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 } })
2501
+ (close) => zone === "values" ? /* @__PURE__ */ React11.createElement(MenuPanel, { name: "ValueMenu", loadingText: labels.loadingMenu, props: { view, index, types, labels, commit, close, onRemove: remove, defaultsOf, info, locale, earlier } }) : zone === "filters" ? /* @__PURE__ */ React11.createElement(MenuPanel, { name: "FilterMenu", loadingText: labels.loadingMenu, props: { view, index, field, types, labels, commit, close, onRemove: remove, locale, info, state, encoded } }) : /* @__PURE__ */ React11.createElement(MenuPanel, { name: "AxisMenu", loadingText: labels.loadingMenu, props: { view, zone, index, field, types, labels, commit, close, onRemove: remove, defaultsOf, rangeOf, locale, info, state, encoded } })
2222
2502
  ), 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 })));
2223
2503
  }
2224
2504
  function Zone({ zone, entries, labels, children, action, explain }) {
@@ -2267,7 +2547,7 @@ function ZoneSummary({ entries, labels, id, onShow, buttonRef }) {
2267
2547
  const text = parts.length ? parts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
2268
2548
  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));
2269
2549
  }
2270
- function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwap, id, folded, onShow, defaultsOf, infoOf, explain = false, showInfo = true }) {
2550
+ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap, id, folded, onShow, defaultsOf, infoOf, explain = false, showInfo = true }) {
2271
2551
  const entries = useMemo7(() => zoneEntries(view, types, labels), [view, types, labels]);
2272
2552
  const dragging = Boolean(useActiveDrag());
2273
2553
  const showing = useRef10(false);
@@ -2280,11 +2560,11 @@ function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwa
2280
2560
  const map = /* @__PURE__ */ new Map();
2281
2561
  for (const zone of ["filters", "cols", "rows"]) {
2282
2562
  for (const e of entries[zone]) {
2283
- map.set(e.field, fieldState(view, e.field, encoded, locale));
2563
+ map.set(e.field, fieldState(view, e.field, encoded, locale, labels, e.type));
2284
2564
  }
2285
2565
  }
2286
2566
  return map;
2287
- }, [entries, view, encoded, locale]);
2567
+ }, [entries, view, encoded, locale, labels]);
2288
2568
  const rangeOf = useCallback8((field) => numberRange(encoded, field), [encoded]);
2289
2569
  const root = useRef10(
2290
2570
  /** @type {HTMLDivElement | null} */
@@ -2383,14 +2663,15 @@ function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwa
2383
2663
  types,
2384
2664
  labels,
2385
2665
  commit,
2386
- openFilter,
2387
2666
  onRemove,
2388
2667
  state: zone === "values" ? null : states.get(e.field),
2389
2668
  locale,
2390
2669
  defaultsOf,
2670
+ earlier,
2391
2671
  rangeOf,
2392
2672
  info: e.field ? infoOf?.(e.field) : void 0,
2393
- showInfo
2673
+ showInfo,
2674
+ encoded
2394
2675
  }
2395
2676
  ))
2396
2677
  ))
@@ -2454,10 +2735,13 @@ function optionsKey(options) {
2454
2735
  }
2455
2736
  var here = () => typeof location !== "undefined" ? { href: location.href, hash: location.hash } : void 0;
2456
2737
  var DEFER_ROWS = 1e4;
2738
+ var dataOf = (d) => Array.isArray(d) || Array.isArray(d?.columns) ? d : [];
2739
+ var rowsOf = (d) => Array.isArray(d) ? d.length : d?.data?.[0]?.length ?? 0;
2740
+ var NO_STEPS = Object.freeze({ past: [], future: [] });
2457
2741
  var unusedNotes = (issues, raw) => issues.filter((i) => (i.code ?? (i.message === "unknown key" ? "unknownKey" : "")) !== "unknownKey" || !["name", "description"].includes(i.path)).map((issue) => ({ issue, raw }));
2458
2742
  function PivotReport(props) {
2459
2743
  const { loading: loading2 = false, data, encoded } = props;
2460
- const [deferred, setDeferred] = useState12(() => !encoded && Array.isArray(data) && data.length > DEFER_ROWS);
2744
+ const [deferred, setDeferred] = useState12(() => !encoded && rowsOf(data) > DEFER_ROWS);
2461
2745
  const [started, setStarted] = useState12(false);
2462
2746
  useEffect11(() => {
2463
2747
  if (!deferred) {
@@ -2491,15 +2775,16 @@ function WaitingReport({ locale = "en-US", labels: customLabels, theme = "auto",
2491
2775
  const themeName = useResolvedTheme(theme, root);
2492
2776
  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 }));
2493
2777
  }
2494
- function defaultsFor(fieldDefaults, field) {
2495
- if (!fieldDefaults || typeof fieldDefaults !== "object") {
2496
- return void 0;
2778
+ function keyOfHostView(view) {
2779
+ try {
2780
+ return JSON.stringify(view ?? null) ?? "null";
2781
+ } catch {
2782
+ return "null";
2497
2783
  }
2498
- const key = Object.keys(fieldDefaults).find((k) => k.toLowerCase() === String(field).toLowerCase());
2499
- return key === void 0 ? void 0 : fieldDefaults[key];
2500
2784
  }
2501
- function EmptyState({ labels, templates, onTemplate }) {
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);
2785
+ var staysTheSame = () => () => void 0;
2786
+ function EmptyState({ labels, templates, onTemplate, onLoad, noData }) {
2787
+ 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, noData ? labels.emptyNoData : labels.emptyTitle), noData ? null : /* @__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)))), onLoad ? /* @__PURE__ */ React12.createElement("div", { className: "pk-drop-zone", "data-testid": "empty-drop" }, /* @__PURE__ */ React12.createElement("p", null, noData ? labels.emptyDrop : labels.emptyLoad), /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn", onClick: onLoad, "data-testid": "empty-load" }, /* @__PURE__ */ React12.createElement(Icon, { name: "upload" }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, labels.loadData))) : null, 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);
2503
2788
  }
2504
2789
  function Report(props) {
2505
2790
  const {
@@ -2545,11 +2830,27 @@ function Report(props) {
2545
2830
  schemaUrl,
2546
2831
  grow: growProp,
2547
2832
  fieldList,
2548
- loading: loading2 = false
2833
+ loading: loading2 = false,
2834
+ allowImport = false,
2835
+ plugins: pluginsProp,
2836
+ onDataLoad,
2837
+ importWorker
2549
2838
  } = props;
2550
2839
  const grow = growProp === "on" || growProp !== "off" && props.height === void 0;
2551
- const sourceId = typeof sourceProp?.id === "string" && sourceProp.id ? sourceProp.id : void 0;
2552
- const sourceName = typeof sourceProp?.name === "string" && sourceProp.name ? sourceProp.name : void 0;
2840
+ const hostSourceId = typeof sourceProp?.id === "string" && sourceProp.id ? sourceProp.id : void 0;
2841
+ const hostSourceName = typeof sourceProp?.name === "string" && sourceProp.name ? sourceProp.name : void 0;
2842
+ const [job, setJob] = useState12(
2843
+ /** @type {{ file: File, n: number } | null} */
2844
+ null
2845
+ );
2846
+ const [dragging, setDragging] = useState12(false);
2847
+ const dragDepth = useRef11(0);
2848
+ const [importMod, setImportMod] = useState12(importNow);
2849
+ const fileInput = useRef11(
2850
+ /** @type {HTMLInputElement | null} */
2851
+ null
2852
+ );
2853
+ const plugins = Array.isArray(pluginsProp) ? pluginsProp : [];
2553
2854
  const labelsKey = JSON.stringify(customLabels ?? null);
2554
2855
  const defaultsKey = JSON.stringify(fieldDefaults ?? null);
2555
2856
  const info = useMemo8(() => fieldInfoOf(JSON.parse(defaultsKey)), [defaultsKey]);
@@ -2575,6 +2876,11 @@ function Report(props) {
2575
2876
  );
2576
2877
  const layoutFolded = folded ?? short;
2577
2878
  const zonesId = useId4();
2879
+ const ownPrefix = useRef11(
2880
+ /** @type {string | null} */
2881
+ null
2882
+ );
2883
+ const formPrefix = useSyncExternalStore3(staysTheSame, () => ownPrefix.current ??= `pk-${Math.random().toString(36).slice(2, 8)}`, () => "pk");
2578
2884
  const [drawer, setDrawer] = useState12(false);
2579
2885
  const [filterTarget, setFilterTarget] = useState12(
2580
2886
  /** @type {{ field: string, anchor: HTMLElement, base?: object } | null} */
@@ -2600,8 +2906,8 @@ function Report(props) {
2600
2906
  useEffect11(() => onMenuTexts(() => setTexts((n) => n + 1)), []);
2601
2907
  const [viewsRequest, setViewsRequest] = useState12(0);
2602
2908
  const [leftOut, setLeftOut] = useState12(
2603
- /** @type {import("./unused.jsx").UnusedNote[]} */
2604
- []
2909
+ /** @type {{ notes: import("./unused.jsx").UnusedNote[], loaded: any, after: string | null }} */
2910
+ { notes: [], loaded: null, after: null }
2605
2911
  );
2606
2912
  const [issuesDismissed, setIssuesDismissed] = useState12(
2607
2913
  /** @type {string | null} */
@@ -2609,10 +2915,6 @@ function Report(props) {
2609
2915
  );
2610
2916
  const [loads, setLoads] = useState12(0);
2611
2917
  const [unusedSaid, setUnusedSaid] = useState12(false);
2612
- const [savedKeys, setSavedKeys] = useState12(
2613
- /** @type {Record<string, string>} */
2614
- {}
2615
- );
2616
2918
  const [rowLabel, setRowLabel] = useState12(
2617
2919
  /** @type {string | null} */
2618
2920
  null
@@ -2631,17 +2933,30 @@ function Report(props) {
2631
2933
  const source = useMemo8(() => {
2632
2934
  try {
2633
2935
  const types2 = JSON.parse(typesKey);
2634
- const enc = encodedProp ?? measured("encode", () => encode(
2635
- /** @type {any[]} */
2636
- Array.isArray(data) ? data : [],
2637
- { timeZone: timeZone ?? "UTC", limits, ...types2 ? { types: types2 } : {} }
2638
- ));
2936
+ const enc = encodedProp ?? measured("encode", () => encode(dataOf(data), { timeZone: timeZone ?? "UTC", limits, ...types2 ? { types: types2 } : {} }));
2639
2937
  return { encoded: enc, error: null };
2640
2938
  } catch (error2) {
2641
2939
  return { encoded: encode([]), error: error2 };
2642
2940
  }
2643
2941
  }, [encodedProp, dataIdentity, timeZone, limits, typesKey]);
2644
- const encoded = source.encoded;
2942
+ const keepKey = allowImport && typeof storageKey === "string" && storageKey ? storageKey : null;
2943
+ const hostData = hostIdentity({ dataKey, sourceId: hostSourceId, schemaKey: schemaKeyOf(source.encoded) });
2944
+ const [kept2] = useState12(() => keepKey ? keptData(keepKey, hostData) : null);
2945
+ const [imported, setImported] = useState12(
2946
+ /** @type {import("./import-steps.js").ShownData | null} */
2947
+ kept2?.imported ?? null
2948
+ );
2949
+ const [dataSteps, setDataSteps] = useState12(
2950
+ /** @type {import("./data-history.js").DataSteps} */
2951
+ kept2?.steps ?? NO_STEPS
2952
+ );
2953
+ const [savedKeys, setSavedKeys] = useState12(
2954
+ /** @type {Record<string, string>} */
2955
+ kept2?.savedKeys ?? {}
2956
+ );
2957
+ const sourceId = imported ? imported.source.id : hostSourceId;
2958
+ const sourceName = imported ? imported.source.name : hostSourceName;
2959
+ const encoded = imported ? imported.encoded : source.encoded;
2645
2960
  const fieldNamesKey = encoded.schema.fields.map((f) => f.name).join("\0");
2646
2961
  const labels = useMemo8(() => {
2647
2962
  const fields2 = displayNames(info, fieldNamesKey ? fieldNamesKey.split("\0") : []);
@@ -2660,8 +2975,23 @@ function Report(props) {
2660
2975
  }
2661
2976
  return (field) => orders.find(([name]) => name.toLowerCase() === field.toLowerCase())?.[1];
2662
2977
  }, [ordersKey]);
2663
- const history = useViewHistory({ encoded, view: viewProp, defaultView, onViewChange, limits, outsideNote: labels.steps.outside, orderOf });
2978
+ const history = useViewHistory({ encoded, view: viewProp, defaultView, onViewChange, limits, outsideNote: labels.steps.outside, orderOf, dataKey: imported ? imported.key : 0, initial: kept2?.history });
2664
2979
  const view = history.view;
2980
+ const [startView] = useState12(() => defaultView);
2981
+ const hostKey = keyOfHostView(viewProp !== void 0 ? viewProp : startView);
2982
+ const keyOf = history.keyOf;
2983
+ const hostNotes = useMemo8(() => {
2984
+ if (hostKey === "null" || loading2 || imported || encoded.schema.fields.length === 0) {
2985
+ return null;
2986
+ }
2987
+ const raw = JSON.parse(hostKey);
2988
+ if (raw === null) {
2989
+ return null;
2990
+ }
2991
+ const notes2 = unusedNotes(normalize2(raw, encoded, { limits }).issues, raw);
2992
+ return notes2.length ? { notes: notes2, loaded: JSON.parse(keyOf(raw)) } : null;
2993
+ }, [hostKey, loading2, imported, encoded, limits, keyOf]);
2994
+ const leaveOut = useCallback9((notes2, given2) => setLeftOut({ notes: notes2, loaded: given2 ? JSON.parse(keyOf(given2)) : null, after: hostKey }), [keyOf, hostKey]);
2665
2995
  const loadedView = tagFor(history.tag, sourceId);
2666
2996
  const viewName = loadedView?.name ?? null;
2667
2997
  const unsaved = Boolean(loadedView) && savedKeys[savedKeyOf(loadedView)] !== history.viewKey;
@@ -2680,26 +3010,32 @@ function Report(props) {
2680
3010
  },
2681
3011
  [labels]
2682
3012
  );
2683
- const undo2 = useCallback9(() => {
2684
- const note = history.undo();
3013
+ const apiNow = useRef11(
3014
+ /** @type {any} */
3015
+ null
3016
+ );
3017
+ const undo2 = () => {
3018
+ const note = history.canUndo || !importMod ? history.undo() : importMod.moveData(apiNow.current, true);
2685
3019
  if (note !== null) {
2686
3020
  announce(fill(labels.toastUndone, { step: note }));
2687
3021
  }
2688
- }, [history, labels, announce]);
2689
- const redo2 = useCallback9(() => {
2690
- const note = history.redo();
3022
+ };
3023
+ const redo2 = () => {
3024
+ const note = history.canRedo || !importMod ? history.redo() : importMod.moveData(apiNow.current, false);
2691
3025
  if (note !== null) {
2692
3026
  announce(fill(labels.toastRedone, { step: note }));
2693
3027
  }
2694
- }, [history, labels, announce]);
3028
+ };
3029
+ const newStep = useCallback9(() => setDataSteps((s) => s.future.length ? { past: s.past, future: [] } : s), []);
2695
3030
  const undoLater = useRef11(undo2);
2696
3031
  useEffect11(() => {
2697
3032
  undoLater.current = undo2;
2698
3033
  });
2699
3034
  const reset2 = useCallback9(() => {
2700
3035
  history.reset(labels.steps.reset);
2701
- announce(labels.toastReset);
2702
- }, [history, labels, announce]);
3036
+ newStep();
3037
+ announce(labels.toastReset, { action: { label: labels.undo, run: () => undoLater.current() } });
3038
+ }, [history, labels, announce, newStep]);
2703
3039
  const param = linkParam(storageKey);
2704
3040
  const [opening, setOpening] = useState12(false);
2705
3041
  const appliedLink = useRef11(
@@ -2772,6 +3108,9 @@ function Report(props) {
2772
3108
  );
2773
3109
  }, []);
2774
3110
  useIsoLayoutEffect(() => {
3111
+ if (kept2) {
3112
+ return;
3113
+ }
2775
3114
  const page = here();
2776
3115
  const link = shareLink ? readLinkParam(page?.hash ?? "", param) : null;
2777
3116
  if (link) {
@@ -2819,18 +3158,19 @@ function Report(props) {
2819
3158
  if (changed) {
2820
3159
  changesRef.current += 1;
2821
3160
  setChanges(changesRef.current);
3161
+ newStep();
2822
3162
  }
2823
3163
  if (!changed || !note.removed) {
2824
3164
  return;
2825
3165
  }
2826
3166
  announce(fill(labels.toastRemoved, { field: note.field ?? "" }).trim(), { action: { label: labels.undo, run: () => undoLater.current() } });
2827
3167
  },
2828
- [history, stepText, labels, announce, limits, locale]
3168
+ [history, stepText, labels, announce, limits, locale, newStep]
2829
3169
  );
2830
3170
  const remember = useCallback9((tag, key) => setSavedKeys((all) => ({ ...all, [savedKeyOf(tag)]: key })), []);
2831
3171
  const applyLoaded = useCallback9(
2832
3172
  /** @param {import("./share.js").LoadedView} loaded @param {{ link?: boolean, restored?: boolean }} [how] */
2833
- (loaded3, { link = false, restored = false } = {}) => {
3173
+ (loaded3, { link = false, restored: restored2 = false } = {}) => {
2834
3174
  if (!loaded3.view) {
2835
3175
  return;
2836
3176
  }
@@ -2838,20 +3178,20 @@ function Report(props) {
2838
3178
  if (tag) {
2839
3179
  remember(tag, latest.current.history.keyOf(loaded3.view));
2840
3180
  }
2841
- if (restored) {
3181
+ if (restored2) {
2842
3182
  latest.current.history.setTag(tag);
2843
3183
  } else {
2844
3184
  commit(loaded3.view, { step: "viewLoaded" }, tag);
2845
3185
  }
2846
3186
  const notes2 = unusedNotes(loaded3.issues, loaded3.file?.view);
2847
- setLeftOut(notes2);
3187
+ leaveOut(notes2, loaded3.view);
2848
3188
  setIssuesDismissed(null);
2849
3189
  setLoads((x) => x + 1);
2850
3190
  setUnusedSaid(notes2.length > 0);
2851
3191
  const text = link ? notes2.length ? labels.toastLinkOpenedPartly : labels.toastLinkOpened : notes2.length ? labels.toastViewLoadedPartly : labels.toastViewLoaded;
2852
- announce(text, restored ? void 0 : { action: { label: labels.undo, run: () => undoLater.current() } });
3192
+ announce(text, restored2 ? void 0 : { action: { label: labels.undo, run: () => undoLater.current() } });
2853
3193
  },
2854
- [commit, labels, announce, remember]
3194
+ [commit, labels, announce, remember, leaveOut]
2855
3195
  );
2856
3196
  useEffect11(() => {
2857
3197
  latest.current = { history, encoded, limits, labels, announce, commit, sourceId, loaded: applyLoaded, sources, onSourceSwitch };
@@ -2990,15 +3330,15 @@ function Report(props) {
2990
3330
  panelRef.current.inert = size === "narrow" && !drawerOpen;
2991
3331
  }
2992
3332
  }, [size, drawerOpen]);
3333
+ const defaultsOf = useCallback9((field) => fieldDefaultsFor(fieldDefaults, field, encoded.column(field)), [fieldDefaults, encoded]);
2993
3334
  const placeOptions = useCallback9(
2994
3335
  (field, zone, index = void 0) => {
2995
3336
  const column = encoded.column(field);
2996
3337
  const unit = zone !== "values" && column && column.type === "date" && !column.derived ? suggestDateUnit(encoded, field) : null;
2997
- return { index, type: typeOf(field), defaults: defaultsFor(fieldDefaults, field), dateUnit: unit, groupName: unit ? groupingName(nameOf(column.name), unit, labels) : void 0 };
3338
+ return { index, type: typeOf(field), defaults: defaultsOf(field), dateUnit: unit, groupName: unit ? groupingName(nameOf(column.name), unit, labels) : void 0 };
2998
3339
  },
2999
- [encoded, typeOf, fieldDefaults, labels, nameOf]
3340
+ [encoded, typeOf, defaultsOf, labels, nameOf]
3000
3341
  );
3001
- const defaultsOf = useCallback9((field) => defaultsFor(fieldDefaults, field), [fieldDefaults]);
3002
3342
  const addTo = useCallback9(
3003
3343
  (field, zone, index = void 0) => {
3004
3344
  const options = placeOptions(field, zone, index);
@@ -3041,10 +3381,10 @@ function Report(props) {
3041
3381
  target.zone
3042
3382
  );
3043
3383
  const note = src.zone !== zone ? { step: "moved", field: src.label ?? src.field, zone } : { step: "reordered", zone };
3044
- commit(moveField(view, src.zone, src.index, zone, target.index, { type: typeOf(src.field) }), note);
3384
+ commit(moveField(view, src.zone, src.index, zone, target.index, { type: typeOf(src.field), defaults: zone === "values" && src.field ? defaultsOf(src.field) : void 0 }), note);
3045
3385
  }
3046
3386
  },
3047
- [view, typeOf, commit, addTo]
3387
+ [view, typeOf, commit, addTo, defaultsOf]
3048
3388
  );
3049
3389
  const openCell = useCallback9(
3050
3390
  /** @param {any} cell */
@@ -3053,19 +3393,95 @@ function Report(props) {
3053
3393
  return;
3054
3394
  }
3055
3395
  setHinted(true);
3056
- const { count, rows, indices } = drillRows(result, { rowPath, colPath, data: encodedProp ? null : data, limit: drillDownLimit });
3396
+ const { count, rows, indices } = drillRows(result, { rowPath, colPath, data: encodedProp || imported || !Array.isArray(data) ? null : data, limit: drillDownLimit });
3057
3397
  onCellClick?.({ row: rowPath, col: colPath, value, valueIndex, text, count, rows });
3058
3398
  if (drillDown) {
3059
3399
  const formatOf = (name) => {
3060
- const d = defaultsFor(fieldDefaults, name);
3400
+ const d = defaultsOf(name);
3061
3401
  return d ? d.drillFormat ?? d.format : void 0;
3062
3402
  };
3063
3403
  setDrill({ result, rowPath, colPath, count, indices, formatOf, nameOf, infoOf });
3064
3404
  }
3065
3405
  },
3066
- [result, encodedProp, data, drillDownLimit, onCellClick, drillDown, fieldDefaults, nameOf, infoOf]
3406
+ [result, encodedProp, imported, data, drillDownLimit, onCellClick, drillDown, defaultsOf, nameOf, infoOf]
3067
3407
  );
3068
3408
  const doExport = useExport({ fileName, result, locale, labels, limits, root, chartRef, announce, onExport });
3409
+ const requestImport = () => loadImport().then((m) => (flushSync(() => setImportMod(() => m)), m));
3410
+ const api = {
3411
+ imported,
3412
+ setImported,
3413
+ steps: dataSteps,
3414
+ setSteps: setDataSteps,
3415
+ job,
3416
+ setJob,
3417
+ dragging,
3418
+ history,
3419
+ encoded,
3420
+ hostEncoded: source.encoded,
3421
+ hostSource: sourceProp,
3422
+ sourceName,
3423
+ labels,
3424
+ locale,
3425
+ plugins,
3426
+ worker: importWorker,
3427
+ limits,
3428
+ timeZone,
3429
+ onDataLoad,
3430
+ announce,
3431
+ dismiss,
3432
+ undo: () => undoLater.current(),
3433
+ box: () => root.current?.getBoundingClientRect(),
3434
+ pick: () => importMod?.pickFile(fileInput.current),
3435
+ load: requestImport
3436
+ };
3437
+ useEffect11(() => {
3438
+ apiNow.current = api;
3439
+ });
3440
+ const restored = useRef11(false);
3441
+ useIsoLayoutEffect(() => {
3442
+ if (kept2 && !restored.current) {
3443
+ restored.current = true;
3444
+ importMod?.restoreData(api);
3445
+ history.replace(kept2.history);
3446
+ }
3447
+ }, []);
3448
+ const snapshot = history.snapshot;
3449
+ const keptKey = useRef11(keepKey);
3450
+ const fileShown = useRef11(false);
3451
+ const hostHasColumns = source.encoded.schema.fields.length > 0;
3452
+ useIsoLayoutEffect(() => {
3453
+ if (keepKey !== null && !kept2 && hostHasColumns) {
3454
+ forgetData(keepKey);
3455
+ }
3456
+ }, []);
3457
+ useEffect11(() => {
3458
+ if (keptKey.current !== keepKey && keptKey.current !== null) {
3459
+ forgetData(keptKey.current);
3460
+ }
3461
+ keptKey.current = keepKey;
3462
+ if (keepKey === null) {
3463
+ return;
3464
+ }
3465
+ if (imported) {
3466
+ fileShown.current = true;
3467
+ keepData(keepKey, { host: hostData, imported, steps: dataSteps, history: snapshot(), savedKeys });
3468
+ } else if (fileShown.current) {
3469
+ fileShown.current = false;
3470
+ forgetData(keepKey);
3471
+ }
3472
+ }, [keepKey, hostData, imported, dataSteps, snapshot, savedKeys]);
3473
+ const fileDrag = (e) => {
3474
+ if (!Array.prototype.includes.call(e.dataTransfer?.types ?? [], "Files")) {
3475
+ return;
3476
+ }
3477
+ e.preventDefault();
3478
+ const files = e.type === "drop" ? [...e.dataTransfer.files] : null;
3479
+ dragDepth.current = files ? 0 : Math.max(0, dragDepth.current + (e.type === "dragenter" ? 1 : e.type === "dragleave" ? -1 : 0));
3480
+ setDragging(dragDepth.current > 0);
3481
+ if (e.type !== "dragover") {
3482
+ requestImport().then((m) => files && m.startFiles(apiNow.current, files), () => void 0);
3483
+ }
3484
+ };
3069
3485
  const base = shareBase(shareLink, here()?.href);
3070
3486
  const share = {
3071
3487
  canLink: base !== null,
@@ -3094,20 +3510,20 @@ function Report(props) {
3094
3510
  commit(t.view, { step: "template", name: t.name }, tag);
3095
3511
  const over = zoneOverLimit(t.view, limits);
3096
3512
  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)]);
3513
+ leaveOut([...over ? [{ text: fill(labels.viewTrimmed, { name: t.name, zone: labels.zones[over.zone], max: over.max.toLocaleString(locale) }), path: over.zone }] : [], ...unusedNotes(issues, t.view)], t.view);
3098
3514
  setIssuesDismissed(null);
3099
3515
  setLoads((x) => x + 1);
3100
3516
  setUnusedSaid(false);
3101
3517
  announce(fill(labels.toastLoaded, { name: t.name }));
3102
3518
  },
3103
- [commit, labels, announce, limits, locale, history, remember, sourceId, encoded]
3519
+ [commit, labels, announce, limits, locale, history, remember, sourceId, encoded, leaveOut]
3104
3520
  );
3105
3521
  const newReport = () => {
3106
3522
  if (empty) {
3107
3523
  return;
3108
3524
  }
3109
3525
  commit(emptyView2(), { step: "new" }, null);
3110
- setLeftOut([]);
3526
+ leaveOut([], null);
3111
3527
  setLoads((x) => x + 1);
3112
3528
  setUnusedSaid(false);
3113
3529
  announce(labels.newEmpty, { action: { label: labels.undo, run: () => undoLater.current() } });
@@ -3149,9 +3565,7 @@ function Report(props) {
3149
3565
  now.setTag(tag);
3150
3566
  }
3151
3567
  },
3152
- viewKey: history.viewKey,
3153
- onNew: newReport,
3154
- canNew: !empty
3568
+ viewKey: history.viewKey
3155
3569
  };
3156
3570
  const onKeyDown = (e) => {
3157
3571
  const target = (
@@ -3163,7 +3577,7 @@ function Report(props) {
3163
3577
  big.setEnlarged(false);
3164
3578
  return;
3165
3579
  }
3166
- if (target.closest("input, textarea, select, [contenteditable]")) {
3580
+ if (target.closest("input, textarea, select, [contenteditable], [aria-modal='true']")) {
3167
3581
  return;
3168
3582
  }
3169
3583
  const mod = e.ctrlKey || e.metaKey;
@@ -3248,11 +3662,9 @@ function Report(props) {
3248
3662
  const help = useMemo8(
3249
3663
  () => ({
3250
3664
  explain: settingSwitch.on,
3251
- labels: helpLabels,
3252
- isOpen: (id) => sectionOpen(id, dismissed),
3253
- setOpen: (id, open) => changeDismissed(withSection(dismissed, id, open), null)
3665
+ labels: helpLabels
3254
3666
  }),
3255
- [settingSwitch.on, helpLabels, dismissed, changeDismissed]
3667
+ [settingSwitch.on, helpLabels]
3256
3668
  );
3257
3669
  const [fieldsSession, setFieldsSession] = useState12(
3258
3670
  /** @type {boolean | null} */
@@ -3302,8 +3714,16 @@ function Report(props) {
3302
3714
  appliedLink.current = null;
3303
3715
  setLinkCheck(null);
3304
3716
  };
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]);
3717
+ const fromHost = hostNotes !== null && leftOut.after !== hostKey;
3718
+ const given = fromHost ? hostNotes : leftOut;
3719
+ const notes = useMemo8(
3720
+ () => [...given.notes.filter((n) => stillApplies(n, given.loaded, view)), ...result && !empty ? result.issues.slice(0, 20).map((issue) => ({ issue, raw: view })) : []],
3721
+ [given, result, empty, view]
3722
+ );
3723
+ const notesKey = useMemo8(
3724
+ () => JSON.stringify([fromHost ? "host" : loads, ...given.notes.map((n) => "issue" in n ? [n.issue.path, n.issue.message] : n.text), ...result && !empty ? result.issues.slice(0, 20).map((i) => [i.path, i.message]) : []]),
3725
+ [fromHost, given, loads, result, empty]
3726
+ );
3307
3727
  const summaryParts = big.enlarged ? layoutSummary(zoneEntries(view, types, labels), labels) : [];
3308
3728
  const summaryText = summaryParts.length ? summaryParts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
3309
3729
  return /* @__PURE__ */ React12.createElement(
@@ -3322,9 +3742,13 @@ function Report(props) {
3322
3742
  "aria-label": label || labels.report,
3323
3743
  style: { height },
3324
3744
  tabIndex: -1,
3325
- onKeyDown
3745
+ onKeyDown,
3746
+ onDragEnter: allowImport ? fileDrag : void 0,
3747
+ onDragOver: allowImport ? fileDrag : void 0,
3748
+ onDragLeave: allowImport ? fileDrag : void 0,
3749
+ onDrop: allowImport ? fileDrag : void 0
3326
3750
  },
3327
- /* @__PURE__ */ React12.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React12.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React12.createElement(
3751
+ /* @__PURE__ */ React12.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React12.createElement(FormNameContext.Provider, { value: formPrefix }, /* @__PURE__ */ React12.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React12.createElement(
3328
3752
  PivotDnd,
3329
3753
  {
3330
3754
  labels,
@@ -3370,12 +3794,15 @@ function Report(props) {
3370
3794
  chartPlan: plan,
3371
3795
  labels,
3372
3796
  size,
3373
- canUndo: history.canUndo,
3374
- canRedo: history.canRedo,
3797
+ canUndo: history.canUndo || dataSteps.past.length > 0,
3798
+ canRedo: history.canRedo || dataSteps.future.length > 0,
3375
3799
  canReset: history.canReset,
3800
+ startEmpty: history.startEmpty,
3801
+ canNew: !empty,
3376
3802
  onUndo: undo2,
3377
3803
  onRedo: redo2,
3378
3804
  onReset: reset2,
3805
+ onNew: newReport,
3379
3806
  loadedView: loadedView ? { name: loadedView.name, changed: unsaved } : null,
3380
3807
  onDisplay: (d) => commit(setDisplay(view, d), { step: "display", display: d }),
3381
3808
  onChart: (p) => commit(setChart(view, p), { step: "chart", type: p }),
@@ -3402,11 +3829,10 @@ function Report(props) {
3402
3829
  canResetTips: dismissed.some((id) => !keptOnReset(id)),
3403
3830
  onResetTips: () => changeDismissed(dismissed.filter(keptOnReset), null),
3404
3831
  help: {
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]
3832
+ explanations: explainUser ? { on: !dismissed.includes(NO_EXPLANATIONS), set: (on) => toggle(NO_EXPLANATIONS, on) } : null
3408
3833
  },
3409
- viewsRequest
3834
+ viewsRequest,
3835
+ data: allowImport ? { loaded: Boolean(imported), panel: (close) => /* @__PURE__ */ React12.createElement(MenuPanel, { name: "DataMenu", loadingText: labels.loadingMenu, props: { api, close, labels } }) } : null
3410
3836
  }
3411
3837
  ), /* @__PURE__ */ React12.createElement(
3412
3838
  Zones,
@@ -3415,7 +3841,6 @@ function Report(props) {
3415
3841
  types,
3416
3842
  labels,
3417
3843
  commit,
3418
- openFilter: (field, anchor) => setFilterTarget({ field, anchor }),
3419
3844
  encoded,
3420
3845
  locale,
3421
3846
  onSwap: () => commit(swapAxes(view), { step: "swap" }),
@@ -3424,6 +3849,7 @@ function Report(props) {
3424
3849
  onShow: () => setFolded(false),
3425
3850
  defaultsOf,
3426
3851
  infoOf,
3852
+ earlier: history.earlier,
3427
3853
  explain: zoneSwitch.on,
3428
3854
  showInfo: fieldSwitch.on
3429
3855
  }
@@ -3443,7 +3869,7 @@ function Report(props) {
3443
3869
  labels,
3444
3870
  locale,
3445
3871
  narrow: size === "narrow",
3446
- quiet: unusedSaid
3872
+ quiet: unusedSaid && !fromHost
3447
3873
  }
3448
3874
  ), /* @__PURE__ */ React12.createElement(
3449
3875
  Tips,
@@ -3454,7 +3880,7 @@ function Report(props) {
3454
3880
  onAction: runTip,
3455
3881
  focusFallback: () => root.current?.focus({ preventScroll: true })
3456
3882
  }
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(
3883
+ ), 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, onLoad: allowImport ? () => requestImport().then((m) => m.pickFile(fileInput.current), () => announce(labels.menuFailed, { tone: "error" })) : void 0, noData: allowImport && fields.length === 0 }) : view.display === "chart" && chartResult ? /* @__PURE__ */ React12.createElement(
3458
3884
  PivotChart,
3459
3885
  {
3460
3886
  result: chartResult,
@@ -3472,9 +3898,9 @@ function Report(props) {
3472
3898
  },
3473
3899
  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 ?? "") })
3474
3900
  }
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),
3901
+ ) : 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 }) : ""), importMod ? /* @__PURE__ */ React12.createElement(importMod.SourceLine, { api }) : null, 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
3902
  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" }))))
3903
+ ), allowImport && importMod ? /* @__PURE__ */ React12.createElement(importMod.ImportLayer, { api, input: fileInput }) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-layer", ref: setLayer }, /* @__PURE__ */ React12.createElement("span", { className: "pk-origin", "aria-hidden": "true" })))))
3478
3904
  );
3479
3905
  }
3480
3906
  export {