pivotkit-react 0.4.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.
Files changed (59) hide show
  1. package/CHANGELOG.md +267 -1
  2. package/README.md +5 -2
  3. package/dist/chunks/{chunk-YITKWZ4L.js → chunk-2RAVX4DO.js} +604 -505
  4. package/dist/chunks/{chunk-ZYEYZSYL.js → chunk-7LERNGUW.js} +36 -2
  5. package/dist/chunks/{chunk-EM23V5GH.js → chunk-E6M57YLL.js} +19 -8
  6. package/dist/chunks/{chunk-RWYHJRQO.js → chunk-JMRTIOX4.js} +17 -7
  7. package/dist/chunks/{chunk-XN55BQ4M.js → chunk-RIOSIYGC.js} +54 -7
  8. package/dist/chunks/{chunk-LEN5RPBM.js → chunk-TR2HROIK.js} +43 -7
  9. package/dist/chunks/chunk-W2KIPREL.js +36 -0
  10. package/dist/chunks/{chunk-6MDAL3IO.js → chunk-XN5HNKJ2.js} +88 -101
  11. package/dist/chunks/{chunk-WB4GKWFQ.js → chunk-YXLANLGL.js} +34 -6
  12. package/dist/chunks/report-run-BZBFOMPF.js +12 -0
  13. package/dist/chunks/{unused-texts-K3VFH65P.js → unused-texts-Y4R67XSN.js} +1 -1
  14. package/dist/chunks/{unused-texts-de-OW4TGIVX.js → unused-texts-de-6YVPTNVS.js} +1 -1
  15. package/dist/echarts.js +38 -156
  16. package/dist/import-ui.js +69 -168
  17. package/dist/index.js +160 -102
  18. package/dist/labels.js +6 -6
  19. package/dist/menu-texts-de.js +1 -1
  20. package/dist/menus.js +778 -277
  21. package/dist/styles.css +207 -93
  22. package/package.json +8 -4
  23. package/types/chart-decorate.d.ts +28 -4
  24. package/types/chart-types.d.ts +2 -4
  25. package/types/echarts.d.ts +1 -1
  26. package/types/export-run.d.ts +42 -4
  27. package/types/field-info.d.ts +3 -10
  28. package/types/filter.d.ts +1 -1
  29. package/types/icons.d.ts +1 -0
  30. package/types/import-host.d.ts +34 -8
  31. package/types/import-labels.d.ts +47 -0
  32. package/types/import-limits.d.ts +6 -0
  33. package/types/import-module.d.ts +1 -1
  34. package/types/import-steps.d.ts +8 -0
  35. package/types/import-ui.d.ts +18 -4
  36. package/types/index.d.ts +76 -17
  37. package/types/labels.d.ts +200 -24
  38. package/types/light-tokens.d.ts +16 -0
  39. package/types/menu-labels.d.ts +43 -14
  40. package/types/menu-ops.d.ts +166 -43
  41. package/types/menu-topics.d.ts +7 -4
  42. package/types/names.d.ts +47 -19
  43. package/types/place.d.ts +24 -0
  44. package/types/print-frame.d.ts +24 -0
  45. package/types/report-run.d.ts +14 -0
  46. package/types/share-actions.d.ts +17 -3
  47. package/types/share.d.ts +13 -17
  48. package/types/sheet-views.d.ts +60 -0
  49. package/types/templates.d.ts +21 -1
  50. package/types/theme.d.ts +2 -16
  51. package/types/tips.d.ts +5 -0
  52. package/types/toolbar-panels.d.ts +9 -6
  53. package/types/unused-texts.d.ts +13 -3
  54. package/types/use-export.d.ts +2 -2
  55. package/types/view-ops.d.ts +65 -6
  56. package/types/view-save.d.ts +10 -6
  57. package/types/view-store.d.ts +21 -11
  58. package/types/chart-layout.d.ts +0 -111
  59. package/types/import-source.d.ts +0 -32
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,
@@ -7,16 +10,17 @@ import {
7
10
  useFormName,
8
11
  useModal,
9
12
  useTopLayer
10
- } from "./chunks/chunk-XN55BQ4M.js";
13
+ } from "./chunks/chunk-RIOSIYGC.js";
11
14
  import {
15
+ errorText,
12
16
  importLabels,
13
17
  noteText
14
- } from "./chunks/chunk-ZYEYZSYL.js";
18
+ } from "./chunks/chunk-7LERNGUW.js";
15
19
  import {
16
20
  fill,
17
21
  messageOf,
18
22
  plural
19
- } from "./chunks/chunk-6MDAL3IO.js";
23
+ } from "./chunks/chunk-XN5HNKJ2.js";
20
24
 
