Skip to content

Commit f66779f

Browse files
committed
chore(paste): update function to match documentation standard
1 parent c0da232 commit f66779f

File tree

1 file changed

+20
-5
lines changed

1 file changed

+20
-5
lines changed

src/index.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import './index.css';
22
import { getLineStartPosition } from './utils/string';
33
import { IconBrackets } from '@codexteam/icons';
4-
import type { API, BlockTool, BlockToolConstructorOptions, BlockToolData, HTMLPasteEvent, PasteConfig, SanitizerConfig, ToolboxConfig } from '@editorjs/editorjs';
4+
import type { API, BlockTool, BlockToolConstructorOptions, BlockToolData, PasteEvent, HTMLPasteEventDetail, PasteConfig, SanitizerConfig, ToolboxConfig } from '@editorjs/editorjs';
55

66
/**
77
* CodeTool for Editor.js
@@ -160,10 +160,15 @@ export default class CodeTool implements BlockTool {
160160
* onPaste callback fired from Editor`s core
161161
* @param event - event with pasted content
162162
*/
163-
public onPaste(event: HTMLPasteEvent): void {
164-
this.data = {
165-
code: event.detail.data.innerHTML,
166-
};
163+
public onPaste(event: PasteEvent): void {
164+
switch (event.type) {
165+
case 'tag': {
166+
const element = (event.detail as HTMLPasteEventDetail).data;
167+
168+
this.handleHTMLPaste(element);
169+
break;
170+
}
171+
}
167172
}
168173

169174
/**
@@ -318,4 +323,14 @@ export default class CodeTool implements BlockTool {
318323

319324
return wrapper;
320325
}
326+
327+
/**
328+
* Handles pasted HTML content
329+
* @param element - pasted HTML element
330+
*/
331+
private handleHTMLPaste(element: HTMLElement): void {
332+
this.data = {
333+
code: element.innerHTML,
334+
};
335+
}
321336
}

0 commit comments

Comments
 (0)