pivotkit-react 0.5.0 → 0.6.1
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 +118 -2
- package/README.md +4 -1
- package/dist/chunks/{chunk-2AT72SLA.js → chunk-3LDE2GPG.js} +58 -34
- package/dist/chunks/{chunk-RIOSIYGC.js → chunk-JOWAEZAD.js} +6 -4
- package/dist/chunks/{chunk-U5Q5I2D5.js → chunk-TR2HROIK.js} +10 -3
- package/dist/chunks/chunk-W2KIPREL.js +36 -0
- package/dist/chunks/{chunk-3WUGQPWV.js → chunk-XN5HNKJ2.js} +10 -95
- package/dist/chunks/{chunk-4RS72AAA.js → chunk-YXLANLGL.js} +8 -2
- package/dist/chunks/{chunk-3E4NB5RZ.js → chunk-ZK5RVCHP.js} +21 -3
- package/dist/import-ui.js +68 -174
- package/dist/index.js +75 -28
- package/dist/labels.js +4 -4
- package/dist/menu-texts-de.js +1 -1
- package/dist/menus.js +338 -82
- package/dist/styles.css +1 -1
- package/package.json +3 -3
- package/types/drill-export.d.ts +3 -2
- package/types/drill-panel.d.ts +4 -2
- package/types/export-run.d.ts +8 -3
- package/types/export-scope.d.ts +47 -0
- package/types/field-info.d.ts +3 -10
- package/types/import-host.d.ts +37 -8
- package/types/import-labels.d.ts +20 -3
- package/types/import-module.d.ts +1 -1
- package/types/import-run.d.ts +0 -8
- package/types/import-steps.d.ts +8 -0
- package/types/import-ui.d.ts +21 -4
- package/types/index.d.ts +59 -12
- package/types/labels.d.ts +2 -22
- package/types/menu-fields.d.ts +9 -0
- package/types/menu-labels.d.ts +6 -0
- package/types/menu-ops.d.ts +28 -3
- package/types/names.d.ts +22 -8
- package/types/share-actions.d.ts +14 -0
- package/types/sheet-views.d.ts +60 -0
- package/types/templates.d.ts +21 -1
- package/types/toolbar-panels.d.ts +13 -6
- package/types/use-export.d.ts +2 -2
- package/types/view-history.d.ts +15 -0
- package/types/view-save.d.ts +10 -6
- package/types/view-store.d.ts +21 -11
- package/types/import-source.d.ts +0 -32
package/dist/menus.js
CHANGED
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
chartTypeOf,
|
|
13
13
|
clone,
|
|
14
14
|
dateSpan,
|
|
15
|
+
dayMs,
|
|
15
16
|
dayText,
|
|
16
17
|
decodeRow,
|
|
17
18
|
emptyPick,
|
|
@@ -23,6 +24,7 @@ import {
|
|
|
23
24
|
hiddenNot,
|
|
24
25
|
importNow,
|
|
25
26
|
isoDay,
|
|
27
|
+
isoYear,
|
|
26
28
|
itemRuleText,
|
|
27
29
|
linkNow,
|
|
28
30
|
loadCheck,
|
|
@@ -55,13 +57,19 @@ import {
|
|
|
55
57
|
viewFromObject,
|
|
56
58
|
viewFromText,
|
|
57
59
|
wholeYears,
|
|
58
|
-
withLinkParam
|
|
59
|
-
|
|
60
|
+
withLinkParam,
|
|
61
|
+
yearOf,
|
|
62
|
+
yearText
|
|
63
|
+
} from "./chunks/chunk-3LDE2GPG.js";
|
|
60
64
|
import {
|
|
61
65
|
addMenuTexts,
|
|
62
66
|
hasMenuTexts,
|
|
63
67
|
menuLabels
|
|
64
|
-
} from "./chunks/chunk-
|
|
68
|
+
} from "./chunks/chunk-TR2HROIK.js";
|
|
69
|
+
import {
|
|
70
|
+
listedFor,
|
|
71
|
+
sheetOfSource
|
|
72
|
+
} from "./chunks/chunk-W2KIPREL.js";
|
|
65
73
|
import {
|
|
66
74
|
Group,
|
|
67
75
|
Icon,
|
|
@@ -73,14 +81,15 @@ import {
|
|
|
73
81
|
rootOf,
|
|
74
82
|
stopAfter,
|
|
75
83
|
useFormName,
|
|
84
|
+
useIsoLayoutEffect,
|
|
76
85
|
useModal
|
|
77
|
-
} from "./chunks/chunk-
|
|
86
|
+
} from "./chunks/chunk-JOWAEZAD.js";
|
|
78
87
|
import {
|
|
79
88
|
fill,
|
|
80
89
|
hostFailure,
|
|
81
90
|
messageOf,
|
|
82
91
|
plural
|
|
83
|
-
} from "./chunks/chunk-
|
|
92
|
+
} from "./chunks/chunk-XN5HNKJ2.js";
|
|
84
93
|
|
|
85
94
|
// src/chip-menus.jsx
|
|
86
95
|
import React6, { useId as useId4, useMemo as useMemo3, useState as useState4 } from "react";
|
|
@@ -95,7 +104,7 @@ import React, { useMemo, useState } from "react";
|
|
|
95
104
|
import { LIMITS, fieldItems, fieldLabel } from "pivotkit-core";
|
|
96
105
|
|
|
97
106
|
// src/menu-ops.js
|
|
98
|
-
import { CATALOG, MATCH_DEFAULTS, computePivot, isFormat } from "pivotkit-core";
|
|
107
|
+
import { CATALOG, MATCH_DEFAULTS, MAX_DATE_MS, computePivot, isFormat } from "pivotkit-core";
|
|
99
108
|
var COUNTING = /* @__PURE__ */ new Set(["count", "countUnique", "listUnique"]);
|
|
100
109
|
var unitOf = (agg) => COUNTING.has(agg) ? "count" : "field";
|
|
101
110
|
function updateValue(view, index, patch, options = {}) {
|
|
@@ -147,16 +156,17 @@ function replaceFilters(view, field, types, entries) {
|
|
|
147
156
|
}
|
|
148
157
|
return next;
|
|
149
158
|
}
|
|
150
|
-
function replaceFilter(view, field, previous, entry) {
|
|
159
|
+
function replaceFilter(view, field, previous, entry, before = null) {
|
|
151
160
|
const next = clone(view);
|
|
152
|
-
const
|
|
153
|
-
const at =
|
|
161
|
+
const indexOf = (f) => f ? next.filters.findIndex((g) => same(g.field, field) && JSON.stringify(g) === JSON.stringify(f)) : -1;
|
|
162
|
+
const at = indexOf(previous);
|
|
154
163
|
if (at === -1) {
|
|
155
164
|
if (!entry) {
|
|
156
165
|
return next;
|
|
157
166
|
}
|
|
167
|
+
const ahead = indexOf(before);
|
|
158
168
|
const last = next.filters.map((f) => same(f.field, field)).lastIndexOf(true);
|
|
159
|
-
next.filters.splice(last + 1, 0, entry);
|
|
169
|
+
next.filters.splice(ahead === -1 ? last + 1 : ahead, 0, entry);
|
|
160
170
|
return next;
|
|
161
171
|
}
|
|
162
172
|
if (entry) {
|
|
@@ -189,7 +199,7 @@ function setTopFilter(view, field, top, previous) {
|
|
|
189
199
|
}
|
|
190
200
|
var RULE_TYPES = Object.freeze(["relative", "compare", "value", "text"]);
|
|
191
201
|
var RULES_MAX = 10;
|
|
192
|
-
var setRule = (view, field, previous, entry) => replaceFilter(view, field, previous, entry);
|
|
202
|
+
var setRule = (view, field, previous, entry, before = null) => replaceFilter(view, field, previous, entry, before);
|
|
193
203
|
var COARSE = Object.freeze(["year", "yearQuarter"]);
|
|
194
204
|
var QUICK_UNITS = Object.freeze(["day", "week", "month", "quarter", "year"]);
|
|
195
205
|
var FINEST = Object.freeze({ day: "day", yearWeek: "week", yearMonth: "month", yearQuarter: "quarter", year: "year" });
|
|
@@ -230,8 +240,8 @@ function yearsCombined(compared, all) {
|
|
|
230
240
|
let kept = new Set(all);
|
|
231
241
|
for (const f of compared) {
|
|
232
242
|
const [a, b] = (
|
|
233
|
-
/** @type {[
|
|
234
|
-
wholeYears(f.value, f.value2)
|
|
243
|
+
/** @type {[number, number]} */
|
|
244
|
+
wholeYears(f.value, f.value2)
|
|
235
245
|
);
|
|
236
246
|
kept = new Set([...kept].filter((y) => (a <= y && y <= b) !== f.not));
|
|
237
247
|
}
|
|
@@ -242,7 +252,10 @@ function yearRules(field, years, all, blanks = "exclude") {
|
|
|
242
252
|
if (!years.length || years.length === all.length) {
|
|
243
253
|
return [];
|
|
244
254
|
}
|
|
245
|
-
const day = (y, last) =>
|
|
255
|
+
const day = (y, last) => {
|
|
256
|
+
const iso = `${isoYear(y)}-${last ? "12-31" : "01-01"}`;
|
|
257
|
+
return Number.isNaN(dayMs(iso)) ? isoDay(last ? MAX_DATE_MS : -MAX_DATE_MS) : iso;
|
|
258
|
+
};
|
|
246
259
|
const rule = (not, from, to) => ({ field, type: "compare", op: "between", value: day(from, false), value2: day(to, true), not, blanks });
|
|
247
260
|
const rules = [rule(false, years[0], years[years.length - 1])];
|
|
248
261
|
for (let i = 1; i < years.length; i++) {
|
|
@@ -377,6 +390,27 @@ function rowsInRange(range, dict, counts) {
|
|
|
377
390
|
}
|
|
378
391
|
return rows;
|
|
379
392
|
}
|
|
393
|
+
function combinedYearsText(on, all, labels, locale) {
|
|
394
|
+
if (on.length === 1) {
|
|
395
|
+
return fill(labels.yearsOne, { year: yearText(on[0], locale) });
|
|
396
|
+
}
|
|
397
|
+
const run = on.length === all.length || on[on.length - 1] - on[0] === on.length - 1;
|
|
398
|
+
return fill(labels.yearsAll, { years: run ? `${yearText(on[0], locale)}\u2013${yearText(on[on.length - 1], locale)}` : on.map((y) => yearText(y, locale)).join(", ") });
|
|
399
|
+
}
|
|
400
|
+
var dayOnOrBefore = (a, b) => dayMs(a) <= dayMs(b);
|
|
401
|
+
var dateInputValue = (iso) => {
|
|
402
|
+
const day = isoDay(dayMs(iso));
|
|
403
|
+
const y = yearOf(day);
|
|
404
|
+
return y >= 1 ? `${String(y).padStart(4, "0")}${day.slice(day.indexOf("-", 1))}` : "";
|
|
405
|
+
};
|
|
406
|
+
function dateFromInput(text) {
|
|
407
|
+
const m = /^(\d{4,})-(\d{2})-(\d{2})$/.exec(text);
|
|
408
|
+
if (!m || Number(m[1]) < 1) {
|
|
409
|
+
return null;
|
|
410
|
+
}
|
|
411
|
+
const iso = `${isoYear(Number(m[1]))}-${m[2]}-${m[3]}`;
|
|
412
|
+
return Number.isNaN(dayMs(iso)) || isoDay(dayMs(iso)) !== iso ? null : iso;
|
|
413
|
+
}
|
|
380
414
|
|
|
381
415
|
// src/filter.jsx
|
|
382
416
|
var FILTER_LIST_MAX = 300;
|
|
@@ -1138,7 +1172,7 @@ function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, sea
|
|
|
1138
1172
|
const top = nav.stack[nav.stack.length - 1];
|
|
1139
1173
|
setNav({ stack: nav.stack.slice(0, -1), focus: focus ?? top?.from ?? null });
|
|
1140
1174
|
};
|
|
1141
|
-
const
|
|
1175
|
+
const pick2 = (choice) => {
|
|
1142
1176
|
if (choice.open) {
|
|
1143
1177
|
choice.run?.();
|
|
1144
1178
|
open(choice.open, choice.backTo ?? `item:${choice.id}`);
|
|
@@ -1195,9 +1229,9 @@ function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, sea
|
|
|
1195
1229
|
}
|
|
1196
1230
|
}
|
|
1197
1231
|
}
|
|
1198
|
-
)) : null, /* @__PURE__ */ React3.createElement("div", { className: "pk-level-first" }, hits ? /* @__PURE__ */ React3.createElement(SearchHits, { hits, labels, onPick:
|
|
1232
|
+
)) : null, /* @__PURE__ */ React3.createElement("div", { className: "pk-level-first" }, hits ? /* @__PURE__ */ React3.createElement(SearchHits, { hits, labels, onPick: pick2, onOpen: open, close }) : /* @__PURE__ */ React3.createElement(MenuList, { label: name, close, testId: "level-first" }, topics.map((t) => /* @__PURE__ */ React3.createElement(TopicFirst, { key: t.id, topic: t, labels, onPick: pick2, onOpen: () => open(t.id) })), foot ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { role: "separator", className: "pk-level-sep" }), foot) : null)));
|
|
1199
1233
|
};
|
|
1200
|
-
return /* @__PURE__ */ React3.createElement("div", { ref: box, className: "pk-levels", onKeyDown, "data-level": level ?? "" }, topic ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { className: "pk-level-head" }, /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-link pk-level-back", onClick: () => back(), "aria-label": fill(labels.backTo, { name }), "data-testid": "level-back" }, /* @__PURE__ */ React3.createElement(Icon, { name: "chevronRight", size: 16, className: "pk-flip" }), labels.back), /* @__PURE__ */ React3.createElement("h3", { id: titleId, className: "pk-level-title", "data-testid": "level-title" }, fill(labels.levelTitle, { name, topic: topic.levelTitle ?? topic.title })), topic.info ? /* @__PURE__ */ React3.createElement(SettingInfo, { id: topic.info, name: topic.title }) : null), /* @__PURE__ */ React3.createElement("div", { className: "pk-level-body", "data-testid": `level-${topic.id}` }, topic.kind === "menu" ? /* @__PURE__ */ React3.createElement(MenuList, { labelledBy: titleId, close }, /* @__PURE__ */ React3.createElement(Groups, { topic, onPick:
|
|
1234
|
+
return /* @__PURE__ */ React3.createElement("div", { ref: box, className: "pk-levels", onKeyDown, "data-level": level ?? "" }, topic ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { className: "pk-level-head" }, /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-link pk-level-back", onClick: () => back(), "aria-label": fill(labels.backTo, { name }), "data-testid": "level-back" }, /* @__PURE__ */ React3.createElement(Icon, { name: "chevronRight", size: 16, className: "pk-flip" }), labels.back), /* @__PURE__ */ React3.createElement("h3", { id: titleId, className: "pk-level-title", "data-testid": "level-title" }, fill(labels.levelTitle, { name, topic: topic.levelTitle ?? topic.title })), topic.info ? /* @__PURE__ */ React3.createElement(SettingInfo, { id: topic.info, name: topic.title }) : null), /* @__PURE__ */ React3.createElement("div", { className: "pk-level-body", "data-testid": `level-${topic.id}` }, topic.kind === "menu" ? /* @__PURE__ */ React3.createElement(MenuList, { labelledBy: titleId, close }, /* @__PURE__ */ React3.createElement(Groups, { topic, onPick: pick2 })) : /* @__PURE__ */ React3.createElement("div", { role: "group", "aria-labelledby": titleId, className: "pk-level-panel" }, panel(topic.id, back, nav.stack[nav.stack.length - 1]?.hint)))) : first());
|
|
1201
1235
|
}
|
|
1202
1236
|
function useLater(wait = 450) {
|
|
1203
1237
|
const timer = useRef(
|
|
@@ -1378,6 +1412,9 @@ function NumberField({ value, onChange, problem, label, testId, className = "pk-
|
|
|
1378
1412
|
}
|
|
1379
1413
|
)), problem ? /* @__PURE__ */ React4.createElement("p", { id, className: "pk-form-problem", "data-testid": `${testId}-problem` }, problem) : null);
|
|
1380
1414
|
}
|
|
1415
|
+
function Radio(props) {
|
|
1416
|
+
return /* @__PURE__ */ React4.createElement("input", { ...props, type: "radio", onClick: (e) => e.currentTarget.focus() });
|
|
1417
|
+
}
|
|
1381
1418
|
var fieldKeys = ({ now, restore, back }) => (e) => {
|
|
1382
1419
|
if (e.key === "Enter") {
|
|
1383
1420
|
e.preventDefault();
|
|
@@ -1405,6 +1442,17 @@ function measuresOf(view, types, labels, ref) {
|
|
|
1405
1442
|
|
|
1406
1443
|
// src/filter-level.jsx
|
|
1407
1444
|
var twin = (op) => op === "between" || op === "notBetween";
|
|
1445
|
+
function useLatest(props) {
|
|
1446
|
+
const ref = useRef2(props);
|
|
1447
|
+
useEffect2(() => {
|
|
1448
|
+
ref.current = props;
|
|
1449
|
+
});
|
|
1450
|
+
return ref;
|
|
1451
|
+
}
|
|
1452
|
+
var emptied = (patch) => ["a", "b", "count"].some((k) => {
|
|
1453
|
+
const v = patch[k];
|
|
1454
|
+
return typeof v === "string" && v.trim() === "";
|
|
1455
|
+
});
|
|
1408
1456
|
var capital = (text, locale) => text.charAt(0).toLocaleUpperCase(locale) + text.slice(1);
|
|
1409
1457
|
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);
|
|
1410
1458
|
var rowKind = (f) => !editable(f) ? "fixed" : f.type === "value" ? "total" : f.type === "text" ? "name" : "item";
|
|
@@ -1507,7 +1555,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1507
1555
|
}
|
|
1508
1556
|
};
|
|
1509
1557
|
const rowsOf = (range) => range ? rowsInRange(range, column.dict, counts) : 0;
|
|
1510
|
-
const reaches = (r) => r !== null && r.from !== null && r.from
|
|
1558
|
+
const reaches = (r) => r !== null && r.from !== null && dayOnOrBefore(r.from, latestDay);
|
|
1511
1559
|
const reach = (unit) => {
|
|
1512
1560
|
for (let n = 1; n <= REACH[unit]; n++) {
|
|
1513
1561
|
if (reaches(datesOf({ unit, count: n }))) {
|
|
@@ -1577,9 +1625,8 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1577
1625
|
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) })));
|
|
1578
1626
|
};
|
|
1579
1627
|
const radio = (id, checked, onPick, name, children, described = true) => /* @__PURE__ */ React5.createElement("label", { className: "pk-radio pk-quick" }, /* @__PURE__ */ React5.createElement(
|
|
1580
|
-
|
|
1628
|
+
Radio,
|
|
1581
1629
|
{
|
|
1582
|
-
type: "radio",
|
|
1583
1630
|
name: groupName,
|
|
1584
1631
|
checked,
|
|
1585
1632
|
onChange: onPick,
|
|
@@ -1695,13 +1742,14 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1695
1742
|
const periodStart = fk.months ? Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), 1) : Date.UTC(today.getUTCFullYear(), 0, 1);
|
|
1696
1743
|
const [anchorOutside] = useState3(() => span.max < periodStart || anchor !== "today");
|
|
1697
1744
|
const anchorKind = ["today", "latest", "first"].includes(anchor) ? anchor : "date";
|
|
1698
|
-
const [day, setDay] = useState3(anchorKind === "date" ? anchor
|
|
1699
|
-
const
|
|
1745
|
+
const [day, setDay] = useState3(dateInputValue(anchorKind === "date" ? anchor : latestDay));
|
|
1746
|
+
const dayIso = dateFromInput(day);
|
|
1747
|
+
const dayWhole = dayIso !== null;
|
|
1700
1748
|
const [seenAnchor, setSeenAnchor] = useState3(anchor);
|
|
1701
1749
|
if (anchor !== seenAnchor) {
|
|
1702
1750
|
setSeenAnchor(anchor);
|
|
1703
1751
|
if (anchorKind === "date") {
|
|
1704
|
-
setDay(anchor
|
|
1752
|
+
setDay(dateInputValue(anchor));
|
|
1705
1753
|
}
|
|
1706
1754
|
}
|
|
1707
1755
|
const dayHint = `${anchorId}-hint`;
|
|
@@ -1711,7 +1759,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1711
1759
|
commit(setAnchor(view, field, a), note);
|
|
1712
1760
|
}
|
|
1713
1761
|
};
|
|
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" ?
|
|
1762
|
+
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" ? dayIso ?? 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
1763
|
"input",
|
|
1716
1764
|
{
|
|
1717
1765
|
type: "date",
|
|
@@ -1719,13 +1767,14 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1719
1767
|
value: day,
|
|
1720
1768
|
onChange: (e) => {
|
|
1721
1769
|
setDay(e.target.value);
|
|
1722
|
-
|
|
1723
|
-
|
|
1770
|
+
const iso = dateFromInput(e.target.value);
|
|
1771
|
+
if (iso) {
|
|
1772
|
+
setAnchorTo(iso);
|
|
1724
1773
|
}
|
|
1725
1774
|
},
|
|
1726
1775
|
onBlur: () => {
|
|
1727
1776
|
if (!dayWhole) {
|
|
1728
|
-
setDay(anchor
|
|
1777
|
+
setDay(dateInputValue(anchor));
|
|
1729
1778
|
}
|
|
1730
1779
|
},
|
|
1731
1780
|
"aria-label": labels.anchorDay,
|
|
@@ -1733,7 +1782,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1733
1782
|
"aria-describedby": dayWhole ? void 0 : dayHint,
|
|
1734
1783
|
"data-testid": "quick-anchor-date"
|
|
1735
1784
|
}
|
|
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
|
|
1785
|
+
) : 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, locale) })) : null);
|
|
1737
1786
|
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
1787
|
"input",
|
|
1739
1788
|
{
|
|
@@ -1760,8 +1809,8 @@ function YearsCombined({ ctx, years, on }) {
|
|
|
1760
1809
|
};
|
|
1761
1810
|
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("p", { className: "pk-hint pk-years-hint" }, fill(labels.yearsCombinedHint, { noun: plural(noun, 1, { lang: labels.lang, locale }) })), /* @__PURE__ */ React5.createElement("div", { className: "pk-years", role: "group", "aria-label": labels.yearsCombined, "data-testid": "years-combined" }, years.map((y) => {
|
|
1762
1811
|
const pressed = on.includes(y.year);
|
|
1763
|
-
return /* @__PURE__ */ React5.createElement("button", { key: y.year, type: "button", className: "pk-year-chip", "aria-pressed": pressed, disabled: pressed && on.length === 1, onClick: () => toggle(y.year), "data-testid": `year-${y.year}` }, pressed ? /* @__PURE__ */ React5.createElement(Icon, { name: "check", size: 12 }) : null, /* @__PURE__ */ React5.createElement("span", null,
|
|
1764
|
-
})), on.length === 1 ? /* @__PURE__ */ React5.createElement("p", { className: "pk-hint" }, fill(labels.yearsCombinedOne, { year:
|
|
1812
|
+
return /* @__PURE__ */ React5.createElement("button", { key: y.year, type: "button", className: "pk-year-chip", "aria-pressed": pressed, disabled: pressed && on.length === 1, onClick: () => toggle(y.year), "data-testid": `year-${y.year}` }, pressed ? /* @__PURE__ */ React5.createElement(Icon, { name: "check", size: 12 }) : null, /* @__PURE__ */ React5.createElement("span", null, yearText(y.year, locale)), /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-rows" }, fill(labels.quickRows, { rows: y.rows.toLocaleString(locale) })));
|
|
1813
|
+
})), on.length === 1 ? /* @__PURE__ */ React5.createElement("p", { className: "pk-hint" }, fill(labels.yearsCombinedOne, { year: yearText(on[0], locale) })) : null);
|
|
1765
1814
|
}
|
|
1766
1815
|
function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
1767
1816
|
const [open, setOpen] = useState3(false);
|
|
@@ -1782,7 +1831,7 @@ function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
|
1782
1831
|
setOpen(true);
|
|
1783
1832
|
};
|
|
1784
1833
|
const close = () => setOpen(false);
|
|
1785
|
-
const
|
|
1834
|
+
const pick2 = (item) => {
|
|
1786
1835
|
close();
|
|
1787
1836
|
onChange(String(item.value));
|
|
1788
1837
|
};
|
|
@@ -1794,7 +1843,7 @@ function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
|
1794
1843
|
} else if (e.key === "Enter") {
|
|
1795
1844
|
e.preventDefault();
|
|
1796
1845
|
if (matching[active]) {
|
|
1797
|
-
|
|
1846
|
+
pick2(matching[active]);
|
|
1798
1847
|
}
|
|
1799
1848
|
} else if (e.key === "Escape") {
|
|
1800
1849
|
e.preventDefault();
|
|
@@ -1853,14 +1902,14 @@ function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
|
1853
1902
|
"aria-selected": String(item.value) === value,
|
|
1854
1903
|
className: `pk-picker-option${i === active ? " pk-picker-active" : ""}`,
|
|
1855
1904
|
onMouseMove: () => setActive(i),
|
|
1856
|
-
onClick: () =>
|
|
1905
|
+
onClick: () => pick2(item),
|
|
1857
1906
|
"data-testid": "picker-option"
|
|
1858
1907
|
},
|
|
1859
1908
|
/* @__PURE__ */ React5.createElement("span", null, item.label),
|
|
1860
1909
|
/* @__PURE__ */ React5.createElement("span", { className: "pk-count" }, item.count.toLocaleString(locale))
|
|
1861
1910
|
)), matching.length ? null : /* @__PURE__ */ React5.createElement("li", { className: "pk-hint pk-picker-none" }, labels.pickerNone)), /* @__PURE__ */ React5.createElement("p", { className: "pk-hint pk-picker-count", "aria-live": "polite", "data-testid": "picker-count" }, fill(labels.pickerMatch, { count: found.length.toLocaleString(locale), total: items.length.toLocaleString(locale) }))));
|
|
1862
1911
|
}
|
|
1863
|
-
function ItemRule({ rule, ctx, apply, first }) {
|
|
1912
|
+
function ItemRule({ rule, ctx, apply, unset, first }) {
|
|
1864
1913
|
const { field, labels, locale, fk, items } = ctx;
|
|
1865
1914
|
const narrow = useContext3(LayerContext).size === "narrow";
|
|
1866
1915
|
const words = fk.dates ? labels.dateOps : labels.valueOps;
|
|
@@ -1876,6 +1925,7 @@ function ItemRule({ rule, ctx, apply, first }) {
|
|
|
1876
1925
|
unit: ranged?.unit ?? "year"
|
|
1877
1926
|
}));
|
|
1878
1927
|
const later = useLater();
|
|
1928
|
+
const latest = useLatest({ rule, apply, unset });
|
|
1879
1929
|
const formName = useFormName();
|
|
1880
1930
|
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);
|
|
1881
1931
|
const entryOf = (x) => {
|
|
@@ -1892,7 +1942,9 @@ function ItemRule({ rule, ctx, apply, first }) {
|
|
|
1892
1942
|
const run = () => {
|
|
1893
1943
|
const entry = entryOf(next);
|
|
1894
1944
|
if (entry) {
|
|
1895
|
-
apply(entry);
|
|
1945
|
+
latest.current.apply(entry);
|
|
1946
|
+
} else if (latest.current.rule && emptied(patch)) {
|
|
1947
|
+
latest.current.unset();
|
|
1896
1948
|
}
|
|
1897
1949
|
};
|
|
1898
1950
|
if (wait) {
|
|
@@ -1945,11 +1997,12 @@ function ItemRule({ rule, ctx, apply, first }) {
|
|
|
1945
1997
|
}
|
|
1946
1998
|
), /* @__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));
|
|
1947
1999
|
}
|
|
1948
|
-
function TotalRule({ rule, ctx, apply, first }) {
|
|
2000
|
+
function TotalRule({ rule, ctx, apply, unset, first }) {
|
|
1949
2001
|
const { view, types, labels, locale } = ctx;
|
|
1950
2002
|
const { choices, names } = measuresOf(view, types, labels, rule?.by);
|
|
1951
2003
|
const [s, setS] = useState3(() => ({ by: choiceIndex(choices, rule?.by), op: rule ? ruleOp(rule) : ">", a: numberText(rule?.value, locale), b: numberText(rule?.value2, locale) }));
|
|
1952
2004
|
const later = useLater();
|
|
2005
|
+
const latest = useLatest({ rule, apply, unset });
|
|
1953
2006
|
const formName = useFormName();
|
|
1954
2007
|
const change = (patch, wait = false) => {
|
|
1955
2008
|
const next = { ...s, ...patch };
|
|
@@ -1958,7 +2011,9 @@ function TotalRule({ rule, ctx, apply, first }) {
|
|
|
1958
2011
|
const [a, b] = [parseNumber(next.a, locale), parseNumber(next.b, locale)];
|
|
1959
2012
|
if (a !== null && (!twin(next.op) || b !== null)) {
|
|
1960
2013
|
const by = choices[next.by];
|
|
1961
|
-
apply({ field: ctx.field, type: "value", by: { field: by.field, agg: by.agg }, ...opOf(next.op), value: a, ...twin(next.op) ? { value2: b } : {} });
|
|
2014
|
+
latest.current.apply({ field: ctx.field, type: "value", by: { field: by.field, agg: by.agg }, ...opOf(next.op), value: a, ...twin(next.op) ? { value2: b } : {} });
|
|
2015
|
+
} else if (latest.current.rule && emptied(patch)) {
|
|
2016
|
+
latest.current.unset();
|
|
1962
2017
|
}
|
|
1963
2018
|
};
|
|
1964
2019
|
if (wait) {
|
|
@@ -1981,12 +2036,14 @@ function TotalRule({ rule, ctx, apply, first }) {
|
|
|
1981
2036
|
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" });
|
|
1982
2037
|
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);
|
|
1983
2038
|
}
|
|
1984
|
-
function NameRule({ rule, ctx, apply, first }) {
|
|
2039
|
+
function NameRule({ rule, ctx, apply, unset, first }) {
|
|
1985
2040
|
const { field, labels } = ctx;
|
|
1986
2041
|
const [op, setOp] = useState3(rule ? ruleOp(rule) : "contains");
|
|
1987
2042
|
const send = (o, value) => {
|
|
1988
|
-
if (value !== "") {
|
|
2043
|
+
if (value.trim() !== "") {
|
|
1989
2044
|
apply({ ...textRule(field, { op: o, value, on: ctx.textOn }), ...rule ? { blanks: rule.blanks } : {} });
|
|
2045
|
+
} else if (rule) {
|
|
2046
|
+
unset();
|
|
1990
2047
|
}
|
|
1991
2048
|
};
|
|
1992
2049
|
const text = useAppliedText(rule?.value ?? "", (value) => send(op, value));
|
|
@@ -2035,6 +2092,11 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2035
2092
|
/** @type {"item" | "total" | "name" | null} */
|
|
2036
2093
|
null
|
|
2037
2094
|
);
|
|
2095
|
+
const [added, setAdded] = useState3(0);
|
|
2096
|
+
const [held, setHeld] = useState3(
|
|
2097
|
+
/** @type {Array<{ at: number, kind: "item" | "total" | "name", blanks?: string }>} */
|
|
2098
|
+
[]
|
|
2099
|
+
);
|
|
2038
2100
|
const blanksName = useFormName();
|
|
2039
2101
|
const [info, setInfo] = useState3(
|
|
2040
2102
|
/** @type {number | null} */
|
|
@@ -2052,6 +2114,7 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2052
2114
|
if (rulesKey !== own) {
|
|
2053
2115
|
setGen(gen + 1);
|
|
2054
2116
|
setDraft(null);
|
|
2117
|
+
setHeld([]);
|
|
2055
2118
|
}
|
|
2056
2119
|
}
|
|
2057
2120
|
const box = useRef2(
|
|
@@ -2059,6 +2122,14 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2059
2122
|
null
|
|
2060
2123
|
);
|
|
2061
2124
|
const focusAdd = useRef2(false);
|
|
2125
|
+
const removed = useRef2(
|
|
2126
|
+
/** @type {Set<string>} */
|
|
2127
|
+
/* @__PURE__ */ new Set()
|
|
2128
|
+
);
|
|
2129
|
+
const now = useRef2({ view, gen });
|
|
2130
|
+
useIsoLayoutEffect(() => {
|
|
2131
|
+
now.current = { view, gen };
|
|
2132
|
+
});
|
|
2062
2133
|
useEffect2(() => {
|
|
2063
2134
|
if (focusAdd.current) {
|
|
2064
2135
|
focusAdd.current = false;
|
|
@@ -2081,12 +2152,19 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2081
2152
|
}
|
|
2082
2153
|
}
|
|
2083
2154
|
}
|
|
2084
|
-
}, [draft]);
|
|
2155
|
+
}, [draft, added]);
|
|
2156
|
+
const add = (k) => {
|
|
2157
|
+
if (draft) {
|
|
2158
|
+
setHeld([...held, { at: rules.length + held.length, kind: draft }]);
|
|
2159
|
+
}
|
|
2160
|
+
setDraft(k);
|
|
2161
|
+
setAdded(added + 1);
|
|
2162
|
+
};
|
|
2085
2163
|
const kinds = (
|
|
2086
2164
|
/** @type {Array<"item" | "total" | "name">} */
|
|
2087
2165
|
["item", "total", "name"].filter((k) => k === "item" ? Boolean(fk.item) : k === "name" ? Boolean(nameKind) : true)
|
|
2088
2166
|
);
|
|
2089
|
-
const count = rules.length + (draft ? 1 : 0);
|
|
2167
|
+
const count = rules.length + (draft ? 1 : 0) + held.length;
|
|
2090
2168
|
const full = count >= RULES_MAX || view.filters.length >= LIMITS2.filters;
|
|
2091
2169
|
const addText = { item: fill(labels.addRuleItem, { field: fieldLabel3(field, labels.core) }), total: labels.addRuleTotal, name: labels.addRuleName };
|
|
2092
2170
|
const infoText = (rule, kind) => {
|
|
@@ -2100,39 +2178,82 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2100
2178
|
}
|
|
2101
2179
|
return fill(labels.ruleInfo[fk.item === "group" ? fk.cyclic ? "cyclic" : "group" : fk.item ?? "group"], { noun: one });
|
|
2102
2180
|
};
|
|
2103
|
-
const
|
|
2181
|
+
const commitOwn = (next) => {
|
|
2182
|
+
setOwn(rulesKeyOf(filtersOf(next, field, RULE_TYPES).filter((f) => !ctx.quickFilters.includes(f))));
|
|
2183
|
+
commit(next, note);
|
|
2184
|
+
};
|
|
2185
|
+
const row = (rule, kind, i, isHeld = false) => {
|
|
2104
2186
|
const Row = ROWS[kind];
|
|
2187
|
+
const key = `${gen}:${i}`;
|
|
2105
2188
|
const apply = (entry) => {
|
|
2106
|
-
|
|
2107
|
-
|
|
2108
|
-
|
|
2109
|
-
|
|
2189
|
+
if (removed.current.has(key)) {
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2192
|
+
const was = isHeld ? held.find((h) => h.at === i) : void 0;
|
|
2193
|
+
const own2 = was?.blanks && ITEM_RULE_TYPES.includes(entry.type) ? { ...entry, blanks: was.blanks } : !rule && ctx.keepBlanks && ITEM_RULE_TYPES.includes(entry.type) ? { ...entry, blanks: "include" } : entry;
|
|
2194
|
+
const current = now.current.gen === gen;
|
|
2195
|
+
if (isHeld && current) {
|
|
2196
|
+
setHeld(held.filter((h) => h.at !== i));
|
|
2197
|
+
} else if (!rule && current) {
|
|
2110
2198
|
setDraft(null);
|
|
2111
2199
|
}
|
|
2112
|
-
|
|
2200
|
+
const before = isHeld ? rows.slice(i + 1).find((x) => x.rule)?.rule ?? null : null;
|
|
2201
|
+
commitOwn(setRule(now.current.view, field, rule, own2, before));
|
|
2202
|
+
};
|
|
2203
|
+
const unset = () => {
|
|
2204
|
+
if (rule && !removed.current.has(key)) {
|
|
2205
|
+
if (now.current.gen === gen) {
|
|
2206
|
+
setHeld([...held, { at: i, kind, blanks: rule.blanks }].sort((a, b) => a.at - b.at));
|
|
2207
|
+
ctx.keepSections();
|
|
2208
|
+
}
|
|
2209
|
+
commitOwn(setRule(now.current.view, field, rule, null));
|
|
2210
|
+
}
|
|
2113
2211
|
};
|
|
2114
2212
|
const remove = () => {
|
|
2213
|
+
removed.current.add(key);
|
|
2115
2214
|
focusAdd.current = true;
|
|
2116
2215
|
if (rule) {
|
|
2117
2216
|
commit(setRule(view, field, rule, null), note);
|
|
2118
2217
|
} else {
|
|
2119
|
-
|
|
2218
|
+
if (isHeld) {
|
|
2219
|
+
setHeld(held.filter((h) => h.at !== i));
|
|
2220
|
+
} else {
|
|
2221
|
+
setDraft(null);
|
|
2222
|
+
}
|
|
2120
2223
|
setGen(gen + 1);
|
|
2224
|
+
if (rows.length === 1) {
|
|
2225
|
+
ctx.releaseSections();
|
|
2226
|
+
}
|
|
2121
2227
|
}
|
|
2122
2228
|
};
|
|
2123
2229
|
const result = rule ? results.get(rule) : null;
|
|
2124
2230
|
const open = info === i;
|
|
2125
2231
|
const infoId = `${gen}-${i}`;
|
|
2126
|
-
return /* @__PURE__ */ React5.createElement("li", { key
|
|
2232
|
+
return /* @__PURE__ */ React5.createElement("li", { key, 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, unset, first: focusFirst && i === 0 || !rule && !isHeld && 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", onMouseDown: (e) => e.preventDefault(), 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);
|
|
2127
2233
|
};
|
|
2128
|
-
|
|
2234
|
+
const rows = rules.map((r) => ({ rule: r, kind: rowKind(r), isHeld: false }));
|
|
2235
|
+
for (const h of held) {
|
|
2236
|
+
rows.splice(h.at, 0, { rule: null, kind: h.kind, isHeld: true });
|
|
2237
|
+
}
|
|
2238
|
+
if (draft) {
|
|
2239
|
+
rows.push({ rule: null, kind: draft, isHeld: false });
|
|
2240
|
+
}
|
|
2241
|
+
useEffect2(() => {
|
|
2242
|
+
for (const key of removed.current) {
|
|
2243
|
+
if (!rows.some((_r, i) => key === `${gen}:${i}`)) {
|
|
2244
|
+
removed.current.delete(key);
|
|
2245
|
+
}
|
|
2246
|
+
}
|
|
2247
|
+
});
|
|
2248
|
+
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, rows.map((x, i) => row(x.rule, x.kind, i, x.isHeld))) : 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(
|
|
2129
2249
|
"button",
|
|
2130
2250
|
{
|
|
2131
2251
|
key: k,
|
|
2132
2252
|
type: "button",
|
|
2133
2253
|
className: "pk-btn pk-small-btn",
|
|
2134
2254
|
disabled: full,
|
|
2135
|
-
|
|
2255
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2256
|
+
onClick: () => add(k),
|
|
2136
2257
|
"data-autofocus": focusFirst && !count && i === 0 ? "" : void 0,
|
|
2137
2258
|
"data-testid": `rule-add-${k}`
|
|
2138
2259
|
},
|
|
@@ -2257,7 +2378,7 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2257
2378
|
const say = (f) => ruleText(view, f, { labels, locale, timeZone, date: fk.dates, labelOf, span });
|
|
2258
2379
|
const number = (n) => n.toLocaleString(locale);
|
|
2259
2380
|
const yearsOn = quick.id === "yearsCombined" && quick.years ? quick.years : years.map((y) => y.year);
|
|
2260
|
-
const yearsText = fk.cyclic && years.length > 1 ? yearsOn
|
|
2381
|
+
const yearsText = fk.cyclic && years.length > 1 ? combinedYearsText(yearsOn, years.map((y) => y.year), labels, locale) : null;
|
|
2261
2382
|
const quickWords = quick.id === "yearsCombined" ? yearsText : quick.filters.length ? relativeText(quick.filters[0], labels, locale, timeZone, void 0, span, view.formatting?.weekStart) : null;
|
|
2262
2383
|
const outByQuick = (
|
|
2263
2384
|
/** @type {Set<string> | undefined} */
|
|
@@ -2334,7 +2455,19 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2334
2455
|
});
|
|
2335
2456
|
};
|
|
2336
2457
|
const keepBlanks = keepsBlanks(view, field);
|
|
2337
|
-
const
|
|
2458
|
+
const keepSections = () => {
|
|
2459
|
+
if (rules.length === 1 && !quick.filters.length) {
|
|
2460
|
+
byHand.current = true;
|
|
2461
|
+
setOpenPicks(openPicks ?? !anyRule);
|
|
2462
|
+
setOpenRules(openRules ?? anyRule);
|
|
2463
|
+
}
|
|
2464
|
+
};
|
|
2465
|
+
const releaseSections = () => {
|
|
2466
|
+
setOpenPicks(null);
|
|
2467
|
+
setOpenRules(null);
|
|
2468
|
+
lost.current = true;
|
|
2469
|
+
};
|
|
2470
|
+
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, keepSections, releaseSections };
|
|
2338
2471
|
const blankRows = info.items.find((i) => i.value === null)?.count ?? 0;
|
|
2339
2472
|
const blanks = blankRows > 0 && (itemRules.length > 0 || quick.filters.length > 0) ? { rows: blankRows, on: keepBlanks } : null;
|
|
2340
2473
|
const picksOpen = openPicks ?? !anyRule;
|
|
@@ -2416,7 +2549,7 @@ function TopLevel({ view, field, types, labels, locale, commit, back, encoded })
|
|
|
2416
2549
|
};
|
|
2417
2550
|
const groupName = useFormName();
|
|
2418
2551
|
const tiesName = useFormName();
|
|
2419
|
-
const radio = (id, text, checked, onPick) => /* @__PURE__ */ React6.createElement("label", { className: "pk-radio" }, /* @__PURE__ */ React6.createElement(
|
|
2552
|
+
const radio = (id, text, checked, onPick) => /* @__PURE__ */ React6.createElement("label", { className: "pk-radio" }, /* @__PURE__ */ React6.createElement(Radio, { name: groupName, checked, onChange: onPick, "data-autofocus": checked ? "" : void 0, "data-testid": `top-${id}` }), /* @__PURE__ */ React6.createElement("span", null, text));
|
|
2420
2553
|
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, () => {
|
|
2421
2554
|
setOwn(false);
|
|
2422
2555
|
set(null);
|
|
@@ -2656,6 +2789,66 @@ function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaul
|
|
|
2656
2789
|
import React7, { useEffect as useEffect3, useId as useId5, useRef as useRef3, useState as useState5 } from "react";
|
|
2657
2790
|
import { VIEW_FILE_LIMITS } from "pivotkit-core";
|
|
2658
2791
|
|
|
2792
|
+
// src/export-scope.js
|
|
2793
|
+
function dataExportOf(exportData, names) {
|
|
2794
|
+
if (exportData === true) {
|
|
2795
|
+
return { source: true, unknown: [] };
|
|
2796
|
+
}
|
|
2797
|
+
if (!exportData || typeof exportData !== "object" || Array.isArray(exportData)) {
|
|
2798
|
+
return { source: false, unknown: [] };
|
|
2799
|
+
}
|
|
2800
|
+
const { columns } = (
|
|
2801
|
+
/** @type {{ columns?: unknown }} */
|
|
2802
|
+
exportData
|
|
2803
|
+
);
|
|
2804
|
+
if (columns === void 0) {
|
|
2805
|
+
return { source: true, unknown: [] };
|
|
2806
|
+
}
|
|
2807
|
+
if (!Array.isArray(columns)) {
|
|
2808
|
+
return { source: false, columns: [], unknown: [], notList: true };
|
|
2809
|
+
}
|
|
2810
|
+
const wanted = columns.filter((c) => typeof c === "string");
|
|
2811
|
+
const picked = pickColumns(names, wanted).map((i) => names[i]);
|
|
2812
|
+
const known = new Set(picked.map((n) => n.toLowerCase()));
|
|
2813
|
+
const unknown = wanted.filter((w) => !known.has(w.toLowerCase()));
|
|
2814
|
+
return { source: picked.length > 0, columns: picked, unknown };
|
|
2815
|
+
}
|
|
2816
|
+
function pickColumns(names, wanted) {
|
|
2817
|
+
if (wanted === void 0) {
|
|
2818
|
+
return names.map((_n, i) => i);
|
|
2819
|
+
}
|
|
2820
|
+
const picked = [];
|
|
2821
|
+
for (const w of wanted) {
|
|
2822
|
+
const i = names.findIndex((n) => n.toLowerCase() === w.toLowerCase());
|
|
2823
|
+
if (i >= 0 && !picked.includes(i)) {
|
|
2824
|
+
picked.push(i);
|
|
2825
|
+
}
|
|
2826
|
+
}
|
|
2827
|
+
return picked;
|
|
2828
|
+
}
|
|
2829
|
+
var warned = /* @__PURE__ */ new Set();
|
|
2830
|
+
function dataExportFor(exportData, encoded) {
|
|
2831
|
+
const names = encoded ? encoded.columns.filter((c) => !c.derived).map((c) => c.name) : [];
|
|
2832
|
+
const scope = dataExportOf(exportData, names);
|
|
2833
|
+
if (scope.notList) {
|
|
2834
|
+
warnOnce("pivotkit: exportData.columns is not a list; Source data and the drill-down's exports are off");
|
|
2835
|
+
} else if (names.length > 0 && scope.columns) {
|
|
2836
|
+
const off = scope.source ? "" : "; no column is left, so Source data and the drill-down's exports are off";
|
|
2837
|
+
const listed = scope.unknown.slice(0, 5).map((n) => JSON.stringify(n.slice(0, 40))).join(", ") + (scope.unknown.length > 5 ? `, and ${scope.unknown.length - 5} more` : "");
|
|
2838
|
+
const text = scope.unknown.length > 0 ? `pivotkit: exportData.columns names no column of the data: ${listed}${off}` : scope.source ? null : `pivotkit: exportData.columns is empty${off}`;
|
|
2839
|
+
if (text) {
|
|
2840
|
+
warnOnce(text);
|
|
2841
|
+
}
|
|
2842
|
+
}
|
|
2843
|
+
return scope;
|
|
2844
|
+
}
|
|
2845
|
+
function warnOnce(text) {
|
|
2846
|
+
if (!warned.has(text)) {
|
|
2847
|
+
warned.add(text);
|
|
2848
|
+
console.warn(text);
|
|
2849
|
+
}
|
|
2850
|
+
}
|
|
2851
|
+
|
|
2659
2852
|
// src/share-actions.js
|
|
2660
2853
|
import { toViewFile, viewFileName, viewFileText } from "pivotkit-core";
|
|
2661
2854
|
|
|
@@ -2738,13 +2931,14 @@ async function copyText(text, container) {
|
|
|
2738
2931
|
}
|
|
2739
2932
|
|
|
2740
2933
|
// src/version.js
|
|
2741
|
-
var VERSION = true ? "0.
|
|
2934
|
+
var VERSION = true ? "0.6.1" : "0.0.0-source";
|
|
2742
2935
|
|
|
2743
2936
|
// src/share-actions.js
|
|
2744
2937
|
var here = () => typeof location !== "undefined" ? location.href : void 0;
|
|
2745
2938
|
function shareActions(ctx, labels) {
|
|
2746
|
-
const { view, viewName, sourceId, sourceName, schemaUrl, encoded, announce, limits, linkKey } = ctx;
|
|
2747
|
-
const
|
|
2939
|
+
const { view, viewName, sourceId, sourceName, sourceParams, schemaUrl, encoded, announce, limits, linkKey } = ctx;
|
|
2940
|
+
const params = sourceParams ? { params: sourceParams } : {};
|
|
2941
|
+
const viewFile = () => viewFileText(toViewFile(view, { name: viewName ?? "", createdAt: /* @__PURE__ */ new Date(), generator: { name: "pivotkit-react", version: VERSION }, source: { id: sourceId, name: sourceName, ...params }, data: encoded, ...schemaUrl !== void 0 ? { schemaUrl } : {} }));
|
|
2748
2942
|
return {
|
|
2749
2943
|
copyLink: async () => {
|
|
2750
2944
|
const target = shareBase(ctx.shareLink, here());
|
|
@@ -2753,7 +2947,7 @@ function shareActions(ctx, labels) {
|
|
|
2753
2947
|
}
|
|
2754
2948
|
let text;
|
|
2755
2949
|
try {
|
|
2756
|
-
text = (linkNow() ?? await loadLink()).encodeViewLink(toViewFile(view, { name: viewName ?? void 0, source: { id: sourceId } }, { link: true }));
|
|
2950
|
+
text = (linkNow() ?? await loadLink()).encodeViewLink(toViewFile(view, { name: viewName ?? void 0, source: { id: sourceId, ...params } }, { link: true }));
|
|
2757
2951
|
} catch (e) {
|
|
2758
2952
|
announce(e && /** @type {any} */
|
|
2759
2953
|
e.code === "LIMIT_EXCEEDED" ? labels.toastLinkTooLong : fill(labels.error, { message: String(e) }), { tone: "error" });
|
|
@@ -2803,6 +2997,10 @@ function shareActions(ctx, labels) {
|
|
|
2803
2997
|
/** @type {import("./share.js").LoadedView} */
|
|
2804
2998
|
loaded
|
|
2805
2999
|
);
|
|
3000
|
+
const made = ready.file?.source;
|
|
3001
|
+
if (made && ready.file?.view && ctx.viaSheet?.({ id: made.id, sheet: sheetOfSource(made) }, ready.file.name || viewName || "", toViewFile(ready.file.view, { name: ready.file.name, source: made })) === "switch") {
|
|
3002
|
+
return null;
|
|
3003
|
+
}
|
|
2806
3004
|
const check = loadCheck(ready, labels, Array.isArray(ctx.sources) ? ctx.sources : []);
|
|
2807
3005
|
if (!check) {
|
|
2808
3006
|
ctx.applyLoaded(ready);
|
|
@@ -2824,8 +3022,11 @@ function shareActions(ctx, labels) {
|
|
|
2824
3022
|
|
|
2825
3023
|
// src/view-save.js
|
|
2826
3024
|
var canSaveAs = (can) => can.host || can.store;
|
|
2827
|
-
var isLoadedEntry = (t, loaded) => !!loaded && t.name === loaded.name && (t.scope === "user" ? "user" : "shared") === loaded.scope && t.at !== void 0 === loaded.store && (!loaded.store || (t.sourceId ?? null) === (loaded.storeSource ?? null));
|
|
2828
|
-
var storeEntry = (entries, name, source
|
|
3025
|
+
var isLoadedEntry = (t, loaded) => !!loaded && t.name === loaded.name && (t.scope === "user" ? "user" : "shared") === loaded.scope && t.at !== void 0 === loaded.store && (!loaded.store || (t.sourceId ?? null) === (loaded.storeSource ?? null) && (t.sheet ?? null) === (loaded.storeSheet ?? null));
|
|
3026
|
+
var storeEntry = (entries, name, source, sheet) => {
|
|
3027
|
+
const of = (s) => entries.find((t) => t.at !== void 0 && t.name === name && (t.sourceId ?? null) === (source ?? null) && (t.sheet ?? null) === s);
|
|
3028
|
+
return of(source ? sheet ?? null : null) ?? (source && sheet ? of(null) : void 0);
|
|
3029
|
+
};
|
|
2829
3030
|
function saveTarget(loaded, entries, can, empty = false) {
|
|
2830
3031
|
if (!loaded) {
|
|
2831
3032
|
return null;
|
|
@@ -2834,8 +3035,8 @@ function saveTarget(loaded, entries, can, empty = false) {
|
|
|
2834
3035
|
if (loaded.scope === "shared") {
|
|
2835
3036
|
target = can.publish ? { kind: "publish" } : canSaveAs(can) ? { kind: null, why: "saveSharedLocked" } : null;
|
|
2836
3037
|
} else if (loaded.scope === "user" && loaded.store) {
|
|
2837
|
-
const entry = storeEntry(entries, loaded.name, loaded.storeSource);
|
|
2838
|
-
target = can.store ? entry ? { kind: "store", at: entry.at, storeSource: loaded.storeSource ?? null } : { kind: "store", storeSource: can.sourceId ?? null } : null;
|
|
3038
|
+
const entry = storeEntry(entries, loaded.name, loaded.storeSource, loaded.storeSheet);
|
|
3039
|
+
target = can.store ? entry ? { kind: "store", at: entry.at, storeSource: loaded.storeSource ?? null, storeSheet: loaded.storeSheet ?? null } : { kind: "store", storeSource: can.sourceId ?? null, storeSheet: can.sheet ?? null } : null;
|
|
2839
3040
|
} else if (loaded.scope === "user") {
|
|
2840
3041
|
target = can.host ? { kind: "host" } : null;
|
|
2841
3042
|
} else {
|
|
@@ -2849,9 +3050,9 @@ function saveAsTarget(name, entries, can) {
|
|
|
2849
3050
|
}
|
|
2850
3051
|
const old = (
|
|
2851
3052
|
/** @type {T | undefined} */
|
|
2852
|
-
storeEntry(entries, name, can.sourceId) ?? storeEntry(entries, name, null)
|
|
3053
|
+
storeEntry(entries, name, can.sourceId, can.sheet) ?? storeEntry(entries, name, null, null)
|
|
2853
3054
|
);
|
|
2854
|
-
return old ? { kind: "store", at: old.at, storeSource: old.sourceId ?? null, replaces: old } : { kind: "store", storeSource: can.sourceId ?? null, replaces: null };
|
|
3055
|
+
return old ? { kind: "store", at: old.at, storeSource: old.sourceId ?? null, storeSheet: old.sheet ?? null, replaces: old } : { kind: "store", storeSource: can.sourceId ?? null, storeSheet: can.sheet ?? null, replaces: null };
|
|
2855
3056
|
}
|
|
2856
3057
|
|
|
2857
3058
|
// src/view-store.js
|
|
@@ -2872,9 +3073,13 @@ function readAll(raw) {
|
|
|
2872
3073
|
}
|
|
2873
3074
|
return parseTemplates(raw).templates;
|
|
2874
3075
|
}
|
|
2875
|
-
function storedViews(raw, sourceId) {
|
|
2876
|
-
return readAll(raw).map((t, at) =>
|
|
3076
|
+
function storedViews(raw, sourceId, shown = { sheet: null, sheets: [] }) {
|
|
3077
|
+
return readAll(raw).map((t, at) => {
|
|
3078
|
+
const sheet = sheetOfSource(t.source);
|
|
3079
|
+
return { name: t.name, view: t.view, at, ...t.source?.id ? { sourceId: t.source.id } : {}, ...sheet ? { sheet } : {} };
|
|
3080
|
+
}).filter((t) => listedFor(t, { id: sourceId, ...shown }));
|
|
2877
3081
|
}
|
|
3082
|
+
var sourceOf2 = (id, sheet) => id ? { id, ...sheet ? { params: { sheet } } : {} } : void 0;
|
|
2878
3083
|
function changedViews(raw, change, message) {
|
|
2879
3084
|
const all = readAll(raw);
|
|
2880
3085
|
let next = all;
|
|
@@ -2890,20 +3095,23 @@ function changedViews(raw, change, message) {
|
|
|
2890
3095
|
if (old?.name !== change.name) {
|
|
2891
3096
|
throw new Error(message("changed", 0));
|
|
2892
3097
|
}
|
|
3098
|
+
const source = old.source?.id && old.source.id === change.sourceId ? sourceOf2(change.sourceId, change.sheet) : old.source;
|
|
2893
3099
|
next = all.map((t, i) => i === change.replace ? { name: old.name, view: (
|
|
2894
3100
|
/** @type {Record<string, unknown>} */
|
|
2895
3101
|
change.view
|
|
2896
|
-
), ...
|
|
3102
|
+
), ...source ? { source } : {} } : t);
|
|
2897
3103
|
} else if (saving) {
|
|
2898
3104
|
const id = change.sourceId;
|
|
2899
|
-
|
|
3105
|
+
const sheet = id ? change.sheet ?? null : null;
|
|
3106
|
+
next = next.filter((t) => t.name !== change.name || (t.source?.id ?? void 0) !== id || sheetOfSource(t.source) !== sheet);
|
|
3107
|
+
const source = sourceOf2(id, sheet);
|
|
2900
3108
|
next.push({ name: (
|
|
2901
3109
|
/** @type {string} */
|
|
2902
3110
|
change.name
|
|
2903
3111
|
), view: (
|
|
2904
3112
|
/** @type {Record<string, unknown>} */
|
|
2905
3113
|
change.view
|
|
2906
|
-
), ...
|
|
3114
|
+
), ...source ? { source } : {} });
|
|
2907
3115
|
if (next.length > VIEW_STORE_LIMITS.count) {
|
|
2908
3116
|
throw new Error(message("count", VIEW_STORE_LIMITS.count));
|
|
2909
3117
|
}
|
|
@@ -3238,23 +3446,33 @@ function viewActions(ctx, labels) {
|
|
|
3238
3446
|
const save = (target, name) => {
|
|
3239
3447
|
const key = ctx.viewKey;
|
|
3240
3448
|
return run(
|
|
3241
|
-
() => target.kind === "publish" ? ctx.onPublish(name, ctx.view) : target.kind === "host" ? ctx.onSave(name, ctx.view, { scope: "user" }) : write({ name, view: ctx.view, sourceId: ctx.sourceId, replace: target.at }),
|
|
3449
|
+
() => target.kind === "publish" ? ctx.onPublish(name, ctx.view, { source: ctx.source }) : target.kind === "host" ? ctx.onSave(name, ctx.view, { scope: "user", source: ctx.source }) : write({ name, view: ctx.view, sourceId: ctx.sourceId, sheet: ctx.sheet, replace: target.at }),
|
|
3242
3450
|
labels.toastSaved,
|
|
3243
3451
|
labels.toastSaveFailed,
|
|
3244
3452
|
labels.toastSaveRejected,
|
|
3245
3453
|
name
|
|
3246
|
-
).then((ok) => ok && ctx.onSaved({ name, scope: target.kind === "publish" ? "shared" : "user", store: target.kind === "store", storeSource: target.kind === "store" ? target.storeSource : null }, key));
|
|
3454
|
+
).then((ok) => ok && ctx.onSaved({ name, scope: target.kind === "publish" ? "shared" : "user", store: target.kind === "store", storeSource: target.kind === "store" ? target.storeSource : null, storeSheet: target.kind === "store" ? storedSheet(target, ctx) : null }, key));
|
|
3247
3455
|
};
|
|
3248
3456
|
return {
|
|
3249
3457
|
// Save and Save as: where to is view-save.js's (the host's onSaveTemplate wins over the store)
|
|
3250
3458
|
save,
|
|
3251
3459
|
remove: ctx.onDelete || ctx.store ? (t) => run(() => t.at !== void 0 ? write({ remove: t.at, removeName: t.name }) : ctx.onDelete(t.name, { scope: t.scope }), labels.toastDeleted, labels.toastDeleteFailed, labels.toastDeleteRejected, t.name) : null,
|
|
3252
|
-
|
|
3460
|
+
// a view of the menu is published with the data it was made for, which is the data shown unless
|
|
3461
|
+
// the entry names other data (a view of the browser store kept for another file or sheet)
|
|
3462
|
+
publish: ctx.onPublish ? (t) => run(() => ctx.onPublish(t.name, ctx.normalized(t.view), { source: entrySource(t, ctx.source) }), labels.toastPublished, labels.toastPublishFailed, labels.toastPublishRejected, t.name) : null
|
|
3253
3463
|
};
|
|
3254
3464
|
}
|
|
3465
|
+
var entrySource = (t, shown) => {
|
|
3466
|
+
const id = t.sourceId ?? t.sheetOf ?? t.fileSource;
|
|
3467
|
+
if (!id) {
|
|
3468
|
+
return shown ?? null;
|
|
3469
|
+
}
|
|
3470
|
+
return { id, ...shown?.id === id && shown.name ? { name: shown.name } : {}, ...t.sheet ? { params: { sheet: t.sheet } } : {} };
|
|
3471
|
+
};
|
|
3472
|
+
var storedSheet = (target, ctx) => target.storeSource && target.storeSource === ctx.sourceId ? ctx.sheet ?? null : target.storeSheet ?? null;
|
|
3255
3473
|
function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
3256
3474
|
const { save, remove: onDelete, publish: onPublish } = viewActions(actions, labels);
|
|
3257
|
-
const can = { host: Boolean(actions.onSave), store: Boolean(actions.store), publish: Boolean(onPublish), sourceId: actions.sourceId };
|
|
3475
|
+
const can = { host: Boolean(actions.onSave), store: Boolean(actions.store), publish: Boolean(onPublish), sourceId: actions.sourceId, sheet: actions.sheet ?? null };
|
|
3258
3476
|
const target = saveTarget(actions.loaded, templates, can, actions.empty);
|
|
3259
3477
|
const store = actions.store && !actions.onSave;
|
|
3260
3478
|
const [asking, setAsking] = useState5(
|
|
@@ -3277,6 +3495,9 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
3277
3495
|
id,
|
|
3278
3496
|
testId: `saved-view-${t.name}`,
|
|
3279
3497
|
text: t.name,
|
|
3498
|
+
// while a workbook's sheet is shown, a view made on a sheet says which (two views of a
|
|
3499
|
+
// name can be kept, one per sheet; one of another sheet reads that sheet when opened)
|
|
3500
|
+
hint: t.sheet && actions.sheet ? fill(labels.viewSheet, { sheet: t.sheet }) : void 0,
|
|
3280
3501
|
icon: "bookmark",
|
|
3281
3502
|
current: isLoadedEntry(t, actions.loaded),
|
|
3282
3503
|
closes: true,
|
|
@@ -3407,7 +3628,8 @@ function ExportOption({ icon, text, info, onSelect, testId, disabled, reason })
|
|
|
3407
3628
|
info
|
|
3408
3629
|
), name: text })) : option;
|
|
3409
3630
|
}
|
|
3410
|
-
function ExportPanel({ labels, onExport, chartReady, display, empty = false, prepare, close }) {
|
|
3631
|
+
function ExportPanel({ labels, onExport, chartReady, display, empty = false, dataExport, prepare, close }) {
|
|
3632
|
+
const source = dataExport ? dataExportFor(dataExport.exportData, dataExport.encoded).source : false;
|
|
3411
3633
|
useEffect3(() => {
|
|
3412
3634
|
prepare();
|
|
3413
3635
|
}, [prepare]);
|
|
@@ -3416,7 +3638,7 @@ function ExportPanel({ labels, onExport, chartReady, display, empty = false, pre
|
|
|
3416
3638
|
onExport(kind);
|
|
3417
3639
|
};
|
|
3418
3640
|
const off = empty ? { disabled: true, reason: labels.exportNeedsField } : {};
|
|
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" })));
|
|
3641
|
+
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" })), source ? /* @__PURE__ */ React7.createElement(Section, { title: labels.exportDataGroup }, /* @__PURE__ */ React7.createElement(ExportOption, { icon: "file", text: labels.exportDataCsv, info: "exportDataCsv", onSelect: run("data-csv"), testId: "export-data-csv" }), /* @__PURE__ */ React7.createElement(ExportOption, { icon: "file", text: labels.exportDataJson, info: "exportDataJson", onSelect: run("data-json"), testId: "export-data-json" })) : null);
|
|
3420
3642
|
}
|
|
3421
3643
|
|
|
3422
3644
|
// src/drill-panel.jsx
|
|
@@ -3624,7 +3846,7 @@ function reportTokens(root, report, chart) {
|
|
|
3624
3846
|
const tokens = lightTokens(root, report.REPORT_TOKENS, () => chart.tokenLengths(root, [...chart.LENGTH_TOKENS, ...report.REPORT_LENGTHS]));
|
|
3625
3847
|
return Object.keys(tokens).length ? tokens : void 0;
|
|
3626
3848
|
}
|
|
3627
|
-
async function runExport(kind, { fileName, result, locale, labels, limits, root, chartRef, announce, onExport, title, source, loadECharts }) {
|
|
3849
|
+
async function runExport(kind, { fileName, result, encoded, exportData, locale, labels, limits, root, chartRef, announce, onExport, title, source, loadECharts }) {
|
|
3628
3850
|
labels = menuLabels(labels);
|
|
3629
3851
|
const base = safeFileName(fileName);
|
|
3630
3852
|
const doc = root.current?.ownerDocument;
|
|
@@ -3638,6 +3860,29 @@ async function runExport(kind, { fileName, result, locale, labels, limits, root,
|
|
|
3638
3860
|
}
|
|
3639
3861
|
return;
|
|
3640
3862
|
}
|
|
3863
|
+
if (kind === "data-csv" || kind === "data-json") {
|
|
3864
|
+
const data = encoded ?? result?.encoded;
|
|
3865
|
+
if (!data) {
|
|
3866
|
+
return;
|
|
3867
|
+
}
|
|
3868
|
+
const scope = dataExportFor(exportData, data);
|
|
3869
|
+
if (!scope.source) {
|
|
3870
|
+
return;
|
|
3871
|
+
}
|
|
3872
|
+
const m2 = exporters ?? await loadExporters();
|
|
3873
|
+
const csv = kind === "data-csv";
|
|
3874
|
+
const file2 = `${base}-data.${csv ? "csv" : "json"}`;
|
|
3875
|
+
const options = { ...limits ? { limits } : {}, ...scope.columns ? { columns: scope.columns } : {} };
|
|
3876
|
+
const blob = csv ? new Blob(
|
|
3877
|
+
/** @type {BlobPart[]} */
|
|
3878
|
+
m2.dataToCsvParts(data, options),
|
|
3879
|
+
{ type: "text/csv;charset=utf-8" }
|
|
3880
|
+
) : new Blob([m2.dataToJson(data, options)], { type: "application/json" });
|
|
3881
|
+
if (deliver(blob, { kind, fileName: file2, doc, onExport })) {
|
|
3882
|
+
announce(fill(labels.toastExported, { file: file2 }));
|
|
3883
|
+
}
|
|
3884
|
+
return;
|
|
3885
|
+
}
|
|
3641
3886
|
if (!result) {
|
|
3642
3887
|
return;
|
|
3643
3888
|
}
|
|
@@ -3710,19 +3955,28 @@ async function runExport(kind, { fileName, result, locale, labels, limits, root,
|
|
|
3710
3955
|
var clampSize = (px) => Math.max(100, Math.min(8e3, Math.round(Number(px) || 0)));
|
|
3711
3956
|
|
|
3712
3957
|
// src/drill-export.js
|
|
3958
|
+
function pick(row, columns) {
|
|
3959
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
3960
|
+
for (const c of columns) {
|
|
3961
|
+
out[c.name] = row[c.name];
|
|
3962
|
+
}
|
|
3963
|
+
return out;
|
|
3964
|
+
}
|
|
3713
3965
|
function rowsText({ shown, count }, labels, locale) {
|
|
3714
3966
|
return shown < count ? fill(labels.drillPart, { shown: shown.toLocaleString(locale), count: count.toLocaleString(locale) }) : plural(labels.drillCount, count, { lang: labels.lang, locale });
|
|
3715
3967
|
}
|
|
3716
|
-
async function exportDrill(kind, { drill, encoded, labels, onExport, announce, root }) {
|
|
3968
|
+
async function exportDrill(kind, { drill, encoded, labels, columns, onExport, announce, root }) {
|
|
3717
3969
|
const { locale } = drill;
|
|
3718
3970
|
const part = { shown: drill.rows.length, count: drill.count };
|
|
3719
3971
|
const rows = rowsText(part, labels, locale);
|
|
3720
3972
|
const base = safeFileName(drill.name);
|
|
3721
3973
|
try {
|
|
3722
3974
|
const m = exportersNow() ?? await loadExporters();
|
|
3975
|
+
const picked = pickColumns(drill.columns.map((c) => c.name), columns);
|
|
3976
|
+
const shown = picked.map((c) => drill.columns[c]);
|
|
3723
3977
|
if (kind === "drill-copy" || kind === "drill-json") {
|
|
3724
3978
|
const json = kind === "drill-json";
|
|
3725
|
-
const text = json ? JSON.stringify(Array.from(drill.indices, (i) => decodeRow(encoded, i)), null, 2) : m.toTsv([
|
|
3979
|
+
const text = json ? JSON.stringify(Array.from(drill.indices, (i) => columns ? pick(decodeRow(encoded, i), shown) : decodeRow(encoded, i)), null, 2) : m.toTsv([shown.map((c) => c.label ?? c.name), ...drill.rows.map((row) => picked.map((c) => row[c]))]);
|
|
3726
3980
|
const done = await copyOut(text, { kind, fileName: `${base}.${json ? "json" : "tsv"}`, type: json ? "application/json" : "text/tab-separated-values", container: root, onExport, rows: part });
|
|
3727
3981
|
if (done !== "kept") {
|
|
3728
3982
|
announce(done === "copied" ? fill(json ? labels.drillCopiedJson : labels.drillCopied, { rows }) : labels.toastCopyBlocked, done === "copied" ? void 0 : { tone: "error" });
|
|
@@ -3730,8 +3984,8 @@ async function exportDrill(kind, { drill, encoded, labels, onExport, announce, r
|
|
|
3730
3984
|
return;
|
|
3731
3985
|
}
|
|
3732
3986
|
const xlsx = kind === "drill-xlsx";
|
|
3733
|
-
const fields = Object.fromEntries(
|
|
3734
|
-
const options = { locale, formats: drill.formats, labels: { fields, true: labels.core.true, false: labels.core.false } };
|
|
3987
|
+
const fields = Object.fromEntries(shown.map((c) => [c.name, c.label ?? c.name]));
|
|
3988
|
+
const options = { locale, formats: drill.formats, columns: shown.map((c) => c.name), labels: { fields, true: labels.core.true, false: labels.core.false } };
|
|
3735
3989
|
const file = `${base}.${xlsx ? "xlsx" : "csv"}`;
|
|
3736
3990
|
const bytes = xlsx ? m.rowsToXlsx(encoded, drill.indices, { ...options, sheetName: drill.name }) : m.rowsToCsvBytes(encoded, drill.indices, options);
|
|
3737
3991
|
const blob = new Blob([
|
|
@@ -3803,7 +4057,9 @@ function drillOf({ result, rowPath, colPath, count, indices, formatOf, nameOf, i
|
|
|
3803
4057
|
}
|
|
3804
4058
|
|
|
3805
4059
|
// src/drill-panel.jsx
|
|
3806
|
-
function DrillPanel({ drill: source, onClose, labels, locale, exportContext }) {
|
|
4060
|
+
function DrillPanel({ drill: source, onClose, labels, locale, exportContext: context }) {
|
|
4061
|
+
const columns = context ? dataExportFor(context.exportData, context.encoded).columns : void 0;
|
|
4062
|
+
const exportContext = context && columns?.length !== 0 ? context : void 0;
|
|
3807
4063
|
const id = useId6();
|
|
3808
4064
|
const drill = useMemo4(() => source ? drillOf(source, labels) : null, [source, labels]);
|
|
3809
4065
|
const panel = useRef4(
|
|
@@ -3826,7 +4082,7 @@ function DrillPanel({ drill: source, onClose, labels, locale, exportContext }) {
|
|
|
3826
4082
|
const run = (kind, close) => () => {
|
|
3827
4083
|
close();
|
|
3828
4084
|
if (exportContext) {
|
|
3829
|
-
void exportDrill(kind, { drill, labels, ...exportContext, root: exportContext.root.current });
|
|
4085
|
+
void exportDrill(kind, { drill, labels, ...exportContext, columns, root: exportContext.root.current });
|
|
3830
4086
|
}
|
|
3831
4087
|
};
|
|
3832
4088
|
return /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement("div", { className: "pk-scrim pk-drill-scrim", onClick: onClose, "aria-hidden": "true" }), /* @__PURE__ */ React8.createElement(
|