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 (
}
}
}
});
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(),
},
});
}
}, "server");
} catch (e: any) {
return e.message.toString();
}
@ -125,22 +109,6 @@ export const code_edit: SAction["code"]["edit"] = async function (
mprop.set("value", src);
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) {
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) {
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";
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.render();
if (should_render !== false) p.render();
};
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;
p.ui.popup.script.typings.status = "loading";
p.ui.popup.script.wb_render();
if ((value || "").includes(IMPORT_SEPARATOR)) {
const valparts = (value || "").split(IMPORT_SEPARATOR + "\n");
if (valparts.length === 2) local.value = valparts[1];
const valparts = (value || "").split(IMPORT_SEPARATOR);
if (valparts.length > 1) local.value = valparts[1];
if (
stype === "prop-instance" &&
local.value.includes(
@ -361,6 +362,7 @@ export const EdScriptMonaco: FC<{}> = () => {
scope = code_result;
}
} else {
console.log(value);
const code_result = await p.sync.code.edit({
type: "adv",
mode: mode,

View File

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

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 };
}
}
if (is_changed) {
}
}
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) => {
for (const [k, v] of Object.entries(arg)) {
if (k === "key" || k === "idx" || k === "continue") continue;
}
let prop: any = {};
if (Array.isArray(arg)) {
prop.children = arg;
@ -41,15 +34,15 @@ export const modifyChild = (arg: any, passprop?: any) => {
prop = arg;
}
const childs = [];
if (Array.isArray(prop.children)) {
const childs = [];
for (const child of prop.children) {
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) => {