feat: improve the advanced editor of model edit page (#3427)

This commit is contained in:
Coki
2024-12-15 02:07:02 +08:00
committed by GitHub
parent 0cf281cac0
commit e3a43d0062

View File

@ -26,10 +26,12 @@ const IframeEditor = forwardRef(({initialModelText, onModelTextChange}, ref) =>
onModelTextChange(event.data.modelText);
} else if (event.data.type === "iframeReady") {
setIframeReady(true);
iframeRef.current?.contentWindow.postMessage({
type: "initializeModel",
modelText: initialModelText,
}, "*");
if (initialModelText && iframeRef.current?.contentWindow) {
iframeRef.current.contentWindow.postMessage({
type: "initializeModel",
modelText: initialModelText,
}, "*");
}
}
};
@ -39,11 +41,15 @@ const IframeEditor = forwardRef(({initialModelText, onModelTextChange}, ref) =>
useImperativeHandle(ref, () => ({
getModelText: () => {
iframeRef.current?.contentWindow.postMessage({type: "getModelText"}, "*");
if (iframeRef.current?.contentWindow) {
iframeRef.current.contentWindow.postMessage({
type: "getModelText",
}, "*");
}
},
updateModelText: (newModelText) => {
if (iframeReady) {
iframeRef.current?.contentWindow.postMessage({
if (iframeReady && iframeRef.current?.contentWindow) {
iframeRef.current.contentWindow.postMessage({
type: "updateModelText",
modelText: newModelText,
}, "*");