This is a start. You may find you’ll have to do some additional adaptation in order to get it to work the way that your app needs.
<!DOCTYPE html>
<html>
<head>
<title>Minimal GoJS Sample</title>
<!-- Copyright 1998-2024 by Northwoods Software Corporation. -->
</head>
<body>
<div id="myDiagramDiv" style="border: solid 1px black; width:100%; height:600px"></div>
<textarea id="mySavedModel" style="width:100%;height:250px"></textarea>
<script src="https://unpkg.com/gojs"></script>
<script id="code">
class CustomTextEditingTool extends go.TextEditingTool {
doMouseDown() { if (this.isActive) { super.doMouseDown(); this.diagram.toolManager.doMouseDown(); } }
doMouseMove() { if (this.isActive) this.diagram.toolManager.doMouseMove(); }
doMouseUp() { if (this.isActive) this.diagram.toolManager.doMouseUp(); }
}
const $ = go.GraphObject.make;
const myDiagram =
new go.Diagram("myDiagramDiv",
{
textEditingTool: new CustomTextEditingTool(),
"undoManager.isEnabled": true,
"ModelChanged": e => { // just for demonstration purposes,
if (e.isTransactionFinished) { // show the model data in the page's TextArea
document.getElementById("mySavedModel").textContent = e.model.toJson();
}
}
});
const AD =
$(go.Adornment, "Spot",
{ mouseLeave: (e, ad) => ad.adornedPart.removeAdornment("AD") },
$(go.Placeholder),
$(go.Panel,
{ background: "transparent", alignment: go.Spot.Right, alignmentFocus: go.Spot.Left },
$("Button", { margin: new go.Margin(2, 2, 2, 6) },
$(go.Shape, "Diamond", { width: 12, height: 12, fill: "red", stroke: "darkred" }),
{ click: (e, shp) => alert(shp.part.adornedObject.data) }
)
)
);
myDiagram.nodeTemplate =
$(go.Node, "Auto",
$(go.Shape, { fill: "lightyellow" }),
$(go.Panel, "Vertical",
new go.Binding("itemArray", "items"),
{
itemTemplate:
$(go.Panel, "Horizontal",
$(go.Shape, { width: 10, height: 10, margin: 2 }),
$(go.TextBlock, { editable: true },
new go.Binding("text", "").makeTwoWay()),
{
mouseEnter: (e, panel) => { AD.adornedObject = panel; panel.part.addAdornment("AD", AD); },
mouseLeave: (e, panel, next) => { if (!next || !next.isContainedBy(AD)) panel.part.removeAdornment("AD"); }
}
),
defaultAlignment: go.Spot.Left,
margin: 6
}
)
);
myDiagram.model = new go.GraphLinksModel(
[
{ key: 1, text: "Alpha",
items: ["one", "two", "three", "four", "five"] },
]);
</script>
</body>
</html>