-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added copy/paste to graph editor #662
base: master
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: bf0d39f The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
PR Reviewer Guide 🔍Here are some key observations to aid the review process:
|
PR Code Suggestions ✨Explore these optional code suggestions:
|
So some edge cases we need to deal with
2025-02-23.17-11-25.mp4
2025-02-23.17-13-54.mp4
2025-02-23.17-16-34.mp4
2025-02-23.17-17-46.mp4
2025-02-23.17-20-12.mp4 |
We're also breaking variadics 2025-02-23.17-50-02.mp4 |
// calculate bounding box of source nodes (these are already in flow coordinates) | ||
const pasteBounds = sourceNodes.reduce( | ||
(acc, node) => ({ | ||
minX: Math.min(acc.minX, node.annotations?.['ui.position.x'] || 0), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use the xpos
and ypos
, etc annotations so we can reduce the amount of hardcoded strings
...currentGraph, | ||
nodes: [...currentGraph.nodes, ...nodes].map((node) => ({ | ||
...node, | ||
selected: idMapping.has(node.id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don't actually store the selected property in the serialization, this would need to be set in reactflow to handle this
}; | ||
|
||
// load the graph with selection state | ||
await graphRef.loadRaw(mergedGraph); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this runs quite a lot of side code and the logger is saying we're deserializing the graph multiple times, I think we need to break up the loadRaw function to smaller useable pieces as we do need to use it to expose the node factories, etc as part of this
reactFlowInstance.setViewport(viewportState); | ||
|
||
// update ReactFlow's internal state | ||
requestAnimationFrame(() => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this? Its already included in the loadRaw call
...currentGraph, | ||
nodes: [...currentGraph.nodes, ...nodes].map((node) => ({ | ||
...node, | ||
selected: idMapping.has(node.id), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also I don't think this is working as you're expecting, because the keys are the old ids not the new ones you created
User description
Description
Limitations:
Resolves #552
Type of change
Video
copying & pasting between graph & subgraph
PR Type
Enhancement
Description
Added copy/paste functionality for nodes in the graph editor.
Implemented
Cut
,Copy
, andPaste
actions with system clipboard integration.Enhanced context menus with new options for node and selection handling.
Introduced a utility for deleting selected nodes and a hook for copy/paste operations.
Changes walkthrough 📝
nodeContextMenu.tsx
Add Cut and Copy options to node context menu
packages/graph-editor/src/components/contextMenus/nodeContextMenu.tsx
Cut
andCopy
actions to the node context menu.useCopyPaste
hook for clipboard operations.paneContextMenu.tsx
Add Paste option to pane context menu
packages/graph-editor/src/components/contextMenus/paneContextMenu.tsx
Paste
action to the pane context menu.useCopyPaste
hook for clipboard operations.selectionContextMenu.tsx
Add Cut and Copy options to selection context menu
packages/graph-editor/src/components/contextMenus/selectionContextMenu.tsx
Cut
andCopy
actions to the selection context menu.useCopyPaste
hook for clipboard operations.index.tsx
Add hotkey support for Cut, Copy, and Paste
packages/graph-editor/src/components/hotKeys/index.tsx
Cut
,Copy
, andPaste
actions.useCopyPaste
hook for clipboard operations.deleteSelectedNodes.tsx
Add utility for deleting selected nodes
packages/graph-editor/src/editor/actions/deleteSelectedNodes.tsx
useCopyPaste.ts
Add useCopyPaste hook for clipboard operations
packages/graph-editor/src/hooks/useCopyPaste.ts
stale-countries-refuse.md
Add changeset for copy/paste feature
.changeset/stale-countries-refuse.md