feat(editor): re-init CM6 on htmx:afterSwap into #modal-content
editor.js exposes initEditors(root) and listens for htmx:afterSwap so editor textareas that arrive via modal swap get CM6 mounted. The DOMContentLoaded path remains for first-paint mounting. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
afd2ed1c3c
commit
f426970d4c
1 changed files with 18 additions and 5 deletions
|
|
@ -86,18 +86,31 @@
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function init() {
|
function initEditors(root) {
|
||||||
for (const ta of document.querySelectorAll("textarea[data-editor-language]")) {
|
const scope = root || document;
|
||||||
|
for (const ta of scope.querySelectorAll("textarea[data-editor-language]")) {
|
||||||
mountOne(ta).catch(err => {
|
mountOne(ta).catch(err => {
|
||||||
console.error("[editor] mount failed", err);
|
console.error("[editor] mount failed", err);
|
||||||
unhideTextarea(ta); // restore the form-usable raw textarea
|
unhideTextarea(ta);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (document.readyState === "loading") {
|
if (document.readyState === "loading") {
|
||||||
document.addEventListener("DOMContentLoaded", init);
|
document.addEventListener("DOMContentLoaded", () => initEditors(document));
|
||||||
} else {
|
} else {
|
||||||
init();
|
initEditors(document);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Re-init editors that arrive via HTMX swap (modal content, etc.).
|
||||||
|
document.body.addEventListener("htmx:afterSwap", (event) => {
|
||||||
|
if (event.target && event.target.id === "modal-content") {
|
||||||
|
initEditors(event.target);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Expose for callers that need to re-mount imperatively.
|
||||||
|
if (window.__editor) {
|
||||||
|
window.__editor.initEditors = initEditors;
|
||||||
}
|
}
|
||||||
})();
|
})();
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue