Files
docuseal/app/javascript/submission_form/areas.vue
T

176 lines
4.4 KiB
Vue
Raw Normal View History

2023-05-25 22:47:52 +03:00
<template>
<template
2024-08-07 23:18:03 +03:00
v-for="(step, stepIndex) in steps"
2023-06-16 00:04:05 +03:00
:key="step[0].uuid"
2023-05-25 22:47:52 +03:00
>
<template
2023-06-16 00:04:05 +03:00
v-for="(field, fieldIndex) in step"
:key="field.uuid"
2023-05-25 22:47:52 +03:00
>
2023-06-16 00:04:05 +03:00
<template
v-for="(area, areaIndex) in field.areas"
:key="areaIndex"
>
2023-07-26 23:17:24 +03:00
<Teleport
2023-12-11 15:18:43 +02:00
v-if="findPageElementForArea(area)"
2023-08-12 12:34:02 +03:00
:to="findPageElementForArea(area)"
2023-07-26 23:17:24 +03:00
>
2023-06-16 00:04:05 +03:00
<FieldArea
:ref="setAreaRef"
v-model="values[field.uuid]"
2024-08-06 00:19:33 +03:00
:values="values"
2023-06-16 00:04:05 +03:00
:field="field"
:area="area"
2024-09-04 00:29:38 +03:00
:submittable="submittable"
2023-06-16 00:04:05 +03:00
:field-index="fieldIndex"
2024-07-02 20:27:25 +03:00
:scroll-padding="scrollPadding"
2024-07-24 20:55:35 +03:00
:submitter="submitter"
2024-07-19 09:40:56 +03:00
:with-field-placeholder="withFieldPlaceholder"
2024-07-24 20:55:35 +03:00
:with-signature-id="withSignatureId"
2023-06-16 00:04:05 +03:00
:is-active="currentStep === step"
2024-08-26 16:42:36 +03:00
:with-label="withLabel && !withFieldPlaceholder && step.length < 2"
2023-06-16 23:39:55 +03:00
:is-value-set="step.some((f) => f.uuid in values)"
2023-06-16 00:04:05 +03:00
:attachments-index="attachmentsIndex"
2024-08-07 23:18:03 +03:00
@click="$emit('focus-step', stepIndex)"
2023-06-16 00:04:05 +03:00
/>
</Teleport>
</template>
2023-05-25 22:47:52 +03:00
</template>
</template>
</template>
<script>
import FieldArea from './area'
export default {
name: 'FieldAreas',
components: {
FieldArea
},
props: {
2023-06-16 00:04:05 +03:00
steps: {
2023-05-25 22:47:52 +03:00
type: Array,
required: false,
default: () => []
},
2024-07-24 20:55:35 +03:00
withSignatureId: {
type: Boolean,
required: false,
default: false
},
2024-09-04 00:29:38 +03:00
submittable: {
type: Boolean,
required: false,
default: true
},
2024-07-24 20:55:35 +03:00
submitter: {
type: Object,
required: true
},
2023-05-25 22:47:52 +03:00
values: {
type: Object,
required: false,
default: () => ({})
},
2024-07-19 09:40:56 +03:00
withFieldPlaceholder: {
type: Boolean,
required: false,
default: false
},
2024-07-02 20:27:25 +03:00
scrollPadding: {
type: String,
required: false,
default: '-80px'
},
2023-05-25 22:47:52 +03:00
attachmentsIndex: {
type: Object,
required: false,
default: () => ({})
2023-06-15 01:05:04 +03:00
},
2023-07-31 00:48:51 +03:00
withLabel: {
type: Boolean,
required: false,
default: true
},
2024-07-22 17:42:29 +03:00
scrollEl: {
type: Object,
required: false,
default: null
},
2023-06-16 00:04:05 +03:00
currentStep: {
type: Array,
2023-06-15 01:05:04 +03:00
required: false,
2023-06-16 00:04:05 +03:00
default: () => []
2023-05-25 22:47:52 +03:00
}
},
2023-06-16 00:04:05 +03:00
emits: ['focus-step'],
2023-05-25 22:47:52 +03:00
data () {
return {
areaRefs: []
}
},
beforeUpdate () {
this.areaRefs = []
},
methods: {
2023-08-12 12:34:02 +03:00
findPageElementForArea (area) {
return (this.$root.$el?.parentNode?.getRootNode() || document).getElementById(`page-${area.attachment_uuid}-${area.page}`)
},
2023-05-25 22:47:52 +03:00
scrollIntoField (field) {
2024-01-06 17:21:15 +02:00
if (field?.areas) {
this.scrollIntoArea(field.areas[0])
}
},
scrollIntoArea (area) {
const areaRef = this.areaRefs.find((a) => a.area === area)
2023-08-12 12:34:02 +03:00
2024-01-06 17:21:15 +02:00
if (areaRef) {
const root = this.$root.$el.parentNode.getRootNode()
const container = root.body || root.querySelector('div')
2023-05-25 22:47:52 +03:00
2024-01-06 17:21:15 +02:00
if (container.style.overflow === 'hidden') {
this.scrollInContainer(areaRef.$el)
2023-05-25 22:47:52 +03:00
} else {
2024-07-22 17:42:29 +03:00
const targetRect = areaRef.$refs.scrollToElem.getBoundingClientRect()
const scrollEl = this.scrollEl || window
2024-09-20 22:21:09 +03:00
let rootRect = {}
if (this.scrollEl === document.documentElement) {
rootRect = this.scrollEl.getBoundingClientRect()
} else {
const root = this.$root.$el?.parentNode?.classList?.contains('ds') ? this.$root.$el : document.body
rootRect = root.getBoundingClientRect()
}
2024-07-22 17:42:29 +03:00
scrollEl.scrollTo({ top: targetRect.top - rootRect.top, behavior: 'smooth' })
2023-05-25 22:47:52 +03:00
}
2024-01-06 17:21:15 +02:00
return true
}
2023-05-25 22:47:52 +03:00
},
2023-07-03 00:03:29 +03:00
scrollInContainer (target) {
2023-08-12 12:34:02 +03:00
const root = this.$root.$el.parentNode.getRootNode()
const scrollbox = root.getElementById('scrollbox')
const formContainer = root.getElementById('form_container')
const container = root.body || root.querySelector('div')
2023-07-03 00:03:29 +03:00
const padding = 64
2023-08-12 12:34:02 +03:00
const boxRect = scrollbox.children[0].getBoundingClientRect()
2023-07-03 00:03:29 +03:00
const targetRect = target.getBoundingClientRect()
const targetTopRelativeToBox = targetRect.top - boxRect.top
2024-07-22 17:42:29 +03:00
scrollbox.scrollTo({ top: targetTopRelativeToBox - container.offsetHeight + formContainer.offsetHeight + target.offsetHeight + padding, behavior: 'smooth' })
2023-07-03 00:03:29 +03:00
},
2023-05-25 22:47:52 +03:00
setAreaRef (el) {
if (el) {
this.areaRefs.push(el)
}
}
}
}
</script>