How to get node list when commandHandler.pasteSelection invoked?

Hi, I want to know node list (more precisely, node’s key) when commandHandler.pasteSelection() is invoked.

After some research, adding “clipboardChanged” event handler to diagram could be solution, and I wrote following TypeScript code, but node.key has no value (undefined).
What’s wrong with my code? and how to fix it?

            diagram.addDiagramListener("ClipboardChanged", function (e) {
                let copiedParts = e.subject; // go.Set object
                let copiedNodes: string[] = [];  // list of node's key

                copiedParts.each(function (part: any) {
                    if (part instanceof go.Node) {
                        const node = part as go.Node;
                        console.log(node.key);   // this line prints "undefined".
                        if (node.key) {
                            copiedNodes.push(node.key.toString());
                        }
                    }
                });
                console.log(copiedNodes);

Thanks in advance.

Are you trying to find out what is in the clipboard? The DiagramEvent.subject will be either null or a List of Parts that were copied into the internal clipboard that the CommandHandler maintains.

Those newly copied Parts are not supposed to have unique keys, because they do not belong to a Diagram and their Part.data do not belong to a Model.

When a paste happens, they will be copied again. Note that when the paste copies the Parts into the Diagram and there is Part.data, it’s actually just the data that will be copied into the Model.

Or are you trying to find out what Parts in the Diagram were copied? For that, just look at the Diagram.selection. Although the actual collection of Parts that were copied might be larger due to including the members of a selected Group or the children of a Node if CommandHandler.copiesTree is true.

Or are you trying to find out what Parts in the Diagram were copied? For that, just look at the Diagram.selection

yes. I want to do this.

What we want to do is following (for example):

scr1

(1) select A, C
(2) copy (Press Ctrl-C)
(3) paste (Press Ctrl-V)
then A’, C’ will be created (copied) by GoJS.

When doing (3), we need to do additional data manipulation. in order to do that, we need to know which nodes were copied. (=A, C)

(remark) sometimes A, C could be deselected, after doing (2) and before doing (3). so I’m afraid that Diagram.selection could not be enough to know which nodes are copied.

Ah, so you care about the paste, not the copy.

But the sequence could be:
(1) select A, C
(2) copy (Press Ctrl-C)
(3) selectAll (press Ctrl-A)
(4) delete (press Delete)
(5) paste (Press Ctrl-V)
So at the time of the paste the original nodes A and C don’t exist. You can only depend on the information in what was pasted, which will be the Diagram.selection or the DiagramEvent.subject.

Make sure that there is enough information in each node data object so that you can distinguish copies.

Thanks walter.
after doing commandHandler.pasteSelection(),
I can get pasted node key with diagram.selection with following code.

export const pasteNode = (e: go.InputEvent, obj: go.GraphObject): void => {
    e.diagram.commit((d: go.Diagram) => {
        d.commandHandler.pasteSelection(
            e.diagram.toolManager.contextMenuTool.mouseDownPoint,
        );
    });

    console.log('*** pasted nodes ***');

    const selectedObjects = e.diagram.selection;
    selectedObjects.each((obj: any) => {
        if (obj instanceof go.Node) {
            const selectedNode = obj as go.Node;
            console.log(`${selectedNode.key}`);
        }
    });
}

console.log’s output:

*** pasted nodes ***
A'
C'

but I want to know source node key (=A, C), not pasted node key(=A’, C’), when paste has done.

Is there any way to do this?

scr2

Hi, Walter.

I tried to use ClipboardChanged event to get selected node’s key when copied,
and save them to diagram.model.modelData.
then when paste invoked, get source node keys from diagram.model.modelData.

this seems working well so far. I’ll continue along this line.

Thank you for your advice.

diagram.addDiagramListener("ClipboardChanged", function (e) {
    let selectedParts = e.diagram.selection;
    let copiedNodes: string[] = [];

    selectedParts.each(function (part: any) {
        if (part instanceof go.Node) {
            const node = part as go.Node;
            if (node.key) {
                copiedNodes.push(node.key.toString());
            }
        }
    });
    e.diagram.model.modelData = copiedNodes;
});

export const pasteNode = (e: go.InputEvent, obj: go.GraphObject): void => {

    console.log('*** copied nodes ***');
    console.log(`${e.diagram.model.modelData}`);

    e.diagram.commit((d: go.Diagram) => {
        d.commandHandler.pasteSelection(
            e.diagram.toolManager.contextMenuTool.mouseDownPoint,
        );
    });

	// ... doing some work with copied nodes
}

Hi, Walter.

Yesterday I told you I found a solution, but after some investigation the way I took is not good enough.

I need to know the relation between copied (source) node and pasted (new) node.

(in the last figure I pasted, I want to know source node of A’ (that is A), and
source node of C’ (that is C))

so I ask you again, is there any way to get to know that?

I’m surprised that there wasn’t enough information in the node data objects for you to tell which pasted node came from which copied node.

Could you please share with us the node data objects for A and C before the copy, and the node data objects for A’ and C’ after the paste?

I tried ChatGPT for solution, then the reply is following:

myDiagram.addDiagramListener("SelectionCopied", function(e) {
    // Get the information of the copied parts (nodes)
    var copiedParts = e.subject; // Contains the copied parts in a Set object

    // Traverse through the copied parts (nodes) and perform operations
    copiedParts.each(function(part) {
        if (part instanceof go.Node) {
            // `part` represents the copied node

            // Get the original node (the node before it was copied)
            var originalNode = part.data.originalNodeKey
                ? myDiagram.findNodeForKey(part.data.originalNodeKey)
                : null;

            if (originalNode) {
                // Handle the relationship between the copied node and the original node
                console.log("Copied node:", part.key);
                console.log("Original node:", originalNode.key);

                // Perform necessary operations here
            }
        }
    });
});

Seems this code works well, but I pasted this code to my program,
first of all, “SelectionCopied” event is not fired when I paste. (Press Ctrl-V)

Is this code right?

You don’t want to share with us the node data objects for A and C before the copy, and the node data objects for A’ and C’ after the paste? That might be a better way to get what you really want rather than some generated code that wasn’t designed to meet your real requirements and isn’t quite right.

Which version of GoJS are you using?

Oh, I’m sorry. I just thought ChatGPT’s answer could lead to faster solution.

By the way, how to print contents of node data object?

I wrote following code, but JSON.stringyfy() causes error because of recursive reference.

diagram.addDiagramListener("ClipboardChanged", function (e) {
    let selectedParts = e.diagram.selection;
    console.log('*** contents of copied nodes ***');
    console.log(JSON.stringify(selectedParts, null, 2));

scr3

in above scrshot,
(1) I selected node A and C
(2) Press Ctrl-C
this causes following output.
(remark: above scrshot is real application of us. the other day’s was simplified scrshot for explanation)

scr4

so, I commented out JSON.stringify()

diagram.addDiagramListener("ClipboardChanged", function (e) {
    let selectedParts = e.diagram.selection;
    console.log('*** contents of copied nodes ***');
    // console.log(JSON.stringify(selectedParts, null, 2));
    console.log(selectedParts);

scr5

Is this output meaningful?

Which version of GoJS are you using?

We’re using GoJS 2.3.

Just call myDiagram.model.toJson().

In the debugger I suppose you could evaluate something like:

myDiagram.selection.each(part => console.log(part.data))

Thank you for advice.
I fixed my code to show contents of model.data, both when copied, and when pasted.

            diagram.addDiagramListener("ClipboardChanged", function (e) {
                console.log('*** model.data (copy) ***');
                console.log(e.diagram.model.toJson());
export const pasteNode = (e: go.InputEvent, obj: go.GraphObject): void => {
    e.diagram.commit((d: go.Diagram) => {
        d.commandHandler.pasteSelection(
            e.diagram.toolManager.contextMenuTool.mouseDownPoint,
        );
    });

    console.log('*** model.data (paste) ***');
    console.log(e.diagram.model.toJson());

the outputs are following.
(the first is copied data, and the second is pasted data)

*** model.data (copy) ***’

{
    "class": "GraphLinksModel",
    "linkKeyProperty": "key",
    "nodeDataArray": [
        {
            "key": "\u5927\u6c17\u6c5a\u67d3?",
            "label": "\u5927\u6c17\u6c5a\u67d3?",
            "position": "73 43",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u4ef6\u6570\u6bd4\u7387"
                    ]
                },
                {
                    "rowName": "\u4f4e\u3044",
                    "values": [
                        "0.9"
                    ]
                },
                {
                    "rowName": "\u9ad8\u3044",
                    "values": [
                        "0.1"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u4f4e\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u9ad8\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u80ba\u304c\u3093?",
            "label": "\u80ba\u304c\u3093?",
            "position": "148 152",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u306f\u3044,\u4f4e\u3044",
                        "\u306f\u3044,\u9ad8\u3044",
                        "\u3044\u3044\u3048,\u4f4e\u3044",
                        "\u3044\u3044\u3048,\u9ad8\u3044"
                    ]
                },
                {
                    "rowName": "\u306f\u3044",
                    "values": [
                        "0.03",
                        "0.05",
                        "0.001",
                        "0.02"
                    ]
                },
                {
                    "rowName": "\u3044\u3044\u3048",
                    "values": [
                        "0.97",
                        "0.95",
                        "0.999",
                        "0.98"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u306f\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u3044\u3044\u3048",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u55ab\u7159\u8005?",
            "label": "\u55ab\u7159\u8005?",
            "position": "214 42",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u4ef6\u6570\u6bd4\u7387"
                    ]
                },
                {
                    "rowName": "\u306f\u3044",
                    "values": [
                        "0.3"
                    ]
                },
                {
                    "rowName": "\u3044\u3044\u3048",
                    "values": [
                        "0.7"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u306f\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u3044\u3044\u3048",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u30ec\u30f3\u30c8\u30b2\u30f3\u691c\u67fb?",
            "label": "\u30ec\u30f3\u30c8\u30b2\u30f3\u691c\u67fb?",
            "position": "71 242",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u306f\u3044",
                        "\u3044\u3044\u3048"
                    ]
                },
                {
                    "rowName": "\u967d",
                    "values": [
                        "0.9",
                        "0.2"
                    ]
                },
                {
                    "rowName": "\u9670",
                    "values": [
                        "0.1",
                        "0.8"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u967d",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u9670",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u547c\u5438\u56f0\u96e3?",
            "label": "\u547c\u5438\u56f0\u96e3?",
            "position": "221 249",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u306f\u3044",
                        "\u3044\u3044\u3048"
                    ]
                },
                {
                    "rowName": "\u306f\u3044",
                    "values": [
                        "0.65",
                        "0.3"
                    ]
                },
                {
                    "rowName": "\u3044\u3044\u3048",
                    "values": [
                        "0.35",
                        "0.7"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u306f\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u3044\u3044\u3048",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        }
    ],
    "linkDataArray": [
        {
            "from": "\u55ab\u7159\u8005?",
            "to": "\u80ba\u304c\u3093?",
            "style": {
                "fillColor": "rgba(2, 20, 47, 1)",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 5,
                "font": "Bold 12pt Meiryo",
                "fontColor": "rgba(31, 31, 31, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "key": -1
        },
        {
            "from": "\u5927\u6c17\u6c5a\u67d3?",
            "to": "\u80ba\u304c\u3093?",
            "style": {
                "fillColor": "rgba(2, 20, 47, 1)",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 5,
                "font": "Bold 12pt Meiryo",
                "fontColor": "rgba(31, 31, 31, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "key": -2
        },
        {
            "from": "\u80ba\u304c\u3093?",
            "to": "\u30ec\u30f3\u30c8\u30b2\u30f3\u691c\u67fb?",
            "style": {
                "fillColor": "rgba(2, 20, 47, 1)",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 5,
                "font": "Bold 12pt Meiryo",
                "fontColor": "rgba(31, 31, 31, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "key": -3
        },
        {
            "from": "\u80ba\u304c\u3093?",
            "to": "\u547c\u5438\u56f0\u96e3?",
            "style": {
                "fillColor": "rgba(2, 20, 47, 1)",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 5,
                "font": "Bold 12pt Meiryo",
                "fontColor": "rgba(31, 31, 31, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "key": -4
        }
    ]
}

*** model.data (paste) ***

{
    "class": "GraphLinksModel",
    "linkKeyProperty": "key",
    "nodeDataArray": [
        {
            "key": "\u5927\u6c17\u6c5a\u67d3?",
            "label": "\u5927\u6c17\u6c5a\u67d3?",
            "position": "73 43",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u4ef6\u6570\u6bd4\u7387"
                    ]
                },
                {
                    "rowName": "\u4f4e\u3044",
                    "values": [
                        "0.9"
                    ]
                },
                {
                    "rowName": "\u9ad8\u3044",
                    "values": [
                        "0.1"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u4f4e\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u9ad8\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u80ba\u304c\u3093?",
            "label": "\u80ba\u304c\u3093?",
            "position": "148 152",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u306f\u3044,\u4f4e\u3044",
                        "\u306f\u3044,\u9ad8\u3044",
                        "\u3044\u3044\u3048,\u4f4e\u3044",
                        "\u3044\u3044\u3048,\u9ad8\u3044"
                    ]
                },
                {
                    "rowName": "\u306f\u3044",
                    "values": [
                        "0.03",
                        "0.05",
                        "0.001",
                        "0.02"
                    ]
                },
                {
                    "rowName": "\u3044\u3044\u3048",
                    "values": [
                        "0.97",
                        "0.95",
                        "0.999",
                        "0.98"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u306f\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u3044\u3044\u3048",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u55ab\u7159\u8005?",
            "label": "\u55ab\u7159\u8005?",
            "position": "214 42",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u4ef6\u6570\u6bd4\u7387"
                    ]
                },
                {
                    "rowName": "\u306f\u3044",
                    "values": [
                        "0.3"
                    ]
                },
                {
                    "rowName": "\u3044\u3044\u3048",
                    "values": [
                        "0.7"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u306f\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u3044\u3044\u3048",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u30ec\u30f3\u30c8\u30b2\u30f3\u691c\u67fb?",
            "label": "\u30ec\u30f3\u30c8\u30b2\u30f3\u691c\u67fb?",
            "position": "71 242",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u306f\u3044",
                        "\u3044\u3044\u3048"
                    ]
                },
                {
                    "rowName": "\u967d",
                    "values": [
                        "0.9",
                        "0.2"
                    ]
                },
                {
                    "rowName": "\u9670",
                    "values": [
                        "0.1",
                        "0.8"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u967d",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u9670",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u547c\u5438\u56f0\u96e3?",
            "label": "\u547c\u5438\u56f0\u96e3?",
            "position": "221 249",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u306f\u3044",
                        "\u3044\u3044\u3048"
                    ]
                },
                {
                    "rowName": "\u306f\u3044",
                    "values": [
                        "0.65",
                        "0.3"
                    ]
                },
                {
                    "rowName": "\u3044\u3044\u3048",
                    "values": [
                        "0.35",
                        "0.7"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u306f\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u3044\u3044\u3048",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u5927\u6c17\u6c5a\u67d3?(1)",
            "label": "\u5927\u6c17\u6c5a\u67d3?(1)",
            "position": "73 43",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u4ef6\u6570\u6bd4\u7387"
                    ]
                },
                {
                    "rowName": "\u4f4e\u3044",
                    "values": [
                        "0.9"
                    ]
                },
                {
                    "rowName": "\u9ad8\u3044",
                    "values": [
                        "0.1"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u4f4e\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u9ad8\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        },
        {
            "key": "\u80ba\u304c\u3093?(1)",
            "label": "\u80ba\u304c\u3093?(1)",
            "position": "148 152",
            "size": "120 50",
            "isGroup": false,
            "style": {
                "fillColor": "#00a0a0",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 2,
                "font": "14pt MS P Gothic",
                "fontColor": "rgba(255, 255, 255, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "cptTable": [
                {
                    "rowName": "\u72b6\u614b\u540d",
                    "values": [
                        "\u306f\u3044,\u4f4e\u3044",
                        "\u306f\u3044,\u9ad8\u3044",
                        "\u3044\u3044\u3048,\u4f4e\u3044",
                        "\u3044\u3044\u3048,\u9ad8\u3044"
                    ]
                },
                {
                    "rowName": "\u306f\u3044",
                    "values": [
                        "0.03",
                        "0.05",
                        "0.001",
                        "0.02"
                    ]
                },
                {
                    "rowName": "\u3044\u3044\u3048",
                    "values": [
                        "0.97",
                        "0.95",
                        "0.999",
                        "0.98"
                    ]
                }
            ],
            "bInvalidCpt": false,
            "cttTable": [],
            "nodeLevels": [
                {
                    "category": "Header"
                },
                {
                    "category": "Data",
                    "level": "\u306f\u3044",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                },
                {
                    "category": "Data",
                    "level": "\u3044\u3044\u3048",
                    "prior": 0.5,
                    "posterior": 0.5,
                    "fixed": false
                }
            ],
            "bSoftEvidence": false,
            "nodeScore": {
                "?": 0
            },
            "bExpl": false,
            "bShowInferMon": false
        }
    ],
    "linkDataArray": [
        {
            "from": "\u55ab\u7159\u8005?",
            "to": "\u80ba\u304c\u3093?",
            "style": {
                "fillColor": "rgba(2, 20, 47, 1)",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 5,
                "font": "Bold 12pt Meiryo",
                "fontColor": "rgba(31, 31, 31, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "key": -1
        },
        {
            "from": "\u5927\u6c17\u6c5a\u67d3?",
            "to": "\u80ba\u304c\u3093?",
            "style": {
                "fillColor": "rgba(2, 20, 47, 1)",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 5,
                "font": "Bold 12pt Meiryo",
                "fontColor": "rgba(31, 31, 31, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "key": -2
        },
        {
            "from": "\u80ba\u304c\u3093?",
            "to": "\u30ec\u30f3\u30c8\u30b2\u30f3\u691c\u67fb?",
            "style": {
                "fillColor": "rgba(2, 20, 47, 1)",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 5,
                "font": "Bold 12pt Meiryo",
                "fontColor": "rgba(31, 31, 31, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "key": -3
        },
        {
            "from": "\u80ba\u304c\u3093?",
            "to": "\u547c\u5438\u56f0\u96e3?",
            "style": {
                "fillColor": "rgba(2, 20, 47, 1)",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 5,
                "font": "Bold 12pt Meiryo",
                "fontColor": "rgba(31, 31, 31, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "key": -4
        },
        {
            "from": "\u5927\u6c17\u6c5a\u67d3?(1)",
            "to": "\u80ba\u304c\u3093?(1)",
            "style": {
                "fillColor": "rgba(2, 20, 47, 1)",
                "edgeColor": "rgba(2, 20, 47, 1)",
                "edgeWeight": 5,
                "font": "Bold 12pt Meiryo",
                "fontColor": "rgba(31, 31, 31, 1)",
                "underline": false,
                "textAlign": "center"
            },
            "key": -5
        }
    ]
}

When I looked at your first data, I saw that the “label” property was a duplicate of the key, and that would be the solution. But then I saw that in the pasted data the “label” had been modified to be a copy of the new key. How did that happen?

Anyway, the idea is that you keep your own property that remembers what it was copied from. Only the key is modified in copied node data objects because its value must be unique.

I asked about the version because in v3.0 we incompatibly changed the default value of Model.copiesKey Model | GoJS API changed from true to false. But because you have not upgraded, that could not be a reason, and in any case you are not drag-and-dropping or copy-and-pasting from a different diagram/model to the main diagram/model.