pivotkit-react 0.4.0 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. package/CHANGELOG.md +219 -1
  2. package/README.md +2 -2
  3. package/dist/chunks/{chunk-YITKWZ4L.js → chunk-2AT72SLA.js} +604 -505
  4. package/dist/chunks/{chunk-ZYEYZSYL.js → chunk-3E4NB5RZ.js} +30 -2
  5. package/dist/chunks/{chunk-6MDAL3IO.js → chunk-3WUGQPWV.js} +78 -6
  6. package/dist/chunks/{chunk-WB4GKWFQ.js → chunk-4RS72AAA.js} +26 -4
  7. package/dist/chunks/{chunk-EM23V5GH.js → chunk-E6M57YLL.js} +19 -8
  8. package/dist/chunks/{chunk-RWYHJRQO.js → chunk-JMRTIOX4.js} +17 -7
  9. package/dist/chunks/{chunk-XN55BQ4M.js → chunk-RIOSIYGC.js} +54 -7
  10. package/dist/chunks/{chunk-LEN5RPBM.js → chunk-U5Q5I2D5.js} +34 -5
  11. package/dist/chunks/report-run-BZBFOMPF.js +12 -0
  12. package/dist/chunks/{unused-texts-K3VFH65P.js → unused-texts-Y4R67XSN.js} +1 -1
  13. package/dist/chunks/{unused-texts-de-OW4TGIVX.js → unused-texts-de-6YVPTNVS.js} +1 -1
  14. package/dist/echarts.js +38 -156
  15. package/dist/import-ui.js +8 -12
  16. package/dist/index.js +97 -82
  17. package/dist/labels.js +6 -6
  18. package/dist/menu-texts-de.js +1 -1
  19. package/dist/menus.js +650 -245
  20. package/dist/styles.css +207 -93
  21. package/package.json +8 -4
  22. package/types/chart-decorate.d.ts +28 -4
  23. package/types/chart-types.d.ts +2 -4
  24. package/types/echarts.d.ts +1 -1
  25. package/types/export-run.d.ts +37 -3
  26. package/types/filter.d.ts +1 -1
  27. package/types/icons.d.ts +1 -0
  28. package/types/import-labels.d.ts +41 -0
  29. package/types/import-limits.d.ts +6 -0
  30. package/types/index.d.ts +25 -7
  31. package/types/labels.d.ts +198 -2
  32. package/types/light-tokens.d.ts +16 -0
  33. package/types/menu-labels.d.ts +37 -14
  34. package/types/menu-ops.d.ts +161 -40
  35. package/types/menu-topics.d.ts +7 -4
  36. package/types/names.d.ts +47 -19
  37. package/types/place.d.ts +24 -0
  38. package/types/print-frame.d.ts +24 -0
  39. package/types/report-run.d.ts +14 -0
  40. package/types/share-actions.d.ts +3 -3
  41. package/types/share.d.ts +13 -17
  42. package/types/theme.d.ts +2 -16
  43. package/types/tips.d.ts +5 -0
  44. package/types/toolbar-panels.d.ts +5 -4
  45. package/types/unused-texts.d.ts +13 -3
  46. package/types/use-export.d.ts +2 -2
  47. package/types/view-ops.d.ts +65 -6
  48. package/types/chart-layout.d.ts +0 -111
package/dist/menus.js CHANGED
@@ -4,6 +4,7 @@ import {
4
4
  ClearInput,
5
5
  HelpContext,
6
6
  InfoButton,
7
+ RULE_OPS,
7
8
  SHORTCUTS,
8
9
  SLICE_TYPES,
9
10
  ZONES,
@@ -13,11 +14,13 @@ import {
13
14
  dateSpan,
14
15
  dayText,
15
16
  decodeRow,
17
+ emptyPick,
16
18
  filterZoneFields,
17
19
  filtersOf,
18
20
  groupField,
19
21
  groupingName,
20
22
  groupingOf,
23
+ hiddenNot,
21
24
  importNow,
22
25
  isoDay,
23
26
  itemRuleText,
@@ -26,15 +29,20 @@ import {
26
29
  loadLink,
27
30
  moveField,
28
31
  numericResult,
32
+ opOf,
29
33
  periodText,
34
+ pickFilter,
35
+ plainRange,
30
36
  rangeShare,
31
37
  readLinkParam,
32
38
  refLabel,
33
39
  relativeDays,
34
40
  relativeText,
35
41
  reorder,
42
+ ruleOp,
36
43
  same,
37
44
  sameRef,
45
+ searchItems,
38
46
  selectedItems,
39
47
  setSort,
40
48
  shareBase,
@@ -48,12 +56,12 @@ import {
48
56
  viewFromText,
49
57
  wholeYears,
50
58
  withLinkParam
51
- } from "./chunks/chunk-YITKWZ4L.js";
59
+ } from "./chunks/chunk-2AT72SLA.js";
52
60
  import {
53
61
  addMenuTexts,
54
62
  hasMenuTexts,
55
63
  menuLabels
56
- } from "./chunks/chunk-LEN5RPBM.js";
64
+ } from "./chunks/chunk-U5Q5I2D5.js";
57
65
  import {
58
66
  Group,
59
67
  Icon,
@@ -66,28 +74,28 @@ import {
66
74
  stopAfter,
67
75
  useFormName,
68
76
  useModal
69
- } from "./chunks/chunk-XN55BQ4M.js";
77
+ } from "./chunks/chunk-RIOSIYGC.js";
70
78
  import {
71
79
  fill,
72
80
  hostFailure,
73
81
  messageOf,
74
82
  plural
75
- } from "./chunks/chunk-6MDAL3IO.js";
83
+ } from "./chunks/chunk-3WUGQPWV.js";
76
84
 
77
85
  // src/chip-menus.jsx
78
- import React6, { useId as useId4, useState as useState4 } from "react";
79
- import { fieldLabel as fieldLabel4 } from "pivotkit-core";
86
+ import React6, { useId as useId4, useMemo as useMemo3, useState as useState4 } from "react";
87
+ import { computePivot as computePivot2, fieldLabel as fieldLabel4 } from "pivotkit-core";
80
88
 
81
89
  // src/filter-level.jsx
