pivotkit-react 0.7.0 → 0.8.1

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 (55) hide show
  1. package/CHANGELOG.md +191 -1
  2. package/README.md +33 -15
  3. package/dist/chunks/{chunk-JMRTIOX4.js → chunk-2N2UGSIG.js} +7 -0
  4. package/dist/chunks/{chunk-XN5HNKJ2.js → chunk-3WWWKPB4.js} +98 -33
  5. package/dist/chunks/{chunk-ZK5RVCHP.js → chunk-6OWC6X5W.js} +1 -1
  6. package/dist/chunks/{chunk-YXLANLGL.js → chunk-GUSQWPTH.js} +56 -3
  7. package/dist/chunks/{chunk-E6M57YLL.js → chunk-MU5BTKSY.js} +7 -0
  8. package/dist/chunks/{chunk-4WZ5F2TJ.js → chunk-W2SVDHGN.js} +371 -32
  9. package/dist/chunks/{chunk-TR2HROIK.js → chunk-ZM45YU3W.js} +66 -5
  10. package/dist/chunks/{unused-texts-Y4R67XSN.js → unused-texts-LRYVWFFN.js} +1 -1
  11. package/dist/chunks/{unused-texts-de-6YVPTNVS.js → unused-texts-de-GB3IWWEM.js} +1 -1
  12. package/dist/echarts.js +426 -35
  13. package/dist/import-ui.js +2 -2
  14. package/dist/index.js +728 -393
  15. package/dist/labels.js +6 -6
  16. package/dist/menu-texts-de.js +1 -1
  17. package/dist/menus.js +1534 -1020
  18. package/dist/styles.css +292 -171
  19. package/package.json +3 -3
  20. package/types/PivotReport.d.ts +6 -0
  21. package/types/add-menu.d.ts +48 -0
  22. package/types/chart-colors.d.ts +8 -0
  23. package/types/chart-decorate.d.ts +66 -3
  24. package/types/chart-legend.d.ts +176 -0
  25. package/types/chart-summary.d.ts +8 -3
  26. package/types/chart-tooltip.d.ts +159 -17
  27. package/types/chart.d.ts +21 -3
  28. package/types/date-context.d.ts +30 -0
  29. package/types/drill-panel.d.ts +4 -2
  30. package/types/echarts.d.ts +7 -3
  31. package/types/export-run.d.ts +7 -14
  32. package/types/export-scope.d.ts +13 -2
  33. package/types/field-info.d.ts +12 -0
  34. package/types/files.d.ts +14 -0
  35. package/types/filter.d.ts +18 -0
  36. package/types/group-context.d.ts +20 -0
  37. package/types/index.d.ts +35 -6
  38. package/types/label-room.d.ts +13 -0
  39. package/types/labels.d.ts +85 -16
  40. package/types/lazy-menus.d.ts +2 -2
  41. package/types/levels.d.ts +16 -7
  42. package/types/menu-labels.d.ts +67 -1
  43. package/types/menu-ops.d.ts +10 -0
  44. package/types/menu-topics.d.ts +110 -21
  45. package/types/menus.d.ts +2 -1
  46. package/types/names.d.ts +32 -3
  47. package/types/overflow.d.ts +18 -30
  48. package/types/rove.d.ts +10 -0
  49. package/types/toolbar-panels.d.ts +34 -10
  50. package/types/unused-texts.d.ts +7 -0
  51. package/types/use-big-result.d.ts +24 -9
  52. package/types/use-export.d.ts +2 -2
  53. package/types/view-ops.d.ts +19 -8
  54. package/types/view-tabs.d.ts +12 -0
  55. package/types/zones.d.ts +41 -9
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-4WZ5F2TJ.js";
91
+ } from "./chunks/chunk-W2SVDHGN.js";
80
92
  import {
81
93
  FormNameContext,
82
94
  Group,
@@ -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-3WWWKPB4.js";
105
119
 
106
120
  // src/PivotReport.jsx
107
- import React12, { useCallback as useCallback10, 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
@@ -342,7 +454,11 @@ function useActiveDrag() {
342
454
  }
343
455
  function collision(args) {
344
456
  if (!args.pointerCoordinates) {
345
- return closestCenter(args);
457
+ const list2 = closestCenter(args);
458
+ const own = list2.find((c) => c.id === args.active.id);
459
+ const start = args.active.rect.current.initial;
460
+ const unmoved = start && Math.abs(args.collisionRect.left - start.left) < 1 && Math.abs(args.collisionRect.top - start.top) < 1;
461
+ return own && unmoved ? [own, ...list2.filter((c) => c !== own)] : list2;
346
462
  }
347
463
  const hits = pointerWithin(args);
348
464
  const list = hits.length ? hits : rectIntersection(args);
@@ -358,11 +474,11 @@ function keyboardCoordinates(event, { context }) {
358
474
  const over = context.over?.data?.current ?? null;
359
475
  const id = nextTarget(event.code, targets, over, context.active?.data?.current ?? { kind: "field" });
360
476
  const rect = id === null ? null : context.droppableRects.get(id);
361
- const own2 = context.collisionRect;
362
- if (!rect || !own2) {
477
+ const own = context.collisionRect;
478
+ if (!rect || !own) {
363
479
  return void 0;
364
480
  }
365
- return { x: rect.left + rect.width / 2 - own2.width / 2, y: rect.top + rect.height / 2 - own2.height / 2 };
481
+ return { x: rect.left + rect.width / 2 - own.width / 2, y: rect.top + rect.height / 2 - own.height / 2 };
366
482
  }
367
483
  function targetOf(source, over) {
368
484
  const data = over?.data?.current;
@@ -433,8 +549,8 @@ function ownEventsOnly(listener) {
433
549
  };
434
550
  }
435
551
  function split(listeners2) {
436
- const own2 = Object.fromEntries(Object.entries(listeners2 ?? {}).map(([name, listener]) => [name, ownEventsOnly(listener)]));
437
- const { onKeyDown, ...pointer } = own2;
552
+ const own = Object.fromEntries(Object.entries(listeners2 ?? {}).map(([name, listener]) => [name, ownEventsOnly(listener)]));
553
+ const { onKeyDown, ...pointer } = own;
438
554
  return { pointer, keyboard: listeners2?.onKeyDown ? { onKeyDown } : {} };
439
555
  }
440
556
  function useDragSource(id, source, disabled = false) {
@@ -456,123 +572,6 @@ function ChipList({ ids, children }) {
456
572
  return /* @__PURE__ */ React2.createElement(SortableContext, { items: ids, strategy: rectSortingStrategy }, children);
457
573
  }
458
574
 
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
575
  // src/fields.jsx
577
576
  import React3, { useCallback, useEffect as useEffect2, useId as useId2, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
578
577
 
@@ -597,6 +596,23 @@ function roveTarget(key, at, rows, slotsOf) {
597
596
  return null;
598
597
  }
599
598
  var opensMenu = (e) => e.key === "ContextMenu" || e.key === "F10" && e.shiftKey;
599
+ function tabStep(key, at, count) {
600
+ if (count <= 0) {
601
+ return null;
602
+ }
603
+ switch (key) {
604
+ case "ArrowRight":
605
+ return (at + 1) % count;
606
+ case "ArrowLeft":
607
+ return (at - 1 + count) % count;
608
+ case "Home":
609
+ return 0;
610
+ case "End":
611
+ return count - 1;
612
+ default:
613
+ return null;
614
+ }
615
+ }
600
616
 
601
617
  // src/fields.jsx
602
618
  function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info, showInfo, stop }) {
@@ -617,8 +633,8 @@ function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info,
617
633
  const action = fieldAction(name, field.type, zones, labels);
618
634
  const describedBy = useId2();
619
635
  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;
636
+ const own = stop && slots.includes(stop) ? stop : stop ? "name" : null;
637
+ const tab = (slot) => own === slot ? 0 : -1;
622
638
  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
639
  /** @type {any} */
624
640
  TYPE_ICON[field.type] ?? "text"
@@ -671,10 +687,7 @@ function FieldPanel({ fields, placed, labels, onAdd, onNote, onFilter, drawer, o
671
687
  const [query, setQuery] = useState3("");
672
688
  const active = useActiveDrag();
673
689
  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]);
690
+ const shown = useMemo2(() => matchingFields(fields, query, info), [fields, query, info]);
678
691
  const removing = active && active.kind !== "field";
679
692
  const modal = drawer && open;
680
693
  const el = useRef2(
@@ -1013,9 +1026,9 @@ function rowLabelOf(grid, r) {
1013
1026
  const row = grid.headerRows + r;
1014
1027
  const texts = [];
1015
1028
  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);
1029
+ const own = grid.rows[row]?.[c];
1030
+ const merge = own ? null : grid.merges.find((m) => m.row <= row && row < m.row + m.rowSpan && m.col <= c && c < m.col + m.colSpan);
1031
+ const cell = own ?? (merge && merge.col === c ? grid.rows[merge.row][merge.col] : null);
1019
1032
  if (cell && cell.text) {
1020
1033
  texts.push(cell.text);
1021
1034
  }
@@ -1048,6 +1061,23 @@ function longestLabels(grid, col, n) {
1048
1061
  return out;
1049
1062
  }
1050
1063
 
1064
+ // src/label-room.js
1065
+ function commonCap(widths, room) {
1066
+ if (room <= 0) {
1067
+ return 0;
1068
+ }
1069
+ const sorted = [...widths].sort((a, b) => a - b);
1070
+ let left = room;
1071
+ for (let i = 0; i < sorted.length; i++) {
1072
+ const share = left / (sorted.length - i);
1073
+ if (sorted[i] > share) {
1074
+ return share;
1075
+ }
1076
+ left -= sorted[i];
1077
+ }
1078
+ return Infinity;
1079
+ }
1080
+
1051
1081
  // src/table.jsx
1052
1082
  var totalClass = (t) => t === 2 ? " pk-grand" : t === 1 ? " pk-sub" : "";
1053
1083
  var MEASURED_LABELS = 50;
@@ -1065,7 +1095,7 @@ function labelWidths(grid, table) {
1065
1095
  Object.assign(probe.style, { position: "absolute", visibility: "hidden", whiteSpace: "pre", width: "auto", minWidth: "0", maxWidth: "none", overflow: "visible" });
1066
1096
  content.append(probe);
1067
1097
  try {
1068
- const widthOf = (l) => {
1098
+ const widthOf2 = (l) => {
1069
1099
  probe.style.fontWeight = l.total ? "var(--pk-weight-bold)" : "";
1070
1100
  probe.textContent = l.text;
1071
1101
  return probe.getBoundingClientRect().width;
@@ -1076,7 +1106,7 @@ function labelWidths(grid, table) {
1076
1106
  const toggleWidth = (toggle ? toggle.getBoundingClientRect().width : em * 1.7) + gap;
1077
1107
  const widths = [];
1078
1108
  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)));
1109
+ const most = Math.max(0, ...longestLabels(grid, c, MEASURED_LABELS).map((l) => widthOf2(l) + (l.toggle ? toggleWidth : 0)));
1080
1110
  widths.push(Math.min(Math.ceil(most) + LABEL_SLACK, LABEL_MAX_EM * em));
1081
1111
  }
1082
1112
  return widths;
@@ -1084,6 +1114,40 @@ function labelWidths(grid, table) {
1084
1114
  probe.remove();
1085
1115
  }
1086
1116
  }
1117
+ var widthOf = (el) => el.getBoundingClientRect().width;
1118
+ function fitLabels(table, box, columns) {
1119
+ if (box.clientWidth === 0) {
1120
+ return;
1121
+ }
1122
+ const over = () => box.scrollWidth - box.clientWidth;
1123
+ table.setAttribute("data-pk-labels", "natural");
1124
+ table.style.removeProperty("--pk-row-room");
1125
+ const head = table.tHead ? table.tHead.rows : [];
1126
+ const last = head[head.length - 1];
1127
+ const overflow = over();
1128
+ if (overflow <= 0 || !last) {
1129
+ return;
1130
+ }
1131
+ const cells = [...last.cells].slice(0, columns);
1132
+ const extras = cells.map((cell) => {
1133
+ const s = getComputedStyle(cell);
1134
+ const grip = cell.querySelector(":scope > .pk-th-grip");
1135
+ return parseFloat(s.paddingLeft) + parseFloat(s.paddingRight) + parseFloat(s.borderLeftWidth) + parseFloat(s.borderRightWidth) + (grip ? widthOf(grip) + parseFloat(getComputedStyle(grip).marginLeft) : 0);
1136
+ });
1137
+ const widths = cells.map((cell, c) => widthOf(cell) - extras[c]);
1138
+ const names = [...last.querySelectorAll("th.pk-colHeader .pk-th-content")].reduce((sum, el) => sum + widthOf(el), 0);
1139
+ const pliable = names + (table.classList.contains("pk-virtual") ? 0 : widths.reduce((a, b) => a + b, 0));
1140
+ if (overflow < pliable) {
1141
+ table.setAttribute("data-pk-labels", "share");
1142
+ if (over() <= 0) {
1143
+ return;
1144
+ }
1145
+ }
1146
+ table.removeAttribute("data-pk-labels");
1147
+ const values = widthOf(table) - cells.reduce((sum, cell) => sum + widthOf(cell), 0);
1148
+ const room = commonCap(widths, box.clientWidth - values - extras.reduce((a, b) => a + b, 0));
1149
+ table.style.setProperty("--pk-row-room", `${Number.isFinite(room) ? Math.floor(room) : Math.max(0, ...widths)}px`);
1150
+ }
1087
1151
  var fontOf = (table) => {
1088
1152
  const s = getComputedStyle(table);
1089
1153
  return `${s.fontFamily}|${s.fontSize}|${s.fontWeight}`;
@@ -1158,6 +1222,11 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1158
1222
  null
1159
1223
  );
1160
1224
  const [fontsLoaded, setFontsLoaded] = useState5(0);
1225
+ const [font, setFont] = useState5("");
1226
+ const fitted = useRef4(
1227
+ /** @type {unknown[]} */
1228
+ []
1229
+ );
1161
1230
  const fixedWidths = virtual && labelsWide?.grid === grid ? labelsWide.widths : null;
1162
1231
  const focusNext = useRef4(false);
1163
1232
  const [sortNote, setSortNote] = useState5("");
@@ -1177,16 +1246,16 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1177
1246
  if (!virtual || !t) {
1178
1247
  return;
1179
1248
  }
1180
- const font = fontOf(t);
1181
- if (labelsWide?.grid !== grid || labelsWide.font !== font || labelsWide.fonts !== fontsLoaded) {
1249
+ const font2 = fontOf(t);
1250
+ if (labelsWide?.grid !== grid || labelsWide.font !== font2 || labelsWide.fonts !== fontsLoaded) {
1182
1251
  const widths = labelWidths(grid, t);
1183
1252
  if (widths) {
1184
- setLabelsWide({ grid, font, fonts: fontsLoaded, widths });
1253
+ setLabelsWide({ grid, font: font2, fonts: fontsLoaded, widths });
1185
1254
  }
1186
1255
  }
1187
1256
  });
1188
1257
  useEffect4(() => {
1189
- const fonts = virtual ? table.current?.ownerDocument.fonts : void 0;
1258
+ const fonts = table.current?.ownerDocument.fonts;
1190
1259
  if (!fonts) {
1191
1260
  return void 0;
1192
1261
  }
@@ -1200,12 +1269,17 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1200
1269
  live = false;
1201
1270
  fonts.removeEventListener?.("loadingdone", loaded3);
1202
1271
  };
1203
- }, [virtual]);
1272
+ }, []);
1204
1273
  useIsoLayoutEffect(() => {
1205
1274
  const t = table.current;
1206
1275
  if (!t) {
1207
1276
  return;
1208
1277
  }
1278
+ const key = [t, grid, width, font, fontsLoaded, fixedWidths];
1279
+ if (wrap.current && !key.every((v, i) => v === fitted.current[i])) {
1280
+ fitted.current = key;
1281
+ fitLabels(t, wrap.current, grid.rowHeaderColumns);
1282
+ }
1209
1283
  const row = t.tBodies[0]?.querySelector("tr[data-r]");
1210
1284
  if (row && row.getBoundingClientRect().height > 0) {
1211
1285
  setRowHeight(row.getBoundingClientRect().height);
@@ -1225,7 +1299,7 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1225
1299
  }
1226
1300
  setLefts((old) => old.length === xs.length && old.every((v, i) => Math.abs(v - xs[i]) < 0.5) ? old : xs);
1227
1301
  }
1228
- }, [grid, version, width, fixedWidths]);
1302
+ }, [grid, version, width, font, fixedWidths, fontsLoaded]);
1229
1303
  useEffect4(() => {
1230
1304
  const el = wrap.current;
1231
1305
  if (!el) {
@@ -1234,6 +1308,9 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
1234
1308
  const update = () => {
1235
1309
  setScroll({ top: el.scrollTop, height: el.clientHeight });
1236
1310
  setWidth(el.clientWidth);
1311
+ if (table.current) {
1312
+ setFont(fontOf(table.current));
1313
+ }
1237
1314
  };
1238
1315
  update();
1239
1316
  const ro = typeof ResizeObserver === "function" ? new ResizeObserver(update) : null;
@@ -1497,12 +1574,12 @@ function Toasts({ toasts, dismiss, pause, closeLabel }) {
1497
1574
  }
1498
1575
 
1499
1576
  // src/templates.js
1500
- import { fieldDefaultsFromSchema as fieldDefaultsFromSchema2, fromViewFile } from "pivotkit-core";
1577
+ import { fieldDefaultsFromSchema, fromViewFile } from "pivotkit-core";
1501
1578
  var warnedScope = false;
1502
1579
  function plainNames(names) {
1503
1580
  const properties = {};
1504
1581
  names.forEach((title, i) => Object.defineProperty(properties, String(i), { value: { title }, enumerable: true }));
1505
- const clean = names.length ? fieldDefaultsFromSchema2({ properties }).defaults : {};
1582
+ const clean = names.length ? fieldDefaultsFromSchema({ properties }).defaults : {};
1506
1583
  return names.map((n, i) => Object.hasOwn(clean, String(i)) ? clean[String(i)].label : void 0);
1507
1584
  }
1508
1585
  var viewsName = (key) => key ? `pivotkit:views:${key}` : "pivotkit:views";
@@ -1591,15 +1668,15 @@ import React9, { useEffect as useEffect7, useMemo as useMemo4, useRef as useRef7
1591
1668
  import { fieldLabel as fieldLabel3 } from "pivotkit-core";
1592
1669
 
1593
1670
  // src/unused-load.js
1594
- var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-6YVPTNVS.js").then((m) => m.de) });
1671
+ var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-GB3IWWEM.js").then((m) => m.de) });
1595
1672
  var pending2 = /* @__PURE__ */ new Map();
1596
1673
  var loaded2 = /* @__PURE__ */ new Map();
1597
1674
  var unusedNow = (lang) => loaded2.get(lang) ?? null;
1598
1675
  function loadUnused(lang) {
1599
1676
  let p = pending2.get(lang);
1600
1677
  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(
1678
+ const own = Object.hasOwn(UNUSED_TEXTS_OF, lang) ? UNUSED_TEXTS_OF[lang]().catch(() => null) : null;
1679
+ p = Promise.all([import("./chunks/unused-texts-LRYVWFFN.js"), own]).then(
1603
1680
  ([mod, texts]) => {
1604
1681
  const out = { mod, lang: texts };
1605
1682
  loaded2.set(lang, out);
@@ -1695,7 +1772,7 @@ function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow,
1695
1772
  // src/unused-keep.js
1696
1773
  var PATH = /^([A-Za-z]+)(?:\[(\d+)\])?(?:\.([A-Za-z]+))?/;
1697
1774
  var lower = (v) => typeof v === "string" ? v.toLowerCase() : v;
1698
- var isObject2 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
1775
+ var isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
1699
1776
  function partOf(path, raw, view) {
1700
1777
  const m = PATH.exec(path ?? "");
1701
1778
  if (!m) {
@@ -1704,19 +1781,19 @@ function partOf(path, raw, view) {
1704
1781
  const [, key, index, sub] = m;
1705
1782
  const section = Object.hasOwn(view, key) ? view[key] : void 0;
1706
1783
  if (key === "values" && index !== void 0 && Array.isArray(section)) {
1707
- const given = isObject2(raw) && Array.isArray(
1784
+ const given = isObject(raw) && Array.isArray(
1708
1785
  /** @type {any} */
1709
1786
  raw.values
1710
1787
  ) ? (
1711
1788
  /** @type {any} */
1712
1789
  raw.values[Number(index)]
1713
1790
  ) : 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;
1791
+ const match = isObject(given) ? section.find((v) => lower(v.field ?? null) === lower(given.field ?? null) && lower(v.agg) === lower(given.agg)) : void 0;
1715
1792
  if (match) {
1716
1793
  return JSON.stringify(match);
1717
1794
  }
1718
1795
  }
1719
- if (sub !== void 0 && isObject2(section)) {
1796
+ if (sub !== void 0 && isObject(section)) {
1720
1797
  return JSON.stringify(Object.hasOwn(section, sub) ? section[sub] : void 0);
1721
1798
  }
1722
1799
  return JSON.stringify(section);
@@ -1735,25 +1812,20 @@ function stillApplies(note, loaded3, shown) {
1735
1812
  import React10, { useCallback as useCallback4, useEffect as useEffect8, useMemo as useMemo5, useRef as useRef8, useState as useState8 } from "react";
1736
1813
 
1737
1814
  // 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"])]);
1815
+ var OVERFLOW_ORDER = Object.freeze(["data", "startOver", "views"]);
1816
+ var MORE_GROUPS = Object.freeze([Object.freeze(["startOver"]), Object.freeze(["data"]), Object.freeze(["views"])]);
1740
1817
  var TOOLBAR_ROOM = Object.freeze({
1741
1818
  fields: 6.4,
1742
- display: 15.3,
1743
- chartType: 12.9,
1744
- sep: 1,
1745
1819
  undo: 8.75,
1746
1820
  redo: 9.15,
1747
1821
  startOver: 10.9,
1748
- layout: 8.4,
1749
- options: 8.75,
1750
1822
  data: 7.4,
1751
1823
  views: 9.1,
1752
1824
  export: 7.5,
1753
1825
  more: 7.2
1754
1826
  });
1755
- var TEXT_BUTTONS = Object.freeze(["fields", "undo", "redo", "layout"]);
1756
- var MENU_BUTTONS = Object.freeze(["chartType", "startOver", "options", "data", "views", "export", "more"]);
1827
+ var TEXT_BUTTONS = Object.freeze(["fields", "undo", "redo"]);
1828
+ var MENU_BUTTONS = Object.freeze(["startOver", "data", "views", "export", "more"]);
1757
1829
  function toolbarTexts(labels) {
1758
1830
  const text = (v) => typeof v === "string" ? v : "";
1759
1831
  return (
@@ -1763,22 +1835,18 @@ function toolbarTexts(labels) {
1763
1835
  undo: [text(labels.undo)],
1764
1836
  redo: [text(labels.redo)],
1765
1837
  startOver: [text(labels.startOver)],
1766
- layout: [text(labels.layout)],
1767
- options: [text(labels.options)],
1768
1838
  views: [text(labels.views)],
1769
1839
  data: [text(labels.data)],
1770
1840
  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)]]
1841
+ more: [text(labels.more)]
1774
1842
  }
1775
1843
  );
1776
1844
  }
1777
1845
  function toolbarRoom(texts, measure, chrome) {
1778
- const widest = (list, kind = "button") => Math.max(0, ...list.map((t) => measure(t, kind)));
1846
+ const widest = (list) => Math.max(0, ...list.map((t) => measure(t)));
1779
1847
  const room = (
1780
1848
  /** @type {Record<string, number>} */
1781
- { sep: chrome.sep + chrome.gap }
1849
+ {}
1782
1850
  );
1783
1851
  for (const id of TEXT_BUTTONS) {
1784
1852
  room[id] = chrome.text + widest(texts[id]) + chrome.gap;
@@ -1786,13 +1854,12 @@ function toolbarRoom(texts, measure, chrome) {
1786
1854
  for (const id of MENU_BUTTONS) {
1787
1855
  room[id] = chrome.menu + widest(texts[id]) + chrome.gap;
1788
1856
  }
1789
- room.display = chrome.display + Math.max(0, ...texts.display.map(([a, b]) => measure(a, "display") + measure(b, "display"))) + chrome.gap;
1790
1857
  return room;
1791
1858
  }
1792
1859
  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;
1860
+ const fixed = (narrow ? room.fields : 0) + room.undo + room.redo + room.export + room.more;
1794
1861
  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);
1862
+ const need = (shown2) => fixed + shown2.reduce((sum, id) => sum + (room[id] ?? 0), 0);
1796
1863
  let shown = order;
1797
1864
  while (shown.length && need(shown) > width) {
1798
1865
  shown = shown.slice(1);
@@ -1824,37 +1891,28 @@ function measuredRoom(el, texts) {
1824
1891
  }
1825
1892
  const undo2 = el.querySelector("[data-testid='undo']");
1826
1893
  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)) {
1894
+ const textOf = (node) => node?.querySelector(".pk-btn-text");
1895
+ if (!measuring || !undo2 || !menu || !textOf(undo2) || !textOf(menu)) {
1831
1896
  return null;
1832
1897
  }
1833
1898
  const view = doc.defaultView;
1834
1899
  if (!view) {
1835
1900
  return null;
1836
1901
  }
1837
- const fonts = { button: fontOf2(view.getComputedStyle(
1902
+ const font = fontOf2(view.getComputedStyle(
1838
1903
  /** @type {Element} */
1839
1904
  textOf(undo2)
1840
- )), display: fontOf2(view.getComputedStyle(
1841
- /** @type {Element} */
1842
- textOf(display)
1843
- )) };
1905
+ ));
1844
1906
  const ctx = measuring;
1845
- const measure = (text, kind) => {
1846
- ctx.font = fonts[kind];
1907
+ const measure = (text) => {
1908
+ ctx.font = font;
1847
1909
  return ctx.measureText(text).width;
1848
1910
  };
1849
1911
  const w = (node) => node.getBoundingClientRect().width;
1850
1912
  const tw = (node) => node ? node.getBoundingClientRect().width : 0;
1851
- const segTexts = [...display.querySelectorAll("button > span")];
1852
- const sepStyle = sep ? view.getComputedStyle(sep) : null;
1853
1913
  const chrome = {
1854
1914
  text: w(undo2) - tw(textOf(undo2)),
1855
1915
  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
1916
  // one more px per part: text widths are fractional, the buttons round them
1859
1917
  gap: (parseFloat(view.getComputedStyle(el).columnGap) || 0) + 1
1860
1918
  };
@@ -1892,8 +1950,8 @@ function useOverflow(ref, key, narrow, present, texts) {
1892
1950
  waiting.current = false;
1893
1951
  const em = parseFloat(getComputedStyle(el).fontSize) || 14;
1894
1952
  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));
1953
+ const own = latest.current.present;
1954
+ setDecided(room ? overflowHidden(width, narrow, own, room) : overflowHidden(width / em, narrow, own));
1897
1955
  setExtra(0);
1898
1956
  setMeasure((m) => m + 1);
1899
1957
  };
@@ -1929,7 +1987,7 @@ function useOverflow(ref, key, narrow, present, texts) {
1929
1987
  return order.filter((id) => decided.includes(id) || more.includes(id));
1930
1988
  }
1931
1989
  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;
1990
+ const { view, labels, size, canUndo, canRedo, canReset, startEmpty, canNew, onUndo, onRedo, onReset, onNew, loadedView, empty, templates, onLoadTemplate, templateActions, onExport, chartReady, onShowFields, share } = props;
1933
1991
  const tips = { controls: props.tipsControls, on: props.tipsOn, onOn: props.onTipsOn, canReset: props.canResetTips, onReset: props.onResetTips };
1934
1992
  const bar = useRef8(
1935
1993
  /** @type {HTMLDivElement | null} */
@@ -1944,21 +2002,15 @@ function Toolbar(props) {
1944
2002
  null
1945
2003
  );
1946
2004
  const [panel, setPanel] = useState8(
1947
- /** @type {"options" | "views" | "chartType" | "data" | null} */
2005
+ /** @type {"views" | "data" | null} */
1948
2006
  null
1949
2007
  );
1950
2008
  const data = props.data;
1951
2009
  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
2010
  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
2011
  const panels = {
1958
2012
  // 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
2013
  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
2014
  data: (close) => data?.panel(close)
1963
2015
  };
1964
2016
  const loadedMark = (testId) => data?.loaded ? dot(testId, labels.dataLoaded) : null;
@@ -1974,36 +2026,11 @@ function Toolbar(props) {
1974
2026
  }, testId: `${prefix}new-report` }, labels.newEmpty)
1975
2027
  ];
1976
2028
  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
2029
  startOver: {
1986
2030
  place: "history",
1987
2031
  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
2032
  entry: (close) => startOverItems(close, "more-")
1989
2033
  },
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
2034
  ...data ? {
2008
2035
  data: {
2009
2036
  place: (
@@ -2028,7 +2055,7 @@ function Toolbar(props) {
2028
2055
  };
2029
2056
  const ORDER = Object.keys(actions);
2030
2057
  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);
2058
+ const hiddenList = useOverflow(bar, `${labels.lang}:${labels.undo}:${labels.more}:${size}:${present.join()}`, size === "narrow", present, texts);
2032
2059
  const hidden = new Set(hiddenList);
2033
2060
  if (panel && !hidden.has(panel)) {
2034
2061
  setPanel(null);
@@ -2076,10 +2103,67 @@ function Toolbar(props) {
2076
2103
  /* @__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
2104
  ] : []
2078
2105
  );
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);
2106
+ 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);
2107
+ }
2108
+
2109
+ // src/view-tabs.jsx
2110
+ import React11, { useRef as useRef9 } from "react";
2111
+ var TABS = Object.freeze(
2112
+ /** @type {const} */
2113
+ ["table", "chart"]
2114
+ );
2115
+ var tabId = (panelId, display) => `${panelId}-${display}`;
2116
+ function ViewTabs(props) {
2117
+ const { view, labels, panelId, narrow, onDisplay, plan, big } = props;
2118
+ const list = useRef9(
2119
+ /** @type {HTMLDivElement | null} */
2120
+ null
2121
+ );
2122
+ const chart = view.display === "chart";
2123
+ const settings = chart ? labels.chartSettings : labels.tableSettings;
2124
+ const onKeyDown = (e) => {
2125
+ const tabs = (
2126
+ /** @type {HTMLElement[]} */
2127
+ [...list.current?.querySelectorAll('[role="tab"]') ?? []]
2128
+ );
2129
+ const at = tabs.indexOf(
2130
+ /** @type {HTMLElement} */
2131
+ e.target
2132
+ );
2133
+ const next = at < 0 ? null : tabStep(e.key, at, tabs.length);
2134
+ if (next !== null) {
2135
+ e.preventDefault();
2136
+ tabs[next].focus();
2137
+ }
2138
+ };
2139
+ const iconOnly = (name) => narrow ? { "aria-label": name, title: name } : {};
2140
+ 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(
2141
+ "button",
2142
+ {
2143
+ key: d,
2144
+ type: "button",
2145
+ role: "tab",
2146
+ id: tabId(panelId, d),
2147
+ "aria-selected": view.display === d,
2148
+ "aria-controls": panelId,
2149
+ tabIndex: view.display === d ? 0 : -1,
2150
+ className: "pk-tab",
2151
+ onClick: () => view.display === d ? void 0 : onDisplay(d),
2152
+ "data-testid": `show-${d}`
2153
+ },
2154
+ /* @__PURE__ */ React11.createElement(Icon, { name: (
2155
+ /** @type {any} */
2156
+ d === "table" ? "table" : CHART_TYPES[plan.name].icon
2157
+ ) }),
2158
+ /* @__PURE__ */ React11.createElement("span", null, d === "table" ? labels.table : labels.chart)
2159
+ ))), /* @__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(
2160
+ MenuPanel,
2161
+ {
2162
+ name: "ChartSettingsPanel",
2163
+ loadingText: labels.loadingMenu,
2164
+ 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 }
2165
+ }
2166
+ ) : /* @__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
2167
  }
2084
2168
 
2085
2169
  // src/use-export.js
@@ -2321,7 +2405,7 @@ function keptData(key, host) {
2321
2405
  }
2322
2406
 
2323
2407
  // src/use-big-result.js
2324
- import { useCallback as useCallback8, useEffect as useEffect9, useRef as useRef9, useState as useState10, useSyncExternalStore as useSyncExternalStore2 } from "react";
2408
+ import { useCallback as useCallback8, useEffect as useEffect9, useRef as useRef10, useState as useState10, useSyncExternalStore as useSyncExternalStore2 } from "react";
2325
2409
  function fullScreenSupported() {
2326
2410
  return typeof document !== "undefined" && Boolean(document.fullscreenEnabled) && typeof HTMLElement !== "undefined" && typeof HTMLElement.prototype.requestFullscreen === "function";
2327
2411
  }
@@ -2361,11 +2445,23 @@ function useBigResult(root) {
2361
2445
  };
2362
2446
  return { enlarged, setEnlarged, toggleEnlarged, full, fullOk, toggleFull };
2363
2447
  }
2364
- function useFitHeight(root, main, grow) {
2365
- const fit = useRef9({ need: 0, open: 0, grow });
2448
+ function useFitHeight(root, main, grow, onOpen) {
2449
+ const fit = useRef10(
2450
+ /** @type {FitState} */
2451
+ { need: 0, open: 0, grow, folded: null, size: null }
2452
+ );
2453
+ const opened = useRef10(onOpen);
2454
+ const watch = useRef10(
2455
+ /** @type {{ ro: ResizeObserver | null, parts: Set<Element> }} */
2456
+ { ro: null, parts: /* @__PURE__ */ new Set() }
2457
+ );
2366
2458
  useIsoLayoutEffect(() => {
2459
+ opened.current = onOpen;
2367
2460
  fit.current.grow = grow;
2368
- measureFit(root.current, main.current, fit);
2461
+ watchParts(watch.current, main.current);
2462
+ if (measureFit(root.current, main.current, fit)) {
2463
+ opened.current?.();
2464
+ }
2369
2465
  });
2370
2466
  useIsoLayoutEffect(() => {
2371
2467
  const el = root.current;
@@ -2375,26 +2471,72 @@ function useFitHeight(root, main, grow) {
2375
2471
  let frame = 0;
2376
2472
  const ro = new ResizeObserver(() => {
2377
2473
  cancelAnimationFrame(frame);
2378
- frame = requestAnimationFrame(() => measureFit(root.current, main.current, fit));
2474
+ frame = requestAnimationFrame(() => {
2475
+ if (measureFit(root.current, main.current, fit)) {
2476
+ opened.current?.();
2477
+ }
2478
+ });
2379
2479
  });
2380
2480
  ro.observe(el);
2481
+ const w = watch.current;
2482
+ w.ro = ro;
2483
+ watchParts(w, main.current);
2381
2484
  return () => {
2382
2485
  cancelAnimationFrame(frame);
2383
2486
  ro.disconnect();
2487
+ w.ro = null;
2488
+ w.parts = /* @__PURE__ */ new Set();
2384
2489
  };
2385
2490
  }, [root, main]);
2386
2491
  return fit;
2387
2492
  }
2493
+ function watchParts(w, m) {
2494
+ if (!w.ro || !m) {
2495
+ return;
2496
+ }
2497
+ const now = new Set(m.children);
2498
+ for (const part of w.parts) {
2499
+ if (!now.has(part)) {
2500
+ w.ro.unobserve(part);
2501
+ }
2502
+ }
2503
+ for (const part of now) {
2504
+ if (!w.parts.has(part)) {
2505
+ w.ro.observe(part);
2506
+ }
2507
+ }
2508
+ w.parts = now;
2509
+ }
2388
2510
  function measureFit(el, m, fit) {
2389
2511
  const result = m?.querySelector(":scope > .pk-result");
2390
2512
  if (!el || !m || !(result instanceof HTMLElement)) {
2391
- return;
2513
+ return false;
2392
2514
  }
2393
2515
  const least = parseFloat(el.ownerDocument.defaultView?.getComputedStyle(result).getPropertyValue("--pk-result-least") ?? "") || 0;
2394
2516
  const needMain = m.scrollHeight - result.offsetHeight + least;
2395
2517
  const need = Math.ceil(el.offsetHeight - m.clientHeight + needMain);
2396
- if (!el.hasAttribute("data-pk-layout") && !el.hasAttribute("data-pk-enlarged")) {
2397
- fit.current.open = need;
2518
+ const f = fit.current;
2519
+ const size = el.getAttribute("data-pk-size");
2520
+ let changed = false;
2521
+ if (size !== f.size) {
2522
+ changed = f.open > 0;
2523
+ f.size = size;
2524
+ f.folded = null;
2525
+ f.open = 0;
2526
+ }
2527
+ let open = f.open;
2528
+ if (el.hasAttribute("data-pk-enlarged")) {
2529
+ f.folded = null;
2530
+ } else if (!el.hasAttribute("data-pk-layout")) {
2531
+ f.folded = null;
2532
+ open = need;
2533
+ } else if (f.open > 0) {
2534
+ f.folded ??= { need, open: f.open };
2535
+ open = f.folded.open - (f.folded.need - need);
2536
+ }
2537
+ if (Math.abs(open - f.open) > 1) {
2538
+ f.open = open;
2539
+ changed = true;
2398
2540
  }
2399
2541
  if (!fit.current.grow) {
2400
2542
  fit.current.need = 0;
@@ -2403,10 +2545,11 @@ function measureFit(el, m, fit) {
2403
2545
  fit.current.need = need;
2404
2546
  el.style.minHeight = `${need}px`;
2405
2547
  }
2548
+ return changed;
2406
2549
  }
2407
2550
 
2408
2551
  // src/zones.jsx
2409
- import React11, { useCallback as useCallback9, useEffect as useEffect10, useMemo as useMemo7, useRef as useRef10, useState as useState11 } from "react";
2552
+ import React12, { useCallback as useCallback9, useEffect as useEffect10, useId as useId4, useMemo as useMemo7, useRef as useRef11, useState as useState11 } from "react";
2410
2553
  import { fieldItems, fieldLabel as fieldLabel4 } from "pivotkit-core";
2411
2554
  function fieldState(view, field, encoded, locale, labels, sourceType) {
2412
2555
  const items = filtersOf(view, field, ["in"]).filter((f) => !isEmptyPick(f));
@@ -2450,47 +2593,48 @@ function Badges({ state, view, labels, locale }) {
2450
2593
  if (state.summary) {
2451
2594
  const text = fill(labels.filterSummary, { shown: state.summary.shown.toLocaleString(locale), total: state.summary.total.toLocaleString(locale) });
2452
2595
  parts.push(
2453
- /* @__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)
2596
+ /* @__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)
2454
2597
  );
2455
2598
  }
2456
2599
  if (state.rules.length) {
2457
2600
  const more = state.rules.length - 1;
2458
2601
  parts.push(
2459
- /* @__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)
2602
+ /* @__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)
2460
2603
  );
2461
2604
  }
2462
2605
  if (state.top) {
2463
2606
  const text = fill(state.top.bottom ? labels.bottomBadge : labels.topBadge, { count: state.top.count.toLocaleString(locale) });
2464
2607
  parts.push(
2465
- /* @__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)
2608
+ /* @__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)
2466
2609
  );
2467
2610
  }
2468
2611
  if (state.condition) {
2469
2612
  const text = valueConditionText(view, state.condition, labels, locale);
2470
2613
  parts.push(
2471
- /* @__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))
2614
+ /* @__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))
2472
2615
  );
2473
2616
  }
2474
2617
  if (state.sort) {
2475
2618
  const desc = state.sort.order === "desc";
2476
- parts.push(/* @__PURE__ */ React11.createElement(Icon, { key: "sort", name: desc ? "sortDesc" : "sortAsc", size: 12, className: "pk-chip-badge" }));
2619
+ parts.push(/* @__PURE__ */ React12.createElement(Icon, { key: "sort", name: desc ? "sortDesc" : "sortAsc", size: 12, className: "pk-chip-badge" }));
2477
2620
  }
2478
- return parts.length ? /* @__PURE__ */ React11.createElement(React11.Fragment, null, parts) : null;
2621
+ return parts.length ? /* @__PURE__ */ React12.createElement(React12.Fragment, null, parts) : null;
2479
2622
  }
2480
- function Chip({ id, zone, index, count, field, text, typeName, view, types, labels, commit, onRemove, state, locale, defaultsOf, earlier, rangeOf, info, showInfo, encoded }) {
2623
+ function Chip({ id, zone, index, count, field, text, title, typeName, view, types, labels, commit, onRemove, state, locale, defaultsOf, earlier, rangeOf, info, showInfo, encoded }) {
2481
2624
  const { setNodeRef, isDragging, style, itemProps, handleProps } = useChip(id, { kind: "chip", zone, index, count, field, label: text, type: typeName });
2482
- const badges = state ? /* @__PURE__ */ React11.createElement(Badges, { state, view, labels, locale }) : null;
2625
+ const badges = state ? /* @__PURE__ */ React12.createElement(Badges, { state, view, labels, locale }) : null;
2483
2626
  const words = stateWords(state, view, labels, locale);
2484
- const name = words ? `${text}, ${words}` : void 0;
2627
+ const full = title ?? text;
2628
+ const name = words ? `${full}, ${words}` : title;
2485
2629
  const remove = () => onRemove(zone, index, text);
2486
- 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: (
2630
+ 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: (
2487
2631
  /** @type {any} */
2488
2632
  TYPE_ICON[typeName] ?? "text"
2489
- ), size: 13 })), /* @__PURE__ */ React11.createElement(
2633
+ ), size: 13 })), /* @__PURE__ */ React12.createElement(
2490
2634
  MenuButton,
2491
2635
  {
2492
2636
  label: fill(labels.fieldMenu, { field: text }),
2493
- text: /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement("span", { className: "pk-chip-name" }, text), badges),
2637
+ text: /* @__PURE__ */ React12.createElement(React12.Fragment, null, /* @__PURE__ */ React12.createElement("span", { className: "pk-chip-name" }, text), badges),
2494
2638
  className: "pk-chip-label",
2495
2639
  name,
2496
2640
  title: name ?? text,
@@ -2499,10 +2643,14 @@ function Chip({ id, zone, index, count, field, text, typeName, view, types, labe
2499
2643
  fill: true,
2500
2644
  testId: `chip-menu-${text}`
2501
2645
  },
2502
- (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 } })
2503
- ), 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 })));
2646
+ (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 } })
2647
+ ), 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 })));
2504
2648
  }
