UNPKG

sql-workbench-embedded

Version:

Lightweight JavaScript library that transforms static SQL code blocks into interactive, browser-based SQL execution environments using DuckDB WASM

272 lines (260 loc) 6.87 kB
/** * Set global configuration */ declare function config(options: Partial<SQLWorkbenchConfig>): void; /** * Custom theme definition */ declare interface CustomTheme { /** Base theme to extend ('light' or 'dark') */ extends?: 'light' | 'dark'; /** Theme configuration overrides */ config: Partial<ThemeConfig>; } /** * Destroy all embeds and cleanup */ declare function destroy(): void; export declare class Embedded { private element; private options; private container; private editorElement; private outputElement; private runButton; private resetButton; private openButton; private initialCode; private state; private destroyed; constructor(element: HTMLElement, options?: Partial<EmbeddedOptions>); /** * Extract initial SQL code from element */ private extractInitialCode; /** * Initialize the embed */ private init; /** * Create UI structure */ private createUI; /** * Resolve theme (auto, light, dark, or custom) */ private resolveTheme; /** * Attach event listeners */ private attachEventListeners; /** * Update editor with syntax highlighting */ private updateEditor; /** * Insert text at current cursor position */ private insertText; /** * Set cursor position in editor */ private setCursorPosition; /** * Get current SQL code from editor */ private getCode; /** * Set SQL code in editor */ private setCode; /** * Run SQL query */ run(): Promise<void>; /** * Reset to original code */ reset(): void; /** * Set embed state */ private setState; /** * Show the Reset button (called after first query execution) */ private showResetButton; /** * Show loading state */ private showLoading; /** * Show error message */ private showError; /** * Show query result */ private showResult; /** * Escape HTML */ private escapeHtml; /** * Encode query for URL using URL-safe Base64 without padding */ private encodeQueryForURL; /** * Open current query in SQL Workbench */ private openInSQLWorkbench; /** * Destroy embed and cleanup */ destroy(): void; /** * Check if embed is destroyed */ isDestroyed(): boolean; /** * Get embed container element */ getContainer(): HTMLElement | null; } /** * Per-instance embedded options */ export declare interface EmbeddedOptions extends SQLWorkbenchConfig { /** Initial SQL code (if not extracted from element) */ initialCode?: string; } /** * Get current global configuration */ declare function getConfig(): Required<SQLWorkbenchConfig>; /** * Initialize embeds automatically */ declare function init(): void; /** * Query execution result */ export declare interface QueryResult { /** Column names */ columns: string[]; /** Row data */ rows: unknown[][]; /** Number of rows returned */ rowCount: number; /** Execution time in milliseconds */ executionTime: number; } declare const SQLWorkbench: { Embedded: typeof Embedded; init: typeof init; destroy: typeof destroy; config: typeof config; getConfig: typeof getConfig; }; export { SQLWorkbench } export default SQLWorkbench; /** * Global configuration options for SQL Workbench Embed */ export declare interface SQLWorkbenchConfig { /** CSS selector for automatic embed discovery */ selector?: string; /** Base URL for resolving relative file paths */ baseUrl?: string; /** Visual theme */ theme?: 'light' | 'dark' | 'auto' | string; /** Custom theme definitions */ customThemes?: Record<string, CustomTheme>; /** Enable automatic initialization on DOMContentLoaded */ autoInit?: boolean; /** DuckDB WASM version to use */ duckdbVersion?: string; /** CDN URL for DuckDB assets */ duckdbCDN?: string; /** Allow SQL code editing */ editable?: boolean; /** Show "Open in SQL Workbench" button */ showOpenButton?: boolean; /** * Initialization queries to execute once before first user query. * Useful for installing/loading DuckDB extensions. * Queries execute sequentially in array order. * Example: ["INSTALL httpfs", "LOAD httpfs"] */ initQueries?: string[]; } /** * CSS theme variables interface */ declare interface ThemeConfig { /** Background color */ bgColor: string; /** Text color */ textColor: string; /** Border color */ borderColor: string; /** Editor background */ editorBg: string; /** Editor text color */ editorText: string; /** Editor focus background */ editorFocusBg: string; /** Controls background */ controlsBg: string; /** Primary button background */ primaryBg: string; /** Primary button text color */ primaryText: string; /** Primary button hover background */ primaryHover: string; /** Secondary button background */ secondaryBg: string; /** Secondary button text color */ secondaryText: string; /** Secondary button hover background */ secondaryHover: string; /** Muted text color */ mutedText: string; /** Error text color */ errorText: string; /** Error background */ errorBg: string; /** Error border color */ errorBorder: string; /** Table header background */ tableHeaderBg: string; /** Table header text color */ tableHeaderText: string; /** Table hover background */ tableHover: string; /** Syntax highlighting - SQL keywords */ syntaxKeyword?: string; /** Syntax highlighting - string literals */ syntaxString?: string; /** Syntax highlighting - numbers */ syntaxNumber?: string; /** Syntax highlighting - comments */ syntaxComment?: string; /** Syntax highlighting - function names */ syntaxFunction?: string; /** Syntax highlighting - operators */ syntaxOperator?: string; /** Font family for the container and UI elements */ fontFamily?: string; /** Font family for the SQL editor */ editorFontFamily?: string; /** Base font size */ fontSize?: string; /** Font size for the SQL editor */ editorFontSize?: string; /** Font size for buttons */ buttonFontSize?: string; /** Font size for metadata text */ metadataFontSize?: string; } export { }