Added duplicate function on menu
This commit is contained in:
parent
bb62ea25bd
commit
71cc9092f8
3 changed files with 44 additions and 15 deletions
|
|
@ -41,7 +41,7 @@ const TabsContextInitialValue: TabsContextType = {
|
||||||
getNodeId: () => "",
|
getNodeId: () => "",
|
||||||
paste: (
|
paste: (
|
||||||
selection: { nodes: any; edges: any },
|
selection: { nodes: any; edges: any },
|
||||||
position: { x: number; y: number }
|
position: { x: number; y: number; paneX?: number; paneY?: number }
|
||||||
) => {},
|
) => {},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -221,7 +221,10 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
* @param flow Optional flow to add.
|
* @param flow Optional flow to add.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function paste(selectionInstance, position) {
|
function paste(
|
||||||
|
selectionInstance,
|
||||||
|
position: { x: number; y: number; paneX?: number; paneY?: number }
|
||||||
|
) {
|
||||||
let minimumX = Infinity;
|
let minimumX = Infinity;
|
||||||
let minimumY = Infinity;
|
let minimumY = Infinity;
|
||||||
let idsMap = {};
|
let idsMap = {};
|
||||||
|
|
@ -236,7 +239,9 @@ export function TabsProvider({ children }: { children: ReactNode }) {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
const insidePosition = reactFlowInstance.project(position);
|
const insidePosition = position.paneX
|
||||||
|
? { x: position.paneX + position.x, y: position.paneY + position.y }
|
||||||
|
: reactFlowInstance.project({ x: position.x, y: position.y });
|
||||||
|
|
||||||
selectionInstance.nodes.forEach((n) => {
|
selectionInstance.nodes.forEach((n) => {
|
||||||
// Generate a unique node ID
|
// Generate a unique node ID
|
||||||
|
|
|
||||||
|
|
@ -7,6 +7,7 @@ import {
|
||||||
PencilSquareIcon,
|
PencilSquareIcon,
|
||||||
DocumentDuplicateIcon,
|
DocumentDuplicateIcon,
|
||||||
DocumentPlusIcon,
|
DocumentPlusIcon,
|
||||||
|
Square2StackIcon,
|
||||||
} from "@heroicons/react/24/outline";
|
} from "@heroicons/react/24/outline";
|
||||||
import { classNames } from "../../../../utils";
|
import { classNames } from "../../../../utils";
|
||||||
import { Fragment } from "react";
|
import { Fragment } from "react";
|
||||||
|
|
@ -15,7 +16,7 @@ import { TabsContext } from "../../../../contexts/tabsContext";
|
||||||
import { useReactFlow } from "reactflow";
|
import { useReactFlow } from "reactflow";
|
||||||
|
|
||||||
const NodeToolbarComponent = (props) => {
|
const NodeToolbarComponent = (props) => {
|
||||||
const { setLastCopiedSelection } = useContext(TabsContext);
|
const { setLastCopiedSelection, paste } = useContext(TabsContext);
|
||||||
const reactFlowInstance = useReactFlow();
|
const reactFlowInstance = useReactFlow();
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
|
|
@ -78,7 +79,7 @@ const NodeToolbarComponent = (props) => {
|
||||||
});
|
});
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DocumentDuplicateIcon className="w-5 h-5 dark:text-gray-300"></DocumentDuplicateIcon>
|
<Square2StackIcon className="w-5 h-5 dark:text-gray-300"></Square2StackIcon>
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
<Menu as="div" className="relative inline-block text-left z-100">
|
<Menu as="div" className="relative inline-block text-left z-100">
|
||||||
|
|
@ -105,13 +106,15 @@ const NodeToolbarComponent = (props) => {
|
||||||
<div className="py-1">
|
<div className="py-1">
|
||||||
<Menu.Item>
|
<Menu.Item>
|
||||||
{({ active }) => (
|
{({ active }) => (
|
||||||
<a
|
<button
|
||||||
href="#"
|
onClick={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
}}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
active
|
active
|
||||||
? "bg-gray-100 text-gray-900"
|
? "bg-gray-100 text-gray-900"
|
||||||
: "text-gray-700",
|
: "text-gray-700",
|
||||||
"group flex items-center px-4 py-2 text-sm"
|
"w-full group flex items-center px-4 py-2 text-sm"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<PencilSquareIcon
|
<PencilSquareIcon
|
||||||
|
|
@ -119,26 +122,47 @@ const NodeToolbarComponent = (props) => {
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
Edit
|
Edit
|
||||||
</a>
|
</button>
|
||||||
)}
|
)}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
<Menu.Item>
|
<Menu.Item>
|
||||||
{({ active }) => (
|
{({ active }) => (
|
||||||
<a
|
<button
|
||||||
href="#"
|
onClick={(event) => {
|
||||||
|
event.preventDefault();
|
||||||
|
console.log(
|
||||||
|
reactFlowInstance.getNode(props.data.id)
|
||||||
|
);
|
||||||
|
paste(
|
||||||
|
{
|
||||||
|
nodes: [
|
||||||
|
reactFlowInstance.getNode(props.data.id),
|
||||||
|
],
|
||||||
|
edges: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
x: 50,
|
||||||
|
y: 10,
|
||||||
|
paneX: reactFlowInstance.getNode(props.data.id)
|
||||||
|
.position.x,
|
||||||
|
paneY: reactFlowInstance.getNode(props.data.id)
|
||||||
|
.position.y,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
}}
|
||||||
className={classNames(
|
className={classNames(
|
||||||
active
|
active
|
||||||
? "bg-gray-100 text-gray-900"
|
? "bg-gray-100 text-gray-900"
|
||||||
: "text-gray-700",
|
: "text-gray-700",
|
||||||
"group flex items-center px-4 py-2 text-sm"
|
"w-full group flex items-center px-4 py-2 text-sm"
|
||||||
)}
|
)}
|
||||||
>
|
>
|
||||||
<DocumentPlusIcon
|
<DocumentDuplicateIcon
|
||||||
className="mr-3 h-5 w-5 text-gray-400 group-hover:text-gray-500"
|
className="mr-3 h-5 w-5 text-gray-400 group-hover:text-gray-500"
|
||||||
aria-hidden="true"
|
aria-hidden="true"
|
||||||
/>
|
/>
|
||||||
Duplicate
|
Duplicate
|
||||||
</a>
|
</button>
|
||||||
)}
|
)}
|
||||||
</Menu.Item>
|
</Menu.Item>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -18,7 +18,7 @@ export type TabsContextType = {
|
||||||
getNodeId: () => string;
|
getNodeId: () => string;
|
||||||
paste: (
|
paste: (
|
||||||
selection: { nodes: any; edges: any },
|
selection: { nodes: any; edges: any },
|
||||||
position: { x: number; y: number }
|
position: { x: number; y: number; paneX?: number; paneY?: number }
|
||||||
) => void;
|
) => void;
|
||||||
lastCopiedSelection: { nodes: any; edges: any };
|
lastCopiedSelection: { nodes: any; edges: any };
|
||||||
setLastCopiedSelection: (selection: { nodes: any; edges: any }) => void;
|
setLastCopiedSelection: (selection: { nodes: any; edges: any }) => void;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue