@maxgraph/core
    Preparing search index...

    Class Clipboard

    Singleton that implements a clipboard for graph cells.

    To copy the selection cells from the graph to the clipboard and paste them into graph2, do the following:

    Clipboard.copy(graph);
    Clipboard.paste(graph2);

    For fine-grained control of the clipboard data the AbstractGraph.canExportCell and AbstractGraph.canImportCell functions can be overridden.

    To restore previous parents for pasted cells, the implementation for copy and paste can be changed as follows.

    Clipboard.copy = function(graph: Graph, cells: Cell[]): void {
    cells = cells ?? graph.getSelectionCells();
    const result = graph.getExportableCells(cells);

    Clipboard.parents = new Object();
    for (let i = 0; i < result.length; i++) {
    Clipboard.parents[i] = graph.model.getParent(cells[i]);
    }

    Clipboard.insertCount = 1;
    Clipboard.setCells(graph.cloneCells(result));

    return result;
    };

    Clipboard.paste = function(graph: Graph): void {
    if (Clipboard.isEmpty()) {
    return;
    }
    const cells = graph.getImportableCells(Clipboard.getCells());
    const delta = Clipboard.insertCount * Clipboard.STEPSIZE;
    const parent = graph.getDefaultParent();

    graph.model.beginUpdate();
    try {
    for (let i = 0; i < cells.length; i++) {
    const tmp = (Clipboard.parents && graph.model.contains(Clipboard.parents[i])) ?
    Clipboard.parents[i] : parent;
    cells[i] = graph.importCells([cells[i]], delta, delta, tmp)[0];
    }
    }
    finally {
    graph.model.endUpdate();
    }

    // Increments the counter and selects the inserted cells
    Clipboard.insertCount++;
    graph.setSelectionCells(cells);
    };
    Index

    Constructors

    Properties

    cells: Cell[]

    Holds the array of Cell currently in the clipboard.

    insertCount: number = 1

    Counts the number of times the clipboard data has been inserted.

    STEPSIZE: number = 10

    Defines the step size to offset the cells after each paste operation.

    10
    

    Methods

    • Returns true if the clipboard currently has no data stored.

      Returns boolean