@sqlrooms/monaco-editor 0.26.0-rc.2 → 0.26.0-rc.4
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 +17 -12
- package/dist/components/MonacoEditor.d.ts.map +1 -1
- package/dist/components/MonacoEditor.js +3 -5
- package/dist/components/MonacoEditor.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/loader.d.ts +45 -2
- package/dist/loader.d.ts.map +1 -1
- package/dist/loader.js +50 -4
- package/dist/loader.js.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -59,25 +59,20 @@ function MyJsonEditor() {
|
|
|
59
59
|
}
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
###
|
|
62
|
+
### Offline Use and Bundling
|
|
63
63
|
|
|
64
|
-
By default, the editor loads
|
|
65
|
-
offline environment, you need to bundle `monaco-editor` with your application.
|
|
66
|
-
You can do this with the `configureMonacoLoader` utility. This function is a
|
|
67
|
-
thin wrapper around the [`loader.config` function](https://github.com/suren-atoyan/monaco-react#loader-config)
|
|
68
|
-
and sets up `self.MonacoEnvironment` automatically when web workers are passed.
|
|
64
|
+
By default, the editor loads from a CDN, which is SSR-friendly (works with Next.js) and reduces bundle size.
|
|
69
65
|
|
|
70
|
-
|
|
71
|
-
Vite (note the `?worker` suffix):
|
|
66
|
+
For offline environments (like PWAs), configure Monaco once at app startup:
|
|
72
67
|
|
|
73
68
|
```ts
|
|
69
|
+
// main.tsx or app entry point
|
|
74
70
|
import {configureMonacoLoader} from '@sqlrooms/monaco-editor';
|
|
75
71
|
import * as monaco from 'monaco-editor';
|
|
76
72
|
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
|
77
73
|
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
|
|
78
74
|
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
|
|
79
75
|
|
|
80
|
-
// Use the monaco-editor package instead of a CDN
|
|
81
76
|
configureMonacoLoader({
|
|
82
77
|
monaco,
|
|
83
78
|
workers: {
|
|
@@ -89,11 +84,21 @@ configureMonacoLoader({
|
|
|
89
84
|
});
|
|
90
85
|
```
|
|
91
86
|
|
|
92
|
-
|
|
93
|
-
|
|
87
|
+
Now all `<MonacoEditor />` components automatically work offline:
|
|
88
|
+
|
|
89
|
+
```tsx
|
|
90
|
+
// No configuration needed - automatically detected!
|
|
91
|
+
<MonacoEditor language="javascript" value="// Works offline!" />
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
**Note:** Vite requires the `?worker` suffix on worker imports. This is a thin wrapper around the [`loader.config` function](https://github.com/suren-atoyan/monaco-react#loader-config).
|
|
95
|
+
|
|
96
|
+
#### Custom CDN path
|
|
97
|
+
|
|
98
|
+
You can also specify a custom CDN path:
|
|
94
99
|
|
|
95
100
|
```ts
|
|
96
|
-
|
|
101
|
+
configureMonacoLoader({paths: {vs: 'https://unpkg.com/monaco-editor/min/vs'}});
|
|
97
102
|
```
|
|
98
103
|
|
|
99
104
|
## Props
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MonacoEditor.d.ts","sourceRoot":"","sources":["../../src/components/MonacoEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"MonacoEditor.d.ts","sourceRoot":"","sources":["../../src/components/MonacoEditor.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAS,WAAW,EAAE,QAAQ,EAAE,OAAO,EAAC,MAAM,sBAAsB,CAAC;AAE5E,OAAO,KAA0B,MAAM,OAAO,CAAC;AAO/C,OAAO,KAAK,KAAK,MAAM,MAAM,eAAe,CAAC;AAE7C,MAAM,WAAW,iBAAkB,SAAQ,IAAI,CAAC,WAAW,EAAE,SAAS,CAAC;IACrE;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB;;OAEG;IACH,QAAQ,CAAC,EAAE,QAAQ,CAAC;IACpB;;;OAGG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB;;;;OAIG;IACH,KAAK,CAAC,EAAE,SAAS,GAAG,OAAO,CAAC;IAC5B;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;OAEG;IACH,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,CAAC,oCAAoC,CAAC;CAC9D;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CAkNpD,CAAC"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { Editor } from '@monaco-editor/react';
|
|
3
|
-
import { ensureMonacoLoaderConfigured } from '../loader';
|
|
4
3
|
import { Spinner, cn, useTheme } from '@sqlrooms/ui';
|
|
5
4
|
import React, { useEffect, useRef } from 'react';
|
|
6
5
|
import { getCssColor, getJsonEditorTheme, getMenuColors, getMonospaceFont, } from '../utils/color-utils';
|
|
@@ -8,15 +7,14 @@ import { getCssColor, getJsonEditorTheme, getMenuColors, getMonospaceFont, } fro
|
|
|
8
7
|
* A wrapper around the Monaco Editor component
|
|
9
8
|
*/
|
|
10
9
|
export const MonacoEditor = ({ className, language = 'javascript', theme: explicitTheme, value = '', readOnly = false, onMount, onChange, options = {}, ...props }) => {
|
|
11
|
-
// Ensure the loader is configured before the editor mounts
|
|
12
|
-
ensureMonacoLoaderConfigured();
|
|
13
|
-
// Get the app theme from the ThemeProvider
|
|
14
10
|
const { theme: appTheme } = useTheme();
|
|
15
11
|
const [renderKey, setRenderKey] = React.useState(0);
|
|
16
|
-
//
|
|
12
|
+
// Determine editor theme based on app theme
|
|
13
|
+
// Use typeof window check to avoid SSR errors in Next.js when accessing window.matchMedia
|
|
17
14
|
const theme = explicitTheme ||
|
|
18
15
|
(appTheme === 'dark' ||
|
|
19
16
|
(appTheme === 'system' &&
|
|
17
|
+
typeof window !== 'undefined' &&
|
|
20
18
|
window.matchMedia('(prefers-color-scheme: dark)').matches)
|
|
21
19
|
? 'vs-dark'
|
|
22
20
|
: 'light');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MonacoEditor.js","sourceRoot":"","sources":["../../src/components/MonacoEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAiC,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAC,4BAA4B,EAAC,MAAM,WAAW,CAAC;AACvD,OAAO,EAAC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC;AACnD,OAAO,KAAK,EAAE,EAAC,SAAS,EAAE,MAAM,EAAC,MAAM,OAAO,CAAC;AAC/C,OAAO,EACL,WAAW,EACX,kBAAkB,EAClB,aAAa,EACb,gBAAgB,GACjB,MAAM,sBAAsB,CAAC;AA2C9B;;GAEG;AACH,MAAM,CAAC,MAAM,YAAY,GAAgC,CAAC,EACxD,SAAS,EACT,QAAQ,GAAG,YAAY,EACvB,KAAK,EAAE,aAAa,EACpB,KAAK,GAAG,EAAE,EACV,QAAQ,GAAG,KAAK,EAChB,OAAO,EACP,QAAQ,EACR,OAAO,GAAG,EAAE,EACZ,GAAG,KAAK,EACT,EAAE,EAAE;IACH,2DAA2D;IAC3D,4BAA4B,EAAE,CAAC;IAC/B,2CAA2C;IAC3C,MAAM,EAAC,KAAK,EAAE,QAAQ,EAAC,GAAG,QAAQ,EAAE,CAAC;IACrC,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC;IAEpD,qFAAqF;IACrF,MAAM,KAAK,GAC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,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,KAEhB,KAAK,IADJ,SAAS,CAEd,GACE,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {Editor, EditorProps, OnChange, OnMount} from '@monaco-editor/react';\nimport {ensureMonacoLoaderConfigured} from '../loader';\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';\nimport type * as Monaco from 'monaco-editor';\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?: Monaco.editor.IStandaloneEditorConstructionOptions;\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 // Ensure the loader is configured before the editor mounts\n ensureMonacoLoaderConfigured();\n // Get the app theme from the ThemeProvider\n const {theme: appTheme} = useTheme();\n const [renderKey, setRenderKey] = React.useState(0);\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 // Force re-render to apply the new theme\n setRenderKey((key) => key + 1);\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 // Force re-render to apply the new theme\n setRenderKey((key) => key + 1);\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 key={renderKey}\n {...props}\n />\n </div>\n );\n};\n"]}
|
|
1
|
+
{"version":3,"file":"MonacoEditor.js","sourceRoot":"","sources":["../../src/components/MonacoEditor.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAC,MAAM,EAAiC,MAAM,sBAAsB,CAAC;AAC5E,OAAO,EAAC,OAAO,EAAE,EAAE,EAAE,QAAQ,EAAC,MAAM,cAAc,CAAC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AAE,KAAC,OAAO,KAAG,KAEhB,KAAK,IADJ,SAAS,CAEd,GACE,CACP,CAAC;AACJ,CAAC,CAAC","sourcesContent":["import {Editor, EditorProps, OnChange, OnMount} 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';\nimport type * as Monaco from 'monaco-editor';\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?: Monaco.editor.IStandaloneEditorConstructionOptions;\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 const {theme: appTheme} = useTheme();\n const [renderKey, setRenderKey] = React.useState(0);\n\n // Determine editor theme based on app theme\n // Use typeof window check to avoid SSR errors in Next.js when accessing window.matchMedia\n const theme =\n explicitTheme ||\n (appTheme === 'dark' ||\n (appTheme === 'system' &&\n typeof window !== 'undefined' &&\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 // Force re-render to apply the new theme\n setRenderKey((key) => key + 1);\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 // Force re-render to apply the new theme\n setRenderKey((key) => key + 1);\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 key={renderKey}\n {...props}\n />\n </div>\n );\n};\n"]}
|
package/dist/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
export { MonacoEditor } from './components/MonacoEditor';
|
|
6
6
|
export type { MonacoEditorProps } from './components/MonacoEditor';
|
|
7
|
-
export { configureMonacoLoader, type LoaderConfig, type MonacoLoaderOptions, type LoaderWorkers,
|
|
7
|
+
export { configureMonacoLoader, isMonacoLoaderConfigured, ensureMonacoLoaderConfigured, type LoaderConfig, type MonacoLoaderOptions, type LoaderWorkers, } from './loader';
|
|
8
8
|
export { JsonMonacoEditor } from './components/JsonMonacoEditor';
|
|
9
9
|
export type { JsonMonacoEditorProps } from './components/JsonMonacoEditor';
|
|
10
10
|
export { getCssColor, hslToHex, getMonospaceFont } from './utils/color-utils';
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AACvD,YAAY,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EACL,qBAAqB,EACrB,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,aAAa,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AACvD,YAAY,EAAC,iBAAiB,EAAC,MAAM,2BAA2B,CAAC;AAEjE,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,4BAA4B,EAC5B,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACxB,KAAK,aAAa,GACnB,MAAM,UAAU,CAAC;AAElB,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAC/D,YAAY,EAAC,qBAAqB,EAAC,MAAM,+BAA+B,CAAC;AAGzE,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAC,MAAM,qBAAqB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* @packageDocumentation
|
|
4
4
|
*/
|
|
5
5
|
export { MonacoEditor } from './components/MonacoEditor';
|
|
6
|
-
export { configureMonacoLoader,
|
|
6
|
+
export { configureMonacoLoader, isMonacoLoaderConfigured, ensureMonacoLoaderConfigured, } from './loader';
|
|
7
7
|
export { JsonMonacoEditor } from './components/JsonMonacoEditor';
|
|
8
8
|
// Export utility functions
|
|
9
9
|
export { getCssColor, hslToHex, getMonospaceFont } from './utils/color-utils';
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAGvD,OAAO,EACL,qBAAqB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAC,YAAY,EAAC,MAAM,2BAA2B,CAAC;AAGvD,OAAO,EACL,qBAAqB,EACrB,wBAAwB,EACxB,4BAA4B,GAI7B,MAAM,UAAU,CAAC;AAElB,OAAO,EAAC,gBAAgB,EAAC,MAAM,+BAA+B,CAAC;AAG/D,2BAA2B;AAC3B,OAAO,EAAC,WAAW,EAAE,QAAQ,EAAE,gBAAgB,EAAC,MAAM,qBAAqB,CAAC","sourcesContent":["/**\n * {@include ../README.md}\n * @packageDocumentation\n */\n\nexport {MonacoEditor} from './components/MonacoEditor';\nexport type {MonacoEditorProps} from './components/MonacoEditor';\n\nexport {\n configureMonacoLoader,\n isMonacoLoaderConfigured,\n ensureMonacoLoaderConfigured,\n type LoaderConfig,\n type MonacoLoaderOptions,\n type LoaderWorkers,\n} from './loader';\n\nexport {JsonMonacoEditor} from './components/JsonMonacoEditor';\nexport type {JsonMonacoEditorProps} from './components/JsonMonacoEditor';\n\n// Export utility functions\nexport {getCssColor, hslToHex, getMonospaceFont} from './utils/color-utils';\n"]}
|
package/dist/loader.d.ts
CHANGED
|
@@ -8,7 +8,6 @@ export interface LoaderWorkers {
|
|
|
8
8
|
new (): Worker;
|
|
9
9
|
} | undefined;
|
|
10
10
|
}
|
|
11
|
-
export declare const DEFAULT_CDN_PATH = "https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs";
|
|
12
11
|
export type LoaderConfig = Parameters<typeof loader.config>[0];
|
|
13
12
|
export interface MonacoLoaderOptions extends LoaderConfig {
|
|
14
13
|
/**
|
|
@@ -21,6 +20,50 @@ export interface MonacoLoaderOptions extends LoaderConfig {
|
|
|
21
20
|
*/
|
|
22
21
|
workers?: LoaderWorkers;
|
|
23
22
|
}
|
|
23
|
+
/**
|
|
24
|
+
* Checks if the Monaco loader has been configured for bundling.
|
|
25
|
+
* When true, Monaco is bundled with the app instead of loaded from CDN.
|
|
26
|
+
*/
|
|
27
|
+
export declare function isMonacoLoaderConfigured(): boolean;
|
|
28
|
+
/**
|
|
29
|
+
* Configures the Monaco loader for bundling Monaco with your application.
|
|
30
|
+
* Call this once at app startup to enable offline use across all editor components.
|
|
31
|
+
*
|
|
32
|
+
* After calling this, all MonacoEditor components will automatically use the bundled version
|
|
33
|
+
* without needing the `bundleMonaco` prop.
|
|
34
|
+
*
|
|
35
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* import {configureMonacoLoader} from '@sqlrooms/monaco-editor';
|
|
38
|
+
* import * as monaco from 'monaco-editor';
|
|
39
|
+
* import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
|
40
|
+
*
|
|
41
|
+
* configureMonacoLoader({
|
|
42
|
+
* monaco,
|
|
43
|
+
* workers: { default: editorWorker }
|
|
44
|
+
* });
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
24
47
|
export declare function configureMonacoLoader(options: MonacoLoaderOptions): void;
|
|
25
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Dynamically imports and configures Monaco for bundling (SSR-safe).
|
|
50
|
+
*
|
|
51
|
+
* @internal
|
|
52
|
+
* This is an advanced utility that most users don't need.
|
|
53
|
+
* Use `configureMonacoLoader()` at app startup instead for better control.
|
|
54
|
+
*
|
|
55
|
+
* This function:
|
|
56
|
+
* - Only runs on the client side (checks typeof window)
|
|
57
|
+
* - Dynamically imports monaco-editor to avoid SSR issues in Next.js
|
|
58
|
+
* - Automatically configures the loader with the imported Monaco instance
|
|
59
|
+
*
|
|
60
|
+
* When to use:
|
|
61
|
+
* - You need Monaco bundled but can't call configureMonacoLoader at app startup
|
|
62
|
+
* - You're working in an environment where top-level imports of monaco-editor fail
|
|
63
|
+
*
|
|
64
|
+
* When NOT to use:
|
|
65
|
+
* - For normal bundling, use `configureMonacoLoader()` at app startup
|
|
66
|
+
* - For CDN loading, just use the component - no configuration needed
|
|
67
|
+
*/
|
|
68
|
+
export declare function ensureMonacoLoaderConfigured(): Promise<void>;
|
|
26
69
|
//# sourceMappingURL=loader.d.ts.map
|
package/dist/loader.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,OAAO,CAAC,EAAE;QAAC,QAAQ,MAAM,CAAA;KAAC,CAAC;IAC3B,CAAC,KAAK,EAAE,MAAM,GAAG;QAAC,QAAQ,MAAM,CAAA;KAAC,GAAG,SAAS,CAAC;CAC/C;AAED,
|
|
1
|
+
{"version":3,"file":"loader.d.ts","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAE5C,MAAM,WAAW,aAAa;IAC5B,0DAA0D;IAC1D,OAAO,CAAC,EAAE;QAAC,QAAQ,MAAM,CAAA;KAAC,CAAC;IAC3B,CAAC,KAAK,EAAE,MAAM,GAAG;QAAC,QAAQ,MAAM,CAAA;KAAC,GAAG,SAAS,CAAC;CAC/C;AAED,MAAM,MAAM,YAAY,GAAG,UAAU,CAAC,OAAO,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC;AAE/D,MAAM,WAAW,mBAAoB,SAAQ,YAAY;IACvD;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAC;IACb;;;OAGG;IACH,OAAO,CAAC,EAAE,aAAa,CAAC;CACzB;AAID;;;GAGG;AACH,wBAAgB,wBAAwB,IAAI,OAAO,CAElD;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,qBAAqB,CAAC,OAAO,EAAE,mBAAmB,QAcjE;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAsB,4BAA4B,kBAMjD"}
|
package/dist/loader.js
CHANGED
|
@@ -1,6 +1,31 @@
|
|
|
1
1
|
import { loader } from '@monaco-editor/react';
|
|
2
|
-
export const DEFAULT_CDN_PATH = 'https://cdn.jsdelivr.net/npm/monaco-editor@0.45.0/min/vs';
|
|
3
2
|
let configured = false;
|
|
3
|
+
/**
|
|
4
|
+
* Checks if the Monaco loader has been configured for bundling.
|
|
5
|
+
* When true, Monaco is bundled with the app instead of loaded from CDN.
|
|
6
|
+
*/
|
|
7
|
+
export function isMonacoLoaderConfigured() {
|
|
8
|
+
return configured;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* Configures the Monaco loader for bundling Monaco with your application.
|
|
12
|
+
* Call this once at app startup to enable offline use across all editor components.
|
|
13
|
+
*
|
|
14
|
+
* After calling this, all MonacoEditor components will automatically use the bundled version
|
|
15
|
+
* without needing the `bundleMonaco` prop.
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```ts
|
|
19
|
+
* import {configureMonacoLoader} from '@sqlrooms/monaco-editor';
|
|
20
|
+
* import * as monaco from 'monaco-editor';
|
|
21
|
+
* import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
|
22
|
+
*
|
|
23
|
+
* configureMonacoLoader({
|
|
24
|
+
* monaco,
|
|
25
|
+
* workers: { default: editorWorker }
|
|
26
|
+
* });
|
|
27
|
+
* ```
|
|
28
|
+
*/
|
|
4
29
|
export function configureMonacoLoader(options) {
|
|
5
30
|
const { workers, ...config } = options;
|
|
6
31
|
loader.config(config);
|
|
@@ -14,9 +39,30 @@ export function configureMonacoLoader(options) {
|
|
|
14
39
|
}
|
|
15
40
|
configured = true;
|
|
16
41
|
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
42
|
+
/**
|
|
43
|
+
* Dynamically imports and configures Monaco for bundling (SSR-safe).
|
|
44
|
+
*
|
|
45
|
+
* @internal
|
|
46
|
+
* This is an advanced utility that most users don't need.
|
|
47
|
+
* Use `configureMonacoLoader()` at app startup instead for better control.
|
|
48
|
+
*
|
|
49
|
+
* This function:
|
|
50
|
+
* - Only runs on the client side (checks typeof window)
|
|
51
|
+
* - Dynamically imports monaco-editor to avoid SSR issues in Next.js
|
|
52
|
+
* - Automatically configures the loader with the imported Monaco instance
|
|
53
|
+
*
|
|
54
|
+
* When to use:
|
|
55
|
+
* - You need Monaco bundled but can't call configureMonacoLoader at app startup
|
|
56
|
+
* - You're working in an environment where top-level imports of monaco-editor fail
|
|
57
|
+
*
|
|
58
|
+
* When NOT to use:
|
|
59
|
+
* - For normal bundling, use `configureMonacoLoader()` at app startup
|
|
60
|
+
* - For CDN loading, just use the component - no configuration needed
|
|
61
|
+
*/
|
|
62
|
+
export async function ensureMonacoLoaderConfigured() {
|
|
63
|
+
if (!configured && typeof window !== 'undefined') {
|
|
64
|
+
const Monaco = await import('monaco-editor');
|
|
65
|
+
loader.config({ monaco: Monaco });
|
|
20
66
|
configured = true;
|
|
21
67
|
}
|
|
22
68
|
}
|
package/dist/loader.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"loader.js","sourceRoot":"","sources":["../src/loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,MAAM,EAAC,MAAM,sBAAsB,CAAC;AAsB5C,IAAI,UAAU,GAAG,KAAK,CAAC;AAEvB;;;GAGG;AACH,MAAM,UAAU,wBAAwB;IACtC,OAAO,UAAU,CAAC;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,qBAAqB,CAAC,OAA4B;IAChE,MAAM,EAAC,OAAO,EAAE,GAAG,MAAM,EAAC,GAAG,OAAO,CAAC;IACrC,MAAM,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;IAEtB,IAAI,OAAO,EAAE,CAAC;QACZ,IAAI,CAAC,iBAAiB,GAAG;YACvB,SAAS,CAAC,CAAU,EAAE,KAAa;gBACjC,MAAM,UAAU,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,OAAO,CAAC,OAAO,IAAI,SAAS,CAAC;gBAClE,OAAO,UAAU,CAAC,CAAC,CAAC,IAAI,UAAU,EAAE,CAAC,CAAC,CAAE,SAAiB,CAAC;YAC5D,CAAC;SACK,CAAC;IACX,CAAC;IAED,UAAU,GAAG,IAAI,CAAC;AACpB,CAAC;AAED;;;;;;;;;;;;;;;;;;;GAmBG;AACH,MAAM,CAAC,KAAK,UAAU,4BAA4B;IAChD,IAAI,CAAC,UAAU,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACjD,MAAM,MAAM,GAAG,MAAM,MAAM,CAAC,eAAe,CAAC,CAAC;QAC7C,MAAM,CAAC,MAAM,CAAC,EAAC,MAAM,EAAE,MAAM,EAAC,CAAC,CAAC;QAChC,UAAU,GAAG,IAAI,CAAC;IACpB,CAAC;AACH,CAAC","sourcesContent":["import {loader} from '@monaco-editor/react';\n\nexport interface LoaderWorkers {\n /** worker used when label does not match other workers */\n default?: {new (): Worker};\n [label: string]: {new (): Worker} | undefined;\n}\n\nexport type LoaderConfig = Parameters<typeof loader.config>[0];\n\nexport interface MonacoLoaderOptions extends LoaderConfig {\n /**\n * Pass the Monaco instance to bundle the editor instead of using a CDN\n */\n monaco?: any;\n /**\n * Provide worker constructors mapped by label to automatically set\n * `self.MonacoEnvironment.getWorker`\n */\n workers?: LoaderWorkers;\n}\n\nlet configured = false;\n\n/**\n * Checks if the Monaco loader has been configured for bundling.\n * When true, Monaco is bundled with the app instead of loaded from CDN.\n */\nexport function isMonacoLoaderConfigured(): boolean {\n return configured;\n}\n\n/**\n * Configures the Monaco loader for bundling Monaco with your application.\n * Call this once at app startup to enable offline use across all editor components.\n *\n * After calling this, all MonacoEditor components will automatically use the bundled version\n * without needing the `bundleMonaco` prop.\n *\n * @example\n * ```ts\n * import {configureMonacoLoader} from '@sqlrooms/monaco-editor';\n * import * as monaco from 'monaco-editor';\n * import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';\n *\n * configureMonacoLoader({\n * monaco,\n * workers: { default: editorWorker }\n * });\n * ```\n */\nexport function configureMonacoLoader(options: MonacoLoaderOptions) {\n const {workers, ...config} = options;\n loader.config(config);\n\n if (workers) {\n self.MonacoEnvironment = {\n getWorker(_: unknown, label: string) {\n const WorkerCtor = workers[label] || workers.default || undefined;\n return WorkerCtor ? new WorkerCtor() : (undefined as any);\n },\n } as any;\n }\n\n configured = true;\n}\n\n/**\n * Dynamically imports and configures Monaco for bundling (SSR-safe).\n *\n * @internal\n * This is an advanced utility that most users don't need.\n * Use `configureMonacoLoader()` at app startup instead for better control.\n *\n * This function:\n * - Only runs on the client side (checks typeof window)\n * - Dynamically imports monaco-editor to avoid SSR issues in Next.js\n * - Automatically configures the loader with the imported Monaco instance\n *\n * When to use:\n * - You need Monaco bundled but can't call configureMonacoLoader at app startup\n * - You're working in an environment where top-level imports of monaco-editor fail\n *\n * When NOT to use:\n * - For normal bundling, use `configureMonacoLoader()` at app startup\n * - For CDN loading, just use the component - no configuration needed\n */\nexport async function ensureMonacoLoaderConfigured() {\n if (!configured && typeof window !== 'undefined') {\n const Monaco = await import('monaco-editor');\n loader.config({monaco: Monaco});\n configured = true;\n }\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sqlrooms/monaco-editor",
|
|
3
|
-
"version": "0.26.0-rc.
|
|
3
|
+
"version": "0.26.0-rc.4",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
},
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@monaco-editor/react": "^4.7.0",
|
|
22
|
-
"@sqlrooms/ui": "0.26.0-rc.
|
|
22
|
+
"@sqlrooms/ui": "0.26.0-rc.4",
|
|
23
23
|
"monaco-editor": "^0.52.2"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
@@ -33,5 +33,5 @@
|
|
|
33
33
|
"typecheck": "tsc --noEmit",
|
|
34
34
|
"typedoc": "typedoc"
|
|
35
35
|
},
|
|
36
|
-
"gitHead": "
|
|
36
|
+
"gitHead": "9e23926085d8852178792d6d98d8091e9a5f71d5"
|
|
37
37
|
}
|