82
90
  import React5, { useContext as useContext3, useEffect as useEffect2, useId as useId3, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
83
- import { CATALOG as CATALOG4, LIMITS, fieldItems as fieldItems2, fieldLabel as fieldLabel3, formatter as formatter2 } from "pivotkit-core";
91
+ import { CATALOG as CATALOG3, LIMITS as LIMITS2, fieldItems as fieldItems2, fieldLabel as fieldLabel3, formatter as formatter2, relativeDateRange } from "pivotkit-core";
84
92
 
85
93
  // src/filter.jsx
86
94
  import React, { useMemo, useState } from "react";
87
- import { CATALOG as CATALOG2, fieldItems, fieldLabel } from "pivotkit-core";
95
+ import { LIMITS, fieldItems, fieldLabel } from "pivotkit-core";
88
96
 
89
97
  // src/menu-ops.js
90
- import { CATALOG, computePivot, isFormat } from "pivotkit-core";
98
+ import { CATALOG, MATCH_DEFAULTS, computePivot, isFormat } from "pivotkit-core";
91
99
  var COUNTING = /* @__PURE__ */ new Set(["count", "countUnique", "listUnique"]);
92
100
  var unitOf = (agg) => COUNTING.has(agg) ? "count" : "field";
93
101
  function updateValue(view, index, patch, options = {}) {
@@ -135,7 +143,7 @@ function replaceFilters(view, field, types, entries) {
135
143
  kept.splice(at, 0, ...entries);
136
144
  next.filters = kept;
137
145
  if (!axisOf(next, field) && filterZoneFields(view).some((f) => same(f, field)) && !kept.some((f) => same(f.field, field))) {
138
- next.filters.splice(at, 0, { field, type: "exclude", items: [] });
146
+ next.filters.splice(at, 0, emptyPick(field));
139
147
  }
140
148
  return next;
141
149
  }
@@ -156,7 +164,7 @@ function replaceFilter(view, field, previous, entry) {
156
164
  } else {
157
165
  next.filters.splice(at, 1);
158
166
  if (!axisOf(next, field) && filterZoneFields(view).some((f) => same(f, field)) && !next.filters.some((f) => same(f.field, field))) {
159
- next.filters.splice(at, 0, { field, type: "exclude", items: [] });
167
+ next.filters.splice(at, 0, emptyPick(field));
160
168
  }
161
169
  }
162
170
  return next;
@@ -164,22 +172,27 @@ function replaceFilter(view, field, previous, entry) {
164
172
  function setItemFilter(view, field, selected, all) {
165
173
  const keep = new Set(selected.map((v) => JSON.stringify(v)));
166
174
  const excluded = all.filter((v) => !keep.has(JSON.stringify(v)));
167
- return replaceFilters(view, field, ["include", "exclude"], excluded.length ? [{ field, type: "exclude", items: excluded }] : []);
175
+ return replaceFilters(view, field, ["in"], excluded.length ? [pickFilter(field, excluded)] : []);
168
176
  }
169
177
  function setLabelFilter(view, field, condition) {
170
- return replaceFilters(view, field, ["label"], condition && condition.value !== "" ? [{ field, type: "label", op: condition.op, value: condition.value }] : []);
178
+ return replaceFilters(view, field, ["text"], condition && condition.value !== "" ? [textRule(field, condition)] : []);
171
179
  }
180
+ var textRule = (field, { op, value, on }) => ({ field, type: "text", ...opOf(op), value, on, match: { ...MATCH_DEFAULTS }, blanks: "exclude" });
181
+ var textOn = (encoded, field) => encoded.column(field)?.type === "string" ? "value" : "label";
172
182
  function setTopFilter(view, field, top, previous) {
173
- const entry = top ? { field, type: "top", count: top.count, bottom: Boolean(top.bottom), ...top.by ? { by: top.by } : {} } : null;
183
+ const ties = top?.ties ?? previous?.ties;
184
+ const entry = top ? { field, type: "top", count: top.count, bottom: Boolean(top.bottom), ...top.by ? { by: top.by } : {}, ...ties === "all" ? { ties: "all" } : {} } : null;
174
185
  if (previous) {
175
186
  return replaceFilter(view, field, previous, entry);
176
187
  }
177
188
  return replaceFilters(view, field, ["top"], entry ? [entry] : []);
178
189
  }
179
- var RULE_TYPES = Object.freeze(["relative", "compare", "value", "label"]);
190
+ var RULE_TYPES = Object.freeze(["relative", "compare", "value", "text"]);
180
191
  var RULES_MAX = 10;
181
192
  var setRule = (view, field, previous, entry) => replaceFilter(view, field, previous, entry);
182
193
  var COARSE = Object.freeze(["year", "yearQuarter"]);
194
+ var QUICK_UNITS = Object.freeze(["day", "week", "month", "quarter", "year"]);
195
+ var FINEST = Object.freeze({ day: "day", yearWeek: "week", yearMonth: "month", yearQuarter: "quarter", year: "year" });
183
196
  function ruleKind(encoded, view, field) {
184
197
  const grouping = groupingOf(view, field);
185
198
  const source = encoded.column(sourceOf(view, field))?.type ?? "string";
@@ -187,10 +200,12 @@ function ruleKind(encoded, view, field) {
187
200
  const item = grouping ? grouping.by === "day" ? "date" : "group" : source === "number" || source === "date" ? source : null;
188
201
  const cyclic = dates && Boolean(grouping) && CATALOG.cyclicUnits.includes(grouping.by);
189
202
  const quick = dates && !cyclic;
190
- return { item, dates, cyclic, quick, months: quick && !COARSE.includes(grouping?.by), days: quick && item === "date", unit: grouping?.by ?? null };
203
+ const finest = grouping ? Object.hasOwn(FINEST, grouping.by) ? FINEST[grouping.by] : "day" : "day";
204
+ const units = quick ? QUICK_UNITS.slice(QUICK_UNITS.indexOf(finest)) : [];
205
+ return { item, dates, cyclic, quick, months: quick && !COARSE.includes(grouping?.by), days: quick && item === "date", unit: grouping?.by ?? null, units };
191
206
  }
192
207
  function ruleText(view, f, { labels, locale, timeZone, date, labelOf, span }) {
193
- return f.type === "value" ? valueConditionText(view, f, labels, locale) : itemRuleText(f, labels, locale, { timeZone, date, labelOf, span });
208
+ return f.type === "value" ? valueConditionText(view, f, labels, locale) : itemRuleText(f, labels, locale, { timeZone, date, labelOf, span, weekStart: view.formatting?.weekStart });
194
209
  }
195
210
  function quickChoice(view, field, fk, all = []) {
196
211
  const ranges = filtersOf(view, field, ["relative"]);
@@ -200,16 +215,16 @@ function quickChoice(view, field, fk, all = []) {
200
215
  const years = whole.length ? yearsCombined(whole, all) : null;
201
216
  return years ? { id: "yearsCombined", years, filters: whole } : { id: "all", filters: [] };
202
217
  }
203
- const offered = { year: true, month: fk.months, day: fk.days };
204
- const r = ranges.find((f) => offered[f.unit]);
218
+ const units = fk.units ?? [];
219
+ const r = ranges.find((f) => units.includes(f.unit) && !f.not && f.blanks !== "only");
205
220
  if (!r) {
206
221
  return { id: "all", filters: [] };
207
222
  }
208
223
  const id = (
209
- /** @type {"thisYear" | "years" | "months" | "days"} */
210
- r.unit === "year" ? r.count === 1 ? "thisYear" : "years" : `${r.unit}s`
224
+ /** @type {"this" | "last" | "next" | "before"} */
225
+ r.direction ?? "last"
211
226
  );
212
- return { id, count: r.count, anchor: r.anchor ?? "today", filters: [r] };
227
+ return { id, unit: r.unit, count: r.count ?? 1, anchor: r.anchor ?? "today", calendar: r.calendar !== false, includeCurrent: r.includeCurrent !== false, filters: [r] };
213
228
  }
214
229
  function yearsCombined(compared, all) {
215
230
  let kept = new Set(all);
@@ -218,45 +233,76 @@ function yearsCombined(compared, all) {
218
233
  /** @type {[string, string]} */
219
234
  wholeYears(f.value, f.value2).map(Number)
220
235
  );
221
- kept = new Set([...kept].filter((y) => (a <= y && y <= b) === (f.op === "between")));
236
+ kept = new Set([...kept].filter((y) => (a <= y && y <= b) !== f.not));
222
237
  }
223
238
  return kept.size ? [...kept].sort((x, y) => x - y) : null;
224
239
  }
225
- var isWholeYear = (f) => f.type === "compare" && (f.op === "between" || f.op === "notBetween") && wholeYears(f.value, f.value2) !== null;
226
- function yearRules(field, years, all) {
240
+ var isWholeYear = (f) => f.type === "compare" && f.op === "between" && f.blanks !== "only" && wholeYears(f.value, f.value2) !== null;
241
+ function yearRules(field, years, all, blanks = "exclude") {
227
242
  if (!years.length || years.length === all.length) {
228
243
  return [];
229
244
  }
230
245
  const day = (y, last) => `${String(y).padStart(4, "0")}-${last ? "12-31" : "01-01"}`;
231
- const rule = (op, from, to) => ({ field, type: "compare", op, value: day(from, false), value2: day(to, true) });
232
- const rules = [rule("between", years[0], years[years.length - 1])];
246
+ const rule = (not, from, to) => ({ field, type: "compare", op: "between", value: day(from, false), value2: day(to, true), not, blanks });
247
+ const rules = [rule(false, years[0], years[years.length - 1])];
233
248
  for (let i = 1; i < years.length; i++) {
234
249
  if (all.some((y) => years[i - 1] < y && y < years[i])) {
235
- rules.push(rule("notBetween", years[i - 1] + 1, years[i] - 1));
250
+ rules.push(rule(true, years[i - 1] + 1, years[i] - 1));
236
251
  }
237
252
  }
238
253
  return rules;
239
254
  }
240
255
  function setYearsCombined(view, field, years, all) {
256
+ const blanks = keepsBlanks(view, field) ? "include" : "exclude";
241
257
  const cleared = filtersOf(view, field, ["compare"]).filter(isWholeYear).reduce((v, f) => setRule(v, field, f, null), view);
242
- return yearRules(field, years, all).reduce((v, r) => setRule(v, field, null, r), cleared);
243
- }
244
- function setQuickRange(view, field, range) {
245
- return replaceFilters(view, field, ["relative"], range ? [{ field, type: "relative", unit: range.unit, count: range.count, ...range.anchor === "latest" ? { anchor: "latest" } : {} }] : []);
258
+ return yearRules(field, years, all, blanks).reduce((v, r) => setRule(v, field, null, r), cleared);
246
259
  }
260
+ function setQuickRange(view, field, range, previous) {
261
+ const entry = range ? relativeRule(field, range) : null;
262
+ if (previous !== void 0) {
263
+ return replaceFilter(view, field, previous, entry);
264
+ }
265
+ return replaceFilters(view, field, ["relative"], entry ? [entry] : []);
266
+ }
267
+ var relativeRule = (field, { direction = "last", unit, count, anchor, calendar = true, includeCurrent = true, blanks = "exclude" }) => ({
268
+ field,
269
+ type: "relative",
270
+ ...direction === "last" ? {} : { direction },
271
+ unit,
272
+ ...direction === "this" ? {} : { count },
273
+ ...calendar ? {} : { calendar: false },
274
+ ...includeCurrent || !calendar || direction === "this" ? {} : { includeCurrent: false },
275
+ ...anchor && anchor !== "today" ? { anchor } : {},
276
+ not: false,
277
+ blanks
278
+ });
247
279
  function setAnchor(view, field, anchor) {
248
280
  const next = clone(view);
249
281
  for (const f of next.filters) {
250
282
  if (same(f.field, field) && f.type === "relative") {
251
283
  delete f.anchor;
252
- if (anchor === "latest") {
253
- f.anchor = "latest";
284
+ if (anchor !== "today") {
285
+ f.anchor = anchor;
254
286
  }
255
287
  }
256
288
  }
257
289
  return next;
258
290
  }
259
- var resetFilter = (view, field) => replaceFilters(view, field, ["include", "exclude", ...RULE_TYPES], []);
291
+ var ITEM_RULE_TYPES = Object.freeze(["relative", "compare", "text"]);
292
+ function keepsBlanks(view, field) {
293
+ const rules = filtersOf(view, field, ITEM_RULE_TYPES);
294
+ return rules.length > 0 && rules.every((f) => f.blanks === "include");
295
+ }
296
+ function setRuleBlanks(view, field, keep) {
297
+ const next = clone(view);
298
+ for (const f of next.filters) {
299
+ if (same(f.field, field) && ITEM_RULE_TYPES.includes(f.type)) {
300
+ f.blanks = keep ? "include" : "exclude";
301
+ }
302
+ }
303
+ return next;
304
+ }
305
+ var resetFilter = (view, field) => replaceFilters(view, field, ["in", "blank", ...RULE_TYPES], []);
260
306
  function itemTotals(encoded, view, field, by, filters) {
261
307
  const result = computePivot(encoded, { ...view, rows: [field], cols: [], values: [{ ...by.field ? { field: by.field } : {}, agg: by.agg }], filters, sort: [] });
262
308
  const totals = /* @__PURE__ */ new Map();
@@ -287,17 +333,18 @@ function removeRules(view, field, keep = []) {
287
333
  return filtersOf(view, field, RULE_TYPES).filter((f) => !kept.has(JSON.stringify(f))).reduce((v, f) => setRule(v, field, f, null), view);
288
334
  }
289
335
  var TOTALS = Object.freeze(["grandTotalRow", "grandTotalColumn", "rowSubtotals", "colSubtotals"]);
336
+ var AXIS_NEEDS = Object.freeze({
337
+ grandTotalRow: { zone: "rows", fields: 1, why: "needsRowField" },
338
+ grandTotalColumn: { zone: "cols", fields: 1, why: "needsColField" },
339
+ rowSubtotals: { zone: "rows", fields: 2, why: "needsRowFields" },
340
+ colSubtotals: { zone: "cols", fields: 2, why: "needsColFields" }
341
+ });
290
342
  function totalNoEffect(view, key) {
291
- if (key === "grandTotalRow") {
292
- return view.rows.length >= 1 ? null : "needsRowField";
293
- }
294
- if (key === "grandTotalColumn") {
295
- return view.cols.length >= 1 ? null : "needsColField";
296
- }
297
- if (key === "rowSubtotals") {
298
- return view.rows.length >= 2 ? null : "needsRowFields";
343
+ const axis = AXIS_NEEDS[key];
344
+ if (view[axis.zone].length < axis.fields) {
345
+ return axis.why;
299
346
  }
300
- return view.cols.length >= 2 ? null : "needsColFields";
347
+ return view.values.length > 0 ? null : "needsValue";
301
348
  }
302
349
  function conditionKind(encoded, view, field) {
303
350
  const type = encoded.column(sourceOf(view, field))?.type ?? "string";
@@ -311,12 +358,25 @@ function filterState(view, field, state, labels, locale) {
311
358
  }
312
359
  parts.push(...state?.rules ?? []);
313
360
  for (const f of view.filters.filter(same2)) {
314
- if (f.type === "value" || f.type === "label" && !state?.rules) {
361
+ if (f.type === "value" || f.type === "text" && !state?.rules) {
315
362
  parts.push(ruleText(view, f, { labels, locale, timeZone: "UTC", date: false }));
316
363
  }
317
364
  }
318
365
  return parts.length ? parts.join(", ") : null;
319
366
  }
367
+ var boundMs = (text) => Date.parse(text.length > 10 ? `${text}Z` : `${text}T00:00Z`);
368
+ function rowsInRange(range, dict, counts) {
369
+ const from = range.from === null ? -Infinity : boundMs(range.from);
370
+ const to = boundMs(range.to) + (range.to.length > 10 ? 6e4 : 864e5);
371
+ let rows = 0;
372
+ for (let code = 0; code < dict.length; code++) {
373
+ const v = dict[code];
374
+ if (typeof v === "number" && v >= from && v < to) {
375
+ rows += counts[code];
376
+ }
377
+ }
378
+ return rows;
379
+ }
320
380
 
321
381
  // src/filter.jsx
322
382
  var FILTER_LIST_MAX = 300;
@@ -324,8 +384,7 @@ var keyOf = (v) => JSON.stringify(v);
324
384
  function ValueList({ items, selected, onChange, labels, locale, autoFocus = false, tail, children }) {
325
385
  const [query, setQuery] = useState("");
326
386
  const name = useFormName();
327
- const q = query.trim().toLocaleLowerCase();
328
- const matching = q ? items.filter((i) => i.label.toLocaleLowerCase().includes(q)) : items;
387
+ const matching = searchItems(items, query);
329
388
  const inList = tail ? matching.filter((i) => !tail.isOut(i)) : matching;
330
389
  const out = tail ? matching.filter((i) => tail.isOut(i)) : [];
331
390
  const shown = inList.slice(0, FILTER_LIST_MAX);
@@ -354,7 +413,12 @@ function ValueList({ items, selected, onChange, labels, locale, autoFocus = fals
354
413
  const k = keyOf(i.value);
355
414
  return /* @__PURE__ */ React.createElement("li", { key: k, className: `pk-value${muted ? " pk-value-out" : ""}` }, /* @__PURE__ */ React.createElement("label", null, /* @__PURE__ */ React.createElement("input", { type: "checkbox", name, checked: selected.has(k), onChange: () => toggle(i.value) }), /* @__PURE__ */ React.createElement("span", { className: "pk-value-label" }, i.label), /* @__PURE__ */ React.createElement("span", { className: "pk-count" }, i.count.toLocaleString(locale))), /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-link pk-only", onClick: () => onChange(/* @__PURE__ */ new Set([k])), "aria-label": `${labels.onlyThis}: ${i.label}` }, labels.onlyThis));
356
415
  };
357
- return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("label", { className: "pk-search" }, /* @__PURE__ */ React.createElement(Icon, { name: "search" }), /* @__PURE__ */ React.createElement("span", { className: "pk-sr" }, labels.searchValues), /* @__PURE__ */ React.createElement(ClearInput, { type: "search", value: query, placeholder: labels.searchValues, onChange: setQuery, clearLabel: labels.clearText, "data-autofocus": autoFocus ? "" : void 0, "data-testid": "filter-search" })), /* @__PURE__ */ React.createElement("div", { className: "pk-filter-actions" }, /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-action", onClick: () => setAll(true), "data-testid": "select-all" }, labels.selectAll), /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-action", onClick: () => setAll(false), "data-testid": "select-none" }, labels.selectNone)), /* @__PURE__ */ React.createElement("div", { className: "pk-filter-body" }, /* @__PURE__ */ React.createElement("ul", { className: "pk-values", role: "list" }, shown.map((i) => row(i, false)), inList.length > shown.length ? /* @__PURE__ */ React.createElement("li", { className: "pk-hint pk-values-more" }, fill(labels.valuesShown, { shown: shown.length, total: inList.length.toLocaleString(locale) })) : null, out.length && tail ? tail.render(out, (i) => row(i, true), q !== "") : null), children));
416
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("label", { className: "pk-search" }, /* @__PURE__ */ React.createElement(Icon, { name: "search" }), /* @__PURE__ */ React.createElement("span", { className: "pk-sr" }, labels.searchValues), /* @__PURE__ */ React.createElement(ClearInput, { type: "search", value: query, placeholder: labels.searchValues, onChange: setQuery, clearLabel: labels.clearText, "data-autofocus": autoFocus ? "" : void 0, "data-testid": "filter-search" })), /* @__PURE__ */ React.createElement("div", { className: "pk-filter-actions" }, /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-action", onClick: () => setAll(true), "data-testid": "select-all" }, labels.selectAll), /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-action", onClick: () => setAll(false), "data-testid": "select-none" }, labels.selectNone)), /* @__PURE__ */ React.createElement("div", { className: "pk-filter-body" }, /* @__PURE__ */ React.createElement("ul", { className: "pk-values", role: "list" }, shown.map((i) => row(i, false)), inList.length > shown.length ? /* @__PURE__ */ React.createElement("li", { className: "pk-hint pk-values-more" }, fill(labels.valuesShown, { shown: shown.length, total: inList.length.toLocaleString(locale) })) : null, out.length && tail ? tail.render(
417
+ out,
418
+ (i) => row(i, true),
419
+ matching !== items
420
+ /* searchItems gives the list itself without a search */
421
+ ) : null), children));
358
422
  }
359
423
  function FilterBody({ view: current, base, field, encoded, locale, labels, commit, close }) {
360
424
  const view = base ?? current;
@@ -362,8 +426,8 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
362
426
  const info = useMemo(() => fieldItems(encoded, field, { view, locale, labels: labels.core }), [encoded, field, view, locale, labels]);
363
427
  const all = useMemo(() => info ? info.items.map((i) => i.value) : [], [info]);
364
428
  const [selected, setSelected] = useState(() => new Set(selectedItems(view, field, all).map(keyOf)));
365
- const label = filtersOf(view, field, ["label"])[0];
366
- const [op, setOp] = useState(label?.op ?? "");
429
+ const label = filtersOf(view, field, ["text"])[0];
430
+ const [op, setOp] = useState(label ? ruleOp(label) : "");
367
431
  const [text, setText] = useState(label?.value ?? "");
368
432
  if (!info) {
369
433
  return null;
@@ -371,7 +435,7 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
371
435
  const name = fieldLabel(field, labels.core);
372
436
  const apply = () => {
373
437
  let next = setItemFilter(view, field, all.filter((v) => selected.has(keyOf(v))), all);
374
- next = setLabelFilter(next, field, op ? { op, value: text } : null);
438
+ next = setLabelFilter(next, field, op ? { op, value: text, on: textOn(encoded, field) } : null);
375
439
  close();
376
440
  commit(next, { step: "filter", field: name });
377
441
  };
@@ -386,21 +450,21 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
386
450
  }
387
451
  },
388
452
  /* @__PURE__ */ React.createElement("div", { className: "pk-popover-head" }, /* @__PURE__ */ React.createElement("h3", null, fill(labels.filterTitle, { field: name })), /* @__PURE__ */ React.createElement("span", { className: "pk-muted" }, fill(labels.selected, { count: selected.size.toLocaleString(locale) }))),
389
- /* @__PURE__ */ React.createElement(ValueList, { items: info.items, selected, onChange: setSelected, labels, locale, autoFocus: true }, kind ? /* @__PURE__ */ React.createElement("fieldset", { className: "pk-condition" }, /* @__PURE__ */ React.createElement("legend", null, kind === "number" ? labels.conditionNumber : labels.condition), /* @__PURE__ */ React.createElement("select", { name: `${formName}-op`, value: op, onChange: (e) => setOp(e.target.value), "aria-label": kind === "number" ? labels.conditionNumber : labels.condition }, /* @__PURE__ */ React.createElement("option", { value: "" }, labels.conditionNone), CATALOG2.labelOps.map((o) => /* @__PURE__ */ React.createElement("option", { key: o, value: o }, labels.labelOps[o] ?? o))), op ? /* @__PURE__ */ React.createElement(
453
+ /* @__PURE__ */ React.createElement(ValueList, { items: info.items, selected, onChange: setSelected, labels, locale, autoFocus: true }, kind ? /* @__PURE__ */ React.createElement("fieldset", { className: "pk-condition" }, /* @__PURE__ */ React.createElement("legend", null, kind === "number" ? labels.conditionNumber : labels.condition), /* @__PURE__ */ React.createElement("select", { name: `${formName}-op`, value: op, onChange: (e) => setOp(e.target.value), "aria-label": kind === "number" ? labels.conditionNumber : labels.condition }, /* @__PURE__ */ React.createElement("option", { value: "" }, labels.conditionNone), RULE_OPS.text.map((o) => /* @__PURE__ */ React.createElement("option", { key: o, value: o }, labels.labelOps[o] ?? o))), op ? /* @__PURE__ */ React.createElement(
390
454
  ClearInput,
391
455
  {
392
456
  type: "text",
393
457
  value: text,
394
458
  onChange: setText,
395
459
  onClear: () => {
396
- if (!base && filtersOf(view, field, ["label"]).length) {
460
+ if (!base && filtersOf(view, field, ["text"]).length) {
397
461
  commit(setLabelFilter(view, field, null), { step: "filter", field: name });
398
462
  }
399
463
  },
400
464
  clearLabel: labels.clearText,
401
465
  "aria-label": labels.conditionValue,
402
466
  placeholder: labels.conditionValue,
403
- maxLength: 1e3,
467
+ maxLength: LIMITS.textValue,
404
468
  "data-testid": "filter-condition-text"
405
469
  }
406
470
  ) : null) : null),
@@ -431,10 +495,10 @@ function Section({ title, children, info }) {
431
495
  }
432
496
 
433
497
  // src/menu-topics.js
434
- import { CATALOG as CATALOG3, aggregatorsFor, fieldLabel as fieldLabel2, formatter, isFormat as isFormat2 } from "pivotkit-core";
498
+ import { CATALOG as CATALOG2, aggregatorsFor, fieldLabel as fieldLabel2, formatter, isFormat as isFormat2 } from "pivotkit-core";
435
499
  var FORMAT_CHOICES = Object.freeze(["number", "number:0", "number:2", "currency", "percent"].filter(isFormat2));
436
500
  var MORE_FORMATS = Object.freeze(["integer", "compact", "bytes", "duration:h", "duration:s"].filter(isFormat2));
437
- var COMMON_SHOW_AS = CATALOG3.showAs.filter((s) => ["percentOfGrandTotal", "percentOfRowTotal", "percentOfColumnTotal"].includes(s));
501
+ var COMMON_SHOW_AS = CATALOG2.showAs.filter((s) => ["percentOfGrandTotal", "percentOfRowTotal", "percentOfColumnTotal"].includes(s));
438
502
  var EXAMPLE = Object.freeze({ percent: 0.256, bytes: 1536e3, "duration:h": 1.5, "duration:s": 3725 });
439
503
  var TOP_COUNTS = Object.freeze([3, 5, 10]);
440
504
  function moveTopic(view, zone, index, count, labels, name, type, defaults) {
@@ -509,8 +573,8 @@ function axisTopics({ view, zone, index, field, types, labels, locale, state, de
509
573
  state: grouping ? labels.units[grouping.by] ?? grouping.by : labels.groupNoneShort,
510
574
  changed: Boolean(grouping),
511
575
  groups: [
512
- { title: labels.groupTimeline, choices: CATALOG3.timelineUnits.map(unit) },
513
- { title: labels.groupCyclic, choices: CATALOG3.cyclicUnits.map(unit) },
576
+ { title: labels.groupTimeline, choices: CATALOG2.timelineUnits.map(unit) },
577
+ { title: labels.groupCyclic, choices: CATALOG2.cyclicUnits.map(unit) },
514
578
  { choices: [{ id: "group-none", text: labels.groupNone, checked: !grouping, closes: true, change: regroup(null) }] }
515
579
  ]
516
580
  });
@@ -550,19 +614,21 @@ function filterTopic({ view, field, labels, locale, state, encoded }) {
550
614
  if (!Number.isSafeInteger(n) || n < 1) {
551
615
  return [];
552
616
  }
553
- const units = n > CATALOG3.relativeMaxCount ? [] : fk.months ? ["year", "month"] : ["year"];
617
+ const units = n > CATALOG2.relativeMaxCount ? [] : fk.months ? ["year", "month"] : ["year"];
554
618
  const anchor = filtersOf(view, field, ["relative"])[0]?.anchor;
619
+ const previous = quickChoice(view, field, fk).filters[0] ?? null;
620
+ const blanks = keepsBlanks(view, field) ? "include" : "exclude";
555
621
  const span = dateSpan(encoded, sourceOf(view, field));
556
622
  const ranges = units.map((unit) => {
557
623
  const text = capital2(relativeText({ unit, count: n, anchor }, labels, locale, timeZone, void 0, span));
558
- return { id: `quick-${unit}-${n}`, text, choice: { id: `quick-${unit}-${n}`, text, change: () => ({ view: setQuickRange(view, field, { unit, count: n, anchor }), note }) } };
624
+ return { id: `quick-${unit}-${n}`, text, choice: { id: `quick-${unit}-${n}`, text, change: () => ({ view: setQuickRange(view, field, { unit, count: n, anchor, blanks }, previous), note }) } };
559
625
  });
560
626
  const keyed = fk.item === "group" && n >= 1e3 && n <= 9999 && view.derived.some((d) => d.name.toLowerCase() === field.toLowerCase() && d.by === "year");
561
627
  if (!keyed) {
562
628
  return ranges;
563
629
  }
564
630
  const compares = [">=", "<=", "<", ">"].map((op) => {
565
- const entry = { field, type: "compare", op, value: n };
631
+ const entry = { field, type: "compare", op, value: n, not: false, blanks: "exclude" };
566
632
  const text = capital2(fill(labels.compareShort[op], { value: String(n) }));
567
633
  return { id: `compare-${op}-${n}`, text, choice: { id: `compare-${op}-${n}`, text, change: () => ({ view: setRule(view, field, null, entry), note }) } };
568
634
  });
@@ -579,7 +645,8 @@ function filterTopic({ view, field, labels, locale, state, encoded }) {
579
645
  // the rules are found by their names, and open the level on them
580
646
  searchExtra: [
581
647
  { id: "open-filter-rules", text: labels.rulesTitle, focus: "conditions" },
582
- { id: "open-filter-text", text: labels.addRuleName, focus: "conditions" },
648
+ // the rule on the name by its operators too ("does not begin with")
649
+ { id: "open-filter-text", text: labels.addRuleName, focus: "conditions", keywords: Object.values(labels.labelOps).join(" ") },
583
650
  { id: "open-filter-value", text: labels.addRuleTotal, focus: "conditions" }
584
651
  ],
585
652
  searchFor
@@ -612,7 +679,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
612
679
  const set = (patch) => () => ({ view: updateValue(view, index, patch, { defaults }), note: { step: "value", field: name } });
613
680
  const aggs = spec.field ? aggregatorsFor(type) : ["count"];
614
681
  const agg = (a) => ({ id: `agg-${a}`, text: labels.core.aggregators[a] ?? a, checked: spec.agg === a, closes: true, change: set({ agg: a }) });
615
- const rare = aggs.filter((a) => !CATALOG3.commonAggregators.includes(a));
682
+ const rare = aggs.filter((a) => !CATALOG2.commonAggregators.includes(a));
616
683
  const topics = [
617
684
  {
618
685
  id: "summarize",
@@ -620,7 +687,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
620
687
  kind: "menu",
621
688
  icon: "sigma",
622
689
  state: labels.core.aggregators[spec.agg] ?? spec.agg,
623
- groups: [{ choices: CATALOG3.commonAggregators.filter((a) => aggs.includes(a)).map(agg) }, ...rare.length ? [{ title: labels.moreStatistics, choices: rare.map(agg) }] : []]
690
+ groups: [{ choices: CATALOG2.commonAggregators.filter((a) => aggs.includes(a)).map(agg) }, ...rare.length ? [{ title: labels.moreStatistics, choices: rare.map(agg) }] : []]
624
691
  }
625
692
  ];
626
693
  if (numericResult(spec, type)) {
@@ -628,7 +695,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
628
695
  const text = labels.showAsNames[s] ?? s;
629
696
  return { id: `showas-${s}`, text, keywords: text.includes("%") ? labels.showAsKeywords : void 0, checked: spec.showAs?.type === s, change: set({ showAs: { type: s, axis: spec.showAs?.axis ?? "rows" } }) };
630
697
  };
631
- const along = spec.showAs && CATALOG3.showAsAlongAxis.includes(spec.showAs.type) ? spec.showAs : null;
698
+ const along = spec.showAs && CATALOG2.showAsAlongAxis.includes(spec.showAs.type) ? spec.showAs : null;
632
699
  topics.push({
633
700
  id: "showAs",
634
701
  title: labels.showAs,
@@ -639,7 +706,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
639
706
  changed: Boolean(spec.showAs),
640
707
  groups: [
641
708
  { choices: [{ id: "showas-none", text: labels.showAsNone, checked: !spec.showAs, change: set({ showAs: null }) }, ...COMMON_SHOW_AS.map(showAs)] },
642
- { title: labels.moreCalculations, choices: CATALOG3.showAs.filter((s) => !COMMON_SHOW_AS.includes(s)).map(showAs) },
709
+ { title: labels.moreCalculations, choices: CATALOG2.showAs.filter((s) => !COMMON_SHOW_AS.includes(s)).map(showAs) },
643
710
  ...along ? [{ title: labels.along, choices: ["rows", "cols"].map((axis) => ({ id: `along-${axis}`, text: labels.zones[axis], checked: along.axis === axis, change: set({ showAs: { ...along, axis } }) })) }] : []
644
711
  ]
645
712
  });
@@ -722,7 +789,7 @@ function optionTopics({ view, labels, folding, tips, explanations, act }) {
722
789
  {
723
790
  choices: TOTALS.map((key) => {
724
791
  const why = totalNoEffect(view, key);
725
- return { id: `total-${key}`, text: labels[key], checkbox: true, checked: view.totals[key], disabled: why !== null, reason: why ? labels[why] : void 0, info: key, run: () => act.total(key, !view.totals[key]) };
792
+ return { id: `total-${key}`, text: labels[key], checkbox: true, checked: why === null && view.totals[key], disabled: why !== null, reason: why ? labels[why] : void 0, info: key, run: () => act.total(key, !view.totals[key]) };
726
793
  })
727
794
  }
728
795
  ]
@@ -760,7 +827,7 @@ function searchEntries(topics, query = "") {
760
827
  return [];
761
828
  }
762
829
  const typed = query && topic.searchFor ? topic.searchFor(query) : [];
763
- const extra = [...typed, ...topic.searchExtra ?? []].map((x) => ({ id: x.id, text: x.text, path: topic.title, topic, choice: x.choice, focus: x.focus }));
830
+ const extra = [...typed, ...topic.searchExtra ?? []].map((x) => ({ id: x.id, text: x.text, path: topic.title, topic, choice: x.choice, focus: x.focus, keywords: x.keywords }));
764
831
  return topic.kind === "panel" ? [{ id: `open-${topic.id}`, text: topic.title, path: "", topic }, ...extra] : (topic.groups ?? []).flatMap((g) => g.choices.map((choice) => ({ id: choice.id, text: choice.text, path: [topic.title, g.title].filter(Boolean).join(" \u203A "), topic, choice })));
765
832
  });
766
833
  }
@@ -772,7 +839,7 @@ function searchHits(entries, query, locale) {
772
839
  return [];
773
840
  }
774
841
  const found = entries.filter((e) => {
775
- const text = lower(`${e.text} ${e.path} ${e.topic.keywords ?? ""} ${e.choice?.keywords ?? ""}`);
842
+ const text = lower(`${e.text} ${e.path} ${e.topic.keywords ?? ""} ${e.choice?.keywords ?? e.keywords ?? ""}`);
776
843
  return words.every((w) => text.includes(w));
777
844
  });
778
845
  const own = (e) => lower(e.choice?.keywords ?? "").split(/\s+/).includes(words[0]);
@@ -1340,26 +1407,17 @@ function measuresOf(view, types, labels, ref) {
1340
1407
  var twin = (op) => op === "between" || op === "notBetween";
1341
1408
  var capital = (text, locale) => text.charAt(0).toLocaleUpperCase(locale) + text.slice(1);
1342
1409
  var rulesKeyOf = (rules) => JSON.stringify(rules, (_k, v) => v && typeof v === "object" && !Array.isArray(v) ? Object.fromEntries(Object.entries(v).sort(([a], [b]) => a < b ? -1 : 1)) : v);
1343
- var rowKind = (f) => f.type === "value" ? "total" : f.type === "label" ? "name" : "item";
1344
- var REACH = Object.freeze({ year: 10, month: 24, day: 90 });
1410
+ var rowKind = (f) => !editable(f) ? "fixed" : f.type === "value" ? "total" : f.type === "text" ? "name" : "item";
1411
+ var RANGE_UNITS = Object.freeze(["year", "month", "day"]);
1412
+ var ruleRange = (f) => plainRange(f) && (f.direction ?? "last") === "last" && f.includeCurrent !== false && RANGE_UNITS.includes(f.unit);
1413
+ var editable = (f) => !hiddenNot(f) && (f.type !== "relative" || ruleRange(f)) && (f.type !== "compare" || (f.precision ?? "day") === "day");
1414
+ var REACH = Object.freeze({ year: 10, quarter: 12, month: 24, week: 104, day: 90 });
1345
1415
  var PICKER_MIN = 13;
1346
- var MS_PER_DAY = 864e5;
1347
1416
  function nounOf(fk, labels) {
1348
1417
  const unit = fk.unit;
1349
1418
  const key = unit === null ? fk.item === "number" ? "value" : fk.item === "date" ? "date" : "item" : unit === "bin" ? "range" : unit === "day" ? "day" : unit.replace(/^year(.)/, (_m, c) => c.toLowerCase());
1350
1419
  return Object.hasOwn(labels.nouns, key) ? labels.nouns[key] : labels.nouns.item;
1351
1420
  }
1352
- function rowsIn(range, column, counts) {
1353
- const from = Date.parse(`${range.from}T00:00Z`);
1354
- const to = Date.parse(`${range.to}T00:00Z`) + MS_PER_DAY;
1355
- let rows = 0;
1356
- column.dict.forEach((v, code) => {
1357
- if (typeof v === "number" && v >= from && v < to) {
1358
- rows += counts[code];
1359
- }
1360
- });
1361
- return rows;
1362
- }
1363
1421
  function countsOf(column) {
1364
1422
  const counts = new Float64Array(column.dict.length);
1365
1423
  for (let i = 0; i < column.codes.length; i++) {
@@ -1430,155 +1488,268 @@ function Summary({ ctx, state }) {
1430
1488
  }
1431
1489
  return /* @__PURE__ */ React5.createElement("div", { className: "pk-filter-summary" }, /* @__PURE__ */ React5.createElement("div", { className: `pk-summary-card${shown === 0 ? " pk-summary-empty" : ""}`, role: "status", "data-testid": "filter-summary" }, /* @__PURE__ */ React5.createElement("p", { className: "pk-summary-head", "data-testid": "filter-summary-head" }, head), /* @__PURE__ */ React5.createElement("p", { className: "pk-summary-why", "data-testid": "filter-summary-why" }, why.length ? why.join(" \xB7 ") : state.rules ? labels.summaryKept : quickWords ? fill(labels.summaryQuickOnly, { quick: quickWords }) : labels.summaryOk), /* @__PURE__ */ React5.createElement("p", { className: "pk-summary-meta", "data-testid": "filter-summary-meta" }, meta.join(" \xB7 ")), /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-action pk-summary-reset", disabled: !state.canReset, onClick: () => ctx.act(resetFilter(view, field), "section-picks"), "data-testid": "filter-reset" }, labels.resetFilter)));
1432
1490
  }
1433
- function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts }) {
1491
+ var COUNTED = Object.freeze(["last", "next", "before"]);
1492
+ var MORE = Object.freeze(["next", "before"]);
1493
+ var inMore = (quick) => MORE.includes(quick.id) || COUNTED.includes(quick.id) && quick.calendar === false;
1494
+ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts, moreOpen, setMoreOpen }) {
1434
1495
  const { view, field, labels, locale, fk, timeZone, commit, note, back } = ctx;
1435
1496
  const lang = { lang: labels.lang, locale };
1436
- const latest = span.max;
1437
- const latestDay = isoDay(latest);
1497
+ const more = labels.relativeMore;
1498
+ const units = fk.units;
1499
+ const weekStart = view.formatting?.weekStart;
1500
+ const latestDay = isoDay(span.max);
1438
1501
  const [now] = useState3(() => Date.now());
1439
- const days = (unit, count) => relativeDays({ unit, count, anchor }, timeZone, now, latest);
1502
+ const datesOf = (spec, at = anchor) => {
1503
+ try {
1504
+ return relativeDateRange(spec.unit, spec.count ?? 1, { ...spec, anchor: at, timeZone, now, latest: span.max, first: span.min, weekStart });
1505
+ } catch {
1506
+ return null;
1507
+ }
1508
+ };
1509
+ const rowsOf = (range) => range ? rowsInRange(range, column.dict, counts) : 0;
1510
+ const reaches = (r) => r !== null && r.from !== null && r.from.slice(0, 10) <= latestDay;
1440
1511
  const reach = (unit) => {
1441
1512
  for (let n = 1; n <= REACH[unit]; n++) {
1442
- const r = days(unit, n);
1443
- if (r && r.from <= latestDay) {
1513
+ if (reaches(datesOf({ unit, count: n }))) {
1444
1514
  return n;
1445
1515
  }
1446
1516
  }
1447
- return null;
1517
+ return REACH[unit];
1448
1518
  };
1449
- const defaults = useMemo2(() => ({ year: Math.max(2, reach("year") ?? REACH.year), month: reach("month") ?? REACH.month, day: reach("day") ?? REACH.day }), [anchor, latest, timeZone]);
1450
- const counted = { year: quick.id === "years" ? quick.count : defaults.year, month: quick.id === "months" ? quick.count : defaults.month, day: quick.id === "days" ? quick.count : defaults.day };
1451
- const [texts, setTexts] = useState3(() => Object.fromEntries(Object.entries(counted).map(([u, n]) => [u, numberText(n, locale)])));
1519
+ const defaultCount = (unit) => Math.max(2, reach(unit));
1520
+ const firstUnit = units.includes("month") ? "month" : units[0];
1521
+ const readCount = (text) => readNumber(text, { kind: "count", max: CATALOG3.relativeMaxCount, labels, locale });
1522
+ const rowOf = (d) => quick.id === d ? { text: numberText(quick.count, locale), unit: quick.unit, current: quick.includeCurrent } : { text: numberText(d === "next" ? 1 : defaultCount(firstUnit), locale), unit: firstUnit, current: true };
1523
+ const [rows, setRows] = useState3(() => Object.fromEntries(COUNTED.map((d) => [d, rowOf(d)])));
1524
+ const [thisUnit, setThisUnit] = useState3(quick.id === "this" ? quick.unit : "year");
1525
+ const [rolling, setRolling] = useState3(() => COUNTED.includes(quick.id) && quick.calendar === false);
1452
1526
  const [editing, setEditing] = useState3(
1453
1527
  /** @type {string | null} */
1454
1528
  null
1455
1529
  );
1456
- const quickKey = `${quick.id}:${quick.count ?? ""}:${anchor}`;
1530
+ const quickKey = JSON.stringify([quick.id, quick.unit, quick.count, quick.calendar, quick.includeCurrent]);
1457
1531
  const [seen, setSeen] = useState3(quickKey);
1458
1532
  if (quickKey !== seen) {
1459
1533
  setSeen(quickKey);
1460
- const synced = { ...texts };
1461
- for (const unit of CATALOG4.relativeUnits) {
1462
- if (unit !== editing) {
1463
- synced[unit] = numberText(counted[unit], locale);
1464
- }
1534
+ if (COUNTED.includes(quick.id)) {
1535
+ const d = quick.id;
1536
+ const own = rowOf(d);
1537
+ setRows({ ...rows, [d]: editing === d ? { ...own, text: rows[d].text } : own });
1538
+ setRolling(quick.calendar === false);
1539
+ } else if (quick.id === "this") {
1540
+ setThisUnit(
1541
+ /** @type {string} */
1542
+ quick.unit
1543
+ );
1465
1544
  }
1466
- setTexts(synced);
1467
1545
  }
1468
1546
  const later = useLater();
1469
1547
  const group = useId3();
1470
1548
  const groupName = useFormName();
1471
- const set = (range) => commit(setQuickRange(view, field, range ? { ...range, anchor } : null), note);
1549
+ const formName = useFormName();
1550
+ const anchorId = useId3();
1551
+ const moreId = useId3();
1552
+ const set = (spec) => commit(setQuickRange(view, field, spec ? { ...spec, anchor, blanks: ctx.keepBlanks ? "include" : "exclude" } : null, quick.filters[0] ?? null), note);
1553
+ const specOf = (d, row = rows[d], roll = rolling) => {
1554
+ const n = readCount(row.text).value;
1555
+ return n === null ? null : { direction: d, unit: row.unit, count: n, calendar: !roll, includeCurrent: row.current };
1556
+ };
1557
+ const subId = (id) => `${group}-${id}`;
1472
1558
  const sub = (range, unit, id) => {
1473
- const share = rangeShare(range, unit, span, locale);
1474
- if (share?.none) {
1559
+ if (!range) {
1475
1560
  return null;
1476
1561
  }
1477
- const period = share ? `${share.data} ` : periodText(range, unit, locale);
1478
- const missing = share ? fill(plural(labels.noData, share.count, lang), { range: share.missing.join(", ") }) : null;
1479
- return /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-sub", id: subId(id) }, /* @__PURE__ */ React5.createElement("span", null, period, missing ? /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-missing" }, "(", missing, ")") : null), /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-rows" }, fill(labels.quickRows, { rows: rowsIn(range, column, counts).toLocaleString(locale) })));
1562
+ const shownUnit = range.from === null || range.from.length > 10 || range.to.length > 10 ? "day" : unit;
1563
+ let period;
1564
+ let missing = null;
1565
+ if (range.from === null) {
1566
+ period = fill(more.until, { to: periodText({ from: range.to, to: range.to }, shownUnit, locale) });
1567
+ } else {
1568
+ const share = rangeShare(range, shownUnit, span, locale);
1569
+ if (share?.none) {
1570
+ period = "";
1571
+ missing = fill(plural(labels.noData, 1, lang), { range: periodText(range, shownUnit, locale) });
1572
+ } else {
1573
+ period = share ? `${share.data} ` : periodText(range, shownUnit, locale);
1574
+ missing = share ? fill(plural(labels.noData, share.count, lang), { range: share.missing.join(", ") }) : null;
1575
+ }
1576
+ }
1577
+ return /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-sub", id: subId(id) }, /* @__PURE__ */ React5.createElement("span", null, period, missing ? /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-missing" }, period ? `(${missing})` : missing) : null), /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-rows" }, fill(labels.quickRows, { rows: rowsOf(range).toLocaleString(locale) })));
1480
1578
  };
1481
- const subId = (id) => `${group}-${id}`;
1482
- const radio = (id, checked, onPick, name, children, sub2, described = Boolean(sub2)) => /* @__PURE__ */ React5.createElement("label", { className: "pk-radio pk-quick", key: id }, /* @__PURE__ */ React5.createElement("input", { type: "radio", name: groupName, checked, onChange: onPick, "aria-label": name, "aria-describedby": described ? subId(id) : void 0, "data-autofocus": checked && ctx.hint !== "conditions" ? "" : void 0, "data-testid": `quick-${id}` }), children, sub2);
1579
+ const radio = (id, checked, onPick, name, children, described = true) => /* @__PURE__ */ React5.createElement("label", { className: "pk-radio pk-quick" }, /* @__PURE__ */ React5.createElement(
1580
+ "input",
1581
+ {
1582
+ type: "radio",
1583
+ name: groupName,
1584
+ checked,
1585
+ onChange: onPick,
1586
+ "aria-label": name,
1587
+ "aria-describedby": described ? subId(id) : void 0,
1588
+ "data-autofocus": checked && ctx.hint !== "conditions" ? "" : void 0,
1589
+ "data-testid": `quick-${id}`
1590
+ }
1591
+ ), children);
1592
+ const unitPick = (value, options, onChange, testId, label) => options.length > 1 ? /* @__PURE__ */ React5.createElement("select", { name: `${formName}-${testId}`, value, onChange: (e) => onChange(e.target.value), "aria-label": label, "data-testid": testId }, options.map((o) => /* @__PURE__ */ React5.createElement("option", { key: o.value, value: o.value }, o.text))) : /* @__PURE__ */ React5.createElement("span", { "aria-hidden": "true" }, options[0]?.text);
1483
1593
  const hidden = [];
1484
- const rows = [radio("all", quick.id === "all" || quick.id === "custom", () => set(null), labels.filterAll, /* @__PURE__ */ React5.createElement("span", null, labels.filterAll), /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-sub", id: subId("all") }, /* @__PURE__ */ React5.createElement("span", null, `${dayText(isoDay(span.min), locale)}\u2013${dayText(latestDay, locale)}`), /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-rows" }, fill(labels.quickRows, { rows: column.codes.length.toLocaleString(locale) }))))];
1485
- const thisYear = days("year", 1);
1486
- const yearWords = capital(labels.relative.year, locale);
1487
- if (thisYear && sub(thisYear, "year", "thisYear")) {
1488
- rows.push(radio("thisYear", quick.id === "thisYear", () => set({ unit: "year", count: 1 }), yearWords, /* @__PURE__ */ React5.createElement("span", null, yearWords), sub(thisYear, "year", "thisYear")));
1489
- } else if (thisYear) {
1490
- hidden.push(`${yearWords} (${periodText(thisYear, "year", locale)})`);
1491
- }
1492
- for (
1493
- const unit of
1494
- /** @type {const} */
1495
- ["year", "month", "day"]
1496
- ) {
1497
- if (unit === "month" && !fk.months || unit === "day" && !fk.days) {
1498
- continue;
1499
- }
1500
- const read = readNumber(texts[unit], { kind: "count", max: CATALOG4.relativeMaxCount, labels, locale });
1501
- const n = read.value;
1502
- const id = `${unit}s`;
1503
- const shown = n ?? counted[unit];
1504
- const forms = Object.fromEntries(Object.entries(labels.quickLast[unit]).map(([k, v]) => [k, String(v).replace("{count}", "{n}")]));
1505
- const words = plural(forms, shown, lang);
1506
- const [before, after] = words.split("{n}");
1507
- const range = days(unit, shown);
1508
- const line = range ? sub(range, unit, id) : null;
1509
- if (!line) {
1510
- if (quick.id !== id) {
1511
- hidden.push(fill(words, { n: shown.toLocaleString(locale) }));
1512
- continue;
1594
+ const main = [
1595
+ /* @__PURE__ */ React5.createElement("div", { className: "pk-quick-row", key: "all" }, radio("all", quick.id === "all", () => set(null), labels.filterAll, /* @__PURE__ */ React5.createElement("span", null, labels.filterAll)), /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-sub", id: subId("all") }, /* @__PURE__ */ React5.createElement("span", null, `${dayText(isoDay(span.min), locale)}\u2013${dayText(latestDay, locale)}`), /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-rows" }, fill(labels.quickRows, { rows: column.codes.length.toLocaleString(locale) }))))
1596
+ ];
1597
+ const thisUnits = units.filter((u) => rowsOf(datesOf({ direction: "this", unit: u })) > 0 || quick.id === "this" && quick.unit === u);
1598
+ if (thisUnits.length) {
1599
+ const u = thisUnits.includes(thisUnit) ? thisUnit : thisUnits[thisUnits.length - 1];
1600
+ const name = capital(more.this[u], locale);
1601
+ main.push(
1602
+ /* @__PURE__ */ React5.createElement("div", { className: "pk-quick-row", key: "this" }, radio("this", quick.id === "this", () => set({ direction: "this", unit: u }), name, thisUnits.length > 1 ? null : /* @__PURE__ */ React5.createElement("span", { "aria-hidden": "true" }, name)), thisUnits.length > 1 && unitPick(
1603
+ u,
1604
+ thisUnits.map((o) => ({ value: o, text: capital(more.this[o], locale) })),
1605
+ (v) => {
1606
+ setThisUnit(v);
1607
+ set({ direction: "this", unit: v });
1608
+ },
1609
+ "quick-this-unit",
1610
+ labels.quickThisUnit
1611
+ ), sub(datesOf({ direction: "this", unit: u }), u, "this"))
1612
+ );
1613
+ } else {
1614
+ const year = datesOf({ direction: "this", unit: "year" });
1615
+ if (year?.from) {
1616
+ hidden.push(`${capital(more.this.year, locale)} (${periodText({ from: year.from, to: year.to }, "year", locale)})`);
1617
+ }
1618
+ }
1619
+ const counted = (d) => {
1620
+ const row = rows[d];
1621
+ const read = readCount(row.text);
1622
+ const n = read.value ?? 2;
1623
+ const formOf = (unit) => plural(Object.fromEntries(Object.entries(more[d][unit]).map(([k, v]) => [k, String(v).replace("{count}", "{n}")])), n, lang);
1624
+ const [before] = formOf(row.unit).split("{n}");
1625
+ const name = capital(fill(formOf(row.unit), { n: n.toLocaleString(locale) }), locale);
1626
+ const range = datesOf({ direction: d, unit: row.unit, count: n, calendar: !rolling, includeCurrent: row.current });
1627
+ const change = (patch, wait = false) => {
1628
+ const next = { ...row, ...patch };
1629
+ setRows({ ...rows, [d]: next });
1630
+ const run = () => {
1631
+ const spec = specOf(d, next);
1632
+ if (spec) {
1633
+ set(spec);
1634
+ }
1635
+ };
1636
+ if (wait) {
1637
+ later.later(run);
1638
+ } else {
1639
+ later.cancel();
1640
+ run();
1513
1641
  }
1514
- }
1515
- const pick = () => set({ unit, count: shown });
1516
- rows.push(
1517
- /* @__PURE__ */ React5.createElement("div", { className: "pk-quick-row", key: unit }, radio(id, quick.id === id, pick, fill(words, { n: shown.toLocaleString(locale) }), /* @__PURE__ */ React5.createElement("span", { "aria-hidden": "true" }, before), null, Boolean(line)), /* @__PURE__ */ React5.createElement(
1518
- NumberField,
1519
- {
1520
- value: texts[unit],
1521
- onChange: (t) => {
1522
- setTexts({ ...texts, [unit]: t });
1523
- later.later(() => {
1524
- const v = readNumber(t, { kind: "count", max: CATALOG4.relativeMaxCount, labels, locale }).value;
1525
- if (v !== null) {
1526
- set({ unit, count: v });
1527
- }
1528
- });
1529
- },
1530
- onKeyDown: fieldKeys({
1531
- now: later.now,
1532
- restore: () => {
1533
- later.cancel();
1534
- const was = numberText(counted[unit], locale);
1535
- if (texts[unit] === was) {
1536
- return false;
1537
- }
1538
- setTexts({ ...texts, [unit]: was });
1539
- return true;
1540
- },
1541
- back
1542
- }),
1543
- onBlur: () => {
1544
- setEditing(null);
1545
- later.now();
1642
+ };
1643
+ const pickUnit = (unit) => {
1644
+ const r = d === "last" && read.value !== null ? datesOf({ unit, count: read.value, calendar: !rolling, includeCurrent: row.current }) : null;
1645
+ const keep = d !== "last" || reaches(r);
1646
+ change({ unit, ...keep ? {} : { text: numberText(defaultCount(unit), locale) } });
1647
+ };
1648
+ const current = datesOf({ direction: "this", unit: row.unit });
1649
+ const currentEmpty = current?.from ? rowsOf(current) === 0 : false;
1650
+ return /* @__PURE__ */ React5.createElement("div", { className: "pk-quick-row", key: d }, radio(d, quick.id === d, () => change({}), name, /* @__PURE__ */ React5.createElement("span", { "aria-hidden": "true" }, capital(before.trimEnd(), locale)), range !== null), /* @__PURE__ */ React5.createElement(
1651
+ NumberField,
1652
+ {
1653
+ value: row.text,
1654
+ onChange: (t) => change({ text: t }, true),
1655
+ onKeyDown: fieldKeys({
1656
+ now: later.now,
1657
+ restore: () => {
1658
+ later.cancel();
1659
+ if (quick.id !== d) {
1660
+ return false;
1661
+ }
1662
+ const was = numberText(
1663
+ /** @type {number} */
1664
+ quick.count,
1665
+ locale
1666
+ );
1667
+ if (row.text === was) {
1668
+ return false;
1669
+ }
1670
+ setRows({ ...rows, [d]: { ...row, text: was } });
1671
+ return true;
1546
1672
  },
1547
- onFocus: () => setEditing(unit),
1548
- problem: read.problem,
1549
- label: labels.quickCount[unit],
1550
- testId: `quick-${id}-count`,
1551
- className: "pk-field-label pk-count-input"
1552
- }
1553
- ), /* @__PURE__ */ React5.createElement("span", { "aria-hidden": "true" }, after), line)
1554
- );
1555
- }
1673
+ back
1674
+ }),
1675
+ onBlur: () => {
1676
+ setEditing(null);
1677
+ later.now();
1678
+ },
1679
+ onFocus: () => setEditing(d),
1680
+ problem: read.problem,
1681
+ label: labels.quickCount[row.unit] ?? labels.quickCount.year,
1682
+ testId: `quick-${d}-count`,
1683
+ className: "pk-field-label pk-count-input"
1684
+ }
1685
+ ), unitPick(
1686
+ row.unit,
1687
+ units.map((u) => ({ value: u, text: formOf(u).split("{n}")[1]?.trim() ?? u })),
1688
+ pickUnit,
1689
+ `quick-${d}-unit`,
1690
+ fill(labels.quickUnitOf, { choice: capital(before.trimEnd(), locale) })
1691
+ ), sub(range, row.unit, d), quick.id === d && !rolling ? /* @__PURE__ */ React5.createElement("label", { className: "pk-check pk-quick-current" }, /* @__PURE__ */ React5.createElement("input", { type: "checkbox", name: `${formName}-${d}-current`, checked: row.current, onChange: (e) => change({ current: e.target.checked }), "data-testid": `quick-${d}-current` }), /* @__PURE__ */ React5.createElement("span", null, labels.quickCurrent[row.unit], currentEmpty ? /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-missing" }, ` (${fill(plural(labels.noData, 1, lang), { range: current?.from ? periodText({ from: current.from, to: current.to }, row.unit, locale) : "" })})`) : null)) : null, quick.id === d && d !== "next" && currentEmpty && anchor === "today" ? /* @__PURE__ */ React5.createElement("div", { className: "pk-quick-fix" }, /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-btn pk-small-btn", onClick: () => setAnchorTo("latest"), "data-testid": `quick-${d}-from-latest` }, /* @__PURE__ */ React5.createElement(Icon, { name: "date", size: 14 }), /* @__PURE__ */ React5.createElement("span", { className: "pk-btn-text" }, fill(labels.anchorUseLatest, { date: dayText(latestDay, locale) })))) : null);
1692
+ };
1693
+ main.push(counted("last"));
1556
1694
  const today = new Date(relativeDays({ unit: "day", count: 1 }, timeZone, now)?.from ?? isoDay(now));
1557
1695
  const periodStart = fk.months ? Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), 1) : Date.UTC(today.getUTCFullYear(), 0, 1);
