wip checkpoint view

This commit is contained in:
Rizky 2023-11-19 13:14:27 +07:00
parent e444740196
commit 619b244046
72 changed files with 124 additions and 22 deletions

View File

@ -3,7 +3,7 @@ import {
EComp, EComp,
EPage, EPage,
ESite, ESite,
} from "../../../web/src/render/ed/logic/ed-global"; } from "../../../web/src/nova/ed/logic/ed-global";
import { IItem } from "../../../web/src/utils/types/item"; import { IItem } from "../../../web/src/utils/types/item";
import { site_group } from "./actions/site_group"; import { site_group } from "./actions/site_group";
import { activity } from "./entity/activity"; import { activity } from "./entity/activity";

View File

@ -1,5 +1,5 @@
import { validate } from "uuid"; import { validate } from "uuid";
import { ESite } from "../../../../web/src/render/ed/logic/ed-global"; import { ESite } from "../../../../web/src/nova/ed/logic/ed-global";
import { SAction } from "../actions"; import { SAction } from "../actions";
import { SyncConnection } from "../type"; import { SyncConnection } from "../type";
import { activity } from "../entity/activity"; import { activity } from "../entity/activity";

View File

@ -1,7 +1,7 @@
import { useEffect } from "react"; import { useEffect } from "react";
import { page, useGlobal } from "web-utils"; import { page, useGlobal } from "web-utils";
import { EDGlobal } from "../../render/ed/logic/ed-global"; import { EDGlobal } from "../../nova/ed/logic/ed-global";
import { edInitSync } from "../../render/ed/logic/ed-sync"; import { edInitSync } from "../../nova/ed/logic/ed-sync";
import { Loading } from "../../utils/ui/loading"; import { Loading } from "../../utils/ui/loading";
import { isLocalhost } from "../../utils/ui/is-localhost"; import { isLocalhost } from "../../utils/ui/is-localhost";

View File

