@vmz/plugin-monaco 0.2.2 → 0.2.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/components/Monaco.vmz +143 -140
- package/package.json +2 -2
package/components/Monaco.vmz
CHANGED
|
@@ -1,184 +1,187 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
|
|
2
|
+
<div data-vmz-monaco class="monaco-host" />
|
|
3
3
|
</template>
|
|
4
|
-
|
|
5
4
|
<style>
|
|
6
5
|
/*
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
6
|
+
Isolate Monaco glyph metrics from page CSS.
|
|
7
|
+
Inherited letter-spacing / proportional fonts desync caret + selection overlays.
|
|
8
|
+
*/
|
|
10
9
|
.monaco-host {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
10
|
+
display: block;
|
|
11
|
+
width: 100%;
|
|
12
|
+
height: 100%;
|
|
13
|
+
min-height: 0;
|
|
14
|
+
overflow: hidden;
|
|
15
|
+
position: relative;
|
|
16
|
+
box-sizing: border-box;
|
|
17
|
+
font:
|
|
18
|
+
14px/21px Consolas,
|
|
19
|
+
"Courier New",
|
|
20
|
+
Menlo,
|
|
21
|
+
Monaco,
|
|
22
|
+
monospace !important;
|
|
23
|
+
letter-spacing: 0 !important;
|
|
24
|
+
word-spacing: 0 !important;
|
|
25
|
+
font-variant-ligatures: none !important;
|
|
26
|
+
text-rendering: auto;
|
|
27
|
+
-webkit-font-smoothing: antialiased;
|
|
24
28
|
}
|
|
25
29
|
.monaco-host .monaco-editor {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
width: 100% !important;
|
|
31
|
+
height: 100% !important;
|
|
32
|
+
outline: none;
|
|
33
|
+
font-family: Consolas, "Courier New", Menlo, Monaco, monospace !important;
|
|
34
|
+
font-size: 14px !important;
|
|
35
|
+
line-height: 21px !important;
|
|
36
|
+
letter-spacing: 0 !important;
|
|
33
37
|
}
|
|
34
38
|
.monaco-host .monaco-editor .view-lines,
|
|
35
39
|
.monaco-host .monaco-editor .view-line,
|
|
36
40
|
.monaco-host .monaco-editor .view-line span,
|
|
37
41
|
.monaco-host .monaco-editor .margin-view-overlays,
|
|
38
42
|
.monaco-host .monaco-editor .lines-content {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
43
|
+
font-family: Consolas, "Courier New", Menlo, Monaco, monospace !important;
|
|
44
|
+
font-size: 14px !important;
|
|
45
|
+
line-height: 21px !important;
|
|
46
|
+
letter-spacing: 0 !important;
|
|
47
|
+
word-spacing: 0 !important;
|
|
44
48
|
}
|
|
45
49
|
/*
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*/
|
|
50
|
+
Keep the hidden textarea from painting native OS selection
|
|
51
|
+
(shows up as yellow boxes / black bands when metrics desync).
|
|
52
|
+
*/
|
|
49
53
|
.monaco-host .monaco-editor .inputarea,
|
|
50
54
|
.monaco-host .monaco-editor textarea.inputarea,
|
|
51
55
|
.monaco-host .monaco-editor .native-edit-context {
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
56
|
+
opacity: 0 !important;
|
|
57
|
+
color: transparent !important;
|
|
58
|
+
background: transparent !important;
|
|
59
|
+
caret-color: transparent !important;
|
|
60
|
+
outline: none !important;
|
|
61
|
+
box-shadow: none !important;
|
|
62
|
+
border: 0 !important;
|
|
63
|
+
-webkit-user-select: text;
|
|
64
|
+
user-select: text;
|
|
61
65
|
}
|
|
62
66
|
.monaco-host .monaco-editor .inputarea::selection,
|
|
63
67
|
.monaco-host .monaco-editor textarea.inputarea::selection,
|
|
64
68
|
.monaco-host .monaco-editor .native-edit-context::selection {
|
|
65
|
-
|
|
66
|
-
|
|
69
|
+
background: transparent !important;
|
|
70
|
+
color: transparent !important;
|
|
67
71
|
}
|
|
68
72
|
.monaco-host .monaco-editor .inputarea::-moz-selection,
|
|
69
73
|
.monaco-host .monaco-editor textarea.inputarea::-moz-selection,
|
|
70
74
|
.monaco-host .monaco-editor .native-edit-context::-moz-selection {
|
|
71
|
-
|
|
72
|
-
|
|
75
|
+
background: transparent !important;
|
|
76
|
+
color: transparent !important;
|
|
73
77
|
}
|
|
74
78
|
</style>
|
|
75
|
-
|
|
76
79
|
<script client>
|
|
77
80
|
export default class Monaco {
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
81
|
+
public value: string = "";
|
|
82
|
+
public language: string = "typescript";
|
|
83
|
+
public theme: string = "vs";
|
|
84
|
+
public readOnly: boolean = false;
|
|
85
|
+
/** Optional JSON Schema URL (IR — completion + diagnostics). */
|
|
86
|
+
public jsonSchemaUrl: string = "";
|
|
87
|
+
public onChange: ((v: string) => void) | null = null;
|
|
85
88
|
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
#api: {
|
|
90
|
+
getValue: () => string;
|
|
91
|
+
setValue: (v: string) => void;
|
|
92
|
+
dispose: () => void;
|
|
93
|
+
monaco?: { editor?: { setTheme?: (t: string) => void } };
|
|
94
|
+
} | null = null;
|
|
95
|
+
#applyingExternal = false;
|
|
96
|
+
#valueWatch: (() => void) | null = null;
|
|
97
|
+
#mountGen = 0;
|
|
98
|
+
#onScheme: ((e: Event) => void) | null = null;
|
|
96
99
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
100
|
+
#resolveTheme() {
|
|
101
|
+
if (typeof document === "undefined") return this.theme || "vs";
|
|
102
|
+
const dark =
|
|
103
|
+
document.documentElement.getAttribute("data-theme") === "dark" ||
|
|
104
|
+
document.documentElement.dataset.theme === "dark";
|
|
105
|
+
return dark ? "vs-dark" : "vs";
|
|
106
|
+
}
|
|
104
107
|
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
108
|
+
async onMount() {
|
|
109
|
+
if (typeof window === "undefined") return;
|
|
110
|
+
const gen = ++this.#mountGen;
|
|
111
|
+
const root = this.__vmzDomRoot;
|
|
112
|
+
const el =
|
|
113
|
+
(root && root.nodeType === 1 && root.matches?.("[data-vmz-monaco]") && root) ||
|
|
114
|
+
root?.querySelector?.("[data-vmz-monaco]") ||
|
|
115
|
+
root;
|
|
116
|
+
if (!el || el.nodeType !== 1) return;
|
|
114
117
|
|
|
115
|
-
|
|
116
|
-
|
|
118
|
+
this.#api?.dispose();
|
|
119
|
+
this.#api = null;
|
|
117
120
|
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
+
// Dynamic import — never evaluate monaco on the Node/SSR route path.
|
|
122
|
+
const { mountMonaco } = await import("@vmz/plugin-monaco/runtime");
|
|
123
|
+
if (gen !== this.#mountGen || this.__vmzDestroyed) return;
|
|
121
124
|
|
|
122
|
-
|
|
123
|
-
|
|
125
|
+
const theme = this.#resolveTheme();
|
|
126
|
+
this.theme = theme;
|
|
124
127
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
128
|
+
const api = await mountMonaco(el, {
|
|
129
|
+
value: this.value,
|
|
130
|
+
language: this.language,
|
|
131
|
+
theme,
|
|
132
|
+
readOnly: this.readOnly,
|
|
133
|
+
jsonSchemaUrl: this.jsonSchemaUrl || undefined,
|
|
134
|
+
onChange: (v) => {
|
|
135
|
+
this.#applyingExternal = true;
|
|
136
|
+
this.value = v;
|
|
137
|
+
this.#applyingExternal = false;
|
|
138
|
+
if (typeof this.onChange === "function") this.onChange(v);
|
|
139
|
+
},
|
|
140
|
+
});
|
|
141
|
+
if (gen !== this.#mountGen || this.__vmzDestroyed) {
|
|
142
|
+
api.dispose();
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
this.#api = api;
|
|
143
146
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
147
|
+
this.#onScheme = () => {
|
|
148
|
+
const next = this.#resolveTheme();
|
|
149
|
+
this.theme = next;
|
|
150
|
+
try {
|
|
151
|
+
this.#api?.monaco?.editor?.setTheme?.(next);
|
|
152
|
+
} catch {
|
|
153
|
+
/* ignore */
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
window.addEventListener("davinci-theme", this.#onScheme);
|
|
157
|
+
window.addEventListener("storage", this.#onScheme);
|
|
155
158
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
159
|
+
let last = this.value;
|
|
160
|
+
const tick = () => {
|
|
161
|
+
if (!this.#api || this.__vmzDestroyed) return;
|
|
162
|
+
if (this.#applyingExternal) return;
|
|
163
|
+
if (this.value !== last) {
|
|
164
|
+
last = this.value;
|
|
165
|
+
if (this.#api.getValue() !== this.value) {
|
|
166
|
+
this.#api.setValue(this.value ?? "");
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
const id = window.setInterval(tick, 50);
|
|
171
|
+
this.#valueWatch = () => window.clearInterval(id);
|
|
166
172
|
}
|
|
167
|
-
const id = window.setInterval(tick, 50)
|
|
168
|
-
this.#valueWatch = () => window.clearInterval(id)
|
|
169
|
-
}
|
|
170
173
|
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
174
|
+
onDestroy() {
|
|
175
|
+
this.#mountGen++;
|
|
176
|
+
if (this.#onScheme && typeof window !== "undefined") {
|
|
177
|
+
window.removeEventListener("davinci-theme", this.#onScheme);
|
|
178
|
+
window.removeEventListener("storage", this.#onScheme);
|
|
179
|
+
}
|
|
180
|
+
this.#onScheme = null;
|
|
181
|
+
this.#valueWatch?.();
|
|
182
|
+
this.#valueWatch = null;
|
|
183
|
+
this.#api?.dispose();
|
|
184
|
+
this.#api = null;
|
|
176
185
|
}
|
|
177
|
-
this.#onScheme = null
|
|
178
|
-
this.#valueWatch?.()
|
|
179
|
-
this.#valueWatch = null
|
|
180
|
-
this.#api?.dispose()
|
|
181
|
-
this.#api = null
|
|
182
|
-
}
|
|
183
186
|
}
|
|
184
187
|
</script>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vmz/plugin-monaco",
|
|
3
|
-
"version": "0.2.
|
|
3
|
+
"version": "0.2.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "VMZ Monaco editor adapter - <Monaco>",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
}
|
|
18
18
|
},
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@vmz/plugin": "0.2.
|
|
20
|
+
"@vmz/plugin": "0.2.4"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"monaco-editor": ">=0.52"
|