pivotkit-react 0.1.0 → 0.3.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 (61) hide show
  1. package/CHANGELOG.md +306 -1
  2. package/README.md +48 -298
  3. package/dist/chunks/{chunk-ILHFIV2P.js → chunk-32Z33U6S.js} +58 -78
  4. package/dist/chunks/chunk-7CC4JHDY.js +363 -0
  5. package/dist/chunks/chunk-APB4NW4O.js +434 -0
  6. package/dist/chunks/chunk-EM23V5GH.js +183 -0
  7. package/dist/chunks/{chunk-KKJO36W5.js → chunk-IOPAM4JD.js} +412 -365
  8. package/dist/chunks/chunk-RWYHJRQO.js +99 -0
  9. package/dist/chunks/unused-texts-K3VFH65P.js +10 -0
  10. package/dist/chunks/unused-texts-de-OW4TGIVX.js +6 -0
  11. package/dist/echarts.js +96 -11
  12. package/dist/index.js +654 -560
  13. package/dist/labels.js +13 -4
  14. package/dist/menu-texts-de.js +6 -0
  15. package/dist/menus.js +2905 -550
  16. package/dist/styles.css +738 -216
  17. package/package.json +2 -2
  18. package/types/chart-layout.d.ts +111 -0
  19. package/types/chart-types.d.ts +0 -91
  20. package/types/chip-menus.d.ts +20 -4
  21. package/types/dnd.d.ts +8 -4
  22. package/types/drill-panel.d.ts +5 -22
  23. package/types/drill-table.d.ts +71 -0
  24. package/types/drill.d.ts +0 -36
  25. package/types/filter-level.d.ts +16 -0
  26. package/types/filter.d.ts +31 -0
  27. package/types/help.d.ts +14 -0
  28. package/types/icons.d.ts +4 -0
  29. package/types/labels.d.ts +114 -101
  30. package/types/lazy-menus.d.ts +18 -6
  31. package/types/levels.d.ts +105 -0
  32. package/types/menu-fields.d.ts +80 -0
  33. package/types/menu-labels-de.d.ts +2 -0
  34. package/types/menu-labels.d.ts +270 -13
  35. package/types/menu-ops.d.ts +286 -0
  36. package/types/menu-texts.d.ts +2 -0
  37. package/types/menu-topics.d.ts +293 -0
  38. package/types/menus.d.ts +2 -2
  39. package/types/names.d.ts +160 -20
  40. package/types/overflow.d.ts +4 -1
  41. package/types/place.d.ts +44 -0
  42. package/types/popover.d.ts +10 -6
  43. package/types/section.d.ts +8 -28
  44. package/types/share-actions.d.ts +99 -0
  45. package/types/share.d.ts +0 -9
  46. package/types/table.d.ts +9 -3
  47. package/types/templates.d.ts +7 -1
  48. package/types/tips.d.ts +1 -34
  49. package/types/toolbar-panels.d.ts +20 -10
  50. package/types/unused-load.d.ts +23 -0
  51. package/types/unused-texts-de.d.ts +2 -0
  52. package/types/unused-texts.d.ts +136 -0
  53. package/types/unused.d.ts +22 -0
  54. package/types/use-view-history.d.ts +8 -4
  55. package/types/view-history.d.ts +23 -6
  56. package/types/view-ops.d.ts +80 -119
  57. package/types/view-save.d.ts +76 -0
  58. package/types/view-store.d.ts +13 -6
  59. package/types/zones.d.ts +5 -4
  60. package/dist/chunks/chunk-C32TYSHG.js +0 -441
  61. package/dist/chunks/chunk-XYP47DJ3.js +0 -123
@@ -1,15 +1,59 @@
1
1
  import {
2
- CHART_TYPES,
3
- MANY_SERIES,
4
- SLICE_TYPES,
5
- chartPlan
6
- } from "./chunk-XYP47DJ3.js";
7
- import {
8
- fill
9
- } from "./chunk-ILHFIV2P.js";
2
+ fill,
3
+ plural
4
+ } from "./chunk-32Z33U6S.js";
5
+
6
+ // src/chart-types.js
7
+ import { autoChartType } from "pivotkit-core";
8
+ var CHART_TYPES = Object.freeze({
9
+ auto: { chart: { type: "auto", stacked: false, horizontal: false }, icon: "sparkle", axis: true },
10
+ bar: { chart: { type: "bar", stacked: false, horizontal: false }, icon: "chart", axis: true },
11
+ stacked: { chart: { type: "bar", stacked: true, horizontal: false }, icon: "stacked", axis: true },
12
+ horizontal: { chart: { type: "bar", stacked: false, horizontal: true }, icon: "horizontal", axis: true },
13
+ line: { chart: { type: "line", stacked: false, horizontal: false }, icon: "line", axis: true },
14
+ area: { chart: { type: "area", stacked: false, horizontal: false }, icon: "area", axis: true },
15
+ pie: { chart: { type: "pie", stacked: false, horizontal: false }, icon: "pie", axis: false },
16
+ donut: { chart: { type: "donut", stacked: false, horizontal: false }, icon: "donut", axis: false },
17
+ heatmap: { chart: { type: "heatmap", stacked: false, horizontal: false }, icon: "heatmap", axis: false }
18
+ });
19
+ var SLICE_TYPES = Object.freeze(["pie", "donut"]);
20
+ var CHART_TYPE_NAMES = Object.freeze(Object.keys(CHART_TYPES));
21
+ function chartTypeOf(chart2) {
22
+ const found = CHART_TYPE_NAMES.find((name2) => {
23
+ const c = CHART_TYPES[name2].chart;
24
+ return c.type === chart2.type && c.stacked === Boolean(chart2.stacked) && c.horizontal === Boolean(chart2.horizontal);
25
+ });
26
+ if (found) {
27
+ return found;
28
+ }
29
+ if (chart2.type === "bar") {
30
+ return chart2.horizontal ? "horizontal" : "stacked";
31
+ }
32
+ return CHART_TYPE_NAMES.find((name2) => CHART_TYPES[name2].chart.type === chart2.type) ?? "bar";
33
+ }
34
+ function chartPlan(view, encoded) {
35
+ if (view.chart.type !== "auto") {
36
+ const name3 = chartTypeOf(view.chart);
37
+ return { name: name3, auto: false, swap: false, chart: { type: view.chart.type, stacked: Boolean(view.chart.stacked), horizontal: Boolean(view.chart.horizontal) } };
38
+ }
39
+ const own = autoChartType(
40
+ /** @type {any} */
41
+ view,
42
+ encoded
43
+ );
44
+ const swap = own === "bar" && view.cols.length > 0 && autoChartType(
45
+ /** @type {any} */
46
+ { ...view, rows: view.cols },
47
+ encoded
48
+ ) === "line";
49
+ const name2 = own === "line" || swap ? "line" : "bar";
50
+ return { name: name2, auto: true, swap, chart: { ...CHART_TYPES[name2].chart } };
51
+ }
52
+ var MANY_SERIES = 8;
53
+ var MAX_CATEGORIES = 50;
10
54
 
11
55
  // src/names.js
