1---2name: diagram-editor3description: Safely change the React Flow database diagram editor, including table, note, zone, relationship, selection, locking, layout, keyboard, and viewport behavior. Use when changing editor components or diagram mutations.4---56# Diagram Editor78## Read First910- `src/lib/types.ts` for node, edge, column, and relationship data shapes.11- `src/store/store.ts` for the mutation API and persistence-facing state transitions.12- `src/components/DiagramEditor.tsx` for React Flow wiring and interaction patterns.13- `src/lib/utils.ts` for ID, handle, position, lock, and relationship helpers.1415## Change Rules16171. Use store actions such as `addNode`, `updateNode`, `deleteNodes`, `addEdge`, `updateEdge`, `deleteEdge`, `onNodesChange`, and `onEdgesChange` instead of mutating diagram arrays in a component.182. Keep table IDs and column IDs stable. Handles usually encode a column ID plus a side suffix such as `${columnId}-right-source` or `${columnId}-left-target`; never parse these with a naive `split("-")` because IDs contain hyphens.193. Treat nodes, notes, zones, and edges as distinct data types. A table soft-delete is not equivalent to removing a note or zone.204. Preserve `sourceColumns`, `targetColumns`, `isComposite`, constraint metadata, and custom edge positions when updating relationships.215. Check diagram lock, zone lock, and position-lock behavior on every new mutation entry point, not only the visible toolbar action.226. When using React Flow's `setNodes` or `setEdges`, verify the resulting change is forwarded to Zustand and survives the debounced IndexedDB save.237. Preserve selection, clipboard, viewport, keyboard shortcut, and responsive canvas behavior.2425## Verification2627- Type-check and lint after edits.28- Exercise create, edit, move, delete, restore, copy/paste, lock/unlock, relationship editing, and viewport persistence when relevant.29- For edge or handle changes, test simple and composite foreign keys and refresh the page before declaring persistence correct.