synergycodes/ng-diagram/ng-diagram-events
Claude Code and agent skill by synergycodes/ng-diagram
- community
Checking that the SKILL.md file is still in the repository.
Use when reacting to ng-diagram events - (selectionChanged), nodeDragEnded, viewportChanged, event payloads, addEventListener, setEventsEnabled - or a listener that never fires, fires on every pointer move, or stops after a model reinit.
Install
npx vskill@latest install synergycodes/ng-diagram/ng-diagram-eventsSKILL.md
Diagram events
Covers the 21 diagram events: the two ways to listen, when each event fires, listener lifecycle, and pausing events. Gesture details stay with their skills (ng-diagram-linking, ng-diagram-edge-relinking, ng-diagram-selection-clipboard, ng-diagram-palette, ng-diagram-resize-rotate-snap).
Rules
- One channel, two surfaces. Every event is an output on
<ng-diagram>and a name forNgDiagramService.addEventListener(name, callback), with the same payload (DiagramEventMap). Outputs are re-wired after a model change and clean up with the component, so prefer them in the component that renders<ng-diagram>. UseaddEventListenerin other components and services under the sameprovideNgDiagram(). - Programmatic listeners belong to the current engine.
<ng-diagram>creates the engine, soaddEventListenercalled earlier (for example in the constructor of the component that renders<ng-diagram>) throws[ngDiagram] Library engine not initialized yet.Setting a new model destroys the engine and all its listeners. Register in aneffectonisInitialized()(recipe below). - Unsubscribe with the returned function. The library listens on the same channel.
removeEventListener(name)without a callback also cuts the(name)output of<ng-diagram>;removeAllEventListeners()cuts every output, theactionState()signal and internal gesture tracking. Removing thediagramInitlisteners before that event keeps the canvas hidden (see "Pause events"). - Handlers run synchronously, after the change is in the model and before change detection. Read the payload or the getters (
getModel().getNodes(),getNodeById(...)). Thenodes(),edges()andselection()signals can still show the previous state inside a handler. - Continuous events need care.
selectionMoved,nodeResized,selectionRotatedandviewportChangedfire on every pointer move. WithboxSelection.realtime(defaulttrue),selectionChangedfires while the box grows. Save or call APIs on the*Endedevents, or debounce. - Use `edgeDrawEnded`, not `edgeDrawn`.
edgeDrawnis deprecated (since 1.2.0) and fires only for successful node-to-node draws.edgeDrawEndedfires for every draw: branch onevent.success. - An ended event can be a cancel.
nodeDragEnded,nodeResizeEndedandnodeRotateEndedcarrycancelReason: 'cancelled'(since 1.3.0) after Escape orcancelActiveInteraction(). The payload then holds the restored geometry, so skip your "user changed something" logic.
Which event for which job
| You want to | Event | When it fires | |
|---|---|---|---|
| Show a toolbar/panel after the user selects | selectionGestureEnded (since 1.1.0) | pointerup after a click or box selection that changed the selection, select-all, paste | |
| Mirror the selection | selectionChanged | every change: pointerdown on an element or empty canvas, Ctrl/Cmd+click, realtime box selection, select(), paste, deleting selected elements | |
| Save after a drag | nodeDragStarted / nodeDragEnded (since 1.1.0) | once the pointer has moved a few pixels / on release or cancel | |
| Follow positions live | selectionMoved | each drag step, arrow-key move and moveNodesBy() | |
| Resize | nodeResizeStarted / nodeResized / nodeResizeEnded (start/end since 1.1.0) | handle pointerdown / each size change (also resizeNode()) / release or cancel | |
| Rotate | nodeRotateStarted / selectionRotated / nodeRotateEnded (start/end since 1.1.0) | handle pointerdown / each angle change (also rotateNodeTo()) / release or cancel | |
| Know about a drawn edge | edgeDrawEnded (since 1.2.0) | release, cancel, or when another gesture takes the pointer | |
| Know about a reconnected edge | edgeRelinkStarted / edgeRelinkEnded (since 1.4.0) | once a relink handle has moved a few pixels / release or cancel | |
| Know what the user deleted | selectionRemoved | Delete/Backspace, deleteSelection(), cut() | |
| Group membership | groupMembershipChanged | drop into/out of a group, addToGroup/removeFromGroup, updateNodes changing groupId | |
| Pasted content | clipboardPasted | keyboard paste or paste() | |
| Palette drop | paletteItemDropped | a palette item dropped on the canvas | |
| Pan and zoom | viewportChanged | every pan/zoom step, programmatic viewport changes, container resize | |
| Diagram ready | diagramInit | once per model, after the visible elements are measured |
Read references/event-payloads.md when you need the exact payload fields, the cancel reasons, or which API calls do not fire an event.
Listen in the host template
Listen from another component or service
isInitialized() turns false when a new model is set and true after the new engine's diagramInit, so the effect registers again on every engine. These listeners start after diagramInit; put init logic in the (diagramInit) output or in this effect. addEventListenerOnce(name, callback) removes itself after the first call.
Gesture in progress (no start event)
There is no event for "an edge draw started" or "panning". Read the actionState() signal instead:
Pause events during a programmatic batch
setEventsEnabled(false) is a global switch for this diagram: it also silences the <ng-diagram> outputs, the actionState() signal and internal gesture tracking. Keep it short and never leave it off while the user interacts. areEventsEnabled() reads the flag. A new model starts with events enabled. Pause events only while isInitialized() is true: the diagram shows its canvas from its own diagramInit listener, so disabling events (or removeAllEventListeners(), removeEventListener('diagramInit')) after a new model is set and before its diagramInit keeps the canvas hidden and (diagramInit) silent. Calls like updateNode(s) fire no events anyway (see the reference), so they need no pause.
Edge cases
diagramInit: programmatic listeners run first. One macrotask laterisInitialized()becomestrue, then the(diagramInit)output fires, thenzoom.zoomToFit.onInitruns, so the output sees the viewport before the fit. A new model firesdiagramInitagain.- With virtualization,
diagramInit.nodes/edgeslist only the elements rendered at init. Read the full model withgetModel(). selectionRemovedfires only for deleting the selection.deleteNodes/deleteEdgesfire noselectionRemoved;selectionChangedstill fires when deleted elements were selected.detachedEdges(since 1.4.0) lists edges kept as dangling edges (seeng-diagram-dangling-edges).selectionMoveddoes not fire forupdateNode(s)position changes, palette drops or paste. Arrow keys andmoveNodesBy()fireselectionMovedbut no drag start/end events.nodeResizeddoes not fire forupdateNode({ size })or for size changes from measurement (autoSize).groupMembershipChangedfires forupdateNodes([...])that changegroupId, not for a singleupdateNode(id, { groupId }).- Pressing a port also selects its node (
selectionChanged) unlesslinking.selectNodeOnPortPressisfalse(since 1.2.0). - Inside a transaction, events fire once when it commits. A middleware that cancels an update also cancels its events.
- A throwing
addEventListenerOncecallback stays registered and runs again next time. Async callbacks are not awaited, and their rejections are not caught by the diagram. hasEventListeners(name)is alwaystruefor public events while<ng-diagram>is mounted (the outputs listen to all of them), so it cannot tell you about your own listeners.
Symptom → fix
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/ng-diagram-events/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/synergycodes/ng-diagram/ng-diagram-events)