pivotkit-react 0.0.0-stage → 0.1.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 (71) hide show
  1. package/CHANGELOG.md +300 -0
  2. package/LICENSE +21 -0
  3. package/README.md +327 -2
  4. package/dist/chunks/chunk-C32TYSHG.js +441 -0
  5. package/dist/chunks/chunk-ILHFIV2P.js +784 -0
  6. package/dist/chunks/chunk-KKJO36W5.js +1833 -0
  7. package/dist/chunks/chunk-XYP47DJ3.js +123 -0
  8. package/dist/echarts.js +262 -0
  9. package/dist/index.js +3390 -0
  10. package/dist/labels.js +12 -0
  11. package/dist/menus.js +1085 -0
  12. package/dist/styles.css +2447 -0
  13. package/package.json +70 -4
  14. package/types/PivotReport.d.ts +20 -0
  15. package/types/all-labels.d.ts +5 -0
  16. package/types/chart-decorate.d.ts +16 -0
  17. package/types/chart-options.d.ts +23 -0
  18. package/types/chart-summary.d.ts +12 -0
  19. package/types/chart-tooltip.d.ts +38 -0
  20. package/types/chart-types.d.ts +152 -0
  21. package/types/chart.d.ts +39 -0
  22. package/types/chip-menus.d.ts +32 -0
  23. package/types/clear-input.d.ts +20 -0
  24. package/types/dnd-moves.d.ts +45 -0
  25. package/types/dnd.d.ts +101 -0
  26. package/types/dom.d.ts +52 -0
  27. package/types/drill-export.d.ts +42 -0
  28. package/types/drill-panel.d.ts +39 -0
  29. package/types/drill.d.ts +62 -0
  30. package/types/echarts.d.ts +4 -0
  31. package/types/export-run.d.ts +59 -0
  32. package/types/field-info.d.ts +34 -0
  33. package/types/fields.d.ts +32 -0
  34. package/types/files.d.ts +27 -0
  35. package/types/filter.d.ts +21 -0
  36. package/types/icons.d.ts +76 -0
  37. package/types/index.d.ts +536 -0
  38. package/types/info.d.ts +34 -0
  39. package/types/iso.d.ts +2 -0
  40. package/types/labels.d.ts +721 -0
  41. package/types/lazy-menus.d.ts +16 -0
  42. package/types/menu-labels.d.ts +255 -0
  43. package/types/menus.d.ts +7 -0
  44. package/types/names.d.ts +80 -0
  45. package/types/numbers.d.ts +13 -0
  46. package/types/overflow.d.ts +59 -0
  47. package/types/place.d.ts +43 -0
  48. package/types/popover.d.ts +89 -0
  49. package/types/rove.d.ts +20 -0
  50. package/types/section.d.ts +42 -0
  51. package/types/share.d.ts +123 -0
  52. package/types/skeleton.d.ts +9 -0
  53. package/types/storage.d.ts +24 -0
  54. package/types/table.d.ts +23 -0
  55. package/types/templates.d.ts +40 -0
  56. package/types/theme.d.ts +24 -0
  57. package/types/tip-list.d.ts +20 -0
  58. package/types/tips.d.ts +298 -0
  59. package/types/toasts.d.ts +26 -0
  60. package/types/toolbar-panels.d.ts +90 -0
  61. package/types/toolbar.d.ts +5 -0
  62. package/types/use-big-result.d.ts +29 -0
  63. package/types/use-export.d.ts +7 -0
  64. package/types/use-theme.d.ts +11 -0
  65. package/types/use-view-history.d.ts +34 -0
  66. package/types/version.d.ts +2 -0
  67. package/types/view-history.d.ts +89 -0
  68. package/types/view-ops.d.ts +344 -0
  69. package/types/view-store.d.ts +52 -0
  70. package/types/virtual.d.ts +44 -0
  71. package/types/zones.d.ts +42 -0
