Skip to content

Commit 150a047

Browse files
authored
Merge pull request #597 from circuitpython/beta
Merge Latest Beta Changes into Main
2 parents 5d0d164 + d9792e8 commit 150a047

17 files changed

Lines changed: 933 additions & 69 deletions

‎index.html‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,11 @@
44
<head>
55
<meta charset="utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1">
7+
<meta name="theme-color" content="#673ab7">
78
<title>CircuitPython Code Editor</title>
89
<link rel="icon" href="/assets/images/favicon.ico" type="image/x-icon" />
10+
<link rel="apple-touch-icon" href="/assets/images/pwa-icon-180.png">
11+
<link rel="manifest" href="/manifest.webmanifest">
912
<link rel="stylesheet" href="/sass/style.scss">
1013
</head>
1114

@@ -64,9 +67,9 @@
6467
<div id="editor-bar">
6568
<button class="purple-button btn-new">New<i class="fa-solid fa-plus"></i></button>
6669
<button class="purple-button btn-open">Open<i class="fa-solid fa-folder-open"></i></button>
70+
<button class="purple-button btn-format">Format<i class="fa-solid fa-wand-magic-sparkles"></i></button>
6771
<button class="purple-button btn-save">Save<i class="fa-solid fa-floppy-disk"></i></button>
6872
<button class="purple-button btn-save-as">Save As<i class="fa-solid fa-download"></i></button>
69-
<div class="file-path"></div>
7073
<button class="purple-button btn-save-run">Save + Run<i class="fa-solid fa-play"></i></button>
7174
</div>
7275
<div id="mobile-editor-bar">
@@ -78,18 +81,22 @@
7881
</button>
7982
</div>
8083
</div>
81-
<div class="file-path"></div>
8284
<a class="purple-button btn-save-run">Save + Run<i class="fa-solid fa-play"></i></a>
8385
<div class="clear"></div>
8486
<nav id="mobile-menu-contents" role="navigation" class="hidden" aria-expanded="false" aria-label="Mobile Menu">
8587
<ul>
8688
<li><a class="btn-new">New<i class="fa-solid fa-plus"></i></a></li>
8789
<li><a class="btn-open">Open<i class="fa-solid fa-folder-open"></i></a></li>
90+
<li><a class="btn-format">Format<i class="fa-solid fa-wand-magic-sparkles"></i></a></li>
8891
<li><a class="btn-save">Save<i class="fa-solid fa-floppy-disk"></i></a></li>
8992
<li><a class="btn-save-as">Save As<i class="fa-solid fa-download"></i></a></li>
9093
</ul>
9194
</nav>
9295
</div>
96+
<div id="editor-tabs-wrapper">
97+
<div id="editor-tabs" role="tablist" aria-label="Open files"></div>
98+
<select id="editor-tab-select" aria-label="Switch open file" hidden></select>
99+
</div>
93100
<div id="editor" tabindex="0"></div>
94101
</div>
95102
<div id="page-separator" class=""></div>
@@ -119,6 +126,7 @@
119126
<div id="footer-bar">
120127
<button id="btn-mode-editor" class="mode-button active">Editor</button>
121128
<button id="btn-mode-serial" class="mode-button">Serial</button>
129+
<span id="connection-indicator" aria-label="" title="" hidden></span>
122130
<div class="spacer"></div>
123131
<button class="purple-button btn-settings">Settings<i class="fa-solid fa-gear"></i></button>
124132
<button class="purple-button btn-info" disabled>Info<i class="fa-solid fa-info-circle"></i></button>

‎js/common/pwa.js‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
export function registerPWA() {
2+
if (!import.meta.env.PROD || !("serviceWorker" in navigator)) {
3+
return;
4+
}
5+
6+
window.addEventListener("load", () => {
7+
navigator.serviceWorker.register("/sw.js").catch((error) => {
8+
console.warn("Unable to register service worker", error);
9+
});
10+
});
11+
}

‎js/common/settings.js‎

Lines changed: 32 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class SettingsDialog extends GenericModal {
2929
contentDiv.appendChild(label);
3030

3131
const control = await this._createControl(setting);
32-
control.value = settings[setting.key];
32+
control.value = settings?.[setting.key] ?? setting.default;
3333
contentDiv.appendChild(control);
3434
}
3535

