mirror of
https://github.com/Comfy-Org/ComfyUI_frontend.git
synced 2026-04-21 06:49:37 +00:00
Support cross domain/application copy/paste (#6087)
 Browsers place very heavy restrictions on what can be copied and pasted. See: - https://alexharri.com/blog/clipboard - https://www.w3.org/TR/clipboard-apis/#mandatory-data-types-x ┆Issue is synchronized with this [Notion page](https://www.notion.so/PR-6087-Experimental-cross-domain-application-copy-paste-28e6d73d36508154a0a8deeb392f43a4) by [Unito](https://www.unito.io)
This commit is contained in:
@@ -3867,11 +3867,10 @@ export class LGraphCanvas
|
||||
* When called without parameters, it copies {@link selectedItems}.
|
||||
* @param items The items to copy. If nullish, all selected items are copied.
|
||||
*/
|
||||
copyToClipboard(items?: Iterable<Positionable>): void {
|
||||
localStorage.setItem(
|
||||
'litegrapheditor_clipboard',
|
||||
JSON.stringify(this._serializeItems(items))
|
||||
)
|
||||
copyToClipboard(items?: Iterable<Positionable>): string {
|
||||
const serializedData = JSON.stringify(this._serializeItems(items))
|
||||
localStorage.setItem('litegrapheditor_clipboard', serializedData)
|
||||
return serializedData
|
||||
}
|
||||
|
||||
emitEvent(detail: LGraphCanvasEventMap['litegraph:canvas']): void {
|
||||
@@ -3907,6 +3906,7 @@ export class LGraphCanvas
|
||||
if (!data) return
|
||||
return this._deserializeItems(JSON.parse(data), options)
|
||||
}
|
||||
|
||||
_deserializeItems(
|
||||
parsed: ClipboardItems,
|
||||
options: IPasteFromClipboardOptions
|
||||
@@ -3923,6 +3923,7 @@ export class LGraphCanvas
|
||||
const { graph } = this
|
||||
if (!graph) throw new NullGraphError()
|
||||
graph.beforeChange()
|
||||
this.emitBeforeChange()
|
||||
|
||||
// Parse & initialise
|
||||
parsed.nodes ??= []
|
||||
@@ -4092,6 +4093,7 @@ export class LGraphCanvas
|
||||
this.selectItems(created)
|
||||
|
||||
graph.afterChange()
|
||||
this.emitAfterChange()
|
||||
|
||||
return results
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user