logo

X6

  • Tutorials
  • API
  • Examples
  • Q&A
  • Change Log
  • XFlow
  • Productsantv logo arrow
  • 2.x
  • Introduction
  • Quickstart
  • Basic
    • Graph
    • Nodes
    • Edges
    • Connection Pile
    • Interaction
    • Events
    • Data Serialization
  • Intermediate
    • Connection Points
    • Tools
    • Group
    • React Nodes
    • Vue Nodes
    • Angular Nodes
    • HTML Nodes
  • Plugin
    • Graphic Transformations
    • Snapline
    • Clipboard
    • Keyboard
    • History
    • Selection Box
    • Scroller
    • Dnd
    • Mini Map
    • Stencil
    • Export
  • Upgrade to Version 2.x
  • Developer Tools

Clipboard

Previous
Snapline
Next
Keyboard

Resource

Ant Design
Galacea Effects
Umi-React Application Framework
Dumi-Component doc generator
ahooks-React Hooks Library

Community

Ant Financial Experience Tech
seeconfSEE Conf-Experience Tech Conference

Help

GitHub
StackOverflow

more productsMore Productions

Ant DesignAnt Design-Enterprise UI design language
yuqueYuque-Knowledge creation and Sharing tool
EggEgg-Enterprise-class Node development framework
kitchenKitchen-Sketch Tool set
GalaceanGalacean-Interactive solution
xtechLiven Experience technology
© Copyright 2025 Ant Group Co., Ltd..备案号:京ICP备15032932号-38

Loading...

This chapter mainly introduces knowledge related to the clipboard. By reading, you can learn about

  • How to use the copy and paste function

Usage

The clipboard is used for copying/pasting nodes and edges. We provide a standalone plugin package @antv/x6-plugin-clipboard to utilize this feature.

# npm
$ npm install @antv/x6-plugin-clipboard --save
# yarn
$ yarn add @antv/x6-plugin-clipboard

Then we use it in the code like this:

import { Clipboard } from '@antv/x6-plugin-clipboard'
const graph = new Graph({
background: {
color: '#F2F7FA',
},
})
graph.use(
new Clipboard({
enabled: true,
}),
)

Demo

  • After selecting a node, click the copy button to copy the node.
  • Set different offset values to observe the effect on the node's position when pasting.
  • After enabling localStorage, copy a node, refresh the page or reopen the browser, then click the paste button.

Configuration

Property NameTypeDefault ValueRequiredDescription
useLocalStoragebooleanfalseWhen enabled, the copied nodes/edges are also saved to localStorage, allowing copy/paste to work after refreshing or reopening the browser.

API

graph.copy(...)

copy(cells: Cell[], options: CopyOptions = {}): this

Copy nodes/edges. Parameters are as follows:

NameTypeRequiredDefault ValueDescription
cellsCell[]✓The nodes/edges to be copied.
options.deepboolean-Whether to recursively copy all child nodes/edges.
options.useLocalStorageboolean-Whether to save the copied nodes/edges in localStorage.

graph.cut(...)

cut(cells: Cell[], options: CopyOptions = {}): this

Cut nodes/edges. Parameters are as follows:

NameTypeRequiredDefault ValueDescription
cellsCell[]✓The nodes/edges to be cut.
options.deepboolean-Whether to recursively copy all child nodes/edges.
options.useLocalStorageboolean-Whether to save the copied nodes/edges in localStorage.

graph.paste(...)

paste(options?: PasteOptions, graph?: Graph): Cell[]

Paste and return the nodes/edges pasted onto the canvas. Parameters are as follows:

NameTypeRequiredDefault ValueDescription
options.useLocalStorageboolean-Whether to use nodes/edges from localStorage.
options.offsetnumber | { dx: number; dy: number }20The offset for the nodes/edges pasted onto the canvas.
options.nodePropsNode.Properties-Additional properties for the nodes pasted onto the canvas.
options.edgePropsEdge.Properties-Additional properties for the edges pasted onto the canvas.
graphGraphthisThe target canvas for pasting, defaults to the current canvas.

graph.getCellsInClipboard()

getCellsInClipboard: Cell[]

Get the nodes/edges in the clipboard.

graph.cleanClipboard()

cleanClipboard(): this

Clear the clipboard.

graph.isClipboardEmpty()

isClipboardEmpty(): boolean

Return whether the clipboard is empty.

graph.isClipboardEnabled()

isClipboardEnabled(): boolean

Return whether the clipboard is enabled.

graph.enableClipboard()

enableClipboard(): this

Enable the clipboard.

graph.disableClipboard()

disableClipboard(): this

Disable the clipboard.

graph.toggleClipboard(...)

toggleClipboard(enabled?: boolean): this

Toggle the clipboard's enabled state. Parameters are as follows:

NameTypeRequiredDefault ValueDescription
enabledboolean-Whether to enable the clipboard; defaults to toggling the clipboard's enabled state.

Events

Event NameParameter TypeDescription
clipboard:changed{ cells: Cell[] }Triggered when copying, cutting, or clearing the clipboard.
graph.on('clipboard:changed', ({ cells }) => {
console.log(cells)
})
// We can also listen to events on the plugin instance
clipboard.on('clipboard:changed', ({ cells }) => {
console.log(cells)
})
Clipboard Settings
Paste Offset
30