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'
|
2023-06-20 23:42:56 +03:00
|
|
|
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'
|
2026-05-21 14:50:30 +03:00
|
|
|
import ConvertUpload from './elements/convert_upload'
|
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'
|
2025-09-27 11:40:16 +03:00
|
|
|
import ToggleSubmit from './elements/toggle_submit'
|
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-09-24 12:07:54 +03:00
|
|
|
import AppTourStart from './elements/app_tour_start'
|
2025-04-25 21:19:28 +03:00
|
|
|
import DashboardDropzone from './elements/dashboard_dropzone'
|
2025-06-13 16:14:19 +03:00
|
|
|
import RequiredCheckboxGroup from './elements/required_checkbox_group'
|
2025-07-14 12:53:15 +03:00
|
|
|
import PageContainer from './elements/page_container'
|
2025-07-24 09:41:57 +03:00
|
|
|
import EmailEditor from './elements/email_editor'
|
2026-02-21 11:05:45 +02:00
|
|
|
import MarkdownEditor from './elements/markdown_editor'
|
2025-07-30 10:22:38 +03:00
|
|
|
import MountOnClick from './elements/mount_on_click'
|
2025-09-24 12:07:54 +03:00
|
|
|
import RemoveOnEvent from './elements/remove_on_event'
|
|
|
|
|
import ScrollTo from './elements/scroll_to'
|
|
|
|
|
import SetValue from './elements/set_value'
|
|
|
|
|
import ReviewForm from './elements/review_form'
|
|
|
|
|
import ShowOnValue from './elements/show_on_value'
|
|
|
|
|
import ToggleClasses from './elements/toggle_classes'
|
2025-09-24 15:45:04 +03:00
|
|
|
import AutosizeField from './elements/autosize_field'
|
2025-10-09 16:43:11 +03:00
|
|
|
import GoogleDriveFilePicker from './elements/google_drive_file_picker'
|
|
|
|
|
import OpenModal from './elements/open_modal'
|
2025-11-22 00:24:21 +02:00
|
|
|
import BarChart from './elements/bar_chart'
|
2025-12-21 12:17:32 +02:00
|
|
|
import FieldCondition from './elements/field_condition'
|
2026-05-29 09:29:21 +03:00
|
|
|
import ConfirmUpload from './elements/confirm_upload'
|
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)
|
2025-09-24 15:45:04 +03:00
|
|
|
document.addEventListener('turbo:before-fetch-request', (event) => {
|
|
|
|
|
event.detail.fetchOptions.headers['X-Turbo'] = 'true'
|
|
|
|
|
})
|
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)
|
2026-05-21 14:50:30 +03:00
|
|
|
safeRegisterElement('convert-upload', ConvertUpload)
|
2024-05-23 13:44:00 +03:00
|
|
|
safeRegisterElement('prompt-password', PromptPassword)
|
|
|
|
|
safeRegisterElement('emails-textarea', EmailsTextarea)
|
|
|
|
|
safeRegisterElement('toggle-cookies', ToggleCookies)
|
2025-09-27 11:40:16 +03:00
|
|
|
safeRegisterElement('toggle-submit', ToggleSubmit)
|
2024-05-23 13:44:00 +03:00
|
|
|
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-09-24 12:07:54 +03:00
|
|
|
safeRegisterElement('app-tour-start', AppTourStart)
|
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)
|
2025-06-13 16:14:19 +03:00
|
|
|
safeRegisterElement('required-checkbox-group', RequiredCheckboxGroup)
|
2025-07-14 12:53:15 +03:00
|
|
|
safeRegisterElement('page-container', PageContainer)
|
2025-07-24 09:41:57 +03:00
|
|
|
safeRegisterElement('email-editor', EmailEditor)
|
2026-02-21 11:05:45 +02:00
|
|
|
safeRegisterElement('markdown-editor', MarkdownEditor)
|
2025-07-30 10:22:38 +03:00
|
|
|
safeRegisterElement('mount-on-click', MountOnClick)
|
2025-09-24 12:07:54 +03:00
|
|
|
safeRegisterElement('remove-on-event', RemoveOnEvent)
|
|
|
|
|
safeRegisterElement('scroll-to', ScrollTo)
|
|
|
|
|
safeRegisterElement('set-value', SetValue)
|
|
|
|
|
safeRegisterElement('review-form', ReviewForm)
|
|
|
|
|
safeRegisterElement('show-on-value', ShowOnValue)
|
|
|
|
|
safeRegisterElement('toggle-classes', ToggleClasses)
|
2025-09-24 15:45:04 +03:00
|
|
|
safeRegisterElement('autosize-field', AutosizeField)
|
2025-10-09 16:43:11 +03:00
|
|
|
safeRegisterElement('google-drive-file-picker', GoogleDriveFilePicker)
|
|
|
|
|
safeRegisterElement('open-modal', OpenModal)
|
2025-11-22 00:24:21 +02:00
|
|
|
safeRegisterElement('bar-chart', BarChart)
|
2025-12-21 12:17:32 +02:00
|
|
|
safeRegisterElement('field-condition', FieldCondition)
|
2026-05-29 09:29:21 +03:00
|
|
|
safeRegisterElement('confirm-upload', ConfirmUpload)
|
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')
|
|
|
|
|
|
2026-02-26 11:03:08 +02:00
|
|
|
const template = reactive(JSON.parse(this.dataset.template))
|
|
|
|
|
|
2023-05-31 23:19:20 +03:00
|
|
|
this.app = createApp(TemplateBuilder, {
|
2026-02-26 11:03:08 +02:00
|
|
|
template,
|
2026-01-26 11:11:19 +02:00
|
|
|
customFields: reactive(JSON.parse(this.dataset.customFields || '[]')),
|
2026-02-12 09:22:08 +02:00
|
|
|
dynamicDocuments: reactive(JSON.parse(this.dataset.dynamicDocuments || '[]')),
|
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',
|
2026-02-26 11:03:08 +02:00
|
|
|
withPrefillable: template.fields?.some((f) => f.prefillable),
|
2024-12-01 00:10:07 +02:00
|
|
|
withVerification: ['true', 'false'].includes(this.dataset.withVerification) ? this.dataset.withVerification === 'true' : null,
|
2026-01-02 16:07:04 +02:00
|
|
|
withKba: ['true', 'false'].includes(this.dataset.withKba) ? this.dataset.withKba === 'true' : null,
|
2023-10-08 12:04:32 +03:00
|
|
|
withLogo: this.dataset.withLogo !== 'false',
|
2025-10-28 10:52:37 +02:00
|
|
|
withFieldsDetection: this.dataset.withFieldsDetection === 'true',
|
2026-04-22 10:27:18 +03:00
|
|
|
withDetectExistingFields: this.dataset.withDetectExistingFields === 'true',
|
2026-05-07 09:48:25 +03:00
|
|
|
withRevisions: true,
|
|
|
|
|
withRevisionsMenu: this.dataset.withRevisionsMenu === 'true',
|
2024-02-03 22:37:17 +02:00
|
|
|
editable: this.dataset.editable !== 'false',
|
2024-03-23 23:16:40 +02:00
|
|
|
authenticityToken: document.querySelector('meta[name="csrf-token"]')?.content,
|
2026-01-26 11:11:19 +02:00
|
|
|
withCustomFields: true,
|
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',
|
2026-02-12 09:22:08 +02:00
|
|
|
withDynamicDocuments: this.dataset.withDynamicDocuments === 'true',
|
2025-10-09 16:43:11 +03:00
|
|
|
withGoogleDrive: this.dataset.withGoogleDrive === 'true',
|
2026-04-24 21:44:57 +03:00
|
|
|
pagePreviewFormat: this.dataset.pagePreviewFormat || '.jpg',
|
2025-05-09 00:01:50 +03:00
|
|
|
withReplaceAndCloneUpload: true,
|
2025-11-05 11:59:37 +02:00
|
|
|
withDownload: 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) => {
|
2026-05-26 09:18:32 +03:00
|
|
|
if (e.detail.success) {
|
|
|
|
|
if (e.detail?.formSubmission?.formElement?.id === 'submitters_form') {
|
|
|
|
|
e.detail.fetchResponse.response.json().then((data) => {
|
|
|
|
|
this.component.template.submitters = data.submitters
|
|
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.detail?.formSubmission?.formElement?.action?.endsWith('/prefillable_fields')) {
|
|
|
|
|
e.detail.fetchResponse.response.text().then((data) => {
|
|
|
|
|
const doc = new DOMParser().parseFromString(data, 'text/html')
|
|
|
|
|
const fragment = doc.querySelector('turbo-stream template').content
|
|
|
|
|
|
|
|
|
|
const prefillableUuidsIndex = {}
|
|
|
|
|
|
|
|
|
|
fragment.querySelectorAll('[name="field_uuid"]').forEach((field) => {
|
|
|
|
|
prefillableUuidsIndex[field.value] = true
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
this.component.template.fields.forEach((field) => {
|
|
|
|
|
if (prefillableUuidsIndex[field.uuid]) {
|
|
|
|
|
field.prefillable = true
|
|
|
|
|
field.readonly = true
|
|
|
|
|
} else if (field.prefillable) {
|
|
|
|
|
delete field.prefillable
|
|
|
|
|
delete field.readonly
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
})
|
|
|
|
|
}
|
2024-09-06 19:30:49 +03:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
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()
|
|
|
|
|
}
|
|
|
|
|
})
|