pivotkit-react 0.6.1 → 0.8.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 +212 -1
- package/README.md +33 -15
- package/dist/chunks/{chunk-JMRTIOX4.js → chunk-2N2UGSIG.js} +7 -0
- package/dist/chunks/{chunk-ZK5RVCHP.js → chunk-BHHIZHUE.js} +1 -1
- package/dist/chunks/{chunk-YXLANLGL.js → chunk-GUSQWPTH.js} +56 -3
- package/dist/chunks/{chunk-JOWAEZAD.js → chunk-JAOOFDNR.js} +21 -1
- package/dist/chunks/{chunk-E6M57YLL.js → chunk-MU5BTKSY.js} +7 -0
- package/dist/chunks/{chunk-TR2HROIK.js → chunk-RNQ32FCN.js} +66 -5
- package/dist/chunks/{chunk-XN5HNKJ2.js → chunk-SJCG4I57.js} +98 -33
- package/dist/chunks/{chunk-3LDE2GPG.js → chunk-VMJMDP7C.js} +372 -33
- package/dist/chunks/{report-run-BZBFOMPF.js → report-run-HU4WPOB7.js} +3 -1
- package/dist/chunks/{unused-texts-Y4R67XSN.js → unused-texts-LRYVWFFN.js} +1 -1
- package/dist/chunks/{unused-texts-de-6YVPTNVS.js → unused-texts-de-GB3IWWEM.js} +1 -1
- package/dist/echarts.js +426 -35
- package/dist/import-ui.js +3 -3
- package/dist/index.js +769 -435
- package/dist/labels.js +6 -6
- package/dist/menu-texts-de.js +1 -1
- package/dist/menus.js +1133 -542
- package/dist/styles.css +271 -158
- package/package.json +8 -4
- package/styles.css.d.ts +3 -0
- package/types/PivotReport.d.ts +6 -0
- package/types/add-menu.d.ts +48 -0
- package/types/chart-colors.d.ts +8 -0
- package/types/chart-decorate.d.ts +66 -3
- package/types/chart-legend.d.ts +176 -0
- package/types/chart-summary.d.ts +8 -3
- package/types/chart-tooltip.d.ts +159 -17
- package/types/chart.d.ts +21 -3
- package/types/date-context.d.ts +30 -0
- package/types/drill-panel.d.ts +4 -2
- package/types/echarts.d.ts +7 -3
- package/types/export-run.d.ts +19 -14
- package/types/export-scope.d.ts +13 -2
- package/types/field-info.d.ts +12 -0
- package/types/files.d.ts +14 -0
- package/types/filter.d.ts +18 -0
- package/types/group-context.d.ts +20 -0
- package/types/index.d.ts +35 -6
- package/types/label-room.d.ts +13 -0
- package/types/labels.d.ts +85 -16
- package/types/lazy-menus.d.ts +2 -2
- package/types/levels.d.ts +16 -7
- package/types/menu-labels.d.ts +67 -1
- package/types/menu-ops.d.ts +10 -0
- package/types/menu-topics.d.ts +110 -21
- package/types/menus.d.ts +3 -2
- package/types/names.d.ts +32 -3
- package/types/overflow.d.ts +18 -30
- package/types/print-frame.d.ts +32 -3
- package/types/report-run.d.ts +5 -0
- package/types/rove.d.ts +10 -0
- package/types/theme-tokens.d.ts +17 -0
- package/types/toolbar-panels.d.ts +43 -15
- package/types/unused-texts.d.ts +7 -0
- package/types/use-big-result.d.ts +24 -9
- package/types/use-export.d.ts +8 -4
- package/types/view-ops.d.ts +19 -8
- package/types/view-tabs.d.ts +12 -0
- package/types/zones.d.ts +41 -9
- package/types/light-tokens.d.ts +0 -16
package/dist/menus.js
CHANGED
|
@@ -11,6 +11,9 @@ import {
|
|
|
11
11
|
axisOf,
|
|
12
12
|
chartTypeOf,
|
|
13
13
|
clone,
|
|
14
|
+
dateDisplayLocale,
|
|
15
|
+
dateFormatter,
|
|
16
|
+
dateRangeText,
|
|
14
17
|
dateSpan,
|
|
15
18
|
dayMs,
|
|
16
19
|
dayText,
|
|
@@ -21,6 +24,7 @@ import {
|
|
|
21
24
|
groupField,
|
|
22
25
|
groupingName,
|
|
23
26
|
groupingOf,
|
|
27
|
+
hiddenAfter,
|
|
24
28
|
hiddenNot,
|
|
25
29
|
importNow,
|
|
26
30
|
isoDay,
|
|
@@ -29,7 +33,9 @@ import {
|
|
|
29
33
|
linkNow,
|
|
30
34
|
loadCheck,
|
|
31
35
|
loadLink,
|
|
36
|
+
matchingFields,
|
|
32
37
|
moveField,
|
|
38
|
+
namedUntil,
|
|
33
39
|
numericResult,
|
|
34
40
|
opOf,
|
|
35
41
|
periodText,
|
|
@@ -38,7 +44,6 @@ import {
|
|
|
38
44
|
rangeShare,
|
|
39
45
|
readLinkParam,
|
|
40
46
|
refLabel,
|
|
41
|
-
relativeDays,
|
|
42
47
|
relativeText,
|
|
43
48
|
reorder,
|
|
44
49
|
ruleOp,
|
|
@@ -52,20 +57,22 @@ import {
|
|
|
52
57
|
sortOf,
|
|
53
58
|
sortText,
|
|
54
59
|
sourceOf,
|
|
60
|
+
todayIn,
|
|
55
61
|
valueConditionText,
|
|
56
62
|
valueLabel,
|
|
63
|
+
valueLabels,
|
|
57
64
|
viewFromObject,
|
|
58
65
|
viewFromText,
|
|
59
66
|
wholeYears,
|
|
60
67
|
withLinkParam,
|
|
61
68
|
yearOf,
|
|
62
69
|
yearText
|
|
63
|
-
} from "./chunks/chunk-
|
|
70
|
+
} from "./chunks/chunk-VMJMDP7C.js";
|
|
64
71
|
import {
|
|
65
72
|
addMenuTexts,
|
|
66
73
|
hasMenuTexts,
|
|
67
74
|
menuLabels
|
|
68
|
-
} from "./chunks/chunk-
|
|
75
|
+
} from "./chunks/chunk-RNQ32FCN.js";
|
|
69
76
|
import {
|
|
70
77
|
listedFor,
|
|
71
78
|
sheetOfSource
|
|
@@ -77,19 +84,21 @@ import {
|
|
|
77
84
|
MenuButton,
|
|
78
85
|
Option,
|
|
79
86
|
Popover,
|
|
87
|
+
TYPE_ICON,
|
|
88
|
+
ZONE_ICON,
|
|
80
89
|
activeIn,
|
|
81
90
|
rootOf,
|
|
82
91
|
stopAfter,
|
|
83
92
|
useFormName,
|
|
84
93
|
useIsoLayoutEffect,
|
|
85
94
|
useModal
|
|
86
|
-
} from "./chunks/chunk-
|
|
95
|
+
} from "./chunks/chunk-JAOOFDNR.js";
|
|
87
96
|
import {
|
|
88
97
|
fill,
|
|
89
98
|
hostFailure,
|
|
90
99
|
messageOf,
|
|
91
100
|
plural
|
|
92
|
-
} from "./chunks/chunk-
|
|
101
|
+
} from "./chunks/chunk-SJCG4I57.js";
|
|
93
102
|
|
|
94
103
|
// src/chip-menus.jsx
|
|
95
104
|
import React6, { useId as useId4, useMemo as useMemo3, useState as useState4 } from "react";
|
|
@@ -97,7 +106,7 @@ import { computePivot as computePivot2, fieldLabel as fieldLabel4 } from "pivotk
|
|
|
97
106
|
|
|
98
107
|
// src/filter-level.jsx
|
|
99
108
|
import React5, { useContext as useContext3, useEffect as useEffect2, useId as useId3, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
|
|
100
|
-
import { CATALOG as
|
|
109
|
+
import { CATALOG as CATALOG4, LIMITS as LIMITS2, fieldItems as fieldItems2, fieldLabel as fieldLabel3, formatter as formatter2, relativeDateRange } from "pivotkit-core";
|
|
101
110
|
|
|
102
111
|
// src/filter.jsx
|
|
103
112
|
import React, { useMemo, useState } from "react";
|
|
@@ -105,6 +114,62 @@ import { LIMITS, fieldItems, fieldLabel } from "pivotkit-core";
|
|
|
105
114
|
|
|
106
115
|
// src/menu-ops.js
|
|
107
116
|
import { CATALOG, MATCH_DEFAULTS, MAX_DATE_MS, computePivot, isFormat } from "pivotkit-core";
|
|
117
|
+
|
|
118
|
+
// src/numbers.js
|
|
119
|
+
var cache = /* @__PURE__ */ new Map();
|
|
120
|
+
function marks(locale) {
|
|
121
|
+
let m = cache.get(locale);
|
|
122
|
+
if (!m) {
|
|
123
|
+
let parts;
|
|
124
|
+
try {
|
|
125
|
+
parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
126
|
+
} catch {
|
|
127
|
+
parts = new Intl.NumberFormat("en-US").formatToParts(12345.6);
|
|
128
|
+
}
|
|
129
|
+
m = {
|
|
130
|
+
decimal: parts.find((p) => p.type === "decimal")?.value ?? ".",
|
|
131
|
+
group: parts.find((p) => p.type === "group")?.value ?? ","
|
|
132
|
+
};
|
|
133
|
+
cache.set(locale, m);
|
|
134
|
+
}
|
|
135
|
+
return m;
|
|
136
|
+
}
|
|
137
|
+
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
138
|
+
var PLAIN = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
139
|
+
function parseNumber(text, locale) {
|
|
140
|
+
const t = String(text ?? "").replace(/[\s\u00a0\u202f]/g, "").replace(/\u2212/g, "-");
|
|
141
|
+
if (t === "") {
|
|
142
|
+
return null;
|
|
143
|
+
}
|
|
144
|
+
const { decimal, group } = marks(locale);
|
|
145
|
+
const g = /[\s\u00a0\u202f]/.test(group) ? "" : escape(group);
|
|
146
|
+
const d = escape(decimal);
|
|
147
|
+
const grouped = g ? `\\d{1,3}(?:${g}\\d{3})+` : "(?!)";
|
|
148
|
+
const local = new RegExp(`^([+-]?)(${grouped}|\\d+)?(?:${d}(\\d+))?$`);
|
|
149
|
+
const match = local.exec(t);
|
|
150
|
+
if (match && (match[2] !== void 0 || match[3] !== void 0)) {
|
|
151
|
+
const whole = (match[2] ?? "0").split(group).join("");
|
|
152
|
+
const n = Number(`${match[1]}${whole}${match[3] !== void 0 ? `.${match[3]}` : ""}`);
|
|
153
|
+
return Number.isFinite(n) ? n : null;
|
|
154
|
+
}
|
|
155
|
+
if (PLAIN.test(t)) {
|
|
156
|
+
const n = Number(t);
|
|
157
|
+
return Number.isFinite(n) ? n : null;
|
|
158
|
+
}
|
|
159
|
+
return null;
|
|
160
|
+
}
|
|
161
|
+
function numberText(n, locale) {
|
|
162
|
+
if (typeof n !== "number" || !Number.isFinite(n)) {
|
|
163
|
+
return "";
|
|
164
|
+
}
|
|
165
|
+
try {
|
|
166
|
+
return n.toLocaleString(locale, { useGrouping: false, maximumFractionDigits: 20 });
|
|
167
|
+
} catch {
|
|
168
|
+
return String(n);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
// src/menu-ops.js
|
|
108
173
|
var COUNTING = /* @__PURE__ */ new Set(["count", "countUnique", "listUnique"]);
|
|
109
174
|
var unitOf = (agg) => COUNTING.has(agg) ? "count" : "field";
|
|
110
175
|
function updateValue(view, index, patch, options = {}) {
|
|
@@ -411,6 +476,14 @@ function dateFromInput(text) {
|
|
|
411
476
|
const iso = `${isoYear(Number(m[1]))}-${m[2]}-${m[3]}`;
|
|
412
477
|
return Number.isNaN(dayMs(iso)) || isoDay(dayMs(iso)) !== iso ? null : iso;
|
|
413
478
|
}
|
|
479
|
+
function parseTarget(text, locale, format) {
|
|
480
|
+
const percent = /^(.*?)[\s\u00a0\u202f]*%$/.exec(String(text ?? "").trim());
|
|
481
|
+
if (!percent) {
|
|
482
|
+
return parseNumber(text, locale);
|
|
483
|
+
}
|
|
484
|
+
const n = /^percent/.test(format ?? "") ? parseNumber(percent[1], locale) : null;
|
|
485
|
+
return n === null ? null : /^percent100/.test(format ?? "") ? n : n / 100;
|
|
486
|
+
}
|
|
414
487
|
|
|
415
488
|
// src/filter.jsx
|
|
416
489
|
var FILTER_LIST_MAX = 300;
|
|
@@ -454,7 +527,7 @@ function ValueList({ items, selected, onChange, labels, locale, autoFocus = fals
|
|
|
454
527
|
/* searchItems gives the list itself without a search */
|
|
455
528
|
) : null), children));
|
|
456
529
|
}
|
|
457
|
-
function FilterBody({ view: current, base, field, encoded, locale, labels, commit, close }) {
|
|
530
|
+
function FilterBody({ view: current, base, field, encoded, locale, labels, commit, close, onCancel, titled = true }) {
|
|
458
531
|
const view = base ?? current;
|
|
459
532
|
const formName = useFormName();
|
|
460
533
|
const info = useMemo(() => fieldItems(encoded, field, { view, locale, labels: labels.core }), [encoded, field, view, locale, labels]);
|
|
@@ -483,7 +556,7 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
|
|
|
483
556
|
apply();
|
|
484
557
|
}
|
|
485
558
|
},
|
|
486
|
-
/* @__PURE__ */ React.createElement("div", { className: "pk-popover-head" }, /* @__PURE__ */ React.createElement("h3", null, fill(labels.filterTitle, { field: name })), /* @__PURE__ */ React.createElement("span", { className: "pk-muted" }, fill(labels.selected, { count: selected.size.toLocaleString(locale) }))),
|
|
559
|
+
/* @__PURE__ */ React.createElement("div", { className: "pk-popover-head" }, titled ? /* @__PURE__ */ React.createElement("h3", null, fill(labels.filterTitle, { field: name })) : null, /* @__PURE__ */ React.createElement("span", { className: "pk-muted" }, fill(labels.selected, { count: selected.size.toLocaleString(locale) }))),
|
|
487
560
|
/* @__PURE__ */ React.createElement(ValueList, { items: info.items, selected, onChange: setSelected, labels, locale, autoFocus: true }, kind ? /* @__PURE__ */ React.createElement("fieldset", { className: "pk-condition" }, /* @__PURE__ */ React.createElement("legend", null, kind === "number" ? labels.conditionNumber : labels.condition), /* @__PURE__ */ React.createElement("select", { name: `${formName}-op`, value: op, onChange: (e) => setOp(e.target.value), "aria-label": kind === "number" ? labels.conditionNumber : labels.condition }, /* @__PURE__ */ React.createElement("option", { value: "" }, labels.conditionNone), RULE_OPS.text.map((o) => /* @__PURE__ */ React.createElement("option", { key: o, value: o }, labels.labelOps[o] ?? o))), op ? /* @__PURE__ */ React.createElement(
|
|
488
561
|
ClearInput,
|
|
489
562
|
{
|
|
@@ -502,7 +575,7 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
|
|
|
502
575
|
"data-testid": "filter-condition-text"
|
|
503
576
|
}
|
|
504
577
|
) : null) : null),
|
|
505
|
-
/* @__PURE__ */ React.createElement("div", { className: "pk-popover-foot" }, /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-btn", onClick: close }, labels.cancel), /* @__PURE__ */ React.createElement("button", { type: "submit", className: "pk-btn pk-primary", "data-testid": "filter-apply" }, labels.apply))
|
|
578
|
+
/* @__PURE__ */ React.createElement("div", { className: "pk-popover-foot" }, /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-btn", onClick: onCancel ?? close, "data-testid": "filter-cancel" }, labels.cancel), /* @__PURE__ */ React.createElement("button", { type: "submit", className: "pk-btn pk-primary", "data-testid": "filter-apply" }, labels.apply))
|
|
506
579
|
);
|
|
507
580
|
}
|
|
508
581
|
function FilterPopover({ target, onClose, view, encoded, locale, labels, commit }) {
|
|
@@ -529,10 +602,81 @@ function Section({ title, children, info }) {
|
|
|
529
602
|
}
|
|
530
603
|
|
|
531
604
|
// src/menu-topics.js
|
|
532
|
-
import { CATALOG as
|
|
605
|
+
import { CATALOG as CATALOG3, aggregatorsFor, fieldLabel as fieldLabel2, formatter, isFormat as isFormat2 } from "pivotkit-core";
|
|
606
|
+
|
|
607
|
+
// src/group-context.js
|
|
608
|
+
import { MAX_DATE_MS as MAX_DATE_MS2, isDateMs } from "pivotkit-core";
|
|
609
|
+
import { CATALOG as CATALOG2 } from "pivotkit-core";
|
|
610
|
+
function groupStats(encoded, field) {
|
|
611
|
+
const column = encoded?.column(field);
|
|
612
|
+
if (!column || column.type !== "date") return null;
|
|
613
|
+
let min = Infinity, max = -Infinity;
|
|
614
|
+
const months = /* @__PURE__ */ new Set();
|
|
615
|
+
const minYear = new Date(-MAX_DATE_MS2).getUTCFullYear();
|
|
616
|
+
const maxYear = new Date(MAX_DATE_MS2).getUTCFullYear();
|
|
617
|
+
const yearBits = new Uint8Array(Math.ceil((maxYear - minYear + 1) / 8));
|
|
618
|
+
let yearCount = 0;
|
|
619
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
620
|
+
for (const value of column.dict) {
|
|
621
|
+
if (!isDateMs(value)) continue;
|
|
622
|
+
min = Math.min(min, value);
|
|
623
|
+
max = Math.max(max, value);
|
|
624
|
+
date.setTime(value);
|
|
625
|
+
const month = date.getUTCMonth();
|
|
626
|
+
const yearIndex = date.getUTCFullYear() - minYear;
|
|
627
|
+
const byte = yearIndex >> 3, mask = 1 << (yearIndex & 7);
|
|
628
|
+
if (!(yearBits[byte] & mask)) {
|
|
629
|
+
yearBits[byte] |= mask;
|
|
630
|
+
yearCount++;
|
|
631
|
+
}
|
|
632
|
+
months.add(month);
|
|
633
|
+
}
|
|
634
|
+
return min <= max ? { span: { min, max }, first: new Date(min), last: new Date(max), years: yearCount, months: [...months].sort((a, b) => a - b) } : null;
|
|
635
|
+
}
|
|
636
|
+
var calendarDays = (span) => Math.floor(span.max / 864e5) - Math.floor(span.min / 864e5) + 1;
|
|
637
|
+
function groupHint(encoded, field, unit, locale, labels, stats = groupStats(encoded, field)) {
|
|
638
|
+
const span = stats?.span;
|
|
639
|
+
if (!span || !stats) return labels.unitHints[unit] || void 0;
|
|
640
|
+
const { first, last, months, years } = stats;
|
|
641
|
+
const y1 = first.getUTCFullYear(), y2 = last.getUTCFullYear();
|
|
642
|
+
const era = y1 <= 0 ? "short" : void 0;
|
|
643
|
+
const firstYear = yearText(y1, locale), lastYear = yearText(y2, locale);
|
|
644
|
+
if (CATALOG2.cyclicUnits.includes(unit)) {
|
|
645
|
+
let example = labels.unitHints[unit];
|
|
646
|
+
if (unit === "month" || unit === "quarter") {
|
|
647
|
+
const name = (m) => unit === "quarter" ? `Q${Math.floor(m / 3) + 1}` : dateFormatter(locale, { calendar: "gregory", month: "short", timeZone: "UTC" }).format(new Date(Date.UTC(2e3, m, 1)));
|
|
648
|
+
const periods = [...new Set(months.map((m) => unit === "quarter" ? Math.floor(m / 3) : m))];
|
|
649
|
+
const runs = [];
|
|
650
|
+
const text = (p) => name(unit === "quarter" ? p * 3 : p);
|
|
651
|
+
for (let i = 0; i < periods.length; i++) {
|
|
652
|
+
const first2 = periods[i];
|
|
653
|
+
while (i + 1 < periods.length && periods[i + 1] === periods[i] + 1) i++;
|
|
654
|
+
runs.push(first2 === periods[i] ? text(first2) : `${text(first2)}\u2013${text(periods[i])}`);
|
|
655
|
+
}
|
|
656
|
+
example = runs.join(", ");
|
|
657
|
+
}
|
|
658
|
+
return `${example} \xB7 ${plural(labels.groupYearsTogether, years, { lang: labels.lang, locale })}`;
|
|
659
|
+
}
|
|
660
|
+
if (unit === "yearQuarter") {
|
|
661
|
+
const q1 = Math.floor(first.getUTCMonth() / 3) + 1, q2 = Math.floor(last.getUTCMonth() / 3) + 1;
|
|
662
|
+
return `Q${q1} ${firstYear} \u2026 Q${q2} ${lastYear} (${(y2 - y1) * 4 + q2 - q1 + 1})`;
|
|
663
|
+
}
|
|
664
|
+
if (unit === "year") return `${firstYear} \u2026 ${lastYear} (${y2 - y1 + 1})`;
|
|
665
|
+
if (unit === "yearMonth") {
|
|
666
|
+
const fmt = dateFormatter(locale, { year: "numeric", month: "short", timeZone: "UTC", era });
|
|
667
|
+
const start = /* @__PURE__ */ new Date(0), end = /* @__PURE__ */ new Date(0);
|
|
668
|
+
start.setUTCFullYear(y1, first.getUTCMonth(), 1);
|
|
669
|
+
end.setUTCFullYear(y2, last.getUTCMonth(), 1);
|
|
670
|
+
return `${fmt.format(start)} \u2026 ${fmt.format(end)} (${(y2 - y1) * 12 + last.getUTCMonth() - first.getUTCMonth() + 1})`;
|
|
671
|
+
}
|
|
672
|
+
return dateRangeText(span, locale);
|
|
673
|
+
}
|
|
674
|
+
|
|
675
|
+
// src/menu-topics.js
|
|
676
|
+
import { valueAddsUp } from "pivotkit-core";
|
|
533
677
|
var FORMAT_CHOICES = Object.freeze(["number", "number:0", "number:2", "currency", "percent"].filter(isFormat2));
|
|
534
678
|
var MORE_FORMATS = Object.freeze(["integer", "compact", "bytes", "duration:h", "duration:s"].filter(isFormat2));
|
|
535
|
-
var COMMON_SHOW_AS =
|
|
679
|
+
var COMMON_SHOW_AS = CATALOG3.showAs.filter((s) => ["percentOfGrandTotal", "percentOfRowTotal", "percentOfColumnTotal"].includes(s));
|
|
536
680
|
var EXAMPLE = Object.freeze({ percent: 0.256, bytes: 1536e3, "duration:h": 1.5, "duration:s": 3725 });
|
|
537
681
|
var TOP_COUNTS = Object.freeze([3, 5, 10]);
|
|
538
682
|
function moveTopic(view, zone, index, count, labels, name, type, defaults) {
|
|
@@ -593,22 +737,26 @@ function axisTopics({ view, zone, index, field, types, labels, locale, state, de
|
|
|
593
737
|
filterTopic({ view, field, labels, locale, state, encoded })
|
|
594
738
|
];
|
|
595
739
|
if (date) {
|
|
740
|
+
const stats = groupStats(encoded, source);
|
|
741
|
+
const span = stats?.span;
|
|
742
|
+
const dateLocale = dateDisplayLocale(view.formatting?.locale || locale);
|
|
596
743
|
const regroup = (unit2) => () => {
|
|
597
744
|
const sourceName = fieldLabel2(source, labels.core);
|
|
598
745
|
const grouped = unit2 ? groupingName(sourceName, unit2, labels) : null;
|
|
599
746
|
return { view: groupField(view, field, unit2, { name: grouped ?? void 0 }).view, note: { step: "group", field: sourceName } };
|
|
600
747
|
};
|
|
601
|
-
const unit = (u) => ({ id: `group-${u}`, text: labels.units[u] ?? u, hint:
|
|
748
|
+
const unit = (u) => ({ id: `group-${u}`, text: labels.units[u] ?? u, hint: groupHint(encoded, source, u, dateLocale, labels, stats), checked: grouping?.by === u, closes: true, change: regroup(u) });
|
|
602
749
|
topics.push({
|
|
603
750
|
id: "group",
|
|
751
|
+
intro: span ? fill(plural(labels.groupDataRange, calendarDays(span), { lang: labels.lang, locale: dateLocale }), { range: dateRangeText(span, dateLocale) }) : void 0,
|
|
604
752
|
title: labels.groupTopic,
|
|
605
753
|
kind: "menu",
|
|
606
754
|
icon: "date",
|
|
607
755
|
state: grouping ? labels.units[grouping.by] ?? grouping.by : labels.groupNoneShort,
|
|
608
756
|
changed: Boolean(grouping),
|
|
609
757
|
groups: [
|
|
610
|
-
{ title: labels.groupTimeline, choices:
|
|
611
|
-
{ title: labels.groupCyclic, choices:
|
|
758
|
+
{ title: labels.groupTimeline, choices: CATALOG3.timelineUnits.map(unit) },
|
|
759
|
+
{ title: labels.groupCyclic, choices: CATALOG3.cyclicUnits.map(unit) },
|
|
612
760
|
{ choices: [{ id: "group-none", text: labels.groupNone, checked: !grouping, closes: true, change: regroup(null) }] }
|
|
613
761
|
]
|
|
614
762
|
});
|
|
@@ -648,7 +796,7 @@ function filterTopic({ view, field, labels, locale, state, encoded }) {
|
|
|
648
796
|
if (!Number.isSafeInteger(n) || n < 1) {
|
|
649
797
|
return [];
|
|
650
798
|
}
|
|
651
|
-
const units = n >
|
|
799
|
+
const units = n > CATALOG3.relativeMaxCount ? [] : fk.months ? ["year", "month"] : ["year"];
|
|
652
800
|
const anchor = filtersOf(view, field, ["relative"])[0]?.anchor;
|
|
653
801
|
const previous = quickChoice(view, field, fk).filters[0] ?? null;
|
|
654
802
|
const blanks = keepsBlanks(view, field) ? "include" : "exclude";
|
|
@@ -709,11 +857,11 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
|
|
|
709
857
|
const spec = view.values[index];
|
|
710
858
|
const type = spec.field ? types.get(spec.field.toLowerCase()) ?? "string" : "number";
|
|
711
859
|
const defaults = spec.field ? defaultsOf?.(spec.field) : void 0;
|
|
712
|
-
const name =
|
|
860
|
+
const name = valueLabels(view.values, labels)[index];
|
|
713
861
|
const set = (patch) => () => ({ view: updateValue(view, index, patch, { defaults }), note: { step: "value", field: name } });
|
|
714
862
|
const aggs = spec.field ? aggregatorsFor(type) : ["count"];
|
|
715
863
|
const agg = (a) => ({ id: `agg-${a}`, text: labels.core.aggregators[a] ?? a, checked: spec.agg === a, closes: true, change: set({ agg: a }) });
|
|
716
|
-
const rare = aggs.filter((a) => !
|
|
864
|
+
const rare = aggs.filter((a) => !CATALOG3.commonAggregators.includes(a));
|
|
717
865
|
const topics = [
|
|
718
866
|
{
|
|
719
867
|
id: "summarize",
|
|
@@ -721,7 +869,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
|
|
|
721
869
|
kind: "menu",
|
|
722
870
|
icon: "sigma",
|
|
723
871
|
state: labels.core.aggregators[spec.agg] ?? spec.agg,
|
|
724
|
-
groups: [{ choices:
|
|
872
|
+
groups: [{ choices: CATALOG3.commonAggregators.filter((a) => aggs.includes(a)).map(agg) }, ...rare.length ? [{ title: labels.moreStatistics, choices: rare.map(agg) }] : []]
|
|
725
873
|
}
|
|
726
874
|
];
|
|
727
875
|
if (numericResult(spec, type)) {
|
|
@@ -729,7 +877,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
|
|
|
729
877
|
const text = labels.showAsNames[s] ?? s;
|
|
730
878
|
return { id: `showas-${s}`, text, keywords: text.includes("%") ? labels.showAsKeywords : void 0, checked: spec.showAs?.type === s, change: set({ showAs: { type: s, axis: spec.showAs?.axis ?? "rows" } }) };
|
|
731
879
|
};
|
|
732
|
-
const along = spec.showAs &&
|
|
880
|
+
const along = spec.showAs && CATALOG3.showAsAlongAxis.includes(spec.showAs.type) ? spec.showAs : null;
|
|
733
881
|
topics.push({
|
|
734
882
|
id: "showAs",
|
|
735
883
|
title: labels.showAs,
|
|
@@ -740,7 +888,7 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
|
|
|
740
888
|
changed: Boolean(spec.showAs),
|
|
741
889
|
groups: [
|
|
742
890
|
{ choices: [{ id: "showas-none", text: labels.showAsNone, checked: !spec.showAs, change: set({ showAs: null }) }, ...COMMON_SHOW_AS.map(showAs)] },
|
|
743
|
-
{ title: labels.moreCalculations, choices:
|
|
891
|
+
{ title: labels.moreCalculations, choices: CATALOG3.showAs.filter((s) => !COMMON_SHOW_AS.includes(s)).map(showAs) },
|
|
744
892
|
...along ? [{ title: labels.along, choices: ["rows", "cols"].map((axis) => ({ id: `along-${axis}`, text: labels.zones[axis], checked: along.axis === axis, change: set({ showAs: { ...along, axis } }) })) }] : []
|
|
745
893
|
]
|
|
746
894
|
});
|
|
@@ -802,17 +950,29 @@ function valueTopics({ view, index, types, labels, locale, defaultsOf, earlier }
|
|
|
802
950
|
topics.push(moveTopic(view, "values", index, view.values.length, labels, name, type));
|
|
803
951
|
return topics;
|
|
804
952
|
}
|
|
805
|
-
function
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
help.push({ id: "show-tips", text: labels.showTips, checkbox: true, checked: tips.on, run: () => act.tipsOn(!tips.on) });
|
|
953
|
+
function rowFoldTexts(view, labels) {
|
|
954
|
+
if (view.rows.length < 2) {
|
|
955
|
+
return { expand: labels.chartShowDetails, collapse: labels.chartShowTotals, named: false };
|
|
809
956
|
}
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
957
|
+
const name = (f) => fieldLabel2(f, labels.core);
|
|
958
|
+
return { expand: fill(labels.chartShowEach, { field: name(view.rows.at(-1)) }), collapse: fill(labels.chartShowOnly, { field: name(view.rows[0]) }), named: true };
|
|
959
|
+
}
|
|
960
|
+
function foldState(view, folding, labels) {
|
|
961
|
+
const name = (f) => fieldLabel2(f, labels.core);
|
|
962
|
+
if (!folding.collapsed) {
|
|
963
|
+
return { text: fill(labels.chartFoldEach, { field: name(view.rows.at(-1)) }), changed: false };
|
|
815
964
|
}
|
|
965
|
+
return { text: folding.canCollapse ? labels.chartFoldSome : fill(labels.chartFoldOnly, { field: name(view.rows[0]) }), changed: true };
|
|
966
|
+
}
|
|
967
|
+
function foldChoices(folding, labels, act, words, ids) {
|
|
968
|
+
const why = (key) => key && Object.hasOwn(labels, key) ? labels[key] : void 0;
|
|
969
|
+
return [
|
|
970
|
+
{ id: ids[0], text: words.expand, icon: "plus", closes: true, disabled: !folding.canExpand, reason: why(folding.why.expand), run: act.expand },
|
|
971
|
+
{ id: ids[1], text: words.collapse, icon: "chevronRight", hint: words.hint, closes: true, disabled: !folding.canCollapse, reason: why(folding.why.collapse), run: act.collapse }
|
|
972
|
+
];
|
|
973
|
+
}
|
|
974
|
+
function tableTopics({ view, labels, folding, act }) {
|
|
975
|
+
const words = rowFoldTexts(view, labels);
|
|
816
976
|
return [
|
|
817
977
|
{
|
|
818
978
|
id: "totals",
|
|
@@ -833,18 +993,157 @@ function optionTopics({ view, labels, folding, tips, explanations, act }) {
|
|
|
833
993
|
title: labels.zones.rows,
|
|
834
994
|
kind: "inline",
|
|
835
995
|
titled: true,
|
|
996
|
+
groups: [{ choices: foldChoices(folding, labels, act, { expand: labels.expandAll, collapse: labels.collapseAll, hint: words.named ? words.collapse : void 0 }, ["expand-all", "collapse-all"]) }]
|
|
997
|
+
}
|
|
998
|
+
];
|
|
999
|
+
}
|
|
1000
|
+
function moreTopics({ labels, tips, explanations, act }) {
|
|
1001
|
+
const help = [];
|
|
1002
|
+
if (tips.controls) {
|
|
1003
|
+
help.push({ id: "show-tips", text: labels.showTips, checkbox: true, checked: tips.on, run: () => act.tipsOn(!tips.on) });
|
|
1004
|
+
}
|
|
1005
|
+
if (explanations) {
|
|
1006
|
+
help.push({ id: "show-explanations", text: labels.showSettingInfo, checkbox: true, checked: explanations.on, run: () => act.explain(!explanations.on) });
|
|
1007
|
+
}
|
|
1008
|
+
if (tips.controls) {
|
|
1009
|
+
help.push({ id: "reset-tips", text: labels.resetTips, icon: "reset", disabled: !tips.canReset, run: act.resetTips });
|
|
1010
|
+
}
|
|
1011
|
+
help.push({ id: "shortcuts", text: labels.shortcutsTitle, icon: "info", open: "shortcuts" });
|
|
1012
|
+
return [
|
|
1013
|
+
{ id: "help", title: labels.helpAndShortcuts, levelTitle: labels.help, kind: "menu", icon: "info", testId: "more-help", groups: [{ choices: help }] },
|
|
1014
|
+
{ id: "shortcuts", title: labels.shortcutsTitle, kind: "panel", hidden: true, levelTitle: `${labels.help} \u203A ${labels.shortcutsTitle}` }
|
|
1015
|
+
];
|
|
1016
|
+
}
|
|
1017
|
+
var VALUE_LABELS = Object.freeze({ slices: ["auto", "off", "value", "percent", "both"], other: ["auto", "off", "value"] });
|
|
1018
|
+
function chartTopics({ view, drawn, labels, names, act, lines = { rules: { average: true, trend: true, target: true, notes: [] }, targetText: "" }, drawnColors = /* @__PURE__ */ new Map(), folding }) {
|
|
1019
|
+
const chart = view.chart;
|
|
1020
|
+
const pie = SLICE_TYPES.includes(drawn);
|
|
1021
|
+
const axis = CHART_TYPES[drawn]?.axis ?? false;
|
|
1022
|
+
const pickOf = (key, value, text, id, info = void 0) => ({ id, text, checked: (chart[key] ?? null) === value, info, run: () => act.display({ [key]: value }) });
|
|
1023
|
+
const flip = (key, text, id, info = void 0) => ({ id, text, checkbox: true, checked: Boolean(chart[key]), info, run: () => act.display({ [key]: !chart[key] }) });
|
|
1024
|
+
const valueLabels2 = !pie && (chart.valueLabels === "percent" || chart.valueLabels === "both") ? "value" : chart.valueLabels;
|
|
1025
|
+
const topics = [
|
|
1026
|
+
{
|
|
1027
|
+
id: "valueLabels",
|
|
1028
|
+
title: labels.valueLabels,
|
|
1029
|
+
kind: "menu",
|
|
1030
|
+
state: labels.valueLabelNames[valueLabels2],
|
|
1031
|
+
changed: valueLabels2 !== "auto",
|
|
1032
|
+
groups: [{ choices: (pie ? VALUE_LABELS.slices : VALUE_LABELS.other).map((v) => ({ ...pickOf("valueLabels", v, labels.valueLabelNames[v], `labels-${v}`), checked: valueLabels2 === v })) }]
|
|
1033
|
+
},
|
|
1034
|
+
{ id: "legend", title: labels.legend, kind: "menu", state: labels.legendNames[chart.legend], changed: chart.legend !== "auto", groups: [{ choices: ["auto", "bottom", "right", "off"].map((v) => pickOf("legend", v, labels.legendNames[v], `legend-${v}`)) }] },
|
|
1035
|
+
{ id: "title", title: labels.chartTitle, kind: "panel", state: chart.title || labels.chartTitleNone, changed: Boolean(chart.title) }
|
|
1036
|
+
];
|
|
1037
|
+
if (axis) {
|
|
1038
|
+
const groups = view.rows.length >= 2;
|
|
1039
|
+
const off = [groups && chart.groupLabels !== "auto" ? `${labels.groupLabels.toLowerCase()} ${labels.groupLabelNames[chart.groupLabels].toLowerCase()}` : null, chart.zoom !== "auto" ? `${labels.zoom.toLowerCase()} ${labels.zoomNames[chart.zoom].toLowerCase()}` : null].filter(Boolean);
|
|
1040
|
+
topics.push({
|
|
1041
|
+
id: "axis",
|
|
1042
|
+
title: labels.chartAxis,
|
|
1043
|
+
kind: "menu",
|
|
1044
|
+
state: [labels.axisLabelNames[chart.axisLabels], ...off].join(", "),
|
|
1045
|
+
changed: chart.axisLabels !== "auto" || off.length > 0,
|
|
1046
|
+
groups: [
|
|
1047
|
+
{ title: labels.axisLabels, choices: ["auto", "all", "nth"].map((v) => pickOf("axisLabels", v, labels.axisLabelNames[v], `axis-${v}`)) },
|
|
1048
|
+
...groups ? [{ title: labels.groupLabels, choices: ["auto", "on", "off"].map((v) => pickOf("groupLabels", v, labels.groupLabelNames[v], `groups-${v}`, v === "auto" ? "groupLabels" : void 0)) }] : [],
|
|
1049
|
+
{ title: labels.zoom, choices: ["auto", "on", "off"].map((v) => pickOf("zoom", v, labels.zoomNames[v], `zoom-${v}`, v === "auto" ? "zoom" : void 0)) }
|
|
1050
|
+
]
|
|
1051
|
+
});
|
|
1052
|
+
}
|
|
1053
|
+
if (drawn !== "heatmap") {
|
|
1054
|
+
const mode = chart.tooltip ?? "auto";
|
|
1055
|
+
const state = [axis ? labels.tooltipNames[mode] : null, chart.tooltipShare ? labels.tooltipShare : null].filter(Boolean).join(", ");
|
|
1056
|
+
topics.push({
|
|
1057
|
+
id: "tooltip",
|
|
1058
|
+
title: labels.tooltip,
|
|
1059
|
+
kind: "menu",
|
|
1060
|
+
info: axis ? "tooltip" : void 0,
|
|
1061
|
+
state: state || null,
|
|
1062
|
+
changed: mode !== "auto" || Boolean(chart.tooltipShare),
|
|
1063
|
+
groups: [...axis ? [{ choices: ["auto", "axis"].map((v) => pickOf("tooltip", v, labels.tooltipNames[v], `tooltip-${v}`)) }] : [], { choices: [flip("tooltipShare", labels.tooltipShare, "chart-tooltip-share")] }]
|
|
1064
|
+
});
|
|
1065
|
+
}
|
|
1066
|
+
if (axis) {
|
|
1067
|
+
const now = chart.referenceLines ?? { average: false, trend: false, target: null };
|
|
1068
|
+
const words = labels.core.referenceLines;
|
|
1069
|
+
const { rules, targetText } = lines;
|
|
1070
|
+
const notes = Array.isArray(rules.notes) ? rules.notes : [];
|
|
1071
|
+
const say = (keys) => {
|
|
1072
|
+
const note2 = notes.find((n) => keys.includes(n));
|
|
1073
|
+
return note2 && Object.hasOwn(labels.linesNotes, note2) ? labels.linesNotes[note2] : void 0;
|
|
1074
|
+
};
|
|
1075
|
+
const total = ["noTotal", "percentStack", "negative"];
|
|
1076
|
+
const set = (patch) => act.display({ referenceLines: { ...now, ...patch } });
|
|
1077
|
+
const choices = [
|
|
1078
|
+
{ id: "line-average", text: words.average, checkbox: true, checked: now.average, disabled: !rules.average, reason: rules.average ? void 0 : say(total), run: () => set({ average: !now.average }) },
|
|
1079
|
+
{ id: "line-trend", text: words.trend, checkbox: true, checked: now.trend, disabled: !rules.trend, reason: rules.trend ? void 0 : say([...total, "noTime"]), run: () => set({ trend: !now.trend }) },
|
|
1080
|
+
{ id: "line-target", text: words.target, hint: now.target !== null ? targetText : labels.targetNone, open: "linesTarget", disabled: !rules.target, reason: rules.target ? void 0 : say(["noTotal", "percentStack", "mixedUnits"]) },
|
|
1081
|
+
// a target the chart cannot draw stays removable
|
|
1082
|
+
...!rules.target && now.target !== null ? [{ id: "target-remove", text: labels.targetRemove, run: () => set({ target: null }) }] : []
|
|
1083
|
+
];
|
|
1084
|
+
const on2 = [now.average ? words.average : null, now.trend ? words.trend : null, now.target !== null ? words.target : null].filter(Boolean);
|
|
1085
|
+
const note = notes.includes("table") ? labels.linesNotes.table : notes.includes("byIndex") && rules.trend ? labels.linesNotes.byIndex : null;
|
|
1086
|
+
topics.push({ id: "lines", title: labels.referenceLines, kind: "menu", state: on2.length ? on2.join(", ") : labels.linesOff, changed: on2.length > 0, groups: [{ choices }], note, noteId: "lines-note" });
|
|
1087
|
+
topics.push({ id: "linesTarget", title: words.target, kind: "panel", hidden: true, levelTitle: `${labels.referenceLines} \u203A ${words.target}` });
|
|
1088
|
+
}
|
|
1089
|
+
if (names.length > 0) {
|
|
1090
|
+
const only = names.length === 1;
|
|
1091
|
+
const hidden = (chart.hidden ?? []).filter((n) => names.includes(n)).length;
|
|
1092
|
+
const now = chart.hidden ?? [];
|
|
1093
|
+
const own = chart.colors ?? [];
|
|
1094
|
+
const same2 = (a, b) => a.toLowerCase() === b.toLowerCase();
|
|
1095
|
+
const recolor = (name, color) => act.display({ colors: [...own.filter((c) => !same2(c.name, name)), ...color ? [{ name, color }] : []] });
|
|
1096
|
+
const stale = own.filter((c) => !names.some((n) => same2(n, c.name)));
|
|
1097
|
+
topics.push({
|
|
1098
|
+
id: "series",
|
|
1099
|
+
title: labels.shownSeries,
|
|
1100
|
+
kind: "menu",
|
|
1101
|
+
info: "chartColors",
|
|
1102
|
+
state: fill(labels.seriesShownOf, { shown: String(names.length - hidden), count: String(names.length) }),
|
|
1103
|
+
changed: hidden > 0 || own.length > 0,
|
|
1104
|
+
// every series or slice, the level scrolls; a switch keeps the level open for the next one;
|
|
1105
|
+
// beside each its colour, and Default where the view fixes one
|
|
836
1106
|
groups: [
|
|
837
1107
|
{
|
|
838
|
-
choices:
|
|
839
|
-
|
|
840
|
-
{
|
|
841
|
-
|
|
842
|
-
|
|
1108
|
+
choices: names.map((name, i) => {
|
|
1109
|
+
const mine = own.find((c) => same2(c.name, name));
|
|
1110
|
+
return {
|
|
1111
|
+
id: `series-${i}`,
|
|
1112
|
+
text: name,
|
|
1113
|
+
checkbox: true,
|
|
1114
|
+
checked: only || !now.includes(name),
|
|
1115
|
+
...only ? { disabled: true, reason: labels.seriesOnly } : {},
|
|
1116
|
+
run: () => act.display({ hidden: hiddenAfter(now, name, now.includes(name)) }),
|
|
1117
|
+
color: { id: `series-${i}-color`, value: mine?.color ?? drawnColors.get(name) ?? "", label: fill(labels.colorOf, { name }), pick: (c) => recolor(name, c) },
|
|
1118
|
+
...mine ? { actions: [{ id: `series-${i}-default`, text: labels.colorDefault, label: `${labels.colorDefault}: ${name}`, icon: "reset", run: () => recolor(name, null) }] } : {}
|
|
1119
|
+
};
|
|
1120
|
+
})
|
|
1121
|
+
},
|
|
1122
|
+
// a view's colour for a name the chart does not show: Remove
|
|
1123
|
+
...stale.length ? [{ title: labels.colorsNotShown, choices: stale.map((c, i) => ({ id: `color-stale-${i}`, text: c.name, label: `${labels.colorRemove}: ${c.name}`, icon: "x", run: () => recolor(c.name, null) })) }] : []
|
|
843
1124
|
]
|
|
844
|
-
}
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
1125
|
+
});
|
|
1126
|
+
}
|
|
1127
|
+
const layout = [];
|
|
1128
|
+
if ((drawn === "stacked" || drawn === "area") && view.values.length > 0 && view.values.every(valueAddsUp)) {
|
|
1129
|
+
layout.push(flip("stackPercent", labels.stackPercent, "chart-stack-percent", "stackPercent"));
|
|
1130
|
+
}
|
|
1131
|
+
if (drawn === "line" || drawn === "area") {
|
|
1132
|
+
layout.push(flip("smooth", labels.smoothLines, "chart-smooth"));
|
|
1133
|
+
}
|
|
1134
|
+
if (pie) {
|
|
1135
|
+
layout.push(...["outside", "inside"].map((v) => ({ ...pickOf("labelPosition", v, labels.labelPositionNames[v], `label-position-${v}`, v === "outside" ? "labelPosition" : void 0), checked: (chart.labelPosition ?? "outside") === v, disabled: chart.valueLabels === "off" })));
|
|
1136
|
+
}
|
|
1137
|
+
const on = layout.filter((c) => c.checked && (c.checkbox || c.id === "label-position-inside")).map((c) => c.text);
|
|
1138
|
+
if (folding && act.expand && act.collapse) {
|
|
1139
|
+
layout.push(...foldChoices(folding, labels, { expand: act.expand, collapse: act.collapse }, rowFoldTexts(view, labels), ["chart-show-each", "chart-show-only"]));
|
|
1140
|
+
}
|
|
1141
|
+
const fold = folding && view.rows.length >= 2 ? foldState(view, folding, labels) : null;
|
|
1142
|
+
if (layout.length) {
|
|
1143
|
+
const state = [...on, ...fold ? [fold.text] : []].join(", ");
|
|
1144
|
+
topics.push({ id: "layout", title: labels.chartLayout, kind: "menu", state: state || null, changed: on.length > 0 || Boolean(fold?.changed), groups: [{ choices: layout }] });
|
|
1145
|
+
}
|
|
1146
|
+
return topics;
|
|
848
1147
|
}
|
|
849
1148
|
function entryIds(templates) {
|
|
850
1149
|
const seen = /* @__PURE__ */ new Map();
|
|
@@ -942,7 +1241,7 @@ function tabLeaves(e, close) {
|
|
|
942
1241
|
close();
|
|
943
1242
|
return true;
|
|
944
1243
|
}
|
|
945
|
-
function MenuList({ label, labelledBy, className, close, children, testId }) {
|
|
1244
|
+
function MenuList({ label, labelledBy, describedBy, className, close, children, testId }) {
|
|
946
1245
|
const ref = useRef(
|
|
947
1246
|
/** @type {HTMLDivElement | null} */
|
|
948
1247
|
null
|
|
@@ -994,6 +1293,7 @@ function MenuList({ label, labelledBy, className, close, children, testId }) {
|
|
|
994
1293
|
e.preventDefault();
|
|
995
1294
|
e.stopPropagation();
|
|
996
1295
|
items[i].focus();
|
|
1296
|
+
items[i].scrollIntoView?.({ block: "nearest" });
|
|
997
1297
|
}
|
|
998
1298
|
};
|
|
999
1299
|
const seg = (
|
|
@@ -1037,12 +1337,13 @@ function MenuList({ label, labelledBy, className, close, children, testId }) {
|
|
|
1037
1337
|
go(typeAheadIndex(items.map((el) => el.dataset.pkText ?? el.textContent ?? ""), at, typed.current.text));
|
|
1038
1338
|
}
|
|
1039
1339
|
};
|
|
1040
|
-
return /* @__PURE__ */ React3.createElement("div", { ref, role: "menu", "aria-label": label, "aria-labelledby": labelledBy, className: `pk-level-menu${className ? ` ${className}` : ""}`, onKeyDown, onFocus, "data-testid": testId }, children);
|
|
1340
|
+
return /* @__PURE__ */ React3.createElement("div", { ref, role: "menu", "aria-label": label, "aria-labelledby": labelledBy, "aria-describedby": describedBy, className: `pk-level-menu${className ? ` ${className}` : ""}`, onKeyDown, onFocus, "data-testid": testId }, children);
|
|
1041
1341
|
}
|
|
1042
|
-
function MenuItem({ id, text, onSelect, checked, checkbox, hint, icon, danger, testId, start, plain, label, className, disabled, reason, haspopup, level, description, current, children }) {
|
|
1342
|
+
function MenuItem({ id, text, onSelect, checked, checkbox, hint, icon, danger, testId, start, plain, label, className, disabled, reason, haspopup, level, description, current, note, children }) {
|
|
1043
1343
|
const role = checked === void 0 ? "menuitem" : checkbox ? "menuitemcheckbox" : "menuitemradio";
|
|
1044
1344
|
const reasonId = useId();
|
|
1045
|
-
const
|
|
1345
|
+
const sub = disabled ? reason : note;
|
|
1346
|
+
const describedBy = [sub ? reasonId : null, description ? `${reasonId}-d` : null].filter(Boolean).join(" ") || void 0;
|
|
1046
1347
|
return /* @__PURE__ */ React3.createElement(
|
|
1047
1348
|
"button",
|
|
1048
1349
|
{
|
|
@@ -1068,7 +1369,7 @@ function MenuItem({ id, text, onSelect, checked, checkbox, hint, icon, danger, t
|
|
|
1068
1369
|
/** @type {any} */
|
|
1069
1370
|
icon
|
|
1070
1371
|
) }) : null),
|
|
1071
|
-
/* @__PURE__ */ React3.createElement("span", { className: "pk-option-text" }, text,
|
|
1372
|
+
/* @__PURE__ */ React3.createElement("span", { className: "pk-option-text" }, text, sub ? /* @__PURE__ */ React3.createElement("span", { id: reasonId, className: "pk-option-hint", "data-testid": `${testId ?? id}-${disabled ? "reason" : "note"}` }, sub) : null),
|
|
1072
1373
|
hint ? /* @__PURE__ */ React3.createElement("span", { className: "pk-item-hint" }, hint) : null,
|
|
1073
1374
|
description ? /* @__PURE__ */ React3.createElement("span", { id: `${reasonId}-d`, hidden: true }, description) : null,
|
|
1074
1375
|
children
|
|
@@ -1077,11 +1378,15 @@ function MenuItem({ id, text, onSelect, checked, checkbox, hint, icon, danger, t
|
|
|
1077
1378
|
function ChoiceItem({ choice: c, onPick, start }) {
|
|
1078
1379
|
const { explain, labels } = useContext2(HelpContext);
|
|
1079
1380
|
const text = c.info && explain && labels?.settingInfo && Object.hasOwn(labels.settingInfo, c.info) ? labels.settingInfo[c.info] : null;
|
|
1080
|
-
const
|
|
1081
|
-
|
|
1381
|
+
const className = [c.open ? "pk-topic-row" : null, c.className].filter(Boolean).join(" ") || void 0;
|
|
1382
|
+
const item = /* @__PURE__ */ React3.createElement(MenuItem, { id: c.id, testId: c.testId, text: c.text, label: c.label, hint: c.hint, icon: c.icon, checked: c.checked, checkbox: c.checkbox, current: c.current, disabled: c.disabled, reason: c.reason, description: text, note: c.note, start, haspopup: c.open ? "dialog" : void 0, className, onSelect: () => onPick(c) }, (c.tags ?? []).map((t) => /* @__PURE__ */ React3.createElement("span", { key: t.text, className: "pk-tag", "aria-hidden": "true" }, /* @__PURE__ */ React3.createElement(Icon, { name: (
|
|
1383
|
+
/** @type {any} */
|
|
1384
|
+
t.icon
|
|
1385
|
+
), size: 12 }), t.text)), c.open ? /* @__PURE__ */ React3.createElement(Icon, { name: "chevronRight", size: 16, className: "pk-topic-chevron" }) : null);
|
|
1386
|
+
if (!text && !c.actions?.length && !c.color) {
|
|
1082
1387
|
return item;
|
|
1083
1388
|
}
|
|
1084
|
-
return /* @__PURE__ */ React3.createElement("div", { role: "none", className: "pk-setting-row" }, item, (c.actions ?? []).map((a) => /* @__PURE__ */ React3.createElement("button", { key: a.id, type: "button", role: "menuitem", tabIndex: -1, className: "pk-icon-btn", "aria-label": a.label, title: a.label, "aria-haspopup": a.open ? "dialog" : void 0, "data-pk-item": a.id, "data-pk-text": a.label, "data-testid": a.testId ?? a.id, onClick: () => onPick(a) }, /* @__PURE__ */ React3.createElement(Icon, { name: (
|
|
1389
|
+
return /* @__PURE__ */ React3.createElement("div", { role: "none", className: "pk-setting-row" }, item, c.color ? /* @__PURE__ */ React3.createElement(ColorPick, { ...c.color }) : null, (c.actions ?? []).map((a) => /* @__PURE__ */ React3.createElement("button", { key: a.id, type: "button", role: "menuitem", tabIndex: -1, className: "pk-icon-btn", "aria-label": a.label, title: a.label, "aria-haspopup": a.open ? "dialog" : void 0, "data-pk-item": a.id, "data-pk-text": a.label, "data-testid": a.testId ?? a.id, onClick: () => onPick(a) }, /* @__PURE__ */ React3.createElement(Icon, { name: (
|
|
1085
1390
|
/** @type {any} */
|
|
1086
1391
|
a.icon
|
|
1087
1392
|
) }))), text ? /* @__PURE__ */ React3.createElement("span", { "aria-hidden": "true" }, /* @__PURE__ */ React3.createElement(SettingInfo, { id: (
|
|
@@ -1089,11 +1394,43 @@ function ChoiceItem({ choice: c, onPick, start }) {
|
|
|
1089
1394
|
c.info
|
|
1090
1395
|
), name: c.text, tabIndex: -1 })) : null);
|
|
1091
1396
|
}
|
|
1397
|
+
function ColorPick({ id, value, label, pick: pick2 }) {
|
|
1398
|
+
const field = useRef(
|
|
1399
|
+
/** @type {HTMLInputElement | null} */
|
|
1400
|
+
null
|
|
1401
|
+
);
|
|
1402
|
+
const button = useRef(
|
|
1403
|
+
/** @type {HTMLButtonElement | null} */
|
|
1404
|
+
null
|
|
1405
|
+
);
|
|
1406
|
+
const latest = useRef(pick2);
|
|
1407
|
+
useEffect(() => {
|
|
1408
|
+
latest.current = pick2;
|
|
1409
|
+
});
|
|
1410
|
+
useEffect(() => {
|
|
1411
|
+
const el = field.current;
|
|
1412
|
+
const picked = () => {
|
|
1413
|
+
if (el) {
|
|
1414
|
+
latest.current(el.value);
|
|
1415
|
+
button.current?.focus({ preventScroll: true });
|
|
1416
|
+
}
|
|
1417
|
+
};
|
|
1418
|
+
el?.addEventListener("change", picked);
|
|
1419
|
+
return () => el?.removeEventListener("change", picked);
|
|
1420
|
+
}, []);
|
|
1421
|
+
useEffect(() => {
|
|
1422
|
+
if (field.current && value && field.current.value !== value) {
|
|
1423
|
+
field.current.value = value;
|
|
1424
|
+
}
|
|
1425
|
+
}, [value]);
|
|
1426
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("button", { ref: button, type: "button", role: "menuitem", tabIndex: -1, className: "pk-icon-btn pk-color-pick", "aria-label": value ? `${label}, ${value}` : label, "aria-haspopup": "dialog", title: label, "data-pk-item": id, "data-pk-text": label, "data-testid": id, onClick: () => field.current?.click() }, /* @__PURE__ */ React3.createElement("span", { className: "pk-dot", "aria-hidden": "true", ref: (el) => el?.style.setProperty("background-color", value || "transparent") })), /* @__PURE__ */ React3.createElement("input", { ref: field, type: "color", className: "pk-sr", tabIndex: -1, "aria-hidden": "true", defaultValue: value || void 0, "data-testid": `${id}-field` }));
|
|
1427
|
+
}
|
|
1092
1428
|
function TopicRow({ topic, labels, onOpen }) {
|
|
1093
1429
|
return /* @__PURE__ */ React3.createElement(
|
|
1094
1430
|
MenuItem,
|
|
1095
1431
|
{
|
|
1096
1432
|
id: `topic-${topic.id}`,
|
|
1433
|
+
testId: topic.testId,
|
|
1097
1434
|
level: topic.id,
|
|
1098
1435
|
text: topic.title,
|
|
1099
1436
|
plain: topic.title,
|
|
@@ -1139,7 +1476,7 @@ function SearchHits({ hits, labels, onPick, onOpen, close }) {
|
|
|
1139
1476
|
}
|
|
1140
1477
|
return /* @__PURE__ */ React3.createElement(MenuList, { label: labels.searchResults, close, testId: "menu-search-hits" }, hits.map((h) => /* @__PURE__ */ React3.createElement(MenuItem, { key: h.id, id: `hit-${h.id}`, text: h.choice ? h.text : `${h.text}\u2026`, plain: h.text, checked: h.choice?.checked, icon: h.choice ? h.topic.icon : "chevronRight", hint: h.path || void 0, haspopup: h.choice ? void 0 : "dialog", onSelect: () => h.choice ? onPick(h.choice) : onOpen(h.topic.id, void 0, h.focus) })));
|
|
1141
1478
|
}
|
|
1142
|
-
function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, search = false, locale, focusAgain }) {
|
|
1479
|
+
function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, search = false, locale, focusAgain, filter, searchText }) {
|
|
1143
1480
|
const [nav, setNav] = useState2(
|
|
1144
1481
|
/** @type {{ stack: Array<{ level: string, from: string, hint?: string }>, focus: string | null }} */
|
|
1145
1482
|
{ stack: [], focus: null }
|
|
@@ -1178,6 +1515,11 @@ function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, sea
|
|
|
1178
1515
|
open(choice.open, choice.backTo ?? `item:${choice.id}`);
|
|
1179
1516
|
return;
|
|
1180
1517
|
}
|
|
1518
|
+
if (choice.checkbox && nav.stack.length) {
|
|
1519
|
+
onPick(choice);
|
|
1520
|
+
setNav({ stack: nav.stack, focus: `item:${choice.id}` });
|
|
1521
|
+
return;
|
|
1522
|
+
}
|
|
1181
1523
|
if (!choice.closes) {
|
|
1182
1524
|
setNav({ stack: [], focus: query ? "search" : nav.stack.length ? nav.stack[0].from : `item:${choice.id}` });
|
|
1183
1525
|
setQuery("");
|
|
@@ -1208,17 +1550,21 @@ function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, sea
|
|
|
1208
1550
|
}
|
|
1209
1551
|
};
|
|
1210
1552
|
const first = () => {
|
|
1211
|
-
const
|
|
1212
|
-
|
|
1553
|
+
const typed = search && query.trim() ? query : "";
|
|
1554
|
+
const shown = typed && filter ? filter(typed) : topics;
|
|
1555
|
+
const hits = typed && !filter ? searchHits(searchEntries(topics, query), query, locale) : null;
|
|
1556
|
+
const none = typed && filter && !shown.some((t) => !t.hidden && (t.groups ?? []).some((g) => g.choices.length));
|
|
1557
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, head, search ? /* @__PURE__ */ React3.createElement("label", { className: "pk-search pk-level-search" }, /* @__PURE__ */ React3.createElement(Icon, { name: "search" }), /* @__PURE__ */ React3.createElement("span", { className: "pk-sr" }, searchText ?? fill(labels.searchMenu, { name })), /* @__PURE__ */ React3.createElement(
|
|
1213
1558
|
ClearInput,
|
|
1214
1559
|
{
|
|
1215
1560
|
type: "search",
|
|
1216
1561
|
value: query,
|
|
1217
|
-
placeholder: labels.searchMenuShort,
|
|
1562
|
+
placeholder: searchText ?? labels.searchMenuShort,
|
|
1218
1563
|
onChange: setQuery,
|
|
1219
1564
|
clearLabel: labels.clearText,
|
|
1220
|
-
"aria-label": fill(labels.searchMenu, { name }),
|
|
1565
|
+
"aria-label": searchText ?? fill(labels.searchMenu, { name }),
|
|
1221
1566
|
autoComplete: "off",
|
|
1567
|
+
"data-autofocus": filter ? "" : void 0,
|
|
1222
1568
|
"data-testid": "menu-search",
|
|
1223
1569
|
onKeyDown: (e) => {
|
|
1224
1570
|
if (e.key === "ArrowDown") {
|
|
@@ -1229,9 +1575,9 @@ function LevelMenu({ name, labels, topics, close, onPick, panel, head, foot, sea
|
|
|
1229
1575
|
}
|
|
1230
1576
|
}
|
|
1231
1577
|
}
|
|
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" },
|
|
1578
|
+
)) : null, /* @__PURE__ */ React3.createElement("div", { className: "pk-level-first" }, hits || none ? /* @__PURE__ */ React3.createElement(SearchHits, { hits: hits ?? [], labels, onPick: pick2, onOpen: open, close }) : /* @__PURE__ */ React3.createElement(MenuList, { label: name, close, testId: "level-first" }, shown.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)));
|
|
1233
1579
|
};
|
|
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());
|
|
1580
|
+
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(React3.Fragment, null, topic.intro ? /* @__PURE__ */ React3.createElement("p", { id: `${titleId}-intro`, className: "pk-hint pk-menu-hint" }, topic.intro) : null, /* @__PURE__ */ React3.createElement(MenuList, { labelledBy: titleId, describedBy: topic.intro ? `${titleId}-intro` : void 0, 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());
|
|
1235
1581
|
}
|
|
1236
1582
|
function useLater(wait = 450) {
|
|
1237
1583
|
const timer = useRef(
|
|
@@ -1320,62 +1666,6 @@ function useAppliedText(applied, apply, wait = 450) {
|
|
|
1320
1666
|
|
|
1321
1667
|
// src/menu-fields.jsx
|
|
1322
1668
|
import React4, { useId as useId2 } from "react";
|
|
1323
|
-
|
|
1324
|
-
// src/numbers.js
|
|
1325
|
-
var cache = /* @__PURE__ */ new Map();
|
|
1326
|
-
function marks(locale) {
|
|
1327
|
-
let m = cache.get(locale);
|
|
1328
|
-
if (!m) {
|
|
1329
|
-
let parts;
|
|
1330
|
-
try {
|
|
1331
|
-
parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
1332
|
-
} catch {
|
|
1333
|
-
parts = new Intl.NumberFormat("en-US").formatToParts(12345.6);
|
|
1334
|
-
}
|
|
1335
|
-
m = {
|
|
1336
|
-
decimal: parts.find((p) => p.type === "decimal")?.value ?? ".",
|
|
1337
|
-
group: parts.find((p) => p.type === "group")?.value ?? ","
|
|
1338
|
-
};
|
|
1339
|
-
cache.set(locale, m);
|
|
1340
|
-
}
|
|
1341
|
-
return m;
|
|
1342
|
-
}
|
|
1343
|
-
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1344
|
-
var PLAIN = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
1345
|
-
function parseNumber(text, locale) {
|
|
1346
|
-
const t = String(text ?? "").replace(/[\s\u00a0\u202f]/g, "").replace(/\u2212/g, "-");
|
|
1347
|
-
if (t === "") {
|
|
1348
|
-
return null;
|
|
1349
|
-
}
|
|
1350
|
-
const { decimal, group } = marks(locale);
|
|
1351
|
-
const g = /[\s\u00a0\u202f]/.test(group) ? "" : escape(group);
|
|
1352
|
-
const d = escape(decimal);
|
|
1353
|
-
const grouped = g ? `\\d{1,3}(?:${g}\\d{3})+` : "(?!)";
|
|
1354
|
-
const local = new RegExp(`^([+-]?)(${grouped}|\\d+)?(?:${d}(\\d+))?$`);
|
|
1355
|
-
const match = local.exec(t);
|
|
1356
|
-
if (match && (match[2] !== void 0 || match[3] !== void 0)) {
|
|
1357
|
-
const whole = (match[2] ?? "0").split(group).join("");
|
|
1358
|
-
const n = Number(`${match[1]}${whole}${match[3] !== void 0 ? `.${match[3]}` : ""}`);
|
|
1359
|
-
return Number.isFinite(n) ? n : null;
|
|
1360
|
-
}
|
|
1361
|
-
if (PLAIN.test(t)) {
|
|
1362
|
-
const n = Number(t);
|
|
1363
|
-
return Number.isFinite(n) ? n : null;
|
|
1364
|
-
}
|
|
1365
|
-
return null;
|
|
1366
|
-
}
|
|
1367
|
-
function numberText(n, locale) {
|
|
1368
|
-
if (typeof n !== "number" || !Number.isFinite(n)) {
|
|
1369
|
-
return "";
|
|
1370
|
-
}
|
|
1371
|
-
try {
|
|
1372
|
-
return n.toLocaleString(locale, { useGrouping: false, maximumFractionDigits: 20 });
|
|
1373
|
-
} catch {
|
|
1374
|
-
return String(n);
|
|
1375
|
-
}
|
|
1376
|
-
}
|
|
1377
|
-
|
|
1378
|
-
// src/menu-fields.jsx
|
|
1379
1669
|
function readNumber(text, { kind = "number", required = true, tried = false, max, labels, locale }) {
|
|
1380
1670
|
const value = parseNumber(text, locale);
|
|
1381
1671
|
if (max !== void 0 && value !== null && Number.isInteger(value) && value > max) {
|
|
@@ -1547,6 +1837,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1547
1837
|
const weekStart = view.formatting?.weekStart;
|
|
1548
1838
|
const latestDay = isoDay(span.max);
|
|
1549
1839
|
const [now] = useState3(() => Date.now());
|
|
1840
|
+
const todayIso = todayIn(timeZone, now);
|
|
1550
1841
|
const datesOf = (spec, at = anchor) => {
|
|
1551
1842
|
try {
|
|
1552
1843
|
return relativeDateRange(spec.unit, spec.count ?? 1, { ...spec, anchor: at, timeZone, now, latest: span.max, first: span.min, weekStart });
|
|
@@ -1566,7 +1857,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1566
1857
|
};
|
|
1567
1858
|
const defaultCount = (unit) => Math.max(2, reach(unit));
|
|
1568
1859
|
const firstUnit = units.includes("month") ? "month" : units[0];
|
|
1569
|
-
const readCount = (text) => readNumber(text, { kind: "count", max:
|
|
1860
|
+
const readCount = (text) => readNumber(text, { kind: "count", max: CATALOG4.relativeMaxCount, labels, locale });
|
|
1570
1861
|
const rowOf = (d) => quick.id === d ? { text: numberText(quick.count, locale), unit: quick.unit, current: quick.includeCurrent } : { text: numberText(d === "next" ? 1 : defaultCount(firstUnit), locale), unit: firstUnit, current: true };
|
|
1571
1862
|
const [rows, setRows] = useState3(() => Object.fromEntries(COUNTED.map((d) => [d, rowOf(d)])));
|
|
1572
1863
|
const [thisUnit, setThisUnit] = useState3(quick.id === "this" ? quick.unit : "year");
|
|
@@ -1613,10 +1904,10 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1613
1904
|
if (range.from === null) {
|
|
1614
1905
|
period = fill(more.until, { to: periodText({ from: range.to, to: range.to }, shownUnit, locale) });
|
|
1615
1906
|
} else {
|
|
1616
|
-
const share = rangeShare(range, shownUnit, span, locale);
|
|
1907
|
+
const share = rangeShare(range, shownUnit, span, locale, todayIso);
|
|
1617
1908
|
if (share?.none) {
|
|
1618
1909
|
period = "";
|
|
1619
|
-
missing = fill(plural(labels.noData, 1, lang), { range: periodText(range, shownUnit, locale) });
|
|
1910
|
+
missing = fill(plural(labels.noData, 1, lang), { range: periodText({ from: range.from, to: share.to ?? range.to }, shownUnit, locale) });
|
|
1620
1911
|
} else {
|
|
1621
1912
|
period = share ? `${share.data} ` : periodText(range, shownUnit, locale);
|
|
1622
1913
|
missing = share ? fill(plural(labels.noData, share.count, lang), { range: share.missing.join(", ") }) : null;
|
|
@@ -1693,7 +1984,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1693
1984
|
change({ unit, ...keep ? {} : { text: numberText(defaultCount(unit), locale) } });
|
|
1694
1985
|
};
|
|
1695
1986
|
const current = datesOf({ direction: "this", unit: row.unit });
|
|
1696
|
-
const currentEmpty = current?.from ? rowsOf(current) === 0 : false;
|
|
1987
|
+
const currentEmpty = current?.from ? rowsOf(current) === 0 && dayMs(namedUntil({ from: current.from, to: current.to }, span, todayIso)) >= dayMs(current.from) : false;
|
|
1697
1988
|
return /* @__PURE__ */ React5.createElement("div", { className: "pk-quick-row", key: d }, radio(d, quick.id === d, () => change({}), name, /* @__PURE__ */ React5.createElement("span", { "aria-hidden": "true" }, capital(before.trimEnd(), locale)), range !== null), /* @__PURE__ */ React5.createElement(
|
|
1698
1989
|
NumberField,
|
|
1699
1990
|
{
|
|
@@ -1738,7 +2029,7 @@ function QuickChoices({ ctx, quick, anchor, setAnchorLocal, span, column, counts
|
|
|
1738
2029
|
), sub(range, row.unit, d), quick.id === d && !rolling ? /* @__PURE__ */ React5.createElement("label", { className: "pk-check pk-quick-current" }, /* @__PURE__ */ React5.createElement("input", { type: "checkbox", name: `${formName}-${d}-current`, checked: row.current, onChange: (e) => change({ current: e.target.checked }), "data-testid": `quick-${d}-current` }), /* @__PURE__ */ React5.createElement("span", null, labels.quickCurrent[row.unit], currentEmpty ? /* @__PURE__ */ React5.createElement("span", { className: "pk-quick-missing" }, ` (${fill(plural(labels.noData, 1, lang), { range: current?.from ? periodText({ from: current.from, to: current.to }, row.unit, locale) : "" })})`) : null)) : null, quick.id === d && d !== "next" && currentEmpty && anchor === "today" ? /* @__PURE__ */ React5.createElement("div", { className: "pk-quick-fix" }, /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-btn pk-small-btn", onClick: () => setAnchorTo("latest"), "data-testid": `quick-${d}-from-latest` }, /* @__PURE__ */ React5.createElement(Icon, { name: "date", size: 14 }), /* @__PURE__ */ React5.createElement("span", { className: "pk-btn-text" }, fill(labels.anchorUseLatest, { date: dayText(latestDay, locale) })))) : null);
|
|
1739
2030
|
};
|
|
1740
2031
|
main.push(counted("last"));
|
|
1741
|
-
const today = new Date(
|
|
2032
|
+
const today = new Date(todayIso);
|
|
1742
2033
|
const periodStart = fk.months ? Date.UTC(today.getUTCFullYear(), today.getUTCMonth(), 1) : Date.UTC(today.getUTCFullYear(), 0, 1);
|
|
1743
2034
|
const [anchorOutside] = useState3(() => span.max < periodStart || anchor !== "today");
|
|
1744
2035
|
const anchorKind = ["today", "latest", "first"].includes(anchor) ? anchor : "date";
|
|
@@ -1930,7 +2221,7 @@ function ItemRule({ rule, ctx, apply, unset, first }) {
|
|
|
1930
2221
|
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);
|
|
1931
2222
|
const entryOf = (x) => {
|
|
1932
2223
|
if (x.op === "last") {
|
|
1933
|
-
const n = readNumber(x.count, { kind: "count", max:
|
|
2224
|
+
const n = readNumber(x.count, { kind: "count", max: CATALOG4.relativeMaxCount, labels, locale }).value;
|
|
1934
2225
|
return n !== null ? { ...relativeRule(field, { unit: x.unit, count: n, anchor: ranged?.anchor }), ...ranged ? { not: ranged.not, blanks: ranged.blanks } : {} } : null;
|
|
1935
2226
|
}
|
|
1936
2227
|
const [a, b] = [read(x.a), read(x.b)];
|
|
@@ -1981,7 +2272,7 @@ function ItemRule({ rule, ctx, apply, unset, first }) {
|
|
|
1981
2272
|
};
|
|
1982
2273
|
const label = fk.item === "date" ? labels.ruleDate : labels.ruleValue;
|
|
1983
2274
|
const lang = { lang: labels.lang, locale };
|
|
1984
|
-
const counted = readNumber(s.count, { kind: "count", max:
|
|
2275
|
+
const counted = readNumber(s.count, { kind: "count", max: CATALOG4.relativeMaxCount, labels, locale });
|
|
1985
2276
|
const many = counted.value ?? 2;
|
|
1986
2277
|
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("span", { className: "pk-rule-subject" }, fieldLabel3(field, labels.core)), /* @__PURE__ */ React5.createElement("select", { className: "pk-rule-op", name: `${formName}-op`, value: s.op, onChange: (e) => change({ op: e.target.value }), "aria-label": labels.valueFilterOp, "data-autofocus": first ? "" : void 0, "data-testid": "rule-item-op" }, ops.map((o) => /* @__PURE__ */ React5.createElement("option", { key: o, value: o }, o === "last" ? plural(labels.lastOp, many, lang) : words[o] ?? o))), s.op === "last" ? /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement(
|
|
1987
2278
|
NumberField,
|
|
@@ -2766,7 +3057,7 @@ function FilterMenu({ view, index, field, types, labels, commit, close, onRemove
|
|
|
2766
3057
|
}
|
|
2767
3058
|
function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaultsOf, info, earlier, locale = "en-US" }) {
|
|
2768
3059
|
const { explain } = React6.useContext(HelpContext);
|
|
2769
|
-
const name =
|
|
3060
|
+
const name = valueLabels(view.values, labels)[index];
|
|
2770
3061
|
const topics = valueTopics({ view, index, types, labels, locale, defaultsOf, earlier });
|
|
2771
3062
|
return /* @__PURE__ */ React6.createElement(
|
|
2772
3063
|
LevelMenu,
|
|
@@ -2785,9 +3076,104 @@ function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaul
|
|
|
2785
3076
|
);
|
|
2786
3077
|
}
|
|
2787
3078
|
|
|
3079
|
+
// src/add-menu.jsx
|
|
3080
|
+
import React7, { useState as useState5 } from "react";
|
|
3081
|
+
var OTHER = { rows: "cols", cols: "rows" };
|
|
3082
|
+
function addEffect(view, zone, name) {
|
|
3083
|
+
const inFilters = filterZoneFields(view).some((f) => same(f, name));
|
|
3084
|
+
if (zone === "values") {
|
|
3085
|
+
return { from: null, already: false };
|
|
3086
|
+
}
|
|
3087
|
+
if (zone === "filters") {
|
|
3088
|
+
return { from: inFilters ? null : axisOf(view, name) ?? null, already: inFilters };
|
|
3089
|
+
}
|
|
3090
|
+
if (view[zone].some((f) => same(f, name))) {
|
|
3091
|
+
return { from: null, already: true };
|
|
3092
|
+
}
|
|
3093
|
+
return { from: view[OTHER[zone]].some((f) => same(f, name)) ? OTHER[zone] : inFilters ? "filters" : null, already: false };
|
|
3094
|
+
}
|
|
3095
|
+
function AddMenu({ zone, view, fields, placed, nameOf, info, labels, close, placeName, onAdd, filterDraft, onAdded, commit, encoded, locale, fullText }) {
|
|
3096
|
+
const [picked, setPicked] = useState5(
|
|
3097
|
+
/** @type {{ field: string, from: string | null } | null} */
|
|
3098
|
+
null
|
|
3099
|
+
);
|
|
3100
|
+
const zoneName = labels.zones[zone];
|
|
3101
|
+
const full = zone === "filters" ? null : fullText(zone, view[zone].length);
|
|
3102
|
+
const name = fill(labels.addTo, { zone: zoneName });
|
|
3103
|
+
const choiceOf = (f) => {
|
|
3104
|
+
const { from, already } = addEffect(view, zone, placeName(f.name, zone));
|
|
3105
|
+
const where = placed.get(f.name.toLowerCase()) ?? [];
|
|
3106
|
+
const second = zone === "values" && where.includes("values");
|
|
3107
|
+
return {
|
|
3108
|
+
id: `add-${f.name}`,
|
|
3109
|
+
testId: `add-pick-${f.name}`,
|
|
3110
|
+
text: nameOf(f.name),
|
|
3111
|
+
icon: TYPE_ICON[f.type] ?? "text",
|
|
3112
|
+
className: `pk-add-type-${f.type}`,
|
|
3113
|
+
tags: where.map((z) => ({ icon: ZONE_ICON[z], text: labels.zones[z] })),
|
|
3114
|
+
note: already ? void 0 : from ? fill(labels.addMoves, { zone: labels.zones[from] }) : second ? labels.addSecond : void 0,
|
|
3115
|
+
disabled: already || Boolean(full),
|
|
3116
|
+
reason: already ? fill(labels.addAlready, { zone: zoneName }) : full ?? void 0,
|
|
3117
|
+
closes: zone !== "filters",
|
|
3118
|
+
open: zone === "filters" ? "filter" : void 0,
|
|
3119
|
+
run: () => {
|
|
3120
|
+
if (zone === "filters") {
|
|
3121
|
+
setPicked({ field: f.name, from });
|
|
3122
|
+
} else {
|
|
3123
|
+
close();
|
|
3124
|
+
onAdded(from, () => onAdd(f.name, zone));
|
|
3125
|
+
}
|
|
3126
|
+
}
|
|
3127
|
+
};
|
|
3128
|
+
};
|
|
3129
|
+
const topicOf = (list) => ({ id: "fields", title: name, kind: (
|
|
3130
|
+
/** @type {const} */
|
|
3131
|
+
"inline"
|
|
3132
|
+
), groups: [{ choices: list.map(choiceOf) }], note: fields.length ? null : labels.emptyFields, noteId: "add-empty" });
|
|
3133
|
+
const draft = picked ? filterDraft(picked.field) : null;
|
|
3134
|
+
const topics = [
|
|
3135
|
+
topicOf(fields),
|
|
3136
|
+
// the filter of the field picked for Filters: a level of its own, with no row
|
|
3137
|
+
{ id: "filter", title: picked ? nameOf(picked.field) : "", kind: (
|
|
3138
|
+
/** @type {const} */
|
|
3139
|
+
"panel"
|
|
3140
|
+
), hidden: true }
|
|
3141
|
+
];
|
|
3142
|
+
return /* @__PURE__ */ React7.createElement("div", { className: "pk-add-menu", "data-testid": `add-menu-${zone}` }, /* @__PURE__ */ React7.createElement(
|
|
3143
|
+
LevelMenu,
|
|
3144
|
+
{
|
|
3145
|
+
name,
|
|
3146
|
+
labels,
|
|
3147
|
+
locale,
|
|
3148
|
+
topics,
|
|
3149
|
+
close,
|
|
3150
|
+
onPick: (choice) => choice.run?.(),
|
|
3151
|
+
search: true,
|
|
3152
|
+
searchText: labels.searchFields,
|
|
3153
|
+
filter: (query) => [topicOf(matchingFields(fields, query, info))],
|
|
3154
|
+
head: /* @__PURE__ */ React7.createElement("div", { className: "pk-level-name" }, /* @__PURE__ */ React7.createElement("span", { className: "pk-level-name-text", "data-testid": "menu-head" }, name)),
|
|
3155
|
+
panel: (id, back) => id === "filter" && picked && draft ? /* @__PURE__ */ React7.createElement(
|
|
3156
|
+
FilterBody,
|
|
3157
|
+
{
|
|
3158
|
+
view,
|
|
3159
|
+
base: draft.base,
|
|
3160
|
+
field: draft.field,
|
|
3161
|
+
encoded,
|
|
3162
|
+
locale,
|
|
3163
|
+
labels,
|
|
3164
|
+
commit: (next, note) => onAdded(picked.from, () => commit(next, note)),
|
|
3165
|
+
close,
|
|
3166
|
+
onCancel: () => back(),
|
|
3167
|
+
titled: false
|
|
3168
|
+
}
|
|
3169
|
+
) : null
|
|
3170
|
+
}
|
|
3171
|
+
));
|
|
3172
|
+
}
|
|
3173
|
+
|
|
2788
3174
|
// src/toolbar-panels.jsx
|
|
2789
|
-
import
|
|
2790
|
-
import { VIEW_FILE_LIMITS } from "pivotkit-core";
|
|
3175
|
+
import React8, { useEffect as useEffect3, useId as useId5, useRef as useRef3, useState as useState6 } from "react";
|
|
3176
|
+
import { VIEW_FILE_LIMITS, referenceLineRules, swapAxes } from "pivotkit-core";
|
|
2791
3177
|
|
|
2792
3178
|
// src/export-scope.js
|
|
2793
3179
|
function dataExportOf(exportData, names) {
|
|
@@ -2813,6 +3199,12 @@ function dataExportOf(exportData, names) {
|
|
|
2813
3199
|
const unknown = wanted.filter((w) => !known.has(w.toLowerCase()));
|
|
2814
3200
|
return { source: picked.length > 0, columns: picked, unknown };
|
|
2815
3201
|
}
|
|
3202
|
+
function drillExportOn(scope, { drillDownExport = false } = {}) {
|
|
3203
|
+
if (scope.columns) {
|
|
3204
|
+
return scope.columns.length > 0;
|
|
3205
|
+
}
|
|
3206
|
+
return scope.source || drillDownExport === true;
|
|
3207
|
+
}
|
|
2816
3208
|
function pickColumns(names, wanted) {
|
|
2817
3209
|
if (wanted === void 0) {
|
|
2818
3210
|
return names.map((_n, i) => i);
|
|
@@ -2929,9 +3321,21 @@ async function copyText(text, container) {
|
|
|
2929
3321
|
before?.focus?.({ preventScroll: true });
|
|
2930
3322
|
return ok;
|
|
2931
3323
|
}
|
|
3324
|
+
async function copyImage(blob, env = { clipboard: typeof navigator !== "undefined" ? navigator.clipboard : void 0, ClipboardItem: typeof ClipboardItem !== "undefined" ? ClipboardItem : void 0 }) {
|
|
3325
|
+
const { clipboard, ClipboardItem: Item } = env;
|
|
3326
|
+
if (!clipboard || typeof clipboard.write !== "function" || typeof Item !== "function") {
|
|
3327
|
+
return false;
|
|
3328
|
+
}
|
|
3329
|
+
try {
|
|
3330
|
+
await clipboard.write([new Item({ [blob.type || "image/png"]: blob })]);
|
|
3331
|
+
return true;
|
|
3332
|
+
} catch {
|
|
3333
|
+
return false;
|
|
3334
|
+
}
|
|
3335
|
+
}
|
|
2932
3336
|
|
|
2933
3337
|
// src/version.js
|
|
2934
|
-
var VERSION = true ? "0.
|
|
3338
|
+
var VERSION = true ? "0.8.0" : "0.0.0-source";
|
|
2935
3339
|
|
|
2936
3340
|
// src/share-actions.js
|
|
2937
3341
|
var here = () => typeof location !== "undefined" ? location.href : void 0;
|
|
@@ -2993,28 +3397,28 @@ function shareActions(ctx, labels) {
|
|
|
2993
3397
|
if (!loaded.view) {
|
|
2994
3398
|
return labels.viewFailed[loaded.failed ?? "notView"] ?? labels.viewFailed.notView;
|
|
2995
3399
|
}
|
|
2996
|
-
const
|
|
3400
|
+
const ready2 = (
|
|
2997
3401
|
/** @type {import("./share.js").LoadedView} */
|
|
2998
3402
|
loaded
|
|
2999
3403
|
);
|
|
3000
|
-
const made =
|
|
3001
|
-
if (made &&
|
|
3404
|
+
const made = ready2.file?.source;
|
|
3405
|
+
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") {
|
|
3002
3406
|
return null;
|
|
3003
3407
|
}
|
|
3004
|
-
const check = loadCheck(
|
|
3408
|
+
const check = loadCheck(ready2, labels, Array.isArray(ctx.sources) ? ctx.sources : []);
|
|
3005
3409
|
if (!check) {
|
|
3006
|
-
ctx.applyLoaded(
|
|
3410
|
+
ctx.applyLoaded(ready2);
|
|
3007
3411
|
return null;
|
|
3008
3412
|
}
|
|
3009
3413
|
const target = check.switchTo;
|
|
3010
3414
|
const switchTo = ctx.onSourceSwitch;
|
|
3011
3415
|
return {
|
|
3012
3416
|
lines: check.lines,
|
|
3013
|
-
load: () => ctx.applyLoaded(
|
|
3417
|
+
load: () => ctx.applyLoaded(ready2),
|
|
3014
3418
|
switchTo: target && typeof switchTo === "function" ? { name: target.name, run: () => switchTo({ source: { id: target.id, name: target.name }, view: (
|
|
3015
3419
|
/** @type {Record<string, unknown>} */
|
|
3016
|
-
|
|
3017
|
-
), name:
|
|
3420
|
+
ready2.file?.view ?? ready2.view
|
|
3421
|
+
), name: ready2.file?.name || void 0 }) } : void 0
|
|
3018
3422
|
};
|
|
3019
3423
|
}
|
|
3020
3424
|
};
|
|
@@ -3055,15 +3459,430 @@ function saveAsTarget(name, entries, can) {
|
|
|
3055
3459
|
return old ? { kind: "store", at: old.at, storeSource: old.sourceId ?? null, storeSheet: old.sheet ?? null, replaces: old } : { kind: "store", storeSource: can.sourceId ?? null, storeSheet: can.sheet ?? null, replaces: null };
|
|
3056
3460
|
}
|
|
3057
3461
|
|
|
3058
|
-
// src/
|
|
3059
|
-
import {
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
var
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3462
|
+
// src/export-run.js
|
|
3463
|
+
import { chartThemeFrom, toGrid } from "pivotkit-core";
|
|
3464
|
+
|
|
3465
|
+
// src/print-frame.js
|
|
3466
|
+
var FRAME_CLASS = "pk-print-frame";
|
|
3467
|
+
var listeners = /* @__PURE__ */ new WeakMap();
|
|
3468
|
+
function removeFrame(frame) {
|
|
3469
|
+
listeners.get(frame)?.abort();
|
|
3470
|
+
frame.remove();
|
|
3471
|
+
}
|
|
3472
|
+
var PRINT_LOAD_TIMEOUT = 5e3;
|
|
3473
|
+
function printParts(html, parser) {
|
|
3474
|
+
const styles = [];
|
|
3475
|
+
const text = html.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => (styles.push(css), ""));
|
|
3476
|
+
const parsed = parser.parseFromString(text, "text/html");
|
|
3477
|
+
for (const node of parsed.querySelectorAll("style, script, meta, link, base")) {
|
|
3478
|
+
node.remove();
|
|
3479
|
+
}
|
|
3480
|
+
return { css: styles.join("\n"), lang: parsed.documentElement.getAttribute("lang") ?? "", dir: parsed.documentElement.getAttribute("dir") ?? "", title: parsed.title, body: parsed.body };
|
|
3481
|
+
}
|
|
3482
|
+
var ready = /* @__PURE__ */ new WeakMap();
|
|
3483
|
+
function newSlot(container) {
|
|
3484
|
+
const doc = container.ownerDocument;
|
|
3485
|
+
const frame = doc.createElement("iframe");
|
|
3486
|
+
frame.className = FRAME_CLASS;
|
|
3487
|
+
frame.setAttribute("sandbox", "allow-same-origin allow-modals");
|
|
3488
|
+
frame.setAttribute("aria-hidden", "true");
|
|
3489
|
+
frame.setAttribute("tabindex", "-1");
|
|
3490
|
+
frame.hidden = true;
|
|
3491
|
+
const slot = { frame, isLoaded: false, loaded: Promise.resolve(false) };
|
|
3492
|
+
const loading = new AbortController();
|
|
3493
|
+
listeners.set(frame, loading);
|
|
3494
|
+
slot.loaded = new Promise((resolve) => {
|
|
3495
|
+
const timer = setTimeout(() => resolve(false), PRINT_LOAD_TIMEOUT);
|
|
3496
|
+
loading.signal.addEventListener("abort", () => {
|
|
3497
|
+
clearTimeout(timer);
|
|
3498
|
+
resolve(false);
|
|
3499
|
+
});
|
|
3500
|
+
const done = () => {
|
|
3501
|
+
if (frame.contentDocument?.URL === "about:srcdoc" && frame.contentDocument.readyState === "complete") {
|
|
3502
|
+
frame.hidden = false;
|
|
3503
|
+
slot.isLoaded = true;
|
|
3504
|
+
resolve(true);
|
|
3505
|
+
loading.abort();
|
|
3506
|
+
}
|
|
3507
|
+
};
|
|
3508
|
+
frame.addEventListener("load", done, { signal: loading.signal });
|
|
3509
|
+
});
|
|
3510
|
+
frame.srcdoc = '<!doctype html><html><head><meta charset="utf-8"><title></title></head><body></body></html>';
|
|
3511
|
+
container.append(frame);
|
|
3512
|
+
return slot;
|
|
3513
|
+
}
|
|
3514
|
+
function preparePrintFrame(container) {
|
|
3515
|
+
if (!ready.get(container)?.frame.isConnected) {
|
|
3516
|
+
ready.set(container, newSlot(container));
|
|
3517
|
+
}
|
|
3518
|
+
}
|
|
3519
|
+
function releasePrintFrame(container) {
|
|
3520
|
+
const slot = ready.get(container);
|
|
3521
|
+
if (slot) {
|
|
3522
|
+
ready.delete(container);
|
|
3523
|
+
removeFrame(slot.frame);
|
|
3524
|
+
}
|
|
3525
|
+
}
|
|
3526
|
+
function takePrintFrame(container) {
|
|
3527
|
+
const kept = ready.get(container);
|
|
3528
|
+
const slot = kept?.frame.isConnected ? kept : newSlot(container);
|
|
3529
|
+
ready.delete(container);
|
|
3530
|
+
for (const old of container.querySelectorAll(`iframe.${FRAME_CLASS}`)) {
|
|
3531
|
+
if (old !== slot.frame) {
|
|
3532
|
+
removeFrame(
|
|
3533
|
+
/** @type {HTMLIFrameElement} */
|
|
3534
|
+
old
|
|
3535
|
+
);
|
|
3536
|
+
}
|
|
3537
|
+
}
|
|
3538
|
+
return slot;
|
|
3539
|
+
}
|
|
3540
|
+
var dropPrintFrame = (slot) => removeFrame(slot.frame);
|
|
3541
|
+
function printHtml(html, slot) {
|
|
3542
|
+
if (slot.isLoaded) {
|
|
3543
|
+
return Promise.resolve(fillAndPrint(html, slot.frame));
|
|
3544
|
+
}
|
|
3545
|
+
return slot.loaded.then((ok) => {
|
|
3546
|
+
if (!ok) {
|
|
3547
|
+
removeFrame(slot.frame);
|
|
3548
|
+
}
|
|
3549
|
+
return ok && fillAndPrint(html, slot.frame);
|
|
3550
|
+
});
|
|
3551
|
+
}
|
|
3552
|
+
function fillAndPrint(html, frame) {
|
|
3553
|
+
try {
|
|
3554
|
+
return fillAndPrintIn(html, frame);
|
|
3555
|
+
} catch (error) {
|
|
3556
|
+
removeFrame(frame);
|
|
3557
|
+
throw error;
|
|
3558
|
+
}
|
|
3559
|
+
}
|
|
3560
|
+
function fillAndPrintIn(html, frame) {
|
|
3561
|
+
const win = frame.contentWindow;
|
|
3562
|
+
const fdoc = frame.contentDocument;
|
|
3563
|
+
if (!frame.isConnected) {
|
|
3564
|
+
return true;
|
|
3565
|
+
}
|
|
3566
|
+
if (!win || !fdoc || !fdoc.body) {
|
|
3567
|
+
removeFrame(frame);
|
|
3568
|
+
return false;
|
|
3569
|
+
}
|
|
3570
|
+
const parts = printParts(html, new /** @type {any} */
|
|
3571
|
+
frame.ownerDocument.defaultView.DOMParser());
|
|
3572
|
+
frame.title = parts.title;
|
|
3573
|
+
fdoc.documentElement.lang = parts.lang;
|
|
3574
|
+
fdoc.documentElement.dir = parts.dir;
|
|
3575
|
+
fdoc.title = parts.title;
|
|
3576
|
+
const FrameSheet = (
|
|
3577
|
+
/** @type {any} */
|
|
3578
|
+
win.CSSStyleSheet
|
|
3579
|
+
);
|
|
3580
|
+
if (typeof FrameSheet === "function" && "adoptedStyleSheets" in fdoc) {
|
|
3581
|
+
const sheet = new FrameSheet();
|
|
3582
|
+
sheet.replaceSync(parts.css);
|
|
3583
|
+
fdoc.adoptedStyleSheets = [sheet];
|
|
3584
|
+
} else {
|
|
3585
|
+
const style = fdoc.createElement("style");
|
|
3586
|
+
style.textContent = parts.css;
|
|
3587
|
+
fdoc.head.append(style);
|
|
3588
|
+
}
|
|
3589
|
+
fdoc.body.replaceChildren(...[...parts.body.childNodes].map((node) => fdoc.importNode(node, true)));
|
|
3590
|
+
void fdoc.documentElement.getBoundingClientRect();
|
|
3591
|
+
const view = frame.ownerDocument.defaultView;
|
|
3592
|
+
const ended = new AbortController();
|
|
3593
|
+
listeners.set(frame, ended);
|
|
3594
|
+
const after = () => setTimeout(() => removeFrame(frame), 0);
|
|
3595
|
+
win.addEventListener("afterprint", after, { once: true, signal: ended.signal });
|
|
3596
|
+
view?.addEventListener("afterprint", after, { once: true, signal: ended.signal });
|
|
3597
|
+
win.print();
|
|
3598
|
+
return true;
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
// src/theme-tokens.js
|
|
3602
|
+
function themeTokens(root, theme, names, more = () => ({})) {
|
|
3603
|
+
const host = (
|
|
3604
|
+
/** @type {{ host?: Element }} */
|
|
3605
|
+
root.getRootNode().host
|
|
3606
|
+
);
|
|
3607
|
+
const other = theme === "light" ? "dark" : "light";
|
|
3608
|
+
const shown = [root, ...host ? [host] : []].filter((el) => el.getAttribute("data-pk-theme") === other);
|
|
3609
|
+
const read = () => {
|
|
3610
|
+
const style = getComputedStyle(root);
|
|
3611
|
+
return { ...Object.fromEntries(names.map((name) => [name, style.getPropertyValue(name).trim()]).filter(([, value]) => value)), ...more() };
|
|
3612
|
+
};
|
|
3613
|
+
if (!shown.length) {
|
|
3614
|
+
return read();
|
|
3615
|
+
}
|
|
3616
|
+
const kept = [root.style.getPropertyValue("--pk-duration"), root.style.getPropertyPriority("--pk-duration")];
|
|
3617
|
+
root.style.setProperty("--pk-duration", "0ms", "important");
|
|
3618
|
+
try {
|
|
3619
|
+
for (const el of shown) {
|
|
3620
|
+
el.setAttribute("data-pk-theme", theme);
|
|
3621
|
+
}
|
|
3622
|
+
try {
|
|
3623
|
+
return read();
|
|
3624
|
+
} finally {
|
|
3625
|
+
for (const el of shown) {
|
|
3626
|
+
el.setAttribute("data-pk-theme", other);
|
|
3627
|
+
}
|
|
3628
|
+
getComputedStyle(root).getPropertyValue("--pk-duration");
|
|
3629
|
+
}
|
|
3630
|
+
} finally {
|
|
3631
|
+
if (kept[0]) {
|
|
3632
|
+
root.style.setProperty("--pk-duration", kept[0], kept[1]);
|
|
3633
|
+
} else {
|
|
3634
|
+
root.style.removeProperty("--pk-duration");
|
|
3635
|
+
}
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
|
|
3639
|
+
// src/export-run.js
|
|
3640
|
+
var XLSX_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
3641
|
+
var exporters = null;
|
|
3642
|
+
var pending = null;
|
|
3643
|
+
function loadExporters() {
|
|
3644
|
+
pending ??= import("pivotkit-core/export").then(
|
|
3645
|
+
(m) => {
|
|
3646
|
+
exporters = m;
|
|
3647
|
+
return m;
|
|
3648
|
+
},
|
|
3649
|
+
(error) => {
|
|
3650
|
+
pending = null;
|
|
3651
|
+
throw error;
|
|
3652
|
+
}
|
|
3653
|
+
);
|
|
3654
|
+
return pending;
|
|
3655
|
+
}
|
|
3656
|
+
var reportPending = null;
|
|
3657
|
+
var reportModules = null;
|
|
3658
|
+
function loadReport(loadECharts) {
|
|
3659
|
+
reportPending ??= Promise.all([import("./chunks/report-run-HU4WPOB7.js"), loadECharts()]).then(
|
|
3660
|
+
(modules) => reportModules = modules,
|
|
3661
|
+
(error) => {
|
|
3662
|
+
reportPending = null;
|
|
3663
|
+
throw error;
|
|
3664
|
+
}
|
|
3665
|
+
);
|
|
3666
|
+
return reportPending;
|
|
3667
|
+
}
|
|
3668
|
+
var exportersNow = () => exporters;
|
|
3669
|
+
var prepareExporters = () => void loadExporters().catch(() => void 0);
|
|
3670
|
+
function prepareExport(what, root, loadECharts) {
|
|
3671
|
+
if (what === "print") {
|
|
3672
|
+
if (loadECharts) {
|
|
3673
|
+
void loadReport(loadECharts).catch(() => void 0);
|
|
3674
|
+
}
|
|
3675
|
+
return void 0;
|
|
3676
|
+
}
|
|
3677
|
+
prepareExporters();
|
|
3678
|
+
const container = root.current;
|
|
3679
|
+
if (!container) {
|
|
3680
|
+
return void 0;
|
|
3681
|
+
}
|
|
3682
|
+
preparePrintFrame(container);
|
|
3683
|
+
return () => releasePrintFrame(container);
|
|
3684
|
+
}
|
|
3685
|
+
function deliver(blob, { doc, onExport, ...file }) {
|
|
3686
|
+
if (onExport?.({ ...file, blob }) === false) {
|
|
3687
|
+
return false;
|
|
3688
|
+
}
|
|
3689
|
+
saveBlob(blob, file.fileName, doc);
|
|
3690
|
+
return true;
|
|
3691
|
+
}
|
|
3692
|
+
async function copyOut(text, { type, container, onExport, ...file }) {
|
|
3693
|
+
if (onExport?.({ ...file, blob: new Blob([text], { type }), text }) === false) {
|
|
3694
|
+
return "kept";
|
|
3695
|
+
}
|
|
3696
|
+
return await copyText(text, container) ? "copied" : "blocked";
|
|
3697
|
+
}
|
|
3698
|
+
var isColor = (text) => typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("color", text);
|
|
3699
|
+
function hexColor(text, ctx, supports = isColor) {
|
|
3700
|
+
if (!text || !ctx || !supports(text)) {
|
|
3701
|
+
return null;
|
|
3702
|
+
}
|
|
3703
|
+
ctx.fillStyle = text;
|
|
3704
|
+
const hex = String(ctx.fillStyle).toLowerCase();
|
|
3705
|
+
return /^#[0-9a-f]{6}$/.test(hex) ? hex : null;
|
|
3706
|
+
}
|
|
3707
|
+
var XLSX_TOKENS = Object.freeze(["--pk-scale-low", "--pk-scale-mid", "--pk-scale-high", "--pk-chart-1"]);
|
|
3708
|
+
function xlsxThemeOf(style, toHex) {
|
|
3709
|
+
const { colorScale = [], dataBar = "" } = chartThemeFrom(style);
|
|
3710
|
+
const scale = colorScale.map(toHex);
|
|
3711
|
+
const [low, high, mid] = [scale[0], scale.at(-1), scale.length === 3 ? scale[1] : null];
|
|
3712
|
+
const bar = toHex(dataBar);
|
|
3713
|
+
return {
|
|
3714
|
+
...low && high ? { colorScale: mid ? [low, mid, high] : [low, high] } : {},
|
|
3715
|
+
...bar ? { dataBar: bar } : {}
|
|
3716
|
+
};
|
|
3717
|
+
}
|
|
3718
|
+
function xlsxTheme(root) {
|
|
3719
|
+
if (!root) {
|
|
3720
|
+
return void 0;
|
|
3721
|
+
}
|
|
3722
|
+
const tokens = themeTokens(root, "light", XLSX_TOKENS);
|
|
3723
|
+
const ctx = root.ownerDocument.createElement("canvas").getContext("2d");
|
|
3724
|
+
return xlsxThemeOf({ getPropertyValue: (name) => tokens[name] ?? "" }, (text) => hexColor(text, ctx));
|
|
3725
|
+
}
|
|
3726
|
+
function reportTokens(root, report, chart, dark) {
|
|
3727
|
+
if (!root) {
|
|
3728
|
+
return {};
|
|
3729
|
+
}
|
|
3730
|
+
const mix = chart.screenColor(root.ownerDocument, (c) => /^#[\da-f]{6}$/i.test(c));
|
|
3731
|
+
const mixable = (found) => Object.fromEntries(Object.entries(found).map(([name, value]) => [name, MIXED_TOKENS.includes(name) ? mix(value) ?? value : value]));
|
|
3732
|
+
const tokens = mixable(themeTokens(root, "light", report.REPORT_TOKENS, () => chart.tokenLengths(root, [...chart.LENGTH_TOKENS, ...report.REPORT_LENGTHS])));
|
|
3733
|
+
const darkTokens = dark ? mixable(themeTokens(root, "dark", report.REPORT_DARK_TOKENS)) : {};
|
|
3734
|
+
return { ...Object.keys(tokens).length ? { tokens } : {}, ...Object.keys(darkTokens).length ? { darkTokens } : {} };
|
|
3735
|
+
}
|
|
3736
|
+
var MIXED_TOKENS = Object.freeze(["--pk-heat-low", "--pk-heat-high", "--pk-scale-low", "--pk-scale-mid", "--pk-scale-high"]);
|
|
3737
|
+
async function runExport(kind, { fileName, result, encoded, exportData, locale, labels, limits, root, chartRef, announce, onExport, title, source, loadECharts, colorMap }) {
|
|
3738
|
+
labels = menuLabels(labels);
|
|
3739
|
+
const base = safeFileName(fileName);
|
|
3740
|
+
const doc = root.current?.ownerDocument;
|
|
3741
|
+
try {
|
|
3742
|
+
if (kind === "png" || kind === "copy-chart") {
|
|
3743
|
+
const surface = root.current ? getComputedStyle(root.current).getPropertyValue("--pk-surface").trim() : "";
|
|
3744
|
+
const url = chartRef.current?.getDataURL({ type: "png", pixelRatio: 2, backgroundColor: surface || void 0, excludeComponents: ["dataZoom"] });
|
|
3745
|
+
const file2 = `${base}.png`;
|
|
3746
|
+
if (kind === "copy-chart") {
|
|
3747
|
+
if (!url) {
|
|
3748
|
+
announce(labels.toastChartNotDrawn, { tone: "error" });
|
|
3749
|
+
return;
|
|
3750
|
+
}
|
|
3751
|
+
const blob = dataUrlToBlob(url);
|
|
3752
|
+
if (onExport?.({ kind, fileName: file2, blob }) === false) {
|
|
3753
|
+
return;
|
|
3754
|
+
}
|
|
3755
|
+
if (await copyImage(blob)) {
|
|
3756
|
+
announce(labels.toastChartCopied);
|
|
3757
|
+
return;
|
|
3758
|
+
}
|
|
3759
|
+
const download = () => {
|
|
3760
|
+
if (deliver(blob, { kind: "png", fileName: file2, doc, onExport })) {
|
|
3761
|
+
announce(fill(labels.toastExported, { file: file2 }));
|
|
3762
|
+
}
|
|
3763
|
+
};
|
|
3764
|
+
announce(labels.toastImageCopyBlocked, { tone: "error", action: { label: labels.downloadPng, run: download } });
|
|
3765
|
+
return;
|
|
3766
|
+
}
|
|
3767
|
+
if (url && deliver(dataUrlToBlob(url), { kind, fileName: file2, doc, onExport })) {
|
|
3768
|
+
announce(fill(labels.toastExported, { file: file2 }));
|
|
3769
|
+
}
|
|
3770
|
+
return;
|
|
3771
|
+
}
|
|
3772
|
+
if (kind === "data-csv" || kind === "data-json") {
|
|
3773
|
+
const data = encoded ?? result?.encoded;
|
|
3774
|
+
if (!data) {
|
|
3775
|
+
return;
|
|
3776
|
+
}
|
|
3777
|
+
const scope = dataExportFor(exportData, data);
|
|
3778
|
+
if (!scope.source) {
|
|
3779
|
+
return;
|
|
3780
|
+
}
|
|
3781
|
+
const m2 = exporters ?? await loadExporters();
|
|
3782
|
+
const csv = kind === "data-csv";
|
|
3783
|
+
const file2 = `${base}-data.${csv ? "csv" : "json"}`;
|
|
3784
|
+
const options = { ...limits ? { limits } : {}, ...scope.columns ? { columns: scope.columns } : {} };
|
|
3785
|
+
const blob = csv ? new Blob(
|
|
3786
|
+
/** @type {BlobPart[]} */
|
|
3787
|
+
m2.dataToCsvParts(data, options),
|
|
3788
|
+
{ type: "text/csv;charset=utf-8" }
|
|
3789
|
+
) : new Blob([m2.dataToJson(data, options)], { type: "application/json" });
|
|
3790
|
+
if (deliver(blob, { kind, fileName: file2, doc, onExport })) {
|
|
3791
|
+
announce(fill(labels.toastExported, { file: file2 }));
|
|
3792
|
+
}
|
|
3793
|
+
return;
|
|
3794
|
+
}
|
|
3795
|
+
if (!result) {
|
|
3796
|
+
return;
|
|
3797
|
+
}
|
|
3798
|
+
if (kind === "html" || kind === "svg" || kind === "print") {
|
|
3799
|
+
const slot = kind === "print" && root.current ? takePrintFrame(root.current) : null;
|
|
3800
|
+
let printing = false;
|
|
3801
|
+
try {
|
|
3802
|
+
const [report, echarts] = reportModules ?? await loadReport(
|
|
3803
|
+
/** @type {() => Promise<any>} */
|
|
3804
|
+
loadECharts
|
|
3805
|
+
);
|
|
3806
|
+
const chart = chartRef.current;
|
|
3807
|
+
const size = chart ? { width: clampSize(chart.getWidth()), height: clampSize(chart.getHeight()) } : void 0;
|
|
3808
|
+
const rendered = await report.render(result.view, result.encoded, {
|
|
3809
|
+
format: kind === "svg" ? "svg" : "html",
|
|
3810
|
+
echarts,
|
|
3811
|
+
locale,
|
|
3812
|
+
trusted: true,
|
|
3813
|
+
labels: labels.core,
|
|
3814
|
+
...limits ? { limits } : {},
|
|
3815
|
+
timeZone: result.timeZone,
|
|
3816
|
+
...title ? { title } : {},
|
|
3817
|
+
...source ? { source } : {},
|
|
3818
|
+
...size ? { size } : {},
|
|
3819
|
+
...reportTokens(root.current, report, echarts, kind === "html"),
|
|
3820
|
+
// the host's fixed colours, as the light chart draws them (a file is light)
|
|
3821
|
+
...echarts.colorMapFor(colorMap, "light") ? { colorMap: echarts.colorMapFor(colorMap, "light") } : {},
|
|
3822
|
+
chartEmbed: kind === "print" ? "inline" : "image"
|
|
3823
|
+
});
|
|
3824
|
+
const file2 = `${base}.${kind === "svg" ? "svg" : "html"}`;
|
|
3825
|
+
const blob = new Blob([
|
|
3826
|
+
/** @type {BlobPart} */
|
|
3827
|
+
rendered.body
|
|
3828
|
+
], { type: rendered.mediaType });
|
|
3829
|
+
if (kind !== "print") {
|
|
3830
|
+
if (deliver(blob, { kind, fileName: file2, doc, onExport })) {
|
|
3831
|
+
announce(fill(labels.toastExported, { file: file2 }));
|
|
3832
|
+
}
|
|
3833
|
+
return;
|
|
3834
|
+
}
|
|
3835
|
+
if (onExport?.({ kind, fileName: file2, blob }) === false) {
|
|
3836
|
+
return;
|
|
3837
|
+
}
|
|
3838
|
+
printing = true;
|
|
3839
|
+
if (!slot || !await printHtml(
|
|
3840
|
+
/** @type {string} */
|
|
3841
|
+
rendered.text,
|
|
3842
|
+
slot
|
|
3843
|
+
)) {
|
|
3844
|
+
announce(labels.toastPrintBlocked, { tone: "error" });
|
|
3845
|
+
}
|
|
3846
|
+
return;
|
|
3847
|
+
} finally {
|
|
3848
|
+
if (slot && !printing) {
|
|
3849
|
+
dropPrintFrame(slot);
|
|
3850
|
+
}
|
|
3851
|
+
}
|
|
3852
|
+
}
|
|
3853
|
+
const m = exporters ?? await loadExporters();
|
|
3854
|
+
const grid = toGrid(result, { locale, labels: labels.core, limits });
|
|
3855
|
+
if (kind === "copy-table" || kind === "copy-json") {
|
|
3856
|
+
const json = kind === "copy-json";
|
|
3857
|
+
const done = await copyOut(json ? m.toJson(grid) : m.toTsv(grid), { kind, fileName: `${base}.${json ? "json" : "tsv"}`, type: json ? "application/json" : "text/tab-separated-values", container: root.current, onExport });
|
|
3858
|
+
if (done !== "kept") {
|
|
3859
|
+
announce(done === "copied" ? json ? labels.toastDataCopied : labels.toastTableCopied : labels.toastCopyBlocked, done === "copied" ? void 0 : { tone: "error" });
|
|
3860
|
+
}
|
|
3861
|
+
return;
|
|
3862
|
+
}
|
|
3863
|
+
const file = `${base}.${kind}`;
|
|
3864
|
+
const bytes = kind === "xlsx" ? m.toXlsx(grid, { sheetName: base, theme: xlsxTheme(root.current) }) : m.toCsvBytes(grid, { bom: true });
|
|
3865
|
+
if (deliver(new Blob([
|
|
3866
|
+
/** @type {BlobPart} */
|
|
3867
|
+
bytes
|
|
3868
|
+
], { type: kind === "xlsx" ? XLSX_TYPE : "text/csv;charset=utf-8" }), { kind, fileName: file, doc, onExport })) {
|
|
3869
|
+
announce(fill(labels.toastExported, { file }));
|
|
3870
|
+
}
|
|
3871
|
+
} catch (e) {
|
|
3872
|
+
announce(fill(labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
|
|
3873
|
+
}
|
|
3874
|
+
}
|
|
3875
|
+
var clampSize = (px) => Math.max(100, Math.min(8e3, Math.round(Number(px) || 0)));
|
|
3876
|
+
|
|
3877
|
+
// src/view-store.js
|
|
3878
|
+
import { toViewFile as toViewFile2 } from "pivotkit-core";
|
|
3879
|
+
import { parseTemplates } from "pivotkit-core/templates";
|
|
3880
|
+
var VIEW_STORE_LIMITS = Object.freeze({ count: 100, text: 5e5 });
|
|
3881
|
+
var warnedLarge = false;
|
|
3882
|
+
function readAll(raw) {
|
|
3883
|
+
if (!raw) {
|
|
3884
|
+
return [];
|
|
3885
|
+
}
|
|
3067
3886
|
if (raw.length > VIEW_STORE_LIMITS.text) {
|
|
3068
3887
|
if (!warnedLarge) {
|
|
3069
3888
|
warnedLarge = true;
|
|
@@ -3133,7 +3952,7 @@ function storeViews(raw, change, labels, locale, keep) {
|
|
|
3133
3952
|
// src/toolbar-panels.jsx
|
|
3134
3953
|
function ChartTypeOptions({ view, plan, labels, onChart, close }) {
|
|
3135
3954
|
const current = chartTypeOf(view.chart);
|
|
3136
|
-
return CHART_TYPE_NAMES.map((p) => /* @__PURE__ */
|
|
3955
|
+
return CHART_TYPE_NAMES.map((p) => /* @__PURE__ */ React8.createElement(
|
|
3137
3956
|
Option,
|
|
3138
3957
|
{
|
|
3139
3958
|
key: p,
|
|
@@ -3149,19 +3968,20 @@ function ChartTypeOptions({ view, plan, labels, onChart, close }) {
|
|
|
3149
3968
|
labels.chartTypes[p]
|
|
3150
3969
|
));
|
|
3151
3970
|
}
|
|
3152
|
-
|
|
3153
|
-
|
|
3154
|
-
|
|
3155
|
-
|
|
3156
|
-
|
|
3971
|
+
function legendNames(drawn, series) {
|
|
3972
|
+
if (!series || drawn === "heatmap") {
|
|
3973
|
+
return [];
|
|
3974
|
+
}
|
|
3975
|
+
return [...new Set(SLICE_TYPES.includes(drawn) ? series.categories : series.series.map((s) => s.name))];
|
|
3976
|
+
}
|
|
3157
3977
|
function ChartTitle({ title, labels, onDisplay }) {
|
|
3158
|
-
const [text, setText] =
|
|
3159
|
-
const [last, setLast] =
|
|
3978
|
+
const [text, setText] = useState6(title ?? "");
|
|
3979
|
+
const [last, setLast] = useState6(title);
|
|
3160
3980
|
if (title !== last) {
|
|
3161
3981
|
setLast(title);
|
|
3162
3982
|
setText(title ?? "");
|
|
3163
3983
|
}
|
|
3164
|
-
return /* @__PURE__ */
|
|
3984
|
+
return /* @__PURE__ */ React8.createElement(
|
|
3165
3985
|
"form",
|
|
3166
3986
|
{
|
|
3167
3987
|
className: "pk-inline-form",
|
|
@@ -3170,7 +3990,7 @@ function ChartTitle({ title, labels, onDisplay }) {
|
|
|
3170
3990
|
onDisplay({ title: text.trim() || null });
|
|
3171
3991
|
}
|
|
3172
3992
|
},
|
|
3173
|
-
/* @__PURE__ */
|
|
3993
|
+
/* @__PURE__ */ React8.createElement(
|
|
3174
3994
|
ClearInput,
|
|
3175
3995
|
{
|
|
3176
3996
|
type: "text",
|
|
@@ -3184,50 +4004,128 @@ function ChartTitle({ title, labels, onDisplay }) {
|
|
|
3184
4004
|
"data-testid": "chart-title"
|
|
3185
4005
|
}
|
|
3186
4006
|
),
|
|
3187
|
-
/* @__PURE__ */
|
|
4007
|
+
/* @__PURE__ */ React8.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: (text.trim() || null) === (title ?? null) }, labels.apply)
|
|
4008
|
+
);
|
|
4009
|
+
}
|
|
4010
|
+
function colorsDrawn(instance) {
|
|
4011
|
+
const out = /* @__PURE__ */ new Map();
|
|
4012
|
+
const option = instance.getOption?.();
|
|
4013
|
+
const palette = Array.isArray(option?.color) ? option.color : [];
|
|
4014
|
+
const of = (item, i) => item?.itemStyle?.color ?? palette[i % Math.max(1, palette.length)];
|
|
4015
|
+
for (const [i, s] of (option?.series ?? []).entries()) {
|
|
4016
|
+
if (s.type === "pie") {
|
|
4017
|
+
(s.data ?? []).forEach((d, j) => out.set(String(d.name), of(d, j)));
|
|
4018
|
+
} else {
|
|
4019
|
+
out.set(String(s.name), of(s, i));
|
|
4020
|
+
}
|
|
4021
|
+
}
|
|
4022
|
+
return out;
|
|
4023
|
+
}
|
|
4024
|
+
function TargetField({ target, labels, locale, format, onTarget }) {
|
|
4025
|
+
const [text, setText] = useState6(numberText(target, locale));
|
|
4026
|
+
const [last, setLast] = useState6(target);
|
|
4027
|
+
if (target !== last) {
|
|
4028
|
+
setLast(target);
|
|
4029
|
+
setText(numberText(target, locale));
|
|
4030
|
+
}
|
|
4031
|
+
const value = parseTarget(text, locale, format);
|
|
4032
|
+
const bad = text.trim() !== "" && value === null;
|
|
4033
|
+
const hintId = useId5();
|
|
4034
|
+
const warnId = useId5();
|
|
4035
|
+
const share = /^percent(?!100)/.test(format ?? "");
|
|
4036
|
+
const hint = share ? labels.targetPercent : /^percent100/.test(format ?? "") ? labels.targetPercent100 : null;
|
|
4037
|
+
const typed = text.trim();
|
|
4038
|
+
const high = share && value !== null && value > 1 && !typed.endsWith("%");
|
|
4039
|
+
const shown = (n) => new Intl.NumberFormat(locale, { style: "percent", maximumFractionDigits: 2 }).format(n);
|
|
4040
|
+
const describedBy = [hint ? hintId : "", high ? warnId : ""].filter(Boolean).join(" ") || void 0;
|
|
4041
|
+
return /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement(
|
|
4042
|
+
"form",
|
|
4043
|
+
{
|
|
4044
|
+
className: "pk-inline-form",
|
|
4045
|
+
onSubmit: (e) => {
|
|
4046
|
+
e.preventDefault();
|
|
4047
|
+
if (!bad) {
|
|
4048
|
+
onTarget(value);
|
|
4049
|
+
}
|
|
4050
|
+
}
|
|
4051
|
+
},
|
|
4052
|
+
/* @__PURE__ */ React8.createElement(
|
|
4053
|
+
ClearInput,
|
|
4054
|
+
{
|
|
4055
|
+
type: "text",
|
|
4056
|
+
inputMode: "decimal",
|
|
4057
|
+
value: text,
|
|
4058
|
+
onChange: setText,
|
|
4059
|
+
onClear: () => target !== null ? onTarget(null) : void 0,
|
|
4060
|
+
clearLabel: labels.clearText,
|
|
4061
|
+
placeholder: labels.targetNone,
|
|
4062
|
+
"aria-label": labels.core.referenceLines.target,
|
|
4063
|
+
"aria-invalid": bad || void 0,
|
|
4064
|
+
"aria-describedby": describedBy,
|
|
4065
|
+
"data-testid": "chart-target"
|
|
4066
|
+
}
|
|
4067
|
+
),
|
|
4068
|
+
/* @__PURE__ */ React8.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: bad || value === target }, labels.apply)
|
|
4069
|
+
), hint ? /* @__PURE__ */ React8.createElement("p", { id: hintId, className: "pk-hint pk-subtitle", "data-testid": "target-hint" }, hint) : null, high ? /* @__PURE__ */ React8.createElement("p", { id: warnId, className: "pk-hint pk-subtitle", role: "status", "data-testid": "target-warning" }, fill(labels.targetPercentHigh, { typed, shown: shown(
|
|
4070
|
+
/** @type {number} */
|
|
4071
|
+
value
|
|
4072
|
+
), share: shown(
|
|
4073
|
+
/** @type {number} */
|
|
4074
|
+
value / 100
|
|
4075
|
+
) })) : null, target !== null ? /* @__PURE__ */ React8.createElement("button", { type: "button", className: "pk-btn", onClick: () => onTarget(null), "data-testid": "target-remove" }, labels.targetRemove) : null);
|
|
4076
|
+
}
|
|
4077
|
+
function ChartSettingsPanel({ view, plan, encoded, lineChecks, labels, locale, onChart, onDisplay, close, series, colors, folding, onExpand, onCollapse }) {
|
|
4078
|
+
const drawn = plan ? plan.name : chartTypeOf(view.chart);
|
|
4079
|
+
const names = legendNames(drawn, series);
|
|
4080
|
+
const lines = view.chart.referenceLines;
|
|
4081
|
+
const plain = plan?.chart && encoded ? referenceLineRules(plan.swap ? swapAxes(view) : view, { ...view.chart, ...plan.chart }, encoded) : { average: true, trend: true, target: true };
|
|
4082
|
+
const rules = lineChecks ?? { ...plain, notes: ["table"] };
|
|
4083
|
+
const [drawnColors, setDrawnColors] = useState6(
|
|
4084
|
+
/** @type {Map<string, string>} */
|
|
4085
|
+
/* @__PURE__ */ new Map()
|
|
4086
|
+
);
|
|
4087
|
+
useEffect3(() => {
|
|
4088
|
+
const instance = colors?.chart?.current;
|
|
4089
|
+
if (!instance) {
|
|
4090
|
+
return void 0;
|
|
4091
|
+
}
|
|
4092
|
+
const ctx = instance.getDom?.()?.ownerDocument?.createElement("canvas").getContext("2d") ?? null;
|
|
4093
|
+
const read = () => setDrawnColors(new Map([...colorsDrawn(instance)].map(([name, c]) => [name, hexColor(String(c), ctx) ?? ""])));
|
|
4094
|
+
read();
|
|
4095
|
+
instance.on("finished", read);
|
|
4096
|
+
return () => instance.off("finished", read);
|
|
4097
|
+
}, [colors?.chart]);
|
|
4098
|
+
const topics = chartTopics({ view, drawn, labels, names, act: { display: onDisplay, expand: () => onExpand(labels), collapse: () => onCollapse(labels) }, lines: { rules, targetText: numberText(lines?.target, locale) }, drawnColors, folding });
|
|
4099
|
+
const head = /* @__PURE__ */ React8.createElement(Section, { title: labels.chartType }, /* @__PURE__ */ React8.createElement("div", { className: "pk-choice-grid", role: "group", "aria-label": fill(labels.chartTypeIs, { type: labels.chartTypes[plan?.auto ? "auto" : drawn] }), "data-testid": "chart-types" }, /* @__PURE__ */ React8.createElement(ChartTypeOptions, { view, plan, labels, onChart, close })));
|
|
4100
|
+
return /* @__PURE__ */ React8.createElement(
|
|
4101
|
+
LevelMenu,
|
|
4102
|
+
{
|
|
4103
|
+
name: labels.chartSettings,
|
|
4104
|
+
labels,
|
|
4105
|
+
topics,
|
|
4106
|
+
close,
|
|
4107
|
+
onPick: runChoice(close),
|
|
4108
|
+
head,
|
|
4109
|
+
panel: (id) => id === "title" ? /* @__PURE__ */ React8.createElement(ChartTitle, { title: view.chart.title, labels, onDisplay }) : id === "linesTarget" ? /* @__PURE__ */ React8.createElement(TargetField, { target: lines?.target ?? null, labels, locale, format: lineChecks?.format, onTarget: (target) => onDisplay({ referenceLines: { ...lines, target } }) }) : null
|
|
4110
|
+
}
|
|
3188
4111
|
);
|
|
3189
4112
|
}
|
|
3190
|
-
function Sub({ title, info, children }) {
|
|
3191
|
-
const titleId = useId5();
|
|
3192
|
-
return /* @__PURE__ */ React7.createElement("div", { className: "pk-subsection", role: title ? "group" : void 0, "aria-labelledby": title ? titleId : void 0 }, title ? /* @__PURE__ */ React7.createElement("div", { className: `pk-subtitle${info ? " pk-setting-row" : ""}` }, /* @__PURE__ */ React7.createElement("span", { id: titleId }, title), info ? /* @__PURE__ */ React7.createElement(SettingInfo, { id: info, name: title }) : null) : null, children);
|
|
3193
|
-
}
|
|
3194
|
-
function ChartDisplay({ view, plan, labels, onDisplay }) {
|
|
3195
|
-
const chart = view.chart;
|
|
3196
|
-
const drawn = plan ? plan.name : chartTypeOf(chart);
|
|
3197
|
-
const pie = SLICE_TYPES.includes(drawn);
|
|
3198
|
-
const axis = CHART_TYPES[drawn].axis;
|
|
3199
|
-
const choices = pie ? VALUE_LABELS.slices : VALUE_LABELS.other;
|
|
3200
|
-
const valueLabels = !pie && (chart.valueLabels === "percent" || chart.valueLabels === "both") ? "value" : chart.valueLabels;
|
|
3201
|
-
return /* @__PURE__ */ React7.createElement(Section, { title: labels.chartDisplay }, /* @__PURE__ */ React7.createElement(Sub, { title: labels.valueLabels }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, choices.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: valueLabels === v, onSelect: () => onDisplay({ valueLabels: v }), testId: `labels-${v}` }, labels.valueLabelNames[v])))), pie ? /* @__PURE__ */ React7.createElement(Sub, { title: labels.labelPosition, info: "labelPosition" }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, LABEL_POSITIONS.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: (chart.labelPosition ?? "outside") === v, disabled: chart.valueLabels === "off", onSelect: () => onDisplay({ labelPosition: v }), testId: `label-position-${v}` }, labels.labelPositionNames[v])))) : null, /* @__PURE__ */ React7.createElement(Sub, { title: labels.legend }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, LEGENDS.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: chart.legend === v, onSelect: () => onDisplay({ legend: v }), testId: `legend-${v}` }, labels.legendNames[v])))), /* @__PURE__ */ React7.createElement(Sub, { title: labels.chartTitle }, /* @__PURE__ */ React7.createElement(ChartTitle, { title: chart.title, labels, onDisplay })), axis ? /* @__PURE__ */ React7.createElement(Sub, { title: labels.axisLabels }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, AXIS_LABELS.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: chart.axisLabels === v, onSelect: () => onDisplay({ axisLabels: v }), testId: `axis-${v}` }, labels.axisLabelNames[v])))) : null, axis && view.rows.length >= 2 ? /* @__PURE__ */ React7.createElement(Sub, { title: labels.groupLabels, info: "groupLabels" }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, GROUP_LABELS.map((v) => /* @__PURE__ */ React7.createElement(Option, { key: v, checked: chart.groupLabels === v, onSelect: () => onDisplay({ groupLabels: v }), testId: `groups-${v}` }, labels.groupLabelNames[v])))) : null, drawn === "line" || drawn === "area" ? /* @__PURE__ */ React7.createElement(Sub, null, /* @__PURE__ */ React7.createElement(Switch, { checked: chart.smooth, onChange: (on) => onDisplay({ smooth: on }), testId: "chart-smooth" }, labels.smoothLines)) : null);
|
|
3202
|
-
}
|
|
3203
|
-
function ChartTypePanel({ view, plan, labels, onChart, onDisplay, close }) {
|
|
3204
|
-
return /* @__PURE__ */ React7.createElement(React7.Fragment, null, /* @__PURE__ */ React7.createElement(Section, { title: labels.chartType }, /* @__PURE__ */ React7.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React7.createElement(ChartTypeOptions, { view, plan, labels, onChart, close }))), /* @__PURE__ */ React7.createElement(ChartDisplay, { view, plan, labels, onDisplay }));
|
|
3205
|
-
}
|
|
3206
4113
|
function Shortcuts({ labels, mod }) {
|
|
3207
4114
|
const key = (k) => k === "Mod" ? mod === "\u2318" ? "\u2318" : labels.keys.Mod : Object.hasOwn(labels.keys, k) ? labels.keys[k] : k;
|
|
3208
|
-
return /* @__PURE__ */
|
|
4115
|
+
return /* @__PURE__ */ React8.createElement("dl", { className: "pk-shortcuts", "data-testid": "shortcuts" }, SHORTCUTS.map((s) => /* @__PURE__ */ React8.createElement("div", { key: s.text, className: "pk-shortcut" }, /* @__PURE__ */ React8.createElement("dt", null, s.keys.map((k, i) => /* @__PURE__ */ React8.createElement(React8.Fragment, { key: k }, i ? " + " : null, /* @__PURE__ */ React8.createElement("kbd", null, key(k))))), /* @__PURE__ */ React8.createElement("dd", null, labels.shortcuts[s.text]))));
|
|
3209
4116
|
}
|
|
3210
|
-
function
|
|
3211
|
-
const
|
|
3212
|
-
return /* @__PURE__ */
|
|
4117
|
+
function TableSettingsPanel({ view, labels, onTotal, onExpand, onCollapse, close, folding }) {
|
|
4118
|
+
const topics = tableTopics({ view, labels, folding, act: { total: onTotal, expand: () => onExpand(labels), collapse: () => onCollapse(labels) } });
|
|
4119
|
+
return /* @__PURE__ */ React8.createElement(LevelMenu, { name: labels.tableSettings, labels, topics, close, onPick: runChoice(close), panel: () => null });
|
|
3213
4120
|
}
|
|
3214
|
-
function
|
|
3215
|
-
const topics =
|
|
3216
|
-
view,
|
|
4121
|
+
function MorePanel({ labels, tips, mod, help, close, foot }) {
|
|
4122
|
+
const topics = moreTopics({
|
|
3217
4123
|
labels,
|
|
3218
|
-
folding,
|
|
3219
4124
|
tips,
|
|
3220
4125
|
explanations: help?.explanations ?? null,
|
|
3221
|
-
act: {
|
|
3222
|
-
total: onTotal,
|
|
3223
|
-
expand: () => onExpand(labels),
|
|
3224
|
-
collapse: () => onCollapse(labels),
|
|
3225
|
-
tipsOn: (on) => tips.onOn(on),
|
|
3226
|
-
resetTips: () => tips.onReset(),
|
|
3227
|
-
explain: (on) => help?.explanations?.set(on)
|
|
3228
|
-
}
|
|
4126
|
+
act: { tipsOn: (on) => tips.onOn(on), resetTips: () => tips.onReset(), explain: (on) => help?.explanations?.set(on) }
|
|
3229
4127
|
});
|
|
3230
|
-
return /* @__PURE__ */
|
|
4128
|
+
return /* @__PURE__ */ React8.createElement(LevelMenu, { name: labels.more, labels, topics, close, onPick: runChoice(close), foot: foot?.(close), panel: (id) => id === "shortcuts" ? /* @__PURE__ */ React8.createElement(Shortcuts, { labels, mod }) : null });
|
|
3231
4129
|
}
|
|
3232
4130
|
var runChoice = (close) => (c) => {
|
|
3233
4131
|
if (c.closes) {
|
|
@@ -3247,11 +4145,11 @@ function Confirm({ question, action, cancel, onYes, onNo, testId, yesId, noId, d
|
|
|
3247
4145
|
useEffect3(() => {
|
|
3248
4146
|
(focusYes ? yes : no).current?.focus({ preventScroll: true });
|
|
3249
4147
|
}, [focusYes]);
|
|
3250
|
-
return /* @__PURE__ */
|
|
4148
|
+
return /* @__PURE__ */ React8.createElement("div", { className: "pk-confirm pk-save-confirm", role: "group", "aria-label": question, "data-testid": testId }, /* @__PURE__ */ React8.createElement("span", { className: "pk-confirm-text" }, question), /* @__PURE__ */ React8.createElement("button", { ref: yes, type: "button", className: danger ? "pk-btn pk-danger-btn" : "pk-btn pk-primary", disabled: busy, "data-autofocus": focusYes ? "" : void 0, "data-testid": yesId, onClick: onYes }, action), /* @__PURE__ */ React8.createElement("button", { ref: no, type: "button", className: "pk-btn", disabled: busy, "data-autofocus": focusYes ? void 0 : "", "data-testid": noId, onClick: onNo }, cancel));
|
|
3251
4149
|
}
|
|
3252
4150
|
function SaveView({ labels, button, onSave, resolve, close }) {
|
|
3253
|
-
const [name, setName] =
|
|
3254
|
-
const [asking, setAsking] =
|
|
4151
|
+
const [name, setName] = useState6("");
|
|
4152
|
+
const [asking, setAsking] = useState6(
|
|
3255
4153
|
/** @type {any} */
|
|
3256
4154
|
null
|
|
3257
4155
|
);
|
|
@@ -3268,7 +4166,7 @@ function SaveView({ labels, button, onSave, resolve, close }) {
|
|
|
3268
4166
|
}
|
|
3269
4167
|
}, [asking]);
|
|
3270
4168
|
if (asking) {
|
|
3271
|
-
return /* @__PURE__ */
|
|
4169
|
+
return /* @__PURE__ */ React8.createElement(
|
|
3272
4170
|
Confirm,
|
|
3273
4171
|
{
|
|
3274
4172
|
question: fill(labels.replaceConfirm, { name: asking.name }),
|
|
@@ -3285,7 +4183,7 @@ function SaveView({ labels, button, onSave, resolve, close }) {
|
|
|
3285
4183
|
}
|
|
3286
4184
|
);
|
|
3287
4185
|
}
|
|
3288
|
-
return /* @__PURE__ */
|
|
4186
|
+
return /* @__PURE__ */ React8.createElement(
|
|
3289
4187
|
"form",
|
|
3290
4188
|
{
|
|
3291
4189
|
className: "pk-inline-form",
|
|
@@ -3301,8 +4199,8 @@ function SaveView({ labels, button, onSave, resolve, close }) {
|
|
|
3301
4199
|
}
|
|
3302
4200
|
}
|
|
3303
4201
|
},
|
|
3304
|
-
/* @__PURE__ */
|
|
3305
|
-
/* @__PURE__ */
|
|
4202
|
+
/* @__PURE__ */ React8.createElement(ClearInput, { type: "text", value: name, onChange: setName, clearLabel: labels.clearText, placeholder: labels.viewName, "aria-label": labels.viewName, maxLength: 120, "data-testid": "saved-view-name", inputRef: field }),
|
|
4203
|
+
/* @__PURE__ */ React8.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: !name.trim() }, button)
|
|
3306
4204
|
);
|
|
3307
4205
|
}
|
|
3308
4206
|
function LoadCheck({ check, labels, onCancel, close, title, quiet = false }) {
|
|
@@ -3316,25 +4214,25 @@ function LoadCheck({ check, labels, onCancel, close, title, quiet = false }) {
|
|
|
3316
4214
|
first.current?.focus({ preventScroll: true });
|
|
3317
4215
|
}
|
|
3318
4216
|
}, [quiet]);
|
|
3319
|
-
return /* @__PURE__ */
|
|
4217
|
+
return /* @__PURE__ */ React8.createElement("div", { className: "pk-load-check", role: "group", "aria-labelledby": titleId, "data-testid": "load-check" }, /* @__PURE__ */ React8.createElement("p", { id: titleId, className: "pk-load-check-title" }, /* @__PURE__ */ React8.createElement(Icon, { name: "info", size: 16 }), /* @__PURE__ */ React8.createElement("span", null, title ?? labels.loadCheckTitle)), /* @__PURE__ */ React8.createElement("ul", { className: "pk-load-check-lines" }, check.lines.map((line, i) => /* @__PURE__ */ React8.createElement("li", { key: i }, line))), /* @__PURE__ */ React8.createElement("div", { className: "pk-load-check-actions" }, check.switchTo ? /* @__PURE__ */ React8.createElement("button", { ref: first, type: "button", className: "pk-btn pk-primary", "data-autofocus": "", "data-testid": "load-switch", onClick: () => {
|
|
3320
4218
|
close();
|
|
3321
4219
|
check.switchTo?.run();
|
|
3322
|
-
} }, fill(labels.switchAndLoad, { source: check.switchTo.name })) : null, /* @__PURE__ */
|
|
4220
|
+
} }, fill(labels.switchAndLoad, { source: check.switchTo.name })) : null, /* @__PURE__ */ React8.createElement("button", { ref: check.switchTo ? void 0 : first, type: "button", className: check.switchTo ? "pk-btn" : "pk-btn pk-primary", "data-autofocus": check.switchTo ? void 0 : "", "data-testid": "load-anyway", onClick: () => {
|
|
3323
4221
|
close();
|
|
3324
4222
|
check.load();
|
|
3325
|
-
} }, labels.loadAnyway), /* @__PURE__ */
|
|
4223
|
+
} }, labels.loadAnyway), /* @__PURE__ */ React8.createElement("button", { type: "button", className: "pk-btn", "data-testid": "load-cancel", onClick: onCancel }, labels.cancel)), check.switchTo ? /* @__PURE__ */ React8.createElement("p", { className: "pk-hint" }, labels.switchStartsFresh) : null);
|
|
3326
4224
|
}
|
|
3327
4225
|
function LoadView({ labels, onLoadText, close }) {
|
|
3328
|
-
const [text, setText] =
|
|
3329
|
-
const [problem, setProblem] =
|
|
4226
|
+
const [text, setText] = useState6("");
|
|
4227
|
+
const [problem, setProblem] = useState6(
|
|
3330
4228
|
/** @type {string | null} */
|
|
3331
4229
|
null
|
|
3332
4230
|
);
|
|
3333
|
-
const [check, setCheck] =
|
|
4231
|
+
const [check, setCheck] = useState6(
|
|
3334
4232
|
/** @type {any} */
|
|
3335
4233
|
null
|
|
3336
4234
|
);
|
|
3337
|
-
const [busy, setBusy] =
|
|
4235
|
+
const [busy, setBusy] = useState6(false);
|
|
3338
4236
|
const file = useRef3(
|
|
3339
4237
|
/** @type {HTMLInputElement | null} */
|
|
3340
4238
|
null
|
|
@@ -3363,9 +4261,9 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
3363
4261
|
}
|
|
3364
4262
|
};
|
|
3365
4263
|
if (check) {
|
|
3366
|
-
return /* @__PURE__ */
|
|
4264
|
+
return /* @__PURE__ */ React8.createElement(LoadCheck, { check, labels, onCancel: () => setCheck(null), close });
|
|
3367
4265
|
}
|
|
3368
|
-
return /* @__PURE__ */
|
|
4266
|
+
return /* @__PURE__ */ React8.createElement(
|
|
3369
4267
|
"form",
|
|
3370
4268
|
{
|
|
3371
4269
|
className: "pk-inline-form pk-load-view",
|
|
@@ -3374,8 +4272,8 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
3374
4272
|
load(text);
|
|
3375
4273
|
}
|
|
3376
4274
|
},
|
|
3377
|
-
/* @__PURE__ */
|
|
3378
|
-
/* @__PURE__ */
|
|
4275
|
+
/* @__PURE__ */ React8.createElement("p", { className: "pk-hint" }, labels.loadViewHint),
|
|
4276
|
+
/* @__PURE__ */ React8.createElement(
|
|
3379
4277
|
ClearInput,
|
|
3380
4278
|
{
|
|
3381
4279
|
multiline: true,
|
|
@@ -3395,8 +4293,8 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
3395
4293
|
inputRef: field
|
|
3396
4294
|
}
|
|
3397
4295
|
),
|
|
3398
|
-
problem ? /* @__PURE__ */
|
|
3399
|
-
/* @__PURE__ */
|
|
4296
|
+
problem ? /* @__PURE__ */ React8.createElement("p", { id: problemId, className: "pk-form-problem", role: "alert", "data-testid": "load-view-problem" }, problem) : null,
|
|
4297
|
+
/* @__PURE__ */ React8.createElement(
|
|
3400
4298
|
"input",
|
|
3401
4299
|
{
|
|
3402
4300
|
ref: file,
|
|
@@ -3427,8 +4325,8 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
3427
4325
|
}
|
|
3428
4326
|
}
|
|
3429
4327
|
),
|
|
3430
|
-
/* @__PURE__ */
|
|
3431
|
-
/* @__PURE__ */
|
|
4328
|
+
/* @__PURE__ */ React8.createElement("button", { type: "button", className: "pk-btn", onClick: () => file.current?.click(), disabled: busy, "data-testid": "load-view-choose" }, /* @__PURE__ */ React8.createElement(Icon, { name: "file" }), /* @__PURE__ */ React8.createElement("span", { className: "pk-btn-text" }, labels.chooseFile)),
|
|
4329
|
+
/* @__PURE__ */ React8.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: busy || !text.trim(), "data-testid": "load-view-apply" }, labels.load)
|
|
3432
4330
|
);
|
|
3433
4331
|
}
|
|
3434
4332
|
function viewActions(ctx, labels) {
|
|
@@ -3475,11 +4373,11 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
3475
4373
|
const can = { host: Boolean(actions.onSave), store: Boolean(actions.store), publish: Boolean(onPublish), sourceId: actions.sourceId, sheet: actions.sheet ?? null };
|
|
3476
4374
|
const target = saveTarget(actions.loaded, templates, can, actions.empty);
|
|
3477
4375
|
const store = actions.store && !actions.onSave;
|
|
3478
|
-
const [asking, setAsking] =
|
|
4376
|
+
const [asking, setAsking] = useState6(
|
|
3479
4377
|
/** @type {{ kind: "delete" | "publish" | "replaceShared", t?: any, focus?: string } | null} */
|
|
3480
4378
|
null
|
|
3481
4379
|
);
|
|
3482
|
-
const [busy, setBusy] =
|
|
4380
|
+
const [busy, setBusy] = useState6(false);
|
|
3483
4381
|
useEffect3(() => {
|
|
3484
4382
|
share?.prepare?.();
|
|
3485
4383
|
}, [share]);
|
|
@@ -3582,13 +4480,13 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
3582
4480
|
];
|
|
3583
4481
|
const panel = (id, back) => {
|
|
3584
4482
|
if (id === "saveAs") {
|
|
3585
|
-
return /* @__PURE__ */
|
|
4483
|
+
return /* @__PURE__ */ React8.createElement(SaveView, { labels, button: actions.loaded ? labels.saveAs.replace(/…$/, "") : labels.save, onSave: (name, t) => save(t, name), resolve: (name) => saveAsTarget(name, templates, can), close });
|
|
3586
4484
|
}
|
|
3587
4485
|
if (id === "load" && act) {
|
|
3588
|
-
return /* @__PURE__ */
|
|
4486
|
+
return /* @__PURE__ */ React8.createElement(LoadView, { labels, onLoadText: act.loadText, close });
|
|
3589
4487
|
}
|
|
3590
4488
|
if (id === "confirm" && question && asking) {
|
|
3591
|
-
return /* @__PURE__ */
|
|
4489
|
+
return /* @__PURE__ */ React8.createElement(
|
|
3592
4490
|
Confirm,
|
|
3593
4491
|
{
|
|
3594
4492
|
question: question.text,
|
|
@@ -3619,340 +4517,29 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
3619
4517
|
}
|
|
3620
4518
|
return null;
|
|
3621
4519
|
};
|
|
3622
|
-
return /* @__PURE__ */
|
|
4520
|
+
return /* @__PURE__ */ React8.createElement(LevelMenu, { name: labels.views, labels, topics, close, onPick: runChoice(close), panel, focusAgain: templates.length });
|
|
3623
4521
|
}
|
|
3624
|
-
function ExportOption({ icon, text, info, onSelect, testId, disabled, reason }) {
|
|
3625
|
-
const option = /* @__PURE__ */
|
|
3626
|
-
return info ? /* @__PURE__ */
|
|
4522
|
+
function ExportOption({ icon, text, info, onSelect, testId, disabled, reason, onIntent }) {
|
|
4523
|
+
const option = /* @__PURE__ */ React8.createElement(Option, { icon, onSelect, disabled, reason, testId }, text);
|
|
4524
|
+
return info ? /* @__PURE__ */ React8.createElement("div", { className: "pk-setting-row", onPointerEnter: onIntent, onPointerDown: onIntent, onFocus: onIntent }, option, /* @__PURE__ */ React8.createElement(SettingInfo, { id: (
|
|
3627
4525
|
/** @type {any} */
|
|
3628
4526
|
info
|
|
3629
4527
|
), name: text })) : option;
|
|
3630
4528
|
}
|
|
3631
4529
|
function ExportPanel({ labels, onExport, chartReady, display, empty = false, dataExport, prepare, close }) {
|
|
3632
4530
|
const source = dataExport ? dataExportFor(dataExport.exportData, dataExport.encoded).source : false;
|
|
3633
|
-
useEffect3(() =>
|
|
3634
|
-
prepare();
|
|
3635
|
-
}, [prepare]);
|
|
4531
|
+
useEffect3(() => prepare("menu"), [prepare]);
|
|
3636
4532
|
const run = (kind) => () => {
|
|
3637
4533
|
close();
|
|
3638
4534
|
onExport(kind);
|
|
3639
4535
|
};
|
|
3640
4536
|
const off = empty ? { disabled: true, reason: labels.exportNeedsField } : {};
|
|
3641
|
-
|
|
4537
|
+
const noRows = (dataExport?.encoded?.length ?? 0) === 0 ? { disabled: true, reason: labels.exportNeedsRows } : {};
|
|
4538
|
+
return /* @__PURE__ */ React8.createElement(React8.Fragment, null, /* @__PURE__ */ React8.createElement(Section, { title: labels.exportDownload }, /* @__PURE__ */ React8.createElement(ExportOption, { icon: "file", text: labels.exportXlsx, info: "exportXlsx", onSelect: run("xlsx"), ...off, testId: "export-xlsx" }), /* @__PURE__ */ React8.createElement(ExportOption, { icon: "file", text: labels.exportCsv, info: "exportCsv", onSelect: run("csv"), ...off, testId: "export-csv" }), /* @__PURE__ */ React8.createElement(ExportOption, { icon: "file", text: labels.exportHtml, info: "exportHtml", onSelect: run("html"), ...off, testId: "export-html" }), /* @__PURE__ */ React8.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__ */ React8.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__ */ React8.createElement(Section, { title: labels.exportPrintGroup }, /* @__PURE__ */ React8.createElement(ExportOption, { icon: "print", text: labels.exportPrint, info: "exportPrint", onSelect: run("print"), ...off, testId: "export-print", onIntent: () => prepare("print") })), /* @__PURE__ */ React8.createElement(Section, { title: labels.exportCopy }, /* @__PURE__ */ React8.createElement(ExportOption, { icon: "copy", text: labels.copyTable, info: "copyTable", onSelect: run("copy-table"), ...off, testId: "export-copy-table" }), /* @__PURE__ */ React8.createElement(ExportOption, { icon: "copy", text: labels.copyDataJson, info: "copyDataJson", onSelect: run("copy-json"), ...off, testId: "export-copy-json" }), /* @__PURE__ */ React8.createElement(ExportOption, { icon: "image", text: labels.copyChart, disabled: empty || !chartReady, reason: empty ? off.reason : display !== "chart" ? labels.exportPngNeedsChart : void 0, onSelect: run("copy-chart"), testId: "export-copy-chart" })), source ? /* @__PURE__ */ React8.createElement(Section, { title: labels.exportDataGroup }, /* @__PURE__ */ React8.createElement(ExportOption, { icon: "file", text: labels.exportDataCsv, info: "exportDataCsv", onSelect: run("data-csv"), ...noRows, testId: "export-data-csv" }), /* @__PURE__ */ React8.createElement(ExportOption, { icon: "file", text: labels.exportDataJson, info: "exportDataJson", onSelect: run("data-json"), ...noRows, testId: "export-data-json" })) : null);
|
|
3642
4539
|
}
|
|
3643
4540
|
|
|
3644
4541
|
// src/drill-panel.jsx
|
|
3645
|
-
import
|
|
3646
|
-
|
|
3647
|
-
// src/export-run.js
|
|
3648
|
-
import { chartThemeFrom, toGrid } from "pivotkit-core";
|
|
3649
|
-
|
|
3650
|
-
// src/print-frame.js
|
|
3651
|
-
var FRAME_CLASS = "pk-print-frame";
|
|
3652
|
-
var listeners = /* @__PURE__ */ new WeakMap();
|
|
3653
|
-
function removeFrame(frame) {
|
|
3654
|
-
listeners.get(frame)?.abort();
|
|
3655
|
-
frame.remove();
|
|
3656
|
-
}
|
|
3657
|
-
var PRINT_LOAD_TIMEOUT = 5e3;
|
|
3658
|
-
function printParts(html, parser) {
|
|
3659
|
-
const styles = [];
|
|
3660
|
-
const text = html.replace(/<style>([\s\S]*?)<\/style>/g, (_, css) => (styles.push(css), ""));
|
|
3661
|
-
const parsed = parser.parseFromString(text, "text/html");
|
|
3662
|
-
for (const node of parsed.querySelectorAll("style, script, meta, link, base")) {
|
|
3663
|
-
node.remove();
|
|
3664
|
-
}
|
|
3665
|
-
return { css: styles.join("\n"), lang: parsed.documentElement.getAttribute("lang") ?? "", dir: parsed.documentElement.getAttribute("dir") ?? "", title: parsed.title, body: parsed.body };
|
|
3666
|
-
}
|
|
3667
|
-
async function printHtml(html, container) {
|
|
3668
|
-
const doc = container.ownerDocument;
|
|
3669
|
-
const view = doc.defaultView;
|
|
3670
|
-
if (!view) {
|
|
3671
|
-
return false;
|
|
3672
|
-
}
|
|
3673
|
-
for (const old of container.querySelectorAll(`iframe.${FRAME_CLASS}`)) {
|
|
3674
|
-
removeFrame(
|
|
3675
|
-
/** @type {HTMLIFrameElement} */
|
|
3676
|
-
old
|
|
3677
|
-
);
|
|
3678
|
-
}
|
|
3679
|
-
const parts = printParts(html, new view.DOMParser());
|
|
3680
|
-
const frame = doc.createElement("iframe");
|
|
3681
|
-
frame.className = FRAME_CLASS;
|
|
3682
|
-
frame.setAttribute("sandbox", "allow-same-origin allow-modals");
|
|
3683
|
-
frame.setAttribute("aria-hidden", "true");
|
|
3684
|
-
frame.setAttribute("tabindex", "-1");
|
|
3685
|
-
frame.title = parts.title;
|
|
3686
|
-
frame.hidden = true;
|
|
3687
|
-
const loaded = new Promise((resolve) => {
|
|
3688
|
-
const timer = setTimeout(() => resolve(false), PRINT_LOAD_TIMEOUT);
|
|
3689
|
-
const done = () => {
|
|
3690
|
-
if (frame.contentDocument?.URL === "about:srcdoc" && frame.contentDocument.readyState === "complete") {
|
|
3691
|
-
clearTimeout(timer);
|
|
3692
|
-
frame.removeEventListener("load", done);
|
|
3693
|
-
resolve(true);
|
|
3694
|
-
}
|
|
3695
|
-
};
|
|
3696
|
-
frame.addEventListener("load", done);
|
|
3697
|
-
});
|
|
3698
|
-
frame.srcdoc = '<!doctype html><html><head><meta charset="utf-8"><title></title></head><body></body></html>';
|
|
3699
|
-
container.append(frame);
|
|
3700
|
-
const win = await loaded ? frame.contentWindow : null;
|
|
3701
|
-
const fdoc = frame.contentDocument;
|
|
3702
|
-
if (!win || !fdoc || !fdoc.body) {
|
|
3703
|
-
frame.remove();
|
|
3704
|
-
return false;
|
|
3705
|
-
}
|
|
3706
|
-
fdoc.documentElement.lang = parts.lang;
|
|
3707
|
-
fdoc.documentElement.dir = parts.dir;
|
|
3708
|
-
fdoc.title = parts.title;
|
|
3709
|
-
const FrameSheet = (
|
|
3710
|
-
/** @type {any} */
|
|
3711
|
-
win.CSSStyleSheet
|
|
3712
|
-
);
|
|
3713
|
-
if (typeof FrameSheet === "function" && "adoptedStyleSheets" in fdoc) {
|
|
3714
|
-
const sheet = new FrameSheet();
|
|
3715
|
-
sheet.replaceSync(parts.css);
|
|
3716
|
-
fdoc.adoptedStyleSheets = [sheet];
|
|
3717
|
-
} else {
|
|
3718
|
-
const style = fdoc.createElement("style");
|
|
3719
|
-
style.textContent = parts.css;
|
|
3720
|
-
fdoc.head.append(style);
|
|
3721
|
-
}
|
|
3722
|
-
fdoc.body.replaceChildren(...[...parts.body.childNodes].map((node) => fdoc.importNode(node, true)));
|
|
3723
|
-
frame.hidden = false;
|
|
3724
|
-
await new Promise((resolve) => view.requestAnimationFrame(() => setTimeout(resolve, 0)));
|
|
3725
|
-
if (!frame.isConnected) {
|
|
3726
|
-
return true;
|
|
3727
|
-
}
|
|
3728
|
-
const ended = new AbortController();
|
|
3729
|
-
listeners.set(frame, ended);
|
|
3730
|
-
const after = () => setTimeout(() => removeFrame(frame), 0);
|
|
3731
|
-
win.addEventListener("afterprint", after, { once: true, signal: ended.signal });
|
|
3732
|
-
view.addEventListener("afterprint", after, { once: true, signal: ended.signal });
|
|
3733
|
-
win.print();
|
|
3734
|
-
return true;
|
|
3735
|
-
}
|
|
3736
|
-
|
|
3737
|
-
// src/light-tokens.js
|
|
3738
|
-
function lightTokens(root, names, more = () => ({})) {
|
|
3739
|
-
const host = (
|
|
3740
|
-
/** @type {{ host?: Element }} */
|
|
3741
|
-
root.getRootNode().host
|
|
3742
|
-
);
|
|
3743
|
-
const dark = [root, ...host ? [host] : []].filter((el) => el.getAttribute("data-pk-theme") === "dark");
|
|
3744
|
-
const read = () => {
|
|
3745
|
-
const style = getComputedStyle(root);
|
|
3746
|
-
return { ...Object.fromEntries(names.map((name) => [name, style.getPropertyValue(name).trim()]).filter(([, value]) => value)), ...more() };
|
|
3747
|
-
};
|
|
3748
|
-
if (!dark.length) {
|
|
3749
|
-
return read();
|
|
3750
|
-
}
|
|
3751
|
-
const kept = [root.style.getPropertyValue("--pk-duration"), root.style.getPropertyPriority("--pk-duration")];
|
|
3752
|
-
root.style.setProperty("--pk-duration", "0ms", "important");
|
|
3753
|
-
try {
|
|
3754
|
-
for (const el of dark) {
|
|
3755
|
-
el.setAttribute("data-pk-theme", "light");
|
|
3756
|
-
}
|
|
3757
|
-
try {
|
|
3758
|
-
return read();
|
|
3759
|
-
} finally {
|
|
3760
|
-
for (const el of dark) {
|
|
3761
|
-
el.setAttribute("data-pk-theme", "dark");
|
|
3762
|
-
}
|
|
3763
|
-
getComputedStyle(root).getPropertyValue("--pk-duration");
|
|
3764
|
-
}
|
|
3765
|
-
} finally {
|
|
3766
|
-
if (kept[0]) {
|
|
3767
|
-
root.style.setProperty("--pk-duration", kept[0], kept[1]);
|
|
3768
|
-
} else {
|
|
3769
|
-
root.style.removeProperty("--pk-duration");
|
|
3770
|
-
}
|
|
3771
|
-
}
|
|
3772
|
-
}
|
|
3773
|
-
|
|
3774
|
-
// src/export-run.js
|
|
3775
|
-
var XLSX_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
3776
|
-
var exporters = null;
|
|
3777
|
-
var pending = null;
|
|
3778
|
-
function loadExporters() {
|
|
3779
|
-
pending ??= import("pivotkit-core/export").then(
|
|
3780
|
-
(m) => {
|
|
3781
|
-
exporters = m;
|
|
3782
|
-
return m;
|
|
3783
|
-
},
|
|
3784
|
-
(error) => {
|
|
3785
|
-
pending = null;
|
|
3786
|
-
throw error;
|
|
3787
|
-
}
|
|
3788
|
-
);
|
|
3789
|
-
return pending;
|
|
3790
|
-
}
|
|
3791
|
-
var reportPending = null;
|
|
3792
|
-
function loadReport(loadECharts) {
|
|
3793
|
-
reportPending ??= Promise.all([import("./chunks/report-run-BZBFOMPF.js"), loadECharts()]).catch((error) => {
|
|
3794
|
-
reportPending = null;
|
|
3795
|
-
throw error;
|
|
3796
|
-
});
|
|
3797
|
-
return reportPending;
|
|
3798
|
-
}
|
|
3799
|
-
var exportersNow = () => exporters;
|
|
3800
|
-
var prepareExporters = () => void loadExporters().catch(() => void 0);
|
|
3801
|
-
function deliver(blob, { doc, onExport, ...file }) {
|
|
3802
|
-
if (onExport?.({ ...file, blob }) === false) {
|
|
3803
|
-
return false;
|
|
3804
|
-
}
|
|
3805
|
-
saveBlob(blob, file.fileName, doc);
|
|
3806
|
-
return true;
|
|
3807
|
-
}
|
|
3808
|
-
async function copyOut(text, { type, container, onExport, ...file }) {
|
|
3809
|
-
if (onExport?.({ ...file, blob: new Blob([text], { type }), text }) === false) {
|
|
3810
|
-
return "kept";
|
|
3811
|
-
}
|
|
3812
|
-
return await copyText(text, container) ? "copied" : "blocked";
|
|
3813
|
-
}
|
|
3814
|
-
var isColor = (text) => typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("color", text);
|
|
3815
|
-
function hexColor(text, ctx, supports = isColor) {
|
|
3816
|
-
if (!text || !ctx || !supports(text)) {
|
|
3817
|
-
return null;
|
|
3818
|
-
}
|
|
3819
|
-
ctx.fillStyle = text;
|
|
3820
|
-
const hex = String(ctx.fillStyle).toLowerCase();
|
|
3821
|
-
return /^#[0-9a-f]{6}$/.test(hex) ? hex : null;
|
|
3822
|
-
}
|
|
3823
|
-
var XLSX_TOKENS = Object.freeze(["--pk-scale-low", "--pk-scale-mid", "--pk-scale-high", "--pk-chart-1"]);
|
|
3824
|
-
function xlsxThemeOf(style, toHex) {
|
|
3825
|
-
const { colorScale = [], dataBar = "" } = chartThemeFrom(style);
|
|
3826
|
-
const scale = colorScale.map(toHex);
|
|
3827
|
-
const [low, high, mid] = [scale[0], scale.at(-1), scale.length === 3 ? scale[1] : null];
|
|
3828
|
-
const bar = toHex(dataBar);
|
|
3829
|
-
return {
|
|
3830
|
-
...low && high ? { colorScale: mid ? [low, mid, high] : [low, high] } : {},
|
|
3831
|
-
...bar ? { dataBar: bar } : {}
|
|
3832
|
-
};
|
|
3833
|
-
}
|
|
3834
|
-
function xlsxTheme(root) {
|
|
3835
|
-
if (!root) {
|
|
3836
|
-
return void 0;
|
|
3837
|
-
}
|
|
3838
|
-
const tokens = lightTokens(root, XLSX_TOKENS);
|
|
3839
|
-
const ctx = root.ownerDocument.createElement("canvas").getContext("2d");
|
|
3840
|
-
return xlsxThemeOf({ getPropertyValue: (name) => tokens[name] ?? "" }, (text) => hexColor(text, ctx));
|
|
3841
|
-
}
|
|
3842
|
-
function reportTokens(root, report, chart) {
|
|
3843
|
-
if (!root) {
|
|
3844
|
-
return void 0;
|
|
3845
|
-
}
|
|
3846
|
-
const tokens = lightTokens(root, report.REPORT_TOKENS, () => chart.tokenLengths(root, [...chart.LENGTH_TOKENS, ...report.REPORT_LENGTHS]));
|
|
3847
|
-
return Object.keys(tokens).length ? tokens : void 0;
|
|
3848
|
-
}
|
|
3849
|
-
async function runExport(kind, { fileName, result, encoded, exportData, locale, labels, limits, root, chartRef, announce, onExport, title, source, loadECharts }) {
|
|
3850
|
-
labels = menuLabels(labels);
|
|
3851
|
-
const base = safeFileName(fileName);
|
|
3852
|
-
const doc = root.current?.ownerDocument;
|
|
3853
|
-
try {
|
|
3854
|
-
if (kind === "png") {
|
|
3855
|
-
const surface = root.current ? getComputedStyle(root.current).getPropertyValue("--pk-surface").trim() : "";
|
|
3856
|
-
const url = chartRef.current?.getDataURL({ type: "png", pixelRatio: 2, backgroundColor: surface || void 0 });
|
|
3857
|
-
const file2 = `${base}.png`;
|
|
3858
|
-
if (url && deliver(dataUrlToBlob(url), { kind, fileName: file2, doc, onExport })) {
|
|
3859
|
-
announce(fill(labels.toastExported, { file: file2 }));
|
|
3860
|
-
}
|
|
3861
|
-
return;
|
|
3862
|
-
}
|
|
3863
|
-
if (kind === "data-csv" || kind === "data-json") {
|
|
3864
|
-
const data = encoded ?? result?.encoded;
|
|
3865
|
-
if (!data) {
|
|
3866
|
-
return;
|
|
3867
|
-
}
|
|
3868
|
-
const scope = dataExportFor(exportData, data);
|
|
3869
|
-
if (!scope.source) {
|
|
3870
|
-
return;
|
|
3871
|
-
}
|
|
3872
|
-
const m2 = exporters ?? await loadExporters();
|
|
3873
|
-
const csv = kind === "data-csv";
|
|
3874
|
-
const file2 = `${base}-data.${csv ? "csv" : "json"}`;
|
|
3875
|
-
const options = { ...limits ? { limits } : {}, ...scope.columns ? { columns: scope.columns } : {} };
|
|
3876
|
-
const blob = csv ? new Blob(
|
|
3877
|
-
/** @type {BlobPart[]} */
|
|
3878
|
-
m2.dataToCsvParts(data, options),
|
|
3879
|
-
{ type: "text/csv;charset=utf-8" }
|
|
3880
|
-
) : new Blob([m2.dataToJson(data, options)], { type: "application/json" });
|
|
3881
|
-
if (deliver(blob, { kind, fileName: file2, doc, onExport })) {
|
|
3882
|
-
announce(fill(labels.toastExported, { file: file2 }));
|
|
3883
|
-
}
|
|
3884
|
-
return;
|
|
3885
|
-
}
|
|
3886
|
-
if (!result) {
|
|
3887
|
-
return;
|
|
3888
|
-
}
|
|
3889
|
-
if (kind === "html" || kind === "svg" || kind === "print") {
|
|
3890
|
-
const [report, echarts] = await loadReport(
|
|
3891
|
-
/** @type {() => Promise<any>} */
|
|
3892
|
-
loadECharts
|
|
3893
|
-
);
|
|
3894
|
-
const chart = chartRef.current;
|
|
3895
|
-
const size = chart ? { width: clampSize(chart.getWidth()), height: clampSize(chart.getHeight()) } : void 0;
|
|
3896
|
-
const rendered = await report.render(result.view, result.encoded, {
|
|
3897
|
-
format: kind === "svg" ? "svg" : "html",
|
|
3898
|
-
echarts,
|
|
3899
|
-
locale,
|
|
3900
|
-
trusted: true,
|
|
3901
|
-
labels: labels.core,
|
|
3902
|
-
...limits ? { limits } : {},
|
|
3903
|
-
timeZone: result.timeZone,
|
|
3904
|
-
...title ? { title } : {},
|
|
3905
|
-
...source ? { source } : {},
|
|
3906
|
-
...size ? { size } : {},
|
|
3907
|
-
tokens: reportTokens(root.current, report, echarts),
|
|
3908
|
-
chartEmbed: kind === "print" ? "inline" : "image"
|
|
3909
|
-
});
|
|
3910
|
-
const file2 = `${base}.${kind === "svg" ? "svg" : "html"}`;
|
|
3911
|
-
const blob = new Blob([
|
|
3912
|
-
/** @type {BlobPart} */
|
|
3913
|
-
rendered.body
|
|
3914
|
-
], { type: rendered.mediaType });
|
|
3915
|
-
if (kind !== "print") {
|
|
3916
|
-
if (deliver(blob, { kind, fileName: file2, doc, onExport })) {
|
|
3917
|
-
announce(fill(labels.toastExported, { file: file2 }));
|
|
3918
|
-
}
|
|
3919
|
-
return;
|
|
3920
|
-
}
|
|
3921
|
-
if (onExport?.({ kind, fileName: file2, blob }) === false) {
|
|
3922
|
-
return;
|
|
3923
|
-
}
|
|
3924
|
-
if (!root.current || !await printHtml(
|
|
3925
|
-
/** @type {string} */
|
|
3926
|
-
rendered.text,
|
|
3927
|
-
root.current
|
|
3928
|
-
)) {
|
|
3929
|
-
announce(labels.toastPrintBlocked, { tone: "error" });
|
|
3930
|
-
}
|
|
3931
|
-
return;
|
|
3932
|
-
}
|
|
3933
|
-
const m = exporters ?? await loadExporters();
|
|
3934
|
-
const grid = toGrid(result, { locale, labels: labels.core, limits });
|
|
3935
|
-
if (kind === "copy-table" || kind === "copy-json") {
|
|
3936
|
-
const json = kind === "copy-json";
|
|
3937
|
-
const done = await copyOut(json ? m.toJson(grid) : m.toTsv(grid), { kind, fileName: `${base}.${json ? "json" : "tsv"}`, type: json ? "application/json" : "text/tab-separated-values", container: root.current, onExport });
|
|
3938
|
-
if (done !== "kept") {
|
|
3939
|
-
announce(done === "copied" ? json ? labels.toastDataCopied : labels.toastTableCopied : labels.toastCopyBlocked, done === "copied" ? void 0 : { tone: "error" });
|
|
3940
|
-
}
|
|
3941
|
-
return;
|
|
3942
|
-
}
|
|
3943
|
-
const file = `${base}.${kind}`;
|
|
3944
|
-
const bytes = kind === "xlsx" ? m.toXlsx(grid, { sheetName: base, theme: xlsxTheme(root.current) }) : m.toCsvBytes(grid, { bom: true });
|
|
3945
|
-
if (deliver(new Blob([
|
|
3946
|
-
/** @type {BlobPart} */
|
|
3947
|
-
bytes
|
|
3948
|
-
], { type: kind === "xlsx" ? XLSX_TYPE : "text/csv;charset=utf-8" }), { kind, fileName: file, doc, onExport })) {
|
|
3949
|
-
announce(fill(labels.toastExported, { file }));
|
|
3950
|
-
}
|
|
3951
|
-
} catch (e) {
|
|
3952
|
-
announce(fill(labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
|
|
3953
|
-
}
|
|
3954
|
-
}
|
|
3955
|
-
var clampSize = (px) => Math.max(100, Math.min(8e3, Math.round(Number(px) || 0)));
|
|
4542
|
+
import React9, { useContext as useContext4, useEffect as useEffect4, useId as useId6, useMemo as useMemo4, useRef as useRef4, useState as useState7 } from "react";
|
|
3956
4543
|
|
|
3957
4544
|
// src/drill-export.js
|
|
3958
4545
|
function pick(row, columns) {
|
|
@@ -4058,15 +4645,17 @@ function drillOf({ result, rowPath, colPath, count, indices, formatOf, nameOf, i
|
|
|
4058
4645
|
|
|
4059
4646
|
// src/drill-panel.jsx
|
|
4060
4647
|
function DrillPanel({ drill: source, onClose, labels, locale, exportContext: context }) {
|
|
4061
|
-
const
|
|
4062
|
-
const
|
|
4648
|
+
const scope = context ? dataExportFor(context.exportData, context.encoded) : void 0;
|
|
4649
|
+
const columns = scope?.columns;
|
|
4650
|
+
const exportContext = context && scope && drillExportOn(scope, { drillDownExport: context.drillDownExport }) ? context : void 0;
|
|
4063
4651
|
const id = useId6();
|
|
4064
4652
|
const drill = useMemo4(() => source ? drillOf(source, labels) : null, [source, labels]);
|
|
4065
4653
|
const panel = useRef4(
|
|
4066
4654
|
/** @type {HTMLDivElement | null} */
|
|
4067
4655
|
null
|
|
4068
4656
|
);
|
|
4069
|
-
const [big, setBig] =
|
|
4657
|
+
const [big, setBig] = useState7(false);
|
|
4658
|
+
const pressed = useRef4(false);
|
|
4070
4659
|
const narrow = useContext4(LayerContext).size === "narrow";
|
|
4071
4660
|
const { onKeyDown } = useModal(panel, Boolean(drill), big ? () => setBig(false) : onClose);
|
|
4072
4661
|
useEffect4(() => {
|
|
@@ -4085,7 +4674,7 @@ function DrillPanel({ drill: source, onClose, labels, locale, exportContext: con
|
|
|
4085
4674
|
void exportDrill(kind, { drill, labels, ...exportContext, columns, root: exportContext.root.current });
|
|
4086
4675
|
}
|
|
4087
4676
|
};
|
|
4088
|
-
return /* @__PURE__ */
|
|
4677
|
+
return /* @__PURE__ */ React9.createElement(React9.Fragment, null, /* @__PURE__ */ React9.createElement("div", { className: "pk-scrim pk-drill-scrim", onPointerDown: (e) => pressed.current = e.target === e.currentTarget, onClick: () => pressed.current && onClose(), "aria-hidden": "true" }), /* @__PURE__ */ React9.createElement(
|
|
4089
4678
|
"div",
|
|
4090
4679
|
{
|
|
4091
4680
|
className: `pk-drill${big && !narrow ? " pk-drill-big" : ""}`,
|
|
@@ -4102,22 +4691,22 @@ function DrillPanel({ drill: source, onClose, labels, locale, exportContext: con
|
|
|
4102
4691
|
}
|
|
4103
4692
|
}
|
|
4104
4693
|
},
|
|
4105
|
-
/* @__PURE__ */
|
|
4106
|
-
/* @__PURE__ */
|
|
4694
|
+
/* @__PURE__ */ React9.createElement("div", { className: "pk-drill-head" }, /* @__PURE__ */ React9.createElement("div", { className: "pk-drill-heading" }, /* @__PURE__ */ React9.createElement("h2", { id }, labels.drillTitle), /* @__PURE__ */ React9.createElement("p", { className: "pk-drill-path" }, drill.title), /* @__PURE__ */ React9.createElement("p", { className: "pk-muted", "data-testid": "drill-count" }, partial ? fill(labels.drillShown, { shown: drill.rows.length.toLocaleString(locale), count: n }) : plural(labels.drillCount, drill.count, { lang: labels.lang, locale }))), /* @__PURE__ */ React9.createElement("div", { className: "pk-drill-actions" }, exportContext ? /* @__PURE__ */ React9.createElement(MenuButton, { label: labels.exportLabel, icon: "download", text: labels.exportLabel, role: "dialog", align: "end", testId: "drill-export", className: "pk-btn pk-small-btn" }, (close) => /* @__PURE__ */ React9.createElement(React9.Fragment, null, partial ? /* @__PURE__ */ React9.createElement("p", { className: "pk-hint pk-menu-hint", "data-testid": "drill-export-note" }, fill(labels.drillExportNote, { shown: drill.rows.length.toLocaleString(locale), count: n })) : null, /* @__PURE__ */ React9.createElement(Section, { title: labels.exportDownload }, /* @__PURE__ */ React9.createElement(ExportOption, { icon: "file", text: labels.drillCsv, onSelect: run("drill-csv", close), testId: "drill-csv" }), /* @__PURE__ */ React9.createElement(ExportOption, { icon: "file", text: labels.drillXlsx, onSelect: run("drill-xlsx", close), testId: "drill-xlsx" })), /* @__PURE__ */ React9.createElement(Section, { title: labels.exportCopy }, /* @__PURE__ */ React9.createElement(ExportOption, { icon: "copy", text: labels.drillCopy, info: "drillCopy", onSelect: run("drill-copy", close), testId: "drill-copy" }), /* @__PURE__ */ React9.createElement(ExportOption, { icon: "copy", text: labels.drillJson, info: "drillJson", onSelect: run("drill-json", close), testId: "drill-json" })))) : null, narrow ? null : /* @__PURE__ */ React9.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "data-pk-on": big ? "" : void 0, onClick: () => setBig((on) => !on), "data-testid": "drill-enlarge" }, /* @__PURE__ */ React9.createElement(Icon, { name: "enlarge", size: 14 }), /* @__PURE__ */ React9.createElement("span", { className: "pk-btn-text" }, big ? labels.reduce : labels.enlarge)), /* @__PURE__ */ React9.createElement("button", { type: "button", className: "pk-icon-btn", onClick: onClose, "data-autofocus": "", "aria-label": labels.close, title: labels.close }, /* @__PURE__ */ React9.createElement(Icon, { name: "x" })))),
|
|
4695
|
+
/* @__PURE__ */ React9.createElement("div", { className: "pk-drill-body", tabIndex: 0, "aria-label": drill.title }, /* @__PURE__ */ React9.createElement("table", { className: "pk-drill-table" }, /* @__PURE__ */ React9.createElement("thead", null, /* @__PURE__ */ React9.createElement("tr", null, drill.columns.map((c) => /* @__PURE__ */ React9.createElement("th", { key: c.name, scope: "col", className: c.numeric ? "pk-num" : void 0, title: c.description, "aria-description": c.description }, c.label ?? c.name)))), /* @__PURE__ */ React9.createElement("tbody", null, drill.rows.map((row, i) => /* @__PURE__ */ React9.createElement("tr", { key: i }, drill.columns.map((c, k) => /* @__PURE__ */ React9.createElement("td", { key: c.name, className: c.numeric ? "pk-num" : void 0 }, c.numeric || row[k].length < 24 ? row[k] : /* @__PURE__ */ React9.createElement("div", { className: "pk-drill-text" }, row[k]))))))))
|
|
4107
4696
|
));
|
|
4108
4697
|
}
|
|
4109
4698
|
|
|
4110
4699
|
// src/data-menu.jsx
|
|
4111
|
-
import
|
|
4700
|
+
import React10, { useEffect as useEffect5, useRef as useRef5, useState as useState8 } from "react";
|
|
4112
4701
|
function DataMenu({ api, close, labels }) {
|
|
4113
4702
|
const mod = importNow();
|
|
4114
|
-
const [failed, setFailed] =
|
|
4115
|
-
const [attempt, setAttempt] =
|
|
4703
|
+
const [failed, setFailed] = useState8(false);
|
|
4704
|
+
const [attempt, setAttempt] = useState8(0);
|
|
4116
4705
|
const box = useRef5(
|
|
4117
4706
|
/** @type {HTMLDivElement | null} */
|
|
4118
4707
|
null
|
|
4119
4708
|
);
|
|
4120
|
-
const [late] =
|
|
4709
|
+
const [late] = useState8(() => !mod);
|
|
4121
4710
|
const load = useRef5(api.load);
|
|
4122
4711
|
useEffect5(() => {
|
|
4123
4712
|
load.current = api.load;
|
|
@@ -4139,27 +4728,29 @@ function DataMenu({ api, close, labels }) {
|
|
|
4139
4728
|
popover.querySelector("[data-pk-option], [data-autofocus]")?.focus({ preventScroll: true });
|
|
4140
4729
|
}
|
|
4141
4730
|
}, [late, mod, failed]);
|
|
4142
|
-
return /* @__PURE__ */
|
|
4731
|
+
return /* @__PURE__ */ React10.createElement("div", { ref: box }, mod ? /* @__PURE__ */ React10.createElement(mod.DataMenuPanel, { api, close }) : failed ? /* @__PURE__ */ React10.createElement("div", { className: "pk-menu-failed", role: "alert", "data-testid": "menu-failed" }, /* @__PURE__ */ React10.createElement("p", null, labels.menuFailed), /* @__PURE__ */ React10.createElement("button", { type: "button", className: "pk-btn pk-small-btn", "data-autofocus": "", onClick: () => {
|
|
4143
4732
|
setFailed(false);
|
|
4144
4733
|
setAttempt((n) => n + 1);
|
|
4145
|
-
} }, labels.tryAgain)) : /* @__PURE__ */
|
|
4734
|
+
} }, labels.tryAgain)) : /* @__PURE__ */ React10.createElement("p", { className: "pk-hint pk-menu-loading", role: "status" }, labels.loadingMenu));
|
|
4146
4735
|
}
|
|
4147
4736
|
export {
|
|
4737
|
+
AddMenu,
|
|
4148
4738
|
AxisMenu,
|
|
4149
|
-
|
|
4739
|
+
ChartSettingsPanel,
|
|
4150
4740
|
DataMenu,
|
|
4151
4741
|
DrillPanel,
|
|
4152
4742
|
ExportPanel,
|
|
4153
4743
|
FilterMenu,
|
|
4154
4744
|
FilterPopover,
|
|
4155
4745
|
LoadCheck,
|
|
4156
|
-
|
|
4746
|
+
MorePanel,
|
|
4747
|
+
TableSettingsPanel,
|
|
4157
4748
|
ValueMenu,
|
|
4158
4749
|
ViewsPanel,
|
|
4159
4750
|
addMenuTexts,
|
|
4160
4751
|
hasMenuTexts,
|
|
4161
4752
|
menuLabels,
|
|
4162
|
-
|
|
4753
|
+
prepareExport,
|
|
4163
4754
|
runExport,
|
|
4164
4755
|
storedViews
|
|
4165
4756
|
};
|