fix tree
This commit is contained in:
parent
d1dc647f62
commit
f0af063c9c
|
|
@ -1,40 +1,17 @@
|
|||
import { scrollTreeActiveItem } from "../../panel/tree/scroll-tree";
|
||||
import { IMeta, PG, active } from "../ed-global";
|
||||
import { getMetaById } from "./get-meta";
|
||||
|
||||
export const activateMeta = (p: PG, _meta: IMeta) => {
|
||||
scrollTreeActiveItem();
|
||||
|
||||
let meta = _meta;
|
||||
let parent_comp_id = meta.parent?.comp_id;
|
||||
|
||||
if (!active.comp_id && meta.parent?.comp_id) {
|
||||
let parent = meta.parent;
|
||||
|
||||
let is_jsx = false;
|
||||
let i = 0;
|
||||
while (parent) {
|
||||
const meta_parent = p.page.meta[parent.id];
|
||||
|
||||
if (meta_parent && meta_parent.parent) {
|
||||
if (meta_parent.item.component?.id === meta.parent?.comp_id) {
|
||||
is_jsx = true;
|
||||
break;
|
||||
}
|
||||
|
||||
parent = meta_parent.parent;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
if (i > 10000) {
|
||||
console.warn("warning cyclic item tree possibility detected.");
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
|
||||
if (is_jsx) {
|
||||
if (meta.parent.instance_id) {
|
||||
meta = p.page.meta[meta.parent.instance_id];
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
if (!Object.keys(meta).includes("jsx_prop") && meta.parent.instance_id) {
|
||||
const comp = getMetaById(p, meta.parent.instance_id);
|
||||
if (comp) meta = comp;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -101,7 +101,8 @@ const TreeItem: FC<{
|
|||
css`
|
||||
padding-left: ${depth * 10 + 10}px;
|
||||
`,
|
||||
f.path === path && "border-r-2 bg-blue-100 border-r-blue-700"
|
||||
f.path === path &&
|
||||
"border-r-2 bg-blue-100 border-r-blue-700"
|
||||
)}
|
||||
onClick={() => {
|
||||
f.selected.clear();
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import { useEffect } from "react";
|
|||
import { IContent } from "../../../../../../utils/types/general";
|
||||
import { getMetaById } from "../../../../logic/active/get-meta";
|
||||
import { IMeta, PG, active } from "../../../../logic/ed-global";
|
||||
import { scrollTreeActiveItem } from "../../scroll-tree";
|
||||
|
||||
export const expandTreeHook = (
|
||||
p: PG,
|
||||
|
|
@ -83,5 +84,6 @@ export const expandTreeHook = (
|
|||
}
|
||||
}
|
||||
}
|
||||
scrollTreeActiveItem();
|
||||
}, [p.page.tree, active.comp_id, active.item_id, p.ui.tree.open_all]);
|
||||
};
|
||||
|
|
|
|||
|
|
@ -0,0 +1,17 @@
|
|||
import { active } from "../../logic/ed-global";
|
||||
|
||||
export const scrollTreeActiveItem = () => {
|
||||
setTimeout(() => {
|
||||
let i = 0;
|
||||
const ival = setInterval(() => {
|
||||
const div = document.querySelector(
|
||||
`.tree-${active.item_id}`
|
||||
) as HTMLDivElement;
|
||||
if (div) {
|
||||
div.scrollIntoView();
|
||||
}
|
||||
if (i > 7) clearInterval(ival);
|
||||
i++;
|
||||
}, 30);
|
||||
}, 100);
|
||||
};
|
||||
Loading…
Reference in New Issue