This commit is contained in:
Rizky 2024-06-05 08:59:49 +07:00
parent ff1f2e2062
commit 0f520d14c4
5 changed files with 29 additions and 17 deletions

View File

@ -89,7 +89,7 @@ export const snapshot = {
async update(data: DocSnapshot) {
const id = `${data.type}-${data.id}`;
this, _db[id] = data;
this._db[id] = data;
return true;
},

View File

@ -140,6 +140,7 @@ export const reloadPage = async (
p.status = "reload";
const remotePage = await p.sync.page.load(page_id);
console.log(remotePage)
if (!remotePage) {
p.status = "page-not-found";
p.render();

View File

@ -50,9 +50,8 @@ export const Root = () => {
base.route.pages = pages;
const basepath = w._prasi.basepath;
let url = `${
basepath.endsWith("/") ? basepath : `${basepath}/`
}_prasi/code/index.js`;
let url = `${basepath.endsWith("/") ? basepath : `${basepath}/`
}_prasi/code/index.js`;
const cur = new URL(location.href);
if (url.startsWith("/")) {
@ -224,19 +223,19 @@ export const Root = () => {
await setkv(`comp-${id}`, item);
}
} catch (e) {}
} catch (e) { }
return comp.list[comp_id];
}}
layout={
base.layout.id && base.layout.root && base.layout.meta
? {
id: base.layout.id,
meta: base.layout.meta,
entry: Object.values(base.layout.root.childs)
.filter((e) => e)
.map((e) => e.id),
}
id: base.layout.id,
meta: base.layout.meta,
entry: Object.values(base.layout.root.childs)
.filter((e) => e)
.map((e) => e.id),
}
: undefined
}
script={{ init_local_effect: base.init_local_effect }}

View File

@ -1,7 +1,7 @@
import { get } from "idb-keyval";
import parseUA from "ua-parser-js";
import init, { decompress } from "wasm-gzip";
import { useGlobal } from "web-utils";
import { deepClone, useGlobal } from "web-utils";
import { w } from "../../utils/types/general";
import { IRoot } from "../../utils/types/root";
import { DeadEnd } from "../../utils/ui/deadend";
@ -16,6 +16,7 @@ import { loadSite } from "../ed/logic/ed-site";
import { treeCacheBuild } from "../ed/logic/tree/build";
import { nav } from "./render/script/extract-nav";
import { Vi } from "./vi";
import { loadComponent } from "../ed/logic/comp/load";
const decoder = new TextDecoder();
export const ViPreview = (arg: { pathname: string }) => {
@ -123,13 +124,24 @@ export const ViPreview = (arg: { pathname: string }) => {
entry={p.page.entry}
api={p.script.api}
db={p.script.db}
comp_load={async (comp_id) => {
let comp = p.comp.loaded[comp_id];
if (comp) {
return comp;
}
await loadComponent(p, comp_id);
comp = p.comp.loaded[comp_id];
return deepClone(comp);
}}
layout={
p.site.layout.id && p.site.layout.meta
? {
id: p.site.layout.id,
meta: p.site.layout.meta,
entry: p.site.layout.entry,
}
id: p.site.layout.id,
meta: p.site.layout.meta,
entry: p.site.layout.entry,
}
: undefined
}
render_stat="disabled"