@ -1,9 +1,9 @@
import { page, useGlobal } from "web-utils"; import { page, useGlobal } from "web-utils";
import { EdBase } from "../../render/ed/ed-base"; import { EdBase } from "../../nova/ed/ed-base";
import { EDGlobal } from "../../render/ed/logic/ed-global"; import { EDGlobal } from "../../nova/ed/logic/ed-global";
import { Loading } from "../../utils/ui/loading"; import { Loading } from "../../utils/ui/loading";
import { initSync } from "wasm-gzip"; import { initSync } from "wasm-gzip";
import { edInitSync } from "../../render/ed/logic/ed-sync"; import { edInitSync } from "../../nova/ed/logic/ed-sync";
export default page({ export default page({
url: "/ed/:site_id/:page_id", url: "/ed/:site_id/:page_id",

View File

@ -76,11 +76,12 @@ export const EDGlobal = {
page: { page: {
cur: EmptyPage, cur: EmptyPage,
doc: null as null | DPage, doc: null as null | DPage,
root: null as null | IRoot, list: {} as Record<string, { page: EPage; doc: DPage }>,
building: false,
meta: {} as Record<string, EdMeta>,
entry: [] as string[], entry: [] as string[],
tree: [] as NodeModel<EdMeta>[], tree: [] as NodeModel<EdMeta>[],
meta: {} as Record<string, EdMeta>,
list: {} as Record<string, { page: EPage; doc: DPage }>,
}, },
comp: { comp: {
cur: EmptyComp, cur: EmptyComp,

View File

@ -1,7 +1,6 @@
import { compress, decompress } from "wasm-gzip"; import { compress, decompress } from "wasm-gzip";
import { PG } from "./ed-global"; import { PG } from "./ed-global";
import { treeRebuild } from "./tree/build"; import { treeRebuild } from "./tree/build";
import { w } from "../../../utils/types/general";
export const edRoute = async (p: PG) => { export const edRoute = async (p: PG) => {
if (p.status === "ready") { if (p.status === "ready") {

View File

@ -1,4 +1,5 @@
import { createId } from "@paralleldrive/cuid2"; import { createId } from "@paralleldrive/cuid2";
import { decompress } from "wasm-gzip";
import { syncronize } from "y-pojo"; import { syncronize } from "y-pojo";
import { TypedMap } from "yjs-types"; import { TypedMap } from "yjs-types";
import { MContent } from "../../../../utils/types/general"; import { MContent } from "../../../../utils/types/general";
@ -9,10 +10,9 @@ import {
FNCompDef, FNCompDef,
FNComponent, FNComponent,
} from "../../../../utils/types/meta-fn"; } from "../../../../utils/types/meta-fn";
import { DComp } from "../../../../utils/types/root"; import { DComp, IRoot } from "../../../../utils/types/root";
import { MSection } from "../../../../utils/types/section"; import { MSection } from "../../../../utils/types/section";
import { EdMeta, PG } from "../ed-global"; import { EdMeta, PG } from "../ed-global";
import { decompress } from "wasm-gzip";
export const treeRebuild = async (p: PG, arg?: { note?: string }) => { export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
const doc = p.page.doc; const doc = p.page.doc;
@ -20,6 +20,9 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
const root = doc.getMap("map").get("root"); const root = doc.getMap("map").get("root");
if (root) { if (root) {
p.page.building = true;
p.render();
const sections = root.get("childs"); const sections = root.get("childs");
if (sections) { if (sections) {
const loaded = new Set<string>(); const loaded = new Set<string>();
@ -60,6 +63,8 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
} }
} }
}); });
p.page.building = false;
p.render(); p.render();
} }
}; };

View File

@ -0,0 +1,22 @@
import { useGlobal } from "web-utils";
import { Loading } from "../../../../utils/ui/loading";
import { View } from "../../../view/view";
import { EDGlobal } from "../../logic/ed-global";
export const EdMain = () => {
const p = useGlobal(EDGlobal, "EDITOR");
return (
<div className="flex flex-1 relative">
{!!p.page.building && <Loading backdrop={false} />}
{!p.page.building && (
<View
load={{
mode: "tree_meta",
meta: p.page.meta,
entry: p.page.entry,
}}
/>
)}
</div>
);
};

View File

@ -1,7 +1,7 @@
import { syncronize } from "y-pojo"; import { syncronize } from "y-pojo";
import { IContent, MContent } from "../../../../../../../utils/types/general"; import { IContent, MContent } from "../../../../../../../utils/types/general";
import { IItem } from "../../../../../../../utils/types/item"; import { IItem } from "../../../../../../../utils/types/item";
import { fillID } from "../../../../../../editor/tools/fill-id"; import { fillID } from "../../../../../../../render/editor/tools/fill-id";
import { PG } from "../../../../../logic/ed-global"; import { PG } from "../../../../../logic/ed-global";
import { treeRebuild } from "../../../../../logic/tree/build"; import { treeRebuild } from "../../../../../logic/tree/build";

View File

@ -2,7 +2,7 @@ import { syncronize } from "y-pojo";
import { IItem } from "../../../../../../../utils/types/item"; import { IItem } from "../../../../../../../utils/types/item";
import { PG } from "../../../../../logic/ed-global"; import { PG } from "../../../../../logic/ed-global";
import { treeRebuild } from "../../../../../logic/tree/build"; import { treeRebuild } from "../../../../../logic/tree/build";
import { fillID } from "../../../../../../editor/tools/fill-id"; import { fillID } from "../../../../../../../render/editor/tools/fill-id";
export const edActionDetach = (p: PG, item: IItem) => { export const edActionDetach = (p: PG, item: IItem) => {
const mitem = p.page.meta[item.id].mitem; const mitem = p.page.meta[item.id].mitem;

View File

@ -3,7 +3,7 @@ import { IContent } from "../../../../../../../utils/types/general";
import { MItem } from "../../../../../../../utils/types/item"; import { MItem } from "../../../../../../../utils/types/item";
import { PG, active } from "../../../../../logic/ed-global"; import { PG, active } from "../../../../../logic/ed-global";
import { treeRebuild } from "../../../../../logic/tree/build"; import { treeRebuild } from "../../../../../logic/tree/build";
import { fillID } from "../../../../../../editor/tools/fill-id"; import { fillID } from "../../../../../../../render/editor/tools/fill-id";
export const edActionPaste = async (p: PG, item: IContent) => { export const edActionPaste = async (p: PG, item: IContent) => {
const mitem = p.page.meta[item.id].mitem; const mitem = p.page.meta[item.id].mitem;

View File

@ -0,0 +1,9 @@
import { EdMeta } from "../../ed/logic/ed-global";
export const ViewGlobal = {
mode: "init" as "init" | "ready",
meta: {} as Record<string, EdMeta>,
entry: [] as string[],
};
export type VG = typeof ViewGlobal & { render: () => void };

View File

@ -0,0 +1,12 @@
import { useGlobal } from "web-utils";
import { VG, ViewGlobal } from "./global";
import { VLoad } from "./types";
export const VInit = (v: VG, load: VLoad) => {
v.mode = "ready";
if (load.mode === "tree_meta") {
v.meta = load.meta;
v.entry = load.entry;
}
};

View File

@ -0,0 +1,10 @@
import { EdMeta } from "../../ed/logic/ed-global";
export type VLoad =
| { mode: "page"; page_id: string }
| { mode: "pathname"; pathname: string }
| {
mode: "tree_meta";
entry: string[];
meta: Record<string, EdMeta>;
};

View File

@ -0,0 +1,10 @@
import { FC, ReactNode } from "react";
import { ISection } from "../../../utils/types/section";
export const VSection: FC<{ item: ISection; children: ReactNode }> = ({
item,
children,
}) => {
console.log(item);
return <div></div>;
};

View File

@ -0,0 +1,37 @@
import { FC } from "react";
import { useGlobal } from "web-utils";
import { Loading } from "../../utils/ui/loading";
import { ViewGlobal } from "./logic/global";
import { VInit } from "./logic/init";
import { VLoad } from "./logic/types";
import { VSection } from "./render/section";
import { ISection } from "../../utils/types/section";
export const View: FC<{
load: VLoad;
}> = ({ load }) => {
const v = useGlobal(ViewGlobal, "VIEW");
if (v.mode === "init") {
VInit(v, load);
}
return (
<div className="flex flex-1 flex-col relative">
{v.mode !== "ready" ? (
<Loading backdrop={false} />
) : (
v.entry.map((section_id) => {
const meta = v.meta[section_id];
const section = meta.item as ISection;
return (
<VSection item={section} key={section_id}>
Hello
</VSection>
);
})
)}
</div>
);
};

View File

@ -1,3 +0,0 @@
export const EdMain = () => {
return <div className="flex flex-1"></div>;
};

View File

@ -5,7 +5,7 @@ import { mobileCSS } from "../elements/e-page";
import { editorStyle } from "../elements/style"; import { editorStyle } from "../elements/style";
import { EditorGlobal } from "../logic/global"; import { EditorGlobal } from "../logic/global";
import { Toolbar } from "./toolbar/Toolbar"; import { Toolbar } from "./toolbar/Toolbar";
import { EdScriptInit } from "../../ed/panel/script/monaco/init"; import { EdScriptInit } from "../../../nova/ed/panel/script/monaco/init";
const ETree = lazy(async () => ({ const ETree = lazy(async () => ({
default: (await import("./tree/tree")).ETree, default: (await import("./tree/tree")).ETree,

View File

@ -10,7 +10,7 @@ import {
} from "../../../../srv/ws/sync/actions-def"; } from "../../../../srv/ws/sync/actions-def";
import { UserConf } from "../../../../srv/ws/sync/entity/user"; import { UserConf } from "../../../../srv/ws/sync/entity/user";
import { SyncType } from "../../../../srv/ws/sync/type"; import { SyncType } from "../../../../srv/ws/sync/type";
import { ESite } from "../../render/ed/logic/ed-global"; import { ESite } from "../../nova/ed/logic/ed-global";
import { w } from "../types/general"; import { w } from "../types/general";
import { initIDB } from "./idb"; import { initIDB } from "./idb";
const packr = new Packr({ structuredClone: true }); const packr = new Packr({ structuredClone: true });