@progress/kendo-angular-utils 12.0.0-develop.8 → 12.0.0

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