Skip to content

Commit dcd22cb

Browse files
Added reactivity to position props
1 parent 352d4d5 commit dcd22cb

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "vue-drag-resize",
3-
"version": "1.1.0",
3+
"version": "1.1.1",
44
"description": "Vue Component for resize and drag elements",
55
"author": "Kirill Murashov <me@kirillmurashov.com>",
66
"main": "dist/index.js",

src/components/vue-drag-resize.js

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,9 +187,6 @@ export default {
187187
return
188188
}
189189

190-
const parentWidth = this.parentWidth;
191-
const parentHeight = this.parentHeight;
192-
193190
this.bodyDrag = true;
194191

195192
this.stickStartPos.mouseX = ev.x;
@@ -200,6 +197,13 @@ export default {
200197
this.stickStartPos.top = this.top;
201198
this.stickStartPos.bottom = this.bottom;
202199

200+
this.calcDragLimitation();
201+
},
202+
203+
calcDragLimitation(){
204+
const parentWidth = this.parentWidth;
205+
const parentHeight = this.parentHeight;
206+
203207
if (this.parentLimitation) {
204208
this.limits = {
205209
minLeft: 0,
@@ -212,7 +216,6 @@ export default {
212216
maxBottom: parentHeight - this.height
213217
};
214218
}
215-
216219
},
217220

218221
bodyMove(ev) {
@@ -610,6 +613,20 @@ export default {
610613
if (val > 0 && val <= this.height) {
611614
this.minHeight = val
612615
}
616+
},
617+
618+
x(){
619+
this.calcDragLimitation();
620+
let delta = this.x - this.left;
621+
this.rawLeft = this.x;
622+
this.rawRight = this.right - delta;
623+
},
624+
625+
y(){
626+
this.calcDragLimitation();
627+
let delta = this.y - this.top;
628+
this.rawTop = this.y;
629+
this.rawBottom = this.bottom - delta;
613630
}
614631
}
615632
}

src/demo/components/toolbar/toolbar.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<div class="toolbar-wh-row">
33
<p class="toolbar-row-title">Position</p>
44
<span class="toolbar-position-inp">top
5-
<input :value="top" disabled />
5+
<input :value="top" @keyup="changeTop" />
66

77
<svgicon name="lock"
88
:color="topIsLocked ? '#42b983 #35495e' : '#AAA'"
@@ -13,7 +13,7 @@
1313
></svgicon>
1414
</span>
1515
<span class="toolbar-position-inp">left
16-
<input :value="left" disabled />
16+
<input :value="left" @keyup="changeLeft" />
1717
<svgicon name="lock"
1818
:color="leftIsLocked ? '#42b983 #35495e' : '#AAA'"
1919
width="15"

src/demo/components/toolbar/toolbar.js

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default {
6060
this.$store.state.rect.rects[this.activeRect].axis === 'none')
6161
},
6262

63-
zIndex(){
63+
zIndex() {
6464
if (this.activeRect === null) {
6565
return null;
6666
}
@@ -119,7 +119,7 @@ export default {
119119

120120
changeMinWidth(ev) {
121121
let minw = parseInt(ev.target.value);
122-
if(typeof minw !== 'number' || isNaN(minw)){
122+
if (typeof minw !== 'number' || isNaN(minw)) {
123123
minw = 1;
124124
}
125125

@@ -137,7 +137,7 @@ export default {
137137
changeMinHeight(ev) {
138138
let minh = parseInt(ev.target.value);
139139

140-
if(typeof minh !== 'number' || isNaN(minh)){
140+
if (typeof minh !== 'number' || isNaN(minh)) {
141141
minh = 1;
142142
}
143143

@@ -150,6 +150,27 @@ export default {
150150
ev.target.value = minh;
151151

152152
this.$store.dispatch('rect/setMinHeight', {id: this.activeRect, height: minh});
153+
},
154+
155+
changeTop(ev) {
156+
let top = parseInt(ev.target.value);
157+
158+
if (typeof top !== 'number' || isNaN(top)) {
159+
top = this.$store.state.rect.rects[this.activeRect].top;
160+
ev.target.value = top;
161+
return
162+
}
163+
},
164+
165+
changeLeft(ev) {
166+
let left = parseInt(ev.target.value);
167+
168+
if (typeof left !== 'number' || isNaN(left)) {
169+
left = this.$store.state.rect.rects[this.activeRect].left;
170+
ev.target.value = left;
171+
}
172+
173+
this.$store.dispatch('rect/setLeft', {id: this.activeRect, left: left});
153174
}
154175
}
155176
}

0 commit comments

Comments
 (0)