pivotkit-react 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +219 -1
  2. package/README.md +2 -2
  3. package/dist/chunks/{chunk-YITKWZ4L.js → chunk-2AT72SLA.js} +604 -505
  4. package/dist/chunks/{chunk-ZYEYZSYL.js → chunk-3E4NB5RZ.js} +30 -2
  5. package/dist/chunks/{chunk-6MDAL3IO.js → chunk-3WUGQPWV.js} +78 -6
  6. package/dist/chunks/{chunk-WB4GKWFQ.js → chunk-4RS72AAA.js} +26 -4
  7. package/dist/chunks/{chunk-EM23V5GH.js → chunk-E6M57YLL.js} +19 -8
  8. package/dist/chunks/{chunk-RWYHJRQO.js → chunk-JMRTIOX4.js} +17 -7
  9. package/dist/chunks/{chunk-XN55BQ4M.js → chunk-RIOSIYGC.js} +54 -7
  10. package/dist/chunks/{chunk-LEN5RPBM.js → chunk-U5Q5I2D5.js} +34 -5
  11. package/dist/chunks/report-run-BZBFOMPF.js +12 -0
  12. package/dist/chunks/{unused-texts-K3VFH65P.js → unused-texts-Y4R67XSN.js} +1 -1
  13. package/dist/chunks/{unused-texts-de-OW4TGIVX.js → unused-texts-de-6YVPTNVS.js} +1 -1
  14. package/dist/echarts.js +38 -156
  15. package/dist/import-ui.js +8 -12
  16. package/dist/index.js +97 -82
  17. package/dist/labels.js +6 -6
  18. package/dist/menu-texts-de.js +1 -1
  19. package/dist/menus.js +650 -245
  20. package/dist/styles.css +207 -93
  21. package/package.json +8 -4
  22. package/types/chart-decorate.d.ts +28 -4
  23. package/types/chart-types.d.ts +2 -4
  24. package/types/echarts.d.ts +1 -1
  25. package/types/export-run.d.ts +37 -3
  26. package/types/filter.d.ts +1 -1
  27. package/types/icons.d.ts +1 -0
  28. package/types/import-labels.d.ts +41 -0
  29. package/types/import-limits.d.ts +6 -0
  30. package/types/index.d.ts +25 -7
  31. package/types/labels.d.ts +198 -2
  32. package/types/light-tokens.d.ts +16 -0
  33. package/types/menu-labels.d.ts +37 -14
  34. package/types/menu-ops.d.ts +161 -40
  35. package/types/menu-topics.d.ts +7 -4
  36. package/types/names.d.ts +47 -19
  37. package/types/place.d.ts +24 -0
  38. package/types/print-frame.d.ts +24 -0
  39. package/types/report-run.d.ts +14 -0
  40. package/types/share-actions.d.ts +3 -3
  41. package/types/share.d.ts +13 -17
  42. package/types/theme.d.ts +2 -16
  43. package/types/tips.d.ts +5 -0
  44. package/types/toolbar-panels.d.ts +5 -4
  45. package/types/unused-texts.d.ts +13 -3
  46. package/types/use-export.d.ts +2 -2
  47. package/types/view-ops.d.ts +65 -6
  48. package/types/chart-layout.d.ts +0 -111
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  Icon,
3
3
  Popover,
4
+ onTheWay,
4
5
  useFormName
5
- } from "./chunk-XN55BQ4M.js";
6
+ } from "./chunk-RIOSIYGC.js";
6
7
  import {
7
8
  fill,
8
9
  plural
9
- } from "./chunk-6MDAL3IO.js";
10
+ } from "./chunk-3WUGQPWV.js";
10
11
 
11
12
  // src/chart-types.js
