Skip to content

feat(core): implement Clipboard Plugin#129

Merged
ilyamore88 merged 32 commits into
mainfrom
feat/clipboard-plugin
Jul 21, 2026
Merged

feat(core): implement Clipboard Plugin#129
ilyamore88 merged 32 commits into
mainfrom
feat/clipboard-plugin

Conversation

@ilyamore88

@ilyamore88 ilyamore88 commented Apr 17, 2026

Copy link
Copy Markdown
Member

Implementation of Clipboard Plugin. Currently it supports the same behaviour from v2, when a user can copy blocks from Editor and then paste it.
During implementation I found a limitation in Safari. The system ignores custom meta data, if user copies and paste data between different domains.

TODO

  • Add missing docs;
  • Add unit tests.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Implements initial “copy” pipeline support by introducing a UI-level ui:copy event, exposing selected blocks via the Selection API, and adding a Core ClipboardPlugin that writes editor-specific clipboard payloads when blocks are selected.

Changes:

  • UI: dispatch a new CopyUIEvent on native copy within the blocks holder.
  • SDK/Core APIs: add selection.selectedBlocks and selection logic to derive selected blocks from caret/index state.
  • Core: auto-register a new ClipboardPlugin that overrides native copy to populate text/plain, text/html, and application/x-editor-js.

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 9 comments.

Show a summary per file
File Description
packages/ui/src/Blocks/Blocks.ts Dispatches CopyUIEvent on native copy events from the blocks holder.
packages/sdk/src/entities/EventBus/events/ui/index.ts Re-exports the new UI copy event from the UI events barrel.
packages/sdk/src/entities/EventBus/events/ui/CopyUIEvent.ts Introduces CopyUIEvent, name constant, and payload type carrying the native ClipboardEvent.
packages/sdk/src/api/SelectionAPI.ts Extends public Selection API with selectedBlocks.
packages/model/src/entities/Index/index.ts Adds Index.isCompositeIndex predicate for composite selections.
packages/core/src/plugins/ClipboardPlugin.ts New plugin that intercepts ui:copy and writes multiple clipboard formats, including editor-specific MIME data.
packages/core/src/index.ts Registers ClipboardPlugin in Core default plugin set.
packages/core/src/components/SelectionManager.ts Adds logic to derive selected blocks from caret index (block index or composite segments).
packages/core/src/api/SelectionAPI.ts Implements SDK Selection API selectedBlocks getter via SelectionManager.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/core/src/plugins/ClipboardPlugin.ts Outdated
Comment thread packages/core/src/plugins/ClipboardPlugin.ts Outdated
Comment thread packages/core/src/components/SelectionManager.ts Outdated
Comment thread packages/model/src/entities/Index/index.ts Outdated
Comment thread packages/sdk/src/api/SelectionAPI.ts Outdated
Comment thread packages/sdk/src/entities/EventBus/events/ui/CopyUIEvent.ts Outdated
Comment thread packages/sdk/src/entities/EventBus/events/ui/CopyUIEvent.ts
Comment thread packages/plugins/clipboard-plugin/src/index.ts
Comment thread packages/model-types/src/Index/index.ts Outdated
* @todo update doc
*/
public destroy(): void {
// do nothing

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could unsubscribe from the copy event

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

return '';
}

const container = document.createElement('div');

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Template might be better instead of div

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

ilyamore88 and others added 3 commits June 9, 2026 19:21
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

Unit Tests

Package Coverage Delta
@editorjs/collaboration-manager 85.81% 0% ⚪️
@editorjs/dom-adapters 86.95% 0% ⚪️
@editorjs/ot-server 20% 0% ⚪️
@editorjs/core 90.47% +0.92% 🟢
@editorjs/model 98.25% 0% ⚪️
@editorjs/model-types 93.75% -4.07% 🔴
@editorjs/clipboard-plugin 66.66% N/A

Mutation Tests

Package Mutation score Dashboard URL
@editorjs/dom-adapters No files to mutate found.
@editorjs/core 32.14% 🔴 Dashboard
@editorjs/model No files to mutate found.
@editorjs/collaboration-manager No files to mutate found.
@editorjs/clipboard-plugin 100.00% 🟢 Dashboard

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 4 comments.

Comment thread packages/ui/src/Blocks/Blocks.ts Outdated
Comment thread packages/core/src/plugins/ClipboardPlugin.ts Outdated
Comment thread packages/sdk/src/entities/EventBus/events/ui/CopyUIEvent.ts
Comment thread packages/sdk/src/api/SelectionAPI.ts Outdated
@ilyamore88
ilyamore88 requested a review from gohabereg July 8, 2026 18:03
@ilyamore88
ilyamore88 marked this pull request as ready for review July 8, 2026 18:03

@gohabereg gohabereg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just fix the code style

Comment thread packages/sdk/src/api/SelectionAPI.ts Outdated
/**
*
*/
get selectedBlocks(): BlockNodeSerialized[] | null;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe [] instead of null

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

@editor-js editor-js deleted a comment from github-actions Bot Jul 19, 2026
@editor-js editor-js deleted a comment from github-actions Bot Jul 19, 2026
@editor-js editor-js deleted a comment from github-actions Bot Jul 19, 2026
@editor-js editor-js deleted a comment from github-actions Bot Jul 19, 2026
@editor-js editor-js deleted a comment from github-actions Bot Jul 19, 2026
@ilyamore88
ilyamore88 requested a review from Copilot July 19, 2026 20:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 23 out of 24 changed files in this pull request and generated 2 comments.

Comment thread packages/plugins/clipboard-plugin/tsconfig.eslint.json
Comment thread packages/core/src/components/SelectionManager.ts

clipboardData.setData('text/plain', selectionAsPlainText);
clipboardData.setData('text/html', selectionAsHTML);
clipboardData.setData('application/x-editor-js', JSON.stringify(clipboardEditorJSObject));

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The mime type could be a const

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

/**
* Custom EditorJS data-type object for clipboard events
*/
interface ClipboardEditorJSObject {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe move interfaces to the top

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resolved

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 27 out of 28 changed files in this pull request and generated 2 comments.

Comment on lines +140 to +146
blocksHolder.addEventListener('copy', (e) => {
const payload: CopyUIEventPayload = {
nativeEvent: e,
};

this.#eventBus.dispatchEvent(new CopyUIEvent(payload));
});

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tracked in #170

Comment thread packages/plugins/clipboard-plugin/src/index.ts
});
});
});
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add more cases covering multiline copying:

  • select several blocks and copy as text.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you mean a test like this? c322b46

Comment thread packages/plugins/clipboard-plugin/src/index.ts

Copilot AI commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

@neSpecc I've opened a new pull request, #175, to work on those changes. Once the pull request is ready, I'll request review from you.

@ilyamore88
ilyamore88 added this pull request to the merge queue Jul 21, 2026
Merged via the queue into main with commit f14b7ce Jul 21, 2026
57 checks passed
@ilyamore88
ilyamore88 deleted the feat/clipboard-plugin branch July 21, 2026 20:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants