pivotkit-react 0.5.0 → 0.6.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/dist/import-ui.js CHANGED
@@ -1,3 +1,6 @@
1
+ import {
2
+ sheetPlan
3
+ } from "./chunks/chunk-W2KIPREL.js";
1
4
  import {
2
5
  Group,
3
6
  Icon,
@@ -12,12 +15,12 @@ import {
12
15
  errorText,
13
16
  importLabels,
14
17
  noteText
15
- } from "./chunks/chunk-3E4NB5RZ.js";
18
+ } from "./chunks/chunk-7LERNGUW.js";
16
19
  import {
17
20
  fill,
18
21
  messageOf,
19
22
  plural
20
- } from "./chunks/chunk-3WUGQPWV.js";
23
+ } from "./chunks/chunk-XN5HNKJ2.js";
21
24
 
22
25
  // src/import-host.jsx
23
26
  import React2 from "react";
@@ -26,7 +29,7 @@ import React2 from "react";
26
29
  import React, { useContext, useEffect, useId, useMemo, useRef, useState } from "react";
27
30
  import { createPortal } from "react-dom";
28
31
  import { encode } from "pivotkit-core";
29
- import { IMPORT_TYPES, fileName, retype } from "pivotkit-core/import";
32
+ import { IMPORT_TYPES, fileName, retype, shownName, sourceIdOf } from "pivotkit-core/import";
30
33
 
31
34
  // src/import-run.js
32
35
  import { PivotkitError } from "pivotkit-core";
@@ -157,148 +160,6 @@ async function sheetsOf(file, { plugins = [], limits, signal } = {}) {
157
160
  return Array.isArray(list) ? list.filter((s) => s && typeof s.name === "string" && Number.isInteger(s.index)) : [];
158
161
  }
159
162
 
160
- // src/import-source.js
161
- var SHOWN_MAX = 120;
162
- function shownName(name) {
163
- if (name.length <= SHOWN_MAX) {
164
- return name;
165
- }
166
- let cut = SHOWN_MAX - 3;
167
- const code = name.charCodeAt(cut - 1);
168
- if (code >= 55296 && code <= 56319) {
169
- cut -= 1;
170
- }
171
- return `${name.slice(0, cut)}...`;
172
- }
173
- var K = new Uint32Array([
174
- 1116352408,
175
- 1899447441,
176
- 3049323471,
177
- 3921009573,
178
- 961987163,
179
- 1508970993,
180
- 2453635748,
181
- 2870763221,
182
- 3624381080,
183
- 310598401,
184
- 607225278,
185
- 1426881987,
186
- 1925078388,
187
- 2162078206,
188
- 2614888103,
189
- 3248222580,
190
- 3835390401,
191
- 4022224774,
192
- 264347078,
193
- 604807628,
194
- 770255983,
195
- 1249150122,
196
- 1555081692,
197
- 1996064986,
198
- 2554220882,
199
- 2821834349,
200
- 2952996808,
201
- 3210313671,
202
- 3336571891,
203
- 3584528711,
204
- 113926993,
205
- 338241895,
206
- 666307205,
207
- 773529912,
208
- 1294757372,
209
- 1396182291,
210
- 1695183700,
211
- 1986661051,
212
- 2177026350,
213
- 2456956037,
214
- 2730485921,
215
- 2820302411,
216
- 3259730800,
217
- 3345764771,
218
- 3516065817,
219
- 3600352804,
220
- 4094571909,
221
- 275423344,
222
- 430227734,
223
- 506948616,
224
- 659060556,
225
- 883997877,
226
- 958139571,
227
- 1322822218,
228
- 1537002063,
229
- 1747873779,
230
- 1955562222,
231
- 2024104815,
232
- 2227730452,
233
- 2361852424,
234
- 2428436474,
235
- 2756734187,
236
- 3204031479,
237
- 3329325298
238
- ]);
239
- function sha256Bytes(bytes) {
240
- const bits = bytes.length * 8;
241
- const padded = new Uint8Array(Math.ceil((bytes.length + 9) / 64) * 64);
242
- padded.set(bytes);
243
- padded[bytes.length] = 128;
244
- const view = new DataView(padded.buffer);
245
- view.setUint32(padded.length - 8, Math.floor(bits / 2 ** 32));
246
- view.setUint32(padded.length - 4, bits >>> 0);
247
- const h = new Uint32Array([1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]);
248
- const w = new Uint32Array(64);
249
- const rotr = (x, n) => x >>> n | x << 32 - n;
250
- for (let at = 0; at < padded.length; at += 64) {
251
- for (let i = 0; i < 16; i++) {
252
- w[i] = view.getUint32(at + i * 4);
253
- }
254
- for (let i = 16; i < 64; i++) {
255
- const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
256
- const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ w[i - 2] >>> 10;
257
- w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
258
- }
259
- let [a, b, c, d, e, f, g, hh] = h;
260
- for (let i = 0; i < 64; i++) {
261
- const t1 = hh + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + (e & f ^ ~e & g) + K[i] + w[i] >>> 0;
262
- const t2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
263
- hh = g;
264
- g = f;
265
- f = e;
266
- e = d + t1 >>> 0;
267
- d = c;
268
- c = b;
269
- b = a;
270
- a = t1 + t2 >>> 0;
271
- }
272
- h[0] += a;
273
- h[1] += b;
274
- h[2] += c;
275
- h[3] += d;
276
- h[4] += e;
277
- h[5] += f;
278
- h[6] += g;
279
- h[7] += hh;
280
- }
281
- const out = new Uint8Array(32);
282
- const outView = new DataView(out.buffer);
283
- h.forEach((v, i) => outView.setUint32(i * 4, v));
284
- return out;
285
- }
286
- async function sha256Hex(text, options = {}) {
287
- const bytes = new TextEncoder().encode(text);
288
- const subtle = options.subtle !== void 0 ? options.subtle : globalThis.crypto?.subtle;
289
- let digest;
290
- try {
291
- digest = subtle ? new Uint8Array(await subtle.digest("SHA-256", bytes)) : sha256Bytes(bytes);
292
- } catch {
293
- digest = sha256Bytes(bytes);
294
- }
295
- return [...digest].map((b) => b.toString(16).padStart(2, "0")).join("");
296
- }
297
- async function sourceIdOf(name, columns, options) {
298
- const hex = await sha256Hex([name, ...columns].join("\0"), options);
299
- return `${shownName(name)}#${hex.slice(0, 16)}`;
300
- }
301
-
302
163
  // src/import-ui.jsx
