wip fix
This commit is contained in:
parent
065f389da0
commit
11ed7390c5
|
|
@ -8,6 +8,8 @@ import { IMeta, PG } from "../ed-global";
|
||||||
import { treeRebuild } from "../tree/build";
|
import { treeRebuild } from "../tree/build";
|
||||||
import { pushTreeNode } from "../tree/build/push-tree";
|
import { pushTreeNode } from "../tree/build/push-tree";
|
||||||
import { isTextEditing } from "../active/is-editing";
|
import { isTextEditing } from "../active/is-editing";
|
||||||
|
import { assignMitem } from "../tree/assign-mitem";
|
||||||
|
import { createId } from "@paralleldrive/cuid2";
|
||||||
|
|
||||||
export const loadcomp = {
|
export const loadcomp = {
|
||||||
timeout: 0 as any,
|
timeout: 0 as any,
|
||||||
|
|
@ -43,13 +45,11 @@ export const loadCompSnapshot = async (
|
||||||
comp_id: string,
|
comp_id: string,
|
||||||
snapshot: Uint8Array
|
snapshot: Uint8Array
|
||||||
) => {
|
) => {
|
||||||
if (p.comp.list[comp_id] && p.comp.list[comp_id].doc) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
const doc = new Y.Doc() as DComp;
|
const doc = new Y.Doc() as DComp;
|
||||||
Y.applyUpdate(doc as any, decompress(snapshot));
|
Y.applyUpdate(doc as any, decompress(snapshot));
|
||||||
const mitem = doc.getMap("map").get("root");
|
const mitem = doc.getMap("map").get("root");
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
|
p.comp.loaded[comp_id] = mitem.toJSON() as IItem;
|
||||||
if (typeof p.comp.list[comp_id]?.on_update === "function") {
|
if (typeof p.comp.list[comp_id]?.on_update === "function") {
|
||||||
doc.off("update", p.comp.list[comp_id].on_update);
|
doc.off("update", p.comp.list[comp_id].on_update);
|
||||||
}
|
}
|
||||||
|
|
@ -159,30 +159,20 @@ export const updateComponentMeta = async (
|
||||||
visit(m) {
|
visit(m) {
|
||||||
pushTreeNode(p, m, meta, tree);
|
pushTreeNode(p, m, meta, tree);
|
||||||
|
|
||||||
if (m.parent) {
|
assignMitem({
|
||||||
if (m.parent.id === "root") {
|
m,
|
||||||
if (m.item.id === item.id) {
|
root: item,
|
||||||
m.mitem = mitem;
|
mitem,
|
||||||
}
|
meta,
|
||||||
} else {
|
new_prop_jsx(meta, mprops, prop_name, prop_val) {
|
||||||
const parent = meta[m.parent.id];
|
transact.list.push(() => {
|
||||||
if (parent && parent.mitem) {
|
const map = new Y.Map();
|
||||||
parent.mitem.get("childs")?.forEach((child) => {
|
if (prop_val.content) prop_val.content.id = createId();
|
||||||
const cid = child.get("id");
|
syncronize(map, prop_val);
|
||||||
if (cid) {
|
mprops.set(prop_name, map as any);
|
||||||
if (
|
});
|
||||||
cid === m.item.id ||
|
},
|
||||||
(m.instances &&
|
});
|
||||||
m.instances[cid] &&
|
|
||||||
m.instances[cid][m.item.id])
|
|
||||||
) {
|
|
||||||
m.mitem = child;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
note: "load-comp-scan-meta",
|
note: "load-comp-scan-meta",
|
||||||
|
|
@ -190,7 +180,19 @@ export const updateComponentMeta = async (
|
||||||
{ item, ignore_first_component: true }
|
{ item, ignore_first_component: true }
|
||||||
);
|
);
|
||||||
|
|
||||||
|
if (transact.list.length > 0) {
|
||||||
|
p.page.doc?.transact(() => {
|
||||||
|
for (const fn of transact.list) {
|
||||||
|
fn();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
p.comp.loaded[comp_id] = item;
|
p.comp.loaded[comp_id] = item;
|
||||||
|
|
||||||
return { meta, tree };
|
return { meta, tree };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const transact = {
|
||||||
|
list: [] as (() => void)[],
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@ import { FMCompDef, FNCompDef } from "../../../../utils/types/meta-fn";
|
||||||
import { IMeta, PG } from "../ed-global";
|
import { IMeta, PG } from "../ed-global";
|
||||||
|
|
||||||
export const assignMitem = (arg: {
|
export const assignMitem = (arg: {
|
||||||
p: PG;
|
|
||||||
m: IMeta;
|
m: IMeta;
|
||||||
root: IItem;
|
root: IItem;
|
||||||
mitem: MItem;
|
mitem: MItem;
|
||||||
|
|
@ -16,7 +15,7 @@ export const assignMitem = (arg: {
|
||||||
prop_val: FNCompDef
|
prop_val: FNCompDef
|
||||||
) => void;
|
) => void;
|
||||||
}) => {
|
}) => {
|
||||||
const { p, m, root, mitem, meta } = arg;
|
const { m, root, mitem, meta } = arg;
|
||||||
|
|
||||||
if (m.jsx_prop && m.parent?.instance_id) {
|
if (m.jsx_prop && m.parent?.instance_id) {
|
||||||
const instance_meta = meta[m.parent?.instance_id];
|
const instance_meta = meta[m.parent?.instance_id];
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,6 @@ export const treeRebuild = async (p: PG, arg?: { note?: string }) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
assignMitem({
|
assignMitem({
|
||||||
p,
|
|
||||||
m,
|
m,
|
||||||
root: item,
|
root: item,
|
||||||
mitem,
|
mitem,
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ export const pushTreeNode = (
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
const parent = metas[meta.parent?.id || ""];
|
const parent = metas[meta.parent?.id || ""];
|
||||||
|
|
||||||
if (parent && parent.mitem) {
|
if (parent && parent.mitem) {
|
||||||
parent.mitem.get("childs")?.forEach((mitem) => {
|
parent.mitem.get("childs")?.forEach((mitem) => {
|
||||||
if (mitem.get("id") === meta.item.id) {
|
if (mitem.get("id") === meta.item.id) {
|
||||||
|
|
|
||||||
|
|
@ -3,7 +3,7 @@ import { useGlobal, useLocal } from "web-utils";
|
||||||
import { IItem } from "../../../../utils/types/item";
|
import { IItem } from "../../../../utils/types/item";
|
||||||
import { FMCompDef, FNCompDef } from "../../../../utils/types/meta-fn";
|
import { FMCompDef, FNCompDef } from "../../../../utils/types/meta-fn";
|
||||||
import { Menu, MenuItem } from "../../../../utils/ui/context-menu";
|
import { Menu, MenuItem } from "../../../../utils/ui/context-menu";
|
||||||
import { EDGlobal, IMeta, active } from "../../logic/ed-global";
|
import { EDGlobal, IMeta, PG, active } from "../../logic/ed-global";
|
||||||
import { createEditScript } from "./prop-instance/edit-script";
|
import { createEditScript } from "./prop-instance/edit-script";
|
||||||
import { EdPropInstanceCode } from "./prop-instance/prop-code";
|
import { EdPropInstanceCode } from "./prop-instance/prop-code";
|
||||||
import { EdPropInstanceOptions } from "./prop-instance/prop-option";
|
import { EdPropInstanceOptions } from "./prop-instance/prop-option";
|
||||||
|
|
@ -20,20 +20,14 @@ export const EdSidePropInstance: FC<{ meta: IMeta }> = ({ meta }) => {
|
||||||
|
|
||||||
let _meta = meta;
|
let _meta = meta;
|
||||||
if (active.comp_id) {
|
if (active.comp_id) {
|
||||||
if (
|
if (p.comp.list[active.comp_id]) {
|
||||||
p.comp.list[active.comp_id] &&
|
_meta = getCompMeta(p, meta);
|
||||||
p.comp.list[active.comp_id].meta &&
|
|
||||||
meta.item.originalId
|
|
||||||
) {
|
|
||||||
const m = p.comp.list[active.comp_id].meta[meta.item.originalId];
|
|
||||||
if (m) {
|
|
||||||
_meta = m;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const item = _meta?.item as IItem;
|
const item = _meta?.item as IItem;
|
||||||
if (!item) return <>Warning: Item not found</>;
|
if (!item) return <>Warning: Item not found</>;
|
||||||
|
if (!_meta.mitem) return <>Warning: MItem Not Found</>;
|
||||||
|
|
||||||
let filtered = [] as { mprop: FMCompDef; cprop: FNCompDef; name: string }[];
|
let filtered = [] as { mprop: FMCompDef; cprop: FNCompDef; name: string }[];
|
||||||
const mprops = _meta.mitem?.get("component")?.get("props");
|
const mprops = _meta.mitem?.get("component")?.get("props");
|
||||||
|
|
@ -216,3 +210,9 @@ export const EdSidePropInstance: FC<{ meta: IMeta }> = ({ meta }) => {
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const getCompMeta = (p: PG, imeta: IMeta) => {
|
||||||
|
let meta = null as unknown as IMeta;
|
||||||
|
|
||||||
|
return imeta;
|
||||||
|
};
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,6 @@ export const EdTreeBody = () => {
|
||||||
const local = useLocal({ tree: null as TreeMethods | null });
|
const local = useLocal({ tree: null as TreeMethods | null });
|
||||||
const TypedTree = DNDTree<IMeta>;
|
const TypedTree = DNDTree<IMeta>;
|
||||||
|
|
||||||
active.hover.renderTree = local.render;
|
|
||||||
expandTreeHook(p, local);
|
expandTreeHook(p, local);
|
||||||
|
|
||||||
let tree: NodeModel<IMeta>[] = [];
|
let tree: NodeModel<IMeta>[] = [];
|
||||||
|
|
|
||||||
|
|
@ -26,6 +26,10 @@ export const EdTreeName = ({
|
||||||
const is_jsx_prop = !!node.data?.jsx_prop?.is_root;
|
const is_jsx_prop = !!node.data?.jsx_prop?.is_root;
|
||||||
|
|
||||||
const isRenaming = p.ui.tree.rename_id === item.id;
|
const isRenaming = p.ui.tree.rename_id === item.id;
|
||||||
|
let name = item.name;
|
||||||
|
if (item.component?.id && p.comp.loaded[item.component.id]) {
|
||||||
|
name = p.comp.loaded[item.component.id].name;
|
||||||
|
}
|
||||||
return (
|
return (
|
||||||
<div className="text-[14px] relative flex flex-col justify-center cursor-pointer flex-1">
|
<div className="text-[14px] relative flex flex-col justify-center cursor-pointer flex-1">
|
||||||
{/* <div className="text-[10px]">{item.id}</div> */}
|
{/* <div className="text-[10px]">{item.id}</div> */}
|
||||||
|
|
@ -37,7 +41,7 @@ export const EdTreeName = ({
|
||||||
)}
|
)}
|
||||||
autoFocus
|
autoFocus
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
defaultValue={local.rename}
|
value={local.rename}
|
||||||
onFocus={(e) => {
|
onFocus={(e) => {
|
||||||
if (node.data?.jsx_prop?.is_root) {
|
if (node.data?.jsx_prop?.is_root) {
|
||||||
p.ui.tree.rename_id = "";
|
p.ui.tree.rename_id = "";
|
||||||
|
|
@ -97,13 +101,13 @@ export const EdTreeName = ({
|
||||||
}
|
}
|
||||||
}}
|
}}
|
||||||
onChange={(e) => {
|
onChange={(e) => {
|
||||||
local.rename = e.target.value;
|
local.rename = e.target.value.replace(/[\W_]+/g, "_");
|
||||||
p.render();
|
p.render();
|
||||||
}}
|
}}
|
||||||
/>
|
/>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<Name name={node.text} is_jsx_prop={is_jsx_prop} />
|
<Name name={name} is_jsx_prop={is_jsx_prop} />
|
||||||
{/* <div className={"text-[9px] text-gray-500 -mt-1"}>
|
{/* <div className={"text-[9px] text-gray-500 -mt-1"}>
|
||||||
{node.id} - {item.originalId}
|
{node.id} - {item.originalId}
|
||||||
</div> */}
|
</div> */}
|
||||||
|
|
|
||||||
|
|
@ -4,21 +4,20 @@ import { IContent } from "../../../../../utils/types/general";
|
||||||
import { Loading } from "../../../../../utils/ui/loading";
|
import { Loading } from "../../../../../utils/ui/loading";
|
||||||
import { getMetaById } from "../../../logic/active/get-meta";
|
import { getMetaById } from "../../../logic/active/get-meta";
|
||||||
import { EDGlobal, IMeta, active } from "../../../logic/ed-global";
|
import { EDGlobal, IMeta, active } from "../../../logic/ed-global";
|
||||||
|
import { text_edit } from "../../main/main-per-item";
|
||||||
import { EdTreeAction } from "./item/action";
|
import { EdTreeAction } from "./item/action";
|
||||||
import { EdTreeCtxMenu } from "./item/ctx-menu";
|
import { EdTreeCtxMenu } from "./item/ctx-menu";
|
||||||
import { EdTreeIndent } from "./item/indent";
|
import { EdTreeIndent } from "./item/indent";
|
||||||
import { EdTreeName } from "./item/name";
|
import { EdTreeName } from "./item/name";
|
||||||
import { treeItemKeyMap } from "./key-map";
|
import { treeItemKeyMap } from "./key-map";
|
||||||
import { text_edit } from "../../main/main-per-item";
|
|
||||||
import { treeRebuild } from "../../../logic/tree/build";
|
|
||||||
|
|
||||||
export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
const local = useLocal({
|
const local = useLocal({
|
||||||
rightClick: null as null | React.MouseEvent<HTMLDivElement, MouseEvent>,
|
rightClick: null as null | React.MouseEvent<HTMLDivElement, MouseEvent>,
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!node || !node.data) {
|
if (!node || !node.data) {
|
||||||
console.log("hello", node, prm);
|
|
||||||
return <></>;
|
return <></>;
|
||||||
}
|
}
|
||||||
const item = node.data?.item;
|
const item = node.data?.item;
|
||||||
|
|
@ -122,9 +121,7 @@ export const nodeRender: NodeRender<IMeta> = (node, prm) => {
|
||||||
}
|
}
|
||||||
active.item_id = item.id;
|
active.item_id = item.id;
|
||||||
p.ui.tree.search = "";
|
p.ui.tree.search = "";
|
||||||
treeRebuild(p);
|
|
||||||
p.render();
|
p.render();
|
||||||
p.page.render();
|
|
||||||
if ((item as IContent).type === "text") {
|
if ((item as IContent).type === "text") {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
if (document.activeElement?.tagName === "INPUT") {
|
if (document.activeElement?.tagName === "INPUT") {
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import { simplifyItemChild } from "./simplify";
|
||||||
|
|
||||||
export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
|
export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
|
||||||
const { item } = arg;
|
const { item } = arg;
|
||||||
|
|
||||||
if (item.type === "item" && item.component?.id && arg.parent?.item.id) {
|
if (item.type === "item" && item.component?.id && arg.parent?.item.id) {
|
||||||
let item_comp = p.comps[item.component.id];
|
let item_comp = p.comps[item.component.id];
|
||||||
if (p.on?.visit_component) {
|
if (p.on?.visit_component) {
|
||||||
|
|
@ -42,8 +43,10 @@ export const genComp = (p: GenMetaP, arg: GenMetaArg) => {
|
||||||
ids: instance,
|
ids: instance,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const meta: IMeta = {
|
const meta: IMeta = {
|
||||||
item: simplifyItemChild(item),
|
item: simplifyItemChild(item),
|
||||||
|
jsx_prop: arg.jsx_prop,
|
||||||
parent: {
|
parent: {
|
||||||
id: arg.parent.item.id,
|
id: arg.parent.item.id,
|
||||||
comp_id: arg.parent?.comp?.component?.id,
|
comp_id: arg.parent?.comp?.component?.id,
|
||||||
|
|
|
||||||
|
|
@ -26,10 +26,40 @@ export const initLoadComp = async (
|
||||||
comp_ids.add(id);
|
comp_ids.add(id);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (component?.props) {
|
||||||
|
for (const [name, prop] of Object.entries(component.props)) {
|
||||||
|
if (prop.meta?.type === "content-element" && prop.content) {
|
||||||
|
genMeta(
|
||||||
|
{
|
||||||
|
...p,
|
||||||
|
on: {
|
||||||
|
visit_component: ({ component }) => {
|
||||||
|
if (component) {
|
||||||
|
const { id } = component;
|
||||||
|
if (!p.comps[id]) {
|
||||||
|
if (!_loaded || (_loaded && !_loaded.has(id))) {
|
||||||
|
comp_ids.add(id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
visit(meta, vitem) {
|
||||||
|
if (opt.visit) opt.visit(meta, vitem, shared);
|
||||||
|
},
|
||||||
|
},
|
||||||
|
set_meta: false,
|
||||||
|
note: "init-load-comp-prop",
|
||||||
|
},
|
||||||
|
{ item: prop.content }
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
visit(meta, item) {
|
visit(meta, vitem) {
|
||||||
if (opt.visit) opt.visit(meta, item, shared);
|
if (opt.visit) opt.visit(meta, vitem, shared);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
set_meta: false,
|
set_meta: false,
|
||||||
|
|
@ -52,6 +82,7 @@ export const initLoadComp = async (
|
||||||
|
|
||||||
for (const id of [...loaded]) {
|
for (const id of [...loaded]) {
|
||||||
const comp = p.comps[id];
|
const comp = p.comps[id];
|
||||||
|
|
||||||
if (comp) {
|
if (comp) {
|
||||||
await initLoadComp(p, comp, opt, loaded);
|
await initLoadComp(p, comp, opt, loaded);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,7 @@ import { simplifyItemChild } from "./simplify";
|
||||||
|
|
||||||
export const genMeta = (p: GenMetaP, arg: GenMetaArg) => {
|
export const genMeta = (p: GenMetaP, arg: GenMetaArg) => {
|
||||||
const item = arg.item as IItem;
|
const item = arg.item as IItem;
|
||||||
|
|
||||||
if (item.type === "item" && item.component?.id) {
|
if (item.type === "item" && item.component?.id) {
|
||||||
if (arg.ignore_first_component !== true) {
|
if (arg.ignore_first_component !== true) {
|
||||||
genComp(p, arg);
|
genComp(p, arg);
|
||||||
|
|
|
||||||
|
|
@ -7,13 +7,12 @@ import {
|
||||||
FMDimension,
|
FMDimension,
|
||||||
FMFont,
|
FMFont,
|
||||||
FMLayout,
|
FMLayout,
|
||||||
FMLinkTag,
|
|
||||||
FMPadding,
|
FMPadding,
|
||||||
FNBackground,
|
FNBackground,
|
||||||
FNBorder,
|
FNBorder,
|
||||||
FNDimension,
|
FNDimension,
|
||||||
FNFont,
|
FNFont,
|
||||||
FNPadding,
|
FNPadding
|
||||||
} from "./meta-fn";
|
} from "./meta-fn";
|
||||||
|
|
||||||
export type MetaItem = {
|
export type MetaItem = {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue