diff --git a/src/main.ts b/src/main.ts index c28cdd8f..210e0514 100644 --- a/src/main.ts +++ b/src/main.ts @@ -338,6 +338,7 @@ export default class StatBlockPlugin extends Plugin implements StatblockAPI { !this.settings.defaultLayouts.find((l) => l.id == layout.id) ); } + console.log(this.settings.defaultLayouts.filter((f) => f.removed)); function fixSpells(...blocks: StatblockItem[]) { for (const block of blocks) { @@ -570,7 +571,10 @@ export default class StatBlockPlugin extends Plugin implements StatblockAPI { } get layouts() { - return [...this.settings.defaultLayouts, ...this.settings.layouts]; + return [ + ...this.settings.defaultLayouts.filter((f) => !f.removed), + ...this.settings.layouts + ]; } get defaultLayout() { diff --git a/src/settings/settings.ts b/src/settings/settings.ts index 42a0a04c..b2a6f7dc 100644 --- a/src/settings/settings.ts +++ b/src/settings/settings.ts @@ -537,7 +537,23 @@ export default class StatblockSettingTab extends PluginSettingTab { ) { layoutContainer.empty(); + if (this.plugin.settings.defaultLayouts.some((f) => f.removed)) { + new Setting(layoutContainer) + .setName("Restore Default Layouts") + .addButton((b) => { + b.setIcon("rotate-ccw").onClick(async () => { + for (const layout of this.plugin.settings + .defaultLayouts) { + delete layout.removed; + } + await this.plugin.saveSettings(); + this.generateLayouts(outerContainer); + }); + }); + } for (const layout of this.plugin.settings.defaultLayouts) { + if (layout.removed) continue; + const setting = new Setting(layoutContainer) .setName(layout.name) .addExtraButton((b) => { @@ -617,11 +633,12 @@ export default class StatblockSettingTab extends PluginSettingTab { b.setIcon("trash") .setTooltip("Delete") .onClick(async () => { - this.plugin.settings.layouts = - this.plugin.settings.layouts.filter( - (l) => l.id !== layout.id - ); + layout.removed = true; await this.plugin.saveSettings(); + console.log( + "🚀 ~ file: settings.ts:623 ~ layout:", + layout + ); this.generateLayouts(outerContainer); }); diff --git a/types/layout.ts b/types/layout.ts index 28f930e7..b0d55acf 100644 --- a/types/layout.ts +++ b/types/layout.ts @@ -223,4 +223,5 @@ export interface Layout { export interface DefaultLayout extends Layout { edited?: boolean; + removed?: boolean; }