@difizen/libro-cofine-editor-core 0.1.2
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/LICENSE +21 -0
- package/README.md +3 -0
- package/es/default-worker-contribution.d.ts +9 -0
- package/es/default-worker-contribution.d.ts.map +1 -0
- package/es/default-worker-contribution.js +32 -0
- package/es/e2-editor.d.ts +30 -0
- package/es/e2-editor.d.ts.map +1 -0
- package/es/e2-editor.js +131 -0
- package/es/editor-handler-registry.d.ts +12 -0
- package/es/editor-handler-registry.d.ts.map +1 -0
- package/es/editor-handler-registry.js +59 -0
- package/es/editor-provider.d.ts +15 -0
- package/es/editor-provider.d.ts.map +1 -0
- package/es/editor-provider.js +1 -0
- package/es/editor.worker.d.ts +2 -0
- package/es/editor.worker.d.ts.map +1 -0
- package/es/editor.worker.js +23 -0
- package/es/global.d.ts +7 -0
- package/es/index.d.ts +18 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +23 -0
- package/es/initialize-provider.d.ts +18 -0
- package/es/initialize-provider.d.ts.map +1 -0
- package/es/initialize-provider.js +120 -0
- package/es/mana-export.d.ts +4 -0
- package/es/mana-export.d.ts.map +1 -0
- package/es/mana-export.js +23 -0
- package/es/monaco-compability.esm.d.ts +4 -0
- package/es/monaco-compability.esm.d.ts.map +1 -0
- package/es/monaco-compability.esm.js +10 -0
- package/es/monaco-environment.d.ts +29 -0
- package/es/monaco-environment.d.ts.map +1 -0
- package/es/monaco-environment.js +276 -0
- package/es/monaco-loader.d.ts +22 -0
- package/es/monaco-loader.d.ts.map +1 -0
- package/es/monaco-loader.js +139 -0
- package/es/monaco-module.d.ts +5 -0
- package/es/monaco-module.d.ts.map +1 -0
- package/es/monaco-module.js +71 -0
- package/es/snippets-suggest-registry.d.ts +31 -0
- package/es/snippets-suggest-registry.d.ts.map +1 -0
- package/es/snippets-suggest-registry.js +110 -0
- package/es/theme-registry.d.ts +58 -0
- package/es/theme-registry.d.ts.map +1 -0
- package/es/theme-registry.js +91 -0
- package/package.json +64 -0
- package/src/default-worker-contribution.ts +25 -0
- package/src/e2-editor.ts +161 -0
- package/src/editor-handler-registry.ts +47 -0
- package/src/editor-provider.ts +29 -0
- package/src/editor.worker.ts +25 -0
- package/src/global.d.ts +7 -0
- package/src/index.spec.ts +8 -0
- package/src/index.ts +46 -0
- package/src/initialize-provider.ts +54 -0
- package/src/mana-export.ts +8 -0
- package/src/monaco-compability.esm.ts +4 -0
- package/src/monaco-environment.ts +115 -0
- package/src/monaco-loader.ts +100 -0
- package/src/monaco-module.ts +101 -0
- package/src/snippets-suggest-registry.ts +101 -0
- package/src/theme-registry.ts +116 -0
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
import type { Contribution } from '@difizen/mana-app';
|
|
2
|
+
import { contrib, inject, singleton, Syringe } from '@difizen/mana-app';
|
|
3
|
+
import * as monaco from '@difizen/monaco-editor-core';
|
|
4
|
+
|
|
5
|
+
import { InitializeContribution } from './initialize-provider.js';
|
|
6
|
+
|
|
7
|
+
export const ThemeContribution = Syringe.defineToken('ThemeContribution');
|
|
8
|
+
|
|
9
|
+
export interface ITextmateThemeSetting {
|
|
10
|
+
colors: Record<string, string>;
|
|
11
|
+
tokenColors: IRawThemeSetting[];
|
|
12
|
+
include?: string;
|
|
13
|
+
name: string;
|
|
14
|
+
givenName?: string;
|
|
15
|
+
base?: monaco.editor.BuiltinTheme;
|
|
16
|
+
givenBase?: string;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export interface ThemeContribution {
|
|
20
|
+
registerItem: (registry: ThemeRegistry) => void;
|
|
21
|
+
_registerFinish?: boolean;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* A single theme setting.
|
|
26
|
+
*/
|
|
27
|
+
export interface IRawThemeSetting {
|
|
28
|
+
readonly name?: string;
|
|
29
|
+
readonly scope?: string | string[];
|
|
30
|
+
readonly settings: {
|
|
31
|
+
readonly fontStyle?: string;
|
|
32
|
+
readonly foreground?: string;
|
|
33
|
+
readonly background?: string;
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* A TextMate theme.
|
|
39
|
+
*/
|
|
40
|
+
export interface IRawTheme {
|
|
41
|
+
readonly name?: string;
|
|
42
|
+
readonly settings: IRawThemeSetting[];
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
export interface MixedTheme extends IRawTheme, monaco.editor.IStandaloneThemeData {}
|
|
46
|
+
|
|
47
|
+
export interface MixedThemeRegistry {
|
|
48
|
+
registerThemes: (
|
|
49
|
+
themeOptions: Record<string, ITextmateThemeSetting>,
|
|
50
|
+
setTheme: (name: string, data: monaco.editor.IStandaloneThemeData) => void,
|
|
51
|
+
) => void;
|
|
52
|
+
}
|
|
53
|
+
export const MixedThemeRegistry = Symbol('MixedThemeRegistry');
|
|
54
|
+
@singleton({ contrib: InitializeContribution })
|
|
55
|
+
export class ThemeRegistry implements InitializeContribution {
|
|
56
|
+
contributions: ThemeContribution[];
|
|
57
|
+
themeOptions: Record<string, ITextmateThemeSetting> = {};
|
|
58
|
+
themes: Map<string, MixedTheme | monaco.editor.IStandaloneThemeData> = new Map();
|
|
59
|
+
awaysInitialized = true;
|
|
60
|
+
|
|
61
|
+
onInitialize() {
|
|
62
|
+
this.provider.getContributions({ cache: false }).forEach((item) => {
|
|
63
|
+
if (item._registerFinish) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
item.registerItem(this);
|
|
67
|
+
item._registerFinish = true;
|
|
68
|
+
});
|
|
69
|
+
if (this.mixedThemeEnable) {
|
|
70
|
+
this.mixedThemeRegistry.registerThemes(
|
|
71
|
+
this.themeOptions,
|
|
72
|
+
this.setTheme.bind(this),
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
protected readonly provider: Contribution.Provider<ThemeContribution>;
|
|
77
|
+
protected readonly mixedThemeRegistry: MixedThemeRegistry;
|
|
78
|
+
constructor(
|
|
79
|
+
@contrib(ThemeContribution) provider: Contribution.Provider<ThemeContribution>,
|
|
80
|
+
@inject(MixedThemeRegistry) mixedThemeRegistry: MixedThemeRegistry,
|
|
81
|
+
) {
|
|
82
|
+
this.provider = provider;
|
|
83
|
+
this.mixedThemeRegistry = mixedThemeRegistry;
|
|
84
|
+
this.contributions = this.provider.getContributions();
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
get mixedThemeEnable(): boolean {
|
|
88
|
+
return !!(this.mixedThemeRegistry && this.mixedThemeRegistry.registerThemes);
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
setTheme(name: string, data: monaco.editor.IStandaloneThemeData): void {
|
|
92
|
+
try {
|
|
93
|
+
this.themes.set(name, data);
|
|
94
|
+
// monaco auto refreshes a theme with new data
|
|
95
|
+
monaco.editor.defineTheme(name, data);
|
|
96
|
+
} catch (ex) {
|
|
97
|
+
console.error(ex);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
registerMonacoTheme(
|
|
102
|
+
setting: monaco.editor.IStandaloneThemeData,
|
|
103
|
+
name: string,
|
|
104
|
+
monacoBase?: monaco.editor.BuiltinTheme,
|
|
105
|
+
): void {
|
|
106
|
+
this.setTheme(name, { ...setting, base: monacoBase || setting.base || 'vs' });
|
|
107
|
+
}
|
|
108
|
+
registerMixedTheme(
|
|
109
|
+
setting: ITextmateThemeSetting,
|
|
110
|
+
givenName: string,
|
|
111
|
+
givenBase?: monaco.editor.BuiltinTheme,
|
|
112
|
+
): void {
|
|
113
|
+
const name = givenName || setting.name;
|
|
114
|
+
this.themeOptions[givenName] = { ...setting, givenName, name, base: givenBase };
|
|
115
|
+
}
|
|
116
|
+
}
|