-
Notifications
You must be signed in to change notification settings - Fork 391
Support cross domain/application copy/paste #6087
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
Changes from all commits
ab6a15b
d8f5001
fe069ef
5b4e9cd
990aae7
0df117e
b4e0602
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,22 @@ import { useCanvasStore } from '@/renderer/core/canvas/canvasStore' | |
| import { app } from '@/scripts/app' | ||
| import { useWorkspaceStore } from '@/stores/workspaceStore' | ||
| import { isAudioNode, isImageNode, isVideoNode } from '@/utils/litegraphUtil' | ||
| import { shouldIgnoreCopyPaste } from '@/workbench/eventHelpers' | ||
|
|
||
| function pasteClipboardItems(data: DataTransfer): boolean { | ||
| const rawData = data.getData('text/html') | ||
| const match = rawData.match(/data-metadata="([A-Za-z0-9+/=]+)"/)?.[1] | ||
| if (!match) return false | ||
| try { | ||
| useCanvasStore() | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [architecture] high Priority Issue: Cross-cutting concerns violation - direct access to canvas store within utility function |
||
| .getCanvas() | ||
| ._deserializeItems(JSON.parse(atob(match)), {}) | ||
| return true | ||
| } catch (err) { | ||
| console.error(err) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [quality] high Priority Issue: Generic error handling that swallows specific error details |
||
| } | ||
| return false | ||
| } | ||
|
|
||
| /** | ||
| * Adds a handler on paste that extracts and loads images or workflows from pasted JSON data | ||
|
|
@@ -38,15 +54,10 @@ export const usePaste = () => { | |
| } | ||
|
|
||
| useEventListener(document, 'paste', async (e) => { | ||
| const isTargetInGraph = | ||
| e.target instanceof Element && | ||
| (e.target.classList.contains('litegraph') || | ||
| e.target.classList.contains('graph-canvas-container') || | ||
| e.target.id === 'graph-canvas') | ||
|
|
||
| // If the target is not in the graph, we don't want to handle the paste event | ||
| if (!isTargetInGraph) return | ||
|
|
||
| if (shouldIgnoreCopyPaste(e.target)) { | ||
| // Default system copy | ||
| return | ||
| } | ||
| // ctrl+shift+v is used to paste nodes with connections | ||
| // this is handled by litegraph | ||
| if (workspaceStore.shiftDown) return | ||
|
|
@@ -109,6 +120,7 @@ export const usePaste = () => { | |
| return | ||
| } | ||
| } | ||
| if (pasteClipboardItems(data)) return | ||
|
|
||
| // No image found. Look for node data | ||
| data = data.getData('text/plain') | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| /** | ||
| * Utility functions for handling workbench events | ||
| */ | ||
|
|
||
| /** | ||
| * Used by clipboard handlers to determine if copy/paste events should be | ||
| * intercepted for graph operations vs. allowing default browser behavior | ||
| * for text inputs and other UI elements. | ||
| * | ||
| * @param target - The event target to check | ||
| * @returns true if copy paste events will be handled by target | ||
| */ | ||
| export function shouldIgnoreCopyPaste(target: EventTarget | null): boolean { | ||
| return ( | ||
| target instanceof HTMLTextAreaElement || | ||
| (target instanceof HTMLInputElement && | ||
| ![ | ||
| 'button', | ||
| 'checkbox', | ||
| 'file', | ||
| 'hidden', | ||
| 'image', | ||
| 'radio', | ||
| 'range', | ||
| 'reset', | ||
| 'search', | ||
| 'submit' | ||
| ].includes(target.type)) | ||
| ) | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.