rename template

This commit is contained in:
Pete Matsyburka committed 2026-09-23 10:59:54 +03:00
1 parent 9678cd1286
commit ca009252ac
8 files changed
+159 -34

No files matched your search

+20 -5
View File
@@ -1,16 +1,27 @@
export default class extends HTMLElement {
connectedCallback () {
this.addEventListener('click', this.dispatch)
if (this.dataset.on === 'submit') {
document.addEventListener('turbo:submit-end', this.onSubmitEnd)
} else {
this.addEventListener('click', this.dispatch)
}
}
disconnectedCallback () {
document.removeEventListener('turbo:submit-end', this.onSubmitEnd)
this.removeEventListener('click', this.dispatch)
}
dispatch = async () => {
const bridge = window.webkit?.messageHandlers?.modal
onSubmitEnd = async (e) => {
const form = e.detail.formSubmission?.formElement
if (!bridge || this.dataset.loading) return
if (!e.detail.success || !form || !this.contains(form)) return
this.post(JSON.stringify({ form: form.id, action: form.action, body: await e.detail.fetchResponse.responseText }))
}
dispatch = async () => {
if (this.dataset.loading) return
let detail = this.dataset.detail || 'null'
@@ -30,6 +41,10 @@ export default class extends HTMLElement {
}
}
bridge.postMessage({ action: 'dispatch', name: this.dataset.name, detail })
this.post(detail)
}
post (detail) {
window.webkit?.messageHandlers?.modal?.postMessage({ action: 'dispatch', name: this.dataset.name, detail, dismiss: this.dataset.dismiss || 'true' })
}
}