pivotkit-react 0.0.0-stage → 0.2.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 +442 -0
- package/LICENSE +21 -0
- package/README.md +77 -2
- package/dist/chunks/chunk-53ZMK4BH.js +177 -0
- package/dist/chunks/chunk-F6MVUAQD.js +741 -0
- package/dist/chunks/chunk-LQCWFJBS.js +310 -0
- package/dist/chunks/chunk-OYY4BKIL.js +93 -0
- package/dist/chunks/chunk-QBD4FOBB.js +254 -0
- package/dist/chunks/chunk-X7H7BAVT.js +1752 -0
- package/dist/chunks/unused-texts-YTNJCFFC.js +10 -0
- package/dist/chunks/unused-texts-de-SGOHV4N7.js +6 -0
- package/dist/echarts.js +347 -0
- package/dist/index.js +3482 -0
- package/dist/labels.js +21 -0
- package/dist/menu-texts-de.js +6 -0
- package/dist/menus.js +1681 -0
- package/dist/styles.css +2529 -0
- package/package.json +70 -4
- package/types/PivotReport.d.ts +20 -0
- package/types/all-labels.d.ts +5 -0
- package/types/chart-decorate.d.ts +16 -0
- package/types/chart-layout.d.ts +111 -0
- package/types/chart-options.d.ts +23 -0
- package/types/chart-summary.d.ts +12 -0
- package/types/chart-tooltip.d.ts +38 -0
- package/types/chart-types.d.ts +61 -0
- package/types/chart.d.ts +39 -0
- package/types/chip-menus.d.ts +32 -0
- package/types/clear-input.d.ts +20 -0
- package/types/dnd-moves.d.ts +45 -0
- package/types/dnd.d.ts +101 -0
- package/types/dom.d.ts +52 -0
- package/types/drill-export.d.ts +42 -0
- package/types/drill-panel.d.ts +22 -0
- package/types/drill-table.d.ts +71 -0
- package/types/drill.d.ts +26 -0
- package/types/echarts.d.ts +4 -0
- package/types/export-run.d.ts +59 -0
- package/types/field-info.d.ts +34 -0
- package/types/fields.d.ts +32 -0
- package/types/files.d.ts +27 -0
- package/types/filter.d.ts +21 -0
- package/types/help.d.ts +21 -0
- package/types/icons.d.ts +80 -0
- package/types/index.d.ts +536 -0
- package/types/info.d.ts +34 -0
- package/types/iso.d.ts +2 -0
- package/types/labels.d.ts +663 -0
- package/types/lazy-menus.d.ts +28 -0
- package/types/menu-labels-de.d.ts +2 -0
- package/types/menu-labels.d.ts +317 -0
- package/types/menu-ops.d.ts +145 -0
- package/types/menu-texts.d.ts +2 -0
- package/types/menus.d.ts +7 -0
- package/types/names.d.ts +80 -0
- package/types/numbers.d.ts +13 -0
- package/types/overflow.d.ts +62 -0
- package/types/place.d.ts +43 -0
- package/types/popover.d.ts +93 -0
- package/types/rove.d.ts +20 -0
- package/types/section.d.ts +25 -0
- package/types/sections.d.ts +2 -0
- package/types/share-actions.d.ts +99 -0
- package/types/share.d.ts +114 -0
- package/types/skeleton.d.ts +9 -0
- package/types/storage.d.ts +24 -0
- package/types/table.d.ts +29 -0
- package/types/templates.d.ts +46 -0
- package/types/theme.d.ts +24 -0
- package/types/tip-list.d.ts +20 -0
- package/types/tips.d.ts +300 -0
- package/types/toasts.d.ts +26 -0
- package/types/toolbar-panels.d.ts +93 -0
- package/types/toolbar.d.ts +5 -0
- package/types/unused-load.d.ts +23 -0
- package/types/unused-texts-de.d.ts +2 -0
- package/types/unused-texts.d.ts +130 -0
- package/types/unused.d.ts +22 -0
- package/types/use-big-result.d.ts +29 -0
- package/types/use-export.d.ts +7 -0
- package/types/use-theme.d.ts +11 -0
- package/types/use-view-history.d.ts +37 -0
- package/types/version.d.ts +2 -0
- package/types/view-history.d.ts +106 -0
- package/types/view-ops.d.ts +293 -0
- package/types/view-save.d.ts +76 -0
- package/types/view-store.d.ts +59 -0
- package/types/virtual.d.ts +44 -0
- package/types/zones.d.ts +42 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,3482 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ALL_TIPS,
|
|
3
|
+
CHART_TYPES,
|
|
4
|
+
ClearInput,
|
|
5
|
+
DRILL_LIMIT,
|
|
6
|
+
FIELDS_COLLAPSED,
|
|
7
|
+
HelpContext,
|
|
8
|
+
Icon,
|
|
9
|
+
InfoButton,
|
|
10
|
+
LayerContext,
|
|
11
|
+
MAX_CATEGORIES,
|
|
12
|
+
MenuButton,
|
|
13
|
+
NO_EXPLANATIONS,
|
|
14
|
+
Option,
|
|
15
|
+
Popover,
|
|
16
|
+
TYPE_ICON,
|
|
17
|
+
ZONES,
|
|
18
|
+
ZONE_ICON,
|
|
19
|
+
activeIn,
|
|
20
|
+
activeTips,
|
|
21
|
+
addField,
|
|
22
|
+
allowedTips,
|
|
23
|
+
chartPlan,
|
|
24
|
+
chartTypeOf,
|
|
25
|
+
cleanDismissed,
|
|
26
|
+
drillRows,
|
|
27
|
+
fieldAction,
|
|
28
|
+
fieldsCollapsed,
|
|
29
|
+
filterZoneFields,
|
|
30
|
+
filtersOf,
|
|
31
|
+
groupField,
|
|
32
|
+
groupingName,
|
|
33
|
+
headerSortState,
|
|
34
|
+
headerSortTarget,
|
|
35
|
+
helpSwitch,
|
|
36
|
+
isEmptyView,
|
|
37
|
+
keptOnReset,
|
|
38
|
+
layoutSummary,
|
|
39
|
+
linkNow,
|
|
40
|
+
linkParam,
|
|
41
|
+
loadCheck,
|
|
42
|
+
loadLink,
|
|
43
|
+
localStore,
|
|
44
|
+
moveField,
|
|
45
|
+
nextHeaderSort,
|
|
46
|
+
numberRange,
|
|
47
|
+
parseStored,
|
|
48
|
+
readItem,
|
|
49
|
+
readLinkParam,
|
|
50
|
+
readStored,
|
|
51
|
+
readStoredView,
|
|
52
|
+
refLabel,
|
|
53
|
+
removeAt,
|
|
54
|
+
rootOf,
|
|
55
|
+
rowFolding,
|
|
56
|
+
sectionOpen,
|
|
57
|
+
selectedItems,
|
|
58
|
+
setChart,
|
|
59
|
+
setChartDisplay,
|
|
60
|
+
setCollapsed,
|
|
61
|
+
setDisplay,
|
|
62
|
+
setSort,
|
|
63
|
+
setTotal,
|
|
64
|
+
shareBase,
|
|
65
|
+
sortOf,
|
|
66
|
+
sortText,
|
|
67
|
+
sourceOf,
|
|
68
|
+
subscribeItem,
|
|
69
|
+
subscribeStored,
|
|
70
|
+
swapAxes,
|
|
71
|
+
tipActionText,
|
|
72
|
+
tipContext,
|
|
73
|
+
tipText,
|
|
74
|
+
toggleCollapsed,
|
|
75
|
+
useIsoLayoutEffect,
|
|
76
|
+
useModal,
|
|
77
|
+
valueConditionText,
|
|
78
|
+
valueLabel,
|
|
79
|
+
viewFromObject,
|
|
80
|
+
withHostOrders,
|
|
81
|
+
withSection,
|
|
82
|
+
withoutFilters,
|
|
83
|
+
writeDismissed,
|
|
84
|
+
writeItem,
|
|
85
|
+
writeStoredView,
|
|
86
|
+
zoneOverLimit
|
|
87
|
+
} from "./chunks/chunk-X7H7BAVT.js";
|
|
88
|
+
import {
|
|
89
|
+
LABELS,
|
|
90
|
+
MENU_TEXTS,
|
|
91
|
+
errorText,
|
|
92
|
+
fill,
|
|
93
|
+
mergeLabels,
|
|
94
|
+
messageOf,
|
|
95
|
+
plural,
|
|
96
|
+
resolveLabels
|
|
97
|
+
} from "./chunks/chunk-F6MVUAQD.js";
|
|
98
|
+
|
|
99
|
+
// src/PivotReport.jsx
|
|
100
|
+
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";
|
|
101
|
+
import { computePivot, emptyView as emptyView2, encode, fieldLabel as fieldLabel5, normalize as normalize2, suggestDateUnit, toGrid, toSeries, viewFields } from "pivotkit-core";
|
|
102
|
+
|
|
103
|
+
// src/chart.jsx
|
|
104
|
+
import React, { useEffect, useId, useRef, useState } from "react";
|
|
105
|
+
import { fieldLabel, toEChartsOption } from "pivotkit-core";
|
|
106
|
+
|
|
107
|
+
// src/chart-summary.js
|
|
108
|
+
import { formatter } from "pivotkit-core";
|
|
109
|
+
var OLD_COUNTS = new RegExp("\\{(categories|series)\\}\\s*\\p{L}", "u");
|
|
110
|
+
function counts(s, labels, locale) {
|
|
111
|
+
const categories = s.categoryCount ?? s.categories.length;
|
|
112
|
+
const series = s.series.length;
|
|
113
|
+
if (OLD_COUNTS.test(labels.chartCounts)) {
|
|
114
|
+
return fill(labels.chartCounts, { categories: categories.toLocaleString(locale), series: series.toLocaleString(locale) });
|
|
115
|
+
}
|
|
116
|
+
return fill(labels.chartCounts, {
|
|
117
|
+
categories: plural(labels.chartCategories, categories, { lang: labels.lang, locale }),
|
|
118
|
+
series: plural(labels.chartSeries, series, { lang: labels.lang, locale })
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
function chartSummary(s, { type, rows, valueNames, labels, locale }) {
|
|
122
|
+
const parts = [
|
|
123
|
+
fill(labels.chartSummary, { type: labels.chartTypes[type] ?? type, values: valueNames.join(", "), categories: rows.length ? rows.join(" / ") : labels.categories }),
|
|
124
|
+
counts(s, labels, locale)
|
|
125
|
+
];
|
|
126
|
+
let max = null;
|
|
127
|
+
let min = null;
|
|
128
|
+
s.series.forEach((series, si) => {
|
|
129
|
+
series.data.forEach((v, ci) => {
|
|
130
|
+
if (typeof v !== "number") {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
if (!max || v > max.v) {
|
|
134
|
+
max = { v, si, ci };
|
|
135
|
+
}
|
|
136
|
+
if (!min || v < min.v) {
|
|
137
|
+
min = { v, si, ci };
|
|
138
|
+
}
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
if (max && min) {
|
|
142
|
+
const where = (p) => s.series.length > 1 && s.series[p.si].name ? `${s.categories[p.ci]} / ${s.series[p.si].name}` : s.categories[p.ci];
|
|
143
|
+
const text = (p) => formatter(s.series[p.si].format, { locale })(p.v);
|
|
144
|
+
parts.push(fill(labels.chartExtremes, { max: text(max), maxAt: where(max), min: text(min), minAt: where(min) }));
|
|
145
|
+
}
|
|
146
|
+
parts.push(labels.chartTableHint);
|
|
147
|
+
return parts.join(" ");
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/theme.js
|
|
151
|
+
function resolveTheme(wanted, htmlTheme, prefersDark) {
|
|
152
|
+
if (wanted === "light" || wanted === "dark") {
|
|
153
|
+
return wanted;
|
|
154
|
+
}
|
|
155
|
+
if (htmlTheme === "light" || htmlTheme === "dark") {
|
|
156
|
+
return htmlTheme;
|
|
157
|
+
}
|
|
158
|
+
return prefersDark ? "dark" : "light";
|
|
159
|
+
}
|
|
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
|
+
|
|
186
|
+
// src/chart.jsx
|
|
187
|
+
var loading = null;
|
|
188
|
+
function loadECharts() {
|
|
189
|
+
loading ??= import("./echarts.js");
|
|
190
|
+
return loading;
|
|
191
|
+
}
|
|
192
|
+
function PivotChart({ result, series, labels, locale, themeName, root, onInstance, onPoint, valueNames, chartOptions, plan }) {
|
|
193
|
+
const el = useRef(
|
|
194
|
+
/** @type {HTMLDivElement | null} */
|
|
195
|
+
null
|
|
196
|
+
);
|
|
197
|
+
const chart = useRef(
|
|
198
|
+
/** @type {any} */
|
|
199
|
+
null
|
|
200
|
+
);
|
|
201
|
+
const [ready, setReady] = useState(false);
|
|
202
|
+
const [failed, setFailed] = useState(
|
|
203
|
+
/** @type {string | null} */
|
|
204
|
+
null
|
|
205
|
+
);
|
|
206
|
+
const [box, setBox] = useState("");
|
|
207
|
+
const [every, setEvery] = useState(1);
|
|
208
|
+
const summaryId = useId();
|
|
209
|
+
const type = plan ? plan.name : chartTypeOf(result.view.chart);
|
|
210
|
+
const drawAs = plan ? plan.chart : null;
|
|
211
|
+
const latest = useRef({ series, onPoint, onInstance, type });
|
|
212
|
+
const lib = useRef(
|
|
213
|
+
/** @type {any} */
|
|
214
|
+
null
|
|
215
|
+
);
|
|
216
|
+
const warned2 = useRef(
|
|
217
|
+
/** @type {unknown} */
|
|
218
|
+
void 0
|
|
219
|
+
);
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
latest.current = { series, onPoint, onInstance, type };
|
|
222
|
+
});
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
let disposed = false;
|
|
225
|
+
let ro = null;
|
|
226
|
+
loadECharts().then(
|
|
227
|
+
(echarts) => {
|
|
228
|
+
if (disposed || !el.current) {
|
|
229
|
+
return;
|
|
230
|
+
}
|
|
231
|
+
lib.current = echarts;
|
|
232
|
+
const instance = echarts.init(el.current, null, { renderer: "canvas" });
|
|
233
|
+
chart.current = instance;
|
|
234
|
+
latest.current.onInstance(instance);
|
|
235
|
+
instance.on("click", (p) => {
|
|
236
|
+
const { series: s, onPoint: cb } = latest.current;
|
|
237
|
+
const kind = p.seriesType;
|
|
238
|
+
if (!s || kind === "pie") {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const seriesEntry = kind === "heatmap" ? s.series.filter((x) => x.valueIndex === s.series[0]?.valueIndex)[p.value?.[0]] : s.series[p.seriesIndex];
|
|
242
|
+
const row = kind === "heatmap" ? p.value?.[1] : p.dataIndex;
|
|
243
|
+
if (seriesEntry && s.categoryPaths[row]) {
|
|
244
|
+
cb({ rowPath: s.categoryPaths[row], colPath: seriesEntry.colPath, valueIndex: seriesEntry.valueIndex, value: kind === "heatmap" ? p.value[2] : p.value });
|
|
245
|
+
}
|
|
246
|
+
});
|
|
247
|
+
ro = typeof ResizeObserver === "function" ? new ResizeObserver(() => {
|
|
248
|
+
instance.resize();
|
|
249
|
+
setBox(`${instance.getWidth()}x${instance.getHeight()}`);
|
|
250
|
+
}) : null;
|
|
251
|
+
ro?.observe(el.current);
|
|
252
|
+
setReady(true);
|
|
253
|
+
},
|
|
254
|
+
(err) => setFailed(String(err && err.message ? err.message : err))
|
|
255
|
+
);
|
|
256
|
+
return () => {
|
|
257
|
+
disposed = true;
|
|
258
|
+
ro?.disconnect();
|
|
259
|
+
chart.current?.dispose();
|
|
260
|
+
chart.current = null;
|
|
261
|
+
latest.current.onInstance(null);
|
|
262
|
+
};
|
|
263
|
+
}, []);
|
|
264
|
+
useEffect(() => {
|
|
265
|
+
if (!ready || !chart.current || !root.current) {
|
|
266
|
+
return;
|
|
267
|
+
}
|
|
268
|
+
const style = getComputedStyle(root.current);
|
|
269
|
+
const option = toEChartsOption(result, { theme: chartThemeFrom(style), locale, labels: labels.core, maxCategories: MAX_CATEGORIES, ...series ? { series } : {}, ...drawAs ? { chart: drawAs } : {} });
|
|
270
|
+
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
|
+
setEvery(axisEvery);
|
|
272
|
+
const clean = chartOptions ? lib.current.cleanChartOptions(chartOptions) : null;
|
|
273
|
+
if (clean?.problems.length && warned2.current !== chartOptions) {
|
|
274
|
+
warned2.current = chartOptions;
|
|
275
|
+
console.warn(`pivotkit: chartOptions entries left out (only plain JSON, and no markup, addresses or text templates): ${clean.problems.slice(0, 5).join("; ")}${clean.problems.length > 5 ? `; and ${clean.problems.length - 5} more` : ""}`);
|
|
276
|
+
}
|
|
277
|
+
chart.current.setOption(clean?.options ? lib.current.mergeChartOptions(drawn, clean.options) : drawn, { notMerge: true });
|
|
278
|
+
}, [ready, result, series, labels, locale, themeName, root, box, chartOptions, drawAs]);
|
|
279
|
+
const empty = result.view.values.length === 0;
|
|
280
|
+
const summary = series && !empty ? chartSummary(series, { type, rows: result.view.rows.map((f) => fieldLabel(f, labels.core)), valueNames, labels, locale }) : labels.noChartData;
|
|
281
|
+
return /* @__PURE__ */ React.createElement("div", { className: "pk-chart-wrap" }, /* @__PURE__ */ React.createElement("div", { className: "pk-chart-box" }, /* @__PURE__ */ React.createElement("div", { ref: el, className: "pk-chart", "data-testid": "pivot-chart", role: "img", "aria-label": result.view.chart.title ? `${labels.chart}: ${result.view.chart.title}` : labels.chart, "aria-describedby": summaryId }), /* @__PURE__ */ React.createElement("p", { id: summaryId, className: "pk-sr", "data-testid": "chart-summary" }, summary), !ready && !failed ? /* @__PURE__ */ React.createElement("div", { className: "pk-chart-note" }, labels.loadingChart) : null, failed ? /* @__PURE__ */ React.createElement("div", { className: "pk-chart-note pk-error" }, failed) : null, ready && empty ? /* @__PURE__ */ React.createElement("div", { className: "pk-chart-note" }, labels.noChartData) : null), ready && !empty && every > 1 ? /* @__PURE__ */ React.createElement("p", { className: "pk-axis-note", "data-testid": "axis-note" }, fill(labels.axisEvery, { n: every.toLocaleString(locale) })) : null);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/dnd.jsx
|
|
285
|
+
import React2, { createContext, useContext, useMemo, useState as useState2 } from "react";
|
|
286
|
+
import {
|
|
287
|
+
DndContext,
|
|
288
|
+
DragOverlay,
|
|
289
|
+
KeyboardSensor,
|
|
290
|
+
MouseSensor,
|
|
291
|
+
TouchSensor,
|
|
292
|
+
closestCenter,
|
|
293
|
+
pointerWithin,
|
|
294
|
+
rectIntersection,
|
|
295
|
+
useDraggable,
|
|
296
|
+
useDroppable,
|
|
297
|
+
useSensor,
|
|
298
|
+
useSensors
|
|
299
|
+
} from "@dnd-kit/core";
|
|
300
|
+
import { SortableContext, rectSortingStrategy, useSortable } from "@dnd-kit/sortable";
|
|
301
|
+
|
|
302
|
+
// src/dnd-moves.js
|
|
303
|
+
var ZONE_ORDER = ["filters", "cols", "rows", "values"];
|
|
304
|
+
function nextTarget(key, targets, over, active) {
|
|
305
|
+
const inZone = (zone2) => targets.filter((t) => t.zone === zone2).sort((a, b) => (a.kind === "zone" ? Infinity : a.index ?? 0) - (b.kind === "zone" ? Infinity : b.index ?? 0));
|
|
306
|
+
const endOf = (zone2) => inZone(zone2).find((t) => t.kind === "zone")?.id ?? null;
|
|
307
|
+
const zone = over?.zone ?? (active.kind === "chip" ? active.zone : null);
|
|
308
|
+
if (!zone) {
|
|
309
|
+
return endOf("rows");
|
|
310
|
+
}
|
|
311
|
+
if (key === "ArrowUp" || key === "ArrowDown") {
|
|
312
|
+
const at = ZONE_ORDER.indexOf(zone) + (key === "ArrowUp" ? -1 : 1);
|
|
313
|
+
return at >= 0 && at < ZONE_ORDER.length ? endOf(ZONE_ORDER[at]) : null;
|
|
314
|
+
}
|
|
315
|
+
const list = inZone(zone);
|
|
316
|
+
let pos = list.findIndex((t) => over && t.zone === over.zone && t.kind === over.kind && t.index === over.index);
|
|
317
|
+
if (pos === -1) {
|
|
318
|
+
const after = list.findIndex((t) => t.kind === "zone" || (t.index ?? 0) > (active.index ?? -1));
|
|
319
|
+
pos = key === "ArrowLeft" ? after : after - 1;
|
|
320
|
+
}
|
|
321
|
+
const next = list[pos + (key === "ArrowLeft" ? -1 : 1)];
|
|
322
|
+
return next ? next.id : null;
|
|
323
|
+
}
|
|
324
|
+
function announcementsOf(labels) {
|
|
325
|
+
const nameOf = (a) => a?.data?.current?.label ?? a?.data?.current?.field ?? "";
|
|
326
|
+
const where = (a, over, at, end, panel) => {
|
|
327
|
+
const d = over?.data?.current;
|
|
328
|
+
const field = nameOf(a);
|
|
329
|
+
if (!d) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
if (d.kind === "panel") {
|
|
333
|
+
return a?.data?.current?.kind === "field" ? null : fill(panel, { field });
|
|
334
|
+
}
|
|
335
|
+
const zone = labels.zones[d.zone] ?? d.zone;
|
|
336
|
+
if (d.kind === "chip") {
|
|
337
|
+
const same = a?.data?.current?.kind === "chip" && a.data.current.zone === d.zone;
|
|
338
|
+
const count = (d.count ?? d.index + 1) + (same ? 0 : 1);
|
|
339
|
+
return fill(at, { field, zone, position: d.index + 1, count });
|
|
340
|
+
}
|
|
341
|
+
return fill(end, { field, zone });
|
|
342
|
+
};
|
|
343
|
+
return {
|
|
344
|
+
onDragStart: ({ active: a }) => fill(labels.dragStart, { field: nameOf(a) }),
|
|
345
|
+
onDragOver: ({ active: a, over }) => where(a, over, labels.dragOverAt, labels.dragOverEnd, labels.dragRemove) ?? fill(labels.dragOverNone, { field: nameOf(a) }),
|
|
346
|
+
onDragEnd: ({ active: a, over }) => where(a, over, labels.dragEndAt, labels.dragEndEnd, labels.toastRemoved) ?? fill(labels.dragCancel, { field: nameOf(a) }),
|
|
347
|
+
onDragCancel: ({ active: a }) => fill(labels.dragCancel, { field: nameOf(a) })
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
// src/dnd.jsx
|
|
352
|
+
var DragContext = createContext({ active: (
|
|
353
|
+
/** @type {DragSource | null} */
|
|
354
|
+
null
|
|
355
|
+
) });
|
|
356
|
+
function useActiveDrag() {
|
|
357
|
+
return useContext(DragContext).active;
|
|
358
|
+
}
|
|
359
|
+
function collision(args) {
|
|
360
|
+
if (!args.pointerCoordinates) {
|
|
361
|
+
return closestCenter(args);
|
|
362
|
+
}
|
|
363
|
+
const hits = pointerWithin(args);
|
|
364
|
+
const list = hits.length ? hits : rectIntersection(args);
|
|
365
|
+
return [...list].sort((a, b) => Number(String(b.id).startsWith("chip:")) - Number(String(a.id).startsWith("chip:")));
|
|
366
|
+
}
|
|
367
|
+
function keyboardCoordinates(event, { context }) {
|
|
368
|
+
if (!["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(event.code)) {
|
|
369
|
+
return void 0;
|
|
370
|
+
}
|
|
371
|
+
event.preventDefault();
|
|
372
|
+
const activeId = context.active?.id;
|
|
373
|
+
const targets = context.droppableContainers.getEnabled().filter((entry) => entry && entry.id !== activeId && (entry.data?.current?.kind === "zone" || entry.data?.current?.kind === "chip")).map((entry) => ({ id: entry.id, zone: entry.data.current.zone, kind: entry.data.current.kind, index: entry.data.current.index }));
|
|
374
|
+
const over = context.over?.data?.current ?? null;
|
|
375
|
+
const id = nextTarget(event.code, targets, over, context.active?.data?.current ?? { kind: "field" });
|
|
376
|
+
const rect = id === null ? null : context.droppableRects.get(id);
|
|
377
|
+
const own2 = context.collisionRect;
|
|
378
|
+
if (!rect || !own2) {
|
|
379
|
+
return void 0;
|
|
380
|
+
}
|
|
381
|
+
return { x: rect.left + rect.width / 2 - own2.width / 2, y: rect.top + rect.height / 2 - own2.height / 2 };
|
|
382
|
+
}
|
|
383
|
+
function targetOf(source, over) {
|
|
384
|
+
const data = over?.data?.current;
|
|
385
|
+
if (!data) {
|
|
386
|
+
return null;
|
|
387
|
+
}
|
|
388
|
+
if (data.kind === "panel") {
|
|
389
|
+
return { zone: "panel" };
|
|
390
|
+
}
|
|
391
|
+
if (data.kind === "zone") {
|
|
392
|
+
return { zone: data.zone };
|
|
393
|
+
}
|
|
394
|
+
if (data.kind === "chip") {
|
|
395
|
+
return { zone: data.zone, index: data.index };
|
|
396
|
+
}
|
|
397
|
+
return null;
|
|
398
|
+
}
|
|
399
|
+
function PivotDnd({ labels, onDrop, onDragStart, renderOverlay, children }) {
|
|
400
|
+
const [active, setActive] = useState2(
|
|
401
|
+
/** @type {DragSource | null} */
|
|
402
|
+
null
|
|
403
|
+
);
|
|
404
|
+
const sensors = useSensors(
|
|
405
|
+
useSensor(MouseSensor, { activationConstraint: { distance: 5 } }),
|
|
406
|
+
useSensor(TouchSensor, { activationConstraint: { delay: 180, tolerance: 8 } }),
|
|
407
|
+
useSensor(KeyboardSensor, { coordinateGetter: keyboardCoordinates })
|
|
408
|
+
);
|
|
409
|
+
const accessibility = useMemo(() => ({ screenReaderInstructions: { draggable: labels.dragInstructions }, announcements: announcementsOf(labels) }), [labels]);
|
|
410
|
+
const reduced = typeof matchMedia === "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
411
|
+
return /* @__PURE__ */ React2.createElement(
|
|
412
|
+
DndContext,
|
|
413
|
+
{
|
|
414
|
+
sensors,
|
|
415
|
+
collisionDetection: collision,
|
|
416
|
+
accessibility,
|
|
417
|
+
autoScroll: { threshold: { x: 0.15, y: 0.15 }, acceleration: 14 },
|
|
418
|
+
onDragStart: (e) => {
|
|
419
|
+
const source = (
|
|
420
|
+
/** @type {DragSource} */
|
|
421
|
+
e.active.data.current
|
|
422
|
+
);
|
|
423
|
+
setActive(source);
|
|
424
|
+
onDragStart?.(source);
|
|
425
|
+
},
|
|
426
|
+
onDragCancel: () => setActive(null),
|
|
427
|
+
onDragEnd: (e) => {
|
|
428
|
+
const source = (
|
|
429
|
+
/** @type {DragSource} */
|
|
430
|
+
e.active.data.current
|
|
431
|
+
);
|
|
432
|
+
setActive(null);
|
|
433
|
+
const target = targetOf(source, e.over);
|
|
434
|
+
if (source && target) {
|
|
435
|
+
onDrop(source, target);
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
},
|
|
439
|
+
/* @__PURE__ */ React2.createElement(DragContext.Provider, { value: { active } }, children),
|
|
440
|
+
/* @__PURE__ */ React2.createElement(DragOverlay, { dropAnimation: reduced ? null : { duration: 160, easing: "cubic-bezier(.2,.8,.2,1)" }, zIndex: 1e3 }, active ? renderOverlay(active) : null)
|
|
441
|
+
);
|
|
442
|
+
}
|
|
443
|
+
function split(listeners2) {
|
|
444
|
+
const { onKeyDown, ...pointer } = listeners2 ?? {};
|
|
445
|
+
return { pointer, keyboard: onKeyDown ? { onKeyDown } : {} };
|
|
446
|
+
}
|
|
447
|
+
function useDragSource(id, source, disabled = false) {
|
|
448
|
+
const { setNodeRef, setActivatorNodeRef, attributes, listeners: listeners2, isDragging } = useDraggable({ id, data: source, disabled });
|
|
449
|
+
const { pointer, keyboard } = split(listeners2);
|
|
450
|
+
return { setNodeRef, isDragging, itemProps: pointer, handleProps: { ref: setActivatorNodeRef, ...attributes, ...keyboard } };
|
|
451
|
+
}
|
|
452
|
+
function useChip(id, source) {
|
|
453
|
+
const { setNodeRef, setActivatorNodeRef, attributes, listeners: listeners2, isDragging, transform, transition } = useSortable({ id, data: source });
|
|
454
|
+
const { pointer, keyboard } = split(listeners2);
|
|
455
|
+
const style = transform ? { transform: `translate3d(${Math.round(transform.x)}px, ${Math.round(transform.y)}px, 0)`, transition } : { transition };
|
|
456
|
+
return { setNodeRef, isDragging, style, itemProps: pointer, handleProps: { ref: setActivatorNodeRef, ...attributes, ...keyboard } };
|
|
457
|
+
}
|
|
458
|
+
function useDropTarget(id, data) {
|
|
459
|
+
const { setNodeRef, isOver } = useDroppable({ id, data });
|
|
460
|
+
return { setNodeRef, isOver };
|
|
461
|
+
}
|
|
462
|
+
function ChipList({ ids, children }) {
|
|
463
|
+
return /* @__PURE__ */ React2.createElement(SortableContext, { items: ids, strategy: rectSortingStrategy }, children);
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
// src/field-info.js
|
|
467
|
+
import { fieldDefaultsFromSchema } from "pivotkit-core";
|
|
468
|
+
var isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
469
|
+
var own = (o, k) => isObject(o) && Object.hasOwn(o, k) ? o[k] : void 0;
|
|
470
|
+
var TYPES = Object.freeze(["string", "number", "date", "boolean"]);
|
|
471
|
+
function fieldInfoOf(fieldDefaults) {
|
|
472
|
+
const map = /* @__PURE__ */ new Map();
|
|
473
|
+
if (!isObject(fieldDefaults)) {
|
|
474
|
+
return map;
|
|
475
|
+
}
|
|
476
|
+
const properties = {};
|
|
477
|
+
for (const name of Object.keys(
|
|
478
|
+
/** @type {object} */
|
|
479
|
+
fieldDefaults
|
|
480
|
+
)) {
|
|
481
|
+
const d = own(fieldDefaults, name);
|
|
482
|
+
const title = own(d, "label");
|
|
483
|
+
const description = own(d, "description");
|
|
484
|
+
const href = own(d, "href");
|
|
485
|
+
if (title !== void 0 || description !== void 0 || href !== void 0) {
|
|
486
|
+
Object.defineProperty(properties, name, { value: { title, description, externalDocs: { url: href } }, enumerable: true });
|
|
487
|
+
}
|
|
488
|
+
}
|
|
489
|
+
if (Object.keys(properties).length === 0) {
|
|
490
|
+
return map;
|
|
491
|
+
}
|
|
492
|
+
const clean = fieldDefaultsFromSchema({ properties }).defaults;
|
|
493
|
+
for (const name of Object.keys(clean)) {
|
|
494
|
+
const { label, description, href } = clean[name];
|
|
495
|
+
const info = {};
|
|
496
|
+
if (label) {
|
|
497
|
+
info.label = label;
|
|
498
|
+
}
|
|
499
|
+
if (description) {
|
|
500
|
+
info.description = description;
|
|
501
|
+
if (href) {
|
|
502
|
+
info.href = href;
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
if (Object.keys(info).length) {
|
|
506
|
+
map.set(name.toLowerCase(), info);
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
return map;
|
|
510
|
+
}
|
|
511
|
+
function displayNames(info, fieldNames = []) {
|
|
512
|
+
const spelling = new Map(fieldNames.map((n) => [String(n).toLowerCase(), String(n)]));
|
|
513
|
+
const uses = /* @__PURE__ */ new Map();
|
|
514
|
+
for (const entry of info.values()) {
|
|
515
|
+
if (entry.label) {
|
|
516
|
+
const l = entry.label.toLowerCase();
|
|
517
|
+
uses.set(l, (uses.get(l) ?? 0) + 1);
|
|
518
|
+
}
|
|
519
|
+
}
|
|
520
|
+
const out = {};
|
|
521
|
+
for (const [key, entry] of info) {
|
|
522
|
+
if (!entry.label) {
|
|
523
|
+
continue;
|
|
524
|
+
}
|
|
525
|
+
const l = entry.label.toLowerCase();
|
|
526
|
+
const clash = uses.get(l) > 1 || spelling.has(l) && l !== key;
|
|
527
|
+
const value = clash ? `${entry.label} (${spelling.get(key) ?? key})` : entry.label;
|
|
528
|
+
Object.defineProperty(out, key, { value, enumerable: true });
|
|
529
|
+
}
|
|
530
|
+
return Object.keys(out).length ? out : null;
|
|
531
|
+
}
|
|
532
|
+
function typesOf(fieldDefaults) {
|
|
533
|
+
if (!isObject(fieldDefaults)) {
|
|
534
|
+
return null;
|
|
535
|
+
}
|
|
536
|
+
const out = {};
|
|
537
|
+
for (const name of Object.keys(
|
|
538
|
+
/** @type {object} */
|
|
539
|
+
fieldDefaults
|
|
540
|
+
)) {
|
|
541
|
+
const type = own(own(fieldDefaults, name), "type");
|
|
542
|
+
if (typeof type === "string" && TYPES.includes(type)) {
|
|
543
|
+
Object.defineProperty(out, name, { value: type, enumerable: true });
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return Object.keys(out).length ? out : null;
|
|
547
|
+
}
|
|
548
|
+
function fieldMatches(field, query, info) {
|
|
549
|
+
if (!query) {
|
|
550
|
+
return true;
|
|
551
|
+
}
|
|
552
|
+
return [field, info?.label, info?.description].some((t) => typeof t === "string" && t.toLowerCase().includes(query));
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
// src/fields.jsx
|
|
556
|
+
import React3, { useCallback, useEffect as useEffect2, useId as useId2, useMemo as useMemo2, useRef as useRef2, useState as useState3 } from "react";
|
|
557
|
+
|
|
558
|
+
// src/rove.js
|
|
559
|
+
var SLOTS = Object.freeze(["handle", "name", "info", "menu"]);
|
|
560
|
+
function roveTarget(key, at, rows, slotsOf) {
|
|
561
|
+
if (rows <= 0) {
|
|
562
|
+
return null;
|
|
563
|
+
}
|
|
564
|
+
const fit = (row, slot) => ({ row, slot: slotsOf(row).includes(slot) ? slot : "name" });
|
|
565
|
+
if (key === "ArrowDown" || key === "ArrowUp") {
|
|
566
|
+
return fit(Math.max(0, Math.min(rows - 1, at.row + (key === "ArrowDown" ? 1 : -1))), at.slot);
|
|
567
|
+
}
|
|
568
|
+
if (key === "Home" || key === "End") {
|
|
569
|
+
return fit(key === "Home" ? 0 : rows - 1, at.slot);
|
|
570
|
+
}
|
|
571
|
+
if (key === "ArrowRight" || key === "ArrowLeft") {
|
|
572
|
+
const slots = slotsOf(at.row);
|
|
573
|
+
const i = Math.max(0, slots.indexOf(at.slot));
|
|
574
|
+
return { row: at.row, slot: slots[Math.max(0, Math.min(slots.length - 1, i + (key === "ArrowRight" ? 1 : -1)))] };
|
|
575
|
+
}
|
|
576
|
+
return null;
|
|
577
|
+
}
|
|
578
|
+
var opensMenu = (e) => e.key === "ContextMenu" || e.key === "F10" && e.shiftKey;
|
|
579
|
+
|
|
580
|
+
// src/fields.jsx
|
|
581
|
+
function FieldItem({ field, labels, zones, onAdd, onNote, onFilter, name, info, showInfo, stop }) {
|
|
582
|
+
const { setNodeRef, isDragging, itemProps, handleProps } = useDragSource(`field:${field.name}`, { kind: "field", field: field.name, type: field.type, label: name });
|
|
583
|
+
const item = useRef2(
|
|
584
|
+
/** @type {HTMLLIElement | null} */
|
|
585
|
+
null
|
|
586
|
+
);
|
|
587
|
+
const menu = useRef2(
|
|
588
|
+
/** @type {HTMLButtonElement | null} */
|
|
589
|
+
null
|
|
590
|
+
);
|
|
591
|
+
const ref = (el) => {
|
|
592
|
+
item.current = el;
|
|
593
|
+
setNodeRef(el);
|
|
594
|
+
};
|
|
595
|
+
const typeLabel = labels.types[field.type] ?? field.type;
|
|
596
|
+
const action = fieldAction(name, field.type, zones, labels);
|
|
597
|
+
const describedBy = useId2();
|
|
598
|
+
const slots = SLOTS.filter((x) => x !== "info" || info && showInfo);
|
|
599
|
+
const own2 = stop && slots.includes(stop) ? stop : stop ? "name" : null;
|
|
600
|
+
const tab = (slot) => own2 === slot ? 0 : -1;
|
|
601
|
+
return /* @__PURE__ */ React3.createElement("li", { className: `pk-field${isDragging ? " pk-dragging" : ""}${zones.length ? " pk-placed" : ""}`, ref, ...itemProps, "data-field": field.name }, /* @__PURE__ */ React3.createElement("span", { className: "pk-handle", ...handleProps, tabIndex: tab("handle"), "data-pk-slot": "handle", "aria-label": fill(labels.dragHandle, { field: name }), title: labels.dragIntoZone, onClick: () => menu.current?.click() }, /* @__PURE__ */ React3.createElement(Icon, { name: "grip", size: 18 })), /* @__PURE__ */ React3.createElement("span", { className: `pk-type pk-type-${field.type}`, title: typeLabel }, /* @__PURE__ */ React3.createElement(Icon, { name: (
|
|
602
|
+
/** @type {any} */
|
|
603
|
+
TYPE_ICON[field.type] ?? "text"
|
|
604
|
+
), size: 14 }), /* @__PURE__ */ React3.createElement("span", { className: "pk-sr" }, typeLabel)), /* @__PURE__ */ React3.createElement(
|
|
605
|
+
"button",
|
|
606
|
+
{
|
|
607
|
+
type: "button",
|
|
608
|
+
className: "pk-field-name",
|
|
609
|
+
tabIndex: tab("name"),
|
|
610
|
+
"data-pk-slot": "name",
|
|
611
|
+
onClick: () => {
|
|
612
|
+
if (action.kind) {
|
|
613
|
+
onAdd(field.name, action.zone);
|
|
614
|
+
} else {
|
|
615
|
+
onNote(fill(labels.alreadyIn, { field: name, zone: labels.zones[action.zone] }));
|
|
616
|
+
}
|
|
617
|
+
},
|
|
618
|
+
title: action.description ? `${action.name} \u2013 ${action.description}` : void 0,
|
|
619
|
+
"aria-label": zones.length ? action.name : void 0,
|
|
620
|
+
"aria-description": info ? void 0 : action.description || void 0,
|
|
621
|
+
"aria-describedby": info ? describedBy : void 0
|
|
622
|
+
},
|
|
623
|
+
/* @__PURE__ */ React3.createElement("span", { className: "pk-field-title", title: name }, name)
|
|
624
|
+
), 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: (
|
|
625
|
+
/** @type {any} */
|
|
626
|
+
ZONE_ICON[z]
|
|
627
|
+
), size: 12 })))) : null, info && showInfo ? /* @__PURE__ */ React3.createElement(InfoButton, { info, name, labels, tabIndex: tab("info"), slot: "info" }) : null, /* @__PURE__ */ React3.createElement(MenuButton, { label: fill(labels.fieldMenu, { field: name }), icon: "more", className: "pk-icon-btn pk-field-menu", testId: `field-menu-${field.name}`, buttonRef: menu, tabIndex: tab("menu"), slot: "menu" }, (close) => /* @__PURE__ */ React3.createElement(React3.Fragment, null, ZONES.map((zone) => /* @__PURE__ */ React3.createElement(
|
|
628
|
+
Option,
|
|
629
|
+
{
|
|
630
|
+
key: zone,
|
|
631
|
+
inMenu: true,
|
|
632
|
+
icon: zone === "values" ? "sigma" : zone === "filters" ? "filter" : zone,
|
|
633
|
+
onSelect: () => {
|
|
634
|
+
close();
|
|
635
|
+
onAdd(field.name, zone);
|
|
636
|
+
}
|
|
637
|
+
},
|
|
638
|
+
fill(zone === "values" && zones.includes("values") ? labels.addAgain : labels.addTo, { zone: labels.zones[zone] })
|
|
639
|
+
)), zones.length === 0 && onFilter ? /* @__PURE__ */ React3.createElement(
|
|
640
|
+
Option,
|
|
641
|
+
{
|
|
642
|
+
inMenu: true,
|
|
643
|
+
icon: "filter",
|
|
644
|
+
onSelect: () => {
|
|
645
|
+
close();
|
|
646
|
+
onFilter(field.name, item.current);
|
|
647
|
+
},
|
|
648
|
+
testId: `field-filter-${field.name}`
|
|
649
|
+
},
|
|
650
|
+
labels.filter
|
|
651
|
+
) : null)));
|
|
652
|
+
}
|
|
653
|
+
function FieldPanel({ fields, placed, labels, onAdd, onNote, onFilter, drawer, open, onClose, nameOf, info, showInfo = true, onSkip, collapsed = false, onCollapse }) {
|
|
654
|
+
const [query, setQuery] = useState3("");
|
|
655
|
+
const active = useActiveDrag();
|
|
656
|
+
const { setNodeRef, isOver } = useDropTarget("panel", { kind: "panel" });
|
|
657
|
+
const shown = useMemo2(() => {
|
|
658
|
+
const q = query.trim().toLowerCase();
|
|
659
|
+
return q ? fields.filter((f) => fieldMatches(f.name, q, info.get(f.name.toLowerCase()))) : fields;
|
|
660
|
+
}, [fields, query, info]);
|
|
661
|
+
const removing = active && active.kind !== "field";
|
|
662
|
+
const modal = drawer && open;
|
|
663
|
+
const el = useRef2(
|
|
664
|
+
/** @type {HTMLElement | null} */
|
|
665
|
+
null
|
|
666
|
+
);
|
|
667
|
+
const { onKeyDown } = useModal(el, modal, onClose, "[data-pk-opener='fields']");
|
|
668
|
+
const ref = (node) => {
|
|
669
|
+
el.current = node;
|
|
670
|
+
setNodeRef(node);
|
|
671
|
+
};
|
|
672
|
+
const refocus = useRef2(
|
|
673
|
+
/** @type {string | null} */
|
|
674
|
+
null
|
|
675
|
+
);
|
|
676
|
+
const rail = collapsed && !drawer;
|
|
677
|
+
useEffect2(() => {
|
|
678
|
+
const to = refocus.current;
|
|
679
|
+
refocus.current = null;
|
|
680
|
+
if (to && el.current) {
|
|
681
|
+
el.current.querySelector(`[data-pk-focus="${to}"], [data-pk-focus="${to}"] input`)?.focus();
|
|
682
|
+
}
|
|
683
|
+
}, [rail]);
|
|
684
|
+
const fold = (next, to) => {
|
|
685
|
+
refocus.current = to;
|
|
686
|
+
onCollapse?.(next);
|
|
687
|
+
};
|
|
688
|
+
const [stop, setStop] = useState3(
|
|
689
|
+
/** @type {{ field: string, slot: string } | null} */
|
|
690
|
+
null
|
|
691
|
+
);
|
|
692
|
+
const current = stop && shown.some((f) => f.name === stop.field) ? stop : shown.length ? { field: shown[0].name, slot: "name" } : null;
|
|
693
|
+
const list = useRef2(
|
|
694
|
+
/** @type {HTMLUListElement | null} */
|
|
695
|
+
null
|
|
696
|
+
);
|
|
697
|
+
const keysId = useId2();
|
|
698
|
+
const onFocus = useCallback((e) => {
|
|
699
|
+
const control = (
|
|
700
|
+
/** @type {HTMLElement} */
|
|
701
|
+
e.target.closest?.("[data-pk-slot]")
|
|
702
|
+
);
|
|
703
|
+
const row = control?.closest("[data-field]");
|
|
704
|
+
if (control && row && list.current?.contains(row)) {
|
|
705
|
+
setStop({ field: row.getAttribute("data-field") ?? "", slot: control.getAttribute("data-pk-slot") ?? "name" });
|
|
706
|
+
}
|
|
707
|
+
}, []);
|
|
708
|
+
const onListKey = (e) => {
|
|
709
|
+
const target = (
|
|
710
|
+
/** @type {HTMLElement} */
|
|
711
|
+
e.target
|
|
712
|
+
);
|
|
713
|
+
if (active || !list.current || !list.current.contains(target)) {
|
|
714
|
+
return;
|
|
715
|
+
}
|
|
716
|
+
const rows = (
|
|
717
|
+
/** @type {HTMLElement[]} */
|
|
718
|
+
[...list.current.querySelectorAll(":scope > [data-field]")]
|
|
719
|
+
);
|
|
720
|
+
const row = target.closest("[data-field]");
|
|
721
|
+
const at = { row: rows.indexOf(
|
|
722
|
+
/** @type {HTMLElement} */
|
|
723
|
+
row
|
|
724
|
+
), slot: target.closest("[data-pk-slot]")?.getAttribute("data-pk-slot") ?? "name" };
|
|
725
|
+
if (at.row < 0) {
|
|
726
|
+
return;
|
|
727
|
+
}
|
|
728
|
+
if (opensMenu(e)) {
|
|
729
|
+
e.preventDefault();
|
|
730
|
+
rows[at.row].querySelector("[data-pk-slot='menu']")?.click();
|
|
731
|
+
return;
|
|
732
|
+
}
|
|
733
|
+
const slotsOf = (i) => [...rows[i].querySelectorAll("[data-pk-slot]")].map((n) => n.getAttribute("data-pk-slot") ?? "");
|
|
734
|
+
const next = roveTarget(e.key, at, rows.length, slotsOf);
|
|
735
|
+
if (next) {
|
|
736
|
+
e.preventDefault();
|
|
737
|
+
rows[next.row].querySelector(`[data-pk-slot='${next.slot}']`)?.focus();
|
|
738
|
+
}
|
|
739
|
+
};
|
|
740
|
+
if (rail) {
|
|
741
|
+
return /* @__PURE__ */ React3.createElement("aside", { className: `pk-panel pk-rail${removing ? " pk-removing" : ""}${isOver && removing ? " pk-over" : ""}`, ref, "aria-label": labels.panel, "data-testid": "field-rail" }, /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-rail-open", "aria-expanded": false, "aria-label": labels.expandFields, title: labels.expandFields, onClick: () => fold(false, "collapse"), "data-pk-focus": "rail", "data-testid": "expand-fields" }, /* @__PURE__ */ React3.createElement("span", { className: "pk-rail-title", "aria-hidden": "true" }, removing ? labels.dropToRemove : labels.fields)), /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-icon-btn", "aria-label": labels.searchFields, title: labels.searchFields, onClick: () => fold(false, "search"), "data-testid": "rail-search" }, /* @__PURE__ */ React3.createElement(Icon, { name: "search" })), /* @__PURE__ */ React3.createElement("span", { className: "pk-sr", role: "status", "data-testid": "rail-status" }, removing ? labels.dropToRemove : ""));
|
|
742
|
+
}
|
|
743
|
+
return /* @__PURE__ */ React3.createElement(
|
|
744
|
+
"aside",
|
|
745
|
+
{
|
|
746
|
+
className: `pk-panel${removing ? " pk-removing" : ""}${isOver && removing ? " pk-over" : ""}`,
|
|
747
|
+
ref,
|
|
748
|
+
"aria-label": labels.panel,
|
|
749
|
+
role: modal ? "dialog" : void 0,
|
|
750
|
+
"aria-modal": modal ? true : void 0,
|
|
751
|
+
onKeyDown: modal ? onKeyDown : void 0
|
|
752
|
+
},
|
|
753
|
+
onSkip && !drawer ? /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-skip", onClick: onSkip, "data-testid": "skip-to-toolbar" }, labels.skipToToolbar) : null,
|
|
754
|
+
/* @__PURE__ */ React3.createElement("div", { className: "pk-panel-head" }, /* @__PURE__ */ React3.createElement("h2", { className: "pk-panel-title" }, labels.fields), onCollapse && !drawer ? /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-icon-btn", "aria-expanded": true, "aria-label": labels.collapseFields, title: labels.collapseFields, onClick: () => fold(true, "rail"), "data-pk-focus": "collapse", "data-testid": "collapse-fields" }, /* @__PURE__ */ React3.createElement("span", { "aria-hidden": "true" }, "\xAB")) : null, drawer ? /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-icon-btn", onClick: onClose, "aria-label": labels.hideFields, title: labels.hideFields }, /* @__PURE__ */ React3.createElement(Icon, { name: "x" })) : null),
|
|
755
|
+
/* @__PURE__ */ React3.createElement("p", { className: "pk-hint" }, labels.fieldsHint),
|
|
756
|
+
/* @__PURE__ */ React3.createElement("label", { className: "pk-search", "data-pk-focus": "search" }, /* @__PURE__ */ React3.createElement(Icon, { name: "search" }), /* @__PURE__ */ React3.createElement("span", { className: "pk-sr" }, labels.searchFields), /* @__PURE__ */ React3.createElement(ClearInput, { type: "search", value: query, placeholder: labels.searchFields, onChange: setQuery, clearLabel: labels.clearText, "data-autofocus": "", "data-testid": "field-search" })),
|
|
757
|
+
/* @__PURE__ */ React3.createElement("ul", { className: "pk-field-list", ref: list, role: "list", "aria-label": labels.fields, "aria-describedby": keysId, onFocus, onKeyDown: onListKey, "data-testid": "field-list" }, shown.map((f) => /* @__PURE__ */ React3.createElement(
|
|
758
|
+
FieldItem,
|
|
759
|
+
{
|
|
760
|
+
key: f.name,
|
|
761
|
+
field: f,
|
|
762
|
+
labels,
|
|
763
|
+
zones: placed.get(f.name.toLowerCase()) ?? [],
|
|
764
|
+
onAdd,
|
|
765
|
+
onNote,
|
|
766
|
+
onFilter,
|
|
767
|
+
showInfo,
|
|
768
|
+
stop: current && current.field === f.name ? current.slot : null,
|
|
769
|
+
name: nameOf(f.name),
|
|
770
|
+
info: info.get(f.name.toLowerCase())?.description ? info.get(f.name.toLowerCase()) : void 0
|
|
771
|
+
}
|
|
772
|
+
))),
|
|
773
|
+
/* @__PURE__ */ React3.createElement("p", { id: keysId, hidden: true }, labels.fieldListKeys),
|
|
774
|
+
shown.length === 0 ? /* @__PURE__ */ React3.createElement("p", { className: "pk-hint" }, fields.length ? fill(labels.noFieldMatch, { query }) : labels.emptyFields) : null,
|
|
775
|
+
removing ? /* @__PURE__ */ React3.createElement("div", { className: "pk-remove-hint", "aria-hidden": "true" }, /* @__PURE__ */ React3.createElement(Icon, { name: "trash" }), " ", labels.dropToRemove) : null
|
|
776
|
+
);
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
// src/lazy-menus.jsx
|
|
780
|
+
import React4, { useEffect as useEffect3, useRef as useRef3, useState as useState4 } from "react";
|
|
781
|
+
|
|
782
|
+
// src/menu-texts.js
|
|
783
|
+
var MENU_TEXTS_OF = Object.freeze({ de: () => import("./menu-texts-de.js").then((m) => m.de) });
|
|
784
|
+
|
|
785
|
+
// src/lazy-menus.jsx
|
|
786
|
+
var pending = null;
|
|
787
|
+
var loaded = null;
|
|
788
|
+
var textsPending = /* @__PURE__ */ new Map();
|
|
789
|
+
var textsFailed = /* @__PURE__ */ new Set();
|
|
790
|
+
var listeners = /* @__PURE__ */ new Set();
|
|
791
|
+
function onMenuTexts(listener) {
|
|
792
|
+
listeners.add(listener);
|
|
793
|
+
return () => void listeners.delete(listener);
|
|
794
|
+
}
|
|
795
|
+
var wantsTexts = (lang) => Object.hasOwn(MENU_TEXTS_OF, lang) && !loaded?.hasMenuTexts(lang);
|
|
796
|
+
function loadMenus(lang = "en") {
|
|
797
|
+
pending ??= import("./menus.js").then(
|
|
798
|
+
(m) => {
|
|
799
|
+
loaded = m;
|
|
800
|
+
return m;
|
|
801
|
+
},
|
|
802
|
+
(error) => {
|
|
803
|
+
pending = null;
|
|
804
|
+
throw error;
|
|
805
|
+
}
|
|
806
|
+
);
|
|
807
|
+
const menus = pending;
|
|
808
|
+
if (!wantsTexts(lang)) {
|
|
809
|
+
return menus;
|
|
810
|
+
}
|
|
811
|
+
let texts = textsPending.get(lang);
|
|
812
|
+
if (!texts) {
|
|
813
|
+
const done = () => listeners.forEach((f) => f());
|
|
814
|
+
texts = Promise.all([menus, MENU_TEXTS_OF[lang]()]).then(
|
|
815
|
+
([m, t]) => {
|
|
816
|
+
m.addMenuTexts(lang, t);
|
|
817
|
+
textsFailed.delete(lang);
|
|
818
|
+
done();
|
|
819
|
+
},
|
|
820
|
+
() => {
|
|
821
|
+
textsPending.delete(lang);
|
|
822
|
+
textsFailed.add(lang);
|
|
823
|
+
done();
|
|
824
|
+
}
|
|
825
|
+
);
|
|
826
|
+
textsPending.set(lang, texts);
|
|
827
|
+
}
|
|
828
|
+
return texts.then(() => menus);
|
|
829
|
+
}
|
|
830
|
+
var menusNow = (lang = "en") => loaded && (!wantsTexts(lang) || textsFailed.has(lang)) ? loaded : null;
|
|
831
|
+
function Loading({ text }) {
|
|
832
|
+
const [say, setSay] = useState4(false);
|
|
833
|
+
useEffect3(() => {
|
|
834
|
+
const t = setTimeout(() => setSay(true), 0);
|
|
835
|
+
return () => clearTimeout(t);
|
|
836
|
+
}, []);
|
|
837
|
+
return /* @__PURE__ */ React4.createElement("p", { className: "pk-hint pk-menu-loading", role: "status" }, say ? text : null);
|
|
838
|
+
}
|
|
839
|
+
function focusFirst(el) {
|
|
840
|
+
const popover = el.closest(".pk-popover");
|
|
841
|
+
const now = activeIn(el);
|
|
842
|
+
if (popover && (now === popover || !now || !popover.contains(now))) {
|
|
843
|
+
const first = (
|
|
844
|
+
/** @type {HTMLElement | null} */
|
|
845
|
+
popover.querySelector("[data-autofocus], [data-pk-option]:not([disabled]), button:not([disabled])")
|
|
846
|
+
);
|
|
847
|
+
first?.focus({ preventScroll: true });
|
|
848
|
+
}
|
|
849
|
+
}
|
|
850
|
+
function MenuPanel({ name, loadingText, props }) {
|
|
851
|
+
const labels = props.labels;
|
|
852
|
+
const lang = labels?.lang;
|
|
853
|
+
const [, setLoads] = useState4(0);
|
|
854
|
+
useEffect3(() => onMenuTexts(() => setLoads((n) => n + 1)), []);
|
|
855
|
+
const mod = menusNow(lang);
|
|
856
|
+
const current = mod && labels ? mod.menuLabels(labels) : null;
|
|
857
|
+
const [kept, setKept] = useState4(
|
|
858
|
+
/** @type {any} */
|
|
859
|
+
null
|
|
860
|
+
);
|
|
861
|
+
if (current && current !== kept) {
|
|
862
|
+
setKept(current);
|
|
863
|
+
}
|
|
864
|
+
const [failed, setFailed] = useState4(false);
|
|
865
|
+
const [attempt, setAttempt] = useState4(0);
|
|
866
|
+
const box = useRef3(
|
|
867
|
+
/** @type {HTMLDivElement | null} */
|
|
868
|
+
null
|
|
869
|
+
);
|
|
870
|
+
const late = useRef3(false);
|
|
871
|
+
const tried = useRef3(
|
|
872
|
+
/** @type {string | undefined | null} */
|
|
873
|
+
null
|
|
874
|
+
);
|
|
875
|
+
useEffect3(() => {
|
|
876
|
+
if (mod && (!wantsTexts(lang) || tried.current === lang)) {
|
|
877
|
+
return void 0;
|
|
878
|
+
}
|
|
879
|
+
tried.current = lang;
|
|
880
|
+
late.current = !mod;
|
|
881
|
+
let live = true;
|
|
882
|
+
loadMenus(lang).then(
|
|
883
|
+
() => {
|
|
884
|
+
if (live) {
|
|
885
|
+
setFailed(false);
|
|
886
|
+
setLoads((n) => n + 1);
|
|
887
|
+
}
|
|
888
|
+
},
|
|
889
|
+
() => {
|
|
890
|
+
if (live) {
|
|
891
|
+
setFailed(true);
|
|
892
|
+
}
|
|
893
|
+
}
|
|
894
|
+
);
|
|
895
|
+
return () => {
|
|
896
|
+
live = false;
|
|
897
|
+
};
|
|
898
|
+
}, [mod, attempt, lang]);
|
|
899
|
+
useEffect3(() => {
|
|
900
|
+
if (box.current && (mod && late.current || failed)) {
|
|
901
|
+
focusFirst(box.current);
|
|
902
|
+
}
|
|
903
|
+
}, [mod, failed]);
|
|
904
|
+
const shown = mod ?? (kept ? menusNow() : null);
|
|
905
|
+
const Panel = shown ? (
|
|
906
|
+
/** @type {any} */
|
|
907
|
+
shown[name]
|
|
908
|
+
) : null;
|
|
909
|
+
return /* @__PURE__ */ React4.createElement("div", { className: "pk-menu-panel", ref: box }, Panel ? (
|
|
910
|
+
// the menus' own texts (menu-labels.js) come with them, under the report's labels
|
|
911
|
+
/* @__PURE__ */ React4.createElement(Panel, { ...props, labels: current ?? kept ?? labels })
|
|
912
|
+
) : 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(
|
|
913
|
+
"button",
|
|
914
|
+
{
|
|
915
|
+
type: "button",
|
|
916
|
+
className: "pk-btn pk-small-btn",
|
|
917
|
+
"data-autofocus": "",
|
|
918
|
+
"data-testid": "menu-retry",
|
|
919
|
+
onClick: () => {
|
|
920
|
+
setFailed(false);
|
|
921
|
+
setAttempt((n) => n + 1);
|
|
922
|
+
}
|
|
923
|
+
},
|
|
924
|
+
labels.tryAgain
|
|
925
|
+
)) : loadingText ? /* @__PURE__ */ React4.createElement(Loading, { text: loadingText }) : null);
|
|
926
|
+
}
|
|
927
|
+
|
|
928
|
+
// src/skeleton.jsx
|
|
929
|
+
import React5 from "react";
|
|
930
|
+
var ROWS = 6;
|
|
931
|
+
function Skeleton({ text, full = false }) {
|
|
932
|
+
const rows = /* @__PURE__ */ React5.createElement("div", { className: "pk-skel-table", "aria-hidden": "true" }, Array.from({ length: ROWS }, (_, i) => /* @__PURE__ */ React5.createElement("div", { key: i, className: "pk-skel-row" }, /* @__PURE__ */ React5.createElement("span", { className: "pk-skel pk-skel-cell pk-skel-head" }), /* @__PURE__ */ React5.createElement("span", { className: "pk-skel pk-skel-cell" }), /* @__PURE__ */ React5.createElement("span", { className: "pk-skel pk-skel-cell" }), /* @__PURE__ */ React5.createElement("span", { className: "pk-skel pk-skel-cell" }))));
|
|
933
|
+
return /* @__PURE__ */ React5.createElement("div", { className: full ? "pk-skeleton pk-skeleton-full" : "pk-skeleton", role: "status", "data-testid": "skeleton" }, /* @__PURE__ */ React5.createElement("span", { className: "pk-sr" }, text), full ? /* @__PURE__ */ React5.createElement("div", { className: "pk-skel-layout", "aria-hidden": "true" }, /* @__PURE__ */ React5.createElement("div", { className: "pk-skel-panel" }, /* @__PURE__ */ React5.createElement("span", { className: "pk-skel pk-skel-title" }), Array.from({ length: 7 }, (_, i) => /* @__PURE__ */ React5.createElement("span", { key: i, className: "pk-skel pk-skel-field" }))), /* @__PURE__ */ React5.createElement("div", { className: "pk-skel-main" }, /* @__PURE__ */ React5.createElement("div", { className: "pk-skel-toolbar" }, /* @__PURE__ */ React5.createElement("span", { className: "pk-skel pk-skel-btn pk-skel-wide" }), /* @__PURE__ */ React5.createElement("span", { className: "pk-skel pk-skel-btn" }), /* @__PURE__ */ React5.createElement("span", { className: "pk-skel pk-skel-btn" }), /* @__PURE__ */ React5.createElement("span", { className: "pk-skel-grow" }), /* @__PURE__ */ React5.createElement("span", { className: "pk-skel pk-skel-btn" })), /* @__PURE__ */ React5.createElement("div", { className: "pk-skel-zones" }, Array.from({ length: 4 }, (_, i) => /* @__PURE__ */ React5.createElement("span", { key: i, className: "pk-skel pk-skel-zone" }))), rows)) : rows);
|
|
934
|
+
}
|
|
935
|
+
|
|
936
|
+
// src/table.jsx
|
|
937
|
+
import React6, { useCallback as useCallback2, useEffect as useEffect4, useMemo as useMemo3, useRef as useRef4, useState as useState5 } from "react";
|
|
938
|
+
import { fieldLabel as fieldLabel2 } from "pivotkit-core";
|
|
939
|
+
|
|
940
|
+
// src/virtual.js
|
|
941
|
+
var VIRTUAL_FROM = 300;
|
|
942
|
+
function windowOf({ count, scrollTop, viewport, rowHeight, overscan = 12 }) {
|
|
943
|
+
const h = Math.max(1, rowHeight);
|
|
944
|
+
const first = Math.floor(Math.max(0, scrollTop) / h);
|
|
945
|
+
const start = Math.max(0, Math.min(count, first - overscan));
|
|
946
|
+
const end = Math.max(start, Math.min(count, first + Math.ceil(Math.max(0, viewport) / h) + overscan));
|
|
947
|
+
return { start, end, padTop: start * h, padBottom: (count - end) * h };
|
|
948
|
+
}
|
|
949
|
+
function sliceRows(grid, start, end) {
|
|
950
|
+
const h = grid.headerRows;
|
|
951
|
+
const out = [];
|
|
952
|
+
for (let r = start; r < end; r++) {
|
|
953
|
+
const row = grid.rows[h + r];
|
|
954
|
+
const cells = [];
|
|
955
|
+
row.forEach((cell, col) => {
|
|
956
|
+
if (cell) {
|
|
957
|
+
cells.push({ cell, col, rowSpan: Math.min(cell.rowSpan ?? 1, end - r), colSpan: cell.colSpan ?? 1 });
|
|
958
|
+
}
|
|
959
|
+
});
|
|
960
|
+
out.push({ index: r, cells });
|
|
961
|
+
}
|
|
962
|
+
if (start > 0 && out.length > 0) {
|
|
963
|
+
const first = out[0].cells;
|
|
964
|
+
for (const m of grid.merges) {
|
|
965
|
+
const top = m.row - h;
|
|
966
|
+
if (top >= 0 && top < start && top + m.rowSpan > start) {
|
|
967
|
+
const cell = grid.rows[m.row][m.col];
|
|
968
|
+
first.push({ cell, col: m.col, rowSpan: Math.min(top + m.rowSpan, end) - start, colSpan: m.colSpan });
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
first.sort((a, b) => a.col - b.col);
|
|
972
|
+
}
|
|
973
|
+
return out;
|
|
974
|
+
}
|
|
975
|
+
function rowLabelOf(grid, r) {
|
|
976
|
+
const row = grid.headerRows + r;
|
|
977
|
+
const texts = [];
|
|
978
|
+
for (let c = 0; c < grid.rowHeaderColumns; c++) {
|
|
979
|
+
const own2 = grid.rows[row]?.[c];
|
|
980
|
+
const merge = own2 ? null : grid.merges.find((m) => m.row <= row && row < m.row + m.rowSpan && m.col <= c && c < m.col + m.colSpan);
|
|
981
|
+
const cell = own2 ?? (merge && merge.col === c ? grid.rows[merge.row][merge.col] : null);
|
|
982
|
+
if (cell && cell.text) {
|
|
983
|
+
texts.push(cell.text);
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
return texts.join(" / ");
|
|
987
|
+
}
|
|
988
|
+
|
|
989
|
+
// src/table.jsx
|
|
990
|
+
var totalClass = (t) => t === 2 ? " pk-grand" : t === 1 ? " pk-sub" : "";
|
|
991
|
+
function conditionalStyle(cell) {
|
|
992
|
+
const s = cell.style;
|
|
993
|
+
if (!s) {
|
|
994
|
+
return void 0;
|
|
995
|
+
}
|
|
996
|
+
if (s.scale !== void 0 && s.color) {
|
|
997
|
+
return { "--pk-cell-bg": s.color };
|
|
998
|
+
}
|
|
999
|
+
if (s.scale !== void 0) {
|
|
1000
|
+
const t = Math.max(0, Math.min(1, s.scale));
|
|
1001
|
+
const [from, to, part] = t < 0.5 ? ["--pk-scale-low", "--pk-scale-mid", t * 2] : ["--pk-scale-mid", "--pk-scale-high", (t - 0.5) * 2];
|
|
1002
|
+
return { "--pk-cell-bg": `color-mix(in srgb, var(${to}) ${Math.round(part * 100)}%, var(${from}))` };
|
|
1003
|
+
}
|
|
1004
|
+
if (s.bar !== void 0) {
|
|
1005
|
+
return { "--pk-bar": `${Math.round(s.bar * 1e3) / 10}%`, ...s.color ? { "--pk-bar-color": s.color } : {} };
|
|
1006
|
+
}
|
|
1007
|
+
return void 0;
|
|
1008
|
+
}
|
|
1009
|
+
var drillable = (cell) => cell.valueIndex !== void 0 && cell.hasRows !== false;
|
|
1010
|
+
function firstValueCell(grid) {
|
|
1011
|
+
for (let r = 0; r < grid.rows.length - grid.headerRows; r++) {
|
|
1012
|
+
const c = grid.rows[grid.headerRows + r].findIndex((cell) => cell && cell.kind === "value" && cell.valueIndex !== void 0);
|
|
1013
|
+
if (c !== -1) {
|
|
1014
|
+
return { r, c };
|
|
1015
|
+
}
|
|
1016
|
+
}
|
|
1017
|
+
return null;
|
|
1018
|
+
}
|
|
1019
|
+
function DraggableHeader({ cell, source, children, className, style, colSpan, rowSpan, scope, description, tooltip = true, sort }) {
|
|
1020
|
+
const { setNodeRef, isDragging, itemProps } = useDragSource(`table:${source.zone}:${source.index}:${source.field ?? ""}`, source);
|
|
1021
|
+
return /* @__PURE__ */ React6.createElement("th", { ref: setNodeRef, ...itemProps, className: `${className} pk-draggable${isDragging ? " pk-dragging" : ""}`, style, colSpan, rowSpan, scope, "data-kind": cell.kind, title: tooltip ? description : void 0, "aria-description": description, "aria-sort": sort ?? void 0 }, children, /* @__PURE__ */ React6.createElement(Icon, { name: "grip", size: 12, className: "pk-th-grip" }));
|
|
1022
|
+
}
|
|
1023
|
+
var toggleKey = (axis, path) => `${axis}:${JSON.stringify(path)}`;
|
|
1024
|
+
function Toggle({ toggle, text, labels, onToggle }) {
|
|
1025
|
+
const name = fill(toggle.collapsed ? labels.expand : labels.collapse, { label: text });
|
|
1026
|
+
return /* @__PURE__ */ React6.createElement("button", { type: "button", className: `pk-toggle${toggle.collapsed ? "" : " pk-open"}`, "aria-expanded": !toggle.collapsed, "aria-label": name, title: name, "data-pk-toggle": toggleKey(toggle.axis, toggle.path), onClick: () => onToggle(toggle.axis, toggle.path) }, /* @__PURE__ */ React6.createElement(Icon, { name: "chevronRight", size: 16 }));
|
|
1027
|
+
}
|
|
1028
|
+
function PivotTable({ grid, view, labels, onToggle: toggleGroup, onCell, version, hintId, onRowLabel, infoOf, showInfo = true, typeOf = () => void 0, hostOrdered = () => false, onSort }) {
|
|
1029
|
+
const wrap = useRef4(
|
|
1030
|
+
/** @type {HTMLDivElement | null} */
|
|
1031
|
+
null
|
|
1032
|
+
);
|
|
1033
|
+
const table = useRef4(
|
|
1034
|
+
/** @type {HTMLTableElement | null} */
|
|
1035
|
+
null
|
|
1036
|
+
);
|
|
1037
|
+
const bodyCount = grid.rows.length - grid.headerRows;
|
|
1038
|
+
const virtual = bodyCount >= VIRTUAL_FROM;
|
|
1039
|
+
const [scroll, setScroll] = useState5({ top: 0, height: 600 });
|
|
1040
|
+
const [rowHeight, setRowHeight] = useState5(34);
|
|
1041
|
+
const [lefts, setLefts] = useState5(
|
|
1042
|
+
/** @type {number[]} */
|
|
1043
|
+
[]
|
|
1044
|
+
);
|
|
1045
|
+
const [tops, setTops] = useState5(
|
|
1046
|
+
/** @type {number[]} */
|
|
1047
|
+
[]
|
|
1048
|
+
);
|
|
1049
|
+
const [headHeight, setHeadHeight] = useState5(0);
|
|
1050
|
+
const [width, setWidth] = useState5(0);
|
|
1051
|
+
const [active, setActive] = useState5(
|
|
1052
|
+
/** @type {{ r: number, c: number } | null} */
|
|
1053
|
+
null
|
|
1054
|
+
);
|
|
1055
|
+
const focusNext = useRef4(false);
|
|
1056
|
+
const [sortNote, setSortNote] = useState5("");
|
|
1057
|
+
const focusToggle = useRef4(
|
|
1058
|
+
/** @type {string | null} */
|
|
1059
|
+
null
|
|
1060
|
+
);
|
|
1061
|
+
const onToggle = useCallback2(
|
|
1062
|
+
(axis, path) => {
|
|
1063
|
+
focusToggle.current = toggleKey(axis, path);
|
|
1064
|
+
toggleGroup(axis, path);
|
|
1065
|
+
},
|
|
1066
|
+
[toggleGroup]
|
|
1067
|
+
);
|
|
1068
|
+
useIsoLayoutEffect(() => {
|
|
1069
|
+
const t = table.current;
|
|
1070
|
+
if (!t) {
|
|
1071
|
+
return;
|
|
1072
|
+
}
|
|
1073
|
+
const row = t.tBodies[0]?.querySelector("tr[data-r]");
|
|
1074
|
+
if (row && row.getBoundingClientRect().height > 0) {
|
|
1075
|
+
setRowHeight(row.getBoundingClientRect().height);
|
|
1076
|
+
}
|
|
1077
|
+
const headRows = t.tHead ? [...t.tHead.rows] : [];
|
|
1078
|
+
setHeadHeight(t.tHead ? t.tHead.offsetHeight : 0);
|
|
1079
|
+
const top = t.tHead ? t.tHead.getBoundingClientRect().top : 0;
|
|
1080
|
+
const ys = headRows.map((tr) => tr.getBoundingClientRect().top - top);
|
|
1081
|
+
setTops((old) => old.length === ys.length && old.every((v, i) => Math.abs(v - ys[i]) < 0.01) ? old : ys);
|
|
1082
|
+
const last = headRows[headRows.length - 1];
|
|
1083
|
+
if (last) {
|
|
1084
|
+
const xs = [];
|
|
1085
|
+
let x = 0;
|
|
1086
|
+
for (let c = 0; c < grid.rowHeaderColumns && c < last.cells.length; c++) {
|
|
1087
|
+
xs.push(x);
|
|
1088
|
+
x += last.cells[c].getBoundingClientRect().width;
|
|
1089
|
+
}
|
|
1090
|
+
setLefts((old) => old.length === xs.length && old.every((v, i) => Math.abs(v - xs[i]) < 0.5) ? old : xs);
|
|
1091
|
+
}
|
|
1092
|
+
}, [grid, version, width]);
|
|
1093
|
+
useEffect4(() => {
|
|
1094
|
+
const el = wrap.current;
|
|
1095
|
+
if (!el) {
|
|
1096
|
+
return void 0;
|
|
1097
|
+
}
|
|
1098
|
+
const update = () => {
|
|
1099
|
+
setScroll({ top: el.scrollTop, height: el.clientHeight });
|
|
1100
|
+
setWidth(el.clientWidth);
|
|
1101
|
+
};
|
|
1102
|
+
update();
|
|
1103
|
+
const ro = typeof ResizeObserver === "function" ? new ResizeObserver(update) : null;
|
|
1104
|
+
ro?.observe(el);
|
|
1105
|
+
return () => ro?.disconnect();
|
|
1106
|
+
}, []);
|
|
1107
|
+
const head = headHeight || rowHeight * grid.headerRows;
|
|
1108
|
+
const win = virtual ? windowOf({ count: bodyCount, scrollTop: scroll.top - head, viewport: scroll.height, rowHeight }) : { start: 0, end: bodyCount, padTop: 0, padBottom: 0 };
|
|
1109
|
+
const rows = useMemo3(() => sliceRows(grid, win.start, win.end), [grid, win.start, win.end]);
|
|
1110
|
+
const [shownRow, setLabelRow] = useState5(
|
|
1111
|
+
/** @type {{ r: number, span: number, grid: unknown } | null} */
|
|
1112
|
+
null
|
|
1113
|
+
);
|
|
1114
|
+
const labelRow = shownRow && shownRow.grid === grid ? shownRow : null;
|
|
1115
|
+
useEffect4(() => {
|
|
1116
|
+
onRowLabel?.(null);
|
|
1117
|
+
}, [grid, onRowLabel]);
|
|
1118
|
+
const showRowLabel = virtual && onRowLabel ? (r, span = 1) => {
|
|
1119
|
+
setLabelRow({ r, span, grid });
|
|
1120
|
+
onRowLabel(rowLabelOf(grid, r));
|
|
1121
|
+
} : void 0;
|
|
1122
|
+
const clearRowLabel = () => {
|
|
1123
|
+
if (labelRow !== null) {
|
|
1124
|
+
setLabelRow(null);
|
|
1125
|
+
onRowLabel?.(null);
|
|
1126
|
+
}
|
|
1127
|
+
};
|
|
1128
|
+
const onScroll = (e) => {
|
|
1129
|
+
const box = e.currentTarget;
|
|
1130
|
+
setScroll({ top: box.scrollTop, height: box.clientHeight });
|
|
1131
|
+
const row = labelRow;
|
|
1132
|
+
if (row !== null) {
|
|
1133
|
+
const y = head + row.r * rowHeight - box.scrollTop;
|
|
1134
|
+
if (y + row.span * rowHeight <= head || y >= box.clientHeight) {
|
|
1135
|
+
clearRowLabel();
|
|
1136
|
+
}
|
|
1137
|
+
}
|
|
1138
|
+
};
|
|
1139
|
+
const onBlur = (e) => {
|
|
1140
|
+
if (!(e.relatedTarget instanceof Node && e.currentTarget.contains(e.relatedTarget))) {
|
|
1141
|
+
clearRowLabel();
|
|
1142
|
+
}
|
|
1143
|
+
};
|
|
1144
|
+
const firstValue = useMemo3(() => firstValueCell(grid), [grid]);
|
|
1145
|
+
const current = active && active.r < bodyCount && grid.rows[grid.headerRows + active.r]?.[active.c]?.kind === "value" ? active : firstValue;
|
|
1146
|
+
const move = (dr, dc) => {
|
|
1147
|
+
if (!current) {
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
let { r, c } = current;
|
|
1151
|
+
const valueAt = (rr, cc) => {
|
|
1152
|
+
const cell = grid.rows[grid.headerRows + rr]?.[cc];
|
|
1153
|
+
return cell && cell.kind === "value" && cell.valueIndex !== void 0;
|
|
1154
|
+
};
|
|
1155
|
+
for (let step = 0; step < Math.max(bodyCount, grid.columnCount); step++) {
|
|
1156
|
+
r += dr;
|
|
1157
|
+
c += dc;
|
|
1158
|
+
if (r < 0 || r >= bodyCount || c < grid.rowHeaderColumns || c >= grid.columnCount) {
|
|
1159
|
+
return;
|
|
1160
|
+
}
|
|
1161
|
+
if (valueAt(r, c)) {
|
|
1162
|
+
break;
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
if (!valueAt(r, c)) {
|
|
1166
|
+
return;
|
|
1167
|
+
}
|
|
1168
|
+
focusNext.current = true;
|
|
1169
|
+
setActive({ r, c });
|
|
1170
|
+
const el = wrap.current;
|
|
1171
|
+
if (virtual && el) {
|
|
1172
|
+
const y = (grid.headerRows + r) * rowHeight;
|
|
1173
|
+
if (y < el.scrollTop + rowHeight * grid.headerRows || y + rowHeight > el.scrollTop + el.clientHeight) {
|
|
1174
|
+
el.scrollTop = Math.max(0, y - el.clientHeight / 2);
|
|
1175
|
+
}
|
|
1176
|
+
}
|
|
1177
|
+
};
|
|
1178
|
+
useEffect4(() => {
|
|
1179
|
+
const key = focusToggle.current;
|
|
1180
|
+
if (key && table.current) {
|
|
1181
|
+
focusToggle.current = null;
|
|
1182
|
+
const button = [...table.current.querySelectorAll("button[data-pk-toggle]")].find((b) => b.getAttribute("data-pk-toggle") === key);
|
|
1183
|
+
button?.focus({ preventScroll: true });
|
|
1184
|
+
}
|
|
1185
|
+
if (focusNext.current && current) {
|
|
1186
|
+
focusNext.current = false;
|
|
1187
|
+
const td = table.current?.querySelector(`td[data-r="${current.r}"][data-c="${current.c}"]`);
|
|
1188
|
+
td?.focus({ preventScroll: false });
|
|
1189
|
+
}
|
|
1190
|
+
});
|
|
1191
|
+
const onKeyDown = (e) => {
|
|
1192
|
+
const keys = { ArrowDown: [1, 0], ArrowUp: [-1, 0], ArrowRight: [0, 1], ArrowLeft: [0, -1] };
|
|
1193
|
+
if (keys[e.key] && e.target instanceof HTMLTableCellElement) {
|
|
1194
|
+
e.preventDefault();
|
|
1195
|
+
const [dr, dc] = keys[e.key];
|
|
1196
|
+
move(dr, dc);
|
|
1197
|
+
} else if ((e.key === "Enter" || e.key === " ") && e.target instanceof HTMLTableCellElement && current) {
|
|
1198
|
+
e.preventDefault();
|
|
1199
|
+
const cell = grid.rows[grid.headerRows + current.r][current.c];
|
|
1200
|
+
if (cell && drillable(cell)) {
|
|
1201
|
+
onCell(cell);
|
|
1202
|
+
}
|
|
1203
|
+
}
|
|
1204
|
+
};
|
|
1205
|
+
const sortButton = (cell, target) => {
|
|
1206
|
+
const state = headerSortState(view, target);
|
|
1207
|
+
const next = nextHeaderSort(view, target, hostOrdered(target.field));
|
|
1208
|
+
const field = fieldLabel2(target.field, labels.core);
|
|
1209
|
+
const words = (s) => sortText(view, s ?? { by: hostOrdered(target.field) ? "custom" : "label", order: "asc" }, labels);
|
|
1210
|
+
const down = state.chosen ? state.order === "descending" : next?.order === "desc";
|
|
1211
|
+
const click = () => {
|
|
1212
|
+
onSort?.(target.field, next);
|
|
1213
|
+
setSortNote(fill(labels.headerSorted, { field, order: words(next) }));
|
|
1214
|
+
};
|
|
1215
|
+
return {
|
|
1216
|
+
// aria-sort only on the header whose sort was chosen (a custom order too): one at a time (WAI-ARIA APG)
|
|
1217
|
+
sort: state.chosen || state.order === "other" ? state.order : null,
|
|
1218
|
+
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" }))
|
|
1219
|
+
};
|
|
1220
|
+
};
|
|
1221
|
+
const stickyStyle = (col, extra) => col < grid.rowHeaderColumns && lefts[col] !== void 0 ? { left: lefts[col], ...extra } : extra;
|
|
1222
|
+
const headerCell = (cell, r, c) => {
|
|
1223
|
+
const top = { top: tops[r] ?? r * rowHeight };
|
|
1224
|
+
const sticky = c < grid.rowHeaderColumns;
|
|
1225
|
+
const className = `pk-th pk-${cell.kind}${totalClass(cell.total)}${sticky ? " pk-sticky" : ""}`;
|
|
1226
|
+
const target = onSort && r === grid.headerRows - 1 ? headerSortTarget(view, cell, typeOf) : null;
|
|
1227
|
+
const sorting = target ? sortButton(cell, target) : null;
|
|
1228
|
+
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));
|
|
1229
|
+
const props = { className, style: stickyStyle(c, top), colSpan: cell.colSpan, rowSpan: cell.rowSpan, scope: cell.kind === "colHeader" ? "col" : void 0 };
|
|
1230
|
+
if (cell.kind === "corner" && !cell.field && !cell.text) {
|
|
1231
|
+
return /* @__PURE__ */ React6.createElement("td", { key: c, className: `${className} pk-blank`, style: props.style, colSpan: cell.colSpan, rowSpan: cell.rowSpan });
|
|
1232
|
+
}
|
|
1233
|
+
if (cell.kind === "corner" && cell.field) {
|
|
1234
|
+
const zone = view.rows.includes(cell.field) ? "rows" : "cols";
|
|
1235
|
+
return /* @__PURE__ */ React6.createElement(DraggableHeader, { key: c, ...props, cell, source: { kind: "table", field: cell.field, zone, index: view[zone].indexOf(cell.field), label: cell.text }, description: infoOf?.(cell.field)?.description, tooltip: showInfo, sort: sorting?.sort }, content);
|
|
1236
|
+
}
|
|
1237
|
+
if (cell.kind === "colHeader" && cell.valueIndex !== void 0 && r === grid.headerRows - 1) {
|
|
1238
|
+
const spec = view.values[cell.valueIndex];
|
|
1239
|
+
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);
|
|
1240
|
+
}
|
|
1241
|
+
return /* @__PURE__ */ React6.createElement("th", { key: c, ...props }, content);
|
|
1242
|
+
};
|
|
1243
|
+
const bodyCell = ({ cell, col, rowSpan, colSpan }, r) => {
|
|
1244
|
+
if (cell.kind === "rowHeader") {
|
|
1245
|
+
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)));
|
|
1246
|
+
}
|
|
1247
|
+
const isValue = cell.valueIndex !== void 0;
|
|
1248
|
+
const clickable = isValue && drillable(cell);
|
|
1249
|
+
const focus = current && current.r === r && current.c === col;
|
|
1250
|
+
const cond = conditionalStyle(cell);
|
|
1251
|
+
return /* @__PURE__ */ React6.createElement(
|
|
1252
|
+
"td",
|
|
1253
|
+
{
|
|
1254
|
+
key: col,
|
|
1255
|
+
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" : ""}`,
|
|
1256
|
+
style: cond,
|
|
1257
|
+
"data-r": r,
|
|
1258
|
+
"data-c": col,
|
|
1259
|
+
tabIndex: isValue ? focus ? 0 : -1 : void 0,
|
|
1260
|
+
onClick: clickable ? () => {
|
|
1261
|
+
setActive({ r, c: col });
|
|
1262
|
+
onCell(cell);
|
|
1263
|
+
} : void 0,
|
|
1264
|
+
onFocus: showRowLabel ? () => showRowLabel(r) : void 0
|
|
1265
|
+
},
|
|
1266
|
+
cell.text,
|
|
1267
|
+
isValue && cell.text === "" ? /* @__PURE__ */ React6.createElement("span", { className: "pk-sr pk-no-copy" }, cell.hasRows ? labels.emptyValue : labels.emptyCell) : null
|
|
1268
|
+
);
|
|
1269
|
+
};
|
|
1270
|
+
const columns = grid.columnCount;
|
|
1271
|
+
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: (
|
|
1272
|
+
/** @type {any} */
|
|
1273
|
+
{ "--pk-row-cols": grid.rowHeaderColumns }
|
|
1274
|
+
), 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)));
|
|
1275
|
+
}
|
|
1276
|
+
|
|
1277
|
+
// src/toasts.jsx
|
|
1278
|
+
import React7, { useCallback as useCallback3, useEffect as useEffect5, useRef as useRef5, useState as useState6 } from "react";
|
|
1279
|
+
var SHOWN_MS = 6e3;
|
|
1280
|
+
var MAX_SHOWN = 2;
|
|
1281
|
+
function useToasts() {
|
|
1282
|
+
const [toasts, setToasts] = useState6(
|
|
1283
|
+
/** @type {Toast[]} */
|
|
1284
|
+
[]
|
|
1285
|
+
);
|
|
1286
|
+
const next = useRef5(1);
|
|
1287
|
+
const timers = useRef5(/* @__PURE__ */ new Map());
|
|
1288
|
+
const paused = useRef5(false);
|
|
1289
|
+
const dismiss = useCallback3((id) => {
|
|
1290
|
+
setToasts((list) => list.filter((t) => t.id !== id));
|
|
1291
|
+
clearTimeout(timers.current.get(id));
|
|
1292
|
+
timers.current.delete(id);
|
|
1293
|
+
}, []);
|
|
1294
|
+
const arm = useCallback3(
|
|
1295
|
+
(id) => {
|
|
1296
|
+
clearTimeout(timers.current.get(id));
|
|
1297
|
+
timers.current.set(id, setTimeout(() => dismiss(id), SHOWN_MS));
|
|
1298
|
+
},
|
|
1299
|
+
[dismiss]
|
|
1300
|
+
);
|
|
1301
|
+
const push = useCallback3(
|
|
1302
|
+
(toast) => {
|
|
1303
|
+
const id = next.current++;
|
|
1304
|
+
setToasts((list) => [...list.slice(-(MAX_SHOWN - 1)), { ...toast, id }]);
|
|
1305
|
+
if (toast.tone !== "error" && !paused.current) {
|
|
1306
|
+
arm(id);
|
|
1307
|
+
}
|
|
1308
|
+
},
|
|
1309
|
+
[arm]
|
|
1310
|
+
);
|
|
1311
|
+
const pause = useCallback3(
|
|
1312
|
+
(on, list) => {
|
|
1313
|
+
paused.current = on;
|
|
1314
|
+
for (const t of list) {
|
|
1315
|
+
if (on) {
|
|
1316
|
+
clearTimeout(timers.current.get(t.id));
|
|
1317
|
+
} else if (t.tone !== "error") {
|
|
1318
|
+
arm(t.id);
|
|
1319
|
+
}
|
|
1320
|
+
}
|
|
1321
|
+
},
|
|
1322
|
+
[arm]
|
|
1323
|
+
);
|
|
1324
|
+
useEffect5(() => {
|
|
1325
|
+
const map = timers.current;
|
|
1326
|
+
return () => map.forEach((t) => clearTimeout(t));
|
|
1327
|
+
}, []);
|
|
1328
|
+
return { toasts, push, dismiss, pause };
|
|
1329
|
+
}
|
|
1330
|
+
function Toasts({ toasts, dismiss, pause, closeLabel }) {
|
|
1331
|
+
const hold = () => pause(true, toasts);
|
|
1332
|
+
const release = (e) => {
|
|
1333
|
+
if (!e || !e.currentTarget.contains(
|
|
1334
|
+
/** @type {Node | null} */
|
|
1335
|
+
e.relatedTarget
|
|
1336
|
+
)) {
|
|
1337
|
+
pause(false, toasts);
|
|
1338
|
+
}
|
|
1339
|
+
};
|
|
1340
|
+
return /* @__PURE__ */ React7.createElement("div", { className: "pk-toasts", role: "status", "aria-live": "polite", "aria-atomic": "false", onMouseEnter: hold, onMouseLeave: () => release(null), onFocus: hold, onBlur: release }, toasts.map((t) => /* @__PURE__ */ React7.createElement("div", { key: t.id, className: `pk-toast${t.tone === "error" ? " pk-error" : ""}`, role: t.tone === "error" ? "alert" : void 0 }, t.tone === "error" ? /* @__PURE__ */ React7.createElement(Icon, { name: "info", size: 14 }) : null, /* @__PURE__ */ React7.createElement("span", { className: "pk-toast-text" }, t.text), t.action ? /* @__PURE__ */ React7.createElement(
|
|
1341
|
+
"button",
|
|
1342
|
+
{
|
|
1343
|
+
type: "button",
|
|
1344
|
+
className: "pk-link pk-toast-action",
|
|
1345
|
+
onClick: () => {
|
|
1346
|
+
dismiss(t.id);
|
|
1347
|
+
t.action?.run();
|
|
1348
|
+
}
|
|
1349
|
+
},
|
|
1350
|
+
t.action.label
|
|
1351
|
+
) : null, /* @__PURE__ */ React7.createElement("button", { type: "button", className: "pk-icon-btn pk-toast-x", "aria-label": closeLabel, title: closeLabel, onClick: () => dismiss(t.id) }, /* @__PURE__ */ React7.createElement(Icon, { name: "x", size: 14 })))));
|
|
1352
|
+
}
|
|
1353
|
+
|
|
1354
|
+
// src/templates.js
|
|
1355
|
+
import { fieldDefaultsFromSchema as fieldDefaultsFromSchema2, fromViewFile } from "pivotkit-core";
|
|
1356
|
+
var warnedScope = false;
|
|
1357
|
+
function plainNames(names) {
|
|
1358
|
+
const properties = {};
|
|
1359
|
+
names.forEach((title, i) => Object.defineProperty(properties, String(i), { value: { title }, enumerable: true }));
|
|
1360
|
+
const clean = names.length ? fieldDefaultsFromSchema2({ properties }).defaults : {};
|
|
1361
|
+
return names.map((n, i) => Object.hasOwn(clean, String(i)) ? clean[String(i)].label : void 0);
|
|
1362
|
+
}
|
|
1363
|
+
var viewsName = (key) => key ? `pivotkit:views:${key}` : "pivotkit:views";
|
|
1364
|
+
function templateEntries(templates, stored, hostDeletes) {
|
|
1365
|
+
const out = [];
|
|
1366
|
+
for (const t of Array.isArray(templates) ? templates : []) {
|
|
1367
|
+
if (!t || typeof t !== "object") {
|
|
1368
|
+
continue;
|
|
1369
|
+
}
|
|
1370
|
+
let { name, view } = t;
|
|
1371
|
+
if (t.file !== void 0 && t.file !== null) {
|
|
1372
|
+
const read = fromViewFile(t.file);
|
|
1373
|
+
view = read.view;
|
|
1374
|
+
name = typeof name === "string" && name ? name : read.name;
|
|
1375
|
+
}
|
|
1376
|
+
if (typeof name === "string" && name && view && typeof view === "object") {
|
|
1377
|
+
const deletable = t.deletable === true;
|
|
1378
|
+
const scoped = t.scope === "shared" || t.scope === "user";
|
|
1379
|
+
if (deletable && !scoped && !warnedScope) {
|
|
1380
|
+
warnedScope = true;
|
|
1381
|
+
console.warn('pivotkit: a template marked deletable without a scope is listed under "My views"; give shared views scope: "shared"');
|
|
1382
|
+
}
|
|
1383
|
+
out.push({ name, view, deletable: deletable && hostDeletes, scope: scoped ? t.scope : deletable ? "user" : "shared" });
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
const all = [...out, ...stored.map((t) => ({ name: t.name, view: t.view, scope: (
|
|
1387
|
+
/** @type {const} */
|
|
1388
|
+
"user"
|
|
1389
|
+
), deletable: true, at: t.at, ...t.sourceId ? { sourceId: t.sourceId } : {} }))];
|
|
1390
|
+
const names = plainNames(all.map((t) => t.name));
|
|
1391
|
+
return all.flatMap((t, i) => names[i] ? [{ ...t, name: (
|
|
1392
|
+
/** @type {string} */
|
|
1393
|
+
names[i]
|
|
1394
|
+
) }] : []);
|
|
1395
|
+
}
|
|
1396
|
+
|
|
1397
|
+
// src/tip-list.jsx
|
|
1398
|
+
import React8, { useEffect as useEffect6, useId as useId3, useRef as useRef6 } from "react";
|
|
1399
|
+
function Tips({ tips, labels, onDismiss, onAction, focusFallback }) {
|
|
1400
|
+
const box = useRef6(
|
|
1401
|
+
/** @type {HTMLDivElement | null} */
|
|
1402
|
+
null
|
|
1403
|
+
);
|
|
1404
|
+
const idBase = useId3();
|
|
1405
|
+
const refocus = useRef6(false);
|
|
1406
|
+
useEffect6(() => {
|
|
1407
|
+
if (!refocus.current) {
|
|
1408
|
+
return;
|
|
1409
|
+
}
|
|
1410
|
+
refocus.current = false;
|
|
1411
|
+
const next = (
|
|
1412
|
+
/** @type {HTMLElement | null | undefined} */
|
|
1413
|
+
box.current?.querySelector(".pk-tip-x")
|
|
1414
|
+
);
|
|
1415
|
+
if (next) {
|
|
1416
|
+
next.focus({ preventScroll: true });
|
|
1417
|
+
} else {
|
|
1418
|
+
focusFallback();
|
|
1419
|
+
}
|
|
1420
|
+
});
|
|
1421
|
+
return /* @__PURE__ */ React8.createElement(React8.Fragment, null, tips.length ? /* @__PURE__ */ React8.createElement("div", { className: "pk-tips", ref: box, role: "group", "aria-label": labels.tipsTitle, "data-testid": "tips" }, tips.map((t) => /* @__PURE__ */ React8.createElement("div", { key: t.id, className: `pk-note pk-tip${t.notice ? " pk-notice" : ""}${t.action ? " pk-has-action" : ""}`, "data-tip": t.id, "data-kind": t.notice ? "notice" : "tip", "data-testid": `tip-${t.id}` }, /* @__PURE__ */ React8.createElement(Icon, { name: (
|
|
1422
|
+
/** @type {any} */
|
|
1423
|
+
t.icon
|
|
1424
|
+
), size: 16 }), /* @__PURE__ */ React8.createElement("span", { className: "pk-tip-text", id: `${idBase}-${t.id}` }, t.text), t.action ? /* @__PURE__ */ React8.createElement("button", { type: "button", className: "pk-btn pk-small-btn", onClick: () => onAction(t.id, t.action), "data-testid": `tip-action-${t.id}` }, /* @__PURE__ */ React8.createElement("span", { className: "pk-btn-text" }, t.actionText)) : null, t.notice ? null : /* @__PURE__ */ React8.createElement(
|
|
1425
|
+
"button",
|
|
1426
|
+
{
|
|
1427
|
+
type: "button",
|
|
1428
|
+
className: "pk-icon-btn pk-tip-x",
|
|
1429
|
+
"aria-label": labels.dismissTip,
|
|
1430
|
+
"aria-describedby": `${idBase}-${t.id}`,
|
|
1431
|
+
title: labels.dismissTip,
|
|
1432
|
+
onClick: () => {
|
|
1433
|
+
refocus.current = true;
|
|
1434
|
+
onDismiss(t.id);
|
|
1435
|
+
}
|
|
1436
|
+
},
|
|
1437
|
+
/* @__PURE__ */ React8.createElement(Icon, { name: "x", size: 14 })
|
|
1438
|
+
)))) : null, /* @__PURE__ */ React8.createElement("div", { className: "pk-sr", "aria-live": "polite", "data-testid": "tips-live" }, tips.map((t) => /* @__PURE__ */ React8.createElement("p", { key: t.id }, t.text))));
|
|
1439
|
+
}
|
|
1440
|
+
|
|
1441
|
+
// src/unused.jsx
|
|
1442
|
+
import React9, { useEffect as useEffect7, useMemo as useMemo4, useRef as useRef7, useState as useState7 } from "react";
|
|
1443
|
+
import { fieldLabel as fieldLabel3 } from "pivotkit-core";
|
|
1444
|
+
|
|
1445
|
+
// src/unused-load.js
|
|
1446
|
+
var UNUSED_TEXTS_OF = Object.freeze({ de: () => import("./chunks/unused-texts-de-SGOHV4N7.js").then((m) => m.de) });
|
|
1447
|
+
var pending2 = /* @__PURE__ */ new Map();
|
|
1448
|
+
var loaded2 = /* @__PURE__ */ new Map();
|
|
1449
|
+
var unusedNow = (lang) => loaded2.get(lang) ?? null;
|
|
1450
|
+
function loadUnused(lang) {
|
|
1451
|
+
let p = pending2.get(lang);
|
|
1452
|
+
if (!p) {
|
|
1453
|
+
const own2 = Object.hasOwn(UNUSED_TEXTS_OF, lang) ? UNUSED_TEXTS_OF[lang]().catch(() => null) : null;
|
|
1454
|
+
p = Promise.all([import("./chunks/unused-texts-YTNJCFFC.js"), own2]).then(
|
|
1455
|
+
([mod, texts]) => {
|
|
1456
|
+
const out = { mod, lang: texts };
|
|
1457
|
+
loaded2.set(lang, out);
|
|
1458
|
+
return out;
|
|
1459
|
+
},
|
|
1460
|
+
(error) => {
|
|
1461
|
+
pending2.delete(lang);
|
|
1462
|
+
throw error;
|
|
1463
|
+
}
|
|
1464
|
+
);
|
|
1465
|
+
pending2.set(lang, p);
|
|
1466
|
+
}
|
|
1467
|
+
return p;
|
|
1468
|
+
}
|
|
1469
|
+
function unusedTexts(loaded3, labels) {
|
|
1470
|
+
const host = (
|
|
1471
|
+
/** @type {any} */
|
|
1472
|
+
labels[MENU_TEXTS]
|
|
1473
|
+
);
|
|
1474
|
+
return mergeLabels(mergeLabels(loaded3.mod.en, loaded3.lang), host && typeof host === "object" ? host.unused : void 0);
|
|
1475
|
+
}
|
|
1476
|
+
|
|
1477
|
+
// src/unused.jsx
|
|
1478
|
+
var FIRST = { narrow: 2, wide: 3 };
|
|
1479
|
+
var FOCUSABLE = 'button:not([disabled]), [href], input:not([disabled]), select:not([disabled]), textarea:not([disabled]), [tabindex]:not([tabindex="-1"])';
|
|
1480
|
+
function Unused({ notes, notesKey, dismissed, onDismiss, labels, locale, narrow, quiet }) {
|
|
1481
|
+
const lang = labels.lang;
|
|
1482
|
+
const show = notes.length > 0 && !dismissed;
|
|
1483
|
+
const [folded, setFolded] = useState7(
|
|
1484
|
+
/** @type {string | null} */
|
|
1485
|
+
null
|
|
1486
|
+
);
|
|
1487
|
+
const [all, setAll] = useState7(
|
|
1488
|
+
/** @type {string | null} */
|
|
1489
|
+
null
|
|
1490
|
+
);
|
|
1491
|
+
const [got, setGot] = useState7(
|
|
1492
|
+
/** @type {{ lang: string, value: import("./unused-load.js").UnusedLoaded } | null} */
|
|
1493
|
+
null
|
|
1494
|
+
);
|
|
1495
|
+
const box = useRef7(
|
|
1496
|
+
/** @type {HTMLDivElement | null} */
|
|
1497
|
+
null
|
|
1498
|
+
);
|
|
1499
|
+
const now = got?.lang === lang ? got.value : unusedNow(lang);
|
|
1500
|
+
const issues = useMemo4(() => (
|
|
1501
|
+
/** @type {Array<{ issue: import("pivotkit-core").Issue, raw: unknown }>} */
|
|
1502
|
+
notes.filter((n) => "issue" in n)
|
|
1503
|
+
), [notes]);
|
|
1504
|
+
const wanted = show && issues.length > 0;
|
|
1505
|
+
useEffect7(() => {
|
|
1506
|
+
if (!wanted || now) {
|
|
1507
|
+
return void 0;
|
|
1508
|
+
}
|
|
1509
|
+
let live = true;
|
|
1510
|
+
loadUnused(lang).then(
|
|
1511
|
+
(value) => live && setGot({ lang, value }),
|
|
1512
|
+
// the core's messages stay; the next view with unused parts tries again
|
|
1513
|
+
() => void 0
|
|
1514
|
+
);
|
|
1515
|
+
return () => {
|
|
1516
|
+
live = false;
|
|
1517
|
+
};
|
|
1518
|
+
}, [wanted, now, lang, notesKey]);
|
|
1519
|
+
const plain = useMemo4(() => {
|
|
1520
|
+
if (!now || !wanted) {
|
|
1521
|
+
return null;
|
|
1522
|
+
}
|
|
1523
|
+
const ctx = { labels, fill, field: (name) => fieldLabel3(name, labels.core), value: (spec) => valueLabel(spec, labels) };
|
|
1524
|
+
return now.mod.unusedItems(issues, unusedTexts(now, labels), ctx);
|
|
1525
|
+
}, [now, wanted, issues, labels]);
|
|
1526
|
+
const title = plural(labels.unusedParts, notes.length, { lang, locale });
|
|
1527
|
+
const first = FIRST[narrow ? "narrow" : "wide"];
|
|
1528
|
+
const cut = all !== notesKey && notes.length > first + 1 ? first : notes.length;
|
|
1529
|
+
const dismiss = () => {
|
|
1530
|
+
const el = box.current;
|
|
1531
|
+
const root = el?.closest(".pk-root");
|
|
1532
|
+
const next = el && root ? [...root.querySelectorAll(FOCUSABLE)].find((c) => !el.contains(c) && el.compareDocumentPosition(c) & Node.DOCUMENT_POSITION_FOLLOWING) : null;
|
|
1533
|
+
onDismiss(
|
|
1534
|
+
/** @type {HTMLElement | null} */
|
|
1535
|
+
next ?? null
|
|
1536
|
+
);
|
|
1537
|
+
};
|
|
1538
|
+
const lineOf = new Map(plain ? issues.map((n, i) => [n, plain[i]]) : []);
|
|
1539
|
+
return /* @__PURE__ */ React9.createElement(React9.Fragment, null, show ? /* @__PURE__ */ React9.createElement("div", { className: "pk-note pk-issues", "data-testid": "view-issues", ref: box }, /* @__PURE__ */ React9.createElement(Icon, { name: "warn", size: 16 }), /* @__PURE__ */ React9.createElement("details", { open: folded !== notesKey, onToggle: (e) => setFolded(e.currentTarget.open ? null : notesKey) }, /* @__PURE__ */ React9.createElement("summary", { "data-testid": "unused-title" }, title), /* @__PURE__ */ React9.createElement("ul", null, notes.slice(0, cut).map((n, i) => {
|
|
1540
|
+
if (!("issue" in n)) {
|
|
1541
|
+
return /* @__PURE__ */ React9.createElement("li", { key: i }, n.text);
|
|
1542
|
+
}
|
|
1543
|
+
const line = lineOf.get(n);
|
|
1544
|
+
return /* @__PURE__ */ React9.createElement("li", { key: i, "data-testid": "unused-item" }, line ? /* @__PURE__ */ React9.createElement(React9.Fragment, null, line.pre, /* @__PURE__ */ React9.createElement("strong", null, line.subject), line.post) : n.issue.message, n.issue.path || line ? /* @__PURE__ */ React9.createElement("small", { className: "pk-issues-path", "data-testid": "unused-path" }, labels.unusedPath, " ", /* @__PURE__ */ React9.createElement("code", null, n.issue.path), line ? ` \xB7 ${n.issue.message}` : null) : null);
|
|
1545
|
+
})), 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));
|
|
1546
|
+
}
|
|
1547
|
+
|
|
1548
|
+
// src/toolbar.jsx
|
|
1549
|
+
import React10, { useCallback as useCallback4, useEffect as useEffect8, useMemo as useMemo5, useRef as useRef8, useState as useState8 } from "react";
|
|
1550
|
+
|
|
1551
|
+
// src/overflow.js
|
|
1552
|
+
var OVERFLOW_ORDER = Object.freeze(["reset", "layout", "options", "chartType", "views"]);
|
|
1553
|
+
var TOOLBAR_ROOM = Object.freeze({
|
|
1554
|
+
// measured in Chromium at the playground's font: the longer of English and German with the gap
|
|
1555
|
+
// after it, plus 2 %; a wider font still fits, as useOverflow measures as well
|
|
1556
|
+
fields: 6.4,
|
|
1557
|
+
display: 15.3,
|
|
1558
|
+
chartType: 12.9,
|
|
1559
|
+
sep: 1,
|
|
1560
|
+
undo: 8.75,
|
|
1561
|
+
redo: 9.15,
|
|
1562
|
+
reset: 9.65,
|
|
1563
|
+
layout: 8.4,
|
|
1564
|
+
options: 8.75,
|
|
1565
|
+
views: 9.1,
|
|
1566
|
+
export: 7.5,
|
|
1567
|
+
more: 7.2
|
|
1568
|
+
});
|
|
1569
|
+
var TEXT_BUTTONS = Object.freeze(["fields", "undo", "redo", "reset", "layout"]);
|
|
1570
|
+
var MENU_BUTTONS = Object.freeze(["chartType", "options", "views", "export", "more"]);
|
|
1571
|
+
function toolbarTexts(sets) {
|
|
1572
|
+
const out = (
|
|
1573
|
+
/** @type {any} */
|
|
1574
|
+
{ fields: [], undo: [], redo: [], reset: [], layout: [], chartType: [], options: [], views: [], export: [], more: [], display: [] }
|
|
1575
|
+
);
|
|
1576
|
+
const text = (v) => typeof v === "string" ? v : "";
|
|
1577
|
+
for (const l of sets) {
|
|
1578
|
+
out.fields.push(text(l.showFields));
|
|
1579
|
+
out.undo.push(text(l.undo));
|
|
1580
|
+
out.redo.push(text(l.redo));
|
|
1581
|
+
out.reset.push(text(l.reset));
|
|
1582
|
+
out.layout.push(text(l.layout));
|
|
1583
|
+
out.options.push(text(l.options));
|
|
1584
|
+
out.views.push(text(l.views));
|
|
1585
|
+
out.export.push(text(l.exportLabel));
|
|
1586
|
+
out.more.push(text(l.more));
|
|
1587
|
+
out.chartType.push(...Object.values(l.chartTypes ?? {}).map(text));
|
|
1588
|
+
out.display.push([text(l.table), text(l.chart)]);
|
|
1589
|
+
}
|
|
1590
|
+
return out;
|
|
1591
|
+
}
|
|
1592
|
+
function toolbarRoom(texts, measure, chrome) {
|
|
1593
|
+
const widest = (list, kind = "button") => Math.max(0, ...list.map((t) => measure(t, kind)));
|
|
1594
|
+
const room = (
|
|
1595
|
+
/** @type {Record<string, number>} */
|
|
1596
|
+
{ sep: chrome.sep + chrome.gap }
|
|
1597
|
+
);
|
|
1598
|
+
for (const id of TEXT_BUTTONS) {
|
|
1599
|
+
room[id] = chrome.text + widest(texts[id]) + chrome.gap;
|
|
1600
|
+
}
|
|
1601
|
+
for (const id of MENU_BUTTONS) {
|
|
1602
|
+
room[id] = chrome.menu + widest(texts[id]) + chrome.gap;
|
|
1603
|
+
}
|
|
1604
|
+
room.display = chrome.display + Math.max(0, ...texts.display.map(([a, b]) => measure(a, "display") + measure(b, "display"))) + chrome.gap;
|
|
1605
|
+
return room;
|
|
1606
|
+
}
|
|
1607
|
+
function overflowLevel(width, narrow, room = TOOLBAR_ROOM) {
|
|
1608
|
+
const fixed = (narrow ? room.fields : 0) + room.display + room.sep + room.undo + room.redo + room.export;
|
|
1609
|
+
let level = 0;
|
|
1610
|
+
const need = (n) => fixed + OVERFLOW_ORDER.slice(n).reduce((sum, id) => sum + room[id], 0) + (n > 0 ? room.more : 0);
|
|
1611
|
+
while (level < OVERFLOW_ORDER.length && need(level) > width) {
|
|
1612
|
+
level += 1;
|
|
1613
|
+
}
|
|
1614
|
+
return level;
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
// src/toolbar.jsx
|
|
1618
|
+
function TextButton({ icon, label, onClick, disabled, testId, shortcut }) {
|
|
1619
|
+
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));
|
|
1620
|
+
}
|
|
1621
|
+
var measuring;
|
|
1622
|
+
var fontOf = (style) => `${style.fontStyle} ${style.fontWeight} ${style.fontSize} ${style.fontFamily}`;
|
|
1623
|
+
function measuredRoom(el, texts) {
|
|
1624
|
+
const doc = el.ownerDocument;
|
|
1625
|
+
if (measuring === void 0) {
|
|
1626
|
+
try {
|
|
1627
|
+
measuring = doc.createElement("canvas").getContext("2d");
|
|
1628
|
+
} catch {
|
|
1629
|
+
measuring = null;
|
|
1630
|
+
}
|
|
1631
|
+
}
|
|
1632
|
+
const undo2 = el.querySelector("[data-testid='undo']");
|
|
1633
|
+
const menu = el.querySelector("[data-testid='export']");
|
|
1634
|
+
const display = el.querySelector(".pk-segmented");
|
|
1635
|
+
const sep = el.querySelector(".pk-sep");
|
|
1636
|
+
const textOf = (node) => node?.querySelector(".pk-btn-text, span");
|
|
1637
|
+
if (!measuring || !undo2 || !menu || !display || !textOf(undo2) || !textOf(display)) {
|
|
1638
|
+
return null;
|
|
1639
|
+
}
|
|
1640
|
+
const view = doc.defaultView;
|
|
1641
|
+
if (!view) {
|
|
1642
|
+
return null;
|
|
1643
|
+
}
|
|
1644
|
+
const fonts = { button: fontOf(view.getComputedStyle(
|
|
1645
|
+
/** @type {Element} */
|
|
1646
|
+
textOf(undo2)
|
|
1647
|
+
)), display: fontOf(view.getComputedStyle(
|
|
1648
|
+
/** @type {Element} */
|
|
1649
|
+
textOf(display)
|
|
1650
|
+
)) };
|
|
1651
|
+
const ctx = measuring;
|
|
1652
|
+
const measure = (text, kind) => {
|
|
1653
|
+
ctx.font = fonts[kind];
|
|
1654
|
+
return ctx.measureText(text).width;
|
|
1655
|
+
};
|
|
1656
|
+
const w = (node) => node.getBoundingClientRect().width;
|
|
1657
|
+
const tw = (node) => node ? node.getBoundingClientRect().width : 0;
|
|
1658
|
+
const segTexts = [...display.querySelectorAll("button > span")];
|
|
1659
|
+
const sepStyle = sep ? view.getComputedStyle(sep) : null;
|
|
1660
|
+
const chrome = {
|
|
1661
|
+
text: w(undo2) - tw(textOf(undo2)),
|
|
1662
|
+
menu: w(menu) - tw(textOf(menu)),
|
|
1663
|
+
display: w(display) - segTexts.reduce((n, s) => n + tw(s), 0),
|
|
1664
|
+
sep: sep && sepStyle ? w(sep) + parseFloat(sepStyle.marginLeft) + parseFloat(sepStyle.marginRight) : 0,
|
|
1665
|
+
// one more px per part: text widths are fractional, the buttons round them
|
|
1666
|
+
gap: (parseFloat(view.getComputedStyle(el).columnGap) || 0) + 1
|
|
1667
|
+
};
|
|
1668
|
+
return toolbarRoom(texts, measure, chrome);
|
|
1669
|
+
}
|
|
1670
|
+
function useOverflow(ref, key, narrow, max, texts) {
|
|
1671
|
+
const [level, setLevel] = useState8(0);
|
|
1672
|
+
const [measure, setMeasure] = useState8(0);
|
|
1673
|
+
const [lastKey, setLastKey] = useState8(key);
|
|
1674
|
+
const latest = useRef8(texts);
|
|
1675
|
+
useIsoLayoutEffect(() => {
|
|
1676
|
+
latest.current = texts;
|
|
1677
|
+
});
|
|
1678
|
+
if (key !== lastKey) {
|
|
1679
|
+
setLastKey(key);
|
|
1680
|
+
setMeasure((m) => m + 1);
|
|
1681
|
+
}
|
|
1682
|
+
useIsoLayoutEffect(() => {
|
|
1683
|
+
const el = ref.current;
|
|
1684
|
+
if (!el || typeof ResizeObserver !== "function") {
|
|
1685
|
+
return void 0;
|
|
1686
|
+
}
|
|
1687
|
+
let width = -1;
|
|
1688
|
+
const decide = () => {
|
|
1689
|
+
const em = parseFloat(getComputedStyle(el).fontSize) || 14;
|
|
1690
|
+
const room = measuredRoom(el, latest.current);
|
|
1691
|
+
setLevel(room ? overflowLevel(width, narrow, room) : overflowLevel(width / em, narrow));
|
|
1692
|
+
setMeasure((m) => m + 1);
|
|
1693
|
+
};
|
|
1694
|
+
const ro = new ResizeObserver(([entry]) => {
|
|
1695
|
+
const w = Math.round(entry.contentRect.width);
|
|
1696
|
+
if (w !== width) {
|
|
1697
|
+
width = w;
|
|
1698
|
+
decide();
|
|
1699
|
+
}
|
|
1700
|
+
});
|
|
1701
|
+
width = Math.round(el.getBoundingClientRect().width);
|
|
1702
|
+
decide();
|
|
1703
|
+
ro.observe(el);
|
|
1704
|
+
let live = true;
|
|
1705
|
+
el.ownerDocument.fonts?.ready.then(() => live && width >= 0 && decide(), () => void 0);
|
|
1706
|
+
return () => {
|
|
1707
|
+
live = false;
|
|
1708
|
+
ro.disconnect();
|
|
1709
|
+
};
|
|
1710
|
+
}, [ref, narrow, key]);
|
|
1711
|
+
useIsoLayoutEffect(() => {
|
|
1712
|
+
const el = ref.current;
|
|
1713
|
+
if (el && el.scrollWidth > el.clientWidth + 1 && level < max) {
|
|
1714
|
+
setLevel(level + 1);
|
|
1715
|
+
}
|
|
1716
|
+
}, [ref, level, measure, key, max]);
|
|
1717
|
+
return level;
|
|
1718
|
+
}
|
|
1719
|
+
function Toolbar(props) {
|
|
1720
|
+
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;
|
|
1721
|
+
const tips = { controls: props.tipsControls, on: props.tipsOn, onOn: props.onTipsOn, canReset: props.canResetTips, onReset: props.onResetTips };
|
|
1722
|
+
const bar = useRef8(
|
|
1723
|
+
/** @type {HTMLDivElement | null} */
|
|
1724
|
+
null
|
|
1725
|
+
);
|
|
1726
|
+
const more = useRef8(
|
|
1727
|
+
/** @type {HTMLButtonElement | null} */
|
|
1728
|
+
null
|
|
1729
|
+
);
|
|
1730
|
+
const viewsButton = useRef8(
|
|
1731
|
+
/** @type {HTMLButtonElement | null} */
|
|
1732
|
+
null
|
|
1733
|
+
);
|
|
1734
|
+
const [panel, setPanel] = useState8(
|
|
1735
|
+
/** @type {"options" | "views" | "chartType" | null} */
|
|
1736
|
+
null
|
|
1737
|
+
);
|
|
1738
|
+
const order = OVERFLOW_ORDER;
|
|
1739
|
+
const texts = useMemo5(() => toolbarTexts([LABELS.en, LABELS.de, labels]), [labels]);
|
|
1740
|
+
const level = useOverflow(bar, `${labels.lang}:${labels.undo}:${size}`, size === "narrow", order.length, texts);
|
|
1741
|
+
const hidden = new Set(order.slice(0, level));
|
|
1742
|
+
if (panel && !hidden.has(panel)) {
|
|
1743
|
+
setPanel(null);
|
|
1744
|
+
}
|
|
1745
|
+
const closePanel = useCallback4(() => setPanel(null), []);
|
|
1746
|
+
const request = props.viewsRequest ?? 0;
|
|
1747
|
+
const [seenRequest, setSeenRequest] = useState8(request);
|
|
1748
|
+
const [clickFor, setClickFor] = useState8(0);
|
|
1749
|
+
if (request !== seenRequest) {
|
|
1750
|
+
setSeenRequest(request);
|
|
1751
|
+
if (hidden.has("views")) {
|
|
1752
|
+
setPanel("views");
|
|
1753
|
+
} else {
|
|
1754
|
+
setClickFor(request);
|
|
1755
|
+
}
|
|
1756
|
+
}
|
|
1757
|
+
useEffect8(() => {
|
|
1758
|
+
const button = viewsButton.current;
|
|
1759
|
+
if (clickFor > 0 && button && button.getAttribute("aria-expanded") !== "true") {
|
|
1760
|
+
button.click();
|
|
1761
|
+
}
|
|
1762
|
+
}, [clickFor]);
|
|
1763
|
+
const plan = props.chartPlan ?? { name: chartTypeOf(view.chart), auto: false };
|
|
1764
|
+
const preset = plan.auto ? "auto" : plan.name;
|
|
1765
|
+
const drawnIcon = CHART_TYPES[plan.name].icon;
|
|
1766
|
+
const mod = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent) ? "\u2318" : "Ctrl+";
|
|
1767
|
+
const chartTypeText = fill(labels.chartTypeIs, { type: labels.chartTypes[preset] });
|
|
1768
|
+
const panels = {
|
|
1769
|
+
// the panels load with the chip menus (menus.js), on demand
|
|
1770
|
+
options: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "OptionsPanel", loadingText: labels.loadingMenu, props: { view, labels, onTotal, onExpand, onCollapse, close, tips, mod, folding, help: props.help } }),
|
|
1771
|
+
views: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ViewsPanel", loadingText: labels.loadingMenu, props: { templates, labels, onLoad: onLoadTemplate, actions: templateActions, close, share } }),
|
|
1772
|
+
chartType: (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ChartTypePanel", loadingText: labels.loadingMenu, props: { view, plan, labels, onChart, onDisplay: onChartDisplay, close } })
|
|
1773
|
+
};
|
|
1774
|
+
const actions = {
|
|
1775
|
+
chartType: {
|
|
1776
|
+
place: "chart",
|
|
1777
|
+
button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "chartType", label: chartTypeText, name: chartTypeText, title: chartTypeText, icon: drawnIcon, text: labels.chartTypes[preset], role: "dialog", testId: "chart-type", popoverClass: "pk-chart-menu" }, panels.chartType),
|
|
1778
|
+
entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "chartType", inMenu: true, icon: drawnIcon, onSelect: () => {
|
|
1779
|
+
close();
|
|
1780
|
+
setPanel("chartType");
|
|
1781
|
+
}, testId: "more-chart-type" }, `${chartTypeText}\u2026`)
|
|
1782
|
+
},
|
|
1783
|
+
reset: {
|
|
1784
|
+
place: "history",
|
|
1785
|
+
button: () => /* @__PURE__ */ React10.createElement(TextButton, { key: "reset", icon: "reset", label: labels.reset, onClick: onReset, disabled: !canReset, testId: "reset" }),
|
|
1786
|
+
entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "reset", inMenu: true, icon: "reset", disabled: !canReset, onSelect: () => {
|
|
1787
|
+
close();
|
|
1788
|
+
onReset();
|
|
1789
|
+
}, testId: "more-reset" }, labels.reset)
|
|
1790
|
+
},
|
|
1791
|
+
layout: {
|
|
1792
|
+
place: "end",
|
|
1793
|
+
// a toggle of the zones: the same text, open or folded; aria-pressed says which
|
|
1794
|
+
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)),
|
|
1795
|
+
entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "layout", inMenu: true, icon: "layout", checked: !layoutFolded, onSelect: () => {
|
|
1796
|
+
close();
|
|
1797
|
+
onLayout();
|
|
1798
|
+
}, testId: "more-layout" }, labels.layout)
|
|
1799
|
+
},
|
|
1800
|
+
options: {
|
|
1801
|
+
place: "end",
|
|
1802
|
+
button: () => /* @__PURE__ */ React10.createElement(MenuButton, { key: "options", label: labels.options, icon: "sliders", text: labels.options, role: "dialog", align: "end", testId: "options" }, panels.options),
|
|
1803
|
+
entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "options", inMenu: true, icon: "sliders", onSelect: () => {
|
|
1804
|
+
close();
|
|
1805
|
+
setPanel("options");
|
|
1806
|
+
}, testId: "more-options" }, `${labels.options}\u2026`)
|
|
1807
|
+
},
|
|
1808
|
+
views: {
|
|
1809
|
+
place: "end",
|
|
1810
|
+
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),
|
|
1811
|
+
entry: (close) => /* @__PURE__ */ React10.createElement(Option, { key: "views", inMenu: true, icon: "bookmark", onSelect: () => {
|
|
1812
|
+
close();
|
|
1813
|
+
setPanel("views");
|
|
1814
|
+
}, testId: "more-views" }, `${labels.views}\u2026`)
|
|
1815
|
+
}
|
|
1816
|
+
};
|
|
1817
|
+
const ORDER = Object.keys(actions);
|
|
1818
|
+
const buttons = (place) => ORDER.filter((id) => actions[id].place === place && !hidden.has(id)).map((id) => actions[id].button());
|
|
1819
|
+
const changedMark = (testId) => /* @__PURE__ */ React10.createElement("span", { className: "pk-view-changed", "data-testid": testId }, /* @__PURE__ */ React10.createElement("span", { className: "pk-sr" }, labels.unsavedChanges));
|
|
1820
|
+
const name = loadedView ? /* @__PURE__ */ React10.createElement(
|
|
1821
|
+
"button",
|
|
1822
|
+
{
|
|
1823
|
+
key: "name",
|
|
1824
|
+
type: "button",
|
|
1825
|
+
className: "pk-view-name",
|
|
1826
|
+
"aria-haspopup": "dialog",
|
|
1827
|
+
title: loadedView.changed ? `${loadedView.name} (${labels.unsavedChanges})` : loadedView.name,
|
|
1828
|
+
onClick: () => hidden.has("views") ? setPanel("views") : viewsButton.current?.click(),
|
|
1829
|
+
"data-testid": "view-name"
|
|
1830
|
+
},
|
|
1831
|
+
/* @__PURE__ */ React10.createElement("span", { className: "pk-view-name-text" }, loadedView.name),
|
|
1832
|
+
loadedView.changed ? changedMark("view-changed") : null
|
|
1833
|
+
) : null;
|
|
1834
|
+
const end = buttons("end");
|
|
1835
|
+
const at = hidden.has("views") ? end.length : end.length - 1;
|
|
1836
|
+
const wrap = level >= order.length;
|
|
1837
|
+
return /* @__PURE__ */ React10.createElement("div", { className: `pk-toolbar${wrap ? " pk-wrap" : ""}`, role: "toolbar", "aria-label": labels.toolbar, ref: bar, "data-overflow": level }, 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: (
|
|
1838
|
+
/** @type {any} */
|
|
1839
|
+
drawnIcon
|
|
1840
|
+
) }), /* @__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 } })), level > 0 ? /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.more, icon: "more", text: labels.more, align: "end", testId: "more", buttonRef: more, mark: hidden.has("views") && loadedView?.changed ? changedMark("more-changed") : null }, (close) => ORDER.filter((id) => hidden.has(id)).map((id) => actions[id].entry(close))) : null, wrap ? name : null, panel ? /* @__PURE__ */ React10.createElement(Popover, { open: true, anchor: more, onClose: closePanel, label: panel === "chartType" ? chartTypeText : panel === "views" ? labels.views : labels.options, role: "dialog", align: "end", className: panel === "chartType" ? "pk-chart-menu" : void 0 }, panels[panel](closePanel)) : null);
|
|
1841
|
+
}
|
|
1842
|
+
|
|
1843
|
+
// src/use-export.js
|
|
1844
|
+
function useExport(context) {
|
|
1845
|
+
return async (kind) => {
|
|
1846
|
+
try {
|
|
1847
|
+
const lang = context.labels.lang;
|
|
1848
|
+
const menus = menusNow(lang) ?? await loadMenus(lang);
|
|
1849
|
+
await menus.runExport(kind, context);
|
|
1850
|
+
} catch (e) {
|
|
1851
|
+
context.announce(fill(context.labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
|
|
1852
|
+
}
|
|
1853
|
+
};
|
|
1854
|
+
}
|
|
1855
|
+
var prepareExporters = () => void loadMenus().then((m) => m.prepareExporters(), () => void 0);
|
|
1856
|
+
|
|
1857
|
+
// src/use-theme.js
|
|
1858
|
+
import { useCallback as useCallback5, useSyncExternalStore } from "react";
|
|
1859
|
+
function hostTheme(el) {
|
|
1860
|
+
let node = el;
|
|
1861
|
+
while (node) {
|
|
1862
|
+
if (node.nodeType === 1 && /** @type {Element} */
|
|
1863
|
+
node.hasAttribute("data-theme")) {
|
|
1864
|
+
return (
|
|
1865
|
+
/** @type {Element} */
|
|
1866
|
+
node.getAttribute("data-theme")
|
|
1867
|
+
);
|
|
1868
|
+
}
|
|
1869
|
+
node = node.parentNode ?? /** @type {ShadowRoot} */
|
|
1870
|
+
node.host ?? null;
|
|
1871
|
+
}
|
|
1872
|
+
return typeof document !== "undefined" ? document.documentElement.getAttribute("data-theme") : null;
|
|
1873
|
+
}
|
|
1874
|
+
var darkQuery = () => typeof matchMedia === "function" ? matchMedia("(prefers-color-scheme: dark)") : null;
|
|
1875
|
+
function useResolvedTheme(wanted, ref) {
|
|
1876
|
+
const subscribe = useCallback5(
|
|
1877
|
+
(onChange) => {
|
|
1878
|
+
if (wanted === "light" || wanted === "dark" || typeof document === "undefined") {
|
|
1879
|
+
return () => {
|
|
1880
|
+
};
|
|
1881
|
+
}
|
|
1882
|
+
const mo = typeof MutationObserver === "function" ? new MutationObserver(onChange) : null;
|
|
1883
|
+
const options = { attributes: true, attributeFilter: ["data-theme"], subtree: true };
|
|
1884
|
+
mo?.observe(document.documentElement, options);
|
|
1885
|
+
for (let root = ref.current?.getRootNode(); root && root.nodeType === 11; root = /** @type {ShadowRoot} */
|
|
1886
|
+
root.host.getRootNode()) {
|
|
1887
|
+
mo?.observe(root, options);
|
|
1888
|
+
}
|
|
1889
|
+
const mq = darkQuery();
|
|
1890
|
+
mq?.addEventListener("change", onChange);
|
|
1891
|
+
return () => {
|
|
1892
|
+
mo?.disconnect();
|
|
1893
|
+
mq?.removeEventListener("change", onChange);
|
|
1894
|
+
};
|
|
1895
|
+
},
|
|
1896
|
+
[wanted, ref]
|
|
1897
|
+
);
|
|
1898
|
+
const snapshot = () => resolveTheme(wanted, typeof document === "undefined" ? null : hostTheme(ref.current), darkQuery()?.matches ?? false);
|
|
1899
|
+
return useSyncExternalStore(subscribe, snapshot, () => resolveTheme(wanted, null, false));
|
|
1900
|
+
}
|
|
1901
|
+
|
|
1902
|
+
// src/use-view-history.js
|
|
1903
|
+
import { useCallback as useCallback6, useMemo as useMemo6, useState as useState9 } from "react";
|
|
1904
|
+
import { emptyView, normalize } from "pivotkit-core";
|
|
1905
|
+
|
|
1906
|
+
// src/view-history.js
|
|
1907
|
+
var tagFor = (tag, sourceId) => tag && tag.sourceId === sourceId ? tag : null;
|
|
1908
|
+
var HISTORY_LIMIT = 100;
|
|
1909
|
+
function createState(schema, start, current = start, tag = null) {
|
|
1910
|
+
return { schema, start, present: current, past: [], future: [], tag };
|
|
1911
|
+
}
|
|
1912
|
+
function settle(state, at) {
|
|
1913
|
+
let s = state.schema === at.schema ? state : createState(at.schema, at.start, at.shown);
|
|
1914
|
+
if (s.present !== at.shown) {
|
|
1915
|
+
s = record(s, at.shown, at.outside);
|
|
1916
|
+
}
|
|
1917
|
+
return s;
|
|
1918
|
+
}
|
|
1919
|
+
function record(state, view, note, tag = state.tag) {
|
|
1920
|
+
if (view === state.present) {
|
|
1921
|
+
return tag === state.tag ? state : { ...state, tag };
|
|
1922
|
+
}
|
|
1923
|
+
const past = [...state.past, { view: state.present, note, tag: state.tag }].slice(-HISTORY_LIMIT);
|
|
1924
|
+
return { ...state, present: view, past, future: [], tag };
|
|
1925
|
+
}
|
|
1926
|
+
function undo(state) {
|
|
1927
|
+
const last = state.past[state.past.length - 1];
|
|
1928
|
+
if (!last) {
|
|
1929
|
+
return { state, note: null };
|
|
1930
|
+
}
|
|
1931
|
+
return {
|
|
1932
|
+
state: { ...state, present: last.view, tag: last.tag, past: state.past.slice(0, -1), future: [...state.future, { view: state.present, note: last.note, tag: state.tag }] },
|
|
1933
|
+
note: last.note
|
|
1934
|
+
};
|
|
1935
|
+
}
|
|
1936
|
+
function redo(state) {
|
|
1937
|
+
const next = state.future[state.future.length - 1];
|
|
1938
|
+
if (!next) {
|
|
1939
|
+
return { state, note: null };
|
|
1940
|
+
}
|
|
1941
|
+
return {
|
|
1942
|
+
state: { ...state, present: next.view, tag: next.tag, future: state.future.slice(0, -1), past: [...state.past, { view: state.present, note: next.note, tag: state.tag }] },
|
|
1943
|
+
note: next.note
|
|
1944
|
+
};
|
|
1945
|
+
}
|
|
1946
|
+
function reset(state, note) {
|
|
1947
|
+
return record(state, state.start, note, null);
|
|
1948
|
+
}
|
|
1949
|
+
|
|
1950
|
+
// src/use-view-history.js
|
|
1951
|
+
function schemaKeyOf(encoded) {
|
|
1952
|
+
return JSON.stringify(encoded.schema.fields.map((f) => [f.name, f.type]));
|
|
1953
|
+
}
|
|
1954
|
+
function useViewHistory({ encoded, view, defaultView, onViewChange, limits, outsideNote, orderOf }) {
|
|
1955
|
+
const controlled = view !== void 0;
|
|
1956
|
+
const schema = useMemo6(() => schemaKeyOf(encoded), [encoded]);
|
|
1957
|
+
const json = useCallback6(
|
|
1958
|
+
(v) => {
|
|
1959
|
+
const normalized = normalize(v ?? emptyView(), encoded, { limits }).view;
|
|
1960
|
+
const ordered = orderOf ? withHostOrders(normalized, orderOf) : normalized;
|
|
1961
|
+
return JSON.stringify(ordered === normalized ? normalized : normalize(ordered, encoded, { limits }).view);
|
|
1962
|
+
},
|
|
1963
|
+
[encoded, limits, orderOf]
|
|
1964
|
+
);
|
|
1965
|
+
const [initial] = useState9(() => (controlled ? view : defaultView) ?? null);
|
|
1966
|
+
const start = useMemo6(() => json(initial), [json, initial]);
|
|
1967
|
+
const [state, setState] = useState9(() => createState(schema, start));
|
|
1968
|
+
const viewKey = controlled ? JSON.stringify(view) : null;
|
|
1969
|
+
const shown = useMemo6(() => {
|
|
1970
|
+
if (viewKey !== null) {
|
|
1971
|
+
return json(JSON.parse(viewKey));
|
|
1972
|
+
}
|
|
1973
|
+
return state.schema === schema ? state.present : json(JSON.parse(state.present));
|
|
1974
|
+
}, [viewKey, json, state, schema]);
|
|
1975
|
+
const current = useMemo6(() => (
|
|
1976
|
+
/** @type {import("pivotkit-core").View} */
|
|
1977
|
+
JSON.parse(shown)
|
|
1978
|
+
), [shown]);
|
|
1979
|
+
const live = useMemo6(() => settle(state, { schema, start, shown, outside: outsideNote }), [state, schema, start, shown, outsideNote]);
|
|
1980
|
+
const apply = useCallback6(
|
|
1981
|
+
(next) => {
|
|
1982
|
+
setState(next);
|
|
1983
|
+
onViewChange?.(JSON.parse(next.present));
|
|
1984
|
+
},
|
|
1985
|
+
[onViewChange]
|
|
1986
|
+
);
|
|
1987
|
+
const commit = useCallback6(
|
|
1988
|
+
(next, note, tag) => {
|
|
1989
|
+
const s = record(live, json(next), note, tag === void 0 ? live.tag : tag);
|
|
1990
|
+
if (s.present === live.present) {
|
|
1991
|
+
if (s !== live) {
|
|
1992
|
+
setState(s);
|
|
1993
|
+
}
|
|
1994
|
+
return false;
|
|
1995
|
+
}
|
|
1996
|
+
apply(s);
|
|
1997
|
+
return true;
|
|
1998
|
+
},
|
|
1999
|
+
[live, json, apply]
|
|
2000
|
+
);
|
|
2001
|
+
const setTag = useCallback6((tag) => setState((s) => ({ ...s, tag })), []);
|
|
2002
|
+
const undo2 = useCallback6(() => {
|
|
2003
|
+
const { state: s, note } = undo(live);
|
|
2004
|
+
if (note !== null) {
|
|
2005
|
+
apply(s);
|
|
2006
|
+
}
|
|
2007
|
+
return note;
|
|
2008
|
+
}, [live, apply]);
|
|
2009
|
+
const redo2 = useCallback6(() => {
|
|
2010
|
+
const { state: s, note } = redo(live);
|
|
2011
|
+
if (note !== null) {
|
|
2012
|
+
apply(s);
|
|
2013
|
+
}
|
|
2014
|
+
return note;
|
|
2015
|
+
}, [live, apply]);
|
|
2016
|
+
const reset2 = useCallback6(
|
|
2017
|
+
(note) => {
|
|
2018
|
+
const s = reset(live, note);
|
|
2019
|
+
if (s.present !== live.present) {
|
|
2020
|
+
apply(s);
|
|
2021
|
+
} else if (s !== live) {
|
|
2022
|
+
setState(s);
|
|
2023
|
+
}
|
|
2024
|
+
},
|
|
2025
|
+
[live, apply]
|
|
2026
|
+
);
|
|
2027
|
+
const restore = useCallback6((next, tag = null) => apply(createState(schema, start, json(next), tag)), [schema, start, json, apply]);
|
|
2028
|
+
const canUndo = live.past.length > 0;
|
|
2029
|
+
const canRedo = live.future.length > 0;
|
|
2030
|
+
const canReset = live.present !== live.start;
|
|
2031
|
+
return useMemo6(
|
|
2032
|
+
() => ({ view: current, viewKey: shown, tag: live.tag, setTag, commit, undo: undo2, redo: redo2, reset: reset2, restore, keyOf: json, canUndo, canRedo, canReset }),
|
|
2033
|
+
[current, shown, live.tag, setTag, commit, undo2, redo2, reset2, restore, json, canUndo, canRedo, canReset]
|
|
2034
|
+
);
|
|
2035
|
+
}
|
|
2036
|
+
|
|
2037
|
+
// src/use-big-result.js
|
|
2038
|
+
import { useCallback as useCallback7, useEffect as useEffect9, useRef as useRef9, useState as useState10, useSyncExternalStore as useSyncExternalStore2 } from "react";
|
|
2039
|
+
function fullScreenSupported() {
|
|
2040
|
+
return typeof document !== "undefined" && Boolean(document.fullscreenEnabled) && typeof HTMLElement !== "undefined" && typeof HTMLElement.prototype.requestFullscreen === "function";
|
|
2041
|
+
}
|
|
2042
|
+
var never = () => () => {
|
|
2043
|
+
};
|
|
2044
|
+
function useBigResult(root) {
|
|
2045
|
+
const [enlarged, setEnlarged] = useState10(false);
|
|
2046
|
+
const [full, setFull] = useState10(false);
|
|
2047
|
+
const fullOk = useSyncExternalStore2(never, fullScreenSupported, () => false);
|
|
2048
|
+
useEffect9(() => {
|
|
2049
|
+
const el = root.current;
|
|
2050
|
+
if (!el) {
|
|
2051
|
+
return void 0;
|
|
2052
|
+
}
|
|
2053
|
+
const doc = el.ownerDocument;
|
|
2054
|
+
const sync = () => setFull(
|
|
2055
|
+
/** @type {any} */
|
|
2056
|
+
rootOf(el)?.fullscreenElement === el
|
|
2057
|
+
);
|
|
2058
|
+
doc.addEventListener("fullscreenchange", sync);
|
|
2059
|
+
return () => doc.removeEventListener("fullscreenchange", sync);
|
|
2060
|
+
}, [root]);
|
|
2061
|
+
const toggleEnlarged = useCallback7(() => setEnlarged((on) => !on), []);
|
|
2062
|
+
const toggleFull = () => {
|
|
2063
|
+
const el = root.current;
|
|
2064
|
+
if (!el) {
|
|
2065
|
+
return;
|
|
2066
|
+
}
|
|
2067
|
+
if (
|
|
2068
|
+
/** @type {any} */
|
|
2069
|
+
rootOf(el)?.fullscreenElement === el
|
|
2070
|
+
) {
|
|
2071
|
+
el.ownerDocument.exitFullscreen?.().catch(() => void 0);
|
|
2072
|
+
} else {
|
|
2073
|
+
el.requestFullscreen?.().catch(() => void 0);
|
|
2074
|
+
}
|
|
2075
|
+
};
|
|
2076
|
+
return { enlarged, setEnlarged, toggleEnlarged, full, fullOk, toggleFull };
|
|
2077
|
+
}
|
|
2078
|
+
function useFitHeight(root, main, grow) {
|
|
2079
|
+
const fit = useRef9({ need: 0, open: 0, grow });
|
|
2080
|
+
useIsoLayoutEffect(() => {
|
|
2081
|
+
fit.current.grow = grow;
|
|
2082
|
+
measureFit(root.current, main.current, fit);
|
|
2083
|
+
});
|
|
2084
|
+
useIsoLayoutEffect(() => {
|
|
2085
|
+
const el = root.current;
|
|
2086
|
+
if (!el || typeof ResizeObserver !== "function") {
|
|
2087
|
+
return void 0;
|
|
2088
|
+
}
|
|
2089
|
+
let frame = 0;
|
|
2090
|
+
const ro = new ResizeObserver(() => {
|
|
2091
|
+
cancelAnimationFrame(frame);
|
|
2092
|
+
frame = requestAnimationFrame(() => measureFit(root.current, main.current, fit));
|
|
2093
|
+
});
|
|
2094
|
+
ro.observe(el);
|
|
2095
|
+
return () => {
|
|
2096
|
+
cancelAnimationFrame(frame);
|
|
2097
|
+
ro.disconnect();
|
|
2098
|
+
};
|
|
2099
|
+
}, [root, main]);
|
|
2100
|
+
return fit;
|
|
2101
|
+
}
|
|
2102
|
+
function measureFit(el, m, fit) {
|
|
2103
|
+
const result = m?.querySelector(":scope > .pk-result");
|
|
2104
|
+
if (!el || !m || !(result instanceof HTMLElement)) {
|
|
2105
|
+
return;
|
|
2106
|
+
}
|
|
2107
|
+
const least = parseFloat(el.ownerDocument.defaultView?.getComputedStyle(result).getPropertyValue("--pk-result-least") ?? "") || 0;
|
|
2108
|
+
const needMain = m.scrollHeight - result.offsetHeight + least;
|
|
2109
|
+
const need = Math.ceil(el.offsetHeight - m.clientHeight + needMain);
|
|
2110
|
+
if (!el.hasAttribute("data-pk-layout") && !el.hasAttribute("data-pk-enlarged")) {
|
|
2111
|
+
fit.current.open = need;
|
|
2112
|
+
}
|
|
2113
|
+
if (!fit.current.grow) {
|
|
2114
|
+
fit.current.need = 0;
|
|
2115
|
+
el.style.minHeight = "";
|
|
2116
|
+
} else if (Math.abs(need - fit.current.need) > 1) {
|
|
2117
|
+
fit.current.need = need;
|
|
2118
|
+
el.style.minHeight = `${need}px`;
|
|
2119
|
+
}
|
|
2120
|
+
}
|
|
2121
|
+
|
|
2122
|
+
// src/zones.jsx
|
|
2123
|
+
import React11, { useCallback as useCallback8, useEffect as useEffect10, useMemo as useMemo7, useRef as useRef10, useState as useState11 } from "react";
|
|
2124
|
+
import { fieldItems, fieldLabel as fieldLabel4 } from "pivotkit-core";
|
|
2125
|
+
function fieldState(view, field, encoded, locale) {
|
|
2126
|
+
const items = filtersOf(view, field, ["include", "exclude"]).filter((f) => f.type === "include" || f.items.length > 0);
|
|
2127
|
+
let summary = null;
|
|
2128
|
+
if (items.length) {
|
|
2129
|
+
const info = fieldItems(encoded, field, { view, locale });
|
|
2130
|
+
if (info) {
|
|
2131
|
+
const all = info.items.map((i) => i.value);
|
|
2132
|
+
summary = { shown: selectedItems(view, field, all).length, total: all.length };
|
|
2133
|
+
}
|
|
2134
|
+
}
|
|
2135
|
+
const top = filtersOf(view, field, ["top"])[0] ?? null;
|
|
2136
|
+
const condition = filtersOf(view, field, ["value"])[0] ?? null;
|
|
2137
|
+
const other = filtersOf(view, field, ["label"]).length > 0;
|
|
2138
|
+
return { summary, top, condition, other, sort: sortOf(view, field) };
|
|
2139
|
+
}
|
|
2140
|
+
function stateWords(state, view, labels, locale) {
|
|
2141
|
+
if (!state) {
|
|
2142
|
+
return "";
|
|
2143
|
+
}
|
|
2144
|
+
const words = [];
|
|
2145
|
+
if (state.summary) {
|
|
2146
|
+
words.push(`${labels.stateFiltered} ${fill(labels.filterSummary, { shown: state.summary.shown.toLocaleString(locale), total: state.summary.total.toLocaleString(locale) })}`);
|
|
2147
|
+
} else if (state.other) {
|
|
2148
|
+
words.push(labels.stateFiltered);
|
|
2149
|
+
}
|
|
2150
|
+
if (state.top) {
|
|
2151
|
+
words.push(fill(state.top.bottom ? labels.bottomBadge : labels.topBadge, { count: state.top.count.toLocaleString(locale) }));
|
|
2152
|
+
}
|
|
2153
|
+
if (state.condition) {
|
|
2154
|
+
words.push(valueConditionText(view, state.condition, labels, locale));
|
|
2155
|
+
}
|
|
2156
|
+
if (state.sort) {
|
|
2157
|
+
words.push(fill(labels.stateSorted, { order: sortText(view, state.sort, labels) }));
|
|
2158
|
+
}
|
|
2159
|
+
return words.join(", ");
|
|
2160
|
+
}
|
|
2161
|
+
function Badges({ state, view, labels, locale }) {
|
|
2162
|
+
const parts = [];
|
|
2163
|
+
if (state.summary) {
|
|
2164
|
+
const text = fill(labels.filterSummary, { shown: state.summary.shown.toLocaleString(locale), total: state.summary.total.toLocaleString(locale) });
|
|
2165
|
+
parts.push(
|
|
2166
|
+
/* @__PURE__ */ React11.createElement("span", { key: "filter", className: "pk-chip-badge pk-badge-text" }, /* @__PURE__ */ React11.createElement(Icon, { name: "filter", size: 12 }), text)
|
|
2167
|
+
);
|
|
2168
|
+
} else if (state.other) {
|
|
2169
|
+
parts.push(/* @__PURE__ */ React11.createElement(Icon, { key: "filter", name: "filter", size: 12, className: "pk-chip-badge" }));
|
|
2170
|
+
}
|
|
2171
|
+
if (state.top) {
|
|
2172
|
+
const text = fill(state.top.bottom ? labels.bottomBadge : labels.topBadge, { count: state.top.count.toLocaleString(locale) });
|
|
2173
|
+
parts.push(
|
|
2174
|
+
/* @__PURE__ */ React11.createElement("span", { key: "top", className: "pk-chip-badge pk-badge-text", "data-testid": "top-badge" }, /* @__PURE__ */ React11.createElement(Icon, { name: "top", size: 12 }), text)
|
|
2175
|
+
);
|
|
2176
|
+
}
|
|
2177
|
+
if (state.condition) {
|
|
2178
|
+
const text = valueConditionText(view, state.condition, labels, locale);
|
|
2179
|
+
parts.push(
|
|
2180
|
+
/* @__PURE__ */ React11.createElement("span", { key: "condition", className: "pk-chip-badge pk-badge-text pk-badge-condition", "data-testid": "condition-badge", title: text }, /* @__PURE__ */ React11.createElement(Icon, { name: "filter", size: 12 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-badge-cut" }, text))
|
|
2181
|
+
);
|
|
2182
|
+
}
|
|
2183
|
+
if (state.sort) {
|
|
2184
|
+
const desc = state.sort.order === "desc";
|
|
2185
|
+
parts.push(/* @__PURE__ */ React11.createElement(Icon, { key: "sort", name: desc ? "sortDesc" : "sortAsc", size: 12, className: "pk-chip-badge" }));
|
|
2186
|
+
}
|
|
2187
|
+
if (!parts.length) {
|
|
2188
|
+
return null;
|
|
2189
|
+
}
|
|
2190
|
+
return /* @__PURE__ */ React11.createElement("span", { className: "pk-badges-inline", "aria-hidden": "true" }, parts);
|
|
2191
|
+
}
|
|
2192
|
+
function Chip({ id, zone, index, count, field, text, typeName, view, types, labels, commit, openFilter, onRemove, state, locale, defaultsOf, rangeOf, info, showInfo }) {
|
|
2193
|
+
const { setNodeRef, isDragging, style, itemProps, handleProps } = useChip(id, { kind: "chip", zone, index, count, field, label: text, type: typeName });
|
|
2194
|
+
const chipRef = useRef10(
|
|
2195
|
+
/** @type {HTMLElement | null} */
|
|
2196
|
+
null
|
|
2197
|
+
);
|
|
2198
|
+
const ref = (el) => {
|
|
2199
|
+
chipRef.current = el;
|
|
2200
|
+
setNodeRef(el);
|
|
2201
|
+
};
|
|
2202
|
+
const badges = state ? /* @__PURE__ */ React11.createElement(Badges, { state, view, labels, locale }) : null;
|
|
2203
|
+
const words = stateWords(state, view, labels, locale);
|
|
2204
|
+
const name = words ? `${text}, ${words}` : void 0;
|
|
2205
|
+
const remove = () => onRemove(zone, index, text);
|
|
2206
|
+
return /* @__PURE__ */ React11.createElement("li", { ref, style, className: `pk-chip pk-chip-${zone}${isDragging ? " pk-dragging" : ""}`, ...itemProps, "data-chip": text }, /* @__PURE__ */ React11.createElement("span", { className: "pk-handle", ...handleProps, "aria-label": fill(labels.dragHandle, { field: text }) }, /* @__PURE__ */ React11.createElement(Icon, { name: "grip", size: 16 })), /* @__PURE__ */ React11.createElement("span", { className: `pk-type pk-type-${typeName}`, "aria-hidden": "true" }, /* @__PURE__ */ React11.createElement(Icon, { name: (
|
|
2207
|
+
/** @type {any} */
|
|
2208
|
+
TYPE_ICON[typeName] ?? "text"
|
|
2209
|
+
), size: 13 })), zone === "filters" ? /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-chip-label", onClick: (e) => openFilter(field, e.currentTarget.closest(".pk-chip")), title: fill(labels.filterTitle, { field: text }), "aria-label": name }, /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, /* @__PURE__ */ React11.createElement("span", { className: "pk-chip-name" }, text), badges)) : /* @__PURE__ */ React11.createElement(
|
|
2210
|
+
MenuButton,
|
|
2211
|
+
{
|
|
2212
|
+
label: fill(labels.fieldMenu, { field: text }),
|
|
2213
|
+
text: /* @__PURE__ */ React11.createElement(React11.Fragment, null, /* @__PURE__ */ React11.createElement("span", { className: "pk-chip-name" }, text), badges),
|
|
2214
|
+
className: "pk-chip-label",
|
|
2215
|
+
name,
|
|
2216
|
+
role: "dialog",
|
|
2217
|
+
popoverClass: "pk-chip-menu",
|
|
2218
|
+
fill: true,
|
|
2219
|
+
testId: `chip-menu-${text}`
|
|
2220
|
+
},
|
|
2221
|
+
(close) => zone === "values" ? /* @__PURE__ */ React11.createElement(MenuPanel, { name: "ValueMenu", loadingText: labels.loadingMenu, props: { view, index, types, labels, commit, close, onRemove: remove, defaultsOf, info } }) : /* @__PURE__ */ React11.createElement(MenuPanel, { name: "AxisMenu", loadingText: labels.loadingMenu, props: { view, zone, index, field, types, labels, commit, close, openFilter, chipRef, onRemove: remove, defaultsOf, rangeOf, locale, info, state } })
|
|
2222
|
+
), info && showInfo ? /* @__PURE__ */ React11.createElement(InfoButton, { info, name: fieldLabel4(sourceOf(view, field), labels.core), labels, className: "pk-chip-info" }) : null, /* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-chip-x", onClick: remove, "aria-label": fill(labels.removeField, { field: text }), title: fill(labels.removeField, { field: text }) }, /* @__PURE__ */ React11.createElement(Icon, { name: "x", size: 14 })));
|
|
2223
|
+
}
|
|
2224
|
+
function Zone({ zone, entries, labels, children, action, explain }) {
|
|
2225
|
+
const count = entries.length;
|
|
2226
|
+
const { setNodeRef, isOver } = useDropTarget(`zone:${zone}`, { kind: "zone", zone, count });
|
|
2227
|
+
const active = useActiveDrag();
|
|
2228
|
+
const dragging = Boolean(active);
|
|
2229
|
+
const [flash, setFlash] = useState11(false);
|
|
2230
|
+
const [prev, setPrev] = useState11(count);
|
|
2231
|
+
if (count !== prev) {
|
|
2232
|
+
setPrev(count);
|
|
2233
|
+
if (count > prev) {
|
|
2234
|
+
setFlash(true);
|
|
2235
|
+
}
|
|
2236
|
+
}
|
|
2237
|
+
useEffect10(() => {
|
|
2238
|
+
if (!flash) {
|
|
2239
|
+
return void 0;
|
|
2240
|
+
}
|
|
2241
|
+
const t = setTimeout(() => setFlash(false), 600);
|
|
2242
|
+
return () => clearTimeout(t);
|
|
2243
|
+
}, [flash]);
|
|
2244
|
+
return /* @__PURE__ */ React11.createElement("section", { ref: setNodeRef, tabIndex: -1, className: `pk-zone pk-zone-${zone}${isOver ? " pk-over" : ""}${dragging ? " pk-dropping" : ""}${flash ? " pk-flash" : ""}`, "aria-label": labels.zones[zone], "data-zone": zone }, /* @__PURE__ */ React11.createElement("div", { className: "pk-zone-head" }, /* @__PURE__ */ React11.createElement("h3", { className: "pk-zone-title" }, /* @__PURE__ */ React11.createElement(Icon, { name: (
|
|
2245
|
+
/** @type {any} */
|
|
2246
|
+
ZONE_ICON[zone]
|
|
2247
|
+
), size: 14 }), labels.zones[zone]), explain ? /* @__PURE__ */ React11.createElement(InfoButton, { info: { description: labels.zoneInfo[zone] }, name: labels.zones[zone], labels, className: "pk-zone-info", testId: `zone-info-${zone}` }) : null, /* @__PURE__ */ React11.createElement("span", { className: "pk-grow" }), action), /* @__PURE__ */ React11.createElement(ChipList, { ids: entries.map((e) => e.id) }, /* @__PURE__ */ React11.createElement("ul", { className: "pk-chips" }, children, count === 0 ? /* @__PURE__ */ React11.createElement("li", { className: "pk-zone-hint" }, labels.zoneHints[zone]) : null)));
|
|
2248
|
+
}
|
|
2249
|
+
function zoneEntries(view, types, labels) {
|
|
2250
|
+
const typeOf = (f) => types.get(String(sourceOf(view, f)).toLowerCase()) ?? "string";
|
|
2251
|
+
const seen = /* @__PURE__ */ new Map();
|
|
2252
|
+
const text = (f) => fieldLabel4(f, labels.core);
|
|
2253
|
+
const axis = (zone) => view[zone].map((f, i) => ({ id: `chip:${zone}:${f}`, field: f, text: text(f), type: typeOf(f), index: i }));
|
|
2254
|
+
return {
|
|
2255
|
+
filters: filterZoneFields(view).map((f, i) => ({ id: `chip:filters:${f}`, field: f, text: text(f), type: typeOf(f), index: i })),
|
|
2256
|
+
cols: axis("cols"),
|
|
2257
|
+
rows: axis("rows"),
|
|
2258
|
+
values: view.values.map((v, i) => {
|
|
2259
|
+
const key = `${v.agg}:${v.field}`;
|
|
2260
|
+
seen.set(key, (seen.get(key) ?? 0) + 1);
|
|
2261
|
+
return { id: `chip:values:${key}:${seen.get(key)}`, field: v.field, text: valueLabel(v, labels), type: v.field ? typeOf(v.field) : "number", index: i };
|
|
2262
|
+
})
|
|
2263
|
+
};
|
|
2264
|
+
}
|
|
2265
|
+
function ZoneSummary({ entries, labels, id, onShow, buttonRef }) {
|
|
2266
|
+
const parts = layoutSummary(entries, labels);
|
|
2267
|
+
const text = parts.length ? parts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
|
|
2268
|
+
return /* @__PURE__ */ React11.createElement("button", { ref: buttonRef, type: "button", id, className: "pk-zones-summary", "aria-expanded": "false", "aria-label": `${labels.showLayout}: ${text}`, title: labels.showLayout, onClick: onShow, "data-testid": "layout-summary" }, /* @__PURE__ */ React11.createElement(Icon, { name: "chevronRight", size: 16 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-zones-summary-text" }, parts.length ? parts.map((p, i) => /* @__PURE__ */ React11.createElement(React11.Fragment, { key: p.zone }, i ? /* @__PURE__ */ React11.createElement("span", { "aria-hidden": "true" }, " \xB7 ") : null, /* @__PURE__ */ React11.createElement("span", { className: "pk-zones-summary-zone" }, p.title, ":"), " ", p.fields)) : labels.layoutEmpty));
|
|
2269
|
+
}
|
|
2270
|
+
function Zones({ view, types, labels, commit, openFilter, encoded, locale, onSwap, id, folded, onShow, defaultsOf, infoOf, explain = false, showInfo = true }) {
|
|
2271
|
+
const entries = useMemo7(() => zoneEntries(view, types, labels), [view, types, labels]);
|
|
2272
|
+
const dragging = Boolean(useActiveDrag());
|
|
2273
|
+
const showing = useRef10(false);
|
|
2274
|
+
const focusInside = useRef10(false);
|
|
2275
|
+
const summary = useRef10(
|
|
2276
|
+
/** @type {HTMLButtonElement | null} */
|
|
2277
|
+
null
|
|
2278
|
+
);
|
|
2279
|
+
const states = useMemo7(() => {
|
|
2280
|
+
const map = /* @__PURE__ */ new Map();
|
|
2281
|
+
for (const zone of ["filters", "cols", "rows"]) {
|
|
2282
|
+
for (const e of entries[zone]) {
|
|
2283
|
+
map.set(e.field, fieldState(view, e.field, encoded, locale));
|
|
2284
|
+
}
|
|
2285
|
+
}
|
|
2286
|
+
return map;
|
|
2287
|
+
}, [entries, view, encoded, locale]);
|
|
2288
|
+
const rangeOf = useCallback8((field) => numberRange(encoded, field), [encoded]);
|
|
2289
|
+
const root = useRef10(
|
|
2290
|
+
/** @type {HTMLDivElement | null} */
|
|
2291
|
+
null
|
|
2292
|
+
);
|
|
2293
|
+
const focusAfter = useRef10(
|
|
2294
|
+
/** @type {{ zone: string, index: number } | null} */
|
|
2295
|
+
null
|
|
2296
|
+
);
|
|
2297
|
+
const onRemove = (zone, index, text) => {
|
|
2298
|
+
focusAfter.current = { zone, index };
|
|
2299
|
+
commit(removeAt(view, zone, index), { step: "removed", field: text, removed: true });
|
|
2300
|
+
};
|
|
2301
|
+
useEffect10(() => {
|
|
2302
|
+
const at = focusAfter.current;
|
|
2303
|
+
if (!at || !root.current) {
|
|
2304
|
+
return;
|
|
2305
|
+
}
|
|
2306
|
+
focusAfter.current = null;
|
|
2307
|
+
const zone = root.current.querySelector(`[data-zone="${at.zone}"]`);
|
|
2308
|
+
const chips = zone ? [...zone.querySelectorAll(".pk-chip .pk-chip-label")] : [];
|
|
2309
|
+
const target = (
|
|
2310
|
+
/** @type {HTMLElement | null} */
|
|
2311
|
+
chips[Math.min(at.index, chips.length - 1)] ?? zone
|
|
2312
|
+
);
|
|
2313
|
+
target?.focus({ preventScroll: true });
|
|
2314
|
+
});
|
|
2315
|
+
useEffect10(() => {
|
|
2316
|
+
if (showing.current && !folded) {
|
|
2317
|
+
showing.current = false;
|
|
2318
|
+
root.current?.querySelector("[data-zone]")?.focus({ preventScroll: true });
|
|
2319
|
+
}
|
|
2320
|
+
if (folded && focusInside.current) {
|
|
2321
|
+
focusInside.current = false;
|
|
2322
|
+
summary.current?.focus({ preventScroll: true });
|
|
2323
|
+
}
|
|
2324
|
+
}, [folded]);
|
|
2325
|
+
if (folded && !dragging) {
|
|
2326
|
+
return /* @__PURE__ */ React11.createElement(
|
|
2327
|
+
ZoneSummary,
|
|
2328
|
+
{
|
|
2329
|
+
entries,
|
|
2330
|
+
labels,
|
|
2331
|
+
id,
|
|
2332
|
+
buttonRef: summary,
|
|
2333
|
+
onShow: () => {
|
|
2334
|
+
showing.current = true;
|
|
2335
|
+
onShow();
|
|
2336
|
+
}
|
|
2337
|
+
}
|
|
2338
|
+
);
|
|
2339
|
+
}
|
|
2340
|
+
return /* @__PURE__ */ React11.createElement(
|
|
2341
|
+
"div",
|
|
2342
|
+
{
|
|
2343
|
+
className: "pk-zones",
|
|
2344
|
+
ref: root,
|
|
2345
|
+
id,
|
|
2346
|
+
onFocus: () => {
|
|
2347
|
+
focusInside.current = true;
|
|
2348
|
+
},
|
|
2349
|
+
onBlur: (e) => {
|
|
2350
|
+
if (e.relatedTarget && !e.currentTarget.contains(
|
|
2351
|
+
/** @type {Node} */
|
|
2352
|
+
e.relatedTarget
|
|
2353
|
+
)) {
|
|
2354
|
+
focusInside.current = false;
|
|
2355
|
+
}
|
|
2356
|
+
}
|
|
2357
|
+
},
|
|
2358
|
+
ZONES.map((zone) => /* @__PURE__ */ React11.createElement(
|
|
2359
|
+
Zone,
|
|
2360
|
+
{
|
|
2361
|
+
key: zone,
|
|
2362
|
+
zone,
|
|
2363
|
+
entries: entries[zone],
|
|
2364
|
+
labels,
|
|
2365
|
+
explain,
|
|
2366
|
+
action: zone === "cols" ? (
|
|
2367
|
+
// the text goes when the zone is too narrow (styles.css): the title keeps it as a tooltip
|
|
2368
|
+
/* @__PURE__ */ React11.createElement("button", { type: "button", className: "pk-link pk-swap", onClick: onSwap, disabled: view.rows.length + view.cols.length === 0, "data-testid": "swap", title: labels.swap }, /* @__PURE__ */ React11.createElement(Icon, { name: "swap", size: 14 }), /* @__PURE__ */ React11.createElement("span", { className: "pk-btn-text" }, labels.swap))
|
|
2369
|
+
) : null
|
|
2370
|
+
},
|
|
2371
|
+
entries[zone].map((e) => /* @__PURE__ */ React11.createElement(
|
|
2372
|
+
Chip,
|
|
2373
|
+
{
|
|
2374
|
+
key: e.id,
|
|
2375
|
+
id: e.id,
|
|
2376
|
+
zone,
|
|
2377
|
+
index: e.index,
|
|
2378
|
+
count: entries[zone].length,
|
|
2379
|
+
field: e.field,
|
|
2380
|
+
text: e.text,
|
|
2381
|
+
typeName: e.type,
|
|
2382
|
+
view,
|
|
2383
|
+
types,
|
|
2384
|
+
labels,
|
|
2385
|
+
commit,
|
|
2386
|
+
openFilter,
|
|
2387
|
+
onRemove,
|
|
2388
|
+
state: zone === "values" ? null : states.get(e.field),
|
|
2389
|
+
locale,
|
|
2390
|
+
defaultsOf,
|
|
2391
|
+
rangeOf,
|
|
2392
|
+
info: e.field ? infoOf?.(e.field) : void 0,
|
|
2393
|
+
showInfo
|
|
2394
|
+
}
|
|
2395
|
+
))
|
|
2396
|
+
))
|
|
2397
|
+
);
|
|
2398
|
+
}
|
|
2399
|
+
|
|
2400
|
+
// src/PivotReport.jsx
|
|
2401
|
+
var savedKeyOf = (t) => JSON.stringify([t.scope, t.store, t.storeSource ?? null, t.sourceId ?? null, t.name]);
|
|
2402
|
+
function sizeOf(width) {
|
|
2403
|
+
return width < 640 ? "narrow" : width < 1024 ? "medium" : "wide";
|
|
2404
|
+
}
|
|
2405
|
+
var COMPACT_HEIGHT = 600;
|
|
2406
|
+
var COMPACT_HEIGHT_NARROW = 820;
|
|
2407
|
+
var compactAt = (size, height) => height < (size === "narrow" ? COMPACT_HEIGHT_NARROW : COMPACT_HEIGHT);
|
|
2408
|
+
var layerOpen = (layer) => Boolean(layer && [...layer.children].some((c) => !c.classList.contains("pk-origin")));
|
|
2409
|
+
function measured(name, fn) {
|
|
2410
|
+
const t0 = typeof performance !== "undefined" ? performance.now() : 0;
|
|
2411
|
+
const out = fn();
|
|
2412
|
+
if (typeof performance !== "undefined" && typeof performance.measure === "function") {
|
|
2413
|
+
try {
|
|
2414
|
+
performance.measure(`pivotkit:${name}`, { start: t0, end: performance.now() });
|
|
2415
|
+
} catch {
|
|
2416
|
+
}
|
|
2417
|
+
}
|
|
2418
|
+
return out;
|
|
2419
|
+
}
|
|
2420
|
+
function outerPaths(result) {
|
|
2421
|
+
const depth = result.rowFields.length;
|
|
2422
|
+
const out = [];
|
|
2423
|
+
const walk = (node) => {
|
|
2424
|
+
if (node.depth > 0 && node.depth < depth) {
|
|
2425
|
+
out.push(node.path);
|
|
2426
|
+
}
|
|
2427
|
+
if (node.depth < depth - 1) {
|
|
2428
|
+
node.children.forEach(walk);
|
|
2429
|
+
}
|
|
2430
|
+
};
|
|
2431
|
+
walk(result.rowRoot);
|
|
2432
|
+
return out;
|
|
2433
|
+
}
|
|
2434
|
+
function sessionStore() {
|
|
2435
|
+
try {
|
|
2436
|
+
return typeof window !== "undefined" && window.sessionStorage ? window.sessionStorage : null;
|
|
2437
|
+
} catch {
|
|
2438
|
+
return null;
|
|
2439
|
+
}
|
|
2440
|
+
}
|
|
2441
|
+
var warned = /* @__PURE__ */ new Set();
|
|
2442
|
+
var warnOnce = (text) => {
|
|
2443
|
+
if (!warned.has(text)) {
|
|
2444
|
+
warned.add(text);
|
|
2445
|
+
console.warn(text);
|
|
2446
|
+
}
|
|
2447
|
+
};
|
|
2448
|
+
function optionsKey(options) {
|
|
2449
|
+
try {
|
|
2450
|
+
return JSON.stringify(options ?? null, (k, v) => ["function", "symbol", "bigint"].includes(typeof v) ? `\0${typeof v}` : v);
|
|
2451
|
+
} catch {
|
|
2452
|
+
return options;
|
|
2453
|
+
}
|
|
2454
|
+
}
|
|
2455
|
+
var here = () => typeof location !== "undefined" ? { href: location.href, hash: location.hash } : void 0;
|
|
2456
|
+
var DEFER_ROWS = 1e4;
|
|
2457
|
+
var unusedNotes = (issues, raw) => issues.filter((i) => (i.code ?? (i.message === "unknown key" ? "unknownKey" : "")) !== "unknownKey" || !["name", "description"].includes(i.path)).map((issue) => ({ issue, raw }));
|
|
2458
|
+
function PivotReport(props) {
|
|
2459
|
+
const { loading: loading2 = false, data, encoded } = props;
|
|
2460
|
+
const [deferred, setDeferred] = useState12(() => !encoded && Array.isArray(data) && data.length > DEFER_ROWS);
|
|
2461
|
+
const [started, setStarted] = useState12(false);
|
|
2462
|
+
useEffect11(() => {
|
|
2463
|
+
if (!deferred) {
|
|
2464
|
+
return void 0;
|
|
2465
|
+
}
|
|
2466
|
+
let timer = 0;
|
|
2467
|
+
const frame = requestAnimationFrame(() => {
|
|
2468
|
+
timer = window.setTimeout(() => setDeferred(false), 0);
|
|
2469
|
+
});
|
|
2470
|
+
return () => {
|
|
2471
|
+
cancelAnimationFrame(frame);
|
|
2472
|
+
clearTimeout(timer);
|
|
2473
|
+
};
|
|
2474
|
+
}, [deferred]);
|
|
2475
|
+
const waiting = Boolean(loading2) || deferred;
|
|
2476
|
+
if (!waiting && !started) {
|
|
2477
|
+
setStarted(true);
|
|
2478
|
+
}
|
|
2479
|
+
if (waiting && !started) {
|
|
2480
|
+
return /* @__PURE__ */ React12.createElement(WaitingReport, { ...props });
|
|
2481
|
+
}
|
|
2482
|
+
return /* @__PURE__ */ React12.createElement(Report, { ...props });
|
|
2483
|
+
}
|
|
2484
|
+
function WaitingReport({ locale = "en-US", labels: customLabels, theme = "auto", height = 640, className, label }) {
|
|
2485
|
+
const root = useRef11(
|
|
2486
|
+
/** @type {HTMLDivElement | null} */
|
|
2487
|
+
null
|
|
2488
|
+
);
|
|
2489
|
+
const labelsKey = JSON.stringify(customLabels ?? null);
|
|
2490
|
+
const labels = useMemo8(() => resolveLabels(locale, JSON.parse(labelsKey)), [locale, labelsKey]);
|
|
2491
|
+
const themeName = useResolvedTheme(theme, root);
|
|
2492
|
+
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 }));
|
|
2493
|
+
}
|
|
2494
|
+
function defaultsFor(fieldDefaults, field) {
|
|
2495
|
+
if (!fieldDefaults || typeof fieldDefaults !== "object") {
|
|
2496
|
+
return void 0;
|
|
2497
|
+
}
|
|
2498
|
+
const key = Object.keys(fieldDefaults).find((k) => k.toLowerCase() === String(field).toLowerCase());
|
|
2499
|
+
return key === void 0 ? void 0 : fieldDefaults[key];
|
|
2500
|
+
}
|
|
2501
|
+
function EmptyState({ labels, templates, onTemplate }) {
|
|
2502
|
+
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, labels.emptyTitle), /* @__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)))), 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);
|
|
2503
|
+
}
|
|
2504
|
+
function Report(props) {
|
|
2505
|
+
const {
|
|
2506
|
+
data,
|
|
2507
|
+
dataKey,
|
|
2508
|
+
encoded: encodedProp,
|
|
2509
|
+
view: viewProp,
|
|
2510
|
+
defaultView,
|
|
2511
|
+
onViewChange,
|
|
2512
|
+
templates = [],
|
|
2513
|
+
onSaveTemplate,
|
|
2514
|
+
onDeleteTemplate,
|
|
2515
|
+
onPublishTemplate,
|
|
2516
|
+
canPublish = false,
|
|
2517
|
+
templateStore,
|
|
2518
|
+
onCellClick,
|
|
2519
|
+
drillDown = true,
|
|
2520
|
+
drillDownLimit = DRILL_LIMIT,
|
|
2521
|
+
locale = "en-US",
|
|
2522
|
+
timeZone,
|
|
2523
|
+
labels: customLabels,
|
|
2524
|
+
theme = "auto",
|
|
2525
|
+
height = 640,
|
|
2526
|
+
limits: limitsProp,
|
|
2527
|
+
className,
|
|
2528
|
+
fileName = "pivot",
|
|
2529
|
+
fieldDefaults,
|
|
2530
|
+
onExport,
|
|
2531
|
+
label,
|
|
2532
|
+
tips: tipsProp = "on",
|
|
2533
|
+
storageKey,
|
|
2534
|
+
dismissedTips,
|
|
2535
|
+
onTipDismiss,
|
|
2536
|
+
chartOptions,
|
|
2537
|
+
shareLink,
|
|
2538
|
+
persistView,
|
|
2539
|
+
fieldInfo: fieldInfoProp,
|
|
2540
|
+
zoneInfo: zoneInfoProp,
|
|
2541
|
+
settingInfo: settingInfoProp,
|
|
2542
|
+
source: sourceProp,
|
|
2543
|
+
sources,
|
|
2544
|
+
onSourceSwitch,
|
|
2545
|
+
schemaUrl,
|
|
2546
|
+
grow: growProp,
|
|
2547
|
+
fieldList,
|
|
2548
|
+
loading: loading2 = false
|
|
2549
|
+
} = props;
|
|
2550
|
+
const grow = growProp === "on" || growProp !== "off" && props.height === void 0;
|
|
2551
|
+
const sourceId = typeof sourceProp?.id === "string" && sourceProp.id ? sourceProp.id : void 0;
|
|
2552
|
+
const sourceName = typeof sourceProp?.name === "string" && sourceProp.name ? sourceProp.name : void 0;
|
|
2553
|
+
const labelsKey = JSON.stringify(customLabels ?? null);
|
|
2554
|
+
const defaultsKey = JSON.stringify(fieldDefaults ?? null);
|
|
2555
|
+
const info = useMemo8(() => fieldInfoOf(JSON.parse(defaultsKey)), [defaultsKey]);
|
|
2556
|
+
const baseLabels = useMemo8(() => resolveLabels(locale, JSON.parse(labelsKey)), [locale, labelsKey]);
|
|
2557
|
+
const typesKey = JSON.stringify(typesOf(fieldDefaults));
|
|
2558
|
+
const limitsKey = JSON.stringify(limitsProp ?? null);
|
|
2559
|
+
const limits = useMemo8(() => JSON.parse(limitsKey) ?? void 0, [limitsKey]);
|
|
2560
|
+
const root = useRef11(
|
|
2561
|
+
/** @type {HTMLDivElement | null} */
|
|
2562
|
+
null
|
|
2563
|
+
);
|
|
2564
|
+
const themeName = useResolvedTheme(theme, root);
|
|
2565
|
+
const [layer, setLayer] = useState12(
|
|
2566
|
+
/** @type {HTMLElement | null} */
|
|
2567
|
+
null
|
|
2568
|
+
);
|
|
2569
|
+
const [size, setSize] = useState12("wide");
|
|
2570
|
+
const [measuredShort, setMeasuredShort] = useState12(false);
|
|
2571
|
+
const [short, setShort] = useState12(false);
|
|
2572
|
+
const [folded, setFolded] = useState12(
|
|
2573
|
+
/** @type {boolean | null} */
|
|
2574
|
+
null
|
|
2575
|
+
);
|
|
2576
|
+
const layoutFolded = folded ?? short;
|
|
2577
|
+
const zonesId = useId4();
|
|
2578
|
+
const [drawer, setDrawer] = useState12(false);
|
|
2579
|
+
const [filterTarget, setFilterTarget] = useState12(
|
|
2580
|
+
/** @type {{ field: string, anchor: HTMLElement, base?: object } | null} */
|
|
2581
|
+
null
|
|
2582
|
+
);
|
|
2583
|
+
const [drill, setDrill] = useState12(
|
|
2584
|
+
/** @type {import("./drill-table.js").DrillSource | null} */
|
|
2585
|
+
null
|
|
2586
|
+
);
|
|
2587
|
+
const [hinted, setHinted] = useState12(false);
|
|
2588
|
+
const changesRef = useRef11(0);
|
|
2589
|
+
const [changes, setChanges] = useState12(0);
|
|
2590
|
+
const [dragAt, setDragAt] = useState12(
|
|
2591
|
+
/** @type {number | null} */
|
|
2592
|
+
null
|
|
2593
|
+
);
|
|
2594
|
+
const [savedAt, setSavedAt] = useState12(0);
|
|
2595
|
+
const [menus, setMenus] = useState12(
|
|
2596
|
+
/** @type {typeof import("./menus.js") | null} */
|
|
2597
|
+
null
|
|
2598
|
+
);
|
|
2599
|
+
const [, setTexts] = useState12(0);
|
|
2600
|
+
useEffect11(() => onMenuTexts(() => setTexts((n) => n + 1)), []);
|
|
2601
|
+
const [viewsRequest, setViewsRequest] = useState12(0);
|
|
2602
|
+
const [leftOut, setLeftOut] = useState12(
|
|
2603
|
+
/** @type {import("./unused.jsx").UnusedNote[]} */
|
|
2604
|
+
[]
|
|
2605
|
+
);
|
|
2606
|
+
const [issuesDismissed, setIssuesDismissed] = useState12(
|
|
2607
|
+
/** @type {string | null} */
|
|
2608
|
+
null
|
|
2609
|
+
);
|
|
2610
|
+
const [loads, setLoads] = useState12(0);
|
|
2611
|
+
const [unusedSaid, setUnusedSaid] = useState12(false);
|
|
2612
|
+
const [savedKeys, setSavedKeys] = useState12(
|
|
2613
|
+
/** @type {Record<string, string>} */
|
|
2614
|
+
{}
|
|
2615
|
+
);
|
|
2616
|
+
const [rowLabel, setRowLabel] = useState12(
|
|
2617
|
+
/** @type {string | null} */
|
|
2618
|
+
null
|
|
2619
|
+
);
|
|
2620
|
+
const chartRef = useRef11(null);
|
|
2621
|
+
const [chartReady, setChartReady] = useState12(false);
|
|
2622
|
+
const hintId = useId4();
|
|
2623
|
+
const closeFilter = useCallback9(() => setFilterTarget(null), []);
|
|
2624
|
+
const { toasts, push, dismiss, pause } = useToasts();
|
|
2625
|
+
const announce = useCallback9(
|
|
2626
|
+
/** @param {string} text @param {{ action?: { label: string, run: () => void }, tone?: "error" }} [extra] */
|
|
2627
|
+
(text, extra) => push({ text, ...extra }),
|
|
2628
|
+
[push]
|
|
2629
|
+
);
|
|
2630
|
+
const dataIdentity = dataKey !== void 0 ? dataKey : data;
|
|
2631
|
+
const source = useMemo8(() => {
|
|
2632
|
+
try {
|
|
2633
|
+
const types2 = JSON.parse(typesKey);
|
|
2634
|
+
const enc = encodedProp ?? measured("encode", () => encode(
|
|
2635
|
+
/** @type {any[]} */
|
|
2636
|
+
Array.isArray(data) ? data : [],
|
|
2637
|
+
{ timeZone: timeZone ?? "UTC", limits, ...types2 ? { types: types2 } : {} }
|
|
2638
|
+
));
|
|
2639
|
+
return { encoded: enc, error: null };
|
|
2640
|
+
} catch (error2) {
|
|
2641
|
+
return { encoded: encode([]), error: error2 };
|
|
2642
|
+
}
|
|
2643
|
+
}, [encodedProp, dataIdentity, timeZone, limits, typesKey]);
|
|
2644
|
+
const encoded = source.encoded;
|
|
2645
|
+
const fieldNamesKey = encoded.schema.fields.map((f) => f.name).join("\0");
|
|
2646
|
+
const labels = useMemo8(() => {
|
|
2647
|
+
const fields2 = displayNames(info, fieldNamesKey ? fieldNamesKey.split("\0") : []);
|
|
2648
|
+
return fields2 ? { ...baseLabels, core: { ...baseLabels.core, fields: fields2 } } : baseLabels;
|
|
2649
|
+
}, [baseLabels, info, fieldNamesKey]);
|
|
2650
|
+
const ordersKey = JSON.stringify(
|
|
2651
|
+
fieldDefaults && typeof fieldDefaults === "object" ? Object.entries(fieldDefaults).filter(([, d]) => d && Array.isArray(d.order) && d.order.length > 0).map(([field, d]) => [field, d.order]) : []
|
|
2652
|
+
);
|
|
2653
|
+
const orderOf = useMemo8(() => {
|
|
2654
|
+
const orders = (
|
|
2655
|
+
/** @type {[string, unknown[]][]} */
|
|
2656
|
+
JSON.parse(ordersKey)
|
|
2657
|
+
);
|
|
2658
|
+
if (!orders.length) {
|
|
2659
|
+
return void 0;
|
|
2660
|
+
}
|
|
2661
|
+
return (field) => orders.find(([name]) => name.toLowerCase() === field.toLowerCase())?.[1];
|
|
2662
|
+
}, [ordersKey]);
|
|
2663
|
+
const history = useViewHistory({ encoded, view: viewProp, defaultView, onViewChange, limits, outsideNote: labels.steps.outside, orderOf });
|
|
2664
|
+
const view = history.view;
|
|
2665
|
+
const loadedView = tagFor(history.tag, sourceId);
|
|
2666
|
+
const viewName = loadedView?.name ?? null;
|
|
2667
|
+
const unsaved = Boolean(loadedView) && savedKeys[savedKeyOf(loadedView)] !== history.viewKey;
|
|
2668
|
+
const chartOptionsKey = optionsKey(chartOptions);
|
|
2669
|
+
const stableChartOptions = useMemo8(() => chartOptions, [chartOptionsKey]);
|
|
2670
|
+
const stepText = useCallback9(
|
|
2671
|
+
(note) => {
|
|
2672
|
+
const template = Object.hasOwn(labels.steps, note.step) ? labels.steps[note.step] : labels.steps.change;
|
|
2673
|
+
return fill(template, {
|
|
2674
|
+
field: note.field ?? "",
|
|
2675
|
+
name: note.name ?? "",
|
|
2676
|
+
zone: labels.zones[note.zone] ?? note.zone ?? "",
|
|
2677
|
+
display: note.display ? labels[note.display] : "",
|
|
2678
|
+
type: note.type ? labels.chartTypes[note.type] : ""
|
|
2679
|
+
});
|
|
2680
|
+
},
|
|
2681
|
+
[labels]
|
|
2682
|
+
);
|
|
2683
|
+
const undo2 = useCallback9(() => {
|
|
2684
|
+
const note = history.undo();
|
|
2685
|
+
if (note !== null) {
|
|
2686
|
+
announce(fill(labels.toastUndone, { step: note }));
|
|
2687
|
+
}
|
|
2688
|
+
}, [history, labels, announce]);
|
|
2689
|
+
const redo2 = useCallback9(() => {
|
|
2690
|
+
const note = history.redo();
|
|
2691
|
+
if (note !== null) {
|
|
2692
|
+
announce(fill(labels.toastRedone, { step: note }));
|
|
2693
|
+
}
|
|
2694
|
+
}, [history, labels, announce]);
|
|
2695
|
+
const undoLater = useRef11(undo2);
|
|
2696
|
+
useEffect11(() => {
|
|
2697
|
+
undoLater.current = undo2;
|
|
2698
|
+
});
|
|
2699
|
+
const reset2 = useCallback9(() => {
|
|
2700
|
+
history.reset(labels.steps.reset);
|
|
2701
|
+
announce(labels.toastReset);
|
|
2702
|
+
}, [history, labels, announce]);
|
|
2703
|
+
const param = linkParam(storageKey);
|
|
2704
|
+
const [opening, setOpening] = useState12(false);
|
|
2705
|
+
const appliedLink = useRef11(
|
|
2706
|
+
/** @type {string | null} */
|
|
2707
|
+
null
|
|
2708
|
+
);
|
|
2709
|
+
const latest = useRef11({ history, encoded, limits, labels, announce, commit: (
|
|
2710
|
+
/** @type {any} */
|
|
2711
|
+
null
|
|
2712
|
+
), sourceId, loaded: (
|
|
2713
|
+
/** @type {any} */
|
|
2714
|
+
null
|
|
2715
|
+
), sources, onSourceSwitch });
|
|
2716
|
+
const [linkCheck, setLinkCheck] = useState12(
|
|
2717
|
+
/** @type {null | { lines: string[], quiet: boolean, load: () => void, switchTo?: { name: string, run: () => void } }} */
|
|
2718
|
+
null
|
|
2719
|
+
);
|
|
2720
|
+
const openLink = useCallback9((text, asStep = false) => {
|
|
2721
|
+
appliedLink.current = text;
|
|
2722
|
+
const now = linkNow();
|
|
2723
|
+
const apply = (m) => {
|
|
2724
|
+
const { history: h, encoded: enc, limits: lim, labels: l, announce: say, sourceId: id, loaded: done, sources: list, onSourceSwitch: switchTo } = latest.current;
|
|
2725
|
+
const decoded = m.decodeViewLink(text);
|
|
2726
|
+
const loaded3 = decoded.view ? viewFromObject(decoded.view, enc, { limits: lim, sourceId: id }) : null;
|
|
2727
|
+
if (!loaded3 || !loaded3.view) {
|
|
2728
|
+
say(loaded3?.failed === "newer" ? l.viewFailed.newer : l.viewFailed.badLink, { tone: "error" });
|
|
2729
|
+
return;
|
|
2730
|
+
}
|
|
2731
|
+
const open = () => {
|
|
2732
|
+
if (asStep) {
|
|
2733
|
+
done(loaded3, { link: true });
|
|
2734
|
+
} else {
|
|
2735
|
+
h.restore(
|
|
2736
|
+
/** @type {object} */
|
|
2737
|
+
loaded3.view
|
|
2738
|
+
);
|
|
2739
|
+
done(loaded3, { link: true, restored: true });
|
|
2740
|
+
}
|
|
2741
|
+
};
|
|
2742
|
+
const check = loadCheck(loaded3, l, Array.isArray(list) ? list : []);
|
|
2743
|
+
if (!check) {
|
|
2744
|
+
open();
|
|
2745
|
+
return;
|
|
2746
|
+
}
|
|
2747
|
+
const target = check.switchTo;
|
|
2748
|
+
setLinkCheck({
|
|
2749
|
+
lines: check.lines,
|
|
2750
|
+
quiet: !asStep,
|
|
2751
|
+
load: open,
|
|
2752
|
+
switchTo: target && typeof switchTo === "function" ? { name: target.name, run: () => switchTo({ source: { id: target.id, name: target.name }, view: (
|
|
2753
|
+
/** @type {Record<string, unknown>} */
|
|
2754
|
+
loaded3.file?.view ?? loaded3.view
|
|
2755
|
+
), name: loaded3.file?.name || void 0 }) } : void 0
|
|
2756
|
+
});
|
|
2757
|
+
};
|
|
2758
|
+
if (now) {
|
|
2759
|
+
apply(now);
|
|
2760
|
+
return;
|
|
2761
|
+
}
|
|
2762
|
+
setOpening(true);
|
|
2763
|
+
loadLink().then(
|
|
2764
|
+
(m) => {
|
|
2765
|
+
setOpening(false);
|
|
2766
|
+
apply(m);
|
|
2767
|
+
},
|
|
2768
|
+
() => {
|
|
2769
|
+
setOpening(false);
|
|
2770
|
+
latest.current.announce(latest.current.labels.viewFailed.badLink, { tone: "error" });
|
|
2771
|
+
}
|
|
2772
|
+
);
|
|
2773
|
+
}, []);
|
|
2774
|
+
useIsoLayoutEffect(() => {
|
|
2775
|
+
const page = here();
|
|
2776
|
+
const link = shareLink ? readLinkParam(page?.hash ?? "", param) : null;
|
|
2777
|
+
if (link) {
|
|
2778
|
+
openLink(link);
|
|
2779
|
+
} else if (persistView === "session") {
|
|
2780
|
+
const raw = readStoredView(storageKey, sessionStore());
|
|
2781
|
+
if (raw) {
|
|
2782
|
+
try {
|
|
2783
|
+
const loaded3 = viewFromObject(JSON.parse(raw), encoded, { limits });
|
|
2784
|
+
if (loaded3.view) {
|
|
2785
|
+
history.restore(loaded3.view);
|
|
2786
|
+
}
|
|
2787
|
+
} catch {
|
|
2788
|
+
}
|
|
2789
|
+
}
|
|
2790
|
+
}
|
|
2791
|
+
}, []);
|
|
2792
|
+
useEffect11(() => {
|
|
2793
|
+
if (!shareLink || typeof window === "undefined") {
|
|
2794
|
+
return void 0;
|
|
2795
|
+
}
|
|
2796
|
+
const onHash = () => {
|
|
2797
|
+
const link = readLinkParam(here()?.hash ?? "", param);
|
|
2798
|
+
if (link && link !== appliedLink.current) {
|
|
2799
|
+
openLink(link, true);
|
|
2800
|
+
}
|
|
2801
|
+
};
|
|
2802
|
+
window.addEventListener("hashchange", onHash);
|
|
2803
|
+
return () => window.removeEventListener("hashchange", onHash);
|
|
2804
|
+
}, [shareLink, param, openLink]);
|
|
2805
|
+
useEffect11(() => {
|
|
2806
|
+
if (persistView === "session") {
|
|
2807
|
+
writeStoredView(storageKey, sessionStore(), JSON.parse(history.viewKey));
|
|
2808
|
+
}
|
|
2809
|
+
}, [persistView, storageKey, history.viewKey]);
|
|
2810
|
+
const commit = useCallback9(
|
|
2811
|
+
/** @param {object} next @param {{ step: string, removed?: boolean, field?: string, zone?: string, name?: string, display?: string, type?: string }} [note] @param {any} [tag] the saved view it is (history.tag) */
|
|
2812
|
+
(next, note = { step: "change" }, tag = void 0) => {
|
|
2813
|
+
const over = note.step === "template" ? null : zoneOverLimit(next, limits);
|
|
2814
|
+
if (over) {
|
|
2815
|
+
announce(fill(labels.zoneFull, { zone: labels.zones[over.zone], max: over.max.toLocaleString(locale) }), { tone: "error" });
|
|
2816
|
+
return;
|
|
2817
|
+
}
|
|
2818
|
+
const changed = history.commit(next, stepText(note), tag);
|
|
2819
|
+
if (changed) {
|
|
2820
|
+
changesRef.current += 1;
|
|
2821
|
+
setChanges(changesRef.current);
|
|
2822
|
+
}
|
|
2823
|
+
if (!changed || !note.removed) {
|
|
2824
|
+
return;
|
|
2825
|
+
}
|
|
2826
|
+
announce(fill(labels.toastRemoved, { field: note.field ?? "" }).trim(), { action: { label: labels.undo, run: () => undoLater.current() } });
|
|
2827
|
+
},
|
|
2828
|
+
[history, stepText, labels, announce, limits, locale]
|
|
2829
|
+
);
|
|
2830
|
+
const remember = useCallback9((tag, key) => setSavedKeys((all) => ({ ...all, [savedKeyOf(tag)]: key })), []);
|
|
2831
|
+
const applyLoaded = useCallback9(
|
|
2832
|
+
/** @param {import("./share.js").LoadedView} loaded @param {{ link?: boolean, restored?: boolean }} [how] */
|
|
2833
|
+
(loaded3, { link = false, restored = false } = {}) => {
|
|
2834
|
+
if (!loaded3.view) {
|
|
2835
|
+
return;
|
|
2836
|
+
}
|
|
2837
|
+
const tag = loaded3.file?.name ? { name: loaded3.file.name, scope: null, store: false, sourceId: latest.current.sourceId } : null;
|
|
2838
|
+
if (tag) {
|
|
2839
|
+
remember(tag, latest.current.history.keyOf(loaded3.view));
|
|
2840
|
+
}
|
|
2841
|
+
if (restored) {
|
|
2842
|
+
latest.current.history.setTag(tag);
|
|
2843
|
+
} else {
|
|
2844
|
+
commit(loaded3.view, { step: "viewLoaded" }, tag);
|
|
2845
|
+
}
|
|
2846
|
+
const notes2 = unusedNotes(loaded3.issues, loaded3.file?.view);
|
|
2847
|
+
setLeftOut(notes2);
|
|
2848
|
+
setIssuesDismissed(null);
|
|
2849
|
+
setLoads((x) => x + 1);
|
|
2850
|
+
setUnusedSaid(notes2.length > 0);
|
|
2851
|
+
const text = link ? notes2.length ? labels.toastLinkOpenedPartly : labels.toastLinkOpened : notes2.length ? labels.toastViewLoadedPartly : labels.toastViewLoaded;
|
|
2852
|
+
announce(text, restored ? void 0 : { action: { label: labels.undo, run: () => undoLater.current() } });
|
|
2853
|
+
},
|
|
2854
|
+
[commit, labels, announce, remember]
|
|
2855
|
+
);
|
|
2856
|
+
useEffect11(() => {
|
|
2857
|
+
latest.current = { history, encoded, limits, labels, announce, commit, sourceId, loaded: applyLoaded, sources, onSourceSwitch };
|
|
2858
|
+
});
|
|
2859
|
+
const computed = useMemo8(() => {
|
|
2860
|
+
try {
|
|
2861
|
+
return { result: measured("computePivot", () => computePivot(encoded, view, { locale, limits })), error: null };
|
|
2862
|
+
} catch (error2) {
|
|
2863
|
+
return { result: null, error: error2 };
|
|
2864
|
+
}
|
|
2865
|
+
}, [encoded, view, locale, limits]);
|
|
2866
|
+
const result = computed.result;
|
|
2867
|
+
const plan = useMemo8(() => chartPlan(view, encoded), [view, encoded]);
|
|
2868
|
+
const chartComputed = useMemo8(() => {
|
|
2869
|
+
if (!plan.swap || view.display !== "chart" || !result) {
|
|
2870
|
+
return computed;
|
|
2871
|
+
}
|
|
2872
|
+
try {
|
|
2873
|
+
return { result: measured("computePivot", () => computePivot(encoded, swapAxes(view), { locale, limits })), error: null };
|
|
2874
|
+
} catch (error2) {
|
|
2875
|
+
return { result: null, error: error2 };
|
|
2876
|
+
}
|
|
2877
|
+
}, [plan.swap, view, encoded, locale, limits, computed, result]);
|
|
2878
|
+
const chartResult = chartComputed.result;
|
|
2879
|
+
const empty = isEmptyView(view);
|
|
2880
|
+
const gridState = useMemo8(() => {
|
|
2881
|
+
if (!result || view.display !== "table" || empty) {
|
|
2882
|
+
return { grid: null, error: null };
|
|
2883
|
+
}
|
|
2884
|
+
try {
|
|
2885
|
+
return { grid: measured("toGrid", () => toGrid(result, { locale, labels: labels.core, limits })), error: null };
|
|
2886
|
+
} catch (error2) {
|
|
2887
|
+
return { grid: null, error: error2 };
|
|
2888
|
+
}
|
|
2889
|
+
}, [result, view.display, empty, locale, labels, limits]);
|
|
2890
|
+
const error = source.error ?? computed.error ?? gridState.error ?? (view.display === "chart" ? chartComputed.error : null);
|
|
2891
|
+
const fields = encoded.schema.fields;
|
|
2892
|
+
const types = useMemo8(() => new Map(viewFields(view, encoded).map((f) => [f.name.toLowerCase(), f.type])), [view, encoded]);
|
|
2893
|
+
const typeOf = useCallback9((field) => types.get(sourceOf(view, field ?? "").toLowerCase()) ?? "string", [types, view]);
|
|
2894
|
+
const nameOf = useCallback9((field) => fieldLabel5(field, labels.core), [labels]);
|
|
2895
|
+
const hostOrdered = useCallback9((field) => sourceOf(view, field) === field && (orderOf?.(field)?.length ?? 0) > 0, [view, orderOf]);
|
|
2896
|
+
const sortFromHeader = useCallback9((field, sort) => commit(setSort(view, field, sort), { step: "sort", field: nameOf(field) }), [view, commit, nameOf]);
|
|
2897
|
+
const infoOf = useCallback9(
|
|
2898
|
+
(field) => {
|
|
2899
|
+
if (!field || info.size === 0) {
|
|
2900
|
+
return void 0;
|
|
2901
|
+
}
|
|
2902
|
+
const entry = info.get(sourceOf(view, field).toLowerCase());
|
|
2903
|
+
return entry && entry.description ? entry : void 0;
|
|
2904
|
+
},
|
|
2905
|
+
[info, view]
|
|
2906
|
+
);
|
|
2907
|
+
const placed = useMemo8(() => {
|
|
2908
|
+
const map = /* @__PURE__ */ new Map();
|
|
2909
|
+
const mark = (name, zone) => {
|
|
2910
|
+
const key = sourceOf(view, name).toLowerCase();
|
|
2911
|
+
const list = map.get(key) ?? [];
|
|
2912
|
+
if (!list.includes(zone)) {
|
|
2913
|
+
list.push(zone);
|
|
2914
|
+
}
|
|
2915
|
+
map.set(key, list);
|
|
2916
|
+
};
|
|
2917
|
+
view.rows.forEach((f) => mark(f, "rows"));
|
|
2918
|
+
view.cols.forEach((f) => mark(f, "cols"));
|
|
2919
|
+
view.values.forEach((v) => v.field && mark(v.field, "values"));
|
|
2920
|
+
filterZoneFields(view).forEach((f) => mark(f, "filters"));
|
|
2921
|
+
return map;
|
|
2922
|
+
}, [view]);
|
|
2923
|
+
const lang = labels.lang;
|
|
2924
|
+
useEffect11(() => {
|
|
2925
|
+
let live = true;
|
|
2926
|
+
loadMenus(lang).then(
|
|
2927
|
+
(m) => {
|
|
2928
|
+
if (live) {
|
|
2929
|
+
setMenus(() => m);
|
|
2930
|
+
}
|
|
2931
|
+
},
|
|
2932
|
+
() => void 0
|
|
2933
|
+
);
|
|
2934
|
+
return () => {
|
|
2935
|
+
live = false;
|
|
2936
|
+
};
|
|
2937
|
+
}, [lang]);
|
|
2938
|
+
const mainRef = useRef11(
|
|
2939
|
+
/** @type {HTMLDivElement | null} */
|
|
2940
|
+
null
|
|
2941
|
+
);
|
|
2942
|
+
const fit = useFitHeight(root, mainRef, grow);
|
|
2943
|
+
const big = useBigResult(root);
|
|
2944
|
+
useIsoLayoutEffect(() => {
|
|
2945
|
+
const el = root.current;
|
|
2946
|
+
if (!el) {
|
|
2947
|
+
return void 0;
|
|
2948
|
+
}
|
|
2949
|
+
const box = el.getBoundingClientRect();
|
|
2950
|
+
setSize(sizeOf(box.width));
|
|
2951
|
+
const first = compactAt(sizeOf(box.width), box.height);
|
|
2952
|
+
setMeasuredShort(first);
|
|
2953
|
+
setShort(first);
|
|
2954
|
+
if (typeof ResizeObserver !== "function") {
|
|
2955
|
+
return void 0;
|
|
2956
|
+
}
|
|
2957
|
+
const ro = new ResizeObserver(([entry]) => {
|
|
2958
|
+
const width = sizeOf(entry.contentRect.width);
|
|
2959
|
+
setSize(width);
|
|
2960
|
+
const height2 = entry.borderBoxSize?.[0]?.blockSize ?? el.getBoundingClientRect().height;
|
|
2961
|
+
setMeasuredShort(compactAt(width, height2) || fit.current.open > 0 && height2 <= fit.current.open + 1);
|
|
2962
|
+
});
|
|
2963
|
+
ro.observe(el);
|
|
2964
|
+
return () => ro.disconnect();
|
|
2965
|
+
}, []);
|
|
2966
|
+
useEffect11(() => {
|
|
2967
|
+
if (measuredShort === short) {
|
|
2968
|
+
return void 0;
|
|
2969
|
+
}
|
|
2970
|
+
const apply = () => {
|
|
2971
|
+
if (!layerOpen(layer)) {
|
|
2972
|
+
setShort(measuredShort);
|
|
2973
|
+
}
|
|
2974
|
+
};
|
|
2975
|
+
apply();
|
|
2976
|
+
if (!layer || typeof MutationObserver !== "function") {
|
|
2977
|
+
return void 0;
|
|
2978
|
+
}
|
|
2979
|
+
const mo = new MutationObserver(apply);
|
|
2980
|
+
mo.observe(layer, { childList: true });
|
|
2981
|
+
return () => mo.disconnect();
|
|
2982
|
+
}, [measuredShort, short, layer]);
|
|
2983
|
+
const drawerOpen = drawer && size === "narrow";
|
|
2984
|
+
const panelRef = useRef11(
|
|
2985
|
+
/** @type {HTMLDivElement | null} */
|
|
2986
|
+
null
|
|
2987
|
+
);
|
|
2988
|
+
useEffect11(() => {
|
|
2989
|
+
if (panelRef.current) {
|
|
2990
|
+
panelRef.current.inert = size === "narrow" && !drawerOpen;
|
|
2991
|
+
}
|
|
2992
|
+
}, [size, drawerOpen]);
|
|
2993
|
+
const placeOptions = useCallback9(
|
|
2994
|
+
(field, zone, index = void 0) => {
|
|
2995
|
+
const column = encoded.column(field);
|
|
2996
|
+
const unit = zone !== "values" && column && column.type === "date" && !column.derived ? suggestDateUnit(encoded, field) : null;
|
|
2997
|
+
return { index, type: typeOf(field), defaults: defaultsFor(fieldDefaults, field), dateUnit: unit, groupName: unit ? groupingName(nameOf(column.name), unit, labels) : void 0 };
|
|
2998
|
+
},
|
|
2999
|
+
[encoded, typeOf, fieldDefaults, labels, nameOf]
|
|
3000
|
+
);
|
|
3001
|
+
const defaultsOf = useCallback9((field) => defaultsFor(fieldDefaults, field), [fieldDefaults]);
|
|
3002
|
+
const addTo = useCallback9(
|
|
3003
|
+
(field, zone, index = void 0) => {
|
|
3004
|
+
const options = placeOptions(field, zone, index);
|
|
3005
|
+
commit(addField(view, field, zone, options), { step: "added", field: options.groupName ?? nameOf(field), zone });
|
|
3006
|
+
},
|
|
3007
|
+
[view, placeOptions, commit, nameOf]
|
|
3008
|
+
);
|
|
3009
|
+
const filterNew = useCallback9(
|
|
3010
|
+
(field, anchor) => {
|
|
3011
|
+
const options = placeOptions(field, "filters");
|
|
3012
|
+
const draft = addField(view, field, "filters", options);
|
|
3013
|
+
const opener = size === "narrow" ? (
|
|
3014
|
+
/** @type {HTMLElement | null} */
|
|
3015
|
+
root.current?.querySelector("[data-pk-opener='fields']") ?? null
|
|
3016
|
+
) : null;
|
|
3017
|
+
if (size === "narrow") {
|
|
3018
|
+
setDrawer(false);
|
|
3019
|
+
}
|
|
3020
|
+
const target = opener ?? anchor;
|
|
3021
|
+
if (target) {
|
|
3022
|
+
setFilterTarget({ field: options.groupName ?? field, anchor: target, base: draft });
|
|
3023
|
+
}
|
|
3024
|
+
},
|
|
3025
|
+
[placeOptions, view, size]
|
|
3026
|
+
);
|
|
3027
|
+
const onDrop = useCallback9(
|
|
3028
|
+
(src, target) => {
|
|
3029
|
+
setDragAt((at) => at ?? changesRef.current + 1);
|
|
3030
|
+
if (target.zone === "panel") {
|
|
3031
|
+
if (src.kind !== "field") {
|
|
3032
|
+
commit(removeAt(view, src.zone, src.index), { step: "removed", removed: true, field: src.label ?? src.field });
|
|
3033
|
+
}
|
|
3034
|
+
return;
|
|
3035
|
+
}
|
|
3036
|
+
if (src.kind === "field") {
|
|
3037
|
+
addTo(src.field, target.zone, target.index);
|
|
3038
|
+
} else {
|
|
3039
|
+
const zone = (
|
|
3040
|
+
/** @type {any} */
|
|
3041
|
+
target.zone
|
|
3042
|
+
);
|
|
3043
|
+
const note = src.zone !== zone ? { step: "moved", field: src.label ?? src.field, zone } : { step: "reordered", zone };
|
|
3044
|
+
commit(moveField(view, src.zone, src.index, zone, target.index, { type: typeOf(src.field) }), note);
|
|
3045
|
+
}
|
|
3046
|
+
},
|
|
3047
|
+
[view, typeOf, commit, addTo]
|
|
3048
|
+
);
|
|
3049
|
+
const openCell = useCallback9(
|
|
3050
|
+
/** @param {any} cell */
|
|
3051
|
+
({ rowPath = [], colPath = [], value, valueIndex, text }) => {
|
|
3052
|
+
if (!result) {
|
|
3053
|
+
return;
|
|
3054
|
+
}
|
|
3055
|
+
setHinted(true);
|
|
3056
|
+
const { count, rows, indices } = drillRows(result, { rowPath, colPath, data: encodedProp ? null : data, limit: drillDownLimit });
|
|
3057
|
+
onCellClick?.({ row: rowPath, col: colPath, value, valueIndex, text, count, rows });
|
|
3058
|
+
if (drillDown) {
|
|
3059
|
+
const formatOf = (name) => {
|
|
3060
|
+
const d = defaultsFor(fieldDefaults, name);
|
|
3061
|
+
return d ? d.drillFormat ?? d.format : void 0;
|
|
3062
|
+
};
|
|
3063
|
+
setDrill({ result, rowPath, colPath, count, indices, formatOf, nameOf, infoOf });
|
|
3064
|
+
}
|
|
3065
|
+
},
|
|
3066
|
+
[result, encodedProp, data, drillDownLimit, onCellClick, drillDown, fieldDefaults, nameOf, infoOf]
|
|
3067
|
+
);
|
|
3068
|
+
const doExport = useExport({ fileName, result, locale, labels, limits, root, chartRef, announce, onExport });
|
|
3069
|
+
const base = shareBase(shareLink, here()?.href);
|
|
3070
|
+
const share = {
|
|
3071
|
+
canLink: base !== null,
|
|
3072
|
+
prepare: base !== null ? () => void loadLink().catch(() => void 0) : void 0,
|
|
3073
|
+
view,
|
|
3074
|
+
viewName,
|
|
3075
|
+
sourceId,
|
|
3076
|
+
sourceName,
|
|
3077
|
+
schemaUrl,
|
|
3078
|
+
encoded,
|
|
3079
|
+
shareLink,
|
|
3080
|
+
param,
|
|
3081
|
+
root,
|
|
3082
|
+
fileName,
|
|
3083
|
+
onExport,
|
|
3084
|
+
announce,
|
|
3085
|
+
limits,
|
|
3086
|
+
sources,
|
|
3087
|
+
onSourceSwitch,
|
|
3088
|
+
applyLoaded
|
|
3089
|
+
};
|
|
3090
|
+
const loadTemplate = useCallback9(
|
|
3091
|
+
(t) => {
|
|
3092
|
+
const tag = { name: t.name, scope: t.scope === "user" ? "user" : "shared", store: t.at !== void 0, storeSource: t.sourceId ?? null, sourceId };
|
|
3093
|
+
remember(tag, history.keyOf(t.view));
|
|
3094
|
+
commit(t.view, { step: "template", name: t.name }, tag);
|
|
3095
|
+
const over = zoneOverLimit(t.view, limits);
|
|
3096
|
+
const issues = normalize2(t.view, encoded, { limits }).issues.filter((i) => !over || i.code !== "tooMany");
|
|
3097
|
+
setLeftOut([...over ? [{ text: fill(labels.viewTrimmed, { name: t.name, zone: labels.zones[over.zone], max: over.max.toLocaleString(locale) }) }] : [], ...unusedNotes(issues, t.view)]);
|
|
3098
|
+
setIssuesDismissed(null);
|
|
3099
|
+
setLoads((x) => x + 1);
|
|
3100
|
+
setUnusedSaid(false);
|
|
3101
|
+
announce(fill(labels.toastLoaded, { name: t.name }));
|
|
3102
|
+
},
|
|
3103
|
+
[commit, labels, announce, limits, locale, history, remember, sourceId, encoded]
|
|
3104
|
+
);
|
|
3105
|
+
const newReport = () => {
|
|
3106
|
+
if (empty) {
|
|
3107
|
+
return;
|
|
3108
|
+
}
|
|
3109
|
+
commit(emptyView2(), { step: "new" }, null);
|
|
3110
|
+
setLeftOut([]);
|
|
3111
|
+
setLoads((x) => x + 1);
|
|
3112
|
+
setUnusedSaid(false);
|
|
3113
|
+
announce(labels.newEmpty, { action: { label: labels.undo, run: () => undoLater.current() } });
|
|
3114
|
+
};
|
|
3115
|
+
const viewStore = templateStore === "browser";
|
|
3116
|
+
const storeName = viewsName(storageKey);
|
|
3117
|
+
const subscribeViews = useCallback9((callback) => viewStore ? subscribeItem(storeName, callback) : () => {
|
|
3118
|
+
}, [viewStore, storeName]);
|
|
3119
|
+
const viewsText = useSyncExternalStore3(subscribeViews, () => viewStore ? readItem(storeName, localStore()) : null, () => null);
|
|
3120
|
+
const entries = useMemo8(() => templateEntries(templates, viewStore && menus ? menus.storedViews(viewsText, sourceId) : [], Boolean(onDeleteTemplate)), [templates, viewStore, menus, viewsText, sourceId, onDeleteTemplate]);
|
|
3121
|
+
const templateActions = {
|
|
3122
|
+
view,
|
|
3123
|
+
announce,
|
|
3124
|
+
locale,
|
|
3125
|
+
sourceId,
|
|
3126
|
+
viewsText,
|
|
3127
|
+
store: viewStore,
|
|
3128
|
+
keep: (text) => writeItem(storeName, localStore(), text),
|
|
3129
|
+
onSave: onSaveTemplate,
|
|
3130
|
+
onDelete: onDeleteTemplate,
|
|
3131
|
+
onPublish: canPublish ? onPublishTemplate : void 0,
|
|
3132
|
+
// a view leaves the report checked against the data, never as it was stored, and in the form a
|
|
3133
|
+
// save hands over (the view as shown: normalized, with the host's orders), so Publish and
|
|
3134
|
+
// Save send the same view
|
|
3135
|
+
normalized: (v) => JSON.parse(history.keyOf(v)),
|
|
3136
|
+
loaded: loadedView,
|
|
3137
|
+
empty,
|
|
3138
|
+
/**
|
|
3139
|
+
* A save kept: the view as it was when the save was clicked (`key`) is that saved view now. The
|
|
3140
|
+
* view shown takes its name only while it is still that view: a slow host may answer after
|
|
3141
|
+
* New, another view loaded or a change, and none of those may become the saved view.
|
|
3142
|
+
*/
|
|
3143
|
+
onSaved: (saved, key) => {
|
|
3144
|
+
setSavedAt(changesRef.current);
|
|
3145
|
+
const tag = { ...saved, sourceId };
|
|
3146
|
+
remember(tag, key);
|
|
3147
|
+
const now = latest.current.history;
|
|
3148
|
+
if (now.viewKey === key) {
|
|
3149
|
+
now.setTag(tag);
|
|
3150
|
+
}
|
|
3151
|
+
},
|
|
3152
|
+
viewKey: history.viewKey,
|
|
3153
|
+
onNew: newReport,
|
|
3154
|
+
canNew: !empty
|
|
3155
|
+
};
|
|
3156
|
+
const onKeyDown = (e) => {
|
|
3157
|
+
const target = (
|
|
3158
|
+
/** @type {HTMLElement} */
|
|
3159
|
+
e.target
|
|
3160
|
+
);
|
|
3161
|
+
if (e.key === "Escape" && big.enlarged && !e.defaultPrevented && !layerOpen(layer) && !drawerOpen && !drill && !filterTarget) {
|
|
3162
|
+
e.preventDefault();
|
|
3163
|
+
big.setEnlarged(false);
|
|
3164
|
+
return;
|
|
3165
|
+
}
|
|
3166
|
+
if (target.closest("input, textarea, select, [contenteditable]")) {
|
|
3167
|
+
return;
|
|
3168
|
+
}
|
|
3169
|
+
const mod = e.ctrlKey || e.metaKey;
|
|
3170
|
+
if (mod && !e.altKey && (e.key === "z" || e.key === "Z")) {
|
|
3171
|
+
e.preventDefault();
|
|
3172
|
+
if (e.shiftKey) {
|
|
3173
|
+
redo2();
|
|
3174
|
+
} else {
|
|
3175
|
+
undo2();
|
|
3176
|
+
}
|
|
3177
|
+
} else if (mod && (e.key === "y" || e.key === "Y")) {
|
|
3178
|
+
e.preventDefault();
|
|
3179
|
+
redo2();
|
|
3180
|
+
}
|
|
3181
|
+
};
|
|
3182
|
+
const layerValue = useMemo8(() => ({ layer, size }), [layer, size]);
|
|
3183
|
+
const renderOverlay = (src) => /* @__PURE__ */ React12.createElement("div", { className: "pk-chip pk-overlay" }, /* @__PURE__ */ React12.createElement(Icon, { name: "grip", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: `pk-type pk-type-${src.type ?? typeOf(src.field)}` }, /* @__PURE__ */ React12.createElement(Icon, { name: (
|
|
3184
|
+
/** @type {any} */
|
|
3185
|
+
TYPE_ICON[src.type ?? typeOf(src.field)] ?? "text"
|
|
3186
|
+
), size: 13 })), /* @__PURE__ */ React12.createElement("span", { className: "pk-chip-text" }, src.label ?? src.field));
|
|
3187
|
+
const showTable = !error && !(empty && view.display === "table") && view.display !== "chart" && gridState.grid;
|
|
3188
|
+
const outer = useMemo8(() => result ? outerPaths(result) : [], [result]);
|
|
3189
|
+
const folding = rowFolding(view, outer);
|
|
3190
|
+
const expandAll = (texts) => {
|
|
3191
|
+
const count = view.collapsed.rows.length;
|
|
3192
|
+
commit(setCollapsed(view, "rows", null), { step: "collapse" });
|
|
3193
|
+
announce(plural(texts.groupsExpanded, count, { lang: labels.lang, locale }));
|
|
3194
|
+
};
|
|
3195
|
+
const collapseAll = (texts) => {
|
|
3196
|
+
if (!result) {
|
|
3197
|
+
return;
|
|
3198
|
+
}
|
|
3199
|
+
commit(setCollapsed(view, "rows", outer), { step: "collapse" });
|
|
3200
|
+
announce(plural(texts.groupsCollapsed, folding.open, { lang: labels.lang, locale }));
|
|
3201
|
+
};
|
|
3202
|
+
const series = useMemo8(() => {
|
|
3203
|
+
if (!chartResult || view.display !== "chart" || view.values.length === 0) {
|
|
3204
|
+
return null;
|
|
3205
|
+
}
|
|
3206
|
+
try {
|
|
3207
|
+
return toSeries(chartResult, { labels: labels.core, maxCategories: MAX_CATEGORIES });
|
|
3208
|
+
} catch {
|
|
3209
|
+
return null;
|
|
3210
|
+
}
|
|
3211
|
+
}, [chartResult, view.display, view.values.length, labels]);
|
|
3212
|
+
const allowedKey = JSON.stringify(allowedTips(tipsProp));
|
|
3213
|
+
const allowed = useMemo8(() => JSON.parse(allowedKey), [allowedKey]);
|
|
3214
|
+
const dismissedKey = JSON.stringify(cleanDismissed(dismissedTips));
|
|
3215
|
+
const [own2, setOwn] = useState12(() => cleanDismissed(JSON.parse(dismissedKey)));
|
|
3216
|
+
const [lastDismissedKey, setLastDismissedKey] = useState12(dismissedKey);
|
|
3217
|
+
if (dismissedKey !== lastDismissedKey) {
|
|
3218
|
+
setLastDismissedKey(dismissedKey);
|
|
3219
|
+
setOwn(JSON.parse(dismissedKey));
|
|
3220
|
+
}
|
|
3221
|
+
const subscribe = useCallback9((callback) => subscribeStored(storageKey, callback), [storageKey]);
|
|
3222
|
+
const storedRaw = useSyncExternalStore3(subscribe, () => readStored(storageKey, localStore()), () => null);
|
|
3223
|
+
const dismissed = useMemo8(() => cleanDismissed([...own2, ...parseStored(storedRaw)]), [own2, storedRaw]);
|
|
3224
|
+
const changeDismissed = useCallback9(
|
|
3225
|
+
(next, id) => {
|
|
3226
|
+
setOwn(next);
|
|
3227
|
+
writeDismissed(storageKey, localStore(), next);
|
|
3228
|
+
onTipDismiss?.({ id, dismissed: next });
|
|
3229
|
+
},
|
|
3230
|
+
[storageKey, onTipDismiss]
|
|
3231
|
+
);
|
|
3232
|
+
const tipsOn = allowed !== "off" && !dismissed.includes(ALL_TIPS);
|
|
3233
|
+
const describedFields = [...info.values()].some((i) => i.description);
|
|
3234
|
+
const fieldSwitch = helpSwitch(fieldInfoProp, dismissed);
|
|
3235
|
+
const zoneSwitch = helpSwitch(zoneInfoProp, dismissed);
|
|
3236
|
+
const settingSwitch = helpSwitch(settingInfoProp, dismissed);
|
|
3237
|
+
const explainUser = settingSwitch.user || zoneSwitch.user || describedFields && fieldSwitch.user;
|
|
3238
|
+
const ready = menus ? menusNow(labels.lang) : null;
|
|
3239
|
+
const withTexts = ready ? ready.menuLabels(labels) : null;
|
|
3240
|
+
const [keptTexts, setKeptTexts] = useState12(
|
|
3241
|
+
/** @type {any} */
|
|
3242
|
+
null
|
|
3243
|
+
);
|
|
3244
|
+
if (withTexts && withTexts !== keptTexts) {
|
|
3245
|
+
setKeptTexts(withTexts);
|
|
3246
|
+
}
|
|
3247
|
+
const helpLabels = withTexts ?? keptTexts ?? labels;
|
|
3248
|
+
const help = useMemo8(
|
|
3249
|
+
() => ({
|
|
3250
|
+
explain: settingSwitch.on,
|
|
3251
|
+
labels: helpLabels,
|
|
3252
|
+
isOpen: (id) => sectionOpen(id, dismissed),
|
|
3253
|
+
setOpen: (id, open) => changeDismissed(withSection(dismissed, id, open), null)
|
|
3254
|
+
}),
|
|
3255
|
+
[settingSwitch.on, helpLabels, dismissed, changeDismissed]
|
|
3256
|
+
);
|
|
3257
|
+
const [fieldsSession, setFieldsSession] = useState12(
|
|
3258
|
+
/** @type {boolean | null} */
|
|
3259
|
+
null
|
|
3260
|
+
);
|
|
3261
|
+
useEffect11(() => {
|
|
3262
|
+
if (fieldList !== void 0 && fieldList !== "open" && fieldList !== "collapsed") {
|
|
3263
|
+
warnOnce(`pivotkit: fieldList ${JSON.stringify(String(fieldList)).slice(0, 40)} is neither "open" nor "collapsed"; the user's choice decides`);
|
|
3264
|
+
}
|
|
3265
|
+
}, [fieldList]);
|
|
3266
|
+
const railed = size !== "narrow" && fieldsCollapsed(fieldsSession, fieldList, dismissed);
|
|
3267
|
+
const collapseFields = (next) => {
|
|
3268
|
+
if (fieldList === "open" || fieldList === "collapsed") {
|
|
3269
|
+
setFieldsSession(next);
|
|
3270
|
+
} else {
|
|
3271
|
+
changeDismissed(next ? [...dismissed, FIELDS_COLLAPSED] : dismissed.filter((d) => d !== FIELDS_COLLAPSED), null);
|
|
3272
|
+
}
|
|
3273
|
+
};
|
|
3274
|
+
const toggle = (id, on) => changeDismissed(on ? dismissed.filter((d) => d !== id) : [...dismissed, id], on ? null : id);
|
|
3275
|
+
const ctx = tipContext({ view, result, encoded, failed: Boolean(error), empty, typeOf, fields: labels.core.fields, series, tableShown: Boolean(showTable), drilled: hinted, changes, dragAt, canSave: Boolean(onSaveTemplate) || viewStore, savedAt, chartPlan: plan });
|
|
3276
|
+
const shownTips = activeTips(ctx, { allowed, dismissed }).map((t) => ({
|
|
3277
|
+
id: t.id,
|
|
3278
|
+
params: t.params,
|
|
3279
|
+
icon: t.entry.icon ?? "info",
|
|
3280
|
+
notice: t.entry.kind === "notice",
|
|
3281
|
+
action: t.entry.action ?? "",
|
|
3282
|
+
text: tipText(t.id, t.params, labels, locale),
|
|
3283
|
+
actionText: tipActionText(t.entry, t.params, labels)
|
|
3284
|
+
}));
|
|
3285
|
+
const runTip = (id, action) => {
|
|
3286
|
+
const params = shownTips.find((t) => t.id === id)?.params ?? {};
|
|
3287
|
+
if (action === "swap") {
|
|
3288
|
+
commit(swapAxes(view), { step: "swap" });
|
|
3289
|
+
} else if (action === "removeFilters") {
|
|
3290
|
+
commit(withoutFilters(view), { step: "filtersRemoved" });
|
|
3291
|
+
} else if (action === "groupDate") {
|
|
3292
|
+
commit(groupField(view, params.source, params.unit, { name: groupingName(nameOf(params.source), params.unit, labels) }).view, { step: "group", field: nameOf(params.source) });
|
|
3293
|
+
} else if (action === "bars") {
|
|
3294
|
+
commit(setChart(view, "bar"), { step: "chart", type: "bar" });
|
|
3295
|
+
} else if (action === "auto") {
|
|
3296
|
+
commit(setChart(view, "auto"), { step: "chart", type: "auto" });
|
|
3297
|
+
} else if (action === "saveTemplate") {
|
|
3298
|
+
setViewsRequest((n) => n + 1);
|
|
3299
|
+
}
|
|
3300
|
+
};
|
|
3301
|
+
const cancelLink = () => {
|
|
3302
|
+
appliedLink.current = null;
|
|
3303
|
+
setLinkCheck(null);
|
|
3304
|
+
};
|
|
3305
|
+
const notes = useMemo8(() => [...leftOut, ...result && !empty ? result.issues.slice(0, 20).map((issue) => ({ issue, raw: view })) : []], [leftOut, result, empty, view]);
|
|
3306
|
+
const notesKey = useMemo8(() => JSON.stringify([loads, ...notes.map((n) => "issue" in n ? [n.issue.path, n.issue.message] : n.text)]), [notes, loads]);
|
|
3307
|
+
const summaryParts = big.enlarged ? layoutSummary(zoneEntries(view, types, labels), labels) : [];
|
|
3308
|
+
const summaryText = summaryParts.length ? summaryParts.map((p) => `${p.title}: ${p.fields}`).join(" \xB7 ") : labels.layoutEmpty;
|
|
3309
|
+
return /* @__PURE__ */ React12.createElement(
|
|
3310
|
+
"div",
|
|
3311
|
+
{
|
|
3312
|
+
ref: root,
|
|
3313
|
+
className: `pk-root${className ? ` ${className}` : ""}`,
|
|
3314
|
+
"data-pk-theme": themeName,
|
|
3315
|
+
"data-pk-size": size,
|
|
3316
|
+
"data-pk-layout": layoutFolded ? "compact" : void 0,
|
|
3317
|
+
"data-pk-enlarged": big.enlarged ? "" : void 0,
|
|
3318
|
+
"data-pk-fields": railed ? "collapsed" : void 0,
|
|
3319
|
+
"data-pk-fit": grow ? void 0 : "contain",
|
|
3320
|
+
lang: labels.lang,
|
|
3321
|
+
role: "region",
|
|
3322
|
+
"aria-label": label || labels.report,
|
|
3323
|
+
style: { height },
|
|
3324
|
+
tabIndex: -1,
|
|
3325
|
+
onKeyDown
|
|
3326
|
+
},
|
|
3327
|
+
/* @__PURE__ */ React12.createElement(LayerContext.Provider, { value: layerValue }, /* @__PURE__ */ React12.createElement(HelpContext.Provider, { value: help }, /* @__PURE__ */ React12.createElement(
|
|
3328
|
+
PivotDnd,
|
|
3329
|
+
{
|
|
3330
|
+
labels,
|
|
3331
|
+
onDrop,
|
|
3332
|
+
renderOverlay,
|
|
3333
|
+
onDragStart: (src) => {
|
|
3334
|
+
if (src.kind === "field" && size === "narrow") {
|
|
3335
|
+
setDrawer(false);
|
|
3336
|
+
}
|
|
3337
|
+
}
|
|
3338
|
+
},
|
|
3339
|
+
/* @__PURE__ */ React12.createElement("div", { className: `pk-layout${drawerOpen ? " pk-drawer-open" : ""}` }, /* @__PURE__ */ React12.createElement("div", { className: "pk-panel-slot", ref: panelRef }, /* @__PURE__ */ React12.createElement(
|
|
3340
|
+
FieldPanel,
|
|
3341
|
+
{
|
|
3342
|
+
fields,
|
|
3343
|
+
placed,
|
|
3344
|
+
labels,
|
|
3345
|
+
onAdd: (f, z) => {
|
|
3346
|
+
addTo(f, z);
|
|
3347
|
+
if (size === "narrow") {
|
|
3348
|
+
setDrawer(false);
|
|
3349
|
+
}
|
|
3350
|
+
},
|
|
3351
|
+
onNote: (text) => announce(text),
|
|
3352
|
+
onFilter: filterNew,
|
|
3353
|
+
nameOf,
|
|
3354
|
+
info,
|
|
3355
|
+
showInfo: fieldSwitch.on,
|
|
3356
|
+
drawer: size === "narrow",
|
|
3357
|
+
open: drawerOpen,
|
|
3358
|
+
onClose: () => setDrawer(false),
|
|
3359
|
+
collapsed: railed,
|
|
3360
|
+
onCollapse: collapseFields,
|
|
3361
|
+
onSkip: () => (
|
|
3362
|
+
/** @type {HTMLElement | null | undefined} */
|
|
3363
|
+
root.current?.querySelector(".pk-toolbar button:not([disabled])")?.focus()
|
|
3364
|
+
)
|
|
3365
|
+
}
|
|
3366
|
+
)), drawerOpen ? /* @__PURE__ */ React12.createElement("div", { className: "pk-scrim pk-drawer-scrim", onClick: () => setDrawer(false), "aria-hidden": "true" }) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-main", ref: mainRef }, /* @__PURE__ */ React12.createElement(
|
|
3367
|
+
Toolbar,
|
|
3368
|
+
{
|
|
3369
|
+
view,
|
|
3370
|
+
chartPlan: plan,
|
|
3371
|
+
labels,
|
|
3372
|
+
size,
|
|
3373
|
+
canUndo: history.canUndo,
|
|
3374
|
+
canRedo: history.canRedo,
|
|
3375
|
+
canReset: history.canReset,
|
|
3376
|
+
onUndo: undo2,
|
|
3377
|
+
onRedo: redo2,
|
|
3378
|
+
onReset: reset2,
|
|
3379
|
+
loadedView: loadedView ? { name: loadedView.name, changed: unsaved } : null,
|
|
3380
|
+
onDisplay: (d) => commit(setDisplay(view, d), { step: "display", display: d }),
|
|
3381
|
+
onChart: (p) => commit(setChart(view, p), { step: "chart", type: p }),
|
|
3382
|
+
onChartDisplay: (patch) => commit(setChartDisplay(view, patch), { step: "chartDisplay" }),
|
|
3383
|
+
onTotal: (key, on) => commit(setTotal(view, key, on), { step: "totals" }),
|
|
3384
|
+
onExpand: expandAll,
|
|
3385
|
+
onCollapse: collapseAll,
|
|
3386
|
+
folding,
|
|
3387
|
+
share,
|
|
3388
|
+
templates: entries,
|
|
3389
|
+
onLoadTemplate: loadTemplate,
|
|
3390
|
+
templateActions,
|
|
3391
|
+
onExport: doExport,
|
|
3392
|
+
prepareExport: prepareExporters,
|
|
3393
|
+
chartReady: view.display === "chart" && chartReady,
|
|
3394
|
+
empty,
|
|
3395
|
+
onShowFields: () => setDrawer(true),
|
|
3396
|
+
layoutFolded,
|
|
3397
|
+
onLayout: () => setFolded(!layoutFolded),
|
|
3398
|
+
zonesId,
|
|
3399
|
+
tipsControls: allowed !== "off",
|
|
3400
|
+
tipsOn,
|
|
3401
|
+
onTipsOn: (on) => changeDismissed(on ? dismissed.filter((id) => id !== ALL_TIPS) : [...dismissed, ALL_TIPS], on ? null : ALL_TIPS),
|
|
3402
|
+
canResetTips: dismissed.some((id) => !keptOnReset(id)),
|
|
3403
|
+
onResetTips: () => changeDismissed(dismissed.filter(keptOnReset), null),
|
|
3404
|
+
help: {
|
|
3405
|
+
explanations: explainUser ? { on: !dismissed.includes(NO_EXPLANATIONS), set: (on) => toggle(NO_EXPLANATIONS, on) } : null,
|
|
3406
|
+
// the list with the sections' states, for "Reset menu sections" (the menus do the rest)
|
|
3407
|
+
sections: [dismissed, changeDismissed]
|
|
3408
|
+
},
|
|
3409
|
+
viewsRequest
|
|
3410
|
+
}
|
|
3411
|
+
), /* @__PURE__ */ React12.createElement(
|
|
3412
|
+
Zones,
|
|
3413
|
+
{
|
|
3414
|
+
view,
|
|
3415
|
+
types,
|
|
3416
|
+
labels,
|
|
3417
|
+
commit,
|
|
3418
|
+
openFilter: (field, anchor) => setFilterTarget({ field, anchor }),
|
|
3419
|
+
encoded,
|
|
3420
|
+
locale,
|
|
3421
|
+
onSwap: () => commit(swapAxes(view), { step: "swap" }),
|
|
3422
|
+
id: zonesId,
|
|
3423
|
+
folded: layoutFolded,
|
|
3424
|
+
onShow: () => setFolded(false),
|
|
3425
|
+
defaultsOf,
|
|
3426
|
+
infoOf,
|
|
3427
|
+
explain: zoneSwitch.on,
|
|
3428
|
+
showInfo: fieldSwitch.on
|
|
3429
|
+
}
|
|
3430
|
+
), linkCheck ? /* @__PURE__ */ React12.createElement("div", { className: "pk-link-check", "data-testid": "link-check" }, /* @__PURE__ */ React12.createElement(MenuPanel, { name: "LoadCheck", props: { check: linkCheck, labels, title: labels.linkCheckTitle, quiet: linkCheck.quiet, close: () => setLinkCheck(null), onCancel: cancelLink } })) : null, /* @__PURE__ */ React12.createElement(
|
|
3431
|
+
Unused,
|
|
3432
|
+
{
|
|
3433
|
+
notes,
|
|
3434
|
+
notesKey,
|
|
3435
|
+
dismissed: issuesDismissed === notesKey,
|
|
3436
|
+
onDismiss: (next) => {
|
|
3437
|
+
setIssuesDismissed(notesKey);
|
|
3438
|
+
next?.focus({ preventScroll: true });
|
|
3439
|
+
if (!next || activeIn(next) !== next) {
|
|
3440
|
+
root.current?.focus({ preventScroll: true });
|
|
3441
|
+
}
|
|
3442
|
+
},
|
|
3443
|
+
labels,
|
|
3444
|
+
locale,
|
|
3445
|
+
narrow: size === "narrow",
|
|
3446
|
+
quiet: unusedSaid
|
|
3447
|
+
}
|
|
3448
|
+
), /* @__PURE__ */ React12.createElement(
|
|
3449
|
+
Tips,
|
|
3450
|
+
{
|
|
3451
|
+
tips: shownTips,
|
|
3452
|
+
labels,
|
|
3453
|
+
onDismiss: (id) => changeDismissed([...dismissed, id], id),
|
|
3454
|
+
onAction: runTip,
|
|
3455
|
+
focusFallback: () => root.current?.focus({ preventScroll: true })
|
|
3456
|
+
}
|
|
3457
|
+
), 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(
|
|
3458
|
+
PivotChart,
|
|
3459
|
+
{
|
|
3460
|
+
result: chartResult,
|
|
3461
|
+
plan,
|
|
3462
|
+
series,
|
|
3463
|
+
labels,
|
|
3464
|
+
locale,
|
|
3465
|
+
themeName,
|
|
3466
|
+
root,
|
|
3467
|
+
valueNames: view.values.map((v) => valueLabel(v, labels)),
|
|
3468
|
+
chartOptions: stableChartOptions,
|
|
3469
|
+
onInstance: (c) => {
|
|
3470
|
+
chartRef.current = c;
|
|
3471
|
+
setChartReady(Boolean(c));
|
|
3472
|
+
},
|
|
3473
|
+
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 ?? "") })
|
|
3474
|
+
}
|
|
3475
|
+
) : 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),
|
|
3476
|
+
filterTarget ? /* @__PURE__ */ React12.createElement(MenuPanel, { name: "FilterPopover", props: { target: filterTarget, onClose: closeFilter, view, encoded, locale, labels, commit } }) : null
|
|
3477
|
+
), /* @__PURE__ */ React12.createElement("div", { className: "pk-layer", ref: setLayer }, /* @__PURE__ */ React12.createElement("span", { className: "pk-origin", "aria-hidden": "true" }))))
|
|
3478
|
+
);
|
|
3479
|
+
}
|
|
3480
|
+
export {
|
|
3481
|
+
PivotReport
|
|
3482
|
+
};
|