wip fix
This commit is contained in:
parent
f32bdf7d62
commit
624758dc69
|
|
@ -7,6 +7,8 @@ import { EDGlobal, PG, active } from "../../../logic/ed-global";
|
||||||
import { EdCompPreviewTree } from "./comp-preview-tree";
|
import { EdCompPreviewTree } from "./comp-preview-tree";
|
||||||
import { compPicker, reloadCompPicker } from "./comp-reload";
|
import { compPicker, reloadCompPicker } from "./comp-reload";
|
||||||
import { loadComponent } from "../../../logic/comp/load";
|
import { loadComponent } from "../../../logic/comp/load";
|
||||||
|
import { NodeModel } from "@minoru/react-dnd-treeview";
|
||||||
|
import { CompItem } from "./comp-tree";
|
||||||
|
|
||||||
export const EdCompPreview = () => {
|
export const EdCompPreview = () => {
|
||||||
const p = useGlobal(EDGlobal, "EDITOR");
|
const p = useGlobal(EDGlobal, "EDITOR");
|
||||||
|
|
@ -23,6 +25,23 @@ export const EdCompPreview = () => {
|
||||||
p.render();
|
p.render();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let found = compPicker.tree.find((e) => e.id === comp_id);
|
||||||
|
if (!found) {
|
||||||
|
found = compPicker.trash.find((e) => e.id === comp_id);
|
||||||
|
}
|
||||||
|
if (found) {
|
||||||
|
const root = ref.tree.find((e) => e.parent === "root");
|
||||||
|
if (root) {
|
||||||
|
if (root.text !== found.text) {
|
||||||
|
found.text = root.text;
|
||||||
|
db.component.update({
|
||||||
|
where: { id: comp_id },
|
||||||
|
data: { name: found.text },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}, [comp_id]);
|
}, [comp_id]);
|
||||||
|
|
||||||
const isTrashed = !!compPicker.trash.find((e) => e.id === comp_id);
|
const isTrashed = !!compPicker.trash.find((e) => e.id === comp_id);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,5 @@
|
||||||
import { NodeModel } from "@minoru/react-dnd-treeview";
|
import { NodeModel } from "@minoru/react-dnd-treeview";
|
||||||
import { PG } from "../../../logic/ed-global";
|
import { IMeta, PG } from "../../../logic/ed-global";
|
||||||
import { CompItem } from "./comp-tree";
|
import { CompItem } from "./comp-tree";
|
||||||
|
|
||||||
export const compPicker = {
|
export const compPicker = {
|
||||||
|
|
@ -57,6 +57,24 @@ export const reloadCompPicker = async (p: PG) => {
|
||||||
? compPicker.tree
|
? compPicker.tree
|
||||||
: compPicker.trash;
|
: compPicker.trash;
|
||||||
|
|
||||||
|
if (p.comp.list[comp.id]) {
|
||||||
|
const tree = p.comp.list[comp.id].tree;
|
||||||
|
if (tree) {
|
||||||
|
const root = tree.find(
|
||||||
|
(e) => e.parent === "root"
|
||||||
|
) as NodeModel<IMeta>;
|
||||||
|
if (root) {
|
||||||
|
if (root.data?.item.name && comp.name !== root.data?.item.name) {
|
||||||
|
comp.name = root.data.item.name;
|
||||||
|
db.component.update({
|
||||||
|
where: { id: comp.id },
|
||||||
|
data: { name: comp.name },
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
tree.push({
|
tree.push({
|
||||||
id: comp.id,
|
id: comp.id,
|
||||||
parent: comp.id_component_group,
|
parent: comp.id_component_group,
|
||||||
|
|
|
||||||
|
|
@ -55,7 +55,7 @@ export const EdTreeCtxMenu = ({
|
||||||
const comp = (item as IItem).component as FNComponent | undefined;
|
const comp = (item as IItem).component as FNComponent | undefined;
|
||||||
const isComponent = comp?.id;
|
const isComponent = comp?.id;
|
||||||
const isActiveComponent = active.comp_id === comp?.id;
|
const isActiveComponent = active.comp_id === comp?.id;
|
||||||
|
const isJSXProp = node.data?.jsx_prop?.is_root;
|
||||||
if (!item) {
|
if (!item) {
|
||||||
return (
|
return (
|
||||||
<Menu mouseEvent={event} onClose={onClose}>
|
<Menu mouseEvent={event} onClose={onClose}>
|
||||||
|
|
@ -69,7 +69,10 @@ export const EdTreeCtxMenu = ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Menu mouseEvent={event} onClose={onClose}>
|
<Menu mouseEvent={event} onClose={onClose}>
|
||||||
{type === "item" && !isActiveComponent && !item.component?.id && (
|
{type === "item" &&
|
||||||
|
!isActiveComponent &&
|
||||||
|
!isJSXProp &&
|
||||||
|
!item.component?.id && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
label="Attach Component"
|
label="Attach Component"
|
||||||
onClick={() => edActionAttach(p, item)}
|
onClick={() => edActionAttach(p, item)}
|
||||||
|
|
@ -81,7 +84,7 @@ export const EdTreeCtxMenu = ({
|
||||||
onClick={() => edActionDetach(p, item)}
|
onClick={() => edActionDetach(p, item)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
{type === "item" && !comp?.id && (
|
{type === "item" && !comp?.id && !isJSXProp && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
label="Create Component"
|
label="Create Component"
|
||||||
onClick={(e) => edActionNewComp(p, item, e)}
|
onClick={(e) => edActionNewComp(p, item, e)}
|
||||||
|
|
@ -91,35 +94,46 @@ export const EdTreeCtxMenu = ({
|
||||||
label={item.hidden ? "Unhide" : "Hide"}
|
label={item.hidden ? "Unhide" : "Hide"}
|
||||||
onClick={() => edActionHide(p, item)}
|
onClick={() => edActionHide(p, item)}
|
||||||
/>
|
/>
|
||||||
|
{!isJSXProp && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
label="Rename"
|
label="Rename"
|
||||||
hotKey={"↵"}
|
hotKey={"↵"}
|
||||||
onClick={() => edActionRename(p, item)}
|
onClick={() => edActionRename(p, item)}
|
||||||
/>
|
/>
|
||||||
|
)}
|
||||||
|
{!isJSXProp && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
label="Cut"
|
label="Cut"
|
||||||
// hotKey={<HotKey shortcut={"X"} />}
|
// hotKey={<HotKey shortcut={"X"} />}
|
||||||
onClick={() => edActionCut(p, item)}
|
onClick={() => edActionCut(p, item)}
|
||||||
/>
|
/>
|
||||||
{!isActiveComponent && (
|
)}
|
||||||
|
|
||||||
|
{!isActiveComponent && !isJSXProp && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
label="Delete"
|
label="Delete"
|
||||||
hotKey="⌫"
|
hotKey="⌫"
|
||||||
onClick={() => edActionDelete(p, item)}
|
onClick={() => edActionDelete(p, item)}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
|
{!isJSXProp && (
|
||||||
<MenuItem label="Clone" onClick={() => edActionClone(p, item)} />
|
<MenuItem label="Clone" onClick={() => edActionClone(p, item)} />
|
||||||
|
)}
|
||||||
|
|
||||||
|
{!isJSXProp && (
|
||||||
<MenuItem label="Copy" onClick={() => edActionCopy(p, item)} />
|
<MenuItem label="Copy" onClick={() => edActionCopy(p, item)} />
|
||||||
|
)}
|
||||||
{local.allowCopy &&
|
{local.allowCopy &&
|
||||||
local.allowPaste &&
|
local.allowPaste &&
|
||||||
!isComponent &&
|
!isComponent &&
|
||||||
item.type !== "text" && (
|
item.type !== "text" && (
|
||||||
<MenuItem label="Paste" onClick={() => edActionPaste(p, item)} />
|
<MenuItem label="Paste" onClick={() => edActionPaste(p, item)} />
|
||||||
)}
|
)}
|
||||||
{["text", "item"].includes(item.type) && (
|
{["text", "item"].includes(item.type) && !isJSXProp && (
|
||||||
<MenuItem label="Wrap" onClick={() => edActionWrap(p, item as IItem)} />
|
<MenuItem label="Wrap" onClick={() => edActionWrap(p, item as IItem)} />
|
||||||
)}
|
)}
|
||||||
{["item"].includes(item.type) && !isComponent && (
|
{["item"].includes(item.type) && !isJSXProp && !isComponent && (
|
||||||
<MenuItem
|
<MenuItem
|
||||||
label="Unwrap"
|
label="Unwrap"
|
||||||
onClick={() => edActionUnwrap(p, item as IItem)}
|
onClick={() => edActionUnwrap(p, item as IItem)}
|
||||||
|
|
|
||||||
|
|
@ -3,6 +3,7 @@ import { FC, useEffect } from "react";
|
||||||
import { useGlobal, useLocal } from "web-utils";
|
import { useGlobal, useLocal } from "web-utils";
|
||||||
import { EDGlobal, IMeta, active } from "../../../../logic/ed-global";
|
import { EDGlobal, IMeta, active } from "../../../../logic/ed-global";
|
||||||
import { Tooltip } from "../../../../../../utils/ui/tooltip";
|
import { Tooltip } from "../../../../../../utils/ui/tooltip";
|
||||||
|
import { treeRebuild } from "../../../../logic/tree/build";
|
||||||
|
|
||||||
export const EdTreeName = ({
|
export const EdTreeName = ({
|
||||||
node,
|
node,
|
||||||
|
|
@ -38,9 +39,17 @@ export const EdTreeName = ({
|
||||||
spellCheck={false}
|
spellCheck={false}
|
||||||
defaultValue={local.rename}
|
defaultValue={local.rename}
|
||||||
onFocus={(e) => {
|
onFocus={(e) => {
|
||||||
|
if (node.data?.jsx_prop?.is_root) {
|
||||||
|
p.ui.tree.rename_id = "";
|
||||||
|
p.render();
|
||||||
|
} else {
|
||||||
e.currentTarget.select();
|
e.currentTarget.select();
|
||||||
|
}
|
||||||
}}
|
}}
|
||||||
onBlur={() => {
|
onBlur={() => {
|
||||||
|
if (node.data?.jsx_prop?.is_root) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
item.name = local.rename;
|
item.name = local.rename;
|
||||||
|
|
||||||
let mitem = node.data?.mitem;
|
let mitem = node.data?.mitem;
|
||||||
|
|
@ -49,10 +58,9 @@ export const EdTreeName = ({
|
||||||
mitem = comp?.doc.getMap("map").get("root");
|
mitem = comp?.doc.getMap("map").get("root");
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mitem) {
|
|
||||||
mitem.doc?.transact(() => {
|
|
||||||
if (mitem) {
|
if (mitem) {
|
||||||
mitem.set("name", item.name);
|
mitem.set("name", item.name);
|
||||||
|
}
|
||||||
|
|
||||||
if (active.comp_id === item.component?.id) {
|
if (active.comp_id === item.component?.id) {
|
||||||
db.component.update({
|
db.component.update({
|
||||||
|
|
@ -64,11 +72,9 @@ export const EdTreeName = ({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
p.ui.tree.rename_id = "";
|
p.ui.tree.rename_id = "";
|
||||||
|
treeRebuild(p);
|
||||||
p.render();
|
p.render();
|
||||||
}}
|
}}
|
||||||
onKeyDown={(e) => {
|
onKeyDown={(e) => {
|
||||||
|
|
@ -98,9 +104,9 @@ export const EdTreeName = ({
|
||||||
) : (
|
) : (
|
||||||
<div className="flex flex-col">
|
<div className="flex flex-col">
|
||||||
<Name name={node.text} is_jsx_prop={is_jsx_prop} />
|
<Name name={node.text} 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> */}
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -45,12 +45,14 @@ export const nodeOnDrop: (
|
||||||
toChilds.insert(relativeIndex, [map]);
|
toChilds.insert(relativeIndex, [map]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fromMeta?.jsx_prop?.is_root) {
|
||||||
from.parent.forEach((e, idx) => {
|
from.parent.forEach((e, idx) => {
|
||||||
if (from && e.get("id") === from.get("id")) {
|
if (from && !!e && !!e.get && e.get("id") === from.get("id")) {
|
||||||
from.parent.delete(idx);
|
from.parent.delete(idx);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
treeRebuild(p);
|
treeRebuild(p);
|
||||||
p.render();
|
p.render();
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue