@sqlrooms/vega 0.29.0-rc.1 → 0.29.0-rc.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.
Files changed (43) hide show
  1. package/dist/VegaChartActions.js +1 -1
  2. package/dist/VegaChartActions.js.map +1 -1
  3. package/dist/VegaChartTool.d.ts +47 -26
  4. package/dist/VegaChartTool.d.ts.map +1 -1
  5. package/dist/VegaChartTool.js +61 -35
  6. package/dist/VegaChartTool.js.map +1 -1
  7. package/dist/VegaChartToolResult.d.ts +8 -20
  8. package/dist/VegaChartToolResult.d.ts.map +1 -1
  9. package/dist/VegaChartToolResult.js +8 -34
  10. package/dist/VegaChartToolResult.js.map +1 -1
  11. package/dist/VegaEditAction.d.ts +4 -9
  12. package/dist/VegaEditAction.d.ts.map +1 -1
  13. package/dist/VegaEditAction.js +9 -12
  14. package/dist/VegaEditAction.js.map +1 -1
  15. package/dist/VegaLiteArrowChart.d.ts.map +1 -1
  16. package/dist/VegaLiteArrowChart.js +1 -0
  17. package/dist/VegaLiteArrowChart.js.map +1 -1
  18. package/dist/VegaLiteChart.d.ts +44 -0
  19. package/dist/VegaLiteChart.d.ts.map +1 -0
  20. package/dist/VegaLiteChart.js +134 -0
  21. package/dist/VegaLiteChart.js.map +1 -0
  22. package/dist/VegaLiteSqlChart.js +1 -1
  23. package/dist/VegaLiteSqlChart.js.map +1 -1
  24. package/dist/editor/VegaCodeMirrorEditor.d.ts +15 -0
  25. package/dist/editor/VegaCodeMirrorEditor.d.ts.map +1 -0
  26. package/dist/editor/VegaCodeMirrorEditor.js +23 -0
  27. package/dist/editor/VegaCodeMirrorEditor.js.map +1 -0
  28. package/dist/editor/VegaMonacoEditor.d.ts +5 -0
  29. package/dist/editor/VegaMonacoEditor.d.ts.map +1 -1
  30. package/dist/editor/VegaMonacoEditor.js +2 -0
  31. package/dist/editor/VegaMonacoEditor.js.map +1 -1
  32. package/dist/editor/VegaSpecEditorPanel.d.ts.map +1 -1
  33. package/dist/editor/VegaSpecEditorPanel.js +11 -7
  34. package/dist/editor/VegaSpecEditorPanel.js.map +1 -1
  35. package/dist/editor/VegaSqlEditorPanel.d.ts +1 -1
  36. package/dist/editor/VegaSqlEditorPanel.d.ts.map +1 -1
  37. package/dist/editor/VegaSqlEditorPanel.js +9 -10
  38. package/dist/editor/VegaSqlEditorPanel.js.map +1 -1
  39. package/dist/index.d.ts +5 -2
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.js +3 -1
  42. package/dist/index.js.map +1 -1
  43. package/package.json +11 -10
