Skip to content

Commit ab84116

Browse files
feat: #9 WIP formatting and styline input / output editors
1 parent 896177e commit ab84116

2 files changed

Lines changed: 45 additions & 32 deletions

File tree

src/index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,18 @@
4141
#output-container {
4242
flex: 1;
4343
width: 100%;
44+
font-family: var(--font-secondary);
4445
}
4546

4647
#input-content,
4748
#output-content {
4849
width: 100%;
4950
height: 100%;
51+
font-family: var(--font-secondary);
52+
}
53+
54+
.monaco-editor {
55+
font-family: var(--font-secondary);
5056
}
5157
</style>
5258
</head>

src/scripts/repl-init.ts

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -6,58 +6,65 @@ const workerUrl = new URL("./repl.ts", import.meta.url);
66
const worker = new Worker(workerUrl, { type: "module" });
77

88
const 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 &copy; \${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 &copy; \${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+
3845
document.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

Comments
 (0)