@@ -5,14 +5,14 @@ import './index.css';
55
66import { IconText } from '@codexteam/icons'
77import { API , BlockTool , PasteEvent } from '@editorjs/editorjs' ;
8- import type { ParagraphToolConfig , ParagraphToolCSS , ParagraphToolData } from './types' ;
8+ import type { ParagraphToolConfig , ParagraphToolCSS , ParagraphToolData , PasteConfig , Toolbox } from './types' ;
99
1010/**
1111 * Base Paragraph Block for the Editor.js.
1212 * Represents simple paragraph
1313 *
14- * @author CodeX ( team@codex.so)
15- * @copyright CodeX 2018
14+ * @author CodeX < team@codex.so>
15+ * @copyright CodeX 2023
1616 * @license The MIT License (MIT)
1717 */
1818export default class Paragraph implements BlockTool {
@@ -55,10 +55,9 @@ export default class Paragraph implements BlockTool {
5555 /**
5656 * Default placeholder for Paragraph Tool
5757 *
58- * @return {string }
5958 * @constructor
6059 */
61- static get DEFAULT_PLACEHOLDER ( ) {
60+ static get DEFAULT_PLACEHOLDER ( ) : string {
6261 return '' ;
6362 }
6463
@@ -84,17 +83,15 @@ export default class Paragraph implements BlockTool {
8483 this . onKeyUp = this . onKeyUp . bind ( this ) ;
8584 }
8685
87- this . placeholder = config . placeholder ? config . placeholder : Paragraph . DEFAULT_PLACEHOLDER ;
86+ this . placeholder = config . placeholder ?? Paragraph . DEFAULT_PLACEHOLDER ;
8887 this . element = this . drawView ( ) ;
89- this . preserveBlank = config . preserveBlank !== undefined ? config . preserveBlank : false ;
88+ this . preserveBlank = config . preserveBlank ?? false ;
9089 this . data = data ;
9190 }
9291
9392 /**
9493 * Check if text content is empty and set empty string to inner html.
9594 * We need this because some browsers (e.g. Safari) insert <br> into empty contenteditanle elements
96- *
97- * @param e - key up event
9895 */
9996 private onKeyUp ( e : KeyboardEvent ) : void {
10097 if ( e . code !== 'Backspace' && e . code !== 'Delete' ) {
@@ -109,9 +106,7 @@ export default class Paragraph implements BlockTool {
109106 }
110107
111108 /**
112- * Create Tool's view
113- *
114- * @return {HTMLElement }
109+ * Create Tool's html view
115110 */
116111 private drawView ( ) : HTMLDivElement {
117112 let div = document . createElement ( 'div' ) ;
@@ -141,7 +136,7 @@ export default class Paragraph implements BlockTool {
141136 * Method that specified how to merge two Text blocks.
142137 * Called by Editor.js by backspace at the beginning of the Block
143138 *
144- * @param data
139+ * @param data - paragraph content
145140 */
146141 public merge ( data : ParagraphToolData ) {
147142 this . data = {
@@ -180,16 +175,14 @@ export default class Paragraph implements BlockTool {
180175
181176 /**
182177 * On paste callback fired from Editor.
183- *
184- * @param {PasteEvent } event - event with pasted data
185178 */
186179 onPaste ( event : PasteEvent ) {
187180 if ( ! ( 'data' in event . detail ) ) {
188181 return ;
189182 }
190183
191184 this . data = {
192- text : ( event . detail . data as HTMLElement ) . innerHTML ,
185+ text : ( event . detail . data as HTMLElement ) . innerHTML ,
193186 } ;
194187 }
195188
@@ -216,17 +209,13 @@ export default class Paragraph implements BlockTool {
216209
217210 /**
218211 * Returns true to notify the core that read-only mode is supported
219- *
220- * @return {boolean }
221212 */
222- static get isReadOnlySupported ( ) {
213+ static get isReadOnlySupported ( ) : boolean {
223214 return true ;
224215 }
225216
226217 /**
227218 * Get current Tools`s data
228- *
229- * @returns Current data
230219 */
231220 private get data ( ) : ParagraphToolData {
232221 this . _data . text = this . element . innerHTML ;
@@ -235,11 +224,7 @@ export default class Paragraph implements BlockTool {
235224 }
236225
237226 /**
238- * Store data in plugin:
239- * - at the this._data property
240- * - at the HTML
241- *
242- * @param data — data to set
227+ * Updates the internal state and state of the html element
243228 */
244229 private set data ( data : ParagraphToolData ) {
245230 this . _data = data || { } ;
@@ -250,21 +235,17 @@ export default class Paragraph implements BlockTool {
250235 /**
251236 * Used by Editor paste handling API.
252237 * Provides configuration to handle P tags.
253- *
254- * @returns {{tags: string[]} }
255238 */
256- static get pasteConfig ( ) {
239+ static get pasteConfig ( ) : PasteConfig {
257240 return {
258- tags : [ 'P' ]
241+ tags : [ 'P' ]
259242 } ;
260243 }
261244
262245 /**
263- * Icon and title for displaying at the Toolbox
264- *
265- * @return {{icon: string, title: string} }
246+ * Icon and title for displaying paragraph module at the Toolbox
266247 */
267- static get toolbox ( ) {
248+ static get toolbox ( ) : Toolbox {
268249 return {
269250 icon : IconText ,
270251 title : 'Text'
0 commit comments