@vmz/plugin-monaco 0.0.3 → 0.0.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 +39 -2
- package/package.json +2 -2
package/components/Monaco.vmz
CHANGED
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
<template>
|
|
2
|
-
<div class="monaco-host" data-vmz-monaco
|
|
2
|
+
<div class="monaco-host" data-vmz-monaco></div>
|
|
3
3
|
</template>
|
|
4
4
|
|
|
5
|
+
<style>
|
|
6
|
+
.monaco-host {
|
|
7
|
+
display: block;
|
|
8
|
+
width: 100%;
|
|
9
|
+
height: 100%;
|
|
10
|
+
min-height: 0;
|
|
11
|
+
}
|
|
12
|
+
</style>
|
|
13
|
+
|
|
5
14
|
<script client>
|
|
6
15
|
import { mountMonaco } from '@vmz/plugin-monaco/runtime';
|
|
7
16
|
|
|
@@ -10,10 +19,19 @@ export default class Monaco {
|
|
|
10
19
|
public language: string = 'typescript';
|
|
11
20
|
public theme: string = 'vs-dark';
|
|
12
21
|
public readOnly: boolean = false;
|
|
22
|
+
/** Parent callback — keeps page state authoritative (same pattern as Switch.onChange). */
|
|
23
|
+
public onChange: ((v: string) => void) | null = null;
|
|
13
24
|
|
|
14
|
-
#api: {
|
|
25
|
+
#api: {
|
|
26
|
+
getValue: () => string;
|
|
27
|
+
setValue: (v: string) => void;
|
|
28
|
+
dispose: () => void;
|
|
29
|
+
} | null = null;
|
|
30
|
+
#applyingExternal = false;
|
|
31
|
+
#valueWatch: (() => void) | null = null;
|
|
15
32
|
|
|
16
33
|
async onMount() {
|
|
34
|
+
if (typeof window === 'undefined') return;
|
|
17
35
|
const root = this.__vmzDomRoot;
|
|
18
36
|
const el =
|
|
19
37
|
(root && root.nodeType === 1 && root.matches?.('[data-vmz-monaco]') && root) ||
|
|
@@ -26,12 +44,31 @@ export default class Monaco {
|
|
|
26
44
|
theme: this.theme,
|
|
27
45
|
readOnly: this.readOnly,
|
|
28
46
|
onChange: (v) => {
|
|
47
|
+
this.#applyingExternal = true;
|
|
29
48
|
this.value = v;
|
|
49
|
+
this.#applyingExternal = false;
|
|
50
|
+
if (typeof this.onChange === 'function') this.onChange(v);
|
|
30
51
|
},
|
|
31
52
|
});
|
|
53
|
+
// Parent may push a new `value` after mount (loadSpec). Sync into the editor.
|
|
54
|
+
let last = this.value;
|
|
55
|
+
const tick = () => {
|
|
56
|
+
if (!this.#api || this.__vmzDestroyed) return;
|
|
57
|
+
if (this.#applyingExternal) return;
|
|
58
|
+
if (this.value !== last) {
|
|
59
|
+
last = this.value;
|
|
60
|
+
if (this.#api.getValue() !== this.value) {
|
|
61
|
+
this.#api.setValue(this.value ?? '');
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
};
|
|
65
|
+
const id = window.setInterval(tick, 50);
|
|
66
|
+
this.#valueWatch = () => window.clearInterval(id);
|
|
32
67
|
}
|
|
33
68
|
|
|
34
69
|
onDestroy() {
|
|
70
|
+
this.#valueWatch?.();
|
|
71
|
+
this.#valueWatch = null;
|
|
35
72
|
this.#api?.dispose();
|
|
36
73
|
this.#api = null;
|
|
37
74
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vmz/plugin-monaco",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.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.0.
|
|
20
|
+
"@vmz/plugin": "0.0.4"
|
|
21
21
|
},
|
|
22
22
|
"peerDependencies": {
|
|
23
23
|
"monaco-editor": ">=0.52"
|