nuxt-monaco-editor 1.2.6 → 1.2.7
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/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,15 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.2.7](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.2.6...v1.2.7) (2024-01-20)
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
### Bug Fixes
|
|
9
|
+
|
|
10
|
+
* restore explicit imports ([d44ab28](https://github.com/e-chan1007/nuxt-monaco-editor/commit/d44ab28ca35c79edbefd69ea45161b8f51632d29))
|
|
11
|
+
* use `watch` for the target element ([878d3e7](https://github.com/e-chan1007/nuxt-monaco-editor/commit/878d3e735819bbbae245af3db7520a3a00a4237b))
|
|
12
|
+
* use `watch` instead of `onMounted` ([6e48fd1](https://github.com/e-chan1007/nuxt-monaco-editor/commit/6e48fd1672517719917d47a3012feb019d46530d))
|
|
13
|
+
|
|
5
14
|
### [1.2.6](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.2.5...v1.2.6) (2023-12-10)
|
|
6
15
|
|
|
7
16
|
|
package/dist/module.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
|
|
7
7
|
<script lang="ts" setup>
|
|
8
8
|
import type * as Monaco from 'monaco-editor'
|
|
9
|
-
import {
|
|
9
|
+
import { onBeforeUnmount, ref, shallowRef, watch } from 'vue'
|
|
10
10
|
import { defu } from 'defu'
|
|
11
11
|
import { useMonaco } from './composables'
|
|
12
12
|
|
|
@@ -44,8 +44,8 @@ const monaco = useMonaco()!
|
|
|
44
44
|
let editor: Monaco.editor.IStandaloneDiffEditor
|
|
45
45
|
let originalModel: Monaco.editor.ITextModel
|
|
46
46
|
let modifiedModel: Monaco.editor.ITextModel
|
|
47
|
-
const editorRef = shallowRef<Monaco.editor.IStandaloneDiffEditor>()
|
|
48
47
|
|
|
48
|
+
const editorRef = shallowRef<Monaco.editor.IStandaloneDiffEditor>()
|
|
49
49
|
const defaultOptions: Monaco.editor.IStandaloneEditorConstructionOptions = {
|
|
50
50
|
automaticLayout: true
|
|
51
51
|
}
|
|
@@ -81,7 +81,8 @@ defineExpose({
|
|
|
81
81
|
$editor: editorRef
|
|
82
82
|
})
|
|
83
83
|
|
|
84
|
-
|
|
84
|
+
watch(editorElement, (newValue, oldValue) => {
|
|
85
|
+
if (!editorElement.value || oldValue) { return }
|
|
85
86
|
editor = monaco.editor.createDiffEditor(editorElement.value!, defu(props.options, defaultOptions))
|
|
86
87
|
editorRef.value = editor
|
|
87
88
|
originalModel = monaco.editor.createModel(props.original, props.lang)
|
|
@@ -99,7 +100,7 @@ onMounted(() => {
|
|
|
99
100
|
emit('load', editor)
|
|
100
101
|
})
|
|
101
102
|
|
|
102
|
-
|
|
103
|
+
onBeforeUnmount(() => {
|
|
103
104
|
editor?.dispose()
|
|
104
105
|
originalModel?.dispose()
|
|
105
106
|
modifiedModel?.dispose()
|
|
@@ -6,26 +6,26 @@
|
|
|
6
6
|
|
|
7
7
|
<script lang="ts" setup>
|
|
8
8
|
import type * as Monaco from 'monaco-editor'
|
|
9
|
-
import { computed,
|
|
9
|
+
import { computed, ref, shallowRef, watch, onBeforeUnmount } from 'vue'
|
|
10
10
|
import { defu } from 'defu'
|
|
11
11
|
import { useMonaco } from './composables'
|
|
12
12
|
|
|
13
13
|
interface Props {
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
/**
|
|
15
|
+
* Programming Language (Not a locale for UI);
|
|
16
|
+
* overrides `options.language`
|
|
17
|
+
*/
|
|
18
|
+
lang?: string;
|
|
19
|
+
/**
|
|
20
|
+
* Options passed to the second argument of `monaco.editor.create`
|
|
21
|
+
*/
|
|
22
|
+
options?: Monaco.editor.IStandaloneEditorConstructionOptions;
|
|
23
|
+
modelValue?: string;
|
|
24
24
|
}
|
|
25
25
|
|
|
26
26
|
interface Emits {
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
(event: 'update:modelValue', value: string): void
|
|
28
|
+
(event: 'load', editor: Monaco.editor.IStandaloneCodeEditor): void
|
|
29
29
|
}
|
|
30
30
|
|
|
31
31
|
const props = withDefaults(defineProps<Props>(), {
|
|
@@ -33,28 +33,30 @@ const props = withDefaults(defineProps<Props>(), {
|
|
|
33
33
|
options: () => ({}),
|
|
34
34
|
modelValue: () => ''
|
|
35
35
|
})
|
|
36
|
+
|
|
36
37
|
const emit = defineEmits<Emits>()
|
|
37
38
|
const isLoading = ref(true)
|
|
38
|
-
|
|
39
39
|
const lang = computed(() => props.lang || props.options.language)
|
|
40
|
-
|
|
41
|
-
const editorElement = shallowRef<HTMLDivElement>()
|
|
42
|
-
const monaco = useMonaco()!
|
|
43
|
-
|
|
44
|
-
let editor: Monaco.editor.IStandaloneCodeEditor
|
|
45
|
-
let model: Monaco.editor.ITextModel
|
|
46
40
|
const editorRef = shallowRef<Monaco.editor.IStandaloneCodeEditor>()
|
|
47
|
-
|
|
41
|
+
const editorElement = ref<HTMLDivElement>()
|
|
42
|
+
const monaco = useMonaco()!
|
|
48
43
|
const defaultOptions: Monaco.editor.IStandaloneEditorConstructionOptions = {
|
|
49
44
|
automaticLayout: true
|
|
50
45
|
}
|
|
51
46
|
|
|
47
|
+
let editor: Monaco.editor.IStandaloneCodeEditor
|
|
48
|
+
let model: Monaco.editor.ITextModel
|
|
49
|
+
|
|
52
50
|
watch(() => props.modelValue, () => {
|
|
53
|
-
if (editor?.getValue() !== props.modelValue) {
|
|
51
|
+
if (editor?.getValue() !== props.modelValue) {
|
|
52
|
+
editor?.setValue(props.modelValue)
|
|
53
|
+
}
|
|
54
54
|
})
|
|
55
55
|
|
|
56
56
|
watch(() => props.lang, () => {
|
|
57
|
-
if (model) {
|
|
57
|
+
if (model) {
|
|
58
|
+
model.dispose()
|
|
59
|
+
}
|
|
58
60
|
model = monaco.editor.createModel(props.modelValue, lang.value)
|
|
59
61
|
editor?.setModel(model)
|
|
60
62
|
})
|
|
@@ -63,17 +65,12 @@ watch(() => props.options, () => {
|
|
|
63
65
|
editor?.updateOptions(defu(props.options, defaultOptions))
|
|
64
66
|
})
|
|
65
67
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
* Monaco editor instance
|
|
69
|
-
*/
|
|
70
|
-
$editor: editorRef
|
|
71
|
-
})
|
|
72
|
-
|
|
73
|
-
onMounted(() => {
|
|
68
|
+
watch(editorElement, (newValue, oldValue) => {
|
|
69
|
+
if (!editorElement.value || oldValue) { return }
|
|
74
70
|
editor = monaco.editor.create(editorElement.value!, defu(props.options, defaultOptions))
|
|
75
|
-
editorRef.value = editor
|
|
76
71
|
model = monaco.editor.createModel(props.modelValue, lang.value)
|
|
72
|
+
editorRef.value = editor
|
|
73
|
+
editor.layout()
|
|
77
74
|
editor.setModel(model)
|
|
78
75
|
editor.onDidChangeModelContent(() => {
|
|
79
76
|
emit('update:modelValue', editor.getValue())
|
|
@@ -82,7 +79,14 @@ onMounted(() => {
|
|
|
82
79
|
emit('load', editor)
|
|
83
80
|
})
|
|
84
81
|
|
|
85
|
-
|
|
82
|
+
defineExpose({
|
|
83
|
+
/**
|
|
84
|
+
* Monaco editor instance
|
|
85
|
+
*/
|
|
86
|
+
$editor: editorRef
|
|
87
|
+
})
|
|
88
|
+
|
|
89
|
+
onBeforeUnmount(() => {
|
|
86
90
|
editor?.dispose()
|
|
87
91
|
model?.dispose()
|
|
88
92
|
})
|