|
|
|
|
@ -1012,13 +1012,6 @@ export default {
|
|
|
|
|
fieldsDragFieldRef: () => ref(),
|
|
|
|
|
customDragFieldRef: () => ref(),
|
|
|
|
|
selectedAreasRef: () => ref([]),
|
|
|
|
|
attachmentUuidsIndex () {
|
|
|
|
|
return this.template.schema.reduce((acc, e, index) => {
|
|
|
|
|
acc[e.attachment_uuid] = index
|
|
|
|
|
|
|
|
|
|
return acc
|
|
|
|
|
}, {})
|
|
|
|
|
},
|
|
|
|
|
language () {
|
|
|
|
|
return this.locale.split('-')[0].toLowerCase()
|
|
|
|
|
},
|
|
|
|
|
@ -1670,9 +1663,20 @@ export default {
|
|
|
|
|
this.save()
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
compareAreas (a, b) {
|
|
|
|
|
const aAttIdx = this.attachmentUuidsIndex[a.attachment_uuid]
|
|
|
|
|
const bAttIdx = this.attachmentUuidsIndex[b.attachment_uuid]
|
|
|
|
|
findFieldInsertIndex (field) {
|
|
|
|
|
if (!field.areas?.length) return -1
|
|
|
|
|
|
|
|
|
|
const area = field.areas[0]
|
|
|
|
|
|
|
|
|
|
const attachmentUuidsIndex = this.template.schema.reduce((acc, e, index) => {
|
|
|
|
|
acc[e.attachment_uuid] = index
|
|
|
|
|
|
|
|
|
|
return acc
|
|
|
|
|
}, {})
|
|
|
|
|
|
|
|
|
|
const compareAreas = (a, b) => {
|
|
|
|
|
const aAttIdx = attachmentUuidsIndex[a.attachment_uuid]
|
|
|
|
|
const bAttIdx = attachmentUuidsIndex[b.attachment_uuid]
|
|
|
|
|
|
|
|
|
|
if (aAttIdx !== bAttIdx) return aAttIdx - bAttIdx
|
|
|
|
|
if (a.page !== b.page) return a.page - b.page
|
|
|
|
|
@ -1684,11 +1688,7 @@ export default {
|
|
|
|
|
if (a.h < b.h ? a.y >= b.y && aY <= bY : b.y >= a.y && bY <= aY) return a.x - b.x
|
|
|
|
|
|
|
|
|
|
return aY - bY
|
|
|
|
|
},
|
|
|
|
|
findFieldInsertIndex (field) {
|
|
|
|
|
if (!field.areas?.length) return -1
|
|
|
|
|
|
|
|
|
|
const area = field.areas[0]
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let closestBeforeIndex = -1
|
|
|
|
|
let closestBeforeArea = null
|
|
|
|
|
@ -1698,15 +1698,15 @@ export default {
|
|
|
|
|
this.template.fields.forEach((f, index) => {
|
|
|
|
|
if (f.submitter_uuid === field.submitter_uuid) {
|
|
|
|
|
(f.areas || []).forEach((a) => {
|
|
|
|
|
const cmp = this.compareAreas(a, area)
|
|
|
|
|
const cmp = compareAreas(a, area)
|
|
|
|
|
|
|
|
|
|
if (cmp < 0) {
|
|
|
|
|
if (!closestBeforeArea || (this.compareAreas(a, closestBeforeArea) > 0 && closestBeforeIndex < index)) {
|
|
|
|
|
if (!closestBeforeArea || (compareAreas(a, closestBeforeArea) > 0 && closestBeforeIndex < index)) {
|
|
|
|
|
closestBeforeIndex = index
|
|
|
|
|
closestBeforeArea = a
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (!closestAfterArea || (this.compareAreas(a, closestAfterArea) < 0 && closestAfterIndex > index)) {
|
|
|
|
|
if (!closestAfterArea || (compareAreas(a, closestAfterArea) < 0 && closestAfterIndex > index)) {
|
|
|
|
|
closestAfterIndex = index
|
|
|
|
|
closestAfterArea = a
|
|
|
|
|
}
|
|
|
|
|
@ -1729,17 +1729,6 @@ export default {
|
|
|
|
|
this.template.fields.push(field)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
insertArea (field, area) {
|
|
|
|
|
field.areas ||= []
|
|
|
|
|
|
|
|
|
|
const insertIndex = field.areas.findIndex((a) => this.compareAreas(a, area) > 0)
|
|
|
|
|
|
|
|
|
|
if (insertIndex === -1) {
|
|
|
|
|
field.areas.push(area)
|
|
|
|
|
} else {
|
|
|
|
|
field.areas.splice(insertIndex, 0, area)
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
insertDetectedField (field) {
|
|
|
|
|
if (!this.withDetectExistingFields || !field.name) {
|
|
|
|
|
this.insertField(field)
|
|
|
|
|
@ -1755,7 +1744,7 @@ export default {
|
|
|
|
|
|
|
|
|
|
if (existingField) {
|
|
|
|
|
existingField.areas = existingField.areas || []
|
|
|
|
|
field.areas.forEach((area) => this.insertArea(existingField, area))
|
|
|
|
|
existingField.areas.push(...(field.areas || []))
|
|
|
|
|
} else {
|
|
|
|
|
const customField = this.detectCustomFieldsIndex[indexKey] || this.detectCustomFieldsIndex[nameKey]
|
|
|
|
|
|
|
|
|
|
@ -2260,7 +2249,7 @@ export default {
|
|
|
|
|
|
|
|
|
|
fieldUuidIndex[field.uuid] = newField
|
|
|
|
|
|
|
|
|
|
this.insertArea(newField, newArea)
|
|
|
|
|
newField.areas.push(newArea)
|
|
|
|
|
newAreas.push(newArea)
|
|
|
|
|
|
|
|
|
|
if (['radio', 'multiple'].includes(field.type) && field.options?.length) {
|
|
|
|
|
@ -2373,7 +2362,17 @@ export default {
|
|
|
|
|
area.y -= area.h / 2
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.insertArea(this.drawField, area)
|
|
|
|
|
this.drawField.areas ||= []
|
|
|
|
|
|
|
|
|
|
const insertBeforeAreaIndex = this.drawField.areas.findIndex((a) => {
|
|
|
|
|
return a.attachment_uuid === area.attachment_uuid && a.page > area.page
|
|
|
|
|
})
|
|
|
|
|
|
|
|
|
|
if (insertBeforeAreaIndex !== -1) {
|
|
|
|
|
this.drawField.areas.splice(insertBeforeAreaIndex, 0, area)
|
|
|
|
|
} else {
|
|
|
|
|
this.drawField.areas.push(area)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (this.template.fields.indexOf(this.drawField) === -1) {
|
|
|
|
|
this.insertField(this.drawField)
|
|
|
|
|
@ -2514,7 +2513,9 @@ export default {
|
|
|
|
|
delete field.height
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.insertArea(field, fieldArea)
|
|
|
|
|
field.areas ||= []
|
|
|
|
|
|
|
|
|
|
field.areas.push(fieldArea)
|
|
|
|
|
|
|
|
|
|
if (this.selectedAreasRef.value.length < 2) {
|
|
|
|
|
this.selectedAreasRef.value = [fieldArea]
|
|
|
|
|
@ -2584,7 +2585,7 @@ export default {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.insertArea(field, fieldArea)
|
|
|
|
|
field.areas.push(fieldArea)
|
|
|
|
|
})
|
|
|
|
|
} else {
|
|
|
|
|
const fieldArea = {
|
|
|
|
|
|