--- package/package.json (excerpt) ---
{
"name": "@antv/x6-plugin-clipboard",
"version": "2.1.6",
"description": "clipboard plugin for X6",
"main": "lib/index.js",
"module": "es/index.js",
"unpkg": "dist/index.js",
"jsdelivr": "dist/index.js",
"types": "lib/index.d.ts",
"files": [
"dist",
"es",
"lib",
"src"
],
"keywords": [
"plugin",
"clipboard",
"x6",
"antv"
],
"peerDependencies": {
"@antv/x6": "^2.x"
},
"devDependencies": {
"@antv/x6": "^2.x"
},
"author": {
"name": "bubkoo",
"email": "bubkoo.wy@gmail.com"
},
"license": "MIT",
"homepage": "https://x6.antv.antgroup.com/tutorial/plugins/clipboard",
"bugs": {
"url": "https://github.com/antvis/x6/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/antvis/x6.git",
"directory": "packages/x6-plugin-clipboard"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"scripts": {
"clean:turbo": "rss",
"clean:build": "rss",
"clean:coverage": "rss",
"clean": "rss",
"build:esm": "rss",
"build:cjs": "rss",
"build:umd": "rss",
"build:dev": "rss",
"build:watch": "rss",
"build:watch:esm": "rss",
"build:watch:cjs": "rss",
"build": "rss",
"prebuild": "rss",
"test": "rss",
"coveralls": "rss",
"pretest": "rss"
}
}
--- package/src/api.ts (excerpt) ---
import { Graph, Cell } from '@antv/x6'
import { Clipboard } from './index'
declare module '@antv/x6/lib/graph/graph' {
interface Graph {
isClipboardEnabled: () => boolean
enableClipboard: () => Graph
disableClipboard: () => Graph
toggleClipboard: (enabled?: boolean) => Graph
isClipboardEmpty: (options?: Clipboard.Options) => boolean
getCellsInClipboard: () => Cell[]
cleanClipboard: () => Graph
copy: (cells: Cell[], options?: Clipboard.CopyOptions) => Graph
cut: (cells: Cell[], options?: Clipboard.CopyOptions) => Graph
paste: (options?: Clipboard.PasteOptions, graph?: Graph) => Cell[]
}
}
declare module '@antv/x6/lib/graph/events' {
interface EventArgs {
'clipboard:changed': { cells: Cell[] }
}
}
Graph.prototype.isClipboardEnabled = function () {
const clipboard = this.getPlugin('clipboard') as Clipboard
if (clipboard) {
return clipboard.isEnabled()
}
return false
}
Graph.prototype.enableClipboard = function () {
const clipboard = this.getPlugin('clipboard') as Clipboard
if (clipboard) {
clipboard.enable()
}
return this
}
Graph.prototype.disableClipboard = function () {
const clipboard = this.getPlugin('clipboard') as Clipboard
if (clipboard) {
clipboard.disable()
}
return this
}
Graph.prototype.toggleClipboard = function (enabled?: boolean) {
const clipboard = this.getPlugin('clipboard') as Clipboard
if (clipboard) {
clipboard.toggleEnabled(enabled)
}
return this
}
Grap
--- package/src/clipboard.ts (excerpt) ---
import { Config, Graph, Cell, Node, Edge, Model, ArrayExt } from '@antv/x6'
export class ClipboardImpl {
protected options: ClipboardImpl.Options
public cells: Cell[] = []
copy(
cells: Cell[],
graph: Graph | Model,
options: ClipboardImpl.CopyOptions = {},
) {
this.options = { ...options }
const model = Model.isModel(graph) ? graph : graph.model
const cloned = model.cloneSubGraph(cells, options)
// sort asc by cell type
this.cells = ArrayExt.sortBy(
Object.keys(cloned).map((key) => cloned[key]),
(cell) => (cell.isEdge() ? 2 : 1),
)
this.serialize(options)
}
cut(
cells: Cell[],
graph: Graph | Model,
options: ClipboardImpl.CopyOptions = {},
) {
this.copy(cells, graph, options)
const model = Graph.isGraph(graph) ? graph.model : graph
model.batchUpdate('cut', () => {
cells.forEach((cell) => cell.remove())
})
}
paste(graph: Graph | Model, options: ClipboardImpl.PasteOptions = {}) {
const localOptions = { ...this.options, ...options }
const { offset, edgeProps, nodeProps } = localOptions
let dx = 20
let dy = 20
if (offset) {
dx = typeof offset === 'number' ? offset : offset.dx
dy = typeof offset === 'number' ? offset : offset.dy
}
this.deserialize(localOptions)
const cells = this.cells
cells.forEach((cell) => {
cell.model = null
cell.removeProp('zIndex')
if (dx || dy) {
cell.translate(dx, dy)
--- bundled output (OSV-MAL flagged — LLM scope expansion) ---
--- dist/index.js (bundled) ---
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/x6")):"function"==typeof define&&define.amd?define(["exports","@antv/x6"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).X6PluginClipboard={},t.X6)}(this,(function(t,e){"use strict";class i{constructor(){this.cells=[]}copy(t,i,s={}){this.options=Object.assign({},s);const o=(e.Model.isModel(i)?i:i.model).cloneSubGraph(t,s);this.cells=e.ArrayExt.sortBy(Object.keys(o).map((t=>o[t])),(t=>t.isEdge()?2:1)),this.serialize(s)}cut(t,i,s={}){this.copy(t,i,s);(e.Graph.isGraph(i)?i.model:i).batchUpdate("cut",(()=>{t.forEach((t=>t.remove()))}))}paste(t,i={}){const s=Object.assign(Object.assign({},this.options),i),{offset:o,edgeProps:n,nodeProps:l}=s;let r=20,a=20;o&&(r="number"==typeof o?o:o.dx,a="number"==typeof o?o:o.dy),this.deserialize(s);const c=this.cells;c.forEach((t=>{t.model=null,t.removeProp("zIndex"),(r||a)&&t.translate(r,a),l&&t.isNode()&&t.prop(l),n&&t.isEdge()&&t.prop(n)}));const p=e.Graph.isGraph(t)?t.model:t;return p.batchUpdate("paste",(()=>{p.addCells(this.cells)})),this.copy(c,t,i),c}serialize(t){!1!==t.useLocalStorage&&s.save(this.cells)}deserialize(t){if(t.useLocalStorage){const t=s.fetch();t&&(this.cells=t)}}isEmpty(t={}){return t.useLocalStorage&&this.deserialize(t),this.cells.length<=0}clean(){this.options={},this.cells=[],s.clean()}}var s;!function(t){const i=`${e.Config.prefixCls}.clipboard.cells`;t.save=function(t){if(window.localStorage){const e=t.map((t=>t.toJSON()));localStorage.setItem(i,JSON.stringify(e))}},t.fetch=function(){if(window.localStorage){const t=localStorage.getItem(i),s=t?JSON.parse(t):[];if(s)return e.Model.fromJSON(s)}},t.clean=function(){window.localStorage&&localStorage.removeItem(i)}}(s||(s={})),e.Graph.prototype.isClipboardEnabled=function(){const t=this.getPlugin("clipboard");return!!t&&t.isEnabled()},e.Graph.prototype.enableClipboard=function(){const t=this.getPlugin("clipboard");return t&&t.enable(),this},e.Graph.prototype{
"name": "@antv/x6-plugin-clipboard",
"version": "2.1.6",
"description": "clipboard plugin for X6",
"main": "lib/index.js",
"module": "es/index.js",
"unpkg": "dist/index.js",
"jsdelivr": "dist/index.js",
"types": "lib/index.d.ts",
"files": [
"dist",
"es",
"lib",
"src"
],
"keywords": [
"plugin",
"clipboard",
"x6",
"antv"
],
"peerDependencies": {
"@antv/x6": "^2.x"
},
"devDependencies": {
"@antv/x6": "^2.x"
},
"author": {
"name": "bubkoo",
"email": "bubkoo.wy@gmail.com"
},
"license": "MIT",
"homepage": "https://x6.antv.antgroup.com/tutorial/plugins/clipboard",
"bugs": {
"url": "https://github.com/antvis/x6/issues"
},
"repository": {
"type": "git",
"url": "https://github.com/antvis/x6.git",
"directory": "packages/x6-plugin-clipboard"
},
"publishConfig": {
"access": "public",
"registry": "https://registry.npmjs.org"
},
"scripts": {
"clean:turbo": "rss",
"clean:build": "rss",
"clean:coverage": "rss",
"clean": "rss",
"build:esm": "rss",
"build:cjs": "rss",
"build:umd": "rss",
"build:dev": "rss",
"build:watch": "rss",
"build:watch:esm": "rss",
"build:watch:cjs": "rss",
"build": "rss",
"prebuild": "rss",
"test": "rss",
"coveralls": "rss",
"pretest": "rss"
}
}
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@antv/x6")):"function"==typeof define&&define.amd?define(["exports","@antv/x6"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).X6PluginClipboard={},t.X6)}(this,(function(t,e){"use strict";class i{constructor(){this.cells=[]}copy(t,i,s={}){this.options=Object.assign({},s);const o=(e.Model.isModel(i)?i:i.model).cloneSubGraph(t,s);this.cells=e.ArrayExt.sortBy(Object.keys(o).map((t=>o[t])),(t=>t.isEdge()?2:1)),this.serialize(s)}cut(t,i,s={}){this.copy(t,i,s);(e.Graph.isGraph(i)?i.model:i).batchUpdate("cut",(()=>{t.forEach((t=>t.remove()))}))}paste(t,i={}){const s=Object.assign(Object.assign({},this.options),i),{offset:o,edgeProps:n,nodeProps:l}=s;let r=20,a=20;o&&(r="number"==typeof o?o:o.dx,a="number"==typeof o?o:o.dy),this.deserialize(s);const c=this.cells;c.forEach((t=>{t.model=null,t.removeProp("zIndex"),(r||a)&&t.translate(r,a),l&&t.isNode()&&t.prop(l),n&&t.isEdge()&&t.prop(n)}));const p=e.Graph.isGraph(t)?t.model:t;return p.batchUpdate("paste",(()=>{p.addCells(this.cells)})),this.copy(c,t,i),c}serialize(t){!1!==t.useLocalStorage&&s.save(this.cells)}deserialize(t){if(t.useLocalStorage){const t=s.fetch();t&&(this.cells=t)}}isEmpty(t={}){return t.useLocalStorage&&this.deserialize(t),this.cells.length<=0}clean(){this.options={},this.cells=[],s.clean()}}var s;!function(t){const i=`${e.Config.prefixCls}.clipboard.cells`;t.save=function(t){if(window.localStorage){const e=t.map((t=>t.toJSON()));localStorage.setItem(i,JSON.stringify(e))}},t.fetch=function(){if(window.localStorage){const t=localStorage.getItem(i),s=t?JSON.parse(t):[];if(s)return e.Model.fromJSON(s)}},t.clean=function(){window.localStorage&&localStorage.removeItem(i)}}(s||(s={})),e.Graph.prototype.isClipboardEnabled=function(){const t=this.getPlugin("clipboard");return!!t&&t.isEnabled()},e.Graph.prototype.enableClipboard=function(){const t=this.getPlugin("clipboard");return t&&t.enable(),this},e.Graph.prototype