@willbooster/monaco-react 2.0.0 → 2.0.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/README.md +3 -4
- package/dist/DiffEditor/DiffEditor.cjs +1 -1
- package/dist/DiffEditor/DiffEditor.cjs.map +1 -1
- package/dist/DiffEditor/DiffEditor.js +1 -1
- package/dist/DiffEditor/DiffEditor.js.map +1 -1
- package/dist/DiffEditor/index.cjs.map +1 -1
- package/dist/DiffEditor/index.js.map +1 -1
- package/dist/Editor/Editor.cjs +1 -1
- package/dist/Editor/Editor.cjs.map +1 -1
- package/dist/Editor/Editor.js +1 -1
- package/dist/Editor/Editor.js.map +1 -1
- package/dist/Editor/index.cjs.map +1 -1
- package/dist/Editor/index.js.map +1 -1
- package/dist/Loading/Loading.cjs +1 -1
- package/dist/Loading/Loading.cjs.map +1 -1
- package/dist/Loading/Loading.js +1 -1
- package/dist/Loading/Loading.js.map +1 -1
- package/dist/Loading/index.cjs.map +1 -1
- package/dist/Loading/index.js.map +1 -1
- package/dist/Loading/styles.cjs.map +1 -1
- package/dist/Loading/styles.js.map +1 -1
- package/dist/MonacoContainer/MonacoContainer.cjs +1 -1
- package/dist/MonacoContainer/MonacoContainer.cjs.map +1 -1
- package/dist/MonacoContainer/MonacoContainer.js +1 -1
- package/dist/MonacoContainer/MonacoContainer.js.map +1 -1
- package/dist/MonacoContainer/index.cjs.map +1 -1
- package/dist/MonacoContainer/index.js.map +1 -1
- package/dist/MonacoContainer/styles.cjs.map +1 -1
- package/dist/MonacoContainer/styles.js.map +1 -1
- package/dist/_virtual/_rolldown/runtime.cjs +1 -1
- package/dist/hooks/useMonaco/index.cjs.map +1 -1
- package/dist/hooks/useMonaco/index.js.map +1 -1
- package/dist/hooks/useMonaco/initMonaco.cjs.map +1 -1
- package/dist/hooks/useMonaco/initMonaco.js.map +1 -1
- package/dist/hooks/useMount/index.cjs.map +1 -1
- package/dist/hooks/useMount/index.js.map +1 -1
- package/dist/hooks/usePrevious/index.cjs.map +1 -1
- package/dist/hooks/usePrevious/index.js.map +1 -1
- package/dist/hooks/useUpdate/index.cjs.map +1 -1
- package/dist/hooks/useUpdate/index.js.map +1 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js.map +1 -1
- package/dist/utils/index.cjs.map +1 -1
- package/dist/utils/index.js.map +1 -1
- package/package.json +13 -11
package/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# @willbooster/monaco-react
|
|
2
2
|
|
|
3
|
+
[](https://www.npmjs.com/package/@willbooster/monaco-react)
|
|
4
|
+
[](https://www.npmjs.com/package/@willbooster/monaco-react)
|
|
3
5
|
[](https://github.com/WillBooster/monaco-react/actions/workflows/test.yml)
|
|
4
6
|
[](https://github.com/semantic-release/semantic-release)
|
|
5
|
-
[](https://www.npmjs.com/package/@willbooster/monaco-react)
|
|
8
|
-
[](https://www.npmjs.com/package/@willbooster/monaco-react)
|
|
7
|
+
[](https://github.com/WillBooster/shared/tree/main/packages/wbfy)
|
|
9
8
|
|
|
10
9
|
React components for [Monaco Editor](https://microsoft.github.io/monaco-editor/), powered by [`@willbooster/monaco-loader`](https://github.com/WillBooster/monaco-loader).
|
|
11
10
|
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";const e=require("../MonacoContainer/index.cjs"),t=require("../hooks/useMount/index.cjs"),n=require("../hooks/useUpdate/index.cjs"),r=require("../hooks/useMonaco/index.cjs"),i=require("../utils/index.cjs");let a=require("react"),o=require("react/jsx-runtime");function s(t){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:s,wrapperProps:l={}}=t;return(0,o.jsx)(a.Suspense,{fallback
|
|
1
|
+
"use strict";"use client";const e=require("../MonacoContainer/index.cjs"),t=require("../hooks/useMount/index.cjs"),n=require("../hooks/useUpdate/index.cjs"),r=require("../hooks/useMonaco/index.cjs"),i=require("../utils/index.cjs");let a=require("react"),o=require("react/jsx-runtime");function s(t){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:s,wrapperProps:l={}}=t;return/* @__PURE__ */ (0,o.jsx)(a.Suspense,{fallback:/* @__PURE__ */ (0,o.jsx)(e.default,{width:n,height:r,isEditorReady:!1,loading:i,className:s,wrapperProps:l}),children:/* @__PURE__ */ (0,o.jsx)(c,{...t})})}function c(t){let n=r.default();if(!n){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:a,wrapperProps:s={}}=t;return/* @__PURE__ */ (0,o.jsx)(e.default,{width:n,height:r,isEditorReady:!1,loading:i,className:a,wrapperProps:s})}return/* @__PURE__ */ (0,o.jsx)(l,{...t,monaco:n})}function l({monaco:r,original:s,modified:c,language:l,originalLanguage:u,modifiedLanguage:d,originalModelPath:f,modifiedModelPath:p,keepCurrentOriginalModel:m=!1,keepCurrentModifiedModel:h=!1,theme:g=`light`,loading:_=`Loading...`,options:v={},height:y=`100%`,width:b=`100%`,className:x,wrapperProps:S={},beforeMount:C=i.noop,onMount:w=i.noop}){let[T,E]=(0,a.useState)(!1),D=(0,a.useRef)(null),O=(0,a.useRef)(r),k=(0,a.useRef)(null),A=(0,a.useRef)(w),j=(0,a.useRef)(C),M=(0,a.useRef)(!1);O.current=r,t.default(()=>()=>{D.current&&F()}),n.default(()=>{if(D.current&&O.current){let e=D.current.getOriginalEditor(),t=i.getOrCreateModel(O.current,s||``,u||l||`text`,f||``);t!==e.getModel()&&e.setModel(t)}},[f],T),n.default(()=>{if(D.current&&O.current){let e=D.current.getModifiedEditor(),t=i.getOrCreateModel(O.current,c||``,d||l||`text`,p||``);t!==e.getModel()&&e.setModel(t)}},[p],T),n.default(()=>{let e=D.current.getModifiedEditor();e.getOption(O.current.editor.EditorOption.readOnly)?e.setValue(c||``):c!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:c||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[c],T),n.default(()=>{D.current?.getModel()?.original.setValue(s||``)},[s],T),n.default(()=>{let{original:e,modified:t}=D.current.getModel();O.current.editor.setModelLanguage(e,u||l||`text`),O.current.editor.setModelLanguage(t,d||l||`text`)},[l,u,d],T),n.default(()=>{O.current?.editor.setTheme(g)},[g],T),n.default(()=>{D.current?.updateOptions(v)},[v],T);let N=(0,a.useCallback)(()=>{j.current(O.current);let e=i.getOrCreateModel(O.current,s||``,u||l||`text`,f||``),t=i.getOrCreateModel(O.current,c||``,d||l||`text`,p||``);D.current?.setModel({original:e,modified:t})},[l,c,d,s,u,f,p]),P=(0,a.useCallback)(()=>{!M.current&&k.current&&(D.current=O.current.editor.createDiffEditor(k.current,{automaticLayout:!0,...v}),N(),O.current?.editor.setTheme(g),E(!0),M.current=!0)},[v,g,N]);(0,a.useEffect)(()=>{T&&A.current(D.current,O.current)},[T]),(0,a.useEffect)(()=>{T||P()},[T,P]);function F(){let e=D.current,t=e?.getModel();e?.getOriginalEditor().setModel(null),e?.getModifiedEditor().setModel(null),e?.dispose(),!m&&t?.original&&!t.original.isDisposed()&&!t.original.isAttachedToEditor()&&t.original.dispose(),!h&&t?.modified&&!t.modified.isDisposed()&&!t.modified.isAttachedToEditor()&&t.modified.dispose(),D.current=null,M.current=!1,E(!1)}return/* @__PURE__ */ (0,o.jsx)(e.default,{width:b,height:y,isEditorReady:T,loading:_,_ref:k,className:x,wrapperProps:S})}exports.default=s;
|
|
2
2
|
//# sourceMappingURL=DiffEditor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiffEditor.cjs","names":["Suspense","MonacoContainer","useMonaco","noop","getOrCreateModel"],"sources":["../../src/DiffEditor/DiffEditor.tsx"],"sourcesContent":["'use client';\n\nimport { Suspense, useState, useRef, useCallback, useEffect } from 'react';\nimport type { ReactElement } from 'react';\n\nimport MonacoContainer from '../MonacoContainer';\nimport useMount from '../hooks/useMount';\nimport useUpdate from '../hooks/useUpdate';\nimport useMonaco from '../hooks/useMonaco';\nimport { noop, getOrCreateModel } from '../utils';\nimport type { DiffEditorProps, MonacoDiffEditor } from './types';\nimport type { Monaco } from '..';\n\nfunction DiffEditor(props: DiffEditorProps): ReactElement {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <Suspense\n fallback={\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n }\n >\n <DiffEditorContent {...props} />\n </Suspense>\n );\n}\n\nfunction DiffEditorContent(props: DiffEditorProps): ReactElement {\n const monaco = useMonaco();\n\n if (!monaco) {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n }\n\n return <MountedDiffEditor {...props} monaco={monaco} />;\n}\n\nfunction MountedDiffEditor({\n monaco,\n original,\n modified,\n language,\n originalLanguage,\n modifiedLanguage,\n originalModelPath,\n modifiedModelPath,\n keepCurrentOriginalModel = false,\n keepCurrentModifiedModel = false,\n theme = 'light',\n loading = 'Loading...',\n options = {},\n height = '100%',\n width = '100%',\n className,\n wrapperProps = {},\n beforeMount = noop,\n onMount = noop,\n}: DiffEditorProps & { monaco: Monaco }): ReactElement {\n const [isEditorReady, setIsEditorReady] = useState(false);\n const editorRef = useRef<MonacoDiffEditor | null>(null);\n const monacoRef = useRef<Monaco>(monaco);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const onMountRef = useRef(onMount);\n const beforeMountRef = useRef(beforeMount);\n const preventCreation = useRef(false);\n\n monacoRef.current = monaco;\n\n useMount(() => {\n return () => {\n if (editorRef.current) {\n disposeEditor();\n }\n };\n });\n\n useUpdate(\n () => {\n if (editorRef.current && monacoRef.current) {\n const originalEditor = editorRef.current.getOriginalEditor();\n const model = getOrCreateModel(\n monacoRef.current,\n original || '',\n originalLanguage || language || 'text',\n originalModelPath || ''\n );\n\n if (model !== originalEditor.getModel()) {\n originalEditor.setModel(model);\n }\n }\n },\n [originalModelPath],\n isEditorReady\n );\n\n useUpdate(\n () => {\n if (editorRef.current && monacoRef.current) {\n const modifiedEditor = editorRef.current.getModifiedEditor();\n const model = getOrCreateModel(\n monacoRef.current,\n modified || '',\n modifiedLanguage || language || 'text',\n modifiedModelPath || ''\n );\n\n if (model !== modifiedEditor.getModel()) {\n modifiedEditor.setModel(model);\n }\n }\n },\n [modifiedModelPath],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const modifiedEditor = editorRef.current!.getModifiedEditor();\n if (modifiedEditor.getOption(monacoRef.current!.editor.EditorOption.readOnly)) {\n modifiedEditor.setValue(modified || '');\n } else {\n if (modified !== modifiedEditor.getValue()) {\n modifiedEditor.executeEdits('', [\n {\n range: modifiedEditor.getModel()!.getFullModelRange(),\n text: modified || '',\n forceMoveMarkers: true,\n },\n ]);\n\n modifiedEditor.pushUndoStop();\n }\n }\n },\n [modified],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.getModel()?.original.setValue(original || '');\n },\n [original],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const { original, modified } = editorRef.current!.getModel()!;\n\n monacoRef.current!.editor.setModelLanguage(original, originalLanguage || language || 'text');\n monacoRef.current!.editor.setModelLanguage(modified, modifiedLanguage || language || 'text');\n },\n [language, originalLanguage, modifiedLanguage],\n isEditorReady\n );\n\n useUpdate(\n () => {\n monacoRef.current?.editor.setTheme(theme);\n },\n [theme],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.updateOptions(options);\n },\n [options],\n isEditorReady\n );\n\n const setModels = useCallback(() => {\n beforeMountRef.current(monacoRef.current);\n const originalModel = getOrCreateModel(\n monacoRef.current,\n original || '',\n originalLanguage || language || 'text',\n originalModelPath || ''\n );\n\n const modifiedModel = getOrCreateModel(\n monacoRef.current,\n modified || '',\n modifiedLanguage || language || 'text',\n modifiedModelPath || ''\n );\n\n editorRef.current?.setModel({\n original: originalModel,\n modified: modifiedModel,\n });\n }, [language, modified, modifiedLanguage, original, originalLanguage, originalModelPath, modifiedModelPath]);\n\n const createEditor = useCallback(() => {\n if (!preventCreation.current && containerRef.current) {\n editorRef.current = monacoRef.current!.editor.createDiffEditor(containerRef.current, {\n automaticLayout: true,\n ...options,\n });\n\n setModels();\n\n monacoRef.current?.editor.setTheme(theme);\n\n setIsEditorReady(true);\n preventCreation.current = true;\n }\n }, [options, theme, setModels]);\n\n useEffect(() => {\n if (isEditorReady) {\n onMountRef.current(editorRef.current!, monacoRef.current!);\n }\n }, [isEditorReady]);\n\n useEffect(() => {\n if (!isEditorReady) {\n createEditor();\n }\n }, [isEditorReady, createEditor]);\n\n function disposeEditor(): void {\n const editor = editorRef.current;\n const models = editor?.getModel();\n\n // Detach inner editor models first so editor.dispose() never reads from a model that another owner disposed.\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor?.getOriginalEditor().setModel(null);\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor?.getModifiedEditor().setModel(null);\n editor?.dispose();\n\n if (\n !keepCurrentOriginalModel &&\n models?.original &&\n !models.original.isDisposed() &&\n !models.original.isAttachedToEditor()\n ) {\n models.original.dispose();\n }\n\n if (\n !keepCurrentModifiedModel &&\n models?.modified &&\n !models.modified.isDisposed() &&\n !models.modified.isAttachedToEditor()\n ) {\n models.modified.dispose();\n }\n\n // oxlint-disable-next-line unicorn/no-null -- React refs use null after unmount.\n editorRef.current = null;\n preventCreation.current = false;\n setIsEditorReady(false);\n }\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={isEditorReady}\n loading={loading}\n _ref={containerRef}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n}\n\nexport default DiffEditor;\n"],"mappings":"6RAaA,SAAS,EAAW,EAAsC,CACxD,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAM,EAElG,OACE,EAAA,EAAA,IAAA,CAACA,EAAAA,SAAD,CACE,UACE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AC,GACD,GAAQ,UACR,CAAC,EAAO,SAAS,WAAW,GAC5B,CAAC,EAAO,SAAS,mBAAmB,GAEpC,EAAO,SAAS,QAAQ,EAI1B,EAAU,QAAU,KACpB,EAAgB,QAAU,GAC1B,EAAiB,EAAK,CACxB,CAEA,OACE,EAAA,EAAA,IAAA,CAACH,EAAAA,QAAD,CACS,QACC,SACO,gBACN,UACT,KAAM,EACK,YACG,cACf,CAAA,CAEL"}
|
|
1
|
+
{"version":3,"file":"DiffEditor.cjs","names":["Suspense","MonacoContainer","useMonaco","noop","useState","useRef","getOrCreateModel","useCallback","require_index","require_index$1","require_index$2","require_index$3","require_index$4","react","react_jsx_runtime","DiffEditor","props","DiffEditorContent","monaco","MountedDiffEditor","isEditorReady","setIsEditorReady","editorRef","monacoRef","containerRef","onMountRef","onMount","beforeMountRef","beforeMount","preventCreation","disposeEditor","originalEditor","model","original","originalLanguage","language","originalModelPath","modifiedEditor","modified","modifiedLanguage","modifiedModelPath","theme","options","setModels","originalModel","modifiedModel","createEditor","editor","models","keepCurrentOriginalModel","keepCurrentModifiedModel"],"sources":["../../src/DiffEditor/DiffEditor.tsx"],"sourcesContent":["'use client';\n\nimport { Suspense, useState, useRef, useCallback, useEffect } from 'react';\nimport type { ReactElement } from 'react';\n\nimport MonacoContainer from '../MonacoContainer';\nimport useMount from '../hooks/useMount';\nimport useUpdate from '../hooks/useUpdate';\nimport useMonaco from '../hooks/useMonaco';\nimport { noop, getOrCreateModel } from '../utils';\nimport type { DiffEditorProps, MonacoDiffEditor } from './types';\nimport type { Monaco } from '..';\n\nfunction DiffEditor(props: DiffEditorProps): ReactElement {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <Suspense\n fallback={\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n }\n >\n <DiffEditorContent {...props} />\n </Suspense>\n );\n}\n\nfunction DiffEditorContent(props: DiffEditorProps): ReactElement {\n const monaco = useMonaco();\n\n if (!monaco) {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n }\n\n return <MountedDiffEditor {...props} monaco={monaco} />;\n}\n\nfunction MountedDiffEditor({\n monaco,\n original,\n modified,\n language,\n originalLanguage,\n modifiedLanguage,\n originalModelPath,\n modifiedModelPath,\n keepCurrentOriginalModel = false,\n keepCurrentModifiedModel = false,\n theme = 'light',\n loading = 'Loading...',\n options = {},\n height = '100%',\n width = '100%',\n className,\n wrapperProps = {},\n beforeMount = noop,\n onMount = noop,\n}: DiffEditorProps & { monaco: Monaco }): ReactElement {\n const [isEditorReady, setIsEditorReady] = useState(false);\n const editorRef = useRef<MonacoDiffEditor | null>(null);\n const monacoRef = useRef<Monaco>(monaco);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const onMountRef = useRef(onMount);\n const beforeMountRef = useRef(beforeMount);\n const preventCreation = useRef(false);\n\n monacoRef.current = monaco;\n\n useMount(() => {\n return () => {\n if (editorRef.current) {\n disposeEditor();\n }\n };\n });\n\n useUpdate(\n () => {\n if (editorRef.current && monacoRef.current) {\n const originalEditor = editorRef.current.getOriginalEditor();\n const model = getOrCreateModel(\n monacoRef.current,\n original || '',\n originalLanguage || language || 'text',\n originalModelPath || ''\n );\n\n if (model !== originalEditor.getModel()) {\n originalEditor.setModel(model);\n }\n }\n },\n [originalModelPath],\n isEditorReady\n );\n\n useUpdate(\n () => {\n if (editorRef.current && monacoRef.current) {\n const modifiedEditor = editorRef.current.getModifiedEditor();\n const model = getOrCreateModel(\n monacoRef.current,\n modified || '',\n modifiedLanguage || language || 'text',\n modifiedModelPath || ''\n );\n\n if (model !== modifiedEditor.getModel()) {\n modifiedEditor.setModel(model);\n }\n }\n },\n [modifiedModelPath],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const modifiedEditor = editorRef.current!.getModifiedEditor();\n if (modifiedEditor.getOption(monacoRef.current!.editor.EditorOption.readOnly)) {\n modifiedEditor.setValue(modified || '');\n } else {\n if (modified !== modifiedEditor.getValue()) {\n modifiedEditor.executeEdits('', [\n {\n range: modifiedEditor.getModel()!.getFullModelRange(),\n text: modified || '',\n forceMoveMarkers: true,\n },\n ]);\n\n modifiedEditor.pushUndoStop();\n }\n }\n },\n [modified],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.getModel()?.original.setValue(original || '');\n },\n [original],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const { original, modified } = editorRef.current!.getModel()!;\n\n monacoRef.current!.editor.setModelLanguage(original, originalLanguage || language || 'text');\n monacoRef.current!.editor.setModelLanguage(modified, modifiedLanguage || language || 'text');\n },\n [language, originalLanguage, modifiedLanguage],\n isEditorReady\n );\n\n useUpdate(\n () => {\n monacoRef.current?.editor.setTheme(theme);\n },\n [theme],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.updateOptions(options);\n },\n [options],\n isEditorReady\n );\n\n const setModels = useCallback(() => {\n beforeMountRef.current(monacoRef.current);\n const originalModel = getOrCreateModel(\n monacoRef.current,\n original || '',\n originalLanguage || language || 'text',\n originalModelPath || ''\n );\n\n const modifiedModel = getOrCreateModel(\n monacoRef.current,\n modified || '',\n modifiedLanguage || language || 'text',\n modifiedModelPath || ''\n );\n\n editorRef.current?.setModel({\n original: originalModel,\n modified: modifiedModel,\n });\n }, [language, modified, modifiedLanguage, original, originalLanguage, originalModelPath, modifiedModelPath]);\n\n const createEditor = useCallback(() => {\n if (!preventCreation.current && containerRef.current) {\n editorRef.current = monacoRef.current!.editor.createDiffEditor(containerRef.current, {\n automaticLayout: true,\n ...options,\n });\n\n setModels();\n\n monacoRef.current?.editor.setTheme(theme);\n\n setIsEditorReady(true);\n preventCreation.current = true;\n }\n }, [options, theme, setModels]);\n\n useEffect(() => {\n if (isEditorReady) {\n onMountRef.current(editorRef.current!, monacoRef.current!);\n }\n }, [isEditorReady]);\n\n useEffect(() => {\n if (!isEditorReady) {\n createEditor();\n }\n }, [isEditorReady, createEditor]);\n\n function disposeEditor(): void {\n const editor = editorRef.current;\n const models = editor?.getModel();\n\n // Detach inner editor models first so editor.dispose() never reads from a model that another owner disposed.\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor?.getOriginalEditor().setModel(null);\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor?.getModifiedEditor().setModel(null);\n editor?.dispose();\n\n if (\n !keepCurrentOriginalModel &&\n models?.original &&\n !models.original.isDisposed() &&\n !models.original.isAttachedToEditor()\n ) {\n models.original.dispose();\n }\n\n if (\n !keepCurrentModifiedModel &&\n models?.modified &&\n !models.modified.isDisposed() &&\n !models.modified.isAttachedToEditor()\n ) {\n models.modified.dispose();\n }\n\n // oxlint-disable-next-line unicorn/no-null -- React refs use null after unmount.\n editorRef.current = null;\n preventCreation.current = false;\n setIsEditorReady(false);\n }\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={isEditorReady}\n loading={loading}\n _ref={containerRef}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n}\n\nexport default DiffEditor;\n"],"mappings":"6RAaA,SAASe,EAAW,EAAsC,CACxD,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAMC,EAElG,MACE,iBAAA,EAAAF,EAAA,IAAA,CAACd,EAAAA,SAAD,CACE,SACE,iBAAA,EAAAc,EAAA,IAAA,CAACb,EAAAA,QAAD,CACS,QACC,SACR,cAAe,GACN,UACE,YACG,cACf,CAAA,EAGH,SAAA,iBAAA,EAAAa,EAAA,IAAA,CAACG,EAAD,CAAmB,GAAID,CAAQ,CAAA,CACvB,CAAA,CAEd,CAEA,SAASC,EAAkB,EAAsC,CAC/D,IAAMC,EAAShB,EAAAA,QAAU,EAEzB,GAAI,CAACgB,EAAQ,CACX,GA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EAIxB,CAACE,GACDF,GAAQ,UACR,CAACA,EAAO,SAAS,WAAW,GAC5B,CAACA,EAAO,SAAS,mBAAmB,GAEpCA,EAAO,SAAS,QAAQ,EAI1B,EAAU,QAAU,KACpB,EAAgB,QAAU,GAC1B3B,EAAiB,EAAK,CACxB,CAEA,MACE,iBAAA,EAAAP,EAAA,IAAA,CAACb,EAAAA,QAAD,CACS,QACC,SACO,gBACN,UACT,KAAMuB,EACK,YACG,cACf,CAAA,CAEL"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import e from"../MonacoContainer/index.js";import t from"../hooks/useMount/index.js";import n from"../hooks/useUpdate/index.js";import r from"../hooks/useMonaco/index.js";import{getOrCreateModel as i,noop as a}from"../utils/index.js";import{Suspense as o,useCallback as s,useEffect as c,useRef as l,useState as u}from"react";import{jsx as d}from"react/jsx-runtime";function f(t){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:a,wrapperProps:s={}}=t;return d(o,{fallback
|
|
1
|
+
"use client";import e from"../MonacoContainer/index.js";import t from"../hooks/useMount/index.js";import n from"../hooks/useUpdate/index.js";import r from"../hooks/useMonaco/index.js";import{getOrCreateModel as i,noop as a}from"../utils/index.js";import{Suspense as o,useCallback as s,useEffect as c,useRef as l,useState as u}from"react";import{jsx as d}from"react/jsx-runtime";function f(t){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:a,wrapperProps:s={}}=t;return/* @__PURE__ */ d(o,{fallback:/* @__PURE__ */ d(e,{width:n,height:r,isEditorReady:!1,loading:i,className:a,wrapperProps:s}),children:/* @__PURE__ */ d(p,{...t})})}function p(t){let n=r();if(!n){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:a,wrapperProps:o={}}=t;return/* @__PURE__ */ d(e,{width:n,height:r,isEditorReady:!1,loading:i,className:a,wrapperProps:o})}return/* @__PURE__ */ d(m,{...t,monaco:n})}function m({monaco:r,original:o,modified:f,language:p,originalLanguage:m,modifiedLanguage:h,originalModelPath:g,modifiedModelPath:_,keepCurrentOriginalModel:v=!1,keepCurrentModifiedModel:y=!1,theme:b=`light`,loading:x=`Loading...`,options:S={},height:C=`100%`,width:w=`100%`,className:T,wrapperProps:E={},beforeMount:D=a,onMount:O=a}){let[k,A]=u(!1),j=l(null),M=l(r),N=l(null),P=l(O),F=l(D),I=l(!1);M.current=r,t(()=>()=>{j.current&&z()}),n(()=>{if(j.current&&M.current){let e=j.current.getOriginalEditor(),t=i(M.current,o||``,m||p||`text`,g||``);t!==e.getModel()&&e.setModel(t)}},[g],k),n(()=>{if(j.current&&M.current){let e=j.current.getModifiedEditor(),t=i(M.current,f||``,h||p||`text`,_||``);t!==e.getModel()&&e.setModel(t)}},[_],k),n(()=>{let e=j.current.getModifiedEditor();e.getOption(M.current.editor.EditorOption.readOnly)?e.setValue(f||``):f!==e.getValue()&&(e.executeEdits(``,[{range:e.getModel().getFullModelRange(),text:f||``,forceMoveMarkers:!0}]),e.pushUndoStop())},[f],k),n(()=>{j.current?.getModel()?.original.setValue(o||``)},[o],k),n(()=>{let{original:e,modified:t}=j.current.getModel();M.current.editor.setModelLanguage(e,m||p||`text`),M.current.editor.setModelLanguage(t,h||p||`text`)},[p,m,h],k),n(()=>{M.current?.editor.setTheme(b)},[b],k),n(()=>{j.current?.updateOptions(S)},[S],k);let L=s(()=>{F.current(M.current);let e=i(M.current,o||``,m||p||`text`,g||``),t=i(M.current,f||``,h||p||`text`,_||``);j.current?.setModel({original:e,modified:t})},[p,f,h,o,m,g,_]),R=s(()=>{!I.current&&N.current&&(j.current=M.current.editor.createDiffEditor(N.current,{automaticLayout:!0,...S}),L(),M.current?.editor.setTheme(b),A(!0),I.current=!0)},[S,b,L]);c(()=>{k&&P.current(j.current,M.current)},[k]),c(()=>{k||R()},[k,R]);function z(){let e=j.current,t=e?.getModel();e?.getOriginalEditor().setModel(null),e?.getModifiedEditor().setModel(null),e?.dispose(),!v&&t?.original&&!t.original.isDisposed()&&!t.original.isAttachedToEditor()&&t.original.dispose(),!y&&t?.modified&&!t.modified.isDisposed()&&!t.modified.isAttachedToEditor()&&t.modified.dispose(),j.current=null,I.current=!1,A(!1)}return/* @__PURE__ */ d(e,{width:w,height:C,isEditorReady:k,loading:x,_ref:N,className:T,wrapperProps:E})}export{f as default};
|
|
2
2
|
//# sourceMappingURL=DiffEditor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DiffEditor.js","names":["MonacoContainer"],"sources":["../../src/DiffEditor/DiffEditor.tsx"],"sourcesContent":["'use client';\n\nimport { Suspense, useState, useRef, useCallback, useEffect } from 'react';\nimport type { ReactElement } from 'react';\n\nimport MonacoContainer from '../MonacoContainer';\nimport useMount from '../hooks/useMount';\nimport useUpdate from '../hooks/useUpdate';\nimport useMonaco from '../hooks/useMonaco';\nimport { noop, getOrCreateModel } from '../utils';\nimport type { DiffEditorProps, MonacoDiffEditor } from './types';\nimport type { Monaco } from '..';\n\nfunction DiffEditor(props: DiffEditorProps): ReactElement {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <Suspense\n fallback={\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n }\n >\n <DiffEditorContent {...props} />\n </Suspense>\n );\n}\n\nfunction DiffEditorContent(props: DiffEditorProps): ReactElement {\n const monaco = useMonaco();\n\n if (!monaco) {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n }\n\n return <MountedDiffEditor {...props} monaco={monaco} />;\n}\n\nfunction MountedDiffEditor({\n monaco,\n original,\n modified,\n language,\n originalLanguage,\n modifiedLanguage,\n originalModelPath,\n modifiedModelPath,\n keepCurrentOriginalModel = false,\n keepCurrentModifiedModel = false,\n theme = 'light',\n loading = 'Loading...',\n options = {},\n height = '100%',\n width = '100%',\n className,\n wrapperProps = {},\n beforeMount = noop,\n onMount = noop,\n}: DiffEditorProps & { monaco: Monaco }): ReactElement {\n const [isEditorReady, setIsEditorReady] = useState(false);\n const editorRef = useRef<MonacoDiffEditor | null>(null);\n const monacoRef = useRef<Monaco>(monaco);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const onMountRef = useRef(onMount);\n const beforeMountRef = useRef(beforeMount);\n const preventCreation = useRef(false);\n\n monacoRef.current = monaco;\n\n useMount(() => {\n return () => {\n if (editorRef.current) {\n disposeEditor();\n }\n };\n });\n\n useUpdate(\n () => {\n if (editorRef.current && monacoRef.current) {\n const originalEditor = editorRef.current.getOriginalEditor();\n const model = getOrCreateModel(\n monacoRef.current,\n original || '',\n originalLanguage || language || 'text',\n originalModelPath || ''\n );\n\n if (model !== originalEditor.getModel()) {\n originalEditor.setModel(model);\n }\n }\n },\n [originalModelPath],\n isEditorReady\n );\n\n useUpdate(\n () => {\n if (editorRef.current && monacoRef.current) {\n const modifiedEditor = editorRef.current.getModifiedEditor();\n const model = getOrCreateModel(\n monacoRef.current,\n modified || '',\n modifiedLanguage || language || 'text',\n modifiedModelPath || ''\n );\n\n if (model !== modifiedEditor.getModel()) {\n modifiedEditor.setModel(model);\n }\n }\n },\n [modifiedModelPath],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const modifiedEditor = editorRef.current!.getModifiedEditor();\n if (modifiedEditor.getOption(monacoRef.current!.editor.EditorOption.readOnly)) {\n modifiedEditor.setValue(modified || '');\n } else {\n if (modified !== modifiedEditor.getValue()) {\n modifiedEditor.executeEdits('', [\n {\n range: modifiedEditor.getModel()!.getFullModelRange(),\n text: modified || '',\n forceMoveMarkers: true,\n },\n ]);\n\n modifiedEditor.pushUndoStop();\n }\n }\n },\n [modified],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.getModel()?.original.setValue(original || '');\n },\n [original],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const { original, modified } = editorRef.current!.getModel()!;\n\n monacoRef.current!.editor.setModelLanguage(original, originalLanguage || language || 'text');\n monacoRef.current!.editor.setModelLanguage(modified, modifiedLanguage || language || 'text');\n },\n [language, originalLanguage, modifiedLanguage],\n isEditorReady\n );\n\n useUpdate(\n () => {\n monacoRef.current?.editor.setTheme(theme);\n },\n [theme],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.updateOptions(options);\n },\n [options],\n isEditorReady\n );\n\n const setModels = useCallback(() => {\n beforeMountRef.current(monacoRef.current);\n const originalModel = getOrCreateModel(\n monacoRef.current,\n original || '',\n originalLanguage || language || 'text',\n originalModelPath || ''\n );\n\n const modifiedModel = getOrCreateModel(\n monacoRef.current,\n modified || '',\n modifiedLanguage || language || 'text',\n modifiedModelPath || ''\n );\n\n editorRef.current?.setModel({\n original: originalModel,\n modified: modifiedModel,\n });\n }, [language, modified, modifiedLanguage, original, originalLanguage, originalModelPath, modifiedModelPath]);\n\n const createEditor = useCallback(() => {\n if (!preventCreation.current && containerRef.current) {\n editorRef.current = monacoRef.current!.editor.createDiffEditor(containerRef.current, {\n automaticLayout: true,\n ...options,\n });\n\n setModels();\n\n monacoRef.current?.editor.setTheme(theme);\n\n setIsEditorReady(true);\n preventCreation.current = true;\n }\n }, [options, theme, setModels]);\n\n useEffect(() => {\n if (isEditorReady) {\n onMountRef.current(editorRef.current!, monacoRef.current!);\n }\n }, [isEditorReady]);\n\n useEffect(() => {\n if (!isEditorReady) {\n createEditor();\n }\n }, [isEditorReady, createEditor]);\n\n function disposeEditor(): void {\n const editor = editorRef.current;\n const models = editor?.getModel();\n\n // Detach inner editor models first so editor.dispose() never reads from a model that another owner disposed.\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor?.getOriginalEditor().setModel(null);\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor?.getModifiedEditor().setModel(null);\n editor?.dispose();\n\n if (\n !keepCurrentOriginalModel &&\n models?.original &&\n !models.original.isDisposed() &&\n !models.original.isAttachedToEditor()\n ) {\n models.original.dispose();\n }\n\n if (\n !keepCurrentModifiedModel &&\n models?.modified &&\n !models.modified.isDisposed() &&\n !models.modified.isAttachedToEditor()\n ) {\n models.modified.dispose();\n }\n\n // oxlint-disable-next-line unicorn/no-null -- React refs use null after unmount.\n editorRef.current = null;\n preventCreation.current = false;\n setIsEditorReady(false);\n }\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={isEditorReady}\n loading={loading}\n _ref={containerRef}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n}\n\nexport default DiffEditor;\n"],"mappings":"0XAaA,SAAS,EAAW,EAAsC,CACxD,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAM,EAElG,OACE,EAAC,EAAD,CACE,SACE,EAACA,EAAD,CACS,QACC,SACR,cAAe,GACN,UACE,YACG,cACf,CAAA,WAGH,EAAC,EAAD,CAAmB,GAAI,CAAQ,CAAA,CACvB,CAAA,CAEd,CAEA,SAAS,EAAkB,EAAsC,CAC/D,IAAM,EAAS,EAAU,EAEzB,GAAI,CAAC,EAAQ,CACX,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAM,EAElG,OACE,EAACA,EAAD,CACS,QACC,SACR,cAAe,GACN,UACE,YACG,cACf,CAAA,CAEL,CAEA,OAAO,EAAC,EAAD,CAAmB,GAAI,EAAe,QAAS,CAAA,CACxD,CAEA,SAAS,EAAkB,CACzB,SACA,WACA,WACA,WACA,mBACA,mBACA,oBACA,oBACA,2BAA2B,GAC3B,2BAA2B,GAC3B,QAAQ,QACR,UAAU,aACV,UAAU,CAAC,EACX,SAAS,OACT,QAAQ,OACR,YACA,eAAe,CAAC,EAChB,cAAc,EACd,UAAU,GAC2C,CACrD,GAAM,CAAC,EAAe,GAAoB,EAAS,EAAK,EAClD,EAAY,EAAgC,IAAI,EAChD,EAAY,EA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Q,EAGd,CAAC,GACD,GAAQ,UACR,CAAC,EAAO,SAAS,WAAW,GAC5B,CAAC,EAAO,SAAS,mBAAmB,GAEpC,EAAO,SAAS,QAAQ,EAIxB,CAAC,GACD,GAAQ,UACR,CAAC,EAAO,SAAS,WAAW,GAC5B,CAAC,EAAO,SAAS,mBAAmB,GAEpC,EAAO,SAAS,QAAQ,EAI1B,EAAU,QAAU,KACpB,EAAgB,QAAU,GAC1B,EAAiB,EAAK,CACxB,CAEA,OACE,EAACA,EAAD,CACS,QACC,SACO,gBACN,UACT,KAAM,EACK,YACG,cACf,CAAA,CAEL"}
|
|
1
|
+
{"version":3,"file":"DiffEditor.js","names":["MonacoContainer","MonacoContainer_default","useMount","useUpdate","useMonaco","DiffEditor","props","Suspense","DiffEditorContent","monaco","MountedDiffEditor","noop","isEditorReady","setIsEditorReady","useState","editorRef","useRef","monacoRef","containerRef","onMountRef","onMount","beforeMountRef","beforeMount","preventCreation","disposeEditor","originalEditor","model","getOrCreateModel","original","originalLanguage","language","originalModelPath","modifiedEditor","modified","modifiedLanguage","modifiedModelPath","theme","options","setModels","useCallback","originalModel","modifiedModel","createEditor","useEffect","editor","models","keepCurrentOriginalModel","keepCurrentModifiedModel"],"sources":["../../src/DiffEditor/DiffEditor.tsx"],"sourcesContent":["'use client';\n\nimport { Suspense, useState, useRef, useCallback, useEffect } from 'react';\nimport type { ReactElement } from 'react';\n\nimport MonacoContainer from '../MonacoContainer';\nimport useMount from '../hooks/useMount';\nimport useUpdate from '../hooks/useUpdate';\nimport useMonaco from '../hooks/useMonaco';\nimport { noop, getOrCreateModel } from '../utils';\nimport type { DiffEditorProps, MonacoDiffEditor } from './types';\nimport type { Monaco } from '..';\n\nfunction DiffEditor(props: DiffEditorProps): ReactElement {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <Suspense\n fallback={\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n }\n >\n <DiffEditorContent {...props} />\n </Suspense>\n );\n}\n\nfunction DiffEditorContent(props: DiffEditorProps): ReactElement {\n const monaco = useMonaco();\n\n if (!monaco) {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n }\n\n return <MountedDiffEditor {...props} monaco={monaco} />;\n}\n\nfunction MountedDiffEditor({\n monaco,\n original,\n modified,\n language,\n originalLanguage,\n modifiedLanguage,\n originalModelPath,\n modifiedModelPath,\n keepCurrentOriginalModel = false,\n keepCurrentModifiedModel = false,\n theme = 'light',\n loading = 'Loading...',\n options = {},\n height = '100%',\n width = '100%',\n className,\n wrapperProps = {},\n beforeMount = noop,\n onMount = noop,\n}: DiffEditorProps & { monaco: Monaco }): ReactElement {\n const [isEditorReady, setIsEditorReady] = useState(false);\n const editorRef = useRef<MonacoDiffEditor | null>(null);\n const monacoRef = useRef<Monaco>(monaco);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const onMountRef = useRef(onMount);\n const beforeMountRef = useRef(beforeMount);\n const preventCreation = useRef(false);\n\n monacoRef.current = monaco;\n\n useMount(() => {\n return () => {\n if (editorRef.current) {\n disposeEditor();\n }\n };\n });\n\n useUpdate(\n () => {\n if (editorRef.current && monacoRef.current) {\n const originalEditor = editorRef.current.getOriginalEditor();\n const model = getOrCreateModel(\n monacoRef.current,\n original || '',\n originalLanguage || language || 'text',\n originalModelPath || ''\n );\n\n if (model !== originalEditor.getModel()) {\n originalEditor.setModel(model);\n }\n }\n },\n [originalModelPath],\n isEditorReady\n );\n\n useUpdate(\n () => {\n if (editorRef.current && monacoRef.current) {\n const modifiedEditor = editorRef.current.getModifiedEditor();\n const model = getOrCreateModel(\n monacoRef.current,\n modified || '',\n modifiedLanguage || language || 'text',\n modifiedModelPath || ''\n );\n\n if (model !== modifiedEditor.getModel()) {\n modifiedEditor.setModel(model);\n }\n }\n },\n [modifiedModelPath],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const modifiedEditor = editorRef.current!.getModifiedEditor();\n if (modifiedEditor.getOption(monacoRef.current!.editor.EditorOption.readOnly)) {\n modifiedEditor.setValue(modified || '');\n } else {\n if (modified !== modifiedEditor.getValue()) {\n modifiedEditor.executeEdits('', [\n {\n range: modifiedEditor.getModel()!.getFullModelRange(),\n text: modified || '',\n forceMoveMarkers: true,\n },\n ]);\n\n modifiedEditor.pushUndoStop();\n }\n }\n },\n [modified],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.getModel()?.original.setValue(original || '');\n },\n [original],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const { original, modified } = editorRef.current!.getModel()!;\n\n monacoRef.current!.editor.setModelLanguage(original, originalLanguage || language || 'text');\n monacoRef.current!.editor.setModelLanguage(modified, modifiedLanguage || language || 'text');\n },\n [language, originalLanguage, modifiedLanguage],\n isEditorReady\n );\n\n useUpdate(\n () => {\n monacoRef.current?.editor.setTheme(theme);\n },\n [theme],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.updateOptions(options);\n },\n [options],\n isEditorReady\n );\n\n const setModels = useCallback(() => {\n beforeMountRef.current(monacoRef.current);\n const originalModel = getOrCreateModel(\n monacoRef.current,\n original || '',\n originalLanguage || language || 'text',\n originalModelPath || ''\n );\n\n const modifiedModel = getOrCreateModel(\n monacoRef.current,\n modified || '',\n modifiedLanguage || language || 'text',\n modifiedModelPath || ''\n );\n\n editorRef.current?.setModel({\n original: originalModel,\n modified: modifiedModel,\n });\n }, [language, modified, modifiedLanguage, original, originalLanguage, originalModelPath, modifiedModelPath]);\n\n const createEditor = useCallback(() => {\n if (!preventCreation.current && containerRef.current) {\n editorRef.current = monacoRef.current!.editor.createDiffEditor(containerRef.current, {\n automaticLayout: true,\n ...options,\n });\n\n setModels();\n\n monacoRef.current?.editor.setTheme(theme);\n\n setIsEditorReady(true);\n preventCreation.current = true;\n }\n }, [options, theme, setModels]);\n\n useEffect(() => {\n if (isEditorReady) {\n onMountRef.current(editorRef.current!, monacoRef.current!);\n }\n }, [isEditorReady]);\n\n useEffect(() => {\n if (!isEditorReady) {\n createEditor();\n }\n }, [isEditorReady, createEditor]);\n\n function disposeEditor(): void {\n const editor = editorRef.current;\n const models = editor?.getModel();\n\n // Detach inner editor models first so editor.dispose() never reads from a model that another owner disposed.\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor?.getOriginalEditor().setModel(null);\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor?.getModifiedEditor().setModel(null);\n editor?.dispose();\n\n if (\n !keepCurrentOriginalModel &&\n models?.original &&\n !models.original.isDisposed() &&\n !models.original.isAttachedToEditor()\n ) {\n models.original.dispose();\n }\n\n if (\n !keepCurrentModifiedModel &&\n models?.modified &&\n !models.modified.isDisposed() &&\n !models.modified.isAttachedToEditor()\n ) {\n models.modified.dispose();\n }\n\n // oxlint-disable-next-line unicorn/no-null -- React refs use null after unmount.\n editorRef.current = null;\n preventCreation.current = false;\n setIsEditorReady(false);\n }\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={isEditorReady}\n loading={loading}\n _ref={containerRef}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n}\n\nexport default DiffEditor;\n"],"mappings":"0XAaA,SAASK,EAAW,EAAsC,CACxD,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAMC,EAElG,MACE,kBAACC,EAAD,CACE,SACE,kBAACP,EAAD,CACS,QACC,SACR,cAAe,GACN,UACE,YACG,cACf,CAAA,EAGH,SAAA,kBAACQ,EAAD,CAAmB,GAAIF,CAAQ,CAAA,CACvB,CAAA,CAEd,CAEA,SAASE,EAAkB,EAAsC,CAC/D,IAAMC,EAASL,EAAU,EAEzB,GAAI,CAACK,EAAQ,CACX,GAAM,CAAE,QAAQ,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AUC,EAAkBE,EAAmBI,CAAiB,CAAC,EAErGO,EAAeH,MAAkB,CACjC,CAAChB,EAAgB,SAAWL,EAAa,UAC3C,EAAU,QAAUD,EAAU,QAAS,OAAO,iBAAiBC,EAAa,QAAS,CACnF,gBAAiB,GACjB,GAAGmB,CACL,CAAC,EAEDC,EAAU,EAEVrB,EAAU,SAAS,OAAO,SAASmB,CAAK,EAExCvB,EAAiB,EAAI,EACrB,EAAgB,QAAU,GAE9B,EAAG,CAACwB,EAASD,EAAOE,CAAS,CAAC,EAE9BK,MAAgB,CACV/B,GACFO,EAAW,QAAQJ,EAAU,QAAUE,EAAU,OAAQ,CAE7D,EAAG,CAACL,CAAa,CAAC,EAElB+B,MAAgB,CACT/B,GACH8B,EAAa,CAEjB,EAAG,CAAC9B,EAAe8B,CAAY,CAAC,EAEhC,SAASlB,GAAsB,CAC7B,IAAMoB,EAAS7B,EAAU,QACnB8B,EAASD,GAAQ,SAAS,EAIhCA,GAAQ,kBAAkB,CAAC,CAAC,SAAS,IAAI,EAEzCA,GAAQ,kBAAkB,CAAC,CAAC,SAAS,IAAI,EACzCA,GAAQ,QAAQ,EAGd,CAACE,GACDD,GAAQ,UACR,CAACA,EAAO,SAAS,WAAW,GAC5B,CAACA,EAAO,SAAS,mBAAmB,GAEpCA,EAAO,SAAS,QAAQ,EAIxB,CAACE,GACDF,GAAQ,UACR,CAACA,EAAO,SAAS,WAAW,GAC5B,CAACA,EAAO,SAAS,mBAAmB,GAEpCA,EAAO,SAAS,QAAQ,EAI1B,EAAU,QAAU,KACpB,EAAgB,QAAU,GAC1BhC,EAAiB,EAAK,CACxB,CAEA,MACE,kBAACb,EAAD,CACS,QACC,SACO,gBACN,UACT,KAAMkB,EACK,YACG,cACf,CAAA,CAEL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["DiffEditor"],"sources":["../../src/DiffEditor/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport DiffEditor from './DiffEditor';\n\nexport * from './types';\n\nexport default memo(DiffEditor);\n"],"mappings":"iDAMA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["memo","DiffEditor","require_DiffEditor","DiffEditor_default"],"sources":["../../src/DiffEditor/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport DiffEditor from './DiffEditor';\n\nexport * from './types';\n\nexport default memo(DiffEditor);\n"],"mappings":"iDAMA,IAAAG,GAAA,iBAAeH,CAAAA,CAAAA,KAAAA,CAAKC,EAAAA,OAAU"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/DiffEditor/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport DiffEditor from './DiffEditor';\n\nexport * from './types';\n\nexport default memo(DiffEditor);\n"],"mappings":"4DAMA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["DiffEditor","DiffEditor_default","memo"],"sources":["../../src/DiffEditor/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport DiffEditor from './DiffEditor';\n\nexport * from './types';\n\nexport default memo(DiffEditor);\n"],"mappings":"4DAMA,IAAAC,EAAeC,EAAKF,CAAU"}
|
package/dist/Editor/Editor.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";"use client";const e=require("../MonacoContainer/index.cjs"),t=require("../hooks/useMount/index.cjs"),n=require("../hooks/useUpdate/index.cjs"),r=require("../hooks/useMonaco/index.cjs"),i=require("../utils/index.cjs"),a=require("../hooks/usePrevious/index.cjs");let o=require("react"),s=require("react/jsx-runtime");const c
|
|
1
|
+
"use strict";"use client";const e=require("../MonacoContainer/index.cjs"),t=require("../hooks/useMount/index.cjs"),n=require("../hooks/useUpdate/index.cjs"),r=require("../hooks/useMonaco/index.cjs"),i=require("../utils/index.cjs"),a=require("../hooks/usePrevious/index.cjs");let o=require("react"),s=require("react/jsx-runtime");const c=/* @__PURE__ */ new Map;function l(t){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:a,wrapperProps:c={}}=t;return/* @__PURE__ */ (0,s.jsx)(o.Suspense,{fallback:/* @__PURE__ */ (0,s.jsx)(e.default,{width:n,height:r,isEditorReady:!1,loading:i,className:a,wrapperProps:c}),children:/* @__PURE__ */ (0,s.jsx)(u,{...t})})}function u(t){let n=r.default();if(!n){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:a,wrapperProps:o={}}=t;return/* @__PURE__ */ (0,s.jsx)(e.default,{width:n,height:r,isEditorReady:!1,loading:i,className:a,wrapperProps:o})}return/* @__PURE__ */ (0,s.jsx)(d,{...t,monaco:n})}function d({monaco:r,defaultValue:l,defaultLanguage:u,defaultPath:d,value:f,language:p,path:m,theme:h=`light`,line:g,loading:_=`Loading...`,options:v={},overrideServices:y={},saveViewState:b=!0,keepCurrentModel:x=!1,width:S=`100%`,height:C=`100%`,className:w,wrapperProps:T={},beforeMount:E=i.noop,onMount:D=i.noop,onChange:O,onValidate:k=i.noop}){let[A,j]=(0,o.useState)(!1),M=(0,o.useRef)(r),N=(0,o.useRef)(void 0),P=(0,o.useRef)(null),F=(0,o.useRef)(D),I=(0,o.useRef)(E),L=(0,o.useRef)(void 0),R=(0,o.useRef)(f),z=a.default(m),B=(0,o.useRef)(!1),V=(0,o.useRef)(!1);M.current=r,t.default(()=>()=>{N.current&&U()}),n.default(()=>{let e=i.getOrCreateModel(M.current,l||f||``,u||p||``,m||d||``);e!==N.current?.getModel()&&(b&&c.set(z,N.current?.saveViewState()),N.current?.setModel(e),b&&N.current?.restoreViewState(c.get(m)))},[m],A),n.default(()=>{N.current?.updateOptions(v)},[v],A),n.default(()=>{N.current&&f!==void 0&&(N.current.getOption(M.current.editor.EditorOption.readOnly)?N.current.setValue(f):f!==N.current.getValue()&&(V.current=!0,N.current.executeEdits(``,[{range:N.current.getModel().getFullModelRange(),text:f,forceMoveMarkers:!0}]),N.current.pushUndoStop(),V.current=!1))},[f],A),n.default(()=>{let e=N.current?.getModel();A&&e&&p&&M.current?.editor.setModelLanguage(e,p)},[p,A],A),n.default(()=>{g!==void 0&&N.current?.revealLine(g)},[g],A),n.default(()=>{M.current?.editor.setTheme(h)},[h],A);let H=(0,o.useCallback)(()=>{if(P.current&&!B.current){I.current(M.current);let e=m||d,t=i.getOrCreateModel(M.current,f||l||``,u||p||``,e||``),n=M.current.editor.create(P.current,{model:t,automaticLayout:!0,...v},y);N.current=n,b&&n.restoreViewState(c.get(e)),M.current.editor.setTheme(h),g!==void 0&&n.revealLine(g),j(!0),B.current=!0}},[l,u,d,f,p,m,v,y,b,h,g]);(0,o.useEffect)(()=>{A&&F.current(N.current,M.current)},[A]),(0,o.useEffect)(()=>{A||H()},[A,H]),R.current=f,(0,o.useEffect)(()=>{A&&O&&(L.current?.dispose(),L.current=N.current?.onDidChangeModelContent(e=>{V.current||O(N.current.getValue(),e)}))},[A,O]),(0,o.useEffect)(()=>{if(A){let e=M.current.editor.onDidChangeMarkers(e=>{let t=N.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=M.current.editor.getModelMarkers({resource:t});k?.(e)}});return()=>{e?.dispose()}}return()=>{}},[A,k]);function U(){L.current?.dispose();let e=N.current,t=e.getModel();x?(b&&c.set(m,e.saveViewState()),e.setModel(null)):t&&(e.setModel(null),!t.isDisposed()&&!t.isAttachedToEditor()&&t.dispose()),e.dispose(),N.current=void 0,B.current=!1,j(!1)}return/* @__PURE__ */ (0,s.jsx)(e.default,{width:S,height:C,isEditorReady:A,loading:_,_ref:P,className:w,wrapperProps:T})}exports.default=l;
|
|
2
2
|
//# sourceMappingURL=Editor.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.cjs","names":["Suspense","MonacoContainer","useMonaco","noop","usePrevious","getOrCreateModel"],"sources":["../../src/Editor/Editor.tsx"],"sourcesContent":["'use client';\n\nimport { Suspense, useState, useEffect, useRef, useCallback } from 'react';\nimport type { ReactElement } from 'react';\nimport useMount from '../hooks/useMount';\nimport useUpdate from '../hooks/useUpdate';\nimport usePrevious from '../hooks/usePrevious';\nimport useMonaco from '../hooks/useMonaco';\nimport type { IDisposable, Uri, editor } from 'monaco-editor';\nimport { noop, getOrCreateModel } from '../utils';\nimport type { EditorProps } from './types';\nimport type { Monaco } from '..';\nimport MonacoContainer from '../MonacoContainer';\n\nconst viewStates = new Map();\n\nfunction Editor(props: EditorProps): ReactElement {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <Suspense\n fallback={\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n }\n >\n <EditorContent {...props} />\n </Suspense>\n );\n}\n\nfunction EditorContent(props: EditorProps): ReactElement {\n const monaco = useMonaco();\n\n if (!monaco) {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n }\n\n return <MountedEditor {...props} monaco={monaco} />;\n}\n\nfunction MountedEditor({\n monaco,\n defaultValue,\n defaultLanguage,\n defaultPath,\n value,\n language,\n path,\n /* === */\n theme = 'light',\n line,\n loading = 'Loading...',\n options = {},\n overrideServices = {},\n saveViewState = true,\n keepCurrentModel = false,\n /* === */\n width = '100%',\n height = '100%',\n className,\n wrapperProps = {},\n /* === */\n beforeMount = noop,\n onMount = noop,\n onChange,\n onValidate = noop,\n}: EditorProps & { monaco: Monaco }): ReactElement {\n const [isEditorReady, setIsEditorReady] = useState(false);\n const monacoRef = useRef<Monaco>(monaco);\n const editorRef = useRef<editor.IStandaloneCodeEditor | undefined>(undefined);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const onMountRef = useRef(onMount);\n const beforeMountRef = useRef(beforeMount);\n const subscriptionRef = useRef<IDisposable | undefined>(undefined);\n const valueRef = useRef(value);\n const previousPath = usePrevious(path);\n const preventCreation = useRef(false);\n const preventTriggerChangeEvent = useRef<boolean>(false);\n\n monacoRef.current = monaco;\n\n useMount(() => {\n return () => {\n if (editorRef.current) {\n disposeEditor();\n }\n };\n });\n\n useUpdate(\n () => {\n const model = getOrCreateModel(\n monacoRef.current!,\n defaultValue || value || '',\n defaultLanguage || language || '',\n path || defaultPath || ''\n );\n\n if (model !== editorRef.current?.getModel()) {\n if (saveViewState) viewStates.set(previousPath, editorRef.current?.saveViewState());\n editorRef.current?.setModel(model);\n if (saveViewState) editorRef.current?.restoreViewState(viewStates.get(path));\n }\n },\n [path],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.updateOptions(options);\n },\n [options],\n isEditorReady\n );\n\n useUpdate(\n () => {\n if (!editorRef.current || value === undefined) return;\n if (editorRef.current.getOption(monacoRef.current!.editor.EditorOption.readOnly)) {\n editorRef.current.setValue(value);\n } else if (value !== editorRef.current.getValue()) {\n preventTriggerChangeEvent.current = true;\n editorRef.current.executeEdits('', [\n {\n range: editorRef.current.getModel()!.getFullModelRange(),\n text: value,\n forceMoveMarkers: true,\n },\n ]);\n\n editorRef.current.pushUndoStop();\n preventTriggerChangeEvent.current = false;\n }\n },\n [value],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const model = editorRef.current?.getModel();\n if (isEditorReady && model && language) {\n monacoRef.current?.editor.setModelLanguage(model, language);\n }\n },\n [language, isEditorReady],\n isEditorReady\n );\n\n useUpdate(\n () => {\n // reason for undefined check: https://github.com/suren-atoyan/monaco-react/pull/188\n if (line !== undefined) {\n editorRef.current?.revealLine(line);\n }\n },\n [line],\n isEditorReady\n );\n\n useUpdate(\n () => {\n monacoRef.current?.editor.setTheme(theme);\n },\n [theme],\n isEditorReady\n );\n\n const createEditor = useCallback(() => {\n if (!containerRef.current) return;\n if (!preventCreation.current) {\n beforeMountRef.current(monacoRef.current);\n const autoCreatedModelPath = path || defaultPath;\n\n const defaultModel = getOrCreateModel(\n monacoRef.current,\n value || defaultValue || '',\n defaultLanguage || language || '',\n autoCreatedModelPath || ''\n );\n\n const editor = monacoRef.current.editor.create(\n containerRef.current,\n {\n model: defaultModel,\n automaticLayout: true,\n ...options,\n },\n overrideServices\n );\n editorRef.current = editor;\n\n if (saveViewState) {\n editor.restoreViewState(viewStates.get(autoCreatedModelPath));\n }\n\n monacoRef.current.editor.setTheme(theme);\n\n if (line !== undefined) {\n editor.revealLine(line);\n }\n\n setIsEditorReady(true);\n preventCreation.current = true;\n }\n }, [\n defaultValue,\n defaultLanguage,\n defaultPath,\n value,\n language,\n path,\n options,\n overrideServices,\n saveViewState,\n theme,\n line,\n ]);\n\n useEffect(() => {\n if (isEditorReady) {\n onMountRef.current(editorRef.current!, monacoRef.current!);\n }\n }, [isEditorReady]);\n\n useEffect(() => {\n if (!isEditorReady) {\n createEditor();\n }\n }, [isEditorReady, createEditor]);\n\n // subscription\n // to avoid unnecessary updates (attach - dispose listener) in subscription\n valueRef.current = value;\n\n // onChange\n useEffect(() => {\n if (isEditorReady && onChange) {\n subscriptionRef.current?.dispose();\n subscriptionRef.current = editorRef.current?.onDidChangeModelContent((event) => {\n if (!preventTriggerChangeEvent.current) {\n onChange(editorRef.current!.getValue(), event);\n }\n });\n }\n }, [isEditorReady, onChange]);\n\n // onValidate\n useEffect(() => {\n if (isEditorReady) {\n const changeMarkersListener = monacoRef.current!.editor.onDidChangeMarkers((uris: readonly Uri[]) => {\n const editorUri = editorRef.current!.getModel()?.uri;\n\n if (editorUri) {\n const currentEditorHasMarkerChanges = uris.find((uri: Uri) => uri.path === editorUri.path);\n if (currentEditorHasMarkerChanges) {\n const markers = monacoRef.current!.editor.getModelMarkers({\n resource: editorUri,\n });\n onValidate?.(markers);\n }\n }\n });\n\n return () => {\n changeMarkersListener?.dispose();\n };\n }\n return () => {\n // eslint happy\n };\n }, [isEditorReady, onValidate]);\n\n function disposeEditor(): void {\n subscriptionRef.current?.dispose();\n const editor = editorRef.current!;\n const model = editor.getModel();\n\n if (keepCurrentModel) {\n if (saveViewState) {\n viewStates.set(path, editor.saveViewState());\n }\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor.setModel(null);\n } else if (model) {\n // Detach first so editor.dispose() never reads from a model that another editor already disposed.\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor.setModel(null);\n if (!model.isDisposed() && !model.isAttachedToEditor()) {\n model.dispose();\n }\n }\n\n editor.dispose();\n\n editorRef.current = undefined;\n preventCreation.current = false;\n setIsEditorReady(false);\n }\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={isEditorReady}\n loading={loading}\n _ref={containerRef}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n}\n\nexport default Editor;\n"],"mappings":"yUAcA,MAAM,EAAa,IAAI,IAEvB,SAAS,EAAO,EAAkC,CAChD,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAM,EAElG,OACE,EAAA,EAAA,IAAA,CAACA,EAAAA,SAAD,CACE,UACE,EAAA,EAAA,IAAA,CAACC,EAAAA,QAAD,CACS,QACC,SACR,cAAe,GACN,UACE,YACG,cACf,CAAA,YAGH,EAAA,EAAA,IAAA,CAAC,EAAD,CAAe,GAAI,CAAQ,CAAA,CACnB,CAAA,CAEd,CAEA,SAAS,EAAc,EAAkC,CACvD,IAAM,EAASC,EAAAA,QAAU,EAEzB,GAAI,CAAC,EAAQ,CACX,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAM,EAElG,OACE,EAAA,EAAA,IAAA,CAACD,EAAAA,QAAD,CACS,QACC,SACR,cAAe,GACN,UACE,YACG,cACf,CAAA,CAEL,CAEA,OAAO,EAAA,EAAA,IAAA,CAAC,EAAD,CAAe,GAAI,EAAe,QAAS,CAAA,CACpD,CAEA,SAAS,EAAc,CACrB,SACA,eACA,kBACA,cACA,QACA,WACA,OAEA,QAAQ,QACR,OACA,UAAU,aACV,UAAU,CAAC,EACX,mBAAmB,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ACxB,CAEA,OACE,EAAA,EAAA,IAAA,CAACJ,EAAAA,QAAD,CACS,QACC,SACO,gBACN,UACT,KAAM,EACK,YACG,cACf,CAAA,CAEL"}
|
|
1
|
+
{"version":3,"file":"Editor.cjs","names":["Suspense","MonacoContainer","useMonaco","noop","useState","useRef","usePrevious","getOrCreateModel","useCallback","require_index","require_index$1","require_index$2","require_index$3","require_index$4","require_index$5","react","react_jsx_runtime","viewStates","Editor","props","EditorContent","monaco","MountedEditor","isEditorReady","setIsEditorReady","monacoRef","editorRef","containerRef","onMountRef","onMount","beforeMountRef","beforeMount","subscriptionRef","valueRef","value","previousPath","path","preventCreation","preventTriggerChangeEvent","disposeEditor","model","defaultValue","defaultLanguage","language","defaultPath","saveViewState","options","line","theme","createEditor","autoCreatedModelPath","defaultModel","editor","overrideServices","onChange","event","changeMarkersListener","editorUri","uris","uri","markers","onValidate","keepCurrentModel"],"sources":["../../src/Editor/Editor.tsx"],"sourcesContent":["'use client';\n\nimport { Suspense, useState, useEffect, useRef, useCallback } from 'react';\nimport type { ReactElement } from 'react';\nimport useMount from '../hooks/useMount';\nimport useUpdate from '../hooks/useUpdate';\nimport usePrevious from '../hooks/usePrevious';\nimport useMonaco from '../hooks/useMonaco';\nimport type { IDisposable, Uri, editor } from 'monaco-editor';\nimport { noop, getOrCreateModel } from '../utils';\nimport type { EditorProps } from './types';\nimport type { Monaco } from '..';\nimport MonacoContainer from '../MonacoContainer';\n\nconst viewStates = new Map();\n\nfunction Editor(props: EditorProps): ReactElement {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <Suspense\n fallback={\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n }\n >\n <EditorContent {...props} />\n </Suspense>\n );\n}\n\nfunction EditorContent(props: EditorProps): ReactElement {\n const monaco = useMonaco();\n\n if (!monaco) {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n }\n\n return <MountedEditor {...props} monaco={monaco} />;\n}\n\nfunction MountedEditor({\n monaco,\n defaultValue,\n defaultLanguage,\n defaultPath,\n value,\n language,\n path,\n /* === */\n theme = 'light',\n line,\n loading = 'Loading...',\n options = {},\n overrideServices = {},\n saveViewState = true,\n keepCurrentModel = false,\n /* === */\n width = '100%',\n height = '100%',\n className,\n wrapperProps = {},\n /* === */\n beforeMount = noop,\n onMount = noop,\n onChange,\n onValidate = noop,\n}: EditorProps & { monaco: Monaco }): ReactElement {\n const [isEditorReady, setIsEditorReady] = useState(false);\n const monacoRef = useRef<Monaco>(monaco);\n const editorRef = useRef<editor.IStandaloneCodeEditor | undefined>(undefined);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const onMountRef = useRef(onMount);\n const beforeMountRef = useRef(beforeMount);\n const subscriptionRef = useRef<IDisposable | undefined>(undefined);\n const valueRef = useRef(value);\n const previousPath = usePrevious(path);\n const preventCreation = useRef(false);\n const preventTriggerChangeEvent = useRef<boolean>(false);\n\n monacoRef.current = monaco;\n\n useMount(() => {\n return () => {\n if (editorRef.current) {\n disposeEditor();\n }\n };\n });\n\n useUpdate(\n () => {\n const model = getOrCreateModel(\n monacoRef.current!,\n defaultValue || value || '',\n defaultLanguage || language || '',\n path || defaultPath || ''\n );\n\n if (model !== editorRef.current?.getModel()) {\n if (saveViewState) viewStates.set(previousPath, editorRef.current?.saveViewState());\n editorRef.current?.setModel(model);\n if (saveViewState) editorRef.current?.restoreViewState(viewStates.get(path));\n }\n },\n [path],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.updateOptions(options);\n },\n [options],\n isEditorReady\n );\n\n useUpdate(\n () => {\n if (!editorRef.current || value === undefined) return;\n if (editorRef.current.getOption(monacoRef.current!.editor.EditorOption.readOnly)) {\n editorRef.current.setValue(value);\n } else if (value !== editorRef.current.getValue()) {\n preventTriggerChangeEvent.current = true;\n editorRef.current.executeEdits('', [\n {\n range: editorRef.current.getModel()!.getFullModelRange(),\n text: value,\n forceMoveMarkers: true,\n },\n ]);\n\n editorRef.current.pushUndoStop();\n preventTriggerChangeEvent.current = false;\n }\n },\n [value],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const model = editorRef.current?.getModel();\n if (isEditorReady && model && language) {\n monacoRef.current?.editor.setModelLanguage(model, language);\n }\n },\n [language, isEditorReady],\n isEditorReady\n );\n\n useUpdate(\n () => {\n // reason for undefined check: https://github.com/suren-atoyan/monaco-react/pull/188\n if (line !== undefined) {\n editorRef.current?.revealLine(line);\n }\n },\n [line],\n isEditorReady\n );\n\n useUpdate(\n () => {\n monacoRef.current?.editor.setTheme(theme);\n },\n [theme],\n isEditorReady\n );\n\n const createEditor = useCallback(() => {\n if (!containerRef.current) return;\n if (!preventCreation.current) {\n beforeMountRef.current(monacoRef.current);\n const autoCreatedModelPath = path || defaultPath;\n\n const defaultModel = getOrCreateModel(\n monacoRef.current,\n value || defaultValue || '',\n defaultLanguage || language || '',\n autoCreatedModelPath || ''\n );\n\n const editor = monacoRef.current.editor.create(\n containerRef.current,\n {\n model: defaultModel,\n automaticLayout: true,\n ...options,\n },\n overrideServices\n );\n editorRef.current = editor;\n\n if (saveViewState) {\n editor.restoreViewState(viewStates.get(autoCreatedModelPath));\n }\n\n monacoRef.current.editor.setTheme(theme);\n\n if (line !== undefined) {\n editor.revealLine(line);\n }\n\n setIsEditorReady(true);\n preventCreation.current = true;\n }\n }, [\n defaultValue,\n defaultLanguage,\n defaultPath,\n value,\n language,\n path,\n options,\n overrideServices,\n saveViewState,\n theme,\n line,\n ]);\n\n useEffect(() => {\n if (isEditorReady) {\n onMountRef.current(editorRef.current!, monacoRef.current!);\n }\n }, [isEditorReady]);\n\n useEffect(() => {\n if (!isEditorReady) {\n createEditor();\n }\n }, [isEditorReady, createEditor]);\n\n // subscription\n // to avoid unnecessary updates (attach - dispose listener) in subscription\n valueRef.current = value;\n\n // onChange\n useEffect(() => {\n if (isEditorReady && onChange) {\n subscriptionRef.current?.dispose();\n subscriptionRef.current = editorRef.current?.onDidChangeModelContent((event) => {\n if (!preventTriggerChangeEvent.current) {\n onChange(editorRef.current!.getValue(), event);\n }\n });\n }\n }, [isEditorReady, onChange]);\n\n // onValidate\n useEffect(() => {\n if (isEditorReady) {\n const changeMarkersListener = monacoRef.current!.editor.onDidChangeMarkers((uris: readonly Uri[]) => {\n const editorUri = editorRef.current!.getModel()?.uri;\n\n if (editorUri) {\n const currentEditorHasMarkerChanges = uris.find((uri: Uri) => uri.path === editorUri.path);\n if (currentEditorHasMarkerChanges) {\n const markers = monacoRef.current!.editor.getModelMarkers({\n resource: editorUri,\n });\n onValidate?.(markers);\n }\n }\n });\n\n return () => {\n changeMarkersListener?.dispose();\n };\n }\n return () => {\n // eslint happy\n };\n }, [isEditorReady, onValidate]);\n\n function disposeEditor(): void {\n subscriptionRef.current?.dispose();\n const editor = editorRef.current!;\n const model = editor.getModel();\n\n if (keepCurrentModel) {\n if (saveViewState) {\n viewStates.set(path, editor.saveViewState());\n }\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor.setModel(null);\n } else if (model) {\n // Detach first so editor.dispose() never reads from a model that another editor already disposed.\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor.setModel(null);\n if (!model.isDisposed() && !model.isAttachedToEditor()) {\n model.dispose();\n }\n }\n\n editor.dispose();\n\n editorRef.current = undefined;\n preventCreation.current = false;\n setIsEditorReady(false);\n }\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={isEditorReady}\n loading={loading}\n _ref={containerRef}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n}\n\nexport default Editor;\n"],"mappings":"yUAcA,MAAMiB,kBAAa,IAAI,IAEvB,SAASC,EAAO,EAAkC,CAChD,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,U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AAA,CAEL"}
|
package/dist/Editor/Editor.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use client";import e from"../MonacoContainer/index.js";import t from"../hooks/useMount/index.js";import n from"../hooks/useUpdate/index.js";import r from"../hooks/useMonaco/index.js";import{getOrCreateModel as i,noop as a}from"../utils/index.js";import o from"../hooks/usePrevious/index.js";import{Suspense as s,useCallback as c,useEffect as l,useRef as u,useState as d}from"react";import{jsx as f}from"react/jsx-runtime";const p
|
|
1
|
+
"use client";import e from"../MonacoContainer/index.js";import t from"../hooks/useMount/index.js";import n from"../hooks/useUpdate/index.js";import r from"../hooks/useMonaco/index.js";import{getOrCreateModel as i,noop as a}from"../utils/index.js";import o from"../hooks/usePrevious/index.js";import{Suspense as s,useCallback as c,useEffect as l,useRef as u,useState as d}from"react";import{jsx as f}from"react/jsx-runtime";const p=/* @__PURE__ */ new Map;function m(t){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:a,wrapperProps:o={}}=t;return/* @__PURE__ */ f(s,{fallback:/* @__PURE__ */ f(e,{width:n,height:r,isEditorReady:!1,loading:i,className:a,wrapperProps:o}),children:/* @__PURE__ */ f(h,{...t})})}function h(t){let n=r();if(!n){let{width:n=`100%`,height:r=`100%`,loading:i=`Loading...`,className:a,wrapperProps:o={}}=t;return/* @__PURE__ */ f(e,{width:n,height:r,isEditorReady:!1,loading:i,className:a,wrapperProps:o})}return/* @__PURE__ */ f(g,{...t,monaco:n})}function g({monaco:r,defaultValue:s,defaultLanguage:m,defaultPath:h,value:g,language:_,path:v,theme:y=`light`,line:b,loading:x=`Loading...`,options:S={},overrideServices:C={},saveViewState:w=!0,keepCurrentModel:T=!1,width:E=`100%`,height:D=`100%`,className:O,wrapperProps:k={},beforeMount:A=a,onMount:j=a,onChange:M,onValidate:N=a}){let[P,F]=d(!1),I=u(r),L=u(void 0),R=u(null),z=u(j),B=u(A),V=u(void 0),H=u(g),U=o(v),W=u(!1),G=u(!1);I.current=r,t(()=>()=>{L.current&&q()}),n(()=>{let e=i(I.current,s||g||``,m||_||``,v||h||``);e!==L.current?.getModel()&&(w&&p.set(U,L.current?.saveViewState()),L.current?.setModel(e),w&&L.current?.restoreViewState(p.get(v)))},[v],P),n(()=>{L.current?.updateOptions(S)},[S],P),n(()=>{L.current&&g!==void 0&&(L.current.getOption(I.current.editor.EditorOption.readOnly)?L.current.setValue(g):g!==L.current.getValue()&&(G.current=!0,L.current.executeEdits(``,[{range:L.current.getModel().getFullModelRange(),text:g,forceMoveMarkers:!0}]),L.current.pushUndoStop(),G.current=!1))},[g],P),n(()=>{let e=L.current?.getModel();P&&e&&_&&I.current?.editor.setModelLanguage(e,_)},[_,P],P),n(()=>{b!==void 0&&L.current?.revealLine(b)},[b],P),n(()=>{I.current?.editor.setTheme(y)},[y],P);let K=c(()=>{if(R.current&&!W.current){B.current(I.current);let e=v||h,t=i(I.current,g||s||``,m||_||``,e||``),n=I.current.editor.create(R.current,{model:t,automaticLayout:!0,...S},C);L.current=n,w&&n.restoreViewState(p.get(e)),I.current.editor.setTheme(y),b!==void 0&&n.revealLine(b),F(!0),W.current=!0}},[s,m,h,g,_,v,S,C,w,y,b]);l(()=>{P&&z.current(L.current,I.current)},[P]),l(()=>{P||K()},[P,K]),H.current=g,l(()=>{P&&M&&(V.current?.dispose(),V.current=L.current?.onDidChangeModelContent(e=>{G.current||M(L.current.getValue(),e)}))},[P,M]),l(()=>{if(P){let e=I.current.editor.onDidChangeMarkers(e=>{let t=L.current.getModel()?.uri;if(t&&e.find(e=>e.path===t.path)){let e=I.current.editor.getModelMarkers({resource:t});N?.(e)}});return()=>{e?.dispose()}}return()=>{}},[P,N]);function q(){V.current?.dispose();let e=L.current,t=e.getModel();T?(w&&p.set(v,e.saveViewState()),e.setModel(null)):t&&(e.setModel(null),!t.isDisposed()&&!t.isAttachedToEditor()&&t.dispose()),e.dispose(),L.current=void 0,W.current=!1,F(!1)}return/* @__PURE__ */ f(e,{width:E,height:D,isEditorReady:P,loading:x,_ref:R,className:O,wrapperProps:k})}export{m as default};
|
|
2
2
|
//# sourceMappingURL=Editor.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Editor.js","names":["MonacoContainer"],"sources":["../../src/Editor/Editor.tsx"],"sourcesContent":["'use client';\n\nimport { Suspense, useState, useEffect, useRef, useCallback } from 'react';\nimport type { ReactElement } from 'react';\nimport useMount from '../hooks/useMount';\nimport useUpdate from '../hooks/useUpdate';\nimport usePrevious from '../hooks/usePrevious';\nimport useMonaco from '../hooks/useMonaco';\nimport type { IDisposable, Uri, editor } from 'monaco-editor';\nimport { noop, getOrCreateModel } from '../utils';\nimport type { EditorProps } from './types';\nimport type { Monaco } from '..';\nimport MonacoContainer from '../MonacoContainer';\n\nconst viewStates = new Map();\n\nfunction Editor(props: EditorProps): ReactElement {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <Suspense\n fallback={\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n }\n >\n <EditorContent {...props} />\n </Suspense>\n );\n}\n\nfunction EditorContent(props: EditorProps): ReactElement {\n const monaco = useMonaco();\n\n if (!monaco) {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n }\n\n return <MountedEditor {...props} monaco={monaco} />;\n}\n\nfunction MountedEditor({\n monaco,\n defaultValue,\n defaultLanguage,\n defaultPath,\n value,\n language,\n path,\n /* === */\n theme = 'light',\n line,\n loading = 'Loading...',\n options = {},\n overrideServices = {},\n saveViewState = true,\n keepCurrentModel = false,\n /* === */\n width = '100%',\n height = '100%',\n className,\n wrapperProps = {},\n /* === */\n beforeMount = noop,\n onMount = noop,\n onChange,\n onValidate = noop,\n}: EditorProps & { monaco: Monaco }): ReactElement {\n const [isEditorReady, setIsEditorReady] = useState(false);\n const monacoRef = useRef<Monaco>(monaco);\n const editorRef = useRef<editor.IStandaloneCodeEditor | undefined>(undefined);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const onMountRef = useRef(onMount);\n const beforeMountRef = useRef(beforeMount);\n const subscriptionRef = useRef<IDisposable | undefined>(undefined);\n const valueRef = useRef(value);\n const previousPath = usePrevious(path);\n const preventCreation = useRef(false);\n const preventTriggerChangeEvent = useRef<boolean>(false);\n\n monacoRef.current = monaco;\n\n useMount(() => {\n return () => {\n if (editorRef.current) {\n disposeEditor();\n }\n };\n });\n\n useUpdate(\n () => {\n const model = getOrCreateModel(\n monacoRef.current!,\n defaultValue || value || '',\n defaultLanguage || language || '',\n path || defaultPath || ''\n );\n\n if (model !== editorRef.current?.getModel()) {\n if (saveViewState) viewStates.set(previousPath, editorRef.current?.saveViewState());\n editorRef.current?.setModel(model);\n if (saveViewState) editorRef.current?.restoreViewState(viewStates.get(path));\n }\n },\n [path],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.updateOptions(options);\n },\n [options],\n isEditorReady\n );\n\n useUpdate(\n () => {\n if (!editorRef.current || value === undefined) return;\n if (editorRef.current.getOption(monacoRef.current!.editor.EditorOption.readOnly)) {\n editorRef.current.setValue(value);\n } else if (value !== editorRef.current.getValue()) {\n preventTriggerChangeEvent.current = true;\n editorRef.current.executeEdits('', [\n {\n range: editorRef.current.getModel()!.getFullModelRange(),\n text: value,\n forceMoveMarkers: true,\n },\n ]);\n\n editorRef.current.pushUndoStop();\n preventTriggerChangeEvent.current = false;\n }\n },\n [value],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const model = editorRef.current?.getModel();\n if (isEditorReady && model && language) {\n monacoRef.current?.editor.setModelLanguage(model, language);\n }\n },\n [language, isEditorReady],\n isEditorReady\n );\n\n useUpdate(\n () => {\n // reason for undefined check: https://github.com/suren-atoyan/monaco-react/pull/188\n if (line !== undefined) {\n editorRef.current?.revealLine(line);\n }\n },\n [line],\n isEditorReady\n );\n\n useUpdate(\n () => {\n monacoRef.current?.editor.setTheme(theme);\n },\n [theme],\n isEditorReady\n );\n\n const createEditor = useCallback(() => {\n if (!containerRef.current) return;\n if (!preventCreation.current) {\n beforeMountRef.current(monacoRef.current);\n const autoCreatedModelPath = path || defaultPath;\n\n const defaultModel = getOrCreateModel(\n monacoRef.current,\n value || defaultValue || '',\n defaultLanguage || language || '',\n autoCreatedModelPath || ''\n );\n\n const editor = monacoRef.current.editor.create(\n containerRef.current,\n {\n model: defaultModel,\n automaticLayout: true,\n ...options,\n },\n overrideServices\n );\n editorRef.current = editor;\n\n if (saveViewState) {\n editor.restoreViewState(viewStates.get(autoCreatedModelPath));\n }\n\n monacoRef.current.editor.setTheme(theme);\n\n if (line !== undefined) {\n editor.revealLine(line);\n }\n\n setIsEditorReady(true);\n preventCreation.current = true;\n }\n }, [\n defaultValue,\n defaultLanguage,\n defaultPath,\n value,\n language,\n path,\n options,\n overrideServices,\n saveViewState,\n theme,\n line,\n ]);\n\n useEffect(() => {\n if (isEditorReady) {\n onMountRef.current(editorRef.current!, monacoRef.current!);\n }\n }, [isEditorReady]);\n\n useEffect(() => {\n if (!isEditorReady) {\n createEditor();\n }\n }, [isEditorReady, createEditor]);\n\n // subscription\n // to avoid unnecessary updates (attach - dispose listener) in subscription\n valueRef.current = value;\n\n // onChange\n useEffect(() => {\n if (isEditorReady && onChange) {\n subscriptionRef.current?.dispose();\n subscriptionRef.current = editorRef.current?.onDidChangeModelContent((event) => {\n if (!preventTriggerChangeEvent.current) {\n onChange(editorRef.current!.getValue(), event);\n }\n });\n }\n }, [isEditorReady, onChange]);\n\n // onValidate\n useEffect(() => {\n if (isEditorReady) {\n const changeMarkersListener = monacoRef.current!.editor.onDidChangeMarkers((uris: readonly Uri[]) => {\n const editorUri = editorRef.current!.getModel()?.uri;\n\n if (editorUri) {\n const currentEditorHasMarkerChanges = uris.find((uri: Uri) => uri.path === editorUri.path);\n if (currentEditorHasMarkerChanges) {\n const markers = monacoRef.current!.editor.getModelMarkers({\n resource: editorUri,\n });\n onValidate?.(markers);\n }\n }\n });\n\n return () => {\n changeMarkersListener?.dispose();\n };\n }\n return () => {\n // eslint happy\n };\n }, [isEditorReady, onValidate]);\n\n function disposeEditor(): void {\n subscriptionRef.current?.dispose();\n const editor = editorRef.current!;\n const model = editor.getModel();\n\n if (keepCurrentModel) {\n if (saveViewState) {\n viewStates.set(path, editor.saveViewState());\n }\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor.setModel(null);\n } else if (model) {\n // Detach first so editor.dispose() never reads from a model that another editor already disposed.\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor.setModel(null);\n if (!model.isDisposed() && !model.isAttachedToEditor()) {\n model.dispose();\n }\n }\n\n editor.dispose();\n\n editorRef.current = undefined;\n preventCreation.current = false;\n setIsEditorReady(false);\n }\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={isEditorReady}\n loading={loading}\n _ref={containerRef}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n}\n\nexport default Editor;\n"],"mappings":"uaAcA,MAAM,EAAa,IAAI,IAEvB,SAAS,EAAO,EAAkC,CAChD,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAM,EAElG,OACE,EAAC,EAAD,CACE,SACE,EAACA,EAAD,CACS,QACC,SACR,cAAe,GACN,UACE,YACG,cACf,CAAA,WAGH,EAAC,EAAD,CAAe,GAAI,CAAQ,CAAA,CACnB,CAAA,CAEd,CAEA,SAAS,EAAc,EAAkC,CACvD,IAAM,EAAS,EAAU,EAEzB,GAAI,CAAC,EAAQ,CACX,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAM,EAElG,OACE,EAACA,EAAD,CACS,QACC,SACR,cAAe,GACN,UACE,YACG,cACf,CAAA,CAEL,CAEA,OAAO,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,EAAa,CAEjB,EAAG,CAAC,EAAe,CAAY,CAAC,EAIhC,EAAS,QAAU,EAGnB,MAAgB,CACV,GAAiB,IACnB,EAAgB,SAAS,QAAQ,EACjC,EAAgB,QAAU,EAAU,SAAS,wBAAyB,GAAU,CACzE,EAA0B,SAC7B,EAAS,EAAU,QAAS,SAAS,EAAG,CAAK,CAEjD,CAAC,EAEL,EAAG,CAAC,EAAe,CAAQ,CAAC,EAG5B,MAAgB,CACd,GAAI,EAAe,CACjB,IAAM,EAAwB,EAAU,QAAS,OAAO,mBAAoB,GAAyB,CACnG,IAAM,EAAY,EAAU,QAAS,SAAS,CAAC,EAAE,IAEjD,GAAI,GACoC,EAAK,KAAM,GAAa,EAAI,OAAS,EAAU,IACrD,EAAG,CACjC,IAAM,EAAU,EAAU,QAAS,OAAO,gBAAgB,CACxD,SAAU,CACZ,CAAC,EACD,IAAa,CAAO,CACtB,CAEJ,CAAC,EAED,UAAa,CACX,GAAuB,QAAQ,CACjC,CACF,CACA,UAAa,CAEb,CACF,EAAG,CAAC,EAAe,CAAU,CAAC,EAE9B,SAAS,GAAsB,CAC7B,EAAgB,SAAS,QAAQ,EACjC,IAAM,EAAS,EAAU,QACnB,EAAQ,EAAO,SAAS,EAE1B,GACE,GACF,EAAW,IAAI,EAAM,EAAO,cAAc,CAAC,EAG7C,EAAO,SAAS,IAAI,GACX,IAGT,EAAO,SAAS,IAAI,EAChB,CAAC,EAAM,WAAW,GAAK,CAAC,EAAM,mBAAmB,GACnD,EAAM,QAAQ,GAIlB,EAAO,QAAQ,EAEf,EAAU,QAAU,IAAA,GACpB,EAAgB,QAAU,GAC1B,EAAiB,EAAK,CACxB,CAEA,OACE,EAACA,EAAD,CACS,QACC,SACO,gBACN,UACT,KAAM,EACK,YACG,cACf,CAAA,CAEL"}
|
|
1
|
+
{"version":3,"file":"Editor.js","names":["MonacoContainer","MonacoContainer_default","useMount","useUpdate","useMonaco","usePrevious","viewStates","Editor","props","Suspense","EditorContent","monaco","MountedEditor","noop","isEditorReady","setIsEditorReady","useState","monacoRef","useRef","editorRef","containerRef","onMountRef","onMount","beforeMountRef","beforeMount","subscriptionRef","valueRef","value","previousPath","path","preventCreation","preventTriggerChangeEvent","disposeEditor","model","getOrCreateModel","defaultValue","defaultLanguage","language","defaultPath","saveViewState","options","line","theme","createEditor","useCallback","autoCreatedModelPath","defaultModel","editor","overrideServices","useEffect","onChange","event","changeMarkersListener","editorUri","uris","uri","markers","onValidate","keepCurrentModel"],"sources":["../../src/Editor/Editor.tsx"],"sourcesContent":["'use client';\n\nimport { Suspense, useState, useEffect, useRef, useCallback } from 'react';\nimport type { ReactElement } from 'react';\nimport useMount from '../hooks/useMount';\nimport useUpdate from '../hooks/useUpdate';\nimport usePrevious from '../hooks/usePrevious';\nimport useMonaco from '../hooks/useMonaco';\nimport type { IDisposable, Uri, editor } from 'monaco-editor';\nimport { noop, getOrCreateModel } from '../utils';\nimport type { EditorProps } from './types';\nimport type { Monaco } from '..';\nimport MonacoContainer from '../MonacoContainer';\n\nconst viewStates = new Map();\n\nfunction Editor(props: EditorProps): ReactElement {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <Suspense\n fallback={\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n }\n >\n <EditorContent {...props} />\n </Suspense>\n );\n}\n\nfunction EditorContent(props: EditorProps): ReactElement {\n const monaco = useMonaco();\n\n if (!monaco) {\n const { width = '100%', height = '100%', loading = 'Loading...', className, wrapperProps = {} } = props;\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={false}\n loading={loading}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n }\n\n return <MountedEditor {...props} monaco={monaco} />;\n}\n\nfunction MountedEditor({\n monaco,\n defaultValue,\n defaultLanguage,\n defaultPath,\n value,\n language,\n path,\n /* === */\n theme = 'light',\n line,\n loading = 'Loading...',\n options = {},\n overrideServices = {},\n saveViewState = true,\n keepCurrentModel = false,\n /* === */\n width = '100%',\n height = '100%',\n className,\n wrapperProps = {},\n /* === */\n beforeMount = noop,\n onMount = noop,\n onChange,\n onValidate = noop,\n}: EditorProps & { monaco: Monaco }): ReactElement {\n const [isEditorReady, setIsEditorReady] = useState(false);\n const monacoRef = useRef<Monaco>(monaco);\n const editorRef = useRef<editor.IStandaloneCodeEditor | undefined>(undefined);\n const containerRef = useRef<HTMLDivElement | null>(null);\n const onMountRef = useRef(onMount);\n const beforeMountRef = useRef(beforeMount);\n const subscriptionRef = useRef<IDisposable | undefined>(undefined);\n const valueRef = useRef(value);\n const previousPath = usePrevious(path);\n const preventCreation = useRef(false);\n const preventTriggerChangeEvent = useRef<boolean>(false);\n\n monacoRef.current = monaco;\n\n useMount(() => {\n return () => {\n if (editorRef.current) {\n disposeEditor();\n }\n };\n });\n\n useUpdate(\n () => {\n const model = getOrCreateModel(\n monacoRef.current!,\n defaultValue || value || '',\n defaultLanguage || language || '',\n path || defaultPath || ''\n );\n\n if (model !== editorRef.current?.getModel()) {\n if (saveViewState) viewStates.set(previousPath, editorRef.current?.saveViewState());\n editorRef.current?.setModel(model);\n if (saveViewState) editorRef.current?.restoreViewState(viewStates.get(path));\n }\n },\n [path],\n isEditorReady\n );\n\n useUpdate(\n () => {\n editorRef.current?.updateOptions(options);\n },\n [options],\n isEditorReady\n );\n\n useUpdate(\n () => {\n if (!editorRef.current || value === undefined) return;\n if (editorRef.current.getOption(monacoRef.current!.editor.EditorOption.readOnly)) {\n editorRef.current.setValue(value);\n } else if (value !== editorRef.current.getValue()) {\n preventTriggerChangeEvent.current = true;\n editorRef.current.executeEdits('', [\n {\n range: editorRef.current.getModel()!.getFullModelRange(),\n text: value,\n forceMoveMarkers: true,\n },\n ]);\n\n editorRef.current.pushUndoStop();\n preventTriggerChangeEvent.current = false;\n }\n },\n [value],\n isEditorReady\n );\n\n useUpdate(\n () => {\n const model = editorRef.current?.getModel();\n if (isEditorReady && model && language) {\n monacoRef.current?.editor.setModelLanguage(model, language);\n }\n },\n [language, isEditorReady],\n isEditorReady\n );\n\n useUpdate(\n () => {\n // reason for undefined check: https://github.com/suren-atoyan/monaco-react/pull/188\n if (line !== undefined) {\n editorRef.current?.revealLine(line);\n }\n },\n [line],\n isEditorReady\n );\n\n useUpdate(\n () => {\n monacoRef.current?.editor.setTheme(theme);\n },\n [theme],\n isEditorReady\n );\n\n const createEditor = useCallback(() => {\n if (!containerRef.current) return;\n if (!preventCreation.current) {\n beforeMountRef.current(monacoRef.current);\n const autoCreatedModelPath = path || defaultPath;\n\n const defaultModel = getOrCreateModel(\n monacoRef.current,\n value || defaultValue || '',\n defaultLanguage || language || '',\n autoCreatedModelPath || ''\n );\n\n const editor = monacoRef.current.editor.create(\n containerRef.current,\n {\n model: defaultModel,\n automaticLayout: true,\n ...options,\n },\n overrideServices\n );\n editorRef.current = editor;\n\n if (saveViewState) {\n editor.restoreViewState(viewStates.get(autoCreatedModelPath));\n }\n\n monacoRef.current.editor.setTheme(theme);\n\n if (line !== undefined) {\n editor.revealLine(line);\n }\n\n setIsEditorReady(true);\n preventCreation.current = true;\n }\n }, [\n defaultValue,\n defaultLanguage,\n defaultPath,\n value,\n language,\n path,\n options,\n overrideServices,\n saveViewState,\n theme,\n line,\n ]);\n\n useEffect(() => {\n if (isEditorReady) {\n onMountRef.current(editorRef.current!, monacoRef.current!);\n }\n }, [isEditorReady]);\n\n useEffect(() => {\n if (!isEditorReady) {\n createEditor();\n }\n }, [isEditorReady, createEditor]);\n\n // subscription\n // to avoid unnecessary updates (attach - dispose listener) in subscription\n valueRef.current = value;\n\n // onChange\n useEffect(() => {\n if (isEditorReady && onChange) {\n subscriptionRef.current?.dispose();\n subscriptionRef.current = editorRef.current?.onDidChangeModelContent((event) => {\n if (!preventTriggerChangeEvent.current) {\n onChange(editorRef.current!.getValue(), event);\n }\n });\n }\n }, [isEditorReady, onChange]);\n\n // onValidate\n useEffect(() => {\n if (isEditorReady) {\n const changeMarkersListener = monacoRef.current!.editor.onDidChangeMarkers((uris: readonly Uri[]) => {\n const editorUri = editorRef.current!.getModel()?.uri;\n\n if (editorUri) {\n const currentEditorHasMarkerChanges = uris.find((uri: Uri) => uri.path === editorUri.path);\n if (currentEditorHasMarkerChanges) {\n const markers = monacoRef.current!.editor.getModelMarkers({\n resource: editorUri,\n });\n onValidate?.(markers);\n }\n }\n });\n\n return () => {\n changeMarkersListener?.dispose();\n };\n }\n return () => {\n // eslint happy\n };\n }, [isEditorReady, onValidate]);\n\n function disposeEditor(): void {\n subscriptionRef.current?.dispose();\n const editor = editorRef.current!;\n const model = editor.getModel();\n\n if (keepCurrentModel) {\n if (saveViewState) {\n viewStates.set(path, editor.saveViewState());\n }\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor.setModel(null);\n } else if (model) {\n // Detach first so editor.dispose() never reads from a model that another editor already disposed.\n // oxlint-disable-next-line unicorn/no-null -- Monaco detaches editor models with null.\n editor.setModel(null);\n if (!model.isDisposed() && !model.isAttachedToEditor()) {\n model.dispose();\n }\n }\n\n editor.dispose();\n\n editorRef.current = undefined;\n preventCreation.current = false;\n setIsEditorReady(false);\n }\n\n return (\n <MonacoContainer\n width={width}\n height={height}\n isEditorReady={isEditorReady}\n loading={loading}\n _ref={containerRef}\n className={className}\n wrapperProps={wrapperProps}\n />\n );\n}\n\nexport default Editor;\n"],"mappings":"uaAcA,MAAMM,kBAAa,IAAI,IAEvB,SAASC,EAAO,EAAkC,CAChD,GAAM,CAAE,QAAQ,OAAQ,SAAS,OAAQ,UAAU,aAAc,YAAW,eAAe,CAAC,GAAMC,EAElG,MACE,kBAACC,EAAD,CACE,SACE,kBAACT,EAAD,CACS,QACC,SACR,cAAe,GACN,UACE,YACG,cACf,CAAA,EAGH,SAAA,kBAACU,EAAD,CAAe,GAAIF,CAAQ,CAAA,CACnB,CAAA,CAEd,CAEA,SAASE,EAAc,EAAkC,CACvD,IAAMC,EAASP,EAAU,EAEzB,GAAI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AAQc,EAAO,SAAS,EAE1BW,GACEnB,GACFjC,EAAW,IAAIuB,EAAMkB,EAAO,cAAc,CAAC,EAG7CA,EAAO,SAAS,IAAI,GACXd,IAGTc,EAAO,SAAS,IAAI,EAChB,CAACd,EAAM,WAAW,GAAK,CAACA,EAAM,mBAAmB,GACnDA,EAAM,QAAQ,GAIlBc,EAAO,QAAQ,EAEf,EAAU,QAAU,IAAA,GACpB,EAAgB,QAAU,GAC1BhC,EAAiB,EAAK,CACxB,CAEA,MACE,kBAACf,EAAD,CACS,QACC,SACO,gBACN,UACT,KAAMoB,EACK,YACG,cACf,CAAA,CAEL"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Editor"],"sources":["../../src/Editor/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport Editor from './Editor';\n\nexport * from './types';\n\nexport default memo(Editor);\n"],"mappings":"6CAMA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["memo","Editor","require_Editor","Editor_default"],"sources":["../../src/Editor/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport Editor from './Editor';\n\nexport * from './types';\n\nexport default memo(Editor);\n"],"mappings":"6CAMA,IAAAG,GAAA,iBAAeH,CAAAA,CAAAA,KAAAA,CAAKC,EAAAA,OAAM"}
|
package/dist/Editor/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/Editor/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport Editor from './Editor';\n\nexport * from './types';\n\nexport default memo(Editor);\n"],"mappings":"wDAMA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["Editor","Editor_default","memo"],"sources":["../../src/Editor/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport Editor from './Editor';\n\nexport * from './types';\n\nexport default memo(Editor);\n"],"mappings":"wDAMA,IAAAC,EAAeC,EAAKF,CAAM"}
|
package/dist/Loading/Loading.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e=require("./styles.cjs");let t=require("react/jsx-runtime");function n({children:n}){return(0,t.jsx)(`div`,{style:e.default.container,children:n})}exports.default=n;
|
|
1
|
+
"use strict";const e=require("./styles.cjs");let t=require("react/jsx-runtime");function n({children:n}){return/* @__PURE__ */ (0,t.jsx)(`div`,{style:e.default.container,children:n})}exports.default=n;
|
|
2
2
|
//# sourceMappingURL=Loading.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Loading.cjs","names":["styles"],"sources":["../../src/Loading/Loading.tsx"],"sourcesContent":["import type { PropsWithChildren, ReactElement } from 'react';\n\nimport styles from './styles';\n\nfunction Loading({ children }: PropsWithChildren): ReactElement {\n return <div style={styles.container}>{children}</div>;\n}\n\nexport default Loading;\n"],"mappings":"gFAIA,
|
|
1
|
+
{"version":3,"file":"Loading.cjs","names":["styles","require_styles","react_jsx_runtime","Loading"],"sources":["../../src/Loading/Loading.tsx"],"sourcesContent":["import type { PropsWithChildren, ReactElement } from 'react';\n\nimport styles from './styles';\n\nfunction Loading({ children }: PropsWithChildren): ReactElement {\n return <div style={styles.container}>{children}</div>;\n}\n\nexport default Loading;\n"],"mappings":"gFAIA,SAASG,EAAQ,CAAE,YAA6C,CAC9D,MAAO,iBAAA,EAAAD,EAAA,IAAA,CAAC,MAAD,CAAK,MAAOF,EAAAA,QAAO,UAAY,UAAc,CAAA,CACtD"}
|
package/dist/Loading/Loading.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"./styles.js";import{jsx as t}from"react/jsx-runtime";function n({children:n}){return t(`div`,{style:e.container,children:n})}export{n as default};
|
|
1
|
+
import e from"./styles.js";import{jsx as t}from"react/jsx-runtime";function n({children:n}){return/* @__PURE__ */ t(`div`,{style:e.container,children:n})}export{n as default};
|
|
2
2
|
//# sourceMappingURL=Loading.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Loading.js","names":[],"sources":["../../src/Loading/Loading.tsx"],"sourcesContent":["import type { PropsWithChildren, ReactElement } from 'react';\n\nimport styles from './styles';\n\nfunction Loading({ children }: PropsWithChildren): ReactElement {\n return <div style={styles.container}>{children}</div>;\n}\n\nexport default Loading;\n"],"mappings":"mEAIA,
|
|
1
|
+
{"version":3,"file":"Loading.js","names":["styles","Loading"],"sources":["../../src/Loading/Loading.tsx"],"sourcesContent":["import type { PropsWithChildren, ReactElement } from 'react';\n\nimport styles from './styles';\n\nfunction Loading({ children }: PropsWithChildren): ReactElement {\n return <div style={styles.container}>{children}</div>;\n}\n\nexport default Loading;\n"],"mappings":"mEAIA,SAASC,EAAQ,CAAE,YAA6C,CAC9D,MAAO,kBAAC,MAAD,CAAK,MAAOD,EAAO,UAAY,UAAc,CAAA,CACtD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Loading"],"sources":["../../src/Loading/index.ts"],"sourcesContent":["import Loading from './Loading';\n\nexport default Loading;\n"],"mappings":"aAEA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Loading","Loading_default"],"sources":["../../src/Loading/index.ts"],"sourcesContent":["import Loading from './Loading';\n\nexport default Loading;\n"],"mappings":"aAEA,IAAAC,yBAAeD,CAAAA,CAAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/Loading/index.ts"],"sourcesContent":["import Loading from './Loading';\n\nexport default Loading;\n"],"mappings":"4BAEA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["Loading","Loading_default"],"sources":["../../src/Loading/index.ts"],"sourcesContent":["import Loading from './Loading';\n\nexport default Loading;\n"],"mappings":"4BAEA,IAAAC,EAAeD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.cjs","names":[],"sources":["../../src/Loading/styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nconst styles: Record<string, CSSProperties> = {\n container: {\n display: 'flex',\n height: '100%',\n width: '100%',\n justifyContent: 'center',\n alignItems: 'center',\n },\n};\n\nexport default styles;\n"],"mappings":"aAEA,
|
|
1
|
+
{"version":3,"file":"styles.cjs","names":["styles"],"sources":["../../src/Loading/styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nconst styles: Record<string, CSSProperties> = {\n container: {\n display: 'flex',\n height: '100%',\n width: '100%',\n justifyContent: 'center',\n alignItems: 'center',\n },\n};\n\nexport default styles;\n"],"mappings":"aAEA,MAAMA,EAAwC,CAC5C,UAAW,CACT,QAAS,OACT,OAAQ,OACR,MAAO,OACP,eAAgB,SAChB,WAAY,QACd,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","names":[],"sources":["../../src/Loading/styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nconst styles: Record<string, CSSProperties> = {\n container: {\n display: 'flex',\n height: '100%',\n width: '100%',\n justifyContent: 'center',\n alignItems: 'center',\n },\n};\n\nexport default styles;\n"],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"styles.js","names":["styles"],"sources":["../../src/Loading/styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nconst styles: Record<string, CSSProperties> = {\n container: {\n display: 'flex',\n height: '100%',\n width: '100%',\n justifyContent: 'center',\n alignItems: 'center',\n },\n};\n\nexport default styles;\n"],"mappings":"AAEA,MAAMA,EAAwC,CAC5C,UAAW,CACT,QAAS,OACT,OAAQ,OACR,MAAO,OACP,eAAgB,SAChB,WAAY,QACd,CACF"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const e=require("./styles.cjs"),t=require("../Loading/index.cjs");let n=require("react/jsx-runtime");function r({width:r,height:i,isEditorReady:a,loading:o,_ref:s,className:c,wrapperProps:l}){return(0,n.jsxs)(`section`,{style:{...e.default.wrapper,width:r,height:i},...l,children:[!a
|
|
1
|
+
"use strict";const e=require("./styles.cjs"),t=require("../Loading/index.cjs");let n=require("react/jsx-runtime");function r({width:r,height:i,isEditorReady:a,loading:o,_ref:s,className:c,wrapperProps:l}){return/* @__PURE__ */ (0,n.jsxs)(`section`,{style:{...e.default.wrapper,width:r,height:i},...l,children:[!a&&/* @__PURE__ */ (0,n.jsx)(t.default,{children:o}),/* @__PURE__ */ (0,n.jsx)(`div`,{ref:s,style:{...e.default.fullWidth,...!a&&e.default.hide},className:c})]})}exports.default=r;
|
|
2
2
|
//# sourceMappingURL=MonacoContainer.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MonacoContainer.cjs","names":["styles","Loading"],"sources":["../../src/MonacoContainer/MonacoContainer.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\n\nimport styles from './styles';\nimport Loading from '../Loading';\nimport type { ContainerProps } from './types';\n\n// ** forwardref render functions do not support proptypes or defaultprops **\n// one of the reasons why we use a separate prop for passing ref instead of using forwardref\n\nfunction MonacoContainer({\n width,\n height,\n isEditorReady,\n loading,\n _ref,\n className,\n wrapperProps,\n}: ContainerProps): ReactElement {\n return (\n <section style={{ ...styles.wrapper, width, height }} {...wrapperProps}>\n {!isEditorReady && <Loading>{loading}</Loading>}\n <div ref={_ref} style={{ ...styles.fullWidth, ...(!isEditorReady && styles.hide) }} className={className} />\n </section>\n );\n}\n\nexport default MonacoContainer;\n"],"mappings":"kHASA,
|
|
1
|
+
{"version":3,"file":"MonacoContainer.cjs","names":["styles","Loading","require_styles","require_index","react_jsx_runtime","MonacoContainer","wrapperProps","isEditorReady","loading","_ref"],"sources":["../../src/MonacoContainer/MonacoContainer.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\n\nimport styles from './styles';\nimport Loading from '../Loading';\nimport type { ContainerProps } from './types';\n\n// ** forwardref render functions do not support proptypes or defaultprops **\n// one of the reasons why we use a separate prop for passing ref instead of using forwardref\n\nfunction MonacoContainer({\n width,\n height,\n isEditorReady,\n loading,\n _ref,\n className,\n wrapperProps,\n}: ContainerProps): ReactElement {\n return (\n <section style={{ ...styles.wrapper, width, height }} {...wrapperProps}>\n {!isEditorReady && <Loading>{loading}</Loading>}\n <div ref={_ref} style={{ ...styles.fullWidth, ...(!isEditorReady && styles.hide) }} className={className} />\n </section>\n );\n}\n\nexport default MonacoContainer;\n"],"mappings":"kHASA,SAASK,EAAgB,CACvB,QACA,SACA,gBACA,UACA,OACA,YACA,gBAC+B,CAC/B,MACE,iBAAA,EAAAD,EAAA,KAAA,CAAC,UAAD,CAAS,MAAO,CAAE,GAAGJ,EAAAA,QAAO,QAAS,QAAO,QAAO,EAAG,GAAIM,EAA1D,SAAA,CACG,CAACC,GAAiB,iBAAA,EAAAH,EAAA,IAAA,CAACH,EAAAA,QAAD,CAAA,SAAUO,CAAiB,CAAA,EAC9C,iBAAA,EAAAJ,EAAA,IAAA,CAAC,MAAD,CAAK,IAAKK,EAAM,MAAO,CAAE,GAAGT,EAAAA,QAAO,UAAW,GAAI,CAACO,GAAiBP,EAAAA,QAAO,IAAM,EAAc,WAAY,CAAA,CACpG,GAEb"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import e from"./styles.js";import t from"../Loading/index.js";import{jsx as n,jsxs as r}from"react/jsx-runtime";function i({width:i,height:a,isEditorReady:o,loading:s,_ref:c,className:l,wrapperProps:u}){return r(`section`,{style:{...e.wrapper,width:i,height:a},...u,children:[!o
|
|
1
|
+
import e from"./styles.js";import t from"../Loading/index.js";import{jsx as n,jsxs as r}from"react/jsx-runtime";function i({width:i,height:a,isEditorReady:o,loading:s,_ref:c,className:l,wrapperProps:u}){return/* @__PURE__ */ r(`section`,{style:{...e.wrapper,width:i,height:a},...u,children:[!o&&/* @__PURE__ */ n(t,{children:s}),/* @__PURE__ */ n(`div`,{ref:c,style:{...e.fullWidth,...!o&&e.hide},className:l})]})}export{i as default};
|
|
2
2
|
//# sourceMappingURL=MonacoContainer.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MonacoContainer.js","names":["Loading"],"sources":["../../src/MonacoContainer/MonacoContainer.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\n\nimport styles from './styles';\nimport Loading from '../Loading';\nimport type { ContainerProps } from './types';\n\n// ** forwardref render functions do not support proptypes or defaultprops **\n// one of the reasons why we use a separate prop for passing ref instead of using forwardref\n\nfunction MonacoContainer({\n width,\n height,\n isEditorReady,\n loading,\n _ref,\n className,\n wrapperProps,\n}: ContainerProps): ReactElement {\n return (\n <section style={{ ...styles.wrapper, width, height }} {...wrapperProps}>\n {!isEditorReady && <Loading>{loading}</Loading>}\n <div ref={_ref} style={{ ...styles.fullWidth, ...(!isEditorReady && styles.hide) }} className={className} />\n </section>\n );\n}\n\nexport default MonacoContainer;\n"],"mappings":"gHASA,
|
|
1
|
+
{"version":3,"file":"MonacoContainer.js","names":["Loading","styles","Loading_default","MonacoContainer","wrapperProps","isEditorReady","loading","_ref"],"sources":["../../src/MonacoContainer/MonacoContainer.tsx"],"sourcesContent":["import type { ReactElement } from 'react';\n\nimport styles from './styles';\nimport Loading from '../Loading';\nimport type { ContainerProps } from './types';\n\n// ** forwardref render functions do not support proptypes or defaultprops **\n// one of the reasons why we use a separate prop for passing ref instead of using forwardref\n\nfunction MonacoContainer({\n width,\n height,\n isEditorReady,\n loading,\n _ref,\n className,\n wrapperProps,\n}: ContainerProps): ReactElement {\n return (\n <section style={{ ...styles.wrapper, width, height }} {...wrapperProps}>\n {!isEditorReady && <Loading>{loading}</Loading>}\n <div ref={_ref} style={{ ...styles.fullWidth, ...(!isEditorReady && styles.hide) }} className={className} />\n </section>\n );\n}\n\nexport default MonacoContainer;\n"],"mappings":"gHASA,SAASG,EAAgB,CACvB,QACA,SACA,gBACA,UACA,OACA,YACA,gBAC+B,CAC/B,MACE,kBAAC,UAAD,CAAS,MAAO,CAAE,GAAGF,EAAO,QAAS,QAAO,QAAO,EAAG,GAAIG,EAA1D,SAAA,CACG,CAACC,GAAiB,kBAACL,EAAD,CAAA,SAAUM,CAAiB,CAAA,EAC9C,kBAAC,MAAD,CAAK,IAAKC,EAAM,MAAO,CAAE,GAAGN,EAAO,UAAW,GAAI,CAACI,GAAiBJ,EAAO,IAAM,EAAc,WAAY,CAAA,CACpG,GAEb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["MonacoContainer"],"sources":["../../src/MonacoContainer/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport MonacoContainer from './MonacoContainer';\n\nexport default memo(MonacoContainer);\n"],"mappings":"sDAIA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["memo","MonacoContainer","require_MonacoContainer","MonacoContainer_default"],"sources":["../../src/MonacoContainer/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport MonacoContainer from './MonacoContainer';\n\nexport default memo(MonacoContainer);\n"],"mappings":"sDAIA,IAAAG,GAAA,iBAAeH,CAAAA,CAAAA,KAAAA,CAAKC,EAAAA,OAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/MonacoContainer/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport MonacoContainer from './MonacoContainer';\n\nexport default memo(MonacoContainer);\n"],"mappings":"iEAIA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["MonacoContainer","MonacoContainer_default","memo"],"sources":["../../src/MonacoContainer/index.ts"],"sourcesContent":["import { memo } from 'react';\n\nimport MonacoContainer from './MonacoContainer';\n\nexport default memo(MonacoContainer);\n"],"mappings":"iEAIA,IAAAC,EAAeC,EAAKF,CAAe"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.cjs","names":[],"sources":["../../src/MonacoContainer/styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nconst styles: Record<string, CSSProperties> = {\n wrapper: {\n display: 'flex',\n position: 'relative',\n textAlign: 'initial',\n },\n fullWidth: {\n width: '100%',\n },\n hide: {\n display: 'none',\n },\n};\n\nexport default styles;\n"],"mappings":"aAEA,
|
|
1
|
+
{"version":3,"file":"styles.cjs","names":["styles"],"sources":["../../src/MonacoContainer/styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nconst styles: Record<string, CSSProperties> = {\n wrapper: {\n display: 'flex',\n position: 'relative',\n textAlign: 'initial',\n },\n fullWidth: {\n width: '100%',\n },\n hide: {\n display: 'none',\n },\n};\n\nexport default styles;\n"],"mappings":"aAEA,MAAMA,EAAwC,CAC5C,QAAS,CACP,QAAS,OACT,SAAU,WACV,UAAW,SACb,EACA,UAAW,CACT,MAAO,MACT,EACA,KAAM,CACJ,QAAS,MACX,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"styles.js","names":[],"sources":["../../src/MonacoContainer/styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nconst styles: Record<string, CSSProperties> = {\n wrapper: {\n display: 'flex',\n position: 'relative',\n textAlign: 'initial',\n },\n fullWidth: {\n width: '100%',\n },\n hide: {\n display: 'none',\n },\n};\n\nexport default styles;\n"],"mappings":"AAEA,
|
|
1
|
+
{"version":3,"file":"styles.js","names":["styles"],"sources":["../../src/MonacoContainer/styles.ts"],"sourcesContent":["import type { CSSProperties } from 'react';\n\nconst styles: Record<string, CSSProperties> = {\n wrapper: {\n display: 'flex',\n position: 'relative',\n textAlign: 'initial',\n },\n fullWidth: {\n width: '100%',\n },\n hide: {\n display: 'none',\n },\n};\n\nexport default styles;\n"],"mappings":"AAEA,MAAMA,EAAwC,CAC5C,QAAS,CACP,QAAS,OACT,SAAU,WACV,UAAW,SACb,EACA,UAAW,CACT,MAAO,MACT,EACA,KAAM,CACJ,QAAS,MACX,CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,
|
|
1
|
+
"use strict";var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,s)=>(s=n==null?{}:e(i(n)),o(r||!n||!n.__esModule||!a.call(n,`default`)?t(s,`default`,{value:n,enumerable:!0}):s,n));exports.__toESM=s;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["initMonaco"],"sources":["../../../src/hooks/useMonaco/index.ts"],"sourcesContent":["import { use, useSyncExternalStore } from 'react';\n\nimport type { Monaco } from '../..';\nimport initMonaco from './initMonaco';\n\nfunction useMonaco(): Monaco | undefined {\n const isHydrated = useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);\n\n if (!isHydrated) {\n return undefined;\n }\n\n return use(initMonaco());\n}\n\nfunction subscribe(onStoreChange: () => void): () => void {\n const timeoutId = setTimeout(onStoreChange, 0);\n\n return () => {\n clearTimeout(timeoutId);\n };\n}\n\nfunction getClientSnapshot(): boolean {\n return true;\n}\n\nfunction getServerSnapshot(): boolean {\n return false;\n}\n\nexport default useMonaco;\n"],"mappings":"wEAKA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useSyncExternalStore","use","initMonaco","require_initMonaco","react","useMonaco","subscribe","getClientSnapshot","getServerSnapshot","timeoutId","onStoreChange"],"sources":["../../../src/hooks/useMonaco/index.ts"],"sourcesContent":["import { use, useSyncExternalStore } from 'react';\n\nimport type { Monaco } from '../..';\nimport initMonaco from './initMonaco';\n\nfunction useMonaco(): Monaco | undefined {\n const isHydrated = useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);\n\n if (!isHydrated) {\n return undefined;\n }\n\n return use(initMonaco());\n}\n\nfunction subscribe(onStoreChange: () => void): () => void {\n const timeoutId = setTimeout(onStoreChange, 0);\n\n return () => {\n clearTimeout(timeoutId);\n };\n}\n\nfunction getClientSnapshot(): boolean {\n return true;\n}\n\nfunction getServerSnapshot(): boolean {\n return false;\n}\n\nexport default useMonaco;\n"],"mappings":"wEAKA,SAASK,GAAgC,CAGvC,IAAI,EAFeL,EAAAA,qBAAAA,CAAqBM,EAAWC,EAAmBC,CAExD,EAId,OAAA,EAAOP,EAAAA,IAAAA,CAAIC,EAAAA,QAAW,CAAC,CACzB,CAEA,SAASI,EAAU,EAAuC,CACxD,IAAMG,EAAY,WAAWC,EAAe,CAAC,EAE7C,UAAa,CACX,aAAaD,CAAS,CACxB,CACF,CAEA,SAASF,GAA6B,CACpC,MAAO,EACT,CAEA,SAASC,GAA6B,CACpC,MAAO,EACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/useMonaco/index.ts"],"sourcesContent":["import { use, useSyncExternalStore } from 'react';\n\nimport type { Monaco } from '../..';\nimport initMonaco from './initMonaco';\n\nfunction useMonaco(): Monaco | undefined {\n const isHydrated = useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);\n\n if (!isHydrated) {\n return undefined;\n }\n\n return use(initMonaco());\n}\n\nfunction subscribe(onStoreChange: () => void): () => void {\n const timeoutId = setTimeout(onStoreChange, 0);\n\n return () => {\n clearTimeout(timeoutId);\n };\n}\n\nfunction getClientSnapshot(): boolean {\n return true;\n}\n\nfunction getServerSnapshot(): boolean {\n return false;\n}\n\nexport default useMonaco;\n"],"mappings":"qFAKA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["initMonaco","useMonaco","useSyncExternalStore","subscribe","getClientSnapshot","getServerSnapshot","use","timeoutId","onStoreChange"],"sources":["../../../src/hooks/useMonaco/index.ts"],"sourcesContent":["import { use, useSyncExternalStore } from 'react';\n\nimport type { Monaco } from '../..';\nimport initMonaco from './initMonaco';\n\nfunction useMonaco(): Monaco | undefined {\n const isHydrated = useSyncExternalStore(subscribe, getClientSnapshot, getServerSnapshot);\n\n if (!isHydrated) {\n return undefined;\n }\n\n return use(initMonaco());\n}\n\nfunction subscribe(onStoreChange: () => void): () => void {\n const timeoutId = setTimeout(onStoreChange, 0);\n\n return () => {\n clearTimeout(timeoutId);\n };\n}\n\nfunction getClientSnapshot(): boolean {\n return true;\n}\n\nfunction getServerSnapshot(): boolean {\n return false;\n}\n\nexport default useMonaco;\n"],"mappings":"qFAKA,SAASC,GAAgC,CAGvC,GAFmBC,EAAqBC,EAAWC,EAAmBC,CAExD,EAId,OAAOC,EAAIN,EAAW,CAAC,CACzB,CAEA,SAASG,EAAU,EAAuC,CACxD,IAAMI,EAAY,WAAWC,EAAe,CAAC,EAE7C,UAAa,CACX,aAAaD,CAAS,CACxB,CACF,CAEA,SAASH,GAA6B,CACpC,MAAO,EACT,CAEA,SAASC,GAA6B,CACpC,MAAO,EACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initMonaco.cjs","names":["loader"],"sources":["../../../src/hooks/useMonaco/initMonaco.ts"],"sourcesContent":["import loader from '@willbooster/monaco-loader';\n\nimport type { Monaco } from '../..';\n\nlet monacoPromise: Promise<Monaco> | undefined;\n\nfunction initMonaco(): Promise<Monaco> {\n monacoPromise ??= loader.init() as Promise<Monaco>;\n return monacoPromise;\n}\n\nexport default initMonaco;\n"],"mappings":"kIAIA,
|
|
1
|
+
{"version":3,"file":"initMonaco.cjs","names":["loader","require_runtime","_willbooster_monaco_loader","monacoPromise","initMonaco"],"sources":["../../../src/hooks/useMonaco/initMonaco.ts"],"sourcesContent":["import loader from '@willbooster/monaco-loader';\n\nimport type { Monaco } from '../..';\n\nlet monacoPromise: Promise<Monaco> | undefined;\n\nfunction initMonaco(): Promise<Monaco> {\n monacoPromise ??= loader.init() as Promise<Monaco>;\n return monacoPromise;\n}\n\nexport default initMonaco;\n"],"mappings":"kIAIA,IAAIG,EAEJ,SAASC,GAA8B,CAErC,MADA,KAAkBJ,EAAAA,QAAO,KAAK,EACvBG,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"initMonaco.js","names":[],"sources":["../../../src/hooks/useMonaco/initMonaco.ts"],"sourcesContent":["import loader from '@willbooster/monaco-loader';\n\nimport type { Monaco } from '../..';\n\nlet monacoPromise: Promise<Monaco> | undefined;\n\nfunction initMonaco(): Promise<Monaco> {\n monacoPromise ??= loader.init() as Promise<Monaco>;\n return monacoPromise;\n}\n\nexport default initMonaco;\n"],"mappings":"0CAIA,
|
|
1
|
+
{"version":3,"file":"initMonaco.js","names":["loader","monacoPromise","initMonaco"],"sources":["../../../src/hooks/useMonaco/initMonaco.ts"],"sourcesContent":["import loader from '@willbooster/monaco-loader';\n\nimport type { Monaco } from '../..';\n\nlet monacoPromise: Promise<Monaco> | undefined;\n\nfunction initMonaco(): Promise<Monaco> {\n monacoPromise ??= loader.init() as Promise<Monaco>;\n return monacoPromise;\n}\n\nexport default initMonaco;\n"],"mappings":"0CAIA,IAAIC,EAEJ,SAASC,GAA8B,CAErC,MADA,KAAkBF,EAAO,KAAK,EACvBC,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/hooks/useMount/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { EffectCallback } from 'react';\n\nfunction useMount(effect: EffectCallback): void {\n const effectRef = useRef(effect);\n\n useEffect(() => effectRef.current(), []);\n}\n\nexport default useMount;\n"],"mappings":"oCAGA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useRef","react","useMount","effectRef","effect"],"sources":["../../../src/hooks/useMount/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { EffectCallback } from 'react';\n\nfunction useMount(effect: EffectCallback): void {\n const effectRef = useRef(effect);\n\n useEffect(() => effectRef.current(), []);\n}\n\nexport default useMount;\n"],"mappings":"oCAGA,SAASE,EAAS,EAA8B,CAC9C,IAAMC,GAAA,EAAYH,EAAAA,OAAAA,CAAOI,CAAM,GAE/B,EAAAH,EAAA,UAAA,KAAgBE,EAAU,QAAQ,EAAG,CAAC,CAAC,CACzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/useMount/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { EffectCallback } from 'react';\n\nfunction useMount(effect: EffectCallback): void {\n const effectRef = useRef(effect);\n\n useEffect(() => effectRef.current(), []);\n}\n\nexport default useMount;\n"],"mappings":"8CAGA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["useMount","effectRef","useRef","effect","useEffect"],"sources":["../../../src/hooks/useMount/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { EffectCallback } from 'react';\n\nfunction useMount(effect: EffectCallback): void {\n const effectRef = useRef(effect);\n\n useEffect(() => effectRef.current(), []);\n}\n\nexport default useMount;\n"],"mappings":"8CAGA,SAASA,EAAS,EAA8B,CAC9C,IAAMC,EAAYC,EAAOC,CAAM,EAE/BC,MAAgBH,EAAU,QAAQ,EAAG,CAAC,CAAC,CACzC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/hooks/usePrevious/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nfunction usePrevious<T>(value: T): T | undefined {\n const ref = useRef<T | undefined>(undefined);\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n\nexport default usePrevious;\n"],"mappings":"oCAEA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useRef","react","usePrevious","ref","value"],"sources":["../../../src/hooks/usePrevious/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nfunction usePrevious<T>(value: T): T | undefined {\n const ref = useRef<T | undefined>(undefined);\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n\nexport default usePrevious;\n"],"mappings":"oCAEA,SAASE,EAAe,EAAyB,CAC/C,IAAMC,GAAA,EAAMH,EAAAA,OAAAA,CAAsB,IAAA,EAAS,EAM3C,OAJA,EAAAC,EAAA,UAAA,KAAgB,CACd,EAAI,QAAUG,CAChB,EAAG,CAACA,CAAK,CAAC,EAEHD,EAAI,OACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/usePrevious/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nfunction usePrevious<T>(value: T): T | undefined {\n const ref = useRef<T | undefined>(undefined);\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n\nexport default usePrevious;\n"],"mappings":"8CAEA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["usePrevious","ref","useRef","useEffect","value"],"sources":["../../../src/hooks/usePrevious/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\n\nfunction usePrevious<T>(value: T): T | undefined {\n const ref = useRef<T | undefined>(undefined);\n\n useEffect(() => {\n ref.current = value;\n }, [value]);\n\n return ref.current;\n}\n\nexport default usePrevious;\n"],"mappings":"8CAEA,SAASA,EAAe,EAAyB,CAC/C,IAAMC,EAAMC,EAAsB,IAAA,EAAS,EAM3C,OAJAC,MAAgB,CACd,EAAI,QAAUC,CAChB,EAAG,CAACA,CAAK,CAAC,EAEHH,EAAI,OACb"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../../src/hooks/useUpdate/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { DependencyList, EffectCallback } from 'react';\n\nfunction useUpdate(effect: EffectCallback, deps: DependencyList, applyChanges = true): void {\n const isInitialMount = useRef(true);\n const applyChangesRef = useRef(applyChanges);\n const effectRef = useRef(effect);\n\n applyChangesRef.current = applyChanges;\n effectRef.current = effect;\n\n useEffect(() => {\n if (isInitialMount.current || !applyChangesRef.current) {\n isInitialMount.current = false;\n return;\n }\n\n return effectRef.current();\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- useUpdate forwards caller-owned dependencies.\n }, deps);\n}\n\nexport default useUpdate;\n"],"mappings":"oCAGA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["useRef","react","useUpdate","isInitialMount","applyChangesRef","applyChanges","effectRef","effect","deps"],"sources":["../../../src/hooks/useUpdate/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { DependencyList, EffectCallback } from 'react';\n\nfunction useUpdate(effect: EffectCallback, deps: DependencyList, applyChanges = true): void {\n const isInitialMount = useRef(true);\n const applyChangesRef = useRef(applyChanges);\n const effectRef = useRef(effect);\n\n applyChangesRef.current = applyChanges;\n effectRef.current = effect;\n\n useEffect(() => {\n if (isInitialMount.current || !applyChangesRef.current) {\n isInitialMount.current = false;\n return;\n }\n\n return effectRef.current();\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- useUpdate forwards caller-owned dependencies.\n }, deps);\n}\n\nexport default useUpdate;\n"],"mappings":"oCAGA,SAASE,EAAU,EAAwB,EAAsB,EAAe,GAAY,CAC1F,IAAMC,GAAA,EAAiBH,EAAAA,OAAAA,CAAO,EAAI,EAC5BI,GAAA,EAAkBJ,EAAAA,OAAAA,CAAOK,CAAY,EACrCC,GAAA,EAAYN,EAAAA,OAAAA,CAAOO,CAAM,EAE/B,EAAgB,QAAUF,EAC1B,EAAU,QAAUE,GAEpB,EAAAN,EAAA,UAAA,KAAgB,CACd,GAAIE,EAAe,SAAW,CAACC,EAAgB,QAAS,CACtD,EAAe,QAAU,GACzB,MACF,CAEA,OAAOE,EAAU,QAAQ,CAE3B,EAAGE,CAAI,CACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../../src/hooks/useUpdate/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { DependencyList, EffectCallback } from 'react';\n\nfunction useUpdate(effect: EffectCallback, deps: DependencyList, applyChanges = true): void {\n const isInitialMount = useRef(true);\n const applyChangesRef = useRef(applyChanges);\n const effectRef = useRef(effect);\n\n applyChangesRef.current = applyChanges;\n effectRef.current = effect;\n\n useEffect(() => {\n if (isInitialMount.current || !applyChangesRef.current) {\n isInitialMount.current = false;\n return;\n }\n\n return effectRef.current();\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- useUpdate forwards caller-owned dependencies.\n }, deps);\n}\n\nexport default useUpdate;\n"],"mappings":"8CAGA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["useUpdate","isInitialMount","useRef","applyChangesRef","applyChanges","effectRef","effect","useEffect","deps"],"sources":["../../../src/hooks/useUpdate/index.ts"],"sourcesContent":["import { useEffect, useRef } from 'react';\nimport type { DependencyList, EffectCallback } from 'react';\n\nfunction useUpdate(effect: EffectCallback, deps: DependencyList, applyChanges = true): void {\n const isInitialMount = useRef(true);\n const applyChangesRef = useRef(applyChanges);\n const effectRef = useRef(effect);\n\n applyChangesRef.current = applyChanges;\n effectRef.current = effect;\n\n useEffect(() => {\n if (isInitialMount.current || !applyChangesRef.current) {\n isInitialMount.current = false;\n return;\n }\n\n return effectRef.current();\n // oxlint-disable-next-line react-hooks/exhaustive-deps -- useUpdate forwards caller-owned dependencies.\n }, deps);\n}\n\nexport default useUpdate;\n"],"mappings":"8CAGA,SAASA,EAAU,EAAwB,EAAsB,EAAe,GAAY,CAC1F,IAAMC,EAAiBC,EAAO,EAAI,EAC5BC,EAAkBD,EAAOE,CAAY,EACrCC,EAAYH,EAAOI,CAAM,EAE/B,EAAgB,QAAUF,EAC1B,EAAU,QAAUE,EAEpBC,MAAgB,CACd,GAAIN,EAAe,SAAW,CAACE,EAAgB,QAAS,CACtD,EAAe,QAAU,GACzB,MACF,CAEA,OAAOE,EAAU,QAAQ,CAE3B,EAAGG,CAAI,CACT"}
|
package/dist/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["Editor"],"sources":["../src/index.ts"],"sourcesContent":["'use client';\n\nimport loader from '@willbooster/monaco-loader';\nexport { loader };\n\nimport DiffEditor from './DiffEditor';\nexport * from './DiffEditor/types';\nexport { DiffEditor };\n\nimport useMonaco from './hooks/useMonaco';\nexport { useMonaco };\n\nimport Editor from './Editor';\nexport * from './Editor/types';\nexport { Editor };\nexport default Editor;\n\n// Monaco\nimport type * as monaco from 'monaco-editor';\nexport type Monaco = typeof monaco;\n\n// Default themes\nexport type Theme = 'vs-dark' | 'light';\n"],"mappings":"uVAeA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["Editor","require_runtime","require_index","require_index$1","require_index$2","_willbooster_monaco_loader","src_default"],"sources":["../src/index.ts"],"sourcesContent":["'use client';\n\nimport loader from '@willbooster/monaco-loader';\nexport { loader };\n\nimport DiffEditor from './DiffEditor';\nexport * from './DiffEditor/types';\nexport { DiffEditor };\n\nimport useMonaco from './hooks/useMonaco';\nexport { useMonaco };\n\nimport Editor from './Editor';\nexport * from './Editor/types';\nexport { Editor };\nexport default Editor;\n\n// Monaco\nimport type * as monaco from 'monaco-editor';\nexport type Monaco = typeof monaco;\n\n// Default themes\nexport type Theme = 'vs-dark' | 'light';\n"],"mappings":"uVAeA,IAAAM,EAAeN,EAAAA"}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":["Editor"],"sources":["../src/index.ts"],"sourcesContent":["'use client';\n\nimport loader from '@willbooster/monaco-loader';\nexport { loader };\n\nimport DiffEditor from './DiffEditor';\nexport * from './DiffEditor/types';\nexport { DiffEditor };\n\nimport useMonaco from './hooks/useMonaco';\nexport { useMonaco };\n\nimport Editor from './Editor';\nexport * from './Editor/types';\nexport { Editor };\nexport default Editor;\n\n// Monaco\nimport type * as monaco from 'monaco-editor';\nexport type Monaco = typeof monaco;\n\n// Default themes\nexport type Theme = 'vs-dark' | 'light';\n"],"mappings":"uKAeA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["Editor","useMonaco","DiffEditor_default","Editor_default","loader","src_default"],"sources":["../src/index.ts"],"sourcesContent":["'use client';\n\nimport loader from '@willbooster/monaco-loader';\nexport { loader };\n\nimport DiffEditor from './DiffEditor';\nexport * from './DiffEditor/types';\nexport { DiffEditor };\n\nimport useMonaco from './hooks/useMonaco';\nexport { useMonaco };\n\nimport Editor from './Editor';\nexport * from './Editor/types';\nexport { Editor };\nexport default Editor;\n\n// Monaco\nimport type * as monaco from 'monaco-editor';\nexport type Monaco = typeof monaco;\n\n// Default themes\nexport type Theme = 'vs-dark' | 'light';\n"],"mappings":"uKAeA,IAAAK,EAAeL"}
|
package/dist/utils/index.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["import type { Monaco } from '..';\nimport type { Uri, editor } from 'monaco-editor';\n\n/**\n * noop is a helper function that does nothing\n * @returns undefined\n */\nfunction noop(): void {\n /** no-op */\n}\n\n/**\n * getOrCreateModel is a helper function that will return a model if it exists\n * or create a new model if it does not exist.\n * This is useful for when you want to create a model for a file that may or may not exist yet.\n * @param monaco The monaco instance\n * @param value The value of the model\n * @param language The language of the model\n * @param path The path of the model\n * @returns The model that was found or created\n */\nfunction getOrCreateModel(monaco: Monaco, value: string, language: string, path: string): editor.ITextModel {\n return getModel(monaco, path) ?? createModel(monaco, value, language, path);\n}\n\n/**\n * getModel is a helper function that will return a model if it exists\n * or return undefined if it does not exist.\n * @param monaco The monaco instance\n * @param path The path of the model\n * @returns The model that was found or undefined\n */\nfunction getModel(monaco: Monaco, path: string): editor.ITextModel | null {\n return monaco.editor.getModel(createModelUri(monaco, path));\n}\n\n/**\n * createModel is a helper function that will create a new model\n * @param monaco The monaco instance\n * @param value The value of the model\n * @param language The language of the model\n * @param path The path of the model\n * @returns The model that was created\n */\nfunction createModel(monaco: Monaco, value: string, language?: string, path?: string): editor.ITextModel {\n return monaco.editor.createModel(value, language, path ? createModelUri(monaco, path) : undefined);\n}\n\n/**\n * createModelUri is a helper function that will create a new model uri\n * @param monaco The monaco instance\n * @param path The path of the model\n * @returns The model uri that was created\n */\nfunction createModelUri(monaco: Monaco, path: string): Uri {\n if (hasUriScheme(path)) {\n return monaco.Uri.parse(path);\n }\n\n const normalizedPath = path.replaceAll('\\\\', '/');\n if (normalizedPath.startsWith('//')) {\n const [authority, ...pathParts] = normalizedPath.slice(2).split('/');\n return monaco.Uri.from({\n scheme: 'file',\n authority,\n path: `/${pathParts.join('/')}`,\n });\n }\n\n return monaco.Uri.from({\n scheme: 'file',\n path: normalizedPath.startsWith('/') ? normalizedPath : `/${normalizedPath}`,\n });\n}\n\nfunction hasUriScheme(path: string): boolean {\n return /^[a-z][a-z0-9+.-]+:/i.test(path);\n}\n\nexport { noop, getOrCreateModel };\n"],"mappings":"aAOA,
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["noop","getOrCreateModel","getModel","monaco","path","createModel","value","language","createModelUri","hasUriScheme","normalizedPath","authority","pathParts"],"sources":["../../src/utils/index.ts"],"sourcesContent":["import type { Monaco } from '..';\nimport type { Uri, editor } from 'monaco-editor';\n\n/**\n * noop is a helper function that does nothing\n * @returns undefined\n */\nfunction noop(): void {\n /** no-op */\n}\n\n/**\n * getOrCreateModel is a helper function that will return a model if it exists\n * or create a new model if it does not exist.\n * This is useful for when you want to create a model for a file that may or may not exist yet.\n * @param monaco The monaco instance\n * @param value The value of the model\n * @param language The language of the model\n * @param path The path of the model\n * @returns The model that was found or created\n */\nfunction getOrCreateModel(monaco: Monaco, value: string, language: string, path: string): editor.ITextModel {\n return getModel(monaco, path) ?? createModel(monaco, value, language, path);\n}\n\n/**\n * getModel is a helper function that will return a model if it exists\n * or return undefined if it does not exist.\n * @param monaco The monaco instance\n * @param path The path of the model\n * @returns The model that was found or undefined\n */\nfunction getModel(monaco: Monaco, path: string): editor.ITextModel | null {\n return monaco.editor.getModel(createModelUri(monaco, path));\n}\n\n/**\n * createModel is a helper function that will create a new model\n * @param monaco The monaco instance\n * @param value The value of the model\n * @param language The language of the model\n * @param path The path of the model\n * @returns The model that was created\n */\nfunction createModel(monaco: Monaco, value: string, language?: string, path?: string): editor.ITextModel {\n return monaco.editor.createModel(value, language, path ? createModelUri(monaco, path) : undefined);\n}\n\n/**\n * createModelUri is a helper function that will create a new model uri\n * @param monaco The monaco instance\n * @param path The path of the model\n * @returns The model uri that was created\n */\nfunction createModelUri(monaco: Monaco, path: string): Uri {\n if (hasUriScheme(path)) {\n return monaco.Uri.parse(path);\n }\n\n const normalizedPath = path.replaceAll('\\\\', '/');\n if (normalizedPath.startsWith('//')) {\n const [authority, ...pathParts] = normalizedPath.slice(2).split('/');\n return monaco.Uri.from({\n scheme: 'file',\n authority,\n path: `/${pathParts.join('/')}`,\n });\n }\n\n return monaco.Uri.from({\n scheme: 'file',\n path: normalizedPath.startsWith('/') ? normalizedPath : `/${normalizedPath}`,\n });\n}\n\nfunction hasUriScheme(path: string): boolean {\n return /^[a-z][a-z0-9+.-]+:/i.test(path);\n}\n\nexport { noop, getOrCreateModel };\n"],"mappings":"aAOA,SAASA,GAAa,CAEtB,CAYA,SAASC,EAAiB,EAAgB,EAAe,EAAkB,EAAiC,CAC1G,OAAOC,EAASC,EAAQC,CAAI,GAAKC,EAAYF,EAAQG,EAAOC,EAAUH,CAAI,CAC5E,CASA,SAASF,EAAS,EAAgB,EAAwC,CACxE,OAAOC,EAAO,OAAO,SAASK,EAAeL,EAAQC,CAAI,CAAC,CAC5D,CAUA,SAASC,EAAY,EAAgB,EAAe,EAAmB,EAAkC,CACvG,OAAOF,EAAO,OAAO,YAAYG,EAAOC,EAAUH,EAAOI,EAAeL,EAAQC,CAAI,EAAI,IAAA,EAAS,CACnG,CAQA,SAASI,EAAe,EAAgB,EAAmB,CACzD,GAAIC,EAAaL,CAAI,EACnB,OAAOD,EAAO,IAAI,MAAMC,CAAI,EAG9B,IAAMM,EAAiBN,EAAK,WAAW,KAAM,GAAG,EAChD,GAAIM,EAAe,WAAW,IAAI,EAAG,CACnC,GAAM,CAACC,EAAW,GAAGC,GAAaF,EAAe,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,EACnE,OAAOP,EAAO,IAAI,KAAK,CACrB,OAAQ,OACR,YACA,KAAM,IAAIS,EAAU,KAAK,GAAG,GAC9B,CAAC,CACH,CAEA,OAAOT,EAAO,IAAI,KAAK,CACrB,OAAQ,OACR,KAAMO,EAAe,WAAW,GAAG,EAAIA,EAAiB,IAAIA,GAC9D,CAAC,CACH,CAEA,SAASD,EAAa,EAAuB,CAC3C,MAAO,uBAAuB,KAAKL,CAAI,CACzC"}
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../../src/utils/index.ts"],"sourcesContent":["import type { Monaco } from '..';\nimport type { Uri, editor } from 'monaco-editor';\n\n/**\n * noop is a helper function that does nothing\n * @returns undefined\n */\nfunction noop(): void {\n /** no-op */\n}\n\n/**\n * getOrCreateModel is a helper function that will return a model if it exists\n * or create a new model if it does not exist.\n * This is useful for when you want to create a model for a file that may or may not exist yet.\n * @param monaco The monaco instance\n * @param value The value of the model\n * @param language The language of the model\n * @param path The path of the model\n * @returns The model that was found or created\n */\nfunction getOrCreateModel(monaco: Monaco, value: string, language: string, path: string): editor.ITextModel {\n return getModel(monaco, path) ?? createModel(monaco, value, language, path);\n}\n\n/**\n * getModel is a helper function that will return a model if it exists\n * or return undefined if it does not exist.\n * @param monaco The monaco instance\n * @param path The path of the model\n * @returns The model that was found or undefined\n */\nfunction getModel(monaco: Monaco, path: string): editor.ITextModel | null {\n return monaco.editor.getModel(createModelUri(monaco, path));\n}\n\n/**\n * createModel is a helper function that will create a new model\n * @param monaco The monaco instance\n * @param value The value of the model\n * @param language The language of the model\n * @param path The path of the model\n * @returns The model that was created\n */\nfunction createModel(monaco: Monaco, value: string, language?: string, path?: string): editor.ITextModel {\n return monaco.editor.createModel(value, language, path ? createModelUri(monaco, path) : undefined);\n}\n\n/**\n * createModelUri is a helper function that will create a new model uri\n * @param monaco The monaco instance\n * @param path The path of the model\n * @returns The model uri that was created\n */\nfunction createModelUri(monaco: Monaco, path: string): Uri {\n if (hasUriScheme(path)) {\n return monaco.Uri.parse(path);\n }\n\n const normalizedPath = path.replaceAll('\\\\', '/');\n if (normalizedPath.startsWith('//')) {\n const [authority, ...pathParts] = normalizedPath.slice(2).split('/');\n return monaco.Uri.from({\n scheme: 'file',\n authority,\n path: `/${pathParts.join('/')}`,\n });\n }\n\n return monaco.Uri.from({\n scheme: 'file',\n path: normalizedPath.startsWith('/') ? normalizedPath : `/${normalizedPath}`,\n });\n}\n\nfunction hasUriScheme(path: string): boolean {\n return /^[a-z][a-z0-9+.-]+:/i.test(path);\n}\n\nexport { noop, getOrCreateModel };\n"],"mappings":"AAOA,
|
|
1
|
+
{"version":3,"file":"index.js","names":["noop","getOrCreateModel","getModel","monaco","path","createModel","value","language","createModelUri","hasUriScheme","normalizedPath","authority","pathParts"],"sources":["../../src/utils/index.ts"],"sourcesContent":["import type { Monaco } from '..';\nimport type { Uri, editor } from 'monaco-editor';\n\n/**\n * noop is a helper function that does nothing\n * @returns undefined\n */\nfunction noop(): void {\n /** no-op */\n}\n\n/**\n * getOrCreateModel is a helper function that will return a model if it exists\n * or create a new model if it does not exist.\n * This is useful for when you want to create a model for a file that may or may not exist yet.\n * @param monaco The monaco instance\n * @param value The value of the model\n * @param language The language of the model\n * @param path The path of the model\n * @returns The model that was found or created\n */\nfunction getOrCreateModel(monaco: Monaco, value: string, language: string, path: string): editor.ITextModel {\n return getModel(monaco, path) ?? createModel(monaco, value, language, path);\n}\n\n/**\n * getModel is a helper function that will return a model if it exists\n * or return undefined if it does not exist.\n * @param monaco The monaco instance\n * @param path The path of the model\n * @returns The model that was found or undefined\n */\nfunction getModel(monaco: Monaco, path: string): editor.ITextModel | null {\n return monaco.editor.getModel(createModelUri(monaco, path));\n}\n\n/**\n * createModel is a helper function that will create a new model\n * @param monaco The monaco instance\n * @param value The value of the model\n * @param language The language of the model\n * @param path The path of the model\n * @returns The model that was created\n */\nfunction createModel(monaco: Monaco, value: string, language?: string, path?: string): editor.ITextModel {\n return monaco.editor.createModel(value, language, path ? createModelUri(monaco, path) : undefined);\n}\n\n/**\n * createModelUri is a helper function that will create a new model uri\n * @param monaco The monaco instance\n * @param path The path of the model\n * @returns The model uri that was created\n */\nfunction createModelUri(monaco: Monaco, path: string): Uri {\n if (hasUriScheme(path)) {\n return monaco.Uri.parse(path);\n }\n\n const normalizedPath = path.replaceAll('\\\\', '/');\n if (normalizedPath.startsWith('//')) {\n const [authority, ...pathParts] = normalizedPath.slice(2).split('/');\n return monaco.Uri.from({\n scheme: 'file',\n authority,\n path: `/${pathParts.join('/')}`,\n });\n }\n\n return monaco.Uri.from({\n scheme: 'file',\n path: normalizedPath.startsWith('/') ? normalizedPath : `/${normalizedPath}`,\n });\n}\n\nfunction hasUriScheme(path: string): boolean {\n return /^[a-z][a-z0-9+.-]+:/i.test(path);\n}\n\nexport { noop, getOrCreateModel };\n"],"mappings":"AAOA,SAASA,GAAa,CAEtB,CAYA,SAASC,EAAiB,EAAgB,EAAe,EAAkB,EAAiC,CAC1G,OAAOC,EAASC,EAAQC,CAAI,GAAKC,EAAYF,EAAQG,EAAOC,EAAUH,CAAI,CAC5E,CASA,SAASF,EAAS,EAAgB,EAAwC,CACxE,OAAOC,EAAO,OAAO,SAASK,EAAeL,EAAQC,CAAI,CAAC,CAC5D,CAUA,SAASC,EAAY,EAAgB,EAAe,EAAmB,EAAkC,CACvG,OAAOF,EAAO,OAAO,YAAYG,EAAOC,EAAUH,EAAOI,EAAeL,EAAQC,CAAI,EAAI,IAAA,EAAS,CACnG,CAQA,SAASI,EAAe,EAAgB,EAAmB,CACzD,GAAIC,EAAaL,CAAI,EACnB,OAAOD,EAAO,IAAI,MAAMC,CAAI,EAG9B,IAAMM,EAAiBN,EAAK,WAAW,KAAM,GAAG,EAChD,GAAIM,EAAe,WAAW,IAAI,EAAG,CACnC,GAAM,CAACC,EAAW,GAAGC,GAAaF,EAAe,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,EACnE,OAAOP,EAAO,IAAI,KAAK,CACrB,OAAQ,OACR,YACA,KAAM,IAAIS,EAAU,KAAK,GAAG,GAC9B,CAAC,CACH,CAEA,OAAOT,EAAO,IAAI,KAAK,CACrB,OAAQ,OACR,KAAMO,EAAe,WAAW,GAAG,EAAIA,EAAiB,IAAIA,GAC9D,CAAC,CACH,CAEA,SAASD,EAAa,EAAuB,CAC3C,MAAO,uBAAuB,KAAKL,CAAI,CACzC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@willbooster/monaco-react",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"description": "Monaco Editor for React - use the monaco-editor in any React application without needing to use webpack (or rollup/parcel/etc) configuration files / plugins",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"code",
|
|
@@ -42,8 +42,9 @@
|
|
|
42
42
|
"format": "bun wb lint --format",
|
|
43
43
|
"lint": "bun wb lint",
|
|
44
44
|
"lint-fix": "bun wb lint --fix",
|
|
45
|
-
"prepare": "lefthook install || true",
|
|
45
|
+
"prepare": "(bun lefthook install || true) && (test ! -f .lefthook/normalize-bun-lockfile.sh || bash .lefthook/normalize-bun-lockfile.sh)",
|
|
46
46
|
"test": "bun wb test",
|
|
47
|
+
"test/ci": "bun wb test-on-ci",
|
|
47
48
|
"test/ci-setup": "playwright install chromium",
|
|
48
49
|
"typecheck": "bun wb typecheck",
|
|
49
50
|
"verify": "bun wb verify",
|
|
@@ -61,21 +62,21 @@
|
|
|
61
62
|
"@tsconfig/bun": "1.0.10",
|
|
62
63
|
"@tsconfig/node-lts": "24.0.0",
|
|
63
64
|
"@tsconfig/node-ts": "23.6.4",
|
|
64
|
-
"@types/bun": "1.
|
|
65
|
+
"@types/bun": "1.4.2",
|
|
65
66
|
"@types/node": "25.6.0",
|
|
66
67
|
"@types/react": "19.2.14",
|
|
67
68
|
"@types/react-dom": "19.2.3",
|
|
68
69
|
"@willbooster/oxfmt-config": "1.2.2",
|
|
69
70
|
"@willbooster/oxlint-config": "1.4.8",
|
|
70
|
-
"@willbooster/wb": "
|
|
71
|
-
"build-ts": "
|
|
71
|
+
"@willbooster/wb": "22.26.1",
|
|
72
|
+
"build-ts": "21.0.25",
|
|
72
73
|
"conventional-changelog-conventionalcommits": "9.3.1",
|
|
73
74
|
"jsdom": "29.0.2",
|
|
74
|
-
"lefthook": "2.1
|
|
75
|
-
"next": "16.
|
|
76
|
-
"oxfmt": "0.
|
|
77
|
-
"oxlint": "1.
|
|
78
|
-
"oxlint-tsgolint": "7.0.
|
|
75
|
+
"lefthook": "2.2.1",
|
|
76
|
+
"next": "16.4.1",
|
|
77
|
+
"oxfmt": "0.72.0",
|
|
78
|
+
"oxlint": "1.87.0",
|
|
79
|
+
"oxlint-tsgolint": "7.0.2003",
|
|
79
80
|
"react": "19.2.5",
|
|
80
81
|
"react-dom": "19.2.5",
|
|
81
82
|
"semantic-release": "25.0.3",
|
|
@@ -91,6 +92,7 @@
|
|
|
91
92
|
"node": ">=24"
|
|
92
93
|
},
|
|
93
94
|
"publishConfig": {
|
|
94
|
-
"access": "public"
|
|
95
|
+
"access": "public",
|
|
96
|
+
"registry": "https://registry.npmjs.org/"
|
|
95
97
|
}
|
|
96
98
|
}
|