55 * @author Calum Knott ([email protected] ) 66 * @license The MIT License (MIT)
77 */
8-
8+
99 /**
1010 * @typedef {object } EditorJsCodeFlaskConfig
1111 * @property {string } placeholder - placeholder for the empty EditorJsCodeFlask
1212 * @property {boolean } preserveBlank - Whether or not to keep blank EditorJsCodeFlasks when saving editor data
1313 */
14-
14+
1515 /**
1616 * @typedef {Object } EditorJsCodeFlaskData
1717 * @description Tool's input and output data format
2323
2424 import Prism from 'prismjs' ;
2525
26+ // Additional languages
27+ import "prismjs/components/prism-java"
28+ import "prismjs/components/prism-go"
29+ import "prismjs/components/prism-typescript"
30+
2631 // import "prismjs-components-importer/esm"; // ALL - Massivly Increases Bundle size!
2732
2833 import "prismjs-components-importer/esm/prism-iecst" ; // Structured Text
29- import "prismjs-components-importer/esm/prism-markdown" ;
30- import "prismjs-components-importer/esm/prism-json" ;
34+ import "prismjs-components-importer/esm/prism-markdown" ;
35+ import "prismjs-components-importer/esm/prism-json" ;
3136 import "prismjs-components-importer/esm/prism-python" ;
3237 import "prismjs-components-importer/esm/prism-bash" ;
33-
38+
3439
3540 import CodeFlask from 'codeflask' ;
3641
3742 import NiceSelect from "nice-select2/dist/js/nice-select2" ;
3843 import NiceSelectStyle from "nice-select2/dist/css/nice-select2.css" ;
3944
40-
41-
42-
43- // console.log(Prism.languages)
44-
45-
46-
4745 class EditorJsCodeFlask {
4846 /**
4947 * Default placeholder for EditorJsCodeFlask Tool
5856 static get enableLineBreaks ( ) {
5957 return true ;
6058 }
61-
59+
6260 /**
6361 * Render plugin`s main Element and fill it with saved data
6462 *
7270 // console.log(data)
7371 this . api = api ;
7472 this . readOnly = readOnly ;
75-
73+
7674 this . _CSS = {
7775 block : this . api . styles . block ,
7876 wrapper : 'ce-EditorJsCodeFlask' ,
7977 settingsButton : this . api . styles . settingsButton ,
8078 settingsButtonActive : this . api . styles . settingsButtonActive ,
8179 } ;
82-
80+
8381 if ( ! this . readOnly ) {
8482 this . onKeyUp = this . onKeyUp . bind ( this ) ;
8583 }
86-
84+
8785 /**
8886 * Placeholder for EditorJsCodeFlask if it is first Block
8987 * @type {string }
9492
9593 this . _element ; // used to hold the wrapper div, as a point of reference
9694
97-
95+
9896
9997 // let x = (x === undefined) ? your_default_value : x;
10098 this . data = { }
106104 // console.log(this.data)
107105
108106 }
109-
107+
110108 /**
111109 * Check if text content is empty and set empty string to inner html.
112110 * We need this because some browsers (e.g. Safari) insert <br> into empty contenteditanle elements
117115 if ( e . code !== 'Backspace' && e . code !== 'Delete' ) {
118116 return ;
119117 }
120-
118+
121119 const { textContent} = this . _element ;
122-
120+
123121 if ( textContent === '' ) {
124122 this . _element . innerHTML = '' ;
125123 }
126124 }
127125
128-
126+
129127 /**
130128 * Return Tool's view
131129 *
145143 this . _element . appendChild ( editorElem )
146144 this . _element . appendChild ( langdisplay )
147145
148- this . data . editorInstance = new CodeFlask ( editorElem , {
149- language : this . data . language ,
146+ this . data . editorInstance = new CodeFlask ( editorElem , {
147+ language : this . data . language ,
150148 lineNumbers : this . data . showlinenumbers ,
151149 readonly : this . readOnly
152150 } ) ;
232230
233231 settingsContainer . appendChild ( languagesSelect ) ;
234232 new NiceSelect ( languagesSelect , { searchable : true , placeholder : "Language..." } ) ;
235-
233+
236234 // settingsContainer.appendChild(settingsButton);
237235
238236 return settingsContainer ;
249247
250248 _updateLanguage = ( lang ) => {
251249 this . data . language = lang
252- this . _element . querySelector ( '.editorjs-codeFlask_LangDisplay' ) . innerHTML = this . data . language
253- this . data . editorInstance . updateLanguage ( this . data . language )
250+ this . _element . querySelector ( '.editorjs-codeFlask_LangDisplay' ) . innerHTML = lang
251+ this . data . editorInstance . addLanguage ( lang , Prism . languages [ lang ] )
252+ this . data . editorInstance . updateLanguage ( lang )
254253 }
255-
256254
257-
255+
256+
258257 /**
259258 * Extract Tool's data from the view
260259 * @param {HTMLDivElement } toolsContent - EditorJsCodeFlask tools rendered view
267266 language : this . data . language ,
268267 showlinenumbers : this . data . showlinenumbers
269268 } ;
270-
269+
271270 return resp
272271 }
273-
272+
274273 /**
275274 * Returns true to notify the core that read-only mode is supported
276275 *
280279 return true ;
281280 }
282281
283-
282+
284283 /**
285284 * Icon and title for displaying at the Toolbox
286285 *
293292 } ;
294293 }
295294 }
296-
297- export { EditorJsCodeFlask as default }
295+
296+ export { EditorJsCodeFlask as default }
0 commit comments