This commit is contained in:
Rizky 2024-01-04 20:25:16 +07:00
parent abb843c3de
commit a353226816
10 changed files with 42 additions and 16 deletions

View File

@ -66,6 +66,10 @@ export const page_load: SAction["page"]["load"] = async function (
return data;
});
};
const page = await db.page.findFirst({ where: { id } });
if (page) {
await prepContentTree(page.id, page.content_tree, this);
}
user.active.delAll({ client_id: this.client_id });

View File

@ -30,18 +30,18 @@ export const prepContentTree = async (
comps,
meta,
on: {
visit(meta, item) {
if (item.adv?.js) {
item.script = parseJs(item.adv.js);
}
visit_component(item) {
if (item.component?.id) {
if (!item.component?.instances) {
item.component.instances = {};
meta.item.childs = [];
}
}
},
visit(meta, item) {
if (item.adv?.js) {
item.script = parseJs(item.adv.js);
}
},
},
mode: "page",
},
@ -56,10 +56,10 @@ export const loadCompForPage = async (ctree: IRoot, sync: SyncConnection) => {
const mcomps: GenMetaP["comps"] = {};
const result = new Set<string>();
const loading = {} as Record<string, Promise<void>>;
for (const mchild of ctree.childs) {
for (const child of ctree.childs) {
await initLoadComp(
{ comps: mcomps, meta, mode: "page" },
mchild as unknown as IItem,
child as unknown as IItem,
async (comp_ids) => {
for (const id of comp_ids) {
if (!docs.comp[id]) {

View File

@ -8,8 +8,7 @@ import { IItem } from "../../../utils/types/item";
import { DComp, DPage } from "../../../utils/types/root";
import {
GenMetaP,
ISimpleMeta,
IMeta as LogicMeta,
IMeta as LogicMeta
} from "../../vi/utils/types";
export type IMeta = LogicMeta;

View File

@ -1,12 +1,18 @@
import { createId } from "@paralleldrive/cuid2";
import { IItem, MItem } from "../../../../utils/types/item";
import { FMCompDef, FNCompDef } from "../../../../utils/types/meta-fn";
import { genMeta } from "../../../vi/meta/meta";
import { IMeta, PG } from "../ed-global";
import { IMeta, PG, active } from "../ed-global";
import { assignMitem } from "./assign-mitem";
import { pushTreeNode } from "./build/push-tree";
export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
if (document.activeElement) {
const a = document.activeElement;
if (a.tagName === "DIV" && a.getAttribute("contenteditable") === "true") {
return;
}
}
const is_layout =
p.site.layout &&
p.site.layout.id === p.page.cur.id &&

View File

@ -59,10 +59,8 @@ export const mainPerItemVisit = (
text_edit.id === meta.item.id ||
text_edit.id === meta.item.originalId
) {
if (document.activeElement !== el) {
setCaret(el, text_edit.caret);
text_edit.caret = null;
}
setCaret(el, text_edit.caret);
text_edit.caret = null;
}
}
};

View File

@ -2,6 +2,8 @@ import { useGlobal, useLocal } from "web-utils";
import { Vi } from "../../../vi/vi";
import { EDGlobal, active } from "../../logic/ed-global";
import { mainPerItemVisit } from "./main-per-item";
import { VG } from "../../../vi/render/global";
import { IItem } from "../../../../utils/types/item";
export const EdMain = () => {
// return <div className="flex flex-1 flex-col relative"></div>;

View File

@ -49,5 +49,18 @@ export const extractExport = (p: PG, m: IMeta) => {
}
}
const props = m.item.component?.props;
if (props) {
for (const [k, v] of Object.entries(props)) {
result[k] = {
type: "prop",
id: m.item.id,
start: 0,
end: 0,
val: v.value,
};
}
}
return result;
};

View File

@ -1,3 +1,4 @@
import { IItem } from "../../../utils/types/item";
import { IMeta } from "../../ed/logic/ed-global";
import { viParts } from "./parts";

View File

@ -11,6 +11,7 @@ export const ViRender: FC<{
children?: ReactNode;
passprop?: any;
}> = ({ meta, children, passprop }) => {
const vi = useGlobal(ViGlobal, "VI");
if (!meta) return null;
if (meta.item.hidden) return null;

View File

@ -8,6 +8,7 @@ import { ErrorBox } from "./utils/error-box";
export const Vi: FC<{
meta: Record<string, IMeta>;
comp_load?: (comp_id: string) => Promise<void>;
entry: string[];
api_url: string;
site_id: string;
@ -18,6 +19,7 @@ export const Vi: FC<{
visit?: VG["visit"];
}> = ({ meta, entry, api_url, site_id, api, db, visit, script }) => {
const vi = useGlobal(ViGlobal, "VI");
if (vi.meta !== meta) {
vi.meta = meta;
}