@@ -1 +1 @@
1
- {"version":3,"file":"VegaLiteArrowChart.d.ts","sourceRoot":"","sources":["../src/VegaLiteArrowChart.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAC,YAAY,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAS3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;IACjC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;IACpC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,OAAO,CAAC,EAAE,YAAY,GACrB,YAAY,CAcd;AAsHD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;CAEH,CAAC"}
1
+ {"version":3,"file":"VegaLiteArrowChart.d.ts","sourceRoot":"","sources":["../src/VegaLiteArrowChart.tsx"],"names":[],"mappings":"AASA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAGtC,OAAO,EAAC,YAAY,EAAE,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAS3D,MAAM,MAAM,uBAAuB,GAAG;IACpC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;IACjC,OAAO,CAAC,EAAE,YAAY,CAAC;IACvB,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;IACpC;;;;;;;;;;;;OAYG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;CAC5B,CAAC;AAEF,wBAAgB,0BAA0B,CACxC,OAAO,CAAC,EAAE,YAAY,GACrB,YAAY,CAed;AAsHD;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,kBAAkB;IAC7B;;OAEG;;IAEH;;OAEG;;IAEH;;OAEG;;CAEH,CAAC"}
@@ -14,6 +14,7 @@ import { VegaExportAction } from './VegaExportAction';
14
14
  export function makeDefaultVegaLiteOptions(options) {
15
15
  return {
16
16
  mode: 'vega-lite',
17
+ renderer: 'svg',
17
18
  theme: undefined,
18
19
  tooltip: true,
19
20
  actions: false,
@@ -1 +1 @@
1
- {"version":3,"file":"VegaLiteArrowChart.js","sourceRoot":"","sources":["../src/VegaLiteArrowChart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAC,MAAM,kBAAkB,CAAC;AAClD,OAAO,EACL,WAAW,EACX,EAAE,EACF,wBAAwB,EACxB,QAAQ,GACT,MAAM,cAAc,CAAC;AACtB,O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WAAW,IACV,KAAK,EAAE,WAAW,EAClB,SAAS,EAAC,kBAAkB,EAC5B,OAAO,kBAEP,cAAK,GAAG,EAAE,GAAG,EAAE,SAAS,EAAC,0BAA0B,GAAG,GAC1C,CACf,CACF,GACG,EACL,QAAQ,IACL,GACmB,CAC5B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE;IACtE;;OAEG;IACH,OAAO,EAAE,gBAAgB;IACzB;;OAEG;IACH,YAAY,EAAE,gBAAgB;IAC9B;;OAEG;IACH,UAAU,EAAE,cAAc;CAC3B,CAAC,CAAC","sourcesContent":["import {ToolErrorMessage} from '@sqlrooms/ai';\nimport {arrowTableToJson} from '@sqlrooms/duckdb';\nimport {\n AspectRatio,\n cn,\n useAspectRatioDimensions,\n useTheme,\n} from '@sqlrooms/ui';\nimport {safeJsonParse} from '@sqlrooms/utils';\nimport * as arrow from 'apache-arrow';\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react';\nimport {useVegaEmbed} from 'react-vega';\nimport {EmbedOptions, VisualizationSpec} from 'vega-embed';\nimport {Config} from 'vega-lite';\nimport {darkTheme} from './themes/darkTheme';\nimport {lightTheme} from './themes/lightTheme';\nimport {VegaChartActions} from './VegaChartActions';\nimport {VegaChartContextProvider} from './VegaChartContext';\nimport {VegaEditAction} from './VegaEditAction';\nimport {VegaExportAction} from './VegaExportAction';\n\nexport type VegaLiteArrowChartProps = {\n className?: string;\n width?: number | 'auto';\n height?: number | 'auto';\n aspectRatio?: number;\n spec: string | VisualizationSpec;\n options?: EmbedOptions;\n arrowTable: arrow.Table | undefined;\n /**\n * Children for composing actions and other elements.\n * Use VegaLiteArrowChart.Actions to add action buttons.\n *\n * @example\n * ```tsx\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction />\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n * ```\n */\n children?: React.ReactNode;\n};\n\nexport function makeDefaultVegaLiteOptions(\n options?: EmbedOptions,\n): EmbedOptions {\n return {\n mode: 'vega-lite',\n theme: undefined,\n tooltip: true,\n actions: false,\n padding: {\n top: 20,\n right: 10,\n bottom: 10,\n left: 10,\n },\n ...options,\n };\n}\n\nconst VegaLiteArrowChartBase: React.FC<VegaLiteArrowChartProps> = ({\n className,\n aspectRatio = 16 / 9,\n spec,\n arrowTable,\n options: propsOptions,\n width = 'auto',\n height = 'auto',\n children,\n}) => {\n const {theme} = useTheme();\n\n const options = useMemo(\n () =>\n makeDefaultVegaLiteOptions({\n config: {\n ...(theme === 'dark' ? darkTheme : lightTheme),\n ...(typeof propsOptions?.config === 'object'\n ? (propsOptions.config as Config)\n : {}),\n },\n\n ...propsOptions,\n }),\n [theme, propsOptions],\n );\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [chartError, setChartError] = useState<Error | null>(null);\n\n const data = useMemo(() => {\n if (!arrowTable) return null;\n return {values: arrowTableToJson(arrowTable)};\n }, [arrowTable]);\n\n const specWithData = useMemo(() => {\n const parsed = typeof spec === 'string' ? safeJsonParse(spec) : spec;\n if (!parsed) {\n setChartError(new Error('Invalid Vega-Lite specification'));\n return null;\n }\n return {\n padding: 10,\n background: 'transparent',\n ...parsed,\n data: data,\n // Override the following props to ensure the chart is responsive\n width: 'container',\n height: 'container',\n autosize: {contains: 'padding'},\n } as VisualizationSpec;\n }, [spec, data]);\n\n // Reset chart error whenever spec or data changes\n useEffect(() => {\n setChartError(null);\n }, [spec, data]);\n\n const ref = useRef<HTMLDivElement>(null);\n const embed = useVegaEmbed({\n ref,\n spec: specWithData ?? '',\n onError: () => setChartError,\n options,\n });\n\n const dimensions = useAspectRatioDimensions({\n containerRef,\n width,\n height,\n aspectRatio,\n });\n const changeDimensions = useCallback(\n (width: number, height: number) => {\n embed?.view.width(width).height(height).runAsync();\n },\n [embed],\n );\n useEffect(() => {\n changeDimensions(dimensions.width, dimensions.height);\n }, [changeDimensions, dimensions.width, dimensions.height]);\n\n return (\n <VegaChartContextProvider value={{embed}}>\n <div\n ref={containerRef}\n className={cn('relative flex h-full w-full flex-col gap-2', className)}\n >\n <div className=\"peer relative\">\n {chartError ? (\n <ToolErrorMessage\n error={chartError}\n triggerLabel=\"Chart rendering failed\"\n title=\"Chart error\"\n align=\"start\"\n details={spec}\n />\n ) : (\n specWithData &&\n data && (\n <AspectRatio\n ratio={aspectRatio}\n className=\"overflow-visible\"\n asChild\n >\n <div ref={ref} className=\"[&_svg]:overflow-visible\" />\n </AspectRatio>\n )\n )}\n </div>\n {children}\n </div>\n </VegaChartContextProvider>\n );\n};\n\n/**\n * Composable Vega-Lite chart component with support for custom actions.\n *\n * @example\n * ```tsx\n * // Basic usage without actions (backwards compatible)\n * <VegaLiteArrowChart spec={spec} arrowTable={data} />\n *\n * // With export action\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction />\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n *\n * // Custom actions with separator\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction pngScale={3} />\n * <Separator orientation=\"vertical\" className=\"h-4\" />\n * <Button size=\"xs\" variant=\"ghost\" onClick={handleRefresh}>\n * <RefreshCw className=\"h-4 w-4\" />\n * </Button>\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n * ```\n */\nexport const VegaLiteArrowChart = Object.assign(VegaLiteArrowChartBase, {\n /**\n * Container for action buttons, positioned as an overlay\n */\n Actions: VegaChartActions,\n /**\n * Built-in export action with PNG/SVG download\n */\n ExportAction: VegaExportAction,\n /**\n * Built-in edit action with spec/SQL editor popover\n */\n EditAction: VegaEditAction,\n});\n"]}
1
+ {"version":3,"file":"VegaLiteArrowChart.js","sourceRoot":"","sources":["../src/VegaLi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eAAe,YAC3B,UAAU,CAAC,CAAC,CAAC,CACZ,KAAC,gBAAgB,IACf,KAAK,EAAE,UAAU,EACjB,YAAY,EAAC,wBAAwB,EACrC,KAAK,EAAC,aAAa,EACnB,KAAK,EAAC,OAAO,EACb,OAAO,EAAE,IAAI,GACb,CACH,CAAC,CAAC,CAAC,CACF,YAAY;wBACZ,IAAI,IAAI,CACN,KAAC,WAAW,IACV,KAAK,EAAE,WAAW,EAClB,SAAS,EAAC,kBAAkB,EAC5B,OAAO,kBAEP,cAAK,GAAG,EAAE,GAAG,EAAE,SAAS,EAAC,0BAA0B,GAAG,GAC1C,CACf,CACF,GACG,EACL,QAAQ,IACL,GACmB,CAC5B,CAAC;AACJ,CAAC,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE;IACtE;;OAEG;IACH,OAAO,EAAE,gBAAgB;IACzB;;OAEG;IACH,YAAY,EAAE,gBAAgB;IAC9B;;OAEG;IACH,UAAU,EAAE,cAAc;CAC3B,CAAC,CAAC","sourcesContent":["import {ToolErrorMessage} from '@sqlrooms/ai';\nimport {arrowTableToJson} from '@sqlrooms/duckdb';\nimport {\n AspectRatio,\n cn,\n useAspectRatioDimensions,\n useTheme,\n} from '@sqlrooms/ui';\nimport {safeJsonParse} from '@sqlrooms/utils';\nimport * as arrow from 'apache-arrow';\nimport {useCallback, useEffect, useMemo, useRef, useState} from 'react';\nimport {useVegaEmbed} from 'react-vega';\nimport {EmbedOptions, VisualizationSpec} from 'vega-embed';\nimport {Config} from 'vega-lite';\nimport {darkTheme} from './themes/darkTheme';\nimport {lightTheme} from './themes/lightTheme';\nimport {VegaChartActions} from './VegaChartActions';\nimport {VegaChartContextProvider} from './VegaChartContext';\nimport {VegaEditAction} from './VegaEditAction';\nimport {VegaExportAction} from './VegaExportAction';\n\nexport type VegaLiteArrowChartProps = {\n className?: string;\n width?: number | 'auto';\n height?: number | 'auto';\n aspectRatio?: number;\n spec: string | VisualizationSpec;\n options?: EmbedOptions;\n arrowTable: arrow.Table | undefined;\n /**\n * Children for composing actions and other elements.\n * Use VegaLiteArrowChart.Actions to add action buttons.\n *\n * @example\n * ```tsx\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction />\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n * ```\n */\n children?: React.ReactNode;\n};\n\nexport function makeDefaultVegaLiteOptions(\n options?: EmbedOptions,\n): EmbedOptions {\n return {\n mode: 'vega-lite',\n renderer: 'svg',\n theme: undefined,\n tooltip: true,\n actions: false,\n padding: {\n top: 20,\n right: 10,\n bottom: 10,\n left: 10,\n },\n ...options,\n };\n}\n\nconst VegaLiteArrowChartBase: React.FC<VegaLiteArrowChartProps> = ({\n className,\n aspectRatio = 16 / 9,\n spec,\n arrowTable,\n options: propsOptions,\n width = 'auto',\n height = 'auto',\n children,\n}) => {\n const {theme} = useTheme();\n\n const options = useMemo(\n () =>\n makeDefaultVegaLiteOptions({\n config: {\n ...(theme === 'dark' ? darkTheme : lightTheme),\n ...(typeof propsOptions?.config === 'object'\n ? (propsOptions.config as Config)\n : {}),\n },\n\n ...propsOptions,\n }),\n [theme, propsOptions],\n );\n\n const containerRef = useRef<HTMLDivElement>(null);\n const [chartError, setChartError] = useState<Error | null>(null);\n\n const data = useMemo(() => {\n if (!arrowTable) return null;\n return {values: arrowTableToJson(arrowTable)};\n }, [arrowTable]);\n\n const specWithData = useMemo(() => {\n const parsed = typeof spec === 'string' ? safeJsonParse(spec) : spec;\n if (!parsed) {\n setChartError(new Error('Invalid Vega-Lite specification'));\n return null;\n }\n return {\n padding: 10,\n background: 'transparent',\n ...parsed,\n data: data,\n // Override the following props to ensure the chart is responsive\n width: 'container',\n height: 'container',\n autosize: {contains: 'padding'},\n } as VisualizationSpec;\n }, [spec, data]);\n\n // Reset chart error whenever spec or data changes\n useEffect(() => {\n setChartError(null);\n }, [spec, data]);\n\n const ref = useRef<HTMLDivElement>(null);\n const embed = useVegaEmbed({\n ref,\n spec: specWithData ?? '',\n onError: () => setChartError,\n options,\n });\n\n const dimensions = useAspectRatioDimensions({\n containerRef,\n width,\n height,\n aspectRatio,\n });\n const changeDimensions = useCallback(\n (width: number, height: number) => {\n embed?.view.width(width).height(height).runAsync();\n },\n [embed],\n );\n useEffect(() => {\n changeDimensions(dimensions.width, dimensions.height);\n }, [changeDimensions, dimensions.width, dimensions.height]);\n\n return (\n <VegaChartContextProvider value={{embed}}>\n <div\n ref={containerRef}\n className={cn('relative flex h-full w-full flex-col gap-2', className)}\n >\n <div className=\"peer relative\">\n {chartError ? (\n <ToolErrorMessage\n error={chartError}\n triggerLabel=\"Chart rendering failed\"\n title=\"Chart error\"\n align=\"start\"\n details={spec}\n />\n ) : (\n specWithData &&\n data && (\n <AspectRatio\n ratio={aspectRatio}\n className=\"overflow-visible\"\n asChild\n >\n <div ref={ref} className=\"[&_svg]:overflow-visible\" />\n </AspectRatio>\n )\n )}\n </div>\n {children}\n </div>\n </VegaChartContextProvider>\n );\n};\n\n/**\n * Composable Vega-Lite chart component with support for custom actions.\n *\n * @example\n * ```tsx\n * // Basic usage without actions (backwards compatible)\n * <VegaLiteArrowChart spec={spec} arrowTable={data} />\n *\n * // With export action\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction />\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n *\n * // Custom actions with separator\n * <VegaLiteArrowChart spec={spec} arrowTable={data}>\n * <VegaLiteArrowChart.Actions>\n * <VegaExportAction pngScale={3} />\n * <Separator orientation=\"vertical\" className=\"h-4\" />\n * <Button size=\"xs\" variant=\"ghost\" onClick={handleRefresh}>\n * <RefreshCw className=\"h-4 w-4\" />\n * </Button>\n * </VegaLiteArrowChart.Actions>\n * </VegaLiteArrowChart>\n * ```\n */\nexport const VegaLiteArrowChart = Object.assign(VegaLiteArrowChartBase, {\n /**\n * Container for action buttons, positioned as an overlay\n */\n Actions: VegaChartActions,\n /**\n * Built-in export action with PNG/SVG download\n */\n ExportAction: VegaExportAction,\n /**\n * Built-in edit action with spec/SQL editor popover\n */\n EditAction: VegaEditAction,\n});\n"]}
@@ -0,0 +1,44 @@
1
+ import * as arrow from 'apache-arrow';
2
+ import { VisualizationSpec } from 'react-vega';
3
+ export declare const ArrowChart: React.FC<{
4
+ className?: string;
5
+ width?: number | 'auto';
6
+ height?: number | 'auto';
7
+ aspectRatio?: number;
8
+ spec: string | VisualizationSpec;
9
+ arrowTable: arrow.Table | undefined;
10
+ dataName?: string;
11
+ }>;
12
+ export declare const VegaLiteChart: import("react").FC<{
13
+ className?: string;
14
+ width?: number | "auto";
15
+ height?: number | "auto";
16
+ aspectRatio?: number;
17
+ sqlQuery: string;
18
+ spec: string | VisualizationSpec;
19
+ dataName?: string;
20
+ lastRunTime?: number;
21
+ isLoading?: boolean;
22
+ }> & {
23
+ SqlChart: import("react").FC<{
24
+ className?: string;
25
+ width?: number | "auto";
26
+ height?: number | "auto";
27
+ aspectRatio?: number;
28
+ sqlQuery: string;
29
+ spec: string | VisualizationSpec;
30
+ dataName?: string;
31
+ lastRunTime?: number;
32
+ isLoading?: boolean;
33
+ }>;
34
+ ArrowChart: import("react").FC<{
35
+ className?: string;
36
+ width?: number | "auto";
37
+ height?: number | "auto";
38
+ aspectRatio?: number;
39
+ spec: string | VisualizationSpec;
40
+ arrowTable: arrow.Table | undefined;
41
+ dataName?: string;
42
+ }>;
43
+ };
44
+ //# sourceMappingURL=VegaLiteChart.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VegaLiteChart.d.ts","sourceRoot":"","sources":["../src/VegaLiteChart.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,KAAK,MAAM,cAAc,CAAC;AAEtC,OAAO,EAAW,iBAAiB,EAAC,MAAM,YAAY,CAAC;AAmIvD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC;IAChC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,KAAK,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC;IACzB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,IAAI,EAAE,MAAM,GAAG,iBAAiB,CAAC;IACjC,UAAU,EAAE,KAAK,CAAC,KAAK,GAAG,SAAS,CAAC;IACpC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB,CAwEA,CAAC;AAEF,eAAO,MAAM,aAAa;gBA9JZ,MAAM;YACV,MAAM,GAAG,MAAM;aACd,MAAM,GAAG,MAAM;kBACV,MAAM;cACV,MAAM;UACV,MAAM,GAAG,iBAAiB;eACrB,MAAM;kBACH,MAAM;gBACR,OAAO;;;oBARP,MAAM;gBACV,MAAM,GAAG,MAAM;iBACd,MAAM,GAAG,MAAM;sBACV,MAAM;kBACV,MAAM;cACV,MAAM,GAAG,iBAAiB;mBACrB,MAAM;sBACH,MAAM;oBACR,OAAO;;;oBAqEP,MAAM;gBACV,MAAM,GAAG,MAAM;iBACd,MAAM,GAAG,MAAM;sBACV,MAAM;cACd,MAAM,GAAG,iBAAiB;oBACpB,KAAK,CAAC,KAAK,GAAG,SAAS;mBACxB,MAAM;;CA8EjB,CAAC"}
@@ -0,0 +1,134 @@
1
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { ToolErrorMessage } from '@sqlrooms/ai';
3
+ import { arrowTableToJson, useSql } from '@sqlrooms/duckdb';
4
+ import { AspectRatio, cn, useAspectRatioDimensions } from '@sqlrooms/ui';
5
+ import { safeJsonParse } from '@sqlrooms/utils';
6
+ import { useEffect, useMemo, useRef, useState } from 'react';
7
+ import { VegaLite } from 'react-vega';
8
+ const DEFAULT_DATA_NAME = 'queryResult';
9
+ /**
10
+ * A component that renders a Vega-Lite chart with SQL data and responsive sizing.
11
+ *
12
+ * The chart can be sized in multiple ways:
13
+ * - Fixed dimensions: Provide both width and height as numbers
14
+ * - Fixed width, proportional height: Provide width as number, height as 'auto'
15
+ * - Fixed height, proportional width: Provide height as number, width as 'auto'
16
+ * - Fully responsive: Leave both as 'auto' (default), chart will fill container while maintaining aspect ratio
17
+ *
18
+ * @param props - The component props
19
+ * @param {number | 'auto'} [props.width='auto'] - The chart width in pixels, or 'auto' to use container width
20
+ * @param {number | 'auto'} [props.height='auto'] - The chart height in pixels, or 'auto' to calculate from aspect ratio
21
+ * @param {number} [props.aspectRatio=3/2] - The desired width-to-height ratio when dimensions are auto-calculated
22
+ * @param {string} props.sqlQuery - The SQL query to fetch data for the chart
23
+ * @param {string | VisualizationSpec} props.spec - The Vega-Lite specification for the chart.
24
+ * Can be either a JSON string or a VisualizationSpec object.
25
+ * The data and size properties will be overridden by the component.
26
+ *
27
+ * @returns The rendered chart component
28
+ *
29
+ * @example
30
+ * // Fixed size chart
31
+ * <VegaLiteChart
32
+ * width={600}
33
+ * height={400}
34
+ * sqlQuery="SELECT category, count(*) as count FROM sales GROUP BY category"
35
+ * spec={{
36
+ * mark: 'bar',
37
+ * encoding: {
38
+ * x: {field: 'category', type: 'nominal'},
39
+ * y: {field: 'count', type: 'quantitative'}
40
+ * }
41
+ * }}
42
+ * />
43
+ *
44
+ * @example
45
+ * // Responsive chart with 16:9 aspect ratio
46
+ * <VegaLiteChart
47
+ * className="max-w-[600px]"
48
+ * aspectRatio={16/9}
49
+ * sqlQuery="SELECT date, value FROM metrics"
50
+ * spec={{
51
+ * mark: 'line',
52
+ * encoding: {
53
+ * x: {field: 'date', type: 'temporal'},
54
+ * y: {field: 'value', type: 'quantitative'}
55
+ * }
56
+ * }}
57
+ * />
58
+ */
59
+ const VegaLiteSqlChart = ({ className, width = 'auto', height = 'auto', aspectRatio, sqlQuery, spec, dataName = DEFAULT_DATA_NAME, lastRunTime, isLoading, }) => {
60
+ const containerRef = useRef(null);
61
+ const dimensions = useAspectRatioDimensions({
62
+ containerRef,
63
+ width,
64
+ height,
65
+ aspectRatio,
66
+ });
67
+ const { width: adjustedWidth, height: adjustedHeight } = dimensions;
68
+ const refinedSpec = useMemo(() => {
69
+ const parsed = typeof spec === 'string' ? safeJsonParse(spec) : spec;
70
+ if (!parsed)
71
+ return null;
72
+ return {
73
+ ...parsed,
74
+ data: { name: dataName },
75
+ width: adjustedWidth,
76
+ height: adjustedHeight,
77
+ autosize: {
78
+ type: 'fit',
79
+ contains: 'padding',
80
+ },
81
+ };
82
+ }, [spec, dataName, adjustedWidth, adjustedHeight]);
83
+ const result = useSql({ query: sqlQuery, version: lastRunTime });
84
+ const arrowTable = result.data?.arrowTable;
85
+ const data = useMemo(() => {
86
+ if (!arrowTable)
87
+ return null;
88
+ return { queryResult: arrowTableToJson(arrowTable) };
89
+ }, [arrowTable]);
90
+ return (_jsx("div", { ref: containerRef, className: cn('flex h-full w-full flex-col gap-2 overflow-hidden', className), children: isLoading || result.isLoading ? (_jsxs("div", { className: "text-muted-foreground flex items-center justify-center gap-2 p-2", children: [_jsx("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600" }), "Running query for chart data\u2026"] })) : refinedSpec && data ? (_jsx(AspectRatio, { ratio: aspectRatio, children: _jsx(VegaLite, { spec: refinedSpec, data: data }) })) : result.error ? (_jsx("div", { className: "whitespace-pre-wrap p-2 font-mono text-sm text-red-500", children: result.error.message })) : null }));
91
+ };
92
+ export const ArrowChart = ({ className, width = 'auto', height = 'auto', aspectRatio = 3 / 2, spec, arrowTable, dataName = DEFAULT_DATA_NAME, }) => {
93
+ const containerRef = useRef(null);
94
+ const [chartError, setChartError] = useState(null);
95
+ const dimensions = useAspectRatioDimensions({
96
+ containerRef,
97
+ width,
98
+ height,
99
+ aspectRatio,
100
+ });
101
+ const refinedSpec = useMemo(() => {
102
+ const parsed = typeof spec === 'string' ? safeJsonParse(spec) : spec;
103
+ if (!parsed) {
104
+ setChartError(new Error('Invalid Vega-Lite specification'));
105
+ return null;
106
+ }
107
+ return {
108
+ ...parsed,
109
+ data: { name: dataName },
110
+ width: dimensions.width,
111
+ height: dimensions.height,
112
+ autosize: {
113
+ type: 'fit',
114
+ contains: 'padding',
115
+ },
116
+ };
117
+ }, [spec, dataName, dimensions]);
118
+ const data = useMemo(() => {
119
+ if (!arrowTable)
120
+ return null;
121
+ return { queryResult: arrowTableToJson(arrowTable) };
122
+ }, [arrowTable]);
123
+ // Reset chart error whenever spec or data changes
124
+ useEffect(() => {
125
+ setChartError(null);
126
+ }, [spec, data]);
127
+ return (_jsx("div", { ref: containerRef, className: cn('flex h-full w-full flex-col gap-2 overflow-hidden', className), children: chartError ? (_jsx(ToolErrorMessage, { error: chartError, triggerLabel: "Chart rendering failed", title: "Chart error", align: "start", details: spec })) : (refinedSpec &&
128
+ data && (_jsx(AspectRatio, { ratio: aspectRatio, children: _jsx(VegaLite, { spec: refinedSpec, data: data, onError: setChartError }) }))) }));
129
+ };
130
+ export const VegaLiteChart = Object.assign(VegaLiteSqlChart, {
131
+ SqlChart: VegaLiteSqlChart,
132
+ ArrowChart: ArrowChart,
133
+ });
134
+ //# sourceMappingURL=VegaLiteChart.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VegaLiteChart.js","sourceRoot":"","sources":["../src/VegaLiteChart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,gBAAgB,EAAC,MAAM,cAAc,CAAC;AAC9C,OAAO,EAAC,gBAAgB,EAAE,MAAM,EAAC,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAC,WAAW,EAAE,EAAE,EAAE,wBAAwB,EAAC,MAAM,cAAc,CAAC;AACvE,OAAO,EAAC,aAAa,EAAC,MAAM,iBAAiB,CAAC;AAE9C,OAAO,EAAC,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAC,QAAQ,EAAoB,MAAM,YAAY,CAAC;AAEvD,MAAM,i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b,OAAO,EAAE,IAAI,GACb,CACH,CAAC,CAAC,CAAC,CACF,WAAW;YACX,IAAI,IAAI,CACN,KAAC,WAAW,IAAC,KAAK,EAAE,WAAW,YAC7B,KAAC,QAAQ,IAAC,IAAI,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,aAAa,GAAI,GACvD,CACf,CACF,GACG,CACP,CAAC;AACJ,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,aAAa,GAAG,MAAM,CAAC,MAAM,CAAC,gBAAgB,EAAE;IAC3D,QAAQ,EAAE,gBAAgB;IAC1B,UAAU,EAAE,UAAU;CACvB,CAAC,CAAC","sourcesContent":["import {ToolErrorMessage} from '@sqlrooms/ai';\nimport {arrowTableToJson, useSql} from '@sqlrooms/duckdb';\nimport {AspectRatio, cn, useAspectRatioDimensions} from '@sqlrooms/ui';\nimport {safeJsonParse} from '@sqlrooms/utils';\nimport * as arrow from 'apache-arrow';\nimport {useEffect, useMemo, useRef, useState} from 'react';\nimport {VegaLite, VisualizationSpec} from 'react-vega';\n\nconst DEFAULT_DATA_NAME = 'queryResult';\n\n/**\n * A component that renders a Vega-Lite chart with SQL data and responsive sizing.\n *\n * The chart can be sized in multiple ways:\n * - Fixed dimensions: Provide both width and height as numbers\n * - Fixed width, proportional height: Provide width as number, height as 'auto'\n * - Fixed height, proportional width: Provide height as number, width as 'auto'\n * - Fully responsive: Leave both as 'auto' (default), chart will fill container while maintaining aspect ratio\n *\n * @param props - The component props\n * @param {number | 'auto'} [props.width='auto'] - The chart width in pixels, or 'auto' to use container width\n * @param {number | 'auto'} [props.height='auto'] - The chart height in pixels, or 'auto' to calculate from aspect ratio\n * @param {number} [props.aspectRatio=3/2] - The desired width-to-height ratio when dimensions are auto-calculated\n * @param {string} props.sqlQuery - The SQL query to fetch data for the chart\n * @param {string | VisualizationSpec} props.spec - The Vega-Lite specification for the chart.\n * Can be either a JSON string or a VisualizationSpec object.\n * The data and size properties will be overridden by the component.\n *\n * @returns The rendered chart component\n *\n * @example\n * // Fixed size chart\n * <VegaLiteChart\n * width={600}\n * height={400}\n * sqlQuery=\"SELECT category, count(*) as count FROM sales GROUP BY category\"\n * spec={{\n * mark: 'bar',\n * encoding: {\n * x: {field: 'category', type: 'nominal'},\n * y: {field: 'count', type: 'quantitative'}\n * }\n * }}\n * />\n *\n * @example\n * // Responsive chart with 16:9 aspect ratio\n * <VegaLiteChart\n * className=\"max-w-[600px]\"\n * aspectRatio={16/9}\n * sqlQuery=\"SELECT date, value FROM metrics\"\n * spec={{\n * mark: 'line',\n * encoding: {\n * x: {field: 'date', type: 'temporal'},\n * y: {field: 'value', type: 'quantitative'}\n * }\n * }}\n * />\n */\nconst VegaLiteSqlChart: React.FC<{\n className?: string;\n width?: number | 'auto';\n height?: number | 'auto';\n aspectRatio?: number;\n sqlQuery: string;\n spec: string | VisualizationSpec;\n dataName?: string;\n lastRunTime?: number;\n isLoading?: boolean;\n}> = ({\n className,\n width = 'auto',\n height = 'auto',\n aspectRatio,\n sqlQuery,\n spec,\n dataName = DEFAULT_DATA_NAME,\n lastRunTime,\n isLoading,\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const dimensions = useAspectRatioDimensions({\n containerRef,\n width,\n height,\n aspectRatio,\n });\n const {width: adjustedWidth, height: adjustedHeight} = dimensions;\n const refinedSpec = useMemo(() => {\n const parsed = typeof spec === 'string' ? safeJsonParse(spec) : spec;\n if (!parsed) return null;\n return {\n ...parsed,\n data: {name: dataName},\n width: adjustedWidth,\n height: adjustedHeight,\n autosize: {\n type: 'fit',\n contains: 'padding',\n },\n } as VisualizationSpec;\n }, [spec, dataName, adjustedWidth, adjustedHeight]);\n\n const result = useSql({query: sqlQuery, version: lastRunTime});\n const arrowTable = result.data?.arrowTable;\n const data = useMemo(() => {\n if (!arrowTable) return null;\n return {queryResult: arrowTableToJson(arrowTable)};\n }, [arrowTable]);\n\n return (\n <div\n ref={containerRef}\n className={cn(\n 'flex h-full w-full flex-col gap-2 overflow-hidden',\n className,\n )}\n >\n {isLoading || result.isLoading ? (\n <div className=\"text-muted-foreground flex items-center justify-center gap-2 p-2\">\n <div className=\"h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600\"></div>\n Running query for chart data…\n </div>\n ) : refinedSpec && data ? (\n <AspectRatio ratio={aspectRatio}>\n <VegaLite spec={refinedSpec} data={data} />\n </AspectRatio>\n ) : result.error ? (\n <div className=\"whitespace-pre-wrap p-2 font-mono text-sm text-red-500\">\n {result.error.message}\n </div>\n ) : null}\n </div>\n );\n};\n\nexport const ArrowChart: React.FC<{\n className?: string;\n width?: number | 'auto';\n height?: number | 'auto';\n aspectRatio?: number;\n spec: string | VisualizationSpec;\n arrowTable: arrow.Table | undefined;\n dataName?: string;\n}> = ({\n className,\n width = 'auto',\n height = 'auto',\n aspectRatio = 3 / 2,\n spec,\n arrowTable,\n dataName = DEFAULT_DATA_NAME,\n}) => {\n const containerRef = useRef<HTMLDivElement>(null);\n const [chartError, setChartError] = useState<Error | null>(null);\n const dimensions = useAspectRatioDimensions({\n containerRef,\n width,\n height,\n aspectRatio,\n });\n\n const refinedSpec = useMemo(() => {\n const parsed = typeof spec === 'string' ? safeJsonParse(spec) : spec;\n if (!parsed) {\n setChartError(new Error('Invalid Vega-Lite specification'));\n return null;\n }\n return {\n ...parsed,\n data: {name: dataName},\n width: dimensions.width,\n height: dimensions.height,\n autosize: {\n type: 'fit',\n contains: 'padding',\n },\n } as VisualizationSpec;\n }, [spec, dataName, dimensions]);\n\n const data = useMemo(() => {\n if (!arrowTable) return null;\n return {queryResult: arrowTableToJson(arrowTable)};\n }, [arrowTable]);\n\n // Reset chart error whenever spec or data changes\n useEffect(() => {\n setChartError(null);\n }, [spec, data]);\n\n return (\n <div\n ref={containerRef}\n className={cn(\n 'flex h-full w-full flex-col gap-2 overflow-hidden',\n className,\n )}\n >\n {chartError ? (\n <ToolErrorMessage\n error={chartError}\n triggerLabel=\"Chart rendering failed\"\n title=\"Chart error\"\n align=\"start\"\n details={spec}\n />\n ) : (\n refinedSpec &&\n data && (\n <AspectRatio ratio={aspectRatio}>\n <VegaLite spec={refinedSpec} data={data} onError={setChartError} />\n </AspectRatio>\n )\n )}\n </div>\n );\n};\n\nexport const VegaLiteChart = Object.assign(VegaLiteSqlChart, {\n SqlChart: VegaLiteSqlChart,\n ArrowChart: ArrowChart,\n});\n"]}
@@ -55,6 +55,6 @@ import { VegaLiteArrowChart, } from './VegaLiteArrowChart';
55
55
  export const VegaLiteSqlChart = ({ className, sqlQuery, ...props }) => {
56
56
  const result = useSql({ query: sqlQuery });
57
57
  const arrowTable = result.data?.arrowTable;
58
- return (_jsxs("div", { className: cn('flex h-full w-full flex-col gap-2 overflow-hidden', className), children: [result.error && (_jsx("div", { className: "whitespace-pre-wrap font-mono text-sm text-red-500", children: result.error.message })), result.isLoading ? (_jsxs("div", { className: "text-muted-foreground align-center flex gap-2 px-2", children: [_jsx("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600" }), "Running query for chart data\u2026"] })) : (arrowTable && _jsx(VegaLiteArrowChart, { ...props, arrowTable: arrowTable }))] }));
58
+ return (_jsxs("div", { className: cn('flex h-full w-full flex-col gap-2 overflow-hidden', className), children: [result.error && (_jsx("div", { className: "font-mono text-sm whitespace-pre-wrap text-red-500", children: result.error.message })), result.isLoading ? (_jsxs("div", { className: "text-muted-foreground align-center flex gap-2 px-2", children: [_jsx("div", { className: "h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600" }), "Running query for chart data\u2026"] })) : (arrowTable && _jsx(VegaLiteArrowChart, { ...props, arrowTable: arrowTable }))] }));
59
59
  };
60
60
  //# sourceMappingURL=VegaLiteSqlChart.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"VegaLiteSqlChart.js","sourceRoot":"","sources":["../src/VegaLiteSqlChart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAChC,OAAO,EACL,kBAAkB,GAEnB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAEzB,CAAC,EAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAC,EAAE,EAAE;IACtC,MAAM,MAAM,GAAG,MAAM,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAC,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC;IAE3C,OAAO,CACL,eACE,SAAS,EAAE,EAAE,CACX,mDAAmD,EACnD,SAAS,CACV,aAEA,MAAM,CAAC,KAAK,IAAI,CACf,cAAK,SAAS,EAAC,oDAAoD,YAChE,MAAM,CAAC,KAAK,CAAC,OAAO,GACjB,CACP,EACA,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAClB,eAAK,SAAS,EAAC,oDAAoD,aACjE,cAAK,SAAS,EAAC,8EAA8E,GAAO,0CAEhG,CACP,CAAC,CAAC,CAAC,CACF,UAAU,IAAI,KAAC,kBAAkB,OAAK,KAAK,EAAE,UAAU,EAAE,UAAU,GAAI,CACxE,IACG,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {useSql} from '@sqlrooms/duckdb';\nimport {cn} from '@sqlrooms/ui';\nimport {\n VegaLiteArrowChart,\n VegaLiteArrowChartProps,\n} from './VegaLiteArrowChart';\n\n/**\n * A component that renders a Vega-Lite chart with SQL data and responsive sizing.\n *\n * The chart can be sized in multiple ways:\n * - Fixed dimensions: Provide both width and height as numbers\n * - Fixed width, proportional height: Provide width as number, height as 'auto'\n * - Fixed height, proportional width: Provide height as number, width as 'auto'\n * - Fully responsive: Leave both as 'auto' (default), chart will fill container while maintaining aspect ratio\n *\n * @param props - The component props\n * @param {number | 'auto'} [props.width='auto'] - The chart width in pixels, or 'auto' to use container width\n * @param {number | 'auto'} [props.height='auto'] - The chart height in pixels, or 'auto' to calculate from aspect ratio\n * @param {number} [props.aspectRatio=3/2] - The desired width-to-height ratio when dimensions are auto-calculated\n * @param {string} props.sqlQuery - The SQL query to fetch data for the chart\n * @param {string | VisualizationSpec} props.spec - The Vega-Lite specification for the chart.\n * Can be either a JSON string or a VisualizationSpec object.\n * The data and size properties will be overridden by the component.\n *\n * @returns The rendered chart component\n *\n * @example\n * // Fixed size chart\n * <VegaLiteChart\n * width={600}\n * height={400}\n * sqlQuery=\"SELECT category, count(*) as count FROM sales GROUP BY category\"\n * spec={{\n * mark: 'bar',\n * encoding: {\n * x: {field: 'category', type: 'nominal'},\n * y: {field: 'count', type: 'quantitative'}\n * }\n * }}\n * />\n *\n * @example\n * // Responsive chart with 16:9 aspect ratio\n * <VegaLiteChart\n * className=\"max-w-[600px]\"\n * aspectRatio={16/9}\n * sqlQuery=\"SELECT date, value FROM metrics\"\n * spec={{\n * mark: 'line',\n * encoding: {\n * x: {field: 'date', type: 'temporal'},\n * y: {field: 'value', type: 'quantitative'}\n * }\n * }}\n * />\n */\nexport const VegaLiteSqlChart: React.FC<\n Omit<VegaLiteArrowChartProps, 'arrowTable'> & {sqlQuery: string}\n> = ({className, sqlQuery, ...props}) => {\n const result = useSql({query: sqlQuery});\n const arrowTable = result.data?.arrowTable;\n\n return (\n <div\n className={cn(\n 'flex h-full w-full flex-col gap-2 overflow-hidden',\n className,\n )}\n >\n {result.error && (\n <div className=\"whitespace-pre-wrap font-mono text-sm text-red-500\">\n {result.error.message}\n </div>\n )}\n {result.isLoading ? (\n <div className=\"text-muted-foreground align-center flex gap-2 px-2\">\n <div className=\"h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600\"></div>\n Running query for chart data…\n </div>\n ) : (\n arrowTable && <VegaLiteArrowChart {...props} arrowTable={arrowTable} />\n )}\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"VegaLiteSqlChart.js","sourceRoot":"","sources":["../src/VegaLiteSqlChart.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,kBAAkB,CAAC;AACxC,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAChC,OAAO,EACL,kBAAkB,GAEnB,MAAM,sBAAsB,CAAC;AAE9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiDG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAEzB,CAAC,EAAC,SAAS,EAAE,QAAQ,EAAE,GAAG,KAAK,EAAC,EAAE,EAAE;IACtC,MAAM,MAAM,GAAG,MAAM,CAAC,EAAC,KAAK,EAAE,QAAQ,EAAC,CAAC,CAAC;IACzC,MAAM,UAAU,GAAG,MAAM,CAAC,IAAI,EAAE,UAAU,CAAC;IAE3C,OAAO,CACL,eACE,SAAS,EAAE,EAAE,CACX,mDAAmD,EACnD,SAAS,CACV,aAEA,MAAM,CAAC,KAAK,IAAI,CACf,cAAK,SAAS,EAAC,oDAAoD,YAChE,MAAM,CAAC,KAAK,CAAC,OAAO,GACjB,CACP,EACA,MAAM,CAAC,SAAS,CAAC,CAAC,CAAC,CAClB,eAAK,SAAS,EAAC,oDAAoD,aACjE,cAAK,SAAS,EAAC,8EAA8E,GAAO,0CAEhG,CACP,CAAC,CAAC,CAAC,CACF,UAAU,IAAI,KAAC,kBAAkB,OAAK,KAAK,EAAE,UAAU,EAAE,UAAU,GAAI,CACxE,IACG,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {useSql} from '@sqlrooms/duckdb';\nimport {cn} from '@sqlrooms/ui';\nimport {\n VegaLiteArrowChart,\n VegaLiteArrowChartProps,\n} from './VegaLiteArrowChart';\n\n/**\n * A component that renders a Vega-Lite chart with SQL data and responsive sizing.\n *\n * The chart can be sized in multiple ways:\n * - Fixed dimensions: Provide both width and height as numbers\n * - Fixed width, proportional height: Provide width as number, height as 'auto'\n * - Fixed height, proportional width: Provide height as number, width as 'auto'\n * - Fully responsive: Leave both as 'auto' (default), chart will fill container while maintaining aspect ratio\n *\n * @param props - The component props\n * @param {number | 'auto'} [props.width='auto'] - The chart width in pixels, or 'auto' to use container width\n * @param {number | 'auto'} [props.height='auto'] - The chart height in pixels, or 'auto' to calculate from aspect ratio\n * @param {number} [props.aspectRatio=3/2] - The desired width-to-height ratio when dimensions are auto-calculated\n * @param {string} props.sqlQuery - The SQL query to fetch data for the chart\n * @param {string | VisualizationSpec} props.spec - The Vega-Lite specification for the chart.\n * Can be either a JSON string or a VisualizationSpec object.\n * The data and size properties will be overridden by the component.\n *\n * @returns The rendered chart component\n *\n * @example\n * // Fixed size chart\n * <VegaLiteChart\n * width={600}\n * height={400}\n * sqlQuery=\"SELECT category, count(*) as count FROM sales GROUP BY category\"\n * spec={{\n * mark: 'bar',\n * encoding: {\n * x: {field: 'category', type: 'nominal'},\n * y: {field: 'count', type: 'quantitative'}\n * }\n * }}\n * />\n *\n * @example\n * // Responsive chart with 16:9 aspect ratio\n * <VegaLiteChart\n * className=\"max-w-[600px]\"\n * aspectRatio={16/9}\n * sqlQuery=\"SELECT date, value FROM metrics\"\n * spec={{\n * mark: 'line',\n * encoding: {\n * x: {field: 'date', type: 'temporal'},\n * y: {field: 'value', type: 'quantitative'}\n * }\n * }}\n * />\n */\nexport const VegaLiteSqlChart: React.FC<\n Omit<VegaLiteArrowChartProps, 'arrowTable'> & {sqlQuery: string}\n> = ({className, sqlQuery, ...props}) => {\n const result = useSql({query: sqlQuery});\n const arrowTable = result.data?.arrowTable;\n\n return (\n <div\n className={cn(\n 'flex h-full w-full flex-col gap-2 overflow-hidden',\n className,\n )}\n >\n {result.error && (\n <div className=\"font-mono text-sm whitespace-pre-wrap text-red-500\">\n {result.error.message}\n </div>\n )}\n {result.isLoading ? (\n <div className=\"text-muted-foreground align-center flex gap-2 px-2\">\n <div className=\"h-4 w-4 animate-spin rounded-full border-2 border-gray-300 border-t-blue-600\"></div>\n Running query for chart data…\n </div>\n ) : (\n arrowTable && <VegaLiteArrowChart {...props} arrowTable={arrowTable} />\n )}\n </div>\n );\n};\n"]}
@@ -0,0 +1,15 @@
1
+ import { JsonCodeMirrorEditorProps } from '@sqlrooms/codemirror';
2
+ import React from 'react';
3
+ export interface VegaCodeMirrorEditorProps extends Omit<JsonCodeMirrorEditorProps, 'schema'> {
4
+ /**
5
+ * Whether to enable Vega-Lite JSON schema validation
6
+ * @default true
7
+ */
8
+ enableSchemaValidation?: boolean;
9
+ }
10
+ /**
11
+ * A CodeMirror editor specialized for editing Vega-Lite specifications.
12
+ * Automatically loads and configures the Vega-Lite JSON schema for validation.
13
+ */
14
+ export declare const VegaCodeMirrorEditor: React.FC<VegaCodeMirrorEditorProps>;
15
+ //# sourceMappingURL=VegaCodeMirrorEditor.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VegaCodeMirrorEditor.d.ts","sourceRoot":"","sources":["../../src/editor/VegaCodeMirrorEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,yBAAyB,EAC1B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAA4B,MAAM,OAAO,CAAC;AAGjD,MAAM,WAAW,yBAA0B,SAAQ,IAAI,CACrD,yBAAyB,EACzB,QAAQ,CACT;IACC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;GAGG;AACH,eAAO,MAAM,oBAAoB,EAAE,KAAK,CAAC,EAAE,CAAC,yBAAyB,CA+BpE,CAAC"}
@@ -0,0 +1,23 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { JsonCodeMirrorEditor, } from '@sqlrooms/codemirror';
3
+ import { useEffect, useState } from 'react';
4
+ import { loadVegaLiteSchema } from '../schema/vegaLiteSchema';
5
+ /**
6
+ * A CodeMirror editor specialized for editing Vega-Lite specifications.
7
+ * Automatically loads and configures the Vega-Lite JSON schema for validation.
8
+ */
9
+ export const VegaCodeMirrorEditor = ({ value, onChange, readOnly = false, className, enableSchemaValidation = true, ...props }) => {
10
+ const [schema, setSchema] = useState(null);
11
+ // Load Vega-Lite schema on mount
12
+ useEffect(() => {
13
+ if (enableSchemaValidation) {
14
+ loadVegaLiteSchema().then((loadedSchema) => {
15
+ if (loadedSchema) {
16
+ setSchema(loadedSchema);
17
+ }
18
+ });
19
+ }
20
+ }, [enableSchemaValidation]);
21
+ return (_jsx(JsonCodeMirrorEditor, { value: value, onChange: onChange, schema: enableSchemaValidation ? (schema ?? undefined) : undefined, readOnly: readOnly, className: className, ...props }));
22
+ };
23
+ //# sourceMappingURL=VegaCodeMirrorEditor.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"VegaCodeMirrorEditor.js","sourceRoot":"","sources":["../../src/editor/VegaCodeMirrorEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,oBAAoB,GAErB,MAAM,sBAAsB,CAAC;AAC9B,OAAc,EAAC,SAAS,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AACjD,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAa5D;;;GAGG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAwC,CAAC,EACxE,KAAK,EACL,QAAQ,EACR,QAAQ,GAAG,KAAK,EAChB,SAAS,EACT,sBAAsB,GAAG,IAAI,EAC7B,GAAG,KAAK,EACT,EAAE,EAAE;IACH,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,QAAQ,CAAgB,IAAI,CAAC,CAAC;IAE1D,iCAAiC;IACjC,SAAS,CAAC,GAAG,EAAE;QACb,IAAI,sBAAsB,EAAE,CAAC;YAC3B,kBAAkB,EAAE,CAAC,IAAI,CAAC,CAAC,YAAY,EAAE,EAAE;gBACzC,IAAI,YAAY,EAAE,CAAC;oBACjB,SAAS,CAAC,YAAY,CAAC,CAAC;gBAC1B,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC;IACH,CAAC,EAAE,CAAC,sBAAsB,CAAC,CAAC,CAAC;IAE7B,OAAO,CACL,KAAC,oBAAoB,IACnB,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,QAAQ,EAClB,MAAM,EAAE,sBAAsB,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,SAAS,CAAC,CAAC,CAAC,CAAC,SAAS,EAClE,QAAQ,EAAE,QAAQ,EAClB,SAAS,EAAE,SAAS,KAChB,KAAK,GACT,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n JsonCodeMirrorEditor,\n JsonCodeMirrorEditorProps,\n} from '@sqlrooms/codemirror';\nimport React, {useEffect, useState} from 'react';\nimport {loadVegaLiteSchema} from '../schema/vegaLiteSchema';\n\nexport interface VegaCodeMirrorEditorProps extends Omit<\n JsonCodeMirrorEditorProps,\n 'schema'\n> {\n /**\n * Whether to enable Vega-Lite JSON schema validation\n * @default true\n */\n enableSchemaValidation?: boolean;\n}\n\n/**\n * A CodeMirror editor specialized for editing Vega-Lite specifications.\n * Automatically loads and configures the Vega-Lite JSON schema for validation.\n */\nexport const VegaCodeMirrorEditor: React.FC<VegaCodeMirrorEditorProps> = ({\n value,\n onChange,\n readOnly = false,\n className,\n enableSchemaValidation = true,\n ...props\n}) => {\n const [schema, setSchema] = useState<object | null>(null);\n\n // Load Vega-Lite schema on mount\n useEffect(() => {\n if (enableSchemaValidation) {\n loadVegaLiteSchema().then((loadedSchema) => {\n if (loadedSchema) {\n setSchema(loadedSchema);\n }\n });\n }\n }, [enableSchemaValidation]);\n\n return (\n <JsonCodeMirrorEditor\n value={value}\n onChange={onChange}\n schema={enableSchemaValidation ? (schema ?? undefined) : undefined}\n readOnly={readOnly}\n className={className}\n {...props}\n />\n );\n};\n"]}
@@ -1,5 +1,8 @@
1
1
  import { MonacoEditorProps } from '@sqlrooms/monaco-editor';
2
2
  import React from 'react';
3
+ /**
4
+ * @deprecated Use VegaCodeMirrorEditorProps instead. This interface is kept for backward compatibility.
5
+ */
3
6
  export interface VegaMonacoEditorProps extends Omit<MonacoEditorProps, 'language'> {
4
7
  /**
5
8
  * Whether to enable Vega-Lite JSON schema validation
@@ -10,6 +13,8 @@ export interface VegaMonacoEditorProps extends Omit<MonacoEditorProps, 'language
10
13
  /**
11
14
  * A Monaco editor specialized for editing Vega-Lite specifications.
12
15
  * Automatically loads and configures the Vega-Lite JSON schema for validation.
16
+ *
17
+ * @deprecated Use VegaCodeMirrorEditor instead. This component is kept for backward compatibility.
13
18
  */
14
19
  export declare const VegaMonacoEditor: React.FC<VegaMonacoEditorProps>;
15
20
  //# sourceMappingURL=VegaMonacoEditor.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"VegaMonacoEditor.d.ts","sourceRoot":"","sources":["../../src/editor/VegaMonacoEditor.tsx"],"names":[],"mappings":"AACA,OAAO,EAAe,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAA0B,MAAM,OAAO,CAAC;AAG/C,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CACjD,iBAAiB,EACjB,UAAU,CACX;IACC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;GAGG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAuE5D,CAAC"}
1
+ {"version":3,"file":"VegaMonacoEditor.d.ts","sourceRoot":"","sources":["../../src/editor/VegaMonacoEditor.tsx"],"names":[],"mappings":"AACA,OAAO,EAAe,iBAAiB,EAAC,MAAM,yBAAyB,CAAC;AACxE,OAAO,KAA0B,MAAM,OAAO,CAAC;AAG/C;;GAEG;AACH,MAAM,WAAW,qBAAsB,SAAQ,IAAI,CACjD,iBAAiB,EACjB,UAAU,CACX;IACC;;;OAGG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAC;CAClC;AAED;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,EAAE,KAAK,CAAC,EAAE,CAAC,qBAAqB,CAuE5D,CAAC"}
@@ -5,6 +5,8 @@ import { loadVegaLiteSchema } from '../schema/vegaLiteSchema';
5
5
  /**
6
6
  * A Monaco editor specialized for editing Vega-Lite specifications.
7
7
  * Automatically loads and configures the Vega-Lite JSON schema for validation.
8
+ *
9
+ * @deprecated Use VegaCodeMirrorEditor instead. This component is kept for backward compatibility.
8
10
  */
9
11
  export const VegaMonacoEditor = ({ value, onChange, readOnly = false, className, enableSchemaValidation = true, onMount, options, ...props }) => {
10
12
  const monacoRef = useRef(null);
@@ -1 +1 @@
1
- {"version":3,"file":"VegaMonacoEditor.js","sourceRoot":"","sources":["../../src/editor/VegaMonacoEditor.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,YAAY,EAAoB,MAAM,yBAAyB,CAAC;AACxE,OAAc,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAa5D;;;GAGG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAoC,CAAC,EAChE,KAAK,EACL,QAAQ,EACR,QAAQ,GAAG,KAAK,EAChB,SAAS,EACT,sBAAsB,GAAG,IAAI,EAC7B,OAAO,EACP,OAAO,EACP,GAAG,KAAK,EACT,EAAE,EAAE;IACH,MAAM,SAAS,GAAG,MAAM,CAAM,IAAI,CAAC,CAAC;IACpC,MAAM,mBAAmB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE1C,4BAA4B;IAC5B,SAAS,CAAC,GAAG,EAAE;QACb,IACE,sBAAsB;YACtB,SAAS,CAAC,OAAO;YACjB,CAAC,mBAAmB,CAAC,OAAO,EAC5B,CAAC;YACD,kBAAkB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBACnC,IAAI,SAAS,CAAC,OAAO,IAAI,MAAM,EAAE,CAAC;oBAChC,mBAAmB,CAAC,SAAS,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;oBAC/C,mBAAmB,CAAC,OAAO,GAAG,IAAI,CAAC;gBACrC,CAAC;YACH,CAA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B,CAAC;QACvD,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE;YACP;gBACE,GAAG,EAAE,iDAAiD;gBACtD,SAAS,EAAE,CAAC,GAAG,CAAC;gBAChB,MAAM,EAAE,MAAiC;aAC1C;SACF;QACD,mBAAmB,EAAE,KAAK;KAC3B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {OnMount} from '@monaco-editor/react';\nimport {MonacoEditor, MonacoEditorProps} from '@sqlrooms/monaco-editor';\nimport React, {useEffect, useRef} from 'react';\nimport {loadVegaLiteSchema} from '../schema/vegaLiteSchema';\n\nexport interface VegaMonacoEditorProps extends Omit<\n MonacoEditorProps,\n 'language'\n> {\n /**\n * Whether to enable Vega-Lite JSON schema validation\n * @default true\n */\n enableSchemaValidation?: boolean;\n}\n\n/**\n * A Monaco editor specialized for editing Vega-Lite specifications.\n * Automatically loads and configures the Vega-Lite JSON schema for validation.\n */\nexport const VegaMonacoEditor: React.FC<VegaMonacoEditorProps> = ({\n value,\n onChange,\n readOnly = false,\n className,\n enableSchemaValidation = true,\n onMount,\n options,\n ...props\n}) => {\n const monacoRef = useRef<any>(null);\n const schemaConfiguredRef = useRef(false);\n\n // Load and configure schema\n useEffect(() => {\n if (\n enableSchemaValidation &&\n monacoRef.current &&\n !schemaConfiguredRef.current\n ) {\n loadVegaLiteSchema().then((schema) => {\n if (monacoRef.current && schema) {\n configureJsonSchema(monacoRef.current, schema);\n schemaConfiguredRef.current = true;\n }\n });\n }\n }, [enableSchemaValidation]);\n\n const handleEditorDidMount: OnMount = (editor, monaco) => {\n monacoRef.current = monaco;\n\n // Configure JSON schema validation if enabled\n if (enableSchemaValidation) {\n loadVegaLiteSchema().then((schema) => {\n if (schema) {\n configureJsonSchema(monaco, schema);\n schemaConfiguredRef.current = true;\n }\n });\n }\n\n // Format on initial load\n setTimeout(() => {\n editor.getAction('editor.action.formatDocument')?.run();\n }, 100);\n\n // Call the original onMount if provided\n onMount?.(editor, monaco);\n };\n\n return (\n <MonacoEditor\n language=\"json\"\n value={value}\n onChange={onChange}\n onMount={handleEditorDidMount}\n className={className}\n readOnly={readOnly}\n options={{\n formatOnPaste: true,\n formatOnType: true,\n folding: true,\n foldingStrategy: 'indentation',\n lineNumbers: 'off',\n fixedOverflowWidgets: false,\n ...options,\n }}\n {...props}\n />\n );\n};\n\n/**\n * Configure Monaco JSON schema validation for Vega-Lite\n */\nfunction configureJsonSchema(monaco: any, schema: object) {\n monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n validate: true,\n schemas: [\n {\n uri: 'https://vega.github.io/schema/vega-lite/v5.json',\n fileMatch: ['*'],\n schema: schema as Record<string, unknown>,\n },\n ],\n enableSchemaRequest: false,\n });\n}\n"]}
1
+ {"version":3,"file":"VegaMonacoEditor.js","sourceRoot":"","sources":["../../src/editor/VegaMonacoEditor.tsx"],"names":[],"mappings":";AACA,OAAO,EAAC,YAAY,EAAoB,MAAM,yBAAyB,CAAC;AACxE,OAAc,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC/C,OAAO,EAAC,kBAAkB,EAAC,MAAM,0BAA0B,CAAC;AAgB5D;;;;;GAKG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAoC,CAAC,EAChE,KAAK,EACL,QAAQ,EACR,QAAQ,GAAG,KAAK,EAChB,SAAS,EACT,sBAAsB,GAAG,IAAI,EAC7B,OAAO,EACP,OAAO,EACP,GAAG,KAAK,EACT,EAAE,EAAE;IACH,MAAM,SAAS,GAAG,MAAM,CAAM,IAAI,CAAC,CAAC;IACpC,MAAM,mBAAmB,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;IAE1C,4BAA4B;IAC5B,SAAS,CAAC,GAAG,EAAE;QACb,IACE,sBAAsB;YACtB,SAAS,CAAC,OAAO;YACjB,CAAC,mBAAmB,CAAC,OAAO,EAC5B,CAAC;YACD,kBAAkB,EAAE,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,EAAE;gBACnC,IAAI,SAAS,CAAC,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,KACG,KAAK,GACT,CACH,CAAC;AACJ,CAAC,CAAC;AAEF;;GAEG;AACH,SAAS,mBAAmB,CAAC,MAAW,EAAE,MAAc;IACtD,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC,YAAY,CAAC,qBAAqB,CAAC;QACvD,QAAQ,EAAE,IAAI;QACd,OAAO,EAAE;YACP;gBACE,GAAG,EAAE,iDAAiD;gBACtD,SAAS,EAAE,CAAC,GAAG,CAAC;gBAChB,MAAM,EAAE,MAAiC;aAC1C;SACF;QACD,mBAAmB,EAAE,KAAK;KAC3B,CAAC,CAAC;AACL,CAAC","sourcesContent":["import type {OnMount} from '@monaco-editor/react';\nimport {MonacoEditor, MonacoEditorProps} from '@sqlrooms/monaco-editor';\nimport React, {useEffect, useRef} from 'react';\nimport {loadVegaLiteSchema} from '../schema/vegaLiteSchema';\n\n/**\n * @deprecated Use VegaCodeMirrorEditorProps instead. This interface is kept for backward compatibility.\n */\nexport interface VegaMonacoEditorProps extends Omit<\n MonacoEditorProps,\n 'language'\n> {\n /**\n * Whether to enable Vega-Lite JSON schema validation\n * @default true\n */\n enableSchemaValidation?: boolean;\n}\n\n/**\n * A Monaco editor specialized for editing Vega-Lite specifications.\n * Automatically loads and configures the Vega-Lite JSON schema for validation.\n *\n * @deprecated Use VegaCodeMirrorEditor instead. This component is kept for backward compatibility.\n */\nexport const VegaMonacoEditor: React.FC<VegaMonacoEditorProps> = ({\n value,\n onChange,\n readOnly = false,\n className,\n enableSchemaValidation = true,\n onMount,\n options,\n ...props\n}) => {\n const monacoRef = useRef<any>(null);\n const schemaConfiguredRef = useRef(false);\n\n // Load and configure schema\n useEffect(() => {\n if (\n enableSchemaValidation &&\n monacoRef.current &&\n !schemaConfiguredRef.current\n ) {\n loadVegaLiteSchema().then((schema) => {\n if (monacoRef.current && schema) {\n configureJsonSchema(monacoRef.current, schema);\n schemaConfiguredRef.current = true;\n }\n });\n }\n }, [enableSchemaValidation]);\n\n const handleEditorDidMount: OnMount = (editor, monaco) => {\n monacoRef.current = monaco;\n\n // Configure JSON schema validation if enabled\n if (enableSchemaValidation) {\n loadVegaLiteSchema().then((schema) => {\n if (schema) {\n configureJsonSchema(monaco, schema);\n schemaConfiguredRef.current = true;\n }\n });\n }\n\n // Format on initial load\n setTimeout(() => {\n editor.getAction('editor.action.formatDocument')?.run();\n }, 100);\n\n // Call the original onMount if provided\n onMount?.(editor, monaco);\n };\n\n return (\n <MonacoEditor\n language=\"json\"\n value={value}\n onChange={onChange}\n onMount={handleEditorDidMount}\n className={className}\n readOnly={readOnly}\n options={{\n formatOnPaste: true,\n formatOnType: true,\n folding: true,\n foldingStrategy: 'indentation',\n lineNumbers: 'off',\n fixedOverflowWidgets: false,\n ...options,\n }}\n {...props}\n />\n );\n};\n\n/**\n * Configure Monaco JSON schema validation for Vega-Lite\n */\nfunction configureJsonSchema(monaco: any, schema: object) {\n monaco.languages.json.jsonDefaults.setDiagnosticsOptions({\n validate: true,\n schemas: [\n {\n uri: 'https://vega.github.io/schema/vega-lite/v5.json',\n fileMatch: ['*'],\n schema: schema as Record<string, unknown>,\n },\n ],\n enableSchemaRequest: false,\n });\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"VegaSpecEditorPanel.d.ts","sourceRoot":"","sources":["../../src/editor/VegaSpecEditorPanel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CA0ClE,CAAC"}
1
+ {"version":3,"file":"VegaSpecEditorPanel.d.ts","sourceRoot":"","sources":["../../src/editor/VegaSpecEditorPanel.tsx"],"names":[],"mappings":"AAEA,OAAO,KAAK,MAAM,OAAO,CAAC;AAI1B,MAAM,WAAW,wBAAwB;IACvC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,mBAAmB,EAAE,KAAK,CAAC,EAAE,CAAC,wBAAwB,CAuDlE,CAAC"}
@@ -1,8 +1,8 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { cn } from '@sqlrooms/ui';
2
+ import { cn, CopyButton } from '@sqlrooms/ui';
3
3
  import { AlertCircle } from 'lucide-react';
4
+ import { VegaCodeMirrorEditor } from './VegaCodeMirrorEditor';
4
5
  import { useVegaEditorContext } from './VegaEditorContext';
5
- import { VegaMonacoEditor } from './VegaMonacoEditor';
6
6
  /**
7
7
  * Spec editor panel subcomponent for VegaLiteChart.Container.
8
8
  * Renders a Monaco editor with Vega-Lite JSON schema validation.
@@ -20,10 +20,14 @@ import { VegaMonacoEditor } from './VegaMonacoEditor';
20
20
  export const VegaSpecEditorPanel = ({ className, title = 'Vega-Lite Spec', }) => {
21
21
  const { state, actions, editable } = useVegaEditorContext();
22
22
  const showHeader = title !== '';
23
- return (_jsxs("div", { className: cn('flex h-full flex-col', className), children: [showHeader && (_jsxs("div", { className: "flex items-center justify-between border-b px-3 py-2", children: [_jsx("span", { className: "text-sm font-medium", children: title }), state.isSpecDirty && (_jsx("span", { className: "text-muted-foreground text-xs", children: "Modified" }))] })), _jsx("div", { className: "relative flex-1", children: _jsx(VegaMonacoEditor, { className: "absolute inset-0 h-full w-full", value: state.editedSpecString, onChange: (value) => {
24
- if (value !== undefined) {
25
- actions.setEditedSpec(value);
26
- }
27
- }, readOnly: !editable }) }), state.specParseError && (_jsxs("div", { className: "bg-destructive/90 text-destructive-foreground flex items-center gap-2 px-3 py-2 backdrop-blur-sm", children: [_jsx(AlertCircle, { className: "h-4 w-4 shrink-0" }), _jsx("span", { className: "truncate text-xs", children: state.specParseError })] }))] }));
23
+ return (_jsxs("div", { className: cn('flex h-full flex-col', className), children: [showHeader && (_jsxs("div", { className: "flex items-center justify-between border-b px-3 py-2", children: [_jsx("span", { className: "text-sm font-medium", children: title }), state.isSpecDirty && (_jsx("span", { className: "text-muted-foreground text-xs", children: "Modified" }))] })), _jsxs("div", { className: "relative flex-1", children: [_jsx(VegaCodeMirrorEditor, { className: "absolute inset-0 h-full w-full", value: state.editedSpecString, onChange: (value) => {
24
+ if (value !== undefined) {
25
+ actions.setEditedSpec(value);
26
+ }
27
+ }, readOnly: !editable, options: {
28
+ lineNumbers: true,
29
+ lineWrapping: false,
30
+ foldGutter: true,
31
+ } }), _jsx("div", { className: "bg-background absolute top-2 right-2 rounded-md border", children: _jsx(CopyButton, { text: state.editedSpecString, size: "xs", tooltipLabel: "Copy spec", disabled: !state.editedSpecString.trim() }) })] }), state.specParseError && (_jsxs("div", { className: "bg-destructive/90 text-destructive-foreground flex items-center gap-2 px-3 py-2 backdrop-blur-sm", children: [_jsx(AlertCircle, { className: "h-4 w-4 shrink-0" }), _jsx("span", { className: "truncate text-xs", children: state.specParseError })] }))] }));
28
32
  };
29
33
  //# sourceMappingURL=VegaSpecEditorPanel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"VegaSpecEditorPanel.js","sourceRoot":"","sources":["../../src/editor/VegaSpecEditorPanel.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,EAAE,EAAC,MAAM,cAAc,CAAC;AAChC,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AACzD,OAAO,EAAC,gBAAgB,EAAC,MAAM,oBAAoB,CAAC;AAcpD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAuC,CAAC,EACtE,SAAS,EACT,KAAK,GAAG,gBAAgB,GACzB,EAAE,EAAE;IACH,MAAM,EAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAC,GAAG,oBAAoB,EAAE,CAAC;IAC1D,MAAM,UAAU,GAAG,KAAK,KAAK,EAAE,CAAC;IAEhC,OAAO,CACL,eAAK,SAAS,EAAE,EAAE,CAAC,sBAAsB,EAAE,SAAS,CAAC,aAElD,UAAU,IAAI,CACb,eAAK,SAAS,EAAC,sDAAsD,aACnE,eAAM,SAAS,EAAC,qBAAqB,YAAE,KAAK,GAAQ,EACnD,KAAK,CAAC,WAAW,IAAI,CACpB,eAAM,SAAS,EAAC,+BAA+B,yBAAgB,CAChE,IACG,CACP,EAGD,cAAK,SAAS,EAAC,iBAAiB,YAC9B,KAAC,gBAAgB,IACf,SAAS,EAAC,gCAAgC,EAC1C,KAAK,EAAE,KAAK,CAAC,gBAAgB,EAC7B,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;wBAClB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;4BACxB,OAAO,CAAC,aAAa,CAAC,KAAK,CAAC,CAAC;wBAC/B,CAAC;oBACH,CAAC,EACD,QAAQ,EAAE,CAAC,QAAQ,GACnB,GACE,EAGL,KAAK,CAAC,cAAc,IAAI,CACvB,eAAK,SAAS,EAAC,kGAAkG,aAC/G,KAAC,WAAW,IAAC,SAAS,EAAC,kBAAkB,GAAG,EAC5C,eAAM,SAAS,EAAC,kBAAkB,YAAE,KAAK,CAAC,cAAc,GAAQ,IAC5D,CACP,IACG,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {cn} from '@sqlrooms/ui';\nimport {AlertCircle} from 'lucide-react';\nimport React from 'react';\nimport {useVegaEditorContext} from './VegaEditorContext';\nimport {VegaMonacoEditor} from './VegaMonacoEditor';\n\nexport interface VegaSpecEditorPanelProps {\n /**\n * Custom class name for the panel\n */\n className?: string;\n /**\n * Title shown in the panel header\n * @default \"Vega-Lite Spec\"\n */\n title?: string;\n}\n\n/**\n * Spec editor panel subcomponent for VegaLiteChart.Container.\n * Renders a Monaco editor with Vega-Lite JSON schema validation.\n *\n * Must be used within a VegaLiteChart.Container component.\n *\n * @example\n * ```tsx\n * <VegaLiteChart.Container spec={spec}>\n * <VegaLiteChart.Chart />\n * <VegaLiteChart.SpecEditor />\n * </VegaLiteChart.Container>\n * ```\n */\nexport const VegaSpecEditorPanel: React.FC<VegaSpecEditorPanelProps> = ({\n className,\n title = 'Vega-Lite Spec',\n}) => {\n const {state, actions, editable} = useVegaEditorContext();\n const showHeader = title !== '';\n\n return (\n <div className={cn('flex h-full flex-col', className)}>\n {/* Header - only show if title is provided */}\n {showHeader && (\n <div className=\"flex items-center justify-between border-b px-3 py-2\">\n <span className=\"text-sm font-medium\">{title}</span>\n {state.isSpecDirty && (\n <span className=\"text-muted-foreground text-xs\">Modified</span>\n )}\n </div>\n )}\n\n {/* Editor */}\n <div className=\"relative flex-1\">\n <VegaMonacoEditor\n className=\"absolute inset-0 h-full w-full\"\n value={state.editedSpecString}\n onChange={(value) => {\n if (value !== undefined) {\n actions.setEditedSpec(value);\n }\n }}\n readOnly={!editable}\n />\n </div>\n\n {/* Spec parse error */}\n {state.specParseError && (\n <div className=\"bg-destructive/90 text-destructive-foreground flex items-center gap-2 px-3 py-2 backdrop-blur-sm\">\n <AlertCircle className=\"h-4 w-4 shrink-0\" />\n <span className=\"truncate text-xs\">{state.specParseError}</span>\n </div>\n )}\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"VegaSpecEditorPanel.js","sourceRoot":"","sources":["../../src/editor/VegaSpecEditorPanel.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,EAAE,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAC,WAAW,EAAC,MAAM,cAAc,CAAC;AAEzC,OAAO,EAAC,oBAAoB,EAAC,MAAM,wBAAwB,CAAC;AAC5D,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAczD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,mBAAmB,GAAuC,CAAC,EACtE,SAAS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AAC,cAAc,GAAQ,IAC5D,CACP,IACG,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {cn, CopyButton} from '@sqlrooms/ui';\nimport {AlertCircle} from 'lucide-react';\nimport React from 'react';\nimport {VegaCodeMirrorEditor} from './VegaCodeMirrorEditor';\nimport {useVegaEditorContext} from './VegaEditorContext';\n\nexport interface VegaSpecEditorPanelProps {\n /**\n * Custom class name for the panel\n */\n className?: string;\n /**\n * Title shown in the panel header\n * @default \"Vega-Lite Spec\"\n */\n title?: string;\n}\n\n/**\n * Spec editor panel subcomponent for VegaLiteChart.Container.\n * Renders a Monaco editor with Vega-Lite JSON schema validation.\n *\n * Must be used within a VegaLiteChart.Container component.\n *\n * @example\n * ```tsx\n * <VegaLiteChart.Container spec={spec}>\n * <VegaLiteChart.Chart />\n * <VegaLiteChart.SpecEditor />\n * </VegaLiteChart.Container>\n * ```\n */\nexport const VegaSpecEditorPanel: React.FC<VegaSpecEditorPanelProps> = ({\n className,\n title = 'Vega-Lite Spec',\n}) => {\n const {state, actions, editable} = useVegaEditorContext();\n const showHeader = title !== '';\n\n return (\n <div className={cn('flex h-full flex-col', className)}>\n {/* Header - only show if title is provided */}\n {showHeader && (\n <div className=\"flex items-center justify-between border-b px-3 py-2\">\n <span className=\"text-sm font-medium\">{title}</span>\n {state.isSpecDirty && (\n <span className=\"text-muted-foreground text-xs\">Modified</span>\n )}\n </div>\n )}\n\n {/* Editor */}\n <div className=\"relative flex-1\">\n <VegaCodeMirrorEditor\n className=\"absolute inset-0 h-full w-full\"\n value={state.editedSpecString}\n onChange={(value) => {\n if (value !== undefined) {\n actions.setEditedSpec(value);\n }\n }}\n readOnly={!editable}\n options={{\n lineNumbers: true,\n lineWrapping: false,\n foldGutter: true,\n }}\n />\n <div className=\"bg-background absolute top-2 right-2 rounded-md border\">\n <CopyButton\n text={state.editedSpecString}\n size=\"xs\"\n tooltipLabel=\"Copy spec\"\n disabled={!state.editedSpecString.trim()}\n />\n </div>\n </div>\n\n {/* Spec parse error */}\n {state.specParseError && (\n <div className=\"bg-destructive/90 text-destructive-foreground flex items-center gap-2 px-3 py-2 backdrop-blur-sm\">\n <AlertCircle className=\"h-4 w-4 shrink-0\" />\n <span className=\"truncate text-xs\">{state.specParseError}</span>\n </div>\n )}\n </div>\n );\n};\n"]}
@@ -17,7 +17,7 @@ export interface VegaSqlEditorPanelProps {
17
17
  }
18
18
  /**
19
19
  * SQL editor panel subcomponent for VegaLiteChart.Container.
20
- * Renders a Monaco editor with SQL syntax highlighting and a query preview.
20
+ * Renders a CodeMirror editor with SQL syntax highlighting and a query preview.
21
21
  *
22
22
  * Must be used within a VegaLiteChart.Container component.
23
23
  *
@@ -1 +1 @@
1
- {"version":3,"file":"VegaSqlEditorPanel.d.ts","sourceRoot":"","sources":["../../src/editor/VegaSqlEditorPanel.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CAsFhE,CAAC"}
1
+ {"version":3,"file":"VegaSqlEditorPanel.d.ts","sourceRoot":"","sources":["../../src/editor/VegaSqlEditorPanel.tsx"],"names":[],"mappings":"AAGA,OAAO,KAA8B,MAAM,OAAO,CAAC;AAGnD,MAAM,WAAW,uBAAuB;IACtC;;OAEG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;CACzB;AAED;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,kBAAkB,EAAE,KAAK,CAAC,EAAE,CAAC,uBAAuB,CA6FhE,CAAC"}
@@ -1,12 +1,12 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
- import { SqlMonacoEditor, SqlQueryPreview } from '@sqlrooms/sql-editor';
3
- import { Button, cn } from '@sqlrooms/ui';
2
+ import { SqlCodeMirrorEditor, SqlQueryPreview } from '@sqlrooms/sql-editor';
3
+ import { Button, cn, CopyButton } from '@sqlrooms/ui';
4
4
  import { PlayIcon } from 'lucide-react';
5
5
  import { useCallback, useState } from 'react';
6
6
  import { useVegaEditorContext } from './VegaEditorContext';
7
7
  /**
8
8
  * SQL editor panel subcomponent for VegaLiteChart.Container.
9
- * Renders a Monaco editor with SQL syntax highlighting and a query preview.
9
+ * Renders a CodeMirror editor with SQL syntax highlighting and a query preview.
10
10
  *
11
11
  * Must be used within a VegaLiteChart.Container component.
12
12
  *
@@ -29,13 +29,12 @@ export const VegaSqlEditorPanel = ({ className, title = 'SQL Query', maxPreviewR
29
29
  const showHeader = title !== '';
30
30
  return (_jsxs("div", { className: cn('flex h-full flex-col', className), children: [showHeader ? (_jsxs("div", { className: "flex items-center justify-between border-b px-3 py-2", children: [_jsx("span", { className: "text-sm font-medium", children: title }), _jsxs("div", { className: "flex items-center gap-2", children: [state.isSqlDirty && (_jsx("span", { className: "text-muted-foreground text-xs", children: "Modified" })), editable && (_jsxs(Button, { variant: "ghost", size: "xs", onClick: handleRunPreview, disabled: !state.editedSql.trim(), children: [_jsx(PlayIcon, { className: "mr-1 h-3 w-3" }), "Preview"] }))] })] })) : (
31
31
  /* Toolbar when no header - just show preview button */
32
- editable && (_jsx("div", { className: "flex items-center justify-end border-b px-2 py-1", children: _jsxs(Button, { variant: "ghost", size: "xs", onClick: handleRunPreview, disabled: !state.editedSql.trim(), children: [_jsx(PlayIcon, { className: "mr-1 h-3 w-3" }), "Preview"] }) }))), _jsx("div", { className: "relative min-h-[100px] flex-1", children: _jsx(SqlMonacoEditor, { className: "absolute inset-0 h-full w-full", value: state.editedSql, onChange: (value) => {
33
- if (value !== undefined) {
32
+ editable && (_jsx("div", { className: "flex items-center justify-end border-b px-2 py-1", children: _jsxs(Button, { variant: "ghost", size: "xs", onClick: handleRunPreview, disabled: !state.editedSql.trim(), children: [_jsx(PlayIcon, { className: "mr-1 h-3 w-3" }), "Preview"] }) }))), _jsxs("div", { className: "relative min-h-[100px] flex-1", children: [_jsx(SqlCodeMirrorEditor, { className: "absolute inset-0 h-full w-full", value: state.editedSql, onChange: (value) => {
34
33
  actions.setEditedSql(value);
35
- }
36
- }, options: {
37
- lineNumbers: 'off',
38
- fixedOverflowWidgets: false,
39
- }, readOnly: !editable }) }), previewQuery && showPreview && (_jsx("div", { className: "max-h-[200px] overflow-auto border-t", children: _jsx(SqlQueryPreview, { query: previewQuery, defaultLimit: maxPreviewRows, limitOptions: [100, 500, 1000] }) }))] }));
34
+ }, options: {
35
+ lineNumbers: true,
36
+ lineWrapping: true,
37
+ foldGutter: true,
38
+ }, readOnly: !editable }), _jsx("div", { className: "bg-background absolute top-2 right-2 rounded-md border", children: _jsx(CopyButton, { text: state.editedSql, size: "xs", tooltipLabel: "Copy SQL", disabled: !state.editedSql.trim() }) })] }), previewQuery && showPreview && (_jsx("div", { className: "max-h-[200px] overflow-auto border-t", children: _jsx(SqlQueryPreview, { query: previewQuery, defaultLimit: maxPreviewRows, limitOptions: [100, 500, 1000] }) }))] }));
40
39
  };
41
40
  //# sourceMappingURL=VegaSqlEditorPanel.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"VegaSqlEditorPanel.js","sourceRoot":"","sources":["../../src/editor/VegaSqlEditorPanel.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,eAAe,EAAE,eAAe,EAAC,MAAM,sBAAsB,CAAC;AACtE,OAAO,EAAC,MAAM,EAAE,EAAE,EAAC,MAAM,cAAc,CAAC;AACxC,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AACtC,OAAc,EAAC,WAAW,EAAE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,GAAG,eAE9B,CACV,IACG,IACF,CACP,CAAC,CAAC,CAAC;YACF,uDAAuD;YACvD,QAAQ,IAAI,CACV,cAAK,SAAS,EAAC,kDAAkD,YAC/D,MAAC,MAAM,IACL,OAAO,EAAC,OAAO,EACf,IAAI,EAAC,IAAI,EACT,OAAO,EAAE,gBAAgB,EACzB,QAAQ,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,aAEjC,KAAC,QAAQ,IAAC,SAAS,EAAC,cAAc,GAAG,eAE9B,GACL,CACP,CACF,EAGD,cAAK,SAAS,EAAC,+BAA+B,YAC5C,KAAC,eAAe,IACd,SAAS,EAAC,gCAAgC,EAC1C,KAAK,EAAE,KAAK,CAAC,SAAS,EACtB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;wBAClB,IAAI,KAAK,KAAK,SAAS,EAAE,CAAC;4BACxB,OAAO,CAAC,YAAY,CAAC,KAAK,CAAC,CAAC;wBAC9B,CAAC;oBACH,CAAC,EACD,OAAO,EAAE;wBACP,WAAW,EAAE,KAAK;wBAClB,oBAAoB,EAAE,KAAK;qBAC5B,EACD,QAAQ,EAAE,CAAC,QAAQ,GACnB,GACE,EAGL,YAAY,IAAI,WAAW,IAAI,CAC9B,cAAK,SAAS,EAAC,sCAAsC,YACnD,KAAC,eAAe,IACd,KAAK,EAAE,YAAY,EACnB,YAAY,EAAE,cAAc,EAC5B,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAC9B,GACE,CACP,IACG,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {SqlMonacoEditor, SqlQueryPreview} from '@sqlrooms/sql-editor';\nimport {Button, cn} from '@sqlrooms/ui';\nimport {PlayIcon} from 'lucide-react';\nimport React, {useCallback, useState} from 'react';\nimport {useVegaEditorContext} from './VegaEditorContext';\n\nexport interface VegaSqlEditorPanelProps {\n /**\n * Custom class name for the panel\n */\n className?: string;\n /**\n * Title shown in the panel header\n * @default \"SQL Query\"\n */\n title?: string;\n /**\n * Max rows to fetch for preview\n * @default 100\n */\n maxPreviewRows?: number;\n}\n\n/**\n * SQL editor panel subcomponent for VegaLiteChart.Container.\n * Renders a Monaco editor with SQL syntax highlighting and a query preview.\n *\n * Must be used within a VegaLiteChart.Container component.\n *\n * @example\n * ```tsx\n * <VegaLiteChart.Container spec={spec} sqlQuery={query}>\n * <VegaLiteChart.Chart />\n * <VegaLiteChart.SqlEditor />\n * </VegaLiteChart.Container>\n * ```\n */\nexport const VegaSqlEditorPanel: React.FC<VegaSqlEditorPanelProps> = ({\n className,\n title = 'SQL Query',\n maxPreviewRows = 100,\n}) => {\n const {state, actions, editable} = useVegaEditorContext();\n const [previewQuery, setPreviewQuery] = useState<string>('');\n const [showPreview, setShowPreview] = useState(false);\n\n const handleRunPreview = useCallback(() => {\n setPreviewQuery(state.editedSql);\n setShowPreview(true);\n }, [state.editedSql]);\n\n const showHeader = title !== '';\n\n return (\n <div className={cn('flex h-full flex-col', className)}>\n {/* Header - only show if title is provided */}\n {showHeader ? (\n <div className=\"flex items-center justify-between border-b px-3 py-2\">\n <span className=\"text-sm font-medium\">{title}</span>\n <div className=\"flex items-center gap-2\">\n {state.isSqlDirty && (\n <span className=\"text-muted-foreground text-xs\">Modified</span>\n )}\n {editable && (\n <Button\n variant=\"ghost\"\n size=\"xs\"\n onClick={handleRunPreview}\n disabled={!state.editedSql.trim()}\n >\n <PlayIcon className=\"mr-1 h-3 w-3\" />\n Preview\n </Button>\n )}\n </div>\n </div>\n ) : (\n /* Toolbar when no header - just show preview button */\n editable && (\n <div className=\"flex items-center justify-end border-b px-2 py-1\">\n <Button\n variant=\"ghost\"\n size=\"xs\"\n onClick={handleRunPreview}\n disabled={!state.editedSql.trim()}\n >\n <PlayIcon className=\"mr-1 h-3 w-3\" />\n Preview\n </Button>\n </div>\n )\n )}\n\n {/* Editor */}\n <div className=\"relative min-h-[100px] flex-1\">\n <SqlMonacoEditor\n className=\"absolute inset-0 h-full w-full\"\n value={state.editedSql}\n onChange={(value) => {\n if (value !== undefined) {\n actions.setEditedSql(value);\n }\n }}\n options={{\n lineNumbers: 'off',\n fixedOverflowWidgets: false,\n }}\n readOnly={!editable}\n />\n </div>\n\n {/* Preview Results */}\n {previewQuery && showPreview && (\n <div className=\"max-h-[200px] overflow-auto border-t\">\n <SqlQueryPreview\n query={previewQuery}\n defaultLimit={maxPreviewRows}\n limitOptions={[100, 500, 1000]}\n />\n </div>\n )}\n </div>\n );\n};\n"]}
1
+ {"version":3,"file":"VegaSqlEditorPanel.js","sourceRoot":"","sources":["../../src/editor/VegaSqlEditorPanel.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,mBAAmB,EAAE,eAAe,EAAC,MAAM,sBAAsB,CAAC;AAC1E,OAAO,EAAC,MAAM,EAAE,EAAE,EAAE,UAAU,EAAC,MAAM,cAAc,CAAC;AACpD,OAAO,EAAC,QAAQ,EAAC,MAAM,cAAc,CAAC;AACtC,OAAc,EAAC,WAAW,EAAE,QAAQ,EAAC,MAAM,OAAO,CAAC;AACnD,OAAO,EAAC,oBAAoB,EAAC,MAAM,qBAAqB,CAAC;AAmBzD;;;;;;;;;;;;;GAaG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAsC,CAAC,EACpE,SAAS,EACT,KAAK,GAAG,WAAW,EACnB,cAAc,GAAG,GAAG,GACrB,EAAE,EAAE;IACH,MAAM,EAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAC,GAAG,oBAAoB,EAAE,CAAC;IAC1D,MAAM,CAAC,YAAY,EAAE,eAAe,CAAC,GAAG,QAAQ,CAAS,EAAE,CAAC,CAAC;IAC7D,MAAM,CAAC,WAAW,EAAE,cAAc,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;IAEtD,MAAM,gBAAgB,GAAG,WAAW,CAAC,GAAG,EAAE;QACxC,eAAe,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;QACjC,cAAc,CAAC,IAAI,CAAC,CAAC;I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AY,EAAE,IAAI;4BAClB,UAAU,EAAE,IAAI;yBACjB,EACD,QAAQ,EAAE,CAAC,QAAQ,GACnB,EACF,cAAK,SAAS,EAAC,wDAAwD,YACrE,KAAC,UAAU,IACT,IAAI,EAAE,KAAK,CAAC,SAAS,EACrB,IAAI,EAAC,IAAI,EACT,YAAY,EAAC,UAAU,EACvB,QAAQ,EAAE,CAAC,KAAK,CAAC,SAAS,CAAC,IAAI,EAAE,GACjC,GACE,IACF,EAGL,YAAY,IAAI,WAAW,IAAI,CAC9B,cAAK,SAAS,EAAC,sCAAsC,YACnD,KAAC,eAAe,IACd,KAAK,EAAE,YAAY,EACnB,YAAY,EAAE,cAAc,EAC5B,YAAY,EAAE,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,GAC9B,GACE,CACP,IACG,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {SqlCodeMirrorEditor, SqlQueryPreview} from '@sqlrooms/sql-editor';\nimport {Button, cn, CopyButton} from '@sqlrooms/ui';\nimport {PlayIcon} from 'lucide-react';\nimport React, {useCallback, useState} from 'react';\nimport {useVegaEditorContext} from './VegaEditorContext';\n\nexport interface VegaSqlEditorPanelProps {\n /**\n * Custom class name for the panel\n */\n className?: string;\n /**\n * Title shown in the panel header\n * @default \"SQL Query\"\n */\n title?: string;\n /**\n * Max rows to fetch for preview\n * @default 100\n */\n maxPreviewRows?: number;\n}\n\n/**\n * SQL editor panel subcomponent for VegaLiteChart.Container.\n * Renders a CodeMirror editor with SQL syntax highlighting and a query preview.\n *\n * Must be used within a VegaLiteChart.Container component.\n *\n * @example\n * ```tsx\n * <VegaLiteChart.Container spec={spec} sqlQuery={query}>\n * <VegaLiteChart.Chart />\n * <VegaLiteChart.SqlEditor />\n * </VegaLiteChart.Container>\n * ```\n */\nexport const VegaSqlEditorPanel: React.FC<VegaSqlEditorPanelProps> = ({\n className,\n title = 'SQL Query',\n maxPreviewRows = 100,\n}) => {\n const {state, actions, editable} = useVegaEditorContext();\n const [previewQuery, setPreviewQuery] = useState<string>('');\n const [showPreview, setShowPreview] = useState(false);\n\n const handleRunPreview = useCallback(() => {\n setPreviewQuery(state.editedSql);\n setShowPreview(true);\n }, [state.editedSql]);\n\n const showHeader = title !== '';\n\n return (\n <div className={cn('flex h-full flex-col', className)}>\n {/* Header - only show if title is provided */}\n {showHeader ? (\n <div className=\"flex items-center justify-between border-b px-3 py-2\">\n <span className=\"text-sm font-medium\">{title}</span>\n <div className=\"flex items-center gap-2\">\n {state.isSqlDirty && (\n <span className=\"text-muted-foreground text-xs\">Modified</span>\n )}\n {editable && (\n <Button\n variant=\"ghost\"\n size=\"xs\"\n onClick={handleRunPreview}\n disabled={!state.editedSql.trim()}\n >\n <PlayIcon className=\"mr-1 h-3 w-3\" />\n Preview\n </Button>\n )}\n </div>\n </div>\n ) : (\n /* Toolbar when no header - just show preview button */\n editable && (\n <div className=\"flex items-center justify-end border-b px-2 py-1\">\n <Button\n variant=\"ghost\"\n size=\"xs\"\n onClick={handleRunPreview}\n disabled={!state.editedSql.trim()}\n >\n <PlayIcon className=\"mr-1 h-3 w-3\" />\n Preview\n </Button>\n </div>\n )\n )}\n\n {/* Editor */}\n <div className=\"relative min-h-[100px] flex-1\">\n <SqlCodeMirrorEditor\n className=\"absolute inset-0 h-full w-full\"\n value={state.editedSql}\n onChange={(value) => {\n actions.setEditedSql(value);\n }}\n options={{\n lineNumbers: true,\n lineWrapping: true,\n foldGutter: true,\n }}\n readOnly={!editable}\n />\n <div className=\"bg-background absolute top-2 right-2 rounded-md border\">\n <CopyButton\n text={state.editedSql}\n size=\"xs\"\n tooltipLabel=\"Copy SQL\"\n disabled={!state.editedSql.trim()}\n />\n </div>\n </div>\n\n {/* Preview Results */}\n {previewQuery && showPreview && (\n <div className=\"max-h-[200px] overflow-auto border-t\">\n <SqlQueryPreview\n query={previewQuery}\n defaultLimit={maxPreviewRows}\n limitOptions={[100, 500, 1000]}\n />\n </div>\n )}\n </div>\n );\n};\n"]}