fix blank

This commit is contained in:
Rizky 2023-10-18 13:59:07 +07:00
parent 297cd61228
commit 7b5b9bb9a0
3 changed files with 55 additions and 31 deletions

View File

@ -16,36 +16,44 @@ const start = async () => {
w.api = createAPI(base);
w.db = createDB(base);
navigator.serviceWorker.addEventListener("message", (e) => {
if (e.data.type === "activated") {
if (e.data.shouldRefresh && sw) {
sw.unregister().then(() => {
window.location.reload();
});
if (!["localhost", "127.0.0.1"].includes(location.hostname)) {
navigator.serviceWorker.addEventListener("message", (e) => {
if (e.data.type === "activated") {
if (e.data.shouldRefresh && sw) {
sw.unregister().then(() => {
window.location.reload();
});
}
}
}
if (e.data.type === "ready") {
const sw = navigator.serviceWorker.controller;
if (e.data.type === "ready") {
const sw = navigator.serviceWorker.controller;
if (sw) {
const routes = Object.entries(w.prasiApi[base].apiEntry).map(
([k, v]: any) => ({
url: v.url,
name: k,
})
);
if (sw) {
const routes = Object.entries(w.prasiApi[base].apiEntry).map(
([k, v]: any) => ({
url: v.url,
name: k,
})
);
sw.postMessage({
type: "add-cache",
url: location.href,
});
sw.postMessage({
type: "define-route",
routes,
});
sw.postMessage({
type: "add-cache",
url: location.href,
});
sw.postMessage({
type: "define-route",
routes,
});
}
}
}
});
});
} else {
navigator.serviceWorker.getRegistrations().then(function (registrations) {
for (let registration of registrations) {
registration.unregister();
}
});
}
const el = document.getElementById("root");
if (el) {

View File

@ -17,6 +17,7 @@ import { fillID } from "../tools/fill-id";
import { newMap } from "../tools/yjs-tools";
import { ComponentOver, ElProp, createElProp } from "./e-relprop";
import { ETextInternal } from "./e-text";
import { DefaultScript } from "../panel/script/monaco/monaco-el";
export const ERender: FC<{
id: string;
@ -174,7 +175,14 @@ export const ERender: FC<{
}
}
if (adv && adv.js && !adv.jsBuilt && meta.mitem) {
if (
adv &&
adv.js &&
typeof adv.js === "string" &&
adv.js.replace(/\W/gi, "") !== DefaultScript.js.replace(/\W/gi, "") &&
!adv.jsBuilt &&
meta.mitem
) {
if (!jscript.build) {
jscript.init().then(() => {
p.render();
@ -188,12 +196,22 @@ export const ERender: FC<{
undefined,
true
)
.then((js) => {});
.then((js) => {
console.log(js);
if (meta.mitem) {
const adv = meta.mitem.get("adv");
if (adv) adv.set("jsBuilt", js);
if (item.adv) {
item.adv.jsBuilt = js;
}
p.render();
}
});
return null;
}
if (!(adv?.jsBuilt && adv?.js) && (meta.scopeAttached || meta.comp)) {
if (!(adv?.jsBuilt && adv?.js) && meta.comp) {
return treeScopeEval(
p,
id,
@ -242,7 +260,6 @@ export const ERender: FC<{
<div className={className} {...elprop}>
{/* <pre className={"text-[9px] font-mono text-black"}>
{item.id}-{item.name}
{item.name === "coba" && JSON.stringify(item.childs)}
</pre> */}
{_children}
{componentOver}

View File

@ -20,7 +20,6 @@ export type ItemMeta = {
parent_comp?: WithRequired<ItemMeta, "comp"> & { item: IItem };
parent_prop?: ItemMeta;
scope?: any;
scopeAttached?: { meta: ItemMeta; value: any }[];
className?: string;
elprop?: any;
depth: number;