1558
- const showAnchor = latest < periodStart;
1559
- const anchorId = useId3();
1560
- const anchorName = useFormName();
1561
- return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { role: "radiogroup", "aria-label": labels.quickTitle, className: "pk-radios pk-quick-choices", "data-testid": "quick-choices" }, rows), showAnchor ? /* @__PURE__ */ React5.createElement("div", { className: "pk-quick-anchor" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: anchorId }, labels.anchorLabel), /* @__PURE__ */ React5.createElement(
1562
- "select",
1696
+ const [anchorOutside] = useState3(() => span.max < periodStart || anchor !== "today");
1697
+ const anchorKind = ["today", "latest", "first"].includes(anchor) ? anchor : "date";
1698
+ const [day, setDay] = useState3(anchorKind === "date" ? anchor.slice(0, 10) : latestDay);
1699
+ const dayWhole = /^\d{4}-\d{2}-\d{2}$/.test(day);
1700
+ const [seenAnchor, setSeenAnchor] = useState3(anchor);
1701
+ if (anchor !== seenAnchor) {
1702
+ setSeenAnchor(anchor);
1703
+ if (anchorKind === "date") {
1704
+ setDay(anchor.slice(0, 10));
1705
+ }
1706
+ }
1707
+ const dayHint = `${anchorId}-hint`;
1708
+ const setAnchorTo = (a) => {
1709
+ setAnchorLocal(a);
1710
+ if (quick.filters.length) {
1711
+ commit(setAnchor(view, field, a), note);
1712
+ }
1713
+ };
1714
+ const anchorRow = /* @__PURE__ */ React5.createElement("div", { className: "pk-quick-anchor" }, /* @__PURE__ */ React5.createElement("label", { htmlFor: anchorId }, labels.anchorLabel), /* @__PURE__ */ React5.createElement("select", { id: anchorId, name: `${formName}-anchor`, value: anchorKind, onChange: (e) => setAnchorTo(e.target.value === "date" ? dayWhole ? day : latestDay : e.target.value), "data-testid": "quick-anchor" }, /* @__PURE__ */ React5.createElement("option", { value: "today" }, fill(labels.anchorToday, { date: dayText(isoDay(today.getTime()), locale) })), /* @__PURE__ */ React5.createElement("option", { value: "latest" }, fill(labels.anchorLatest, { date: dayText(latestDay, locale) })), /* @__PURE__ */ React5.createElement("option", { value: "first" }, fill(labels.anchorFirst, { date: dayText(isoDay(span.min), locale) })), /* @__PURE__ */ React5.createElement("option", { value: "date" }, labels.anchorDate)), anchorKind === "date" ? /* @__PURE__ */ React5.createElement(
1715
+ "input",
1563
1716
  {
1564
- id: anchorId,
1565
- name: anchorName,
1566
- value: anchor,
1717
+ type: "date",
1718
+ name: `${formName}-day`,
1719
+ value: day,
1567
1720
  onChange: (e) => {
1568
- const next = (
1569
- /** @type {"today" | "latest"} */
1570
- e.target.value
1571
- );
1572
- setAnchorLocal(next);
1573
- if (quick.filters.length) {
1574
- commit(setAnchor(view, field, next), note);
1721
+ setDay(e.target.value);
1722
+ if (/^\d{4}-\d{2}-\d{2}$/.test(e.target.value)) {
1723
+ setAnchorTo(e.target.value);
1575
1724
  }
1576
1725
  },
1577
- "data-testid": "quick-anchor"
1578
- },
1579
- /* @__PURE__ */ React5.createElement("option", { value: "today" }, fill(labels.anchorToday, { date: dayText(isoDay(today.getTime()), locale) })),
1580
- /* @__PURE__ */ React5.createElement("option", { value: "latest" }, fill(labels.anchorLatest, { date: dayText(latestDay, locale) }))
1581
- )) : null, hidden.length ? /* @__PURE__ */ React5.createElement("p", { className: "pk-hint pk-quick-hidden", "data-testid": "quick-hidden" }, fill(plural(labels.quickHidden, hidden.length, lang), { choices: hidden.join(", "), latest: dayText(latestDay, locale) })) : null);
1726
+ onBlur: () => {
1727
+ if (!dayWhole) {
1728
+ setDay(anchor.slice(0, 10));
1729
+ }
1730
+ },
1731
+ "aria-label": labels.anchorDay,
1732
+ "aria-invalid": dayWhole ? void 0 : true,
1733
+ "aria-describedby": dayWhole ? void 0 : dayHint,
1734
+ "data-testid": "quick-anchor-date"
1735
+ }
1736
+ ) : null, anchorKind === "date" && !dayWhole ? /* @__PURE__ */ React5.createElement("p", { className: "pk-hint pk-quick-missing", id: dayHint, "data-testid": "quick-anchor-date-hint" }, fill(labels.anchorDayIncomplete, { date: dayText(anchor.slice(0, 10), locale) })) : null);
1737
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { role: "radiogroup", "aria-label": labels.quickTitle, className: "pk-radios pk-quick-choices", "data-testid": "quick-choices" }, main), hidden.length ? /* @__PURE__ */ React5.createElement("p", { className: "pk-hint pk-quick-hidden", "data-testid": "quick-hidden" }, fill(plural(labels.quickHidden, hidden.length, lang), { choices: hidden.join(", "), latest: dayText(latestDay, locale) })) : null, anchorOutside ? anchorRow : null, /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-quick-more-toggle", "aria-expanded": moreOpen, "aria-controls": moreId, onClick: () => setMoreOpen(!moreOpen), "data-testid": "quick-more" }, /* @__PURE__ */ React5.createElement(Icon, { name: moreOpen ? "chevronDown" : "chevronRight", size: 14 }), /* @__PURE__ */ React5.createElement("span", null, labels.quickMore)), moreOpen ? /* @__PURE__ */ React5.createElement("div", { id: moreId, className: "pk-quick-more", "data-testid": "quick-more-body" }, /* @__PURE__ */ React5.createElement("div", { role: "radiogroup", "aria-label": labels.quickMore, className: "pk-radios pk-quick-choices" }, counted("next"), counted("before")), /* @__PURE__ */ React5.createElement("label", { className: "pk-check" }, /* @__PURE__ */ React5.createElement(
1738
+ "input",
1739
+ {
1740
+ type: "checkbox",
1741
+ name: `${formName}-rolling`,
1742
+ checked: rolling,
1743
+ onChange: (e) => {
1744
+ setRolling(e.target.checked);
1745
+ const spec = COUNTED.includes(quick.id) ? specOf(quick.id, rows[quick.id], e.target.checked) : null;
1746
+ if (spec) {
1747
+ set(spec);
1748
+ }
1749
+ },
1750
+ "data-testid": "quick-rolling"
1751
+ }
1752
+ ), /* @__PURE__ */ React5.createElement("span", null, labels.quickRolling)), anchorOutside ? null : anchorRow) : null);
1582
1753
  }
