This commit is contained in:
Rizky 2024-01-28 06:46:53 +07:00
parent c5825c89c4
commit ddab876d8c
5 changed files with 40 additions and 77 deletions

View File

@ -87,23 +87,7 @@ export const code_edit: SAction["code"]["edit"] = async function (
} }
} }
} }
}); }, "server");
if (save_to === "comp" && comp_id) {
db.component.update({
where: { id: comp_id },
data: {
content_tree: root.toJSON(),
},
});
} else if (page_id) {
db.page.update({
where: { id: page_id },
data: {
content_tree: root.toJSON(),
},
});
}
} catch (e: any) { } catch (e: any) {
return e.message.toString(); return e.message.toString();
} }
@ -125,22 +109,6 @@ export const code_edit: SAction["code"]["edit"] = async function (
mprop.set("value", src); mprop.set("value", src);
mprop.set("valueBuilt", res.code.substring(6)); mprop.set("valueBuilt", res.code.substring(6));
}); });
if (save_to === "comp" && comp_id) {
db.component.update({
where: { id: comp_id },
data: {
content_tree: root.toJSON(),
},
});
} else if (page_id) {
db.page.update({
where: { id: page_id },
data: {
content_tree: root.toJSON(),
},
});
}
} catch (e: any) { } catch (e: any) {
return e.message.toString(); return e.message.toString();
} }
@ -183,12 +151,6 @@ export const code_edit: SAction["code"]["edit"] = async function (
} }
} }
}); });
await db.component.update({
where: { id: comp_id },
data: {
content_tree: root.toJSON(),
},
});
} catch (e: any) { } catch (e: any) {
return e.message.toString(); return e.message.toString();
} }

View File

