@sqlrooms/monaco-editor 0.7.0 → 0.8.1
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/README.md +3 -1
- package/dist/components/MonacoEditor.js +1 -1
- package/dist/components/MonacoEditor.js.map +1 -1
- package/package.json +3 -3
- package/dist/components/SqlMonacoEditor.d.ts +0 -27
- package/dist/components/SqlMonacoEditor.d.ts.map +0 -1
- package/dist/components/SqlMonacoEditor.js +0 -172
- package/dist/components/SqlMonacoEditor.js.map +0 -1
- package/dist/constants/duckdb.d.ts +0 -73
- package/dist/constants/duckdb.d.ts.map +0 -1
- package/dist/constants/duckdb.js +0 -392
- package/dist/constants/duckdb.js.map +0 -1
package/README.md
CHANGED
|
@@ -149,6 +149,6 @@ export const MonacoEditor = ({ className, language = 'javascript', theme: explic
|
|
|
149
149
|
fontLigatures: true,
|
|
150
150
|
...options,
|
|
151
151
|
};
|
|
152
|
-
return (_jsx("div", { className: cn('
|
|
152
|
+
return (_jsx("div", { className: cn('h-[300px] w-full', className), children: _jsx(Editor, { height: "100%", width: "100%", language: language, theme: theme, value: value, options: defaultOptions, onMount: handleEditorDidMount, onChange: onChange, loading: _jsx(Spinner, {}), ...props }) }));
|
|
153
153
|
};
|
|
154
154
|
//# sourceMappingURL=MonacoEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MonacoEditor.js","sourceRoot":"","sources":["../../src/components/MonacoEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,MAAM,EAIN,MAAM,GACP,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AACnD,OAAc,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AAE9B,8BAA8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AC,CAAC;YAEF,iCAAiC;YACjC,UAAU,CAAC,gBAAgB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YAEpD,WAAW;YACX,OAAO,GAAG,EAAE;gBACV,UAAU,CAAC,mBAAmB,CAAC,QAAQ,EAAE,YAAY,CAAC,CAAC;YACzD,CAAC,CAAC;QACJ,CAAC;IACH,CAAC,EAAE,CAAC,QAAQ,EAAE,aAAa,EAAE,QAAQ,CAAC,CAAC,CAAC;IAExC,qCAAqC;IACrC,MAAM,UAAU,GAAG,gBAAgB,EAAE,CAAC;IAEtC,MAAM,cAAc,GAAG;QACrB,OAAO,EAAE,EAAC,OAAO,EAAE,KAAK,EAAC;QACzB,oBAAoB,EAAE,KAAK;QAC3B,eAAe,EAAE,IAAI;QACrB,QAAQ;QACR,UAAU;QACV,aAAa,EAAE,IAAI;QACnB,GAAG,OAAO;KACX,CAAC;IAEF,OAAO,CACL,cAAK,SAAS,EAAE,EAAE,CAAC,kBAAkB,EAAE,SAAS,CAAC,YAC/C,KAAC,MAAM,IACL,MAAM,EAAC,MAAM,EACb,KAAK,EAAC,MAAM,EACZ,QAAQ,EAAE,QAAQ,EAClB,KAAK,EAAE,KAAK,EACZ,KAAK,EAAE,KAAK,EACZ,OAAO,EAAE,cAAc,EACvB,OAAO,EAAE,oBAAoB,EAC7B,QAAQ,EAAE,QAAQ,EAClB,OAAO,EAAE,KAAC,OAAO,KAAG,KAChB,KAAK,GACT,GACE,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {\n Editor,\n EditorProps,\n OnChange,\n OnMount,\n loader,\n} from '@monaco-editor/react';\nimport {Spinner, cn, useTheme} from '@sqlrooms/ui';\nimport React, {useEffect, useRef} from 'react';\nimport {\n getCssColor,\n getJsonEditorTheme,\n getMenuColors,\n getMonospaceFont,\n} from '../utils/color-utils';\n\n// Configure the Monaco loader\nloader.config({\n paths: {\n vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs',\n },\n});\n\nexport interface MonacoEditorProps extends Omit<EditorProps, 'onMount'> {\n /**\n * Callback when the editor is mounted\n */\n onMount?: OnMount;\n /**\n * Callback when the editor content changes\n */\n onChange?: OnChange;\n /**\n * CSS class name for the editor container\n * @default ''\n */\n className?: string;\n /**\n * The language of the editor\n * @default 'javascript'\n */\n language?: string;\n /**\n * The theme of the editor\n * Can be explicitly set or will automatically use the app theme if not provided\n * @default 'vs-dark'\n */\n theme?: 'vs-dark' | 'light';\n /**\n * The value of the editor\n */\n value?: string;\n /**\n * Whether the editor is read-only\n * @default false\n */\n readOnly?: boolean;\n /**\n * Additional options for the editor\n */\n options?: Record<string, any>;\n}\n\n/**\n * A wrapper around the Monaco Editor component\n */\nexport const MonacoEditor: React.FC<MonacoEditorProps> = ({\n className,\n language = 'javascript',\n theme: explicitTheme,\n value = '',\n readOnly = false,\n onMount,\n onChange,\n options = {},\n ...props\n}) => {\n // Get the app theme from the ThemeProvider\n const {theme: appTheme} = useTheme();\n\n // If a theme is explicitly provided, use it. Otherwise, determine from the app theme\n const theme =\n explicitTheme ||\n (appTheme === 'dark' ||\n (appTheme === 'system' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches)\n ? 'vs-dark'\n : 'light');\n\n const editorRef = useRef<any>(null);\n const monacoRef = useRef<any>(null);\n\n const handleEditorDidMount: OnMount = (editor, monaco) => {\n editorRef.current = editor;\n monacoRef.current = monaco;\n\n // Special language configuration for JSON\n if (language === 'json') {\n // Define a more robust tokenizer for JSON with improved rules\n monaco.languages.setMonarchTokensProvider('json', {\n tokenizer: {\n root: [\n // Property keys (strings followed by a colon)\n [/\"([^\"]*)\"(?=\\s*:)/, 'string.key.json'],\n\n // Regular string values (any quoted string not followed by a colon)\n [/\"([^\"]*)\"(?!\\s*:)/, 'string.value.json'],\n\n // Numbers (integers, decimals, and scientific notation)\n [/-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/, 'number'],\n\n // Keywords\n [/\\b(?:true|false|null)\\b/, 'keyword'],\n\n // Punctuation and delimiters\n [/[{}[\\],:]/, 'delimiter'],\n ],\n },\n });\n }\n\n // Define editor themes with Tailwind CSS variables\n monaco.editor.defineTheme('sqlrooms-light', {\n base: 'vs',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': getCssColor('--background', '#ffffff'),\n 'editor.foreground': getCssColor('--foreground', '#000000'),\n 'editor.lineHighlightBackground': getCssColor('--muted', '#f5f5f5'),\n 'editorCursor.foreground': getCssColor('--primary', '#000000'),\n 'editor.selectionBackground': getCssColor('--accent', '#e3e3e3'),\n 'editorLineNumber.foreground': getCssColor(\n '--muted-foreground',\n '#888888',\n ),\n ...getMenuColors(false),\n },\n });\n\n monaco.editor.defineTheme('sqlrooms-dark', {\n base: 'vs-dark',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': getCssColor('--background', '#1e1e1e'),\n 'editor.foreground': getCssColor('--foreground', '#d4d4d4'),\n 'editor.lineHighlightBackground': getCssColor('--muted', '#2a2a2a'),\n 'editorCursor.foreground': getCssColor('--primary', '#ffffff'),\n 'editor.selectionBackground': getCssColor('--accent', '#264f78'),\n 'editorLineNumber.foreground': getCssColor(\n '--muted-foreground',\n '#858585',\n ),\n ...getMenuColors(true),\n },\n });\n\n // Define JSON-specific themes with rich token coloring\n monaco.editor.defineTheme('sqlrooms-json-light', getJsonEditorTheme(false));\n monaco.editor.defineTheme('sqlrooms-json-dark', getJsonEditorTheme(true));\n\n // Apply the custom theme based on content type\n const isDark =\n appTheme === 'dark' ||\n (appTheme === 'system' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches);\n\n // Use JSON-specific theme for JSON files\n if (language === 'json') {\n monaco.editor.setTheme(\n isDark ? 'sqlrooms-json-dark' : 'sqlrooms-json-light',\n );\n } else {\n monaco.editor.setTheme(isDark ? 'sqlrooms-dark' : 'sqlrooms-light');\n }\n\n if (onMount) {\n onMount(editor, monaco);\n }\n };\n\n // Apply readOnly option\n useEffect(() => {\n if (editorRef.current) {\n editorRef.current.updateOptions({readOnly});\n }\n }, [readOnly]);\n\n // Update the editor theme when app theme changes\n useEffect(() => {\n if (editorRef.current && monacoRef.current && !explicitTheme) {\n const isDark =\n appTheme === 'dark' ||\n (appTheme === 'system' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches);\n\n // Use JSON-specific theme for JSON files\n if (language === 'json') {\n monacoRef.current.editor.setTheme(\n isDark ? 'sqlrooms-json-dark' : 'sqlrooms-json-light',\n );\n } else {\n monacoRef.current.editor.setTheme(\n isDark ? 'sqlrooms-dark' : 'sqlrooms-light',\n );\n }\n }\n }, [appTheme, explicitTheme, language]);\n\n // Listen for system theme changes if using system theme\n useEffect(() => {\n if (appTheme === 'system' && !explicitTheme && monacoRef.current) {\n const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');\n const handleChange = () => {\n if (monacoRef.current) {\n // Use JSON-specific theme for JSON files\n if (language === 'json') {\n monacoRef.current.editor.setTheme(\n mediaQuery.matches ? 'sqlrooms-json-dark' : 'sqlrooms-json-light',\n );\n } else {\n monacoRef.current.editor.setTheme(\n mediaQuery.matches ? 'sqlrooms-dark' : 'sqlrooms-light',\n );\n }\n }\n };\n\n // Add listener for theme changes\n mediaQuery.addEventListener('change', handleChange);\n\n // Clean up\n return () => {\n mediaQuery.removeEventListener('change', handleChange);\n };\n }\n }, [appTheme, explicitTheme, language]);\n\n // Get monospace font for code editor\n const fontFamily = getMonospaceFont();\n\n const defaultOptions = {\n minimap: {enabled: false},\n scrollBeyondLastLine: false,\n automaticLayout: true,\n readOnly,\n fontFamily,\n fontLigatures: true,\n ...options,\n };\n\n return (\n <div className={cn('w-full h-[300px]', className)}>\n <Editor\n height=\"100%\"\n width=\"100%\"\n language={language}\n theme={theme}\n value={value}\n options={defaultOptions}\n onMount={handleEditorDidMount}\n onChange={onChange}\n loading={<Spinner />}\n {...props}\n />\n </div>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"MonacoEditor.js","sourceRoot":"","sources":["../../src/components/MonacoEditor.tsx"],"names":[],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","sourcesContent":["import {\n Editor,\n EditorProps,\n OnChange,\n OnMount,\n loader,\n} from '@monaco-editor/react';\nimport {Spinner, cn, useTheme} from '@sqlrooms/ui';\nimport React, {useEffect, useRef} from 'react';\nimport {\n getCssColor,\n getJsonEditorTheme,\n getMenuColors,\n getMonospaceFont,\n} from '../utils/color-utils';\n\n// Configure the Monaco loader\nloader.config({\n paths: {\n vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs',\n },\n});\n\nexport interface MonacoEditorProps extends Omit<EditorProps, 'onMount'> {\n /**\n * Callback when the editor is mounted\n */\n onMount?: OnMount;\n /**\n * Callback when the editor content changes\n */\n onChange?: OnChange;\n /**\n * CSS class name for the editor container\n * @default ''\n */\n className?: string;\n /**\n * The language of the editor\n * @default 'javascript'\n */\n language?: string;\n /**\n * The theme of the editor\n * Can be explicitly set or will automatically use the app theme if not provided\n * @default 'vs-dark'\n */\n theme?: 'vs-dark' | 'light';\n /**\n * The value of the editor\n */\n value?: string;\n /**\n * Whether the editor is read-only\n * @default false\n */\n readOnly?: boolean;\n /**\n * Additional options for the editor\n */\n options?: Record<string, any>;\n}\n\n/**\n * A wrapper around the Monaco Editor component\n */\nexport const MonacoEditor: React.FC<MonacoEditorProps> = ({\n className,\n language = 'javascript',\n theme: explicitTheme,\n value = '',\n readOnly = false,\n onMount,\n onChange,\n options = {},\n ...props\n}) => {\n // Get the app theme from the ThemeProvider\n const {theme: appTheme} = useTheme();\n\n // If a theme is explicitly provided, use it. Otherwise, determine from the app theme\n const theme =\n explicitTheme ||\n (appTheme === 'dark' ||\n (appTheme === 'system' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches)\n ? 'vs-dark'\n : 'light');\n\n const editorRef = useRef<any>(null);\n const monacoRef = useRef<any>(null);\n\n const handleEditorDidMount: OnMount = (editor, monaco) => {\n editorRef.current = editor;\n monacoRef.current = monaco;\n\n // Special language configuration for JSON\n if (language === 'json') {\n // Define a more robust tokenizer for JSON with improved rules\n monaco.languages.setMonarchTokensProvider('json', {\n tokenizer: {\n root: [\n // Property keys (strings followed by a colon)\n [/\"([^\"]*)\"(?=\\s*:)/, 'string.key.json'],\n\n // Regular string values (any quoted string not followed by a colon)\n [/\"([^\"]*)\"(?!\\s*:)/, 'string.value.json'],\n\n // Numbers (integers, decimals, and scientific notation)\n [/-?\\d+(?:\\.\\d+)?(?:[eE][+-]?\\d+)?/, 'number'],\n\n // Keywords\n [/\\b(?:true|false|null)\\b/, 'keyword'],\n\n // Punctuation and delimiters\n [/[{}[\\],:]/, 'delimiter'],\n ],\n },\n });\n }\n\n // Define editor themes with Tailwind CSS variables\n monaco.editor.defineTheme('sqlrooms-light', {\n base: 'vs',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': getCssColor('--background', '#ffffff'),\n 'editor.foreground': getCssColor('--foreground', '#000000'),\n 'editor.lineHighlightBackground': getCssColor('--muted', '#f5f5f5'),\n 'editorCursor.foreground': getCssColor('--primary', '#000000'),\n 'editor.selectionBackground': getCssColor('--accent', '#e3e3e3'),\n 'editorLineNumber.foreground': getCssColor(\n '--muted-foreground',\n '#888888',\n ),\n ...getMenuColors(false),\n },\n });\n\n monaco.editor.defineTheme('sqlrooms-dark', {\n base: 'vs-dark',\n inherit: true,\n rules: [],\n colors: {\n 'editor.background': getCssColor('--background', '#1e1e1e'),\n 'editor.foreground': getCssColor('--foreground', '#d4d4d4'),\n 'editor.lineHighlightBackground': getCssColor('--muted', '#2a2a2a'),\n 'editorCursor.foreground': getCssColor('--primary', '#ffffff'),\n 'editor.selectionBackground': getCssColor('--accent', '#264f78'),\n 'editorLineNumber.foreground': getCssColor(\n '--muted-foreground',\n '#858585',\n ),\n ...getMenuColors(true),\n },\n });\n\n // Define JSON-specific themes with rich token coloring\n monaco.editor.defineTheme('sqlrooms-json-light', getJsonEditorTheme(false));\n monaco.editor.defineTheme('sqlrooms-json-dark', getJsonEditorTheme(true));\n\n // Apply the custom theme based on content type\n const isDark =\n appTheme === 'dark' ||\n (appTheme === 'system' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches);\n\n // Use JSON-specific theme for JSON files\n if (language === 'json') {\n monaco.editor.setTheme(\n isDark ? 'sqlrooms-json-dark' : 'sqlrooms-json-light',\n );\n } else {\n monaco.editor.setTheme(isDark ? 'sqlrooms-dark' : 'sqlrooms-light');\n }\n\n if (onMount) {\n onMount(editor, monaco);\n }\n };\n\n // Apply readOnly option\n useEffect(() => {\n if (editorRef.current) {\n editorRef.current.updateOptions({readOnly});\n }\n }, [readOnly]);\n\n // Update the editor theme when app theme changes\n useEffect(() => {\n if (editorRef.current && monacoRef.current && !explicitTheme) {\n const isDark =\n appTheme === 'dark' ||\n (appTheme === 'system' &&\n window.matchMedia('(prefers-color-scheme: dark)').matches);\n\n // Use JSON-specific theme for JSON files\n if (language === 'json') {\n monacoRef.current.editor.setTheme(\n isDark ? 'sqlrooms-json-dark' : 'sqlrooms-json-light',\n );\n } else {\n monacoRef.current.editor.setTheme(\n isDark ? 'sqlrooms-dark' : 'sqlrooms-light',\n );\n }\n }\n }, [appTheme, explicitTheme, language]);\n\n // Listen for system theme changes if using system theme\n useEffect(() => {\n if (appTheme === 'system' && !explicitTheme && monacoRef.current) {\n const mediaQuery = window.matchMedia('(prefers-color-scheme: dark)');\n const handleChange = () => {\n if (monacoRef.current) {\n // Use JSON-specific theme for JSON files\n if (language === 'json') {\n monacoRef.current.editor.setTheme(\n mediaQuery.matches ? 'sqlrooms-json-dark' : 'sqlrooms-json-light',\n );\n } else {\n monacoRef.current.editor.setTheme(\n mediaQuery.matches ? 'sqlrooms-dark' : 'sqlrooms-light',\n );\n }\n }\n };\n\n // Add listener for theme changes\n mediaQuery.addEventListener('change', handleChange);\n\n // Clean up\n return () => {\n mediaQuery.removeEventListener('change', handleChange);\n };\n }\n }, [appTheme, explicitTheme, language]);\n\n // Get monospace font for code editor\n const fontFamily = getMonospaceFont();\n\n const defaultOptions = {\n minimap: {enabled: false},\n scrollBeyondLastLine: false,\n automaticLayout: true,\n readOnly,\n fontFamily,\n fontLigatures: true,\n ...options,\n };\n\n return (\n <div className={cn('h-[300px] w-full', className)}>\n <Editor\n height=\"100%\"\n width=\"100%\"\n language={language}\n theme={theme}\n value={value}\n options={defaultOptions}\n onMount={handleEditorDidMount}\n onChange={onChange}\n loading={<Spinner />}\n {...props}\n />\n </div>\n );\n};\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/monaco-editor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
},
|
|
21
21
|
"dependencies": {
|
|
22
22
|
"@monaco-editor/react": "^4.7.0",
|
|
23
|
-
"@sqlrooms/ui": "0.
|
|
23
|
+
"@sqlrooms/ui": "0.8.1",
|
|
24
24
|
"monaco-editor": "^0.52.2"
|
|
25
25
|
},
|
|
26
26
|
"peerDependencies": {
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"lint": "eslint .",
|
|
34
34
|
"typedoc": "typedoc"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "7b5e727b79d675c17b93412c109d1ba1b22699c8"
|
|
37
37
|
}
|
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
import React from 'react';
|
|
2
|
-
import { MonacoEditorProps } from './MonacoEditor';
|
|
3
|
-
export interface SqlMonacoEditorProps extends Omit<MonacoEditorProps, 'language'> {
|
|
4
|
-
/**
|
|
5
|
-
* Custom SQL keywords to add to the completion provider
|
|
6
|
-
*/
|
|
7
|
-
customKeywords?: string[];
|
|
8
|
-
/**
|
|
9
|
-
* Custom SQL functions to add to the completion provider
|
|
10
|
-
*/
|
|
11
|
-
customFunctions?: string[];
|
|
12
|
-
/**
|
|
13
|
-
* Table schemas for autocompletion
|
|
14
|
-
* Format: { tableName: { columnName: columnType, ... }, ... }
|
|
15
|
-
*/
|
|
16
|
-
tableSchemas?: Record<string, Record<string, string>>;
|
|
17
|
-
/**
|
|
18
|
-
* Sample data for tables to enhance autocompletion
|
|
19
|
-
* Format: { tableName: [sampleDescription1, sampleDescription2, ...], ... }
|
|
20
|
-
*/
|
|
21
|
-
tableSamples?: Record<string, string[]>;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* A Monaco editor for editing SQL with DuckDB syntax highlighting and autocompletion
|
|
25
|
-
*/
|
|
26
|
-
export declare const SqlMonacoEditor: React.FC<SqlMonacoEditorProps>;
|
|
27
|
-
//# sourceMappingURL=SqlMonacoEditor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SqlMonacoEditor.d.ts","sourceRoot":"","sources":["../../src/components/SqlMonacoEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAe,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAS/D,MAAM,WAAW,oBACf,SAAQ,IAAI,CAAC,iBAAiB,EAAE,UAAU,CAAC;IAC3C;;OAEG;IACH,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B;;OAEG;IACH,eAAe,CAAC,EAAE,MAAM,EAAE,CAAC;IAC3B;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC,CAAC;IACtD;;;OAGG;IACH,YAAY,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,CAAC;CACzC;AAED;;GAEG;AACH,eAAO,MAAM,eAAe,EAAE,KAAK,CAAC,EAAE,CAAC,oBAAoB,CA2M1D,CAAC"}
|
|
@@ -1,172 +0,0 @@
|
|
|
1
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import { MonacoEditor } from './MonacoEditor';
|
|
3
|
-
import { DUCKDB_KEYWORDS, DUCKDB_FUNCTIONS, SQL_LANGUAGE_CONFIGURATION, } from '../constants/duckdb';
|
|
4
|
-
/**
|
|
5
|
-
* A Monaco editor for editing SQL with DuckDB syntax highlighting and autocompletion
|
|
6
|
-
*/
|
|
7
|
-
export const SqlMonacoEditor = ({ customKeywords = [], customFunctions = [], tableSchemas = {}, tableSamples = {}, onMount, className, ...props }) => {
|
|
8
|
-
// Handle editor mounting to configure SQL language features
|
|
9
|
-
const handleEditorDidMount = (editor, monaco) => {
|
|
10
|
-
// Register SQL language if not already registered
|
|
11
|
-
if (!monaco.languages.getLanguages().some((lang) => lang.id === 'sql')) {
|
|
12
|
-
monaco.languages.register({ id: 'sql' });
|
|
13
|
-
}
|
|
14
|
-
// Combine keywords and functions with custom ones
|
|
15
|
-
const keywords = [...DUCKDB_KEYWORDS, ...customKeywords];
|
|
16
|
-
const functions = [...DUCKDB_FUNCTIONS, ...customFunctions];
|
|
17
|
-
// Set the language configuration
|
|
18
|
-
monaco.languages.setMonarchTokensProvider('sql', {
|
|
19
|
-
...SQL_LANGUAGE_CONFIGURATION,
|
|
20
|
-
keywords,
|
|
21
|
-
builtinFunctions: functions,
|
|
22
|
-
}); // Using 'as any' to bypass the type checking issue
|
|
23
|
-
// Dispose any existing completion providers for SQL
|
|
24
|
-
// Using a safer approach that doesn't rely on internal properties
|
|
25
|
-
try {
|
|
26
|
-
// We'll register our provider and let Monaco handle the disposal of previous ones
|
|
27
|
-
}
|
|
28
|
-
catch (error) {
|
|
29
|
-
console.error('Error disposing completion providers:', error);
|
|
30
|
-
}
|
|
31
|
-
// Register SQL completion provider
|
|
32
|
-
const disposable = monaco.languages.registerCompletionItemProvider('sql', {
|
|
33
|
-
triggerCharacters: [' ', '.', ',', '(', '='],
|
|
34
|
-
provideCompletionItems: (model, position) => {
|
|
35
|
-
try {
|
|
36
|
-
const suggestions = [];
|
|
37
|
-
const word = model.getWordUntilPosition(position);
|
|
38
|
-
const range = {
|
|
39
|
-
startLineNumber: position.lineNumber,
|
|
40
|
-
endLineNumber: position.lineNumber,
|
|
41
|
-
startColumn: word.startColumn,
|
|
42
|
-
endColumn: word.endColumn,
|
|
43
|
-
};
|
|
44
|
-
// Get the text before the cursor to determine context
|
|
45
|
-
const lineContent = model.getLineContent(position.lineNumber);
|
|
46
|
-
const textBeforeCursor = lineContent
|
|
47
|
-
.substring(0, position.column - 1)
|
|
48
|
-
.trim()
|
|
49
|
-
.toLowerCase();
|
|
50
|
-
// Check if we're after a FROM, JOIN, or similar clause to prioritize table suggestions
|
|
51
|
-
const isTableContext = /\b(from|join|into|update|table)\s+\w*$/.test(textBeforeCursor);
|
|
52
|
-
// Check if we're after a table name and period to prioritize column suggestions
|
|
53
|
-
const isColumnContext = /\b(\w+)\.\w*$/.test(textBeforeCursor);
|
|
54
|
-
// Add keyword suggestions (if not in a specific context)
|
|
55
|
-
if (!isColumnContext) {
|
|
56
|
-
keywords.forEach((keyword) => {
|
|
57
|
-
suggestions.push({
|
|
58
|
-
label: keyword,
|
|
59
|
-
kind: monaco.languages.CompletionItemKind.Keyword,
|
|
60
|
-
insertText: keyword,
|
|
61
|
-
range: range,
|
|
62
|
-
detail: 'Keyword',
|
|
63
|
-
sortText: isTableContext ? 'z' + keyword : 'a' + keyword, // Lower priority in table context
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
// Add function suggestions (if not in a specific context)
|
|
68
|
-
if (!isColumnContext) {
|
|
69
|
-
functions.forEach((func) => {
|
|
70
|
-
suggestions.push({
|
|
71
|
-
label: func,
|
|
72
|
-
kind: monaco.languages.CompletionItemKind.Function,
|
|
73
|
-
insertText: func,
|
|
74
|
-
range: range,
|
|
75
|
-
detail: 'Function',
|
|
76
|
-
sortText: isTableContext ? 'z' + func : 'b' + func, // Lower priority in table context
|
|
77
|
-
});
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
// Add table and column suggestions from schemas
|
|
81
|
-
Object.entries(tableSchemas).forEach(([tableName, columns]) => {
|
|
82
|
-
// Get sample data for this table if available
|
|
83
|
-
const samples = tableSamples[tableName] || [];
|
|
84
|
-
const sampleText = samples.length > 0 ? `\nSample data:\n${samples.join('\n')}` : '';
|
|
85
|
-
// Add table suggestion
|
|
86
|
-
suggestions.push({
|
|
87
|
-
label: tableName,
|
|
88
|
-
kind: monaco.languages.CompletionItemKind.Class,
|
|
89
|
-
insertText: tableName,
|
|
90
|
-
range: range,
|
|
91
|
-
detail: 'Table',
|
|
92
|
-
documentation: {
|
|
93
|
-
value: `Table: ${tableName}${sampleText}`,
|
|
94
|
-
isTrusted: true,
|
|
95
|
-
},
|
|
96
|
-
sortText: isTableContext ? 'a' + tableName : 'c' + tableName, // Higher priority in table context
|
|
97
|
-
});
|
|
98
|
-
// Extract table name from context if we're in a column context
|
|
99
|
-
let contextTableName = '';
|
|
100
|
-
if (isColumnContext) {
|
|
101
|
-
const match = textBeforeCursor.match(/\b(\w+)\.\w*$/);
|
|
102
|
-
if (match && match[1]) {
|
|
103
|
-
contextTableName = match[1];
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
// Only add columns for the current table if we're in a column context
|
|
107
|
-
if (!isColumnContext || contextTableName === tableName) {
|
|
108
|
-
// Add column suggestions
|
|
109
|
-
Object.entries(columns).forEach(([columnName, columnType]) => {
|
|
110
|
-
// Find sample values for this column if available
|
|
111
|
-
const columnSample = samples.find((s) => s.startsWith(`${columnName}:`));
|
|
112
|
-
const sampleInfo = columnSample
|
|
113
|
-
? `\nSample: ${columnSample.split(':')[1]?.trim() || ''}`
|
|
114
|
-
: '';
|
|
115
|
-
suggestions.push({
|
|
116
|
-
label: columnName,
|
|
117
|
-
kind: monaco.languages.CompletionItemKind.Field,
|
|
118
|
-
insertText: columnName,
|
|
119
|
-
range: range,
|
|
120
|
-
detail: `Column (${columnType})`,
|
|
121
|
-
documentation: {
|
|
122
|
-
value: `Column from table ${tableName}${sampleInfo}`,
|
|
123
|
-
isTrusted: true,
|
|
124
|
-
},
|
|
125
|
-
sortText: isColumnContext && contextTableName === tableName
|
|
126
|
-
? 'a' + columnName
|
|
127
|
-
: 'd' + columnName,
|
|
128
|
-
});
|
|
129
|
-
// Only add table.column suggestions if not in a column context
|
|
130
|
-
if (!isColumnContext) {
|
|
131
|
-
suggestions.push({
|
|
132
|
-
label: `${tableName}.${columnName}`,
|
|
133
|
-
kind: monaco.languages.CompletionItemKind.Field,
|
|
134
|
-
insertText: `${tableName}.${columnName}`,
|
|
135
|
-
range: range,
|
|
136
|
-
detail: `Column (${columnType})`,
|
|
137
|
-
documentation: {
|
|
138
|
-
value: `Column from table ${tableName}${sampleInfo}`,
|
|
139
|
-
isTrusted: true,
|
|
140
|
-
},
|
|
141
|
-
sortText: 'e' + tableName + columnName,
|
|
142
|
-
});
|
|
143
|
-
}
|
|
144
|
-
});
|
|
145
|
-
}
|
|
146
|
-
});
|
|
147
|
-
return {
|
|
148
|
-
suggestions,
|
|
149
|
-
};
|
|
150
|
-
}
|
|
151
|
-
catch (error) {
|
|
152
|
-
console.error('Error in SQL completion provider:', error);
|
|
153
|
-
return { suggestions: [] };
|
|
154
|
-
}
|
|
155
|
-
},
|
|
156
|
-
});
|
|
157
|
-
// Store the disposable to clean up later if needed
|
|
158
|
-
editor.onDidDispose(() => {
|
|
159
|
-
disposable.dispose();
|
|
160
|
-
});
|
|
161
|
-
// Call the original onMount if provided
|
|
162
|
-
if (onMount) {
|
|
163
|
-
onMount(editor, monaco);
|
|
164
|
-
}
|
|
165
|
-
};
|
|
166
|
-
return (_jsx(MonacoEditor, { language: "sql", onMount: handleEditorDidMount, className: className, options: {
|
|
167
|
-
formatOnPaste: true,
|
|
168
|
-
formatOnType: true,
|
|
169
|
-
wordWrap: 'on',
|
|
170
|
-
}, ...props }));
|
|
171
|
-
};
|
|
172
|
-
//# sourceMappingURL=SqlMonacoEditor.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Sq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vB,CAAC,CAAC,CAAC;QAEH,wCAAwC;QACxC,IAAI,OAAO,EAAE,CAAC;YACZ,OAAO,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC,CAAC;IAEF,OAAO,CACL,KAAC,YAAY,IACX,QAAQ,EAAC,KAAK,EACd,OAAO,EAAE,oBAAoB,EAC7B,SAAS,EAAE,SAAS,EACpB,OAAO,EAAE;YACP,aAAa,EAAE,IAAI;YACnB,YAAY,EAAE,IAAI;YAClB,QAAQ,EAAE,IAAI;SACf,KACG,KAAK,GACT,CACH,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import React from 'react';\nimport {MonacoEditor, MonacoEditorProps} from './MonacoEditor';\nimport {OnMount} from '@monaco-editor/react';\nimport type * as Monaco from 'monaco-editor';\nimport {\n DUCKDB_KEYWORDS,\n DUCKDB_FUNCTIONS,\n SQL_LANGUAGE_CONFIGURATION,\n} from '../constants/duckdb';\n\nexport interface SqlMonacoEditorProps\n extends Omit<MonacoEditorProps, 'language'> {\n /**\n * Custom SQL keywords to add to the completion provider\n */\n customKeywords?: string[];\n /**\n * Custom SQL functions to add to the completion provider\n */\n customFunctions?: string[];\n /**\n * Table schemas for autocompletion\n * Format: { tableName: { columnName: columnType, ... }, ... }\n */\n tableSchemas?: Record<string, Record<string, string>>;\n /**\n * Sample data for tables to enhance autocompletion\n * Format: { tableName: [sampleDescription1, sampleDescription2, ...], ... }\n */\n tableSamples?: Record<string, string[]>;\n}\n\n/**\n * A Monaco editor for editing SQL with DuckDB syntax highlighting and autocompletion\n */\nexport const SqlMonacoEditor: React.FC<SqlMonacoEditorProps> = ({\n customKeywords = [],\n customFunctions = [],\n tableSchemas = {},\n tableSamples = {},\n onMount,\n className,\n ...props\n}) => {\n // Handle editor mounting to configure SQL language features\n const handleEditorDidMount: OnMount = (editor, monaco) => {\n // Register SQL language if not already registered\n if (!monaco.languages.getLanguages().some((lang) => lang.id === 'sql')) {\n monaco.languages.register({id: 'sql'});\n }\n\n // Combine keywords and functions with custom ones\n const keywords = [...DUCKDB_KEYWORDS, ...customKeywords];\n const functions = [...DUCKDB_FUNCTIONS, ...customFunctions];\n\n // Set the language configuration\n monaco.languages.setMonarchTokensProvider('sql', {\n ...SQL_LANGUAGE_CONFIGURATION,\n keywords,\n builtinFunctions: functions,\n } as any); // Using 'as any' to bypass the type checking issue\n\n // Dispose any existing completion providers for SQL\n // Using a safer approach that doesn't rely on internal properties\n try {\n // We'll register our provider and let Monaco handle the disposal of previous ones\n } catch (error) {\n console.error('Error disposing completion providers:', error);\n }\n\n // Register SQL completion provider\n const disposable = monaco.languages.registerCompletionItemProvider('sql', {\n triggerCharacters: [' ', '.', ',', '(', '='],\n provideCompletionItems: (model, position) => {\n try {\n const suggestions: Monaco.languages.CompletionItem[] = [];\n const word = model.getWordUntilPosition(position);\n const range = {\n startLineNumber: position.lineNumber,\n endLineNumber: position.lineNumber,\n startColumn: word.startColumn,\n endColumn: word.endColumn,\n };\n\n // Get the text before the cursor to determine context\n const lineContent = model.getLineContent(position.lineNumber);\n const textBeforeCursor = lineContent\n .substring(0, position.column - 1)\n .trim()\n .toLowerCase();\n\n // Check if we're after a FROM, JOIN, or similar clause to prioritize table suggestions\n const isTableContext = /\\b(from|join|into|update|table)\\s+\\w*$/.test(\n textBeforeCursor,\n );\n\n // Check if we're after a table name and period to prioritize column suggestions\n const isColumnContext = /\\b(\\w+)\\.\\w*$/.test(textBeforeCursor);\n\n // Add keyword suggestions (if not in a specific context)\n if (!isColumnContext) {\n keywords.forEach((keyword) => {\n suggestions.push({\n label: keyword,\n kind: monaco.languages.CompletionItemKind.Keyword,\n insertText: keyword,\n range: range,\n detail: 'Keyword',\n sortText: isTableContext ? 'z' + keyword : 'a' + keyword, // Lower priority in table context\n });\n });\n }\n\n // Add function suggestions (if not in a specific context)\n if (!isColumnContext) {\n functions.forEach((func) => {\n suggestions.push({\n label: func,\n kind: monaco.languages.CompletionItemKind.Function,\n insertText: func,\n range: range,\n detail: 'Function',\n sortText: isTableContext ? 'z' + func : 'b' + func, // Lower priority in table context\n });\n });\n }\n\n // Add table and column suggestions from schemas\n Object.entries(tableSchemas).forEach(([tableName, columns]) => {\n // Get sample data for this table if available\n const samples = tableSamples[tableName] || [];\n const sampleText =\n samples.length > 0 ? `\\nSample data:\\n${samples.join('\\n')}` : '';\n\n // Add table suggestion\n suggestions.push({\n label: tableName,\n kind: monaco.languages.CompletionItemKind.Class,\n insertText: tableName,\n range: range,\n detail: 'Table',\n documentation: {\n value: `Table: ${tableName}${sampleText}`,\n isTrusted: true,\n },\n sortText: isTableContext ? 'a' + tableName : 'c' + tableName, // Higher priority in table context\n });\n\n // Extract table name from context if we're in a column context\n let contextTableName = '';\n if (isColumnContext) {\n const match = textBeforeCursor.match(/\\b(\\w+)\\.\\w*$/);\n if (match && match[1]) {\n contextTableName = match[1];\n }\n }\n\n // Only add columns for the current table if we're in a column context\n if (!isColumnContext || contextTableName === tableName) {\n // Add column suggestions\n Object.entries(columns).forEach(([columnName, columnType]) => {\n // Find sample values for this column if available\n const columnSample = samples.find((s) =>\n s.startsWith(`${columnName}:`),\n );\n const sampleInfo = columnSample\n ? `\\nSample: ${columnSample.split(':')[1]?.trim() || ''}`\n : '';\n\n suggestions.push({\n label: columnName,\n kind: monaco.languages.CompletionItemKind.Field,\n insertText: columnName,\n range: range,\n detail: `Column (${columnType})`,\n documentation: {\n value: `Column from table ${tableName}${sampleInfo}`,\n isTrusted: true,\n },\n sortText:\n isColumnContext && contextTableName === tableName\n ? 'a' + columnName\n : 'd' + columnName,\n });\n\n // Only add table.column suggestions if not in a column context\n if (!isColumnContext) {\n suggestions.push({\n label: `${tableName}.${columnName}`,\n kind: monaco.languages.CompletionItemKind.Field,\n insertText: `${tableName}.${columnName}`,\n range: range,\n detail: `Column (${columnType})`,\n documentation: {\n value: `Column from table ${tableName}${sampleInfo}`,\n isTrusted: true,\n },\n sortText: 'e' + tableName + columnName,\n });\n }\n });\n }\n });\n\n return {\n suggestions,\n };\n } catch (error) {\n console.error('Error in SQL completion provider:', error);\n return {suggestions: []};\n }\n },\n });\n\n // Store the disposable to clean up later if needed\n editor.onDidDispose(() => {\n disposable.dispose();\n });\n\n // Call the original onMount if provided\n if (onMount) {\n onMount(editor, monaco);\n }\n };\n\n return (\n <MonacoEditor\n language=\"sql\"\n onMount={handleEditorDidMount}\n className={className}\n options={{\n formatOnPaste: true,\n formatOnType: true,\n wordWrap: 'on',\n }}\n {...props}\n />\n );\n};\n"]}
|
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DuckDB SQL language constants for Monaco Editor
|
|
3
|
-
*/
|
|
4
|
-
export declare const DUCKDB_KEYWORDS: string[];
|
|
5
|
-
export declare const DUCKDB_FUNCTIONS: string[];
|
|
6
|
-
export declare const SQL_OPERATORS: string[];
|
|
7
|
-
export declare const SQL_VARIABLES: string[];
|
|
8
|
-
export declare const SQL_PSEUDO_COLUMNS: string[];
|
|
9
|
-
export declare const SQL_LANGUAGE_CONFIGURATION: {
|
|
10
|
-
defaultToken: string;
|
|
11
|
-
tokenPostfix: string;
|
|
12
|
-
ignoreCase: boolean;
|
|
13
|
-
brackets: {
|
|
14
|
-
open: string;
|
|
15
|
-
close: string;
|
|
16
|
-
token: string;
|
|
17
|
-
}[];
|
|
18
|
-
keywords: string[];
|
|
19
|
-
operators: string[];
|
|
20
|
-
builtinFunctions: string[];
|
|
21
|
-
builtinVariables: string[];
|
|
22
|
-
pseudoColumns: string[];
|
|
23
|
-
tokenizer: {
|
|
24
|
-
root: ((string | RegExp)[] | {
|
|
25
|
-
include: string;
|
|
26
|
-
} | (RegExp | {
|
|
27
|
-
cases: {
|
|
28
|
-
'@keywords': string;
|
|
29
|
-
'@operators': string;
|
|
30
|
-
'@builtinFunctions': string;
|
|
31
|
-
'@builtinVariables': string;
|
|
32
|
-
'@pseudoColumns': string;
|
|
33
|
-
'@default': string;
|
|
34
|
-
};
|
|
35
|
-
})[])[];
|
|
36
|
-
whitespace: (string | RegExp)[][];
|
|
37
|
-
comments: ((string | RegExp)[] | (RegExp | {
|
|
38
|
-
token: string;
|
|
39
|
-
next: string;
|
|
40
|
-
})[])[];
|
|
41
|
-
comment: ((string | RegExp)[] | (RegExp | {
|
|
42
|
-
token: string;
|
|
43
|
-
next: string;
|
|
44
|
-
})[])[];
|
|
45
|
-
numbers: (string | RegExp)[][];
|
|
46
|
-
strings: (RegExp | {
|
|
47
|
-
token: string;
|
|
48
|
-
next: string;
|
|
49
|
-
})[][];
|
|
50
|
-
string: ((string | RegExp)[] | (RegExp | {
|
|
51
|
-
token: string;
|
|
52
|
-
next: string;
|
|
53
|
-
})[])[];
|
|
54
|
-
stringDouble: ((string | RegExp)[] | (RegExp | {
|
|
55
|
-
token: string;
|
|
56
|
-
next: string;
|
|
57
|
-
})[])[];
|
|
58
|
-
complexIdentifiers: (RegExp | {
|
|
59
|
-
token: string;
|
|
60
|
-
next: string;
|
|
61
|
-
})[][];
|
|
62
|
-
bracketedIdentifier: ((string | RegExp)[] | (RegExp | {
|
|
63
|
-
token: string;
|
|
64
|
-
next: string;
|
|
65
|
-
})[])[];
|
|
66
|
-
quotedIdentifier: ((string | RegExp)[] | (RegExp | {
|
|
67
|
-
token: string;
|
|
68
|
-
next: string;
|
|
69
|
-
})[])[];
|
|
70
|
-
scopes: never[];
|
|
71
|
-
};
|
|
72
|
-
};
|
|
73
|
-
//# sourceMappingURL=duckdb.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"duckdb.d.ts","sourceRoot":"","sources":["../../src/constants/duckdb.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,eAAO,MAAM,eAAe,UA6H3B,CAAC;AAGF,eAAO,MAAM,gBAAgB,UAgI5B,CAAC;AAGF,eAAO,MAAM,aAAa,UAyBzB,CAAC;AAGF,eAAO,MAAM,aAAa,UAUzB,CAAC;AAGF,eAAO,MAAM,kBAAkB,UAK9B,CAAC;AAGF,eAAO,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAsFtC,CAAC"}
|
package/dist/constants/duckdb.js
DELETED
|
@@ -1,392 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* DuckDB SQL language constants for Monaco Editor
|
|
3
|
-
*/
|
|
4
|
-
// DuckDB specific keywords
|
|
5
|
-
export const DUCKDB_KEYWORDS = [
|
|
6
|
-
'PRAGMA',
|
|
7
|
-
'RETURNING',
|
|
8
|
-
'QUALIFY',
|
|
9
|
-
'PIVOT',
|
|
10
|
-
'UNPIVOT',
|
|
11
|
-
'EXCLUDE',
|
|
12
|
-
'INCLUDE',
|
|
13
|
-
'WINDOW',
|
|
14
|
-
'FILTER',
|
|
15
|
-
'WITHIN',
|
|
16
|
-
'OVER',
|
|
17
|
-
'PARTITION',
|
|
18
|
-
'RANGE',
|
|
19
|
-
'ROWS',
|
|
20
|
-
'GROUPS',
|
|
21
|
-
'PRECEDING',
|
|
22
|
-
'FOLLOWING',
|
|
23
|
-
'CURRENT',
|
|
24
|
-
'ROW',
|
|
25
|
-
'TIES',
|
|
26
|
-
'OTHERS',
|
|
27
|
-
'EXCLUDE',
|
|
28
|
-
'RESPECT',
|
|
29
|
-
'NULLS',
|
|
30
|
-
'FIRST',
|
|
31
|
-
'LAST',
|
|
32
|
-
'MATERIALIZED',
|
|
33
|
-
'RECURSIVE',
|
|
34
|
-
'TEMPORARY',
|
|
35
|
-
'TEMP',
|
|
36
|
-
'UNLOGGED',
|
|
37
|
-
'GLOBAL',
|
|
38
|
-
'LOCAL',
|
|
39
|
-
'STORED',
|
|
40
|
-
'VIRTUAL',
|
|
41
|
-
'DELIMITED',
|
|
42
|
-
'CSV',
|
|
43
|
-
'JSON',
|
|
44
|
-
'COPY',
|
|
45
|
-
'DESCRIBE',
|
|
46
|
-
'EXPLAIN',
|
|
47
|
-
'SUMMARIZE',
|
|
48
|
-
'PROFILE',
|
|
49
|
-
'LOAD',
|
|
50
|
-
'INSTALL',
|
|
51
|
-
'FORCE',
|
|
52
|
-
'PARALLEL',
|
|
53
|
-
'SEQUENTIAL',
|
|
54
|
-
'PRAGMA',
|
|
55
|
-
// Standard SQL keywords
|
|
56
|
-
'SELECT',
|
|
57
|
-
'FROM',
|
|
58
|
-
'WHERE',
|
|
59
|
-
'GROUP',
|
|
60
|
-
'BY',
|
|
61
|
-
'HAVING',
|
|
62
|
-
'ORDER',
|
|
63
|
-
'LIMIT',
|
|
64
|
-
'OFFSET',
|
|
65
|
-
'INSERT',
|
|
66
|
-
'INTO',
|
|
67
|
-
'VALUES',
|
|
68
|
-
'UPDATE',
|
|
69
|
-
'SET',
|
|
70
|
-
'DELETE',
|
|
71
|
-
'CREATE',
|
|
72
|
-
'ALTER',
|
|
73
|
-
'DROP',
|
|
74
|
-
'TABLE',
|
|
75
|
-
'VIEW',
|
|
76
|
-
'INDEX',
|
|
77
|
-
'TRIGGER',
|
|
78
|
-
'PROCEDURE',
|
|
79
|
-
'FUNCTION',
|
|
80
|
-
'DATABASE',
|
|
81
|
-
'SCHEMA',
|
|
82
|
-
'JOIN',
|
|
83
|
-
'INNER',
|
|
84
|
-
'LEFT',
|
|
85
|
-
'RIGHT',
|
|
86
|
-
'FULL',
|
|
87
|
-
'OUTER',
|
|
88
|
-
'CROSS',
|
|
89
|
-
'NATURAL',
|
|
90
|
-
'ON',
|
|
91
|
-
'USING',
|
|
92
|
-
'AND',
|
|
93
|
-
'OR',
|
|
94
|
-
'NOT',
|
|
95
|
-
'NULL',
|
|
96
|
-
'IS',
|
|
97
|
-
'IN',
|
|
98
|
-
'BETWEEN',
|
|
99
|
-
'LIKE',
|
|
100
|
-
'AS',
|
|
101
|
-
'CASE',
|
|
102
|
-
'WHEN',
|
|
103
|
-
'THEN',
|
|
104
|
-
'ELSE',
|
|
105
|
-
'END',
|
|
106
|
-
'DISTINCT',
|
|
107
|
-
'ALL',
|
|
108
|
-
'UNION',
|
|
109
|
-
'INTERSECT',
|
|
110
|
-
'EXCEPT',
|
|
111
|
-
'WITH',
|
|
112
|
-
'CAST',
|
|
113
|
-
'PRIMARY',
|
|
114
|
-
'KEY',
|
|
115
|
-
'FOREIGN',
|
|
116
|
-
'REFERENCES',
|
|
117
|
-
'CONSTRAINT',
|
|
118
|
-
'DEFAULT',
|
|
119
|
-
'CHECK',
|
|
120
|
-
'UNIQUE',
|
|
121
|
-
'INDEX',
|
|
122
|
-
'CASCADE',
|
|
123
|
-
'RESTRICT',
|
|
124
|
-
'ASC',
|
|
125
|
-
'DESC',
|
|
126
|
-
'IF',
|
|
127
|
-
'EXISTS',
|
|
128
|
-
'TRUE',
|
|
129
|
-
'FALSE',
|
|
130
|
-
];
|
|
131
|
-
// DuckDB functions
|
|
132
|
-
export const DUCKDB_FUNCTIONS = [
|
|
133
|
-
// Aggregate functions
|
|
134
|
-
'ARRAY_AGG',
|
|
135
|
-
'AVG',
|
|
136
|
-
'BIT_AND',
|
|
137
|
-
'BIT_OR',
|
|
138
|
-
'BIT_XOR',
|
|
139
|
-
'COUNT',
|
|
140
|
-
'FIRST',
|
|
141
|
-
'LAST',
|
|
142
|
-
'LIST',
|
|
143
|
-
'MAX',
|
|
144
|
-
'MIN',
|
|
145
|
-
'STRING_AGG',
|
|
146
|
-
'SUM',
|
|
147
|
-
'MEDIAN',
|
|
148
|
-
'QUANTILE',
|
|
149
|
-
'APPROX_COUNT_DISTINCT',
|
|
150
|
-
'APPROX_QUANTILE',
|
|
151
|
-
// Window functions
|
|
152
|
-
'ROW_NUMBER',
|
|
153
|
-
'RANK',
|
|
154
|
-
'DENSE_RANK',
|
|
155
|
-
'PERCENT_RANK',
|
|
156
|
-
'CUME_DIST',
|
|
157
|
-
'NTILE',
|
|
158
|
-
'LAG',
|
|
159
|
-
'LEAD',
|
|
160
|
-
'FIRST_VALUE',
|
|
161
|
-
'LAST_VALUE',
|
|
162
|
-
'NTH_VALUE',
|
|
163
|
-
// Date functions
|
|
164
|
-
'AGE',
|
|
165
|
-
'DATE_PART',
|
|
166
|
-
'DATE_TRUNC',
|
|
167
|
-
'EXTRACT',
|
|
168
|
-
'GREATEST',
|
|
169
|
-
'LEAST',
|
|
170
|
-
'NOW',
|
|
171
|
-
'CURRENT_DATE',
|
|
172
|
-
'CURRENT_TIME',
|
|
173
|
-
'CURRENT_TIMESTAMP',
|
|
174
|
-
'EPOCH',
|
|
175
|
-
'STRFTIME',
|
|
176
|
-
'STRPTIME',
|
|
177
|
-
'TO_TIMESTAMP',
|
|
178
|
-
// String functions
|
|
179
|
-
'CONCAT',
|
|
180
|
-
'LENGTH',
|
|
181
|
-
'LOWER',
|
|
182
|
-
'LPAD',
|
|
183
|
-
'LTRIM',
|
|
184
|
-
'REGEXP_MATCHES',
|
|
185
|
-
'REGEXP_REPLACE',
|
|
186
|
-
'REPEAT',
|
|
187
|
-
'REPLACE',
|
|
188
|
-
'REVERSE',
|
|
189
|
-
'RIGHT',
|
|
190
|
-
'RPAD',
|
|
191
|
-
'RTRIM',
|
|
192
|
-
'SPLIT',
|
|
193
|
-
'SUBSTRING',
|
|
194
|
-
'TRIM',
|
|
195
|
-
'UPPER',
|
|
196
|
-
// Nested functions
|
|
197
|
-
'LIST_EXTRACT',
|
|
198
|
-
'LIST_ELEMENT',
|
|
199
|
-
'LIST_VALUE',
|
|
200
|
-
'STRUCT_EXTRACT',
|
|
201
|
-
'STRUCT_PACK',
|
|
202
|
-
'MAP',
|
|
203
|
-
'MAP_EXTRACT',
|
|
204
|
-
// Math functions
|
|
205
|
-
'ABS',
|
|
206
|
-
'CEIL',
|
|
207
|
-
'CEILING',
|
|
208
|
-
'FLOOR',
|
|
209
|
-
'ROUND',
|
|
210
|
-
'SIGN',
|
|
211
|
-
'SQRT',
|
|
212
|
-
'CBRT',
|
|
213
|
-
'EXP',
|
|
214
|
-
'LN',
|
|
215
|
-
'LOG',
|
|
216
|
-
'POWER',
|
|
217
|
-
'MOD',
|
|
218
|
-
'RANDOM',
|
|
219
|
-
'SETSEED',
|
|
220
|
-
'ACOS',
|
|
221
|
-
'ASIN',
|
|
222
|
-
'ATAN',
|
|
223
|
-
'ATAN2',
|
|
224
|
-
'COS',
|
|
225
|
-
'COT',
|
|
226
|
-
'SIN',
|
|
227
|
-
'TAN',
|
|
228
|
-
'RADIANS',
|
|
229
|
-
'DEGREES',
|
|
230
|
-
'PI',
|
|
231
|
-
// Other functions
|
|
232
|
-
'COALESCE',
|
|
233
|
-
'NULLIF',
|
|
234
|
-
'TYPEOF',
|
|
235
|
-
'CURRENT_SCHEMA',
|
|
236
|
-
'CURRENT_USER',
|
|
237
|
-
'HASH',
|
|
238
|
-
'UUID',
|
|
239
|
-
'CHAR_LENGTH',
|
|
240
|
-
'CHARACTER_LENGTH',
|
|
241
|
-
'POSITION',
|
|
242
|
-
'OVERLAY',
|
|
243
|
-
'CONCAT_WS',
|
|
244
|
-
'FORMAT',
|
|
245
|
-
'TO_CHAR',
|
|
246
|
-
'TO_DATE',
|
|
247
|
-
'TO_NUMBER',
|
|
248
|
-
'LOCALTIME',
|
|
249
|
-
'LOCALTIMESTAMP',
|
|
250
|
-
'JUSTIFY_DAYS',
|
|
251
|
-
'JUSTIFY_HOURS',
|
|
252
|
-
'JUSTIFY_INTERVAL',
|
|
253
|
-
'MAKE_DATE',
|
|
254
|
-
'MAKE_INTERVAL',
|
|
255
|
-
'MAKE_TIME',
|
|
256
|
-
'MAKE_TIMESTAMP',
|
|
257
|
-
'CLOCK_TIMESTAMP',
|
|
258
|
-
'STATEMENT_TIMESTAMP',
|
|
259
|
-
'TRANSACTION_TIMESTAMP',
|
|
260
|
-
];
|
|
261
|
-
// SQL operators
|
|
262
|
-
export const SQL_OPERATORS = [
|
|
263
|
-
'+',
|
|
264
|
-
'-',
|
|
265
|
-
'*',
|
|
266
|
-
'/',
|
|
267
|
-
'%',
|
|
268
|
-
'&',
|
|
269
|
-
'|',
|
|
270
|
-
'^',
|
|
271
|
-
'=',
|
|
272
|
-
'<>',
|
|
273
|
-
'!=',
|
|
274
|
-
'>',
|
|
275
|
-
'>=',
|
|
276
|
-
'<',
|
|
277
|
-
'<=',
|
|
278
|
-
'<<',
|
|
279
|
-
'>>',
|
|
280
|
-
'||',
|
|
281
|
-
'::',
|
|
282
|
-
'->>',
|
|
283
|
-
'->',
|
|
284
|
-
'~',
|
|
285
|
-
'!',
|
|
286
|
-
'@',
|
|
287
|
-
];
|
|
288
|
-
// SQL variables
|
|
289
|
-
export const SQL_VARIABLES = [
|
|
290
|
-
'$1',
|
|
291
|
-
'$2',
|
|
292
|
-
'$3',
|
|
293
|
-
'$4',
|
|
294
|
-
'$5',
|
|
295
|
-
'$6',
|
|
296
|
-
'$7',
|
|
297
|
-
'$8',
|
|
298
|
-
'$9',
|
|
299
|
-
];
|
|
300
|
-
// SQL pseudo columns
|
|
301
|
-
export const SQL_PSEUDO_COLUMNS = [
|
|
302
|
-
'$ACTION',
|
|
303
|
-
'$IDENTITY',
|
|
304
|
-
'$ROWGUID',
|
|
305
|
-
'$PARTITION',
|
|
306
|
-
];
|
|
307
|
-
// SQL language configuration for Monaco Editor
|
|
308
|
-
export const SQL_LANGUAGE_CONFIGURATION = {
|
|
309
|
-
defaultToken: '',
|
|
310
|
-
tokenPostfix: '.sql',
|
|
311
|
-
ignoreCase: true,
|
|
312
|
-
brackets: [
|
|
313
|
-
{ open: '[', close: ']', token: 'delimiter.square' },
|
|
314
|
-
{ open: '(', close: ')', token: 'delimiter.parenthesis' },
|
|
315
|
-
],
|
|
316
|
-
keywords: DUCKDB_KEYWORDS,
|
|
317
|
-
operators: SQL_OPERATORS,
|
|
318
|
-
builtinFunctions: DUCKDB_FUNCTIONS,
|
|
319
|
-
builtinVariables: SQL_VARIABLES,
|
|
320
|
-
pseudoColumns: SQL_PSEUDO_COLUMNS,
|
|
321
|
-
tokenizer: {
|
|
322
|
-
root: [
|
|
323
|
-
{ include: '@comments' },
|
|
324
|
-
{ include: '@whitespace' },
|
|
325
|
-
{ include: '@numbers' },
|
|
326
|
-
{ include: '@strings' },
|
|
327
|
-
{ include: '@complexIdentifiers' },
|
|
328
|
-
{ include: '@scopes' },
|
|
329
|
-
[/[;,.]/, 'delimiter'],
|
|
330
|
-
[/[()]/, '@brackets'],
|
|
331
|
-
[
|
|
332
|
-
/[\w@#$]+/,
|
|
333
|
-
{
|
|
334
|
-
cases: {
|
|
335
|
-
'@keywords': 'keyword',
|
|
336
|
-
'@operators': 'operator',
|
|
337
|
-
'@builtinFunctions': 'predefined',
|
|
338
|
-
'@builtinVariables': 'predefined',
|
|
339
|
-
'@pseudoColumns': 'predefined',
|
|
340
|
-
'@default': 'identifier',
|
|
341
|
-
},
|
|
342
|
-
},
|
|
343
|
-
],
|
|
344
|
-
[/[<>=!%&+\-*/|~^]/, 'operator'],
|
|
345
|
-
],
|
|
346
|
-
whitespace: [[/\s+/, 'white']],
|
|
347
|
-
comments: [
|
|
348
|
-
[/--+.*/, 'comment'],
|
|
349
|
-
[/\/\*/, { token: 'comment.quote', next: '@comment' }],
|
|
350
|
-
],
|
|
351
|
-
comment: [
|
|
352
|
-
[/[^*/]+/, 'comment'],
|
|
353
|
-
[/\*\//, { token: 'comment.quote', next: '@pop' }],
|
|
354
|
-
[/./, 'comment'],
|
|
355
|
-
],
|
|
356
|
-
numbers: [
|
|
357
|
-
[/0[xX][0-9a-fA-F]*/, 'number'],
|
|
358
|
-
[/[$][+-]*\d*(\.\d*)?/, 'number'],
|
|
359
|
-
[/((\d+(\.\d*)?)|(\.\d+))([eE][\-+]?\d+)?/, 'number'],
|
|
360
|
-
],
|
|
361
|
-
strings: [
|
|
362
|
-
[/'/, { token: 'string', next: '@string' }],
|
|
363
|
-
[/"/, { token: 'string.double', next: '@stringDouble' }],
|
|
364
|
-
],
|
|
365
|
-
string: [
|
|
366
|
-
[/[^']+/, 'string'],
|
|
367
|
-
[/''/, 'string'],
|
|
368
|
-
[/'/, { token: 'string', next: '@pop' }],
|
|
369
|
-
],
|
|
370
|
-
stringDouble: [
|
|
371
|
-
[/[^"]+/, 'string.double'],
|
|
372
|
-
[/""/, 'string.double'],
|
|
373
|
-
[/"/, { token: 'string.double', next: '@pop' }],
|
|
374
|
-
],
|
|
375
|
-
complexIdentifiers: [
|
|
376
|
-
[/\[/, { token: 'identifier.quote', next: '@bracketedIdentifier' }],
|
|
377
|
-
[/"/, { token: 'identifier.quote', next: '@quotedIdentifier' }],
|
|
378
|
-
],
|
|
379
|
-
bracketedIdentifier: [
|
|
380
|
-
[/[^\]]+/, 'identifier'],
|
|
381
|
-
[/]]/, 'identifier'],
|
|
382
|
-
[/]/, { token: 'identifier.quote', next: '@pop' }],
|
|
383
|
-
],
|
|
384
|
-
quotedIdentifier: [
|
|
385
|
-
[/[^"]+/, 'identifier'],
|
|
386
|
-
[/""/, 'identifier'],
|
|
387
|
-
[/"/, { token: 'identifier.quote', next: '@pop' }],
|
|
388
|
-
],
|
|
389
|
-
scopes: [],
|
|
390
|
-
},
|
|
391
|
-
};
|
|
392
|
-
//# sourceMappingURL=duckdb.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"duckdb.js","sourceRoot":"","sources":["../../src/constants/duckdb.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,2BAA2B;AAC3B,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,QAAQ;IACR,WAAW;IACX,SAAS;IACT,OAAO;IACP,SAAS;IACT,SAAS;IACT,SAAS;IACT,QAAQ;IACR,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,WAAW;IACX,OAAO;IACP,MAAM;IACN,QAAQ;IACR,WAAW;IACX,WAAW;IACX,SAAS;IACT,KAAK;IACL,MAAM;IACN,QAAQ;IACR,SAAS;IACT,SAAS;IACT,OAAO;IACP,OAAO;IACP,MAAM;IACN,cAAc;IACd,WAAW;IACX,WAAW;IACX,MAAM;IACN,UAAU;IACV,QAAQ;IACR,OAAO;IACP,QAAQ;IACR,SAAS;IACT,WAAW;IACX,KAAK;IACL,MAAM;IACN,MAAM;IACN,UA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,CAAC,IAAI,EAAE,QAAQ,CAAC;YAChB,CAAC,GAAG,EAAE,EAAC,KAAK,EAAE,QAAQ,EAAE,IAAI,EAAE,MAAM,EAAC,CAAC;SACvC;QACD,YAAY,EAAE;YACZ,CAAC,OAAO,EAAE,eAAe,CAAC;YAC1B,CAAC,IAAI,EAAE,eAAe,CAAC;YACvB,CAAC,GAAG,EAAE,EAAC,KAAK,EAAE,eAAe,EAAE,IAAI,EAAE,MAAM,EAAC,CAAC;SAC9C;QACD,kBAAkB,EAAE;YAClB,CAAC,IAAI,EAAE,EAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,sBAAsB,EAAC,CAAC;YACjE,CAAC,GAAG,EAAE,EAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,mBAAmB,EAAC,CAAC;SAC9D;QACD,mBAAmB,EAAE;YACnB,CAAC,QAAQ,EAAE,YAAY,CAAC;YACxB,CAAC,IAAI,EAAE,YAAY,CAAC;YACpB,CAAC,GAAG,EAAE,EAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAC,CAAC;SACjD;QACD,gBAAgB,EAAE;YAChB,CAAC,OAAO,EAAE,YAAY,CAAC;YACvB,CAAC,IAAI,EAAE,YAAY,CAAC;YACpB,CAAC,GAAG,EAAE,EAAC,KAAK,EAAE,kBAAkB,EAAE,IAAI,EAAE,MAAM,EAAC,CAAC;SACjD;QACD,MAAM,EAAE,EAAE;KACX;CACF,CAAC","sourcesContent":["/**\n * DuckDB SQL language constants for Monaco Editor\n */\n\n// DuckDB specific keywords\nexport const DUCKDB_KEYWORDS = [\n 'PRAGMA',\n 'RETURNING',\n 'QUALIFY',\n 'PIVOT',\n 'UNPIVOT',\n 'EXCLUDE',\n 'INCLUDE',\n 'WINDOW',\n 'FILTER',\n 'WITHIN',\n 'OVER',\n 'PARTITION',\n 'RANGE',\n 'ROWS',\n 'GROUPS',\n 'PRECEDING',\n 'FOLLOWING',\n 'CURRENT',\n 'ROW',\n 'TIES',\n 'OTHERS',\n 'EXCLUDE',\n 'RESPECT',\n 'NULLS',\n 'FIRST',\n 'LAST',\n 'MATERIALIZED',\n 'RECURSIVE',\n 'TEMPORARY',\n 'TEMP',\n 'UNLOGGED',\n 'GLOBAL',\n 'LOCAL',\n 'STORED',\n 'VIRTUAL',\n 'DELIMITED',\n 'CSV',\n 'JSON',\n 'COPY',\n 'DESCRIBE',\n 'EXPLAIN',\n 'SUMMARIZE',\n 'PROFILE',\n 'LOAD',\n 'INSTALL',\n 'FORCE',\n 'PARALLEL',\n 'SEQUENTIAL',\n 'PRAGMA',\n // Standard SQL keywords\n 'SELECT',\n 'FROM',\n 'WHERE',\n 'GROUP',\n 'BY',\n 'HAVING',\n 'ORDER',\n 'LIMIT',\n 'OFFSET',\n 'INSERT',\n 'INTO',\n 'VALUES',\n 'UPDATE',\n 'SET',\n 'DELETE',\n 'CREATE',\n 'ALTER',\n 'DROP',\n 'TABLE',\n 'VIEW',\n 'INDEX',\n 'TRIGGER',\n 'PROCEDURE',\n 'FUNCTION',\n 'DATABASE',\n 'SCHEMA',\n 'JOIN',\n 'INNER',\n 'LEFT',\n 'RIGHT',\n 'FULL',\n 'OUTER',\n 'CROSS',\n 'NATURAL',\n 'ON',\n 'USING',\n 'AND',\n 'OR',\n 'NOT',\n 'NULL',\n 'IS',\n 'IN',\n 'BETWEEN',\n 'LIKE',\n 'AS',\n 'CASE',\n 'WHEN',\n 'THEN',\n 'ELSE',\n 'END',\n 'DISTINCT',\n 'ALL',\n 'UNION',\n 'INTERSECT',\n 'EXCEPT',\n 'WITH',\n 'CAST',\n 'PRIMARY',\n 'KEY',\n 'FOREIGN',\n 'REFERENCES',\n 'CONSTRAINT',\n 'DEFAULT',\n 'CHECK',\n 'UNIQUE',\n 'INDEX',\n 'CASCADE',\n 'RESTRICT',\n 'ASC',\n 'DESC',\n 'IF',\n 'EXISTS',\n 'TRUE',\n 'FALSE',\n];\n\n// DuckDB functions\nexport const DUCKDB_FUNCTIONS = [\n // Aggregate functions\n 'ARRAY_AGG',\n 'AVG',\n 'BIT_AND',\n 'BIT_OR',\n 'BIT_XOR',\n 'COUNT',\n 'FIRST',\n 'LAST',\n 'LIST',\n 'MAX',\n 'MIN',\n 'STRING_AGG',\n 'SUM',\n 'MEDIAN',\n 'QUANTILE',\n 'APPROX_COUNT_DISTINCT',\n 'APPROX_QUANTILE',\n // Window functions\n 'ROW_NUMBER',\n 'RANK',\n 'DENSE_RANK',\n 'PERCENT_RANK',\n 'CUME_DIST',\n 'NTILE',\n 'LAG',\n 'LEAD',\n 'FIRST_VALUE',\n 'LAST_VALUE',\n 'NTH_VALUE',\n // Date functions\n 'AGE',\n 'DATE_PART',\n 'DATE_TRUNC',\n 'EXTRACT',\n 'GREATEST',\n 'LEAST',\n 'NOW',\n 'CURRENT_DATE',\n 'CURRENT_TIME',\n 'CURRENT_TIMESTAMP',\n 'EPOCH',\n 'STRFTIME',\n 'STRPTIME',\n 'TO_TIMESTAMP',\n // String functions\n 'CONCAT',\n 'LENGTH',\n 'LOWER',\n 'LPAD',\n 'LTRIM',\n 'REGEXP_MATCHES',\n 'REGEXP_REPLACE',\n 'REPEAT',\n 'REPLACE',\n 'REVERSE',\n 'RIGHT',\n 'RPAD',\n 'RTRIM',\n 'SPLIT',\n 'SUBSTRING',\n 'TRIM',\n 'UPPER',\n // Nested functions\n 'LIST_EXTRACT',\n 'LIST_ELEMENT',\n 'LIST_VALUE',\n 'STRUCT_EXTRACT',\n 'STRUCT_PACK',\n 'MAP',\n 'MAP_EXTRACT',\n // Math functions\n 'ABS',\n 'CEIL',\n 'CEILING',\n 'FLOOR',\n 'ROUND',\n 'SIGN',\n 'SQRT',\n 'CBRT',\n 'EXP',\n 'LN',\n 'LOG',\n 'POWER',\n 'MOD',\n 'RANDOM',\n 'SETSEED',\n 'ACOS',\n 'ASIN',\n 'ATAN',\n 'ATAN2',\n 'COS',\n 'COT',\n 'SIN',\n 'TAN',\n 'RADIANS',\n 'DEGREES',\n 'PI',\n // Other functions\n 'COALESCE',\n 'NULLIF',\n 'TYPEOF',\n 'CURRENT_SCHEMA',\n 'CURRENT_USER',\n 'HASH',\n 'UUID',\n 'CHAR_LENGTH',\n 'CHARACTER_LENGTH',\n 'POSITION',\n 'OVERLAY',\n 'CONCAT_WS',\n 'FORMAT',\n 'TO_CHAR',\n 'TO_DATE',\n 'TO_NUMBER',\n 'LOCALTIME',\n 'LOCALTIMESTAMP',\n 'JUSTIFY_DAYS',\n 'JUSTIFY_HOURS',\n 'JUSTIFY_INTERVAL',\n 'MAKE_DATE',\n 'MAKE_INTERVAL',\n 'MAKE_TIME',\n 'MAKE_TIMESTAMP',\n 'CLOCK_TIMESTAMP',\n 'STATEMENT_TIMESTAMP',\n 'TRANSACTION_TIMESTAMP',\n];\n\n// SQL operators\nexport const SQL_OPERATORS = [\n '+',\n '-',\n '*',\n '/',\n '%',\n '&',\n '|',\n '^',\n '=',\n '<>',\n '!=',\n '>',\n '>=',\n '<',\n '<=',\n '<<',\n '>>',\n '||',\n '::',\n '->>',\n '->',\n '~',\n '!',\n '@',\n];\n\n// SQL variables\nexport const SQL_VARIABLES = [\n '$1',\n '$2',\n '$3',\n '$4',\n '$5',\n '$6',\n '$7',\n '$8',\n '$9',\n];\n\n// SQL pseudo columns\nexport const SQL_PSEUDO_COLUMNS = [\n '$ACTION',\n '$IDENTITY',\n '$ROWGUID',\n '$PARTITION',\n];\n\n// SQL language configuration for Monaco Editor\nexport const SQL_LANGUAGE_CONFIGURATION = {\n defaultToken: '',\n tokenPostfix: '.sql',\n ignoreCase: true,\n\n brackets: [\n {open: '[', close: ']', token: 'delimiter.square'},\n {open: '(', close: ')', token: 'delimiter.parenthesis'},\n ],\n\n keywords: DUCKDB_KEYWORDS,\n operators: SQL_OPERATORS,\n builtinFunctions: DUCKDB_FUNCTIONS,\n builtinVariables: SQL_VARIABLES,\n pseudoColumns: SQL_PSEUDO_COLUMNS,\n\n tokenizer: {\n root: [\n {include: '@comments'},\n {include: '@whitespace'},\n {include: '@numbers'},\n {include: '@strings'},\n {include: '@complexIdentifiers'},\n {include: '@scopes'},\n [/[;,.]/, 'delimiter'],\n [/[()]/, '@brackets'],\n [\n /[\\w@#$]+/,\n {\n cases: {\n '@keywords': 'keyword',\n '@operators': 'operator',\n '@builtinFunctions': 'predefined',\n '@builtinVariables': 'predefined',\n '@pseudoColumns': 'predefined',\n '@default': 'identifier',\n },\n },\n ],\n [/[<>=!%&+\\-*/|~^]/, 'operator'],\n ],\n whitespace: [[/\\s+/, 'white']],\n comments: [\n [/--+.*/, 'comment'],\n [/\\/\\*/, {token: 'comment.quote', next: '@comment'}],\n ],\n comment: [\n [/[^*/]+/, 'comment'],\n [/\\*\\//, {token: 'comment.quote', next: '@pop'}],\n [/./, 'comment'],\n ],\n numbers: [\n [/0[xX][0-9a-fA-F]*/, 'number'],\n [/[$][+-]*\\d*(\\.\\d*)?/, 'number'],\n [/((\\d+(\\.\\d*)?)|(\\.\\d+))([eE][\\-+]?\\d+)?/, 'number'],\n ],\n strings: [\n [/'/, {token: 'string', next: '@string'}],\n [/\"/, {token: 'string.double', next: '@stringDouble'}],\n ],\n string: [\n [/[^']+/, 'string'],\n [/''/, 'string'],\n [/'/, {token: 'string', next: '@pop'}],\n ],\n stringDouble: [\n [/[^\"]+/, 'string.double'],\n [/\"\"/, 'string.double'],\n [/\"/, {token: 'string.double', next: '@pop'}],\n ],\n complexIdentifiers: [\n [/\\[/, {token: 'identifier.quote', next: '@bracketedIdentifier'}],\n [/\"/, {token: 'identifier.quote', next: '@quotedIdentifier'}],\n ],\n bracketedIdentifier: [\n [/[^\\]]+/, 'identifier'],\n [/]]/, 'identifier'],\n [/]/, {token: 'identifier.quote', next: '@pop'}],\n ],\n quotedIdentifier: [\n [/[^\"]+/, 'identifier'],\n [/\"\"/, 'identifier'],\n [/\"/, {token: 'identifier.quote', next: '@pop'}],\n ],\n scopes: [],\n },\n};\n"]}
|