UNPKG

react-sql-workbench-embedded

Version:

React wrapper component for the sql-workbench-embedded package, which is a library for creating interactive SQL editors in the browser using DuckDB WASM.

158 lines (143 loc) 4.07 kB
import { default as default_2 } from 'react'; import { Embedded } from 'sql-workbench-embedded'; import { EmbeddedOptions } from 'sql-workbench-embedded'; import { JSX } from 'react/jsx-runtime'; import { QueryResult } from 'sql-workbench-embedded'; import { ReactNode } from 'react'; import { SQLWorkbenchConfig } from 'sql-workbench-embedded'; export { Embedded } export { EmbeddedOptions } export { QueryResult } export { SQLWorkbenchConfig } declare interface SQLWorkbenchContextValue { isReady: boolean; error: Error | null; } /** * React wrapper component for sql-workbench-embedded * * @example * ```tsx * import { SQLWorkbenchEmbedded } from 'react-sql-workbench-embedded'; * * function MyComponent() { * return ( * <SQLWorkbenchEmbedded * initialCode="SELECT * FROM generate_series(1, 10);" * theme="dark" * editable={true} * /> * ); * } * ``` */ export declare const SQLWorkbenchEmbedded: default_2.ForwardRefExoticComponent<SQLWorkbenchEmbeddedProps & default_2.RefAttributes<SQLWorkbenchEmbeddedRef>>; export declare type SQLWorkbenchEmbeddedInstance = Embedded; export declare interface SQLWorkbenchEmbeddedProps { /** * Initial SQL code to display in the workbench */ initialCode?: string; /** * Theme for the workbench ('light', 'dark', 'auto', or custom theme name) * @default 'auto' */ theme?: Theme; /** * Whether the SQL editor is editable * @default true */ editable?: boolean; /** * Show "Open in SQL Workbench" button * @default true */ showOpenButton?: boolean; /** * Custom className for the container element */ className?: string; /** * Custom styles for the container element */ style?: default_2.CSSProperties; /** * Callback fired when the workbench instance is ready */ onReady?: (instance: SQLWorkbenchEmbeddedInstance) => void; /** * Callback fired when there's an error initializing the workbench */ onError?: (error: Error) => void; } export declare interface SQLWorkbenchEmbeddedRef { /** * Get the underlying SQLWorkbench instance */ getInstance: () => SQLWorkbenchEmbeddedInstance | null; /** * Get the container element */ getElement: () => HTMLDivElement | null; } /** * Provider component for global SQL Workbench configuration * * @example * ```tsx * import { SQLWorkbenchProvider } from 'react-sql-workbench-embedded'; * * function App() { * return ( * <SQLWorkbenchProvider * config={{ * theme: 'dark', * editable: true, * initQueries: ['INSTALL spatial', 'LOAD spatial'] * }} * > * <YourApp /> * </SQLWorkbenchProvider> * ); * } * ``` */ export declare function SQLWorkbenchProvider({ config, children, onReady, onError }: SQLWorkbenchProviderProps): JSX.Element; export declare interface SQLWorkbenchProviderProps { /** * Global configuration for SQL Workbench */ config?: SQLWorkbenchConfig; /** * Children components */ children: ReactNode; /** * Callback fired when SQL Workbench is ready */ onReady?: () => void; /** * Callback fired when there's an error loading SQL Workbench */ onError?: (error: Error) => void; } export declare type Theme = NonNullable<SQLWorkbenchConfig['theme']>; /** * Hook to access SQL Workbench context * * @returns The SQL Workbench context value * * @example * ```tsx * function MyComponent() { * const { isReady, error } = useSQLWorkbench(); * * if (error) return <div>Error: {error.message}</div>; * if (!isReady) return <div>Loading...</div>; * * return <SQLWorkbenchEmbedded initialCode="SELECT 1;" />; * } * ``` */ export declare function useSQLWorkbench(): SQLWorkbenchContextValue; export { }