1583
1754
  function YearsCombined({ ctx, years, on }) {
1584
1755
  const { view, field, labels, locale, commit, note, noun } = ctx;
@@ -1602,8 +1773,7 @@ function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
1602
1773
  );
1603
1774
  const listId = useId3();
1604
1775
  const searchName = useFormName();
1605
- const q = query.trim().toLocaleLowerCase();
1606
- const found = q ? items.filter((i) => i.label.toLocaleLowerCase().includes(q)) : items;
1776
+ const found = searchItems(items, query);
1607
1777
  const matching = found.slice(0, FILTER_LIST_MAX);
1608
1778
  const current = items.find((i) => String(i.value) === value);
1609
1779
  const show = () => {
@@ -1694,12 +1864,12 @@ function ItemRule({ rule, ctx, apply, first }) {
1694
1864
  const { field, labels, locale, fk, items } = ctx;
1695
1865
  const narrow = useContext3(LayerContext).size === "narrow";
1696
1866
  const words = fk.dates ? labels.dateOps : labels.valueOps;
1697
- const ops = fk.dates ? [...CATALOG4.valueOps, "last"] : CATALOG4.valueOps;
1867
+ const ops = fk.dates ? [...RULE_OPS.compare, "last"] : RULE_OPS.compare;
1698
1868
  const textOf = (v) => v === void 0 ? "" : fk.item === "number" ? numberText(v, locale) : String(v);
1699
1869
  const compared = rule?.type === "compare" ? rule : null;
1700
1870
  const ranged = rule?.type === "relative" ? rule : null;
1701
1871
  const [s, setS] = useState3(() => ({
1702
- op: ranged ? "last" : compared?.op ?? ">=",
1872
+ op: ranged ? "last" : compared ? ruleOp(compared) : ">=",
1703
1873
  a: textOf(compared?.value),
1704
1874
  b: textOf(compared?.value2),
1705
1875
  count: numberText(ranged?.count ?? 5, locale),
@@ -1710,11 +1880,11 @@ function ItemRule({ rule, ctx, apply, first }) {
1710
1880
  const read = (text) => fk.item === "number" ? parseNumber(text, locale) : fk.item === "date" ? /^\d{4,}-\d{2}-\d{2}$/.test(text) ? text : null : text === "" ? null : Number(text);
1711
1881
  const entryOf = (x) => {
1712
1882
  if (x.op === "last") {
1713
- const n = readNumber(x.count, { kind: "count", max: CATALOG4.relativeMaxCount, labels, locale }).value;
1714
- return n !== null ? { field, type: "relative", unit: x.unit, count: n, ...ranged?.anchor === "latest" ? { anchor: "latest" } : {} } : null;
1883
+ const n = readNumber(x.count, { kind: "count", max: CATALOG3.relativeMaxCount, labels, locale }).value;
1884
+ return n !== null ? { ...relativeRule(field, { unit: x.unit, count: n, anchor: ranged?.anchor }), ...ranged ? { not: ranged.not, blanks: ranged.blanks } : {} } : null;
1715
1885
  }
1716
1886
  const [a, b] = [read(x.a), read(x.b)];
1717
- return a === null || twin(x.op) && b === null ? null : { field, type: "compare", op: x.op, value: a, ...twin(x.op) ? { value2: b } : {} };
1887
+ return a === null || twin(x.op) && b === null ? null : { field, type: "compare", ...opOf(x.op), value: a, ...twin(x.op) ? { value2: b } : {}, blanks: compared?.blanks ?? "exclude" };
1718
1888
  };
1719
1889
  const change = (patch, wait = false) => {
1720
1890
  const next = { ...s, ...patch };
@@ -1759,7 +1929,7 @@ function ItemRule({ rule, ctx, apply, first }) {
1759
1929
  };
1760
1930
  const label = fk.item === "date" ? labels.ruleDate : labels.ruleValue;
1761
1931
  const lang = { lang: labels.lang, locale };
1762
- const counted = readNumber(s.count, { kind: "count", max: CATALOG4.relativeMaxCount, labels, locale });
1932
+ const counted = readNumber(s.count, { kind: "count", max: CATALOG3.relativeMaxCount, labels, locale });
1763
1933
  const many = counted.value ?? 2;
1764
1934
  return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("span", { className: "pk-rule-subject" }, fieldLabel3(field, labels.core)), /* @__PURE__ */ React5.createElement("select", { className: "pk-rule-op", name: `${formName}-op`, value: s.op, onChange: (e) => change({ op: e.target.value }), "aria-label": labels.valueFilterOp, "data-autofocus": first ? "" : void 0, "data-testid": "rule-item-op" }, ops.map((o) => /* @__PURE__ */ React5.createElement("option", { key: o, value: o }, o === "last" ? plural(labels.lastOp, many, lang) : words[o] ?? o))), s.op === "last" ? /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
1765
1935
  NumberField,
@@ -1773,12 +1943,12 @@ function ItemRule({ rule, ctx, apply, first }) {
1773
1943
  testId: "rule-last-count",
1774
1944
  className: "pk-field-label pk-count-input"
1775
1945
  }
1776
- ), /* @__PURE__ */ React5.createElement("select", { name: `${formName}-unit`, value: s.unit, onChange: (e) => change({ unit: e.target.value }), "aria-label": labels.ruleUnit, "data-testid": "rule-last-unit" }, CATALOG4.relativeUnits.map((u) => /* @__PURE__ */ React5.createElement("option", { key: u, value: u }, plural(labels.ruleUnits[u], many, lang))))) : /* @__PURE__ */ React5.createElement(React5.Fragment, null, value("a", label, "rule-item-value"), twin(s.op) ? /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("span", null, labels.valueFilterTo), value("b", `${labels.valueFilterTo} ${label}`, "rule-item-value2")) : null, s.op === "!=" || s.op === "notBetween" ? /* @__PURE__ */ React5.createElement("span", { className: "pk-hint pk-rule-note", "data-testid": "rule-blanks" }, labels.blanksOut) : null));
1946
+ ), /* @__PURE__ */ React5.createElement("select", { name: `${formName}-unit`, value: s.unit, onChange: (e) => change({ unit: e.target.value }), "aria-label": labels.ruleUnit, "data-testid": "rule-last-unit" }, RANGE_UNITS.map((u) => /* @__PURE__ */ React5.createElement("option", { key: u, value: u }, plural(labels.ruleUnits[u], many, lang))))) : /* @__PURE__ */ React5.createElement(React5.Fragment, null, value("a", label, "rule-item-value"), twin(s.op) ? /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("span", null, labels.valueFilterTo), value("b", `${labels.valueFilterTo} ${label}`, "rule-item-value2")) : null, (s.op === "!=" || s.op === "notBetween") && (compared?.blanks ?? (ctx.keepBlanks ? "include" : "exclude")) === "exclude" ? /* @__PURE__ */ React5.createElement("span", { className: "pk-hint pk-rule-note", "data-testid": "rule-blanks" }, labels.blanksOut) : null));
1777
1947
  }
