@surfaces-ui/components 0.0.0-stage → 0.2.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 (264) hide show
  1. package/LICENSE +202 -0
  2. package/NOTICE +4 -0
  3. package/README.md +48 -2
  4. package/dist/appComponents.d.ts +86 -0
  5. package/dist/appComponents.js +555 -0
  6. package/dist/appComponents.js.map +1 -0
  7. package/dist/chart/BulletGraph.d.ts +44 -0
  8. package/dist/chart/BulletGraph.js +40 -0
  9. package/dist/chart/BulletGraph.js.map +1 -0
  10. package/dist/chart/Chart.d.ts +177 -0
  11. package/dist/chart/Chart.js +279 -0
  12. package/dist/chart/Chart.js.map +1 -0
  13. package/dist/chart/Sparkline.d.ts +35 -0
  14. package/dist/chart/Sparkline.js +37 -0
  15. package/dist/chart/Sparkline.js.map +1 -0
  16. package/dist/chart/advice.d.ts +28 -0
  17. package/dist/chart/advice.js +39 -0
  18. package/dist/chart/advice.js.map +1 -0
  19. package/dist/chart/option.d.ts +90 -0
  20. package/dist/chart/option.js +252 -0
  21. package/dist/chart/option.js.map +1 -0
  22. package/dist/controls/Combobox.d.ts +39 -0
  23. package/dist/controls/Combobox.js +75 -0
  24. package/dist/controls/Combobox.js.map +1 -0
  25. package/dist/controls/ConfirmDialog.d.ts +35 -0
  26. package/dist/controls/ConfirmDialog.js +84 -0
  27. package/dist/controls/ConfirmDialog.js.map +1 -0
  28. package/dist/controls/ItemControls.d.ts +115 -0
  29. package/dist/controls/ItemControls.js +109 -0
  30. package/dist/controls/ItemControls.js.map +1 -0
  31. package/dist/controls/Popover.d.ts +31 -0
  32. package/dist/controls/Popover.js +114 -0
  33. package/dist/controls/Popover.js.map +1 -0
  34. package/dist/controls/ResizeHandle.d.ts +48 -0
  35. package/dist/controls/ResizeHandle.js +91 -0
  36. package/dist/controls/ResizeHandle.js.map +1 -0
  37. package/dist/controls/SegmentedControl.d.ts +27 -0
  38. package/dist/controls/SegmentedControl.js +17 -0
  39. package/dist/controls/SegmentedControl.js.map +1 -0
  40. package/dist/controls/StatusBadge.d.ts +17 -0
  41. package/dist/controls/StatusBadge.js +10 -0
  42. package/dist/controls/StatusBadge.js.map +1 -0
  43. package/dist/controls/context.d.ts +17 -0
  44. package/dist/controls/context.js +2 -0
  45. package/dist/controls/context.js.map +1 -0
  46. package/dist/controls/placement.d.ts +43 -0
  47. package/dist/controls/placement.js +19 -0
  48. package/dist/controls/placement.js.map +1 -0
  49. package/dist/controls/resize.d.ts +23 -0
  50. package/dist/controls/resize.js +49 -0
  51. package/dist/controls/resize.js.map +1 -0
  52. package/dist/data/DataSourceProvider.d.ts +11 -0
  53. package/dist/data/DataSourceProvider.js +21 -0
  54. package/dist/data/DataSourceProvider.js.map +1 -0
  55. package/dist/data/export.d.ts +33 -0
  56. package/dist/data/export.js +77 -0
  57. package/dist/data/export.js.map +1 -0
  58. package/dist/data/format.d.ts +44 -0
  59. package/dist/data/format.js +127 -0
  60. package/dist/data/format.js.map +1 -0
  61. package/dist/data/messages.d.ts +13 -0
  62. package/dist/data/messages.js +2 -0
  63. package/dist/data/messages.js.map +1 -0
  64. package/dist/data/useRowWindow.d.ts +70 -0
  65. package/dist/data/useRowWindow.js +175 -0
  66. package/dist/data/useRowWindow.js.map +1 -0
  67. package/dist/discovery/AskData.d.ts +22 -0
  68. package/dist/discovery/AskData.js +48 -0
  69. package/dist/discovery/AskData.js.map +1 -0
  70. package/dist/discovery/ContextBuilder.d.ts +49 -0
  71. package/dist/discovery/ContextBuilder.js +167 -0
  72. package/dist/discovery/ContextBuilder.js.map +1 -0
  73. package/dist/discovery/DataSearch.d.ts +27 -0
  74. package/dist/discovery/DataSearch.js +73 -0
  75. package/dist/discovery/DataSearch.js.map +1 -0
  76. package/dist/discovery/ObjectDetail.d.ts +38 -0
  77. package/dist/discovery/ObjectDetail.js +129 -0
  78. package/dist/discovery/ObjectDetail.js.map +1 -0
  79. package/dist/discovery/RelationshipGraph.d.ts +19 -0
  80. package/dist/discovery/RelationshipGraph.js +64 -0
  81. package/dist/discovery/RelationshipGraph.js.map +1 -0
  82. package/dist/discovery/shared.d.ts +38 -0
  83. package/dist/discovery/shared.js +64 -0
  84. package/dist/discovery/shared.js.map +1 -0
  85. package/dist/editor/SqlEditor.d.ts +41 -0
  86. package/dist/editor/SqlEditor.js +181 -0
  87. package/dist/editor/SqlEditor.js.map +1 -0
  88. package/dist/explore/Explorer.d.ts +110 -0
  89. package/dist/explore/Explorer.js +471 -0
  90. package/dist/explore/Explorer.js.map +1 -0
  91. package/dist/explore/ModelLineage.d.ts +22 -0
  92. package/dist/explore/ModelLineage.js +70 -0
  93. package/dist/explore/ModelLineage.js.map +1 -0
  94. package/dist/explore/ReportBuilder.d.ts +39 -0
  95. package/dist/explore/ReportBuilder.js +98 -0
  96. package/dist/explore/ReportBuilder.js.map +1 -0
  97. package/dist/explore/SemanticModelEditor.d.ts +60 -0
  98. package/dist/explore/SemanticModelEditor.js +220 -0
  99. package/dist/explore/SemanticModelEditor.js.map +1 -0
  100. package/dist/explore/SemanticRows.d.ts +42 -0
  101. package/dist/explore/SemanticRows.js +117 -0
  102. package/dist/explore/SemanticRows.js.map +1 -0
  103. package/dist/explore/SemanticsProvider.d.ts +31 -0
  104. package/dist/explore/SemanticsProvider.js +72 -0
  105. package/dist/explore/SemanticsProvider.js.map +1 -0
  106. package/dist/explore/model.d.ts +151 -0
  107. package/dist/explore/model.js +344 -0
  108. package/dist/explore/model.js.map +1 -0
  109. package/dist/explore/report.d.ts +60 -0
  110. package/dist/explore/report.js +92 -0
  111. package/dist/explore/report.js.map +1 -0
  112. package/dist/explore/semantic-proposal.d.ts +44 -0
  113. package/dist/explore/semantic-proposal.js +67 -0
  114. package/dist/explore/semantic-proposal.js.map +1 -0
  115. package/dist/explore/semantic.d.ts +44 -0
  116. package/dist/explore/semantic.js +154 -0
  117. package/dist/explore/semantic.js.map +1 -0
  118. package/dist/files/FileBrowser.d.ts +42 -0
  119. package/dist/files/FileBrowser.js +314 -0
  120. package/dist/files/FileBrowser.js.map +1 -0
  121. package/dist/files/files.d.ts +65 -0
  122. package/dist/files/files.js +165 -0
  123. package/dist/files/files.js.map +1 -0
  124. package/dist/filter/FilterBar.d.ts +49 -0
  125. package/dist/filter/FilterBar.js +153 -0
  126. package/dist/filter/FilterBar.js.map +1 -0
  127. package/dist/filter/QueryFilters.d.ts +25 -0
  128. package/dist/filter/QueryFilters.js +58 -0
  129. package/dist/filter/QueryFilters.js.map +1 -0
  130. package/dist/form/Form.d.ts +76 -0
  131. package/dist/form/Form.js +131 -0
  132. package/dist/form/Form.js.map +1 -0
  133. package/dist/graph/NodeGraph.d.ts +30 -0
  134. package/dist/graph/NodeGraph.js +86 -0
  135. package/dist/graph/NodeGraph.js.map +1 -0
  136. package/dist/graph/model.d.ts +68 -0
  137. package/dist/graph/model.js +122 -0
  138. package/dist/graph/model.js.map +1 -0
  139. package/dist/grid/DataGrid.d.ts +98 -0
  140. package/dist/grid/DataGrid.js +399 -0
  141. package/dist/grid/DataGrid.js.map +1 -0
  142. package/dist/index.d.ts +84 -0
  143. package/dist/index.js +86 -0
  144. package/dist/index.js.map +1 -0
  145. package/dist/locale/SurfacesText.d.ts +17 -0
  146. package/dist/locale/SurfacesText.js +17 -0
  147. package/dist/locale/SurfacesText.js.map +1 -0
  148. package/dist/locale/locale.d.ts +305 -0
  149. package/dist/locale/locale.js +359 -0
  150. package/dist/locale/locale.js.map +1 -0
  151. package/dist/menu/ContextMenu.d.ts +31 -0
  152. package/dist/menu/ContextMenu.js +95 -0
  153. package/dist/menu/ContextMenu.js.map +1 -0
  154. package/dist/metric/Metric.d.ts +33 -0
  155. package/dist/metric/Metric.js +63 -0
  156. package/dist/metric/Metric.js.map +1 -0
  157. package/dist/metric/useMeasure.d.ts +23 -0
  158. package/dist/metric/useMeasure.js +43 -0
  159. package/dist/metric/useMeasure.js.map +1 -0
  160. package/dist/model/ModelDiagram.d.ts +142 -0
  161. package/dist/model/ModelDiagram.js +699 -0
  162. package/dist/model/ModelDiagram.js.map +1 -0
  163. package/dist/panzoom/usePanZoom.d.ts +117 -0
  164. package/dist/panzoom/usePanZoom.js +313 -0
  165. package/dist/panzoom/usePanZoom.js.map +1 -0
  166. package/dist/pipeline/DatasetReview.d.ts +48 -0
  167. package/dist/pipeline/DatasetReview.js +157 -0
  168. package/dist/pipeline/DatasetReview.js.map +1 -0
  169. package/dist/pipeline/IngestWizard.d.ts +51 -0
  170. package/dist/pipeline/IngestWizard.js +79 -0
  171. package/dist/pipeline/IngestWizard.js.map +1 -0
  172. package/dist/pipeline/Pipeline.d.ts +171 -0
  173. package/dist/pipeline/Pipeline.js +203 -0
  174. package/dist/pipeline/Pipeline.js.map +1 -0
  175. package/dist/pipeline/PipelineView.d.ts +63 -0
  176. package/dist/pipeline/PipelineView.js +239 -0
  177. package/dist/pipeline/PipelineView.js.map +1 -0
  178. package/dist/pivot/PivotTable.d.ts +94 -0
  179. package/dist/pivot/PivotTable.js +171 -0
  180. package/dist/pivot/PivotTable.js.map +1 -0
  181. package/dist/plan/QueryPlan.d.ts +29 -0
  182. package/dist/plan/QueryPlan.js +79 -0
  183. package/dist/plan/QueryPlan.js.map +1 -0
  184. package/dist/result/QueryResult.d.ts +51 -0
  185. package/dist/result/QueryResult.js +255 -0
  186. package/dist/result/QueryResult.js.map +1 -0
  187. package/dist/review/ActionReceipt.d.ts +52 -0
  188. package/dist/review/ActionReceipt.js +32 -0
  189. package/dist/review/ActionReceipt.js.map +1 -0
  190. package/dist/review/PiiReview.d.ts +37 -0
  191. package/dist/review/PiiReview.js +29 -0
  192. package/dist/review/PiiReview.js.map +1 -0
  193. package/dist/review/PlanReview.d.ts +42 -0
  194. package/dist/review/PlanReview.js +37 -0
  195. package/dist/review/PlanReview.js.map +1 -0
  196. package/dist/review/StepFlow.d.ts +25 -0
  197. package/dist/review/StepFlow.js +21 -0
  198. package/dist/review/StepFlow.js.map +1 -0
  199. package/dist/review/pii.d.ts +21 -0
  200. package/dist/review/pii.js +67 -0
  201. package/dist/review/pii.js.map +1 -0
  202. package/dist/rows/RowList.d.ts +41 -0
  203. package/dist/rows/RowList.js +71 -0
  204. package/dist/rows/RowList.js.map +1 -0
  205. package/dist/schema/ObjectBrowser.d.ts +78 -0
  206. package/dist/schema/ObjectBrowser.js +467 -0
  207. package/dist/schema/ObjectBrowser.js.map +1 -0
  208. package/dist/schema/ObjectInfo.d.ts +25 -0
  209. package/dist/schema/ObjectInfo.js +69 -0
  210. package/dist/schema/ObjectInfo.js.map +1 -0
  211. package/dist/schema/SchemaExplorer.d.ts +32 -0
  212. package/dist/schema/SchemaExplorer.js +175 -0
  213. package/dist/schema/SchemaExplorer.js.map +1 -0
  214. package/dist/schema/refs.d.ts +32 -0
  215. package/dist/schema/refs.js +65 -0
  216. package/dist/schema/refs.js.map +1 -0
  217. package/dist/site/Site.d.ts +191 -0
  218. package/dist/site/Site.js +138 -0
  219. package/dist/site/Site.js.map +1 -0
  220. package/dist/source/ConnectionBuilder.d.ts +54 -0
  221. package/dist/source/ConnectionBuilder.js +115 -0
  222. package/dist/source/ConnectionBuilder.js.map +1 -0
  223. package/dist/source/SourceList.d.ts +17 -0
  224. package/dist/source/SourceList.js +71 -0
  225. package/dist/source/SourceList.js.map +1 -0
  226. package/dist/styles.css +9882 -0
  227. package/dist/styles.layer.css +9886 -0
  228. package/dist/table/DataTable.d.ts +72 -0
  229. package/dist/table/DataTable.js +68 -0
  230. package/dist/table/DataTable.js.map +1 -0
  231. package/dist/table/Pagination.d.ts +20 -0
  232. package/dist/table/Pagination.js +16 -0
  233. package/dist/table/Pagination.js.map +1 -0
  234. package/dist/table/SelectionBar.d.ts +43 -0
  235. package/dist/table/SelectionBar.js +18 -0
  236. package/dist/table/SelectionBar.js.map +1 -0
  237. package/dist/text/Markdown.d.ts +71 -0
  238. package/dist/text/Markdown.js +187 -0
  239. package/dist/text/Markdown.js.map +1 -0
  240. package/dist/text/highlight.d.ts +23 -0
  241. package/dist/text/highlight.js +196 -0
  242. package/dist/text/highlight.js.map +1 -0
  243. package/dist/theme/ThemePicker.d.ts +16 -0
  244. package/dist/theme/ThemePicker.js +49 -0
  245. package/dist/theme/ThemePicker.js.map +1 -0
  246. package/dist/theme/ThemeProvider.d.ts +43 -0
  247. package/dist/theme/ThemeProvider.js +107 -0
  248. package/dist/theme/ThemeProvider.js.map +1 -0
  249. package/dist/workspace/NavBar.d.ts +23 -0
  250. package/dist/workspace/NavBar.js +171 -0
  251. package/dist/workspace/NavBar.js.map +1 -0
  252. package/dist/workspace/SideNav.d.ts +61 -0
  253. package/dist/workspace/SideNav.js +149 -0
  254. package/dist/workspace/SideNav.js.map +1 -0
  255. package/dist/workspace/Workspace.d.ts +50 -0
  256. package/dist/workspace/Workspace.js +243 -0
  257. package/dist/workspace/Workspace.js.map +1 -0
  258. package/dist/workspace/icons.d.ts +34 -0
  259. package/dist/workspace/icons.js +37 -0
  260. package/dist/workspace/icons.js.map +1 -0
  261. package/dist/workspace/layout.d.ts +74 -0
  262. package/dist/workspace/layout.js +276 -0
  263. package/dist/workspace/layout.js.map +1 -0
  264. package/package.json +85 -3
