nuxt-monaco-editor 1.2.5 → 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,22 @@
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
+
14
+ ### [1.2.6](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.2.5...v1.2.6) (2023-12-10)
15
+
16
+
17
+ ### Features
18
+
19
+ * make `automaticLayout: true` as a default option ([16c3f10](https://github.com/e-chan1007/nuxt-monaco-editor/commit/16c3f10a7c5e86c12b7115ab509d0bca690afb3b))
20
+
5
21
  ### [1.2.5](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.2.4...v1.2.5) (2023-12-05)
6
22
 
7
23
 
package/dist/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.1.0"
6
6
  },
7
- "version": "1.2.5"
7
+ "version": "1.2.7"
8
8
  }
@@ -6,7 +6,8 @@
6
6
 
7
7
  <script lang="ts" setup>
8
8
  import type * as Monaco from 'monaco-editor'
9
- import { onMounted, onUnmounted, ref, watch } from 'vue'
9
+ import { onBeforeUnmount, ref, shallowRef, watch } from 'vue'
10
+ import { defu } from 'defu'
10
11
  import { useMonaco } from './composables'
11
12
 
12
13
  interface Props {
@@ -37,13 +38,17 @@ const props = withDefaults(defineProps<Props>(), {
37
38
  const emit = defineEmits<Emits>()
38
39
  const isLoading = ref(true)
39
40
 
40
- const editorElement = ref<HTMLDivElement>()
41
+ const editorElement = shallowRef<HTMLDivElement>()
41
42
  const monaco = useMonaco()!
42
43
 
43
44
  let editor: Monaco.editor.IStandaloneDiffEditor
44
45
  let originalModel: Monaco.editor.ITextModel
45
46
  let modifiedModel: Monaco.editor.ITextModel
46
- const editorRef = ref()
47
+
48
+ const editorRef = shallowRef<Monaco.editor.IStandaloneDiffEditor>()
49
+ const defaultOptions: Monaco.editor.IStandaloneEditorConstructionOptions = {
50
+ automaticLayout: true
51
+ }
47
52
 
48
53
  watch(() => [props.original, props.modelValue], () => {
49
54
  if (originalModel.getValue() !== props.original || modifiedModel.getValue() !== props.modelValue) {
@@ -66,7 +71,7 @@ watch(() => props.lang, () => {
66
71
  })
67
72
 
68
73
  watch(() => props.options, () => {
69
- editor?.updateOptions(props.options)
74
+ editor?.updateOptions(defu(props.options, defaultOptions))
70
75
  })
71
76
 
72
77
  defineExpose({
@@ -76,8 +81,9 @@ defineExpose({
76
81
  $editor: editorRef
77
82
  })
78
83
 
79
- onMounted(() => {
80
- editor = monaco.editor.createDiffEditor(editorElement.value!, props.options)
84
+ watch(editorElement, (newValue, oldValue) => {
85
+ if (!editorElement.value || oldValue) { return }
86
+ editor = monaco.editor.createDiffEditor(editorElement.value!, defu(props.options, defaultOptions))
81
87
  editorRef.value = editor
82
88
  originalModel = monaco.editor.createModel(props.original, props.lang)
83
89
  modifiedModel = monaco.editor.createModel(props.modelValue, props.lang)
@@ -94,7 +100,7 @@ onMounted(() => {
94
100
  emit('load', editor)
95
101
  })
96
102
 
97
- onUnmounted(() => {
103
+ onBeforeUnmount(() => {
98
104
  editor?.dispose()
99
105
  originalModel?.dispose()
100
106
  modifiedModel?.dispose()
@@ -6,25 +6,26 @@
6
6
 
7
7
  <script lang="ts" setup>
8
8
  import type * as Monaco from 'monaco-editor'
9
- import { computed, onMounted, onUnmounted, ref, watch } from 'vue'
9
+ import { computed, ref, shallowRef, watch, onBeforeUnmount } from 'vue'
10
+ import { defu } from 'defu'
10
11
  import { useMonaco } from './composables'
11
12
 
12
13
  interface Props {
13
- /**
14
- * Programming Language (Not a locale for UI);
15
- * overrides `options.language`
16
- */
17
- lang?: string;
18
- /**
19
- * Options passed to the second argument of `monaco.editor.create`
20
- */
21
- options?: Monaco.editor.IStandaloneEditorConstructionOptions;
22
- modelValue?: string;
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;
23
24
  }
24
25
 
25
26
  interface Emits {
26
- (event: 'update:modelValue', value: string): void
27
- (event: 'load', editor: Monaco.editor.IStandaloneCodeEditor): void
27
+ (event: 'update:modelValue', value: string): void
28
+ (event: 'load', editor: Monaco.editor.IStandaloneCodeEditor): void
28
29
  }
29
30
 
30
31
  const props = withDefaults(defineProps<Props>(), {
@@ -32,43 +33,44 @@ const props = withDefaults(defineProps<Props>(), {
32
33
  options: () => ({}),
33
34
  modelValue: () => ''
34
35
  })
36
+
35
37
  const emit = defineEmits<Emits>()
36
38
  const isLoading = ref(true)
37
-
38
39
  const lang = computed(() => props.lang || props.options.language)
39
-
40
+ const editorRef = shallowRef<Monaco.editor.IStandaloneCodeEditor>()
40
41
  const editorElement = ref<HTMLDivElement>()
41
42
  const monaco = useMonaco()!
43
+ const defaultOptions: Monaco.editor.IStandaloneEditorConstructionOptions = {
44
+ automaticLayout: true
45
+ }
42
46
 
43
47
  let editor: Monaco.editor.IStandaloneCodeEditor
44
48
  let model: Monaco.editor.ITextModel
45
- const editorRef = ref()
46
49
 
47
50
  watch(() => props.modelValue, () => {
48
- if (editor?.getValue() !== props.modelValue) { editor?.setValue(props.modelValue) }
51
+ if (editor?.getValue() !== props.modelValue) {
52
+ editor?.setValue(props.modelValue)
53
+ }
49
54
  })
50
55
 
51
56
  watch(() => props.lang, () => {
52
- if (model) { model.dispose() }
57
+ if (model) {
58
+ model.dispose()
59
+ }
53
60
  model = monaco.editor.createModel(props.modelValue, lang.value)
54
61
  editor?.setModel(model)
55
62
  })
56
63
 
57
64
  watch(() => props.options, () => {
58
- editor?.updateOptions(props.options)
59
- })
60
-
61
- defineExpose({
62
- /**
63
- * Monaco editor instance
64
- */
65
- $editor: editorRef
65
+ editor?.updateOptions(defu(props.options, defaultOptions))
66
66
  })
67
67
 
68
- onMounted(() => {
69
- editor = monaco.editor.create(editorElement.value!, props.options)
70
- editorRef.value = editor
68
+ watch(editorElement, (newValue, oldValue) => {
69
+ if (!editorElement.value || oldValue) { return }
70
+ editor = monaco.editor.create(editorElement.value!, defu(props.options, defaultOptions))
71
71
  model = monaco.editor.createModel(props.modelValue, lang.value)
72
+ editorRef.value = editor
73
+ editor.layout()
72
74
  editor.setModel(model)
73
75
  editor.onDidChangeModelContent(() => {
74
76
  emit('update:modelValue', editor.getValue())
@@ -77,7 +79,14 @@ onMounted(() => {
77
79
  emit('load', editor)
78
80
  })
79
81
 
80
- onUnmounted(() => {
82
+ defineExpose({
83
+ /**
84
+ * Monaco editor instance
85
+ */
86
+ $editor: editorRef
87
+ })
88
+
89
+ onBeforeUnmount(() => {
81
90
  editor?.dispose()
82
91
  model?.dispose()
83
92
  })
package/package.json CHANGED
@@ -11,7 +11,7 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/e-chan1007/nuxt-monaco-editor.git"
13
13
  },
14
- "version": "1.2.5",
14
+ "version": "1.2.7",
15
15
  "type": "module",
16
16
  "license": "MIT",
17
17
  "exports": {
@@ -46,6 +46,7 @@
46
46
  },
47
47
  "dependencies": {
48
48
  "@nuxt/kit": "^3.8.1",
49
+ "defu": "^6.1.3",
49
50
  "monaco-editor-nls": "^3.1.0",
50
51
  "vite-plugin-static-copy": "^0.17.0"
51
52
  },