pivotkit-react 0.1.0 → 0.2.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 (53) hide show
  1. package/CHANGELOG.md +143 -1
  2. package/README.md +48 -298
  3. package/dist/chunks/chunk-53ZMK4BH.js +177 -0
  4. package/dist/chunks/{chunk-ILHFIV2P.js → chunk-F6MVUAQD.js} +35 -78
  5. package/dist/chunks/chunk-LQCWFJBS.js +310 -0
  6. package/dist/chunks/chunk-OYY4BKIL.js +93 -0
  7. package/dist/chunks/chunk-QBD4FOBB.js +254 -0
  8. package/dist/chunks/{chunk-KKJO36W5.js → chunk-X7H7BAVT.js} +243 -324
  9. package/dist/chunks/unused-texts-YTNJCFFC.js +10 -0
  10. package/dist/chunks/unused-texts-de-SGOHV4N7.js +6 -0
  11. package/dist/echarts.js +96 -11
  12. package/dist/index.js +619 -527
  13. package/dist/labels.js +13 -4
  14. package/dist/menu-texts-de.js +6 -0
  15. package/dist/menus.js +787 -191
  16. package/dist/styles.css +113 -31
  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/drill-panel.d.ts +5 -22
  21. package/types/drill-table.d.ts +71 -0
  22. package/types/drill.d.ts +0 -36
  23. package/types/help.d.ts +21 -0
  24. package/types/icons.d.ts +4 -0
  25. package/types/labels.d.ts +43 -101
  26. package/types/lazy-menus.d.ts +16 -4
  27. package/types/menu-labels-de.d.ts +2 -0
  28. package/types/menu-labels.d.ts +71 -9
  29. package/types/menu-ops.d.ts +145 -0
  30. package/types/menu-texts.d.ts +2 -0
  31. package/types/menus.d.ts +1 -1
  32. package/types/names.d.ts +19 -19
  33. package/types/overflow.d.ts +4 -1
  34. package/types/popover.d.ts +10 -6
  35. package/types/section.d.ts +7 -24
  36. package/types/sections.d.ts +2 -0
  37. package/types/share-actions.d.ts +99 -0
  38. package/types/share.d.ts +0 -9
  39. package/types/table.d.ts +9 -3
  40. package/types/templates.d.ts +7 -1
  41. package/types/tips.d.ts +9 -7
  42. package/types/toolbar-panels.d.ts +8 -5
  43. package/types/unused-load.d.ts +23 -0
  44. package/types/unused-texts-de.d.ts +2 -0
  45. package/types/unused-texts.d.ts +130 -0
  46. package/types/unused.d.ts +22 -0
  47. package/types/use-view-history.d.ts +7 -4
  48. package/types/view-history.d.ts +23 -6
  49. package/types/view-ops.d.ts +72 -123
  50. package/types/view-save.d.ts +76 -0
  51. package/types/view-store.d.ts +13 -6
  52. package/dist/chunks/chunk-C32TYSHG.js +0 -441
  53. package/dist/chunks/chunk-XYP47DJ3.js +0 -123