2505
- function Zone({ zone, entries, labels, children, action, explain }) {
2649
+ function AddButton({ zone, labels, menu }) {
2650
+ const name = fill(labels.addFieldTo, { zone: labels.zones[zone] });
2651
+ 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 } }));
2652
+ }
2653
+ function Zone({ zone, entries, labels, children, explain, add }) {
2506
2654
  const count = entries.length;
2507
2655
  const { setNodeRef, isOver } = useDropTarget(`zone:${zone}`, { kind: "zone", zone, count });
2508
2656
  const active = useActiveDrag();
@@ -2522,11 +2670,13 @@ function Zone({ zone, entries, labels, children, action, explain }) {
2522
2670
  const t = setTimeout(() => setFlash(false), 600);
2523
2671
  return () => clearTimeout(t);
2524
2672
  }, [flash]);
2525
- 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: (
2673
+ 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: (
2526
2674
  /** @type {any} */
2527
2675
  ZONE_ICON[zone]
2528
- ), 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)));
2676
+ ), 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)));
2529
2677
  }
2678
+ var SAY_AFTER = 100;
2679
+ var SAY_FOR = 8e3;
2530
2680
  function zoneEntries(view, types, labels) {
2531
2681
  const typeOf = (f) => types.get(String(sourceOf(view, f)).toLowerCase()) ?? "string";
2532
2682
  const seen = /* @__PURE__ */ new Map();
@@ -2536,24 +2686,44 @@ function zoneEntries(view, types, labels) {
2536
2686
  filters: filterZoneFields(view).map((f, i) => ({ id: `chip:filters:${f}`, field: f, text: text(f), type: typeOf(f), index: i })),
2537
2687
  cols: axis("cols"),
2538
2688
  rows: axis("rows"),
2539
- values: view.values.map((v, i) => {
2689
+ values: valueLabels(view.values, labels).map((text2, i) => {
2690
+ const v = view.values[i];
2540
2691
  const key = `${v.agg}:${v.field}`;
2541
2692
  seen.set(key, (seen.get(key) ?? 0) + 1);
2542
- return { id: `chip:values:${key}:${seen.get(key)}`, field: v.field, text: valueLabel(v, labels), type: v.field ? typeOf(v.field) : "number", index: i };
2693
+ return { id: `chip:values:${key}:${seen.get(key)}`, field: v.field, text: text2, type: v.field ? typeOf(v.field) : "number", index: i };
2543
2694
  })
2544
2695
  };
2545
2696
  }
2546
- function ZoneSummary({ entries, labels, id, onShow, buttonRef }) {
2697
+ function SectionHead({ entries, labels, id, open, onFold, onSwap, canSwap, buttonRef, explain }) {
2698
+ const own = useId4();
2547
2699
  const parts = layoutSummary(entries, labels);
2548
2700
  const text = parts.length ? parts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
2549
- 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));
2701
+ return /* @__PURE__ */ React12.createElement("div", { className: "pk-section-row" }, /* @__PURE__ */ React12.createElement(
2702
+ "button",
2703
+ {
2704
+ ref: buttonRef,
2705
+ type: "button",
2706
+ className: "pk-section-fold",
2707
+ "aria-expanded": open,
2708
+ "aria-controls": open ? id : void 0,
2709
+ "aria-labelledby": `${own}-t`,
2710
+ "aria-describedby": open ? void 0 : `${own}-s`,
2711
+ title: open ? void 0 : text,
2712
+ onClick: onFold,
2713
+ "data-testid": "layout-summary"
2714
+ },
2715
+ /* @__PURE__ */ React12.createElement(Icon, { name: "chevronRight", className: "pk-section-chevron" }),
2716
+ /* @__PURE__ */ React12.createElement("span", { id: `${own}-t`, className: "pk-section-heading" }, labels.zonesTitle)
2717
+ ), 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" }) : (
2718
+ // the button's description and a larger target for the pointer; the keys use the button
2719
+ /* @__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)
2720
+ ), /* @__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)));
2550
2721
  }
2551
- function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap, id, folded, onShow, defaultsOf, infoOf, explain = false, showInfo = true }) {
2722
+ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap, id, folded, onFold, defaultsOf, infoOf, titleOf, explain = false, showInfo = true, adding }) {
2552
2723
  const entries = useMemo7(() => zoneEntries(view, types, labels), [view, types, labels]);
2553
2724
  const dragging = Boolean(useActiveDrag());
2554
- const showing = useRef10(false);
2555
- const focusInside = useRef10(false);
2556
- const summary = useRef10(
2725
+ const focusInside = useRef11(false);
2726
+ const summary = useRef11(
2557
2727
  /** @type {HTMLButtonElement | null} */
2558
2728
  null
2559
2729
  );
@@ -2567,11 +2737,11 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2567
2737
  return map;
2568
2738
  }, [entries, view, encoded, locale, labels]);
