pivotkit-react 0.3.0 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +339 -1
- package/README.md +2 -2
- package/dist/chunks/{chunk-IOPAM4JD.js → chunk-2AT72SLA.js} +635 -980
- package/dist/chunks/chunk-3E4NB5RZ.js +215 -0
- package/dist/chunks/{chunk-32Z33U6S.js → chunk-3WUGQPWV.js} +106 -9
- package/dist/chunks/{chunk-7CC4JHDY.js → chunk-4RS72AAA.js} +27 -8
- package/dist/chunks/{chunk-EM23V5GH.js → chunk-E6M57YLL.js} +19 -8
- package/dist/chunks/{chunk-RWYHJRQO.js → chunk-JMRTIOX4.js} +17 -7
- package/dist/chunks/chunk-RIOSIYGC.js +665 -0
- package/dist/chunks/{chunk-APB4NW4O.js → chunk-U5Q5I2D5.js} +36 -10
- package/dist/chunks/report-run-BZBFOMPF.js +12 -0
- package/dist/chunks/{unused-texts-K3VFH65P.js → unused-texts-Y4R67XSN.js} +1 -1
- package/dist/chunks/{unused-texts-de-OW4TGIVX.js → unused-texts-de-6YVPTNVS.js} +1 -1
- package/dist/echarts.js +38 -156
- package/dist/import-ui.js +765 -0
- package/dist/import-worker.js +20 -0
- package/dist/index.js +683 -244
- package/dist/labels.js +14 -10
- package/dist/menu-texts-de.js +1 -1
- package/dist/menus.js +768 -299
- package/dist/styles.css +322 -100
- package/package.json +9 -4
- package/types/chart-decorate.d.ts +28 -4
- package/types/chart-types.d.ts +2 -4
- package/types/data-history.d.ts +85 -0
- package/types/data-keep.d.ts +51 -0
- package/types/data-menu.d.ts +11 -0
- package/types/dom.d.ts +40 -7
- package/types/echarts.d.ts +1 -1
- package/types/export-run.d.ts +37 -3
- package/types/field-info.d.ts +32 -0
- package/types/filter.d.ts +1 -1
- package/types/icons.d.ts +1 -0
- package/types/import-host.d.ts +53 -0
- package/types/import-labels.d.ts +401 -0
- package/types/import-limits.d.ts +6 -0
- package/types/import-module.d.ts +2 -0
- package/types/import-run.d.ts +73 -0
- package/types/import-source.d.ts +32 -0
- package/types/import-steps.d.ts +121 -0
- package/types/import-ui.d.ts +108 -0
- package/types/import-worker.d.ts +1 -0
- package/types/index.d.ts +81 -11
- package/types/labels.d.ts +224 -4
- package/types/lazy-import.d.ts +4 -0
- package/types/lazy-menus.d.ts +2 -2
- package/types/levels.d.ts +3 -2
- package/types/light-tokens.d.ts +16 -0
- package/types/menu-labels.d.ts +37 -17
- package/types/menu-ops.d.ts +161 -40
- package/types/menu-topics.d.ts +9 -8
- package/types/menus.d.ts +1 -0
- package/types/names.d.ts +47 -19
- package/types/overflow.d.ts +29 -17
- package/types/place.d.ts +24 -0
- package/types/popover.d.ts +47 -5
- package/types/print-frame.d.ts +24 -0
- package/types/report-run.d.ts +14 -0
- package/types/section.d.ts +2 -2
- package/types/share-actions.d.ts +3 -3
- package/types/share.d.ts +13 -17
- package/types/theme.d.ts +2 -16
- package/types/tips.d.ts +5 -0
- package/types/toasts.d.ts +1 -1
- package/types/toolbar-panels.d.ts +11 -9
- package/types/unused-keep.d.ts +20 -0
- package/types/unused-texts.d.ts +13 -3
- package/types/unused.d.ts +1 -0
- package/types/use-export.d.ts +2 -2
- package/types/use-view-history.d.ts +12 -4
- package/types/view-ops.d.ts +65 -6
- package/types/virtual.d.ts +15 -0
- package/types/chart-layout.d.ts +0 -111
|
@@ -1,10 +1,16 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Icon,
|
|
3
|
+
Popover,
|
|
4
|
+
onTheWay,
|
|
5
|
+
useFormName
|
|
6
|
+
} from "./chunk-RIOSIYGC.js";
|
|
1
7
|
import {
|
|
2
8
|
fill,
|
|
3
9
|
plural
|
|
4
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-3WUGQPWV.js";
|
|
5
11
|
|
|
6
12
|
// src/chart-types.js
|
|
7
|
-
import {
|
|
13
|
+
import { chartPlan as corePlan } from "pivotkit-core";
|
|
8
14
|
var CHART_TYPES = Object.freeze({
|
|
9
15
|
auto: { chart: { type: "auto", stacked: false, horizontal: false }, icon: "sparkle", axis: true },
|
|
10
16
|
bar: { chart: { type: "bar", stacked: false, horizontal: false }, icon: "chart", axis: true },
|
|
@@ -29,869 +35,42 @@ function chartTypeOf(chart2) {
|
|
|
29
35
|
if (chart2.type === "bar") {
|
|
30
36
|
return chart2.horizontal ? "horizontal" : "stacked";
|
|
31
37
|
}
|
|
32
|
-
return CHART_TYPE_NAMES.find((name2) => CHART_TYPES[name2].chart.type === chart2.type) ?? "bar";
|
|
33
|
-
}
|
|
34
|
-
function chartPlan(view, encoded) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
return { name: name3, auto: false, swap: false, chart: { type: view.chart.type, stacked: Boolean(view.chart.stacked), horizontal: Boolean(view.chart.horizontal) } };
|
|
38
|
-
}
|
|
39
|
-
const own = autoChartType(
|
|
40
|
-
/** @type {any} */
|
|
41
|
-
view,
|
|
42
|
-
encoded
|
|
43
|
-
);
|
|
44
|
-
const swap = own === "bar" && view.cols.length > 0 && autoChartType(
|
|
45
|
-
/** @type {any} */
|
|
46
|
-
{ ...view, rows: view.cols },
|
|
47
|
-
encoded
|
|
48
|
-
) === "line";
|
|
49
|
-
const name2 = own === "line" || swap ? "line" : "bar";
|
|
50
|
-
return { name: name2, auto: true, swap, chart: { ...CHART_TYPES[name2].chart } };
|
|
51
|
-
}
|
|
52
|
-
var MANY_SERIES = 8;
|
|
53
|
-
var MAX_CATEGORIES = 50;
|
|
54
|
-
|
|
55
|
-
// src/names.js
|
|
56
|
-
import { fieldLabel, relativeDateRange } from "pivotkit-core";
|
|
57
|
-
function valueLabel(spec, labels) {
|
|
58
|
-
if (spec.label) {
|
|
59
|
-
return spec.label;
|
|
60
|
-
}
|
|
61
|
-
const core = labels.core;
|
|
62
|
-
let base;
|
|
63
|
-
if (!spec.field) {
|
|
64
|
-
base = core.countRows;
|
|
65
|
-
} else {
|
|
66
|
-
const agg = Object.hasOwn(core.aggregators, spec.agg) ? core.aggregators[spec.agg] : spec.agg;
|
|
67
|
-
base = fill(core.valueName, { agg, field: fieldLabel(spec.field, core) });
|
|
68
|
-
}
|
|
69
|
-
if (!spec.showAs || !core.showAs || !core.showAsName) {
|
|
70
|
-
return base;
|
|
71
|
-
}
|
|
72
|
-
const showAs = Object.hasOwn(core.showAs, spec.showAs.type) ? core.showAs[spec.showAs.type] : spec.showAs.type;
|
|
73
|
-
return fill(core.showAsName, { showAs, value: spec.field && spec.agg === "sum" ? fieldLabel(spec.field, core) : base });
|
|
74
|
-
}
|
|
75
|
-
function refLabel(view, ref, labels) {
|
|
76
|
-
const field = ref?.field ?? null;
|
|
77
|
-
const sameField = (v) => field === null || v.field === null || v.field === void 0 ? (v.field ?? null) === field : v.field.toLowerCase() === field.toLowerCase();
|
|
78
|
-
const spec = ref ? (view.values ?? []).find((v) => v.agg === ref.agg && sameField(v)) : void 0;
|
|
79
|
-
if (!spec && field === null) {
|
|
80
|
-
return labels.countOfRows;
|
|
81
|
-
}
|
|
82
|
-
return valueLabel({ ...spec ?? ref, showAs: null }, labels);
|
|
83
|
-
}
|
|
84
|
-
function sortText(view, sort, labels) {
|
|
85
|
-
const desc = sort.order === "desc";
|
|
86
|
-
if (sort.by === "value") {
|
|
87
|
-
return fill(desc ? labels.sortValueDesc : labels.sortValueAsc, { value: refLabel(view, sort.value, labels) });
|
|
88
|
-
}
|
|
89
|
-
if (sort.by === "custom") {
|
|
90
|
-
return desc ? labels.sortCustomDesc : labels.sortCustom;
|
|
91
|
-
}
|
|
92
|
-
return desc ? labels.sortLabelDesc : labels.sortLabelAsc;
|
|
93
|
-
}
|
|
94
|
-
var OP_SIGNS = Object.freeze({ "=": "=", "!=": "\u2260", ">": ">", ">=": "\u2265", "<": "<", "<=": "\u2264" });
|
|
95
|
-
function valueConditionText(view, f, labels, locale) {
|
|
96
|
-
const number = (x) => typeof x === "number" ? x.toLocaleString(locale, { maximumFractionDigits: 6 }) : "";
|
|
97
|
-
const value = refLabel(view, f.by ?? (view.values?.[0] ? { field: view.values[0].field ?? null, agg: view.values[0].agg } : null), labels);
|
|
98
|
-
if (f.op === "between" || f.op === "notBetween") {
|
|
99
|
-
const [from, to] = typeof f.value2 === "number" && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
|
|
100
|
-
return fill(labels.valueConditions[f.op], { value, from: number(from), to: number(to) });
|
|
101
|
-
}
|
|
102
|
-
return fill(labels.valueConditions.compare, { value, op: Object.hasOwn(OP_SIGNS, f.op) ? OP_SIGNS[f.op] : f.op, number: number(f.value) });
|
|
103
|
-
}
|
|
104
|
-
var dayText = (iso, locale) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { dateStyle: "medium", timeZone: "UTC" });
|
|
105
|
-
var isoDay = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
106
|
-
var dayAfter = (iso, n = 1) => isoDay(Date.parse(`${iso}T00:00Z`) + n * 864e5);
|
|
107
|
-
var relativeDays = (f, timeZone, now, latest) => relativeDateRange(f.unit, f.count, { timeZone, now, anchor: f.anchor, latest: latest ?? void 0 });
|
|
108
|
-
function periodText(range, unit, locale) {
|
|
109
|
-
const month = (iso) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { month: "short", year: "numeric", timeZone: "UTC" });
|
|
110
|
-
const text = unit === "year" ? (iso) => iso.slice(0, 4) : unit === "month" ? month : (iso) => dayText(iso, locale);
|
|
111
|
-
const [from, to] = [text(range.from), text(range.to)];
|
|
112
|
-
return from === to ? from : `${from}\u2013${to}`;
|
|
113
|
-
}
|
|
114
|
-
function rangeShare(range, unit, span, locale) {
|
|
115
|
-
const [first, last] = [periodStart(isoDay(span.min), unit), periodEnd(isoDay(span.max), unit)];
|
|
116
|
-
if (first <= range.from && last >= range.to) {
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
const from = range.from > first ? range.from : first;
|
|
120
|
-
const to = range.to < last ? range.to : last;
|
|
121
|
-
if (from > to) {
|
|
122
|
-
return { none: true };
|
|
123
|
-
}
|
|
124
|
-
const missing = [];
|
|
125
|
-
let count = 0;
|
|
126
|
-
const part = (a, b, dataYear) => {
|
|
127
|
-
const years = [];
|
|
128
|
-
const [ya, yb] = [Number(a.slice(0, 4)), Number(b.slice(0, 4))];
|
|
129
|
-
for (let y = ya; y <= yb; y++) {
|
|
130
|
-
if (y !== dataYear) {
|
|
131
|
-
years.push(y);
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
if (years.length) {
|
|
135
|
-
missing.push(years.length === 1 ? String(years[0]) : `${years[0]}\u2013${years[years.length - 1]}`);
|
|
136
|
-
count += years.length;
|
|
137
|
-
}
|
|
138
|
-
if (ya <= dataYear && dataYear <= yb) {
|
|
139
|
-
const yearFrom = `${String(dataYear).padStart(4, "0")}-01-01`;
|
|
140
|
-
const yearTo = `${String(dataYear).padStart(4, "0")}-12-31`;
|
|
141
|
-
const rest = { from: a > yearFrom ? a : yearFrom, to: b < yearTo ? b : yearTo };
|
|
142
|
-
missing.push(periodText(rest, unit, locale));
|
|
143
|
-
count += periodText({ from: rest.from, to: rest.from }, unit, locale) === periodText({ from: rest.to, to: rest.to }, unit, locale) ? 1 : 2;
|
|
144
|
-
}
|
|
145
|
-
};
|
|
146
|
-
if (range.from < first) {
|
|
147
|
-
part(range.from, dayAfter(first, -1), Number(first.slice(0, 4)));
|
|
148
|
-
}
|
|
149
|
-
if (range.to > last) {
|
|
150
|
-
part(dayAfter(last), range.to, Number(last.slice(0, 4)));
|
|
151
|
-
}
|
|
152
|
-
return { none: false, data: periodText({ from, to }, unit, locale), missing, count };
|
|
153
|
-
}
|
|
154
|
-
var periodStart = (iso, unit) => unit === "year" ? `${iso.slice(0, 4)}-01-01` : unit === "month" ? `${iso.slice(0, 7)}-01` : iso;
|
|
155
|
-
function periodEnd(iso, unit) {
|
|
156
|
-
if (unit === "day") {
|
|
157
|
-
return iso;
|
|
158
|
-
}
|
|
159
|
-
const [y, m] = [Number(iso.slice(0, 4)), Number(iso.slice(5, 7))];
|
|
160
|
-
return isoDay(unit === "year" ? Date.UTC(y, 11, 31) : Date.UTC(y, m, 0));
|
|
161
|
-
}
|
|
162
|
-
function relativeText(f, labels, locale, timeZone, now, span) {
|
|
163
|
-
const key = f.count === 1 ? f.unit : `${f.unit}s`;
|
|
164
|
-
let text = fill(Object.hasOwn(labels.relative, key) ? labels.relative[key] : key, { count: f.count.toLocaleString(locale) });
|
|
165
|
-
const range = relativeDays(f, timeZone, now, span?.max);
|
|
166
|
-
if (!range) {
|
|
167
|
-
return text;
|
|
168
|
-
}
|
|
169
|
-
const latest = f.anchor === "latest";
|
|
170
|
-
if (latest) {
|
|
171
|
-
text = fill(labels.relativeTo, { text, end: periodText({ from: range.to, to: range.to }, f.unit, locale) });
|
|
172
|
-
}
|
|
173
|
-
const share = span ? rangeShare(range, f.unit, span, locale) : null;
|
|
174
|
-
if (!share) {
|
|
175
|
-
return latest ? text : fill(labels.withRange, { text, range: periodText(range, f.unit, locale) });
|
|
176
|
-
}
|
|
177
|
-
const lang = { lang: labels.lang, locale };
|
|
178
|
-
if (share.none) {
|
|
179
|
-
return fill(labels.withRange, { text, range: fill(plural(labels.noData, 1, lang), { range: periodText(range, f.unit, locale) }) });
|
|
180
|
-
}
|
|
181
|
-
return fill(labels.withShare, { text, range: share.data, missing: fill(plural(labels.noData, share.count, lang), { range: share.missing.join(", ") }) });
|
|
182
|
-
}
|
|
183
|
-
function wholeYears(from, to) {
|
|
184
|
-
const whole = typeof from === "string" && typeof to === "string" && /^\d{4}-01-01$/.test(from) && /^\d{4}-12-31$/.test(to);
|
|
185
|
-
return whole ? [from.slice(0, 4), to.slice(0, 4)] : null;
|
|
186
|
-
}
|
|
187
|
-
function compareText(f, labels, locale, { date, labelOf }) {
|
|
188
|
-
const shown = (v) => typeof v === "string" ? dayText(v, locale) : labelOf?.(v) ?? (date ? String(v) : v.toLocaleString(locale, { maximumFractionDigits: 6 }));
|
|
189
|
-
const forms = labels.compareShort;
|
|
190
|
-
if (f.op === "between" || f.op === "notBetween") {
|
|
191
|
-
const [from, to] = f.value2 !== void 0 && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
|
|
192
|
-
const years = wholeYears(from, to);
|
|
193
|
-
if (years) {
|
|
194
|
-
return years[0] === years[1] ? fill(forms[f.op === "between" ? "=" : "!="], { value: years[0] }) : fill(forms[f.op], { from: years[0], to: years[1] });
|
|
195
|
-
}
|
|
196
|
-
return fill(forms[f.op], { from: shown(from), to: shown(to) });
|
|
197
|
-
}
|
|
198
|
-
return date && Object.hasOwn(forms, f.op) ? fill(forms[f.op], { value: shown(f.value) }) : `${Object.hasOwn(OP_SIGNS, f.op) ? OP_SIGNS[f.op] : f.op} ${shown(f.value)}`;
|
|
199
|
-
}
|
|
200
|
-
function itemRuleText(f, labels, locale, { timeZone, date, labelOf, span }) {
|
|
201
|
-
if (f.type === "relative") {
|
|
202
|
-
return relativeText(
|
|
203
|
-
/** @type {any} */
|
|
204
|
-
f,
|
|
205
|
-
labels,
|
|
206
|
-
locale,
|
|
207
|
-
timeZone,
|
|
208
|
-
void 0,
|
|
209
|
-
span
|
|
210
|
-
);
|
|
211
|
-
}
|
|
212
|
-
if (f.type === "compare") {
|
|
213
|
-
return compareText(
|
|
214
|
-
/** @type {any} */
|
|
215
|
-
f,
|
|
216
|
-
labels,
|
|
217
|
-
locale,
|
|
218
|
-
{ date, labelOf }
|
|
219
|
-
);
|
|
220
|
-
}
|
|
221
|
-
const op = String(f.op);
|
|
222
|
-
return `${Object.hasOwn(labels.labelOps, op) ? labels.labelOps[op] : op} ${fill(labels.quote, { text: f.value })}`;
|
|
223
|
-
}
|
|
224
|
-
function groupingName(source, unit, labels, size) {
|
|
225
|
-
const inName = labels.unitInName && Object.hasOwn(labels.unitInName, unit) ? labels.unitInName[unit] : labels.units[unit];
|
|
226
|
-
return unit === "bin" ? fill(labels.binsName, { field: source, size }) : fill(labels.derivedName, { field: source, unit: inName ?? unit });
|
|
227
|
-
}
|
|
228
|
-
var quickZone = (type) => type === "number" ? "values" : "rows";
|
|
229
|
-
function fieldAction(field, type, zones, labels) {
|
|
230
|
-
const zone = quickZone(type);
|
|
231
|
-
const kind = zones.includes(zone) ? null : zone !== "values" && zones.some((z) => z === "cols" || z === "filters") ? "move" : "add";
|
|
232
|
-
const name2 = zones.length ? `${field}, ${fill(labels.inZone, { zone: zones.map((z) => labels.zones[z] ?? z).join(", ") })}` : field;
|
|
233
|
-
const description = kind === null ? "" : fill(kind === "move" ? labels.moveTo : labels.addTo, { zone: labels.zones[zone] });
|
|
234
|
-
return { zone, kind, name: name2, description };
|
|
235
|
-
}
|
|
236
|
-
var SUMMARY_ORDER = Object.freeze(["rows", "cols", "values", "filters"]);
|
|
237
|
-
function layoutSummary(entries2, labels) {
|
|
238
|
-
return SUMMARY_ORDER.filter((zone) => entries2[zone] && entries2[zone].length).map((zone) => ({ zone, title: labels.zones[zone], fields: entries2[zone].map((e) => e.text).join(", ") }));
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
// src/drill.js
|
|
242
|
-
import { cellRows } from "pivotkit-core";
|
|
243
|
-
var DRILL_LIMIT = 1e3;
|
|
244
|
-
function decodeRow(encoded, i) {
|
|
245
|
-
const row = {};
|
|
246
|
-
for (const column of encoded.columns) {
|
|
247
|
-
const code = column.codes[i];
|
|
248
|
-
const v = code < 0 ? null : column.dict[code];
|
|
249
|
-
const value = column.type === "date" && typeof v === "number" ? new Date(v).toISOString().replace(/(T00:00:00)?\.000Z$/, "").replace(/:00$/, "") : v;
|
|
250
|
-
Object.defineProperty(row, column.name, { value, enumerable: true, writable: true, configurable: true });
|
|
251
|
-
}
|
|
252
|
-
return row;
|
|
253
|
-
}
|
|
254
|
-
function drillRows(result, { rowPath = [], colPath = [], data = null, limit = DRILL_LIMIT }) {
|
|
255
|
-
const all = cellRows(result, { row: rowPath, col: colPath });
|
|
256
|
-
const indices = all.slice(0, Math.max(0, limit));
|
|
257
|
-
const rows = new Array(indices.length);
|
|
258
|
-
for (let k = 0; k < indices.length; k++) {
|
|
259
|
-
rows[k] = data ? data[indices[k]] : decodeRow(result.encoded, indices[k]);
|
|
260
|
-
}
|
|
261
|
-
return { count: all.length, rows, indices };
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
// src/icons.jsx
|
|
265
|
-
import React from "react";
|
|
266
|
-
var PATHS = {
|
|
267
|
-
grip: "M9 6h.01M9 12h.01M9 18h.01M15 6h.01M15 12h.01M15 18h.01",
|
|
268
|
-
text: "M4 18 8.5 6h1L14 18M5.6 14h6.8M17 11.5c.6-.7 1.4-1 2.3-1 1.5 0 2.2.9 2.2 2.3V18m0-3.4c-.8-.4-1.6-.5-2.5-.5-1.4 0-2.3.7-2.3 1.9 0 1.1.8 1.8 2 1.8 1.2 0 2.1-.6 2.8-1.6",
|
|
269
|
-
number: "M9 4 7 20M17 4l-2 16M4 9h16M3 15h16",
|
|
270
|
-
date: "M7 3v3M17 3v3M4 8h16M5 5h14a1 1 0 0 1 1 1v13a1 1 0 0 1-1 1H5a1 1 0 0 1-1-1V6a1 1 0 0 1 1-1ZM8 12h2M14 12h2M8 16h2M14 16h2",
|
|
271
|
-
boolean: "M8 7h8a5 5 0 0 1 0 10H8A5 5 0 0 1 8 7ZM16 14a2 2 0 1 0 0-4 2 2 0 0 0 0 4Z",
|
|
272
|
-
search: "M11 18a7 7 0 1 0 0-14 7 7 0 0 0 0 14ZM20 20l-4-4",
|
|
273
|
-
x: "M6 6l12 12M18 6 6 18",
|
|
274
|
-
chevronDown: "m6 9 6 6 6-6",
|
|
275
|
-
chevronRight: "m9 6 6 6-6 6",
|
|
276
|
-
arrowUp: "M12 19V5M6 11l6-6 6 6",
|
|
277
|
-
arrowDown: "M12 5v14M6 13l6 6 6-6",
|
|
278
|
-
undo: "M9 14 4 9l5-5M4 9h10.5a5.5 5.5 0 0 1 0 11H11",
|
|
279
|
-
redo: "m15 14 5-5-5-5M20 9H9.5a5.5 5.5 0 0 0 0 11H13",
|
|
280
|
-
reset: "M3 12a9 9 0 1 0 3-6.7L3 8M3 3v5h5",
|
|
281
|
-
table: "M4 5h16v14H4zM4 10h16M4 15h16M10 5v14",
|
|
282
|
-
chart: "M4 20h16M7 16v-5M12 16V6M17 16v-8",
|
|
283
|
-
stacked: "M4 20h16M7 16v-3M7 13v-3M12 16v-4M12 12V6M17 16v-2M17 14V9",
|
|
284
|
-
horizontal: "M4 4v16M8 7h7M8 12h11M8 17h5",
|
|
285
|
-
line: "M4 18 9 12l4 3 7-9M4 20h16",
|
|
286
|
-
area: "M4 18 9 11l4 3 7-8v14H4Z",
|
|
287
|
-
pie: "M12 3a9 9 0 1 0 9 9h-9Z M15 3.5A9 9 0 0 1 20.5 9H15Z",
|
|
288
|
-
donut: "M12 3a9 9 0 1 0 9 9h-4a5 5 0 1 1-5-5Z M14.5 3.4A9 9 0 0 1 20.6 9.5h-4.1a5 5 0 0 0-2-2Z",
|
|
289
|
-
heatmap: "M4 4h7v7H4zM13 4h7v7h-7zM4 13h7v7H4zM13 13h7v7h-7z",
|
|
290
|
-
download: "M12 4v11M7 10l5 5 5-5M5 20h14",
|
|
291
|
-
bookmark: "M7 4h10a1 1 0 0 1 1 1v15l-6-4-6 4V5a1 1 0 0 1 1-1Z",
|
|
292
|
-
sliders: "M4 7h10M18 7h2M4 17h4M12 17h8M16 5v4M10 15v4",
|
|
293
|
-
filter: "M4 5h16l-6 7.5V19l-4-2v-4.5Z",
|
|
294
|
-
more: "M12 6h.01M12 12h.01M12 18h.01",
|
|
295
|
-
plus: "M12 5v14M5 12h14",
|
|
296
|
-
check: "m5 12 5 5 9-10",
|
|
297
|
-
sortAsc: "M7 4v16M3 8l4-4 4 4M14 6h7M14 12h5M14 18h3",
|
|
298
|
-
sortDesc: "M7 4v16M3 16l4 4 4-4M14 6h3M14 12h5M14 18h7",
|
|
299
|
-
panel: "M4 5h16v14H4zM9 5v14",
|
|
300
|
-
layout: "M4 5h7v6H4zM13 5h7v6h-7zM4 13h7v6H4zM13 13h7v6h-7z",
|
|
301
|
-
trash: "M5 7h14M10 11v6M14 11v6M6 7l1 13h10l1-13M9 7V4h6v3",
|
|
302
|
-
save: "M5 4h11l3 3v13H5zM8 4v5h7V4M8 20v-6h8v6",
|
|
303
|
-
sparkle: "M12 4l1.8 4.6L18 10l-4.2 1.4L12 16l-1.8-4.6L6 10l4.2-1.4Z",
|
|
304
|
-
rows: "M4 6h16M4 12h16M4 18h16",
|
|
305
|
-
cols: "M6 4v16M12 4v16M18 4v16",
|
|
306
|
-
sigma: "M18 5H6l6 7-6 7h12",
|
|
307
|
-
info: "M12 21a9 9 0 1 0 0-18 9 9 0 0 0 0 18ZM12 11v5M12 8h.01",
|
|
308
|
-
warn: "M12 4 2.8 20h18.4ZM12 10v4.5M12 17.5h.01",
|
|
309
|
-
image: "M4 5h16v14H4zM4 16l5-5 4 4 3-3 4 4M15 9h.01",
|
|
310
|
-
file: "M6 3h8l4 4v14H6zM14 3v4h4",
|
|
311
|
-
newFile: "M6 3h8l4 4v14H6zM14 3v4h4M12 11v6M9 14h6",
|
|
312
|
-
swap: "M7 4 3 8l4 4M3 8h14M17 20l4-4-4-4M21 16H7",
|
|
313
|
-
top: "M4 20v-6h5v6M9 20V8h6v12M15 20v-9h5v9M3 20h18",
|
|
314
|
-
link: "M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1",
|
|
315
|
-
copy: "M8 8h11v12H8zM5 16V4h11",
|
|
316
|
-
upload: "M12 16V5M7 10l5-5 5 5M5 20h14",
|
|
317
|
-
drag: "M12 3v18M3 12h18M12 3l-3 3M12 3l3 3M12 21l-3-3M12 21l3-3M3 12l3-3M3 12l3 3M21 12l-3-3M21 12l-3 3",
|
|
318
|
-
enlarge: "M14 4h6v6M10 20H4v-6M20 4l-7 7M4 20l7-7",
|
|
319
|
-
fullScreen: "M3 8V3h5M21 8V3h-5M3 16v5h5M21 16v5h-5"
|
|
320
|
-
};
|
|
321
|
-
function Icon({ name: name2, size = 16, className }) {
|
|
322
|
-
return /* @__PURE__ */ React.createElement("svg", { className: className ? `pk-icon ${className}` : "pk-icon", width: size, height: size, viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "1.8", strokeLinecap: "round", strokeLinejoin: "round", "aria-hidden": "true", focusable: "false" }, /* @__PURE__ */ React.createElement("path", { d: PATHS[name2] ?? PATHS.info }));
|
|
323
|
-
}
|
|
324
|
-
var TYPE_ICON = { string: "text", number: "number", date: "date", boolean: "boolean", null: "text" };
|
|
325
|
-
var ZONE_ICON = { rows: "rows", cols: "cols", values: "sigma", filters: "filter" };
|
|
326
|
-
|
|
327
|
-
// src/clear-input.jsx
|
|
328
|
-
import React2, { useRef } from "react";
|
|
329
|
-
function emptyField(el) {
|
|
330
|
-
el.focus({ preventScroll: true });
|
|
331
|
-
let done;
|
|
332
|
-
try {
|
|
333
|
-
el.select();
|
|
334
|
-
const doc = (
|
|
335
|
-
/** @type {Document & { execCommand?: (cmd: string) => boolean }} */
|
|
336
|
-
el.ownerDocument
|
|
337
|
-
);
|
|
338
|
-
done = typeof doc.execCommand === "function" && doc.execCommand("delete") && el.value === "";
|
|
339
|
-
} catch {
|
|
340
|
-
done = false;
|
|
341
|
-
}
|
|
342
|
-
if (!done) {
|
|
343
|
-
const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
344
|
-
Object.getOwnPropertyDescriptor(proto, "value")?.set?.call(el, "");
|
|
345
|
-
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
function ClearInput({ value, onChange, onClear, clearLabel, multiline = false, className, inputRef, ...rest }) {
|
|
349
|
-
const own = useRef(
|
|
350
|
-
/** @type {HTMLInputElement | HTMLTextAreaElement | null} */
|
|
351
|
-
null
|
|
352
|
-
);
|
|
353
|
-
const ref = inputRef ?? own;
|
|
354
|
-
const clear = () => {
|
|
355
|
-
if (ref.current) {
|
|
356
|
-
emptyField(ref.current);
|
|
357
|
-
}
|
|
358
|
-
onClear?.();
|
|
359
|
-
};
|
|
360
|
-
const onKeyDown = (e) => {
|
|
361
|
-
rest.onKeyDown?.(e);
|
|
362
|
-
if (e.key === "Escape" && value !== "" && !e.defaultPrevented) {
|
|
363
|
-
e.preventDefault();
|
|
364
|
-
e.stopPropagation();
|
|
365
|
-
clear();
|
|
366
|
-
}
|
|
367
|
-
};
|
|
368
|
-
const Tag = multiline ? "textarea" : "input";
|
|
369
|
-
return /* @__PURE__ */ React2.createElement("span", { className: `pk-clear-input${multiline ? " pk-clear-multi" : ""}${className ? ` ${className}` : ""}` }, /* @__PURE__ */ React2.createElement(Tag, { ...rest, ref, value, onChange: (e) => onChange(e.target.value), onKeyDown }), value !== "" ? /* @__PURE__ */ React2.createElement(
|
|
370
|
-
"button",
|
|
371
|
-
{
|
|
372
|
-
type: "button",
|
|
373
|
-
className: "pk-clear-x",
|
|
374
|
-
"aria-label": clearLabel,
|
|
375
|
-
title: clearLabel,
|
|
376
|
-
onPointerDown: (e) => e.preventDefault(),
|
|
377
|
-
onMouseDown: (e) => e.preventDefault(),
|
|
378
|
-
onClick: clear,
|
|
379
|
-
"data-testid": "clear-input"
|
|
380
|
-
},
|
|
381
|
-
/* @__PURE__ */ React2.createElement(Icon, { name: "x", size: 14 })
|
|
382
|
-
) : null);
|
|
383
|
-
}
|
|
384
|
-
|
|
385
|
-
// src/dom.js
|
|
386
|
-
import { useEffect, useRef as useRef2 } from "react";
|
|
387
|
-
var FOCUSABLE = "button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex='-1'])";
|
|
388
|
-
function rootOf(node) {
|
|
389
|
-
const root = node && typeof node.getRootNode === "function" ? node.getRootNode() : null;
|
|
390
|
-
if (root && (root.nodeType === 9 || root.nodeType === 11)) {
|
|
391
|
-
return (
|
|
392
|
-
/** @type {Document | ShadowRoot} */
|
|
393
|
-
root
|
|
394
|
-
);
|
|
395
|
-
}
|
|
396
|
-
return typeof document !== "undefined" ? document : null;
|
|
397
|
-
}
|
|
398
|
-
function activeIn(node) {
|
|
399
|
-
return rootOf(node)?.activeElement ?? null;
|
|
400
|
-
}
|
|
401
|
-
function eventWithin(event, elements) {
|
|
402
|
-
const path = typeof event.composedPath === "function" ? event.composedPath() : [];
|
|
403
|
-
return elements.some((el) => el && (path.includes(el) || event.target instanceof Node && el.contains(event.target)));
|
|
404
|
-
}
|
|
405
|
-
function tabbables(container) {
|
|
406
|
-
return (
|
|
407
|
-
/** @type {HTMLElement[]} */
|
|
408
|
-
[...container.querySelectorAll(FOCUSABLE)].filter((el) => !el.closest("[inert]") && el.getClientRects().length > 0)
|
|
409
|
-
);
|
|
410
|
-
}
|
|
411
|
-
function trapTab(event, container) {
|
|
412
|
-
if (event.key !== "Tab" || !container) {
|
|
413
|
-
return;
|
|
414
|
-
}
|
|
415
|
-
const list = tabbables(container);
|
|
416
|
-
if (list.length === 0) {
|
|
417
|
-
event.preventDefault();
|
|
418
|
-
return;
|
|
419
|
-
}
|
|
420
|
-
const first = list[0];
|
|
421
|
-
const last = list[list.length - 1];
|
|
422
|
-
const active = activeIn(container);
|
|
423
|
-
if (event.shiftKey && (active === first || !container.contains(active))) {
|
|
424
|
-
event.preventDefault();
|
|
425
|
-
last.focus();
|
|
426
|
-
} else if (!event.shiftKey && (active === last || !container.contains(active))) {
|
|
427
|
-
event.preventDefault();
|
|
428
|
-
first.focus();
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
var layers = [];
|
|
432
|
-
function useEscapeLayer(open, onClose) {
|
|
433
|
-
const close = useRef2(onClose);
|
|
434
|
-
useEffect(() => {
|
|
435
|
-
close.current = onClose;
|
|
436
|
-
});
|
|
437
|
-
useEffect(() => {
|
|
438
|
-
if (!open || typeof document === "undefined") {
|
|
439
|
-
return void 0;
|
|
440
|
-
}
|
|
441
|
-
const token = {};
|
|
442
|
-
layers.push(token);
|
|
443
|
-
const onKey = (e) => {
|
|
444
|
-
if (e.key === "Escape" && layers[layers.length - 1] === token && !e.defaultPrevented) {
|
|
445
|
-
e.preventDefault();
|
|
446
|
-
close.current();
|
|
447
|
-
}
|
|
448
|
-
};
|
|
449
|
-
document.addEventListener("keydown", onKey);
|
|
450
|
-
return () => {
|
|
451
|
-
document.removeEventListener("keydown", onKey);
|
|
452
|
-
layers.splice(layers.indexOf(token), 1);
|
|
453
|
-
};
|
|
454
|
-
}, [open]);
|
|
455
|
-
}
|
|
456
|
-
function useModal(ref, open, onClose, opener) {
|
|
457
|
-
useEscapeLayer(open, onClose);
|
|
458
|
-
useEffect(() => {
|
|
459
|
-
const el = ref.current;
|
|
460
|
-
if (!open || !el) {
|
|
461
|
-
return void 0;
|
|
462
|
-
}
|
|
463
|
-
const was = activeIn(el);
|
|
464
|
-
const plain = !was || was === el.ownerDocument.body || was.classList.contains("pk-root");
|
|
465
|
-
const back = plain && opener ? el.closest(".pk-root")?.querySelector(opener) ?? was : was;
|
|
466
|
-
const t = requestAnimationFrame(() => {
|
|
467
|
-
const first = (
|
|
468
|
-
/** @type {HTMLElement | null} */
|
|
469
|
-
el.querySelector("[data-autofocus]") ?? tabbables(el)[0] ?? el
|
|
470
|
-
);
|
|
471
|
-
first.focus({ preventScroll: true });
|
|
472
|
-
});
|
|
473
|
-
return () => {
|
|
474
|
-
cancelAnimationFrame(t);
|
|
475
|
-
const target = (
|
|
476
|
-
/** @type {HTMLElement | null} */
|
|
477
|
-
back
|
|
478
|
-
);
|
|
479
|
-
const now = activeIn(el);
|
|
480
|
-
if (target && target.isConnected && (!now || el.contains(now) || now === el.ownerDocument.body)) {
|
|
481
|
-
target.focus({ preventScroll: true });
|
|
482
|
-
}
|
|
483
|
-
};
|
|
484
|
-
}, [ref, open, opener]);
|
|
485
|
-
return { onKeyDown: (e) => trapTab(e, ref.current) };
|
|
486
|
-
}
|
|
487
|
-
|
|
488
|
-
// src/iso.js
|
|
489
|
-
import { useEffect as useEffect2, useLayoutEffect } from "react";
|
|
490
|
-
var useIsoLayoutEffect = typeof window !== "undefined" && typeof document !== "undefined" ? useLayoutEffect : useEffect2;
|
|
491
|
-
|
|
492
|
-
// src/popover.jsx
|
|
493
|
-
import React3, { createContext, useCallback, useContext, useEffect as useEffect3, useId, useRef as useRef3, useState } from "react";
|
|
494
|
-
import { createPortal } from "react-dom";
|
|
495
|
-
|
|
496
|
-
// src/place.js
|
|
497
|
-
var MARGIN = 8;
|
|
498
|
-
var GAP = 6;
|
|
499
|
-
function viewportOf(doc) {
|
|
500
|
-
const root = doc.documentElement;
|
|
501
|
-
const win = doc.defaultView;
|
|
502
|
-
return { width: root?.clientWidth || win?.innerWidth || 0, height: root?.clientHeight || win?.innerHeight || 0 };
|
|
503
|
-
}
|
|
504
|
-
function placePopover(anchor, size, viewport, align = "start", { fill: fill2 = false } = {}) {
|
|
505
|
-
const below = viewport.height - anchor.bottom - GAP - MARGIN;
|
|
506
|
-
const above = anchor.top - GAP - MARGIN;
|
|
507
|
-
const wanted = align === "end" ? anchor.right - size.width : anchor.left;
|
|
508
|
-
const left = Math.max(MARGIN, Math.min(wanted, viewport.width - size.width - MARGIN));
|
|
509
|
-
const most = Math.max(0, viewport.height - 2 * MARGIN);
|
|
510
|
-
if (fill2 && size.height > below && size.height > above) {
|
|
511
|
-
const height2 = Math.min(size.height, most);
|
|
512
|
-
const side2 = below >= above ? "below" : "above";
|
|
513
|
-
const near = side2 === "below" ? anchor.bottom + GAP : anchor.top - GAP - height2;
|
|
514
|
-
return { top: Math.max(MARGIN, Math.min(near, viewport.height - MARGIN - height2)), left, maxHeight: most, side: side2 };
|
|
515
|
-
}
|
|
516
|
-
const side = size.height <= below || below >= above ? "below" : "above";
|
|
517
|
-
const room = side === "below" ? below : above;
|
|
518
|
-
const height = Math.min(size.height, room);
|
|
519
|
-
const top = side === "below" ? anchor.bottom + GAP : anchor.top - GAP - height;
|
|
520
|
-
return { top: Math.max(MARGIN, top), left, maxHeight: Math.max(120, room), side };
|
|
521
|
-
}
|
|
522
|
-
var KEEP_ROOM = 240;
|
|
523
|
-
function keepPlace(last, next, anchor, size, viewport) {
|
|
524
|
-
if (!last || last.anchorTop !== anchor.top || last.side === next.side) {
|
|
525
|
-
return next;
|
|
526
|
-
}
|
|
527
|
-
const room = last.side === "below" ? viewport.height - anchor.bottom - GAP - MARGIN : anchor.top - GAP - MARGIN;
|
|
528
|
-
if (room < Math.min(size.height, KEEP_ROOM)) {
|
|
529
|
-
return next;
|
|
530
|
-
}
|
|
531
|
-
const height = Math.min(size.height, room);
|
|
532
|
-
const top = last.side === "below" ? anchor.bottom + GAP : anchor.top - GAP - height;
|
|
533
|
-
return { ...next, top: Math.max(MARGIN, top), maxHeight: room, side: last.side };
|
|
534
|
-
}
|
|
535
|
-
function fromOrigin(place, origin) {
|
|
536
|
-
return { ...place, top: place.top - origin.top, left: place.left - origin.left };
|
|
537
|
-
}
|
|
538
|
-
|
|
539
|
-
// src/popover.jsx
|
|
540
|
-
var LayerContext = createContext({ layer: (
|
|
541
|
-
/** @type {HTMLElement | null} */
|
|
542
|
-
null
|
|
543
|
-
), size: "wide" });
|
|
544
|
-
var OPTION = "[data-pk-option]:not([disabled])";
|
|
545
|
-
function wheelScrollsInside(path, popover, dx, dy) {
|
|
546
|
-
for (const node of path) {
|
|
547
|
-
if (!(node instanceof Element)) {
|
|
548
|
-
continue;
|
|
549
|
-
}
|
|
550
|
-
const style = node.ownerDocument.defaultView?.getComputedStyle(node);
|
|
551
|
-
const scrolls = (overflow) => overflow === "auto" || overflow === "scroll";
|
|
552
|
-
if (style && scrolls(style.overflowY) && (dy < 0 && node.scrollTop > 0 || dy > 0 && node.scrollTop + node.clientHeight < node.scrollHeight - 1)) {
|
|
553
|
-
return true;
|
|
554
|
-
}
|
|
555
|
-
if (style && scrolls(style.overflowX) && (dx < 0 && node.scrollLeft > 0 || dx > 0 && node.scrollLeft + node.clientWidth < node.scrollWidth - 1)) {
|
|
556
|
-
return true;
|
|
557
|
-
}
|
|
558
|
-
if (node === popover) {
|
|
559
|
-
return false;
|
|
560
|
-
}
|
|
561
|
-
}
|
|
562
|
-
return false;
|
|
563
|
-
}
|
|
564
|
-
function Popover({ open, anchor, onClose, label, role = "dialog", align = "start", className, id, passive = false, fill: fill2 = false, onPointerEnter, onPointerLeave, children }) {
|
|
565
|
-
const { layer, size } = useContext(LayerContext);
|
|
566
|
-
const ref = useRef3(
|
|
567
|
-
/** @type {HTMLDivElement | null} */
|
|
568
|
-
null
|
|
569
|
-
);
|
|
570
|
-
const ownId = useId();
|
|
571
|
-
const elId = id ?? ownId;
|
|
572
|
-
const parentId = anchor.current?.closest?.(".pk-popover")?.id;
|
|
573
|
-
const within = (n) => n === ref.current || n.getAttribute("data-pk-parent") === elId;
|
|
574
|
-
const [pos, setPos] = useState(
|
|
575
|
-
/** @type {null | { top: number, left: number, maxHeight: number, side: string }} */
|
|
576
|
-
null
|
|
577
|
-
);
|
|
578
|
-
const sheet = size === "narrow" && !passive;
|
|
579
|
-
useIsoLayoutEffect(() => {
|
|
580
|
-
if (!open) {
|
|
581
|
-
setPos(null);
|
|
582
|
-
return void 0;
|
|
583
|
-
}
|
|
584
|
-
let last = null;
|
|
585
|
-
const place = () => {
|
|
586
|
-
const el2 = ref.current;
|
|
587
|
-
const a = anchor.current;
|
|
588
|
-
if (!el2 || !a || sheet) {
|
|
589
|
-
return;
|
|
590
|
-
}
|
|
591
|
-
const r = a.getBoundingClientRect();
|
|
592
|
-
const size2 = { width: el2.offsetWidth, height: el2.scrollHeight };
|
|
593
|
-
const viewport = viewportOf(el2.ownerDocument);
|
|
594
|
-
const place2 = keepPlace(last, placePopover(r, size2, viewport, align, { fill: fill2 }), r, size2, viewport);
|
|
595
|
-
last = { top: place2.top, side: place2.side, anchorTop: r.top };
|
|
596
|
-
const probe = layer?.querySelector(".pk-origin");
|
|
597
|
-
setPos(probe ? fromOrigin(place2, probe.getBoundingClientRect()) : place2);
|
|
598
|
-
};
|
|
599
|
-
place();
|
|
600
|
-
const el = ref.current;
|
|
601
|
-
const ro = typeof ResizeObserver === "function" && el ? new ResizeObserver(place) : null;
|
|
602
|
-
if (ro && el) {
|
|
603
|
-
ro.observe(el);
|
|
604
|
-
}
|
|
605
|
-
window.addEventListener("resize", place);
|
|
606
|
-
window.addEventListener("scroll", place, true);
|
|
607
|
-
return () => {
|
|
608
|
-
ro?.disconnect();
|
|
609
|
-
window.removeEventListener("resize", place);
|
|
610
|
-
window.removeEventListener("scroll", place, true);
|
|
611
|
-
};
|
|
612
|
-
}, [open, anchor, align, sheet, layer, fill2]);
|
|
613
|
-
useEscapeLayer(open, onClose);
|
|
614
|
-
const closeRef = useRef3(onClose);
|
|
615
|
-
useEffect3(() => {
|
|
616
|
-
closeRef.current = onClose;
|
|
617
|
-
});
|
|
618
|
-
useEffect3(() => {
|
|
619
|
-
if (!open || passive) {
|
|
620
|
-
return void 0;
|
|
621
|
-
}
|
|
622
|
-
const el = ref.current;
|
|
623
|
-
const shown = (o) => o.getClientRects().length > 0;
|
|
624
|
-
const first = el?.querySelector("[data-autofocus]") ?? [...el?.querySelectorAll(OPTION) ?? []].find(shown) ?? [...el?.querySelectorAll(FOCUSABLE) ?? []].find((o) => shown(o) && !o.classList.contains("pk-info")) ?? (el?.querySelector("[data-pk-option]") ? el : null);
|
|
625
|
-
const t = requestAnimationFrame(() => (
|
|
626
|
-
/** @type {HTMLElement | null} */
|
|
627
|
-
first?.focus({ preventScroll: true })
|
|
628
|
-
));
|
|
629
|
-
const onDown = (e) => {
|
|
630
|
-
if (!eventWithin(e, [el, anchor.current]) && !e.composedPath().some((n) => n instanceof Element && n !== el && n.getAttribute("data-pk-parent") === elId)) {
|
|
631
|
-
closeRef.current();
|
|
632
|
-
}
|
|
633
|
-
};
|
|
634
|
-
const doc = el?.ownerDocument ?? document;
|
|
635
|
-
doc.addEventListener("pointerdown", onDown, true);
|
|
636
|
-
const onWheel = (e) => {
|
|
637
|
-
if (el && !e.ctrlKey && !wheelScrollsInside(e.composedPath(), el, e.deltaX, e.deltaY)) {
|
|
638
|
-
e.preventDefault();
|
|
639
|
-
}
|
|
640
|
-
};
|
|
641
|
-
el?.addEventListener("wheel", onWheel, { passive: false });
|
|
642
|
-
const button = anchor.current;
|
|
643
|
-
return () => {
|
|
644
|
-
cancelAnimationFrame(t);
|
|
645
|
-
doc.removeEventListener("pointerdown", onDown, true);
|
|
646
|
-
el?.removeEventListener("wheel", onWheel);
|
|
647
|
-
const now = activeIn(button);
|
|
648
|
-
if (button && button.isConnected && (!now || now === doc.body || el?.contains(now) || !now.isConnected)) {
|
|
649
|
-
button.focus({ preventScroll: true });
|
|
650
|
-
}
|
|
651
|
-
};
|
|
652
|
-
}, [open, anchor, passive, elId]);
|
|
653
|
-
if (!open || !layer) {
|
|
654
|
-
return null;
|
|
655
|
-
}
|
|
656
|
-
const onKeyDown = (e) => {
|
|
657
|
-
if (role === "menu" && e.key === "Tab") {
|
|
658
|
-
e.preventDefault();
|
|
659
|
-
onClose();
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
if (sheet) {
|
|
663
|
-
trapTab(e, ref.current);
|
|
664
|
-
}
|
|
665
|
-
if (e.key === "ArrowDown" || e.key === "ArrowUp" || e.key === "Home" || e.key === "End") {
|
|
666
|
-
const options = (
|
|
667
|
-
/** @type {HTMLElement[]} */
|
|
668
|
-
[...ref.current?.querySelectorAll(OPTION) ?? []].filter((o) => o.getClientRects().length > 0)
|
|
669
|
-
);
|
|
670
|
-
if (options.length === 0 || e.target instanceof HTMLInputElement && e.target.type !== "checkbox") {
|
|
671
|
-
return;
|
|
672
|
-
}
|
|
673
|
-
e.preventDefault();
|
|
674
|
-
const at = options.indexOf(
|
|
675
|
-
/** @type {HTMLElement} */
|
|
676
|
-
activeIn(ref.current)
|
|
677
|
-
);
|
|
678
|
-
const next = e.key === "Home" ? 0 : e.key === "End" ? options.length - 1 : (at + (e.key === "ArrowDown" ? 1 : -1) + options.length) % options.length;
|
|
679
|
-
options[next].focus();
|
|
680
|
-
}
|
|
681
|
-
};
|
|
682
|
-
const onBlur = (e) => {
|
|
683
|
-
const to = (
|
|
684
|
-
/** @type {Node | null} */
|
|
685
|
-
e.relatedTarget
|
|
686
|
-
);
|
|
687
|
-
if (to && !ref.current?.contains(to) && !anchor.current?.contains(to) && !(to instanceof Element && [...to.ownerDocument.querySelectorAll(".pk-popover")].some((p) => p.contains(to) && within(p)))) {
|
|
688
|
-
onClose();
|
|
689
|
-
}
|
|
690
|
-
};
|
|
691
|
-
const style = sheet ? void 0 : pos ? { top: pos.top, left: pos.left, maxHeight: pos.maxHeight } : { top: 0, left: 0, visibility: (
|
|
692
|
-
/** @type {const} */
|
|
693
|
-
"hidden"
|
|
694
|
-
) };
|
|
695
|
-
return createPortal(
|
|
696
|
-
/* @__PURE__ */ React3.createElement(React3.Fragment, null, sheet ? /* @__PURE__ */ React3.createElement("div", { className: "pk-scrim", onClick: onClose, "aria-hidden": "true" }) : null, /* @__PURE__ */ React3.createElement(
|
|
697
|
-
"div",
|
|
698
|
-
{
|
|
699
|
-
ref,
|
|
700
|
-
id: elId,
|
|
701
|
-
"data-pk-parent": parentId,
|
|
702
|
-
role,
|
|
703
|
-
"aria-label": passive ? void 0 : label,
|
|
704
|
-
"aria-modal": sheet && role === "dialog" ? true : void 0,
|
|
705
|
-
className: `pk-popover${sheet ? " pk-sheet" : ""}${pos?.side === "above" ? " pk-above" : ""}${className ? ` ${className}` : ""}`,
|
|
706
|
-
style,
|
|
707
|
-
onKeyDown,
|
|
708
|
-
onBlur: sheet || passive ? void 0 : onBlur,
|
|
709
|
-
onPointerEnter,
|
|
710
|
-
onPointerLeave,
|
|
711
|
-
tabIndex: passive ? void 0 : -1
|
|
712
|
-
},
|
|
713
|
-
children
|
|
714
|
-
)),
|
|
715
|
-
layer
|
|
716
|
-
);
|
|
717
|
-
}
|
|
718
|
-
function MenuButton({ label, icon, text, showText = true, className, role = "menu", align, popoverClass, disabled, title, children, testId, buttonRef, name: name2, tabIndex, slot, fill: fill2, mark }) {
|
|
719
|
-
const [open, setOpen] = useState(false);
|
|
720
|
-
const own = useRef3(
|
|
721
|
-
/** @type {HTMLButtonElement | null} */
|
|
722
|
-
null
|
|
723
|
-
);
|
|
724
|
-
const ref = buttonRef ?? own;
|
|
725
|
-
const id = useId();
|
|
726
|
-
const close = useCallback(() => setOpen(false), []);
|
|
727
|
-
return /* @__PURE__ */ React3.createElement(React3.Fragment, null, /* @__PURE__ */ React3.createElement(
|
|
728
|
-
"button",
|
|
729
|
-
{
|
|
730
|
-
ref,
|
|
731
|
-
type: "button",
|
|
732
|
-
className: className ?? "pk-btn",
|
|
733
|
-
"aria-haspopup": role === "menu" ? "menu" : "dialog",
|
|
734
|
-
"aria-expanded": open,
|
|
735
|
-
"aria-controls": open ? id : void 0,
|
|
736
|
-
"aria-label": name2 ?? (showText && text ? void 0 : label),
|
|
737
|
-
title: title ?? (showText && text ? void 0 : label),
|
|
738
|
-
disabled,
|
|
739
|
-
tabIndex,
|
|
740
|
-
"data-pk-slot": slot,
|
|
741
|
-
"data-testid": testId,
|
|
742
|
-
onClick: () => setOpen((o) => !o)
|
|
743
|
-
},
|
|
744
|
-
icon ? /* @__PURE__ */ React3.createElement(Icon, { name: (
|
|
745
|
-
/** @type {any} */
|
|
746
|
-
icon
|
|
747
|
-
) }) : null,
|
|
748
|
-
showText && text ? /* @__PURE__ */ React3.createElement("span", { className: "pk-btn-text" }, text) : null,
|
|
749
|
-
mark,
|
|
750
|
-
showText && text ? /* @__PURE__ */ React3.createElement(Icon, { name: "chevronDown", size: 14, className: "pk-caret" }) : null
|
|
751
|
-
), /* @__PURE__ */ React3.createElement(Popover, { open, anchor: ref, onClose: close, label, role, align, className: popoverClass, id, fill: fill2 }, children(close)));
|
|
752
|
-
}
|
|
753
|
-
function Option({ onSelect, icon, checked, children, hint, reason, inMenu = false, disabled, danger, tone, testId, current }) {
|
|
754
|
-
const second = disabled && reason ? reason : hint;
|
|
755
|
-
const role = inMenu ? checked === void 0 ? "menuitem" : "menuitemradio" : void 0;
|
|
756
|
-
return /* @__PURE__ */ React3.createElement(
|
|
757
|
-
"button",
|
|
758
|
-
{
|
|
759
|
-
type: "button",
|
|
760
|
-
role,
|
|
761
|
-
"aria-checked": inMenu && checked !== void 0 ? checked : void 0,
|
|
762
|
-
"aria-pressed": !inMenu && checked !== void 0 ? checked : void 0,
|
|
763
|
-
"aria-current": current ? "true" : void 0,
|
|
764
|
-
className: `pk-option${checked ? " pk-checked" : ""}${danger ? " pk-danger" : ""}${tone === "accent" ? " pk-accent" : ""}`,
|
|
765
|
-
"data-pk-option": "",
|
|
766
|
-
"data-testid": testId,
|
|
767
|
-
disabled,
|
|
768
|
-
onClick: onSelect
|
|
769
|
-
},
|
|
770
|
-
/* @__PURE__ */ React3.createElement("span", { className: "pk-option-icon" }, checked || current ? /* @__PURE__ */ React3.createElement(Icon, { name: "check" }) : icon ? /* @__PURE__ */ React3.createElement(Icon, { name: (
|
|
771
|
-
/** @type {any} */
|
|
772
|
-
icon
|
|
773
|
-
) }) : null),
|
|
774
|
-
/* @__PURE__ */ React3.createElement("span", { className: "pk-option-text" }, children, second ? /* @__PURE__ */ React3.createElement("span", { className: "pk-option-hint" }, second) : null)
|
|
775
|
-
);
|
|
776
|
-
}
|
|
777
|
-
|
|
778
|
-
// src/info.jsx
|
|
779
|
-
import React4, { useCallback as useCallback2, useEffect as useEffect4, useId as useId2, useRef as useRef4, useState as useState2 } from "react";
|
|
780
|
-
var LEAVE_DELAY = 250;
|
|
781
|
-
function FieldDescription({ info, labels, link = true, className = "pk-field-desc" }) {
|
|
782
|
-
return /* @__PURE__ */ React4.createElement("p", { className }, /* @__PURE__ */ React4.createElement("span", null, info.description), link && info.href ? /* @__PURE__ */ React4.createElement(React4.Fragment, null, " ", /* @__PURE__ */ React4.createElement("a", { href: info.href, target: "_blank", rel: "noopener noreferrer", className: "pk-learn-more" }, labels.learnMore)) : null);
|
|
783
|
-
}
|
|
784
|
-
function InfoButton({ info, name: name2, labels, className, testId = "field-info", label: named, tabIndex, slot }) {
|
|
785
|
-
const [mode, setMode] = useState2(
|
|
786
|
-
/** @type {null | "peek" | "open"} */
|
|
787
|
-
null
|
|
788
|
-
);
|
|
789
|
-
const ref = useRef4(
|
|
790
|
-
/** @type {HTMLButtonElement | null} */
|
|
791
|
-
null
|
|
792
|
-
);
|
|
793
|
-
const quiet = useRef4(false);
|
|
794
|
-
const leaving = useRef4(
|
|
795
|
-
/** @type {ReturnType<typeof setTimeout> | null} */
|
|
796
|
-
null
|
|
797
|
-
);
|
|
798
|
-
const id = useId2();
|
|
799
|
-
const textId = useId2();
|
|
800
|
-
const stay = () => {
|
|
801
|
-
if (leaving.current) {
|
|
802
|
-
clearTimeout(leaving.current);
|
|
803
|
-
leaving.current = null;
|
|
804
|
-
}
|
|
805
|
-
};
|
|
806
|
-
const leaveSoon = () => {
|
|
807
|
-
stay();
|
|
808
|
-
leaving.current = setTimeout(() => setMode((m) => m === "peek" ? null : m), LEAVE_DELAY);
|
|
809
|
-
};
|
|
810
|
-
useEffect4(() => stay, []);
|
|
811
|
-
const close = useCallback2(() => {
|
|
812
|
-
quiet.current = true;
|
|
813
|
-
setMode(null);
|
|
814
|
-
requestAnimationFrame(() => {
|
|
815
|
-
quiet.current = false;
|
|
816
|
-
});
|
|
817
|
-
}, []);
|
|
818
|
-
const label = named ?? fill(labels.aboutField, { field: name2 });
|
|
819
|
-
return /* @__PURE__ */ React4.createElement(React4.Fragment, null, /* @__PURE__ */ React4.createElement(
|
|
820
|
-
"button",
|
|
821
|
-
{
|
|
822
|
-
ref,
|
|
823
|
-
type: "button",
|
|
824
|
-
className: `pk-info${className ? ` ${className}` : ""}`,
|
|
825
|
-
"aria-label": label,
|
|
826
|
-
"aria-describedby": textId,
|
|
827
|
-
"aria-expanded": mode === "open",
|
|
828
|
-
"aria-controls": mode ? id : void 0,
|
|
829
|
-
"aria-haspopup": "dialog",
|
|
830
|
-
tabIndex,
|
|
831
|
-
"data-pk-slot": slot,
|
|
832
|
-
"data-testid": testId,
|
|
833
|
-
onPointerEnter: (e) => {
|
|
834
|
-
if (e.pointerType === "mouse") {
|
|
835
|
-
stay();
|
|
836
|
-
setMode((m) => m ?? "peek");
|
|
837
|
-
}
|
|
838
|
-
},
|
|
839
|
-
onPointerLeave: (e) => {
|
|
840
|
-
if (e.pointerType === "mouse" && mode === "peek") {
|
|
841
|
-
leaveSoon();
|
|
842
|
-
}
|
|
843
|
-
},
|
|
844
|
-
onFocus: () => {
|
|
845
|
-
if (mode === null && !quiet.current) {
|
|
846
|
-
setMode("peek");
|
|
847
|
-
}
|
|
848
|
-
},
|
|
849
|
-
onBlur: (e) => {
|
|
850
|
-
const to = (
|
|
851
|
-
/** @type {Element | null} */
|
|
852
|
-
e.relatedTarget
|
|
853
|
-
);
|
|
854
|
-
if (mode === "peek" && !(to && to.closest?.(".pk-info-pop"))) {
|
|
855
|
-
setMode(null);
|
|
856
|
-
}
|
|
857
|
-
},
|
|
858
|
-
onClick: () => {
|
|
859
|
-
stay();
|
|
860
|
-
setMode(mode === "open" ? null : "open");
|
|
861
|
-
}
|
|
862
|
-
},
|
|
863
|
-
/* @__PURE__ */ React4.createElement(Icon, { name: "info", size: 14 })
|
|
864
|
-
), /* @__PURE__ */ React4.createElement("span", { id: textId, hidden: true }, info.description), /* @__PURE__ */ React4.createElement(
|
|
865
|
-
Popover,
|
|
866
|
-
{
|
|
867
|
-
key: mode ?? "closed",
|
|
868
|
-
open: mode !== null,
|
|
869
|
-
passive: mode === "peek",
|
|
870
|
-
anchor: ref,
|
|
871
|
-
onClose: close,
|
|
872
|
-
label,
|
|
873
|
-
role: mode === "peek" ? "tooltip" : "dialog",
|
|
874
|
-
className: "pk-info-pop",
|
|
875
|
-
id,
|
|
876
|
-
onPointerEnter: stay,
|
|
877
|
-
onPointerLeave: (e) => {
|
|
878
|
-
if (e.pointerType === "mouse" && mode === "peek") {
|
|
879
|
-
leaveSoon();
|
|
880
|
-
}
|
|
881
|
-
}
|
|
882
|
-
},
|
|
883
|
-
/* @__PURE__ */ React4.createElement(FieldDescription, { info, labels })
|
|
884
|
-
));
|
|
38
|
+
return CHART_TYPE_NAMES.find((name2) => CHART_TYPES[name2].chart.type === chart2.type) ?? "bar";
|
|
39
|
+
}
|
|
40
|
+
function chartPlan(view, encoded) {
|
|
41
|
+
const plan = corePlan(view, encoded);
|
|
42
|
+
return { name: chartTypeOf(plan.chart), ...plan };
|
|
885
43
|
}
|
|
44
|
+
var MANY_SERIES = 8;
|
|
45
|
+
var MAX_CATEGORIES = 50;
|
|
886
46
|
|
|
887
47
|
// src/view-ops.js
|
|
888
|
-
import { LIMITS, aggregatorsFor, isFormat } from "pivotkit-core";
|
|
48
|
+
import { LIMITS, aggregatorsFor, foldText, isFormat, swapAxes } from "pivotkit-core";
|
|
889
49
|
var ZONES = Object.freeze(
|
|
890
50
|
/** @type {Zone[]} */
|
|
891
51
|
["filters", "cols", "rows", "values"]
|
|
892
52
|
);
|
|
893
53
|
var clone = (view) => JSON.parse(JSON.stringify(view));
|
|
54
|
+
var NEGATED = Object.freeze({ "=": "!=", between: "notBetween", equals: "notEquals", contains: "notContains", beginsWith: "notBeginsWith", endsWith: "notEndsWith" });
|
|
55
|
+
var RULE_OPS = Object.freeze({
|
|
56
|
+
text: Object.freeze(["equals", "notEquals", "contains", "notContains", "beginsWith", "notBeginsWith", "endsWith", "notEndsWith"]),
|
|
57
|
+
compare: Object.freeze(["=", "!=", ">", ">=", "<", "<=", "between", "notBetween"])
|
|
58
|
+
});
|
|
59
|
+
var ruleOp = (f) => f.not && typeof f.op === "string" && Object.hasOwn(NEGATED, f.op) ? NEGATED[f.op] : String(f.op);
|
|
60
|
+
var hiddenNot = (f) => Boolean(f.not) && !(typeof f.op === "string" && Object.hasOwn(NEGATED, f.op));
|
|
61
|
+
function opOf(menuOp) {
|
|
62
|
+
const positive = Object.keys(NEGATED).find((op) => NEGATED[op] === menuOp);
|
|
63
|
+
return positive ? { op: positive, not: true } : { op: menuOp, not: false };
|
|
64
|
+
}
|
|
65
|
+
var pickFilter = (field, excluded) => ({ field, type: "in", items: excluded.filter((v) => v !== null), not: true, blanks: excluded.includes(null) ? "exclude" : "include" });
|
|
66
|
+
var emptyPick = (field) => pickFilter(field, []);
|
|
67
|
+
var isPick = (f) => f.type === "in";
|
|
68
|
+
var isEmptyPick = (f) => isPick(f) && f.not === true && f.items.length === 0 && f.blanks === "include";
|
|
894
69
|
var same = (a, b) => typeof a === "string" && typeof b === "string" && a.toLowerCase() === b.toLowerCase();
|
|
70
|
+
function searchItems(items, query) {
|
|
71
|
+
const q = foldText(query);
|
|
72
|
+
return q ? items.filter((i) => foldText(i.label).includes(q)) : items;
|
|
73
|
+
}
|
|
895
74
|
var clamp = (i, n) => Number.isInteger(i) ? Math.max(0, Math.min(i, n)) : n;
|
|
896
75
|
function filterZoneFields(view) {
|
|
897
76
|
const seen = /* @__PURE__ */ new Set();
|
|
@@ -972,7 +151,7 @@ function addField(view, field, zone, options = {}) {
|
|
|
972
151
|
} else if (zone === "filters") {
|
|
973
152
|
dropFromAxes(next, field);
|
|
974
153
|
if (!next.filters.some((f) => same(f.field, field))) {
|
|
975
|
-
next.filters.push(
|
|
154
|
+
next.filters.push(emptyPick(field));
|
|
976
155
|
}
|
|
977
156
|
}
|
|
978
157
|
resetCollapsed(next, view);
|
|
@@ -1103,7 +282,7 @@ function groupField(view, field, unit, options = {}) {
|
|
|
1103
282
|
const inFilterZone = !axis && filterZoneFields(view).some((f) => same(f, field));
|
|
1104
283
|
next.filters = next.filters.filter((f) => !same(f.field, field));
|
|
1105
284
|
if (inFilterZone) {
|
|
1106
|
-
next.filters.push(
|
|
285
|
+
next.filters.push(emptyPick(name2));
|
|
1107
286
|
}
|
|
1108
287
|
}
|
|
1109
288
|
next.sort = next.sort.map((s) => same(s.field, field) ? { ...s, field: name2 } : s);
|
|
@@ -1179,9 +358,10 @@ function filtersOf(view, field, types) {
|
|
|
1179
358
|
}
|
|
1180
359
|
function selectedItems(view, field, all) {
|
|
1181
360
|
let selected = all;
|
|
1182
|
-
for (const f of filtersOf(view, field, ["
|
|
361
|
+
for (const f of filtersOf(view, field, ["in"])) {
|
|
1183
362
|
const listed = new Set(f.items.map((v) => JSON.stringify(v)));
|
|
1184
|
-
|
|
363
|
+
const blank = f.blanks !== "exclude";
|
|
364
|
+
selected = selected.filter((v) => v === null ? blank : f.blanks !== "only" && listed.has(JSON.stringify(v)) !== f.not);
|
|
1185
365
|
}
|
|
1186
366
|
return selected;
|
|
1187
367
|
}
|
|
@@ -1192,7 +372,7 @@ function sameRef(a, b) {
|
|
|
1192
372
|
return Boolean(a && b) && a.agg === b.agg && (a.field === null || b.field === null ? a.field === b.field : same(a.field, b.field));
|
|
1193
373
|
}
|
|
1194
374
|
function isFiltered(view, field) {
|
|
1195
|
-
return filtersOf(view, field).some((f) => f
|
|
375
|
+
return filtersOf(view, field).some((f) => !isEmptyPick(f));
|
|
1196
376
|
}
|
|
1197
377
|
function toggleCollapsed(view, axis, path) {
|
|
1198
378
|
const next = clone(view);
|
|
@@ -1204,82 +384,545 @@ function toggleCollapsed(view, axis, path) {
|
|
|
1204
384
|
} else {
|
|
1205
385
|
list.splice(at, 1);
|
|
1206
386
|
}
|
|
1207
|
-
return next;
|
|
387
|
+
return next;
|
|
388
|
+
}
|
|
389
|
+
function rowFolding(view, outer) {
|
|
390
|
+
const keys = new Set(view.collapsed.rows.map((p) => JSON.stringify(p)));
|
|
391
|
+
const collapsed = outer.filter((p) => keys.has(JSON.stringify(p))).length;
|
|
392
|
+
const open = view.rows.length < 2 ? 0 : outer.length - collapsed;
|
|
393
|
+
const canExpand = view.collapsed.rows.length > 0;
|
|
394
|
+
const canCollapse = open > 0;
|
|
395
|
+
return {
|
|
396
|
+
canExpand,
|
|
397
|
+
canCollapse,
|
|
398
|
+
collapsed: view.collapsed.rows.length,
|
|
399
|
+
open,
|
|
400
|
+
// keys of the menus' texts (menu-labels.js): the Options menu shows them with its labels
|
|
401
|
+
why: {
|
|
402
|
+
expand: canExpand ? null : "expandNothing",
|
|
403
|
+
collapse: canCollapse ? null : view.rows.length < 2 ? "collapseNeedsRows" : "collapseAllDone"
|
|
404
|
+
}
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
function setCollapsed(view, axis, paths) {
|
|
408
|
+
const next = clone(view);
|
|
409
|
+
next.collapsed[axis] = paths ? paths : [];
|
|
410
|
+
return next;
|
|
411
|
+
}
|
|
412
|
+
function setTotal(view, key, on) {
|
|
413
|
+
const next = clone(view);
|
|
414
|
+
next.totals[key] = Boolean(on);
|
|
415
|
+
return next;
|
|
416
|
+
}
|
|
417
|
+
function setDisplay(view, display) {
|
|
418
|
+
const next = clone(view);
|
|
419
|
+
next.display = display;
|
|
420
|
+
return next;
|
|
421
|
+
}
|
|
422
|
+
function setChart(view, name2) {
|
|
423
|
+
const next = clone(view);
|
|
424
|
+
next.chart = { ...next.chart, ...CHART_TYPES[name2].chart };
|
|
425
|
+
next.display = "chart";
|
|
426
|
+
return next;
|
|
427
|
+
}
|
|
428
|
+
function setChartDisplay(view, patch) {
|
|
429
|
+
const next = clone(view);
|
|
430
|
+
next.chart = { ...next.chart, ...patch };
|
|
431
|
+
return next;
|
|
432
|
+
}
|
|
433
|
+
function isEmptyView(view) {
|
|
434
|
+
return view.rows.length === 0 && view.cols.length === 0 && view.values.length === 0;
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// src/names.js
|
|
438
|
+
import { fieldLabel, relativeDateRange } from "pivotkit-core";
|
|
439
|
+
var withNot = (f, text, labels) => hiddenNot(f) ? fill(labels.notRule, { rule: text }) : text;
|
|
440
|
+
function valueLabel(spec, labels) {
|
|
441
|
+
if (spec.label) {
|
|
442
|
+
return spec.label;
|
|
443
|
+
}
|
|
444
|
+
const core = labels.core;
|
|
445
|
+
let base;
|
|
446
|
+
if (!spec.field) {
|
|
447
|
+
base = core.countRows;
|
|
448
|
+
} else {
|
|
449
|
+
const agg = Object.hasOwn(core.aggregators, spec.agg) ? core.aggregators[spec.agg] : spec.agg;
|
|
450
|
+
base = fill(core.valueName, { agg, field: fieldLabel(spec.field, core) });
|
|
451
|
+
}
|
|
452
|
+
if (!spec.showAs || !core.showAs || !core.showAsName) {
|
|
453
|
+
return base;
|
|
454
|
+
}
|
|
455
|
+
const showAs = Object.hasOwn(core.showAs, spec.showAs.type) ? core.showAs[spec.showAs.type] : spec.showAs.type;
|
|
456
|
+
return fill(core.showAsName, { showAs, value: spec.field && spec.agg === "sum" ? fieldLabel(spec.field, core) : base });
|
|
457
|
+
}
|
|
458
|
+
function refLabel(view, ref, labels) {
|
|
459
|
+
const field = ref?.field ?? null;
|
|
460
|
+
const sameField = (v) => field === null || v.field === null || v.field === void 0 ? (v.field ?? null) === field : v.field.toLowerCase() === field.toLowerCase();
|
|
461
|
+
const spec = ref ? (view.values ?? []).find((v) => v.agg === ref.agg && sameField(v)) : void 0;
|
|
462
|
+
if (!spec && field === null) {
|
|
463
|
+
return labels.countOfRows;
|
|
464
|
+
}
|
|
465
|
+
return valueLabel({ ...spec ?? ref, showAs: null }, labels);
|
|
466
|
+
}
|
|
467
|
+
function sortText(view, sort, labels) {
|
|
468
|
+
const desc = sort.order === "desc";
|
|
469
|
+
if (sort.by === "value") {
|
|
470
|
+
return fill(desc ? labels.sortValueDesc : labels.sortValueAsc, { value: refLabel(view, sort.value, labels) });
|
|
471
|
+
}
|
|
472
|
+
if (sort.by === "custom") {
|
|
473
|
+
return desc ? labels.sortCustomDesc : labels.sortCustom;
|
|
474
|
+
}
|
|
475
|
+
return desc ? labels.sortLabelDesc : labels.sortLabelAsc;
|
|
476
|
+
}
|
|
477
|
+
var OP_SIGNS = Object.freeze({ "=": "=", "!=": "\u2260", ">": ">", ">=": "\u2265", "<": "<", "<=": "\u2264" });
|
|
478
|
+
function valueConditionText(view, f, labels, locale) {
|
|
479
|
+
const number = (x) => typeof x === "number" ? x.toLocaleString(locale, { maximumFractionDigits: 6 }) : "";
|
|
480
|
+
const value = refLabel(view, f.by ?? (view.values?.[0] ? { field: view.values[0].field ?? null, agg: view.values[0].agg } : null), labels);
|
|
481
|
+
const op = ruleOp(f);
|
|
482
|
+
if (op === "between" || op === "notBetween") {
|
|
483
|
+
const [from, to] = typeof f.value2 === "number" && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
|
|
484
|
+
return fill(labels.valueConditions[op], { value, from: number(from), to: number(to) });
|
|
485
|
+
}
|
|
486
|
+
return withNot(f, fill(labels.valueConditions.compare, { value, op: Object.hasOwn(OP_SIGNS, op) ? OP_SIGNS[op] : op, number: number(f.value) }), labels);
|
|
487
|
+
}
|
|
488
|
+
var dayText = (iso, locale) => (/* @__PURE__ */ new Date(`${iso}T00:00Z`)).toLocaleDateString(locale, { dateStyle: "medium", timeZone: "UTC" });
|
|
489
|
+
var isoDay = (ms) => new Date(ms).toISOString().slice(0, 10);
|
|
490
|
+
var dayAfter = (iso, n = 1) => isoDay(Date.parse(`${iso}T00:00Z`) + n * 864e5);
|
|
491
|
+
function relativeDays(f, timeZone, now, latest, more = {}) {
|
|
492
|
+
const range = datesOf(f, timeZone, now, latest, more);
|
|
493
|
+
return range && range.from !== null ? { from: range.from, to: range.to } : null;
|
|
494
|
+
}
|
|
495
|
+
var datesOf = (f, timeZone, now, latest, more = {}) => relativeDateRange(f.unit, f.count ?? 1, { timeZone, now, anchor: f.anchor, latest: latest ?? void 0, first: more.first ?? void 0, direction: f.direction, calendar: f.calendar, includeCurrent: f.includeCurrent, weekStart: more.weekStart });
|
|
496
|
+
var plainRange = (f) => ["last", "this"].includes(f.direction ?? "last") && f.calendar !== false && (f.anchor === void 0 || f.anchor === "today" || f.anchor === "latest") && ["year", "quarter", "month", "week", "day"].includes(f.unit);
|
|
497
|
+
function periodText(range, unit, locale) {
|
|
498
|
+
const month = (iso) => (/* @__PURE__ */ new Date(`${iso.slice(0, 10)}T00:00Z`)).toLocaleDateString(locale, { month: "short", year: "numeric", timeZone: "UTC" });
|
|
499
|
+
const quarter = (iso) => `Q${Math.floor((Number(iso.slice(5, 7)) - 1) / 3) + 1} ${iso.slice(0, 4)}`;
|
|
500
|
+
const text = unit === "year" ? (iso) => iso.slice(0, 4) : unit === "quarter" ? quarter : unit === "month" ? month : (iso) => dayText(iso.slice(0, 10), locale);
|
|
501
|
+
const [from, to] = [text(range.from), text(range.to)];
|
|
502
|
+
return from === to ? from : `${from}\u2013${to}`;
|
|
503
|
+
}
|
|
504
|
+
function rangeShare(range, unit, span, locale) {
|
|
505
|
+
const grain = unit === "quarter" ? "month" : unit === "week" ? "day" : unit;
|
|
506
|
+
range = { from: range.from.slice(0, 10), to: range.to.slice(0, 10) };
|
|
507
|
+
const [first, last] = [periodStart(isoDay(span.min), grain), periodEnd(isoDay(span.max), grain)];
|
|
508
|
+
if (first <= range.from && last >= range.to) {
|
|
509
|
+
return null;
|
|
510
|
+
}
|
|
511
|
+
const from = range.from > first ? range.from : first;
|
|
512
|
+
const to = range.to < last ? range.to : last;
|
|
513
|
+
if (from > to) {
|
|
514
|
+
return { none: true };
|
|
515
|
+
}
|
|
516
|
+
const missing = [];
|
|
517
|
+
let count = 0;
|
|
518
|
+
const part = (a, b, dataYear) => {
|
|
519
|
+
const years = [];
|
|
520
|
+
const [ya, yb] = [Number(a.slice(0, 4)), Number(b.slice(0, 4))];
|
|
521
|
+
for (let y = ya; y <= yb; y++) {
|
|
522
|
+
if (y !== dataYear) {
|
|
523
|
+
years.push(y);
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
if (years.length) {
|
|
527
|
+
missing.push(years.length === 1 ? String(years[0]) : `${years[0]}\u2013${years[years.length - 1]}`);
|
|
528
|
+
count += years.length;
|
|
529
|
+
}
|
|
530
|
+
if (ya <= dataYear && dataYear <= yb) {
|
|
531
|
+
const yearFrom = `${String(dataYear).padStart(4, "0")}-01-01`;
|
|
532
|
+
const yearTo = `${String(dataYear).padStart(4, "0")}-12-31`;
|
|
533
|
+
const rest = { from: a > yearFrom ? a : yearFrom, to: b < yearTo ? b : yearTo };
|
|
534
|
+
missing.push(periodText(rest, unit, locale));
|
|
535
|
+
count += periodText({ from: rest.from, to: rest.from }, unit, locale) === periodText({ from: rest.to, to: rest.to }, unit, locale) ? 1 : 2;
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
if (range.from < first) {
|
|
539
|
+
part(range.from, dayAfter(first, -1), Number(first.slice(0, 4)));
|
|
540
|
+
}
|
|
541
|
+
if (range.to > last) {
|
|
542
|
+
part(dayAfter(last), range.to, Number(last.slice(0, 4)));
|
|
543
|
+
}
|
|
544
|
+
return { none: false, data: periodText({ from, to }, unit, locale), missing, count };
|
|
545
|
+
}
|
|
546
|
+
var periodStart = (iso, unit) => unit === "year" ? `${iso.slice(0, 4)}-01-01` : unit === "month" ? `${iso.slice(0, 7)}-01` : iso;
|
|
547
|
+
function periodEnd(iso, unit) {
|
|
548
|
+
if (unit === "day") {
|
|
549
|
+
return iso;
|
|
550
|
+
}
|
|
551
|
+
const [y, m] = [Number(iso.slice(0, 4)), Number(iso.slice(5, 7))];
|
|
552
|
+
return isoDay(unit === "year" ? Date.UTC(y, 11, 31) : Date.UTC(y, m, 0));
|
|
553
|
+
}
|
|
554
|
+
function relativeText(f, labels, locale, timeZone, now, span, weekStart) {
|
|
555
|
+
if (!plainRange(f)) {
|
|
556
|
+
return otherRangeText(f, labels, locale, timeZone, now, span, weekStart);
|
|
557
|
+
}
|
|
558
|
+
const more = labels.relativeMore;
|
|
559
|
+
const count = f.count ?? 1;
|
|
560
|
+
const key = count === 1 ? f.unit : `${f.unit}s`;
|
|
561
|
+
let text = f.direction === "this" ? more.this[f.unit] ?? f.unit : Object.hasOwn(labels.relative, key) ? fill(labels.relative[key], { count: count.toLocaleString(locale) }) : fill(plural(more.last[f.unit] ?? { other: f.unit }, count, { lang: labels.lang, locale }), { count: count.toLocaleString(locale) });
|
|
562
|
+
const range = relativeDays(f, timeZone, now, span?.max, { weekStart });
|
|
563
|
+
const latest = f.anchor === "latest";
|
|
564
|
+
if (f.includeCurrent === false && f.direction !== "this" && !latest) {
|
|
565
|
+
text = fill(more.withoutCurrent, { text });
|
|
566
|
+
}
|
|
567
|
+
if (!range) {
|
|
568
|
+
return text;
|
|
569
|
+
}
|
|
570
|
+
if (latest) {
|
|
571
|
+
text = fill(labels.relativeTo, { text, end: periodText({ from: range.to, to: range.to }, f.unit, locale) });
|
|
572
|
+
}
|
|
573
|
+
const share = span ? rangeShare(range, f.unit, span, locale) : null;
|
|
574
|
+
if (!share) {
|
|
575
|
+
return latest ? text : fill(labels.withRange, { text, range: periodText(range, f.unit, locale) });
|
|
576
|
+
}
|
|
577
|
+
const lang = { lang: labels.lang, locale };
|
|
578
|
+
if (share.none) {
|
|
579
|
+
return fill(labels.withRange, { text, range: fill(plural(labels.noData, 1, lang), { range: periodText(range, f.unit, locale) }) });
|
|
580
|
+
}
|
|
581
|
+
return fill(labels.withShare, { text, range: share.data, missing: fill(plural(labels.noData, share.count, lang), { range: share.missing.join(", ") }) });
|
|
582
|
+
}
|
|
583
|
+
function otherRangeText(f, labels, locale, timeZone, now, span, weekStart) {
|
|
584
|
+
const more = labels.relativeMore;
|
|
585
|
+
const lang = { lang: labels.lang, locale };
|
|
586
|
+
const direction = f.direction ?? "last";
|
|
587
|
+
let text = direction === "this" ? more.this[f.unit] ?? f.unit : plural(more[direction]?.[f.unit] ?? { other: f.unit }, f.count ?? 1, lang);
|
|
588
|
+
if (f.calendar === false && direction !== "this") {
|
|
589
|
+
text = fill(more.rolling, { text });
|
|
590
|
+
} else if (f.includeCurrent === false && direction !== "this") {
|
|
591
|
+
text = fill(more.withoutCurrent, { text });
|
|
592
|
+
}
|
|
593
|
+
if (f.anchor === "latest") {
|
|
594
|
+
text = fill(more.fromLatest, { text });
|
|
595
|
+
} else if (f.anchor === "first") {
|
|
596
|
+
text = fill(more.fromFirst, { text });
|
|
597
|
+
} else if (f.anchor && f.anchor !== "today") {
|
|
598
|
+
text = fill(more.fromDate, { text, date: pointText(f.anchor, locale) });
|
|
599
|
+
}
|
|
600
|
+
const range = datesOf(f, timeZone, now, span?.max, { first: span?.min, weekStart });
|
|
601
|
+
if (!range) {
|
|
602
|
+
return text;
|
|
603
|
+
}
|
|
604
|
+
const days = (range.from === null || range.from.endsWith("T00:00")) && range.to.endsWith("T00:00");
|
|
605
|
+
const point = (iso) => pointText(days ? iso.slice(0, 10) : iso, locale);
|
|
606
|
+
const to = point(range.to);
|
|
607
|
+
return fill(labels.withRange, { text, range: range.from === null ? fill(more.until, { to }) : range.from === range.to ? to : `${point(range.from)} \u2013 ${to}` });
|
|
608
|
+
}
|
|
609
|
+
function precisionText(iso, precision, locale) {
|
|
610
|
+
if (precision === "year" || precision === "quarter" || precision === "month") {
|
|
611
|
+
const at = /* @__PURE__ */ new Date(`${iso.slice(0, 10)}T00:00Z`);
|
|
612
|
+
if (precision === "month") {
|
|
613
|
+
return at.toLocaleDateString(locale, { month: "short", year: "numeric", timeZone: "UTC" });
|
|
614
|
+
}
|
|
615
|
+
return precision === "year" ? iso.slice(0, iso.length - 6) : `Q${Math.floor(at.getUTCMonth() / 3) + 1} ${iso.slice(0, iso.length - 6)}`;
|
|
616
|
+
}
|
|
617
|
+
return pointText(iso, locale);
|
|
618
|
+
}
|
|
619
|
+
var pointText = (iso, locale) => iso.length > 10 ? (/* @__PURE__ */ new Date(`${iso.slice(0, 16)}Z`)).toLocaleString(locale, { dateStyle: "medium", timeStyle: "short", timeZone: "UTC" }) : dayText(iso, locale);
|
|
620
|
+
function wholeYears(from, to) {
|
|
621
|
+
const whole = typeof from === "string" && typeof to === "string" && /^\d{4}-01-01$/.test(from) && /^\d{4}-12-31$/.test(to);
|
|
622
|
+
return whole ? [from.slice(0, 4), to.slice(0, 4)] : null;
|
|
623
|
+
}
|
|
624
|
+
function compareText(f, labels, locale, { date, labelOf }) {
|
|
625
|
+
const shown = (v) => typeof v === "string" ? precisionText(v, f.precision, locale) : labelOf?.(v) ?? (date ? String(v) : v.toLocaleString(locale, { maximumFractionDigits: 6 }));
|
|
626
|
+
const forms = labels.compareShort;
|
|
627
|
+
const op = ruleOp(f);
|
|
628
|
+
if (op === "between" || op === "notBetween") {
|
|
629
|
+
const [from, to] = f.value2 !== void 0 && f.value2 < f.value ? [f.value2, f.value] : [f.value, f.value2];
|
|
630
|
+
const years = wholeYears(from, to);
|
|
631
|
+
if (years) {
|
|
632
|
+
return years[0] === years[1] ? fill(forms[op === "between" ? "=" : "!="], { value: years[0] }) : fill(forms[op], { from: years[0], to: years[1] });
|
|
633
|
+
}
|
|
634
|
+
return fill(forms[op], { from: shown(from), to: shown(to) });
|
|
635
|
+
}
|
|
636
|
+
return withNot(f, date && Object.hasOwn(forms, op) ? fill(forms[op], { value: shown(f.value) }) : `${Object.hasOwn(OP_SIGNS, op) ? OP_SIGNS[op] : op} ${shown(f.value)}`, labels);
|
|
637
|
+
}
|
|
638
|
+
function itemRuleText(f, labels, locale, { timeZone, date, labelOf, span, weekStart }) {
|
|
639
|
+
if (f.type === "relative") {
|
|
640
|
+
return withNot(f, relativeText(
|
|
641
|
+
/** @type {any} */
|
|
642
|
+
f,
|
|
643
|
+
labels,
|
|
644
|
+
locale,
|
|
645
|
+
timeZone,
|
|
646
|
+
void 0,
|
|
647
|
+
span,
|
|
648
|
+
weekStart
|
|
649
|
+
), labels);
|
|
650
|
+
}
|
|
651
|
+
if (f.type === "compare") {
|
|
652
|
+
return compareText(
|
|
653
|
+
/** @type {any} */
|
|
654
|
+
f,
|
|
655
|
+
labels,
|
|
656
|
+
locale,
|
|
657
|
+
{ date, labelOf }
|
|
658
|
+
);
|
|
659
|
+
}
|
|
660
|
+
const op = ruleOp(f);
|
|
661
|
+
return withNot(f, `${Object.hasOwn(labels.labelOps, op) ? labels.labelOps[op] : op} ${fill(labels.quote, { text: f.value })}`, labels);
|
|
662
|
+
}
|
|
663
|
+
function groupingName(source, unit, labels, size) {
|
|
664
|
+
const inName = labels.unitInName && Object.hasOwn(labels.unitInName, unit) ? labels.unitInName[unit] : labels.units[unit];
|
|
665
|
+
return unit === "bin" ? fill(labels.binsName, { field: source, size }) : fill(labels.derivedName, { field: source, unit: inName ?? unit });
|
|
666
|
+
}
|
|
667
|
+
var quickZone = (type) => type === "number" ? "values" : "rows";
|
|
668
|
+
function fieldAction(field, type, zones, labels) {
|
|
669
|
+
const zone = quickZone(type);
|
|
670
|
+
const kind = zones.includes(zone) ? null : zone !== "values" && zones.some((z) => z === "cols" || z === "filters") ? "move" : "add";
|
|
671
|
+
const name2 = zones.length ? `${field}, ${fill(labels.inZone, { zone: zones.map((z) => labels.zones[z] ?? z).join(", ") })}` : field;
|
|
672
|
+
const description = kind === null ? "" : fill(kind === "move" ? labels.moveTo : labels.addTo, { zone: labels.zones[zone] });
|
|
673
|
+
return { zone, kind, name: name2, description };
|
|
674
|
+
}
|
|
675
|
+
var SUMMARY_ORDER = Object.freeze(["rows", "cols", "values", "filters"]);
|
|
676
|
+
function layoutSummary(entries, labels) {
|
|
677
|
+
return SUMMARY_ORDER.filter((zone) => entries[zone] && entries[zone].length).map((zone) => ({ zone, title: labels.zones[zone], fields: entries[zone].map((e) => e.text).join(", ") }));
|
|
678
|
+
}
|
|
679
|
+
|
|
680
|
+
// src/drill.js
|
|
681
|
+
import { cellRows } from "pivotkit-core";
|
|
682
|
+
var DRILL_LIMIT = 1e3;
|
|
683
|
+
function decodeRow(encoded, i) {
|
|
684
|
+
const row = {};
|
|
685
|
+
for (const column of encoded.columns) {
|
|
686
|
+
const code = column.codes[i];
|
|
687
|
+
const v = code < 0 ? null : column.dict[code];
|
|
688
|
+
const value = column.type === "date" && typeof v === "number" ? new Date(v).toISOString().replace(/(T00:00:00)?\.000Z$/, "").replace(/:00$/, "") : v;
|
|
689
|
+
Object.defineProperty(row, column.name, { value, enumerable: true, writable: true, configurable: true });
|
|
690
|
+
}
|
|
691
|
+
return row;
|
|
692
|
+
}
|
|
693
|
+
function drillRows(result, { rowPath = [], colPath = [], data = null, limit = DRILL_LIMIT }) {
|
|
694
|
+
const all = cellRows(result, { row: rowPath, col: colPath });
|
|
695
|
+
const indices = all.slice(0, Math.max(0, limit));
|
|
696
|
+
const rows = new Array(indices.length);
|
|
697
|
+
for (let k = 0; k < indices.length; k++) {
|
|
698
|
+
rows[k] = data ? data[indices[k]] : decodeRow(result.encoded, indices[k]);
|
|
699
|
+
}
|
|
700
|
+
return { count: all.length, rows, indices };
|
|
701
|
+
}
|
|
702
|
+
|
|
703
|
+
// src/clear-input.jsx
|
|
704
|
+
import React, { useRef } from "react";
|
|
705
|
+
function emptyField(el) {
|
|
706
|
+
el.focus({ preventScroll: true });
|
|
707
|
+
let done;
|
|
708
|
+
try {
|
|
709
|
+
el.select();
|
|
710
|
+
const doc = (
|
|
711
|
+
/** @type {Document & { execCommand?: (cmd: string) => boolean }} */
|
|
712
|
+
el.ownerDocument
|
|
713
|
+
);
|
|
714
|
+
done = typeof doc.execCommand === "function" && doc.execCommand("delete") && el.value === "";
|
|
715
|
+
} catch {
|
|
716
|
+
done = false;
|
|
717
|
+
}
|
|
718
|
+
if (!done) {
|
|
719
|
+
const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
720
|
+
Object.getOwnPropertyDescriptor(proto, "value")?.set?.call(el, "");
|
|
721
|
+
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
722
|
+
}
|
|
1208
723
|
}
|
|
1209
|
-
function
|
|
1210
|
-
const
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
const
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1218
|
-
|
|
1219
|
-
open,
|
|
1220
|
-
// keys of the menus' texts (menu-labels.js): the Options menu shows them with its labels
|
|
1221
|
-
why: {
|
|
1222
|
-
expand: canExpand ? null : "expandNothing",
|
|
1223
|
-
collapse: canCollapse ? null : view.rows.length < 2 ? "collapseNeedsRows" : "collapseAllDone"
|
|
724
|
+
function ClearInput({ value, onChange, onClear, clearLabel, multiline = false, className, inputRef, ...rest }) {
|
|
725
|
+
const own = useRef(
|
|
726
|
+
/** @type {HTMLInputElement | HTMLTextAreaElement | null} */
|
|
727
|
+
null
|
|
728
|
+
);
|
|
729
|
+
const name2 = useFormName();
|
|
730
|
+
const ref = inputRef ?? own;
|
|
731
|
+
const clear = () => {
|
|
732
|
+
if (ref.current) {
|
|
733
|
+
emptyField(ref.current);
|
|
1224
734
|
}
|
|
735
|
+
onClear?.();
|
|
1225
736
|
};
|
|
737
|
+
const onKeyDown = (e) => {
|
|
738
|
+
rest.onKeyDown?.(e);
|
|
739
|
+
if (e.key === "Escape" && value !== "" && !e.defaultPrevented) {
|
|
740
|
+
e.preventDefault();
|
|
741
|
+
e.stopPropagation();
|
|
742
|
+
clear();
|
|
743
|
+
}
|
|
744
|
+
};
|
|
745
|
+
const Tag = multiline ? "textarea" : "input";
|
|
746
|
+
return /* @__PURE__ */ React.createElement("span", { className: `pk-clear-input${multiline ? " pk-clear-multi" : ""}${className ? ` ${className}` : ""}` }, /* @__PURE__ */ React.createElement(Tag, { name: name2, ...rest, ref, value, onChange: (e) => onChange(e.target.value), onKeyDown }), value !== "" ? /* @__PURE__ */ React.createElement(
|
|
747
|
+
"button",
|
|
748
|
+
{
|
|
749
|
+
type: "button",
|
|
750
|
+
className: "pk-clear-x",
|
|
751
|
+
"aria-label": clearLabel,
|
|
752
|
+
title: clearLabel,
|
|
753
|
+
onPointerDown: (e) => e.preventDefault(),
|
|
754
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
755
|
+
onClick: clear,
|
|
756
|
+
"data-testid": "clear-input"
|
|
757
|
+
},
|
|
758
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "x", size: 14 })
|
|
759
|
+
) : null);
|
|
1226
760
|
}
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
|
|
1232
|
-
function
|
|
1233
|
-
|
|
1234
|
-
next.totals[key] = Boolean(on);
|
|
1235
|
-
return next;
|
|
1236
|
-
}
|
|
1237
|
-
function setDisplay(view, display) {
|
|
1238
|
-
const next = clone(view);
|
|
1239
|
-
next.display = display;
|
|
1240
|
-
return next;
|
|
1241
|
-
}
|
|
1242
|
-
function setChart(view, name2) {
|
|
1243
|
-
const next = clone(view);
|
|
1244
|
-
next.chart = { ...next.chart, ...CHART_TYPES[name2].chart };
|
|
1245
|
-
next.display = "chart";
|
|
1246
|
-
return next;
|
|
1247
|
-
}
|
|
1248
|
-
function setChartDisplay(view, patch) {
|
|
1249
|
-
const next = clone(view);
|
|
1250
|
-
next.chart = { ...next.chart, ...patch };
|
|
1251
|
-
return next;
|
|
761
|
+
|
|
762
|
+
// src/info.jsx
|
|
763
|
+
import React2, { useCallback, useEffect, useId, useRef as useRef2, useState } from "react";
|
|
764
|
+
var LEAVE_DELAY = 250;
|
|
765
|
+
var WAY_TIME = 1500;
|
|
766
|
+
function FieldDescription({ info, labels, link = true, className = "pk-field-desc" }) {
|
|
767
|
+
return /* @__PURE__ */ React2.createElement("p", { className }, /* @__PURE__ */ React2.createElement("span", null, info.description), link && 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);
|
|
1252
768
|
}
|
|
1253
|
-
function
|
|
1254
|
-
const
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
769
|
+
function InfoButton({ info, name: name2, labels, className, testId = "field-info", label: named, tabIndex, slot }) {
|
|
770
|
+
const [mode, setMode] = useState(
|
|
771
|
+
/** @type {null | "peek" | "open"} */
|
|
772
|
+
null
|
|
773
|
+
);
|
|
774
|
+
const ref = useRef2(
|
|
775
|
+
/** @type {HTMLButtonElement | null} */
|
|
776
|
+
null
|
|
777
|
+
);
|
|
778
|
+
const quiet = useRef2(false);
|
|
779
|
+
const leaving = useRef2(
|
|
780
|
+
/** @type {ReturnType<typeof setTimeout> | null} */
|
|
781
|
+
null
|
|
782
|
+
);
|
|
783
|
+
const id = useId();
|
|
784
|
+
const textId = useId();
|
|
785
|
+
const pointer = useRef2(
|
|
786
|
+
/** @type {{ x: number, y: number } | null} */
|
|
787
|
+
null
|
|
788
|
+
);
|
|
789
|
+
const stay = () => {
|
|
790
|
+
if (leaving.current) {
|
|
791
|
+
clearTimeout(leaving.current);
|
|
792
|
+
leaving.current = null;
|
|
1260
793
|
}
|
|
1261
|
-
}
|
|
1262
|
-
const
|
|
1263
|
-
|
|
1264
|
-
|
|
1265
|
-
|
|
794
|
+
};
|
|
795
|
+
const hovered = (onItsWay) => {
|
|
796
|
+
const button = ref.current;
|
|
797
|
+
const root = (
|
|
798
|
+
/** @type {Document | ShadowRoot | null} */
|
|
799
|
+
button?.getRootNode() ?? null
|
|
800
|
+
);
|
|
801
|
+
const pop = root && "getElementById" in root ? root.getElementById(id) : null;
|
|
802
|
+
return Boolean(
|
|
803
|
+
button?.matches(":hover") || pop?.matches(":hover") || onItsWay && button && pop && onTheWay(button.getBoundingClientRect(), pop.getBoundingClientRect(), pointer.current)
|
|
804
|
+
);
|
|
805
|
+
};
|
|
806
|
+
const leaveSoon = () => {
|
|
807
|
+
stay();
|
|
808
|
+
const left = Date.now();
|
|
809
|
+
const check = () => {
|
|
810
|
+
if (hovered(Date.now() - left < WAY_TIME)) {
|
|
811
|
+
leaving.current = setTimeout(check, LEAVE_DELAY);
|
|
812
|
+
return;
|
|
813
|
+
}
|
|
814
|
+
leaving.current = null;
|
|
815
|
+
setMode((m) => m === "peek" ? null : m);
|
|
816
|
+
};
|
|
817
|
+
leaving.current = setTimeout(check, LEAVE_DELAY);
|
|
818
|
+
};
|
|
819
|
+
useEffect(() => stay, []);
|
|
820
|
+
useEffect(() => {
|
|
821
|
+
const doc = ref.current?.ownerDocument;
|
|
822
|
+
if (mode !== "peek" || !doc) {
|
|
823
|
+
return void 0;
|
|
1266
824
|
}
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
}
|
|
1270
|
-
|
|
1271
|
-
|
|
825
|
+
const follow = (e) => {
|
|
826
|
+
pointer.current = { x: e.clientX, y: e.clientY };
|
|
827
|
+
};
|
|
828
|
+
const gone = (e) => {
|
|
829
|
+
if (!e.relatedTarget) {
|
|
830
|
+
pointer.current = null;
|
|
831
|
+
}
|
|
832
|
+
};
|
|
833
|
+
doc.addEventListener("pointermove", follow, { capture: true, passive: true });
|
|
834
|
+
doc.addEventListener("pointerout", gone, { capture: true, passive: true });
|
|
835
|
+
return () => {
|
|
836
|
+
doc.removeEventListener("pointermove", follow, { capture: true });
|
|
837
|
+
doc.removeEventListener("pointerout", gone, { capture: true });
|
|
838
|
+
pointer.current = null;
|
|
839
|
+
};
|
|
840
|
+
}, [mode]);
|
|
841
|
+
const close = useCallback(() => {
|
|
842
|
+
quiet.current = true;
|
|
843
|
+
setMode(null);
|
|
844
|
+
requestAnimationFrame(() => {
|
|
845
|
+
quiet.current = false;
|
|
846
|
+
});
|
|
847
|
+
}, []);
|
|
848
|
+
const label = named ?? fill(labels.aboutField, { field: name2 });
|
|
849
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
850
|
+
"button",
|
|
851
|
+
{
|
|
852
|
+
ref,
|
|
853
|
+
type: "button",
|
|
854
|
+
className: `pk-info${className ? ` ${className}` : ""}`,
|
|
855
|
+
"aria-label": label,
|
|
856
|
+
"aria-describedby": textId,
|
|
857
|
+
"aria-expanded": mode === "open",
|
|
858
|
+
"aria-controls": mode ? id : void 0,
|
|
859
|
+
"aria-haspopup": "dialog",
|
|
860
|
+
tabIndex,
|
|
861
|
+
"data-pk-slot": slot,
|
|
862
|
+
"data-testid": testId,
|
|
863
|
+
onPointerEnter: (e) => {
|
|
864
|
+
if (e.pointerType === "mouse") {
|
|
865
|
+
stay();
|
|
866
|
+
setMode((m) => m ?? "peek");
|
|
867
|
+
}
|
|
868
|
+
},
|
|
869
|
+
onPointerLeave: (e) => {
|
|
870
|
+
if (e.pointerType === "mouse" && mode === "peek") {
|
|
871
|
+
leaveSoon();
|
|
872
|
+
}
|
|
873
|
+
},
|
|
874
|
+
onFocus: () => {
|
|
875
|
+
if (mode === null && !quiet.current) {
|
|
876
|
+
setMode("peek");
|
|
877
|
+
}
|
|
878
|
+
},
|
|
879
|
+
onBlur: (e) => {
|
|
880
|
+
const to = (
|
|
881
|
+
/** @type {Element | null} */
|
|
882
|
+
e.relatedTarget
|
|
883
|
+
);
|
|
884
|
+
if (mode === "peek" && !(to && to.closest?.(".pk-info-pop"))) {
|
|
885
|
+
setMode(null);
|
|
886
|
+
}
|
|
887
|
+
},
|
|
888
|
+
onClick: () => {
|
|
889
|
+
stay();
|
|
890
|
+
setMode(mode === "open" ? null : "open");
|
|
891
|
+
}
|
|
892
|
+
},
|
|
893
|
+
/* @__PURE__ */ React2.createElement(Icon, { name: "info", size: 14 })
|
|
894
|
+
), /* @__PURE__ */ React2.createElement("span", { id: textId, hidden: true }, info.description), /* @__PURE__ */ React2.createElement(
|
|
895
|
+
Popover,
|
|
896
|
+
{
|
|
897
|
+
key: mode ?? "closed",
|
|
898
|
+
open: mode !== null,
|
|
899
|
+
passive: mode === "peek",
|
|
900
|
+
anchor: ref,
|
|
901
|
+
onClose: close,
|
|
902
|
+
label,
|
|
903
|
+
role: mode === "peek" ? "tooltip" : "dialog",
|
|
904
|
+
className: "pk-info-pop",
|
|
905
|
+
id,
|
|
906
|
+
onPointerEnter: stay,
|
|
907
|
+
onPointerLeave: (e) => {
|
|
908
|
+
if (e.pointerType === "mouse" && mode === "peek") {
|
|
909
|
+
leaveSoon();
|
|
910
|
+
}
|
|
911
|
+
}
|
|
912
|
+
},
|
|
913
|
+
/* @__PURE__ */ React2.createElement(FieldDescription, { info, labels })
|
|
914
|
+
));
|
|
1272
915
|
}
|
|
1273
916
|
|
|
1274
917
|
// src/help.js
|
|
1275
|
-
import { createContext
|
|
1276
|
-
var HelpContext =
|
|
918
|
+
import { createContext } from "react";
|
|
919
|
+
var HelpContext = createContext(
|
|
1277
920
|
/** @type {Help} */
|
|
1278
921
|
{ explain: true, labels: null }
|
|
1279
922
|
);
|
|
1280
923
|
|
|
1281
924
|
// src/share.js
|
|
1282
|
-
import { VIEW_FILE_LIMITS, fromViewFile, normalize } from "pivotkit-core";
|
|
925
|
+
import { VIEW_FILE_LIMITS, fromViewFile, linkFragment, normalize, outsideLimits, withLinkFragment } from "pivotkit-core";
|
|
1283
926
|
var linkModule = null;
|
|
1284
927
|
var linkLoaded = null;
|
|
1285
928
|
function loadLink() {
|
|
@@ -1290,24 +933,8 @@ function loadLink() {
|
|
|
1290
933
|
return linkModule;
|
|
1291
934
|
}
|
|
1292
935
|
var linkNow = () => linkLoaded;
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
}
|
|
1296
|
-
var entries = (fragment) => fragment ? fragment.split("&") : [];
|
|
1297
|
-
var isEntry = (entry, param) => entry.startsWith(`${encodeURIComponent(param)}=`);
|
|
1298
|
-
function readLinkParam(hash, param) {
|
|
1299
|
-
const text = typeof hash === "string" ? hash.replace(/^#/, "") : "";
|
|
1300
|
-
const entry = entries(text).find((e) => isEntry(e, param));
|
|
1301
|
-
const value = entry ? entry.slice(encodeURIComponent(param).length + 1) : "";
|
|
1302
|
-
return value ? value : null;
|
|
1303
|
-
}
|
|
1304
|
-
function withLinkParam(url, param, encoded) {
|
|
1305
|
-
const at = url.indexOf("#");
|
|
1306
|
-
const base = at === -1 ? url : url.slice(0, at);
|
|
1307
|
-
const kept = entries(at === -1 ? "" : url.slice(at + 1)).filter((e) => !isEntry(e, param));
|
|
1308
|
-
const next = encoded ? [...kept, `${encodeURIComponent(param)}=${encoded}`] : kept;
|
|
1309
|
-
return next.length ? `${base}#${next.join("&")}` : base;
|
|
1310
|
-
}
|
|
936
|
+
var readLinkParam = (hash, key) => linkFragment(hash, key);
|
|
937
|
+
var withLinkParam = (url, key, encoded) => withLinkFragment(url, key, encoded);
|
|
1311
938
|
function shareBase(shareLink, here) {
|
|
1312
939
|
if (shareLink === true) {
|
|
1313
940
|
if (!here) {
|
|
@@ -1357,19 +984,19 @@ function viewFromObject(input, encoded, options = {}) {
|
|
|
1357
984
|
const failed = file.failed ?? "notView";
|
|
1358
985
|
return { view: null, issues: file.issues, failed: Object.hasOwn(FAILED, failed) ? FAILED[failed] : failed, file };
|
|
1359
986
|
}
|
|
1360
|
-
const { view, issues } = normalize(file.view, encoded,
|
|
987
|
+
const { view, issues } = normalize(file.view, encoded, { limits: outsideLimits(options.limits) });
|
|
1361
988
|
if (issues.some((i) => i.path === "version")) {
|
|
1362
989
|
return { view: null, issues, failed: "newer", file };
|
|
1363
990
|
}
|
|
1364
991
|
return { view, issues, failed: null, file };
|
|
1365
992
|
}
|
|
1366
|
-
function loadCheck(
|
|
1367
|
-
const fit =
|
|
1368
|
-
if (!
|
|
993
|
+
function loadCheck(loaded2, labels, sources = []) {
|
|
994
|
+
const fit = loaded2.file?.compatible;
|
|
995
|
+
if (!loaded2.view || !fit || fit.ok) {
|
|
1369
996
|
return null;
|
|
1370
997
|
}
|
|
1371
998
|
const lines2 = [];
|
|
1372
|
-
const fileSource =
|
|
999
|
+
const fileSource = loaded2.file?.source;
|
|
1373
1000
|
const target = fit.source === "other" && fileSource?.id ? sources.find((s) => s && s.id === fileSource.id) : void 0;
|
|
1374
1001
|
if (fit.source === "other") {
|
|
1375
1002
|
const name2 = target?.name || fileSource?.name || fileSource?.id;
|
|
@@ -1514,6 +1141,14 @@ var TIPS = Object.freeze([
|
|
|
1514
1141
|
return spec ? { type: spec.showAs.type } : null;
|
|
1515
1142
|
}
|
|
1516
1143
|
},
|
|
1144
|
+
{
|
|
1145
|
+
// column subtotals with two or more fields in Columns: what a Total column next to the
|
|
1146
|
+
// others adds up (people read "1 Critical Total" as one more status)
|
|
1147
|
+
id: "colSubtotals",
|
|
1148
|
+
icon: "sigma",
|
|
1149
|
+
action: "colSubtotalsOff",
|
|
1150
|
+
when: (ctx) => table(ctx) && ctx.view.values.length > 0 && ctx.view.totals.colSubtotals && ctx.view.cols.length >= 2 && ctx.colSubtotalShown ? {} : null
|
|
1151
|
+
},
|
|
1517
1152
|
{
|
|
1518
1153
|
// a type the user chose for data over time: lines show it (automatic draws them)
|
|
1519
1154
|
id: "chartOverTime",
|
|
@@ -1667,6 +1302,11 @@ var SHORTCUTS = Object.freeze([
|
|
|
1667
1302
|
{ keys: ["Arrow keys"], text: "fields" },
|
|
1668
1303
|
{ keys: ["Shift", "F10"], text: "fieldMenu" }
|
|
1669
1304
|
]);
|
|
1305
|
+
function expandedGroup(nodes, depth, collapsed) {
|
|
1306
|
+
const shut = new Set(collapsed.map((path) => JSON.stringify(path)));
|
|
1307
|
+
const open = (path) => path.every((_, i) => !shut.has(JSON.stringify(path.slice(0, i + 1))));
|
|
1308
|
+
return nodes.some((node) => node.depth > 0 && node.depth < depth && node.children.length > 1 && open(node.path));
|
|
1309
|
+
}
|
|
1670
1310
|
function tipContext({ view, result, encoded, failed, empty, typeOf, fields, series = null, tableShown = false, drilled = false, changes = 0, dragAt = null, canSave = false, savedAt = 0, chartPlan: chartPlan2 = { name: "bar", auto: true, swap: false } }) {
|
|
1671
1311
|
const leaves = (nodes, depth) => result && depth > 0 ? nodes.reduce((n, node) => n + (node.depth === depth ? 1 : 0), 0) : 1;
|
|
1672
1312
|
return {
|
|
@@ -1678,6 +1318,7 @@ function tipContext({ view, result, encoded, failed, empty, typeOf, fields, seri
|
|
|
1678
1318
|
fields,
|
|
1679
1319
|
rowLeaves: result ? leaves(result.rowNodes, result.rowFields.length) : 0,
|
|
1680
1320
|
colLeaves: result ? leaves(result.colNodes, result.colFields.length) : 0,
|
|
1321
|
+
colSubtotalShown: result ? expandedGroup(result.colNodes, result.colFields.length, view.collapsed?.cols ?? []) : false,
|
|
1681
1322
|
matched: result ? result.rows.length : 0,
|
|
1682
1323
|
dataRows: encoded.length,
|
|
1683
1324
|
series,
|
|
@@ -1767,9 +1408,24 @@ function writeDismissed(key, storage, dismissed) {
|
|
|
1767
1408
|
}
|
|
1768
1409
|
}
|
|
1769
1410
|
function withoutFilters(view) {
|
|
1770
|
-
return { ...view, filters: filterZoneFields(view).map(
|
|
1411
|
+
return { ...view, filters: filterZoneFields(view).map(emptyPick) };
|
|
1771
1412
|
}
|
|
1772
1413
|
|
|
1414
|
+
// src/lazy-import.js
|
|
1415
|
+
var pending = null;
|
|
1416
|
+
var loaded = null;
|
|
1417
|
+
function loadImport() {
|
|
1418
|
+
pending ??= import("../import-ui.js").then(
|
|
1419
|
+
(m) => loaded = m,
|
|
1420
|
+
(error) => {
|
|
1421
|
+
pending = null;
|
|
1422
|
+
throw error;
|
|
1423
|
+
}
|
|
1424
|
+
);
|
|
1425
|
+
return pending;
|
|
1426
|
+
}
|
|
1427
|
+
var importNow = () => loaded;
|
|
1428
|
+
|
|
1773
1429
|
export {
|
|
1774
1430
|
CHART_TYPES,
|
|
1775
1431
|
SLICE_TYPES,
|
|
@@ -1777,40 +1433,18 @@ export {
|
|
|
1777
1433
|
chartTypeOf,
|
|
1778
1434
|
chartPlan,
|
|
1779
1435
|
MAX_CATEGORIES,
|
|
1780
|
-
|
|
1781
|
-
refLabel,
|
|
1782
|
-
sortText,
|
|
1783
|
-
valueConditionText,
|
|
1784
|
-
dayText,
|
|
1785
|
-
isoDay,
|
|
1786
|
-
relativeDays,
|
|
1787
|
-
periodText,
|
|
1788
|
-
rangeShare,
|
|
1789
|
-
relativeText,
|
|
1790
|
-
wholeYears,
|
|
1791
|
-
itemRuleText,
|
|
1792
|
-
groupingName,
|
|
1793
|
-
fieldAction,
|
|
1794
|
-
layoutSummary,
|
|
1795
|
-
DRILL_LIMIT,
|
|
1796
|
-
decodeRow,
|
|
1797
|
-
drillRows,
|
|
1798
|
-
Icon,
|
|
1799
|
-
TYPE_ICON,
|
|
1800
|
-
ZONE_ICON,
|
|
1801
|
-
ClearInput,
|
|
1802
|
-
rootOf,
|
|
1803
|
-
activeIn,
|
|
1804
|
-
useModal,
|
|
1805
|
-
useIsoLayoutEffect,
|
|
1806
|
-
LayerContext,
|
|
1807
|
-
Popover,
|
|
1808
|
-
MenuButton,
|
|
1809
|
-
Option,
|
|
1810
|
-
InfoButton,
|
|
1436
|
+
swapAxes,
|
|
1811
1437
|
ZONES,
|
|
1812
1438
|
clone,
|
|
1439
|
+
RULE_OPS,
|
|
1440
|
+
ruleOp,
|
|
1441
|
+
hiddenNot,
|
|
1442
|
+
opOf,
|
|
1443
|
+
pickFilter,
|
|
1444
|
+
emptyPick,
|
|
1445
|
+
isEmptyPick,
|
|
1813
1446
|
same,
|
|
1447
|
+
searchItems,
|
|
1814
1448
|
filterZoneFields,
|
|
1815
1449
|
axisOf,
|
|
1816
1450
|
zoneOverLimit,
|
|
@@ -1841,12 +1475,31 @@ export {
|
|
|
1841
1475
|
setDisplay,
|
|
1842
1476
|
setChart,
|
|
1843
1477
|
setChartDisplay,
|
|
1844
|
-
swapAxes,
|
|
1845
1478
|
isEmptyView,
|
|
1479
|
+
valueLabel,
|
|
1480
|
+
refLabel,
|
|
1481
|
+
sortText,
|
|
1482
|
+
valueConditionText,
|
|
1483
|
+
dayText,
|
|
1484
|
+
isoDay,
|
|
1485
|
+
relativeDays,
|
|
1486
|
+
plainRange,
|
|
1487
|
+
periodText,
|
|
1488
|
+
rangeShare,
|
|
1489
|
+
relativeText,
|
|
1490
|
+
wholeYears,
|
|
1491
|
+
itemRuleText,
|
|
1492
|
+
groupingName,
|
|
1493
|
+
fieldAction,
|
|
1494
|
+
layoutSummary,
|
|
1495
|
+
DRILL_LIMIT,
|
|
1496
|
+
decodeRow,
|
|
1497
|
+
drillRows,
|
|
1498
|
+
ClearInput,
|
|
1499
|
+
InfoButton,
|
|
1846
1500
|
HelpContext,
|
|
1847
1501
|
loadLink,
|
|
1848
1502
|
linkNow,
|
|
1849
|
-
linkParam,
|
|
1850
1503
|
readLinkParam,
|
|
1851
1504
|
withLinkParam,
|
|
1852
1505
|
shareBase,
|
|
@@ -1876,5 +1529,7 @@ export {
|
|
|
1876
1529
|
parseStored,
|
|
1877
1530
|
subscribeStored,
|
|
1878
1531
|
writeDismissed,
|
|
1879
|
-
withoutFilters
|
|
1532
|
+
withoutFilters,
|
|
1533
|
+
loadImport,
|
|
1534
|
+
importNow
|
|
1880
1535
|
};
|