nuxt-monaco-editor 1.1.3 → 1.2.0-beta.0

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,27 @@
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.0-beta.0](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.1.4...v1.2.0-beta.0) (2023-03-24)
6
+
7
+
8
+ ### Features
9
+
10
+ * load monaco-editor with ESM ([#1](https://github.com/e-chan1007/nuxt-monaco-editor/issues/1), [#19](https://github.com/e-chan1007/nuxt-monaco-editor/issues/19), [#26](https://github.com/e-chan1007/nuxt-monaco-editor/issues/26)) ([f1ea2e0](https://github.com/e-chan1007/nuxt-monaco-editor/commit/f1ea2e0bf31fbdc1adf7fcbb3b1184c5b6465aed))
11
+
12
+
13
+ ### Bug Fixes
14
+
15
+ * copy esm to `_nuxt` ([fcefdbf](https://github.com/e-chan1007/nuxt-monaco-editor/commit/fcefdbf992bcbdc6a9d9b4ebed5ba490233be427))
16
+ * resolve paths correctly ([01b6450](https://github.com/e-chan1007/nuxt-monaco-editor/commit/01b645077abd7b602b30c9dbdda91372289a8d93))
17
+ * update link to IStandaloneCodeEditor in monaco editor official documentation ([9debaa8](https://github.com/e-chan1007/nuxt-monaco-editor/commit/9debaa8e33296ea4babe7eb6fe3bd06396479841))
18
+
19
+ ### [1.1.4](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.1.3...v1.1.4) (2023-02-22)
20
+
21
+
22
+ ### Bug Fixes
23
+
24
+ * change the directory to which `monaco-editor` will be copied ([7f88db5](https://github.com/e-chan1007/nuxt-monaco-editor/commit/7f88db5ea359ae0b91ea7664872b9f908f26994a))
25
+
5
26
  ### [1.1.3](https://github.com/e-chan1007/nuxt-monaco-editor/compare/v1.1.3-beta.0...v1.1.3) (2023-01-28)
6
27
 
7
28
 
package/dist/module.d.ts CHANGED
@@ -1,8 +1,7 @@
1
1
  import * as _nuxt_schema from '@nuxt/schema';
2
2
 
3
- type MonacoEditorLocale = 'de' | 'es' | 'fr' | 'it' | 'ja' | 'ko' | 'ru' | 'zh-cn' | 'zh-tw' | 'en';
3
+ type MonacoEditorLocale = 'cs' | 'de' | 'es' | 'fr' | 'it' | 'ja' | 'ko' | 'pl' | 'pt-br' | 'qps-ploc' | 'ru' | 'tr' | 'zh-hans' | 'zh-hant' | 'en';
4
4
  interface ModuleOptions {
5
- dest?: string;
6
5
  locale?: MonacoEditorLocale;
7
6
  componentName?: {
8
7
  codeEditor?: string;
package/dist/module.json CHANGED
@@ -4,5 +4,5 @@
4
4
  "compatibility": {
5
5
  "nuxt": "^3.1.0"
6
6
  },
7
- "version": "1.1.3"
7
+ "version": "1.2.0-beta.0"
8
8
  }
package/dist/module.mjs CHANGED
@@ -1,6 +1,8 @@
1
- import { fileURLToPath } from 'url';
2
- import { defineNuxtModule, createResolver, extendViteConfig, addPlugin, addComponent, addImports } from '@nuxt/kit';
1
+ import { fileURLToPath } from 'node:url';
2
+ import { createResolver, defineNuxtModule, addVitePlugin, addPlugin, addComponent, addImports } from '@nuxt/kit';
3
3
  import { viteStaticCopy } from 'vite-plugin-static-copy';
4
+ import fs from 'fs/promises';
5
+ import { createRequire } from 'node:module';
4
6
 
5
7
 
6
8
 
@@ -11,8 +13,46 @@ import __cjs_mod__ from 'module';
11
13
  const __filename = __cjs_url__.fileURLToPath(import.meta.url);
12
14
  const __dirname = __cjs_path__.dirname(__filename);
13
15
  const require = __cjs_mod__.createRequire(import.meta.url);
16
+ const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
17
+ const { resolve } = createResolver(runtimeDir);
18
+ const rewrittenMonacoFiles = /* @__PURE__ */ new Map();
19
+ const nlsPath = resolve("nls.mjs");
20
+ const { resolve: resolveModule } = createRequire(import.meta.url);
21
+ const plugin = (options, nuxtOptions) => ({
22
+ name: "vite-plugin-nuxt-monaco-editor",
23
+ enforce: "pre",
24
+ resolveId(src) {
25
+ if (src.includes("monaco-editor/esm/vs/") && src.endsWith(".js?worker")) {
26
+ return resolveModule(
27
+ src.replace("?worker", "").replace("__skip_vite", "").replace("node_modules", "").replace(nuxtOptions.app.baseURL, "/").replace(/\/\/+/g, "/").replace(/^\//, "")
28
+ );
29
+ }
30
+ },
31
+ async load(id) {
32
+ if (options.locale !== "en") {
33
+ id = id.split("?")[0];
34
+ if (rewrittenMonacoFiles.has(id)) {
35
+ return { code: rewrittenMonacoFiles.get(id) };
36
+ }
37
+ 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
+ rewrittenMonacoFiles.set(id, code);
40
+ return { code };
41
+ }
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 };
49
+ }
50
+ }
51
+ }
52
+ }
53
+ });
54
+
14
55
  const DEFAULTS = {
15
- dest: "_monaco",
16
56
  locale: "en",
17
57
  componentName: {
18
58
  codeEditor: "MonacoEditor",
@@ -27,29 +67,28 @@ const module = defineNuxtModule({
27
67
  },
28
68
  defaults: DEFAULTS,
29
69
  setup(options, nuxt) {
70
+ const isDev = nuxt.options.dev;
30
71
  const runtimeDir = fileURLToPath(new URL("./runtime", import.meta.url));
31
- const { resolve: resolveURL } = createResolver(nuxt.options.app.baseURL);
32
72
  const { resolve } = createResolver(runtimeDir);
33
- const monacoEditorLocation = resolveURL(options.dest);
34
73
  nuxt.options.build.transpile.push(runtimeDir);
35
74
  nuxt.options.build.transpile.push(({ isClient }) => isClient ? "monaco-editor" : false);
36
- nuxt.options.runtimeConfig.app.__MONACO_EDITOR_LOCALE__ = options.locale;
37
- nuxt.options.runtimeConfig.app.__MONACO_EDITOR_LOCATION__ = monacoEditorLocation;
38
- extendViteConfig((config) => {
39
- const viteStaticCopyPlugin = viteStaticCopy({
40
- targets: [{
41
- src: require.resolve("monaco-editor/min/vs/loader.js").replace(/\\/g, "/").replace(/\/vs\/loader\.js$/, "/*"),
42
- dest: options.dest
43
- }]
75
+ addVitePlugin(plugin(options, nuxt.options));
76
+ addVitePlugin(viteStaticCopy({
77
+ targets: [{
78
+ src: require.resolve("monaco-editor/esm/metadata.js").replace(/\\/g, "/").replace(/\/metadata.js$/, "/*"),
79
+ dest: "_nuxt/nuxt-monaco-editor"
80
+ }]
81
+ }));
82
+ nuxt.hook("build:manifest", (manifest) => {
83
+ Object.entries(manifest).forEach(([key, entry]) => {
84
+ if (key.includes("node_modules/monaco-editor/esm/vs")) {
85
+ entry.isEntry = false;
86
+ }
44
87
  });
45
- if (!config.plugins) {
46
- config.plugins = [];
47
- }
48
- config.plugins.push(...viteStaticCopyPlugin);
49
88
  });
50
- addPlugin(resolve("plugin.client"));
51
- addComponent({ name: options.componentName.codeEditor, filePath: resolve("MonacoEditor.vue") });
52
- addComponent({ name: options.componentName.diffEditor, filePath: resolve("MonacoDiffEditor.vue") });
89
+ addPlugin(isDev ? resolve("plugin-dev.client") : resolve("plugin-prod.client"));
90
+ addComponent({ name: options.componentName.codeEditor, filePath: resolve("MonacoEditor.client.vue") });
91
+ addComponent({ name: options.componentName.diffEditor, filePath: resolve("MonacoDiffEditor.client.vue") });
53
92
  addImports({ name: "useMonaco", as: "useMonaco", from: resolve("composables") });
54
93
  }
55
94
  });
@@ -0,0 +1,5 @@
1
+ export function _format(message: any, args: any): any;
2
+ export function localize(path: any, _data: any, defaultMessage: any, ...args: any[]): any;
3
+ export function loadMessageBundle(file: any): typeof localize;
4
+ export function config(opt: any): typeof loadMessageBundle;
5
+ export function getConfiguredDefaultLocale(): undefined;
@@ -0,0 +1,40 @@
1
+ import localeData from '__LOCALE_DATA_PATH__'
2
+
3
+ export function _format (message, args) {
4
+ let result
5
+ if (args.length === 0) {
6
+ result = message
7
+ } else {
8
+ result = String(message).replace(/\{(\d+)\}/g, function (match, rest) {
9
+ const index = rest[0]
10
+ return typeof args[index] !== 'undefined' ? args[index] : match
11
+ })
12
+ }
13
+ return result
14
+ }
15
+
16
+ export function localize (path, _data, defaultMessage) {
17
+ const key = typeof _data === 'object' ? _data.key : _data
18
+ const data = localeData || {}
19
+ let message = (data[path] || {})[key]
20
+ if (!message) {
21
+ message = defaultMessage
22
+ }
23
+ const args = []
24
+ for (let _i = 3; _i < arguments.length; _i++) {
25
+ args[_i - 3] = arguments[_i]
26
+ }
27
+ return _format(message, args)
28
+ }
29
+
30
+ export function loadMessageBundle (file) {
31
+ return localize
32
+ }
33
+
34
+ export function config (opt) {
35
+ return loadMessageBundle
36
+ }
37
+
38
+ export function getConfiguredDefaultLocale () {
39
+ return undefined
40
+ }
@@ -0,0 +1,33 @@
1
+ import { defineNuxtPlugin } from "#app";
2
+ import { _useMonacoState } from "./composables.mjs";
3
+ export default defineNuxtPlugin(async (nuxtApp) => {
4
+ const getWorkerModule = (moduleUrl, label) => {
5
+ return new Worker(new URL("/node_modules/monaco-editor/esm/vs/" + moduleUrl + ".js?worker", import.meta.url), {
6
+ name: label,
7
+ type: "module"
8
+ });
9
+ };
10
+ self.MonacoEnvironment = {
11
+ getWorker(workerId, label) {
12
+ switch (label) {
13
+ case "json":
14
+ return getWorkerModule("language/json/json.worker", label);
15
+ case "css":
16
+ case "scss":
17
+ case "less":
18
+ return getWorkerModule("language/css/css.worker", label);
19
+ case "html":
20
+ case "handlebars":
21
+ case "razor":
22
+ return getWorkerModule("language/html/html.worker", label);
23
+ case "typescript":
24
+ case "javascript":
25
+ return getWorkerModule("language/typescript/ts.worker", label);
26
+ default:
27
+ return getWorkerModule("editor/editor.worker", label);
28
+ }
29
+ }
30
+ };
31
+ const monacoState = _useMonacoState();
32
+ monacoState.value = await import("monaco-editor");
33
+ });
@@ -0,0 +1,2 @@
1
+ declare const _default: any;
2
+ export default _default;
@@ -0,0 +1,33 @@
1
+ import { defineNuxtPlugin } from "#app";
2
+ import { _useMonacoState } from "./composables.mjs";
3
+ export default defineNuxtPlugin(async (nuxtApp) => {
4
+ const getWorkerModule = (moduleUrl, label) => {
5
+ return new Worker(new URL(`${nuxtApp.$config.app.baseURL}/_nuxt/nuxt-monaco-editor/vs/${moduleUrl}.js`.replace(/\/\//g, "/"), import.meta.url), {
6
+ name: label,
7
+ type: "module"
8
+ });
9
+ };
10
+ self.MonacoEnvironment = {
11
+ getWorker(workerId, label) {
12
+ switch (label) {
13
+ case "json":
14
+ return getWorkerModule("language/json/json.worker", label);
15
+ case "css":
16
+ case "scss":
17
+ case "less":
18
+ return getWorkerModule("language/css/css.worker", label);
19
+ case "html":
20
+ case "handlebars":
21
+ case "razor":
22
+ return getWorkerModule("language/html/html.worker", label);
23
+ case "typescript":
24
+ case "javascript":
25
+ return getWorkerModule("language/typescript/ts.worker", label);
26
+ default:
27
+ return getWorkerModule("editor/editor.worker", label);
28
+ }
29
+ }
30
+ };
31
+ const monacoState = _useMonacoState();
32
+ monacoState.value = await import("monaco-editor");
33
+ });
package/package.json CHANGED
@@ -11,13 +11,16 @@
11
11
  "type": "git",
12
12
  "url": "https://github.com/e-chan1007/nuxt-monaco-editor.git"
13
13
  },
14
- "version": "1.1.3",
14
+ "version": "1.2.0-beta.0",
15
15
  "type": "module",
16
16
  "license": "MIT",
17
17
  "exports": {
18
18
  ".": {
19
19
  "import": "./dist/module.mjs",
20
20
  "require": "./dist/module.cjs"
21
+ },
22
+ "./dist/*": {
23
+ "import": "./dist/*"
21
24
  }
22
25
  },
23
26
  "main": "./dist/module.cjs",
@@ -42,28 +45,29 @@
42
45
  "docs:preview": "nuxt preview docs"
43
46
  },
44
47
  "dependencies": {
45
- "@nuxt/kit": "^3.1.1",
46
- "vite-plugin-static-copy": "^0.13.0"
48
+ "@nuxt/kit": "^3.3.1",
49
+ "monaco-editor-nls": "^3.0.0",
50
+ "vite-plugin-static-copy": "^0.13.1"
47
51
  },
48
52
  "devDependencies": {
49
- "@commitlint/cli": "^17.4.2",
50
- "@commitlint/config-conventional": "^17.4.2",
51
- "@nuxt-themes/docus": "^1.6.3",
53
+ "@commitlint/cli": "^17.5.0",
54
+ "@commitlint/config-conventional": "^17.4.4",
55
+ "@nuxt-themes/docus": "^1.9.10",
52
56
  "@nuxt/module-builder": "latest",
53
- "@nuxt/test-utils": "^3.1.1",
57
+ "@nuxt/test-utils": "^3.3.1",
54
58
  "@nuxtjs/eslint-config-typescript": "^12.0.0",
55
- "eslint": "^8.32.0",
56
- "execa": "^6.1.0",
59
+ "eslint": "^8.36.0",
60
+ "execa": "^7.1.1",
57
61
  "husky": "^8.0.3",
58
- "monaco-editor": "^0.34.1",
59
- "nuxt": "^3.1.1",
62
+ "monaco-editor": "^0.36.1",
63
+ "nuxt": "^3.3.1",
60
64
  "pinst": "^3.0.0",
61
- "playwright": "^1.30.0",
65
+ "playwright": "^1.32.0",
62
66
  "remark-cli": "^11.0.0",
63
67
  "remark-lint": "^9.1.1",
64
68
  "remark-preset-lint-recommended": "^6.1.2",
65
69
  "standard-version": "^9.5.0",
66
- "vitest": "^0.28.3"
70
+ "vitest": "^0.29.7"
67
71
  },
68
72
  "peerDependencies": {
69
73
  "monaco-editor": "*"
@@ -77,5 +81,8 @@
77
81
  ]
78
82
  ]
79
83
  },
84
+ "workspaces": [
85
+ "playground"
86
+ ],
80
87
  "packageManager": "yarn@3.2.4"
81
88
  }
@@ -1,25 +0,0 @@
1
- import { defineNuxtPlugin, useRuntimeConfig } from "#app";
2
- import { _useMonacoState } from "./composables.mjs";
3
- export default defineNuxtPlugin((_nuxtApp) => new Promise((resolve) => {
4
- const monacoState = _useMonacoState();
5
- const { __MONACO_EDITOR_LOCALE__: locale, __MONACO_EDITOR_LOCATION__: monacoEditorLocation } = useRuntimeConfig().app;
6
- const loaderScript = document.createElement("script");
7
- loaderScript.src = `${monacoEditorLocation}/vs/loader.js`;
8
- loaderScript.addEventListener("load", () => {
9
- require.config({ paths: { vs: `${monacoEditorLocation}/vs` } });
10
- if (locale !== "en") {
11
- require.config({
12
- "vs/nls": {
13
- availableLanguages: {
14
- "*": locale
15
- }
16
- }
17
- });
18
- }
19
- require(["vs/editor/editor.main"], (monaco) => {
20
- monacoState.value = monaco;
21
- resolve();
22
- });
23
- });
24
- document.body.appendChild(loaderScript);
25
- }));