12
- import { autoChartType } from "pivotkit-core";
13
+ import { chartPlan as corePlan } from "pivotkit-core";
13
14
  var CHART_TYPES = Object.freeze({
14
15
  auto: { chart: { type: "auto", stacked: false, horizontal: false }, icon: "sparkle", axis: true },
15
16
  bar: { chart: { type: "bar", stacked: false, horizontal: false }, icon: "chart", axis: true },
@@ -37,411 +38,39 @@ function chartTypeOf(chart2) {
37
38
  return CHART_TYPE_NAMES.find((name2) => CHART_TYPES[name2].chart.type === chart2.type) ?? "bar";
38
39
  }
39
40
  function chartPlan(view, encoded) {
40
- if (view.chart.type !== "auto") {
41
- const name3 = chartTypeOf(view.chart);
42
- return { name: name3, auto: false, swap: false, chart: { type: view.chart.type, stacked: Boolean(view.chart.stacked), horizontal: Boolean(view.chart.horizontal) } };
43
- }
44
- const own = autoChartType(
45
- /** @type {any} */
46
- view,
47
- encoded
48
- );
49
- const swap = own === "bar" && view.cols.length > 0 && autoChartType(
50
- /** @type {any} */
51
- { ...view, rows: view.cols },
52
- encoded
53
- ) === "line";
54
- const name2 = own === "line" || swap ? "line" : "bar";
55
- return { name: name2, auto: true, swap, chart: { ...CHART_TYPES[name2].chart } };
56
- }
57
- var MANY_SERIES = 8;
58
- var MAX_CATEGORIES = 50;
59
-
60
- // src/names.js
61
- import { fieldLabel, relativeDateRange } from "pivotkit-core";
62
- function valueLabel(spec, labels) {
63
- if (spec.label) {
64
- return spec.label;
65
- }
66
- const core = labels.core;
67
- let base;
68
- if (!spec.field) {
69
- base = core.countRows;
70
- } else {
71
- const agg = Object.hasOwn(core.aggregators, spec.agg) ? core.aggregators[spec.agg] : spec.agg;
72
- base = fill(core.valueName, { agg, field: fieldLabel(spec.field, core) });
73
- }
74
- if (!spec.showAs || !core.showAs || !core.showAsName) {
75
- return base;
76
- }
77
- const showAs = Object.hasOwn(core.showAs, spec.showAs.type) ? core.showAs[spec.showAs.type] : spec.showAs.type;
78
- return fill(core.showAsName, { showAs, value: spec.field && spec.agg === "sum" ? fieldLabel(spec.field, core) : base });
79
- }
80
- function refLabel(view, ref, labels) {
81
- const field = ref?.field ?? null;
82
- const sameField = (v) => field === null || v.field === null || v.field === void 0 ? (v.field ?? null) === field : v.field.toLowerCase() === field.toLowerCase();
83
- const spec = ref ? (view.values ?? []).find((v) => v.agg === ref.agg && sameField(v)) : void 0;
84
- if (!spec && field === null) {
85
- return labels.countOfRows;
86
- }
87
- return valueLabel({ ...spec ?? ref, showAs: null }, labels);
88
- }
89
- function sortText(view, sort, labels) {
90
- const desc = sort.order === "desc";
91
- if (sort.by === "value") {
92
- return fill(desc ? labels.sortValueDesc : labels.sortValueAsc, { value: refLabel(view, sort.value, labels) });
93
- }
94
- if (sort.by === "custom") {
95
- return desc ? labels.sortCustomDesc : labels.sortCustom;
96
- }
97
- return desc ? labels.sortLabelDesc : labels.sortLabelAsc;
98
- }
99
- var OP_SIGNS = Object.freeze({ "=": "=", "!=": "\u2260", ">": ">", ">=": "\u2265", "<": "<", "<=": "\u2264" });
100
- function valueConditionText(view, f, labels, locale) {
101
- const number = (x) => typeof x === "number" ? x.toLocaleString(locale, { maximumFractionDigits: 6 }) : "";
102
- const value = refLabel(view, f.by ?? (view.values?.[0] ? { field: view.values[0].field ?? null, agg: view.values[0].agg } : null), labels);
103
- if (f.op === "between" || f.op === "notBetween") {
104
- const [from, to] = typeof f.value2 === "number" && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
105
- return fill(labels.valueConditions[f.op], { value, from: number(from), to: number(to) });
106
- }
107
- return fill(labels.valueConditions.compare, { value, op: Object.hasOwn(OP_SIGNS, f.op) ? OP_SIGNS[f.op] : f.op, number: number(f.value) });
108
- }
109
- var dayText = (iso, locale) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { dateStyle: "medium", timeZone: "UTC" });
110
- var isoDay = (ms) => new Date(ms).toISOString().slice(0, 10);
111
- var dayAfter = (iso, n = 1) => isoDay(Date.parse(`${iso}T00:00Z`) + n * 864e5);
112
- var relativeDays = (f, timeZone, now, latest) => relativeDateRange(f.unit, f.count, { timeZone, now, anchor: f.anchor, latest: latest ?? void 0 });
113
- function periodText(range, unit, locale) {
114
- const month = (iso) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { month: "short", year: "numeric", timeZone: "UTC" });
115
- const text = unit === "year" ? (iso) => iso.slice(0, 4) : unit === "month" ? month : (iso) => dayText(iso, locale);
116
- const [from, to] = [text(range.from), text(range.to)];
117
- return from === to ? from : `${from}\u2013${to}`;
118
- }
119
- function rangeShare(range, unit, span, locale) {
120
- const [first, last] = [periodStart(isoDay(span.min), unit), periodEnd(isoDay(span.max), unit)];
121
- if (first <= range.from && last >= range.to) {
122
- return null;
123
- }
124
- const from = range.from > first ? range.from : first;
125
- const to = range.to < last ? range.to : last;
126
- if (from > to) {
127
- return { none: true };
128
- }
129
- const missing = [];
130
- let count = 0;
131
- const part = (a, b, dataYear) => {
132
- const years = [];
133
- const [ya, yb] = [Number(a.slice(0, 4)), Number(b.slice(0, 4))];
134
- for (let y = ya; y <= yb; y++) {
135
- if (y !== dataYear) {
136
- years.push(y);
137
- }
138
- }
139
- if (years.length) {
140
- missing.push(years.length === 1 ? String(years[0]) : `${years[0]}\u2013${years[years.length - 1]}`);
141
- count += years.length;
142
- }
143
- if (ya <= dataYear && dataYear <= yb) {
144
- const yearFrom = `${String(dataYear).padStart(4, "0")}-01-01`;
145
- const yearTo = `${String(dataYear).padStart(4, "0")}-12-31`;
146
- const rest = { from: a > yearFrom ? a : yearFrom, to: b < yearTo ? b : yearTo };
147
- missing.push(periodText(rest, unit, locale));
148
- count += periodText({ from: rest.from, to: rest.from }, unit, locale) === periodText({ from: rest.to, to: rest.to }, unit, locale) ? 1 : 2;
149
- }
150
- };
151
- if (range.from < first) {
152
- part(range.from, dayAfter(first, -1), Number(first.slice(0, 4)));
153
- }
154
- if (range.to > last) {
155
- part(dayAfter(last), range.to, Number(last.slice(0, 4)));
156
- }
157
- return { none: false, data: periodText({ from, to }, unit, locale), missing, count };
158
- }
159
- var periodStart = (iso, unit) => unit === "year" ? `${iso.slice(0, 4)}-01-01` : unit === "month" ? `${iso.slice(0, 7)}-01` : iso;
160
- function periodEnd(iso, unit) {
161
- if (unit === "day") {
162
- return iso;
163
- }
164
- const [y, m] = [Number(iso.slice(0, 4)), Number(iso.slice(5, 7))];
165
- return isoDay(unit === "year" ? Date.UTC(y, 11, 31) : Date.UTC(y, m, 0));
166
- }
167
- function relativeText(f, labels, locale, timeZone, now, span) {
168
- const key = f.count === 1 ? f.unit : `${f.unit}s`;
169
- let text = fill(Object.hasOwn(labels.relative, key) ? labels.relative[key] : key, { count: f.count.toLocaleString(locale) });
170
- const range = relativeDays(f, timeZone, now, span?.max);
171
- if (!range) {
172
- return text;
173
- }
174
- const latest = f.anchor === "latest";
175
- if (latest) {
176
- text = fill(labels.relativeTo, { text, end: periodText({ from: range.to, to: range.to }, f.unit, locale) });
177
- }
178
- const share = span ? rangeShare(range, f.unit, span, locale) : null;
179
- if (!share) {
180
- return latest ? text : fill(labels.withRange, { text, range: periodText(range, f.unit, locale) });
181
- }
182
- const lang = { lang: labels.lang, locale };
183
- if (share.none) {
184
- return fill(labels.withRange, { text, range: fill(plural(labels.noData, 1, lang), { range: periodText(range, f.unit, locale) }) });
185
- }
186
- return fill(labels.withShare, { text, range: share.data, missing: fill(plural(labels.noData, share.count, lang), { range: share.missing.join(", ") }) });
187
- }
188
- function wholeYears(from, to) {
189
- const whole = typeof from === "string" && typeof to === "string" && /^\d{4}-01-01$/.test(from) && /^\d{4}-12-31$/.test(to);
190
- return whole ? [from.slice(0, 4), to.slice(0, 4)] : null;
191
- }
192
- function compareText(f, labels, locale, { date, labelOf }) {
193
- const shown = (v) => typeof v === "string" ? dayText(v, locale) : labelOf?.(v) ?? (date ? String(v) : v.toLocaleString(locale, { maximumFractionDigits: 6 }));
194
- const forms = labels.compareShort;
195
- if (f.op === "between" || f.op === "notBetween") {
196
- const [from, to] = f.value2 !== void 0 && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
197
- const years = wholeYears(from, to);
198
- if (years) {
199
- return years[0] === years[1] ? fill(forms[f.op === "between" ? "=" : "!="], { value: years[0] }) : fill(forms[f.op], { from: years[0], to: years[1] });
200
- }
201
- return fill(forms[f.op], { from: shown(from), to: shown(to) });
202
- }
203
- return date && Object.hasOwn(forms, f.op) ? fill(forms[f.op], { value: shown(f.value) }) : `${Object.hasOwn(OP_SIGNS, f.op) ? OP_SIGNS[f.op] : f.op} ${shown(f.value)}`;
204
- }
205
- function itemRuleText(f, labels, locale, { timeZone, date, labelOf, span }) {
206
- if (f.type === "relative") {
207
- return relativeText(
208
- /** @type {any} */
209
- f,
210
- labels,
211
- locale,
212
- timeZone,
213
- void 0,
214
- span
215
- );
216
- }
217
- if (f.type === "compare") {
218
- return compareText(
219
- /** @type {any} */
220
- f,
221
- labels,
222
- locale,
223
- { date, labelOf }
224
- );
225
- }
226
- const op = String(f.op);
227
- return `${Object.hasOwn(labels.labelOps, op) ? labels.labelOps[op] : op} ${fill(labels.quote, { text: f.value })}`;
228
- }
229
- function groupingName(source, unit, labels, size) {
230
- const inName = labels.unitInName && Object.hasOwn(labels.unitInName, unit) ? labels.unitInName[unit] : labels.units[unit];
231
- return unit === "bin" ? fill(labels.binsName, { field: source, size }) : fill(labels.derivedName, { field: source, unit: inName ?? unit });
232
- }
233
- var quickZone = (type) => type === "number" ? "values" : "rows";
234
- function fieldAction(field, type, zones, labels) {
235
- const zone = quickZone(type);
236
- const kind = zones.includes(zone) ? null : zone !== "values" && zones.some((z) => z === "cols" || z === "filters") ? "move" : "add";
237
- const name2 = zones.length ? `${field}, ${fill(labels.inZone, { zone: zones.map((z) => labels.zones[z] ?? z).join(", ") })}` : field;
238
- const description = kind === null ? "" : fill(kind === "move" ? labels.moveTo : labels.addTo, { zone: labels.zones[zone] });
239
- return { zone, kind, name: name2, description };
240
- }
241
- var SUMMARY_ORDER = Object.freeze(["rows", "cols", "values", "filters"]);
242
- function layoutSummary(entries2, labels) {
243
- return SUMMARY_ORDER.filter((zone) => entries2[zone] && entries2[zone].length).map((zone) => ({ zone, title: labels.zones[zone], fields: entries2[zone].map((e) => e.text).join(", ") }));
244
- }
245
-
246
- // src/drill.js
247
- import { cellRows } from "pivotkit-core";
248
- var DRILL_LIMIT = 1e3;
249
- function decodeRow(encoded, i) {
250
- const row = {};
251
- for (const column of encoded.columns) {
252
- const code = column.codes[i];
253
- const v = code < 0 ? null : column.dict[code];
254
- const value = column.type === "date" && typeof v === "number" ? new Date(v).toISOString().replace(/(T00:00:00)?\.000Z$/, "").replace(/:00$/, "") : v;
255
- Object.defineProperty(row, column.name, { value, enumerable: true, writable: true, configurable: true });
256
- }
257
- return row;
258
- }
259
- function drillRows(result, { rowPath = [], colPath = [], data = null, limit = DRILL_LIMIT }) {
260
- const all = cellRows(result, { row: rowPath, col: colPath });
261
- const indices = all.slice(0, Math.max(0, limit));
262
- const rows = new Array(indices.length);
263
- for (let k = 0; k < indices.length; k++) {
264
- rows[k] = data ? data[indices[k]] : decodeRow(result.encoded, indices[k]);
265
- }
266
- return { count: all.length, rows, indices };
267
- }
268
-
269
- // src/clear-input.jsx
270
- import React, { useRef } from "react";
271
- function emptyField(el) {
272
- el.focus({ preventScroll: true });
273
- let done;
274
- try {
275
- el.select();
276
- const doc = (
277
- /** @type {Document & { execCommand?: (cmd: string) => boolean }} */
278
- el.ownerDocument
279
- );
280
- done = typeof doc.execCommand === "function" && doc.execCommand("delete") && el.value === "";
281
- } catch {
282
- done = false;
283
- }
284
- if (!done) {
285
- const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
286
- Object.getOwnPropertyDescriptor(proto, "value")?.set?.call(el, "");
287
- el.dispatchEvent(new Event("input", { bubbles: true }));
288
- }
289
- }
290
- function ClearInput({ value, onChange, onClear, clearLabel, multiline = false, className, inputRef, ...rest }) {
291
- const own = useRef(
292
- /** @type {HTMLInputElement | HTMLTextAreaElement | null} */
293
- null
294
- );
295
- const name2 = useFormName();
296
- const ref = inputRef ?? own;
297
- const clear = () => {
298
- if (ref.current) {
299
- emptyField(ref.current);
300
- }
301
- onClear?.();
302
- };
303
- const onKeyDown = (e) => {
304
- rest.onKeyDown?.(e);
305
- if (e.key === "Escape" && value !== "" && !e.defaultPrevented) {
306
- e.preventDefault();
307
- e.stopPropagation();
308
- clear();
309
- }
310
- };
311
- const Tag = multiline ? "textarea" : "input";
312
- return /* @__PURE__ */ React.createElement("span", { className: `pk-clear-input${multiline ? " pk-clear-multi" : ""}${className ? ` ${className}` : ""}` }, /* @__PURE__ */ React.createElement(Tag, { name: name2, ...rest, ref, value, onChange: (e) => onChange(e.target.value), onKeyDown }), value !== "" ? /* @__PURE__ */ React.createElement(
313
- "button",
314
- {
315
- type: "button",
316
- className: "pk-clear-x",
317
- "aria-label": clearLabel,
318
- title: clearLabel,
319
- onPointerDown: (e) => e.preventDefault(),
320
- onMouseDown: (e) => e.preventDefault(),
321
- onClick: clear,
322
- "data-testid": "clear-input"
323
- },
324
- /* @__PURE__ */ React.createElement(Icon, { name: "x", size: 14 })
325
- ) : null);
326
- }
327
-
328
- // src/info.jsx
329
- import React2, { useCallback, useEffect, useId, useRef as useRef2, useState } from "react";
330
- var LEAVE_DELAY = 250;
331
- function FieldDescription({ info, labels, link = true, className = "pk-field-desc" }) {
332
- return /* @__PURE__ */ React2.createElement("p", { className }, /* @__PURE__ */ React2.createElement("span", null, info.description), link && info.href ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, " ", /* @__PURE__ */ React2.createElement("a", { href: info.href, target: "_blank", rel: "noopener noreferrer", className: "pk-learn-more" }, labels.learnMore)) : null);
333
- }
334
- function InfoButton({ info, name: name2, labels, className, testId = "field-info", label: named, tabIndex, slot }) {
335
- const [mode, setMode] = useState(
336
- /** @type {null | "peek" | "open"} */
337
- null
338
- );
339
- const ref = useRef2(
340
- /** @type {HTMLButtonElement | null} */
341
- null
342
- );
343
- const quiet = useRef2(false);
344
- const leaving = useRef2(
345
- /** @type {ReturnType<typeof setTimeout> | null} */
346
- null
347
- );
348
- const id = useId();
349
- const textId = useId();
350
- const stay = () => {
351
- if (leaving.current) {
352
- clearTimeout(leaving.current);
353
- leaving.current = null;
354
- }
355
- };
356
- const leaveSoon = () => {
357
- stay();
358
- leaving.current = setTimeout(() => setMode((m) => m === "peek" ? null : m), LEAVE_DELAY);
359
- };
360
- useEffect(() => stay, []);
361
- const close = useCallback(() => {
362
- quiet.current = true;
363
- setMode(null);
364
- requestAnimationFrame(() => {
365
- quiet.current = false;
366
- });
367
- }, []);
368
- const label = named ?? fill(labels.aboutField, { field: name2 });
369
- return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
370
- "button",
371
- {
372
- ref,
373
- type: "button",
374
- className: `pk-info${className ? ` ${className}` : ""}`,
375
- "aria-label": label,
376
- "aria-describedby": textId,
377
- "aria-expanded": mode === "open",
378
- "aria-controls": mode ? id : void 0,
379
- "aria-haspopup": "dialog",
380
- tabIndex,
381
- "data-pk-slot": slot,
382
- "data-testid": testId,
383
- onPointerEnter: (e) => {
384
- if (e.pointerType === "mouse") {
385
- stay();
386
- setMode((m) => m ?? "peek");
387
- }
388
- },
389
- onPointerLeave: (e) => {
390
- if (e.pointerType === "mouse" && mode === "peek") {
391
- leaveSoon();
392
- }
393
- },
394
- onFocus: () => {
395
- if (mode === null && !quiet.current) {
396
- setMode("peek");
397
- }
398
- },
399
- onBlur: (e) => {
400
- const to = (
401
- /** @type {Element | null} */
402
- e.relatedTarget
403
- );
404
- if (mode === "peek" && !(to && to.closest?.(".pk-info-pop"))) {
405
- setMode(null);
406
- }
407
- },
408
- onClick: () => {
409
- stay();
410
- setMode(mode === "open" ? null : "open");
411
- }
412
- },
413
- /* @__PURE__ */ React2.createElement(Icon, { name: "info", size: 14 })
414
- ), /* @__PURE__ */ React2.createElement("span", { id: textId, hidden: true }, info.description), /* @__PURE__ */ React2.createElement(
415
- Popover,
416
- {
417
- key: mode ?? "closed",
418
- open: mode !== null,
419
- passive: mode === "peek",
420
- anchor: ref,
421
- onClose: close,
422
- label,
423
- role: mode === "peek" ? "tooltip" : "dialog",
424
- className: "pk-info-pop",
425
- id,
426
- onPointerEnter: stay,
427
- onPointerLeave: (e) => {
428
- if (e.pointerType === "mouse" && mode === "peek") {
429
- leaveSoon();
430
- }
431
- }
432
- },
433
- /* @__PURE__ */ React2.createElement(FieldDescription, { info, labels })
434
- ));
41
+ const plan = corePlan(view, encoded);
42
+ return { name: chartTypeOf(plan.chart), ...plan };
435
43
  }
