Skip to main content

Module: @lexical/clipboard

Interfaces

Functions

$generateJSONFromSelectedNodes

$generateJSONFromSelectedNodes<SerializedNode>(editor, selection): Object

Gets the Lexical JSON of the nodes inside the provided Selection.

Type parameters

NameType
SerializedNodeextends BaseSerializedNode

Parameters

NameTypeDescription
editorLexicalEditorLexicalEditor to get the JSON content from.
selectionnull | BaseSelectionSelection to get the JSON content from.

Returns

Object

an object with the editor namespace and a list of serializable nodes as JavaScript objects.

NameType
namespacestring
nodesSerializedNode[]

Defined in

packages/lexical-clipboard/src/clipboard.ts:335


$generateNodesFromSerializedNodes

$generateNodesFromSerializedNodes(serializedNodes): LexicalNode[]

This method takes an array of objects conforming to the BaseSeralizedNode interface and returns an Array containing instances of the corresponding LexicalNode classes registered on the editor. Normally, you'd get an Array of BaseSerialized nodes from $generateJSONFromSelectedNodes

Parameters

NameTypeDescription
serializedNodesBaseSerializedNode[]an Array of objects conforming to the BaseSerializedNode interface.

Returns

LexicalNode[]

an Array of Lexical Node objects.

Defined in

packages/lexical-clipboard/src/clipboard.ts:365


$getClipboardDataFromSelection

$getClipboardDataFromSelection(selection?): LexicalClipboardData

Serialize the content of the current selection to strings in text/plain, text/html, and application/x-lexical-editor (Lexical JSON) formats (as available).

Parameters

NameTypeDescription
selectionnull | BaseSelectionthe selection to serialize (defaults to $getSelection())

Returns

LexicalClipboardData

LexicalClipboardData

Defined in

packages/lexical-clipboard/src/clipboard.ts:507


$getHtmlContent

$getHtmlContent(editor, selection?): string

Returns the currently selected Lexical content as an HTML string, relying on the logic defined in the exportDOM methods on the LexicalNode classes. Note that this will not return the HTML content of the entire editor (unless all the content is included in the current selection).

Parameters

NameTypeDescription
editorLexicalEditorLexicalEditor instance to get HTML content from
selectionnull | BaseSelectionThe selection to use (default is $getSelection())

Returns

string

a string of HTML content

Defined in

packages/lexical-clipboard/src/clipboard.ts:54


$getLexicalContent

$getLexicalContent(editor, selection?): null | string

Returns the currently selected Lexical content as a JSON string, relying on the logic defined in the exportJSON methods on the LexicalNode classes. Note that this will not return the JSON content of the entire editor (unless all the content is included in the current selection).

Parameters

NameTypeDescription
editorLexicalEditorLexicalEditor instance to get the JSON content from
selectionnull | BaseSelectionThe selection to use (default is $getSelection())

Returns

null | string

Defined in

packages/lexical-clipboard/src/clipboard.ts:83


$insertDataTransferForPlainText

$insertDataTransferForPlainText(dataTransfer, selection): void

Attempts to insert content of the mime-types text/plain or text/uri-list from the provided DataTransfer object into the editor at the provided selection. text/uri-list is only used if text/plain is not also provided.

Parameters

NameTypeDescription
dataTransferDataTransferan object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
selectionBaseSelectionthe selection to use as the insertion point for the content in the DataTransfer object

Returns

void

Defined in

packages/lexical-clipboard/src/clipboard.ts:110


$insertDataTransferForRichText

$insertDataTransferForRichText(dataTransfer, selection, editor): void

Attempts to insert content of the mime-types application/x-lexical-editor, text/html, text/plain, or text/uri-list (in descending order of priority) from the provided DataTransfer object into the editor at the provided selection.

Parameters

NameTypeDescription
dataTransferDataTransferan object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
selectionBaseSelectionthe selection to use as the insertion point for the content in the DataTransfer object
editorLexicalEditorthe LexicalEditor the content is being inserted into.

Returns

void

Defined in

packages/lexical-clipboard/src/clipboard.ts:131


$insertGeneratedNodes

$insertGeneratedNodes(editor, nodes, selection): void

Inserts Lexical nodes into the editor using different strategies depending on some simple selection-based heuristics. If you're looking for a generic way to to insert nodes into the editor at a specific selection point, you probably want lexical.$insertNodes

Parameters

NameTypeDescription
editorLexicalEditorLexicalEditor instance to insert the nodes into.
nodesLexicalNode[]The nodes to insert.
selectionBaseSelectionThe selection to insert the nodes into.

Returns

void

Defined in

packages/lexical-clipboard/src/clipboard.ts:205


copyToClipboard

copyToClipboard(editor, event, data?): Promise<boolean>

Copies the content of the current selection to the clipboard in text/plain, text/html, and application/x-lexical-editor (Lexical JSON) formats.

Parameters

NameTypeDescription
editorLexicalEditorthe LexicalEditor instance to copy content from
eventnull | ClipboardEventthe native browser ClipboardEvent to add the content to.
data?LexicalClipboardData-

Returns

Promise<boolean>

Defined in

packages/lexical-clipboard/src/clipboard.ts:394


setLexicalClipboardDataTransfer

setLexicalClipboardDataTransfer(clipboardData, data): void

Call setData on the given clipboardData for each MIME type present in the given data (from $getClipboardDataFromSelection)

Parameters

NameTypeDescription
clipboardDataDataTransferthe event.clipboardData to populate from data
dataLexicalClipboardDataThe lexical data

Returns

void

Defined in

packages/lexical-clipboard/src/clipboard.ts:532