Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { EditorAPI } from './api/index.js';
import { generateId } from './utils/uid.js';
import { Paragraph, BoldInlineTool, LinkInlineTool, ItalicInlineTool } from './tools/internal';
import { ShortcutsPlugin } from './plugins/ShortcutsPlugin.js';
import { ClipboardPlugin } from './plugins/ClipboardPlugin.js';

/**
* If no holder is provided via config, the editor will be appended to the element with this id
Expand Down Expand Up @@ -135,6 +136,7 @@ export default class Core {
this.use(ItalicInlineTool);
this.use(LinkInlineTool);
this.use(ShortcutsPlugin);
this.use(ClipboardPlugin);
}

/**
Expand Down
32 changes: 32 additions & 0 deletions packages/core/src/plugins/ClipboardPlugin.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import type { CopyUIEvent, EditorAPI, EditorjsPlugin, EditorjsPluginParams } from '@editorjs/sdk';
import { CopyUIEventName } from '@editorjs/sdk';
import { PluginType } from '@editorjs/sdk';

/**
* @todo update doc
*/
export class ClipboardPlugin implements EditorjsPlugin {
public static readonly type = PluginType.Plugin;

readonly #api: EditorAPI;

/**
* @param params @todo update doc
*/
constructor(params: EditorjsPluginParams) {
const { api, eventBus } = params;

this.#api = api;

eventBus.addEventListener(`ui:${CopyUIEventName}`, (e: CopyUIEvent) => {
console.log('Copied to clipboard plugin', e.detail);
});
}

/**
* @todo update doc
*/
public destroy(): void {
// do nothing
}
}
28 changes: 28 additions & 0 deletions packages/sdk/src/entities/EventBus/events/ui/CopyUIEvent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import { UIEventBase } from './UIEventBase.js';

/**
* Name of the copy UI event (dispatched as `ui:copy`)
*/
export const CopyUIEventName = 'copy';

/**
* Payload @todo update doc
*/
export interface CopyUIEventPayload {
/**
* @todo update doc
*/
nativeEvent: ClipboardEvent;
}

/**
* Delegated copy event from the editor @todo update doc
*/
export class CopyUIEvent extends UIEventBase<CopyUIEventPayload> {
/**
* @param payload - carries the original DOM `ClipboardEvent` as `nativeEvent` for providing rich clipboard data
*/
constructor(payload: CopyUIEventPayload) {
super(CopyUIEventName, payload);
}
}
1 change: 1 addition & 0 deletions packages/sdk/src/entities/EventBus/events/ui/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './UIEventBase.js';
export * from './BeforeInputUIEvent.js';
export * from './KeydownUIEvent.js';
export * from './CopyUIEvent.js';
21 changes: 16 additions & 5 deletions packages/ui/src/Blocks/Blocks.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import type { BlockAddedCoreEvent,
BlockRemovedCoreEvent,
EditorjsPlugin,
EditorjsPluginParams } from '@editorjs/sdk';
import { CopyUIEvent } from '@editorjs/sdk';
import {
CoreEventType,
UiComponentType,
BeforeInputUIEvent
} from '@editorjs/sdk';
import type { EventBus } from '@editorjs/sdk';
import type { EventBus,
BlockAddedCoreEvent,
BlockRemovedCoreEvent, CopyUIEventPayload,
EditorjsPlugin,
EditorjsPluginParams } from '@editorjs/sdk';
import Style from './Blocks.module.pcss';
import { isNativeInput, make } from '@editorjs/dom';
import { BlocksHolderRenderedUIEvent, BlockSelectedUIEvent } from './events/index.js';
Expand Down Expand Up @@ -130,6 +131,16 @@ export class BlocksUI implements EditorjsPlugin {
e.preventDefault();
});

blocksHolder.addEventListener('copy', (e) => {
const payload: CopyUIEventPayload = {
nativeEvent: e,
};

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

e.preventDefault();
});

return blocksHolder;
}

Expand Down
Loading