pivotkit-react 0.1.0 → 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 +143 -1
- package/README.md +48 -298
- package/dist/chunks/chunk-53ZMK4BH.js +177 -0
- package/dist/chunks/{chunk-ILHFIV2P.js → chunk-F6MVUAQD.js} +35 -78
- 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-KKJO36W5.js → chunk-X7H7BAVT.js} +243 -324
- package/dist/chunks/unused-texts-YTNJCFFC.js +10 -0
- package/dist/chunks/unused-texts-de-SGOHV4N7.js +6 -0
- package/dist/echarts.js +96 -11
- package/dist/index.js +619 -527
- package/dist/labels.js +13 -4
- package/dist/menu-texts-de.js +6 -0
- package/dist/menus.js +787 -191
- package/dist/styles.css +113 -31
- package/package.json +2 -2
- package/types/chart-layout.d.ts +111 -0
- package/types/chart-types.d.ts +0 -91
- package/types/drill-panel.d.ts +5 -22
- package/types/drill-table.d.ts +71 -0
- package/types/drill.d.ts +0 -36
- package/types/help.d.ts +21 -0
- package/types/icons.d.ts +4 -0
- package/types/labels.d.ts +43 -101
- package/types/lazy-menus.d.ts +16 -4
- package/types/menu-labels-de.d.ts +2 -0
- package/types/menu-labels.d.ts +71 -9
- package/types/menu-ops.d.ts +145 -0
- package/types/menu-texts.d.ts +2 -0
- package/types/menus.d.ts +1 -1
- package/types/names.d.ts +19 -19
- package/types/overflow.d.ts +4 -1
- package/types/popover.d.ts +10 -6
- package/types/section.d.ts +7 -24
- package/types/sections.d.ts +2 -0
- package/types/share-actions.d.ts +99 -0
- package/types/share.d.ts +0 -9
- package/types/table.d.ts +9 -3
- package/types/templates.d.ts +7 -1
- package/types/tips.d.ts +9 -7
- package/types/toolbar-panels.d.ts +8 -5
- 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-view-history.d.ts +7 -4
- package/types/view-history.d.ts +23 -6
- package/types/view-ops.d.ts +72 -123
- package/types/view-save.d.ts +76 -0
- package/types/view-store.d.ts +13 -6
- package/dist/chunks/chunk-C32TYSHG.js +0 -441
- package/dist/chunks/chunk-XYP47DJ3.js +0 -123
package/dist/menus.js
CHANGED
|
@@ -1,71 +1,67 @@
|
|
|
1
1
|
import {
|
|
2
|
+
CHART_TYPES,
|
|
3
|
+
CHART_TYPE_NAMES,
|
|
2
4
|
ClearInput,
|
|
3
|
-
|
|
5
|
+
HelpContext,
|
|
4
6
|
Icon,
|
|
7
|
+
InfoButton,
|
|
5
8
|
LayerContext,
|
|
6
9
|
MenuButton,
|
|
7
10
|
Option,
|
|
8
11
|
Popover,
|
|
9
12
|
SHORTCUTS,
|
|
10
|
-
|
|
11
|
-
SettingInfo,
|
|
12
|
-
TOTALS,
|
|
13
|
+
SLICE_TYPES,
|
|
13
14
|
ZONES,
|
|
14
15
|
ZONE_ICON,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
copyText,
|
|
19
|
-
dataUrlToBlob,
|
|
16
|
+
axisOf,
|
|
17
|
+
chartTypeOf,
|
|
18
|
+
clone,
|
|
20
19
|
decodeRow,
|
|
21
|
-
|
|
20
|
+
filterZoneFields,
|
|
22
21
|
filtersOf,
|
|
23
22
|
groupField,
|
|
24
23
|
groupingName,
|
|
25
24
|
groupingOf,
|
|
26
|
-
|
|
27
|
-
|
|
25
|
+
isSection,
|
|
26
|
+
linkNow,
|
|
27
|
+
loadCheck,
|
|
28
|
+
loadLink,
|
|
28
29
|
moveField,
|
|
29
30
|
numericResult,
|
|
31
|
+
readLinkParam,
|
|
30
32
|
refLabel,
|
|
31
|
-
removeFilters,
|
|
32
33
|
reorder,
|
|
33
|
-
|
|
34
|
+
same,
|
|
34
35
|
sameRef,
|
|
35
|
-
saveBlob,
|
|
36
36
|
selectedItems,
|
|
37
|
-
setItemFilter,
|
|
38
|
-
setLabelFilter,
|
|
39
37
|
setSort,
|
|
40
|
-
|
|
41
|
-
|
|
38
|
+
shareBase,
|
|
39
|
+
sortEntry,
|
|
42
40
|
sortOf,
|
|
41
|
+
sortText,
|
|
43
42
|
sourceOf,
|
|
44
|
-
totalNoEffect,
|
|
45
|
-
updateValue,
|
|
46
43
|
useModal,
|
|
44
|
+
valueConditionText,
|
|
47
45
|
valueLabel,
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
CHART_TYPE_NAMES,
|
|
53
|
-
SLICE_TYPES,
|
|
54
|
-
chartTypeOf
|
|
55
|
-
} from "./chunks/chunk-XYP47DJ3.js";
|
|
46
|
+
viewFromObject,
|
|
47
|
+
viewFromText,
|
|
48
|
+
withLinkParam
|
|
49
|
+
} from "./chunks/chunk-X7H7BAVT.js";
|
|
56
50
|
import {
|
|
51
|
+
addMenuTexts,
|
|
52
|
+
hasMenuTexts,
|
|
57
53
|
menuLabels
|
|
58
|
-
} from "./chunks/chunk-
|
|
54
|
+
} from "./chunks/chunk-LQCWFJBS.js";
|
|
59
55
|
import {
|
|
60
56
|
fill,
|
|
61
57
|
hostFailure,
|
|
62
58
|
messageOf,
|
|
63
59
|
plural
|
|
64
|
-
} from "./chunks/chunk-
|
|
60
|
+
} from "./chunks/chunk-F6MVUAQD.js";
|
|
65
61
|
|
|
66
62
|
// src/chip-menus.jsx
|
|
67
|
-
import
|
|
68
|
-
import { CATALOG, aggregatorsFor, fieldLabel, isFormat } from "pivotkit-core";
|
|
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";
|
|
69
65
|
|
|
70
66
|
// src/numbers.js
|
|
71
67
|
var cache = /* @__PURE__ */ new Map();
|
|
@@ -121,12 +117,192 @@ function numberText(n, locale) {
|
|
|
121
117
|
}
|
|
122
118
|
}
|
|
123
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
|
+
|
|
124
300
|
// src/chip-menus.jsx
|
|
125
|
-
var FORMAT_CHOICES = ["number", "number:0", "number:2", "currency", "percent"].filter(
|
|
126
|
-
var MORE_FORMATS = ["integer", "compact", "bytes", "duration:h", "duration:s"].filter(
|
|
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);
|
|
127
303
|
var COMMON_SHOW_AS = CATALOG.showAs.filter((s) => ["percentOfGrandTotal", "percentOfRowTotal", "percentOfColumnTotal"].includes(s));
|
|
128
304
|
function More({ title, open, children }) {
|
|
129
|
-
return /* @__PURE__ */
|
|
305
|
+
return /* @__PURE__ */ React2.createElement("details", { className: "pk-more", open }, /* @__PURE__ */ React2.createElement("summary", { className: "pk-more-title" }, title), children);
|
|
130
306
|
}
|
|
131
307
|
function readNumber(text, { kind = "number", required = true, tried = false, labels, locale }) {
|
|
132
308
|
const value = parseNumber(text, locale);
|
|
@@ -138,8 +314,8 @@ function readNumber(text, { kind = "number", required = true, tried = false, lab
|
|
|
138
314
|
return ok ? { value, problem: null } : { value: null, problem: say() };
|
|
139
315
|
}
|
|
140
316
|
function NumberField({ value, onChange, problem, label, testId, className = "pk-field-label", shown, shownClass }) {
|
|
141
|
-
const id =
|
|
142
|
-
return /* @__PURE__ */
|
|
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(
|
|
143
319
|
"input",
|
|
144
320
|
{
|
|
145
321
|
type: "text",
|
|
@@ -153,20 +329,20 @@ function NumberField({ value, onChange, problem, label, testId, className = "pk-
|
|
|
153
329
|
"aria-describedby": problem ? id : void 0,
|
|
154
330
|
"data-testid": testId
|
|
155
331
|
}
|
|
156
|
-
)), problem ? /* @__PURE__ */
|
|
332
|
+
)), problem ? /* @__PURE__ */ React2.createElement("p", { id, className: "pk-form-problem", "data-testid": `${testId}-problem` }, problem) : null);
|
|
157
333
|
}
|
|
158
|
-
function BinForm({ grouping, labels, onApply, onClear, range, locale }) {
|
|
334
|
+
function BinForm({ grouping, labels, onApply, onClear, onCancel, range, locale }) {
|
|
159
335
|
const [size, setSize] = useState(numberText(grouping?.size, locale));
|
|
160
336
|
const [start, setStart] = useState(numberText(grouping?.origin, locale));
|
|
161
337
|
const [tried, setTried] = useState(false);
|
|
162
|
-
const problemId =
|
|
338
|
+
const problemId = useId2();
|
|
163
339
|
const sized = readNumber(size, { kind: "size", tried, labels, locale });
|
|
164
340
|
const started = readNumber(start, { required: false, labels, locale });
|
|
165
341
|
const n = sized.value;
|
|
166
342
|
const s = start.trim() === "" ? 0 : started.value;
|
|
167
343
|
const far = n !== null && s !== null && binProblem(n, s, range) === "far";
|
|
168
344
|
const number = (x) => x.toLocaleString(locale, { maximumFractionDigits: 6 });
|
|
169
|
-
return /* @__PURE__ */
|
|
345
|
+
return /* @__PURE__ */ React2.createElement(
|
|
170
346
|
"form",
|
|
171
347
|
{
|
|
172
348
|
className: "pk-inline-form pk-bin-form",
|
|
@@ -182,27 +358,27 @@ function BinForm({ grouping, labels, onApply, onClear, range, locale }) {
|
|
|
182
358
|
}
|
|
183
359
|
}
|
|
184
360
|
},
|
|
185
|
-
/* @__PURE__ */
|
|
186
|
-
/* @__PURE__ */
|
|
187
|
-
started.problem ? /* @__PURE__ */
|
|
188
|
-
/* @__PURE__ */
|
|
189
|
-
|
|
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" })
|
|
190
366
|
);
|
|
191
367
|
}
|
|
192
368
|
function MeasurePick({ choices, names, index, onChange, label, prefix, testId }) {
|
|
193
369
|
if (choices.length < 2) {
|
|
194
|
-
return /* @__PURE__ */
|
|
370
|
+
return /* @__PURE__ */ React2.createElement("span", { className: "pk-muted pk-by" }, prefix ? `${prefix} ${names[0]}` : names[0]);
|
|
195
371
|
}
|
|
196
|
-
return /* @__PURE__ */
|
|
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]))));
|
|
197
373
|
}
|
|
198
374
|
var choiceIndex = (choices, ref) => Math.max(0, choices.findIndex((c) => sameRef(c, ref)));
|
|
199
|
-
function TopForm({ top, labels, choices, names, onApply, locale }) {
|
|
375
|
+
function TopForm({ top, labels, choices, names, onApply, onCancel, locale }) {
|
|
200
376
|
const [count, setCount] = useState(numberText(top?.count ?? 10, locale));
|
|
201
377
|
const [bottom, setBottom] = useState(Boolean(top?.bottom));
|
|
202
378
|
const [by, setBy] = useState(() => choiceIndex(choices, top?.by));
|
|
203
379
|
const [tried, setTried] = useState(false);
|
|
204
380
|
const counted = readNumber(count, { kind: "count", tried, labels, locale });
|
|
205
|
-
return /* @__PURE__ */
|
|
381
|
+
return /* @__PURE__ */ React2.createElement(
|
|
206
382
|
"form",
|
|
207
383
|
{
|
|
208
384
|
className: "pk-inline-form",
|
|
@@ -218,14 +394,14 @@ function TopForm({ top, labels, choices, names, onApply, locale }) {
|
|
|
218
394
|
}
|
|
219
395
|
}
|
|
220
396
|
},
|
|
221
|
-
/* @__PURE__ */
|
|
222
|
-
/* @__PURE__ */
|
|
223
|
-
/* @__PURE__ */
|
|
224
|
-
/* @__PURE__ */
|
|
225
|
-
|
|
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" })
|
|
226
402
|
);
|
|
227
403
|
}
|
|
228
|
-
function ValueFilterForm({ condition, labels, choices, names, onApply, locale }) {
|
|
404
|
+
function ValueFilterForm({ condition, labels, choices, names, onApply, onCancel, locale }) {
|
|
229
405
|
const [by, setBy] = useState(() => choiceIndex(choices, condition?.by));
|
|
230
406
|
const [op, setOp] = useState(condition?.op ?? ">");
|
|
231
407
|
const [first, setFirst] = useState(numberText(condition?.value, locale));
|
|
@@ -235,7 +411,7 @@ function ValueFilterForm({ condition, labels, choices, names, onApply, locale })
|
|
|
235
411
|
const a = readNumber(first, { tried, labels, locale });
|
|
236
412
|
const b = readNumber(second, { tried, labels, locale });
|
|
237
413
|
const ok = a.value !== null && (!between || b.value !== null);
|
|
238
|
-
return /* @__PURE__ */
|
|
414
|
+
return /* @__PURE__ */ React2.createElement(
|
|
239
415
|
"form",
|
|
240
416
|
{
|
|
241
417
|
className: "pk-inline-form pk-value-filter",
|
|
@@ -257,28 +433,57 @@ function ValueFilterForm({ condition, labels, choices, names, onApply, locale })
|
|
|
257
433
|
}
|
|
258
434
|
}
|
|
259
435
|
},
|
|
260
|
-
/* @__PURE__ */
|
|
261
|
-
/* @__PURE__ */
|
|
262
|
-
/* @__PURE__ */
|
|
263
|
-
between ? /* @__PURE__ */
|
|
264
|
-
/* @__PURE__ */
|
|
265
|
-
|
|
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" })
|
|
266
442
|
);
|
|
267
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
|
+
}
|
|
268
473
|
function MoveSection({ view, zone, index, count, labels, commit, close, text, type }) {
|
|
269
|
-
return /* @__PURE__ */
|
|
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: () => {
|
|
270
475
|
close();
|
|
271
476
|
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__ */
|
|
477
|
+
}, testId: `move-${z}` }, fill(labels.moveTo, { zone: labels.zones[z] }))), zone !== "filters" && index > 0 ? /* @__PURE__ */ React2.createElement(Option, { icon: "chevronRight", onSelect: () => {
|
|
273
478
|
close();
|
|
274
479
|
commit(reorder(view, zone, index, index - 1), { step: "reordered", zone });
|
|
275
|
-
} }, labels.moveLeft) : null, zone !== "filters" && index < count - 1 ? /* @__PURE__ */
|
|
480
|
+
} }, labels.moveLeft) : null, zone !== "filters" && index < count - 1 ? /* @__PURE__ */ React2.createElement(Option, { icon: "chevronRight", onSelect: () => {
|
|
276
481
|
close();
|
|
277
482
|
commit(reorder(view, zone, index, index + 1), { step: "reordered", zone });
|
|
278
483
|
} }, labels.moveRight) : null);
|
|
279
484
|
}
|
|
280
485
|
function RemoveFoot({ labels, onRemove, close }) {
|
|
281
|
-
return /* @__PURE__ */
|
|
486
|
+
return /* @__PURE__ */ React2.createElement("div", { className: "pk-menu-foot" }, /* @__PURE__ */ React2.createElement(Option, { icon: "trash", danger: true, onSelect: () => {
|
|
282
487
|
close();
|
|
283
488
|
onRemove();
|
|
284
489
|
}, testId: "menu-remove" }, labels.remove));
|
|
@@ -305,7 +510,7 @@ function AxisMenu({ view, zone, index, field, types, labels, commit, close, open
|
|
|
305
510
|
const doSort = (by, order, ref) => {
|
|
306
511
|
close();
|
|
307
512
|
const spec = by === "value" ? { by, order, value: ref } : by === "custom" ? { by, order, items: [...customItems] } : { by, order };
|
|
308
|
-
commit(setSort(view, field,
|
|
513
|
+
commit(setSort(view, field, sortEntry(spec, Array.isArray(hostOrder) && hostOrder.length > 0)), { step: "sort", field: name });
|
|
309
514
|
};
|
|
310
515
|
const regroup = (unit, size, origin) => {
|
|
311
516
|
close();
|
|
@@ -313,23 +518,36 @@ function AxisMenu({ view, zone, index, field, types, labels, commit, close, open
|
|
|
313
518
|
const grouped = unit ? groupingName(sourceName, unit, labels, size) : null;
|
|
314
519
|
commit(groupField(view, field, unit, { size, origin, name: grouped ?? void 0 }).view, { step: "group", field: sourceName });
|
|
315
520
|
};
|
|
316
|
-
const
|
|
317
|
-
|
|
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) => {
|
|
318
538
|
close();
|
|
319
539
|
commit(setTopFilter(view, field, t, top), { step: "top", field: name });
|
|
320
|
-
}
|
|
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: () => {
|
|
321
542
|
close();
|
|
322
543
|
openFilter(field, chipRef.current);
|
|
323
|
-
}, testId: "open-filter" },
|
|
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: () => {
|
|
324
545
|
close();
|
|
325
|
-
commit(
|
|
326
|
-
}, testId: "
|
|
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) => {
|
|
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) => {
|
|
330
548
|
close();
|
|
331
549
|
commit(setValueFilter(view, field, c, condition), { step: "filter", field: name });
|
|
332
|
-
} }))), /* @__PURE__ */
|
|
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 }));
|
|
333
551
|
}
|
|
334
552
|
function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaultsOf, info }) {
|
|
335
553
|
const spec = view.values[index];
|
|
@@ -345,13 +563,14 @@ function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaul
|
|
|
345
563
|
commit(updateValue(view, index, patch, { defaults: spec.field ? defaultsOf?.(spec.field) : void 0 }), { step: "value", field: name });
|
|
346
564
|
};
|
|
347
565
|
const [rename, setRename] = useState(spec.label ?? "");
|
|
348
|
-
const
|
|
349
|
-
const
|
|
350
|
-
const
|
|
351
|
-
|
|
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) => {
|
|
352
571
|
e.preventDefault();
|
|
353
572
|
set({ label: rename.trim() || null });
|
|
354
|
-
} }, /* @__PURE__ */
|
|
573
|
+
} }, /* @__PURE__ */ React2.createElement(
|
|
355
574
|
ClearInput,
|
|
356
575
|
{
|
|
357
576
|
type: "text",
|
|
@@ -364,15 +583,216 @@ function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaul
|
|
|
364
583
|
maxLength: 200,
|
|
365
584
|
"data-testid": "value-name"
|
|
366
585
|
}
|
|
367
|
-
), /* @__PURE__ */
|
|
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 }));
|
|
368
587
|
}
|
|
369
588
|
|
|
370
589
|
// src/toolbar-panels.jsx
|
|
371
|
-
import
|
|
590
|
+
import React3, { useEffect as useEffect2, useId as useId3, useRef as useRef2, useState as useState2 } from "react";
|
|
372
591
|
import { VIEW_FILE_LIMITS } from "pivotkit-core";
|
|
373
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
|
+
|
|
374
794
|
// src/view-store.js
|
|
375
|
-
import { toViewFile } from "pivotkit-core";
|
|
795
|
+
import { toViewFile as toViewFile2 } from "pivotkit-core";
|
|
376
796
|
import { parseTemplates } from "pivotkit-core/templates";
|
|
377
797
|
var VIEW_STORE_LIMITS = Object.freeze({ count: 100, text: 5e5 });
|
|
378
798
|
var warnedLarge = false;
|
|
@@ -390,7 +810,7 @@ function readAll(raw) {
|
|
|
390
810
|
return parseTemplates(raw).templates;
|
|
391
811
|
}
|
|
392
812
|
function storedViews(raw, sourceId) {
|
|
393
|
-
return readAll(raw).map((t, at) => ({ name: t.name, view: t.view, id: t.source
|
|
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);
|
|
394
814
|
}
|
|
395
815
|
function changedViews(raw, change, message) {
|
|
396
816
|
const all = readAll(raw);
|
|
@@ -402,7 +822,16 @@ function changedViews(raw, change, message) {
|
|
|
402
822
|
next = all.filter((t, i) => i !== change.remove);
|
|
403
823
|
}
|
|
404
824
|
const saving = Boolean(change.name && change.view);
|
|
405
|
-
if (saving) {
|
|
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) {
|
|
406
835
|
const id = change.sourceId;
|
|
407
836
|
next = next.filter((t) => t.name !== change.name || (t.source?.id ?? void 0) !== id);
|
|
408
837
|
next.push({ name: (
|
|
@@ -416,7 +845,7 @@ function changedViews(raw, change, message) {
|
|
|
416
845
|
throw new Error(message("count", VIEW_STORE_LIMITS.count));
|
|
417
846
|
}
|
|
418
847
|
}
|
|
419
|
-
const text = next.length ? JSON.stringify(next.map((t) =>
|
|
848
|
+
const text = next.length ? JSON.stringify(next.map((t) => toViewFile2(t.view, { name: t.name, source: t.source }, { link: true }))) : null;
|
|
420
849
|
if (saving && text && text.length > VIEW_STORE_LIMITS.text) {
|
|
421
850
|
throw new Error(message("text", VIEW_STORE_LIMITS.text));
|
|
422
851
|
}
|
|
@@ -433,7 +862,7 @@ function storeViews(raw, change, labels, locale, keep) {
|
|
|
433
862
|
// src/toolbar-panels.jsx
|
|
434
863
|
function ChartTypeOptions({ view, plan, labels, onChart, close }) {
|
|
435
864
|
const current = chartTypeOf(view.chart);
|
|
436
|
-
return CHART_TYPE_NAMES.map((p) => /* @__PURE__ */
|
|
865
|
+
return CHART_TYPE_NAMES.map((p) => /* @__PURE__ */ React3.createElement(
|
|
437
866
|
Option,
|
|
438
867
|
{
|
|
439
868
|
key: p,
|
|
@@ -461,7 +890,7 @@ function ChartTitle({ title, labels, onDisplay }) {
|
|
|
461
890
|
setLast(title);
|
|
462
891
|
setText(title ?? "");
|
|
463
892
|
}
|
|
464
|
-
return /* @__PURE__ */
|
|
893
|
+
return /* @__PURE__ */ React3.createElement(
|
|
465
894
|
"form",
|
|
466
895
|
{
|
|
467
896
|
className: "pk-inline-form",
|
|
@@ -470,7 +899,7 @@ function ChartTitle({ title, labels, onDisplay }) {
|
|
|
470
899
|
onDisplay({ title: text.trim() || null });
|
|
471
900
|
}
|
|
472
901
|
},
|
|
473
|
-
/* @__PURE__ */
|
|
902
|
+
/* @__PURE__ */ React3.createElement(
|
|
474
903
|
ClearInput,
|
|
475
904
|
{
|
|
476
905
|
type: "text",
|
|
@@ -484,7 +913,7 @@ function ChartTitle({ title, labels, onDisplay }) {
|
|
|
484
913
|
"data-testid": "chart-title"
|
|
485
914
|
}
|
|
486
915
|
),
|
|
487
|
-
/* @__PURE__ */
|
|
916
|
+
/* @__PURE__ */ React3.createElement("button", { type: "submit", className: "pk-btn pk-primary", disabled: (text.trim() || null) === (title ?? null) }, labels.apply)
|
|
488
917
|
);
|
|
489
918
|
}
|
|
490
919
|
function ChartDisplay({ view, plan, labels, onDisplay }) {
|
|
@@ -494,81 +923,150 @@ function ChartDisplay({ view, plan, labels, onDisplay }) {
|
|
|
494
923
|
const axis = CHART_TYPES[drawn].axis;
|
|
495
924
|
const choices = pie ? VALUE_LABELS.slices : VALUE_LABELS.other;
|
|
496
925
|
const valueLabels = !pie && (chart.valueLabels === "percent" || chart.valueLabels === "both") ? "value" : chart.valueLabels;
|
|
497
|
-
|
|
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);
|
|
498
936
|
}
|
|
499
937
|
function ChartTypePanel({ view, plan, labels, onChart, onDisplay, close }) {
|
|
500
|
-
return /* @__PURE__ */
|
|
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 }));
|
|
501
939
|
}
|
|
502
940
|
function Shortcuts({ labels, mod }) {
|
|
503
941
|
const key = (k) => k === "Mod" ? mod === "\u2318" ? "\u2318" : labels.keys.Mod : Object.hasOwn(labels.keys, k) ? labels.keys[k] : k;
|
|
504
|
-
return /* @__PURE__ */
|
|
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]))));
|
|
505
943
|
}
|
|
506
944
|
function Switch({ checked, onChange, testId, children, disabled, reason, info, name }) {
|
|
507
|
-
const reasonId =
|
|
508
|
-
return /* @__PURE__ */
|
|
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 : ""));
|
|
509
973
|
}
|
|
510
974
|
function OptionsPanel({ view, labels, onTotal, onExpand, onCollapse, close, tips, mod, folding, help }) {
|
|
511
|
-
return /* @__PURE__ */
|
|
975
|
+
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(Section, { title: labels.totals, id: "totals" }, TOTALS.map((key) => {
|
|
512
976
|
const why = totalNoEffect(view, key);
|
|
513
|
-
return /* @__PURE__ */
|
|
514
|
-
})), /* @__PURE__ */
|
|
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: () => {
|
|
515
979
|
close();
|
|
516
|
-
onExpand();
|
|
517
|
-
}, disabled: !folding.canExpand, reason: folding.why.expand ? labels[folding.why.expand] : void 0, testId: "expand-all" }, labels.expandAll), /* @__PURE__ */
|
|
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: () => {
|
|
518
982
|
close();
|
|
519
|
-
onCollapse();
|
|
520
|
-
}, disabled: !folding.canCollapse, reason: folding.why.collapse ? labels[folding.why.collapse] : void 0, testId: "collapse-all" }, labels.collapseAll)), /* @__PURE__ */
|
|
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));
|
|
521
995
|
}
|
|
522
|
-
function SaveView({ labels, onSave }) {
|
|
996
|
+
function SaveView({ labels, button, onSave, resolve, close }) {
|
|
523
997
|
const [name, setName] = useState2("");
|
|
524
|
-
const
|
|
998
|
+
const [asking, setAsking] = useState2(
|
|
999
|
+
/** @type {any} */
|
|
1000
|
+
null
|
|
1001
|
+
);
|
|
1002
|
+
const field = useRef2(
|
|
525
1003
|
/** @type {HTMLInputElement | null} */
|
|
526
1004
|
null
|
|
527
1005
|
);
|
|
528
|
-
|
|
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(
|
|
529
1033
|
"form",
|
|
530
1034
|
{
|
|
531
1035
|
className: "pk-inline-form",
|
|
532
1036
|
onSubmit: (e) => {
|
|
533
1037
|
e.preventDefault();
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
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
|
-
);
|
|
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);
|
|
547
1045
|
}
|
|
548
1046
|
}
|
|
549
1047
|
},
|
|
550
|
-
/* @__PURE__ */
|
|
551
|
-
/* @__PURE__ */
|
|
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)
|
|
552
1050
|
);
|
|
553
1051
|
}
|
|
554
1052
|
function LoadCheck({ check, labels, onCancel, close, title, quiet = false }) {
|
|
555
|
-
const titleId =
|
|
556
|
-
const first =
|
|
1053
|
+
const titleId = useId3();
|
|
1054
|
+
const first = useRef2(
|
|
557
1055
|
/** @type {HTMLButtonElement | null} */
|
|
558
1056
|
null
|
|
559
1057
|
);
|
|
560
|
-
|
|
1058
|
+
useEffect2(() => {
|
|
561
1059
|
if (!quiet) {
|
|
562
1060
|
first.current?.focus({ preventScroll: true });
|
|
563
1061
|
}
|
|
564
1062
|
}, [quiet]);
|
|
565
|
-
return /* @__PURE__ */
|
|
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: () => {
|
|
566
1064
|
close();
|
|
567
1065
|
check.switchTo?.run();
|
|
568
|
-
} }, fill(labels.switchAndLoad, { source: check.switchTo.name })) : null, /* @__PURE__ */
|
|
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: () => {
|
|
569
1067
|
close();
|
|
570
1068
|
check.load();
|
|
571
|
-
} }, labels.loadAnyway), /* @__PURE__ */
|
|
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);
|
|
572
1070
|
}
|
|
573
1071
|
function LoadView({ labels, onLoadText, close }) {
|
|
574
1072
|
const [text, setText] = useState2("");
|
|
@@ -581,16 +1079,16 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
581
1079
|
null
|
|
582
1080
|
);
|
|
583
1081
|
const [busy, setBusy] = useState2(false);
|
|
584
|
-
const file =
|
|
1082
|
+
const file = useRef2(
|
|
585
1083
|
/** @type {HTMLInputElement | null} */
|
|
586
1084
|
null
|
|
587
1085
|
);
|
|
588
|
-
const field =
|
|
1086
|
+
const field = useRef2(
|
|
589
1087
|
/** @type {HTMLTextAreaElement | null} */
|
|
590
1088
|
null
|
|
591
1089
|
);
|
|
592
|
-
const problemId =
|
|
593
|
-
|
|
1090
|
+
const problemId = useId3();
|
|
1091
|
+
useEffect2(() => {
|
|
594
1092
|
if (!check) {
|
|
595
1093
|
field.current?.focus({ preventScroll: true });
|
|
596
1094
|
}
|
|
@@ -608,9 +1106,9 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
608
1106
|
}
|
|
609
1107
|
};
|
|
610
1108
|
if (check) {
|
|
611
|
-
return /* @__PURE__ */
|
|
1109
|
+
return /* @__PURE__ */ React3.createElement(LoadCheck, { check, labels, onCancel: () => setCheck(null), close });
|
|
612
1110
|
}
|
|
613
|
-
return /* @__PURE__ */
|
|
1111
|
+
return /* @__PURE__ */ React3.createElement(
|
|
614
1112
|
"form",
|
|
615
1113
|
{
|
|
616
1114
|
className: "pk-inline-form pk-load-view",
|
|
@@ -619,8 +1117,8 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
619
1117
|
load(text);
|
|
620
1118
|
}
|
|
621
1119
|
},
|
|
622
|
-
/* @__PURE__ */
|
|
623
|
-
/* @__PURE__ */
|
|
1120
|
+
/* @__PURE__ */ React3.createElement("p", { className: "pk-hint" }, labels.loadViewHint),
|
|
1121
|
+
/* @__PURE__ */ React3.createElement(
|
|
624
1122
|
ClearInput,
|
|
625
1123
|
{
|
|
626
1124
|
multiline: true,
|
|
@@ -640,8 +1138,8 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
640
1138
|
inputRef: field
|
|
641
1139
|
}
|
|
642
1140
|
),
|
|
643
|
-
problem ? /* @__PURE__ */
|
|
644
|
-
/* @__PURE__ */
|
|
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(
|
|
645
1143
|
"input",
|
|
646
1144
|
{
|
|
647
1145
|
ref: file,
|
|
@@ -670,25 +1168,26 @@ function LoadView({ labels, onLoadText, close }) {
|
|
|
670
1168
|
}
|
|
671
1169
|
}
|
|
672
1170
|
),
|
|
673
|
-
/* @__PURE__ */
|
|
674
|
-
/* @__PURE__ */
|
|
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)
|
|
675
1173
|
);
|
|
676
1174
|
}
|
|
677
1175
|
function ShareSection({ labels, share, close }) {
|
|
678
1176
|
const [loading, setLoading] = useState2(false);
|
|
1177
|
+
const act = shareActions(share, labels);
|
|
679
1178
|
if (loading) {
|
|
680
|
-
return /* @__PURE__ */
|
|
1179
|
+
return /* @__PURE__ */ React3.createElement(Section, { title: labels.loadView.replace(/…$/, "") }, /* @__PURE__ */ React3.createElement(LoadView, { labels, onLoadText: act.loadText, close }));
|
|
681
1180
|
}
|
|
682
|
-
return /* @__PURE__ */
|
|
1181
|
+
return /* @__PURE__ */ React3.createElement(Section, { title: labels.share, id: "share" }, share.canLink ? /* @__PURE__ */ React3.createElement(Option, { icon: "link", onSelect: () => {
|
|
683
1182
|
close();
|
|
684
|
-
|
|
685
|
-
}, testId: "copy-link" }, labels.copyLink) : null, /* @__PURE__ */
|
|
1183
|
+
act.copyLink();
|
|
1184
|
+
}, testId: "copy-link" }, labels.copyLink) : null, /* @__PURE__ */ React3.createElement(Option, { icon: "copy", onSelect: () => {
|
|
686
1185
|
close();
|
|
687
|
-
|
|
688
|
-
}, testId: "copy-json" }, labels.copyJson), /* @__PURE__ */
|
|
1186
|
+
act.copyJson();
|
|
1187
|
+
}, testId: "copy-json" }, labels.copyJson), /* @__PURE__ */ React3.createElement(Option, { icon: "download", onSelect: () => {
|
|
689
1188
|
close();
|
|
690
|
-
|
|
691
|
-
}, testId: "download-view" }, labels.downloadView), /* @__PURE__ */
|
|
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));
|
|
692
1191
|
}
|
|
693
1192
|
function viewActions(ctx, labels) {
|
|
694
1193
|
const run = (task, done, failed, rejected, name) => Promise.resolve().then(task).then(
|
|
@@ -702,23 +1201,35 @@ function viewActions(ctx, labels) {
|
|
|
702
1201
|
}
|
|
703
1202
|
);
|
|
704
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
|
+
};
|
|
705
1214
|
return {
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
) : null,
|
|
1215
|
+
// Save and Save as: where to is view-save.js's (the host's onSaveTemplate wins over the store)
|
|
1216
|
+
save,
|
|
709
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,
|
|
710
1218
|
publish: ctx.onPublish ? (t) => run(() => ctx.onPublish(t.name, ctx.normalized(t.view)), labels.toastPublished, labels.toastPublishFailed, labels.toastPublishRejected, t.name) : null
|
|
711
1219
|
};
|
|
712
1220
|
}
|
|
713
1221
|
function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
714
|
-
const { save
|
|
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);
|
|
715
1226
|
const store = actions.store && !actions.onSave;
|
|
716
1227
|
const [confirming, setConfirming] = useState2(
|
|
717
1228
|
/** @type {{ at: number, kind: "delete" | "publish" } | null} */
|
|
718
1229
|
null
|
|
719
1230
|
);
|
|
720
1231
|
const [busy, setBusy] = useState2(false);
|
|
721
|
-
const box =
|
|
1232
|
+
const box = useRef2(
|
|
722
1233
|
/** @type {HTMLDivElement | null} */
|
|
723
1234
|
null
|
|
724
1235
|
);
|
|
@@ -726,10 +1237,10 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
726
1237
|
/** @type {{ key: string, place: number } | null} */
|
|
727
1238
|
null
|
|
728
1239
|
);
|
|
729
|
-
|
|
1240
|
+
useEffect2(() => {
|
|
730
1241
|
share?.prepare?.();
|
|
731
1242
|
}, [share]);
|
|
732
|
-
|
|
1243
|
+
useEffect2(() => {
|
|
733
1244
|
if (refocus && box.current) {
|
|
734
1245
|
const entries = [...box.current.querySelectorAll("[data-pk-entry]")];
|
|
735
1246
|
const entry2 = entries.find((el) => el.getAttribute("data-pk-entry") === refocus.key) ?? entries[Math.min(refocus.place, entries.length - 1)];
|
|
@@ -738,7 +1249,7 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
738
1249
|
}
|
|
739
1250
|
}, [refocus, templates]);
|
|
740
1251
|
const keyOf2 = (t) => `${t.scope}:${t.at ?? ""}:${t.name}`;
|
|
741
|
-
|
|
1252
|
+
useEffect2(() => {
|
|
742
1253
|
if (confirming) {
|
|
743
1254
|
box.current?.querySelector(".pk-confirm [data-autofocus]")?.focus({ preventScroll: true });
|
|
744
1255
|
}
|
|
@@ -753,7 +1264,7 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
753
1264
|
const kind = confirming.kind;
|
|
754
1265
|
const publish = kind === "publish";
|
|
755
1266
|
const question = fill(publish ? labels.publishConfirm : labels.deleteConfirm, { name: t.name });
|
|
756
|
-
return /* @__PURE__ */
|
|
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(
|
|
757
1268
|
"button",
|
|
758
1269
|
{
|
|
759
1270
|
type: "button",
|
|
@@ -771,40 +1282,66 @@ function ViewsPanel({ templates, labels, onLoad, actions, close, share }) {
|
|
|
771
1282
|
}
|
|
772
1283
|
},
|
|
773
1284
|
publish ? labels.publishAction : labels.deleteAction
|
|
774
|
-
), /* @__PURE__ */
|
|
1285
|
+
), /* @__PURE__ */ React3.createElement("button", { type: "button", className: "pk-btn", disabled: busy, onClick: () => answer(t) }, labels.cancel));
|
|
775
1286
|
}
|
|
776
|
-
const button = (kind, icon, text) => /* @__PURE__ */
|
|
777
|
-
return /* @__PURE__ */
|
|
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: () => {
|
|
778
1289
|
close();
|
|
779
1290
|
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__ */
|
|
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);
|
|
781
1292
|
};
|
|
782
1293
|
const sharedChange = Boolean(onPublish) || templates.some((t) => t.scope === "shared" && t.deletable);
|
|
783
1294
|
const group = (scope) => templates.map((t, at) => t.scope === scope ? entry(t, at) : null).filter(Boolean);
|
|
784
1295
|
const shared = group("shared");
|
|
785
1296
|
const mine = group("user");
|
|
786
|
-
return /* @__PURE__ */
|
|
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);
|
|
787
1323
|
}
|
|
788
1324
|
function ExportOption({ icon, text, info, onSelect, testId, disabled, reason }) {
|
|
789
|
-
const option = /* @__PURE__ */
|
|
790
|
-
return info ? /* @__PURE__ */
|
|
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: (
|
|
791
1327
|
/** @type {any} */
|
|
792
1328
|
info
|
|
793
1329
|
), name: text })) : option;
|
|
794
1330
|
}
|
|
795
|
-
function ExportPanel({ labels, onExport, chartReady, display, prepare, close }) {
|
|
796
|
-
|
|
1331
|
+
function ExportPanel({ labels, onExport, chartReady, display, empty = false, prepare, close }) {
|
|
1332
|
+
useEffect2(() => {
|
|
797
1333
|
prepare();
|
|
798
1334
|
}, [prepare]);
|
|
799
1335
|
const run = (kind) => () => {
|
|
800
1336
|
close();
|
|
801
1337
|
onExport(kind);
|
|
802
1338
|
};
|
|
803
|
-
|
|
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" })));
|
|
804
1341
|
}
|
|
805
1342
|
|
|
806
1343
|
// src/filter.jsx
|
|
807
|
-
import
|
|
1344
|
+
import React4, { useMemo, useState as useState3 } from "react";
|
|
808
1345
|
import { CATALOG as CATALOG2, fieldItems, fieldLabel as fieldLabel2 } from "pivotkit-core";
|
|
809
1346
|
var FILTER_LIST_MAX = 300;
|
|
810
1347
|
var keyOf = (v) => JSON.stringify(v);
|
|
@@ -853,7 +1390,7 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
|
|
|
853
1390
|
};
|
|
854
1391
|
const filtering = !base && hasFilter(view, field);
|
|
855
1392
|
const kind = conditionKind(encoded, view, field) ?? (label ? "text" : null);
|
|
856
|
-
return /* @__PURE__ */
|
|
1393
|
+
return /* @__PURE__ */ React4.createElement(
|
|
857
1394
|
"form",
|
|
858
1395
|
{
|
|
859
1396
|
className: "pk-filter",
|
|
@@ -862,8 +1399,8 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
|
|
|
862
1399
|
apply();
|
|
863
1400
|
}
|
|
864
1401
|
},
|
|
865
|
-
/* @__PURE__ */
|
|
866
|
-
filtering ? /* @__PURE__ */
|
|
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(
|
|
867
1404
|
"button",
|
|
868
1405
|
{
|
|
869
1406
|
type: "button",
|
|
@@ -874,15 +1411,15 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
|
|
|
874
1411
|
},
|
|
875
1412
|
"data-testid": "filter-remove"
|
|
876
1413
|
},
|
|
877
|
-
/* @__PURE__ */
|
|
878
|
-
/* @__PURE__ */
|
|
1414
|
+
/* @__PURE__ */ React4.createElement(Icon, { name: "x" }),
|
|
1415
|
+
/* @__PURE__ */ React4.createElement("span", { className: "pk-btn-text" }, labels.removeFilter)
|
|
879
1416
|
) : null,
|
|
880
|
-
/* @__PURE__ */
|
|
881
|
-
/* @__PURE__ */
|
|
882
|
-
/* @__PURE__ */
|
|
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) => {
|
|
883
1420
|
const k = keyOf(i.value);
|
|
884
|
-
return /* @__PURE__ */
|
|
885
|
-
})), matching.length > shown.length ? /* @__PURE__ */
|
|
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(
|
|
886
1423
|
ClearInput,
|
|
887
1424
|
{
|
|
888
1425
|
type: "text",
|
|
@@ -900,16 +1437,16 @@ function FilterBody({ view: current, base, field, encoded, locale, labels, commi
|
|
|
900
1437
|
"data-testid": "filter-condition-text"
|
|
901
1438
|
}
|
|
902
1439
|
) : null) : null),
|
|
903
|
-
/* @__PURE__ */
|
|
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))
|
|
904
1441
|
);
|
|
905
1442
|
}
|
|
906
1443
|
function FilterPopover({ target, onClose, view, encoded, locale, labels, commit }) {
|
|
907
1444
|
const anchor = useMemo(() => ({ current: target ? target.anchor : null }), [target]);
|
|
908
|
-
return /* @__PURE__ */
|
|
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);
|
|
909
1446
|
}
|
|
910
1447
|
|
|
911
1448
|
// src/drill-panel.jsx
|
|
912
|
-
import
|
|
1449
|
+
import React5, { useContext as useContext3, useEffect as useEffect3, useId as useId4, useMemo as useMemo2, useRef as useRef3, useState as useState4 } from "react";
|
|
913
1450
|
|
|
914
1451
|
// src/export-run.js
|
|
915
1452
|
import { toGrid } from "pivotkit-core";
|
|
@@ -1021,17 +1558,74 @@ async function exportDrill(kind, { drill, encoded, labels, onExport, announce, r
|
|
|
1021
1558
|
}
|
|
1022
1559
|
}
|
|
1023
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
|
+
|
|
1024
1617
|
// src/drill-panel.jsx
|
|
1025
|
-
function DrillPanel({ drill, onClose, labels, locale, exportContext }) {
|
|
1026
|
-
const id =
|
|
1027
|
-
const
|
|
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(
|
|
1028
1622
|
/** @type {HTMLDivElement | null} */
|
|
1029
1623
|
null
|
|
1030
1624
|
);
|
|
1031
1625
|
const [big, setBig] = useState4(false);
|
|
1032
|
-
const narrow =
|
|
1626
|
+
const narrow = useContext3(LayerContext).size === "narrow";
|
|
1033
1627
|
const { onKeyDown } = useModal(panel, Boolean(drill), big ? () => setBig(false) : onClose);
|
|
1034
|
-
|
|
1628
|
+
useEffect3(() => {
|
|
1035
1629
|
if (drill && exportContext) {
|
|
1036
1630
|
prepareExporters();
|
|
1037
1631
|
}
|
|
@@ -1047,7 +1641,7 @@ function DrillPanel({ drill, onClose, labels, locale, exportContext }) {
|
|
|
1047
1641
|
void exportDrill(kind, { drill, labels, ...exportContext, root: exportContext.root.current });
|
|
1048
1642
|
}
|
|
1049
1643
|
};
|
|
1050
|
-
return /* @__PURE__ */
|
|
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(
|
|
1051
1645
|
"div",
|
|
1052
1646
|
{
|
|
1053
1647
|
className: `pk-drill${big && !narrow ? " pk-drill-big" : ""}`,
|
|
@@ -1064,8 +1658,8 @@ function DrillPanel({ drill, onClose, labels, locale, exportContext }) {
|
|
|
1064
1658
|
}
|
|
1065
1659
|
}
|
|
1066
1660
|
},
|
|
1067
|
-
/* @__PURE__ */
|
|
1068
|
-
/* @__PURE__ */
|
|
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]))))))))
|
|
1069
1663
|
));
|
|
1070
1664
|
}
|
|
1071
1665
|
export {
|
|
@@ -1078,6 +1672,8 @@ export {
|
|
|
1078
1672
|
OptionsPanel,
|
|
1079
1673
|
ValueMenu,
|
|
1080
1674
|
ViewsPanel,
|
|
1675
|
+
addMenuTexts,
|
|
1676
|
+
hasMenuTexts,
|
|
1081
1677
|
menuLabels,
|
|
1082
1678
|
prepareExporters,
|
|
1083
1679
|
runExport,
|