12
- import { fieldLabel } from "pivotkit-core";
56
+ import { fieldLabel, relativeDateRange } from "pivotkit-core";
13
57
  function valueLabel(spec, labels) {
14
58
  if (spec.label) {
15
59
  return spec.label;
@@ -29,13 +73,24 @@ function valueLabel(spec, labels) {
29
73
  return fill(core.showAsName, { showAs, value: spec.field && spec.agg === "sum" ? fieldLabel(spec.field, core) : base });
30
74
  }
31
75
  function refLabel(view, ref, labels) {
32
- if (!ref) {
33
- return labels.core.countRows;
76
+ const field = ref?.field ?? null;
77
+ const sameField = (v) => field === null || v.field === null || v.field === void 0 ? (v.field ?? null) === field : v.field.toLowerCase() === field.toLowerCase();
78
+ const spec = ref ? (view.values ?? []).find((v) => v.agg === ref.agg && sameField(v)) : void 0;
79
+ if (!spec && field === null) {
80
+ return labels.countOfRows;
34
81
  }
35
- const sameField = (v) => ref.field === null || v.field === null || v.field === void 0 ? (v.field ?? null) === ref.field : v.field.toLowerCase() === ref.field.toLowerCase();
36
- const spec = (view.values ?? []).find((v) => v.agg === ref.agg && sameField(v));
37
82
  return valueLabel({ ...spec ?? ref, showAs: null }, labels);
38
83
  }
84
+ function sortText(view, sort, labels) {
85
+ const desc = sort.order === "desc";
86
+ if (sort.by === "value") {
87
+ return fill(desc ? labels.sortValueDesc : labels.sortValueAsc, { value: refLabel(view, sort.value, labels) });
88
+ }
89
+ if (sort.by === "custom") {
90
+ return desc ? labels.sortCustomDesc : labels.sortCustom;
91
+ }
92
+ return desc ? labels.sortLabelDesc : labels.sortLabelAsc;
93
+ }
39
94
  var OP_SIGNS = Object.freeze({ "=": "=", "!=": "\u2260", ">": ">", ">=": "\u2265", "<": "<", "<=": "\u2264" });
40
95
  function valueConditionText(view, f, labels, locale) {
41
96
  const number = (x) => typeof x === "number" ? x.toLocaleString(locale, { maximumFractionDigits: 6 }) : "";
@@ -46,6 +101,126 @@ function valueConditionText(view, f, labels, locale) {
46
101
  }
47
102
  return fill(labels.valueConditions.compare, { value, op: Object.hasOwn(OP_SIGNS, f.op) ? OP_SIGNS[f.op] : f.op, number: number(f.value) });
48
103
  }
104
+ var dayText = (iso, locale) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { dateStyle: "medium", timeZone: "UTC" });
105
+ var isoDay = (ms) => new Date(ms).toISOString().slice(0, 10);
106
+ var dayAfter = (iso, n = 1) => isoDay(Date.parse(`${iso}T00:00Z`) + n * 864e5);
107
+ var relativeDays = (f, timeZone, now, latest) => relativeDateRange(f.unit, f.count, { timeZone, now, anchor: f.anchor, latest: latest ?? void 0 });
108
+ function periodText(range, unit, locale) {
109
+ const month = (iso) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { month: "short", year: "numeric", timeZone: "UTC" });
110
+ const text = unit === "year" ? (iso) => iso.slice(0, 4) : unit === "month" ? month : (iso) => dayText(iso, locale);
111
+ const [from, to] = [text(range.from), text(range.to)];
112
+ return from === to ? from : `${from}\u2013${to}`;
113
+ }
114
+ function rangeShare(range, unit, span, locale) {
115
+ const [first, last] = [periodStart(isoDay(span.min), unit), periodEnd(isoDay(span.max), unit)];
116
+ if (first <= range.from && last >= range.to) {
117
+ return null;
118
+ }
119
+ const from = range.from > first ? range.from : first;
120
+ const to = range.to < last ? range.to : last;
121
+ if (from > to) {
122
+ return { none: true };
123
+ }
124
+ const missing = [];
125
+ let count = 0;
126
+ const part = (a, b, dataYear) => {
127
+ const years = [];
128
+ const [ya, yb] = [Number(a.slice(0, 4)), Number(b.slice(0, 4))];
129
+ for (let y = ya; y <= yb; y++) {
130
+ if (y !== dataYear) {
131
+ years.push(y);
132
+ }
133
+ }
134
+ if (years.length) {
135
+ missing.push(years.length === 1 ? String(years[0]) : `${years[0]}\u2013${years[years.length - 1]}`);
136
+ count += years.length;
137
+ }
138
+ if (ya <= dataYear && dataYear <= yb) {
139
+ const yearFrom = `${String(dataYear).padStart(4, "0")}-01-01`;
140
+ const yearTo = `${String(dataYear).padStart(4, "0")}-12-31`;
141
+ const rest = { from: a > yearFrom ? a : yearFrom, to: b < yearTo ? b : yearTo };
142
+ missing.push(periodText(rest, unit, locale));
143
+ count += periodText({ from: rest.from, to: rest.from }, unit, locale) === periodText({ from: rest.to, to: rest.to }, unit, locale) ? 1 : 2;
144
+ }
145
+ };
146
+ if (range.from < first) {
147
+ part(range.from, dayAfter(first, -1), Number(first.slice(0, 4)));
148
+ }
149
+ if (range.to > last) {
150
+ part(dayAfter(last), range.to, Number(last.slice(0, 4)));
151
+ }
152
+ return { none: false, data: periodText({ from, to }, unit, locale), missing, count };
153
+ }
154
+ var periodStart = (iso, unit) => unit === "year" ? `${iso.slice(0, 4)}-01-01` : unit === "month" ? `${iso.slice(0, 7)}-01` : iso;
155
+ function periodEnd(iso, unit) {
156
+ if (unit === "day") {
157
+ return iso;
158
+ }
159
+ const [y, m] = [Number(iso.slice(0, 4)), Number(iso.slice(5, 7))];
160
+ return isoDay(unit === "year" ? Date.UTC(y, 11, 31) : Date.UTC(y, m, 0));
161
+ }
162
+ function relativeText(f, labels, locale, timeZone, now, span) {
163
+ const key = f.count === 1 ? f.unit : `${f.unit}s`;
164
+ let text = fill(Object.hasOwn(labels.relative, key) ? labels.relative[key] : key, { count: f.count.toLocaleString(locale) });
165
+ const range = relativeDays(f, timeZone, now, span?.max);
166
+ if (!range) {
167
+ return text;
168
+ }
169
+ const latest = f.anchor === "latest";
170
+ if (latest) {
171
+ text = fill(labels.relativeTo, { text, end: periodText({ from: range.to, to: range.to }, f.unit, locale) });
172
+ }
173
+ const share = span ? rangeShare(range, f.unit, span, locale) : null;
174
+ if (!share) {
175
+ return latest ? text : fill(labels.withRange, { text, range: periodText(range, f.unit, locale) });
176
+ }
177
+ const lang = { lang: labels.lang, locale };
178
+ if (share.none) {
179
+ return fill(labels.withRange, { text, range: fill(plural(labels.noData, 1, lang), { range: periodText(range, f.unit, locale) }) });
180
+ }
181
+ return fill(labels.withShare, { text, range: share.data, missing: fill(plural(labels.noData, share.count, lang), { range: share.missing.join(", ") }) });
182
+ }
183
+ function wholeYears(from, to) {
184
+ const whole = typeof from === "string" && typeof to === "string" && /^\d{4}-01-01$/.test(from) && /^\d{4}-12-31$/.test(to);
185
+ return whole ? [from.slice(0, 4), to.slice(0, 4)] : null;
186
+ }
187
+ function compareText(f, labels, locale, { date, labelOf }) {
188
+ const shown = (v) => typeof v === "string" ? dayText(v, locale) : labelOf?.(v) ?? (date ? String(v) : v.toLocaleString(locale, { maximumFractionDigits: 6 }));
189
+ const forms = labels.compareShort;
190
+ if (f.op === "between" || f.op === "notBetween") {
191
+ const [from, to] = f.value2 !== void 0 && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
192
+ const years = wholeYears(from, to);
193
+ if (years) {
194
+ return years[0] === years[1] ? fill(forms[f.op === "between" ? "=" : "!="], { value: years[0] }) : fill(forms[f.op], { from: years[0], to: years[1] });
195
+ }
196
+ return fill(forms[f.op], { from: shown(from), to: shown(to) });
197
+ }
198
+ 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)}`;
199
+ }
200
+ function itemRuleText(f, labels, locale, { timeZone, date, labelOf, span }) {
201
+ if (f.type === "relative") {
202
+ return relativeText(
203
+ /** @type {any} */
204
+ f,
205
+ labels,
206
+ locale,
207
+ timeZone,
208
+ void 0,
209
+ span
210
+ );
211
+ }
212
+ if (f.type === "compare") {
213
+ return compareText(
214
+ /** @type {any} */
215
+ f,
216
+ labels,
217
+ locale,
218
+ { date, labelOf }
219
+ );
220
+ }
221
+ const op = String(f.op);
222
+ return `${Object.hasOwn(labels.labelOps, op) ? labels.labelOps[op] : op} ${fill(labels.quote, { text: f.value })}`;
223
+ }
49
224
  function groupingName(source, unit, labels, size) {
50
225
  const inName = labels.unitInName && Object.hasOwn(labels.unitInName, unit) ? labels.unitInName[unit] : labels.units[unit];
51
226
  return unit === "bin" ? fill(labels.binsName, { field: source, size }) : fill(labels.derivedName, { field: source, unit: inName ?? unit });
@@ -53,34 +228,18 @@ function groupingName(source, unit, labels, size) {
53
228
  var quickZone = (type) => type === "number" ? "values" : "rows";
54
229
  function fieldAction(field, type, zones, labels) {
55
230
  const zone = quickZone(type);
56
- const kind = zone === "values" ? "add" : zones.includes(zone) ? null : zones.some((z) => z === "cols" || z === "filters") ? "move" : "add";
231
+ const kind = zones.includes(zone) ? null : zone !== "values" && zones.some((z) => z === "cols" || z === "filters") ? "move" : "add";
57
232
  const name2 = zones.length ? `${field}, ${fill(labels.inZone, { zone: zones.map((z) => labels.zones[z] ?? z).join(", ") })}` : field;
58
233
  const description = kind === null ? "" : fill(kind === "move" ? labels.moveTo : labels.addTo, { zone: labels.zones[zone] });
59
234
  return { zone, kind, name: name2, description };
60
235
  }
61
236
  var SUMMARY_ORDER = Object.freeze(["rows", "cols", "values", "filters"]);
62
- function layoutSummary(entries, labels) {
63
- 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(", ") }));
64
- }
65
- function filterText(view, field, state, labels, locale) {
66
- const same2 = (f) => typeof f.field === "string" && f.field.toLowerCase() === field.toLowerCase();
67
- const parts = [];
68
- if (state && state.summary) {
69
- parts.push(fill(labels.filterSummary, { shown: state.summary.shown.toLocaleString(locale), total: state.summary.total.toLocaleString(locale) }));
70
- }
71
- for (const f of view.filters.filter(same2)) {
72
- if (f.type === "label") {
73
- const op = Object.hasOwn(labels.labelOps, f.op) ? labels.labelOps[f.op] : f.op;
74
- parts.push(`${op} \u201C${f.value}\u201D`);
75
- } else if (f.type === "value") {
76
- parts.push(valueConditionText(view, f, labels, locale));
77
- }
78
- }
79
- return parts.length ? fill(labels.filterIs, { filter: parts.join(", ") }) : null;
237
+ function layoutSummary(entries2, labels) {
238
+ 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(", ") }));
80
239
  }
81
240
 
82
241
  // src/drill.js
83
- import { cellRows, formatter, isFormat } from "pivotkit-core";
242
+ import { cellRows } from "pivotkit-core";
84
243
  var DRILL_LIMIT = 1e3;
85
244
  function decodeRow(encoded, i) {
86
245
  const row = {};
@@ -101,38 +260,6 @@ function drillRows(result, { rowPath = [], colPath = [], data = null, limit = DR
101
260
  }
102
261
  return { count: all.length, rows, indices };
103
262
  }
104
- var DATE_FORMATS = /* @__PURE__ */ new Set(["date", "datetime", "time"]);
105
- function columnText(column, { locale, labels, format }) {
106
- const spec = typeof format === "string" && isFormat(format) ? format.trim().toLowerCase() : null;
107
- if (column.type === "date") {
108
- const f = formatter(spec && DATE_FORMATS.has(spec.split(":")[0]) ? spec : column.dateOnly ? "date" : "datetime", { locale });
109
- return { text: f, numeric: false };
110
- }
111
- if (column.type === "number") {
112
- const nf = new Intl.NumberFormat(locale, { maximumFractionDigits: 6 });
113
- const f = spec && !DATE_FORMATS.has(spec.split(":")[0]) ? formatter(spec, { locale }) : (v) => nf.format(
114
- /** @type {number} */
115
- v
116
- );
117
- return { text: f, numeric: spec !== "text" };
118
- }
119
- if (column.type === "boolean") {
120
- return { text: (v) => v ? labels.true : labels.false, numeric: false };
121
- }
122
- return { text: (v) => String(v), numeric: false };
123
- }
124
- function drillTable(encoded, indices, { locale, labels, formatOf = () => void 0 }) {
125
- const cols = encoded.columns.map((column) => ({ column, ...columnText(column, { locale, labels, format: formatOf(column.name) }) }));
126
- const rows = Array.from(
127
- indices,
128
- (i) => cols.map(({ column, text }) => {
129
- const code = column.codes[i];
130
- const v = code < 0 ? null : column.dict[code];
131
- return v === null || v === void 0 ? "" : text(v);
132
- })
133
- );
134
- return { columns: cols.map((c) => ({ name: c.column.name, numeric: c.numeric })), rows };
135
- }
136
263
 
137
264
  // src/icons.jsx
138
265
  import React from "react";
@@ -146,6 +273,8 @@ var PATHS = {
146
273
  x: "M6 6l12 12M18 6 6 18",
147
274
  chevronDown: "m6 9 6 6 6-6",
148
275
  chevronRight: "m9 6 6 6-6 6",
276
+ arrowUp: "M12 19V5M6 11l6-6 6 6",
277
+ arrowDown: "M12 5v14M6 13l6 6 6-6",
149
278
  undo: "M9 14 4 9l5-5M4 9h10.5a5.5 5.5 0 0 1 0 11H11",
150
279
  redo: "m15 14 5-5-5-5M20 9H9.5a5.5 5.5 0 0 0 0 11H13",
151
280
  reset: "M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5",
@@ -176,8 +305,10 @@ var PATHS = {
176
305
  cols: "M6 4v16M12 4v16M18 4v16",
177
306
  sigma: "M18 5H6l6 7-6 7h12",
178
307
  info: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18ZM12 11v5M12 8h.01",
308
+ warn: "M12 4 2.8 20h18.4ZM12 10v4.5M12 17.5h.01",
179
309
  image: "M4 5h16v14H4zM4 16l5-5 4 4 3-3 4 4M15 9h.01",
180
310
  file: "M6 3h8l4 4v14H6zM14 3v4h4",
311
+ newFile: "M6 3h8l4 4v14H6zM14 3v4h4M12 11v6M9 14h6",
181
312
  swap: "M7 4 3 8l4 4M3 8h14M17 20l4-4-4-4M21 16H7",
182
313
  top: "M4 20v-6h5v6M9 20V8h6v12M15 20v-9h5v9M3 20h18",
183
314
  link: "M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",
@@ -365,6 +496,11 @@ import { createPortal } from "react-dom";
365
496
  // src/place.js
366
497
  var MARGIN = 8;
367
498
  var GAP = 6;
499
+ function viewportOf(doc) {
500
+ const root = doc.documentElement;
501
+ const win = doc.defaultView;
502
+ return { width: root?.clientWidth || win?.innerWidth || 0, height: root?.clientHeight || win?.innerHeight || 0 };
503
+ }
368
504
  function placePopover(anchor, size, viewport, align = "start", { fill: fill2 = false } = {}) {
369
505
  const below = viewport.height - anchor.bottom - GAP - MARGIN;
370
506
  const above = anchor.top - GAP - MARGIN;
@@ -383,6 +519,19 @@ function placePopover(anchor, size, viewport, align = "start", { fill: fill2 = f
383
519
  const top = side === "below" ? anchor.bottom + GAP : anchor.top - GAP - height;
384
520
  return { top: Math.max(MARGIN, top), left, maxHeight: Math.max(120, room), side };
385
521
  }
522
+ var KEEP_ROOM = 240;
523
+ function keepPlace(last, next, anchor, size, viewport) {
524
+ if (!last || last.anchorTop !== anchor.top || last.side === next.side) {
525
+ return next;
526
+ }
527
+ const room = last.side === "below" ? viewport.height - anchor.bottom - GAP - MARGIN : anchor.top - GAP - MARGIN;
528
+ if (room < Math.min(size.height, KEEP_ROOM)) {
529
+ return next;
530
+ }
531
+ const height = Math.min(size.height, room);
532
+ const top = last.side === "below" ? anchor.bottom + GAP : anchor.top - GAP - height;
533
+ return { ...next, top: Math.max(MARGIN, top), maxHeight: room, side: last.side };
534
+ }
386
535
  function fromOrigin(place, origin) {
387
536
  return { ...place, top: place.top - origin.top, left: place.left - origin.left };
388
537
  }
@@ -418,6 +567,10 @@ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start
418
567
  /** @type {HTMLDivElement | null} */
419
568
  null
420
569
  );
570
+ const ownId = useId();
571
+ const elId = id ?? ownId;
572
+ const parentId = anchor.current?.closest?.(".pk-popover")?.id;
573
+ const within = (n) => n === ref.current || n.getAttribute("data-pk-parent") === elId;
421
574
  const [pos, setPos] = useState(
422
575
  /** @type {null | { top: number, left: number, maxHeight: number, side: string }} */
423
576
  null
@@ -428,6 +581,7 @@ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start
428
581
  setPos(null);
429
582
  return void 0;
430
583
  }
584
+ let last = null;
431
585
  const place = () => {
432
586
  const el2 = ref.current;
433
587
  const a = anchor.current;
@@ -435,7 +589,10 @@ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start
435
589
  return;
436
590
  }
437
591
  const r = a.getBoundingClientRect();
438
- const place2 = placePopover(r, { width: el2.offsetWidth, height: el2.scrollHeight }, { width: window.innerWidth, height: window.innerHeight }, align, { fill: fill2 });
592
+ const size2 = { width: el2.offsetWidth, height: el2.scrollHeight };
593
+ const viewport = viewportOf(el2.ownerDocument);
594
+ const place2 = keepPlace(last, placePopover(r, size2, viewport, align, { fill: fill2 }), r, size2, viewport);
595
+ last = { top: place2.top, side: place2.side, anchorTop: r.top };
439
596
  const probe = layer?.querySelector(".pk-origin");
440
597
  setPos(probe ? fromOrigin(place2, probe.getBoundingClientRect()) : place2);
441
598
  };
@@ -464,13 +621,13 @@ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start
464
621
  }
465
622
  const el = ref.current;
466
623
  const shown = (o) => o.getClientRects().length > 0;
467
- const first = el?.querySelector("[data-autofocus]") ?? [...el?.querySelectorAll(OPTION) ?? []].find(shown) ?? [...el?.querySelectorAll(FOCUSABLE) ?? []].find(shown);
624
+ const first = el?.querySelector("[data-autofocus]") ?? [...el?.querySelectorAll(OPTION) ?? []].find(shown) ?? [...el?.querySelectorAll(FOCUSABLE) ?? []].find((o) => shown(o) && !o.classList.contains("pk-info")) ?? (el?.querySelector("[data-pk-option]") ? el : null);
468
625
  const t = requestAnimationFrame(() => (
469
626
  /** @type {HTMLElement | null} */
470
627
  first?.focus({ preventScroll: true })
471
628
  ));
472
629
  const onDown = (e) => {
473
- if (!eventWithin(e, [el, anchor.current])) {
630
+ if (!eventWithin(e, [el, anchor.current]) && !e.composedPath().some((n) => n instanceof Element && n !== el && n.getAttribute("data-pk-parent") === elId)) {
474
631
  closeRef.current();
475
632
  }
476
633
  };
@@ -492,7 +649,7 @@ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start
492
649
  button.focus({ preventScroll: true });
493
650
  }
494
651
  };
495
- }, [open, anchor, passive]);
652
+ }, [open, anchor, passive, elId]);
496
653
  if (!open || !layer) {
497
654
  return null;
498
655
  }
@@ -527,7 +684,7 @@ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start
527
684
  /** @type {Node | null} */
528
685
  e.relatedTarget
529
686
  );
530
- if (to && !ref.current?.contains(to) && !anchor.current?.contains(to)) {
687
+ if (to && !ref.current?.contains(to) && !anchor.current?.contains(to) && !(to instanceof Element && [...to.ownerDocument.querySelectorAll(".pk-popover")].some((p) => p.contains(to) && within(p)))) {
531
688
  onClose();
532
689
  }
533
690
  };
@@ -540,7 +697,8 @@ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start
540
697
  "div",
541
698
  {
542
699
  ref,
543
- id,
700
+ id: elId,
701
+ "data-pk-parent": parentId,
544
702
  role,
545
703
  "aria-label": passive ? void 0 : label,
546
704
  "aria-modal": sheet && role === "dialog" ? true : void 0,
@@ -557,7 +715,7 @@ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start
557
715
  layer
558
716
  );
559
717
  }
560
- function MenuButton({ label, icon, text, showText = true, className, role = "menu", align, popoverClass, disabled, title, children, testId, buttonRef, name: name2, tabIndex, slot, fill: fill2 }) {
718
+ function MenuButton({ label, icon, text, showText = true, className, role = "menu", align, popoverClass, disabled, title, children, testId, buttonRef, name: name2, tabIndex, slot, fill: fill2, mark }) {
561
719
  const [open, setOpen] = useState(false);
562
720
  const own = useRef3(
563
721
  /** @type {HTMLButtonElement | null} */
@@ -588,10 +746,11 @@ function MenuButton({ label, icon, text, showText = true, className, role = "men
588
746
  icon
589
747
  ) }) : null,
590
748
  showText && text ? /* @__PURE__ */ React3.createElement("span", { className: "pk-btn-text" }, text) : null,
749
+ mark,
591
750
  showText && text ? /* @__PURE__ */ React3.createElement(Icon, { name: "chevronDown", size: 14, className: "pk-caret" }) : null
592
751
  ), /* @__PURE__ */ React3.createElement(Popover, { open, anchor: ref, onClose: close, label, role, align, className: popoverClass, id, fill: fill2 }, children(close)));
593
752
  }
594
- function Option({ onSelect, icon, checked, children, hint, reason, inMenu = false, disabled, danger, tone, testId }) {
753
+ function Option({ onSelect, icon, checked, children, hint, reason, inMenu = false, disabled, danger, tone, testId, current }) {
595
754
  const second = disabled && reason ? reason : hint;
596
755
  const role = inMenu ? checked === void 0 ? "menuitem" : "menuitemradio" : void 0;
597
756
  return /* @__PURE__ */ React3.createElement(
@@ -601,13 +760,14 @@ function Option({ onSelect, icon, checked, children, hint, reason, inMenu = fals
601
760
  role,
602
761
  "aria-checked": inMenu && checked !== void 0 ? checked : void 0,
603
762
  "aria-pressed": !inMenu && checked !== void 0 ? checked : void 0,
763
+ "aria-current": current ? "true" : void 0,
604
764
  className: `pk-option${checked ? " pk-checked" : ""}${danger ? " pk-danger" : ""}${tone === "accent" ? " pk-accent" : ""}`,
605
765
  "data-pk-option": "",
606
766
  "data-testid": testId,
607
767
  disabled,
608
768
  onClick: onSelect
609
769
  },
610
- /* @__PURE__ */ React3.createElement("span", { className: "pk-option-icon" }, checked ? /* @__PURE__ */ React3.createElement(Icon, { name: "check" }) : icon ? /* @__PURE__ */ React3.createElement(Icon, { name: (
770
+ /* @__PURE__ */ React3.createElement("span", { className: "pk-option-icon" }, checked || current ? /* @__PURE__ */ React3.createElement(Icon, { name: "check" }) : icon ? /* @__PURE__ */ React3.createElement(Icon, { name: (
611
771
  /** @type {any} */
612
772
  icon
613
773
  ) }) : null),
@@ -725,7 +885,7 @@ function InfoButton({ info, name: name2, labels, className, testId = "field-info
725
885
  }
726
886
 
727
887
  // src/view-ops.js
728
- import { LIMITS, aggregatorsFor, isFormat as isFormat2 } from "pivotkit-core";
888
+ import { LIMITS, aggregatorsFor, isFormat } from "pivotkit-core";
729
889
  var ZONES = Object.freeze(
730
890
  /** @type {Zone[]} */
731
891
  ["filters", "cols", "rows", "values"]
@@ -807,7 +967,7 @@ function addField(view, field, zone, options = {}) {
807
967
  }
808
968
  } else if (zone === "values") {
809
969
  const wanted = options.defaults ?? {};
810
- const format = typeof wanted.format === "string" && isFormat2(wanted.format) ? wanted.format : null;
970
+ const format = typeof wanted.format === "string" && isFormat(wanted.format) ? wanted.format : null;
811
971
  next.values.splice(clamp(options.index, next.values.length), 0, { field, agg: defaultAgg(options.type, wanted.agg), format, label: null, showAs: null, conditional: null });
812
972
  } else if (zone === "filters") {
813
973
  dropFromAxes(next, field);
@@ -883,31 +1043,6 @@ function reorder(view, zone, from, to) {
883
1043
  resetCollapsed(next, view);
884
1044
  return next;
885
1045
  }
886
- var COUNTING = /* @__PURE__ */ new Set(["count", "countUnique", "listUnique"]);
887
- var unitOf = (agg) => COUNTING.has(agg) ? "count" : "field";
888
- function updateValue(view, index, patch, options = {}) {
889
- const next = clone(view);
890
- if (!next.values[index]) {
891
- return view;
892
- }
893
- const before = view.values[index];
894
- const value = { ...next.values[index], ...patch };
895
- if (patch.agg && patch.agg !== before.agg) {
896
- value.showAs = patch.showAs ?? null;
897
- const wanted = options.defaults ?? {};
898
- const hostFormat = typeof wanted.format === "string" && isFormat2(wanted.format) ? wanted.format : null;
899
- const own = before.format && before.format !== hostFormat ? before.format : null;
900
- if (patch.format !== void 0) {
901
- value.format = patch.format;
902
- } else if (own) {
903
- value.format = unitOf(before.agg) === unitOf(patch.agg) ? own : null;
904
- } else {
905
- value.format = hostFormat && unitOf(typeof wanted.agg === "string" ? wanted.agg : "sum") === unitOf(patch.agg) ? hostFormat : null;
906
- }
907
- }
908
- next.values[index] = value;
909
- return next;
910
- }
911
1046
  function numberRange(encoded, field) {
912
1047
  const column = encoded.column(field);
913
1048
  if (!column || column.type !== "number") {
@@ -923,19 +1058,20 @@ function numberRange(encoded, field) {
923
1058
  }
924
1059
  return min <= max ? { min, max } : null;
925
1060
  }
926
- function binProblem(size, start, range) {
927
- if (!range) {
1061
+ function dateSpan(encoded, field) {
1062
+ const column = encoded.column(field);
1063
+ if (!column || column.type !== "date") {
928
1064
  return null;
929
1065
  }
930
- for (const v of [range.min, range.max]) {
931
- const k = Math.floor((v - start) / size);
932
- const low = start + k * size;
933
- const slack = size * 1e-9;
934
- if (!Number.isSafeInteger(k) || low + size === low || low > v + slack || v >= low + size + slack) {
935
- return "far";
1066
+ let min = Infinity;
1067
+ let max = -Infinity;
1068
+ for (const v of column.dict) {
1069
+ if (typeof v === "number") {
1070
+ min = Math.min(min, v);
1071
+ max = Math.max(max, v);
936
1072
  }
937
1073
  }
938
- return null;
1074
+ return min <= max ? { min, max } : null;
939
1075
  }
940
1076
  function groupField(view, field, unit, options = {}) {
941
1077
  const spec = view.derived.find((d) => same(d.name, field));
@@ -1005,47 +1141,41 @@ function withHostOrders(view, orderOf) {
1005
1141
  function sortOf(view, field) {
1006
1142
  return view.sort.find((s) => same(s.field, field)) ?? null;
1007
1143
  }
1008
- function filtersOf(view, field, types) {
1009
- return view.filters.filter((f) => same(f.field, field) && (!types || types.includes(f.type)));
1144
+ function sortEntry(spec, hostOrdered) {
1145
+ return spec.by === "label" && spec.order === "asc" && !hostOrdered ? null : spec;
1010
1146
  }
1011
- function replaceFilters(view, field, types, entries) {
1012
- const next = clone(view);
1013
- const index = next.filters.findIndex((f) => same(f.field, field));
1014
- const kept = next.filters.filter((f) => !(same(f.field, field) && types.includes(f.type)));
1015
- const at = index === -1 ? kept.length : Math.min(index, kept.length);
1016
- kept.splice(at, 0, ...entries);
1017
- next.filters = kept;
1018
- if (!axisOf(next, field) && filterZoneFields(view).some((f) => same(f, field)) && !kept.some((f) => same(f.field, field))) {
1019
- next.filters.splice(at, 0, { field, type: "exclude", items: [] });
1147
+ function headerSortTarget(view, cell, typeOf) {
1148
+ if (cell.kind === "corner") {
1149
+ return cell.field && view.rows.some((f) => same(f, cell.field)) ? { field: cell.field } : null;
1020
1150
  }
1021
- return next;
1151
+ const spec = cell.kind === "colHeader" && cell.valueIndex !== void 0 && !cell.colPath?.length ? view.values[cell.valueIndex] : void 0;
1152
+ if (!spec || !view.rows.length || !numericResult(spec, spec.field ? typeOf(spec.field) ?? "string" : "number")) {
1153
+ return null;
1154
+ }
1155
+ return { field: view.rows[view.rows.length - 1], ref: { field: spec.field ?? null, agg: spec.agg } };
1022
1156
  }
1023
- function replaceFilter(view, field, previous, entry) {
1024
- const next = clone(view);
1025
- const key = previous ? JSON.stringify(previous) : null;
1026
- const at = key === null ? -1 : next.filters.findIndex((f) => same(f.field, field) && JSON.stringify(f) === key);
1027
- if (at === -1) {
1028
- if (!entry) {
1029
- return next;
1030
- }
1031
- const last = next.filters.map((f) => same(f.field, field)).lastIndexOf(true);
1032
- next.filters.splice(last + 1, 0, entry);
1033
- return next;
1157
+ function headerSortState(view, target) {
1158
+ const s = sortOf(view, target.field);
1159
+ const word = (order) => order === "desc" ? "descending" : "ascending";
1160
+ if (target.ref) {
1161
+ return s?.by === "value" && sameRef(s.value, target.ref) ? { order: word(s.order), chosen: true } : { order: null, chosen: false };
1034
1162
  }
1035
- if (entry) {
1036
- next.filters[at] = entry;
1037
- } else {
1038
- next.filters.splice(at, 1);
1039
- if (!axisOf(next, field) && filterZoneFields(view).some((f) => same(f, field)) && !next.filters.some((f) => same(f.field, field))) {
1040
- next.filters.splice(at, 0, { field, type: "exclude", items: [] });
1041
- }
1163
+ if (!s) {
1164
+ return { order: "ascending", chosen: false };
1042
1165
  }
1043
- return next;
1166
+ return { order: s.by === "label" ? word(s.order) : s.by === "custom" ? "other" : null, chosen: s.by === "label" };
1044
1167
  }
1045
- function setItemFilter(view, field, selected, all) {
1046
- const keep = new Set(selected.map((v) => JSON.stringify(v)));
1047
- const excluded = all.filter((v) => !keep.has(JSON.stringify(v)));
1048
- return replaceFilters(view, field, ["include", "exclude"], excluded.length ? [{ field, type: "exclude", items: excluded }] : []);
1168
+ function nextHeaderSort(view, target, hostOrdered) {
1169
+ const s = sortOf(view, target.field);
1170
+ if (target.ref) {
1171
+ const mine = s?.by === "value" && sameRef(s.value, target.ref);
1172
+ return mine && s.order === "asc" ? null : { by: "value", order: mine ? "asc" : "desc", value: mine ? s.value : target.ref };
1173
+ }
1174
+ const desc = !s || s.by === "label" && s.order === "asc";
1175
+ return sortEntry({ by: "label", order: desc ? "desc" : "asc" }, hostOrdered);
1176
+ }
1177
+ function filtersOf(view, field, types) {
1178
+ return view.filters.filter((f) => same(f.field, field) && (!types || types.includes(f.type)));
1049
1179
  }
1050
1180
  function selectedItems(view, field, all) {
1051
1181
  let selected = all;
@@ -1055,53 +1185,12 @@ function selectedItems(view, field, all) {
1055
1185
  }
1056
1186
  return selected;
1057
1187
  }
1058
- function setLabelFilter(view, field, condition) {
1059
- return replaceFilters(view, field, ["label"], condition && condition.value !== "" ? [{ field, type: "label", op: condition.op, value: condition.value }] : []);
1060
- }
1061
- function setTopFilter(view, field, top, previous) {
1062
- const entry = top ? { field, type: "top", count: top.count, bottom: Boolean(top.bottom), ...top.by ? { by: top.by } : {} } : null;
1063
- if (previous) {
1064
- return replaceFilter(view, field, previous, entry);
1065
- }
1066
- return replaceFilters(view, field, ["top"], entry ? [entry] : []);
1067
- }
1068
- function setValueFilter(view, field, condition, previous) {
1069
- let entry = null;
1070
- if (condition) {
1071
- const { by, op, value, value2 } = condition;
1072
- const between = op === "between" || op === "notBetween";
1073
- entry = { field, type: "value", by: { field: by.field, agg: by.agg }, op, value, ...between ? { value2 } : {} };
1074
- }
1075
- if (previous) {
1076
- return replaceFilter(view, field, previous, entry);
1077
- }
1078
- return replaceFilters(view, field, ["value"], entry ? [entry] : []);
1079
- }
1080
1188
  function numericResult(spec, type) {
1081
1189
  return spec.agg !== "listUnique" && !(["first", "last"].includes(spec.agg) && type !== "number") && !(type === "date" && ["average", "median", "min", "max"].includes(spec.agg));
1082
1190
  }
1083
- function withMeasure(choices, ref) {
1084
- return ref && !choices.some((c) => sameRef(c, ref)) ? [...choices, { field: ref.field ?? null, agg: ref.agg }] : choices;
1085
- }
1086
1191
  function sameRef(a, b) {
1087
1192
  return Boolean(a && b) && a.agg === b.agg && (a.field === null || b.field === null ? a.field === b.field : same(a.field, b.field));
1088
1193
  }
1089
- function measureChoices(view, typeOf) {
1090
- const out = [];
1091
- for (const v of view.values) {
1092
- const ref = { field: v.field ?? null, agg: v.agg };
1093
- if (numericResult(v, v.field ? typeOf(v.field) ?? "string" : "number") && !out.some((r) => sameRef(r, ref))) {
1094
- out.push(ref);
1095
- }
1096
- }
1097
- return out.length ? out : [{ field: null, agg: "count" }];
1098
- }
1099
- function removeFilters(view, field) {
1100
- return replaceFilters(view, field, ["include", "exclude", "label", "value"], []);
1101
- }
1102
- function hasFilter(view, field) {
1103
- return filtersOf(view, field, ["include", "exclude", "label", "value"]).some((f) => f.type !== "exclude" || f.items.length > 0);
1104
- }
1105
1194
  function isFiltered(view, field) {
1106
1195
  return filtersOf(view, field).some((f) => f.type !== "exclude" || f.items.length > 0);
1107
1196
  }
@@ -1128,6 +1217,7 @@ function rowFolding(view, outer) {
1128
1217
  canCollapse,
1129
1218
  collapsed: view.collapsed.rows.length,
1130
1219
  open,
1220
+ // keys of the menus' texts (menu-labels.js): the Options menu shows them with its labels
1131
1221
  why: {
1132
1222
  expand: canExpand ? null : "expandNothing",
1133
1223
  collapse: canCollapse ? null : view.rows.length < 2 ? "collapseNeedsRows" : "collapseAllDone"
@@ -1139,19 +1229,6 @@ function setCollapsed(view, axis, paths) {
1139
1229
  next.collapsed[axis] = paths ? paths : [];
1140
1230
  return next;
1141
1231
  }
1142
- var TOTALS = Object.freeze(["grandTotalRow", "grandTotalColumn", "rowSubtotals", "colSubtotals"]);
1143
- function totalNoEffect(view, key) {
1144
- if (key === "grandTotalRow") {
1145
- return view.rows.length >= 1 ? null : "needsRowField";
1146
- }
1147
- if (key === "grandTotalColumn") {
1148
- return view.cols.length >= 1 ? null : "needsColField";
1149
- }
1150
- if (key === "rowSubtotals") {
1151
- return view.rows.length >= 2 ? null : "needsRowFields";
1152
- }
1153
- return view.cols.length >= 2 ? null : "needsColFields";
1154
- }
1155
1232
  function setTotal(view, key, on) {
1156
1233
  const next = clone(view);
1157
1234
  next.totals[key] = Boolean(on);
@@ -1193,115 +1270,118 @@ function swapAxes(view) {
1193
1270
  function isEmptyView(view) {
1194
1271
  return view.rows.length === 0 && view.cols.length === 0 && view.values.length === 0;
1195
1272
  }
1196
- function conditionKind(encoded, view, field) {
1197
- const type = encoded.column(sourceOf(view, field))?.type ?? "string";
1198
- return type === "date" || type === "boolean" ? null : type === "number" ? "number" : "text";
1199
- }
1200
1273
 
1201
- // src/files.js
1202
- var UNSAFE = /[<>:"/\\|?*\u0000-\u001F\u007F]+/g;
1203
- var RESERVED = /^(con|prn|aux|nul|com\d|lpt\d)$/i;
1204
- function safeFileName(name2) {
1205
- const text = typeof name2 === "string" ? name2 : "";
1206
- const cleaned = trimEnd(text.replace(UNSAFE, "-").replace(/^[\s.-]+/, "").slice(0, 120));
1207
- return cleaned && !RESERVED.test(cleaned) ? cleaned : "pivot";
1208
- }
1209
- function trimEnd(text) {
1210
- let end = text.length;
1211
- while (end > 0 && (text[end - 1] === "." || /\s/.test(text[end - 1]))) {
1212
- end--;
1213
- }
1214
- return text.slice(0, end);
1215
- }
1216
- function dataUrlToBlob(url) {
1217
- const match = /^data:([^,;]*)((?:;[^,;]*)*?)(;base64)?,(.*)$/s.exec(url);
1218
- if (!match) {
1219
- throw new TypeError("not a data: URL");
1220
- }
1221
- const type = match[1] || "application/octet-stream";
1222
- if (match[3]) {
1223
- const bin = atob(match[4]);
1224
- const bytes = new Uint8Array(bin.length);
1225
- for (let i = 0; i < bin.length; i++) {
1226
- bytes[i] = bin.charCodeAt(i);
1274
+ // src/help.js
1275
+ import { createContext as createContext2 } from "react";
1276
+ var HelpContext = createContext2(
1277
+ /** @type {Help} */
1278
+ { explain: true, labels: null }
1279
+ );
1280
+
1281
+ // src/share.js
1282
+ import { VIEW_FILE_LIMITS, fromViewFile, normalize } from "pivotkit-core";
1283
+ var linkModule = null;
1284
+ var linkLoaded = null;
1285
+ function loadLink() {
1286
+ linkModule ??= import("pivotkit-core/link").then((m) => {
1287
+ linkLoaded = m;
1288
+ return m;
1289
+ });
1290
+ return linkModule;
1291
+ }
1292
+ var linkNow = () => linkLoaded;
1293
+ function linkParam(storageKey) {
1294
+ return storageKey ? `pivot-${storageKey}` : "pivot";
1295
+ }
1296
+ var entries = (fragment) => fragment ? fragment.split("&") : [];
1297
+ var isEntry = (entry, param) => entry.startsWith(`${encodeURIComponent(param)}=`);
1298
+ function readLinkParam(hash, param) {
1299
+ const text = typeof hash === "string" ? hash.replace(/^#/, "") : "";
1300
+ const entry = entries(text).find((e) => isEntry(e, param));
1301
+ const value = entry ? entry.slice(encodeURIComponent(param).length + 1) : "";
1302
+ return value ? value : null;
1303
+ }
1304
+ function withLinkParam(url, param, encoded) {
1305
+ const at = url.indexOf("#");
1306
+ const base = at === -1 ? url : url.slice(0, at);
1307
+ const kept = entries(at === -1 ? "" : url.slice(at + 1)).filter((e) => !isEntry(e, param));
1308
+ const next = encoded ? [...kept, `${encodeURIComponent(param)}=${encoded}`] : kept;
1309
+ return next.length ? `${base}#${next.join("&")}` : base;
1310
+ }
1311
+ function shareBase(shareLink, here) {
1312
+ if (shareLink === true) {
1313
+ if (!here) {
1314
+ return null;
1227
1315
  }
1228
- return new Blob([bytes], { type });
1229
- }
1230
- return new Blob([decodeURIComponent(match[4])], { type });
1231
- }
1232
- function saveBlob(blob, name2, doc = document) {
1233
- const url = URL.createObjectURL(blob);
1234
- const a = doc.createElement("a");
1235
- a.href = url;
1236
- a.download = name2;
1237
- a.rel = "noopener";
1238
- doc.body.appendChild(a);
1239
- a.click();
1240
- a.remove();
1241
- setTimeout(() => URL.revokeObjectURL(url), 1e4);
1242
- }
1243
- async function copyText(text, container) {
1244
- try {
1245
- if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
1246
- await navigator.clipboard.writeText(text);
1247
- return true;
1316
+ try {
1317
+ const url = new URL(here);
1318
+ return `${url.origin}${url.pathname}${url.hash}`;
1319
+ } catch {
1320
+ return null;
1248
1321
  }
1322
+ }
1323
+ return typeof shareLink === "string" && shareLink.trim() ? shareLink.trim() : null;
1324
+ }
1325
+ var viewStorageName = (key) => `pivotkit:view:${key ?? ""}`;
1326
+ function readStoredView(key, storage) {
1327
+ if (!storage) {
1328
+ return null;
1329
+ }
1330
+ try {
1331
+ return storage.getItem(viewStorageName(key));
1249
1332
  } catch {
1333
+ return null;
1334
+ }
1335
+ }
1336
+ function writeStoredView(key, storage, view) {
1337
+ if (!storage) {
1338
+ return;
1250
1339
  }
1251
- if (!container) {
1252
- return false;
1253
- }
1254
- const doc = container.ownerDocument;
1255
- const field = doc.createElement("textarea");
1256
- field.value = text;
1257
- field.readOnly = true;
1258
- field.className = "pk-sr";
1259
- const before = (
1260
- /** @type {HTMLElement | null} */
1261
- container.getRootNode() instanceof ShadowRoot ? (
1262
- /** @type {ShadowRoot} */
1263
- container.getRootNode().activeElement
1264
- ) : doc.activeElement
1265
- );
1266
- container.appendChild(field);
1267
- let ok;
1268
1340
  try {
1269
- field.select();
1270
- ok = typeof doc.execCommand === "function" && doc.execCommand("copy");
1341
+ storage.setItem(viewStorageName(key), JSON.stringify(view));
1271
1342
  } catch {
1272
- ok = false;
1273
1343
  }
1274
- field.remove();
1275
- before?.focus?.({ preventScroll: true });
1276
- return ok;
1277
1344
  }
