cortena-ui 1.4.0 → 1.4.2
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.
- package/dist/a2ui/catalogue-doc.d.ts +1 -13
- package/dist/a2ui/index.d.ts +2 -2
- package/dist/a2ui.d.ts +2 -2
- package/dist/a2ui.js +1 -2
- package/dist/chart.d.ts +2 -2
- package/dist/chart.js +1 -2
- package/dist/components/chart/chart.js +2 -1
- package/dist/components/chart/chart.js.map +1 -1
- package/dist/components/chart/index.d.ts +2 -2
- package/dist/components/chart/index.js +1 -2
- package/dist/components/chart/nivo-theme.d.ts +0 -16
- package/dist/components/chart/recharts-charts.js +2 -1
- package/dist/components/chart/recharts-charts.js.map +1 -1
- package/dist/index.d.ts +3 -3
- package/dist/index.js +1 -3
- package/package.json +1 -1
- package/src/a2ui/index.ts +6 -1
- package/src/components/chart/chart.tsx +1 -0
- package/src/components/chart/index.tsx +4 -1
- package/src/components/chart/recharts-charts.tsx +8 -0
- package/dist/a2ui/catalogue-doc.js +0 -169
- package/dist/a2ui/catalogue-doc.js.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use client";
|
|
2
2
|
import { A2UIComponentSpec } from "./message.js";
|
|
3
|
-
import {
|
|
3
|
+
import { A2UIGroup } from "./catalogue.js";
|
|
4
4
|
//#region src/a2ui/catalogue-doc.d.ts
|
|
5
5
|
/** A JSON Schema object, as far as this module cares. */
|
|
6
6
|
export type JsonSchema = Record<string, unknown>;
|
|
@@ -28,17 +28,5 @@ export interface A2UICatalogueDoc {
|
|
|
28
28
|
generator: string;
|
|
29
29
|
components: A2UIComponentDoc[];
|
|
30
30
|
}
|
|
31
|
-
/** Build the machine-readable catalogue document. */
|
|
32
|
-
export declare function buildCatalogueDoc(catalogue?: A2UICatalogue): A2UICatalogueDoc;
|
|
33
|
-
/**
|
|
34
|
-
* Render the catalogue document as markdown.
|
|
35
|
-
*
|
|
36
|
-
* The output is written to be pasted into a system prompt: one table per
|
|
37
|
-
* component listing every property with its type, whether it is required and
|
|
38
|
-
* what it means, then a fenced example an agent can copy.
|
|
39
|
-
*/
|
|
40
|
-
export declare function catalogueMarkdown(doc?: A2UICatalogueDoc): string;
|
|
41
|
-
/** Turn an entry's example into the messages an agent would actually send. */
|
|
42
|
-
export declare function exampleMessages(component: A2UIComponentDoc): unknown[];
|
|
43
31
|
//#endregion
|
|
44
32
|
//# sourceMappingURL=catalogue-doc.d.ts.map
|
package/dist/a2ui/index.d.ts
CHANGED
|
@@ -2,6 +2,6 @@
|
|
|
2
2
|
import { A2UIAction, A2UIActionSpec, A2UIBeginRendering, A2UIChildList, A2UIChildren, A2UIComponentSpec, A2UICreateSurface, A2UIDataBinding, A2UIDeleteSurface, A2UIFoldResult, A2UIMessage, A2UIMessageInput, A2UIPropertyValue, A2UISurface, A2UIUpdateComponents, A2UIUpdateDataModel, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, foldMessages, getAtPointer, isDataBinding, parseA2UIMessages, pointerSegments, readAction, readChildren, readComponent, resolvePointer, resolveValue, setAtPointer } from "./message.js";
|
|
3
3
|
import { A2UIColumn, A2UIErrorCard, A2UINodeInfo, A2UIResolvedAction, A2UIRow, A2UITableSource, A2UIView, A2UIViewProps } from "./views.js";
|
|
4
4
|
import { A2UICatalogue, A2UICatalogueEntry, A2UIExample, A2UIGroup, A2UI_CATALOGUE_ID, catalogueNames, defaultCatalogue } from "./catalogue.js";
|
|
5
|
-
import { A2UICatalogueDoc, A2UIComponentDoc, JsonSchema
|
|
5
|
+
import { A2UICatalogueDoc, A2UIComponentDoc, JsonSchema } from "./catalogue-doc.js";
|
|
6
6
|
import { A2UIRenderer, A2UIRendererProps } from "./renderer.js";
|
|
7
|
-
export { type A2UIAction, type A2UIActionSpec, type A2UIBeginRendering, type A2UICatalogue, type A2UICatalogueDoc, type A2UICatalogueEntry, type A2UIChildList, type A2UIChildren, type A2UIColumn, type A2UIComponentDoc, type A2UIComponentSpec, type A2UICreateSurface, type A2UIDataBinding, type A2UIDeleteSurface, A2UIErrorCard, type A2UIExample, type A2UIFoldResult, type A2UIGroup, type A2UIMessage, type A2UIMessageInput, type A2UINodeInfo, type A2UIPropertyValue, A2UIRenderer, type A2UIRendererProps, type A2UIResolvedAction, type A2UIRow, type A2UISurface, type A2UITableSource, type A2UIUpdateComponents, type A2UIUpdateDataModel, type A2UIView, type A2UIViewProps, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, type JsonSchema,
|
|
7
|
+
export { type A2UIAction, type A2UIActionSpec, type A2UIBeginRendering, type A2UICatalogue, type A2UICatalogueDoc, type A2UICatalogueEntry, type A2UIChildList, type A2UIChildren, type A2UIColumn, type A2UIComponentDoc, type A2UIComponentSpec, type A2UICreateSurface, type A2UIDataBinding, type A2UIDeleteSurface, A2UIErrorCard, type A2UIExample, type A2UIFoldResult, type A2UIGroup, type A2UIMessage, type A2UIMessageInput, type A2UINodeInfo, type A2UIPropertyValue, A2UIRenderer, type A2UIRendererProps, type A2UIResolvedAction, type A2UIRow, type A2UISurface, type A2UITableSource, type A2UIUpdateComponents, type A2UIUpdateDataModel, type A2UIView, type A2UIViewProps, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, type JsonSchema, catalogueNames, defaultCatalogue, foldMessages, getAtPointer, isDataBinding, parseA2UIMessages, pointerSegments, readAction, readChildren, readComponent, resolvePointer, resolveValue, setAtPointer };
|
package/dist/a2ui.d.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import { A2UIAction, A2UIActionSpec, A2UIBeginRendering, A2UIChildList, A2UIChildren, A2UIComponentSpec, A2UICreateSurface, A2UIDataBinding, A2UIDeleteSurface, A2UIFoldResult, A2UIMessage, A2UIMessageInput, A2UIPropertyValue, A2UISurface, A2UIUpdateComponents, A2UIUpdateDataModel, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, foldMessages, getAtPointer, isDataBinding, parseA2UIMessages, pointerSegments, readAction, readChildren, readComponent, resolvePointer, resolveValue, setAtPointer } from "./a2ui/message.js";
|
|
3
3
|
import { A2UIColumn, A2UIErrorCard, A2UINodeInfo, A2UIResolvedAction, A2UIRow, A2UITableSource, A2UIView, A2UIViewProps } from "./a2ui/views.js";
|
|
4
4
|
import { A2UICatalogue, A2UICatalogueEntry, A2UIExample, A2UIGroup, A2UI_CATALOGUE_ID, catalogueNames, defaultCatalogue } from "./a2ui/catalogue.js";
|
|
5
|
-
import { A2UICatalogueDoc, A2UIComponentDoc, JsonSchema
|
|
5
|
+
import { A2UICatalogueDoc, A2UIComponentDoc, JsonSchema } from "./a2ui/catalogue-doc.js";
|
|
6
6
|
import { A2UIRenderer, A2UIRendererProps } from "./a2ui/renderer.js";
|
|
7
7
|
import "./a2ui/index.js";
|
|
8
|
-
export { type A2UIAction, type A2UIActionSpec, type A2UIBeginRendering, type A2UICatalogue, type A2UICatalogueDoc, type A2UICatalogueEntry, type A2UIChildList, type A2UIChildren, type A2UIColumn, type A2UIComponentDoc, type A2UIComponentSpec, type A2UICreateSurface, type A2UIDataBinding, type A2UIDeleteSurface, A2UIErrorCard, type A2UIExample, type A2UIFoldResult, type A2UIGroup, type A2UIMessage, type A2UIMessageInput, type A2UINodeInfo, type A2UIPropertyValue, A2UIRenderer, type A2UIRendererProps, type A2UIResolvedAction, type A2UIRow, type A2UISurface, type A2UITableSource, type A2UIUpdateComponents, type A2UIUpdateDataModel, type A2UIView, type A2UIViewProps, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, type JsonSchema,
|
|
8
|
+
export { type A2UIAction, type A2UIActionSpec, type A2UIBeginRendering, type A2UICatalogue, type A2UICatalogueDoc, type A2UICatalogueEntry, type A2UIChildList, type A2UIChildren, type A2UIColumn, type A2UIComponentDoc, type A2UIComponentSpec, type A2UICreateSurface, type A2UIDataBinding, type A2UIDeleteSurface, A2UIErrorCard, type A2UIExample, type A2UIFoldResult, type A2UIGroup, type A2UIMessage, type A2UIMessageInput, type A2UINodeInfo, type A2UIPropertyValue, A2UIRenderer, type A2UIRendererProps, type A2UIResolvedAction, type A2UIRow, type A2UISurface, type A2UITableSource, type A2UIUpdateComponents, type A2UIUpdateDataModel, type A2UIView, type A2UIViewProps, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, type JsonSchema, catalogueNames, defaultCatalogue, foldMessages, getAtPointer, isDataBinding, parseA2UIMessages, pointerSegments, readAction, readChildren, readComponent, resolvePointer, resolveValue, setAtPointer };
|
package/dist/a2ui.js
CHANGED
|
@@ -2,6 +2,5 @@
|
|
|
2
2
|
import { A2UIErrorCard } from "./a2ui/views.js";
|
|
3
3
|
import { A2UI_CATALOGUE_ID, catalogueNames, defaultCatalogue } from "./a2ui/catalogue.js";
|
|
4
4
|
import { A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, foldMessages, getAtPointer, isDataBinding, parseA2UIMessages, pointerSegments, readAction, readChildren, readComponent, resolvePointer, resolveValue, setAtPointer } from "./a2ui/message.js";
|
|
5
|
-
import { buildCatalogueDoc, catalogueMarkdown, exampleMessages } from "./a2ui/catalogue-doc.js";
|
|
6
5
|
import { A2UIRenderer } from "./a2ui/renderer.js";
|
|
7
|
-
export { A2UIErrorCard, A2UIRenderer, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION,
|
|
6
|
+
export { A2UIErrorCard, A2UIRenderer, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, catalogueNames, defaultCatalogue, foldMessages, getAtPointer, isDataBinding, parseA2UIMessages, pointerSegments, readAction, readChildren, readComponent, resolvePointer, resolveValue, setAtPointer };
|
package/dist/chart.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ import { ChartConfig, ChartDataFor, ChartDay, ChartEngine, ChartLabels, ChartMat
|
|
|
3
3
|
import { ChartContainer, ChartContainerProps, ChartEmpty, ChartError, ChartLegendContent, ChartLegendContentProps, ChartLoading, ChartTooltipContent, ChartTooltipContentProps, seriesColor, useChart } from "./components/chart/container.js";
|
|
4
4
|
import { Chart, ChartProps } from "./components/chart/chart.js";
|
|
5
5
|
import { ChartLegend, ChartTooltip } from "./components/chart/recharts-parts.js";
|
|
6
|
-
import { NivoTheme
|
|
6
|
+
import { NivoTheme } from "./components/chart/nivo-theme.js";
|
|
7
7
|
import { ChartScales, VIZ_SERIES_COUNT, chartScales, resolveColor, resolveVizSeries, toHex, vizSeriesVars, vizVar } from "./components/chart/tokens.js";
|
|
8
8
|
import { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, ComposedChart, Funnel, FunnelChart, LabelList, Line, LineChart, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Radar, RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, XAxis, YAxis } from "./components/chart/index.js";
|
|
9
|
-
export { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, Chart, type ChartConfig, ChartContainer, type ChartContainerProps, type ChartDataFor, type ChartDay, ChartEmpty, type ChartEngine, ChartError, type ChartLabels, ChartLegend, ChartLegendContent, type ChartLegendContentProps, ChartLoading, type ChartMatrix, type ChartPoint, type ChartProps, type ChartRenderer, type ChartRow, type ChartScale, type ChartScales, type ChartSeries, type ChartSlice, ChartTooltip, ChartTooltipContent, type ChartTooltipContentProps, type ChartTree, type ChartType, ComposedChart, Funnel, FunnelChart, LabelList, Line, LineChart, NIVO_TYPES, type NivoTheme, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, RECHARTS_TYPES, Radar, RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, VIZ_SERIES_COUNT, XAxis, YAxis, chartEngine, chartScales,
|
|
9
|
+
export { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, Chart, type ChartConfig, ChartContainer, type ChartContainerProps, type ChartDataFor, type ChartDay, ChartEmpty, type ChartEngine, ChartError, type ChartLabels, ChartLegend, ChartLegendContent, type ChartLegendContentProps, ChartLoading, type ChartMatrix, type ChartPoint, type ChartProps, type ChartRenderer, type ChartRow, type ChartScale, type ChartScales, type ChartSeries, type ChartSlice, ChartTooltip, ChartTooltipContent, type ChartTooltipContentProps, type ChartTree, type ChartType, ComposedChart, Funnel, FunnelChart, LabelList, Line, LineChart, NIVO_TYPES, type NivoTheme, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, RECHARTS_TYPES, Radar, RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, VIZ_SERIES_COUNT, XAxis, YAxis, chartEngine, chartScales, resolveColor, resolveVizSeries, seriesColor, toHex, useChart, vizSeriesVars, vizVar };
|
package/dist/chart.js
CHANGED
|
@@ -4,6 +4,5 @@ import { ChartContainer, ChartEmpty, ChartError, ChartLegendContent, ChartLoadin
|
|
|
4
4
|
import { NIVO_TYPES, RECHARTS_TYPES, chartEngine } from "./components/chart/types.js";
|
|
5
5
|
import { Chart } from "./components/chart/chart.js";
|
|
6
6
|
import { ChartLegend, ChartTooltip } from "./components/chart/recharts-parts.js";
|
|
7
|
-
import { nivoTheme, useNivoTheme } from "./components/chart/nivo-theme.js";
|
|
8
7
|
import { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, ComposedChart, Funnel, FunnelChart, LabelList, Line, LineChart, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Radar, RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, XAxis, YAxis } from "./components/chart/index.js";
|
|
9
|
-
export { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, Chart, ChartContainer, ChartEmpty, ChartError, ChartLegend, ChartLegendContent, ChartLoading, ChartTooltip, ChartTooltipContent, ComposedChart, Funnel, FunnelChart, LabelList, Line, LineChart, NIVO_TYPES, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, RECHARTS_TYPES, Radar, RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, VIZ_SERIES_COUNT, XAxis, YAxis, chartEngine, chartScales,
|
|
8
|
+
export { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, Chart, ChartContainer, ChartEmpty, ChartError, ChartLegend, ChartLegendContent, ChartLoading, ChartTooltip, ChartTooltipContent, ComposedChart, Funnel, FunnelChart, LabelList, Line, LineChart, NIVO_TYPES, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, RECHARTS_TYPES, Radar, RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, VIZ_SERIES_COUNT, XAxis, YAxis, chartEngine, chartScales, resolveColor, resolveVizSeries, seriesColor, toHex, useChart, vizSeriesVars, vizVar };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"chart.js","names":[],"sources":["../../../src/components/chart/chart.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { ChartContainer, ChartEmpty, ChartError, ChartLoading, type ChartContainerProps } from \"./container\";\nimport { configFor, isEmptyData, isMatrix, isSeriesArray, toRows, toSlices } from \"./data\";\nimport type { NivoType } from \"./nivo-charts\";\nimport { NivoChartLazy, resetNivoChunks } from \"./nivo-lazy\";\nimport type { RechartsType } from \"./recharts-charts\";\nimport { RechartsChartLazy, resetRechartsChunks } from \"./recharts-lazy\";\nimport {\n chartEngine,\n type ChartConfig,\n type ChartDataFor,\n type ChartLabels,\n type ChartMatrix,\n type ChartRenderer,\n type ChartRow,\n type ChartScale,\n type ChartSeries,\n type ChartSlice,\n type ChartTree,\n type ChartType,\n} from \"./types\";\n\nexport interface ChartProps<T extends ChartType = ChartType>\n extends Omit<ChartContainerProps, \"children\" | \"config\" | \"responsive\"> {\n /** Which chart to draw; the package picks the engine. See {@link ChartType} for the data shape per type. */\n type: T;\n /** The data, in the shape documented on {@link ChartType}. */\n data: ChartDataFor<T>;\n /** Series presentation keyed by series id; colours default to `--ds-viz-1..n` in order. */\n config?: ChartConfig;\n /** Nivo renderer; `canvas` for large series. Ignored by the Recharts types and by sunburst. */\n renderer?: ChartRenderer;\n /** Category key for row data (bar, line, area, radar); inferred as the first string field. */\n indexBy?: string;\n /** Series keys for row data; inferred as every numeric field. */\n keys?: string[];\n /** Stack bars and areas instead of grouping them. */\n stacked?: boolean;\n /** Continuous scale for heatmap and calendar. Default sequential. */\n scale?: ChartScale;\n /** Show a legend. Default: when there is more than one series. */\n legend?: boolean;\n /** Draw grid lines (cartesian and radar types). Default true. */\n grid?: boolean;\n /** Show a tooltip on hover. Default true. */\n tooltip?: boolean;\n /**\n * Per-arc labels for `pie` and `donut`; ignored by every other type. Default\n * `percent`, which is what the reader almost always wants and what cortenaweb's\n * donuts showed before this package existed. See {@link ChartLabels}.\n */\n labels?: ChartLabels;\n /** Format values in axes, tooltips and labels. */\n valueFormatter?: (value: number) => string;\n /** Calendar range (ISO dates); defaults to the data's extent. */\n from?: string;\n to?: string;\n /** Render the loading skeleton instead of the data. */\n loading?: boolean;\n /** Render the error state with this message instead of the data. */\n error?: React.ReactNode | Error | null;\n /** Content of the empty state. Default \"No data\". */\n emptyMessage?: React.ReactNode;\n}\n\nfunction seriesKeys(type: ChartType, data: unknown, indexBy?: string, keys?: string[]): string[] {\n switch (type) {\n case \"bar\":\n case \"line\":\n case \"area\":\n case \"radar\":\n return toRows(data as ChartRow[] | ChartSeries[], indexBy, keys).keys;\n case \"pie\":\n case \"donut\":\n case \"funnel\":\n return toSlices(data as ChartSlice[]).map((s) => s.id);\n case \"heatmap\":\n if (isMatrix(data)) return data.rows.map(String);\n return isSeriesArray(data) ? data.map((s) => String(s.id)) : [];\n case \"scatter\":\n case \"scatterplot\":\n return isSeriesArray(data) ? data.map((s) => String(s.id)) : [];\n case \"treemap\":\n case \"sunburst\":\n return ((data as ChartTree).children ?? []).map((c) => String(c.id ?? c.name ?? \"\"));\n case \"calendar\":\n return [];\n }\n}\n\ninterface ChunkBoundaryProps {\n children: React.ReactNode;\n /** Changing it clears a previous failure and renders the children again. */\n resetKey: string;\n fallback: (retry: () => void) => React.ReactNode;\n}\n\n/**\n * Catches a Nivo chunk that failed to load. Recovering takes two things,\n * because `React.lazy` memoises a rejection for the life of the page: fresh\n * lazy components ({@link resetNivoChunks}) and a boundary that leaves its\n * failed state. `resetKey` does the second on its own when the chart changes,\n * and the fallback gets a `retry` that does both.\n */\nclass ChunkBoundary extends React.Component<ChunkBoundaryProps, { failed: boolean; key: string }> {\n state = { failed: false, key: this.props.resetKey };\n static getDerivedStateFromError() {\n return { failed: true };\n }\n static getDerivedStateFromProps(props: ChunkBoundaryProps, state: { failed: boolean; key: string }) {\n return props.resetKey === state.key ? null : { failed: false, key: props.resetKey };\n }\n retry = () => {\n resetNivoChunks();\n resetRechartsChunks();\n this.setState({ failed: false });\n };\n render() {\n return this.state.failed ? this.props.fallback(this.retry) : this.props.children;\n }\n}\n\n/** Shown when an engine chunk could not be fetched, with a way back. */\nfunction chunkFallback(retry: () => void): React.ReactNode {\n return (\n <ChartError>\n Chart could not be loaded.{\" \"}\n <button type=\"button\" data-slot=\"chart-retry\" onClick={retry} className=\"underline underline-offset-2\">\n Retry\n </button>\n </ChartError>\n );\n}\n\n/**\n * Chart — one component for every chart type the fleet draws.\n *\n * `type` picks the engine: Recharts for bar, line, area, pie, donut, scatter,\n * radar and funnel; Nivo for heatmap, calendar, treemap and sunburst, with\n * `renderer=\"canvas\"` for large series. Both are loaded on the first render of\n * a chart that needs them — Recharts as one chunk, each `@nivo/*` package as\n * its own — so importing `Chart` costs nothing until a chart is drawn, and a\n * screen that draws a bar chart never fetches Nivo.\n * Colours, fonts, axes, grid, tooltip, legend and the empty, loading and\n * error states all come from cortena-design tokens; a consumer passes data\n * and, optionally, a `config` of labels.\n *\n * `heatmap` takes either the Nivo series shape or a categorical\n * {@link ChartMatrix} — `{ rows, columns, values }` — for the correlation and\n * confusion matrices that are already in that form.\n *\n * `testMode` gives the drawing area a 600×300 floor so a chart still draws\n * where the layout gives it no size; see {@link ChartContainerProps.testMode}\n * and README.md, \"Charts in tests\".\n */\nfunction Chart<T extends ChartType>({\n type,\n data,\n config,\n renderer = \"svg\",\n indexBy,\n keys,\n stacked,\n scale = \"sequential\",\n legend,\n grid = true,\n tooltip = true,\n labels = \"percent\",\n valueFormatter,\n from,\n to,\n loading,\n error,\n emptyMessage,\n className,\n height,\n ...props\n}: ChartProps<T>) {\n const engine = chartEngine(type);\n const empty = isEmptyData(data);\n const fullConfig = React.useMemo(\n () => configFor(empty ? [] : seriesKeys(type, data, indexBy, keys), config),\n [type, data, indexBy, keys, config, empty],\n );\n const showLegend = legend ?? Object.keys(fullConfig).length > 1;\n const errorText = error instanceof Error ? error.message : error;\n\n let body: React.ReactNode;\n let responsive = false;\n if (loading) body = <ChartLoading />;\n else if (errorText) body = <ChartError>{errorText}</ChartError>;\n else if (empty) body = <ChartEmpty>{emptyMessage}</ChartEmpty>;\n else if (engine === \"nivo\") {\n body = (\n <ChunkBoundary resetKey={`${type}|${renderer}`} fallback={chunkFallback}>\n <React.Suspense fallback={<ChartLoading />}>\n <NivoChartLazy\n type={type as NivoType}\n data={data}\n config={fullConfig}\n renderer={renderer}\n scale={scale}\n legend={showLegend}\n valueFormatter={valueFormatter}\n from={from}\n to={to}\n />\n </React.Suspense>\n </ChunkBoundary>\n );\n } else {\n responsive = true;\n body = (\n <ChunkBoundary resetKey={type} fallback={chunkFallback}>\n <RechartsChartLazy\n type={type as RechartsType}\n data={data}\n config={fullConfig}\n indexBy={indexBy}\n keys={keys}\n stacked={stacked}\n legend={showLegend}\n grid={grid}\n tooltip={tooltip}\n labels={labels}\n valueFormatter={valueFormatter}\n />\n </ChunkBoundary>\n );\n }\n\n return (\n <ChartContainer\n data-type={type}\n data-engine={engine}\n data-renderer={engine === \"nivo\" ? renderer : \"svg\"}\n config={fullConfig}\n height={height}\n responsive={responsive}\n className={cn(className)}\n {...props}\n >\n {body}\n </ChartContainer>\n );\n}\n\nexport { Chart };\n"],"mappings":";;;;;;;;;;;AAoEA,SAAS,WAAW,MAAiB,MAAe,SAAkB,MAA2B;CAC/F,QAAQ,MAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,KAAK,SACH,OAAO,OAAO,MAAoC,SAAS,IAAI,CAAC,CAAC;EACnE,KAAK;EACL,KAAK;EACL,KAAK,UACH,OAAO,SAAS,IAAoB,CAAC,CAAC,KAAK,MAAM,EAAE,EAAE;EACvD,KAAK;GACH,IAAI,SAAS,IAAI,GAAG,OAAO,KAAK,KAAK,IAAI,MAAM;GAC/C,OAAO,cAAc,IAAI,IAAI,KAAK,KAAK,MAAM,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC;EAChE,KAAK;EACL,KAAK,eACH,OAAO,cAAc,IAAI,IAAI,KAAK,KAAK,MAAM,OAAO,EAAE,EAAE,CAAC,IAAI,CAAC;EAChE,KAAK;EACL,KAAK,YACH,QAAS,KAAmB,YAAY,CAAC,EAAA,CAAG,KAAK,MAAM,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,CAAC;EACrF,KAAK,YACH,OAAO,CAAC;CACZ;AACF;;;;;;;;AAgBA,IAAM,gBAAN,cAA4B,MAAM,UAAgE;CAChG,QAAQ;EAAE,QAAQ;EAAO,KAAK,KAAK,MAAM;CAAS;CAClD,OAAO,2BAA2B;EAChC,OAAO,EAAE,QAAQ,KAAK;CACxB;CACA,OAAO,yBAAyB,OAA2B,OAAyC;EAClG,OAAO,MAAM,aAAa,MAAM,MAAM,OAAO;GAAE,QAAQ;GAAO,KAAK,MAAM;EAAS;CACpF;CACA,cAAc;EACZ,gBAAgB;EAChB,oBAAoB;EACpB,KAAK,SAAS,EAAE,QAAQ,MAAM,CAAC;CACjC;CACA,SAAS;EACP,OAAO,KAAK,MAAM,SAAS,KAAK,MAAM,SAAS,KAAK,KAAK,IAAI,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EACb,OACE,oBAAC,eAAD;GAAe,UAAU;GAAM,UAAU;GACvC,UAAA,oBAAC,mBAAD;IACQ;IACA;IACN,QAAQ;IACC;IACH;IACG;IACT,QAAQ;IACF;IACG;IACD;IACQ;GACjB,CAAA;EACY,CAAA;CAEnB;CAEA,OACE,oBAAC,gBAAD;EACE,aAAW;EACX,eAAa;EACb,iBAAe,WAAW,SAAS,WAAW;EAC9C,QAAQ;EACA;EACI;EACZ,WAAW,GAAG,SAAS;EACvB,GAAI;EAEH,UAAA;CACa,CAAA;AAEpB"}
|
|
1
|
+
{"version":3,"file":"chart.js","names":[],"sources":["../../../src/components/chart/chart.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport { cn } from \"@/lib/cn\";\nimport { ChartContainer, ChartEmpty, ChartError, ChartLoading, type ChartContainerProps } from \"./container\";\nimport { configFor, isEmptyData, isMatrix, isSeriesArray, toRows, toSlices } from \"./data\";\nimport type { NivoType } from \"./nivo-charts\";\nimport { NivoChartLazy, resetNivoChunks } from \"./nivo-lazy\";\nimport type { RechartsType } from \"./recharts-charts\";\nimport { RechartsChartLazy, resetRechartsChunks } from \"./recharts-lazy\";\nimport {\n chartEngine,\n type ChartConfig,\n type ChartDataFor,\n type ChartLabels,\n type ChartMatrix,\n type ChartRenderer,\n type ChartRow,\n type ChartScale,\n type ChartSeries,\n type ChartSlice,\n type ChartTree,\n type ChartType,\n} from \"./types\";\n\nexport interface ChartProps<T extends ChartType = ChartType>\n extends Omit<ChartContainerProps, \"children\" | \"config\" | \"responsive\"> {\n /** Which chart to draw; the package picks the engine. See {@link ChartType} for the data shape per type. */\n type: T;\n /** The data, in the shape documented on {@link ChartType}. */\n data: ChartDataFor<T>;\n /** Series presentation keyed by series id; colours default to `--ds-viz-1..n` in order. */\n config?: ChartConfig;\n /** Nivo renderer; `canvas` for large series. Ignored by the Recharts types and by sunburst. */\n renderer?: ChartRenderer;\n /** Category key for row data (bar, line, area, radar); inferred as the first string field. */\n indexBy?: string;\n /** Series keys for row data; inferred as every numeric field. */\n keys?: string[];\n /** Stack bars and areas instead of grouping them. */\n stacked?: boolean;\n /** Continuous scale for heatmap and calendar. Default sequential. */\n scale?: ChartScale;\n /** Show a legend. Default: when there is more than one series. */\n legend?: boolean;\n /** Draw grid lines (cartesian and radar types). Default true. */\n grid?: boolean;\n /** Show a tooltip on hover. Default true. */\n tooltip?: boolean;\n /**\n * Per-arc labels for `pie` and `donut`; ignored by every other type. Default\n * `percent`, which is what the reader almost always wants and what cortenaweb's\n * donuts showed before this package existed. See {@link ChartLabels}.\n */\n labels?: ChartLabels;\n /** Format values in axes, tooltips and labels. */\n valueFormatter?: (value: number) => string;\n /** Calendar range (ISO dates); defaults to the data's extent. */\n from?: string;\n to?: string;\n /** Render the loading skeleton instead of the data. */\n loading?: boolean;\n /** Render the error state with this message instead of the data. */\n error?: React.ReactNode | Error | null;\n /** Content of the empty state. Default \"No data\". */\n emptyMessage?: React.ReactNode;\n}\n\nfunction seriesKeys(type: ChartType, data: unknown, indexBy?: string, keys?: string[]): string[] {\n switch (type) {\n case \"bar\":\n case \"line\":\n case \"area\":\n case \"radar\":\n return toRows(data as ChartRow[] | ChartSeries[], indexBy, keys).keys;\n case \"pie\":\n case \"donut\":\n case \"funnel\":\n return toSlices(data as ChartSlice[]).map((s) => s.id);\n case \"heatmap\":\n if (isMatrix(data)) return data.rows.map(String);\n return isSeriesArray(data) ? data.map((s) => String(s.id)) : [];\n case \"scatter\":\n case \"scatterplot\":\n return isSeriesArray(data) ? data.map((s) => String(s.id)) : [];\n case \"treemap\":\n case \"sunburst\":\n return ((data as ChartTree).children ?? []).map((c) => String(c.id ?? c.name ?? \"\"));\n case \"calendar\":\n return [];\n }\n}\n\ninterface ChunkBoundaryProps {\n children: React.ReactNode;\n /** Changing it clears a previous failure and renders the children again. */\n resetKey: string;\n fallback: (retry: () => void) => React.ReactNode;\n}\n\n/**\n * Catches a Nivo chunk that failed to load. Recovering takes two things,\n * because `React.lazy` memoises a rejection for the life of the page: fresh\n * lazy components ({@link resetNivoChunks}) and a boundary that leaves its\n * failed state. `resetKey` does the second on its own when the chart changes,\n * and the fallback gets a `retry` that does both.\n */\nclass ChunkBoundary extends React.Component<ChunkBoundaryProps, { failed: boolean; key: string }> {\n state = { failed: false, key: this.props.resetKey };\n static getDerivedStateFromError() {\n return { failed: true };\n }\n static getDerivedStateFromProps(props: ChunkBoundaryProps, state: { failed: boolean; key: string }) {\n return props.resetKey === state.key ? null : { failed: false, key: props.resetKey };\n }\n retry = () => {\n resetNivoChunks();\n resetRechartsChunks();\n this.setState({ failed: false });\n };\n render() {\n return this.state.failed ? this.props.fallback(this.retry) : this.props.children;\n }\n}\n\n/** Shown when an engine chunk could not be fetched, with a way back. */\nfunction chunkFallback(retry: () => void): React.ReactNode {\n return (\n <ChartError>\n Chart could not be loaded.{\" \"}\n <button type=\"button\" data-slot=\"chart-retry\" onClick={retry} className=\"underline underline-offset-2\">\n Retry\n </button>\n </ChartError>\n );\n}\n\n/**\n * Chart — one component for every chart type the fleet draws.\n *\n * `type` picks the engine: Recharts for bar, line, area, pie, donut, scatter,\n * radar and funnel; Nivo for heatmap, calendar, treemap and sunburst, with\n * `renderer=\"canvas\"` for large series. Both are loaded on the first render of\n * a chart that needs them — Recharts as one chunk, each `@nivo/*` package as\n * its own — so importing `Chart` costs nothing until a chart is drawn, and a\n * screen that draws a bar chart never fetches Nivo.\n * Colours, fonts, axes, grid, tooltip, legend and the empty, loading and\n * error states all come from cortena-design tokens; a consumer passes data\n * and, optionally, a `config` of labels.\n *\n * `heatmap` takes either the Nivo series shape or a categorical\n * {@link ChartMatrix} — `{ rows, columns, values }` — for the correlation and\n * confusion matrices that are already in that form.\n *\n * `testMode` gives the drawing area a 600×300 floor so a chart still draws\n * where the layout gives it no size; see {@link ChartContainerProps.testMode}\n * and README.md, \"Charts in tests\".\n */\nfunction Chart<T extends ChartType>({\n type,\n data,\n config,\n renderer = \"svg\",\n indexBy,\n keys,\n stacked,\n scale = \"sequential\",\n legend,\n grid = true,\n tooltip = true,\n labels = \"percent\",\n valueFormatter,\n from,\n to,\n loading,\n error,\n emptyMessage,\n className,\n height,\n ...props\n}: ChartProps<T>) {\n const engine = chartEngine(type);\n const empty = isEmptyData(data);\n const fullConfig = React.useMemo(\n () => configFor(empty ? [] : seriesKeys(type, data, indexBy, keys), config),\n [type, data, indexBy, keys, config, empty],\n );\n const showLegend = legend ?? Object.keys(fullConfig).length > 1;\n const errorText = error instanceof Error ? error.message : error;\n\n let body: React.ReactNode;\n let responsive = false;\n if (loading) body = <ChartLoading />;\n else if (errorText) body = <ChartError>{errorText}</ChartError>;\n else if (empty) body = <ChartEmpty>{emptyMessage}</ChartEmpty>;\n else if (engine === \"nivo\") {\n body = (\n <ChunkBoundary resetKey={`${type}|${renderer}`} fallback={chunkFallback}>\n <React.Suspense fallback={<ChartLoading />}>\n <NivoChartLazy\n type={type as NivoType}\n data={data}\n config={fullConfig}\n renderer={renderer}\n scale={scale}\n legend={showLegend}\n valueFormatter={valueFormatter}\n from={from}\n to={to}\n />\n </React.Suspense>\n </ChunkBoundary>\n );\n } else {\n responsive = true;\n body = (\n <ChunkBoundary resetKey={type} fallback={chunkFallback}>\n <RechartsChartLazy\n type={type as RechartsType}\n data={data}\n config={fullConfig}\n indexBy={indexBy}\n keys={keys}\n stacked={stacked}\n legend={showLegend}\n grid={grid}\n tooltip={tooltip}\n labels={labels}\n valueFormatter={valueFormatter}\n animate={!props.testMode}\n />\n </ChunkBoundary>\n );\n }\n\n return (\n <ChartContainer\n data-type={type}\n data-engine={engine}\n data-renderer={engine === \"nivo\" ? renderer : \"svg\"}\n config={fullConfig}\n height={height}\n responsive={responsive}\n className={cn(className)}\n {...props}\n >\n {body}\n </ChartContainer>\n );\n}\n\nexport { Chart };\n"],"mappings":";;;;;;;;;;;AAoEA,SAAS,WAAW,MAAiB,MAAe,SAAkB,MAA2B;CAC/F,QAAQ,MAAR;EACE,KAAK;EACL,KAAK;EACL,KAAK;EACL,K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gBAAD;EACE,aAAW;EACX,eAAa;EACb,iBAAe,WAAW,SAAS,WAAW;EAC9C,QAAQ;EACA;EACI;EACZ,WAAW,GAAG,SAAS;EACvB,GAAI;EAEH,UAAA;CACa,CAAA;AAEpB"}
|
|
@@ -3,7 +3,7 @@ import { ChartConfig, ChartDataFor, ChartDay, ChartEngine, ChartLabels, ChartMat
|
|
|
3
3
|
import { ChartContainer, ChartContainerProps, ChartEmpty, ChartError, ChartLegendContent, ChartLegendContentProps, ChartLoading, ChartTooltipContent, ChartTooltipContentProps, seriesColor, useChart } from "./container.js";
|
|
4
4
|
import { Chart, ChartProps } from "./chart.js";
|
|
5
5
|
import { ChartLegend, ChartTooltip } from "./recharts-parts.js";
|
|
6
|
-
import { NivoTheme
|
|
6
|
+
import { NivoTheme } from "./nivo-theme.js";
|
|
7
7
|
import { ChartScales, VIZ_SERIES_COUNT, chartScales, resolveColor, resolveVizSeries, toHex, vizSeriesVars, vizVar } from "./tokens.js";
|
|
8
8
|
import { Area as Area$1, AreaChart as AreaChart$1, Bar as Bar$1, BarChart as BarChart$1, CartesianGrid as CartesianGrid$1, Cell as Cell$1, ComposedChart, Funnel as Funnel$1, FunnelChart as FunnelChart$1, LabelList, Legend as RechartsLegend, Line as Line$1, LineChart as LineChart$1, Pie as Pie$1, PieChart as PieChart$1, PolarAngleAxis as PolarAngleAxis$1, PolarGrid as PolarGrid$1, PolarRadiusAxis as PolarRadiusAxis$1, Radar as Radar$1, RadarChart as RadarChart$1, ReferenceLine, ResponsiveContainer, Scatter as Scatter$1, ScatterChart as ScatterChart$1, Tooltip as RechartsTooltip, XAxis as XAxis$1, YAxis as YAxis$1 } from "recharts";
|
|
9
|
-
export { Area$1 as Area, AreaChart$1 as AreaChart, Bar$1 as Bar, BarChart$1 as BarChart, CartesianGrid$1 as CartesianGrid, Cell$1 as Cell, Chart, type ChartConfig, ChartContainer, type ChartContainerProps, type ChartDataFor, type ChartDay, ChartEmpty, type ChartEngine, ChartError, type ChartLabels, ChartLegend, ChartLegendContent, type ChartLegendContentProps, ChartLoading, type ChartMatrix, type ChartPoint, type ChartProps, type ChartRenderer, type ChartRow, type ChartScale, type ChartScales, type ChartSeries, type ChartSlice, ChartTooltip, ChartTooltipContent, type ChartTooltipContentProps, type ChartTree, type ChartType, ComposedChart, Funnel$1 as Funnel, FunnelChart$1 as FunnelChart, LabelList, Line$1 as Line, LineChart$1 as LineChart, NIVO_TYPES, type NivoTheme, Pie$1 as Pie, PieChart$1 as PieChart, PolarAngleAxis$1 as PolarAngleAxis, PolarGrid$1 as PolarGrid, PolarRadiusAxis$1 as PolarRadiusAxis, RECHARTS_TYPES, Radar$1 as Radar, RadarChart$1 as RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter$1 as Scatter, ScatterChart$1 as ScatterChart, VIZ_SERIES_COUNT, XAxis$1 as XAxis, YAxis$1 as YAxis, chartEngine, chartScales,
|
|
9
|
+
export { Area$1 as Area, AreaChart$1 as AreaChart, Bar$1 as Bar, BarChart$1 as BarChart, CartesianGrid$1 as CartesianGrid, Cell$1 as Cell, Chart, type ChartConfig, ChartContainer, type ChartContainerProps, type ChartDataFor, type ChartDay, ChartEmpty, type ChartEngine, ChartError, type ChartLabels, ChartLegend, ChartLegendContent, type ChartLegendContentProps, ChartLoading, type ChartMatrix, type ChartPoint, type ChartProps, type ChartRenderer, type ChartRow, type ChartScale, type ChartScales, type ChartSeries, type ChartSlice, ChartTooltip, ChartTooltipContent, type ChartTooltipContentProps, type ChartTree, type ChartType, ComposedChart, Funnel$1 as Funnel, FunnelChart$1 as FunnelChart, LabelList, Line$1 as Line, LineChart$1 as LineChart, NIVO_TYPES, type NivoTheme, Pie$1 as Pie, PieChart$1 as PieChart, PolarAngleAxis$1 as PolarAngleAxis, PolarGrid$1 as PolarGrid, PolarRadiusAxis$1 as PolarRadiusAxis, RECHARTS_TYPES, Radar$1 as Radar, RadarChart$1 as RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter$1 as Scatter, ScatterChart$1 as ScatterChart, VIZ_SERIES_COUNT, XAxis$1 as XAxis, YAxis$1 as YAxis, chartEngine, chartScales, resolveColor, resolveVizSeries, seriesColor, toHex, useChart, vizSeriesVars, vizVar };
|
|
@@ -5,6 +5,5 @@ import { ChartContainer, ChartEmpty, ChartError, ChartLegendContent, ChartLoadin
|
|
|
5
5
|
import { NIVO_TYPES, RECHARTS_TYPES, chartEngine } from "./types.js";
|
|
6
6
|
import { Chart } from "./chart.js";
|
|
7
7
|
import { ChartLegend, ChartTooltip } from "./recharts-parts.js";
|
|
8
|
-
import { nivoTheme, useNivoTheme } from "./nivo-theme.js";
|
|
9
8
|
import { Area as Area$1, AreaChart as AreaChart$1, Bar as Bar$1, BarChart as BarChart$1, CartesianGrid as CartesianGrid$1, Cell as Cell$1, ComposedChart, Funnel as Funnel$1, FunnelChart as FunnelChart$1, LabelList, Legend as RechartsLegend, Line as Line$1, LineChart as LineChart$1, Pie as Pie$1, PieChart as PieChart$1, PolarAngleAxis as PolarAngleAxis$1, PolarGrid as PolarGrid$1, PolarRadiusAxis as PolarRadiusAxis$1, Radar as Radar$1, RadarChart as RadarChart$1, ReferenceLine, ResponsiveContainer, Scatter as Scatter$1, ScatterChart as ScatterChart$1, Tooltip as RechartsTooltip, XAxis as XAxis$1, YAxis as YAxis$1 } from "recharts";
|
|
10
|
-
export { Area$1 as Area, AreaChart$1 as AreaChart, Bar$1 as Bar, BarChart$1 as BarChart, CartesianGrid$1 as CartesianGrid, Cell$1 as Cell, Chart, ChartContainer, ChartEmpty, ChartError, ChartLegend, ChartLegendContent, ChartLoading, ChartTooltip, ChartTooltipContent, ComposedChart, Funnel$1 as Funnel, FunnelChart$1 as FunnelChart, LabelList, Line$1 as Line, LineChart$1 as LineChart, NIVO_TYPES, Pie$1 as Pie, PieChart$1 as PieChart, PolarAngleAxis$1 as PolarAngleAxis, PolarGrid$1 as PolarGrid, PolarRadiusAxis$1 as PolarRadiusAxis, RECHARTS_TYPES, Radar$1 as Radar, RadarChart$1 as RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter$1 as Scatter, ScatterChart$1 as ScatterChart, VIZ_SERIES_COUNT, XAxis$1 as XAxis, YAxis$1 as YAxis, chartEngine, chartScales,
|
|
9
|
+
export { Area$1 as Area, AreaChart$1 as AreaChart, Bar$1 as Bar, BarChart$1 as BarChart, CartesianGrid$1 as CartesianGrid, Cell$1 as Cell, Chart, ChartContainer, ChartEmpty, ChartError, ChartLegend, ChartLegendContent, ChartLoading, ChartTooltip, ChartTooltipContent, ComposedChart, Funnel$1 as Funnel, FunnelChart$1 as FunnelChart, LabelList, Line$1 as Line, LineChart$1 as LineChart, NIVO_TYPES, Pie$1 as Pie, PieChart$1 as PieChart, PolarAngleAxis$1 as PolarAngleAxis, PolarGrid$1 as PolarGrid, PolarRadiusAxis$1 as PolarRadiusAxis, RECHARTS_TYPES, Radar$1 as Radar, RadarChart$1 as RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter$1 as Scatter, ScatterChart$1 as ScatterChart, VIZ_SERIES_COUNT, XAxis$1 as XAxis, YAxis$1 as YAxis, chartEngine, chartScales, resolveColor, resolveVizSeries, seriesColor, toHex, useChart, vizSeriesVars, vizVar };
|
|
@@ -136,21 +136,5 @@ export interface NivoTheme {
|
|
|
136
136
|
};
|
|
137
137
|
};
|
|
138
138
|
}
|
|
139
|
-
/**
|
|
140
|
-
* Build the Nivo theme from the tokens, resolved on `el` (default `<html>`).
|
|
141
|
-
* Every colour is read from a `--ds-*` custom property and converted to hex,
|
|
142
|
-
* because Nivo's canvas renderer and its colour derivation cannot read
|
|
143
|
-
* `var()`. Sizes come from the type scale with `--ds-text-caption-sm` (11px)
|
|
144
|
-
* as the floor for ticks and labels.
|
|
145
|
-
*
|
|
146
|
-
* Moved here from cortenaweb's webchat renderer; nothing is hard-coded.
|
|
147
|
-
*/
|
|
148
|
-
export declare function nivoTheme(el?: Element | null): NivoTheme;
|
|
149
|
-
/**
|
|
150
|
-
* The Nivo theme for the current theme, re-resolved when `data-theme` or the
|
|
151
|
-
* OS scheme flips. Inside a ChartContainer the tokens are read on its element,
|
|
152
|
-
* so a nested theme scope is honoured.
|
|
153
|
-
*/
|
|
154
|
-
export declare function useNivoTheme(): NivoTheme;
|
|
155
139
|
//#endregion
|
|
156
140
|
//# sourceMappingURL=nivo-theme.d.ts.map
|
|
@@ -65,7 +65,7 @@ function arcLabel(labels, colourOn, fillOf, valueFormatter) {
|
|
|
65
65
|
* (config colour or `var(--ds-viz-N)` by series index) and every other visual
|
|
66
66
|
* value from the container's token styling.
|
|
67
67
|
*/
|
|
68
|
-
function RechartsChart({ type, data, config, indexBy, keys, stacked, legend, grid, tooltip, labels, valueFormatter }) {
|
|
68
|
+
function RechartsChart({ type, data, config, indexBy, keys, stacked, legend, grid, tooltip, labels, valueFormatter, animate = true }) {
|
|
69
69
|
const themeVersion = useThemeVersion();
|
|
70
70
|
const element = useChart()?.element ?? null;
|
|
71
71
|
const colourOn = React.useMemo(() => contrastLabel(element), [element, themeVersion]);
|
|
@@ -190,6 +190,7 @@ function RechartsChart({ type, data, config, indexBy, keys, stacked, legend, gri
|
|
|
190
190
|
outerRadius: "80%",
|
|
191
191
|
paddingAngle: type === "donut" ? 2 : 0,
|
|
192
192
|
strokeWidth: 1,
|
|
193
|
+
isAnimationActive: animate,
|
|
193
194
|
label: labels === "none" ? void 0 : arcLabel(labels, colourOn, fillOf, valueFormatter),
|
|
194
195
|
labelLine: false,
|
|
195
196
|
children: slices.map((slice, i) => /* @__PURE__ */ jsx(Cell, { fill: fillOf(i) }, slice.id))
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"recharts-charts.js","names":["series"],"sources":["../../../src/components/chart/recharts-charts.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n Area,\n AreaChart,\n Bar,\n BarChart,\n CartesianGrid,\n Cell,\n Funnel,\n FunnelChart,\n Line,\n LineChart,\n Pie,\n PieChart,\n PolarAngleAxis,\n PolarGrid,\n PolarRadiusAxis,\n Radar,\n RadarChart,\n Scatter,\n ScatterChart,\n XAxis,\n YAxis,\n} from \"recharts\";\nimport { seriesColor, useChart } from \"./container\";\nimport { ChartLegend, ChartTooltip } from \"./recharts-parts\";\nimport { toRows, toSlices } from \"./data\";\nimport { contrastLabel, useThemeVersion } from \"./tokens\";\nimport type { ChartConfig, ChartLabels, ChartRow, ChartSeries, ChartSlice, ChartType } from \"./types\";\n\nexport type RechartsType = Extract<\n ChartType,\n \"bar\" | \"line\" | \"area\" | \"pie\" | \"donut\" | \"scatter\" | \"scatterplot\" | \"radar\" | \"funnel\"\n>;\n\nexport interface RechartsRenderProps {\n type: RechartsType;\n data: unknown;\n config: ChartConfig;\n indexBy?: string;\n keys?: string[];\n stacked?: boolean;\n legend: boolean;\n grid: boolean;\n tooltip: boolean;\n /** Per-arc labels for pie and donut. Ignored by every other type. */\n labels: ChartLabels;\n valueFormatter?: (value: number) => string;\n}\n\nconst MARGIN = { top: 8, right: 8, bottom: 0, left: 0 };\n\n/**\n * Where an arc label sits, as a fraction of the way from the inner radius to\n * the outer one. Just inside the middle of the band: the arc is widest towards\n * its outer edge, so a label pushed slightly out has more room than a centred\n * one, without ever touching the rim.\n */\nconst ARC_LABEL_RADIUS = 0.58;\n\n/**\n * Arcs smaller than this share of the whole are left unlabelled.\n *\n * Below roughly a twentieth the arc is narrower than the text it would carry,\n * so the label either overflows into its neighbours or has to be dragged\n * outside on a leader line. Leader lines on a small chart are worse than no\n * label — they collide with each other and with the legend, and the reader\n * still has to trace them. The tooltip covers the slices that fall out.\n */\nconst ARC_LABEL_MIN_FRACTION = 0.05;\n\n/**\n * What Recharts hands a `<Pie label={…}>` renderer. Every geometry field is\n * optional on its side — the same callback types the label of a chart that has\n * not measured itself yet — so each is checked before it is used rather than\n * asserted away.\n */\ninterface ArcLabelProps {\n cx?: number;\n cy?: number;\n midAngle?: number;\n innerRadius?: number;\n outerRadius?: number;\n percent?: number;\n value?: number;\n index?: number;\n}\n\n/**\n * A per-arc label, drawn inside the arc it belongs to.\n *\n * Inside rather than outside so there is nothing to collide: each label is\n * bounded by its own sector, and a sector too thin to hold one simply does not\n * get one. The text colour comes from `contrastLabel`, the same measured\n * ink-or-white choice the Nivo charts make, so a label stays legible on a pale\n * series colour and on a dark one, in either theme.\n */\nfunction arcLabel(\n labels: Exclude<ChartLabels, \"none\">,\n colourOn: (fill: string) => string,\n fillOf: (index: number) => string,\n valueFormatter?: (value: number) => string,\n) {\n return function ArcLabel({ cx, cy, midAngle, innerRadius, outerRadius, percent, value, index }: ArcLabelProps) {\n if (cx == null || cy == null || midAngle == null || innerRadius == null || outerRadius == null) return null;\n if (!(percent != null && percent >= ARC_LABEL_MIN_FRACTION)) return null;\n const radius = innerRadius + (outerRadius - innerRadius) * ARC_LABEL_RADIUS;\n // Recharts measures angles anticlockwise from the positive x-axis, SVG's y\n // grows downward, so the sine is negated to land on the drawn arc.\n const radians = (-midAngle * Math.PI) / 180;\n const text =\n labels === \"percent\"\n ? `${Math.round(percent * 100)}%`\n : (valueFormatter?.(Number(value)) ?? String(value ?? \"\"));\n return (\n <text\n data-slot=\"chart-arc-label\"\n x={cx + radius * Math.cos(radians)}\n y={cy + radius * Math.sin(radians)}\n fill={colourOn(fillOf(index ?? 0))}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n className=\"pointer-events-none text-[length:var(--ds-text-caption)] font-medium tabular-nums\"\n >\n {text}\n </text>\n );\n };\n}\n\n/**\n * The Recharts side of `Chart`. Returns a chart element for the\n * ResponsiveContainer inside ChartContainer; colours come from `seriesColor`\n * (config colour or `var(--ds-viz-N)` by series index) and every other visual\n * value from the container's token styling.\n */\nexport function RechartsChart({\n type,\n data,\n config,\n indexBy,\n keys,\n stacked,\n legend,\n grid,\n tooltip,\n labels,\n valueFormatter,\n}: RechartsRenderProps): React.ReactElement {\n // Arc labels sit on top of a series colour, so their ink depends on which\n // colour and on the theme. `useThemeVersion` is the cache key for that DOM\n // read; `element` scopes it to a nested theme rather than the document.\n const themeVersion = useThemeVersion();\n const element = useChart()?.element ?? null;\n // eslint-disable-next-line react-hooks/exhaustive-deps -- themeVersion is the cache key for the DOM read\n const colourOn = React.useMemo(() => contrastLabel(element), [element, themeVersion]);\n\n const tip = tooltip ? (\n <ChartTooltip\n formatter={valueFormatter ? (value: unknown) => valueFormatter(Number(value)) : undefined}\n />\n ) : null;\n const leg = legend ? <ChartLegend /> : null;\n\n switch (type) {\n case \"bar\": {\n const { rows, indexBy: index, keys: series } = toRows(data as ChartRow[] | ChartSeries[], indexBy, keys);\n return (\n <BarChart data={rows} margin={MARGIN}>\n {grid ? <CartesianGrid vertical={false} /> : null}\n <XAxis dataKey={index} tickLine={false} axisLine={false} tickMargin={8} />\n <YAxis tickLine={false} axisLine={false} tickFormatter={valueFormatter} />\n {tip}\n {leg}\n {series.map((key, i) => (\n <Bar\n key={key}\n dataKey={key}\n name={key}\n fill={seriesColor(config, key, i)}\n stackId={stacked ? \"stack\" : undefined}\n radius={stacked ? 0 : [2, 2, 0, 0]}\n maxBarSize={48}\n />\n ))}\n </BarChart>\n );\n }\n\n case \"line\": {\n const { rows, indexBy: index, keys: series } = toRows(data as ChartRow[] | ChartSeries[], indexBy, keys);\n return (\n <LineChart data={rows} margin={MARGIN}>\n {grid ? <CartesianGrid vertical={false} /> : null}\n <XAxis dataKey={index} tickLine={false} axisLine={false} tickMargin={8} />\n <YAxis tickLine={false} axisLine={false} tickFormatter={valueFormatter} />\n {tip}\n {leg}\n {series.map((key, i) => (\n <Line\n key={key}\n type=\"monotone\"\n dataKey={key}\n name={key}\n stroke={seriesColor(config, key, i)}\n strokeWidth={2}\n dot={false}\n activeDot={{ r: 4 }}\n />\n ))}\n </LineChart>\n );\n }\n\n case \"area\": {\n const { rows, indexBy: index, keys: series } = toRows(data as ChartRow[] | ChartSeries[], indexBy, keys);\n return (\n <AreaChart data={rows} margin={MARGIN}>\n {grid ? <CartesianGrid vertical={false} /> : null}\n <XAxis dataKey={index} tickLine={false} axisLine={false} tickMargin={8} />\n <YAxis tickLine={false} axisLine={false} tickFormatter={valueFormatter} />\n {tip}\n {leg}\n {series.map((key, i) => (\n <Area\n key={key}\n type=\"monotone\"\n dataKey={key}\n name={key}\n stroke={seriesColor(config, key, i)}\n fill={seriesColor(config, key, i)}\n fillOpacity={0.2}\n strokeWidth={2}\n stackId={stacked ? \"stack\" : undefined}\n />\n ))}\n </AreaChart>\n );\n }\n\n case \"pie\":\n case \"donut\": {\n const slices = toSlices(data as ChartSlice[]);\n const fillOf = (i: number) => seriesColor(config, slices[i]?.id ?? String(i), i);\n return (\n <PieChart margin={MARGIN}>\n {tip}\n {leg}\n <Pie\n data={slices}\n dataKey=\"value\"\n nameKey=\"name\"\n innerRadius={type === \"donut\" ? \"55%\" : 0}\n outerRadius=\"80%\"\n paddingAngle={type === \"donut\" ? 2 : 0}\n strokeWidth={1}\n label={labels === \"none\" ? undefined : arcLabel(labels, colourOn, fillOf, valueFormatter)}\n // The labels are inside their arcs, so there is nothing to lead to.\n labelLine={false}\n >\n {slices.map((slice, i) => (\n <Cell key={slice.id} fill={fillOf(i)} />\n ))}\n </Pie>\n </PieChart>\n );\n }\n\n case \"scatter\":\n case \"scatterplot\": {\n const series = data as ChartSeries[];\n return (\n <ScatterChart margin={MARGIN}>\n {grid ? <CartesianGrid /> : null}\n <XAxis dataKey=\"x\" type=\"number\" name=\"x\" tickLine={false} axisLine={false} tickMargin={8} />\n <YAxis dataKey=\"y\" type=\"number\" name=\"y\" tickLine={false} axisLine={false} tickFormatter={valueFormatter} />\n {tip}\n {leg}\n {series.map((s, i) => (\n <Scatter key={String(s.id)} name={String(s.id)} data={s.data} fill={seriesColor(config, String(s.id), i)} />\n ))}\n </ScatterChart>\n );\n }\n\n case \"radar\": {\n const { rows, indexBy: index, keys: series } = toRows(data as ChartRow[] | ChartSeries[], indexBy, keys);\n return (\n <RadarChart data={rows} margin={MARGIN}>\n {grid ? <PolarGrid /> : null}\n <PolarAngleAxis dataKey={index} />\n <PolarRadiusAxis tick={false} axisLine={false} />\n {tip}\n {leg}\n {series.map((key, i) => (\n <Radar\n key={key}\n dataKey={key}\n name={key}\n stroke={seriesColor(config, key, i)}\n fill={seriesColor(config, key, i)}\n fillOpacity={0.2}\n strokeWidth={2}\n />\n ))}\n </RadarChart>\n );\n }\n\n case \"funnel\": {\n const slices = toSlices(data as ChartSlice[]);\n return (\n <FunnelChart margin={MARGIN}>\n {tip}\n {leg}\n <Funnel data={slices} dataKey=\"value\" nameKey=\"name\">\n {slices.map((slice, i) => (\n <Cell key={slice.id} fill={seriesColor(config, slice.id, i)} />\n ))}\n </Funnel>\n </FunnelChart>\n );\n }\n }\n}\n"],"mappings":";;;;;;;;;;AAoDA,MAAM,SAAS;CAAE,KAAK;CAAG,OAAO;CAAG,QAAQ;CAAG,MAAM;AAAE;;;;;;;AAQtD,MAAM,mBAAmB;;;;;;;;;;AAWzB,MAAM,yBAAyB;;;;;;;;;;AA4B/B,SAAS,SACP,QACA,UACA,QACA,gBACA;CACA,OAAO,SAAS,SAAS,EAAE,IAAI,IAAI,UAAU,aAAa,aAAa,SAAS,OAAO,SAAwB;EAC7G,IAAI,MAAM,QAAQ,MAAM,QAAQ,YAAY,QAAQ,eAAe,QAAQ,eAAe,MAAM,OAAO;EACvG,IAAI,EAAE,WAAW,QAAQ,WAAW,yBAAyB,OAAO;EACpE,MAAM,SAAS,eAAe,cAAc,eAAe;EAG3D,MAAM,UAAW,CAAC,WAAW,KAAK,KAAM;EACxC,MAAM,OACJ,WAAW,YACP,GAAG,KAAK,MAAM,UAAU,GAAG,EAAE,KAC5B,iBAAiB,OAAO,KAAK,CAAC,KAAK,OAAO,SAAS,EAAE;EAC5D,OACE,oBAAC,QAAD;GACE,aAAU;GACV,GAAG,KAAK,SAAS,KAAK,IAAI,OAAO;GACjC,GAAG,KAAK,SAAS,KAAK,IAAI,OAAO;GACjC,MAA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AAA;KAC/C;KACA;KACA,OAAO,KAAK,KAAK,MAChB,oBAAC,OAAD;MAEE,SAAS;MACT,MAAM;MACN,QAAQ,YAAY,QAAQ,KAAK,CAAC;MAClC,MAAM,YAAY,QAAQ,KAAK,CAAC;MAChC,aAAa;MACb,aAAa;KACd,GAPM,GAON,CACF;IACS;;EAEhB;EAEA,KAAK,UAAU;GACb,MAAM,SAAS,SAAS,IAAoB;GAC5C,OACE,qBAAC,aAAD;IAAa,QAAQ;IAArB,UAAA;KACG;KACA;KACD,oBAAC,QAAD;MAAQ,MAAM;MAAQ,SAAQ;MAAQ,SAAQ;MAC3C,UAAA,OAAO,KAAK,OAAO,MAClB,oBAAC,MAAD,EAAqB,MAAM,YAAY,QAAQ,MAAM,IAAI,CAAC,EAAI,GAAnD,MAAM,EAA6C,CAC/D;KACK,CAAA;IACG;;EAEjB;CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"recharts-charts.js","names":["series"],"sources":["../../../src/components/chart/recharts-charts.tsx"],"sourcesContent":["\"use client\";\n\nimport * as React from \"react\";\nimport {\n Area,\n AreaChart,\n Bar,\n BarChart,\n CartesianGrid,\n Cell,\n Funnel,\n FunnelChart,\n Line,\n LineChart,\n Pie,\n PieChart,\n PolarAngleAxis,\n PolarGrid,\n PolarRadiusAxis,\n Radar,\n RadarChart,\n Scatter,\n ScatterChart,\n XAxis,\n YAxis,\n} from \"recharts\";\nimport { seriesColor, useChart } from \"./container\";\nimport { ChartLegend, ChartTooltip } from \"./recharts-parts\";\nimport { toRows, toSlices } from \"./data\";\nimport { contrastLabel, useThemeVersion } from \"./tokens\";\nimport type { ChartConfig, ChartLabels, ChartRow, ChartSeries, ChartSlice, ChartType } from \"./types\";\n\nexport type RechartsType = Extract<\n ChartType,\n \"bar\" | \"line\" | \"area\" | \"pie\" | \"donut\" | \"scatter\" | \"scatterplot\" | \"radar\" | \"funnel\"\n>;\n\nexport interface RechartsRenderProps {\n type: RechartsType;\n data: unknown;\n config: ChartConfig;\n indexBy?: string;\n keys?: string[];\n stacked?: boolean;\n legend: boolean;\n grid: boolean;\n tooltip: boolean;\n /** Per-arc labels for pie and donut. Ignored by every other type. */\n labels: ChartLabels;\n valueFormatter?: (value: number) => string;\n /**\n * Entry animation. Off under `testMode`: Recharts draws pie labels only\n * once the animation has finished, so a test that asserts on them would\n * otherwise be racing the clock.\n */\n animate?: boolean;\n}\n\nconst MARGIN = { top: 8, right: 8, bottom: 0, left: 0 };\n\n/**\n * Where an arc label sits, as a fraction of the way from the inner radius to\n * the outer one. Just inside the middle of the band: the arc is widest towards\n * its outer edge, so a label pushed slightly out has more room than a centred\n * one, without ever touching the rim.\n */\nconst ARC_LABEL_RADIUS = 0.58;\n\n/**\n * Arcs smaller than this share of the whole are left unlabelled.\n *\n * Below roughly a twentieth the arc is narrower than the text it would carry,\n * so the label either overflows into its neighbours or has to be dragged\n * outside on a leader line. Leader lines on a small chart are worse than no\n * label — they collide with each other and with the legend, and the reader\n * still has to trace them. The tooltip covers the slices that fall out.\n */\nconst ARC_LABEL_MIN_FRACTION = 0.05;\n\n/**\n * What Recharts hands a `<Pie label={…}>` renderer. Every geometry field is\n * optional on its side — the same callback types the label of a chart that has\n * not measured itself yet — so each is checked before it is used rather than\n * asserted away.\n */\ninterface ArcLabelProps {\n cx?: number;\n cy?: number;\n midAngle?: number;\n innerRadius?: number;\n outerRadius?: number;\n percent?: number;\n value?: number;\n index?: number;\n}\n\n/**\n * A per-arc label, drawn inside the arc it belongs to.\n *\n * Inside rather than outside so there is nothing to collide: each label is\n * bounded by its own sector, and a sector too thin to hold one simply does not\n * get one. The text colour comes from `contrastLabel`, the same measured\n * ink-or-white choice the Nivo charts make, so a label stays legible on a pale\n * series colour and on a dark one, in either theme.\n */\nfunction arcLabel(\n labels: Exclude<ChartLabels, \"none\">,\n colourOn: (fill: string) => string,\n fillOf: (index: number) => string,\n valueFormatter?: (value: number) => string,\n) {\n return function ArcLabel({ cx, cy, midAngle, innerRadius, outerRadius, percent, value, index }: ArcLabelProps) {\n if (cx == null || cy == null || midAngle == null || innerRadius == null || outerRadius == null) return null;\n if (!(percent != null && percent >= ARC_LABEL_MIN_FRACTION)) return null;\n const radius = innerRadius + (outerRadius - innerRadius) * ARC_LABEL_RADIUS;\n // Recharts measures angles anticlockwise from the positive x-axis, SVG's y\n // grows downward, so the sine is negated to land on the drawn arc.\n const radians = (-midAngle * Math.PI) / 180;\n const text =\n labels === \"percent\"\n ? `${Math.round(percent * 100)}%`\n : (valueFormatter?.(Number(value)) ?? String(value ?? \"\"));\n return (\n <text\n data-slot=\"chart-arc-label\"\n x={cx + radius * Math.cos(radians)}\n y={cy + radius * Math.sin(radians)}\n fill={colourOn(fillOf(index ?? 0))}\n textAnchor=\"middle\"\n dominantBaseline=\"central\"\n className=\"pointer-events-none text-[length:var(--ds-text-caption)] font-medium tabular-nums\"\n >\n {text}\n </text>\n );\n };\n}\n\n/**\n * The Recharts side of `Chart`. Returns a chart element for the\n * ResponsiveContainer inside ChartContainer; colours come from `seriesColor`\n * (config colour or `var(--ds-viz-N)` by series index) and every other visual\n * value from the container's token styling.\n */\nexport function RechartsChart({\n type,\n data,\n config,\n indexBy,\n keys,\n stacked,\n legend,\n grid,\n tooltip,\n labels,\n valueFormatter,\n animate = true,\n}: RechartsRenderProps): React.ReactElement {\n // Arc labels sit on top of a series colour, so their ink depends on which\n // colour and on the theme. `useThemeVersion` is the cache key for that DOM\n // read; `element` scopes it to a nested theme rather than the document.\n const themeVersion = useThemeVersion();\n const element = useChart()?.element ?? null;\n // eslint-disable-next-line react-hooks/exhaustive-deps -- themeVersion is the cache key for the DOM read\n const colourOn = React.useMemo(() => contrastLabel(element), [element, themeVersion]);\n\n const tip = tooltip ? (\n <ChartTooltip\n formatter={valueFormatter ? (value: unknown) => valueFormatter(Number(value)) : undefined}\n />\n ) : null;\n const leg = legend ? <ChartLegend /> : null;\n\n switch (type) {\n case \"bar\": {\n const { rows, indexBy: index, keys: series } = toRows(data as ChartRow[] | ChartSeries[], indexBy, keys);\n return (\n <BarChart data={rows} margin={MARGIN}>\n {grid ? <CartesianGrid vertical={false} /> : null}\n <XAxis dataKey={index} tickLine={false} axisLine={false} tickMargin={8} />\n <YAxis tickLine={false} axisLine={false} tickFormatter={valueFormatter} />\n {tip}\n {leg}\n {series.map((key, i) => (\n <Bar\n key={key}\n dataKey={key}\n name={key}\n fill={seriesColor(config, key, i)}\n stackId={stacked ? \"stack\" : undefined}\n radius={stacked ? 0 : [2, 2, 0, 0]}\n maxBarSize={48}\n />\n ))}\n </BarChart>\n );\n }\n\n case \"line\": {\n const { rows, indexBy: index, keys: series } = toRows(data as ChartRow[] | ChartSeries[], indexBy, keys);\n return (\n <LineChart data={rows} margin={MARGIN}>\n {grid ? <CartesianGrid vertical={false} /> : null}\n <XAxis dataKey={index} tickLine={false} axisLine={false} tickMargin={8} />\n <YAxis tickLine={false} axisLine={false} tickFormatter={valueFormatter} />\n {tip}\n {leg}\n {series.map((key, i) => (\n <Line\n key={key}\n type=\"monotone\"\n dataKey={key}\n name={key}\n stroke={seriesColor(config, key, i)}\n strokeWidth={2}\n dot={false}\n activeDot={{ r: 4 }}\n />\n ))}\n </LineChart>\n );\n }\n\n case \"area\": {\n const { rows, indexBy: index, keys: series } = toRows(data as ChartRow[] | ChartSeries[], indexBy, keys);\n return (\n <AreaChart data={rows} margin={MARGIN}>\n {grid ? <CartesianGrid vertical={false} /> : null}\n <XAxis dataKey={index} tickLine={false} axisLine={false} tickMargin={8} />\n <YAxis tickLine={false} axisLine={false} tickFormatter={valueFormatter} />\n {tip}\n {leg}\n {series.map((key, i) => (\n <Area\n key={key}\n type=\"monotone\"\n dataKey={key}\n name={key}\n stroke={seriesColor(config, key, i)}\n fill={seriesColor(config, key, i)}\n fillOpacity={0.2}\n strokeWidth={2}\n stackId={stacked ? \"stack\" : undefined}\n />\n ))}\n </AreaChart>\n );\n }\n\n case \"pie\":\n case \"donut\": {\n const slices = toSlices(data as ChartSlice[]);\n const fillOf = (i: number) => seriesColor(config, slices[i]?.id ?? String(i), i);\n return (\n <PieChart margin={MARGIN}>\n {tip}\n {leg}\n <Pie\n data={slices}\n dataKey=\"value\"\n nameKey=\"name\"\n innerRadius={type === \"donut\" ? \"55%\" : 0}\n outerRadius=\"80%\"\n paddingAngle={type === \"donut\" ? 2 : 0}\n strokeWidth={1}\n isAnimationActive={animate}\n label={labels === \"none\" ? undefined : arcLabel(labels, colourOn, fillOf, valueFormatter)}\n // The labels are inside their arcs, so there is nothing to lead to.\n labelLine={false}\n >\n {slices.map((slice, i) => (\n <Cell key={slice.id} fill={fillOf(i)} />\n ))}\n </Pie>\n </PieChart>\n );\n }\n\n case \"scatter\":\n case \"scatterplot\": {\n const series = data as ChartSeries[];\n return (\n <ScatterChart margin={MARGIN}>\n {grid ? <CartesianGrid /> : null}\n <XAxis dataKey=\"x\" type=\"number\" name=\"x\" tickLine={false} axisLine={false} tickMargin={8} />\n <YAxis dataKey=\"y\" type=\"number\" name=\"y\" tickLine={false} axisLine={false} tickFormatter={valueFormatter} />\n {tip}\n {leg}\n {series.map((s, i) => (\n <Scatter key={String(s.id)} name={String(s.id)} data={s.data} fill={seriesColor(config, String(s.id), i)} />\n ))}\n </ScatterChart>\n );\n }\n\n case \"radar\": {\n const { rows, indexBy: index, keys: series } = toRows(data as ChartRow[] | ChartSeries[], indexBy, keys);\n return (\n <RadarChart data={rows} margin={MARGIN}>\n {grid ? <PolarGrid /> : null}\n <PolarAngleAxis dataKey={index} />\n <PolarRadiusAxis tick={false} axisLine={false} />\n {tip}\n {leg}\n {series.map((key, i) => (\n <Radar\n key={key}\n dataKey={key}\n name={key}\n stroke={seriesColor(config, key, i)}\n fill={seriesColor(config, key, i)}\n fillOpacity={0.2}\n strokeWidth={2}\n />\n ))}\n </RadarChart>\n );\n }\n\n case \"funnel\": {\n const slices = toSlices(data as ChartSlice[]);\n return (\n <FunnelChart margin={MARGIN}>\n {tip}\n {leg}\n <Funnel data={slices} dataKey=\"value\" nameKey=\"name\">\n {slices.map((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Q;MAAQ,SAAQ;MAC3C,UAAA,OAAO,KAAK,OAAO,MAClB,oBAAC,MAAD,EAAqB,MAAM,YAAY,QAAQ,MAAM,IAAI,CAAC,EAAI,GAAnD,MAAM,EAA6C,CAC/D;KACK,CAAA;IACG;;EAEjB;CACF;AACF"}
|
package/dist/index.d.ts
CHANGED
|
@@ -9,13 +9,13 @@ import { useDataTable } from "./components/data-table/use-data-table.js";
|
|
|
9
9
|
import { ExportCell, ExportSheet, downloadCsv, downloadExcel, toCsv, toSheet } from "./components/data-table/export.js";
|
|
10
10
|
import { A2UIColumn, A2UIErrorCard, A2UINodeInfo, A2UIResolvedAction, A2UIRow, A2UITableSource, A2UIView, A2UIViewProps } from "./a2ui/views.js";
|
|
11
11
|
import { A2UICatalogue, A2UICatalogueEntry, A2UIExample, A2UIGroup, A2UI_CATALOGUE_ID, catalogueNames, defaultCatalogue } from "./a2ui/catalogue.js";
|
|
12
|
-
import { A2UICatalogueDoc, A2UIComponentDoc, JsonSchema
|
|
12
|
+
import { A2UICatalogueDoc, A2UIComponentDoc, JsonSchema } from "./a2ui/catalogue-doc.js";
|
|
13
13
|
import { A2UIRenderer, A2UIRendererProps } from "./a2ui/renderer.js";
|
|
14
14
|
import "./a2ui.js";
|
|
15
15
|
import { ChartContainer, ChartContainerProps, ChartEmpty, ChartError, ChartLegendContent, ChartLegendContentProps, ChartLoading, ChartTooltipContent, ChartTooltipContentProps, seriesColor, useChart } from "./components/chart/container.js";
|
|
16
16
|
import { Chart, ChartProps } from "./components/chart/chart.js";
|
|
17
17
|
import { ChartLegend, ChartTooltip } from "./components/chart/recharts-parts.js";
|
|
18
|
-
import { NivoTheme
|
|
18
|
+
import { NivoTheme } from "./components/chart/nivo-theme.js";
|
|
19
19
|
import { ChartScales, VIZ_SERIES_COUNT, chartScales, resolveColor, resolveVizSeries, toHex, vizSeriesVars, vizVar } from "./components/chart/tokens.js";
|
|
20
20
|
import { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, ComposedChart, Funnel, FunnelChart, LabelList, Line, LineChart, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Radar, RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, XAxis, YAxis } from "./components/chart/index.js";
|
|
21
21
|
import "./chart.js";
|
|
@@ -73,4 +73,4 @@ import { CodeRendererProps, Markdown, MarkdownComponents as Components, Markdown
|
|
|
73
73
|
import "./markdown.js";
|
|
74
74
|
import { SortableHandle, SortableHandleProps, SortableList, SortableListProps, SortableRenderState, SortableReorderDetails, arrayMove } from "./components/sortable-list.js";
|
|
75
75
|
import "./sortable-list.js";
|
|
76
|
-
export { type A2UIAction, type A2UIActionSpec, type A2UIBeginRendering, type A2UICatalogue, type A2UICatalogueDoc, type A2UICatalogueEntry, type A2UIChildList, type A2UIChildren, type A2UIColumn, type A2UIComponentDoc, type A2UIComponentSpec, type A2UICreateSurface, type A2UIDataBinding, type A2UIDeleteSurface, A2UIErrorCard, type A2UIExample, type A2UIFoldResult, type A2UIGroup, type A2UIMessage, type A2UIMessageInput, type A2UINodeInfo, type A2UIPropertyValue, A2UIRenderer, type A2UIRendererProps, type A2UIResolvedAction, type A2UIRow, type A2UISurface, type A2UITableSource, type A2UIUpdateComponents, type A2UIUpdateDataModel, type A2UIView, type A2UIViewProps, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, type Accept, Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertIcon, type AlertProps, AlertTitle, Area, AreaChart, Avatar, AvatarFallback, AvatarImage, Badge, type BadgeProps, Bar, BarChart, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, type BreadcrumbLinkProps, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, ButtonLink, type ButtonLinkProps, type ButtonProps, Calendar, CalendarDayButton, type CalendarProps, Card, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, CartesianGrid, Cell, Chart, type ChartConfig, ChartContainer, type ChartContainerProps, type ChartDataFor, type ChartDay, ChartEmpty, type ChartEngine, ChartError, type ChartLabels, ChartLegend, ChartLegendContent, type ChartLegendContentProps, ChartLoading, type ChartMatrix, type ChartPoint, type ChartProps, type ChartRenderer, type ChartRow, type ChartScale, type ChartScales, type ChartSeries, type ChartSlice, ChartTooltip, ChartTooltipContent, type ChartTooltipContentProps, type ChartTree, type ChartType, Checkbox, type CheckboxProps, Chip, type ChipProps, type ClientSource, type CodeRendererProps, Combobox, ComboboxChip, type ComboboxChipProps, ComboboxChips, type ComboboxChipsProps, ComboboxClear, ComboboxCollection, ComboboxContent, type ComboboxContentProps, ComboboxEmpty, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, type ComboboxInputProps, ComboboxItem, ComboboxSeparator, ComboboxStatus, ComboboxTrigger, ComboboxValue, Command, CommandDialog, type CommandDialogProps, CommandEmpty, CommandGroup, CommandInput, CommandItem, type CommandItemProps, CommandList, CommandLoading, CommandSeparator, CommandShortcut, ComposedChart, type CortenaTheme, type CortenaThemeMessage, DEFAULT_THEME_STORAGE_KEY, type DataSource, DataTable, type DataTableCell, type DataTableColumn, type DataTableColumnDef, DataTableColumnHeader, type DataTableColumnHeaderProps, type DataTableColumnMeta, type DataTableEditable, type DataTableEditingCell, DataTableExportMenu, type DataTableExportMenuProps, DataTableFacetedFilter, type DataTableFacetedFilterOption, type DataTableFacetedFilterProps, type DataTableFeatures, type DataTableInstance, DataTablePagination, type DataTablePaginationMode, type DataTablePaginationProps, type DataTableProps, type DataTableRow, type DataTableState, type DataTableTable, DataTableToolbar, type DataTableToolbarProps, DataTableView, DataTableViewOptions, type DataTableViewOptionsProps, type DataTableViewProps, DateField, type DateFieldProps, DatePicker, type DatePickerProps, DateRangePicker, type DateRangePickerProps, Dialog, DialogBody, DialogClose, DialogContent, type DialogContentProps, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, type DropdownMenuContentProps, DropdownMenuGroup, DropdownMenuItem, type DropdownMenuItemProps, DropdownMenuLabel, type DropdownMenuLabelProps, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, type DropdownMenuSubTriggerProps, DropdownMenuTrigger, Dropzone, type DropzoneProps, type DropzoneState, EmptyState, type EmptyStateProps, ErrorBanner, type ErrorBannerProps, type ExportCell, type ExportSheet, Field, FieldContent, FieldControl, type FieldControlProps, FieldDescription, type FieldDescriptionProps, FieldError, type FieldErrorItem, type FieldErrorProps, FieldGroup, FieldLabel, type FieldLabelProps, type FieldProps, Fieldset, FieldsetLegend, type FieldsetLegendProps, type FieldsetProps, FileList, type FileListProps, type FileRejection, Form, FormControl, type FormControlProps, FormDescription, type FormDescriptionProps, FormField, FormItem, type FormItemProps, FormLabel, type FormLabelProps, FormMessage, type FormMessageProps, Funnel, FunnelChart, Input, type InputProps, type JsonSchema, Kbd, Label, LabelList, type LabelProps, Line, LineChart, LoadingSkeleton, type LoadingSkeletonPreset, type LoadingSkeletonProps, Markdown, type Components as MarkdownComponents, type MarkdownProps, NIVO_TYPES, type NivoTheme, PageHeader, type PageHeaderProps, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Popover, PopoverClose, PopoverContent, type PopoverContentProps, PopoverDescription, PopoverTitle, PopoverTrigger, Progress, ProgressIndicator, ProgressLabel, type ProgressProps, ProgressTrack, ProgressValue, RECHARTS_TYPES, Radar, RadarChart, RadioGroup, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, RechartsLegend, RechartsTooltip, ReferenceLine, type ResolvedCortenaTheme, ResponsiveContainer, Scatter, ScatterChart, ScrollArea, type ScrollAreaProps, ScrollBar, SectionCard, type SectionCardProps, Segmented, type SegmentedOption, type SegmentedProps, Select, SelectContent, type SelectContentProps, SelectGroup, SelectItem, SelectLabel, type SelectProps, SelectSeparator, SelectTrigger, type SelectTriggerProps, SelectValue, Separator, type SeparatorProps, type ServerSource, Sheet, SheetClose, SheetContent, type SheetContentProps, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, type SheetProps, SheetTitle, SheetTrigger, Skeleton, SortableHandle, type SortableHandleProps, SortableList, type SortableListProps, type SortableRenderState, type SortableReorderDetails, Spinner, type SpinnerProps, StatusDot, type StatusDotProps, type StatusDotTone, type SubmitHandler, Switch, type SwitchProps, THEME_MESSAGE_TYPE, type TableQuery, type TableResult, Tabs, TabsContent, TabsIndicator, TabsList, TabsTrigger, Textarea, type TextareaProps, Toast, type ToastProps, Toaster, type ToasterProps, Toolbar, ToolbarEnd, type ToolbarProps, ToolbarSeparator, ToolbarStart, Tooltip, TooltipContent, type TooltipContentProps, TooltipProvider, TooltipTrigger, type UseCortenaThemeOptions, type UseCortenaThemeResult, type UseDataTableOptions, type UseFormFieldReturn, type UseFormReturn, VIZ_SERIES_COUNT, XAxis, YAxis, alertVariants, applyStoredTheme, applyTheme, arrayMove, badgeVariants,
|
|
76
|
+
export { type A2UIAction, type A2UIActionSpec, type A2UIBeginRendering, type A2UICatalogue, type A2UICatalogueDoc, type A2UICatalogueEntry, type A2UIChildList, type A2UIChildren, type A2UIColumn, type A2UIComponentDoc, type A2UIComponentSpec, type A2UICreateSurface, type A2UIDataBinding, type A2UIDeleteSurface, A2UIErrorCard, type A2UIExample, type A2UIFoldResult, type A2UIGroup, type A2UIMessage, type A2UIMessageInput, type A2UINodeInfo, type A2UIPropertyValue, A2UIRenderer, type A2UIRendererProps, type A2UIResolvedAction, type A2UIRow, type A2UISurface, type A2UITableSource, type A2UIUpdateComponents, type A2UIUpdateDataModel, type A2UIView, type A2UIViewProps, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, type Accept, Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertIcon, type AlertProps, AlertTitle, Area, AreaChart, Avatar, AvatarFallback, AvatarImage, Badge, type BadgeProps, Bar, BarChart, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, type BreadcrumbLinkProps, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, ButtonLink, type ButtonLinkProps, type ButtonProps, Calendar, CalendarDayButton, type CalendarProps, Card, CardContent, CardDescription, CardFooter, CardHeader, type CardProps, CardTitle, CartesianGrid, Cell, Chart, type ChartConfig, ChartContainer, type ChartContainerProps, type ChartDataFor, type ChartDay, ChartEmpty, type ChartEngine, ChartError, type ChartLabels, ChartLegend, ChartLegendContent, type ChartLegendContentProps, ChartLoading, type ChartMatrix, type ChartPoint, type ChartProps, type ChartRenderer, type ChartRow, type ChartScale, type ChartScales, type ChartSeries, type ChartSlice, ChartTooltip, ChartTooltipContent, type ChartTooltipContentProps, type ChartTree, type ChartType, Checkbox, type CheckboxProps, Chip, type ChipProps, type ClientSource, type CodeRendererProps, Combobox, ComboboxChip, type ComboboxChipProps, ComboboxChips, type ComboboxChipsProps, ComboboxClear, ComboboxCollection, ComboboxContent, type ComboboxContentProps, ComboboxEmpty, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, type ComboboxInputProps, ComboboxItem, ComboboxSeparator, ComboboxStatus, ComboboxTrigger, ComboboxValue, Command, CommandDialog, type CommandDialogProps, CommandEmpty, CommandGroup, CommandInput, CommandItem, type CommandItemProps, CommandList, CommandLoading, CommandSeparator, CommandShortcut, ComposedChart, type CortenaTheme, type CortenaThemeMessage, DEFAULT_THEME_STORAGE_KEY, type DataSource, DataTable, type DataTableCell, type DataTableColumn, type DataTableColumnDef, DataTableColumnHeader, type DataTableColumnHeaderProps, type DataTableColumnMeta, type DataTableEditable, type DataTableEditingCell, DataTableExportMenu, type DataTableExportMenuProps, DataTableFacetedFilter, type DataTableFacetedFilterOption, type DataTableFacetedFilterProps, type DataTableFeatures, type DataTableInstance, DataTablePagination, type DataTablePaginationMode, type DataTablePaginationProps, type DataTableProps, type DataTableRow, type DataTableState, type DataTableTable, DataTableToolbar, type DataTableToolbarProps, DataTableView, DataTableViewOptions, type DataTableViewOptionsProps, type DataTableViewProps, DateField, type DateFieldProps, DatePicker, type DatePickerProps, DateRangePicker, type DateRangePickerProps, Dialog, DialogBody, DialogClose, DialogContent, type DialogContentProps, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, type DropdownMenuContentProps, DropdownMenuGroup, DropdownMenuItem, type DropdownMenuItemProps, DropdownMenuLabel, type DropdownMenuLabelProps, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, type DropdownMenuSubTriggerProps, DropdownMenuTrigger, Dropzone, type DropzoneProps, type DropzoneState, EmptyState, type EmptyStateProps, ErrorBanner, type ErrorBannerProps, type ExportCell, type ExportSheet, Field, FieldContent, FieldControl, type FieldControlProps, FieldDescription, type FieldDescriptionProps, FieldError, type FieldErrorItem, type FieldErrorProps, FieldGroup, FieldLabel, type FieldLabelProps, type FieldProps, Fieldset, FieldsetLegend, type FieldsetLegendProps, type FieldsetProps, FileList, type FileListProps, type FileRejection, Form, FormControl, type FormControlProps, FormDescription, type FormDescriptionProps, FormField, FormItem, type FormItemProps, FormLabel, type FormLabelProps, FormMessage, type FormMessageProps, Funnel, FunnelChart, Input, type InputProps, type JsonSchema, Kbd, Label, LabelList, type LabelProps, Line, LineChart, LoadingSkeleton, type LoadingSkeletonPreset, type LoadingSkeletonProps, Markdown, type Components as MarkdownComponents, type MarkdownProps, NIVO_TYPES, type NivoTheme, PageHeader, type PageHeaderProps, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Popover, PopoverClose, PopoverContent, type PopoverContentProps, PopoverDescription, PopoverTitle, PopoverTrigger, Progress, ProgressIndicator, ProgressLabel, type ProgressProps, ProgressTrack, ProgressValue, RECHARTS_TYPES, Radar, RadarChart, RadioGroup, RadioGroupItem, type RadioGroupItemProps, type RadioGroupProps, RechartsLegend, RechartsTooltip, ReferenceLine, type ResolvedCortenaTheme, ResponsiveContainer, Scatter, ScatterChart, ScrollArea, type ScrollAreaProps, ScrollBar, SectionCard, type SectionCardProps, Segmented, type SegmentedOption, type SegmentedProps, Select, SelectContent, type SelectContentProps, SelectGroup, SelectItem, SelectLabel, type SelectProps, SelectSeparator, SelectTrigger, type SelectTriggerProps, SelectValue, Separator, type SeparatorProps, type ServerSource, Sheet, SheetClose, SheetContent, type SheetContentProps, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, type SheetProps, SheetTitle, SheetTrigger, Skeleton, SortableHandle, type SortableHandleProps, SortableList, type SortableListProps, type SortableRenderState, type SortableReorderDetails, Spinner, type SpinnerProps, StatusDot, type StatusDotProps, type StatusDotTone, type SubmitHandler, Switch, type SwitchProps, THEME_MESSAGE_TYPE, type TableQuery, type TableResult, Tabs, TabsContent, TabsIndicator, TabsList, TabsTrigger, Textarea, type TextareaProps, Toast, type ToastProps, Toaster, type ToasterProps, Toolbar, ToolbarEnd, type ToolbarProps, ToolbarSeparator, ToolbarStart, Tooltip, TooltipContent, type TooltipContentProps, TooltipProvider, TooltipTrigger, type UseCortenaThemeOptions, type UseCortenaThemeResult, type UseDataTableOptions, type UseFormFieldReturn, type UseFormReturn, VIZ_SERIES_COUNT, XAxis, YAxis, alertVariants, applyStoredTheme, applyTheme, arrayMove, badgeVariants, buttonVariants, catalogueNames, chartEngine, chartScales, chipVariants, cn, createColumnHelper, dataTableFeatures, defaultCatalogue, downloadCsv, downloadExcel, fieldVariants, foldMessages, formatDateDefault, formatDateISO, formatDateLong, formatDateShort, formatFileSize, formatRelative, getAtPointer, getThemeInitScript, inputClassName, isDataBinding, labelVariants, markdownSanitizeSchema, parseA2UIMessages, parseDateDefault, parseDateISO, pointerSegments, readAction, readChildren, readComponent, readStoredTheme, resolveColor, resolvePointer, resolveValue, resolveVizSeries, seriesColor, setAtPointer, sheetVariants, textareaClassName, themeFromBackground, themeFromMessage, themeInitScript, toCsv, toHex, toSheet, toastVariants, useChart, useComboboxFilter, useCortenaTheme, useDataTable, useForm, useFormField, useToast, vizSeriesVars, vizVar, zodResolver };
|
package/dist/index.js
CHANGED
|
@@ -56,13 +56,11 @@ import { ChartContainer, ChartEmpty, ChartError, ChartLegendContent, ChartLoadin
|
|
|
56
56
|
import { NIVO_TYPES, RECHARTS_TYPES, chartEngine } from "./components/chart/types.js";
|
|
57
57
|
import { Chart } from "./components/chart/chart.js";
|
|
58
58
|
import { ChartLegend, ChartTooltip } from "./components/chart/recharts-parts.js";
|
|
59
|
-
import { nivoTheme, useNivoTheme } from "./components/chart/nivo-theme.js";
|
|
60
59
|
import { Area, AreaChart, Bar, BarChart, CartesianGrid, Cell, ComposedChart, Funnel, FunnelChart, LabelList, Line, LineChart, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Radar, RadarChart, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, XAxis, YAxis } from "./components/chart/index.js";
|
|
61
60
|
import { Markdown, markdownSanitizeSchema } from "./components/markdown.js";
|
|
62
61
|
import { A2UIErrorCard } from "./a2ui/views.js";
|
|
63
62
|
import { A2UI_CATALOGUE_ID, catalogueNames, defaultCatalogue } from "./a2ui/catalogue.js";
|
|
64
63
|
import { A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, foldMessages, getAtPointer, isDataBinding, parseA2UIMessages, pointerSegments, readAction, readChildren, readComponent, resolvePointer, resolveValue, setAtPointer } from "./a2ui/message.js";
|
|
65
|
-
import { buildCatalogueDoc, catalogueMarkdown, exampleMessages } from "./a2ui/catalogue-doc.js";
|
|
66
64
|
import { A2UIRenderer } from "./a2ui/renderer.js";
|
|
67
65
|
import { SortableHandle, SortableList, arrayMove } from "./components/sortable-list.js";
|
|
68
|
-
export { A2UIErrorCard, A2UIRenderer, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertIcon, AlertTitle, Area, AreaChart, Avatar, AvatarFallback, AvatarImage, Badge, Bar, BarChart, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, ButtonLink, Calendar, CalendarDayButton, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CartesianGrid, Cell, Chart, ChartContainer, ChartEmpty, ChartError, ChartLegend, ChartLegendContent, ChartLoading, ChartTooltip, ChartTooltipContent, Checkbox, Chip, Combobox, ComboboxChip, ComboboxChips, ComboboxClear, ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, ComboboxItem, ComboboxSeparator, ComboboxStatus, ComboboxTrigger, ComboboxValue, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandLoading, CommandSeparator, CommandShortcut, ComposedChart, DEFAULT_THEME_STORAGE_KEY, DataTable, DataTableColumnHeader, DataTableExportMenu, DataTableFacetedFilter, DataTablePagination, DataTableToolbar, DataTableView, DataTableViewOptions, DateField, DatePicker, DateRangePicker, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Dropzone, EmptyState, ErrorBanner, Field, FieldContent, FieldControl, FieldDescription, FieldError, FieldGroup, FieldLabel, Fieldset, FieldsetLegend, FileList, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, Funnel, FunnelChart, Input, Kbd, Label, LabelList, Line, LineChart, LoadingSkeleton, Markdown, NIVO_TYPES, PageHeader, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger, Progress, ProgressIndicator, ProgressLabel, ProgressTrack, ProgressValue, RECHARTS_TYPES, Radar, RadarChart, RadioGroup, RadioGroupItem, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, ScrollArea, ScrollBar, SectionCard, Segmented, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, Skeleton, SortableHandle, SortableList, Spinner, StatusDot, Switch, THEME_MESSAGE_TYPE, Tabs, TabsContent, TabsIndicator, TabsList, TabsTrigger, Textarea, Toast, Toaster, Toolbar, ToolbarEnd, ToolbarSeparator, ToolbarStart, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, VIZ_SERIES_COUNT, XAxis, YAxis, alertVariants, applyStoredTheme, applyTheme, arrayMove, badgeVariants,
|
|
66
|
+
export { A2UIErrorCard, A2UIRenderer, A2UI_CATALOGUE_ID, A2UI_DEFAULT_SURFACE_ID, A2UI_VERSION, Accordion, AccordionContent, AccordionItem, AccordionTrigger, Alert, AlertDescription, AlertIcon, AlertTitle, Area, AreaChart, Avatar, AvatarFallback, AvatarImage, Badge, Bar, BarChart, Breadcrumb, BreadcrumbEllipsis, BreadcrumbItem, BreadcrumbLink, BreadcrumbList, BreadcrumbPage, BreadcrumbSeparator, Button, ButtonLink, Calendar, CalendarDayButton, Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle, CartesianGrid, Cell, Chart, ChartContainer, ChartEmpty, ChartError, ChartLegend, ChartLegendContent, ChartLoading, ChartTooltip, ChartTooltipContent, Checkbox, Chip, Combobox, ComboboxChip, ComboboxChips, ComboboxClear, ComboboxCollection, ComboboxContent, ComboboxEmpty, ComboboxGroup, ComboboxGroupLabel, ComboboxInput, ComboboxItem, ComboboxSeparator, ComboboxStatus, ComboboxTrigger, ComboboxValue, Command, CommandDialog, CommandEmpty, CommandGroup, CommandInput, CommandItem, CommandList, CommandLoading, CommandSeparator, CommandShortcut, ComposedChart, DEFAULT_THEME_STORAGE_KEY, DataTable, DataTableColumnHeader, DataTableExportMenu, DataTableFacetedFilter, DataTablePagination, DataTableToolbar, DataTableView, DataTableViewOptions, DateField, DatePicker, DateRangePicker, Dialog, DialogBody, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogOverlay, DialogPortal, DialogTitle, DialogTrigger, DropdownMenu, DropdownMenuCheckboxItem, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuPortal, DropdownMenuRadioGroup, DropdownMenuRadioItem, DropdownMenuSeparator, DropdownMenuShortcut, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, Dropzone, EmptyState, ErrorBanner, Field, FieldContent, FieldControl, FieldDescription, FieldError, FieldGroup, FieldLabel, Fieldset, FieldsetLegend, FileList, Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage, Funnel, FunnelChart, Input, Kbd, Label, LabelList, Line, LineChart, LoadingSkeleton, Markdown, NIVO_TYPES, PageHeader, Pie, PieChart, PolarAngleAxis, PolarGrid, PolarRadiusAxis, Popover, PopoverClose, PopoverContent, PopoverDescription, PopoverTitle, PopoverTrigger, Progress, ProgressIndicator, ProgressLabel, ProgressTrack, ProgressValue, RECHARTS_TYPES, Radar, RadarChart, RadioGroup, RadioGroupItem, RechartsLegend, RechartsTooltip, ReferenceLine, ResponsiveContainer, Scatter, ScatterChart, ScrollArea, ScrollBar, SectionCard, Segmented, Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue, Separator, Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetOverlay, SheetPortal, SheetTitle, SheetTrigger, Skeleton, SortableHandle, SortableList, Spinner, StatusDot, Switch, THEME_MESSAGE_TYPE, Tabs, TabsContent, TabsIndicator, TabsList, TabsTrigger, Textarea, Toast, Toaster, Toolbar, ToolbarEnd, ToolbarSeparator, ToolbarStart, Tooltip, TooltipContent, TooltipProvider, TooltipTrigger, VIZ_SERIES_COUNT, XAxis, YAxis, alertVariants, applyStoredTheme, applyTheme, arrayMove, badgeVariants, buttonVariants, catalogueNames, chartEngine, chartScales, chipVariants, cn, createColumnHelper, dataTableFeatures, defaultCatalogue, downloadCsv, downloadExcel, fieldVariants, foldMessages, formatDateDefault, formatDateISO, formatDateLong, formatDateShort, formatFileSize, formatRelative, getAtPointer, getThemeInitScript, inputClassName, isDataBinding, labelVariants, markdownSanitizeSchema, parseA2UIMessages, parseDateDefault, parseDateISO, pointerSegments, readAction, readChildren, readComponent, readStoredTheme, resolveColor, resolvePointer, resolveValue, resolveVizSeries, seriesColor, setAtPointer, sheetVariants, textareaClassName, themeFromBackground, themeFromMessage, themeInitScript, toCsv, toHex, toSheet, toastVariants, useChart, useComboboxFilter, useCortenaTheme, useDataTable, useForm, useFormField, useToast, vizSeriesVars, vizVar, zodResolver };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortena-ui",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.2",
|
|
4
4
|
"description": "Cortena UI — the shared React component library for cortenaweb and every Cortena extension. shadcn over Base UI, styled entirely from cortena-design tokens.",
|
|
5
5
|
"license": "UNLICENSED",
|
|
6
6
|
"repository": {
|
package/src/a2ui/index.ts
CHANGED
|
@@ -24,7 +24,12 @@ export {
|
|
|
24
24
|
defaultCatalogue,
|
|
25
25
|
} from "./catalogue";
|
|
26
26
|
export type { A2UICatalogue, A2UICatalogueEntry, A2UIExample, A2UIGroup } from "./catalogue";
|
|
27
|
-
|
|
27
|
+
// The catalogue doc generator is a build-time tool (`pnpm a2ui:catalogue`
|
|
28
|
+
// loads it from source) and the one place that needs zod 4's `toJSONSchema`.
|
|
29
|
+
// It is not exported from the runtime entry: a consumer whose lockfile
|
|
30
|
+
// resolves the zod peer to 3.x must still bundle this package, and a bundler
|
|
31
|
+
// that checks ESM exports (Next's webpack) fails the build on a namespace
|
|
32
|
+
// member that does not exist rather than trusting the runtime guard.
|
|
28
33
|
export type { A2UICatalogueDoc, A2UIComponentDoc, JsonSchema } from "./catalogue-doc";
|
|
29
34
|
export {
|
|
30
35
|
A2UI_DEFAULT_SURFACE_ID,
|
|
@@ -24,7 +24,10 @@ export {
|
|
|
24
24
|
// engine; see the note in recharts-parts.tsx.
|
|
25
25
|
export { ChartLegend, ChartTooltip } from "./recharts-parts";
|
|
26
26
|
export type { ChartContainerProps, ChartLegendContentProps, ChartTooltipContentProps } from "./container";
|
|
27
|
-
|
|
27
|
+
// The Nivo theme is not re-exported: `nivo-theme.ts` reads `@nivo/core`,
|
|
28
|
+
// `@nivo/legends` and `@nivo/theming` for real, so a static export here puts
|
|
29
|
+
// 63 kB of the engine on the eager path of every chart consumer. It stays
|
|
30
|
+
// reachable from the Nivo chunk, which is the only place that needs it.
|
|
28
31
|
export type { NivoTheme } from "./nivo-theme";
|
|
29
32
|
export {
|
|
30
33
|
chartScales,
|
|
@@ -48,6 +48,12 @@ export interface RechartsRenderProps {
|
|
|
48
48
|
/** Per-arc labels for pie and donut. Ignored by every other type. */
|
|
49
49
|
labels: ChartLabels;
|
|
50
50
|
valueFormatter?: (value: number) => string;
|
|
51
|
+
/**
|
|
52
|
+
* Entry animation. Off under `testMode`: Recharts draws pie labels only
|
|
53
|
+
* once the animation has finished, so a test that asserts on them would
|
|
54
|
+
* otherwise be racing the clock.
|
|
55
|
+
*/
|
|
56
|
+
animate?: boolean;
|
|
51
57
|
}
|
|
52
58
|
|
|
53
59
|
const MARGIN = { top: 8, right: 8, bottom: 0, left: 0 };
|
|
@@ -148,6 +154,7 @@ export function RechartsChart({
|
|
|
148
154
|
tooltip,
|
|
149
155
|
labels,
|
|
150
156
|
valueFormatter,
|
|
157
|
+
animate = true,
|
|
151
158
|
}: RechartsRenderProps): React.ReactElement {
|
|
152
159
|
// Arc labels sit on top of a series colour, so their ink depends on which
|
|
153
160
|
// colour and on the theme. `useThemeVersion` is the cache key for that DOM
|
|
@@ -256,6 +263,7 @@ export function RechartsChart({
|
|
|
256
263
|
outerRadius="80%"
|
|
257
264
|
paddingAngle={type === "donut" ? 2 : 0}
|
|
258
265
|
strokeWidth={1}
|
|
266
|
+
isAnimationActive={animate}
|
|
259
267
|
label={labels === "none" ? undefined : arcLabel(labels, colourOn, fillOf, valueFormatter)}
|
|
260
268
|
// The labels are inside their arcs, so there is nothing to lead to.
|
|
261
269
|
labelLine={false}
|
|
@@ -1,169 +0,0 @@
|
|
|
1
|
-
"use client";
|
|
2
|
-
import { A2UI_CATALOGUE_ID, defaultCatalogue } from "./catalogue.js";
|
|
3
|
-
import { A2UI_VERSION } from "./message.js";
|
|
4
|
-
import { z } from "zod";
|
|
5
|
-
//#region src/a2ui/catalogue-doc.ts
|
|
6
|
-
/**
|
|
7
|
-
* Catalogue documentation generator.
|
|
8
|
-
*
|
|
9
|
-
* Emits a machine-readable description of the catalogue — every component's
|
|
10
|
-
* name, group, summary, property schema, events and a worked example — plus a
|
|
11
|
-
* markdown rendering of the same thing.
|
|
12
|
-
*
|
|
13
|
-
* This exists so the "Rich Content" system-prompt section can be *generated*
|
|
14
|
-
* from the catalogue rather than written beside it (DESIGN-34). A prompt that
|
|
15
|
-
* describes a component the renderer does not have, or omits one it does, is
|
|
16
|
-
* the failure `05-agent-ui.md` calls out; the only way to prevent it is for
|
|
17
|
-
* both to come from one object.
|
|
18
|
-
*
|
|
19
|
-
* `pnpm a2ui:catalogue` writes `dist-a2ui/catalogue.json` and `.md`.
|
|
20
|
-
*/
|
|
21
|
-
/**
|
|
22
|
-
* zod 4 ships `toJSONSchema`; zod 3 does not.
|
|
23
|
-
*
|
|
24
|
-
* The package's zod peer allows both, so this is checked rather than assumed —
|
|
25
|
-
* emitting `{}` for every component would produce a doc that passes every test
|
|
26
|
-
* and teaches an agent nothing, which is the silent-success failure this whole
|
|
27
|
-
* package's lint exists to avoid.
|
|
28
|
-
*/
|
|
29
|
-
function toJsonSchema(schema) {
|
|
30
|
-
const converter = z.toJSONSchema;
|
|
31
|
-
if (typeof converter !== "function") throw new Error("Generating the A2UI catalogue doc needs zod 4 (z.toJSONSchema). The installed zod is 3.x.");
|
|
32
|
-
return converter(schema, {
|
|
33
|
-
io: "input",
|
|
34
|
-
unrepresentable: "any"
|
|
35
|
-
});
|
|
36
|
-
}
|
|
37
|
-
/** Build the machine-readable catalogue document. */
|
|
38
|
-
function buildCatalogueDoc(catalogue = defaultCatalogue) {
|
|
39
|
-
const components = Object.values(catalogue).map((entry) => {
|
|
40
|
-
const schema = toJsonSchema(entry.props);
|
|
41
|
-
const properties = schema.properties ?? {};
|
|
42
|
-
const required = Array.isArray(schema.required) ? schema.required : [];
|
|
43
|
-
return {
|
|
44
|
-
name: entry.name,
|
|
45
|
-
group: entry.group,
|
|
46
|
-
summary: entry.summary,
|
|
47
|
-
children: entry.children,
|
|
48
|
-
events: [...entry.events],
|
|
49
|
-
props: properties,
|
|
50
|
-
required,
|
|
51
|
-
example: {
|
|
52
|
-
components: entry.example.components,
|
|
53
|
-
...entry.example.data ? { data: entry.example.data } : {}
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
}).sort((a, b) => a.name.localeCompare(b.name));
|
|
57
|
-
return {
|
|
58
|
-
catalogueId: A2UI_CATALOGUE_ID,
|
|
59
|
-
protocol: A2UI_VERSION,
|
|
60
|
-
generator: "cortena-ui/a2ui",
|
|
61
|
-
components
|
|
62
|
-
};
|
|
63
|
-
}
|
|
64
|
-
const GROUP_ORDER = [
|
|
65
|
-
"layout",
|
|
66
|
-
"text",
|
|
67
|
-
"input",
|
|
68
|
-
"feedback",
|
|
69
|
-
"data"
|
|
70
|
-
];
|
|
71
|
-
const GROUP_TITLE = {
|
|
72
|
-
layout: "Layout",
|
|
73
|
-
text: "Text and media",
|
|
74
|
-
input: "Inputs and actions",
|
|
75
|
-
feedback: "Feedback",
|
|
76
|
-
data: "Data"
|
|
77
|
-
};
|
|
78
|
-
/** One-line type summary for a JSON Schema property, for the markdown table. */
|
|
79
|
-
function describeType(schema) {
|
|
80
|
-
if (typeof schema !== "object" || schema === null) return "any";
|
|
81
|
-
const node = schema;
|
|
82
|
-
if (Array.isArray(node.enum)) return node.enum.map((value) => JSON.stringify(value)).join(" \\| ");
|
|
83
|
-
if (Array.isArray(node.anyOf) || Array.isArray(node.oneOf)) return (node.anyOf ?? node.oneOf).map((option) => describeType(option)).join(" \\| ");
|
|
84
|
-
if (node.const !== void 0) return JSON.stringify(node.const);
|
|
85
|
-
if (node.type === "array") return `${describeType(node.items)}[]`;
|
|
86
|
-
if (typeof node.type === "string") return node.type;
|
|
87
|
-
if (Array.isArray(node.type)) return node.type.join(" \\| ");
|
|
88
|
-
return "any";
|
|
89
|
-
}
|
|
90
|
-
function escapeCell(text) {
|
|
91
|
-
return text.replace(/\|/g, "\\|").replace(/\n+/g, " ").trim();
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Render the catalogue document as markdown.
|
|
95
|
-
*
|
|
96
|
-
* The output is written to be pasted into a system prompt: one table per
|
|
97
|
-
* component listing every property with its type, whether it is required and
|
|
98
|
-
* what it means, then a fenced example an agent can copy.
|
|
99
|
-
*/
|
|
100
|
-
function catalogueMarkdown(doc = buildCatalogueDoc()) {
|
|
101
|
-
const lines = [];
|
|
102
|
-
lines.push("# A2UI catalogue — cortena-ui");
|
|
103
|
-
lines.push("");
|
|
104
|
-
lines.push(`Protocol \`${doc.protocol}\`, catalogue \`${doc.catalogueId}\`. Generated from the catalogue definition in \`cortena-ui\`; do not edit by hand.`);
|
|
105
|
-
lines.push("");
|
|
106
|
-
lines.push("A surface is described by three message kinds: `createSurface` names it, `updateComponents` sends the component tree, `updateDataModel` sends the data those components bind to. Any property may be a literal or a `{ \"path\": \"/pointer\" }` binding into the data model. A component takes children through `children`, either a list of ids or `{ \"componentId\": \"…\", \"path\": \"/items\" }` to repeat one component per array item.");
|
|
107
|
-
lines.push("");
|
|
108
|
-
lines.push(`${doc.components.length} components:`);
|
|
109
|
-
lines.push("");
|
|
110
|
-
for (const group of GROUP_ORDER) {
|
|
111
|
-
const inGroup = doc.components.filter((component) => component.group === group);
|
|
112
|
-
if (inGroup.length === 0) continue;
|
|
113
|
-
lines.push(`## ${GROUP_TITLE[group]}`);
|
|
114
|
-
lines.push("");
|
|
115
|
-
for (const component of inGroup) {
|
|
116
|
-
lines.push(`### ${component.name}`);
|
|
117
|
-
lines.push("");
|
|
118
|
-
lines.push(component.summary);
|
|
119
|
-
lines.push("");
|
|
120
|
-
lines.push(`Children: ${component.children === "many" ? "yes" : "no"}. Events: ${component.events.length > 0 ? component.events.map((e) => `\`${e}\``).join(", ") : "none"}.`);
|
|
121
|
-
lines.push("");
|
|
122
|
-
const propertyNames = Object.keys(component.props);
|
|
123
|
-
if (propertyNames.length > 0) {
|
|
124
|
-
lines.push("| Property | Type | Required | Description |");
|
|
125
|
-
lines.push("| --- | --- | --- | --- |");
|
|
126
|
-
for (const name of propertyNames) {
|
|
127
|
-
const schema = component.props[name];
|
|
128
|
-
const description = typeof schema?.description === "string" ? schema.description : "";
|
|
129
|
-
lines.push(`| \`${name}\` | ${escapeCell(describeType(schema))} | ${component.required.includes(name) ? "yes" : "no"} | ${escapeCell(description)} |`);
|
|
130
|
-
}
|
|
131
|
-
lines.push("");
|
|
132
|
-
}
|
|
133
|
-
lines.push("```json");
|
|
134
|
-
lines.push(JSON.stringify(exampleMessages(component), null, 2));
|
|
135
|
-
lines.push("```");
|
|
136
|
-
lines.push("");
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
return `${lines.join("\n").trimEnd()}\n`;
|
|
140
|
-
}
|
|
141
|
-
/** Turn an entry's example into the messages an agent would actually send. */
|
|
142
|
-
function exampleMessages(component) {
|
|
143
|
-
const messages = [{
|
|
144
|
-
version: "v0.9",
|
|
145
|
-
createSurface: {
|
|
146
|
-
surfaceId: "demo",
|
|
147
|
-
root: component.example.components[0]?.id ?? "root"
|
|
148
|
-
}
|
|
149
|
-
}, {
|
|
150
|
-
version: "v0.9",
|
|
151
|
-
updateComponents: {
|
|
152
|
-
surfaceId: "demo",
|
|
153
|
-
components: component.example.components
|
|
154
|
-
}
|
|
155
|
-
}];
|
|
156
|
-
if (component.example.data) messages.push({
|
|
157
|
-
version: "v0.9",
|
|
158
|
-
updateDataModel: {
|
|
159
|
-
surfaceId: "demo",
|
|
160
|
-
path: "/",
|
|
161
|
-
value: component.example.data
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
return messages;
|
|
165
|
-
}
|
|
166
|
-
//#endregion
|
|
167
|
-
export { buildCatalogueDoc, catalogueMarkdown, exampleMessages };
|
|
168
|
-
|
|
169
|
-
//# sourceMappingURL=catalogue-doc.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"catalogue-doc.js","names":[],"sources":["../../src/a2ui/catalogue-doc.ts"],"sourcesContent":["/**\n * Catalogue documentation generator.\n *\n * Emits a machine-readable description of the catalogue — every component's\n * name, group, summary, property schema, events and a worked example — plus a\n * markdown rendering of the same thing.\n *\n * This exists so the \"Rich Content\" system-prompt section can be *generated*\n * from the catalogue rather than written beside it (DESIGN-34). A prompt that\n * describes a component the renderer does not have, or omits one it does, is\n * the failure `05-agent-ui.md` calls out; the only way to prevent it is for\n * both to come from one object.\n *\n * `pnpm a2ui:catalogue` writes `dist-a2ui/catalogue.json` and `.md`.\n */\n\nimport { z } from \"zod\";\nimport { A2UI_CATALOGUE_ID, defaultCatalogue, type A2UICatalogue, type A2UIGroup } from \"./catalogue\";\nimport { A2UI_VERSION, type A2UIComponentSpec } from \"./message\";\n\n/** A JSON Schema object, as far as this module cares. */\nexport type JsonSchema = Record<string, unknown>;\n\nexport interface A2UIComponentDoc {\n name: string;\n group: A2UIGroup;\n summary: string;\n /** Whether the component takes a `children` list. */\n children: \"none\" | \"many\";\n /** Event names the component raises through `onAction`. */\n events: string[];\n /** JSON Schema of the resolved properties, derived from the zod schema. */\n props: JsonSchema;\n /** Property names that must be present. */\n required: string[];\n /** A complete, renderable example: the components and any data they bind to. */\n example: { components: A2UIComponentSpec[]; data?: Record<string, unknown> };\n}\n\nexport interface A2UICatalogueDoc {\n catalogueId: string;\n protocol: string;\n generator: string;\n components: A2UIComponentDoc[];\n}\n\n/**\n * zod 4 ships `toJSONSchema`; zod 3 does not.\n *\n * The package's zod peer allows both, so this is checked rather than assumed —\n * emitting `{}` for every component would produce a doc that passes every test\n * and teaches an agent nothing, which is the silent-success failure this whole\n * package's lint exists to avoid.\n */\nfunction toJsonSchema(schema: z.ZodType<unknown>): JsonSchema {\n const converter = (z as unknown as { toJSONSchema?: (s: unknown, o?: unknown) => JsonSchema })\n .toJSONSchema;\n if (typeof converter !== \"function\") {\n throw new Error(\n \"Generating the A2UI catalogue doc needs zod 4 (z.toJSONSchema). The installed zod is 3.x.\",\n );\n }\n return converter(schema, { io: \"input\", unrepresentable: \"any\" });\n}\n\n/** Build the machine-readable catalogue document. */\nexport function buildCatalogueDoc(catalogue: A2UICatalogue = defaultCatalogue): A2UICatalogueDoc {\n const components = Object.values(catalogue)\n .map((entry): A2UIComponentDoc => {\n const schema = toJsonSchema(entry.props as unknown as z.ZodType<unknown>);\n const properties = (schema.properties ?? {}) as JsonSchema;\n const required = Array.isArray(schema.required) ? (schema.required as string[]) : [];\n return {\n name: entry.name,\n group: entry.group,\n summary: entry.summary,\n children: entry.children,\n events: [...entry.events],\n props: properties,\n required,\n example: {\n components: entry.example.components,\n ...(entry.example.data ? { data: entry.example.data } : {}),\n },\n };\n })\n .sort((a, b) => a.name.localeCompare(b.name));\n\n return {\n catalogueId: A2UI_CATALOGUE_ID,\n protocol: A2UI_VERSION,\n generator: \"cortena-ui/a2ui\",\n components,\n };\n}\n\nconst GROUP_ORDER: A2UIGroup[] = [\"layout\", \"text\", \"input\", \"feedback\", \"data\"];\n\nconst GROUP_TITLE: Record<A2UIGroup, string> = {\n layout: \"Layout\",\n text: \"Text and media\",\n input: \"Inputs and actions\",\n feedback: \"Feedback\",\n data: \"Data\",\n};\n\n/** One-line type summary for a JSON Schema property, for the markdown table. */\nfunction describeType(schema: unknown): string {\n if (typeof schema !== \"object\" || schema === null) {\n return \"any\";\n }\n const node = schema as JsonSchema;\n if (Array.isArray(node.enum)) {\n return node.enum.map((value) => JSON.stringify(value)).join(\" \\\\| \");\n }\n if (Array.isArray(node.anyOf) || Array.isArray(node.oneOf)) {\n const options = (node.anyOf ?? node.oneOf) as unknown[];\n return options.map((option) => describeType(option)).join(\" \\\\| \");\n }\n if (node.const !== undefined) {\n return JSON.stringify(node.const);\n }\n if (node.type === \"array\") {\n return `${describeType(node.items)}[]`;\n }\n if (typeof node.type === \"string\") {\n return node.type;\n }\n if (Array.isArray(node.type)) {\n return node.type.join(\" \\\\| \");\n }\n return \"any\";\n}\n\nfunction escapeCell(text: string): string {\n return text.replace(/\\|/g, \"\\\\|\").replace(/\\n+/g, \" \").trim();\n}\n\n/**\n * Render the catalogue document as markdown.\n *\n * The output is written to be pasted into a system prompt: one table per\n * component listing every property with its type, whether it is required and\n * what it means, then a fenced example an agent can copy.\n */\nexport function catalogueMarkdown(doc: A2UICatalogueDoc = buildCatalogueDoc()): string {\n const lines: string[] = [];\n lines.push(\"# A2UI catalogue — cortena-ui\");\n lines.push(\"\");\n lines.push(\n `Protocol \\`${doc.protocol}\\`, catalogue \\`${doc.catalogueId}\\`. Generated from the catalogue definition in \\`cortena-ui\\`; do not edit by hand.`,\n );\n lines.push(\"\");\n lines.push(\n \"A surface is described by three message kinds: `createSurface` names it, `updateComponents` sends the component tree, `updateDataModel` sends the data those components bind to. Any property may be a literal or a `{ \\\"path\\\": \\\"/pointer\\\" }` binding into the data model. A component takes children through `children`, either a list of ids or `{ \\\"componentId\\\": \\\"…\\\", \\\"path\\\": \\\"/items\\\" }` to repeat one component per array item.\",\n );\n lines.push(\"\");\n lines.push(`${doc.components.length} components:`);\n lines.push(\"\");\n\n for (const group of GROUP_ORDER) {\n const inGroup = doc.components.filter((component) => component.group === group);\n if (inGroup.length === 0) {\n continue;\n }\n lines.push(`## ${GROUP_TITLE[group]}`);\n lines.push(\"\");\n for (const component of inGroup) {\n lines.push(`### ${component.name}`);\n lines.push(\"\");\n lines.push(component.summary);\n lines.push(\"\");\n lines.push(\n `Children: ${component.children === \"many\" ? \"yes\" : \"no\"}. Events: ${\n component.events.length > 0 ? component.events.map((e) => `\\`${e}\\``).join(\", \") : \"none\"\n }.`,\n );\n lines.push(\"\");\n const propertyNames = Object.keys(component.props);\n if (propertyNames.length > 0) {\n lines.push(\"| Property | Type | Required | Description |\");\n lines.push(\"| --- | --- | --- | --- |\");\n for (const name of propertyNames) {\n const schema = component.props[name] as JsonSchema | undefined;\n const description =\n typeof schema?.description === \"string\" ? schema.description : \"\";\n lines.push(\n `| \\`${name}\\` | ${escapeCell(describeType(schema))} | ${\n component.required.includes(name) ? \"yes\" : \"no\"\n } | ${escapeCell(description)} |`,\n );\n }\n lines.push(\"\");\n }\n lines.push(\"```json\");\n lines.push(JSON.stringify(exampleMessages(component), null, 2));\n lines.push(\"```\");\n lines.push(\"\");\n }\n }\n return `${lines.join(\"\\n\").trimEnd()}\\n`;\n}\n\n/** Turn an entry's example into the messages an agent would actually send. */\nexport function exampleMessages(component: A2UIComponentDoc): unknown[] {\n const root = component.example.components[0]?.id ?? \"root\";\n const messages: unknown[] = [\n { version: \"v0.9\", createSurface: { surfaceId: \"demo\", root } },\n { version: \"v0.9\", updateComponents: { surfaceId: \"demo\", components: component.example.components } },\n ];\n if (component.example.data) {\n messages.push({\n version: \"v0.9\",\n updateDataModel: { surfaceId: \"demo\", path: \"/\", value: component.example.data },\n });\n }\n return messages;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAsDA,SAAS,aAAa,QAAwC;CAC5D,MAAM,YAAa,EAChB;CACH,IAAI,OAAO,cAAc,YACvB,MAAM,IAAI,MACR,2FACF;CAEF,OAAO,UAAU,QAAQ;EAAE,IAAI;EAAS,iBAAiB;CAAM,CAAC;AAClE;;AAGA,SAAgB,kBAAkB,YAA2B,kBAAoC;CAC/F,MAAM,aAAa,OAAO,OAAO,SAAS,CAAC,CACxC,KAAK,UAA4B;EAChC,MAAM,SAAS,aAAa,MAAM,KAAsC;EACxE,MAAM,aAAc,OAAO,cAAc,CAAC;EAC1C,MAAM,WAAW,MAAM,QAAQ,OAAO,QAAQ,IAAK,OAAO,WAAwB,CAAC;EACnF,OAAO;GACL,MAAM,MAAM;GACZ,OAAO,MAAM;GACb,SAAS,MAAM;GACf,UAAU,MAAM;GAChB,QAAQ,CAAC,GAAG,MAAM,MAAM;GACxB,OAAO;GACP;GACA,SAAS;IACP,YAAY,MAAM,QAAQ;IAC1B,GAAI,MAAM,QAAQ,OAAO,EAAE,MAAM,MAAM,QAAQ,KAAK,IAAI,CAAC;GAC3D;EACF;CACF,CAAC,CAAC,CACD,MAAM,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,IAAI,CAAC;CAE9C,OAAO;EACL,aAAa;EACb,UAAU;EACV,WAAW;EACX;CACF;AACF;AAEA,MAAM,cAA2B;CAAC;CAAU;CAAQ;CAAS;CAAY;AAAM;AAE/E,MAAM,cAAyC;CAC7C,QAAQ;CACR,MAAM;CACN,OAAO;CACP,UAAU;CACV,MAAM;AACR;;AAGA,SAAS,aAAa,QAAyB;CAC7C,IAAI,OAAO,WAAW,YAAY,WAAW,MAC3C,OAAO;CAET,MAAM,OAAO;CACb,IAAI,MAAM,QAAQ,KAAK,IAAI,GACzB,OAAO,KAAK,KAAK,KAAK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