@@ -0,0 +1,90 @@
1
+ import { type Field } from "apache-arrow";
2
+ export type ChartType = "bar" | "line" | "area" | "scatter" | "pie";
3
+ /** How one series is drawn. A chart whose series differ is a compound chart. */
4
+ export type SeriesType = Exclude<ChartType, "pie">;
5
+ export type LegendPlacement = "top" | "bottom" | "right" | "none";
6
+ export interface ChartSpecSeries {
7
+ /** Output column holding the values. */
8
+ column: string;
9
+ /** Name shown in the legend and tooltip. */
10
+ label: string;
11
+ /** Draw this series as something other than the chart's type, e.g. a line over bars. */
12
+ type?: SeriesType;
13
+ /** The y axis this series is measured on. Defaults to "left". */
14
+ axis?: "left" | "right";
15
+ /** Series with the same stack name are stacked on each other. */
16
+ stack?: string;
17
+ /** Draw this series in this colour instead of the next one in the theme's order. */
18
+ color?: string;
19
+ }
20
+ export interface ChartOptionInput {
21
+ type: ChartType;
22
+ /** Column for the x axis (or the slice names of a pie). */
23
+ x: string;
24
+ series: ChartSpecSeries[];
25
+ /** Column whose distinct values split each measure into separate series. */
26
+ splitBy?: string;
27
+ fields: Field[];
28
+ /** Rows as plain chart values, keyed by column. */
29
+ rows: Record<string, string | number | null>[];
30
+ /** Where the legend goes. Defaults to "top" when there is more than one series, otherwise "none". */
31
+ legend?: LegendPlacement;
32
+ /** Stack every series that has no stack name of its own. */
33
+ stacked?: boolean;
34
+ /** Colours for particular values of the split column, by value. */
35
+ splitColors?: Record<string, string>;
36
+ /** Axis titles. */
37
+ xTitle?: string;
38
+ yTitle?: string;
39
+ yRightTitle?: string;
40
+ /** How the left axis writes its numbers. Changes the labels only, never the values. */
41
+ yFormat?: AxisFormat;
42
+ /**
43
+ * "value" puts categories in order of size, largest first, unless x is a
44
+ * date or number, whose own order is kept. "x" keeps the rows as given.
45
+ */
46
+ sort?: "value" | "x";
47
+ /**
48
+ * Bars run across instead of up: the categories go down the left side,
49
+ * largest at the top, and the values along the bottom. Applies only when
50
+ * every series is a bar on one scale; otherwise it is ignored.
51
+ */
52
+ horizontal?: boolean;
53
+ }
54
+ /** True when a chart of this shape can be turned on its side: bars only, on one scale. */
55
+ export declare function canTurnSideways(type: ChartType, series: {
56
+ type?: SeriesType;
57
+ axis?: "left" | "right";
58
+ }[]): boolean;
59
+ /** True when a column's values have an order of their own: dates, times and numbers. */
60
+ export declare function isOrdered(field: Field | undefined): boolean;
61
+ /**
62
+ * The order categories are drawn in when sorted by size: by the total of the
63
+ * first measure across every series, largest first. Sorting by the total
64
+ * keeps a stacked or grouped chart in one order for all its series.
65
+ */
66
+ export declare function categoriesBySize(rows: Record<string, string | number | null>[], x: string, measure: string): string[];
67
+ /** A number on an axis: 12K, 1.5M, and for a value under one enough digits to tell the ticks apart (0.02, not 0). */
68
+ export declare const axisNumber: (value: number) => string;
69
+ export type AxisFormat = "number" | "compact" | "currency" | "percent";
70
+ /** A number on an axis in a measure's own format: 6% rather than 0.06, $1.2M rather than 1.2M. */
71
+ export declare const axisFormatter: (format: AxisFormat | undefined) => ((value: number) => string);
72
+ /**
73
+ * A value in a tooltip, where a person reads one number closely: in full rather than compact, rounded to what can be
74
+ * told apart (6.1%, $1,234.50, 1,234.57, 0.0123), in the measure's own format. Changes the text only, never the value.
75
+ */
76
+ export declare const tooltipFormatter: (format: AxisFormat | undefined) => (value: unknown) => string;
77
+ /**
78
+ * The rows a chart cannot place: those with no x, on a time or number axis. (A category axis draws them under
79
+ * "null".) They are left out of the option whole, since a point that is not drawn must not size the y axis:
80
+ * a count of the rows with no date would otherwise flatten the line of every week that has one.
81
+ */
82
+ export declare function rowsWithoutX(input: Pick<ChartOptionInput, "type" | "x" | "series" | "fields" | "rows">): ChartOptionInput["rows"];
83
+ /**
84
+ * Builds an ECharts option from query rows. Pure, so it can be tested and
85
+ * reused on a server or by an agent. Colours and fonts come from the theme
86
+ * passed to `echarts.init`, not from here.
87
+ */
88
+ export declare function buildChartOption(given: ChartOptionInput): Record<string, unknown>;
89
+ /** A round bin width that splits [min, max] into about `bins` bins. */
90
+ export declare function niceBinWidth(min: number, max: number, bins: number): number;
@@ -0,0 +1,252 @@
1
+ import { DataType } from "apache-arrow";
2
+ import { numberFormat } from "../locale/locale.js";
3
+ /**
4
+ * An axis title sits a fixed gap beyond the tick labels, wherever they end. A gap measured from the axis line
5
+ * suits one width of label only: beside two-digit ticks the title ran off the chart's edge.
6
+ */
7
+ const TITLE_CLEAR = { nameGap: 8, nameMoveOverlap: true };
8
+ /** True when a chart of this shape can be turned on its side: bars only, on one scale. */
9
+ export function canTurnSideways(type, series) {
10
+ return series.length > 0 && series.every((s) => (s.type ?? type) === "bar" && s.axis !== "right");
11
+ }
12
+ /** True when a column's values have an order of their own: dates, times and numbers. */
13
+ export function isOrdered(field) {
14
+ if (!field)
15
+ return false;
16
+ return DataType.isTimestamp(field.type) || DataType.isDate(field.type) || DataType.isInt(field.type) || DataType.isFloat(field.type) || DataType.isDecimal(field.type);
17
+ }
18
+ /**
19
+ * The order categories are drawn in when sorted by size: by the total of the
20
+ * first measure across every series, largest first. Sorting by the total
21
+ * keeps a stacked or grouped chart in one order for all its series.
22
+ */
23
+ export function categoriesBySize(rows, x, measure) {
24
+ const totals = new Map();
25
+ for (const row of rows) {
26
+ const key = String(row[x] ?? "null");
27
+ totals.set(key, (totals.get(key) ?? 0) + (Number(row[measure]) || 0));
28
+ }
29
+ return [...totals.entries()].sort((a, b) => b[1] - a[1]).map(([key]) => key);
30
+ }
31
+ function axisType(field, scatter) {
32
+ if (!field)
33
+ return "category";
34
+ if (DataType.isTimestamp(field.type) || DataType.isDate(field.type))
35
+ return "time";
36
+ const numeric = DataType.isInt(field.type) || DataType.isFloat(field.type) || DataType.isDecimal(field.type);
37
+ return numeric && scatter ? "value" : "category";
38
+ }
39
+ const compact = () => numberFormat({ notation: "compact", maximumFractionDigits: 1 });
40
+ const fraction = () => numberFormat({ maximumSignificantDigits: 2 });
41
+ /** A number on an axis: 12K, 1.5M, and for a value under one enough digits to tell the ticks apart (0.02, not 0). */
42
+ export const axisNumber = (value) => (value !== 0 && Math.abs(value) < 1 ? fraction().format(value) : compact().format(value));
43
+ const percent = () => numberFormat({ style: "percent", maximumSignificantDigits: 2 });
44
+ const money = () => numberFormat({ style: "currency", currency: "USD", notation: "compact", maximumSignificantDigits: 3 });
45
+ /** A number on an axis in a measure's own format: 6% rather than 0.06, $1.2M rather than 1.2M. */
46
+ export const axisFormatter = (format) => format === "percent" ? (value) => percent().format(value) : format === "currency" ? (value) => money().format(value) : axisNumber;
47
+ const exactPercent = () => numberFormat({ style: "percent", maximumFractionDigits: 1 });
48
+ const exactMoney = () => numberFormat({ style: "currency", currency: "USD", maximumFractionDigits: 2 });
49
+ const exact = () => numberFormat({ maximumFractionDigits: 2 });
50
+ /**
51
+ * A value in a tooltip, where a person reads one number closely: in full rather than compact, rounded to what can be
52
+ * told apart (6.1%, $1,234.50, 1,234.57, 0.0123), in the measure's own format. Changes the text only, never the value.
53
+ */
54
+ export const tooltipFormatter = (format) => (value) => {
55
+ const n = typeof value === "number" ? value : Number(value);
56
+ if (value == null || value === "" || !Number.isFinite(n))
57
+ return value == null ? "–" : String(value);
58
+ if (format === "percent")
59
+ return exactPercent().format(n);
60
+ if (format === "currency")
61
+ return exactMoney().format(n);
62
+ return n !== 0 && Math.abs(n) < 1 ? fraction().format(n) : exact().format(n);
63
+ };
64
+ function legendOption(placement) {
65
+ if (placement === "none")
66
+ return { show: false };
67
+ if (placement === "right")
68
+ return { type: "scroll", orient: "vertical", right: 0, top: "middle" };
69
+ return { type: "scroll", [placement]: 0 };
70
+ }
71
+ /**
72
+ * True when the last points of every series are far enough apart for a label
73
+ * at each end to be read. Lines that finish close together keep the legend.
74
+ */
75
+ function endsApart(series, dataset, rows) {
76
+ const sets = Array.isArray(dataset) ? dataset : undefined;
77
+ const ends = [];
78
+ let low = Infinity;
79
+ let high = -Infinity;
80
+ for (const item of series) {
81
+ const column = item.encode.y;
82
+ const source = sets ? (sets[item.datasetIndex]?.source ?? []) : rows;
83
+ const values = source.map((row) => Number(row[column])).filter((v) => Number.isFinite(v));
84
+ if (values.length === 0)
85
+ return false;
86
+ ends.push(values.at(-1));
87
+ low = Math.min(low, ...values);
88
+ high = Math.max(high, ...values);
89
+ }
90
+ const room = (high - Math.min(low, 0)) * 0.08;
91
+ const sorted = [...ends].sort((a, b) => a - b);
92
+ return sorted.every((value, i) => i === 0 || value - sorted[i - 1] >= room);
93
+ }
94
+ /**
95
+ * The rows a chart cannot place: those with no x, on a time or number axis. (A category axis draws them under
96
+ * "null".) They are left out of the option whole, since a point that is not drawn must not size the y axis:
97
+ * a count of the rows with no date would otherwise flatten the line of every week that has one.
98
+ */
99
+ export function rowsWithoutX(input) {
100
+ if (input.type === "pie")
101
+ return [];
102
+ const kinds = input.series.map((s) => s.type ?? input.type);
103
+ const xType = axisType(input.fields.find((f) => f.name === input.x), kinds.every((k) => k === "scatter"));
104
+ return xType === "category" ? [] : input.rows.filter((row) => row[input.x] == null);
105
+ }
106
+ /**
107
+ * Builds an ECharts option from query rows. Pure, so it can be tested and
108
+ * reused on a server or by an agent. Colours and fonts come from the theme
109
+ * passed to `echarts.init`, not from here.
110
+ */
111
+ export function buildChartOption(given) {
112
+ const unplaced = rowsWithoutX(given);
113
+ const input = unplaced.length > 0 ? { ...given, rows: given.rows.filter((row) => row[given.x] != null) } : given;
114
+ const { type, x, splitBy } = input;
115
+ const xField = input.fields.find((f) => f.name === x);
116
+ // A date or number axis is drawn in its own order, whatever order the rows arrived in.
117
+ const byX = type !== "pie" && isOrdered(xField) && input.sort === "value";
118
+ // A missing category is drawn under its own name rather than dropped from the axis.
119
+ const named = type !== "pie" && input.sort === "value" && !isOrdered(xField) ? input.rows.map((row) => (row[x] == null ? { ...row, [x]: "null" } : row)) : input.rows;
120
+ const rows = byX ? [...input.rows].sort((a, b) => (typeof a[x] === "number" && typeof b[x] === "number" ? a[x] - b[x] : String(a[x]).localeCompare(String(b[x])))) : named;
121
+ if (type === "pie") {
122
+ const measure = input.series[0];
123
+ return {
124
+ tooltip: { trigger: "item", valueFormatter: tooltipFormatter(input.yFormat) },
125
+ legend: legendOption(input.legend ?? "bottom"),
126
+ series: [
127
+ {
128
+ type: "pie",
129
+ name: measure?.label ?? "",
130
+ radius: ["45%", "72%"],
131
+ center: ["50%", "45%"],
132
+ label: { show: rows.length <= 8 },
133
+ data: measure ? rows.map((row) => ({ name: String(row[x] ?? "null"), value: row[measure.column] })) : [],
134
+ },
135
+ ],
136
+ };
137
+ }
138
+ const kinds = input.series.map((s) => s.type ?? type);
139
+ const xType = axisType(xField, kinds.every((k) => k === "scatter"));
140
+ const sideways = !!input.horizontal && canTurnSideways(type, input.series);
141
+ // On its side, the category axis is the vertical one and the value axis the horizontal one.
142
+ const at = (category, value) => (sideways ? { x: value, y: category } : { x: category, y: value });
143
+ const large = rows.length > 2000 ? { large: true, sampling: "lttb", showSymbol: false } : {};
144
+ const hasRight = input.series.some((s) => s.axis === "right");
145
+ const shape = (measure) => {
146
+ const kind = measure.type ?? type;
147
+ const stack = measure.stack ?? (input.stacked && kind !== "scatter" ? `stack-${measure.axis ?? "left"}-${kind}` : undefined);
148
+ return {
149
+ type: kind === "area" ? "line" : kind,
150
+ ...(kind === "area" ? { areaStyle: { opacity: 0.18 }, showSymbol: false } : {}),
151
+ ...(stack ? { stack } : {}),
152
+ ...(hasRight ? { yAxisIndex: measure.axis === "right" ? 1 : 0 } : {}),
153
+ tooltip: { valueFormatter: tooltipFormatter(measure.axis === "right" ? undefined : input.yFormat) },
154
+ ...large,
155
+ };
156
+ };
157
+ const painted = (color) => (color ? { itemStyle: { color }, lineStyle: { color } } : {});
158
+ let series;
159
+ let dataset;
160
+ if (splitBy) {
161
+ // One dataset per distinct value of the split column, one series per (value, measure).
162
+ const groups = new Map();
163
+ for (const row of rows) {
164
+ const key = String(row[splitBy] ?? "null");
165
+ const group = groups.get(key);
166
+ if (group)
167
+ group.push(row);
168
+ else
169
+ groups.set(key, [row]);
170
+ }
171
+ const keys = [...groups.keys()];
172
+ dataset = keys.map((key) => ({ source: groups.get(key) }));
173
+ series = keys.flatMap((key, datasetIndex) => input.series.map((measure) => ({
174
+ ...shape(measure),
175
+ ...painted(input.splitColors?.[key]),
176
+ name: input.series.length > 1 ? `${key} · ${measure.label}` : key,
177
+ datasetIndex,
178
+ encode: at(x, measure.column),
179
+ })));
180
+ }
181
+ else {
182
+ dataset = { source: rows };
183
+ series = input.series.map((measure) => ({ ...shape(measure), ...painted(measure.color), name: measure.label, encode: at(x, measure.column) }));
184
+ }
185
+ // Up to four lines are named at their ends, where the eye already is, instead of in a legend.
186
+ const direct = input.legend === undefined && series.length >= 2 && series.length <= 4 && kinds.every((k) => k === "line") && !input.stacked && !hasRight && endsApart(series, dataset, rows);
187
+ if (direct)
188
+ series = series.map((s) => ({ ...s, endLabel: { show: true, formatter: "{a}", distance: 6 }, labelLayout: { moveOverlap: "shiftY" } }));
189
+ const legend = input.legend ?? (direct ? "none" : series.length > 1 ? "top" : "none");
190
+ const categories = input.sort === "value" && !isOrdered(xField) && input.series[0] ? categoriesBySize(rows, x, input.series[0].column) : undefined;
191
+ // A zoom bar earns its space only when there are too many points to read at once.
192
+ const zoom = new Set(rows.map((row) => row[x])).size > 60;
193
+ const valueAxis = (name, right) => ({
194
+ type: "value",
195
+ name,
196
+ nameLocation: "middle",
197
+ ...TITLE_CLEAR,
198
+ position: right ? "right" : "left",
199
+ // A second axis has its own scale, so its grid lines would not line up with the first.
200
+ splitLine: { show: !right },
201
+ axisLabel: { formatter: right ? axisNumber : axisFormatter(input.yFormat) },
202
+ });
203
+ return {
204
+ // Times come from the engine in UTC (a month bucket is midnight UTC on the 1st). Drawn in the
205
+ // viewer's own zone they would land on the last day of the month before.
206
+ useUTC: true,
207
+ dataset,
208
+ // The margins are what is left around the plot, its tick labels and its axis titles together: the plot shrinks
209
+ // until all three fit, however wide the tick labels turn out to be.
210
+ grid: {
211
+ left: 8,
212
+ right: legend === "right" ? 140 : direct ? 96 : 16,
213
+ top: legend === "top" ? 36 : 16,
214
+ bottom: (zoom && !sideways ? 40 : 8) + (legend === "bottom" ? 28 : 0),
215
+ outerBoundsMode: "same",
216
+ outerBoundsContain: "all",
217
+ },
218
+ tooltip: { trigger: kinds.every((k) => k === "scatter") ? "item" : "axis" },
219
+ legend: legendOption(legend),
220
+ ...(sideways
221
+ ? {
222
+ // The largest bar at the top, where reading starts; the values along the bottom from zero.
223
+ yAxis: { type: xType, ...(xType === "category" && categories ? { data: categories } : {}), inverse: true, name: input.xTitle, nameLocation: "start", nameGap: 8, axisLabel: { hideOverlap: true, ...(xType === "category" ? { interval: 0 } : {}) } },
224
+ xAxis: { ...valueAxis(input.yTitle, false), position: "bottom" },
225
+ }
226
+ : {
227
+ xAxis: {
228
+ type: xType,
229
+ ...(xType === "category" && categories ? { data: categories } : {}),
230
+ name: input.xTitle ?? (xType === "value" ? x : undefined),
231
+ nameLocation: "middle",
232
+ ...TITLE_CLEAR,
233
+ // A category axis tries every label (ECharts otherwise skips some on a guess) and hides only those that collide.
234
+ axisLabel: { hideOverlap: true, ...(xType === "category" ? { interval: 0 } : {}) },
235
+ },
236
+ yAxis: hasRight ? [valueAxis(input.yTitle, false), valueAxis(input.yRightTitle, true)] : valueAxis(input.yTitle, false),
237
+ }),
238
+ dataZoom: !zoom ? [] : sideways ? [{ type: "inside", yAxisIndex: 0 }, { type: "slider", yAxisIndex: 0, width: 18, right: 8 }] : [{ type: "inside" }, { type: "slider", height: 18, bottom: legend === "bottom" ? 32 : 8 }],
239
+ series,
240
+ };
241
+ }
242
+ /** A round bin width that splits [min, max] into about `bins` bins. */
243
+ export function niceBinWidth(min, max, bins) {
244
+ const span = max - min;
245
+ if (!(span > 0) || !(bins > 0))
246
+ return 1;
247
+ const rough = span / bins;
248
+ const power = 10 ** Math.floor(Math.log10(rough));
249
+ const step = [1, 2, 2.5, 5, 10].find((m) => m * power >= rough) ?? 10;
250
+ return step * power;
251
+ }
252
+ //# sourceMappingURL=option.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"option.js","sourceRoot":"","sources":["../../src/chart/option.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAc,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAyDnD;;;GAGG;AACH,MAAM,WAAW,GAAG,EAAE,OAAO,EAAE,CAAC,EAAE,eAAe,EAAE,IAAI,EAAW,CAAC;AAEnE,0FAA0F;AAC1F,MAAM,UAAU,eAAe,CAAC,IAAe,EAAE,MAAwD;IACvG,OAAO,MAAM,CAAC,MAAM,GAAG,CAAC,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,IAAI,IAAI,IAAI,CAAC,KAAK,KAAK,IAAI,CAAC,CAAC,IAAI,KAAK,OAAO,CAAC,CAAC;AACpG,CAAC;AAED,wFAAwF;AACxF,MAAM,UAAU,SAAS,CAAC,KAAwB;IAChD,IAAI,C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AAE,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;QAC1N,MAAM;KACP,CAAC;AACJ,CAAC;AAED,uEAAuE;AACvE,MAAM,UAAU,YAAY,CAAC,GAAW,EAAE,GAAW,EAAE,IAAY;IACjE,MAAM,IAAI,GAAG,GAAG,GAAG,GAAG,CAAC;IACvB,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,GAAG,CAAC,CAAC;QAAE,OAAO,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,GAAG,IAAI,CAAC;IAC1B,MAAM,KAAK,GAAG,EAAE,IAAI,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,MAAM,IAAI,GAAG,CAAC,CAAC,EAAE,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,GAAG,KAAK,IAAI,KAAK,CAAC,IAAI,EAAE,CAAC;IACtE,OAAO,IAAI,GAAG,KAAK,CAAC;AACtB,CAAC","sourcesContent":["import { DataType, type Field } from \"apache-arrow\";\nimport { numberFormat } from \"../locale/locale.js\";\n\nexport type ChartType = \"bar\" | \"line\" | \"area\" | \"scatter\" | \"pie\";\n/** How one series is drawn. A chart whose series differ is a compound chart. */\nexport type SeriesType = Exclude<ChartType, \"pie\">;\nexport type LegendPlacement = \"top\" | \"bottom\" | \"right\" | \"none\";\n\nexport interface ChartSpecSeries {\n /** Output column holding the values. */\n column: string;\n /** Name shown in the legend and tooltip. */\n label: string;\n /** Draw this series as something other than the chart's type, e.g. a line over bars. */\n type?: SeriesType;\n /** The y axis this series is measured on. Defaults to \"left\". */\n axis?: \"left\" | \"right\";\n /** Series with the same stack name are stacked on each other. */\n stack?: string;\n /** Draw this series in this colour instead of the next one in the theme's order. */\n color?: string;\n}\n\nexport interface ChartOptionInput {\n type: ChartType;\n /** Column for the x axis (or the slice names of a pie). */\n x: string;\n series: ChartSpecSeries[];\n /** Column whose distinct values split each measure into separate series. */\n splitBy?: string;\n fields: Field[];\n /** Rows as plain chart values, keyed by column. */\n rows: Record<string, string | number | null>[];\n /** Where the legend goes. Defaults to \"top\" when there is more than one series, otherwise \"none\". */\n legend?: LegendPlacement;\n /** Stack every series that has no stack name of its own. */\n stacked?: boolean;\n /** Colours for particular values of the split column, by value. */\n splitColors?: Record<string, string>;\n /** Axis titles. */\n xTitle?: string;\n yTitle?: string;\n yRightTitle?: string;\n /** How the left axis writes its numbers. Changes the labels only, never the values. */\n yFormat?: AxisFormat;\n /**\n * \"value\" puts categories in order of size, largest first, unless x is a\n * date or number, whose own order is kept. \"x\" keeps the rows as given.\n */\n sort?: \"value\" | \"x\";\n /**\n * Bars run across instead of up: the categories go down the left side,\n * largest at the top, and the values along the bottom. Applies only when\n * every series is a bar on one scale; otherwise it is ignored.\n */\n horizontal?: boolean;\n}\n\n/**\n * An axis title sits a fixed gap beyond the tick labels, wherever they end. A gap measured from the axis line\n * suits one width of label only: beside two-digit ticks the title ran off the chart's edge.\n */\nconst TITLE_CLEAR = { nameGap: 8, nameMoveOverlap: true } as const;\n\n/** True when a chart of this shape can be turned on its side: bars only, on one scale. */\nexport function canTurnSideways(type: ChartType, series: { type?: SeriesType; axis?: \"left\" | \"right\" }[]): boolean {\n return series.length > 0 && series.every((s) => (s.type ?? type) === \"bar\" && s.axis !== \"right\");\n}\n\n/** True when a column's values have an order of their own: dates, times and numbers. */\nexport function isOrdered(field: Field | undefined): boolean {\n if (!field) return false;\n return DataType.isTimestamp(field.type) || DataType.isDate(field.type) || DataType.isInt(field.type) || DataType.isFloat(field.type) || DataType.isDecimal(field.type);\n}\n\n/**\n * The order categories are drawn in when sorted by size: by the total of the\n * first measure across every series, largest first. Sorting by the total\n * keeps a stacked or grouped chart in one order for all its series.\n */\nexport function categoriesBySize(rows: Record<string, string | number | null>[], x: string, measure: string): string[] {\n const totals = new Map<string, number>();\n for (const row of rows) {\n const key = String(row[x] ?? \"null\");\n totals.set(key, (totals.get(key) ?? 0) + (Number(row[measure]) || 0));\n }\n return [...totals.entries()].sort((a, b) => b[1] - a[1]).map(([key]) => key);\n}\n\ntype AxisType = \"category\" | \"time\" | \"value\";\n\nfunction axisType(field: Field | undefined, scatter: boolean): AxisType {\n if (!field) return \"category\";\n if (DataType.isTimestamp(field.type) || DataType.isDate(field.type)) return \"time\";\n const numeric = DataType.isInt(field.type) || DataType.isFloat(field.type) || DataType.isDecimal(field.type);\n return numeric && scatter ? \"value\" : \"category\";\n}\n\nconst compact = () => numberFormat({ notation: \"compact\", maximumFractionDigits: 1 });\nconst fraction = () => numberFormat({ maximumSignificantDigits: 2 });\n/** A number on an axis: 12K, 1.5M, and for a value under one enough digits to tell the ticks apart (0.02, not 0). */\nexport const axisNumber = (value: number) => (value !== 0 && Math.abs(value) < 1 ? fraction().format(value) : compact().format(value));\n\nexport type AxisFormat = \"number\" | \"compact\" | \"currency\" | \"percent\";\nconst percent = () => numberFormat({ style: \"percent\", maximumSignificantDigits: 2 });\nconst money = () => numberFormat({ style: \"currency\", currency: \"USD\", notation: \"compact\", maximumSignificantDigits: 3 });\n/** A number on an axis in a measure's own format: 6% rather than 0.06, $1.2M rather than 1.2M. */\nexport const axisFormatter = (format: AxisFormat | undefined): ((value: number) => string) =>\n format === \"percent\" ? (value) => percent().format(value) : format === \"currency\" ? (value) => money().format(value) : axisNumber;\n\nconst exactPercent = () => numberFormat({ style: \"percent\", maximumFractionDigits: 1 });\nconst exactMoney = () => numberFormat({ style: \"currency\", currency: \"USD\", maximumFractionDigits: 2 });\nconst exact = () => numberFormat({ maximumFractionDigits: 2 });\n/**\n * A value in a tooltip, where a person reads one number closely: in full rather than compact, rounded to what can be\n * told apart (6.1%, $1,234.50, 1,234.57, 0.0123), in the measure's own format. Changes the text only, never the value.\n */\nexport const tooltipFormatter =\n (format: AxisFormat | undefined) =>\n (value: unknown): string => {\n const n = typeof value === \"number\" ? value : Number(value);\n if (value == null || value === \"\" || !Number.isFinite(n)) return value == null ? \"–\" : String(value);\n if (format === \"percent\") return exactPercent().format(n);\n if (format === \"currency\") return exactMoney().format(n);\n return n !== 0 && Math.abs(n) < 1 ? fraction().format(n) : exact().format(n);\n };\n\nfunction legendOption(placement: LegendPlacement): Record<string, unknown> {\n if (placement === \"none\") return { show: false };\n if (placement === \"right\") return { type: \"scroll\", orient: \"vertical\", right: 0, top: \"middle\" };\n return { type: \"scroll\", [placement]: 0 };\n}\n\n/**\n * True when the last points of every series are far enough apart for a label\n * at each end to be read. Lines that finish close together keep the legend.\n */\nfunction endsApart(series: Record<string, unknown>[], dataset: unknown, rows: Record<string, string | number | null>[]): boolean {\n const sets = Array.isArray(dataset) ? (dataset as { source?: Record<string, string | number | null>[] }[]) : undefined;\n const ends: number[] = [];\n let low = Infinity;\n let high = -Infinity;\n for (const item of series) {\n const column = (item.encode as { y: string }).y;\n const source = sets ? (sets[item.datasetIndex as number]?.source ?? []) : rows;\n const values = source.map((row) => Number(row[column])).filter((v) => Number.isFinite(v));\n if (values.length === 0) return false;\n ends.push(values.at(-1)!);\n low = Math.min(low, ...values);\n high = Math.max(high, ...values);\n }\n const room = (high - Math.min(low, 0)) * 0.08;\n const sorted = [...ends].sort((a, b) => a - b);\n return sorted.every((value, i) => i === 0 || value - sorted[i - 1]! >= room);\n}\n\n/**\n * The rows a chart cannot place: those with no x, on a time or number axis. (A category axis draws them under\n * \"null\".) They are left out of the option whole, since a point that is not drawn must not size the y axis:\n * a count of the rows with no date would otherwise flatten the line of every week that has one.\n */\nexport function rowsWithoutX(input: Pick<ChartOptionInput, \"type\" | \"x\" | \"series\" | \"fields\" | \"rows\">): ChartOptionInput[\"rows\"] {\n if (input.type === \"pie\") return [];\n const kinds = input.series.map((s) => s.type ?? input.type);\n const xType = axisType(input.fields.find((f) => f.name === input.x), kinds.every((k) => k === \"scatter\"));\n return xType === \"category\" ? [] : input.rows.filter((row) => row[input.x] == null);\n}\n\n/**\n * Builds an ECharts option from query rows. Pure, so it can be tested and\n * reused on a server or by an agent. Colours and fonts come from the theme\n * passed to `echarts.init`, not from here.\n */\nexport function buildChartOption(given: ChartOptionInput): Record<string, unknown> {\n const unplaced = rowsWithoutX(given);\n const input = unplaced.length > 0 ? { ...given, rows: given.rows.filter((row) => row[given.x] != null) } : given;\n const { type, x, splitBy } = input;\n const xField = input.fields.find((f) => f.name === x);\n // A date or number axis is drawn in its own order, whatever order the rows arrived in.\n const byX = type !== \"pie\" && isOrdered(xField) && input.sort === \"value\";\n // A missing category is drawn under its own name rather than dropped from the axis.\n const named = type !== \"pie\" && input.sort === \"value\" && !isOrdered(xField) ? input.rows.map((row) => (row[x] == null ? { ...row, [x]: \"null\" } : row)) : input.rows;\n const rows = byX ? [...input.rows].sort((a, b) => (typeof a[x] === \"number\" && typeof b[x] === \"number\" ? a[x] - b[x] : String(a[x]).localeCompare(String(b[x])))) : named;\n\n if (type === \"pie\") {\n const measure = input.series[0];\n return {\n tooltip: { trigger: \"item\", valueFormatter: tooltipFormatter(input.yFormat) },\n legend: legendOption(input.legend ?? \"bottom\"),\n series: [\n {\n type: \"pie\",\n name: measure?.label ?? \"\",\n radius: [\"45%\", \"72%\"],\n center: [\"50%\", \"45%\"],\n label: { show: rows.length <= 8 },\n data: measure ? rows.map((row) => ({ name: String(row[x] ?? \"null\"), value: row[measure.column] })) : [],\n },\n ],\n };\n }\n\n const kinds = input.series.map((s) => s.type ?? type);\n const xType = axisType(xField, kinds.every((k) => k === \"scatter\"));\n const sideways = !!input.horizontal && canTurnSideways(type, input.series);\n // On its side, the category axis is the vertical one and the value axis the horizontal one.\n const at = (category: string, value: string) => (sideways ? { x: value, y: category } : { x: category, y: value });\n const large = rows.length > 2000 ? { large: true, sampling: \"lttb\", showSymbol: false } : {};\n const hasRight = input.series.some((s) => s.axis === \"right\");\n const shape = (measure: ChartSpecSeries): Record<string, unknown> => {\n const kind = measure.type ?? type;\n const stack = measure.stack ?? (input.stacked && kind !== \"scatter\" ? `stack-${measure.axis ?? \"left\"}-${kind}` : undefined);\n return {\n type: kind === \"area\" ? \"line\" : kind,\n ...(kind === \"area\" ? { areaStyle: { opacity: 0.18 }, showSymbol: false } : {}),\n ...(stack ? { stack } : {}),\n ...(hasRight ? { yAxisIndex: measure.axis === \"right\" ? 1 : 0 } : {}),\n tooltip: { valueFormatter: tooltipFormatter(measure.axis === \"right\" ? undefined : input.yFormat) },\n ...large,\n };\n };\n const painted = (color: string | undefined) => (color ? { itemStyle: { color }, lineStyle: { color } } : {});\n\n let series: Record<string, unknown>[];\n let dataset: Record<string, unknown> | Record<string, unknown>[];\n if (splitBy) {\n // One dataset per distinct value of the split column, one series per (value, measure).\n const groups = new Map<string, Record<string, string | number | null>[]>();\n for (const row of rows) {\n const key = String(row[splitBy] ?? \"null\");\n const group = groups.get(key);\n if (group) group.push(row);\n else groups.set(key, [row]);\n }\n const keys = [...groups.keys()];\n dataset = keys.map((key) => ({ source: groups.get(key) }));\n series = keys.flatMap((key, datasetIndex) =>\n input.series.map((measure) => ({\n ...shape(measure),\n ...painted(input.splitColors?.[key]),\n name: input.series.length > 1 ? `${key} · ${measure.label}` : key,\n datasetIndex,\n encode: at(x, measure.column),\n })),\n );\n } else {\n dataset = { source: rows };\n series = input.series.map((measure) => ({ ...shape(measure), ...painted(measure.color), name: measure.label, encode: at(x, measure.column) }));\n }\n\n // Up to four lines are named at their ends, where the eye already is, instead of in a legend.\n const direct =\n input.legend === undefined && series.length >= 2 && series.length <= 4 && kinds.every((k) => k === \"line\") && !input.stacked && !hasRight && endsApart(series, dataset, rows);\n if (direct) series = series.map((s) => ({ ...s, endLabel: { show: true, formatter: \"{a}\", distance: 6 }, labelLayout: { moveOverlap: \"shiftY\" } }));\n const legend = input.legend ?? (direct ? \"none\" : series.length > 1 ? \"top\" : \"none\");\n const categories = input.sort === \"value\" && !isOrdered(xField) && input.series[0] ? categoriesBySize(rows, x, input.series[0].column) : undefined;\n // A zoom bar earns its space only when there are too many points to read at once.\n const zoom = new Set(rows.map((row) => row[x])).size > 60;\n const valueAxis = (name: string | undefined, right: boolean) => ({\n type: \"value\",\n name,\n nameLocation: \"middle\",\n ...TITLE_CLEAR,\n position: right ? \"right\" : \"left\",\n // A second axis has its own scale, so its grid lines would not line up with the first.\n splitLine: { show: !right },\n axisLabel: { formatter: right ? axisNumber : axisFormatter(input.yFormat) },\n });\n return {\n // Times come from the engine in UTC (a month bucket is midnight UTC on the 1st). Drawn in the\n // viewer's own zone they would land on the last day of the month before.\n useUTC: true,\n dataset,\n // The margins are what is left around the plot, its tick labels and its axis titles together: the plot shrinks\n // until all three fit, however wide the tick labels turn out to be.\n grid: {\n left: 8,\n right: legend === \"right\" ? 140 : direct ? 96 : 16,\n top: legend === \"top\" ? 36 : 16,\n bottom: (zoom && !sideways ? 40 : 8) + (legend === \"bottom\" ? 28 : 0),\n outerBoundsMode: \"same\",\n outerBoundsContain: \"all\",\n },\n tooltip: { trigger: kinds.every((k) => k === \"scatter\") ? \"item\" : \"axis\" },\n legend: legendOption(legend),\n ...(sideways\n ? {\n // The largest bar at the top, where reading starts; the values along the bottom from zero.\n yAxis: { type: xType, ...(xType === \"category\" && categories ? { data: categories } : {}), inverse: true, name: input.xTitle, nameLocation: \"start\", nameGap: 8, axisLabel: { hideOverlap: true, ...(xType === \"category\" ? { interval: 0 } : {}) } },\n xAxis: { ...valueAxis(input.yTitle, false), position: \"bottom\" },\n }\n : {\n xAxis: {\n type: xType,\n ...(xType === \"category\" && categories ? { data: categories } : {}),\n name: input.xTitle ?? (xType === \"value\" ? x : undefined),\n nameLocation: \"middle\",\n ...TITLE_CLEAR,\n // A category axis tries every label (ECharts otherwise skips some on a guess) and hides only those that collide.\n axisLabel: { hideOverlap: true, ...(xType === \"category\" ? { interval: 0 } : {}) },\n },\n yAxis: hasRight ? [valueAxis(input.yTitle, false), valueAxis(input.yRightTitle, true)] : valueAxis(input.yTitle, false),\n }),\n dataZoom: !zoom ? [] : sideways ? [{ type: \"inside\", yAxisIndex: 0 }, { type: \"slider\", yAxisIndex: 0, width: 18, right: 8 }] : [{ type: \"inside\" }, { type: \"slider\", height: 18, bottom: legend === \"bottom\" ? 32 : 8 }],\n series,\n };\n}\n\n/** A round bin width that splits [min, max] into about `bins` bins. */\nexport function niceBinWidth(min: number, max: number, bins: number): number {\n const span = max - min;\n if (!(span > 0) || !(bins > 0)) return 1;\n const rough = span / bins;\n const power = 10 ** Math.floor(Math.log10(rough));\n const step = [1, 2, 2.5, 5, 10].find((m) => m * power >= rough) ?? 10;\n return step * power;\n}\n"]}
@@ -0,0 +1,39 @@
1
+ /** One suggestion in a `Combobox`. */
2
+ export interface ComboboxOption {
3
+ /** What choosing it puts in the box, and what `onPick` reports: an email, an id. */
4
+ value: string;
5
+ /** The words shown for it: a name. */
6
+ label: string;
7
+ /** A second line: the email under a name. */
8
+ detail?: string;
9
+ }
10
+ export interface ComboboxProps {
11
+ /** The field's name, shown above it. */
12
+ label: string;
13
+ /** The text in the box. The host holds it. */
14
+ value: string;
15
+ /** Every change to the text, typed or chosen. Search with it and pass back what matches as `options`. */
16
+ onChange(value: string): void;
17
+ /** The suggestions for the text as it is now, best first. The box does not filter them. */
18
+ options: readonly ComboboxOption[];
19
+ /** A suggestion was chosen; `onChange` has already had its value. */
20
+ onPick?(option: ComboboxOption): void;
21
+ /** Suggestions are being fetched. */
22
+ loading?: boolean;
23
+ /** The input's type: "text" (the default), "email" or "search". */
24
+ type?: "text" | "email" | "search";
25
+ placeholder?: string;
26
+ required?: boolean;
27
+ disabled?: boolean;
28
+ /** The input's name, when a form reads it. */
29
+ name?: string;
30
+ /** A sentence under the field. */
31
+ help?: string;
32
+ className?: string;
33
+ }
34
+ /**
35
+ * A text box that suggests as a person types: a person to hand work to, a table, a tag. Anything may be typed; a
36
+ * suggestion is a shortcut. The host searches (on its server, for a long list) and passes the matches in. The ARIA
37
+ * 1.2 combobox: Down and Up move through the list, Enter chooses, Escape closes it and then clears the box.
38
+ */
39
+ export declare function Combobox(props: ComboboxProps): import("react").JSX.Element;
@@ -0,0 +1,75 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { useEffect, useId, useRef, useState } from "react";
3
+ import { numberFormat, label as text } from "../locale/locale.js";
4
+ /**
5
+ * A text box that suggests as a person types: a person to hand work to, a table, a tag. Anything may be typed; a
6
+ * suggestion is a shortcut. The host searches (on its server, for a long list) and passes the matches in. The ARIA
7
+ * 1.2 combobox: Down and Up move through the list, Enter chooses, Escape closes it and then clears the box.
8
+ */
9
+ export function Combobox(props) {
10
+ const { label, value, onChange, options, onPick, loading, type = "text", placeholder, required, disabled, name, help, className } = props;
11
+ const id = useId();
12
+ const listId = `${id}-list`;
13
+ const helpId = `${id}-help`;
14
+ const [open, setOpen] = useState(false);
15
+ const [active, setActive] = useState(-1);
16
+ const box = useRef(null);
17
+ const shown = open && (options.length > 0 || loading || value.trim() !== "");
18
+ // New suggestions start with none of them active, so Enter keeps what was typed. Compared by value, so a host that
19
+ // builds a fresh array on every render does not lose the person's place.
20
+ const listed = options.map((option) => option.value).join("\n");
21
+ // biome-ignore lint/correctness/useExhaustiveDependencies: reset when the suggestions themselves change.
22
+ useEffect(() => setActive(-1), [listed]);
23
+ const pick = (option) => {
24
+ onChange(option.value);
25
+ onPick?.(option);
26
+ setOpen(false);
27
+ setActive(-1);
28
+ };
29
+ const onKeyDown = (event) => {
30
+ if (event.key === "ArrowDown") {
31
+ event.preventDefault();
32
+ if (!open)
33
+ setOpen(true);
34
+ else if (options.length > 0)
35
+ setActive((at) => (at + 1) % options.length);
36
+ }
37
+ else if (event.key === "ArrowUp") {
38
+ event.preventDefault();
39
+ if (!open)
40
+ setOpen(true);
41
+ else if (options.length > 0)
42
+ setActive((at) => (at <= 0 ? options.length - 1 : at - 1));
43
+ }
44
+ else if (event.key === "Enter") {
45
+ const option = open ? options[active] : undefined;
46
+ if (option) {
47
+ event.preventDefault();
48
+ pick(option);
49
+ }
50
+ }
51
+ else if (event.key === "Escape") {
52
+ if (open) {
53
+ event.preventDefault();
54
+ setOpen(false);
55
+ setActive(-1);
56
+ }
57
+ else if (value) {
58
+ event.preventDefault();
59
+ onChange("");
60
+ }
61
+ }
62
+ else if (event.key === "Tab") {
63
+ setOpen(false);
64
+ }
65
+ };
66
+ const count = options.length === 1 ? text("combobox.countOne") : text("combobox.count", { count: numberFormat().format(options.length) });
67
+ return (_jsxs("div", { ref: box, className: ["sf-combobox", className].filter(Boolean).join(" "), onBlur: (event) => {
68
+ if (!box.current?.contains(event.relatedTarget))
69
+ setOpen(false);
70
+ }, children: [_jsx("label", { className: "sf-combobox-label", htmlFor: `${id}-input`, children: label }), _jsx("input", { id: `${id}-input`, className: "sf-input", type: type, role: "combobox", "aria-expanded": shown, "aria-controls": listId, "aria-autocomplete": "list", "aria-activedescendant": shown && active >= 0 ? `${id}-option-${active}` : undefined, "aria-describedby": help ? helpId : undefined, autoComplete: "off", value: value, name: name, placeholder: placeholder, required: required, disabled: disabled, onChange: (event) => {
71
+ onChange(event.target.value);
72
+ setOpen(true);
73
+ }, onFocus: () => setOpen(true), onClick: () => setOpen(true), onKeyDown: onKeyDown }), help && (_jsx("p", { id: helpId, className: "sf-combobox-help", children: help })), _jsxs("div", { className: "sf-combobox-popup", hidden: !shown, children: [_jsx("ul", { id: listId, role: "listbox", "aria-label": label, className: "sf-combobox-list", hidden: options.length === 0, children: options.map((option, index) => (_jsxs("li", { id: `${id}-option-${index}`, role: "option", "aria-selected": index === active, className: "sf-combobox-option", onMouseDown: (event) => event.preventDefault(), onClick: () => pick(option), onMouseMove: () => setActive(index), children: [_jsx("span", { children: option.label }), option.detail && _jsx("span", { className: "sf-combobox-detail", children: option.detail })] }, option.value))) }), options.length === 0 && _jsx("p", { className: "sf-combobox-note", children: loading ? text("combobox.loading") : text("combobox.none") })] }), _jsx("span", { className: "sf-visually-hidden", "aria-live": "polite", children: shown && !loading ? (options.length > 0 ? count : text("combobox.none")) : "" })] }));
74
+ }
75
+ //# sourceMappingURL=Combobox.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Combobox.js","sourceRoot":"","sources":["../../src/controls/Combobox.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAsB,SAAS,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC/E,OAAO,EAAE,YAAY,EAAE,KAAK,IAAI,IAAI,EAAE,MAAM,qBAAqB,CAAC;AAqClE;;;;GAIG;AACH,MAAM,UAAU,QAAQ,CAAC,KAAoB;IAC3C,MAAM,EAAE,KAAK,EAAE,KAAK,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,GAAG,MAAM,EAAE,WAAW,EAAE,QAAQ,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC;IAC1I,MAAM,EAAE,GAAG,KAAK,EAAE,CAAC;IACnB,MAAM,MAAM,GAAG,GAAG,EAAE,OAAO,CAAC;IAC5B,MAAM,MAAM,GAAG,GAAG,EAAE,OAAO,CAAC;IAC5B,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IACxC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,MAAM,GAAG,GAAG,MAAM,CAAiB,IAAI,CAAC,CAAC;IACzC,MAAM,KAAK,GAAG,IAAI,IAAI,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,IAAI,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,CAAC,CAAC;IAE7E,mHAAmH;IACnH,yEAAyE;IACzE,MAAM,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC,IAAI,CAA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AAE,WAAW,KAAK,EAAE,EAC3B,IAAI,EAAC,QAAQ,mBACE,KAAK,KAAK,MAAM,EAC/B,SAAS,EAAC,oBAAoB,EAC9B,WAAW,EAAE,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,cAAc,EAAE,EAC9C,OAAO,EAAE,GAAG,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,EAC3B,WAAW,EAAE,GAAG,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,aAEnC,yBAAO,MAAM,CAAC,KAAK,GAAQ,EAC1B,MAAM,CAAC,MAAM,IAAI,eAAM,SAAS,EAAC,oBAAoB,YAAE,MAAM,CAAC,MAAM,GAAQ,KAVxE,MAAM,CAAC,KAAK,CAWd,CACN,CAAC,GACC,EACJ,OAAO,CAAC,MAAM,KAAK,CAAC,IAAI,YAAG,SAAS,EAAC,kBAAkB,YAAE,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,GAAK,IACrH,EACN,eAAM,SAAS,EAAC,oBAAoB,eAAW,QAAQ,YACpD,KAAK,IAAI,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,IAAI,CAAC,eAAe,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,GACzE,IACH,CACP,CAAC;AACJ,CAAC","sourcesContent":["import { type KeyboardEvent, useEffect, useId, useRef, useState } from \"react\";\nimport { numberFormat, label as text } from \"../locale/locale.js\";\n\n/** One suggestion in a `Combobox`. */\nexport interface ComboboxOption {\n /** What choosing it puts in the box, and what `onPick` reports: an email, an id. */\n value: string;\n /** The words shown for it: a name. */\n label: string;\n /** A second line: the email under a name. */\n detail?: string;\n}\n\nexport interface ComboboxProps {\n /** The field's name, shown above it. */\n label: string;\n /** The text in the box. The host holds it. */\n value: string;\n /** Every change to the text, typed or chosen. Search with it and pass back what matches as `options`. */\n onChange(value: string): void;\n /** The suggestions for the text as it is now, best first. The box does not filter them. */\n options: readonly ComboboxOption[];\n /** A suggestion was chosen; `onChange` has already had its value. */\n onPick?(option: ComboboxOption): void;\n /** Suggestions are being fetched. */\n loading?: boolean;\n /** The input's type: \"text\" (the default), \"email\" or \"search\". */\n type?: \"text\" | \"email\" | \"search\";\n placeholder?: string;\n required?: boolean;\n disabled?: boolean;\n /** The input's name, when a form reads it. */\n name?: string;\n /** A sentence under the field. */\n help?: string;\n className?: string;\n}\n\n/**\n * A text box that suggests as a person types: a person to hand work to, a table, a tag. Anything may be typed; a\n * suggestion is a shortcut. The host searches (on its server, for a long list) and passes the matches in. The ARIA\n * 1.2 combobox: Down and Up move through the list, Enter chooses, Escape closes it and then clears the box.\n */\nexport function Combobox(props: ComboboxProps) {\n const { label, value, onChange, options, onPick, loading, type = \"text\", placeholder, required, disabled, name, help, className } = props;\n const id = useId();\n const listId = `${id}-list`;\n const helpId = `${id}-help`;\n const [open, setOpen] = useState(false);\n const [active, setActive] = useState(-1);\n const box = useRef<HTMLDivElement>(null);\n const shown = open && (options.length > 0 || loading || value.trim() !== \"\");\n\n // New suggestions start with none of them active, so Enter keeps what was typed. Compared by value, so a host that\n // builds a fresh array on every render does not lose the person's place.\n const listed = options.map((option) => option.value).join(\"\\n\");\n // biome-ignore lint/correctness/useExhaustiveDependencies: reset when the suggestions themselves change.\n useEffect(() => setActive(-1), [listed]);\n\n const pick = (option: ComboboxOption) => {\n onChange(option.value);\n onPick?.(option);\n setOpen(false);\n setActive(-1);\n };\n const onKeyDown = (event: KeyboardEvent<HTMLInputElement>) => {\n if (event.key === \"ArrowDown\") {\n event.preventDefault();\n if (!open) setOpen(true);\n else if (options.length > 0) setActive((at) => (at + 1) % options.length);\n } else if (event.key === \"ArrowUp\") {\n event.preventDefault();\n if (!open) setOpen(true);\n else if (options.length > 0) setActive((at) => (at <= 0 ? options.length - 1 : at - 1));\n } else if (event.key === \"Enter\") {\n const option = open ? options[active] : undefined;\n if (option) {\n event.preventDefault();\n pick(option);\n }\n } else if (event.key === \"Escape\") {\n if (open) {\n event.preventDefault();\n setOpen(false);\n setActive(-1);\n } else if (value) {\n event.preventDefault();\n onChange(\"\");\n }\n } else if (event.key === \"Tab\") {\n setOpen(false);\n }\n };\n const count = options.length === 1 ? text(\"combobox.countOne\") : text(\"combobox.count\", { count: numberFormat().format(options.length) });\n\n return (\n <div\n ref={box}\n className={[\"sf-combobox\", className].filter(Boolean).join(\" \")}\n onBlur={(event) => {\n if (!box.current?.contains(event.relatedTarget as Node | null)) setOpen(false);\n }}\n >\n <label className=\"sf-combobox-label\" htmlFor={`${id}-input`}>\n {label}\n </label>\n <input\n id={`${id}-input`}\n className=\"sf-input\"\n type={type}\n role=\"combobox\"\n aria-expanded={shown}\n aria-controls={listId}\n aria-autocomplete=\"list\"\n aria-activedescendant={shown && active >= 0 ? `${id}-option-${active}` : undefined}\n aria-describedby={help ? helpId : undefined}\n autoComplete=\"off\"\n value={value}\n name={name}\n placeholder={placeholder}\n required={required}\n disabled={disabled}\n onChange={(event) => {\n onChange(event.target.value);\n setOpen(true);\n }}\n onFocus={() => setOpen(true)}\n onClick={() => setOpen(true)}\n onKeyDown={onKeyDown}\n />\n {help && (\n <p id={helpId} className=\"sf-combobox-help\">\n {help}\n </p>\n )}\n <div className=\"sf-combobox-popup\" hidden={!shown}>\n {/* An empty listbox is not allowed; with no suggestions the popup says why instead. */}\n <ul id={listId} role=\"listbox\" aria-label={label} className=\"sf-combobox-list\" hidden={options.length === 0}>\n {options.map((option, index) => (\n <li\n key={option.value}\n id={`${id}-option-${index}`}\n role=\"option\"\n aria-selected={index === active}\n className=\"sf-combobox-option\"\n onMouseDown={(event) => event.preventDefault()}\n onClick={() => pick(option)}\n onMouseMove={() => setActive(index)}\n >\n <span>{option.label}</span>\n {option.detail && <span className=\"sf-combobox-detail\">{option.detail}</span>}\n </li>\n ))}\n </ul>\n {options.length === 0 && <p className=\"sf-combobox-note\">{loading ? text(\"combobox.loading\") : text(\"combobox.none\")}</p>}\n </div>\n <span className=\"sf-visually-hidden\" aria-live=\"polite\">\n {shown && !loading ? (options.length > 0 ? count : text(\"combobox.none\")) : \"\"}\n </span>\n </div>\n );\n}\n"]}
@@ -0,0 +1,35 @@
1
+ import { type ReactNode } from "react";
2
+ export interface ConfirmDialogProps {
3
+ /** Whether the dialog is showing. */
4
+ open: boolean;
5
+ /** The question, as a heading: "Turn off 5 accounts?" */
6
+ title: string;
7
+ /** What will happen, and what cannot be undone. */
8
+ body?: ReactNode;
9
+ /** The button that goes ahead, named for what it does: "Turn off", not "OK". Defaults to "Confirm". */
10
+ confirmLabel?: string;
11
+ /** Defaults to "Cancel". */
12
+ cancelLabel?: string;
13
+ /** For something that takes away or cannot be undone: the button is marked, and Cancel has focus first. */
14
+ danger?: boolean;
15
+ onConfirm(): void;
16
+ /** Cancel, Escape, or a press outside the dialog. */
17
+ onCancel(): void;
18
+ className?: string;
19
+ }
20
+ /**
21
+ * Asks a person to confirm one action before it runs, as a modal dialog: the page behind cannot be used, focus starts
22
+ * inside it and returns where it was, and Escape cancels. Name the button for the action. For something that can be
23
+ * undone, prefer doing it and offering Undo (`ActionReceipt`). `useConfirm` asks from code and waits for the answer.
24
+ */
25
+ export declare function ConfirmDialog({ open, title, body, confirmLabel, cancelLabel, danger, onConfirm, onCancel, className }: ConfirmDialogProps): import("react").JSX.Element | null;
26
+ /** What `useConfirm`'s `confirm` asks. */
27
+ export type ConfirmRequest = Omit<ConfirmDialogProps, "open" | "onConfirm" | "onCancel">;
28
+ export interface Confirm {
29
+ /** Shows the dialog and resolves true if the person goes ahead, false if not. Asking again while one is open answers the first with false. */
30
+ confirm(request: ConfirmRequest): Promise<boolean>;
31
+ /** Render this once, anywhere in the component. */
32
+ element: ReactNode;
33
+ }
34
+ /** Asks for confirmation from an event handler: `if (await confirm({ title, body, confirmLabel, danger })) run()`. */
35
+ export declare function useConfirm(): Confirm;