21
25
  // src/import-host.jsx
22
26
  import React2 from "react";
@@ -25,7 +29,7 @@ import React2 from "react";
25
29
  import React, { useContext, useEffect, useId, useMemo, useRef, useState } from "react";
26
30
  import { createPortal } from "react-dom";
27
31
  import { encode } from "pivotkit-core";
28
- import { IMPORT_TYPES, fileName, retype } from "pivotkit-core/import";
32
+ import { IMPORT_TYPES, fileName, retype, shownName, sourceIdOf } from "pivotkit-core/import";
29
33
 
30
34
  // src/import-run.js
31
35
  import { PivotkitError } from "pivotkit-core";
@@ -156,148 +160,6 @@ async function sheetsOf(file, { plugins = [], limits, signal } = {}) {
156
160
  return Array.isArray(list) ? list.filter((s) => s && typeof s.name === "string" && Number.isInteger(s.index)) : [];
157
161
  }
158
162
 
159
- // src/import-source.js
160
- var SHOWN_MAX = 120;
161
- function shownName(name) {
162
- if (name.length <= SHOWN_MAX) {
163
- return name;
164
- }
165
- let cut = SHOWN_MAX - 3;
166
- const code = name.charCodeAt(cut - 1);
167
- if (code >= 55296 && code <= 56319) {
168
- cut -= 1;
169
- }
170
- return `${name.slice(0, cut)}...`;
171
- }
172
- var K = new Uint32Array([
173
- 1116352408,
174
- 1899447441,
175
- 3049323471,
176
- 3921009573,
177
- 961987163,
178
- 1508970993,
179
- 2453635748,
180
- 2870763221,
181
- 3624381080,
182
- 310598401,
183
- 607225278,
184
- 1426881987,
185
- 1925078388,
186
- 2162078206,
187
- 2614888103,
188
- 3248222580,
189
- 3835390401,
190
- 4022224774,
191
- 264347078,
192
- 604807628,
193
- 770255983,
194
- 1249150122,
195
- 1555081692,
196
- 1996064986,
197
- 2554220882,
198
- 2821834349,
199
- 2952996808,
200
- 3210313671,
201
- 3336571891,
202
- 3584528711,
203
- 113926993,
204
- 338241895,
205
- 666307205,
206
- 773529912,
207
- 1294757372,
208
- 1396182291,
209
- 1695183700,
210
- 1986661051,
211
- 2177026350,
212
- 2456956037,
213
- 2730485921,
214
- 2820302411,
215
- 3259730800,
216
- 3345764771,
217
- 3516065817,
218
- 3600352804,
219
- 4094571909,
220
- 275423344,
221
- 430227734,
222
- 506948616,
223
- 659060556,
224
- 883997877,
225
- 958139571,
226
- 1322822218,
227
- 1537002063,
228
- 1747873779,
229
- 1955562222,
230
- 2024104815,
231
- 2227730452,
232
- 2361852424,
233
- 2428436474,
234
- 2756734187,
235
- 3204031479,
236
- 3329325298
237
- ]);
238
- function sha256Bytes(bytes) {
239
- const bits = bytes.length * 8;
240
- const padded = new Uint8Array(Math.ceil((bytes.length + 9) / 64) * 64);
241
- padded.set(bytes);
242
- padded[bytes.length] = 128;
243
- const view = new DataView(padded.buffer);
244
- view.setUint32(padded.length - 8, Math.floor(bits / 2 ** 32));
245
- view.setUint32(padded.length - 4, bits >>> 0);
246
- const h = new Uint32Array([1779033703, 3144134277, 1013904242, 2773480762, 1359893119, 2600822924, 528734635, 1541459225]);
247
- const w = new Uint32Array(64);
248
- const rotr = (x, n) => x >>> n | x << 32 - n;
249
- for (let at = 0; at < padded.length; at += 64) {
250
- for (let i = 0; i < 16; i++) {
251
- w[i] = view.getUint32(at + i * 4);
252
- }
253
- for (let i = 16; i < 64; i++) {
254
- const s0 = rotr(w[i - 15], 7) ^ rotr(w[i - 15], 18) ^ w[i - 15] >>> 3;
255
- const s1 = rotr(w[i - 2], 17) ^ rotr(w[i - 2], 19) ^ w[i - 2] >>> 10;
256
- w[i] = w[i - 16] + s0 + w[i - 7] + s1 >>> 0;
257
- }
258
- let [a, b, c, d, e, f, g, hh] = h;
259
- for (let i = 0; i < 64; i++) {
260
- const t1 = hh + (rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25)) + (e & f ^ ~e & g) + K[i] + w[i] >>> 0;
261
- const t2 = (rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22)) + (a & b ^ a & c ^ b & c) >>> 0;
262
- hh = g;
263
- g = f;
264
- f = e;
265
- e = d + t1 >>> 0;
266
- d = c;
267
- c = b;
268
- b = a;
269
- a = t1 + t2 >>> 0;
270
- }
271
- h[0] += a;
272
- h[1] += b;
273
- h[2] += c;
274
- h[3] += d;
275
- h[4] += e;
276
- h[5] += f;
277
- h[6] += g;
278
- h[7] += hh;
279
- }
280
- const out = new Uint8Array(32);
281
- const outView = new DataView(out.buffer);
282
- h.forEach((v, i) => outView.setUint32(i * 4, v));
283
- return out;
284
- }
285
- async function sha256Hex(text, options = {}) {
286
- const bytes = new TextEncoder().encode(text);
287
- const subtle = options.subtle !== void 0 ? options.subtle : globalThis.crypto?.subtle;
288
- let digest;
289
- try {
290
- digest = subtle ? new Uint8Array(await subtle.digest("SHA-256", bytes)) : sha256Bytes(bytes);
291
- } catch {
292
- digest = sha256Bytes(bytes);
293
- }
294
- return [...digest].map((b) => b.toString(16).padStart(2, "0")).join("");
295
- }
296
- async function sourceIdOf(name, columns, options) {
297
- const hex = await sha256Hex([name, ...columns].join("\0"), options);
298
- return `${shownName(name)}#${hex.slice(0, 16)}`;
299
- }
300
-
301
163
  // src/import-ui.jsx
