1
1
import './index.css' ;
2
2
import { getLineStartPosition } from './utils/string' ;
3
3
import { IconBrackets } from '@codexteam/icons' ;
4
- import { API , PasteEvent } from '@editorjs/editorjs' ;
4
+ import { API , BlockToolConstructorOptions , BlockTool , PasteEvent } from '@editorjs/editorjs' ;
5
5
6
6
/**
7
7
* CodeTool for Editor.js
@@ -11,7 +11,7 @@ import { API, PasteEvent } from '@editorjs/editorjs';
11
11
*/
12
12
13
13
/**
14
- * @description CodeTool's data
14
+ * @description CodeTool generates data in this format
15
15
*/
16
16
export interface CodeData {
17
17
code : string ;
@@ -42,54 +42,34 @@ interface CodeToolNodes {
42
42
textarea : HTMLTextAreaElement | null ;
43
43
}
44
44
45
- /**
46
- * @description Constructor arguments for CodeTool
47
- */
48
- interface ConstructorArgs {
49
- /** Previously saved data */
50
- data : CodeData ;
51
- /** User config for the tool */
52
- config : CodeConfig ;
53
- /** Editor.js API */
54
- api : API ;
55
- /** Read-only mode flag */
56
- readOnly : boolean ;
57
- }
58
-
59
45
/**
60
46
* Code Tool for the Editor.js allows to include code examples in your articles.
61
47
*/
62
- export default class CodeTool {
48
+ export default class CodeTool implements BlockTool {
63
49
/**
64
50
* Editor.js API
65
- * @private
66
51
*/
67
52
private api : API ;
68
53
/**
69
54
* Read-only mode flag
70
- * @private
71
55
*/
72
56
private readOnly : boolean ;
73
57
/**
74
58
* CodeTool's placeholder
75
- * @private
76
59
*/
77
60
private placeholder : string ;
78
61
/**
79
62
* CodeTool's CSS
80
- * @private
81
63
*/
82
64
private CSS : CodeToolCSS ;
83
65
/**
84
66
* CodeTool nodes
85
- * @private
86
67
*/
87
68
private nodes : CodeToolNodes ;
88
69
/**
89
70
* CodeTool's data
90
- * @private
91
71
*/
92
- private _data : CodeData ;
72
+ private _data ! : CodeData ;
93
73
94
74
/**
95
75
* Notify core that read-only mode is supported
@@ -124,7 +104,7 @@ export default class CodeTool {
124
104
* @param {object } options.api - Editor.js API
125
105
* @param {boolean } options.readOnly - read only mode flag
126
106
*/
127
- constructor ( { data, config, api, readOnly } : ConstructorArgs ) {
107
+ constructor ( { data, config, api, readOnly } : BlockToolConstructorOptions ) {
128
108
this . api = api ;
129
109
this . readOnly = readOnly ;
130
110
@@ -142,7 +122,7 @@ export default class CodeTool {
142
122
textarea : null ,
143
123
} ;
144
124
145
- this . _data = {
125
+ this . data = {
146
126
code : data . code || '' ,
147
127
} ;
148
128
@@ -161,7 +141,7 @@ export default class CodeTool {
161
141
162
142
wrapper . classList . add ( this . CSS . baseClass , this . CSS . wrapper ) ;
163
143
textarea . classList . add ( this . CSS . textarea , this . CSS . input ) ;
164
- textarea . textContent = this . _data . code ;
144
+ textarea . textContent = this . data . code ;
165
145
166
146
textarea . placeholder = this . placeholder ;
167
147
@@ -220,7 +200,7 @@ export default class CodeTool {
220
200
221
201
if ( 'data' in detail ) {
222
202
const content = detail . data as string ;
223
- this . _data = {
203
+ this . data = {
224
204
code : content || '' ,
225
205
} ;
226
206
}
0 commit comments