From e9feb84fa5a851240df5da887862f0468769b969 Mon Sep 17 00:00:00 2001 From: "C." Date: Fri, 25 Oct 2024 08:55:06 -0500 Subject: [PATCH 1/4] Add application/x-lexical-editor as a custom format to clipboard --- packages/lexical-clipboard/src/clipboard.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/lexical-clipboard/src/clipboard.ts b/packages/lexical-clipboard/src/clipboard.ts index 3de6860e998..870676b1a85 100644 --- a/packages/lexical-clipboard/src/clipboard.ts +++ b/packages/lexical-clipboard/src/clipboard.ts @@ -39,6 +39,7 @@ export interface LexicalClipboardData { 'text/html'?: string | undefined; 'application/x-lexical-editor'?: string | undefined; 'text/plain': string; + 'web application/x-lexical-editor'?: string | null; } /** @@ -133,8 +134,9 @@ export function $insertDataTransferForRichText( selection: BaseSelection, editor: LexicalEditor, ): void { - const lexicalString = dataTransfer.getData('application/x-lexical-editor'); - + const lexicalString = + dataTransfer.getData('application/x-lexical-editor') || + dataTransfer.getData('application/x-lexical/editor'); if (lexicalString) { try { const payload = JSON.parse(lexicalString); @@ -500,6 +502,7 @@ function $copyToClipboardEvent( if (clipboardData === null) { return false; } + setLexicalClipboardDataTransfer(clipboardData, data); return true; } @@ -507,6 +510,7 @@ function $copyToClipboardEvent( const clipboardDataFunctions = [ ['text/html', $getHtmlContent], ['application/x-lexical-editor', $getLexicalContent], + ['web application/x-lexical-editor', $getLexicalContent], ] as const; /** @@ -519,12 +523,13 @@ const clipboardDataFunctions = [ */ export function $getClipboardDataFromSelection( selection: BaseSelection | null = $getSelection(), + editor: LexicalEditor = $getEditor(), ): LexicalClipboardData { const clipboardData: LexicalClipboardData = { 'text/plain': selection ? selection.getTextContent() : '', + 'web application/x-lexical-editor': $getLexicalContent(editor, selection), }; if (selection) { - const editor = $getEditor(); for (const [mimeType, $editorFn] of clipboardDataFunctions) { const v = $editorFn(editor, selection); if (v !== null) { From 1c37c8c1635b3609c3bb365956a4c0e713e0da5a Mon Sep 17 00:00:00 2001 From: "C." <106287207+citruscai@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:40:39 -0500 Subject: [PATCH 2/4] Update packages/lexical-clipboard/src/clipboard.ts Co-authored-by: Bob Ippolito --- packages/lexical-clipboard/src/clipboard.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lexical-clipboard/src/clipboard.ts b/packages/lexical-clipboard/src/clipboard.ts index 870676b1a85..65c8a68d060 100644 --- a/packages/lexical-clipboard/src/clipboard.ts +++ b/packages/lexical-clipboard/src/clipboard.ts @@ -136,7 +136,7 @@ export function $insertDataTransferForRichText( ): void { const lexicalString = dataTransfer.getData('application/x-lexical-editor') || - dataTransfer.getData('application/x-lexical/editor'); + dataTransfer.getData('web application/x-lexical-editor'); if (lexicalString) { try { const payload = JSON.parse(lexicalString); From b74e691206949abc71a45446fdf1834f6f1729c7 Mon Sep 17 00:00:00 2001 From: "C." <106287207+citruscai@users.noreply.github.com> Date: Fri, 25 Oct 2024 13:40:58 -0500 Subject: [PATCH 3/4] Update packages/lexical-clipboard/src/clipboard.ts Co-authored-by: Bob Ippolito --- packages/lexical-clipboard/src/clipboard.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/lexical-clipboard/src/clipboard.ts b/packages/lexical-clipboard/src/clipboard.ts index 65c8a68d060..35b61c99def 100644 --- a/packages/lexical-clipboard/src/clipboard.ts +++ b/packages/lexical-clipboard/src/clipboard.ts @@ -39,7 +39,7 @@ export interface LexicalClipboardData { 'text/html'?: string | undefined; 'application/x-lexical-editor'?: string | undefined; 'text/plain': string; - 'web application/x-lexical-editor'?: string | null; + 'web application/x-lexical-editor'?: string | undefined; } /** From 12b31d43f046836a393604e3daa44a814ee47764 Mon Sep 17 00:00:00 2001 From: "C." Date: Fri, 25 Oct 2024 13:46:58 -0500 Subject: [PATCH 4/4] Remove changes to $getClipboardDataFromSelection --- packages/lexical-clipboard/src/clipboard.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/packages/lexical-clipboard/src/clipboard.ts b/packages/lexical-clipboard/src/clipboard.ts index 35b61c99def..06f463478be 100644 --- a/packages/lexical-clipboard/src/clipboard.ts +++ b/packages/lexical-clipboard/src/clipboard.ts @@ -523,13 +523,12 @@ const clipboardDataFunctions = [ */ export function $getClipboardDataFromSelection( selection: BaseSelection | null = $getSelection(), - editor: LexicalEditor = $getEditor(), ): LexicalClipboardData { const clipboardData: LexicalClipboardData = { 'text/plain': selection ? selection.getTextContent() : '', - 'web application/x-lexical-editor': $getLexicalContent(editor, selection), }; if (selection) { + const editor = $getEditor(); for (const [mimeType, $editorFn] of clipboardDataFunctions) { const v = $editorFn(editor, selection); if (v !== null) {