Replace the Notebook tab toolbar with an x, a rename dialog and drag-only reordering

AI Assisted
This commit is contained in:
jparkerweb committed 2026-10-20 12:01:37 -07:00
1 parent d4adb53a3a
commit 086c735c65
7 files changed
+194 -182

No files matched your search

+24 -22
View File
@@ -2615,28 +2615,6 @@
<div class="notepad-tabs" id="notepad-tabs" role="tablist" aria-label="Notebook tabs"></div>
<button type="button" class="btn small ghost notepad-tab-new" id="notepad-tab-new">+ New tab</button>
</div>
<div class="notepad-tab-tools" id="notepad-tab-tools" role="group" aria-label="This tab" hidden>
<button type="button" class="btn tiny ghost" id="notepad-tab-rename">Rename</button>
<button type="button" class="btn tiny ghost" id="notepad-tab-left">Move left</button>
<button type="button" class="btn tiny ghost" id="notepad-tab-right">Move right</button>
<button type="button" class="btn tiny ghost notepad-tab-delete" id="notepad-tab-delete">Delete</button>
</div>
<form class="notepad-name-form" id="notepad-name-form" hidden novalidate>
<label for="notepad-name" id="notepad-name-label">Name this tab</label>
<div class="notepad-name-row">
<input type="text" id="notepad-name" autocomplete="off" spellcheck="false" aria-describedby="notepad-name-error" />
<button type="submit" class="btn small primary" id="notepad-name-save">Save</button>
<button type="button" class="btn small ghost" id="notepad-name-cancel">Cancel</button>
</div>
<p class="help notepad-name-error" id="notepad-name-error" aria-live="polite"></p>
</form>
<div class="notepad-delete" id="notepad-delete" role="group" aria-labelledby="notepad-delete-text" hidden>
<p id="notepad-delete-text"></p>
<div class="notepad-delete-row">
<button type="button" class="btn small" id="notepad-delete-keep">Keep tab</button>
<button type="button" class="btn small danger" id="notepad-delete-go">Delete tab…</button>
</div>
</div>
<div class="notepad-empty" id="notepad-empty" hidden>
<p>No tabs yet. Make one to start writing.</p>
<button type="button" class="btn small primary" id="notepad-empty-new">+ New tab</button>
@@ -2655,6 +2633,30 @@
</div>
</dialog>
<!-- The Notebook's name and delete questions: small dialogs over the Notebook.
A tab's double-click (or F2) opens the name one for Rename, + New tab
opens it for a new name, and a tab's x opens the delete one, which asks twice. -->
<dialog class="modal notepad-sub" id="notepad-name-dlg" aria-labelledby="notepad-name-label">
<form class="notepad-name-form" id="notepad-name-form" novalidate>
<h2 id="notepad-name-label">Name this tab</h2>
<input type="text" id="notepad-name" autocomplete="off" spellcheck="false" aria-describedby="notepad-name-error" />
<p class="help notepad-name-error" id="notepad-name-error" aria-live="polite"></p>
<div class="modal-actions">
<button type="button" class="btn ghost" id="notepad-name-cancel">Cancel</button>
<button type="submit" class="btn primary" id="notepad-name-save">Save</button>
</div>
</form>
</dialog>
<dialog class="modal notepad-sub notepad-delete" id="notepad-delete" aria-labelledby="notepad-delete-title" aria-describedby="notepad-delete-text">
<h2 id="notepad-delete-title">Delete this tab?</h2>
<p id="notepad-delete-text"></p>
<div class="modal-actions">
<button type="button" class="btn ghost" id="notepad-delete-keep">Keep tab</button>
<button type="button" class="btn danger" id="notepad-delete-go">Delete tab…</button>
</div>
</dialog>
<!-- The Notebook's full-screen picture preview, opened over the Notebook
from a thumbnail by screens/notepad.js. -->
<dialog class="modal notepad-preview" id="notepad-preview" aria-label="Image preview">
+24 -13
View File
@@ -1,11 +1,12 @@
// Plan2Code Web Console - the Notebook's tab bar.
//
// Draws #notepad-tabs from a list of { id, name } and tells screens/notepad.js
// what the person did: pick a tab (onSwitch), reorder with the keyboard or a
// drag, or ask to rename (onChange). No fetches here: the screen owns every
// request, and notepad.js owns the rules for order.
// what the person did: pick a tab (onSwitch), reorder with a drag, ask to
// rename (a double-click or F2) or ask to delete (the x beside the name, or the
// Delete key) (onChange). No fetches here: the screen owns every request, and
// notepad.js owns the rules for order.
import { dropTab, moveTab } from "./notepad.js";
import { dropTab } from "./notepad.js";
import { el } from "./render.js";
const $ = (id) => document.getElementById(id);
@@ -15,7 +16,7 @@ const DRAG_TYPE = "application/x-plan2code-notepad-tab";
/**
* `onSwitch(id)` runs when a tab is picked. `onChange(event)` runs for
* `{ type: "order", order, focus }` (a new order to save, focus the moved tab
* afterwards) and `{ type: "rename", id }`.
* afterwards), `{ type: "rename", id }` and `{ type: "delete", id }`.
*/
export function createTabs({ onSwitch, onChange }) {
const bar = $("notepad-tabs");
@@ -25,6 +26,7 @@ export function createTabs({ onSwitch, onChange }) {
// or text dragged over the bar does nothing.
let dragging = null;
// The tab buttons; each sits in a wrapper with its x.
const buttons = () => Array.from(bar.querySelectorAll(".notepad-tab"));
const buttonFor = (id) => buttons().find((b) => b.dataset.id === id) || null;
const ids = () => tabs.map((t) => t.id);
@@ -43,7 +45,6 @@ export function createTabs({ onSwitch, onChange }) {
const left = e.key === "ArrowLeft";
if (left || e.key === "ArrowRight") {
e.preventDefault();
if (e.altKey) return reorder(moveTab(ids(), id, left ? -1 : 1), id);
const list = buttons();
const at = list.findIndex((b) => b.dataset.id === id);
const next = list[Math.max(0, Math.min(list.length - 1, at + (left ? -1 : 1)))];
@@ -55,6 +56,9 @@ export function createTabs({ onSwitch, onChange }) {
} else if (e.key === "F2") {
e.preventDefault();
onChange({ type: "rename", id });
} else if (e.key === "Delete") {
e.preventDefault();
onChange({ type: "delete", id });
}
}
@@ -82,14 +86,25 @@ export function createTabs({ onSwitch, onChange }) {
dragging = null;
clearMarks();
});
b.addEventListener("dragover", (e) => {
// The x is a button of its own beside the name, so the tab's text stays
// its name and a double-click or a drag on the name never reaches it.
const x = el("button", "notepad-tab-x", "×");
x.type = "button";
x.setAttribute("aria-label", "Delete " + tab.name);
x.title = "Delete tab";
x.tabIndex = active ? 0 : -1;
x.addEventListener("click", () => onChange({ type: "delete", id: tab.id }));
const wrap = el("div", "notepad-tabwrap");
wrap.setAttribute("role", "presentation");
wrap.append(b, x);
wrap.addEventListener("dragover", (e) => {
if (dragging === null) return;
e.preventDefault();
e.dataTransfer.dropEffect = "move";
clearMarks();
if (tab.id !== dragging) b.classList.add("is-drop-before");
});
b.addEventListener("drop", (e) => {
wrap.addEventListener("drop", (e) => {
if (dragging === null) return;
e.preventDefault();
e.stopPropagation();
@@ -98,7 +113,7 @@ export function createTabs({ onSwitch, onChange }) {
clearMarks();
reorder(dropTab(ids(), id, tab.id), id);
});
return b;
return wrap;
}
// Dropping on the empty part of the bar moves the tab to the end.
@@ -131,10 +146,6 @@ export function createTabs({ onSwitch, onChange }) {
const empty = tabs.length === 0;
$("notepad-empty").hidden = !empty;
$("notepad-body").hidden = empty;
$("notepad-tab-tools").hidden = empty;
const at = tabs.findIndex((t) => t.id === activeId);
$("notepad-tab-left").disabled = at <= 0;
$("notepad-tab-right").disabled = at < 0 || at >= tabs.length - 1;
// A long row scrolls the current tab into view.
buttonFor(activeId)?.scrollIntoView?.({ block: "nearest", inline: "nearest" });
},
+15 -37
View File
@@ -21,7 +21,6 @@ import {
cleanTabName,
errorSentence,
keepsText,
moveTab,
nextDelete,
nextSave,
noteBytes,
@@ -246,19 +245,10 @@ async function readNote(tab) {
const nameOf = (id) => (tabs.find((t) => t.id === id) || {}).name || "";
const ids = () => tabs.map((t) => t.id);
function drawTabs() {
tabBar.draw(tabs, activeId);
const none = !activeId;
$("notepad-tab-rename").disabled = none || busy;
$("notepad-tab-delete").disabled = none || busy;
$("notepad-tab-new").disabled = busy;
$("notepad-empty-new").disabled = busy;
if (busy) {
$("notepad-tab-left").disabled = true;
$("notepad-tab-right").disabled = true;
}
$("notepad-name-save").disabled = busy;
}
@@ -342,13 +332,6 @@ async function reorder(order, focus) {
drawTabs();
}
// The current tab one place to the left or right.
function moveCurrent(delta) {
if (!activeId || busy) return;
const order = moveTab(ids(), activeId, delta);
if (order.join() !== ids().join()) reorder(order, activeId);
}
// A tab is no longer there (deleted here, or from another page): off the bar,
// its unsaved text dropped without a save, and its neighbour on screen.
async function gone(id, index = tabs.findIndex((t) => t.id === id), announce = true) {
@@ -387,8 +370,8 @@ function openNameForm(mode) {
closeDelete();
naming = mode;
$("notepad-name-label").textContent = mode === "new" ? "Name this tab" : "Rename this tab";
$("notepad-name-form").hidden = false;
$("notepad-name-error").textContent = "";
if (!$("notepad-name-dlg").open) $("notepad-name-dlg").showModal();
const input = $("notepad-name");
input.value = mode === "rename" ? nameOf(activeId) : "";
input.focus();
@@ -399,7 +382,7 @@ function closeNameForm(toFocus = true) {
if (!naming) return;
const was = naming;
naming = null;
$("notepad-name-form").hidden = true;
$("notepad-name-dlg").close();
if (!toFocus) return;
if (was === "rename") tabBar.focusTab(activeId);
else (tabs.length ? $("notepad-tab-new") : $("notepad-empty-new")).focus();
@@ -456,8 +439,9 @@ async function submitName() {
/* ------------------------------------------------------------ delete */
function paintDelete() {
$("notepad-delete").hidden = stage === "none";
if (stage === "none") return;
const dlg = $("notepad-delete");
if (stage === "none") return void (dlg.open && dlg.close());
if (!dlg.open) dlg.showModal();
const name = nameOf(activeId);
const count = images.filter((img) => img.id).length;
const pics = count === 1 ? "1 picture" : `${count} pictures`;
@@ -914,7 +898,7 @@ export async function openNotepad() {
tell("");
inform("");
naming = null;
$("notepad-name-form").hidden = true;
$("notepad-name-dlg").close();
stage = "none";
paintDelete();
if (!dlg.open) dlg.showModal();
@@ -928,9 +912,12 @@ export function wireNotepad() {
onSwitch: (id) => switchTo(id),
onChange: async (event) => {
if (event.type === "order") return reorder(event.order, event.focus);
// Rename acts on the current tab: a double-click or F2 on another one picks it first.
// Rename and delete act on the current tab: a double-click, F2 or x on
// another one picks it first.
if (event.id && event.id !== activeId) await switchTo(event.id);
if (!event.id || event.id === activeId) openNameForm("rename");
if (event.id && event.id !== activeId) return;
if (event.type === "delete") openDelete();
else openNameForm("rename");
},
});
lightDismiss(dlg);
@@ -940,10 +927,6 @@ export function wireNotepad() {
$("notepad-close").addEventListener("click", () => dlg.close());
$("notepad-tab-new").addEventListener("click", () => openNameForm("new"));
$("notepad-empty-new").addEventListener("click", () => openNameForm("new"));
$("notepad-tab-rename").addEventListener("click", () => openNameForm("rename"));
$("notepad-tab-left").addEventListener("click", () => moveCurrent(-1));
$("notepad-tab-right").addEventListener("click", () => moveCurrent(1));
$("notepad-tab-delete").addEventListener("click", openDelete);
$("notepad-delete-keep").addEventListener("click", () => closeDelete(true));
$("notepad-delete-go").addEventListener("click", confirmDelete);
$("notepad-name-cancel").addEventListener("click", () => closeNameForm());
@@ -951,15 +934,10 @@ export function wireNotepad() {
e.preventDefault();
submitName();
});
// Esc backs out of the name form or the delete question first, and only
// then closes the dialog.
dlg.addEventListener("keydown", (e) => {
if (e.key !== "Escape" || (!naming && stage === "none")) return;
e.preventDefault();
e.stopPropagation();
if (naming) closeNameForm();
else closeDelete(true);
});
// The two small dialogs are modal over the Notebook, so Esc (or any other
// way they close) backs out of them alone and the state follows the dialog.
$("notepad-name-dlg").addEventListener("close", () => closeNameForm());
$("notepad-delete").addEventListener("close", () => closeDelete(true));
dlg.addEventListener("close", () => {
flush();
$("btn-notepad").focus();
+58 -34
View File
@@ -38,7 +38,7 @@
flex: 1 1 auto;
min-height: 0;
border: 1px solid var(--rule-2);
border-radius: 8px;
border-radius: 0;
overflow: hidden;
background: var(--panel);
}
@@ -165,18 +165,35 @@
.notepad-status { margin: 0 auto 0 0; min-height: 1.4em; font-size: 12.5px; color: var(--ink-3); }
.notepad-status.is-problem { color: var(--warn); }
/* The tab bar: a scrolling row of tab buttons with the current one marked,
then New tab. The tools under it act on the current tab. */
.notepad-tabbar { flex: none; display: flex; align-items: flex-end; gap: 8px; margin-bottom: 4px; }
.notepad-tabs { flex: 1 1 auto; min-width: 0; display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; }
.notepad-tab {
/* The tab bar: a scrolling row of tabs, each its name and an x, with the
current one marked, then New tab. A double-click renames, the x deletes and
a drag moves; the questions open in the small dialogs below. */
.notepad-tabbar { flex: none; display: flex; align-items: flex-end; gap: 8px; margin-bottom: -1px; position: relative; z-index: 1; }
.notepad-tabs { flex: 1 1 auto; min-width: 0; display: flex; gap: 4px; overflow-x: auto; padding-bottom: 0; }
.notepad-tabwrap {
flex: none;
max-width: 220px;
padding: 6px 12px;
max-width: 240px;
display: flex;
align-items: center;
border: 1px solid var(--rule-2);
border-radius: 8px 8px 0 0;
background: var(--panel-2);
color: var(--ink-2);
}
.notepad-tabwrap:hover { color: var(--accent); border-color: var(--accent-line); }
.notepad-tabwrap:has(.notepad-tab[aria-selected="true"]) {
background: var(--accent-soft);
border-color: var(--accent);
border-bottom-color: var(--panel);
color: var(--ink);
}
.notepad-tab {
flex: 0 1 auto;
min-width: 0;
padding: 6px 4px 6px 12px;
border: 0;
background: none;
color: inherit;
font: inherit;
font-size: 13px;
line-height: 1.2;
@@ -185,27 +202,37 @@
text-overflow: ellipsis;
white-space: nowrap;
}
.notepad-tab:hover { color: var(--accent); border-color: var(--accent-line); }
.notepad-tab[aria-selected="true"] {
background: var(--accent-soft);
border-color: var(--accent);
color: var(--ink);
font-weight: 600;
.notepad-tab[aria-selected="true"] { font-weight: 600; }
.notepad-tab-x {
flex: none;
width: 20px;
height: 20px;
margin-right: 6px;
padding: 0;
border: 0;
border-radius: 4px;
background: none;
color: inherit;
font: inherit;
font-size: 16px;
line-height: 1;
cursor: pointer;
opacity: 0.6;
}
.notepad-tabwrap:hover .notepad-tab-x,
.notepad-tabwrap:has(.notepad-tab[aria-selected="true"]) .notepad-tab-x,
.notepad-tab-x:focus-visible { opacity: 1; }
.notepad-tab-x:hover { background: var(--panel); color: var(--warn); }
.notepad-tab:focus-visible,
.notepad-tab-x:focus-visible,
.notepad-tab-new:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.notepad-tab.is-dragging { opacity: 0.5; }
.notepad-tab.is-drop-before { box-shadow: -3px 0 0 0 var(--accent); }
.notepad-tabwrap:has(.is-dragging) { opacity: 0.5; }
.notepad-tabwrap:has(.is-drop-before) { box-shadow: -3px 0 0 0 var(--accent); }
.notepad-tabs.is-drop-end { box-shadow: inset -3px 0 0 0 var(--accent); }
.notepad-tab-new { flex: none; margin-bottom: 2px; }
.notepad-tab-tools { flex: none; display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 8px; }
.notepad-tab-tools[hidden] { display: none; }
.notepad-tab-tools .btn.tiny { margin-bottom: 0; }
.notepad-tab-new { flex: none; margin-bottom: 4px; }
/* The name form (New tab and Rename) and the delete question sit between the
tools and the editor, in the dialog, never in a browser prompt. */
.notepad-name-form,
.notepad-delete,
/* The name and delete questions: small dialogs over the Notebook, never a
browser prompt. The empty state sits where the editor would. */
.notepad-empty {
flex: none;
margin: 0 0 10px;
@@ -214,14 +241,12 @@
border-radius: 8px;
background: var(--panel-2);
}
.notepad-name-form[hidden],
.notepad-delete[hidden],
.notepad-empty[hidden] { display: none; }
.notepad-name-form label { display: block; margin-bottom: 6px; font-size: 13px; font-weight: 600; }
.notepad-name-row { display: flex; gap: 8px; align-items: center; }
.notepad-name-row input {
flex: 1 1 auto;
min-width: 0;
.modal.notepad-sub { width: min(420px, calc(100vw - 32px)); }
.modal.notepad-sub h2 { margin: 0 0 10px; }
.notepad-name-form input {
display: block;
width: 100%;
padding: 6px 8px;
border: 1px solid var(--rule-2);
border-radius: 6px;
@@ -229,12 +254,11 @@
color: var(--ink);
font: inherit;
}
.notepad-name-row input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.notepad-name-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.notepad-name-error { min-height: 1.2em; margin: 6px 0 0; }
.notepad-name-error:not(:empty) { color: var(--warn); }
.modal.notepad-delete { border-color: var(--warn); }
.notepad-delete p { margin: 0 0 8px; }
.notepad-delete { border-color: var(--warn); }
.notepad-delete-row { display: flex; gap: 8px; }
.notepad-empty { text-align: center; padding: 28px 12px; }
.notepad-empty p { margin: 0 0 12px; color: var(--ink-2); }
/* Editor and pictures together, so the empty state hides both at once. */
+4 -5
View File
@@ -64,11 +64,10 @@
.notepad-images { flex-direction: column; align-items: stretch; }
.notepad-tabbar { flex-wrap: wrap; }
.modal.notepad .notepad-tab-new,
.modal.notepad .notepad-tab-tools .btn,
.modal.notepad .notepad-name-row .btn,
.modal.notepad .notepad-delete-row .btn,
.notepad-tab { min-height: 44px; }
.notepad-name-row { flex-wrap: wrap; }
.modal.notepad-sub .modal-actions .btn,
.notepad-tab,
.notepad-tab-x { min-height: 44px; }
.notepad-tab-x { width: 32px; }
.notepad-add { align-self: flex-start; }
.notepad-thumb .notepad-thumb-delete { width: 30px; height: 30px; font-size: 18px; }
.modal.notepad-preview[open] { grid-template-columns: 52px minmax(0, 1fr) 52px; }