feat: clear all

typescript_changes
flop 3 weeks ago
parent c4bd427eff
commit de45362fe4
  1. 8
      ts/index.html
  2. 22
      ts/src/browser.ts

@ -32,6 +32,14 @@
Export .bin
</button>
<div class="tb-sep"></div>
<button class="tb-btn" onclick="clearAll()">
<svg viewBox="0 0 24 24">
<polyline points="3 6 5 6 21 6" />
<path d="M19 6l-1 14H6L5 6" />
<path d="M10 11v6M14 11v6" />
</svg>
Clear all
</button>
<button class="tb-btn" onclick="addSection()">
<svg viewBox="0 0 24 24">
<line x1="12" y1="5" x2="12" y2="19" />

@ -818,8 +818,28 @@ m.mount(document.getElementById("sections-wrap")!, SectionsList);
m.mount(document.getElementById("demo-btns")!, DemoButtons);
m.mount(document.getElementById("sec-meta")!, MetaPanel);
async function clearAll() {
if (isDirty && file.sections.length) {
const ok = await showConfirm("Clear all sections?", [
{ label: "Cancel", action: false },
{ label: "Clear", primary: true, action: true },
]);
if (!ok) return;
}
file = new MonoDisplayFile([]);
activeSecIndex = null;
activeElIndex = null;
currentFilename = "untitled";
const filenameEl = document.getElementById("filename");
if (filenameEl) filenameEl.textContent = "untitled";
localStorage.removeItem(STORAGE_KEY);
markClean();
triggerPreview();
m.redraw();
}
// Expose globals referenced by topbar inline handlers
Object.assign(window, { loadBin, exportBin, addSection, cycleTheme });
Object.assign(window, { loadBin, exportBin, addSection, clearAll, cycleTheme });
window.addEventListener("beforeunload", (e) => {
if (isDirty) e.preventDefault();

Loading…
Cancel
Save