Skip to content

Commit 3f9066b

Browse files
updates
1 parent ce5023a commit 3f9066b

File tree

2 files changed

+25
-26
lines changed

2 files changed

+25
-26
lines changed

lib/builder.js

Lines changed: 22 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,30 @@ const Builder = () => {
3434
const translate = useTranslations();
3535
const router = useRouter();
3636

37+
const [language, setLanguage] = useState('javascript');
3738
const randomType = ["redirect", "compress", "docs"];
3839

40+
useEffect(() => {
41+
var h_div = document.getElementById('monaco');
42+
var editor = monaco.editor.create(h_div, {
43+
value: [
44+
'module.exports = {',
45+
`\\ttype: "${randomType[Math.floor(Math.random() * randomType.length)]}"`,
46+
'}'
47+
].join('\\n'),
48+
language,
49+
fontFamily: "'Source Code Pro', Consolas, 'Courier New', monospace",
50+
fontSize: 15
51+
});
52+
window.addEventListener('resize', () => {
53+
editor.layout();
54+
});
55+
editor.updateOptions({fontSize: 14});
56+
document.body.addEventListener('click', () => {
57+
setLanguage(document.body.style.getPropertyValue('--l'));
58+
});
59+
}, []);
60+
3961
return (
4062
<>
4163
<div className='builder'>
@@ -101,32 +123,6 @@ const Builder = () => {
101123
</Script>
102124
<script src="/third-party/monaco-editor/package/min/vs/loader.js"></script>
103125
<script src="/third-party/monaco-editor/package/min/vs/editor/editor.main.js"></script>
104-
<Script id="builder" strategy="afterInteractive">
105-
{`
106-
var h_div = document.getElementById('monaco');
107-
const defwidth = window.innerWidth;
108-
window.addEventListener('resize', () => {
109-
if (defwidth > window.innerWidth) {
110-
window.location.reload();
111-
}
112-
});
113-
var editor = monaco.editor.create(h_div, {
114-
value: [
115-
'module.exports = {',
116-
'\\ttype: "${randomType[Math.floor(Math.random() * randomType.length)]}"',
117-
'}'
118-
].join('\\n'),
119-
language: 'javascript',
120-
fontFamily: "'Source Code Pro', Consolas, 'Courier New', monospace",
121-
fontSize: 15
122-
});
123-
editor.updateOptions({fontSize: 14});
124-
document.body.addEventListener('click', () => {
125-
editor.updateOptions({language: document.body.style.getPropertyValue('--l'), fontSize: 15});
126-
editor.updateOptions({fontSize: 14});
127-
});
128-
`}
129-
</Script>
130126
</>
131127
)
132128
}

lib/ui/select.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,9 @@ const Select = ({
4949
selectID++;
5050
useEffect(() => {
5151
document.body.style.setProperty(`--${variable || 'select'+selectID}`, items[id][2] || id);
52+
return () => {
53+
document.body.style.setProperty(`--${variable || 'select'+selectID}`, items[id][2] || id);
54+
}
5255
}, [id]);
5356

5457
return (

0 commit comments

Comments
 (0)