303
164
  var PREVIEW_ROWS = 8;
304
165
  var PREVIEW_COLUMNS = 60;
@@ -381,15 +242,15 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
381
242
  const file = job.file;
382
243
  const name = useMemo(() => fileName(file, {}), [file]);
383
244
  const [sheet, setSheet] = useState(
384
- /** @type {number | undefined} */
385
- void 0
245
+ /** @type {number | string | undefined} */
246
+ job.sheet
386
247
  );
387
248
  const [sheets, setSheets] = useState(
388
249
  /** @type {import("pivotkit-core/import").SheetInfo[]} */
389
250
  []
390
251
  );
391
252
  const [read, setRead] = useState(
392
- /** @type {{ table: import("pivotkit-core/import").ImportTable, sheet: number | undefined } | null} */
253
+ /** @type {{ table: import("pivotkit-core/import").ImportTable, sheet: number | string | undefined } | null} */
393
254
  null
394
255
  );
395
256
  const [types, setTypes] = useState(
@@ -406,7 +267,7 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
406
267
  );
407
268
  const [busy, setBusy] = useState(false);
408
269
  const [failed, setFailed] = useState(
409
- /** @type {number | undefined | null} */
270
+ /** @type {number | string | undefined | null} */
410
271
  null
411
272
  );
412
273
  const current = read && read.sheet === sheet ? read : null;
@@ -510,7 +371,7 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
510
371
  const n = shown?.notes.find((x) => x.code === "SHEET");
511
372
  return n && n.params?.sheet !== void 0 ? String(n.params.sheet) : null;
512
373
  })();
513
- const sheetIndex = sheet ?? sheets.find((s) => s.name === sheetName)?.index ?? 0;
374
+ const sheetIndex = typeof sheet === "number" ? sheet : sheets.find((s) => s.name === sheetName)?.index ?? 0;
514
375
  const apply = async () => {
515
376
  if (!shown || busy) {
516
377
  return;
@@ -528,6 +389,8 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
528
389
  source: { id, name: shownName(name) },
529
390
  file: { name, size: file.size, type: file.type },
530
391
  sheet: sheetName,
392
+ sheets: sheets.map((s) => s.name),
393
+ blob: file,
531
394
  rows: shown.rowCount,
532
395
  columns: shown.columns.map((c, i) => ({ name: c, type: shown.types[i] })),
533
396
  notes: shown.notes.map((n) => ({ code: n.code, params: { ...n.params }, message: n.message }))
@@ -539,6 +402,13 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
539
402
  }
540
403
  }
541
404
  };
405
+ const autoDone = useRef(false);
406
+ useEffect(() => {
407
+ if (job.auto && ready && shown && shown.rowCount > 0 && !typed.error && !autoDone.current) {
408
+ autoDone.current = true;
409
+ void apply();
410
+ }
411
+ });
542
412
  if (!layer) {
543
413
  return null;
544
414
  }
@@ -638,7 +508,7 @@ function tell(ctx, detail) {
638
508
  }
639
509
  }
