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/menus.js
ADDED
|
@@ -0,0 +1,1681 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CHART_TYPES,
|
|
3
|
+
CHART_TYPE_NAMES,
|
|
4
|
+
ClearInput,
|
|
5
|
+
HelpContext,
|
|
6
|
+
Icon,
|
|
7
|
+
InfoButton,
|
|
8
|
+
LayerContext,
|
|
9
|
+
MenuButton,
|
|
10
|
+
Option,
|
|
11
|
+
Popover,
|
|
12
|
+
SHORTCUTS,
|
|
13
|
+
SLICE_TYPES,
|
|
14
|
+
ZONES,
|
|
15
|
+
ZONE_ICON,
|
|
16
|
+
axisOf,
|
|
17
|
+
chartTypeOf,
|
|
18
|
+
clone,
|
|
19
|
+
decodeRow,
|
|
20
|
+
filterZoneFields,
|
|
21
|
+
filtersOf,
|
|
22
|
+
groupField,
|
|
23
|
+
groupingName,
|
|
24
|
+
groupingOf,
|
|
25
|
+
isSection,
|
|
26
|
+
linkNow,
|
|
27
|
+
loadCheck,
|
|
28
|
+
loadLink,
|
|
29
|
+
moveField,
|
|
30
|
+
numericResult,
|
|
31
|
+
readLinkParam,
|
|
32
|
+
refLabel,
|
|
33
|
+
reorder,
|
|
34
|
+
same,
|
|
35
|
+
sameRef,
|
|
36
|
+
selectedItems,
|
|
37
|
+
setSort,
|
|
38
|
+
shareBase,
|
|
39
|
+
sortEntry,
|
|
40
|
+
sortOf,
|
|
41
|
+
sortText,
|
|
42
|
+
sourceOf,
|
|
43
|
+
useModal,
|
|
44
|
+
valueConditionText,
|
|
45
|
+
valueLabel,
|
|
46
|
+
viewFromObject,
|
|
47
|
+
viewFromText,
|
|
48
|
+
withLinkParam
|
|
49
|
+
} from "./chunks/chunk-X7H7BAVT.js";
|
|
50
|
+
import {
|
|
51
|
+
addMenuTexts,
|
|
52
|
+
hasMenuTexts,
|
|
53
|
+
menuLabels
|
|
54
|
+
} from "./chunks/chunk-LQCWFJBS.js";
|
|
55
|
+
import {
|
|
56
|
+
fill,
|
|
57
|
+
hostFailure,
|
|
58
|
+
messageOf,
|
|
59
|
+
plural
|
|
60
|
+
} from "./chunks/chunk-F6MVUAQD.js";
|
|
61
|
+
|
|
62
|
+
// src/chip-menus.jsx
|
|
63
|
+
import React2, { useContext as useContext2, useEffect, useId as useId2, useRef, useState } from "react";
|
|
64
|
+
import { CATALOG, aggregatorsFor, fieldLabel, isFormat as isFormat2 } from "pivotkit-core";
|
|
65
|
+
|
|
66
|
+
// src/numbers.js
|
|
67
|
+
var cache = /* @__PURE__ */ new Map();
|
|
68
|
+
function marks(locale) {
|
|
69
|
+
let m = cache.get(locale);
|
|
70
|
+
if (!m) {
|
|
71
|
+
let parts;
|
|
72
|
+
try {
|
|
73
|
+
parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
74
|
+
} catch {
|
|
75
|
+
parts = new Intl.NumberFormat("en-US").formatToParts(12345.6);
|
|
76
|
+
}
|
|
77
|
+
m = {
|
|
78
|
+
decimal: parts.find((p) => p.type === "decimal")?.value ?? ".",
|
|
79
|
+
group: parts.find((p) => p.type === "group")?.value ?? ","
|
|
80
|
+
};
|
|
81
|
+
cache.set(locale, m);
|
|
82
|
+
}
|
|
83
|
+
return m;
|
|
84
|
+
}
|
|
85
|
+
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
86
|
+
var PLAIN = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
87
|
+
function parseNumber(text, locale) {
|
|
88
|
+
const t = String(text ?? "").replace(/[\s\u00a0\u202f]/g, "").replace(/\u2212/g, "-");
|
|
89
|
+
if (t === "") {
|
|
90
|
+
return null;
|
|
91
|
+
}
|
|
92
|
+
const { decimal, group } = marks(locale);
|
|
93
|
+
const g = /[\s\u00a0\u202f]/.test(group) ? "" : escape(group);
|
|
94
|
+
const d = escape(decimal);
|
|
95
|
+
const grouped = g ? `\\d{1,3}(?:${g}\\d{3})+` : "(?!)";
|
|
96
|
+
const local = new RegExp(`^([+-]?)(${grouped}|\\d+)?(?:${d}(\\d+))?$`);
|
|
97
|
+
const match = local.exec(t);
|
|
98
|
+
if (match && (match[2] !== void 0 || match[3] !== void 0)) {
|
|
99
|
+
const whole = (match[2] ?? "0").split(group).join("");
|
|
100
|
+
const n = Number(`${match[1]}${whole}${match[3] !== void 0 ? `.${match[3]}` : ""}`);
|
|
101
|
+
return Number.isFinite(n) ? n : null;
|
|
102
|
+
}
|
|
103
|
+
if (PLAIN.test(t)) {
|
|
104
|
+
const n = Number(t);
|
|
105
|
+
return Number.isFinite(n) ? n : null;
|
|
106
|
+
}
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
function numberText(n, locale) {
|
|
110
|
+
if (typeof n !== "number" || !Number.isFinite(n)) {
|
|
111
|
+
return "";
|
|
112
|
+
}
|
|
113
|
+
try {
|
|
114
|
+
return n.toLocaleString(locale, { useGrouping: false, maximumFractionDigits: 20 });
|
|
115
|
+
} catch {
|
|
116
|
+
return String(n);
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
// src/section.jsx
|
|
121
|
+
import React, { useContext, useId } from "react";
|
|
122
|
+
function SettingInfo({ id, name }) {
|
|
123
|
+
const { explain, labels } = useContext(HelpContext);
|
|
124
|
+
const text = labels && labels.settingInfo && Object.hasOwn(labels.settingInfo, id) ? labels.settingInfo[id] : null;
|
|
125
|
+
if (!explain || !labels || !text) {
|
|
126
|
+
return null;
|
|
127
|
+
}
|
|
128
|
+
return /* @__PURE__ */ React.createElement(InfoButton, { info: { description: text }, name, label: fill(labels.aboutSetting, { setting: name }), labels, className: "pk-setting-info", testId: `setting-info-${id}` });
|
|
129
|
+
}
|
|
130
|
+
function Section({ title, children, id, info, state, changed }) {
|
|
131
|
+
const titleId = useId();
|
|
132
|
+
const bodyId = useId();
|
|
133
|
+
const { isOpen, setOpen, labels } = useContext(HelpContext);
|
|
134
|
+
const name = typeof title === "string" ? title : "";
|
|
135
|
+
const head = info ? /* @__PURE__ */ React.createElement(SettingInfo, { id: info, name }) : null;
|
|
136
|
+
if (!id) {
|
|
137
|
+
return /* @__PURE__ */ React.createElement("div", { className: "pk-section", role: "group", "aria-labelledby": titleId }, /* @__PURE__ */ React.createElement("div", { className: "pk-section-head" }, /* @__PURE__ */ React.createElement("div", { className: "pk-section-title", id: titleId }, title), head), children);
|
|
138
|
+
}
|
|
139
|
+
const open = isOpen(id);
|
|
140
|
+
const shown = !open && state;
|
|
141
|
+
const label = shown && name ? `${name}, ${state}${changed && labels?.sectionChanged ? labels.sectionChanged : ""}` : void 0;
|
|
142
|
+
return /* @__PURE__ */ React.createElement("div", { className: `pk-section${open ? "" : " pk-folded"}`, role: "group", "aria-labelledby": titleId, "data-section": id }, /* @__PURE__ */ React.createElement("div", { className: "pk-section-head" }, /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-section-title pk-section-toggle", id: titleId, "aria-expanded": open, "aria-controls": bodyId, "aria-label": label, onClick: () => setOpen(id, !open), "data-testid": `section-${id}` }, /* @__PURE__ */ React.createElement(Icon, { name: open ? "chevronDown" : "chevronRight", size: 18 }), /* @__PURE__ */ React.createElement("span", { className: "pk-section-name" }, title), shown ? /* @__PURE__ */ React.createElement("span", { className: "pk-section-state pk-badge-cut", "data-testid": `section-state-${id}` }, changed ? /* @__PURE__ */ React.createElement("span", { className: "pk-section-mark", "aria-hidden": "true" }, "\u25CF ") : null, state) : null), head), /* @__PURE__ */ React.createElement("div", { id: bodyId, className: "pk-section-body", hidden: !open }, children));
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// src/menu-ops.js
|
|
146
|
+
import { isFormat } from "pivotkit-core";
|
|
147
|
+
var COUNTING = /* @__PURE__ */ new Set(["count", "countUnique", "listUnique"]);
|
|
148
|
+
var unitOf = (agg) => COUNTING.has(agg) ? "count" : "field";
|
|
149
|
+
function updateValue(view, index, patch, options = {}) {
|
|
150
|
+
const next = clone(view);
|
|
151
|
+
if (!next.values[index]) {
|
|
152
|
+
return view;
|
|
153
|
+
}
|
|
154
|
+
const before = view.values[index];
|
|
155
|
+
const value = { ...next.values[index], ...patch };
|
|
156
|
+
if (patch.agg && patch.agg !== before.agg) {
|
|
157
|
+
value.showAs = patch.showAs ?? null;
|
|
158
|
+
const wanted = options.defaults ?? {};
|
|
159
|
+
const hostFormat = typeof wanted.format === "string" && isFormat(wanted.format) ? wanted.format : null;
|
|
160
|
+
const own = before.format && before.format !== hostFormat ? before.format : null;
|
|
161
|
+
if (patch.format !== void 0) {
|
|
162
|
+
value.format = patch.format;
|
|
163
|
+
} else if (own) {
|
|
164
|
+
value.format = unitOf(before.agg) === unitOf(patch.agg) ? own : null;
|
|
165
|
+
} else {
|
|
166
|
+
value.format = hostFormat && unitOf(typeof wanted.agg === "string" ? wanted.agg : "sum") === unitOf(patch.agg) ? hostFormat : null;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
next.values[index] = value;
|
|
170
|
+
return next;
|
|
171
|
+
}
|
|
172
|
+
function binProblem(size, start, range) {
|
|
173
|
+
if (!range) {
|
|
174
|
+
return null;
|
|
175
|
+
}
|
|
176
|
+
for (const v of [range.min, range.max]) {
|
|
177
|
+
const k = Math.floor((v - start) / size);
|
|
178
|
+
const low = start + k * size;
|
|
179
|
+
const slack = size * 1e-9;
|
|
180
|
+
if (!Number.isSafeInteger(k) || low + size === low || low > v + slack || v >= low + size + slack) {
|
|
181
|
+
return "far";
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
function replaceFilters(view, field, types, entries) {
|
|
187
|
+
const next = clone(view);
|
|
188
|
+
const index = next.filters.findIndex((f) => same(f.field, field));
|
|
189
|
+
const kept = next.filters.filter((f) => !(same(f.field, field) && types.includes(f.type)));
|
|
190
|
+
const at = index === -1 ? kept.length : Math.min(index, kept.length);
|
|
191
|
+
kept.splice(at, 0, ...entries);
|
|
192
|
+
next.filters = kept;
|
|
193
|
+
if (!axisOf(next, field) && filterZoneFields(view).some((f) => same(f, field)) && !kept.some((f) => same(f.field, field))) {
|
|
194
|
+
next.filters.splice(at, 0, { field, type: "exclude", items: [] });
|
|
195
|
+
}
|
|
196
|
+
return next;
|
|
197
|
+
}
|
|
198
|
+
function replaceFilter(view, field, previous, entry) {
|
|
199
|
+
const next = clone(view);
|
|
200
|
+
const key = previous ? JSON.stringify(previous) : null;
|
|
201
|
+
const at = key === null ? -1 : next.filters.findIndex((f) => same(f.field, field) && JSON.stringify(f) === key);
|
|
202
|
+
if (at === -1) {
|
|
203
|
+
if (!entry) {
|
|
204
|
+
return next;
|
|
205
|
+
}
|
|
206
|
+
const last = next.filters.map((f) => same(f.field, field)).lastIndexOf(true);
|
|
207
|
+
next.filters.splice(last + 1, 0, entry);
|
|
208
|
+
return next;
|
|
209
|
+
}
|
|
210
|
+
if (entry) {
|
|
211
|
+
next.filters[at] = entry;
|
|
212
|
+
} else {
|
|
213
|
+
next.filters.splice(at, 1);
|
|
214
|
+
if (!axisOf(next, field) && filterZoneFields(view).some((f) => same(f, field)) && !next.filters.some((f) => same(f.field, field))) {
|
|
215
|
+
next.filters.splice(at, 0, { field, type: "exclude", items: [] });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
return next;
|
|
219
|
+
}
|
|
220
|
+
function setItemFilter(view, field, selected, all) {
|
|
221
|
+
const keep = new Set(selected.map((v) => JSON.stringify(v)));
|
|
222
|
+
const excluded = all.filter((v) => !keep.has(JSON.stringify(v)));
|
|
223
|
+
return replaceFilters(view, field, ["include", "exclude"], excluded.length ? [{ field, type: "exclude", items: excluded }] : []);
|
|
224
|
+
}
|
|
225
|
+
function setLabelFilter(view, field, condition) {
|
|
226
|
+
return replaceFilters(view, field, ["label"], condition && condition.value !== "" ? [{ field, type: "label", op: condition.op, value: condition.value }] : []);
|
|
227
|
+
}
|
|
228
|
+
function setTopFilter(view, field, top, previous) {
|
|
229
|
+
const entry = top ? { field, type: "top", count: top.count, bottom: Boolean(top.bottom), ...top.by ? { by: top.by } : {} } : null;
|
|
230
|
+
if (previous) {
|
|
231
|
+
return replaceFilter(view, field, previous, entry);
|
|
232
|
+
}
|
|
233
|
+
return replaceFilters(view, field, ["top"], entry ? [entry] : []);
|
|
234
|
+
}
|
|
235
|
+
function setValueFilter(view, field, condition, previous) {
|
|
236
|
+
let entry = null;
|
|
237
|
+
if (condition) {
|
|
238
|
+
const { by, op, value, value2 } = condition;
|
|
239
|
+
const between = op === "between" || op === "notBetween";
|
|
240
|
+
entry = { field, type: "value", by: { field: by.field, agg: by.agg }, op, value, ...between ? { value2 } : {} };
|
|
241
|
+
}
|
|
242
|
+
if (previous) {
|
|
243
|
+
return replaceFilter(view, field, previous, entry);
|
|
244
|
+
}
|
|
245
|
+
return replaceFilters(view, field, ["value"], entry ? [entry] : []);
|
|
246
|
+
}
|
|
247
|
+
function withMeasure(choices, ref) {
|
|
248
|
+
return ref && !choices.some((c) => sameRef(c, ref)) ? [...choices, { field: ref.field ?? null, agg: ref.agg }] : choices;
|
|
249
|
+
}
|
|
250
|
+
function measureChoices(view, typeOf) {
|
|
251
|
+
const out = [];
|
|
252
|
+
for (const v of view.values) {
|
|
253
|
+
const ref = { field: v.field ?? null, agg: v.agg };
|
|
254
|
+
if (numericResult(v, v.field ? typeOf(v.field) ?? "string" : "number") && !out.some((r) => sameRef(r, ref))) {
|
|
255
|
+
out.push(ref);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
return out.length ? out : [{ field: null, agg: "count" }];
|
|
259
|
+
}
|
|
260
|
+
function removeFilters(view, field) {
|
|
261
|
+
return replaceFilters(view, field, ["include", "exclude", "label", "value"], []);
|
|
262
|
+
}
|
|
263
|
+
function hasFilter(view, field) {
|
|
264
|
+
return filtersOf(view, field, ["include", "exclude", "label", "value"]).some((f) => f.type !== "exclude" || f.items.length > 0);
|
|
265
|
+
}
|
|
266
|
+
var TOTALS = Object.freeze(["grandTotalRow", "grandTotalColumn", "rowSubtotals", "colSubtotals"]);
|
|
267
|
+
function totalNoEffect(view, key) {
|
|
268
|
+
if (key === "grandTotalRow") {
|
|
269
|
+
return view.rows.length >= 1 ? null : "needsRowField";
|
|
270
|
+
}
|
|
271
|
+
if (key === "grandTotalColumn") {
|
|
272
|
+
return view.cols.length >= 1 ? null : "needsColField";
|
|
273
|
+
}
|
|
274
|
+
if (key === "rowSubtotals") {
|
|
275
|
+
return view.rows.length >= 2 ? null : "needsRowFields";
|
|
276
|
+
}
|
|
277
|
+
return view.cols.length >= 2 ? null : "needsColFields";
|
|
278
|
+
}
|
|
279
|
+
function conditionKind(encoded, view, field) {
|
|
280
|
+
const type = encoded.column(sourceOf(view, field))?.type ?? "string";
|
|
281
|
+
return type === "date" || type === "boolean" ? null : type === "number" ? "number" : "text";
|
|
282
|
+
}
|
|
283
|
+
function filterText(view, field, state, labels, locale) {
|
|
284
|
+
const same2 = (f) => typeof f.field === "string" && f.field.toLowerCase() === field.toLowerCase();
|
|
285
|
+
const parts = [];
|
|
286
|
+
if (state && state.summary) {
|
|
287
|
+
parts.push(fill(labels.filterSummary, { shown: state.summary.shown.toLocaleString(locale), total: state.summary.total.toLocaleString(locale) }));
|
|
288
|
+
}
|
|
289
|
+
for (const f of view.filters.filter(same2)) {
|
|
290
|
+
if (f.type === "label") {
|
|
291
|
+
const op = Object.hasOwn(labels.labelOps, f.op) ? labels.labelOps[f.op] : f.op;
|
|
292
|
+
parts.push(`${op} \u201C${f.value}\u201D`);
|
|
293
|
+
} else if (f.type === "value") {
|
|
294
|
+
parts.push(valueConditionText(view, f, labels, locale));
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
return parts.length ? fill(labels.filterIs, { filter: parts.join(", ") }) : null;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
// src/chip-menus.jsx
|
|
301
|
+
var FORMAT_CHOICES = ["number", "number:0", "number:2", "currency", "percent"].filter(isFormat2);
|
|
302
|
+
var MORE_FORMATS = ["integer", "compact", "bytes", "duration:h", "duration:s"].filter(isFormat2);
|
|
303
|
+
var COMMON_SHOW_AS = CATALOG.showAs.filter((s) => ["percentOfGrandTotal", "percentOfRowTotal", "percentOfColumnTotal"].includes(s));
|
|
304
|
+
function More({ title, open, children }) {
|
|
305
|
+
return /* @__PURE__ */ React2.createElement("details", { className: "pk-more", open }, /* @__PURE__ */ React2.createElement("summary", { className: "pk-more-title" }, title), children);
|
|
306
|
+
}
|
|
307
|
+
function readNumber(text, { kind = "number", required = true, tried = false, labels, locale }) {
|
|
308
|
+
const value = parseNumber(text, locale);
|
|
309
|
+
const ok = value !== null && (kind === "number" || (kind === "size" ? value > 0 : Number.isInteger(value) && value >= 1));
|
|
310
|
+
const say = () => kind === "count" ? labels.countInvalid : fill(kind === "size" ? labels.sizeInvalid : labels.numberInvalid, { example: (kind === "size" ? 0.5 : 1234.5).toLocaleString(locale) });
|
|
311
|
+
if (text.trim() === "") {
|
|
312
|
+
return { value: null, problem: required && tried ? say() : null };
|
|
313
|
+
}
|
|
314
|
+
return ok ? { value, problem: null } : { value: null, problem: say() };
|
|
315
|
+
}
|
|
316
|
+
function NumberField({ value, onChange, problem, label, testId, className = "pk-field-label", shown, shownClass }) {
|
|
317
|
+
const id = useId2();
|
|
318
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("label", { className }, shown ? /* @__PURE__ */ React2.createElement("span", { className: shownClass }, shown) : /* @__PURE__ */ React2.createElement("span", { className: "pk-sr" }, label), /* @__PURE__ */ React2.createElement(
|
|
319
|
+
"input",
|
|
320
|
+
{
|
|
321
|
+
type: "text",
|
|
322
|
+
inputMode: "decimal",
|
|
323
|
+
autoComplete: "off",
|
|
324
|
+
spellCheck: false,
|
|
325
|
+
value,
|
|
326
|
+
onChange: (e) => onChange(e.target.value),
|
|
327
|
+
"aria-label": label,
|
|
328
|
+
"aria-invalid": problem ? true : void 0,
|
|
329
|
+
"aria-describedby": problem ? id : void 0,
|
|
330
|
+
"data-testid": testId
|
|
331
|
+
}
|
|
332
|
+
)), problem ? /* @__PURE__ */ React2.createElement("p", { id, className: "pk-form-problem", "data-testid": `${testId}-problem` }, problem) : null);
|
|
333
|
+
}
|
|
334
|
+
function BinForm({ grouping, labels, onApply, onClear, onCancel, range, locale }) {
|
|
335
|
+
const [size, setSize] = useState(numberText(grouping?.size, locale));
|
|
336
|
+
const [start, setStart] = useState(numberText(grouping?.origin, locale));
|
|
337
|
+
const [tried, setTried] = useState(false);
|
|
338
|
+
const problemId = useId2();
|
|
339
|
+
const sized = readNumber(size, { kind: "size", tried, labels, locale });
|
|
340
|
+
const started = readNumber(start, { required: false, labels, locale });
|
|
341
|
+
const n = sized.value;
|
|
342
|
+
const s = start.trim() === "" ? 0 : started.value;
|
|
343
|
+
const far = n !== null && s !== null && binProblem(n, s, range) === "far";
|
|
344
|
+
const number = (x) => x.toLocaleString(locale, { maximumFractionDigits: 6 });
|
|
345
|
+
return /* @__PURE__ */ React2.createElement(
|
|
346
|
+
"form",
|
|
347
|
+
{
|
|
348
|
+
className: "pk-inline-form pk-bin-form",
|
|
349
|
+
onSubmit: (e) => {
|
|
350
|
+
e.preventDefault();
|
|
351
|
+
if (onClear && size.trim() === "") {
|
|
352
|
+
onClear();
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
setTried(true);
|
|
356
|
+
if (n !== null && s !== null && !far) {
|
|
357
|
+
onApply(n, s);
|
|
358
|
+
}
|
|
359
|
+
}
|
|
360
|
+
},
|
|
361
|
+
/* @__PURE__ */ React2.createElement(NumberField, { value: size, onChange: setSize, problem: sized.problem, label: labels.binSize, shown: labels.binSize, testId: "bin-size" }),
|
|
362
|
+
/* @__PURE__ */ React2.createElement("label", { className: "pk-field-label" }, /* @__PURE__ */ React2.createElement("span", null, labels.binStart), /* @__PURE__ */ React2.createElement(ClearInput, { type: "text", inputMode: "decimal", autoComplete: "off", spellCheck: false, value: start, placeholder: "0", onChange: setStart, clearLabel: labels.clearText, "data-testid": "bin-start", "aria-invalid": far || started.problem ? true : void 0, "aria-describedby": far || started.problem ? problemId : void 0 })),
|
|
363
|
+
started.problem ? /* @__PURE__ */ React2.createElement("p", { id: problemId, className: "pk-form-problem", "data-testid": "bin-start-problem" }, started.problem) : far && range && s !== null && n !== null ? /* @__PURE__ */ React2.createElement("p", { id: problemId, className: "pk-form-problem", "data-testid": "bin-problem" }, fill(labels.binStartFar, { start: number(s), min: number(range.min), max: number(range.max) })) : null,
|
|
364
|
+
/* @__PURE__ */ React2.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: far }, labels.apply),
|
|
365
|
+
/* @__PURE__ */ React2.createElement(CancelButton, { labels, onCancel, testId: "bin-cancel" })
|
|
366
|
+
);
|
|
367
|
+
}
|
|
368
|
+
function MeasurePick({ choices, names, index, onChange, label, prefix, testId }) {
|
|
369
|
+
if (choices.length < 2) {
|
|
370
|
+
return /* @__PURE__ */ React2.createElement("span", { className: "pk-muted pk-by" }, prefix ? `${prefix} ${names[0]}` : names[0]);
|
|
371
|
+
}
|
|
372
|
+
return /* @__PURE__ */ React2.createElement("label", { className: "pk-field-label pk-by-pick" }, prefix ? /* @__PURE__ */ React2.createElement("span", { className: "pk-muted" }, prefix) : /* @__PURE__ */ React2.createElement("span", { className: "pk-sr" }, label), /* @__PURE__ */ React2.createElement("select", { value: index, onChange: (e) => onChange(Number(e.target.value)), "aria-label": label, "data-testid": testId }, choices.map((c, i) => /* @__PURE__ */ React2.createElement("option", { key: `${c.field}:${c.agg}`, value: i }, names[i]))));
|
|
373
|
+
}
|
|
374
|
+
var choiceIndex = (choices, ref) => Math.max(0, choices.findIndex((c) => sameRef(c, ref)));
|
|
375
|
+
function TopForm({ top, labels, choices, names, onApply, onCancel, locale }) {
|
|
376
|
+
const [count, setCount] = useState(numberText(top?.count ?? 10, locale));
|
|
377
|
+
const [bottom, setBottom] = useState(Boolean(top?.bottom));
|
|
378
|
+
const [by, setBy] = useState(() => choiceIndex(choices, top?.by));
|
|
379
|
+
const [tried, setTried] = useState(false);
|
|
380
|
+
const counted = readNumber(count, { kind: "count", tried, labels, locale });
|
|
381
|
+
return /* @__PURE__ */ React2.createElement(
|
|
382
|
+
"form",
|
|
383
|
+
{
|
|
384
|
+
className: "pk-inline-form",
|
|
385
|
+
onSubmit: (e) => {
|
|
386
|
+
e.preventDefault();
|
|
387
|
+
if (top && count.trim() === "") {
|
|
388
|
+
onApply(null);
|
|
389
|
+
return;
|
|
390
|
+
}
|
|
391
|
+
setTried(true);
|
|
392
|
+
if (counted.value !== null) {
|
|
393
|
+
onApply({ count: counted.value, bottom, by: choices[by] });
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
/* @__PURE__ */ React2.createElement("div", { className: "pk-segmented pk-small", role: "group", "aria-label": labels.topN }, /* @__PURE__ */ React2.createElement("button", { type: "button", "aria-pressed": !bottom, onClick: () => setBottom(false) }, labels.top), /* @__PURE__ */ React2.createElement("button", { type: "button", "aria-pressed": bottom, onClick: () => setBottom(true) }, labels.bottom)),
|
|
398
|
+
/* @__PURE__ */ React2.createElement(NumberField, { value: count, onChange: setCount, problem: counted.problem, label: labels.topCount, testId: "top-count", className: "pk-field-label pk-narrow-input" }),
|
|
399
|
+
/* @__PURE__ */ React2.createElement(MeasurePick, { choices, names, index: by, onChange: setBy, label: labels.topBy, prefix: labels.topBy, testId: "top-by" }),
|
|
400
|
+
/* @__PURE__ */ React2.createElement("button", { type: "submit", className: "pk-btn pk-primary" }, labels.apply),
|
|
401
|
+
/* @__PURE__ */ React2.createElement(CancelButton, { labels, onCancel, testId: "top-cancel" })
|
|
402
|
+
);
|
|
403
|
+
}
|
|
404
|
+
function ValueFilterForm({ condition, labels, choices, names, onApply, onCancel, locale }) {
|
|
405
|
+
const [by, setBy] = useState(() => choiceIndex(choices, condition?.by));
|
|
406
|
+
const [op, setOp] = useState(condition?.op ?? ">");
|
|
407
|
+
const [first, setFirst] = useState(numberText(condition?.value, locale));
|
|
408
|
+
const [second, setSecond] = useState(numberText(condition?.value2, locale));
|
|
409
|
+
const [tried, setTried] = useState(false);
|
|
410
|
+
const between = op === "between" || op === "notBetween";
|
|
411
|
+
const a = readNumber(first, { tried, labels, locale });
|
|
412
|
+
const b = readNumber(second, { tried, labels, locale });
|
|
413
|
+
const ok = a.value !== null && (!between || b.value !== null);
|
|
414
|
+
return /* @__PURE__ */ React2.createElement(
|
|
415
|
+
"form",
|
|
416
|
+
{
|
|
417
|
+
className: "pk-inline-form pk-value-filter",
|
|
418
|
+
onSubmit: (e) => {
|
|
419
|
+
e.preventDefault();
|
|
420
|
+
if (condition && first.trim() === "" && second.trim() === "") {
|
|
421
|
+
onApply(null);
|
|
422
|
+
return;
|
|
423
|
+
}
|
|
424
|
+
setTried(true);
|
|
425
|
+
if (ok) {
|
|
426
|
+
onApply({ by: choices[by], op, value: (
|
|
427
|
+
/** @type {number} */
|
|
428
|
+
a.value
|
|
429
|
+
), ...between ? { value2: (
|
|
430
|
+
/** @type {number} */
|
|
431
|
+
b.value
|
|
432
|
+
) } : {} });
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
/* @__PURE__ */ React2.createElement(MeasurePick, { choices, names, index: by, onChange: setBy, label: labels.valueFilterBy, testId: "value-filter-by" }),
|
|
437
|
+
/* @__PURE__ */ React2.createElement("label", { className: "pk-field-label" }, /* @__PURE__ */ React2.createElement("span", { className: "pk-sr" }, labels.valueFilterOp), /* @__PURE__ */ React2.createElement("select", { value: op, onChange: (e) => setOp(e.target.value), "aria-label": labels.valueFilterOp, "data-testid": "value-filter-op" }, CATALOG.valueOps.map((o) => /* @__PURE__ */ React2.createElement("option", { key: o, value: o }, labels.valueOps[o] ?? o)))),
|
|
438
|
+
/* @__PURE__ */ React2.createElement(NumberField, { value: first, onChange: setFirst, problem: a.problem, label: labels.valueFilterNumber, testId: "value-filter-number", className: "pk-field-label pk-narrow-input" }),
|
|
439
|
+
between ? /* @__PURE__ */ React2.createElement(NumberField, { value: second, onChange: setSecond, problem: b.problem, label: `${labels.valueFilterTo} ${labels.valueFilterNumber}`, shown: labels.valueFilterTo, shownClass: "pk-muted", testId: "value-filter-number2", className: "pk-field-label pk-narrow-input" }) : null,
|
|
440
|
+
/* @__PURE__ */ React2.createElement("button", { type: "submit", className: "pk-btn pk-primary", "data-testid": "value-filter-apply" }, labels.apply),
|
|
441
|
+
/* @__PURE__ */ React2.createElement(CancelButton, { labels, onCancel, testId: "value-filter-cancel" })
|
|
442
|
+
);
|
|
443
|
+
}
|
|
444
|
+
function CancelButton({ labels, onCancel, testId }) {
|
|
445
|
+
return /* @__PURE__ */ React2.createElement("button", { type: "button", className: "pk-btn", onClick: onCancel, "data-testid": testId }, labels.cancel);
|
|
446
|
+
}
|
|
447
|
+
function Editable({ text, start, icon, labels, onRemove, testId, form }) {
|
|
448
|
+
const [editing, setEditing] = useState(false);
|
|
449
|
+
const box = useRef(
|
|
450
|
+
/** @type {HTMLDivElement | null} */
|
|
451
|
+
null
|
|
452
|
+
);
|
|
453
|
+
const was = useRef(false);
|
|
454
|
+
useEffect(() => {
|
|
455
|
+
if (editing !== was.current) {
|
|
456
|
+
was.current = editing;
|
|
457
|
+
box.current?.querySelector(editing ? "input, select" : "button")?.focus({ preventScroll: true });
|
|
458
|
+
box.current?.scrollIntoView({ block: "nearest" });
|
|
459
|
+
}
|
|
460
|
+
}, [editing]);
|
|
461
|
+
return /* @__PURE__ */ React2.createElement("div", { ref: box, className: "pk-editable" }, editing ? form(() => setEditing(false)) : text ? /* @__PURE__ */ React2.createElement("div", { className: "pk-inline-form pk-state-line", "data-testid": `${testId}-state` }, /* @__PURE__ */ React2.createElement("span", { className: "pk-state-text" }, text), /* @__PURE__ */ React2.createElement("button", { type: "button", className: "pk-link", onClick: () => setEditing(true), "data-testid": `${testId}-change` }, labels.change), /* @__PURE__ */ React2.createElement("button", { type: "button", className: "pk-link", onClick: onRemove, "data-testid": `${testId}-remove` }, labels.removeSetting)) : /* @__PURE__ */ React2.createElement(Option, { icon, onSelect: () => setEditing(true), testId: `${testId}-open` }, start));
|
|
462
|
+
}
|
|
463
|
+
function MenuHead({ name, info, extra, labels }) {
|
|
464
|
+
if (!info?.description && !extra) {
|
|
465
|
+
return null;
|
|
466
|
+
}
|
|
467
|
+
const text = /* @__PURE__ */ React2.createElement(React2.Fragment, null, info?.description, info?.href ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, " ", /* @__PURE__ */ React2.createElement("a", { href: info.href, target: "_blank", rel: "noopener noreferrer", className: "pk-learn-more" }, labels.learnMore)) : null, info?.description && extra ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("br", null), /* @__PURE__ */ React2.createElement("br", null)) : null, extra);
|
|
468
|
+
return /* @__PURE__ */ React2.createElement("div", { className: "pk-section" }, /* @__PURE__ */ React2.createElement("div", { className: "pk-section-head" }, /* @__PURE__ */ React2.createElement("div", { className: "pk-section-title", "data-testid": "menu-head" }, name), /* @__PURE__ */ React2.createElement(InfoButton, { info: { description: (
|
|
469
|
+
/** @type {any} */
|
|
470
|
+
text
|
|
471
|
+
) }, name, labels, className: "pk-menu-info", testId: "menu-info" })));
|
|
472
|
+
}
|
|
473
|
+
function MoveSection({ view, zone, index, count, labels, commit, close, text, type }) {
|
|
474
|
+
return /* @__PURE__ */ React2.createElement(Section, { title: labels.move, id: "move" }, ZONES.filter((z) => z !== zone).map((z) => /* @__PURE__ */ React2.createElement(Option, { key: z, icon: ZONE_ICON[z], onSelect: () => {
|
|
475
|
+
close();
|
|
476
|
+
commit(moveField(view, zone, index, z, void 0, { type }), { step: "moved", field: text, zone: z });
|
|
477
|
+
}, testId: `move-${z}` }, fill(labels.moveTo, { zone: labels.zones[z] }))), zone !== "filters" && index > 0 ? /* @__PURE__ */ React2.createElement(Option, { icon: "chevronRight", onSelect: () => {
|
|
478
|
+
close();
|
|
479
|
+
commit(reorder(view, zone, index, index - 1), { step: "reordered", zone });
|
|
480
|
+
} }, labels.moveLeft) : null, zone !== "filters" && index < count - 1 ? /* @__PURE__ */ React2.createElement(Option, { icon: "chevronRight", onSelect: () => {
|
|
481
|
+
close();
|
|
482
|
+
commit(reorder(view, zone, index, index + 1), { step: "reordered", zone });
|
|
483
|
+
} }, labels.moveRight) : null);
|
|
484
|
+
}
|
|
485
|
+
function RemoveFoot({ labels, onRemove, close }) {
|
|
486
|
+
return /* @__PURE__ */ React2.createElement("div", { className: "pk-menu-foot" }, /* @__PURE__ */ React2.createElement(Option, { icon: "trash", danger: true, onSelect: () => {
|
|
487
|
+
close();
|
|
488
|
+
onRemove();
|
|
489
|
+
}, testId: "menu-remove" }, labels.remove));
|
|
490
|
+
}
|
|
491
|
+
function AxisMenu({ view, zone, index, field, types, labels, commit, close, openFilter, chipRef, onRemove, defaultsOf, rangeOf, locale, info, state }) {
|
|
492
|
+
const source = sourceOf(view, field);
|
|
493
|
+
const name = fieldLabel(field, labels.core);
|
|
494
|
+
const sourceType = types.get(source.toLowerCase());
|
|
495
|
+
const grouping = groupingOf(view, field);
|
|
496
|
+
const sort = sortOf(view, field);
|
|
497
|
+
const shown = measureChoices(view, (f) => types.get(f.toLowerCase()));
|
|
498
|
+
const top = filtersOf(view, field, ["top"])[0];
|
|
499
|
+
const condition = filtersOf(view, field, ["value"])[0];
|
|
500
|
+
const pick = (ref) => {
|
|
501
|
+
const list = withMeasure(shown, ref);
|
|
502
|
+
return { choices: list, names: list.map((c) => refLabel(view, c, labels)) };
|
|
503
|
+
};
|
|
504
|
+
const { choices, names } = pick(sort?.by === "value" ? sort.value : null);
|
|
505
|
+
const topPick = pick(top?.by);
|
|
506
|
+
const conditionPick = pick(condition?.by);
|
|
507
|
+
const isSort = (by, order, ref) => sort ? sort.by === by && sort.order === order && (by !== "value" || sameRef(sort.value, ref)) : by === "label" && order === "asc";
|
|
508
|
+
const hostOrder = source === field ? defaultsOf?.(source)?.order : void 0;
|
|
509
|
+
const customItems = sort?.by === "custom" ? sort.items : Array.isArray(hostOrder) && hostOrder.length > 0 ? hostOrder : null;
|
|
510
|
+
const doSort = (by, order, ref) => {
|
|
511
|
+
close();
|
|
512
|
+
const spec = by === "value" ? { by, order, value: ref } : by === "custom" ? { by, order, items: [...customItems] } : { by, order };
|
|
513
|
+
commit(setSort(view, field, sortEntry(spec, Array.isArray(hostOrder) && hostOrder.length > 0)), { step: "sort", field: name });
|
|
514
|
+
};
|
|
515
|
+
const regroup = (unit, size, origin) => {
|
|
516
|
+
close();
|
|
517
|
+
const sourceName = fieldLabel(source, labels.core);
|
|
518
|
+
const grouped = unit ? groupingName(sourceName, unit, labels, size) : null;
|
|
519
|
+
commit(groupField(view, field, unit, { size, origin, name: grouped ?? void 0 }).view, { step: "group", field: sourceName });
|
|
520
|
+
};
|
|
521
|
+
const number = (x) => x.toLocaleString(locale, { maximumFractionDigits: 6 });
|
|
522
|
+
const topText = top ? `${fill(top.bottom ? labels.bottomBadge : labels.topBadge, { count: number(top.count) })} ${fill(labels.by, { value: topPick.names[choiceIndex(topPick.choices, top.by)] })}` : null;
|
|
523
|
+
const binsText = grouping?.by === "bin" ? fill(labels.binsState, { size: number(grouping.size), start: number(grouping.origin ?? 0) }) : null;
|
|
524
|
+
const unitOption = (u) => /* @__PURE__ */ React2.createElement(Option, { key: u, checked: grouping?.by === u, onSelect: () => regroup(u), testId: `group-${u}`, hint: labels.unitHints[u] || void 0 }, labels.units[u] ?? u);
|
|
525
|
+
const bins = grouping?.by === "bin" ? grouping : null;
|
|
526
|
+
const conditions = filtersOf(view, field, ["value"]);
|
|
527
|
+
const itemsView = { ...view, filters: view.filters.filter((f) => !conditions.includes(f)) };
|
|
528
|
+
const filtered = hasFilter(itemsView, field);
|
|
529
|
+
const filterLine = filtered ? filterText(itemsView, field, state, labels, locale) : null;
|
|
530
|
+
const prefix = labels.filterIs.split("{filter}")[0];
|
|
531
|
+
const filterState = [filterLine?.startsWith(prefix) ? filterLine.slice(prefix.length) : filterLine, condition ? valueConditionText(view, condition, labels, locale) : null].filter(Boolean).join(", ");
|
|
532
|
+
const removeItems = () => {
|
|
533
|
+
close();
|
|
534
|
+
const items = new Set(filtersOf(itemsView, field, ["include", "exclude", "label"]));
|
|
535
|
+
commit({ ...view, filters: view.filters.filter((f) => !items.has(f)) }, { step: "filter", field: name });
|
|
536
|
+
};
|
|
537
|
+
const setTop = (t) => {
|
|
538
|
+
close();
|
|
539
|
+
commit(setTopFilter(view, field, t, top), { step: "top", field: name });
|
|
540
|
+
};
|
|
541
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { className: "pk-menu-body" }, /* @__PURE__ */ React2.createElement(MenuHead, { name: fieldLabel(source, labels.core), info, labels }), /* @__PURE__ */ React2.createElement(Section, { title: labels.sort, id: "sort", state: sort ? sortText(view, sort, labels) : null, changed: Boolean(sort) }, /* @__PURE__ */ React2.createElement(Option, { checked: isSort("label", "asc"), icon: "sortAsc", onSelect: () => doSort("label", "asc") }, sourceType === "date" ? labels.sortOldest : labels.sortLabelAsc), /* @__PURE__ */ React2.createElement(Option, { checked: isSort("label", "desc"), icon: "sortDesc", onSelect: () => doSort("label", "desc") }, sourceType === "date" ? labels.sortNewest : labels.sortLabelDesc), choices.map((c, i) => /* @__PURE__ */ React2.createElement(React2.Fragment, { key: `${c.field}:${c.agg}` }, /* @__PURE__ */ React2.createElement(Option, { checked: isSort("value", "desc", c), icon: "sortDesc", onSelect: () => doSort("value", "desc", c), testId: `sort-value-desc-${i}` }, fill(labels.sortValueDesc, { value: names[i] })), /* @__PURE__ */ React2.createElement(Option, { checked: isSort("value", "asc", c), icon: "sortAsc", onSelect: () => doSort("value", "asc", c), testId: `sort-value-asc-${i}` }, fill(labels.sortValueAsc, { value: names[i] })))), customItems ? /* @__PURE__ */ React2.createElement(Option, { checked: isSort("custom", "asc"), icon: "sortAsc", onSelect: () => doSort("custom", "asc"), testId: "sort-custom" }, labels.sortCustom) : null, customItems ? /* @__PURE__ */ React2.createElement(Option, { checked: isSort("custom", "desc"), icon: "sortDesc", onSelect: () => doSort("custom", "desc"), testId: "sort-custom-desc" }, labels.sortCustomDesc) : null), /* @__PURE__ */ React2.createElement(Section, { title: labels.zones.filters, id: "filters", state: filterState || null, changed: Boolean(filterState) }, filtered ? /* @__PURE__ */ React2.createElement("div", { className: "pk-inline-form pk-state-line", "data-testid": "filter-state" }, /* @__PURE__ */ React2.createElement("span", { className: "pk-state-text" }, filterLine), /* @__PURE__ */ React2.createElement("button", { type: "button", className: "pk-link", onClick: removeItems, "data-testid": "remove-filter" }, labels.removeSetting)) : null, /* @__PURE__ */ React2.createElement(Option, { icon: "filter", onSelect: () => {
|
|
542
|
+
close();
|
|
543
|
+
openFilter(field, chipRef.current);
|
|
544
|
+
}, testId: "open-filter" }, labels.chooseValues), /* @__PURE__ */ React2.createElement(Editable, { text: condition ? valueConditionText(view, condition, labels, locale) : null, start: labels.valueFilter, icon: "sigma", labels, onRemove: () => {
|
|
545
|
+
close();
|
|
546
|
+
commit(setValueFilter(view, field, null, condition), { step: "filter", field: name });
|
|
547
|
+
}, testId: "value-filter", form: (cancel) => /* @__PURE__ */ React2.createElement(ValueFilterForm, { condition, labels, choices: conditionPick.choices, names: conditionPick.names, locale, onCancel: cancel, onApply: (c) => {
|
|
548
|
+
close();
|
|
549
|
+
commit(setValueFilter(view, field, c, condition), { step: "filter", field: name });
|
|
550
|
+
} }) })), /* @__PURE__ */ React2.createElement(Section, { title: labels.topN, id: "topN", state: top ? topText : null, changed: Boolean(top) }, /* @__PURE__ */ React2.createElement(Editable, { text: top ? topText : null, start: labels.topStart, icon: "top", labels, onRemove: () => setTop(null), testId: "top", form: (cancel) => /* @__PURE__ */ React2.createElement(TopForm, { top, labels, choices: topPick.choices, names: topPick.names, locale, onCancel: cancel, onApply: setTop }) })), sourceType === "date" ? /* @__PURE__ */ React2.createElement(Section, { title: labels.groupBy, id: "groupBy", state: grouping ? labels.units[grouping.by] ?? grouping.by : null, changed: Boolean(grouping) }, /* @__PURE__ */ React2.createElement("div", { className: "pk-subtitle" }, labels.groupTimeline), /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, CATALOG.timelineUnits.map(unitOption)), /* @__PURE__ */ React2.createElement("div", { className: "pk-subtitle" }, labels.groupCyclic), /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, CATALOG.cyclicUnits.map(unitOption)), /* @__PURE__ */ React2.createElement(Option, { checked: !grouping, onSelect: () => regroup(null), testId: "group-none" }, labels.groupNone)) : null, sourceType === "number" ? /* @__PURE__ */ React2.createElement(Section, { title: labels.bins, id: "bins", state: binsText, changed: Boolean(bins) }, /* @__PURE__ */ React2.createElement(Editable, { text: binsText, start: labels.binsStart, icon: "number", labels, onRemove: () => regroup(null), testId: "bin", form: (cancel) => /* @__PURE__ */ React2.createElement(BinForm, { grouping: bins, labels, range: rangeOf?.(source) ?? null, locale, onCancel: cancel, onApply: (size, origin) => regroup("bin", size, origin), onClear: bins ? () => regroup(null) : null }) })) : null, /* @__PURE__ */ React2.createElement(MoveSection, { view, zone, index, count: view[zone].length, labels, commit, close, text: name, type: sourceType })), /* @__PURE__ */ React2.createElement(RemoveFoot, { labels, onRemove, close }));
|
|
551
|
+
}
|
|
552
|
+
function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaultsOf, info }) {
|
|
553
|
+
const spec = view.values[index];
|
|
554
|
+
const type = spec.field ? types.get(spec.field.toLowerCase()) ?? "string" : "number";
|
|
555
|
+
const aggs = spec.field ? aggregatorsFor(type) : ["count"];
|
|
556
|
+
const common = CATALOG.commonAggregators.filter((a) => aggs.includes(a));
|
|
557
|
+
const rare = aggs.filter((a) => !CATALOG.commonAggregators.includes(a));
|
|
558
|
+
const otherShowAs = CATALOG.showAs.filter((s) => !COMMON_SHOW_AS.includes(s));
|
|
559
|
+
const numeric = numericResult(spec, type);
|
|
560
|
+
const name = valueLabel(spec, labels);
|
|
561
|
+
const set = (patch) => {
|
|
562
|
+
close();
|
|
563
|
+
commit(updateValue(view, index, patch, { defaults: spec.field ? defaultsOf?.(spec.field) : void 0 }), { step: "value", field: name });
|
|
564
|
+
};
|
|
565
|
+
const [rename, setRename] = useState(spec.label ?? "");
|
|
566
|
+
const { explain } = useContext2(HelpContext);
|
|
567
|
+
const aggOption = (a) => /* @__PURE__ */ React2.createElement(Option, { key: a, checked: spec.agg === a, onSelect: () => set({ agg: a }), testId: `agg-${a}` }, labels.core.aggregators[a] ?? a);
|
|
568
|
+
const formatOption = (f) => /* @__PURE__ */ React2.createElement(Option, { key: f, checked: spec.format === f, onSelect: () => set({ format: f }), testId: `format-${f}` }, labels.formats[f] ?? f);
|
|
569
|
+
const showAsOption = (s) => /* @__PURE__ */ React2.createElement(Option, { key: s, checked: spec.showAs?.type === s, onSelect: () => set({ showAs: { type: s, axis: spec.showAs?.axis ?? "rows" } }), testId: `showas-${s}` }, labels.showAsNames[s] ?? s);
|
|
570
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { className: "pk-menu-body" }, /* @__PURE__ */ React2.createElement(MenuHead, { name, info, extra: explain ? labels.settingInfo.valuesFilter : null, labels }), /* @__PURE__ */ React2.createElement(Section, { title: labels.aggregation, id: "summarize", state: labels.core.aggregators[spec.agg] ?? spec.agg }, /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, common.map(aggOption)), rare.length ? /* @__PURE__ */ React2.createElement(More, { title: labels.moreStatistics, open: rare.includes(spec.agg) }, /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, rare.map(aggOption))) : null), numeric ? /* @__PURE__ */ React2.createElement(Section, { title: labels.showAs, id: "showAs", info: "showAs", state: spec.showAs ? labels.showAsNames[spec.showAs.type] ?? spec.showAs.type : labels.showAsNone, changed: Boolean(spec.showAs) }, /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React2.createElement(Option, { checked: !spec.showAs, onSelect: () => set({ showAs: null }), testId: "showas-none" }, labels.showAsNone), COMMON_SHOW_AS.map(showAsOption)), /* @__PURE__ */ React2.createElement(More, { title: labels.moreCalculations, open: Boolean(spec.showAs && otherShowAs.includes(spec.showAs.type)) }, /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, otherShowAs.map(showAsOption))), spec.showAs && CATALOG.showAsAlongAxis.includes(spec.showAs.type) ? /* @__PURE__ */ React2.createElement("div", { className: "pk-setting-row" }, /* @__PURE__ */ React2.createElement("div", { className: "pk-segmented pk-small", role: "group", "aria-label": labels.along }, /* @__PURE__ */ React2.createElement("span", { className: "pk-muted" }, labels.along), ["rows", "cols"].map((axis) => /* @__PURE__ */ React2.createElement("button", { key: axis, type: "button", "aria-pressed": spec.showAs.axis === axis, onClick: () => set({ showAs: { ...spec.showAs, axis } }) }, labels.zones[axis]))), /* @__PURE__ */ React2.createElement(SettingInfo, { id: "along", name: labels.along })) : null) : null, numeric ? /* @__PURE__ */ React2.createElement(Section, { title: labels.format, id: "format", state: spec.format ? labels.formats[spec.format] ?? labels.formats[spec.format.split(":")[0]] ?? spec.format : labels.formatAuto, changed: Boolean(spec.format) && spec.format !== (spec.field ? defaultsOf?.(spec.field)?.format : void 0) }, /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React2.createElement(Option, { checked: !spec.format, onSelect: () => set({ format: null }) }, labels.formatAuto), FORMAT_CHOICES.map(formatOption)), /* @__PURE__ */ React2.createElement(More, { title: labels.moreFormats, open: MORE_FORMATS.includes(spec.format ?? "") }, /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, MORE_FORMATS.map(formatOption)))) : null, numeric ? /* @__PURE__ */ React2.createElement(Section, { title: labels.conditional, id: "highlight", state: spec.conditional ? spec.conditional.type === "dataBar" ? labels.dataBar : labels.colorScale : labels.conditionalNone, changed: Boolean(spec.conditional) }, /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React2.createElement(Option, { checked: !spec.conditional, onSelect: () => set({ conditional: null }) }, labels.conditionalNone), /* @__PURE__ */ React2.createElement(Option, { checked: spec.conditional?.type === "colorScale", onSelect: () => set({ conditional: { type: "colorScale" } }), testId: "cond-colorScale" }, labels.colorScale), /* @__PURE__ */ React2.createElement(Option, { checked: spec.conditional?.type === "dataBar", onSelect: () => set({ conditional: { type: "dataBar", color: null } }), testId: "cond-dataBar" }, labels.dataBar))) : null, /* @__PURE__ */ React2.createElement(Section, { title: labels.rename }, /* @__PURE__ */ React2.createElement("form", { className: "pk-inline-form", onSubmit: (e) => {
|
|
571
|
+
e.preventDefault();
|
|
572
|
+
set({ label: rename.trim() || null });
|
|
573
|
+
} }, /* @__PURE__ */ React2.createElement(
|
|
574
|
+
ClearInput,
|
|
575
|
+
{
|
|
576
|
+
type: "text",
|
|
577
|
+
value: rename,
|
|
578
|
+
placeholder: valueLabel({ ...spec, label: null }, labels),
|
|
579
|
+
onChange: setRename,
|
|
580
|
+
onClear: () => spec.label ? commit(updateValue(view, index, { label: null }), { step: "value", field: name }) : void 0,
|
|
581
|
+
clearLabel: labels.defaultName,
|
|
582
|
+
"aria-label": labels.rename,
|
|
583
|
+
maxLength: 200,
|
|
584
|
+
"data-testid": "value-name"
|
|
585
|
+
}
|
|
586
|
+
), /* @__PURE__ */ React2.createElement("button", { type: "submit", className: "pk-btn pk-primary" }, labels.apply))), /* @__PURE__ */ React2.createElement(MoveSection, { view, zone: "values", index, count: view.values.length, labels, commit, close, text: name, type })), /* @__PURE__ */ React2.createElement(RemoveFoot, { labels, onRemove, close }));
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
// src/toolbar-panels.jsx
|
|
590
|
+
import React3, { useEffect as useEffect2, useId as useId3, useRef as useRef2, useState as useState2 } from "react";
|
|
591
|
+
import { VIEW_FILE_LIMITS } from "pivotkit-core";
|
|
592
|
+
|
|
593
|
+
// src/sections.js
|
|
594
|
+
var withoutSections = (dismissed) => dismissed.filter((id) => !isSection(id));
|
|
595
|
+
|
|
596
|
+
// src/share-actions.js
|
|
597
|
+
import { toViewFile, viewFileName, viewFileText } from "pivotkit-core";
|
|
598
|
+
|
|
599
|
+
// src/files.js
|
|
600
|
+
var UNSAFE = /[<>:"/\\|?*\u0000-\u001F\u007F]+/g;
|
|
601
|
+
var RESERVED = /^(con|prn|aux|nul|com\d|lpt\d)$/i;
|
|
602
|
+
function safeFileName(name) {
|
|
603
|
+
const text = typeof name === "string" ? name : "";
|
|
604
|
+
const cleaned = trimEnd(text.replace(UNSAFE, "-").replace(/^[\s.-]+/, "").slice(0, 120));
|
|
605
|
+
return cleaned && !RESERVED.test(cleaned) ? cleaned : "pivot";
|
|
606
|
+
}
|
|
607
|
+
function trimEnd(text) {
|
|
608
|
+
let end = text.length;
|
|
609
|
+
while (end > 0 && (text[end - 1] === "." || /\s/.test(text[end - 1]))) {
|
|
610
|
+
end--;
|
|
611
|
+
}
|
|
612
|
+
return text.slice(0, end);
|
|
613
|
+
}
|
|
614
|
+
function dataUrlToBlob(url) {
|
|
615
|
+
const match = /^data:([^,;]*)((?:;[^,;]*)*?)(;base64)?,(.*)$/s.exec(url);
|
|
616
|
+
if (!match) {
|
|
617
|
+
throw new TypeError("not a data: URL");
|
|
618
|
+
}
|
|
619
|
+
const type = match[1] || "application/octet-stream";
|
|
620
|
+
if (match[3]) {
|
|
621
|
+
const bin = atob(match[4]);
|
|
622
|
+
const bytes = new Uint8Array(bin.length);
|
|
623
|
+
for (let i = 0; i < bin.length; i++) {
|
|
624
|
+
bytes[i] = bin.charCodeAt(i);
|
|
625
|
+
}
|
|
626
|
+
return new Blob([bytes], { type });
|
|
627
|
+
}
|
|
628
|
+
return new Blob([decodeURIComponent(match[4])], { type });
|
|
629
|
+
}
|
|
630
|
+
function saveBlob(blob, name, doc = document) {
|
|
631
|
+
const url = URL.createObjectURL(blob);
|
|
632
|
+
const a = doc.createElement("a");
|
|
633
|
+
a.href = url;
|
|
634
|
+
a.download = name;
|
|
635
|
+
a.rel = "noopener";
|
|
636
|
+
doc.body.appendChild(a);
|
|
637
|
+
a.click();
|
|
638
|
+
a.remove();
|
|
639
|
+
setTimeout(() => URL.revokeObjectURL(url), 1e4);
|
|
640
|
+
}
|
|
641
|
+
async function copyText(text, container) {
|
|
642
|
+
try {
|
|
643
|
+
if (typeof navigator !== "undefined" && navigator.clipboard && typeof navigator.clipboard.writeText === "function") {
|
|
644
|
+
await navigator.clipboard.writeText(text);
|
|
645
|
+
return true;
|
|
646
|
+
}
|
|
647
|
+
} catch {
|
|
648
|
+
}
|
|
649
|
+
if (!container) {
|
|
650
|
+
return false;
|
|
651
|
+
}
|
|
652
|
+
const doc = container.ownerDocument;
|
|
653
|
+
const field = doc.createElement("textarea");
|
|
654
|
+
field.value = text;
|
|
655
|
+
field.readOnly = true;
|
|
656
|
+
field.className = "pk-sr";
|
|
657
|
+
const before = (
|
|
658
|
+
/** @type {HTMLElement | null} */
|
|
659
|
+
container.getRootNode() instanceof ShadowRoot ? (
|
|
660
|
+
/** @type {ShadowRoot} */
|
|
661
|
+
container.getRootNode().activeElement
|
|
662
|
+
) : doc.activeElement
|
|
663
|
+
);
|
|
664
|
+
container.appendChild(field);
|
|
665
|
+
let ok;
|
|
666
|
+
try {
|
|
667
|
+
field.select();
|
|
668
|
+
ok = typeof doc.execCommand === "function" && doc.execCommand("copy");
|
|
669
|
+
} catch {
|
|
670
|
+
ok = false;
|
|
671
|
+
}
|
|
672
|
+
field.remove();
|
|
673
|
+
before?.focus?.({ preventScroll: true });
|
|
674
|
+
return ok;
|
|
675
|
+
}
|
|
676
|
+
|
|
677
|
+
// src/version.js
|
|
678
|
+
var VERSION = true ? "0.2.0" : "0.0.0-source";
|
|
679
|
+
|
|
680
|
+
// src/share-actions.js
|
|
681
|
+
var here = () => typeof location !== "undefined" ? location.href : void 0;
|
|
682
|
+
function shareActions(ctx, labels) {
|
|
683
|
+
const { view, viewName, sourceId, sourceName, schemaUrl, encoded, announce, limits, param } = ctx;
|
|
684
|
+
const viewFile = () => viewFileText(toViewFile(view, { name: viewName ?? "", createdAt: /* @__PURE__ */ new Date(), generator: { name: "pivotkit-react", version: VERSION }, source: { id: sourceId, name: sourceName }, data: encoded, ...schemaUrl !== void 0 ? { schemaUrl } : {} }));
|
|
685
|
+
return {
|
|
686
|
+
copyLink: async () => {
|
|
687
|
+
const target = shareBase(ctx.shareLink, here());
|
|
688
|
+
if (target === null) {
|
|
689
|
+
return;
|
|
690
|
+
}
|
|
691
|
+
let text;
|
|
692
|
+
try {
|
|
693
|
+
text = (linkNow() ?? await loadLink()).encodeViewLink(toViewFile(view, { name: viewName ?? void 0, source: { id: sourceId } }, { link: true }));
|
|
694
|
+
} catch (e) {
|
|
695
|
+
announce(e && /** @type {any} */
|
|
696
|
+
e.code === "LIMIT_EXCEEDED" ? labels.toastLinkTooLong : fill(labels.error, { message: String(e) }), { tone: "error" });
|
|
697
|
+
return;
|
|
698
|
+
}
|
|
699
|
+
const ok = await copyText(withLinkParam(target, param, text), ctx.root.current);
|
|
700
|
+
announce(ok ? labels.toastLinkCopied : labels.toastCopyFailed, ok ? void 0 : { tone: "error" });
|
|
701
|
+
},
|
|
702
|
+
copyJson: async () => {
|
|
703
|
+
const ok = await copyText(viewFile(), ctx.root.current);
|
|
704
|
+
announce(ok ? labels.toastJsonCopied : labels.toastCopyFailed, ok ? void 0 : { tone: "error" });
|
|
705
|
+
},
|
|
706
|
+
download: () => {
|
|
707
|
+
const file = viewFileName(viewName || sourceName || safeFileName(ctx.fileName));
|
|
708
|
+
const blob = new Blob([viewFile()], { type: "application/json" });
|
|
709
|
+
if (ctx.onExport?.({ kind: "json", fileName: file, blob }) === false) {
|
|
710
|
+
return;
|
|
711
|
+
}
|
|
712
|
+
saveBlob(blob, file, ctx.root.current?.ownerDocument ?? document);
|
|
713
|
+
announce(fill(labels.toastExported, { file }));
|
|
714
|
+
},
|
|
715
|
+
/**
|
|
716
|
+
* @param {string} text
|
|
717
|
+
* @returns {Promise<string | null | { lines: string[], load: () => void, switchTo?: { name: string, run: () => void } }>}
|
|
718
|
+
* why nothing was loaded, null when it was, or what to ask first (a view for other data)
|
|
719
|
+
*/
|
|
720
|
+
loadText: async (text) => {
|
|
721
|
+
let loaded = viewFromText(text, encoded, { limits, sourceId });
|
|
722
|
+
if (loaded.failed === "notJson") {
|
|
723
|
+
const t = text.trim();
|
|
724
|
+
const fromUrl = t.includes("#") ? readLinkParam(t.slice(t.indexOf("#")), param) ?? readLinkParam(t.slice(t.indexOf("#")), "pivot") : null;
|
|
725
|
+
const payload = fromUrl ?? (t.startsWith("1.") ? t : null);
|
|
726
|
+
if (!payload) {
|
|
727
|
+
return labels.viewFailed.notJson;
|
|
728
|
+
}
|
|
729
|
+
try {
|
|
730
|
+
const decoded = (linkNow() ?? await loadLink()).decodeViewLink(payload);
|
|
731
|
+
loaded = decoded.view ? viewFromObject(decoded.view, encoded, { limits, sourceId }) : { view: null, issues: [], failed: "badLink", file: null };
|
|
732
|
+
} catch {
|
|
733
|
+
return labels.viewFailed.badLink;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
if (!loaded.view) {
|
|
737
|
+
return labels.viewFailed[loaded.failed ?? "notView"] ?? labels.viewFailed.notView;
|
|
738
|
+
}
|
|
739
|
+
const ready = (
|
|
740
|
+
/** @type {import("./share.js").LoadedView} */
|
|
741
|
+
loaded
|
|
742
|
+
);
|
|
743
|
+
const check = loadCheck(ready, labels, Array.isArray(ctx.sources) ? ctx.sources : []);
|
|
744
|
+
if (!check) {
|
|
745
|
+
ctx.applyLoaded(ready);
|
|
746
|
+
return null;
|
|
747
|
+
}
|
|
748
|
+
const target = check.switchTo;
|
|
749
|
+
const switchTo = ctx.onSourceSwitch;
|
|
750
|
+
return {
|
|
751
|
+
lines: check.lines,
|
|
752
|
+
load: () => ctx.applyLoaded(ready),
|
|
753
|
+
switchTo: target && typeof switchTo === "function" ? { name: target.name, run: () => switchTo({ source: { id: target.id, name: target.name }, view: (
|
|
754
|
+
/** @type {Record<string, unknown>} */
|
|
755
|
+
ready.file?.view ?? ready.view
|
|
756
|
+
), name: ready.file?.name || void 0 }) } : void 0
|
|
757
|
+
};
|
|
758
|
+
}
|
|
759
|
+
};
|
|
760
|
+
}
|
|
761
|
+
|
|
762
|
+
// src/view-save.js
|
|
763
|
+
var canSaveAs = (can) => can.host || can.store;
|
|
764
|
+
var isLoadedEntry = (t, loaded) => !!loaded && t.name === loaded.name && (t.scope === "user" ? "user" : "shared") === loaded.scope && t.at !== void 0 === loaded.store && (!loaded.store || (t.sourceId ?? null) === (loaded.storeSource ?? null));
|
|
765
|
+
var storeEntry = (entries, name, source) => entries.find((t) => t.at !== void 0 && t.name === name && (t.sourceId ?? null) === (source ?? null));
|
|
766
|
+
function saveTarget(loaded, entries, can, empty = false) {
|
|
767
|
+
if (!loaded) {
|
|
768
|
+
return null;
|
|
769
|
+
}
|
|
770
|
+
let target;
|
|
771
|
+
if (loaded.scope === "shared") {
|
|
772
|
+
target = can.publish ? { kind: "publish" } : canSaveAs(can) ? { kind: null, why: "saveSharedLocked" } : null;
|
|
773
|
+
} else if (loaded.scope === "user" && loaded.store) {
|
|
774
|
+
const entry = storeEntry(entries, loaded.name, loaded.storeSource);
|
|
775
|
+
target = can.store ? entry ? { kind: "store", at: entry.at, storeSource: loaded.storeSource ?? null } : { kind: "store", storeSource: can.sourceId ?? null } : null;
|
|
776
|
+
} else if (loaded.scope === "user") {
|
|
777
|
+
target = can.host ? { kind: "host" } : null;
|
|
778
|
+
} else {
|
|
779
|
+
target = canSaveAs(can) ? { kind: null, why: "saveNotInViews" } : null;
|
|
780
|
+
}
|
|
781
|
+
return target && target.kind && empty ? { kind: null, why: "exportNeedsField" } : target;
|
|
782
|
+
}
|
|
783
|
+
function saveAsTarget(name, entries, can) {
|
|
784
|
+
if (can.host) {
|
|
785
|
+
return { kind: "host", replaces: entries.find((t) => t.scope === "user" && t.at === void 0 && t.name === name) ?? null };
|
|
786
|
+
}
|
|
787
|
+
const old = (
|
|
788
|
+
/** @type {T | undefined} */
|
|
789
|
+
storeEntry(entries, name, can.sourceId) ?? storeEntry(entries, name, null)
|
|
790
|
+
);
|
|
791
|
+
return old ? { kind: "store", at: old.at, storeSource: old.sourceId ?? null, replaces: old } : { kind: "store", storeSource: can.sourceId ?? null, replaces: null };
|
|
792
|
+
}
|
|
793
|
+
|
|
794
|
+
// src/view-store.js
|
|
795
|
+
import { toViewFile as toViewFile2 } from "pivotkit-core";
|
|
796
|
+
import { parseTemplates } from "pivotkit-core/templates";
|
|
797
|
+
var VIEW_STORE_LIMITS = Object.freeze({ count: 100, text: 5e5 });
|
|
798
|
+
var warnedLarge = false;
|
|
799
|
+
function readAll(raw) {
|
|
800
|
+
if (!raw) {
|
|
801
|
+
return [];
|
|
802
|
+
}
|
|
803
|
+
if (raw.length > VIEW_STORE_LIMITS.text) {
|
|
804
|
+
if (!warnedLarge) {
|
|
805
|
+
warnedLarge = true;
|
|
806
|
+
console.warn(`pivotkit: the browser store of views holds more than ${VIEW_STORE_LIMITS.text} characters; it is not read, and the next save replaces it`);
|
|
807
|
+
}
|
|
808
|
+
return [];
|
|
809
|
+
}
|
|
810
|
+
return parseTemplates(raw).templates;
|
|
811
|
+
}
|
|
812
|
+
function storedViews(raw, sourceId) {
|
|
813
|
+
return readAll(raw).map((t, at) => ({ name: t.name, view: t.view, at, ...t.source?.id ? { sourceId: t.source.id } : {} })).filter((t) => !t.sourceId || !sourceId || t.sourceId === sourceId);
|
|
814
|
+
}
|
|
815
|
+
function changedViews(raw, change, message) {
|
|
816
|
+
const all = readAll(raw);
|
|
817
|
+
let next = all;
|
|
818
|
+
if (change.remove !== void 0) {
|
|
819
|
+
if (all[change.remove]?.name !== change.removeName) {
|
|
820
|
+
throw new Error(message("changed", 0));
|
|
821
|
+
}
|
|
822
|
+
next = all.filter((t, i) => i !== change.remove);
|
|
823
|
+
}
|
|
824
|
+
const saving = Boolean(change.name && change.view);
|
|
825
|
+
if (saving && change.replace !== void 0) {
|
|
826
|
+
const old = all[change.replace];
|
|
827
|
+
if (old?.name !== change.name) {
|
|
828
|
+
throw new Error(message("changed", 0));
|
|
829
|
+
}
|
|
830
|
+
next = all.map((t, i) => i === change.replace ? { name: old.name, view: (
|
|
831
|
+
/** @type {Record<string, unknown>} */
|
|
832
|
+
change.view
|
|
833
|
+
), ...old.source ? { source: old.source } : {} } : t);
|
|
834
|
+
} else if (saving) {
|
|
835
|
+
const id = change.sourceId;
|
|
836
|
+
next = next.filter((t) => t.name !== change.name || (t.source?.id ?? void 0) !== id);
|
|
837
|
+
next.push({ name: (
|
|
838
|
+
/** @type {string} */
|
|
839
|
+
change.name
|
|
840
|
+
), view: (
|
|
841
|
+
/** @type {Record<string, unknown>} */
|
|
842
|
+
change.view
|
|
843
|
+
), ...id ? { source: { id } } : {} });
|
|
844
|
+
if (next.length > VIEW_STORE_LIMITS.count) {
|
|
845
|
+
throw new Error(message("count", VIEW_STORE_LIMITS.count));
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
const text = next.length ? JSON.stringify(next.map((t) => toViewFile2(t.view, { name: t.name, source: t.source }, { link: true }))) : null;
|
|
849
|
+
if (saving && text && text.length > VIEW_STORE_LIMITS.text) {
|
|
850
|
+
throw new Error(message("text", VIEW_STORE_LIMITS.text));
|
|
851
|
+
}
|
|
852
|
+
return text;
|
|
853
|
+
}
|
|
854
|
+
function storeViews(raw, change, labels, locale, keep) {
|
|
855
|
+
const texts = { count: labels.storeFull, text: labels.storeTooLarge, changed: labels.storeChanged };
|
|
856
|
+
const text = changedViews(raw, change, (kind, max) => fill(texts[kind], { max: max.toLocaleString(locale) }));
|
|
857
|
+
if (!keep(text)) {
|
|
858
|
+
throw new Error(labels.storeRefused);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
861
|
+
|
|
862
|
+
// src/toolbar-panels.jsx
|
|
863
|
+
function ChartTypeOptions({ view, plan, labels, onChart, close }) {
|
|
864
|
+
const current = chartTypeOf(view.chart);
|
|
865
|
+
return CHART_TYPE_NAMES.map((p) => /* @__PURE__ */ React3.createElement(
|
|
866
|
+
Option,
|
|
867
|
+
{
|
|
868
|
+
key: p,
|
|
869
|
+
icon: CHART_TYPES[p].icon,
|
|
870
|
+
checked: view.display === "chart" && current === p,
|
|
871
|
+
hint: p === "auto" && plan ? fill(labels.chartAutoNow, { type: labels.chartTypes[plan.name] }) : void 0,
|
|
872
|
+
onSelect: () => {
|
|
873
|
+
close();
|
|
874
|
+
onChart(p);
|
|
875
|
+
},
|
|
876
|
+
testId: `chart-${p}`
|
|
877
|
+
},
|
|
878
|
+
labels.chartTypes[p]
|
|
879
|
+
));
|
|
880
|
+
}
|
|
881
|
+
var VALUE_LABELS = { slices: ["auto", "off", "value", "percent", "both"], other: ["auto", "off", "value"] };
|
|
882
|
+
var LABEL_POSITIONS = ["outside", "inside"];
|
|
883
|
+
var LEGENDS = ["auto", "bottom", "right", "off"];
|
|
884
|
+
var AXIS_LABELS = ["auto", "all", "nth"];
|
|
885
|
+
var GROUP_LABELS = ["auto", "on", "off"];
|
|
886
|
+
function ChartTitle({ title, labels, onDisplay }) {
|
|
887
|
+
const [text, setText] = useState2(title ?? "");
|
|
888
|
+
const [last, setLast] = useState2(title);
|
|
889
|
+
if (title !== last) {
|
|
890
|
+
setLast(title);
|
|
891
|
+
setText(title ?? "");
|
|
892
|
+
}
|
|
893
|
+
return /* @__PURE__ */ React3.createElement(
|
|
894
|
+
"form",
|
|
895
|
+
{
|
|
896
|
+
className: "pk-inline-form",
|
|
897
|
+
onSubmit: (e) => {
|
|
898
|
+
e.preventDefault();
|
|
899
|
+
onDisplay({ title: text.trim() || null });
|
|
900
|
+
}
|
|
901
|
+
},
|
|
902
|
+
/* @__PURE__ */ React3.createElement(
|
|
903
|
+
ClearInput,
|
|
904
|
+
{
|
|
905
|
+
type: "text",
|
|
906
|
+
value: text,
|
|
907
|
+
onChange: setText,
|
|
908
|
+
onClear: () => title ? onDisplay({ title: null }) : void 0,
|
|
909
|
+
clearLabel: labels.clearText,
|
|
910
|
+
placeholder: labels.chartTitleNone,
|
|
911
|
+
"aria-label": labels.chartTitle,
|
|
912
|
+
maxLength: 200,
|
|
913
|
+
"data-testid": "chart-title"
|
|
914
|
+
}
|
|
915
|
+
),
|
|
916
|
+
/* @__PURE__ */ React3.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: (text.trim() || null) === (title ?? null) }, labels.apply)
|
|
917
|
+
);
|
|
918
|
+
}
|
|
919
|
+
function ChartDisplay({ view, plan, labels, onDisplay }) {
|
|
920
|
+
const chart = view.chart;
|
|
921
|
+
const drawn = plan ? plan.name : chartTypeOf(chart);
|
|
922
|
+
const pie = SLICE_TYPES.includes(drawn);
|
|
923
|
+
const axis = CHART_TYPES[drawn].axis;
|
|
924
|
+
const choices = pie ? VALUE_LABELS.slices : VALUE_LABELS.other;
|
|
925
|
+
const valueLabels = !pie && (chart.valueLabels === "percent" || chart.valueLabels === "both") ? "value" : chart.valueLabels;
|
|
926
|
+
const changed = [
|
|
927
|
+
[valueLabels !== "auto", labels.valueLabels],
|
|
928
|
+
[pie && (chart.labelPosition ?? "outside") !== "outside", labels.labelPosition],
|
|
929
|
+
[chart.legend !== "auto", labels.legend],
|
|
930
|
+
[Boolean(chart.title), labels.chartTitle],
|
|
931
|
+
[axis && chart.axisLabels !== "auto", labels.axisLabels],
|
|
932
|
+
[axis && view.rows.length >= 2 && chart.groupLabels !== "auto", labels.groupLabels],
|
|
933
|
+
[(drawn === "line" || drawn === "area") && chart.smooth, labels.smoothLines]
|
|
934
|
+
].flatMap(([on, name]) => on ? [name] : []);
|
|
935
|
+
return /* @__PURE__ */ React3.createElement(Section, { title: labels.chartDisplay, id: "chartDisplay", state: changed.join(", ") || labels.formatAuto, changed: changed.length > 0 }, /* @__PURE__ */ React3.createElement("div", { className: "pk-subtitle" }, labels.valueLabels), /* @__PURE__ */ React3.createElement("div", { className: "pk-choice-grid" }, choices.map((v) => /* @__PURE__ */ React3.createElement(Option, { key: v, checked: valueLabels === v, onSelect: () => onDisplay({ valueLabels: v }), testId: `labels-${v}` }, labels.valueLabelNames[v]))), pie ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { className: "pk-subtitle pk-setting-row" }, /* @__PURE__ */ React3.createElement("span", null, labels.labelPosition), /* @__PURE__ */ React3.createElement(SettingInfo, { id: "labelPosition", name: labels.labelPosition })), /* @__PURE__ */ React3.createElement("div", { className: "pk-choice-grid" }, LABEL_POSITIONS.map((v) => /* @__PURE__ */ React3.createElement(Option, { key: v, checked: (chart.labelPosition ?? "outside") === v, disabled: chart.valueLabels === "off", onSelect: () => onDisplay({ labelPosition: v }), testId: `label-position-${v}` }, labels.labelPositionNames[v])))) : null, /* @__PURE__ */ React3.createElement("div", { className: "pk-subtitle" }, labels.legend), /* @__PURE__ */ React3.createElement("div", { className: "pk-choice-grid" }, LEGENDS.map((v) => /* @__PURE__ */ React3.createElement(Option, { key: v, checked: chart.legend === v, onSelect: () => onDisplay({ legend: v }), testId: `legend-${v}` }, labels.legendNames[v]))), /* @__PURE__ */ React3.createElement("div", { className: "pk-subtitle" }, labels.chartTitle), /* @__PURE__ */ React3.createElement(ChartTitle, { title: chart.title, labels, onDisplay }), axis ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { className: "pk-subtitle" }, labels.axisLabels), /* @__PURE__ */ React3.createElement("div", { className: "pk-choice-grid" }, AXIS_LABELS.map((v) => /* @__PURE__ */ React3.createElement(Option, { key: v, checked: chart.axisLabels === v, onSelect: () => onDisplay({ axisLabels: v }), testId: `axis-${v}` }, labels.axisLabelNames[v])))) : null, axis && view.rows.length >= 2 ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { className: "pk-subtitle pk-setting-row" }, /* @__PURE__ */ React3.createElement("span", null, labels.groupLabels), /* @__PURE__ */ React3.createElement(SettingInfo, { id: "groupLabels", name: labels.groupLabels })), /* @__PURE__ */ React3.createElement("div", { className: "pk-choice-grid" }, GROUP_LABELS.map((v) => /* @__PURE__ */ React3.createElement(Option, { key: v, checked: chart.groupLabels === v, onSelect: () => onDisplay({ groupLabels: v }), testId: `groups-${v}` }, labels.groupLabelNames[v])))) : null, drawn === "line" || drawn === "area" ? /* @__PURE__ */ React3.createElement(Switch, { checked: chart.smooth, onChange: (on) => onDisplay({ smooth: on }), testId: "chart-smooth" }, labels.smoothLines) : null);
|
|
936
|
+
}
|
|
937
|
+
function ChartTypePanel({ view, plan, labels, onChart, onDisplay, close }) {
|
|
938
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(Section, { title: labels.chartType, id: "chartType" }, /* @__PURE__ */ React3.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React3.createElement(ChartTypeOptions, { view, plan, labels, onChart, close }))), /* @__PURE__ */ React3.createElement(ChartDisplay, { view, plan, labels, onDisplay }));
|
|
939
|
+
}
|
|
940
|
+
function Shortcuts({ labels, mod }) {
|
|
941
|
+
const key = (k) => k === "Mod" ? mod === "\u2318" ? "\u2318" : labels.keys.Mod : Object.hasOwn(labels.keys, k) ? labels.keys[k] : k;
|
|
942
|
+
return /* @__PURE__ */ React3.createElement("dl", { className: "pk-shortcuts", "data-testid": "shortcuts" }, SHORTCUTS.map((s) => /* @__PURE__ */ React3.createElement("div", { key: s.text, className: "pk-shortcut" }, /* @__PURE__ */ React3.createElement("dt", null, s.keys.map((k, i) => /* @__PURE__ */ React3.createElement(React3.Fragment, { key: k }, i ? " + " : null, /* @__PURE__ */ React3.createElement("kbd", null, key(k))))), /* @__PURE__ */ React3.createElement("dd", null, labels.shortcuts[s.text]))));
|
|
943
|
+
}
|
|
944
|
+
function Switch({ checked, onChange, testId, children, disabled, reason, info, name }) {
|
|
945
|
+
const reasonId = useId3();
|
|
946
|
+
return /* @__PURE__ */ React3.createElement("div", { className: "pk-setting-row" }, /* @__PURE__ */ React3.createElement("label", { className: `pk-switch${disabled ? " pk-disabled" : ""}` }, /* @__PURE__ */ React3.createElement("input", { type: "checkbox", checked, disabled, onChange: (e) => onChange(e.target.checked), "aria-describedby": disabled && reason ? reasonId : void 0, "data-testid": testId }), /* @__PURE__ */ React3.createElement("span", { className: "pk-switch-track", "aria-hidden": "true" }), /* @__PURE__ */ React3.createElement("span", { className: "pk-switch-text" }, children, disabled && reason ? /* @__PURE__ */ React3.createElement("span", { id: reasonId, className: "pk-option-hint", "data-testid": testId ? `${testId}-reason` : void 0 }, reason) : null)), info ? /* @__PURE__ */ React3.createElement(SettingInfo, { id: info, name: name ?? "" }) : null);
|
|
947
|
+
}
|
|
948
|
+
function ResetSections({ list, change, labels }) {
|
|
949
|
+
const rest = withoutSections(list);
|
|
950
|
+
const [done, setDone] = useState2(false);
|
|
951
|
+
const status = useRef2(
|
|
952
|
+
/** @type {HTMLSpanElement | null} */
|
|
953
|
+
null
|
|
954
|
+
);
|
|
955
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
|
|
956
|
+
Option,
|
|
957
|
+
{
|
|
958
|
+
icon: "reset",
|
|
959
|
+
onSelect: () => {
|
|
960
|
+
const title = (
|
|
961
|
+
/** @type {HTMLElement | null | undefined} */
|
|
962
|
+
status.current?.closest(".pk-section")?.querySelector(".pk-section-toggle")
|
|
963
|
+
);
|
|
964
|
+
change(rest, null);
|
|
965
|
+
title?.focus();
|
|
966
|
+
setDone(true);
|
|
967
|
+
},
|
|
968
|
+
disabled: rest.length === list.length,
|
|
969
|
+
testId: "reset-sections"
|
|
970
|
+
},
|
|
971
|
+
labels.resetSections
|
|
972
|
+
), /* @__PURE__ */ React3.createElement("span", { ref: status, className: "pk-sr", role: "status", "data-testid": "reset-sections-status" }, done ? labels.resetSectionsDone : ""));
|
|
973
|
+
}
|
|
974
|
+
function OptionsPanel({ view, labels, onTotal, onExpand, onCollapse, close, tips, mod, folding, help }) {
|
|
975
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(Section, { title: labels.totals, id: "totals" }, TOTALS.map((key) => {
|
|
976
|
+
const why = totalNoEffect(view, key);
|
|
977
|
+
return /* @__PURE__ */ React3.createElement(Switch, { key, checked: view.totals[key], onChange: (on) => onTotal(key, on), disabled: why !== null, reason: why ? labels[why] : null, info: key, name: labels[key], testId: `total-${key}` }, labels[key]);
|
|
978
|
+
})), /* @__PURE__ */ React3.createElement(Section, { title: labels.zones.rows }, /* @__PURE__ */ React3.createElement(Option, { icon: "chevronDown", onSelect: () => {
|
|
979
|
+
close();
|
|
980
|
+
onExpand(labels);
|
|
981
|
+
}, disabled: !folding.canExpand, reason: folding.why.expand ? labels[folding.why.expand] : void 0, testId: "expand-all" }, labels.expandAll), /* @__PURE__ */ React3.createElement(Option, { icon: "chevronRight", onSelect: () => {
|
|
982
|
+
close();
|
|
983
|
+
onCollapse(labels);
|
|
984
|
+
}, disabled: !folding.canCollapse, reason: folding.why.collapse ? labels[folding.why.collapse] : void 0, testId: "collapse-all" }, labels.collapseAll)), /* @__PURE__ */ React3.createElement(Section, { title: labels.help, id: "help" }, tips.controls ? /* @__PURE__ */ React3.createElement(Switch, { checked: tips.on, onChange: tips.onOn, testId: "show-tips" }, labels.showTips) : null, help?.explanations ? /* @__PURE__ */ React3.createElement(Switch, { checked: help.explanations.on, onChange: help.explanations.set, testId: "show-explanations" }, labels.showSettingInfo) : null, tips.controls ? /* @__PURE__ */ React3.createElement(Option, { icon: "reset", onSelect: () => tips.onReset(), disabled: !tips.canReset, testId: "reset-tips" }, labels.resetTips) : null, help?.sections ? /* @__PURE__ */ React3.createElement(ResetSections, { list: help.sections[0], change: help.sections[1], labels }) : null, /* @__PURE__ */ React3.createElement("details", { className: "pk-more" }, /* @__PURE__ */ React3.createElement("summary", { className: "pk-more-title", "data-testid": "shortcuts-title" }, labels.shortcutsTitle), /* @__PURE__ */ React3.createElement(Shortcuts, { labels, mod }))));
|
|
985
|
+
}
|
|
986
|
+
function Confirm({ question, action, cancel, onYes, onNo, testId, yesId, noId }) {
|
|
987
|
+
const no = useRef2(
|
|
988
|
+
/** @type {HTMLButtonElement | null} */
|
|
989
|
+
null
|
|
990
|
+
);
|
|
991
|
+
useEffect2(() => {
|
|
992
|
+
no.current?.focus({ preventScroll: true });
|
|
993
|
+
}, []);
|
|
994
|
+
return /* @__PURE__ */ React3.createElement("div", { className: "pk-confirm pk-save-confirm", role: "group", "aria-label": question, "data-testid": testId }, /* @__PURE__ */ React3.createElement("span", { className: "pk-confirm-text" }, question), /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-btn pk-primary", "data-testid": yesId, onClick: onYes }, action), /* @__PURE__ */ React3.createElement("button", { ref: no, type: "button", className: "pk-btn", "data-autofocus": "", "data-testid": noId, onClick: onNo }, cancel));
|
|
995
|
+
}
|
|
996
|
+
function SaveView({ labels, button, onSave, resolve, close }) {
|
|
997
|
+
const [name, setName] = useState2("");
|
|
998
|
+
const [asking, setAsking] = useState2(
|
|
999
|
+
/** @type {any} */
|
|
1000
|
+
null
|
|
1001
|
+
);
|
|
1002
|
+
const field = useRef2(
|
|
1003
|
+
/** @type {HTMLInputElement | null} */
|
|
1004
|
+
null
|
|
1005
|
+
);
|
|
1006
|
+
const asked = useRef2(false);
|
|
1007
|
+
useEffect2(() => {
|
|
1008
|
+
if (asking) {
|
|
1009
|
+
asked.current = true;
|
|
1010
|
+
} else if (asked.current) {
|
|
1011
|
+
field.current?.focus({ preventScroll: true });
|
|
1012
|
+
}
|
|
1013
|
+
}, [asking]);
|
|
1014
|
+
if (asking) {
|
|
1015
|
+
return /* @__PURE__ */ React3.createElement(
|
|
1016
|
+
Confirm,
|
|
1017
|
+
{
|
|
1018
|
+
question: fill(labels.replaceConfirm, { name: asking.name }),
|
|
1019
|
+
action: labels.replaceAction,
|
|
1020
|
+
cancel: labels.cancel,
|
|
1021
|
+
testId: "replace-confirm",
|
|
1022
|
+
yesId: "confirm-replace",
|
|
1023
|
+
noId: "cancel-replace",
|
|
1024
|
+
onYes: () => {
|
|
1025
|
+
close();
|
|
1026
|
+
onSave(asking.name, asking.target);
|
|
1027
|
+
},
|
|
1028
|
+
onNo: () => setAsking(null)
|
|
1029
|
+
}
|
|
1030
|
+
);
|
|
1031
|
+
}
|
|
1032
|
+
return /* @__PURE__ */ React3.createElement(
|
|
1033
|
+
"form",
|
|
1034
|
+
{
|
|
1035
|
+
className: "pk-inline-form",
|
|
1036
|
+
onSubmit: (e) => {
|
|
1037
|
+
e.preventDefault();
|
|
1038
|
+
const wanted = name.trim();
|
|
1039
|
+
const target = wanted ? resolve(wanted) : null;
|
|
1040
|
+
if (target?.replaces) {
|
|
1041
|
+
setAsking({ name: wanted, target });
|
|
1042
|
+
} else if (target) {
|
|
1043
|
+
close();
|
|
1044
|
+
onSave(wanted, target);
|
|
1045
|
+
}
|
|
1046
|
+
}
|
|
1047
|
+
},
|
|
1048
|
+
/* @__PURE__ */ React3.createElement(ClearInput, { type: "text", value: name, onChange: setName, clearLabel: labels.clearText, placeholder: labels.viewName, "aria-label": labels.viewName, maxLength: 120, "data-testid": "saved-view-name", inputRef: field }),
|
|
1049
|
+
/* @__PURE__ */ React3.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: !name.trim() }, button)
|
|
1050
|
+
);
|
|
1051
|
+
}
|
|
1052
|
+
function LoadCheck({ check, labels, onCancel, close, title, quiet = false }) {
|
|
1053
|
+
const titleId = useId3();
|
|
1054
|
+
const first = useRef2(
|
|
1055
|
+
/** @type {HTMLButtonElement | null} */
|
|
1056
|
+
null
|
|
1057
|
+
);
|
|
1058
|
+
useEffect2(() => {
|
|
1059
|
+
if (!quiet) {
|
|
1060
|
+
first.current?.focus({ preventScroll: true });
|
|
1061
|
+
}
|
|
1062
|
+
}, [quiet]);
|
|
1063
|
+
return /* @__PURE__ */ React3.createElement("div", { className: "pk-load-check", role: "group", "aria-labelledby": titleId, "data-testid": "load-check" }, /* @__PURE__ */ React3.createElement("p", { id: titleId, className: "pk-load-check-title" }, /* @__PURE__ */ React3.createElement(Icon, { name: "info", size: 16 }), /* @__PURE__ */ React3.createElement("span", null, title ?? labels.loadCheckTitle)), /* @__PURE__ */ React3.createElement("ul", { className: "pk-load-check-lines" }, check.lines.map((line, i) => /* @__PURE__ */ React3.createElement("li", { key: i }, line))), /* @__PURE__ */ React3.createElement("div", { className: "pk-load-check-actions" }, check.switchTo ? /* @__PURE__ */ React3.createElement("button", { ref: first, type: "button", className: "pk-btn pk-primary", "data-autofocus": "", "data-testid": "load-switch", onClick: () => {
|
|
1064
|
+
close();
|
|
1065
|
+
check.switchTo?.run();
|
|
1066
|
+
} }, fill(labels.switchAndLoad, { source: check.switchTo.name })) : null, /* @__PURE__ */ React3.createElement("button", { ref: check.switchTo ? void 0 : first, type: "button", className: check.switchTo ? "pk-btn" : "pk-btn pk-primary", "data-autofocus": check.switchTo ? void 0 : "", "data-testid": "load-anyway", onClick: () => {
|
|
1067
|
+
close();
|
|
1068
|
+
check.load();
|
|
1069
|
+
} }, labels.loadAnyway), /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-btn", "data-testid": "load-cancel", onClick: onCancel }, labels.cancel)), check.switchTo ? /* @__PURE__ */ React3.createElement("p", { className: "pk-hint" }, labels.switchStartsFresh) : null);
|
|
1070
|
+
}
|
|
1071
|
+
function LoadView({ labels, onLoadText, close }) {
|
|
1072
|
+
const [text, setText] = useState2("");
|
|
1073
|
+
const [problem, setProblem] = useState2(
|
|
1074
|
+
/** @type {string | null} */
|
|
1075
|
+
null
|
|
1076
|
+
);
|
|
1077
|
+
const [check, setCheck] = useState2(
|
|
1078
|
+
/** @type {any} */
|
|
1079
|
+
null
|
|
1080
|
+
);
|
|
1081
|
+
const [busy, setBusy] = useState2(false);
|
|
1082
|
+
const file = useRef2(
|
|
1083
|
+
/** @type {HTMLInputElement | null} */
|
|
1084
|
+
null
|
|
1085
|
+
);
|
|
1086
|
+
const field = useRef2(
|
|
1087
|
+
/** @type {HTMLTextAreaElement | null} */
|
|
1088
|
+
null
|
|
1089
|
+
);
|
|
1090
|
+
const problemId = useId3();
|
|
1091
|
+
useEffect2(() => {
|
|
1092
|
+
if (!check) {
|
|
1093
|
+
field.current?.focus({ preventScroll: true });
|
|
1094
|
+
}
|
|
1095
|
+
}, [check]);
|
|
1096
|
+
const load = async (value) => {
|
|
1097
|
+
setBusy(true);
|
|
1098
|
+
const outcome = await onLoadText(value);
|
|
1099
|
+
setBusy(false);
|
|
1100
|
+
if (typeof outcome === "string") {
|
|
1101
|
+
setProblem(outcome);
|
|
1102
|
+
} else if (outcome) {
|
|
1103
|
+
setCheck(outcome);
|
|
1104
|
+
} else {
|
|
1105
|
+
close();
|
|
1106
|
+
}
|
|
1107
|
+
};
|
|
1108
|
+
if (check) {
|
|
1109
|
+
return /* @__PURE__ */ React3.createElement(LoadCheck, { check, labels, onCancel: () => setCheck(null), close });
|
|
1110
|
+
}
|
|
1111
|
+
return /* @__PURE__ */ React3.createElement(
|
|
1112
|
+
"form",
|
|
1113
|
+
{
|
|
1114
|
+
className: "pk-inline-form pk-load-view",
|
|
1115
|
+
onSubmit: (e) => {
|
|
1116
|
+
e.preventDefault();
|
|
1117
|
+
load(text);
|
|
1118
|
+
}
|
|
1119
|
+
},
|
|
1120
|
+
/* @__PURE__ */ React3.createElement("p", { className: "pk-hint" }, labels.loadViewHint),
|
|
1121
|
+
/* @__PURE__ */ React3.createElement(
|
|
1122
|
+
ClearInput,
|
|
1123
|
+
{
|
|
1124
|
+
multiline: true,
|
|
1125
|
+
value: text,
|
|
1126
|
+
onChange: (v) => {
|
|
1127
|
+
setText(v);
|
|
1128
|
+
setProblem(null);
|
|
1129
|
+
},
|
|
1130
|
+
clearLabel: labels.clearText,
|
|
1131
|
+
"aria-label": labels.loadViewText,
|
|
1132
|
+
placeholder: labels.loadViewText,
|
|
1133
|
+
rows: 4,
|
|
1134
|
+
spellCheck: false,
|
|
1135
|
+
"aria-invalid": problem ? true : void 0,
|
|
1136
|
+
"aria-describedby": problem ? problemId : void 0,
|
|
1137
|
+
"data-testid": "load-view-text",
|
|
1138
|
+
inputRef: field
|
|
1139
|
+
}
|
|
1140
|
+
),
|
|
1141
|
+
problem ? /* @__PURE__ */ React3.createElement("p", { id: problemId, className: "pk-form-problem", role: "alert", "data-testid": "load-view-problem" }, problem) : null,
|
|
1142
|
+
/* @__PURE__ */ React3.createElement(
|
|
1143
|
+
"input",
|
|
1144
|
+
{
|
|
1145
|
+
ref: file,
|
|
1146
|
+
type: "file",
|
|
1147
|
+
accept: "application/json,.json",
|
|
1148
|
+
className: "pk-sr",
|
|
1149
|
+
tabIndex: -1,
|
|
1150
|
+
"aria-hidden": "true",
|
|
1151
|
+
"data-testid": "load-view-file",
|
|
1152
|
+
onChange: async (e) => {
|
|
1153
|
+
const chosen = e.target.files?.[0];
|
|
1154
|
+
e.target.value = "";
|
|
1155
|
+
if (chosen) {
|
|
1156
|
+
let content;
|
|
1157
|
+
try {
|
|
1158
|
+
content = chosen.size > VIEW_FILE_LIMITS.text ? null : await chosen.text();
|
|
1159
|
+
} catch {
|
|
1160
|
+
content = null;
|
|
1161
|
+
}
|
|
1162
|
+
if (content === null) {
|
|
1163
|
+
setProblem(chosen.size > VIEW_FILE_LIMITS.text ? labels.viewFailed.tooLarge : labels.viewFailed.file);
|
|
1164
|
+
} else {
|
|
1165
|
+
load(content);
|
|
1166
|
+
}
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
}
|
|
1170
|
+
),
|
|
1171
|
+
/* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-btn", onClick: () => file.current?.click(), disabled: busy, "data-testid": "load-view-choose" }, /* @__PURE__ */ React3.createElement(Icon, { name: "file" }), /* @__PURE__ */ React3.createElement("span", { className: "pk-btn-text" }, labels.chooseFile)),
|
|
1172
|
+
/* @__PURE__ */ React3.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: busy || !text.trim(), "data-testid": "load-view-apply" }, labels.load)
|
|
1173
|
+
);
|
|
1174
|
+
}
|
|
1175
|
+
function ShareSection({ labels, share, close }) {
|
|
1176
|
+
const [loading, setLoading] = useState2(false);
|
|
1177
|
+
const act = shareActions(share, labels);
|
|
1178
|
+
if (loading) {
|
|
1179
|
+
return /* @__PURE__ */ React3.createElement(Section, { title: labels.loadView.replace(/…$/, "") }, /* @__PURE__ */ React3.createElement(LoadView, { labels, onLoadText: act.loadText, close }));
|
|
1180
|
+
}
|
|
1181
|
+
return /* @__PURE__ */ React3.createElement(Section, { title: labels.share, id: "share" }, share.canLink ? /* @__PURE__ */ React3.createElement(Option, { icon: "link", onSelect: () => {
|
|
1182
|
+
close();
|
|
1183
|
+
act.copyLink();
|
|
1184
|
+
}, testId: "copy-link" }, labels.copyLink) : null, /* @__PURE__ */ React3.createElement(Option, { icon: "copy", onSelect: () => {
|
|
1185
|
+
close();
|
|
1186
|
+
act.copyJson();
|
|
1187
|
+
}, testId: "copy-json" }, labels.copyJson), /* @__PURE__ */ React3.createElement(Option, { icon: "download", onSelect: () => {
|
|
1188
|
+
close();
|
|
1189
|
+
act.download();
|
|
1190
|
+
}, testId: "download-view" }, labels.downloadView), /* @__PURE__ */ React3.createElement(Option, { icon: "upload", onSelect: () => setLoading(true), testId: "load-view" }, labels.loadView), /* @__PURE__ */ React3.createElement("p", { className: "pk-hint pk-menu-hint", "data-testid": "share-privacy" }, labels.sharePrivacy));
|
|
1191
|
+
}
|
|
1192
|
+
function viewActions(ctx, labels) {
|
|
1193
|
+
const run = (task, done, failed, rejected, name) => Promise.resolve().then(task).then(
|
|
1194
|
+
() => {
|
|
1195
|
+
ctx.announce(fill(done, { name }));
|
|
1196
|
+
return true;
|
|
1197
|
+
},
|
|
1198
|
+
(e) => {
|
|
1199
|
+
ctx.announce(hostFailure(failed, rejected, e), { tone: "error" });
|
|
1200
|
+
return false;
|
|
1201
|
+
}
|
|
1202
|
+
);
|
|
1203
|
+
const write = (change) => storeViews(ctx.viewsText, change, labels, ctx.locale, ctx.keep);
|
|
1204
|
+
const save = (target, name) => {
|
|
1205
|
+
const key = ctx.viewKey;
|
|
1206
|
+
return run(
|
|
1207
|
+
() => target.kind === "publish" ? ctx.onPublish(name, ctx.view) : target.kind === "host" ? ctx.onSave(name, ctx.view, { scope: "user" }) : write({ name, view: ctx.view, sourceId: ctx.sourceId, replace: target.at }),
|
|
1208
|
+
labels.toastSaved,
|
|
1209
|
+
labels.toastSaveFailed,
|
|
1210
|
+
labels.toastSaveRejected,
|
|
1211
|
+
name
|
|
1212
|
+
).then((ok) => ok && ctx.onSaved({ name, scope: target.kind === "publish" ? "shared" : "user", store: target.kind === "store", storeSource: target.kind === "store" ? target.storeSource : null }, key));
|
|
1213
|
+
};
|
|
1214
|
+
return {
|
|
1215
|
+
// Save and Save as: where to is view-save.js's (the host's onSaveTemplate wins over the store)
|
|
1216
|
+
save,
|
|
1217
|
+
remove: ctx.onDelete || ctx.store ? (t) => run(() => t.at !== void 0 ? write({ remove: t.at, removeName: t.name }) : ctx.onDelete(t.name, { scope: t.scope }), labels.toastDeleted, labels.toastDeleteFailed, labels.toastDeleteRejected, t.name) : null,
|
|
1218
|
+
publish: ctx.onPublish ? (t) => run(() => ctx.onPublish(t.name, ctx.normalized(t.view)), labels.toastPublished, labels.toastPublishFailed, labels.toastPublishRejected, t.name) : null
|
|
1219
|
+
};
|
|
1220
|
+
}
|
|
1221
|
+
function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
1222
|
+
const { save, remove: onDelete, publish: onPublish } = viewActions(actions, labels);
|
|
1223
|
+
const can = { host: Boolean(actions.onSave), store: Boolean(actions.store), publish: Boolean(onPublish), sourceId: actions.sourceId };
|
|
1224
|
+
const target = saveTarget(actions.loaded, templates, can, actions.empty);
|
|
1225
|
+
const [askShared, setAskShared] = useState2(false);
|
|
1226
|
+
const store = actions.store && !actions.onSave;
|
|
1227
|
+
const [confirming, setConfirming] = useState2(
|
|
1228
|
+
/** @type {{ at: number, kind: "delete" | "publish" } | null} */
|
|
1229
|
+
null
|
|
1230
|
+
);
|
|
1231
|
+
const [busy, setBusy] = useState2(false);
|
|
1232
|
+
const box = useRef2(
|
|
1233
|
+
/** @type {HTMLDivElement | null} */
|
|
1234
|
+
null
|
|
1235
|
+
);
|
|
1236
|
+
const [refocus, setRefocus] = useState2(
|
|
1237
|
+
/** @type {{ key: string, place: number } | null} */
|
|
1238
|
+
null
|
|
1239
|
+
);
|
|
1240
|
+
useEffect2(() => {
|
|
1241
|
+
share?.prepare?.();
|
|
1242
|
+
}, [share]);
|
|
1243
|
+
useEffect2(() => {
|
|
1244
|
+
if (refocus && box.current) {
|
|
1245
|
+
const entries = [...box.current.querySelectorAll("[data-pk-entry]")];
|
|
1246
|
+
const entry2 = entries.find((el) => el.getAttribute("data-pk-entry") === refocus.key) ?? entries[Math.min(refocus.place, entries.length - 1)];
|
|
1247
|
+
(entry2 ?? box.current).querySelector("[data-pk-option]")?.focus({ preventScroll: true });
|
|
1248
|
+
setRefocus(null);
|
|
1249
|
+
}
|
|
1250
|
+
}, [refocus, templates]);
|
|
1251
|
+
const keyOf2 = (t) => `${t.scope}:${t.at ?? ""}:${t.name}`;
|
|
1252
|
+
useEffect2(() => {
|
|
1253
|
+
if (confirming) {
|
|
1254
|
+
box.current?.querySelector(".pk-confirm [data-autofocus]")?.focus({ preventScroll: true });
|
|
1255
|
+
}
|
|
1256
|
+
}, [confirming]);
|
|
1257
|
+
const answer = (t) => {
|
|
1258
|
+
setConfirming(null);
|
|
1259
|
+
const entries = box.current ? [...box.current.querySelectorAll("[data-pk-entry], .pk-confirm")] : [];
|
|
1260
|
+
setRefocus({ key: keyOf2(t), place: Math.max(0, entries.findIndex((el) => el.classList.contains("pk-confirm"))) });
|
|
1261
|
+
};
|
|
1262
|
+
const entry = (t, at) => {
|
|
1263
|
+
if (confirming && confirming.at === at) {
|
|
1264
|
+
const kind = confirming.kind;
|
|
1265
|
+
const publish = kind === "publish";
|
|
1266
|
+
const question = fill(publish ? labels.publishConfirm : labels.deleteConfirm, { name: t.name });
|
|
1267
|
+
return /* @__PURE__ */ React3.createElement("div", { key: `${at}:${t.name}`, className: "pk-template pk-confirm", role: "group", "aria-label": question }, /* @__PURE__ */ React3.createElement("span", { className: "pk-confirm-text" }, question), /* @__PURE__ */ React3.createElement(
|
|
1268
|
+
"button",
|
|
1269
|
+
{
|
|
1270
|
+
type: "button",
|
|
1271
|
+
className: publish ? "pk-btn pk-primary" : "pk-btn pk-danger-btn",
|
|
1272
|
+
disabled: busy,
|
|
1273
|
+
"data-autofocus": "",
|
|
1274
|
+
"data-testid": `confirm-${kind}`,
|
|
1275
|
+
onClick: async () => {
|
|
1276
|
+
setBusy(true);
|
|
1277
|
+
const ok = await (publish ? onPublish : onDelete)?.(t);
|
|
1278
|
+
setBusy(false);
|
|
1279
|
+
if (ok) {
|
|
1280
|
+
answer(t);
|
|
1281
|
+
}
|
|
1282
|
+
}
|
|
1283
|
+
},
|
|
1284
|
+
publish ? labels.publishAction : labels.deleteAction
|
|
1285
|
+
), /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-btn", disabled: busy, onClick: () => answer(t) }, labels.cancel));
|
|
1286
|
+
}
|
|
1287
|
+
const button = (kind, icon, text) => /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-icon-btn", onClick: () => setConfirming({ at, kind }), "aria-label": text, title: text, "data-testid": `${kind}-view-${t.name}` }, /* @__PURE__ */ React3.createElement(Icon, { name: icon }));
|
|
1288
|
+
return /* @__PURE__ */ React3.createElement("div", { key: `${at}:${t.name}`, className: "pk-template", "data-pk-entry": keyOf2(t) }, /* @__PURE__ */ React3.createElement(Option, { icon: "bookmark", current: isLoadedEntry(t, actions.loaded), onSelect: () => {
|
|
1289
|
+
close();
|
|
1290
|
+
onLoad(t);
|
|
1291
|
+
}, testId: `saved-view-${t.name}` }, t.name), onPublish && t.scope === "user" ? button("publish", "upload", fill(labels.publishView, { name: t.name })) : null, onDelete && t.deletable ? button("delete", "trash", fill(labels.deleteView, { name: t.name })) : t.scope === "shared" && sharedChange ? /* @__PURE__ */ React3.createElement(SettingInfo, { id: "sharedView", name: t.name }) : null);
|
|
1292
|
+
};
|
|
1293
|
+
const sharedChange = Boolean(onPublish) || templates.some((t) => t.scope === "shared" && t.deletable);
|
|
1294
|
+
const group = (scope) => templates.map((t, at) => t.scope === scope ? entry(t, at) : null).filter(Boolean);
|
|
1295
|
+
const shared = group("shared");
|
|
1296
|
+
const mine = group("user");
|
|
1297
|
+
return /* @__PURE__ */ React3.createElement("div", { ref: box, className: "pk-views" }, /* @__PURE__ */ React3.createElement(Section, { title: labels.thisView, id: "thisView" }, target && askShared && target.kind === "publish" ? /* @__PURE__ */ React3.createElement(
|
|
1298
|
+
Confirm,
|
|
1299
|
+
{
|
|
1300
|
+
question: fill(labels.replaceSharedConfirm, { name: actions.loaded.name }),
|
|
1301
|
+
action: labels.replaceAction,
|
|
1302
|
+
cancel: labels.cancel,
|
|
1303
|
+
testId: "replace-shared-confirm",
|
|
1304
|
+
yesId: "confirm-replace-shared",
|
|
1305
|
+
noId: "cancel-replace-shared",
|
|
1306
|
+
onYes: () => {
|
|
1307
|
+
close();
|
|
1308
|
+
save(target, actions.loaded.name);
|
|
1309
|
+
},
|
|
1310
|
+
onNo: () => setAskShared(false)
|
|
1311
|
+
}
|
|
1312
|
+
) : target ? /* @__PURE__ */ React3.createElement(Option, { icon: "save", onSelect: () => {
|
|
1313
|
+
if (target.kind === "publish") {
|
|
1314
|
+
setAskShared(true);
|
|
1315
|
+
} else {
|
|
1316
|
+
close();
|
|
1317
|
+
save(target, actions.loaded.name);
|
|
1318
|
+
}
|
|
1319
|
+
}, disabled: target.kind === null, reason: target.kind === null ? labels[target.why] : void 0, testId: "save-loaded" }, fill(labels.saveNamed, { name: actions.loaded.name })) : null, canSaveAs(can) ? /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement("div", { className: "pk-subtitle" }, actions.loaded ? labels.saveAs : labels.saveView), /* @__PURE__ */ React3.createElement(SaveView, { labels, button: actions.loaded ? labels.saveAs.replace(/…$/, "") : labels.save, onSave: (name, t) => save(t, name), resolve: (name) => saveAsTarget(name, templates, can), close })) : null, /* @__PURE__ */ React3.createElement("div", { className: "pk-setting-row" }, /* @__PURE__ */ React3.createElement(Option, { icon: "newFile", onSelect: () => {
|
|
1320
|
+
close();
|
|
1321
|
+
actions.onNew();
|
|
1322
|
+
}, disabled: !actions.canNew, reason: actions.canNew ? void 0 : labels.newAlready, testId: "new-report" }, labels.newEmpty), /* @__PURE__ */ React3.createElement(SettingInfo, { id: "newReport", name: labels.newEmpty }))), shared.length ? /* @__PURE__ */ React3.createElement(Section, { title: labels.sharedViews, id: "sharedViews" }, shared) : null, mine.length || canSaveAs(can) || !shared.length ? /* @__PURE__ */ React3.createElement(Section, { title: labels.myViews, id: "myViews" }, mine.length ? mine : /* @__PURE__ */ React3.createElement("p", { className: "pk-hint", "data-testid": store ? "store-note" : void 0 }, store ? labels.noViewsStore : labels.noViews), store && mine.length ? /* @__PURE__ */ React3.createElement("p", { className: "pk-hint pk-menu-hint", "data-testid": "store-note" }, labels.storeNote) : null) : null, share ? /* @__PURE__ */ React3.createElement(ShareSection, { labels, share, close }) : null);
|
|
1323
|
+
}
|
|
1324
|
+
function ExportOption({ icon, text, info, onSelect, testId, disabled, reason }) {
|
|
1325
|
+
const option = /* @__PURE__ */ React3.createElement(Option, { icon, onSelect, disabled, reason, testId }, text);
|
|
1326
|
+
return info ? /* @__PURE__ */ React3.createElement("div", { className: "pk-setting-row" }, option, /* @__PURE__ */ React3.createElement(SettingInfo, { id: (
|
|
1327
|
+
/** @type {any} */
|
|
1328
|
+
info
|
|
1329
|
+
), name: text })) : option;
|
|
1330
|
+
}
|
|
1331
|
+
function ExportPanel({ labels, onExport, chartReady, display, empty = false, prepare, close }) {
|
|
1332
|
+
useEffect2(() => {
|
|
1333
|
+
prepare();
|
|
1334
|
+
}, [prepare]);
|
|
1335
|
+
const run = (kind) => () => {
|
|
1336
|
+
close();
|
|
1337
|
+
onExport(kind);
|
|
1338
|
+
};
|
|
1339
|
+
const off = empty ? { disabled: true, reason: labels.exportNeedsField } : {};
|
|
1340
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(Section, { title: labels.exportDownload, id: "exportDownload" }, /* @__PURE__ */ React3.createElement(ExportOption, { icon: "file", text: labels.exportXlsx, info: "exportXlsx", onSelect: run("xlsx"), ...off, testId: "export-xlsx" }), /* @__PURE__ */ React3.createElement(ExportOption, { icon: "file", text: labels.exportCsv, info: "exportCsv", onSelect: run("csv"), ...off, testId: "export-csv" }), /* @__PURE__ */ React3.createElement(ExportOption, { icon: "image", text: labels.exportPng, disabled: empty || !chartReady, reason: empty ? off.reason : display !== "chart" ? labels.exportPngNeedsChart : void 0, onSelect: run("png"), testId: "export-png" })), /* @__PURE__ */ React3.createElement(Section, { title: labels.exportCopy, id: "exportCopy" }, /* @__PURE__ */ React3.createElement(ExportOption, { icon: "copy", text: labels.copyTable, info: "copyTable", onSelect: run("copy-table"), ...off, testId: "export-copy-table" }), /* @__PURE__ */ React3.createElement(ExportOption, { icon: "copy", text: labels.copyDataJson, info: "copyDataJson", onSelect: run("copy-json"), ...off, testId: "export-copy-json" })));
|
|
1341
|
+
}
|
|
1342
|
+
|
|
1343
|
+
// src/filter.jsx
|
|
1344
|
+
import React4, { useMemo, useState as useState3 } from "react";
|
|
1345
|
+
import { CATALOG as CATALOG2, fieldItems, fieldLabel as fieldLabel2 } from "pivotkit-core";
|
|
1346
|
+
var FILTER_LIST_MAX = 300;
|
|
1347
|
+
var keyOf = (v) => JSON.stringify(v);
|
|
1348
|
+
function FilterBody({ view: current, base, field, encoded, locale, labels, commit, close }) {
|
|
1349
|
+
const view = base ?? current;
|
|
1350
|
+
const info = useMemo(() => fieldItems(encoded, field, { view, locale, labels: labels.core }), [encoded, field, view, locale, labels]);
|
|
1351
|
+
const all = useMemo(() => info ? info.items.map((i) => i.value) : [], [info]);
|
|
1352
|
+
const [selected, setSelected] = useState3(() => new Set(selectedItems(view, field, all).map(keyOf)));
|
|
1353
|
+
const [query, setQuery] = useState3("");
|
|
1354
|
+
const label = filtersOf(view, field, ["label"])[0];
|
|
1355
|
+
const [op, setOp] = useState3(label?.op ?? "");
|
|
1356
|
+
const [text, setText] = useState3(label?.value ?? "");
|
|
1357
|
+
if (!info) {
|
|
1358
|
+
return null;
|
|
1359
|
+
}
|
|
1360
|
+
const q = query.trim().toLocaleLowerCase();
|
|
1361
|
+
const matching = q ? info.items.filter((i) => i.label.toLocaleLowerCase().includes(q)) : info.items;
|
|
1362
|
+
const shown = matching.slice(0, FILTER_LIST_MAX);
|
|
1363
|
+
const setAll = (on) => {
|
|
1364
|
+
const next = new Set(selected);
|
|
1365
|
+
for (const i of matching) {
|
|
1366
|
+
if (on) {
|
|
1367
|
+
next.add(keyOf(i.value));
|
|
1368
|
+
} else {
|
|
1369
|
+
next.delete(keyOf(i.value));
|
|
1370
|
+
}
|
|
1371
|
+
}
|
|
1372
|
+
setSelected(next);
|
|
1373
|
+
};
|
|
1374
|
+
const toggle = (v) => {
|
|
1375
|
+
const next = new Set(selected);
|
|
1376
|
+
const k = keyOf(v);
|
|
1377
|
+
if (next.has(k)) {
|
|
1378
|
+
next.delete(k);
|
|
1379
|
+
} else {
|
|
1380
|
+
next.add(k);
|
|
1381
|
+
}
|
|
1382
|
+
setSelected(next);
|
|
1383
|
+
};
|
|
1384
|
+
const name = fieldLabel2(field, labels.core);
|
|
1385
|
+
const apply = () => {
|
|
1386
|
+
let next = setItemFilter(view, field, all.filter((v) => selected.has(keyOf(v))), all);
|
|
1387
|
+
next = setLabelFilter(next, field, op ? { op, value: text } : null);
|
|
1388
|
+
close();
|
|
1389
|
+
commit(next, { step: "filter", field: name });
|
|
1390
|
+
};
|
|
1391
|
+
const filtering = !base && hasFilter(view, field);
|
|
1392
|
+
const kind = conditionKind(encoded, view, field) ?? (label ? "text" : null);
|
|
1393
|
+
return /* @__PURE__ */ React4.createElement(
|
|
1394
|
+
"form",
|
|
1395
|
+
{
|
|
1396
|
+
className: "pk-filter",
|
|
1397
|
+
onSubmit: (e) => {
|
|
1398
|
+
e.preventDefault();
|
|
1399
|
+
apply();
|
|
1400
|
+
}
|
|
1401
|
+
},
|
|
1402
|
+
/* @__PURE__ */ React4.createElement("div", { className: "pk-popover-head" }, /* @__PURE__ */ React4.createElement("h3", null, fill(labels.filterTitle, { field: name })), /* @__PURE__ */ React4.createElement("span", { className: "pk-muted" }, fill(labels.selected, { count: selected.size.toLocaleString(locale) }))),
|
|
1403
|
+
filtering ? /* @__PURE__ */ React4.createElement(
|
|
1404
|
+
"button",
|
|
1405
|
+
{
|
|
1406
|
+
type: "button",
|
|
1407
|
+
className: "pk-btn pk-remove-filter",
|
|
1408
|
+
onClick: () => {
|
|
1409
|
+
close();
|
|
1410
|
+
commit(removeFilters(view, field), { step: "filter", field: name });
|
|
1411
|
+
},
|
|
1412
|
+
"data-testid": "filter-remove"
|
|
1413
|
+
},
|
|
1414
|
+
/* @__PURE__ */ React4.createElement(Icon, { name: "x" }),
|
|
1415
|
+
/* @__PURE__ */ React4.createElement("span", { className: "pk-btn-text" }, labels.removeFilter)
|
|
1416
|
+
) : null,
|
|
1417
|
+
/* @__PURE__ */ React4.createElement("label", { className: "pk-search" }, /* @__PURE__ */ React4.createElement(Icon, { name: "search" }), /* @__PURE__ */ React4.createElement("span", { className: "pk-sr" }, labels.searchValues), /* @__PURE__ */ React4.createElement(ClearInput, { type: "search", value: query, placeholder: labels.searchValues, onChange: setQuery, clearLabel: labels.clearText, "data-autofocus": "", "data-testid": "filter-search" })),
|
|
1418
|
+
/* @__PURE__ */ React4.createElement("div", { className: "pk-filter-actions" }, /* @__PURE__ */ React4.createElement("button", { type: "button", className: "pk-link", onClick: () => setAll(true) }, labels.selectAll), /* @__PURE__ */ React4.createElement("button", { type: "button", className: "pk-link", onClick: () => setAll(false) }, labels.selectNone)),
|
|
1419
|
+
/* @__PURE__ */ React4.createElement("div", { className: "pk-filter-body" }, /* @__PURE__ */ React4.createElement("ul", { className: "pk-values", role: "list" }, shown.map((i) => {
|
|
1420
|
+
const k = keyOf(i.value);
|
|
1421
|
+
return /* @__PURE__ */ React4.createElement("li", { key: k, className: "pk-value" }, /* @__PURE__ */ React4.createElement("label", null, /* @__PURE__ */ React4.createElement("input", { type: "checkbox", checked: selected.has(k), onChange: () => toggle(i.value) }), /* @__PURE__ */ React4.createElement("span", { className: "pk-value-label" }, i.label), /* @__PURE__ */ React4.createElement("span", { className: "pk-count" }, i.count.toLocaleString(locale))), /* @__PURE__ */ React4.createElement("button", { type: "button", className: "pk-link pk-only", onClick: () => setSelected(/* @__PURE__ */ new Set([k])), "aria-label": `${labels.onlyThis}: ${i.label}` }, labels.onlyThis));
|
|
1422
|
+
})), matching.length > shown.length ? /* @__PURE__ */ React4.createElement("p", { className: "pk-hint" }, fill(labels.valuesShown, { shown: shown.length, total: matching.length.toLocaleString(locale) })) : null, kind ? /* @__PURE__ */ React4.createElement("fieldset", { className: "pk-condition" }, /* @__PURE__ */ React4.createElement("legend", null, kind === "number" ? labels.conditionNumber : labels.condition), /* @__PURE__ */ React4.createElement("select", { value: op, onChange: (e) => setOp(e.target.value), "aria-label": kind === "number" ? labels.conditionNumber : labels.condition }, /* @__PURE__ */ React4.createElement("option", { value: "" }, labels.conditionNone), CATALOG2.labelOps.map((o) => /* @__PURE__ */ React4.createElement("option", { key: o, value: o }, labels.labelOps[o] ?? o))), op ? /* @__PURE__ */ React4.createElement(
|
|
1423
|
+
ClearInput,
|
|
1424
|
+
{
|
|
1425
|
+
type: "text",
|
|
1426
|
+
value: text,
|
|
1427
|
+
onChange: setText,
|
|
1428
|
+
onClear: () => {
|
|
1429
|
+
if (!base && filtersOf(view, field, ["label"]).length) {
|
|
1430
|
+
commit(setLabelFilter(view, field, null), { step: "filter", field: name });
|
|
1431
|
+
}
|
|
1432
|
+
},
|
|
1433
|
+
clearLabel: labels.clearText,
|
|
1434
|
+
"aria-label": labels.conditionValue,
|
|
1435
|
+
placeholder: labels.conditionValue,
|
|
1436
|
+
maxLength: 1e3,
|
|
1437
|
+
"data-testid": "filter-condition-text"
|
|
1438
|
+
}
|
|
1439
|
+
) : null) : null),
|
|
1440
|
+
/* @__PURE__ */ React4.createElement("div", { className: "pk-popover-foot" }, /* @__PURE__ */ React4.createElement("button", { type: "button", className: "pk-btn", onClick: close }, labels.cancel), /* @__PURE__ */ React4.createElement("button", { type: "submit", className: "pk-btn pk-primary", "data-testid": "filter-apply" }, labels.apply))
|
|
1441
|
+
);
|
|
1442
|
+
}
|
|
1443
|
+
function FilterPopover({ target, onClose, view, encoded, locale, labels, commit }) {
|
|
1444
|
+
const anchor = useMemo(() => ({ current: target ? target.anchor : null }), [target]);
|
|
1445
|
+
return /* @__PURE__ */ React4.createElement(Popover, { open: Boolean(target), anchor, onClose, label: target ? fill(labels.filterTitle, { field: fieldLabel2(target.field, labels.core) }) : "", className: "pk-filter-popover", fill: true }, target ? /* @__PURE__ */ React4.createElement(FilterBody, { key: target.field, view, base: target.base, field: target.field, encoded, locale, labels, commit, close: onClose }) : null);
|
|
1446
|
+
}
|
|
1447
|
+
|
|
1448
|
+
// src/drill-panel.jsx
|
|
1449
|
+
import React5, { useContext as useContext3, useEffect as useEffect3, useId as useId4, useMemo as useMemo2, useRef as useRef3, useState as useState4 } from "react";
|
|
1450
|
+
|
|
1451
|
+
// src/export-run.js
|
|
1452
|
+
import { toGrid } from "pivotkit-core";
|
|
1453
|
+
var XLSX_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
1454
|
+
var exporters = null;
|
|
1455
|
+
var pending = null;
|
|
1456
|
+
function loadExporters() {
|
|
1457
|
+
pending ??= import("pivotkit-core/export").then(
|
|
1458
|
+
(m) => {
|
|
1459
|
+
exporters = m;
|
|
1460
|
+
return m;
|
|
1461
|
+
},
|
|
1462
|
+
(error) => {
|
|
1463
|
+
pending = null;
|
|
1464
|
+
throw error;
|
|
1465
|
+
}
|
|
1466
|
+
);
|
|
1467
|
+
return pending;
|
|
1468
|
+
}
|
|
1469
|
+
var exportersNow = () => exporters;
|
|
1470
|
+
var prepareExporters = () => void loadExporters().catch(() => void 0);
|
|
1471
|
+
function deliver(blob, { doc, onExport, ...file }) {
|
|
1472
|
+
if (onExport?.({ ...file, blob }) === false) {
|
|
1473
|
+
return false;
|
|
1474
|
+
}
|
|
1475
|
+
saveBlob(blob, file.fileName, doc);
|
|
1476
|
+
return true;
|
|
1477
|
+
}
|
|
1478
|
+
async function copyOut(text, { type, container, onExport, ...file }) {
|
|
1479
|
+
if (onExport?.({ ...file, blob: new Blob([text], { type }), text }) === false) {
|
|
1480
|
+
return "kept";
|
|
1481
|
+
}
|
|
1482
|
+
return await copyText(text, container) ? "copied" : "blocked";
|
|
1483
|
+
}
|
|
1484
|
+
async function runExport(kind, { fileName, result, locale, labels, limits, root, chartRef, announce, onExport }) {
|
|
1485
|
+
labels = menuLabels(labels);
|
|
1486
|
+
const base = safeFileName(fileName);
|
|
1487
|
+
const doc = root.current?.ownerDocument;
|
|
1488
|
+
try {
|
|
1489
|
+
if (kind === "png") {
|
|
1490
|
+
const surface = root.current ? getComputedStyle(root.current).getPropertyValue("--pk-surface").trim() : "";
|
|
1491
|
+
const url = chartRef.current?.getDataURL({ type: "png", pixelRatio: 2, backgroundColor: surface || void 0 });
|
|
1492
|
+
const file2 = `${base}.png`;
|
|
1493
|
+
if (url && deliver(dataUrlToBlob(url), { kind, fileName: file2, doc, onExport })) {
|
|
1494
|
+
announce(fill(labels.toastExported, { file: file2 }));
|
|
1495
|
+
}
|
|
1496
|
+
return;
|
|
1497
|
+
}
|
|
1498
|
+
if (!result) {
|
|
1499
|
+
return;
|
|
1500
|
+
}
|
|
1501
|
+
const m = exporters ?? await loadExporters();
|
|
1502
|
+
const grid = toGrid(result, { locale, labels: labels.core, limits });
|
|
1503
|
+
if (kind === "copy-table" || kind === "copy-json") {
|
|
1504
|
+
const json = kind === "copy-json";
|
|
1505
|
+
const done = await copyOut(json ? m.toJson(grid) : m.toTsv(grid), { kind, fileName: `${base}.${json ? "json" : "tsv"}`, type: json ? "application/json" : "text/tab-separated-values", container: root.current, onExport });
|
|
1506
|
+
if (done !== "kept") {
|
|
1507
|
+
announce(done === "copied" ? json ? labels.toastDataCopied : labels.toastTableCopied : labels.toastCopyBlocked, done === "copied" ? void 0 : { tone: "error" });
|
|
1508
|
+
}
|
|
1509
|
+
return;
|
|
1510
|
+
}
|
|
1511
|
+
const file = `${base}.${kind}`;
|
|
1512
|
+
const bytes = kind === "xlsx" ? m.toXlsx(grid, { sheetName: base }) : m.toCsvBytes(grid, { bom: true });
|
|
1513
|
+
if (deliver(new Blob([
|
|
1514
|
+
/** @type {BlobPart} */
|
|
1515
|
+
bytes
|
|
1516
|
+
], { type: kind === "xlsx" ? XLSX_TYPE : "text/csv;charset=utf-8" }), { kind, fileName: file, doc, onExport })) {
|
|
1517
|
+
announce(fill(labels.toastExported, { file }));
|
|
1518
|
+
}
|
|
1519
|
+
} catch (e) {
|
|
1520
|
+
announce(fill(labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
|
|
1521
|
+
}
|
|
1522
|
+
}
|
|
1523
|
+
|
|
1524
|
+
// src/drill-export.js
|
|
1525
|
+
function rowsText({ shown, count }, labels, locale) {
|
|
1526
|
+
return shown < count ? fill(labels.drillPart, { shown: shown.toLocaleString(locale), count: count.toLocaleString(locale) }) : plural(labels.drillCount, count, { lang: labels.lang, locale });
|
|
1527
|
+
}
|
|
1528
|
+
async function exportDrill(kind, { drill, encoded, labels, onExport, announce, root }) {
|
|
1529
|
+
const { locale } = drill;
|
|
1530
|
+
const part = { shown: drill.rows.length, count: drill.count };
|
|
1531
|
+
const rows = rowsText(part, labels, locale);
|
|
1532
|
+
const base = safeFileName(drill.name);
|
|
1533
|
+
try {
|
|
1534
|
+
const m = exportersNow() ?? await loadExporters();
|
|
1535
|
+
if (kind === "drill-copy" || kind === "drill-json") {
|
|
1536
|
+
const json = kind === "drill-json";
|
|
1537
|
+
const text = json ? JSON.stringify(Array.from(drill.indices, (i) => decodeRow(encoded, i)), null, 2) : m.toTsv([drill.columns.map((c) => c.label ?? c.name), ...drill.rows]);
|
|
1538
|
+
const done = await copyOut(text, { kind, fileName: `${base}.${json ? "json" : "tsv"}`, type: json ? "application/json" : "text/tab-separated-values", container: root, onExport, rows: part });
|
|
1539
|
+
if (done !== "kept") {
|
|
1540
|
+
announce(done === "copied" ? fill(json ? labels.drillCopiedJson : labels.drillCopied, { rows }) : labels.toastCopyBlocked, done === "copied" ? void 0 : { tone: "error" });
|
|
1541
|
+
}
|
|
1542
|
+
return;
|
|
1543
|
+
}
|
|
1544
|
+
const xlsx = kind === "drill-xlsx";
|
|
1545
|
+
const fields = Object.fromEntries(drill.columns.map((c) => [c.name, c.label ?? c.name]));
|
|
1546
|
+
const options = { locale, formats: drill.formats, labels: { fields, true: labels.core.true, false: labels.core.false } };
|
|
1547
|
+
const file = `${base}.${xlsx ? "xlsx" : "csv"}`;
|
|
1548
|
+
const bytes = xlsx ? m.rowsToXlsx(encoded, drill.indices, { ...options, sheetName: drill.name }) : m.rowsToCsvBytes(encoded, drill.indices, options);
|
|
1549
|
+
const blob = new Blob([
|
|
1550
|
+
/** @type {BlobPart} */
|
|
1551
|
+
bytes
|
|
1552
|
+
], { type: xlsx ? XLSX_TYPE : "text/csv;charset=utf-8" });
|
|
1553
|
+
if (deliver(blob, { kind, fileName: file, doc: root?.ownerDocument, onExport, rows: part })) {
|
|
1554
|
+
announce(fill(labels.drillExported, { file, rows }));
|
|
1555
|
+
}
|
|
1556
|
+
} catch (e) {
|
|
1557
|
+
announce(fill(labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
|
|
1558
|
+
}
|
|
1559
|
+
}
|
|
1560
|
+
|
|
1561
|
+
// src/drill-table.js
|
|
1562
|
+
import { fieldLabel as fieldLabel3, findNode, formatter, isFormat as isFormat3 } from "pivotkit-core";
|
|
1563
|
+
var DATE_FORMATS = /* @__PURE__ */ new Set(["date", "datetime", "time"]);
|
|
1564
|
+
function columnText(column, { locale, labels, format }) {
|
|
1565
|
+
const spec = typeof format === "string" && isFormat3(format) ? format.trim().toLowerCase() : null;
|
|
1566
|
+
if (column.type === "date") {
|
|
1567
|
+
const f = formatter(spec && DATE_FORMATS.has(spec.split(":")[0]) ? spec : column.dateOnly ? "date" : "datetime", { locale });
|
|
1568
|
+
return { text: f, numeric: false };
|
|
1569
|
+
}
|
|
1570
|
+
if (column.type === "number") {
|
|
1571
|
+
const nf = new Intl.NumberFormat(locale, { maximumFractionDigits: 6 });
|
|
1572
|
+
const f = spec && !DATE_FORMATS.has(spec.split(":")[0]) ? formatter(spec, { locale }) : (v) => nf.format(
|
|
1573
|
+
/** @type {number} */
|
|
1574
|
+
v
|
|
1575
|
+
);
|
|
1576
|
+
return { text: f, numeric: spec !== "text" };
|
|
1577
|
+
}
|
|
1578
|
+
if (column.type === "boolean") {
|
|
1579
|
+
return { text: (v) => v ? labels.true : labels.false, numeric: false };
|
|
1580
|
+
}
|
|
1581
|
+
return { text: (v) => String(v), numeric: false };
|
|
1582
|
+
}
|
|
1583
|
+
function drillTable(encoded, indices, { locale, labels, formatOf = () => void 0 }) {
|
|
1584
|
+
const cols = encoded.columns.map((column) => ({ column, ...columnText(column, { locale, labels, format: formatOf(column.name) }) }));
|
|
1585
|
+
const rows = Array.from(
|
|
1586
|
+
indices,
|
|
1587
|
+
(i) => cols.map(({ column, text }) => {
|
|
1588
|
+
const code = column.codes[i];
|
|
1589
|
+
const v = code < 0 ? null : column.dict[code];
|
|
1590
|
+
return v === null || v === void 0 ? "" : text(v);
|
|
1591
|
+
})
|
|
1592
|
+
);
|
|
1593
|
+
return { columns: cols.map((c) => ({ name: c.column.name, numeric: c.numeric })), rows };
|
|
1594
|
+
}
|
|
1595
|
+
function pathTitle(result, rowPath, colPath, labels) {
|
|
1596
|
+
const parts = [];
|
|
1597
|
+
const items = [];
|
|
1598
|
+
const add = (axis, fields, path) => {
|
|
1599
|
+
const node = findNode(result, axis, path);
|
|
1600
|
+
for (let n = node; n && n.parent; n = n.parent) {
|
|
1601
|
+
const item = result.label(axis, n, labels.core);
|
|
1602
|
+
parts.unshift(`${fieldLabel3(fields[n.depth - 1], labels.core)}: ${item}`);
|
|
1603
|
+
items.unshift(item);
|
|
1604
|
+
}
|
|
1605
|
+
};
|
|
1606
|
+
add("cols", result.colFields, colPath);
|
|
1607
|
+
add("rows", result.rowFields, rowPath);
|
|
1608
|
+
return { title: parts.length ? parts.join(" \xB7 ") : labels.core.grandTotal, name: items.length ? items.join(" \u2013 ") : labels.core.grandTotal };
|
|
1609
|
+
}
|
|
1610
|
+
function drillOf({ result, rowPath, colPath, count, indices, formatOf, nameOf, infoOf }, labels) {
|
|
1611
|
+
const table = drillTable(result.encoded, indices, { locale: result.locale, labels: labels.core, formatOf });
|
|
1612
|
+
const columns = table.columns.map((c) => ({ ...c, label: nameOf(c.name), description: infoOf(c.name)?.description }));
|
|
1613
|
+
const formats = Object.fromEntries(table.columns.map((c) => [c.name, formatOf(c.name)]).filter(([, f]) => typeof f === "string"));
|
|
1614
|
+
return { ...pathTitle(result, rowPath, colPath, labels), count, rows: table.rows, columns, indices, formats, locale: result.locale };
|
|
1615
|
+
}
|
|
1616
|
+
|
|
1617
|
+
// src/drill-panel.jsx
|
|
1618
|
+
function DrillPanel({ drill: source, onClose, labels, locale, exportContext }) {
|
|
1619
|
+
const id = useId4();
|
|
1620
|
+
const drill = useMemo2(() => source ? drillOf(source, labels) : null, [source, labels]);
|
|
1621
|
+
const panel = useRef3(
|
|
1622
|
+
/** @type {HTMLDivElement | null} */
|
|
1623
|
+
null
|
|
1624
|
+
);
|
|
1625
|
+
const [big, setBig] = useState4(false);
|
|
1626
|
+
const narrow = useContext3(LayerContext).size === "narrow";
|
|
1627
|
+
const { onKeyDown } = useModal(panel, Boolean(drill), big ? () => setBig(false) : onClose);
|
|
1628
|
+
useEffect3(() => {
|
|
1629
|
+
if (drill && exportContext) {
|
|
1630
|
+
prepareExporters();
|
|
1631
|
+
}
|
|
1632
|
+
}, [drill, exportContext]);
|
|
1633
|
+
if (!drill) {
|
|
1634
|
+
return null;
|
|
1635
|
+
}
|
|
1636
|
+
const n = drill.count.toLocaleString(locale);
|
|
1637
|
+
const partial = drill.rows.length < drill.count;
|
|
1638
|
+
const run = (kind, close) => () => {
|
|
1639
|
+
close();
|
|
1640
|
+
if (exportContext) {
|
|
1641
|
+
void exportDrill(kind, { drill, labels, ...exportContext, root: exportContext.root.current });
|
|
1642
|
+
}
|
|
1643
|
+
};
|
|
1644
|
+
return /* @__PURE__ */ React5.createElement(React5.Fragment, null, /* @__PURE__ */ React5.createElement("div", { className: "pk-scrim pk-drill-scrim", onClick: onClose, "aria-hidden": "true" }), /* @__PURE__ */ React5.createElement(
|
|
1645
|
+
"div",
|
|
1646
|
+
{
|
|
1647
|
+
className: `pk-drill${big && !narrow ? " pk-drill-big" : ""}`,
|
|
1648
|
+
role: "dialog",
|
|
1649
|
+
"aria-modal": "true",
|
|
1650
|
+
"aria-labelledby": id,
|
|
1651
|
+
"data-testid": "drill-panel",
|
|
1652
|
+
"data-pk-enlarged": big && !narrow ? "" : void 0,
|
|
1653
|
+
ref: panel,
|
|
1654
|
+
tabIndex: -1,
|
|
1655
|
+
onKeyDown: (e) => {
|
|
1656
|
+
if (e.target instanceof Node && panel.current?.contains(e.target)) {
|
|
1657
|
+
onKeyDown(e);
|
|
1658
|
+
}
|
|
1659
|
+
}
|
|
1660
|
+
},
|
|
1661
|
+
/* @__PURE__ */ React5.createElement("div", { className: "pk-drill-head" }, /* @__PURE__ */ React5.createElement("div", { className: "pk-drill-heading" }, /* @__PURE__ */ React5.createElement("h2", { id }, labels.drillTitle), /* @__PURE__ */ React5.createElement("p", { className: "pk-drill-path" }, drill.title), /* @__PURE__ */ React5.createElement("p", { className: "pk-muted", "data-testid": "drill-count" }, partial ? fill(labels.drillShown, { shown: drill.rows.length.toLocaleString(locale), count: n }) : plural(labels.drillCount, drill.count, { lang: labels.lang, locale }))), /* @__PURE__ */ React5.createElement("div", { className: "pk-drill-actions" }, exportContext ? /* @__PURE__ */ React5.createElement(MenuButton, { label: labels.exportLabel, icon: "download", text: labels.exportLabel, role: "dialog", align: "end", testId: "drill-export", className: "pk-btn pk-small-btn" }, (close) => /* @__PURE__ */ React5.createElement(React5.Fragment, null, partial ? /* @__PURE__ */ React5.createElement("p", { className: "pk-hint pk-menu-hint", "data-testid": "drill-export-note" }, fill(labels.drillExportNote, { shown: drill.rows.length.toLocaleString(locale), count: n })) : null, /* @__PURE__ */ React5.createElement(Section, { title: labels.exportDownload, id: "exportDownload" }, /* @__PURE__ */ React5.createElement(ExportOption, { icon: "file", text: labels.drillCsv, onSelect: run("drill-csv", close), testId: "drill-csv" }), /* @__PURE__ */ React5.createElement(ExportOption, { icon: "file", text: labels.drillXlsx, onSelect: run("drill-xlsx", close), testId: "drill-xlsx" })), /* @__PURE__ */ React5.createElement(Section, { title: labels.exportCopy, id: "exportCopy" }, /* @__PURE__ */ React5.createElement(ExportOption, { icon: "copy", text: labels.drillCopy, info: "drillCopy", onSelect: run("drill-copy", close), testId: "drill-copy" }), /* @__PURE__ */ React5.createElement(ExportOption, { icon: "copy", text: labels.drillJson, info: "drillJson", onSelect: run("drill-json", close), testId: "drill-json" })))) : null, narrow ? null : /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "data-pk-on": big ? "" : void 0, onClick: () => setBig((on) => !on), "data-testid": "drill-enlarge" }, /* @__PURE__ */ React5.createElement(Icon, { name: "enlarge", size: 14 }), /* @__PURE__ */ React5.createElement("span", { className: "pk-btn-text" }, big ? labels.reduce : labels.enlarge)), /* @__PURE__ */ React5.createElement("button", { type: "button", className: "pk-icon-btn", onClick: onClose, "data-autofocus": "", "aria-label": labels.close, title: labels.close }, /* @__PURE__ */ React5.createElement(Icon, { name: "x" })))),
|
|
1662
|
+
/* @__PURE__ */ React5.createElement("div", { className: "pk-drill-body", tabIndex: 0, "aria-label": drill.title }, /* @__PURE__ */ React5.createElement("table", { className: "pk-drill-table" }, /* @__PURE__ */ React5.createElement("thead", null, /* @__PURE__ */ React5.createElement("tr", null, drill.columns.map((c) => /* @__PURE__ */ React5.createElement("th", { key: c.name, scope: "col", className: c.numeric ? "pk-num" : void 0, title: c.description, "aria-description": c.description }, c.label ?? c.name)))), /* @__PURE__ */ React5.createElement("tbody", null, drill.rows.map((row, i) => /* @__PURE__ */ React5.createElement("tr", { key: i }, drill.columns.map((c, k) => /* @__PURE__ */ React5.createElement("td", { key: c.name, className: c.numeric ? "pk-num" : void 0 }, c.numeric || row[k].length < 24 ? row[k] : /* @__PURE__ */ React5.createElement("div", { className: "pk-drill-text" }, row[k]))))))))
|
|
1663
|
+
));
|
|
1664
|
+
}
|
|
1665
|
+
export {
|
|
1666
|
+
AxisMenu,
|
|
1667
|
+
ChartTypePanel,
|
|
1668
|
+
DrillPanel,
|
|
1669
|
+
ExportPanel,
|
|
1670
|
+
FilterPopover,
|
|
1671
|
+
LoadCheck,
|
|
1672
|
+
OptionsPanel,
|
|
1673
|
+
ValueMenu,
|
|
1674
|
+
ViewsPanel,
|
|
1675
|
+
addMenuTexts,
|
|
1676
|
+
hasMenuTexts,
|
|
1677
|
+
menuLabels,
|
|
1678
|
+
prepareExporters,
|
|
1679
|
+
runExport,
|
|
1680
|
+
storedViews
|
|
1681
|
+
};
|