Enable page refreshes with morphing

Update Trix to a compatible version https://github.com/basecamp/house/tree/morphing-2
This commit is contained in:
Jorge Manrubia
2025-04-02 16:19:24 +02:00
parent f7e2d04808
commit 5a740a4251
5 changed files with 57 additions and 12 deletions
@@ -1,5 +1,5 @@
import { Controller } from "@hotwired/stimulus"
import { debounce } from "helpers/timing_helpers"
import { debounce, nextFrame } from "helpers/timing_helpers"
export default class extends Controller {
static targets = ["input"]
@@ -10,7 +10,7 @@ export default class extends Controller {
}
connect() {
this.#restoreContent()
this.restoreContent()
}
submit({ detail: { success } }) {
@@ -28,20 +28,22 @@ export default class extends Controller {
}
}
// Private
#clear() {
localStorage.removeItem(this.keyValue)
}
#restoreContent() {
async restoreContent() {
await nextFrame()
const savedContent = localStorage.getItem(this.keyValue)
if (savedContent) {
this.inputTarget.value = savedContent
this.#triggerChangeEvent(savedContent)
}
}
// Private
#clear() {
localStorage.removeItem(this.keyValue)
}
#triggerChangeEvent(newValue) {
if (this.inputTarget.tagName === "HOUSE-MD") {
this.inputTarget.dispatchEvent(new CustomEvent('house-md:change', {