2023-05-21 17:59:36 +03:00
|
|
|
import '@hotwired/turbo-rails'
|
|
|
|
|
|
|
|
|
|
import ToggleVisible from './elements/toggle_visible'
|
|
|
|
|
import DisableHidden from './elements/disable_hidden'
|
|
|
|
|
import TurboModal from './elements/turbo_modal'
|
2023-05-28 23:20:48 +03:00
|
|
|
import FileDropzone from './elements/file_dropzone'
|
2023-05-30 00:55:14 +03:00
|
|
|
import MenuActive from './elements/menu_active'
|
2023-06-03 21:22:03 +03:00
|
|
|
import ClipboardCopy from './elements/clipboard_copy'
|
2023-06-17 20:22:21 +00:00
|
|
|
import DynamicList from './elements/dynamic_list'
|
2023-06-20 22:38:38 +03:00
|
|
|
import DownloadButton from './elements/download_button'
|
2023-06-20 23:42:56 +03:00
|
|
|
import SetOriginUrl from './elements/set_origin_url'
|
2023-05-21 17:59:36 +03:00
|
|
|
|
2023-05-29 23:08:55 +03:00
|
|
|
document.addEventListener('turbo:before-cache', () => {
|
|
|
|
|
window.flash?.remove()
|
|
|
|
|
})
|
|
|
|
|
|
2023-06-04 01:08:45 +03:00
|
|
|
document.addEventListener('keyup', (e) => {
|
|
|
|
|
if (e.code === 'Escape') {
|
|
|
|
|
document.activeElement?.blur()
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
|
2023-05-21 17:59:36 +03:00
|
|
|
window.customElements.define('toggle-visible', ToggleVisible)
|
|
|
|
|
window.customElements.define('disable-hidden', DisableHidden)
|
|
|
|
|
window.customElements.define('turbo-modal', TurboModal)
|
2023-05-28 23:20:48 +03:00
|
|
|
window.customElements.define('file-dropzone', FileDropzone)
|
2023-05-30 00:55:14 +03:00
|
|
|
window.customElements.define('menu-active', MenuActive)
|
2023-06-03 21:22:03 +03:00
|
|
|
window.customElements.define('clipboard-copy', ClipboardCopy)
|
2023-06-17 20:22:21 +00:00
|
|
|
window.customElements.define('dynamic-list', DynamicList)
|
2023-06-20 22:38:38 +03:00
|
|
|
window.customElements.define('download-button', DownloadButton)
|
2023-06-20 23:42:56 +03:00
|
|
|
window.customElements.define('set-origin-url', SetOriginUrl)
|
2023-05-21 17:59:36 +03:00
|
|
|
|
2023-05-31 23:19:20 +03:00
|
|
|
window.customElements.define('template-builder', class extends HTMLElement {
|
2023-06-24 18:31:12 +03:00
|
|
|
async connectedCallback () {
|
|
|
|
|
const [
|
|
|
|
|
{ createApp, reactive },
|
|
|
|
|
{ default: TemplateBuilder }
|
|
|
|
|
] = await Promise.all([
|
|
|
|
|
import('vue'),
|
|
|
|
|
import('./template_builder/builder')
|
|
|
|
|
])
|
|
|
|
|
|
|
|
|
|
this.appElem = this.children[0]
|
2023-05-21 17:59:36 +03:00
|
|
|
|
2023-05-31 23:19:20 +03:00
|
|
|
this.app = createApp(TemplateBuilder, {
|
|
|
|
|
template: reactive(JSON.parse(this.dataset.template))
|
2023-05-21 17:59:36 +03:00
|
|
|
})
|
|
|
|
|
|
2023-06-04 01:08:45 +03:00
|
|
|
this.app.config.globalProperties.$t = (key) => TemplateBuilder.i18n[key] || key
|
|
|
|
|
|
2023-05-21 17:59:36 +03:00
|
|
|
this.app.mount(this.appElem)
|
|
|
|
|
|
|
|
|
|
this.appendChild(this.appElem)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
disconnectedCallback () {
|
|
|
|
|
this.app?.unmount()
|
|
|
|
|
}
|
|
|
|
|
})
|