pivotkit-react 0.3.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.
- package/CHANGELOG.md +339 -1
- package/README.md +2 -2
- package/dist/chunks/{chunk-IOPAM4JD.js → chunk-2AT72SLA.js} +635 -980
- package/dist/chunks/chunk-3E4NB5RZ.js +215 -0
- package/dist/chunks/{chunk-32Z33U6S.js → chunk-3WUGQPWV.js} +106 -9
- package/dist/chunks/{chunk-7CC4JHDY.js → chunk-4RS72AAA.js} +27 -8
- package/dist/chunks/{chunk-EM23V5GH.js → chunk-E6M57YLL.js} +19 -8
- package/dist/chunks/{chunk-RWYHJRQO.js → chunk-JMRTIOX4.js} +17 -7
- package/dist/chunks/chunk-RIOSIYGC.js +665 -0
- package/dist/chunks/{chunk-APB4NW4O.js → chunk-U5Q5I2D5.js} +36 -10
- package/dist/chunks/report-run-BZBFOMPF.js +12 -0
- package/dist/chunks/{unused-texts-K3VFH65P.js → unused-texts-Y4R67XSN.js} +1 -1
- package/dist/chunks/{unused-texts-de-OW4TGIVX.js → unused-texts-de-6YVPTNVS.js} +1 -1
- package/dist/echarts.js +38 -156
- package/dist/import-ui.js +765 -0
- package/dist/import-worker.js +20 -0
- package/dist/index.js +683 -244
- package/dist/labels.js +14 -10
- package/dist/menu-texts-de.js +1 -1
- package/dist/menus.js +768 -299
- package/dist/styles.css +322 -100
- package/package.json +9 -4
- package/types/chart-decorate.d.ts +28 -4
- package/types/chart-types.d.ts +2 -4
- package/types/data-history.d.ts +85 -0
- package/types/data-keep.d.ts +51 -0
- package/types/data-menu.d.ts +11 -0
- package/types/dom.d.ts +40 -7
- package/types/echarts.d.ts +1 -1
- package/types/export-run.d.ts +37 -3
- package/types/field-info.d.ts +32 -0
- package/types/filter.d.ts +1 -1
- package/types/icons.d.ts +1 -0
- package/types/import-host.d.ts +53 -0
- package/types/import-labels.d.ts +401 -0
- package/types/import-limits.d.ts +6 -0
- package/types/import-module.d.ts +2 -0
- package/types/import-run.d.ts +73 -0
- package/types/import-source.d.ts +32 -0
- package/types/import-steps.d.ts +121 -0
- package/types/import-ui.d.ts +108 -0
- package/types/import-worker.d.ts +1 -0
- package/types/index.d.ts +81 -11
- package/types/labels.d.ts +224 -4
- package/types/lazy-import.d.ts +4 -0
- package/types/lazy-menus.d.ts +2 -2
- package/types/levels.d.ts +3 -2
- package/types/light-tokens.d.ts +16 -0
- package/types/menu-labels.d.ts +37 -17
- package/types/menu-ops.d.ts +161 -40
- package/types/menu-topics.d.ts +9 -8
- package/types/menus.d.ts +1 -0
- package/types/names.d.ts +47 -19
- package/types/overflow.d.ts +29 -17
- package/types/place.d.ts +24 -0
- package/types/popover.d.ts +47 -5
- package/types/print-frame.d.ts +24 -0
- package/types/report-run.d.ts +14 -0
- package/types/section.d.ts +2 -2
- package/types/share-actions.d.ts +3 -3
- package/types/share.d.ts +13 -17
- package/types/theme.d.ts +2 -16
- package/types/tips.d.ts +5 -0
- package/types/toasts.d.ts +1 -1
- package/types/toolbar-panels.d.ts +11 -9
- package/types/unused-keep.d.ts +20 -0
- package/types/unused-texts.d.ts +13 -3
- package/types/unused.d.ts +1 -0
- package/types/use-export.d.ts +2 -2
- package/types/use-view-history.d.ts +12 -4
- package/types/view-ops.d.ts +65 -6
- package/types/virtual.d.ts +15 -0
- package/types/chart-layout.d.ts +0 -111
package/dist/menus.js
CHANGED
|
@@ -3,27 +3,25 @@ import {
|
|
|
3
3
|
CHART_TYPE_NAMES,
|
|
4
4
|
ClearInput,
|
|
5
5
|
HelpContext,
|
|
6
|
-
Icon,
|
|
7
6
|
InfoButton,
|
|
8
|
-
|
|
9
|
-
MenuButton,
|
|
10
|
-
Option,
|
|
11
|
-
Popover,
|
|
7
|
+
RULE_OPS,
|
|
12
8
|
SHORTCUTS,
|
|
13
9
|
SLICE_TYPES,
|
|
14
10
|
ZONES,
|
|
15
|
-
activeIn,
|
|
16
11
|
axisOf,
|
|
17
12
|
chartTypeOf,
|
|
18
13
|
clone,
|
|
19
14
|
dateSpan,
|
|
20
15
|
dayText,
|
|
21
16
|
decodeRow,
|
|
17
|
+
emptyPick,
|
|
22
18
|
filterZoneFields,
|
|
23
19
|
filtersOf,
|
|
24
20
|
groupField,
|
|
25
21
|
groupingName,
|
|
26
22
|
groupingOf,
|
|
23
|
+
hiddenNot,
|
|
24
|
+
importNow,
|
|
27
25
|
isoDay,
|
|
28
26
|
itemRuleText,
|
|
29
27
|
linkNow,
|
|
@@ -31,16 +29,20 @@ import {
|
|
|
31
29
|
loadLink,
|
|
32
30
|
moveField,
|
|
33
31
|
numericResult,
|
|
32
|
+
opOf,
|
|
34
33
|
periodText,
|
|
34
|
+
pickFilter,
|
|
35
|
+
plainRange,
|
|
35
36
|
rangeShare,
|
|
36
37
|
readLinkParam,
|
|
37
38
|
refLabel,
|
|
38
39
|
relativeDays,
|
|
39
40
|
relativeText,
|
|
40
41
|
reorder,
|
|
41
|
-
|
|
42
|
+
ruleOp,
|
|
42
43
|
same,
|
|
43
44
|
sameRef,
|
|
45
|
+
searchItems,
|
|
44
46
|
selectedItems,
|
|
45
47
|
setSort,
|
|
46
48
|
shareBase,
|
|
@@ -48,40 +50,52 @@ import {
|
|
|
48
50
|
sortOf,
|
|
49
51
|
sortText,
|
|
50
52
|
sourceOf,
|
|
51
|
-
useModal,
|
|
52
53
|
valueConditionText,
|
|
53
54
|
valueLabel,
|
|
54
55
|
viewFromObject,
|
|
55
56
|
viewFromText,
|
|
56
57
|
wholeYears,
|
|
57
58
|
withLinkParam
|
|
58
|
-
} from "./chunks/chunk-
|
|
59
|
+
} from "./chunks/chunk-2AT72SLA.js";
|
|
59
60
|
import {
|
|
60
61
|
addMenuTexts,
|
|
61
62
|
hasMenuTexts,
|
|
62
63
|
menuLabels
|
|
63
|
-
} from "./chunks/chunk-
|
|
64
|
+
} from "./chunks/chunk-U5Q5I2D5.js";
|
|
65
|
+
import {
|
|
66
|
+
Group,
|
|
67
|
+
Icon,
|
|
68
|
+
LayerContext,
|
|
69
|
+
MenuButton,
|
|
70
|
+
Option,
|
|
71
|
+
Popover,
|
|
72
|
+
activeIn,
|
|
73
|
+
rootOf,
|
|
74
|
+
stopAfter,
|
|
75
|
+
useFormName,
|
|
76
|
+
useModal
|
|
77
|
+
} from "./chunks/chunk-RIOSIYGC.js";
|
|
64
78
|
import {
|
|
65
79
|
fill,
|
|
66
80
|
hostFailure,
|
|
67
81
|
messageOf,
|
|
68
82
|
plural
|
|
69
|
-
} from "./chunks/chunk-
|
|
83
|
+
} from "./chunks/chunk-3WUGQPWV.js";
|
|
70
84
|
|
|
71
85
|
// src/chip-menus.jsx
|
|
72
|
-
import React6, { useId as
|
|
73
|
-
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";
|
|
74
88
|
|
|
75
89
|
// src/filter-level.jsx
|
|
76
|
-
import React5, { useContext as useContext3, useEffect as useEffect2, useId as
|
|
77
|
-
import { CATALOG as
|
|
90
|
+
import React5, { useContext as useContext3, useEffect as useEffect2, useId as useId3, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
|
|
91
|
+
import { CATALOG as CATALOG3, LIMITS as LIMITS2, fieldItems as fieldItems2, fieldLabel as fieldLabel3, formatter as formatter2, relativeDateRange } from "pivotkit-core";
|
|
78
92
|
|
|
79
93
|
// src/filter.jsx
|
|
80
94
|
import React, { useMemo, useState } from "react";
|
|
81
|
-
import {
|
|
95
|
+
import { LIMITS, fieldItems, fieldLabel } from "pivotkit-core";
|
|
82
96
|
|
|
83
97
|
// src/menu-ops.js
|
|
84
|
-
import { CATALOG, computePivot, isFormat } from "pivotkit-core";
|
|
98
|
+
import { CATALOG, MATCH_DEFAULTS, computePivot, isFormat } from "pivotkit-core";
|
|
85
99
|
var COUNTING = /* @__PURE__ */ new Set(["count", "countUnique", "listUnique"]);
|
|
86
100
|
var unitOf = (agg) => COUNTING.has(agg) ? "count" : "field";
|
|
87
101
|
function updateValue(view, index, patch, options = {}) {
|
|
@@ -129,7 +143,7 @@ function replaceFilters(view, field, types, entries) {
|
|
|
129
143
|
kept.splice(at, 0, ...entries);
|
|
130
144
|
next.filters = kept;
|
|
131
145
|
if (!axisOf(next, field) && filterZoneFields(view).some((f) => same(f, field)) && !kept.some((f) => same(f.field, field))) {
|
|
132
|
-
next.filters.splice(at, 0,
|
|
146
|
+
next.filters.splice(at, 0, emptyPick(field));
|
|
133
147
|
}
|
|
134
148
|
return next;
|
|
135
149
|
}
|
|
@@ -150,7 +164,7 @@ function replaceFilter(view, field, previous, entry) {
|
|
|
150
164
|
} else {
|
|
151
165
|
next.filters.splice(at, 1);
|
|
152
166
|
if (!axisOf(next, field) && filterZoneFields(view).some((f) => same(f, field)) && !next.filters.some((f) => same(f.field, field))) {
|
|
153
|
-
next.filters.splice(at, 0,
|
|
167
|
+
next.filters.splice(at, 0, emptyPick(field));
|
|
154
168
|
}
|
|
155
169
|
}
|
|
156
170
|
return next;
|
|
@@ -158,22 +172,27 @@ function replaceFilter(view, field, previous, entry) {
|
|
|
158
172
|
function setItemFilter(view, field, selected, all) {
|
|
159
173
|
const keep = new Set(selected.map((v) => JSON.stringify(v)));
|
|
160
174
|
const excluded = all.filter((v) => !keep.has(JSON.stringify(v)));
|
|
161
|
-
return replaceFilters(view, field, ["
|
|
175
|
+
return replaceFilters(view, field, ["in"], excluded.length ? [pickFilter(field, excluded)] : []);
|
|
162
176
|
}
|
|
163
177
|
function setLabelFilter(view, field, condition) {
|
|
164
|
-
return replaceFilters(view, field, ["
|
|
178
|
+
return replaceFilters(view, field, ["text"], condition && condition.value !== "" ? [textRule(field, condition)] : []);
|
|
165
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";
|
|
166
182
|
function setTopFilter(view, field, top, previous) {
|
|
167
|
-
const
|
|
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;
|
|
168
185
|
if (previous) {
|
|
169
186
|
return replaceFilter(view, field, previous, entry);
|
|
170
187
|
}
|
|
171
188
|
return replaceFilters(view, field, ["top"], entry ? [entry] : []);
|
|
172
189
|
}
|
|
173
|
-
var RULE_TYPES = Object.freeze(["relative", "compare", "value", "
|
|
190
|
+
var RULE_TYPES = Object.freeze(["relative", "compare", "value", "text"]);
|
|
174
191
|
var RULES_MAX = 10;
|
|
175
192
|
var setRule = (view, field, previous, entry) => replaceFilter(view, field, previous, entry);
|
|
176
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" });
|
|
177
196
|
function ruleKind(encoded, view, field) {
|
|
178
197
|
const grouping = groupingOf(view, field);
|
|
179
198
|
const source = encoded.column(sourceOf(view, field))?.type ?? "string";
|
|
@@ -181,10 +200,12 @@ function ruleKind(encoded, view, field) {
|
|
|
181
200
|
const item = grouping ? grouping.by === "day" ? "date" : "group" : source === "number" || source === "date" ? source : null;
|
|
182
201
|
const cyclic = dates && Boolean(grouping) && CATALOG.cyclicUnits.includes(grouping.by);
|
|
183
202
|
const quick = dates && !cyclic;
|
|
184
|
-
|
|
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 };
|
|
185
206
|
}
|
|
186
207
|
function ruleText(view, f, { labels, locale, timeZone, date, labelOf, span }) {
|
|
187
|
-
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 });
|
|
188
209
|
}
|
|
189
210
|
function quickChoice(view, field, fk, all = []) {
|
|
190
211
|
const ranges = filtersOf(view, field, ["relative"]);
|
|
@@ -194,16 +215,16 @@ function quickChoice(view, field, fk, all = []) {
|
|
|
194
215
|
const years = whole.length ? yearsCombined(whole, all) : null;
|
|
195
216
|
return years ? { id: "yearsCombined", years, filters: whole } : { id: "all", filters: [] };
|
|
196
217
|
}
|
|
197
|
-
const
|
|
198
|
-
const r = ranges.find((f) =>
|
|
218
|
+
const units = fk.units ?? [];
|
|
219
|
+
const r = ranges.find((f) => units.includes(f.unit) && !f.not && f.blanks !== "only");
|
|
199
220
|
if (!r) {
|
|
200
221
|
return { id: "all", filters: [] };
|
|
201
222
|
}
|
|
202
223
|
const id = (
|
|
203
|
-
/** @type {"
|
|
204
|
-
r.
|
|
224
|
+
/** @type {"this" | "last" | "next" | "before"} */
|
|
225
|
+
r.direction ?? "last"
|
|
205
226
|
);
|
|
206
|
-
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] };
|
|
207
228
|
}
|
|
208
229
|
function yearsCombined(compared, all) {
|
|
209
230
|
let kept = new Set(all);
|
|
@@ -212,45 +233,76 @@ function yearsCombined(compared, all) {
|
|
|
212
233
|
/** @type {[string, string]} */
|
|
213
234
|
wholeYears(f.value, f.value2).map(Number)
|
|
214
235
|
);
|
|
215
|
-
kept = new Set([...kept].filter((y) => (a <= y && y <= b)
|
|
236
|
+
kept = new Set([...kept].filter((y) => (a <= y && y <= b) !== f.not));
|
|
216
237
|
}
|
|
217
238
|
return kept.size ? [...kept].sort((x, y) => x - y) : null;
|
|
218
239
|
}
|
|
219
|
-
var isWholeYear = (f) => f.type === "compare" &&
|
|
220
|
-
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") {
|
|
221
242
|
if (!years.length || years.length === all.length) {
|
|
222
243
|
return [];
|
|
223
244
|
}
|
|
224
245
|
const day = (y, last) => `${String(y).padStart(4, "0")}-${last ? "12-31" : "01-01"}`;
|
|
225
|
-
const rule = (
|
|
226
|
-
const rules = [rule(
|
|
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])];
|
|
227
248
|
for (let i = 1; i < years.length; i++) {
|
|
228
249
|
if (all.some((y) => years[i - 1] < y && y < years[i])) {
|
|
229
|
-
rules.push(rule(
|
|
250
|
+
rules.push(rule(true, years[i - 1] + 1, years[i] - 1));
|
|
230
251
|
}
|
|
231
252
|
}
|
|
232
253
|
return rules;
|
|
233
254
|
}
|
|
234
255
|
function setYearsCombined(view, field, years, all) {
|
|
256
|
+
const blanks = keepsBlanks(view, field) ? "include" : "exclude";
|
|
235
257
|
const cleared = filtersOf(view, field, ["compare"]).filter(isWholeYear).reduce((v, f) => setRule(v, field, f, null), view);
|
|
236
|
-
return yearRules(field, years, all).reduce((v, r) => setRule(v, field, null, r), cleared);
|
|
237
|
-
}
|
|
238
|
-
function setQuickRange(view, field, range) {
|
|
239
|
-
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);
|
|
240
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
|
+
});
|
|
241
279
|
function setAnchor(view, field, anchor) {
|
|
242
280
|
const next = clone(view);
|
|
243
281
|
for (const f of next.filters) {
|
|
244
282
|
if (same(f.field, field) && f.type === "relative") {
|
|
245
283
|
delete f.anchor;
|
|
246
|
-
if (anchor
|
|
247
|
-
f.anchor =
|
|
284
|
+
if (anchor !== "today") {
|
|
285
|
+
f.anchor = anchor;
|
|
248
286
|
}
|
|
249
287
|
}
|
|
250
288
|
}
|
|
251
289
|
return next;
|
|
252
290
|
}
|
|
253
|
-
var
|
|
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], []);
|
|
254
306
|
function itemTotals(encoded, view, field, by, filters) {
|
|
255
307
|
const result = computePivot(encoded, { ...view, rows: [field], cols: [], values: [{ ...by.field ? { field: by.field } : {}, agg: by.agg }], filters, sort: [] });
|
|
256
308
|
const totals = /* @__PURE__ */ new Map();
|
|
@@ -281,17 +333,18 @@ function removeRules(view, field, keep = []) {
|
|
|
281
333
|
return filtersOf(view, field, RULE_TYPES).filter((f) => !kept.has(JSON.stringify(f))).reduce((v, f) => setRule(v, field, f, null), view);
|
|
282
334
|
}
|
|
283
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
|
+
});
|
|
284
342
|
function totalNoEffect(view, key) {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
if (key === "grandTotalColumn") {
|
|
289
|
-
return view.cols.length >= 1 ? null : "needsColField";
|
|
343
|
+
const axis = AXIS_NEEDS[key];
|
|
344
|
+
if (view[axis.zone].length < axis.fields) {
|
|
345
|
+
return axis.why;
|
|
290
346
|
}
|
|
291
|
-
|
|
292
|
-
return view.rows.length >= 2 ? null : "needsRowFields";
|
|
293
|
-
}
|
|
294
|
-
return view.cols.length >= 2 ? null : "needsColFields";
|
|
347
|
+
return view.values.length > 0 ? null : "needsValue";
|
|
295
348
|
}
|
|
296
349
|
function conditionKind(encoded, view, field) {
|
|
297
350
|
const type = encoded.column(sourceOf(view, field))?.type ?? "string";
|
|
@@ -305,20 +358,33 @@ function filterState(view, field, state, labels, locale) {
|
|
|
305
358
|
}
|
|
306
359
|
parts.push(...state?.rules ?? []);
|
|
307
360
|
for (const f of view.filters.filter(same2)) {
|
|
308
|
-
if (f.type === "value" || f.type === "
|
|
361
|
+
if (f.type === "value" || f.type === "text" && !state?.rules) {
|
|
309
362
|
parts.push(ruleText(view, f, { labels, locale, timeZone: "UTC", date: false }));
|
|
310
363
|
}
|
|
311
364
|
}
|
|
312
365
|
return parts.length ? parts.join(", ") : null;
|
|
313
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
|
+
}
|
|
314
380
|
|
|
315
381
|
// src/filter.jsx
|
|
316
382
|
var FILTER_LIST_MAX = 300;
|
|
317
383
|
var keyOf = (v) => JSON.stringify(v);
|
|
318
384
|
function ValueList({ items, selected, onChange, labels, locale, autoFocus = false, tail, children }) {
|
|
319
385
|
const [query, setQuery] = useState("");
|
|
320
|
-
const
|
|
321
|
-
const matching =
|
|
386
|
+
const name = useFormName();
|
|
387
|
+
const matching = searchItems(items, query);
|
|
322
388
|
const inList = tail ? matching.filter((i) => !tail.isOut(i)) : matching;
|
|
323
389
|
const out = tail ? matching.filter((i) => tail.isOut(i)) : [];
|
|
324
390
|
const shown = inList.slice(0, FILTER_LIST_MAX);
|
|
@@ -345,17 +411,23 @@ function ValueList({ items, selected, onChange, labels, locale, autoFocus = fals
|
|
|
345
411
|
};
|
|
346
412
|
const row = (i, muted) => {
|
|
347
413
|
const k = keyOf(i.value);
|
|
348
|
-
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", 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));
|
|
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));
|
|
349
415
|
};
|
|
350
|
-
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(
|
|
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));
|
|
351
422
|
}
|
|
352
423
|
function FilterBody({ view: current, base, field, encoded, locale, labels, commit, close }) {
|
|
353
424
|
const view = base ?? current;
|
|
425
|
+
const formName = useFormName();
|
|
354
426
|
const info = useMemo(() => fieldItems(encoded, field, { view, locale, labels: labels.core }), [encoded, field, view, locale, labels]);
|
|
355
427
|
const all = useMemo(() => info ? info.items.map((i) => i.value) : [], [info]);
|
|
356
428
|
const [selected, setSelected] = useState(() => new Set(selectedItems(view, field, all).map(keyOf)));
|
|
357
|
-
const label = filtersOf(view, field, ["
|
|
358
|
-
const [op, setOp] = useState(label
|
|
429
|
+
const label = filtersOf(view, field, ["text"])[0];
|
|
430
|
+
const [op, setOp] = useState(label ? ruleOp(label) : "");
|
|
359
431
|
const [text, setText] = useState(label?.value ?? "");
|
|
360
432
|
if (!info) {
|
|
361
433
|
return null;
|
|
@@ -363,7 +435,7 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
|
|
|
363
435
|
const name = fieldLabel(field, labels.core);
|
|
364
436
|
const apply = () => {
|
|
365
437
|
let next = setItemFilter(view, field, all.filter((v) => selected.has(keyOf(v))), all);
|
|
366
|
-
next = setLabelFilter(next, field, op ? { op, value: text } : null);
|
|
438
|
+
next = setLabelFilter(next, field, op ? { op, value: text, on: textOn(encoded, field) } : null);
|
|
367
439
|
close();
|
|
368
440
|
commit(next, { step: "filter", field: name });
|
|
369
441
|
};
|
|
@@ -378,21 +450,21 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
|
|
|
378
450
|
}
|
|
379
451
|
},
|
|
380
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) }))),
|
|
381
|
-
/* @__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", { value: op, onChange: (e) => setOp(e.target.value), "aria-label": kind === "number" ? labels.conditionNumber : labels.condition }, /* @__PURE__ */ React.createElement("option", { value: "" }, labels.conditionNone),
|
|
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(
|
|
382
454
|
ClearInput,
|
|
383
455
|
{
|
|
384
456
|
type: "text",
|
|
385
457
|
value: text,
|
|
386
458
|
onChange: setText,
|
|
387
459
|
onClear: () => {
|
|
388
|
-
if (!base && filtersOf(view, field, ["
|
|
460
|
+
if (!base && filtersOf(view, field, ["text"]).length) {
|
|
389
461
|
commit(setLabelFilter(view, field, null), { step: "filter", field: name });
|
|
390
462
|
}
|
|
391
463
|
},
|
|
392
464
|
clearLabel: labels.clearText,
|
|
393
465
|
"aria-label": labels.conditionValue,
|
|
394
466
|
placeholder: labels.conditionValue,
|
|
395
|
-
maxLength:
|
|
467
|
+
maxLength: LIMITS.textValue,
|
|
396
468
|
"data-testid": "filter-condition-text"
|
|
397
469
|
}
|
|
398
470
|
) : null) : null),
|
|
@@ -405,10 +477,10 @@ function FilterPopover({ target, onClose, view, encoded, locale, labels, commit
|
|
|
405
477
|
}
|
|
406
478
|
|
|
407
479
|
// src/levels.jsx
|
|
408
|
-
import React3, { useContext as useContext2, useEffect, useId
|
|
480
|
+
import React3, { useContext as useContext2, useEffect, useId, useLayoutEffect, useRef, useState as useState2 } from "react";
|
|
409
481
|
|
|
410
482
|
// src/section.jsx
|
|
411
|
-
import React2, { useContext
|
|
483
|
+
import React2, { useContext } from "react";
|
|
412
484
|
function SettingInfo({ id, name, tabIndex }) {
|
|
413
485
|
const { explain, labels } = useContext(HelpContext);
|
|
414
486
|
const text = labels && labels.settingInfo && Object.hasOwn(labels.settingInfo, id) ? labels.settingInfo[id] : null;
|
|
@@ -418,21 +490,20 @@ function SettingInfo({ id, name, tabIndex }) {
|
|
|
418
490
|
return /* @__PURE__ */ React2.createElement(InfoButton, { info: { description: text }, name, label: fill(labels.aboutSetting, { setting: name }), labels, className: "pk-setting-info", testId: `setting-info-${id}`, tabIndex });
|
|
419
491
|
}
|
|
420
492
|
function Section({ title, children, info }) {
|
|
421
|
-
const titleId = useId();
|
|
422
493
|
const name = typeof title === "string" ? title : "";
|
|
423
|
-
return /* @__PURE__ */ React2.createElement(
|
|
494
|
+
return /* @__PURE__ */ React2.createElement(Group, { title, head: info ? /* @__PURE__ */ React2.createElement(SettingInfo, { id: info, name }) : null }, children);
|
|
424
495
|
}
|
|
425
496
|
|
|
426
497
|
// src/menu-topics.js
|
|
427
|
-
import { CATALOG as
|
|
498
|
+
import { CATALOG as CATALOG2, aggregatorsFor, fieldLabel as fieldLabel2, formatter, isFormat as isFormat2 } from "pivotkit-core";
|
|
428
499
|
var FORMAT_CHOICES = Object.freeze(["number", "number:0", "number:2", "currency", "percent"].filter(isFormat2));
|
|
429
500
|
var MORE_FORMATS = Object.freeze(["integer", "compact", "bytes", "duration:h", "duration:s"].filter(isFormat2));
|
|
430
|
-
var COMMON_SHOW_AS =
|
|
501
|
+
var COMMON_SHOW_AS = CATALOG2.showAs.filter((s) => ["percentOfGrandTotal", "percentOfRowTotal", "percentOfColumnTotal"].includes(s));
|
|
431
502
|
var EXAMPLE = Object.freeze({ percent: 0.256, bytes: 1536e3, "duration:h": 1.5, "duration:s": 3725 });
|
|
432
503
|
var TOP_COUNTS = Object.freeze([3, 5, 10]);
|
|
433
|
-
function moveTopic(view, zone, index, count, labels, name, type) {
|
|
504
|
+
function moveTopic(view, zone, index, count, labels, name, type, defaults) {
|
|
434
505
|
const note = (z) => ({ step: "moved", field: name, zone: z });
|
|
435
|
-
const choices = ZONES.filter((z) => z !== zone).map((z) => ({ id: `move-${z}`, text: fill(labels.moveTo, { zone: labels.zones[z] }), icon: "chevronRight", closes: true, change: () => ({ view: moveField(view, zone, index, z, void 0, { type }), note: note(z) }) }));
|
|
506
|
+
const choices = ZONES.filter((z) => z !== zone).map((z) => ({ id: `move-${z}`, text: fill(labels.moveTo, { zone: labels.zones[z] }), icon: "chevronRight", closes: true, change: () => ({ view: moveField(view, zone, index, z, void 0, { type, defaults: z === "values" ? defaults : void 0 }), note: note(z) }) }));
|
|
436
507
|
if (zone !== "filters" && index > 0) {
|
|
437
508
|
choices.push({ id: "move-left", text: labels.moveLeft, icon: "chevronRight", closes: true, change: () => ({ view: reorder(view, zone, index, index - 1), note: { step: "reordered", zone } }) });
|
|
438
509
|
}
|
|
@@ -502,8 +573,8 @@ function axisTopics({ view, zone, index, field, types, labels, locale, state, de
|
|
|
502
573
|
state: grouping ? labels.units[grouping.by] ?? grouping.by : labels.groupNoneShort,
|
|
503
574
|
changed: Boolean(grouping),
|
|
504
575
|
groups: [
|
|
505
|
-
{ title: labels.groupTimeline, choices:
|
|
506
|
-
{ title: labels.groupCyclic, choices:
|
|
576
|
+
{ title: labels.groupTimeline, choices: CATALOG2.timelineUnits.map(unit) },
|
|
577
|
+
{ title: labels.groupCyclic, choices: CATALOG2.cyclicUnits.map(unit) },
|
|
507
578
|
{ choices: [{ id: "group-none", text: labels.groupNone, checked: !grouping, closes: true, change: regroup(null) }] }
|
|
508
579
|
]
|
|
509
580
|
});
|
|
@@ -527,7 +598,7 @@ function axisTopics({ view, zone, index, field, types, labels, locale, state, de
|
|
|
527
598
|
choice: { id: `top-${n}`, text: fill(labels.topBadge, { count: n.toLocaleString(locale) }), checked: Boolean(top && !top.bottom && top.count === n), change: () => ({ view: setTopFilter(view, field, { count: n, bottom: false, by: topBy }, top), note: { step: "top", field: name } }) }
|
|
528
599
|
}))
|
|
529
600
|
});
|
|
530
|
-
topics.push(moveTopic(view, zone, index, view[zone].length, labels, name, sourceType));
|
|
601
|
+
topics.push(moveTopic(view, zone, index, view[zone].length, labels, name, sourceType, defaultsOf?.(field)));
|
|
531
602
|
return topics;
|
|
532
603
|
}
|
|
533
604
|
var NUMBER_TYPED = /\d+/;
|
|
@@ -543,19 +614,21 @@ function filterTopic({ view, field, labels, locale, state, encoded }) {
|
|
|
543
614
|
if (!Number.isSafeInteger(n) || n < 1) {
|
|
544
615
|
return [];
|
|
545
616
|
}
|
|
546
|
-
const units = n >
|
|
617
|
+
const units = n > CATALOG2.relativeMaxCount ? [] : fk.months ? ["year", "month"] : ["year"];
|
|
547
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";
|
|
548
621
|
const span = dateSpan(encoded, sourceOf(view, field));
|
|
549
622
|
const ranges = units.map((unit) => {
|
|
550
623
|
const text = capital2(relativeText({ unit, count: n, anchor }, labels, locale, timeZone, void 0, span));
|
|
551
|
-
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 }) } };
|
|
552
625
|
});
|
|
553
626
|
const keyed = fk.item === "group" && n >= 1e3 && n <= 9999 && view.derived.some((d) => d.name.toLowerCase() === field.toLowerCase() && d.by === "year");
|
|
554
627
|
if (!keyed) {
|
|
555
628
|
return ranges;
|
|
556
629
|
}
|
|
557
630
|
const compares = [">=", "<=", "<", ">"].map((op) => {
|
|
558
|
-
const entry = { field, type: "compare", op, value: n };
|
|
631
|
+
const entry = { field, type: "compare", op, value: n, not: false, blanks: "exclude" };
|
|
559
632
|
const text = capital2(fill(labels.compareShort[op], { value: String(n) }));
|
|
560
633
|
return { id: `compare-${op}-${n}`, text, choice: { id: `compare-${op}-${n}`, text, change: () => ({ view: setRule(view, field, null, entry), note }) } };
|
|
561
634
|
});
|
|
@@ -572,7 +645,8 @@ function filterTopic({ view, field, labels, locale, state, encoded }) {
|
|
|
572
645
|
// the rules are found by their names, and open the level on them
|
|
573
646
|
searchExtra: [
|
|
574
647
|
{ id: "open-filter-rules", text: labels.rulesTitle, focus: "conditions" },
|
|
575
|
-
|
|
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(" ") },
|
|
576
650
|
{ id: "open-filter-value", text: labels.addRuleTotal, focus: "conditions" }
|
|
577
651
|
],
|
|
578
652
|
searchFor
|
|
@@ -605,7 +679,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
|
|
|
605
679
|
const set = (patch) => () => ({ view: updateValue(view, index, patch, { defaults }), note: { step: "value", field: name } });
|
|
606
680
|
const aggs = spec.field ? aggregatorsFor(type) : ["count"];
|
|
607
681
|
const agg = (a) => ({ id: `agg-${a}`, text: labels.core.aggregators[a] ?? a, checked: spec.agg === a, closes: true, change: set({ agg: a }) });
|
|
608
|
-
const rare = aggs.filter((a) => !
|
|
682
|
+
const rare = aggs.filter((a) => !CATALOG2.commonAggregators.includes(a));
|
|
609
683
|
const topics = [
|
|
610
684
|
{
|
|
611
685
|
id: "summarize",
|
|
@@ -613,7 +687,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
|
|
|
613
687
|
kind: "menu",
|
|
614
688
|
icon: "sigma",
|
|
615
689
|
state: labels.core.aggregators[spec.agg] ?? spec.agg,
|
|
616
|
-
groups: [{ choices:
|
|
690
|
+
groups: [{ choices: CATALOG2.commonAggregators.filter((a) => aggs.includes(a)).map(agg) }, ...rare.length ? [{ title: labels.moreStatistics, choices: rare.map(agg) }] : []]
|
|
617
691
|
}
|
|
618
692
|
];
|
|
619
693
|
if (numericResult(spec, type)) {
|
|
@@ -621,7 +695,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
|
|
|
621
695
|
const text = labels.showAsNames[s] ?? s;
|
|
622
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" } }) };
|
|
623
697
|
};
|
|
624
|
-
const along = spec.showAs &&
|
|
698
|
+
const along = spec.showAs && CATALOG2.showAsAlongAxis.includes(spec.showAs.type) ? spec.showAs : null;
|
|
625
699
|
topics.push({
|
|
626
700
|
id: "showAs",
|
|
627
701
|
title: labels.showAs,
|
|
@@ -632,7 +706,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
|
|
|
632
706
|
changed: Boolean(spec.showAs),
|
|
633
707
|
groups: [
|
|
634
708
|
{ choices: [{ id: "showas-none", text: labels.showAsNone, checked: !spec.showAs, change: set({ showAs: null }) }, ...COMMON_SHOW_AS.map(showAs)] },
|
|
635
|
-
{ title: labels.moreCalculations, choices:
|
|
709
|
+
{ title: labels.moreCalculations, choices: CATALOG2.showAs.filter((s) => !COMMON_SHOW_AS.includes(s)).map(showAs) },
|
|
636
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 } }) })) }] : []
|
|
637
711
|
]
|
|
638
712
|
});
|
|
@@ -715,7 +789,7 @@ function optionTopics({ view, labels, folding, tips, explanations, act }) {
|
|
|
715
789
|
{
|
|
716
790
|
choices: TOTALS.map((key) => {
|
|
717
791
|
const why = totalNoEffect(view, key);
|
|
718
|
-
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]) };
|
|
719
793
|
})
|
|
720
794
|
}
|
|
721
795
|
]
|
|
@@ -753,7 +827,7 @@ function searchEntries(topics, query = "") {
|
|
|
753
827
|
return [];
|
|
754
828
|
}
|
|
755
829
|
const typed = query && topic.searchFor ? topic.searchFor(query) : [];
|
|
756
|
-
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 }));
|
|
757
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 })));
|
|
758
832
|
});
|
|
759
833
|
}
|
|
@@ -765,7 +839,7 @@ function searchHits(entries, query, locale) {
|
|
|
765
839
|
return [];
|
|
766
840
|
}
|
|
767
841
|
const found = entries.filter((e) => {
|
|
768
|
-
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 ?? ""}`);
|
|
769
843
|
return words.every((w) => text.includes(w));
|
|
770
844
|
});
|
|
771
845
|
const own = (e) => lower(e.choice?.keywords ?? "").split(/\s+/).includes(words[0]);
|
|
@@ -825,10 +899,11 @@ function tabLeaves(e, close) {
|
|
|
825
899
|
/** @type {Element} */
|
|
826
900
|
e.target
|
|
827
901
|
);
|
|
828
|
-
|
|
902
|
+
const next = opener ? stopAfter(opener) : null;
|
|
903
|
+
e.preventDefault();
|
|
904
|
+
next?.focus();
|
|
905
|
+
if (opener && (!next || activeIn(next) !== next)) {
|
|
829
906
|
opener.focus({ preventScroll: true });
|
|
830
|
-
} else {
|
|
831
|
-
e.preventDefault();
|
|
832
907
|
}
|
|
833
908
|
close();
|
|
834
909
|
return true;
|
|
@@ -932,7 +1007,7 @@ function MenuList({ label, labelledBy, className, close, children, testId }) {
|
|
|
932
1007
|
}
|
|
933
1008
|
function MenuItem({ id, text, onSelect, checked, checkbox, hint, icon, danger, testId, start, plain, label, className, disabled, reason, haspopup, level, description, current, children }) {
|
|
934
1009
|
const role = checked === void 0 ? "menuitem" : checkbox ? "menuitemcheckbox" : "menuitemradio";
|
|
935
|
-
const reasonId =
|
|
1010
|
+
const reasonId = useId();
|
|
936
1011
|
const describedBy = [disabled && reason ? reasonId : null, description ? `${reasonId}-d` : null].filter(Boolean).join(" ") || void 0;
|
|
937
1012
|
return /* @__PURE__ */ React3.createElement(
|
|
938
1013
|
"button",
|
|
@@ -999,21 +1074,17 @@ function TopicRow({ topic, labels, onOpen }) {
|
|
|
999
1074
|
);
|
|
1000
1075
|
}
|
|
1001
1076
|
function Groups({ topic, onPick }) {
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
});
|
|
1007
|
-
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, groups, topic.note ? /* @__PURE__ */ React3.createElement("p", { className: "pk-hint pk-menu-hint", role: "none", "data-testid": topic.noteId }, topic.note) : null);
|
|
1077
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, (topic.groups ?? []).map((g, i) => /* @__PURE__ */ React3.createElement(Group, { key: i, menu: true, title: g.title, label: g.title ? void 0 : topic.title }, g.choices.map((c) => /* @__PURE__ */ React3.createElement(ChoiceItem, { key: c.id, choice: c, start: c.checked, onPick })))), /* @__PURE__ */ React3.createElement(TopicNote, { topic }));
|
|
1078
|
+
}
|
|
1079
|
+
function TopicNote({ topic }) {
|
|
1080
|
+
return topic.note ? /* @__PURE__ */ React3.createElement("p", { className: "pk-hint pk-menu-hint", role: "none", "data-testid": topic.noteId }, topic.note) : null;
|
|
1008
1081
|
}
|
|
1009
1082
|
function TopicFirst({ topic, labels, onPick, onOpen }) {
|
|
1010
|
-
const titleId = useId2();
|
|
1011
1083
|
if (topic.hidden) {
|
|
1012
1084
|
return null;
|
|
1013
1085
|
}
|
|
1014
1086
|
if (topic.kind === "menu" || topic.kind === "panel") {
|
|
1015
|
-
|
|
1016
|
-
return topic.heading ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { className: "pk-subtitle", id: titleId, role: "presentation", "data-testid": `topic-title-${topic.id}` }, topic.heading), /* @__PURE__ */ React3.createElement("div", { role: "group", "aria-labelledby": titleId }, row)) : row;
|
|
1087
|
+
return /* @__PURE__ */ React3.createElement(TopicRow, { topic, labels, onOpen });
|
|
1017
1088
|
}
|
|
1018
1089
|
const choices = topic.groups?.[0]?.choices ?? [];
|
|
1019
1090
|
if (topic.kind === "segmented") {
|
|
@@ -1025,7 +1096,8 @@ function TopicFirst({ topic, labels, onPick, onOpen }) {
|
|
|
1025
1096
|
) }) : null), topic.title, topic.changed && !topic.state ? /* @__PURE__ */ React3.createElement("span", { className: "pk-section-mark" }, " \u25CF") : null), topic.state ? /* @__PURE__ */ React3.createElement("span", { className: "pk-topic-state pk-topic-seg-state", "data-testid": `topic-state-${topic.id}` }, topic.changed ? /* @__PURE__ */ React3.createElement("span", { className: "pk-section-mark", "aria-hidden": "true" }, "\u25CF ") : null, /* @__PURE__ */ React3.createElement("span", { className: "pk-badge-cut" }, topic.state)) : null, /* @__PURE__ */ React3.createElement("span", { className: "pk-segmented pk-small" }, choices.map((c) => /* @__PURE__ */ React3.createElement("button", { key: c.id, type: "button", role: "menuitemradio", "aria-checked": Boolean(c.checked), tabIndex: -1, "data-pk-option": "", "data-pk-item": c.id, "data-pk-text": c.text, "data-testid": c.id, onClick: () => onPick(c) }, c.text))))
|
|
1026
1097
|
);
|
|
1027
1098
|
}
|
|
1028
|
-
|
|
1099
|
+
const items = choices.map((c) => /* @__PURE__ */ React3.createElement(ChoiceItem, { key: c.id, choice: c, onPick }));
|
|
1100
|
+
return topic.titled ? /* @__PURE__ */ React3.createElement(Group, { menu: true, title: topic.title, testId: `topic-${topic.id}`, titleTestId: `topic-title-${topic.id}`, after: /* @__PURE__ */ React3.createElement(TopicNote, { topic }) }, items) : /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { role: "group", "aria-label": topic.title, "data-testid": `topic-${topic.id}` }, items), /* @__PURE__ */ React3.createElement(TopicNote, { topic }));
|
|
1029
1101
|
}
|
|
1030
1102
|
function SearchHits({ hits, labels, onPick, onOpen, close }) {
|
|
1031
1103
|
if (!hits.length) {
|
|
@@ -1044,7 +1116,7 @@ function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, sea
|
|
|
1044
1116
|
/** @type {HTMLDivElement | null} */
|
|
1045
1117
|
null
|
|
1046
1118
|
);
|
|
1047
|
-
const titleId =
|
|
1119
|
+
const titleId = useId();
|
|
1048
1120
|
const topic = level ? topics.find((t) => t.id === level) ?? null : null;
|
|
1049
1121
|
useLayoutEffect(() => {
|
|
1050
1122
|
const el = box.current;
|
|
@@ -1213,7 +1285,7 @@ function useAppliedText(applied, apply, wait = 450) {
|
|
|
1213
1285
|
}
|
|
1214
1286
|
|
|
1215
1287
|
// src/menu-fields.jsx
|
|
1216
|
-
import React4, { useId as
|
|
1288
|
+
import React4, { useId as useId2 } from "react";
|
|
1217
1289
|
|
|
1218
1290
|
// src/numbers.js
|
|
1219
1291
|
var cache = /* @__PURE__ */ new Map();
|
|
@@ -1283,11 +1355,13 @@ function readNumber(text, { kind = "number", required = true, tried = false, max
|
|
|
1283
1355
|
return ok ? { value, problem: null } : { value: null, problem: say() };
|
|
1284
1356
|
}
|
|
1285
1357
|
function NumberField({ value, onChange, problem, label, testId, className = "pk-field-label", shown, shownClass, onKeyDown, onBlur, onFocus, autoFocus }) {
|
|
1286
|
-
const id =
|
|
1358
|
+
const id = useId2();
|
|
1359
|
+
const name = useFormName();
|
|
1287
1360
|
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement("label", { className }, shown ? /* @__PURE__ */ React4.createElement("span", { className: shownClass }, shown) : /* @__PURE__ */ React4.createElement("span", { className: "pk-sr" }, label), /* @__PURE__ */ React4.createElement(
|
|
1288
1361
|
"input",
|
|
1289
1362
|
{
|
|
1290
1363
|
type: "text",
|
|
1364
|
+
name,
|
|
1291
1365
|
inputMode: "decimal",
|
|
1292
1366
|
autoComplete: "off",
|
|
1293
1367
|
spellCheck: false,
|
|
@@ -1317,10 +1391,11 @@ var fieldKeys = ({ now, restore, back }) => (e) => {
|
|
|
1317
1391
|
}
|
|
1318
1392
|
};
|
|
1319
1393
|
function MeasurePick({ choices, names, index, onChange, label, prefix, testId }) {
|
|
1394
|
+
const name = useFormName();
|
|
1320
1395
|
if (choices.length < 2) {
|
|
1321
1396
|
return /* @__PURE__ */ React4.createElement("span", { className: "pk-by", "data-testid": testId }, prefix ? `${prefix} ${names[0]}` : names[0]);
|
|
1322
1397
|
}
|
|
1323
|
-
return /* @__PURE__ */ React4.createElement("label", { className: "pk-field-label pk-by-pick" }, prefix ? /* @__PURE__ */ React4.createElement("span", null, prefix) : /* @__PURE__ */ React4.createElement("span", { className: "pk-sr" }, label), /* @__PURE__ */ React4.createElement("select", { value: index, onChange: (e) => onChange(Number(e.target.value)), "aria-label": label, "data-testid": testId }, choices.map((c, i) => /* @__PURE__ */ React4.createElement("option", { key: `${c.field}:${c.agg}`, value: i }, names[i]))));
|
|
1398
|
+
return /* @__PURE__ */ React4.createElement("label", { className: "pk-field-label pk-by-pick" }, prefix ? /* @__PURE__ */ React4.createElement("span", null, prefix) : /* @__PURE__ */ React4.createElement("span", { className: "pk-sr" }, label), /* @__PURE__ */ React4.createElement("select", { name, value: index, onChange: (e) => onChange(Number(e.target.value)), "aria-label": label, "data-testid": testId }, choices.map((c, i) => /* @__PURE__ */ React4.createElement("option", { key: `${c.field}:${c.agg}`, value: i }, names[i]))));
|
|
1324
1399
|
}
|
|
1325
1400
|
var choiceIndex = (choices, ref) => Math.max(0, choices.findIndex((c) => sameRef(c, ref)));
|
|
1326
1401
|
function measuresOf(view, types, labels, ref) {
|
|
@@ -1332,26 +1407,17 @@ function measuresOf(view, types, labels, ref) {
|
|
|
1332
1407
|
var twin = (op) => op === "between" || op === "notBetween";
|
|
1333
1408
|
var capital = (text, locale) => text.charAt(0).toLocaleUpperCase(locale) + text.slice(1);
|
|
1334
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);
|
|
1335
|
-
var rowKind = (f) => f.type === "value" ? "total" : f.type === "
|
|
1336
|
-
var
|
|
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 });
|
|
1337
1415
|
var PICKER_MIN = 13;
|
|
1338
|
-
var MS_PER_DAY = 864e5;
|
|
1339
1416
|
function nounOf(fk, labels) {
|
|
1340
1417
|
const unit = fk.unit;
|
|
1341
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());
|
|
1342
1419
|
return Object.hasOwn(labels.nouns, key) ? labels.nouns[key] : labels.nouns.item;
|
|
1343
1420
|
}
|
|
1344
|
-
function rowsIn(range, column, counts) {
|
|
1345
|
-
const from = Date.parse(`${range.from}T00:00Z`);
|
|
1346
|
-
const to = Date.parse(`${range.to}T00:00Z`) + MS_PER_DAY;
|
|
1347
|
-
let rows = 0;
|
|
1348
|
-
column.dict.forEach((v, code) => {
|
|
1349
|
-
if (typeof v === "number" && v >= from && v < to) {
|
|
1350
|
-
rows += counts[code];
|
|
1351
|
-
}
|
|
1352
|
-
});
|
|
1353
|
-
return rows;
|
|
1354
|
-
}
|
|
1355
1421
|
function countsOf(column) {
|
|
1356
1422
|
const counts = new Float64Array(column.dict.length);
|
|
1357
1423
|
for (let i = 0; i < column.codes.length; i++) {
|
|
@@ -1373,7 +1439,7 @@ function yearsOf(column, counts) {
|
|
|
1373
1439
|
}
|
|
1374
1440
|
function LeftOut({ out, row, searching, labels, locale }) {
|
|
1375
1441
|
const [open, setOpen] = useState3(false);
|
|
1376
|
-
const id =
|
|
1442
|
+
const id = useId3();
|
|
1377
1443
|
const shown = open || searching;
|
|
1378
1444
|
const list = useRef2(
|
|
1379
1445
|
/** @type {HTMLUListElement | null} */
|
|
@@ -1387,7 +1453,7 @@ function LeftOut({ out, row, searching, labels, locale }) {
|
|
|
1387
1453
|
return /* @__PURE__ */ React5.createElement("li", { className: "pk-values-tail" }, /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-tail-toggle", "aria-expanded": shown, "aria-controls": id, onClick: () => setOpen(!shown), "data-testid": "tail-toggle" }, /* @__PURE__ */ React5.createElement(Icon, { name: shown ? "chevronDown" : "chevronRight", size: 14 }), /* @__PURE__ */ React5.createElement("span", null, fill(plural(labels.tailOut, out.length, { lang: labels.lang, locale }), { count: out.length.toLocaleString(locale) }))), shown ? /* @__PURE__ */ React5.createElement("ul", { ref: list, id, role: "list", className: "pk-tail-list", "data-testid": "tail-list" }, out.slice(0, FILTER_LIST_MAX).map(row)) : null);
|
|
1388
1454
|
}
|
|
1389
1455
|
function Section2({ id, title, state, open, onToggle, action, children }) {
|
|
1390
|
-
const bodyId =
|
|
1456
|
+
const bodyId = useId3();
|
|
1391
1457
|
return /* @__PURE__ */ React5.createElement("section", { className: "pk-fsection", "data-testid": `fsection-${id}` }, /* @__PURE__ */ React5.createElement("div", { className: "pk-fsection-head" }, /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-fsection-toggle", "aria-expanded": open, "aria-controls": bodyId, onClick: onToggle, "data-testid": `section-${id}` }, /* @__PURE__ */ React5.createElement(Icon, { name: open ? "chevronDown" : "chevronRight", size: 16 }), /* @__PURE__ */ React5.createElement("span", { className: "pk-fsection-title" }, title), state ? /* @__PURE__ */ React5.createElement("span", { className: "pk-fsection-state" }, state) : null), action), open ? /* @__PURE__ */ React5.createElement("div", { className: "pk-fsection-body", id: bodyId, "data-testid": `${id}-body` }, children) : null);
|
|
1392
1458
|
}
|
|
1393
1459
|
function Summary({ ctx, state }) {
|
|
@@ -1422,152 +1488,268 @@ function Summary({ ctx, state }) {
|
|
|
1422
1488
|
}
|
|
1423
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)));
|
|
1424
1490
|
}
|
|
1425
|
-
|
|
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 }) {
|
|
1426
1495
|
const { view, field, labels, locale, fk, timeZone, commit, note, back } = ctx;
|
|
1427
1496
|
const lang = { lang: labels.lang, locale };
|
|
1428
|
-
const
|
|
1429
|
-
const
|
|
1497
|
+
const more = labels.relativeMore;
|
|
1498
|
+
const units = fk.units;
|
|
1499
|
+
const weekStart = view.formatting?.weekStart;
|
|
1500
|
+
const latestDay = isoDay(span.max);
|
|
1430
1501
|
const [now] = useState3(() => Date.now());
|
|
1431
|
-
const
|
|
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;
|
|
1432
1511
|
const reach = (unit) => {
|
|
1433
1512
|
for (let n = 1; n <= REACH[unit]; n++) {
|
|
1434
|
-
|
|
1435
|
-
if (r && r.from <= latestDay) {
|
|
1513
|
+
if (reaches(datesOf({ unit, count: n }))) {
|
|
1436
1514
|
return n;
|
|
1437
1515
|
}
|
|
1438
1516
|
}
|
|
1439
|
-
return
|
|
1517
|
+
return REACH[unit];
|
|
1440
1518
|
};
|
|
1441
|
-
const
|
|
1442
|
-
const
|
|
1443
|
-
const
|
|
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);
|
|
1444
1526
|
const [editing, setEditing] = useState3(
|
|
1445
1527
|
/** @type {string | null} */
|
|
1446
1528
|
null
|
|
1447
1529
|
);
|
|
1448
|
-
const quickKey =
|
|
1530
|
+
const quickKey = JSON.stringify([quick.id, quick.unit, quick.count, quick.calendar, quick.includeCurrent]);
|
|
1449
1531
|
const [seen, setSeen] = useState3(quickKey);
|
|
1450
1532
|
if (quickKey !== seen) {
|
|
1451
1533
|
setSeen(quickKey);
|
|
1452
|
-
|
|
1453
|
-
|
|
1454
|
-
|
|
1455
|
-
|
|
1456
|
-
|
|
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
|
+
);
|
|
1457
1544
|
}
|
|
1458
|
-
setTexts(synced);
|
|
1459
1545
|
}
|
|
1460
1546
|
const later = useLater();
|
|
1461
|
-
const group =
|
|
1462
|
-
const
|
|
1547
|
+
const group = useId3();
|
|
1548
|
+
const groupName = useFormName();
|
|
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}`;
|
|
1463
1558
|
const sub = (range, unit, id) => {
|
|
1464
|
-
|
|
1465
|
-
if (share?.none) {
|
|
1559
|
+
if (!range) {
|
|
1466
1560
|
return null;
|
|
1467
1561
|
}
|
|
1468
|
-
const
|
|
1469
|
-
|
|
1470
|
-
|
|
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) })));
|
|
1471
1578
|
};
|
|
1472
|
-
const
|
|
1473
|
-
|
|
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);
|
|
1474
1593
|
const hidden = [];
|
|
1475
|
-
const
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1494
|
-
|
|
1495
|
-
const
|
|
1496
|
-
|
|
1497
|
-
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1501
|
-
|
|
1502
|
-
|
|
1503
|
-
|
|
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();
|
|
1504
1641
|
}
|
|
1505
|
-
}
|
|
1506
|
-
const
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
setEditing(null);
|
|
1536
|
-
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;
|
|
1537
1672
|
},
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
}
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
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"));
|
|
1547
1694
|
const today = new Date(relativeDays({ unit: "day", count: 1 }, timeZone, now)?.from ?? isoDay(now));
|
|
1548
1695
|
const periodStart = fk.months ? Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), 1) : Date.UTC(today.getUTCFullYear(), 0, 1);
|
|
1549
|
-
const
|
|
1550
|
-
const
|
|
1551
|
-
|
|
1552
|
-
|
|
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",
|
|
1553
1716
|
{
|
|
1554
|
-
|
|
1555
|
-
|
|
1717
|
+
type: "date",
|
|
1718
|
+
name: `${formName}-day`,
|
|
1719
|
+
value: day,
|
|
1556
1720
|
onChange: (e) => {
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
e.target.value
|
|
1560
|
-
);
|
|
1561
|
-
setAnchorLocal(next);
|
|
1562
|
-
if (quick.filters.length) {
|
|
1563
|
-
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);
|
|
1564
1724
|
}
|
|
1565
1725
|
},
|
|
1566
|
-
|
|
1567
|
-
|
|
1568
|
-
|
|
1569
|
-
|
|
1570
|
-
|
|
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);
|
|
1571
1753
|
}
|
|
1572
1754
|
function YearsCombined({ ctx, years, on }) {
|
|
1573
1755
|
const { view, field, labels, locale, commit, note, noun } = ctx;
|
|
@@ -1589,9 +1771,9 @@ function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
|
1589
1771
|
/** @type {HTMLButtonElement | null} */
|
|
1590
1772
|
null
|
|
1591
1773
|
);
|
|
1592
|
-
const listId =
|
|
1593
|
-
const
|
|
1594
|
-
const found =
|
|
1774
|
+
const listId = useId3();
|
|
1775
|
+
const searchName = useFormName();
|
|
1776
|
+
const found = searchItems(items, query);
|
|
1595
1777
|
const matching = found.slice(0, FILTER_LIST_MAX);
|
|
1596
1778
|
const current = items.find((i) => String(i.value) === value);
|
|
1597
1779
|
const show = () => {
|
|
@@ -1643,6 +1825,7 @@ function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
|
1643
1825
|
"input",
|
|
1644
1826
|
{
|
|
1645
1827
|
type: "search",
|
|
1828
|
+
name: searchName,
|
|
1646
1829
|
role: "combobox",
|
|
1647
1830
|
className: "pk-picker-search",
|
|
1648
1831
|
value: query,
|
|
@@ -1681,26 +1864,27 @@ function ItemRule({ rule, ctx, apply, first }) {
|
|
|
1681
1864
|
const { field, labels, locale, fk, items } = ctx;
|
|
1682
1865
|
const narrow = useContext3(LayerContext).size === "narrow";
|
|
1683
1866
|
const words = fk.dates ? labels.dateOps : labels.valueOps;
|
|
1684
|
-
const ops = fk.dates ? [...
|
|
1867
|
+
const ops = fk.dates ? [...RULE_OPS.compare, "last"] : RULE_OPS.compare;
|
|
1685
1868
|
const textOf = (v) => v === void 0 ? "" : fk.item === "number" ? numberText(v, locale) : String(v);
|
|
1686
1869
|
const compared = rule?.type === "compare" ? rule : null;
|
|
1687
1870
|
const ranged = rule?.type === "relative" ? rule : null;
|
|
1688
1871
|
const [s, setS] = useState3(() => ({
|
|
1689
|
-
op: ranged ? "last" : compared
|
|
1872
|
+
op: ranged ? "last" : compared ? ruleOp(compared) : ">=",
|
|
1690
1873
|
a: textOf(compared?.value),
|
|
1691
1874
|
b: textOf(compared?.value2),
|
|
1692
1875
|
count: numberText(ranged?.count ?? 5, locale),
|
|
1693
1876
|
unit: ranged?.unit ?? "year"
|
|
1694
1877
|
}));
|
|
1695
1878
|
const later = useLater();
|
|
1879
|
+
const formName = useFormName();
|
|
1696
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);
|
|
1697
1881
|
const entryOf = (x) => {
|
|
1698
1882
|
if (x.op === "last") {
|
|
1699
|
-
const n = readNumber(x.count, { kind: "count", max:
|
|
1700
|
-
return n !== null ? { field,
|
|
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;
|
|
1701
1885
|
}
|
|
1702
1886
|
const [a, b] = [read(x.a), read(x.b)];
|
|
1703
|
-
return a === null || twin(x.op) && b === null ? null : { field, type: "compare",
|
|
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" };
|
|
1704
1888
|
};
|
|
1705
1889
|
const change = (patch, wait = false) => {
|
|
1706
1890
|
const next = { ...s, ...patch };
|
|
@@ -1734,20 +1918,20 @@ function ItemRule({ rule, ctx, apply, first }) {
|
|
|
1734
1918
|
return /* @__PURE__ */ React5.createElement(NumberField, { value: s[key], onChange: (t) => change({ [key]: t }, true), onKeyDown: keys, onBlur: later.now, problem, label: label2, testId, className: "pk-field-label pk-narrow-input" });
|
|
1735
1919
|
}
|
|
1736
1920
|
if (fk.item === "date") {
|
|
1737
|
-
return /* @__PURE__ */ React5.createElement("input", { type: "date", value: s[key], onChange: (e) => change({ [key]: e.target.value }), "aria-label": label2, "data-testid": testId });
|
|
1921
|
+
return /* @__PURE__ */ React5.createElement("input", { type: "date", name: `${formName}-${key}`, value: s[key], onChange: (e) => change({ [key]: e.target.value }), "aria-label": label2, "data-testid": testId });
|
|
1738
1922
|
}
|
|
1739
1923
|
const listed = items.filter((i) => typeof i.value === "number");
|
|
1740
1924
|
const own = s[key] !== "" && !listed.some((i) => String(i.value) === s[key]);
|
|
1741
1925
|
if (listed.length >= PICKER_MIN && !narrow) {
|
|
1742
1926
|
return /* @__PURE__ */ React5.createElement(ItemPicker, { items: own ? [{ value: Number(s[key]), label: s[key], count: 0 }, ...listed] : listed, value: s[key], onChange: (v) => change({ [key]: v }), label: label2, testId, labels, locale });
|
|
1743
1927
|
}
|
|
1744
|
-
return /* @__PURE__ */ React5.createElement("select", { value: s[key], onChange: (e) => change({ [key]: e.target.value }), "aria-label": label2, "data-testid": testId }, /* @__PURE__ */ React5.createElement("option", { value: "", disabled: true }, labels.ruleValue), own ? /* @__PURE__ */ React5.createElement("option", { value: s[key] }, s[key]) : null, listed.map((i) => /* @__PURE__ */ React5.createElement("option", { key: String(i.value), value: String(i.value) }, i.label)));
|
|
1928
|
+
return /* @__PURE__ */ React5.createElement("select", { name: `${formName}-${key}`, value: s[key], onChange: (e) => change({ [key]: e.target.value }), "aria-label": label2, "data-testid": testId }, /* @__PURE__ */ React5.createElement("option", { value: "", disabled: true }, labels.ruleValue), own ? /* @__PURE__ */ React5.createElement("option", { value: s[key] }, s[key]) : null, listed.map((i) => /* @__PURE__ */ React5.createElement("option", { key: String(i.value), value: String(i.value) }, i.label)));
|
|
1745
1929
|
};
|
|
1746
1930
|
const label = fk.item === "date" ? labels.ruleDate : labels.ruleValue;
|
|
1747
1931
|
const lang = { lang: labels.lang, locale };
|
|
1748
|
-
const counted = readNumber(s.count, { kind: "count", max:
|
|
1932
|
+
const counted = readNumber(s.count, { kind: "count", max: CATALOG3.relativeMaxCount, labels, locale });
|
|
1749
1933
|
const many = counted.value ?? 2;
|
|
1750
|
-
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", 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(
|
|
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(
|
|
1751
1935
|
NumberField,
|
|
1752
1936
|
{
|
|
1753
1937
|
value: s.count,
|
|
@@ -1759,13 +1943,14 @@ function ItemRule({ rule, ctx, apply, first }) {
|
|
|
1759
1943
|
testId: "rule-last-count",
|
|
1760
1944
|
className: "pk-field-label pk-count-input"
|
|
1761
1945
|
}
|
|
1762
|
-
), /* @__PURE__ */ React5.createElement("select", { value: s.unit, onChange: (e) => change({ unit: e.target.value }), "aria-label": labels.ruleUnit, "data-testid": "rule-last-unit" },
|
|
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));
|
|
1763
1947
|
}
|
|
1764
1948
|
function TotalRule({ rule, ctx, apply, first }) {
|
|
1765
1949
|
const { view, types, labels, locale } = ctx;
|
|
1766
1950
|
const { choices, names } = measuresOf(view, types, labels, rule?.by);
|
|
1767
|
-
const [s, setS] = useState3(() => ({ by: choiceIndex(choices, rule?.by), op: rule
|
|
1951
|
+
const [s, setS] = useState3(() => ({ by: choiceIndex(choices, rule?.by), op: rule ? ruleOp(rule) : ">", a: numberText(rule?.value, locale), b: numberText(rule?.value2, locale) }));
|
|
1768
1952
|
const later = useLater();
|
|
1953
|
+
const formName = useFormName();
|
|
1769
1954
|
const change = (patch, wait = false) => {
|
|
1770
1955
|
const next = { ...s, ...patch };
|
|
1771
1956
|
setS(next);
|
|
@@ -1773,7 +1958,7 @@ function TotalRule({ rule, ctx, apply, first }) {
|
|
|
1773
1958
|
const [a, b] = [parseNumber(next.a, locale), parseNumber(next.b, locale)];
|
|
1774
1959
|
if (a !== null && (!twin(next.op) || b !== null)) {
|
|
1775
1960
|
const by = choices[next.by];
|
|
1776
|
-
apply({ field: ctx.field, type: "value", by: { field: by.field, agg: by.agg },
|
|
1961
|
+
apply({ field: ctx.field, type: "value", by: { field: by.field, agg: by.agg }, ...opOf(next.op), value: a, ...twin(next.op) ? { value2: b } : {} });
|
|
1777
1962
|
}
|
|
1778
1963
|
};
|
|
1779
1964
|
if (wait) {
|
|
@@ -1794,21 +1979,23 @@ function TotalRule({ rule, ctx, apply, first }) {
|
|
|
1794
1979
|
};
|
|
1795
1980
|
const keys = fieldKeys({ now: later.now, restore, back: ctx.back });
|
|
1796
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" });
|
|
1797
|
-
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", value: s.op, onChange: (e) => change({ op: e.target.value }), "aria-label": labels.valueFilterOp, "data-autofocus": first ? "" : void 0, "data-testid": "value-filter-op" },
|
|
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);
|
|
1798
1983
|
}
|
|
1799
1984
|
function NameRule({ rule, ctx, apply, first }) {
|
|
1800
1985
|
const { field, labels } = ctx;
|
|
1801
|
-
const [op, setOp] = useState3(rule
|
|
1986
|
+
const [op, setOp] = useState3(rule ? ruleOp(rule) : "contains");
|
|
1802
1987
|
const send = (o, value) => {
|
|
1803
1988
|
if (value !== "") {
|
|
1804
|
-
apply({ field,
|
|
1989
|
+
apply({ ...textRule(field, { op: o, value, on: ctx.textOn }), ...rule ? { blanks: rule.blanks } : {} });
|
|
1805
1990
|
}
|
|
1806
1991
|
};
|
|
1807
1992
|
const text = useAppliedText(rule?.value ?? "", (value) => send(op, value));
|
|
1993
|
+
const opName = useFormName();
|
|
1808
1994
|
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("span", { className: "pk-rule-subject" }, labels.ruleName), /* @__PURE__ */ React5.createElement(
|
|
1809
1995
|
"select",
|
|
1810
1996
|
{
|
|
1811
1997
|
className: "pk-rule-op",
|
|
1998
|
+
name: opName,
|
|
1812
1999
|
value: op,
|
|
1813
2000
|
onChange: (e) => {
|
|
1814
2001
|
setOp(e.target.value);
|
|
@@ -1818,7 +2005,7 @@ function NameRule({ rule, ctx, apply, first }) {
|
|
|
1818
2005
|
"data-autofocus": first ? "" : void 0,
|
|
1819
2006
|
"data-testid": "filter-condition-op"
|
|
1820
2007
|
},
|
|
1821
|
-
|
|
2008
|
+
RULE_OPS.text.map((o) => /* @__PURE__ */ React5.createElement("option", { key: o, value: o }, labels.labelOps[o] ?? o))
|
|
1822
2009
|
), /* @__PURE__ */ React5.createElement(
|
|
1823
2010
|
ClearInput,
|
|
1824
2011
|
{
|
|
@@ -1831,13 +2018,16 @@ function NameRule({ rule, ctx, apply, first }) {
|
|
|
1831
2018
|
clearLabel: labels.clearText,
|
|
1832
2019
|
"aria-label": labels.conditionValue,
|
|
1833
2020
|
placeholder: labels.conditionValue,
|
|
1834
|
-
maxLength:
|
|
2021
|
+
maxLength: LIMITS2.textValue,
|
|
1835
2022
|
"data-testid": "filter-condition-text"
|
|
1836
2023
|
}
|
|
1837
2024
|
));
|
|
1838
2025
|
}
|
|
1839
|
-
|
|
1840
|
-
|
|
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 }) {
|
|
1841
2031
|
const { view, field, labels, locale, commit, note, fk, nameKind, noun } = ctx;
|
|
1842
2032
|
const { explain } = useContext3(HelpContext);
|
|
1843
2033
|
const lang = { lang: labels.lang, locale };
|
|
@@ -1845,6 +2035,7 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results }) {
|
|
|
1845
2035
|
/** @type {"item" | "total" | "name" | null} */
|
|
1846
2036
|
null
|
|
1847
2037
|
);
|
|
2038
|
+
const blanksName = useFormName();
|
|
1848
2039
|
const [info, setInfo] = useState3(
|
|
1849
2040
|
/** @type {number | null} */
|
|
1850
2041
|
null
|
|
@@ -1896,7 +2087,7 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results }) {
|
|
|
1896
2087
|
["item", "total", "name"].filter((k) => k === "item" ? Boolean(fk.item) : k === "name" ? Boolean(nameKind) : true)
|
|
1897
2088
|
);
|
|
1898
2089
|
const count = rules.length + (draft ? 1 : 0);
|
|
1899
|
-
const full = count >= RULES_MAX || view.filters.length >=
|
|
2090
|
+
const full = count >= RULES_MAX || view.filters.length >= LIMITS2.filters;
|
|
1900
2091
|
const addText = { item: fill(labels.addRuleItem, { field: fieldLabel3(field, labels.core) }), total: labels.addRuleTotal, name: labels.addRuleName };
|
|
1901
2092
|
const infoText = (rule, kind) => {
|
|
1902
2093
|
const one = plural(noun, 1, lang);
|
|
@@ -1912,7 +2103,8 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results }) {
|
|
|
1912
2103
|
const row = (rule, kind, i) => {
|
|
1913
2104
|
const Row = ROWS[kind];
|
|
1914
2105
|
const apply = (entry) => {
|
|
1915
|
-
const
|
|
2106
|
+
const own2 = !rule && ctx.keepBlanks && ITEM_RULE_TYPES.includes(entry.type) ? { ...entry, blanks: "include" } : entry;
|
|
2107
|
+
const next = setRule(view, field, rule, own2);
|
|
1916
2108
|
setOwn(rulesKeyOf(filtersOf(next, field, RULE_TYPES).filter((f) => !ctx.quickFilters.includes(f))));
|
|
1917
2109
|
if (!rule) {
|
|
1918
2110
|
setDraft(null);
|
|
@@ -1933,7 +2125,7 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results }) {
|
|
|
1933
2125
|
const infoId = `${gen}-${i}`;
|
|
1934
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);
|
|
1935
2127
|
};
|
|
1936
|
-
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(
|
|
1937
2129
|
"button",
|
|
1938
2130
|
{
|
|
1939
2131
|
key: k,
|
|
@@ -1960,13 +2152,11 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
1960
2152
|
const years = useMemo2(() => fk.cyclic && column && counts ? yearsOf(column, counts) : [], [fk.cyclic, column, counts]);
|
|
1961
2153
|
const quick = quickChoice(view, field, fk, years.map((y) => y.year));
|
|
1962
2154
|
const [anchorLocal, setAnchorLocal] = useState3(
|
|
1963
|
-
/** @type {
|
|
2155
|
+
/** @type {string | null} */
|
|
1964
2156
|
null
|
|
1965
2157
|
);
|
|
1966
|
-
const anchor =
|
|
1967
|
-
|
|
1968
|
-
quick.anchor ?? anchorLocal ?? "today"
|
|
1969
|
-
);
|
|
2158
|
+
const anchor = quick.anchor ?? anchorLocal ?? "today";
|
|
2159
|
+
const [moreOpen, setMoreOpen] = useState3(() => inMore(quick));
|
|
1970
2160
|
const [openQuick, setOpenQuick] = useState3(true);
|
|
1971
2161
|
const [openPicks, setOpenPicks] = useState3(
|
|
1972
2162
|
/** @type {boolean | null} */
|
|
@@ -2017,7 +2207,7 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2017
2207
|
if (goQuick) {
|
|
2018
2208
|
const target = (
|
|
2019
2209
|
/** @type {HTMLElement | null | undefined} */
|
|
2020
|
-
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)')
|
|
2021
2211
|
);
|
|
2022
2212
|
target?.scrollIntoView?.({ block: "center" });
|
|
2023
2213
|
target?.focus({ preventScroll: true });
|
|
@@ -2062,13 +2252,13 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2062
2252
|
const all = info.items.map((i) => i.value);
|
|
2063
2253
|
const picked = selectedItems(view, field, all);
|
|
2064
2254
|
const selected = new Set(picked.map(keyOf));
|
|
2065
|
-
const nameKind = conditionKind(encoded, view, field) ?? (rules.some((r) => r.type === "
|
|
2255
|
+
const nameKind = conditionKind(encoded, view, field) ?? (rules.some((r) => r.type === "text") ? "text" : null);
|
|
2066
2256
|
const labelOf = (v) => info.items.find((i) => i.value === v)?.label;
|
|
2067
2257
|
const say = (f) => ruleText(view, f, { labels, locale, timeZone, date: fk.dates, labelOf, span });
|
|
2068
2258
|
const number = (n) => n.toLocaleString(locale);
|
|
2069
2259
|
const yearsOn = quick.id === "yearsCombined" && quick.years ? quick.years : years.map((y) => y.year);
|
|
2070
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;
|
|
2071
|
-
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;
|
|
2072
2262
|
const outByQuick = (
|
|
2073
2263
|
/** @type {Set<string> | undefined} */
|
|
2074
2264
|
itemResults.get("quick") ?? (quick.filters.length ? new Set(info.items.filter((i) => !i.kept).map((i) => keyOf(i.value))) : /* @__PURE__ */ new Set())
|
|
@@ -2092,7 +2282,7 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2092
2282
|
};
|
|
2093
2283
|
const totalWords = (r) => {
|
|
2094
2284
|
const measure = refLabel(view, r.by, labels);
|
|
2095
|
-
const op = labels.valueOps[r
|
|
2285
|
+
const op = labels.valueOps[ruleOp(r)] ?? ruleOp(r);
|
|
2096
2286
|
const num = (x) => typeof x === "number" ? x.toLocaleString(locale, { maximumFractionDigits: 6 }) : "";
|
|
2097
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) });
|
|
2098
2288
|
};
|
|
@@ -2129,6 +2319,9 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2129
2319
|
const scope = scopeParts.length ? scopeParts.join(labels.listAnd) : labels.scopeRows;
|
|
2130
2320
|
const focusQuick = () => {
|
|
2131
2321
|
setOpenQuick(true);
|
|
2322
|
+
if (inMore(quick)) {
|
|
2323
|
+
setMoreOpen(true);
|
|
2324
|
+
}
|
|
2132
2325
|
setGoQuick((n) => n + 1);
|
|
2133
2326
|
};
|
|
2134
2327
|
const act = (next, header) => {
|
|
@@ -2140,7 +2333,10 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2140
2333
|
}
|
|
2141
2334
|
});
|
|
2142
2335
|
};
|
|
2143
|
-
const
|
|
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;
|
|
2144
2340
|
const picksOpen = openPicks ?? !anyRule;
|
|
2145
2341
|
const rulesOpen = openRules ?? anyRule;
|
|
2146
2342
|
const togglePicks = () => {
|
|
@@ -2159,7 +2355,7 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2159
2355
|
};
|
|
2160
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 };
|
|
2161
2357
|
const outOf = (i) => i.kept === false;
|
|
2162
|
-
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;
|
|
2163
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(
|
|
2164
2360
|
Section2,
|
|
2165
2361
|
{
|
|
@@ -2192,13 +2388,15 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2192
2388
|
onToggle: toggleRules,
|
|
2193
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)
|
|
2194
2390
|
},
|
|
2195
|
-
/* @__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 })
|
|
2196
2392
|
));
|
|
2197
2393
|
}
|
|
2198
2394
|
|
|
2199
2395
|
// src/chip-menus.jsx
|
|
2200
|
-
function TopLevel({ view, field, types, labels, locale, commit, back }) {
|
|
2396
|
+
function TopLevel({ view, field, types, labels, locale, commit, back, encoded }) {
|
|
2201
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]);
|
|
2202
2400
|
const { choices, names } = measuresOf(view, types, labels, top?.by);
|
|
2203
2401
|
const [by, setBy] = useState4(() => choiceIndex(choices, top?.by));
|
|
2204
2402
|
const quick = top && !top.bottom && TOP_COUNTS.includes(top.count) ? top.count : null;
|
|
@@ -2216,8 +2414,9 @@ function TopLevel({ view, field, types, labels, locale, commit, back }) {
|
|
|
2216
2414
|
set({ count: n, bottom: s.bottom, by: choices[s.by] });
|
|
2217
2415
|
}
|
|
2218
2416
|
};
|
|
2219
|
-
const groupName =
|
|
2220
|
-
const
|
|
2417
|
+
const groupName = useFormName();
|
|
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));
|
|
2221
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, () => {
|
|
2222
2421
|
setOwn(false);
|
|
2223
2422
|
set(null);
|
|
@@ -2272,7 +2471,16 @@ function TopLevel({ view, field, types, labels, locale, commit, back }) {
|
|
|
2272
2471
|
if (top) {
|
|
2273
2472
|
set({ count: top.count, bottom: Boolean(top.bottom), by: choices[i] });
|
|
2274
2473
|
}
|
|
2275
|
-
}, 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);
|
|
2276
2484
|
}
|
|
2277
2485
|
function BinsLevel({ view, field, labels, locale, range, regroup, back }) {
|
|
2278
2486
|
const grouping = groupingOf(view, field);
|
|
@@ -2280,7 +2488,7 @@ function BinsLevel({ view, field, labels, locale, range, regroup, back }) {
|
|
|
2280
2488
|
const [size, setSize] = useState4(numberText(bins?.size, locale));
|
|
2281
2489
|
const [start, setStart] = useState4(numberText(bins?.origin, locale));
|
|
2282
2490
|
const [tried, setTried] = useState4(false);
|
|
2283
|
-
const problemId =
|
|
2491
|
+
const problemId = useId4();
|
|
2284
2492
|
const sized = readNumber(size, { kind: "size", tried, labels, locale });
|
|
2285
2493
|
const started = readNumber(start, { required: false, labels, locale });
|
|
2286
2494
|
const n = sized.value;
|
|
@@ -2387,7 +2595,7 @@ function AxisMenu({ view, zone, index, field, types, labels, commit, close, onRe
|
|
|
2387
2595
|
const grouped = unit ? groupingName(sourceName, unit, labels, size) : null;
|
|
2388
2596
|
commit(groupField(view, field, unit, { size, origin, name: grouped ?? void 0 }).view, { step: "group", field: sourceName });
|
|
2389
2597
|
};
|
|
2390
|
-
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;
|
|
2391
2599
|
const name = fieldLabel4(field, labels.core);
|
|
2392
2600
|
return /* @__PURE__ */ React6.createElement(
|
|
2393
2601
|
LevelMenu,
|
|
@@ -2445,7 +2653,7 @@ function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaul
|
|
|
2445
2653
|
}
|
|
2446
2654
|
|
|
2447
2655
|
// src/toolbar-panels.jsx
|
|
2448
|
-
import React7, { useEffect as useEffect3, useId as
|
|
2656
|
+
import React7, { useEffect as useEffect3, useId as useId5, useRef as useRef3, useState as useState5 } from "react";
|
|
2449
2657
|
import { VIEW_FILE_LIMITS } from "pivotkit-core";
|
|
2450
2658
|
|
|
2451
2659
|
// src/share-actions.js
|
|
@@ -2530,12 +2738,12 @@ async function copyText(text, container) {
|
|
|
2530
2738
|
}
|
|
2531
2739
|
|
|
2532
2740
|
// src/version.js
|
|
2533
|
-
var VERSION = true ? "0.
|
|
2741
|
+
var VERSION = true ? "0.5.0" : "0.0.0-source";
|
|
2534
2742
|
|
|
2535
2743
|
// src/share-actions.js
|
|
2536
2744
|
var here = () => typeof location !== "undefined" ? location.href : void 0;
|
|
2537
2745
|
function shareActions(ctx, labels) {
|
|
2538
|
-
const { view, viewName, sourceId, sourceName, schemaUrl, encoded, announce, limits,
|
|
2746
|
+
const { view, viewName, sourceId, sourceName, schemaUrl, encoded, announce, limits, linkKey } = ctx;
|
|
2539
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 } : {} }));
|
|
2540
2748
|
return {
|
|
2541
2749
|
copyLink: async () => {
|
|
@@ -2551,7 +2759,7 @@ function shareActions(ctx, labels) {
|
|
|
2551
2759
|
e.code === "LIMIT_EXCEEDED" ? labels.toastLinkTooLong : fill(labels.error, { message: String(e) }), { tone: "error" });
|
|
2552
2760
|
return;
|
|
2553
2761
|
}
|
|
2554
|
-
const ok = await copyText(withLinkParam(target,
|
|
2762
|
+
const ok = await copyText(withLinkParam(target, linkKey, text), ctx.root.current);
|
|
2555
2763
|
announce(ok ? labels.toastLinkCopied : labels.toastCopyFailed, ok ? void 0 : { tone: "error" });
|
|
2556
2764
|
},
|
|
2557
2765
|
copyJson: async () => {
|
|
@@ -2576,7 +2784,7 @@ function shareActions(ctx, labels) {
|
|
|
2576
2784
|
let loaded = viewFromText(text, encoded, { limits, sourceId });
|
|
2577
2785
|
if (loaded.failed === "notJson") {
|
|
2578
2786
|
const t = text.trim();
|
|
2579
|
-
const fromUrl = t.includes("#") ? readLinkParam(t.slice(t.indexOf("#")),
|
|
2787
|
+
const fromUrl = t.includes("#") ? readLinkParam(t.slice(t.indexOf("#")), linkKey) ?? readLinkParam(t.slice(t.indexOf("#")), void 0) : null;
|
|
2580
2788
|
const payload = fromUrl ?? (t.startsWith("1.") ? t : null);
|
|
2581
2789
|
if (!payload) {
|
|
2582
2790
|
return labels.viewFailed.notJson;
|
|
@@ -2771,6 +2979,10 @@ function ChartTitle({ title, labels, onDisplay }) {
|
|
|
2771
2979
|
/* @__PURE__ */ React7.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: (text.trim() || null) === (title ?? null) }, labels.apply)
|
|
2772
2980
|
);
|
|
2773
2981
|
}
|
|
2982
|
+
function Sub({ title, info, children }) {
|
|
2983
|
+
const titleId = useId5();
|
|
2984
|
+
return /* @__PURE__ */ React7.createElement("div", { className: "pk-subsection", role: title ? "group" : void 0, "aria-labelledby": title ? titleId : void 0 }, title ? /* @__PURE__ */ React7.createElement("div", { className: `pk-subtitle${info ? " pk-setting-row" : ""}` }, /* @__PURE__ */ React7.createElement("span", { id: titleId }, title), info ? /* @__PURE__ */ React7.createElement(SettingInfo, { id: info, name: title }) : null) : null, children);
|
|
2985
|
+
}
|
|
2774
2986
|
function ChartDisplay({ view, plan, labels, onDisplay }) {
|
|
2775
2987
|
const chart = view.chart;
|
|
2776
2988
|
const drawn = plan ? plan.name : chartTypeOf(chart);
|
|
@@ -2778,7 +2990,7 @@ function ChartDisplay({ view, plan, labels, onDisplay }) {
|
|
|
2778
2990
|
const axis = CHART_TYPES[drawn].axis;
|
|
2779
2991
|
const choices = pie ? VALUE_LABELS.slices : VALUE_LABELS.other;
|
|
2780
2992
|
const valueLabels = !pie && (chart.valueLabels === "percent" || chart.valueLabels === "both") ? "value" : chart.valueLabels;
|
|
2781
|
-
return /* @__PURE__ */ React7.createElement(Section, { title: labels.chartDisplay }, /* @__PURE__ */ React7.createElement(
|
|
2993
|
+
return /* @__PURE__ */ React7.createElement(Section, { title: labels.chartDisplay }, /* @__PURE__ */ React7.createElement(Sub, { title: labels.valueLabels }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, choices.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: valueLabels === v, onSelect: () => onDisplay({ valueLabels: v }), testId: `labels-${v}` }, labels.valueLabelNames[v])))), pie ? /* @__PURE__ */ React7.createElement(Sub, { title: labels.labelPosition, info: "labelPosition" }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, LABEL_POSITIONS.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: (chart.labelPosition ?? "outside") === v, disabled: chart.valueLabels === "off", onSelect: () => onDisplay({ labelPosition: v }), testId: `label-position-${v}` }, labels.labelPositionNames[v])))) : null, /* @__PURE__ */ React7.createElement(Sub, { title: labels.legend }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, LEGENDS.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: chart.legend === v, onSelect: () => onDisplay({ legend: v }), testId: `legend-${v}` }, labels.legendNames[v])))), /* @__PURE__ */ React7.createElement(Sub, { title: labels.chartTitle }, /* @__PURE__ */ React7.createElement(ChartTitle, { title: chart.title, labels, onDisplay })), axis ? /* @__PURE__ */ React7.createElement(Sub, { title: labels.axisLabels }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, AXIS_LABELS.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: chart.axisLabels === v, onSelect: () => onDisplay({ axisLabels: v }), testId: `axis-${v}` }, labels.axisLabelNames[v])))) : null, axis && view.rows.length >= 2 ? /* @__PURE__ */ React7.createElement(Sub, { title: labels.groupLabels, info: "groupLabels" }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, GROUP_LABELS.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: chart.groupLabels === v, onSelect: () => onDisplay({ groupLabels: v }), testId: `groups-${v}` }, labels.groupLabelNames[v])))) : null, drawn === "line" || drawn === "area" ? /* @__PURE__ */ React7.createElement(Sub, null, /* @__PURE__ */ React7.createElement(Switch, { checked: chart.smooth, onChange: (on) => onDisplay({ smooth: on }), testId: "chart-smooth" }, labels.smoothLines)) : null);
|
|
2782
2994
|
}
|
|
2783
2995
|
function ChartTypePanel({ view, plan, labels, onChart, onDisplay, close }) {
|
|
2784
2996
|
return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(Section, { title: labels.chartType }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React7.createElement(ChartTypeOptions, { view, plan, labels, onChart, close }))), /* @__PURE__ */ React7.createElement(ChartDisplay, { view, plan, labels, onDisplay }));
|
|
@@ -2788,7 +3000,8 @@ function Shortcuts({ labels, mod }) {
|
|
|
2788
3000
|
return /* @__PURE__ */ React7.createElement("dl", { className: "pk-shortcuts", "data-testid": "shortcuts" }, SHORTCUTS.map((s) => /* @__PURE__ */ React7.createElement("div", { key: s.text, className: "pk-shortcut" }, /* @__PURE__ */ React7.createElement("dt", null, s.keys.map((k, i) => /* @__PURE__ */ React7.createElement(React7.Fragment, { key: k }, i ? " + " : null, /* @__PURE__ */ React7.createElement("kbd", null, key(k))))), /* @__PURE__ */ React7.createElement("dd", null, labels.shortcuts[s.text]))));
|
|
2789
3001
|
}
|
|
2790
3002
|
function Switch({ checked, onChange, testId, children }) {
|
|
2791
|
-
|
|
3003
|
+
const name = useFormName();
|
|
3004
|
+
return /* @__PURE__ */ React7.createElement("label", { className: "pk-switch" }, /* @__PURE__ */ React7.createElement("input", { type: "checkbox", name, checked, onChange: (e) => onChange(e.target.checked), "data-testid": testId }), /* @__PURE__ */ React7.createElement("span", { className: "pk-switch-track", "aria-hidden": "true" }), /* @__PURE__ */ React7.createElement("span", { className: "pk-switch-text" }, children));
|
|
2792
3005
|
}
|
|
2793
3006
|
function OptionsPanel({ view, labels, onTotal, onExpand, onCollapse, close, tips, mod, folding, help }) {
|
|
2794
3007
|
const topics = optionTopics({
|
|
@@ -2885,7 +3098,7 @@ function SaveView({ labels, button, onSave, resolve, close }) {
|
|
|
2885
3098
|
);
|
|
2886
3099
|
}
|
|
2887
3100
|
function LoadCheck({ check, labels, onCancel, close, title, quiet = false }) {
|
|
2888
|
-
const titleId =
|
|
3101
|
+
const titleId = useId5();
|
|
2889
3102
|
const first = useRef3(
|
|
2890
3103
|
/** @type {HTMLButtonElement | null} */
|
|
2891
3104
|
null
|
|
@@ -2922,7 +3135,8 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
2922
3135
|
/** @type {HTMLTextAreaElement | null} */
|
|
2923
3136
|
null
|
|
2924
3137
|
);
|
|
2925
|
-
const problemId =
|
|
3138
|
+
const problemId = useId5();
|
|
3139
|
+
const fileName = useFormName();
|
|
2926
3140
|
useEffect3(() => {
|
|
2927
3141
|
if (!check) {
|
|
2928
3142
|
field.current?.focus({ preventScroll: true });
|
|
@@ -2979,10 +3193,12 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
2979
3193
|
{
|
|
2980
3194
|
ref: file,
|
|
2981
3195
|
type: "file",
|
|
3196
|
+
name: `${fileName}-file`,
|
|
2982
3197
|
accept: "application/json,.json",
|
|
2983
3198
|
className: "pk-sr",
|
|
2984
3199
|
tabIndex: -1,
|
|
2985
3200
|
"aria-hidden": "true",
|
|
3201
|
+
"aria-label": labels.chooseFile,
|
|
2986
3202
|
"data-testid": "load-view-file",
|
|
2987
3203
|
onChange: async (e) => {
|
|
2988
3204
|
const chosen = e.target.files?.[0];
|
|
@@ -3089,11 +3305,13 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
3089
3305
|
if (canSaveAs(can)) {
|
|
3090
3306
|
thisView.push({ id: "save-as", text: actions.loaded ? labels.saveAs : `${labels.saveView}\u2026`, icon: "save", open: "saveAs" });
|
|
3091
3307
|
}
|
|
3092
|
-
thisView.push({ id: "new-report", text: labels.newEmpty, icon: "newFile", disabled: !actions.canNew, reason: actions.canNew ? void 0 : labels.newAlready, info: "newReport", closes: true, run: () => actions.onNew() });
|
|
3093
3308
|
const act = share ? shareActions(share, labels) : null;
|
|
3094
3309
|
const question = asking?.kind === "replaceShared" ? { text: fill(labels.replaceSharedConfirm, { name: actions.loaded?.name }), action: labels.replaceAction, testId: "replace-shared-confirm", yesId: "confirm-replace-shared", noId: "cancel-replace-shared" } : asking ? { text: fill(asking.kind === "publish" ? labels.publishConfirm : labels.deleteConfirm, { name: asking.t.name }), action: asking.kind === "publish" ? labels.publishAction : labels.deleteAction, testId: `${asking.kind}-confirm`, yesId: `confirm-${asking.kind}`, noId: `cancel-${asking.kind}` } : null;
|
|
3095
3310
|
const topics = [
|
|
3096
|
-
{ id: "thisView", title: labels.thisView, kind:
|
|
3311
|
+
...thisView.length ? [{ id: "thisView", title: labels.thisView, kind: (
|
|
3312
|
+
/** @type {const} */
|
|
3313
|
+
"inline"
|
|
3314
|
+
), titled: true, groups: [{ choices: thisView }] }] : [],
|
|
3097
3315
|
...shared.length ? [{ id: "sharedViews", title: labels.sharedViews, kind: (
|
|
3098
3316
|
/** @type {const} */
|
|
3099
3317
|
"inline"
|
|
@@ -3116,14 +3334,12 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
3116
3334
|
...act ? [
|
|
3117
3335
|
{
|
|
3118
3336
|
id: "share",
|
|
3119
|
-
title: labels.
|
|
3120
|
-
// under a heading of its own, like the lists before it
|
|
3121
|
-
heading: labels.shareThisView,
|
|
3337
|
+
title: labels.shareThisView,
|
|
3122
3338
|
kind: (
|
|
3123
3339
|
/** @type {const} */
|
|
3124
|
-
"
|
|
3340
|
+
"inline"
|
|
3125
3341
|
),
|
|
3126
|
-
|
|
3342
|
+
titled: true,
|
|
3127
3343
|
groups: [
|
|
3128
3344
|
{
|
|
3129
3345
|
choices: [
|
|
@@ -3200,14 +3416,140 @@ function ExportPanel({ labels, onExport, chartReady, display, empty = false, pre
|
|
|
3200
3416
|
onExport(kind);
|
|
3201
3417
|
};
|
|
3202
3418
|
const off = empty ? { disabled: true, reason: labels.exportNeedsField } : {};
|
|
3203
|
-
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" })));
|
|
3204
3420
|
}
|
|
3205
3421
|
|
|
3206
3422
|
// src/drill-panel.jsx
|
|
3207
|
-
import React8, { useContext as useContext4, useEffect as useEffect4, useId as
|
|
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
|
+
}
|
|
3208
3551
|
|
|
3209
3552
|
// src/export-run.js
|
|
3210
|
-
import { toGrid } from "pivotkit-core";
|
|
3211
3553
|
var XLSX_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
3212
3554
|
var exporters = null;
|
|
3213
3555
|
var pending = null;
|
|
@@ -3224,6 +3566,14 @@ function loadExporters() {
|
|
|
3224
3566
|
);
|
|
3225
3567
|
return pending;
|
|
3226
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
|
+
}
|
|
3227
3577
|
var exportersNow = () => exporters;
|
|
3228
3578
|
var prepareExporters = () => void loadExporters().catch(() => void 0);
|
|
3229
3579
|
function deliver(blob, { doc, onExport, ...file }) {
|
|
@@ -3239,7 +3589,42 @@ async function copyOut(text, { type, container, onExport, ...file }) {
|
|
|
3239
3589
|
}
|
|
3240
3590
|
return await copyText(text, container) ? "copied" : "blocked";
|
|
3241
3591
|
}
|
|
3242
|
-
|
|
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 }) {
|
|
3243
3628
|
labels = menuLabels(labels);
|
|
3244
3629
|
const base = safeFileName(fileName);
|
|
3245
3630
|
const doc = root.current?.ownerDocument;
|
|
@@ -3256,6 +3641,50 @@ async function runExport(kind, { fileName, result, locale, labels, limits, root,
|
|
|
3256
3641
|
if (!result) {
|
|
3257
3642
|
return;
|
|
3258
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
|
+
}
|
|
3259
3688
|
const m = exporters ?? await loadExporters();
|
|
3260
3689
|
const grid = toGrid(result, { locale, labels: labels.core, limits });
|
|
3261
3690
|
if (kind === "copy-table" || kind === "copy-json") {
|
|
@@ -3267,7 +3696,7 @@ async function runExport(kind, { fileName, result, locale, labels, limits, root,
|
|
|
3267
3696
|
return;
|
|
3268
3697
|
}
|
|
3269
3698
|
const file = `${base}.${kind}`;
|
|
3270
|
-
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 });
|
|
3271
3700
|
if (deliver(new Blob([
|
|
3272
3701
|
/** @type {BlobPart} */
|
|
3273
3702
|
bytes
|
|
@@ -3278,6 +3707,7 @@ async function runExport(kind, { fileName, result, locale, labels, limits, root,
|
|
|
3278
3707
|
announce(fill(labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
|
|
3279
3708
|
}
|
|
3280
3709
|
}
|
|
3710
|
+
var clampSize = (px) => Math.max(100, Math.min(8e3, Math.round(Number(px) || 0)));
|
|
3281
3711
|
|
|
3282
3712
|
// src/drill-export.js
|
|
3283
3713
|
function rowsText({ shown, count }, labels, locale) {
|
|
@@ -3374,8 +3804,8 @@ function drillOf({ result, rowPath, colPath, count, indices, formatOf, nameOf, i
|
|
|
3374
3804
|
|
|
3375
3805
|
// src/drill-panel.jsx
|
|
3376
3806
|
function DrillPanel({ drill: source, onClose, labels, locale, exportContext }) {
|
|
3377
|
-
const id =
|
|
3378
|
-
const drill =
|
|
3807
|
+
const id = useId6();
|
|
3808
|
+
const drill = useMemo4(() => source ? drillOf(source, labels) : null, [source, labels]);
|
|
3379
3809
|
const panel = useRef4(
|
|
3380
3810
|
/** @type {HTMLDivElement | null} */
|
|
3381
3811
|
null
|
|
@@ -3420,9 +3850,48 @@ function DrillPanel({ drill: source, onClose, labels, locale, exportContext }) {
|
|
|
3420
3850
|
/* @__PURE__ */ React8.createElement("div", { className: "pk-drill-body", tabIndex: 0, "aria-label": drill.title }, /* @__PURE__ */ React8.createElement("table", { className: "pk-drill-table" }, /* @__PURE__ */ React8.createElement("thead", null, /* @__PURE__ */ React8.createElement("tr", null, drill.columns.map((c) => /* @__PURE__ */ React8.createElement("th", { key: c.name, scope: "col", className: c.numeric ? "pk-num" : void 0, title: c.description, "aria-description": c.description }, c.label ?? c.name)))), /* @__PURE__ */ React8.createElement("tbody", null, drill.rows.map((row, i) => /* @__PURE__ */ React8.createElement("tr", { key: i }, drill.columns.map((c, k) => /* @__PURE__ */ React8.createElement("td", { key: c.name, className: c.numeric ? "pk-num" : void 0 }, c.numeric || row[k].length < 24 ? row[k] : /* @__PURE__ */ React8.createElement("div", { className: "pk-drill-text" }, row[k]))))))))
|
|
3421
3851
|
));
|
|
3422
3852
|
}
|
|
3853
|
+
|
|
3854
|
+
// src/data-menu.jsx
|
|
3855
|
+
import React9, { useEffect as useEffect5, useRef as useRef5, useState as useState7 } from "react";
|
|
3856
|
+
function DataMenu({ api, close, labels }) {
|
|
3857
|
+
const mod = importNow();
|
|
3858
|
+
const [failed, setFailed] = useState7(false);
|
|
3859
|
+
const [attempt, setAttempt] = useState7(0);
|
|
3860
|
+
const box = useRef5(
|
|
3861
|
+
/** @type {HTMLDivElement | null} */
|
|
3862
|
+
null
|
|
3863
|
+
);
|
|
3864
|
+
const [late] = useState7(() => !mod);
|
|
3865
|
+
const load = useRef5(api.load);
|
|
3866
|
+
useEffect5(() => {
|
|
3867
|
+
load.current = api.load;
|
|
3868
|
+
});
|
|
3869
|
+
useEffect5(() => {
|
|
3870
|
+
if (mod) {
|
|
3871
|
+
return void 0;
|
|
3872
|
+
}
|
|
3873
|
+
let live = true;
|
|
3874
|
+
load.current().catch(() => live && setFailed(true));
|
|
3875
|
+
return () => {
|
|
3876
|
+
live = false;
|
|
3877
|
+
};
|
|
3878
|
+
}, [mod, attempt]);
|
|
3879
|
+
useEffect5(() => {
|
|
3880
|
+
const popover = box.current?.closest(".pk-popover");
|
|
3881
|
+
const now = activeIn(popover);
|
|
3882
|
+
if (late && popover && (now === popover || !now || !popover.contains(now))) {
|
|
3883
|
+
popover.querySelector("[data-pk-option], [data-autofocus]")?.focus({ preventScroll: true });
|
|
3884
|
+
}
|
|
3885
|
+
}, [late, mod, failed]);
|
|
3886
|
+
return /* @__PURE__ */ React9.createElement("div", { ref: box }, mod ? /* @__PURE__ */ React9.createElement(mod.DataMenuPanel, { api, close }) : failed ? /* @__PURE__ */ React9.createElement("div", { className: "pk-menu-failed", role: "alert", "data-testid": "menu-failed" }, /* @__PURE__ */ React9.createElement("p", null, labels.menuFailed), /* @__PURE__ */ React9.createElement("button", { type: "button", className: "pk-btn pk-small-btn", "data-autofocus": "", onClick: () => {
|
|
3887
|
+
setFailed(false);
|
|
3888
|
+
setAttempt((n) => n + 1);
|
|
3889
|
+
} }, labels.tryAgain)) : /* @__PURE__ */ React9.createElement("p", { className: "pk-hint pk-menu-loading", role: "status" }, labels.loadingMenu));
|
|
3890
|
+
}
|
|
3423
3891
|
export {
|
|
3424
3892
|
AxisMenu,
|
|
3425
3893
|
ChartTypePanel,
|
|
3894
|
+
DataMenu,
|
|
3426
3895
|
DrillPanel,
|
|
3427
3896
|
ExportPanel,
|
|
3428
3897
|
FilterMenu,
|