Replace unsupported window prompt/confirm/alert with an in-app modal dialog

This commit is contained in:
avi 2026-08-17 11:15:14 -05:00
commit 17a895dffe
5 changed files with 218 additions and 22 deletions

View file

@ -69,6 +69,19 @@ const BOOK_DIR = __BOOKDIR_VALUE__;
out.orderAfterKb = orderKb;
out.kbMoved = orderKb[0] === orderAfter[1] && orderKb[1] === orderAfter[0];
// UI-driven chapter creation via the in-app modal (window.prompt is unsupported)
const countBefore = (await window.folio.getBookMeta()).chapterOrder.length;
document.getElementById("addChapterBtn").click();
await new Promise((r) => setTimeout(r, 80));
const modalInput = document.getElementById("modalInput");
out.modalShown = !!modalInput && !document.getElementById("modalBackdrop").classList.contains("hidden");
modalInput.value = "Via Modal";
document.getElementById("modalOk").click();
await new Promise((r) => setTimeout(r, 300));
const metaAfterUi = await window.folio.getBookMeta();
out.uiCreated = metaAfterUi.chapterOrder.length === countBefore + 1 &&
Object.values(metaAfterUi.chapters).some((c) => c.title === "Via Modal");
out.all = true;
} catch (e) {
out.error = String((e && e.message) || e);