wip fix
This commit is contained in:
parent
4e2fa56cd9
commit
0c22d2cdef
|
|
@ -146,9 +146,9 @@ export const EDGlobal = {
|
||||||
on_update?: (bin: Uint8Array, origin: any) => Promise<void>;
|
on_update?: (bin: Uint8Array, origin: any) => Promise<void>;
|
||||||
}
|
}
|
||||||
>,
|
>,
|
||||||
scope: {} as IScope,
|
|
||||||
building: false,
|
building: false,
|
||||||
meta: {} as Record<string, IMeta>,
|
meta: {} as Record<string, IMeta>,
|
||||||
|
smeta: {} as Record<string, ISimpleMeta>,
|
||||||
entry: [] as string[],
|
entry: [] as string[],
|
||||||
tree: [] as NodeModel<IMeta>[],
|
tree: [] as NodeModel<IMeta>[],
|
||||||
render: () => {},
|
render: () => {},
|
||||||
|
|
|
||||||
|
|
@ -56,6 +56,7 @@ export const reloadPage = async (p: PG, page_id: string, note: string) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
p.page.entry = remotePage.entry;
|
p.page.entry = remotePage.entry;
|
||||||
|
p.page.smeta = remotePage.meta;
|
||||||
|
|
||||||
p.page.cur = remotePage;
|
p.page.cur = remotePage;
|
||||||
if (remotePage.snapshot) {
|
if (remotePage.snapshot) {
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
import { IItem, MItem } from "../../../../utils/types/item";
|
import { IItem, MItem } from "../../../../utils/types/item";
|
||||||
import { viEvalComp } from "../../../vi/render/comp";
|
import { viEvalProps } from "../../../vi/render/comp";
|
||||||
import { ViRender } from "../../../vi/render/render";
|
import { viEvalScript } from "../../../vi/render/script";
|
||||||
import { ViScript } from "../../../vi/render/script";
|
|
||||||
import { genMeta } from "../../../view/logic/meta/meta";
|
import { genMeta } from "../../../view/logic/meta/meta";
|
||||||
import { PG, active } from "../ed-global";
|
import { PG, active } from "../ed-global";
|
||||||
import { pushTreeNode } from "./build/push-tree";
|
import { pushTreeNode } from "./build/push-tree";
|
||||||
|
|
@ -34,29 +33,27 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
for (const mitem of mitems) {
|
for (const mitem of mitems) {
|
||||||
const item = mitem.toJSON() as IItem;
|
const item = mitem.toJSON() as IItem;
|
||||||
if (item) {
|
if (item) {
|
||||||
|
p.page;
|
||||||
genMeta(
|
genMeta(
|
||||||
{
|
{
|
||||||
comps: p.comp.loaded,
|
comps: p.comp.loaded,
|
||||||
meta,
|
meta,
|
||||||
on: !is_layout
|
smeta: p.page.smeta,
|
||||||
? {
|
on: {
|
||||||
visit(meta) {
|
async visit(meta) {
|
||||||
pushTreeNode(p, meta);
|
if (!is_layout) {
|
||||||
|
pushTreeNode(p, meta);
|
||||||
|
|
||||||
if (!meta.item.adv?.js && !meta.item.component?.id) {
|
if (meta.item.component?.props) {
|
||||||
meta.fc = ViRender;
|
viEvalProps({ meta: p.page.meta, tick: 0 }, meta);
|
||||||
} else {
|
}
|
||||||
if (meta.item.component?.id) {
|
|
||||||
viEvalComp(meta);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (meta.item.adv?.js) {
|
if (meta.item.adv?.jsBuilt) {
|
||||||
meta.fc = ViScript;
|
viEvalScript({ meta: p.page.meta, tick: 0 }, meta);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
|
||||||
}
|
}
|
||||||
: undefined,
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
{ item, mitem }
|
{ item, mitem }
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,11 @@
|
||||||
import { ReactNode, useEffect } from "react";
|
import { useGlobal } from "web-utils";
|
||||||
import { useGlobal, useLocal } from "web-utils";
|
import { Vi } from "../../../vi/vi";
|
||||||
import { Loading } from "../../../../utils/ui/loading";
|
import { EDGlobal } from "../../logic/ed-global";
|
||||||
import { View } from "../../../view/view";
|
|
||||||
import { EDGlobal, active } from "../../logic/ed-global";
|
|
||||||
import { getMetaById } from "../../logic/tree/build";
|
|
||||||
import { loadComponent } from "../../logic/tree/sync-walk";
|
|
||||||
import { code } from "../popup/code/code";
|
|
||||||
import { IMeta } from "../../../view/logic/meta/types";
|
|
||||||
|
|
||||||
export const EdMain = () => {
|
export const EdMain = () => {
|
||||||
return <div className="flex-1"></div>;
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
// const p = useGlobal(EDGlobal, "EDITOR");
|
return <Vi ctx={{ meta: p.page.meta }} entry={p.page.entry} />;
|
||||||
|
|
||||||
// const local = useLocal({
|
// const local = useLocal({
|
||||||
// el: null as ReactNode,
|
// el: null as ReactNode,
|
||||||
// });
|
// });
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,9 @@
|
||||||
import { IMeta } from "../../ed/logic/ed-global";
|
import { IMeta } from "../../ed/logic/ed-global";
|
||||||
|
import { ViContext } from "./parts";
|
||||||
|
|
||||||
export const viEvalComp = (meta: IMeta) => {};
|
export const viEvalProps = async (ctx: ViContext, meta: IMeta) => {
|
||||||
|
if (meta.item.component?.props) {
|
||||||
|
for (const [k, v] of Object.entries(meta.item.component.props)) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,39 @@
|
||||||
|
import { produceCSS } from "../../../utils/css/gen";
|
||||||
|
import { IContent } from "../../../utils/types/general";
|
||||||
|
import { IMeta } from "../../ed/logic/ed-global";
|
||||||
|
|
||||||
|
export type ViContext = {
|
||||||
|
meta: Record<string, IMeta>;
|
||||||
|
tick: number;
|
||||||
|
};
|
||||||
|
export type ViParts = {
|
||||||
|
mode: "mobile" | "desktop";
|
||||||
|
hover?: boolean;
|
||||||
|
active?: boolean;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const viParts = (meta: IMeta, arg?: ViParts) => {
|
||||||
|
const item = meta.item;
|
||||||
|
const content = meta.item as unknown as IContent;
|
||||||
|
|
||||||
|
const props: React.DetailedHTMLProps<
|
||||||
|
React.HTMLAttributes<HTMLDivElement>,
|
||||||
|
HTMLDivElement
|
||||||
|
> = {};
|
||||||
|
|
||||||
|
let shouldRenderChild = true;
|
||||||
|
if (content.type === "text") {
|
||||||
|
props.dangerouslySetInnerHTML = { __html: item.html || "" };
|
||||||
|
shouldRenderChild = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return {
|
||||||
|
className: produceCSS(item, {
|
||||||
|
mode: arg?.mode || "desktop",
|
||||||
|
hover: arg?.hover,
|
||||||
|
active: arg?.active,
|
||||||
|
}),
|
||||||
|
shouldRenderChild,
|
||||||
|
props,
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
@ -1,6 +1,35 @@
|
||||||
import { FC } from "react";
|
import { FC, ReactNode } from "react";
|
||||||
import { IMeta } from "../../ed/logic/ed-global";
|
import { IMeta } from "../../ed/logic/ed-global";
|
||||||
|
import { ViContext, viParts } from "./parts";
|
||||||
|
import { ViScript } from "./script";
|
||||||
|
|
||||||
export const ViRender: FC<{ meta: IMeta }> = () => {
|
export const ViRender: FC<{
|
||||||
return <div></div>;
|
ctx: ViContext;
|
||||||
|
meta: IMeta;
|
||||||
|
children?: ReactNode;
|
||||||
|
}> = ({ meta, children, ctx }) => {
|
||||||
|
if (!meta) return null;
|
||||||
|
|
||||||
|
if (meta.item.adv?.js || meta.item.component?.id) {
|
||||||
|
return <ViScript ctx={ctx} meta={meta} />;
|
||||||
|
}
|
||||||
|
|
||||||
|
const parts = viParts(meta);
|
||||||
|
let renderChild = undefined;
|
||||||
|
|
||||||
|
if (parts.shouldRenderChild) {
|
||||||
|
renderChild = children
|
||||||
|
? children
|
||||||
|
: meta.item.childs?.map((item) => {
|
||||||
|
if (!item) return null;
|
||||||
|
const { id } = item;
|
||||||
|
return <ViRender key={id} ctx={ctx} meta={ctx.meta[id]} />;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div {...parts.props} className={parts.className}>
|
||||||
|
{renderChild}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,29 @@
|
||||||
import { FC } from "react";
|
import { FC } from "react";
|
||||||
import { IMeta } from "../../ed/logic/ed-global";
|
import { IMeta } from "../../ed/logic/ed-global";
|
||||||
|
import { ViContext, viParts } from "./parts";
|
||||||
|
import { ViRender } from "./render";
|
||||||
|
|
||||||
export const ViScript: FC<{ meta: IMeta }> = () => {
|
export const ViScript: FC<{ ctx: ViContext; meta: IMeta }> = ({
|
||||||
return <div></div>;
|
ctx,
|
||||||
|
meta,
|
||||||
|
}) => {
|
||||||
|
const childs = meta.item.childs;
|
||||||
|
const parts = viParts(meta);
|
||||||
|
|
||||||
|
let renderChild = undefined;
|
||||||
|
if (parts.shouldRenderChild) {
|
||||||
|
renderChild =
|
||||||
|
Array.isArray(childs) &&
|
||||||
|
childs.map(({ id }) => {
|
||||||
|
return <ViRender key={id} ctx={ctx} meta={ctx.meta[id]} />;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div {...parts.props} className={parts.className}>
|
||||||
|
{renderChild}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const viEvalScript = async (ctx: ViContext, meta: IMeta) => {};
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,26 @@
|
||||||
|
import { FC } from "react";
|
||||||
|
import { ViContext } from "./render/parts";
|
||||||
|
import { ViRender } from "./render/render";
|
||||||
|
import { useLocal } from "web-utils";
|
||||||
|
|
||||||
|
export const ViRoot: FC<{
|
||||||
|
ctx: ViContext;
|
||||||
|
entry: string[];
|
||||||
|
}> = ({ ctx, entry }) => {
|
||||||
|
const local = useLocal({ tick: Date.now() });
|
||||||
|
ctx.tick = local.tick;
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="flex flex-1 flex-col relative">
|
||||||
|
{entry.map((id) => {
|
||||||
|
const meta = ctx.meta[id];
|
||||||
|
if (meta) {
|
||||||
|
if (Element) {
|
||||||
|
return <ViRender key={meta.item.id} ctx={ctx} meta={meta} />;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
})}
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
@ -0,0 +1,56 @@
|
||||||
|
import { useErrorBoundary, withErrorBoundary } from "react-use-error-boundary";
|
||||||
|
import { useLocal } from "web-utils";
|
||||||
|
import { IMeta } from "../../ed/logic/ed-global";
|
||||||
|
|
||||||
|
export const ErrorBox = withErrorBoundary(
|
||||||
|
({
|
||||||
|
children,
|
||||||
|
meta,
|
||||||
|
id,
|
||||||
|
silent,
|
||||||
|
}: {
|
||||||
|
children: any;
|
||||||
|
meta?: IMeta;
|
||||||
|
id?: string;
|
||||||
|
silent?: boolean;
|
||||||
|
}) => {
|
||||||
|
const local = useLocal({ retrying: false });
|
||||||
|
const [error, resetError] = useErrorBoundary((error, errorInfo) => {
|
||||||
|
if (silent !== true) console.warn(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
let _meta = meta;
|
||||||
|
|
||||||
|
if (error) {
|
||||||
|
return (
|
||||||
|
<div className="bg-red-100 border border-red-300 rounded-sm text-xs flex flex-col items-center">
|
||||||
|
<div className="text-[10px] font-bold text-red-900 self-stretch px-1">
|
||||||
|
ERROR {_meta?.item.name ? "[" + _meta.item.name + "]:" : ""}
|
||||||
|
</div>
|
||||||
|
<p className="border-b border-red-300 px-1 pb-1 min-w-[100px]">
|
||||||
|
{!local.retrying ? <>{(error as any).message}</> : <>Retrying...</>}
|
||||||
|
</p>
|
||||||
|
<div className="p-1">
|
||||||
|
<button
|
||||||
|
onClick={() => {
|
||||||
|
local.retrying = true;
|
||||||
|
local.render();
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
local.retrying = false;
|
||||||
|
local.render();
|
||||||
|
resetError();
|
||||||
|
}, 100);
|
||||||
|
}}
|
||||||
|
className="bg-white border border-white hover:border-red-400 hover:bg-red-50 rounded px-2"
|
||||||
|
>
|
||||||
|
Try again
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return children;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
@ -0,0 +1,13 @@
|
||||||
|
import { Suspense } from "react";
|
||||||
|
import { ViRoot } from "./root";
|
||||||
|
import { ErrorBox } from "./utils/error-box";
|
||||||
|
|
||||||
|
export const Vi: typeof ViRoot = (props) => {
|
||||||
|
return (
|
||||||
|
<ErrorBox>
|
||||||
|
<Suspense>
|
||||||
|
<ViRoot {...props} />
|
||||||
|
</Suspense>
|
||||||
|
</ErrorBox>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
@ -1,6 +1,8 @@
|
||||||
import { FC } from "react";
|
import { FC, ReactNode } from "react";
|
||||||
import { IContent, MContent } from "../../../../utils/types/general";
|
import { IContent, MContent } from "../../../../utils/types/general";
|
||||||
import { IItem, MItem } from "../../../../utils/types/item";
|
import { IItem, MItem } from "../../../../utils/types/item";
|
||||||
|
import { ViContext } from "../../../vi/render/parts";
|
||||||
|
import { ViRender } from "../../../vi/render/render";
|
||||||
|
|
||||||
export type GenMetaP = {
|
export type GenMetaP = {
|
||||||
meta: Record<string, IMeta>;
|
meta: Record<string, IMeta>;
|
||||||
|
|
@ -59,7 +61,6 @@ export type IMeta = {
|
||||||
name: string;
|
name: string;
|
||||||
is_root: boolean;
|
is_root: boolean;
|
||||||
};
|
};
|
||||||
fc?: FC<{ meta: IMeta }>;
|
|
||||||
scope: {
|
scope: {
|
||||||
val?: any;
|
val?: any;
|
||||||
def?: {
|
def?: {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue