Skip to content

Commit 98e1fd6

Browse files
committed
feat: rewrited remaining types and updated some comment
1 parent 55ac901 commit 98e1fd6

4 files changed

Lines changed: 52 additions & 56 deletions

File tree

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2018 CodeX
3+
Copyright (c) 2023 CodeX
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

src/index.css

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
.ce-paragraph {
2-
line-height: 1.6em;
3-
outline: none;
2+
line-height: 1.6em;
3+
outline: none;
44
}
55

6-
.ce-paragraph[data-placeholder]:empty::before{
6+
.ce-paragraph[data-placeholder]:empty::before {
77
content: attr(data-placeholder);
88
color: #707684;
99
font-weight: normal;
@@ -20,10 +20,10 @@
2020
opacity: 0;
2121
}
2222

23-
.ce-paragraph p:first-of-type{
24-
margin-top: 0;
23+
.ce-paragraph p:first-of-type {
24+
margin-top: 0;
2525
}
2626

27-
.ce-paragraph p:last-of-type{
28-
margin-bottom: 0;
27+
.ce-paragraph p:last-of-type {
28+
margin-bottom: 0;
2929
}

src/index.ts

Lines changed: 15 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import './index.css';
55

66
import { IconText } from '@codexteam/icons'
77
import { 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
*/
1818
export 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'

src/types/index.ts

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,26 +4,41 @@ import { BlockToolData, ToolConfig } from '@editorjs/editorjs';
44
* Tool's input and output data format
55
*/
66
export interface ParagraphToolData extends BlockToolData {
7-
/**
8-
* Paragraph's content. Can include HTML tags: <a><b><i>
9-
*/
10-
text?: string;
7+
/**
8+
* Paragraph's content. Can include HTML tags: <a><b><i>
9+
*/
10+
text?: string;
1111
}
1212

1313
export interface ParagraphToolConfig extends ToolConfig {
14-
/**
15-
* Placeholder for the empty paragraph
16-
*/
17-
placeholder?: string;
14+
/**
15+
* Placeholder for the empty paragraph
16+
*/
17+
placeholder?: string;
1818

19-
/**
20-
* Whether or not to keep blank paragraphs when saving editor data
21-
*/
22-
preserveBlank?: boolean;
19+
/**
20+
* Whether or not to keep blank paragraphs when saving editor data
21+
*/
22+
preserveBlank?: boolean;
2323
}
2424

2525
export interface ParagraphToolCSS {
26-
block: string;
26+
/**
27+
* Block CSS class name
28+
*/
29+
block: string;
2730

28-
wrapper: 'ce-paragraph';
31+
/**
32+
* Wrapper CSS class name
33+
*/
34+
wrapper: string;
35+
}
36+
37+
export interface PasteConfig {
38+
tags: string[];
39+
}
40+
41+
export interface Toolbox {
42+
icon: string;
43+
title: string;
2944
}

0 commit comments

Comments
 (0)