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