Articles in this section

How to Perform Clipboard Operation Context Menu in Vue Diagram?

This article explains how to perform clipboard operations using the context menu in the Vue Diagram. In Syncfusion® Vue Diagram, enable the context menu by setting the show property of the contextMenuSettings to true. To display only the custom context menu, set showCustomMenuOnly to true. When a user clicks on an item in the context menu associated with a diagram node or connector, the contextMenuClick event is triggered.

To implement cut, copy, and paste functionality for multiple nodes using the context menu, follow these steps:

Cut Functionality

• When the “Cut” option is clicked in the context menu, create an empty array, and push the selected nodes into the array.
• Remove the nodes from the diagram.

<ejs-diagram
         ref="diagramObject"
         id="diagram"
         :width="width"
         :height="height"
         :nodes="nodes"
         :contextMenuSettings="contextMenuSettings"
         :contextMenuClick="contextMenuClick"
></ejs-diagram>
// Cut functionality
if (args.item.id == 'cut') {
 if (diagram.selectedItems.nodes && diagram.selectedItems.nodes.length > 0) {
   copyNode = [];
   for (let i = 0; i < diagram.selectedItems.nodes.length; i++) {
     copyNode.push(diagram.selectedItems.nodes[i]);
     diagram.remove(diagram.selectedItems.nodes[i]);
   }
 }
} 

Copy Functionality

When the “Copy” option is clicked in the context menu, create an empty array, and push the selected nodes into the array.

// Copy functionality

if (args.item.id == 'copy') {
 if (diagram.selectedItems.nodes && diagram.selectedItems.nodes.length > 0) {
   copyNode = [];
   for (let i = 0; i < diagram.selectedItems.nodes.length; i++) {
     copyNode.push(diagram.selectedItems.nodes[i]);
   }
 }
}
Paste Functionality

• When the “Paste” option is clicked in the context menu, retrieve the copied nodes from the array.
• Iterate over the copied nodes and create new nodes based on the copied node’s properties.
• Adjust the offsetX and offsetY properties of the new nodes based on the mouse position to paste them at the desired location.
• Add the newly created nodes to the diagram.

// Paste functionality
if (args.item.id == 'paste') {
     for (let i = 0; i < copyNode.length; i++) {
      args.cancel=true;
       let pasteNode = [
         {
           id: randomId() + i,
           width: copyNode[i].width,
           height: copyNode[i].height,
           shape: copyNode[i].shape,
           offsetX: args.event.pageX,
           offsetY: args.event.pageY,
         },
       ];
       if (i > 0) {
         pasteNode[0].offsetX =
           args.event.pageX + (copyNode[i].offsetX - copyNode[0].offsetX);
         pasteNode[0].offsetY =
           args.event.pageY + (copyNode[i].offsetY - copyNode[0].offsetY);
       }
       diagram.add(pasteNode[0]);
     }
   }

Refer to the working sample for additional details and implementation: Sample

Conclusion

We hope you enjoyed learning how to perform clipboard operations using the context menu in Vue Diagram.

You can refer to our Vue Diagram feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications. You can also explore our Vue Diagram example to understand how to create and manipulate data.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, BoldDesk Support, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied