pivotkit-react 0.0.0-stage → 0.1.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 +300 -0
- package/LICENSE +21 -0
- package/README.md +327 -2
- package/dist/chunks/chunk-C32TYSHG.js +441 -0
- package/dist/chunks/chunk-ILHFIV2P.js +784 -0
- package/dist/chunks/chunk-KKJO36W5.js +1833 -0
- package/dist/chunks/chunk-XYP47DJ3.js +123 -0
- package/dist/echarts.js +262 -0
- package/dist/index.js +3390 -0
- package/dist/labels.js +12 -0
- package/dist/menus.js +1085 -0
- package/dist/styles.css +2447 -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-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 +152 -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 +39 -0
- package/types/drill.d.ts +62 -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/icons.d.ts +76 -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 +721 -0
- package/types/lazy-menus.d.ts +16 -0
- package/types/menu-labels.d.ts +255 -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 +59 -0
- package/types/place.d.ts +43 -0
- package/types/popover.d.ts +89 -0
- package/types/rove.d.ts +20 -0
- package/types/section.d.ts +42 -0
- package/types/share.d.ts +123 -0
- package/types/skeleton.d.ts +9 -0
- package/types/storage.d.ts +24 -0
- package/types/table.d.ts +23 -0
- package/types/templates.d.ts +40 -0
- package/types/theme.d.ts +24 -0
- package/types/tip-list.d.ts +20 -0
- package/types/tips.d.ts +298 -0
- package/types/toasts.d.ts +26 -0
- package/types/toolbar-panels.d.ts +90 -0
- package/types/toolbar.d.ts +5 -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 +34 -0
- package/types/version.d.ts +2 -0
- package/types/view-history.d.ts +89 -0
- package/types/view-ops.d.ts +344 -0
- package/types/view-store.d.ts +52 -0
- package/types/virtual.d.ts +44 -0
- package/types/zones.d.ts +42 -0
package/dist/menus.js
ADDED
|
@@ -0,0 +1,1085 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ClearInput,
|
|
3
|
+
FieldDescription,
|
|
4
|
+
Icon,
|
|
5
|
+
LayerContext,
|
|
6
|
+
MenuButton,
|
|
7
|
+
Option,
|
|
8
|
+
Popover,
|
|
9
|
+
SHORTCUTS,
|
|
10
|
+
Section,
|
|
11
|
+
SettingInfo,
|
|
12
|
+
TOTALS,
|
|
13
|
+
ZONES,
|
|
14
|
+
ZONE_ICON,
|
|
15
|
+
activeIn,
|
|
16
|
+
binProblem,
|
|
17
|
+
conditionKind,
|
|
18
|
+
copyText,
|
|
19
|
+
dataUrlToBlob,
|
|
20
|
+
decodeRow,
|
|
21
|
+
filterText,
|
|
22
|
+
filtersOf,
|
|
23
|
+
groupField,
|
|
24
|
+
groupingName,
|
|
25
|
+
groupingOf,
|
|
26
|
+
hasFilter,
|
|
27
|
+
measureChoices,
|
|
28
|
+
moveField,
|
|
29
|
+
numericResult,
|
|
30
|
+
refLabel,
|
|
31
|
+
removeFilters,
|
|
32
|
+
reorder,
|
|
33
|
+
safeFileName,
|
|
34
|
+
sameRef,
|
|
35
|
+
saveBlob,
|
|
36
|
+
selectedItems,
|
|
37
|
+
setItemFilter,
|
|
38
|
+
setLabelFilter,
|
|
39
|
+
setSort,
|
|
40
|
+
setTopFilter,
|
|
41
|
+
setValueFilter,
|
|
42
|
+
sortOf,
|
|
43
|
+
sourceOf,
|
|
44
|
+
totalNoEffect,
|
|
45
|
+
updateValue,
|
|
46
|
+
useModal,
|
|
47
|
+
valueLabel,
|
|
48
|
+
withMeasure
|
|
49
|
+
} from "./chunks/chunk-KKJO36W5.js";
|
|
50
|
+
import {
|
|
51
|
+
CHART_TYPES,
|
|
52
|
+
CHART_TYPE_NAMES,
|
|
53
|
+
SLICE_TYPES,
|
|
54
|
+
chartTypeOf
|
|
55
|
+
} from "./chunks/chunk-XYP47DJ3.js";
|
|
56
|
+
import {
|
|
57
|
+
menuLabels
|
|
58
|
+
} from "./chunks/chunk-C32TYSHG.js";
|
|
59
|
+
import {
|
|
60
|
+
fill,
|
|
61
|
+
hostFailure,
|
|
62
|
+
messageOf,
|
|
63
|
+
plural
|
|
64
|
+
} from "./chunks/chunk-ILHFIV2P.js";
|
|
65
|
+
|
|
66
|
+
// src/chip-menus.jsx
|
|
67
|
+
import React, { useId, useState } from "react";
|
|
68
|
+
import { CATALOG, aggregatorsFor, fieldLabel, isFormat } from "pivotkit-core";
|
|
69
|
+
|
|
70
|
+
// src/numbers.js
|
|
71
|
+
var cache = /* @__PURE__ */ new Map();
|
|
72
|
+
function marks(locale) {
|
|
73
|
+
let m = cache.get(locale);
|
|
74
|
+
if (!m) {
|
|
75
|
+
let parts;
|
|
76
|
+
try {
|
|
77
|
+
parts = new Intl.NumberFormat(locale).formatToParts(12345.6);
|
|
78
|
+
} catch {
|
|
79
|
+
parts = new Intl.NumberFormat("en-US").formatToParts(12345.6);
|
|
80
|
+
}
|
|
81
|
+
m = {
|
|
82
|
+
decimal: parts.find((p) => p.type === "decimal")?.value ?? ".",
|
|
83
|
+
group: parts.find((p) => p.type === "group")?.value ?? ","
|
|
84
|
+
};
|
|
85
|
+
cache.set(locale, m);
|
|
86
|
+
}
|
|
87
|
+
return m;
|
|
88
|
+
}
|
|
89
|
+
var escape = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
90
|
+
var PLAIN = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
91
|
+
function parseNumber(text, locale) {
|
|
92
|
+
const t = String(text ?? "").replace(/[\s\u00a0\u202f]/g, "").replace(/\u2212/g, "-");
|
|
93
|
+
if (t === "") {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
const { decimal, group } = marks(locale);
|
|
97
|
+
const g = /[\s\u00a0\u202f]/.test(group) ? "" : escape(group);
|
|
98
|
+
const d = escape(decimal);
|
|
99
|
+
const grouped = g ? `\\d{1,3}(?:${g}\\d{3})+` : "(?!)";
|
|
100
|
+
const local = new RegExp(`^([+-]?)(${grouped}|\\d+)?(?:${d}(\\d+))?$`);
|
|
101
|
+
const match = local.exec(t);
|
|
102
|
+
if (match && (match[2] !== void 0 || match[3] !== void 0)) {
|
|
103
|
+
const whole = (match[2] ?? "0").split(group).join("");
|
|
104
|
+
const n = Number(`${match[1]}${whole}${match[3] !== void 0 ? `.${match[3]}` : ""}`);
|
|
105
|
+
return Number.isFinite(n) ? n : null;
|
|
106
|
+
}
|
|
107
|
+
if (PLAIN.test(t)) {
|
|
108
|
+
const n = Number(t);
|
|
109
|
+
return Number.isFinite(n) ? n : null;
|
|
110
|
+
}
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
function numberText(n, locale) {
|
|
114
|
+
if (typeof n !== "number" || !Number.isFinite(n)) {
|
|
115
|
+
return "";
|
|
116
|
+
}
|
|
117
|
+
try {
|
|
118
|
+
return n.toLocaleString(locale, { useGrouping: false, maximumFractionDigits: 20 });
|
|
119
|
+
} catch {
|
|
120
|
+
return String(n);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// src/chip-menus.jsx
|
|
125
|
+
var FORMAT_CHOICES = ["number", "number:0", "number:2", "currency", "percent"].filter(isFormat);
|
|
126
|
+
var MORE_FORMATS = ["integer", "compact", "bytes", "duration:h", "duration:s"].filter(isFormat);
|
|
127
|
+
var COMMON_SHOW_AS = CATALOG.showAs.filter((s) => ["percentOfGrandTotal", "percentOfRowTotal", "percentOfColumnTotal"].includes(s));
|
|
128
|
+
function More({ title, open, children }) {
|
|
129
|
+
return /* @__PURE__ */ React.createElement("details", { className: "pk-more", open }, /* @__PURE__ */ React.createElement("summary", { className: "pk-more-title" }, title), children);
|
|
130
|
+
}
|
|
131
|
+
function readNumber(text, { kind = "number", required = true, tried = false, labels, locale }) {
|
|
132
|
+
const value = parseNumber(text, locale);
|
|
133
|
+
const ok = value !== null && (kind === "number" || (kind === "size" ? value > 0 : Number.isInteger(value) && value >= 1));
|
|
134
|
+
const say = () => kind === "count" ? labels.countInvalid : fill(kind === "size" ? labels.sizeInvalid : labels.numberInvalid, { example: (kind === "size" ? 0.5 : 1234.5).toLocaleString(locale) });
|
|
135
|
+
if (text.trim() === "") {
|
|
136
|
+
return { value: null, problem: required && tried ? say() : null };
|
|
137
|
+
}
|
|
138
|
+
return ok ? { value, problem: null } : { value: null, problem: say() };
|
|
139
|
+
}
|
|
140
|
+
function NumberField({ value, onChange, problem, label, testId, className = "pk-field-label", shown, shownClass }) {
|
|
141
|
+
const id = useId();
|
|
142
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("label", { className }, shown ? /* @__PURE__ */ React.createElement("span", { className: shownClass }, shown) : /* @__PURE__ */ React.createElement("span", { className: "pk-sr" }, label), /* @__PURE__ */ React.createElement(
|
|
143
|
+
"input",
|
|
144
|
+
{
|
|
145
|
+
type: "text",
|
|
146
|
+
inputMode: "decimal",
|
|
147
|
+
autoComplete: "off",
|
|
148
|
+
spellCheck: false,
|
|
149
|
+
value,
|
|
150
|
+
onChange: (e) => onChange(e.target.value),
|
|
151
|
+
"aria-label": label,
|
|
152
|
+
"aria-invalid": problem ? true : void 0,
|
|
153
|
+
"aria-describedby": problem ? id : void 0,
|
|
154
|
+
"data-testid": testId
|
|
155
|
+
}
|
|
156
|
+
)), problem ? /* @__PURE__ */ React.createElement("p", { id, className: "pk-form-problem", "data-testid": `${testId}-problem` }, problem) : null);
|
|
157
|
+
}
|
|
158
|
+
function BinForm({ grouping, labels, onApply, onClear, range, locale }) {
|
|
159
|
+
const [size, setSize] = useState(numberText(grouping?.size, locale));
|
|
160
|
+
const [start, setStart] = useState(numberText(grouping?.origin, locale));
|
|
161
|
+
const [tried, setTried] = useState(false);
|
|
162
|
+
const problemId = useId();
|
|
163
|
+
const sized = readNumber(size, { kind: "size", tried, labels, locale });
|
|
164
|
+
const started = readNumber(start, { required: false, labels, locale });
|
|
165
|
+
const n = sized.value;
|
|
166
|
+
const s = start.trim() === "" ? 0 : started.value;
|
|
167
|
+
const far = n !== null && s !== null && binProblem(n, s, range) === "far";
|
|
168
|
+
const number = (x) => x.toLocaleString(locale, { maximumFractionDigits: 6 });
|
|
169
|
+
return /* @__PURE__ */ React.createElement(
|
|
170
|
+
"form",
|
|
171
|
+
{
|
|
172
|
+
className: "pk-inline-form pk-bin-form",
|
|
173
|
+
onSubmit: (e) => {
|
|
174
|
+
e.preventDefault();
|
|
175
|
+
if (onClear && size.trim() === "") {
|
|
176
|
+
onClear();
|
|
177
|
+
return;
|
|
178
|
+
}
|
|
179
|
+
setTried(true);
|
|
180
|
+
if (n !== null && s !== null && !far) {
|
|
181
|
+
onApply(n, s);
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
},
|
|
185
|
+
/* @__PURE__ */ React.createElement(NumberField, { value: size, onChange: setSize, problem: sized.problem, label: labels.binSize, shown: labels.binSize, testId: "bin-size" }),
|
|
186
|
+
/* @__PURE__ */ React.createElement("label", { className: "pk-field-label" }, /* @__PURE__ */ React.createElement("span", null, labels.binStart), /* @__PURE__ */ React.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 })),
|
|
187
|
+
started.problem ? /* @__PURE__ */ React.createElement("p", { id: problemId, className: "pk-form-problem", "data-testid": "bin-start-problem" }, started.problem) : far && range && s !== null && n !== null ? /* @__PURE__ */ React.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,
|
|
188
|
+
/* @__PURE__ */ React.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: far }, labels.apply),
|
|
189
|
+
onClear ? /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-btn", onClick: onClear, "data-testid": "bin-remove" }, labels.removeSetting) : null
|
|
190
|
+
);
|
|
191
|
+
}
|
|
192
|
+
function MeasurePick({ choices, names, index, onChange, label, prefix, testId }) {
|
|
193
|
+
if (choices.length < 2) {
|
|
194
|
+
return /* @__PURE__ */ React.createElement("span", { className: "pk-muted pk-by" }, prefix ? `${prefix} ${names[0]}` : names[0]);
|
|
195
|
+
}
|
|
196
|
+
return /* @__PURE__ */ React.createElement("label", { className: "pk-field-label pk-by-pick" }, prefix ? /* @__PURE__ */ React.createElement("span", { className: "pk-muted" }, prefix) : /* @__PURE__ */ React.createElement("span", { className: "pk-sr" }, label), /* @__PURE__ */ React.createElement("select", { value: index, onChange: (e) => onChange(Number(e.target.value)), "aria-label": label, "data-testid": testId }, choices.map((c, i) => /* @__PURE__ */ React.createElement("option", { key: `${c.field}:${c.agg}`, value: i }, names[i]))));
|
|
197
|
+
}
|
|
198
|
+
var choiceIndex = (choices, ref) => Math.max(0, choices.findIndex((c) => sameRef(c, ref)));
|
|
199
|
+
function TopForm({ top, labels, choices, names, onApply, locale }) {
|
|
200
|
+
const [count, setCount] = useState(numberText(top?.count ?? 10, locale));
|
|
201
|
+
const [bottom, setBottom] = useState(Boolean(top?.bottom));
|
|
202
|
+
const [by, setBy] = useState(() => choiceIndex(choices, top?.by));
|
|
203
|
+
const [tried, setTried] = useState(false);
|
|
204
|
+
const counted = readNumber(count, { kind: "count", tried, labels, locale });
|
|
205
|
+
return /* @__PURE__ */ React.createElement(
|
|
206
|
+
"form",
|
|
207
|
+
{
|
|
208
|
+
className: "pk-inline-form",
|
|
209
|
+
onSubmit: (e) => {
|
|
210
|
+
e.preventDefault();
|
|
211
|
+
if (top && count.trim() === "") {
|
|
212
|
+
onApply(null);
|
|
213
|
+
return;
|
|
214
|
+
}
|
|
215
|
+
setTried(true);
|
|
216
|
+
if (counted.value !== null) {
|
|
217
|
+
onApply({ count: counted.value, bottom, by: choices[by] });
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
},
|
|
221
|
+
/* @__PURE__ */ React.createElement("div", { className: "pk-segmented pk-small", role: "group", "aria-label": labels.topN }, /* @__PURE__ */ React.createElement("button", { type: "button", "aria-pressed": !bottom, onClick: () => setBottom(false) }, labels.top), /* @__PURE__ */ React.createElement("button", { type: "button", "aria-pressed": bottom, onClick: () => setBottom(true) }, labels.bottom)),
|
|
222
|
+
/* @__PURE__ */ React.createElement(NumberField, { value: count, onChange: setCount, problem: counted.problem, label: labels.topCount, testId: "top-count", className: "pk-field-label pk-narrow-input" }),
|
|
223
|
+
/* @__PURE__ */ React.createElement(MeasurePick, { choices, names, index: by, onChange: setBy, label: labels.topBy, prefix: labels.topBy, testId: "top-by" }),
|
|
224
|
+
/* @__PURE__ */ React.createElement("button", { type: "submit", className: "pk-btn pk-primary" }, labels.apply),
|
|
225
|
+
top ? /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-btn", onClick: () => onApply(null), "data-testid": "top-remove" }, labels.removeSetting) : null
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
function ValueFilterForm({ condition, labels, choices, names, onApply, locale }) {
|
|
229
|
+
const [by, setBy] = useState(() => choiceIndex(choices, condition?.by));
|
|
230
|
+
const [op, setOp] = useState(condition?.op ?? ">");
|
|
231
|
+
const [first, setFirst] = useState(numberText(condition?.value, locale));
|
|
232
|
+
const [second, setSecond] = useState(numberText(condition?.value2, locale));
|
|
233
|
+
const [tried, setTried] = useState(false);
|
|
234
|
+
const between = op === "between" || op === "notBetween";
|
|
235
|
+
const a = readNumber(first, { tried, labels, locale });
|
|
236
|
+
const b = readNumber(second, { tried, labels, locale });
|
|
237
|
+
const ok = a.value !== null && (!between || b.value !== null);
|
|
238
|
+
return /* @__PURE__ */ React.createElement(
|
|
239
|
+
"form",
|
|
240
|
+
{
|
|
241
|
+
className: "pk-inline-form pk-value-filter",
|
|
242
|
+
onSubmit: (e) => {
|
|
243
|
+
e.preventDefault();
|
|
244
|
+
if (condition && first.trim() === "" && second.trim() === "") {
|
|
245
|
+
onApply(null);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
setTried(true);
|
|
249
|
+
if (ok) {
|
|
250
|
+
onApply({ by: choices[by], op, value: (
|
|
251
|
+
/** @type {number} */
|
|
252
|
+
a.value
|
|
253
|
+
), ...between ? { value2: (
|
|
254
|
+
/** @type {number} */
|
|
255
|
+
b.value
|
|
256
|
+
) } : {} });
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
},
|
|
260
|
+
/* @__PURE__ */ React.createElement(MeasurePick, { choices, names, index: by, onChange: setBy, label: labels.valueFilterBy, testId: "value-filter-by" }),
|
|
261
|
+
/* @__PURE__ */ React.createElement("label", { className: "pk-field-label" }, /* @__PURE__ */ React.createElement("span", { className: "pk-sr" }, labels.valueFilterOp), /* @__PURE__ */ React.createElement("select", { value: op, onChange: (e) => setOp(e.target.value), "aria-label": labels.valueFilterOp, "data-testid": "value-filter-op" }, CATALOG.valueOps.map((o) => /* @__PURE__ */ React.createElement("option", { key: o, value: o }, labels.valueOps[o] ?? o)))),
|
|
262
|
+
/* @__PURE__ */ React.createElement(NumberField, { value: first, onChange: setFirst, problem: a.problem, label: labels.valueFilterNumber, testId: "value-filter-number", className: "pk-field-label pk-narrow-input" }),
|
|
263
|
+
between ? /* @__PURE__ */ React.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,
|
|
264
|
+
/* @__PURE__ */ React.createElement("button", { type: "submit", className: "pk-btn pk-primary", "data-testid": "value-filter-apply" }, labels.apply),
|
|
265
|
+
condition ? /* @__PURE__ */ React.createElement("button", { type: "button", className: "pk-btn", onClick: () => onApply(null), "data-testid": "value-filter-remove" }, labels.removeSetting) : null
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
function MoveSection({ view, zone, index, count, labels, commit, close, text, type }) {
|
|
269
|
+
return /* @__PURE__ */ React.createElement(Section, { title: labels.move, id: "move" }, ZONES.filter((z) => z !== zone).map((z) => /* @__PURE__ */ React.createElement(Option, { key: z, icon: ZONE_ICON[z], onSelect: () => {
|
|
270
|
+
close();
|
|
271
|
+
commit(moveField(view, zone, index, z, void 0, { type }), { step: "moved", field: text, zone: z });
|
|
272
|
+
}, testId: `move-${z}` }, fill(labels.moveTo, { zone: labels.zones[z] }))), zone !== "filters" && index > 0 ? /* @__PURE__ */ React.createElement(Option, { icon: "chevronRight", onSelect: () => {
|
|
273
|
+
close();
|
|
274
|
+
commit(reorder(view, zone, index, index - 1), { step: "reordered", zone });
|
|
275
|
+
} }, labels.moveLeft) : null, zone !== "filters" && index < count - 1 ? /* @__PURE__ */ React.createElement(Option, { icon: "chevronRight", onSelect: () => {
|
|
276
|
+
close();
|
|
277
|
+
commit(reorder(view, zone, index, index + 1), { step: "reordered", zone });
|
|
278
|
+
} }, labels.moveRight) : null);
|
|
279
|
+
}
|
|
280
|
+
function RemoveFoot({ labels, onRemove, close }) {
|
|
281
|
+
return /* @__PURE__ */ React.createElement("div", { className: "pk-menu-foot" }, /* @__PURE__ */ React.createElement(Option, { icon: "trash", danger: true, onSelect: () => {
|
|
282
|
+
close();
|
|
283
|
+
onRemove();
|
|
284
|
+
}, testId: "menu-remove" }, labels.remove));
|
|
285
|
+
}
|
|
286
|
+
function AxisMenu({ view, zone, index, field, types, labels, commit, close, openFilter, chipRef, onRemove, defaultsOf, rangeOf, locale, info, state }) {
|
|
287
|
+
const source = sourceOf(view, field);
|
|
288
|
+
const name = fieldLabel(field, labels.core);
|
|
289
|
+
const sourceType = types.get(source.toLowerCase());
|
|
290
|
+
const grouping = groupingOf(view, field);
|
|
291
|
+
const sort = sortOf(view, field);
|
|
292
|
+
const shown = measureChoices(view, (f) => types.get(f.toLowerCase()));
|
|
293
|
+
const top = filtersOf(view, field, ["top"])[0];
|
|
294
|
+
const condition = filtersOf(view, field, ["value"])[0];
|
|
295
|
+
const pick = (ref) => {
|
|
296
|
+
const list = withMeasure(shown, ref);
|
|
297
|
+
return { choices: list, names: list.map((c) => refLabel(view, c, labels)) };
|
|
298
|
+
};
|
|
299
|
+
const { choices, names } = pick(sort?.by === "value" ? sort.value : null);
|
|
300
|
+
const topPick = pick(top?.by);
|
|
301
|
+
const conditionPick = pick(condition?.by);
|
|
302
|
+
const isSort = (by, order, ref) => sort ? sort.by === by && sort.order === order && (by !== "value" || sameRef(sort.value, ref)) : by === "label" && order === "asc";
|
|
303
|
+
const hostOrder = source === field ? defaultsOf?.(source)?.order : void 0;
|
|
304
|
+
const customItems = sort?.by === "custom" ? sort.items : Array.isArray(hostOrder) && hostOrder.length > 0 ? hostOrder : null;
|
|
305
|
+
const doSort = (by, order, ref) => {
|
|
306
|
+
close();
|
|
307
|
+
const spec = by === "value" ? { by, order, value: ref } : by === "custom" ? { by, order, items: [...customItems] } : { by, order };
|
|
308
|
+
commit(setSort(view, field, by === "label" && order === "asc" && !(Array.isArray(hostOrder) && hostOrder.length > 0) ? null : spec), { step: "sort", field: name });
|
|
309
|
+
};
|
|
310
|
+
const regroup = (unit, size, origin) => {
|
|
311
|
+
close();
|
|
312
|
+
const sourceName = fieldLabel(source, labels.core);
|
|
313
|
+
const grouped = unit ? groupingName(sourceName, unit, labels, size) : null;
|
|
314
|
+
commit(groupField(view, field, unit, { size, origin, name: grouped ?? void 0 }).view, { step: "group", field: sourceName });
|
|
315
|
+
};
|
|
316
|
+
const unitOption = (u) => /* @__PURE__ */ React.createElement(Option, { key: u, checked: grouping?.by === u, onSelect: () => regroup(u), testId: `group-${u}`, hint: labels.unitHints[u] || void 0 }, labels.units[u] ?? u);
|
|
317
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "pk-menu-body" }, info ? /* @__PURE__ */ React.createElement(FieldDescription, { info, labels, className: "pk-field-desc pk-menu-desc" }) : null, /* @__PURE__ */ React.createElement(Section, { title: labels.sort, id: "sort" }, /* @__PURE__ */ React.createElement(Option, { checked: isSort("label", "asc"), icon: "sortAsc", onSelect: () => doSort("label", "asc") }, sourceType === "date" ? labels.sortOldest : labels.sortLabelAsc), /* @__PURE__ */ React.createElement(Option, { checked: isSort("label", "desc"), icon: "sortDesc", onSelect: () => doSort("label", "desc") }, sourceType === "date" ? labels.sortNewest : labels.sortLabelDesc), choices.map((c, i) => /* @__PURE__ */ React.createElement(React.Fragment, { key: `${c.field}:${c.agg}` }, /* @__PURE__ */ React.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__ */ React.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__ */ React.createElement(Option, { checked: isSort("custom", "asc"), icon: "sortAsc", onSelect: () => doSort("custom", "asc"), testId: "sort-custom" }, labels.sortCustom) : null, customItems ? /* @__PURE__ */ React.createElement(Option, { checked: isSort("custom", "desc"), icon: "sortDesc", onSelect: () => doSort("custom", "desc"), testId: "sort-custom-desc" }, labels.sortCustomDesc) : null), sourceType === "date" ? /* @__PURE__ */ React.createElement(Section, { title: labels.groupBy, id: "groupBy" }, /* @__PURE__ */ React.createElement("div", { className: "pk-subtitle" }, labels.groupTimeline), /* @__PURE__ */ React.createElement("div", { className: "pk-choice-grid" }, CATALOG.timelineUnits.map(unitOption)), /* @__PURE__ */ React.createElement("div", { className: "pk-subtitle" }, labels.groupCyclic), /* @__PURE__ */ React.createElement("div", { className: "pk-choice-grid" }, CATALOG.cyclicUnits.map(unitOption)), /* @__PURE__ */ React.createElement(Option, { checked: !grouping, onSelect: () => regroup(null), testId: "group-none" }, labels.groupNone)) : null, sourceType === "number" ? /* @__PURE__ */ React.createElement(Section, { title: labels.bins, id: "bins" }, /* @__PURE__ */ React.createElement(BinForm, { grouping: grouping?.by === "bin" ? grouping : null, labels, range: rangeOf?.(source) ?? null, locale, onApply: (size, origin) => regroup("bin", size, origin), onClear: grouping ? () => regroup(null) : null })) : null, /* @__PURE__ */ React.createElement(Section, { title: labels.topN, id: "topN" }, /* @__PURE__ */ React.createElement(TopForm, { top, labels, choices: topPick.choices, names: topPick.names, locale, onApply: (t) => {
|
|
318
|
+
close();
|
|
319
|
+
commit(setTopFilter(view, field, t, top), { step: "top", field: name });
|
|
320
|
+
} })), /* @__PURE__ */ React.createElement(Section, { title: labels.zones.filters, id: "filters" }, hasFilter(view, field) ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(Option, { icon: "filter", tone: "accent", onSelect: () => {
|
|
321
|
+
close();
|
|
322
|
+
openFilter(field, chipRef.current);
|
|
323
|
+
}, testId: "open-filter" }, filterText(view, field, state, labels, locale)), /* @__PURE__ */ React.createElement(Option, { icon: "x", onSelect: () => {
|
|
324
|
+
close();
|
|
325
|
+
commit(removeFilters(view, field), { step: "filter", field: name });
|
|
326
|
+
}, testId: "remove-filter" }, labels.removeFilter)) : /* @__PURE__ */ React.createElement(Option, { icon: "filter", onSelect: () => {
|
|
327
|
+
close();
|
|
328
|
+
openFilter(field, chipRef.current);
|
|
329
|
+
}, testId: "open-filter" }, labels.filter), /* @__PURE__ */ React.createElement(More, { title: labels.valueFilter, open: Boolean(condition) }, /* @__PURE__ */ React.createElement(ValueFilterForm, { condition, labels, choices: conditionPick.choices, names: conditionPick.names, locale, onApply: (c) => {
|
|
330
|
+
close();
|
|
331
|
+
commit(setValueFilter(view, field, c, condition), { step: "filter", field: name });
|
|
332
|
+
} }))), /* @__PURE__ */ React.createElement(MoveSection, { view, zone, index, count: view[zone].length, labels, commit, close, text: name, type: sourceType })), /* @__PURE__ */ React.createElement(RemoveFoot, { labels, onRemove, close }));
|
|
333
|
+
}
|
|
334
|
+
function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaultsOf, info }) {
|
|
335
|
+
const spec = view.values[index];
|
|
336
|
+
const type = spec.field ? types.get(spec.field.toLowerCase()) ?? "string" : "number";
|
|
337
|
+
const aggs = spec.field ? aggregatorsFor(type) : ["count"];
|
|
338
|
+
const common = CATALOG.commonAggregators.filter((a) => aggs.includes(a));
|
|
339
|
+
const rare = aggs.filter((a) => !CATALOG.commonAggregators.includes(a));
|
|
340
|
+
const otherShowAs = CATALOG.showAs.filter((s) => !COMMON_SHOW_AS.includes(s));
|
|
341
|
+
const numeric = numericResult(spec, type);
|
|
342
|
+
const name = valueLabel(spec, labels);
|
|
343
|
+
const set = (patch) => {
|
|
344
|
+
close();
|
|
345
|
+
commit(updateValue(view, index, patch, { defaults: spec.field ? defaultsOf?.(spec.field) : void 0 }), { step: "value", field: name });
|
|
346
|
+
};
|
|
347
|
+
const [rename, setRename] = useState(spec.label ?? "");
|
|
348
|
+
const aggOption = (a) => /* @__PURE__ */ React.createElement(Option, { key: a, checked: spec.agg === a, onSelect: () => set({ agg: a }), testId: `agg-${a}` }, labels.core.aggregators[a] ?? a);
|
|
349
|
+
const formatOption = (f) => /* @__PURE__ */ React.createElement(Option, { key: f, checked: spec.format === f, onSelect: () => set({ format: f }), testId: `format-${f}` }, labels.formats[f] ?? f);
|
|
350
|
+
const showAsOption = (s) => /* @__PURE__ */ React.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);
|
|
351
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "pk-menu-body" }, info ? /* @__PURE__ */ React.createElement(FieldDescription, { info, labels, className: "pk-field-desc pk-menu-desc" }) : null, /* @__PURE__ */ React.createElement(Section, { title: labels.aggregation, id: "summarize" }, /* @__PURE__ */ React.createElement("div", { className: "pk-choice-grid" }, common.map(aggOption)), rare.length ? /* @__PURE__ */ React.createElement(More, { title: labels.moreStatistics, open: rare.includes(spec.agg) }, /* @__PURE__ */ React.createElement("div", { className: "pk-choice-grid" }, rare.map(aggOption))) : null), numeric ? /* @__PURE__ */ React.createElement(Section, { title: labels.showAs, id: "showAs", info: "showAs" }, /* @__PURE__ */ React.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React.createElement(Option, { checked: !spec.showAs, onSelect: () => set({ showAs: null }), testId: "showas-none" }, labels.showAsNone), COMMON_SHOW_AS.map(showAsOption)), /* @__PURE__ */ React.createElement(More, { title: labels.moreCalculations, open: Boolean(spec.showAs && otherShowAs.includes(spec.showAs.type)) }, /* @__PURE__ */ React.createElement("div", { className: "pk-choice-grid" }, otherShowAs.map(showAsOption))), spec.showAs && CATALOG.showAsAlongAxis.includes(spec.showAs.type) ? /* @__PURE__ */ React.createElement("div", { className: "pk-setting-row" }, /* @__PURE__ */ React.createElement("div", { className: "pk-segmented pk-small", role: "group", "aria-label": labels.along }, /* @__PURE__ */ React.createElement("span", { className: "pk-muted" }, labels.along), ["rows", "cols"].map((axis) => /* @__PURE__ */ React.createElement("button", { key: axis, type: "button", "aria-pressed": spec.showAs.axis === axis, onClick: () => set({ showAs: { ...spec.showAs, axis } }) }, labels.zones[axis]))), /* @__PURE__ */ React.createElement(SettingInfo, { id: "along", name: labels.along })) : null) : null, numeric ? /* @__PURE__ */ React.createElement(Section, { title: labels.format, id: "format" }, /* @__PURE__ */ React.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React.createElement(Option, { checked: !spec.format, onSelect: () => set({ format: null }) }, labels.formatAuto), FORMAT_CHOICES.map(formatOption)), /* @__PURE__ */ React.createElement(More, { title: labels.moreFormats, open: MORE_FORMATS.includes(spec.format ?? "") }, /* @__PURE__ */ React.createElement("div", { className: "pk-choice-grid" }, MORE_FORMATS.map(formatOption)))) : null, numeric ? /* @__PURE__ */ React.createElement(Section, { title: labels.conditional, id: "highlight" }, /* @__PURE__ */ React.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React.createElement(Option, { checked: !spec.conditional, onSelect: () => set({ conditional: null }) }, labels.conditionalNone), /* @__PURE__ */ React.createElement(Option, { checked: spec.conditional?.type === "colorScale", onSelect: () => set({ conditional: { type: "colorScale" } }), testId: "cond-colorScale" }, labels.colorScale), /* @__PURE__ */ React.createElement(Option, { checked: spec.conditional?.type === "dataBar", onSelect: () => set({ conditional: { type: "dataBar", color: null } }), testId: "cond-dataBar" }, labels.dataBar))) : null, /* @__PURE__ */ React.createElement(Section, { title: labels.rename, id: "name" }, /* @__PURE__ */ React.createElement("form", { className: "pk-inline-form", onSubmit: (e) => {
|
|
352
|
+
e.preventDefault();
|
|
353
|
+
set({ label: rename.trim() || null });
|
|
354
|
+
} }, /* @__PURE__ */ React.createElement(
|
|
355
|
+
ClearInput,
|
|
356
|
+
{
|
|
357
|
+
type: "text",
|
|
358
|
+
value: rename,
|
|
359
|
+
placeholder: valueLabel({ ...spec, label: null }, labels),
|
|
360
|
+
onChange: setRename,
|
|
361
|
+
onClear: () => spec.label ? commit(updateValue(view, index, { label: null }), { step: "value", field: name }) : void 0,
|
|
362
|
+
clearLabel: labels.defaultName,
|
|
363
|
+
"aria-label": labels.rename,
|
|
364
|
+
maxLength: 200,
|
|
365
|
+
"data-testid": "value-name"
|
|
366
|
+
}
|
|
367
|
+
), /* @__PURE__ */ React.createElement("button", { type: "submit", className: "pk-btn pk-primary" }, labels.apply))), /* @__PURE__ */ React.createElement(Section, { title: labels.zones.filters, id: "valueFilters" }, /* @__PURE__ */ React.createElement("p", { className: "pk-hint pk-menu-hint", "data-testid": "values-filter-hint" }, labels.valuesFilterHint)), /* @__PURE__ */ React.createElement(MoveSection, { view, zone: "values", index, count: view.values.length, labels, commit, close, text: name, type })), /* @__PURE__ */ React.createElement(RemoveFoot, { labels, onRemove, close }));
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
// src/toolbar-panels.jsx
|
|
371
|
+
import React2, { useEffect, useId as useId2, useRef, useState as useState2 } from "react";
|
|
372
|
+
import { VIEW_FILE_LIMITS } from "pivotkit-core";
|
|
373
|
+
|
|
374
|
+
// src/view-store.js
|
|
375
|
+
import { toViewFile } from "pivotkit-core";
|
|
376
|
+
import { parseTemplates } from "pivotkit-core/templates";
|
|
377
|
+
var VIEW_STORE_LIMITS = Object.freeze({ count: 100, text: 5e5 });
|
|
378
|
+
var warnedLarge = false;
|
|
379
|
+
function readAll(raw) {
|
|
380
|
+
if (!raw) {
|
|
381
|
+
return [];
|
|
382
|
+
}
|
|
383
|
+
if (raw.length > VIEW_STORE_LIMITS.text) {
|
|
384
|
+
if (!warnedLarge) {
|
|
385
|
+
warnedLarge = true;
|
|
386
|
+
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`);
|
|
387
|
+
}
|
|
388
|
+
return [];
|
|
389
|
+
}
|
|
390
|
+
return parseTemplates(raw).templates;
|
|
391
|
+
}
|
|
392
|
+
function storedViews(raw, sourceId) {
|
|
393
|
+
return readAll(raw).map((t, at) => ({ name: t.name, view: t.view, id: t.source?.id, at })).filter((t) => !t.id || !sourceId || t.id === sourceId).map(({ name, view, at }) => ({ name, view, at }));
|
|
394
|
+
}
|
|
395
|
+
function changedViews(raw, change, message) {
|
|
396
|
+
const all = readAll(raw);
|
|
397
|
+
let next = all;
|
|
398
|
+
if (change.remove !== void 0) {
|
|
399
|
+
if (all[change.remove]?.name !== change.removeName) {
|
|
400
|
+
throw new Error(message("changed", 0));
|
|
401
|
+
}
|
|
402
|
+
next = all.filter((t, i) => i !== change.remove);
|
|
403
|
+
}
|
|
404
|
+
const saving = Boolean(change.name && change.view);
|
|
405
|
+
if (saving) {
|
|
406
|
+
const id = change.sourceId;
|
|
407
|
+
next = next.filter((t) => t.name !== change.name || (t.source?.id ?? void 0) !== id);
|
|
408
|
+
next.push({ name: (
|
|
409
|
+
/** @type {string} */
|
|
410
|
+
change.name
|
|
411
|
+
), view: (
|
|
412
|
+
/** @type {Record<string, unknown>} */
|
|
413
|
+
change.view
|
|
414
|
+
), ...id ? { source: { id } } : {} });
|
|
415
|
+
if (next.length > VIEW_STORE_LIMITS.count) {
|
|
416
|
+
throw new Error(message("count", VIEW_STORE_LIMITS.count));
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
const text = next.length ? JSON.stringify(next.map((t) => toViewFile(t.view, { name: t.name, source: t.source }, { link: true }))) : null;
|
|
420
|
+
if (saving && text && text.length > VIEW_STORE_LIMITS.text) {
|
|
421
|
+
throw new Error(message("text", VIEW_STORE_LIMITS.text));
|
|
422
|
+
}
|
|
423
|
+
return text;
|
|
424
|
+
}
|
|
425
|
+
function storeViews(raw, change, labels, locale, keep) {
|
|
426
|
+
const texts = { count: labels.storeFull, text: labels.storeTooLarge, changed: labels.storeChanged };
|
|
427
|
+
const text = changedViews(raw, change, (kind, max) => fill(texts[kind], { max: max.toLocaleString(locale) }));
|
|
428
|
+
if (!keep(text)) {
|
|
429
|
+
throw new Error(labels.storeRefused);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
// src/toolbar-panels.jsx
|
|
434
|
+
function ChartTypeOptions({ view, plan, labels, onChart, close }) {
|
|
435
|
+
const current = chartTypeOf(view.chart);
|
|
436
|
+
return CHART_TYPE_NAMES.map((p) => /* @__PURE__ */ React2.createElement(
|
|
437
|
+
Option,
|
|
438
|
+
{
|
|
439
|
+
key: p,
|
|
440
|
+
icon: CHART_TYPES[p].icon,
|
|
441
|
+
checked: view.display === "chart" && current === p,
|
|
442
|
+
hint: p === "auto" && plan ? fill(labels.chartAutoNow, { type: labels.chartTypes[plan.name] }) : void 0,
|
|
443
|
+
onSelect: () => {
|
|
444
|
+
close();
|
|
445
|
+
onChart(p);
|
|
446
|
+
},
|
|
447
|
+
testId: `chart-${p}`
|
|
448
|
+
},
|
|
449
|
+
labels.chartTypes[p]
|
|
450
|
+
));
|
|
451
|
+
}
|
|
452
|
+
var VALUE_LABELS = { slices: ["auto", "off", "value", "percent", "both"], other: ["auto", "off", "value"] };
|
|
453
|
+
var LABEL_POSITIONS = ["outside", "inside"];
|
|
454
|
+
var LEGENDS = ["auto", "bottom", "right", "off"];
|
|
455
|
+
var AXIS_LABELS = ["auto", "all", "nth"];
|
|
456
|
+
var GROUP_LABELS = ["auto", "on", "off"];
|
|
457
|
+
function ChartTitle({ title, labels, onDisplay }) {
|
|
458
|
+
const [text, setText] = useState2(title ?? "");
|
|
459
|
+
const [last, setLast] = useState2(title);
|
|
460
|
+
if (title !== last) {
|
|
461
|
+
setLast(title);
|
|
462
|
+
setText(title ?? "");
|
|
463
|
+
}
|
|
464
|
+
return /* @__PURE__ */ React2.createElement(
|
|
465
|
+
"form",
|
|
466
|
+
{
|
|
467
|
+
className: "pk-inline-form",
|
|
468
|
+
onSubmit: (e) => {
|
|
469
|
+
e.preventDefault();
|
|
470
|
+
onDisplay({ title: text.trim() || null });
|
|
471
|
+
}
|
|
472
|
+
},
|
|
473
|
+
/* @__PURE__ */ React2.createElement(
|
|
474
|
+
ClearInput,
|
|
475
|
+
{
|
|
476
|
+
type: "text",
|
|
477
|
+
value: text,
|
|
478
|
+
onChange: setText,
|
|
479
|
+
onClear: () => title ? onDisplay({ title: null }) : void 0,
|
|
480
|
+
clearLabel: labels.clearText,
|
|
481
|
+
placeholder: labels.chartTitleNone,
|
|
482
|
+
"aria-label": labels.chartTitle,
|
|
483
|
+
maxLength: 200,
|
|
484
|
+
"data-testid": "chart-title"
|
|
485
|
+
}
|
|
486
|
+
),
|
|
487
|
+
/* @__PURE__ */ React2.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: (text.trim() || null) === (title ?? null) }, labels.apply)
|
|
488
|
+
);
|
|
489
|
+
}
|
|
490
|
+
function ChartDisplay({ view, plan, labels, onDisplay }) {
|
|
491
|
+
const chart = view.chart;
|
|
492
|
+
const drawn = plan ? plan.name : chartTypeOf(chart);
|
|
493
|
+
const pie = SLICE_TYPES.includes(drawn);
|
|
494
|
+
const axis = CHART_TYPES[drawn].axis;
|
|
495
|
+
const choices = pie ? VALUE_LABELS.slices : VALUE_LABELS.other;
|
|
496
|
+
const valueLabels = !pie && (chart.valueLabels === "percent" || chart.valueLabels === "both") ? "value" : chart.valueLabels;
|
|
497
|
+
return /* @__PURE__ */ React2.createElement(Section, { title: labels.chartDisplay, id: "chartDisplay" }, /* @__PURE__ */ React2.createElement("div", { className: "pk-subtitle" }, labels.valueLabels), /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, choices.map((v) => /* @__PURE__ */ React2.createElement(Option, { key: v, checked: valueLabels === v, onSelect: () => onDisplay({ valueLabels: v }), testId: `labels-${v}` }, labels.valueLabelNames[v]))), pie ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { className: "pk-subtitle pk-setting-row" }, /* @__PURE__ */ React2.createElement("span", null, labels.labelPosition), /* @__PURE__ */ React2.createElement(SettingInfo, { id: "labelPosition", name: labels.labelPosition })), /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, LABEL_POSITIONS.map((v) => /* @__PURE__ */ React2.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__ */ React2.createElement("div", { className: "pk-subtitle" }, labels.legend), /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, LEGENDS.map((v) => /* @__PURE__ */ React2.createElement(Option, { key: v, checked: chart.legend === v, onSelect: () => onDisplay({ legend: v }), testId: `legend-${v}` }, labels.legendNames[v]))), /* @__PURE__ */ React2.createElement("div", { className: "pk-subtitle" }, labels.chartTitle), /* @__PURE__ */ React2.createElement(ChartTitle, { title: chart.title, labels, onDisplay }), axis ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { className: "pk-subtitle" }, labels.axisLabels), /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, AXIS_LABELS.map((v) => /* @__PURE__ */ React2.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__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { className: "pk-subtitle pk-setting-row" }, /* @__PURE__ */ React2.createElement("span", null, labels.groupLabels), /* @__PURE__ */ React2.createElement(SettingInfo, { id: "groupLabels", name: labels.groupLabels })), /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, GROUP_LABELS.map((v) => /* @__PURE__ */ React2.createElement(Option, { key: v, checked: chart.groupLabels === v, onSelect: () => onDisplay({ groupLabels: v }), testId: `groups-${v}` }, labels.groupLabelNames[v])))) : null, drawn === "line" || drawn === "area" ? /* @__PURE__ */ React2.createElement(Switch, { checked: chart.smooth, onChange: (on) => onDisplay({ smooth: on }), testId: "chart-smooth" }, labels.smoothLines) : null);
|
|
498
|
+
}
|
|
499
|
+
function ChartTypePanel({ view, plan, labels, onChart, onDisplay, close }) {
|
|
500
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Section, { title: labels.chartType, id: "chartType" }, /* @__PURE__ */ React2.createElement("div", { className: "pk-choice-grid" }, /* @__PURE__ */ React2.createElement(ChartTypeOptions, { view, plan, labels, onChart, close }))), /* @__PURE__ */ React2.createElement(ChartDisplay, { view, plan, labels, onDisplay }));
|
|
501
|
+
}
|
|
502
|
+
function Shortcuts({ labels, mod }) {
|
|
503
|
+
const key = (k) => k === "Mod" ? mod === "\u2318" ? "\u2318" : labels.keys.Mod : Object.hasOwn(labels.keys, k) ? labels.keys[k] : k;
|
|
504
|
+
return /* @__PURE__ */ React2.createElement("dl", { className: "pk-shortcuts", "data-testid": "shortcuts" }, SHORTCUTS.map((s) => /* @__PURE__ */ React2.createElement("div", { key: s.text, className: "pk-shortcut" }, /* @__PURE__ */ React2.createElement("dt", null, s.keys.map((k, i) => /* @__PURE__ */ React2.createElement(React2.Fragment, { key: k }, i ? " + " : null, /* @__PURE__ */ React2.createElement("kbd", null, key(k))))), /* @__PURE__ */ React2.createElement("dd", null, labels.shortcuts[s.text]))));
|
|
505
|
+
}
|
|
506
|
+
function Switch({ checked, onChange, testId, children, disabled, reason, info, name }) {
|
|
507
|
+
const reasonId = useId2();
|
|
508
|
+
return /* @__PURE__ */ React2.createElement("div", { className: "pk-setting-row" }, /* @__PURE__ */ React2.createElement("label", { className: `pk-switch${disabled ? " pk-disabled" : ""}` }, /* @__PURE__ */ React2.createElement("input", { type: "checkbox", checked, disabled, onChange: (e) => onChange(e.target.checked), "aria-describedby": disabled && reason ? reasonId : void 0, "data-testid": testId }), /* @__PURE__ */ React2.createElement("span", { className: "pk-switch-track", "aria-hidden": "true" }), /* @__PURE__ */ React2.createElement("span", { className: "pk-switch-text" }, children, disabled && reason ? /* @__PURE__ */ React2.createElement("span", { id: reasonId, className: "pk-option-hint", "data-testid": testId ? `${testId}-reason` : void 0 }, reason) : null)), info ? /* @__PURE__ */ React2.createElement(SettingInfo, { id: info, name: name ?? "" }) : null);
|
|
509
|
+
}
|
|
510
|
+
function OptionsPanel({ view, labels, onTotal, onExpand, onCollapse, close, tips, mod, folding, help }) {
|
|
511
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Section, { title: labels.totals, id: "totals" }, TOTALS.map((key) => {
|
|
512
|
+
const why = totalNoEffect(view, key);
|
|
513
|
+
return /* @__PURE__ */ React2.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]);
|
|
514
|
+
})), /* @__PURE__ */ React2.createElement(Section, { title: labels.zones.rows, id: "folding" }, /* @__PURE__ */ React2.createElement(Option, { icon: "chevronDown", onSelect: () => {
|
|
515
|
+
close();
|
|
516
|
+
onExpand();
|
|
517
|
+
}, disabled: !folding.canExpand, reason: folding.why.expand ? labels[folding.why.expand] : void 0, testId: "expand-all" }, labels.expandAll), /* @__PURE__ */ React2.createElement(Option, { icon: "chevronRight", onSelect: () => {
|
|
518
|
+
close();
|
|
519
|
+
onCollapse();
|
|
520
|
+
}, disabled: !folding.canCollapse, reason: folding.why.collapse ? labels[folding.why.collapse] : void 0, testId: "collapse-all" }, labels.collapseAll)), /* @__PURE__ */ React2.createElement(Section, { title: labels.help, id: "help" }, tips.controls ? /* @__PURE__ */ React2.createElement(Switch, { checked: tips.on, onChange: tips.onOn, testId: "show-tips" }, labels.showTips) : null, help?.explanations ? /* @__PURE__ */ React2.createElement(Switch, { checked: help.explanations.on, onChange: help.explanations.set, testId: "show-explanations" }, labels.showSettingInfo) : null, tips.controls ? /* @__PURE__ */ React2.createElement(Option, { icon: "reset", onSelect: () => tips.onReset(), disabled: !tips.canReset, testId: "reset-tips" }, labels.resetTips) : null, /* @__PURE__ */ React2.createElement("details", { className: "pk-more" }, /* @__PURE__ */ React2.createElement("summary", { className: "pk-more-title", "data-testid": "shortcuts-title" }, labels.shortcutsTitle), /* @__PURE__ */ React2.createElement(Shortcuts, { labels, mod }))));
|
|
521
|
+
}
|
|
522
|
+
function SaveView({ labels, onSave }) {
|
|
523
|
+
const [name, setName] = useState2("");
|
|
524
|
+
const field = useRef(
|
|
525
|
+
/** @type {HTMLInputElement | null} */
|
|
526
|
+
null
|
|
527
|
+
);
|
|
528
|
+
return /* @__PURE__ */ React2.createElement(
|
|
529
|
+
"form",
|
|
530
|
+
{
|
|
531
|
+
className: "pk-inline-form",
|
|
532
|
+
onSubmit: (e) => {
|
|
533
|
+
e.preventDefault();
|
|
534
|
+
if (name.trim()) {
|
|
535
|
+
const saved = onSave(name.trim());
|
|
536
|
+
setName("");
|
|
537
|
+
field.current?.focus({ preventScroll: true });
|
|
538
|
+
Promise.resolve(saved).then(
|
|
539
|
+
() => requestAnimationFrame(() => {
|
|
540
|
+
const el = field.current;
|
|
541
|
+
const now = el ? activeIn(el) : null;
|
|
542
|
+
if (el && el.isConnected && now !== el && !(now instanceof HTMLInputElement || now instanceof HTMLTextAreaElement)) {
|
|
543
|
+
el.focus({ preventScroll: true });
|
|
544
|
+
}
|
|
545
|
+
})
|
|
546
|
+
);
|
|
547
|
+
}
|
|
548
|
+
}
|
|
549
|
+
},
|
|
550
|
+
/* @__PURE__ */ React2.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 }),
|
|
551
|
+
/* @__PURE__ */ React2.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: !name.trim() }, labels.save)
|
|
552
|
+
);
|
|
553
|
+
}
|
|
554
|
+
function LoadCheck({ check, labels, onCancel, close, title, quiet = false }) {
|
|
555
|
+
const titleId = useId2();
|
|
556
|
+
const first = useRef(
|
|
557
|
+
/** @type {HTMLButtonElement | null} */
|
|
558
|
+
null
|
|
559
|
+
);
|
|
560
|
+
useEffect(() => {
|
|
561
|
+
if (!quiet) {
|
|
562
|
+
first.current?.focus({ preventScroll: true });
|
|
563
|
+
}
|
|
564
|
+
}, [quiet]);
|
|
565
|
+
return /* @__PURE__ */ React2.createElement("div", { className: "pk-load-check", role: "group", "aria-labelledby": titleId, "data-testid": "load-check" }, /* @__PURE__ */ React2.createElement("p", { id: titleId, className: "pk-load-check-title" }, /* @__PURE__ */ React2.createElement(Icon, { name: "info", size: 16 }), /* @__PURE__ */ React2.createElement("span", null, title ?? labels.loadCheckTitle)), /* @__PURE__ */ React2.createElement("ul", { className: "pk-load-check-lines" }, check.lines.map((line, i) => /* @__PURE__ */ React2.createElement("li", { key: i }, line))), /* @__PURE__ */ React2.createElement("div", { className: "pk-load-check-actions" }, check.switchTo ? /* @__PURE__ */ React2.createElement("button", { ref: first, type: "button", className: "pk-btn pk-primary", "data-autofocus": "", "data-testid": "load-switch", onClick: () => {
|
|
566
|
+
close();
|
|
567
|
+
check.switchTo?.run();
|
|
568
|
+
} }, fill(labels.switchAndLoad, { source: check.switchTo.name })) : null, /* @__PURE__ */ React2.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: () => {
|
|
569
|
+
close();
|
|
570
|
+
check.load();
|
|
571
|
+
} }, labels.loadAnyway), /* @__PURE__ */ React2.createElement("button", { type: "button", className: "pk-btn", "data-testid": "load-cancel", onClick: onCancel }, labels.cancel)), check.switchTo ? /* @__PURE__ */ React2.createElement("p", { className: "pk-hint" }, labels.switchStartsFresh) : null);
|
|
572
|
+
}
|
|
573
|
+
function LoadView({ labels, onLoadText, close }) {
|
|
574
|
+
const [text, setText] = useState2("");
|
|
575
|
+
const [problem, setProblem] = useState2(
|
|
576
|
+
/** @type {string | null} */
|
|
577
|
+
null
|
|
578
|
+
);
|
|
579
|
+
const [check, setCheck] = useState2(
|
|
580
|
+
/** @type {any} */
|
|
581
|
+
null
|
|
582
|
+
);
|
|
583
|
+
const [busy, setBusy] = useState2(false);
|
|
584
|
+
const file = useRef(
|
|
585
|
+
/** @type {HTMLInputElement | null} */
|
|
586
|
+
null
|
|
587
|
+
);
|
|
588
|
+
const field = useRef(
|
|
589
|
+
/** @type {HTMLTextAreaElement | null} */
|
|
590
|
+
null
|
|
591
|
+
);
|
|
592
|
+
const problemId = useId2();
|
|
593
|
+
useEffect(() => {
|
|
594
|
+
if (!check) {
|
|
595
|
+
field.current?.focus({ preventScroll: true });
|
|
596
|
+
}
|
|
597
|
+
}, [check]);
|
|
598
|
+
const load = async (value) => {
|
|
599
|
+
setBusy(true);
|
|
600
|
+
const outcome = await onLoadText(value);
|
|
601
|
+
setBusy(false);
|
|
602
|
+
if (typeof outcome === "string") {
|
|
603
|
+
setProblem(outcome);
|
|
604
|
+
} else if (outcome) {
|
|
605
|
+
setCheck(outcome);
|
|
606
|
+
} else {
|
|
607
|
+
close();
|
|
608
|
+
}
|
|
609
|
+
};
|
|
610
|
+
if (check) {
|
|
611
|
+
return /* @__PURE__ */ React2.createElement(LoadCheck, { check, labels, onCancel: () => setCheck(null), close });
|
|
612
|
+
}
|
|
613
|
+
return /* @__PURE__ */ React2.createElement(
|
|
614
|
+
"form",
|
|
615
|
+
{
|
|
616
|
+
className: "pk-inline-form pk-load-view",
|
|
617
|
+
onSubmit: (e) => {
|
|
618
|
+
e.preventDefault();
|
|
619
|
+
load(text);
|
|
620
|
+
}
|
|
621
|
+
},
|
|
622
|
+
/* @__PURE__ */ React2.createElement("p", { className: "pk-hint" }, labels.loadViewHint),
|
|
623
|
+
/* @__PURE__ */ React2.createElement(
|
|
624
|
+
ClearInput,
|
|
625
|
+
{
|
|
626
|
+
multiline: true,
|
|
627
|
+
value: text,
|
|
628
|
+
onChange: (v) => {
|
|
629
|
+
setText(v);
|
|
630
|
+
setProblem(null);
|
|
631
|
+
},
|
|
632
|
+
clearLabel: labels.clearText,
|
|
633
|
+
"aria-label": labels.loadViewText,
|
|
634
|
+
placeholder: labels.loadViewText,
|
|
635
|
+
rows: 4,
|
|
636
|
+
spellCheck: false,
|
|
637
|
+
"aria-invalid": problem ? true : void 0,
|
|
638
|
+
"aria-describedby": problem ? problemId : void 0,
|
|
639
|
+
"data-testid": "load-view-text",
|
|
640
|
+
inputRef: field
|
|
641
|
+
}
|
|
642
|
+
),
|
|
643
|
+
problem ? /* @__PURE__ */ React2.createElement("p", { id: problemId, className: "pk-form-problem", role: "alert", "data-testid": "load-view-problem" }, problem) : null,
|
|
644
|
+
/* @__PURE__ */ React2.createElement(
|
|
645
|
+
"input",
|
|
646
|
+
{
|
|
647
|
+
ref: file,
|
|
648
|
+
type: "file",
|
|
649
|
+
accept: "application/json,.json",
|
|
650
|
+
className: "pk-sr",
|
|
651
|
+
tabIndex: -1,
|
|
652
|
+
"aria-hidden": "true",
|
|
653
|
+
"data-testid": "load-view-file",
|
|
654
|
+
onChange: async (e) => {
|
|
655
|
+
const chosen = e.target.files?.[0];
|
|
656
|
+
e.target.value = "";
|
|
657
|
+
if (chosen) {
|
|
658
|
+
let content;
|
|
659
|
+
try {
|
|
660
|
+
content = chosen.size > VIEW_FILE_LIMITS.text ? null : await chosen.text();
|
|
661
|
+
} catch {
|
|
662
|
+
content = null;
|
|
663
|
+
}
|
|
664
|
+
if (content === null) {
|
|
665
|
+
setProblem(chosen.size > VIEW_FILE_LIMITS.text ? labels.viewFailed.tooLarge : labels.viewFailed.file);
|
|
666
|
+
} else {
|
|
667
|
+
load(content);
|
|
668
|
+
}
|
|
669
|
+
}
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
),
|
|
673
|
+
/* @__PURE__ */ React2.createElement("button", { type: "button", className: "pk-btn", onClick: () => file.current?.click(), disabled: busy, "data-testid": "load-view-choose" }, /* @__PURE__ */ React2.createElement(Icon, { name: "file" }), /* @__PURE__ */ React2.createElement("span", { className: "pk-btn-text" }, labels.chooseFile)),
|
|
674
|
+
/* @__PURE__ */ React2.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: busy || !text.trim(), "data-testid": "load-view-apply" }, labels.load)
|
|
675
|
+
);
|
|
676
|
+
}
|
|
677
|
+
function ShareSection({ labels, share, close }) {
|
|
678
|
+
const [loading, setLoading] = useState2(false);
|
|
679
|
+
if (loading) {
|
|
680
|
+
return /* @__PURE__ */ React2.createElement(Section, { title: labels.loadView.replace(/…$/, "") }, /* @__PURE__ */ React2.createElement(LoadView, { labels, onLoadText: share.loadText, close }));
|
|
681
|
+
}
|
|
682
|
+
return /* @__PURE__ */ React2.createElement(Section, { title: labels.share, id: "share" }, share.canLink ? /* @__PURE__ */ React2.createElement(Option, { icon: "link", onSelect: () => {
|
|
683
|
+
close();
|
|
684
|
+
share.copyLink();
|
|
685
|
+
}, testId: "copy-link" }, labels.copyLink) : null, /* @__PURE__ */ React2.createElement(Option, { icon: "copy", onSelect: () => {
|
|
686
|
+
close();
|
|
687
|
+
share.copyJson();
|
|
688
|
+
}, testId: "copy-json" }, labels.copyJson), /* @__PURE__ */ React2.createElement(Option, { icon: "download", onSelect: () => {
|
|
689
|
+
close();
|
|
690
|
+
share.download();
|
|
691
|
+
}, testId: "download-view" }, labels.downloadView), /* @__PURE__ */ React2.createElement(Option, { icon: "upload", onSelect: () => setLoading(true), testId: "load-view" }, labels.loadView), /* @__PURE__ */ React2.createElement("p", { className: "pk-hint pk-menu-hint", "data-testid": "share-privacy" }, labels.sharePrivacy));
|
|
692
|
+
}
|
|
693
|
+
function viewActions(ctx, labels) {
|
|
694
|
+
const run = (task, done, failed, rejected, name) => Promise.resolve().then(task).then(
|
|
695
|
+
() => {
|
|
696
|
+
ctx.announce(fill(done, { name }));
|
|
697
|
+
return true;
|
|
698
|
+
},
|
|
699
|
+
(e) => {
|
|
700
|
+
ctx.announce(hostFailure(failed, rejected, e), { tone: "error" });
|
|
701
|
+
return false;
|
|
702
|
+
}
|
|
703
|
+
);
|
|
704
|
+
const write = (change) => storeViews(ctx.viewsText, change, labels, ctx.locale, ctx.keep);
|
|
705
|
+
return {
|
|
706
|
+
save: ctx.onSave || ctx.store ? (name) => run(() => ctx.onSave ? ctx.onSave(name, ctx.view, { scope: "user" }) : write({ name, view: ctx.view, sourceId: ctx.sourceId }), labels.toastSaved, labels.toastSaveFailed, labels.toastSaveRejected, name).then(
|
|
707
|
+
(ok) => ok && ctx.onSaved()
|
|
708
|
+
) : null,
|
|
709
|
+
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,
|
|
710
|
+
publish: ctx.onPublish ? (t) => run(() => ctx.onPublish(t.name, ctx.normalized(t.view)), labels.toastPublished, labels.toastPublishFailed, labels.toastPublishRejected, t.name) : null
|
|
711
|
+
};
|
|
712
|
+
}
|
|
713
|
+
function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
714
|
+
const { save: onSave, remove: onDelete, publish: onPublish } = viewActions(actions, labels);
|
|
715
|
+
const store = actions.store && !actions.onSave;
|
|
716
|
+
const [confirming, setConfirming] = useState2(
|
|
717
|
+
/** @type {{ at: number, kind: "delete" | "publish" } | null} */
|
|
718
|
+
null
|
|
719
|
+
);
|
|
720
|
+
const [busy, setBusy] = useState2(false);
|
|
721
|
+
const box = useRef(
|
|
722
|
+
/** @type {HTMLDivElement | null} */
|
|
723
|
+
null
|
|
724
|
+
);
|
|
725
|
+
const [refocus, setRefocus] = useState2(
|
|
726
|
+
/** @type {{ key: string, place: number } | null} */
|
|
727
|
+
null
|
|
728
|
+
);
|
|
729
|
+
useEffect(() => {
|
|
730
|
+
share?.prepare?.();
|
|
731
|
+
}, [share]);
|
|
732
|
+
useEffect(() => {
|
|
733
|
+
if (refocus && box.current) {
|
|
734
|
+
const entries = [...box.current.querySelectorAll("[data-pk-entry]")];
|
|
735
|
+
const entry2 = entries.find((el) => el.getAttribute("data-pk-entry") === refocus.key) ?? entries[Math.min(refocus.place, entries.length - 1)];
|
|
736
|
+
(entry2 ?? box.current).querySelector("[data-pk-option]")?.focus({ preventScroll: true });
|
|
737
|
+
setRefocus(null);
|
|
738
|
+
}
|
|
739
|
+
}, [refocus, templates]);
|
|
740
|
+
const keyOf2 = (t) => `${t.scope}:${t.at ?? ""}:${t.name}`;
|
|
741
|
+
useEffect(() => {
|
|
742
|
+
if (confirming) {
|
|
743
|
+
box.current?.querySelector(".pk-confirm [data-autofocus]")?.focus({ preventScroll: true });
|
|
744
|
+
}
|
|
745
|
+
}, [confirming]);
|
|
746
|
+
const answer = (t) => {
|
|
747
|
+
setConfirming(null);
|
|
748
|
+
const entries = box.current ? [...box.current.querySelectorAll("[data-pk-entry], .pk-confirm")] : [];
|
|
749
|
+
setRefocus({ key: keyOf2(t), place: Math.max(0, entries.findIndex((el) => el.classList.contains("pk-confirm"))) });
|
|
750
|
+
};
|
|
751
|
+
const entry = (t, at) => {
|
|
752
|
+
if (confirming && confirming.at === at) {
|
|
753
|
+
const kind = confirming.kind;
|
|
754
|
+
const publish = kind === "publish";
|
|
755
|
+
const question = fill(publish ? labels.publishConfirm : labels.deleteConfirm, { name: t.name });
|
|
756
|
+
return /* @__PURE__ */ React2.createElement("div", { key: `${at}:${t.name}`, className: "pk-template pk-confirm", role: "group", "aria-label": question }, /* @__PURE__ */ React2.createElement("span", { className: "pk-confirm-text" }, question), /* @__PURE__ */ React2.createElement(
|
|
757
|
+
"button",
|
|
758
|
+
{
|
|
759
|
+
type: "button",
|
|
760
|
+
className: publish ? "pk-btn pk-primary" : "pk-btn pk-danger-btn",
|
|
761
|
+
disabled: busy,
|
|
762
|
+
"data-autofocus": "",
|
|
763
|
+
"data-testid": `confirm-${kind}`,
|
|
764
|
+
onClick: async () => {
|
|
765
|
+
setBusy(true);
|
|
766
|
+
const ok = await (publish ? onPublish : onDelete)?.(t);
|
|
767
|
+
setBusy(false);
|
|
768
|
+
if (ok) {
|
|
769
|
+
answer(t);
|
|
770
|
+
}
|
|
771
|
+
}
|
|
772
|
+
},
|
|
773
|
+
publish ? labels.publishAction : labels.deleteAction
|
|
774
|
+
), /* @__PURE__ */ React2.createElement("button", { type: "button", className: "pk-btn", disabled: busy, onClick: () => answer(t) }, labels.cancel));
|
|
775
|
+
}
|
|
776
|
+
const button = (kind, icon, text) => /* @__PURE__ */ React2.createElement("button", { type: "button", className: "pk-icon-btn", onClick: () => setConfirming({ at, kind }), "aria-label": text, title: text, "data-testid": `${kind}-view-${t.name}` }, /* @__PURE__ */ React2.createElement(Icon, { name: icon }));
|
|
777
|
+
return /* @__PURE__ */ React2.createElement("div", { key: `${at}:${t.name}`, className: "pk-template", "data-pk-entry": keyOf2(t) }, /* @__PURE__ */ React2.createElement(Option, { icon: "bookmark", onSelect: () => {
|
|
778
|
+
close();
|
|
779
|
+
onLoad(t);
|
|
780
|
+
}, 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__ */ React2.createElement(SettingInfo, { id: "sharedView", name: t.name }) : null);
|
|
781
|
+
};
|
|
782
|
+
const sharedChange = Boolean(onPublish) || templates.some((t) => t.scope === "shared" && t.deletable);
|
|
783
|
+
const group = (scope) => templates.map((t, at) => t.scope === scope ? entry(t, at) : null).filter(Boolean);
|
|
784
|
+
const shared = group("shared");
|
|
785
|
+
const mine = group("user");
|
|
786
|
+
return /* @__PURE__ */ React2.createElement("div", { ref: box, className: "pk-views" }, shared.length ? /* @__PURE__ */ React2.createElement(Section, { title: labels.sharedViews, id: "sharedViews" }, shared) : null, mine.length || onSave || !shared.length ? /* @__PURE__ */ React2.createElement(Section, { title: labels.myViews, id: "myViews" }, mine.length || onSave ? mine : /* @__PURE__ */ React2.createElement("p", { className: "pk-hint" }, labels.noViews), onSave ? /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement("div", { className: "pk-subtitle" }, labels.saveView), /* @__PURE__ */ React2.createElement(SaveView, { labels, onSave })) : null, store ? /* @__PURE__ */ React2.createElement("p", { className: "pk-hint pk-menu-hint", "data-testid": "store-note" }, labels.storeNote) : null) : null, share ? /* @__PURE__ */ React2.createElement(ShareSection, { labels, share, close }) : null);
|
|
787
|
+
}
|
|
788
|
+
function ExportOption({ icon, text, info, onSelect, testId, disabled, reason }) {
|
|
789
|
+
const option = /* @__PURE__ */ React2.createElement(Option, { icon, onSelect, disabled, reason, testId }, text);
|
|
790
|
+
return info ? /* @__PURE__ */ React2.createElement("div", { className: "pk-setting-row" }, option, /* @__PURE__ */ React2.createElement(SettingInfo, { id: (
|
|
791
|
+
/** @type {any} */
|
|
792
|
+
info
|
|
793
|
+
), name: text })) : option;
|
|
794
|
+
}
|
|
795
|
+
function ExportPanel({ labels, onExport, chartReady, display, prepare, close }) {
|
|
796
|
+
useEffect(() => {
|
|
797
|
+
prepare();
|
|
798
|
+
}, [prepare]);
|
|
799
|
+
const run = (kind) => () => {
|
|
800
|
+
close();
|
|
801
|
+
onExport(kind);
|
|
802
|
+
};
|
|
803
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(Section, { title: labels.exportDownload, id: "exportDownload" }, /* @__PURE__ */ React2.createElement(ExportOption, { icon: "file", text: labels.exportXlsx, info: "exportXlsx", onSelect: run("xlsx"), testId: "export-xlsx" }), /* @__PURE__ */ React2.createElement(ExportOption, { icon: "file", text: labels.exportCsv, info: "exportCsv", onSelect: run("csv"), testId: "export-csv" }), /* @__PURE__ */ React2.createElement(ExportOption, { icon: "image", text: labels.exportPng, disabled: !chartReady, reason: display !== "chart" ? labels.exportPngNeedsChart : void 0, onSelect: run("png"), testId: "export-png" })), /* @__PURE__ */ React2.createElement(Section, { title: labels.exportCopy, id: "exportCopy" }, /* @__PURE__ */ React2.createElement(ExportOption, { icon: "copy", text: labels.copyTable, info: "copyTable", onSelect: run("copy-table"), testId: "export-copy-table" }), /* @__PURE__ */ React2.createElement(ExportOption, { icon: "copy", text: labels.copyDataJson, info: "copyDataJson", onSelect: run("copy-json"), testId: "export-copy-json" })));
|
|
804
|
+
}
|
|
805
|
+
|
|
806
|
+
// src/filter.jsx
|
|
807
|
+
import React3, { useMemo, useState as useState3 } from "react";
|
|
808
|
+
import { CATALOG as CATALOG2, fieldItems, fieldLabel as fieldLabel2 } from "pivotkit-core";
|
|
809
|
+
var FILTER_LIST_MAX = 300;
|
|
810
|
+
var keyOf = (v) => JSON.stringify(v);
|
|
811
|
+
function FilterBody({ view: current, base, field, encoded, locale, labels, commit, close }) {
|
|
812
|
+
const view = base ?? current;
|
|
813
|
+
const info = useMemo(() => fieldItems(encoded, field, { view, locale, labels: labels.core }), [encoded, field, view, locale, labels]);
|
|
814
|
+
const all = useMemo(() => info ? info.items.map((i) => i.value) : [], [info]);
|
|
815
|
+
const [selected, setSelected] = useState3(() => new Set(selectedItems(view, field, all).map(keyOf)));
|
|
816
|
+
const [query, setQuery] = useState3("");
|
|
817
|
+
const label = filtersOf(view, field, ["label"])[0];
|
|
818
|
+
const [op, setOp] = useState3(label?.op ?? "");
|
|
819
|
+
const [text, setText] = useState3(label?.value ?? "");
|
|
820
|
+
if (!info) {
|
|
821
|
+
return null;
|
|
822
|
+
}
|
|
823
|
+
const q = query.trim().toLocaleLowerCase();
|
|
824
|
+
const matching = q ? info.items.filter((i) => i.label.toLocaleLowerCase().includes(q)) : info.items;
|
|
825
|
+
const shown = matching.slice(0, FILTER_LIST_MAX);
|
|
826
|
+
const setAll = (on) => {
|
|
827
|
+
const next = new Set(selected);
|
|
828
|
+
for (const i of matching) {
|
|
829
|
+
if (on) {
|
|
830
|
+
next.add(keyOf(i.value));
|
|
831
|
+
} else {
|
|
832
|
+
next.delete(keyOf(i.value));
|
|
833
|
+
}
|
|
834
|
+
}
|
|
835
|
+
setSelected(next);
|
|
836
|
+
};
|
|
837
|
+
const toggle = (v) => {
|
|
838
|
+
const next = new Set(selected);
|
|
839
|
+
const k = keyOf(v);
|
|
840
|
+
if (next.has(k)) {
|
|
841
|
+
next.delete(k);
|
|
842
|
+
} else {
|
|
843
|
+
next.add(k);
|
|
844
|
+
}
|
|
845
|
+
setSelected(next);
|
|
846
|
+
};
|
|
847
|
+
const name = fieldLabel2(field, labels.core);
|
|
848
|
+
const apply = () => {
|
|
849
|
+
let next = setItemFilter(view, field, all.filter((v) => selected.has(keyOf(v))), all);
|
|
850
|
+
next = setLabelFilter(next, field, op ? { op, value: text } : null);
|
|
851
|
+
close();
|
|
852
|
+
commit(next, { step: "filter", field: name });
|
|
853
|
+
};
|
|
854
|
+
const filtering = !base && hasFilter(view, field);
|
|
855
|
+
const kind = conditionKind(encoded, view, field) ?? (label ? "text" : null);
|
|
856
|
+
return /* @__PURE__ */ React3.createElement(
|
|
857
|
+
"form",
|
|
858
|
+
{
|
|
859
|
+
className: "pk-filter",
|
|
860
|
+
onSubmit: (e) => {
|
|
861
|
+
e.preventDefault();
|
|
862
|
+
apply();
|
|
863
|
+
}
|
|
864
|
+
},
|
|
865
|
+
/* @__PURE__ */ React3.createElement("div", { className: "pk-popover-head" }, /* @__PURE__ */ React3.createElement("h3", null, fill(labels.filterTitle, { field: name })), /* @__PURE__ */ React3.createElement("span", { className: "pk-muted" }, fill(labels.selected, { count: selected.size.toLocaleString(locale) }))),
|
|
866
|
+
filtering ? /* @__PURE__ */ React3.createElement(
|
|
867
|
+
"button",
|
|
868
|
+
{
|
|
869
|
+
type: "button",
|
|
870
|
+
className: "pk-btn pk-remove-filter",
|
|
871
|
+
onClick: () => {
|
|
872
|
+
close();
|
|
873
|
+
commit(removeFilters(view, field), { step: "filter", field: name });
|
|
874
|
+
},
|
|
875
|
+
"data-testid": "filter-remove"
|
|
876
|
+
},
|
|
877
|
+
/* @__PURE__ */ React3.createElement(Icon, { name: "x" }),
|
|
878
|
+
/* @__PURE__ */ React3.createElement("span", { className: "pk-btn-text" }, labels.removeFilter)
|
|
879
|
+
) : null,
|
|
880
|
+
/* @__PURE__ */ React3.createElement("label", { className: "pk-search" }, /* @__PURE__ */ React3.createElement(Icon, { name: "search" }), /* @__PURE__ */ React3.createElement("span", { className: "pk-sr" }, labels.searchValues), /* @__PURE__ */ React3.createElement(ClearInput, { type: "search", value: query, placeholder: labels.searchValues, onChange: setQuery, clearLabel: labels.clearText, "data-autofocus": "", "data-testid": "filter-search" })),
|
|
881
|
+
/* @__PURE__ */ React3.createElement("div", { className: "pk-filter-actions" }, /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-link", onClick: () => setAll(true) }, labels.selectAll), /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-link", onClick: () => setAll(false) }, labels.selectNone)),
|
|
882
|
+
/* @__PURE__ */ React3.createElement("div", { className: "pk-filter-body" }, /* @__PURE__ */ React3.createElement("ul", { className: "pk-values", role: "list" }, shown.map((i) => {
|
|
883
|
+
const k = keyOf(i.value);
|
|
884
|
+
return /* @__PURE__ */ React3.createElement("li", { key: k, className: "pk-value" }, /* @__PURE__ */ React3.createElement("label", null, /* @__PURE__ */ React3.createElement("input", { type: "checkbox", checked: selected.has(k), onChange: () => toggle(i.value) }), /* @__PURE__ */ React3.createElement("span", { className: "pk-value-label" }, i.label), /* @__PURE__ */ React3.createElement("span", { className: "pk-count" }, i.count.toLocaleString(locale))), /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-link pk-only", onClick: () => setSelected(/* @__PURE__ */ new Set([k])), "aria-label": `${labels.onlyThis}: ${i.label}` }, labels.onlyThis));
|
|
885
|
+
})), matching.length > shown.length ? /* @__PURE__ */ React3.createElement("p", { className: "pk-hint" }, fill(labels.valuesShown, { shown: shown.length, total: matching.length.toLocaleString(locale) })) : null, kind ? /* @__PURE__ */ React3.createElement("fieldset", { className: "pk-condition" }, /* @__PURE__ */ React3.createElement("legend", null, kind === "number" ? labels.conditionNumber : labels.condition), /* @__PURE__ */ React3.createElement("select", { value: op, onChange: (e) => setOp(e.target.value), "aria-label": kind === "number" ? labels.conditionNumber : labels.condition }, /* @__PURE__ */ React3.createElement("option", { value: "" }, labels.conditionNone), CATALOG2.labelOps.map((o) => /* @__PURE__ */ React3.createElement("option", { key: o, value: o }, labels.labelOps[o] ?? o))), op ? /* @__PURE__ */ React3.createElement(
|
|
886
|
+
ClearInput,
|
|
887
|
+
{
|
|
888
|
+
type: "text",
|
|
889
|
+
value: text,
|
|
890
|
+
onChange: setText,
|
|
891
|
+
onClear: () => {
|
|
892
|
+
if (!base && filtersOf(view, field, ["label"]).length) {
|
|
893
|
+
commit(setLabelFilter(view, field, null), { step: "filter", field: name });
|
|
894
|
+
}
|
|
895
|
+
},
|
|
896
|
+
clearLabel: labels.clearText,
|
|
897
|
+
"aria-label": labels.conditionValue,
|
|
898
|
+
placeholder: labels.conditionValue,
|
|
899
|
+
maxLength: 1e3,
|
|
900
|
+
"data-testid": "filter-condition-text"
|
|
901
|
+
}
|
|
902
|
+
) : null) : null),
|
|
903
|
+
/* @__PURE__ */ React3.createElement("div", { className: "pk-popover-foot" }, /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-btn", onClick: close }, labels.cancel), /* @__PURE__ */ React3.createElement("button", { type: "submit", className: "pk-btn pk-primary", "data-testid": "filter-apply" }, labels.apply))
|
|
904
|
+
);
|
|
905
|
+
}
|
|
906
|
+
function FilterPopover({ target, onClose, view, encoded, locale, labels, commit }) {
|
|
907
|
+
const anchor = useMemo(() => ({ current: target ? target.anchor : null }), [target]);
|
|
908
|
+
return /* @__PURE__ */ React3.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__ */ React3.createElement(FilterBody, { key: target.field, view, base: target.base, field: target.field, encoded, locale, labels, commit, close: onClose }) : null);
|
|
909
|
+
}
|
|
910
|
+
|
|
911
|
+
// src/drill-panel.jsx
|
|
912
|
+
import React4, { useContext, useEffect as useEffect2, useId as useId3, useRef as useRef2, useState as useState4 } from "react";
|
|
913
|
+
|
|
914
|
+
// src/export-run.js
|
|
915
|
+
import { toGrid } from "pivotkit-core";
|
|
916
|
+
var XLSX_TYPE = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
|
|
917
|
+
var exporters = null;
|
|
918
|
+
var pending = null;
|
|
919
|
+
function loadExporters() {
|
|
920
|
+
pending ??= import("pivotkit-core/export").then(
|
|
921
|
+
(m) => {
|
|
922
|
+
exporters = m;
|
|
923
|
+
return m;
|
|
924
|
+
},
|
|
925
|
+
(error) => {
|
|
926
|
+
pending = null;
|
|
927
|
+
throw error;
|
|
928
|
+
}
|
|
929
|
+
);
|
|
930
|
+
return pending;
|
|
931
|
+
}
|
|
932
|
+
var exportersNow = () => exporters;
|
|
933
|
+
var prepareExporters = () => void loadExporters().catch(() => void 0);
|
|
934
|
+
function deliver(blob, { doc, onExport, ...file }) {
|
|
935
|
+
if (onExport?.({ ...file, blob }) === false) {
|
|
936
|
+
return false;
|
|
937
|
+
}
|
|
938
|
+
saveBlob(blob, file.fileName, doc);
|
|
939
|
+
return true;
|
|
940
|
+
}
|
|
941
|
+
async function copyOut(text, { type, container, onExport, ...file }) {
|
|
942
|
+
if (onExport?.({ ...file, blob: new Blob([text], { type }), text }) === false) {
|
|
943
|
+
return "kept";
|
|
944
|
+
}
|
|
945
|
+
return await copyText(text, container) ? "copied" : "blocked";
|
|
946
|
+
}
|
|
947
|
+
async function runExport(kind, { fileName, result, locale, labels, limits, root, chartRef, announce, onExport }) {
|
|
948
|
+
labels = menuLabels(labels);
|
|
949
|
+
const base = safeFileName(fileName);
|
|
950
|
+
const doc = root.current?.ownerDocument;
|
|
951
|
+
try {
|
|
952
|
+
if (kind === "png") {
|
|
953
|
+
const surface = root.current ? getComputedStyle(root.current).getPropertyValue("--pk-surface").trim() : "";
|
|
954
|
+
const url = chartRef.current?.getDataURL({ type: "png", pixelRatio: 2, backgroundColor: surface || void 0 });
|
|
955
|
+
const file2 = `${base}.png`;
|
|
956
|
+
if (url && deliver(dataUrlToBlob(url), { kind, fileName: file2, doc, onExport })) {
|
|
957
|
+
announce(fill(labels.toastExported, { file: file2 }));
|
|
958
|
+
}
|
|
959
|
+
return;
|
|
960
|
+
}
|
|
961
|
+
if (!result) {
|
|
962
|
+
return;
|
|
963
|
+
}
|
|
964
|
+
const m = exporters ?? await loadExporters();
|
|
965
|
+
const grid = toGrid(result, { locale, labels: labels.core, limits });
|
|
966
|
+
if (kind === "copy-table" || kind === "copy-json") {
|
|
967
|
+
const json = kind === "copy-json";
|
|
968
|
+
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 });
|
|
969
|
+
if (done !== "kept") {
|
|
970
|
+
announce(done === "copied" ? json ? labels.toastDataCopied : labels.toastTableCopied : labels.toastCopyBlocked, done === "copied" ? void 0 : { tone: "error" });
|
|
971
|
+
}
|
|
972
|
+
return;
|
|
973
|
+
}
|
|
974
|
+
const file = `${base}.${kind}`;
|
|
975
|
+
const bytes = kind === "xlsx" ? m.toXlsx(grid, { sheetName: base }) : m.toCsvBytes(grid, { bom: true });
|
|
976
|
+
if (deliver(new Blob([
|
|
977
|
+
/** @type {BlobPart} */
|
|
978
|
+
bytes
|
|
979
|
+
], { type: kind === "xlsx" ? XLSX_TYPE : "text/csv;charset=utf-8" }), { kind, fileName: file, doc, onExport })) {
|
|
980
|
+
announce(fill(labels.toastExported, { file }));
|
|
981
|
+
}
|
|
982
|
+
} catch (e) {
|
|
983
|
+
announce(fill(labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
|
|
984
|
+
}
|
|
985
|
+
}
|
|
986
|
+
|
|
987
|
+
// src/drill-export.js
|
|
988
|
+
function rowsText({ shown, count }, labels, locale) {
|
|
989
|
+
return shown < count ? fill(labels.drillPart, { shown: shown.toLocaleString(locale), count: count.toLocaleString(locale) }) : plural(labels.drillCount, count, { lang: labels.lang, locale });
|
|
990
|
+
}
|
|
991
|
+
async function exportDrill(kind, { drill, encoded, labels, onExport, announce, root }) {
|
|
992
|
+
const { locale } = drill;
|
|
993
|
+
const part = { shown: drill.rows.length, count: drill.count };
|
|
994
|
+
const rows = rowsText(part, labels, locale);
|
|
995
|
+
const base = safeFileName(drill.name);
|
|
996
|
+
try {
|
|
997
|
+
const m = exportersNow() ?? await loadExporters();
|
|
998
|
+
if (kind === "drill-copy" || kind === "drill-json") {
|
|
999
|
+
const json = kind === "drill-json";
|
|
1000
|
+
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]);
|
|
1001
|
+
const done = await copyOut(text, { kind, fileName: `${base}.${json ? "json" : "tsv"}`, type: json ? "application/json" : "text/tab-separated-values", container: root, onExport, rows: part });
|
|
1002
|
+
if (done !== "kept") {
|
|
1003
|
+
announce(done === "copied" ? fill(json ? labels.drillCopiedJson : labels.drillCopied, { rows }) : labels.toastCopyBlocked, done === "copied" ? void 0 : { tone: "error" });
|
|
1004
|
+
}
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
const xlsx = kind === "drill-xlsx";
|
|
1008
|
+
const fields = Object.fromEntries(drill.columns.map((c) => [c.name, c.label ?? c.name]));
|
|
1009
|
+
const options = { locale, formats: drill.formats, labels: { fields, true: labels.core.true, false: labels.core.false } };
|
|
1010
|
+
const file = `${base}.${xlsx ? "xlsx" : "csv"}`;
|
|
1011
|
+
const bytes = xlsx ? m.rowsToXlsx(encoded, drill.indices, { ...options, sheetName: drill.name }) : m.rowsToCsvBytes(encoded, drill.indices, options);
|
|
1012
|
+
const blob = new Blob([
|
|
1013
|
+
/** @type {BlobPart} */
|
|
1014
|
+
bytes
|
|
1015
|
+
], { type: xlsx ? XLSX_TYPE : "text/csv;charset=utf-8" });
|
|
1016
|
+
if (deliver(blob, { kind, fileName: file, doc: root?.ownerDocument, onExport, rows: part })) {
|
|
1017
|
+
announce(fill(labels.drillExported, { file, rows }));
|
|
1018
|
+
}
|
|
1019
|
+
} catch (e) {
|
|
1020
|
+
announce(fill(labels.toastExportFailed, { message: messageOf(e) }), { tone: "error" });
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
// src/drill-panel.jsx
|
|
1025
|
+
function DrillPanel({ drill, onClose, labels, locale, exportContext }) {
|
|
1026
|
+
const id = useId3();
|
|
1027
|
+
const panel = useRef2(
|
|
1028
|
+
/** @type {HTMLDivElement | null} */
|
|
1029
|
+
null
|
|
1030
|
+
);
|
|
1031
|
+
const [big, setBig] = useState4(false);
|
|
1032
|
+
const narrow = useContext(LayerContext).size === "narrow";
|
|
1033
|
+
const { onKeyDown } = useModal(panel, Boolean(drill), big ? () => setBig(false) : onClose);
|
|
1034
|
+
useEffect2(() => {
|
|
1035
|
+
if (drill && exportContext) {
|
|
1036
|
+
prepareExporters();
|
|
1037
|
+
}
|
|
1038
|
+
}, [drill, exportContext]);
|
|
1039
|
+
if (!drill) {
|
|
1040
|
+
return null;
|
|
1041
|
+
}
|
|
1042
|
+
const n = drill.count.toLocaleString(locale);
|
|
1043
|
+
const partial = drill.rows.length < drill.count;
|
|
1044
|
+
const run = (kind, close) => () => {
|
|
1045
|
+
close();
|
|
1046
|
+
if (exportContext) {
|
|
1047
|
+
void exportDrill(kind, { drill, labels, ...exportContext, root: exportContext.root.current });
|
|
1048
|
+
}
|
|
1049
|
+
};
|
|
1050
|
+
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement("div", { className: "pk-scrim pk-drill-scrim", onClick: onClose, "aria-hidden": "true" }), /* @__PURE__ */ React4.createElement(
|
|
1051
|
+
"div",
|
|
1052
|
+
{
|
|
1053
|
+
className: `pk-drill${big && !narrow ? " pk-drill-big" : ""}`,
|
|
1054
|
+
role: "dialog",
|
|
1055
|
+
"aria-modal": "true",
|
|
1056
|
+
"aria-labelledby": id,
|
|
1057
|
+
"data-testid": "drill-panel",
|
|
1058
|
+
"data-pk-enlarged": big && !narrow ? "" : void 0,
|
|
1059
|
+
ref: panel,
|
|
1060
|
+
tabIndex: -1,
|
|
1061
|
+
onKeyDown: (e) => {
|
|
1062
|
+
if (e.target instanceof Node && panel.current?.contains(e.target)) {
|
|
1063
|
+
onKeyDown(e);
|
|
1064
|
+
}
|
|
1065
|
+
}
|
|
1066
|
+
},
|
|
1067
|
+
/* @__PURE__ */ React4.createElement("div", { className: "pk-drill-head" }, /* @__PURE__ */ React4.createElement("div", { className: "pk-drill-heading" }, /* @__PURE__ */ React4.createElement("h2", { id }, labels.drillTitle), /* @__PURE__ */ React4.createElement("p", { className: "pk-drill-path" }, drill.title), /* @__PURE__ */ React4.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__ */ React4.createElement("div", { className: "pk-drill-actions" }, exportContext ? /* @__PURE__ */ React4.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__ */ React4.createElement(React4.Fragment, null, partial ? /* @__PURE__ */ React4.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__ */ React4.createElement(Section, { title: labels.exportCopy, id: "exportCopy" }, /* @__PURE__ */ React4.createElement(ExportOption, { icon: "copy", text: labels.drillCopy, info: "drillCopy", onSelect: run("drill-copy", close), testId: "drill-copy" }), /* @__PURE__ */ React4.createElement(ExportOption, { icon: "copy", text: labels.drillJson, info: "drillJson", onSelect: run("drill-json", close), testId: "drill-json" })), /* @__PURE__ */ React4.createElement(Section, { title: labels.exportDownload, id: "exportDownload" }, /* @__PURE__ */ React4.createElement(ExportOption, { icon: "file", text: labels.drillCsv, onSelect: run("drill-csv", close), testId: "drill-csv" }), /* @__PURE__ */ React4.createElement(ExportOption, { icon: "file", text: labels.drillXlsx, onSelect: run("drill-xlsx", close), testId: "drill-xlsx" })))) : null, narrow ? null : /* @__PURE__ */ React4.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__ */ React4.createElement(Icon, { name: "enlarge", size: 14 }), /* @__PURE__ */ React4.createElement("span", { className: "pk-btn-text" }, big ? labels.reduce : labels.enlarge)), /* @__PURE__ */ React4.createElement("button", { type: "button", className: "pk-icon-btn", onClick: onClose, "data-autofocus": "", "aria-label": labels.close, title: labels.close }, /* @__PURE__ */ React4.createElement(Icon, { name: "x" })))),
|
|
1068
|
+
/* @__PURE__ */ React4.createElement("div", { className: "pk-drill-body", tabIndex: 0, "aria-label": drill.title }, /* @__PURE__ */ React4.createElement("table", { className: "pk-drill-table" }, /* @__PURE__ */ React4.createElement("thead", null, /* @__PURE__ */ React4.createElement("tr", null, drill.columns.map((c) => /* @__PURE__ */ React4.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__ */ React4.createElement("tbody", null, drill.rows.map((row, i) => /* @__PURE__ */ React4.createElement("tr", { key: i }, drill.columns.map((c, k) => /* @__PURE__ */ React4.createElement("td", { key: c.name, className: c.numeric ? "pk-num" : void 0 }, c.numeric || row[k].length < 24 ? row[k] : /* @__PURE__ */ React4.createElement("div", { className: "pk-drill-text" }, row[k]))))))))
|
|
1069
|
+
));
|
|
1070
|
+
}
|
|
1071
|
+
export {
|
|
1072
|
+
AxisMenu,
|
|
1073
|
+
ChartTypePanel,
|
|
1074
|
+
DrillPanel,
|
|
1075
|
+
ExportPanel,
|
|
1076
|
+
FilterPopover,
|
|
1077
|
+
LoadCheck,
|
|
1078
|
+
OptionsPanel,
|
|
1079
|
+
ValueMenu,
|
|
1080
|
+
ViewsPanel,
|
|
1081
|
+
menuLabels,
|
|
1082
|
+
prepareExporters,
|
|
1083
|
+
runExport,
|
|
1084
|
+
storedViews
|
|
1085
|
+
};
|