pivotkit-react 0.6.0 → 0.7.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 +114 -1
- package/dist/chunks/{chunk-2RAVX4DO.js → chunk-4WZ5F2TJ.js} +57 -33
- package/dist/chunks/{chunk-RIOSIYGC.js → chunk-JAOOFDNR.js} +27 -5
- package/dist/chunks/{chunk-7LERNGUW.js → chunk-ZK5RVCHP.js} +14 -2
- package/dist/chunks/{report-run-BZBFOMPF.js → report-run-HU4WPOB7.js} +3 -1
- package/dist/import-ui.js +13 -24
- package/dist/index.js +61 -54
- package/dist/labels.js +1 -1
- package/dist/menus.js +388 -151
- package/dist/styles.css +4 -1
- package/package.json +8 -4
- package/styles.css.d.ts +3 -0
- package/types/drill-export.d.ts +3 -2
- package/types/drill-panel.d.ts +4 -2
- package/types/export-run.d.ts +16 -3
- package/types/export-scope.d.ts +47 -0
- package/types/import-host.d.ts +8 -5
- package/types/import-labels.d.ts +14 -3
- package/types/import-run.d.ts +0 -8
- package/types/import-ui.d.ts +5 -2
- package/types/index.d.ts +14 -8
- package/types/menu-fields.d.ts +9 -0
- package/types/menu-ops.d.ts +23 -0
- package/types/menus.d.ts +1 -1
- package/types/names.d.ts +22 -8
- package/types/print-frame.d.ts +32 -3
- package/types/report-run.d.ts +5 -0
- package/types/theme-tokens.d.ts +17 -0
- package/types/toolbar-panels.d.ts +15 -6
- package/types/use-export.d.ts +8 -4
- package/types/view-history.d.ts +15 -0
- package/types/light-tokens.d.ts +0 -16
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,8 +57,10 @@ import {
|
|
|
55
57
|
viewFromObject,
|
|
56
58
|
viewFromText,
|
|
57
59
|
wholeYears,
|
|
58
|
-
withLinkParam
|
|
59
|
-
|
|
60
|
+
withLinkParam,
|
|
61
|
+
yearOf,
|
|
62
|
+
yearText
|
|
63
|
+
} from "./chunks/chunk-4WZ5F2TJ.js";
|
|
60
64
|
import {
|
|
61
65
|
addMenuTexts,
|
|
62
66
|
hasMenuTexts,
|
|
@@ -77,8 +81,9 @@ import {
|
|
|
77
81
|
rootOf,
|
|
78
82
|
stopAfter,
|
|
79
83
|
useFormName,
|
|
84
|
+
useIsoLayoutEffect,
|
|
80
85
|
useModal
|
|
81
|
-
} from "./chunks/chunk-
|
|
86
|
+
} from "./chunks/chunk-JAOOFDNR.js";
|
|
82
87
|
import {
|
|
83
88
|
fill,
|
|
84
89
|
hostFailure,
|
|
@@ -99,7 +104,7 @@ import React, { useMemo, useState } from "react";
|
|
|
99
104
|
import { LIMITS, fieldItems, fieldLabel } from "pivotkit-core";
|
|
100
105
|
|
|
101
106
|
// src/menu-ops.js
|
|
102
|
-
import { CATALOG, MATCH_DEFAULTS, computePivot, isFormat } from "pivotkit-core";
|
|
107
|
+
import { CATALOG, MATCH_DEFAULTS, MAX_DATE_MS, computePivot, isFormat } from "pivotkit-core";
|
|
103
108
|
var COUNTING = /* @__PURE__ */ new Set(["count", "countUnique", "listUnique"]);
|
|
104
109
|
var unitOf = (agg) => COUNTING.has(agg) ? "count" : "field";
|
|
105
110
|
function updateValue(view, index, patch, options = {}) {
|
|
@@ -235,8 +240,8 @@ function yearsCombined(compared, all) {
|
|
|
235
240
|
let kept = new Set(all);
|
|
236
241
|
for (const f of compared) {
|
|
237
242
|
const [a, b] = (
|
|
238
|
-
/** @type {[
|
|
239
|
-
wholeYears(f.value, f.value2)
|
|
243
|
+
/** @type {[number, number]} */
|
|
244
|
+
wholeYears(f.value, f.value2)
|
|
240
245
|
);
|
|
241
246
|
kept = new Set([...kept].filter((y) => (a <= y && y <= b) !== f.not));
|
|
242
247
|
}
|
|
@@ -247,7 +252,10 @@ function yearRules(field, years, all, blanks = "exclude") {
|
|
|
247
252
|
if (!years.length || years.length === all.length) {
|
|
248
253
|
return [];
|
|
249
254
|
}
|
|
250
|
-
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
|
+
};
|
|
251
259
|
const rule = (not, from, to) => ({ field, type: "compare", op: "between", value: day(from, false), value2: day(to, true), not, blanks });
|
|
252
260
|
const rules = [rule(false, years[0], years[years.length - 1])];
|
|
253
261
|
for (let i = 1; i < years.length; i++) {
|
|
@@ -382,6 +390,27 @@ function rowsInRange(range, dict, counts) {
|
|
|
382
390
|
}
|
|
383
391
|
return rows;
|
|
384
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
|
+
}
|
|
385
414
|
|
|
386
415
|
// src/filter.jsx
|
|
387
416
|
var FILTER_LIST_MAX = 300;
|
|
@@ -1143,7 +1172,7 @@ function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, sea
|
|
|
1143
1172
|
const top = nav.stack[nav.stack.length - 1];
|
|
1144
1173
|
setNav({ stack: nav.stack.slice(0, -1), focus: focus ?? top?.from ?? null });
|
|
1145
1174
|
};
|
|
1146
|
-
const
|
|
1175
|
+
const pick2 = (choice) => {
|
|
1147
1176
|
if (choice.open) {
|
|
1148
1177
|
choice.run?.();
|
|
1149
1178
|
open(choice.open, choice.backTo ?? `item:${choice.id}`);
|
|
@@ -1200,9 +1229,9 @@ function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, sea
|
|
|
1200
1229
|
}
|
|
1201
1230
|
}
|
|
1202
1231
|
}
|
|
1203
|
-
)) : 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)));
|
|
1204
1233
|
};
|
|
1205
|
-
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());
|
|
1206
1235
|
}
|
|
1207
1236
|
function useLater(wait = 450) {
|
|
1208
1237
|
const timer = useRef(
|
|
@@ -1383,6 +1412,9 @@ function NumberField({ value, onChange, problem, label, testId, className = "pk-
|
|
|
1383
1412
|
}
|
|
1384
1413
|
)), problem ? /* @__PURE__ */ React4.createElement("p", { id, className: "pk-form-problem", "data-testid": `${testId}-problem` }, problem) : null);
|
|
1385
1414
|
}
|
|
1415
|
+
function Radio(props) {
|
|
1416
|
+
return /* @__PURE__ */ React4.createElement("input", { ...props, type: "radio", onClick: (e) => e.currentTarget.focus() });
|
|
1417
|
+
}
|
|
1386
1418
|
var fieldKeys = ({ now, restore, back }) => (e) => {
|
|
1387
1419
|
if (e.key === "Enter") {
|
|
1388
1420
|
e.preventDefault();
|
|
@@ -1410,6 +1442,17 @@ function measuresOf(view, types, labels, ref) {
|
|
|
1410
1442
|
|
|
1411
1443
|
// src/filter-level.jsx
|
|
1412
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
|
+
});
|
|
1413
1456
|
var capital = (text, locale) => text.charAt(0).toLocaleUpperCase(locale) + text.slice(1);
|
|
1414
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);
|
|
1415
1458
|
var rowKind = (f) => !editable(f) ? "fixed" : f.type === "value" ? "total" : f.type === "text" ? "name" : "item";
|
|
@@ -1512,7 +1555,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1512
1555
|
}
|
|
1513
1556
|
};
|
|
1514
1557
|
const rowsOf = (range) => range ? rowsInRange(range, column.dict, counts) : 0;
|
|
1515
|
-
const reaches = (r) => r !== null && r.from !== null && r.from
|
|
1558
|
+
const reaches = (r) => r !== null && r.from !== null && dayOnOrBefore(r.from, latestDay);
|
|
1516
1559
|
const reach = (unit) => {
|
|
1517
1560
|
for (let n = 1; n <= REACH[unit]; n++) {
|
|
1518
1561
|
if (reaches(datesOf({ unit, count: n }))) {
|
|
@@ -1582,9 +1625,8 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1582
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) })));
|
|
1583
1626
|
};
|
|
1584
1627
|
const radio = (id, checked, onPick, name, children, described = true) => /* @__PURE__ */ React5.createElement("label", { className: "pk-radio pk-quick" }, /* @__PURE__ */ React5.createElement(
|
|
1585
|
-
|
|
1628
|
+
Radio,
|
|
1586
1629
|
{
|
|
1587
|
-
type: "radio",
|
|
1588
1630
|
name: groupName,
|
|
1589
1631
|
checked,
|
|
1590
1632
|
onChange: onPick,
|
|
@@ -1700,13 +1742,14 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1700
1742
|
const periodStart = fk.months ? Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), 1) : Date.UTC(today.getUTCFullYear(), 0, 1);
|
|
1701
1743
|
const [anchorOutside] = useState3(() => span.max < periodStart || anchor !== "today");
|
|
1702
1744
|
const anchorKind = ["today", "latest", "first"].includes(anchor) ? anchor : "date";
|
|
1703
|
-
const [day, setDay] = useState3(anchorKind === "date" ? anchor
|
|
1704
|
-
const
|
|
1745
|
+
const [day, setDay] = useState3(dateInputValue(anchorKind === "date" ? anchor : latestDay));
|
|
1746
|
+
const dayIso = dateFromInput(day);
|
|
1747
|
+
const dayWhole = dayIso !== null;
|
|
1705
1748
|
const [seenAnchor, setSeenAnchor] = useState3(anchor);
|
|
1706
1749
|
if (anchor !== seenAnchor) {
|
|
1707
1750
|
setSeenAnchor(anchor);
|
|
1708
1751
|
if (anchorKind === "date") {
|
|
1709
|
-
setDay(anchor
|
|
1752
|
+
setDay(dateInputValue(anchor));
|
|
1710
1753
|
}
|
|
1711
1754
|
}
|
|
1712
1755
|
const dayHint = `${anchorId}-hint`;
|
|
@@ -1716,7 +1759,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1716
1759
|
commit(setAnchor(view, field, a), note);
|
|
1717
1760
|
}
|
|
1718
1761
|
};
|
|
1719
|
-
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(
|
|
1720
1763
|
"input",
|
|
1721
1764
|
{
|
|
1722
1765
|
type: "date",
|
|
@@ -1724,13 +1767,14 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1724
1767
|
value: day,
|
|
1725
1768
|
onChange: (e) => {
|
|
1726
1769
|
setDay(e.target.value);
|
|
1727
|
-
|
|
1728
|
-
|
|
1770
|
+
const iso = dateFromInput(e.target.value);
|
|
1771
|
+
if (iso) {
|
|
1772
|
+
setAnchorTo(iso);
|
|
1729
1773
|
}
|
|
1730
1774
|
},
|
|
1731
1775
|
onBlur: () => {
|
|
1732
1776
|
if (!dayWhole) {
|
|
1733
|
-
setDay(anchor
|
|
1777
|
+
setDay(dateInputValue(anchor));
|
|
1734
1778
|
}
|
|
1735
1779
|
},
|
|
1736
1780
|
"aria-label": labels.anchorDay,
|
|
@@ -1738,7 +1782,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1738
1782
|
"aria-describedby": dayWhole ? void 0 : dayHint,
|
|
1739
1783
|
"data-testid": "quick-anchor-date"
|
|
1740
1784
|
}
|
|
1741
|
-
) : 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);
|
|
1742
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(
|
|
1743
1787
|
"input",
|
|
1744
1788
|
{
|
|
@@ -1765,8 +1809,8 @@ function YearsCombined({ ctx, years, on }) {
|
|
|
1765
1809
|
};
|
|
1766
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) => {
|
|
1767
1811
|
const pressed = on.includes(y.year);
|
|
1768
|
-
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,
|
|
1769
|
-
})), 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);
|
|
1770
1814
|
}
|
|
1771
1815
|
function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
1772
1816
|
const [open, setOpen] = useState3(false);
|
|
@@ -1787,7 +1831,7 @@ function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
|
1787
1831
|
setOpen(true);
|
|
1788
1832
|
};
|
|
1789
1833
|
const close = () => setOpen(false);
|
|
1790
|
-
const
|
|
1834
|
+
const pick2 = (item) => {
|
|
1791
1835
|
close();
|
|
1792
1836
|
onChange(String(item.value));
|
|
1793
1837
|
};
|
|
@@ -1799,7 +1843,7 @@ function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
|
1799
1843
|
} else if (e.key === "Enter") {
|
|
1800
1844
|
e.preventDefault();
|
|
1801
1845
|
if (matching[active]) {
|
|
1802
|
-
|
|
1846
|
+
pick2(matching[active]);
|
|
1803
1847
|
}
|
|
1804
1848
|
} else if (e.key === "Escape") {
|
|
1805
1849
|
e.preventDefault();
|
|
@@ -1858,14 +1902,14 @@ function ItemPicker({ items, value, onChange, label, testId, labels, locale }) {
|
|
|
1858
1902
|
"aria-selected": String(item.value) === value,
|
|
1859
1903
|
className: `pk-picker-option${i === active ? " pk-picker-active" : ""}`,
|
|
1860
1904
|
onMouseMove: () => setActive(i),
|
|
1861
|
-
onClick: () =>
|
|
1905
|
+
onClick: () => pick2(item),
|
|
1862
1906
|
"data-testid": "picker-option"
|
|
1863
1907
|
},
|
|
1864
1908
|
/* @__PURE__ */ React5.createElement("span", null, item.label),
|
|
1865
1909
|
/* @__PURE__ */ React5.createElement("span", { className: "pk-count" }, item.count.toLocaleString(locale))
|
|
1866
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) }))));
|
|
1867
1911
|
}
|
|
1868
|
-
function ItemRule({ rule, ctx, apply, first }) {
|
|
1912
|
+
function ItemRule({ rule, ctx, apply, unset, first }) {
|
|
1869
1913
|
const { field, labels, locale, fk, items } = ctx;
|
|
1870
1914
|
const narrow = useContext3(LayerContext).size === "narrow";
|
|
1871
1915
|
const words = fk.dates ? labels.dateOps : labels.valueOps;
|
|
@@ -1881,6 +1925,7 @@ function ItemRule({ rule, ctx, apply, first }) {
|
|
|
1881
1925
|
unit: ranged?.unit ?? "year"
|
|
1882
1926
|
}));
|
|
1883
1927
|
const later = useLater();
|
|
1928
|
+
const latest = useLatest({ rule, apply, unset });
|
|
1884
1929
|
const formName = useFormName();
|
|
1885
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);
|
|
1886
1931
|
const entryOf = (x) => {
|
|
@@ -1897,7 +1942,9 @@ function ItemRule({ rule, ctx, apply, first }) {
|
|
|
1897
1942
|
const run = () => {
|
|
1898
1943
|
const entry = entryOf(next);
|
|
1899
1944
|
if (entry) {
|
|
1900
|
-
apply(entry);
|
|
1945
|
+
latest.current.apply(entry);
|
|
1946
|
+
} else if (latest.current.rule && emptied(patch)) {
|
|
1947
|
+
latest.current.unset();
|
|
1901
1948
|
}
|
|
1902
1949
|
};
|
|
1903
1950
|
if (wait) {
|
|
@@ -1950,11 +1997,12 @@ function ItemRule({ rule, ctx, apply, first }) {
|
|
|
1950
1997
|
}
|
|
1951
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));
|
|
1952
1999
|
}
|
|
1953
|
-
function TotalRule({ rule, ctx, apply, first }) {
|
|
2000
|
+
function TotalRule({ rule, ctx, apply, unset, first }) {
|
|
1954
2001
|
const { view, types, labels, locale } = ctx;
|
|
1955
2002
|
const { choices, names } = measuresOf(view, types, labels, rule?.by);
|
|
1956
2003
|
const [s, setS] = useState3(() => ({ by: choiceIndex(choices, rule?.by), op: rule ? ruleOp(rule) : ">", a: numberText(rule?.value, locale), b: numberText(rule?.value2, locale) }));
|
|
1957
2004
|
const later = useLater();
|
|
2005
|
+
const latest = useLatest({ rule, apply, unset });
|
|
1958
2006
|
const formName = useFormName();
|
|
1959
2007
|
const change = (patch, wait = false) => {
|
|
1960
2008
|
const next = { ...s, ...patch };
|
|
@@ -1963,7 +2011,9 @@ function TotalRule({ rule, ctx, apply, first }) {
|
|
|
1963
2011
|
const [a, b] = [parseNumber(next.a, locale), parseNumber(next.b, locale)];
|
|
1964
2012
|
if (a !== null && (!twin(next.op) || b !== null)) {
|
|
1965
2013
|
const by = choices[next.by];
|
|
1966
|
-
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();
|
|
1967
2017
|
}
|
|
1968
2018
|
};
|
|
1969
2019
|
if (wait) {
|
|
@@ -2042,6 +2092,7 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2042
2092
|
/** @type {"item" | "total" | "name" | null} */
|
|
2043
2093
|
null
|
|
2044
2094
|
);
|
|
2095
|
+
const [added, setAdded] = useState3(0);
|
|
2045
2096
|
const [held, setHeld] = useState3(
|
|
2046
2097
|
/** @type {Array<{ at: number, kind: "item" | "total" | "name", blanks?: string }>} */
|
|
2047
2098
|
[]
|
|
@@ -2071,6 +2122,14 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2071
2122
|
null
|
|
2072
2123
|
);
|
|
2073
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
|
+
});
|
|
2074
2133
|
useEffect2(() => {
|
|
2075
2134
|
if (focusAdd.current) {
|
|
2076
2135
|
focusAdd.current = false;
|
|
@@ -2093,7 +2152,14 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2093
2152
|
}
|
|
2094
2153
|
}
|
|
2095
2154
|
}
|
|
2096
|
-
}, [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
|
+
};
|
|
2097
2163
|
const kinds = (
|
|
2098
2164
|
/** @type {Array<"item" | "total" | "name">} */
|
|
2099
2165
|
["item", "total", "name"].filter((k) => k === "item" ? Boolean(fk.item) : k === "name" ? Boolean(nameKind) : true)
|
|
@@ -2118,25 +2184,33 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2118
2184
|
};
|
|
2119
2185
|
const row = (rule, kind, i, isHeld = false) => {
|
|
2120
2186
|
const Row = ROWS[kind];
|
|
2187
|
+
const key = `${gen}:${i}`;
|
|
2121
2188
|
const apply = (entry) => {
|
|
2189
|
+
if (removed.current.has(key)) {
|
|
2190
|
+
return;
|
|
2191
|
+
}
|
|
2122
2192
|
const was = isHeld ? held.find((h) => h.at === i) : void 0;
|
|
2123
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;
|
|
2124
|
-
|
|
2194
|
+
const current = now.current.gen === gen;
|
|
2195
|
+
if (isHeld && current) {
|
|
2125
2196
|
setHeld(held.filter((h) => h.at !== i));
|
|
2126
|
-
} else if (!rule) {
|
|
2197
|
+
} else if (!rule && current) {
|
|
2127
2198
|
setDraft(null);
|
|
2128
2199
|
}
|
|
2129
2200
|
const before = isHeld ? rows.slice(i + 1).find((x) => x.rule)?.rule ?? null : null;
|
|
2130
|
-
commitOwn(setRule(view, field, rule, own2, before));
|
|
2201
|
+
commitOwn(setRule(now.current.view, field, rule, own2, before));
|
|
2131
2202
|
};
|
|
2132
2203
|
const unset = () => {
|
|
2133
|
-
if (rule) {
|
|
2134
|
-
|
|
2135
|
-
|
|
2136
|
-
|
|
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));
|
|
2137
2210
|
}
|
|
2138
2211
|
};
|
|
2139
2212
|
const remove = () => {
|
|
2213
|
+
removed.current.add(key);
|
|
2140
2214
|
focusAdd.current = true;
|
|
2141
2215
|
if (rule) {
|
|
2142
2216
|
commit(setRule(view, field, rule, null), note);
|
|
@@ -2155,7 +2229,7 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2155
2229
|
const result = rule ? results.get(rule) : null;
|
|
2156
2230
|
const open = info === i;
|
|
2157
2231
|
const infoId = `${gen}-${i}`;
|
|
2158
|
-
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);
|
|
2159
2233
|
};
|
|
2160
2234
|
const rows = rules.map((r) => ({ rule: r, kind: rowKind(r), isHeld: false }));
|
|
2161
2235
|
for (const h of held) {
|
|
@@ -2164,6 +2238,13 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2164
2238
|
if (draft) {
|
|
2165
2239
|
rows.push({ rule: null, kind: draft, isHeld: false });
|
|
2166
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
|
+
});
|
|
2167
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(
|
|
2168
2249
|
"button",
|
|
2169
2250
|
{
|
|
@@ -2171,7 +2252,8 @@ function RuleEditor({ ctx, rules, focusFirst, quickLine, results, blanks }) {
|
|
|
2171
2252
|
type: "button",
|
|
2172
2253
|
className: "pk-btn pk-small-btn",
|
|
2173
2254
|
disabled: full,
|
|
2174
|
-
|
|
2255
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
2256
|
+
onClick: () => add(k),
|
|
2175
2257
|
"data-autofocus": focusFirst && !count && i === 0 ? "" : void 0,
|
|
2176
2258
|
"data-testid": `rule-add-${k}`
|
|
2177
2259
|
},
|
|
@@ -2296,7 +2378,7 @@ function FilterLevel({ view, field, encoded, types, labels, locale, commit, back
|
|
|
2296
2378
|
const say = (f) => ruleText(view, f, { labels, locale, timeZone, date: fk.dates, labelOf, span });
|
|
2297
2379
|
const number = (n) => n.toLocaleString(locale);
|
|
2298
2380
|
const yearsOn = quick.id === "yearsCombined" && quick.years ? quick.years : years.map((y) => y.year);
|
|
2299
|
-
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;
|
|
2300
2382
|
const quickWords = quick.id === "yearsCombined" ? yearsText : quick.filters.length ? relativeText(quick.filters[0], labels, locale, timeZone, void 0, span, view.formatting?.weekStart) : null;
|
|
2301
2383
|
const outByQuick = (
|
|
2302
2384
|
/** @type {Set<string> | undefined} */
|
|
@@ -2467,7 +2549,7 @@ function TopLevel({ view, field, types, labels, locale, commit, back, encoded })
|
|
|
2467
2549
|
};
|
|
2468
2550
|
const groupName = useFormName();
|
|
2469
2551
|
const tiesName = useFormName();
|
|
2470
|
-
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));
|
|
2471
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, () => {
|
|
2472
2554
|
setOwn(false);
|
|
2473
2555
|
set(null);
|
|
@@ -2707,6 +2789,66 @@ function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaul
|
|
|
2707
2789
|
import React7, { useEffect as useEffect3, useId as useId5, useRef as useRef3, useState as useState5 } from "react";
|
|
2708
2790
|
import { VIEW_FILE_LIMITS } from "pivotkit-core";
|
|
2709
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
|
+
|
|
2710
2852
|
// src/share-actions.js
|
|
2711
2853
|
import { toViewFile, viewFileName, viewFileText } from "pivotkit-core";
|
|
2712
2854
|
|
|
@@ -2789,7 +2931,7 @@ async function copyText(text, container) {
|
|
|
2789
2931
|
}
|
|
2790
2932
|
|
|
2791
2933
|
// src/version.js
|
|
2792
|
-
var VERSION = true ? "0.
|
|
2934
|
+
var VERSION = true ? "0.7.0" : "0.0.0-source";
|
|
2793
2935
|
|
|
2794
2936
|
// src/share-actions.js
|
|
2795
2937
|
var here = () => typeof location !== "undefined" ? location.href : void 0;
|
|
@@ -2851,28 +2993,28 @@ function shareActions(ctx, labels) {
|
|
|
2851
2993
|
if (!loaded.view) {
|
|
2852
2994
|
return labels.viewFailed[loaded.failed ?? "notView"] ?? labels.viewFailed.notView;
|
|
2853
2995
|
}
|
|
2854
|
-
const
|
|
2996
|
+
const ready2 = (
|
|
2855
2997
|
/** @type {import("./share.js").LoadedView} */
|
|
2856
2998
|
loaded
|
|
2857
2999
|
);
|
|
2858
|
-
const made =
|
|
2859
|
-
if (made &&
|
|
3000
|
+
const made = ready2.file?.source;
|
|
3001
|
+
if (made && ready2.file?.view && ctx.viaSheet?.({ id: made.id, sheet: sheetOfSource(made) }, ready2.file.name || viewName || "", toViewFile(ready2.file.view, { name: ready2.file.name, source: made })) === "switch") {
|
|
2860
3002
|
return null;
|
|
2861
3003
|
}
|
|
2862
|
-
const check = loadCheck(
|
|
3004
|
+
const check = loadCheck(ready2, labels, Array.isArray(ctx.sources) ? ctx.sources : []);
|
|
2863
3005
|
if (!check) {
|
|
2864
|
-
ctx.applyLoaded(
|
|
3006
|
+
ctx.applyLoaded(ready2);
|
|
2865
3007
|
return null;
|
|
2866
3008
|
}
|
|
2867
3009
|
const target = check.switchTo;
|
|
2868
3010
|
const switchTo = ctx.onSourceSwitch;
|
|
2869
3011
|
return {
|
|
2870
3012
|
lines: check.lines,
|
|
2871
|
-
load: () => ctx.applyLoaded(
|
|
3013
|
+
load: () => ctx.applyLoaded(ready2),
|
|
2872
3014
|
switchTo: target && typeof switchTo === "function" ? { name: target.name, run: () => switchTo({ source: { id: target.id, name: target.name }, view: (
|
|
2873
3015
|
/** @type {Record<string, unknown>} */
|
|
2874
|
-
|
|
2875
|
-
), name:
|
|
3016
|
+
ready2.file?.view ?? ready2.view
|
|
3017
|
+
), name: ready2.file?.name || void 0 }) } : void 0
|
|
2876
3018
|
};
|
|
2877
3019
|
}
|
|
2878
3020
|
};
|
|
@@ -3479,23 +3621,22 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
3479
3621
|
};
|
|
3480
3622
|
return /* @__PURE__ */ React7.createElement(LevelMenu, { name: labels.views, labels, topics, close, onPick: runChoice(close), panel, focusAgain: templates.length });
|
|
3481
3623
|
}
|
|
3482
|
-
function ExportOption({ icon, text, info, onSelect, testId, disabled, reason }) {
|
|
3624
|
+
function ExportOption({ icon, text, info, onSelect, testId, disabled, reason, onIntent }) {
|
|
3483
3625
|
const option = /* @__PURE__ */ React7.createElement(Option, { icon, onSelect, disabled, reason, testId }, text);
|
|
3484
|
-
return info ? /* @__PURE__ */ React7.createElement("div", { className: "pk-setting-row" }, option, /* @__PURE__ */ React7.createElement(SettingInfo, { id: (
|
|
3626
|
+
return info ? /* @__PURE__ */ React7.createElement("div", { className: "pk-setting-row", onPointerEnter: onIntent, onPointerDown: onIntent, onFocus: onIntent }, option, /* @__PURE__ */ React7.createElement(SettingInfo, { id: (
|
|
3485
3627
|
/** @type {any} */
|
|
3486
3628
|
info
|
|
3487
3629
|
), name: text })) : option;
|
|
3488
3630
|
}
|
|
3489
|
-
function ExportPanel({ labels, onExport, chartReady, display, empty = false, dataExport
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
}, [prepare]);
|
|
3631
|
+
function ExportPanel({ labels, onExport, chartReady, display, empty = false, dataExport, prepare, close }) {
|
|
3632
|
+
const source = dataExport ? dataExportFor(dataExport.exportData, dataExport.encoded).source : false;
|
|
3633
|
+
useEffect3(() => prepare("menu"), [prepare]);
|
|
3493
3634
|
const run = (kind) => () => {
|
|
3494
3635
|
close();
|
|
3495
3636
|
onExport(kind);
|
|
3496
3637
|
};
|
|
3497
3638
|
const off = empty ? { disabled: true, reason: labels.exportNeedsField } : {};
|
|
3498
|
-
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" })),
|
|
3639
|
+
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", onIntent: () => prepare("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);
|
|
3499
3640
|
}
|
|
3500
3641
|
|
|
3501
3642
|
// src/drill-panel.jsx
|
|
@@ -3521,45 +3662,97 @@ function printParts(html, parser) {
|
|
|
3521
3662
|
}
|
|
3522
3663
|
return { css: styles.join("\n"), lang: parsed.documentElement.getAttribute("lang") ?? "", dir: parsed.documentElement.getAttribute("dir") ?? "", title: parsed.title, body: parsed.body };
|
|
3523
3664
|
}
|
|
3524
|
-
|
|
3665
|
+
var ready = /* @__PURE__ */ new WeakMap();
|
|
3666
|
+
function newSlot(container) {
|
|
3525
3667
|
const doc = container.ownerDocument;
|
|
3526
|
-
const view = doc.defaultView;
|
|
3527
|
-
if (!view) {
|
|
3528
|
-
return false;
|
|
3529
|
-
}
|
|
3530
|
-
for (const old of container.querySelectorAll(`iframe.${FRAME_CLASS}`)) {
|
|
3531
|
-
removeFrame(
|
|
3532
|
-
/** @type {HTMLIFrameElement} */
|
|
3533
|
-
old
|
|
3534
|
-
);
|
|
3535
|
-
}
|
|
3536
|
-
const parts = printParts(html, new view.DOMParser());
|
|
3537
3668
|
const frame = doc.createElement("iframe");
|
|
3538
3669
|
frame.className = FRAME_CLASS;
|
|
3539
3670
|
frame.setAttribute("sandbox", "allow-same-origin allow-modals");
|
|
3540
3671
|
frame.setAttribute("aria-hidden", "true");
|
|
3541
3672
|
frame.setAttribute("tabindex", "-1");
|
|
3542
|
-
frame.title = parts.title;
|
|
3543
3673
|
frame.hidden = true;
|
|
3544
|
-
const
|
|
3674
|
+
const slot = { frame, isLoaded: false, loaded: Promise.resolve(false) };
|
|
3675
|
+
const loading = new AbortController();
|
|
3676
|
+
listeners.set(frame, loading);
|
|
3677
|
+
slot.loaded = new Promise((resolve) => {
|
|
3545
3678
|
const timer = setTimeout(() => resolve(false), PRINT_LOAD_TIMEOUT);
|
|
3679
|
+
loading.signal.addEventListener("abort", () => {
|
|
3680
|
+
clearTimeout(timer);
|
|
3681
|
+
resolve(false);
|
|
3682
|
+
});
|
|
3546
3683
|
const done = () => {
|
|
3547
3684
|
if (frame.contentDocument?.URL === "about:srcdoc" && frame.contentDocument.readyState === "complete") {
|
|
3548
|
-
|
|
3549
|
-
|
|
3685
|
+
frame.hidden = false;
|
|
3686
|
+
slot.isLoaded = true;
|
|
3550
3687
|
resolve(true);
|
|
3688
|
+
loading.abort();
|
|
3551
3689
|
}
|
|
3552
3690
|
};
|
|
3553
|
-
frame.addEventListener("load", done);
|
|
3691
|
+
frame.addEventListener("load", done, { signal: loading.signal });
|
|
3554
3692
|
});
|
|
3555
3693
|
frame.srcdoc = '<!doctype html><html><head><meta charset="utf-8"><title></title></head><body></body></html>';
|
|
3556
3694
|
container.append(frame);
|
|
3557
|
-
|
|
3695
|
+
return slot;
|
|
3696
|
+
}
|
|
3697
|
+
function preparePrintFrame(container) {
|
|
3698
|
+
if (!ready.get(container)?.frame.isConnected) {
|
|
3699
|
+
ready.set(container, newSlot(container));
|
|
3700
|
+
}
|
|
3701
|
+
}
|
|
3702
|
+
function releasePrintFrame(container) {
|
|
3703
|
+
const slot = ready.get(container);
|
|
3704
|
+
if (slot) {
|
|
3705
|
+
ready.delete(container);
|
|
3706
|
+
removeFrame(slot.frame);
|
|
3707
|
+
}
|
|
3708
|
+
}
|
|
3709
|
+
function takePrintFrame(container) {
|
|
3710
|
+
const kept = ready.get(container);
|
|
3711
|
+
const slot = kept?.frame.isConnected ? kept : newSlot(container);
|
|
3712
|
+
ready.delete(container);
|
|
3713
|
+
for (const old of container.querySelectorAll(`iframe.${FRAME_CLASS}`)) {
|
|
3714
|
+
if (old !== slot.frame) {
|
|
3715
|
+
removeFrame(
|
|
3716
|
+
/** @type {HTMLIFrameElement} */
|
|
3717
|
+
old
|
|
3718
|
+
);
|
|
3719
|
+
}
|
|
3720
|
+
}
|
|
3721
|
+
return slot;
|
|
3722
|
+
}
|
|
3723
|
+
var dropPrintFrame = (slot) => removeFrame(slot.frame);
|
|
3724
|
+
function printHtml(html, slot) {
|
|
3725
|
+
if (slot.isLoaded) {
|
|
3726
|
+
return Promise.resolve(fillAndPrint(html, slot.frame));
|
|
3727
|
+
}
|
|
3728
|
+
return slot.loaded.then((ok) => {
|
|
3729
|
+
if (!ok) {
|
|
3730
|
+
removeFrame(slot.frame);
|
|
3731
|
+
}
|
|
3732
|
+
return ok && fillAndPrint(html, slot.frame);
|
|
3733
|
+
});
|
|
3734
|
+
}
|
|
3735
|
+
function fillAndPrint(html, frame) {
|
|
3736
|
+
try {
|
|
3737
|
+
return fillAndPrintIn(html, frame);
|
|
3738
|
+
} catch (error) {
|
|
3739
|
+
removeFrame(frame);
|
|
3740
|
+
throw error;
|
|
3741
|
+
}
|
|
3742
|
+
}
|
|
3743
|
+
function fillAndPrintIn(html, frame) {
|
|
3744
|
+
const win = frame.contentWindow;
|
|
3558
3745
|
const fdoc = frame.contentDocument;
|
|
3746
|
+
if (!frame.isConnected) {
|
|
3747
|
+
return true;
|
|
3748
|
+
}
|
|
3559
3749
|
if (!win || !fdoc || !fdoc.body) {
|
|
3560
|
-
frame
|
|
3750
|
+
removeFrame(frame);
|
|
3561
3751
|
return false;
|
|
3562
3752
|
}
|
|
3753
|
+
const parts = printParts(html, new /** @type {any} */
|
|
3754
|
+
frame.ownerDocument.defaultView.DOMParser());
|
|
3755
|
+
frame.title = parts.title;
|
|
3563
3756
|
fdoc.documentElement.lang = parts.lang;
|
|
3564
3757
|
fdoc.documentElement.dir = parts.dir;
|
|
3565
3758
|
fdoc.title = parts.title;
|
|
@@ -3577,45 +3770,43 @@ async function printHtml(html, container) {
|
|
|
3577
3770
|
fdoc.head.append(style);
|
|
3578
3771
|
}
|
|
3579
3772
|
fdoc.body.replaceChildren(...[...parts.body.childNodes].map((node) => fdoc.importNode(node, true)));
|
|
3580
|
-
|
|
3581
|
-
|
|
3582
|
-
if (!frame.isConnected) {
|
|
3583
|
-
return true;
|
|
3584
|
-
}
|
|
3773
|
+
void fdoc.documentElement.getBoundingClientRect();
|
|
3774
|
+
const view = frame.ownerDocument.defaultView;
|
|
3585
3775
|
const ended = new AbortController();
|
|
3586
3776
|
listeners.set(frame, ended);
|
|
3587
3777
|
const after = () => setTimeout(() => removeFrame(frame), 0);
|
|
3588
3778
|
win.addEventListener("afterprint", after, { once: true, signal: ended.signal });
|
|
3589
|
-
view
|
|
3779
|
+
view?.addEventListener("afterprint", after, { once: true, signal: ended.signal });
|
|
3590
3780
|
win.print();
|
|
3591
3781
|
return true;
|
|
3592
3782
|
}
|
|
3593
3783
|
|
|
3594
|
-
// src/
|
|
3595
|
-
function
|
|
3784
|
+
// src/theme-tokens.js
|
|
3785
|
+
function themeTokens(root, theme, names, more = () => ({})) {
|
|
3596
3786
|
const host = (
|
|
3597
3787
|
/** @type {{ host?: Element }} */
|
|
3598
3788
|
root.getRootNode().host
|
|
3599
3789
|
);
|
|
3600
|
-
const
|
|
3790
|
+
const other = theme === "light" ? "dark" : "light";
|
|
3791
|
+
const shown = [root, ...host ? [host] : []].filter((el) => el.getAttribute("data-pk-theme") === other);
|
|
3601
3792
|
const read = () => {
|
|
3602
3793
|
const style = getComputedStyle(root);
|
|
3603
3794
|
return { ...Object.fromEntries(names.map((name) => [name, style.getPropertyValue(name).trim()]).filter(([, value]) => value)), ...more() };
|
|
3604
3795
|
};
|
|
3605
|
-
if (!
|
|
3796
|
+
if (!shown.length) {
|
|
3606
3797
|
return read();
|
|
3607
3798
|
}
|
|
3608
3799
|
const kept = [root.style.getPropertyValue("--pk-duration"), root.style.getPropertyPriority("--pk-duration")];
|
|
3609
3800
|
root.style.setProperty("--pk-duration", "0ms", "important");
|
|
3610
3801
|
try {
|
|
3611
|
-
for (const el of
|
|
3612
|
-
el.setAttribute("data-pk-theme",
|
|
3802
|
+
for (const el of shown) {
|
|
3803
|
+
el.setAttribute("data-pk-theme", theme);
|
|
3613
3804
|
}
|
|
3614
3805
|
try {
|
|
3615
3806
|
return read();
|
|
3616
3807
|
} finally {
|
|
3617
|
-
for (const el of
|
|
3618
|
-
el.setAttribute("data-pk-theme",
|
|
3808
|
+
for (const el of shown) {
|
|
3809
|
+
el.setAttribute("data-pk-theme", other);
|
|
3619
3810
|
}
|
|
3620
3811
|
getComputedStyle(root).getPropertyValue("--pk-duration");
|
|
3621
3812
|
}
|
|
@@ -3646,15 +3837,34 @@ function loadExporters() {
|
|
|
3646
3837
|
return pending;
|
|
3647
3838
|
}
|
|
3648
3839
|
var reportPending = null;
|
|
3840
|
+
var reportModules = null;
|
|
3649
3841
|
function loadReport(loadECharts) {
|
|
3650
|
-
reportPending ??= Promise.all([import("./chunks/report-run-
|
|
3651
|
-
|
|
3652
|
-
|
|
3653
|
-
|
|
3842
|
+
reportPending ??= Promise.all([import("./chunks/report-run-HU4WPOB7.js"), loadECharts()]).then(
|
|
3843
|
+
(modules) => reportModules = modules,
|
|
3844
|
+
(error) => {
|
|
3845
|
+
reportPending = null;
|
|
3846
|
+
throw error;
|
|
3847
|
+
}
|
|
3848
|
+
);
|
|
3654
3849
|
return reportPending;
|
|
3655
3850
|
}
|
|
3656
3851
|
var exportersNow = () => exporters;
|
|
3657
3852
|
var prepareExporters = () => void loadExporters().catch(() => void 0);
|
|
3853
|
+
function prepareExport(what, root, loadECharts) {
|
|
3854
|
+
if (what === "print") {
|
|
3855
|
+
if (loadECharts) {
|
|
3856
|
+
void loadReport(loadECharts).catch(() => void 0);
|
|
3857
|
+
}
|
|
3858
|
+
return void 0;
|
|
3859
|
+
}
|
|
3860
|
+
prepareExporters();
|
|
3861
|
+
const container = root.current;
|
|
3862
|
+
if (!container) {
|
|
3863
|
+
return void 0;
|
|
3864
|
+
}
|
|
3865
|
+
preparePrintFrame(container);
|
|
3866
|
+
return () => releasePrintFrame(container);
|
|
3867
|
+
}
|
|
3658
3868
|
function deliver(blob, { doc, onExport, ...file }) {
|
|
3659
3869
|
if (onExport?.({ ...file, blob }) === false) {
|
|
3660
3870
|
return false;
|
|
@@ -3692,16 +3902,17 @@ function xlsxTheme(root) {
|
|
|
3692
3902
|
if (!root) {
|
|
3693
3903
|
return void 0;
|
|
3694
3904
|
}
|
|
3695
|
-
const tokens =
|
|
3905
|
+
const tokens = themeTokens(root, "light", XLSX_TOKENS);
|
|
3696
3906
|
const ctx = root.ownerDocument.createElement("canvas").getContext("2d");
|
|
3697
3907
|
return xlsxThemeOf({ getPropertyValue: (name) => tokens[name] ?? "" }, (text) => hexColor(text, ctx));
|
|
3698
3908
|
}
|
|
3699
|
-
function reportTokens(root, report, chart) {
|
|
3909
|
+
function reportTokens(root, report, chart, dark) {
|
|
3700
3910
|
if (!root) {
|
|
3701
|
-
return
|
|
3911
|
+
return {};
|
|
3702
3912
|
}
|
|
3703
|
-
const tokens =
|
|
3704
|
-
|
|
3913
|
+
const tokens = themeTokens(root, "light", report.REPORT_TOKENS, () => chart.tokenLengths(root, [...chart.LENGTH_TOKENS, ...report.REPORT_LENGTHS]));
|
|
3914
|
+
const darkTokens = dark ? themeTokens(root, "dark", report.REPORT_DARK_TOKENS) : {};
|
|
3915
|
+
return { ...Object.keys(tokens).length ? { tokens } : {}, ...Object.keys(darkTokens).length ? { darkTokens } : {} };
|
|
3705
3916
|
}
|
|
3706
3917
|
async function runExport(kind, { fileName, result, encoded, exportData, locale, labels, limits, root, chartRef, announce, onExport, title, source, loadECharts }) {
|
|
3707
3918
|
labels = menuLabels(labels);
|
|
@@ -3719,16 +3930,22 @@ async function runExport(kind, { fileName, result, encoded, exportData, locale,
|
|
|
3719
3930
|
}
|
|
3720
3931
|
if (kind === "data-csv" || kind === "data-json") {
|
|
3721
3932
|
const data = encoded ?? result?.encoded;
|
|
3722
|
-
if (!
|
|
3933
|
+
if (!data) {
|
|
3934
|
+
return;
|
|
3935
|
+
}
|
|
3936
|
+
const scope = dataExportFor(exportData, data);
|
|
3937
|
+
if (!scope.source) {
|
|
3723
3938
|
return;
|
|
3724
3939
|
}
|
|
3725
3940
|
const m2 = exporters ?? await loadExporters();
|
|
3726
3941
|
const csv = kind === "data-csv";
|
|
3727
3942
|
const file2 = `${base}-data.${csv ? "csv" : "json"}`;
|
|
3728
|
-
const
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
3943
|
+
const options = { ...limits ? { limits } : {}, ...scope.columns ? { columns: scope.columns } : {} };
|
|
3944
|
+
const blob = csv ? new Blob(
|
|
3945
|
+
/** @type {BlobPart[]} */
|
|
3946
|
+
m2.dataToCsvParts(data, options),
|
|
3947
|
+
{ type: "text/csv;charset=utf-8" }
|
|
3948
|
+
) : new Blob([m2.dataToJson(data, options)], { type: "application/json" });
|
|
3732
3949
|
if (deliver(blob, { kind, fileName: file2, doc, onExport })) {
|
|
3733
3950
|
announce(fill(labels.toastExported, { file: file2 }));
|
|
3734
3951
|
}
|
|
@@ -3738,48 +3955,57 @@ async function runExport(kind, { fileName, result, encoded, exportData, locale,
|
|
|
3738
3955
|
return;
|
|
3739
3956
|
}
|
|
3740
3957
|
if (kind === "html" || kind === "svg" || kind === "print") {
|
|
3741
|
-
const
|
|
3742
|
-
|
|
3743
|
-
|
|
3744
|
-
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
3755
|
-
|
|
3756
|
-
|
|
3757
|
-
|
|
3758
|
-
|
|
3759
|
-
|
|
3760
|
-
|
|
3761
|
-
|
|
3762
|
-
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3958
|
+
const slot = kind === "print" && root.current ? takePrintFrame(root.current) : null;
|
|
3959
|
+
let printing = false;
|
|
3960
|
+
try {
|
|
3961
|
+
const [report, echarts] = reportModules ?? await loadReport(
|
|
3962
|
+
/** @type {() => Promise<any>} */
|
|
3963
|
+
loadECharts
|
|
3964
|
+
);
|
|
3965
|
+
const chart = chartRef.current;
|
|
3966
|
+
const size = chart ? { width: clampSize(chart.getWidth()), height: clampSize(chart.getHeight()) } : void 0;
|
|
3967
|
+
const rendered = await report.render(result.view, result.encoded, {
|
|
3968
|
+
format: kind === "svg" ? "svg" : "html",
|
|
3969
|
+
echarts,
|
|
3970
|
+
locale,
|
|
3971
|
+
trusted: true,
|
|
3972
|
+
labels: labels.core,
|
|
3973
|
+
...limits ? { limits } : {},
|
|
3974
|
+
timeZone: result.timeZone,
|
|
3975
|
+
...title ? { title } : {},
|
|
3976
|
+
...source ? { source } : {},
|
|
3977
|
+
...size ? { size } : {},
|
|
3978
|
+
...reportTokens(root.current, report, echarts, kind === "html"),
|
|
3979
|
+
chartEmbed: kind === "print" ? "inline" : "image"
|
|
3980
|
+
});
|
|
3981
|
+
const file2 = `${base}.${kind === "svg" ? "svg" : "html"}`;
|
|
3982
|
+
const blob = new Blob([
|
|
3983
|
+
/** @type {BlobPart} */
|
|
3984
|
+
rendered.body
|
|
3985
|
+
], { type: rendered.mediaType });
|
|
3986
|
+
if (kind !== "print") {
|
|
3987
|
+
if (deliver(blob, { kind, fileName: file2, doc, onExport })) {
|
|
3988
|
+
announce(fill(labels.toastExported, { file: file2 }));
|
|
3989
|
+
}
|
|
3990
|
+
return;
|
|
3991
|
+
}
|
|
3992
|
+
if (onExport?.({ kind, fileName: file2, blob }) === false) {
|
|
3993
|
+
return;
|
|
3994
|
+
}
|
|
3995
|
+
printing = true;
|
|
3996
|
+
if (!slot || !await printHtml(
|
|
3997
|
+
/** @type {string} */
|
|
3998
|
+
rendered.text,
|
|
3999
|
+
slot
|
|
4000
|
+
)) {
|
|
4001
|
+
announce(labels.toastPrintBlocked, { tone: "error" });
|
|
3769
4002
|
}
|
|
3770
4003
|
return;
|
|
4004
|
+
} finally {
|
|
4005
|
+
if (slot && !printing) {
|
|
4006
|
+
dropPrintFrame(slot);
|
|
4007
|
+
}
|
|
3771
4008
|
}
|
|
3772
|
-
if (onExport?.({ kind, fileName: file2, blob }) === false) {
|
|
3773
|
-
return;
|
|
3774
|
-
}
|
|
3775
|
-
if (!root.current || !await printHtml(
|
|
3776
|
-
/** @type {string} */
|
|
3777
|
-
rendered.text,
|
|
3778
|
-
root.current
|
|
3779
|
-
)) {
|
|
3780
|
-
announce(labels.toastPrintBlocked, { tone: "error" });
|
|
3781
|
-
}
|
|
3782
|
-
return;
|
|
3783
4009
|
}
|
|
3784
4010
|
const m = exporters ?? await loadExporters();
|
|
3785
4011
|
const grid = toGrid(result, { locale, labels: labels.core, limits });
|
|
@@ -3806,19 +4032,28 @@ async function runExport(kind, { fileName, result, encoded, exportData, locale,
|
|
|
3806
4032
|
var clampSize = (px) => Math.max(100, Math.min(8e3, Math.round(Number(px) || 0)));
|
|
3807
4033
|
|
|
3808
4034
|
// src/drill-export.js
|
|
4035
|
+
function pick(row, columns) {
|
|
4036
|
+
const out = /* @__PURE__ */ Object.create(null);
|
|
4037
|
+
for (const c of columns) {
|
|
4038
|
+
out[c.name] = row[c.name];
|
|
4039
|
+
}
|
|
4040
|
+
return out;
|
|
4041
|
+
}
|
|
3809
4042
|
function rowsText({ shown, count }, labels, locale) {
|
|
3810
4043
|
return shown < count ? fill(labels.drillPart, { shown: shown.toLocaleString(locale), count: count.toLocaleString(locale) }) : plural(labels.drillCount, count, { lang: labels.lang, locale });
|
|
3811
4044
|
}
|
|
3812
|
-
async function exportDrill(kind, { drill, encoded, labels, onExport, announce, root }) {
|
|
4045
|
+
async function exportDrill(kind, { drill, encoded, labels, columns, onExport, announce, root }) {
|
|
3813
4046
|
const { locale } = drill;
|
|
3814
4047
|
const part = { shown: drill.rows.length, count: drill.count };
|
|
3815
4048
|
const rows = rowsText(part, labels, locale);
|
|
3816
4049
|
const base = safeFileName(drill.name);
|
|
3817
4050
|
try {
|
|
3818
4051
|
const m = exportersNow() ?? await loadExporters();
|
|
4052
|
+
const picked = pickColumns(drill.columns.map((c) => c.name), columns);
|
|
4053
|
+
const shown = picked.map((c) => drill.columns[c]);
|
|
3819
4054
|
if (kind === "drill-copy" || kind === "drill-json") {
|
|
3820
4055
|
const json = kind === "drill-json";
|
|
3821
|
-
const text = json ? JSON.stringify(Array.from(drill.indices, (i) => decodeRow(encoded, i)), null, 2) : m.toTsv([
|
|
4056
|
+
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]))]);
|
|
3822
4057
|
const done = await copyOut(text, { kind, fileName: `${base}.${json ? "json" : "tsv"}`, type: json ? "application/json" : "text/tab-separated-values", container: root, onExport, rows: part });
|
|
3823
4058
|
if (done !== "kept") {
|
|
3824
4059
|
announce(done === "copied" ? fill(json ? labels.drillCopiedJson : labels.drillCopied, { rows }) : labels.toastCopyBlocked, done === "copied" ? void 0 : { tone: "error" });
|
|
@@ -3826,8 +4061,8 @@ async function exportDrill(kind, { drill, encoded, labels, onExport, announce, r
|
|
|
3826
4061
|
return;
|
|
3827
4062
|
}
|
|
3828
4063
|
const xlsx = kind === "drill-xlsx";
|
|
3829
|
-
const fields = Object.fromEntries(
|
|
3830
|
-
const options = { locale, formats: drill.formats, labels: { fields, true: labels.core.true, false: labels.core.false } };
|
|
4064
|
+
const fields = Object.fromEntries(shown.map((c) => [c.name, c.label ?? c.name]));
|
|
4065
|
+
const options = { locale, formats: drill.formats, columns: shown.map((c) => c.name), labels: { fields, true: labels.core.true, false: labels.core.false } };
|
|
3831
4066
|
const file = `${base}.${xlsx ? "xlsx" : "csv"}`;
|
|
3832
4067
|
const bytes = xlsx ? m.rowsToXlsx(encoded, drill.indices, { ...options, sheetName: drill.name }) : m.rowsToCsvBytes(encoded, drill.indices, options);
|
|
3833
4068
|
const blob = new Blob([
|
|
@@ -3899,7 +4134,9 @@ function drillOf({ result, rowPath, colPath, count, indices, formatOf, nameOf, i
|
|
|
3899
4134
|
}
|
|
3900
4135
|
|
|
3901
4136
|
// src/drill-panel.jsx
|
|
3902
|
-
function DrillPanel({ drill: source, onClose, labels, locale, exportContext }) {
|
|
4137
|
+
function DrillPanel({ drill: source, onClose, labels, locale, exportContext: context }) {
|
|
4138
|
+
const columns = context ? dataExportFor(context.exportData, context.encoded).columns : void 0;
|
|
4139
|
+
const exportContext = context && columns?.length !== 0 ? context : void 0;
|
|
3903
4140
|
const id = useId6();
|
|
3904
4141
|
const drill = useMemo4(() => source ? drillOf(source, labels) : null, [source, labels]);
|
|
3905
4142
|
const panel = useRef4(
|
|
@@ -3922,7 +4159,7 @@ function DrillPanel({ drill: source, onClose, labels, locale, exportContext }) {
|
|
|
3922
4159
|
const run = (kind, close) => () => {
|
|
3923
4160
|
close();
|
|
3924
4161
|
if (exportContext) {
|
|
3925
|
-
void exportDrill(kind, { drill, labels, ...exportContext, root: exportContext.root.current });
|
|
4162
|
+
void exportDrill(kind, { drill, labels, ...exportContext, columns, root: exportContext.root.current });
|
|
3926
4163
|
}
|
|
3927
4164
|
};
|
|
3928
4165
|
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(
|
|
@@ -3999,7 +4236,7 @@ export {
|
|
|
3999
4236
|
addMenuTexts,
|
|
4000
4237
|
hasMenuTexts,
|
|
4001
4238
|
menuLabels,
|
|
4002
|
-
|
|
4239
|
+
prepareExport,
|
|
4003
4240
|
runExport,
|
|
4004
4241
|
storedViews
|
|
4005
4242
|
};
|