302
164
  var PREVIEW_ROWS = 8;
303
165
  var PREVIEW_COLUMNS = 60;
@@ -360,11 +222,6 @@ function SourceLine({ labels, source }) {
360
222
  const t = importLabels(labels);
361
223
  return /* @__PURE__ */ React.createElement("span", { className: "pk-row-label pk-source", "data-testid": "source-line" }, /* @__PURE__ */ React.createElement(Icon, { name: "file", size: 14 }), fill(source.sheet ? t.sourceSheet : t.sourceLine, { name: source.name, sheet: source.sheet ?? "" }));
362
224
  }
363
- function readerMessage(error, name) {
364
- const text = messageOf(error);
365
- const prefix = `"${name}": `;
366
- return text.startsWith(prefix) ? text.slice(prefix.length) : text;
367
- }
368
225
  function cellText(value, type, t, locale) {
369
226
  if (value === null || value === void 0) {
370
227
  return "";
@@ -385,15 +242,15 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
385
242
  const file = job.file;
386
243
  const name = useMemo(() => fileName(file, {}), [file]);
387
244
  const [sheet, setSheet] = useState(
388
- /** @type {number | undefined} */
389
- void 0
245
+ /** @type {number | string | undefined} */
246
+ job.sheet
390
247
  );
391
248
  const [sheets, setSheets] = useState(
392
249
  /** @type {import("pivotkit-core/import").SheetInfo[]} */
393
250
  []
394
251
  );
395
252
  const [read, setRead] = useState(
396
- /** @type {{ table: import("pivotkit-core/import").ImportTable, sheet: number | undefined } | null} */
253
+ /** @type {{ table: import("pivotkit-core/import").ImportTable, sheet: number | string | undefined } | null} */
397
254
  null
398
255
  );
399
256
  const [types, setTypes] = useState(
@@ -410,14 +267,14 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
410
267
  );
411
268
  const [busy, setBusy] = useState(false);
412
269
  const [failed, setFailed] = useState(
413
- /** @type {number | undefined | null} */
270
+ /** @type {number | string | undefined | null} */
414
271
  null
415
272
  );
416
273
  const current = read && read.sheet === sheet ? read : null;
417
274
  const reading = !current && failed !== sheet;
418
- const latest = useRef({ onClose, announce, t, name, plugins, worker, locale, limits });
275
+ const latest = useRef({ onClose, announce, t, name, plugins, worker, locale, limits, where });
419
276
  useEffect(() => {
420
- latest.current = { onClose, announce, t, name, plugins, worker, locale, limits };
277
+ latest.current = { onClose, announce, t, name, plugins, worker, locale, limits, where };
421
278
  });
422
279
  useEffect(() => {
423
280
  const controller = new AbortController();
@@ -449,7 +306,7 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
449
306
  if (controller.signal.aborted) {
450
307
  return;
451
308
  }
452
- const text = fill(latest.current.t.failed, { name: latest.current.name, message: readerMessage(e, latest.current.name) });
309
+ const text = fill(latest.current.t.failed, { name: latest.current.name, message: errorText(e, latest.current.name, latest.current.t, latest.current.where) });
453
310
  if (sheet === void 0) {
454
311
  latest.current.announce(text, { tone: "error" });
455
312
  latest.current.onClose();
@@ -514,7 +371,7 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
514
371
  const n = shown?.notes.find((x) => x.code === "SHEET");
515
372
  return n && n.params?.sheet !== void 0 ? String(n.params.sheet) : null;
516
373
  })();
517
- 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;
518
375
  const apply = async () => {
519
376
  if (!shown || busy) {
520
377
  return;
@@ -532,17 +389,26 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
532
389
  source: { id, name: shownName(name) },
533
390
  file: { name, size: file.size, type: file.type },
534
391
  sheet: sheetName,
392
+ sheets: sheets.map((s) => s.name),
393
+ blob: file,
535
394
  rows: shown.rowCount,
536
395
  columns: shown.columns.map((c, i) => ({ name: c, type: shown.types[i] })),
537
396
  notes: shown.notes.map((n) => ({ code: n.code, params: { ...n.params }, message: n.message }))
538
397
  });
539
398
  } catch (e) {
540
399
  if (live.current) {
541
- setError(fill(t.failed, { name, message: readerMessage(e, name) }));
400
+ setError(fill(t.failed, { name, message: errorText(e, name, t, where) }));
542
401
  setBusy(false);
543
402
  }
544
403
  }
545
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
+ });
546
412
  if (!layer) {
547
413
  return null;
548
414
  }
