From 742d40f1d5529c82e0bb75720450636265f505b9 Mon Sep 17 00:00:00 2001 From: Rizky Date: Fri, 29 Dec 2023 17:02:18 +0700 Subject: [PATCH] wip fix --- app/srv/ws/sync/actions/code_edit.ts | 31 +++++++++++++++---- app/web/src/nova/ed/logic/ed-global.ts | 1 + .../src/nova/ed/panel/popup/script/monaco.tsx | 12 +++++-- .../nova/ed/panel/popup/script/pop-script.tsx | 2 ++ 4 files changed, 38 insertions(+), 8 deletions(-) diff --git a/app/srv/ws/sync/actions/code_edit.ts b/app/srv/ws/sync/actions/code_edit.ts index 5cdf0b84..2a80f33e 100644 --- a/app/srv/ws/sync/actions/code_edit.ts +++ b/app/srv/ws/sync/actions/code_edit.ts @@ -145,20 +145,39 @@ export const code_edit: SAction["code"]["edit"] = async function ( }; const findId = (mitem: MContent | MRoot, id: string) => { - if ((mitem as MItem).get("id") === id) { - return mitem as MItem; + let found: null | MItem = null; + + const m = mitem as MItem; + if (m.get("id") === id) { + return m; } - const childs = (mitem as MItem).get("childs"); + const childs = m.get("childs"); if (childs) { - let found: null | MItem = null; childs.forEach((child) => { const f = findId(child, id); if (f) { found = f; } }); - - if (found) return found; } + + if (!found) { + const mprops = m.get("component")?.get("props"); + if (mprops) { + mprops.forEach((mprop) => { + if (mprop.get("meta")?.get("type") === "content-element") { + const mcontent = mprop.get("content"); + if (mcontent) { + const f = findId(mcontent, id); + if (f) { + found = f; + } + } + } + }); + } + } + + if (found) return found; }; diff --git a/app/web/src/nova/ed/logic/ed-global.ts b/app/web/src/nova/ed/logic/ed-global.ts index 44eb1662..8464c91d 100644 --- a/app/web/src/nova/ed/logic/ed-global.ts +++ b/app/web/src/nova/ed/logic/ed-global.ts @@ -214,6 +214,7 @@ export const EDGlobal = { type: "item" as "item" | "prop-master" | "prop-instance", prop_kind: "" as PropFieldKind, prop_name: "", + on_close: () => {}, }, site: null as null | ((site_id: string) => void | Promise), site_form: null as null | { diff --git a/app/web/src/nova/ed/panel/popup/script/monaco.tsx b/app/web/src/nova/ed/panel/popup/script/monaco.tsx index 7d521ae7..d7bf4b90 100644 --- a/app/web/src/nova/ed/panel/popup/script/monaco.tsx +++ b/app/web/src/nova/ed/panel/popup/script/monaco.tsx @@ -189,7 +189,8 @@ export const EdScriptMonaco: FC<{}> = () => { local.value = val || ""; local.render(); clearTimeout(scriptEdit.timeout); - scriptEdit.timeout = setTimeout(async () => { + + const applyChanges = async () => { const meta = getActiveMeta(p); const type = p.ui.popup.script.mode; if (meta && meta.mitem) { @@ -232,7 +233,14 @@ export const EdScriptMonaco: FC<{}> = () => { meta.item.script = scope; } } - }, 1000); + }; + + p.ui.popup.script.on_close = () => { + clearTimeout(scriptEdit.timeout); + applyChanges(); + p.ui.popup.script.on_close = () => {}; + }; + scriptEdit.timeout = setTimeout(applyChanges, 1000); }} onMount={async (editor, monaco) => { local.monaco = monaco; diff --git a/app/web/src/nova/ed/panel/popup/script/pop-script.tsx b/app/web/src/nova/ed/panel/popup/script/pop-script.tsx index 5561a356..8ff16ac2 100644 --- a/app/web/src/nova/ed/panel/popup/script/pop-script.tsx +++ b/app/web/src/nova/ed/panel/popup/script/pop-script.tsx @@ -26,6 +26,8 @@ export const EdPopScript = () => { delete p.script.init_local_effect[active.item_id]; } + script.on_close(); + p.render(); } }