Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ <h1><button id="browse-button" aria-haspopup="dialog" aria-controls="entries"><s
<textarea id="page" aria-label="Note" spellcheck="true" autocapitalize="sentences"></textarea>
<section id="draft-conflict" hidden aria-label="Conflicting note" aria-live="polite">
<p>This note changed elsewhere. Copy your text before using the saved version.</p>
<p id="deleted-copy-feedback" hidden></p>
<button id="copy-conflicting-text" type="button">Copy my text</button>
<button id="start-new-after-deletion" type="button" hidden>Start a new page</button>
<button id="use-saved-version" type="button">Use saved version</button>
</section>
</main>
Expand Down
14 changes: 8 additions & 6 deletions public/journal.css

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 27 additions & 6 deletions src/view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase:
};
const page = element<HTMLTextAreaElement>("page");
const menu = element<HTMLDialogElement>("menu");
const copyFeedback = element("deleted-copy-feedback");
const typeChoice = element<HTMLSelectElement>("entry-type");
const status = element("status");
const pending = element("pending-count");
Expand Down Expand Up @@ -69,6 +70,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase:
let inputEpoch = 0;
let displayedRecordRevision: string | null = null;
let conflicted = false;
let deletedCopyFeedback = "";
const retrying = new Set<string>();
const edited = new Set<string>();
const preferences = drafts.preferences();
Expand Down Expand Up @@ -156,6 +158,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase:
}
let renderedDraftId = current.id;
function renderPage(): void {
deletedCopyFeedback = "";
if (renderedDraftId !== current.id) conflicted = false;
renderedDraftId = current.id;
displayedRecordRevision = data?.snapshot(current.id)?.record.revision ?? null;
Expand Down Expand Up @@ -187,7 +190,11 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase:
conflicted = conflicted || current.reviewRequired === true || observed?.state === "conflict";
element("draft-conflict").hidden = !conflicted && !current.deletedElsewhere;
element("draft-conflict").setAttribute("aria-label", current.deletedElsewhere ? "Deleted entry" : "Conflicting note");
element("draft-conflict").querySelector("p")!.textContent = current.deletedElsewhere ? `${DELETED_ENTRY_NOTICE} Copy it to keep writing in a new page.` : "This note changed elsewhere. Copy your text before using the saved version.";
element("draft-conflict").querySelector("p")!.textContent = current.deletedElsewhere ? DELETED_ENTRY_NOTICE : "This note changed elsewhere. Copy your text before using the saved version.";
if (!current.deletedElsewhere) deletedCopyFeedback = "";
copyFeedback.hidden = !deletedCopyFeedback;
if (copyFeedback.textContent !== deletedCopyFeedback) copyFeedback.textContent = deletedCopyFeedback;
element("start-new-after-deletion").hidden = !current.deletedElsewhere;
element("use-saved-version").hidden = !!current.deletedElsewhere;
element<HTMLButtonElement>("use-saved-version").disabled = !!current.deletedElsewhere || current.reviewRequired === true && !data;
if (entriesDialog.open) renderEntries();
Expand Down Expand Up @@ -276,7 +283,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase:
typeChoice.replaceChildren(option("Choose a type…", ""), ...types.map(item => option(item.name, item.name)));
typeChoice.value = type?.name ?? "";
element("type-row").hidden = types.length < 2;
element("new-button").hidden = !current.body.trim();
element("new-button").hidden = !current.body.trim() || !!current.deletedElsewhere;
element("undo-button").hidden = !undoId;
const retryCurrent = recovering(current.id), retryElement = element<HTMLButtonElement>("retry-button");
retryElement.hidden = !retryCurrent; retryButton(retryElement, current.id);
Expand Down Expand Up @@ -310,7 +317,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase:
element("word-count").hidden = words === 0;
}
function newPage(): void {transaction(() => {
if (!current.body.trim()) {page.focus(); return;}
if (!current.body.trim() && !current.deletedElsewhere) {page.focus(); return;}
if (memoryOnly) {problem = "Keep this page open: its text has not been preserved on this device."; render(); return;}
const previous = current;
try {
Expand Down Expand Up @@ -562,6 +569,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase:
}
listen(page, "input", () => {
clearUndo();
deletedCopyFeedback = "";
const body = page.value, base = current, wasUnpersisted = unpersistedDraft, owned = data;
const source = {body: base.body, revision: displayedRecordRevision}, epoch = ++inputEpoch;
current = {...base, body, revision: draftRevision(body)};
Expand Down Expand Up @@ -591,6 +599,7 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase:
if (viewport) listen(viewport, "resize", () => document.defaultView?.requestAnimationFrame(revealCaret));
listen(document, "keydown", event => {const key = event as KeyboardEvent; if ((key.ctrlKey || key.metaKey) && key.key === "Enter" && key.target === page && !document.querySelector("dialog[open]")) {key.preventDefault(); newPage();}});
listen(element("new-button"), "click", newPage);
listen(element("start-new-after-deletion"), "click", newPage);
listen(element("undo-button"), "click", undoNewPage);
listen(element("retry-button"), "click", () => retry(current.id));
let menuOpener: HTMLElement | null = null;
Expand Down Expand Up @@ -669,10 +678,22 @@ export function mountJournal(document: Document, drafts: JournalDrafts, mdbase:
applyTheme();
const unlistenApp = mdbase?.subscribe(() => transaction(changed)) ?? (() => {});
if (document.defaultView) for (const name of ["online", "offline"]) listen(document.defaultView, name, render);
listen(element("copy-conflicting-text"), "click", () => {
listen(element("copy-conflicting-text"), "click", async () => {
const clipboard = document.defaultView?.navigator.clipboard;
if (!clipboard) {page.focus(); page.select(); problem = current.deletedElsewhere ? "Your text is selected. Copy it before starting a new page." : "Your text is selected. Copy it before using the saved version."; render(); return;}
void clipboard.writeText(page.value).then(() => {problem = current.deletedElsewhere ? "Text copied. Start a new page to keep writing." : "Text copied. You can now use the saved version."; render();}, () => {page.focus(); page.select(); problem = current.deletedElsewhere ? "Copy your selected text before starting a new page." : "Copy your selected text before using the saved version."; render();});
const id = current.id, epoch = inputEpoch, body = page.value;
let copied = false;
if (clipboard) {
try {await clipboard.writeText(body); copied = true;}
catch {/* Clipboard access can be denied. Select the text for manual copying. */}
}
if (disposed || current.id !== id || inputEpoch !== epoch || page.value !== body) return;
if (!copied) {page.focus(); page.select();}
if (current.deletedElsewhere) {
deletedCopyFeedback = copied ? "Text copied." : "Your text is selected. Copy it before starting a new page.";
} else {
problem = copied ? "Text copied. You can now use the saved version." : "Your text is selected. Copy it before using the saved version.";
}
render();
});
listen(element("use-saved-version"), "click", () => {
const id = current.id, chosenEpoch = inputEpoch;
Expand Down
15 changes: 14 additions & 1 deletion tests/deleted-entries.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ for (const body of ["Unsaved local text", ""]) test(`a deleted record retains an
assert.equal(window.document.getElementById("draft-conflict")!.hidden, false);
assert.equal(window.document.getElementById("use-saved-version")!.hidden, true);
window.document.getElementById("copy-conflicting-text")!.click();
assert.match(window.document.getElementById("status")!.textContent!, /Copy it before starting a new page/);
assert.match(window.document.getElementById("draft-conflict")!.textContent!, /Your text is selected\. Copy it before starting a new page/);
assert.match(window.document.getElementById("status")!.textContent!, /deleted elsewhere.*text.*device/i);
assert.equal(drafts.get(draft.id)?.savedBody, "Saved entry");
view.dispose(); window.close();
window = windowForJournal(); view = mountJournal(window.document, new JournalDrafts(storage), h.mdbase);
Expand Down Expand Up @@ -223,6 +224,18 @@ test("a queued autosave rejected as deleted offers to copy the unsaved text with
assert.equal(window.document.getElementById("use-saved-version")!.hidden, true);
window.document.getElementById("copy-conflicting-text")!.click();
assert.equal(await copied.promise, unsaved);
await until(() => !!recovery.textContent?.includes("Text copied"));
assert.equal(recovery.hidden, false);
assert.match(recovery.textContent!, /deleted elsewhere.*text.*device/i);
assert.match(status.textContent!, /deleted elsewhere.*text.*device/i);
assert.match(window.document.getElementById("status-button")!.getAttribute("aria-label")!, /^Journal settings\./);
const startNew = recovery.querySelector<HTMLButtonElement>("#start-new-after-deletion")!;
assert.equal(startNew.hidden, false);
startNew.click();
await until(() => view.currentDraft().id !== draft.id);
assert.equal(recovery.hidden, true);
assert.equal(page.value, "");
assert.equal(drafts.get(draft.id)?.body, unsaved);
assert.equal(await h.records.find(recordId), null);
assert.equal(update.mock.callCount(), 1);
assert.equal(create.mock.callCount(), 0);
Expand Down
22 changes: 22 additions & 0 deletions tests/setup-conflicts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,28 @@ function needsSetupSnapshot(ready: Awaited<ReturnType<typeof applicationFixture>
};
}

test("the collection panel footer stays in the scrollable Settings sheet during setup conflict", async () => {
const f = await applicationFixture();
const h = dom();
const {document} = h.window;
const style = document.createElement("style");
style.textContent = readFileSync(new URL("../public/journal.css", import.meta.url), "utf8");
document.head.append(style);
f.fixture.controls.setSetupPlan(nonAdoptablePlan());
f.fixture.controls.publishSnapshot({...needsSetupSnapshot(f.ready), links: {account: "https://fixture.example/account", manageAccess: "https://fixture.example/access"}});
const view = mountJournal(document, new JournalDrafts(memoryStorage()), f.mdbase);
try {
h.click("status-button");
const panelFooter = await until(() => h.menu.querySelector("#collection-panel footer") ?? undefined);
assert.equal(h.menu.open, true);
assert.match(panelFooter.textContent!, /Choose a different collection/);
assert.equal(panelFooter.querySelector("a")?.textContent, "Manage access");
assert.equal(h.window.getComputedStyle(document.querySelector("body > footer")!).position, "fixed");
assert.notEqual(h.window.getComputedStyle(panelFooter).position, "fixed");
assert.equal(h.window.getComputedStyle(h.menu).overflowY, "auto");
} finally {view.dispose(); h.window.close(); await f.fixture.close();}
});

test("backupPathFor produces safe non-record, non-resource backup paths", () => {
const date = new Date("2026-11-27T08:30:15Z");
const path = backupPathFor(CONTRACT_TARGET, date, "journal-setup-backups", "abc123");
Expand Down
2 changes: 2 additions & 0 deletions tests/view.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ test("the ready writing page has one level-one heading naming the current journa
const h = dom(), f = await applicationFixture();
const view = mountJournal(h.window.document, new JournalDrafts(memoryStorage()), f.mdbase);
try {
await until(() => h.window.document.getElementById("menu-connection")!.textContent === "Notes save to Writing.");
const headings = h.window.document.querySelectorAll("h1");
assert.equal(headings.length, 1);
const date = h.window.document.querySelector("#browse-button")!.textContent!.trim();
assert.ok(date);
assert.equal(headings[0]!.textContent!.trim(), date);
assert.equal(headings[0]!.querySelector("#browse-button")?.getAttribute("aria-controls"), "entries");
assert.equal(headings[0]!.closest("dialog, [hidden], [aria-hidden=true]"), null);
} finally {view.dispose(); f.close(); h.window.close();}
});
Expand Down