@@ -1,12 +1,55 @@
1
- import {
2
- CHART_TYPES,
3
- MANY_SERIES,
4
- SLICE_TYPES,
5
- chartPlan
6
- } from "./chunk-XYP47DJ3.js";
7
1
  import {
8
2
  fill
9
- } from "./chunk-ILHFIV2P.js";
3
+ } from "./chunk-F6MVUAQD.js";
4
+
5
+ // src/chart-types.js
6
+ import { autoChartType } from "pivotkit-core";
7
+ var CHART_TYPES = Object.freeze({
8
+ auto: { chart: { type: "auto", stacked: false, horizontal: false }, icon: "sparkle", axis: true },
9
+ bar: { chart: { type: "bar", stacked: false, horizontal: false }, icon: "chart", axis: true },
10
+ stacked: { chart: { type: "bar", stacked: true, horizontal: false }, icon: "stacked", axis: true },
11
+ horizontal: { chart: { type: "bar", stacked: false, horizontal: true }, icon: "horizontal", axis: true },
12
+ line: { chart: { type: "line", stacked: false, horizontal: false }, icon: "line", axis: true },
13
+ area: { chart: { type: "area", stacked: false, horizontal: false }, icon: "area", axis: true },
14
+ pie: { chart: { type: "pie", stacked: false, horizontal: false }, icon: "pie", axis: false },
15
+ donut: { chart: { type: "donut", stacked: false, horizontal: false }, icon: "donut", axis: false },
16
+ heatmap: { chart: { type: "heatmap", stacked: false, horizontal: false }, icon: "heatmap", axis: false }
17
+ });
18
+ var SLICE_TYPES = Object.freeze(["pie", "donut"]);
19
+ var CHART_TYPE_NAMES = Object.freeze(Object.keys(CHART_TYPES));
20
+ function chartTypeOf(chart2) {
21
+ const found = CHART_TYPE_NAMES.find((name2) => {
22
+ const c = CHART_TYPES[name2].chart;
23
+ return c.type === chart2.type && c.stacked === Boolean(chart2.stacked) && c.horizontal === Boolean(chart2.horizontal);
24
+ });
25
+ if (found) {
26
+ return found;
27
+ }
28
+ if (chart2.type === "bar") {
29
+ return chart2.horizontal ? "horizontal" : "stacked";
30
+ }
31
+ return CHART_TYPE_NAMES.find((name2) => CHART_TYPES[name2].chart.type === chart2.type) ?? "bar";
32
+ }
33
+ function chartPlan(view, encoded) {
34
+ if (view.chart.type !== "auto") {
35
+ const name3 = chartTypeOf(view.chart);
36
+ return { name: name3, auto: false, swap: false, chart: { type: view.chart.type, stacked: Boolean(view.chart.stacked), horizontal: Boolean(view.chart.horizontal) } };
37
+ }
38
+ const own = autoChartType(
39
+ /** @type {any} */
40
+ view,
41
+ encoded
42
+ );
43
+ const swap = own === "bar" && view.cols.length > 0 && autoChartType(
44
+ /** @type {any} */
45
+ { ...view, rows: view.cols },
46
+ encoded
47
+ ) === "line";
48
+ const name2 = own === "line" || swap ? "line" : "bar";
49
+ return { name: name2, auto: true, swap, chart: { ...CHART_TYPES[name2].chart } };
50
+ }
51
+ var MANY_SERIES = 8;
52
+ var MAX_CATEGORIES = 50;
10
53
 
11
54
  // src/names.js
12
55
  import { fieldLabel } from "pivotkit-core";
@@ -36,6 +79,16 @@ function refLabel(view, ref, labels) {
36
79
  const spec = (view.values ?? []).find((v) => v.agg === ref.agg && sameField(v));
37
80
  return valueLabel({ ...spec ?? ref, showAs: null }, labels);
38
81
  }
82
+ function sortText(view, sort, labels) {
83
+ const desc = sort.order === "desc";
84
+ if (sort.by === "value") {
85
+ return fill(desc ? labels.sortValueDesc : labels.sortValueAsc, { value: refLabel(view, sort.value, labels) });
86
+ }
87
+ if (sort.by === "custom") {
88
+ return desc ? labels.sortCustomDesc : labels.sortCustom;
89
+ }
90
+ return desc ? labels.sortLabelDesc : labels.sortLabelAsc;
91
+ }
39
92
  var OP_SIGNS = Object.freeze({ "=": "=", "!=": "\u2260", ">": ">", ">=": "\u2265", "<": "<", "<=": "\u2264" });
