pivotkit-react 0.6.1 → 0.8.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 (62) hide show
  1. package/CHANGELOG.md +212 -1
  2. package/README.md +33 -15
  3. package/dist/chunks/{chunk-JMRTIOX4.js → chunk-2N2UGSIG.js} +7 -0
  4. package/dist/chunks/{chunk-ZK5RVCHP.js → chunk-BHHIZHUE.js} +1 -1
  5. package/dist/chunks/{chunk-YXLANLGL.js → chunk-GUSQWPTH.js} +56 -3
  6. package/dist/chunks/{chunk-JOWAEZAD.js → chunk-JAOOFDNR.js} +21 -1
  7. package/dist/chunks/{chunk-E6M57YLL.js → chunk-MU5BTKSY.js} +7 -0
  8. package/dist/chunks/{chunk-TR2HROIK.js → chunk-RNQ32FCN.js} +66 -5
  9. package/dist/chunks/{chunk-XN5HNKJ2.js → chunk-SJCG4I57.js} +98 -33
  10. package/dist/chunks/{chunk-3LDE2GPG.js → chunk-VMJMDP7C.js} +372 -33
  11. package/dist/chunks/{report-run-BZBFOMPF.js → report-run-HU4WPOB7.js} +3 -1
  12. package/dist/chunks/{unused-texts-Y4R67XSN.js → unused-texts-LRYVWFFN.js} +1 -1
  13. package/dist/chunks/{unused-texts-de-6YVPTNVS.js → unused-texts-de-GB3IWWEM.js} +1 -1
  14. package/dist/echarts.js +426 -35
  15. package/dist/import-ui.js +3 -3
  16. package/dist/index.js +769 -435
  17. package/dist/labels.js +6 -6
  18. package/dist/menu-texts-de.js +1 -1
  19. package/dist/menus.js +1133 -542
  20. package/dist/styles.css +271 -158
  21. package/package.json +8 -4
  22. package/styles.css.d.ts +3 -0
  23. package/types/PivotReport.d.ts +6 -0
  24. package/types/add-menu.d.ts +48 -0
  25. package/types/chart-colors.d.ts +8 -0
  26. package/types/chart-decorate.d.ts +66 -3
  27. package/types/chart-legend.d.ts +176 -0
  28. package/types/chart-summary.d.ts +8 -3
  29. package/types/chart-tooltip.d.ts +159 -17
  30. package/types/chart.d.ts +21 -3
  31. package/types/date-context.d.ts +30 -0
  32. package/types/drill-panel.d.ts +4 -2
  33. package/types/echarts.d.ts +7 -3
  34. package/types/export-run.d.ts +19 -14
  35. package/types/export-scope.d.ts +13 -2
  36. package/types/field-info.d.ts +12 -0
  37. package/types/files.d.ts +14 -0
  38. package/types/filter.d.ts +18 -0
  39. package/types/group-context.d.ts +20 -0
  40. package/types/index.d.ts +35 -6
  41. package/types/label-room.d.ts +13 -0
  42. package/types/labels.d.ts +85 -16
  43. package/types/lazy-menus.d.ts +2 -2
  44. package/types/levels.d.ts +16 -7
  45. package/types/menu-labels.d.ts +67 -1
  46. package/types/menu-ops.d.ts +10 -0
  47. package/types/menu-topics.d.ts +110 -21
  48. package/types/menus.d.ts +3 -2
  49. package/types/names.d.ts +32 -3
  50. package/types/overflow.d.ts +18 -30
  51. package/types/print-frame.d.ts +32 -3
  52. package/types/report-run.d.ts +5 -0
  53. package/types/rove.d.ts +10 -0
  54. package/types/theme-tokens.d.ts +17 -0
  55. package/types/toolbar-panels.d.ts +43 -15
  56. package/types/unused-texts.d.ts +7 -0
  57. package/types/use-big-result.d.ts +24 -9
  58. package/types/use-export.d.ts +8 -4
  59. package/types/view-ops.d.ts +19 -8
  60. package/types/view-tabs.d.ts +12 -0
  61. package/types/zones.d.ts +41 -9
  62. package/types/light-tokens.d.ts +0 -16
