@@ -6,58 +6,65 @@ const workerUrl = new URL("./repl.ts", import.meta.url);
66const worker = new Worker ( workerUrl , { type : "module" } ) ;
77
88const inputContents = `
9- const template = document.createElement('template');
10-
11- template.innerHTML = \`
12- <style>
13- .footer {
14- color: white;
15- background-color: #192a27;
16- }
17- </style>
18-
19- <footer class="footer">
20- <h4>My Blog © \${new Date().getFullYear()}</h4>
21- </footer>
22- \`;
23-
24- class Footer extends HTMLElement {
25- connectedCallback() {
26- if (!this.shadowRoot) {
27- this.attachShadow({ mode: 'open' });
28- this.shadowRoot.appendChild(template.content.cloneNode(true));
29- }
9+ const template = document.createElement('template');
10+
11+ template.innerHTML = \`
12+ <style>
13+ .footer {
14+ color: white;
15+ background-color: #192a27;
16+ }
17+ </style>
18+
19+ <footer class="footer">
20+ <h4>My Blog © \${new Date().getFullYear()}</h4>
21+ </footer>
22+ \`;
23+
24+ class Footer extends HTMLElement {
25+ connectedCallback() {
26+ if (!this.shadowRoot) {
27+ this.attachShadow({ mode: 'open' });
28+ this.shadowRoot.appendChild(template.content.cloneNode(true));
3029 }
3130 }
31+ }
3232
33- export default Footer;
33+ export default Footer;
3434
35- customElements.define('wcc-footer', Footer);
35+ customElements.define('wcc-footer', Footer);
3636` ;
3737
38+ const commonTheme = {
39+ fontFamily : "Geist-Mono" ,
40+ fontSize : 16 ,
41+ minimap : { enabled : false } ,
42+ colorDecorators : false , // Disables hex color swatches and picker
43+ } ;
44+
3845document . addEventListener ( "DOMContentLoaded" , ( ) => {
39- console . log ( "Initializing Monaco Editor..." , { monaco } ) ;
46+ console . log ( "Initializing Editor..." ) ;
4047
4148 const inputEditor = monaco . editor . create ( inputContainer , {
42- value : inputContents ,
49+ value : inputContents . trim ( ) ,
4350 language : "javascript" ,
51+ ...commonTheme ,
4452 } ) ;
45-
4653 const outputEditor = monaco . editor . create ( outputContainer , {
47- // value: "<h1>Output</h1>",
4854 language : "html" ,
55+ ...commonTheme ,
4956 } ) ;
5057
58+ // listen for changes in the input editor and send the updated code to the worker for compilation
5159 inputEditor . onDidChangeModelContent ( ( ) => {
52- const inputContent = inputEditor . getValue ( ) ;
53- console . log ( "Input content changed" , { inputContent } ) ;
54- // const worker = new Worker(workerUrl, { type: "module" });
55- worker . postMessage ( [ inputContent ] ) ;
60+ worker . postMessage ( [ inputEditor . getValue ( ) ] ) ;
5661 } ) ;
5762
63+ // once the worker sends back the compiled HTML, update the output editor with the result
5864 worker . onmessage = ( result ) => {
59- outputEditor . setValue ( result . data . html ) ;
65+ outputEditor . setValue ( result . data . html . trim ( ) ) ;
6066 } ;
6167
68+ // trigger an initial compilation with the default input contents
6269 worker . postMessage ( [ inputEditor . getValue ( ) ] ) ;
6370} ) ;
0 commit comments