640
510
  function loadData(ctx, loaded) {
641
- const data = { key: ++keys, encoded: loaded.encoded, source: loaded.source, sheet: loaded.sheet, file: loaded.file };
511
+ const data = { key: ++keys, encoded: loaded.encoded, source: loaded.source, sheet: loaded.sheet, sheets: loaded.sheets, blob: loaded.blob, file: loaded.file };
642
512
  const t = importLabels(ctx.labels);
643
513
  const told = tell(ctx, describe(ctx, data, "load", loaded.notes));
644
514
  if (told.refused) {
@@ -694,17 +564,46 @@ function sayError(api, text) {
694
564
  }
695
565
  }
696
566
  function startFiles(api, files) {
697
- const dismiss = api.dismiss;
698
- if (typeof dismiss === "function") {
699
- (shownErrors.get(dismiss) ?? []).forEach((id) => dismiss(id));
700
- shownErrors.delete(dismiss);
701
- }
567
+ closeErrors(api);
702
568
  if (files.length === 1) {
703
569
  api.setJob({ file: files[0], n: ++jobs });
704
570
  } else if (files.length > 1) {
705
571
  sayError(api, importLabels(api.labels).dropOne);
706
572
  }
707
573
  }
574
+ function loadSheet(api, sheet, done) {
575
+ const file = api.imported?.blob;
576
+ if (!file) {
577
+ done(false);
578
+ return;
579
+ }
580
+ closeErrors(api);
581
+ api.setJob({ file, n: ++jobs, sheet, auto: true, done });
582
+ }
583
+ function openOnSheet(api, made, name, then) {
584
+ const shown = api.imported;
585
+ const plan = sheetPlan(made, { id: shown?.source.id, sheet: shown?.sheet ?? null, sheets: shown?.sheets ?? [] });
586
+ const t = importLabels(api.labels);
587
+ if (plan.kind === "switch") {
588
+ api.afterData(null);
589
+ loadSheet(api, plan.sheet, (loaded, refused) => {
590
+ api.afterData(loaded ? then : null);
591
+ if (refused) {
592
+ sayError(api, fill(t.sheetRefused, { name, sheet: plan.sheet }));
593
+ }
594
+ });
595
+ } else if (plan.kind === "missing") {
596
+ sayError(api, fill(t.sheetMissing, { name, sheet: plan.sheet, file: shown?.file.name ?? "" }));
597
+ }
598
+ return plan.kind;
599
+ }
600
+ function closeErrors(api) {
601
+ const dismiss = api.dismiss;
602
+ if (typeof dismiss === "function") {
603
+ (shownErrors.get(dismiss) ?? []).forEach((id) => dismiss(id));
604
+ shownErrors.delete(dismiss);
605
+ }
606
+ }
708
607
  function pickFile(input) {
709
608
  if (input) {
710
609
  input.value = "";
@@ -739,10 +638,14 @@ function ImportLayer({ api, input }) {
739
638
  limits: api.limits,
740
639
  timeZone: api.timeZone,
741
640
  announce: (text, extra) => extra?.tone === "error" ? sayError(api, text) : api.announce(text, extra),
742
- onClose: () => api.setJob((j) => j === job ? null : j),
641
+ onClose: () => {
642
+ api.setJob((j) => j === job ? null : j);
643
+ job.done?.(false);
644
+ },
743
645
  onApply: (loaded) => {
744
- loadData(api, loaded);
646
+ const ok = loadData(api, loaded);
745
647
  api.setJob((j) => j === job ? null : j);
648
+ job.done?.(ok, !ok);
746
649
  }
747
650
  }
748
651
  ) : null);
@@ -758,7 +661,9 @@ export {
758
661
  DataMenuPanel,
759
662
  ImportLayer,
760
663
  SourceLine2 as SourceLine,
664
+ loadSheet,
761
665
  moveData,
666
+ openOnSheet,
762
667
  pickFile,
763
668
  restoreData,
764
669
  startFiles
package/dist/index.js CHANGED
@@ -76,7 +76,7 @@ import {
76
76
  writeItem,
77
77
  writeStoredView,
78
78
  zoneOverLimit
79
- } from "./chunks/chunk-2AT72SLA.js";
79
+ } from "./chunks/chunk-2RAVX4DO.js";
80
80
  import {
81
81
  FormNameContext,
82
82
  Group,
@@ -101,7 +101,7 @@ import {
101
101
  messageOf,
102
102
  plural,
103
103
  resolveLabels
104
- } from "./chunks/chunk-3WUGQPWV.js";
104
+ } from "./chunks/chunk-XN5HNKJ2.js";
105
105
 
106
106
  // src/PivotReport.jsx
107
107
  import React12, { useCallback as useCallback9, useEffect as useEffect11, useId as useId4, useMemo as useMemo8, useRef as useRef11, useState as useState12, useSyncExternalStore as useSyncExternalStore3 } from "react";
@@ -457,7 +457,7 @@ function ChipList({ ids, children }) {
457
457
  }
458
458
 
459
459
  // src/field-info.js
460
- import { fieldDefaultsFromSchema } from "pivotkit-core";
460
+ import { fieldDefaultsFromSchema, isIdentifierName } from "pivotkit-core";
461
461
  var isObject = (v) => v !== null && typeof v === "object" && !Array.isArray(v);
462
462
  var own = (o, k) => isObject(o) && Object.hasOwn(o, k) ? o[k] : void 0;
463
463
  var TYPES = Object.freeze(["string", "number", "date", "boolean"]);
@@ -544,15 +544,6 @@ function fieldMatches(field, query, info) {
544
544
  }
545
545
  return [field, info?.label, info?.description].some((t) => typeof t === "string" && t.toLowerCase().includes(query));
546
546
  }
