Skip to content

Commit a28e8ee

Browse files
authored
Merge pull request #18 from LibreSign/feat/read-only-elements
feat: implement read only elements
2 parents a008750 + f42a630 commit a28e8ee

3 files changed

Lines changed: 25 additions & 0 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ A Vue 2 component for rendering PDFs with draggable and resizable element overla
2424
| `hideSelectionUI` | Boolean | `false` | Hide selection handles and actions UI |
2525
| `showSelectionHandles` | Boolean | `true` | Show resize/move handles on selected elements |
2626
| `showElementActions` | Boolean | `true` | Show action buttons on selected elements |
27+
| `readOnly` | Boolean | `false` | Disable drag, resize, and actions for elements |
2728
| `pageCountFormat` | String | `'{currentPage} of {totalPages}'` | Format string for page counter |
2829
| `autoFitZoom` | Boolean | `false` | Automatically adjust zoom to fit viewport on window resize |
2930

src/components/DraggableElement.vue

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ export default {
120120
showDefaultActions: {
121121
type: Boolean,
122122
default: true,
123+
},
124+
readOnly: {
125+
type: Boolean,
126+
default: false,
123127
}
124128
},
125129
data() {
@@ -170,6 +174,7 @@ export default {
170174
top: `${currentY * scale}px`,
171175
width: `${currentWidth * scale}px`,
172176
height: `${currentHeight * scale}px`,
177+
pointerEvents: this.readOnly ? 'none' : 'auto',
173178
}
174179
},
175180
toolbarStyle() {
@@ -218,6 +223,9 @@ export default {
218223
},
219224
methods: {
220225
handleElementClick(event) {
226+
if (this.readOnly) {
227+
return
228+
}
221229
if (event.target.closest('.delete-handle') || event.target.closest('[data-stop-drag]') || event.target.closest('.actions-toolbar')) {
222230
return
223231
}
@@ -235,6 +243,7 @@ export default {
235243
this.startResize(direction, event)
236244
},
237245
startDrag(event) {
246+
if (this.readOnly) return
238247
if (event.target.classList.contains('delete')) return
239248
if (event.target.classList.contains('resize-handle')) return
240249
this.mode = 'drag'
@@ -271,6 +280,7 @@ export default {
271280
window.addEventListener('touchend', this.boundStopInteraction)
272281
},
273282
startResize(direction, event) {
283+
if (this.readOnly) return
274284
this.mode = 'resize'
275285
this.direction = direction
276286
this.startX = event.type.includes('touch') ? event.touches[0].clientX : event.clientX

src/components/PDFElements.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ SPDX-License-Identifier: AGPL-3.0-or-later
5858
:pages-scale="getRenderPageScale(docIndex, pIndex)"
5959
:page-width="getPageWidth(docIndex, pIndex)"
6060
:page-height="getPageHeight(docIndex, pIndex)"
61+
:read-only="readOnly"
6162
:on-update="(payload) => updateObject(docIndex, object.id, payload)"
6263
:on-delete="() => deleteObject(docIndex, object.id)"
6364
:on-drag-start="(mouseX, mouseY, pointerOffset, dragShift) => startDraggingElement(docIndex, pIndex, object, mouseX, mouseY, pointerOffset, dragShift)"
@@ -183,6 +184,10 @@ export default {
183184
type: Boolean,
184185
default: true,
185186
},
187+
readOnly: {
188+
type: Boolean,
189+
default: false,
190+
},
186191
pageCountFormat: {
187192
type: String,
188193
default: '{currentPage} of {totalPages}',
@@ -222,6 +227,7 @@ export default {
222227
debouncedApplyZoom: null,
223228
visualScale: this.initialScale,
224229
autoFitApplied: false,
230+
lastContainerWidth: 0,
225231
}
226232
},
227233
mounted() {
@@ -450,6 +456,14 @@ export default {
450456
if (this.isAddingMode || this.isDraggingElement) {
451457
this.cachePageBounds()
452458
}
459+
if (this.autoFitZoom && !this.isAddingMode && !this.isDraggingElement) {
460+
const containerWidth = this.$el?.clientWidth || 0
461+
if (containerWidth && containerWidth !== this.lastContainerWidth) {
462+
this.lastContainerWidth = containerWidth
463+
this.autoFitApplied = false
464+
this.scheduleAutoFitZoom()
465+
}
466+
}
453467
this.viewportRafId = 0
454468
})
455469
},

0 commit comments

Comments
 (0)