Skip to content

Commit

Permalink
Update mod.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
ca-d authored Jul 5, 2021
1 parent 5304c28 commit f85bcab
Showing 1 changed file with 36 additions and 21 deletions.
57 changes: 36 additions & 21 deletions mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,13 @@ const defaults = {
mode: "typescript",
url: "https://raw.githubusercontent.com/ca-d/ide/main/mod.ts",
format: "data:text/javascript;base64,",
shortcuts: `{
r: reload,
s: copy,
S: download,
o: open,
d: deploy,
}`,
};

function env(key) {
Expand Down Expand Up @@ -129,19 +136,17 @@ const html = `<html>
var editor = document.querySelector('ace-editor');
async function initEditor() {
const gitRes = await fetch('${env("url")}')
const gitText = await gitRes.text();
if (gitText) {
console.log('git', gitText);
editor.setAttribute('value', gitText);
}
const clipURL = await navigator.clipboard.readText();
if (clipURL?.startsWith('${env("format")}')) {
console.log('clip', clipURL);
editor.setAttribute('value', atob(clipURL.substring(${env("format").length})));
}
const deployURLRes = await fetch('/src', {
async function loadURL(url) {
const res = await fetch(url);
const text = await res.text();
if (text) {
console.log('loading', url);
editor.setAttribute('valu', text);
}
}
async function reload() {
const deployURLRes = await fetch('/src', {
method: 'GET',
headers: {
'Content-Type': 'text/plain',
Expand All @@ -153,10 +158,17 @@ const html = `<html>
const deployRes = await fetch(deployURL);
const deployText = await deployRes.text();
if (deployText) {
console.log('deploy', deployText);
console.log('deploy', deployURL);
editor.setAttribute('value', deployText);
}
}
async function initEditor() {
await loadURL('${env("url")}');
const clipURL = await navigator.clipboard.readText();
await loadURL(clipURL);
await reload();
}
initEditor();
Expand Down Expand Up @@ -213,14 +225,10 @@ const html = `<html>
saveUI.addEventListener('click', download);
shareUI.addEventListener('click', copy);
uploadUI.addEventListener('click', deploy);
downloadUI.addEventListener('click', reload);
openUI.addEventListener('click', open);
const shortcuts = {
s: copy,
d: deploy,
S: download,
o: open,
};
const shortcuts = ${env('shortcuts')};
document.addEventListener('keydown',
async e => {
Expand All @@ -243,7 +251,7 @@ const html = `<html>
ace-editor.ace_editor {
width: 100vw;
height: 100vh;
font-size: 20px;
font-size: 1.7vmin;
font-family: 'Fira Code';
}
Expand All @@ -254,6 +262,13 @@ const html = `<html>
bottom: 16px;
right: 16px;
}
div.fabs > * > div {
width: 64px;
height: 64px;
font-size: 48px;
padding: 8px;
}
</style>
</body>
</html>`;
Expand Down

0 comments on commit f85bcab

Please sign in to comment.