1778
1948
  function TotalRule({ rule, ctx, apply, first }) {
1779
1949
  const { view, types, labels, locale } = ctx;
1780
1950
  const { choices, names } = measuresOf(view, types, labels, rule?.by);
1781
- const [s, setS] = useState3(() => ({ by: choiceIndex(choices, rule?.by), op: rule?.op ?? ">", a: numberText(rule?.value, locale), b: numberText(rule?.value2, locale) }));
1951
+ const [s, setS] = useState3(() => ({ by: choiceIndex(choices, rule?.by), op: rule ? ruleOp(rule) : ">", a: numberText(rule?.value, locale), b: numberText(rule?.value2, locale) }));
1782
1952
  const later = useLater();
1783
1953
  const formName = useFormName();
1784
1954
  const change = (patch, wait = false) => {
@@ -1788,7 +1958,7 @@ function TotalRule({ rule, ctx, apply, first }) {
1788
1958
  const [a, b] = [parseNumber(next.a, locale), parseNumber(next.b, locale)];
1789
1959
  if (a !== null && (!twin(next.op) || b !== null)) {
1790
1960
  const by = choices[next.by];
1791
- apply({ field: ctx.field, type: "value", by: { field: by.field, agg: by.agg }, op: next.op, value: a, ...twin(next.op) ? { value2: b } : {} });
1961
+ apply({ field: ctx.field, type: "value", by: { field: by.field, agg: by.agg }, ...opOf(next.op), value: a, ...twin(next.op) ? { value2: b } : {} });
1792
1962
  }
1793
1963
  };
1794
1964
  if (wait) {
@@ -1809,14 +1979,14 @@ function TotalRule({ rule, ctx, apply, first }) {
1809
1979
  };
1810
1980
  const keys = fieldKeys({ now: later.now, restore, back: ctx.back });
1811
1981
  const number = (key, label, testId, shown) => /* @__PURE__ */ React5.createElement(NumberField, { value: s[key], onChange: (t) => change({ [key]: t }, true), onKeyDown: keys, onBlur: later.now, problem: readNumber(s[key], { required: false, labels, locale }).problem, label, shown, testId, className: "pk-field-label pk-narrow-input" });
1812
- return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("span", { className: "pk-rule-subject pk-rule-lead" }, fill(labels.ruleWhose, { field: fieldLabel3(ctx.field, labels.core) })), /* @__PURE__ */ React5.createElement(MeasurePick, { choices, names, index: s.by, onChange: (i) => change({ by: i }), label: labels.valueFilterBy, testId: "value-filter-by" }), /* @__PURE__ */ React5.createElement("select", { className: "pk-rule-op", name: `${formName}-op`, value: s.op, onChange: (e) => change({ op: e.target.value }), "aria-label": labels.valueFilterOp, "data-autofocus": first ? "" : void 0, "data-testid": "value-filter-op" }, CATALOG4.valueOps.map((o) => /* @__PURE__ */ React5.createElement("option", { key: o, value: o }, labels.valueOps[o] ?? o))), number("a", labels.valueFilterNumber, "value-filter-number"), twin(s.op) ? number("b", `${labels.valueFilterTo} ${labels.valueFilterNumber}`, "value-filter-number2", labels.valueFilterTo) : null);
1982
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("span", { className: "pk-rule-subject pk-rule-lead" }, fill(labels.ruleWhose, { field: fieldLabel3(ctx.field, labels.core) })), /* @__PURE__ */ React5.createElement(MeasurePick, { choices, names, index: s.by, onChange: (i) => change({ by: i }), label: labels.valueFilterBy, testId: "value-filter-by" }), /* @__PURE__ */ React5.createElement("select", { className: "pk-rule-op", name: `${formName}-op`, value: s.op, onChange: (e) => change({ op: e.target.value }), "aria-label": labels.valueFilterOp, "data-autofocus": first ? "" : void 0, "data-testid": "value-filter-op" }, RULE_OPS.compare.map((o) => /* @__PURE__ */ React5.createElement("option", { key: o, value: o }, labels.valueOps[o] ?? o))), number("a", labels.valueFilterNumber, "value-filter-number"), twin(s.op) ? number("b", `${labels.valueFilterTo} ${labels.valueFilterNumber}`, "value-filter-number2", labels.valueFilterTo) : null);
1813
1983
  }