package/package.json CHANGED
@@ -1,6 +1,72 @@
1
1
  {
2
2
  "name": "pivotkit-react",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "React 18/19 pivot report builder on pivotkit-core: drag-and-drop fields, table and Apache ECharts chart, filters, templates as JSON, undo, Excel and CSV export.",
5
+ "license": "MIT",
6
+ "author": "eizedev <oss@eize.dev>",
7
+ "homepage": "https://pivotkit.eize.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/eizedev/pivotkit.git",
11
+ "directory": "packages/pivotkit-react"
12
+ },
13
+ "bugs": "https://github.com/eizedev/pivotkit/issues",
14
+ "keywords": [
15
+ "pivot-table",
16
+ "pivot",
17
+ "react",
18
+ "reporting",
19
+ "drag-and-drop",
20
+ "echarts",
21
+ "self-service-bi"
22
+ ],
23
+ "type": "module",
24
+ "sideEffects": [
25
+ "*.css",
26
+ "./dist/echarts.js"
27
+ ],
28
+ "exports": {
29
+ ".": {
30
+ "types": "./types/index.d.ts",
31
+ "default": "./dist/index.js"
32
+ },
33
+ "./labels": {
34
+ "types": "./types/all-labels.d.ts",
35
+ "default": "./dist/labels.js"
36
+ },
37
+ "./styles.css": "./dist/styles.css",
38
+ "./package.json": "./package.json"
39
+ },
40
+ "files": [
41
+ "dist",
42
+ "types",
43
+ "README.md",
44
+ "CHANGELOG.md",
45
+ "LICENSE"
46
+ ],
47
+ "scripts": {
48
+ "build": "node build.js",
49
+ "test": "node build.js && node --test \"test/*.test.js\"",
50
+ "types": "tsc -p .",
51
+ "test:types": "tsc -p test/types",
52
+ "prepack": "node build.js && npm run types && node -e \"require('node:fs').copyFileSync('../../LICENSE', 'LICENSE')\"",
53
+ "coverage": "node build.js && node --test --experimental-test-coverage --test-coverage-include=\"src/**/*.js\" \"test/*.test.js\""
54
+ },
55
+ "peerDependencies": {
56
+ "echarts": ">=6.1.0 <7",
57
+ "react": ">=18.2 <20",
58
+ "react-dom": ">=18.2 <20"
59
+ },
60
+ "dependencies": {
61
+ "@dnd-kit/core": "6.3.1",
62
+ "@dnd-kit/sortable": "10.0.0",
63
+ "pivotkit-core": "^0.1.0"
64
+ },
65
+ "devDependencies": {
66
+ "echarts": "6.1.0"
67
+ },
68
+ "types": "./types/index.d.ts",
69
+ "publishConfig": {
70
+ "access": "public"
71
+ }
72
+ }
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ /** Width classes of the report (its own width, not the window's). */
3
+ export declare function sizeOf(width: any): "medium" | "narrow" | "wide";
4
+ /**
5
+ * Below this height (px, border box) the report starts with its zones folded into one line, the
6
+ * compact layout; a narrow report (its zones stacked, one line each) below COMPACT_HEIGHT_NARROW.
7
+ */
8
+ export declare const COMPACT_HEIGHT = 600;
9
+ export declare const COMPACT_HEIGHT_NARROW = 820;
10
+ /** Whether a report of this width class and height starts compact. */
11
+ export declare const compactAt: (size: any, height: any) => boolean;
12
+ /** Rows above which the report shows its skeleton first and encodes the data in the next frame. */
13
+ export declare const DEFER_ROWS = 10000;
14
+ /**
15
+ * The pivot report builder. While the host's data loads (`loading`) or a large data set is encoded for
16
+ * the first time, the report shows its skeleton; once shown, the report stays (its view and history
17
+ * too) and a later `loading` covers its result only.
18
+ * @param {import("./index.js").PivotReportProps} props
19
+ */
20
+ export declare function PivotReport(props: import("./index.js").PivotReportProps): React.JSX.Element;
@@ -0,0 +1,5 @@
1
+ /** @type {Readonly<{ en: import("./labels.js").UiLabels, de: import("./labels.js").UiLabels }>} */
2
+ export declare const LABELS: Readonly<{
3
+ en: import("./labels.js").UiLabels;
4
+ de: import("./labels.js").UiLabels;
5
+ }>;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Mark styles on top of the core's option: rounded bar ends, 2 px lines, tooltips in the theme, built
3
+ * as DOM nodes (chart-tooltip.js) so a strict Content-Security-Policy allows them.
4
+ * @param {any} option
5
+ * @param {CSSStyleDeclaration} style the report's computed style (the --pk-* tokens)
6
+ * @param {number} [height] the chart's height in px, for the room around a pie
7
+ * @param {Document} [doc] the chart's document, for the tooltip's nodes
8
+ * @param {number} [width] the chart's width in px, for the column names of a heatmap and the category axis
9
+ * @param {{ categoryNames?: string[], axisLabels?: string }} [extra] the categories' whole names (the
10
+ * tooltip's title when the axis writes them shorter) and the view's chart.axisLabels
11
+ * @returns {any} the option; `axisEvery` (not ECharts') is n when the category axis writes every n-th label
12
+ */
13
+ export declare function decorate(option: any, style: CSSStyleDeclaration, height?: number, doc?: Document, width?: number, extra?: {
14
+ categoryNames?: string[];
15
+ axisLabels?: string;
16
+ }): any;
@@ -0,0 +1,23 @@
1
+ /** How deep the object may nest, and how many entries it may have in all. */
2
+ export declare const CHART_OPTIONS_CAPS: Readonly<{
3
+ depth: 12;
4
+ entries: 2000;
5
+ }>;
6
+ /**
7
+ * The JSON part of the host's chartOptions and what was dropped (as "path: why").
8
+ * @param {unknown} value
9
+ * @returns {{ options: Record<string, unknown> | null, problems: string[] }}
10
+ */
11
+ export declare function cleanChartOptions(value: unknown): {
12
+ options: Record<string, unknown> | null;
13
+ problems: string[];
14
+ };
15
+ /**
16
+ * The option with `over` merged into it, neither changed: objects are merged key by key; a list
17
+ * (series, xAxis) is merged entry by entry, and an object given for a list is merged into every
18
+ * entry of it ({ series: { barMaxWidth: 24 } } sets every series); anything else replaces.
19
+ * @param {unknown} base
20
+ * @param {unknown} over
21
+ * @returns {any}
22
+ */
23
+ export declare function mergeChartOptions(base: unknown, over: unknown): any;
@@ -0,0 +1,12 @@
1
+ /**
2
+ * "Bars: Sum of Revenue by Region. 4 categories, 3 series. Highest 1,234 at North / A; lowest ..."
3
+ * @param {ReturnType<typeof import("pivotkit-core").toSeries>} s
4
+ * @param {{ type: string, rows: string[], valueNames: string[], labels: import("./labels.js").UiLabels, locale: string }} options
5
+ */
6
+ export declare function chartSummary(s: ReturnType<typeof import("pivotkit-core").toSeries>, { type, rows, valueNames, labels, locale }: {
7
+ type: string;
8
+ rows: string[];
9
+ valueNames: string[];
10
+ labels: import("./labels.js").UiLabels;
11
+ locale: string;
12
+ }): string;
@@ -0,0 +1,38 @@
1
+ export type TooltipLine = {
2
+ /**
3
+ * the series' or slice's colour, null when it is not a plain colour
4
+ */
5
+ color: string | null;
6
+ name: string;
7
+ value: string;
8
+ };
9
+ /**
10
+ * @typedef {object} TooltipLine
11
+ * @property {string | null} color the series' or slice's colour, null when it is not a plain colour
12
+ * @property {string} name
13
+ * @property {string} value
14
+ */
15
+ /**
16
+ * What a tooltip shows for ECharts' formatter parameters: a title and one line per series or slice.
17
+ * @param {any} params one item (trigger "item") or a list (trigger "axis")
18
+ * @param {{ valueFormatter?: (v: unknown) => string, xNames?: string[], yNames?: string[], categoryNames?: string[] }} [options]
19
+ * valueFormatter: the core's; xNames, yNames: the categories of a heatmap's axes; categoryNames: the
20
+ * whole name of each category, for an axis that writes them shorter (cut, or without their group)
21
+ * @returns {{ title: string, lines: TooltipLine[] }}
22
+ */
23
+ export declare function tooltipContent(params: any, { valueFormatter, xNames, yNames, categoryNames }?: {
24
+ valueFormatter?: (v: unknown) => string;
25
+ xNames?: string[];
26
+ yNames?: string[];
27
+ categoryNames?: string[];
28
+ }): {
29
+ title: string;
30
+ lines: TooltipLine[];
31
+ };
32
+ /**
33
+ * A tooltip formatter for ECharts that returns DOM nodes (see the top of this module).
34
+ * @param {Document} doc the chart's document
35
+ * @param {Parameters<typeof tooltipContent>[1]} options
36
+ * @returns {(params: any) => HTMLElement}
37
+ */
38
+ export declare function tooltipFormatter(doc: Document, options: Parameters<typeof tooltipContent>[1]): (params: any) => HTMLElement;
@@ -0,0 +1,152 @@
1
+ export type ChartTypeEntry = {
2
+ chart: {
3
+ type: string;
4
+ stacked: boolean;
5
+ horizontal: boolean;
6
+ };
7
+ icon: string;
8
+ axis: boolean;
9
+ };
10
+ /** @typedef {{ chart: { type: string, stacked: boolean, horizontal: boolean }, icon: string, axis: boolean }} ChartTypeEntry */
11
+ /**
12
+ * @type {Readonly<Record<string, ChartTypeEntry>>} axis: drawn along a category axis (series hints
13
+ * apply). "auto" is the view's default: the data decides (chartPlan), until the user picks a type.
14
+ */
15
+ export declare const CHART_TYPES: Readonly<Record<string, ChartTypeEntry>>;
16
+ /** The picker entries drawn as slices of a circle (pivotkit-core's SLICE_CHART_TYPES). */
17
+ export declare const SLICE_TYPES: readonly string[];
18
+ /** The picker entries in their order. */
19
+ export declare const CHART_TYPE_NAMES: readonly string[];
20
+ /**
21
+ * The picker entry of a view's chart settings.
22
+ * @param {{ type: string, stacked?: boolean, horizontal?: boolean }} chart
23
+ */
24
+ export declare function chartTypeOf(chart: {
25
+ type: string;
26
+ stacked?: boolean;
27
+ horizontal?: boolean;
28
+ }): string;
29
+ /**
30
+ * What the chart draws for a view. A type the user chose is drawn as it is. "auto" (the default)
31
+ * draws lines when a date is on Rows; with a date on Columns only it draws lines too, with rows and
32
+ * columns swapped for the chart alone (`swap`), so the dates run along the axis and the table keeps
33
+ * its layout; else bars (pivotkit-core's autoChartType decides).
34
+ * @param {{ rows: string[], cols: string[], derived: any[], chart: { type: string, stacked?: boolean, horizontal?: boolean } }} view
35
+ * @param {import("pivotkit-core").Encoded} encoded
36
+ * @returns {{ name: string, auto: boolean, swap: boolean, chart: { type: string, stacked: boolean, horizontal: boolean } }}
37
+ * `name`: the picker entry drawn (never "auto"); `chart`: the settings to draw with
38
+ */
39
+ export declare function chartPlan(view: {
40
+ rows: string[];
41
+ cols: string[];
42
+ derived: any[];
43
+ chart: {
44
+ type: string;
45
+ stacked?: boolean;
46
+ horizontal?: boolean;
47
+ };
48
+ }, encoded: import("pivotkit-core").Encoded): {
49
+ name: string;
50
+ auto: boolean;
51
+ swap: boolean;
52
+ chart: {
53
+ type: string;
54
+ stacked: boolean;
55
+ horizontal: boolean;
56
+ };
57
+ };
58
+ /** Charts with more series than this get a hint to swap or filter. */
59
+ export declare const MANY_SERIES = 8;
60
+ /** Categories a chart draws at most; the rest are left out with a note. */
61
+ export declare const MAX_CATEGORIES = 50;
62
+ /**
63
+ * Room (px) above and below a pie for the labels outside it, for a chart `height` px high: 5 % of the
64
+ * height, at most 24 px. The pie's radius is a share of its box, so in a low box the top and bottom
65
+ * labels would reach past the canvas; a tall box keeps nearly all of its pie.
66
+ * @param {number} height
67
+ */
68
+ export declare function pieLabelRoom(height: number): number;
69
+ /** Width (px) a slanted column name of a heatmap takes at most; a longer one ends in "…". */
70
+ export declare const SLANTED_LABEL_WIDTH = 120;
71
+ /**
72
+ * How a heatmap writes its column names along the x axis of a chart `width` px wide: straight when
73
+ * the longest fits its column, else slanted by 45 degrees and cut at SLANTED_LABEL_WIDTH. Every name is
74
+ * shown (the core sets interval 0); the width of a character is estimated as 0.55 of the font size.
75
+ * @param {string[]} names
76
+ * @param {number} width the chart's width in px
77
+ * @param {number} [fontSize] px, ECharts' default for axis labels
78
+ * @returns {{ rotate: number, width?: number, overflow?: "truncate" }}
79
+ */
80
+ export declare function columnLabelLayout(names: string[], width: number, fontSize?: number): {
81
+ rotate: number;
82
+ width?: number;
83
+ overflow?: "truncate";
84
+ };
85
+ /**
86
+ * True when the cells of a heatmap of `columns` x `rows` in a chart of `width` x `height` px hold their
87
+ * numbers as the chart writes them (`texts`, formatted: "1,234.5", "-12.3%"): the longest, estimated at
88
+ * 0.55 of the font size per character, fits a cell's width with room on both sides, and a line its height.
89
+ * @param {number} columns
90
+ * @param {number} rows
91
+ * @param {number} width
92
+ * @param {number} height
93
+ * @param {string[]} texts
94
+ * @param {number} [fontSize] px, ECharts' default for labels
95
+ */
96
+ export declare function heatmapCellLabels(columns: number, rows: number, width: number, height: number, texts: string[], fontSize?: number): boolean;
97
+ /**
98
+ * Which row names of a heatmap the y axis writes in a chart `height` px high: every one (0) when a line
99
+ * fits each row, else every n-th (ECharts' interval: n - 1 names left out between two shown), so the
100
+ * names never overlap and the first one is always there.
101
+ * @param {number} rows
102
+ * @param {number} height
103
+ */
104
+ export declare function rowLabelInterval(rows: number, height: number): number;
105
+ /** Width (px) a category label of bars, lines and areas takes at most: a longer one ends in "…" (the tooltip has it whole). */
106
+ export declare const CATEGORY_LABEL_WIDTH = 120;
107
+ /**
108
+ * How the category axis of bars, lines and areas writes its labels (`chart.axisLabels`):
109
+ * - "auto": every label straight when the longest fits its slot, else slanted by 45 degrees while a
110
+ * line fits each slot, else every n-th slanted (`every` > 1, the chart says so in a note);
111
+ * - "all": every label, slanted when they do not fit straight;
112
+ * - "nth": straight, every n-th so they never overlap.
113
+ * Along a vertical axis (horizontal bars) the labels stay straight: every one while a line fits each
114
+ * row, else every n-th. A label is cut at CATEGORY_LABEL_WIDTH; character width estimated at 0.55 of the font size.
115
+ * @param {string[]} names
116
+ * @param {{ width: number, height: number, horizontal?: boolean, mode?: string, fontSize?: number }} box
117
+ * @returns {{ rotate: number, interval: number, every: number, width: number, overflow: "truncate" }}
118
+ */
119
+ export declare function categoryLabelLayout(names: string[], { width, height, horizontal, mode, fontSize }: {
120
+ width: number;
121
+ height: number;
122
+ horizontal?: boolean;
123
+ mode?: string;
124
+ fontSize?: number;
125
+ }): {
126
+ rotate: number;
127
+ interval: number;
128
+ every: number;
129
+ width: number;
130
+ overflow: "truncate";
131
+ };
132
+ /** The least room (px) a group label needs along the axis, and the least size of a chart with group labels. */
133
+ export declare const GROUP_LABEL_ROOM: Readonly<{
134
+ along: 56;
135
+ across: 28;
136
+ width: 420;
137
+ height: 260;
138
+ }>;
139
+ /**
140
+ * Whether "auto" group labels fit a chart of `width` x `height` px with `count` categories whose
141
+ * smallest group has `groupSize` of them: each group's name needs GROUP_LABEL_ROOM.along px under the
142
+ * axis (across: a line per group beside a vertical axis), and the chart itself a least size, or the
143
+ * plot area left over is too small to read.
144
+ * @param {number} count
145
+ * @param {number} groupSize
146
+ * @param {{ width: number, height: number, horizontal?: boolean }} box
147
+ */
148
+ export declare function groupLabelsFit(count: number, groupSize: number, { width, height, horizontal }: {
149
+ width: number;
150
+ height: number;
151
+ horizontal?: boolean;
152
+ }): boolean;
@@ -0,0 +1,39 @@
1
+ import React from "react";
2
+ /** ECharts with the parts the chart draws with (echarts.js), loaded once on the first chart. */
3
+ export declare function loadECharts(): Promise<any>;
4
+ /**
5
+ * @param {{ result: import("pivotkit-core").PivotResult, series: ReturnType<typeof import("pivotkit-core").toSeries> | null,
6
+ * labels: import("./labels.js").UiLabels, locale: string,
7
+ * themeName: string, root: React.RefObject<HTMLElement>, onInstance: (chart: any) => void,
8
+ * onPoint: (point: { rowPath: any[], colPath: any[], valueIndex: number, value: unknown }) => void,
9
+ * valueNames: string[], chartOptions?: Record<string, unknown> | null,
10
+ * plan?: { name: string, chart: { type: string, stacked: boolean, horizontal: boolean } } }} props
11
+ * `series`: pivotkit-core's toSeries with MAX_CATEGORIES, null when there is nothing to draw;
12
+ * `chartOptions`: the host's plain JSON (chart-options.js, checked), merged over everything else;
13
+ * `plan`: what to draw (chart-types.js chartPlan), the view's type resolved when it is "auto"
14
+ */
15
+ export declare function PivotChart({ result, series, labels, locale, themeName, root, onInstance, onPoint, valueNames, chartOptions, plan }: {
16
+ result: import("pivotkit-core").PivotResult;
17
+ series: ReturnType<typeof import("pivotkit-core").toSeries> | null;
18
+ labels: import("./labels.js").UiLabels;
19
+ locale: string;
20
+ themeName: string;
21
+ root: React.RefObject<HTMLElement>;
22
+ onInstance: (chart: any) => void;
23
+ onPoint: (point: {
24
+ rowPath: any[];
25
+ colPath: any[];
26
+ valueIndex: number;
27
+ value: unknown;
28
+ }) => void;
29
+ valueNames: string[];
30
+ chartOptions?: Record<string, unknown> | null;
31
+ plan?: {
32
+ name: string;
33
+ chart: {
34
+ type: string;
35
+ stacked: boolean;
36
+ horizontal: boolean;
37
+ };
38
+ };
39
+ }): React.JSX.Element;
@@ -0,0 +1,32 @@
1
+ import React from "react";
2
+ /** The menu of a chip on Rows or Columns. */
3
+ export declare function AxisMenu({ view, zone, index, field, types, labels, commit, close, openFilter, chipRef, onRemove, defaultsOf, rangeOf, locale, info, state }: {
4
+ chipRef: any;
5
+ close: any;
6
+ commit: any;
7
+ defaultsOf: any;
8
+ field: any;
9
+ index: any;
10
+ info: any;
11
+ labels: any;
12
+ locale: any;
13
+ onRemove: any;
14
+ openFilter: any;
15
+ rangeOf: any;
16
+ state: any;
17
+ types: any;
18
+ view: any;
19
+ zone: any;
20
+ }): React.JSX.Element;
21
+ /** The menu of a value chip. */
22
+ export declare function ValueMenu({ view, index, types, labels, commit, close, onRemove, defaultsOf, info }: {
23
+ close: any;
24
+ commit: any;
25
+ defaultsOf: any;
26
+ index: any;
27
+ info: any;
28
+ labels: any;
29
+ onRemove: any;
30
+ types: any;
31
+ view: any;
32
+ }): React.JSX.Element;
@@ -0,0 +1,20 @@
1
+ import React from "react";
2
+ /**
3
+ * Empties a text field as an edit of its own, so it can be undone in the field.
4
+ * @param {HTMLInputElement | HTMLTextAreaElement} el
5
+ */
6
+ export declare function emptyField(el: HTMLInputElement | HTMLTextAreaElement): void;
7
+ /**
8
+ * @param {{ value: string, onChange: (value: string) => void, onClear?: () => void, clearLabel: string,
9
+ * multiline?: boolean, className?: string, inputRef?: React.RefObject<any> } & Record<string, any>} props
10
+ * every other prop goes to the input (type, placeholder, aria-label, data-testid, ...)
11
+ */
12
+ export declare function ClearInput({ value, onChange, onClear, clearLabel, multiline, className, inputRef, ...rest }: {
13
+ value: string;
14
+ onChange: (value: string) => void;
15
+ onClear?: () => void;
16
+ clearLabel: string;
17
+ multiline?: boolean;
18
+ className?: string;
19
+ inputRef?: React.RefObject<any>;
20
+ } & Record<string, any>): React.JSX.Element;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * Where a keyboard move goes, from the drop targets (zones and the chips in them) and the target the
3
+ * item is over: Left and Right step through the positions of a zone (before each chip, then the end),
4
+ * Up and Down go to the zone above or below. A field from the field list starts in Rows. The field
5
+ * list is never a keyboard target (removing is the x button or the menu).
6
+ * @param {string} key "ArrowLeft", "ArrowRight", "ArrowUp" or "ArrowDown"
7
+ * @param {Array<{ id: any, zone: string, kind: "zone" | "chip", index?: number }>} targets without the item itself
8
+ * @param {{ zone?: string, kind?: string, index?: number } | null} over the target the item is over
9
+ * @param {{ kind: string, zone?: string, index?: number }} active the item
10
+ * @returns {any} the id of the next target, or null to stay
11
+ */
12
+ export declare function nextTarget(key: string, targets: Array<{
13
+ id: any;
14
+ zone: string;
15
+ kind: "zone" | "chip";
16
+ index?: number;
17
+ }>, over: {
18
+ zone?: string;
19
+ kind?: string;
20
+ index?: number;
21
+ } | null, active: {
22
+ kind: string;
23
+ zone?: string;
24
+ index?: number;
25
+ }): any;
26
+ /**
27
+ * What a screen reader hears while dragging: the zone and the position ("Rows, position 2 of 3").
28
+ * @param {import("./labels.js").UiLabels} labels
29
+ */
30
+ export declare function announcementsOf(labels: import("./labels.js").UiLabels): {
31
+ onDragStart: ({ active: a }: {
32
+ active: any;
33
+ }) => string;
34
+ onDragOver: ({ active: a, over }: {
35
+ active: any;
36
+ over: any;
37
+ }) => string;
38
+ onDragEnd: ({ active: a, over }: {
39
+ active: any;
40
+ over: any;
41
+ }) => string;
42
+ onDragCancel: ({ active: a }: {
43
+ active: any;
44
+ }) => string;
45
+ };
package/types/dnd.d.ts ADDED
@@ -0,0 +1,101 @@
1
+ import React from "react";
2
+ export type DragSource = {
3
+ kind: "field" | "chip" | "table";
4
+ field: string;
5
+ zone?: string;
6
+ index?: number;
7
+ type?: string;
8
+ label?: string;
9
+ };
10
+ export type DropTarget = {
11
+ zone: string;
12
+ index?: number;
13
+ };
14
+ /** The source being dragged, or null. */
15
+ export declare function useActiveDrag(): DragSource | null;
16
+ /** Where a drop over `over` goes. */
17
+ export declare function targetOf(source: any, over: any): {
18
+ zone: any;
19
+ index?: undefined;
20
+ } | {
21
+ zone: any;
22
+ index: any;
23
+ } | null;
24
+ /**
25
+ * @param {{ labels: import("./labels.js").UiLabels, onDrop: (source: DragSource, target: DropTarget) => void,
26
+ * onDragStart?: (source: DragSource) => void, renderOverlay: (source: DragSource) => React.ReactNode, children: React.ReactNode }} props
27
+ */
28
+ export declare function PivotDnd({ labels, onDrop, onDragStart, renderOverlay, children }: {
29
+ labels: import("./labels.js").UiLabels;
30
+ onDrop: (source: DragSource, target: DropTarget) => void;
31
+ onDragStart?: (source: DragSource) => void;
32
+ renderOverlay: (source: DragSource) => React.ReactNode;
33
+ children: React.ReactNode;
34
+ }): React.JSX.Element;
35
+ /** A field of the field list or a table header cell. */
36
+ export declare function useDragSource(id: any, source: any, disabled?: boolean): {
37
+ setNodeRef: (element: HTMLElement | null) => void;
38
+ isDragging: boolean;
39
+ itemProps: any;
40
+ handleProps: {
41
+ role: string;
42
+ tabIndex: number;
43
+ 'aria-disabled': boolean;
44
+ 'aria-pressed': boolean | undefined;
45
+ 'aria-roledescription': string;
46
+ 'aria-describedby': string;
47
+ onKeyDown: any;
48
+ ref: (element: HTMLElement | null) => void;
49
+ } | {
50
+ role: string;
51
+ tabIndex: number;
52
+ 'aria-disabled': boolean;
53
+ 'aria-pressed': boolean | undefined;
54
+ 'aria-roledescription': string;
55
+ 'aria-describedby': string;
56
+ onKeyDown?: undefined;
57
+ ref: (element: HTMLElement | null) => void;
58
+ };
59
+ };
60
+ /** A chip in a zone: draggable and sortable within its zone. */
61
+ export declare function useChip(id: any, source: any): {
62
+ setNodeRef: (node: HTMLElement | null) => void;
63
+ isDragging: boolean;
64
+ style: {
65
+ transform: string;
66
+ transition: string | undefined;
67
+ } | {
68
+ transform?: undefined;
69
+ transition: string | undefined;
70
+ };
71
+ itemProps: any;
72
+ handleProps: {
73
+ role: string;
74
+ tabIndex: number;
75
+ 'aria-disabled': boolean;
76
+ 'aria-pressed': boolean | undefined;
77
+ 'aria-roledescription': string;
78
+ 'aria-describedby': string;
79
+ onKeyDown: any;
80
+ ref: (element: HTMLElement | null) => void;
81
+ } | {
82
+ role: string;
83
+ tabIndex: number;
84
+ 'aria-disabled': boolean;
85
+ 'aria-pressed': boolean | undefined;
86
+ 'aria-roledescription': string;
87
+ 'aria-describedby': string;
88
+ onKeyDown?: undefined;
89
+ ref: (element: HTMLElement | null) => void;
90
+ };
91
+ };
92
+ /** A drop zone: `kind` "zone" with its zone name, or "panel". */
93
+ export declare function useDropTarget(id: any, data: any): {
94
+ setNodeRef: (element: HTMLElement | null) => void;
95
+ isOver: boolean;
96
+ };
97
+ /** The sortable list of chips of one zone. */
98
+ export declare function ChipList({ ids, children }: {
99
+ children: any;
100
+ ids: any;
101
+ }): React.JSX.Element;
package/types/dom.d.ts ADDED
@@ -0,0 +1,52 @@
1
+ /** Elements that take the focus with Tab. */
2
+ export declare const FOCUSABLE = "button:not([disabled]), input:not([disabled]), select:not([disabled]), textarea:not([disabled]), a[href], [tabindex]:not([tabindex='-1'])";
3
+ /**
4
+ * The document or shadow root a node is in.
5
+ * @param {Node | null | undefined} node
6
+ * @returns {Document | ShadowRoot | null}
7
+ */
8
+ export declare function rootOf(node: Node | null | undefined): Document | ShadowRoot | null;
9
+ /**
10
+ * The focused element of a node's root: inside a shadow root its own activeElement, not the host.
11
+ * @param {Node | null | undefined} node
12
+ * @returns {Element | null}
13
+ */
14
+ export declare function activeIn(node: Node | null | undefined): Element | null;
15
+ /**
16
+ * Whether an event happened inside one of the elements, across shadow root boundaries.
17
+ * @param {Event} event
18
+ * @param {Array<Element | null | undefined>} elements
19
+ */
20
+ export declare function eventWithin(event: Event, elements: Array<Element | null | undefined>): boolean;
21
+ /**
22
+ * The elements of a container that Tab reaches, in order.
23
+ * @param {Element} container
24
+ * @returns {HTMLElement[]}
25
+ */
26
+ export declare function tabbables(container: Element): HTMLElement[];
27
+ /**
28
+ * Keeps Tab and Shift+Tab inside a container: from the last element to the first and back.
29
+ * @param {KeyboardEvent | React.KeyboardEvent} event
30
+ * @param {Element | null} container
31
+ */
32
+ export declare function trapTab(event: KeyboardEvent | React.KeyboardEvent, container: Element | null): void;
33
+ /**
34
+ * Escape closes this layer while it is open and the newest one, wherever the focus is (also on the
35
+ * page around the report).
36
+ * @param {boolean} open
37
+ * @param {() => void} onClose
38
+ */
39
+ export declare function useEscapeLayer(open: boolean, onClose: () => void): void;
40
+ /**
41
+ * A modal layer (drill-down, field drawer, bottom sheet): focus moves into it when it opens and back
42
+ * to where it was when it closes; Tab stays inside (`onKeyDown`); Escape closes it.
43
+ * @param {React.RefObject<HTMLElement | null>} ref
44
+ * @param {boolean} open
45
+ * @param {() => void} onClose
46
+ * @param {string} [opener] a selector for the button that opens the layer, inside the report: the
47
+ * focus goes there when there was no focused control before (Safari does not focus a clicked button)
48
+ * @returns {{ onKeyDown: (e: React.KeyboardEvent) => void }}
49
+ */
50
+ export declare function useModal(ref: React.RefObject<HTMLElement | null>, open: boolean, onClose: () => void, opener?: string): {
51
+ onKeyDown: (e: React.KeyboardEvent) => void;
52
+ };