547
- var IDENTIFIER_WORDS = Object.freeze(["id", "nr", "no", "number", "key", "#"]);
548
- function isIdentifierName(name) {
549
- const words = String(name).replace(/(\s*\([^()]*\))+\s*$/, "").replace(/([a-z0-9])([A-Z])/g, "$1 $2").replace(/([A-Za-z])(\d)/g, "$1 $2").replace(/#/g, " # ").split(/[\s_.\-/:()]+/).filter(Boolean);
550
- while (words.length > 1 && /^\d+$/.test(words[words.length - 1])) {
551
- words.pop();
552
- }
553
- const last = words[words.length - 1];
554
- return last !== void 0 && IDENTIFIER_WORDS.includes(last.toLowerCase());
555
- }
556
547
  var identifierColumns = /* @__PURE__ */ new WeakMap();
557
548
  function isIdentifier(column) {
558
549
  if (!column || column.type !== "number" || column.derived || !isIdentifierName(column.name)) {
@@ -1522,10 +1513,13 @@ function templateEntries(templates, stored, hostDeletes) {
1522
1513
  continue;
1523
1514
  }
1524
1515
  let { name, view } = t;
1516
+ let made = {};
1525
1517
  if (t.file !== void 0 && t.file !== null) {
1526
1518
  const read = fromViewFile(t.file);
1527
1519
  view = read.view;
1528
1520
  name = typeof name === "string" && name ? name : read.name;
1521
+ const sheet = read.source?.params?.sheet;
1522
+ made = { ...read.source?.id ? { fileSource: read.source.id } : {}, ...sheet && read.source?.id ? { sheet, sheetOf: read.source.id } : {} };
1529
1523
  }
1530
1524
  if (typeof name === "string" && name && view && typeof view === "object") {
1531
1525
  const deletable = t.deletable === true;
@@ -1534,13 +1528,13 @@ function templateEntries(templates, stored, hostDeletes) {
1534
1528
  warnedScope = true;
1535
1529
  console.warn('pivotkit: a template marked deletable without a scope is listed under "My views"; give shared views scope: "shared"');
1536
1530
  }
1537
- out.push({ name, view, deletable: deletable && hostDeletes, scope: scoped ? t.scope : deletable ? "user" : "shared" });
1531
+ out.push({ name, view, deletable: deletable && hostDeletes, scope: scoped ? t.scope : deletable ? "user" : "shared", ...made });
1538
1532
  }
1539
1533
  }
1540
1534
  const all = [...out, ...stored.map((t) => ({ name: t.name, view: t.view, scope: (
1541
1535
  /** @type {const} */
1542
1536
  "user"
1543
- ), deletable: true, at: t.at, ...t.sourceId ? { sourceId: t.sourceId } : {} }))];
1537
+ ), deletable: true, at: t.at, ...t.sourceId ? { sourceId: t.sourceId } : {}, ...t.sheet ? { sheet: t.sheet } : {} }))];
1544
1538
  const names = plainNames(all.map((t) => t.name));