1814
1984
  function NameRule({ rule, ctx, apply, first }) {
1815
1985
  const { field, labels } = ctx;
1816
- const [op, setOp] = useState3(rule?.op ?? "contains");
1986
+ const [op, setOp] = useState3(rule ? ruleOp(rule) : "contains");
1817
1987
  const send = (o, value) => {
1818
1988
  if (value !== "") {
1819
- apply({ field, type: "label", op: o, value });
1989
+ apply({ ...textRule(field, { op: o, value, on: ctx.textOn }), ...rule ? { blanks: rule.blanks } : {} });
1820
1990
  }
1821
1991
  };
1822
1992
  const text = useAppliedText(rule?.value ?? "", (value) => send(op, value));
@@ -1835,7 +2005,7 @@ function NameRule({ rule, ctx, apply, first }) {
1835
2005
  "data-autofocus": first ? "" : void 0,
1836
2006
  "data-testid": "filter-condition-op"
1837
2007
  },
1838
- CATALOG4.labelOps.map((o) => /* @__PURE__ */ React5.createElement("option", { key: o, value: o }, labels.labelOps[o] ?? o))
2008
+ RULE_OPS.text.map((o) => /* @__PURE__ */ React5.createElement("option", { key: o, value: o }, labels.labelOps[o] ?? o))
1839
2009
  ), /* @__PURE__ */ React5.createElement(
1840
2010
  ClearInput,
1841
2011
  {
@@ -1848,13 +2018,16 @@ function NameRule({ rule, ctx, apply, first }) {
1848
2018
  clearLabel: labels.clearText,
1849
2019
  "aria-label": labels.conditionValue,
1850
2020
  placeholder: labels.conditionValue,
1851
- maxLength: 1e3,
2021
+ maxLength: LIMITS2.textValue,
1852
2022
  "data-testid": "filter-condition-text"
1853
2023
  }
1854
2024
  ));
1855
2025
  }
1856
- var ROWS = { item: ItemRule, total: TotalRule, name: NameRule };
1857
- function RuleEditor({ ctx, rules, focusFirst, quickLine, results }) {
2026
+ function FixedRule({ rule, ctx }) {
2027
+ return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("span", { className: "pk-rule-subject" }, ctx.say(rule)), /* @__PURE__ */ React5.createElement("span", { className: "pk-hint pk-rule-note", "data-testid": "rule-fixed" }, ctx.labels.ruleFixed));
2028
+ }
2029
+ var ROWS = { item: ItemRule, total: TotalRule, name: NameRule, fixed: FixedRule };
2030
+ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
1858
2031
  const { view, field, labels, locale, commit, note, fk, nameKind, noun } = ctx;
1859
2032
  const { explain } = useContext3(HelpContext);
1860
2033
  const lang = { lang: labels.lang, locale };
@@ -1862,6 +2035,7 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results }) {
1862
2035
  /** @type {"item" | "total" | "name" | null} */
1863
2036
  null
1864
2037
  );
2038
+ const blanksName = useFormName();
1865
2039
  const [info, setInfo] = useState3(
1866
2040
  /** @type {number | null} */
1867
2041
  null
@@ -1913,7 +2087,7 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results }) {
1913
2087
  ["item", "total", "name"].filter((k) => k === "item" ? Boolean(fk.item) : k === "name" ? Boolean(nameKind) : true)
1914
2088
  );
1915
2089
  const count = rules.length + (draft ? 1 : 0);
1916
- const full = count >= RULES_MAX || view.filters.length >= LIMITS.filters;
2090
+ const full = count >= RULES_MAX || view.filters.length >= LIMITS2.filters;
1917
2091
  const addText = { item: fill(labels.addRuleItem, { field: fieldLabel3(field, labels.core) }), total: labels.addRuleTotal, name: labels.addRuleName };
1918
2092
  const infoText = (rule, kind) => {
1919
2093
  const one = plural(noun, 1, lang);
@@ -1929,7 +2103,8 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results }) {
1929
2103
  const row = (rule, kind, i) => {
1930
2104
  const Row = ROWS[kind];
1931
2105
  const apply = (entry) => {
1932
- const next = setRule(view, field, rule, entry);
2106
+ const own2 = !rule && ctx.keepBlanks && ITEM_RULE_TYPES.includes(entry.type) ? { ...entry, blanks: "include" } : entry;
2107
+ const next = setRule(view, field, rule, own2);
1933
2108
  setOwn(rulesKeyOf(filtersOf(next, field, RULE_TYPES).filter((f) => !ctx.quickFilters.includes(f))));
1934
2109
  if (!rule) {
1935
2110
  setDraft(null);
@@ -1950,7 +2125,7 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results }) {
1950
2125
  const infoId = `${gen}-${i}`;
1951
2126
  return /* @__PURE__ */ React5.createElement("li", { key: `${gen}:${i}`, className: "pk-rule", "data-testid": "rule", "data-kind": kind }, i > 0 || quickLine ? /* @__PURE__ */ React5.createElement("span", { className: "pk-rule-and" }, labels.ruleAnd) : null, /* @__PURE__ */ React5.createElement("span", { className: "pk-rule-body" }, /* @__PURE__ */ React5.createElement(Row, { rule, ctx, apply, first: focusFirst && i === 0 || !rule && draft !== null })), /* @__PURE__ */ React5.createElement("span", { className: "pk-rule-tools" }, explain ? /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-icon-btn pk-rule-info", "aria-expanded": open, "aria-controls": open ? infoId : void 0, onClick: () => setInfo(open ? null : i), "aria-label": labels.explainRule, title: labels.explainRule, "data-testid": "rule-info" }, /* @__PURE__ */ React5.createElement(Icon, { name: "info", size: 14 })) : null, /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-icon-btn pk-rule-remove", onClick: remove, "aria-label": labels.removeRule, title: labels.removeRule, "data-testid": "rule-remove" }, /* @__PURE__ */ React5.createElement(Icon, { name: "x", size: 14 }))), /* @__PURE__ */ React5.createElement("p", { className: `pk-hint pk-rule-result${result && result.kept === 0 ? " pk-rule-result-empty" : ""}`, "data-testid": "rule-result" }, result ? result.text : labels.ruleIncomplete), open ? /* @__PURE__ */ React5.createElement("p", { className: "pk-rule-info-text", id: infoId, "data-testid": "rule-info-text" }, infoText(rule, kind)) : null);
1952
2127
  };
