Files
docuseal/app/javascript/application.js
T

180 lines
7.0 KiB
JavaScript
Raw Normal View History

2023-07-02 17:56:14 +03:00
import '@hotwired/turbo'
import { encodeMethodIntoRequestBody } from '@hotwired/turbo-rails/app/javascript/turbo/fetch_requests'
2023-05-21 17:59:36 +03:00
2023-06-24 22:50:12 +03:00
import { createApp, reactive } from 'vue'
import TemplateBuilder from './template_builder/builder'
2024-03-30 19:37:48 +02:00
import ImportList from './template_builder/import_list'
2023-06-24 22:50:12 +03:00
2023-05-21 17:59:36 +03:00
import ToggleVisible from './elements/toggle_visible'
2024-04-03 00:59:25 +03:00
import ToggleCookies from './elements/toggle_cookies'
2023-05-21 17:59:36 +03:00
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'
import SetOriginUrl from './elements/set_origin_url'
2023-06-30 01:26:13 +03:00
import SetTimezone from './elements/set_timezone'
2023-07-01 01:09:44 +03:00
import AutoresizeTextarea from './elements/autoresize_textarea'
2023-09-20 02:00:00 +03:00
import SubmittersAutocomplete from './elements/submitter_autocomplete'
2023-09-22 02:20:38 +03:00
import FolderAutocomplete from './elements/folder_autocomplete'
2023-09-22 21:50:39 +03:00
import SignatureForm from './elements/signature_form'
2023-10-28 23:07:18 +03:00
import SubmitForm from './elements/submit_form'
2024-01-14 23:22:41 +02:00
import PromptPassword from './elements/prompt_password'
2024-03-16 22:18:43 +02:00
import EmailsTextarea from './elements/emails_textarea'
2024-04-17 16:08:58 +03:00
import ToggleOnSubmit from './elements/toggle_on_submit'
2025-05-26 13:32:32 +03:00
import CheckOnClick from './elements/check_on_click'
2024-08-01 21:37:42 +03:00
import PasswordInput from './elements/password_input'
2024-08-14 16:34:30 +03:00
import SearchInput from './elements/search_input'
2024-09-06 19:30:49 +03:00
import ToggleAttribute from './elements/toggle_attribute'
import LinkedInput from './elements/linked_input'
2024-09-12 17:31:37 +03:00
import CheckboxGroup from './elements/checkbox_group'
2024-10-25 16:03:52 +03:00
import MaskedInput from './elements/masked_input'
2024-11-20 22:49:06 +02:00
import SetDateButton from './elements/set_date_button'
2024-12-19 17:17:34 +02:00
import IndeterminateCheckbox from './elements/indeterminate_checkbox'
2025-02-21 23:56:18 +02:00
import AppTour from './elements/app_tour'
2025-04-25 21:19:28 +03:00
import DashboardDropzone from './elements/dashboard_dropzone'
2023-05-21 17:59:36 +03:00
2023-07-02 17:56:14 +03:00
import * as TurboInstantClick from './lib/turbo_instant_click'
TurboInstantClick.start()
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-07-02 17:56:14 +03:00
document.addEventListener('turbo:before-fetch-request', encodeMethodIntoRequestBody)
2023-08-20 15:18:15 +03:00
document.addEventListener('turbo:submit-end', async (event) => {
const resp = event.detail?.formSubmission?.result?.fetchResponse?.response
if (!resp?.headers?.get('content-disposition')?.includes('attachment')) {
return
}
const url = URL.createObjectURL(await resp.blob())
const link = document.createElement('a')
link.href = url
link.setAttribute('download', decodeURIComponent(resp.headers.get('content-disposition').split('"')[1]))
document.body.appendChild(link)
link.click()
document.body.removeChild(link)
URL.revokeObjectURL(url)
})
2023-07-02 17:56:14 +03:00
2024-05-23 13:44:00 +03:00
const safeRegisterElement = (name, element, options = {}) => !window.customElements.get(name) && window.customElements.define(name, element, options)
safeRegisterElement('toggle-visible', ToggleVisible)
safeRegisterElement('disable-hidden', DisableHidden)
safeRegisterElement('turbo-modal', TurboModal)
safeRegisterElement('file-dropzone', FileDropzone)
safeRegisterElement('menu-active', MenuActive)
safeRegisterElement('clipboard-copy', ClipboardCopy)
safeRegisterElement('dynamic-list', DynamicList)
safeRegisterElement('download-button', DownloadButton)
safeRegisterElement('set-origin-url', SetOriginUrl)
safeRegisterElement('set-timezone', SetTimezone)
safeRegisterElement('autoresize-textarea', AutoresizeTextarea)
safeRegisterElement('submitters-autocomplete', SubmittersAutocomplete)
safeRegisterElement('folder-autocomplete', FolderAutocomplete)
safeRegisterElement('signature-form', SignatureForm)
safeRegisterElement('submit-form', SubmitForm)
safeRegisterElement('prompt-password', PromptPassword)
safeRegisterElement('emails-textarea', EmailsTextarea)
safeRegisterElement('toggle-cookies', ToggleCookies)
safeRegisterElement('toggle-on-submit', ToggleOnSubmit)
2024-08-01 21:37:42 +03:00
safeRegisterElement('password-input', PasswordInput)
2024-08-14 16:34:30 +03:00
safeRegisterElement('search-input', SearchInput)
2024-09-06 19:30:49 +03:00
safeRegisterElement('toggle-attribute', ToggleAttribute)
safeRegisterElement('linked-input', LinkedInput)
2024-09-12 17:31:37 +03:00
safeRegisterElement('checkbox-group', CheckboxGroup)
2024-10-25 16:03:52 +03:00
safeRegisterElement('masked-input', MaskedInput)
2024-11-20 22:49:06 +02:00
safeRegisterElement('set-date-button', SetDateButton)
2024-12-19 17:17:34 +02:00
safeRegisterElement('indeterminate-checkbox', IndeterminateCheckbox)
2025-02-21 23:56:18 +02:00
safeRegisterElement('app-tour', AppTour)
2025-04-25 21:19:28 +03:00
safeRegisterElement('dashboard-dropzone', DashboardDropzone)
2025-05-26 13:32:32 +03:00
safeRegisterElement('check-on-click', CheckOnClick)
2024-05-23 13:44:00 +03:00
safeRegisterElement('template-builder', class extends HTMLElement {
2023-06-24 22:50:12 +03:00
connectedCallback () {
2024-09-06 19:30:49 +03:00
document.addEventListener('turbo:submit-end', this.onSubmit)
2023-06-24 22:50:12 +03:00
this.appElem = document.createElement('div')
2023-05-21 17:59:36 +03:00
2023-11-24 22:44:27 +02:00
this.appElem.classList.add('md:h-screen')
2023-05-31 23:19:20 +03:00
this.app = createApp(TemplateBuilder, {
template: reactive(JSON.parse(this.dataset.template)),
2023-08-28 23:43:33 +03:00
backgroundColor: '#faf7f5',
2024-08-05 19:38:47 +03:00
locale: this.dataset.locale,
2023-09-05 01:00:21 +03:00
withPhone: this.dataset.withPhone === 'true',
2024-12-01 00:10:07 +02:00
withVerification: ['true', 'false'].includes(this.dataset.withVerification) ? this.dataset.withVerification === 'true' : null,
2023-10-08 12:04:32 +03:00
withLogo: this.dataset.withLogo !== 'false',
editable: this.dataset.editable !== 'false',
2024-03-23 23:16:40 +02:00
authenticityToken: document.querySelector('meta[name="csrf-token"]')?.content,
2023-12-30 11:42:46 +02:00
withPayment: this.dataset.withPayment === 'true',
2024-03-29 22:51:58 +02:00
isPaymentConnected: this.dataset.isPaymentConnected === 'true',
2024-02-24 01:01:36 +02:00
withFormula: this.dataset.withFormula === 'true',
2024-08-26 11:30:52 +03:00
withSendButton: this.dataset.withSendButton !== 'false',
withSignYourselfButton: this.dataset.withSignYourselfButton !== 'false',
2024-03-01 23:29:37 +02:00
withConditions: this.dataset.withConditions === 'true',
2025-05-09 00:01:50 +03:00
withReplaceAndCloneUpload: true,
2024-01-26 10:43:32 +02:00
currencies: (this.dataset.currencies || '').split(',').filter(Boolean),
2025-02-21 23:56:18 +02:00
acceptFileTypes: this.dataset.acceptFileTypes,
showTourStartForm: this.dataset.showTourStartForm === 'true'
2023-05-21 17:59:36 +03:00
})
2024-09-06 19:30:49 +03:00
this.component = this.app.mount(this.appElem)
2023-05-21 17:59:36 +03:00
this.appendChild(this.appElem)
}
2024-09-06 19:30:49 +03:00
onSubmit = (e) => {
if (e.detail.success && e.detail?.formSubmission?.formElement?.id === 'submitters_form') {
e.detail.fetchResponse.response.json().then((data) => {
this.component.template.submitters = data.submitters
})
}
}
2023-05-21 17:59:36 +03:00
disconnectedCallback () {
2024-09-06 19:30:49 +03:00
document.removeEventListener('turbo:submit-end', this.onSubmit)
2023-05-21 17:59:36 +03:00
this.app?.unmount()
2023-06-24 22:50:12 +03:00
this.appElem?.remove()
2023-05-21 17:59:36 +03:00
}
})
2024-03-30 19:37:48 +02:00
2024-05-23 13:44:00 +03:00
safeRegisterElement('import-list', class extends HTMLElement {
2024-03-30 19:37:48 +02:00
connectedCallback () {
this.appElem = document.createElement('div')
this.app = createApp(ImportList, {
template: JSON.parse(this.dataset.template),
2024-07-04 17:59:08 +03:00
multitenant: this.dataset.multitenant === 'true',
2024-09-23 15:22:07 +03:00
authenticityToken: document.querySelector('meta[name="csrf-token"]')?.content,
i18n: JSON.parse(this.dataset.i18n || '{}')
2024-03-30 19:37:48 +02:00
})
this.app.mount(this.appElem)
this.appendChild(this.appElem)
}
disconnectedCallback () {
this.app?.unmount()
this.appElem?.remove()
}
})