2569
2739
  const rangeOf = useCallback9((field) => numberRange(encoded, field), [encoded]);
2570
- const root = useRef10(
2740
+ const root = useRef11(
2571
2741
  /** @type {HTMLDivElement | null} */
2572
2742
  null
2573
2743
  );
2574
- const focusAfter = useRef10(
2744
+ const focusAfter = useRef11(
2575
2745
  /** @type {{ zone: string, index: number } | null} */
2576
2746
  null
2577
2747
  );
@@ -2593,32 +2763,57 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2593
2763
  );
2594
2764
  target?.focus({ preventScroll: true });
2595
2765
  });
2766
+ const added = useRef11(
2767
+ /** @type {{ zone: string, from: string | null, ids: Set<string> } | null} */
2768
+ null
2769
+ );
2770
+ const [said, setSaid] = useState11("");
2771
+ const sayTimers = useRef11(
2772
+ /** @type {ReturnType<typeof setTimeout>[]} */
2773
+ []
2774
+ );
2775
+ useEffect10(() => () => sayTimers.current.forEach(clearTimeout), []);
2596
2776
  useEffect10(() => {
2597
- if (showing.current && !folded) {
2598
- showing.current = false;
2599
- root.current?.querySelector("[data-zone]")?.focus({ preventScroll: true });
2777
+ const at = added.current;
2778
+ if (!at) {
2779
+ return;
2780
+ }
2781
+ added.current = null;
2782
+ const fresh = entries[at.zone].find((e) => !at.ids.has(e.id));
2783
+ if (!fresh) {
2784
+ return;
2600
2785
  }
2786
+ const chip = root.current?.querySelectorAll(`[data-zone="${at.zone}"] .pk-chip`)[fresh.index];
2787
+ chip?.querySelector(".pk-chip-label")?.focus({ preventScroll: true });
2788
+ 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] : "" });
2789
+ sayTimers.current.forEach(clearTimeout);
2790
+ setSaid("");
2791
+ sayTimers.current = [setTimeout(() => setSaid(text), SAY_AFTER), setTimeout(() => setSaid(""), SAY_FOR)];
2792
+ }, [entries, labels]);
2793
+ const addMenu = useMemo7(
2794
+ () => adding ? {
2795
+ ...adding,
2796
+ view,
2797
+ commit,
2798
+ encoded,
2799
+ locale,
2800
+ onAdded: (zone) => (from, run) => {
2801
+ added.current = { zone, from, ids: new Set(entries[zone].map((e) => e.id)) };
2802
+ if (!run()) {
2803
+ added.current = null;
2804
+ }
2805
+ }
2806
+ } : null,
2807
+ [adding, view, commit, encoded, locale, entries]
2808
+ );
2809
+ useEffect10(() => {
2601
2810
  if (folded && focusInside.current) {
2602
2811
  focusInside.current = false;
2603
2812
  summary.current?.focus({ preventScroll: true });
2604
2813
  }
2605
2814
  }, [folded]);