1545
1539
  return all.flatMap((t, i) => names[i] ? [{ ...t, name: (
1546
1540
  /** @type {string} */
@@ -2085,7 +2079,7 @@ function Toolbar(props) {
2085
2079
  return /* @__PURE__ */ React10.createElement("div", { className: `pk-toolbar${wrap ? " pk-wrap" : ""}`, role: "toolbar", "aria-label": labels.toolbar, ref: bar, "data-overflow": hidden.size }, size === "narrow" ? /* @__PURE__ */ React10.createElement("button", { type: "button", className: "pk-btn", onClick: onShowFields, "data-testid": "show-fields", "data-pk-opener": "fields" }, /* @__PURE__ */ React10.createElement(Icon, { name: "panel" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-btn-text" }, labels.showFields)) : null, /* @__PURE__ */ React10.createElement("div", { className: "pk-segmented", role: "group", "aria-label": labels.view }, /* @__PURE__ */ React10.createElement("button", { type: "button", "aria-pressed": view.display === "table", onClick: () => onDisplay("table"), "data-testid": "show-table" }, /* @__PURE__ */ React10.createElement(Icon, { name: "table" }), /* @__PURE__ */ React10.createElement("span", null, labels.table)), /* @__PURE__ */ React10.createElement("button", { type: "button", "aria-pressed": view.display === "chart", onClick: () => onDisplay("chart"), "data-testid": "show-chart" }, /* @__PURE__ */ React10.createElement(Icon, { name: (
2086
2080
  /** @type {any} */
2087
2081
  drawnIcon
2088
- ) }), /* @__PURE__ */ React10.createElement("span", null, labels.chart))), buttons("chart"), /* @__PURE__ */ React10.createElement("span", { className: "pk-sep", "aria-hidden": "true" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-toolbar-pair" }, /* @__PURE__ */ React10.createElement(TextButton, { icon: "undo", label: labels.undo, onClick: onUndo, disabled: !canUndo, testId: "undo", shortcut: `${mod}Z` }), /* @__PURE__ */ React10.createElement(TextButton, { icon: "redo", label: labels.redo, onClick: onRedo, disabled: !canRedo, testId: "redo", shortcut: `${mod}\u21E7Z` })), buttons("history"), /* @__PURE__ */ React10.createElement("span", { className: "pk-grow" }), end.slice(0, at), wrap ? null : name, end.slice(at), /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.exportLabel, icon: "download", text: labels.exportLabel, role: "dialog", align: "end", testId: "export" }, (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ExportPanel", loadingText: labels.loadingMenu, props: { labels, onExport, chartReady, display: view.display, empty, prepare: props.prepareExport, close } })), hidden.size > 0 ? /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.more, icon: "more", text: labels.more, align: "end", testId: "more", buttonRef: more, arrowOpens: true, mark: hidden.has("views") && loadedView?.changed ? changedMark("more-changed") : hidden.has("data") ? loadedMark("more-loaded") : null }, moreGroups) : null, wrap ? name : null, panel ? /* @__PURE__ */ React10.createElement(Popover, { open: true, anchor: more, onClose: closePanel, label: panel === "chartType" ? chartTypeText : panel === "views" ? labels.views : panel === "data" ? labels.data : labels.options, role: "dialog", align: "end", className: panel === "chartType" ? "pk-chart-menu" : void 0 }, panels[panel](closePanel)) : null);
2082
+ ) }), /* @__PURE__ */ React10.createElement("span", null, labels.chart))), buttons("chart"), /* @__PURE__ */ React10.createElement("span", { className: "pk-sep", "aria-hidden": "true" }), /* @__PURE__ */ React10.createElement("span", { className: "pk-toolbar-pair" }, /* @__PURE__ */ React10.createElement(TextButton, { icon: "undo", label: labels.undo, onClick: onUndo, disabled: !canUndo, testId: "undo", shortcut: `${mod}Z` }), /* @__PURE__ */ React10.createElement(TextButton, { icon: "redo", label: labels.redo, onClick: onRedo, disabled: !canRedo, testId: "redo", shortcut: `${mod}\u21E7Z` })), buttons("history"), /* @__PURE__ */ React10.createElement("span", { className: "pk-grow" }), end.slice(0, at), wrap ? null : name, end.slice(at), /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.exportLabel, icon: "download", text: labels.exportLabel, role: "dialog", align: "end", testId: "export" }, (close) => /* @__PURE__ */ React10.createElement(MenuPanel, { name: "ExportPanel", loadingText: labels.loadingMenu, props: { labels, onExport, chartReady, display: view.display, empty, dataExport: props.dataExport, prepare: props.prepareExport, close } })), hidden.size > 0 ? /* @__PURE__ */ React10.createElement(MenuButton, { label: labels.more, icon: "more", text: labels.more, align: "end", testId: "more", buttonRef: more, arrowOpens: true, mark: hidden.has("views") && loadedView?.changed ? changedMark("more-changed") : hidden.has("data") ? loadedMark("more-loaded") : null }, moreGroups) : null, wrap ? name : null, panel ? /* @__PURE__ */ React10.createElement(Popover, { open: true, anchor: more, onClose: closePanel, label: panel === "chartType" ? chartTypeText : panel === "views" ? labels.views : panel === "data" ? labels.data : labels.options, role: "dialog", align: "end", className: panel === "chartType" ? "pk-chart-menu" : void 0 }, panels[panel](closePanel)) : null);
2089
2083
  }
2090
2084
 
2091
2085
  // src/use-export.js
