@progress/kendo-angular-utils 12.0.0-develop.8 → 12.0.0-develop.9
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/drag-and-drop/drag-state.service.d.ts +4 -0
- package/drag-and-drop/draghandle.directive.d.ts +1 -0
- package/drag-and-drop/dragtarget-container.directive.d.ts +164 -0
- package/drag-and-drop/dragtarget.directive.d.ts +45 -42
- package/drag-and-drop/droptarget-container.directive.d.ts +89 -0
- package/drag-and-drop/droptarget.directive.d.ts +7 -18
- package/drag-and-drop/events/drag-target/drag-event.d.ts +23 -5
- package/drag-and-drop/events/drag-target/dragready-event.d.ts +30 -0
- package/drag-and-drop/events/drag-target/end-event.d.ts +22 -4
- package/drag-and-drop/events/drag-target/index.d.ts +2 -0
- package/drag-and-drop/events/drag-target/press-event.d.ts +23 -5
- package/drag-and-drop/events/drag-target/release-event.d.ts +40 -0
- package/drag-and-drop/events/drag-target/start-event.d.ts +22 -4
- package/drag-and-drop/events/drop-target-event.d.ts +48 -0
- package/drag-and-drop/events/index.d.ts +6 -0
- package/drag-and-drop/hint.component.d.ts +3 -4
- package/{esm2020/drag-and-drop/events/drop-target/drop-event.mjs → drag-and-drop/models/drag-mode.d.ts} +2 -9
- package/drag-and-drop/models/functions.d.ts +17 -0
- package/drag-and-drop/models/hint-settings.d.ts +22 -0
- package/drag-and-drop/models/index.d.ts +4 -2
- package/drag-and-drop/util.d.ts +22 -2
- package/drag-and-drop.module.d.ts +5 -3
- package/esm2020/drag-and-drop/drag-state.service.mjs +2 -0
- package/esm2020/drag-and-drop/draghandle.directive.mjs +1 -0
- package/esm2020/drag-and-drop/dragtarget-container.directive.mjs +621 -0
- package/esm2020/drag-and-drop/dragtarget.directive.mjs +260 -162
- package/esm2020/drag-and-drop/droptarget-container.directive.mjs +224 -0
- package/esm2020/drag-and-drop/droptarget.directive.mjs +25 -43
- package/esm2020/drag-and-drop/events/drag-target/drag-event.mjs +15 -1
- package/esm2020/drag-and-drop/events/{drop-target/enter-event.mjs → drag-target/dragready-event.mjs} +2 -2
- package/esm2020/drag-and-drop/events/drag-target/end-event.mjs +15 -1
- package/esm2020/drag-and-drop/events/drag-target/index.mjs +2 -0
- package/esm2020/drag-and-drop/events/drag-target/press-event.mjs +15 -1
- package/esm2020/drag-and-drop/events/{drop-target/leave-event.mjs → drag-target/release-event.mjs} +16 -2
- package/esm2020/drag-and-drop/events/drag-target/start-event.mjs +15 -1
- package/esm2020/drag-and-drop/events/drop-target-event.mjs +29 -0
- package/esm2020/drag-and-drop/events/index.mjs +6 -0
- package/esm2020/drag-and-drop/hint.component.mjs +9 -20
- package/esm2020/drag-and-drop/models/functions.mjs +5 -0
- package/esm2020/drag-and-drop/models/hint-settings.mjs +5 -0
- package/esm2020/drag-and-drop/util.mjs +73 -5
- package/esm2020/drag-and-drop.module.mjs +8 -0
- package/esm2020/index.mjs +4 -1
- package/esm2020/package-metadata.mjs +2 -2
- package/fesm2015/progress-kendo-angular-utils.mjs +1346 -307
- package/fesm2020/progress-kendo-angular-utils.mjs +1349 -313
- package/index.d.ts +4 -2
- package/package.json +3 -3
- package/drag-and-drop/events/drop-target/drop-event.d.ts +0 -22
- package/drag-and-drop/events/drop-target/enter-event.d.ts +0 -22
- package/drag-and-drop/events/drop-target/index.d.ts +0 -8
- package/drag-and-drop/events/drop-target/leave-event.d.ts +0 -22
- package/drag-and-drop/events/drop-target/over-event.d.ts +0 -22
- package/drag-and-drop/models/allowed-target.d.ts +0 -16
- package/esm2020/drag-and-drop/events/drop-target/index.mjs +0 -8
- package/esm2020/drag-and-drop/events/drop-target/over-event.mjs +0 -15
- /package/drag-and-drop/models/{dragaxis.d.ts → drag-axis.d.ts} +0 -0
- /package/esm2020/drag-and-drop/models/{allowed-target.mjs → drag-axis.mjs} +0 -0
- /package/esm2020/drag-and-drop/models/{dragaxis.mjs → drag-mode.mjs} +0 -0
|
@@ -3,12 +3,14 @@
|
|
|
3
3
|
* Licensed under commercial license. See LICENSE.md in the project root for more information
|
|
4
4
|
*-------------------------------------------------------------------------------------------*/
|
|
5
5
|
import * as i0 from '@angular/core';
|
|
6
|
-
import { Directive, HostBinding, Component, Input, Injectable, EventEmitter, Output, ContentChildren, NgModule } from '@angular/core';
|
|
6
|
+
import { Directive, HostBinding, Component, Input, Injectable, EventEmitter, isDevMode, Output, ContentChildren, NgModule } from '@angular/core';
|
|
7
7
|
import * as i1 from '@angular/common';
|
|
8
8
|
import { CommonModule } from '@angular/common';
|
|
9
9
|
import { validatePackage } from '@progress/kendo-licensing';
|
|
10
10
|
import { dispatchDragAndDrop, getScrollableParent, autoScroll } from '@progress/kendo-draggable-common';
|
|
11
|
-
import { PreventableEvent, contains, isDocumentAvailable } from '@progress/kendo-angular-common';
|
|
11
|
+
import { PreventableEvent, contains, isDocumentAvailable, parseCSSClassNames } from '@progress/kendo-angular-common';
|
|
12
|
+
import { fromEvent, merge } from 'rxjs';
|
|
13
|
+
import { filter } from 'rxjs/operators';
|
|
12
14
|
|
|
13
15
|
/**
|
|
14
16
|
* @hidden
|
|
@@ -17,13 +19,14 @@ const packageMetadata = {
|
|
|
17
19
|
name: '@progress/kendo-angular-utils',
|
|
18
20
|
productName: 'Kendo UI for Angular',
|
|
19
21
|
productCodes: ['KENDOUIANGULAR', 'KENDOUICOMPLETE'],
|
|
20
|
-
publishDate:
|
|
21
|
-
version: '12.0.0-develop.
|
|
22
|
+
publishDate: 1681884386,
|
|
23
|
+
version: '12.0.0-develop.9',
|
|
22
24
|
licensingDocsUrl: 'https://www.telerik.com/kendo-angular-ui/my-license/'
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
/**
|
|
26
28
|
* Represents the Kendo UI DragHandle directive for Angular.
|
|
29
|
+
* It is used to specify a concrete element within a drag target as a handle for dragging, instead the drag target itself.
|
|
27
30
|
*/
|
|
28
31
|
class DragHandleDirective {
|
|
29
32
|
constructor(element) {
|
|
@@ -44,68 +47,78 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
|
|
|
44
47
|
args: ['class.k-cursor-pointer']
|
|
45
48
|
}] } });
|
|
46
49
|
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
*/
|
|
50
|
-
class DragTargetPressEvent {
|
|
51
|
-
/**
|
|
52
|
-
* @hidden
|
|
53
|
-
*/
|
|
54
|
-
constructor(args) {
|
|
55
|
-
Object.assign(this, args);
|
|
56
|
-
}
|
|
50
|
+
function isDocumentNode(container) {
|
|
51
|
+
return container.nodeType === 9;
|
|
57
52
|
}
|
|
58
|
-
|
|
59
53
|
/**
|
|
60
|
-
*
|
|
54
|
+
* @hidden
|
|
61
55
|
*/
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
Object.assign(this, args);
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
|
|
56
|
+
const getAction = (event, draggable) => {
|
|
57
|
+
return {
|
|
58
|
+
event: event,
|
|
59
|
+
payload: draggable
|
|
60
|
+
};
|
|
61
|
+
};
|
|
72
62
|
/**
|
|
73
|
-
*
|
|
63
|
+
* @hidden
|
|
74
64
|
*/
|
|
75
|
-
|
|
76
|
-
/**
|
|
77
|
-
* @hidden
|
|
78
|
-
*/
|
|
79
|
-
constructor(args) {
|
|
80
|
-
Object.assign(this, args);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
|
|
65
|
+
const dragTargetTransition = 'transform .3s ease-in-out';
|
|
84
66
|
/**
|
|
85
|
-
*
|
|
67
|
+
* @hidden
|
|
86
68
|
*/
|
|
87
|
-
|
|
88
|
-
/**
|
|
89
|
-
* @hidden
|
|
90
|
-
*/
|
|
91
|
-
constructor(args) {
|
|
92
|
-
super();
|
|
93
|
-
Object.assign(this, args);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
69
|
+
const isPresent = (value) => value !== null && value !== undefined;
|
|
97
70
|
/**
|
|
98
71
|
* @hidden
|
|
99
72
|
*/
|
|
100
|
-
|
|
73
|
+
function closestBySelector(element, selector) {
|
|
74
|
+
if (element.closest) {
|
|
75
|
+
return element.closest(selector);
|
|
76
|
+
}
|
|
77
|
+
const matches = Element.prototype.matches ?
|
|
78
|
+
(el, sel) => el.matches(sel)
|
|
79
|
+
: (el, sel) => el.msMatchesSelector(sel);
|
|
80
|
+
let node = element;
|
|
81
|
+
while (node && !isDocumentNode(node)) {
|
|
82
|
+
if (matches(node, selector)) {
|
|
83
|
+
return node;
|
|
84
|
+
}
|
|
85
|
+
node = node.parentNode;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
101
88
|
/**
|
|
102
89
|
* @hidden
|
|
103
90
|
*/
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
91
|
+
const intersect = (element, candidates) => {
|
|
92
|
+
let max = 0;
|
|
93
|
+
let result = null;
|
|
94
|
+
candidates.forEach((candidate) => {
|
|
95
|
+
if (candidate && element) {
|
|
96
|
+
const ration = getRatio(element, candidate);
|
|
97
|
+
if (ration > max) {
|
|
98
|
+
max = ration;
|
|
99
|
+
result = candidate;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
return result;
|
|
104
|
+
};
|
|
105
|
+
const getRatio = (element, target) => {
|
|
106
|
+
const elementRect = element.getBoundingClientRect();
|
|
107
|
+
const targetRect = target.getBoundingClientRect();
|
|
108
|
+
const top = Math.max(targetRect.top, elementRect.top);
|
|
109
|
+
const left = Math.max(targetRect.left, elementRect.left);
|
|
110
|
+
const right = Math.min(targetRect.left + targetRect.width, elementRect.left + elementRect.width);
|
|
111
|
+
const bottom = Math.min(targetRect.top + targetRect.height, elementRect.top + elementRect.height);
|
|
112
|
+
const width = right - left;
|
|
113
|
+
const height = bottom - top;
|
|
114
|
+
if (left < right && top < bottom) {
|
|
115
|
+
const targetArea = targetRect.width * targetRect.height;
|
|
116
|
+
const entryArea = elementRect.width * elementRect.height;
|
|
117
|
+
const intersectionArea = width * height;
|
|
118
|
+
const intersectionRatio = intersectionArea / (targetArea + entryArea - intersectionArea);
|
|
119
|
+
return Number(intersectionRatio.toFixed(4));
|
|
120
|
+
}
|
|
121
|
+
return 0;
|
|
109
122
|
};
|
|
110
123
|
/**
|
|
111
124
|
* @hidden
|
|
@@ -119,30 +132,35 @@ const setElementStyles = (renderer, elem, styles) => {
|
|
|
119
132
|
/**
|
|
120
133
|
* @hidden
|
|
121
134
|
*/
|
|
122
|
-
const
|
|
135
|
+
const allPointerDownEvents = ['pointerdown', 'mousedown', 'touchstart'];
|
|
136
|
+
/**
|
|
137
|
+
* @hidden
|
|
138
|
+
*/
|
|
139
|
+
const allPointerMoveEvents = ['pointermove', 'mousemove', 'touchmove'];
|
|
140
|
+
/**
|
|
141
|
+
* @hidden
|
|
142
|
+
*/
|
|
143
|
+
const allPointerUpEvents = ['pointerup', 'pointercancel', 'mouseup', 'contextmenu', 'touchend', 'touchcancel'];
|
|
123
144
|
|
|
124
|
-
const DEFAULT_ZINDEX = 10;
|
|
125
145
|
/**
|
|
126
146
|
* @hidden
|
|
127
147
|
*/
|
|
128
148
|
class HintComponent {
|
|
129
149
|
constructor(element) {
|
|
130
150
|
this.element = element;
|
|
131
|
-
this.hostClasses = true;
|
|
132
|
-
this.zIndex = DEFAULT_ZINDEX;
|
|
133
|
-
this.touchAction = 'none';
|
|
134
151
|
}
|
|
135
152
|
}
|
|
136
153
|
HintComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: HintComponent, deps: [{ token: i0.ElementRef }], target: i0.ɵɵFactoryTarget.Component });
|
|
137
|
-
HintComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.12", type: HintComponent, selector: "
|
|
138
|
-
<ng-container *ngTemplateOutlet="template; context: { $implicit: directive }">
|
|
154
|
+
HintComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.12", type: HintComponent, selector: "kendo-draghint", inputs: { template: "template", directive: "directive", targetIndex: "targetIndex", contextData: "contextData" }, ngImport: i0, template: `
|
|
155
|
+
<ng-container *ngTemplateOutlet="template; context: { $implicit: directive, index: targetIndex, data: contextData }">
|
|
139
156
|
</ng-container>
|
|
140
157
|
`, isInline: true, directives: [{ type: i1.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }] });
|
|
141
158
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: HintComponent, decorators: [{
|
|
142
159
|
type: Component,
|
|
143
160
|
args: [{
|
|
161
|
+
selector: 'kendo-draghint',
|
|
144
162
|
template: `
|
|
145
|
-
<ng-container *ngTemplateOutlet="template; context: { $implicit: directive }">
|
|
163
|
+
<ng-container *ngTemplateOutlet="template; context: { $implicit: directive, index: targetIndex, data: contextData }">
|
|
146
164
|
</ng-container>
|
|
147
165
|
`
|
|
148
166
|
}]
|
|
@@ -150,20 +168,156 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
|
|
|
150
168
|
type: Input
|
|
151
169
|
}], directive: [{
|
|
152
170
|
type: Input
|
|
153
|
-
}],
|
|
154
|
-
type:
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
type: HostBinding,
|
|
158
|
-
args: ['class.k-cursor-grab']
|
|
159
|
-
}], zIndex: [{
|
|
160
|
-
type: HostBinding,
|
|
161
|
-
args: ['style.zIndex']
|
|
162
|
-
}], touchAction: [{
|
|
163
|
-
type: HostBinding,
|
|
164
|
-
args: ['style.touch-action']
|
|
171
|
+
}], targetIndex: [{
|
|
172
|
+
type: Input
|
|
173
|
+
}], contextData: [{
|
|
174
|
+
type: Input
|
|
165
175
|
}] } });
|
|
166
176
|
|
|
177
|
+
/**
|
|
178
|
+
* Arguments for the press event of the DragTarget and DragTargetContainer.
|
|
179
|
+
*/
|
|
180
|
+
class DragTargetPressEvent {
|
|
181
|
+
/**
|
|
182
|
+
* @hidden
|
|
183
|
+
*/
|
|
184
|
+
constructor(args) {
|
|
185
|
+
Object.assign(this, args);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
189
|
+
* @hidden
|
|
190
|
+
*/
|
|
191
|
+
get normalizedEvent() {
|
|
192
|
+
return this.dragEvent;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
196
|
+
* @hidden
|
|
197
|
+
*/
|
|
198
|
+
get hostElement() {
|
|
199
|
+
return this.dragTarget;
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Arguments for the dragReady event of the DragTarget and DragTargetContainer.
|
|
205
|
+
*/
|
|
206
|
+
class DragTargetDragReadyEvent {
|
|
207
|
+
/**
|
|
208
|
+
* @hidden
|
|
209
|
+
*/
|
|
210
|
+
constructor(args) {
|
|
211
|
+
Object.assign(this, args);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Arguments for the dragStart event of the DragTarget and DragTargetContainer.
|
|
217
|
+
*/
|
|
218
|
+
class DragTargetDragStartEvent extends PreventableEvent {
|
|
219
|
+
/**
|
|
220
|
+
* @hidden
|
|
221
|
+
*/
|
|
222
|
+
constructor(args) {
|
|
223
|
+
super();
|
|
224
|
+
Object.assign(this, args);
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
228
|
+
* @hidden
|
|
229
|
+
*/
|
|
230
|
+
get normalizedEvent() {
|
|
231
|
+
return this.dragEvent;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
235
|
+
* @hidden
|
|
236
|
+
*/
|
|
237
|
+
get hostElement() {
|
|
238
|
+
return this.dragTarget;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Arguments for the dragEnd event of the DragTarget and DragTargetContainer.
|
|
244
|
+
*/
|
|
245
|
+
class DragTargetDragEndEvent {
|
|
246
|
+
/**
|
|
247
|
+
* @hidden
|
|
248
|
+
*/
|
|
249
|
+
constructor(args) {
|
|
250
|
+
Object.assign(this, args);
|
|
251
|
+
}
|
|
252
|
+
/**
|
|
253
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
254
|
+
* @hidden
|
|
255
|
+
*/
|
|
256
|
+
get normalizedEvent() {
|
|
257
|
+
return this.dragEvent;
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
261
|
+
* @hidden
|
|
262
|
+
*/
|
|
263
|
+
get hostElement() {
|
|
264
|
+
return this.dragTarget;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
/**
|
|
269
|
+
* Arguments for the drag event of the DragTarget and DragTargetContainer.
|
|
270
|
+
*/
|
|
271
|
+
class DragTargetDragEvent extends PreventableEvent {
|
|
272
|
+
/**
|
|
273
|
+
* @hidden
|
|
274
|
+
*/
|
|
275
|
+
constructor(args) {
|
|
276
|
+
super();
|
|
277
|
+
Object.assign(this, args);
|
|
278
|
+
}
|
|
279
|
+
/**
|
|
280
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
281
|
+
* @hidden
|
|
282
|
+
*/
|
|
283
|
+
get normalizedEvent() {
|
|
284
|
+
return this.dragEvent;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
288
|
+
* @hidden
|
|
289
|
+
*/
|
|
290
|
+
get hostElement() {
|
|
291
|
+
return this.dragTarget;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Arguments for the release event of the DragTarget and DragTargetContainer.
|
|
297
|
+
*/
|
|
298
|
+
class DragTargetReleaseEvent {
|
|
299
|
+
/**
|
|
300
|
+
* @hidden
|
|
301
|
+
*/
|
|
302
|
+
constructor(args) {
|
|
303
|
+
Object.assign(this, args);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
307
|
+
* @hidden
|
|
308
|
+
*/
|
|
309
|
+
get normalizedEvent() {
|
|
310
|
+
return this.dragEvent;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Left for backward compatibility for the DragTarget deprecated events.
|
|
314
|
+
* @hidden
|
|
315
|
+
*/
|
|
316
|
+
get hostElement() {
|
|
317
|
+
return this.dragTarget;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
|
|
167
321
|
/**
|
|
168
322
|
* @hidden
|
|
169
323
|
*/
|
|
@@ -186,6 +340,8 @@ class DragStateService {
|
|
|
186
340
|
this.offset = { x: 0, y: 0 };
|
|
187
341
|
this.pageOffset = { x: 0, y: 0 };
|
|
188
342
|
this.velocity = { x: 0, y: 0 };
|
|
343
|
+
this.dragIndex = null;
|
|
344
|
+
this.dropIndex = null;
|
|
189
345
|
this.callbacks = {};
|
|
190
346
|
this.scrollInterval = null;
|
|
191
347
|
this.setCallbacks();
|
|
@@ -284,21 +440,26 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
|
|
|
284
440
|
}]
|
|
285
441
|
}], ctorParameters: function () { return []; } });
|
|
286
442
|
|
|
287
|
-
let isDragStartPrevented = false;
|
|
288
|
-
let isDragPrevented = false;
|
|
443
|
+
let isDragStartPrevented$1 = false;
|
|
444
|
+
let isDragPrevented$1 = false;
|
|
289
445
|
/**
|
|
290
446
|
* Represents the Kendo UI DragTarget directive for Angular.
|
|
291
447
|
*/
|
|
292
448
|
class DragTargetDirective {
|
|
293
|
-
constructor(element, renderer, ngZone, service, viewContainer
|
|
449
|
+
constructor(element, renderer, ngZone, service, viewContainer) {
|
|
294
450
|
this.element = element;
|
|
295
451
|
this.renderer = renderer;
|
|
296
452
|
this.ngZone = ngZone;
|
|
297
453
|
this.service = service;
|
|
298
454
|
this.viewContainer = viewContainer;
|
|
299
|
-
this.resolver = resolver;
|
|
300
455
|
/**
|
|
301
|
-
*
|
|
456
|
+
* Defines whether a hint will be used for dragging. By default, the hint is a copy of the drag target. ([see example]({% slug drag_hint %})).
|
|
457
|
+
*
|
|
458
|
+
* @default false
|
|
459
|
+
*/
|
|
460
|
+
this.hint = false;
|
|
461
|
+
/**
|
|
462
|
+
* The number of pixels the pointer moves in any direction before the dragging starts ([see example]({% slug minimum_distance %})). Applicable when `manualDrag` is set to `false`.
|
|
302
463
|
*
|
|
303
464
|
* @default 0
|
|
304
465
|
*/
|
|
@@ -315,18 +476,22 @@ class DragTargetDirective {
|
|
|
315
476
|
* @default 0
|
|
316
477
|
*/
|
|
317
478
|
this.dragDelay = 0;
|
|
479
|
+
/**
|
|
480
|
+
* Specifies whether the default dragging behavior will be performed or the developer will manually handle the drag action.
|
|
481
|
+
*
|
|
482
|
+
* @default 'auto'
|
|
483
|
+
*/
|
|
484
|
+
this.mode = 'auto';
|
|
318
485
|
/**
|
|
319
486
|
* Fires when the user presses the DragTarget element.
|
|
320
487
|
*/
|
|
321
488
|
this.press = new EventEmitter();
|
|
322
489
|
/**
|
|
323
490
|
* Fires when the dragging of the DragTarget element begins.
|
|
324
|
-
* This event is preventable.
|
|
325
491
|
*/
|
|
326
492
|
this.dragStart = new EventEmitter();
|
|
327
493
|
/**
|
|
328
494
|
* Fires while the user drags the DragTarget element.
|
|
329
|
-
* This event is preventable.
|
|
330
495
|
*/
|
|
331
496
|
this.drag = new EventEmitter();
|
|
332
497
|
/**
|
|
@@ -341,32 +506,42 @@ class DragTargetDirective {
|
|
|
341
506
|
* Fires when the dragging of the DragTarget ends and the element is released.
|
|
342
507
|
*/
|
|
343
508
|
this.dragEnd = new EventEmitter();
|
|
344
|
-
this.touchAction = 'none';
|
|
345
509
|
this.dragTarget = null;
|
|
346
510
|
this.domSubscriptions = [];
|
|
347
|
-
this.
|
|
348
|
-
this.initialPosition = { x: 0, y: 0 };
|
|
511
|
+
this.hintComponent = null;
|
|
349
512
|
this.dragStarted = false;
|
|
350
513
|
this.pressed = false;
|
|
351
514
|
this.dragTimeout = null;
|
|
515
|
+
this.initialPosition = { x: 0, y: 0 };
|
|
352
516
|
this.position = { x: 0, y: 0 };
|
|
517
|
+
this.scrollableParent = null;
|
|
518
|
+
this.defaultHint = null;
|
|
519
|
+
this._dragData = () => null;
|
|
353
520
|
validatePackage(packageMetadata);
|
|
354
521
|
}
|
|
355
522
|
/**
|
|
356
|
-
*
|
|
523
|
+
* Defines a callback function used for attaching custom data to the dragTarget.
|
|
524
|
+
* The data will be available in the events of the respective [`DropTarget`]({% slug api_utils_droptargetdirective %}) or [`DropTargetContainer`]({% slug api_utils_droptargetcontainerdirective %}) directives.
|
|
525
|
+
* The current DragTarget HTML element and its `dragTargetId` will be available as arguments.
|
|
357
526
|
*/
|
|
527
|
+
set dragData(fn) {
|
|
528
|
+
if (isDevMode && typeof fn !== 'function') {
|
|
529
|
+
throw new Error(`dragData must be a function, but received ${JSON.stringify(fn)}.`);
|
|
530
|
+
}
|
|
531
|
+
this._dragData = fn;
|
|
532
|
+
}
|
|
533
|
+
get dragData() {
|
|
534
|
+
return this._dragData;
|
|
535
|
+
}
|
|
536
|
+
get hintTemplate() {
|
|
537
|
+
return isPresent(this.hint) && typeof this.hint === 'object' ? this.hint.hintTemplate : null;
|
|
538
|
+
}
|
|
358
539
|
get nativeElement() {
|
|
359
540
|
return this.element.nativeElement;
|
|
360
541
|
}
|
|
361
|
-
/**
|
|
362
|
-
* @hidden
|
|
363
|
-
*/
|
|
364
542
|
get hintElem() {
|
|
365
|
-
return this.
|
|
543
|
+
return this.hintTemplate && isPresent(this.hintComponent) ? this.hintComponent.instance.element.nativeElement : this.defaultHint;
|
|
366
544
|
}
|
|
367
|
-
/**
|
|
368
|
-
* @hidden
|
|
369
|
-
*/
|
|
370
545
|
onPointerDown(event) {
|
|
371
546
|
if (this.dragHandles.length && !this.isDragHandle(event.target)) {
|
|
372
547
|
return;
|
|
@@ -377,127 +552,88 @@ class DragTargetDirective {
|
|
|
377
552
|
this.service.autoScroll = typeof this.autoScroll === 'object' ? this.autoScroll.enabled !== false : this.autoScroll;
|
|
378
553
|
this.service.scrollableParent = this.getAutoScrollContainer();
|
|
379
554
|
this.service.autoScrollDirection = typeof this.autoScroll === 'object' ? this.autoScroll.direction : { horizontal: true, vertical: true };
|
|
380
|
-
this.
|
|
381
|
-
this.attachDomHandlers();
|
|
382
|
-
});
|
|
555
|
+
this.attachDomHandlers();
|
|
383
556
|
}
|
|
384
|
-
/**
|
|
385
|
-
* @hidden
|
|
386
|
-
*/
|
|
387
557
|
onPointerMove(event) {
|
|
388
558
|
event.preventDefault();
|
|
389
559
|
const action = getAction(event, this.dragTarget);
|
|
390
560
|
this.service.handleDragAndDrop(action);
|
|
391
561
|
}
|
|
392
|
-
/**
|
|
393
|
-
* @hidden
|
|
394
|
-
*/
|
|
395
562
|
onPointerUp(event) {
|
|
396
563
|
event.preventDefault();
|
|
397
564
|
const action = getAction(event, this.dragTarget);
|
|
398
565
|
this.service.handleDragAndDrop(action);
|
|
399
|
-
this.
|
|
400
|
-
this.attachDomHandlers();
|
|
401
|
-
});
|
|
566
|
+
this.attachDomHandlers();
|
|
402
567
|
}
|
|
403
568
|
ngOnInit() {
|
|
404
|
-
this.
|
|
569
|
+
this.initializeDragTarget();
|
|
405
570
|
}
|
|
406
571
|
ngAfterContentInit() {
|
|
407
572
|
if (isPresent(this.element) || isPresent(this.dragTarget)) {
|
|
408
|
-
this.
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
}
|
|
413
|
-
});
|
|
573
|
+
this.attachDomHandlers();
|
|
574
|
+
if (!this.dragHandles.length) {
|
|
575
|
+
this.renderer.addClass(this.nativeElement, 'k-cursor-pointer');
|
|
576
|
+
}
|
|
414
577
|
}
|
|
415
578
|
this.service.dragTargets.push(this.dragTarget);
|
|
416
579
|
}
|
|
417
580
|
ngOnDestroy() {
|
|
418
581
|
this.domSubscriptions.forEach(subscription => subscription());
|
|
419
582
|
}
|
|
420
|
-
/**
|
|
421
|
-
* @hidden
|
|
422
|
-
*/
|
|
423
583
|
handlePress(event) {
|
|
424
584
|
if (this.dragDelay > 0) {
|
|
425
|
-
this.dragTimeout = setTimeout(() => {
|
|
585
|
+
this.dragTimeout = window.setTimeout(() => {
|
|
426
586
|
this.pressed = true;
|
|
427
|
-
this.
|
|
428
|
-
this.dragReady.emit();
|
|
429
|
-
});
|
|
587
|
+
this.emitZoneAwareEvent('dragReady', event);
|
|
430
588
|
}, this.dragDelay);
|
|
431
589
|
}
|
|
432
590
|
else {
|
|
433
591
|
this.pressed = true;
|
|
434
592
|
}
|
|
435
|
-
this.
|
|
436
|
-
|
|
437
|
-
this.press.emit(eventArgs);
|
|
438
|
-
});
|
|
593
|
+
this.scrollableParent = this.dragTarget.element ? getScrollableParent(this.dragTarget.element) : null;
|
|
594
|
+
this.emitZoneAwareEvent('press', event);
|
|
439
595
|
}
|
|
440
|
-
/**
|
|
441
|
-
* @hidden
|
|
442
|
-
*/
|
|
443
596
|
handleDragStart(event) {
|
|
444
597
|
if (!this.pressed) {
|
|
445
598
|
if (this.dragTimeout) {
|
|
446
|
-
clearTimeout(this.dragTimeout);
|
|
599
|
+
window.clearTimeout(this.dragTimeout);
|
|
447
600
|
this.dragTimeout = null;
|
|
448
601
|
}
|
|
449
602
|
return;
|
|
450
603
|
}
|
|
451
|
-
this.
|
|
452
|
-
|
|
453
|
-
});
|
|
454
|
-
if (isDragStartPrevented) {
|
|
604
|
+
isDragStartPrevented$1 = this.emitZoneAwareEvent('dragStart', event).isDefaultPrevented();
|
|
605
|
+
if (isDragStartPrevented$1) {
|
|
455
606
|
return;
|
|
456
607
|
}
|
|
457
|
-
if (
|
|
608
|
+
if (this.hint) {
|
|
458
609
|
this.createHint();
|
|
459
|
-
if (
|
|
610
|
+
if (this.mode === 'auto') {
|
|
460
611
|
this.renderer.setStyle(this.nativeElement, 'opacity', '0.7');
|
|
461
612
|
}
|
|
613
|
+
this.initialPosition = { x: event.offsetX, y: event.offsetY };
|
|
614
|
+
}
|
|
615
|
+
else {
|
|
616
|
+
this.initialPosition = { x: event.clientX - this.position.x, y: event.clientY - this.position.y };
|
|
462
617
|
}
|
|
463
618
|
this.dragStarted = this.threshold === 0;
|
|
464
619
|
this.service.dragTarget = this.dragTarget;
|
|
465
620
|
this.service.dragTargetDirective = this;
|
|
466
|
-
this.
|
|
621
|
+
this.service.dragData = this.dragData(this.dragTarget.element, this.dragTargetIdResult);
|
|
467
622
|
}
|
|
468
623
|
handleDrag(event) {
|
|
469
|
-
if (!this.pressed || isDragStartPrevented) {
|
|
624
|
+
if (!this.pressed || isDragStartPrevented$1) {
|
|
470
625
|
return;
|
|
471
626
|
}
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
this.ngZone.run(() => {
|
|
475
|
-
isDragPrevented = this.emitEvent('drag', eventArgsProps).isDefaultPrevented();
|
|
476
|
-
});
|
|
477
|
-
if (isDragPrevented) {
|
|
627
|
+
isDragPrevented$1 = this.emitZoneAwareEvent('drag', event).isDefaultPrevented();
|
|
628
|
+
if (isDragPrevented$1) {
|
|
478
629
|
return;
|
|
479
630
|
}
|
|
480
|
-
if (this.
|
|
481
|
-
this.
|
|
482
|
-
}
|
|
483
|
-
else if (this.restrictByAxis === 'vertical') {
|
|
484
|
-
this.position = { x: 0, y: event.clientY - this.initialPosition.y + event.scrollY };
|
|
631
|
+
if (this.mode === 'auto') {
|
|
632
|
+
this.performDrag(event);
|
|
485
633
|
}
|
|
486
634
|
else {
|
|
487
|
-
this.position = { x: event.clientX - this.initialPosition.x + event.scrollX, y: event.clientY - this.initialPosition.y + event.scrollY };
|
|
488
|
-
}
|
|
489
|
-
const thresholdNotReached = Math.abs(this.position.x) < this.threshold && Math.abs(this.position.y) < this.threshold;
|
|
490
|
-
if (!this.dragStarted && thresholdNotReached) {
|
|
491
|
-
return;
|
|
492
|
-
}
|
|
493
|
-
if (!this.dragStarted && this.threshold > 0) {
|
|
494
635
|
this.dragStarted = true;
|
|
495
636
|
}
|
|
496
|
-
const transform = `translate(${this.position.x}px, ${this.position.y}px)`;
|
|
497
|
-
setElementStyles(this.renderer, elem, {
|
|
498
|
-
transform: transform,
|
|
499
|
-
transition: 'none'
|
|
500
|
-
});
|
|
501
637
|
}
|
|
502
638
|
handleRelease(event) {
|
|
503
639
|
if (this.dragTimeout) {
|
|
@@ -505,45 +641,36 @@ class DragTargetDirective {
|
|
|
505
641
|
this.dragTimeout = null;
|
|
506
642
|
this.pressed = false;
|
|
507
643
|
}
|
|
508
|
-
this.
|
|
509
|
-
this.service.dragTargetDirective = null;
|
|
510
|
-
this.ngZone.run(() => {
|
|
511
|
-
const eventArgs = new DragTargetPressEvent({ normalizedEvent: event, hostElement: this.nativeElement });
|
|
512
|
-
this.release.emit(eventArgs);
|
|
513
|
-
});
|
|
644
|
+
this.emitZoneAwareEvent('release', event);
|
|
514
645
|
}
|
|
515
646
|
handleDragEnd(event) {
|
|
516
647
|
var _a, _b;
|
|
517
|
-
if (this.
|
|
518
|
-
|
|
519
|
-
this.
|
|
520
|
-
this.
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
transition: dragTargetTransition
|
|
528
|
-
});
|
|
529
|
-
this.position = { x: 0, y: 0 };
|
|
648
|
+
if (this.mode === 'auto') {
|
|
649
|
+
const isDroppedOverParentTarget = isPresent(this.service.dropTarget) && !contains((_a = this.service.dropTarget) === null || _a === void 0 ? void 0 : _a.element, (_b = this.service.dragTarget) === null || _b === void 0 ? void 0 : _b.element, true);
|
|
650
|
+
const elem = this.hint ? this.hintElem : this.nativeElement;
|
|
651
|
+
if (isDroppedOverParentTarget || this.service.dropTargets.length > 0 && isPresent(elem)) {
|
|
652
|
+
this.renderer.removeStyle(elem, 'transform');
|
|
653
|
+
setElementStyles(this.renderer, elem, {
|
|
654
|
+
transition: dragTargetTransition
|
|
655
|
+
});
|
|
656
|
+
this.position = { x: 0, y: 0 };
|
|
657
|
+
}
|
|
530
658
|
}
|
|
531
|
-
if (isPresent(this.
|
|
532
|
-
this.renderer.removeStyle(this.nativeElement, 'opacity');
|
|
659
|
+
if (this.hint && isPresent(this.hintElem)) {
|
|
533
660
|
this.destroyHint();
|
|
661
|
+
if (this.mode === 'auto') {
|
|
662
|
+
this.renderer.removeStyle(this.nativeElement, 'opacity');
|
|
663
|
+
}
|
|
534
664
|
}
|
|
535
665
|
this.service.dragTarget = null;
|
|
536
666
|
this.service.dragTargetDirective = null;
|
|
537
|
-
if (!this.dragStarted || isDragStartPrevented || isDragPrevented) {
|
|
667
|
+
if (!this.dragStarted || isDragStartPrevented$1 || isDragPrevented$1) {
|
|
538
668
|
return;
|
|
539
669
|
}
|
|
540
|
-
this.
|
|
541
|
-
const eventArgs = new DragTargetDragEndEvent({ normalizedEvent: event, hostElement: this.nativeElement });
|
|
542
|
-
this.dragEnd.emit(eventArgs);
|
|
543
|
-
});
|
|
670
|
+
this.emitZoneAwareEvent('dragEnd', event);
|
|
544
671
|
this.dragStarted = false;
|
|
545
672
|
}
|
|
546
|
-
|
|
673
|
+
initializeDragTarget() {
|
|
547
674
|
this.dragTarget = {
|
|
548
675
|
element: this.nativeElement,
|
|
549
676
|
hint: null,
|
|
@@ -555,43 +682,44 @@ class DragTargetDirective {
|
|
|
555
682
|
};
|
|
556
683
|
}
|
|
557
684
|
attachDomHandlers() {
|
|
558
|
-
|
|
559
|
-
this.domSubscriptions.
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
685
|
+
this.ngZone.runOutsideAngular(() => {
|
|
686
|
+
if (this.domSubscriptions.length > 0) {
|
|
687
|
+
this.domSubscriptions.forEach(subscription => subscription());
|
|
688
|
+
}
|
|
689
|
+
if (!(isDocumentAvailable() && isPresent(this.element))) {
|
|
690
|
+
return;
|
|
691
|
+
}
|
|
692
|
+
if (this.service.pressed) {
|
|
693
|
+
this.onPointerMove = this.onPointerMove.bind(this);
|
|
694
|
+
this.onPointerUp = this.onPointerUp.bind(this);
|
|
695
|
+
this.domSubscriptions = [
|
|
696
|
+
this.renderer.listen(document, 'pointermove', this.onPointerMove),
|
|
697
|
+
this.renderer.listen(document, 'mousemove', this.onPointerMove),
|
|
698
|
+
this.renderer.listen(document, 'touchmove', this.onPointerMove),
|
|
699
|
+
this.renderer.listen(document, 'pointerup', this.onPointerUp),
|
|
700
|
+
this.renderer.listen(document, 'pointercancel', this.onPointerUp),
|
|
701
|
+
this.renderer.listen(document, 'mouseup', this.onPointerUp),
|
|
702
|
+
this.renderer.listen(document, 'contextmenu', this.onPointerUp),
|
|
703
|
+
this.renderer.listen(document, 'touchend', this.onPointerUp),
|
|
704
|
+
this.renderer.listen(document, 'touchcancel', this.onPointerUp)
|
|
705
|
+
];
|
|
706
|
+
if (isPresent(this.scrollableParent)) {
|
|
707
|
+
if (this.scrollableParent === document.getElementsByTagName('html')[0]) {
|
|
708
|
+
this.scrollableParent = window;
|
|
709
|
+
}
|
|
710
|
+
this.domSubscriptions.push(this.renderer.listen(this.scrollableParent, 'scroll', this.onPointerMove));
|
|
582
711
|
}
|
|
583
|
-
this.domSubscriptions.push(this.renderer.listen(scrollable, 'scroll', this.onPointerMove));
|
|
584
712
|
}
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
}
|
|
713
|
+
else {
|
|
714
|
+
this.onPointerDown = this.onPointerDown.bind(this);
|
|
715
|
+
const element = this.nativeElement;
|
|
716
|
+
this.domSubscriptions = [
|
|
717
|
+
this.renderer.listen(element, 'pointerdown', this.onPointerDown),
|
|
718
|
+
this.renderer.listen(element, 'mousedown', this.onPointerDown),
|
|
719
|
+
this.renderer.listen(element, 'touchstart', this.onPointerDown)
|
|
720
|
+
];
|
|
721
|
+
}
|
|
722
|
+
});
|
|
595
723
|
}
|
|
596
724
|
isDragHandle(el) {
|
|
597
725
|
return this.dragHandles.toArray().some(dh => contains(dh.element.nativeElement, el, true));
|
|
@@ -603,55 +731,182 @@ class DragTargetDirective {
|
|
|
603
731
|
this.autoScroll.boundaryElementRef.nativeElement : null;
|
|
604
732
|
}
|
|
605
733
|
createHint() {
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
this.hint.
|
|
610
|
-
|
|
611
|
-
|
|
734
|
+
if (!(isDocumentAvailable() && isPresent(this.element))) {
|
|
735
|
+
return;
|
|
736
|
+
}
|
|
737
|
+
if (isPresent(this.hint) && typeof this.hint === 'object') {
|
|
738
|
+
if (isPresent(this.hint.hintTemplate)) {
|
|
739
|
+
this.createCustomHint();
|
|
740
|
+
}
|
|
741
|
+
else {
|
|
742
|
+
this.createDefaultHint();
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
else {
|
|
746
|
+
this.createDefaultHint();
|
|
747
|
+
}
|
|
748
|
+
this.dragTarget.hint = this.hintElem;
|
|
749
|
+
if (typeof this.hint === 'object' && isPresent(this.hint.appendTo)) {
|
|
750
|
+
this.hint.appendTo.element.nativeElement.appendChild(this.hintElem);
|
|
751
|
+
}
|
|
752
|
+
else {
|
|
753
|
+
document.body.appendChild(this.hintElem);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
createDefaultHint() {
|
|
757
|
+
this.defaultHint = this.nativeElement.cloneNode(true);
|
|
758
|
+
if (typeof this.hint === 'object') {
|
|
759
|
+
if (isPresent(this.hint.hintClass)) {
|
|
760
|
+
const hintClasses = parseCSSClassNames(this.hint.hintClass);
|
|
761
|
+
hintClasses.forEach(className => this.renderer.addClass(this.defaultHint, className));
|
|
762
|
+
}
|
|
763
|
+
}
|
|
764
|
+
}
|
|
765
|
+
createCustomHint() {
|
|
766
|
+
if (isPresent(this.hint.appendTo)) {
|
|
767
|
+
this.hintComponent = this.hint.appendTo.createComponent(HintComponent);
|
|
768
|
+
}
|
|
769
|
+
else {
|
|
770
|
+
this.hintComponent = this.viewContainer.createComponent(HintComponent);
|
|
771
|
+
}
|
|
772
|
+
this.hintComponent.instance.template = this.hintTemplate;
|
|
773
|
+
this.hintComponent.instance.directive = this;
|
|
774
|
+
this.hintComponent.changeDetectorRef.detectChanges();
|
|
612
775
|
}
|
|
613
776
|
destroyHint() {
|
|
614
|
-
this.
|
|
615
|
-
|
|
616
|
-
|
|
777
|
+
if (isPresent(this.hintTemplate)) {
|
|
778
|
+
this.hintComponent.destroy();
|
|
779
|
+
this.hintComponent.changeDetectorRef.detectChanges();
|
|
780
|
+
this.hintComponent = null;
|
|
781
|
+
}
|
|
782
|
+
else {
|
|
783
|
+
if (typeof this.hint === 'object' && isPresent(this.hint.appendTo)) {
|
|
784
|
+
this.hint.appendTo.element.nativeElement.removeChild(this.defaultHint);
|
|
785
|
+
}
|
|
786
|
+
else {
|
|
787
|
+
document.body.removeChild(this.defaultHint);
|
|
788
|
+
}
|
|
789
|
+
this.defaultHint = null;
|
|
790
|
+
}
|
|
617
791
|
this.dragTarget.hint = null;
|
|
618
792
|
}
|
|
619
|
-
|
|
793
|
+
emitZoneAwareEvent(event, normalizedEvent) {
|
|
794
|
+
const eventProps = {
|
|
795
|
+
dragTarget: this.nativeElement,
|
|
796
|
+
dragEvent: normalizedEvent
|
|
797
|
+
};
|
|
798
|
+
if (this.hint && isPresent(this.hintElem)) {
|
|
799
|
+
eventProps.hintElement = this.hintElem;
|
|
800
|
+
}
|
|
801
|
+
if (this.dragTargetId && this.dragTargetId !== '') {
|
|
802
|
+
eventProps.dragTargetId = this.dragTargetIdResult;
|
|
803
|
+
}
|
|
620
804
|
let eventArgs;
|
|
621
805
|
switch (event) {
|
|
806
|
+
case 'dragReady':
|
|
807
|
+
eventArgs = new DragTargetDragReadyEvent(eventProps);
|
|
808
|
+
break;
|
|
809
|
+
case 'press':
|
|
810
|
+
eventArgs = new DragTargetPressEvent(eventProps);
|
|
811
|
+
break;
|
|
622
812
|
case 'dragStart':
|
|
623
|
-
eventArgs = new DragTargetDragStartEvent(
|
|
813
|
+
eventArgs = new DragTargetDragStartEvent(eventProps);
|
|
624
814
|
break;
|
|
625
815
|
case 'drag':
|
|
626
|
-
eventArgs = new DragTargetDragEvent(
|
|
816
|
+
eventArgs = new DragTargetDragEvent(eventProps);
|
|
817
|
+
break;
|
|
818
|
+
case 'release':
|
|
819
|
+
eventArgs = new DragTargetReleaseEvent(eventProps);
|
|
820
|
+
break;
|
|
821
|
+
case 'dragEnd':
|
|
822
|
+
eventArgs = new DragTargetDragEndEvent(eventProps);
|
|
627
823
|
break;
|
|
628
824
|
default:
|
|
629
825
|
break;
|
|
630
826
|
}
|
|
631
|
-
this
|
|
827
|
+
this.ngZone.run(() => {
|
|
828
|
+
this[event].emit(eventArgs);
|
|
829
|
+
});
|
|
632
830
|
return eventArgs;
|
|
633
831
|
}
|
|
832
|
+
get dragTargetIdResult() {
|
|
833
|
+
if (this.dragTargetId && this.dragTargetId !== '') {
|
|
834
|
+
return typeof this.dragTargetId === 'string' ? this.dragTargetId : this.dragTargetId(this.dragTarget.element);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
performDrag(event) {
|
|
838
|
+
const elem = this.hint ? this.hintElem : this.nativeElement;
|
|
839
|
+
this.position = this.calculatePosition(elem, event);
|
|
840
|
+
const thresholdNotReached = Math.abs(this.position.x) < this.threshold && Math.abs(this.position.y) < this.threshold;
|
|
841
|
+
if (!this.dragStarted && thresholdNotReached) {
|
|
842
|
+
return;
|
|
843
|
+
}
|
|
844
|
+
if (!this.dragStarted && this.threshold > 0) {
|
|
845
|
+
this.dragStarted = true;
|
|
846
|
+
}
|
|
847
|
+
const styles = this.getStylesPerElement(elem);
|
|
848
|
+
setElementStyles(this.renderer, elem, styles);
|
|
849
|
+
}
|
|
850
|
+
calculatePosition(element, event) {
|
|
851
|
+
let position = null;
|
|
852
|
+
if (element === this.hintElem) {
|
|
853
|
+
position = { x: event.clientX, y: event.clientY };
|
|
854
|
+
}
|
|
855
|
+
else {
|
|
856
|
+
position = { x: event.clientX - this.initialPosition.x + event.scrollX, y: event.clientY - this.initialPosition.y + event.scrollY };
|
|
857
|
+
}
|
|
858
|
+
if (this.restrictByAxis === 'horizontal') {
|
|
859
|
+
position.y = 0;
|
|
860
|
+
}
|
|
861
|
+
else if (this.restrictByAxis === 'vertical') {
|
|
862
|
+
position.x = 0;
|
|
863
|
+
}
|
|
864
|
+
return position;
|
|
865
|
+
}
|
|
866
|
+
getStylesPerElement(element) {
|
|
867
|
+
if (element === this.hintElem) {
|
|
868
|
+
const hintCoordinates = { x: this.position.x - this.initialPosition.x, y: this.position.y - this.initialPosition.y };
|
|
869
|
+
return {
|
|
870
|
+
top: `${hintCoordinates.y}px`,
|
|
871
|
+
left: `${hintCoordinates.x}px`,
|
|
872
|
+
transition: 'none',
|
|
873
|
+
position: 'absolute',
|
|
874
|
+
zIndex: 1999
|
|
875
|
+
};
|
|
876
|
+
}
|
|
877
|
+
else {
|
|
878
|
+
const transform = `translate(${this.position.x}px, ${this.position.y}px)`;
|
|
879
|
+
return {
|
|
880
|
+
transform: transform,
|
|
881
|
+
transition: 'none'
|
|
882
|
+
};
|
|
883
|
+
}
|
|
884
|
+
}
|
|
634
885
|
}
|
|
635
|
-
DragTargetDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragTargetDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.NgZone }, { token: DragStateService }, { token: i0.ViewContainerRef }
|
|
636
|
-
DragTargetDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: DragTargetDirective, selector: "[kendoDragTarget]", inputs: {
|
|
886
|
+
DragTargetDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragTargetDirective, deps: [{ token: i0.ElementRef }, { token: i0.Renderer2 }, { token: i0.NgZone }, { token: DragStateService }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
887
|
+
DragTargetDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: DragTargetDirective, selector: "[kendoDragTarget]", inputs: { hint: "hint", threshold: "threshold", autoScroll: "autoScroll", dragTargetId: "dragTargetId", dragDelay: "dragDelay", restrictByAxis: "restrictByAxis", mode: "mode", dragData: "dragData" }, outputs: { press: "press", dragStart: "dragStart", drag: "drag", dragReady: "dragReady", release: "release", dragEnd: "dragEnd" }, queries: [{ propertyName: "dragHandles", predicate: DragHandleDirective }], exportAs: ["kendoDragTarget"], ngImport: i0 });
|
|
637
888
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragTargetDirective, decorators: [{
|
|
638
889
|
type: Directive,
|
|
639
890
|
args: [{
|
|
640
891
|
selector: '[kendoDragTarget]',
|
|
641
892
|
exportAs: 'kendoDragTarget'
|
|
642
893
|
}]
|
|
643
|
-
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }, { type: DragStateService }, { type: i0.ViewContainerRef }
|
|
894
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }, { type: DragStateService }, { type: i0.ViewContainerRef }]; }, propDecorators: { hint: [{
|
|
644
895
|
type: Input
|
|
645
896
|
}], threshold: [{
|
|
646
897
|
type: Input
|
|
647
898
|
}], autoScroll: [{
|
|
648
899
|
type: Input
|
|
649
|
-
}],
|
|
900
|
+
}], dragTargetId: [{
|
|
650
901
|
type: Input
|
|
651
902
|
}], dragDelay: [{
|
|
652
903
|
type: Input
|
|
653
904
|
}], restrictByAxis: [{
|
|
654
905
|
type: Input
|
|
906
|
+
}], mode: [{
|
|
907
|
+
type: Input
|
|
908
|
+
}], dragData: [{
|
|
909
|
+
type: Input
|
|
655
910
|
}], press: [{
|
|
656
911
|
type: Output
|
|
657
912
|
}], dragStart: [{
|
|
@@ -664,59 +919,34 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
|
|
|
664
919
|
type: Output
|
|
665
920
|
}], dragEnd: [{
|
|
666
921
|
type: Output
|
|
667
|
-
}], touchAction: [{
|
|
668
|
-
type: HostBinding,
|
|
669
|
-
args: ['style.touch-action']
|
|
670
922
|
}], dragHandles: [{
|
|
671
923
|
type: ContentChildren,
|
|
672
924
|
args: [DragHandleDirective]
|
|
673
925
|
}] } });
|
|
674
926
|
|
|
675
927
|
/**
|
|
676
|
-
* Arguments for the
|
|
677
|
-
*/
|
|
678
|
-
class DropTargetDragEnterEvent {
|
|
679
|
-
/**
|
|
680
|
-
* @hidden
|
|
681
|
-
*/
|
|
682
|
-
constructor(args) {
|
|
683
|
-
Object.assign(this, args);
|
|
684
|
-
}
|
|
685
|
-
}
|
|
686
|
-
|
|
687
|
-
/**
|
|
688
|
-
* Arguments for the dragOver event of the DropTarget.
|
|
928
|
+
* Arguments for the drag events of the DropTarget and DropTargetContainer directives.
|
|
689
929
|
*/
|
|
690
|
-
class
|
|
930
|
+
class DropTargetEvent {
|
|
691
931
|
/**
|
|
692
932
|
* @hidden
|
|
693
933
|
*/
|
|
694
934
|
constructor(args) {
|
|
695
935
|
Object.assign(this, args);
|
|
696
936
|
}
|
|
697
|
-
}
|
|
698
|
-
|
|
699
|
-
/**
|
|
700
|
-
* Arguments for the dragLeave event of the DropTarget.
|
|
701
|
-
*/
|
|
702
|
-
class DropTargetDragLeaveEvent {
|
|
703
937
|
/**
|
|
938
|
+
* Left for backward compatibility for the DropTarget deprecated events.
|
|
704
939
|
* @hidden
|
|
705
940
|
*/
|
|
706
|
-
|
|
707
|
-
|
|
941
|
+
get normalizedEvent() {
|
|
942
|
+
return this.dragEvent;
|
|
708
943
|
}
|
|
709
|
-
}
|
|
710
|
-
|
|
711
|
-
/**
|
|
712
|
-
* Arguments for the drop event of the DropTarget.
|
|
713
|
-
*/
|
|
714
|
-
class DropTargetDropEvent {
|
|
715
944
|
/**
|
|
945
|
+
* Left for backward compatibility for the DropTarget deprecated events.
|
|
716
946
|
* @hidden
|
|
717
947
|
*/
|
|
718
|
-
|
|
719
|
-
|
|
948
|
+
get hostElement() {
|
|
949
|
+
return this.dropTarget;
|
|
720
950
|
}
|
|
721
951
|
}
|
|
722
952
|
|
|
@@ -730,22 +960,18 @@ class DropTargetDirective {
|
|
|
730
960
|
this.ngZone = ngZone;
|
|
731
961
|
/**
|
|
732
962
|
* Fires when a DragTarget element enters the DropTarget.
|
|
733
|
-
* This event is preventable. Preventing it allows full logic customization.
|
|
734
963
|
*/
|
|
735
964
|
this.dragEnter = new EventEmitter();
|
|
736
965
|
/**
|
|
737
966
|
* Fires when a DragTarget element is being dragged over the DropTarget.
|
|
738
|
-
* This event is preventable. Preventing it allows full logic customization.
|
|
739
967
|
*/
|
|
740
968
|
this.dragOver = new EventEmitter();
|
|
741
969
|
/**
|
|
742
970
|
* Fires when a DragTarget element leaves the DropTarget.
|
|
743
|
-
* This event is preventable. Preventing it allows full logic customization.
|
|
744
971
|
*/
|
|
745
972
|
this.dragLeave = new EventEmitter();
|
|
746
973
|
/**
|
|
747
974
|
* Fires when a DragTarget element is dropped over the DropTarget.
|
|
748
|
-
* This event is preventable. Preventing it allows full logic customization.
|
|
749
975
|
*/
|
|
750
976
|
this.drop = new EventEmitter();
|
|
751
977
|
validatePackage(packageMetadata);
|
|
@@ -761,29 +987,10 @@ class DropTargetDirective {
|
|
|
761
987
|
if (!this.service.dragTarget) {
|
|
762
988
|
return;
|
|
763
989
|
}
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
allowed = this.allowedDragTargets(this.service.dragTargetDirective);
|
|
769
|
-
break;
|
|
770
|
-
}
|
|
771
|
-
case 'string': {
|
|
772
|
-
allowed = this.service.dragTargetDirective.link === this.allowedDragTargets;
|
|
773
|
-
break;
|
|
774
|
-
}
|
|
775
|
-
default: {
|
|
776
|
-
allowed = this.allowedDragTargets.some(dt => dt === this.service.dragTargetDirective.link);
|
|
777
|
-
}
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
if (allowed) {
|
|
781
|
-
this.service.dropTarget = this.dropTarget;
|
|
782
|
-
this.ngZone.run(() => {
|
|
783
|
-
const eventArgs = new DropTargetDragEnterEvent({ normalizedEvent: event, hostElement: this.element.nativeElement });
|
|
784
|
-
this.dragEnter.emit(eventArgs);
|
|
785
|
-
});
|
|
786
|
-
}
|
|
990
|
+
this.service.dropTarget = this.dropTarget;
|
|
991
|
+
this.ngZone.run(() => {
|
|
992
|
+
this.emitEvent('dragEnter', event);
|
|
993
|
+
});
|
|
787
994
|
}
|
|
788
995
|
/**
|
|
789
996
|
* @hidden
|
|
@@ -794,8 +1001,7 @@ class DropTargetDirective {
|
|
|
794
1001
|
return;
|
|
795
1002
|
}
|
|
796
1003
|
this.ngZone.run(() => {
|
|
797
|
-
|
|
798
|
-
this.dragLeave.emit(eventArgs);
|
|
1004
|
+
this.emitEvent('dragLeave', event);
|
|
799
1005
|
});
|
|
800
1006
|
}
|
|
801
1007
|
/**
|
|
@@ -806,8 +1012,7 @@ class DropTargetDirective {
|
|
|
806
1012
|
return;
|
|
807
1013
|
}
|
|
808
1014
|
this.ngZone.run(() => {
|
|
809
|
-
|
|
810
|
-
this.dragOver.emit(eventArgs);
|
|
1015
|
+
this.emitEvent('dragOver', event);
|
|
811
1016
|
});
|
|
812
1017
|
}
|
|
813
1018
|
/**
|
|
@@ -815,13 +1020,9 @@ class DropTargetDirective {
|
|
|
815
1020
|
*/
|
|
816
1021
|
handleDrop(event) {
|
|
817
1022
|
this.ngZone.run(() => {
|
|
818
|
-
|
|
819
|
-
this.drop.emit(eventArgs);
|
|
1023
|
+
this.emitEvent('drop', event);
|
|
820
1024
|
});
|
|
821
1025
|
}
|
|
822
|
-
/**
|
|
823
|
-
* @hidden
|
|
824
|
-
*/
|
|
825
1026
|
initializeDropTarget() {
|
|
826
1027
|
this.dropTarget = {
|
|
827
1028
|
element: this.element.nativeElement,
|
|
@@ -831,16 +1032,848 @@ class DropTargetDirective {
|
|
|
831
1032
|
onDrop: this.handleDrop.bind(this)
|
|
832
1033
|
};
|
|
833
1034
|
}
|
|
1035
|
+
emitEvent(event, normalizedEvent) {
|
|
1036
|
+
var _a, _b;
|
|
1037
|
+
const eventProps = {
|
|
1038
|
+
dropTarget: this.element.nativeElement,
|
|
1039
|
+
dragTarget: (_a = this.service.dragTarget) === null || _a === void 0 ? void 0 : _a.element,
|
|
1040
|
+
dragEvent: normalizedEvent,
|
|
1041
|
+
dragData: this.service.dragData
|
|
1042
|
+
};
|
|
1043
|
+
if (isPresent((_b = this.service.dragTarget) === null || _b === void 0 ? void 0 : _b.hint)) {
|
|
1044
|
+
eventProps.hintElement = this.service.dragTarget.element;
|
|
1045
|
+
}
|
|
1046
|
+
const eventArgs = new DropTargetEvent(eventProps);
|
|
1047
|
+
this[event].emit(eventArgs);
|
|
1048
|
+
}
|
|
834
1049
|
}
|
|
835
1050
|
DropTargetDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DropTargetDirective, deps: [{ token: DragStateService }, { token: i0.ElementRef }, { token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Directive });
|
|
836
|
-
DropTargetDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: DropTargetDirective, selector: "[kendoDropTarget]",
|
|
1051
|
+
DropTargetDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: DropTargetDirective, selector: "[kendoDropTarget]", outputs: { dragEnter: "dragEnter", dragOver: "dragOver", dragLeave: "dragLeave", drop: "drop" }, exportAs: ["kendoDropTarget"], ngImport: i0 });
|
|
837
1052
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DropTargetDirective, decorators: [{
|
|
838
1053
|
type: Directive,
|
|
839
1054
|
args: [{
|
|
840
1055
|
selector: '[kendoDropTarget]',
|
|
841
1056
|
exportAs: 'kendoDropTarget'
|
|
842
1057
|
}]
|
|
843
|
-
}], ctorParameters: function () { return [{ type: DragStateService }, { type: i0.ElementRef }, { type: i0.NgZone }]; }, propDecorators: {
|
|
1058
|
+
}], ctorParameters: function () { return [{ type: DragStateService }, { type: i0.ElementRef }, { type: i0.NgZone }]; }, propDecorators: { dragEnter: [{
|
|
1059
|
+
type: Output
|
|
1060
|
+
}], dragOver: [{
|
|
1061
|
+
type: Output
|
|
1062
|
+
}], dragLeave: [{
|
|
1063
|
+
type: Output
|
|
1064
|
+
}], drop: [{
|
|
1065
|
+
type: Output
|
|
1066
|
+
}] } });
|
|
1067
|
+
|
|
1068
|
+
let isDragStartPrevented = false;
|
|
1069
|
+
let isDragPrevented = false;
|
|
1070
|
+
/**
|
|
1071
|
+
* Represents the [Kendo UI DragTargetContainer directive for Angular]({% slug api_utils_dragtargetcontainerdirective %}).
|
|
1072
|
+
* Used to configure multiple elements as draggable.
|
|
1073
|
+
*
|
|
1074
|
+
* @example
|
|
1075
|
+
* ```ts-no-run
|
|
1076
|
+
* <ul kendoDragTargetContainer dragTargetFilter=".my-draggable">
|
|
1077
|
+
* <li class="my-draggable">foo</li>
|
|
1078
|
+
* </ul>
|
|
1079
|
+
* ```
|
|
1080
|
+
*/
|
|
1081
|
+
class DragTargetContainerDirective {
|
|
1082
|
+
constructor(wrapper, ngZone, renderer, service, viewContainer, cdr) {
|
|
1083
|
+
this.wrapper = wrapper;
|
|
1084
|
+
this.ngZone = ngZone;
|
|
1085
|
+
this.renderer = renderer;
|
|
1086
|
+
this.service = service;
|
|
1087
|
+
this.viewContainer = viewContainer;
|
|
1088
|
+
this.cdr = cdr;
|
|
1089
|
+
/**
|
|
1090
|
+
* Defines whether a hint will be used for dragging. By default, the hint is a copy of the current drag target. ([see example]({% slug drag_target_container_hint %})).
|
|
1091
|
+
*
|
|
1092
|
+
* @default false
|
|
1093
|
+
*/
|
|
1094
|
+
this.hint = false;
|
|
1095
|
+
/**
|
|
1096
|
+
* Defines the delay in milliseconds after which the drag will begin ([see example]({% slug drag_target_container_delay %})).
|
|
1097
|
+
*
|
|
1098
|
+
* @default 0
|
|
1099
|
+
*/
|
|
1100
|
+
this.dragDelay = 0;
|
|
1101
|
+
/**
|
|
1102
|
+
* The number of pixels the pointer moves in any direction before the dragging starts ([see example]({% slug drag_target_container_minimum_distance %})).
|
|
1103
|
+
*
|
|
1104
|
+
* @default 0
|
|
1105
|
+
*/
|
|
1106
|
+
this.threshold = 0;
|
|
1107
|
+
/**
|
|
1108
|
+
* Specifies whether the default dragging behavior will be performed or the developer will manually handle the drag action.
|
|
1109
|
+
*
|
|
1110
|
+
* @default 'auto'
|
|
1111
|
+
*/
|
|
1112
|
+
this.mode = 'auto';
|
|
1113
|
+
/**
|
|
1114
|
+
* Fires when a DragTarget's `dragDelay` has passed and the user is able to drag the element.
|
|
1115
|
+
*/
|
|
1116
|
+
this.dragReady = new EventEmitter();
|
|
1117
|
+
/**
|
|
1118
|
+
* Fires when the user presses a DragTarget element.
|
|
1119
|
+
*/
|
|
1120
|
+
this.press = new EventEmitter();
|
|
1121
|
+
/**
|
|
1122
|
+
* Fires when the dragging of a DragTarget element begins.
|
|
1123
|
+
*/
|
|
1124
|
+
this.dragStart = new EventEmitter();
|
|
1125
|
+
/**
|
|
1126
|
+
* Fires while the user drags a DragTarget element.
|
|
1127
|
+
*/
|
|
1128
|
+
this.drag = new EventEmitter();
|
|
1129
|
+
/**
|
|
1130
|
+
* Fires when the user releases a DragTarget element after being pressed.
|
|
1131
|
+
*/
|
|
1132
|
+
this.release = new EventEmitter();
|
|
1133
|
+
/**
|
|
1134
|
+
* Fires when the dragging of a DragTarget ends and the element is released.
|
|
1135
|
+
*/
|
|
1136
|
+
this.dragEnd = new EventEmitter();
|
|
1137
|
+
this.currentDragTarget = null;
|
|
1138
|
+
this.dragTimeout = null;
|
|
1139
|
+
this.pressed = false;
|
|
1140
|
+
this.dragStarted = false;
|
|
1141
|
+
this.hintComponent = null;
|
|
1142
|
+
this.defaultHint = null;
|
|
1143
|
+
this.currentDragTargetElement = null;
|
|
1144
|
+
this.scrollableParent = null;
|
|
1145
|
+
this.previousDragTargets = [];
|
|
1146
|
+
this.initialPosition = { x: 0, y: 0 };
|
|
1147
|
+
this.position = { x: 0, y: 0 };
|
|
1148
|
+
this.positionsMap = new Map();
|
|
1149
|
+
this._dragTargetFilter = null;
|
|
1150
|
+
this._dragDisabled = false;
|
|
1151
|
+
this._dragData = () => null;
|
|
1152
|
+
this._dragTargetId = () => null;
|
|
1153
|
+
validatePackage(packageMetadata);
|
|
1154
|
+
}
|
|
1155
|
+
/**
|
|
1156
|
+
* Specifies a selector for elements within a container which will be configured as draggable
|
|
1157
|
+
* ([see example]({% slug drag_target_container %})). The possible values include any
|
|
1158
|
+
* DOM `selector`.
|
|
1159
|
+
*/
|
|
1160
|
+
set dragTargetFilter(value) {
|
|
1161
|
+
this._dragTargetFilter = value;
|
|
1162
|
+
if (!this.dragDisabled) {
|
|
1163
|
+
this.initializeDragTargets();
|
|
1164
|
+
}
|
|
1165
|
+
}
|
|
1166
|
+
get dragTargetFilter() {
|
|
1167
|
+
return this._dragTargetFilter;
|
|
1168
|
+
}
|
|
1169
|
+
/**
|
|
1170
|
+
* Defines a unique identifier for each drag target.
|
|
1171
|
+
* It exposes the current DragTarget HTML element and its index in the collection of drag targets as arguments.
|
|
1172
|
+
*/
|
|
1173
|
+
set dragTargetId(fn) {
|
|
1174
|
+
if (isDevMode && typeof fn !== 'function') {
|
|
1175
|
+
throw new Error(`dragTargetId must be a function, but received ${JSON.stringify(fn)}.`);
|
|
1176
|
+
}
|
|
1177
|
+
this._dragTargetId = fn;
|
|
1178
|
+
}
|
|
1179
|
+
get dragTargetId() {
|
|
1180
|
+
return this._dragTargetId;
|
|
1181
|
+
}
|
|
1182
|
+
/**
|
|
1183
|
+
* Defines a callback function which returns custom data passed to the DropTarget events.
|
|
1184
|
+
* It exposes the current DragTarget HTML element, its `dragTargetId` and its index in the collection of drag targets as arguments.
|
|
1185
|
+
*/
|
|
1186
|
+
set dragData(fn) {
|
|
1187
|
+
if (isDevMode && typeof fn !== 'function') {
|
|
1188
|
+
throw new Error(`dragData must be a function, but received ${JSON.stringify(fn)}.`);
|
|
1189
|
+
}
|
|
1190
|
+
this._dragData = fn;
|
|
1191
|
+
}
|
|
1192
|
+
get dragData() {
|
|
1193
|
+
return this._dragData;
|
|
1194
|
+
}
|
|
1195
|
+
/**
|
|
1196
|
+
* If set to true, the dragging of DragTargets within the container will be disabled.
|
|
1197
|
+
*
|
|
1198
|
+
* @default false
|
|
1199
|
+
*/
|
|
1200
|
+
set dragDisabled(value) {
|
|
1201
|
+
this._dragDisabled = value;
|
|
1202
|
+
if (value) {
|
|
1203
|
+
this.clearPreviousTargets();
|
|
1204
|
+
this.unsubscribe();
|
|
1205
|
+
if (isPresent(this.hintElem)) {
|
|
1206
|
+
this.destroyHint();
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
else {
|
|
1210
|
+
if (isPresent(this.wrapper) || isPresent(this.currentDragTarget)) {
|
|
1211
|
+
this.subscribe();
|
|
1212
|
+
}
|
|
1213
|
+
this.initializeDragTargets();
|
|
1214
|
+
}
|
|
1215
|
+
}
|
|
1216
|
+
get dragDisabled() {
|
|
1217
|
+
return this._dragDisabled;
|
|
1218
|
+
}
|
|
1219
|
+
/**
|
|
1220
|
+
* Used for notifying the DragTargetContainer that its content has changed.
|
|
1221
|
+
*/
|
|
1222
|
+
notify() {
|
|
1223
|
+
this.cdr.detectChanges();
|
|
1224
|
+
this.initializeDragTargets();
|
|
1225
|
+
}
|
|
1226
|
+
get allDragTargets() {
|
|
1227
|
+
return this.queryHost(this.dragTargetFilter);
|
|
1228
|
+
}
|
|
1229
|
+
get dragHandles() {
|
|
1230
|
+
return this.queryHost(this.dragHandle);
|
|
1231
|
+
}
|
|
1232
|
+
get hintTemplate() {
|
|
1233
|
+
return isPresent(this.hint) && typeof this.hint === 'object' ? this.hint.hintTemplate : null;
|
|
1234
|
+
}
|
|
1235
|
+
ngAfterViewInit() {
|
|
1236
|
+
const isTargetPresent = isPresent(this.wrapper) || isPresent(this.currentDragTarget);
|
|
1237
|
+
if (!this.dragDisabled && isTargetPresent) {
|
|
1238
|
+
this.subscribe();
|
|
1239
|
+
}
|
|
1240
|
+
!this.dragDisabled && this.initializeDragTargets();
|
|
1241
|
+
}
|
|
1242
|
+
onPointerDown(event) {
|
|
1243
|
+
if (isPresent(this.dragHandles) && this.dragHandles.length && !this.isDragHandle(event.target)) {
|
|
1244
|
+
return;
|
|
1245
|
+
}
|
|
1246
|
+
const action = getAction(event, this.currentDragTarget);
|
|
1247
|
+
this.service.handleDragAndDrop(action);
|
|
1248
|
+
this.subscribe();
|
|
1249
|
+
}
|
|
1250
|
+
onPointerMove(event) {
|
|
1251
|
+
event.preventDefault();
|
|
1252
|
+
const action = getAction(event, this.currentDragTarget);
|
|
1253
|
+
this.service.handleDragAndDrop(action);
|
|
1254
|
+
}
|
|
1255
|
+
onPointerUp(event) {
|
|
1256
|
+
event.preventDefault();
|
|
1257
|
+
const action = getAction(event, this.currentDragTarget);
|
|
1258
|
+
this.service.handleDragAndDrop(action);
|
|
1259
|
+
this.ngZone.runOutsideAngular(() => {
|
|
1260
|
+
this.subscribe();
|
|
1261
|
+
});
|
|
1262
|
+
}
|
|
1263
|
+
handlePress(event) {
|
|
1264
|
+
if (this.dragDelay > 0) {
|
|
1265
|
+
this.dragTimeout = window.setTimeout(() => {
|
|
1266
|
+
this.pressed = true;
|
|
1267
|
+
this.emitZoneAwareEvent('dragReady', event);
|
|
1268
|
+
}, this.dragDelay);
|
|
1269
|
+
}
|
|
1270
|
+
else {
|
|
1271
|
+
this.pressed = true;
|
|
1272
|
+
}
|
|
1273
|
+
const eventTarget = event.originalEvent.target;
|
|
1274
|
+
this.currentDragTargetElement = closestBySelector(eventTarget, this.dragTargetFilter);
|
|
1275
|
+
this.currentDragTarget.element = this.currentDragTargetElement;
|
|
1276
|
+
this.service.dragIndex = this.getDragIndex();
|
|
1277
|
+
this.scrollableParent = this.hintTemplate ? document.body : this.currentDragTargetElement ? getScrollableParent(this.currentDragTargetElement) : null;
|
|
1278
|
+
this.emitZoneAwareEvent('press', event);
|
|
1279
|
+
}
|
|
1280
|
+
handleDragStart(event) {
|
|
1281
|
+
if (!this.pressed) {
|
|
1282
|
+
if (this.dragTimeout) {
|
|
1283
|
+
window.clearTimeout(this.dragTimeout);
|
|
1284
|
+
this.dragTimeout = null;
|
|
1285
|
+
}
|
|
1286
|
+
return;
|
|
1287
|
+
}
|
|
1288
|
+
isDragStartPrevented = this.emitZoneAwareEvent('dragStart', event).isDefaultPrevented();
|
|
1289
|
+
if (isDragStartPrevented) {
|
|
1290
|
+
return;
|
|
1291
|
+
}
|
|
1292
|
+
this.position = this.positionsMap.has(this.currentDragTargetElement) ? this.positionsMap.get(this.currentDragTargetElement) : { x: 0, y: 0 };
|
|
1293
|
+
if (this.hint) {
|
|
1294
|
+
this.createHint();
|
|
1295
|
+
if (this.mode === 'auto') {
|
|
1296
|
+
this.renderer.setStyle(this.currentDragTargetElement, 'opacity', '0.7');
|
|
1297
|
+
}
|
|
1298
|
+
}
|
|
1299
|
+
else {
|
|
1300
|
+
this.initialPosition = { x: event.clientX - this.position.x, y: event.clientY - this.position.y };
|
|
1301
|
+
}
|
|
1302
|
+
this.emitZoneAwareEvent('dragStart', event);
|
|
1303
|
+
this.dragStarted = this.threshold === 0;
|
|
1304
|
+
this.service.dragTarget = this.currentDragTarget;
|
|
1305
|
+
this.service.dragTargetId = this.dragTargetId(this.currentDragTargetElement, this.service.dragIndex);
|
|
1306
|
+
this.service.dragData = this.dragData(this.currentDragTargetElement, this.service.dragTargetId, this.service.dragIndex);
|
|
1307
|
+
}
|
|
1308
|
+
handleDrag(event) {
|
|
1309
|
+
if (!this.pressed || isDragStartPrevented) {
|
|
1310
|
+
return;
|
|
1311
|
+
}
|
|
1312
|
+
isDragPrevented = this.emitZoneAwareEvent('drag', event).isDefaultPrevented();
|
|
1313
|
+
if (isDragPrevented) {
|
|
1314
|
+
return;
|
|
1315
|
+
}
|
|
1316
|
+
if (this.mode === 'auto') {
|
|
1317
|
+
this.performDrag(event);
|
|
1318
|
+
}
|
|
1319
|
+
else {
|
|
1320
|
+
this.dragStarted = true;
|
|
1321
|
+
}
|
|
1322
|
+
this.dragStarted && this.emitZoneAwareEvent('drag', event);
|
|
1323
|
+
}
|
|
1324
|
+
handleRelease(event) {
|
|
1325
|
+
if (this.dragStarted) {
|
|
1326
|
+
this.positionsMap.set(this.currentDragTargetElement, this.position);
|
|
1327
|
+
}
|
|
1328
|
+
if (this.dragTimeout) {
|
|
1329
|
+
clearTimeout(this.dragTimeout);
|
|
1330
|
+
this.dragTimeout = null;
|
|
1331
|
+
this.pressed = false;
|
|
1332
|
+
}
|
|
1333
|
+
this.emitZoneAwareEvent('release', event);
|
|
1334
|
+
}
|
|
1335
|
+
handleDragEnd(event) {
|
|
1336
|
+
var _a, _b;
|
|
1337
|
+
if (!this.dragStarted) {
|
|
1338
|
+
return;
|
|
1339
|
+
}
|
|
1340
|
+
if (this.mode === 'auto') {
|
|
1341
|
+
const isDroppedOverParentTarget = isPresent(this.service.dropTarget) && !contains((_a = this.service.dropTarget) === null || _a === void 0 ? void 0 : _a.element, (_b = this.service.dragTarget) === null || _b === void 0 ? void 0 : _b.element, true);
|
|
1342
|
+
const elem = this.hint ? this.hintElem : this.currentDragTargetElement;
|
|
1343
|
+
if (isDroppedOverParentTarget || this.service.dropTargets.length > 0 && isPresent(elem)) {
|
|
1344
|
+
this.renderer.removeStyle(elem, 'transform');
|
|
1345
|
+
setElementStyles(this.renderer, elem, {
|
|
1346
|
+
transition: dragTargetTransition
|
|
1347
|
+
});
|
|
1348
|
+
this.positionsMap.delete(this.currentDragTargetElement);
|
|
1349
|
+
}
|
|
1350
|
+
}
|
|
1351
|
+
if (this.hint && isPresent(this.hintElem)) {
|
|
1352
|
+
this.destroyHint();
|
|
1353
|
+
if (this.mode === 'auto') {
|
|
1354
|
+
this.renderer.removeStyle(this.currentDragTargetElement, 'opacity');
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
this.service.dragTarget = null;
|
|
1358
|
+
this.service.dragIndex = null;
|
|
1359
|
+
this.currentDragTarget.element = null;
|
|
1360
|
+
this.emitZoneAwareEvent('dragEnd', event);
|
|
1361
|
+
if (isDragStartPrevented || isDragPrevented) {
|
|
1362
|
+
return;
|
|
1363
|
+
}
|
|
1364
|
+
this.dragStarted = false;
|
|
1365
|
+
}
|
|
1366
|
+
get nativeElement() {
|
|
1367
|
+
return this.wrapper.nativeElement;
|
|
1368
|
+
}
|
|
1369
|
+
get hintElem() {
|
|
1370
|
+
return this.hintTemplate && isPresent(this.hintComponent) ? this.hintComponent.instance.element.nativeElement : this.defaultHint;
|
|
1371
|
+
}
|
|
1372
|
+
unsubscribe() {
|
|
1373
|
+
if (this.pointerDownSubscription) {
|
|
1374
|
+
this.pointerDownSubscription.unsubscribe();
|
|
1375
|
+
}
|
|
1376
|
+
if (this.pointerMoveSubscription) {
|
|
1377
|
+
this.pointerMoveSubscription.unsubscribe();
|
|
1378
|
+
}
|
|
1379
|
+
if (this.pointerUpSubscription) {
|
|
1380
|
+
this.pointerUpSubscription.unsubscribe();
|
|
1381
|
+
}
|
|
1382
|
+
if (this.scrollSubscription) {
|
|
1383
|
+
this.scrollSubscription.unsubscribe();
|
|
1384
|
+
}
|
|
1385
|
+
}
|
|
1386
|
+
subscribe() {
|
|
1387
|
+
this.ngZone.runOutsideAngular(() => {
|
|
1388
|
+
this.unsubscribe();
|
|
1389
|
+
if (!(isDocumentAvailable() && isPresent(this.wrapper))) {
|
|
1390
|
+
return;
|
|
1391
|
+
}
|
|
1392
|
+
const element = this.nativeElement;
|
|
1393
|
+
if (this.service.pressed) {
|
|
1394
|
+
const pointerMoveStreams = allPointerMoveEvents.map((ev) => fromEvent(document, ev));
|
|
1395
|
+
const pointerUpStreams = allPointerUpEvents.map((ev) => fromEvent(document, ev));
|
|
1396
|
+
this.pointerMoveSubscription = merge(...pointerMoveStreams)
|
|
1397
|
+
.pipe(filter(() => this.dragTargetFilter !== ''))
|
|
1398
|
+
.subscribe(e => this.onPointerMove(e));
|
|
1399
|
+
this.pointerUpSubscription = merge(...pointerUpStreams)
|
|
1400
|
+
.subscribe(e => this.onPointerUp(e));
|
|
1401
|
+
if (isPresent(this.scrollableParent)) {
|
|
1402
|
+
this.scrollSubscription = fromEvent(this.scrollableParent, 'scroll')
|
|
1403
|
+
.subscribe(e => this.onPointerMove(e));
|
|
1404
|
+
}
|
|
1405
|
+
}
|
|
1406
|
+
else {
|
|
1407
|
+
const pointerDownStreams = allPointerDownEvents.map((ev) => fromEvent(element, ev));
|
|
1408
|
+
this.pointerDownSubscription = merge(...pointerDownStreams)
|
|
1409
|
+
.pipe(filter(() => this.dragTargetFilter !== ''))
|
|
1410
|
+
.subscribe((e) => {
|
|
1411
|
+
const filterElement = closestBySelector(e.target, this.dragTargetFilter);
|
|
1412
|
+
if (filterElement) {
|
|
1413
|
+
this.onPointerDown(e);
|
|
1414
|
+
}
|
|
1415
|
+
});
|
|
1416
|
+
}
|
|
1417
|
+
});
|
|
1418
|
+
}
|
|
1419
|
+
emitZoneAwareEvent(event, normalizedEvent) {
|
|
1420
|
+
const eventProps = {
|
|
1421
|
+
dragTarget: this.currentDragTargetElement,
|
|
1422
|
+
dragEvent: normalizedEvent,
|
|
1423
|
+
dragTargetIndex: this.service.dragIndex,
|
|
1424
|
+
dragTargetId: this.dragTargetId(this.currentDragTargetElement, this.service.dragIndex)
|
|
1425
|
+
};
|
|
1426
|
+
if (this.hint && isPresent(this.hintElem)) {
|
|
1427
|
+
eventProps.hintElement = this.hintElem;
|
|
1428
|
+
}
|
|
1429
|
+
let eventArgs;
|
|
1430
|
+
switch (event) {
|
|
1431
|
+
case 'dragReady':
|
|
1432
|
+
eventArgs = new DragTargetDragReadyEvent(eventProps);
|
|
1433
|
+
break;
|
|
1434
|
+
case 'press':
|
|
1435
|
+
eventArgs = new DragTargetPressEvent(eventProps);
|
|
1436
|
+
break;
|
|
1437
|
+
case 'dragStart':
|
|
1438
|
+
eventArgs = new DragTargetDragStartEvent(eventProps);
|
|
1439
|
+
break;
|
|
1440
|
+
case 'drag':
|
|
1441
|
+
eventArgs = new DragTargetDragEvent(eventProps);
|
|
1442
|
+
break;
|
|
1443
|
+
case 'release':
|
|
1444
|
+
eventArgs = new DragTargetReleaseEvent(eventProps);
|
|
1445
|
+
break;
|
|
1446
|
+
case 'dragEnd':
|
|
1447
|
+
eventArgs = new DragTargetDragEndEvent(eventProps);
|
|
1448
|
+
break;
|
|
1449
|
+
default:
|
|
1450
|
+
break;
|
|
1451
|
+
}
|
|
1452
|
+
this.ngZone.run(() => {
|
|
1453
|
+
this[event].emit(eventArgs);
|
|
1454
|
+
});
|
|
1455
|
+
return eventArgs;
|
|
1456
|
+
}
|
|
1457
|
+
createHint() {
|
|
1458
|
+
if (!(isDocumentAvailable() && isPresent(this.wrapper))) {
|
|
1459
|
+
return;
|
|
1460
|
+
}
|
|
1461
|
+
if (isPresent(this.hint) && typeof this.hint === 'object') {
|
|
1462
|
+
if (isPresent(this.hint.hintTemplate)) {
|
|
1463
|
+
this.createCustomHint();
|
|
1464
|
+
}
|
|
1465
|
+
else {
|
|
1466
|
+
this.createDefaultHint();
|
|
1467
|
+
}
|
|
1468
|
+
}
|
|
1469
|
+
else {
|
|
1470
|
+
this.createDefaultHint();
|
|
1471
|
+
}
|
|
1472
|
+
this.currentDragTarget.hint = this.hintElem;
|
|
1473
|
+
if (typeof this.hint === 'object' && isPresent(this.hint.appendTo)) {
|
|
1474
|
+
this.hint.appendTo.element.nativeElement.appendChild(this.hintElem);
|
|
1475
|
+
}
|
|
1476
|
+
else {
|
|
1477
|
+
document.body.appendChild(this.hintElem);
|
|
1478
|
+
}
|
|
1479
|
+
}
|
|
1480
|
+
createDefaultHint() {
|
|
1481
|
+
this.defaultHint = this.currentDragTargetElement.cloneNode(true);
|
|
1482
|
+
if (typeof this.hint === 'object') {
|
|
1483
|
+
if (isPresent(this.hint.hintClass)) {
|
|
1484
|
+
const hintClasses = parseCSSClassNames(this.hint.hintClass);
|
|
1485
|
+
hintClasses.forEach(className => this.renderer.addClass(this.defaultHint, className));
|
|
1486
|
+
}
|
|
1487
|
+
}
|
|
1488
|
+
}
|
|
1489
|
+
createCustomHint() {
|
|
1490
|
+
if (isPresent(this.hint.appendTo)) {
|
|
1491
|
+
this.hintComponent = this.hint.appendTo.createComponent(HintComponent);
|
|
1492
|
+
}
|
|
1493
|
+
else {
|
|
1494
|
+
this.hintComponent = this.viewContainer.createComponent(HintComponent);
|
|
1495
|
+
}
|
|
1496
|
+
this.hintComponent.instance.template = this.hintTemplate;
|
|
1497
|
+
this.hintComponent.instance.directive = this;
|
|
1498
|
+
this.hintComponent.instance.targetIndex = this.service.dragIndex;
|
|
1499
|
+
this.hintComponent.instance.contextData = this.dragData(this.currentDragTargetElement, this.service.dragIndex);
|
|
1500
|
+
this.hintComponent.changeDetectorRef.detectChanges();
|
|
1501
|
+
}
|
|
1502
|
+
destroyHint() {
|
|
1503
|
+
if (isPresent(this.hintTemplate)) {
|
|
1504
|
+
this.hintComponent.destroy();
|
|
1505
|
+
this.hintComponent.changeDetectorRef.detectChanges();
|
|
1506
|
+
this.hintComponent = null;
|
|
1507
|
+
}
|
|
1508
|
+
else {
|
|
1509
|
+
document.body.removeChild(this.defaultHint);
|
|
1510
|
+
this.defaultHint = null;
|
|
1511
|
+
}
|
|
1512
|
+
this.currentDragTarget.hint = null;
|
|
1513
|
+
}
|
|
1514
|
+
getDragIndex() {
|
|
1515
|
+
return this.allDragTargets.indexOf(this.currentDragTargetElement);
|
|
1516
|
+
}
|
|
1517
|
+
initializeDragTargets() {
|
|
1518
|
+
if (!isPresent(this.allDragTargets)) {
|
|
1519
|
+
if (this.previousDragTargets.length > 0) {
|
|
1520
|
+
this.clearPreviousTargets();
|
|
1521
|
+
}
|
|
1522
|
+
return;
|
|
1523
|
+
}
|
|
1524
|
+
this.allDragTargets.forEach(dragTargetEl => {
|
|
1525
|
+
const isDragTargetInitialized = this.service.dragTargets.find(dt => dt.element === dragTargetEl);
|
|
1526
|
+
if (!isDragTargetInitialized) {
|
|
1527
|
+
this.service.dragTargets.push({
|
|
1528
|
+
element: dragTargetEl,
|
|
1529
|
+
hint: null,
|
|
1530
|
+
onPress: this.handlePress.bind(this),
|
|
1531
|
+
onRelease: this.handleRelease.bind(this),
|
|
1532
|
+
onDragStart: this.handleDragStart.bind(this),
|
|
1533
|
+
onDrag: this.handleDrag.bind(this),
|
|
1534
|
+
onDragEnd: this.handleDragEnd.bind(this)
|
|
1535
|
+
});
|
|
1536
|
+
}
|
|
1537
|
+
});
|
|
1538
|
+
if (this.previousDragTargets.length > 0) {
|
|
1539
|
+
const dragTargetsToRemove = this.previousDragTargets.filter(dt => !this.allDragTargets.includes(dt));
|
|
1540
|
+
dragTargetsToRemove.forEach(dragTarget => {
|
|
1541
|
+
const idx = this.service.dragTargets.findIndex(serviceDragTarget => serviceDragTarget.element === dragTarget);
|
|
1542
|
+
if (idx > -1) {
|
|
1543
|
+
this.service.dragTargets.splice(idx, 1);
|
|
1544
|
+
}
|
|
1545
|
+
});
|
|
1546
|
+
}
|
|
1547
|
+
this.previousDragTargets = this.allDragTargets;
|
|
1548
|
+
this.currentDragTarget = {
|
|
1549
|
+
element: null,
|
|
1550
|
+
hint: null,
|
|
1551
|
+
onPress: this.handlePress.bind(this),
|
|
1552
|
+
onRelease: this.handleRelease.bind(this),
|
|
1553
|
+
onDragStart: this.handleDragStart.bind(this),
|
|
1554
|
+
onDrag: this.handleDrag.bind(this),
|
|
1555
|
+
onDragEnd: this.handleDragEnd.bind(this)
|
|
1556
|
+
};
|
|
1557
|
+
this.setCursorStyle();
|
|
1558
|
+
}
|
|
1559
|
+
isDragHandle(el) {
|
|
1560
|
+
return this.dragHandles.some(dh => contains(dh, el, true));
|
|
1561
|
+
}
|
|
1562
|
+
setCursorStyle() {
|
|
1563
|
+
if (!isDocumentAvailable()) {
|
|
1564
|
+
return;
|
|
1565
|
+
}
|
|
1566
|
+
if (isPresent(this.dragHandles) && this.dragHandles.length > 0) {
|
|
1567
|
+
this.dragHandles.forEach(handle => {
|
|
1568
|
+
this.renderer.addClass(handle, 'k-cursor-pointer');
|
|
1569
|
+
});
|
|
1570
|
+
}
|
|
1571
|
+
else {
|
|
1572
|
+
this.allDragTargets.forEach(target => {
|
|
1573
|
+
this.renderer.addClass(target, 'k-cursor-pointer');
|
|
1574
|
+
});
|
|
1575
|
+
}
|
|
1576
|
+
}
|
|
1577
|
+
queryHost(selector) {
|
|
1578
|
+
if (isPresent(selector) && selector !== "") {
|
|
1579
|
+
return Array.from(this.nativeElement.querySelectorAll(selector));
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
clearPreviousTargets() {
|
|
1583
|
+
this.previousDragTargets.forEach(dragTarget => {
|
|
1584
|
+
const idx = this.service.dragTargets.findIndex(serviceDragTarget => serviceDragTarget.element === dragTarget);
|
|
1585
|
+
if (idx > -1) {
|
|
1586
|
+
this.service.dragTargets.splice(idx, 1);
|
|
1587
|
+
}
|
|
1588
|
+
});
|
|
1589
|
+
this.previousDragTargets = [];
|
|
1590
|
+
}
|
|
1591
|
+
performDrag(event) {
|
|
1592
|
+
const elem = this.hint ? this.hintElem : this.currentDragTargetElement;
|
|
1593
|
+
this.position = this.calculatePosition(elem, event);
|
|
1594
|
+
const thresholdNotReached = Math.abs(this.position.x) < this.threshold && Math.abs(this.position.y) < this.threshold;
|
|
1595
|
+
if (!this.dragStarted && thresholdNotReached) {
|
|
1596
|
+
return;
|
|
1597
|
+
}
|
|
1598
|
+
if (!this.dragStarted && this.threshold > 0) {
|
|
1599
|
+
this.dragStarted = true;
|
|
1600
|
+
}
|
|
1601
|
+
const styles = this.getStylesPerElement(elem);
|
|
1602
|
+
setElementStyles(this.renderer, elem, styles);
|
|
1603
|
+
}
|
|
1604
|
+
calculatePosition(element, event) {
|
|
1605
|
+
let position = null;
|
|
1606
|
+
if (element === this.hintElem) {
|
|
1607
|
+
position = { x: event.clientX, y: event.clientY };
|
|
1608
|
+
}
|
|
1609
|
+
else {
|
|
1610
|
+
position = { x: event.clientX - this.initialPosition.x + event.scrollX, y: event.clientY - this.initialPosition.y + event.scrollY };
|
|
1611
|
+
}
|
|
1612
|
+
return position;
|
|
1613
|
+
}
|
|
1614
|
+
getStylesPerElement(element) {
|
|
1615
|
+
if (element === this.hintElem) {
|
|
1616
|
+
const hintCoordinates = { x: this.position.x - this.initialPosition.x, y: this.position.y - this.initialPosition.y };
|
|
1617
|
+
return {
|
|
1618
|
+
top: `${hintCoordinates.y}px`,
|
|
1619
|
+
left: `${hintCoordinates.x}px`,
|
|
1620
|
+
transition: 'none',
|
|
1621
|
+
position: 'absolute',
|
|
1622
|
+
zIndex: 1999
|
|
1623
|
+
};
|
|
1624
|
+
}
|
|
1625
|
+
else {
|
|
1626
|
+
const transform = `translate(${this.position.x}px, ${this.position.y}px)`;
|
|
1627
|
+
return {
|
|
1628
|
+
transform: transform,
|
|
1629
|
+
transition: 'none'
|
|
1630
|
+
};
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
}
|
|
1634
|
+
DragTargetContainerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragTargetContainerDirective, deps: [{ token: i0.ElementRef }, { token: i0.NgZone }, { token: i0.Renderer2 }, { token: DragStateService }, { token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
1635
|
+
DragTargetContainerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: DragTargetContainerDirective, selector: "[kendoDragTargetContainer]", inputs: { hint: "hint", dragTargetFilter: "dragTargetFilter", dragHandle: "dragHandle", dragDelay: "dragDelay", threshold: "threshold", dragTargetId: "dragTargetId", dragData: "dragData", dragDisabled: "dragDisabled", mode: "mode" }, outputs: { dragReady: "dragReady", press: "press", dragStart: "dragStart", drag: "drag", release: "release", dragEnd: "dragEnd" }, exportAs: ["kendoDragTargetContainer"], ngImport: i0 });
|
|
1636
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragTargetContainerDirective, decorators: [{
|
|
1637
|
+
type: Directive,
|
|
1638
|
+
args: [{
|
|
1639
|
+
selector: '[kendoDragTargetContainer]',
|
|
1640
|
+
exportAs: 'kendoDragTargetContainer'
|
|
1641
|
+
}]
|
|
1642
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: i0.Renderer2 }, { type: DragStateService }, { type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { hint: [{
|
|
1643
|
+
type: Input
|
|
1644
|
+
}], dragTargetFilter: [{
|
|
1645
|
+
type: Input
|
|
1646
|
+
}], dragHandle: [{
|
|
1647
|
+
type: Input
|
|
1648
|
+
}], dragDelay: [{
|
|
1649
|
+
type: Input
|
|
1650
|
+
}], threshold: [{
|
|
1651
|
+
type: Input
|
|
1652
|
+
}], dragTargetId: [{
|
|
1653
|
+
type: Input
|
|
1654
|
+
}], dragData: [{
|
|
1655
|
+
type: Input
|
|
1656
|
+
}], dragDisabled: [{
|
|
1657
|
+
type: Input
|
|
1658
|
+
}], mode: [{
|
|
1659
|
+
type: Input
|
|
1660
|
+
}], dragReady: [{
|
|
1661
|
+
type: Output
|
|
1662
|
+
}], press: [{
|
|
1663
|
+
type: Output
|
|
1664
|
+
}], dragStart: [{
|
|
1665
|
+
type: Output
|
|
1666
|
+
}], drag: [{
|
|
1667
|
+
type: Output
|
|
1668
|
+
}], release: [{
|
|
1669
|
+
type: Output
|
|
1670
|
+
}], dragEnd: [{
|
|
1671
|
+
type: Output
|
|
1672
|
+
}] } });
|
|
1673
|
+
|
|
1674
|
+
/**
|
|
1675
|
+
* Represents the [Kendo UI DropTargetContainer directive for Angular]({% slug api_utils_droptargetcontainerdirective %}).
|
|
1676
|
+
* Used to configure multiple elements as drop targets.
|
|
1677
|
+
*
|
|
1678
|
+
* @example
|
|
1679
|
+
* ```ts-no-run
|
|
1680
|
+
* <div kendoDropTargetContainer dropTargetFilter=".my-droptarget">
|
|
1681
|
+
* <div class="my-droptarget">foo</div>
|
|
1682
|
+
* </div>
|
|
1683
|
+
* ```
|
|
1684
|
+
*/
|
|
1685
|
+
class DropTargetContainerDirective {
|
|
1686
|
+
constructor(service, element, ngZone, cdr) {
|
|
1687
|
+
this.service = service;
|
|
1688
|
+
this.element = element;
|
|
1689
|
+
this.ngZone = ngZone;
|
|
1690
|
+
this.cdr = cdr;
|
|
1691
|
+
/**
|
|
1692
|
+
* Fires when a DragTarget element enters the DropTarget.
|
|
1693
|
+
*/
|
|
1694
|
+
this.dragEnter = new EventEmitter();
|
|
1695
|
+
/**
|
|
1696
|
+
* Fires when a DragTarget element is being dragged over the DropTarget.
|
|
1697
|
+
*/
|
|
1698
|
+
this.dragOver = new EventEmitter();
|
|
1699
|
+
/**
|
|
1700
|
+
* Fires when a DragTarget element leaves the DropTarget.
|
|
1701
|
+
*/
|
|
1702
|
+
this.dragLeave = new EventEmitter();
|
|
1703
|
+
/**
|
|
1704
|
+
* Fires when a DragTarget element is dropped over the DropTarget.
|
|
1705
|
+
*/
|
|
1706
|
+
this.drop = new EventEmitter();
|
|
1707
|
+
this.currentDropTarget = null;
|
|
1708
|
+
this.currentDropTargetElement = null;
|
|
1709
|
+
this.previousDropTargets = [];
|
|
1710
|
+
this._dropTargetFilter = null;
|
|
1711
|
+
this._dropDisabled = false;
|
|
1712
|
+
validatePackage(packageMetadata);
|
|
1713
|
+
}
|
|
1714
|
+
/**
|
|
1715
|
+
* Specifies a selector for elements within a container which will be configured as drop targets
|
|
1716
|
+
* ([see example]({% slug drop_target_container %})). The possible values include any
|
|
1717
|
+
* DOM `selector`.
|
|
1718
|
+
*/
|
|
1719
|
+
set dropTargetFilter(value) {
|
|
1720
|
+
this._dropTargetFilter = value;
|
|
1721
|
+
if (!this.dropDisabled) {
|
|
1722
|
+
this.initializeDropTargets();
|
|
1723
|
+
}
|
|
1724
|
+
}
|
|
1725
|
+
get dropTargetFilter() {
|
|
1726
|
+
return this._dropTargetFilter;
|
|
1727
|
+
}
|
|
1728
|
+
/**
|
|
1729
|
+
* Specifies whether the Drop Targets within the container will emit the corresponding events upon interaction with a Drag Target.
|
|
1730
|
+
*/
|
|
1731
|
+
set dropDisabled(value) {
|
|
1732
|
+
if (value) {
|
|
1733
|
+
this.clearPreviousTargets();
|
|
1734
|
+
}
|
|
1735
|
+
else {
|
|
1736
|
+
this.initializeDropTargets();
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
get dropDisabled() {
|
|
1740
|
+
return this._dropDisabled;
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Used for notifying the DropTargetContainer that its content has changed.
|
|
1744
|
+
*/
|
|
1745
|
+
notify() {
|
|
1746
|
+
this.cdr.detectChanges();
|
|
1747
|
+
this.initializeDropTargets();
|
|
1748
|
+
}
|
|
1749
|
+
get nativeElement() {
|
|
1750
|
+
return this.element.nativeElement;
|
|
1751
|
+
}
|
|
1752
|
+
ngAfterViewInit() {
|
|
1753
|
+
!this.dropDisabled && this.initializeDropTargets();
|
|
1754
|
+
}
|
|
1755
|
+
get allDropTargets() {
|
|
1756
|
+
if (isPresent(this.dropTargetFilter) && this.dropTargetFilter !== '') {
|
|
1757
|
+
return Array.from(this.nativeElement.querySelectorAll(this.dropTargetFilter));
|
|
1758
|
+
}
|
|
1759
|
+
}
|
|
1760
|
+
/**
|
|
1761
|
+
* @hidden
|
|
1762
|
+
*/
|
|
1763
|
+
handleDragEnter(event) {
|
|
1764
|
+
if (!this.service.dragTarget) {
|
|
1765
|
+
return;
|
|
1766
|
+
}
|
|
1767
|
+
const eventTarget = event.originalEvent.target;
|
|
1768
|
+
this.currentDropTargetElement = intersect(eventTarget, this.allDropTargets);
|
|
1769
|
+
this.currentDropTarget = this.service.dropTargets.find(dt => dt.element === this.currentDropTargetElement);
|
|
1770
|
+
this.service.dropTarget = this.currentDropTarget;
|
|
1771
|
+
this.service.dropIndex = this.getDropIndex();
|
|
1772
|
+
this.emitZoneAwareEvent('dragEnter', event);
|
|
1773
|
+
}
|
|
1774
|
+
/**
|
|
1775
|
+
* @hidden
|
|
1776
|
+
*/
|
|
1777
|
+
handleDragLeave(event) {
|
|
1778
|
+
this.service.dropTarget = null;
|
|
1779
|
+
if (!this.service.dragTarget) {
|
|
1780
|
+
return;
|
|
1781
|
+
}
|
|
1782
|
+
this.emitZoneAwareEvent('dragLeave', event);
|
|
1783
|
+
}
|
|
1784
|
+
/**
|
|
1785
|
+
* @hidden
|
|
1786
|
+
*/
|
|
1787
|
+
handleDragOver(event) {
|
|
1788
|
+
if (!this.service.dragTarget) {
|
|
1789
|
+
return;
|
|
1790
|
+
}
|
|
1791
|
+
this.emitZoneAwareEvent('dragOver', event);
|
|
1792
|
+
}
|
|
1793
|
+
/**
|
|
1794
|
+
* @hidden
|
|
1795
|
+
*/
|
|
1796
|
+
handleDrop(event) {
|
|
1797
|
+
if (!this.service.dragTarget) {
|
|
1798
|
+
return;
|
|
1799
|
+
}
|
|
1800
|
+
this.emitZoneAwareEvent('drop', event);
|
|
1801
|
+
this.currentDropTarget = null;
|
|
1802
|
+
this.currentDropTargetElement = null;
|
|
1803
|
+
this.service.dropIndex = null;
|
|
1804
|
+
}
|
|
1805
|
+
initializeDropTargets() {
|
|
1806
|
+
if (!isPresent(this.allDropTargets)) {
|
|
1807
|
+
if (this.previousDropTargets.length > 0) {
|
|
1808
|
+
this.clearPreviousTargets();
|
|
1809
|
+
}
|
|
1810
|
+
return;
|
|
1811
|
+
}
|
|
1812
|
+
this.allDropTargets.forEach(dropTargetEl => {
|
|
1813
|
+
const isDropTargetInitialized = this.service.dropTargets.find(dt => dt.element === dropTargetEl);
|
|
1814
|
+
if (!isDropTargetInitialized) {
|
|
1815
|
+
this.service.dropTargets.push({
|
|
1816
|
+
element: dropTargetEl,
|
|
1817
|
+
onDragEnter: this.handleDragEnter.bind(this),
|
|
1818
|
+
onDragLeave: this.handleDragLeave.bind(this),
|
|
1819
|
+
onDragOver: this.handleDragOver.bind(this),
|
|
1820
|
+
onDrop: this.handleDrop.bind(this)
|
|
1821
|
+
});
|
|
1822
|
+
}
|
|
1823
|
+
});
|
|
1824
|
+
if (this.previousDropTargets.length > 0) {
|
|
1825
|
+
const dropTargetsToRemove = this.previousDropTargets.filter(dt => !this.allDropTargets.includes(dt));
|
|
1826
|
+
dropTargetsToRemove.forEach(dropTarget => {
|
|
1827
|
+
const idx = this.service.dropTargets.findIndex(serviceDropTarget => serviceDropTarget.element === dropTarget);
|
|
1828
|
+
if (idx > -1) {
|
|
1829
|
+
this.service.dropTargets.splice(idx, 1);
|
|
1830
|
+
}
|
|
1831
|
+
});
|
|
1832
|
+
}
|
|
1833
|
+
this.previousDropTargets = this.allDropTargets;
|
|
1834
|
+
}
|
|
1835
|
+
emitZoneAwareEvent(event, normalizedEvent) {
|
|
1836
|
+
var _a;
|
|
1837
|
+
const eventProps = {
|
|
1838
|
+
dragTarget: this.service.dragTarget,
|
|
1839
|
+
dropTarget: this.currentDropTargetElement,
|
|
1840
|
+
dragData: this.service.dragData,
|
|
1841
|
+
dragEvent: normalizedEvent,
|
|
1842
|
+
dropTargetIndex: this.service.dropIndex
|
|
1843
|
+
};
|
|
1844
|
+
if (isPresent((_a = this.service.dragTarget) === null || _a === void 0 ? void 0 : _a.hint)) {
|
|
1845
|
+
eventProps.hintElement = this.service.dragTarget.hint;
|
|
1846
|
+
}
|
|
1847
|
+
const eventArgs = new DropTargetEvent(eventProps);
|
|
1848
|
+
this.ngZone.run(() => {
|
|
1849
|
+
this[event].emit(eventArgs);
|
|
1850
|
+
});
|
|
1851
|
+
}
|
|
1852
|
+
getDropIndex() {
|
|
1853
|
+
const allTargets = this.nativeElement.querySelectorAll(this.dropTargetFilter);
|
|
1854
|
+
return Array.from(allTargets).indexOf(this.currentDropTargetElement);
|
|
1855
|
+
}
|
|
1856
|
+
clearPreviousTargets() {
|
|
1857
|
+
this.previousDropTargets.forEach(dropTarget => {
|
|
1858
|
+
const idx = this.service.dropTargets.findIndex(serviceDropTarget => serviceDropTarget.element === dropTarget);
|
|
1859
|
+
if (idx > -1) {
|
|
1860
|
+
this.service.dropTargets.splice(idx, 1);
|
|
1861
|
+
}
|
|
1862
|
+
});
|
|
1863
|
+
this.previousDropTargets = [];
|
|
1864
|
+
}
|
|
1865
|
+
}
|
|
1866
|
+
DropTargetContainerDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DropTargetContainerDirective, deps: [{ token: DragStateService }, { token: i0.ElementRef }, { token: i0.NgZone }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
1867
|
+
DropTargetContainerDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.12", type: DropTargetContainerDirective, selector: "[kendoDropTargetContainer]", inputs: { dropTargetFilter: "dropTargetFilter", dropDisabled: "dropDisabled" }, outputs: { dragEnter: "dragEnter", dragOver: "dragOver", dragLeave: "dragLeave", drop: "drop" }, exportAs: ["kendoDropTargetContainer"], ngImport: i0 });
|
|
1868
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DropTargetContainerDirective, decorators: [{
|
|
1869
|
+
type: Directive,
|
|
1870
|
+
args: [{
|
|
1871
|
+
selector: '[kendoDropTargetContainer]',
|
|
1872
|
+
exportAs: 'kendoDropTargetContainer'
|
|
1873
|
+
}]
|
|
1874
|
+
}], ctorParameters: function () { return [{ type: DragStateService }, { type: i0.ElementRef }, { type: i0.NgZone }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { dropTargetFilter: [{
|
|
1875
|
+
type: Input
|
|
1876
|
+
}], dropDisabled: [{
|
|
844
1877
|
type: Input
|
|
845
1878
|
}], dragEnter: [{
|
|
846
1879
|
type: Output
|
|
@@ -856,6 +1889,8 @@ const EXPORTS = [
|
|
|
856
1889
|
DragTargetDirective,
|
|
857
1890
|
DragHandleDirective,
|
|
858
1891
|
DropTargetDirective,
|
|
1892
|
+
DragTargetContainerDirective,
|
|
1893
|
+
DropTargetContainerDirective,
|
|
859
1894
|
HintComponent
|
|
860
1895
|
];
|
|
861
1896
|
/**
|
|
@@ -895,9 +1930,13 @@ DragAndDropModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", versio
|
|
|
895
1930
|
DragAndDropModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragAndDropModule, declarations: [DragTargetDirective,
|
|
896
1931
|
DragHandleDirective,
|
|
897
1932
|
DropTargetDirective,
|
|
1933
|
+
DragTargetContainerDirective,
|
|
1934
|
+
DropTargetContainerDirective,
|
|
898
1935
|
HintComponent], imports: [CommonModule], exports: [DragTargetDirective,
|
|
899
1936
|
DragHandleDirective,
|
|
900
1937
|
DropTargetDirective,
|
|
1938
|
+
DragTargetContainerDirective,
|
|
1939
|
+
DropTargetContainerDirective,
|
|
901
1940
|
HintComponent] });
|
|
902
1941
|
DragAndDropModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragAndDropModule, imports: [[CommonModule]] });
|
|
903
1942
|
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragAndDropModule, decorators: [{
|
|
@@ -957,5 +1996,5 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
|
|
|
957
1996
|
* Generated bundle index. Do not edit.
|
|
958
1997
|
*/
|
|
959
1998
|
|
|
960
|
-
export { DragAndDropModule, DragHandleDirective, DragTargetDirective, DragTargetDragEndEvent, DragTargetDragEvent, DragTargetDragStartEvent, DragTargetPressEvent,
|
|
1999
|
+
export { DragAndDropModule, DragHandleDirective, DragTargetContainerDirective, DragTargetDirective, DragTargetDragEndEvent, DragTargetDragEvent, DragTargetDragReadyEvent, DragTargetDragStartEvent, DragTargetPressEvent, DragTargetReleaseEvent, DropTargetContainerDirective, DropTargetDirective, DropTargetEvent, HintComponent, UtilsModule };
|
|
961
2000
|
|