mirror of
https://github.com/casdoor/casdoor.git
synced 2025-07-03 20:50:19 +08:00
feat: improve the advanced editor of model edit page (#3427)
This commit is contained in:
@ -26,11 +26,13 @@ const IframeEditor = forwardRef(({initialModelText, onModelTextChange}, ref) =>
|
|||||||
onModelTextChange(event.data.modelText);
|
onModelTextChange(event.data.modelText);
|
||||||
} else if (event.data.type === "iframeReady") {
|
} else if (event.data.type === "iframeReady") {
|
||||||
setIframeReady(true);
|
setIframeReady(true);
|
||||||
iframeRef.current?.contentWindow.postMessage({
|
if (initialModelText && iframeRef.current?.contentWindow) {
|
||||||
|
iframeRef.current.contentWindow.postMessage({
|
||||||
type: "initializeModel",
|
type: "initializeModel",
|
||||||
modelText: initialModelText,
|
modelText: initialModelText,
|
||||||
}, "*");
|
}, "*");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
window.addEventListener("message", handleMessage);
|
window.addEventListener("message", handleMessage);
|
||||||
@ -39,11 +41,15 @@ const IframeEditor = forwardRef(({initialModelText, onModelTextChange}, ref) =>
|
|||||||
|
|
||||||
useImperativeHandle(ref, () => ({
|
useImperativeHandle(ref, () => ({
|
||||||
getModelText: () => {
|
getModelText: () => {
|
||||||
iframeRef.current?.contentWindow.postMessage({type: "getModelText"}, "*");
|
if (iframeRef.current?.contentWindow) {
|
||||||
|
iframeRef.current.contentWindow.postMessage({
|
||||||
|
type: "getModelText",
|
||||||
|
}, "*");
|
||||||
|
}
|
||||||
},
|
},
|
||||||
updateModelText: (newModelText) => {
|
updateModelText: (newModelText) => {
|
||||||
if (iframeReady) {
|
if (iframeReady && iframeRef.current?.contentWindow) {
|
||||||
iframeRef.current?.contentWindow.postMessage({
|
iframeRef.current.contentWindow.postMessage({
|
||||||
type: "updateModelText",
|
type: "updateModelText",
|
||||||
modelText: newModelText,
|
modelText: newModelText,
|
||||||
}, "*");
|
}, "*");
|
||||||
|
Reference in New Issue
Block a user