accept drop from explore file or node
This commit is contained in:
1 parent
0ff92fe429
commit
f8d04581d1
4 files changed
+45
-3
No files matched your search
@@ -632,9 +632,9 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
});
|
});
|
||||||
|
|
||||||
editor.graph.on("node:drop", (e: G6GraphEvent) => {
|
editor.graph.on("node:drop", (e: G6GraphEvent) => {
|
||||||
const srcNodeId = editor.dragSrcId;
|
|
||||||
const dstNode = e.item;
|
const dstNode = e.item;
|
||||||
|
|
||||||
|
let srcNodeId = editor.dragSrcId;
|
||||||
let dragDir;
|
let dragDir;
|
||||||
if (dstNode.hasState("dragRight")) {
|
if (dstNode.hasState("dragRight")) {
|
||||||
dragDir = "dragRight";
|
dragDir = "dragRight";
|
||||||
@@ -647,6 +647,39 @@ export const Editor: FC<EditorProps> = ({ onUpdate: updateState, data: editor, .
|
|||||||
clearDragSrcState();
|
clearDragSrcState();
|
||||||
clearDragDstState();
|
clearDragDstState();
|
||||||
|
|
||||||
|
if (e.originalEvent instanceof DragEvent) {
|
||||||
|
const dragEvent = e.originalEvent as DragEvent;
|
||||||
|
const exploreFile = dragEvent.dataTransfer?.getData("explore-file");
|
||||||
|
const exploreNode = dragEvent.dataTransfer?.getData("explore-node");
|
||||||
|
const dstData = findDataById(dstNode.getID());
|
||||||
|
|
||||||
|
if (exploreNode) {
|
||||||
|
const newTreeData: TreeGraphData = b3util.createTreeData(
|
||||||
|
{
|
||||||
|
id: editor.autoId++,
|
||||||
|
name: exploreNode,
|
||||||
|
},
|
||||||
|
dstData.id
|
||||||
|
);
|
||||||
|
dstData.children ||= [];
|
||||||
|
dstData.children.push(newTreeData);
|
||||||
|
srcNodeId = newTreeData.id;
|
||||||
|
} else if (exploreFile && exploreFile !== editor.path) {
|
||||||
|
const newTreeData: TreeGraphData = b3util.createTreeData(
|
||||||
|
{
|
||||||
|
id: editor.autoId++,
|
||||||
|
name: "unknow",
|
||||||
|
path: Path.relative(workspace.workdir, exploreFile).replaceAll(Path.sep, "/"),
|
||||||
|
},
|
||||||
|
dstData.id
|
||||||
|
);
|
||||||
|
dstData.children ||= [];
|
||||||
|
dstData.children.push(newTreeData);
|
||||||
|
srcNodeId = newTreeData.id;
|
||||||
|
editor.autoId = b3util.refreshTreeDataId(newTreeData, Number(srcNodeId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (!srcNodeId) {
|
if (!srcNodeId) {
|
||||||
console.log("no drag src");
|
console.log("no drag src");
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -147,7 +147,7 @@ export const Explorer: FC = () => {
|
|||||||
<Flex justify="center" align="center" style={{ height: "100%" }}>
|
<Flex justify="center" align="center" style={{ height: "100%" }}>
|
||||||
<img
|
<img
|
||||||
className="b3-node-icon"
|
className="b3-node-icon"
|
||||||
style={{ width: "14px", height: "14px", color: "white" }}
|
style={{ width: "13px", height: "13px", color: "white" }}
|
||||||
src={`./icons/${catalog.title}.svg`}
|
src={`./icons/${catalog.title}.svg`}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
@@ -696,6 +696,7 @@ export const Explorer: FC = () => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<Flex
|
<Flex
|
||||||
|
className="b3-explorer"
|
||||||
vertical
|
vertical
|
||||||
ref={keysRef}
|
ref={keysRef}
|
||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
@@ -781,6 +782,9 @@ export const Explorer: FC = () => {
|
|||||||
allowDrop={(options) => {
|
allowDrop={(options) => {
|
||||||
return !options.dropNode.isLeaf;
|
return !options.dropNode.isLeaf;
|
||||||
}}
|
}}
|
||||||
|
onDragStart={(e) => {
|
||||||
|
e.event.dataTransfer.setData("explore-file", e.node.path);
|
||||||
|
}}
|
||||||
defaultExpandedKeys={[workspace.fileTree.path]}
|
defaultExpandedKeys={[workspace.fileTree.path]}
|
||||||
draggable={newName !== null ? false : { icon: false }}
|
draggable={newName !== null ? false : { icon: false }}
|
||||||
expandedKeys={expandedKeys}
|
expandedKeys={expandedKeys}
|
||||||
@@ -793,6 +797,10 @@ export const Explorer: FC = () => {
|
|||||||
tabIndex={-1}
|
tabIndex={-1}
|
||||||
fieldNames={{ key: "title" }}
|
fieldNames={{ key: "title" }}
|
||||||
treeData={workspace.nodeTree ? [workspace.nodeTree] : []}
|
treeData={workspace.nodeTree ? [workspace.nodeTree] : []}
|
||||||
|
draggable={{ icon: false, nodeDraggable: (node) => !!node.isLeaf }}
|
||||||
|
onDragStart={(e) => {
|
||||||
|
e.event.dataTransfer.setData("explore-node", e.node.def?.name ?? "");
|
||||||
|
}}
|
||||||
switcherIcon={<DownOutlined />}
|
switcherIcon={<DownOutlined />}
|
||||||
/>
|
/>
|
||||||
</Flex>
|
</Flex>
|
||||||
|
|||||||
@@ -271,7 +271,6 @@ export const Menu: FC<LayoutProps> = () => {
|
|||||||
{
|
{
|
||||||
id: "menu.view.zoomIn",
|
id: "menu.view.zoomIn",
|
||||||
label: t("zoomIn"),
|
label: t("zoomIn"),
|
||||||
role: "zoomIn",
|
|
||||||
click: () => {
|
click: () => {
|
||||||
const webContents = getFocusedWebContents();
|
const webContents = getFocusedWebContents();
|
||||||
if (webContents) {
|
if (webContents) {
|
||||||
|
|||||||
@@ -310,6 +310,8 @@ export const createTreeData = (node: NodeModel, parent?: string) => {
|
|||||||
treeData.lastModified = fs.statSync(subtreePath).mtimeMs;
|
treeData.lastModified = fs.statSync(subtreePath).mtimeMs;
|
||||||
treeData.path = node.path;
|
treeData.path = node.path;
|
||||||
treeData.debug = node.debug;
|
treeData.debug = node.debug;
|
||||||
|
treeData.parent = parent;
|
||||||
|
treeData.id = node.id.toFixed();
|
||||||
treeData.size = calcTreeDataSize(treeData);
|
treeData.size = calcTreeDataSize(treeData);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
message.error(`解析子树失败:${node.path}`);
|
message.error(`解析子树失败:${node.path}`);
|
||||||
|
|||||||
Reference in new issue
Block a user