pivotkit-react 0.4.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.
Files changed (48) hide show
  1. package/CHANGELOG.md +219 -1
  2. package/README.md +2 -2
  3. package/dist/chunks/{chunk-YITKWZ4L.js → chunk-2AT72SLA.js} +604 -505
  4. package/dist/chunks/{chunk-ZYEYZSYL.js → chunk-3E4NB5RZ.js} +30 -2
  5. package/dist/chunks/{chunk-6MDAL3IO.js → chunk-3WUGQPWV.js} +78 -6
  6. package/dist/chunks/{chunk-WB4GKWFQ.js → chunk-4RS72AAA.js} +26 -4
  7. package/dist/chunks/{chunk-EM23V5GH.js → chunk-E6M57YLL.js} +19 -8
  8. package/dist/chunks/{chunk-RWYHJRQO.js → chunk-JMRTIOX4.js} +17 -7
  9. package/dist/chunks/{chunk-XN55BQ4M.js → chunk-RIOSIYGC.js} +54 -7
  10. package/dist/chunks/{chunk-LEN5RPBM.js → chunk-U5Q5I2D5.js} +34 -5
  11. package/dist/chunks/report-run-BZBFOMPF.js +12 -0
  12. package/dist/chunks/{unused-texts-K3VFH65P.js → unused-texts-Y4R67XSN.js} +1 -1
  13. package/dist/chunks/{unused-texts-de-OW4TGIVX.js → unused-texts-de-6YVPTNVS.js} +1 -1
  14. package/dist/echarts.js +38 -156
  15. package/dist/import-ui.js +8 -12
  16. package/dist/index.js +97 -82
  17. package/dist/labels.js +6 -6
  18. package/dist/menu-texts-de.js +1 -1
  19. package/dist/menus.js +650 -245
  20. package/dist/styles.css +207 -93
  21. package/package.json +8 -4
  22. package/types/chart-decorate.d.ts +28 -4
  23. package/types/chart-types.d.ts +2 -4
  24. package/types/echarts.d.ts +1 -1
  25. package/types/export-run.d.ts +37 -3
  26. package/types/filter.d.ts +1 -1
  27. package/types/icons.d.ts +1 -0
  28. package/types/import-labels.d.ts +41 -0
  29. package/types/import-limits.d.ts +6 -0
  30. package/types/index.d.ts +25 -7
  31. package/types/labels.d.ts +198 -2
  32. package/types/light-tokens.d.ts +16 -0
  33. package/types/menu-labels.d.ts +37 -14
  34. package/types/menu-ops.d.ts +161 -40
  35. package/types/menu-topics.d.ts +7 -4
  36. package/types/names.d.ts +47 -19
  37. package/types/place.d.ts +24 -0
  38. package/types/print-frame.d.ts +24 -0
  39. package/types/report-run.d.ts +14 -0
  40. package/types/share-actions.d.ts +3 -3
  41. package/types/share.d.ts +13 -17
  42. package/types/theme.d.ts +2 -16
  43. package/types/tips.d.ts +5 -0
  44. package/types/toolbar-panels.d.ts +5 -4
  45. package/types/unused-texts.d.ts +13 -3
  46. package/types/use-export.d.ts +2 -2
  47. package/types/view-ops.d.ts +65 -6
  48. package/types/chart-layout.d.ts +0 -111
@@ -0,0 +1,12 @@
1
+ // src/report-run.js
2
+ import { use as register } from "echarts/core";
3
+ import { SVGRenderer } from "echarts/renderers";
4
+ import { LIGHT_TOKENS, SHAPE_TOKENS, SIZE_TOKENS, WEIGHT_TOKENS, render } from "pivotkit-report";
5
+ register([SVGRenderer]);
6
+ var REPORT_TOKENS = Object.freeze([...Object.keys(WEIGHT_TOKENS), ...Object.keys(SHAPE_TOKENS), ...Object.keys(LIGHT_TOKENS), "--pk-scale-mid"]);
7
+ var REPORT_LENGTHS = Object.freeze(Object.keys(SIZE_TOKENS));
8
+ export {
9
+ REPORT_LENGTHS,
10
+ REPORT_TOKENS,
11
+ render
12
+ };
@@ -2,7 +2,7 @@ import {
2
2
  en,
3
3
  unusedItem,
4
4
  unusedItems
5
- } from "./chunk-EM23V5GH.js";
5
+ } from "./chunk-E6M57YLL.js";
6
6
  export {
7
7
  en,
8
8
  unusedItem,
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  de
3
- } from "./chunk-RWYHJRQO.js";
3
+ } from "./chunk-JMRTIOX4.js";
4
4
  export {
5
5
  de
6
6
  };