2606
- if (folded && !dragging) {
2607
- return /* @__PURE__ */ React11.createElement(
2608
- ZoneSummary,
2609
- {
2610
- entries,
2611
- labels,
2612
- id,
2613
- buttonRef: summary,
2614
- onShow: () => {
2615
- showing.current = true;
2616
- onShow();
2617
- }
2618
- }
2619
- );
2620
- }
2621
- return /* @__PURE__ */ React11.createElement(
2815
+ const open = !folded || dragging;
2816
+ 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(
2622
2817
  "div",
2623
2818
  {
2624
2819
  className: "pk-zones",
@@ -2636,7 +2831,7 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2636
2831
  }
2637
2832
  }
2638
2833
  },
2639
- ZONES.map((zone) => /* @__PURE__ */ React11.createElement(
2834
+ ZONES.map((zone) => /* @__PURE__ */ React12.createElement(
2640
2835
  Zone,
2641
2836
  {
2642
2837
  key: zone,
@@ -2644,12 +2839,9 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2644
2839
  entries: entries[zone],
2645
2840
  labels,
2646
2841
  explain,
2647
- action: zone === "cols" ? (
2648
- // the text goes when the zone is too narrow (styles.css): the title keeps it as a tooltip
2649
- /* @__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))
2650
- ) : null
2842
+ add: addMenu ? { ...addMenu, onAdded: addMenu.onAdded(zone) } : null
2651
2843
  },
2652
- entries[zone].map((e) => /* @__PURE__ */ React11.createElement(
2844
+ entries[zone].map((e) => /* @__PURE__ */ React12.createElement(
2653
2845
  Chip,
2654
2846
  {
2655
2847
  key: e.id,
@@ -2659,6 +2851,7 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2659
2851
  count: entries[zone].length,
2660
2852
  field: e.field,
2661
2853
  text: e.text,
2854
+ title: e.field ? titleOf?.(e.field) : void 0,
2662
2855
  typeName: e.type,
2663
2856
  view,
2664
2857
  types,
@@ -2676,7 +2869,7 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2676
2869
  }
2677
2870
  ))
2678
2871
  ))
2679
- );
2872
+ ) : null);
2680
2873
  }
2681
2874
 
2682
2875
  // src/PivotReport.jsx
@@ -2687,6 +2880,7 @@ function sizeOf(width) {
2687
2880
  var COMPACT_HEIGHT = 600;
2688
2881
  var COMPACT_HEIGHT_NARROW = 820;
2689
2882
  var compactAt = (size, height) => height < (size === "narrow" ? COMPACT_HEIGHT_NARROW : COMPACT_HEIGHT);
2883
+ var zonesStart = (zones) => zones === "folded" ? true : zones === "open" ? false : null;
2690
2884
  var layerOpen = (layer) => Boolean(layer && [...layer.children].some((c) => !c.classList.contains("pk-origin")));
2691
2885
  function measured(name, fn) {
2692
2886
  const t0 = typeof performance !== "undefined" ? performance.now() : 0;
@@ -2764,19 +2958,19 @@ function PivotReport(props) {
2764
2958
  setStarted(true);
2765
2959
  }
2766
2960
  if (waiting && !started) {
2767
- return /* @__PURE__ */ React12.createElement(WaitingReport, { ...props });
2961
+ return /* @__PURE__ */ React13.createElement(WaitingReport, { ...props });
2768
2962
  }
2769
- return /* @__PURE__ */ React12.createElement(Report, { ...props });
2963
+ return /* @__PURE__ */ React13.createElement(Report, { ...props });
2770
2964
  }
2771
2965
  function WaitingReport({ locale = "en-US", labels: customLabels, theme = "auto", height = 640, className, label }) {
2772
- const root = useRef11(
2966
+ const root = useRef12(
2773
2967
  /** @type {HTMLDivElement | null} */
2774
2968
  null
2775
2969
  );
2776
2970
  const labelsKey = JSON.stringify(customLabels ?? null);
2777
2971
  const labels = useMemo8(() => resolveLabels(locale, JSON.parse(labelsKey)), [locale, labelsKey]);
2778
2972
  const themeName = useResolvedTheme(theme, root);
2779
- 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 }));
2973
+ 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 }));
2780
2974
  }
