Support cross domain/application copy/paste (#6087)

![AnimateDiff_00001](https://github.com/user-attachments/assets/8ae88dc5-bba8-40c0-9cc2-5e81f579761d)


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:
AustinMroz
2025-10-20 10:03:15 -07:00
committed by GitHub
parent 55d2b300a6
commit 8eac19d06e
4 changed files with 71 additions and 30 deletions

View File

@@ -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
}