Skip to content

Commit

Permalink
export all of monaco
Browse files Browse the repository at this point in the history
  • Loading branch information
George-Payne committed Apr 16, 2024
1 parent ba9a670 commit d657009
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 16 deletions.
28 changes: 24 additions & 4 deletions packages/editor/monaco.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,24 @@
const MONACO_EDITOR = Symbol.for('monaco-editor');
const MONACO_LANGUAGES = Symbol.for('monaco-languages');
export const editor = window[MONACO_EDITOR];
export const languages = window[MONACO_LANGUAGES];
const MONACO = Symbol.for('monaco');

export const {
// namespaces
editor,
languages,
worker,

// enums
KeyCode,
MarkerSeverity,
MarkerTag,
SelectionDirection,

// classes
CancellationTokenSource,
Emitter,
KeyMod,
Position,
Range,
Selection,
Token,
Uri,
} = window[MONACO];
23 changes: 11 additions & 12 deletions packages/editor/utils/initialize.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import { editor, languages, type Environment } from 'monaco-editor';
import * as monaco from 'monaco-editor';
import { theme } from '@eventstore-ui/theme';
import {
ES_DARK,
ES_HIGH_CONTRAST_DARK,
ES_HIGH_CONTRAST_LIGHT,
} from './themes';

const MONACO = Symbol.for('monaco');
const MONACO_EDITOR = Symbol.for('monaco-editor');
const MONACO_LANGUAGES = Symbol.for('monaco-languages');

declare global {
interface Window {
MonacoEnvironment: Environment;
[MONACO_EDITOR]: typeof editor;
[MONACO_LANGUAGES]: typeof languages;
MonacoEnvironment: monaco.Environment;
[MONACO]: typeof monaco;
[MONACO_EDITOR]: typeof monaco.editor;
}
}

Expand All @@ -22,7 +22,7 @@ declare global {
* By default it will set getWorkerUrl to return `/workers/<name>.worker.js`
*/
export const initialize = (
environment: Environment = {
environment: monaco.Environment = {
getWorkerUrl(_moduleId: any, label: string) {
if (label === 'json') {
return '/workers/json.worker.js';
Expand All @@ -44,19 +44,18 @@ export const initialize = (
},
},
) => {
self[MONACO_EDITOR] = editor;
self[MONACO_LANGUAGES] = languages;
self[MONACO] = monaco;
self.MonacoEnvironment = environment;

theme.onThemeChange(({ meta: { contrast, shade } }) => {
if (contrast === 'high' && shade === 'dark') {
editor.setTheme(ES_HIGH_CONTRAST_DARK);
monaco.editor.setTheme(ES_HIGH_CONTRAST_DARK);
} else if (contrast === 'high' && shade === 'light') {
editor.setTheme(ES_HIGH_CONTRAST_LIGHT);
monaco.editor.setTheme(ES_HIGH_CONTRAST_LIGHT);
} else if (shade === 'dark') {
editor.setTheme(ES_DARK);
monaco.editor.setTheme(ES_DARK);
} else {
editor.setTheme('vs');
monaco.editor.setTheme('vs');
}
}, true);
};
Expand Down

0 comments on commit d657009

Please sign in to comment.