@@ -2679,7 +2673,7 @@ function Zones({ view, types, labels, commit, earlier, encoded, locale, onSwap,
2679
2673
  }
2680
2674
 
2681
2675
  // src/PivotReport.jsx
2682
- var savedKeyOf = (t) => JSON.stringify([t.scope, t.store, t.storeSource ?? null, t.sourceId ?? null, t.name]);
2676
+ var savedKeyOf = (t) => JSON.stringify([t.scope, t.store, t.storeSource ?? null, t.storeSheet ?? null, t.sourceId ?? null, t.name]);
2683
2677
  function sizeOf(width) {
2684
2678
  return width < 640 ? "narrow" : width < 1024 ? "medium" : "wide";
2685
2679
  }
@@ -2738,6 +2732,8 @@ var DEFER_ROWS = 1e4;
2738
2732
  var dataOf = (d) => Array.isArray(d) || Array.isArray(d?.columns) ? d : [];
2739
2733
  var rowsOf = (d) => Array.isArray(d) ? d.length : d?.data?.[0]?.length ?? 0;
2740
2734
  var NO_STEPS = Object.freeze({ past: [], future: [] });
2735
+ var NO_SHEETS = Object.freeze([]);
2736
+ var SHEET_GONE = "\0";
2741
2737
  var unusedNotes = (issues, raw) => issues.filter((i) => (i.code ?? (i.message === "unknown key" ? "unknownKey" : "")) !== "unknownKey" || !["name", "description"].includes(i.path)).map((issue) => ({ issue, raw }));
2742
2738
  function PivotReport(props) {
2743
2739
  const { loading: loading2 = false, data, encoded } = props;
@@ -2814,6 +2810,7 @@ function Report(props) {
2814
2810
  fileName = "pivot",
2815
2811
  fieldDefaults,
2816
2812
  onExport,
2813
+ exportData = false,
2817
2814
  label,
2818
2815
  tips: tipsProp = "on",
2819
2816
  storageKey,
@@ -2841,7 +2838,11 @@ function Report(props) {
2841
2838
  const hostSourceId = typeof sourceProp?.id === "string" && sourceProp.id ? sourceProp.id : void 0;
2842
2839
  const hostSourceName = typeof sourceProp?.name === "string" && sourceProp.name ? sourceProp.name : void 0;
2843
2840
  const [job, setJob] = useState12(
2844
- /** @type {{ file: File, n: number } | null} */
2841
+ /** @type {import("./import-host.jsx").ImportJob | null} */
2842
+ null
2843
+ );
2844
+ const afterSheet = useRef11(
2845
+ /** @type {(() => void) | null} */
2845
2846
  null
2846
2847
  );
2847
2848
  const [dragging, setDragging] = useState12(false);
@@ -2959,6 +2960,9 @@ function Report(props) {
2959
2960
  );
2960
2961
  const sourceId = imported ? imported.source.id : hostSourceId;
2961
2962
  const sourceName = imported ? imported.source.name : hostSourceName;
2963
+ const shownSheet = imported?.sheet ?? null;
2964
+ const shownSheets = imported?.sheets ?? NO_SHEETS;
2965
+ const sourceParams = shownSheet ? { sheet: shownSheet } : void 0;
2962
2966
  const encoded = imported ? imported.encoded : source.encoded;
2963
2967
  const limits = imported ? fileLimits : hostLimits;
2964
2968
  const fieldNamesKey = encoded.schema.fields.map((f) => f.name).join("\0");
@@ -3418,7 +3422,7 @@ function Report(props) {
3418
3422
  },
3419
3423
  [result, encodedProp, imported, data, drillDownLimit, onCellClick, drillDown, defaultsOf, nameOf, infoOf]
3420
3424
  );
3421
- const doExport = useExport({ fileName, result, locale, labels, limits, root, chartRef, announce, onExport, title: viewName, source: sourceName, loadECharts });
3425
+ const doExport = useExport({ fileName, result, encoded, exportData, locale, labels, limits, root, chartRef, announce, onExport, title: viewName, source: sourceName, loadECharts });
3422
3426
  const requestImport = () => loadImport().then((m) => (flushSync(() => setImportMod(() => m)), m));
3423
3427
  const api = {
3424
3428
  imported,
@@ -3445,7 +3449,9 @@ function Report(props) {
3445
3449
  undo: () => undoLater.current(),
3446
3450
  box: () => root.current?.getBoundingClientRect(),
3447
3451
  pick: () => importMod?.pickFile(fileInput.current),
3448
- load: requestImport
3452
+ load: requestImport,
3453
+ // what waits for another sheet of the file to be read (openOnSheet): it runs once that data is shown
3454
+ afterData: (run) => void (afterSheet.current = run)
3449
3455
  };
3450
3456
  useEffect11(() => {
3451
3457
  apiNow.current = api;
@@ -3503,6 +3509,9 @@ function Report(props) {
3503
3509
  viewName,
3504
3510
  sourceId,
3505
3511
  sourceName,
3512
+ sourceParams,
3513
+ // a view file that names another sheet of the workbook shown reads that sheet first
3514
+ viaSheet: (made, name, file) => viaSheet(made, name, () => loadLater.current?.({ file })),
3506
3515
  schemaUrl,
3507
3516
  encoded,
3508
3517
  shareLink,
@@ -3516,9 +3525,10 @@ function Report(props) {
3516
3525
  onSourceSwitch,
3517
3526
  applyLoaded
3518
3527
  };
3528
+ const viaSheet = (made, name, then) => imported && importMod ? importMod.openOnSheet(apiNow.current, made, name, then) : "none";
3519
3529
  const loadTemplate = useCallback9(
3520
3530
  (t) => {
3521
- const tag = { name: t.name, scope: t.scope === "user" ? "user" : "shared", store: t.at !== void 0, storeSource: t.sourceId ?? null, sourceId };
3531
+ const tag = { name: t.name, scope: t.scope === "user" ? "user" : "shared", store: t.at !== void 0, storeSource: t.sourceId ?? null, storeSheet: t.sheet ?? null, sourceId };
3522
3532
  remember(tag, history.keyOf(t.view));
3523
3533
  commit(t.view, { step: "template", name: t.name }, tag);
3524
3534
  const over = zoneOverLimit(t.view, limits);
@@ -3531,6 +3541,31 @@ function Report(props) {
3531
3541
  },
3532
3542
  [commit, labels, announce, limits, locale, history, remember, sourceId, encoded, leaveOut]
3533
3543
  );
3544
+ const openTemplate = (t) => {
3545
+ const how = viaSheet({ id: t.sourceId ?? t.sheetOf, sheet: t.sheet }, t.name, () => loadLater.current?.({ template: t }));
3546
+ if (how !== "switch") {
3547
+ loadTemplate(how === "missing" ? { ...t, sheet: SHEET_GONE } : t);
3548
+ }
3549
+ };
3550
+ const loadLater = useRef11(
3551
+ /** @type {((what: { template?: any, file?: object }) => void) | null} */
3552
+ null
3553
+ );
3554
+ useEffect11(() => {
3555
+ loadLater.current = ({ template, file }) => {
3556
+ if (template) {
3557
+ loadTemplate(template);
3558
+ } else if (file) {
3559
+ const loaded3 = viewFromObject(file, encoded, { limits, sourceId });
3560
+ applyLoaded(loaded3);
3561
+ }
3562
+ };
3563
+ const run = afterSheet.current;
3564
+ if (run && imported) {
3565
+ afterSheet.current = null;
3566
+ run();
3567
+ }
3568
+ }, [imported, loadTemplate, encoded, limits, sourceId, applyLoaded]);
3534
3569
  const newReport = () => {
3535
3570
  if (empty) {
3536
3571
  return;
@@ -3546,12 +3581,19 @@ function Report(props) {
3546
3581
  const subscribeViews = useCallback9((callback) => viewStore ? subscribeItem(storeName, callback) : () => {
3547
3582
  }, [viewStore, storeName]);
3548
3583
  const viewsText = useSyncExternalStore3(subscribeViews, () => viewStore ? readItem(storeName, localStore()) : null, () => null);
3549
- const entries = useMemo8(() => templateEntries(templates, viewStore && menus ? menus.storedViews(viewsText, sourceId) : [], Boolean(onDeleteTemplate)), [templates, viewStore, menus, viewsText, sourceId, onDeleteTemplate]);
3584
+ const entries = useMemo8(
3585
+ () => templateEntries(templates, viewStore && menus ? menus.storedViews(viewsText, sourceId, { sheet: shownSheet, sheets: shownSheets }) : [], Boolean(onDeleteTemplate)),
3586
+ [templates, viewStore, menus, viewsText, sourceId, shownSheet, shownSheets, onDeleteTemplate]
3587
+ );
3550
3588
  const templateActions = {
3551
3589
  view,
3552
3590
  announce,
3553
3591
  locale,
3554
3592
  sourceId,
3593
+ // the sheet of a workbook shown, which a view saved into the browser store names, and the data
3594
+ // shown as the host's callbacks get it
3595
+ sheet: shownSheet,
3596
+ source: sourceId ? { id: sourceId, ...sourceName ? { name: sourceName } : {}, ...sourceParams ? { params: sourceParams } : {} } : null,
3555
3597
  viewsText,
3556
3598
  store: viewStore,
3557
3599
  keep: (text) => writeItem(storeName, localStore(), text),
@@ -3828,10 +3870,11 @@ function Report(props) {
3828
3870
  folding,
3829
3871
  share,
3830
3872
  templates: entries,
3831
- onLoadTemplate: loadTemplate,
3873
+ onLoadTemplate: openTemplate,
3832
3874
  templateActions,
3833
3875
  onExport: doExport,
3834
3876
  prepareExport: prepareExporters,
3877
+ dataExport: exportData,
3835
3878
  chartReady: view.display === "chart" && chartReady,
3836
3879
  empty,
3837
3880
  onShowFields: () => setDrawer(true),
@@ -3895,7 +3938,7 @@ function Report(props) {
3895
3938
  onAction: runTip,
3896
3939
  focusFallback: () => root.current?.focus({ preventScroll: true })
3897
3940
  }
3898
- ), showTable && view.values.length ? /* @__PURE__ */ React12.createElement("p", { id: hintId, className: "pk-sr", "data-testid": "cell-hint" }, labels.tips.cells) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-result-head" }, big.enlarged ? /* @__PURE__ */ React12.createElement("p", { className: "pk-enlarged-fields", "data-testid": "enlarged-fields" }, summaryText) : null, /* @__PURE__ */ React12.createElement("span", { className: "pk-grow" }), /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "data-pk-on": big.enlarged ? "" : void 0, onClick: big.toggleEnlarged, "data-testid": "enlarge" }, /* @__PURE__ */ React12.createElement(Icon, { name: "enlarge", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, big.enlarged ? labels.reduce : labels.enlarge)), big.fullOk ? /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "aria-pressed": big.full, onClick: big.toggleFull, "data-testid": "full-screen" }, /* @__PURE__ */ React12.createElement(Icon, { name: "fullScreen", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, labels.fullScreen)) : null), /* @__PURE__ */ React12.createElement("section", { className: "pk-result", "aria-label": view.display === "chart" ? labels.chart : labels.table }, loading2 || opening ? /* @__PURE__ */ React12.createElement(Skeleton, { text: labels.loadingReport }) : error ? /* @__PURE__ */ React12.createElement("div", { className: "pk-message pk-error", role: "alert" }, /* @__PURE__ */ React12.createElement(Icon, { name: "info" }), /* @__PURE__ */ React12.createElement("p", null, errorText(error, labels, locale))) : empty && view.display === "table" ? /* @__PURE__ */ React12.createElement(EmptyState, { labels, templates: entries, onTemplate: loadTemplate, onLoad: allowImport ? () => requestImport().then((m) => m.pickFile(fileInput.current), () => announce(labels.menuFailed, { tone: "error" })) : void 0, noData: allowImport && fields.length === 0 }) : view.display === "chart" && chartResult ? /* @__PURE__ */ React12.createElement(
3941
+ ), showTable && view.values.length ? /* @__PURE__ */ React12.createElement("p", { id: hintId, className: "pk-sr", "data-testid": "cell-hint" }, labels.tips.cells) : null, /* @__PURE__ */ React12.createElement("div", { className: "pk-result-head" }, big.enlarged ? /* @__PURE__ */ React12.createElement("p", { className: "pk-enlarged-fields", "data-testid": "enlarged-fields" }, summaryText) : null, /* @__PURE__ */ React12.createElement("span", { className: "pk-grow" }), /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "data-pk-on": big.enlarged ? "" : void 0, onClick: big.toggleEnlarged, "data-testid": "enlarge" }, /* @__PURE__ */ React12.createElement(Icon, { name: "enlarge", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, big.enlarged ? labels.reduce : labels.enlarge)), big.fullOk ? /* @__PURE__ */ React12.createElement("button", { type: "button", className: "pk-btn pk-pressable pk-small-btn", "aria-pressed": big.full, onClick: big.toggleFull, "data-testid": "full-screen" }, /* @__PURE__ */ React12.createElement(Icon, { name: "fullScreen", size: 14 }), /* @__PURE__ */ React12.createElement("span", { className: "pk-btn-text" }, labels.fullScreen)) : null), /* @__PURE__ */ React12.createElement("section", { className: "pk-result", "aria-label": view.display === "chart" ? labels.chart : labels.table }, loading2 || opening ? /* @__PURE__ */ React12.createElement(Skeleton, { text: labels.loadingReport }) : error ? /* @__PURE__ */ React12.createElement("div", { className: "pk-message pk-error", role: "alert" }, /* @__PURE__ */ React12.createElement(Icon, { name: "info" }), /* @__PURE__ */ React12.createElement("p", null, errorText(error, labels, locale))) : empty && view.display === "table" ? /* @__PURE__ */ React12.createElement(EmptyState, { labels, templates: entries, onTemplate: openTemplate, onLoad: allowImport ? () => requestImport().then((m) => m.pickFile(fileInput.current), () => announce(labels.menuFailed, { tone: "error" })) : void 0, noData: allowImport && fields.length === 0 }) : view.display === "chart" && chartResult ? /* @__PURE__ */ React12.createElement(
3899
3942
  PivotChart,
3900
3943
  {
3901
3944
  result: chartResult,
package/dist/labels.js CHANGED
@@ -6,17 +6,17 @@ import {
6
6
  } from "./chunks/chunk-E6M57YLL.js";
7
7
  import {
8
8
  en
9
- } from "./chunks/chunk-U5Q5I2D5.js";
9
+ } from "./chunks/chunk-TR2HROIK.js";
10
10
  import {
11
11
  de
12
- } from "./chunks/chunk-4RS72AAA.js";
12
+ } from "./chunks/chunk-YXLANLGL.js";
13
13
  import {
14
14
  de as de2,
15
15
  en as en2
16
- } from "./chunks/chunk-3E4NB5RZ.js";
16
+ } from "./chunks/chunk-7LERNGUW.js";
17
17
  import {
18
18
  LABELS
19
- } from "./chunks/chunk-3WUGQPWV.js";
19
+ } from "./chunks/chunk-XN5HNKJ2.js";
20
20
 
21
21
  // src/all-labels.js
22
22
  var LABELS2 = Object.freeze({ en: { ...LABELS.en, ...en, unused: en3, dataImport: en2 }, de: { ...LABELS.de, ...de, unused: de3, dataImport: de2 } });
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  de
3
- } from "./chunks/chunk-4RS72AAA.js";
3
+ } from "./chunks/chunk-YXLANLGL.js";
4
4
  export {
5
5
  de
6
6
  };