pivotkit-react 0.8.2 → 0.9.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 +93 -1
- package/dist/chunks/chunk-24T2VRMU.js +1010 -0
- package/dist/chunks/chunk-6R7TJHS3.js +212 -0
- package/dist/chunks/{chunk-GUSQWPTH.js → chunk-EPGRJSPP.js} +20 -5
- package/dist/chunks/{chunk-JAOOFDNR.js → chunk-FAAQZSR4.js} +4 -1
- package/dist/chunks/{chunk-2N2UGSIG.js → chunk-FI22Z6CC.js} +5 -2
- package/dist/chunks/{chunk-ZM45YU3W.js → chunk-G3R5C3J7.js} +28 -6
- package/dist/chunks/{chunk-MU5BTKSY.js → chunk-QCBVEI23.js} +6 -2
- package/dist/chunks/{chunk-6OWC6X5W.js → chunk-QVE7JM4G.js} +1 -1
- package/dist/chunks/{chunk-3WWWKPB4.js → chunk-V233JHVY.js} +75 -336
- package/dist/chunks/chunk-W6BG3GGS.js +679 -0
- package/dist/chunks/chunk-YAT2TFMK.js +138 -0
- package/dist/chunks/chunk-ZQ2M3U74.js +341 -0
- package/dist/chunks/{unused-texts-de-GB3IWWEM.js → labels-de-ZC3CSQZR.js} +1 -1
- package/dist/chunks/tips-SYGQPI3Q.js +22 -0
- package/dist/chunks/{unused-texts-LRYVWFFN.js → unused-texts-ERQ6ACNX.js} +1 -1
- package/dist/chunks/unused-texts-de-AC5GS3FS.js +6 -0
- package/dist/deferred-late.js +13 -0
- package/dist/deferred.js +18 -0
- package/dist/echarts.js +30 -6
- package/dist/import-ui.js +3 -3
- package/dist/index.js +427 -202
- package/dist/labels.js +15 -12
- package/dist/menu-texts-de.js +1 -1
- package/dist/menus.js +518 -381
- package/dist/styles.css +128 -9
- package/package.json +5 -4
- package/types/PivotReport.d.ts +3 -1
- package/types/chart-tooltip.d.ts +18 -1
- package/types/chart-types.d.ts +7 -2
- package/types/chart.d.ts +10 -2
- package/types/chip-menus.d.ts +1 -1
- package/types/deferred-late.d.ts +2 -0
- package/types/deferred.d.ts +28 -0
- package/types/field-info.d.ts +6 -3
- package/types/fields.d.ts +3 -2
- package/types/icons.d.ts +2 -0
- package/types/index.d.ts +20 -10
- package/types/labels-de.d.ts +2 -0
- package/types/labels.d.ts +55 -459
- package/types/lazy-menus.d.ts +2 -2
- package/types/menu-labels.d.ts +20 -0
- package/types/menu-ops.d.ts +33 -0
- package/types/menu-topics.d.ts +6 -3
- package/types/menus.d.ts +1 -0
- package/types/names.d.ts +20 -2
- package/types/notices.d.ts +212 -0
- package/types/point-menu.d.ts +21 -0
- package/types/quick-choices.d.ts +28 -0
- package/types/side-by-side.d.ts +19 -0
- package/types/tip-state.d.ts +97 -0
- package/types/tips.d.ts +13 -250
- package/types/unused-texts.d.ts +3 -0
- package/types/view-ops.d.ts +27 -14
- package/types/view-tabs.d.ts +4 -3
- package/dist/chunks/chunk-W2SVDHGN.js +0 -1898
|
@@ -0,0 +1,679 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Icon,
|
|
3
|
+
Popover,
|
|
4
|
+
onTheWay,
|
|
5
|
+
useFormName
|
|
6
|
+
} from "./chunk-FAAQZSR4.js";
|
|
7
|
+
import {
|
|
8
|
+
dateSpan,
|
|
9
|
+
filterZoneFields,
|
|
10
|
+
sourceOf,
|
|
11
|
+
yearText
|
|
12
|
+
} from "./chunk-24T2VRMU.js";
|
|
13
|
+
import {
|
|
14
|
+
fill
|
|
15
|
+
} from "./chunk-V233JHVY.js";
|
|
16
|
+
|
|
17
|
+
// src/drill.js
|
|
18
|
+
import { cellRows } from "pivotkit-core";
|
|
19
|
+
var DRILL_LIMIT = 1e3;
|
|
20
|
+
function decodeRow(encoded, i) {
|
|
21
|
+
const row = {};
|
|
22
|
+
for (const column of encoded.columns) {
|
|
23
|
+
const code = column.codes[i];
|
|
24
|
+
const v = code < 0 ? null : column.dict[code];
|
|
25
|
+
const value = column.type === "date" && typeof v === "number" ? new Date(v).toISOString().replace(/(T00:00:00)?\.000Z$/, "").replace(/:00$/, "") : v;
|
|
26
|
+
Object.defineProperty(row, column.name, { value, enumerable: true, writable: true, configurable: true });
|
|
27
|
+
}
|
|
28
|
+
return row;
|
|
29
|
+
}
|
|
30
|
+
function drillRows(result, { rowPath = [], colPath = [], data = null, limit = DRILL_LIMIT }) {
|
|
31
|
+
const all = cellRows(result, { row: rowPath, col: colPath });
|
|
32
|
+
const indices = all.slice(0, Math.max(0, limit));
|
|
33
|
+
const rows = new Array(indices.length);
|
|
34
|
+
for (let k = 0; k < indices.length; k++) {
|
|
35
|
+
rows[k] = data ? data[indices[k]] : decodeRow(result.encoded, indices[k]);
|
|
36
|
+
}
|
|
37
|
+
return { count: all.length, rows, indices };
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/date-context.js
|
|
41
|
+
import { isDateMs } from "pivotkit-core";
|
|
42
|
+
import { CATALOG, fieldLabel, monthName } from "pivotkit-core";
|
|
43
|
+
var formatters = /* @__PURE__ */ new Map();
|
|
44
|
+
function dateFormatter(locale, options) {
|
|
45
|
+
const key = JSON.stringify([locale, options]);
|
|
46
|
+
let fmt = formatters.get(key);
|
|
47
|
+
if (!fmt) {
|
|
48
|
+
fmt = new Intl.DateTimeFormat(locale, options);
|
|
49
|
+
if (formatters.size >= 32) {
|
|
50
|
+
const oldest = formatters.keys().next().value;
|
|
51
|
+
if (oldest !== void 0) formatters.delete(oldest);
|
|
52
|
+
}
|
|
53
|
+
formatters.set(key, fmt);
|
|
54
|
+
}
|
|
55
|
+
return fmt;
|
|
56
|
+
}
|
|
57
|
+
function dateDisplayLocale(locale) {
|
|
58
|
+
try {
|
|
59
|
+
dateFormatter(locale, { year: "numeric", timeZone: "UTC" });
|
|
60
|
+
return locale;
|
|
61
|
+
} catch {
|
|
62
|
+
return "en-US";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
function dateRangeText(span, locale) {
|
|
66
|
+
if (!span || !isDateMs(span.min) || !isDateMs(span.max)) return "";
|
|
67
|
+
const fmt = dateFormatter(locale, { year: "numeric", month: "short", day: "numeric", timeZone: "UTC", era: new Date(span.min).getUTCFullYear() <= 0 ? "short" : void 0 });
|
|
68
|
+
return `${fmt.format(span.min)} \u2013 ${fmt.format(span.max)}`;
|
|
69
|
+
}
|
|
70
|
+
var YEAR_CONTEXT_LIMIT = 32;
|
|
71
|
+
var YEAR_IN_ITEMS = ["month", "quarter"];
|
|
72
|
+
var yearCache = /* @__PURE__ */ new WeakMap();
|
|
73
|
+
function yearsOf(result, field) {
|
|
74
|
+
let cached = yearCache.get(result);
|
|
75
|
+
if (!cached) yearCache.set(result, cached = /* @__PURE__ */ new Map());
|
|
76
|
+
const previous = cached.get(field);
|
|
77
|
+
if (previous) return previous.years;
|
|
78
|
+
const column = result.encoded.column(field);
|
|
79
|
+
let truncated = false;
|
|
80
|
+
const spans = /* @__PURE__ */ new Map();
|
|
81
|
+
const months = /* @__PURE__ */ new Map();
|
|
82
|
+
if (column?.type === "date") {
|
|
83
|
+
const date = /* @__PURE__ */ new Date(0);
|
|
84
|
+
for (const row of result.rows) {
|
|
85
|
+
const code = column.codes[row];
|
|
86
|
+
const value = column.dict[code];
|
|
87
|
+
if (isDateMs(value)) {
|
|
88
|
+
date.setTime(value);
|
|
89
|
+
const year = date.getUTCFullYear();
|
|
90
|
+
const month = date.getUTCMonth() + 1;
|
|
91
|
+
const monthSpan = months.get(month);
|
|
92
|
+
if (monthSpan) {
|
|
93
|
+
monthSpan.min = Math.min(monthSpan.min, value);
|
|
94
|
+
monthSpan.max = Math.max(monthSpan.max, value);
|
|
95
|
+
} else months.set(month, { min: value, max: value });
|
|
96
|
+
const span = spans.get(year);
|
|
97
|
+
if (span) {
|
|
98
|
+
span.min = Math.min(span.min, value);
|
|
99
|
+
span.max = Math.max(span.max, value);
|
|
100
|
+
} else if (spans.size < YEAR_CONTEXT_LIMIT) spans.set(year, { min: value, max: value });
|
|
101
|
+
else truncated = true;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
const sorted = [...spans.keys()].sort((a, b) => a - b);
|
|
106
|
+
cached.set(field, { years: sorted, spans, months, truncated });
|
|
107
|
+
return sorted;
|
|
108
|
+
}
|
|
109
|
+
function yearSetText(years, locale = "en-US") {
|
|
110
|
+
const truncated = years.length > YEAR_CONTEXT_LIMIT;
|
|
111
|
+
years = years.slice(0, YEAR_CONTEXT_LIMIT);
|
|
112
|
+
const runs = [];
|
|
113
|
+
for (let i = 0; i < years.length; i++) {
|
|
114
|
+
const first = years[i];
|
|
115
|
+
while (i + 1 < years.length && years[i + 1] === years[i] + 1) i++;
|
|
116
|
+
runs.push(first === years[i] ? yearText(first, locale) : `${yearText(first, locale)}\u2013${yearText(years[i], locale)}`);
|
|
117
|
+
}
|
|
118
|
+
return runs.join(", ") + (truncated ? ", \u2026" : "");
|
|
119
|
+
}
|
|
120
|
+
function observedYears(result, field) {
|
|
121
|
+
const years = yearsOf(result, field);
|
|
122
|
+
const truncated = yearCache.get(result)?.get(field)?.truncated ?? false;
|
|
123
|
+
const suffix = truncated ? ", \u2026" : "";
|
|
124
|
+
const fmt = dateFormatter(result.locale, { year: "numeric", timeZone: "UTC", era: years[0] <= 0 ? "short" : void 0 });
|
|
125
|
+
if (["gregory", "iso8601"].includes(fmt.resolvedOptions().calendar)) return { text: yearSetText(years, result.locale) + suffix, combined: truncated || years.length > 1 };
|
|
126
|
+
const spans = yearCache.get(result)?.get(field)?.spans;
|
|
127
|
+
const parts = [];
|
|
128
|
+
let combined = truncated || years.length > 1;
|
|
129
|
+
for (const year of years) {
|
|
130
|
+
const span = spans?.get(year);
|
|
131
|
+
if (!span) continue;
|
|
132
|
+
const first = fmt.format(span.min), last = fmt.format(span.max);
|
|
133
|
+
combined ||= first !== last;
|
|
134
|
+
const previous = parts[parts.length - 1];
|
|
135
|
+
if (previous && previous.last === first) previous.last = last;
|
|
136
|
+
else parts.push({ first, last });
|
|
137
|
+
}
|
|
138
|
+
return { text: parts.map(({ first, last }) => first === last ? first : `${first}\u2013${last}`).join(", ") + suffix, combined };
|
|
139
|
+
}
|
|
140
|
+
function dateContext(result, labels) {
|
|
141
|
+
if (!result) return { result, labels, ranges: [], titles: /* @__PURE__ */ new Map() };
|
|
142
|
+
const { view, encoded, locale } = result;
|
|
143
|
+
const fields = { ...labels.core.fields };
|
|
144
|
+
const single = /* @__PURE__ */ new Map();
|
|
145
|
+
const titles = /* @__PURE__ */ new Map();
|
|
146
|
+
const observedMonths = /* @__PURE__ */ new Map();
|
|
147
|
+
const used = /* @__PURE__ */ new Set([...view.rows, ...view.cols, ...filterZoneFields(view)]);
|
|
148
|
+
const combinedMonths = /* @__PURE__ */ new Set();
|
|
149
|
+
for (const d of view.derived) {
|
|
150
|
+
if (!used.has(d.name) || !CATALOG.cyclicUnits.includes(d.by)) continue;
|
|
151
|
+
const years = yearsOf(result, d.field);
|
|
152
|
+
const observed = observedYears(result, d.field);
|
|
153
|
+
const titled = (words) => {
|
|
154
|
+
const title = `${fieldLabel(d.name, labels.core)} \xB7 ${fill(words, { years: observed.text })}`;
|
|
155
|
+
titles.set(d.name, title);
|
|
156
|
+
Object.defineProperty(fields, d.name, { value: title, enumerable: true, configurable: true, writable: true });
|
|
157
|
+
};
|
|
158
|
+
if (observed.combined) {
|
|
159
|
+
if (d.by === "month") combinedMonths.add(d.name);
|
|
160
|
+
titled(labels.dateYearsCombined);
|
|
161
|
+
} else if (years.length === 1 && YEAR_IN_ITEMS.includes(d.by)) {
|
|
162
|
+
single.set(d.name, observed.text);
|
|
163
|
+
if (d.by === "month") {
|
|
164
|
+
const months = yearCache.get(result)?.get(d.field)?.months;
|
|
165
|
+
if (months) observedMonths.set(d.name, months);
|
|
166
|
+
}
|
|
167
|
+
} else if (years.length === 1) {
|
|
168
|
+
titled(labels.dateYearOnly);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
const decorated = { ...result, label: (axis, node, core) => {
|
|
172
|
+
const text = result.label(axis, node, core);
|
|
173
|
+
const field = (axis === "rows" ? result.rowFields : result.colFields)[node.depth - 1];
|
|
174
|
+
if (node.parent && typeof node.key === "number" && combinedMonths.has(field)) {
|
|
175
|
+
return monthName(node.key, locale);
|
|
176
|
+
}
|
|
177
|
+
const span = typeof node.key === "number" ? observedMonths.get(field)?.get(node.key) : void 0;
|
|
178
|
+
if (node.parent && span) {
|
|
179
|
+
const fmt = dateFormatter(locale, { month: "short", year: "numeric", timeZone: "UTC", era: new Date(span.min).getUTCFullYear() <= 0 ? "short" : void 0 });
|
|
180
|
+
if (!["gregory", "iso8601"].includes(fmt.resolvedOptions().calendar)) {
|
|
181
|
+
const first = fmt.format(span.min), last = fmt.format(span.max);
|
|
182
|
+
return first === last ? first : `${first} \u2013 ${last}`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return node.parent && node.key !== null && single.has(field) ? `${text} ${single.get(field)}` : text;
|
|
186
|
+
} };
|
|
187
|
+
const active = [...new Set([...view.rows, ...view.cols, ...filterZoneFields(view)].map((f) => sourceOf(view, f)))];
|
|
188
|
+
const ranges = active.flatMap((field) => {
|
|
189
|
+
const text = dateRangeText(dateSpan(encoded, field), locale);
|
|
190
|
+
return text ? [{ field, text }] : [];
|
|
191
|
+
});
|
|
192
|
+
return { result: decorated, labels: { ...labels, core: { ...labels.core, fields } }, ranges, titles };
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/field-info.js
|
|
196
|
+
import { fieldDefaultsFromSchema, isIdentifierName } from "pivotkit-core";
|
|
197
|
+
var isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
|
|
198
|
+
var own = (o, k) => isObject(o) && Object.hasOwn(o, k) ? o[k] : void 0;
|
|
199
|
+
var TYPES = Object.freeze(["string", "number", "date", "boolean"]);
|
|
200
|
+
function fieldInfoOf(fieldDefaults) {
|
|
201
|
+
const map = /* @__PURE__ */ new Map();
|
|
202
|
+
if (!isObject(fieldDefaults)) {
|
|
203
|
+
return map;
|
|
204
|
+
}
|
|
205
|
+
const properties = {};
|
|
206
|
+
for (const name of Object.keys(
|
|
207
|
+
/** @type {object} */
|
|
208
|
+
fieldDefaults
|
|
209
|
+
)) {
|
|
210
|
+
const d = own(fieldDefaults, name);
|
|
211
|
+
const title = own(d, "label");
|
|
212
|
+
const description = own(d, "description");
|
|
213
|
+
const href = own(d, "href");
|
|
214
|
+
if (title !== void 0 || description !== void 0 || href !== void 0) {
|
|
215
|
+
Object.defineProperty(properties, name, { value: { title, description, externalDocs: { url: href } }, enumerable: true });
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
if (Object.keys(properties).length === 0) {
|
|
219
|
+
return map;
|
|
220
|
+
}
|
|
221
|
+
const clean = fieldDefaultsFromSchema({ properties }).defaults;
|
|
222
|
+
for (const name of Object.keys(clean)) {
|
|
223
|
+
const { label, description, href } = clean[name];
|
|
224
|
+
const info = {};
|
|
225
|
+
if (label) {
|
|
226
|
+
info.label = label;
|
|
227
|
+
}
|
|
228
|
+
if (description) {
|
|
229
|
+
info.description = description;
|
|
230
|
+
if (href) {
|
|
231
|
+
info.href = href;
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
if (Object.keys(info).length) {
|
|
235
|
+
map.set(name.toLowerCase(), info);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
return map;
|
|
239
|
+
}
|
|
240
|
+
function displayNames(info, fieldNames = []) {
|
|
241
|
+
const spelling = new Map(fieldNames.map((n) => [String(n).toLowerCase(), String(n)]));
|
|
242
|
+
const uses = /* @__PURE__ */ new Map();
|
|
243
|
+
for (const entry of info.values()) {
|
|
244
|
+
if (entry.label) {
|
|
245
|
+
const l = entry.label.toLowerCase();
|
|
246
|
+
uses.set(l, (uses.get(l) ?? 0) + 1);
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
const out = {};
|
|
250
|
+
for (const [key, entry] of info) {
|
|
251
|
+
if (!entry.label) {
|
|
252
|
+
continue;
|
|
253
|
+
}
|
|
254
|
+
const l = entry.label.toLowerCase();
|
|
255
|
+
const clash = uses.get(l) > 1 || spelling.has(l) && l !== key;
|
|
256
|
+
const value = clash ? `${entry.label} (${spelling.get(key) ?? key})` : entry.label;
|
|
257
|
+
Object.defineProperty(out, key, { value, enumerable: true });
|
|
258
|
+
}
|
|
259
|
+
return Object.keys(out).length ? out : null;
|
|
260
|
+
}
|
|
261
|
+
function typesOf(fieldDefaults) {
|
|
262
|
+
if (!isObject(fieldDefaults)) {
|
|
263
|
+
return null;
|
|
264
|
+
}
|
|
265
|
+
const out = {};
|
|
266
|
+
for (const name of Object.keys(
|
|
267
|
+
/** @type {object} */
|
|
268
|
+
fieldDefaults
|
|
269
|
+
)) {
|
|
270
|
+
const type = own(own(fieldDefaults, name), "type");
|
|
271
|
+
if (typeof type === "string" && TYPES.includes(type)) {
|
|
272
|
+
Object.defineProperty(out, name, { value: type, enumerable: true });
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
return Object.keys(out).length ? out : null;
|
|
276
|
+
}
|
|
277
|
+
function fieldMatches(field, query, info, shown) {
|
|
278
|
+
if (!query) {
|
|
279
|
+
return true;
|
|
280
|
+
}
|
|
281
|
+
return [field, info?.label, shown, info?.description].some((t) => typeof t === "string" && t.toLowerCase().includes(query));
|
|
282
|
+
}
|
|
283
|
+
function matchingFields(fields, query, info, nameOf) {
|
|
284
|
+
const q = query.trim().toLowerCase();
|
|
285
|
+
return q ? fields.filter((f) => fieldMatches(f.name, q, info.get(f.name.toLowerCase()), nameOf?.(f.name))) : fields;
|
|
286
|
+
}
|
|
287
|
+
var identifierColumns = /* @__PURE__ */ new WeakMap();
|
|
288
|
+
function isIdentifier(column) {
|
|
289
|
+
if (!column || column.type !== "number" || column.derived || !isIdentifierName(column.name)) {
|
|
290
|
+
return false;
|
|
291
|
+
}
|
|
292
|
+
const known = identifierColumns.get(column);
|
|
293
|
+
if (known !== void 0) {
|
|
294
|
+
return known;
|
|
295
|
+
}
|
|
296
|
+
let whole = true;
|
|
297
|
+
for (let i = 0; i < column.dict.length && whole; i++) {
|
|
298
|
+
whole = Number.isInteger(column.dict[i]);
|
|
299
|
+
}
|
|
300
|
+
identifierColumns.set(column, whole);
|
|
301
|
+
return whole;
|
|
302
|
+
}
|
|
303
|
+
function fieldDefaultsFor(fieldDefaults, field, column) {
|
|
304
|
+
const key = isObject(fieldDefaults) ? Object.keys(
|
|
305
|
+
/** @type {object} */
|
|
306
|
+
fieldDefaults
|
|
307
|
+
).find((k) => k.toLowerCase() === String(field).toLowerCase()) : void 0;
|
|
308
|
+
const host = key === void 0 ? void 0 : own(fieldDefaults, key);
|
|
309
|
+
const set = ["agg", "format", "drillFormat"].some((k) => own(host, k) !== void 0);
|
|
310
|
+
if (set || !isIdentifier(column)) {
|
|
311
|
+
return isObject(host) ? host : void 0;
|
|
312
|
+
}
|
|
313
|
+
return { ...isObject(host) ? host : {}, agg: "count", drillFormat: "text" };
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// src/clear-input.jsx
|
|
317
|
+
import React, { useRef } from "react";
|
|
318
|
+
function emptyField(el) {
|
|
319
|
+
el.focus({ preventScroll: true });
|
|
320
|
+
let done;
|
|
321
|
+
try {
|
|
322
|
+
el.select();
|
|
323
|
+
const doc = (
|
|
324
|
+
/** @type {Document & { execCommand?: (cmd: string) => boolean }} */
|
|
325
|
+
el.ownerDocument
|
|
326
|
+
);
|
|
327
|
+
done = typeof doc.execCommand === "function" && doc.execCommand("delete") && el.value === "";
|
|
328
|
+
} catch {
|
|
329
|
+
done = false;
|
|
330
|
+
}
|
|
331
|
+
if (!done) {
|
|
332
|
+
const proto = el instanceof HTMLTextAreaElement ? HTMLTextAreaElement.prototype : HTMLInputElement.prototype;
|
|
333
|
+
Object.getOwnPropertyDescriptor(proto, "value")?.set?.call(el, "");
|
|
334
|
+
el.dispatchEvent(new Event("input", { bubbles: true }));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
function ClearInput({ value, onChange, onClear, clearLabel, multiline = false, className, inputRef, ...rest }) {
|
|
338
|
+
const own2 = useRef(
|
|
339
|
+
/** @type {HTMLInputElement | HTMLTextAreaElement | null} */
|
|
340
|
+
null
|
|
341
|
+
);
|
|
342
|
+
const name = useFormName();
|
|
343
|
+
const ref = inputRef ?? own2;
|
|
344
|
+
const clear = () => {
|
|
345
|
+
if (ref.current) {
|
|
346
|
+
emptyField(ref.current);
|
|
347
|
+
}
|
|
348
|
+
onClear?.();
|
|
349
|
+
};
|
|
350
|
+
const onKeyDown = (e) => {
|
|
351
|
+
rest.onKeyDown?.(e);
|
|
352
|
+
if (e.key === "Escape" && value !== "" && !e.defaultPrevented) {
|
|
353
|
+
e.preventDefault();
|
|
354
|
+
e.stopPropagation();
|
|
355
|
+
clear();
|
|
356
|
+
}
|
|
357
|
+
};
|
|
358
|
+
const Tag = multiline ? "textarea" : "input";
|
|
359
|
+
return /* @__PURE__ */ React.createElement("span", { className: `pk-clear-input${multiline ? " pk-clear-multi" : ""}${className ? ` ${className}` : ""}` }, /* @__PURE__ */ React.createElement(Tag, { name, ...rest, ref, value, onChange: (e) => onChange(e.target.value), onKeyDown }), value !== "" ? /* @__PURE__ */ React.createElement(
|
|
360
|
+
"button",
|
|
361
|
+
{
|
|
362
|
+
type: "button",
|
|
363
|
+
className: "pk-clear-x",
|
|
364
|
+
"aria-label": clearLabel,
|
|
365
|
+
title: clearLabel,
|
|
366
|
+
onPointerDown: (e) => e.preventDefault(),
|
|
367
|
+
onMouseDown: (e) => e.preventDefault(),
|
|
368
|
+
onClick: clear,
|
|
369
|
+
"data-testid": "clear-input"
|
|
370
|
+
},
|
|
371
|
+
/* @__PURE__ */ React.createElement(Icon, { name: "x", size: 14 })
|
|
372
|
+
) : null);
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
// src/info.jsx
|
|
376
|
+
import React2, { useCallback, useEffect, useId, useRef as useRef2, useState } from "react";
|
|
377
|
+
var LEAVE_DELAY = 250;
|
|
378
|
+
var WAY_TIME = 1500;
|
|
379
|
+
function FieldDescription({ info, labels, link = true, className = "pk-field-desc" }) {
|
|
380
|
+
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);
|
|
381
|
+
}
|
|
382
|
+
function InfoButton({ info, name, labels, className, testId = "field-info", label: named, tabIndex, slot }) {
|
|
383
|
+
const [mode, setMode] = useState(
|
|
384
|
+
/** @type {null | "peek" | "open"} */
|
|
385
|
+
null
|
|
386
|
+
);
|
|
387
|
+
const ref = useRef2(
|
|
388
|
+
/** @type {HTMLButtonElement | null} */
|
|
389
|
+
null
|
|
390
|
+
);
|
|
391
|
+
const quiet = useRef2(false);
|
|
392
|
+
const leaving = useRef2(
|
|
393
|
+
/** @type {ReturnType<typeof setTimeout> | null} */
|
|
394
|
+
null
|
|
395
|
+
);
|
|
396
|
+
const id = useId();
|
|
397
|
+
const textId = useId();
|
|
398
|
+
const pointer = useRef2(
|
|
399
|
+
/** @type {{ x: number, y: number } | null} */
|
|
400
|
+
null
|
|
401
|
+
);
|
|
402
|
+
const muted = useRef2(false);
|
|
403
|
+
const muteIfHovered = () => {
|
|
404
|
+
muted.current = Boolean(ref.current?.matches(":hover"));
|
|
405
|
+
};
|
|
406
|
+
const stay = () => {
|
|
407
|
+
if (leaving.current) {
|
|
408
|
+
clearTimeout(leaving.current);
|
|
409
|
+
leaving.current = null;
|
|
410
|
+
}
|
|
411
|
+
};
|
|
412
|
+
const hovered = (onItsWay) => {
|
|
413
|
+
const button = ref.current;
|
|
414
|
+
const root = (
|
|
415
|
+
/** @type {Document | ShadowRoot | null} */
|
|
416
|
+
button?.getRootNode() ?? null
|
|
417
|
+
);
|
|
418
|
+
const pop = root && "getElementById" in root ? root.getElementById(id) : null;
|
|
419
|
+
return Boolean(
|
|
420
|
+
button?.matches(":hover") || pop?.matches(":hover") || onItsWay && button && pop && onTheWay(button.getBoundingClientRect(), pop.getBoundingClientRect(), pointer.current)
|
|
421
|
+
);
|
|
422
|
+
};
|
|
423
|
+
const leaveSoon = () => {
|
|
424
|
+
stay();
|
|
425
|
+
const left = Date.now();
|
|
426
|
+
const check = () => {
|
|
427
|
+
if (hovered(Date.now() - left < WAY_TIME)) {
|
|
428
|
+
leaving.current = setTimeout(check, LEAVE_DELAY);
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
leaving.current = null;
|
|
432
|
+
setMode((m) => m === "peek" ? null : m);
|
|
433
|
+
};
|
|
434
|
+
leaving.current = setTimeout(check, LEAVE_DELAY);
|
|
435
|
+
};
|
|
436
|
+
useEffect(() => stay, []);
|
|
437
|
+
useEffect(() => {
|
|
438
|
+
const doc = ref.current?.ownerDocument;
|
|
439
|
+
if (mode !== "peek" || !doc) {
|
|
440
|
+
return void 0;
|
|
441
|
+
}
|
|
442
|
+
const follow = (e) => {
|
|
443
|
+
pointer.current = { x: e.clientX, y: e.clientY };
|
|
444
|
+
};
|
|
445
|
+
const gone = (e) => {
|
|
446
|
+
if (!e.relatedTarget) {
|
|
447
|
+
pointer.current = null;
|
|
448
|
+
}
|
|
449
|
+
};
|
|
450
|
+
doc.addEventListener("pointermove", follow, { capture: true, passive: true });
|
|
451
|
+
doc.addEventListener("pointerout", gone, { capture: true, passive: true });
|
|
452
|
+
return () => {
|
|
453
|
+
doc.removeEventListener("pointermove", follow, { capture: true });
|
|
454
|
+
doc.removeEventListener("pointerout", gone, { capture: true });
|
|
455
|
+
pointer.current = null;
|
|
456
|
+
};
|
|
457
|
+
}, [mode]);
|
|
458
|
+
const close = useCallback(() => {
|
|
459
|
+
quiet.current = true;
|
|
460
|
+
muteIfHovered();
|
|
461
|
+
setMode(null);
|
|
462
|
+
requestAnimationFrame(() => {
|
|
463
|
+
quiet.current = false;
|
|
464
|
+
});
|
|
465
|
+
}, []);
|
|
466
|
+
const label = named ?? fill(labels.aboutField, { field: name });
|
|
467
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(
|
|
468
|
+
"button",
|
|
469
|
+
{
|
|
470
|
+
ref,
|
|
471
|
+
type: "button",
|
|
472
|
+
className: `pk-info${className ? ` ${className}` : ""}`,
|
|
473
|
+
"aria-label": label,
|
|
474
|
+
"aria-describedby": textId,
|
|
475
|
+
"aria-expanded": mode === "open",
|
|
476
|
+
"aria-controls": mode ? id : void 0,
|
|
477
|
+
"aria-haspopup": "dialog",
|
|
478
|
+
tabIndex,
|
|
479
|
+
"data-pk-slot": slot,
|
|
480
|
+
"data-testid": testId,
|
|
481
|
+
onPointerMove: (e) => {
|
|
482
|
+
if (e.pointerType === "mouse" && !muted.current) {
|
|
483
|
+
stay();
|
|
484
|
+
setMode((m) => m ?? "peek");
|
|
485
|
+
}
|
|
486
|
+
},
|
|
487
|
+
onPointerLeave: (e) => {
|
|
488
|
+
muted.current = false;
|
|
489
|
+
if (e.pointerType === "mouse" && mode === "peek") {
|
|
490
|
+
leaveSoon();
|
|
491
|
+
}
|
|
492
|
+
},
|
|
493
|
+
onFocus: () => {
|
|
494
|
+
if (mode === null && !quiet.current) {
|
|
495
|
+
setMode("peek");
|
|
496
|
+
}
|
|
497
|
+
},
|
|
498
|
+
onBlur: (e) => {
|
|
499
|
+
const to = (
|
|
500
|
+
/** @type {Element | null} */
|
|
501
|
+
e.relatedTarget
|
|
502
|
+
);
|
|
503
|
+
if (mode === "peek" && !(to && to.closest?.(".pk-info-pop"))) {
|
|
504
|
+
setMode(null);
|
|
505
|
+
}
|
|
506
|
+
},
|
|
507
|
+
onClick: () => {
|
|
508
|
+
stay();
|
|
509
|
+
if (mode === "open") {
|
|
510
|
+
muteIfHovered();
|
|
511
|
+
}
|
|
512
|
+
setMode(mode === "open" ? null : "open");
|
|
513
|
+
}
|
|
514
|
+
},
|
|
515
|
+
/* @__PURE__ */ React2.createElement(Icon, { name: "info", size: 14 })
|
|
516
|
+
), /* @__PURE__ */ React2.createElement("span", { id: textId, hidden: true }, info.description), /* @__PURE__ */ React2.createElement(
|
|
517
|
+
Popover,
|
|
518
|
+
{
|
|
519
|
+
key: mode ?? "closed",
|
|
520
|
+
open: mode !== null,
|
|
521
|
+
passive: mode === "peek",
|
|
522
|
+
anchor: ref,
|
|
523
|
+
onClose: close,
|
|
524
|
+
label,
|
|
525
|
+
role: mode === "peek" ? "tooltip" : "dialog",
|
|
526
|
+
className: "pk-info-pop",
|
|
527
|
+
id,
|
|
528
|
+
onPointerEnter: stay,
|
|
529
|
+
onPointerLeave: (e) => {
|
|
530
|
+
if (e.pointerType === "mouse" && mode === "peek") {
|
|
531
|
+
leaveSoon();
|
|
532
|
+
}
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
/* @__PURE__ */ React2.createElement(FieldDescription, { info, labels })
|
|
536
|
+
));
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
// src/help.js
|
|
540
|
+
import { createContext } from "react";
|
|
541
|
+
var HelpContext = createContext(
|
|
542
|
+
/** @type {Help} */
|
|
543
|
+
{ explain: true, labels: null }
|
|
544
|
+
);
|
|
545
|
+
|
|
546
|
+
// src/share.js
|
|
547
|
+
import { VIEW_FILE_LIMITS, fromViewFile, linkFragment, normalize, outsideLimits, withLinkFragment } from "pivotkit-core";
|
|
548
|
+
var linkModule = null;
|
|
549
|
+
var linkLoaded = null;
|
|
550
|
+
function loadLink() {
|
|
551
|
+
linkModule ??= import("pivotkit-core/link").then((m) => {
|
|
552
|
+
linkLoaded = m;
|
|
553
|
+
return m;
|
|
554
|
+
});
|
|
555
|
+
return linkModule;
|
|
556
|
+
}
|
|
557
|
+
var linkNow = () => linkLoaded;
|
|
558
|
+
var readLinkParam = (hash, key) => linkFragment(hash, key);
|
|
559
|
+
var withLinkParam = (url, key, encoded) => withLinkFragment(url, key, encoded);
|
|
560
|
+
function shareBase(shareLink, here) {
|
|
561
|
+
if (shareLink === true) {
|
|
562
|
+
if (!here) {
|
|
563
|
+
return null;
|
|
564
|
+
}
|
|
565
|
+
try {
|
|
566
|
+
const url = new URL(here);
|
|
567
|
+
return `${url.origin}${url.pathname}${url.hash}`;
|
|
568
|
+
} catch {
|
|
569
|
+
return null;
|
|
570
|
+
}
|
|
571
|
+
}
|
|
572
|
+
return typeof shareLink === "string" && shareLink.trim() ? shareLink.trim() : null;
|
|
573
|
+
}
|
|
574
|
+
var viewStorageName = (key) => `pivotkit:view:${key ?? ""}`;
|
|
575
|
+
function readStoredView(key, storage) {
|
|
576
|
+
if (!storage) {
|
|
577
|
+
return null;
|
|
578
|
+
}
|
|
579
|
+
try {
|
|
580
|
+
return storage.getItem(viewStorageName(key));
|
|
581
|
+
} catch {
|
|
582
|
+
return null;
|
|
583
|
+
}
|
|
584
|
+
}
|
|
585
|
+
function writeStoredView(key, storage, view) {
|
|
586
|
+
if (!storage) {
|
|
587
|
+
return;
|
|
588
|
+
}
|
|
589
|
+
try {
|
|
590
|
+
storage.setItem(viewStorageName(key), JSON.stringify(view));
|
|
591
|
+
} catch {
|
|
592
|
+
}
|
|
593
|
+
}
|
|
594
|
+
var VIEW_TEXT_MAX = VIEW_FILE_LIMITS.text;
|
|
595
|
+
var quoteNames = (names, labels) => {
|
|
596
|
+
const shown = names.slice(0, 5).map((n) => fill(labels.quote, { text: n.length > 60 ? `${n.slice(0, 59)}\u2026` : n })).join(", ");
|
|
597
|
+
return names.length > 5 ? `${shown} \u2026` : shown;
|
|
598
|
+
};
|
|
599
|
+
var FAILED = Object.freeze({ newerFormat: "newer", newerView: "newer" });
|
|
600
|
+
function viewFromText(text, encoded, options = {}) {
|
|
601
|
+
return viewFromObject(text, encoded, options);
|
|
602
|
+
}
|
|
603
|
+
function viewFromObject(input, encoded, options = {}) {
|
|
604
|
+
const file = fromViewFile(input, { data: encoded, sourceId: options.sourceId });
|
|
605
|
+
if (file.failed || !file.view) {
|
|
606
|
+
const failed = file.failed ?? "notView";
|
|
607
|
+
return { view: null, issues: file.issues, failed: Object.hasOwn(FAILED, failed) ? FAILED[failed] : failed, file };
|
|
608
|
+
}
|
|
609
|
+
const { view, issues } = normalize(file.view, encoded, { limits: outsideLimits(options.limits) });
|
|
610
|
+
if (issues.some((i) => i.path === "version")) {
|
|
611
|
+
return { view: null, issues, failed: "newer", file };
|
|
612
|
+
}
|
|
613
|
+
return { view, issues, failed: null, file };
|
|
614
|
+
}
|
|
615
|
+
function loadCheck(loaded2, labels, sources = []) {
|
|
616
|
+
const fit = loaded2.file?.compatible;
|
|
617
|
+
if (!loaded2.view || !fit || fit.ok) {
|
|
618
|
+
return null;
|
|
619
|
+
}
|
|
620
|
+
const lines = [];
|
|
621
|
+
const fileSource = loaded2.file?.source;
|
|
622
|
+
const target = fit.source === "other" && fileSource?.id ? sources.find((s) => s && s.id === fileSource.id) : void 0;
|
|
623
|
+
if (fit.source === "other") {
|
|
624
|
+
const name = target?.name || fileSource?.name || fileSource?.id;
|
|
625
|
+
lines.push(name ? fill(labels.loadCheckSource, { source: name }) : labels.loadCheckOtherSource);
|
|
626
|
+
}
|
|
627
|
+
if (fit.missing.length) {
|
|
628
|
+
lines.push(fill(labels.loadCheckMissing, { fields: quoteNames(fit.missing, labels) }));
|
|
629
|
+
}
|
|
630
|
+
if (fit.changed.length) {
|
|
631
|
+
lines.push(fill(labels.loadCheckChanged, { fields: quoteNames(fit.changed.map((c) => c.name), labels) }));
|
|
632
|
+
}
|
|
633
|
+
return { lines, switchTo: target ? { id: target.id, name: target.name || target.id } : null };
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
// src/lazy-import.js
|
|
637
|
+
var pending = null;
|
|
638
|
+
var loaded = null;
|
|
639
|
+
function loadImport() {
|
|
640
|
+
pending ??= import("../import-ui.js").then(
|
|
641
|
+
(m) => loaded = m,
|
|
642
|
+
(error) => {
|
|
643
|
+
pending = null;
|
|
644
|
+
throw error;
|
|
645
|
+
}
|
|
646
|
+
);
|
|
647
|
+
return pending;
|
|
648
|
+
}
|
|
649
|
+
var importNow = () => loaded;
|
|
650
|
+
|
|
651
|
+
export {
|
|
652
|
+
DRILL_LIMIT,
|
|
653
|
+
decodeRow,
|
|
654
|
+
drillRows,
|
|
655
|
+
dateFormatter,
|
|
656
|
+
dateDisplayLocale,
|
|
657
|
+
dateRangeText,
|
|
658
|
+
dateContext,
|
|
659
|
+
fieldInfoOf,
|
|
660
|
+
displayNames,
|
|
661
|
+
typesOf,
|
|
662
|
+
matchingFields,
|
|
663
|
+
fieldDefaultsFor,
|
|
664
|
+
ClearInput,
|
|
665
|
+
InfoButton,
|
|
666
|
+
HelpContext,
|
|
667
|
+
loadLink,
|
|
668
|
+
linkNow,
|
|
669
|
+
readLinkParam,
|
|
670
|
+
withLinkParam,
|
|
671
|
+
shareBase,
|
|
672
|
+
readStoredView,
|
|
673
|
+
writeStoredView,
|
|
674
|
+
viewFromText,
|
|
675
|
+
viewFromObject,
|
|
676
|
+
loadCheck,
|
|
677
|
+
loadImport,
|
|
678
|
+
importNow
|
|
679
|
+
};
|