@@ -642,7 +508,7 @@ function tell(ctx, detail) {
642
508
  }
643
509
  }
644
510
  function loadData(ctx, loaded) {
645
- 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 };
646
512
  const t = importLabels(ctx.labels);
647
513
  const told = tell(ctx, describe(ctx, data, "load", loaded.notes));
648
514
  if (told.refused) {
@@ -698,17 +564,46 @@ function sayError(api, text) {
698
564
  }
699
565
  }
700
566
  function startFiles(api, files) {
701
- const dismiss = api.dismiss;
702
- if (typeof dismiss === "function") {
703
- (shownErrors.get(dismiss) ?? []).forEach((id) => dismiss(id));
704
- shownErrors.delete(dismiss);
705
- }
567
+ closeErrors(api);
706
568
  if (files.length === 1) {
707
569
  api.setJob({ file: files[0], n: ++jobs });
708
570
  } else if (files.length > 1) {
709
571
  sayError(api, importLabels(api.labels).dropOne);
710
572
  }
711
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
+ }
712
607
  function pickFile(input) {
713
608
  if (input) {
714
609
  input.value = "";
@@ -743,10 +638,14 @@ function ImportLayer({ api, input }) {
743
638
  limits: api.limits,
744
639
  timeZone: api.timeZone,
745
640
  announce: (text, extra) => extra?.tone === "error" ? sayError(api, text) : api.announce(text, extra),
746
- onClose: () => api.setJob((j) => j === job ? null : j),
641
+ onClose: () => {
642
+ api.setJob((j) => j === job ? null : j);
643
+ job.done?.(false);
644
+ },
747
645
  onApply: (loaded) => {
748
- loadData(api, loaded);
646
+ const ok = loadData(api, loaded);
749
647
  api.setJob((j) => j === job ? null : j);
648
+ job.done?.(ok, !ok);
750
649
  }
751
650
  }
752
651
  ) : null);
@@ -762,7 +661,9 @@ export {
762
661
  DataMenuPanel,
763
662
  ImportLayer,
764
663
  SourceLine2 as SourceLine,
664
+ loadSheet,
765
665
  moveData,
666
+ openOnSheet,
766
667
  pickFile,
767
668
  restoreData,
768
669
  startFiles