1278
-
1279
- // src/section.jsx
1280
- import React5, { createContext as createContext2, useContext as useContext2, useId as useId3 } from "react";
1281
- var HelpContext = createContext2(
1282
- /** @type {Help} */
1283
- { explain: true, isOpen: () => true, setOpen: () => {
1284
- }, labels: null }
1285
- );
1286
- function SettingInfo({ id, name: name2 }) {
1287
- const { explain, labels } = useContext2(HelpContext);
1288
- const text = labels && labels.settingInfo && Object.hasOwn(labels.settingInfo, id) ? labels.settingInfo[id] : null;
1289
- if (!explain || !labels || !text) {
1290
- return null;
1345
+ var VIEW_TEXT_MAX = VIEW_FILE_LIMITS.text;
1346
+ var quoteNames = (names, labels) => {
1347
+ const shown = names.slice(0, 5).map((n) => fill(labels.quote, { text: n.length > 60 ? `${n.slice(0, 59)}\u2026` : n })).join(", ");
1348
+ return names.length > 5 ? `${shown} \u2026` : shown;
1349
+ };
1350
+ var FAILED = Object.freeze({ newerFormat: "newer", newerView: "newer" });
1351
+ function viewFromText(text, encoded, options = {}) {
1352
+ return viewFromObject(text, encoded, options);
1353
+ }
1354
+ function viewFromObject(input, encoded, options = {}) {
1355
+ const file = fromViewFile(input, { data: encoded, sourceId: options.sourceId });
1356
+ if (file.failed || !file.view) {
1357
+ const failed = file.failed ?? "notView";
1358
+ return { view: null, issues: file.issues, failed: Object.hasOwn(FAILED, failed) ? FAILED[failed] : failed, file };
1359
+ }
1360
+ const { view, issues } = normalize(file.view, encoded, options.limits ? { limits: options.limits } : void 0);
1361
+ if (issues.some((i) => i.path === "version")) {
1362
+ return { view: null, issues, failed: "newer", file };
1291
1363
  }
1292
- return /* @__PURE__ */ React5.createElement(InfoButton, { info: { description: text }, name: name2, label: fill(labels.aboutSetting, { setting: name2 }), labels, className: "pk-setting-info", testId: `setting-info-${id}` });
1364
+ return { view, issues, failed: null, file };
1293
1365
  }
1294
- function Section({ title, children, id, info }) {
1295
- const titleId = useId3();
1296
- const bodyId = useId3();
1297
- const { isOpen, setOpen } = useContext2(HelpContext);
1298
- const name2 = typeof title === "string" ? title : "";
1299
- const infoButton = info ? /* @__PURE__ */ React5.createElement(SettingInfo, { id: info, name: name2 }) : null;
1300
- if (!id) {
1301
- return /* @__PURE__ */ React5.createElement("div", { className: "pk-section", role: "group", "aria-labelledby": titleId }, /* @__PURE__ */ React5.createElement("div", { className: "pk-section-head" }, /* @__PURE__ */ React5.createElement("div", { className: "pk-section-title", id: titleId }, title), infoButton), children);
1366
+ function loadCheck(loaded, labels, sources = []) {
1367
+ const fit = loaded.file?.compatible;
1368
+ if (!loaded.view || !fit || fit.ok) {
1369
+ return null;
1370
+ }
1371
+ const lines2 = [];
1372
+ const fileSource = loaded.file?.source;
1373
+ const target = fit.source === "other" && fileSource?.id ? sources.find((s) => s && s.id === fileSource.id) : void 0;
1374
+ if (fit.source === "other") {
1375
+ const name2 = target?.name || fileSource?.name || fileSource?.id;
1376
+ lines2.push(name2 ? fill(labels.loadCheckSource, { source: name2 }) : labels.loadCheckOtherSource);
1302
1377
  }
1303
- const open = isOpen(id);
1304
- return /* @__PURE__ */ React5.createElement("div", { className: `pk-section${open ? "" : " pk-folded"}`, role: "group", "aria-labelledby": titleId, "data-section": id }, /* @__PURE__ */ React5.createElement("div", { className: "pk-section-head" }, /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-section-title pk-section-toggle", id: titleId, "aria-expanded": open, "aria-controls": bodyId, onClick: () => setOpen(id, !open), "data-testid": `section-${id}` }, /* @__PURE__ */ React5.createElement(Icon, { name: open ? "chevronDown" : "chevronRight", size: 14 }), /* @__PURE__ */ React5.createElement("span", null, title)), infoButton), /* @__PURE__ */ React5.createElement("div", { id: bodyId, className: "pk-section-body", hidden: !open }, children));
1378
+ if (fit.missing.length) {
1379
+ lines2.push(fill(labels.loadCheckMissing, { fields: quoteNames(fit.missing, labels) }));
1380
+ }
1381
+ if (fit.changed.length) {
1382
+ lines2.push(fill(labels.loadCheckChanged, { fields: quoteNames(fit.changed.map((c) => c.name), labels) }));
1383
+ }
1384
+ return { lines: lines2, switchTo: target ? { id: target.id, name: target.name || target.id } : null };
1305
1385
  }
1306
1386
 
1307
1387
  // src/storage.js
@@ -1570,50 +1650,7 @@ var SWITCHES = Object.freeze([ALL_TIPS, NO_EXPLANATIONS, FIELDS_COLLAPSED]);
1570
1650
  function fieldsCollapsed(session, forced, dismissed) {
1571
1651
  return session ?? (forced === "collapsed" || forced === "open" ? forced === "collapsed" : dismissed.includes(FIELDS_COLLAPSED));
1572
1652
  }
1573
- var SECTIONS = Object.freeze({
1574
- // a value's menu
1575
- summarize: true,
1576
- showAs: true,
1577
- format: false,
1578
- highlight: false,
1579
- name: false,
1580
- valueFilters: false,
1581
- move: false,
1582
- // a field's menu on Rows or Columns
1583
- sort: true,
1584
- groupBy: true,
1585
- bins: true,
1586
- topN: true,
1587
- filters: true,
1588
- // the toolbar's menus
1589
- totals: true,
1590
- folding: true,
1591
- help: true,
1592
- // the Export menus (the toolbar's and the drill-down's)
1593
- exportDownload: true,
1594
- exportCopy: true,
1595
- sharedViews: true,
1596
- myViews: true,
1597
- share: true,
1598
- chartType: true,
1599
- chartDisplay: true
1600
- });
1601
- function sectionOpen(id, dismissed) {
1602
- if (dismissed.includes(`open:${id}`)) {
1603
- return true;
1604
- }
1605
- if (dismissed.includes(`closed:${id}`)) {
1606
- return false;
1607
- }
1608
- return Object.hasOwn(SECTIONS, id) ? SECTIONS[id] : true;
1609
- }
1610
- function withSection(dismissed, id, open) {
1611
- const rest = dismissed.filter((d) => d !== `open:${id}` && d !== `closed:${id}`);
1612
- const def = Object.hasOwn(SECTIONS, id) ? SECTIONS[id] : true;
1613
- return open === def ? rest : [...rest, `${open ? "open" : "closed"}:${id}`];
1614
- }
1615
- var isSection = (id) => /^(open|closed):/.test(id) && Object.hasOwn(SECTIONS, id.slice(id.indexOf(":") + 1));
1616
- var keptOnReset = (id) => SWITCHES.includes(id) || isSection(id);
1653
+ var keptOnReset = (id) => SWITCHES.includes(id);
1617
1654
  function helpSwitch(forced, dismissed, off = NO_EXPLANATIONS) {
1618
1655
  if (forced === "on" || forced === "off") {
1619
1656
  return { on: forced === "on", user: false };
@@ -1704,7 +1741,7 @@ function allowedTips(value) {
1704
1741
  return list.map((id) => String(id).trim()).filter((id) => TIP_IDS.includes(id));
1705
1742
  }
1706
1743
  function cleanDismissed(value) {
1707
- return Array.isArray(value) ? [...new Set(value.filter((id) => typeof id === "string" && (SWITCHES.includes(id) || TIP_IDS.includes(id) || isSection(id))))] : [];
1744
+ return Array.isArray(value) ? [...new Set(value.filter((id) => typeof id === "string" && (SWITCHES.includes(id) || TIP_IDS.includes(id))))] : [];
1708
1745
  }
1709
1746
  var storageName = (key) => `pivotkit:tips:${key}`;
1710
1747
  function readStored(key, storage) {
@@ -1734,17 +1771,30 @@ function withoutFilters(view) {
1734
1771
  }
1735
1772
 
1736
1773
  export {
1774
+ CHART_TYPES,
1775
+ SLICE_TYPES,
1776
+ CHART_TYPE_NAMES,
1777
+ chartTypeOf,
1778
+ chartPlan,
1779
+ MAX_CATEGORIES,
1737
1780
  valueLabel,
1738
1781
  refLabel,
1782
+ sortText,
1739
1783
  valueConditionText,
1784
+ dayText,
1785
+ isoDay,
1786
+ relativeDays,
1787
+ periodText,
1788
+ rangeShare,
1789
+ relativeText,
1790
+ wholeYears,
1791
+ itemRuleText,
1740
1792
  groupingName,
1741
1793
  fieldAction,
1742
1794
  layoutSummary,
1743
- filterText,
1744
1795
  DRILL_LIMIT,
1745
1796
  decodeRow,
1746
1797
  drillRows,
1747
- drillTable,
1748
1798
  Icon,
1749
1799
  TYPE_ICON,
1750
1800
  ZONE_ICON,
@@ -1757,55 +1807,54 @@ export {
1757
1807
  Popover,
1758
1808
  MenuButton,
1759
1809
  Option,
1760
- FieldDescription,
1761
1810
  InfoButton,
1762
1811
  ZONES,
1812
+ clone,
1813
+ same,
1763
1814
  filterZoneFields,
1815
+ axisOf,
1764
1816
  zoneOverLimit,
1765
1817
  addField,
1766
1818
  removeAt,
1767
1819
  moveField,
1768
1820
  reorder,
1769
- updateValue,
1770
1821
  numberRange,
1771
- binProblem,
1822
+ dateSpan,
1772
1823
  groupField,
1773
1824
  groupingOf,
1774
1825
  sourceOf,
1775
1826
  setSort,
1776
1827
  withHostOrders,
1777
1828
  sortOf,
1829
+ sortEntry,
1830
+ headerSortTarget,
1831
+ headerSortState,
1832
+ nextHeaderSort,
1778
1833
  filtersOf,
1779
- setItemFilter,
1780
1834
  selectedItems,
1781
- setLabelFilter,
1782
- setTopFilter,
1783
- setValueFilter,
1784
1835
  numericResult,
1785
- withMeasure,
1786
1836
  sameRef,
1787
- measureChoices,
1788
- removeFilters,
1789
- hasFilter,
1790
1837
  toggleCollapsed,
1791
1838
  rowFolding,
1792
1839
  setCollapsed,
1793
- TOTALS,
1794
- totalNoEffect,
1795
1840
  setTotal,
1796
1841
  setDisplay,
1797
1842
  setChart,
1798
1843
  setChartDisplay,
1799
1844
  swapAxes,
1800
1845
  isEmptyView,
1801
- conditionKind,
1802
- safeFileName,
1803
- dataUrlToBlob,
1804
- saveBlob,
1805
- copyText,
1806
1846
  HelpContext,
1807
- SettingInfo,
1808
- Section,
1847
+ loadLink,
1848
+ linkNow,
1849
+ linkParam,
1850
+ readLinkParam,
1851
+ withLinkParam,
1852
+ shareBase,
1853
+ readStoredView,
1854
+ writeStoredView,
1855
+ viewFromText,
1856
+ viewFromObject,
1857
+ loadCheck,
1809
1858
  localStore,
1810
1859
  readItem,
1811
1860
  subscribeItem,
@@ -1814,8 +1863,6 @@ export {
1814
1863
  NO_EXPLANATIONS,
1815
1864
  FIELDS_COLLAPSED,
1816
1865
  fieldsCollapsed,
1817
- sectionOpen,
1818
- withSection,
1819
1866
  keptOnReset,
1820
1867
  helpSwitch,
1821
1868
  SHORTCUTS,