2781
2975
  function keyOfHostView(view) {
2782
2976
  try {
@@ -2787,7 +2981,7 @@ function keyOfHostView(view) {
2787
2981
  }
2788
2982
  var staysTheSame = () => () => void 0;
2789
2983
  function EmptyState({ labels, templates, onTemplate, onLoad, noData }) {
2790
- 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);
2984
+ 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);
2791
2985
  }
2792
2986
  function Report(props) {
2793
2987
  const {
@@ -2818,12 +3012,14 @@ function Report(props) {
2818
3012
  fieldDefaults,
2819
3013
  onExport,
2820
3014
  exportData = false,
3015
+ drillDownExport = false,
2821
3016
  label,
2822
3017
  tips: tipsProp = "on",
2823
3018
  storageKey,
2824
3019
  dismissedTips,
2825
3020
  onTipDismiss,
2826
3021
  chartOptions,
3022
+ colorMap,
2827
3023
  shareLink,
2828
3024
  persistView,
2829
3025
  fieldInfo: fieldInfoProp,
@@ -2835,6 +3031,7 @@ function Report(props) {
2835
3031
  schemaUrl,
2836
3032
  grow: growProp,
2837
3033
  fieldList,
3034
+ zones: zonesProp,
2838
3035
  loading: loading2 = false,
2839
3036
  allowImport = false,
2840
3037
  plugins: pluginsProp,
@@ -2848,14 +3045,14 @@ function Report(props) {
2848
3045
  /** @type {import("./import-host.jsx").ImportJob | null} */
2849
3046
  null
2850
3047
  );
2851
- const afterSheet = useRef11(
3048
+ const afterSheet = useRef12(
2852
3049
  /** @type {(() => void) | null} */
2853
3050
  null
2854
3051
  );
2855
3052
  const [dragging, setDragging] = useState12(false);
2856
- const dragDepth = useRef11(0);
3053
+ const dragDepth = useRef12(0);
2857
3054
  const [importMod, setImportMod] = useState12(importNow);
2858
- const fileInput = useRef11(
3055
+ const fileInput = useRef12(
2859
3056
  /** @type {HTMLInputElement | null} */
2860
3057
  null
2861
3058
  );
@@ -2869,7 +3066,7 @@ function Report(props) {
2869
3066
  const hostLimits = useMemo8(() => JSON.parse(limitsKey) ?? void 0, [limitsKey]);
2870
3067
  const importLimitsKey = JSON.stringify(importLimitsProp ?? null);
2871
3068
  const fileLimits = useMemo8(() => importLimitsOf(hostLimits, JSON.parse(importLimitsKey)), [hostLimits, importLimitsKey]);
2872
- const root = useRef11(
3069
+ const root = useRef12(
2873
3070
  /** @type {HTMLDivElement | null} */
2874
3071
  null
2875
3072
  );
@@ -2883,11 +3080,17 @@ function Report(props) {
2883
3080
  const [short, setShort] = useState12(false);
2884
3081
  const [folded, setFolded] = useState12(
2885
3082
  /** @type {boolean | null} */
2886
- null
3083
+ zonesStart(zonesProp)
2887
3084
  );
2888
- const layoutFolded = folded ?? short;
2889
- const zonesId = useId4();
2890
- const ownPrefix = useRef11(
3085
+ const foldOpenWhileEmpty = useRef12(false);
3086
+ const [zonesSeen, setZonesSeen] = useState12(zonesProp);
3087
+ if (zonesProp !== zonesSeen) {
3088
+ setZonesSeen(zonesProp);
3089
+ setFolded(zonesStart(zonesProp));
3090
+ }
3091
+ const zonesId = useId5();
3092
+ const resultId = useId5();
3093
+ const ownPrefix = useRef12(
2891
3094
  /** @type {string | null} */
2892
3095
  null
2893
3096
  );
@@ -2902,7 +3105,7 @@ function Report(props) {
2902
3105
  null
2903
3106
  );
2904
3107
  const [hinted, setHinted] = useState12(false);
2905
- const changesRef = useRef11(0);
3108
+ const changesRef = useRef12(0);
2906
3109
  const [changes, setChanges] = useState12(0);
2907
3110
  const [dragAt, setDragAt] = useState12(
2908
3111
  /** @type {number | null} */
@@ -2930,9 +3133,13 @@ function Report(props) {
2930
3133
  /** @type {string | null} */
2931
3134
  null
2932
3135
  );
2933
- const chartRef = useRef11(null);
3136
+ const chartRef = useRef12(null);
2934
3137
  const [chartReady, setChartReady] = useState12(false);
2935
- const hintId = useId4();
3138
+ const [lineChecks, setLineChecks] = useState12(
3139
+ /** @type {any} */
3140
+ null
3141
+ );
3142
+ const hintId = useId5();
2936
3143
  const closeFilter = useCallback10(() => setFilterTarget(null), []);
2937
3144
  const { toasts, push, dismiss, pause } = useToasts();
2938
3145
  const announce = useCallback10(
@@ -3010,8 +3217,8 @@ function Report(props) {
3010
3217
  const loadedView = tagFor(history.tag, sourceId);
3011
3218
  const viewName = loadedView?.name ?? null;
3012
3219
  const unsaved = Boolean(loadedView) && savedKeys[savedKeyOf(loadedView)] !== history.viewKey;
3013
- const chartOptionsKey = optionsKey(chartOptions);
3014
- const stableChartOptions = useMemo8(() => chartOptions, [chartOptionsKey]);
3220
+ const chartHostKey = optionsKey([chartOptions, colorMap]);
3221
+ const [stableChartOptions, stableColorMap] = useMemo8(() => [chartOptions, colorMap], [chartHostKey]);
3015
3222
  const stepText = useCallback10(
3016
3223
  (note) => {
3017
3224
  const template = Object.hasOwn(labels.steps, note.step) ? labels.steps[note.step] : labels.steps.change;
@@ -3025,7 +3232,7 @@ function Report(props) {
3025
3232
  },
3026
3233
  [labels]
3027
3234
  );
3028
- const apiNow = useRef11(
3235
+ const apiNow = useRef12(
3029
3236
  /** @type {any} */
3030
3237
  null
3031
3238
  );
@@ -3042,7 +3249,7 @@ function Report(props) {
3042
3249
  }
3043
3250
  };
3044
3251
  const newStep = useCallback10(() => setDataSteps((s) => s.future.length ? { past: s.past, future: [] } : s), []);
3045
- const undoLater = useRef11(undo2);
3252
+ const undoLater = useRef12(undo2);
3046
3253
  useEffect11(() => {
3047
3254
  undoLater.current = undo2;
3048
3255
  });
@@ -3052,11 +3259,11 @@ function Report(props) {
3052
3259
  announce(labels.toastReset, { action: { label: labels.undo, run: () => undoLater.current() } });
3053
3260
  }, [history, labels, announce, newStep]);
3054
3261
  const [opening, setOpening] = useState12(false);
3055
- const appliedLink = useRef11(
3262
+ const appliedLink = useRef12(
3056
3263
  /** @type {string | null} */
3057
3264
  null
3058
3265
  );
3059
- const latest = useRef11({ history, encoded, limits, labels, announce, commit: (
3266
+ const latest = useRef12({ history, encoded, limits, labels, announce, commit: (
3060
3267
  /** @type {any} */
3061
3268
  null
3062
3269
  ), sourceId, loaded: (
@@ -3161,23 +3368,26 @@ function Report(props) {
3161
3368
  }
3162
3369
  }, [persistView, storageKey, history.viewKey]);
3163
3370
  const commit = useCallback10(
3164
- /** @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) */
3371
+ /** @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 */
3165
3372
  (next, note = { step: "change" }, tag = void 0) => {
3166
3373
  const over = note.step === "template" ? null : zoneOverLimit(next, limits);
3167
3374
  if (over) {
3168
3375
  announce(fill(labels.zoneFull, { zone: labels.zones[over.zone], max: over.max.toLocaleString(locale) }), { tone: "error" });
3169
- return;
3376
+ return false;
3170
3377
  }
3171
3378
  const changed = history.commit(next, stepText(note), tag);
3379
+ if (changed && note.step === "added" && foldOpenWhileEmpty.current) {
3380
+ setFolded(false);
3381
+ }
3172
3382
  if (changed) {
3173
3383
  changesRef.current += 1;
3174
3384
  setChanges(changesRef.current);
3175
3385
  newStep();
3176
3386
  }
3177
- if (!changed || !note.removed) {
3178
- return;
3387
+ if (changed && note.removed) {
3388
+ announce(fill(labels.toastRemoved, { field: note.field ?? "" }).trim(), { action: { label: labels.undo, run: () => undoLater.current() } });
3179
3389
  }
3180
- announce(fill(labels.toastRemoved, { field: note.field ?? "" }).trim(), { action: { label: labels.undo, run: () => undoLater.current() } });
3390
+ return changed;
3181
3391
  },
3182
3392
  [history, stepText, labels, announce, limits, locale, newStep]
3183
3393
  );
@@ -3217,7 +3427,8 @@ function Report(props) {
3217
3427
  return { result: null, error: error2 };
3218
3428
  }
3219
3429
  }, [encoded, view, locale, limits]);
3220
- const result = computed.result;
3430
+ const context = useMemo8(() => dateContext(computed.result, labels), [computed.result, labels]);
3431
+ const result = context.result;
3221
3432
  const unusedLocale = useMemo8(() => {
3222
3433
  const requested = view.formatting?.locale || locale;
3223
3434
  try {
@@ -3238,19 +3449,26 @@ function Report(props) {
3238
3449
  return { result: null, error: error2 };
3239
3450
  }
3240
3451
  }, [plan.swap, view, encoded, locale, limits, computed, result]);
3241
- const chartResult = chartComputed.result;
3452
+ const titleOf = useCallback10((field) => context.titles.get(field), [context]);
3453
+ const chartContext = useMemo8(() => chartComputed.result === computed.result ? context : dateContext(chartComputed.result, labels), [chartComputed.result, computed.result, context, labels]);
3454
+ const chartResult = chartContext.result;
3242
3455
  const empty = isEmptyView(view);
3456
+ const layoutFolded = folded ?? (short && !empty);
3457
+ useEffect11(() => {
3458
+ foldOpenWhileEmpty.current = empty && short && folded === null;
3459
+ });
3243
3460
  const gridState = useMemo8(() => {
3244
3461
  if (!result || view.display !== "table" || empty) {
3245
3462
  return { grid: null, error: null };
3246
3463
  }
3247
3464
  try {
3248
- return { grid: measured("toGrid", () => toGrid(result, { locale, labels: labels.core, limits })), error: null };
3465
+ return { grid: measured("toGrid", () => toGrid(result, { locale, labels: context.labels.core, limits })), error: null };
3249
3466
  } catch (error2) {
3250
3467
  return { grid: null, error: error2 };
3251
3468
  }
3252
- }, [result, view.display, empty, locale, labels, limits]);
3469
+ }, [result, view.display, empty, locale, context.labels, limits]);
3253
3470
  const error = source.error ?? computed.error ?? gridState.error ?? (view.display === "chart" ? chartComputed.error : null);
3471
+ const dateLocale = useMemo8(() => dateDisplayLocale(view.formatting?.locale || locale), [view.formatting?.locale, locale]);
3254
3472
  const fields = encoded.schema.fields;
3255
3473
  const types = useMemo8(() => new Map(viewFields(view, encoded).map((f) => [f.name.toLowerCase(), f.type])), [view, encoded]);
3256
3474
  const typeOf = useCallback10((field) => types.get(sourceOf(view, field ?? "").toLowerCase()) ?? "string", [types, view]);
@@ -3259,14 +3477,24 @@ function Report(props) {
3259
3477
  const sortFromHeader = useCallback10((field, sort) => commit(setSort(view, field, sort), { step: "sort", field: nameOf(field) }), [view, commit, nameOf]);
3260
3478
  const infoOf = useCallback10(
3261
3479
  (field) => {
3262
- if (!field || info.size === 0) {
3480
+ if (!field) {
3263
3481
  return void 0;
3264
3482
  }
3265
3483
  const entry = info.get(sourceOf(view, field).toLowerCase());
3266
- return entry && entry.description ? entry : void 0;
3484
+ const range = dateRangeText(dateSpan(encoded, sourceOf(view, field)), dateLocale);
3485
+ const description = [entry?.description, range && fill(labels.dateRangeData, { range })].filter(Boolean).join(" \xB7 ");
3486
+ return description ? { ...entry, description } : void 0;
3267
3487
  },
3268
- [info, view]
3488
+ [info, view, encoded, dateLocale, labels]
3269
3489
  );
3490
+ const fieldInfo = useMemo8(() => {
3491
+ const entries2 = new Map(info);
3492
+ for (const field of encoded.schema.fields) {
3493
+ const entry = infoOf(field.name);
3494
+ if (entry) entries2.set(field.name.toLowerCase(), entry);
3495
+ }
3496
+ return entries2;
3497
+ }, [info, infoOf, encoded]);
3270
3498
  const placed = useMemo8(() => {
3271
3499
  const map = /* @__PURE__ */ new Map();
3272
3500
  const mark = (name, zone) => {
@@ -3298,11 +3526,13 @@ function Report(props) {
3298
3526
  live = false;
3299
3527
  };
3300
3528
  }, [lang]);
3301
- const mainRef = useRef11(
3529
+ const mainRef = useRef12(
3302
3530
  /** @type {HTMLDivElement | null} */
3303
3531
  null
3304
3532
  );
3305
- const fit = useFitHeight(root, mainRef, grow);
3533
+ const checkLow = useRef12(() => {
3534
+ });
3535
+ const fit = useFitHeight(root, mainRef, grow, () => checkLow.current());
3306
3536
  const big = useBigResult(root);
3307
3537
  useIsoLayoutEffect(() => {
3308
3538
  const el = root.current;
@@ -3314,17 +3544,78 @@ function Report(props) {
3314
3544
  const first = compactAt(sizeOf(box.width), box.height);
3315
3545
  setMeasuredShort(first);
3316
3546
  setShort(first);
3547
+ const low = (width, height2) => compactAt(width, height2) || fit.current.open > 0 && height2 <= fit.current.open + 1;
3548
+ let waiting = false;
3549
+ let lastInArea = false;
3550
+ const inArea = (t) => t instanceof Node && Boolean(el.querySelector(".pk-zone-section")?.contains(t) || el.querySelector(".pk-layer")?.contains(t));
3551
+ const note = (e) => {
3552
+ lastInArea = inArea(e.composedPath()[0] ?? e.target);
3553
+ };
3554
+ el.addEventListener("pointerdown", note, true);
3555
+ el.addEventListener("focusin", note, true);
3556
+ const busy = () => {
3557
+ const section = el.querySelector(".pk-zone-section");
3558
+ if (!section) {
3559
+ return false;
3560
+ }
3561
+ const active = (
3562
+ /** @type {Document | ShadowRoot} */
3563
+ el.getRootNode().activeElement
3564
+ );
3565
+ const focusGone = !active || active === el.ownerDocument.body;
3566
+ return Boolean(layerOpen(el.querySelector(".pk-layer")) || section.matches(":hover") || section.matches(":focus-within") || section.querySelector(".pk-dropping") || lastInArea && focusGone);
3567
+ };
3568
+ const doc = el.ownerDocument;
3569
+ let again = 0;
3570
+ const retry = () => {
3571
+ clearTimeout(again);
3572
+ again = window.setTimeout(() => waiting && checkLow.current(), 0);
3573
+ };
3574
+ const watch = (on) => {
3575
+ const how = on ? "addEventListener" : "removeEventListener";
3576
+ el[how]("pointerout", retry);
3577
+ el[how]("focusout", retry);
3578
+ doc[how]("pointerup", retry);
3579
+ };
3580
+ checkLow.current = () => {
3581
+ if (busy()) {
3582
+ if (!waiting) {
3583
+ waiting = true;
3584
+ watch(true);
3585
+ }
3586
+ return;
3587
+ }
3588
+ if (waiting) {
3589
+ waiting = false;
3590
+ watch(false);
3591
+ }
3592
+ const now = el.getBoundingClientRect();
3593
+ setMeasuredShort(low(sizeOf(now.width), now.height));
3594
+ };
3595
+ const release = () => {
3596
+ el.removeEventListener("pointerdown", note, true);
3597
+ el.removeEventListener("focusin", note, true);
3598
+ clearTimeout(again);
3599
+ if (waiting) {
3600
+ waiting = false;
3601
+ watch(false);
3602
+ }
3603
+ };
3317
3604
  if (typeof ResizeObserver !== "function") {
3318
- return void 0;
3605
+ return release;
3319
3606
  }
3320
3607
  const ro = new ResizeObserver(([entry]) => {
3321
3608
  const width = sizeOf(entry.contentRect.width);
3322
3609
  setSize(width);
3323
- const height2 = entry.borderBoxSize?.[0]?.blockSize ?? el.getBoundingClientRect().height;
3324
- setMeasuredShort(compactAt(width, height2) || fit.current.open > 0 && height2 <= fit.current.open + 1);
3610
+ setMeasuredShort(low(width, entry.borderBoxSize?.[0]?.blockSize ?? el.getBoundingClientRect().height));
3325
3611
  });
3326
3612
  ro.observe(el);
3327
- return () => ro.disconnect();
3613
+ return () => {
3614
+ checkLow.current = () => {
3615
+ };
3616
+ release();
3617
+ ro.disconnect();
3618
+ };
3328
3619
  }, []);
3329
3620
  useEffect11(() => {
3330
3621
  if (measuredShort === short) {
@@ -3344,7 +3635,7 @@ function Report(props) {
3344
3635
  return () => mo.disconnect();
3345
3636
  }, [measuredShort, short, layer]);
3346
3637
  const drawerOpen = drawer && size === "narrow";
3347
- const panelRef = useRef11(
3638
+ const panelRef = useRef12(
3348
3639
  /** @type {HTMLDivElement | null} */
3349
3640
  null
3350
3641
  );
@@ -3365,15 +3656,22 @@ function Report(props) {
3365
3656
  const addTo = useCallback10(
3366
3657
  (field, zone, index = void 0) => {
3367
3658
  const options = placeOptions(field, zone, index);
3368
- commit(addField(view, field, zone, options), { step: "added", field: options.groupName ?? nameOf(field), zone });
3659
+ return commit(addField(view, field, zone, options), { step: "added", field: options.groupName ?? nameOf(field), zone });
3369
3660
  },
3370
3661
  [view, placeOptions, commit, nameOf]
3371
3662
  );
3372
- const filterField = useCallback10(
3373
- (field, anchor) => {
3663
+ const placeName = useCallback10((field, zone) => placeOptions(field, zone).groupName ?? field, [placeOptions]);
3664
+ const filterDraft = useCallback10(
3665
+ (field) => {
3374
3666
  const options = placeOptions(field, "filters");
3375
3667
  const name = options.groupName ?? field;
3376
- const draft = filterZoneFields(view).some((f) => same(f, name)) ? void 0 : addField(view, field, "filters", options);
3668
+ return { field: name, base: filterZoneFields(view).some((f) => same(f, name)) ? void 0 : addField(view, field, "filters", options) };
3669
+ },
3670
+ [placeOptions, view]
3671
+ );
3672
+ const filterField = useCallback10(
3673
+ (field, anchor) => {
3674
+ const draft = filterDraft(field);
3377
3675
  const opener = size === "narrow" ? (
3378
3676
  /** @type {HTMLElement | null} */
3379
3677
  root.current?.querySelector("[data-pk-opener='fields']") ?? null
@@ -3383,11 +3681,19 @@ function Report(props) {
3383
3681
  }
3384
3682
  const target = opener ?? anchor;
3385
3683
  if (target) {
3386
- setFilterTarget({ field: name, anchor: target, base: draft });
3684
+ setFilterTarget({ field: draft.field, anchor: target, base: draft.base });
3387
3685
  }
3388
3686
  },
3389
- [placeOptions, view, size]
3687
+ [filterDraft, size]
3688
+ );
3689
+ const zoneFullText = useCallback10(
3690
+ (zone, count) => {
3691
+ const max = zoneMax(zone, limits);
3692
+ return max !== null && count >= max ? fill(labels.zoneFull, { zone: labels.zones[zone], max: max.toLocaleString(locale) }) : null;
3693
+ },
3694
+ [limits, labels, locale]
3390
3695
  );
3696
+ const adding = useMemo8(() => ({ fields, placed, nameOf, info, placeName, onAdd: addTo, filterDraft, fullText: zoneFullText }), [fields, placed, nameOf, info, placeName, addTo, filterDraft, zoneFullText]);
3391
3697
  const onDrop = useCallback10(
3392
3698
  (src, target) => {
3393
3699
  setDragAt((at) => at ?? changesRef.current + 1);
@@ -3429,7 +3735,7 @@ function Report(props) {
3429
3735
  },
3430
3736
  [result, encodedProp, imported, data, drillDownLimit, onCellClick, drillDown, defaultsOf, nameOf, infoOf]
3431
3737
  );
3432
- const { run: doExport, prepare: prepareExport } = useExport({ fileName, result, encoded, exportData, locale, labels, limits, root, chartRef, announce, onExport, title: viewName, source: sourceName, loadECharts });
3738
+ 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 });
3433
3739
  const requestImport = () => loadImport().then((m) => (flushSync(() => setImportMod(() => m)), m));
3434
3740
  const api = {
3435
3741
  imported,
@@ -3463,7 +3769,7 @@ function Report(props) {
3463
3769
  useEffect11(() => {
3464
3770
  apiNow.current = api;
3465
3771
  });
3466
- const restored = useRef11(false);
3772
+ const restored = useRef12(false);
3467
3773
  useIsoLayoutEffect(() => {
3468
3774
  if (kept2 && !restored.current) {
3469
3775
  restored.current = true;
@@ -3472,8 +3778,8 @@ function Report(props) {
3472
3778
  }
3473
3779
  }, []);
3474
3780
  const snapshot = history.snapshot;
3475
- const keptKey = useRef11(keepKey);
3476
- const fileShown = useRef11(false);
3781
+ const keptKey = useRef12(keepKey);
3782
+ const fileShown = useRef12(false);
3477
3783
  const hostHasColumns = source.encoded.schema.fields.length > 0;
3478
3784
  useIsoLayoutEffect(() => {
3479
3785
  if (keepKey !== null && !kept2 && hostHasColumns) {
@@ -3554,7 +3860,7 @@ function Report(props) {
3554
3860
  loadTemplate(how === "missing" ? { ...t, sheet: SHEET_GONE } : t);
3555
3861
  }
3556
3862
  };
3557
- const loadLater = useRef11(
3863
+ const loadLater = useRef12(
3558
3864
  /** @type {((what: { template?: any, file?: object }) => void) | null} */
3559
3865
  null
3560
3866
  );
@@ -3656,10 +3962,10 @@ function Report(props) {
3656
3962
  }
3657
3963
  };
3658
3964
  const layerValue = useMemo8(() => ({ layer, size }), [layer, size]);
3659
- 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: (
3965
+ 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: (
3660
3966
  /** @type {any} */
3661
3967
  TYPE_ICON[src.type ?? typeOf(src.field)] ?? "text"
3662
- ), size: 13 })), /* @__PURE__ */ React12.createElement("span", { className: "pk-chip-text" }, src.label ?? src.field));
3968
+ ), size: 13 })), /* @__PURE__ */ React13.createElement("span", { className: "pk-chip-text" }, src.label ?? src.field));
3663
3969
  const showTable = !error && !(empty && view.display === "table") && view.display !== "chart" && gridState.grid;
3664
3970
  const outer = useMemo8(() => result ? outerPaths(result) : [], [result]);
3665
3971
  const folding = rowFolding(view, outer);
@@ -3680,15 +3986,15 @@ function Report(props) {
3680
3986
  return null;
3681
3987
  }
3682
3988
  try {
3683
- return toSeries(chartResult, { labels: labels.core, maxCategories: MAX_CATEGORIES });
3989
+ return toSeries(chartResult, { labels: chartContext.labels.core, maxCategories: MAX_CATEGORIES });
3684
3990
  } catch {
3685
3991
  return null;
3686
3992
  }
3687
- }, [chartResult, view.display, view.values.length, labels]);
3993
+ }, [chartResult, view.display, view.values.length, chartContext.labels]);
3688
3994
  const allowedKey = JSON.stringify(allowedTips(tipsProp));
3689
3995
  const allowed = useMemo8(() => JSON.parse(allowedKey), [allowedKey]);
3690
3996
  const dismissedKey = JSON.stringify(cleanDismissed(dismissedTips));
3691
- const [own2, setOwn] = useState12(() => cleanDismissed(JSON.parse(dismissedKey)));
3997
+ const [own, setOwn] = useState12(() => cleanDismissed(JSON.parse(dismissedKey)));
3692
3998
  const [lastDismissedKey, setLastDismissedKey] = useState12(dismissedKey);
3693
3999
  if (dismissedKey !== lastDismissedKey) {
3694
4000
  setLastDismissedKey(dismissedKey);
@@ -3696,7 +4002,7 @@ function Report(props) {
3696
4002
  }
3697
4003
  const subscribe = useCallback10((callback) => subscribeStored(storageKey, callback), [storageKey]);
3698
4004
  const storedRaw = useSyncExternalStore3(subscribe, () => readStored(storageKey, localStore()), () => null);
3699
- const dismissed = useMemo8(() => cleanDismissed([...own2, ...parseStored(storedRaw)]), [own2, storedRaw]);
4005
+ const dismissed = useMemo8(() => cleanDismissed([...own, ...parseStored(storedRaw)]), [own, storedRaw]);
3700
4006
  const changeDismissed = useCallback10(
3701
4007
  (next, id) => {
3702
4008
  setOwn(next);
@@ -3706,7 +4012,7 @@ function Report(props) {
3706
4012
  [storageKey, onTipDismiss]
3707
4013
  );
3708
4014
  const tipsOn = allowed !== "off" && !dismissed.includes(ALL_TIPS);
3709
- const describedFields = [...info.values()].some((i) => i.description);
4015
+ const describedFields = [...fieldInfo.values()].some((i) => i.description);
3710
4016
  const fieldSwitch = helpSwitch(fieldInfoProp, dismissed);
3711
4017
  const zoneSwitch = helpSwitch(zoneInfoProp, dismissed);
3712
4018
  const settingSwitch = helpSwitch(settingInfoProp, dismissed);
@@ -3737,6 +4043,16 @@ function Report(props) {
3737
4043
  warnOnce(`pivotkit: fieldList ${JSON.stringify(String(fieldList)).slice(0, 40)} is neither "open" nor "collapsed"; the user's choice decides`);
3738
4044
  }
3739
4045
  }, [fieldList]);
4046
+ useEffect11(() => {
4047
+ for (const [key, now] of removedLabels(JSON.parse(labelsKey))) {
4048
+ warnOnce(`pivotkit: labels.${key} is no longer shown and is ignored; set labels.${now} instead`);
4049
+ }
4050
+ }, [labelsKey]);
4051
+ useEffect11(() => {
4052
+ if (zonesProp !== void 0 && zonesStart(zonesProp) === null) {
4053
+ warnOnce(`pivotkit: zones ${JSON.stringify(String(zonesProp)).slice(0, 40)} is neither "open" nor "folded"; the report's height decides`);
4054
+ }
4055
+ }, [zonesProp]);
3740
4056
  const railed = size !== "narrow" && fieldsCollapsed(fieldsSession, fieldList, dismissed);
3741
4057
  const collapseFields = (next) => {
3742
4058
  if (fieldList === "open" || fieldList === "collapsed") {
@@ -3788,9 +4104,9 @@ function Report(props) {
3788
4104
  () => 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]) : []]),
3789
4105
  [fromHost, given, loads, result, empty]
3790
4106
  );
3791
- const summaryParts = big.enlarged ? layoutSummary(zoneEntries(view, types, labels), labels) : [];
4107
+ const summaryParts = big.enlarged ? layoutSummary(zoneEntries(view, types, context.labels), context.labels) : [];
3792
4108
  const summaryText = summaryParts.length ? summaryParts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
3793
- return /* @__PURE__ */ React12.createElement(
4109
+ return /* @__PURE__ */ React13.createElement(
3794
4110
  "div",
3795
4111
  {
3796
4112
  ref: root,
@@ -3812,7 +4128,7 @@ function Report(props) {
3812
4128
  onDragLeave: allowImport ? fileDrag : void 0,
3813
4129
  onDrop: allowImport ? fileDrag : void 0
3814
4130
  },
3815
- /* @__PURE__ */ React12.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React12.createElement(FormNameContext.Provider, { value: formPrefix }, /* @__PURE__ */ React12.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React12.createElement(
4131
+ /* @__PURE__ */ React13.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React13.createElement(FormNameContext.Provider, { value: formPrefix }, /* @__PURE__ */ React13.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React13.createElement(
3816
4132
  PivotDnd,
3817
4133
  {
3818
4134
  labels,
@@ -3824,7 +4140,7 @@ function Report(props) {
3824
4140
  }
3825
4141
  }
3826
4142
  },
3827
- /* @__PURE__ */ React12.createElement("div", { className: `pk-layout${drawerOpen ? " pk-drawer-open" : ""}` }, /* @__PURE__ */ React12.createElement("div", { className: "pk-panel-slot", ref: panelRef }, /* @__PURE__ */ React12.createElement(
4143
+ /* @__PURE__ */ React13.createElement("div", { className: `pk-layout${drawerOpen ? " pk-drawer-open" : ""}` }, /* @__PURE__ */ React13.createElement("div", { className: "pk-panel-slot", ref: panelRef }, /* @__PURE__ */ React13.createElement(
3828
4144
  FieldPanel,
3829
4145
  {
3830
4146
  fields,
@@ -3839,7 +4155,7 @@ function Report(props) {
3839
4155
  onNote: (text) => announce(text),
3840
4156
  onFilter: filterField,
3841
4157
  nameOf,
3842
- info,
4158
+ info: fieldInfo,
3843
4159
  showInfo: fieldSwitch.on,
3844
4160
  drawer: size === "narrow",
3845
4161
  open: drawerOpen,
@@ -3851,11 +4167,10 @@ function Report(props) {
3851
4167
  root.current?.querySelector(".pk-toolbar button:not([disabled])")?.focus()
3852
4168
  )
3853
4169
  }
3854
- )), 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(
4170
+ )), 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(
3855
4171
  Toolbar,
3856
4172
  {
3857
4173
  view,
3858
- chartPlan: plan,
3859
4174
  labels,
3860
4175
  size,
3861
4176
  canUndo: history.canUndo || dataSteps.past.length > 0,
@@ -3868,13 +4183,6 @@ function Report(props) {
3868
4183
  onReset: reset2,
3869
4184
  onNew: newReport,
3870
4185
  loadedView: loadedView ? { name: loadedView.name, changed: unsaved } : null,
3871
- onDisplay: (d) => commit(setDisplay(view, d), { step: "display", display: d }),
3872
- onChart: (p) => commit(setChart(view, p), { step: "chart", type: p }),
3873
- onChartDisplay: (patch) => commit(setChartDisplay(view, patch), { step: "chartDisplay" }),
3874
- onTotal: (key, on) => commit(setTotal(view, key, on), { step: "totals" }),
3875
- onExpand: expandAll,
3876
- onCollapse: collapseAll,
3877
- folding,
3878
4186
  share,
3879
4187
  templates: entries,
3880
4188
  onLoadTemplate: openTemplate,
@@ -3885,9 +4193,6 @@ function Report(props) {
3885
4193
  chartReady: view.display === "chart" && chartReady,
3886
4194
  empty,
3887
4195
  onShowFields: () => setDrawer(true),
3888
- layoutFolded,
3889
- onLayout: () => setFolded(!layoutFolded),
3890
- zonesId,
3891
4196
  tipsControls: allowed !== "off",
3892
4197
  tipsOn,
3893
4198
  onTipsOn: (on) => changeDismissed(on ? dismissed.filter((id) => id !== ALL_TIPS) : [...dismissed, ALL_TIPS], on ? null : ALL_TIPS),
@@ -3897,9 +4202,9 @@ function Report(props) {
3897
4202
  explanations: explainUser ? { on: !dismissed.includes(NO_EXPLANATIONS), set: (on) => toggle(NO_EXPLANATIONS, on) } : null
3898
4203
  },
3899
4204
  viewsRequest,
3900
- data: allowImport ? { loaded: Boolean(imported), panel: (close) => /* @__PURE__ */ React12.createElement(MenuPanel, { name: "DataMenu", loadingText: labels.loadingMenu, props: { api, close, labels } }) } : null
4205
+ data: allowImport ? { loaded: Boolean(imported), panel: (close) => /* @__PURE__ */ React13.createElement(MenuPanel, { name: "DataMenu", loadingText: labels.loadingMenu, props: { api, close, labels } }) } : null
3901
4206
  }
3902
- ), /* @__PURE__ */ React12.createElement(
4207
+ ), /* @__PURE__ */ React13.createElement(
3903
4208
  Zones,
3904
4209
  {
3905
4210
  view,
@@ -3907,18 +4212,20 @@ function Report(props) {
3907
4212
  labels,
3908
4213
  commit,
3909
4214
  encoded,
3910
- locale,
4215
+ locale: dateLocale,
3911
4216
  onSwap: () => commit(swapAxes(view), { step: "swap" }),
3912
4217
  id: zonesId,
3913
4218
  folded: layoutFolded,
3914
- onShow: () => setFolded(false),
4219
+ onFold: () => setFolded(!layoutFolded),
3915
4220
  defaultsOf,
3916
4221
  infoOf,
4222
+ titleOf,
3917
4223
  earlier: history.earlier,
3918
4224
  explain: zoneSwitch.on,
3919
- showInfo: fieldSwitch.on
4225
+ showInfo: fieldSwitch.on,
4226
+ adding
3920
4227
  }
3921
- ), 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(
4228
+ ), 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(
3922
4229
  Unused,
3923
4230
  {
3924
4231
  notes,
@@ -3936,7 +4243,7 @@ function Report(props) {
3936
4243
  narrow: size === "narrow",
3937
4244
  quiet: unusedSaid && !fromHost
3938
4245
  }
3939
- ), /* @__PURE__ */ React12.createElement(
4246
+ ), /* @__PURE__ */ React13.createElement(
3940
4247
  Tips,
3941
4248
  {
3942
4249
  tips: shownTips,
@@ -3945,27 +4252,55 @@ function Report(props) {
3945
4252
  onAction: runTip,
3946
4253
  focusFallback: () => root.current?.focus({ preventScroll: true })
3947
4254
  }
3948
- ), 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(
4255
+ ), 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(
4256
+ ViewTabs,
4257
+ {
4258
+ view,
4259
+ labels,
4260
+ panelId: resultId,
4261
+ narrow: size === "narrow",
4262
+ big,
4263
+ plan,
4264
+ encoded,
4265
+ lineChecks: lineChecks?.view === view ? lineChecks.checks : null,
4266
+ locale,
4267
+ chartSeries: series,
4268
+ chartColors: { chart: chartRef },
4269
+ onDisplay: (d) => commit(setDisplay(view, d), { step: "display", display: d }),
4270
+ onChart: (p) => commit(setChart(view, p), { step: "chart", type: p }),
4271
+ onChartDisplay: (patch) => commit(setChartDisplay(view, patch), { step: "chartDisplay" }),
4272
+ onTotal: (key, on) => commit(setTotal(view, key, on), { step: "totals" }),
4273
+ onExpand: expandAll,
4274
+ onCollapse: collapseAll,
4275
+ folding
4276
+ }
4277
+ ), /* @__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(
3949
4278
  PivotChart,
3950
4279
  {
3951
4280
  result: chartResult,
3952
4281
  plan,
3953
4282
  series,
3954
- labels,
4283
+ labels: context.labels,
3955
4284
  locale,
3956
4285
  themeName,
3957
4286
  root,
3958
- valueNames: view.values.map((v) => valueLabel(v, labels)),
4287
+ valueNames: valueLabels(view.values, labels),
3959
4288
  chartOptions: stableChartOptions,
4289
+ colorMap: stableColorMap,
4290
+ onLegend: ({ name, shown }) => {
4291
+ commit(setChartDisplay(view, { hidden: hiddenAfter(view.chart.hidden, name, shown) }), { step: "chartDisplay" });
4292
+ announce(fill(shown ? labels.chartShown : labels.chartHidden, { name }));
4293
+ },
3960
4294
  onInstance: (c) => {
3961
4295
  chartRef.current = c;
3962
4296
  setChartReady(Boolean(c));
3963
4297
  },
4298
+ onLines: (checks) => setLineChecks(checks && { checks, view }),
3964
4299
  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 ?? "") })
3965
4300
  }
3966
- ) : 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),
3967
- filterTarget ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "FilterPopover", props: { target: filterTarget, onClose: closeFilter, view, encoded, locale, labels, commit } }) : null
3968
- ), 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" })))))
4301
+ ) : 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),
4302
+ filterTarget ? /* @__PURE__ */ React13.createElement(MenuPanel, { name: "FilterPopover", props: { target: filterTarget, onClose: closeFilter, view, encoded, locale, labels, commit } }) : null
4303
+ ), 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" })))))
3969
4304
  );
3970
4305
  }
3971
4306
  export {