diff --git a/app/srv/ws/sync/actions.ts b/app/srv/ws/sync/actions.ts index cb143f1d..cdcb21b1 100644 --- a/app/srv/ws/sync/actions.ts +++ b/app/srv/ws/sync/actions.ts @@ -106,12 +106,20 @@ export const SyncActions = { value: Uint8Array; } | { - type: "prop"; + type: "prop-master"; comp_id: string; prop_name: string; prop_kind: PropFieldKind; value: Uint8Array; } + | { + type: "prop-instance"; + item_id: string; + page_id?: string; + comp_id?: string; + prop_name: string; + value: Uint8Array; + } ) => ({}) as boolean | ParsedScope, parse: async (code: string | Record) => ({}) as Record>, diff --git a/app/srv/ws/sync/actions/code_edit.ts b/app/srv/ws/sync/actions/code_edit.ts index 1390b5b7..521762ff 100644 --- a/app/srv/ws/sync/actions/code_edit.ts +++ b/app/srv/ws/sync/actions/code_edit.ts @@ -17,8 +17,8 @@ export const code_edit: SAction["code"]["edit"] = async function ( ) { const src = decoder.decode(await gunzipAsync(arg.value)); - if (arg.type === "adv") { - const { item_id, mode, comp_id, page_id } = arg; + if (arg.type === "adv" || arg.type === "prop-instance") { + const { item_id, comp_id, page_id } = arg; let root = undefined as undefined | MRoot | MItem; let doc = undefined as undefined | Doc; @@ -38,43 +38,64 @@ export const code_edit: SAction["code"]["edit"] = async function ( if (root) { const mitem = findId(root, item_id); - if (mitem) { - let adv = mitem.get("adv"); - if (!adv) { - mitem.set("adv", new Y.Map() as any); - adv = mitem.get("adv"); - } - - if (adv) { - try { - const res = await transform(`render(${src})`, { - jsx: "transform", - format: "cjs", - loader: "tsx", - minify: true, - sourcemap: "inline", - }); - - doc?.transact(() => { - if (adv) { - adv.set(mode, src); - if (mode === "js") { - adv.set("jsBuilt", res.code); - } - } - }); - } catch (e) { - g.log.error(e); + if (arg.type === "adv") { + const mode = arg.mode; + let adv = mitem.get("adv"); + if (!adv) { + mitem.set("adv", new Y.Map() as any); + adv = mitem.get("adv"); } - if (mode === "js") { - return parseJs(adv.get("js")) || false; + if (adv) { + try { + const res = await transform(`render(${src})`, { + jsx: "transform", + format: "cjs", + loader: "tsx", + minify: true, + sourcemap: "inline", + }); + + doc?.transact(() => { + if (adv) { + adv.set(mode, src); + if (mode === "js") { + adv.set("jsBuilt", res.code); + } + } + }); + } catch (e) { + g.log.error(e); + } + + if (mode === "js") { + return parseJs(adv.get("js")) || false; + } + } + } else { + const mprop = mitem + .get("component") + ?.get("props") + ?.get(arg.prop_name); + if (mprop) { + try { + const res = await transform(`return ${src}`, { + jsx: "transform", + format: "cjs", + loader: "tsx", + }); + + doc?.transact(() => { + mprop.set("value", src); + mprop.set("valueBuilt", res.code.substring(6)); + }); + } catch (e) {} } } } } - } else { + } else if (arg.type === "prop-master") { const { comp_id, prop_kind, prop_name } = arg; if (comp_id) { const ref = docs.comp[comp_id]; 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 45678327..7ffb88bf 100644 --- a/app/web/src/nova/ed/panel/popup/script/monaco.tsx +++ b/app/web/src/nova/ed/panel/popup/script/monaco.tsx @@ -209,6 +209,15 @@ export const EdScriptMonaco: FC<{}> = () => { value: compress(encode.encode(val || "")), ...arg, }); + } else if (p.ui.popup.script.type === "prop-instance") { + scope = await p.sync.code.edit({ + type: "adv", + mode: type, + prop_name: p.ui.popup.script.prop_name, + item_id: active.item_id, + value: compress(encode.encode(val || "")), + ...arg, + }); } else { scope = await p.sync.code.edit({ type: "adv",