11import './index.css' ;
22import { getLineStartPosition } from './utils/string' ;
33import { IconBrackets } from '@codexteam/icons' ;
4- import type { API , BlockTool , BlockToolConstructorOptions , PasteEvent , SanitizerConfig } from '@editorjs/editorjs' ;
4+ import type { API , BlockTool , BlockToolConstructorOptions , BlockToolData , PasteConfig , PasteEvent , SanitizerConfig , ToolboxConfig } from '@editorjs/editorjs' ;
55
66/**
77 * CodeTool for Editor.js
@@ -12,7 +12,7 @@ import type { API, BlockTool, BlockToolConstructorOptions, PasteEvent, Sanitizer
1212/**
1313 * Data structure for CodeTool's data
1414 */
15- export interface CodeData {
15+ export interface CodeData extends BlockToolData {
1616 /**
1717 * The code content input by the user
1818 */
@@ -53,6 +53,16 @@ interface CodeToolNodes {
5353 textarea : HTMLTextAreaElement | null ;
5454}
5555
56+ /**
57+ * Options passed to the constructor of a block tool
58+ */
59+ interface CodeToolConstructorOptions extends BlockToolConstructorOptions {
60+ /**
61+ * Data specific to the CodeTool
62+ */
63+ data : CodeData ;
64+ }
65+
5666/**
5767 * Code Tool for the Editor.js allows to include code examples in your articles.
5868 */
@@ -86,7 +96,7 @@ export default class CodeTool implements BlockTool {
8696 * Notify core that read-only mode is supported
8797 * @returns true if read-only mode is supported
8898 */
89- static get isReadOnlySupported ( ) : boolean {
99+ public static get isReadOnlySupported ( ) : boolean {
90100 return true ;
91101 }
92102
@@ -95,15 +105,10 @@ export default class CodeTool implements BlockTool {
95105 * This enables multi-line input within the code editor.
96106 * @returns true if line breaks are allowed in the textarea
97107 */
98- static get enableLineBreaks ( ) : boolean {
108+ public static get enableLineBreaks ( ) : boolean {
99109 return true ;
100110 }
101111
102- /**
103- * CodeData — plugin saved data
104- * code - previously saved plugin code
105- */
106-
107112 /**
108113 * Render plugin`s main Element and fill it with saved data
109114 * @param options - tool constricting options
@@ -112,7 +117,7 @@ export default class CodeTool implements BlockTool {
112117 * @param options.api - Editor.js API
113118 * @param options.readOnly - read only mode flag
114119 */
115- constructor ( { data, config, api, readOnly } : BlockToolConstructorOptions ) {
120+ constructor ( { data, config, api, readOnly } : CodeToolConstructorOptions ) {
116121 this . api = api ;
117122 this . readOnly = readOnly ;
118123
@@ -131,7 +136,7 @@ export default class CodeTool implements BlockTool {
131136 } ;
132137
133138 this . data = {
134- code : data . code as string || '' ,
139+ code : data . code ?? '' ,
135140 } ;
136141
137142 this . nodes . holder = this . drawView ( ) ;
@@ -199,7 +204,7 @@ export default class CodeTool implements BlockTool {
199204 * - icon: SVG representation of the Tool's icon
200205 * - title: Title to show in the toolbox
201206 */
202- static get toolbox ( ) : { icon : string ; title : string } {
207+ public static get toolbox ( ) : ToolboxConfig {
203208 return {
204209 icon : IconBrackets ,
205210 title : 'Code' ,
@@ -210,7 +215,7 @@ export default class CodeTool implements BlockTool {
210215 * Default placeholder for CodeTool's textarea
211216 * @returns
212217 */
213- static get DEFAULT_PLACEHOLDER ( ) : string {
218+ public static get DEFAULT_PLACEHOLDER ( ) : string {
214219 return 'Enter a code' ;
215220 }
216221
@@ -219,7 +224,7 @@ export default class CodeTool implements BlockTool {
219224 * Provides configuration to handle CODE tag.
220225 * @returns
221226 */
222- static get pasteConfig ( ) : { tags : string [ ] } {
227+ public static get pasteConfig ( ) : PasteConfig {
223228 return {
224229 tags : [ 'pre' ] ,
225230 } ;
@@ -229,7 +234,7 @@ export default class CodeTool implements BlockTool {
229234 * Automatic sanitize config
230235 * @returns
231236 */
232- static get sanitize ( ) : SanitizerConfig {
237+ public static get sanitize ( ) : SanitizerConfig {
233238 return {
234239 code : true , // Allow HTML tags
235240 } ;
0 commit comments