1953
- return /* @__PURE__ */ React5.createElement("fieldset", { ref: box, className: "pk-condition pk-rules", "data-testid": "rules" }, /* @__PURE__ */ React5.createElement("legend", { className: "pk-sr" }, labels.rulesTitle), /* @__PURE__ */ React5.createElement("p", { className: "pk-hint" }, fill(count || quickLine ? labels.rulesKeep : labels.rulesNone, { noun: plural(noun, 2, lang) })), count || quickLine ? /* @__PURE__ */ React5.createElement("ul", { className: "pk-rule-list", role: "list" }, quickLine ? /* @__PURE__ */ React5.createElement("li", { className: "pk-rule pk-rule-quick", "data-testid": "rule-quick" }, /* @__PURE__ */ React5.createElement("span", null, fill(labels.quickLine, { text: quickLine })), /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-action", onClick: ctx.focusQuick, "data-testid": "rule-quick-change" }, labels.changeAbove)) : null, [...rules.map((r, i) => row(r, rowKind(r), i)), ...draft ? [row(null, draft, rules.length)] : []]) : null, /* @__PURE__ */ React5.createElement("div", { className: "pk-rule-adds", role: "group", "aria-label": labels.addRule }, kinds.map((k, i) => /* @__PURE__ */ React5.createElement(
2128
+ return /* @__PURE__ */ React5.createElement("fieldset", { ref: box, className: "pk-condition pk-rules", "data-testid": "rules" }, /* @__PURE__ */ React5.createElement("legend", { className: "pk-sr" }, labels.rulesTitle), /* @__PURE__ */ React5.createElement("p", { className: "pk-hint" }, fill(count || quickLine ? labels.rulesKeep : labels.rulesNone, { noun: plural(noun, 2, lang) })), count || quickLine ? /* @__PURE__ */ React5.createElement("ul", { className: "pk-rule-list", role: "list" }, quickLine ? /* @__PURE__ */ React5.createElement("li", { className: "pk-rule pk-rule-quick", "data-testid": "rule-quick" }, /* @__PURE__ */ React5.createElement("span", null, fill(labels.quickLine, { text: quickLine })), /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-action", onClick: ctx.focusQuick, "data-testid": "rule-quick-change" }, labels.changeAbove)) : null, [...rules.map((r, i) => row(r, rowKind(r), i)), ...draft ? [row(null, draft, rules.length)] : []]) : null, blanks ? /* @__PURE__ */ React5.createElement("label", { className: "pk-check pk-rules-blanks" }, /* @__PURE__ */ React5.createElement("input", { type: "checkbox", name: `${blanksName}`, checked: blanks.on, onChange: (e) => commit(setRuleBlanks(view, field, e.target.checked), note), "data-testid": "rules-blanks" }), /* @__PURE__ */ React5.createElement("span", null, fill(plural(labels.rulesBlanks, blanks.rows, lang), { rows: blanks.rows.toLocaleString(locale) }))) : null, /* @__PURE__ */ React5.createElement("div", { className: "pk-rule-adds", role: "group", "aria-label": labels.addRule }, kinds.map((k, i) => /* @__PURE__ */ React5.createElement(
1954
2129
  "button",
1955
2130
  {
1956
2131
  key: k,
@@ -1977,13 +2152,11 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
1977
2152
  const years = useMemo2(() => fk.cyclic && column && counts ? yearsOf(column, counts) : [], [fk.cyclic, column, counts]);
1978
2153
  const quick = quickChoice(view, field, fk, years.map((y) => y.year));
1979
2154
  const [anchorLocal, setAnchorLocal] = useState3(
1980
- /** @type {"today" | "latest" | null} */
2155
+ /** @type {string | null} */
1981
2156
  null
1982
2157
  );
1983
- const anchor = (
1984
- /** @type {"today" | "latest"} */
1985
- quick.anchor ?? anchorLocal ?? "today"
1986
- );
2158
+ const anchor = quick.anchor ?? anchorLocal ?? "today";
2159
+ const [moreOpen, setMoreOpen] = useState3(() => inMore(quick));
1987
2160
  const [openQuick, setOpenQuick] = useState3(true);
1988
2161
  const [openPicks, setOpenPicks] = useState3(
1989
2162
  /** @type {boolean | null} */
@@ -2034,7 +2207,7 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
2034
2207
  if (goQuick) {
2035
2208
  const target = (
2036
2209
  /** @type {HTMLElement | null | undefined} */
2037
- box.current?.querySelector('[data-testid="quick-choices"] input:checked, [data-testid="years-combined"] [aria-pressed="true"]:not(:disabled)') ?? box.current?.querySelector('[data-testid="years-combined"] button:not(:disabled)')
2210
+ box.current?.querySelector('[data-testid="quick-choices"] input:checked, [data-testid="quick-more-body"] input[type="radio"]:checked, [data-testid="years-combined"] [aria-pressed="true"]:not(:disabled)') ?? box.current?.querySelector('[data-testid="years-combined"] button:not(:disabled)')
2038
2211
  );
2039
2212
  target?.scrollIntoView?.({ block: "center" });
2040
2213
  target?.focus({ preventScroll: true });
@@ -2079,13 +2252,13 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
2079
2252
  const all = info.items.map((i) => i.value);
2080
2253
  const picked = selectedItems(view, field, all);
2081
2254
  const selected = new Set(picked.map(keyOf));
2082
- const nameKind = conditionKind(encoded, view, field) ?? (rules.some((r) => r.type === "label") ? "text" : null);
2255
+ const nameKind = conditionKind(encoded, view, field) ?? (rules.some((r) => r.type === "text") ? "text" : null);
2083
2256
  const labelOf = (v) => info.items.find((i) => i.value === v)?.label;
2084
2257
  const say = (f) => ruleText(view, f, { labels, locale, timeZone, date: fk.dates, labelOf, span });
2085
2258
  const number = (n) => n.toLocaleString(locale);
2086
2259
  const yearsOn = quick.id === "yearsCombined" && quick.years ? quick.years : years.map((y) => y.year);
2087
2260
  const yearsText = fk.cyclic && years.length > 1 ? yearsOn.length === 1 ? fill(labels.yearsOne, { year: String(yearsOn[0]) }) : fill(labels.yearsAll, { years: yearsOn.length === years.length || yearsOn[yearsOn.length - 1] - yearsOn[0] === yearsOn.length - 1 ? `${yearsOn[0]}\u2013${yearsOn[yearsOn.length - 1]}` : yearsOn.join(", ") }) : null;
2088
- const quickWords = quick.id === "yearsCombined" ? yearsText : quick.filters.length ? relativeText(quick.filters[0], labels, locale, timeZone, void 0, span) : null;
2261
+ const quickWords = quick.id === "yearsCombined" ? yearsText : quick.filters.length ? relativeText(quick.filters[0], labels, locale, timeZone, void 0, span, view.formatting?.weekStart) : null;
2089
2262
  const outByQuick = (
2090
2263
  /** @type {Set<string> | undefined} */
2091
2264
  itemResults.get("quick") ?? (quick.filters.length ? new Set(info.items.filter((i) => !i.kept).map((i) => keyOf(i.value))) : /* @__PURE__ */ new Set())
@@ -2109,7 +2282,7 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
2109
2282
  };
2110
2283
  const totalWords = (r) => {
2111
2284
  const measure = refLabel(view, r.by, labels);
2112
- const op = labels.valueOps[r.op] ?? r.op;
2285
+ const op = labels.valueOps[ruleOp(r)] ?? ruleOp(r);
2113
2286
  const num = (x) => typeof x === "number" ? x.toLocaleString(locale, { maximumFractionDigits: 6 }) : "";
2114
2287
  return twin(r.op) ? fill(labels.totalWordsTwo, { measure, op, from: num(Math.min(r.value, r.value2)), to: num(Math.max(r.value, r.value2)) }) : fill(labels.totalWords, { measure, op, number: num(r.value) });
2115
2288
  };
@@ -2146,6 +2319,9 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
2146
2319
  const scope = scopeParts.length ? scopeParts.join(labels.listAnd) : labels.scopeRows;
2147
2320
  const focusQuick = () => {
2148
2321
  setOpenQuick(true);
2322
+ if (inMore(quick)) {
2323
+ setMoreOpen(true);
2324
+ }
2149
2325
  setGoQuick((n) => n + 1);
2150
2326
  };
2151
2327
  const act = (next, header) => {
@@ -2157,7 +2333,10 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
2157
2333
  }
2158
2334
  });
2159
2335
  };
2160
- const ctx = { view, field, types, labels, locale, commit, note, back, fk, nameKind, timeZone, hint, items: info.items, noun, scope, quickFilters: quick.filters, focusQuick, act };
2336
+ const keepBlanks = keepsBlanks(view, field);
2337
+ const ctx = { view, field, types, labels, locale, commit, note, back, fk, nameKind, say, textOn: textOn(encoded, field), timeZone, hint, items: info.items, noun, scope, quickFilters: quick.filters, focusQuick, act, keepBlanks };
2338
+ const blankRows = info.items.find((i) => i.value === null)?.count ?? 0;
2339
+ const blanks = blankRows > 0 && (itemRules.length > 0 || quick.filters.length > 0) ? { rows: blankRows, on: keepBlanks } : null;
2161
2340
  const picksOpen = openPicks ?? !anyRule;
2162
2341
  const rulesOpen = openRules ?? anyRule;
2163
2342
  const togglePicks = () => {
@@ -2176,7 +2355,7 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
2176
2355
  };
2177
2356
  const summary = { shown, total: all.length, noun, unpicked, byQuick, byRules, byTotals, itemRules: itemRules.length, totalRules: totalRules.length, rows: totals.rows, rowsAll: encoded.length, span, yearsText, empty, quickWords, rules: rules.length, canReset: unpicked > 0 || anyRule };
2178
2357
  const outOf = (i) => i.kept === false;
2179
- const quickSection = fk.quick && span && column && counts ? { id: "quick", title: labels.quickTitle, body: /* @__PURE__ */ React5.createElement(QuickChoices, { ctx, quick, anchor, setAnchorLocal, span, column, counts }) } : fk.cyclic && years.length > 1 && years.length <= 12 ? { id: "years", title: labels.yearsCombined, body: /* @__PURE__ */ React5.createElement(YearsCombined, { ctx, years, on: yearsOn }) } : null;
2358
+ const quickSection = fk.quick && span && column && counts ? { id: "quick", title: labels.quickTitle, body: /* @__PURE__ */ React5.createElement(QuickChoices, { ctx, quick, anchor, setAnchorLocal, span, column, counts, moreOpen, setMoreOpen }) } : fk.cyclic && years.length > 1 && years.length <= 12 ? { id: "years", title: labels.yearsCombined, body: /* @__PURE__ */ React5.createElement(YearsCombined, { ctx, years, on: yearsOn }) } : null;
2180
2359
  return /* @__PURE__ */ React5.createElement("div", { ref: box, className: "pk-filter pk-filter-level" }, /* @__PURE__ */ React5.createElement(Summary, { ctx, state: summary }), quickSection ? /* @__PURE__ */ React5.createElement(Section2, { id: quickSection.id, title: quickSection.title, state: quickWords && !openQuick ? quickWords : null, open: openQuick, onToggle: () => setOpenQuick(!openQuick) }, quickSection.body) : null, /* @__PURE__ */ React5.createElement(
2181
2360
  Section2,
2182
2361
  {
@@ -2209,13 +2388,15 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
2209
2388
  onToggle: toggleRules,
2210
2389
  action: /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-action", disabled: !rules.length, "aria-label": labels.removeRules, onClick: () => act(removeRules(view, field, quick.filters), "section-rules"), "data-testid": "filter-remove-rules" }, labels.removeAll)
2211
2390
  },
2212
- /* @__PURE__ */ React5.createElement(RuleEditor, { ctx, rules, focusFirst: hint === "conditions", quickLine: quickWords, results })
2391
+ /* @__PURE__ */ React5.createElement(RuleEditor, { ctx, rules, focusFirst: hint === "conditions", quickLine: quickWords, results, blanks })
2213
2392
  ));
2214
2393
  }
2215
2394
 
2216
2395
  // src/chip-menus.jsx
2217
- function TopLevel({ view, field, types, labels, locale, commit, back }) {
2396
+ function TopLevel({ view, field, types, labels, locale, commit, back, encoded }) {
2218
2397
  const top = filtersOf(view, field, ["top"])[0];
2398
+ const axis = view.rows[0]?.toLowerCase() === field.toLowerCase() ? "rowRoot" : view.cols[0]?.toLowerCase() === field.toLowerCase() ? "colRoot" : null;
2399
+ const shown = useMemo3(() => top && axis && encoded ? computePivot2(encoded, view)[axis].children.length : null, [top, axis, encoded, view]);
2219
2400
  const { choices, names } = measuresOf(view, types, labels, top?.by);
2220
2401
  const [by, setBy] = useState4(() => choiceIndex(choices, top?.by));
2221
2402
  const quick = top && !top.bottom && TOP_COUNTS.includes(top.count) ? top.count : null;
@@ -2234,7 +2415,8 @@ function TopLevel({ view, field, types, labels, locale, commit, back }) {
2234
2415
  }
2235
2416
  };
2236
2417
  const groupName = useFormName();
2237
- const radio = (id, text, checked, onPick) => /* @__PURE__ */ React6.createElement("label", { className: "pk-radio" }, /* @__PURE__ */ React6.createElement("input", { type: "radio", name: groupName, checked, onChange: onPick, "data-autofocus": checked ? "" : void 0, "data-testid": `top-${id}` }), /* @__PURE__ */ React6.createElement("span", null, text));
2418
+ const tiesName = useFormName();
2419
+ const radio = (id, text, checked, onPick) => /* @__PURE__ */ React6.createElement("label", { className: "pk-radio" }, /* @__PURE__ */ React6.createElement("input", { type: "radio", name: groupName, checked, onClick: (e) => e.currentTarget.focus(), onChange: onPick, "data-autofocus": checked ? "" : void 0, "data-testid": `top-${id}` }), /* @__PURE__ */ React6.createElement("span", null, text));
2238
2420
  return /* @__PURE__ */ React6.createElement("div", { className: "pk-level-form" }, /* @__PURE__ */ React6.createElement("div", { role: "radiogroup", "aria-label": labels.topN, className: "pk-radios" }, radio("off", labels.off, !top && !own, () => {
2239
2421
  setOwn(false);
2240
2422
  set(null);
@@ -2289,7 +2471,16 @@ function TopLevel({ view, field, types, labels, locale, commit, back }) {
2289
2471
  if (top) {
2290
2472
  set({ count: top.count, bottom: Boolean(top.bottom), by: choices[i] });
2291
2473
  }
2292
- }, label: labels.topBy, prefix: labels.topBy, testId: "top-by" })));
2474
+ }, label: labels.topBy, prefix: labels.topBy, testId: "top-by" })), top ? /* @__PURE__ */ React6.createElement("label", { className: "pk-check" }, /* @__PURE__ */ React6.createElement(
2475
+ "input",
2476
+ {
2477
+ type: "checkbox",
2478
+ name: tiesName,
2479
+ checked: top.ties === "all",
2480
+ onChange: (e) => set({ count: top.count, bottom: Boolean(top.bottom), by: top.by ?? choices[by], ties: e.target.checked ? "all" : "first" }),
2481
+ "data-testid": "top-ties"
2482
+ }
2483
+ ), /* @__PURE__ */ React6.createElement("span", null, labels.topTies)) : null, top && (shown !== null || top.ties === "all") ? /* @__PURE__ */ React6.createElement("p", { className: "pk-hint pk-top-shown", "data-testid": "top-shown" }, shown !== null ? fill(plural(labels.topShown, shown, { lang: labels.lang, locale }), { count: shown.toLocaleString(locale) }) : fill(labels.topTiesGroups, { count: top.count.toLocaleString(locale) })) : null);
2293
2484
  }
