From 38674a9fc949ab0cc37cc5c98055ba7d77b3997a Mon Sep 17 00:00:00 2001 From: Alex Turchyn Date: Wed, 21 May 2025 22:05:33 +0300 Subject: [PATCH] fix accidental checkbox addition --- app/javascript/template_builder/builder.vue | 4 ++-- app/javascript/template_builder/document.vue | 2 +- app/javascript/template_builder/page.vue | 7 ++++++- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/app/javascript/template_builder/builder.vue b/app/javascript/template_builder/builder.vue index 514740eb..ab26e912 100644 --- a/app/javascript/template_builder/builder.vue +++ b/app/javascript/template_builder/builder.vue @@ -1279,7 +1279,7 @@ export default { area.h = (pageMask.clientWidth / 35 / pageMask.clientWidth) } }, - onDraw (area) { + onDraw ({ area, isTooSmall }) { if (this.drawField) { if (this.drawOption) { const areaWithoutOption = this.drawField.areas?.find((a) => !a.option_uuid) @@ -1374,7 +1374,7 @@ export default { area.y -= area.h / 2 } - if (area.w) { + if (area.w && (type !== 'checkbox' || this.drawFieldType || !isTooSmall)) { this.addField(type, area) this.selectedAreaRef.value = area diff --git a/app/javascript/template_builder/document.vue b/app/javascript/template_builder/document.vue index ea0b850e..7bba06c7 100644 --- a/app/javascript/template_builder/document.vue +++ b/app/javascript/template_builder/document.vue @@ -23,7 +23,7 @@ @drop-field="$emit('drop-field', {...$event, attachment_uuid: document.uuid })" @remove-area="$emit('remove-area', $event)" @scroll-to="scrollToArea" - @draw="$emit('draw', {...$event, attachment_uuid: document.uuid })" + @draw="$emit('draw', { area: {...$event.area, attachment_uuid: document.uuid }, isTooSmall: $event.isTooSmall })" /> diff --git a/app/javascript/template_builder/page.vue b/app/javascript/template_builder/page.vue index 4ff6bebf..3934f24b 100644 --- a/app/javascript/template_builder/page.vue +++ b/app/javascript/template_builder/page.vue @@ -290,7 +290,12 @@ export default { area.cell_w = this.newArea.cell_w } - this.$emit('draw', area) + const dx = Math.abs(e.offsetX - this.$refs.mask.clientWidth * this.newArea.initialX) + const dy = Math.abs(e.offsetY - this.$refs.mask.clientHeight * this.newArea.initialY) + + const isTooSmall = dx < 8 && dy < 8 + + this.$emit('draw', { area, isTooSmall }) } this.showMask = false