emacroh5lib 1.0.94 → 1.0.95
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.
@@ -1,955 +1,1076 @@
|
|
1
1
|
<template>
|
2
|
-
<div
|
3
|
-
|
4
|
-
|
2
|
+
<div
|
3
|
+
class="vdr"
|
4
|
+
:style="positionStyle"
|
5
|
+
:class="`${active || isActive ? 'active' : 'inactive'} ${
|
6
|
+
contentClass ? contentClass : ''
|
7
|
+
}`"
|
8
|
+
@mousedown="bodyDown($event)"
|
9
|
+
@touchstart="bodyDown($event)"
|
10
|
+
@touchend="up($event)"
|
11
|
+
>
|
5
12
|
<div :style="sizeStyle" class="content-container" ref="container">
|
6
13
|
<slot></slot>
|
7
14
|
</div>
|
8
|
-
<div
|
9
|
-
|
10
|
-
|
11
|
-
|
15
|
+
<div
|
16
|
+
v-for="stick in sticks"
|
17
|
+
class="vdr-stick"
|
18
|
+
:class="['vdr-stick-' + stick, isResizable ? '' : 'not-resizable']"
|
19
|
+
@mousedown.stop.prevent="stickDown(stick, $event)"
|
20
|
+
@touchstart.stop.prevent="stickDown(stick, $event)"
|
21
|
+
:style="vdrStick(stick)"
|
22
|
+
></div>
|
12
23
|
</div>
|
13
24
|
</template>
|
14
25
|
|
15
26
|
<script lang="ts">
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
27
|
+
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
|
28
|
+
|
29
|
+
const styleMapping: any = {
|
30
|
+
y: {
|
31
|
+
t: "top",
|
32
|
+
m: "marginTop",
|
33
|
+
b: "bottom",
|
34
|
+
},
|
35
|
+
x: {
|
36
|
+
l: "left",
|
37
|
+
m: "marginLeft",
|
38
|
+
r: "right",
|
39
|
+
},
|
40
|
+
};
|
41
|
+
|
42
|
+
function addEvents(events: any) {
|
43
|
+
events.forEach((cb: any, eventName: string) => {
|
44
|
+
document.documentElement.addEventListener(eventName, cb);
|
45
|
+
});
|
46
|
+
}
|
47
|
+
|
48
|
+
function removeEvents(events: any) {
|
49
|
+
events.forEach((cb: any, eventName: any) => {
|
50
|
+
document.documentElement.removeEventListener(eventName, cb);
|
51
|
+
});
|
52
|
+
}
|
53
|
+
|
54
|
+
@Component({ name: "DragResizeView" })
|
55
|
+
export default class DragResizeView extends Vue {
|
56
|
+
@Prop({
|
57
|
+
type: String,
|
58
|
+
required: false,
|
59
|
+
default: "",
|
60
|
+
})
|
61
|
+
name!: string;
|
62
|
+
|
63
|
+
@Prop({ type: Number, default: 8 }) stickSize!: number;
|
64
|
+
@Prop({ type: Number, default: 1 }) parentScaleX!: number;
|
65
|
+
@Prop({ type: Number, default: 1 }) parentScaleY!: number;
|
66
|
+
@Prop({ type: Boolean, default: false }) isActive!: boolean;
|
67
|
+
@Prop({ type: Boolean, default: false }) preventActiveBehavior!: boolean;
|
68
|
+
@Prop({ type: Boolean, default: true }) isDraggable!: boolean;
|
69
|
+
@Prop({ type: Boolean, default: true }) isResizable!: boolean;
|
70
|
+
@Prop({ type: Boolean, default: false }) aspectRatio!: boolean;
|
71
|
+
@Prop({
|
72
|
+
type: Boolean,
|
73
|
+
default: false,
|
74
|
+
})
|
75
|
+
parentLimitation!: boolean;
|
76
|
+
@Prop({
|
77
|
+
type: Boolean,
|
78
|
+
default: false,
|
79
|
+
})
|
80
|
+
snapToGrid!: number;
|
81
|
+
|
82
|
+
@Prop({
|
83
|
+
type: Number,
|
84
|
+
default: 50,
|
85
|
+
validator(val) {
|
86
|
+
return val >= 0;
|
23
87
|
},
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
88
|
+
})
|
89
|
+
gridX!: number;
|
90
|
+
|
91
|
+
@Prop({
|
92
|
+
type: Number,
|
93
|
+
default: 50,
|
94
|
+
validator(val) {
|
95
|
+
return val >= 0;
|
28
96
|
},
|
29
|
-
}
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
97
|
+
})
|
98
|
+
gridY!: number;
|
99
|
+
|
100
|
+
@Prop({
|
101
|
+
type: Number,
|
102
|
+
default: 0,
|
103
|
+
validator(val) {
|
104
|
+
return val >= 0;
|
105
|
+
},
|
106
|
+
})
|
107
|
+
parentW!: number;
|
108
|
+
|
109
|
+
@Prop({
|
110
|
+
type: Number,
|
111
|
+
default: 0,
|
112
|
+
validator(val) {
|
113
|
+
return val >= 0;
|
114
|
+
},
|
115
|
+
})
|
116
|
+
parentH!: number;
|
117
|
+
|
118
|
+
@Prop({
|
119
|
+
type: [String, Number],
|
120
|
+
default: 200,
|
121
|
+
validator(val) {
|
122
|
+
return typeof val === "string" ? val === "auto" : val >= 0;
|
123
|
+
},
|
124
|
+
})
|
125
|
+
w!: any;
|
126
|
+
|
127
|
+
@Prop({
|
128
|
+
type: [String, Number],
|
129
|
+
default: 200,
|
130
|
+
validator(val) {
|
131
|
+
return typeof val === "string" ? val === "auto" : val >= 0;
|
132
|
+
},
|
133
|
+
})
|
134
|
+
h!: any;
|
135
|
+
|
136
|
+
@Prop({
|
137
|
+
type: Number,
|
138
|
+
default: 50,
|
139
|
+
validator(val) {
|
140
|
+
return val >= 0;
|
141
|
+
},
|
142
|
+
})
|
143
|
+
minw!: number;
|
144
|
+
|
145
|
+
@Prop({
|
146
|
+
type: Number,
|
147
|
+
default: 50,
|
148
|
+
validator(val) {
|
149
|
+
return val >= 0;
|
150
|
+
},
|
151
|
+
})
|
152
|
+
minh!: number;
|
153
|
+
|
154
|
+
@Prop({
|
155
|
+
type: Number,
|
156
|
+
default: 0,
|
157
|
+
validator(val) {
|
158
|
+
return typeof val === "number";
|
159
|
+
},
|
160
|
+
})
|
161
|
+
x!: number;
|
162
|
+
|
163
|
+
@Prop({
|
164
|
+
type: Number,
|
165
|
+
default: 0,
|
166
|
+
validator(val) {
|
167
|
+
return typeof val === "number";
|
168
|
+
},
|
169
|
+
})
|
170
|
+
y!: number;
|
171
|
+
@Prop({
|
172
|
+
type: [String, Number],
|
173
|
+
default: "auto",
|
174
|
+
validator(val) {
|
175
|
+
return typeof val === "string" ? val === "auto" : val >= 0;
|
176
|
+
},
|
177
|
+
})
|
178
|
+
z!: string | number;
|
179
|
+
@Prop({
|
180
|
+
type: String,
|
181
|
+
default: null,
|
182
|
+
})
|
183
|
+
dragHandle!: string;
|
184
|
+
|
185
|
+
@Prop({
|
186
|
+
type: String,
|
187
|
+
default: null,
|
188
|
+
})
|
189
|
+
dragCancel!: string;
|
190
|
+
|
191
|
+
@Prop({
|
192
|
+
type: Array,
|
193
|
+
default() {
|
194
|
+
return ["tl", "tm", "tr", "mr", "br", "bm", "bl", "ml"];
|
195
|
+
},
|
196
|
+
})
|
197
|
+
sticks!: Array<string>;
|
198
|
+
|
199
|
+
@Prop({
|
200
|
+
type: String,
|
201
|
+
default: "both",
|
202
|
+
validator(val) {
|
203
|
+
return ["x", "y", "both", "none"].indexOf(val) !== -1;
|
204
|
+
},
|
205
|
+
})
|
206
|
+
axis!: string;
|
207
|
+
|
208
|
+
@Prop({
|
209
|
+
type: String,
|
210
|
+
required: false,
|
211
|
+
default: "",
|
212
|
+
})
|
213
|
+
contentClass!: boolean;
|
214
|
+
|
215
|
+
@Prop({
|
216
|
+
type: Boolean,
|
217
|
+
required: false,
|
218
|
+
default: false,
|
219
|
+
})
|
220
|
+
isStorage!: boolean;
|
221
|
+
|
222
|
+
public emits = [
|
223
|
+
"clicked",
|
224
|
+
"dragging",
|
225
|
+
"dragstop",
|
226
|
+
"resizing",
|
227
|
+
"resizestop",
|
228
|
+
"activated",
|
229
|
+
"deactivated",
|
230
|
+
];
|
231
|
+
|
232
|
+
public fixAspectRatio = null;
|
233
|
+
public active = false;
|
234
|
+
public zIndex: number = 0;
|
235
|
+
public parentWidth = 0;
|
236
|
+
public parentHeight = 0;
|
237
|
+
public left = 0;
|
238
|
+
public top = 0;
|
239
|
+
public right = 50;
|
240
|
+
public bottom = 50;
|
241
|
+
public minHeight = 10;
|
242
|
+
public stickDrag = false;
|
243
|
+
public bodyDrag = false;
|
244
|
+
public dimensionsBeforeMove: any;
|
245
|
+
public limits: any;
|
246
|
+
public currentStick: any;
|
247
|
+
public aspectFactor: any;
|
248
|
+
public domEvents: any;
|
249
|
+
public parentElement: any;
|
250
|
+
public _uid: any;
|
251
|
+
|
252
|
+
beforeCreate() {
|
253
|
+
this.stickDrag = false;
|
254
|
+
this.bodyDrag = false;
|
255
|
+
this.dimensionsBeforeMove = {
|
256
|
+
pointerX: 0,
|
257
|
+
pointerY: 0,
|
258
|
+
x: 0,
|
259
|
+
y: 0,
|
260
|
+
w: 0,
|
261
|
+
h: 0,
|
262
|
+
};
|
263
|
+
this.limits = {
|
264
|
+
left: { min: null, max: null },
|
265
|
+
right: { min: null, max: null },
|
266
|
+
top: { min: null, max: null },
|
267
|
+
bottom: { min: null, max: null },
|
268
|
+
};
|
269
|
+
|
270
|
+
this.currentStick = null;
|
41
271
|
}
|
42
272
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
type: Number,
|
86
|
-
default: 0,
|
87
|
-
validator(val) {
|
88
|
-
return val >= 0;
|
89
|
-
},
|
90
|
-
}) parentW!: number;
|
91
|
-
|
92
|
-
@Prop({
|
93
|
-
type: Number,
|
94
|
-
default: 0,
|
95
|
-
validator(val) {
|
96
|
-
return val >= 0;
|
97
|
-
},
|
98
|
-
}) parentH!: number;
|
99
|
-
|
100
|
-
@Prop({
|
101
|
-
type: [String, Number],
|
102
|
-
default: 200,
|
103
|
-
validator(val) {
|
104
|
-
return (typeof val === 'string') ? val === 'auto' : val >= 0;
|
105
|
-
},
|
106
|
-
}) w!: any;
|
107
|
-
|
108
|
-
@Prop({
|
109
|
-
type: [String, Number],
|
110
|
-
default: 200,
|
111
|
-
validator(val) {
|
112
|
-
return (typeof val === 'string') ? val === 'auto' : val >= 0;
|
113
|
-
},
|
114
|
-
}) h!: any;
|
115
|
-
|
116
|
-
@Prop({
|
117
|
-
type: Number,
|
118
|
-
default: 50,
|
119
|
-
validator(val) {
|
120
|
-
return val >= 0;
|
121
|
-
},
|
122
|
-
}) minw!: number;
|
123
|
-
|
124
|
-
@Prop({
|
125
|
-
type: Number,
|
126
|
-
default: 50,
|
127
|
-
validator(val) {
|
128
|
-
return val >= 0;
|
129
|
-
},
|
130
|
-
}) minh!: number;
|
131
|
-
|
132
|
-
@Prop({
|
133
|
-
type: Number,
|
134
|
-
default: 0,
|
135
|
-
validator(val) {
|
136
|
-
return typeof val === 'number';
|
137
|
-
},
|
138
|
-
}) x!: number;
|
139
|
-
|
140
|
-
@Prop({
|
141
|
-
type: Number,
|
142
|
-
default: 0,
|
143
|
-
validator(val) {
|
144
|
-
return typeof val === 'number';
|
145
|
-
},
|
146
|
-
}) y!: number;
|
147
|
-
@Prop({
|
148
|
-
type: [String, Number],
|
149
|
-
default: 'auto',
|
150
|
-
validator(val) {
|
151
|
-
return (typeof val === 'string') ? val === 'auto' : val >= 0;
|
152
|
-
},
|
153
|
-
}) z!: string | number;
|
154
|
-
@Prop({
|
155
|
-
type: String,
|
156
|
-
default: null,
|
157
|
-
}) dragHandle!: string;
|
158
|
-
|
159
|
-
@Prop({
|
160
|
-
type: String,
|
161
|
-
default: null,
|
162
|
-
}) dragCancel!: string;
|
163
|
-
|
164
|
-
@Prop({
|
165
|
-
type: Array,
|
166
|
-
default() {
|
167
|
-
return ['tl', 'tm', 'tr', 'mr', 'br', 'bm', 'bl', 'ml'];
|
168
|
-
},
|
169
|
-
}) sticks!: Array<string>;
|
170
|
-
|
171
|
-
@Prop({
|
172
|
-
type: String,
|
173
|
-
default: 'both',
|
174
|
-
validator(val) {
|
175
|
-
return ['x', 'y', 'both', 'none'].indexOf(val) !== -1;
|
176
|
-
},
|
177
|
-
}) axis!: string;
|
178
|
-
|
179
|
-
@Prop({
|
180
|
-
type: String,
|
181
|
-
required: false,
|
182
|
-
default: '',
|
183
|
-
}) contentClass!: boolean;
|
184
|
-
|
185
|
-
@Prop({
|
186
|
-
type: Boolean,
|
187
|
-
required: false,
|
188
|
-
default: false
|
189
|
-
}) isStorage!: boolean;
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
public emits = ['clicked', 'dragging', 'dragstop', 'resizing', 'resizestop', 'activated', 'deactivated']
|
194
|
-
|
195
|
-
public fixAspectRatio = null
|
196
|
-
public active = false
|
197
|
-
public zIndex: number = 0;
|
198
|
-
public parentWidth = 0;
|
199
|
-
public parentHeight = 0;
|
200
|
-
public left = 0;
|
201
|
-
public top = 0;
|
202
|
-
public right = 50;
|
203
|
-
public bottom = 50;
|
204
|
-
public minHeight = 10;
|
205
|
-
public stickDrag = false;
|
206
|
-
public bodyDrag = false;
|
207
|
-
public dimensionsBeforeMove: any;
|
208
|
-
public limits: any;
|
209
|
-
public currentStick: any;
|
210
|
-
public aspectFactor: any;
|
211
|
-
public domEvents: any;
|
212
|
-
public parentElement: any;
|
213
|
-
public _uid: any;
|
214
|
-
|
215
|
-
beforeCreate() {
|
216
|
-
this.stickDrag = false;
|
217
|
-
this.bodyDrag = false;
|
218
|
-
this.dimensionsBeforeMove = { pointerX: 0, pointerY: 0, x: 0, y: 0, w: 0, h: 0 };
|
219
|
-
this.limits = {
|
220
|
-
left: { min: null, max: null },
|
221
|
-
right: { min: null, max: null },
|
222
|
-
top: { min: null, max: null },
|
223
|
-
bottom: { min: null, max: null },
|
224
|
-
};
|
225
|
-
|
226
|
-
this.currentStick = null;
|
273
|
+
mounted() {
|
274
|
+
this.parentElement = this.$el.parentNode;
|
275
|
+
this.parentWidth = this.parentW
|
276
|
+
? this.parentW
|
277
|
+
: this.parentElement.clientWidth;
|
278
|
+
this.parentHeight = this.parentH
|
279
|
+
? this.parentH
|
280
|
+
: this.parentElement.clientHeight;
|
281
|
+
|
282
|
+
this.left = this.x;
|
283
|
+
this.top = this.y;
|
284
|
+
this.right =
|
285
|
+
this.parentWidth -
|
286
|
+
(this.w === "auto"
|
287
|
+
? (this.$refs.container as HTMLElement).scrollWidth
|
288
|
+
: this.w) -
|
289
|
+
this.left;
|
290
|
+
this.bottom =
|
291
|
+
this.parentHeight -
|
292
|
+
(this.h === "auto"
|
293
|
+
? (this.$refs.container as HTMLElement).scrollHeight
|
294
|
+
: this.h) -
|
295
|
+
this.top;
|
296
|
+
|
297
|
+
this.domEvents = new Map([
|
298
|
+
["mousemove", this.move],
|
299
|
+
["mouseup", this.up],
|
300
|
+
["mouseleave", this.up],
|
301
|
+
["mousedown", this.deselect],
|
302
|
+
["touchmove", this.move],
|
303
|
+
["touchend", this.up],
|
304
|
+
["touchcancel", this.up],
|
305
|
+
["touchstart", this.up],
|
306
|
+
["keydown", this.keydown],
|
307
|
+
]);
|
308
|
+
|
309
|
+
addEvents(this.domEvents);
|
310
|
+
|
311
|
+
if (this.dragHandle) {
|
312
|
+
[...this.$el.querySelectorAll(this.dragHandle)].forEach((dragHandle) => {
|
313
|
+
dragHandle.setAttribute("data-drag-handle", this._uid);
|
314
|
+
});
|
227
315
|
}
|
228
316
|
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
this.parentWidth = this.parentW ? this.parentW : this.parentElement.clientWidth;
|
234
|
-
this.parentHeight = this.parentH ? this.parentH : this.parentElement.clientHeight;
|
235
|
-
|
236
|
-
|
237
|
-
this.left = this.x;
|
238
|
-
this.top = this.y;
|
239
|
-
this.right = this.parentWidth - (this.w === 'auto' ? (this.$refs.container as HTMLElement).scrollWidth : this.w) - this.left;
|
240
|
-
this.bottom = this.parentHeight - (this.h === 'auto' ? (this.$refs.container as HTMLElement).scrollHeight : this.h) - this.top;
|
241
|
-
|
242
|
-
this.domEvents = new Map([
|
243
|
-
['mousemove', this.move],
|
244
|
-
['mouseup', this.up],
|
245
|
-
['mouseleave', this.up],
|
246
|
-
['mousedown', this.deselect],
|
247
|
-
['touchmove', this.move],
|
248
|
-
['touchend', this.up],
|
249
|
-
['touchcancel', this.up],
|
250
|
-
['touchstart', this.up],
|
251
|
-
['keydown', this.keydown],
|
252
|
-
]);
|
253
|
-
|
254
|
-
addEvents(this.domEvents);
|
255
|
-
|
256
|
-
if (this.dragHandle) {
|
257
|
-
[...this.$el.querySelectorAll(this.dragHandle)].forEach((dragHandle) => {
|
258
|
-
dragHandle.setAttribute('data-drag-handle', this._uid);
|
259
|
-
});
|
260
|
-
}
|
261
|
-
|
262
|
-
if (this.dragCancel) {
|
263
|
-
[...this.$el.querySelectorAll(this.dragCancel)].forEach((cancelHandle) => {
|
264
|
-
cancelHandle.setAttribute('data-drag-cancel', this._uid);
|
265
|
-
});
|
266
|
-
}
|
267
|
-
|
268
|
-
if (this.name.trim() !== '' && this.isStorage) {
|
269
|
-
let info = JSON.parse(localStorage.getItem("DragResizeView_Rect_" + this.name) as string)
|
270
|
-
if (info !== null
|
271
|
-
&& info.left !== null && info.top !== null
|
272
|
-
&& info.right !== null && info.bottom !== null) {
|
273
|
-
this.left = info.left
|
274
|
-
this.top = info.top
|
275
|
-
this.right = info.right
|
276
|
-
this.bottom = info.bottom
|
277
|
-
} else {
|
278
|
-
localStorage.removeItem("DragResizeView_Rect_" + this.name)
|
317
|
+
if (this.dragCancel) {
|
318
|
+
[...this.$el.querySelectorAll(this.dragCancel)].forEach(
|
319
|
+
(cancelHandle) => {
|
320
|
+
cancelHandle.setAttribute("data-drag-cancel", this._uid);
|
279
321
|
}
|
280
|
-
|
281
|
-
}
|
282
|
-
|
283
|
-
beforeDestroy() {
|
284
|
-
removeEvents(this.domEvents);
|
322
|
+
);
|
285
323
|
}
|
286
324
|
|
287
|
-
|
288
|
-
|
289
|
-
|
325
|
+
if (this.name.trim() !== "" && this.isStorage) {
|
326
|
+
let info = JSON.parse(
|
327
|
+
localStorage.getItem("DragResizeView_Rect_" + this.name) as string
|
328
|
+
);
|
329
|
+
if (
|
330
|
+
info !== null &&
|
331
|
+
info.left !== null &&
|
332
|
+
info.top !== null &&
|
333
|
+
info.right !== null &&
|
334
|
+
info.bottom !== null
|
335
|
+
) {
|
336
|
+
this.left = info.left;
|
337
|
+
this.top = info.top;
|
338
|
+
this.right = info.right;
|
339
|
+
this.bottom = info.bottom;
|
340
|
+
} else {
|
341
|
+
localStorage.removeItem("DragResizeView_Rect_" + this.name);
|
290
342
|
}
|
291
|
-
this.active = false;
|
292
343
|
}
|
344
|
+
}
|
293
345
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
return;
|
298
|
-
}
|
299
|
-
|
300
|
-
ev.stopPropagation();
|
301
|
-
|
302
|
-
const pageX = typeof ev.pageX !== 'undefined' ? ev.pageX : ev.touches[0].pageX;
|
303
|
-
const pageY = typeof ev.pageY !== 'undefined' ? ev.pageY : ev.touches[0].pageY;
|
304
|
-
|
305
|
-
const { dimensionsBeforeMove } = this;
|
306
|
-
|
307
|
-
const delta = {
|
308
|
-
x: (dimensionsBeforeMove.pointerX - pageX) / this.parentScaleX,
|
309
|
-
y: (dimensionsBeforeMove.pointerY - pageY) / this.parentScaleY,
|
310
|
-
};
|
311
|
-
|
312
|
-
if (this.stickDrag) {
|
313
|
-
this.stickMove(delta);
|
314
|
-
}
|
346
|
+
beforeDestroy() {
|
347
|
+
removeEvents(this.domEvents);
|
348
|
+
}
|
315
349
|
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
} else if (this.axis === 'y') {
|
320
|
-
delta.x = 0;
|
321
|
-
} else if (this.axis === 'none') {
|
322
|
-
return;
|
323
|
-
}
|
324
|
-
this.bodyMove(delta);
|
325
|
-
}
|
350
|
+
deselect() {
|
351
|
+
if (this.preventActiveBehavior) {
|
352
|
+
return;
|
326
353
|
}
|
354
|
+
this.active = false;
|
355
|
+
}
|
327
356
|
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
} else if (this.bodyDrag) {
|
332
|
-
this.bodyUp();
|
333
|
-
}
|
357
|
+
move(ev: any) {
|
358
|
+
if (!this.stickDrag && !this.bodyDrag) {
|
359
|
+
return;
|
334
360
|
}
|
335
361
|
|
336
|
-
|
362
|
+
ev.stopPropagation();
|
337
363
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
ev.
|
364
|
+
const pageX =
|
365
|
+
typeof ev.pageX !== "undefined" ? ev.pageX : ev.touches[0].pageX;
|
366
|
+
const pageY =
|
367
|
+
typeof ev.pageY !== "undefined" ? ev.pageY : ev.touches[0].pageY;
|
342
368
|
|
343
|
-
|
344
|
-
let pageX = 0, pageY = 0;
|
345
|
-
if (ev.key === "a" || ev.key === "ArrowLeft") {
|
346
|
-
pageX = dimensionsBeforeMove.pointerX - 1;
|
347
|
-
pageY = dimensionsBeforeMove.pointerY;
|
348
|
-
} else if (ev.key === "d" || ev.key === "ArrowRight") {
|
349
|
-
pageX = dimensionsBeforeMove.pointerX + 1;
|
350
|
-
pageY = dimensionsBeforeMove.pointerY;
|
351
|
-
} else if (ev.key === "w" || ev.key === "ArrowUp") {
|
352
|
-
pageX = dimensionsBeforeMove.pointerX;
|
353
|
-
pageY = dimensionsBeforeMove.pointerY - 1;
|
354
|
-
} else if (ev.key === "s" || ev.key === "ArrowDown") {
|
355
|
-
pageX = dimensionsBeforeMove.pointerX;
|
356
|
-
pageY = dimensionsBeforeMove.pointerY + 1;
|
357
|
-
} else {
|
358
|
-
return
|
359
|
-
}
|
369
|
+
const { dimensionsBeforeMove } = this;
|
360
370
|
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
371
|
+
const delta = {
|
372
|
+
x: (dimensionsBeforeMove.pointerX - pageX) / this.parentScaleX,
|
373
|
+
y: (dimensionsBeforeMove.pointerY - pageY) / this.parentScaleY,
|
374
|
+
};
|
365
375
|
|
366
|
-
|
367
|
-
|
368
|
-
|
376
|
+
if (this.stickDrag) {
|
377
|
+
this.stickMove(delta);
|
378
|
+
}
|
369
379
|
|
370
|
-
|
380
|
+
if (this.bodyDrag) {
|
381
|
+
if (this.axis === "x") {
|
371
382
|
delta.y = 0;
|
372
|
-
} else if (this.axis ===
|
383
|
+
} else if (this.axis === "y") {
|
373
384
|
delta.x = 0;
|
374
|
-
} else if (this.axis ===
|
385
|
+
} else if (this.axis === "none") {
|
375
386
|
return;
|
376
387
|
}
|
377
388
|
this.bodyMove(delta);
|
378
|
-
|
379
|
-
this.saveDimensionsBeforeMove(delta.x, delta.y);
|
380
389
|
}
|
390
|
+
}
|
381
391
|
|
392
|
+
up(ev: any) {
|
393
|
+
if (this.stickDrag) {
|
394
|
+
this.stickUp();
|
395
|
+
} else if (this.bodyDrag) {
|
396
|
+
this.bodyUp();
|
397
|
+
}
|
398
|
+
}
|
382
399
|
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
390
|
-
|
391
|
-
|
392
|
-
|
400
|
+
keydown(ev: any) {
|
401
|
+
if (!this.stickDrag && !this.bodyDrag) {
|
402
|
+
return;
|
403
|
+
}
|
404
|
+
ev.stopPropagation();
|
405
|
+
|
406
|
+
const { dimensionsBeforeMove } = this;
|
407
|
+
let pageX = 0,
|
408
|
+
pageY = 0;
|
409
|
+
if (ev.key === "a" || ev.key === "ArrowLeft") {
|
410
|
+
pageX = dimensionsBeforeMove.pointerX - 1;
|
411
|
+
pageY = dimensionsBeforeMove.pointerY;
|
412
|
+
} else if (ev.key === "d" || ev.key === "ArrowRight") {
|
413
|
+
pageX = dimensionsBeforeMove.pointerX + 1;
|
414
|
+
pageY = dimensionsBeforeMove.pointerY;
|
415
|
+
} else if (ev.key === "w" || ev.key === "ArrowUp") {
|
416
|
+
pageX = dimensionsBeforeMove.pointerX;
|
417
|
+
pageY = dimensionsBeforeMove.pointerY - 1;
|
418
|
+
} else if (ev.key === "s" || ev.key === "ArrowDown") {
|
419
|
+
pageX = dimensionsBeforeMove.pointerX;
|
420
|
+
pageY = dimensionsBeforeMove.pointerY + 1;
|
421
|
+
} else {
|
422
|
+
return;
|
423
|
+
}
|
393
424
|
|
394
|
-
|
425
|
+
const delta = {
|
426
|
+
x: (dimensionsBeforeMove.pointerX - pageX) / this.parentScaleX,
|
427
|
+
y: (dimensionsBeforeMove.pointerY - pageY) / this.parentScaleY,
|
428
|
+
};
|
395
429
|
|
396
|
-
|
397
|
-
|
398
|
-
|
430
|
+
if (this.stickDrag) {
|
431
|
+
this.stickMove(delta);
|
432
|
+
}
|
399
433
|
|
400
|
-
|
401
|
-
|
402
|
-
|
434
|
+
if (this.axis === "x") {
|
435
|
+
delta.y = 0;
|
436
|
+
} else if (this.axis === "y") {
|
437
|
+
delta.x = 0;
|
438
|
+
} else if (this.axis === "none") {
|
439
|
+
return;
|
440
|
+
}
|
441
|
+
this.bodyMove(delta);
|
403
442
|
|
404
|
-
|
405
|
-
|
406
|
-
}
|
443
|
+
this.saveDimensionsBeforeMove(delta.x, delta.y);
|
444
|
+
}
|
407
445
|
|
408
|
-
|
409
|
-
|
410
|
-
}
|
446
|
+
bodyDown(ev: any) {
|
447
|
+
const { target, button } = ev;
|
411
448
|
|
412
|
-
|
413
|
-
|
414
|
-
|
449
|
+
if (!this.preventActiveBehavior) {
|
450
|
+
this.active = true;
|
451
|
+
}
|
415
452
|
|
416
|
-
|
417
|
-
|
418
|
-
|
453
|
+
if (button && button !== 0) {
|
454
|
+
return;
|
455
|
+
}
|
419
456
|
|
420
|
-
|
421
|
-
const pointerY = typeof ev.pageY !== 'undefined' ? ev.pageY : ev.touches[0].pageY;
|
457
|
+
this.$emit("clicked", ev);
|
422
458
|
|
423
|
-
|
459
|
+
if (!this.active) {
|
460
|
+
return;
|
461
|
+
}
|
424
462
|
|
425
|
-
|
426
|
-
|
427
|
-
|
463
|
+
if (
|
464
|
+
this.dragHandle &&
|
465
|
+
target.getAttribute("data-drag-handle") !== this._uid.toString()
|
466
|
+
) {
|
467
|
+
return;
|
428
468
|
}
|
429
469
|
|
430
|
-
|
470
|
+
if (
|
471
|
+
this.dragCancel &&
|
472
|
+
target.getAttribute("data-drag-cancel") === this._uid.toString()
|
473
|
+
) {
|
474
|
+
return;
|
475
|
+
}
|
431
476
|
|
432
|
-
|
477
|
+
if (typeof ev.stopPropagation !== "undefined") {
|
478
|
+
ev.stopPropagation();
|
479
|
+
}
|
433
480
|
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
let newRight = dimensionsBeforeMove.right + delta.x;
|
481
|
+
if (typeof ev.preventDefault !== "undefined") {
|
482
|
+
ev.preventDefault();
|
483
|
+
}
|
438
484
|
|
439
|
-
|
440
|
-
|
441
|
-
|
485
|
+
if (this.isDraggable) {
|
486
|
+
this.bodyDrag = true;
|
487
|
+
}
|
442
488
|
|
443
|
-
|
444
|
-
|
445
|
-
|
446
|
-
|
489
|
+
const pointerX =
|
490
|
+
typeof ev.pageX !== "undefined" ? ev.pageX : ev.touches[0].pageX;
|
491
|
+
const pointerY =
|
492
|
+
typeof ev.pageY !== "undefined" ? ev.pageY : ev.touches[0].pageY;
|
447
493
|
|
448
|
-
|
449
|
-
diffT -= gridY;
|
450
|
-
}
|
451
|
-
if (diffB > (gridY / 2)) {
|
452
|
-
diffB -= gridY;
|
453
|
-
}
|
454
|
-
if (diffL > (gridX / 2)) {
|
455
|
-
diffL -= gridX;
|
456
|
-
}
|
457
|
-
if (diffR > (gridX / 2)) {
|
458
|
-
diffR -= gridX;
|
459
|
-
}
|
494
|
+
this.saveDimensionsBeforeMove(pointerX, pointerY);
|
460
495
|
|
461
|
-
|
462
|
-
|
463
|
-
|
464
|
-
|
465
|
-
alignLeft = false;
|
466
|
-
}
|
496
|
+
if (this.parentLimitation) {
|
497
|
+
this.limits = this.calcDragLimitation();
|
498
|
+
}
|
499
|
+
}
|
467
500
|
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
501
|
+
bodyMove(delta: any) {
|
502
|
+
const {
|
503
|
+
dimensionsBeforeMove,
|
504
|
+
parentWidth,
|
505
|
+
parentHeight,
|
506
|
+
gridX,
|
507
|
+
gridY,
|
508
|
+
width,
|
509
|
+
height,
|
510
|
+
} = this;
|
511
|
+
|
512
|
+
let newTop = dimensionsBeforeMove.top - delta.y;
|
513
|
+
let newBottom = dimensionsBeforeMove.bottom + delta.y;
|
514
|
+
let newLeft = dimensionsBeforeMove.left - delta.x;
|
515
|
+
let newRight = dimensionsBeforeMove.right + delta.x;
|
516
|
+
|
517
|
+
if (this.snapToGrid) {
|
518
|
+
let alignTop = true;
|
519
|
+
let alignLeft = true;
|
520
|
+
|
521
|
+
let diffT = newTop - Math.floor(newTop / gridY) * gridY;
|
522
|
+
let diffB =
|
523
|
+
parentHeight -
|
524
|
+
newBottom -
|
525
|
+
Math.floor((parentHeight - newBottom) / gridY) * gridY;
|
526
|
+
let diffL = newLeft - Math.floor(newLeft / gridX) * gridX;
|
527
|
+
let diffR =
|
528
|
+
parentWidth -
|
529
|
+
newRight -
|
530
|
+
Math.floor((parentWidth - newRight) / gridX) * gridX;
|
531
|
+
|
532
|
+
if (diffT > gridY / 2) {
|
533
|
+
diffT -= gridY;
|
534
|
+
}
|
535
|
+
if (diffB > gridY / 2) {
|
536
|
+
diffB -= gridY;
|
537
|
+
}
|
538
|
+
if (diffL > gridX / 2) {
|
539
|
+
diffL -= gridX;
|
540
|
+
}
|
541
|
+
if (diffR > gridX / 2) {
|
542
|
+
diffR -= gridX;
|
472
543
|
}
|
473
544
|
|
474
|
-
({
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
}
|
480
|
-
|
481
|
-
this.$emit('dragging', this.rect);
|
545
|
+
if (Math.abs(diffB) < Math.abs(diffT)) {
|
546
|
+
alignTop = false;
|
547
|
+
}
|
548
|
+
if (Math.abs(diffR) < Math.abs(diffL)) {
|
549
|
+
alignLeft = false;
|
550
|
+
}
|
482
551
|
|
483
|
-
|
552
|
+
newTop -= alignTop ? diffT : diffB;
|
553
|
+
newBottom = parentHeight - height - newTop;
|
554
|
+
newLeft -= alignLeft ? diffL : diffR;
|
555
|
+
newRight = parentWidth - width - newLeft;
|
484
556
|
}
|
485
557
|
|
486
|
-
|
487
|
-
this.
|
488
|
-
|
489
|
-
|
558
|
+
({
|
559
|
+
newLeft: this.left,
|
560
|
+
newRight: this.right,
|
561
|
+
newTop: this.top,
|
562
|
+
newBottom: this.bottom,
|
563
|
+
} = this.rectCorrectionByLimit({ newLeft, newRight, newTop, newBottom }));
|
490
564
|
|
491
|
-
|
492
|
-
|
493
|
-
this.limits = {
|
494
|
-
left: { min: null, max: null },
|
495
|
-
right: { min: null, max: null },
|
496
|
-
top: { min: null, max: null },
|
497
|
-
bottom: { min: null, max: null },
|
498
|
-
};
|
499
|
-
}
|
565
|
+
this.$emit("dragging", this.rect);
|
500
566
|
|
501
|
-
|
502
|
-
|
503
|
-
return;
|
504
|
-
}
|
567
|
+
this.storageElementInfo();
|
568
|
+
}
|
505
569
|
|
506
|
-
|
570
|
+
bodyUp() {
|
571
|
+
this.bodyDrag = false;
|
572
|
+
this.$emit("dragging", this.rect);
|
573
|
+
this.$emit("dragstop", this.rect);
|
574
|
+
|
575
|
+
this.dimensionsBeforeMove = {
|
576
|
+
pointerX: 0,
|
577
|
+
pointerY: 0,
|
578
|
+
x: 0,
|
579
|
+
y: 0,
|
580
|
+
w: 0,
|
581
|
+
h: 0,
|
582
|
+
};
|
583
|
+
|
584
|
+
this.limits = {
|
585
|
+
left: { min: null, max: null },
|
586
|
+
right: { min: null, max: null },
|
587
|
+
top: { min: null, max: null },
|
588
|
+
bottom: { min: null, max: null },
|
589
|
+
};
|
590
|
+
}
|
507
591
|
|
508
|
-
|
509
|
-
|
592
|
+
stickDown(stick: any, ev: any, force = false) {
|
593
|
+
if ((!this.isResizable || !this.active) && !force) {
|
594
|
+
return;
|
595
|
+
}
|
510
596
|
|
511
|
-
|
597
|
+
this.stickDrag = true;
|
512
598
|
|
513
|
-
|
599
|
+
const pointerX =
|
600
|
+
typeof ev.pageX !== "undefined" ? ev.pageX : ev.touches[0].pageX;
|
601
|
+
const pointerY =
|
602
|
+
typeof ev.pageY !== "undefined" ? ev.pageY : ev.touches[0].pageY;
|
514
603
|
|
515
|
-
|
516
|
-
}
|
604
|
+
this.saveDimensionsBeforeMove(pointerX, pointerY);
|
517
605
|
|
518
|
-
|
519
|
-
this.dimensionsBeforeMove.pointerX = pointerX;
|
520
|
-
this.dimensionsBeforeMove.pointerY = pointerY;
|
606
|
+
this.currentStick = stick;
|
521
607
|
|
522
|
-
|
523
|
-
|
524
|
-
this.dimensionsBeforeMove.top = this.top;
|
525
|
-
this.dimensionsBeforeMove.bottom = this.bottom;
|
608
|
+
this.limits = this.calcResizeLimits();
|
609
|
+
}
|
526
610
|
|
527
|
-
|
528
|
-
|
611
|
+
saveDimensionsBeforeMove(pointerX: number, pointerY: number): void {
|
612
|
+
this.dimensionsBeforeMove.pointerX = pointerX;
|
613
|
+
this.dimensionsBeforeMove.pointerY = pointerY;
|
529
614
|
|
530
|
-
|
531
|
-
|
615
|
+
this.dimensionsBeforeMove.left = this.left;
|
616
|
+
this.dimensionsBeforeMove.right = this.right;
|
617
|
+
this.dimensionsBeforeMove.top = this.top;
|
618
|
+
this.dimensionsBeforeMove.bottom = this.bottom;
|
532
619
|
|
533
|
-
|
534
|
-
|
535
|
-
currentStick,
|
536
|
-
dimensionsBeforeMove,
|
537
|
-
gridY,
|
538
|
-
gridX,
|
539
|
-
snapToGrid,
|
540
|
-
parentHeight,
|
541
|
-
parentWidth,
|
542
|
-
} = this;
|
620
|
+
this.dimensionsBeforeMove.width = this.width;
|
621
|
+
this.dimensionsBeforeMove.height = this.height;
|
543
622
|
|
544
|
-
|
545
|
-
|
546
|
-
let newLeft = dimensionsBeforeMove.left;
|
547
|
-
let newRight = dimensionsBeforeMove.right;
|
548
|
-
switch (currentStick[0]) {
|
549
|
-
case 'b':
|
550
|
-
newBottom = dimensionsBeforeMove.bottom + delta.y;
|
623
|
+
this.aspectFactor = this.width / this.height;
|
624
|
+
}
|
551
625
|
|
552
|
-
|
553
|
-
|
554
|
-
|
626
|
+
stickMove(delta: any) {
|
627
|
+
const {
|
628
|
+
currentStick,
|
629
|
+
dimensionsBeforeMove,
|
630
|
+
gridY,
|
631
|
+
gridX,
|
632
|
+
snapToGrid,
|
633
|
+
parentHeight,
|
634
|
+
parentWidth,
|
635
|
+
} = this;
|
636
|
+
|
637
|
+
let newTop = dimensionsBeforeMove.top;
|
638
|
+
let newBottom = dimensionsBeforeMove.bottom;
|
639
|
+
let newLeft = dimensionsBeforeMove.left;
|
640
|
+
let newRight = dimensionsBeforeMove.right;
|
641
|
+
switch (currentStick[0]) {
|
642
|
+
case "b":
|
643
|
+
newBottom = dimensionsBeforeMove.bottom + delta.y;
|
644
|
+
|
645
|
+
if (snapToGrid) {
|
646
|
+
newBottom =
|
647
|
+
parentHeight -
|
648
|
+
Math.round((parentHeight - newBottom) / gridY) * gridY;
|
649
|
+
}
|
555
650
|
|
556
|
-
|
651
|
+
break;
|
557
652
|
|
558
|
-
|
559
|
-
|
653
|
+
case "t":
|
654
|
+
newTop = dimensionsBeforeMove.top - delta.y;
|
560
655
|
|
561
|
-
|
562
|
-
|
563
|
-
|
656
|
+
if (snapToGrid) {
|
657
|
+
newTop = Math.round(newTop / gridY) * gridY;
|
658
|
+
}
|
564
659
|
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
660
|
+
break;
|
661
|
+
default:
|
662
|
+
break;
|
663
|
+
}
|
569
664
|
|
570
|
-
|
571
|
-
|
572
|
-
|
665
|
+
switch (currentStick[1]) {
|
666
|
+
case "r":
|
667
|
+
newRight = dimensionsBeforeMove.right + delta.x;
|
573
668
|
|
574
|
-
|
575
|
-
|
576
|
-
|
669
|
+
if (snapToGrid) {
|
670
|
+
newRight =
|
671
|
+
parentWidth - Math.round((parentWidth - newRight) / gridX) * gridX;
|
672
|
+
}
|
577
673
|
|
578
|
-
|
674
|
+
break;
|
579
675
|
|
580
|
-
|
581
|
-
|
676
|
+
case "l":
|
677
|
+
newLeft = dimensionsBeforeMove.left - delta.x;
|
582
678
|
|
583
|
-
|
584
|
-
|
585
|
-
|
679
|
+
if (snapToGrid) {
|
680
|
+
newLeft = Math.round(newLeft / gridX) * gridX;
|
681
|
+
}
|
586
682
|
|
587
|
-
|
588
|
-
|
589
|
-
|
590
|
-
|
683
|
+
break;
|
684
|
+
default:
|
685
|
+
break;
|
686
|
+
}
|
591
687
|
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
688
|
+
({ newLeft, newRight, newTop, newBottom } = this.rectCorrectionByLimit({
|
689
|
+
newLeft,
|
690
|
+
newRight,
|
691
|
+
newTop,
|
692
|
+
newBottom,
|
693
|
+
}));
|
598
694
|
|
599
|
-
|
600
|
-
|
695
|
+
if (this.aspectRatio) {
|
696
|
+
({ newLeft, newRight, newTop, newBottom } =
|
697
|
+
this.rectCorrectionByAspectRatio({
|
601
698
|
newLeft,
|
602
699
|
newRight,
|
603
700
|
newTop,
|
604
701
|
newBottom,
|
605
|
-
}
|
606
|
-
}
|
607
|
-
|
608
|
-
this.left = newLeft;
|
609
|
-
this.right = newRight;
|
610
|
-
this.top = newTop;
|
611
|
-
this.bottom = newBottom;
|
612
|
-
|
613
|
-
this.$emit('resizing', this.rect);
|
614
|
-
|
615
|
-
this.storageElementInfo()
|
702
|
+
}));
|
616
703
|
}
|
617
704
|
|
618
|
-
|
619
|
-
|
620
|
-
|
621
|
-
|
622
|
-
pointerY: 0,
|
623
|
-
x: 0,
|
624
|
-
y: 0,
|
625
|
-
w: 0,
|
626
|
-
h: 0,
|
627
|
-
};
|
628
|
-
this.limits = {
|
629
|
-
left: { min: null, max: null },
|
630
|
-
right: { min: null, max: null },
|
631
|
-
top: { min: null, max: null },
|
632
|
-
bottom: { min: null, max: null },
|
633
|
-
};
|
634
|
-
|
635
|
-
this.$emit('resizing', this.rect);
|
636
|
-
this.$emit('resizestop', this.rect);
|
637
|
-
}
|
705
|
+
this.left = newLeft;
|
706
|
+
this.right = newRight;
|
707
|
+
this.top = newTop;
|
708
|
+
this.bottom = newBottom;
|
638
709
|
|
639
|
-
|
640
|
-
const { parentWidth, parentHeight } = this;
|
710
|
+
this.$emit("resizing", this.rect);
|
641
711
|
|
642
|
-
|
643
|
-
|
644
|
-
right: { min: 0, max: parentWidth - this.width },
|
645
|
-
top: { min: 0, max: parentHeight - this.height },
|
646
|
-
bottom: { min: 0, max: parentHeight - this.height },
|
647
|
-
};
|
648
|
-
}
|
712
|
+
this.storageElementInfo();
|
713
|
+
}
|
649
714
|
|
650
|
-
|
651
|
-
|
652
|
-
|
715
|
+
stickUp() {
|
716
|
+
this.stickDrag = false;
|
717
|
+
this.dimensionsBeforeMove = {
|
718
|
+
pointerX: 0,
|
719
|
+
pointerY: 0,
|
720
|
+
x: 0,
|
721
|
+
y: 0,
|
722
|
+
w: 0,
|
723
|
+
h: 0,
|
724
|
+
};
|
725
|
+
this.limits = {
|
726
|
+
left: { min: null, max: null },
|
727
|
+
right: { min: null, max: null },
|
728
|
+
top: { min: null, max: null },
|
729
|
+
bottom: { min: null, max: null },
|
730
|
+
};
|
731
|
+
|
732
|
+
this.$emit("resizing", this.rect);
|
733
|
+
this.$emit("resizestop", this.rect);
|
734
|
+
}
|
653
735
|
|
654
|
-
|
736
|
+
calcDragLimitation() {
|
737
|
+
const { parentWidth, parentHeight } = this;
|
655
738
|
|
656
|
-
|
657
|
-
|
658
|
-
|
659
|
-
|
660
|
-
|
661
|
-
|
662
|
-
|
739
|
+
return {
|
740
|
+
left: { min: 0, max: parentWidth - this.width },
|
741
|
+
right: { min: 0, max: parentWidth - this.width },
|
742
|
+
top: { min: 0, max: parentHeight - this.height },
|
743
|
+
bottom: { min: 0, max: parentHeight - this.height },
|
744
|
+
};
|
745
|
+
}
|
663
746
|
|
664
|
-
|
665
|
-
|
666
|
-
|
667
|
-
top: { min: parentLim, max: top + (height - minHeight) },
|
668
|
-
bottom: { min: parentLim, max: bottom + (height - minHeight) },
|
669
|
-
};
|
747
|
+
calcResizeLimits() {
|
748
|
+
const { aspectFactor, width, height, bottom, top, left, right } = this;
|
749
|
+
let { minh: minHeight, minw: minWidth } = this;
|
670
750
|
|
671
|
-
|
672
|
-
const aspectLimits = {
|
673
|
-
left: {
|
674
|
-
min: left - (Math.min(top, bottom) * aspectFactor) * 2,
|
675
|
-
max: left + ((((height - minHeight) / 2) * aspectFactor) * 2),
|
676
|
-
},
|
677
|
-
right: {
|
678
|
-
min: right - (Math.min(top, bottom) * aspectFactor) * 2,
|
679
|
-
max: right + ((((height - minHeight) / 2) * aspectFactor) * 2),
|
680
|
-
},
|
681
|
-
top: {
|
682
|
-
min: top - (Math.min(left, right) / aspectFactor) * 2,
|
683
|
-
max: top + ((((width - minWidth) / 2) / aspectFactor) * 2),
|
684
|
-
},
|
685
|
-
bottom: {
|
686
|
-
min: bottom - (Math.min(left, right) / aspectFactor) * 2,
|
687
|
-
max: bottom + ((((width - minWidth) / 2) / aspectFactor) * 2),
|
688
|
-
},
|
689
|
-
};
|
751
|
+
const parentLim = this.parentLimitation ? 0 : null;
|
690
752
|
|
691
|
-
|
692
|
-
|
693
|
-
|
694
|
-
|
695
|
-
|
696
|
-
limits.right = {
|
697
|
-
min: Math.max(limits.right.min as number, aspectLimits.right.min),
|
698
|
-
max: Math.min(limits.right.max, aspectLimits.right.max),
|
699
|
-
};
|
700
|
-
|
701
|
-
} else if (this.currentStick[1] === 'm') {
|
702
|
-
limits.top = {
|
703
|
-
min: Math.max(limits.top.min as number, aspectLimits.top.min),
|
704
|
-
max: Math.min(limits.top.max, aspectLimits.top.max),
|
705
|
-
};
|
706
|
-
limits.bottom = {
|
707
|
-
min: Math.max(limits.bottom.min as number, aspectLimits.bottom.min),
|
708
|
-
max: Math.min(limits.bottom.max, aspectLimits.bottom.max),
|
709
|
-
};
|
710
|
-
}
|
753
|
+
if (this.aspectRatio) {
|
754
|
+
if (minWidth / minHeight > aspectFactor) {
|
755
|
+
minHeight = minWidth / aspectFactor;
|
756
|
+
} else {
|
757
|
+
minWidth = aspectFactor * minHeight;
|
711
758
|
}
|
712
|
-
|
713
|
-
return limits;
|
714
759
|
}
|
715
760
|
|
716
|
-
|
717
|
-
|
761
|
+
const limits = {
|
762
|
+
left: { min: parentLim, max: left + (width - minWidth) },
|
763
|
+
right: { min: parentLim, max: right + (width - minWidth) },
|
764
|
+
top: { min: parentLim, max: top + (height - minHeight) },
|
765
|
+
bottom: { min: parentLim, max: bottom + (height - minHeight) },
|
766
|
+
};
|
767
|
+
|
768
|
+
if (this.aspectRatio) {
|
769
|
+
const aspectLimits = {
|
770
|
+
left: {
|
771
|
+
min: left - Math.min(top, bottom) * aspectFactor * 2,
|
772
|
+
max: left + ((height - minHeight) / 2) * aspectFactor * 2,
|
773
|
+
},
|
774
|
+
right: {
|
775
|
+
min: right - Math.min(top, bottom) * aspectFactor * 2,
|
776
|
+
max: right + ((height - minHeight) / 2) * aspectFactor * 2,
|
777
|
+
},
|
778
|
+
top: {
|
779
|
+
min: top - (Math.min(left, right) / aspectFactor) * 2,
|
780
|
+
max: top + ((width - minWidth) / 2 / aspectFactor) * 2,
|
781
|
+
},
|
782
|
+
bottom: {
|
783
|
+
min: bottom - (Math.min(left, right) / aspectFactor) * 2,
|
784
|
+
max: bottom + ((width - minWidth) / 2 / aspectFactor) * 2,
|
785
|
+
},
|
786
|
+
};
|
718
787
|
|
719
|
-
if (
|
720
|
-
|
721
|
-
|
722
|
-
|
788
|
+
if (this.currentStick[0] === "m") {
|
789
|
+
limits.left = {
|
790
|
+
min: Math.max(limits.left.min as number, aspectLimits.left.min),
|
791
|
+
max: Math.min(limits.left.max, aspectLimits.left.max),
|
792
|
+
};
|
793
|
+
limits.right = {
|
794
|
+
min: Math.max(limits.right.min as number, aspectLimits.right.min),
|
795
|
+
max: Math.min(limits.right.max, aspectLimits.right.max),
|
796
|
+
};
|
797
|
+
} else if (this.currentStick[1] === "m") {
|
798
|
+
limits.top = {
|
799
|
+
min: Math.max(limits.top.min as number, aspectLimits.top.min),
|
800
|
+
max: Math.min(limits.top.max, aspectLimits.top.max),
|
801
|
+
};
|
802
|
+
limits.bottom = {
|
803
|
+
min: Math.max(limits.bottom.min as number, aspectLimits.bottom.min),
|
804
|
+
max: Math.min(limits.bottom.max, aspectLimits.bottom.max),
|
805
|
+
};
|
723
806
|
}
|
724
|
-
|
725
|
-
return value;
|
726
807
|
}
|
727
808
|
|
728
|
-
|
729
|
-
|
730
|
-
let { newRight, newLeft, newBottom, newTop } = rect;
|
809
|
+
return limits;
|
810
|
+
}
|
731
811
|
|
732
|
-
|
733
|
-
|
734
|
-
newTop = this.sideCorrectionByLimit(limits.top, newTop);
|
735
|
-
newBottom = this.sideCorrectionByLimit(limits.bottom, newBottom);
|
812
|
+
sideCorrectionByLimit(limit: any, current: any) {
|
813
|
+
let value = current;
|
736
814
|
|
737
|
-
|
738
|
-
|
739
|
-
|
740
|
-
|
741
|
-
newBottom,
|
742
|
-
};
|
815
|
+
if (limit.min !== null && current < limit.min) {
|
816
|
+
value = limit.min;
|
817
|
+
} else if (limit.max !== null && limit.max < current) {
|
818
|
+
value = limit.max;
|
743
819
|
}
|
744
820
|
|
745
|
-
|
746
|
-
|
747
|
-
const { parentWidth, parentHeight, currentStick, aspectFactor, dimensionsBeforeMove } = this;
|
748
|
-
|
749
|
-
let newWidth = parentWidth - newLeft - newRight;
|
750
|
-
let newHeight = parentHeight - newTop - newBottom;
|
751
|
-
|
752
|
-
if (currentStick[1] === 'm') {
|
753
|
-
const deltaHeight = newHeight - dimensionsBeforeMove.height;
|
754
|
-
|
755
|
-
newLeft -= (deltaHeight * aspectFactor) / 2;
|
756
|
-
newRight -= (deltaHeight * aspectFactor) / 2;
|
757
|
-
} else if (currentStick[0] === 'm') {
|
758
|
-
const deltaWidth = newWidth - dimensionsBeforeMove.width;
|
821
|
+
return value;
|
822
|
+
}
|
759
823
|
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
824
|
+
rectCorrectionByLimit(rect: any) {
|
825
|
+
const { limits } = this;
|
826
|
+
let { newRight, newLeft, newBottom, newTop } = rect;
|
827
|
+
|
828
|
+
newLeft = this.sideCorrectionByLimit(limits.left, newLeft);
|
829
|
+
newRight = this.sideCorrectionByLimit(limits.right, newRight);
|
830
|
+
newTop = this.sideCorrectionByLimit(limits.top, newTop);
|
831
|
+
newBottom = this.sideCorrectionByLimit(limits.bottom, newBottom);
|
832
|
+
|
833
|
+
return {
|
834
|
+
newLeft,
|
835
|
+
newRight,
|
836
|
+
newTop,
|
837
|
+
newBottom,
|
838
|
+
};
|
839
|
+
}
|
764
840
|
|
765
|
-
|
766
|
-
|
767
|
-
|
768
|
-
|
769
|
-
|
841
|
+
rectCorrectionByAspectRatio(rect: any) {
|
842
|
+
let { newLeft, newRight, newTop, newBottom } = rect;
|
843
|
+
const {
|
844
|
+
parentWidth,
|
845
|
+
parentHeight,
|
846
|
+
currentStick,
|
847
|
+
aspectFactor,
|
848
|
+
dimensionsBeforeMove,
|
849
|
+
} = this;
|
850
|
+
|
851
|
+
let newWidth = parentWidth - newLeft - newRight;
|
852
|
+
let newHeight = parentHeight - newTop - newBottom;
|
853
|
+
|
854
|
+
if (currentStick[1] === "m") {
|
855
|
+
const deltaHeight = newHeight - dimensionsBeforeMove.height;
|
856
|
+
|
857
|
+
newLeft -= (deltaHeight * aspectFactor) / 2;
|
858
|
+
newRight -= (deltaHeight * aspectFactor) / 2;
|
859
|
+
} else if (currentStick[0] === "m") {
|
860
|
+
const deltaWidth = newWidth - dimensionsBeforeMove.width;
|
861
|
+
|
862
|
+
newTop -= deltaWidth / aspectFactor / 2;
|
863
|
+
newBottom -= deltaWidth / aspectFactor / 2;
|
864
|
+
} else if (newWidth / newHeight > aspectFactor) {
|
865
|
+
newWidth = aspectFactor * newHeight;
|
866
|
+
|
867
|
+
if (currentStick[1] === "l") {
|
868
|
+
newLeft = parentWidth - newRight - newWidth;
|
770
869
|
} else {
|
771
|
-
|
772
|
-
|
773
|
-
if (currentStick[0] === 't') {
|
774
|
-
newTop = parentHeight - newBottom - newHeight;
|
775
|
-
} else {
|
776
|
-
newBottom = parentHeight - newTop - newHeight;
|
777
|
-
}
|
870
|
+
newRight = parentWidth - newLeft - newWidth;
|
778
871
|
}
|
872
|
+
} else {
|
873
|
+
newHeight = newWidth / aspectFactor;
|
779
874
|
|
780
|
-
|
875
|
+
if (currentStick[0] === "t") {
|
876
|
+
newTop = parentHeight - newBottom - newHeight;
|
877
|
+
} else {
|
878
|
+
newBottom = parentHeight - newTop - newHeight;
|
879
|
+
}
|
781
880
|
}
|
782
881
|
|
783
|
-
|
784
|
-
|
785
|
-
if (!this.isStorage)
|
786
|
-
return
|
882
|
+
return { newLeft, newRight, newTop, newBottom };
|
883
|
+
}
|
787
884
|
|
788
|
-
|
789
|
-
|
790
|
-
}
|
885
|
+
storageElementInfo() {
|
886
|
+
if (!this.isStorage) return;
|
791
887
|
|
792
|
-
|
793
|
-
|
794
|
-
}
|
795
|
-
|
796
|
-
const info = { "left": this.rect.left, "top": this.rect.top, "right": this.right, "bottom": this.bottom }
|
797
|
-
localStorage.setItem("DragResizeView_Rect_" + this.name, JSON.stringify(info))
|
888
|
+
if (this.name.trim() === "") {
|
889
|
+
throw "unspecified name";
|
798
890
|
}
|
799
891
|
|
800
|
-
|
801
|
-
|
802
|
-
|
803
|
-
|
804
|
-
|
805
|
-
|
892
|
+
if (
|
893
|
+
this.rect.left === null ||
|
894
|
+
this.rect.top === null ||
|
895
|
+
this.right === null ||
|
896
|
+
this.bottom === null
|
897
|
+
) {
|
898
|
+
return;
|
806
899
|
}
|
807
900
|
|
808
|
-
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
}
|
901
|
+
const info = {
|
902
|
+
left: this.rect.left,
|
903
|
+
top: this.rect.top,
|
904
|
+
right: this.right,
|
905
|
+
bottom: this.bottom,
|
906
|
+
};
|
907
|
+
localStorage.setItem(
|
908
|
+
"DragResizeView_Rect_" + this.name,
|
909
|
+
JSON.stringify(info)
|
910
|
+
);
|
911
|
+
}
|
814
912
|
|
913
|
+
get positionStyle() {
|
914
|
+
return {
|
915
|
+
top: this.top + "px",
|
916
|
+
left: this.left + "px",
|
917
|
+
zIndex: this.zIndex,
|
918
|
+
};
|
919
|
+
}
|
815
920
|
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
921
|
+
get sizeStyle() {
|
922
|
+
return {
|
923
|
+
width: this.w == "auto" ? "auto" : this.width + "px",
|
924
|
+
height: this.h == "auto" ? "auto" : this.height + "px",
|
925
|
+
};
|
926
|
+
}
|
927
|
+
|
928
|
+
get vdrStick() {
|
929
|
+
return (stick: any) => {
|
930
|
+
const stickStyle: any = {
|
931
|
+
width: `${this.stickSize / this.parentScaleX}px`,
|
932
|
+
height: `${this.stickSize / this.parentScaleY}px`,
|
825
933
|
};
|
826
|
-
|
934
|
+
stickStyle[styleMapping.y[stick[0]]] = `${
|
935
|
+
this.stickSize / this.parentScaleX / -2
|
936
|
+
}px`;
|
937
|
+
stickStyle[styleMapping.x[stick[1]]] = `${
|
938
|
+
this.stickSize / this.parentScaleX / -2
|
939
|
+
}px`;
|
940
|
+
return stickStyle;
|
941
|
+
};
|
942
|
+
}
|
827
943
|
|
828
|
-
|
829
|
-
|
830
|
-
|
944
|
+
get width() {
|
945
|
+
return this.parentWidth - this.left - this.right;
|
946
|
+
}
|
831
947
|
|
832
|
-
|
833
|
-
|
834
|
-
|
948
|
+
get height() {
|
949
|
+
return this.parentHeight - this.top - this.bottom;
|
950
|
+
}
|
835
951
|
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
952
|
+
get rect() {
|
953
|
+
return {
|
954
|
+
left: Math.round(this.left),
|
955
|
+
top: Math.round(this.top),
|
956
|
+
width: Math.round(this.width),
|
957
|
+
height: Math.round(this.height),
|
958
|
+
};
|
959
|
+
}
|
844
960
|
|
845
|
-
|
846
|
-
|
847
|
-
|
848
|
-
|
849
|
-
|
850
|
-
|
851
|
-
}
|
961
|
+
@Watch("active", { immediate: false, deep: false })
|
962
|
+
onActive(isActive: boolean) {
|
963
|
+
if (isActive) {
|
964
|
+
this.$emit("activated");
|
965
|
+
} else {
|
966
|
+
this.$emit("deactivated");
|
852
967
|
}
|
968
|
+
}
|
853
969
|
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
970
|
+
@Watch("isActive", { immediate: true, deep: false })
|
971
|
+
onIsActive(val: boolean) {
|
972
|
+
this.active = val;
|
973
|
+
}
|
858
974
|
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
}
|
975
|
+
@Watch("z", { immediate: true, deep: false })
|
976
|
+
onZ(val: number | string) {
|
977
|
+
if (val >= 0 || val === "auto") {
|
978
|
+
this.zIndex = val as number;
|
864
979
|
}
|
980
|
+
}
|
865
981
|
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
}
|
871
|
-
|
872
|
-
const delta = oldVal - newVal;
|
873
|
-
|
874
|
-
this.bodyDown({ pageX: this.left, pageY: this.top });
|
875
|
-
this.bodyMove({ x: delta, y: 0 });
|
876
|
-
|
877
|
-
this.$nextTick(() => {
|
878
|
-
this.bodyUp();
|
879
|
-
});
|
982
|
+
@Watch("x", { immediate: false, deep: false })
|
983
|
+
onX(newVal: number, oldVal: number) {
|
984
|
+
if (this.stickDrag || this.bodyDrag || newVal === this.left) {
|
985
|
+
return;
|
880
986
|
}
|
881
987
|
|
882
|
-
|
883
|
-
onY(newVal: number, oldVal: number) {
|
884
|
-
if (this.stickDrag || this.bodyDrag || (newVal === this.top)) {
|
885
|
-
return;
|
886
|
-
}
|
988
|
+
const delta = oldVal - newVal;
|
887
989
|
|
888
|
-
|
990
|
+
this.bodyDown({ pageX: this.left, pageY: this.top });
|
991
|
+
this.bodyMove({ x: delta, y: 0 });
|
889
992
|
|
890
|
-
|
891
|
-
this.
|
993
|
+
this.$nextTick(() => {
|
994
|
+
this.bodyUp();
|
995
|
+
});
|
996
|
+
}
|
892
997
|
|
893
|
-
|
894
|
-
|
895
|
-
|
998
|
+
@Watch("y", { immediate: false, deep: false })
|
999
|
+
onY(newVal: number, oldVal: number) {
|
1000
|
+
if (this.stickDrag || this.bodyDrag || newVal === this.top) {
|
1001
|
+
return;
|
896
1002
|
}
|
897
1003
|
|
898
|
-
|
899
|
-
onW(newVal: number, oldVal: number) {
|
900
|
-
if (this.stickDrag || this.bodyDrag || (newVal === this.width)) {
|
901
|
-
return;
|
902
|
-
}
|
1004
|
+
const delta = oldVal - newVal;
|
903
1005
|
|
904
|
-
|
905
|
-
|
1006
|
+
this.bodyDown({ pageX: this.left, pageY: this.top });
|
1007
|
+
this.bodyMove({ x: 0, y: delta });
|
906
1008
|
|
907
|
-
|
908
|
-
this.
|
1009
|
+
this.$nextTick(() => {
|
1010
|
+
this.bodyUp();
|
1011
|
+
});
|
1012
|
+
}
|
909
1013
|
|
910
|
-
|
911
|
-
|
912
|
-
|
1014
|
+
@Watch("w", { immediate: false, deep: false })
|
1015
|
+
onW(newVal: number, oldVal: number) {
|
1016
|
+
if (this.stickDrag || this.bodyDrag || newVal === this.width) {
|
1017
|
+
return;
|
913
1018
|
}
|
914
1019
|
|
915
|
-
|
916
|
-
|
917
|
-
if (this.stickDrag || this.bodyDrag || (newVal === this.height)) {
|
918
|
-
return;
|
919
|
-
}
|
1020
|
+
const stick = "mr";
|
1021
|
+
const delta = oldVal - newVal;
|
920
1022
|
|
921
|
-
|
922
|
-
|
1023
|
+
this.stickDown(
|
1024
|
+
stick,
|
1025
|
+
{ pageX: this.right, pageY: this.top + this.height / 2 },
|
1026
|
+
true
|
1027
|
+
);
|
1028
|
+
this.stickMove({ x: delta, y: 0 });
|
923
1029
|
|
924
|
-
|
925
|
-
this.
|
1030
|
+
this.$nextTick(() => {
|
1031
|
+
this.stickUp();
|
1032
|
+
});
|
1033
|
+
}
|
926
1034
|
|
927
|
-
|
928
|
-
|
929
|
-
|
1035
|
+
@Watch("h", { immediate: false, deep: false })
|
1036
|
+
onH(newVal: number, oldVal: number) {
|
1037
|
+
if (this.stickDrag || this.bodyDrag || newVal === this.height) {
|
1038
|
+
return;
|
930
1039
|
}
|
931
1040
|
|
932
|
-
|
933
|
-
|
934
|
-
this.right = val - this.width - this.left;
|
935
|
-
this.parentWidth = val;
|
936
|
-
}
|
1041
|
+
const stick = "bm";
|
1042
|
+
const delta = oldVal - newVal;
|
937
1043
|
|
1044
|
+
this.stickDown(
|
1045
|
+
stick,
|
1046
|
+
{ pageX: this.left + this.width / 2, pageY: this.bottom },
|
1047
|
+
true
|
1048
|
+
);
|
1049
|
+
this.stickMove({ x: 0, y: delta });
|
938
1050
|
|
939
|
-
|
940
|
-
|
941
|
-
|
942
|
-
|
943
|
-
}
|
1051
|
+
this.$nextTick(() => {
|
1052
|
+
this.stickUp();
|
1053
|
+
});
|
1054
|
+
}
|
944
1055
|
|
1056
|
+
@Watch("parentW", { immediate: false, deep: false })
|
1057
|
+
onParentW(val: number) {
|
1058
|
+
this.right = val - this.width - this.left;
|
1059
|
+
this.parentWidth = val;
|
945
1060
|
}
|
946
1061
|
|
947
|
-
|
948
|
-
|
949
|
-
|
1062
|
+
@Watch("parentH", { immediate: false, deep: false })
|
1063
|
+
onParentH(val: number) {
|
1064
|
+
this.bottom = val - this.height - this.top;
|
1065
|
+
this.parentHeight = val;
|
1066
|
+
}
|
1067
|
+
}
|
950
1068
|
|
1069
|
+
// 待实现功能:
|
1070
|
+
// 1. 移动时与其他组件对齐
|
1071
|
+
// 2. 通过键盘上下左右移动
|
951
1072
|
</script>
|
952
1073
|
|
953
1074
|
<style lang="less" scoped>
|
954
|
-
|
955
|
-
</style>
|
1075
|
+
@import "index.less";
|
1076
|
+
</style>
|