FIX: don't reset open state on details tag when morphing (#702)

This commit is contained in:
Régis Hanol 2024-07-05 00:07:28 +02:00 committed by GitHub
parent 442681a3d3
commit d555f18c6f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 11 additions and 7 deletions

View File

@ -67,6 +67,12 @@ class StreamUpdater {
}
class PostUpdater extends StreamUpdater {
morphingOptions = {
beforeAttributeUpdated: (element, attributeName) => {
return !(element.tagName === "DETAILS" && attributeName === "open");
},
};
constructor(postStream, postId) {
super();
this.postStream = postStream;
@ -116,13 +122,11 @@ class PostUpdater extends StreamUpdater {
async setCooked(value) {
this.post.set("cooked", value);
const oldElement = this.postElement.querySelector(".cooked");
// TODO: use `morphInner` once version morphlex 0.0.16 is out
const newElement = oldElement.cloneNode(false);
newElement.innerHTML = value;
(await loadMorphlex()).morph(oldElement, newElement);
(await loadMorphlex()).morphInner(
this.postElement.querySelector(".cooked"),
`<div>${value}</div>`,
this.morphingOptions
);
}
get raw() {