package/dist/index.js CHANGED
@@ -8,6 +8,7 @@ import {
8
8
  InfoButton,
9
9
  MAX_CATEGORIES,
10
10
  NO_EXPLANATIONS,
11
+ SLICE_TYPES,
11
12
  ZONES,
12
13
  activeTips,
13
14
  addField,
@@ -15,9 +16,15 @@ import {
15
16
  chartPlan,
16
17
  chartTypeOf,
17
18
  cleanDismissed,
19
+ dateContext,
20
+ dateDisplayLocale,
21
+ dateRangeText,
18
22
  dateSpan,
23
+ displayNames,
19
24
  drillRows,
20
25
  fieldAction,
26
+ fieldDefaultsFor,
27
+ fieldInfoOf,
21
28
  fieldsCollapsed,
22
29
  filterZoneFields,
23
30
  filtersOf,
@@ -26,6 +33,7 @@ import {
26
33
  headerSortState,
27
34
  headerSortTarget,
28
35
  helpSwitch,
36
+ hiddenAfter,
29
37
  importNow,
30
38
  isEmptyPick,
31
39
  isEmptyView,
@@ -37,6 +45,7 @@ import {
37
45
  loadImport,
38
46
  loadLink,
39
47
  localStore,
48
+ matchingFields,
40
49
  moveField,
41
50
  nextHeaderSort,
42
51
  numberRange,
@@ -67,16 +76,19 @@ import {
67
76
  tipContext,
68
77
  tipText,
69
78
  toggleCollapsed,
79
+ typesOf,
70
80
  valueConditionText,
71
81
  valueLabel,
82
+ valueLabels,
72
83
  viewFromObject,
73
84
  withHostOrders,
74
85
  withoutFilters,
75
86
  writeDismissed,
76
87
  writeItem,
77
88
  writeStoredView,
89
+ zoneMax,
78
90
  zoneOverLimit
79
- } from "./chunks/chunk-3LDE2GPG.js";
91
+ } from "./chunks/chunk-VMJMDP7C.js";
80
92
  import {
81
93
  FormNameContext,
82
94
  Group,
@@ -92,7 +104,7 @@ import {
92
104
  tabStops,
93
105
  useIsoLayoutEffect,
94
106
  useModal
95
- } from "./chunks/chunk-JOWAEZAD.js";
107
+ } from "./chunks/chunk-JAOOFDNR.js";
96
108
  import {
97
109
  MENU_TEXTS,
98
110
  errorText,
@@ -100,17 +112,19 @@ import {
100
112
  mergeLabels,
101
113
  messageOf,
102
114
  plural,
103
- resolveLabels
104
- } from "./chunks/chunk-XN5HNKJ2.js";
115
+ removedLabels,
116
+ resolveLabels,
117
+ rowCount
118
+ } from "./chunks/chunk-SJCG4I57.js";
105
119
 
106
120
  // src/PivotReport.jsx
107
- 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";
121
+ import React13, { useCallback as useCallback10, useEffect as useEffect11, useId as useId5, useMemo as useMemo8, useRef as useRef12, useState as useState12, useSyncExternalStore as useSyncExternalStore3 } from "react";
108
122
  import { flushSync } from "react-dom";
109
123
  import { computePivot, emptyView as emptyView2, encode, fieldLabel as fieldLabel5, normalize as normalize2, suggestDateUnit, toGrid, toSeries, viewFields } from "pivotkit-core";
110
124
 
111
125
  // src/chart.jsx
112
126
  import React, { useEffect, useId, useRef, useState } from "react";
113
- import { fieldLabel, toEChartsOption } from "pivotkit-core";
127
+ import { fieldLabel } from "pivotkit-core";
114
128
 
115
129
  // src/chart-summary.js
116
130
  import { formatter } from "pivotkit-core";
@@ -126,10 +140,11 @@ function counts(s, labels, locale) {
126
140
  series: plural(labels.chartSeries, series, { lang: labels.lang, locale })
127
141
  });
128
142
  }
129
- function chartSummary(s, { type, rows, valueNames, labels, locale }) {
143
+ function chartSummary(s, { type, rows, valueNames, labels, locale, shares = false, linesText = "" }) {
130
144
  const parts = [
131
145
  fill(labels.chartSummary, { type: labels.chartTypes[type] ?? type, values: valueNames.join(", "), categories: rows.length ? rows.join(" / ") : labels.categories }),
132
- counts(s, labels, locale)
146
+ counts(s, labels, locale),
147
+ ...shares ? [labels.chartShares] : []
133
148
  ];
134
149
  let max = null;
135
150
  let min = null;
@@ -151,6 +166,9 @@ function chartSummary(s, { type, rows, valueNames, labels, locale }) {
151
166
  const text = (p) => formatter(s.series[p.si].format, { locale })(p.v);
152
167
  parts.push(fill(labels.chartExtremes, { max: text(max), maxAt: where(max), min: text(min), minAt: where(min) }));
153
168
  }
169
+ if (linesText) {
170
+ parts.push(linesText);
171
+ }
154
172
  parts.push(labels.chartTableHint);
155
173
  return parts.join(" ");
156
174
  }
@@ -169,11 +187,12 @@ function resolveTheme(wanted, htmlTheme, prefersDark) {
169
187
 
170
188
  // src/chart.jsx
171
189
  var loading = null;
190
+ var TAP_WAIT = 1e4;
172
191
  function loadECharts() {
173
192
  loading ??= import("./echarts.js");
174
193
  return loading;
175
194
  }
176
- function PivotChart({ result, series, labels, locale, themeName, root, onInstance, onPoint, valueNames, chartOptions, plan }) {
195
+ function PivotChart({ result, series, labels, locale, themeName, root, onInstance, onPoint, onLines, onLegend, valueNames, chartOptions, colorMap, plan }) {
177
196
  const el = useRef(
178
197
  /** @type {HTMLDivElement | null} */
179
198
  null
@@ -189,10 +208,24 @@ function PivotChart({ result, series, labels, locale, themeName, root, onInstanc
189
208
  );
190
209
  const [box, setBox] = useState("");
191
210
  const [every, setEvery] = useState(1);
211
+ const [linesText, setLinesText] = useState("");
192
212
  const summaryId = useId();
193
213
  const type = plan ? plan.name : chartTypeOf(result.view.chart);
194
214
  const drawAs = plan ? plan.chart : null;
195
- const latest = useRef({ series, onPoint, onInstance, type });
215
+ const latest = useRef({ series, onPoint, onInstance, onLines, onLegend, type });
216
+ const keeper = useRef(
217
+ /** @type {any} */
218
+ null
219
+ );
220
+ const [zoomed, setZoomed] = useState(0);
221
+ const [zoomKeys, setZoomKeys] = useState(
222
+ /** @type {any} */
223
+ null
224
+ );
225
+ const [shown, setShown] = useState(
226
+ /** @type {{ series: any, shares: boolean } | null} */
227
+ null
228
+ );
196
229
  const lib = useRef(
197
230
  /** @type {any} */
198
231
  null
@@ -201,12 +234,23 @@ function PivotChart({ result, series, labels, locale, themeName, root, onInstanc
201
234
  /** @type {unknown} */
202
235
  void 0
203
236
  );
237
+ const hover = useRef(
238
+ /** @type {{ seriesIndex: number, dataIndex: number } | null} */
239
+ null
240
+ );
241
+ const tapped = useRef(
242
+ /** @type {{ element: string, at: number } | null} */
243
+ null
244
+ );
245
+ const touched = useRef(false);
204
246
  useEffect(() => {
205
- latest.current = { series, onPoint, onInstance, type };
247
+ latest.current = { series, onPoint, onInstance, onLines, onLegend, type };
206
248
  });
207
249
  useEffect(() => {
208
250
  let disposed = false;
209
251
  let ro = null;
252
+ let onPress = null;
253
+ let doc = null;
210
254
  loadECharts().then(
211
255
  (echarts) => {
212
256
  if (disposed || !el.current) {
@@ -224,8 +268,50 @@ function PivotChart({ result, series, labels, locale, themeName, root, onInstanc
224
268
  }
225
269
  const seriesEntry = kind === "heatmap" ? s.series.filter((x) => x.valueIndex === s.series[0]?.valueIndex)[p.value?.[0]] : s.series[p.seriesIndex];
226
270
  const row = kind === "heatmap" ? p.value?.[1] : p.dataIndex;
227
- if (seriesEntry && s.categoryPaths[row]) {
228
- cb({ rowPath: s.categoryPaths[row], colPath: seriesEntry.colPath, valueIndex: seriesEntry.valueIndex, value: kind === "heatmap" ? p.value[2] : p.value });
271
+ if (!seriesEntry || !s.categoryPaths[row]) {
272
+ return;
273
+ }
274
+ const element = `${p.seriesIndex}:${p.dataIndex}`;
275
+ const last = tapped.current;
276
+ if (touched.current && (last?.element !== element || Date.now() - last.at > TAP_WAIT)) {
277
+ tapped.current = { element, at: Date.now() };
278
+ return;
279
+ }
280
+ tapped.current = null;
281
+ instance.dispatchAction({ type: "hideTip" });
282
+ const value = kind === "heatmap" ? p.value[2] : typeof p.data?.raw === "number" ? p.data.raw : p.value;
283
+ cb({ rowPath: s.categoryPaths[row], colPath: seriesEntry.colPath, valueIndex: seriesEntry.valueIndex, value });
284
+ });
285
+ keeper.current = echarts.chartKeeper(instance, { categories: () => latest.current.series?.categories, onLegend: (change) => latest.current.onLegend?.(change), redraw: () => setZoomed((n) => n + 1), onWindow: (control) => setZoomKeys(control ? { ...control, props: echarts.zoomKeyProps } : null) });
286
+ const redraw = (e) => {
287
+ const at = e?.event;
288
+ if (at && typeof at.offsetX === "number") {
289
+ instance.dispatchAction({ type: "hideTip" });
290
+ instance.dispatchAction({ type: "showTip", x: at.offsetX, y: at.offsetY });
291
+ }
292
+ };
293
+ instance.on("mousemove", (e) => {
294
+ if (e.componentType === "series" && (e.seriesType === "bar" || e.seriesType === "line") && typeof e.dataIndex === "number") {
295
+ const last = hover.current;
296
+ if (last?.seriesIndex !== e.seriesIndex || last?.dataIndex !== e.dataIndex) {
297
+ hover.current = { seriesIndex: e.seriesIndex, dataIndex: e.dataIndex };
298
+ redraw(e);
299
+ }
300
+ }
301
+ });
302
+ instance.on("mouseout", (e) => {
303
+ if (hover.current) {
304
+ hover.current = null;
305
+ redraw(e);
306
+ }
307
+ });
308
+ instance.on("globalout", () => {
309
+ hover.current = null;
310
+ tapped.current = null;
311
+ });
312
+ instance.getZr().on("click", (e) => {
313
+ if (!e.target) {
314
+ tapped.current = null;
229
315
  }
230
316
  });
231
317
  ro = typeof ResizeObserver === "function" ? new ResizeObserver(() => {
@@ -233,36 +319,62 @@ function PivotChart({ result, series, labels, locale, themeName, root, onInstanc
233
319
  setBox(`${instance.getWidth()}x${instance.getHeight()}`);
234
320
  }) : null;
235
321
  ro?.observe(el.current);
322
+ const box2 = el.current;
323
+ doc = box2.ownerDocument;
324
+ onPress = (e) => {
325
+ if (e.composedPath().includes(box2)) {
326
+ touched.current = e.pointerType === "touch";
327
+ } else {
328
+ tapped.current = null;
329
+ }
330
+ };
331
+ doc.addEventListener("pointerdown", onPress, true);
236
332
  setReady(true);
237
333
  },
238
334
  (err) => setFailed(String(err && err.message ? err.message : err))
239
335
  );
240
336
  return () => {
241
337
  disposed = true;
338
+ keeper.current?.dispose();
242
339
  ro?.disconnect();
340
+ if (onPress) {
341
+ doc?.removeEventListener("pointerdown", onPress, true);
342
+ }
243
343
  chart.current?.dispose();
244
344
  chart.current = null;
245
345
  latest.current.onInstance(null);
346
+ latest.current.onLines?.(null);
246
347
  };
247
348
  }, []);
248
349
  useEffect(() => {
249
350
  if (!ready || !chart.current || !root.current) {
250
351
  return;
251
352
  }
353
+ const { toEChartsOption } = lib.current;
252
354
  const style = lib.current.chartStyle(root.current);
253
- const option = toEChartsOption(result, { theme: chartThemeFrom(style), locale, labels: labels.core, maxCategories: MAX_CATEGORIES, ...series ? { series } : {}, ...drawAs ? { chart: drawAs } : {} });
254
- const { axisEvery, ...drawn } = lib.current.decorate(option, style, chart.current.getHeight(), root.current.ownerDocument, chart.current.getWidth(), { categoryNames: series?.categories, axisLabels: result.view.chart.axisLabels });
255
- setEvery(axisEvery);
355
+ const colors = lib.current.colorMapFor(colorMap, themeName);
356
+ const option = toEChartsOption(result, { theme: chartThemeFrom(style), locale, labels: labels.core, maxCategories: MAX_CATEGORIES, ...series ? { series } : {}, ...drawAs ? { chart: drawAs } : {}, ...colors ? { colorMap: colors } : {} });
357
+ hover.current = null;
358
+ tapped.current = null;
359
+ const values = (series?.series ?? []).map((x) => result.view.values[x.valueIndex]);
360
+ const lines = series ? lib.current.chartLines(result, { series, chart: drawAs, labels, locale }) : null;
361
+ setLinesText(lines?.text ?? "");
362
+ latest.current.onLines?.(lines?.checks ?? null);
363
+ const tooltip = { mode: result.view.chart.tooltip, share: result.view.chart.tooltipShare, hover, totalLabel: labels.chartTotal, moreLabel: labels.chartMore, moreInTotalLabel: labels.chartMoreInTotal, values, lines: lines?.lines ?? [] };
364
+ const doc = root.current.ownerDocument;
365
+ setShown(series ? lib.current.shownOf(series, option, result.view.chart.hidden, SLICE_TYPES.includes(type)) : null);
256
366
  const clean = chartOptions ? lib.current.cleanChartOptions(chartOptions) : null;
257
367
  if (clean?.problems.length && warned2.current !== chartOptions) {
258
368
  warned2.current = chartOptions;
259
369
  console.warn(`pivotkit: chartOptions entries left out (only plain JSON, and no markup, addresses or text templates): ${clean.problems.slice(0, 5).join("; ")}${clean.problems.length > 5 ? `; and ${clean.problems.length - 5} more` : ""}`);
260
370
  }
261
- chart.current.setOption(clean?.options ? lib.current.mergeChartOptions(drawn, clean.options) : drawn, { notMerge: true });
262
- }, [ready, result, series, labels, locale, themeName, root, box, chartOptions, drawAs]);
371
+ const drawn = lib.current.drawOption(chart.current, option, style, doc, { categoryNames: series?.categories, axisLabels: result.view.chart.axisLabels, ...keeper.current.zoomOf(result, series?.categories ?? [], doc), tooltip, parseColor: lib.current.color.parse }, clean?.options);
372
+ keeper.current.drawn(drawn.dataZoom);
373
+ setEvery(drawn.axisEvery);
374
+ }, [ready, result, series, labels, locale, themeName, root, box, chartOptions, colorMap, drawAs, zoomed, type]);
263
375
  const empty = result.view.values.length === 0;
264
- const summary = series && !empty ? chartSummary(series, { type, rows: result.view.rows.map((f) => fieldLabel(f, labels.core)), valueNames, labels, locale }) : labels.noChartData;
265
- return /* @__PURE__ */ React.createElement("div", { className: "pk-chart-wrap" }, /* @__PURE__ */ React.createElement("div", { className: "pk-chart-box" }, /* @__PURE__ */ React.createElement("div", { ref: el, className: "pk-chart", "data-testid": "pivot-chart", role: "img", "aria-label": result.view.chart.title ? `${labels.chart}: ${result.view.chart.title}` : labels.chart, "aria-describedby": summaryId }), /* @__PURE__ */ React.createElement("p", { id: summaryId, className: "pk-sr", "data-testid": "chart-summary" }, summary), !ready && !failed ? /* @__PURE__ */ React.createElement("div", { className: "pk-chart-note" }, labels.loadingChart) : null, failed ? /* @__PURE__ */ React.createElement("div", { className: "pk-chart-note pk-error" }, failed) : null, ready && empty ? /* @__PURE__ */ React.createElement("div", { className: "pk-chart-note" }, labels.noChartData) : null), ready && !empty && every > 1 ? /* @__PURE__ */ React.createElement("p", { className: "pk-axis-note", "data-testid": "axis-note" }, fill(labels.axisEvery, { n: every.toLocaleString(locale) })) : null);
376
+ const summary = series && !empty ? chartSummary(shown?.series ?? series, { type, rows: result.view.rows.map((f) => fieldLabel(f, labels.core)), valueNames, labels, locale, shares: shown?.shares, linesText }) : labels.noChartData;
377
+ return /* @__PURE__ */ React.createElement("div", { className: "pk-chart-wrap" }, /* @__PURE__ */ React.createElement("div", { className: "pk-chart-box" }, /* @__PURE__ */ React.createElement("div", { ref: el, className: "pk-chart", "data-testid": "pivot-chart", role: "img", "aria-label": result.view.chart.title ? `${labels.chart}: ${result.view.chart.title}` : labels.chart, "aria-describedby": summaryId }), /* @__PURE__ */ React.createElement("p", { id: summaryId, className: "pk-sr", "data-testid": "chart-summary" }, summary), zoomKeys ? /* @__PURE__ */ React.createElement("div", { ...zoomKeys.props(zoomKeys, labels, fill, locale) }) : null, !ready && !failed ? /* @__PURE__ */ React.createElement("div", { className: "pk-chart-note" }, labels.loadingChart) : null, failed ? /* @__PURE__ */ React.createElement("div", { className: "pk-chart-note pk-error" }, failed) : null, ready && empty ? /* @__PURE__ */ React.createElement("div", { className: "pk-chart-note" }, labels.noChartData) : null), ready && !empty && every > 1 ? /* @__PURE__ */ React.createElement("p", { className: "pk-axis-note", "data-testid": "axis-note" }, fill(labels.axisEvery, { n: every.toLocaleString(locale) })) : null);
266
378
  }
267
379
 
268
380
  // src/dnd.jsx
@@ -358,11 +470,11 @@ function keyboardCoordinates(event, { context }) {
358
470
  const over = context.over?.data?.current ?? null;
359
471
  const id = nextTarget(event.code, targets, over, context.active?.data?.current ?? { kind: "field" });
360
472
  const rect = id === null ? null : context.droppableRects.get(id);
361
- const own2 = context.collisionRect;
362
- if (!rect || !own2) {
473
+ const own = context.collisionRect;
474
+ if (!rect || !own) {
363
475
  return void 0;
364
476
  }
365
- return { x: rect.left + rect.width / 2 - own2.width / 2, y: rect.top + rect.height / 2 - own2.height / 2 };
477
+ return { x: rect.left + rect.width / 2 - own.width / 2, y: rect.top + rect.height / 2 - own.height / 2 };
366
478
  }
367
479
  function targetOf(source, over) {
368
480
  const data = over?.data?.current;
@@ -433,8 +545,8 @@ function ownEventsOnly(listener) {
433
545
  };
434
546
  }
435
547
  function split(listeners2) {
436
- const own2 = Object.fromEntries(Object.entries(listeners2 ?? {}).map(([name, listener]) => [name, ownEventsOnly(listener)]));
437
- const { onKeyDown, ...pointer } = own2;
548
+ const own = Object.fromEntries(Object.entries(listeners2 ?? {}).map(([name, listener]) => [name, ownEventsOnly(listener)]));
549
+ const { onKeyDown, ...pointer } = own;
438
550
  return { pointer, keyboard: listeners2?.onKeyDown ? { onKeyDown } : {} };
439
551
  }
440
552
  function useDragSource(id, source, disabled = false) {
@@ -456,123 +568,6 @@ function ChipList({ ids, children }) {
456
568
  return /* @__PURE__ */ React2.createElement(SortableContext, { items: ids, strategy: rectSortingStrategy }, children);
457
569
  }
458
570
 
459
- // src/field-info.js
460
- import { fieldDefaultsFromSchema, isIdentifierName } from "pivotkit-core";
461
- var isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
462
- var own = (o, k) => isObject(o) && Object.hasOwn(o, k) ? o[k] : void 0;
463
- var TYPES = Object.freeze(["string", "number", "date", "boolean"]);
464
- function fieldInfoOf(fieldDefaults) {
465
- const map = /* @__PURE__ */ new Map();
466
- if (!isObject(fieldDefaults)) {
467
- return map;
468
- }
469
- const properties = {};
470
- for (const name of Object.keys(
471
- /** @type {object} */
472
- fieldDefaults
473
- )) {
474
- const d = own(fieldDefaults, name);
475
- const title = own(d, "label");
476
- const description = own(d, "description");
477
- const href = own(d, "href");
478
- if (title !== void 0 || description !== void 0 || href !== void 0) {
479
- Object.defineProperty(properties, name, { value: { title, description, externalDocs: { url: href } }, enumerable: true });
480
- }
481
- }
482
- if (Object.keys(properties).length === 0) {
483
- return map;
484
- }
485
- const clean = fieldDefaultsFromSchema({ properties }).defaults;
486
- for (const name of Object.keys(clean)) {
487
- const { label, description, href } = clean[name];
488
- const info = {};
489
- if (label) {
490
- info.label = label;
491
- }
492
- if (description) {
493
- info.description = description;
494
- if (href) {
495
- info.href = href;
496
- }
497
- }
498
- if (Object.keys(info).length) {
499
- map.set(name.toLowerCase(), info);
500
- }
501
- }
502
- return map;
503
- }
504
- function displayNames(info, fieldNames = []) {
505
- const spelling = new Map(fieldNames.map((n) => [String(n).toLowerCase(), String(n)]));
506
- const uses = /* @__PURE__ */ new Map();
507
- for (const entry of info.values()) {
508
- if (entry.label) {
509
- const l = entry.label.toLowerCase();
510
- uses.set(l, (uses.get(l) ?? 0) + 1);
511
- }
512
- }
513
- const out = {};
514
- for (const [key, entry] of info) {
515
- if (!entry.label) {
516
- continue;
517
- }
518
- const l = entry.label.toLowerCase();
519
- const clash = uses.get(l) > 1 || spelling.has(l) && l !== key;
520
- const value = clash ? `${entry.label} (${spelling.get(key) ?? key})` : entry.label;
521
- Object.defineProperty(out, key, { value, enumerable: true });
522
- }
523
- return Object.keys(out).length ? out : null;
524
- }
525
- function typesOf(fieldDefaults) {
526
- if (!isObject(fieldDefaults)) {
527
- return null;
528
- }
529
- const out = {};
530
- for (const name of Object.keys(
531
- /** @type {object} */
532
- fieldDefaults
533
- )) {
534
- const type = own(own(fieldDefaults, name), "type");
535
- if (typeof type === "string" && TYPES.includes(type)) {
536
- Object.defineProperty(out, name, { value: type, enumerable: true });
537
- }
538
- }
539
- return Object.keys(out).length ? out : null;
540
- }
541
- function fieldMatches(field, query, info) {
542
- if (!query) {
543
- return true;
544
- }
545
- return [field, info?.label, info?.description].some((t) => typeof t === "string" && t.toLowerCase().includes(query));
546
- }
547
- var identifierColumns = /* @__PURE__ */ new WeakMap();
548
- function isIdentifier(column) {
549
- if (!column || column.type !== "number" || column.derived || !isIdentifierName(column.name)) {
550
- return false;
551
- }
552
- const known = identifierColumns.get(column);
553
- if (known !== void 0) {
554
- return known;
555
- }
556
- let whole = true;
557
- for (let i = 0; i < column.dict.length && whole; i++) {
558
- whole = Number.isInteger(column.dict[i]);
559
- }
560
- identifierColumns.set(column, whole);
561
- return whole;
562
- }
563
- function fieldDefaultsFor(fieldDefaults, field, column) {
564
- const key = isObject(fieldDefaults) ? Object.keys(
565
- /** @type {object} */
566
- fieldDefaults
567
- ).find((k) => k.toLowerCase() === String(field).toLowerCase()) : void 0;
568
- const host = key === void 0 ? void 0 : own(fieldDefaults, key);
569
- const set = ["agg", "format", "drillFormat"].some((k) => own(host, k) !== void 0);
570
- if (set || !isIdentifier(column)) {
571
- return isObject(host) ? host : void 0;
572
- }
573
- return { ...isObject(host) ? host : {}, agg: "count", drillFormat: "text" };
574
- }
575
-
576
571
  // src/fields.jsx
577
572
  import React3, { useCallback, useEffect as useEffect2, useId as useId2, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
578
573
 
@@ -597,6 +592,23 @@ function roveTarget(key, at, rows, slotsOf) {
597
592
  return null;
598
593
  }
599
594
  var opensMenu = (e) => e.key === "ContextMenu" || e.key === "F10" && e.shiftKey;
595
+ function tabStep(key, at, count) {
596
+ if (count <= 0) {
597
+ return null;
598
+ }
599
+ switch (key) {
600
+ case "ArrowRight":
601
+ return (at + 1) % count;
602
+ case "ArrowLeft":
603
+ return (at - 1 + count) % count;
604
+ case "Home":
605
+ return 0;
606
+ case "End":
607
+ return count - 1;
608
+ default:
609
+ return null;
610
+ }
611
+ }
600
612
 
601
613
  // src/fields.jsx
602
614
  function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info, showInfo, stop }) {
@@ -617,8 +629,8 @@ function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info,
617
629
  const action = fieldAction(name, field.type, zones, labels);
618
630
  const describedBy = useId2();
619
631
  const slots = SLOTS.filter((x) => x !== "info" || info && showInfo);
620
- const own2 = stop && slots.includes(stop) ? stop : stop ? "name" : null;
621
- const tab = (slot) => own2 === slot ? 0 : -1;
632
+ const own = stop && slots.includes(stop) ? stop : stop ? "name" : null;
633
+ const tab = (slot) => own === slot ? 0 : -1;
622
634
  return /* @__PURE__ */ React3.createElement("li", { className: `pk-field${isDragging ? " pk-dragging" : ""}${zones.length ? " pk-placed" : ""}`, ref, ...itemProps, "data-field": field.name }, /* @__PURE__ */ React3.createElement("span", { className: "pk-handle", ...handleProps, tabIndex: tab("handle"), "data-pk-slot": "handle", "aria-label": fill(labels.dragHandle, { field: name }), title: labels.dragIntoZone, onClick: () => menu.current?.click() }, /* @__PURE__ */ React3.createElement(Icon, { name: "grip", size: 18 })), /* @__PURE__ */ React3.createElement("span", { className: `pk-type pk-type-${field.type}`, title: typeLabel }, /* @__PURE__ */ React3.createElement(Icon, { name: (
623
635
  /** @type {any} */
624
636
  TYPE_ICON[field.type] ?? "text"
@@ -671,10 +683,7 @@ function FieldPanel({ fields, placed, labels, onAdd, onNote, onFilter, drawer, o
671
683
  const [query, setQuery] = useState3("");
672
684
  const active = useActiveDrag();
673
685
  const { setNodeRef, isOver } = useDropTarget("panel", { kind: "panel" });
674
- const shown = useMemo2(() => {
675
- const q = query.trim().toLowerCase();
676
- return q ? fields.filter((f) => fieldMatches(f.name, q, info.get(f.name.toLowerCase()))) : fields;
677
- }, [fields, query, info]);
686
+ const shown = useMemo2(() => matchingFields(fields, query, info), [fields, query, info]);
678
687
  const removing = active && active.kind !== "field";
679
688
  const modal = drawer && open;
680
689
  const el = useRef2(
@@ -1013,9 +1022,9 @@ function rowLabelOf(grid, r) {
1013
1022
  const row = grid.headerRows + r;
1014
1023
  const texts = [];
1015
1024
  for (let c = 0; c < grid.rowHeaderColumns; c++) {
1016
- const own2 = grid.rows[row]?.[c];
1017
- const merge = own2 ? null : grid.merges.find((m) => m.row <= row && row < m.row + m.rowSpan && m.col <= c && c < m.col + m.colSpan);
1018
- const cell = own2 ?? (merge && merge.col === c ? grid.rows[merge.row][merge.col] : null);
1025
+ const own = grid.rows[row]?.[c];
1026
+ const merge = own ? null : grid.merges.find((m) => m.row <= row && row < m.row + m.rowSpan && m.col <= c && c < m.col + m.colSpan);
1027
+ const cell = own ?? (merge && merge.col === c ? grid.rows[merge.row][merge.col] : null);
1019
1028
  if (cell && cell.text) {
1020
1029
  texts.push(cell.text);
1021
1030
  }
@@ -1048,6 +1057,23 @@ function longestLabels(grid, col, n) {
1048
1057
  return out;
1049
1058
  }
1050
1059
 
1060
+ // src/label-room.js
1061
+ function commonCap(widths, room) {
1062
+ if (room <= 0) {
1063
+ return 0;
1064
+ }
1065
+ const sorted = [...widths].sort((a, b) => a - b);
1066
+ let left = room;
1067
+ for (let i = 0; i < sorted.length; i++) {
1068
+ const share = left / (sorted.length - i);
1069
+ if (sorted[i] > share) {
1070
+ return share;
1071
+ }
1072
+ left -= sorted[i];
1073
+ }
1074
+ return Infinity;
1075
+ }
1076
+
1051
1077
  // src/table.jsx
1052
1078
  var totalClass = (t) => t === 2 ? " pk-grand" : t === 1 ? " pk-sub" : "";
1053
1079
  var MEASURED_LABELS = 50;
@@ -1065,7 +1091,7 @@ function labelWidths(grid, table) {
1065
1091
  Object.assign(probe.style, { position: "absolute", visibility: "hidden", whiteSpace: "pre", width: "auto", minWidth: "0", maxWidth: "none", overflow: "visible" });
1066
1092
  content.append(probe);
1067
1093
  try {
1068
- const widthOf = (l) => {
1094
+ const widthOf2 = (l) => {
1069
1095
  probe.style.fontWeight = l.total ? "var(--pk-weight-bold)" : "";
1070
1096
  probe.textContent = l.text;
1071
1097
  return probe.getBoundingClientRect().width;
@@ -1076,7 +1102,7 @@ function labelWidths(grid, table) {
1076
1102
  const toggleWidth = (toggle ? toggle.getBoundingClientRect().width : em * 1.7) + gap;
1077
1103
  const widths = [];
1078
1104
  for (let c = 0; c < grid.rowHeaderColumns; c++) {
1079
- const most = Math.max(0, ...longestLabels(grid, c, MEASURED_LABELS).map((l) => widthOf(l) + (l.toggle ? toggleWidth : 0)));
1105
+ const most = Math.max(0, ...longestLabels(grid, c, MEASURED_LABELS).map((l) => widthOf2(l) + (l.toggle ? toggleWidth : 0)));
1080
1106
  widths.push(Math.min(Math.ceil(most) + LABEL_SLACK, LABEL_MAX_EM * em));
1081
1107
  }
1082
1108
  return widths;
@@ -1084,6 +1110,40 @@ function labelWidths(grid, table) {
1084
1110
  probe.remove();
1085
1111
  }
1086
1112
  }
1113
+ var widthOf = (el) => el.getBoundingClientRect().width;
1114
+ function fitLabels(table, box, columns) {
1115
+ if (box.clientWidth === 0) {
1116
+ return;
1117
+ }
1118
+ const over = () => box.scrollWidth - box.clientWidth;
1119
+ table.setAttribute("data-pk-labels", "natural");
1120
+ table.style.removeProperty("--pk-row-room");
1121
+ const head = table.tHead ? table.tHead.rows : [];
1122
+ const last = head[head.length - 1];
1123
+ const overflow = over();
1124
+ if (overflow <= 0 || !last) {
1125
+ return;
1126
+ }
1127
+ const cells = [...last.cells].slice(0, columns);
1128
+ const extras = cells.map((cell) => {
1129
+ const s = getComputedStyle(cell);
1130
+ const grip = cell.querySelector(":scope > .pk-th-grip");
1131
+ return parseFloat(s.paddingLeft) + parseFloat(s.paddingRight) + parseFloat(s.borderLeftWidth) + parseFloat(s.borderRightWidth) + (grip ? widthOf(grip) + parseFloat(getComputedStyle(grip).marginLeft) : 0);
1132
+ });
1133
+ const widths = cells.map((cell, c) => widthOf(cell) - extras[c]);
1134
+ const names = [...last.querySelectorAll("th.pk-colHeader .pk-th-content")].reduce((sum, el) => sum + widthOf(el), 0);
1135
+ const pliable = names + (table.classList.contains("pk-virtual") ? 0 : widths.reduce((a, b) => a + b, 0));
1136
+ if (overflow < pliable) {
1137
+ table.setAttribute("data-pk-labels", "share");
1138
+ if (over() <= 0) {
1139
+ return;
1140
+ }
1141
+ }
1142
+ table.removeAttribute("data-pk-labels");
1143
+ const values = widthOf(table) - cells.reduce((sum, cell) => sum + widthOf(cell), 0);
1144
+ const room = commonCap(widths, box.clientWidth - values - extras.reduce((a, b) => a + b, 0));
1145
+ table.style.setProperty("--pk-row-room", `${Number.isFinite(room) ? Math.floor(room) : Math.max(0, ...widths)}px`);
1146
+ }
1087
1147
  var fontOf = (table) => {
1088
1148
  const s = getComputedStyle(table);
1089
1149
  return `${s.fontFamily}|${s.fontSize}|${s.fontWeight}`;
@@ -1158,6 +1218,11 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1158
1218
  null
1159
1219
  );
1160
1220
  const [fontsLoaded, setFontsLoaded] = useState5(0);
1221
+ const [font, setFont] = useState5("");
1222
+ const fitted = useRef4(
1223
+ /** @type {unknown[]} */
1224
+ []
1225
+ );
1161
1226
  const fixedWidths = virtual && labelsWide?.grid === grid ? labelsWide.widths : null;
1162
1227
  const focusNext = useRef4(false);
1163
1228
  const [sortNote, setSortNote] = useState5("");
@@ -1177,16 +1242,16 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1177
1242
  if (!virtual || !t) {
1178
1243
  return;
1179
1244
  }
1180
- const font = fontOf(t);
1181
- if (labelsWide?.grid !== grid || labelsWide.font !== font || labelsWide.fonts !== fontsLoaded) {
1245
+ const font2 = fontOf(t);
1246
+ if (labelsWide?.grid !== grid || labelsWide.font !== font2 || labelsWide.fonts !== fontsLoaded) {
1182
1247
  const widths = labelWidths(grid, t);
1183
1248
  if (widths) {
1184
- setLabelsWide({ grid, font, fonts: fontsLoaded, widths });
1249
+ setLabelsWide({ grid, font: font2, fonts: fontsLoaded, widths });
1185
1250
  }
1186
1251
  }
1187
1252
  });
1188
1253
  useEffect4(() => {
1189
- const fonts = virtual ? table.current?.ownerDocument.fonts : void 0;
1254
+ const fonts = table.current?.ownerDocument.fonts;
1190
1255
  if (!fonts) {
1191
1256
  return void 0;
1192
1257
  }
@@ -1200,12 +1265,17 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1200
1265
  live = false;
1201
1266
  fonts.removeEventListener?.("loadingdone", loaded3);
1202
1267
  };
1203
- }, [virtual]);
1268
+ }, []);
1204
1269
  useIsoLayoutEffect(() => {
1205
1270
  const t = table.current;
1206
1271
  if (!t) {
1207
1272
  return;
1208
1273
  }
1274
+ const key = [t, grid, width, font, fontsLoaded, fixedWidths];
1275
+ if (wrap.current && !key.every((v, i) => v === fitted.current[i])) {
1276
+ fitted.current = key;
1277
+ fitLabels(t, wrap.current, grid.rowHeaderColumns);
1278
+ }
1209
1279
  const row = t.tBodies[0]?.querySelector("tr[data-r]");
1210
1280
  if (row && row.getBoundingClientRect().height > 0) {
1211
1281
  setRowHeight(row.getBoundingClientRect().height);
@@ -1225,7 +1295,7 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1225
1295
  }
1226
1296
  setLefts((old) => old.length === xs.length && old.every((v, i) => Math.abs(v - xs[i]) < 0.5) ? old : xs);
1227
1297
  }
1228
- }, [grid, version, width, fixedWidths]);
1298
+ }, [grid, version, width, font, fixedWidths, fontsLoaded]);
1229
1299
  useEffect4(() => {
1230
1300
  const el = wrap.current;
1231
1301
  if (!el) {
@@ -1234,6 +1304,9 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1234
1304
  const update = () => {
1235
1305
  setScroll({ top: el.scrollTop, height: el.clientHeight });
1236
1306
  setWidth(el.clientWidth);
1307
+ if (table.current) {
1308
+ setFont(fontOf(table.current));
1309
+ }
1237
1310
  };
1238
1311
  update();
1239
1312
  const ro = typeof ResizeObserver === "function" ? new ResizeObserver(update) : null;
@@ -1497,12 +1570,12 @@ function Toasts({ toasts, dismiss, pause, closeLabel }) {
1497
1570
  }
1498
1571
 
1499
1572
  // src/templates.js
1500
- import { fieldDefaultsFromSchema as fieldDefaultsFromSchema2, fromViewFile } from "pivotkit-core";
1573
+ import { fieldDefaultsFromSchema, fromViewFile } from "pivotkit-core";
1501
1574
  var warnedScope = false;
1502
1575
  function plainNames(names) {
1503
1576
  const properties = {};
1504
1577
  names.forEach((title, i) => Object.defineProperty(properties, String(i), { value: { title }, enumerable: true }));
1505
- const clean = names.length ? fieldDefaultsFromSchema2({ properties }).defaults : {};
1578
+ const clean = names.length ? fieldDefaultsFromSchema({ properties }).defaults : {};
1506
1579
  return names.map((n, i) => Object.hasOwn(clean, String(i)) ? clean[String(i)].label : void 0);
1507
1580
  }
1508
1581
  var viewsName = (key) => key ? `pivotkit:views:${key}` : "pivotkit:views";
@@ -1591,15 +1664,15 @@ import React9, { useEffect as useEffect7, useMemo as useMemo4, useRef as useRef7
1591
1664
  import { fieldLabel as fieldLabel3 } from "pivotkit-core";
1592
1665
 
1593
1666
  // src/unused-load.js
1594
- var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-6YVPTNVS.js").then((m) => m.de) });
1667
+ var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-GB3IWWEM.js").then((m) => m.de) });
1595
1668
  var pending2 = /* @__PURE__ */ new Map();
1596
1669
  var loaded2 = /* @__PURE__ */ new Map();
1597
1670
  var unusedNow = (lang) => loaded2.get(lang) ?? null;
1598
1671
  function loadUnused(lang) {
1599
1672
  let p = pending2.get(lang);
1600
1673
  if (!p) {
1601
- const own2 = Object.hasOwn(UNUSED_TEXTS_OF, lang) ? UNUSED_TEXTS_OF[lang]().catch(() => null) : null;
1602
- p = Promise.all([import("./chunks/unused-texts-Y4R67XSN.js"), own2]).then(
1674
+ const own = Object.hasOwn(UNUSED_TEXTS_OF, lang) ? UNUSED_TEXTS_OF[lang]().catch(() => null) : null;
1675
+ p = Promise.all([import("./chunks/unused-texts-LRYVWFFN.js"), own]).then(
1603
1676
  ([mod, texts]) => {
1604
1677
  const out = { mod, lang: texts };
1605
1678
  loaded2.set(lang, out);
@@ -1695,7 +1768,7 @@ function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow,
1695
1768
  // src/unused-keep.js
1696
1769
  var PATH = /^([A-Za-z]+)(?:\[(\d+)\])?(?:\.([A-Za-z]+))?/;
1697
1770
  var lower = (v) => typeof v === "string" ? v.toLowerCase() : v;
1698
- var isObject2 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
1771
+ var isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
1699
1772
  function partOf(path, raw, view) {
1700
1773
  const m = PATH.exec(path ?? "");
1701
1774
  if (!m) {
@@ -1704,19 +1777,19 @@ function partOf(path, raw, view) {
1704
1777
  const [, key, index, sub] = m;
1705
1778
  const section = Object.hasOwn(view, key) ? view[key] : void 0;
1706
1779
  if (key === "values" && index !== void 0 && Array.isArray(section)) {
1707
- const given = isObject2(raw) && Array.isArray(
1780
+ const given = isObject(raw) && Array.isArray(
1708
1781
  /** @type {any} */
1709
1782
  raw.values
1710
1783
  ) ? (
1711
1784
  /** @type {any} */
1712
1785
  raw.values[Number(index)]
1713
1786
  ) : void 0;
1714
- const match = isObject2(given) ? section.find((v) => lower(v.field ?? null) === lower(given.field ?? null) && lower(v.agg) === lower(given.agg)) : void 0;
1787
+ const match = isObject(given) ? section.find((v) => lower(v.field ?? null) === lower(given.field ?? null) && lower(v.agg) === lower(given.agg)) : void 0;
1715
1788
  if (match) {
1716
1789
  return JSON.stringify(match);
1717
1790
  }
1718
1791
  }
1719
- if (sub !== void 0 && isObject2(section)) {
1792
+ if (sub !== void 0 && isObject(section)) {
1720
1793
  return JSON.stringify(Object.hasOwn(section, sub) ? section[sub] : void 0);
1721
1794
  }
1722
1795
  return JSON.stringify(section);
@@ -1735,25 +1808,20 @@ function stillApplies(note, loaded3, shown) {
1735
1808
  import React10, { useCallback as useCallback4, useEffect as useEffect8, useMemo as useMemo5, useRef as useRef8, useState as useState8 } from "react";
1736
1809
 
1737
1810
  // src/overflow.js
1738
- var OVERFLOW_ORDER = Object.freeze(["layout", "options", "chartType", "data", "startOver", "views"]);
1739
- var MORE_GROUPS = Object.freeze([Object.freeze(["startOver"]), Object.freeze(["layout", "chartType", "options"]), Object.freeze(["data"]), Object.freeze(["views"])]);
1811
+ var OVERFLOW_ORDER = Object.freeze(["data", "startOver", "views"]);
1812
+ var MORE_GROUPS = Object.freeze([Object.freeze(["startOver"]), Object.freeze(["data"]), Object.freeze(["views"])]);
1740
1813
  var TOOLBAR_ROOM = Object.freeze({
1741
1814
  fields: 6.4,
1742
- display: 15.3,
1743
- chartType: 12.9,
1744
- sep: 1,
1745
1815
  undo: 8.75,
1746
1816
  redo: 9.15,
1747
1817
  startOver: 10.9,
1748
- layout: 8.4,
1749
- options: 8.75,
1750
1818
  data: 7.4,
1751
1819
  views: 9.1,
1752
1820
  export: 7.5,
1753
1821
  more: 7.2
1754
1822
  });
1755
- var TEXT_BUTTONS = Object.freeze(["fields", "undo", "redo", "layout"]);
1756
- var MENU_BUTTONS = Object.freeze(["chartType", "startOver", "options", "data", "views", "export", "more"]);
1823
+ var TEXT_BUTTONS = Object.freeze(["fields", "undo", "redo"]);
1824
+ var MENU_BUTTONS = Object.freeze(["startOver", "data", "views", "export", "more"]);
1757
1825
  function toolbarTexts(labels) {
1758
1826
  const text = (v) => typeof v === "string" ? v : "";
1759
1827
  return (
@@ -1763,22 +1831,18 @@ function toolbarTexts(labels) {
1763
1831
  undo: [text(labels.undo)],
1764
1832
  redo: [text(labels.redo)],
1765
1833
  startOver: [text(labels.startOver)],
1766
- layout: [text(labels.layout)],
1767
- options: [text(labels.options)],
1768
1834
  views: [text(labels.views)],
1769
1835
  data: [text(labels.data)],
1770
1836
  export: [text(labels.exportLabel)],
1771
- more: [text(labels.more)],
1772
- chartType: Object.values(labels.chartTypes ?? {}).map(text),
1773
- display: [[text(labels.table), text(labels.chart)]]
1837
+ more: [text(labels.more)]
1774
1838
  }
1775
1839
  );
1776
1840
  }
1777
1841
  function toolbarRoom(texts, measure, chrome) {
1778
- const widest = (list, kind = "button") => Math.max(0, ...list.map((t) => measure(t, kind)));
1842
+ const widest = (list) => Math.max(0, ...list.map((t) => measure(t)));
1779
1843
  const room = (
1780
1844
  /** @type {Record<string, number>} */
1781
- { sep: chrome.sep + chrome.gap }
1845
+ {}
1782
1846
  );
1783
1847
  for (const id of TEXT_BUTTONS) {
1784
1848
  room[id] = chrome.text + widest(texts[id]) + chrome.gap;
@@ -1786,13 +1850,12 @@ function toolbarRoom(texts, measure, chrome) {
1786
1850
  for (const id of MENU_BUTTONS) {
1787
1851
  room[id] = chrome.menu + widest(texts[id]) + chrome.gap;
1788
1852
  }
1789
- room.display = chrome.display + Math.max(0, ...texts.display.map(([a, b]) => measure(a, "display") + measure(b, "display"))) + chrome.gap;
1790
1853
  return room;
1791
1854
  }
1792
1855
  function overflowHidden(width, narrow, present, room = TOOLBAR_ROOM) {
1793
- const fixed = (narrow ? room.fields : 0) + room.display + room.sep + room.undo + room.redo + room.export;
1856
+ const fixed = (narrow ? room.fields : 0) + room.undo + room.redo + room.export + room.more;
1794
1857
  const order = OVERFLOW_ORDER.filter((id) => present.includes(id));
1795
- const need = (shown2) => fixed + shown2.reduce((sum, id) => sum + (room[id] ?? 0), 0) + (shown2.length < order.length ? room.more : 0);
1858
+ const need = (shown2) => fixed + shown2.reduce((sum, id) => sum + (room[id] ?? 0), 0);
1796
1859
  let shown = order;
1797
1860
  while (shown.length && need(shown) > width) {
1798
1861
  shown = shown.slice(1);
@@ -1824,37 +1887,28 @@ function measuredRoom(el, texts) {
1824
1887
  }
1825
1888
  const undo2 = el.querySelector("[data-testid='undo']");
1826
1889
  const menu = el.querySelector("[data-testid='export']");
1827
- const display = el.querySelector(".pk-segmented");
1828
- const sep = el.querySelector(".pk-sep");
1829
- const textOf = (node) => node?.querySelector(".pk-btn-text, span");
1830
- if (!measuring || !undo2 || !menu || !display || !textOf(undo2) || !textOf(display)) {
1890
+ const textOf = (node) => node?.querySelector(".pk-btn-text");
1891
+ if (!measuring || !undo2 || !menu || !textOf(undo2) || !textOf(menu)) {
1831
1892
  return null;
1832
1893
  }
1833
1894
  const view = doc.defaultView;
1834
1895
  if (!view) {
1835
1896
  return null;
1836
1897
  }
1837
- const fonts = { button: fontOf2(view.getComputedStyle(
1898
+ const font = fontOf2(view.getComputedStyle(
1838
1899
  /** @type {Element} */
1839
1900
  textOf(undo2)
1840
- )), display: fontOf2(view.getComputedStyle(
1841
- /** @type {Element} */
1842
- textOf(display)
1843
- )) };
1901
+ ));
1844
1902
  const ctx = measuring;
1845
- const measure = (text, kind) => {
1846
- ctx.font = fonts[kind];
1903
+ const measure = (text) => {
1904
+ ctx.font = font;
1847
1905
  return ctx.measureText(text).width;
1848
1906
  };
1849
1907
  const w = (node) => node.getBoundingClientRect().width;
1850
1908
  const tw = (node) => node ? node.getBoundingClientRect().width : 0;
1851
- const segTexts = [...display.querySelectorAll("button > span")];
1852
- const sepStyle = sep ? view.getComputedStyle(sep) : null;
1853
1909
  const chrome = {
1854
1910
  text: w(undo2) - tw(textOf(undo2)),
1855
1911
  menu: w(menu) - tw(textOf(menu)),
1856
- display: w(display) - segTexts.reduce((n, s) => n + tw(s), 0),
1857
- sep: sep && sepStyle ? w(sep) + parseFloat(sepStyle.marginLeft) + parseFloat(sepStyle.marginRight) : 0,
1858
1912
  // one more px per part: text widths are fractional, the buttons round them
1859
1913
  gap: (parseFloat(view.getComputedStyle(el).columnGap) || 0) + 1
1860
1914
  };
@@ -1892,8 +1946,8 @@ function useOverflow(ref, key, narrow, present, texts) {
1892
1946
  waiting.current = false;
1893
1947
  const em = parseFloat(getComputedStyle(el).fontSize) || 14;
1894
1948
  const room = measuredRoom(el, latest.current.texts);
1895
- const own2 = latest.current.present;
1896
- setDecided(room ? overflowHidden(width, narrow, own2, room) : overflowHidden(width / em, narrow, own2));
1949
+ const own = latest.current.present;
1950
+ setDecided(room ? overflowHidden(width, narrow, own, room) : overflowHidden(width / em, narrow, own));
1897
1951
  setExtra(0);
1898
1952
  setMeasure((m) => m + 1);
1899
1953
  };
@@ -1929,7 +1983,7 @@ function useOverflow(ref, key, narrow, present, texts) {
1929
1983
  return order.filter((id) => decided.includes(id) || more.includes(id));
1930
1984
  }
1931
1985
  function Toolbar(props) {
1932
- 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;
1986
+ const { view, labels, size, canUndo, canRedo, canReset, startEmpty, canNew, onUndo, onRedo, onReset, onNew, loadedView, empty, templates, onLoadTemplate, templateActions, onExport, chartReady, onShowFields, share } = props;
1933
1987
  const tips = { controls: props.tipsControls, on: props.tipsOn, onOn: props.onTipsOn, canReset: props.canResetTips, onReset: props.onResetTips };
1934
1988
  const bar = useRef8(
1935
1989
  /** @type {HTMLDivElement | null} */
@@ -1944,21 +1998,15 @@ function Toolbar(props) {
1944
1998
  null
1945
1999
  );
1946
2000
  const [panel, setPanel] = useState8(
1947
- /** @type {"options" | "views" | "chartType" | "data" | null} */
2001
+ /** @type {"views" | "data" | null} */
1948
2002
  null
1949
2003
  );
1950
2004
  const data = props.data;
1951
2005
  const texts = useMemo5(() => toolbarTexts(labels), [labels]);
1952
- const plan = props.chartPlan ?? { name: chartTypeOf(view.chart), auto: false };
1953
- const preset = plan.auto ? "auto" : plan.name;
1954
- const drawnIcon = CHART_TYPES[plan.name].icon;
1955
2006
  const mod = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent) ? "\u2318" : "Ctrl+";
1956
- const chartTypeText = fill(labels.chartTypeIs, { type: labels.chartTypes[preset] });
1957
2007
  const panels = {
1958
2008
  // the panels load with the chip menus (menus.js), on demand
1959
- options: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "OptionsPanel", loadingText: labels.loadingMenu, props: { view, labels, onTotal, onExpand, onCollapse, close, tips, mod, folding, help: props.help } }),
1960
2009
  views: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ViewsPanel", loadingText: labels.loadingMenu, props: { templates, labels, onLoad: onLoadTemplate, actions: templateActions, close, share } }),
1961
- chartType: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ChartTypePanel", loadingText: labels.loadingMenu, props: { view, plan, labels, onChart, onDisplay: onChartDisplay, close } }),
1962
2010
  data: (close) => data?.panel(close)
1963
2011
  };
1964
2012
  const loadedMark = (testId) => data?.loaded ? dot(testId, labels.dataLoaded) : null;
@@ -1974,36 +2022,11 @@ function Toolbar(props) {
1974
2022
  }, testId: `${prefix}new-report` }, labels.newEmpty)
1975
2023
  ];
1976
2024
  const actions = {
1977
- chartType: {
1978
- place: "chart",
1979
- button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "chartType", label: chartTypeText, name: chartTypeText, title: chartTypeText, icon: drawnIcon, text: labels.chartTypes[preset], role: "dialog", testId: "chart-type", popoverClass: "pk-chart-menu" }, panels.chartType),
1980
- entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "chartType", inMenu: true, icon: drawnIcon, onSelect: () => {
1981
- close();
1982
- setPanel("chartType");
1983
- }, testId: "more-chart-type" }, `${chartTypeText}\u2026`)
1984
- },
1985
2025
  startOver: {
1986
2026
  place: "history",
1987
2027
  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, "")),
1988
2028
  entry: (close) => startOverItems(close, "more-")
1989
2029
  },
1990
- layout: {
1991
- place: "end",
1992
- // a toggle of the zones: the same text, open or folded; aria-pressed says which
1993
- 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)),
1994
- entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "layout", inMenu: true, checkbox: true, icon: "layout", checked: !layoutFolded, onSelect: () => {
1995
- close();
1996
- onLayout();
1997
- }, testId: "more-layout" }, labels.layout)
1998
- },
1999
- options: {
2000
- place: "end",
2001
- button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "options", label: labels.options, icon: "sliders", text: labels.options, role: "dialog", align: "end", testId: "options" }, panels.options),
2002
- entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "options", inMenu: true, icon: "sliders", onSelect: () => {
2003
- close();
2004
- setPanel("options");
2005
- }, testId: "more-options" }, `${labels.options}\u2026`)
2006
- },
2007
2030
  ...data ? {
2008
2031
  data: {
2009
2032
  place: (
@@ -2028,7 +2051,7 @@ function Toolbar(props) {
2028
2051
  };
2029
2052
  const ORDER = Object.keys(actions);
2030
2053
  const present = OVERFLOW_ORDER.filter((id) => ORDER.includes(id));
2031
- const hiddenList = useOverflow(bar, `${labels.lang}:${labels.undo}:${size}:${present.join()}`, size === "narrow", present, texts);
2054
+ const hiddenList = useOverflow(bar, `${labels.lang}:${labels.undo}:${labels.more}:${size}:${present.join()}`, size === "narrow", present, texts);
2032
2055
  const hidden = new Set(hiddenList);
2033
2056
  if (panel && !hidden.has(panel)) {
2034
2057
  setPanel(null);
@@ -2076,15 +2099,75 @@ function Toolbar(props) {
2076
2099
  /* @__PURE__ */ React10.createElement(Group, { key: ids[0], menu: true, label: ids[0] === "startOver" ? labels.startOver : void 0 }, ids.map((id) => actions[id].entry(close)))
2077
2100
  ] : []
2078
2101
  );
2079
- 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: (
2080
- /** @type {any} */
2081
- drawnIcon
2082
- ) }), /* @__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, dataExport: props.dataExport, 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);
2102
+ 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("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, dataExport: props.dataExport, prepare: props.prepareExport, close } })), /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.more, icon: "more", text: labels.more, role: "dialog", align: "end", testId: "more", buttonRef: more, arrowOpens: true, mark: hidden.has("views") && loadedView?.changed ? changedMark("more-changed") : hidden.has("data") ? loadedMark("more-loaded") : null }, (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "MorePanel", loadingText: labels.loadingMenu, props: { labels, tips, mod, help: props.help, close, foot: hidden.size > 0 ? moreGroups : void 0 } })), wrap ? name : null, panel ? /* @__PURE__ */ React10.createElement(Popover, { open: true, anchor: more, onClose: closePanel, label: panel === "views" ? labels.views : labels.data, role: "dialog", align: "end" }, panels[panel](closePanel)) : null);
2103
+ }
2104
+
2105
+ // src/view-tabs.jsx
2106
+ import React11, { useRef as useRef9 } from "react";
2107
+ var TABS = Object.freeze(
2108
+ /** @type {const} */
2109
+ ["table", "chart"]
2110
+ );
2111
+ var tabId = (panelId, display) => `${panelId}-${display}`;
2112
+ function ViewTabs(props) {
2113
+ const { view, labels, panelId, narrow, onDisplay, plan, big } = props;
2114
+ const list = useRef9(
2115
+ /** @type {HTMLDivElement | null} */
2116
+ null
2117
+ );
2118
+ const chart = view.display === "chart";
2119
+ const settings = chart ? labels.chartSettings : labels.tableSettings;
2120
+ const onKeyDown = (e) => {
2121
+ const tabs = (
2122
+ /** @type {HTMLElement[]} */
2123
+ [...list.current?.querySelectorAll('[role="tab"]') ?? []]
2124
+ );
2125
+ const at = tabs.indexOf(
2126
+ /** @type {HTMLElement} */
2127
+ e.target
2128
+ );
2129
+ const next = at < 0 ? null : tabStep(e.key, at, tabs.length);
2130
+ if (next !== null) {
2131
+ e.preventDefault();
2132
+ tabs[next].focus();
2133
+ }
2134
+ };
2135
+ const iconOnly = (name) => narrow ? { "aria-label": name, title: name } : {};
2136
+ return /* @__PURE__ */ React11.createElement("div", { className: "pk-result-head", "data-testid": "view-tabs-row" }, /* @__PURE__ */ React11.createElement("div", { ref: list, className: "pk-tabs", role: "tablist", "aria-label": labels.view, onKeyDown }, TABS.map((d) => /* @__PURE__ */ React11.createElement(
2137
+ "button",
2138
+ {
2139
+ key: d,
2140
+ type: "button",
2141
+ role: "tab",
2142
+ id: tabId(panelId, d),
2143
+ "aria-selected": view.display === d,
2144
+ "aria-controls": panelId,
2145
+ tabIndex: view.display === d ? 0 : -1,
2146
+ className: "pk-tab",
2147
+ onClick: () => view.display === d ? void 0 : onDisplay(d),
2148
+ "data-testid": `show-${d}`
2149
+ },
2150
+ /* @__PURE__ */ React11.createElement(Icon, { name: (
2151
+ /** @type {any} */
2152
+ d === "table" ? "table" : CHART_TYPES[plan.name].icon
2153
+ ) }),
2154
+ /* @__PURE__ */ React11.createElement("span", null, d === "table" ? labels.table : labels.chart)
2155
+ ))), /* @__PURE__ */ React11.createElement("span", { className: "pk-grow" }), /* @__PURE__ */ React11.createElement(MenuButton, { label: settings, icon: "sliders", text: narrow ? labels.settingsShort : settings, name: narrow ? settings : void 0, title: narrow ? settings : void 0, className: "pk-btn pk-small-btn", role: "dialog", align: "end", testId: "view-settings", popoverClass: chart ? "pk-chart-menu" : void 0 }, (close) => chart ? /* @__PURE__ */ React11.createElement(
2156
+ MenuPanel,
2157
+ {
2158
+ name: "ChartSettingsPanel",
2159
+ loadingText: labels.loadingMenu,
2160
+ props: { view, plan, encoded: props.encoded, lineChecks: props.lineChecks, labels, locale: props.locale, onChart: props.onChart, onDisplay: props.onChartDisplay, close, series: props.chartSeries, colors: props.chartColors, folding: props.folding, onExpand: props.onExpand, onCollapse: props.onCollapse }
2161
+ }
2162
+ ) : /* @__PURE__ */ React11.createElement(MenuPanel, { name: "TableSettingsPanel", loadingText: labels.loadingMenu, props: { view, labels, onTotal: props.onTotal, onExpand: props.onExpand, onCollapse: props.onCollapse, close, folding: props.folding } })), /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "data-pk-on": big.enlarged ? "" : void 0, onClick: big.toggleEnlarged, "data-testid": "enlarge", ...iconOnly(big.enlarged ? labels.reduce : labels.enlarge) }, /* @__PURE__ */ React11.createElement(Icon, { name: "enlarge", size: 14 }), narrow ? null : /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, big.enlarged ? labels.reduce : labels.enlarge)), big.fullOk ? /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "aria-pressed": big.full, onClick: big.toggleFull, "data-testid": "full-screen", ...iconOnly(labels.fullScreen) }, /* @__PURE__ */ React11.createElement(Icon, { name: "fullScreen", size: 14 }), narrow ? null : /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, labels.fullScreen)) : null);
2083
2163
  }
2084
2164
 
2085
2165
  // src/use-export.js
2166
+ import { useCallback as useCallback5 } from "react";
2086
2167
  function useExport(context) {
2087
- return async (kind) => {
2168
+ const { root, loadECharts: loadECharts2 } = context;
2169
+ const prepare = useCallback5((what) => menusNow()?.prepareExport(what, root, loadECharts2), [root, loadECharts2]);
2170
+ const run = async (kind) => {
2088
2171
  try {
2089
2172
  const lang = context.labels.lang;
2090
2173
  const menus = menusNow(lang) ?? await loadMenus(lang);
@@ -2093,11 +2176,11 @@ function useExport(context) {
2093
2176
  context.announce(fill(context.labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
2094
2177
  }
2095
2178
  };
2179
+ return { run, prepare };
2096
2180
  }
2097
- var prepareExporters = () => void loadMenus().then((m) => m.prepareExporters(), () => void 0);
2098
2181
 
2099
2182
  // src/use-theme.js
2100
- import { useCallback as useCallback5, useSyncExternalStore } from "react";
2183
+ import { useCallback as useCallback6, useSyncExternalStore } from "react";
2101
2184
  function hostTheme(el) {
2102
2185
  let node = el;
2103
2186
  while (node) {
@@ -2115,7 +2198,7 @@ function hostTheme(el) {
2115
2198
  }
2116
2199
  var darkQuery = () => typeof matchMedia === "function" ? matchMedia("(prefers-color-scheme: dark)") : null;
2117
2200
  function useResolvedTheme(wanted, ref) {
2118
- const subscribe = useCallback5(
2201
+ const subscribe = useCallback6(
2119
2202
  (onChange) => {
2120
2203
  if (wanted === "light" || wanted === "dark" || typeof document === "undefined") {
2121
2204
  return () => {
@@ -2142,7 +2225,7 @@ function useResolvedTheme(wanted, ref) {
2142
2225
  }
2143
2226
 
2144
2227
  // src/use-view-history.js
2145
- import { useCallback as useCallback6, useMemo as useMemo6, useState as useState9 } from "react";
2228
+ import { useCallback as useCallback7, useMemo as useMemo6, useState as useState9 } from "react";
2146
2229
  import { emptyView, normalize } from "pivotkit-core";
2147
2230
 
2148
2231
  // src/view-history.js
@@ -2201,7 +2284,7 @@ function schemaKeyOf(encoded) {
2201
2284
  function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outsideNote, orderOf, dataKey = 0, initial: initialState = null }) {
2202
2285
  const controlled = view !== void 0;
2203
2286
  const schema = useMemo6(() => `${dataKey}|${schemaKeyOf(encoded)}`, [encoded, dataKey]);
2204
- const json = useCallback6(
2287
+ const json = useCallback7(
2205
2288
  (v) => {
2206
2289
  const normalized = normalize(v ?? emptyView(), encoded, { limits }).view;
2207
2290
  const ordered = orderOf ? withHostOrders(normalized, orderOf) : normalized;
@@ -2231,7 +2314,7 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
2231
2314
  ), [shown]);
2232
2315
  const waiting = viewKey !== null && pending3.length > 0 && state.schema === schema;
2233
2316
  const live = useMemo6(() => waiting ? state : settle(state, { schema, start, shown, outside: outsideNote }), [waiting, state, schema, start, shown, outsideNote]);
2234
- const apply = useCallback6(
2317
+ const apply = useCallback7(
2235
2318
  (next) => {
2236
2319
  setState(next);
2237
2320
  if (viewKey !== null) {
@@ -2241,7 +2324,7 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
2241
2324
  },
2242
2325
  [onViewChange, viewKey, pending3]
2243
2326
  );
2244
- const commit = useCallback6(
2327
+ const commit = useCallback7(
2245
2328
  (next, note, tag) => {
2246
2329
  const s = record(live, json(next), note, tag === void 0 ? live.tag : tag);
2247
2330
  if (s.present === live.present) {
@@ -2255,22 +2338,22 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
2255
2338
  },
2256
2339
  [live, json, apply]
2257
2340
  );
2258
- const setTag = useCallback6((tag) => setState((s) => ({ ...s, tag })), []);
2259
- const undo2 = useCallback6(() => {
2341
+ const setTag = useCallback7((tag) => setState((s) => ({ ...s, tag })), []);
2342
+ const undo2 = useCallback7(() => {
2260
2343
  const { state: s, note } = undo(live);
2261
2344
  if (note !== null) {
2262
2345
  apply(s);
2263
2346
  }
2264
2347
  return note;
2265
2348
  }, [live, apply]);
2266
- const redo2 = useCallback6(() => {
2349
+ const redo2 = useCallback7(() => {
2267
2350
  const { state: s, note } = redo(live);
2268
2351
  if (note !== null) {
2269
2352
  apply(s);
2270
2353
  }
2271
2354
  return note;
2272
2355
  }, [live, apply]);
2273
- const reset2 = useCallback6(
2356
+ const reset2 = useCallback7(
2274
2357
  (note) => {
2275
2358
  const s = reset(live, note);
2276
2359
  if (s.present !== live.present) {
@@ -2281,9 +2364,9 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
2281
2364
  },
2282
2365
  [live, apply]
2283
2366
  );
2284
- const restore = useCallback6((next, tag = null) => apply(createState(schema, start, json(next), tag)), [schema, start, json, apply]);
2285
- const snapshot = useCallback6(() => live, [live]);
2286
- const earlier = useCallback6(() => live.past.map((p) => JSON.parse(p.view)), [live.past]);
2367
+ const restore = useCallback7((next, tag = null) => apply(createState(schema, start, json(next), tag)), [schema, start, json, apply]);
2368
+ const snapshot = useCallback7(() => live, [live]);
2369
+ const earlier = useCallback7(() => live.past.map((p) => JSON.parse(p.view)), [live.past]);
2287
2370
  const canUndo = live.past.length > 0;
2288
2371
  const canRedo = live.future.length > 0;
2289
2372
  const canReset = live.present !== live.start;
@@ -2318,7 +2401,7 @@ function keptData(key, host) {
2318
2401
  }
2319
2402
 
2320
2403
  // src/use-big-result.js
2321
- import { useCallback as useCallback7, useEffect as useEffect9, useRef as useRef9, useState as useState10, useSyncExternalStore as useSyncExternalStore2 } from "react";
2404
+ import { useCallback as useCallback8, useEffect as useEffect9, useRef as useRef10, useState as useState10, useSyncExternalStore as useSyncExternalStore2 } from "react";
2322
2405
  function fullScreenSupported() {
2323
2406
  return typeof document !== "undefined" && Boolean(document.fullscreenEnabled) && typeof HTMLElement !== "undefined" && typeof HTMLElement.prototype.requestFullscreen === "function";
2324
2407
  }
@@ -2341,7 +2424,7 @@ function useBigResult(root) {
2341
2424
  doc.addEventListener("fullscreenchange", sync);
2342
2425
  return () => doc.removeEventListener("fullscreenchange", sync);
2343
2426
  }, [root]);
2344
- const toggleEnlarged = useCallback7(() => setEnlarged((on) => !on), []);
2427
+ const toggleEnlarged = useCallback8(() => setEnlarged((on) => !on), []);
2345
2428
  const toggleFull = () => {
2346
2429
  const el = root.current;
2347
2430
  if (!el) {
@@ -2358,11 +2441,23 @@ function useBigResult(root) {
2358
2441
  };
2359
2442
  return { enlarged, setEnlarged, toggleEnlarged, full, fullOk, toggleFull };
2360
2443
  }
2361
- function useFitHeight(root, main, grow) {
2362
- const fit = useRef9({ need: 0, open: 0, grow });
2444
+ function useFitHeight(root, main, grow, onOpen) {
2445
+ const fit = useRef10(
2446
+ /** @type {FitState} */
2447
+ { need: 0, open: 0, grow, folded: null, size: null }
2448
+ );
2449
+ const opened = useRef10(onOpen);
2450
+ const watch = useRef10(
2451
+ /** @type {{ ro: ResizeObserver | null, parts: Set<Element> }} */
2452
+ { ro: null, parts: /* @__PURE__ */ new Set() }
2453
+ );
2363
2454
  useIsoLayoutEffect(() => {
2455
+ opened.current = onOpen;
2364
2456
  fit.current.grow = grow;
2365
- measureFit(root.current, main.current, fit);
2457
+ watchParts(watch.current, main.current);
2458
+ if (measureFit(root.current, main.current, fit)) {
2459
+ opened.current?.();
2460
+ }
2366
2461
  });
2367
2462
  useIsoLayoutEffect(() => {
2368
2463
  const el = root.current;
@@ -2372,26 +2467,72 @@ function useFitHeight(root, main, grow) {
2372
2467
  let frame = 0;
2373
2468
  const ro = new ResizeObserver(() => {
2374
2469
  cancelAnimationFrame(frame);
2375
- frame = requestAnimationFrame(() => measureFit(root.current, main.current, fit));
2470
+ frame = requestAnimationFrame(() => {
2471
+ if (measureFit(root.current, main.current, fit)) {
2472
+ opened.current?.();
2473
+ }
2474
+ });
2376
2475
  });
2377
2476
  ro.observe(el);
2477
+ const w = watch.current;
2478
+ w.ro = ro;
2479
+ watchParts(w, main.current);
2378
2480
  return () => {
2379
2481
  cancelAnimationFrame(frame);
2380
2482
  ro.disconnect();
2483
+ w.ro = null;
2484
+ w.parts = /* @__PURE__ */ new Set();
2381
2485
  };
2382
2486
  }, [root, main]);
2383
2487
  return fit;
2384
2488
  }
2489
+ function watchParts(w, m) {
2490
+ if (!w.ro || !m) {
2491
+ return;
2492
+ }
2493
+ const now = new Set(m.children);
2494
+ for (const part of w.parts) {
2495
+ if (!now.has(part)) {
2496
+ w.ro.unobserve(part);
2497
+ }
2498
+ }
2499
+ for (const part of now) {
2500
+ if (!w.parts.has(part)) {
2501
+ w.ro.observe(part);
2502
+ }
2503
+ }
2504
+ w.parts = now;
2505
+ }
2385
2506
  function measureFit(el, m, fit) {
2386
2507
  const result = m?.querySelector(":scope > .pk-result");
2387
2508
  if (!el || !m || !(result instanceof HTMLElement)) {
2388
- return;
2509
+ return false;
2389
2510
  }
2390
2511
  const least = parseFloat(el.ownerDocument.defaultView?.getComputedStyle(result).getPropertyValue("--pk-result-least") ?? "") || 0;
2391
2512
  const needMain = m.scrollHeight - result.offsetHeight + least;
2392
2513
  const need = Math.ceil(el.offsetHeight - m.clientHeight + needMain);
2393
- if (!el.hasAttribute("data-pk-layout") && !el.hasAttribute("data-pk-enlarged")) {
2394
- fit.current.open = need;
2514
+ const f = fit.current;
2515
+ const size = el.getAttribute("data-pk-size");
2516
+ let changed = false;
2517
+ if (size !== f.size) {
2518
+ changed = f.open > 0;
2519
+ f.size = size;
2520
+ f.folded = null;
2521
+ f.open = 0;
2522
+ }
2523
+ let open = f.open;
2524
+ if (el.hasAttribute("data-pk-enlarged")) {
2525
+ f.folded = null;
2526
+ } else if (!el.hasAttribute("data-pk-layout")) {
2527
+ f.folded = null;
2528
+ open = need;
2529
+ } else if (f.open > 0) {
2530
+ f.folded ??= { need, open: f.open };
2531
+ open = f.folded.open - (f.folded.need - need);
2532
+ }
2533
+ if (Math.abs(open - f.open) > 1) {
2534
+ f.open = open;
2535
+ changed = true;
2395
2536
  }
2396
2537
  if (!fit.current.grow) {
2397
2538
  fit.current.need = 0;
@@ -2400,10 +2541,11 @@ function measureFit(el, m, fit) {
2400
2541
  fit.current.need = need;
2401
2542
  el.style.minHeight = `${need}px`;
2402
2543
  }
2544
+ return changed;
2403
2545
  }
2404
2546
 
2405
2547
  // src/zones.jsx
2406
- import React11, { useCallback as useCallback8, useEffect as useEffect10, useMemo as useMemo7, useRef as useRef10, useState as useState11 } from "react";
2548
+ import React12, { useCallback as useCallback9, useEffect as useEffect10, useId as useId4, useMemo as useMemo7, useRef as useRef11, useState as useState11 } from "react";
2407
2549
  import { fieldItems, fieldLabel as fieldLabel4 } from "pivotkit-core";
2408
2550
  function fieldState(view, field, encoded, locale, labels, sourceType) {
2409
2551
  const items = filtersOf(view, field, ["in"]).filter((f) => !isEmptyPick(f));
@@ -2447,47 +2589,48 @@ function Badges({ state, view, labels, locale }) {
2447
2589
  if (state.summary) {
2448
2590
  const text = fill(labels.filterSummary, { shown: state.summary.shown.toLocaleString(locale), total: state.summary.total.toLocaleString(locale) });
2449
2591
  parts.push(
2450
- /* @__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)
2592
+ /* @__PURE__ */ React12.createElement("span", { key: "filter", className: "pk-chip-badge pk-badge-text", "aria-hidden": "true" }, /* @__PURE__ */ React12.createElement(Icon, { name: "filter", size: 12 }), text)
2451
2593
  );
2452
2594
  }
2453
2595
  if (state.rules.length) {
2454
2596
  const more = state.rules.length - 1;
2455
2597
  parts.push(
2456
- /* @__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)
2598
+ /* @__PURE__ */ React12.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__ */ React12.createElement(Icon, { name: "filter", size: 12 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-badge-cut" }, state.rules[0]), more ? /* @__PURE__ */ React12.createElement("span", null, ` +${more.toLocaleString(locale)}`) : null)
2457
2599
  );
2458
2600
  }
2459
2601
  if (state.top) {
2460
2602
  const text = fill(state.top.bottom ? labels.bottomBadge : labels.topBadge, { count: state.top.count.toLocaleString(locale) });
2461
2603
  parts.push(
2462
- /* @__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)
2604
+ /* @__PURE__ */ React12.createElement("span", { key: "top", className: "pk-chip-badge pk-badge-text", "data-testid": "top-badge", "aria-hidden": "true" }, /* @__PURE__ */ React12.createElement(Icon, { name: "top", size: 12 }), text)
2463
2605
  );
2464
2606
  }
2465
2607
  if (state.condition) {
2466
2608
  const text = valueConditionText(view, state.condition, labels, locale);
2467
2609
  parts.push(
2468
- /* @__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))
2610
+ /* @__PURE__ */ React12.createElement("span", { key: "condition", className: "pk-chip-badge pk-badge-text pk-badge-condition", "data-testid": "condition-badge", "aria-hidden": "true" }, /* @__PURE__ */ React12.createElement(Icon, { name: "filter", size: 12 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-badge-cut" }, text))
2469
2611
  );
2470
2612
  }
2471
2613
  if (state.sort) {
2472
2614
  const desc = state.sort.order === "desc";
2473
- parts.push(/* @__PURE__ */ React11.createElement(Icon, { key: "sort", name: desc ? "sortDesc" : "sortAsc", size: 12, className: "pk-chip-badge" }));
2615
+ parts.push(/* @__PURE__ */ React12.createElement(Icon, { key: "sort", name: desc ? "sortDesc" : "sortAsc", size: 12, className: "pk-chip-badge" }));
2474
2616
  }
2475
- return parts.length ? /* @__PURE__ */ React11.createElement(React11.Fragment, null, parts) : null;
2617
+ return parts.length ? /* @__PURE__ */ React12.createElement(React12.Fragment, null, parts) : null;
2476
2618
  }
2477
- function Chip({ id, zone, index, count, field, text, typeName, view, types, labels, commit, onRemove, state, locale, defaultsOf, earlier, rangeOf, info, showInfo, encoded }) {
2619
+ function Chip({ id, zone, index, count, field, text, title, typeName, view, types, labels, commit, onRemove, state, locale, defaultsOf, earlier, rangeOf, info, showInfo, encoded }) {
2478
2620
  const { setNodeRef, isDragging, style, itemProps, handleProps } = useChip(id, { kind: "chip", zone, index, count, field, label: text, type: typeName });
2479
- const badges = state ? /* @__PURE__ */ React11.createElement(Badges, { state, view, labels, locale }) : null;
2621
+ const badges = state ? /* @__PURE__ */ React12.createElement(Badges, { state, view, labels, locale }) : null;
2480
2622
  const words = stateWords(state, view, labels, locale);
2481
- const name = words ? `${text}, ${words}` : void 0;
2623
+ const full = title ?? text;
2624
+ const name = words ? `${full}, ${words}` : title;
2482
2625
  const remove = () => onRemove(zone, index, text);
2483
- 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: (
2626
+ return /* @__PURE__ */ React12.createElement("li", { ref: setNodeRef, style, className: `pk-chip pk-chip-${zone}${isDragging ? " pk-dragging" : ""}`, ...itemProps, "data-chip": text }, /* @__PURE__ */ React12.createElement("span", { className: "pk-handle", ...handleProps, "aria-label": fill(labels.dragHandle, { field: text }) }, /* @__PURE__ */ React12.createElement(Icon, { name: "grip", size: 16 })), /* @__PURE__ */ React12.createElement("span", { className: `pk-type pk-type-${typeName}`, "aria-hidden": "true" }, /* @__PURE__ */ React12.createElement(Icon, { name: (
2484
2627
  /** @type {any} */
2485
2628
  TYPE_ICON[typeName] ?? "text"
2486
- ), size: 13 })), /* @__PURE__ */ React11.createElement(
2629
+ ), size: 13 })), /* @__PURE__ */ React12.createElement(
2487
2630
  MenuButton,
2488
2631
  {
2489
2632
  label: fill(labels.fieldMenu, { field: text }),
2490
- text: /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement("span", { className: "pk-chip-name" }, text), badges),
2633
+ text: /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement("span", { className: "pk-chip-name" }, text), badges),
2491
2634
  className: "pk-chip-label",
2492
2635
  name,
2493
2636
  title: name ?? text,
@@ -2496,10 +2639,14 @@ function Chip({ id, zone, index, count, field, text, typeName, view, types, labe
2496
2639
  fill: true,
2497
2640
  testId: `chip-menu-${text}`
2498
2641
  },
2499
- (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 } })
2500
- ), 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 })));
2642
+ (close) => zone === "values" ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "ValueMenu", loadingText: labels.loadingMenu, props: { view, index, types, labels, commit, close, onRemove: remove, defaultsOf, info, locale, earlier } }) : zone === "filters" ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "FilterMenu", loadingText: labels.loadingMenu, props: { view, index, field, types, labels, commit, close, onRemove: remove, locale, info, state, encoded } }) : /* @__PURE__ */ React12.createElement(MenuPanel, { name: "AxisMenu", loadingText: labels.loadingMenu, props: { view, zone, index, field, types, labels, commit, close, onRemove: remove, defaultsOf, rangeOf, locale, info, state, encoded } })
2643
+ ), info && showInfo ? /* @__PURE__ */ React12.createElement(InfoButton, { info, name: fieldLabel4(sourceOf(view, field), labels.core), labels, className: "pk-chip-info" }) : null, /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-chip-x", onClick: remove, "aria-label": fill(labels.removeField, { field: text }), title: fill(labels.removeField, { field: text }) }, /* @__PURE__ */ React12.createElement(Icon, { name: "x", size: 14 })));
2644
+ }
2645
+ function AddButton({ zone, labels, menu }) {
2646
+ const name = fill(labels.addFieldTo, { zone: labels.zones[zone] });
2647
+ return /* @__PURE__ */ React12.createElement(MenuButton, { label: name, name, title: name, icon: "plus", text: labels.addField, className: "pk-zone-add", role: "dialog", popoverClass: "pk-chip-menu", fill: true, testId: `add-field-${zone}` }, (close) => /* @__PURE__ */ React12.createElement(MenuPanel, { name: "AddMenu", loadingText: labels.loadingMenu, props: { ...menu, labels, zone, close } }));
2501
2648
  }
2502
- function Zone({ zone, entries, labels, children, action, explain }) {
2649
+ function Zone({ zone, entries, labels, children, explain, add }) {
2503
2650
  const count = entries.length;
2504
2651
  const { setNodeRef, isOver } = useDropTarget(`zone:${zone}`, { kind: "zone", zone, count });
2505
2652
  const active = useActiveDrag();
@@ -2519,11 +2666,13 @@ function Zone({ zone, entries, labels, children, action, explain }) {
2519
2666
  const t = setTimeout(() => setFlash(false), 600);
2520
2667
  return () => clearTimeout(t);
2521
2668
  }, [flash]);
2522
- return /* @__PURE__ */ React11.createElement("section", { ref: setNodeRef, tabIndex: -1, className: `pk-zone pk-zone-${zone}${isOver ? " pk-over" : ""}${dragging ? " pk-dropping" : ""}${flash ? " pk-flash" : ""}`, "aria-label": labels.zones[zone], "data-zone": zone }, /* @__PURE__ */ React11.createElement("div", { className: "pk-zone-head" }, /* @__PURE__ */ React11.createElement("h3", { className: "pk-zone-title" }, /* @__PURE__ */ React11.createElement(Icon, { name: (
2669
+ return /* @__PURE__ */ React12.createElement("section", { ref: setNodeRef, tabIndex: -1, className: `pk-zone pk-zone-${zone}${isOver ? " pk-over" : ""}${dragging ? " pk-dropping" : ""}${flash ? " pk-flash" : ""}`, "aria-label": labels.zones[zone], "data-zone": zone }, /* @__PURE__ */ React12.createElement("div", { className: "pk-zone-head" }, /* @__PURE__ */ React12.createElement("h3", { className: "pk-zone-title" }, /* @__PURE__ */ React12.createElement(Icon, { name: (
2523
2670
  /** @type {any} */
2524
2671
  ZONE_ICON[zone]
2525
- ), size: 14 }), labels.zones[zone]), explain ? /* @__PURE__ */ React11.createElement(InfoButton, { info: { description: labels.zoneInfo[zone] }, name: labels.zones[zone], labels, className: "pk-zone-info", testId: `zone-info-${zone}` }) : null, /* @__PURE__ */ React11.createElement("span", { className: "pk-grow" }), action), /* @__PURE__ */ React11.createElement(ChipList, { ids: entries.map((e) => e.id) }, /* @__PURE__ */ React11.createElement("ul", { className: "pk-chips" }, children, count === 0 ? /* @__PURE__ */ React11.createElement("li", { className: "pk-zone-hint" }, labels.zoneHints[zone]) : null)));
2672
+ ), size: 14 }), labels.zones[zone]), explain ? /* @__PURE__ */ React12.createElement(InfoButton, { info: { description: labels.zoneInfo[zone] }, name: labels.zones[zone], labels, className: "pk-zone-info", testId: `zone-info-${zone}` }) : null, add ? /* @__PURE__ */ React12.createElement(AddButton, { zone, labels, menu: add }) : null), /* @__PURE__ */ React12.createElement(ChipList, { ids: entries.map((e) => e.id) }, /* @__PURE__ */ React12.createElement("ul", { className: "pk-chips" }, children, count === 0 ? /* @__PURE__ */ React12.createElement("li", { className: "pk-zone-hint" }, labels.zoneHints[zone]) : null)));
2526
2673
  }
2674
+ var SAY_AFTER = 100;
2675
+ var SAY_FOR = 8e3;
2527
2676
  function zoneEntries(view, types, labels) {
2528
2677
  const typeOf = (f) => types.get(String(sourceOf(view, f)).toLowerCase()) ?? "string";
2529
2678
  const seen = /* @__PURE__ */ new Map();
@@ -2533,24 +2682,44 @@ function zoneEntries(view, types, labels) {
2533
2682
  filters: filterZoneFields(view).map((f, i) => ({ id: `chip:filters:${f}`, field: f, text: text(f), type: typeOf(f), index: i })),
2534
2683
  cols: axis("cols"),
2535
2684
  rows: axis("rows"),
2536
- values: view.values.map((v, i) => {
2685
+ values: valueLabels(view.values, labels).map((text2, i) => {
2686
+ const v = view.values[i];
2537
2687
  const key = `${v.agg}:${v.field}`;
2538
2688
  seen.set(key, (seen.get(key) ?? 0) + 1);
2539
- return { id: `chip:values:${key}:${seen.get(key)}`, field: v.field, text: valueLabel(v, labels), type: v.field ? typeOf(v.field) : "number", index: i };
2689
+ return { id: `chip:values:${key}:${seen.get(key)}`, field: v.field, text: text2, type: v.field ? typeOf(v.field) : "number", index: i };
2540
2690
  })
2541
2691
  };
2542
2692
  }
2543
- function ZoneSummary({ entries, labels, id, onShow, buttonRef }) {
2693
+ function SectionHead({ entries, labels, id, open, onFold, onSwap, canSwap, buttonRef, explain }) {
2694
+ const own = useId4();
2544
2695
  const parts = layoutSummary(entries, labels);
2545
2696
  const text = parts.length ? parts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
2546
- 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));
2697
+ return /* @__PURE__ */ React12.createElement("div", { className: "pk-section-row" }, /* @__PURE__ */ React12.createElement(
2698
+ "button",
2699
+ {
2700
+ ref: buttonRef,
2701
+ type: "button",
2702
+ className: "pk-section-fold",
2703
+ "aria-expanded": open,
2704
+ "aria-controls": open ? id : void 0,
2705
+ "aria-labelledby": `${own}-t`,
2706
+ "aria-describedby": open ? void 0 : `${own}-s`,
2707
+ title: open ? void 0 : text,
2708
+ onClick: onFold,
2709
+ "data-testid": "layout-summary"
2710
+ },
2711
+ /* @__PURE__ */ React12.createElement(Icon, { name: "chevronRight", className: "pk-section-chevron" }),
2712
+ /* @__PURE__ */ React12.createElement("span", { id: `${own}-t`, className: "pk-section-heading" }, labels.zonesTitle)
2713
+ ), explain ? /* @__PURE__ */ React12.createElement(InfoButton, { info: { description: labels.zonesHint }, name: labels.zonesTitle, labels, className: "pk-section-info", testId: "zones-info" }) : null, open ? /* @__PURE__ */ React12.createElement("span", { className: "pk-grow" }) : (
2714
+ // the button's description and a larger target for the pointer; the keys use the button
2715
+ /* @__PURE__ */ React12.createElement("span", { id: `${own}-s`, className: "pk-section-sub", onClick: onFold, "data-testid": "zones-sub" }, parts.length ? parts.map((p, i) => /* @__PURE__ */ React12.createElement(React12.Fragment, { key: p.zone }, i ? " \xB7 " : null, /* @__PURE__ */ React12.createElement("span", { className: "pk-zones-summary-zone" }, p.title, ":"), " ", p.fields)) : labels.layoutEmpty)
2716
+ ), /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-small-btn pk-swap", onClick: onSwap, disabled: !canSwap, "data-testid": "swap", title: labels.swap }, /* @__PURE__ */ React12.createElement(Icon, { name: "swap", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, labels.swap)));
2547
2717
  }
2548
- function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap, id, folded, onShow, defaultsOf, infoOf, explain = false, showInfo = true }) {
2718
+ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap, id, folded, onFold, defaultsOf, infoOf, titleOf, explain = false, showInfo = true, adding }) {
2549
2719
  const entries = useMemo7(() => zoneEntries(view, types, labels), [view, types, labels]);
2550
2720
  const dragging = Boolean(useActiveDrag());
2551
- const showing = useRef10(false);
2552
- const focusInside = useRef10(false);
2553
- const summary = useRef10(
2721
+ const focusInside = useRef11(false);
2722
+ const summary = useRef11(
2554
2723
  /** @type {HTMLButtonElement | null} */
2555
2724
  null
2556
2725
  );
@@ -2563,12 +2732,12 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2563
2732
  }
2564
2733
  return map;
2565
2734
  }, [entries, view, encoded, locale, labels]);
2566
- const rangeOf = useCallback8((field) => numberRange(encoded, field), [encoded]);
2567
- const root = useRef10(
2735
+ const rangeOf = useCallback9((field) => numberRange(encoded, field), [encoded]);
2736
+ const root = useRef11(
2568
2737
  /** @type {HTMLDivElement | null} */
2569
2738
  null
2570
2739
  );
2571
- const focusAfter = useRef10(
2740
+ const focusAfter = useRef11(
2572
2741
  /** @type {{ zone: string, index: number } | null} */
2573
2742
  null
2574
2743
  );
@@ -2590,32 +2759,57 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2590
2759
  );
2591
2760
  target?.focus({ preventScroll: true });
2592
2761
  });
2762
+ const added = useRef11(
2763
+ /** @type {{ zone: string, from: string | null, ids: Set<string> } | null} */
2764
+ null
2765
+ );
2766
+ const [said, setSaid] = useState11("");
2767
+ const sayTimers = useRef11(
2768
+ /** @type {ReturnType<typeof setTimeout>[]} */
2769
+ []
2770
+ );
2771
+ useEffect10(() => () => sayTimers.current.forEach(clearTimeout), []);
2593
2772
  useEffect10(() => {
2594
- if (showing.current && !folded) {
2595
- showing.current = false;
2596
- root.current?.querySelector("[data-zone]")?.focus({ preventScroll: true });
2773
+ const at = added.current;
2774
+ if (!at) {
2775
+ return;
2776
+ }
2777
+ added.current = null;
2778
+ const fresh = entries[at.zone].find((e) => !at.ids.has(e.id));
2779
+ if (!fresh) {
2780
+ return;
2597
2781
  }
2782
+ const chip = root.current?.querySelectorAll(`[data-zone="${at.zone}"] .pk-chip`)[fresh.index];
2783
+ chip?.querySelector(".pk-chip-label")?.focus({ preventScroll: true });
2784
+ const text = fill(at.from ? labels.movedFrom : labels.steps.added, { field: fresh.text, zone: labels.zones[at.zone], from: at.from ? labels.zones[at.from] : "" });
2785
+ sayTimers.current.forEach(clearTimeout);
2786
+ setSaid("");
2787
+ sayTimers.current = [setTimeout(() => setSaid(text), SAY_AFTER), setTimeout(() => setSaid(""), SAY_FOR)];
2788
+ }, [entries, labels]);
2789
+ const addMenu = useMemo7(
2790
+ () => adding ? {
2791
+ ...adding,
2792
+ view,
2793
+ commit,
2794
+ encoded,
2795
+ locale,
2796
+ onAdded: (zone) => (from, run) => {
2797
+ added.current = { zone, from, ids: new Set(entries[zone].map((e) => e.id)) };
2798
+ if (!run()) {
2799
+ added.current = null;
2800
+ }
2801
+ }
2802
+ } : null,
2803
+ [adding, view, commit, encoded, locale, entries]
2804
+ );
2805
+ useEffect10(() => {
2598
2806
  if (folded && focusInside.current) {
2599
2807
  focusInside.current = false;
2600
2808
  summary.current?.focus({ preventScroll: true });
2601
2809
  }
2602
2810
  }, [folded]);
2603
- if (folded && !dragging) {
2604
- return /* @__PURE__ */ React11.createElement(
2605
- ZoneSummary,
2606
- {
2607
- entries,
2608
- labels,
2609
- id,
2610
- buttonRef: summary,
2611
- onShow: () => {
2612
- showing.current = true;
2613
- onShow();
2614
- }
2615
- }
2616
- );
2617
- }
2618
- return /* @__PURE__ */ React11.createElement(
2811
+ const open = !folded || dragging;
2812
+ return /* @__PURE__ */ React12.createElement("div", { className: "pk-zone-section", "data-pk-open": open ? "" : void 0, "data-testid": "zone-section" }, /* @__PURE__ */ React12.createElement(SectionHead, { entries, labels, id, open, onFold, onSwap, canSwap: view.rows.length + view.cols.length > 0, buttonRef: summary, explain }), /* @__PURE__ */ React12.createElement("span", { className: "pk-sr", role: "status", "data-testid": "zones-status" }, said), open ? /* @__PURE__ */ React12.createElement(
2619
2813
  "div",
2620
2814
  {
2621
2815
  className: "pk-zones",
@@ -2633,7 +2827,7 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2633
2827
  }
2634
2828
  }
2635
2829
  },
2636
- ZONES.map((zone) => /* @__PURE__ */ React11.createElement(
2830
+ ZONES.map((zone) => /* @__PURE__ */ React12.createElement(
2637
2831
  Zone,
2638
2832
  {
2639
2833
  key: zone,
@@ -2641,12 +2835,9 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2641
2835
  entries: entries[zone],
2642
2836
  labels,
2643
2837
  explain,
2644
- action: zone === "cols" ? (
2645
- // the text goes when the zone is too narrow (styles.css): the title keeps it as a tooltip
2646
- /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-link pk-swap", onClick: onSwap, disabled: view.rows.length + view.cols.length === 0, "data-testid": "swap", title: labels.swap }, /* @__PURE__ */ React11.createElement(Icon, { name: "swap", size: 14 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, labels.swap))
2647
- ) : null
2838
+ add: addMenu ? { ...addMenu, onAdded: addMenu.onAdded(zone) } : null
2648
2839
  },
2649
- entries[zone].map((e) => /* @__PURE__ */ React11.createElement(
2840
+ entries[zone].map((e) => /* @__PURE__ */ React12.createElement(
2650
2841
  Chip,
2651
2842
  {
2652
2843
  key: e.id,
@@ -2656,6 +2847,7 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2656
2847
  count: entries[zone].length,
2657
2848
  field: e.field,
2658
2849
  text: e.text,
2850
+ title: e.field ? titleOf?.(e.field) : void 0,
2659
2851
  typeName: e.type,
2660
2852
  view,
2661
2853
  types,
@@ -2673,7 +2865,7 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2673
2865
  }
2674
2866
  ))
2675
2867
  ))
2676
- );
2868
+ ) : null);
2677
2869
  }
2678
2870
 
2679
2871
  // src/PivotReport.jsx
@@ -2684,6 +2876,7 @@ function sizeOf(width) {
2684
2876
  var COMPACT_HEIGHT = 600;
2685
2877
  var COMPACT_HEIGHT_NARROW = 820;
2686
2878
  var compactAt = (size, height) => height < (size === "narrow" ? COMPACT_HEIGHT_NARROW : COMPACT_HEIGHT);
2879
+ var zonesStart = (zones) => zones === "folded" ? true : zones === "open" ? false : null;
2687
2880
  var layerOpen = (layer) => Boolean(layer && [...layer.children].some((c) => !c.classList.contains("pk-origin")));
2688
2881
  function measured(name, fn) {
2689
2882
  const t0 = typeof performance !== "undefined" ? performance.now() : 0;
@@ -2761,19 +2954,19 @@ function PivotReport(props) {
2761
2954
  setStarted(true);
2762
2955
  }
2763
2956
  if (waiting && !started) {
2764
- return /* @__PURE__ */ React12.createElement(WaitingReport, { ...props });
2957
+ return /* @__PURE__ */ React13.createElement(WaitingReport, { ...props });
2765
2958
  }
2766
- return /* @__PURE__ */ React12.createElement(Report, { ...props });
2959
+ return /* @__PURE__ */ React13.createElement(Report, { ...props });
2767
2960
  }
2768
2961
  function WaitingReport({ locale = "en-US", labels: customLabels, theme = "auto", height = 640, className, label }) {
2769
- const root = useRef11(
2962
+ const root = useRef12(
2770
2963
  /** @type {HTMLDivElement | null} */
2771
2964
  null
2772
2965
  );
2773
2966
  const labelsKey = JSON.stringify(customLabels ?? null);
2774
2967
  const labels = useMemo8(() => resolveLabels(locale, JSON.parse(labelsKey)), [locale, labelsKey]);
2775
2968
  const themeName = useResolvedTheme(theme, root);
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 }));
2969
+ return /* @__PURE__ */ React13.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__ */ React13.createElement(Skeleton, { full: true, text: labels.loadingReport }));
2777
2970
  }
2778
2971
  function keyOfHostView(view) {
2779
2972
  try {
@@ -2784,7 +2977,7 @@ function keyOfHostView(view) {
2784
2977
  }
2785
2978
  var staysTheSame = () => () => void 0;
2786
2979
  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);
2980
+ return /* @__PURE__ */ React13.createElement("div", { className: "pk-empty", "data-testid": "empty-state" }, /* @__PURE__ */ React13.createElement("div", { className: "pk-empty-art", "aria-hidden": "true" }, /* @__PURE__ */ React13.createElement("span", { className: "pk-empty-chip pk-c1" }), /* @__PURE__ */ React13.createElement("span", { className: "pk-empty-chip pk-c2" }), /* @__PURE__ */ React13.createElement("span", { className: "pk-empty-chip pk-c3" })), /* @__PURE__ */ React13.createElement("h2", null, noData ? labels.emptyNoData : labels.emptyTitle), noData ? null : /* @__PURE__ */ React13.createElement("ol", { className: "pk-steps" }, labels.emptySteps.map((s, i) => /* @__PURE__ */ React13.createElement("li", { key: i }, /* @__PURE__ */ React13.createElement("span", { className: "pk-step-n", "aria-hidden": "true" }, i + 1), /* @__PURE__ */ React13.createElement("span", null, s)))), onLoad ? /* @__PURE__ */ React13.createElement("div", { className: "pk-drop-zone", "data-testid": "empty-drop" }, /* @__PURE__ */ React13.createElement("p", null, noData ? labels.emptyDrop : labels.emptyLoad), /* @__PURE__ */ React13.createElement("button", { type: "button", className: "pk-btn", onClick: onLoad, "data-testid": "empty-load" }, /* @__PURE__ */ React13.createElement(Icon, { name: "upload" }), /* @__PURE__ */ React13.createElement("span", { className: "pk-btn-text" }, labels.loadData))) : null, templates.length ? /* @__PURE__ */ React13.createElement("div", { className: "pk-empty-actions" }, templates.slice(0, 3).map((t, i) => /* @__PURE__ */ React13.createElement("button", { key: `${i}:${t.name}`, type: "button", className: "pk-btn", onClick: () => onTemplate(t) }, /* @__PURE__ */ React13.createElement(Icon, { name: "sparkle" }), /* @__PURE__ */ React13.createElement("span", { className: "pk-btn-text" }, fill(labels.tryView, { name: t.name }))))) : null);
2788
2981
  }
2789
2982
  function Report(props) {
2790
2983
  const {
@@ -2815,12 +3008,14 @@ function Report(props) {
2815
3008
  fieldDefaults,
2816
3009
  onExport,
2817
3010
  exportData = false,
3011
+ drillDownExport = false,
2818
3012
  label,
2819
3013
  tips: tipsProp = "on",
2820
3014
  storageKey,
2821
3015
  dismissedTips,
2822
3016
  onTipDismiss,
2823
3017
  chartOptions,
3018
+ colorMap,
2824
3019
  shareLink,
2825
3020
  persistView,
2826
3021
  fieldInfo: fieldInfoProp,
@@ -2832,6 +3027,7 @@ function Report(props) {
2832
3027
  schemaUrl,
2833
3028
  grow: growProp,
2834
3029
  fieldList,
3030
+ zones: zonesProp,
2835
3031
  loading: loading2 = false,
2836
3032
  allowImport = false,
2837
3033
  plugins: pluginsProp,
@@ -2845,14 +3041,14 @@ function Report(props) {
2845
3041
  /** @type {import("./import-host.jsx").ImportJob | null} */
2846
3042
  null
2847
3043
  );
2848
- const afterSheet = useRef11(
3044
+ const afterSheet = useRef12(
2849
3045
  /** @type {(() => void) | null} */
2850
3046
  null
2851
3047
  );
2852
3048
  const [dragging, setDragging] = useState12(false);
2853
- const dragDepth = useRef11(0);
3049
+ const dragDepth = useRef12(0);
2854
3050
  const [importMod, setImportMod] = useState12(importNow);
2855
- const fileInput = useRef11(
3051
+ const fileInput = useRef12(
2856
3052
  /** @type {HTMLInputElement | null} */
2857
3053
  null
2858
3054
  );
@@ -2866,7 +3062,7 @@ function Report(props) {
2866
3062
  const hostLimits = useMemo8(() => JSON.parse(limitsKey) ?? void 0, [limitsKey]);
2867
3063
  const importLimitsKey = JSON.stringify(importLimitsProp ?? null);
2868
3064
  const fileLimits = useMemo8(() => importLimitsOf(hostLimits, JSON.parse(importLimitsKey)), [hostLimits, importLimitsKey]);
2869
- const root = useRef11(
3065
+ const root = useRef12(
2870
3066
  /** @type {HTMLDivElement | null} */
2871
3067
  null
2872
3068
  );
@@ -2880,11 +3076,17 @@ function Report(props) {
2880
3076
  const [short, setShort] = useState12(false);
2881
3077
  const [folded, setFolded] = useState12(
2882
3078
  /** @type {boolean | null} */
2883
- null
3079
+ zonesStart(zonesProp)
2884
3080
  );
2885
- const layoutFolded = folded ?? short;
2886
- const zonesId = useId4();
2887
- const ownPrefix = useRef11(
3081
+ const foldOpenWhileEmpty = useRef12(false);
3082
+ const [zonesSeen, setZonesSeen] = useState12(zonesProp);
3083
+ if (zonesProp !== zonesSeen) {
3084
+ setZonesSeen(zonesProp);
3085
+ setFolded(zonesStart(zonesProp));
3086
+ }
3087
+ const zonesId = useId5();
3088
+ const resultId = useId5();
3089
+ const ownPrefix = useRef12(
2888
3090
  /** @type {string | null} */
2889
3091
  null
2890
3092
  );
@@ -2899,7 +3101,7 @@ function Report(props) {
2899
3101
  null
2900
3102
  );
2901
3103
  const [hinted, setHinted] = useState12(false);
2902
- const changesRef = useRef11(0);
3104
+ const changesRef = useRef12(0);
2903
3105
  const [changes, setChanges] = useState12(0);
2904
3106
  const [dragAt, setDragAt] = useState12(
2905
3107
  /** @type {number | null} */
@@ -2927,12 +3129,16 @@ function Report(props) {
2927
3129
  /** @type {string | null} */
2928
3130
  null
2929
3131
  );
2930
- const chartRef = useRef11(null);
3132
+ const chartRef = useRef12(null);
2931
3133
  const [chartReady, setChartReady] = useState12(false);
2932
- const hintId = useId4();
2933
- const closeFilter = useCallback9(() => setFilterTarget(null), []);
3134
+ const [lineChecks, setLineChecks] = useState12(
3135
+ /** @type {any} */
3136
+ null
3137
+ );
3138
+ const hintId = useId5();
3139
+ const closeFilter = useCallback10(() => setFilterTarget(null), []);
2934
3140
  const { toasts, push, dismiss, pause } = useToasts();
2935
- const announce = useCallback9(
3141
+ const announce = useCallback10(
2936
3142
  /** @param {string} text @param {{ action?: { label: string, run: () => void }, tone?: "error" }} [extra] */
2937
3143
  (text, extra) => push({ text, ...extra }),
2938
3144
  [push]
@@ -3003,13 +3209,13 @@ function Report(props) {
3003
3209
  const notes2 = unusedNotes(normalize2(raw, encoded, { limits }).issues, raw);
3004
3210
  return notes2.length ? { notes: notes2, loaded: JSON.parse(keyOf(raw)) } : null;
3005
3211
  }, [hostKey, loading2, imported, encoded, limits, keyOf]);
3006
- const leaveOut = useCallback9((notes2, given2) => setLeftOut({ notes: notes2, loaded: given2 ? JSON.parse(keyOf(given2)) : null, after: hostKey }), [keyOf, hostKey]);
3212
+ const leaveOut = useCallback10((notes2, given2) => setLeftOut({ notes: notes2, loaded: given2 ? JSON.parse(keyOf(given2)) : null, after: hostKey }), [keyOf, hostKey]);
3007
3213
  const loadedView = tagFor(history.tag, sourceId);
3008
3214
  const viewName = loadedView?.name ?? null;
3009
3215
  const unsaved = Boolean(loadedView) && savedKeys[savedKeyOf(loadedView)] !== history.viewKey;
3010
- const chartOptionsKey = optionsKey(chartOptions);
3011
- const stableChartOptions = useMemo8(() => chartOptions, [chartOptionsKey]);
3012
- const stepText = useCallback9(
3216
+ const chartHostKey = optionsKey([chartOptions, colorMap]);
3217
+ const [stableChartOptions, stableColorMap] = useMemo8(() => [chartOptions, colorMap], [chartHostKey]);
3218
+ const stepText = useCallback10(
3013
3219
  (note) => {
3014
3220
  const template = Object.hasOwn(labels.steps, note.step) ? labels.steps[note.step] : labels.steps.change;
3015
3221
  return fill(template, {
@@ -3022,7 +3228,7 @@ function Report(props) {
3022
3228
  },
3023
3229
  [labels]
3024
3230
  );
3025
- const apiNow = useRef11(
3231
+ const apiNow = useRef12(
3026
3232
  /** @type {any} */
3027
3233
  null
3028
3234
  );
@@ -3038,22 +3244,22 @@ function Report(props) {
3038
3244
  announce(fill(labels.toastRedone, { step: note }));
3039
3245
  }
3040
3246
  };
3041
- const newStep = useCallback9(() => setDataSteps((s) => s.future.length ? { past: s.past, future: [] } : s), []);
3042
- const undoLater = useRef11(undo2);
3247
+ const newStep = useCallback10(() => setDataSteps((s) => s.future.length ? { past: s.past, future: [] } : s), []);
3248
+ const undoLater = useRef12(undo2);
3043
3249
  useEffect11(() => {
3044
3250
  undoLater.current = undo2;
3045
3251
  });
3046
- const reset2 = useCallback9(() => {
3252
+ const reset2 = useCallback10(() => {
3047
3253
  history.reset(labels.steps.reset);
3048
3254
  newStep();
3049
3255
  announce(labels.toastReset, { action: { label: labels.undo, run: () => undoLater.current() } });
3050
3256
  }, [history, labels, announce, newStep]);
3051
3257
  const [opening, setOpening] = useState12(false);
3052
- const appliedLink = useRef11(
3258
+ const appliedLink = useRef12(
3053
3259
  /** @type {string | null} */
3054
3260
  null
3055
3261
  );
3056
- const latest = useRef11({ history, encoded, limits, labels, announce, commit: (
3262
+ const latest = useRef12({ history, encoded, limits, labels, announce, commit: (
3057
3263
  /** @type {any} */
3058
3264
  null
3059
3265
  ), sourceId, loaded: (
@@ -3064,7 +3270,7 @@ function Report(props) {
3064
3270
  /** @type {null | { lines: string[], quiet: boolean, load: () => void, switchTo?: { name: string, run: () => void } }} */
3065
3271
  null
3066
3272
  );
3067
- const openLink = useCallback9((text, asStep = false) => {
3273
+ const openLink = useCallback10((text, asStep = false) => {
3068
3274
  appliedLink.current = text;
3069
3275
  const now = linkNow();
3070
3276
  const apply = (m) => {
@@ -3157,29 +3363,32 @@ function Report(props) {
3157
3363
  writeStoredView(storageKey, sessionStore(), JSON.parse(history.viewKey));
3158
3364
  }
3159
3365
  }, [persistView, storageKey, history.viewKey]);
3160
- const commit = useCallback9(
3161
- /** @param {object} next @param {{ step: string, removed?: boolean, field?: string, zone?: string, name?: string, display?: string, type?: string }} [note] @param {any} [tag] the saved view it is (history.tag) */
3366
+ const commit = useCallback10(
3367
+ /** @param {object} next @param {{ step: string, removed?: boolean, field?: string, zone?: string, name?: string, display?: string, type?: string }} [note] @param {any} [tag] the saved view it is (history.tag) @returns {boolean} whether the view changed */
3162
3368
  (next, note = { step: "change" }, tag = void 0) => {
3163
3369
  const over = note.step === "template" ? null : zoneOverLimit(next, limits);
3164
3370
  if (over) {
3165
3371
  announce(fill(labels.zoneFull, { zone: labels.zones[over.zone], max: over.max.toLocaleString(locale) }), { tone: "error" });
3166
- return;
3372
+ return false;
3167
3373
  }
3168
3374
  const changed = history.commit(next, stepText(note), tag);
3375
+ if (changed && note.step === "added" && foldOpenWhileEmpty.current) {
3376
+ setFolded(false);
3377
+ }
3169
3378
  if (changed) {
3170
3379
  changesRef.current += 1;
3171
3380
  setChanges(changesRef.current);
3172
3381
  newStep();
3173
3382
  }
3174
- if (!changed || !note.removed) {
3175
- return;
3383
+ if (changed && note.removed) {
3384
+ announce(fill(labels.toastRemoved, { field: note.field ?? "" }).trim(), { action: { label: labels.undo, run: () => undoLater.current() } });
3176
3385
  }
3177
- announce(fill(labels.toastRemoved, { field: note.field ?? "" }).trim(), { action: { label: labels.undo, run: () => undoLater.current() } });
3386
+ return changed;
3178
3387
  },
3179
3388
  [history, stepText, labels, announce, limits, locale, newStep]
3180
3389
  );
3181
- const remember = useCallback9((tag, key) => setSavedKeys((all) => ({ ...all, [savedKeyOf(tag)]: key })), []);
3182
- const applyLoaded = useCallback9(
3390
+ const remember = useCallback10((tag, key) => setSavedKeys((all) => ({ ...all, [savedKeyOf(tag)]: key })), []);
3391
+ const applyLoaded = useCallback10(
3183
3392
  /** @param {import("./share.js").LoadedView} loaded @param {{ link?: boolean, restored?: boolean }} [how] */
3184
3393
  (loaded3, { link = false, restored: restored2 = false } = {}) => {
3185
3394
  if (!loaded3.view) {
@@ -3214,7 +3423,8 @@ function Report(props) {
3214
3423
  return { result: null, error: error2 };
3215
3424
  }
3216
3425
  }, [encoded, view, locale, limits]);
3217
- const result = computed.result;
3426
+ const context = useMemo8(() => dateContext(computed.result, labels), [computed.result, labels]);
3427
+ const result = context.result;
3218
3428
  const unusedLocale = useMemo8(() => {
3219
3429
  const requested = view.formatting?.locale || locale;
3220
3430
  try {
@@ -3235,35 +3445,52 @@ function Report(props) {
3235
3445
  return { result: null, error: error2 };
3236
3446
  }
3237
3447
  }, [plan.swap, view, encoded, locale, limits, computed, result]);
3238
- const chartResult = chartComputed.result;
3448
+ const titleOf = useCallback10((field) => context.titles.get(field), [context]);
3449
+ const chartContext = useMemo8(() => chartComputed.result === computed.result ? context : dateContext(chartComputed.result, labels), [chartComputed.result, computed.result, context, labels]);
3450
+ const chartResult = chartContext.result;
3239
3451
  const empty = isEmptyView(view);
3452
+ const layoutFolded = folded ?? (short && !empty);
3453
+ useEffect11(() => {
3454
+ foldOpenWhileEmpty.current = empty && short && folded === null;
3455
+ });
3240
3456
  const gridState = useMemo8(() => {
3241
3457
  if (!result || view.display !== "table" || empty) {
3242
3458
  return { grid: null, error: null };
3243
3459
  }
3244
3460
  try {
3245
- return { grid: measured("toGrid", () => toGrid(result, { locale, labels: labels.core, limits })), error: null };
3461
+ return { grid: measured("toGrid", () => toGrid(result, { locale, labels: context.labels.core, limits })), error: null };
3246
3462
  } catch (error2) {
3247
3463
  return { grid: null, error: error2 };
3248
3464
  }
3249
- }, [result, view.display, empty, locale, labels, limits]);
3465
+ }, [result, view.display, empty, locale, context.labels, limits]);
3250
3466
  const error = source.error ?? computed.error ?? gridState.error ?? (view.display === "chart" ? chartComputed.error : null);
3467
+ const dateLocale = useMemo8(() => dateDisplayLocale(view.formatting?.locale || locale), [view.formatting?.locale, locale]);
3251
3468
  const fields = encoded.schema.fields;
3252
3469
  const types = useMemo8(() => new Map(viewFields(view, encoded).map((f) => [f.name.toLowerCase(), f.type])), [view, encoded]);
3253
- const typeOf = useCallback9((field) => types.get(sourceOf(view, field ?? "").toLowerCase()) ?? "string", [types, view]);
3254
- const nameOf = useCallback9((field) => fieldLabel5(field, labels.core), [labels]);
3255
- const hostOrdered = useCallback9((field) => sourceOf(view, field) === field && (orderOf?.(field)?.length ?? 0) > 0, [view, orderOf]);
3256
- const sortFromHeader = useCallback9((field, sort) => commit(setSort(view, field, sort), { step: "sort", field: nameOf(field) }), [view, commit, nameOf]);
3257
- const infoOf = useCallback9(
3470
+ const typeOf = useCallback10((field) => types.get(sourceOf(view, field ?? "").toLowerCase()) ?? "string", [types, view]);
3471
+ const nameOf = useCallback10((field) => fieldLabel5(field, labels.core), [labels]);
3472
+ const hostOrdered = useCallback10((field) => sourceOf(view, field) === field && (orderOf?.(field)?.length ?? 0) > 0, [view, orderOf]);
3473
+ const sortFromHeader = useCallback10((field, sort) => commit(setSort(view, field, sort), { step: "sort", field: nameOf(field) }), [view, commit, nameOf]);
3474
+ const infoOf = useCallback10(
3258
3475
  (field) => {
3259
- if (!field || info.size === 0) {
3476
+ if (!field) {
3260
3477
  return void 0;
3261
3478
  }
3262
3479
  const entry = info.get(sourceOf(view, field).toLowerCase());
3263
- return entry && entry.description ? entry : void 0;
3480
+ const range = dateRangeText(dateSpan(encoded, sourceOf(view, field)), dateLocale);
3481
+ const description = [entry?.description, range && fill(labels.dateRangeData, { range })].filter(Boolean).join(" \xB7 ");
3482
+ return description ? { ...entry, description } : void 0;
3264
3483
  },
3265
- [info, view]
3484
+ [info, view, encoded, dateLocale, labels]
3266
3485
  );
3486
+ const fieldInfo = useMemo8(() => {
3487
+ const entries2 = new Map(info);
3488
+ for (const field of encoded.schema.fields) {
3489
+ const entry = infoOf(field.name);
3490
+ if (entry) entries2.set(field.name.toLowerCase(), entry);
3491
+ }
3492
+ return entries2;
3493
+ }, [info, infoOf, encoded]);
3267
3494
  const placed = useMemo8(() => {
3268
3495
  const map = /* @__PURE__ */ new Map();
3269
3496
  const mark = (name, zone) => {
@@ -3295,11 +3522,13 @@ function Report(props) {
3295
3522
  live = false;
3296
3523
  };
3297
3524
  }, [lang]);
3298
- const mainRef = useRef11(
3525
+ const mainRef = useRef12(
3299
3526
  /** @type {HTMLDivElement | null} */
3300
3527
  null
3301
3528
  );
3302
- const fit = useFitHeight(root, mainRef, grow);
3529
+ const checkLow = useRef12(() => {
3530
+ });
3531
+ const fit = useFitHeight(root, mainRef, grow, () => checkLow.current());
3303
3532
  const big = useBigResult(root);
3304
3533
  useIsoLayoutEffect(() => {
3305
3534
  const el = root.current;
@@ -3311,17 +3540,78 @@ function Report(props) {
3311
3540
  const first = compactAt(sizeOf(box.width), box.height);
3312
3541
  setMeasuredShort(first);
3313
3542
  setShort(first);
3543
+ const low = (width, height2) => compactAt(width, height2) || fit.current.open > 0 && height2 <= fit.current.open + 1;
3544
+ let waiting = false;
3545
+ let lastInArea = false;
3546
+ const inArea = (t) => t instanceof Node && Boolean(el.querySelector(".pk-zone-section")?.contains(t) || el.querySelector(".pk-layer")?.contains(t));
3547
+ const note = (e) => {
3548
+ lastInArea = inArea(e.composedPath()[0] ?? e.target);
3549
+ };
3550
+ el.addEventListener("pointerdown", note, true);
3551
+ el.addEventListener("focusin", note, true);
3552
+ const busy = () => {
3553
+ const section = el.querySelector(".pk-zone-section");
3554
+ if (!section) {
3555
+ return false;
3556
+ }
3557
+ const active = (
3558
+ /** @type {Document | ShadowRoot} */
3559
+ el.getRootNode().activeElement
3560
+ );
3561
+ const focusGone = !active || active === el.ownerDocument.body;
3562
+ return Boolean(layerOpen(el.querySelector(".pk-layer")) || section.matches(":hover") || section.matches(":focus-within") || section.querySelector(".pk-dropping") || lastInArea && focusGone);
3563
+ };
3564
+ const doc = el.ownerDocument;
3565
+ let again = 0;
3566
+ const retry = () => {
3567
+ clearTimeout(again);
3568
+ again = window.setTimeout(() => waiting && checkLow.current(), 0);
3569
+ };
3570
+ const watch = (on) => {
3571
+ const how = on ? "addEventListener" : "removeEventListener";
3572
+ el[how]("pointerout", retry);
3573
+ el[how]("focusout", retry);
3574
+ doc[how]("pointerup", retry);
3575
+ };
3576
+ checkLow.current = () => {
3577
+ if (busy()) {
3578
+ if (!waiting) {
3579
+ waiting = true;
3580
+ watch(true);
3581
+ }
3582
+ return;
3583
+ }
3584
+ if (waiting) {
3585
+ waiting = false;
3586
+ watch(false);
3587
+ }
3588
+ const now = el.getBoundingClientRect();
3589
+ setMeasuredShort(low(sizeOf(now.width), now.height));
3590
+ };
3591
+ const release = () => {
3592
+ el.removeEventListener("pointerdown", note, true);
3593
+ el.removeEventListener("focusin", note, true);
3594
+ clearTimeout(again);
3595
+ if (waiting) {
3596
+ waiting = false;
3597
+ watch(false);
3598
+ }
3599
+ };
3314
3600
  if (typeof ResizeObserver !== "function") {
3315
- return void 0;
3601
+ return release;
3316
3602
  }
3317
3603
  const ro = new ResizeObserver(([entry]) => {
3318
3604
  const width = sizeOf(entry.contentRect.width);
3319
3605
  setSize(width);
3320
- const height2 = entry.borderBoxSize?.[0]?.blockSize ?? el.getBoundingClientRect().height;
3321
- setMeasuredShort(compactAt(width, height2) || fit.current.open > 0 && height2 <= fit.current.open + 1);
3606
+ setMeasuredShort(low(width, entry.borderBoxSize?.[0]?.blockSize ?? el.getBoundingClientRect().height));
3322
3607
  });
3323
3608
  ro.observe(el);
3324
- return () => ro.disconnect();
3609
+ return () => {
3610
+ checkLow.current = () => {
3611
+ };
3612
+ release();
3613
+ ro.disconnect();
3614
+ };
3325
3615
  }, []);
3326
3616
  useEffect11(() => {
3327
3617
  if (measuredShort === short) {
@@ -3341,7 +3631,7 @@ function Report(props) {
3341
3631
  return () => mo.disconnect();
3342
3632
  }, [measuredShort, short, layer]);
3343
3633
  const drawerOpen = drawer && size === "narrow";
3344
- const panelRef = useRef11(
3634
+ const panelRef = useRef12(
3345
3635
  /** @type {HTMLDivElement | null} */
3346
3636
  null
3347
3637
  );
@@ -3350,8 +3640,8 @@ function Report(props) {
3350
3640
  panelRef.current.inert = size === "narrow" && !drawerOpen;
3351
3641
  }
3352
3642
  }, [size, drawerOpen]);
3353
- const defaultsOf = useCallback9((field) => fieldDefaultsFor(fieldDefaults, field, encoded.column(field)), [fieldDefaults, encoded]);
3354
- const placeOptions = useCallback9(
3643
+ const defaultsOf = useCallback10((field) => fieldDefaultsFor(fieldDefaults, field, encoded.column(field)), [fieldDefaults, encoded]);
3644
+ const placeOptions = useCallback10(
3355
3645
  (field, zone, index = void 0) => {
3356
3646
  const column = encoded.column(field);
3357
3647
  const unit = zone !== "values" && column && column.type === "date" && !column.derived ? suggestDateUnit(encoded, field) : null;
@@ -3359,18 +3649,25 @@ function Report(props) {
3359
3649
  },
3360
3650
  [encoded, typeOf, defaultsOf, labels, nameOf]
3361
3651
  );
3362
- const addTo = useCallback9(
3652
+ const addTo = useCallback10(
3363
3653
  (field, zone, index = void 0) => {
3364
3654
  const options = placeOptions(field, zone, index);
3365
- commit(addField(view, field, zone, options), { step: "added", field: options.groupName ?? nameOf(field), zone });
3655
+ return commit(addField(view, field, zone, options), { step: "added", field: options.groupName ?? nameOf(field), zone });
3366
3656
  },
3367
3657
  [view, placeOptions, commit, nameOf]
3368
3658
  );
3369
- const filterField = useCallback9(
3370
- (field, anchor) => {
3659
+ const placeName = useCallback10((field, zone) => placeOptions(field, zone).groupName ?? field, [placeOptions]);
3660
+ const filterDraft = useCallback10(
3661
+ (field) => {
3371
3662
  const options = placeOptions(field, "filters");
3372
3663
  const name = options.groupName ?? field;
3373
- const draft = filterZoneFields(view).some((f) => same(f, name)) ? void 0 : addField(view, field, "filters", options);
3664
+ return { field: name, base: filterZoneFields(view).some((f) => same(f, name)) ? void 0 : addField(view, field, "filters", options) };
3665
+ },
3666
+ [placeOptions, view]
3667
+ );
3668
+ const filterField = useCallback10(
3669
+ (field, anchor) => {
3670
+ const draft = filterDraft(field);
3374
3671
  const opener = size === "narrow" ? (
3375
3672
  /** @type {HTMLElement | null} */
3376
3673
  root.current?.querySelector("[data-pk-opener='fields']") ?? null
@@ -3380,12 +3677,20 @@ function Report(props) {
3380
3677
  }
3381
3678
  const target = opener ?? anchor;
3382
3679
  if (target) {
3383
- setFilterTarget({ field: name, anchor: target, base: draft });
3680
+ setFilterTarget({ field: draft.field, anchor: target, base: draft.base });
3384
3681
  }
3385
3682
  },
3386
- [placeOptions, view, size]
3683
+ [filterDraft, size]
3684
+ );
3685
+ const zoneFullText = useCallback10(
3686
+ (zone, count) => {
3687
+ const max = zoneMax(zone, limits);
3688
+ return max !== null && count >= max ? fill(labels.zoneFull, { zone: labels.zones[zone], max: max.toLocaleString(locale) }) : null;
3689
+ },
3690
+ [limits, labels, locale]
3387
3691
  );
3388
- const onDrop = useCallback9(
3692
+ const adding = useMemo8(() => ({ fields, placed, nameOf, info, placeName, onAdd: addTo, filterDraft, fullText: zoneFullText }), [fields, placed, nameOf, info, placeName, addTo, filterDraft, zoneFullText]);
3693
+ const onDrop = useCallback10(
3389
3694
  (src, target) => {
3390
3695
  setDragAt((at) => at ?? changesRef.current + 1);
3391
3696
  if (target.zone === "panel") {
@@ -3407,7 +3712,7 @@ function Report(props) {
3407
3712
  },
3408
3713
  [view, typeOf, commit, addTo, defaultsOf]
3409
3714
  );
3410
- const openCell = useCallback9(
3715
+ const openCell = useCallback10(
3411
3716
  /** @param {any} cell */
3412
3717
  ({ rowPath = [], colPath = [], value, valueIndex, text }) => {
3413
3718
  if (!result) {
@@ -3426,7 +3731,7 @@ function Report(props) {
3426
3731
  },
3427
3732
  [result, encodedProp, imported, data, drillDownLimit, onCellClick, drillDown, defaultsOf, nameOf, infoOf]
3428
3733
  );
3429
- const doExport = useExport({ fileName, result, encoded, exportData, locale, labels, limits, root, chartRef, announce, onExport, title: viewName, source: sourceName, loadECharts });
3734
+ const { run: doExport, prepare: prepareExport } = useExport({ fileName, result: computed.result, encoded, exportData, locale, labels, limits, root, chartRef, announce, onExport, title: viewName, source: sourceName, loadECharts, colorMap: stableColorMap });
3430
3735
  const requestImport = () => loadImport().then((m) => (flushSync(() => setImportMod(() => m)), m));
3431
3736
  const api = {
3432
3737
  imported,
@@ -3460,7 +3765,7 @@ function Report(props) {
3460
3765
  useEffect11(() => {
3461
3766
  apiNow.current = api;
3462
3767
  });
3463
- const restored = useRef11(false);
3768
+ const restored = useRef12(false);
3464
3769
  useIsoLayoutEffect(() => {
3465
3770
  if (kept2 && !restored.current) {
3466
3771
  restored.current = true;
@@ -3469,8 +3774,8 @@ function Report(props) {
3469
3774
  }
3470
3775
  }, []);
3471
3776
  const snapshot = history.snapshot;
3472
- const keptKey = useRef11(keepKey);
3473
- const fileShown = useRef11(false);
3777
+ const keptKey = useRef12(keepKey);
3778
+ const fileShown = useRef12(false);
3474
3779
  const hostHasColumns = source.encoded.schema.fields.length > 0;
3475
3780
  useIsoLayoutEffect(() => {
3476
3781
  if (keepKey !== null && !kept2 && hostHasColumns) {
@@ -3530,7 +3835,7 @@ function Report(props) {
3530
3835
  applyLoaded
3531
3836
  };
3532
3837
  const viaSheet = (made, name, then) => imported && importMod ? importMod.openOnSheet(apiNow.current, made, name, then) : "none";
3533
- const loadTemplate = useCallback9(
3838
+ const loadTemplate = useCallback10(
3534
3839
  (t) => {
3535
3840
  const tag = { name: t.name, scope: t.scope === "user" ? "user" : "shared", store: t.at !== void 0, storeSource: t.sourceId ?? null, storeSheet: t.sheet ?? null, sourceId };
3536
3841
  remember(tag, history.keyOf(t.view));
@@ -3551,7 +3856,7 @@ function Report(props) {
3551
3856
  loadTemplate(how === "missing" ? { ...t, sheet: SHEET_GONE } : t);
3552
3857
  }
3553
3858
  };
3554
- const loadLater = useRef11(
3859
+ const loadLater = useRef12(
3555
3860
  /** @type {((what: { template?: any, file?: object }) => void) | null} */
3556
3861
  null
3557
3862
  );
@@ -3582,7 +3887,7 @@ function Report(props) {
3582
3887
  };
3583
3888
  const viewStore = templateStore === "browser";
3584
3889
  const storeName = viewsName(storageKey);
3585
- const subscribeViews = useCallback9((callback) => viewStore ? subscribeItem(storeName, callback) : () => {
3890
+ const subscribeViews = useCallback10((callback) => viewStore ? subscribeItem(storeName, callback) : () => {
3586
3891
  }, [viewStore, storeName]);
3587
3892
  const viewsText = useSyncExternalStore3(subscribeViews, () => viewStore ? readItem(storeName, localStore()) : null, () => null);
3588
3893
  const entries = useMemo8(
@@ -3653,10 +3958,10 @@ function Report(props) {
3653
3958
  }
3654
3959
  };
3655
3960
  const layerValue = useMemo8(() => ({ layer, size }), [layer, size]);
3656
- const renderOverlay = (src) => /* @__PURE__ */ React12.createElement("div", { className: "pk-chip pk-overlay" }, /* @__PURE__ */ React12.createElement(Icon, { name: "grip", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: `pk-type pk-type-${src.type ?? typeOf(src.field)}` }, /* @__PURE__ */ React12.createElement(Icon, { name: (
3961
+ const renderOverlay = (src) => /* @__PURE__ */ React13.createElement("div", { className: "pk-chip pk-overlay" }, /* @__PURE__ */ React13.createElement(Icon, { name: "grip", size: 14 }), /* @__PURE__ */ React13.createElement("span", { className: `pk-type pk-type-${src.type ?? typeOf(src.field)}` }, /* @__PURE__ */ React13.createElement(Icon, { name: (
3657
3962
  /** @type {any} */
3658
3963
  TYPE_ICON[src.type ?? typeOf(src.field)] ?? "text"
3659
- ), size: 13 })), /* @__PURE__ */ React12.createElement("span", { className: "pk-chip-text" }, src.label ?? src.field));
3964
+ ), size: 13 })), /* @__PURE__ */ React13.createElement("span", { className: "pk-chip-text" }, src.label ?? src.field));
3660
3965
  const showTable = !error && !(empty && view.display === "table") && view.display !== "chart" && gridState.grid;
3661
3966
  const outer = useMemo8(() => result ? outerPaths(result) : [], [result]);
3662
3967
  const folding = rowFolding(view, outer);
@@ -3677,24 +3982,24 @@ function Report(props) {
3677
3982
  return null;
3678
3983
  }
3679
3984
  try {
3680
- return toSeries(chartResult, { labels: labels.core, maxCategories: MAX_CATEGORIES });
3985
+ return toSeries(chartResult, { labels: chartContext.labels.core, maxCategories: MAX_CATEGORIES });
3681
3986
  } catch {
3682
3987
  return null;
3683
3988
  }
3684
- }, [chartResult, view.display, view.values.length, labels]);
3989
+ }, [chartResult, view.display, view.values.length, chartContext.labels]);
3685
3990
  const allowedKey = JSON.stringify(allowedTips(tipsProp));
3686
3991
  const allowed = useMemo8(() => JSON.parse(allowedKey), [allowedKey]);
3687
3992
  const dismissedKey = JSON.stringify(cleanDismissed(dismissedTips));
3688
- const [own2, setOwn] = useState12(() => cleanDismissed(JSON.parse(dismissedKey)));
3993
+ const [own, setOwn] = useState12(() => cleanDismissed(JSON.parse(dismissedKey)));
3689
3994
  const [lastDismissedKey, setLastDismissedKey] = useState12(dismissedKey);
3690
3995
  if (dismissedKey !== lastDismissedKey) {
3691
3996
  setLastDismissedKey(dismissedKey);
3692
3997
  setOwn(JSON.parse(dismissedKey));
3693
3998
  }
3694
- const subscribe = useCallback9((callback) => subscribeStored(storageKey, callback), [storageKey]);
3999
+ const subscribe = useCallback10((callback) => subscribeStored(storageKey, callback), [storageKey]);
3695
4000
  const storedRaw = useSyncExternalStore3(subscribe, () => readStored(storageKey, localStore()), () => null);
3696
- const dismissed = useMemo8(() => cleanDismissed([...own2, ...parseStored(storedRaw)]), [own2, storedRaw]);
3697
- const changeDismissed = useCallback9(
4001
+ const dismissed = useMemo8(() => cleanDismissed([...own, ...parseStored(storedRaw)]), [own, storedRaw]);
4002
+ const changeDismissed = useCallback10(
3698
4003
  (next, id) => {
3699
4004
  setOwn(next);
3700
4005
  writeDismissed(storageKey, localStore(), next);
@@ -3703,7 +4008,7 @@ function Report(props) {
3703
4008
  [storageKey, onTipDismiss]
3704
4009
  );
3705
4010
  const tipsOn = allowed !== "off" && !dismissed.includes(ALL_TIPS);
3706
- const describedFields = [...info.values()].some((i) => i.description);
4011
+ const describedFields = [...fieldInfo.values()].some((i) => i.description);
3707
4012
  const fieldSwitch = helpSwitch(fieldInfoProp, dismissed);
3708
4013
  const zoneSwitch = helpSwitch(zoneInfoProp, dismissed);
3709
4014
  const settingSwitch = helpSwitch(settingInfoProp, dismissed);
@@ -3734,6 +4039,16 @@ function Report(props) {
3734
4039
  warnOnce(`pivotkit: fieldList ${JSON.stringify(String(fieldList)).slice(0, 40)} is neither "open" nor "collapsed"; the user's choice decides`);
3735
4040
  }
3736
4041
  }, [fieldList]);
4042
+ useEffect11(() => {
4043
+ for (const [key, now] of removedLabels(JSON.parse(labelsKey))) {
4044
+ warnOnce(`pivotkit: labels.${key} is no longer shown and is ignored; set labels.${now} instead`);
4045
+ }
4046
+ }, [labelsKey]);
4047
+ useEffect11(() => {
4048
+ if (zonesProp !== void 0 && zonesStart(zonesProp) === null) {
4049
+ warnOnce(`pivotkit: zones ${JSON.stringify(String(zonesProp)).slice(0, 40)} is neither "open" nor "folded"; the report's height decides`);
4050
+ }
4051
+ }, [zonesProp]);
3737
4052
  const railed = size !== "narrow" && fieldsCollapsed(fieldsSession, fieldList, dismissed);
3738
4053
  const collapseFields = (next) => {
3739
4054
  if (fieldList === "open" || fieldList === "collapsed") {
@@ -3785,9 +4100,9 @@ function Report(props) {
3785
4100
  () => 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]) : []]),
3786
4101
  [fromHost, given, loads, result, empty]
3787
4102
  );
3788
- const summaryParts = big.enlarged ? layoutSummary(zoneEntries(view, types, labels), labels) : [];
4103
+ const summaryParts = big.enlarged ? layoutSummary(zoneEntries(view, types, context.labels), context.labels) : [];
3789
4104
  const summaryText = summaryParts.length ? summaryParts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
3790
- return /* @__PURE__ */ React12.createElement(
4105
+ return /* @__PURE__ */ React13.createElement(
3791
4106
  "div",
3792
4107
  {
3793
4108
  ref: root,
@@ -3809,7 +4124,7 @@ function Report(props) {
3809
4124
  onDragLeave: allowImport ? fileDrag : void 0,
3810
4125
  onDrop: allowImport ? fileDrag : void 0
3811
4126
  },
3812
- /* @__PURE__ */ React12.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React12.createElement(FormNameContext.Provider, { value: formPrefix }, /* @__PURE__ */ React12.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React12.createElement(
4127
+ /* @__PURE__ */ React13.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React13.createElement(FormNameContext.Provider, { value: formPrefix }, /* @__PURE__ */ React13.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React13.createElement(
3813
4128
  PivotDnd,
3814
4129
  {
3815
4130
  labels,
@@ -3821,7 +4136,7 @@ function Report(props) {
3821
4136
  }
3822
4137
  }
3823
4138
  },
3824
- /* @__PURE__ */ React12.createElement("div", { className: `pk-layout${drawerOpen ? " pk-drawer-open" : ""}` }, /* @__PURE__ */ React12.createElement("div", { className: "pk-panel-slot", ref: panelRef }, /* @__PURE__ */ React12.createElement(
4139
+ /* @__PURE__ */ React13.createElement("div", { className: `pk-layout${drawerOpen ? " pk-drawer-open" : ""}` }, /* @__PURE__ */ React13.createElement("div", { className: "pk-panel-slot", ref: panelRef }, /* @__PURE__ */ React13.createElement(
3825
4140
  FieldPanel,
3826
4141
  {
3827
4142
  fields,
@@ -3836,7 +4151,7 @@ function Report(props) {
3836
4151
  onNote: (text) => announce(text),
3837
4152
  onFilter: filterField,
3838
4153
  nameOf,
3839
- info,
4154
+ info: fieldInfo,
3840
4155
  showInfo: fieldSwitch.on,
3841
4156
  drawer: size === "narrow",
3842
4157
  open: drawerOpen,
@@ -3848,11 +4163,10 @@ function Report(props) {
3848
4163
  root.current?.querySelector(".pk-toolbar button:not([disabled])")?.focus()
3849
4164
  )
3850
4165
  }
3851
- )), drawerOpen ? /* @__PURE__ */ React12.createElement("div", { className: "pk-scrim pk-drawer-scrim", onClick: () => setDrawer(false), "aria-hidden": "true" }) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-main", ref: mainRef }, /* @__PURE__ */ React12.createElement(
4166
+ )), drawerOpen ? /* @__PURE__ */ React13.createElement("div", { className: "pk-scrim pk-drawer-scrim", onClick: () => setDrawer(false), "aria-hidden": "true" }) : null, /* @__PURE__ */ React13.createElement("div", { className: "pk-main", ref: mainRef }, /* @__PURE__ */ React13.createElement(
3852
4167
  Toolbar,
3853
4168
  {
3854
4169
  view,
3855
- chartPlan: plan,
3856
4170
  labels,
3857
4171
  size,
3858
4172
  canUndo: history.canUndo || dataSteps.past.length > 0,
@@ -3865,26 +4179,16 @@ function Report(props) {
3865
4179
  onReset: reset2,
3866
4180
  onNew: newReport,
3867
4181
  loadedView: loadedView ? { name: loadedView.name, changed: unsaved } : null,
3868
- onDisplay: (d) => commit(setDisplay(view, d), { step: "display", display: d }),
3869
- onChart: (p) => commit(setChart(view, p), { step: "chart", type: p }),
3870
- onChartDisplay: (patch) => commit(setChartDisplay(view, patch), { step: "chartDisplay" }),
3871
- onTotal: (key, on) => commit(setTotal(view, key, on), { step: "totals" }),
3872
- onExpand: expandAll,
3873
- onCollapse: collapseAll,
3874
- folding,
3875
4182
  share,
3876
4183
  templates: entries,
3877
4184
  onLoadTemplate: openTemplate,
3878
4185
  templateActions,
3879
4186
  onExport: doExport,
3880
- prepareExport: prepareExporters,
4187
+ prepareExport,
3881
4188
  dataExport: { exportData, encoded },
3882
4189
  chartReady: view.display === "chart" && chartReady,
3883
4190
  empty,
3884
4191
  onShowFields: () => setDrawer(true),
3885
- layoutFolded,
3886
- onLayout: () => setFolded(!layoutFolded),
3887
- zonesId,
3888
4192
  tipsControls: allowed !== "off",
3889
4193
  tipsOn,
3890
4194
  onTipsOn: (on) => changeDismissed(on ? dismissed.filter((id) => id !== ALL_TIPS) : [...dismissed, ALL_TIPS], on ? null : ALL_TIPS),
@@ -3894,9 +4198,9 @@ function Report(props) {
3894
4198
  explanations: explainUser ? { on: !dismissed.includes(NO_EXPLANATIONS), set: (on) => toggle(NO_EXPLANATIONS, on) } : null
3895
4199
  },
3896
4200
  viewsRequest,
3897
- data: allowImport ? { loaded: Boolean(imported), panel: (close) => /* @__PURE__ */ React12.createElement(MenuPanel, { name: "DataMenu", loadingText: labels.loadingMenu, props: { api, close, labels } }) } : null
4201
+ data: allowImport ? { loaded: Boolean(imported), panel: (close) => /* @__PURE__ */ React13.createElement(MenuPanel, { name: "DataMenu", loadingText: labels.loadingMenu, props: { api, close, labels } }) } : null
3898
4202
  }
3899
- ), /* @__PURE__ */ React12.createElement(
4203
+ ), /* @__PURE__ */ React13.createElement(
3900
4204
  Zones,
3901
4205
  {
3902
4206
  view,
@@ -3904,18 +4208,20 @@ function Report(props) {
3904
4208
  labels,
3905
4209
  commit,
3906
4210
  encoded,
3907
- locale,
4211
+ locale: dateLocale,
3908
4212
  onSwap: () => commit(swapAxes(view), { step: "swap" }),
3909
4213
  id: zonesId,
3910
4214
  folded: layoutFolded,
3911
- onShow: () => setFolded(false),
4215
+ onFold: () => setFolded(!layoutFolded),
3912
4216
  defaultsOf,
3913
4217
  infoOf,
4218
+ titleOf,
3914
4219
  earlier: history.earlier,
3915
4220
  explain: zoneSwitch.on,
3916
- showInfo: fieldSwitch.on
4221
+ showInfo: fieldSwitch.on,
4222
+ adding
3917
4223
  }
3918
- ), linkCheck ? /* @__PURE__ */ React12.createElement("div", { className: "pk-link-check", "data-testid": "link-check" }, /* @__PURE__ */ React12.createElement(MenuPanel, { name: "LoadCheck", props: { check: linkCheck, labels, title: labels.linkCheckTitle, quiet: linkCheck.quiet, close: () => setLinkCheck(null), onCancel: cancelLink } })) : null, /* @__PURE__ */ React12.createElement(
4224
+ ), linkCheck ? /* @__PURE__ */ React13.createElement("div", { className: "pk-link-check", "data-testid": "link-check" }, /* @__PURE__ */ React13.createElement(MenuPanel, { name: "LoadCheck", props: { check: linkCheck, labels, title: labels.linkCheckTitle, quiet: linkCheck.quiet, close: () => setLinkCheck(null), onCancel: cancelLink } })) : null, /* @__PURE__ */ React13.createElement(
3919
4225
  Unused,
3920
4226
  {
3921
4227
  notes,
@@ -3933,7 +4239,7 @@ function Report(props) {
3933
4239
  narrow: size === "narrow",
3934
4240
  quiet: unusedSaid && !fromHost
3935
4241
  }
3936
- ), /* @__PURE__ */ React12.createElement(
4242
+ ), /* @__PURE__ */ React13.createElement(
3937
4243
  Tips,
3938
4244
  {
3939
4245
  tips: shownTips,
@@ -3942,27 +4248,55 @@ function Report(props) {
3942
4248
  onAction: runTip,
3943
4249
  focusFallback: () => root.current?.focus({ preventScroll: true })
3944
4250
  }
3945
- ), 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: openTemplate, 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(
4251
+ ), showTable && view.values.length ? /* @__PURE__ */ React13.createElement("p", { id: hintId, className: "pk-sr", "data-testid": "cell-hint" }, labels.tips.cells) : null, big.enlarged ? /* @__PURE__ */ React13.createElement("p", { className: "pk-enlarged-fields", "data-testid": "enlarged-fields" }, summaryText) : null, /* @__PURE__ */ React13.createElement(
4252
+ ViewTabs,
4253
+ {
4254
+ view,
4255
+ labels,
4256
+ panelId: resultId,
4257
+ narrow: size === "narrow",
4258
+ big,
4259
+ plan,
4260
+ encoded,
4261
+ lineChecks: lineChecks?.view === view ? lineChecks.checks : null,
4262
+ locale,
4263
+ chartSeries: series,
4264
+ chartColors: { chart: chartRef },
4265
+ onDisplay: (d) => commit(setDisplay(view, d), { step: "display", display: d }),
4266
+ onChart: (p) => commit(setChart(view, p), { step: "chart", type: p }),
4267
+ onChartDisplay: (patch) => commit(setChartDisplay(view, patch), { step: "chartDisplay" }),
4268
+ onTotal: (key, on) => commit(setTotal(view, key, on), { step: "totals" }),
4269
+ onExpand: expandAll,
4270
+ onCollapse: collapseAll,
4271
+ folding
4272
+ }
4273
+ ), /* @__PURE__ */ React13.createElement("section", { className: "pk-result", id: resultId, role: "tabpanel", "aria-labelledby": tabId(resultId, view.display === "chart" ? "chart" : "table") }, loading2 || opening ? /* @__PURE__ */ React13.createElement(Skeleton, { text: labels.loadingReport }) : error ? /* @__PURE__ */ React13.createElement("div", { className: "pk-message pk-error", role: "alert" }, /* @__PURE__ */ React13.createElement(Icon, { name: "info" }), /* @__PURE__ */ React13.createElement("p", null, errorText(error, labels, locale))) : empty && view.display === "table" ? /* @__PURE__ */ React13.createElement(EmptyState, { labels, templates: entries, onTemplate: openTemplate, 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__ */ React13.createElement(
3946
4274
  PivotChart,
3947
4275
  {
3948
4276
  result: chartResult,
3949
4277
  plan,
3950
4278
  series,
3951
- labels,
4279
+ labels: context.labels,
3952
4280
  locale,
3953
4281
  themeName,
3954
4282
  root,
3955
- valueNames: view.values.map((v) => valueLabel(v, labels)),
4283
+ valueNames: valueLabels(view.values, labels),
3956
4284
  chartOptions: stableChartOptions,
4285
+ colorMap: stableColorMap,
4286
+ onLegend: ({ name, shown }) => {
4287
+ commit(setChartDisplay(view, { hidden: hiddenAfter(view.chart.hidden, name, shown) }), { step: "chartDisplay" });
4288
+ announce(fill(shown ? labels.chartShown : labels.chartHidden, { name }));
4289
+ },
3957
4290
  onInstance: (c) => {
3958
4291
  chartRef.current = c;
3959
4292
  setChartReady(Boolean(c));
3960
4293
  },
4294
+ onLines: (checks) => setLineChecks(checks && { checks, view }),
3961
4295
  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 ?? "") })
3962
4296
  }
3963
- ) : 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, exportData } } }) : null),
3964
- filterTarget ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "FilterPopover", props: { target: filterTarget, onClose: closeFilter, view, encoded, locale, labels, commit } }) : null
3965
- ), 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" })))))
4297
+ ) : gridState.grid ? /* @__PURE__ */ React13.createElement(PivotTable, { grid: gridState.grid, view, labels: context.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__ */ React13.createElement("div", { className: "pk-status" }, /* @__PURE__ */ React13.createElement("span", { className: "pk-row-count", "data-testid": "row-count" }, result ? rowCount(result.rows.length, result.encoded.length, labels, locale) : ""), context.ranges.map(({ field, text }) => /* @__PURE__ */ React13.createElement("span", { key: field, "data-testid": "date-range", title: fill(labels.dateRangeTitle, { field: fieldLabel5(field, labels.core) }) }, context.ranges.length > 1 ? fill(labels.dateRangeField, { field: fieldLabel5(field, labels.core), range: text }) : fill(labels.dateRangeData, { range: text }))), importMod ? /* @__PURE__ */ React13.createElement(importMod.SourceLine, { api }) : null, rowLabel && showTable ? /* @__PURE__ */ React13.createElement("span", { className: "pk-row-label", "data-testid": "row-label" }, fill(labels.rowLabel, { label: rowLabel })) : null), /* @__PURE__ */ React13.createElement("div", { className: "pk-toast-dock" }, /* @__PURE__ */ React13.createElement(Toasts, { toasts, dismiss, pause, closeLabel: labels.close }))), drill ? /* @__PURE__ */ React13.createElement(MenuPanel, { name: "DrillPanel", props: { drill, onClose: () => setDrill(null), labels: context.labels, locale, exportContext: { encoded, onExport, announce, root, exportData, drillDownExport } } }) : null),
4298
+ filterTarget ? /* @__PURE__ */ React13.createElement(MenuPanel, { name: "FilterPopover", props: { target: filterTarget, onClose: closeFilter, view, encoded, locale, labels, commit } }) : null
4299
+ ), allowImport && importMod ? /* @__PURE__ */ React13.createElement(importMod.ImportLayer, { api, input: fileInput }) : null, /* @__PURE__ */ React13.createElement("div", { className: "pk-layer", ref: setLayer }, /* @__PURE__ */ React13.createElement("span", { className: "pk-origin", "aria-hidden": "true" })))))
3966
4300
  );
3967
4301
  }
3968
4302
  export {