@@ -40,7 +40,20 @@ class SettingsDialog extends GenericModal {
4040
let settings = {}
4141
for (const setting of this._settingsData) {
4242
const control = this._currentModal.querySelector(`#setting-${setting.key}`);
43-
settings[setting.key] = control.value;
43+
let value = control.value;
44+
if (setting.type === 'number') {
45+
value = Number.parseInt(value, 10);
46+
if (Number.isNaN(value)) {
47+
value = setting.default;
48+
}
49+
if (setting.min !== undefined) {
50+
value = Math.max(value, setting.min);
51+
}
52+
if (setting.max !== undefined) {
53+
value = Math.min(value, setting.max);
54+
}
55+
}
56+
settings[setting.key] = value;
4457
}
4558
this._returnValue(settings);
4659
}
@@ -56,6 +69,18 @@ class SettingsDialog extends GenericModal {
5669
option.textContent = optionValue.charAt(0).toUpperCase() + optionValue.slice(1);
5770
control.appendChild(option);
5871
}
72+
} else if (settingData.type === 'number') {
73+
control = document.createElement('input');
74+
control.type = 'number';
75+
if (settingData.min !== undefined) {
76+
control.min = settingData.min;
77+
}
78+
if (settingData.max !== undefined) {
79+
control.max = settingData.max;
80+
}
81+
if (settingData.step !== undefined) {
82+
control.step = settingData.step;
83+
}
5984
}
6085
control.id = `setting-${settingData.key}`;
6186

@@ -70,7 +95,8 @@ class Settings {
7095
constructor() {
7196
// This will hold the layout/save data for the settings
7297
this._settingsData = [
73-
{ key: 'theme', type: 'select', label: 'Editor Theme', icon: 'palette', options: ['dark', 'light'], default: 'dark' }
98+
{ key: 'theme', type: 'select', label: 'Editor Theme', icon: 'palette', options: ['dark', 'light'], default: 'dark' },
99+
{ key: 'editorFontSize', type: 'number', label: 'Font Size', icon: 'text-height', min: 8, max: 48, step: 1, default: 16 }
74100
];
75101
this._settings = {};
76102
this._loadSettings();
@@ -110,8 +136,9 @@ class Settings {
110136
}
111137

112138
async showDialog() {
113-
this._settings = await this._settingsDialog.open(this._settings);
114-
if (this._settings) {
139+
const updatedSettings = await this._settingsDialog.open(this._settings);
140+
if (updatedSettings) {
141+
this._settings = updatedSettings;
115142
this._saveSettings();
116143
return true;
117144
}

‎js/layout.js‎

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,21 @@ export function showSerial() {
9999
updatePageLayout(UPDATE_TYPE_SERIAL);
100100
}
101101

102+
function updateModeButtons() {
103+
// Match the button state to the panel state to avoid getting out of sync
104+
if (isEditorVisible()) {
105+
btnModeEditor.classList.add('active');
106+
} else {
107+
btnModeEditor.classList.remove('active');
108+
}
109+
110+
if (isSerialVisible()) {
111+
btnModeSerial.classList.add('active');
112+
} else {
113+
btnModeSerial.classList.remove('active');
114+
}
115+
}
116+
102117
// update type is used to indicate which button was clicked
103118
function updatePageLayout(updateType) {
104119
// If both are visible, show the separator
@@ -110,6 +125,7 @@ function updatePageLayout(updateType) {
110125
editorPage.style.flex = null;
111126
serialPage.style.width = null;
112127
serialPage.style.flex = null;
128+
updateModeButtons();
113129
return;
114130
}
115131

@@ -133,25 +149,14 @@ function updatePageLayout(updateType) {
133149
serialPage.style.flex = 'none';
134150
}
135151

136-
// Match the button state to the panel state to avoid getting out of sync
137-
if (isEditorVisible()) {
138-
btnModeEditor.classList.add('active');
139-
} else {
140-
btnModeEditor.classList.remove('active');
141-
}
142-
143-
if (isSerialVisible()) {
144-
btnModeSerial.classList.add('active');
145-
} else {
146-
btnModeSerial.classList.remove('active');
147-
}
152+
updateModeButtons();
148153

149154
if (isSerialVisible()) {
150155
refitTerminal();
151156
}
152157
}
153158

154-
function refitTerminal() {
159+
export function refitTerminal() {
155160
// Custom function to replace the terminal refit function as it was a bit buggy
156161

157162
// Re-fitting the terminal requires a full re-layout of the DOM which can be tricky to time right.

0 commit comments

Comments
 (0)