@ -129,7 +129,12 @@ export const reloadLayout = async (p: PG, layout_id: string, note: string) => {
} }
}; };
export const reloadPage = async (p: PG, page_id: string, note: string) => { export const reloadPage = async (
p: PG,
page_id: string,
note: string,
should_render?: boolean
) => {
p.status = "reload"; p.status = "reload";
const remotePage = await p.sync.page.load(page_id); const remotePage = await p.sync.page.load(page_id);
@ -219,7 +224,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => {
} }
p.status = "ready"; p.status = "ready";
p.render(); if (should_render !== false) p.render();
}; };
export const loadPageMetaCache = async (p: PG, page_id: string) => { export const loadPageMetaCache = async (p: PG, page_id: string) => {

View File

@ -305,9 +305,10 @@ export const EdScriptMonaco: FC<{}> = () => {
const stype = p.ui.popup.script.type; const stype = p.ui.popup.script.type;
p.ui.popup.script.typings.status = "loading"; p.ui.popup.script.typings.status = "loading";
p.ui.popup.script.wb_render(); p.ui.popup.script.wb_render();
if ((value || "").includes(IMPORT_SEPARATOR)) { if ((value || "").includes(IMPORT_SEPARATOR)) {
const valparts = (value || "").split(IMPORT_SEPARATOR + "\n"); const valparts = (value || "").split(IMPORT_SEPARATOR);
if (valparts.length === 2) local.value = valparts[1]; if (valparts.length > 1) local.value = valparts[1];
if ( if (
stype === "prop-instance" && stype === "prop-instance" &&
local.value.includes( local.value.includes(
@ -361,6 +362,7 @@ export const EdScriptMonaco: FC<{}> = () => {
scope = code_result; scope = code_result;
} }
} else { } else {
console.log(value);
const code_result = await p.sync.code.edit({ const code_result = await p.sync.code.edit({
type: "adv", type: "adv",
mode: mode, mode: mode,

View File

@ -79,15 +79,11 @@ export const ViPreview = (arg: { pathname: string }) => {
const mode = p.mode; const mode = p.mode;
if (!w.isEditor && !p.preview.meta_cache[params.page_id]) {
savePageMetaCache(p, p.page.meta);
}
return ( return (
<div className={cx("relative flex flex-1 items-center justify-center")}> <div className={cx("relative flex flex-1 items-center justify-center")}>
<div <div
className={cx( className={cx(
"absolute flex flex-col items-stretch flex-1 bg-white ", "absolute flex flex-col items-stretch flex-1 bg-white main-content-preview",
mode === "mobile" mode === "mobile"
? css` ? css`
@media (min-width: 768px) { @media (min-width: 768px) {
@ -148,7 +144,6 @@ export const ViPreview = (arg: { pathname: string }) => {
if (load_urls.length > 0) { if (load_urls.length > 0) {
const res = await p.sync.page.cache(p.site.id, load_urls, [ const res = await p.sync.page.cache(p.site.id, load_urls, [
...Object.keys(p.preview.page_cache), ...Object.keys(p.preview.page_cache),
p.page.cur.id,
]); ]);
if (res) { if (res) {
@ -172,6 +167,10 @@ export const ViPreview = (arg: { pathname: string }) => {
); );
}; };
const preview = {
first_render: true,
};
const viRoute = async (p: PG) => { const viRoute = async (p: PG) => {
if (p.status === "ready" || p.status === "init") { if (p.status === "ready" || p.status === "init") {
if (p.status === "init") { if (p.status === "init") {
@ -216,17 +215,18 @@ const viRoute = async (p: PG) => {
p.script.init_local_effect = {}; p.script.init_local_effect = {};
if (!w.isEditor && p.page.cur.id !== params.page_id) { if (!w.isEditor) {
if (preview.first_render) {
preview.first_render = false;
} else {
let page_cache = p.preview.meta_cache[params.page_id]; let page_cache = p.preview.meta_cache[params.page_id];
let should_render = false;
if (!page_cache) { if (!page_cache) {
const idb_cache = await get(`page-${params.page_id}`, nav.store); const idb_cache = await get(`page-${params.page_id}`, nav.store);
if (idb_cache) { if (idb_cache) {
page_cache = idb_cache; page_cache = idb_cache;
p.preview.meta_cache[params.page_id] = idb_cache; p.preview.meta_cache[params.page_id] = idb_cache;
} }
should_render = true;
} }
if (page_cache) { if (page_cache) {
@ -237,7 +237,8 @@ const viRoute = async (p: PG) => {
p.page.cur = { id: params.page_id } as any; p.page.cur = { id: params.page_id } as any;
} }
p.status = "ready"; p.status = "ready";
if (should_render) p.render(); return;
}
} }
} }

View File

@ -20,9 +20,6 @@ export const createViPassProp = (vi: { meta: VG["meta"] }, meta: IMeta) => {
meta.item.script.passprop[k] = { end: 0, start: 0, value: v }; meta.item.script.passprop[k] = { end: 0, start: 0, value: v };
} }
} }
if (is_changed) {
}
} }
return modifyChild(arg, meta.script?.scope); return modifyChild(arg, meta.script?.scope);
@ -30,10 +27,6 @@ export const createViPassProp = (vi: { meta: VG["meta"] }, meta: IMeta) => {
}; };
export const modifyChild = (arg: any, passprop?: any) => { export const modifyChild = (arg: any, passprop?: any) => {
for (const [k, v] of Object.entries(arg)) {
if (k === "key" || k === "idx" || k === "continue") continue;
}
let prop: any = {}; let prop: any = {};
if (Array.isArray(arg)) { if (Array.isArray(arg)) {
prop.children = arg; prop.children = arg;
@ -41,15 +34,15 @@ export const modifyChild = (arg: any, passprop?: any) => {
prop = arg; prop = arg;
} }
const childs = [];
if (Array.isArray(prop.children)) { if (Array.isArray(prop.children)) {
const childs = [];
for (const child of prop.children) { for (const child of prop.children) {
childs.push(modify(child, prop, passprop)); childs.push(modify(child, prop, passprop));
} }
} else {
childs.push(modify(prop.children, prop, passprop));
}
return childs; return childs;
}
return modify(prop.children, prop, passprop);
}; };
const modify = (el: ReactNode, arg: any, passprop?: any) => { const modify = (el: ReactNode, arg: any, passprop?: any) => {