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,14 @@
1
+ import { render } from "pivotkit-report";
2
+ export { render };
3
+ /**
4
+ * The tokens of an HTML report and an SVG, as the report's light theme resolves them (export-run.js):
5
+ * pivotkit-report's colours, font weights and corners, and a host's middle colour of a colour scale.
6
+ * The chart's lengths in px come from the chart's module (LENGTH_TOKENS).
7
+ */
8
+ export declare const REPORT_TOKENS: readonly string[];
9
+ /**
10
+ * The HTML report's font sizes, in px as the report resolves them (export-run.js): its text and
11
+ * secondary text, so the file's text is the size the screen's is, and a host's title and print sizes
12
+ * where it sets them (pivotkit-report's own defaults else).
13
+ */
14
+ export declare const REPORT_LENGTHS: readonly string[];
@@ -27,9 +27,9 @@ export type ShareContext = {
27
27
  */
28
28
  shareLink: boolean | string | undefined;
29
29
  /**
30
- * the link's parameter in the fragment
30
+ * the report's key in the fragment (its storageKey): "pivot-<key>", else "pivot"
31
31
  */
32
- param: string;
32
+ linkKey: string | undefined;
33
33
  /**
34
34
  * the report's root (copies and downloads start from its document)
35
35
  */
@@ -64,7 +64,7 @@ export type ShareContext = {
64
64
  * @property {string | null | undefined} schemaUrl the `$schema` of the view files (the prop)
65
65
  * @property {import("pivotkit-core").Encoded} encoded
66
66
  * @property {boolean | string | undefined} shareLink the prop: the base of the link
67
- * @property {string} param the link's parameter in the fragment
67
+ * @property {string | undefined} linkKey the report's key in the fragment (its storageKey): "pivot-<key>", else "pivot"
68
68
  * @property {{ current: HTMLElement | null }} root the report's root (copies and downloads start from its document)
69
69
  * @property {string | undefined} fileName the host's file name of exports
70
70
  * @property {((file: any) => unknown) | undefined} onExport
package/types/share.d.ts CHANGED
@@ -3,28 +3,21 @@ export declare function loadLink(): Promise<typeof import("pivotkit-core/link")>
3
3
  /** The link module when it is loaded already, else null (see loadLink). */
4
4
  export declare const linkNow: () => typeof import("pivotkit-core/link") | null;
5
5
  /**
6
- * The name of a report's view in the URL fragment: "pivot", or "pivot-<storageKey>" so several reports
7
- * on one page each have their own.
8
- * @param {string | undefined} storageKey
9
- */
10
- export declare function linkParam(storageKey: string | undefined): string;
11
- /**
12
- * The encoded view of a fragment ("#pivot=1.abc&pivot-sales=1.def") under a name, or null. The
13
- * fragment is read as it is, not as form data, so a hash route next to it ("#/reports/a?tab=2&pivot=...")
14
- * does not matter.
6
+ * The link text of a report's entry in a fragment ("#pivot=1.abc&pivot-sales=1.def"), or null:
7
+ * pivotkit-core's linkFragment. `key` is the report's storageKey: its entry is "pivot-<key>", else
8
+ * "pivot". The fragment is read as it is, so a hash route next to it does not matter.
15
9
  * @param {string} hash location.hash, with or without "#"
16
- * @param {string} param
10
+ * @param {string | undefined} key
17
11
  */
18
- export declare function readLinkParam(hash: string, param: string): any;
12
+ export declare const readLinkParam: (hash: string, key: string | undefined) => string | null;
19
13
  /**
20
- * A URL with the encoded view under `param` in its fragment. Only that entry is added, replaced or
21
- * removed; the rest of the fragment (another report's entry, a hash route such as "#/reports/a?tab=2",
22
- * an anchor) stays byte for byte.
14
+ * A URL with the report's link text in its fragment (pivotkit-core's withLinkFragment): only that
15
+ * entry is added, replaced or removed (null), the rest of the fragment stays byte for byte.
23
16
  * @param {string} url
24
- * @param {string} param
25
- * @param {string | null} encoded null removes the entry
17
+ * @param {string | undefined} key the report's storageKey
18
+ * @param {string | null} encoded
26
19
  */
27
- export declare function withLinkParam(url: string, param: string, encoded: string | null): string;
20
+ export declare const withLinkParam: (url: string, key: string | undefined, encoded: string | null) => string;
28
21
  /**
29
22
  * The address a shared link points to: the host's base URL as given, or for `true` the page's own
30
23
  * address without its query (it may hold tokens or ids the host did not mean to share) and with its
@@ -84,6 +77,9 @@ export declare function viewFromText(text: string, encoded: import("pivotkit-cor
84
77
  /**
85
78
  * A view from a parsed object (a link's) or a text, read as a view file and normalized against the
86
79
  * data; `file.compatible` says how it fits (the same source by `options.sourceId`, its fields there).
80
+ * Every view that comes in this way (a link, a file, pasted JSON, the tab's stored view) comes from
81
+ * outside the host's code: it is normalized with pivotkit-core's outsideLimits() over the host's
82
+ * `options.limits` (at most 50 filters, or the host's lower value).
87
83
  * @param {unknown} input
88
84
  * @param {import("pivotkit-core").Encoded} encoded
89
85
  * @param {{ limits?: object, sourceId?: string }} [options]
package/types/theme.d.ts CHANGED
@@ -6,19 +6,5 @@
6
6
  * @returns {"light" | "dark"}
7
7
  */
8
8
  export declare function resolveTheme(wanted: "auto" | "light" | "dark" | undefined, htmlTheme: string | null | undefined, prefersDark: boolean): "light" | "dark";
9
- /** Number of categorical chart colours (--pk-chart-1 ... --pk-chart-8). */
10
- export declare const CHART_COLORS = 8;
11
- /**
12
- * The ECharts theme of pivotkit-core's toEChartsOption from the computed style of the report's root.
13
- * @param {{ getPropertyValue(name: string): string }} style getComputedStyle(root)
14
- */
15
- export declare function chartThemeFrom(style: {
16
- getPropertyValue(name: string): string;
17
- }): {
18
- colors: any[];
19
- textColor: string | undefined;
20
- axisColor: string | undefined;
21
- gridColor: string | undefined;
22
- fontFamily: string | undefined;
23
- backgroundColor: string;
24
- };
9
+ /** The chart's colours from the --pk-* tokens: pivotkit-core's, the same for an SVG and a printed report. */
10
+ export { CHART_COLORS, chartThemeFrom } from "pivotkit-core";
package/types/tips.d.ts CHANGED
@@ -45,6 +45,11 @@ export type TipContext = {
45
45
  * columns of the innermost column field (1 without column fields)
46
46
  */
47
47
  colLeaves: number;
48
+ /**
49
+ * a column group with more than one child is expanded, so a
50
+ * column subtotal shows when column subtotals are on (core's layout.js draws none for one child)
51
+ */
52
+ colSubtotalShown: boolean;
48
53
  /**
49
54
  * source rows left after the filters
50
55
  */
@@ -84,10 +84,11 @@ export declare function ExportOption({ icon, text, info, onSelect, testId, disab
84
84
  reason?: string;
85
85
  }): React.JSX.Element;
86
86
  /**
87
- * The Export menu: the table as a file (Excel, CSV), the chart as an image, and the table on the
88
- * clipboard (as shown, or its data as JSON). The export module loads when the menu opens, so a copy
89
- * happens right in the click.
90
- * An empty report (no field placed) has nothing to export: every entry is off, and says so.
87
+ * The Export menu: the table as a file (Excel, CSV), the chart as an image (PNG, SVG), an HTML report,
88
+ * printing (or saving as PDF from the print dialog), and the table on the clipboard (as shown, or its
89
+ * data as JSON). The export module loads when the menu opens, so a copy happens right in the click.
90
+ * An empty report (no field placed) has nothing to export: every entry is off, and says so; the chart's
91
+ * images are off while the table is shown.
91
92
  * @param {{ labels: import("./labels.js").UiLabels, onExport: (kind: string) => void, chartReady: boolean, display: string, empty?: boolean, prepare: () => void, close: () => void }} props
92
93
  */
93
94
  export declare function ExportPanel({ labels, onExport, chartReady, display, empty, prepare, close }: {
@@ -45,6 +45,8 @@ export declare const en: {
45
45
  tooMany: string;
46
46
  tooManyItems: string;
47
47
  itemType: string;
48
+ itemTooLong: string;
49
+ itemCase: string;
48
50
  unknownField: string;
49
51
  unknownFieldHere: string;
50
52
  placedTwice: string;
@@ -70,15 +72,22 @@ export declare const en: {
70
72
  dataBarColor: string;
71
73
  unknownFilterType: string;
72
74
  filterNoItems: string;
73
- filterLabelOp: string;
75
+ filterFieldType: string;
76
+ filterTextOp: string;
77
+ filterMatch: string;
78
+ filterNot: string;
79
+ filterBlanks: string;
80
+ blanksUnspecified: string;
81
+ filterEmpty: string;
74
82
  filterText: string;
75
83
  filterNotNumber: string;
84
+ filterTies: string;
85
+ filterPrecision: string;
76
86
  filterCount: string;
77
87
  filterValue: string;
78
88
  filterValue2: string;
79
- filterCompareField: string;
80
89
  filterCompareValue: string;
81
- filterRelativeField: string;
90
+ filterRelativeDirection: string;
82
91
  filterRelativeUnit: string;
83
92
  filterRelativeCount: string;
84
93
  filterRelativeAnchor: string;
@@ -91,6 +100,7 @@ export declare const en: {
91
100
  unknownLocale: string;
92
101
  unknownTimeZone: string;
93
102
  timeZoneMismatch: string;
103
+ tooManyIssues: string;
94
104
  };
95
105
  other: string;
96
106
  };
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * @param {import("./export-run.js").ExportContext} context
3
- * @returns {(kind: "xlsx" | "csv" | "png" | "copy-table" | "copy-json") => Promise<void>}
3
+ * @returns {(kind: "xlsx" | "csv" | "png" | "html" | "svg" | "print" | "copy-table" | "copy-json") => Promise<void>}
4
4
  */
5
- export declare function useExport(context: import("./export-run.js").ExportContext): (kind: "xlsx" | "csv" | "png" | "copy-table" | "copy-json") => Promise<void>;
5
+ export declare function useExport(context: import("./export-run.js").ExportContext): (kind: "xlsx" | "csv" | "png" | "html" | "svg" | "print" | "copy-table" | "copy-json") => Promise<void>;
6
6
  /** Starts loading the export module when a menu that copies opens: a copy right in the click is allowed everywhere. */
7
7
  export declare const prepareExporters: () => undefined;
@@ -1,8 +1,70 @@
1
+ import { swapAxes } from "pivotkit-core";
1
2
  export type Zone = "rows" | "cols" | "values" | "filters";
2
3
  /** @typedef {"rows" | "cols" | "values" | "filters"} Zone */
3
4
  export declare const ZONES: readonly Zone[];
4
5
  export declare const clone: (view: any) => any;
6
+ /** The operators of the menus' rules: on an item's name, on an item or its total. */
7
+ export declare const RULE_OPS: Readonly<{
8
+ text: readonly string[];
9
+ compare: readonly string[];
10
+ }>;
11
+ /**
12
+ * A filter's operator as the menus name it: its own, or with `not` its negation ("!=", "notBetween",
13
+ * "notContains", "notBeginsWith"). A `not` the menus have no word for (a loaded view's "not greater
14
+ * than") is hiddenNot().
15
+ * @param {{ op?: string, not?: boolean }} f
16
+ */
17
+ export declare const ruleOp: (f: {
18
+ op?: string;
19
+ not?: boolean;
20
+ }) => any;
21
+ /** Whether a filter's `not` has no word in the menus (ruleOp gives the operator without it). */
22
+ export declare const hiddenNot: (f: any) => boolean;
23
+ /**
24
+ * A menu's operator as version 2 writes it: `{ op, not }` ("notBetween" is between with not).
25
+ * @param {string} menuOp
26
+ */
27
+ export declare function opOf(menuOp: string): {
28
+ op: string;
29
+ not: boolean;
30
+ };
31
+ /**
32
+ * The pick of a field: the values not ticked dropped (null is the blank), so values that appear in
33
+ * newer data are shown, as in Excel.
34
+ * @param {string} field
35
+ * @param {unknown[]} excluded
36
+ */
37
+ export declare const pickFilter: (field: string, excluded: unknown[]) => {
38
+ field: string;
39
+ type: string;
40
+ items: ({} | undefined)[];
41
+ not: boolean;
42
+ blanks: string;
43
+ };
44
+ /** The pick of a field that drops nothing: a field in the Filters zone without a filter holds it. */
45
+ export declare const emptyPick: (field: any) => {
46
+ field: string;
47
+ type: string;
48
+ items: ({} | undefined)[];
49
+ not: boolean;
50
+ blanks: string;
51
+ };
52
+ /** Whether a filter is a field's pick (an item list, ticked in the menus). */
53
+ export declare const isPick: (f: any) => boolean;
54
+ /** Whether a pick drops nothing (emptyPick). */
55
+ export declare const isEmptyPick: (f: any) => boolean;
5
56
  export declare const same: (a: any, b: any) => boolean;
57
+ /**
58
+ * The items of a picker whose label holds what was typed: as text filters compare (pivotkit-core's
59
+ * foldText), so case and runs of whitespace, a no-break space among them, do not matter.
60
+ * @param {Array<{ label: string } & Record<string, any>>} items
61
+ * @param {string} query
62
+ */
63
+ export declare function searchItems(items: Array<{
64
+ label: string;
65
+ } & Record<string, any>>, query: string): ({
66
+ label: string;
67
+ } & Record<string, any>)[];
6
68
  /** The fields shown in the Filters zone: filtered fields that are on no axis, once each. */
7
69
  export declare function filterZoneFields(view: any): any[];
8
70
  /** The axis a field is on, or null. */
@@ -235,7 +297,7 @@ export declare function nextHeaderSort(view: any, target: {
235
297
  } | null;
236
298
  /** Filters of one type of a field. */
237
299
  export declare function filtersOf(view: any, field: any, types: any): any;
238
- /** The values an item filter lets through, from the field's values; all of them without a filter. */
300
+ /** The values a field's picks let through, from the field's values (null is the blank); all of them without a pick. */
239
301
  export declare function selectedItems(view: any, field: any, all: any): any;
240
302
  /**
241
303
  * True when a value gives a number for each cell, so it can be shown as a share, formatted, highlighted,
@@ -296,10 +358,7 @@ export declare function setChartDisplay(view: any, patch: {
296
358
  title?: string | null;
297
359
  smooth?: boolean;
298
360
  }): any;
299
- /**
300
- * Swaps the fields of Rows and Columns, with their collapsed groups; a calculation along an axis
301
- * ("running total along Rows") goes along the other one, so it still runs along the same fields.
302
- */
303
- export declare function swapAxes(view: any): any;
361
+ /** Rows and Columns swapped (pivotkit-core's swapAxes): the chart's swap, the zones' Swap button. */
362
+ export { swapAxes };
304
363
  /** True when nothing is placed: the UI shows its first steps. */
305
364
  export declare function isEmptyView(view: any): boolean;
@@ -1,111 +0,0 @@
1
- /**
2
- * Room (px) above and below a pie for the labels outside it, for a chart `height` px high: 5 % of the
3
- * height, at most 24 px. The pie's radius is a share of its box, so in a low box the top and bottom
4
- * labels would reach past the canvas; a tall box keeps nearly all of its pie.
5
- * @param {number} height
6
- */
7
- export declare function pieLabelRoom(height: number): number;
8
- /**
9
- * The least width (px) of a chart that keeps a legend on its right: the legend's column takes 160 px
10
- * (pivotkit-core), so a narrower chart (a phone) would squeeze the pie or the plot into a sliver. Below
11
- * it the legend is drawn at the bottom instead, with the room pivotkit-core gives a bottom legend.
12
- */
13
- export declare const RIGHT_LEGEND_MIN_WIDTH = 480;
14
- /** Room (px) pivotkit-core gives a legend at the bottom of a chart. */
15
- export declare const BOTTOM_LEGEND_ROOM = 32;
16
- /**
17
- * Whether the numbers written inside a donut's ring fit across it: the ring is the outer less the
18
- * inner radius, both a share (ECharts' "70%") of half the smaller side of the pie's box. A pie (no
19
- * inner radius) has room from its centre and always fits.
20
- * @param {[string | number, string | number]} radius the series' radius, inner and outer
21
- * @param {{ width: number, height: number }} box the pie's box: the chart less the room around it
22
- * @param {string[]} texts the labels written on the slices
23
- */
24
- export declare function ringLabelsFit(radius: [string | number, string | number], box: {
25
- width: number;
26
- height: number;
27
- }, texts: string[]): boolean;
28
- /** Width (px) a slanted column name of a heatmap takes at most; a longer one ends in "…". */
29
- export declare const SLANTED_LABEL_WIDTH = 120;
30
- /**
31
- * How a heatmap writes its column names along the x axis of a chart `width` px wide: straight when
32
- * the longest fits its column, else slanted by 45 degrees and cut at SLANTED_LABEL_WIDTH. Every name is
33
- * shown (the core sets interval 0); the width of a character is estimated as 0.55 of the font size.
34
- * @param {string[]} names
35
- * @param {number} width the chart's width in px
36
- * @param {number} [fontSize] px, ECharts' default for axis labels
37
- * @returns {{ rotate: number, width?: number, overflow?: "truncate" }}
38
- */
39
- export declare function columnLabelLayout(names: string[], width: number, fontSize?: number): {
40
- rotate: number;
41
- width?: number;
42
- overflow?: "truncate";
43
- };
44
- /**
45
- * True when the cells of a heatmap of `columns` x `rows` in a chart of `width` x `height` px hold their
46
- * numbers as the chart writes them (`texts`, formatted: "1,234.5", "-12.3%"): the longest, estimated at
47
- * 0.55 of the font size per character, fits a cell's width with room on both sides, and a line its height.
48
- * @param {number} columns
49
- * @param {number} rows
50
- * @param {number} width
51
- * @param {number} height
52
- * @param {string[]} texts
53
- * @param {number} [fontSize] px, ECharts' default for labels
54
- */
55
- export declare function heatmapCellLabels(columns: number, rows: number, width: number, height: number, texts: string[], fontSize?: number): boolean;
56
- /**
57
- * Which row names of a heatmap the y axis writes in a chart `height` px high: every one (0) when a line
58
- * fits each row, else every n-th (ECharts' interval: n - 1 names left out between two shown), so the
59
- * names never overlap and the first one is always there.
60
- * @param {number} rows
61
- * @param {number} height
62
- */
63
- export declare function rowLabelInterval(rows: number, height: number): number;
64
- /** Width (px) a category label of bars, lines and areas takes at most: a longer one ends in "…" (the tooltip has it whole). */
65
- export declare const CATEGORY_LABEL_WIDTH = 120;
66
- /**
67
- * How the category axis of bars, lines and areas writes its labels (`chart.axisLabels`):
68
- * - "auto": every label straight when the longest fits its slot, else slanted by 45 degrees while a
69
- * line fits each slot, else every n-th slanted (`every` > 1, the chart says so in a note);
70
- * - "all": every label, slanted when they do not fit straight;
71
- * - "nth": straight, every n-th so they never overlap.
72
- * Along a vertical axis (horizontal bars) the labels stay straight: every one while a line fits each
73
- * row, else every n-th. A label is cut at CATEGORY_LABEL_WIDTH; character width estimated at 0.55 of the font size.
74
- * @param {string[]} names
75
- * @param {{ width: number, height: number, horizontal?: boolean, mode?: string, fontSize?: number }} box
76
- * @returns {{ rotate: number, interval: number, every: number, width: number, overflow: "truncate" }}
77
- */
78
- export declare function categoryLabelLayout(names: string[], { width, height, horizontal, mode, fontSize }: {
79
- width: number;
80
- height: number;
81
- horizontal?: boolean;
82
- mode?: string;
83
- fontSize?: number;
84
- }): {
85
- rotate: number;
86
- interval: number;
87
- every: number;
88
- width: number;
89
- overflow: "truncate";
90
- };
91
- /** The least room (px) a group label needs along the axis, and the least size of a chart with group labels. */
92
- export declare const GROUP_LABEL_ROOM: Readonly<{
93
- along: 56;
94
- across: 28;
95
- width: 420;
96
- height: 260;
97
- }>;
98
- /**
99
- * Whether "auto" group labels fit a chart of `width` x `height` px with `count` categories whose
100
- * smallest group has `groupSize` of them: each group's name needs GROUP_LABEL_ROOM.along px under the
101
- * axis (across: a line per group beside a vertical axis), and the chart itself a least size, or the
102
- * plot area left over is too small to read.
103
- * @param {number} count
104
- * @param {number} groupSize
105
- * @param {{ width: number, height: number, horizontal?: boolean }} box
106
- */
107
- export declare function groupLabelsFit(count: number, groupSize: number, { width, height, horizontal }: {
108
- width: number;
109
- height: number;
110
- horizontal?: boolean;
111
- }): boolean;