nuxt-monaco-editor 1.2.6 → 1.2.8

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,17 @@
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.8](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.2.7...v1.2.8) (2024-04-20)
6
+
7
+ ### [1.2.7](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.2.6...v1.2.7) (2024-01-20)
8
+
9
+
10
+ ### Bug Fixes
11
+
12
+ * restore explicit imports ([d44ab28](https://github.com/e-chan1007/nuxt-monaco-editor/commit/d44ab28ca35c79edbefd69ea45161b8f51632d29))
13
+ * use `watch` for the target element ([878d3e7](https://github.com/e-chan1007/nuxt-monaco-editor/commit/878d3e735819bbbae245af3db7520a3a00a4237b))
14
+ * use `watch` instead of `onMounted` ([6e48fd1](https://github.com/e-chan1007/nuxt-monaco-editor/commit/6e48fd1672517719917d47a3012feb019d46530d))
15
+
5
16
  ### [1.2.6](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.2.5...v1.2.6) (2023-12-10)
6
17
 
7
18
 
package/README.md CHANGED
@@ -8,14 +8,7 @@ Integrate [monaco-editor](https://microsoft.github.io/monaco-editor/) with Nuxt
8
8
 
9
9
  ## Install
10
10
  ```sh
11
- # npm
12
- npm install -D monaco-editor nuxt-monaco-editor
13
-
14
- # yarn
15
- yarn add -D monaco-editor nuxt-monaco-editor
16
-
17
- # pnpm
18
- pnpm add -D monaco-editor nuxt-monaco-editor
11
+ npx nuxi@latest module add nuxt-monaco-editor
19
12
  ```
20
13
  Don't forget to install `monaco-editor`.
21
14
 
package/dist/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.1.0"
6
6
  },
7
- "version": "1.2.6"
7
+ "version": "1.2.8"
8
8
  }
package/dist/module.mjs CHANGED
@@ -29,25 +29,33 @@ const plugin = (options, nuxtOptions) => ({
29
29
  }
30
30
  },
31
31
  async load(id) {
32
+ id = id.split("?")[0];
33
+ const vsPath = id.includes("monaco-editor/esm") ? id.split("monaco-editor/esm/").pop() : null;
32
34
  if (options.locale !== "en") {
33
- id = id.split("?")[0];
34
35
  if (rewrittenMonacoFiles.has(id)) {
35
36
  return { code: rewrittenMonacoFiles.get(id) };
36
37
  }
37
38
  if (/\/(vscode-)?nls\.m?js/.test(id)) {
38
- const code = (await fs.readFile(resolve("nls.mjs"), "utf-8")).replace("__LOCALE_DATA_PATH__", `monaco-editor-nls/locale/${options.locale}.json`);
39
+ const code = (await fs.readFile(resolve("nls.mjs"), "utf-8")).replace("__LOCALE_DATA_PATH__", `nuxt-monaco-editor/dist/i18n/${options.locale}.json`);
39
40
  rewrittenMonacoFiles.set(id, code);
40
41
  return { code };
41
42
  }
42
- if (/monaco-editor\/esm\/vs.+\.js/.test(id)) {
43
- const vsPath = id.split(/monaco-editor\/esm\//).pop();
44
- if (vsPath) {
45
- const path = vsPath.replace(".js", "");
46
- const code = (await fs.readFile(id, "utf-8")).replace(/import \* as nls from '.+nls\.js(\?v=.+)?';/g, `import * as nls from '${nlsPath}';`).replace(/(?<!function )localize\(/g, `localize('${path}', `);
47
- rewrittenMonacoFiles.set(id, code);
48
- return { code };
43
+ if (vsPath && id.endsWith(".js")) {
44
+ const path = vsPath.replace(/\.js$/, "");
45
+ let code = (await fs.readFile(id, "utf-8")).replace(/import \* as nls from '.+nls\.js(\?v=.+)?';/g, `import * as nls from '${nlsPath}';`).replace(/(?<!function )localize\(/g, `localize('${path}', `);
46
+ if (path === "vs/base/common/platform") {
47
+ code = code.replace("let _isWeb = false;", "let _isWeb = true;");
49
48
  }
49
+ rewrittenMonacoFiles.set(id, code);
50
+ return { code };
50
51
  }
52
+ return;
53
+ }
54
+ if (vsPath === "vs/base/common/platform.js") {
55
+ let code = await fs.readFile(id, "utf-8");
56
+ code = code.replace("let _isWeb = false;", "let _isWeb = true;");
57
+ rewrittenMonacoFiles.set(id, code);
58
+ return { code };
51
59
  }
52
60
  }
53
61
  });
@@ -70,6 +78,9 @@ const module = defineNuxtModule({
70
78
  const isDev = nuxt.options.dev;
71
79
  const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
72
80
  const { resolve } = createResolver(runtimeDir);
81
+ if (isDev) {
82
+ nuxt.options.vite.optimizeDeps?.exclude?.push("monaco-editor");
83
+ }
73
84
  nuxt.options.build.transpile.push(runtimeDir);
74
85
  nuxt.options.build.transpile.push(({ isClient }) => isClient ? "monaco-editor" : false);
75
86
  addVitePlugin(plugin(options, nuxt.options));
@@ -6,7 +6,7 @@
6
6
 
7
7
  <script lang="ts" setup>
8
8
  import type * as Monaco from 'monaco-editor'
9
- import { onMounted, onUnmounted, ref, shallowRef, watch } from 'vue'
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
- onMounted(() => {
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
- onUnmounted(() => {
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, onMounted, onUnmounted, ref, shallowRef, watch } from 'vue'
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
- * 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;
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
- (event: 'update:modelValue', value: string): void
28
- (event: 'load', editor: Monaco.editor.IStandaloneCodeEditor): void
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) { editor?.setValue(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) { model.dispose() }
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
- defineExpose({
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
- onUnmounted(() => {
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
  })
@@ -3,3 +3,7 @@ export function localize(path: any, _data: any, defaultMessage: any, ...args: an
3
3
  export function loadMessageBundle(file: any): typeof localize;
4
4
  export function config(opt: any): typeof loadMessageBundle;
5
5
  export function getConfiguredDefaultLocale(): undefined;
6
+ export function localize2(data: any, message: any, ...args: any[]): {
7
+ value: any;
8
+ original: any;
9
+ };
@@ -15,7 +15,7 @@ export function _format (message, args) {
15
15
 
16
16
  export function localize (path, _data, defaultMessage) {
17
17
  const key = typeof _data === 'object' ? _data.key : _data
18
- const data = localeData || {}
18
+ const data = localeData?.contents || {}
19
19
  let message = (data[path] || {})[key]
20
20
  if (!message) {
21
21
  message = defaultMessage
@@ -27,6 +27,14 @@ export function localize (path, _data, defaultMessage) {
27
27
  return _format(message, args)
28
28
  }
29
29
 
30
+ export const localize2 = (data, message, ...args) => {
31
+ const original = _format(message, args)
32
+ return {
33
+ value: original,
34
+ original
35
+ }
36
+ }
37
+
30
38
  export function loadMessageBundle (file) {
31
39
  return localize
32
40
  }
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.6",
14
+ "version": "1.2.8",
15
15
  "type": "module",
16
16
  "license": "MIT",
17
17
  "exports": {
@@ -31,45 +31,49 @@
31
31
  "scripts": {
32
32
  "postpack": "pinst --enable",
33
33
  "_postinstall": "husky install && playwright install",
34
- "build": "nuxt-module-build",
34
+ "build": "nuxt-module-build && yarn loc:build",
35
35
  "lint": "eslint --ext .js,.cjs,.mjs,.ts,.cts,.mts,.vue . && remark . -q",
36
36
  "test": "nuxt test",
37
37
  "prepack": "pinst --disable && nuxt-module-build",
38
38
  "release": "standard-version",
39
39
  "dev": "nuxt dev playground",
40
40
  "dev:build": "nuxt build playground",
41
- "dev:prepare": "nuxt-module-build --stub && nuxt prepare playground",
41
+ "dev:prepare": "nuxt-module-build --stub && nuxt prepare playground && yarn loc:build",
42
42
  "docs:dev": "nuxt dev docs",
43
43
  "docs:generate": "nuxt generate docs",
44
44
  "docs:prepare": "nuxt prepare docs",
45
- "docs:preview": "nuxt preview docs"
45
+ "docs:preview": "nuxt preview docs",
46
+ "loc:build": "jiti scripts/build-loc.ts"
46
47
  },
47
48
  "dependencies": {
48
- "@nuxt/kit": "^3.8.1",
49
- "defu": "^6.1.3",
50
- "monaco-editor-nls": "^3.1.0",
51
- "vite-plugin-static-copy": "^0.17.0"
49
+ "@nuxt/kit": "^3.11.2",
50
+ "defu": "^6.1.4",
51
+ "vite-plugin-static-copy": "^1.0.3"
52
52
  },
53
53
  "devDependencies": {
54
- "@commitlint/cli": "^18.4.1",
55
- "@commitlint/config-conventional": "^18.4.0",
54
+ "@commitlint/cli": "^19.2.2",
55
+ "@commitlint/config-conventional": "^19.2.2",
56
56
  "@nuxt-themes/docus": "^1.15.0",
57
57
  "@nuxt/module-builder": "latest",
58
- "@nuxt/test-utils": "^3.8.1",
58
+ "@nuxt/test-utils": "3.11.0",
59
59
  "@nuxtjs/eslint-config-typescript": "^12.1.0",
60
- "eslint": "^8.53.0",
60
+ "@vue/test-utils": "^2.4.5",
61
+ "eslint": "^8.57.0",
61
62
  "execa": "^8.0.1",
62
- "husky": "^8.0.3",
63
- "monaco-editor": "^0.44.0",
64
- "nuxt": "^3.8.1",
63
+ "happy-dom": "^14.7.1",
64
+ "husky": "^9.0.11",
65
+ "jiti": "^1.21.0",
66
+ "monaco-editor": "^0.47.0",
67
+ "nuxt": "^3.11.2",
65
68
  "pinst": "^3.0.0",
66
- "playwright": "^1.39.0",
69
+ "playwright": "^1.43.1",
70
+ "playwright-core": "^1.43.1",
67
71
  "remark-cli": "^12.0.0",
68
- "remark-lint": "^9.1.2",
69
- "remark-preset-lint-recommended": "^6.1.3",
72
+ "remark-lint": "^10.0.0",
73
+ "remark-preset-lint-recommended": "^7.0.0",
70
74
  "standard-version": "^9.5.0",
71
- "typescript": "^5.2.2",
72
- "vitest": "^0.33.0"
75
+ "typescript": "^5.4.5",
76
+ "vitest": "^1.5.0"
73
77
  },
74
78
  "peerDependencies": {
75
79
  "monaco-editor": "*"
@@ -86,5 +90,5 @@
86
90
  "workspaces": [
87
91
  "playground"
88
92
  ],
89
- "packageManager": "yarn@4.0.1"
93
+ "packageManager": "yarn@4.1.1"
90
94
  }