44
+ var MANY_SERIES = 8;
45
+ var MAX_CATEGORIES = 50;
436
46
 
437
47
  // src/view-ops.js
438
- import { LIMITS, aggregatorsFor, isFormat } from "pivotkit-core";
48
+ import { LIMITS, aggregatorsFor, foldText, isFormat, swapAxes } from "pivotkit-core";
439
49
  var ZONES = Object.freeze(
440
50
  /** @type {Zone[]} */
441
51
  ["filters", "cols", "rows", "values"]
442
52
  );
443
53
  var clone = (view) => JSON.parse(JSON.stringify(view));
54
+ var NEGATED = Object.freeze({ "=": "!=", between: "notBetween", equals: "notEquals", contains: "notContains", beginsWith: "notBeginsWith", endsWith: "notEndsWith" });
55
+ var RULE_OPS = Object.freeze({
56
+ text: Object.freeze(["equals", "notEquals", "contains", "notContains", "beginsWith", "notBeginsWith", "endsWith", "notEndsWith"]),
57
+ compare: Object.freeze(["=", "!=", ">", ">=", "<", "<=", "between", "notBetween"])
58
+ });
59
+ var ruleOp = (f) => f.not && typeof f.op === "string" && Object.hasOwn(NEGATED, f.op) ? NEGATED[f.op] : String(f.op);
60
+ var hiddenNot = (f) => Boolean(f.not) && !(typeof f.op === "string" && Object.hasOwn(NEGATED, f.op));
61
+ function opOf(menuOp) {
62
+ const positive = Object.keys(NEGATED).find((op) => NEGATED[op] === menuOp);
63
+ return positive ? { op: positive, not: true } : { op: menuOp, not: false };
64
+ }
65
+ var pickFilter = (field, excluded) => ({ field, type: "in", items: excluded.filter((v) => v !== null), not: true, blanks: excluded.includes(null) ? "exclude" : "include" });
66
+ var emptyPick = (field) => pickFilter(field, []);
67
+ var isPick = (f) => f.type === "in";
68
+ var isEmptyPick = (f) => isPick(f) && f.not === true && f.items.length === 0 && f.blanks === "include";
444
69
  var same = (a, b) => typeof a === "string" && typeof b === "string" && a.toLowerCase() === b.toLowerCase();
