Skip to content

Commit 0b6c5c7

Browse files
committed
Default light/dark theme based on host system preference
Add loading screen
1 parent cb7d331 commit 0b6c5c7

File tree

9 files changed

+360
-263
lines changed

9 files changed

+360
-263
lines changed

site/assets/js/lab/dragndrop_operations.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ export class MoveFieldDragOperation extends DragOperation {
329329
const insert_column = (insert_data.alignment > 0 && col.cell_count > 0);
330330
const max_columns = this.nb.columns.length >= this.nb.max_columns;
331331

332-
333332
if (swap_mode) {
334333
if (different_pos && this.placeholder) {
335334
// Take the old position and swap it with our new position

site/assets/js/lab/index.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ export async function init(compiler_worker_path: string) {
1818

1919
let nb = new NB(2);
2020

21+
22+
2123
let grammar_input_field = nb.add_field(new NBEditorField("Grammar"), 0)
2224
grammar_input_field.set_content_visible(true);
2325
grammar_input_field.set_text("");
@@ -177,6 +179,10 @@ export async function init(compiler_worker_path: string) {
177179
setupConfig(config => {
178180
config_input.update(config);
179181
});
182+
183+
setTimeout(() => {
184+
document.getElementById("loading-screen")!.classList.remove("active");
185+
}, 500);
180186
}
181187

182188
const grammar_examples = [

site/assets/js/lab/settings-panel.ts

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ export function setupOpenCloseTriggers(panel: Element, button_selector: string =
204204

205205
function setupThemes(setting_panel: Element) {
206206

207-
let default_theme = <string>document.body.dataset.defaulttheme;
208-
let active_theme = getLocalValue(LocalStoreKeys.ActiveTheme) || default_theme;
207+
let active_theme = getLocalValue(LocalStoreKeys.ActiveTheme);
209208

210209
//document.body.classList.add(active_theme);
211210
let node = <HTMLTemplateElement>document.querySelector("#theme-entry-template");
@@ -219,13 +218,15 @@ function setupThemes(setting_panel: Element) {
219218
let title = <HTMLElement>theme_entry.querySelector(".theme-entry-title");
220219
let theme_entry_theme = <HTMLElement>theme_entry.querySelector(".theme");
221220

222-
let { bg, mg, fg, target: target_class } = theme.dataset;
221+
let { text, bg, inner_border, inner_bg, border, target: target_class } = theme.dataset;
223222

224-
theme_entry.style.color = <string>fg;
223+
theme_entry.style.color = <string>text;
225224
theme_entry.style.backgroundColor = <string>bg;
225+
theme_entry.style.borderColor = <string>border;
226226

227-
theme_entry_theme.style.borderColor = <string>mg;
228-
theme_entry_theme.style.backgroundColor = <string>fg;
227+
theme_entry_theme.style.borderColor = <string>inner_border;
228+
theme_entry_theme.style.backgroundColor = <string>inner_bg;
229+
title.style.color = <string>text
229230

230231
title.innerHTML = (<string>target_class).replace(/^(\w)|-(\w)/g, " <span style='text-transform:uppercase'>$1$2</span>");
231232

@@ -234,22 +235,22 @@ function setupThemes(setting_panel: Element) {
234235
let old_theme = active_theme;
235236
active_theme = <string>target_class;
236237
setLocalValue(LocalStoreKeys.ActiveTheme, active_theme);
237-
document.body.classList.replace(old_theme, active_theme);
238-
//document.body.classList.remove(old_theme);
238+
if (active_theme)
239+
document.body.classList.add(active_theme);
240+
if (old_theme)
241+
document.body.classList.remove(old_theme);
239242
await sleep(400);
240243
}
241244
});
242245

243246
theme.parentElement?.replaceChild(theme_entry, theme);
244247

245-
246-
if (default_theme != active_theme) {
247-
document.body.classList.replace(default_theme, active_theme);
248+
if (active_theme) {
249+
document.body.classList.add(active_theme);
248250
}
249251

250-
251252
return {
252-
theme_entry, bg, fg, target_class
253+
theme_entry, bg, fg: inner_bg, target_class
253254
};
254255
});
255256
}

0 commit comments

Comments
 (0)