pivotkit-react 0.2.0 → 0.4.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 (64) hide show
  1. package/CHANGELOG.md +284 -1
  2. package/README.md +1 -1
  3. package/dist/chunks/{chunk-F6MVUAQD.js → chunk-6MDAL3IO.js} +51 -3
  4. package/dist/chunks/{chunk-53ZMK4BH.js → chunk-EM23V5GH.js} +6 -0
  5. package/dist/chunks/{chunk-LQCWFJBS.js → chunk-LEN5RPBM.js} +147 -26
  6. package/dist/chunks/{chunk-OYY4BKIL.js → chunk-RWYHJRQO.js} +6 -0
  7. package/dist/chunks/{chunk-QBD4FOBB.js → chunk-WB4GKWFQ.js} +124 -18
  8. package/dist/chunks/chunk-XN55BQ4M.js +618 -0
  9. package/dist/chunks/{chunk-X7H7BAVT.js → chunk-YITKWZ4L.js} +312 -628
  10. package/dist/chunks/chunk-ZYEYZSYL.js +187 -0
  11. package/dist/chunks/{unused-texts-YTNJCFFC.js → unused-texts-K3VFH65P.js} +1 -1
  12. package/dist/chunks/{unused-texts-de-SGOHV4N7.js → unused-texts-de-OW4TGIVX.js} +1 -1
  13. package/dist/import-ui.js +769 -0
  14. package/dist/import-worker.js +20 -0
  15. package/dist/index.js +653 -227
  16. package/dist/labels.js +14 -10
  17. package/dist/menu-texts-de.js +1 -1
  18. package/dist/menus.js +2499 -676
  19. package/dist/styles.css +673 -125
  20. package/package.json +3 -2
  21. package/types/chip-menus.d.ts +20 -4
  22. package/types/data-history.d.ts +85 -0
  23. package/types/data-keep.d.ts +51 -0
  24. package/types/data-menu.d.ts +11 -0
  25. package/types/dnd.d.ts +8 -4
  26. package/types/dom.d.ts +40 -7
  27. package/types/field-info.d.ts +32 -0
  28. package/types/filter-level.d.ts +16 -0
  29. package/types/filter.d.ts +31 -0
  30. package/types/help.d.ts +0 -7
  31. package/types/import-host.d.ts +53 -0
  32. package/types/import-labels.d.ts +360 -0
  33. package/types/import-module.d.ts +2 -0
  34. package/types/import-run.d.ts +73 -0
  35. package/types/import-source.d.ts +32 -0
  36. package/types/import-steps.d.ts +121 -0
  37. package/types/import-ui.d.ts +108 -0
  38. package/types/import-worker.d.ts +1 -0
  39. package/types/index.d.ts +56 -4
  40. package/types/labels.d.ts +97 -2
  41. package/types/lazy-import.d.ts +4 -0
  42. package/types/lazy-menus.d.ts +2 -2
  43. package/types/levels.d.ts +106 -0
  44. package/types/menu-fields.d.ts +80 -0
  45. package/types/menu-labels.d.ts +214 -22
  46. package/types/menu-ops.d.ts +150 -9
  47. package/types/menu-topics.d.ts +291 -0
  48. package/types/menus.d.ts +2 -1
  49. package/types/names.d.ts +141 -1
  50. package/types/overflow.d.ts +29 -17
  51. package/types/place.d.ts +44 -0
  52. package/types/popover.d.ts +47 -5
  53. package/types/section.d.ts +8 -11
  54. package/types/tips.d.ts +1 -36
  55. package/types/toasts.d.ts +1 -1
  56. package/types/toolbar-panels.d.ts +17 -9
  57. package/types/unused-keep.d.ts +20 -0
  58. package/types/unused-texts.d.ts +6 -0
  59. package/types/unused.d.ts +1 -0
  60. package/types/use-view-history.d.ts +13 -4
  61. package/types/view-ops.d.ts +12 -0
  62. package/types/virtual.d.ts +15 -0
  63. package/types/zones.d.ts +5 -4
  64. package/types/sections.d.ts +0 -2
@@ -1,6 +1,12 @@
1
1
  import {
2
- fill
3
- } from "./chunk-F6MVUAQD.js";
2
+ Icon,
3
+ Popover,
4
+ useFormName
5
+ } from "./chunk-XN55BQ4M.js";
6
+ import {
7
+ fill,
8
+ plural
9
+ } from "./chunk-6MDAL3IO.js";
4
10
 
5
11
  // src/chart-types.js
6
12
  import { autoChartType } from "pivotkit-core";
@@ -52,7 +58,7 @@ var MANY_SERIES = 8;
52
58
  var MAX_CATEGORIES = 50;
53
59
 
54
60
  // src/names.js
