Skip to content

ckeditor5-elements / ElementPasteCommand

Class: ElementPasteCommand ​

Pastes the system clipboard content relative to an element.

The element is the given one, the parent of the given position, or the selected element or the parent of the selection (see ElementOrPositionCommand). Parts of a structure, such as table cells, rows and captions, cannot be replaced, nor have content pasted next to them, so the command is disabled for them.

The content is pasted as with Ctrl+V: it goes through the clipboard pipeline (the clipboardInput event of the editing view document), so other plugins process it, e.g. paste from Office cleans up content from Word, and image upload uploads the images on the clipboard. The selection is moved to the pasted content.

Requires a secure context (HTTPS or localhost), as it uses the asynchronous Clipboard API. The browser may ask the user for permission.

Extends ​

Constructors ​

Constructor ​

ts
new ElementPasteCommand(editor, placement): ElementPasteCommand;

Parameters ​

ParameterType
editorEditor
placementElementPastePlacement

Returns ​

ElementPasteCommand

Overrides ​

ElementOrPositionCommand.constructor

Properties ​

icon ​

ts
icon: string | undefined;

Observable

The icon (SVG string) of the command.

Inherited from ​

ElementOrPositionCommand.icon


isForceDisabled ​

ts
readonly isForceDisabled: boolean;

Observable

Whether the command is disabled with forceDisabled() (and not enabled back with clearForceDisabled() for every id), so it is disabled for every target.

Inherited from ​

ElementOrPositionCommand.isForceDisabled


isToggleable ​

ts
isToggleable: boolean = false;

Whether the command can be "on" (see _isOnFor), e.g. because it toggles something. Its buttons then tell assistive technology whether it is on: toolbar buttons with aria-pressed, menu items with aria-checked. Defaults to false; the commands of one element that toggle it set it, e.g. ElementInlineCommand.

Inherited from ​

ElementOrPositionCommand.isToggleable


placement ​

ts
readonly placement: ElementPastePlacement;

Where the pasted content goes, relative to the element.


title ​

ts
title: string;

Observable

The title of the command.

Inherited from ​

ElementOrPositionCommand.title


tooltip ​

ts
tooltip: string | boolean;

Observable

The tooltip of the command. true uses the title.

Inherited from ​

ElementOrPositionCommand.tooltip

Methods ​

_getElement() ​

ts
protected _getElement(elementOrPosition?): 
  | ModelElement
  | null;

Resolves the target (see _getElementOrPosition) to an element: a position becomes its parent element. Never returns a root.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

| ModelElement | null

Inherited from ​

ElementOrPositionCommand._getElement


_getElementOrPosition() ​

ts
protected _getElementOrPosition(elementOrPosition?): ElementOrPosition | null;

Returns the given position or element, or resolves it from the current selection when absent. Returns null for a target that is not in the document (any more), e.g. a removed element, so commands ignore such targets.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

ElementOrPosition | null

Inherited from ​

ElementOrPositionCommand._getElementOrPosition


_getPosition() ​

ts
protected _getPosition(elementOrPosition?): 
  | ModelPosition
  | null;

Resolves the target (see _getElementOrPosition) to a position: an element becomes the position before it.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

| ModelPosition | null

Inherited from ​

ElementOrPositionCommand._getPosition


_getStateFor() ​

ts
protected _getStateFor(elementOrPosition?): ElementOrPositionState;

Returns whether the command is enabled and "on" for the target, before read-only mode and forceDisabled(): the one source of the state, for refresh and getState. By default, from _isEnabledFor and _isOnFor.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

ElementOrPositionState

Inherited from ​

ElementOrPositionCommand._getStateFor


_isEnabledFor() ​

ts
protected _isEnabledFor(elementOrPosition?): boolean;

Whether the command is enabled for the target. By default: when there is a target and it can be edited.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

boolean

Overrides ​

ElementOrPositionCommand._isEnabledFor


_isOnFor() ​

ts
protected _isOnFor(elementOrPosition?): boolean;

Whether the command is "on" for the target. By default: never. Commands that override it should set isToggleable.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

boolean

Inherited from ​

ElementOrPositionCommand._isOnFor


_requireElement() ​

ts
protected _requireElement(elementOrPosition?): ModelElement;

Returns the element of the target (see _getElement), in execute() of a command that is enabled only for a target with an element: execute() runs only then, so there is one. Throws when there is none.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

ModelElement

Inherited from ​

ElementOrPositionCommand._requireElement


clearForceDisabled() ​

ts
clearForceDisabled(id): void;

Clears the disabling done by forceDisabled with this id. When no id is left, the command is refreshed, so isEnabled follows the selection again.

Parameters ​

ParameterType
idstring

Returns ​

void

Inherited from ​

ElementOrPositionCommand.clearForceDisabled


execute() ​

ts
execute(elementOrPosition?): Promise<void>;

Pastes the clipboard content relative to the element. Resolves when the content has been pasted; rejects when the browser does not allow reading the clipboard.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

Promise<void>

Overrides ​

ElementOrPositionCommand.execute


executeFor() ​

ts
executeFor(elementOrPosition, ...args): unknown;

Executes the command for the target, even when the command is disabled for the selection (execute() checks isEnabled, which follows the selection). Does nothing when the command is disabled for the target.

The target is the first argument of execute(); the other arguments are passed after it.

Parameters ​

ParameterType
elementOrPositionElementOrPosition
...argsunknown[]

Returns ​

unknown

Inherited from ​

ElementOrPositionCommand.executeFor


forceDisabled() ​

ts
forceDisabled(id): void;

Disables the command for every target until it is enabled back with clearForceDisabled for every id it was disabled with. See isForceDisabled.

Parameters ​

ParameterType
idstring

Returns ​

void

Inherited from ​

ElementOrPositionCommand.forceDisabled


getState() ​

ts
getState(elementOrPosition?): ElementOrPositionState;

Returns whether the command would be enabled and "on" for the target, without changing isEnabled. Commands that change the data are disabled in read-only mode, and all commands are disabled when isForceDisabled.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

ElementOrPositionState

Inherited from ​

ElementOrPositionCommand.getState


refresh() ​

ts
refresh(elementOrPosition?): void;

Sets isEnabled for the target (by default, the selection). See _getStateFor.

Parameters ​

ParameterType
elementOrPosition?ElementOrPosition

Returns ​

void

Inherited from ​

ElementOrPositionCommand.refresh