@lexical/clipboard
Interfaces
LexicalClipboardData
Defined in: packages/lexical-clipboard/src/clipboard.ts:54
Indexable
[
mimeType:string]:string|undefined
Properties
application/x-lexical-editor?
optionalapplication/x-lexical-editor?:string
Defined in: packages/lexical-clipboard/src/clipboard.ts:56
text/html?
optionaltext/html?:string
Defined in: packages/lexical-clipboard/src/clipboard.ts:55
text/plain
text/plain:
string
Defined in: packages/lexical-clipboard/src/clipboard.ts:57
Functions
$generateJSONFromSelectedNodes()
$generateJSONFromSelectedNodes<
SerializedNode>(editor,selection):object
Defined in: packages/lexical-clipboard/src/clipboard.ts:684
Gets the Lexical JSON of the nodes inside the provided Selection.
Type Parameters
SerializedNode
SerializedNode extends BaseSerializedNode
Parameters
editor
LexicalEditor to get the JSON content from.
selection
BaseSelection | null
Selection to get the JSON content from.
Returns
object
an object with the editor namespace and a list of serializable nodes as JavaScript objects.
namespace
namespace:
string
nodes
nodes:
SerializedNode[]
$generateNodesFromSerializedNodes()
$generateNodesFromSerializedNodes(
serializedNodes):LexicalNode[]
Defined in: packages/lexical-clipboard/src/clipboard.ts:714
This method takes an array of objects conforming to the BaseSerializedNode 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
serializedNodes
BaseSerializedNode[]
an Array of objects conforming to the BaseSerializedNode interface.
Returns
an Array of Lexical Node objects.
$getClipboardDataFromSelection()
$getClipboardDataFromSelection(
selection?):LexicalClipboardData
Defined in: packages/lexical-clipboard/src/clipboard.ts:857
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
selection?
BaseSelection | null
the selection to serialize (defaults to $getSelection())
Returns
LexicalClipboardData
$getHtmlContent()
$getHtmlContent(
editor,selection?):string
Defined in: packages/lexical-clipboard/src/clipboard.ts:71
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
editor
LexicalEditor instance to get HTML content from
selection?
BaseSelection | null
The selection to use (default is $getSelection())
Returns
string
a string of HTML content
$getLexicalContent()
$getLexicalContent(
editor,selection?):string|null
Defined in: packages/lexical-clipboard/src/clipboard.ts:100
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
editor
LexicalEditor instance to get the JSON content from
selection?
BaseSelection | null
The selection to use (default is $getSelection())
Returns
string | null
$handleTextDrop()
$handleTextDrop(
event,editor,$insertDataTransfer):boolean
Defined in: packages/lexical-clipboard/src/clipboard.ts:430
Implements drag-and-drop behavior for an editor. When the drop originates from a non-collapsed RangeSelection in the same editor, the selected content is moved to the drop location. When the drop originates from a different editor that called $setDragSource on DRAGSTART, the content is inserted at the drop location and removed from the source editor (cut-and- paste semantics across editors). Otherwise the DataTransfer content is inserted at the drop location (e.g. for external drags). Returns true when the drop was handled (and event.preventDefault was called), otherwise false.
For full-fidelity internal moves (including custom nodes like images), callers should populate the DataTransfer with Lexical's serialization format on DRAGSTART via setLexicalClipboardDataTransfer and $getClipboardDataFromSelection.
Parameters
event
DragEvent
the DragEvent that triggered the drop.
editor
the LexicalEditor receiving the drop.
$insertDataTransfer
(dataTransfer, selection, targetEditor) => void
strategy for inserting the DataTransfer payload at the drop selection (e.g. $insertDataTransferForRichText or $insertDataTransferForPlainText).
Returns
boolean
$insertDataTransferForPlainText()
$insertDataTransferForPlainText(
dataTransfer,selection):void
Defined in: packages/lexical-clipboard/src/clipboard.ts:127
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
dataTransfer
DataTransfer
an object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
selection
the selection to use as the insertion point for the content in the DataTransfer object
Returns
void
$insertDataTransferForRichText()
$insertDataTransferForRichText(
dataTransfer,selection,editor):void
Defined in: packages/lexical-clipboard/src/clipboard.ts:148
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
dataTransfer
DataTransfer
an object conforming to the [DataTransfer interface] (https://html.spec.whatwg.org/multipage/dnd.html#the-datatransfer-interface)
selection
the selection to use as the insertion point for the content in the DataTransfer object
editor
the LexicalEditor the content is being inserted into.
Returns
void
$insertGeneratedNodes()
$insertGeneratedNodes(
editor,nodes,selection):void
Defined in: packages/lexical-clipboard/src/clipboard.ts:532
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
editor
LexicalEditor instance to insert the nodes into.
nodes
The nodes to insert.
selection
The selection to insert the nodes into.
Returns
void
$setDragSource()
$setDragSource(
editor):void
Defined in: packages/lexical-clipboard/src/clipboard.ts:393
Register the current RangeSelection as the source of an active drag so that a drop in a different editor can remove the dragged content from the source. Must be called within an editor update or read context (it reads the current selection). If there is no non-collapsed RangeSelection, the drag source is cleared.
Callers should pair this with clearDragSource on DRAGEND to avoid stale state if the drag is cancelled.
Parameters
editor
Returns
void
clearDragSource()
clearDragSource():
void
Defined in: packages/lexical-clipboard/src/clipboard.ts:405
Clear any previously recorded drag source. Safe to call at any time.
Returns
void
copyToClipboard()
copyToClipboard(
editor,event,data?):Promise<boolean>
Defined in: packages/lexical-clipboard/src/clipboard.ts:743
Copies the content of the current selection to the clipboard in text/plain, text/html, and application/x-lexical-editor (Lexical JSON) formats.
Parameters
editor
the LexicalEditor instance to copy content from
event
ClipboardEvent | null
the native browser ClipboardEvent to add the content to.
data?
Returns
Promise<boolean>
setLexicalClipboardDataTransfer()
setLexicalClipboardDataTransfer(
clipboardData,data):void
Defined in: packages/lexical-clipboard/src/clipboard.ts:873
Call setData on the given clipboardData for each MIME type present in the given data (from $getClipboardDataFromSelection)
Parameters
clipboardData
DataTransfer
the event.clipboardData to populate from data
data
The lexical data
Returns
void