package/dist/echarts.js CHANGED
@@ -116,6 +116,9 @@ function mergeChartOptions(base, over) {
116
116
  return over;
117
117
  }
118
118
 
119
+ // src/chart-decorate.js
120
+ import { decorateOption } from "pivotkit-core/chart";
121
+
119
122
  // src/chart-tooltip.js
120
123
  function tooltipContent(params, { valueFormatter = (v) => String(v ?? ""), xNames = [], yNames = [], categoryNames = [] } = {}) {
121
124
  const color = (p) => typeof p.color === "string" ? p.color : null;
@@ -146,7 +149,7 @@ function tooltipFormatter(doc, options) {
146
149
  if (title) {
147
150
  const head = doc.createElement("div");
148
151
  head.textContent = title;
149
- head.style.fontWeight = "600";
152
+ head.style.fontWeight = "var(--pk-weight-strong)";
150
153
  head.style.marginBottom = "2px";
151
154
  box.append(head);
152
155
  }
@@ -169,7 +172,7 @@ function tooltipFormatter(doc, options) {
169
172
  name.style.flex = "1";
170
173
  const value = doc.createElement("span");
171
174
  value.textContent = line.value;
172
- value.style.fontWeight = "600";
175
+ value.style.fontWeight = "var(--pk-weight-strong)";
173
176
  value.style.marginLeft = "12px";
174
177
  row.append(marker, name, value);
175
178
  box.append(row);
@@ -178,170 +181,49 @@ function tooltipFormatter(doc, options) {
178
181
  };
179
182
  }
180
183
 
181
- // src/chart-layout.js
182
- function pieLabelRoom(height) {
183
- return Math.round(Math.min(24, Math.max(0, height) * 0.05));
184
- }
185
- var RIGHT_LEGEND_MIN_WIDTH = 480;
186
- var BOTTOM_LEGEND_ROOM = 32;
187
- var labelWidth = (text) => String(text).length * 7;
188
- function ringLabelsFit(radius, box, texts) {
189
- const half = Math.max(0, Math.min(box.width, box.height)) / 2;
190
- const px = (r) => typeof r === "number" ? r : /%$/.test(String(r)) ? parseFloat(String(r)) / 100 * half : parseFloat(String(r)) || 0;
191
- const inner = px(radius[0]);
192
- if (inner <= 0) {
193
- return true;
194
- }
195
- const ring = px(radius[1]) - inner;
196
- return texts.every((t) => labelWidth(t) + 6 <= ring);
197
- }
198
- var SLANTED_LABEL_WIDTH = 120;
199
- var HEATMAP_FRAME = { x: 80, y: 120 };
200
- var LABEL_LINE = 16;
201
- var LABEL_PAD = 4;
202
- function columnLabelLayout(names, width, fontSize = 12) {
203
- if (names.length === 0) {
204
- return { rotate: 0 };
205
- }
206
- const slot = Math.max(0, width - HEATMAP_FRAME.x) / names.length;
207
- const longest = Math.max(...names.map((n) => String(n).length)) * fontSize * 0.55;
208
- return longest <= slot ? { rotate: 0 } : { rotate: 45, width: SLANTED_LABEL_WIDTH, overflow: "truncate" };
209
- }
210
- function heatmapCellLabels(columns, rows, width, height, texts, fontSize = 12) {
211
- const w = Math.max(0, width - HEATMAP_FRAME.x) / Math.max(1, columns);
212
- const h = Math.max(0, height - HEATMAP_FRAME.y) / Math.max(1, rows);
213
- const longest = texts.reduce((m, t) => Math.max(m, String(t).length), 0) * fontSize * 0.55;
214
- return w >= longest + 2 * LABEL_PAD && h >= LABEL_LINE;
215
- }
216
- function rowLabelInterval(rows, height) {
217
- const h = Math.max(0, height - HEATMAP_FRAME.y) / Math.max(1, rows);
218
- return h >= LABEL_LINE ? 0 : Math.ceil(LABEL_LINE / Math.max(h, 0.1)) - 1;
219
- }
220
- var CATEGORY_LABEL_WIDTH = 120;
221
- var AXIS_FRAME = { x: 80, y: 60 };
222
- function categoryLabelLayout(names, { width, height, horizontal = false, mode = "auto", fontSize = 12 }) {
223
- const n = Math.max(1, names.length);
224
- const cut = { width: CATEGORY_LABEL_WIDTH, overflow: (
225
- /** @type {const} */
226
- "truncate"
227
- ) };
228
- const every = (slot2, need) => Math.max(1, Math.ceil(need / Math.max(slot2, 0.1)));
229
- const result = (rotate, step) => ({ rotate, interval: step - 1, every: step, ...cut });
230
- if (horizontal) {
231
- const slot2 = Math.max(0, height - AXIS_FRAME.y) / n;
232
- return result(0, mode === "all" ? 1 : every(slot2, fontSize + 1));
233
- }
234
- const slot = Math.max(0, width - AXIS_FRAME.x) / n;
235
- const longest = Math.min(CATEGORY_LABEL_WIDTH, Math.max(0, ...names.map((t) => String(t).length)) * fontSize * 0.55);
236
- if (mode === "nth") {
237
- return result(0, every(slot, longest + 8));
238
- }
239
- if (longest + 8 <= slot) {
240
- return result(0, 1);
241
- }
242
- return result(45, mode === "all" ? 1 : every(slot, LABEL_LINE));
243
- }
244
- var GROUP_LABEL_ROOM = Object.freeze({ along: 56, across: 28, width: 420, height: 260 });
245
- function groupLabelsFit(count, groupSize, { width, height, horizontal = false }) {
246
- if (width < GROUP_LABEL_ROOM.width || height < GROUP_LABEL_ROOM.height) {
247
- return false;
248
- }
249
- const n = Math.max(1, count);
250
- const slot = horizontal ? Math.max(0, height - AXIS_FRAME.y) / n : Math.max(0, width - AXIS_FRAME.x) / n;
251
- return slot * Math.max(1, groupSize) >= (horizontal ? GROUP_LABEL_ROOM.across : GROUP_LABEL_ROOM.along);
252
- }
253
-
254
184
  // src/chart-decorate.js
255
- var without = (obj, keys) => Object.fromEntries(Object.entries(obj).filter(([k]) => !keys.includes(k)));
256
185
  function decorate(option, style, height = 480, doc = void 0, width = 800, extra = {}) {
257
- const first = (a) => Array.isArray(a) ? a[0] : a;
258
- const v = (name) => style.getPropertyValue(name).trim();
259
- const rightLegend = option.legend?.orient === "vertical" && typeof option.legend.right === "number";
260
- const legendDown = rightLegend && width < RIGHT_LEGEND_MIN_WIDTH;
261
- if (legendDown) {
262
- option = {
263
- ...option,
264
- legend: { ...without(option.legend, ["orient", "right", "top"]), bottom: 0 },
265
- series: (option.series || []).map((s) => s.type === "pie" ? { ...without(s, ["right"]), bottom: (typeof s.bottom === "number" ? s.bottom : 0) + BOTTOM_LEGEND_ROOM } : s),
266
- ...option.grid ? { grid: { ...without(option.grid, ["right"]), bottom: BOTTOM_LEGEND_ROOM + 8 } } : {}
267
- };
186
+ return decorateOption(option, style, { height, width, ...extra, tooltipFormatter: doc ? (context) => tooltipFormatter(doc, context) : void 0 });
187
+ }
188
+ var LENGTH_TOKENS = Object.freeze(["--pk-chart-title-size", "--pk-chart-text-size", "--pk-radius-chart"]);
189
+ function tokenLengths(root, names = LENGTH_TOKENS) {
190
+ const view = root.ownerDocument.defaultView;
191
+ const style = view?.getComputedStyle(root);
192
+ const lengthy = (value) => Boolean(value) && (typeof CSS === "undefined" || CSS.supports("margin-left", value));
193
+ const set = style ? names.filter((name) => lengthy(style.getPropertyValue(name).trim())) : [];
194
+ if (!view || !set.length) {
195
+ return {};
268
196
  }
269
- const surface = v("--pk-surface") || void 0;
270
- const tooltip = {
271
- ...option.tooltip,
272
- backgroundColor: v("--pk-surface-raised") || surface,
273
- borderColor: v("--pk-border") || void 0,
274
- textStyle: { color: v("--pk-text") || void 0, fontFamily: style.getPropertyValue("font-family") || void 0 },
275
- extraCssText: `box-shadow: ${v("--pk-shadow") || "none"}; border-radius: 8px;`,
276
- ...doc ? { formatter: tooltipFormatter(doc, { valueFormatter: option.tooltip?.valueFormatter, xNames: first(option.xAxis)?.data, yNames: first(option.yAxis)?.data, categoryNames: extra.categoryNames }) } : {}
277
- };
278
- const series = (option.series || []).map((s) => {
279
- if (s.type === "bar") {
280
- const horizontal = first(option.yAxis)?.type === "category";
281
- const r = horizontal ? [0, 4, 4, 0] : [4, 4, 0, 0];
282
- return { ...s, barMaxWidth: 48, itemStyle: { borderRadius: s.stack ? 0 : r, borderColor: s.stack ? surface : void 0, borderWidth: s.stack ? 1 : 0 }, emphasis: { focus: "series" } };
283
- }
284
- if (s.type === "line") {
285
- return { ...s, lineStyle: { width: 2 }, symbolSize: 7, smooth: Boolean(s.smooth), areaStyle: s.areaStyle ? { opacity: 0.18 } : void 0, emphasis: { focus: "series" } };
286
- }
287
- if (s.type === "pie") {
288
- const room = pieLabelRoom(height);
289
- const top = (typeof s.top === "number" ? s.top : 0) + room;
290
- const bottom = (typeof s.bottom === "number" ? s.bottom : 0) + room;
291
- let label = s.label;
292
- let line = s.labelLine;
293
- if (label?.position === "inside" && label.show !== false && Array.isArray(s.radius)) {
294
- const box = { width: width - (typeof s.right === "number" ? s.right : 0), height: height - top - bottom };
295
- const total = (s.data || []).reduce((sum, d) => sum + (typeof d.value === "number" ? d.value : 0), 0);
296
- const texts = typeof label.formatter === "function" ? (s.data || []).map((d) => label.formatter({ name: d.name, value: d.value, percent: total ? d.value / total * 100 : 0 })) : [];
297
- if (!ringLabelsFit(s.radius, box, texts)) {
298
- label = without(label, ["position"]);
299
- line = { show: true };
300
- }
301
- }
302
- return { ...s, top, bottom, labelLine: line, itemStyle: { borderColor: surface, borderWidth: 2, borderRadius: 4 }, label: { ...label, color: label?.position === "inside" ? void 0 : v("--pk-text") || void 0 } };
303
- }
304
- if (s.type === "heatmap") {
305
- const texts = typeof s.label?.formatter === "function" ? s.data.map((d) => s.label.formatter({ value: d })) : [];
306
- const fits = heatmapCellLabels(option.xAxis?.data?.length ?? 1, option.yAxis?.data?.length ?? 1, width, height, texts);
307
- return { ...s, itemStyle: { borderColor: surface, borderWidth: 2, borderRadius: 3 }, label: { ...s.label, show: Boolean(s.label?.show) && fits, color: v("--pk-text") || void 0 } };
308
- }
309
- return s;
310
- });
311
- const legend = option.legend ? { ...option.legend, icon: "roundRect", itemWidth: 12, itemHeight: 12, textStyle: { ...option.legend.textStyle, color: v("--pk-text") || void 0 } } : void 0;
312
- const grid = option.grid ? { left: 12, right: 24, bottom: option.visualMap ? 64 : 12, containLabel: true, ...option.grid } : void 0;
313
- const heatmap = series.some((s) => s.type === "heatmap") && option.xAxis?.axisLabel;
314
- const xAxis = heatmap ? { ...option.xAxis, axisLabel: { ...option.xAxis.axisLabel, ...columnLabelLayout(option.xAxis.data ?? [], width) } } : option.xAxis;
315
- const yAxis = heatmap && option.yAxis ? { ...option.yAxis, axisLabel: { ...option.yAxis.axisLabel, interval: rowLabelInterval(option.yAxis.data?.length ?? 0, height) } } : option.yAxis;
316
- const title = option.title ? { title: { ...option.title, textStyle: { ...option.title.textStyle, width: Math.max(40, width - 32), overflow: "truncate" } } } : {};
317
- let axes = { xAxis, yAxis };
318
- let axisEvery = 1;
319
- const along = !heatmap && series.some((s) => s.type === "bar" || s.type === "line") ? first(option.yAxis)?.type === "category" ? "yAxis" : first(option.xAxis)?.type === "category" ? "xAxis" : null : null;
320
- if (along) {
321
- let list = Array.isArray(axes[along]) ? axes[along] : [axes[along]];
322
- const group = list[1]?.groups ? list[1] : null;
323
- if (group && group.groupsAuto && !groupLabelsFit(list[0].data?.length ?? 0, group.groupSize ?? 1, { width, height, horizontal: along === "yAxis" })) {
324
- list = [{ ...list[0], data: extra.categoryNames ?? list[0].data }];
325
- }
326
- const names = list[0].data ?? [];
327
- const layout = categoryLabelLayout(names, { width, height, horizontal: along === "yAxis", mode: extra.axisLabels });
328
- axisEvery = layout.every;
329
- const longest = Math.min(CATEGORY_LABEL_WIDTH, Math.max(0, ...names.map((t) => String(t).length)) * 12 * 0.55);
330
- const offset = along === "yAxis" ? Math.round(longest) + 16 : layout.rotate ? Math.round(longest * 0.71) + 14 : 24;
331
- const main = { ...list[0], axisLabel: { ...list[0].axisLabel, rotate: layout.rotate, interval: layout.interval, width: layout.width, overflow: layout.overflow } };
332
- const slot = (along === "yAxis" ? Math.max(0, height - 60) : Math.max(0, width - 80)) / Math.max(1, names.length);
333
- const groupWidth = along === "yAxis" ? CATEGORY_LABEL_WIDTH : Math.max(24, Math.round(slot * (list[1]?.groupSize ?? 1)) - 8);
334
- const rest = list.slice(1).map((a) => a.groups ? { ...a, offset, axisTick: { ...a.axisTick, length: offset }, axisLabel: { ...a.axisLabel, width: groupWidth, overflow: "truncate" } } : a);
335
- axes = { ...axes, [along]: rest.length ? [main, ...rest] : main };
197
+ const probe = root.ownerDocument.createElement("span");
198
+ probe.setAttribute("aria-hidden", "true");
199
+ probe.style.setProperty("position", "absolute");
200
+ probe.style.setProperty("visibility", "hidden");
201
+ root.append(probe);
202
+ try {
203
+ return Object.fromEntries(
204
+ set.map((name) => {
205
+ probe.style.setProperty("margin-left", `var(${name})`);
206
+ return [name, view.getComputedStyle(probe).marginLeft];
207
+ }).filter(([, value]) => /px$/.test(value))
208
+ );
209
+ } finally {
210
+ probe.remove();
336
211
  }
337
- return { ...option, ...title, tooltip, series, ...axes.xAxis ? { xAxis: axes.xAxis } : {}, ...axes.yAxis ? { yAxis: axes.yAxis } : {}, ...legend ? { legend } : {}, ...grid ? { grid } : {}, animationDuration: style.getPropertyValue("--pk-duration").trim() === "0ms" ? 0 : 400, axisEvery };
212
+ }
213
+ function chartStyle(root) {
214
+ const style = getComputedStyle(root);
215
+ const lengths = tokenLengths(root);
216
+ return { getPropertyValue: (name) => lengths[name] ?? style.getPropertyValue(name) };
338
217
  }
339
218
 
340
219
  // src/echarts.js
341
220
  register([BarChart, LineChart, PieChart, HeatmapChart, GridComponent, TooltipComponent, LegendComponent, TitleComponent, VisualMapComponent, CanvasRenderer]);
342
221
  export {
222
+ LENGTH_TOKENS,
223
+ chartStyle,
343
224
  cleanChartOptions,
344
225
  decorate,
345
226
  init,
346
- mergeChartOptions
227
+ mergeChartOptions,
228
+ tokenLengths
347
229
  };
package/dist/import-ui.js CHANGED
@@ -7,16 +7,17 @@ import {
7
7
  useFormName,
8
8
  useModal,
9
9
  useTopLayer
10
- } from "./chunks/chunk-XN55BQ4M.js";
10
+ } from "./chunks/chunk-RIOSIYGC.js";
11
11
  import {
12
+ errorText,
12
13
  importLabels,
13
14
  noteText
14
- } from "./chunks/chunk-ZYEYZSYL.js";
15
+ } from "./chunks/chunk-3E4NB5RZ.js";
15
16
  import {
16
17
  fill,
17
18
  messageOf,
18
19
  plural
19
- } from "./chunks/chunk-6MDAL3IO.js";
20
+ } from "./chunks/chunk-3WUGQPWV.js";
20
21
 
21
22
  // src/import-host.jsx
22
23
  import React2 from "react";
@@ -360,11 +361,6 @@ function SourceLine({ labels, source }) {
360
361
  const t = importLabels(labels);
361
362
  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
363
  }
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
364
  function cellText(value, type, t, locale) {
369
365
  if (value === null || value === void 0) {
370
366
  return "";
@@ -415,9 +411,9 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
415
411
  );
416
412
  const current = read && read.sheet === sheet ? read : null;
417
413
  const reading = !current && failed !== sheet;
418
- const latest = useRef({ onClose, announce, t, name, plugins, worker, locale, limits });
414
+ const latest = useRef({ onClose, announce, t, name, plugins, worker, locale, limits, where });
419
415
  useEffect(() => {
420
- latest.current = { onClose, announce, t, name, plugins, worker, locale, limits };
416
+ latest.current = { onClose, announce, t, name, plugins, worker, locale, limits, where };
421
417
  });
422
418
  useEffect(() => {
423
419
  const controller = new AbortController();
@@ -449,7 +445,7 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
449
445
  if (controller.signal.aborted) {
450
446
  return;
451
447
  }
452
- const text = fill(latest.current.t.failed, { name: latest.current.name, message: readerMessage(e, latest.current.name) });
448
+ const text = fill(latest.current.t.failed, { name: latest.current.name, message: errorText(e, latest.current.name, latest.current.t, latest.current.where) });
453
449
  if (sheet === void 0) {
454
450
  latest.current.announce(text, { tone: "error" });
455
451
  latest.current.onClose();
@@ -538,7 +534,7 @@ function ImportDialog({ job, labels, locale, plugins, worker, limits, timeZone,
538
534
  });
539
535
  } catch (e) {
540
536
  if (live.current) {
541
- setError(fill(t.failed, { name, message: readerMessage(e, name) }));
537
+ setError(fill(t.failed, { name, message: errorText(e, name, t, where) }));
542
538
  setBusy(false);
543
539
  }
544
540
  }