openatc-components 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.babelrc +18 -18
- package/.editorconfig +9 -9
- package/.eslintignore +5 -5
- package/.eslintrc.js +29 -29
- package/.postcssrc.js +10 -10
- package/README.md +30 -30
- package/build/build.js +41 -41
- package/build/check-versions.js +54 -54
- package/build/package.config.js +58 -58
- package/build/package.dev.config.js +25 -25
- package/build/package.prod.config.js +60 -60
- package/build/utils.js +101 -101
- package/build/vue-loader.conf.js +22 -22
- package/build/webpack.base.conf.js +109 -109
- package/build/webpack.dev.conf.js +95 -95
- package/build/webpack.prod.conf.js +149 -149
- package/config/dev.env.js +7 -7
- package/config/index.js +76 -76
- package/config/prod.env.js +4 -4
- package/config/test.env.js +7 -7
- package/index.html +12 -12
- package/package/kisscomps/components/CircleMenu/KissCircleMenu.vue +398 -398
- package/package/kisscomps/components/CircleMenu/index.js +2 -2
- package/package/kisscomps/components/DashBoard/MakeGradientColor.js +84 -84
- package/package/kisscomps/components/DashBoard/dashboard.js +471 -471
- package/package/kisscomps/components/DashBoard/dashboard.vue +57 -57
- package/package/kisscomps/components/DashBoard/index.js +2 -2
- package/package/kisscomps/components/Horizontal/KissHorizontal.vue +146 -146
- package/package/kisscomps/components/Horizontal/index.js +2 -2
- package/package/kisscomps/components/HorizontalChildren/KissHorizontalChildren.vue +196 -196
- package/package/kisscomps/components/HorizontalChildren/index.js +2 -2
- package/package/kisscomps/components/KissCircleMenu/CircleMenu.vue +113 -113
- package/package/kisscomps/components/KissCircleMenu/index.js +2 -2
- package/package/kisscomps/components/KissCircleMenu/style/index.less +1 -1
- package/package/kisscomps/components/KissCircleMenu/style/main/core.less +161 -161
- package/package/kisscomps/components/KissCircleMenu/style/main/other.less +94 -94
- package/package/kisscomps/components/KissCircleMenu/style/mixin/mixin.less +36 -36
- package/package/kisscomps/components/KissCircleMenu/style/var/var.less +21 -21
- package/package/kisscomps/components/KissCircleMenu/utils/colorRE.js +5 -5
- package/package/kisscomps/components/KissMessageBox/KissMessageBox.vue +108 -108
- package/package/kisscomps/components/KissMessageBox/index.js +2 -2
- package/package/kisscomps/components/KissSearchInput/index.js +2 -2
- package/package/kisscomps/components/KissSearchInput/kisssearchinput.vue +77 -77
- package/package/kisscomps/components/KissSimulationProgress/KissSimulationProgress.vue +294 -294
- package/package/kisscomps/components/KissSimulationProgress/index.js +2 -2
- package/package/kisscomps/components/StatusBar/StatusBar.vue +222 -222
- package/package/kisscomps/components/StatusBar/index.js +2 -2
- package/package/kisscomps/components/TragResize/index.js +2 -2
- package/package/kisscomps/components/TragResize/kissdragresize.vue +536 -536
- package/package/kisscomps/components/TragResize/util/dom.js +23 -23
- package/package/kisscomps/components/TragResize/util/fns.js +3 -3
- package/package/kisscomps/components/XRDDirSelector/XRDDirSelector.1.vue +320 -320
- package/package/kisscomps/components/XRDDirSelector/XRDDirSelector.vue +345 -345
- package/package/kisscomps/components/XRDDirSelector/index.js +2 -2
- package/package/kisscomps/components/button/index.js +2 -2
- package/package/kisscomps/components/button/kissbutton.vue +168 -168
- package/package/kisscomps/components/compass3D/compass.vue +180 -180
- package/package/kisscomps/components/compass3D/index.js +2 -2
- package/package/kisscomps/components/header/index.js +2 -2
- package/package/kisscomps/components/header/kissHead.vue +83 -83
- package/package/kisscomps/components/horizontalMenu/index.js +2 -2
- package/package/kisscomps/components/horizontalMenu/kissHorizontalMenu.vue +254 -254
- package/package/kisscomps/components/input/index.js +2 -2
- package/package/kisscomps/components/input/kissinput.vue +57 -57
- package/package/kisscomps/components/menu/index.js +2 -2
- package/package/kisscomps/components/menu/kissmenu.vue +324 -324
- package/package/kisscomps/components/mutipletips/Tdrag.js +585 -585
- package/package/kisscomps/components/mutipletips/index.js +2 -2
- package/package/kisscomps/components/mutipletips/kissmutipletips.vue +192 -192
- package/package/kisscomps/components/panel/index.js +2 -2
- package/package/kisscomps/components/panel/kissPanel.vue +151 -151
- package/package/kisscomps/components/select/chosen.jquery.min.js +3 -3
- package/package/kisscomps/components/select/index.js +2 -2
- package/package/kisscomps/components/select/kissselect.vue +527 -527
- package/package/kisscomps/components/tablebutton/index.js +2 -2
- package/package/kisscomps/components/tablebutton/tablebutton.vue +97 -97
- package/package/kisscomps/components/timectrl/KissTimeCtrl.vue +67 -67
- package/package/kisscomps/components/timectrl/index.js +2 -2
- package/package/kisscomps/components/timectrl/timectrl.css +851 -851
- package/package/kisscomps/components/tip/Tdrag.js +585 -585
- package/package/kisscomps/components/tip/index.js +2 -2
- package/package/kisscomps/components/tip/kisstips.1.vue +154 -154
- package/package/kisscomps/components/tip/kisstips.vue +154 -154
- package/package/kisscomps/components/tip/kisstips.vue.bak +211 -211
- package/package/kisscomps/index.js +71 -71
- package/package/kissui.js +203 -203
- package/package/kissui.min.js +203 -203
- package/package.json +1 -1
- package/src/App.vue +25 -25
- package/src/kisscomps/components/CircleMenu/KissCircleMenu.vue +398 -398
- package/src/kisscomps/components/CircleMenu/index.js +2 -2
- package/src/kisscomps/components/DashBoard/MakeGradientColor.js +84 -84
- package/src/kisscomps/components/DashBoard/dashboard.js +471 -471
- package/src/kisscomps/components/DashBoard/dashboard.vue +57 -57
- package/src/kisscomps/components/DashBoard/index.js +2 -2
- package/src/kisscomps/components/KissCircleMenu/CircleMenu.vue +113 -113
- package/src/kisscomps/components/KissCircleMenu/index.js +2 -2
- package/src/kisscomps/components/KissCircleMenu/style/index.less +1 -1
- package/src/kisscomps/components/KissCircleMenu/style/main/core.less +161 -161
- package/src/kisscomps/components/KissCircleMenu/style/main/other.less +94 -94
- package/src/kisscomps/components/KissCircleMenu/style/mixin/mixin.less +36 -36
- package/src/kisscomps/components/KissCircleMenu/style/var/var.less +21 -21
- package/src/kisscomps/components/KissCircleMenu/utils/colorRE.js +5 -5
- package/src/kisscomps/components/KissSearchInput/index.js +2 -2
- package/src/kisscomps/components/KissSearchInput/kisssearchinput.vue +77 -77
- package/src/kisscomps/components/SchemeConfig/closePhaselControlModal/index.vue +193 -0
- package/src/kisscomps/components/SchemeConfig/index.js +2 -0
- package/src/kisscomps/components/SchemeConfig/lockingPhaselControlModal/index.vue +214 -0
- package/src/kisscomps/components/SchemeConfig/manualControlModal/index.vue +176 -0
- package/src/kisscomps/components/SchemeConfig/realtimeStatusModal/index.vue +294 -0
- package/src/kisscomps/components/SchemeConfig/schemeconfig.vue +711 -0
- package/src/kisscomps/components/StatusBar/StatusBar.vue +222 -222
- package/src/kisscomps/components/StatusBar/index.js +2 -2
- package/src/kisscomps/components/TragResize/index.js +2 -2
- package/src/kisscomps/components/TragResize/kissdragresize.vue +536 -536
- package/src/kisscomps/components/XRDDirSelector/XRDDirSelector.1.vue +320 -320
- package/src/kisscomps/components/XRDDirSelector/XRDDirSelector.vue +345 -345
- package/src/kisscomps/components/XRDDirSelector/index.js +2 -2
- package/src/kisscomps/components/button/index.js +2 -2
- package/src/kisscomps/components/button/kissbutton.vue +168 -168
- package/src/kisscomps/components/compass3D/compass.vue +180 -180
- package/src/kisscomps/components/compass3D/index.js +2 -2
- package/src/kisscomps/components/horizontalMenu/index.js +2 -2
- package/src/kisscomps/components/horizontalMenu/kissHorizontalMenu.vue +254 -254
- package/src/kisscomps/components/input/index.js +2 -2
- package/src/kisscomps/components/input/kissinput.vue +57 -57
- package/src/kisscomps/components/menu/index.js +2 -2
- package/src/kisscomps/components/menu/kissmenu.vue +324 -324
- package/src/kisscomps/components/mutipletips/Tdrag.js +585 -585
- package/src/kisscomps/components/mutipletips/index.js +2 -2
- package/src/kisscomps/components/mutipletips/kissmutipletips.vue +192 -192
- package/src/kisscomps/components/select/chosen.jquery.min.js +3 -3
- package/src/kisscomps/components/select/index.js +2 -2
- package/src/kisscomps/components/select/kissselect.vue +527 -527
- package/src/kisscomps/components/timectrl/KissTimeCtrl.vue +67 -67
- package/src/kisscomps/components/timectrl/index.js +2 -2
- package/src/kisscomps/components/tip/Tdrag.js +585 -585
- package/src/kisscomps/components/tip/index.js +2 -2
- package/src/kisscomps/components/tip/kisstips.1.vue +154 -154
- package/src/kisscomps/components/tip/kisstips.vue +154 -154
- package/src/kisscomps/components/tip/kisstips.vue.bak +211 -211
- package/src/kisscomps/index.js +73 -71
- package/src/main.js +23 -23
- package/src/router/index.js +15 -15
- package/src/views/home.1.vue +479 -479
- package/src/views/home.vue +196 -196
- package/test/e2e/custom-assertions/elementCount.js +27 -27
- package/test/e2e/nightwatch.conf.js +46 -46
- package/test/e2e/runner.js +48 -48
- package/test/e2e/specs/test.js +19 -19
- package/test/unit/.eslintrc +7 -7
- package/test/unit/jest.conf.js +30 -30
- package/test/unit/setup.js +3 -3
- package/test/unit/specs/HelloWorld.spec.js +11 -11
|
@@ -1,536 +1,536 @@
|
|
|
1
|
-
<template>
|
|
2
|
-
<div
|
|
3
|
-
class="vdr"
|
|
4
|
-
:style="style"
|
|
5
|
-
:class="{
|
|
6
|
-
draggable: draggable,
|
|
7
|
-
resizable: resizable,
|
|
8
|
-
active: enabled,
|
|
9
|
-
dragging: dragging,
|
|
10
|
-
resizing: resizing
|
|
11
|
-
}"
|
|
12
|
-
@mousedown="elmDown"
|
|
13
|
-
@touchstart.stop="elmDown"
|
|
14
|
-
@dblclick="fillParent"
|
|
15
|
-
>
|
|
16
|
-
<div
|
|
17
|
-
v-for="handle in handles"
|
|
18
|
-
v-if="resizable"
|
|
19
|
-
class="handle"
|
|
20
|
-
:key="handle"
|
|
21
|
-
:class="'handle-' + handle"
|
|
22
|
-
:style="{ display: enabled ? 'block' : 'none'}"
|
|
23
|
-
@mousedown.stop.prevent="handleDown(handle, $event)"
|
|
24
|
-
@touchstart.stop.prevent="handleDown(handle, $event)"
|
|
25
|
-
></div>
|
|
26
|
-
<slot></slot>
|
|
27
|
-
</div>
|
|
28
|
-
</template>
|
|
29
|
-
|
|
30
|
-
<script>
|
|
31
|
-
import { matchesSelectorToParentElements } from './util/dom'
|
|
32
|
-
|
|
33
|
-
export default {
|
|
34
|
-
replace: true,
|
|
35
|
-
name: 'VueDraggableResizable',
|
|
36
|
-
props: {
|
|
37
|
-
active: {
|
|
38
|
-
type: Boolean, default: false
|
|
39
|
-
},
|
|
40
|
-
draggable: {
|
|
41
|
-
type: Boolean, default: true
|
|
42
|
-
},
|
|
43
|
-
resizable: {
|
|
44
|
-
type: Boolean, default: true
|
|
45
|
-
},
|
|
46
|
-
w: {
|
|
47
|
-
type: Number,
|
|
48
|
-
default: 200,
|
|
49
|
-
validator: function (val) {
|
|
50
|
-
return val > 0
|
|
51
|
-
}
|
|
52
|
-
},
|
|
53
|
-
h: {
|
|
54
|
-
type: Number,
|
|
55
|
-
default: 200,
|
|
56
|
-
validator: function (val) {
|
|
57
|
-
return val > 0
|
|
58
|
-
}
|
|
59
|
-
},
|
|
60
|
-
minw: {
|
|
61
|
-
type: Number,
|
|
62
|
-
default: 50,
|
|
63
|
-
validator: function (val) {
|
|
64
|
-
return val >= 0
|
|
65
|
-
}
|
|
66
|
-
},
|
|
67
|
-
minh: {
|
|
68
|
-
type: Number,
|
|
69
|
-
default: 50,
|
|
70
|
-
validator: function (val) {
|
|
71
|
-
return val >= 0
|
|
72
|
-
}
|
|
73
|
-
},
|
|
74
|
-
x: {
|
|
75
|
-
type: Number,
|
|
76
|
-
default: 0,
|
|
77
|
-
validator: function (val) {
|
|
78
|
-
return typeof val === 'number'
|
|
79
|
-
}
|
|
80
|
-
},
|
|
81
|
-
y: {
|
|
82
|
-
type: Number,
|
|
83
|
-
default: 0,
|
|
84
|
-
validator: function (val) {
|
|
85
|
-
return typeof val === 'number'
|
|
86
|
-
}
|
|
87
|
-
},
|
|
88
|
-
z: {
|
|
89
|
-
type: [ String, Number ],
|
|
90
|
-
default: 'auto',
|
|
91
|
-
validator: function (val) {
|
|
92
|
-
let valid = (typeof val === 'string') ? val === 'auto' : val >= 0
|
|
93
|
-
return valid
|
|
94
|
-
}
|
|
95
|
-
},
|
|
96
|
-
handles: {
|
|
97
|
-
type: Array,
|
|
98
|
-
default: function () {
|
|
99
|
-
return ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml']
|
|
100
|
-
},
|
|
101
|
-
validator: function (val) {
|
|
102
|
-
var s = new Set(['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml'])
|
|
103
|
-
|
|
104
|
-
return new Set(val.filter(h => s.has(h))).size === val.length
|
|
105
|
-
}
|
|
106
|
-
},
|
|
107
|
-
dragHandle: {
|
|
108
|
-
type: String,
|
|
109
|
-
default: null
|
|
110
|
-
},
|
|
111
|
-
dragCancel: {
|
|
112
|
-
type: String,
|
|
113
|
-
default: null
|
|
114
|
-
},
|
|
115
|
-
axis: {
|
|
116
|
-
type: String,
|
|
117
|
-
default: 'both',
|
|
118
|
-
validator: function (val) {
|
|
119
|
-
return ['x', 'y', 'both'].indexOf(val) !== -1
|
|
120
|
-
}
|
|
121
|
-
},
|
|
122
|
-
grid: {
|
|
123
|
-
type: Array,
|
|
124
|
-
default: function () {
|
|
125
|
-
return [1, 1]
|
|
126
|
-
}
|
|
127
|
-
},
|
|
128
|
-
parent: {
|
|
129
|
-
type: Boolean, default: false
|
|
130
|
-
},
|
|
131
|
-
maximize: {
|
|
132
|
-
type: Boolean, default: false
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
|
|
136
|
-
created: function () {
|
|
137
|
-
this.parentX = 0
|
|
138
|
-
this.parentW = 9999
|
|
139
|
-
this.parentY = 0
|
|
140
|
-
this.parentH = 9999
|
|
141
|
-
|
|
142
|
-
this.mouseX = 0
|
|
143
|
-
this.mouseY = 0
|
|
144
|
-
|
|
145
|
-
this.lastMouseX = 0
|
|
146
|
-
this.lastMouseY = 0
|
|
147
|
-
|
|
148
|
-
this.mouseOffX = 0
|
|
149
|
-
this.mouseOffY = 0
|
|
150
|
-
|
|
151
|
-
this.elmX = 0
|
|
152
|
-
this.elmY = 0
|
|
153
|
-
|
|
154
|
-
this.elmW = 0
|
|
155
|
-
this.elmH = 0
|
|
156
|
-
},
|
|
157
|
-
mounted: function () {
|
|
158
|
-
document.documentElement.addEventListener('mousemove', this.handleMove, true)
|
|
159
|
-
document.documentElement.addEventListener('mousedown', this.deselect, true)
|
|
160
|
-
document.documentElement.addEventListener('mouseup', this.handleUp, true)
|
|
161
|
-
|
|
162
|
-
// touch events bindings
|
|
163
|
-
document.documentElement.addEventListener('touchmove', this.handleMove, true)
|
|
164
|
-
document.documentElement.addEventListener('touchend touchcancel', this.deselect, true)
|
|
165
|
-
document.documentElement.addEventListener('touchstart', this.handleUp, true)
|
|
166
|
-
|
|
167
|
-
this.elmX = parseInt(this.$el.style.left)
|
|
168
|
-
this.elmY = parseInt(this.$el.style.top)
|
|
169
|
-
this.elmW = this.$el.offsetWidth || this.$el.clientWidth
|
|
170
|
-
this.elmH = this.$el.offsetHeight || this.$el.clientHeight
|
|
171
|
-
|
|
172
|
-
this.reviewDimensions()
|
|
173
|
-
},
|
|
174
|
-
beforeDestroy: function () {
|
|
175
|
-
document.documentElement.removeEventListener('mousemove', this.handleMove, true)
|
|
176
|
-
document.documentElement.removeEventListener('mousedown', this.deselect, true)
|
|
177
|
-
document.documentElement.removeEventListener('mouseup', this.handleUp, true)
|
|
178
|
-
|
|
179
|
-
// touch events bindings removed
|
|
180
|
-
document.documentElement.addEventListener('touchmove', this.handleMove, true)
|
|
181
|
-
document.documentElement.addEventListener('touchend touchcancel', this.deselect, true)
|
|
182
|
-
document.documentElement.addEventListener('touchstart', this.handleUp, true)
|
|
183
|
-
},
|
|
184
|
-
|
|
185
|
-
data: function () {
|
|
186
|
-
return {
|
|
187
|
-
top: this.y,
|
|
188
|
-
left: this.x,
|
|
189
|
-
width: this.w,
|
|
190
|
-
height: this.h,
|
|
191
|
-
resizing: false,
|
|
192
|
-
dragging: false,
|
|
193
|
-
enabled: this.active,
|
|
194
|
-
handle: null,
|
|
195
|
-
zIndex: this.z
|
|
196
|
-
}
|
|
197
|
-
},
|
|
198
|
-
|
|
199
|
-
methods: {
|
|
200
|
-
reviewDimensions: function () {
|
|
201
|
-
if (this.minw > this.w) this.width = this.minw
|
|
202
|
-
|
|
203
|
-
if (this.minh > this.h) this.height = this.minh
|
|
204
|
-
|
|
205
|
-
if (this.parent) {
|
|
206
|
-
const parentW = parseInt(this.$el.parentNode.clientWidth, 10)
|
|
207
|
-
const parentH = parseInt(this.$el.parentNode.clientHeight, 10)
|
|
208
|
-
|
|
209
|
-
this.parentW = parentW
|
|
210
|
-
this.parentH = parentH
|
|
211
|
-
|
|
212
|
-
if (this.w > this.parentW) this.width = parentW
|
|
213
|
-
|
|
214
|
-
if (this.h > this.parentH) this.height = parentH
|
|
215
|
-
|
|
216
|
-
if ((this.x + this.w) > this.parentW) this.width = parentW - this.x
|
|
217
|
-
|
|
218
|
-
if ((this.y + this.h) > this.parentH) this.height = parentH - this.y
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
this.elmW = this.width
|
|
222
|
-
this.elmH = this.height
|
|
223
|
-
|
|
224
|
-
this.$emit('resizing', this.left, this.top, this.width, this.height)
|
|
225
|
-
},
|
|
226
|
-
elmDown: function (e) {
|
|
227
|
-
const target = e.target || e.srcElement
|
|
228
|
-
|
|
229
|
-
if (this.$el.contains(target)) {
|
|
230
|
-
if (
|
|
231
|
-
(this.dragHandle && !matchesSelectorToParentElements(target, this.dragHandle, this.$el)) ||
|
|
232
|
-
(this.dragCancel && matchesSelectorToParentElements(target, this.dragCancel, this.$el))) {
|
|
233
|
-
return
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
e.stopPropagation()
|
|
237
|
-
e.preventDefault()
|
|
238
|
-
|
|
239
|
-
this.reviewDimensions()
|
|
240
|
-
|
|
241
|
-
if (!this.enabled) {
|
|
242
|
-
this.enabled = true
|
|
243
|
-
|
|
244
|
-
this.$emit('activated')
|
|
245
|
-
this.$emit('update:active', true)
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (this.draggable) {
|
|
249
|
-
this.dragging = true
|
|
250
|
-
}
|
|
251
|
-
}
|
|
252
|
-
},
|
|
253
|
-
deselect: function (e) {
|
|
254
|
-
if (e.type.indexOf('touch') !== -1) {
|
|
255
|
-
this.mouseX = e.changedTouches[0].clientX
|
|
256
|
-
this.mouseY = e.changedTouches[0].clientY
|
|
257
|
-
} else {
|
|
258
|
-
this.mouseX = e.pageX || e.clientX + document.documentElement.scrollLeft
|
|
259
|
-
this.mouseY = e.pageY || e.clientY + document.documentElement.scrollTop
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
this.lastMouseX = this.mouseX
|
|
263
|
-
this.lastMouseY = this.mouseY
|
|
264
|
-
|
|
265
|
-
const target = e.target || e.srcElement
|
|
266
|
-
const regex = new RegExp('handle-([trmbl]{2})', '')
|
|
267
|
-
|
|
268
|
-
if (!this.$el.contains(target) && !regex.test(target.className)) {
|
|
269
|
-
if (this.enabled) {
|
|
270
|
-
this.enabled = false
|
|
271
|
-
|
|
272
|
-
this.$emit('deactivated')
|
|
273
|
-
this.$emit('update:active', false)
|
|
274
|
-
}
|
|
275
|
-
}
|
|
276
|
-
},
|
|
277
|
-
handleDown: function (handle, e) {
|
|
278
|
-
this.handle = handle
|
|
279
|
-
|
|
280
|
-
if (e.stopPropagation) e.stopPropagation()
|
|
281
|
-
if (e.preventDefault) e.preventDefault()
|
|
282
|
-
|
|
283
|
-
this.resizing = true
|
|
284
|
-
},
|
|
285
|
-
fillParent: function (e) {
|
|
286
|
-
if (!this.parent || !this.resizable || !this.maximize) return
|
|
287
|
-
|
|
288
|
-
let done = false
|
|
289
|
-
|
|
290
|
-
const animate = () => {
|
|
291
|
-
if (!done) {
|
|
292
|
-
window.requestAnimationFrame(animate)
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
if (this.axis === 'x') {
|
|
296
|
-
if (
|
|
297
|
-
this.width === this.parentW && this.left === this.parentX
|
|
298
|
-
) done = true
|
|
299
|
-
} else if (this.axis === 'y') {
|
|
300
|
-
if (
|
|
301
|
-
this.height === this.parentH && this.top === this.parentY
|
|
302
|
-
) done = true
|
|
303
|
-
} else if (this.axis === 'both') {
|
|
304
|
-
if (
|
|
305
|
-
this.width === this.parentW &&
|
|
306
|
-
this.height === this.parentH &&
|
|
307
|
-
this.top === this.parentY &&
|
|
308
|
-
this.left === this.parentX
|
|
309
|
-
) done = true
|
|
310
|
-
}
|
|
311
|
-
|
|
312
|
-
if (this.axis === 'x' || this.axis === 'both') {
|
|
313
|
-
if (this.width < this.parentW) {
|
|
314
|
-
this.width++
|
|
315
|
-
this.elmW++
|
|
316
|
-
}
|
|
317
|
-
|
|
318
|
-
if (this.left > this.parentX) {
|
|
319
|
-
this.left--
|
|
320
|
-
this.elmX--
|
|
321
|
-
}
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
if (this.axis === 'y' || this.axis === 'both') {
|
|
325
|
-
if (this.height < this.parentH) {
|
|
326
|
-
this.height++
|
|
327
|
-
this.elmH++
|
|
328
|
-
}
|
|
329
|
-
|
|
330
|
-
if (this.top > this.parentY) {
|
|
331
|
-
this.top--
|
|
332
|
-
this.elmY--
|
|
333
|
-
}
|
|
334
|
-
}
|
|
335
|
-
|
|
336
|
-
this.$emit('resizing', this.left, this.top, this.width, this.height)
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
window.requestAnimationFrame(animate)
|
|
340
|
-
},
|
|
341
|
-
handleMove: function (e) {
|
|
342
|
-
const isTouchMove = e.type.indexOf('touchmove') !== -1
|
|
343
|
-
this.mouseX = isTouchMove
|
|
344
|
-
? e.touches[0].clientX
|
|
345
|
-
: e.pageX || e.clientX + document.documentElement.scrollLeft
|
|
346
|
-
this.mouseY = isTouchMove
|
|
347
|
-
? e.touches[0].clientY
|
|
348
|
-
: e.pageY || e.clientY + document.documentElement.scrollTop
|
|
349
|
-
|
|
350
|
-
let diffX = this.mouseX - this.lastMouseX + this.mouseOffX
|
|
351
|
-
let diffY = this.mouseY - this.lastMouseY + this.mouseOffY
|
|
352
|
-
|
|
353
|
-
this.mouseOffX = this.mouseOffY = 0
|
|
354
|
-
|
|
355
|
-
this.lastMouseX = this.mouseX
|
|
356
|
-
this.lastMouseY = this.mouseY
|
|
357
|
-
|
|
358
|
-
let dX = diffX
|
|
359
|
-
let dY = diffY
|
|
360
|
-
|
|
361
|
-
if (this.resizing) {
|
|
362
|
-
if (this.handle.indexOf('t') >= 0) {
|
|
363
|
-
if (this.elmH - dY < this.minh) this.mouseOffY = (dY - (diffY = this.elmH - this.minh))
|
|
364
|
-
else if (this.parent && this.elmY + dY < this.parentY) this.mouseOffY = (dY - (diffY = this.parentY - this.elmY))
|
|
365
|
-
this.elmY += diffY
|
|
366
|
-
this.elmH -= diffY
|
|
367
|
-
}
|
|
368
|
-
|
|
369
|
-
if (this.handle.indexOf('b') >= 0) {
|
|
370
|
-
if (this.elmH + dY < this.minh) this.mouseOffY = (dY - (diffY = this.minh - this.elmH))
|
|
371
|
-
else if (this.parent && this.elmY + this.elmH + dY > this.parentH) this.mouseOffY = (dY - (diffY = this.parentH - this.elmY - this.elmH))
|
|
372
|
-
this.elmH += diffY
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
if (this.handle.indexOf('l') >= 0) {
|
|
376
|
-
if (this.elmW - dX < this.minw) this.mouseOffX = (dX - (diffX = this.elmW - this.minw))
|
|
377
|
-
else if (this.parent && this.elmX + dX < this.parentX) this.mouseOffX = (dX - (diffX = this.parentX - this.elmX))
|
|
378
|
-
this.elmX += diffX
|
|
379
|
-
this.elmW -= diffX
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
if (this.handle.indexOf('r') >= 0) {
|
|
383
|
-
if (this.elmW + dX < this.minw) this.mouseOffX = (dX - (diffX = this.minw - this.elmW))
|
|
384
|
-
else if (this.parent && this.elmX + this.elmW + dX > this.parentW) this.mouseOffX = (dX - (diffX = this.parentW - this.elmX - this.elmW))
|
|
385
|
-
this.elmW += diffX
|
|
386
|
-
}
|
|
387
|
-
|
|
388
|
-
this.left = (Math.round(this.elmX / this.grid[0]) * this.grid[0])
|
|
389
|
-
this.top = (Math.round(this.elmY / this.grid[1]) * this.grid[1])
|
|
390
|
-
|
|
391
|
-
this.width = (Math.round(this.elmW / this.grid[0]) * this.grid[0])
|
|
392
|
-
this.height = (Math.round(this.elmH / this.grid[1]) * this.grid[1])
|
|
393
|
-
|
|
394
|
-
this.$emit('resizing', this.left, this.top, this.width, this.height)
|
|
395
|
-
} else if (this.dragging) {
|
|
396
|
-
if (this.parent) {
|
|
397
|
-
if (this.elmX + dX < this.parentX) this.mouseOffX = (dX - (diffX = this.parentX - this.elmX))
|
|
398
|
-
else if (this.elmX + this.elmW + dX > this.parentW) this.mouseOffX = (dX - (diffX = this.parentW - this.elmX - this.elmW))
|
|
399
|
-
|
|
400
|
-
if (this.elmY + dY < this.parentY) this.mouseOffY = (dY - (diffY = this.parentY - this.elmY))
|
|
401
|
-
else if (this.elmY + this.elmH + dY > this.parentH) this.mouseOffY = (dY - (diffY = this.parentH - this.elmY - this.elmH))
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
this.elmX += diffX
|
|
405
|
-
this.elmY += diffY
|
|
406
|
-
|
|
407
|
-
if (this.axis === 'x' || this.axis === 'both') {
|
|
408
|
-
this.left = (Math.round(this.elmX / this.grid[0]) * this.grid[0])
|
|
409
|
-
}
|
|
410
|
-
if (this.axis === 'y' || this.axis === 'both') {
|
|
411
|
-
this.top = (Math.round(this.elmY / this.grid[1]) * this.grid[1])
|
|
412
|
-
}
|
|
413
|
-
|
|
414
|
-
this.$emit('dragging', this.left, this.top)
|
|
415
|
-
}
|
|
416
|
-
},
|
|
417
|
-
handleUp: function (e) {
|
|
418
|
-
if (e.type.indexOf('touch') !== -1) {
|
|
419
|
-
this.lastMouseX = e.changedTouches[0].clientX
|
|
420
|
-
this.lastMouseY = e.changedTouches[0].clientY
|
|
421
|
-
}
|
|
422
|
-
this.handle = null
|
|
423
|
-
if (this.resizing) {
|
|
424
|
-
this.resizing = false
|
|
425
|
-
this.$emit('resizestop', this.left, this.top, this.width, this.height)
|
|
426
|
-
}
|
|
427
|
-
if (this.dragging) {
|
|
428
|
-
this.dragging = false
|
|
429
|
-
this.$emit('dragstop', this.left, this.top)
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
this.elmX = this.left
|
|
433
|
-
this.elmY = this.top
|
|
434
|
-
}
|
|
435
|
-
},
|
|
436
|
-
|
|
437
|
-
computed: {
|
|
438
|
-
style: function () {
|
|
439
|
-
return {
|
|
440
|
-
top: this.top + 'px',
|
|
441
|
-
left: this.left + 'px',
|
|
442
|
-
width: this.width + 'px',
|
|
443
|
-
height: this.height + 'px',
|
|
444
|
-
zIndex: this.zIndex
|
|
445
|
-
}
|
|
446
|
-
}
|
|
447
|
-
},
|
|
448
|
-
|
|
449
|
-
watch: {
|
|
450
|
-
active: function (val) {
|
|
451
|
-
this.enabled = val
|
|
452
|
-
},
|
|
453
|
-
z: function (val) {
|
|
454
|
-
if (val >= 0 || val === 'auto') {
|
|
455
|
-
this.zIndex = val
|
|
456
|
-
}
|
|
457
|
-
}
|
|
458
|
-
}
|
|
459
|
-
}
|
|
460
|
-
</script>
|
|
461
|
-
|
|
462
|
-
<style scoped>
|
|
463
|
-
.vdr {
|
|
464
|
-
position: absolute;
|
|
465
|
-
box-sizing: border-box;
|
|
466
|
-
}
|
|
467
|
-
.handle {
|
|
468
|
-
box-sizing: border-box;
|
|
469
|
-
display: none;
|
|
470
|
-
position: absolute;
|
|
471
|
-
width: 10px;
|
|
472
|
-
height: 10px;
|
|
473
|
-
font-size: 1px;
|
|
474
|
-
background: transparent;
|
|
475
|
-
/* background: #42daff; */
|
|
476
|
-
border: 1px solid #333;
|
|
477
|
-
}
|
|
478
|
-
.handle:hover {
|
|
479
|
-
background: #42daff;
|
|
480
|
-
}
|
|
481
|
-
.handle-tl {
|
|
482
|
-
top: -10px;
|
|
483
|
-
left: -10px;
|
|
484
|
-
cursor: nw-resize;
|
|
485
|
-
}
|
|
486
|
-
.handle-tm {
|
|
487
|
-
top: -10px;
|
|
488
|
-
left: 50%;
|
|
489
|
-
margin-left: -5px;
|
|
490
|
-
cursor: n-resize;
|
|
491
|
-
}
|
|
492
|
-
.handle-tr {
|
|
493
|
-
top: -10px;
|
|
494
|
-
right: -10px;
|
|
495
|
-
cursor: ne-resize;
|
|
496
|
-
}
|
|
497
|
-
.handle-ml {
|
|
498
|
-
top: 50%;
|
|
499
|
-
margin-top: -5px;
|
|
500
|
-
left: -10px;
|
|
501
|
-
cursor: w-resize;
|
|
502
|
-
}
|
|
503
|
-
.handle-mr {
|
|
504
|
-
top: 50%;
|
|
505
|
-
margin-top: -5px;
|
|
506
|
-
right: -10px;
|
|
507
|
-
cursor: e-resize;
|
|
508
|
-
}
|
|
509
|
-
.handle-bl {
|
|
510
|
-
bottom: -10px;
|
|
511
|
-
left: -10px;
|
|
512
|
-
cursor: sw-resize;
|
|
513
|
-
}
|
|
514
|
-
.handle-bm {
|
|
515
|
-
bottom: -10px;
|
|
516
|
-
left: 50%;
|
|
517
|
-
margin-left: -5px;
|
|
518
|
-
cursor: s-resize;
|
|
519
|
-
}
|
|
520
|
-
.handle-br {
|
|
521
|
-
bottom: -10px;
|
|
522
|
-
right: -10px;
|
|
523
|
-
cursor: se-resize;
|
|
524
|
-
}
|
|
525
|
-
@media only screen and (max-width: 768px) {
|
|
526
|
-
/* For mobile phones: */
|
|
527
|
-
[class*="handle-"]:before {
|
|
528
|
-
content: '';
|
|
529
|
-
left: -10px;
|
|
530
|
-
right: -10px;
|
|
531
|
-
bottom: -10px;
|
|
532
|
-
top: -10px;
|
|
533
|
-
position: absolute;
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
</style>
|
|
1
|
+
<template>
|
|
2
|
+
<div
|
|
3
|
+
class="vdr"
|
|
4
|
+
:style="style"
|
|
5
|
+
:class="{
|
|
6
|
+
draggable: draggable,
|
|
7
|
+
resizable: resizable,
|
|
8
|
+
active: enabled,
|
|
9
|
+
dragging: dragging,
|
|
10
|
+
resizing: resizing
|
|
11
|
+
}"
|
|
12
|
+
@mousedown="elmDown"
|
|
13
|
+
@touchstart.stop="elmDown"
|
|
14
|
+
@dblclick="fillParent"
|
|
15
|
+
>
|
|
16
|
+
<div
|
|
17
|
+
v-for="handle in handles"
|
|
18
|
+
v-if="resizable"
|
|
19
|
+
class="handle"
|
|
20
|
+
:key="handle"
|
|
21
|
+
:class="'handle-' + handle"
|
|
22
|
+
:style="{ display: enabled ? 'block' : 'none'}"
|
|
23
|
+
@mousedown.stop.prevent="handleDown(handle, $event)"
|
|
24
|
+
@touchstart.stop.prevent="handleDown(handle, $event)"
|
|
25
|
+
></div>
|
|
26
|
+
<slot></slot>
|
|
27
|
+
</div>
|
|
28
|
+
</template>
|
|
29
|
+
|
|
30
|
+
<script>
|
|
31
|
+
import { matchesSelectorToParentElements } from './util/dom'
|
|
32
|
+
|
|
33
|
+
export default {
|
|
34
|
+
replace: true,
|
|
35
|
+
name: 'VueDraggableResizable',
|
|
36
|
+
props: {
|
|
37
|
+
active: {
|
|
38
|
+
type: Boolean, default: false
|
|
39
|
+
},
|
|
40
|
+
draggable: {
|
|
41
|
+
type: Boolean, default: true
|
|
42
|
+
},
|
|
43
|
+
resizable: {
|
|
44
|
+
type: Boolean, default: true
|
|
45
|
+
},
|
|
46
|
+
w: {
|
|
47
|
+
type: Number,
|
|
48
|
+
default: 200,
|
|
49
|
+
validator: function (val) {
|
|
50
|
+
return val > 0
|
|
51
|
+
}
|
|
52
|
+
},
|
|
53
|
+
h: {
|
|
54
|
+
type: Number,
|
|
55
|
+
default: 200,
|
|
56
|
+
validator: function (val) {
|
|
57
|
+
return val > 0
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
minw: {
|
|
61
|
+
type: Number,
|
|
62
|
+
default: 50,
|
|
63
|
+
validator: function (val) {
|
|
64
|
+
return val >= 0
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
minh: {
|
|
68
|
+
type: Number,
|
|
69
|
+
default: 50,
|
|
70
|
+
validator: function (val) {
|
|
71
|
+
return val >= 0
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
x: {
|
|
75
|
+
type: Number,
|
|
76
|
+
default: 0,
|
|
77
|
+
validator: function (val) {
|
|
78
|
+
return typeof val === 'number'
|
|
79
|
+
}
|
|
80
|
+
},
|
|
81
|
+
y: {
|
|
82
|
+
type: Number,
|
|
83
|
+
default: 0,
|
|
84
|
+
validator: function (val) {
|
|
85
|
+
return typeof val === 'number'
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
z: {
|
|
89
|
+
type: [ String, Number ],
|
|
90
|
+
default: 'auto',
|
|
91
|
+
validator: function (val) {
|
|
92
|
+
let valid = (typeof val === 'string') ? val === 'auto' : val >= 0
|
|
93
|
+
return valid
|
|
94
|
+
}
|
|
95
|
+
},
|
|
96
|
+
handles: {
|
|
97
|
+
type: Array,
|
|
98
|
+
default: function () {
|
|
99
|
+
return ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml']
|
|
100
|
+
},
|
|
101
|
+
validator: function (val) {
|
|
102
|
+
var s = new Set(['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml'])
|
|
103
|
+
|
|
104
|
+
return new Set(val.filter(h => s.has(h))).size === val.length
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
dragHandle: {
|
|
108
|
+
type: String,
|
|
109
|
+
default: null
|
|
110
|
+
},
|
|
111
|
+
dragCancel: {
|
|
112
|
+
type: String,
|
|
113
|
+
default: null
|
|
114
|
+
},
|
|
115
|
+
axis: {
|
|
116
|
+
type: String,
|
|
117
|
+
default: 'both',
|
|
118
|
+
validator: function (val) {
|
|
119
|
+
return ['x', 'y', 'both'].indexOf(val) !== -1
|
|
120
|
+
}
|
|
121
|
+
},
|
|
122
|
+
grid: {
|
|
123
|
+
type: Array,
|
|
124
|
+
default: function () {
|
|
125
|
+
return [1, 1]
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
parent: {
|
|
129
|
+
type: Boolean, default: false
|
|
130
|
+
},
|
|
131
|
+
maximize: {
|
|
132
|
+
type: Boolean, default: false
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
created: function () {
|
|
137
|
+
this.parentX = 0
|
|
138
|
+
this.parentW = 9999
|
|
139
|
+
this.parentY = 0
|
|
140
|
+
this.parentH = 9999
|
|
141
|
+
|
|
142
|
+
this.mouseX = 0
|
|
143
|
+
this.mouseY = 0
|
|
144
|
+
|
|
145
|
+
this.lastMouseX = 0
|
|
146
|
+
this.lastMouseY = 0
|
|
147
|
+
|
|
148
|
+
this.mouseOffX = 0
|
|
149
|
+
this.mouseOffY = 0
|
|
150
|
+
|
|
151
|
+
this.elmX = 0
|
|
152
|
+
this.elmY = 0
|
|
153
|
+
|
|
154
|
+
this.elmW = 0
|
|
155
|
+
this.elmH = 0
|
|
156
|
+
},
|
|
157
|
+
mounted: function () {
|
|
158
|
+
document.documentElement.addEventListener('mousemove', this.handleMove, true)
|
|
159
|
+
document.documentElement.addEventListener('mousedown', this.deselect, true)
|
|
160
|
+
document.documentElement.addEventListener('mouseup', this.handleUp, true)
|
|
161
|
+
|
|
162
|
+
// touch events bindings
|
|
163
|
+
document.documentElement.addEventListener('touchmove', this.handleMove, true)
|
|
164
|
+
document.documentElement.addEventListener('touchend touchcancel', this.deselect, true)
|
|
165
|
+
document.documentElement.addEventListener('touchstart', this.handleUp, true)
|
|
166
|
+
|
|
167
|
+
this.elmX = parseInt(this.$el.style.left)
|
|
168
|
+
this.elmY = parseInt(this.$el.style.top)
|
|
169
|
+
this.elmW = this.$el.offsetWidth || this.$el.clientWidth
|
|
170
|
+
this.elmH = this.$el.offsetHeight || this.$el.clientHeight
|
|
171
|
+
|
|
172
|
+
this.reviewDimensions()
|
|
173
|
+
},
|
|
174
|
+
beforeDestroy: function () {
|
|
175
|
+
document.documentElement.removeEventListener('mousemove', this.handleMove, true)
|
|
176
|
+
document.documentElement.removeEventListener('mousedown', this.deselect, true)
|
|
177
|
+
document.documentElement.removeEventListener('mouseup', this.handleUp, true)
|
|
178
|
+
|
|
179
|
+
// touch events bindings removed
|
|
180
|
+
document.documentElement.addEventListener('touchmove', this.handleMove, true)
|
|
181
|
+
document.documentElement.addEventListener('touchend touchcancel', this.deselect, true)
|
|
182
|
+
document.documentElement.addEventListener('touchstart', this.handleUp, true)
|
|
183
|
+
},
|
|
184
|
+
|
|
185
|
+
data: function () {
|
|
186
|
+
return {
|
|
187
|
+
top: this.y,
|
|
188
|
+
left: this.x,
|
|
189
|
+
width: this.w,
|
|
190
|
+
height: this.h,
|
|
191
|
+
resizing: false,
|
|
192
|
+
dragging: false,
|
|
193
|
+
enabled: this.active,
|
|
194
|
+
handle: null,
|
|
195
|
+
zIndex: this.z
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
|
|
199
|
+
methods: {
|
|
200
|
+
reviewDimensions: function () {
|
|
201
|
+
if (this.minw > this.w) this.width = this.minw
|
|
202
|
+
|
|
203
|
+
if (this.minh > this.h) this.height = this.minh
|
|
204
|
+
|
|
205
|
+
if (this.parent) {
|
|
206
|
+
const parentW = parseInt(this.$el.parentNode.clientWidth, 10)
|
|
207
|
+
const parentH = parseInt(this.$el.parentNode.clientHeight, 10)
|
|
208
|
+
|
|
209
|
+
this.parentW = parentW
|
|
210
|
+
this.parentH = parentH
|
|
211
|
+
|
|
212
|
+
if (this.w > this.parentW) this.width = parentW
|
|
213
|
+
|
|
214
|
+
if (this.h > this.parentH) this.height = parentH
|
|
215
|
+
|
|
216
|
+
if ((this.x + this.w) > this.parentW) this.width = parentW - this.x
|
|
217
|
+
|
|
218
|
+
if ((this.y + this.h) > this.parentH) this.height = parentH - this.y
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
this.elmW = this.width
|
|
222
|
+
this.elmH = this.height
|
|
223
|
+
|
|
224
|
+
this.$emit('resizing', this.left, this.top, this.width, this.height)
|
|
225
|
+
},
|
|
226
|
+
elmDown: function (e) {
|
|
227
|
+
const target = e.target || e.srcElement
|
|
228
|
+
|
|
229
|
+
if (this.$el.contains(target)) {
|
|
230
|
+
if (
|
|
231
|
+
(this.dragHandle && !matchesSelectorToParentElements(target, this.dragHandle, this.$el)) ||
|
|
232
|
+
(this.dragCancel && matchesSelectorToParentElements(target, this.dragCancel, this.$el))) {
|
|
233
|
+
return
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
e.stopPropagation()
|
|
237
|
+
e.preventDefault()
|
|
238
|
+
|
|
239
|
+
this.reviewDimensions()
|
|
240
|
+
|
|
241
|
+
if (!this.enabled) {
|
|
242
|
+
this.enabled = true
|
|
243
|
+
|
|
244
|
+
this.$emit('activated')
|
|
245
|
+
this.$emit('update:active', true)
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (this.draggable) {
|
|
249
|
+
this.dragging = true
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
deselect: function (e) {
|
|
254
|
+
if (e.type.indexOf('touch') !== -1) {
|
|
255
|
+
this.mouseX = e.changedTouches[0].clientX
|
|
256
|
+
this.mouseY = e.changedTouches[0].clientY
|
|
257
|
+
} else {
|
|
258
|
+
this.mouseX = e.pageX || e.clientX + document.documentElement.scrollLeft
|
|
259
|
+
this.mouseY = e.pageY || e.clientY + document.documentElement.scrollTop
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
this.lastMouseX = this.mouseX
|
|
263
|
+
this.lastMouseY = this.mouseY
|
|
264
|
+
|
|
265
|
+
const target = e.target || e.srcElement
|
|
266
|
+
const regex = new RegExp('handle-([trmbl]{2})', '')
|
|
267
|
+
|
|
268
|
+
if (!this.$el.contains(target) && !regex.test(target.className)) {
|
|
269
|
+
if (this.enabled) {
|
|
270
|
+
this.enabled = false
|
|
271
|
+
|
|
272
|
+
this.$emit('deactivated')
|
|
273
|
+
this.$emit('update:active', false)
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
handleDown: function (handle, e) {
|
|
278
|
+
this.handle = handle
|
|
279
|
+
|
|
280
|
+
if (e.stopPropagation) e.stopPropagation()
|
|
281
|
+
if (e.preventDefault) e.preventDefault()
|
|
282
|
+
|
|
283
|
+
this.resizing = true
|
|
284
|
+
},
|
|
285
|
+
fillParent: function (e) {
|
|
286
|
+
if (!this.parent || !this.resizable || !this.maximize) return
|
|
287
|
+
|
|
288
|
+
let done = false
|
|
289
|
+
|
|
290
|
+
const animate = () => {
|
|
291
|
+
if (!done) {
|
|
292
|
+
window.requestAnimationFrame(animate)
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
if (this.axis === 'x') {
|
|
296
|
+
if (
|
|
297
|
+
this.width === this.parentW && this.left === this.parentX
|
|
298
|
+
) done = true
|
|
299
|
+
} else if (this.axis === 'y') {
|
|
300
|
+
if (
|
|
301
|
+
this.height === this.parentH && this.top === this.parentY
|
|
302
|
+
) done = true
|
|
303
|
+
} else if (this.axis === 'both') {
|
|
304
|
+
if (
|
|
305
|
+
this.width === this.parentW &&
|
|
306
|
+
this.height === this.parentH &&
|
|
307
|
+
this.top === this.parentY &&
|
|
308
|
+
this.left === this.parentX
|
|
309
|
+
) done = true
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
if (this.axis === 'x' || this.axis === 'both') {
|
|
313
|
+
if (this.width < this.parentW) {
|
|
314
|
+
this.width++
|
|
315
|
+
this.elmW++
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
if (this.left > this.parentX) {
|
|
319
|
+
this.left--
|
|
320
|
+
this.elmX--
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
if (this.axis === 'y' || this.axis === 'both') {
|
|
325
|
+
if (this.height < this.parentH) {
|
|
326
|
+
this.height++
|
|
327
|
+
this.elmH++
|
|
328
|
+
}
|
|
329
|
+
|
|
330
|
+
if (this.top > this.parentY) {
|
|
331
|
+
this.top--
|
|
332
|
+
this.elmY--
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
this.$emit('resizing', this.left, this.top, this.width, this.height)
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
window.requestAnimationFrame(animate)
|
|
340
|
+
},
|
|
341
|
+
handleMove: function (e) {
|
|
342
|
+
const isTouchMove = e.type.indexOf('touchmove') !== -1
|
|
343
|
+
this.mouseX = isTouchMove
|
|
344
|
+
? e.touches[0].clientX
|
|
345
|
+
: e.pageX || e.clientX + document.documentElement.scrollLeft
|
|
346
|
+
this.mouseY = isTouchMove
|
|
347
|
+
? e.touches[0].clientY
|
|
348
|
+
: e.pageY || e.clientY + document.documentElement.scrollTop
|
|
349
|
+
|
|
350
|
+
let diffX = this.mouseX - this.lastMouseX + this.mouseOffX
|
|
351
|
+
let diffY = this.mouseY - this.lastMouseY + this.mouseOffY
|
|
352
|
+
|
|
353
|
+
this.mouseOffX = this.mouseOffY = 0
|
|
354
|
+
|
|
355
|
+
this.lastMouseX = this.mouseX
|
|
356
|
+
this.lastMouseY = this.mouseY
|
|
357
|
+
|
|
358
|
+
let dX = diffX
|
|
359
|
+
let dY = diffY
|
|
360
|
+
|
|
361
|
+
if (this.resizing) {
|
|
362
|
+
if (this.handle.indexOf('t') >= 0) {
|
|
363
|
+
if (this.elmH - dY < this.minh) this.mouseOffY = (dY - (diffY = this.elmH - this.minh))
|
|
364
|
+
else if (this.parent && this.elmY + dY < this.parentY) this.mouseOffY = (dY - (diffY = this.parentY - this.elmY))
|
|
365
|
+
this.elmY += diffY
|
|
366
|
+
this.elmH -= diffY
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
if (this.handle.indexOf('b') >= 0) {
|
|
370
|
+
if (this.elmH + dY < this.minh) this.mouseOffY = (dY - (diffY = this.minh - this.elmH))
|
|
371
|
+
else if (this.parent && this.elmY + this.elmH + dY > this.parentH) this.mouseOffY = (dY - (diffY = this.parentH - this.elmY - this.elmH))
|
|
372
|
+
this.elmH += diffY
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
if (this.handle.indexOf('l') >= 0) {
|
|
376
|
+
if (this.elmW - dX < this.minw) this.mouseOffX = (dX - (diffX = this.elmW - this.minw))
|
|
377
|
+
else if (this.parent && this.elmX + dX < this.parentX) this.mouseOffX = (dX - (diffX = this.parentX - this.elmX))
|
|
378
|
+
this.elmX += diffX
|
|
379
|
+
this.elmW -= diffX
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
if (this.handle.indexOf('r') >= 0) {
|
|
383
|
+
if (this.elmW + dX < this.minw) this.mouseOffX = (dX - (diffX = this.minw - this.elmW))
|
|
384
|
+
else if (this.parent && this.elmX + this.elmW + dX > this.parentW) this.mouseOffX = (dX - (diffX = this.parentW - this.elmX - this.elmW))
|
|
385
|
+
this.elmW += diffX
|
|
386
|
+
}
|
|
387
|
+
|
|
388
|
+
this.left = (Math.round(this.elmX / this.grid[0]) * this.grid[0])
|
|
389
|
+
this.top = (Math.round(this.elmY / this.grid[1]) * this.grid[1])
|
|
390
|
+
|
|
391
|
+
this.width = (Math.round(this.elmW / this.grid[0]) * this.grid[0])
|
|
392
|
+
this.height = (Math.round(this.elmH / this.grid[1]) * this.grid[1])
|
|
393
|
+
|
|
394
|
+
this.$emit('resizing', this.left, this.top, this.width, this.height)
|
|
395
|
+
} else if (this.dragging) {
|
|
396
|
+
if (this.parent) {
|
|
397
|
+
if (this.elmX + dX < this.parentX) this.mouseOffX = (dX - (diffX = this.parentX - this.elmX))
|
|
398
|
+
else if (this.elmX + this.elmW + dX > this.parentW) this.mouseOffX = (dX - (diffX = this.parentW - this.elmX - this.elmW))
|
|
399
|
+
|
|
400
|
+
if (this.elmY + dY < this.parentY) this.mouseOffY = (dY - (diffY = this.parentY - this.elmY))
|
|
401
|
+
else if (this.elmY + this.elmH + dY > this.parentH) this.mouseOffY = (dY - (diffY = this.parentH - this.elmY - this.elmH))
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
this.elmX += diffX
|
|
405
|
+
this.elmY += diffY
|
|
406
|
+
|
|
407
|
+
if (this.axis === 'x' || this.axis === 'both') {
|
|
408
|
+
this.left = (Math.round(this.elmX / this.grid[0]) * this.grid[0])
|
|
409
|
+
}
|
|
410
|
+
if (this.axis === 'y' || this.axis === 'both') {
|
|
411
|
+
this.top = (Math.round(this.elmY / this.grid[1]) * this.grid[1])
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
this.$emit('dragging', this.left, this.top)
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
handleUp: function (e) {
|
|
418
|
+
if (e.type.indexOf('touch') !== -1) {
|
|
419
|
+
this.lastMouseX = e.changedTouches[0].clientX
|
|
420
|
+
this.lastMouseY = e.changedTouches[0].clientY
|
|
421
|
+
}
|
|
422
|
+
this.handle = null
|
|
423
|
+
if (this.resizing) {
|
|
424
|
+
this.resizing = false
|
|
425
|
+
this.$emit('resizestop', this.left, this.top, this.width, this.height)
|
|
426
|
+
}
|
|
427
|
+
if (this.dragging) {
|
|
428
|
+
this.dragging = false
|
|
429
|
+
this.$emit('dragstop', this.left, this.top)
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
this.elmX = this.left
|
|
433
|
+
this.elmY = this.top
|
|
434
|
+
}
|
|
435
|
+
},
|
|
436
|
+
|
|
437
|
+
computed: {
|
|
438
|
+
style: function () {
|
|
439
|
+
return {
|
|
440
|
+
top: this.top + 'px',
|
|
441
|
+
left: this.left + 'px',
|
|
442
|
+
width: this.width + 'px',
|
|
443
|
+
height: this.height + 'px',
|
|
444
|
+
zIndex: this.zIndex
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
},
|
|
448
|
+
|
|
449
|
+
watch: {
|
|
450
|
+
active: function (val) {
|
|
451
|
+
this.enabled = val
|
|
452
|
+
},
|
|
453
|
+
z: function (val) {
|
|
454
|
+
if (val >= 0 || val === 'auto') {
|
|
455
|
+
this.zIndex = val
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
</script>
|
|
461
|
+
|
|
462
|
+
<style scoped>
|
|
463
|
+
.vdr {
|
|
464
|
+
position: absolute;
|
|
465
|
+
box-sizing: border-box;
|
|
466
|
+
}
|
|
467
|
+
.handle {
|
|
468
|
+
box-sizing: border-box;
|
|
469
|
+
display: none;
|
|
470
|
+
position: absolute;
|
|
471
|
+
width: 10px;
|
|
472
|
+
height: 10px;
|
|
473
|
+
font-size: 1px;
|
|
474
|
+
background: transparent;
|
|
475
|
+
/* background: #42daff; */
|
|
476
|
+
border: 1px solid #333;
|
|
477
|
+
}
|
|
478
|
+
.handle:hover {
|
|
479
|
+
background: #42daff;
|
|
480
|
+
}
|
|
481
|
+
.handle-tl {
|
|
482
|
+
top: -10px;
|
|
483
|
+
left: -10px;
|
|
484
|
+
cursor: nw-resize;
|
|
485
|
+
}
|
|
486
|
+
.handle-tm {
|
|
487
|
+
top: -10px;
|
|
488
|
+
left: 50%;
|
|
489
|
+
margin-left: -5px;
|
|
490
|
+
cursor: n-resize;
|
|
491
|
+
}
|
|
492
|
+
.handle-tr {
|
|
493
|
+
top: -10px;
|
|
494
|
+
right: -10px;
|
|
495
|
+
cursor: ne-resize;
|
|
496
|
+
}
|
|
497
|
+
.handle-ml {
|
|
498
|
+
top: 50%;
|
|
499
|
+
margin-top: -5px;
|
|
500
|
+
left: -10px;
|
|
501
|
+
cursor: w-resize;
|
|
502
|
+
}
|
|
503
|
+
.handle-mr {
|
|
504
|
+
top: 50%;
|
|
505
|
+
margin-top: -5px;
|
|
506
|
+
right: -10px;
|
|
507
|
+
cursor: e-resize;
|
|
508
|
+
}
|
|
509
|
+
.handle-bl {
|
|
510
|
+
bottom: -10px;
|
|
511
|
+
left: -10px;
|
|
512
|
+
cursor: sw-resize;
|
|
513
|
+
}
|
|
514
|
+
.handle-bm {
|
|
515
|
+
bottom: -10px;
|
|
516
|
+
left: 50%;
|
|
517
|
+
margin-left: -5px;
|
|
518
|
+
cursor: s-resize;
|
|
519
|
+
}
|
|
520
|
+
.handle-br {
|
|
521
|
+
bottom: -10px;
|
|
522
|
+
right: -10px;
|
|
523
|
+
cursor: se-resize;
|
|
524
|
+
}
|
|
525
|
+
@media only screen and (max-width: 768px) {
|
|
526
|
+
/* For mobile phones: */
|
|
527
|
+
[class*="handle-"]:before {
|
|
528
|
+
content: '';
|
|
529
|
+
left: -10px;
|
|
530
|
+
right: -10px;
|
|
531
|
+
bottom: -10px;
|
|
532
|
+
top: -10px;
|
|
533
|
+
position: absolute;
|
|
534
|
+
}
|
|
535
|
+
}
|
|
536
|
+
</style>
|