react-monaco-editor-view 0.1.0 → 0.1.1
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/dist/index.d.mts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +2 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -3,8 +3,9 @@ import * as _monaco_editor_react from '@monaco-editor/react';
|
|
|
3
3
|
import { OnMount, EditorProps } from '@monaco-editor/react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* 本包构建会将 `public/vs`
|
|
7
|
-
*
|
|
6
|
+
* 本包构建会将 `public/vs` 复制到 `dist/vs`,默认前缀相对 `dist/index.{mjs,js}` 解析。
|
|
7
|
+
* 使用具体文件 `./vs/loader.js` 作为锚点:Webpack / Rspack 等无法把目录 `./vs/` 当作可解析依赖,会报 Can't resolve。
|
|
8
|
+
* 若宿主把本包打进单 chunk 且未保留 `dist/vs` 静态资源,请在入口 `configureMonacoVsPath` 或传 `monacoVsPath`。
|
|
8
9
|
*/
|
|
9
10
|
declare function getDefaultMonacoVsPath(): string;
|
|
10
11
|
/** 与 {@link getDefaultMonacoVsPath} 在模块加载时解析一次的结果相同 */
|
package/dist/index.d.ts
CHANGED
|
@@ -3,8 +3,9 @@ import * as _monaco_editor_react from '@monaco-editor/react';
|
|
|
3
3
|
import { OnMount, EditorProps } from '@monaco-editor/react';
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
|
-
* 本包构建会将 `public/vs`
|
|
7
|
-
*
|
|
6
|
+
* 本包构建会将 `public/vs` 复制到 `dist/vs`,默认前缀相对 `dist/index.{mjs,js}` 解析。
|
|
7
|
+
* 使用具体文件 `./vs/loader.js` 作为锚点:Webpack / Rspack 等无法把目录 `./vs/` 当作可解析依赖,会报 Can't resolve。
|
|
8
|
+
* 若宿主把本包打进单 chunk 且未保留 `dist/vs` 静态资源,请在入口 `configureMonacoVsPath` 或传 `monacoVsPath`。
|
|
8
9
|
*/
|
|
9
10
|
declare function getDefaultMonacoVsPath(): string;
|
|
10
11
|
/** 与 {@link getDefaultMonacoVsPath} 在模块加载时解析一次的结果相同 */
|
package/dist/index.js
CHANGED
|
@@ -12,7 +12,8 @@ var Editor__default = /*#__PURE__*/_interopDefault(Editor);
|
|
|
12
12
|
// src/constants.ts
|
|
13
13
|
function getDefaultMonacoVsPath() {
|
|
14
14
|
try {
|
|
15
|
-
|
|
15
|
+
const loaderHref = new URL("./vs/loader.js", (typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.js', document.baseURI).href))).href;
|
|
16
|
+
return loaderHref.replace(/\/?loader\.js$/i, "");
|
|
16
17
|
} catch {
|
|
17
18
|
return "/vs";
|
|
18
19
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/MonacoEditorView.tsx"],"names":["loader","useRef","useEffect","useImperativeHandle","jsx","Editor","forwardRef"],"mappings":";;;;;;;;;;;;
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/MonacoEditorView.tsx"],"names":["loader","useRef","useEffect","useImperativeHandle","jsx","Editor","forwardRef"],"mappings":";;;;;;;;;;;;AAKO,SAAS,sBAAA,GAAiC;AAC/C,EAAA,IAAI;AACF,IAAA,MAAM,aAAa,IAAI,GAAA,CAAI,gBAAA,EAAkB,0PAAe,CAAA,CAAE,IAAA;AAC9D,IAAA,OAAO,UAAA,CAAW,OAAA,CAAQ,iBAAA,EAAmB,EAAE,CAAA;AAAA,EACjD,CAAA,CAAA,MAAQ;AACN,IAAA,OAAO,KAAA;AAAA,EACT;AACF;AAGO,IAAM,yBAAyB,sBAAA;ACEtC,IAAI,sBAAA,GAAwC,IAAA;AAE5C,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,CAAA;AAAA,EAC1B,CAAA;AAEA,EAAA,uBAAOC,cAAA,CAACC,uBAAA,EAAA,EAAQ,GAAG,WAAA,EAAa,SAAS,WAAA,EAAa,CAAA;AACxD;AAEO,IAAM,gBAAA,GAAmBC,iBAG9B,qBAAqB;AAEvB,gBAAA,CAAiB,WAAA,GAAc,kBAAA","file":"index.js","sourcesContent":["/**\n * 本包构建会将 `public/vs` 复制到 `dist/vs`,默认前缀相对 `dist/index.{mjs,js}` 解析。\n * 使用具体文件 `./vs/loader.js` 作为锚点:Webpack / Rspack 等无法把目录 `./vs/` 当作可解析依赖,会报 Can't resolve。\n * 若宿主把本包打进单 chunk 且未保留 `dist/vs` 静态资源,请在入口 `configureMonacoVsPath` 或传 `monacoVsPath`。\n */\nexport function getDefaultMonacoVsPath(): string {\n try {\n const loaderHref = new URL(\"./vs/loader.js\", import.meta.url).href;\n return loaderHref.replace(/\\/?loader\\.js$/i, \"\");\n } catch {\n return \"/vs\";\n }\n}\n\n/** 与 {@link getDefaultMonacoVsPath} 在模块加载时解析一次的结果相同 */\nexport const DEFAULT_MONACO_VS_PATH = getDefaultMonacoVsPath();\n","import Editor, { loader, type OnMount } from \"@monaco-editor/react\";\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n type Ref,\n} from \"react\";\n\nimport { getDefaultMonacoVsPath } from \"./constants\";\nimport type {\n MonacoEditorViewProps,\n MonacoEditorViewRef,\n MonacoStandaloneEditor,\n} from \"./types\";\n\n/** 是否已通过 {@link configureMonacoVsPath} 设置过路径(含「使用包内默认」的一次调用) */\nlet vsPathFromConfigureApi: string | null = null;\n\nfunction resolveVsPath(monacoVsPath: string | false | undefined): string | false {\n if (monacoVsPath === false) {\n return false;\n }\n if (monacoVsPath !== undefined) {\n return monacoVsPath;\n }\n if (vsPathFromConfigureApi !== null) {\n return vsPathFromConfigureApi;\n }\n return getDefaultMonacoVsPath();\n}\n\n/**\n * 在应用入口可选调用一次,统一指定 Monaco `vs` 目录 URL。\n * - 不传参:使用包内随 `dist/vs` 发布的资源(构建由 `public/vs` 复制而来)。\n * - 传参:使用自定义地址(CDN、宿主静态目录等)。\n */\nexport function configureMonacoVsPath(vsPath?: string) {\n const vs = vsPath ?? getDefaultMonacoVsPath();\n vsPathFromConfigureApi = vs;\n loader.config({ paths: { vs } });\n}\n\nfunction MonacoEditorViewInner(\n props: MonacoEditorViewProps,\n ref: Ref<MonacoEditorViewRef>,\n) {\n const { monacoVsPath, onMount: userOnMount, ...editorProps } = props;\n const editorRef = useRef<MonacoStandaloneEditor | null>(null);\n\n useEffect(() => {\n const vs = resolveVsPath(monacoVsPath);\n if (vs === false) {\n return;\n }\n loader.config({ paths: { vs } });\n }, [monacoVsPath]);\n\n useImperativeHandle(ref, () => ({\n getEditor: () => editorRef.current,\n getValue: () => editorRef.current?.getValue(),\n }));\n\n const handleMount: OnMount = (ed, monaco) => {\n editorRef.current = ed;\n userOnMount?.(ed, monaco);\n };\n\n return <Editor {...editorProps} onMount={handleMount} />;\n}\n\nexport const MonacoEditorView = forwardRef<\n MonacoEditorViewRef,\n MonacoEditorViewProps\n>(MonacoEditorViewInner);\n\nMonacoEditorView.displayName = \"MonacoEditorView\";\n"]}
|
package/dist/index.mjs
CHANGED
|
@@ -5,7 +5,8 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
5
5
|
// src/constants.ts
|
|
6
6
|
function getDefaultMonacoVsPath() {
|
|
7
7
|
try {
|
|
8
|
-
|
|
8
|
+
const loaderHref = new URL("./vs/loader.js", import.meta.url).href;
|
|
9
|
+
return loaderHref.replace(/\/?loader\.js$/i, "");
|
|
9
10
|
} catch {
|
|
10
11
|
return "/vs";
|
|
11
12
|
}
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/constants.ts","../src/MonacoEditorView.tsx"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"sources":["../src/constants.ts","../src/MonacoEditorView.tsx"],"names":[],"mapp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AA,EACjC,CAAA,EAAG,CAAC,YAAY,CAAC,CAAA;AAEjB,EAAA,mBAAA,CAAoB,KAAK,OAAO;AAAA,IAC9B,SAAA,EAAW,MAAM,SAAA,CAAU,OAAA;AAAA,IAC3B,QAAA,EAAU,MAAM,SAAA,CAAU,OAAA,EAAS,QAAA;AAAS,GAC9C,CAAE,CAAA;AAEF,EAAA,MAAM,WAAA,GAAuB,CAAC,EAAA,EAAI,MAAA,KAAW;AAC3C,IAAA,SAAA,CAAU,OAAA,GAAU,EAAA;AACpB,IAAA,WAAA,GAAc,IAAI,MAAM,CAAA;AAAA,EAC1B,CAAA;AAEA,EAAA,uBAAO,GAAA,CAAC,MAAA,EAAA,EAAQ,GAAG,WAAA,EAAa,SAAS,WAAA,EAAa,CAAA;AACxD;AAEO,IAAM,gBAAA,GAAmB,WAG9B,qBAAqB;AAEvB,gBAAA,CAAiB,WAAA,GAAc,kBAAA","file":"index.mjs","sourcesContent":["/**\n * 本包构建会将 `public/vs` 复制到 `dist/vs`,默认前缀相对 `dist/index.{mjs,js}` 解析。\n * 使用具体文件 `./vs/loader.js` 作为锚点:Webpack / Rspack 等无法把目录 `./vs/` 当作可解析依赖,会报 Can't resolve。\n * 若宿主把本包打进单 chunk 且未保留 `dist/vs` 静态资源,请在入口 `configureMonacoVsPath` 或传 `monacoVsPath`。\n */\nexport function getDefaultMonacoVsPath(): string {\n try {\n const loaderHref = new URL(\"./vs/loader.js\", import.meta.url).href;\n return loaderHref.replace(/\\/?loader\\.js$/i, \"\");\n } catch {\n return \"/vs\";\n }\n}\n\n/** 与 {@link getDefaultMonacoVsPath} 在模块加载时解析一次的结果相同 */\nexport const DEFAULT_MONACO_VS_PATH = getDefaultMonacoVsPath();\n","import Editor, { loader, type OnMount } from \"@monaco-editor/react\";\nimport {\n forwardRef,\n useEffect,\n useImperativeHandle,\n useRef,\n type Ref,\n} from \"react\";\n\nimport { getDefaultMonacoVsPath } from \"./constants\";\nimport type {\n MonacoEditorViewProps,\n MonacoEditorViewRef,\n MonacoStandaloneEditor,\n} from \"./types\";\n\n/** 是否已通过 {@link configureMonacoVsPath} 设置过路径(含「使用包内默认」的一次调用) */\nlet vsPathFromConfigureApi: string | null = null;\n\nfunction resolveVsPath(monacoVsPath: string | false | undefined): string | false {\n if (monacoVsPath === false) {\n return false;\n }\n if (monacoVsPath !== undefined) {\n return monacoVsPath;\n }\n if (vsPathFromConfigureApi !== null) {\n return vsPathFromConfigureApi;\n }\n return getDefaultMonacoVsPath();\n}\n\n/**\n * 在应用入口可选调用一次,统一指定 Monaco `vs` 目录 URL。\n * - 不传参:使用包内随 `dist/vs` 发布的资源(构建由 `public/vs` 复制而来)。\n * - 传参:使用自定义地址(CDN、宿主静态目录等)。\n */\nexport function configureMonacoVsPath(vsPath?: string) {\n const vs = vsPath ?? getDefaultMonacoVsPath();\n vsPathFromConfigureApi = vs;\n loader.config({ paths: { vs } });\n}\n\nfunction MonacoEditorViewInner(\n props: MonacoEditorViewProps,\n ref: Ref<MonacoEditorViewRef>,\n) {\n const { monacoVsPath, onMount: userOnMount, ...editorProps } = props;\n const editorRef = useRef<MonacoStandaloneEditor | null>(null);\n\n useEffect(() => {\n const vs = resolveVsPath(monacoVsPath);\n if (vs === false) {\n return;\n }\n loader.config({ paths: { vs } });\n }, [monacoVsPath]);\n\n useImperativeHandle(ref, () => ({\n getEditor: () => editorRef.current,\n getValue: () => editorRef.current?.getValue(),\n }));\n\n const handleMount: OnMount = (ed, monaco) => {\n editorRef.current = ed;\n userOnMount?.(ed, monaco);\n };\n\n return <Editor {...editorProps} onMount={handleMount} />;\n}\n\nexport const MonacoEditorView = forwardRef<\n MonacoEditorViewRef,\n MonacoEditorViewProps\n>(MonacoEditorViewInner);\n\nMonacoEditorView.displayName = \"MonacoEditorView\";\n"]}
|