40
93
  function valueConditionText(view, f, labels, locale) {
41
94
  const number = (x) => typeof x === "number" ? x.toLocaleString(locale, { maximumFractionDigits: 6 }) : "";
@@ -53,34 +106,18 @@ function groupingName(source, unit, labels, size) {
53
106
  var quickZone = (type) => type === "number" ? "values" : "rows";
54
107
  function fieldAction(field, type, zones, labels) {
55
108
  const zone = quickZone(type);
56
- const kind = zone === "values" ? "add" : zones.includes(zone) ? null : zones.some((z) => z === "cols" || z === "filters") ? "move" : "add";
109
+ const kind = zones.includes(zone) ? null : zone !== "values" && zones.some((z) => z === "cols" || z === "filters") ? "move" : "add";
57
110
  const name2 = zones.length ? `${field}, ${fill(labels.inZone, { zone: zones.map((z) => labels.zones[z] ?? z).join(", ") })}` : field;
58
111
  const description = kind === null ? "" : fill(kind === "move" ? labels.moveTo : labels.addTo, { zone: labels.zones[zone] });
59
112
  return { zone, kind, name: name2, description };
60
113
  }
61
114
  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;
115
+ function layoutSummary(entries2, labels) {
116
+ 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
117
  }
81
118
 
82
119
  // src/drill.js
83
- import { cellRows, formatter, isFormat } from "pivotkit-core";
120
+ import { cellRows } from "pivotkit-core";
84
121
  var DRILL_LIMIT = 1e3;
85
122
  function decodeRow(encoded, i) {
86
123
  const row = {};
@@ -101,38 +138,6 @@ function drillRows(result, { rowPath = [], colPath = [], data = null, limit = DR
101
138
  }
102
139
  return { count: all.length, rows, indices };
103
140
  }
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
141
 
137
142
  // src/icons.jsx
138
143
  import React from "react";
@@ -146,6 +151,8 @@ var PATHS = {
146
151
  x: "M6 6l12 12M18 6 6 18",
147
152
  chevronDown: "m6 9 6 6 6-6",
148
153
  chevronRight: "m9 6 6 6-6 6",
154
+ arrowUp: "M12 19V5M6 11l6-6 6 6",
155
+ arrowDown: "M12 5v14M6 13l6 6 6-6",
149
156
  undo: "M9 14 4 9l5-5M4 9h10.5a5.5 5.5 0 0 1 0 11H11",
150
157
  redo: "m15 14 5-5-5-5M20 9H9.5a5.5 5.5 0 0 0 0 11H13",
151
158
  reset: "M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5",
@@ -176,8 +183,10 @@ var PATHS = {
176
183
  cols: "M6 4v16M12 4v16M18 4v16",
177
184
  sigma: "M18 5H6l6 7-6 7h12",
178
185
  info: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18ZM12 11v5M12 8h.01",
186
+ warn: "M12 4 2.8 20h18.4ZM12 10v4.5M12 17.5h.01",
179
187
  image: "M4 5h16v14H4zM4 16l5-5 4 4 3-3 4 4M15 9h.01",
180
188
  file: "M6 3h8l4 4v14H6zM14 3v4h4",
189
+ newFile: "M6 3h8l4 4v14H6zM14 3v4h4M12 11v6M9 14h6",
181
190
  swap: "M7 4 3 8l4 4M3 8h14M17 20l4-4-4-4M21 16H7",
182
191
  top: "M4 20v-6h5v6M9 20V8h6v12M15 20v-9h5v9M3 20h18",
183
192
  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",
@@ -557,7 +566,7 @@ function Popover({ open, anchor, onClose, label, role = "dialog", align = "start
557
566
  layer
558
567
  );
559
568
  }
560
- function MenuButton({ label, icon, text, showText = true, className, role = "menu", align, popoverClass, disabled, title, children, testId, buttonRef, name: name2, tabIndex, slot, fill: fill2 }) {
569
+ 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
570
  const [open, setOpen] = useState(false);
562
571
  const own = useRef3(
563
572
  /** @type {HTMLButtonElement | null} */
@@ -588,10 +597,11 @@ function MenuButton({ label, icon, text, showText = true, className, role = "men
588
597
  icon
589
598
  ) }) : null,
590
599
  showText && text ? /* @__PURE__ */ React3.createElement("span", { className: "pk-btn-text" }, text) : null,
600
+ mark,
591
601
  showText && text ? /* @__PURE__ */ React3.createElement(Icon, { name: "chevronDown", size: 14, className: "pk-caret" }) : null
592
602
  ), /* @__PURE__ */ React3.createElement(Popover, { open, anchor: ref, onClose: close, label, role, align, className: popoverClass, id, fill: fill2 }, children(close)));
593
603
  }
594
- function Option({ onSelect, icon, checked, children, hint, reason, inMenu = false, disabled, danger, tone, testId }) {
604
+ function Option({ onSelect, icon, checked, children, hint, reason, inMenu = false, disabled, danger, tone, testId, current }) {
595
605
  const second = disabled && reason ? reason : hint;
596
606
  const role = inMenu ? checked === void 0 ? "menuitem" : "menuitemradio" : void 0;
597
607
  return /* @__PURE__ */ React3.createElement(
@@ -601,13 +611,14 @@ function Option({ onSelect, icon, checked, children, hint, reason, inMenu = fals
601
611
  role,
602
612
  "aria-checked": inMenu && checked !== void 0 ? checked : void 0,
603
613
  "aria-pressed": !inMenu && checked !== void 0 ? checked : void 0,
614
+ "aria-current": current ? "true" : void 0,
604
615
  className: `pk-option${checked ? " pk-checked" : ""}${danger ? " pk-danger" : ""}${tone === "accent" ? " pk-accent" : ""}`,
605
616
  "data-pk-option": "",
606
617
  "data-testid": testId,
607
618
  disabled,
608
619
  onClick: onSelect
609
620
  },
610
- /* @__PURE__ */ React3.createElement("span", { className: "pk-option-icon" }, checked ? /* @__PURE__ */ React3.createElement(Icon, { name: "check" }) : icon ? /* @__PURE__ */ React3.createElement(Icon, { name: (
621
+ /* @__PURE__ */ React3.createElement("span", { className: "pk-option-icon" }, checked || current ? /* @__PURE__ */ React3.createElement(Icon, { name: "check" }) : icon ? /* @__PURE__ */ React3.createElement(Icon, { name: (
611
622
  /** @type {any} */
612
623
  icon
613
624
  ) }) : null),
@@ -725,7 +736,7 @@ function InfoButton({ info, name: name2, labels, className, testId = "field-info
725
736
  }
726
737
 
727
738
  // src/view-ops.js
728
- import { LIMITS, aggregatorsFor, isFormat as isFormat2 } from "pivotkit-core";
739
+ import { LIMITS, aggregatorsFor, isFormat } from "pivotkit-core";
729
740
  var ZONES = Object.freeze(
730
741
  /** @type {Zone[]} */
731
742
  ["filters", "cols", "rows", "values"]
@@ -807,7 +818,7 @@ function addField(view, field, zone, options = {}) {
807
818
  }
808
819
  } else if (zone === "values") {
809
820
  const wanted = options.defaults ?? {};
810
- const format = typeof wanted.format === "string" && isFormat2(wanted.format) ? wanted.format : null;
821
+ const format = typeof wanted.format === "string" && isFormat(wanted.format) ? wanted.format : null;
811
822
  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
823
  } else if (zone === "filters") {
813
824
  dropFromAxes(next, field);
@@ -883,31 +894,6 @@ function reorder(view, zone, from, to) {
883
894
  resetCollapsed(next, view);
884
895
  return next;
885
896
  }
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
897
  function numberRange(encoded, field) {
912
898
  const column = encoded.column(field);
913
899
  if (!column || column.type !== "number") {
@@ -923,20 +909,6 @@ function numberRange(encoded, field) {
923
909
  }
924
910
  return min <= max ? { min, max } : null;
925
911
  }
926
- function binProblem(size, start, range) {
927
- if (!range) {
928
- return null;
929
- }
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";
936
- }
937
- }
938
- return null;
939
- }
940
912
  function groupField(view, field, unit, options = {}) {
941
913
  const spec = view.derived.find((d) => same(d.name, field));
942
914
  const source = spec ? spec.field : field;
@@ -1005,47 +977,41 @@ function withHostOrders(view, orderOf) {
1005
977
  function sortOf(view, field) {
1006
978
  return view.sort.find((s) => same(s.field, field)) ?? null;
1007
979
  }
1008
- function filtersOf(view, field, types) {
1009
- return view.filters.filter((f) => same(f.field, field) && (!types || types.includes(f.type)));
980
+ function sortEntry(spec, hostOrdered) {
981
+ return spec.by === "label" && spec.order === "asc" && !hostOrdered ? null : spec;
1010
982
  }
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: [] });
983
+ function headerSortTarget(view, cell, typeOf) {
984
+ if (cell.kind === "corner") {
985
+ return cell.field && view.rows.some((f) => same(f, cell.field)) ? { field: cell.field } : null;
1020
986
  }
1021
- return next;
987
+ const spec = cell.kind === "colHeader" && cell.valueIndex !== void 0 && !cell.colPath?.length ? view.values[cell.valueIndex] : void 0;
988
+ if (!spec || !view.rows.length || !numericResult(spec, spec.field ? typeOf(spec.field) ?? "string" : "number")) {
989
+ return null;
990
+ }
991
+ return { field: view.rows[view.rows.length - 1], ref: { field: spec.field ?? null, agg: spec.agg } };
1022
992
  }
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;
993
+ function headerSortState(view, target) {
994
+ const s = sortOf(view, target.field);
995
+ const word = (order) => order === "desc" ? "descending" : "ascending";
996
+ if (target.ref) {
997
+ return s?.by === "value" && sameRef(s.value, target.ref) ? { order: word(s.order), chosen: true } : { order: null, chosen: false };
1034
998
  }
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
- }
999
+ if (!s) {
1000
+ return { order: "ascending", chosen: false };
1042
1001
  }
1043
- return next;
1002
+ return { order: s.by === "label" ? word(s.order) : s.by === "custom" ? "other" : null, chosen: s.by === "label" };
1044
1003
  }
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 }] : []);
1004
+ function nextHeaderSort(view, target, hostOrdered) {
1005
+ const s = sortOf(view, target.field);
1006
+ if (target.ref) {
1007
+ const mine = s?.by === "value" && sameRef(s.value, target.ref);
1008
+ return mine && s.order === "asc" ? null : { by: "value", order: mine ? "asc" : "desc", value: mine ? s.value : target.ref };
1009
+ }
1010
+ const desc = !s || s.by === "label" && s.order === "asc";
1011
+ return sortEntry({ by: "label", order: desc ? "desc" : "asc" }, hostOrdered);
1012
+ }
1013
+ function filtersOf(view, field, types) {
1014
+ return view.filters.filter((f) => same(f.field, field) && (!types || types.includes(f.type)));
1049
1015
  }
1050
1016
  function selectedItems(view, field, all) {
1051
1017
  let selected = all;
@@ -1055,53 +1021,12 @@ function selectedItems(view, field, all) {
1055
1021
  }
1056
1022
  return selected;
1057
1023
  }
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
1024
  function numericResult(spec, type) {
1081
1025
  return spec.agg !== "listUnique" && !(["first", "last"].includes(spec.agg) && type !== "number") && !(type === "date" && ["average", "median", "min", "max"].includes(spec.agg));
1082
1026
  }
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
1027
  function sameRef(a, b) {
1087
1028
  return Boolean(a && b) && a.agg === b.agg && (a.field === null || b.field === null ? a.field === b.field : same(a.field, b.field));
1088
1029
  }
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
1030
  function isFiltered(view, field) {
1106
1031
  return filtersOf(view, field).some((f) => f.type !== "exclude" || f.items.length > 0);
1107
1032
  }
@@ -1128,6 +1053,7 @@ function rowFolding(view, outer) {
1128
1053
  canCollapse,
1129
1054
  collapsed: view.collapsed.rows.length,
1130
1055
  open,
1056
+ // keys of the menus' texts (menu-labels.js): the Options menu shows them with its labels
1131
1057
  why: {
1132
1058
  expand: canExpand ? null : "expandNothing",
1133
1059
  collapse: canCollapse ? null : view.rows.length < 2 ? "collapseNeedsRows" : "collapseAllDone"
@@ -1139,19 +1065,6 @@ function setCollapsed(view, axis, paths) {
1139
1065
  next.collapsed[axis] = paths ? paths : [];
1140
1066
  return next;
1141
1067
  }
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
1068
  function setTotal(view, key, on) {
1156
1069
  const next = clone(view);
1157
1070
  next.totals[key] = Boolean(on);
@@ -1193,116 +1106,14 @@ function swapAxes(view) {
1193
1106
  function isEmptyView(view) {
1194
1107
  return view.rows.length === 0 && view.cols.length === 0 && view.values.length === 0;
1195
1108
  }
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
1109
 
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);
1227
- }
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;
1248
- }
1249
- } catch {
1250
- }
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
- try {
1269
- field.select();
1270
- ok = typeof doc.execCommand === "function" && doc.execCommand("copy");
1271
- } catch {
1272
- ok = false;
1273
- }
1274
- field.remove();
1275
- before?.focus?.({ preventScroll: true });
1276
- return ok;
1277
- }
1278
-
1279
- // src/section.jsx
1280
- import React5, { createContext as createContext2, useContext as useContext2, useId as useId3 } from "react";
1110
+ // src/help.js
1111
+ import { createContext as createContext2 } from "react";
1281
1112
  var HelpContext = createContext2(
1282
1113
  /** @type {Help} */
1283
1114
  { explain: true, isOpen: () => true, setOpen: () => {
1284
1115
  }, labels: null }
1285
1116
  );
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;
1291
- }
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}` });
1293
- }
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);
1302
- }
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));
1305
- }
1306
1117
 
1307
1118
  // src/storage.js
1308
1119
  function localStore() {
@@ -1576,8 +1387,6 @@ var SECTIONS = Object.freeze({
1576
1387
  showAs: true,
1577
1388
  format: false,
1578
1389
  highlight: false,
1579
- name: false,
1580
- valueFilters: false,
1581
1390
  move: false,
1582
1391
  // a field's menu on Rows or Columns
1583
1392
  sort: true,
@@ -1587,16 +1396,16 @@ var SECTIONS = Object.freeze({
1587
1396
  filters: true,
1588
1397
  // the toolbar's menus
1589
1398
  totals: true,
1590
- folding: true,
1591
1399
  help: true,
1592
1400
  // the Export menus (the toolbar's and the drill-down's)
1593
1401
  exportDownload: true,
1594
1402
  exportCopy: true,
1403
+ thisView: true,
1595
1404
  sharedViews: true,
1596
1405
  myViews: true,
1597
- share: true,
1406
+ share: false,
1598
1407
  chartType: true,
1599
- chartDisplay: true
1408
+ chartDisplay: false
1600
1409
  });
1601
1410
  function sectionOpen(id, dismissed) {
1602
1411
  if (dismissed.includes(`open:${id}`)) {
@@ -1733,18 +1542,129 @@ function withoutFilters(view) {
1733
1542
  return { ...view, filters: filterZoneFields(view).map((field) => ({ field, type: "exclude", items: [] })) };
1734
1543
  }
1735
1544
 
1545
+ // src/share.js
1546
+ import { VIEW_FILE_LIMITS, fromViewFile, normalize } from "pivotkit-core";
1547
+ var linkModule = null;
1548
+ var linkLoaded = null;
1549
+ function loadLink() {
1550
+ linkModule ??= import("pivotkit-core/link").then((m) => {
1551
+ linkLoaded = m;
1552
+ return m;
1553
+ });
1554
+ return linkModule;
1555
+ }
1556
+ var linkNow = () => linkLoaded;
1557
+ function linkParam(storageKey) {
1558
+ return storageKey ? `pivot-${storageKey}` : "pivot";
1559
+ }
1560
+ var entries = (fragment) => fragment ? fragment.split("&") : [];
1561
+ var isEntry = (entry, param) => entry.startsWith(`${encodeURIComponent(param)}=`);
1562
+ function readLinkParam(hash, param) {
1563
+ const text = typeof hash === "string" ? hash.replace(/^#/, "") : "";
1564
+ const entry = entries(text).find((e) => isEntry(e, param));
1565
+ const value = entry ? entry.slice(encodeURIComponent(param).length + 1) : "";
1566
+ return value ? value : null;
1567
+ }
1568
+ function withLinkParam(url, param, encoded) {
1569
+ const at = url.indexOf("#");
1570
+ const base = at === -1 ? url : url.slice(0, at);
1571
+ const kept = entries(at === -1 ? "" : url.slice(at + 1)).filter((e) => !isEntry(e, param));
1572
+ const next = encoded ? [...kept, `${encodeURIComponent(param)}=${encoded}`] : kept;
1573
+ return next.length ? `${base}#${next.join("&")}` : base;
1574
+ }
1575
+ function shareBase(shareLink, here) {
1576
+ if (shareLink === true) {
1577
+ if (!here) {
1578
+ return null;
1579
+ }
1580
+ try {
1581
+ const url = new URL(here);
1582
+ return `${url.origin}${url.pathname}${url.hash}`;
1583
+ } catch {
1584
+ return null;
1585
+ }
1586
+ }
1587
+ return typeof shareLink === "string" && shareLink.trim() ? shareLink.trim() : null;
1588
+ }
1589
+ var viewStorageName = (key) => `pivotkit:view:${key ?? ""}`;
1590
+ function readStoredView(key, storage) {
1591
+ if (!storage) {
1592
+ return null;
1593
+ }
1594
+ try {
1595
+ return storage.getItem(viewStorageName(key));
1596
+ } catch {
1597
+ return null;
1598
+ }
1599
+ }
1600
+ function writeStoredView(key, storage, view) {
1601
+ if (!storage) {
1602
+ return;
1603
+ }
1604
+ try {
1605
+ storage.setItem(viewStorageName(key), JSON.stringify(view));
1606
+ } catch {
1607
+ }
1608
+ }
1609
+ var VIEW_TEXT_MAX = VIEW_FILE_LIMITS.text;
1610
+ var quoteNames = (names) => {
1611
+ const shown = names.slice(0, 5).map((n) => `\u201C${n.length > 60 ? `${n.slice(0, 59)}\u2026` : n}\u201D`).join(", ");
1612
+ return names.length > 5 ? `${shown} \u2026` : shown;
1613
+ };
1614
+ var FAILED = Object.freeze({ newerFormat: "newer", newerView: "newer" });
1615
+ function viewFromText(text, encoded, options = {}) {
1616
+ return viewFromObject(text, encoded, options);
1617
+ }
1618
+ function viewFromObject(input, encoded, options = {}) {
1619
+ const file = fromViewFile(input, { data: encoded, sourceId: options.sourceId });
1620
+ if (file.failed || !file.view) {
1621
+ const failed = file.failed ?? "notView";
1622
+ return { view: null, issues: file.issues, failed: Object.hasOwn(FAILED, failed) ? FAILED[failed] : failed, file };
1623
+ }
1624
+ const { view, issues } = normalize(file.view, encoded, options.limits ? { limits: options.limits } : void 0);
1625
+ if (issues.some((i) => i.path === "version")) {
1626
+ return { view: null, issues, failed: "newer", file };
1627
+ }
1628
+ return { view, issues, failed: null, file };
1629
+ }
1630
+ function loadCheck(loaded, labels, sources = []) {
1631
+ const fit = loaded.file?.compatible;
1632
+ if (!loaded.view || !fit || fit.ok) {
1633
+ return null;
1634
+ }
1635
+ const lines2 = [];
1636
+ const fileSource = loaded.file?.source;
1637
+ const target = fit.source === "other" && fileSource?.id ? sources.find((s) => s && s.id === fileSource.id) : void 0;
1638
+ if (fit.source === "other") {
1639
+ const name2 = target?.name || fileSource?.name || fileSource?.id;
1640
+ lines2.push(name2 ? fill(labels.loadCheckSource, { source: name2 }) : labels.loadCheckOtherSource);
1641
+ }
1642
+ if (fit.missing.length) {
1643
+ lines2.push(fill(labels.loadCheckMissing, { fields: quoteNames(fit.missing) }));
1644
+ }
1645
+ if (fit.changed.length) {
1646
+ lines2.push(fill(labels.loadCheckChanged, { fields: quoteNames(fit.changed.map((c) => c.name)) }));
1647
+ }
1648
+ return { lines: lines2, switchTo: target ? { id: target.id, name: target.name || target.id } : null };
1649
+ }
1650
+
1736
1651
  export {
1652
+ CHART_TYPES,
1653
+ SLICE_TYPES,
1654
+ CHART_TYPE_NAMES,
1655
+ chartTypeOf,
1656
+ chartPlan,
1657
+ MAX_CATEGORIES,
1737
1658
  valueLabel,
1738
1659
  refLabel,
1660
+ sortText,
1739
1661
  valueConditionText,
1740
1662
  groupingName,
1741
1663
  fieldAction,
1742
1664
  layoutSummary,
1743
- filterText,
1744
1665
  DRILL_LIMIT,
1745
1666
  decodeRow,
1746
1667
  drillRows,
1747
- drillTable,
1748
1668
  Icon,
1749
1669
  TYPE_ICON,
1750
1670
  ZONE_ICON,
@@ -1757,55 +1677,42 @@ export {
1757
1677
  Popover,
1758
1678
  MenuButton,
1759
1679
  Option,
1760
- FieldDescription,
1761
1680
  InfoButton,
1762
1681
  ZONES,
1682
+ clone,
1683
+ same,
1763
1684
  filterZoneFields,
1685
+ axisOf,
1764
1686
  zoneOverLimit,
1765
1687
  addField,
1766
1688
  removeAt,
1767
1689
  moveField,
1768
1690
  reorder,
1769
- updateValue,
1770
1691
  numberRange,
1771
- binProblem,
1772
1692
  groupField,
1773
1693
  groupingOf,
1774
1694
  sourceOf,
1775
1695
  setSort,
1776
1696
  withHostOrders,
1777
1697
  sortOf,
1698
+ sortEntry,
1699
+ headerSortTarget,
1700
+ headerSortState,
1701
+ nextHeaderSort,
1778
1702
  filtersOf,
1779
- setItemFilter,
1780
1703
  selectedItems,
1781
- setLabelFilter,
1782
- setTopFilter,
1783
- setValueFilter,
1784
1704
  numericResult,
1785
- withMeasure,
1786
1705
  sameRef,
1787
- measureChoices,
1788
- removeFilters,
1789
- hasFilter,
1790
1706
  toggleCollapsed,
1791
1707
  rowFolding,
1792
1708
  setCollapsed,
1793
- TOTALS,
1794
- totalNoEffect,
1795
1709
  setTotal,
1796
1710
  setDisplay,
1797
1711
  setChart,
1798
1712
  setChartDisplay,
1799
1713
  swapAxes,
1800
1714
  isEmptyView,
1801
- conditionKind,
1802
- safeFileName,
1803
- dataUrlToBlob,
1804
- saveBlob,
1805
- copyText,
1806
1715
  HelpContext,
1807
- SettingInfo,
1808
- Section,
1809
1716
  localStore,
1810
1717
  readItem,
1811
1718
  subscribeItem,
@@ -1816,6 +1723,7 @@ export {
1816
1723
  fieldsCollapsed,
1817
1724
  sectionOpen,
1818
1725
  withSection,
1726
+ isSection,
1819
1727
  keptOnReset,
1820
1728
  helpSwitch,
1821
1729
  SHORTCUTS,
@@ -1829,5 +1737,16 @@ export {
1829
1737
  parseStored,
1830
1738
  subscribeStored,
1831
1739
  writeDismissed,
1832
- withoutFilters
1740
+ withoutFilters,
1741
+ loadLink,
1742
+ linkNow,
1743
+ linkParam,
1744
+ readLinkParam,
1745
+ withLinkParam,
1746
+ shareBase,
1747
+ readStoredView,
1748
+ writeStoredView,
1749
+ viewFromText,
1750
+ viewFromObject,
1751
+ loadCheck
1833
1752
  };