This commit is contained in:
Rizky 2023-12-21 17:04:54 +07:00
parent 44759a8fb1
commit 7c8d772d3f
3 changed files with 71 additions and 33 deletions

View File

@ -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<string, string>) =>
({}) as Record<string, ReturnType<typeof parseJs>>,

View File

@ -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];

View File

@ -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",