55 * @version 1.0.0
66 * @created - 2020.02.12
77 * @author - Adombang Munang Mbomndih (Bomdi) <dzedock@gmail.com> (https://bomdisoft.com)
8+ *
9+ * Version History
10+ * ---------------
11+ * @version 2.0.0 - 2022.09.06 - Use TypeScript - Adombang Munang Mbomndih
812 */
913
1014
1115//#region imports
1216require ( './style.css' ) . toString ( ) ;
13- const { DEFAULT_THEMES , COMMON_LANGUAGES } = require ( './constants' ) ;
1417//#endregion
1518
19+ const DEFAULT_THEMES = [ 'light' , 'dark' ] ;
20+ const COMMON_LANGUAGES = {
21+ none : 'Auto-detect' , apache : 'Apache' , bash : 'Bash' , cs : 'C#' , cpp : 'C++' , css : 'CSS' , coffeescript : 'CoffeeScript' , diff : 'Diff' ,
22+ go : 'Go' , html : 'HTML, XML' , http : 'HTTP' , json : 'JSON' , java : 'Java' , javascript : 'JavaScript' , kotlin : 'Kotlin' ,
23+ less : 'Less' , lua : 'Lua' , makefile : 'Makefile' , markdown : 'Markdown' , nginx : 'Nginx' , objectivec : 'Objective-C' ,
24+ php : 'PHP' , perl : 'Perl' , properties : 'Properties' , python : 'Python' , ruby : 'Ruby' , rust : 'Rust' , scss : 'SCSS' ,
25+ sql : 'SQL' , shell : 'Shell Session' , swift : 'Swift' , toml : 'TOML, also INI' , typescript : 'TypeScript' , yaml : 'YAML' ,
26+ plaintext : 'Plaintext'
27+ } ;
28+
1629class CodeBox {
30+ api : any ;
31+ config : { themeName : any ; themeURL : any ; useDefaultTheme : any ; } ;
32+ data : { code : any ; language : any ; theme : any ; } ;
33+ highlightScriptID : string ;
34+ highlightCSSID : string ;
35+ codeArea : HTMLDivElement ;
36+ selectInput : HTMLInputElement ;
37+ selectDropIcon : HTMLElement ;
38+
1739 constructor ( { data, api, config } ) {
1840 this . api = api ;
1941 this . config = {
@@ -68,7 +90,7 @@ class CodeBox {
6890
6991 codeAreaHolder . setAttribute ( 'class' , 'codeBoxHolder' ) ;
7092 this . codeArea . setAttribute ( 'class' , `codeBoxTextArea ${ this . config . useDefaultTheme } ${ this . data . language } ` ) ;
71- this . codeArea . setAttribute ( 'contenteditable' , true ) ;
93+ this . codeArea . setAttribute ( 'contenteditable' , ' true' ) ;
7294 this . codeArea . innerHTML = this . data . code ;
7395 this . api . listeners . on ( this . codeArea , 'blur' , event => this . _highlightCodeArea ( event ) , false ) ;
7496 this . api . listeners . on ( this . codeArea , 'paste' , event => this . _handleCodeAreaPaste ( event ) , false ) ;
@@ -106,7 +128,7 @@ class CodeBox {
106128 this . selectDropIcon . innerHTML = '↓' ;
107129 this . selectInput . setAttribute ( 'class' , `codeBoxSelectInput ${ this . config . useDefaultTheme } ` ) ;
108130 this . selectInput . setAttribute ( 'type' , 'text' ) ;
109- this . selectInput . setAttribute ( 'readonly' , true ) ;
131+ this . selectInput . setAttribute ( 'readonly' , ' true' ) ;
110132 this . selectInput . value = this . data . language ;
111133 this . api . listeners . on ( this . selectInput , 'click' , event => this . _handleSelectInputClick ( event ) , false ) ;
112134
@@ -130,7 +152,7 @@ class CodeBox {
130152 }
131153
132154 _highlightCodeArea ( event ) {
133- hljs . highlightBlock ( this . codeArea ) ;
155+ window . hljs . highlightBlock ( this . codeArea ) ;
134156 }
135157
136158 _handleCodeAreaPaste ( event ) {
@@ -147,7 +169,7 @@ class CodeBox {
147169 this . codeArea . removeAttribute ( 'class' ) ;
148170 this . data . language = language [ 0 ] ;
149171 this . codeArea . setAttribute ( 'class' , `codeBoxTextArea ${ this . config . useDefaultTheme } ${ this . data . language } ` ) ;
150- hljs . highlightBlock ( this . codeArea ) ;
172+ window . hljs . highlightBlock ( this . codeArea ) ;
151173 }
152174
153175 _closeAllLanguageSelects ( ) {
@@ -195,4 +217,4 @@ class CodeBox {
195217}
196218
197219
198- module . exports = CodeBox ;
220+ export default CodeBox ;
0 commit comments