Search Docs
Loading...
Skip to content

Class: ClipboardAPI

Copy and paste through the system clipboard, so blocks move between scenes, tabs, windows and editors, and content from other apps can be pasted.

Constructors#

Constructor#


ClipboardAPI

Methods#

registerPasteHandler()#


Adds a handler for pasted content. On a paste, the handler with the highest priority whose canHandle returns true runs first. When its handle resolves false or rejects, the next handler runs. A handler with the id of a registered one replaces it, so a host can change how a built-in handler places its blocks.

const unregister = engine.clipboard.registerPasteHandler({
id: 'my.app.clipboard.csv',
priority: 300,
canHandle: (snapshot) => snapshot.files.some((file) => file.type === 'text/csv'),
handle: async (snapshot, { engine, parent }) => {
// Create blocks from the CSV and append them to `parent`.
return true;
}
});

Parameters#

Parameter Type Description
handler ClipboardHandler The handler to add.

Returns#

A function that removes the handler again.

() => void

Signature#

registerPasteHandler(handler: ClipboardHandler): () => void

hasBlocks()#


Returns whether the snapshot holds blocks that readBlocks can return.

Parameters#

Parameter Type Description
snapshot ClipboardSnapshot The content of the paste.

Returns#

boolean

Whether the snapshot holds CE.SDK blocks.

Signature#

hasBlocks(snapshot: ClipboardSnapshot): boolean

readBlocks()#


Returns the blocks in the snapshot, for a paste handler that places them its own way. Load them with block.loadFromString, then pass the result to relocatePastedResources at once, before the blocks render.

Parameters#

Parameter Type Description
snapshot ClipboardSnapshot The content of the paste.

Returns#

Promise<PastedBlocks>

The blocks, or undefined when the snapshot holds none.

Signature#

readBlocks(snapshot: ClipboardSnapshot): Promise<PastedBlocks>

relocatePastedResources()#


Points the loaded blocks of a paste at local blob: URLs of the resources that a copy from another engine carried. Call it right after the load: until then, the blocks name those resources by URLs that only the copy knows.

Parameters#

Parameter Type Description
pasted PastedBlocks The blocks that readBlocks returned.

Returns#

void

Signature#

relocatePastedResources(pasted: PastedBlocks): void