2294
2485
  function BinsLevel({ view, field, labels, locale, range, regroup, back }) {
2295
2486
  const grouping = groupingOf(view, field);
@@ -2404,7 +2595,7 @@ function AxisMenu({ view, zone, index, field, types, labels, commit, close, onRe
2404
2595
  const grouped = unit ? groupingName(sourceName, unit, labels, size) : null;
2405
2596
  commit(groupField(view, field, unit, { size, origin, name: grouped ?? void 0 }).view, { step: "group", field: sourceName });
2406
2597
  };
2407
- const panel = (id, back, hint) => id === "filter" ? /* @__PURE__ */ React6.createElement(FilterLevel, { view, field, encoded, types, labels, locale, commit, back, hint }) : id === "top" ? /* @__PURE__ */ React6.createElement(TopLevel, { view, field, types, labels, locale, commit, back }) : id === "bins" ? /* @__PURE__ */ React6.createElement(BinsLevel, { view, field, labels, locale, range: rangeOf?.(source) ?? null, regroup, back }) : null;
2598
+ const panel = (id, back, hint) => id === "filter" ? /* @__PURE__ */ React6.createElement(FilterLevel, { view, field, encoded, types, labels, locale, commit, back, hint }) : id === "top" ? /* @__PURE__ */ React6.createElement(TopLevel, { view, field, types, labels, locale, commit, back, encoded }) : id === "bins" ? /* @__PURE__ */ React6.createElement(BinsLevel, { view, field, labels, locale, range: rangeOf?.(source) ?? null, regroup, back }) : null;
2408
2599
  const name = fieldLabel4(field, labels.core);
2409
2600
  return /* @__PURE__ */ React6.createElement(
2410
2601
  LevelMenu,
@@ -2547,12 +2738,12 @@ async function copyText(text, container) {
2547
2738
  }
2548
2739
 
2549
2740
  // src/version.js
2550
- var VERSION = true ? "0.4.0" : "0.0.0-source";
2741
+ var VERSION = true ? "0.5.0" : "0.0.0-source";
2551
2742
 
2552
2743
  // src/share-actions.js
2553
2744
  var here = () => typeof location !== "undefined" ? location.href : void 0;
2554
2745
  function shareActions(ctx, labels) {
2555
- const { view, viewName, sourceId, sourceName, schemaUrl, encoded, announce, limits, param } = ctx;
2746
+ const { view, viewName, sourceId, sourceName, schemaUrl, encoded, announce, limits, linkKey } = ctx;
2556
2747
  const viewFile = () => viewFileText(toViewFile(view, { name: viewName ?? "", createdAt: /* @__PURE__ */ new Date(), generator: { name: "pivotkit-react", version: VERSION }, source: { id: sourceId, name: sourceName }, data: encoded, ...schemaUrl !== void 0 ? { schemaUrl } : {} }));
2557
2748
  return {
2558
2749
  copyLink: async () => {
@@ -2568,7 +2759,7 @@ function shareActions(ctx, labels) {
2568
2759
  e.code === "LIMIT_EXCEEDED" ? labels.toastLinkTooLong : fill(labels.error, { message: String(e) }), { tone: "error" });
2569
2760
  return;
2570
2761
  }
2571
- const ok = await copyText(withLinkParam(target, param, text), ctx.root.current);
2762
+ const ok = await copyText(withLinkParam(target, linkKey, text), ctx.root.current);
2572
2763
  announce(ok ? labels.toastLinkCopied : labels.toastCopyFailed, ok ? void 0 : { tone: "error" });
2573
2764
  },
2574
2765
  copyJson: async () => {
@@ -2593,7 +2784,7 @@ function shareActions(ctx, labels) {
2593
2784
  let loaded = viewFromText(text, encoded, { limits, sourceId });
2594
2785
  if (loaded.failed === "notJson") {
2595
2786
  const t = text.trim();
2596
- const fromUrl = t.includes("#") ? readLinkParam(t.slice(t.indexOf("#")), param) ?? readLinkParam(t.slice(t.indexOf("#")), "pivot") : null;
2787
+ const fromUrl = t.includes("#") ? readLinkParam(t.slice(t.indexOf("#")), linkKey) ?? readLinkParam(t.slice(t.indexOf("#")), void 0) : null;
2597
2788
  const payload = fromUrl ?? (t.startsWith("1.") ? t : null);
2598
2789
  if (!payload) {
2599
2790
  return labels.viewFailed.notJson;
@@ -3225,14 +3416,140 @@ function ExportPanel({ labels, onExport, chartReady, display, empty = false, pre
3225
3416
  onExport(kind);
3226
3417
  };
3227
3418
  const off = empty ? { disabled: true, reason: labels.exportNeedsField } : {};
3228
- return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(Section, { title: labels.exportDownload }, /* @__PURE__ */ React7.createElement(ExportOption, { icon: "file", text: labels.exportXlsx, info: "exportXlsx", onSelect: run("xlsx"), ...off, testId: "export-xlsx" }), /* @__PURE__ */ React7.createElement(ExportOption, { icon: "file", text: labels.exportCsv, info: "exportCsv", onSelect: run("csv"), ...off, testId: "export-csv" }), /* @__PURE__ */ React7.createElement(ExportOption, { icon: "image", text: labels.exportPng, disabled: empty || !chartReady, reason: empty ? off.reason : display !== "chart" ? labels.exportPngNeedsChart : void 0, onSelect: run("png"), testId: "export-png" })), /* @__PURE__ */ React7.createElement(Section, { title: labels.exportCopy }, /* @__PURE__ */ React7.createElement(ExportOption, { icon: "copy", text: labels.copyTable, info: "copyTable", onSelect: run("copy-table"), ...off, testId: "export-copy-table" }), /* @__PURE__ */ React7.createElement(ExportOption, { icon: "copy", text: labels.copyDataJson, info: "copyDataJson", onSelect: run("copy-json"), ...off, testId: "export-copy-json" })));
3419
+ return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(Section, { title: labels.exportDownload }, /* @__PURE__ */ React7.createElement(ExportOption, { icon: "file", text: labels.exportXlsx, info: "exportXlsx", onSelect: run("xlsx"), ...off, testId: "export-xlsx" }), /* @__PURE__ */ React7.createElement(ExportOption, { icon: "file", text: labels.exportCsv, info: "exportCsv", onSelect: run("csv"), ...off, testId: "export-csv" }), /* @__PURE__ */ React7.createElement(ExportOption, { icon: "file", text: labels.exportHtml, info: "exportHtml", onSelect: run("html"), ...off, testId: "export-html" }), /* @__PURE__ */ React7.createElement(ExportOption, { icon: "image", text: labels.exportPng, disabled: empty || !chartReady, reason: empty ? off.reason : display !== "chart" ? labels.exportPngNeedsChart : void 0, onSelect: run("png"), testId: "export-png" }), /* @__PURE__ */ React7.createElement(ExportOption, { icon: "image", text: labels.exportSvg, disabled: empty || display !== "chart", reason: empty ? off.reason : display !== "chart" ? labels.exportPngNeedsChart : void 0, onSelect: run("svg"), testId: "export-svg" })), /* @__PURE__ */ React7.createElement(Section, { title: labels.exportPrintGroup }, /* @__PURE__ */ React7.createElement(ExportOption, { icon: "print", text: labels.exportPrint, info: "exportPrint", onSelect: run("print"), ...off, testId: "export-print" })), /* @__PURE__ */ React7.createElement(Section, { title: labels.exportCopy }, /* @__PURE__ */ React7.createElement(ExportOption, { icon: "copy", text: labels.copyTable, info: "copyTable", onSelect: run("copy-table"), ...off, testId: "export-copy-table" }), /* @__PURE__ */ React7.createElement(ExportOption, { icon: "copy", text: labels.copyDataJson, info: "copyDataJson", onSelect: run("copy-json"), ...off, testId: "export-copy-json" })));
3229
3420
  }
3230
3421
 
3231
3422
  // src/drill-panel.jsx
3232
- import React8, { useContext as useContext4, useEffect as useEffect4, useId as useId6, useMemo as useMemo3, useRef as useRef4, useState as useState6 } from "react";
3423
+ import React8, { useContext as useContext4, useEffect as useEffect4, useId as useId6, useMemo as useMemo4, useRef as useRef4, useState as useState6 } from "react";
3424
+
3425
+ // src/export-run.js
3426
+ import { chartThemeFrom, toGrid } from "pivotkit-core";
3427
+
3428
+ // src/print-frame.js
3429
+ var FRAME_CLASS = "pk-print-frame";
3430
+ var listeners = /* @__PURE__ */ new WeakMap();
3431
+ function removeFrame(frame) {
3432
+ listeners.get(frame)?.abort();
3433
+ frame.remove();
3434
+ }
3435
+ var PRINT_LOAD_TIMEOUT = 5e3;
3436
+ function printParts(html, parser) {
3437
+ const styles = [];
3438
+ const text = html.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => (styles.push(css), ""));
3439
+ const parsed = parser.parseFromString(text, "text/html");
3440
+ for (const node of parsed.querySelectorAll("style, script, meta, link, base")) {
3441
+ node.remove();
3442
+ }
3443
+ return { css: styles.join("\n"), lang: parsed.documentElement.getAttribute("lang") ?? "", dir: parsed.documentElement.getAttribute("dir") ?? "", title: parsed.title, body: parsed.body };
3444
+ }
3445
+ async function printHtml(html, container) {
3446
+ const doc = container.ownerDocument;
3447
+ const view = doc.defaultView;
3448
+ if (!view) {
3449
+ return false;
3450
+ }
3451
+ for (const old of container.querySelectorAll(`iframe.${FRAME_CLASS}`)) {
3452
+ removeFrame(
3453
+ /** @type {HTMLIFrameElement} */
3454
+ old
3455
+ );
3456
+ }
3457
+ const parts = printParts(html, new view.DOMParser());
3458
+ const frame = doc.createElement("iframe");
3459
+ frame.className = FRAME_CLASS;
3460
+ frame.setAttribute("sandbox", "allow-same-origin allow-modals");
3461
+ frame.setAttribute("aria-hidden", "true");
3462
+ frame.setAttribute("tabindex", "-1");
3463
+ frame.title = parts.title;
3464
+ frame.hidden = true;
3465
+ const loaded = new Promise((resolve) => {
3466
+ const timer = setTimeout(() => resolve(false), PRINT_LOAD_TIMEOUT);
3467
+ const done = () => {
3468
+ if (frame.contentDocument?.URL === "about:srcdoc" && frame.contentDocument.readyState === "complete") {
3469
+ clearTimeout(timer);
3470
+ frame.removeEventListener("load", done);
3471
+ resolve(true);
3472
+ }
3473
+ };
3474
+ frame.addEventListener("load", done);
3475
+ });
3476
+ frame.srcdoc = '<!doctype html><html><head><meta charset="utf-8"><title></title></head><body></body></html>';
3477
+ container.append(frame);
3478
+ const win = await loaded ? frame.contentWindow : null;
3479
+ const fdoc = frame.contentDocument;
3480
+ if (!win || !fdoc || !fdoc.body) {
3481
+ frame.remove();
3482
+ return false;
3483
+ }
3484
+ fdoc.documentElement.lang = parts.lang;
3485
+ fdoc.documentElement.dir = parts.dir;
3486
+ fdoc.title = parts.title;
3487
+ const FrameSheet = (
3488
+ /** @type {any} */
3489
+ win.CSSStyleSheet
3490
+ );
3491
+ if (typeof FrameSheet === "function" && "adoptedStyleSheets" in fdoc) {
3492
+ const sheet = new FrameSheet();
3493
+ sheet.replaceSync(parts.css);
3494
+ fdoc.adoptedStyleSheets = [sheet];
3495
+ } else {
3496
+ const style = fdoc.createElement("style");
3497
+ style.textContent = parts.css;
3498
+ fdoc.head.append(style);
3499
+ }
3500
+ fdoc.body.replaceChildren(...[...parts.body.childNodes].map((node) => fdoc.importNode(node, true)));
3501
+ frame.hidden = false;
3502
+ await new Promise((resolve) => view.requestAnimationFrame(() => setTimeout(resolve, 0)));
3503
+ if (!frame.isConnected) {
3504
+ return true;
3505
+ }
3506
+ const ended = new AbortController();
3507
+ listeners.set(frame, ended);
3508
+ const after = () => setTimeout(() => removeFrame(frame), 0);
3509
+ win.addEventListener("afterprint", after, { once: true, signal: ended.signal });
3510
+ view.addEventListener("afterprint", after, { once: true, signal: ended.signal });
3511
+ win.print();
3512
+ return true;
3513
+ }
3514
+
3515
+ // src/light-tokens.js
3516
+ function lightTokens(root, names, more = () => ({})) {
3517
+ const host = (
3518
+ /** @type {{ host?: Element }} */
3519
+ root.getRootNode().host
3520
+ );
3521
+ const dark = [root, ...host ? [host] : []].filter((el) => el.getAttribute("data-pk-theme") === "dark");
3522
+ const read = () => {
3523
+ const style = getComputedStyle(root);
3524
+ return { ...Object.fromEntries(names.map((name) => [name, style.getPropertyValue(name).trim()]).filter(([, value]) => value)), ...more() };
3525
+ };
3526
+ if (!dark.length) {
3527
+ return read();
3528
+ }
3529
+ const kept = [root.style.getPropertyValue("--pk-duration"), root.style.getPropertyPriority("--pk-duration")];
3530
+ root.style.setProperty("--pk-duration", "0ms", "important");
3531
+ try {
3532
+ for (const el of dark) {
3533
+ el.setAttribute("data-pk-theme", "light");
3534
+ }
3535
+ try {
3536
+ return read();
3537
+ } finally {
3538
+ for (const el of dark) {
3539
+ el.setAttribute("data-pk-theme", "dark");
3540
+ }
3541
+ getComputedStyle(root).getPropertyValue("--pk-duration");
3542
+ }
3543
+ } finally {
3544
+ if (kept[0]) {
3545
+ root.style.setProperty("--pk-duration", kept[0], kept[1]);
3546
+ } else {
3547
+ root.style.removeProperty("--pk-duration");
3548
+ }
3549
+ }
3550
+ }
3233
3551
 
3234
3552
  // src/export-run.js
3235
- import { toGrid } from "pivotkit-core";
3236
3553
  var XLSX_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
3237
3554
  var exporters = null;
3238
3555
  var pending = null;
@@ -3249,6 +3566,14 @@ function loadExporters() {
3249
3566
  );
3250
3567
  return pending;
3251
3568
  }
3569
+ var reportPending = null;
3570
+ function loadReport(loadECharts) {
3571
+ reportPending ??= Promise.all([import("./chunks/report-run-BZBFOMPF.js"), loadECharts()]).catch((error) => {
3572
+ reportPending = null;
3573
+ throw error;
3574
+ });
3575
+ return reportPending;
3576
+ }
3252
3577
  var exportersNow = () => exporters;
3253
3578
  var prepareExporters = () => void loadExporters().catch(() => void 0);
3254
3579
  function deliver(blob, { doc, onExport, ...file }) {
@@ -3264,7 +3589,42 @@ async function copyOut(text, { type, container, onExport, ...file }) {
3264
3589
  }
3265
3590
  return await copyText(text, container) ? "copied" : "blocked";
3266
3591
  }
3267
- async function runExport(kind, { fileName, result, locale, labels, limits, root, chartRef, announce, onExport }) {
3592
+ var isColor = (text) => typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("color", text);
3593
+ function hexColor(text, ctx, supports = isColor) {
3594
+ if (!text || !ctx || !supports(text)) {
3595
+ return null;
3596
+ }
3597
+ ctx.fillStyle = text;
3598
+ const hex = String(ctx.fillStyle).toLowerCase();
3599
+ return /^#[0-9a-f]{6}$/.test(hex) ? hex : null;
3600
+ }
3601
+ var XLSX_TOKENS = Object.freeze(["--pk-scale-low", "--pk-scale-mid", "--pk-scale-high", "--pk-chart-1"]);
3602
+ function xlsxThemeOf(style, toHex) {
3603
+ const { colorScale = [], dataBar = "" } = chartThemeFrom(style);
3604
+ const scale = colorScale.map(toHex);
3605
+ const [low, high, mid] = [scale[0], scale.at(-1), scale.length === 3 ? scale[1] : null];
3606
+ const bar = toHex(dataBar);
3607
+ return {
3608
+ ...low && high ? { colorScale: mid ? [low, mid, high] : [low, high] } : {},
3609
+ ...bar ? { dataBar: bar } : {}
3610
+ };
3611
+ }
3612
+ function xlsxTheme(root) {
3613
+ if (!root) {
3614
+ return void 0;
3615
+ }
3616
+ const tokens = lightTokens(root, XLSX_TOKENS);
3617
+ const ctx = root.ownerDocument.createElement("canvas").getContext("2d");
3618
+ return xlsxThemeOf({ getPropertyValue: (name) => tokens[name] ?? "" }, (text) => hexColor(text, ctx));
3619
+ }
3620
+ function reportTokens(root, report, chart) {
3621
+ if (!root) {
3622
+ return void 0;
3623
+ }
3624
+ const tokens = lightTokens(root, report.REPORT_TOKENS, () => chart.tokenLengths(root, [...chart.LENGTH_TOKENS, ...report.REPORT_LENGTHS]));
3625
+ return Object.keys(tokens).length ? tokens : void 0;
3626
+ }
3627
+ async function runExport(kind, { fileName, result, locale, labels, limits, root, chartRef, announce, onExport, title, source, loadECharts }) {
3268
3628
  labels = menuLabels(labels);
3269
3629
  const base = safeFileName(fileName);
3270
3630
  const doc = root.current?.ownerDocument;
@@ -3281,6 +3641,50 @@ async function runExport(kind, { fileName, result, locale, labels, limits, root,
3281
3641
  if (!result) {
3282
3642
  return;
3283
3643
  }
3644
+ if (kind === "html" || kind === "svg" || kind === "print") {
3645
+ const [report, echarts] = await loadReport(
3646
+ /** @type {() => Promise<any>} */
3647
+ loadECharts
3648
+ );
3649
+ const chart = chartRef.current;
3650
+ const size = chart ? { width: clampSize(chart.getWidth()), height: clampSize(chart.getHeight()) } : void 0;
3651
+ const rendered = await report.render(result.view, result.encoded, {
3652
+ format: kind === "svg" ? "svg" : "html",
3653
+ echarts,
3654
+ locale,
3655
+ trusted: true,
3656
+ labels: labels.core,
3657
+ ...limits ? { limits } : {},
3658
+ timeZone: result.timeZone,
3659
+ ...title ? { title } : {},
3660
+ ...source ? { source } : {},
3661
+ ...size ? { size } : {},
3662
+ tokens: reportTokens(root.current, report, echarts),
3663
+ chartEmbed: kind === "print" ? "inline" : "image"
3664
+ });
3665
+ const file2 = `${base}.${kind === "svg" ? "svg" : "html"}`;
3666
+ const blob = new Blob([
3667
+ /** @type {BlobPart} */
3668
+ rendered.body
3669
+ ], { type: rendered.mediaType });
3670
+ if (kind !== "print") {
3671
+ if (deliver(blob, { kind, fileName: file2, doc, onExport })) {
3672
+ announce(fill(labels.toastExported, { file: file2 }));
3673
+ }
3674
+ return;
3675
+ }
3676
+ if (onExport?.({ kind, fileName: file2, blob }) === false) {
3677
+ return;
3678
+ }
3679
+ if (!root.current || !await printHtml(
3680
+ /** @type {string} */
3681
+ rendered.text,
3682
+ root.current
3683
+ )) {
3684
+ announce(labels.toastPrintBlocked, { tone: "error" });
3685
+ }
3686
+ return;
3687
+ }
3284
3688
  const m = exporters ?? await loadExporters();
3285
3689
  const grid = toGrid(result, { locale, labels: labels.core, limits });
3286
3690
  if (kind === "copy-table" || kind === "copy-json") {
@@ -3292,7 +3696,7 @@ async function runExport(kind, { fileName, result, locale, labels, limits, root,
3292
3696
  return;
3293
3697
  }
3294
3698
  const file = `${base}.${kind}`;
3295
- const bytes = kind === "xlsx" ? m.toXlsx(grid, { sheetName: base }) : m.toCsvBytes(grid, { bom: true });
3699
+ const bytes = kind === "xlsx" ? m.toXlsx(grid, { sheetName: base, theme: xlsxTheme(root.current) }) : m.toCsvBytes(grid, { bom: true });
3296
3700
  if (deliver(new Blob([
3297
3701
  /** @type {BlobPart} */
3298
3702
  bytes
@@ -3303,6 +3707,7 @@ async function runExport(kind, { fileName, result, locale, labels, limits, root,
3303
3707
  announce(fill(labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
3304
3708
  }
3305
3709
  }
3710
+ var clampSize = (px) => Math.max(100, Math.min(8e3, Math.round(Number(px) || 0)));
3306
3711
 
3307
3712
  // src/drill-export.js
3308
3713
  function rowsText({ shown, count }, labels, locale) {
@@ -3400,7 +3805,7 @@ function drillOf({ result, rowPath, colPath, count, indices, formatOf, nameOf, i
3400
3805
  // src/drill-panel.jsx
3401
3806
  function DrillPanel({ drill: source, onClose, labels, locale, exportContext }) {
3402
3807
  const id = useId6();
3403
- const drill = useMemo3(() => source ? drillOf(source, labels) : null, [source, labels]);
3808
+ const drill = useMemo4(() => source ? drillOf(source, labels) : null, [source, labels]);
3404
3809
  const panel = useRef4(
3405
3810
  /** @type {HTMLDivElement | null} */
3406
3811
  null