pivotkit-react 0.6.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 +69 -1
- package/dist/chunks/{chunk-2RAVX4DO.js → chunk-3LDE2GPG.js} +57 -33
- package/dist/chunks/{chunk-RIOSIYGC.js → chunk-JOWAEZAD.js} +6 -4
- package/dist/chunks/{chunk-7LERNGUW.js → chunk-ZK5RVCHP.js} +14 -2
- package/dist/import-ui.js +13 -24
- package/dist/index.js +11 -7
- package/dist/labels.js +1 -1
- package/dist/menus.js +216 -56
- 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 +4 -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/names.d.ts +22 -8
- package/types/toolbar-panels.d.ts +7 -2
- package/types/view-history.d.ts +15 -0
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-3LDE2GPG.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-JOWAEZAD.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.6.
|
|
2934
|
+
var VERSION = true ? "0.6.1" : "0.0.0-source";
|
|
2793
2935
|
|
|
2794
2936
|
// src/share-actions.js
|
|
2795
2937
|
var here = () => typeof location !== "undefined" ? location.href : void 0;
|
|
@@ -3486,7 +3628,8 @@ function ExportOption({ icon, text, info, onSelect, testId, disabled, reason })
|
|
|
3486
3628
|
info
|
|
3487
3629
|
), name: text })) : option;
|
|
3488
3630
|
}
|
|
3489
|
-
function ExportPanel({ labels, onExport, chartReady, display, empty = false, dataExport
|
|
3631
|
+
function ExportPanel({ labels, onExport, chartReady, display, empty = false, dataExport, prepare, close }) {
|
|
3632
|
+
const source = dataExport ? dataExportFor(dataExport.exportData, dataExport.encoded).source : false;
|
|
3490
3633
|
useEffect3(() => {
|
|
3491
3634
|
prepare();
|
|
3492
3635
|
}, [prepare]);
|
|
@@ -3495,7 +3638,7 @@ function ExportPanel({ labels, onExport, chartReady, display, empty = false, dat
|
|
|
3495
3638
|
onExport(kind);
|
|
3496
3639
|
};
|
|
3497
3640
|
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" })),
|
|
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);
|
|
3499
3642
|
}
|
|
3500
3643
|
|
|
3501
3644
|
// src/drill-panel.jsx
|
|
@@ -3719,16 +3862,22 @@ async function runExport(kind, { fileName, result, encoded, exportData, locale,
|
|
|
3719
3862
|
}
|
|
3720
3863
|
if (kind === "data-csv" || kind === "data-json") {
|
|
3721
3864
|
const data = encoded ?? result?.encoded;
|
|
3722
|
-
if (!
|
|
3865
|
+
if (!data) {
|
|
3866
|
+
return;
|
|
3867
|
+
}
|
|
3868
|
+
const scope = dataExportFor(exportData, data);
|
|
3869
|
+
if (!scope.source) {
|
|
3723
3870
|
return;
|
|
3724
3871
|
}
|
|
3725
3872
|
const m2 = exporters ?? await loadExporters();
|
|
3726
3873
|
const csv = kind === "data-csv";
|
|
3727
3874
|
const file2 = `${base}-data.${csv ? "csv" : "json"}`;
|
|
3728
|
-
const
|
|
3729
|
-
|
|
3730
|
-
|
|
3731
|
-
|
|
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" });
|
|
3732
3881
|
if (deliver(blob, { kind, fileName: file2, doc, onExport })) {
|
|
3733
3882
|
announce(fill(labels.toastExported, { file: file2 }));
|
|
3734
3883
|
}
|
|
@@ -3806,19 +3955,28 @@ async function runExport(kind, { fileName, result, encoded, exportData, locale,
|
|
|
3806
3955
|
var clampSize = (px) => Math.max(100, Math.min(8e3, Math.round(Number(px) || 0)));
|
|
3807
3956
|
|
|
3808
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
|
+
}
|
|
3809
3965
|
function rowsText({ shown, count }, labels, locale) {
|
|
3810
3966
|
return shown < count ? fill(labels.drillPart, { shown: shown.toLocaleString(locale), count: count.toLocaleString(locale) }) : plural(labels.drillCount, count, { lang: labels.lang, locale });
|
|
3811
3967
|
}
|
|
3812
|
-
async function exportDrill(kind, { drill, encoded, labels, onExport, announce, root }) {
|
|
3968
|
+
async function exportDrill(kind, { drill, encoded, labels, columns, onExport, announce, root }) {
|
|
3813
3969
|
const { locale } = drill;
|
|
3814
3970
|
const part = { shown: drill.rows.length, count: drill.count };
|
|
3815
3971
|
const rows = rowsText(part, labels, locale);
|
|
3816
3972
|
const base = safeFileName(drill.name);
|
|
3817
3973
|
try {
|
|
3818
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]);
|
|
3819
3977
|
if (kind === "drill-copy" || kind === "drill-json") {
|
|
3820
3978
|
const json = kind === "drill-json";
|
|
3821
|
-
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]))]);
|
|
3822
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 });
|
|
3823
3981
|
if (done !== "kept") {
|
|
3824
3982
|
announce(done === "copied" ? fill(json ? labels.drillCopiedJson : labels.drillCopied, { rows }) : labels.toastCopyBlocked, done === "copied" ? void 0 : { tone: "error" });
|
|
@@ -3826,8 +3984,8 @@ async function exportDrill(kind, { drill, encoded, labels, onExport, announce, r
|
|
|
3826
3984
|
return;
|
|
3827
3985
|
}
|
|
3828
3986
|
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 } };
|
|
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 } };
|
|
3831
3989
|
const file = `${base}.${xlsx ? "xlsx" : "csv"}`;
|
|
3832
3990
|
const bytes = xlsx ? m.rowsToXlsx(encoded, drill.indices, { ...options, sheetName: drill.name }) : m.rowsToCsvBytes(encoded, drill.indices, options);
|
|
3833
3991
|
const blob = new Blob([
|
|
@@ -3899,7 +4057,9 @@ function drillOf({ result, rowPath, colPath, count, indices, formatOf, nameOf, i
|
|
|
3899
4057
|
}
|
|
3900
4058
|
|
|
3901
4059
|
// src/drill-panel.jsx
|
|
3902
|
-
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;
|
|
3903
4063
|
const id = useId6();
|
|
3904
4064
|
const drill = useMemo4(() => source ? drillOf(source, labels) : null, [source, labels]);
|
|
3905
4065
|
const panel = useRef4(
|
|
@@ -3922,7 +4082,7 @@ function DrillPanel({ drill: source, onClose, labels, locale, exportContext }) {
|
|
|
3922
4082
|
const run = (kind, close) => () => {
|
|
3923
4083
|
close();
|
|
3924
4084
|
if (exportContext) {
|
|
3925
|
-
void exportDrill(kind, { drill, labels, ...exportContext, root: exportContext.root.current });
|
|
4085
|
+
void exportDrill(kind, { drill, labels, ...exportContext, columns, root: exportContext.root.current });
|
|
3926
4086
|
}
|
|
3927
4087
|
};
|
|
3928
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(
|