@databricks/appkit-ui 0.91.3 → 0.93.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CLAUDE.md +2 -0
- package/NOTICE.md +3 -3
- package/dist/cli/commands/doctor/checks-existence.js +15 -0
- package/dist/cli/commands/doctor/checks-existence.js.map +1 -1
- package/dist/cli/commands/plugin/add/add.js +398 -0
- package/dist/cli/commands/plugin/add/add.js.map +1 -0
- package/dist/cli/commands/plugin/add/plan.js +216 -0
- package/dist/cli/commands/plugin/add/plan.js.map +1 -0
- package/dist/cli/commands/plugin/add/resolve.js +45 -0
- package/dist/cli/commands/plugin/add/resolve.js.map +1 -0
- package/dist/cli/commands/plugin/create/resource-defaults.js +4 -0
- package/dist/cli/commands/plugin/create/resource-defaults.js.map +1 -1
- package/dist/cli/commands/plugin/index.js +4 -1
- package/dist/cli/commands/plugin/index.js.map +1 -1
- package/dist/cli/commands/plugin/schema-resources.js +2 -1
- package/dist/cli/commands/plugin/schema-resources.js.map +1 -1
- package/dist/cli/commands/registry/add.js +3 -2
- package/dist/cli/commands/registry/add.js.map +1 -1
- package/dist/cli/commands/registry/config-plan.js +1 -1
- package/dist/cli/commands/registry/config-plan.js.map +1 -1
- package/dist/cli/commands/registry/config-writer.js +77 -9
- package/dist/cli/commands/registry/config-writer.js.map +1 -1
- package/dist/cli/commands/registry/env-writer.js +15 -2
- package/dist/cli/commands/registry/env-writer.js.map +1 -1
- package/dist/cli/commands/registry/server-register.js +62 -26
- package/dist/cli/commands/registry/server-register.js.map +1 -1
- package/dist/cli/commands/registry/workspace-picker.js +47 -2
- package/dist/cli/commands/registry/workspace-picker.js.map +1 -1
- package/dist/cli/deploy-config.js.map +1 -1
- package/dist/cli/index.js +1 -1
- package/dist/react/beta.d.ts +3 -1
- package/dist/react/beta.js +3 -1
- package/dist/react/charts/base.d.ts +1 -1
- package/dist/react/charts/base.d.ts.map +1 -1
- package/dist/react/charts/base.js +5 -3
- package/dist/react/charts/base.js.map +1 -1
- package/dist/react/charts/constants.js +13 -1
- package/dist/react/charts/constants.js.map +1 -1
- package/dist/react/charts/create-chart.js +1 -1
- package/dist/react/charts/create-chart.js.map +1 -1
- package/dist/react/charts/index.d.ts +1 -1
- package/dist/react/charts/types.d.ts +7 -3
- package/dist/react/charts/types.d.ts.map +1 -1
- package/dist/react/charts/types.js.map +1 -1
- package/dist/react/charts/wrapper.d.ts +1 -1
- package/dist/react/charts/wrapper.d.ts.map +1 -1
- package/dist/react/charts/wrapper.js +12 -5
- package/dist/react/charts/wrapper.js.map +1 -1
- package/dist/react/design-page.d.ts +33 -0
- package/dist/react/design-page.d.ts.map +1 -0
- package/dist/react/design-page.js +173 -0
- package/dist/react/design-page.js.map +1 -0
- package/dist/react/hooks/use-design-ready.d.ts +19 -0
- package/dist/react/hooks/use-design-ready.d.ts.map +1 -0
- package/dist/react/hooks/use-design-ready.js +33 -0
- package/dist/react/hooks/use-design-ready.js.map +1 -0
- package/dist/react/index.d.ts +2 -2
- package/dist/schemas/manifest.d.ts +79 -0
- package/dist/schemas/manifest.d.ts.map +1 -1
- package/dist/schemas/manifest.js +10 -1
- package/dist/schemas/manifest.js.map +1 -1
- package/dist/shared/src/plugin.d.ts.map +1 -1
- package/docs/api/appkit/Enumeration.ResourceType.md +9 -0
- package/docs/api/appkit/TypeAlias.ResourcePermission.md +1 -0
- package/docs/api/appkit/Variable.design.md +6 -0
- package/docs/api/appkit-ui/data/AreaChart.md +2 -2
- package/docs/api/appkit-ui/data/BarChart.md +2 -2
- package/docs/api/appkit-ui/data/DonutChart.md +2 -2
- package/docs/api/appkit-ui/data/HeatmapChart.md +2 -2
- package/docs/api/appkit-ui/data/LineChart.md +2 -2
- package/docs/api/appkit-ui/data/PieChart.md +2 -2
- package/docs/api/appkit-ui/data/RadarChart.md +2 -2
- package/docs/api/appkit-ui/data/ScatterChart.md +2 -2
- package/docs/api/appkit.md +1 -0
- package/docs/plugins/agents.md +3 -3
- package/docs/plugins/analytics.md +8 -0
- package/docs/plugins/design.md +233 -0
- package/docs/plugins/manifest.md +1 -0
- package/llms.txt +2 -0
- package/package.json +1 -1
- package/sbom.cdx.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"constants.js","names":[],"sources":["../../../src/react/charts/constants.ts"],"sourcesContent":["// ============================================================================\n// Shared Constants for Chart Components\n// ============================================================================\n\nimport type { ChartUITokens } from \"./types\";\n\n// Re-export field patterns from shared constants\nexport {\n DATE_FIELD_PATTERNS,\n METADATA_DATE_PATTERNS,\n NAME_FIELD_PATTERNS,\n} from \"@/js/constants\";\n\n// ============================================================================\n// Chart Color Palettes\n// ============================================================================\n\n/** CSS variable names for categorical chart colors (distinct categories) */\nexport const CHART_COLOR_VARS_CATEGORICAL = [\n \"--chart-cat-1\",\n \"--chart-cat-2\",\n \"--chart-cat-3\",\n \"--chart-cat-4\",\n \"--chart-cat-5\",\n \"--chart-cat-6\",\n \"--chart-cat-7\",\n \"--chart-cat-8\",\n] as const;\n\n/** CSS variable names for sequential chart colors (low → high) */\nexport const CHART_COLOR_VARS_SEQUENTIAL = [\n \"--chart-seq-1\",\n \"--chart-seq-2\",\n \"--chart-seq-3\",\n \"--chart-seq-4\",\n \"--chart-seq-5\",\n \"--chart-seq-6\",\n \"--chart-seq-7\",\n \"--chart-seq-8\",\n] as const;\n\n/** CSS variable names for diverging chart colors (negative ↔ positive) */\nexport const CHART_COLOR_VARS_DIVERGING = [\n \"--chart-div-1\",\n \"--chart-div-2\",\n \"--chart-div-3\",\n \"--chart-div-4\",\n \"--chart-div-5\",\n \"--chart-div-6\",\n \"--chart-div-7\",\n \"--chart-div-8\",\n] as const;\n\n/** Legacy: CSS variable names for chart colors (aliases to categorical) */\nexport const CHART_COLOR_VARS = [\n \"--chart-1\",\n \"--chart-2\",\n \"--chart-3\",\n \"--chart-4\",\n \"--chart-5\",\n \"--chart-6\",\n \"--chart-7\",\n \"--chart-8\",\n] as const;\n\n// ============================================================================\n// Fallback Colors (when CSS variables unavailable)\n// ============================================================================\n\n/** Fallback categorical colors */\nexport const FALLBACK_COLORS_CATEGORICAL = [\n \"hsla(221, 83%, 53%, 1)\", // Blue\n \"hsla(160, 60%, 45%, 1)\", // Teal\n \"hsla(291, 47%, 51%, 1)\", // Purple\n \"hsla(35, 92%, 55%, 1)\", // Amber\n \"hsla(349, 72%, 52%, 1)\", // Rose\n \"hsla(189, 75%, 42%, 1)\", // Cyan\n \"hsla(271, 55%, 60%, 1)\", // Lavender\n \"hsla(142, 55%, 45%, 1)\", // Emerald\n];\n\n/** Fallback sequential colors (light → dark blue) */\nexport const FALLBACK_COLORS_SEQUENTIAL = [\n \"hsla(221, 70%, 94%, 1)\",\n \"hsla(221, 72%, 85%, 1)\",\n \"hsla(221, 74%, 74%, 1)\",\n \"hsla(221, 76%, 63%, 1)\",\n \"hsla(221, 78%, 52%, 1)\",\n \"hsla(221, 80%, 42%, 1)\",\n \"hsla(221, 82%, 32%, 1)\",\n \"hsla(221, 84%, 24%, 1)\",\n];\n\n/** Fallback diverging colors (blue → red) */\nexport const FALLBACK_COLORS_DIVERGING = [\n \"hsla(221, 80%, 35%, 1)\", // Strong negative\n \"hsla(221, 70%, 50%, 1)\",\n \"hsla(221, 55%, 65%, 1)\",\n \"hsla(221, 35%, 82%, 1)\", // Weak negative\n \"hsla(10, 35%, 82%, 1)\", // Weak positive\n \"hsla(10, 60%, 65%, 1)\",\n \"hsla(10, 72%, 50%, 1)\",\n \"hsla(10, 80%, 40%, 1)\", // Strong positive\n];\n\n// ============================================================================\n// Chart UI tokens (axis text, titles, grid lines)\n// ============================================================================\n\n/** CSS variable names for the chart UI tokens (read at runtime like the palettes) */\nexport const CHART_UI_VARS: Record<keyof ChartUITokens, string> = {\n axisLabel: \"--chart-axis-label\",\n axisTitle: \"--chart-axis-title\",\n grid: \"--chart-grid\",\n tooltipBg: \"--chart-tooltip-bg\",\n};\n\n/** Fallback chart UI tokens (light values). */\nexport const FALLBACK_UI_TOKENS: ChartUITokens = {\n axisLabel: \"hsla(240, 4%, 46%, 1)\", // ≈ --muted-foreground\n axisTitle: \"hsla(240, 6%, 10%, 1)\", // ≈ --foreground\n grid: \"hsla(240, 5%, 90%, 1)\", // ≈ --border\n tooltipBg: \"hsla(0, 0%, 100%, 1)\", // ≈ --popover\n};\n"],"mappings":";;;;AAkBA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,8BAA8B;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,6BAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,mBAAmB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAOD,MAAa,8BAA8B;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,6BAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAOD,MAAa,gBAAqD;CAChE,WAAW;CACX,WAAW;CACX,MAAM;CACN,WAAW;CACZ;;AAGD,MAAa,qBAAoC;CAC/C,WAAW;CACX,WAAW;CACX,MAAM;CACN,WAAW;CACZ"}
|
|
1
|
+
{"version":3,"file":"constants.js","names":[],"sources":["../../../src/react/charts/constants.ts"],"sourcesContent":["// ============================================================================\n// Shared Constants for Chart Components\n// ============================================================================\n\nimport type { ChartUITokens } from \"./types\";\n\n// Re-export field patterns from shared constants\nexport {\n DATE_FIELD_PATTERNS,\n METADATA_DATE_PATTERNS,\n NAME_FIELD_PATTERNS,\n} from \"@/js/constants\";\n\n// ============================================================================\n// Chart Color Palettes\n// ============================================================================\n\n/** CSS variable names for categorical chart colors (distinct categories) */\nexport const CHART_COLOR_VARS_CATEGORICAL = [\n \"--chart-cat-1\",\n \"--chart-cat-2\",\n \"--chart-cat-3\",\n \"--chart-cat-4\",\n \"--chart-cat-5\",\n \"--chart-cat-6\",\n \"--chart-cat-7\",\n \"--chart-cat-8\",\n] as const;\n\n/** CSS variable names for sequential chart colors (low → high) */\nexport const CHART_COLOR_VARS_SEQUENTIAL = [\n \"--chart-seq-1\",\n \"--chart-seq-2\",\n \"--chart-seq-3\",\n \"--chart-seq-4\",\n \"--chart-seq-5\",\n \"--chart-seq-6\",\n \"--chart-seq-7\",\n \"--chart-seq-8\",\n] as const;\n\n/** CSS variable names for diverging chart colors (negative ↔ positive) */\nexport const CHART_COLOR_VARS_DIVERGING = [\n \"--chart-div-1\",\n \"--chart-div-2\",\n \"--chart-div-3\",\n \"--chart-div-4\",\n \"--chart-div-5\",\n \"--chart-div-6\",\n \"--chart-div-7\",\n \"--chart-div-8\",\n] as const;\n\n/** Legacy: CSS variable names for chart colors (aliases to categorical) */\nexport const CHART_COLOR_VARS = [\n \"--chart-1\",\n \"--chart-2\",\n \"--chart-3\",\n \"--chart-4\",\n \"--chart-5\",\n \"--chart-6\",\n \"--chart-7\",\n \"--chart-8\",\n] as const;\n\n// ============================================================================\n// Fallback Colors (when CSS variables unavailable)\n// ============================================================================\n\n/** Fallback categorical colors */\nexport const FALLBACK_COLORS_CATEGORICAL = [\n \"hsla(221, 83%, 53%, 1)\", // Blue\n \"hsla(160, 60%, 45%, 1)\", // Teal\n \"hsla(291, 47%, 51%, 1)\", // Purple\n \"hsla(35, 92%, 55%, 1)\", // Amber\n \"hsla(349, 72%, 52%, 1)\", // Rose\n \"hsla(189, 75%, 42%, 1)\", // Cyan\n \"hsla(271, 55%, 60%, 1)\", // Lavender\n \"hsla(142, 55%, 45%, 1)\", // Emerald\n];\n\n/** Fallback sequential colors (light → dark blue) */\nexport const FALLBACK_COLORS_SEQUENTIAL = [\n \"hsla(221, 70%, 94%, 1)\",\n \"hsla(221, 72%, 85%, 1)\",\n \"hsla(221, 74%, 74%, 1)\",\n \"hsla(221, 76%, 63%, 1)\",\n \"hsla(221, 78%, 52%, 1)\",\n \"hsla(221, 80%, 42%, 1)\",\n \"hsla(221, 82%, 32%, 1)\",\n \"hsla(221, 84%, 24%, 1)\",\n];\n\n/** Fallback diverging colors (blue → red) */\nexport const FALLBACK_COLORS_DIVERGING = [\n \"hsla(221, 80%, 35%, 1)\", // Strong negative\n \"hsla(221, 70%, 50%, 1)\",\n \"hsla(221, 55%, 65%, 1)\",\n \"hsla(221, 35%, 82%, 1)\", // Weak negative\n \"hsla(10, 35%, 82%, 1)\", // Weak positive\n \"hsla(10, 60%, 65%, 1)\",\n \"hsla(10, 72%, 50%, 1)\",\n \"hsla(10, 80%, 40%, 1)\", // Strong positive\n];\n\n// ============================================================================\n// Chart UI tokens (axis text, titles, grid lines)\n// ============================================================================\n\n/** CSS variable names for the chart UI tokens (read at runtime like the palettes) */\nexport const CHART_UI_VARS: Record<keyof ChartUITokens, string> = {\n axisLabel: \"--chart-axis-label\",\n axisTitle: \"--chart-axis-title\",\n grid: \"--chart-grid\",\n tooltipBg: \"--chart-tooltip-bg\",\n};\n\n/** Fallback chart UI tokens (light values). */\nexport const FALLBACK_UI_TOKENS: ChartUITokens = {\n axisLabel: \"hsla(240, 4%, 46%, 1)\", // ≈ --muted-foreground\n axisTitle: \"hsla(240, 6%, 10%, 1)\", // ≈ --foreground\n grid: \"hsla(240, 5%, 90%, 1)\", // ≈ --border\n tooltipBg: \"hsla(0, 0%, 100%, 1)\", // ≈ --popover\n};\n\n/** Smallest height a chart takes when it fills its parent (no `height` prop). */\nexport const CHART_MIN_HEIGHT = 160;\n\n/**\n * A chart's box: exactly `height` pixels, or its parent's height, at least\n * {@link CHART_MIN_HEIGHT} when that comes from its content.\n */\nexport function chartSizeStyle(height?: number): {\n height: number | string;\n minHeight?: number;\n} {\n return height !== undefined\n ? { height }\n : { height: \"100%\", minHeight: CHART_MIN_HEIGHT };\n}\n"],"mappings":";;;;AAkBA,MAAa,+BAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,8BAA8B;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,6BAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,mBAAmB;CAC9B;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAOD,MAAa,8BAA8B;CACzC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,6BAA6B;CACxC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAGD,MAAa,4BAA4B;CACvC;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACD;;AAOD,MAAa,gBAAqD;CAChE,WAAW;CACX,WAAW;CACX,MAAM;CACN,WAAW;CACZ;;AAGD,MAAa,qBAAoC;CAC/C,WAAW;CACX,WAAW;CACX,MAAM;CACN,WAAW;CACZ;;AAGD,MAAa,mBAAmB;;;;;AAMhC,SAAgB,eAAe,QAG7B;AACA,QAAO,WAAW,SACd,EAAE,QAAQ,GACV;EAAE,QAAQ;EAAQ,WAAW;EAAkB"}
|
|
@@ -19,7 +19,7 @@ import { jsx } from "react/jsx-runtime";
|
|
|
19
19
|
*/
|
|
20
20
|
function createChart(chartType, displayName) {
|
|
21
21
|
const Component = (props) => {
|
|
22
|
-
const { queryKey, parameters, format, transformer, data, height
|
|
22
|
+
const { queryKey, parameters, format, transformer, data, height, className, ariaLabel, testId, ...chartProps } = props;
|
|
23
23
|
return /* @__PURE__ */ jsx(ChartWrapper, {
|
|
24
24
|
...data !== void 0 ? {
|
|
25
25
|
data,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create-chart.js","names":[],"sources":["../../../src/react/charts/create-chart.tsx"],"sourcesContent":["import { BaseChart } from \"./base\";\nimport type { ChartType, UnifiedChartProps } from \"./types\";\nimport { ChartWrapper } from \"./wrapper\";\n\n/**\n * Factory function to create chart components.\n * Eliminates boilerplate by generating components with the same pattern.\n *\n * @param chartType - The ECharts chart type\n * @param displayName - Component display name for React DevTools\n * @returns A typed chart component\n *\n * @example\n * ```tsx\n * export const BarChart = createChart<BarChartProps>(\"bar\", \"BarChart\");\n * export const LineChart = createChart<LineChartProps>(\"line\", \"LineChart\");\n * ```\n */\nexport function createChart<TProps extends UnifiedChartProps>(\n chartType: ChartType,\n displayName: string,\n) {\n const Component = (props: TProps) => {\n const {\n // Query props\n queryKey,\n parameters,\n format,\n transformer,\n // Data props\n data,\n // Common props\n height
|
|
1
|
+
{"version":3,"file":"create-chart.js","names":[],"sources":["../../../src/react/charts/create-chart.tsx"],"sourcesContent":["import { BaseChart } from \"./base\";\nimport type { ChartData, ChartType, UnifiedChartProps } from \"./types\";\nimport { ChartWrapper } from \"./wrapper\";\n\n/**\n * Factory function to create chart components.\n * Eliminates boilerplate by generating components with the same pattern.\n *\n * @param chartType - The ECharts chart type\n * @param displayName - Component display name for React DevTools\n * @returns A typed chart component\n *\n * @example\n * ```tsx\n * export const BarChart = createChart<BarChartProps>(\"bar\", \"BarChart\");\n * export const LineChart = createChart<LineChartProps>(\"line\", \"LineChart\");\n * ```\n */\nexport function createChart<TProps extends UnifiedChartProps>(\n chartType: ChartType,\n displayName: string,\n) {\n const Component = (props: TProps) => {\n const {\n // Query props\n queryKey,\n parameters,\n format,\n transformer,\n // Data props\n data,\n // Common props\n height,\n className,\n ariaLabel,\n testId,\n // All remaining props pass through to BaseChart\n ...chartProps\n } = props as TProps & {\n queryKey?: string;\n parameters?: Record<string, unknown>;\n format?: string;\n transformer?: unknown;\n data?: unknown;\n height?: number;\n className?: string;\n ariaLabel?: string;\n testId?: string;\n };\n\n const wrapperProps =\n data !== undefined\n ? // ChartDataInput also admits interface-typed and readonly rows; at\n // runtime they're the same plain objects the chart reads.\n { data: data as ChartData, height, className, ariaLabel, testId }\n : {\n queryKey: queryKey as string,\n parameters,\n format,\n transformer,\n height,\n className,\n ariaLabel,\n testId: testId ?? `${chartType}-chart-${queryKey}`,\n };\n\n return (\n <ChartWrapper {...wrapperProps}>\n {(chartData) => (\n <BaseChart\n data={chartData}\n chartType={chartType}\n height={height}\n className={className}\n {...chartProps}\n />\n )}\n </ChartWrapper>\n );\n };\n\n Component.displayName = displayName;\n return Component;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAkBA,SAAgB,YACd,WACA,aACA;CACA,MAAM,aAAa,UAAkB;EACnC,MAAM,EAEJ,UACA,YACA,QACA,aAEA,MAEA,QACA,WACA,WACA,QAEA,GAAG,eACD;AA4BJ,SACE,oBAAC;GAAa,GAhBd,SAAS,SAGL;IAAQ;IAAmB;IAAQ;IAAW;IAAW;IAAQ,GACjE;IACY;IACV;IACA;IACA;IACA;IACA;IACA;IACA,QAAQ,UAAU,GAAG,UAAU,SAAS;IACzC;cAID,cACA,oBAAC;IACC,MAAM;IACK;IACH;IACG;IACX,GAAI;KACJ;IAES;;AAInB,WAAU,cAAc;AACxB,QAAO"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { DATE_FIELD_PATTERNS, METADATA_DATE_PATTERNS, NAME_FIELD_PATTERNS } from "../../js/constants.js";
|
|
2
2
|
import { formatLabel } from "../../js/format/index.js";
|
|
3
|
-
import { AreaChartProps, AreaChartSpecificProps, BarChartProps, BarChartSpecificProps, ChartBaseProps, ChartClickDatum, ChartColorPalette, ChartData, ChartType, ChartUITokens, ChartValueFormatter, DataFormat, DataProps, DonutChartProps, HeatmapChartProps, HeatmapChartSpecificProps, LineChartProps, LineChartSpecificProps, NormalizedChartData, NormalizedChartDataBase, Orientation, PieChartProps, PieChartSpecificProps, QueryProps, RadarChartProps, RadarChartSpecificProps, ScatterChartProps, ScatterChartSpecificProps, UnifiedChartProps, isArrowTable, isDataProps, isQueryProps } from "./types.js";
|
|
3
|
+
import { AreaChartProps, AreaChartSpecificProps, BarChartProps, BarChartSpecificProps, ChartBaseProps, ChartClickDatum, ChartColorPalette, ChartData, ChartDataInput, ChartRow, ChartType, ChartUITokens, ChartValueFormatter, DataFormat, DataProps, DonutChartProps, HeatmapChartProps, HeatmapChartSpecificProps, LineChartProps, LineChartSpecificProps, NormalizedChartData, NormalizedChartDataBase, Orientation, PieChartProps, PieChartSpecificProps, QueryProps, RadarChartProps, RadarChartSpecificProps, ScatterChartProps, ScatterChartSpecificProps, UnifiedChartProps, isArrowTable, isDataProps, isQueryProps } from "./types.js";
|
|
4
4
|
import { AreaChart } from "./area/index.js";
|
|
5
5
|
import { BarChart } from "./bar/index.js";
|
|
6
6
|
import { HeatmapChart } from "./heatmap/index.js";
|
|
@@ -16,6 +16,10 @@ type Orientation = "vertical" | "horizontal";
|
|
|
16
16
|
type ChartType = "bar" | "line" | "area" | "pie" | "donut" | "scatter" | "radar" | "heatmap";
|
|
17
17
|
/** Data that can be passed to unified charts */
|
|
18
18
|
type ChartData = Table | Record<string, unknown>[];
|
|
19
|
+
/** One row of chart data (indexable, to type plain data modules). */
|
|
20
|
+
type ChartRow = Record<string, unknown>;
|
|
21
|
+
/** A chart's `data`: an Arrow Table, or rows (interfaces and `as const` arrays too). */
|
|
22
|
+
type ChartDataInput = Table | readonly object[];
|
|
19
23
|
/** Formats a measure value for chart axes, tooltips, and value labels. */
|
|
20
24
|
type ChartValueFormatter = (value: string | number, field: string) => string;
|
|
21
25
|
/** Color palette types for different visualization needs */
|
|
@@ -46,7 +50,7 @@ interface ChartBaseProps {
|
|
|
46
50
|
colorPalette?: ChartColorPalette;
|
|
47
51
|
/** Custom colors for series (overrides colorPalette) */
|
|
48
52
|
colors?: string[];
|
|
49
|
-
/** Chart height in pixels
|
|
53
|
+
/** Chart height in pixels. Defaults to filling its parent (see `chartSizeStyle`). */
|
|
50
54
|
height?: number;
|
|
51
55
|
/** Additional CSS classes */
|
|
52
56
|
className?: string;
|
|
@@ -133,7 +137,7 @@ interface QueryProps extends ChartBaseProps {
|
|
|
133
137
|
/** Props for direct data injection */
|
|
134
138
|
interface DataProps extends ChartBaseProps {
|
|
135
139
|
/** Arrow Table or JSON array */
|
|
136
|
-
data:
|
|
140
|
+
data: ChartDataInput;
|
|
137
141
|
queryKey?: never;
|
|
138
142
|
parameters?: never;
|
|
139
143
|
format?: never;
|
|
@@ -227,5 +231,5 @@ declare function isQueryProps(props: UnifiedChartProps): props is QueryProps;
|
|
|
227
231
|
/** Type guard to check if props are data-based */
|
|
228
232
|
declare function isDataProps(props: UnifiedChartProps): props is DataProps;
|
|
229
233
|
//#endregion
|
|
230
|
-
export { AreaChartProps, AreaChartSpecificProps, BarChartProps, BarChartSpecificProps, ChartBaseProps, ChartClickDatum, ChartColorPalette, ChartData, ChartType, ChartUITokens, ChartValueFormatter, DataFormat, DataProps, DonutChartProps, HeatmapChartProps, HeatmapChartSpecificProps, LineChartProps, LineChartSpecificProps, NormalizedChartData, NormalizedChartDataBase, Orientation, PieChartProps, PieChartSpecificProps, QueryProps, RadarChartProps, RadarChartSpecificProps, ScatterChartProps, ScatterChartSpecificProps, UnifiedChartProps, isArrowTable, isDataProps, isQueryProps };
|
|
234
|
+
export { AreaChartProps, AreaChartSpecificProps, BarChartProps, BarChartSpecificProps, ChartBaseProps, ChartClickDatum, ChartColorPalette, ChartData, ChartDataInput, ChartRow, ChartType, ChartUITokens, ChartValueFormatter, DataFormat, DataProps, DonutChartProps, HeatmapChartProps, HeatmapChartSpecificProps, LineChartProps, LineChartSpecificProps, NormalizedChartData, NormalizedChartDataBase, Orientation, PieChartProps, PieChartSpecificProps, QueryProps, RadarChartProps, RadarChartSpecificProps, ScatterChartProps, ScatterChartSpecificProps, UnifiedChartProps, isArrowTable, isDataProps, isQueryProps };
|
|
231
235
|
//# sourceMappingURL=types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/react/charts/types.ts"],"mappings":";;;;;AAcA;;;;;AAUA;KAVY,UAAA;;KAUA,WAAA;;KAGA,SAAA;AAWZ;AAAA,KAAY,SAAA,GAAY,KAAA,GAAQ,MAAA;;KAGpB,mBAAA,IACV,KAAA,mBACA,KAAA;;KAQU,iBAAA;;
|
|
1
|
+
{"version":3,"file":"types.d.ts","names":[],"sources":["../../../src/react/charts/types.ts"],"mappings":"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"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","names":[],"sources":["../../../src/react/charts/types.ts"],"sourcesContent":["import type { Table } from \"apache-arrow\";\n\n// ============================================================================\n// Data Format Types\n// ============================================================================\n\n/**\n * Supported data formats for analytics queries.\n *\n * \"json\" and \"arrow\" are legacy aliases kept for backwards compatibility\n * with appkit-ui < 0.33.0 — safe to remove once no consumer is on a\n * pre-0.33.0 version. resolveFormat() normalizes them to their canonical\n * equivalents before any downstream code reads the value.\n */\nexport type DataFormat =\n | \"json_array\"\n | \"arrow_stream\"\n | \"auto\"\n /** @deprecated Use \"json_array\". Safe to remove once no consumer is on appkit-ui < 0.33.0. */\n | \"json\"\n /** @deprecated Use \"arrow_stream\". Safe to remove once no consumer is on appkit-ui < 0.33.0. */\n | \"arrow\";\n\n/** Chart orientation */\nexport type Orientation = \"vertical\" | \"horizontal\";\n\n/** Supported chart types */\nexport type ChartType =\n | \"bar\"\n | \"line\"\n | \"area\"\n | \"pie\"\n | \"donut\"\n | \"scatter\"\n | \"radar\"\n | \"heatmap\";\n\n/** Data that can be passed to unified charts */\nexport type ChartData = Table | Record<string, unknown>[];\n\n/** Formats a measure value for chart axes, tooltips, and value labels. */\nexport type ChartValueFormatter = (\n value: string | number,\n field: string,\n) => string;\n\n// ============================================================================\n// Base Props (shared by all charts)\n// ============================================================================\n\n/** Color palette types for different visualization needs */\nexport type ChartColorPalette = \"categorical\" | \"sequential\" | \"diverging\";\n\n/** Resolved colors for the chart UI — axis text, titles, grid lines, and tooltip. */\nexport interface ChartUITokens {\n /** Axis tick labels (≈ `--muted-foreground`) */\n axisLabel: string;\n /** Axis names, legend, title, and visualMap text (≈ `--foreground`) */\n axisTitle: string;\n /** Axis, tick, and split (grid) lines (≈ `--border`) */\n grid: string;\n /** Tooltip popover background (≈ `--popover`) */\n tooltipBg: string;\n}\n\n/** Common visual and behavior props for all charts */\nexport interface ChartBaseProps {\n /** Chart title */\n title?: string;\n /** Show legend */\n showLegend?: boolean;\n /**\n * Color palette to use. Auto-selected based on chart type if not specified.\n * - \"categorical\": Distinct colors for different categories (bar, pie, line)\n * - \"sequential\": Gradient for magnitude/intensity (heatmap)\n * - \"diverging\": Two-tone for positive/negative values\n */\n colorPalette?: ChartColorPalette;\n /** Custom colors for series (overrides colorPalette) */\n colors?: string[];\n /** Chart height in pixels @default 300 */\n height?: number;\n /** Additional CSS classes */\n className?: string;\n\n /** X-axis field key. Auto-detected from schema if not provided. */\n xKey?: string;\n /** Y-axis field key(s). Auto-detected from schema if not provided. */\n yKey?: string | string[];\n\n /** Accessibility label for screen readers */\n ariaLabel?: string;\n /** Test ID for automated testing */\n testId?: string;\n\n /** Additional ECharts options to merge */\n options?: Record<string, unknown>;\n\n /**\n * Formats measure values in the chart's built-in value axes, tooltips, and\n * value labels. `field` is the corresponding `yKey`, so one formatter can\n * select a different format for each series.\n *\n * For charts with multiple series on one value axis, axis ticks use the\n * first `yKey`; each tooltip uses its own series field.\n */\n valueFormatter?: ChartValueFormatter;\n\n /**\n * Pointer-only: charts render to <canvas>, so this does not fire for keyboard\n * users. Provide a keyboard-accessible equivalent (e.g. a table row action) for\n * the same action.\n */\n onDataClick?: (datum: ChartClickDatum) => void;\n\n /**\n * Controlled selection by category name. Matching data element(s) render at full\n * prominence while the rest are dimmed. Drive it from your own state to reflect a\n * cross-filter or selection. Categorical charts (bar, pie/donut) show emphasis;\n * other chart types ignore it.\n */\n selected?: string | string[];\n}\n\n// ============================================================================\n// Interaction / Click Events\n// ============================================================================\n\n/**\n * A normalized description of a clicked chart element.\n *\n * In the common cross-filter case, {@link ChartClickDatum.name} carries the\n * dimension value of the clicked element.\n */\nexport interface ChartClickDatum {\n /** Category label of the clicked element — the dimension value in the common cross-filter case. */\n name: string;\n /**\n * The datum's scalar value:\n * - bar / pie — the datum itself.\n * - time-series / scatter — the y-component of the `[x, y]` point (see\n * {@link ChartClickDatum.x} / {@link ChartClickDatum.y}).\n * - heatmap — the cell value (the third entry of ECharts'\n * `[xIndex, yIndex, value]` triple), *not* an axis index.\n * - radar — `null`; the item holds one value per indicator, so there is no\n * single scalar to report. Read the vector from {@link ChartClickDatum.raw}.\n *\n * `null` whenever there is no scalar value to surface.\n */\n value: number | string | null;\n x?: number | string;\n y?: number | string;\n seriesName?: string;\n dataIndex: number;\n seriesIndex: number;\n // Untouched ECharts event params.\n raw: unknown;\n}\n\n// ============================================================================\n// Query-based Props (chart fetches data)\n// ============================================================================\n\n/** Props for query-based data fetching */\nexport interface QueryProps extends ChartBaseProps {\n /** Analytics query key registered with analytics plugin */\n queryKey: string;\n /** Query parameters passed to the analytics endpoint */\n parameters?: Record<string, unknown>;\n /**\n * Data format to use\n * - \"json_array\": Use JSON format (smaller payloads, simpler)\n * - \"arrow_stream\": Use Arrow format (faster for large datasets)\n * - \"auto\": Automatically select based on expected data size\n * @default \"auto\"\n */\n format?: DataFormat;\n /** Transform raw data before rendering */\n transformer?: <T>(data: T) => T;\n // Discriminator: cannot use direct data with query\n data?: never;\n}\n\n// ============================================================================\n// Data-based Props (chart receives data externally)\n// ============================================================================\n\n/** Props for direct data injection */\nexport interface DataProps extends ChartBaseProps {\n /** Arrow Table or JSON array */\n data: ChartData;\n\n // Discriminator: cannot use query props with direct data\n queryKey?: never;\n parameters?: never;\n format?: never;\n transformer?: never;\n}\n\n// ============================================================================\n// Union Types for Each Chart\n// ============================================================================\n\n/** Base union type - either query-based or data-based */\nexport type UnifiedChartProps = QueryProps | DataProps;\n\n// ============================================================================\n// Chart-Specific Props\n// ============================================================================\n\n/** Props specific to bar charts */\nexport interface BarChartSpecificProps {\n /** Chart orientation @default \"vertical\" */\n orientation?: Orientation;\n /** Stack bars */\n stacked?: boolean;\n}\n\n/** Props specific to line charts */\nexport interface LineChartSpecificProps {\n /** Chart orientation @default \"vertical\" */\n orientation?: Orientation;\n /** Show data point symbols @default false */\n showSymbol?: boolean;\n /** Smooth line curves @default true */\n smooth?: boolean;\n}\n\n/** Props specific to area charts */\nexport interface AreaChartSpecificProps {\n /** Chart orientation @default \"vertical\" */\n orientation?: Orientation;\n /** Show data point symbols @default false */\n showSymbol?: boolean;\n /** Smooth line curves @default true */\n smooth?: boolean;\n /** Stack areas @default false */\n stacked?: boolean;\n}\n\n/** Props specific to scatter charts */\nexport interface ScatterChartSpecificProps {\n /** Symbol size @default 8 */\n symbolSize?: number;\n}\n\n/** Props specific to pie/donut charts */\nexport interface PieChartSpecificProps {\n /** Inner radius for donut charts (0-100%) @default 0 */\n innerRadius?: number;\n /** Show labels on slices @default true */\n showLabels?: boolean;\n /** Label position @default \"outside\" */\n labelPosition?: \"outside\" | \"inside\" | \"center\";\n}\n\n/** Props specific to radar charts */\nexport interface RadarChartSpecificProps {\n /** Show area fill @default true */\n showArea?: boolean;\n}\n\n/** Props specific to heatmap charts */\nexport interface HeatmapChartSpecificProps {\n /**\n * Field key for the Y-axis categories.\n * For heatmaps, data should have: xKey (column), yAxisKey (row), and yKey (value).\n */\n yAxisKey?: string;\n /** Min value for color scale (auto-detected if not provided) */\n min?: number;\n /** Max value for color scale (auto-detected if not provided) */\n max?: number;\n /** Show value labels on cells @default false */\n showLabels?: boolean;\n}\n\n// ============================================================================\n// Complete Chart Props (union + specific)\n// ============================================================================\n\nexport type BarChartProps = (QueryProps | DataProps) & BarChartSpecificProps;\nexport type LineChartProps = (QueryProps | DataProps) & LineChartSpecificProps;\nexport type AreaChartProps = (QueryProps | DataProps) & AreaChartSpecificProps;\nexport type ScatterChartProps = (QueryProps | DataProps) &\n ScatterChartSpecificProps;\nexport type PieChartProps = (QueryProps | DataProps) & PieChartSpecificProps;\nexport type DonutChartProps = (QueryProps | DataProps) & PieChartSpecificProps;\nexport type RadarChartProps = (QueryProps | DataProps) &\n RadarChartSpecificProps;\nexport type HeatmapChartProps = (QueryProps | DataProps) &\n HeatmapChartSpecificProps;\n\n// ============================================================================\n// Internal Types\n// ============================================================================\n\n/** Base normalized data shared by all chart types */\nexport interface NormalizedChartDataBase {\n xData: (string | number)[];\n xField: string;\n yFields: string[];\n chartType: \"timeseries\" | \"categorical\";\n}\n\n/** Normalized chart data for rendering (standard charts) */\nexport interface NormalizedChartData extends NormalizedChartDataBase {\n yDataMap: Record<string, (string | number)[]>;\n}\n\n/** Type guard to check if data is an Arrow Table */\nexport function isArrowTable(data: ChartData): data is Table {\n return (\n data !== null &&\n typeof data === \"object\" &&\n \"schema\" in data &&\n \"numRows\" in data &&\n typeof (data as Table).getChild === \"function\"\n );\n}\n\n/** Type guard to check if props are query-based */\nexport function isQueryProps(props: UnifiedChartProps): props is QueryProps {\n return (\n \"queryKey\" in props &&\n typeof props.queryKey === \"string\" &&\n props.queryKey.length > 0\n );\n}\n\n/** Type guard to check if props are data-based */\nexport function isDataProps(props: UnifiedChartProps): props is DataProps {\n return \"data\" in props && props.data != null;\n}\n"],"mappings":";;AAuTA,SAAgB,aAAa,MAAgC;AAC3D,QACE,SAAS,QACT,OAAO,SAAS,YAChB,YAAY,QACZ,aAAa,QACb,OAAQ,KAAe,aAAa;;;AAKxC,SAAgB,aAAa,OAA+C;AAC1E,QACE,cAAc,SACd,OAAO,MAAM,aAAa,YAC1B,MAAM,SAAS,SAAS;;;AAK5B,SAAgB,YAAY,OAA8C;AACxE,QAAO,UAAU,SAAS,MAAM,QAAQ"}
|
|
1
|
+
{"version":3,"file":"types.js","names":[],"sources":["../../../src/react/charts/types.ts"],"sourcesContent":["import type { Table } from \"apache-arrow\";\n\n// ============================================================================\n// Data Format Types\n// ============================================================================\n\n/**\n * Supported data formats for analytics queries.\n *\n * \"json\" and \"arrow\" are legacy aliases kept for backwards compatibility\n * with appkit-ui < 0.33.0 — safe to remove once no consumer is on a\n * pre-0.33.0 version. resolveFormat() normalizes them to their canonical\n * equivalents before any downstream code reads the value.\n */\nexport type DataFormat =\n | \"json_array\"\n | \"arrow_stream\"\n | \"auto\"\n /** @deprecated Use \"json_array\". Safe to remove once no consumer is on appkit-ui < 0.33.0. */\n | \"json\"\n /** @deprecated Use \"arrow_stream\". Safe to remove once no consumer is on appkit-ui < 0.33.0. */\n | \"arrow\";\n\n/** Chart orientation */\nexport type Orientation = \"vertical\" | \"horizontal\";\n\n/** Supported chart types */\nexport type ChartType =\n | \"bar\"\n | \"line\"\n | \"area\"\n | \"pie\"\n | \"donut\"\n | \"scatter\"\n | \"radar\"\n | \"heatmap\";\n\n/** Data that can be passed to unified charts */\nexport type ChartData = Table | Record<string, unknown>[];\n\n/** One row of chart data (indexable, to type plain data modules). */\nexport type ChartRow = Record<string, unknown>;\n\n/** A chart's `data`: an Arrow Table, or rows (interfaces and `as const` arrays too). */\nexport type ChartDataInput = Table | readonly object[];\n\n/** Formats a measure value for chart axes, tooltips, and value labels. */\nexport type ChartValueFormatter = (\n value: string | number,\n field: string,\n) => string;\n\n// ============================================================================\n// Base Props (shared by all charts)\n// ============================================================================\n\n/** Color palette types for different visualization needs */\nexport type ChartColorPalette = \"categorical\" | \"sequential\" | \"diverging\";\n\n/** Resolved colors for the chart UI — axis text, titles, grid lines, and tooltip. */\nexport interface ChartUITokens {\n /** Axis tick labels (≈ `--muted-foreground`) */\n axisLabel: string;\n /** Axis names, legend, title, and visualMap text (≈ `--foreground`) */\n axisTitle: string;\n /** Axis, tick, and split (grid) lines (≈ `--border`) */\n grid: string;\n /** Tooltip popover background (≈ `--popover`) */\n tooltipBg: string;\n}\n\n/** Common visual and behavior props for all charts */\nexport interface ChartBaseProps {\n /** Chart title */\n title?: string;\n /** Show legend */\n showLegend?: boolean;\n /**\n * Color palette to use. Auto-selected based on chart type if not specified.\n * - \"categorical\": Distinct colors for different categories (bar, pie, line)\n * - \"sequential\": Gradient for magnitude/intensity (heatmap)\n * - \"diverging\": Two-tone for positive/negative values\n */\n colorPalette?: ChartColorPalette;\n /** Custom colors for series (overrides colorPalette) */\n colors?: string[];\n /** Chart height in pixels. Defaults to filling its parent (see `chartSizeStyle`). */\n height?: number;\n /** Additional CSS classes */\n className?: string;\n\n /** X-axis field key. Auto-detected from schema if not provided. */\n xKey?: string;\n /** Y-axis field key(s). Auto-detected from schema if not provided. */\n yKey?: string | string[];\n\n /** Accessibility label for screen readers */\n ariaLabel?: string;\n /** Test ID for automated testing */\n testId?: string;\n\n /** Additional ECharts options to merge */\n options?: Record<string, unknown>;\n\n /**\n * Formats measure values in the chart's built-in value axes, tooltips, and\n * value labels. `field` is the corresponding `yKey`, so one formatter can\n * select a different format for each series.\n *\n * For charts with multiple series on one value axis, axis ticks use the\n * first `yKey`; each tooltip uses its own series field.\n */\n valueFormatter?: ChartValueFormatter;\n\n /**\n * Pointer-only: charts render to <canvas>, so this does not fire for keyboard\n * users. Provide a keyboard-accessible equivalent (e.g. a table row action) for\n * the same action.\n */\n onDataClick?: (datum: ChartClickDatum) => void;\n\n /**\n * Controlled selection by category name. Matching data element(s) render at full\n * prominence while the rest are dimmed. Drive it from your own state to reflect a\n * cross-filter or selection. Categorical charts (bar, pie/donut) show emphasis;\n * other chart types ignore it.\n */\n selected?: string | string[];\n}\n\n// ============================================================================\n// Interaction / Click Events\n// ============================================================================\n\n/**\n * A normalized description of a clicked chart element.\n *\n * In the common cross-filter case, {@link ChartClickDatum.name} carries the\n * dimension value of the clicked element.\n */\nexport interface ChartClickDatum {\n /** Category label of the clicked element — the dimension value in the common cross-filter case. */\n name: string;\n /**\n * The datum's scalar value:\n * - bar / pie — the datum itself.\n * - time-series / scatter — the y-component of the `[x, y]` point (see\n * {@link ChartClickDatum.x} / {@link ChartClickDatum.y}).\n * - heatmap — the cell value (the third entry of ECharts'\n * `[xIndex, yIndex, value]` triple), *not* an axis index.\n * - radar — `null`; the item holds one value per indicator, so there is no\n * single scalar to report. Read the vector from {@link ChartClickDatum.raw}.\n *\n * `null` whenever there is no scalar value to surface.\n */\n value: number | string | null;\n x?: number | string;\n y?: number | string;\n seriesName?: string;\n dataIndex: number;\n seriesIndex: number;\n // Untouched ECharts event params.\n raw: unknown;\n}\n\n// ============================================================================\n// Query-based Props (chart fetches data)\n// ============================================================================\n\n/** Props for query-based data fetching */\nexport interface QueryProps extends ChartBaseProps {\n /** Analytics query key registered with analytics plugin */\n queryKey: string;\n /** Query parameters passed to the analytics endpoint */\n parameters?: Record<string, unknown>;\n /**\n * Data format to use\n * - \"json_array\": Use JSON format (smaller payloads, simpler)\n * - \"arrow_stream\": Use Arrow format (faster for large datasets)\n * - \"auto\": Automatically select based on expected data size\n * @default \"auto\"\n */\n format?: DataFormat;\n /** Transform raw data before rendering */\n transformer?: <T>(data: T) => T;\n // Discriminator: cannot use direct data with query\n data?: never;\n}\n\n// ============================================================================\n// Data-based Props (chart receives data externally)\n// ============================================================================\n\n/** Props for direct data injection */\nexport interface DataProps extends ChartBaseProps {\n /** Arrow Table or JSON array */\n data: ChartDataInput;\n\n // Discriminator: cannot use query props with direct data\n queryKey?: never;\n parameters?: never;\n format?: never;\n transformer?: never;\n}\n\n// ============================================================================\n// Union Types for Each Chart\n// ============================================================================\n\n/** Base union type - either query-based or data-based */\nexport type UnifiedChartProps = QueryProps | DataProps;\n\n// ============================================================================\n// Chart-Specific Props\n// ============================================================================\n\n/** Props specific to bar charts */\nexport interface BarChartSpecificProps {\n /** Chart orientation @default \"vertical\" */\n orientation?: Orientation;\n /** Stack bars */\n stacked?: boolean;\n}\n\n/** Props specific to line charts */\nexport interface LineChartSpecificProps {\n /** Chart orientation @default \"vertical\" */\n orientation?: Orientation;\n /** Show data point symbols @default false */\n showSymbol?: boolean;\n /** Smooth line curves @default true */\n smooth?: boolean;\n}\n\n/** Props specific to area charts */\nexport interface AreaChartSpecificProps {\n /** Chart orientation @default \"vertical\" */\n orientation?: Orientation;\n /** Show data point symbols @default false */\n showSymbol?: boolean;\n /** Smooth line curves @default true */\n smooth?: boolean;\n /** Stack areas @default false */\n stacked?: boolean;\n}\n\n/** Props specific to scatter charts */\nexport interface ScatterChartSpecificProps {\n /** Symbol size @default 8 */\n symbolSize?: number;\n}\n\n/** Props specific to pie/donut charts */\nexport interface PieChartSpecificProps {\n /** Inner radius for donut charts (0-100%) @default 0 */\n innerRadius?: number;\n /** Show labels on slices @default true */\n showLabels?: boolean;\n /** Label position @default \"outside\" */\n labelPosition?: \"outside\" | \"inside\" | \"center\";\n}\n\n/** Props specific to radar charts */\nexport interface RadarChartSpecificProps {\n /** Show area fill @default true */\n showArea?: boolean;\n}\n\n/** Props specific to heatmap charts */\nexport interface HeatmapChartSpecificProps {\n /**\n * Field key for the Y-axis categories.\n * For heatmaps, data should have: xKey (column), yAxisKey (row), and yKey (value).\n */\n yAxisKey?: string;\n /** Min value for color scale (auto-detected if not provided) */\n min?: number;\n /** Max value for color scale (auto-detected if not provided) */\n max?: number;\n /** Show value labels on cells @default false */\n showLabels?: boolean;\n}\n\n// ============================================================================\n// Complete Chart Props (union + specific)\n// ============================================================================\n\nexport type BarChartProps = (QueryProps | DataProps) & BarChartSpecificProps;\nexport type LineChartProps = (QueryProps | DataProps) & LineChartSpecificProps;\nexport type AreaChartProps = (QueryProps | DataProps) & AreaChartSpecificProps;\nexport type ScatterChartProps = (QueryProps | DataProps) &\n ScatterChartSpecificProps;\nexport type PieChartProps = (QueryProps | DataProps) & PieChartSpecificProps;\nexport type DonutChartProps = (QueryProps | DataProps) & PieChartSpecificProps;\nexport type RadarChartProps = (QueryProps | DataProps) &\n RadarChartSpecificProps;\nexport type HeatmapChartProps = (QueryProps | DataProps) &\n HeatmapChartSpecificProps;\n\n// ============================================================================\n// Internal Types\n// ============================================================================\n\n/** Base normalized data shared by all chart types */\nexport interface NormalizedChartDataBase {\n xData: (string | number)[];\n xField: string;\n yFields: string[];\n chartType: \"timeseries\" | \"categorical\";\n}\n\n/** Normalized chart data for rendering (standard charts) */\nexport interface NormalizedChartData extends NormalizedChartDataBase {\n yDataMap: Record<string, (string | number)[]>;\n}\n\n/** Type guard to check if data is an Arrow Table */\nexport function isArrowTable(data: ChartData): data is Table {\n return (\n data !== null &&\n typeof data === \"object\" &&\n \"schema\" in data &&\n \"numRows\" in data &&\n typeof (data as Table).getChild === \"function\"\n );\n}\n\n/** Type guard to check if props are query-based */\nexport function isQueryProps(props: UnifiedChartProps): props is QueryProps {\n return (\n \"queryKey\" in props &&\n typeof props.queryKey === \"string\" &&\n props.queryKey.length > 0\n );\n}\n\n/** Type guard to check if props are data-based */\nexport function isDataProps(props: UnifiedChartProps): props is DataProps {\n return \"data\" in props && props.data != null;\n}\n"],"mappings":";;AA6TA,SAAgB,aAAa,MAAgC;AAC3D,QACE,SAAS,QACT,OAAO,SAAS,YAChB,YAAY,QACZ,aAAa,QACb,OAAQ,KAAe,aAAa;;;AAKxC,SAAgB,aAAa,OAA+C;AAC1E,QACE,cAAc,SACd,OAAO,MAAM,aAAa,YAC1B,MAAM,SAAS,SAAS;;;AAK5B,SAAgB,YAAY,OAA8C;AACxE,QAAO,UAAU,SAAS,MAAM,QAAQ"}
|
|
@@ -25,7 +25,7 @@ interface ChartWrapperDataProps {
|
|
|
25
25
|
transformer?: never;
|
|
26
26
|
}
|
|
27
27
|
interface CommonProps {
|
|
28
|
-
/** Chart height in pixels */
|
|
28
|
+
/** Chart height in pixels. By default the chart fills its parent's height (at least 160px). */
|
|
29
29
|
height?: number;
|
|
30
30
|
/** Additional CSS classes */
|
|
31
31
|
className?: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.d.ts","names":[],"sources":["../../../src/react/charts/wrapper.tsx"],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"wrapper.d.ts","names":[],"sources":["../../../src/react/charts/wrapper.tsx"],"mappings":";;;;;UAiCU,sBAAA;;EAER,QAAA;EAFQ;EAIR,UAAA,GAAa,MAAA;EAJiB;EAM9B,MAAA,GAAS,UAAA;EAAA;EAET,WAAA,OAAkB,IAAA,EAAM,CAAA,KAAM,CAAA;EAAA;EAE9B,IAAA;AAAA;AAAA,UAGQ,qBAAA;EATR;EAWA,IAAA,EAAM,SAAA;EATN;EAWA,QAAA;EACA,UAAA;EACA,MAAA;EACA,WAAA;AAAA;AAAA,UAGQ,WAAA;EAbR;EAeA,MAAA;EAfI;EAiBJ,SAAA;EAd6B;EAgB7B,SAAA;EAde;EAgBf,MAAA;EAhBM;EAkBN,QAAA,GAAW,IAAA,EAAM,SAAA,KAAc,SAAA;AAAA;AAAA,KAGrB,iBAAA,GAAoB,WAAA,IAC7B,sBAAA,GAAyB,qBAAA;;;;AAjBf;;;;;;;;;;;;;;AAgBb;;;;;iBAwHgB,YAAA,CAAa,KAAA,EAAO,iBAAA,GAAiB,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { chartSizeStyle } from "./constants.js";
|
|
1
2
|
import { isArrowTable } from "./types.js";
|
|
2
3
|
import { useChartData } from "../hooks/use-chart-data.js";
|
|
3
4
|
import { ChartErrorBoundary } from "./chart-error-boundary.js";
|
|
@@ -20,15 +21,21 @@ function QueryModeContent({ queryKey, parameters, format, transformer, height, c
|
|
|
20
21
|
format,
|
|
21
22
|
transformer
|
|
22
23
|
});
|
|
23
|
-
if (isWarehouseWaiting(loading, data, warehouseStatus)) return /* @__PURE__ */ jsx(
|
|
24
|
-
|
|
24
|
+
if (isWarehouseWaiting(loading, data, warehouseStatus)) return /* @__PURE__ */ jsx("div", {
|
|
25
|
+
style: chartSizeStyle(height),
|
|
26
|
+
children: /* @__PURE__ */ jsx(ResourceWaitingPlaceholder, { height: "100%" })
|
|
27
|
+
});
|
|
28
|
+
if (loading) return /* @__PURE__ */ jsx("div", {
|
|
29
|
+
style: chartSizeStyle(height),
|
|
30
|
+
children: /* @__PURE__ */ jsx(LoadingSkeleton, { height: "100%" })
|
|
31
|
+
});
|
|
25
32
|
if (error) return /* @__PURE__ */ jsx(ErrorState, { error });
|
|
26
33
|
if (isEmpty || !data) return /* @__PURE__ */ jsx(EmptyState, {});
|
|
27
34
|
return /* @__PURE__ */ jsx(ChartErrorBoundary, {
|
|
28
35
|
fallback: /* @__PURE__ */ jsx(ErrorState, { error: "Failed to render chart" }),
|
|
29
36
|
children: /* @__PURE__ */ jsx("div", {
|
|
30
37
|
className,
|
|
31
|
-
style:
|
|
38
|
+
style: chartSizeStyle(height),
|
|
32
39
|
"aria-label": ariaLabel,
|
|
33
40
|
"data-testid": testId,
|
|
34
41
|
role: "img",
|
|
@@ -42,7 +49,7 @@ function DataModeContent({ data, height, className, ariaLabel, testId, children
|
|
|
42
49
|
fallback: /* @__PURE__ */ jsx(ErrorState, { error: "Failed to render chart" }),
|
|
43
50
|
children: /* @__PURE__ */ jsx("div", {
|
|
44
51
|
className,
|
|
45
|
-
style:
|
|
52
|
+
style: chartSizeStyle(height),
|
|
46
53
|
"aria-label": ariaLabel,
|
|
47
54
|
"data-testid": testId,
|
|
48
55
|
role: "img",
|
|
@@ -73,7 +80,7 @@ function DataModeContent({ data, height, className, ariaLabel, testId, children
|
|
|
73
80
|
* ```
|
|
74
81
|
*/
|
|
75
82
|
function ChartWrapper(props) {
|
|
76
|
-
const { height
|
|
83
|
+
const { height, className, ariaLabel, testId, children } = props;
|
|
77
84
|
if ("data" in props && props.data !== void 0) return /* @__PURE__ */ jsx(DataModeContent, {
|
|
78
85
|
data: props.data,
|
|
79
86
|
height,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"wrapper.js","names":[],"sources":["../../../src/react/charts/wrapper.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nimport type { WarehouseStatus } from \"../hooks/types\";\nimport { useChartData } from \"../hooks/use-chart-data\";\nimport { ChartErrorBoundary } from \"./chart-error-boundary\";\nimport { EmptyState } from \"./empty\";\nimport { ErrorState } from \"./error\";\nimport { LoadingSkeleton, ResourceWaitingPlaceholder } from \"./loading\";\nimport type { ChartData, DataFormat } from \"./types\";\nimport { isArrowTable } from \"./types\";\n\nconst WAREHOUSE_ERROR_STATES = new Set([\"DELETED\", \"DELETING\"]);\n\nfunction isWarehouseWaiting(\n loading: boolean,\n data: ChartData | null,\n warehouseStatus: WarehouseStatus | null,\n): boolean {\n if (!loading || data || !warehouseStatus) return false;\n if (\n warehouseStatus.state === \"RUNNING\" ||\n WAREHOUSE_ERROR_STATES.has(warehouseStatus.state)\n ) {\n return false;\n }\n return true;\n}\n\n// ============================================================================\n// Props Types\n// ============================================================================\n\ninterface ChartWrapperQueryProps {\n /** Analytics query key */\n queryKey: string;\n /** Query parameters */\n parameters?: Record<string, unknown>;\n /** Data format preference */\n format?: DataFormat;\n /** Transform data after fetching */\n transformer?: <T>(data: T) => T;\n /** Direct data - not used in query mode */\n data?: never;\n}\n\ninterface ChartWrapperDataProps {\n /** Direct data (Arrow Table or JSON array) */\n data: ChartData;\n /** Not used in data mode */\n queryKey?: never;\n parameters?: never;\n format?: never;\n transformer?: never;\n}\n\ninterface CommonProps {\n /** Chart height in pixels */\n height?: number;\n /** Additional CSS classes */\n className?: string;\n /** Accessibility label */\n ariaLabel?: string;\n /** Test ID for automated testing */\n testId?: string;\n /** Render function receiving the chart data */\n children: (data: ChartData) => ReactNode;\n}\n\nexport type ChartWrapperProps = CommonProps &\n (ChartWrapperQueryProps | ChartWrapperDataProps);\n\n// ============================================================================\n// Query Mode Content\n// ============================================================================\n\nfunction QueryModeContent({\n queryKey,\n parameters,\n format,\n transformer,\n height,\n className,\n ariaLabel,\n testId,\n children,\n}: CommonProps & ChartWrapperQueryProps) {\n const { data, loading, error, isEmpty, warehouseStatus } = useChartData({\n queryKey,\n parameters,\n format,\n transformer,\n });\n\n if (isWarehouseWaiting(loading, data, warehouseStatus)) {\n return <
|
|
1
|
+
{"version":3,"file":"wrapper.js","names":[],"sources":["../../../src/react/charts/wrapper.tsx"],"sourcesContent":["import type { ReactNode } from \"react\";\n\nimport type { WarehouseStatus } from \"../hooks/types\";\nimport { useChartData } from \"../hooks/use-chart-data\";\nimport { ChartErrorBoundary } from \"./chart-error-boundary\";\nimport { chartSizeStyle } from \"./constants\";\nimport { EmptyState } from \"./empty\";\nimport { ErrorState } from \"./error\";\nimport { LoadingSkeleton, ResourceWaitingPlaceholder } from \"./loading\";\nimport type { ChartData, DataFormat } from \"./types\";\nimport { isArrowTable } from \"./types\";\n\nconst WAREHOUSE_ERROR_STATES = new Set([\"DELETED\", \"DELETING\"]);\n\nfunction isWarehouseWaiting(\n loading: boolean,\n data: ChartData | null,\n warehouseStatus: WarehouseStatus | null,\n): boolean {\n if (!loading || data || !warehouseStatus) return false;\n if (\n warehouseStatus.state === \"RUNNING\" ||\n WAREHOUSE_ERROR_STATES.has(warehouseStatus.state)\n ) {\n return false;\n }\n return true;\n}\n\n// ============================================================================\n// Props Types\n// ============================================================================\n\ninterface ChartWrapperQueryProps {\n /** Analytics query key */\n queryKey: string;\n /** Query parameters */\n parameters?: Record<string, unknown>;\n /** Data format preference */\n format?: DataFormat;\n /** Transform data after fetching */\n transformer?: <T>(data: T) => T;\n /** Direct data - not used in query mode */\n data?: never;\n}\n\ninterface ChartWrapperDataProps {\n /** Direct data (Arrow Table or JSON array) */\n data: ChartData;\n /** Not used in data mode */\n queryKey?: never;\n parameters?: never;\n format?: never;\n transformer?: never;\n}\n\ninterface CommonProps {\n /** Chart height in pixels. By default the chart fills its parent's height (at least 160px). */\n height?: number;\n /** Additional CSS classes */\n className?: string;\n /** Accessibility label */\n ariaLabel?: string;\n /** Test ID for automated testing */\n testId?: string;\n /** Render function receiving the chart data */\n children: (data: ChartData) => ReactNode;\n}\n\nexport type ChartWrapperProps = CommonProps &\n (ChartWrapperQueryProps | ChartWrapperDataProps);\n\n// ============================================================================\n// Query Mode Content\n// ============================================================================\n\nfunction QueryModeContent({\n queryKey,\n parameters,\n format,\n transformer,\n height,\n className,\n ariaLabel,\n testId,\n children,\n}: CommonProps & ChartWrapperQueryProps) {\n const { data, loading, error, isEmpty, warehouseStatus } = useChartData({\n queryKey,\n parameters,\n format,\n transformer,\n });\n\n if (isWarehouseWaiting(loading, data, warehouseStatus)) {\n return (\n <div style={chartSizeStyle(height)}>\n <ResourceWaitingPlaceholder height=\"100%\" />\n </div>\n );\n }\n if (loading) {\n return (\n <div style={chartSizeStyle(height)}>\n <LoadingSkeleton height=\"100%\" />\n </div>\n );\n }\n if (error) return <ErrorState error={error} />;\n if (isEmpty || !data) return <EmptyState />;\n\n return (\n <ChartErrorBoundary\n fallback={<ErrorState error=\"Failed to render chart\" />}\n >\n <div\n className={className}\n style={chartSizeStyle(height)}\n aria-label={ariaLabel}\n data-testid={testId}\n role=\"img\"\n >\n {children(data)}\n </div>\n </ChartErrorBoundary>\n );\n}\n\n// ============================================================================\n// Data Mode Content\n// ============================================================================\n\nfunction DataModeContent({\n data,\n height,\n className,\n ariaLabel,\n testId,\n children,\n}: CommonProps & ChartWrapperDataProps) {\n const isEmpty = isArrowTable(data)\n ? data.numRows === 0\n : !Array.isArray(data) || data.length === 0;\n\n if (isEmpty) return <EmptyState />;\n\n return (\n <ChartErrorBoundary\n fallback={<ErrorState error=\"Failed to render chart\" />}\n >\n <div\n className={className}\n style={chartSizeStyle(height)}\n aria-label={ariaLabel}\n data-testid={testId}\n role=\"img\"\n >\n {children(data)}\n </div>\n </ChartErrorBoundary>\n );\n}\n\n// ============================================================================\n// Main Wrapper Component\n// ============================================================================\n\n/**\n * Wrapper component for charts.\n * Handles data fetching (query mode) or direct data injection (data mode).\n *\n * @example Query mode - fetches data from analytics endpoint\n * ```tsx\n * <ChartWrapper\n * queryKey=\"spend_data\"\n * parameters={{ limit: 100 }}\n * format=\"auto\"\n * >\n * {(data) => <MyChart data={data} />}\n * </ChartWrapper>\n * ```\n *\n * @example Data mode - uses provided data directly\n * ```tsx\n * <ChartWrapper data={myArrowTable}>\n * {(data) => <MyChart data={data} />}\n * </ChartWrapper>\n * ```\n */\nexport function ChartWrapper(props: ChartWrapperProps) {\n const { height, className, ariaLabel, testId, children } = props;\n\n // Data mode: use provided data directly\n if (\"data\" in props && props.data !== undefined) {\n return (\n <DataModeContent\n data={props.data}\n height={height}\n className={className}\n ariaLabel={ariaLabel}\n testId={testId}\n >\n {children}\n </DataModeContent>\n );\n }\n\n // Query mode: fetch data from analytics endpoint\n if (\"queryKey\" in props && props.queryKey !== undefined) {\n return (\n <QueryModeContent\n queryKey={props.queryKey}\n parameters={props.parameters}\n format={props.format}\n transformer={props.transformer}\n height={height}\n className={className}\n ariaLabel={ariaLabel}\n testId={testId}\n >\n {children}\n </QueryModeContent>\n );\n }\n\n // Should never reach here due to TypeScript, but safety fallback\n return <ErrorState error=\"Chart requires either 'queryKey' or 'data' prop\" />;\n}\n"],"mappings":";;;;;;;;;;AAYA,MAAM,yBAAyB,IAAI,IAAI,CAAC,WAAW,WAAW,CAAC;AAE/D,SAAS,mBACP,SACA,MACA,iBACS;AACT,KAAI,CAAC,WAAW,QAAQ,CAAC,gBAAiB,QAAO;AACjD,KACE,gBAAgB,UAAU,aAC1B,uBAAuB,IAAI,gBAAgB,MAAM,CAEjD,QAAO;AAET,QAAO;;AAkDT,SAAS,iBAAiB,EACxB,UACA,YACA,QACA,aACA,QACA,WACA,WACA,QACA,YACuC;CACvC,MAAM,EAAE,MAAM,SAAS,OAAO,SAAS,oBAAoB,aAAa;EACtE;EACA;EACA;EACA;EACD,CAAC;AAEF,KAAI,mBAAmB,SAAS,MAAM,gBAAgB,CACpD,QACE,oBAAC;EAAI,OAAO,eAAe,OAAO;YAChC,oBAAC,8BAA2B,QAAO,SAAS;GACxC;AAGV,KAAI,QACF,QACE,oBAAC;EAAI,OAAO,eAAe,OAAO;YAChC,oBAAC,mBAAgB,QAAO,SAAS;GAC7B;AAGV,KAAI,MAAO,QAAO,oBAAC,cAAkB,QAAS;AAC9C,KAAI,WAAW,CAAC,KAAM,QAAO,oBAAC,eAAa;AAE3C,QACE,oBAAC;EACC,UAAU,oBAAC,cAAW,OAAM,2BAA2B;YAEvD,oBAAC;GACY;GACX,OAAO,eAAe,OAAO;GAC7B,cAAY;GACZ,eAAa;GACb,MAAK;aAEJ,SAAS,KAAK;IACX;GACa;;AAQzB,SAAS,gBAAgB,EACvB,MACA,QACA,WACA,WACA,QACA,YACsC;AAKtC,KAJgB,aAAa,KAAK,GAC9B,KAAK,YAAY,IACjB,CAAC,MAAM,QAAQ,KAAK,IAAI,KAAK,WAAW,EAE/B,QAAO,oBAAC,eAAa;AAElC,QACE,oBAAC;EACC,UAAU,oBAAC,cAAW,OAAM,2BAA2B;YAEvD,oBAAC;GACY;GACX,OAAO,eAAe,OAAO;GAC7B,cAAY;GACZ,eAAa;GACb,MAAK;aAEJ,SAAS,KAAK;IACX;GACa;;;;;;;;;;;;;;;;;;;;;;;;AA8BzB,SAAgB,aAAa,OAA0B;CACrD,MAAM,EAAE,QAAQ,WAAW,WAAW,QAAQ,aAAa;AAG3D,KAAI,UAAU,SAAS,MAAM,SAAS,OACpC,QACE,oBAAC;EACC,MAAM,MAAM;EACJ;EACG;EACA;EACH;EAEP;GACe;AAKtB,KAAI,cAAc,SAAS,MAAM,aAAa,OAC5C,QACE,oBAAC;EACC,UAAU,MAAM;EAChB,YAAY,MAAM;EAClB,QAAQ,MAAM;EACd,aAAa,MAAM;EACX;EACG;EACA;EACH;EAEP;GACgB;AAKvB,QAAO,oBAAC,cAAW,OAAM,oDAAoD"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { ReactNode } from "react";
|
|
2
|
+
import * as react_jsx_runtime0 from "react/jsx-runtime";
|
|
3
|
+
|
|
4
|
+
//#region src/react/design-page.d.ts
|
|
5
|
+
interface DesignPageProps {
|
|
6
|
+
children: ReactNode;
|
|
7
|
+
/** Called with each render error the page hits. */
|
|
8
|
+
onError?: (error: Error) => void;
|
|
9
|
+
/** Changing it retries rendering after an error (e.g. after a hot update). */
|
|
10
|
+
resetKey?: unknown;
|
|
11
|
+
/** Shown for an error before anything rendered. Defaults to the message. */
|
|
12
|
+
errorFallback?: (error: Error) => ReactNode;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* The shell the `design()` plugin renders every `/design` page in: the app's
|
|
16
|
+
* theme from the first paint, and the last good frame instead of a broken one.
|
|
17
|
+
*/
|
|
18
|
+
declare function DesignPage({
|
|
19
|
+
children,
|
|
20
|
+
onError,
|
|
21
|
+
resetKey,
|
|
22
|
+
errorFallback
|
|
23
|
+
}: DesignPageProps): react_jsx_runtime0.JSX.Element;
|
|
24
|
+
type DraftPlaceholderKind = "chart" | "table" | "card" | "generic";
|
|
25
|
+
/** Skeleton the `design()` plugin shows for a component a streaming draft hasn't defined yet. */
|
|
26
|
+
declare function DraftPlaceholder({
|
|
27
|
+
kind
|
|
28
|
+
}: {
|
|
29
|
+
kind?: DraftPlaceholderKind;
|
|
30
|
+
}): react_jsx_runtime0.JSX.Element;
|
|
31
|
+
//#endregion
|
|
32
|
+
export { DesignPage, DesignPageProps, DraftPlaceholder, DraftPlaceholderKind };
|
|
33
|
+
//# sourceMappingURL=design-page.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-page.d.ts","names":[],"sources":["../../src/react/design-page.tsx"],"mappings":";;;;UAuHiB,eAAA;EACf,QAAA,EAAU,SAAA;;EAEV,OAAA,IAAW,KAAA,EAAO,KAAA;EAHY;EAK9B,QAAA;EAJU;EAMV,aAAA,IAAiB,KAAA,EAAO,KAAA,KAAU,SAAA;AAAA;;;;;iBAOpB,UAAA,CAAA;EACd,QAAA;EACA,OAAA;EACA,QAAA;EACA;AAAA,GACC,eAAA,GAAe,kBAAA,CAAA,GAAA,CAAA,OAAA;AAAA,KAmDN,oBAAA;;iBAGI,gBAAA,CAAA;EACd;AAAA;EAEA,IAAA,GAAO,oBAAA;AAAA,IACR,kBAAA,CAAA,GAAA,CAAA,OAAA"}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { Skeleton } from "./ui/skeleton.js";
|
|
2
|
+
import { useDesignReady } from "./hooks/use-design-ready.js";
|
|
3
|
+
import { Component, useLayoutEffect, useRef } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
|
|
6
|
+
//#region src/react/design-page.tsx
|
|
7
|
+
/** `?theme=dark|light`, else the system setting, applied before the first paint. */
|
|
8
|
+
function useDesignTheme() {
|
|
9
|
+
useLayoutEffect(() => {
|
|
10
|
+
const param = new URLSearchParams(location.search).get("theme");
|
|
11
|
+
const media = window.matchMedia?.("(prefers-color-scheme: dark)");
|
|
12
|
+
const apply = () => document.documentElement.classList.toggle("dark", param ? param === "dark" : !!media?.matches);
|
|
13
|
+
apply();
|
|
14
|
+
if (param || !media) return;
|
|
15
|
+
media.addEventListener("change", apply);
|
|
16
|
+
return () => media.removeEventListener("change", apply);
|
|
17
|
+
}, []);
|
|
18
|
+
}
|
|
19
|
+
function capture(root) {
|
|
20
|
+
return {
|
|
21
|
+
nodes: Array.from(root.childNodes).map((n) => n.cloneNode(true)),
|
|
22
|
+
pixels: Array.from(root.querySelectorAll("canvas")).map((c) => {
|
|
23
|
+
const copy = document.createElement("canvas");
|
|
24
|
+
copy.width = c.width;
|
|
25
|
+
copy.height = c.height;
|
|
26
|
+
if (c.width && c.height) copy.getContext("2d")?.drawImage(c, 0, 0);
|
|
27
|
+
return copy;
|
|
28
|
+
})
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
function restore(holder, frame) {
|
|
32
|
+
if (!holder) return;
|
|
33
|
+
holder.replaceChildren(...frame.nodes.map((n) => n.cloneNode(true)));
|
|
34
|
+
holder.querySelectorAll("canvas").forEach((c, i) => {
|
|
35
|
+
const px = frame.pixels[i];
|
|
36
|
+
if (!px?.width || !px.height) return;
|
|
37
|
+
c.width = px.width;
|
|
38
|
+
c.height = px.height;
|
|
39
|
+
c.getContext("2d")?.drawImage(px, 0, 0);
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
function HoldReady() {
|
|
43
|
+
useDesignReady(false);
|
|
44
|
+
return null;
|
|
45
|
+
}
|
|
46
|
+
var LastGoodFrame = class extends Component {
|
|
47
|
+
state = {
|
|
48
|
+
error: null,
|
|
49
|
+
resetKey: this.props.resetKey
|
|
50
|
+
};
|
|
51
|
+
static getDerivedStateFromError(error) {
|
|
52
|
+
return { error };
|
|
53
|
+
}
|
|
54
|
+
static getDerivedStateFromProps(props, state) {
|
|
55
|
+
return props.resetKey === state.resetKey ? null : {
|
|
56
|
+
error: null,
|
|
57
|
+
resetKey: props.resetKey
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
componentDidCatch(error) {
|
|
61
|
+
this.props.onError?.(error);
|
|
62
|
+
}
|
|
63
|
+
render() {
|
|
64
|
+
const { error } = this.state;
|
|
65
|
+
if (!error) return this.props.children;
|
|
66
|
+
const frame = this.props.frame.current;
|
|
67
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(HoldReady, {}), frame ? /* @__PURE__ */ jsx("div", {
|
|
68
|
+
"data-design-last-good": "",
|
|
69
|
+
style: { display: "contents" },
|
|
70
|
+
ref: (el) => restore(el, frame)
|
|
71
|
+
}) : /* @__PURE__ */ jsx("div", {
|
|
72
|
+
"data-design-error": "",
|
|
73
|
+
style: { display: "contents" },
|
|
74
|
+
children: this.props.errorFallback(error)
|
|
75
|
+
})] });
|
|
76
|
+
}
|
|
77
|
+
};
|
|
78
|
+
const defaultErrorFallback = (error) => /* @__PURE__ */ jsxs("pre", {
|
|
79
|
+
className: "text-destructive p-4 whitespace-pre-wrap",
|
|
80
|
+
children: ["Design page failed to render: ", error.message]
|
|
81
|
+
});
|
|
82
|
+
/**
|
|
83
|
+
* The shell the `design()` plugin renders every `/design` page in: the app's
|
|
84
|
+
* theme from the first paint, and the last good frame instead of a broken one.
|
|
85
|
+
*/
|
|
86
|
+
function DesignPage({ children, onError, resetKey, errorFallback = defaultErrorFallback }) {
|
|
87
|
+
useDesignTheme();
|
|
88
|
+
const root = useRef(null);
|
|
89
|
+
const frame = useRef(null);
|
|
90
|
+
useLayoutEffect(() => {
|
|
91
|
+
const el = root.current;
|
|
92
|
+
if (!el) return;
|
|
93
|
+
const keep = () => {
|
|
94
|
+
if (!el.querySelector("[data-design-last-good], [data-design-error]")) frame.current = capture(el);
|
|
95
|
+
};
|
|
96
|
+
if (el.childNodes.length > 0) keep();
|
|
97
|
+
let pending = false;
|
|
98
|
+
const observer = new MutationObserver(() => {
|
|
99
|
+
if (pending) return;
|
|
100
|
+
pending = true;
|
|
101
|
+
requestAnimationFrame(() => {
|
|
102
|
+
pending = false;
|
|
103
|
+
keep();
|
|
104
|
+
});
|
|
105
|
+
});
|
|
106
|
+
observer.observe(el, {
|
|
107
|
+
subtree: true,
|
|
108
|
+
childList: true,
|
|
109
|
+
characterData: true,
|
|
110
|
+
attributes: true
|
|
111
|
+
});
|
|
112
|
+
return () => observer.disconnect();
|
|
113
|
+
}, []);
|
|
114
|
+
return /* @__PURE__ */ jsx("div", {
|
|
115
|
+
ref: root,
|
|
116
|
+
"data-design-page": "",
|
|
117
|
+
className: "bg-background text-foreground min-h-screen",
|
|
118
|
+
children: /* @__PURE__ */ jsx(LastGoodFrame, {
|
|
119
|
+
frame,
|
|
120
|
+
resetKey,
|
|
121
|
+
onError,
|
|
122
|
+
errorFallback,
|
|
123
|
+
children
|
|
124
|
+
})
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
/** Skeleton the `design()` plugin shows for a component a streaming draft hasn't defined yet. */
|
|
128
|
+
function DraftPlaceholder({ kind = "generic" }) {
|
|
129
|
+
if (kind === "chart") return /* @__PURE__ */ jsx("div", {
|
|
130
|
+
"data-draft-placeholder": "chart",
|
|
131
|
+
className: "flex h-56 items-end gap-2 p-4",
|
|
132
|
+
children: [
|
|
133
|
+
40,
|
|
134
|
+
65,
|
|
135
|
+
50,
|
|
136
|
+
80,
|
|
137
|
+
60,
|
|
138
|
+
90,
|
|
139
|
+
70
|
|
140
|
+
].map((h) => /* @__PURE__ */ jsx(Skeleton, {
|
|
141
|
+
className: "flex-1",
|
|
142
|
+
style: { height: `${h}%` }
|
|
143
|
+
}, h))
|
|
144
|
+
});
|
|
145
|
+
if (kind === "table") return /* @__PURE__ */ jsxs("div", {
|
|
146
|
+
"data-draft-placeholder": "table",
|
|
147
|
+
className: "space-y-2 p-4",
|
|
148
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-6 w-full" }), [
|
|
149
|
+
0,
|
|
150
|
+
1,
|
|
151
|
+
2,
|
|
152
|
+
3
|
|
153
|
+
].map((r) => /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-full opacity-70" }, r))]
|
|
154
|
+
});
|
|
155
|
+
if (kind === "card") return /* @__PURE__ */ jsxs("div", {
|
|
156
|
+
"data-draft-placeholder": "card",
|
|
157
|
+
className: "space-y-3 rounded-xl border p-4",
|
|
158
|
+
children: [
|
|
159
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-1/3" }),
|
|
160
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-8 w-1/2" }),
|
|
161
|
+
/* @__PURE__ */ jsx(Skeleton, { className: "h-3 w-2/3" })
|
|
162
|
+
]
|
|
163
|
+
});
|
|
164
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
165
|
+
"data-draft-placeholder": "generic",
|
|
166
|
+
className: "space-y-2 p-2",
|
|
167
|
+
children: [/* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-3/4" }), /* @__PURE__ */ jsx(Skeleton, { className: "h-4 w-1/2" })]
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
//#endregion
|
|
172
|
+
export { DesignPage, DraftPlaceholder };
|
|
173
|
+
//# sourceMappingURL=design-page.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"design-page.js","names":[],"sources":["../../src/react/design-page.tsx"],"sourcesContent":["import { Component, type ReactNode, useLayoutEffect, useRef } from \"react\";\n\nimport { useDesignReady } from \"./hooks/use-design-ready\";\nimport { Skeleton } from \"./ui/skeleton\";\n\n/** `?theme=dark|light`, else the system setting, applied before the first paint. */\nfunction useDesignTheme() {\n useLayoutEffect(() => {\n const param = new URLSearchParams(location.search).get(\"theme\");\n const media = window.matchMedia?.(\"(prefers-color-scheme: dark)\");\n const apply = () =>\n document.documentElement.classList.toggle(\n \"dark\",\n param ? param === \"dark\" : !!media?.matches,\n );\n apply();\n if (param || !media) return;\n media.addEventListener(\"change\", apply);\n return () => media.removeEventListener(\"change\", apply);\n }, []);\n}\n\n/** The last good frame: the page's DOM, with chart canvases as pixels. */\ninterface Frame {\n nodes: Node[];\n pixels: HTMLCanvasElement[];\n}\n\nfunction capture(root: HTMLElement): Frame {\n return {\n nodes: Array.from(root.childNodes).map((n) => n.cloneNode(true)),\n pixels: Array.from(root.querySelectorAll(\"canvas\")).map((c) => {\n const copy = document.createElement(\"canvas\");\n copy.width = c.width;\n copy.height = c.height;\n // A canvas not laid out yet (0x0) can't be drawn from.\n if (c.width && c.height) copy.getContext(\"2d\")?.drawImage(c, 0, 0);\n return copy;\n }),\n };\n}\n\nfunction restore(holder: HTMLElement | null, frame: Frame) {\n if (!holder) return;\n holder.replaceChildren(...frame.nodes.map((n) => n.cloneNode(true)));\n holder.querySelectorAll(\"canvas\").forEach((c, i) => {\n const px = frame.pixels[i];\n if (!px?.width || !px.height) return;\n c.width = px.width;\n c.height = px.height;\n c.getContext(\"2d\")?.drawImage(px, 0, 0);\n });\n}\n\nfunction HoldReady() {\n useDesignReady(false);\n return null;\n}\n\ninterface LastGoodFrameProps {\n children: ReactNode;\n frame: { current: Frame | null };\n resetKey: unknown;\n onError?: (error: Error) => void;\n errorFallback: (error: Error) => ReactNode;\n}\n\n/** On a render error, shows the last good frame (or `errorFallback`) and holds readiness back. */\ninterface LastGoodFrameState {\n error: Error | null;\n resetKey: unknown;\n}\n\nclass LastGoodFrame extends Component<LastGoodFrameProps, LastGoodFrameState> {\n state: LastGoodFrameState = { error: null, resetKey: this.props.resetKey };\n static getDerivedStateFromError(error: Error) {\n return { error };\n }\n // A new resetKey retries: render the children again.\n static getDerivedStateFromProps(\n props: LastGoodFrameProps,\n state: LastGoodFrameState,\n ): Partial<LastGoodFrameState> | null {\n return props.resetKey === state.resetKey\n ? null\n : { error: null, resetKey: props.resetKey };\n }\n componentDidCatch(error: Error) {\n this.props.onError?.(error);\n }\n render() {\n const { error } = this.state;\n if (!error) return this.props.children;\n const frame = this.props.frame.current;\n return (\n <>\n <HoldReady />\n {frame ? (\n <div\n data-design-last-good=\"\"\n style={{ display: \"contents\" }}\n ref={(el) => restore(el, frame)}\n />\n ) : (\n <div data-design-error=\"\" style={{ display: \"contents\" }}>\n {this.props.errorFallback(error)}\n </div>\n )}\n </>\n );\n }\n}\n\nconst defaultErrorFallback = (error: Error) => (\n <pre className=\"text-destructive p-4 whitespace-pre-wrap\">\n Design page failed to render: {error.message}\n </pre>\n);\n\nexport interface DesignPageProps {\n children: ReactNode;\n /** Called with each render error the page hits. */\n onError?: (error: Error) => void;\n /** Changing it retries rendering after an error (e.g. after a hot update). */\n resetKey?: unknown;\n /** Shown for an error before anything rendered. Defaults to the message. */\n errorFallback?: (error: Error) => ReactNode;\n}\n\n/**\n * The shell the `design()` plugin renders every `/design` page in: the app's\n * theme from the first paint, and the last good frame instead of a broken one.\n */\nexport function DesignPage({\n children,\n onError,\n resetKey,\n errorFallback = defaultErrorFallback,\n}: DesignPageProps) {\n useDesignTheme();\n const root = useRef<HTMLDivElement>(null);\n const frame = useRef<Frame | null>(null);\n // Hot updates re-render the page without this component: copy every frame.\n useLayoutEffect(() => {\n const el = root.current;\n if (!el) return;\n // Only what the page rendered, not an error or a restored copy.\n const keep = () => {\n if (!el.querySelector(\"[data-design-last-good], [data-design-error]\")) {\n frame.current = capture(el);\n }\n };\n // The first frame is already in place: no mutation reports it.\n if (el.childNodes.length > 0) keep();\n let pending = false;\n const observer = new MutationObserver(() => {\n if (pending) return;\n pending = true;\n requestAnimationFrame(() => {\n pending = false;\n keep();\n });\n });\n observer.observe(el, {\n subtree: true,\n childList: true,\n characterData: true,\n attributes: true,\n });\n return () => observer.disconnect();\n }, []);\n return (\n <div\n ref={root}\n data-design-page=\"\"\n className=\"bg-background text-foreground min-h-screen\"\n >\n <LastGoodFrame\n frame={frame}\n resetKey={resetKey}\n onError={onError}\n errorFallback={errorFallback}\n >\n {children}\n </LastGoodFrame>\n </div>\n );\n}\n\nexport type DraftPlaceholderKind = \"chart\" | \"table\" | \"card\" | \"generic\";\n\n/** Skeleton the `design()` plugin shows for a component a streaming draft hasn't defined yet. */\nexport function DraftPlaceholder({\n kind = \"generic\",\n}: {\n kind?: DraftPlaceholderKind;\n}) {\n if (kind === \"chart\") {\n return (\n <div\n data-draft-placeholder=\"chart\"\n className=\"flex h-56 items-end gap-2 p-4\"\n >\n {[40, 65, 50, 80, 60, 90, 70].map((h) => (\n <Skeleton key={h} className=\"flex-1\" style={{ height: `${h}%` }} />\n ))}\n </div>\n );\n }\n if (kind === \"table\") {\n return (\n <div data-draft-placeholder=\"table\" className=\"space-y-2 p-4\">\n <Skeleton className=\"h-6 w-full\" />\n {[0, 1, 2, 3].map((r) => (\n <Skeleton key={r} className=\"h-4 w-full opacity-70\" />\n ))}\n </div>\n );\n }\n if (kind === \"card\") {\n return (\n <div\n data-draft-placeholder=\"card\"\n className=\"space-y-3 rounded-xl border p-4\"\n >\n <Skeleton className=\"h-4 w-1/3\" />\n <Skeleton className=\"h-8 w-1/2\" />\n <Skeleton className=\"h-3 w-2/3\" />\n </div>\n );\n }\n return (\n <div data-draft-placeholder=\"generic\" className=\"space-y-2 p-2\">\n <Skeleton className=\"h-4 w-3/4\" />\n <Skeleton className=\"h-4 w-1/2\" />\n </div>\n );\n}\n"],"mappings":"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"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
//#region src/react/hooks/use-design-ready.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Holds back a page's readiness (`/design/__status`, `appkit:design-ready`,
|
|
4
|
+
* `appkit:app-ready`) while `ready` is `false`, for content the page can't
|
|
5
|
+
* detect on its own. Does nothing without the `design()` plugin's dev scripts.
|
|
6
|
+
*
|
|
7
|
+
* @example
|
|
8
|
+
* ```tsx
|
|
9
|
+
* function TripsChart() {
|
|
10
|
+
* const { data, loading } = useAnalyticsQuery("trips_per_day", {});
|
|
11
|
+
* useDesignReady(!loading && data != null);
|
|
12
|
+
* return <LineChart data={data ?? []} />;
|
|
13
|
+
* }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare function useDesignReady(ready?: boolean): void;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { useDesignReady };
|
|
19
|
+
//# sourceMappingURL=use-design-ready.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-design-ready.d.ts","names":[],"sources":["../../../src/react/hooks/use-design-ready.ts"],"mappings":";;AAsBA;;;;;;;;;;;;;iBAAgB,cAAA,CAAe,KAAA"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { useLayoutEffect } from "react";
|
|
2
|
+
|
|
3
|
+
//#region src/react/hooks/use-design-ready.ts
|
|
4
|
+
/**
|
|
5
|
+
* Holds back a page's readiness (`/design/__status`, `appkit:design-ready`,
|
|
6
|
+
* `appkit:app-ready`) while `ready` is `false`, for content the page can't
|
|
7
|
+
* detect on its own. Does nothing without the `design()` plugin's dev scripts.
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
* ```tsx
|
|
11
|
+
* function TripsChart() {
|
|
12
|
+
* const { data, loading } = useAnalyticsQuery("trips_per_day", {});
|
|
13
|
+
* useDesignReady(!loading && data != null);
|
|
14
|
+
* return <LineChart data={data ?? []} />;
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
function useDesignReady(ready = true) {
|
|
19
|
+
useLayoutEffect(() => {
|
|
20
|
+
if (ready) return;
|
|
21
|
+
const host = window.__appkitDesign;
|
|
22
|
+
if (!host) return;
|
|
23
|
+
host.blockers++;
|
|
24
|
+
return () => {
|
|
25
|
+
host.blockers--;
|
|
26
|
+
host.changed?.();
|
|
27
|
+
};
|
|
28
|
+
}, [ready]);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
//#endregion
|
|
32
|
+
export { useDesignReady };
|
|
33
|
+
//# sourceMappingURL=use-design-ready.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-design-ready.js","names":[],"sources":["../../../src/react/hooks/use-design-ready.ts"],"sourcesContent":["import { useLayoutEffect } from \"react\";\n\n/** CONTRACT: same key and shape as `window.__appkitDesign` in the design plugin's vite-plugin.ts. */\ninterface DesignHost {\n blockers: number;\n changed?: () => void;\n}\n\n/**\n * Holds back a page's readiness (`/design/__status`, `appkit:design-ready`,\n * `appkit:app-ready`) while `ready` is `false`, for content the page can't\n * detect on its own. Does nothing without the `design()` plugin's dev scripts.\n *\n * @example\n * ```tsx\n * function TripsChart() {\n * const { data, loading } = useAnalyticsQuery(\"trips_per_day\", {});\n * useDesignReady(!loading && data != null);\n * return <LineChart data={data ?? []} />;\n * }\n * ```\n */\nexport function useDesignReady(ready = true): void {\n useLayoutEffect(() => {\n if (ready) return;\n const host = (window as { __appkitDesign?: DesignHost }).__appkitDesign;\n if (!host) return;\n host.blockers++;\n return () => {\n host.blockers--;\n host.changed?.();\n };\n }, [ready]);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAsBA,SAAgB,eAAe,QAAQ,MAAY;AACjD,uBAAsB;AACpB,MAAI,MAAO;EACX,MAAM,OAAQ,OAA2C;AACzD,MAAI,CAAC,KAAM;AACX,OAAK;AACL,eAAa;AACX,QAAK;AACL,QAAK,WAAW;;IAEjB,CAAC,MAAM,CAAC"}
|