Skip to content

Commit 6b04b2c

Browse files
authored
Codeit 3.4.2
Patch 1
2 parents 3151fa8 + 7f6fe54 commit 6b04b2c

File tree

7 files changed

+163
-85
lines changed

7 files changed

+163
-85
lines changed

filebrowser.js

Lines changed: 114 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -398,38 +398,6 @@ async function renderSidebarHTML() {
398398

399399
// if navigating in repository
400400
if (repo != '') {
401-
402-
// legacy modified file dir
403-
404-
let modFilesChanged = false;
405-
406-
Object.values(modifiedFiles).forEach(modFile => {
407-
408-
if (modFile.dir) {
409-
410-
// map modified file location
411-
let [fileUser, fileRepo, fileDir] = modFile.dir.split(',');
412-
413-
// if modified file dosen't have a branch
414-
// and is in current repo
415-
if (!fileRepo.includes(':')
416-
&& fileUser === user
417-
&& fileRepo === repoName) {
418-
419-
// append default branch to file
420-
fileRepo = fileRepo + ':' + branch;
421-
modFile.dir = [fileUser, fileRepo, fileDir].join();
422-
423-
modFilesChanged = true;
424-
425-
}
426-
427-
}
428-
429-
});
430-
431-
if (modFilesChanged) updateModFilesLS();
432-
433401

434402
// get all eclipsed files in directory
435403
eclipsedFiles = Object.values(modifiedFiles).filter(modFile => modFile.dir == treeLoc.join());
@@ -463,8 +431,7 @@ async function renderSidebarHTML() {
463431

464432
// scroll to end of title
465433
sidebarLogo.scrollTo({
466-
left: sidebarLogo.scrollWidth - sidebarLogo.offsetLeft//,
467-
//behavior: 'smooth'
434+
left: sidebarLogo.scrollWidth - sidebarLogo.offsetLeft
468435
});
469436

470437
sidebarLogo.classList.add('notransition');
@@ -832,6 +799,11 @@ async function renderSidebarHTML() {
832799
protectUnsavedCode();
833800

834801
}
802+
803+
804+
// hide branch menu
805+
branchMenu.classList.remove('visible');
806+
sidebarBranch.classList.remove('active');
835807

836808
}
837809

@@ -1341,10 +1313,104 @@ async function loadFileInHTML(fileEl, fileSha) {
13411313
startLoading();
13421314
}
13431315

1316+
1317+
const fileDir = treeLoc.join();
1318+
13441319
// get file from git
13451320
let resp = await git.getFile(treeLoc, fileName);
13461321

13471322

1323+
const currSelectedFileName = fileWrapper.querySelector('.selected .name').textContent.replaceAll('\n','');
1324+
1325+
// if switched file or directory while loading, return
1326+
if (treeLoc.join() !== fileDir ||
1327+
currSelectedFileName !== fileName) {
1328+
1329+
return;
1330+
1331+
}
1332+
1333+
1334+
// if file dosen't exist
1335+
if (resp.message && resp.message === 'Not Found') {
1336+
1337+
// stop loading
1338+
stopLoading();
1339+
1340+
showMessage('Hmm... that file dosen\'t exist.', 5000);
1341+
1342+
1343+
// remove file from HTML
1344+
if (fileEl) fileEl.remove();
1345+
1346+
// if previous file selection exists
1347+
if (selectedFile.sha) {
1348+
1349+
const prevSelFileEl = fileWrapper.querySelector('.item[sha="'+ selectedFile.sha +'"]');
1350+
1351+
// if previous file selection exists in HTML
1352+
if (prevSelFileEl) {
1353+
1354+
// load previous selected file
1355+
loadFileInHTML(prevSelFileEl, selectedFile.sha);
1356+
1357+
} else {
1358+
1359+
// clear editor to protect unsaved code
1360+
clearEditor();
1361+
1362+
}
1363+
1364+
} else {
1365+
1366+
// clear editor to protect unsaved code
1367+
clearEditor();
1368+
1369+
}
1370+
1371+
function clearEditor() {
1372+
1373+
// clear codeit contents
1374+
cd.textContent = '\r\n';
1375+
1376+
// change codeit lang
1377+
cd.lang = '';
1378+
1379+
// clear codeit history
1380+
cd.history.records = [{ html: cd.innerHTML, pos: cd.getSelection() }];
1381+
cd.history.pos = 0;
1382+
1383+
// update line numbers
1384+
updateLineNumbersHTML();
1385+
1386+
// if on mobile, show sidebar
1387+
if (isMobile) {
1388+
1389+
// don't transition
1390+
body.classList.add('notransition');
1391+
1392+
// show sidebar
1393+
toggleSidebar(true);
1394+
saveSidebarStateLS();
1395+
1396+
onNextFrame(() => {
1397+
1398+
body.classList.remove('notransition');
1399+
1400+
});
1401+
1402+
}
1403+
1404+
// change selected file to empty file
1405+
changeSelectedFile('', '', '', '', '', [0, 0], [0, 0], false);
1406+
1407+
}
1408+
1409+
return;
1410+
1411+
}
1412+
1413+
13481414
// if file is over 1MB
13491415
if (resp.size >= 1000000 && resp.content === '') {
13501416

@@ -1612,7 +1678,7 @@ async function renderBranchMenuHTML(renderAll) {
16121678
if (getAttr(branchMenu, 'tree') !== [user, repoName, contents].join()) {
16131679

16141680
// show loading message
1615-
branchMenu.innerHTML = '<div class="icon selected"><a>Loading...</a></div>';
1681+
branchMenu.innerHTML = '<div class="icon" style="pointer-events: none; opacity: .5; font-weight: 500;"><a>Loading...</a></div>';
16161682

16171683
setAttr(branchMenu, 'tree', [user, repoName, contents].join());
16181684

@@ -1723,7 +1789,7 @@ async function renderBranchMenuHTML(renderAll) {
17231789
// render show more button
17241790
if (!renderAll && branchResp.length > 1) {
17251791

1726-
out += '<div class="icon see-more">' + moreIcon + '<a>see more</a></div>';
1792+
out += '<div class="icon see-more">' + moreIcon + '<a>more</a></div>';
17271793

17281794
}
17291795

@@ -2011,8 +2077,8 @@ sidebarBranch.addEventListener('click', () => {
20112077
moveElToEl(branchMenu, sidebarBranch, 23);
20122078

20132079
}
2014-
2015-
branchMenu.classList.add('top-margin');
2080+
2081+
branchMenu.scrollTo(0, 0);
20162082

20172083
}
20182084

@@ -2930,7 +2996,7 @@ function codeChange() {
29302996
// protect unsaved code
29312997
// if selected file is in current directory
29322998
// but does not exist in the HTML
2933-
function protectUnsavedCode() {
2999+
async function protectUnsavedCode() {
29343000

29353001
// map tree location
29363002
const [user, repo, contents] = treeLoc;
@@ -2962,55 +3028,24 @@ function protectUnsavedCode() {
29623028
// if new version of selected file exists
29633029
if (selectedElName !== null) {
29643030

2965-
// load file
2966-
loadFileInHTML(selectedElName, getAttr(selectedElName, 'sha'));
2967-
2968-
} else {
2969-
2970-
// if the selected file was deleted,
2971-
// protect unsaved code by clearing codeit
2972-
2973-
// clear codeit contents
2974-
cd.textContent = '\r\n';
2975-
2976-
// change codeit lang
2977-
cd.lang = '';
3031+
const scrollPos = selectedFile.scrollPos;
29783032

2979-
// clear codeit history
2980-
cd.history.records = [{ html: cd.innerHTML, pos: cd.getSelection() }];
2981-
cd.history.pos = 0;
2982-
2983-
// update line numbers
2984-
updateLineNumbersHTML();
2985-
2986-
// if on mobile, show sidebar
2987-
if (isMobile) {
2988-
2989-
// don't transition
2990-
body.classList.add('notransition');
2991-
2992-
// show sidebar
2993-
toggleSidebar(true);
2994-
saveSidebarStateLS();
2995-
2996-
onNextFrame(() => {
2997-
2998-
body.classList.remove('notransition');
2999-
3000-
});
3001-
3002-
}
3033+
// load file
3034+
await loadFileInHTML(selectedElName, getAttr(selectedElName, 'sha'));
30033035

3004-
// change selected file to empty file
3005-
changeSelectedFile('', '', '', '', '', [0, 0], [0, 0], false);
3036+
// prevent bottom float disappearing on mobile
3037+
if (isMobile) lastScrollTop = scrollPos[1];
3038+
3039+
// scroll to pos in code
3040+
cd.scrollTo(scrollPos[0], scrollPos[1]);
30063041

30073042
}
30083043

30093044
} else {
30103045

30113046
// if selected file isn't loaded
30123047
if (selectedFile.sha !== getAttr(selectedElSha, 'sha')) {
3013-
3048+
30143049
// load file
30153050
loadFileInHTML(selectedElSha, getAttr(selectedElSha, 'sha'));
30163051

full.css

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,26 @@ body.mobile .context-menu {
17511751
display: none;
17521752
}
17531753

1754+
.live-view-menu {
1755+
left: 11px;
1756+
top: 41px;
1757+
z-index: 1001;
1758+
margin-top: 7px;
1759+
padding: 0;
1760+
}
1761+
1762+
body:not(.mobile) .live-view-menu {
1763+
display: none;
1764+
}
1765+
1766+
.live-view-menu:not(.visible) {
1767+
padding: 2px 2px 2px 0px;
1768+
}
1769+
1770+
.live-view-menu:not(.visible) .icon {
1771+
padding: 9.5px 13px;
1772+
}
1773+
17541774

17551775
.dialog-wrapper {
17561776
position: fixed;

full.html

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
</div>
8484
</div>
8585
<div class="live-buttons">
86+
<!-- <svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" class="live-button options"><path d="M0 0h24v24H0z" fill="none"></path><path d="M12 8c1.1 0 2-.9 2-2s-.9-2-2-2-2 .9-2 2 .9 2 2 2zm0 2c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2zm0 6c-1.1 0-2 .9-2 2s.9 2 2 2 2-.9 2-2-.9-2-2-2z" fill="currentColor"></path></svg> -->
8687
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" class="live-button share"><path d="M0 0h24v24H0z" fill="none"></path><path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92 1.61 0 2.92-1.31 2.92-2.92s-1.31-2.92-2.92-2.92z" fill="currentColor"></path><path xmlns="http://www.w3.org/2000/svg" d="M16 5l-1.42 1.42-1.59-1.59V16h-1.98V4.83L9.42 6.42 8 5l4-4 4 4zm4 5v11c0 1.1-.9 2-2 2H6c-1.11 0-2-.9-2-2V10c0-1.11.89-2 2-2h3v2H6v11h12V10h-3V8h3c1.1 0 2 .89 2 2z" fill="currentColor" class="ios"></path></svg>
8788
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" class="live-button close"><path d="M0 0h24v24H0z" fill="none"></path><path d="M8.7 15.9L4.8 12l3.9-3.9c.39-.39.39-1.01 0-1.4-.39-.39-1.01-.39-1.4 0l-4.59 4.59c-.39.39-.39 1.02 0 1.41l4.59 4.6c.39.39 1.01.39 1.4 0 .39-.39.39-1.01 0-1.4zm6.6 0l3.9-3.9-3.9-3.9c-.39-.39-.39-1.01 0-1.4.39-.39 1.01-.39 1.4 0l4.59 4.59c.39.39.39 1.02 0 1.41l-4.59 4.6c-.39.39-1.01.39-1.4 0-.39-.39-.39-1.01 0-1.4z" fill="currentColor"></path></svg>
8889
</div>
@@ -223,7 +224,7 @@
223224
</div>
224225
</div>
225226

226-
<div class="menu branch-menu"></div>
227+
<div class="menu branch-menu top-margin"></div>
227228

228229
<div class="menu context-menu">
229230
<div class="icon push">
@@ -280,6 +281,23 @@
280281
</div>
281282
</div>
282283

284+
<div class="menu live-view-menu">
285+
<div class="icon console">
286+
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" class="branch-icon">
287+
<path d="M0 0h24v24H0V0z" fill="none"></path>
288+
<path d="M20,4H4C2.89,4,2,4.9,2,6v12c0,1.1,0.89,2,2,2h16c1.1,0,2-0.9,2-2V6C22,4.9,21.11,4,20,4z M20,18H4V8h16V18z M12,16 c0-0.55,0.45-1,1-1h4c0.55,0,1,0.45,1,1c0,0.55-0.45,1-1,1h-4C12.45,17,12,16.55,12,16z M6.79,9.71c0.39-0.39,1.02-0.39,1.41,0 l2.59,2.59c0.39,0.39,0.39,1.02,0,1.41l-2.59,2.59c-0.39,0.39-1.02,0.39-1.41,0c-0.39-0.39-0.39-1.02,0-1.41L8.67,13l-1.88-1.88 C6.4,10.73,6.4,10.1,6.79,9.71z" fill="currentColor"></path>
289+
</svg>
290+
<a>Console</a>
291+
</div>
292+
<div class="icon share">
293+
<svg xmlns="http://www.w3.org/2000/svg" height="24" viewBox="0 0 24 24" width="24" class="branch-icon">
294+
<path d="M0 0h24v24H0V0z" fill="none"></path>
295+
<path d="M18 16.08c-.76 0-1.44.3-1.96.77L8.91 12.7c.05-.23.09-.46.09-.7s-.04-.47-.09-.7l7.05-4.11c.54.5 1.25.81 2.04.81 1.66 0 3-1.34 3-3s-1.34-3-3-3-3 1.34-3 3c0 .24.04.47.09.7L8.04 9.81C7.5 9.31 6.79 9 6 9c-1.66 0-3 1.34-3 3s1.34 3 3 3c.79 0 1.5-.31 2.04-.81l7.12 4.16c-.05.21-.08.43-.08.65 0 1.61 1.31 2.92 2.92 2.92s2.92-1.31 2.92-2.92-1.31-2.92-2.92-2.92z" fill="currentColor"></path>
296+
</svg>
297+
<a>Share</a>
298+
</div>
299+
</div>
300+
283301
<div class="dialog-wrapper">
284302
<div class="dialog-anim-wrapper">
285303
<div class="dialog">

git/gitauth.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,8 @@ window.addEventListener('load', async () => {
7979
window.addEventListener('message', async (event) => {
8080

8181
// if received a git code
82-
if (event.origin === window.location.origin
83-
&& event.data.startsWith('gitCode=')) {
82+
if (event.origin === window.location.origin &&
83+
event.data && event.data.startsWith('gitCode=')) {
8484

8585
// hide intro screen
8686
sidebar.classList.remove('intro');

live-view/live-view.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1196,12 +1196,17 @@ async function renderLiveViewMarkdown(file) {
11961196

11971197
await loadScript(window.location.origin + '/lib/prism.js', frameDoc.body);
11981198

1199+
11991200
let s = document.createElement('script');
1201+
12001202
s.appendChild(document.createTextNode(`Prism.plugins.autoloader.languages_path = 'https://cdnjs.cloudflare.com/ajax/libs/prism/1.28.0/components/'`));
1203+
1204+
frameDoc.body.appendChild(s);
1205+
12011206
onNextFrame(() => {
12021207
frameDoc.body.removeChild(s);
12031208
});
1204-
frameDoc.body.appendChild(s);
1209+
12051210

12061211
await loadScript(window.location.origin + '/lib/codeit.js', frameDoc.body);
12071212

utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ const body = document.body,
6868

6969

7070
// version
71-
const version = '3.4.1';
71+
const version = '3.4.2';
7272
versionEl.innerText = version;
7373

7474
let logVersion = () => {

worker/client-channel.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55

66
// update worker name when updating worker
7-
const WORKER_NAME = 'codeit-worker-v613';
7+
const WORKER_NAME = 'codeit-worker-v614';
88

99

1010
// internal paths

0 commit comments

Comments
 (0)