pivotkit-react 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +339 -1
- package/README.md +2 -2
- package/dist/chunks/{chunk-IOPAM4JD.js → chunk-2AT72SLA.js} +635 -980
- package/dist/chunks/chunk-3E4NB5RZ.js +215 -0
- package/dist/chunks/{chunk-32Z33U6S.js → chunk-3WUGQPWV.js} +106 -9
- package/dist/chunks/{chunk-7CC4JHDY.js → chunk-4RS72AAA.js} +27 -8
- package/dist/chunks/{chunk-EM23V5GH.js → chunk-E6M57YLL.js} +19 -8
- package/dist/chunks/{chunk-RWYHJRQO.js → chunk-JMRTIOX4.js} +17 -7
- package/dist/chunks/chunk-RIOSIYGC.js +665 -0
- package/dist/chunks/{chunk-APB4NW4O.js → chunk-U5Q5I2D5.js} +36 -10
- package/dist/chunks/report-run-BZBFOMPF.js +12 -0
- package/dist/chunks/{unused-texts-K3VFH65P.js → unused-texts-Y4R67XSN.js} +1 -1
- package/dist/chunks/{unused-texts-de-OW4TGIVX.js → unused-texts-de-6YVPTNVS.js} +1 -1
- package/dist/echarts.js +38 -156
- package/dist/import-ui.js +765 -0
- package/dist/import-worker.js +20 -0
- package/dist/index.js +683 -244
- package/dist/labels.js +14 -10
- package/dist/menu-texts-de.js +1 -1
- package/dist/menus.js +768 -299
- package/dist/styles.css +322 -100
- package/package.json +9 -4
- package/types/chart-decorate.d.ts +28 -4
- package/types/chart-types.d.ts +2 -4
- package/types/data-history.d.ts +85 -0
- package/types/data-keep.d.ts +51 -0
- package/types/data-menu.d.ts +11 -0
- package/types/dom.d.ts +40 -7
- package/types/echarts.d.ts +1 -1
- package/types/export-run.d.ts +37 -3
- package/types/field-info.d.ts +32 -0
- package/types/filter.d.ts +1 -1
- package/types/icons.d.ts +1 -0
- package/types/import-host.d.ts +53 -0
- package/types/import-labels.d.ts +401 -0
- package/types/import-limits.d.ts +6 -0
- package/types/import-module.d.ts +2 -0
- package/types/import-run.d.ts +73 -0
- package/types/import-source.d.ts +32 -0
- package/types/import-steps.d.ts +121 -0
- package/types/import-ui.d.ts +108 -0
- package/types/import-worker.d.ts +1 -0
- package/types/index.d.ts +81 -11
- package/types/labels.d.ts +224 -4
- package/types/lazy-import.d.ts +4 -0
- package/types/lazy-menus.d.ts +2 -2
- package/types/levels.d.ts +3 -2
- package/types/light-tokens.d.ts +16 -0
- package/types/menu-labels.d.ts +37 -17
- package/types/menu-ops.d.ts +161 -40
- package/types/menu-topics.d.ts +9 -8
- package/types/menus.d.ts +1 -0
- package/types/names.d.ts +47 -19
- package/types/overflow.d.ts +29 -17
- package/types/place.d.ts +24 -0
- package/types/popover.d.ts +47 -5
- package/types/print-frame.d.ts +24 -0
- package/types/report-run.d.ts +14 -0
- package/types/section.d.ts +2 -2
- package/types/share-actions.d.ts +3 -3
- package/types/share.d.ts +13 -17
- package/types/theme.d.ts +2 -16
- package/types/tips.d.ts +5 -0
- package/types/toasts.d.ts +1 -1
- package/types/toolbar-panels.d.ts +11 -9
- package/types/unused-keep.d.ts +20 -0
- package/types/unused-texts.d.ts +13 -3
- package/types/unused.d.ts +1 -0
- package/types/use-export.d.ts +2 -2
- package/types/use-view-history.d.ts +12 -4
- package/types/view-ops.d.ts +65 -6
- package/types/virtual.d.ts +15 -0
- package/types/chart-layout.d.ts +0 -111
package/dist/index.js
CHANGED
|
@@ -5,18 +5,10 @@ import {
|
|
|
5
5
|
DRILL_LIMIT,
|
|
6
6
|
FIELDS_COLLAPSED,
|
|
7
7
|
HelpContext,
|
|
8
|
-
Icon,
|
|
9
8
|
InfoButton,
|
|
10
|
-
LayerContext,
|
|
11
9
|
MAX_CATEGORIES,
|
|
12
|
-
MenuButton,
|
|
13
10
|
NO_EXPLANATIONS,
|
|
14
|
-
Option,
|
|
15
|
-
Popover,
|
|
16
|
-
TYPE_ICON,
|
|
17
11
|
ZONES,
|
|
18
|
-
ZONE_ICON,
|
|
19
|
-
activeIn,
|
|
20
12
|
activeTips,
|
|
21
13
|
addField,
|
|
22
14
|
allowedTips,
|
|
@@ -34,13 +26,15 @@ import {
|
|
|
34
26
|
headerSortState,
|
|
35
27
|
headerSortTarget,
|
|
36
28
|
helpSwitch,
|
|
29
|
+
importNow,
|
|
30
|
+
isEmptyPick,
|
|
37
31
|
isEmptyView,
|
|
38
32
|
itemRuleText,
|
|
39
33
|
keptOnReset,
|
|
40
34
|
layoutSummary,
|
|
41
35
|
linkNow,
|
|
42
|
-
linkParam,
|
|
43
36
|
loadCheck,
|
|
37
|
+
loadImport,
|
|
44
38
|
loadLink,
|
|
45
39
|
localStore,
|
|
46
40
|
moveField,
|
|
@@ -53,8 +47,8 @@ import {
|
|
|
53
47
|
readStoredView,
|
|
54
48
|
refLabel,
|
|
55
49
|
removeAt,
|
|
56
|
-
rootOf,
|
|
57
50
|
rowFolding,
|
|
51
|
+
same,
|
|
58
52
|
selectedItems,
|
|
59
53
|
setChart,
|
|
60
54
|
setChartDisplay,
|
|
@@ -73,8 +67,6 @@ import {
|
|
|
73
67
|
tipContext,
|
|
74
68
|
tipText,
|
|
75
69
|
toggleCollapsed,
|
|
76
|
-
useIsoLayoutEffect,
|
|
77
|
-
useModal,
|
|
78
70
|
valueConditionText,
|
|
79
71
|
valueLabel,
|
|
80
72
|
viewFromObject,
|
|
@@ -84,9 +76,24 @@ import {
|
|
|
84
76
|
writeItem,
|
|
85
77
|
writeStoredView,
|
|
86
78
|
zoneOverLimit
|
|
87
|
-
} from "./chunks/chunk-
|
|
79
|
+
} from "./chunks/chunk-2AT72SLA.js";
|
|
80
|
+
import {
|
|
81
|
+
FormNameContext,
|
|
82
|
+
Group,
|
|
83
|
+
Icon,
|
|
84
|
+
LayerContext,
|
|
85
|
+
MenuButton,
|
|
86
|
+
Option,
|
|
87
|
+
Popover,
|
|
88
|
+
TYPE_ICON,
|
|
89
|
+
ZONE_ICON,
|
|
90
|
+
activeIn,
|
|
91
|
+
rootOf,
|
|
92
|
+
tabStops,
|
|
93
|
+
useIsoLayoutEffect,
|
|
94
|
+
useModal
|
|
95
|
+
} from "./chunks/chunk-RIOSIYGC.js";
|
|
88
96
|
import {
|
|
89
|
-
LABELS,
|
|
90
97
|
MENU_TEXTS,
|
|
91
98
|
errorText,
|
|
92
99
|
fill,
|
|
@@ -94,10 +101,11 @@ import {
|
|
|
94
101
|
messageOf,
|
|
95
102
|
plural,
|
|
96
103
|
resolveLabels
|
|
97
|
-
} from "./chunks/chunk-
|
|
104
|
+
} from "./chunks/chunk-3WUGQPWV.js";
|
|
98
105
|
|
|
99
106
|
// src/PivotReport.jsx
|
|
100
107
|
import React12, { useCallback as useCallback9, useEffect as useEffect11, useId as useId4, useMemo as useMemo8, useRef as useRef11, useState as useState12, useSyncExternalStore as useSyncExternalStore3 } from "react";
|
|
108
|
+
import { flushSync } from "react-dom";
|
|
101
109
|
import { computePivot, emptyView as emptyView2, encode, fieldLabel as fieldLabel5, normalize as normalize2, suggestDateUnit, toGrid, toSeries, viewFields } from "pivotkit-core";
|
|
102
110
|
|
|
103
111
|
// src/chart.jsx
|
|
@@ -148,6 +156,7 @@ function chartSummary(s, { type, rows, valueNames, labels, locale }) {
|
|
|
148
156
|
}
|
|
149
157
|
|
|
150
158
|
// src/theme.js
|
|
159
|
+
import { CHART_COLORS, chartThemeFrom } from "pivotkit-core";
|
|
151
160
|
function resolveTheme(wanted, htmlTheme, prefersDark) {
|
|
152
161
|
if (wanted === "light" || wanted === "dark") {
|
|
153
162
|
return wanted;
|
|
@@ -157,31 +166,6 @@ function resolveTheme(wanted, htmlTheme, prefersDark) {
|
|
|
157
166
|
}
|
|
158
167
|
return prefersDark ? "dark" : "light";
|
|
159
168
|
}
|
|
160
|
-
var CHART_COLORS = 8;
|
|
161
|
-
function chartThemeFrom(style) {
|
|
162
|
-
const v = (name) => style.getPropertyValue(name).trim();
|
|
163
|
-
const colors = [];
|
|
164
|
-
for (let i = 1; i <= CHART_COLORS; i++) {
|
|
165
|
-
const c = v(`--pk-chart-${i}`);
|
|
166
|
-
if (c) {
|
|
167
|
-
colors.push(c);
|
|
168
|
-
}
|
|
169
|
-
}
|
|
170
|
-
const theme = {
|
|
171
|
-
colors,
|
|
172
|
-
textColor: v("--pk-muted") || void 0,
|
|
173
|
-
axisColor: v("--pk-border") || void 0,
|
|
174
|
-
gridColor: v("--pk-grid") || v("--pk-border") || void 0,
|
|
175
|
-
fontFamily: v("font-family") || void 0,
|
|
176
|
-
backgroundColor: "transparent"
|
|
177
|
-
};
|
|
178
|
-
const low = v("--pk-heat-low");
|
|
179
|
-
const high = v("--pk-heat-high");
|
|
180
|
-
if (low && high) {
|
|
181
|
-
theme.heatmapColors = [low, high];
|
|
182
|
-
}
|
|
183
|
-
return theme;
|
|
184
|
-
}
|
|
185
169
|
|
|
186
170
|
// src/chart.jsx
|
|
187
171
|
var loading = null;
|
|
@@ -265,7 +249,7 @@ function PivotChart({ result, series, labels, locale, themeName, root, onInstanc
|
|
|
265
249
|
if (!ready || !chart.current || !root.current) {
|
|
266
250
|
return;
|
|
267
251
|
}
|
|
268
|
-
const style =
|
|
252
|
+
const style = lib.current.chartStyle(root.current);
|
|
269
253
|
const option = toEChartsOption(result, { theme: chartThemeFrom(style), locale, labels: labels.core, maxCategories: MAX_CATEGORIES, ...series ? { series } : {}, ...drawAs ? { chart: drawAs } : {} });
|
|
270
254
|
const { axisEvery, ...drawn } = lib.current.decorate(option, style, chart.current.getHeight(), root.current.ownerDocument, chart.current.getWidth(), { categoryNames: series?.categories, axisLabels: result.view.chart.axisLabels });
|
|
271
255
|
setEvery(axisEvery);
|
|
@@ -334,8 +318,8 @@ function announcementsOf(labels) {
|
|
|
334
318
|
}
|
|
335
319
|
const zone = labels.zones[d.zone] ?? d.zone;
|
|
336
320
|
if (d.kind === "chip") {
|
|
337
|
-
const
|
|
338
|
-
const count = (d.count ?? d.index + 1) + (
|
|
321
|
+
const same2 = a?.data?.current?.kind === "chip" && a.data.current.zone === d.zone;
|
|
322
|
+
const count = (d.count ?? d.index + 1) + (same2 ? 0 : 1);
|
|
339
323
|
return fill(at, { field, zone, position: d.index + 1, count });
|
|
340
324
|
}
|
|
341
325
|
return fill(end, { field, zone });
|
|
@@ -560,6 +544,43 @@ function fieldMatches(field, query, info) {
|
|
|
560
544
|
}
|
|
561
545
|
return [field, info?.label, info?.description].some((t) => typeof t === "string" && t.toLowerCase().includes(query));
|
|
562
546
|
}
|
|
547
|
+
var IDENTIFIER_WORDS = Object.freeze(["id", "nr", "no", "number", "key", "#"]);
|
|
548
|
+
function isIdentifierName(name) {
|
|
549
|
+
const words = String(name).replace(/(\s*\([^()]*\))+\s*$/, "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Za-z])(\d)/g, "$1 $2").replace(/#/g, " # ").split(/[\s_.\-/:()]+/).filter(Boolean);
|
|
550
|
+
while (words.length > 1 && /^\d+$/.test(words[words.length - 1])) {
|
|
551
|
+
words.pop();
|
|
552
|
+
}
|
|
553
|
+
const last = words[words.length - 1];
|
|
554
|
+
return last !== void 0 && IDENTIFIER_WORDS.includes(last.toLowerCase());
|
|
555
|
+
}
|
|
556
|
+
var identifierColumns = /* @__PURE__ */ new WeakMap();
|
|
557
|
+
function isIdentifier(column) {
|
|
558
|
+
if (!column || column.type !== "number" || column.derived || !isIdentifierName(column.name)) {
|
|
559
|
+
return false;
|
|
560
|
+
}
|
|
561
|
+
const known = identifierColumns.get(column);
|
|
562
|
+
if (known !== void 0) {
|
|
563
|
+
return known;
|
|
564
|
+
}
|
|
565
|
+
let whole = true;
|
|
566
|
+
for (let i = 0; i < column.dict.length && whole; i++) {
|
|
567
|
+
whole = Number.isInteger(column.dict[i]);
|
|
568
|
+
}
|
|
569
|
+
identifierColumns.set(column, whole);
|
|
570
|
+
return whole;
|
|
571
|
+
}
|
|
572
|
+
function fieldDefaultsFor(fieldDefaults, field, column) {
|
|
573
|
+
const key = isObject(fieldDefaults) ? Object.keys(
|
|
574
|
+
/** @type {object} */
|
|
575
|
+
fieldDefaults
|
|
576
|
+
).find((k) => k.toLowerCase() === String(field).toLowerCase()) : void 0;
|
|
577
|
+
const host = key === void 0 ? void 0 : own(fieldDefaults, key);
|
|
578
|
+
const set = ["agg", "format", "drillFormat"].some((k) => own(host, k) !== void 0);
|
|
579
|
+
if (set || !isIdentifier(column)) {
|
|
580
|
+
return isObject(host) ? host : void 0;
|
|
581
|
+
}
|
|
582
|
+
return { ...isObject(host) ? host : {}, agg: "count", drillFormat: "text" };
|
|
583
|
+
}
|
|
563
584
|
|
|
564
585
|
// src/fields.jsx
|
|
565
586
|
import React3, { useCallback, useEffect as useEffect2, useId as useId2, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
|
|
@@ -629,7 +650,7 @@ function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info,
|
|
|
629
650
|
"aria-description": info ? void 0 : action.description || void 0,
|
|
630
651
|
"aria-describedby": info ? describedBy : void 0
|
|
631
652
|
},
|
|
632
|
-
/* @__PURE__ */ React3.createElement("span", { className: "pk-field-title", title: name }, name)
|
|
653
|
+
/* @__PURE__ */ React3.createElement("span", { className: "pk-field-title", title: name }, wordsOf(name))
|
|
633
654
|
), info ? /* @__PURE__ */ React3.createElement("span", { id: describedBy, className: "pk-sr" }, [action.description, info.description].filter(Boolean).join(". ")) : null, zones.length ? /* @__PURE__ */ React3.createElement("span", { className: "pk-badges", "aria-hidden": "true" }, zones.map((z) => /* @__PURE__ */ React3.createElement("span", { key: z, className: `pk-badge pk-badge-${z}`, "aria-hidden": "true", title: fill(labels.inZone, { zone: labels.zones[z] }) }, /* @__PURE__ */ React3.createElement(Icon, { name: (
|
|
634
655
|
/** @type {any} */
|
|
635
656
|
ZONE_ICON[z]
|
|
@@ -641,23 +662,19 @@ function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info,
|
|
|
641
662
|
icon: zone === "values" ? "sigma" : zone === "filters" ? "filter" : zone,
|
|
642
663
|
onSelect: () => {
|
|
643
664
|
close();
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
Option,
|
|
650
|
-
{
|
|
651
|
-
inMenu: true,
|
|
652
|
-
icon: "filter",
|
|
653
|
-
onSelect: () => {
|
|
654
|
-
close();
|
|
655
|
-
onFilter(field.name, item.current);
|
|
665
|
+
if (zone === "filters" && onFilter) {
|
|
666
|
+
onFilter(field.name, item.current);
|
|
667
|
+
} else {
|
|
668
|
+
onAdd(field.name, zone);
|
|
669
|
+
}
|
|
656
670
|
},
|
|
657
|
-
testId: `field-filter-${field.name}`
|
|
671
|
+
testId: zone === "filters" ? `field-filter-${field.name}` : void 0
|
|
658
672
|
},
|
|
659
|
-
labels.
|
|
660
|
-
)
|
|
673
|
+
fill(zone === "values" && zones.includes("values") ? labels.addAgain : labels.addTo, { zone: labels.zones[zone] })
|
|
674
|
+
)))));
|
|
675
|
+
}
|
|
676
|
+
function wordsOf(name) {
|
|
677
|
+
return name.split(/(\s+)/).map((part, i) => i % 2 === 1 ? " " : part ? /* @__PURE__ */ React3.createElement("span", { key: i, className: "pk-word" }, part) : null);
|
|
661
678
|
}
|
|
662
679
|
function FieldPanel({ fields, placed, labels, onAdd, onNote, onFilter, drawer, open, onClose, nameOf, info, showInfo = true, onSkip, collapsed = false, onCollapse }) {
|
|
663
680
|
const [query, setQuery] = useState3("");
|
|
@@ -863,11 +880,11 @@ function MenuPanel({ name, loadingText, props }) {
|
|
|
863
880
|
useEffect3(() => onMenuTexts(() => setLoads((n) => n + 1)), []);
|
|
864
881
|
const mod = menusNow(lang);
|
|
865
882
|
const current = mod && labels ? mod.menuLabels(labels) : null;
|
|
866
|
-
const [
|
|
883
|
+
const [kept2, setKept] = useState4(
|
|
867
884
|
/** @type {any} */
|
|
868
885
|
null
|
|
869
886
|
);
|
|
870
|
-
if (current && current !==
|
|
887
|
+
if (current && current !== kept2) {
|
|
871
888
|
setKept(current);
|
|
872
889
|
}
|
|
873
890
|
const [failed, setFailed] = useState4(false);
|
|
@@ -910,14 +927,14 @@ function MenuPanel({ name, loadingText, props }) {
|
|
|
910
927
|
focusFirst(box.current);
|
|
911
928
|
}
|
|
912
929
|
}, [mod, failed]);
|
|
913
|
-
const shown = mod ?? (
|
|
930
|
+
const shown = mod ?? (kept2 ? menusNow() : null);
|
|
914
931
|
const Panel = shown ? (
|
|
915
932
|
/** @type {any} */
|
|
916
933
|
shown[name]
|
|
917
934
|
) : null;
|
|
918
935
|
return /* @__PURE__ */ React4.createElement("div", { className: "pk-menu-panel", ref: box }, Panel ? (
|
|
919
936
|
// the menus' own texts (menu-labels.js) come with them, under the report's labels
|
|
920
|
-
/* @__PURE__ */ React4.createElement(Panel, { ...props, labels: current ??
|
|
937
|
+
/* @__PURE__ */ React4.createElement(Panel, { ...props, labels: current ?? kept2 ?? labels })
|
|
921
938
|
) : failed && labels ? /* @__PURE__ */ React4.createElement("div", { className: "pk-menu-failed", role: "alert", "data-testid": "menu-failed" }, /* @__PURE__ */ React4.createElement("p", null, labels.menuFailed), /* @__PURE__ */ React4.createElement(
|
|
922
939
|
"button",
|
|
923
940
|
{
|
|
@@ -934,6 +951,26 @@ function MenuPanel({ name, loadingText, props }) {
|
|
|
934
951
|
)) : loadingText ? /* @__PURE__ */ React4.createElement(Loading, { text: loadingText }) : null);
|
|
935
952
|
}
|
|
936
953
|
|
|
954
|
+
// src/import-limits.js
|
|
955
|
+
function importLimitsOf(limits, importLimits) {
|
|
956
|
+
if (importLimits === null || importLimits === void 0) {
|
|
957
|
+
return (
|
|
958
|
+
/** @type {any} */
|
|
959
|
+
limits ?? void 0
|
|
960
|
+
);
|
|
961
|
+
}
|
|
962
|
+
if (!isRecord(importLimits) || !isRecord(limits)) {
|
|
963
|
+
return (
|
|
964
|
+
/** @type {any} */
|
|
965
|
+
importLimits
|
|
966
|
+
);
|
|
967
|
+
}
|
|
968
|
+
return { ...limits, ...importLimits };
|
|
969
|
+
}
|
|
970
|
+
function isRecord(value) {
|
|
971
|
+
return value !== null && typeof value === "object" && !Array.isArray(value);
|
|
972
|
+
}
|
|
973
|
+
|
|
937
974
|
// src/skeleton.jsx
|
|
938
975
|
import React5 from "react";
|
|
939
976
|
var ROWS = 6;
|
|
@@ -994,9 +1031,73 @@ function rowLabelOf(grid, r) {
|
|
|
994
1031
|
}
|
|
995
1032
|
return texts.join(" / ");
|
|
996
1033
|
}
|
|
1034
|
+
function longestLabels(grid, col, n) {
|
|
1035
|
+
const out = [];
|
|
1036
|
+
if (n < 1) {
|
|
1037
|
+
return out;
|
|
1038
|
+
}
|
|
1039
|
+
for (let r = grid.headerRows; r < grid.rows.length; r++) {
|
|
1040
|
+
const cell = grid.rows[r][col];
|
|
1041
|
+
if (!cell || cell.kind !== "rowHeader" || !cell.text || (cell.colSpan ?? 1) > 1) {
|
|
1042
|
+
continue;
|
|
1043
|
+
}
|
|
1044
|
+
if (out.length === n && cell.text.length <= out[n - 1].text.length) {
|
|
1045
|
+
continue;
|
|
1046
|
+
}
|
|
1047
|
+
const entry = { text: cell.text, toggle: Boolean(cell.toggle), total: Boolean(cell.total) };
|
|
1048
|
+
let at = out.length;
|
|
1049
|
+
while (at > 0 && out[at - 1].text.length < entry.text.length) {
|
|
1050
|
+
at--;
|
|
1051
|
+
}
|
|
1052
|
+
out.splice(at, 0, entry);
|
|
1053
|
+
if (out.length > n) {
|
|
1054
|
+
out.pop();
|
|
1055
|
+
}
|
|
1056
|
+
}
|
|
1057
|
+
return out;
|
|
1058
|
+
}
|
|
997
1059
|
|
|
998
1060
|
// src/table.jsx
|
|
999
1061
|
var totalClass = (t) => t === 2 ? " pk-grand" : t === 1 ? " pk-sub" : "";
|
|
1062
|
+
var MEASURED_LABELS = 50;
|
|
1063
|
+
var LABEL_MAX_EM = 28;
|
|
1064
|
+
var LABEL_SLACK = 2;
|
|
1065
|
+
function labelWidths(grid, table) {
|
|
1066
|
+
const text = table.querySelector("tbody th.pk-rowHeader .pk-th-text");
|
|
1067
|
+
const content = text?.parentElement;
|
|
1068
|
+
if (!text || !content) {
|
|
1069
|
+
return null;
|
|
1070
|
+
}
|
|
1071
|
+
const probe = table.ownerDocument.createElement("span");
|
|
1072
|
+
probe.className = "pk-th-text";
|
|
1073
|
+
probe.setAttribute("aria-hidden", "true");
|
|
1074
|
+
Object.assign(probe.style, { position: "absolute", visibility: "hidden", whiteSpace: "pre", width: "auto", minWidth: "0", maxWidth: "none", overflow: "visible" });
|
|
1075
|
+
content.append(probe);
|
|
1076
|
+
try {
|
|
1077
|
+
const widthOf = (l) => {
|
|
1078
|
+
probe.style.fontWeight = l.total ? "var(--pk-weight-bold)" : "";
|
|
1079
|
+
probe.textContent = l.text;
|
|
1080
|
+
return probe.getBoundingClientRect().width;
|
|
1081
|
+
};
|
|
1082
|
+
const em = parseFloat(getComputedStyle(text).fontSize) || 14;
|
|
1083
|
+
const toggle = table.querySelector(".pk-toggle");
|
|
1084
|
+
const gap = parseFloat(getComputedStyle(content).columnGap) || 0;
|
|
1085
|
+
const toggleWidth = (toggle ? toggle.getBoundingClientRect().width : em * 1.7) + gap;
|
|
1086
|
+
const widths = [];
|
|
1087
|
+
for (let c = 0; c < grid.rowHeaderColumns; c++) {
|
|
1088
|
+
const most = Math.max(0, ...longestLabels(grid, c, MEASURED_LABELS).map((l) => widthOf(l) + (l.toggle ? toggleWidth : 0)));
|
|
1089
|
+
widths.push(Math.min(Math.ceil(most) + LABEL_SLACK, LABEL_MAX_EM * em));
|
|
1090
|
+
}
|
|
1091
|
+
return widths;
|
|
1092
|
+
} finally {
|
|
1093
|
+
probe.remove();
|
|
1094
|
+
}
|
|
1095
|
+
}
|
|
1096
|
+
var fontOf = (table) => {
|
|
1097
|
+
const s = getComputedStyle(table);
|
|
1098
|
+
return `${s.fontFamily}|${s.fontSize}|${s.fontWeight}`;
|
|
1099
|
+
};
|
|
1100
|
+
var SCALE_MID = "var(--pk-scale-mid, color-mix(in srgb, var(--pk-scale-low), var(--pk-scale-high)))";
|
|
1000
1101
|
function conditionalStyle(cell) {
|
|
1001
1102
|
const s = cell.style;
|
|
1002
1103
|
if (!s) {
|
|
@@ -1007,8 +1108,8 @@ function conditionalStyle(cell) {
|
|
|
1007
1108
|
}
|
|
1008
1109
|
if (s.scale !== void 0) {
|
|
1009
1110
|
const t = Math.max(0, Math.min(1, s.scale));
|
|
1010
|
-
const [from, to, part] = t < 0.5 ? ["--pk-scale-low",
|
|
1011
|
-
return { "--pk-cell-bg": `color-mix(in srgb,
|
|
1111
|
+
const [from, to, part] = t < 0.5 ? ["var(--pk-scale-low)", SCALE_MID, t * 2] : [SCALE_MID, "var(--pk-scale-high)", (t - 0.5) * 2];
|
|
1112
|
+
return { "--pk-cell-bg": `color-mix(in srgb, ${to} ${Math.round(part * 100)}%, ${from})` };
|
|
1012
1113
|
}
|
|
1013
1114
|
if (s.bar !== void 0) {
|
|
1014
1115
|
return { "--pk-bar": `${Math.round(s.bar * 1e3) / 10}%`, ...s.color ? { "--pk-bar-color": s.color } : {} };
|
|
@@ -1061,6 +1162,12 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
|
|
|
1061
1162
|
/** @type {{ r: number, c: number } | null} */
|
|
1062
1163
|
null
|
|
1063
1164
|
);
|
|
1165
|
+
const [labelsWide, setLabelsWide] = useState5(
|
|
1166
|
+
/** @type {{ grid: unknown, font: string, fonts: number, widths: number[] } | null} */
|
|
1167
|
+
null
|
|
1168
|
+
);
|
|
1169
|
+
const [fontsLoaded, setFontsLoaded] = useState5(0);
|
|
1170
|
+
const fixedWidths = virtual && labelsWide?.grid === grid ? labelsWide.widths : null;
|
|
1064
1171
|
const focusNext = useRef4(false);
|
|
1065
1172
|
const [sortNote, setSortNote] = useState5("");
|
|
1066
1173
|
const focusToggle = useRef4(
|
|
@@ -1074,6 +1181,35 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
|
|
|
1074
1181
|
},
|
|
1075
1182
|
[toggleGroup]
|
|
1076
1183
|
);
|
|
1184
|
+
useIsoLayoutEffect(() => {
|
|
1185
|
+
const t = table.current;
|
|
1186
|
+
if (!virtual || !t) {
|
|
1187
|
+
return;
|
|
1188
|
+
}
|
|
1189
|
+
const font = fontOf(t);
|
|
1190
|
+
if (labelsWide?.grid !== grid || labelsWide.font !== font || labelsWide.fonts !== fontsLoaded) {
|
|
1191
|
+
const widths = labelWidths(grid, t);
|
|
1192
|
+
if (widths) {
|
|
1193
|
+
setLabelsWide({ grid, font, fonts: fontsLoaded, widths });
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
});
|
|
1197
|
+
useEffect4(() => {
|
|
1198
|
+
const fonts = virtual ? table.current?.ownerDocument.fonts : void 0;
|
|
1199
|
+
if (!fonts) {
|
|
1200
|
+
return void 0;
|
|
1201
|
+
}
|
|
1202
|
+
let live = true;
|
|
1203
|
+
const loaded3 = () => live && setFontsLoaded((n) => n + 1);
|
|
1204
|
+
fonts.addEventListener?.("loadingdone", loaded3);
|
|
1205
|
+
if (fonts.status === "loading") {
|
|
1206
|
+
fonts.ready.then(loaded3, () => void 0);
|
|
1207
|
+
}
|
|
1208
|
+
return () => {
|
|
1209
|
+
live = false;
|
|
1210
|
+
fonts.removeEventListener?.("loadingdone", loaded3);
|
|
1211
|
+
};
|
|
1212
|
+
}, [virtual]);
|
|
1077
1213
|
useIsoLayoutEffect(() => {
|
|
1078
1214
|
const t = table.current;
|
|
1079
1215
|
if (!t) {
|
|
@@ -1098,7 +1234,7 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
|
|
|
1098
1234
|
}
|
|
1099
1235
|
setLefts((old) => old.length === xs.length && old.every((v, i) => Math.abs(v - xs[i]) < 0.5) ? old : xs);
|
|
1100
1236
|
}
|
|
1101
|
-
}, [grid, version, width]);
|
|
1237
|
+
}, [grid, version, width, fixedWidths]);
|
|
1102
1238
|
useEffect4(() => {
|
|
1103
1239
|
const el = wrap.current;
|
|
1104
1240
|
if (!el) {
|
|
@@ -1111,6 +1247,9 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
|
|
|
1111
1247
|
update();
|
|
1112
1248
|
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(update) : null;
|
|
1113
1249
|
ro?.observe(el);
|
|
1250
|
+
if (table.current) {
|
|
1251
|
+
ro?.observe(table.current);
|
|
1252
|
+
}
|
|
1114
1253
|
return () => ro?.disconnect();
|
|
1115
1254
|
}, []);
|
|
1116
1255
|
const head = headHeight || rowHeight * grid.headerRows;
|
|
@@ -1227,11 +1366,15 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
|
|
|
1227
1366
|
content: /* @__PURE__ */ React6.createElement("button", { type: "button", className: `pk-th-sort${state.chosen ? " pk-sorted" : ""}`, title: target.ref && next ? fill(next.order === "desc" ? labels.headerSortDesc : labels.headerSortAsc, { value: refLabel(view, target.ref, labels) }) : fill(labels.headerSort, { field, order: words(next) }), onClick: click }, /* @__PURE__ */ React6.createElement("span", { className: "pk-th-text" }, cell.text), /* @__PURE__ */ React6.createElement(Icon, { name: down ? "arrowDown" : "arrowUp", size: 14, className: "pk-th-arrow" }))
|
|
1228
1367
|
};
|
|
1229
1368
|
};
|
|
1369
|
+
const subStart = (col) => {
|
|
1370
|
+
const data = grid.dataColumns[col - grid.rowHeaderColumns];
|
|
1371
|
+
return data && data.total === 1 && data.valueIndex <= 0 ? " pk-sub-start" : "";
|
|
1372
|
+
};
|
|
1230
1373
|
const stickyStyle = (col, extra) => col < grid.rowHeaderColumns && lefts[col] !== void 0 ? { left: lefts[col], ...extra } : extra;
|
|
1231
1374
|
const headerCell = (cell, r, c) => {
|
|
1232
1375
|
const top = { top: tops[r] ?? r * rowHeight };
|
|
1233
1376
|
const sticky = c < grid.rowHeaderColumns;
|
|
1234
|
-
const className = `pk-th pk-${cell.kind}${totalClass(cell.total)}${sticky ? " pk-sticky" : ""}`;
|
|
1377
|
+
const className = `pk-th pk-${cell.kind}${totalClass(cell.total)}${subStart(c)}${sticky ? " pk-sticky" : ""}`;
|
|
1235
1378
|
const target = onSort && r === grid.headerRows - 1 ? headerSortTarget(view, cell, typeOf) : null;
|
|
1236
1379
|
const sorting = target ? sortButton(cell, target) : null;
|
|
1237
1380
|
const content = /* @__PURE__ */ React6.createElement("span", { className: "pk-th-content" }, cell.toggle ? /* @__PURE__ */ React6.createElement(Toggle, { toggle: cell.toggle, text: cell.text, labels, onToggle }) : null, sorting ? sorting.content : /* @__PURE__ */ React6.createElement("span", { className: "pk-th-text" }, cell.text));
|
|
@@ -1247,11 +1390,12 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
|
|
|
1247
1390
|
const spec = view.values[cell.valueIndex];
|
|
1248
1391
|
return /* @__PURE__ */ React6.createElement(DraggableHeader, { key: c, ...props, cell, source: { kind: "table", field: spec?.field ?? null, zone: "values", index: cell.valueIndex, label: cell.text }, description: spec?.field ? infoOf?.(spec.field)?.description : void 0, tooltip: showInfo, sort: sorting?.sort }, content);
|
|
1249
1392
|
}
|
|
1250
|
-
|
|
1393
|
+
const title = cell.kind === "colHeader" && cell.total === 1 && r < grid.headerRows - 1 ? labels.tips.colSubtotals : void 0;
|
|
1394
|
+
return /* @__PURE__ */ React6.createElement("th", { key: c, ...props, title }, content);
|
|
1251
1395
|
};
|
|
1252
1396
|
const bodyCell = ({ cell, col, rowSpan, colSpan }, r) => {
|
|
1253
1397
|
if (cell.kind === "rowHeader") {
|
|
1254
|
-
return /* @__PURE__ */ React6.createElement("th", { key: col, scope: "row", className: `pk-th pk-rowHeader pk-sticky${totalClass(cell.total)}${rowSpan > 1 ? " pk-span" : ""}`, style: stickyStyle(col), rowSpan: rowSpan > 1 ? rowSpan : void 0, colSpan: colSpan > 1 ? colSpan : void 0, title: virtual ? cell.text : void 0, onClick: showRowLabel ? () => showRowLabel(r, rowSpan) : void 0 }, /* @__PURE__ */ React6.createElement("span", { className: "pk-th-content" }, cell.toggle ? /* @__PURE__ */ React6.createElement(Toggle, { toggle: cell.toggle, text: cell.text, labels, onToggle }) : null, /* @__PURE__ */ React6.createElement("span", { className: "pk-th-text" }, cell.text)));
|
|
1398
|
+
return /* @__PURE__ */ React6.createElement("th", { key: col, scope: "row", className: `pk-th pk-rowHeader pk-sticky${totalClass(cell.total)}${rowSpan > 1 ? " pk-span" : ""}`, style: stickyStyle(col), rowSpan: rowSpan > 1 ? rowSpan : void 0, colSpan: colSpan > 1 ? colSpan : void 0, title: virtual ? cell.text : void 0, onClick: showRowLabel ? () => showRowLabel(r, rowSpan) : void 0 }, /* @__PURE__ */ React6.createElement("span", { className: "pk-th-content", style: fixedWidths && colSpan <= 1 && fixedWidths[col] !== void 0 ? { width: fixedWidths[col] } : void 0 }, cell.toggle ? /* @__PURE__ */ React6.createElement(Toggle, { toggle: cell.toggle, text: cell.text, labels, onToggle }) : null, /* @__PURE__ */ React6.createElement("span", { className: "pk-th-text" }, cell.text)));
|
|
1255
1399
|
}
|
|
1256
1400
|
const isValue = cell.valueIndex !== void 0;
|
|
1257
1401
|
const clickable = isValue && drillable(cell);
|
|
@@ -1261,7 +1405,7 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
|
|
|
1261
1405
|
"td",
|
|
1262
1406
|
{
|
|
1263
1407
|
key: col,
|
|
1264
|
-
className: `pk-td${totalClass(cell.total)}${clickable ? " pk-clickable" : ""}${cell.valueType === "text" ? " pk-text" : ""}${cond ? cell.style.bar !== void 0 ? " pk-has-bar" : " pk-has-scale" : ""}`,
|
|
1408
|
+
className: `pk-td${totalClass(cell.total)}${subStart(col)}${clickable ? " pk-clickable" : ""}${cell.valueType === "text" ? " pk-text" : ""}${cond ? cell.style.bar !== void 0 ? " pk-has-bar" : " pk-has-scale" : ""}`,
|
|
1265
1409
|
style: cond,
|
|
1266
1410
|
"data-r": r,
|
|
1267
1411
|
"data-c": col,
|
|
@@ -1277,7 +1421,7 @@ function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version
|
|
|
1277
1421
|
);
|
|
1278
1422
|
};
|
|
1279
1423
|
const columns = grid.columnCount;
|
|
1280
|
-
return /* @__PURE__ */ React6.createElement("div", { className: "pk-table-wrap", ref: wrap, onScroll: virtual ? onScroll : void 0, onBlur: virtual ? onBlur : void 0, "data-testid": "pivot-table" }, onSort ? /* @__PURE__ */ React6.createElement("span", { className: "pk-sr", role: "status", "data-testid": "sort-status" }, sortNote) : null, /* @__PURE__ */ React6.createElement("table", { ref: table, className: `pk-table${virtual ? " pk-virtual" : ""}`, style: (
|
|
1424
|
+
return /* @__PURE__ */ React6.createElement("div", { className: "pk-table-wrap", ref: wrap, onScroll: virtual ? onScroll : void 0, onBlur: virtual ? onBlur : void 0, "data-testid": "pivot-table" }, onSort ? /* @__PURE__ */ React6.createElement("span", { className: "pk-sr", role: "status", "data-testid": "sort-status" }, sortNote) : null, /* @__PURE__ */ React6.createElement("table", { ref: table, className: `pk-table${virtual ? " pk-virtual" : ""}${grid.columnCount === grid.rowHeaderColumns ? " pk-labels-only" : ""}`, style: (
|
|
1281
1425
|
/** @type {any} */
|
|
1282
1426
|
{ "--pk-row-cols": grid.rowHeaderColumns }
|
|
1283
1427
|
), onKeyDown, "aria-rowcount": grid.rows.length, "aria-label": labels.tableName, "aria-describedby": hintId }, /* @__PURE__ */ React6.createElement("thead", null, grid.rows.slice(0, grid.headerRows).map((row, r) => /* @__PURE__ */ React6.createElement("tr", { key: r }, row.map((cell, c) => cell ? headerCell(cell, r, c) : null)))), /* @__PURE__ */ React6.createElement("tbody", null, win.padTop > 0 ? /* @__PURE__ */ React6.createElement("tr", { className: "pk-spacer", "aria-hidden": "true", style: { height: win.padTop } }, /* @__PURE__ */ React6.createElement("td", { colSpan: columns })) : null, rows.map(({ index, cells }) => /* @__PURE__ */ React6.createElement("tr", { key: index, "data-r": index, "aria-rowindex": grid.headerRows + index + 1, className: totalClass(grid.bodyRows[index]?.total).trim() || void 0 }, cells.map((c) => bodyCell(c, index)))), win.padBottom > 0 ? /* @__PURE__ */ React6.createElement("tr", { className: "pk-spacer", "aria-hidden": "true", style: { height: win.padBottom } }, /* @__PURE__ */ React6.createElement("td", { colSpan: columns })) : null)));
|
|
@@ -1314,6 +1458,7 @@ function useToasts() {
|
|
|
1314
1458
|
if (toast.tone !== "error" && !paused.current) {
|
|
1315
1459
|
arm(id);
|
|
1316
1460
|
}
|
|
1461
|
+
return id;
|
|
1317
1462
|
},
|
|
1318
1463
|
[arm]
|
|
1319
1464
|
);
|
|
@@ -1452,7 +1597,7 @@ import React9, { useEffect as useEffect7, useMemo as useMemo4, useRef as useRef7
|
|
|
1452
1597
|
import { fieldLabel as fieldLabel3 } from "pivotkit-core";
|
|
1453
1598
|
|
|
1454
1599
|
// src/unused-load.js
|
|
1455
|
-
var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-
|
|
1600
|
+
var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-6YVPTNVS.js").then((m) => m.de) });
|
|
1456
1601
|
var pending2 = /* @__PURE__ */ new Map();
|
|
1457
1602
|
var loaded2 = /* @__PURE__ */ new Map();
|
|
1458
1603
|
var unusedNow = (lang) => loaded2.get(lang) ?? null;
|
|
@@ -1460,7 +1605,7 @@ function loadUnused(lang) {
|
|
|
1460
1605
|
let p = pending2.get(lang);
|
|
1461
1606
|
if (!p) {
|
|
1462
1607
|
const own2 = Object.hasOwn(UNUSED_TEXTS_OF, lang) ? UNUSED_TEXTS_OF[lang]().catch(() => null) : null;
|
|
1463
|
-
p = Promise.all([import("./chunks/unused-texts-
|
|
1608
|
+
p = Promise.all([import("./chunks/unused-texts-Y4R67XSN.js"), own2]).then(
|
|
1464
1609
|
([mod, texts]) => {
|
|
1465
1610
|
const out = { mod, lang: texts };
|
|
1466
1611
|
loaded2.set(lang, out);
|
|
@@ -1485,7 +1630,6 @@ function unusedTexts(loaded3, labels) {
|
|
|
1485
1630
|
|
|
1486
1631
|
// src/unused.jsx
|
|
1487
1632
|
var FIRST = { narrow: 2, wide: 3 };
|
|
1488
|
-
var FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
1489
1633
|
function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow, quiet }) {
|
|
1490
1634
|
const lang = labels.lang;
|
|
1491
1635
|
const show = notes.length > 0 && !dismissed;
|
|
@@ -1538,7 +1682,7 @@ function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow,
|
|
|
1538
1682
|
const dismiss = () => {
|
|
1539
1683
|
const el = box.current;
|
|
1540
1684
|
const root = el?.closest(".pk-root");
|
|
1541
|
-
const next = el && root ?
|
|
1685
|
+
const next = el && root ? tabStops(root).find((c) => !el.contains(c) && el.compareDocumentPosition(c) & Node.DOCUMENT_POSITION_FOLLOWING) : null;
|
|
1542
1686
|
onDismiss(
|
|
1543
1687
|
/** @type {HTMLElement | null} */
|
|
1544
1688
|
next ?? null
|
|
@@ -1554,49 +1698,87 @@ function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow,
|
|
|
1554
1698
|
})), notes.length > first + 1 ? /* @__PURE__ */ React9.createElement("button", { type: "button", className: "pk-btn pk-small-btn pk-issues-more", onClick: () => setAll(all === notesKey ? null : notesKey), "data-testid": "unused-more" }, cut < notes.length ? plural(labels.unusedMore, notes.length - cut, { lang, locale }) : labels.unusedFewer) : null), /* @__PURE__ */ React9.createElement("button", { type: "button", className: "pk-icon-btn pk-issues-x", "aria-label": labels.dismissIssues, title: labels.dismissIssues, onClick: dismiss, "data-testid": "dismiss-issues" }, /* @__PURE__ */ React9.createElement(Icon, { name: "x", size: 14 }))) : null, /* @__PURE__ */ React9.createElement("div", { className: "pk-sr", "aria-live": "polite", "data-testid": "unused-live" }, show && !quiet ? title : null));
|
|
1555
1699
|
}
|
|
1556
1700
|
|
|
1701
|
+
// src/unused-keep.js
|
|
1702
|
+
var PATH = /^([A-Za-z]+)(?:\[(\d+)\])?(?:\.([A-Za-z]+))?/;
|
|
1703
|
+
var lower = (v) => typeof v === "string" ? v.toLowerCase() : v;
|
|
1704
|
+
var isObject2 = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
1705
|
+
function partOf(path, raw, view) {
|
|
1706
|
+
const m = PATH.exec(path ?? "");
|
|
1707
|
+
if (!m) {
|
|
1708
|
+
return JSON.stringify(view);
|
|
1709
|
+
}
|
|
1710
|
+
const [, key, index, sub] = m;
|
|
1711
|
+
const section = Object.hasOwn(view, key) ? view[key] : void 0;
|
|
1712
|
+
if (key === "values" && index !== void 0 && Array.isArray(section)) {
|
|
1713
|
+
const given = isObject2(raw) && Array.isArray(
|
|
1714
|
+
/** @type {any} */
|
|
1715
|
+
raw.values
|
|
1716
|
+
) ? (
|
|
1717
|
+
/** @type {any} */
|
|
1718
|
+
raw.values[Number(index)]
|
|
1719
|
+
) : void 0;
|
|
1720
|
+
const match = isObject2(given) ? section.find((v) => lower(v.field ?? null) === lower(given.field ?? null) && lower(v.agg) === lower(given.agg)) : void 0;
|
|
1721
|
+
if (match) {
|
|
1722
|
+
return JSON.stringify(match);
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
if (sub !== void 0 && isObject2(section)) {
|
|
1726
|
+
return JSON.stringify(Object.hasOwn(section, sub) ? section[sub] : void 0);
|
|
1727
|
+
}
|
|
1728
|
+
return JSON.stringify(section);
|
|
1729
|
+
}
|
|
1730
|
+
function stillApplies(note, loaded3, shown) {
|
|
1731
|
+
if (!loaded3) {
|
|
1732
|
+
return true;
|
|
1733
|
+
}
|
|
1734
|
+
if ("issue" in note) {
|
|
1735
|
+
return partOf(note.issue.path, note.raw, loaded3) === partOf(note.issue.path, note.raw, shown);
|
|
1736
|
+
}
|
|
1737
|
+
return note.path === void 0 || partOf(note.path, null, loaded3) === partOf(note.path, null, shown);
|
|
1738
|
+
}
|
|
1739
|
+
|
|
1557
1740
|
// src/toolbar.jsx
|
|
1558
1741
|
import React10, { useCallback as useCallback4, useEffect as useEffect8, useMemo as useMemo5, useRef as useRef8, useState as useState8 } from "react";
|
|
1559
1742
|
|
|
1560
1743
|
// src/overflow.js
|
|
1561
|
-
var OVERFLOW_ORDER = Object.freeze(["
|
|
1744
|
+
var OVERFLOW_ORDER = Object.freeze(["layout", "options", "chartType", "data", "startOver", "views"]);
|
|
1745
|
+
var MORE_GROUPS = Object.freeze([Object.freeze(["startOver"]), Object.freeze(["layout", "chartType", "options"]), Object.freeze(["data"]), Object.freeze(["views"])]);
|
|
1562
1746
|
var TOOLBAR_ROOM = Object.freeze({
|
|
1563
|
-
// measured in Chromium at the playground's font: the longer of English and German with the gap
|
|
1564
|
-
// after it, plus 2 %; a wider font still fits, as useOverflow measures as well
|
|
1565
1747
|
fields: 6.4,
|
|
1566
1748
|
display: 15.3,
|
|
1567
1749
|
chartType: 12.9,
|
|
1568
1750
|
sep: 1,
|
|
1569
1751
|
undo: 8.75,
|
|
1570
1752
|
redo: 9.15,
|
|
1571
|
-
|
|
1753
|
+
startOver: 10.9,
|
|
1572
1754
|
layout: 8.4,
|
|
1573
1755
|
options: 8.75,
|
|
1756
|
+
data: 7.4,
|
|
1574
1757
|
views: 9.1,
|
|
1575
1758
|
export: 7.5,
|
|
1576
1759
|
more: 7.2
|
|
1577
1760
|
});
|
|
1578
|
-
var TEXT_BUTTONS = Object.freeze(["fields", "undo", "redo", "
|
|
1579
|
-
var MENU_BUTTONS = Object.freeze(["chartType", "options", "views", "export", "more"]);
|
|
1580
|
-
function toolbarTexts(
|
|
1581
|
-
const
|
|
1761
|
+
var TEXT_BUTTONS = Object.freeze(["fields", "undo", "redo", "layout"]);
|
|
1762
|
+
var MENU_BUTTONS = Object.freeze(["chartType", "startOver", "options", "data", "views", "export", "more"]);
|
|
1763
|
+
function toolbarTexts(labels) {
|
|
1764
|
+
const text = (v) => typeof v === "string" ? v : "";
|
|
1765
|
+
return (
|
|
1582
1766
|
/** @type {any} */
|
|
1583
|
-
{
|
|
1767
|
+
{
|
|
1768
|
+
fields: [text(labels.showFields)],
|
|
1769
|
+
undo: [text(labels.undo)],
|
|
1770
|
+
redo: [text(labels.redo)],
|
|
1771
|
+
startOver: [text(labels.startOver)],
|
|
1772
|
+
layout: [text(labels.layout)],
|
|
1773
|
+
options: [text(labels.options)],
|
|
1774
|
+
views: [text(labels.views)],
|
|
1775
|
+
data: [text(labels.data)],
|
|
1776
|
+
export: [text(labels.exportLabel)],
|
|
1777
|
+
more: [text(labels.more)],
|
|
1778
|
+
chartType: Object.values(labels.chartTypes ?? {}).map(text),
|
|
1779
|
+
display: [[text(labels.table), text(labels.chart)]]
|
|
1780
|
+
}
|
|
1584
1781
|
);
|
|
1585
|
-
const text = (v) => typeof v === "string" ? v : "";
|
|
1586
|
-
for (const l of sets) {
|
|
1587
|
-
out.fields.push(text(l.showFields));
|
|
1588
|
-
out.undo.push(text(l.undo));
|
|
1589
|
-
out.redo.push(text(l.redo));
|
|
1590
|
-
out.reset.push(text(l.reset));
|
|
1591
|
-
out.layout.push(text(l.layout));
|
|
1592
|
-
out.options.push(text(l.options));
|
|
1593
|
-
out.views.push(text(l.views));
|
|
1594
|
-
out.export.push(text(l.exportLabel));
|
|
1595
|
-
out.more.push(text(l.more));
|
|
1596
|
-
out.chartType.push(...Object.values(l.chartTypes ?? {}).map(text));
|
|
1597
|
-
out.display.push([text(l.table), text(l.chart)]);
|
|
1598
|
-
}
|
|
1599
|
-
return out;
|
|
1600
1782
|
}
|
|
1601
1783
|
function toolbarRoom(texts, measure, chrome) {
|
|
1602
1784
|
const widest = (list, kind = "button") => Math.max(0, ...list.map((t) => measure(t, kind)));
|
|
@@ -1613,14 +1795,22 @@ function toolbarRoom(texts, measure, chrome) {
|
|
|
1613
1795
|
room.display = chrome.display + Math.max(0, ...texts.display.map(([a, b]) => measure(a, "display") + measure(b, "display"))) + chrome.gap;
|
|
1614
1796
|
return room;
|
|
1615
1797
|
}
|
|
1616
|
-
function
|
|
1798
|
+
function overflowHidden(width, narrow, present, room = TOOLBAR_ROOM) {
|
|
1617
1799
|
const fixed = (narrow ? room.fields : 0) + room.display + room.sep + room.undo + room.redo + room.export;
|
|
1618
|
-
|
|
1619
|
-
const need = (
|
|
1620
|
-
|
|
1621
|
-
|
|
1800
|
+
const order = OVERFLOW_ORDER.filter((id) => present.includes(id));
|
|
1801
|
+
const need = (shown2) => fixed + shown2.reduce((sum, id) => sum + (room[id] ?? 0), 0) + (shown2.length < order.length ? room.more : 0);
|
|
1802
|
+
let shown = order;
|
|
1803
|
+
while (shown.length && need(shown) > width) {
|
|
1804
|
+
shown = shown.slice(1);
|
|
1622
1805
|
}
|
|
1623
|
-
|
|
1806
|
+
const gone = order.filter((id) => !shown.includes(id));
|
|
1807
|
+
for (const id of gone.reverse()) {
|
|
1808
|
+
const next = order.filter((o) => o === id || shown.includes(o));
|
|
1809
|
+
if (need(next) <= width) {
|
|
1810
|
+
shown = next;
|
|
1811
|
+
}
|
|
1812
|
+
}
|
|
1813
|
+
return order.filter((id) => !shown.includes(id));
|
|
1624
1814
|
}
|
|
1625
1815
|
|
|
1626
1816
|
// src/toolbar.jsx
|
|
@@ -1628,7 +1818,7 @@ function TextButton({ icon, label, onClick, disabled, testId, shortcut }) {
|
|
|
1628
1818
|
return /* @__PURE__ */ React10.createElement("button", { type: "button", className: "pk-btn", onClick, disabled, title: shortcut ? `${label} (${shortcut})` : void 0, "aria-keyshortcuts": shortcut ? shortcut.replace("\u2318", "Meta+").replace("\u21E7", "Shift+") : void 0, "data-testid": testId }, /* @__PURE__ */ React10.createElement(Icon, { name: icon }), /* @__PURE__ */ React10.createElement("span", { className: "pk-btn-text" }, label));
|
|
1629
1819
|
}
|
|
1630
1820
|
var measuring;
|
|
1631
|
-
var
|
|
1821
|
+
var fontOf2 = (style) => `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
|
|
1632
1822
|
function measuredRoom(el, texts) {
|
|
1633
1823
|
const doc = el.ownerDocument;
|
|
1634
1824
|
if (measuring === void 0) {
|
|
@@ -1650,10 +1840,10 @@ function measuredRoom(el, texts) {
|
|
|
1650
1840
|
if (!view) {
|
|
1651
1841
|
return null;
|
|
1652
1842
|
}
|
|
1653
|
-
const fonts = { button:
|
|
1843
|
+
const fonts = { button: fontOf2(view.getComputedStyle(
|
|
1654
1844
|
/** @type {Element} */
|
|
1655
1845
|
textOf(undo2)
|
|
1656
|
-
)), display:
|
|
1846
|
+
)), display: fontOf2(view.getComputedStyle(
|
|
1657
1847
|
/** @type {Element} */
|
|
1658
1848
|
textOf(display)
|
|
1659
1849
|
)) };
|
|
@@ -1676,14 +1866,20 @@ function measuredRoom(el, texts) {
|
|
|
1676
1866
|
};
|
|
1677
1867
|
return toolbarRoom(texts, measure, chrome);
|
|
1678
1868
|
}
|
|
1679
|
-
function useOverflow(ref, key, narrow,
|
|
1680
|
-
const [
|
|
1869
|
+
function useOverflow(ref, key, narrow, present, texts) {
|
|
1870
|
+
const [decided, setDecided] = useState8(
|
|
1871
|
+
/** @type {string[]} */
|
|
1872
|
+
[]
|
|
1873
|
+
);
|
|
1874
|
+
const [extra, setExtra] = useState8(0);
|
|
1681
1875
|
const [measure, setMeasure] = useState8(0);
|
|
1682
1876
|
const [lastKey, setLastKey] = useState8(key);
|
|
1683
|
-
const latest = useRef8(texts);
|
|
1877
|
+
const latest = useRef8({ texts, present });
|
|
1878
|
+
const waiting = useRef8(false);
|
|
1684
1879
|
useIsoLayoutEffect(() => {
|
|
1685
|
-
latest.current = texts;
|
|
1880
|
+
latest.current = { texts, present };
|
|
1686
1881
|
});
|
|
1882
|
+
const isOpen = (el) => Boolean(el.querySelector('[aria-expanded="true"]'));
|
|
1687
1883
|
if (key !== lastKey) {
|
|
1688
1884
|
setLastKey(key);
|
|
1689
1885
|
setMeasure((m) => m + 1);
|
|
@@ -1695,9 +1891,16 @@ function useOverflow(ref, key, narrow, max, texts) {
|
|
|
1695
1891
|
}
|
|
1696
1892
|
let width = -1;
|
|
1697
1893
|
const decide = () => {
|
|
1894
|
+
if (isOpen(el)) {
|
|
1895
|
+
waiting.current = true;
|
|
1896
|
+
return;
|
|
1897
|
+
}
|
|
1898
|
+
waiting.current = false;
|
|
1698
1899
|
const em = parseFloat(getComputedStyle(el).fontSize) || 14;
|
|
1699
|
-
const room = measuredRoom(el, latest.current);
|
|
1700
|
-
|
|
1900
|
+
const room = measuredRoom(el, latest.current.texts);
|
|
1901
|
+
const own2 = latest.current.present;
|
|
1902
|
+
setDecided(room ? overflowHidden(width, narrow, own2, room) : overflowHidden(width / em, narrow, own2));
|
|
1903
|
+
setExtra(0);
|
|
1701
1904
|
setMeasure((m) => m + 1);
|
|
1702
1905
|
};
|
|
1703
1906
|
const ro = new ResizeObserver(([entry]) => {
|
|
@@ -1710,23 +1913,29 @@ function useOverflow(ref, key, narrow, max, texts) {
|
|
|
1710
1913
|
width = Math.round(el.getBoundingClientRect().width);
|
|
1711
1914
|
decide();
|
|
1712
1915
|
ro.observe(el);
|
|
1916
|
+
const mo = typeof MutationObserver === "function" ? new MutationObserver(() => waiting.current && decide()) : null;
|
|
1917
|
+
mo?.observe(el, { subtree: true, attributes: true, attributeFilter: ["aria-expanded"] });
|
|
1713
1918
|
let live = true;
|
|
1714
1919
|
el.ownerDocument.fonts?.ready.then(() => live && width >= 0 && decide(), () => void 0);
|
|
1715
1920
|
return () => {
|
|
1716
1921
|
live = false;
|
|
1717
1922
|
ro.disconnect();
|
|
1923
|
+
mo?.disconnect();
|
|
1718
1924
|
};
|
|
1719
1925
|
}, [ref, narrow, key]);
|
|
1926
|
+
const order = OVERFLOW_ORDER.filter((id) => present.includes(id));
|
|
1927
|
+
const shown = order.filter((id) => !decided.includes(id));
|
|
1928
|
+
const more = shown.slice(0, extra);
|
|
1720
1929
|
useIsoLayoutEffect(() => {
|
|
1721
1930
|
const el = ref.current;
|
|
1722
|
-
if (el && el.scrollWidth > el.clientWidth + 1 &&
|
|
1723
|
-
|
|
1931
|
+
if (el && !isOpen(el) && el.scrollWidth > el.clientWidth + 1 && extra < shown.length) {
|
|
1932
|
+
setExtra(extra + 1);
|
|
1724
1933
|
}
|
|
1725
|
-
}, [ref,
|
|
1726
|
-
return
|
|
1934
|
+
}, [ref, extra, measure, key, shown.length]);
|
|
1935
|
+
return order.filter((id) => decided.includes(id) || more.includes(id));
|
|
1727
1936
|
}
|
|
1728
1937
|
function Toolbar(props) {
|
|
1729
|
-
const { view, labels, size, canUndo, canRedo, canReset, onUndo, onRedo, onReset, loadedView, empty, onDisplay, onChart, onChartDisplay, onTotal, onExpand, onCollapse, folding, templates, onLoadTemplate, templateActions, onExport, chartReady, onShowFields, layoutFolded, onLayout, zonesId, share } = props;
|
|
1938
|
+
const { view, labels, size, canUndo, canRedo, canReset, startEmpty, canNew, onUndo, onRedo, onReset, onNew, loadedView, empty, onDisplay, onChart, onChartDisplay, onTotal, onExpand, onCollapse, folding, templates, onLoadTemplate, templateActions, onExport, chartReady, onShowFields, layoutFolded, onLayout, zonesId, share } = props;
|
|
1730
1939
|
const tips = { controls: props.tipsControls, on: props.tipsOn, onOn: props.onTipsOn, canReset: props.canResetTips, onReset: props.onResetTips };
|
|
1731
1940
|
const bar = useRef8(
|
|
1732
1941
|
/** @type {HTMLDivElement | null} */
|
|
@@ -1741,34 +1950,11 @@ function Toolbar(props) {
|
|
|
1741
1950
|
null
|
|
1742
1951
|
);
|
|
1743
1952
|
const [panel, setPanel] = useState8(
|
|
1744
|
-
/** @type {"options" | "views" | "chartType" | null} */
|
|
1953
|
+
/** @type {"options" | "views" | "chartType" | "data" | null} */
|
|
1745
1954
|
null
|
|
1746
1955
|
);
|
|
1747
|
-
const
|
|
1748
|
-
const texts = useMemo5(() => toolbarTexts(
|
|
1749
|
-
const level = useOverflow(bar, `${labels.lang}:${labels.undo}:${size}`, size === "narrow", order.length, texts);
|
|
1750
|
-
const hidden = new Set(order.slice(0, level));
|
|
1751
|
-
if (panel && !hidden.has(panel)) {
|
|
1752
|
-
setPanel(null);
|
|
1753
|
-
}
|
|
1754
|
-
const closePanel = useCallback4(() => setPanel(null), []);
|
|
1755
|
-
const request = props.viewsRequest ?? 0;
|
|
1756
|
-
const [seenRequest, setSeenRequest] = useState8(request);
|
|
1757
|
-
const [clickFor, setClickFor] = useState8(0);
|
|
1758
|
-
if (request !== seenRequest) {
|
|
1759
|
-
setSeenRequest(request);
|
|
1760
|
-
if (hidden.has("views")) {
|
|
1761
|
-
setPanel("views");
|
|
1762
|
-
} else {
|
|
1763
|
-
setClickFor(request);
|
|
1764
|
-
}
|
|
1765
|
-
}
|
|
1766
|
-
useEffect8(() => {
|
|
1767
|
-
const button = viewsButton.current;
|
|
1768
|
-
if (clickFor > 0 && button && button.getAttribute("aria-expanded") !== "true") {
|
|
1769
|
-
button.click();
|
|
1770
|
-
}
|
|
1771
|
-
}, [clickFor]);
|
|
1956
|
+
const data = props.data;
|
|
1957
|
+
const texts = useMemo5(() => toolbarTexts(labels), [labels]);
|
|
1772
1958
|
const plan = props.chartPlan ?? { name: chartTypeOf(view.chart), auto: false };
|
|
1773
1959
|
const preset = plan.auto ? "auto" : plan.name;
|
|
1774
1960
|
const drawnIcon = CHART_TYPES[plan.name].icon;
|
|
@@ -1778,8 +1964,21 @@ function Toolbar(props) {
|
|
|
1778
1964
|
// the panels load with the chip menus (menus.js), on demand
|
|
1779
1965
|
options: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "OptionsPanel", loadingText: labels.loadingMenu, props: { view, labels, onTotal, onExpand, onCollapse, close, tips, mod, folding, help: props.help } }),
|
|
1780
1966
|
views: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ViewsPanel", loadingText: labels.loadingMenu, props: { templates, labels, onLoad: onLoadTemplate, actions: templateActions, close, share } }),
|
|
1781
|
-
chartType: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ChartTypePanel", loadingText: labels.loadingMenu, props: { view, plan, labels, onChart, onDisplay: onChartDisplay, close } })
|
|
1967
|
+
chartType: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ChartTypePanel", loadingText: labels.loadingMenu, props: { view, plan, labels, onChart, onDisplay: onChartDisplay, close } }),
|
|
1968
|
+
data: (close) => data?.panel(close)
|
|
1782
1969
|
};
|
|
1970
|
+
const loadedMark = (testId) => data?.loaded ? dot(testId, labels.dataLoaded) : null;
|
|
1971
|
+
const resetWhy = !canReset ? labels.resetAlready : startEmpty ? labels.resetStartEmpty : void 0;
|
|
1972
|
+
const startOverItems = (close, prefix) => [
|
|
1973
|
+
/* @__PURE__ */ React10.createElement(Option, { key: "reset", inMenu: true, icon: "reset", hint: labels.resetHint, disabled: Boolean(resetWhy), reason: resetWhy, onSelect: () => {
|
|
1974
|
+
close();
|
|
1975
|
+
onReset();
|
|
1976
|
+
}, testId: `${prefix}reset` }, labels.reset),
|
|
1977
|
+
/* @__PURE__ */ React10.createElement(Option, { key: "new", inMenu: true, icon: "newFile", hint: labels.newHint, disabled: !canNew, reason: labels.newAlready, onSelect: () => {
|
|
1978
|
+
close();
|
|
1979
|
+
onNew();
|
|
1980
|
+
}, testId: `${prefix}new-report` }, labels.newEmpty)
|
|
1981
|
+
];
|
|
1783
1982
|
const actions = {
|
|
1784
1983
|
chartType: {
|
|
1785
1984
|
place: "chart",
|
|
@@ -1789,19 +1988,16 @@ function Toolbar(props) {
|
|
|
1789
1988
|
setPanel("chartType");
|
|
1790
1989
|
}, testId: "more-chart-type" }, `${chartTypeText}\u2026`)
|
|
1791
1990
|
},
|
|
1792
|
-
|
|
1991
|
+
startOver: {
|
|
1793
1992
|
place: "history",
|
|
1794
|
-
button: () => /* @__PURE__ */ React10.createElement(
|
|
1795
|
-
entry: (close) =>
|
|
1796
|
-
close();
|
|
1797
|
-
onReset();
|
|
1798
|
-
}, testId: "more-reset" }, labels.reset)
|
|
1993
|
+
button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "startOver", label: labels.startOver, icon: "reset", text: labels.startOver, testId: "start-over", arrowOpens: true, off: resetWhy && !canNew ? labels.newAlready : void 0 }, (close) => startOverItems(close, "")),
|
|
1994
|
+
entry: (close) => startOverItems(close, "more-")
|
|
1799
1995
|
},
|
|
1800
1996
|
layout: {
|
|
1801
1997
|
place: "end",
|
|
1802
1998
|
// a toggle of the zones: the same text, open or folded; aria-pressed says which
|
|
1803
1999
|
button: () => /* @__PURE__ */ React10.createElement("button", { key: "layout", type: "button", className: "pk-btn pk-pressable", onClick: onLayout, "aria-pressed": !layoutFolded, "aria-controls": zonesId, title: labels.showLayout, "data-testid": "layout" }, /* @__PURE__ */ React10.createElement(Icon, { name: "layout" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-btn-text" }, labels.layout)),
|
|
1804
|
-
entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "layout", inMenu: true, icon: "layout", checked: !layoutFolded, onSelect: () => {
|
|
2000
|
+
entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "layout", inMenu: true, checkbox: true, icon: "layout", checked: !layoutFolded, onSelect: () => {
|
|
1805
2001
|
close();
|
|
1806
2002
|
onLayout();
|
|
1807
2003
|
}, testId: "more-layout" }, labels.layout)
|
|
@@ -1814,6 +2010,19 @@ function Toolbar(props) {
|
|
|
1814
2010
|
setPanel("options");
|
|
1815
2011
|
}, testId: "more-options" }, `${labels.options}\u2026`)
|
|
1816
2012
|
},
|
|
2013
|
+
...data ? {
|
|
2014
|
+
data: {
|
|
2015
|
+
place: (
|
|
2016
|
+
/** @type {const} */
|
|
2017
|
+
"end"
|
|
2018
|
+
),
|
|
2019
|
+
button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "data", label: labels.data, icon: "file", text: labels.data, role: "dialog", align: "end", testId: "data", mark: loadedMark("data-loaded") }, panels.data),
|
|
2020
|
+
entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "data", inMenu: true, icon: "file", onSelect: () => {
|
|
2021
|
+
close();
|
|
2022
|
+
setPanel("data");
|
|
2023
|
+
}, testId: "more-data" }, `${labels.data}\u2026`, loadedMark("more-data-loaded"))
|
|
2024
|
+
}
|
|
2025
|
+
} : {},
|
|
1817
2026
|
views: {
|
|
1818
2027
|
place: "end",
|
|
1819
2028
|
button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "views", label: labels.views, icon: "bookmark", text: labels.views, role: "dialog", align: "end", testId: "views", buttonRef: viewsButton }, panels.views),
|
|
@@ -1824,8 +2033,33 @@ function Toolbar(props) {
|
|
|
1824
2033
|
}
|
|
1825
2034
|
};
|
|
1826
2035
|
const ORDER = Object.keys(actions);
|
|
2036
|
+
const present = OVERFLOW_ORDER.filter((id) => ORDER.includes(id));
|
|
2037
|
+
const hiddenList = useOverflow(bar, `${labels.lang}:${labels.undo}:${size}:${present.join()}`, size === "narrow", present, texts);
|
|
2038
|
+
const hidden = new Set(hiddenList);
|
|
2039
|
+
if (panel && !hidden.has(panel)) {
|
|
2040
|
+
setPanel(null);
|
|
2041
|
+
}
|
|
2042
|
+
const closePanel = useCallback4(() => setPanel(null), []);
|
|
2043
|
+
const request = props.viewsRequest ?? 0;
|
|
2044
|
+
const [seenRequest, setSeenRequest] = useState8(request);
|
|
2045
|
+
const [clickFor, setClickFor] = useState8(0);
|
|
2046
|
+
if (request !== seenRequest) {
|
|
2047
|
+
setSeenRequest(request);
|
|
2048
|
+
if (hidden.has("views")) {
|
|
2049
|
+
setPanel("views");
|
|
2050
|
+
} else {
|
|
2051
|
+
setClickFor(request);
|
|
2052
|
+
}
|
|
2053
|
+
}
|
|
2054
|
+
useEffect8(() => {
|
|
2055
|
+
const button = viewsButton.current;
|
|
2056
|
+
if (clickFor > 0 && button && button.getAttribute("aria-expanded") !== "true") {
|
|
2057
|
+
button.click();
|
|
2058
|
+
}
|
|
2059
|
+
}, [clickFor]);
|
|
1827
2060
|
const buttons = (place) => ORDER.filter((id) => actions[id].place === place && !hidden.has(id)).map((id) => actions[id].button());
|
|
1828
|
-
const
|
|
2061
|
+
const dot = (testId, text) => /* @__PURE__ */ React10.createElement("span", { className: "pk-view-changed", "data-testid": testId }, /* @__PURE__ */ React10.createElement("span", { className: "pk-sr" }, text));
|
|
2062
|
+
const changedMark = (testId) => dot(testId, labels.unsavedChanges);
|
|
1829
2063
|
const name = loadedView ? /* @__PURE__ */ React10.createElement(
|
|
1830
2064
|
"button",
|
|
1831
2065
|
{
|
|
@@ -1842,11 +2076,16 @@ function Toolbar(props) {
|
|
|
1842
2076
|
) : null;
|
|
1843
2077
|
const end = buttons("end");
|
|
1844
2078
|
const at = hidden.has("views") ? end.length : end.length - 1;
|
|
1845
|
-
const wrap =
|
|
1846
|
-
|
|
2079
|
+
const wrap = hidden.size > 0 && hidden.size >= present.length;
|
|
2080
|
+
const moreGroups = (close) => MORE_GROUPS.map((group) => group.filter((id) => hidden.has(id))).flatMap(
|
|
2081
|
+
(ids) => ids.length ? [
|
|
2082
|
+
/* @__PURE__ */ React10.createElement(Group, { key: ids[0], menu: true, label: ids[0] === "startOver" ? labels.startOver : void 0 }, ids.map((id) => actions[id].entry(close)))
|
|
2083
|
+
] : []
|
|
2084
|
+
);
|
|
2085
|
+
return /* @__PURE__ */ React10.createElement("div", { className: `pk-toolbar${wrap ? " pk-wrap" : ""}`, role: "toolbar", "aria-label": labels.toolbar, ref: bar, "data-overflow": hidden.size }, size === "narrow" ? /* @__PURE__ */ React10.createElement("button", { type: "button", className: "pk-btn", onClick: onShowFields, "data-testid": "show-fields", "data-pk-opener": "fields" }, /* @__PURE__ */ React10.createElement(Icon, { name: "panel" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-btn-text" }, labels.showFields)) : null, /* @__PURE__ */ React10.createElement("div", { className: "pk-segmented", role: "group", "aria-label": labels.view }, /* @__PURE__ */ React10.createElement("button", { type: "button", "aria-pressed": view.display === "table", onClick: () => onDisplay("table"), "data-testid": "show-table" }, /* @__PURE__ */ React10.createElement(Icon, { name: "table" }), /* @__PURE__ */ React10.createElement("span", null, labels.table)), /* @__PURE__ */ React10.createElement("button", { type: "button", "aria-pressed": view.display === "chart", onClick: () => onDisplay("chart"), "data-testid": "show-chart" }, /* @__PURE__ */ React10.createElement(Icon, { name: (
|
|
1847
2086
|
/** @type {any} */
|
|
1848
2087
|
drawnIcon
|
|
1849
|
-
) }), /* @__PURE__ */ React10.createElement("span", null, labels.chart))), buttons("chart"), /* @__PURE__ */ React10.createElement("span", { className: "pk-sep", "aria-hidden": "true" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-toolbar-pair" }, /* @__PURE__ */ React10.createElement(TextButton, { icon: "undo", label: labels.undo, onClick: onUndo, disabled: !canUndo, testId: "undo", shortcut: `${mod}Z` }), /* @__PURE__ */ React10.createElement(TextButton, { icon: "redo", label: labels.redo, onClick: onRedo, disabled: !canRedo, testId: "redo", shortcut: `${mod}\u21E7Z` })), buttons("history"), /* @__PURE__ */ React10.createElement("span", { className: "pk-grow" }), end.slice(0, at), wrap ? null : name, end.slice(at), /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.exportLabel, icon: "download", text: labels.exportLabel, role: "dialog", align: "end", testId: "export" }, (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ExportPanel", loadingText: labels.loadingMenu, props: { labels, onExport, chartReady, display: view.display, empty, prepare: props.prepareExport, close } })),
|
|
2088
|
+
) }), /* @__PURE__ */ React10.createElement("span", null, labels.chart))), buttons("chart"), /* @__PURE__ */ React10.createElement("span", { className: "pk-sep", "aria-hidden": "true" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-toolbar-pair" }, /* @__PURE__ */ React10.createElement(TextButton, { icon: "undo", label: labels.undo, onClick: onUndo, disabled: !canUndo, testId: "undo", shortcut: `${mod}Z` }), /* @__PURE__ */ React10.createElement(TextButton, { icon: "redo", label: labels.redo, onClick: onRedo, disabled: !canRedo, testId: "redo", shortcut: `${mod}\u21E7Z` })), buttons("history"), /* @__PURE__ */ React10.createElement("span", { className: "pk-grow" }), end.slice(0, at), wrap ? null : name, end.slice(at), /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.exportLabel, icon: "download", text: labels.exportLabel, role: "dialog", align: "end", testId: "export" }, (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ExportPanel", loadingText: labels.loadingMenu, props: { labels, onExport, chartReady, display: view.display, empty, prepare: props.prepareExport, close } })), hidden.size > 0 ? /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.more, icon: "more", text: labels.more, align: "end", testId: "more", buttonRef: more, arrowOpens: true, mark: hidden.has("views") && loadedView?.changed ? changedMark("more-changed") : hidden.has("data") ? loadedMark("more-loaded") : null }, moreGroups) : null, wrap ? name : null, panel ? /* @__PURE__ */ React10.createElement(Popover, { open: true, anchor: more, onClose: closePanel, label: panel === "chartType" ? chartTypeText : panel === "views" ? labels.views : panel === "data" ? labels.data : labels.options, role: "dialog", align: "end", className: panel === "chartType" ? "pk-chart-menu" : void 0 }, panels[panel](closePanel)) : null);
|
|
1850
2089
|
}
|
|
1851
2090
|
|
|
1852
2091
|
// src/use-export.js
|
|
@@ -1960,9 +2199,9 @@ function reset(state, note) {
|
|
|
1960
2199
|
function schemaKeyOf(encoded) {
|
|
1961
2200
|
return JSON.stringify(encoded.schema.fields.map((f) => [f.name, f.type]));
|
|
1962
2201
|
}
|
|
1963
|
-
function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outsideNote, orderOf }) {
|
|
2202
|
+
function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outsideNote, orderOf, dataKey = 0, initial: initialState = null }) {
|
|
1964
2203
|
const controlled = view !== void 0;
|
|
1965
|
-
const schema = useMemo6(() => schemaKeyOf(encoded)
|
|
2204
|
+
const schema = useMemo6(() => `${dataKey}|${schemaKeyOf(encoded)}`, [encoded, dataKey]);
|
|
1966
2205
|
const json = useCallback6(
|
|
1967
2206
|
(v) => {
|
|
1968
2207
|
const normalized = normalize(v ?? emptyView(), encoded, { limits }).view;
|
|
@@ -1973,8 +2212,15 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
|
|
|
1973
2212
|
);
|
|
1974
2213
|
const [initial] = useState9(() => (controlled ? view : defaultView) ?? null);
|
|
1975
2214
|
const start = useMemo6(() => json(initial), [json, initial]);
|
|
1976
|
-
const [state, setState] = useState9(() => createState(schema, start));
|
|
2215
|
+
const [state, setState] = useState9(() => initialState ?? createState(schema, start));
|
|
1977
2216
|
const viewKey = controlled ? JSON.stringify(view) : null;
|
|
2217
|
+
const [echo, setEcho] = useState9(() => ({ over: viewKey, pending: initialState ? [initialState.present] : [] }));
|
|
2218
|
+
let pending3 = echo.pending;
|
|
2219
|
+
if (viewKey !== echo.over) {
|
|
2220
|
+
const index = viewKey === null ? -1 : pending3.indexOf(json(JSON.parse(viewKey)));
|
|
2221
|
+
pending3 = index < 0 ? [] : pending3.slice(index + 1);
|
|
2222
|
+
setEcho({ over: viewKey, pending: pending3 });
|
|
2223
|
+
}
|
|
1978
2224
|
const shown = useMemo6(() => {
|
|
1979
2225
|
if (viewKey !== null) {
|
|
1980
2226
|
return json(JSON.parse(viewKey));
|
|
@@ -1985,13 +2231,17 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
|
|
|
1985
2231
|
/** @type {import("pivotkit-core").View} */
|
|
1986
2232
|
JSON.parse(shown)
|
|
1987
2233
|
), [shown]);
|
|
1988
|
-
const
|
|
2234
|
+
const waiting = viewKey !== null && pending3.length > 0 && state.schema === schema;
|
|
2235
|
+
const live = useMemo6(() => waiting ? state : settle(state, { schema, start, shown, outside: outsideNote }), [waiting, state, schema, start, shown, outsideNote]);
|
|
1989
2236
|
const apply = useCallback6(
|
|
1990
2237
|
(next) => {
|
|
1991
2238
|
setState(next);
|
|
2239
|
+
if (viewKey !== null) {
|
|
2240
|
+
setEcho((previous) => ({ over: viewKey, pending: [...previous.over === viewKey ? previous.pending : pending3, next.present] }));
|
|
2241
|
+
}
|
|
1992
2242
|
onViewChange?.(JSON.parse(next.present));
|
|
1993
2243
|
},
|
|
1994
|
-
[onViewChange]
|
|
2244
|
+
[onViewChange, viewKey, pending3]
|
|
1995
2245
|
);
|
|
1996
2246
|
const commit = useCallback6(
|
|
1997
2247
|
(next, note, tag) => {
|
|
@@ -2034,16 +2284,41 @@ function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outs
|
|
|
2034
2284
|
[live, apply]
|
|
2035
2285
|
);
|
|
2036
2286
|
const restore = useCallback6((next, tag = null) => apply(createState(schema, start, json(next), tag)), [schema, start, json, apply]);
|
|
2287
|
+
const snapshot = useCallback6(() => live, [live]);
|
|
2037
2288
|
const earlier = useCallback6(() => live.past.map((p) => JSON.parse(p.view)), [live.past]);
|
|
2038
2289
|
const canUndo = live.past.length > 0;
|
|
2039
2290
|
const canRedo = live.future.length > 0;
|
|
2040
2291
|
const canReset = live.present !== live.start;
|
|
2292
|
+
const emptyKey = useMemo6(() => json(null), [json]);
|
|
2293
|
+
const startEmpty = live.start === emptyKey;
|
|
2041
2294
|
return useMemo6(
|
|
2042
|
-
() => ({ view: current, viewKey: shown, tag: live.tag, setTag, commit, undo: undo2, redo: redo2, reset: reset2, restore, keyOf: json, earlier, canUndo, canRedo, canReset }),
|
|
2043
|
-
[current, shown, live.tag, setTag, commit, undo2, redo2, reset2, restore, json, earlier, canUndo, canRedo, canReset]
|
|
2295
|
+
() => ({ view: current, viewKey: shown, tag: live.tag, setTag, commit, undo: undo2, redo: redo2, reset: reset2, restore, keyOf: json, earlier, canUndo, canRedo, canReset, startEmpty, snapshot, replace: apply }),
|
|
2296
|
+
[current, shown, live.tag, setTag, commit, undo2, redo2, reset2, restore, json, earlier, canUndo, canRedo, canReset, startEmpty, snapshot, apply]
|
|
2044
2297
|
);
|
|
2045
2298
|
}
|
|
2046
2299
|
|
|
2300
|
+
// src/data-keep.js
|
|
2301
|
+
var KEPT_REPORTS = 4;
|
|
2302
|
+
var kept = /* @__PURE__ */ new Map();
|
|
2303
|
+
var hostIdentity = ({ dataKey, sourceId, schemaKey }) => JSON.stringify([sourceId ?? null, dataKey !== void 0 ? ["key", String(dataKey)] : ["columns", schemaKey]]);
|
|
2304
|
+
function keepData(key, entry) {
|
|
2305
|
+
kept.delete(key);
|
|
2306
|
+
kept.set(key, entry);
|
|
2307
|
+
while (kept.size > KEPT_REPORTS) {
|
|
2308
|
+
kept.delete(
|
|
2309
|
+
/** @type {string} */
|
|
2310
|
+
kept.keys().next().value
|
|
2311
|
+
);
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
function forgetData(key) {
|
|
2315
|
+
kept.delete(key);
|
|
2316
|
+
}
|
|
2317
|
+
function keptData(key, host) {
|
|
2318
|
+
const entry = kept.get(key);
|
|
2319
|
+
return entry && entry.host === host ? entry : null;
|
|
2320
|
+
}
|
|
2321
|
+
|
|
2047
2322
|
// src/use-big-result.js
|
|
2048
2323
|
import { useCallback as useCallback7, useEffect as useEffect9, useRef as useRef9, useState as useState10, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
2049
2324
|
function fullScreenSupported() {
|
|
@@ -2133,7 +2408,7 @@ function measureFit(el, m, fit) {
|
|
|
2133
2408
|
import React11, { useCallback as useCallback8, useEffect as useEffect10, useMemo as useMemo7, useRef as useRef10, useState as useState11 } from "react";
|
|
2134
2409
|
import { fieldItems, fieldLabel as fieldLabel4 } from "pivotkit-core";
|
|
2135
2410
|
function fieldState(view, field, encoded, locale, labels, sourceType) {
|
|
2136
|
-
const items = filtersOf(view, field, ["
|
|
2411
|
+
const items = filtersOf(view, field, ["in"]).filter((f) => !isEmptyPick(f));
|
|
2137
2412
|
const compared = filtersOf(view, field, ["compare"]);
|
|
2138
2413
|
const info = items.length || compared.length ? fieldItems(encoded, field, { view, locale }) : null;
|
|
2139
2414
|
let summary = null;
|
|
@@ -2144,7 +2419,7 @@ function fieldState(view, field, encoded, locale, labels, sourceType) {
|
|
|
2144
2419
|
const labelOf = (v) => info?.items.find((i) => i.value === v)?.label;
|
|
2145
2420
|
const date = sourceType === "date";
|
|
2146
2421
|
const span = date ? dateSpan(encoded, sourceOf(view, field)) : null;
|
|
2147
|
-
const rules = filtersOf(view, field, ["relative", "compare", "
|
|
2422
|
+
const rules = filtersOf(view, field, ["relative", "compare", "text"]).map((f) => itemRuleText(f, labels, locale, { timeZone: encoded.timeZone, date, labelOf, span, weekStart: view.formatting?.weekStart }));
|
|
2148
2423
|
const top = filtersOf(view, field, ["top"])[0] ?? null;
|
|
2149
2424
|
const condition = filtersOf(view, field, ["value"])[0] ?? null;
|
|
2150
2425
|
return { summary, rules, top, condition, sort: sortOf(view, field) };
|
|
@@ -2460,10 +2735,13 @@ function optionsKey(options) {
|
|
|
2460
2735
|
}
|
|
2461
2736
|
var here = () => typeof location !== "undefined" ? { href: location.href, hash: location.hash } : void 0;
|
|
2462
2737
|
var DEFER_ROWS = 1e4;
|
|
2738
|
+
var dataOf = (d) => Array.isArray(d) || Array.isArray(d?.columns) ? d : [];
|
|
2739
|
+
var rowsOf = (d) => Array.isArray(d) ? d.length : d?.data?.[0]?.length ?? 0;
|
|
2740
|
+
var NO_STEPS = Object.freeze({ past: [], future: [] });
|
|
2463
2741
|
var unusedNotes = (issues, raw) => issues.filter((i) => (i.code ?? (i.message === "unknown key" ? "unknownKey" : "")) !== "unknownKey" || !["name", "description"].includes(i.path)).map((issue) => ({ issue, raw }));
|
|
2464
2742
|
function PivotReport(props) {
|
|
2465
2743
|
const { loading: loading2 = false, data, encoded } = props;
|
|
2466
|
-
const [deferred, setDeferred] = useState12(() => !encoded &&
|
|
2744
|
+
const [deferred, setDeferred] = useState12(() => !encoded && rowsOf(data) > DEFER_ROWS);
|
|
2467
2745
|
const [started, setStarted] = useState12(false);
|
|
2468
2746
|
useEffect11(() => {
|
|
2469
2747
|
if (!deferred) {
|
|
@@ -2497,15 +2775,16 @@ function WaitingReport({ locale = "en-US", labels: customLabels, theme = "auto",
|
|
|
2497
2775
|
const themeName = useResolvedTheme(theme, root);
|
|
2498
2776
|
return /* @__PURE__ */ React12.createElement("div", { ref: root, className: `pk-root${className ? ` ${className}` : ""}`, "data-pk-theme": themeName, lang: labels.lang, role: "region", "aria-label": label || labels.report, style: { height } }, /* @__PURE__ */ React12.createElement(Skeleton, { full: true, text: labels.loadingReport }));
|
|
2499
2777
|
}
|
|
2500
|
-
function
|
|
2501
|
-
|
|
2502
|
-
return
|
|
2778
|
+
function keyOfHostView(view) {
|
|
2779
|
+
try {
|
|
2780
|
+
return JSON.stringify(view ?? null) ?? "null";
|
|
2781
|
+
} catch {
|
|
2782
|
+
return "null";
|
|
2503
2783
|
}
|
|
2504
|
-
const key = Object.keys(fieldDefaults).find((k) => k.toLowerCase() === String(field).toLowerCase());
|
|
2505
|
-
return key === void 0 ? void 0 : fieldDefaults[key];
|
|
2506
2784
|
}
|
|
2507
|
-
|
|
2508
|
-
|
|
2785
|
+
var staysTheSame = () => () => void 0;
|
|
2786
|
+
function EmptyState({ labels, templates, onTemplate, onLoad, noData }) {
|
|
2787
|
+
return /* @__PURE__ */ React12.createElement("div", { className: "pk-empty", "data-testid": "empty-state" }, /* @__PURE__ */ React12.createElement("div", { className: "pk-empty-art", "aria-hidden": "true" }, /* @__PURE__ */ React12.createElement("span", { className: "pk-empty-chip pk-c1" }), /* @__PURE__ */ React12.createElement("span", { className: "pk-empty-chip pk-c2" }), /* @__PURE__ */ React12.createElement("span", { className: "pk-empty-chip pk-c3" })), /* @__PURE__ */ React12.createElement("h2", null, noData ? labels.emptyNoData : labels.emptyTitle), noData ? null : /* @__PURE__ */ React12.createElement("ol", { className: "pk-steps" }, labels.emptySteps.map((s, i) => /* @__PURE__ */ React12.createElement("li", { key: i }, /* @__PURE__ */ React12.createElement("span", { className: "pk-step-n", "aria-hidden": "true" }, i + 1), /* @__PURE__ */ React12.createElement("span", null, s)))), onLoad ? /* @__PURE__ */ React12.createElement("div", { className: "pk-drop-zone", "data-testid": "empty-drop" }, /* @__PURE__ */ React12.createElement("p", null, noData ? labels.emptyDrop : labels.emptyLoad), /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn", onClick: onLoad, "data-testid": "empty-load" }, /* @__PURE__ */ React12.createElement(Icon, { name: "upload" }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, labels.loadData))) : null, templates.length ? /* @__PURE__ */ React12.createElement("div", { className: "pk-empty-actions" }, templates.slice(0, 3).map((t, i) => /* @__PURE__ */ React12.createElement("button", { key: `${i}:${t.name}`, type: "button", className: "pk-btn", onClick: () => onTemplate(t) }, /* @__PURE__ */ React12.createElement(Icon, { name: "sparkle" }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, fill(labels.tryView, { name: t.name }))))) : null);
|
|
2509
2788
|
}
|
|
2510
2789
|
function Report(props) {
|
|
2511
2790
|
const {
|
|
@@ -2530,6 +2809,7 @@ function Report(props) {
|
|
|
2530
2809
|
theme = "auto",
|
|
2531
2810
|
height = 640,
|
|
2532
2811
|
limits: limitsProp,
|
|
2812
|
+
importLimits: importLimitsProp,
|
|
2533
2813
|
className,
|
|
2534
2814
|
fileName = "pivot",
|
|
2535
2815
|
fieldDefaults,
|
|
@@ -2551,18 +2831,36 @@ function Report(props) {
|
|
|
2551
2831
|
schemaUrl,
|
|
2552
2832
|
grow: growProp,
|
|
2553
2833
|
fieldList,
|
|
2554
|
-
loading: loading2 = false
|
|
2834
|
+
loading: loading2 = false,
|
|
2835
|
+
allowImport = false,
|
|
2836
|
+
plugins: pluginsProp,
|
|
2837
|
+
onDataLoad,
|
|
2838
|
+
importWorker
|
|
2555
2839
|
} = props;
|
|
2556
2840
|
const grow = growProp === "on" || growProp !== "off" && props.height === void 0;
|
|
2557
|
-
const
|
|
2558
|
-
const
|
|
2841
|
+
const hostSourceId = typeof sourceProp?.id === "string" && sourceProp.id ? sourceProp.id : void 0;
|
|
2842
|
+
const hostSourceName = typeof sourceProp?.name === "string" && sourceProp.name ? sourceProp.name : void 0;
|
|
2843
|
+
const [job, setJob] = useState12(
|
|
2844
|
+
/** @type {{ file: File, n: number } | null} */
|
|
2845
|
+
null
|
|
2846
|
+
);
|
|
2847
|
+
const [dragging, setDragging] = useState12(false);
|
|
2848
|
+
const dragDepth = useRef11(0);
|
|
2849
|
+
const [importMod, setImportMod] = useState12(importNow);
|
|
2850
|
+
const fileInput = useRef11(
|
|
2851
|
+
/** @type {HTMLInputElement | null} */
|
|
2852
|
+
null
|
|
2853
|
+
);
|
|
2854
|
+
const plugins = Array.isArray(pluginsProp) ? pluginsProp : [];
|
|
2559
2855
|
const labelsKey = JSON.stringify(customLabels ?? null);
|
|
2560
2856
|
const defaultsKey = JSON.stringify(fieldDefaults ?? null);
|
|
2561
2857
|
const info = useMemo8(() => fieldInfoOf(JSON.parse(defaultsKey)), [defaultsKey]);
|
|
2562
2858
|
const baseLabels = useMemo8(() => resolveLabels(locale, JSON.parse(labelsKey)), [locale, labelsKey]);
|
|
2563
2859
|
const typesKey = JSON.stringify(typesOf(fieldDefaults));
|
|
2564
2860
|
const limitsKey = JSON.stringify(limitsProp ?? null);
|
|
2565
|
-
const
|
|
2861
|
+
const hostLimits = useMemo8(() => JSON.parse(limitsKey) ?? void 0, [limitsKey]);
|
|
2862
|
+
const importLimitsKey = JSON.stringify(importLimitsProp ?? null);
|
|
2863
|
+
const fileLimits = useMemo8(() => importLimitsOf(hostLimits, JSON.parse(importLimitsKey)), [hostLimits, importLimitsKey]);
|
|
2566
2864
|
const root = useRef11(
|
|
2567
2865
|
/** @type {HTMLDivElement | null} */
|
|
2568
2866
|
null
|
|
@@ -2581,6 +2879,11 @@ function Report(props) {
|
|
|
2581
2879
|
);
|
|
2582
2880
|
const layoutFolded = folded ?? short;
|
|
2583
2881
|
const zonesId = useId4();
|
|
2882
|
+
const ownPrefix = useRef11(
|
|
2883
|
+
/** @type {string | null} */
|
|
2884
|
+
null
|
|
2885
|
+
);
|
|
2886
|
+
const formPrefix = useSyncExternalStore3(staysTheSame, () => ownPrefix.current ??= `pk-${Math.random().toString(36).slice(2, 8)}`, () => "pk");
|
|
2584
2887
|
const [drawer, setDrawer] = useState12(false);
|
|
2585
2888
|
const [filterTarget, setFilterTarget] = useState12(
|
|
2586
2889
|
/** @type {{ field: string, anchor: HTMLElement, base?: object } | null} */
|
|
@@ -2606,8 +2909,8 @@ function Report(props) {
|
|
|
2606
2909
|
useEffect11(() => onMenuTexts(() => setTexts((n) => n + 1)), []);
|
|
2607
2910
|
const [viewsRequest, setViewsRequest] = useState12(0);
|
|
2608
2911
|
const [leftOut, setLeftOut] = useState12(
|
|
2609
|
-
/** @type {import("./unused.jsx").UnusedNote[]} */
|
|
2610
|
-
[]
|
|
2912
|
+
/** @type {{ notes: import("./unused.jsx").UnusedNote[], loaded: any, after: string | null }} */
|
|
2913
|
+
{ notes: [], loaded: null, after: null }
|
|
2611
2914
|
);
|
|
2612
2915
|
const [issuesDismissed, setIssuesDismissed] = useState12(
|
|
2613
2916
|
/** @type {string | null} */
|
|
@@ -2615,10 +2918,6 @@ function Report(props) {
|
|
|
2615
2918
|
);
|
|
2616
2919
|
const [loads, setLoads] = useState12(0);
|
|
2617
2920
|
const [unusedSaid, setUnusedSaid] = useState12(false);
|
|
2618
|
-
const [savedKeys, setSavedKeys] = useState12(
|
|
2619
|
-
/** @type {Record<string, string>} */
|
|
2620
|
-
{}
|
|
2621
|
-
);
|
|
2622
2921
|
const [rowLabel, setRowLabel] = useState12(
|
|
2623
2922
|
/** @type {string | null} */
|
|
2624
2923
|
null
|
|
@@ -2637,17 +2936,31 @@ function Report(props) {
|
|
|
2637
2936
|
const source = useMemo8(() => {
|
|
2638
2937
|
try {
|
|
2639
2938
|
const types2 = JSON.parse(typesKey);
|
|
2640
|
-
const enc = encodedProp ?? measured("encode", () => encode(
|
|
2641
|
-
/** @type {any[]} */
|
|
2642
|
-
Array.isArray(data) ? data : [],
|
|
2643
|
-
{ timeZone: timeZone ?? "UTC", limits, ...types2 ? { types: types2 } : {} }
|
|
2644
|
-
));
|
|
2939
|
+
const enc = encodedProp ?? measured("encode", () => encode(dataOf(data), { timeZone: timeZone ?? "UTC", limits: hostLimits, ...types2 ? { types: types2 } : {} }));
|
|
2645
2940
|
return { encoded: enc, error: null };
|
|
2646
2941
|
} catch (error2) {
|
|
2647
2942
|
return { encoded: encode([]), error: error2 };
|
|
2648
2943
|
}
|
|
2649
|
-
}, [encodedProp, dataIdentity, timeZone,
|
|
2650
|
-
const
|
|
2944
|
+
}, [encodedProp, dataIdentity, timeZone, hostLimits, typesKey]);
|
|
2945
|
+
const keepKey = allowImport && typeof storageKey === "string" && storageKey ? storageKey : null;
|
|
2946
|
+
const hostData = hostIdentity({ dataKey, sourceId: hostSourceId, schemaKey: schemaKeyOf(source.encoded) });
|
|
2947
|
+
const [kept2] = useState12(() => keepKey ? keptData(keepKey, hostData) : null);
|
|
2948
|
+
const [imported, setImported] = useState12(
|
|
2949
|
+
/** @type {import("./import-steps.js").ShownData | null} */
|
|
2950
|
+
kept2?.imported ?? null
|
|
2951
|
+
);
|
|
2952
|
+
const [dataSteps, setDataSteps] = useState12(
|
|
2953
|
+
/** @type {import("./data-history.js").DataSteps} */
|
|
2954
|
+
kept2?.steps ?? NO_STEPS
|
|
2955
|
+
);
|
|
2956
|
+
const [savedKeys, setSavedKeys] = useState12(
|
|
2957
|
+
/** @type {Record<string, string>} */
|
|
2958
|
+
kept2?.savedKeys ?? {}
|
|
2959
|
+
);
|
|
2960
|
+
const sourceId = imported ? imported.source.id : hostSourceId;
|
|
2961
|
+
const sourceName = imported ? imported.source.name : hostSourceName;
|
|
2962
|
+
const encoded = imported ? imported.encoded : source.encoded;
|
|
2963
|
+
const limits = imported ? fileLimits : hostLimits;
|
|
2651
2964
|
const fieldNamesKey = encoded.schema.fields.map((f) => f.name).join("\0");
|
|
2652
2965
|
const labels = useMemo8(() => {
|
|
2653
2966
|
const fields2 = displayNames(info, fieldNamesKey ? fieldNamesKey.split("\0") : []);
|
|
@@ -2666,8 +2979,23 @@ function Report(props) {
|
|
|
2666
2979
|
}
|
|
2667
2980
|
return (field) => orders.find(([name]) => name.toLowerCase() === field.toLowerCase())?.[1];
|
|
2668
2981
|
}, [ordersKey]);
|
|
2669
|
-
const history = useViewHistory({ encoded, view: viewProp, defaultView, onViewChange, limits, outsideNote: labels.steps.outside, orderOf });
|
|
2982
|
+
const history = useViewHistory({ encoded, view: viewProp, defaultView, onViewChange, limits, outsideNote: labels.steps.outside, orderOf, dataKey: imported ? imported.key : 0, initial: kept2?.history });
|
|
2670
2983
|
const view = history.view;
|
|
2984
|
+
const [startView] = useState12(() => defaultView);
|
|
2985
|
+
const hostKey = keyOfHostView(viewProp !== void 0 ? viewProp : startView);
|
|
2986
|
+
const keyOf = history.keyOf;
|
|
2987
|
+
const hostNotes = useMemo8(() => {
|
|
2988
|
+
if (hostKey === "null" || loading2 || imported || encoded.schema.fields.length === 0) {
|
|
2989
|
+
return null;
|
|
2990
|
+
}
|
|
2991
|
+
const raw = JSON.parse(hostKey);
|
|
2992
|
+
if (raw === null) {
|
|
2993
|
+
return null;
|
|
2994
|
+
}
|
|
2995
|
+
const notes2 = unusedNotes(normalize2(raw, encoded, { limits }).issues, raw);
|
|
2996
|
+
return notes2.length ? { notes: notes2, loaded: JSON.parse(keyOf(raw)) } : null;
|
|
2997
|
+
}, [hostKey, loading2, imported, encoded, limits, keyOf]);
|
|
2998
|
+
const leaveOut = useCallback9((notes2, given2) => setLeftOut({ notes: notes2, loaded: given2 ? JSON.parse(keyOf(given2)) : null, after: hostKey }), [keyOf, hostKey]);
|
|
2671
2999
|
const loadedView = tagFor(history.tag, sourceId);
|
|
2672
3000
|
const viewName = loadedView?.name ?? null;
|
|
2673
3001
|
const unsaved = Boolean(loadedView) && savedKeys[savedKeyOf(loadedView)] !== history.viewKey;
|
|
@@ -2686,27 +3014,32 @@ function Report(props) {
|
|
|
2686
3014
|
},
|
|
2687
3015
|
[labels]
|
|
2688
3016
|
);
|
|
2689
|
-
const
|
|
2690
|
-
|
|
3017
|
+
const apiNow = useRef11(
|
|
3018
|
+
/** @type {any} */
|
|
3019
|
+
null
|
|
3020
|
+
);
|
|
3021
|
+
const undo2 = () => {
|
|
3022
|
+
const note = history.canUndo || !importMod ? history.undo() : importMod.moveData(apiNow.current, true);
|
|
2691
3023
|
if (note !== null) {
|
|
2692
3024
|
announce(fill(labels.toastUndone, { step: note }));
|
|
2693
3025
|
}
|
|
2694
|
-
}
|
|
2695
|
-
const redo2 =
|
|
2696
|
-
const note = history.redo();
|
|
3026
|
+
};
|
|
3027
|
+
const redo2 = () => {
|
|
3028
|
+
const note = history.canRedo || !importMod ? history.redo() : importMod.moveData(apiNow.current, false);
|
|
2697
3029
|
if (note !== null) {
|
|
2698
3030
|
announce(fill(labels.toastRedone, { step: note }));
|
|
2699
3031
|
}
|
|
2700
|
-
}
|
|
3032
|
+
};
|
|
3033
|
+
const newStep = useCallback9(() => setDataSteps((s) => s.future.length ? { past: s.past, future: [] } : s), []);
|
|
2701
3034
|
const undoLater = useRef11(undo2);
|
|
2702
3035
|
useEffect11(() => {
|
|
2703
3036
|
undoLater.current = undo2;
|
|
2704
3037
|
});
|
|
2705
3038
|
const reset2 = useCallback9(() => {
|
|
2706
3039
|
history.reset(labels.steps.reset);
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
3040
|
+
newStep();
|
|
3041
|
+
announce(labels.toastReset, { action: { label: labels.undo, run: () => undoLater.current() } });
|
|
3042
|
+
}, [history, labels, announce, newStep]);
|
|
2710
3043
|
const [opening, setOpening] = useState12(false);
|
|
2711
3044
|
const appliedLink = useRef11(
|
|
2712
3045
|
/** @type {string | null} */
|
|
@@ -2778,8 +3111,11 @@ function Report(props) {
|
|
|
2778
3111
|
);
|
|
2779
3112
|
}, []);
|
|
2780
3113
|
useIsoLayoutEffect(() => {
|
|
3114
|
+
if (kept2) {
|
|
3115
|
+
return;
|
|
3116
|
+
}
|
|
2781
3117
|
const page = here();
|
|
2782
|
-
const link = shareLink ? readLinkParam(page?.hash ?? "",
|
|
3118
|
+
const link = shareLink ? readLinkParam(page?.hash ?? "", storageKey) : null;
|
|
2783
3119
|
if (link) {
|
|
2784
3120
|
openLink(link);
|
|
2785
3121
|
} else if (persistView === "session") {
|
|
@@ -2800,14 +3136,14 @@ function Report(props) {
|
|
|
2800
3136
|
return void 0;
|
|
2801
3137
|
}
|
|
2802
3138
|
const onHash = () => {
|
|
2803
|
-
const link = readLinkParam(here()?.hash ?? "",
|
|
3139
|
+
const link = readLinkParam(here()?.hash ?? "", storageKey);
|
|
2804
3140
|
if (link && link !== appliedLink.current) {
|
|
2805
3141
|
openLink(link, true);
|
|
2806
3142
|
}
|
|
2807
3143
|
};
|
|
2808
3144
|
window.addEventListener("hashchange", onHash);
|
|
2809
3145
|
return () => window.removeEventListener("hashchange", onHash);
|
|
2810
|
-
}, [shareLink,
|
|
3146
|
+
}, [shareLink, storageKey, openLink]);
|
|
2811
3147
|
useEffect11(() => {
|
|
2812
3148
|
if (persistView === "session") {
|
|
2813
3149
|
writeStoredView(storageKey, sessionStore(), JSON.parse(history.viewKey));
|
|
@@ -2825,18 +3161,19 @@ function Report(props) {
|
|
|
2825
3161
|
if (changed) {
|
|
2826
3162
|
changesRef.current += 1;
|
|
2827
3163
|
setChanges(changesRef.current);
|
|
3164
|
+
newStep();
|
|
2828
3165
|
}
|
|
2829
3166
|
if (!changed || !note.removed) {
|
|
2830
3167
|
return;
|
|
2831
3168
|
}
|
|
2832
3169
|
announce(fill(labels.toastRemoved, { field: note.field ?? "" }).trim(), { action: { label: labels.undo, run: () => undoLater.current() } });
|
|
2833
3170
|
},
|
|
2834
|
-
[history, stepText, labels, announce, limits, locale]
|
|
3171
|
+
[history, stepText, labels, announce, limits, locale, newStep]
|
|
2835
3172
|
);
|
|
2836
3173
|
const remember = useCallback9((tag, key) => setSavedKeys((all) => ({ ...all, [savedKeyOf(tag)]: key })), []);
|
|
2837
3174
|
const applyLoaded = useCallback9(
|
|
2838
3175
|
/** @param {import("./share.js").LoadedView} loaded @param {{ link?: boolean, restored?: boolean }} [how] */
|
|
2839
|
-
(loaded3, { link = false, restored = false } = {}) => {
|
|
3176
|
+
(loaded3, { link = false, restored: restored2 = false } = {}) => {
|
|
2840
3177
|
if (!loaded3.view) {
|
|
2841
3178
|
return;
|
|
2842
3179
|
}
|
|
@@ -2844,20 +3181,20 @@ function Report(props) {
|
|
|
2844
3181
|
if (tag) {
|
|
2845
3182
|
remember(tag, latest.current.history.keyOf(loaded3.view));
|
|
2846
3183
|
}
|
|
2847
|
-
if (
|
|
3184
|
+
if (restored2) {
|
|
2848
3185
|
latest.current.history.setTag(tag);
|
|
2849
3186
|
} else {
|
|
2850
3187
|
commit(loaded3.view, { step: "viewLoaded" }, tag);
|
|
2851
3188
|
}
|
|
2852
3189
|
const notes2 = unusedNotes(loaded3.issues, loaded3.file?.view);
|
|
2853
|
-
|
|
3190
|
+
leaveOut(notes2, loaded3.view);
|
|
2854
3191
|
setIssuesDismissed(null);
|
|
2855
3192
|
setLoads((x) => x + 1);
|
|
2856
3193
|
setUnusedSaid(notes2.length > 0);
|
|
2857
3194
|
const text = link ? notes2.length ? labels.toastLinkOpenedPartly : labels.toastLinkOpened : notes2.length ? labels.toastViewLoadedPartly : labels.toastViewLoaded;
|
|
2858
|
-
announce(text,
|
|
3195
|
+
announce(text, restored2 ? void 0 : { action: { label: labels.undo, run: () => undoLater.current() } });
|
|
2859
3196
|
},
|
|
2860
|
-
[commit, labels, announce, remember]
|
|
3197
|
+
[commit, labels, announce, remember, leaveOut]
|
|
2861
3198
|
);
|
|
2862
3199
|
useEffect11(() => {
|
|
2863
3200
|
latest.current = { history, encoded, limits, labels, announce, commit, sourceId, loaded: applyLoaded, sources, onSourceSwitch };
|
|
@@ -2870,6 +3207,15 @@ function Report(props) {
|
|
|
2870
3207
|
}
|
|
2871
3208
|
}, [encoded, view, locale, limits]);
|
|
2872
3209
|
const result = computed.result;
|
|
3210
|
+
const unusedLocale = useMemo8(() => {
|
|
3211
|
+
const requested = view.formatting?.locale || locale;
|
|
3212
|
+
try {
|
|
3213
|
+
new Intl.NumberFormat(requested);
|
|
3214
|
+
return requested;
|
|
3215
|
+
} catch {
|
|
3216
|
+
return "en-US";
|
|
3217
|
+
}
|
|
3218
|
+
}, [view.formatting?.locale, locale]);
|
|
2873
3219
|
const plan = useMemo8(() => chartPlan(view, encoded), [view, encoded]);
|
|
2874
3220
|
const chartComputed = useMemo8(() => {
|
|
2875
3221
|
if (!plan.swap || view.display !== "chart" || !result) {
|
|
@@ -2996,15 +3342,15 @@ function Report(props) {
|
|
|
2996
3342
|
panelRef.current.inert = size === "narrow" && !drawerOpen;
|
|
2997
3343
|
}
|
|
2998
3344
|
}, [size, drawerOpen]);
|
|
3345
|
+
const defaultsOf = useCallback9((field) => fieldDefaultsFor(fieldDefaults, field, encoded.column(field)), [fieldDefaults, encoded]);
|
|
2999
3346
|
const placeOptions = useCallback9(
|
|
3000
3347
|
(field, zone, index = void 0) => {
|
|
3001
3348
|
const column = encoded.column(field);
|
|
3002
3349
|
const unit = zone !== "values" && column && column.type === "date" && !column.derived ? suggestDateUnit(encoded, field) : null;
|
|
3003
|
-
return { index, type: typeOf(field), defaults:
|
|
3350
|
+
return { index, type: typeOf(field), defaults: defaultsOf(field), dateUnit: unit, groupName: unit ? groupingName(nameOf(column.name), unit, labels) : void 0 };
|
|
3004
3351
|
},
|
|
3005
|
-
[encoded, typeOf,
|
|
3352
|
+
[encoded, typeOf, defaultsOf, labels, nameOf]
|
|
3006
3353
|
);
|
|
3007
|
-
const defaultsOf = useCallback9((field) => defaultsFor(fieldDefaults, field), [fieldDefaults]);
|
|
3008
3354
|
const addTo = useCallback9(
|
|
3009
3355
|
(field, zone, index = void 0) => {
|
|
3010
3356
|
const options = placeOptions(field, zone, index);
|
|
@@ -3012,10 +3358,11 @@ function Report(props) {
|
|
|
3012
3358
|
},
|
|
3013
3359
|
[view, placeOptions, commit, nameOf]
|
|
3014
3360
|
);
|
|
3015
|
-
const
|
|
3361
|
+
const filterField = useCallback9(
|
|
3016
3362
|
(field, anchor) => {
|
|
3017
3363
|
const options = placeOptions(field, "filters");
|
|
3018
|
-
const
|
|
3364
|
+
const name = options.groupName ?? field;
|
|
3365
|
+
const draft = filterZoneFields(view).some((f) => same(f, name)) ? void 0 : addField(view, field, "filters", options);
|
|
3019
3366
|
const opener = size === "narrow" ? (
|
|
3020
3367
|
/** @type {HTMLElement | null} */
|
|
3021
3368
|
root.current?.querySelector("[data-pk-opener='fields']") ?? null
|
|
@@ -3025,7 +3372,7 @@ function Report(props) {
|
|
|
3025
3372
|
}
|
|
3026
3373
|
const target = opener ?? anchor;
|
|
3027
3374
|
if (target) {
|
|
3028
|
-
setFilterTarget({ field:
|
|
3375
|
+
setFilterTarget({ field: name, anchor: target, base: draft });
|
|
3029
3376
|
}
|
|
3030
3377
|
},
|
|
3031
3378
|
[placeOptions, view, size]
|
|
@@ -3047,10 +3394,10 @@ function Report(props) {
|
|
|
3047
3394
|
target.zone
|
|
3048
3395
|
);
|
|
3049
3396
|
const note = src.zone !== zone ? { step: "moved", field: src.label ?? src.field, zone } : { step: "reordered", zone };
|
|
3050
|
-
commit(moveField(view, src.zone, src.index, zone, target.index, { type: typeOf(src.field) }), note);
|
|
3397
|
+
commit(moveField(view, src.zone, src.index, zone, target.index, { type: typeOf(src.field), defaults: zone === "values" && src.field ? defaultsOf(src.field) : void 0 }), note);
|
|
3051
3398
|
}
|
|
3052
3399
|
},
|
|
3053
|
-
[view, typeOf, commit, addTo]
|
|
3400
|
+
[view, typeOf, commit, addTo, defaultsOf]
|
|
3054
3401
|
);
|
|
3055
3402
|
const openCell = useCallback9(
|
|
3056
3403
|
/** @param {any} cell */
|
|
@@ -3059,19 +3406,95 @@ function Report(props) {
|
|
|
3059
3406
|
return;
|
|
3060
3407
|
}
|
|
3061
3408
|
setHinted(true);
|
|
3062
|
-
const { count, rows, indices } = drillRows(result, { rowPath, colPath, data: encodedProp ? null : data, limit: drillDownLimit });
|
|
3409
|
+
const { count, rows, indices } = drillRows(result, { rowPath, colPath, data: encodedProp || imported || !Array.isArray(data) ? null : data, limit: drillDownLimit });
|
|
3063
3410
|
onCellClick?.({ row: rowPath, col: colPath, value, valueIndex, text, count, rows });
|
|
3064
3411
|
if (drillDown) {
|
|
3065
3412
|
const formatOf = (name) => {
|
|
3066
|
-
const d =
|
|
3413
|
+
const d = defaultsOf(name);
|
|
3067
3414
|
return d ? d.drillFormat ?? d.format : void 0;
|
|
3068
3415
|
};
|
|
3069
3416
|
setDrill({ result, rowPath, colPath, count, indices, formatOf, nameOf, infoOf });
|
|
3070
3417
|
}
|
|
3071
3418
|
},
|
|
3072
|
-
[result, encodedProp, data, drillDownLimit, onCellClick, drillDown,
|
|
3073
|
-
);
|
|
3074
|
-
const doExport = useExport({ fileName, result, locale, labels, limits, root, chartRef, announce, onExport });
|
|
3419
|
+
[result, encodedProp, imported, data, drillDownLimit, onCellClick, drillDown, defaultsOf, nameOf, infoOf]
|
|
3420
|
+
);
|
|
3421
|
+
const doExport = useExport({ fileName, result, locale, labels, limits, root, chartRef, announce, onExport, title: viewName, source: sourceName, loadECharts });
|
|
3422
|
+
const requestImport = () => loadImport().then((m) => (flushSync(() => setImportMod(() => m)), m));
|
|
3423
|
+
const api = {
|
|
3424
|
+
imported,
|
|
3425
|
+
setImported,
|
|
3426
|
+
steps: dataSteps,
|
|
3427
|
+
setSteps: setDataSteps,
|
|
3428
|
+
job,
|
|
3429
|
+
setJob,
|
|
3430
|
+
dragging,
|
|
3431
|
+
history,
|
|
3432
|
+
encoded,
|
|
3433
|
+
hostEncoded: source.encoded,
|
|
3434
|
+
hostSource: sourceProp,
|
|
3435
|
+
sourceName,
|
|
3436
|
+
labels,
|
|
3437
|
+
locale,
|
|
3438
|
+
plugins,
|
|
3439
|
+
worker: importWorker,
|
|
3440
|
+
limits: fileLimits,
|
|
3441
|
+
timeZone,
|
|
3442
|
+
onDataLoad,
|
|
3443
|
+
announce,
|
|
3444
|
+
dismiss,
|
|
3445
|
+
undo: () => undoLater.current(),
|
|
3446
|
+
box: () => root.current?.getBoundingClientRect(),
|
|
3447
|
+
pick: () => importMod?.pickFile(fileInput.current),
|
|
3448
|
+
load: requestImport
|
|
3449
|
+
};
|
|
3450
|
+
useEffect11(() => {
|
|
3451
|
+
apiNow.current = api;
|
|
3452
|
+
});
|
|
3453
|
+
const restored = useRef11(false);
|
|
3454
|
+
useIsoLayoutEffect(() => {
|
|
3455
|
+
if (kept2 && !restored.current) {
|
|
3456
|
+
restored.current = true;
|
|
3457
|
+
importMod?.restoreData(api);
|
|
3458
|
+
history.replace(kept2.history);
|
|
3459
|
+
}
|
|
3460
|
+
}, []);
|
|
3461
|
+
const snapshot = history.snapshot;
|
|
3462
|
+
const keptKey = useRef11(keepKey);
|
|
3463
|
+
const fileShown = useRef11(false);
|
|
3464
|
+
const hostHasColumns = source.encoded.schema.fields.length > 0;
|
|
3465
|
+
useIsoLayoutEffect(() => {
|
|
3466
|
+
if (keepKey !== null && !kept2 && hostHasColumns) {
|
|
3467
|
+
forgetData(keepKey);
|
|
3468
|
+
}
|
|
3469
|
+
}, []);
|
|
3470
|
+
useEffect11(() => {
|
|
3471
|
+
if (keptKey.current !== keepKey && keptKey.current !== null) {
|
|
3472
|
+
forgetData(keptKey.current);
|
|
3473
|
+
}
|
|
3474
|
+
keptKey.current = keepKey;
|
|
3475
|
+
if (keepKey === null) {
|
|
3476
|
+
return;
|
|
3477
|
+
}
|
|
3478
|
+
if (imported) {
|
|
3479
|
+
fileShown.current = true;
|
|
3480
|
+
keepData(keepKey, { host: hostData, imported, steps: dataSteps, history: snapshot(), savedKeys });
|
|
3481
|
+
} else if (fileShown.current) {
|
|
3482
|
+
fileShown.current = false;
|
|
3483
|
+
forgetData(keepKey);
|
|
3484
|
+
}
|
|
3485
|
+
}, [keepKey, hostData, imported, dataSteps, snapshot, savedKeys]);
|
|
3486
|
+
const fileDrag = (e) => {
|
|
3487
|
+
if (!Array.prototype.includes.call(e.dataTransfer?.types ?? [], "Files")) {
|
|
3488
|
+
return;
|
|
3489
|
+
}
|
|
3490
|
+
e.preventDefault();
|
|
3491
|
+
const files = e.type === "drop" ? [...e.dataTransfer.files] : null;
|
|
3492
|
+
dragDepth.current = files ? 0 : Math.max(0, dragDepth.current + (e.type === "dragenter" ? 1 : e.type === "dragleave" ? -1 : 0));
|
|
3493
|
+
setDragging(dragDepth.current > 0);
|
|
3494
|
+
if (e.type !== "dragover") {
|
|
3495
|
+
requestImport().then((m) => files && m.startFiles(apiNow.current, files), () => void 0);
|
|
3496
|
+
}
|
|
3497
|
+
};
|
|
3075
3498
|
const base = shareBase(shareLink, here()?.href);
|
|
3076
3499
|
const share = {
|
|
3077
3500
|
canLink: base !== null,
|
|
@@ -3083,7 +3506,7 @@ function Report(props) {
|
|
|
3083
3506
|
schemaUrl,
|
|
3084
3507
|
encoded,
|
|
3085
3508
|
shareLink,
|
|
3086
|
-
|
|
3509
|
+
linkKey: storageKey,
|
|
3087
3510
|
root,
|
|
3088
3511
|
fileName,
|
|
3089
3512
|
onExport,
|
|
@@ -3100,20 +3523,20 @@ function Report(props) {
|
|
|
3100
3523
|
commit(t.view, { step: "template", name: t.name }, tag);
|
|
3101
3524
|
const over = zoneOverLimit(t.view, limits);
|
|
3102
3525
|
const issues = normalize2(t.view, encoded, { limits }).issues.filter((i) => !over || i.code !== "tooMany");
|
|
3103
|
-
|
|
3526
|
+
leaveOut([...over ? [{ text: fill(labels.viewTrimmed, { name: t.name, zone: labels.zones[over.zone], max: over.max.toLocaleString(locale) }), path: over.zone }] : [], ...unusedNotes(issues, t.view)], t.view);
|
|
3104
3527
|
setIssuesDismissed(null);
|
|
3105
3528
|
setLoads((x) => x + 1);
|
|
3106
3529
|
setUnusedSaid(false);
|
|
3107
3530
|
announce(fill(labels.toastLoaded, { name: t.name }));
|
|
3108
3531
|
},
|
|
3109
|
-
[commit, labels, announce, limits, locale, history, remember, sourceId, encoded]
|
|
3532
|
+
[commit, labels, announce, limits, locale, history, remember, sourceId, encoded, leaveOut]
|
|
3110
3533
|
);
|
|
3111
3534
|
const newReport = () => {
|
|
3112
3535
|
if (empty) {
|
|
3113
3536
|
return;
|
|
3114
3537
|
}
|
|
3115
3538
|
commit(emptyView2(), { step: "new" }, null);
|
|
3116
|
-
|
|
3539
|
+
leaveOut([], null);
|
|
3117
3540
|
setLoads((x) => x + 1);
|
|
3118
3541
|
setUnusedSaid(false);
|
|
3119
3542
|
announce(labels.newEmpty, { action: { label: labels.undo, run: () => undoLater.current() } });
|
|
@@ -3155,9 +3578,7 @@ function Report(props) {
|
|
|
3155
3578
|
now.setTag(tag);
|
|
3156
3579
|
}
|
|
3157
3580
|
},
|
|
3158
|
-
viewKey: history.viewKey
|
|
3159
|
-
onNew: newReport,
|
|
3160
|
-
canNew: !empty
|
|
3581
|
+
viewKey: history.viewKey
|
|
3161
3582
|
};
|
|
3162
3583
|
const onKeyDown = (e) => {
|
|
3163
3584
|
const target = (
|
|
@@ -3169,7 +3590,7 @@ function Report(props) {
|
|
|
3169
3590
|
big.setEnlarged(false);
|
|
3170
3591
|
return;
|
|
3171
3592
|
}
|
|
3172
|
-
if (target.closest("input, textarea, select, [contenteditable]")) {
|
|
3593
|
+
if (target.closest("input, textarea, select, [contenteditable], [aria-modal='true']")) {
|
|
3173
3594
|
return;
|
|
3174
3595
|
}
|
|
3175
3596
|
const mod = e.ctrlKey || e.metaKey;
|
|
@@ -3300,14 +3721,24 @@ function Report(props) {
|
|
|
3300
3721
|
commit(setChart(view, "auto"), { step: "chart", type: "auto" });
|
|
3301
3722
|
} else if (action === "saveTemplate") {
|
|
3302
3723
|
setViewsRequest((n) => n + 1);
|
|
3724
|
+
} else if (action === "colSubtotalsOff") {
|
|
3725
|
+
commit(setTotal(view, "colSubtotals", false), { step: "totals" });
|
|
3303
3726
|
}
|
|
3304
3727
|
};
|
|
3305
3728
|
const cancelLink = () => {
|
|
3306
3729
|
appliedLink.current = null;
|
|
3307
3730
|
setLinkCheck(null);
|
|
3308
3731
|
};
|
|
3309
|
-
const
|
|
3310
|
-
const
|
|
3732
|
+
const fromHost = hostNotes !== null && leftOut.after !== hostKey;
|
|
3733
|
+
const given = fromHost ? hostNotes : leftOut;
|
|
3734
|
+
const notes = useMemo8(
|
|
3735
|
+
() => [...given.notes.filter((n) => stillApplies(n, given.loaded, view)), ...result && !empty ? result.issues.slice(0, 20).map((issue) => ({ issue, raw: view })) : []],
|
|
3736
|
+
[given, result, empty, view]
|
|
3737
|
+
);
|
|
3738
|
+
const notesKey = useMemo8(
|
|
3739
|
+
() => JSON.stringify([fromHost ? "host" : loads, ...given.notes.map((n) => "issue" in n ? [n.issue.path, n.issue.message] : n.text), ...result && !empty ? result.issues.slice(0, 20).map((i) => [i.path, i.message]) : []]),
|
|
3740
|
+
[fromHost, given, loads, result, empty]
|
|
3741
|
+
);
|
|
3311
3742
|
const summaryParts = big.enlarged ? layoutSummary(zoneEntries(view, types, labels), labels) : [];
|
|
3312
3743
|
const summaryText = summaryParts.length ? summaryParts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
|
|
3313
3744
|
return /* @__PURE__ */ React12.createElement(
|
|
@@ -3326,9 +3757,13 @@ function Report(props) {
|
|
|
3326
3757
|
"aria-label": label || labels.report,
|
|
3327
3758
|
style: { height },
|
|
3328
3759
|
tabIndex: -1,
|
|
3329
|
-
onKeyDown
|
|
3760
|
+
onKeyDown,
|
|
3761
|
+
onDragEnter: allowImport ? fileDrag : void 0,
|
|
3762
|
+
onDragOver: allowImport ? fileDrag : void 0,
|
|
3763
|
+
onDragLeave: allowImport ? fileDrag : void 0,
|
|
3764
|
+
onDrop: allowImport ? fileDrag : void 0
|
|
3330
3765
|
},
|
|
3331
|
-
/* @__PURE__ */ React12.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React12.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React12.createElement(
|
|
3766
|
+
/* @__PURE__ */ React12.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React12.createElement(FormNameContext.Provider, { value: formPrefix }, /* @__PURE__ */ React12.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React12.createElement(
|
|
3332
3767
|
PivotDnd,
|
|
3333
3768
|
{
|
|
3334
3769
|
labels,
|
|
@@ -3353,7 +3788,7 @@ function Report(props) {
|
|
|
3353
3788
|
}
|
|
3354
3789
|
},
|
|
3355
3790
|
onNote: (text) => announce(text),
|
|
3356
|
-
onFilter:
|
|
3791
|
+
onFilter: filterField,
|
|
3357
3792
|
nameOf,
|
|
3358
3793
|
info,
|
|
3359
3794
|
showInfo: fieldSwitch.on,
|
|
@@ -3374,12 +3809,15 @@ function Report(props) {
|
|
|
3374
3809
|
chartPlan: plan,
|
|
3375
3810
|
labels,
|
|
3376
3811
|
size,
|
|
3377
|
-
canUndo: history.canUndo,
|
|
3378
|
-
canRedo: history.canRedo,
|
|
3812
|
+
canUndo: history.canUndo || dataSteps.past.length > 0,
|
|
3813
|
+
canRedo: history.canRedo || dataSteps.future.length > 0,
|
|
3379
3814
|
canReset: history.canReset,
|
|
3815
|
+
startEmpty: history.startEmpty,
|
|
3816
|
+
canNew: !empty,
|
|
3380
3817
|
onUndo: undo2,
|
|
3381
3818
|
onRedo: redo2,
|
|
3382
3819
|
onReset: reset2,
|
|
3820
|
+
onNew: newReport,
|
|
3383
3821
|
loadedView: loadedView ? { name: loadedView.name, changed: unsaved } : null,
|
|
3384
3822
|
onDisplay: (d) => commit(setDisplay(view, d), { step: "display", display: d }),
|
|
3385
3823
|
onChart: (p) => commit(setChart(view, p), { step: "chart", type: p }),
|
|
@@ -3408,7 +3846,8 @@ function Report(props) {
|
|
|
3408
3846
|
help: {
|
|
3409
3847
|
explanations: explainUser ? { on: !dismissed.includes(NO_EXPLANATIONS), set: (on) => toggle(NO_EXPLANATIONS, on) } : null
|
|
3410
3848
|
},
|
|
3411
|
-
viewsRequest
|
|
3849
|
+
viewsRequest,
|
|
3850
|
+
data: allowImport ? { loaded: Boolean(imported), panel: (close) => /* @__PURE__ */ React12.createElement(MenuPanel, { name: "DataMenu", loadingText: labels.loadingMenu, props: { api, close, labels } }) } : null
|
|
3412
3851
|
}
|
|
3413
3852
|
), /* @__PURE__ */ React12.createElement(
|
|
3414
3853
|
Zones,
|
|
@@ -3443,9 +3882,9 @@ function Report(props) {
|
|
|
3443
3882
|
}
|
|
3444
3883
|
},
|
|
3445
3884
|
labels,
|
|
3446
|
-
locale,
|
|
3885
|
+
locale: result?.locale ?? unusedLocale,
|
|
3447
3886
|
narrow: size === "narrow",
|
|
3448
|
-
quiet: unusedSaid
|
|
3887
|
+
quiet: unusedSaid && !fromHost
|
|
3449
3888
|
}
|
|
3450
3889
|
), /* @__PURE__ */ React12.createElement(
|
|
3451
3890
|
Tips,
|
|
@@ -3456,7 +3895,7 @@ function Report(props) {
|
|
|
3456
3895
|
onAction: runTip,
|
|
3457
3896
|
focusFallback: () => root.current?.focus({ preventScroll: true })
|
|
3458
3897
|
}
|
|
3459
|
-
), showTable && view.values.length ? /* @__PURE__ */ React12.createElement("p", { id: hintId, className: "pk-sr", "data-testid": "cell-hint" }, labels.tips.cells) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-result-head" }, big.enlarged ? /* @__PURE__ */ React12.createElement("p", { className: "pk-enlarged-fields", "data-testid": "enlarged-fields" }, summaryText) : null, /* @__PURE__ */ React12.createElement("span", { className: "pk-grow" }), /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "data-pk-on": big.enlarged ? "" : void 0, onClick: big.toggleEnlarged, "data-testid": "enlarge" }, /* @__PURE__ */ React12.createElement(Icon, { name: "enlarge", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, big.enlarged ? labels.reduce : labels.enlarge)), big.fullOk ? /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "aria-pressed": big.full, onClick: big.toggleFull, "data-testid": "full-screen" }, /* @__PURE__ */ React12.createElement(Icon, { name: "fullScreen", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, labels.fullScreen)) : null), /* @__PURE__ */ React12.createElement("section", { className: "pk-result", "aria-label": view.display === "chart" ? labels.chart : labels.table }, loading2 || opening ? /* @__PURE__ */ React12.createElement(Skeleton, { text: labels.loadingReport }) : error ? /* @__PURE__ */ React12.createElement("div", { className: "pk-message pk-error", role: "alert" }, /* @__PURE__ */ React12.createElement(Icon, { name: "info" }), /* @__PURE__ */ React12.createElement("p", null, errorText(error, labels, locale))) : empty && view.display === "table" ? /* @__PURE__ */ React12.createElement(EmptyState, { labels, templates: entries, onTemplate: loadTemplate }) : view.display === "chart" && chartResult ? /* @__PURE__ */ React12.createElement(
|
|
3898
|
+
), showTable && view.values.length ? /* @__PURE__ */ React12.createElement("p", { id: hintId, className: "pk-sr", "data-testid": "cell-hint" }, labels.tips.cells) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-result-head" }, big.enlarged ? /* @__PURE__ */ React12.createElement("p", { className: "pk-enlarged-fields", "data-testid": "enlarged-fields" }, summaryText) : null, /* @__PURE__ */ React12.createElement("span", { className: "pk-grow" }), /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "data-pk-on": big.enlarged ? "" : void 0, onClick: big.toggleEnlarged, "data-testid": "enlarge" }, /* @__PURE__ */ React12.createElement(Icon, { name: "enlarge", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, big.enlarged ? labels.reduce : labels.enlarge)), big.fullOk ? /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "aria-pressed": big.full, onClick: big.toggleFull, "data-testid": "full-screen" }, /* @__PURE__ */ React12.createElement(Icon, { name: "fullScreen", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, labels.fullScreen)) : null), /* @__PURE__ */ React12.createElement("section", { className: "pk-result", "aria-label": view.display === "chart" ? labels.chart : labels.table }, loading2 || opening ? /* @__PURE__ */ React12.createElement(Skeleton, { text: labels.loadingReport }) : error ? /* @__PURE__ */ React12.createElement("div", { className: "pk-message pk-error", role: "alert" }, /* @__PURE__ */ React12.createElement(Icon, { name: "info" }), /* @__PURE__ */ React12.createElement("p", null, errorText(error, labels, locale))) : empty && view.display === "table" ? /* @__PURE__ */ React12.createElement(EmptyState, { labels, templates: entries, onTemplate: loadTemplate, onLoad: allowImport ? () => requestImport().then((m) => m.pickFile(fileInput.current), () => announce(labels.menuFailed, { tone: "error" })) : void 0, noData: allowImport && fields.length === 0 }) : view.display === "chart" && chartResult ? /* @__PURE__ */ React12.createElement(
|
|
3460
3899
|
PivotChart,
|
|
3461
3900
|
{
|
|
3462
3901
|
result: chartResult,
|
|
@@ -3474,9 +3913,9 @@ function Report(props) {
|
|
|
3474
3913
|
},
|
|
3475
3914
|
onPoint: (p) => openCell({ rowPath: plan.swap ? p.colPath : p.rowPath, colPath: plan.swap ? p.rowPath : p.colPath, value: p.value, valueIndex: p.valueIndex, text: String(p.value ?? "") })
|
|
3476
3915
|
}
|
|
3477
|
-
) : gridState.grid ? /* @__PURE__ */ React12.createElement(PivotTable, { grid: gridState.grid, view, labels, version: history.viewKey, hintId: view.values.length ? hintId : void 0, onRowLabel: setRowLabel, infoOf, showInfo: fieldSwitch.on, typeOf, hostOrdered, onSort: sortFromHeader, onToggle: (axis, path) => commit(toggleCollapsed(view, axis, path), { step: "collapse" }), onCell: (cell) => openCell(cell) }) : null), /* @__PURE__ */ React12.createElement("div", { className: "pk-status" }, /* @__PURE__ */ React12.createElement("span", { "data-testid": "row-count" }, result ? plural(labels.rowsCount, result.rows.length, { lang: labels.lang, locale }) : ""), rowLabel && showTable ? /* @__PURE__ */ React12.createElement("span", { className: "pk-row-label", "data-testid": "row-label" }, fill(labels.rowLabel, { label: rowLabel })) : null), /* @__PURE__ */ React12.createElement("div", { className: "pk-toast-dock" }, /* @__PURE__ */ React12.createElement(Toasts, { toasts, dismiss, pause, closeLabel: labels.close }))), drill ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "DrillPanel", props: { drill, onClose: () => setDrill(null), labels, locale, exportContext: { encoded, onExport, announce, root } } }) : null),
|
|
3916
|
+
) : gridState.grid ? /* @__PURE__ */ React12.createElement(PivotTable, { grid: gridState.grid, view, labels, version: history.viewKey, hintId: view.values.length ? hintId : void 0, onRowLabel: setRowLabel, infoOf, showInfo: fieldSwitch.on, typeOf, hostOrdered, onSort: sortFromHeader, onToggle: (axis, path) => commit(toggleCollapsed(view, axis, path), { step: "collapse" }), onCell: (cell) => openCell(cell) }) : null), /* @__PURE__ */ React12.createElement("div", { className: "pk-status" }, /* @__PURE__ */ React12.createElement("span", { "data-testid": "row-count" }, result ? plural(labels.rowsCount, result.rows.length, { lang: labels.lang, locale }) : ""), importMod ? /* @__PURE__ */ React12.createElement(importMod.SourceLine, { api }) : null, rowLabel && showTable ? /* @__PURE__ */ React12.createElement("span", { className: "pk-row-label", "data-testid": "row-label" }, fill(labels.rowLabel, { label: rowLabel })) : null), /* @__PURE__ */ React12.createElement("div", { className: "pk-toast-dock" }, /* @__PURE__ */ React12.createElement(Toasts, { toasts, dismiss, pause, closeLabel: labels.close }))), drill ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "DrillPanel", props: { drill, onClose: () => setDrill(null), labels, locale, exportContext: { encoded, onExport, announce, root } } }) : null),
|
|
3478
3917
|
filterTarget ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "FilterPopover", props: { target: filterTarget, onClose: closeFilter, view, encoded, locale, labels, commit } }) : null
|
|
3479
|
-
), /* @__PURE__ */ React12.createElement("div", { className: "pk-layer", ref: setLayer }, /* @__PURE__ */ React12.createElement("span", { className: "pk-origin", "aria-hidden": "true" }))))
|
|
3918
|
+
), allowImport && importMod ? /* @__PURE__ */ React12.createElement(importMod.ImportLayer, { api, input: fileInput }) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-layer", ref: setLayer }, /* @__PURE__ */ React12.createElement("span", { className: "pk-origin", "aria-hidden": "true" })))))
|
|
3480
3919
|
);
|
|
3481
3920
|
}
|
|
3482
3921
|
export {
|