70
+ function searchItems(items, query) {
71
+ const q = foldText(query);
72
+ return q ? items.filter((i) => foldText(i.label).includes(q)) : items;
73
+ }
445
74
  var clamp = (i, n) => Number.isInteger(i) ? Math.max(0, Math.min(i, n)) : n;
446
75
  function filterZoneFields(view) {
447
76
  const seen = /* @__PURE__ */ new Set();
@@ -522,7 +151,7 @@ function addField(view, field, zone, options = {}) {
522
151
  } else if (zone === "filters") {
523
152
  dropFromAxes(next, field);
524
153
  if (!next.filters.some((f) => same(f.field, field))) {
525
- next.filters.push({ field, type: "exclude", items: [] });
154
+ next.filters.push(emptyPick(field));
526
155
  }
527
156
  }
528
157
  resetCollapsed(next, view);
@@ -653,7 +282,7 @@ function groupField(view, field, unit, options = {}) {
653
282
  const inFilterZone = !axis && filterZoneFields(view).some((f) => same(f, field));
654
283
  next.filters = next.filters.filter((f) => !same(f.field, field));
655
284
  if (inFilterZone) {
656
- next.filters.push({ field: name2, type: "exclude", items: [] });
285
+ next.filters.push(emptyPick(name2));
657
286
  }
658
287
  }
659
288
  next.sort = next.sort.map((s) => same(s.field, field) ? { ...s, field: name2 } : s);
@@ -729,9 +358,10 @@ function filtersOf(view, field, types) {
729
358
  }
730
359
  function selectedItems(view, field, all) {
731
360
  let selected = all;
732
- for (const f of filtersOf(view, field, ["include", "exclude"])) {
361
+ for (const f of filtersOf(view, field, ["in"])) {
733
362
  const listed = new Set(f.items.map((v) => JSON.stringify(v)));
734
- selected = selected.filter((v) => listed.has(JSON.stringify(v)) === (f.type === "include"));
363
+ const blank = f.blanks !== "exclude";
364
+ selected = selected.filter((v) => v === null ? blank : f.blanks !== "only" && listed.has(JSON.stringify(v)) !== f.not);
735
365
  }
736
366
  return selected;
737
367
  }
@@ -742,7 +372,7 @@ function sameRef(a, b) {
742
372
  return Boolean(a && b) && a.agg === b.agg && (a.field === null || b.field === null ? a.field === b.field : same(a.field, b.field));
743
373
  }
744
374
  function isFiltered(view, field) {
745
- return filtersOf(view, field).some((f) => f.type !== "exclude" || f.items.length > 0);
375
+ return filtersOf(view, field).some((f) => !isEmptyPick(f));
746
376
  }
747
377
  function toggleCollapsed(view, axis, path) {
748
378
  const next = clone(view);
@@ -754,71 +384,534 @@ function toggleCollapsed(view, axis, path) {
754
384
  } else {
755
385
  list.splice(at, 1);
756
386
  }
757
- return next;
387
+ return next;
388
+ }
389
+ function rowFolding(view, outer) {
390
+ const keys = new Set(view.collapsed.rows.map((p) => JSON.stringify(p)));
391
+ const collapsed = outer.filter((p) => keys.has(JSON.stringify(p))).length;
392
+ const open = view.rows.length < 2 ? 0 : outer.length - collapsed;
393
+ const canExpand = view.collapsed.rows.length > 0;
394
+ const canCollapse = open > 0;
395
+ return {
396
+ canExpand,
397
+ canCollapse,
398
+ collapsed: view.collapsed.rows.length,
399
+ open,
400
+ // keys of the menus' texts (menu-labels.js): the Options menu shows them with its labels
401
+ why: {
402
+ expand: canExpand ? null : "expandNothing",
403
+ collapse: canCollapse ? null : view.rows.length < 2 ? "collapseNeedsRows" : "collapseAllDone"
404
+ }
405
+ };
406
+ }
407
+ function setCollapsed(view, axis, paths) {
408
+ const next = clone(view);
409
+ next.collapsed[axis] = paths ? paths : [];
410
+ return next;
411
+ }
412
+ function setTotal(view, key, on) {
413
+ const next = clone(view);
414
+ next.totals[key] = Boolean(on);
415
+ return next;
416
+ }
417
+ function setDisplay(view, display) {
418
+ const next = clone(view);
419
+ next.display = display;
420
+ return next;
421
+ }
422
+ function setChart(view, name2) {
423
+ const next = clone(view);
424
+ next.chart = { ...next.chart, ...CHART_TYPES[name2].chart };
425
+ next.display = "chart";
426
+ return next;
427
+ }
428
+ function setChartDisplay(view, patch) {
429
+ const next = clone(view);
430
+ next.chart = { ...next.chart, ...patch };
431
+ return next;
432
+ }
433
+ function isEmptyView(view) {
434
+ return view.rows.length === 0 && view.cols.length === 0 && view.values.length === 0;
435
+ }
436
+
437
+ // src/names.js
438
+ import { fieldLabel, relativeDateRange } from "pivotkit-core";
439
+ var withNot = (f, text, labels) => hiddenNot(f) ? fill(labels.notRule, { rule: text }) : text;
440
+ function valueLabel(spec, labels) {
441
+ if (spec.label) {
442
+ return spec.label;
443
+ }
444
+ const core = labels.core;
445
+ let base;
446
+ if (!spec.field) {
447
+ base = core.countRows;
448
+ } else {
449
+ const agg = Object.hasOwn(core.aggregators, spec.agg) ? core.aggregators[spec.agg] : spec.agg;
450
+ base = fill(core.valueName, { agg, field: fieldLabel(spec.field, core) });
451
+ }
452
+ if (!spec.showAs || !core.showAs || !core.showAsName) {
453
+ return base;
454
+ }
455
+ const showAs = Object.hasOwn(core.showAs, spec.showAs.type) ? core.showAs[spec.showAs.type] : spec.showAs.type;
456
+ return fill(core.showAsName, { showAs, value: spec.field && spec.agg === "sum" ? fieldLabel(spec.field, core) : base });
457
+ }
458
+ function refLabel(view, ref, labels) {
459
+ const field = ref?.field ?? null;
460
+ const sameField = (v) => field === null || v.field === null || v.field === void 0 ? (v.field ?? null) === field : v.field.toLowerCase() === field.toLowerCase();
461
+ const spec = ref ? (view.values ?? []).find((v) => v.agg === ref.agg && sameField(v)) : void 0;
462
+ if (!spec && field === null) {
463
+ return labels.countOfRows;
464
+ }
465
+ return valueLabel({ ...spec ?? ref, showAs: null }, labels);
466
+ }
467
+ function sortText(view, sort, labels) {
468
+ const desc = sort.order === "desc";
469
+ if (sort.by === "value") {
470
+ return fill(desc ? labels.sortValueDesc : labels.sortValueAsc, { value: refLabel(view, sort.value, labels) });
471
+ }
472
+ if (sort.by === "custom") {
473
+ return desc ? labels.sortCustomDesc : labels.sortCustom;
474
+ }
475
+ return desc ? labels.sortLabelDesc : labels.sortLabelAsc;
476
+ }
477
+ var OP_SIGNS = Object.freeze({ "=": "=", "!=": "\u2260", ">": ">", ">=": "\u2265", "<": "<", "<=": "\u2264" });
478
+ function valueConditionText(view, f, labels, locale) {
479
+ const number = (x) => typeof x === "number" ? x.toLocaleString(locale, { maximumFractionDigits: 6 }) : "";
480
+ const value = refLabel(view, f.by ?? (view.values?.[0] ? { field: view.values[0].field ?? null, agg: view.values[0].agg } : null), labels);
481
+ const op = ruleOp(f);
482
+ if (op === "between" || op === "notBetween") {
483
+ const [from, to] = typeof f.value2 === "number" && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
484
+ return fill(labels.valueConditions[op], { value, from: number(from), to: number(to) });
485
+ }
486
+ return withNot(f, fill(labels.valueConditions.compare, { value, op: Object.hasOwn(OP_SIGNS, op) ? OP_SIGNS[op] : op, number: number(f.value) }), labels);
487
+ }
488
+ var dayText = (iso, locale) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { dateStyle: "medium", timeZone: "UTC" });
489
+ var isoDay = (ms) => new Date(ms).toISOString().slice(0, 10);
490
+ var dayAfter = (iso, n = 1) => isoDay(Date.parse(`${iso}T00:00Z`) + n * 864e5);
491
+ function relativeDays(f, timeZone, now, latest, more = {}) {
492
+ const range = datesOf(f, timeZone, now, latest, more);
493
+ return range && range.from !== null ? { from: range.from, to: range.to } : null;
494
+ }
495
+ var datesOf = (f, timeZone, now, latest, more = {}) => relativeDateRange(f.unit, f.count ?? 1, { timeZone, now, anchor: f.anchor, latest: latest ?? void 0, first: more.first ?? void 0, direction: f.direction, calendar: f.calendar, includeCurrent: f.includeCurrent, weekStart: more.weekStart });
496
+ var plainRange = (f) => ["last", "this"].includes(f.direction ?? "last") && f.calendar !== false && (f.anchor === void 0 || f.anchor === "today" || f.anchor === "latest") && ["year", "quarter", "month", "week", "day"].includes(f.unit);
497
+ function periodText(range, unit, locale) {
498
+ const month = (iso) => (/* @__PURE__ */ new Date(`${iso.slice(0, 10)}T00:00Z`)).toLocaleDateString(locale, { month: "short", year: "numeric", timeZone: "UTC" });
499
+ const quarter = (iso) => `Q${Math.floor((Number(iso.slice(5, 7)) - 1) / 3) + 1} ${iso.slice(0, 4)}`;
500
+ const text = unit === "year" ? (iso) => iso.slice(0, 4) : unit === "quarter" ? quarter : unit === "month" ? month : (iso) => dayText(iso.slice(0, 10), locale);
501
+ const [from, to] = [text(range.from), text(range.to)];
502
+ return from === to ? from : `${from}\u2013${to}`;
503
+ }
504
+ function rangeShare(range, unit, span, locale) {
505
+ const grain = unit === "quarter" ? "month" : unit === "week" ? "day" : unit;
506
+ range = { from: range.from.slice(0, 10), to: range.to.slice(0, 10) };
507
+ const [first, last] = [periodStart(isoDay(span.min), grain), periodEnd(isoDay(span.max), grain)];
508
+ if (first <= range.from && last >= range.to) {
509
+ return null;
510
+ }
511
+ const from = range.from > first ? range.from : first;
512
+ const to = range.to < last ? range.to : last;
513
+ if (from > to) {
514
+ return { none: true };
515
+ }
516
+ const missing = [];
517
+ let count = 0;
518
+ const part = (a, b, dataYear) => {
519
+ const years = [];
520
+ const [ya, yb] = [Number(a.slice(0, 4)), Number(b.slice(0, 4))];
521
+ for (let y = ya; y <= yb; y++) {
522
+ if (y !== dataYear) {
523
+ years.push(y);
524
+ }
525
+ }
526
+ if (years.length) {
527
+ missing.push(years.length === 1 ? String(years[0]) : `${years[0]}\u2013${years[years.length - 1]}`);
528
+ count += years.length;
529
+ }
530
+ if (ya <= dataYear && dataYear <= yb) {
531
+ const yearFrom = `${String(dataYear).padStart(4, "0")}-01-01`;
532
+ const yearTo = `${String(dataYear).padStart(4, "0")}-12-31`;
533
+ const rest = { from: a > yearFrom ? a : yearFrom, to: b < yearTo ? b : yearTo };
534
+ missing.push(periodText(rest, unit, locale));
535
+ count += periodText({ from: rest.from, to: rest.from }, unit, locale) === periodText({ from: rest.to, to: rest.to }, unit, locale) ? 1 : 2;
536
+ }
537
+ };
538
+ if (range.from < first) {
539
+ part(range.from, dayAfter(first, -1), Number(first.slice(0, 4)));
540
+ }
541
+ if (range.to > last) {
542
+ part(dayAfter(last), range.to, Number(last.slice(0, 4)));
543
+ }
544
+ return { none: false, data: periodText({ from, to }, unit, locale), missing, count };
545
+ }
546
+ var periodStart = (iso, unit) => unit === "year" ? `${iso.slice(0, 4)}-01-01` : unit === "month" ? `${iso.slice(0, 7)}-01` : iso;
547
+ function periodEnd(iso, unit) {
548
+ if (unit === "day") {
549
+ return iso;
550
+ }
551
+ const [y, m] = [Number(iso.slice(0, 4)), Number(iso.slice(5, 7))];
552
+ return isoDay(unit === "year" ? Date.UTC(y, 11, 31) : Date.UTC(y, m, 0));
553
+ }
554
+ function relativeText(f, labels, locale, timeZone, now, span, weekStart) {
555
+ if (!plainRange(f)) {
556
+ return otherRangeText(f, labels, locale, timeZone, now, span, weekStart);
557
+ }
558
+ const more = labels.relativeMore;
559
+ const count = f.count ?? 1;
560
+ const key = count === 1 ? f.unit : `${f.unit}s`;
561
+ let text = f.direction === "this" ? more.this[f.unit] ?? f.unit : Object.hasOwn(labels.relative, key) ? fill(labels.relative[key], { count: count.toLocaleString(locale) }) : fill(plural(more.last[f.unit] ?? { other: f.unit }, count, { lang: labels.lang, locale }), { count: count.toLocaleString(locale) });
562
+ const range = relativeDays(f, timeZone, now, span?.max, { weekStart });
563
+ const latest = f.anchor === "latest";
564
+ if (f.includeCurrent === false && f.direction !== "this" && !latest) {
565
+ text = fill(more.withoutCurrent, { text });
566
+ }
567
+ if (!range) {
568
+ return text;
569
+ }
570
+ if (latest) {
571
+ text = fill(labels.relativeTo, { text, end: periodText({ from: range.to, to: range.to }, f.unit, locale) });
572
+ }
573
+ const share = span ? rangeShare(range, f.unit, span, locale) : null;
574
+ if (!share) {
575
+ return latest ? text : fill(labels.withRange, { text, range: periodText(range, f.unit, locale) });
576
+ }
577
+ const lang = { lang: labels.lang, locale };
578
+ if (share.none) {
579
+ return fill(labels.withRange, { text, range: fill(plural(labels.noData, 1, lang), { range: periodText(range, f.unit, locale) }) });
580
+ }
581
+ return fill(labels.withShare, { text, range: share.data, missing: fill(plural(labels.noData, share.count, lang), { range: share.missing.join(", ") }) });
582
+ }
583
+ function otherRangeText(f, labels, locale, timeZone, now, span, weekStart) {
584
+ const more = labels.relativeMore;
585
+ const lang = { lang: labels.lang, locale };
586
+ const direction = f.direction ?? "last";
587
+ let text = direction === "this" ? more.this[f.unit] ?? f.unit : plural(more[direction]?.[f.unit] ?? { other: f.unit }, f.count ?? 1, lang);
588
+ if (f.calendar === false && direction !== "this") {
589
+ text = fill(more.rolling, { text });
590
+ } else if (f.includeCurrent === false && direction !== "this") {
591
+ text = fill(more.withoutCurrent, { text });
592
+ }
593
+ if (f.anchor === "latest") {
594
+ text = fill(more.fromLatest, { text });
595
+ } else if (f.anchor === "first") {
596
+ text = fill(more.fromFirst, { text });
597
+ } else if (f.anchor && f.anchor !== "today") {
598
+ text = fill(more.fromDate, { text, date: pointText(f.anchor, locale) });
599
+ }
600
+ const range = datesOf(f, timeZone, now, span?.max, { first: span?.min, weekStart });
601
+ if (!range) {
602
+ return text;
603
+ }
604
+ const days = (range.from === null || range.from.endsWith("T00:00")) && range.to.endsWith("T00:00");
605
+ const point = (iso) => pointText(days ? iso.slice(0, 10) : iso, locale);
606
+ const to = point(range.to);
607
+ return fill(labels.withRange, { text, range: range.from === null ? fill(more.until, { to }) : range.from === range.to ? to : `${point(range.from)} \u2013 ${to}` });
608
+ }
609
+ function precisionText(iso, precision, locale) {
610
+ if (precision === "year" || precision === "quarter" || precision === "month") {
611
+ const at = /* @__PURE__ */ new Date(`${iso.slice(0, 10)}T00:00Z`);
612
+ if (precision === "month") {
613
+ return at.toLocaleDateString(locale, { month: "short", year: "numeric", timeZone: "UTC" });
614
+ }
615
+ return precision === "year" ? iso.slice(0, iso.length - 6) : `Q${Math.floor(at.getUTCMonth() / 3) + 1} ${iso.slice(0, iso.length - 6)}`;
616
+ }
617
+ return pointText(iso, locale);
618
+ }
619
+ var pointText = (iso, locale) => iso.length > 10 ? (/* @__PURE__ */ new Date(`${iso.slice(0, 16)}Z`)).toLocaleString(locale, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" }) : dayText(iso, locale);
620
+ function wholeYears(from, to) {
621
+ const whole = typeof from === "string" && typeof to === "string" && /^\d{4}-01-01$/.test(from) && /^\d{4}-12-31$/.test(to);
622
+ return whole ? [from.slice(0, 4), to.slice(0, 4)] : null;
623
+ }
624
+ function compareText(f, labels, locale, { date, labelOf }) {
625
+ const shown = (v) => typeof v === "string" ? precisionText(v, f.precision, locale) : labelOf?.(v) ?? (date ? String(v) : v.toLocaleString(locale, { maximumFractionDigits: 6 }));
626
+ const forms = labels.compareShort;
627
+ const op = ruleOp(f);
628
+ if (op === "between" || op === "notBetween") {
629
+ const [from, to] = f.value2 !== void 0 && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
630
+ const years = wholeYears(from, to);
631
+ if (years) {
632
+ return years[0] === years[1] ? fill(forms[op === "between" ? "=" : "!="], { value: years[0] }) : fill(forms[op], { from: years[0], to: years[1] });
633
+ }
634
+ return fill(forms[op], { from: shown(from), to: shown(to) });
635
+ }
636
+ return withNot(f, date && Object.hasOwn(forms, op) ? fill(forms[op], { value: shown(f.value) }) : `${Object.hasOwn(OP_SIGNS, op) ? OP_SIGNS[op] : op} ${shown(f.value)}`, labels);
637
+ }
638
+ function itemRuleText(f, labels, locale, { timeZone, date, labelOf, span, weekStart }) {
639
+ if (f.type === "relative") {
640
+ return withNot(f, relativeText(
641
+ /** @type {any} */
642
+ f,
643
+ labels,
644
+ locale,
645
+ timeZone,
646
+ void 0,
647
+ span,
648
+ weekStart
649
+ ), labels);
650
+ }
651
+ if (f.type === "compare") {
652
+ return compareText(
653
+ /** @type {any} */
654
+ f,
655
+ labels,
656
+ locale,
657
+ { date, labelOf }
658
+ );
659
+ }
660
+ const op = ruleOp(f);
661
+ return withNot(f, `${Object.hasOwn(labels.labelOps, op) ? labels.labelOps[op] : op} ${fill(labels.quote, { text: f.value })}`, labels);
662
+ }
663
+ function groupingName(source, unit, labels, size) {
664
+ const inName = labels.unitInName && Object.hasOwn(labels.unitInName, unit) ? labels.unitInName[unit] : labels.units[unit];
665
+ return unit === "bin" ? fill(labels.binsName, { field: source, size }) : fill(labels.derivedName, { field: source, unit: inName ?? unit });
666
+ }
667
+ var quickZone = (type) => type === "number" ? "values" : "rows";
668
+ function fieldAction(field, type, zones, labels) {
669
+ const zone = quickZone(type);
670
+ const kind = zones.includes(zone) ? null : zone !== "values" && zones.some((z) => z === "cols" || z === "filters") ? "move" : "add";
671
+ const name2 = zones.length ? `${field}, ${fill(labels.inZone, { zone: zones.map((z) => labels.zones[z] ?? z).join(", ") })}` : field;
672
+ const description = kind === null ? "" : fill(kind === "move" ? labels.moveTo : labels.addTo, { zone: labels.zones[zone] });
673
+ return { zone, kind, name: name2, description };
674
+ }
675
+ var SUMMARY_ORDER = Object.freeze(["rows", "cols", "values", "filters"]);
676
+ function layoutSummary(entries, labels) {
677
+ return SUMMARY_ORDER.filter((zone) => entries[zone] && entries[zone].length).map((zone) => ({ zone, title: labels.zones[zone], fields: entries[zone].map((e) => e.text).join(", ") }));
678
+ }
679
+
680
+ // src/drill.js
681
+ import { cellRows } from "pivotkit-core";
682
+ var DRILL_LIMIT = 1e3;
683
+ function decodeRow(encoded, i) {
684
+ const row = {};
685
+ for (const column of encoded.columns) {
686
+ const code = column.codes[i];
687
+ const v = code < 0 ? null : column.dict[code];
688
+ const value = column.type === "date" && typeof v === "number" ? new Date(v).toISOString().replace(/(T00:00:00)?\.000Z$/, "").replace(/:00$/, "") : v;
689
+ Object.defineProperty(row, column.name, { value, enumerable: true, writable: true, configurable: true });
690
+ }
691
+ return row;
692
+ }
693
+ function drillRows(result, { rowPath = [], colPath = [], data = null, limit = DRILL_LIMIT }) {
694
+ const all = cellRows(result, { row: rowPath, col: colPath });
695
+ const indices = all.slice(0, Math.max(0, limit));
696
+ const rows = new Array(indices.length);
697
+ for (let k = 0; k < indices.length; k++) {
698
+ rows[k] = data ? data[indices[k]] : decodeRow(result.encoded, indices[k]);
699
+ }
700
+ return { count: all.length, rows, indices };
701
+ }
702
+
703
+ // src/clear-input.jsx
704
+ import React, { useRef } from "react";
705
+ function emptyField(el) {
706
+ el.focus({ preventScroll: true });
707
+ let done;
708
+ try {
709
+ el.select();
710
+ const doc = (
711
+ /** @type {Document & { execCommand?: (cmd: string) => boolean }} */
712
+ el.ownerDocument
713
+ );
714
+ done = typeof doc.execCommand === "function" && doc.execCommand("delete") && el.value === "";
715
+ } catch {
716
+ done = false;
717
+ }
718
+ if (!done) {
719
+ const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
720
+ Object.getOwnPropertyDescriptor(proto, "value")?.set?.call(el, "");
721
+ el.dispatchEvent(new Event("input", { bubbles: true }));
722
+ }
758
723
  }
759
- function rowFolding(view, outer) {
760
- const keys = new Set(view.collapsed.rows.map((p) => JSON.stringify(p)));
761
- const collapsed = outer.filter((p) => keys.has(JSON.stringify(p))).length;
762
- const open = view.rows.length < 2 ? 0 : outer.length - collapsed;
763
- const canExpand = view.collapsed.rows.length > 0;
764
- const canCollapse = open > 0;
765
- return {
766
- canExpand,
767
- canCollapse,
768
- collapsed: view.collapsed.rows.length,
769
- open,
770
- // keys of the menus' texts (menu-labels.js): the Options menu shows them with its labels
771
- why: {
772
- expand: canExpand ? null : "expandNothing",
773
- collapse: canCollapse ? null : view.rows.length < 2 ? "collapseNeedsRows" : "collapseAllDone"
724
+ function ClearInput({ value, onChange, onClear, clearLabel, multiline = false, className, inputRef, ...rest }) {
725
+ const own = useRef(
726
+ /** @type {HTMLInputElement | HTMLTextAreaElement | null} */
727
+ null
728
+ );
729
+ const name2 = useFormName();
730
+ const ref = inputRef ?? own;
731
+ const clear = () => {
732
+ if (ref.current) {
733
+ emptyField(ref.current);
774
734
  }
735
+ onClear?.();
775
736
  };
737
+ const onKeyDown = (e) => {
738
+ rest.onKeyDown?.(e);
739
+ if (e.key === "Escape" && value !== "" && !e.defaultPrevented) {
740
+ e.preventDefault();
741
+ e.stopPropagation();
742
+ clear();
743
+ }
744
+ };
745
+ const Tag = multiline ? "textarea" : "input";
746
+ return /* @__PURE__ */ React.createElement("span", { className: `pk-clear-input${multiline ? " pk-clear-multi" : ""}${className ? ` ${className}` : ""}` }, /* @__PURE__ */ React.createElement(Tag, { name: name2, ...rest, ref, value, onChange: (e) => onChange(e.target.value), onKeyDown }), value !== "" ? /* @__PURE__ */ React.createElement(
747
+ "button",
748
+ {
749
+ type: "button",
750
+ className: "pk-clear-x",
751
+ "aria-label": clearLabel,
752
+ title: clearLabel,
753
+ onPointerDown: (e) => e.preventDefault(),
754
+ onMouseDown: (e) => e.preventDefault(),
755
+ onClick: clear,
756
+ "data-testid": "clear-input"
757
+ },
758
+ /* @__PURE__ */ React.createElement(Icon, { name: "x", size: 14 })
759
+ ) : null);
776
760
  }
777
- function setCollapsed(view, axis, paths) {
778
- const next = clone(view);
779
- next.collapsed[axis] = paths ? paths : [];
780
- return next;
781
- }
782
- function setTotal(view, key, on) {
783
- const next = clone(view);
784
- next.totals[key] = Boolean(on);
785
- return next;
786
- }
787
- function setDisplay(view, display) {
788
- const next = clone(view);
789
- next.display = display;
790
- return next;
791
- }
792
- function setChart(view, name2) {
793
- const next = clone(view);
794
- next.chart = { ...next.chart, ...CHART_TYPES[name2].chart };
795
- next.display = "chart";
796
- return next;
797
- }
798
- function setChartDisplay(view, patch) {
799
- const next = clone(view);
800
- next.chart = { ...next.chart, ...patch };
801
- return next;
761
+
762
+ // src/info.jsx
763
+ import React2, { useCallback, useEffect, useId, useRef as useRef2, useState } from "react";
764
+ var LEAVE_DELAY = 250;
765
+ var WAY_TIME = 1500;
766
+ function FieldDescription({ info, labels, link = true, className = "pk-field-desc" }) {
767
+ return /* @__PURE__ */ React2.createElement("p", { className }, /* @__PURE__ */ React2.createElement("span", null, info.description), link && info.href ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, " ", /* @__PURE__ */ React2.createElement("a", { href: info.href, target: "_blank", rel: "noopener noreferrer", className: "pk-learn-more" }, labels.learnMore)) : null);
802
768
  }
803
- function swapAxes(view) {
804
- const next = clone(view);
805
- [next.rows, next.cols] = [next.cols, next.rows];
806
- next.collapsed = { rows: next.collapsed.cols, cols: next.collapsed.rows };
807
- for (const v of next.values) {
808
- if (v.showAs && v.showAs.axis) {
809
- v.showAs = { ...v.showAs, axis: v.showAs.axis === "rows" ? "cols" : "rows" };
769
+ function InfoButton({ info, name: name2, labels, className, testId = "field-info", label: named, tabIndex, slot }) {
770
+ const [mode, setMode] = useState(
771
+ /** @type {null | "peek" | "open"} */
772
+ null
773
+ );
774
+ const ref = useRef2(
775
+ /** @type {HTMLButtonElement | null} */
776
+ null
777
+ );
778
+ const quiet = useRef2(false);
779
+ const leaving = useRef2(
780
+ /** @type {ReturnType<typeof setTimeout> | null} */
781
+ null
782
+ );
783
+ const id = useId();
784
+ const textId = useId();
785
+ const pointer = useRef2(
786
+ /** @type {{ x: number, y: number } | null} */
787
+ null
788
+ );
789
+ const stay = () => {
790
+ if (leaving.current) {
791
+ clearTimeout(leaving.current);
792
+ leaving.current = null;
810
793
  }
811
- }
812
- const swapped = { percentOfRowTotal: "percentOfColumnTotal", percentOfColumnTotal: "percentOfRowTotal", percentOfParentRow: "percentOfParentColumn", percentOfParentColumn: "percentOfParentRow" };
813
- for (const v of next.values) {
814
- if (v.showAs && Object.hasOwn(swapped, v.showAs.type)) {
815
- v.showAs = { ...v.showAs, type: swapped[v.showAs.type] };
794
+ };
795
+ const hovered = (onItsWay) => {
796
+ const button = ref.current;
797
+ const root = (
798
+ /** @type {Document | ShadowRoot | null} */
799
+ button?.getRootNode() ?? null
800
+ );
801
+ const pop = root && "getElementById" in root ? root.getElementById(id) : null;
802
+ return Boolean(
803
+ button?.matches(":hover") || pop?.matches(":hover") || onItsWay && button && pop && onTheWay(button.getBoundingClientRect(), pop.getBoundingClientRect(), pointer.current)
804
+ );
805
+ };
806
+ const leaveSoon = () => {
807
+ stay();
808
+ const left = Date.now();
809
+ const check = () => {
810
+ if (hovered(Date.now() - left < WAY_TIME)) {
811
+ leaving.current = setTimeout(check, LEAVE_DELAY);
812
+ return;
813
+ }
814
+ leaving.current = null;
815
+ setMode((m) => m === "peek" ? null : m);
816
+ };
817
+ leaving.current = setTimeout(check, LEAVE_DELAY);
818
+ };
819
+ useEffect(() => stay, []);
820
+ useEffect(() => {
821
+ const doc = ref.current?.ownerDocument;
822
+ if (mode !== "peek" || !doc) {
823
+ return void 0;
816
824
  }
817
- }
818
- return next;
819
- }
820
- function isEmptyView(view) {
821
- return view.rows.length === 0 && view.cols.length === 0 && view.values.length === 0;
825
+ const follow = (e) => {
826
+ pointer.current = { x: e.clientX, y: e.clientY };
827
+ };
828
+ const gone = (e) => {
829
+ if (!e.relatedTarget) {
830
+ pointer.current = null;
831
+ }
832
+ };
833
+ doc.addEventListener("pointermove", follow, { capture: true, passive: true });
834
+ doc.addEventListener("pointerout", gone, { capture: true, passive: true });
835
+ return () => {
836
+ doc.removeEventListener("pointermove", follow, { capture: true });
837
+ doc.removeEventListener("pointerout", gone, { capture: true });
838
+ pointer.current = null;
839
+ };
840
+ }, [mode]);
841
+ const close = useCallback(() => {
842
+ quiet.current = true;
843
+ setMode(null);
844
+ requestAnimationFrame(() => {
845
+ quiet.current = false;
846
+ });
847
+ }, []);
848
+ const label = named ?? fill(labels.aboutField, { field: name2 });
849
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
850
+ "button",
851
+ {
852
+ ref,
853
+ type: "button",
854
+ className: `pk-info${className ? ` ${className}` : ""}`,
855
+ "aria-label": label,
856
+ "aria-describedby": textId,
857
+ "aria-expanded": mode === "open",
858
+ "aria-controls": mode ? id : void 0,
859
+ "aria-haspopup": "dialog",
860
+ tabIndex,
861
+ "data-pk-slot": slot,
862
+ "data-testid": testId,
863
+ onPointerEnter: (e) => {
864
+ if (e.pointerType === "mouse") {
865
+ stay();
866
+ setMode((m) => m ?? "peek");
867
+ }
868
+ },
869
+ onPointerLeave: (e) => {
870
+ if (e.pointerType === "mouse" && mode === "peek") {
871
+ leaveSoon();
872
+ }
873
+ },
874
+ onFocus: () => {
875
+ if (mode === null && !quiet.current) {
876
+ setMode("peek");
877
+ }
878
+ },
879
+ onBlur: (e) => {
880
+ const to = (
881
+ /** @type {Element | null} */
882
+ e.relatedTarget
883
+ );
884
+ if (mode === "peek" && !(to && to.closest?.(".pk-info-pop"))) {
885
+ setMode(null);
886
+ }
887
+ },
888
+ onClick: () => {
889
+ stay();
890
+ setMode(mode === "open" ? null : "open");
891
+ }
892
+ },
893
+ /* @__PURE__ */ React2.createElement(Icon, { name: "info", size: 14 })
894
+ ), /* @__PURE__ */ React2.createElement("span", { id: textId, hidden: true }, info.description), /* @__PURE__ */ React2.createElement(
895
+ Popover,
896
+ {
897
+ key: mode ?? "closed",
898
+ open: mode !== null,
899
+ passive: mode === "peek",
900
+ anchor: ref,
901
+ onClose: close,
902
+ label,
903
+ role: mode === "peek" ? "tooltip" : "dialog",
904
+ className: "pk-info-pop",
905
+ id,
906
+ onPointerEnter: stay,
907
+ onPointerLeave: (e) => {
908
+ if (e.pointerType === "mouse" && mode === "peek") {
909
+ leaveSoon();
910
+ }
911
+ }
912
+ },
913
+ /* @__PURE__ */ React2.createElement(FieldDescription, { info, labels })
914
+ ));
822
915
  }
823
916
 
824
917
  // src/help.js
@@ -829,7 +922,7 @@ var HelpContext = createContext(
829
922
  );
830
923
 
831
924
  // src/share.js
832
- import { VIEW_FILE_LIMITS, fromViewFile, normalize } from "pivotkit-core";
925
+ import { VIEW_FILE_LIMITS, fromViewFile, linkFragment, normalize, outsideLimits, withLinkFragment } from "pivotkit-core";
833
926
  var linkModule = null;
834
927
  var linkLoaded = null;
835
928
  function loadLink() {
@@ -840,24 +933,8 @@ function loadLink() {
840
933
  return linkModule;
841
934
  }
842
935
  var linkNow = () => linkLoaded;
843
- function linkParam(storageKey) {
844
- return storageKey ? `pivot-${storageKey}` : "pivot";
845
- }
846
- var entries = (fragment) => fragment ? fragment.split("&") : [];
847
- var isEntry = (entry, param) => entry.startsWith(`${encodeURIComponent(param)}=`);
848
- function readLinkParam(hash, param) {
849
- const text = typeof hash === "string" ? hash.replace(/^#/, "") : "";
850
- const entry = entries(text).find((e) => isEntry(e, param));
851
- const value = entry ? entry.slice(encodeURIComponent(param).length + 1) : "";
852
- return value ? value : null;
853
- }
854
- function withLinkParam(url, param, encoded) {
855
- const at = url.indexOf("#");
856
- const base = at === -1 ? url : url.slice(0, at);
857
- const kept = entries(at === -1 ? "" : url.slice(at + 1)).filter((e) => !isEntry(e, param));
858
- const next = encoded ? [...kept, `${encodeURIComponent(param)}=${encoded}`] : kept;
859
- return next.length ? `${base}#${next.join("&")}` : base;
860
- }
936
+ var readLinkParam = (hash, key) => linkFragment(hash, key);
937
+ var withLinkParam = (url, key, encoded) => withLinkFragment(url, key, encoded);
861
938
  function shareBase(shareLink, here) {
862
939
  if (shareLink === true) {
863
940
  if (!here) {
@@ -907,7 +984,7 @@ function viewFromObject(input, encoded, options = {}) {
907
984
  const failed = file.failed ?? "notView";
908
985
  return { view: null, issues: file.issues, failed: Object.hasOwn(FAILED, failed) ? FAILED[failed] : failed, file };
909
986
  }
910
- const { view, issues } = normalize(file.view, encoded, options.limits ? { limits: options.limits } : void 0);
987
+ const { view, issues } = normalize(file.view, encoded, { limits: outsideLimits(options.limits) });
911
988
  if (issues.some((i) => i.path === "version")) {
912
989
  return { view: null, issues, failed: "newer", file };
913
990
  }
@@ -1064,6 +1141,14 @@ var TIPS = Object.freeze([
1064
1141
  return spec ? { type: spec.showAs.type } : null;
1065
1142
  }
1066
1143
  },
1144
+ {
1145
+ // column subtotals with two or more fields in Columns: what a Total column next to the
1146
+ // others adds up (people read "1 Critical Total" as one more status)
1147
+ id: "colSubtotals",
1148
+ icon: "sigma",
1149
+ action: "colSubtotalsOff",
1150
+ when: (ctx) => table(ctx) && ctx.view.values.length > 0 && ctx.view.totals.colSubtotals && ctx.view.cols.length >= 2 && ctx.colSubtotalShown ? {} : null
1151
+ },
1067
1152
  {
1068
1153
  // a type the user chose for data over time: lines show it (automatic draws them)
1069
1154
  id: "chartOverTime",
@@ -1217,6 +1302,11 @@ var SHORTCUTS = Object.freeze([
1217
1302
  { keys: ["Arrow keys"], text: "fields" },
1218
1303
  { keys: ["Shift", "F10"], text: "fieldMenu" }
1219
1304
  ]);
1305
+ function expandedGroup(nodes, depth, collapsed) {
1306
+ const shut = new Set(collapsed.map((path) => JSON.stringify(path)));
1307
+ const open = (path) => path.every((_, i) => !shut.has(JSON.stringify(path.slice(0, i + 1))));
1308
+ return nodes.some((node) => node.depth > 0 && node.depth < depth && node.children.length > 1 && open(node.path));
1309
+ }
1220
1310
  function tipContext({ view, result, encoded, failed, empty, typeOf, fields, series = null, tableShown = false, drilled = false, changes = 0, dragAt = null, canSave = false, savedAt = 0, chartPlan: chartPlan2 = { name: "bar", auto: true, swap: false } }) {
1221
1311
  const leaves = (nodes, depth) => result && depth > 0 ? nodes.reduce((n, node) => n + (node.depth === depth ? 1 : 0), 0) : 1;
1222
1312
  return {
@@ -1228,6 +1318,7 @@ function tipContext({ view, result, encoded, failed, empty, typeOf, fields, seri
1228
1318
  fields,
1229
1319
  rowLeaves: result ? leaves(result.rowNodes, result.rowFields.length) : 0,
1230
1320
  colLeaves: result ? leaves(result.colNodes, result.colFields.length) : 0,
1321
+ colSubtotalShown: result ? expandedGroup(result.colNodes, result.colFields.length, view.collapsed?.cols ?? []) : false,
1231
1322
  matched: result ? result.rows.length : 0,
1232
1323
  dataRows: encoded.length,
1233
1324
  series,
@@ -1317,7 +1408,7 @@ function writeDismissed(key, storage, dismissed) {
1317
1408
  }
1318
1409
  }
1319
1410
  function withoutFilters(view) {
1320
- return { ...view, filters: filterZoneFields(view).map((field) => ({ field, type: "exclude", items: [] })) };
1411
+ return { ...view, filters: filterZoneFields(view).map(emptyPick) };
1321
1412
  }
1322
1413
 
1323
1414
  // src/lazy-import.js
@@ -1342,29 +1433,18 @@ export {
1342
1433
  chartTypeOf,
1343
1434
  chartPlan,
1344
1435
  MAX_CATEGORIES,
1345
- valueLabel,
1346
- refLabel,
1347
- sortText,
1348
- valueConditionText,
1349
- dayText,
1350
- isoDay,
1351
- relativeDays,
1352
- periodText,
1353
- rangeShare,
1354
- relativeText,
1355
- wholeYears,
1356
- itemRuleText,
1357
- groupingName,
1358
- fieldAction,
1359
- layoutSummary,
1360
- DRILL_LIMIT,
1361
- decodeRow,
1362
- drillRows,
1363
- ClearInput,
1364
- InfoButton,
1436
+ swapAxes,
1365
1437
  ZONES,
1366
1438
  clone,
1439
+ RULE_OPS,
1440
+ ruleOp,
1441
+ hiddenNot,
1442
+ opOf,
1443
+ pickFilter,
1444
+ emptyPick,
1445
+ isEmptyPick,
1367
1446
  same,
1447
+ searchItems,
1368
1448
  filterZoneFields,
1369
1449
  axisOf,
1370
1450
  zoneOverLimit,
@@ -1395,12 +1475,31 @@ export {
1395
1475
  setDisplay,
1396
1476
  setChart,
1397
1477
  setChartDisplay,
1398
- swapAxes,
1399
1478
  isEmptyView,
1479
+ valueLabel,
1480
+ refLabel,
1481
+ sortText,
1482
+ valueConditionText,
1483
+ dayText,
1484
+ isoDay,
1485
+ relativeDays,
1486
+ plainRange,
1487
+ periodText,
1488
+ rangeShare,
1489
+ relativeText,
1490
+ wholeYears,
1491
+ itemRuleText,
1492
+ groupingName,
1493
+ fieldAction,
1494
+ layoutSummary,
1495
+ DRILL_LIMIT,
1496
+ decodeRow,
1497
+ drillRows,
1498
+ ClearInput,
1499
+ InfoButton,
1400
1500
  HelpContext,
1401
1501
  loadLink,
1402
1502
  linkNow,
1403
- linkParam,
1404
1503
  readLinkParam,
1405
1504
  withLinkParam,
1406
1505
  shareBase,