55
- import { fieldLabel } from "pivotkit-core";
61
+ import { fieldLabel, relativeDateRange } from "pivotkit-core";
56
62
  function valueLabel(spec, labels) {
57
63
  if (spec.label) {
58
64
  return spec.label;
@@ -72,11 +78,12 @@ function valueLabel(spec, labels) {
72
78
  return fill(core.showAsName, { showAs, value: spec.field && spec.agg === "sum" ? fieldLabel(spec.field, core) : base });
73
79
  }
74
80
  function refLabel(view, ref, labels) {
75
- if (!ref) {
76
- return labels.core.countRows;
81
+ const field = ref?.field ?? null;
82
+ const sameField = (v) => field === null || v.field === null || v.field === void 0 ? (v.field ?? null) === field : v.field.toLowerCase() === field.toLowerCase();
83
+ const spec = ref ? (view.values ?? []).find((v) => v.agg === ref.agg && sameField(v)) : void 0;
84
+ if (!spec && field === null) {
85
+ return labels.countOfRows;
77
86
  }
78
- const sameField = (v) => ref.field === null || v.field === null || v.field === void 0 ? (v.field ?? null) === ref.field : v.field.toLowerCase() === ref.field.toLowerCase();
79
- const spec = (view.values ?? []).find((v) => v.agg === ref.agg && sameField(v));
80
87
  return valueLabel({ ...spec ?? ref, showAs: null }, labels);
81
88
  }
82
89
  function sortText(view, sort, labels) {
@@ -99,6 +106,126 @@ function valueConditionText(view, f, labels, locale) {
99
106
  }
100
107
  return fill(labels.valueConditions.compare, { value, op: Object.hasOwn(OP_SIGNS, f.op) ? OP_SIGNS[f.op] : f.op, number: number(f.value) });
101
108
  }
109
+ var dayText = (iso, locale) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { dateStyle: "medium", timeZone: "UTC" });
110
+ var isoDay = (ms) => new Date(ms).toISOString().slice(0, 10);
111
+ var dayAfter = (iso, n = 1) => isoDay(Date.parse(`${iso}T00:00Z`) + n * 864e5);
112
+ var relativeDays = (f, timeZone, now, latest) => relativeDateRange(f.unit, f.count, { timeZone, now, anchor: f.anchor, latest: latest ?? void 0 });
113
+ function periodText(range, unit, locale) {
114
+ const month = (iso) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { month: "short", year: "numeric", timeZone: "UTC" });
115
+ const text = unit === "year" ? (iso) => iso.slice(0, 4) : unit === "month" ? month : (iso) => dayText(iso, locale);
116
+ const [from, to] = [text(range.from), text(range.to)];
117
+ return from === to ? from : `${from}\u2013${to}`;
118
+ }
119
+ function rangeShare(range, unit, span, locale) {
120
+ const [first, last] = [periodStart(isoDay(span.min), unit), periodEnd(isoDay(span.max), unit)];
121
+ if (first <= range.from && last >= range.to) {
122
+ return null;
123
+ }
124
+ const from = range.from > first ? range.from : first;
125
+ const to = range.to < last ? range.to : last;
126
+ if (from > to) {
127
+ return { none: true };
128
+ }
129
+ const missing = [];
130
+ let count = 0;
131
+ const part = (a, b, dataYear) => {
132
+ const years = [];
133
+ const [ya, yb] = [Number(a.slice(0, 4)), Number(b.slice(0, 4))];
134
+ for (let y = ya; y <= yb; y++) {
135
+ if (y !== dataYear) {
136
+ years.push(y);
137
+ }
138
+ }
139
+ if (years.length) {
140
+ missing.push(years.length === 1 ? String(years[0]) : `${years[0]}\u2013${years[years.length - 1]}`);
141
+ count += years.length;
142
+ }
143
+ if (ya <= dataYear && dataYear <= yb) {
144
+ const yearFrom = `${String(dataYear).padStart(4, "0")}-01-01`;
145
+ const yearTo = `${String(dataYear).padStart(4, "0")}-12-31`;
146
+ const rest = { from: a > yearFrom ? a : yearFrom, to: b < yearTo ? b : yearTo };
147
+ missing.push(periodText(rest, unit, locale));
148
+ count += periodText({ from: rest.from, to: rest.from }, unit, locale) === periodText({ from: rest.to, to: rest.to }, unit, locale) ? 1 : 2;
149
+ }
150
+ };
151
+ if (range.from < first) {
152
+ part(range.from, dayAfter(first, -1), Number(first.slice(0, 4)));
153
+ }
154
+ if (range.to > last) {
155
+ part(dayAfter(last), range.to, Number(last.slice(0, 4)));
156
+ }
157
+ return { none: false, data: periodText({ from, to }, unit, locale), missing, count };
158
+ }
159
+ var periodStart = (iso, unit) => unit === "year" ? `${iso.slice(0, 4)}-01-01` : unit === "month" ? `${iso.slice(0, 7)}-01` : iso;
160
+ function periodEnd(iso, unit) {
161
+ if (unit === "day") {
162
+ return iso;
163
+ }
164
+ const [y, m] = [Number(iso.slice(0, 4)), Number(iso.slice(5, 7))];
165
+ return isoDay(unit === "year" ? Date.UTC(y, 11, 31) : Date.UTC(y, m, 0));
166
+ }
167
+ function relativeText(f, labels, locale, timeZone, now, span) {
168
+ const key = f.count === 1 ? f.unit : `${f.unit}s`;
169
+ let text = fill(Object.hasOwn(labels.relative, key) ? labels.relative[key] : key, { count: f.count.toLocaleString(locale) });
170
+ const range = relativeDays(f, timeZone, now, span?.max);
171
+ if (!range) {
172
+ return text;
173
+ }
174
+ const latest = f.anchor === "latest";
175
+ if (latest) {
176
+ text = fill(labels.relativeTo, { text, end: periodText({ from: range.to, to: range.to }, f.unit, locale) });
177
+ }
178
+ const share = span ? rangeShare(range, f.unit, span, locale) : null;
179
+ if (!share) {
180
+ return latest ? text : fill(labels.withRange, { text, range: periodText(range, f.unit, locale) });
181
+ }
182
+ const lang = { lang: labels.lang, locale };
183
+ if (share.none) {
184
+ return fill(labels.withRange, { text, range: fill(plural(labels.noData, 1, lang), { range: periodText(range, f.unit, locale) }) });
185
+ }
186
+ return fill(labels.withShare, { text, range: share.data, missing: fill(plural(labels.noData, share.count, lang), { range: share.missing.join(", ") }) });
187
+ }
188
+ function wholeYears(from, to) {
189
+ const whole = typeof from === "string" && typeof to === "string" && /^\d{4}-01-01$/.test(from) && /^\d{4}-12-31$/.test(to);
190
+ return whole ? [from.slice(0, 4), to.slice(0, 4)] : null;
191
+ }
192
+ function compareText(f, labels, locale, { date, labelOf }) {
193
+ const shown = (v) => typeof v === "string" ? dayText(v, locale) : labelOf?.(v) ?? (date ? String(v) : v.toLocaleString(locale, { maximumFractionDigits: 6 }));
194
+ const forms = labels.compareShort;
195
+ if (f.op === "between" || f.op === "notBetween") {
196
+ const [from, to] = f.value2 !== void 0 && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
197
+ const years = wholeYears(from, to);
198
+ if (years) {
199
+ return years[0] === years[1] ? fill(forms[f.op === "between" ? "=" : "!="], { value: years[0] }) : fill(forms[f.op], { from: years[0], to: years[1] });
200
+ }
201
+ return fill(forms[f.op], { from: shown(from), to: shown(to) });
202
+ }
203
+ return date && Object.hasOwn(forms, f.op) ? fill(forms[f.op], { value: shown(f.value) }) : `${Object.hasOwn(OP_SIGNS, f.op) ? OP_SIGNS[f.op] : f.op} ${shown(f.value)}`;
204
+ }
205
+ function itemRuleText(f, labels, locale, { timeZone, date, labelOf, span }) {
206
+ if (f.type === "relative") {
207
+ return relativeText(
208
+ /** @type {any} */
209
+ f,
210
+ labels,
211
+ locale,
212
+ timeZone,
213
+ void 0,
214
+ span
215
+ );
216
+ }
217
+ if (f.type === "compare") {
218
+ return compareText(
219
+ /** @type {any} */
220
+ f,
221
+ labels,
222
+ locale,
223
+ { date, labelOf }
224
+ );
225
+ }
226
+ const op = String(f.op);
227
+ return `${Object.hasOwn(labels.labelOps, op) ? labels.labelOps[op] : op} ${fill(labels.quote, { text: f.value })}`;
228
+ }
102
229
  function groupingName(source, unit, labels, size) {
103
230
  const inName = labels.unitInName && Object.hasOwn(labels.unitInName, unit) ? labels.unitInName[unit] : labels.units[unit];
104
231
  return unit === "bin" ? fill(labels.binsName, { field: source, size }) : fill(labels.derivedName, { field: source, unit: inName ?? unit });
@@ -139,71 +266,8 @@ function drillRows(result, { rowPath = [], colPath = [], data = null, limit = DR
139
266
  return { count: all.length, rows, indices };
140
267
  }
141
268
 
142
- // src/icons.jsx
143
- import React from "react";
144
- var PATHS = {
145
- grip: "M9 6h.01M9 12h.01M9 18h.01M15 6h.01M15 12h.01M15 18h.01",
146
- text: "M4 18 8.5 6h1L14 18M5.6 14h6.8M17 11.5c.6-.7 1.4-1 2.3-1 1.5 0 2.2.9 2.2 2.3V18m0-3.4c-.8-.4-1.6-.5-2.5-.5-1.4 0-2.3.7-2.3 1.9 0 1.1.8 1.8 2 1.8 1.2 0 2.1-.6 2.8-1.6",
147
- number: "M9 4 7 20M17 4l-2 16M4 9h16M3 15h16",
148
- date: "M7 3v3M17 3v3M4 8h16M5 5h14a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1ZM8 12h2M14 12h2M8 16h2M14 16h2",
149
- boolean: "M8 7h8a5 5 0 0 1 0 10H8A5 5 0 0 1 8 7ZM16 14a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z",
150
- search: "M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14ZM20 20l-4-4",
151
- x: "M6 6l12 12M18 6 6 18",
152
- chevronDown: "m6 9 6 6 6-6",
153
- chevronRight: "m9 6 6 6-6 6",
154
- arrowUp: "M12 19V5M6 11l6-6 6 6",
155
- arrowDown: "M12 5v14M6 13l6 6 6-6",
156
- undo: "M9 14 4 9l5-5M4 9h10.5a5.5 5.5 0 0 1 0 11H11",
157
- redo: "m15 14 5-5-5-5M20 9H9.5a5.5 5.5 0 0 0 0 11H13",
158
- reset: "M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5",
159
- table: "M4 5h16v14H4zM4 10h16M4 15h16M10 5v14",
160
- chart: "M4 20h16M7 16v-5M12 16V6M17 16v-8",
161
- stacked: "M4 20h16M7 16v-3M7 13v-3M12 16v-4M12 12V6M17 16v-2M17 14V9",
162
- horizontal: "M4 4v16M8 7h7M8 12h11M8 17h5",
163
- line: "M4 18 9 12l4 3 7-9M4 20h16",
164
- area: "M4 18 9 11l4 3 7-8v14H4Z",
165
- pie: "M12 3a9 9 0 1 0 9 9h-9Z M15 3.5A9 9 0 0 1 20.5 9H15Z",
166
- donut: "M12 3a9 9 0 1 0 9 9h-4a5 5 0 1 1-5-5Z M14.5 3.4A9 9 0 0 1 20.6 9.5h-4.1a5 5 0 0 0-2-2Z",
167
- heatmap: "M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z",
168
- download: "M12 4v11M7 10l5 5 5-5M5 20h14",
169
- bookmark: "M7 4h10a1 1 0 0 1 1 1v15l-6-4-6 4V5a1 1 0 0 1 1-1Z",
170
- sliders: "M4 7h10M18 7h2M4 17h4M12 17h8M16 5v4M10 15v4",
171
- filter: "M4 5h16l-6 7.5V19l-4-2v-4.5Z",
172
- more: "M12 6h.01M12 12h.01M12 18h.01",
173
- plus: "M12 5v14M5 12h14",
174
- check: "m5 12 5 5 9-10",
175
- sortAsc: "M7 4v16M3 8l4-4 4 4M14 6h7M14 12h5M14 18h3",
176
- sortDesc: "M7 4v16M3 16l4 4 4-4M14 6h3M14 12h5M14 18h7",
177
- panel: "M4 5h16v14H4zM9 5v14",
178
- layout: "M4 5h7v6H4zM13 5h7v6h-7zM4 13h7v6H4zM13 13h7v6h-7z",
179
- trash: "M5 7h14M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3",
180
- save: "M5 4h11l3 3v13H5zM8 4v5h7V4M8 20v-6h8v6",
181
- sparkle: "M12 4l1.8 4.6L18 10l-4.2 1.4L12 16l-1.8-4.6L6 10l4.2-1.4Z",
182
- rows: "M4 6h16M4 12h16M4 18h16",
183
- cols: "M6 4v16M12 4v16M18 4v16",
184
- sigma: "M18 5H6l6 7-6 7h12",
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",
187
- image: "M4 5h16v14H4zM4 16l5-5 4 4 3-3 4 4M15 9h.01",
188
- file: "M6 3h8l4 4v14H6zM14 3v4h4",
189
- newFile: "M6 3h8l4 4v14H6zM14 3v4h4M12 11v6M9 14h6",
190
- swap: "M7 4 3 8l4 4M3 8h14M17 20l4-4-4-4M21 16H7",
191
- top: "M4 20v-6h5v6M9 20V8h6v12M15 20v-9h5v9M3 20h18",
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",
193
- copy: "M8 8h11v12H8zM5 16V4h11",
194
- upload: "M12 16V5M7 10l5-5 5 5M5 20h14",
195
- drag: "M12 3v18M3 12h18M12 3l-3 3M12 3l3 3M12 21l-3-3M12 21l3-3M3 12l3-3M3 12l3 3M21 12l-3-3M21 12l-3 3",
196
- enlarge: "M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7",
197
- fullScreen: "M3 8V3h5M21 8V3h-5M3 16v5h5M21 16v5h-5"
198
- };
199
- function Icon({ name: name2, size = 16, className }) {
200
- return /* @__PURE__ */ React.createElement("svg", { className: className ? `pk-icon ${className}` : "pk-icon", width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false" }, /* @__PURE__ */ React.createElement("path", { d: PATHS[name2] ?? PATHS.info }));
201
- }
202
- var TYPE_ICON = { string: "text", number: "number", date: "date", boolean: "boolean", null: "text" };
203
- var ZONE_ICON = { rows: "rows", cols: "cols", values: "sigma", filters: "filter" };
204
-
205
269
  // src/clear-input.jsx
206
- import React2, { useRef } from "react";
270
+ import React, { useRef } from "react";
207
271
  function emptyField(el) {
208
272
  el.focus({ preventScroll: true });
209
273
  let done;
@@ -228,6 +292,7 @@ function ClearInput({ value, onChange, onClear, clearLabel, multiline = false, c
228
292
  /** @type {HTMLInputElement | HTMLTextAreaElement | null} */
229
293
  null
230
294
  );
295
+ const name2 = useFormName();
231
296
  const ref = inputRef ?? own;
232
297
  const clear = () => {
233
298
  if (ref.current) {
@@ -244,7 +309,7 @@ function ClearInput({ value, onChange, onClear, clearLabel, multiline = false, c
244
309
  }
245
310
  };
246
311
  const Tag = multiline ? "textarea" : "input";
247
- return /* @__PURE__ */ React2.createElement("span", { className: `pk-clear-input${multiline ? " pk-clear-multi" : ""}${className ? ` ${className}` : ""}` }, /* @__PURE__ */ React2.createElement(Tag, { ...rest, ref, value, onChange: (e) => onChange(e.target.value), onKeyDown }), value !== "" ? /* @__PURE__ */ React2.createElement(
312
+ return /* @__PURE__ */ React.createElement("span", { className: `pk-clear-input${multiline ? " pk-clear-multi" : ""}${className ? ` ${className}` : ""}` }, /* @__PURE__ */ React.createElement(Tag, { name: name2, ...rest, ref, value, onChange: (e) => onChange(e.target.value), onKeyDown }), value !== "" ? /* @__PURE__ */ React.createElement(
248
313
  "button",
249
314
  {
250
315
  type: "button",
@@ -256,398 +321,32 @@ function ClearInput({ value, onChange, onClear, clearLabel, multiline = false, c
256
321
  onClick: clear,
257
322
  "data-testid": "clear-input"
258
323
  },
259
- /* @__PURE__ */ React2.createElement(Icon, { name: "x", size: 14 })
324
+ /* @__PURE__ */ React.createElement(Icon, { name: "x", size: 14 })
260
325
  ) : null);
261
326
  }
262
327
 
263
- // src/dom.js
264
- import { useEffect, useRef as useRef2 } from "react";
265
- var FOCUSABLE = "button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex='-1'])";
266
- function rootOf(node) {
267
- const root = node && typeof node.getRootNode === "function" ? node.getRootNode() : null;
268
- if (root && (root.nodeType === 9 || root.nodeType === 11)) {
269
- return (
270
- /** @type {Document | ShadowRoot} */
271
- root
272
- );
273
- }
274
- return typeof document !== "undefined" ? document : null;
275
- }
276
- function activeIn(node) {
277
- return rootOf(node)?.activeElement ?? null;
278
- }
279
- function eventWithin(event, elements) {
280
- const path = typeof event.composedPath === "function" ? event.composedPath() : [];
281
- return elements.some((el) => el && (path.includes(el) || event.target instanceof Node && el.contains(event.target)));
282
- }
283
- function tabbables(container) {
284
- return (
285
- /** @type {HTMLElement[]} */
286
- [...container.querySelectorAll(FOCUSABLE)].filter((el) => !el.closest("[inert]") && el.getClientRects().length > 0)
287
- );
288
- }
289
- function trapTab(event, container) {
290
- if (event.key !== "Tab" || !container) {
291
- return;
292
- }
293
- const list = tabbables(container);
294
- if (list.length === 0) {
295
- event.preventDefault();
296
- return;
297
- }
298
- const first = list[0];
299
- const last = list[list.length - 1];
300
- const active = activeIn(container);
301
- if (event.shiftKey && (active === first || !container.contains(active))) {
302
- event.preventDefault();
303
- last.focus();
304
- } else if (!event.shiftKey && (active === last || !container.contains(active))) {
305
- event.preventDefault();
306
- first.focus();
307
- }
308
- }
309
- var layers = [];
310
- function useEscapeLayer(open, onClose) {
311
- const close = useRef2(onClose);
312
- useEffect(() => {
313
- close.current = onClose;
314
- });
315
- useEffect(() => {
316
- if (!open || typeof document === "undefined") {
317
- return void 0;
318
- }
319
- const token = {};
320
- layers.push(token);
321
- const onKey = (e) => {
322
- if (e.key === "Escape" && layers[layers.length - 1] === token && !e.defaultPrevented) {
323
- e.preventDefault();
324
- close.current();
325
- }
326
- };
327
- document.addEventListener("keydown", onKey);
328
- return () => {
329
- document.removeEventListener("keydown", onKey);
330
- layers.splice(layers.indexOf(token), 1);
331
- };
332
- }, [open]);
333
- }
334
- function useModal(ref, open, onClose, opener) {
335
- useEscapeLayer(open, onClose);
336
- useEffect(() => {
337
- const el = ref.current;
338
- if (!open || !el) {
339
- return void 0;
340
- }
341
- const was = activeIn(el);
342
- const plain = !was || was === el.ownerDocument.body || was.classList.contains("pk-root");
343
- const back = plain && opener ? el.closest(".pk-root")?.querySelector(opener) ?? was : was;
344
- const t = requestAnimationFrame(() => {
345
- const first = (
346
- /** @type {HTMLElement | null} */
347
- el.querySelector("[data-autofocus]") ?? tabbables(el)[0] ?? el
348
- );
349
- first.focus({ preventScroll: true });
350
- });
351
- return () => {
352
- cancelAnimationFrame(t);
353
- const target = (
354
- /** @type {HTMLElement | null} */
355
- back
356
- );
357
- const now = activeIn(el);
358
- if (target && target.isConnected && (!now || el.contains(now) || now === el.ownerDocument.body)) {
359
- target.focus({ preventScroll: true });
360
- }
361
- };
362
- }, [ref, open, opener]);
363
- return { onKeyDown: (e) => trapTab(e, ref.current) };
364
- }
365
-
366
- // src/iso.js
367
- import { useEffect as useEffect2, useLayoutEffect } from "react";
368
- var useIsoLayoutEffect = typeof window !== "undefined" && typeof document !== "undefined" ? useLayoutEffect : useEffect2;
369
-
370
- // src/popover.jsx
371
- import React3, { createContext, useCallback, useContext, useEffect as useEffect3, useId, useRef as useRef3, useState } from "react";
372
- import { createPortal } from "react-dom";
373
-
374
- // src/place.js
375
- var MARGIN = 8;
376
- var GAP = 6;
377
- function placePopover(anchor, size, viewport, align = "start", { fill: fill2 = false } = {}) {
378
- const below = viewport.height - anchor.bottom - GAP - MARGIN;
379
- const above = anchor.top - GAP - MARGIN;
380
- const wanted = align === "end" ? anchor.right - size.width : anchor.left;
381
- const left = Math.max(MARGIN, Math.min(wanted, viewport.width - size.width - MARGIN));
382
- const most = Math.max(0, viewport.height - 2 * MARGIN);
383
- if (fill2 && size.height > below && size.height > above) {
384
- const height2 = Math.min(size.height, most);
385
- const side2 = below >= above ? "below" : "above";
386
- const near = side2 === "below" ? anchor.bottom + GAP : anchor.top - GAP - height2;
387
- return { top: Math.max(MARGIN, Math.min(near, viewport.height - MARGIN - height2)), left, maxHeight: most, side: side2 };
388
- }
389
- const side = size.height <= below || below >= above ? "below" : "above";
390
- const room = side === "below" ? below : above;
391
- const height = Math.min(size.height, room);
392
- const top = side === "below" ? anchor.bottom + GAP : anchor.top - GAP - height;
393
- return { top: Math.max(MARGIN, top), left, maxHeight: Math.max(120, room), side };
394
- }
395
- function fromOrigin(place, origin) {
396
- return { ...place, top: place.top - origin.top, left: place.left - origin.left };
397
- }
398
-
399
- // src/popover.jsx
400
- var LayerContext = createContext({ layer: (
401
- /** @type {HTMLElement | null} */
402
- null
403
- ), size: "wide" });
404
- var OPTION = "[data-pk-option]:not([disabled])";
405
- function wheelScrollsInside(path, popover, dx, dy) {
406
- for (const node of path) {
407
- if (!(node instanceof Element)) {
408
- continue;
409
- }
410
- const style = node.ownerDocument.defaultView?.getComputedStyle(node);
411
- const scrolls = (overflow) => overflow === "auto" || overflow === "scroll";
412
- if (style && scrolls(style.overflowY) && (dy < 0 && node.scrollTop > 0 || dy > 0 && node.scrollTop + node.clientHeight < node.scrollHeight - 1)) {
413
- return true;
414
- }
415
- if (style && scrolls(style.overflowX) && (dx < 0 && node.scrollLeft > 0 || dx > 0 && node.scrollLeft + node.clientWidth < node.scrollWidth - 1)) {
416
- return true;
417
- }
418
- if (node === popover) {
419
- return false;
420
- }
421
- }
422
- return false;
423
- }
424
- function Popover({ open, anchor, onClose, label, role = "dialog", align = "start", className, id, passive = false, fill: fill2 = false, onPointerEnter, onPointerLeave, children }) {
425
- const { layer, size } = useContext(LayerContext);
426
- const ref = useRef3(
427
- /** @type {HTMLDivElement | null} */
428
- null
429
- );
430
- const [pos, setPos] = useState(
431
- /** @type {null | { top: number, left: number, maxHeight: number, side: string }} */
432
- null
433
- );
434
- const sheet = size === "narrow" && !passive;
435
- useIsoLayoutEffect(() => {
436
- if (!open) {
437
- setPos(null);
438
- return void 0;
439
- }
440
- const place = () => {
441
- const el2 = ref.current;
442
- const a = anchor.current;
443
- if (!el2 || !a || sheet) {
444
- return;
445
- }
446
- const r = a.getBoundingClientRect();
447
- const place2 = placePopover(r, { width: el2.offsetWidth, height: el2.scrollHeight }, { width: window.innerWidth, height: window.innerHeight }, align, { fill: fill2 });
448
- const probe = layer?.querySelector(".pk-origin");
449
- setPos(probe ? fromOrigin(place2, probe.getBoundingClientRect()) : place2);
450
- };
451
- place();
452
- const el = ref.current;
453
- const ro = typeof ResizeObserver === "function" && el ? new ResizeObserver(place) : null;
454
- if (ro && el) {
455
- ro.observe(el);
456
- }
457
- window.addEventListener("resize", place);
458
- window.addEventListener("scroll", place, true);
459
- return () => {
460
- ro?.disconnect();
461
- window.removeEventListener("resize", place);
462
- window.removeEventListener("scroll", place, true);
463
- };
464
- }, [open, anchor, align, sheet, layer, fill2]);
465
- useEscapeLayer(open, onClose);
466
- const closeRef = useRef3(onClose);
467
- useEffect3(() => {
468
- closeRef.current = onClose;
469
- });
470
- useEffect3(() => {
471
- if (!open || passive) {
472
- return void 0;
473
- }
474
- const el = ref.current;
475
- const shown = (o) => o.getClientRects().length > 0;
476
- const first = el?.querySelector("[data-autofocus]") ?? [...el?.querySelectorAll(OPTION) ?? []].find(shown) ?? [...el?.querySelectorAll(FOCUSABLE) ?? []].find(shown);
477
- const t = requestAnimationFrame(() => (
478
- /** @type {HTMLElement | null} */
479
- first?.focus({ preventScroll: true })
480
- ));
481
- const onDown = (e) => {
482
- if (!eventWithin(e, [el, anchor.current])) {
483
- closeRef.current();
484
- }
485
- };
486
- const doc = el?.ownerDocument ?? document;
487
- doc.addEventListener("pointerdown", onDown, true);
488
- const onWheel = (e) => {
489
- if (el && !e.ctrlKey && !wheelScrollsInside(e.composedPath(), el, e.deltaX, e.deltaY)) {
490
- e.preventDefault();
491
- }
492
- };
493
- el?.addEventListener("wheel", onWheel, { passive: false });
494
- const button = anchor.current;
495
- return () => {
496
- cancelAnimationFrame(t);
497
- doc.removeEventListener("pointerdown", onDown, true);
498
- el?.removeEventListener("wheel", onWheel);
499
- const now = activeIn(button);
500
- if (button && button.isConnected && (!now || now === doc.body || el?.contains(now) || !now.isConnected)) {
501
- button.focus({ preventScroll: true });
502
- }
503
- };
504
- }, [open, anchor, passive]);
505
- if (!open || !layer) {
506
- return null;
507
- }
508
- const onKeyDown = (e) => {
509
- if (role === "menu" && e.key === "Tab") {
510
- e.preventDefault();
511
- onClose();
512
- return;
513
- }
514
- if (sheet) {
515
- trapTab(e, ref.current);
516
- }
517
- if (e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "Home" || e.key === "End") {
518
- const options = (
519
- /** @type {HTMLElement[]} */
520
- [...ref.current?.querySelectorAll(OPTION) ?? []].filter((o) => o.getClientRects().length > 0)
521
- );
522
- if (options.length === 0 || e.target instanceof HTMLInputElement && e.target.type !== "checkbox") {
523
- return;
524
- }
525
- e.preventDefault();
526
- const at = options.indexOf(
527
- /** @type {HTMLElement} */
528
- activeIn(ref.current)
529
- );
530
- const next = e.key === "Home" ? 0 : e.key === "End" ? options.length - 1 : (at + (e.key === "ArrowDown" ? 1 : -1) + options.length) % options.length;
531
- options[next].focus();
532
- }
533
- };
534
- const onBlur = (e) => {
535
- const to = (
536
- /** @type {Node | null} */
537
- e.relatedTarget
538
- );
539
- if (to && !ref.current?.contains(to) && !anchor.current?.contains(to)) {
540
- onClose();
541
- }
542
- };
543
- const style = sheet ? void 0 : pos ? { top: pos.top, left: pos.left, maxHeight: pos.maxHeight } : { top: 0, left: 0, visibility: (
544
- /** @type {const} */
545
- "hidden"
546
- ) };
547
- return createPortal(
548
- /* @__PURE__ */ React3.createElement(React3.Fragment, null, sheet ? /* @__PURE__ */ React3.createElement("div", { className: "pk-scrim", onClick: onClose, "aria-hidden": "true" }) : null, /* @__PURE__ */ React3.createElement(
549
- "div",
550
- {
551
- ref,
552
- id,
553
- role,
554
- "aria-label": passive ? void 0 : label,
555
- "aria-modal": sheet && role === "dialog" ? true : void 0,
556
- className: `pk-popover${sheet ? " pk-sheet" : ""}${pos?.side === "above" ? " pk-above" : ""}${className ? ` ${className}` : ""}`,
557
- style,
558
- onKeyDown,
559
- onBlur: sheet || passive ? void 0 : onBlur,
560
- onPointerEnter,
561
- onPointerLeave,
562
- tabIndex: passive ? void 0 : -1
563
- },
564
- children
565
- )),
566
- layer
567
- );
568
- }
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 }) {
570
- const [open, setOpen] = useState(false);
571
- const own = useRef3(
572
- /** @type {HTMLButtonElement | null} */
573
- null
574
- );
575
- const ref = buttonRef ?? own;
576
- const id = useId();
577
- const close = useCallback(() => setOpen(false), []);
578
- return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
579
- "button",
580
- {
581
- ref,
582
- type: "button",
583
- className: className ?? "pk-btn",
584
- "aria-haspopup": role === "menu" ? "menu" : "dialog",
585
- "aria-expanded": open,
586
- "aria-controls": open ? id : void 0,
587
- "aria-label": name2 ?? (showText && text ? void 0 : label),
588
- title: title ?? (showText && text ? void 0 : label),
589
- disabled,
590
- tabIndex,
591
- "data-pk-slot": slot,
592
- "data-testid": testId,
593
- onClick: () => setOpen((o) => !o)
594
- },
595
- icon ? /* @__PURE__ */ React3.createElement(Icon, { name: (
596
- /** @type {any} */
597
- icon
598
- ) }) : null,
599
- showText && text ? /* @__PURE__ */ React3.createElement("span", { className: "pk-btn-text" }, text) : null,
600
- mark,
601
- showText && text ? /* @__PURE__ */ React3.createElement(Icon, { name: "chevronDown", size: 14, className: "pk-caret" }) : null
602
- ), /* @__PURE__ */ React3.createElement(Popover, { open, anchor: ref, onClose: close, label, role, align, className: popoverClass, id, fill: fill2 }, children(close)));
603
- }
604
- function Option({ onSelect, icon, checked, children, hint, reason, inMenu = false, disabled, danger, tone, testId, current }) {
605
- const second = disabled && reason ? reason : hint;
606
- const role = inMenu ? checked === void 0 ? "menuitem" : "menuitemradio" : void 0;
607
- return /* @__PURE__ */ React3.createElement(
608
- "button",
609
- {
610
- type: "button",
611
- role,
612
- "aria-checked": inMenu && checked !== void 0 ? checked : void 0,
613
- "aria-pressed": !inMenu && checked !== void 0 ? checked : void 0,
614
- "aria-current": current ? "true" : void 0,
615
- className: `pk-option${checked ? " pk-checked" : ""}${danger ? " pk-danger" : ""}${tone === "accent" ? " pk-accent" : ""}`,
616
- "data-pk-option": "",
617
- "data-testid": testId,
618
- disabled,
619
- onClick: onSelect
620
- },
621
- /* @__PURE__ */ React3.createElement("span", { className: "pk-option-icon" }, checked || current ? /* @__PURE__ */ React3.createElement(Icon, { name: "check" }) : icon ? /* @__PURE__ */ React3.createElement(Icon, { name: (
622
- /** @type {any} */
623
- icon
624
- ) }) : null),
625
- /* @__PURE__ */ React3.createElement("span", { className: "pk-option-text" }, children, second ? /* @__PURE__ */ React3.createElement("span", { className: "pk-option-hint" }, second) : null)
626
- );
627
- }
628
-
629
328
  // src/info.jsx
630
- import React4, { useCallback as useCallback2, useEffect as useEffect4, useId as useId2, useRef as useRef4, useState as useState2 } from "react";
329
+ import React2, { useCallback, useEffect, useId, useRef as useRef2, useState } from "react";
631
330
  var LEAVE_DELAY = 250;
632
331
  function FieldDescription({ info, labels, link = true, className = "pk-field-desc" }) {
633
- return /* @__PURE__ */ React4.createElement("p", { className }, /* @__PURE__ */ React4.createElement("span", null, info.description), link && info.href ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, " ", /* @__PURE__ */ React4.createElement("a", { href: info.href, target: "_blank", rel: "noopener noreferrer", className: "pk-learn-more" }, labels.learnMore)) : null);
332
+ return /* @__PURE__ */ React2.createElement("p", { className }, /* @__PURE__ */ React2.createElement("span", null, info.description), link && info.href ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, " ", /* @__PURE__ */ React2.createElement("a", { href: info.href, target: "_blank", rel: "noopener noreferrer", className: "pk-learn-more" }, labels.learnMore)) : null);
634
333
  }
635
334
  function InfoButton({ info, name: name2, labels, className, testId = "field-info", label: named, tabIndex, slot }) {
636
- const [mode, setMode] = useState2(
335
+ const [mode, setMode] = useState(
637
336
  /** @type {null | "peek" | "open"} */
638
337
  null
639
338
  );
640
- const ref = useRef4(
339
+ const ref = useRef2(
641
340
  /** @type {HTMLButtonElement | null} */
642
341
  null
643
342
  );
644
- const quiet = useRef4(false);
645
- const leaving = useRef4(
343
+ const quiet = useRef2(false);
344
+ const leaving = useRef2(
646
345
  /** @type {ReturnType<typeof setTimeout> | null} */
647
346
  null
648
347
  );
649
- const id = useId2();
650
- const textId = useId2();
348
+ const id = useId();
349
+ const textId = useId();
651
350
  const stay = () => {
652
351
  if (leaving.current) {
653
352
  clearTimeout(leaving.current);
@@ -658,8 +357,8 @@ function InfoButton({ info, name: name2, labels, className, testId = "field-info
658
357
  stay();
659
358
  leaving.current = setTimeout(() => setMode((m) => m === "peek" ? null : m), LEAVE_DELAY);
660
359
  };
661
- useEffect4(() => stay, []);
662
- const close = useCallback2(() => {
360
+ useEffect(() => stay, []);
361
+ const close = useCallback(() => {
663
362
  quiet.current = true;
664
363
  setMode(null);
665
364
  requestAnimationFrame(() => {
@@ -667,7 +366,7 @@ function InfoButton({ info, name: name2, labels, className, testId = "field-info
667
366
  });
668
367
  }, []);
669
368
  const label = named ?? fill(labels.aboutField, { field: name2 });
670
- return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
369
+ return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
671
370
  "button",
672
371
  {
673
372
  ref,
@@ -711,8 +410,8 @@ function InfoButton({ info, name: name2, labels, className, testId = "field-info
711
410
  setMode(mode === "open" ? null : "open");
712
411
  }
713
412
  },
714
- /* @__PURE__ */ React4.createElement(Icon, { name: "info", size: 14 })
715
- ), /* @__PURE__ */ React4.createElement("span", { id: textId, hidden: true }, info.description), /* @__PURE__ */ React4.createElement(
413
+ /* @__PURE__ */ React2.createElement(Icon, { name: "info", size: 14 })
414
+ ), /* @__PURE__ */ React2.createElement("span", { id: textId, hidden: true }, info.description), /* @__PURE__ */ React2.createElement(
716
415
  Popover,
717
416
  {
718
417
  key: mode ?? "closed",
@@ -731,7 +430,7 @@ function InfoButton({ info, name: name2, labels, className, testId = "field-info
731
430
  }
732
431
  }
733
432
  },
734
- /* @__PURE__ */ React4.createElement(FieldDescription, { info, labels })
433
+ /* @__PURE__ */ React2.createElement(FieldDescription, { info, labels })
735
434
  ));
736
435
  }
737
436
 
@@ -909,6 +608,21 @@ function numberRange(encoded, field) {
909
608
  }
910
609
  return min <= max ? { min, max } : null;
911
610
  }
611
+ function dateSpan(encoded, field) {
612
+ const column = encoded.column(field);
613
+ if (!column || column.type !== "date") {
614
+ return null;
615
+ }
616
+ let min = Infinity;
617
+ let max = -Infinity;
618
+ for (const v of column.dict) {
619
+ if (typeof v === "number") {
620
+ min = Math.min(min, v);
621
+ max = Math.max(max, v);
622
+ }
623
+ }
624
+ return min <= max ? { min, max } : null;
625
+ }
912
626
  function groupField(view, field, unit, options = {}) {
913
627
  const spec = view.derived.find((d) => same(d.name, field));
914
628
  const source = spec ? spec.field : field;
@@ -1108,13 +822,118 @@ function isEmptyView(view) {
1108
822
  }
1109
823
 
1110
824
  // src/help.js
1111
- import { createContext as createContext2 } from "react";
1112
- var HelpContext = createContext2(
825
+ import { createContext } from "react";
826
+ var HelpContext = createContext(
1113
827
  /** @type {Help} */
1114
- { explain: true, isOpen: () => true, setOpen: () => {
1115
- }, labels: null }
828
+ { explain: true, labels: null }
1116
829
  );
1117
830
 
831
+ // src/share.js
832
+ import { VIEW_FILE_LIMITS, fromViewFile, normalize } from "pivotkit-core";
833
+ var linkModule = null;
834
+ var linkLoaded = null;
835
+ function loadLink() {
836
+ linkModule ??= import("pivotkit-core/link").then((m) => {
837
+ linkLoaded = m;
838
+ return m;
839
+ });
840
+ return linkModule;
841
+ }
842
+ var linkNow = () => linkLoaded;
843
+ function linkParam(storageKey) {
844
+ return storageKey ? `pivot-${storageKey}` : "pivot";
845
+ }
846
+ var entries = (fragment) => fragment ? fragment.split("&") : [];
847
+ var isEntry = (entry, param) => entry.startsWith(`${encodeURIComponent(param)}=`);
848
+ function readLinkParam(hash, param) {
849
+ const text = typeof hash === "string" ? hash.replace(/^#/, "") : "";
850
+ const entry = entries(text).find((e) => isEntry(e, param));
851
+ const value = entry ? entry.slice(encodeURIComponent(param).length + 1) : "";
852
+ return value ? value : null;
853
+ }
854
+ function withLinkParam(url, param, encoded) {
855
+ const at = url.indexOf("#");
856
+ const base = at === -1 ? url : url.slice(0, at);
857
+ const kept = entries(at === -1 ? "" : url.slice(at + 1)).filter((e) => !isEntry(e, param));
858
+ const next = encoded ? [...kept, `${encodeURIComponent(param)}=${encoded}`] : kept;
859
+ return next.length ? `${base}#${next.join("&")}` : base;
860
+ }
861
+ function shareBase(shareLink, here) {
862
+ if (shareLink === true) {
863
+ if (!here) {
864
+ return null;
865
+ }
866
+ try {
867
+ const url = new URL(here);
868
+ return `${url.origin}${url.pathname}${url.hash}`;
869
+ } catch {
870
+ return null;
871
+ }
872
+ }
873
+ return typeof shareLink === "string" && shareLink.trim() ? shareLink.trim() : null;
874
+ }
875
+ var viewStorageName = (key) => `pivotkit:view:${key ?? ""}`;
876
+ function readStoredView(key, storage) {
877
+ if (!storage) {
878
+ return null;
879
+ }
880
+ try {
881
+ return storage.getItem(viewStorageName(key));
882
+ } catch {
883
+ return null;
884
+ }
885
+ }
886
+ function writeStoredView(key, storage, view) {
887
+ if (!storage) {
888
+ return;
889
+ }
890
+ try {
891
+ storage.setItem(viewStorageName(key), JSON.stringify(view));
892
+ } catch {
893
+ }
894
+ }
895
+ var VIEW_TEXT_MAX = VIEW_FILE_LIMITS.text;
896
+ var quoteNames = (names, labels) => {
897
+ const shown = names.slice(0, 5).map((n) => fill(labels.quote, { text: n.length > 60 ? `${n.slice(0, 59)}\u2026` : n })).join(", ");
898
+ return names.length > 5 ? `${shown} \u2026` : shown;
899
+ };
900
+ var FAILED = Object.freeze({ newerFormat: "newer", newerView: "newer" });
901
+ function viewFromText(text, encoded, options = {}) {
902
+ return viewFromObject(text, encoded, options);
903
+ }
904
+ function viewFromObject(input, encoded, options = {}) {
905
+ const file = fromViewFile(input, { data: encoded, sourceId: options.sourceId });
906
+ if (file.failed || !file.view) {
907
+ const failed = file.failed ?? "notView";
908
+ return { view: null, issues: file.issues, failed: Object.hasOwn(FAILED, failed) ? FAILED[failed] : failed, file };
909
+ }
910
+ const { view, issues } = normalize(file.view, encoded, options.limits ? { limits: options.limits } : void 0);
911
+ if (issues.some((i) => i.path === "version")) {
912
+ return { view: null, issues, failed: "newer", file };
913
+ }
914
+ return { view, issues, failed: null, file };
915
+ }
916
+ function loadCheck(loaded2, labels, sources = []) {
917
+ const fit = loaded2.file?.compatible;
918
+ if (!loaded2.view || !fit || fit.ok) {
919
+ return null;
920
+ }
921
+ const lines2 = [];
922
+ const fileSource = loaded2.file?.source;
923
+ const target = fit.source === "other" && fileSource?.id ? sources.find((s) => s && s.id === fileSource.id) : void 0;
924
+ if (fit.source === "other") {
925
+ const name2 = target?.name || fileSource?.name || fileSource?.id;
926
+ lines2.push(name2 ? fill(labels.loadCheckSource, { source: name2 }) : labels.loadCheckOtherSource);
927
+ }
928
+ if (fit.missing.length) {
929
+ lines2.push(fill(labels.loadCheckMissing, { fields: quoteNames(fit.missing, labels) }));
930
+ }
931
+ if (fit.changed.length) {
932
+ lines2.push(fill(labels.loadCheckChanged, { fields: quoteNames(fit.changed.map((c) => c.name), labels) }));
933
+ }
934
+ return { lines: lines2, switchTo: target ? { id: target.id, name: target.name || target.id } : null };
935
+ }
936
+
1118
937
  // src/storage.js
1119
938
  function localStore() {
1120
939
  try {
@@ -1381,48 +1200,7 @@ var SWITCHES = Object.freeze([ALL_TIPS, NO_EXPLANATIONS, FIELDS_COLLAPSED]);
1381
1200
  function fieldsCollapsed(session, forced, dismissed) {
1382
1201
  return session ?? (forced === "collapsed" || forced === "open" ? forced === "collapsed" : dismissed.includes(FIELDS_COLLAPSED));
1383
1202
  }
1384
- var SECTIONS = Object.freeze({
1385
- // a value's menu
1386
- summarize: true,
1387
- showAs: true,
1388
- format: false,
1389
- highlight: false,
1390
- move: false,
1391
- // a field's menu on Rows or Columns
1392
- sort: true,
1393
- groupBy: true,
1394
- bins: true,
1395
- topN: true,
1396
- filters: true,
1397
- // the toolbar's menus
1398
- totals: true,
1399
- help: true,
1400
- // the Export menus (the toolbar's and the drill-down's)
1401
- exportDownload: true,
1402
- exportCopy: true,
1403
- thisView: true,
1404
- sharedViews: true,
1405
- myViews: true,
1406
- share: false,
1407
- chartType: true,
1408
- chartDisplay: false
1409
- });
1410
- function sectionOpen(id, dismissed) {
1411
- if (dismissed.includes(`open:${id}`)) {
1412
- return true;
1413
- }
1414
- if (dismissed.includes(`closed:${id}`)) {
1415
- return false;
1416
- }
1417
- return Object.hasOwn(SECTIONS, id) ? SECTIONS[id] : true;
1418
- }
1419
- function withSection(dismissed, id, open) {
1420
- const rest = dismissed.filter((d) => d !== `open:${id}` && d !== `closed:${id}`);
1421
- const def = Object.hasOwn(SECTIONS, id) ? SECTIONS[id] : true;
1422
- return open === def ? rest : [...rest, `${open ? "open" : "closed"}:${id}`];
1423
- }
1424
- var isSection = (id) => /^(open|closed):/.test(id) && Object.hasOwn(SECTIONS, id.slice(id.indexOf(":") + 1));
1425
- var keptOnReset = (id) => SWITCHES.includes(id) || isSection(id);
1203
+ var keptOnReset = (id) => SWITCHES.includes(id);
1426
1204
  function helpSwitch(forced, dismissed, off = NO_EXPLANATIONS) {
1427
1205
  if (forced === "on" || forced === "off") {
1428
1206
  return { on: forced === "on", user: false };
@@ -1513,7 +1291,7 @@ function allowedTips(value) {
1513
1291
  return list.map((id) => String(id).trim()).filter((id) => TIP_IDS.includes(id));
1514
1292
  }
1515
1293
  function cleanDismissed(value) {
1516
- return Array.isArray(value) ? [...new Set(value.filter((id) => typeof id === "string" && (SWITCHES.includes(id) || TIP_IDS.includes(id) || isSection(id))))] : [];
1294
+ return Array.isArray(value) ? [...new Set(value.filter((id) => typeof id === "string" && (SWITCHES.includes(id) || TIP_IDS.includes(id))))] : [];
1517
1295
  }
1518
1296
  var storageName = (key) => `pivotkit:tips:${key}`;
1519
1297
  function readStored(key, storage) {
@@ -1542,111 +1320,20 @@ function withoutFilters(view) {
1542
1320
  return { ...view, filters: filterZoneFields(view).map((field) => ({ field, type: "exclude", items: [] })) };
1543
1321
  }
1544
1322
 
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;
1323
+ // src/lazy-import.js
1324
+ var pending = null;
1325
+ var loaded = null;
1326
+ function loadImport() {
1327
+ pending ??= import("../import-ui.js").then(
1328
+ (m) => loaded = m,
1329
+ (error) => {
1330
+ pending = null;
1331
+ throw error;
1579
1332
  }
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 };
1333
+ );
1334
+ return pending;
1649
1335
  }
1336
+ var importNow = () => loaded;
1650
1337
 
1651
1338
  export {
1652
1339
  CHART_TYPES,
@@ -1659,24 +1346,21 @@ export {
1659
1346
  refLabel,
1660
1347
  sortText,
1661
1348
  valueConditionText,
1349
+ dayText,
1350
+ isoDay,
1351
+ relativeDays,
1352
+ periodText,
1353
+ rangeShare,
1354
+ relativeText,
1355
+ wholeYears,
1356
+ itemRuleText,
1662
1357
  groupingName,
1663
1358
  fieldAction,
1664
1359
  layoutSummary,
1665
1360
  DRILL_LIMIT,
1666
1361
  decodeRow,
1667
1362
  drillRows,
1668
- Icon,
1669
- TYPE_ICON,
1670
- ZONE_ICON,
1671
1363
  ClearInput,
1672
- rootOf,
1673
- activeIn,
1674
- useModal,
1675
- useIsoLayoutEffect,
1676
- LayerContext,
1677
- Popover,
1678
- MenuButton,
1679
- Option,
1680
1364
  InfoButton,
1681
1365
  ZONES,
1682
1366
  clone,
@@ -1689,6 +1373,7 @@ export {
1689
1373
  moveField,
1690
1374
  reorder,
1691
1375
  numberRange,
1376
+ dateSpan,
1692
1377
  groupField,
1693
1378
  groupingOf,
1694
1379
  sourceOf,
@@ -1713,6 +1398,17 @@ export {
1713
1398
  swapAxes,
1714
1399
  isEmptyView,
1715
1400
  HelpContext,
1401
+ loadLink,
1402
+ linkNow,
1403
+ linkParam,
1404
+ readLinkParam,
1405
+ withLinkParam,
1406
+ shareBase,
1407
+ readStoredView,
1408
+ writeStoredView,
1409
+ viewFromText,
1410
+ viewFromObject,
1411
+ loadCheck,
1716
1412
  localStore,
1717
1413
  readItem,
1718
1414
  subscribeItem,
@@ -1721,9 +1417,6 @@ export {
1721
1417
  NO_EXPLANATIONS,
1722
1418
  FIELDS_COLLAPSED,
1723
1419
  fieldsCollapsed,
1724
- sectionOpen,
1725
- withSection,
1726
- isSection,
1727
1420
  keptOnReset,
1728
1421
  helpSwitch,
1729
1422
  SHORTCUTS,
@@ -1738,15 +1431,6 @@ export {
1738
1431
  subscribeStored,
1739
1432
  writeDismissed,
1740
1433
  withoutFilters,
1741
- loadLink,
1742
- linkNow,
1743
- linkParam,
1744
- readLinkParam,
1745
- withLinkParam,
1746
- shareBase,
1747
- readStoredView,
1748
- writeStoredView,
1749
- viewFromText,
1750
- viewFromObject,
1751
- loadCheck
1434
+ loadImport,
1435
+ importNow
1752
1436
  };