@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
@@ -2,16 +2,18 @@
2
2
  * Copyright © 2023 Progress Software Corporation. All rights reserved.
3
3
  * Licensed under commercial license. See LICENSE.md in the project root for more information
4
4
  *-------------------------------------------------------------------------------------------*/
5
- import { Directive, EventEmitter, HostBinding, Output, ElementRef, Renderer2, NgZone, Input, ContentChildren, QueryList, TemplateRef, ViewContainerRef, ComponentFactoryResolver } from "@angular/core";
5
+ import { Directive, EventEmitter, Output, ElementRef, Renderer2, NgZone, Input, ContentChildren, QueryList, ViewContainerRef, isDevMode } from "@angular/core";
6
6
  import { validatePackage } from '@progress/kendo-licensing';
7
7
  import { packageMetadata } from '../package-metadata';
8
8
  import { DragHandleDirective } from "./draghandle.directive";
9
9
  import { getScrollableParent } from "@progress/kendo-draggable-common";
10
- import { DragTargetDragStartEvent, DragTargetDragEndEvent, DragTargetPressEvent, DragTargetDragEvent } from "./events/drag-target";
11
10
  import { DragStateService } from "./drag-state.service";
12
11
  import { getAction, isPresent, setElementStyles, dragTargetTransition } from './util';
13
- import { contains, isDocumentAvailable } from "@progress/kendo-angular-common";
12
+ import { contains, isDocumentAvailable, parseCSSClassNames } from "@progress/kendo-angular-common";
14
13
  import { HintComponent } from "./hint.component";
14
+ import { DragTargetDragEndEvent, DragTargetDragEvent, DragTargetDragStartEvent, DragTargetPressEvent } from "./events/drag-target";
15
+ import { DragTargetReleaseEvent } from "./events/drag-target/release-event";
16
+ import { DragTargetDragReadyEvent } from "./events/drag-target/dragready-event";
15
17
  import * as i0 from "@angular/core";
16
18
  import * as i1 from "./drag-state.service";
17
19
  let isDragStartPrevented = false;
@@ -20,15 +22,20 @@ let isDragPrevented = false;
20
22
  * Represents the Kendo UI DragTarget directive for Angular.
21
23
  */
22
24
  export class DragTargetDirective {
23
- constructor(element, renderer, ngZone, service, viewContainer, resolver) {
25
+ constructor(element, renderer, ngZone, service, viewContainer) {
24
26
  this.element = element;
25
27
  this.renderer = renderer;
26
28
  this.ngZone = ngZone;
27
29
  this.service = service;
28
30
  this.viewContainer = viewContainer;
29
- this.resolver = resolver;
30
31
  /**
31
- * The number of pixels the pointer moves in any direction before the dragging starts ([see example]({% slug minimum_distance %})).
32
+ * 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 %})).
33
+ *
34
+ * @default false
35
+ */
36
+ this.hint = false;
37
+ /**
38
+ * 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`.
32
39
  *
33
40
  * @default 0
34
41
  */
@@ -45,18 +52,22 @@ export class DragTargetDirective {
45
52
  * @default 0
46
53
  */
47
54
  this.dragDelay = 0;
55
+ /**
56
+ * Specifies whether the default dragging behavior will be performed or the developer will manually handle the drag action.
57
+ *
58
+ * @default 'auto'
59
+ */
60
+ this.mode = 'auto';
48
61
  /**
49
62
  * Fires when the user presses the DragTarget element.
50
63
  */
51
64
  this.press = new EventEmitter();
52
65
  /**
53
66
  * Fires when the dragging of the DragTarget element begins.
54
- * This event is preventable.
55
67
  */
56
68
  this.dragStart = new EventEmitter();
57
69
  /**
58
70
  * Fires while the user drags the DragTarget element.
59
- * This event is preventable.
60
71
  */
61
72
  this.drag = new EventEmitter();
62
73
  /**
@@ -71,32 +82,42 @@ export class DragTargetDirective {
71
82
  * Fires when the dragging of the DragTarget ends and the element is released.
72
83
  */
73
84
  this.dragEnd = new EventEmitter();
74
- this.touchAction = 'none';
75
85
  this.dragTarget = null;
76
86
  this.domSubscriptions = [];
77
- this.hint = null;
78
- this.initialPosition = { x: 0, y: 0 };
87
+ this.hintComponent = null;
79
88
  this.dragStarted = false;
80
89
  this.pressed = false;
81
90
  this.dragTimeout = null;
91
+ this.initialPosition = { x: 0, y: 0 };
82
92
  this.position = { x: 0, y: 0 };
93
+ this.scrollableParent = null;
94
+ this.defaultHint = null;
95
+ this._dragData = () => null;
83
96
  validatePackage(packageMetadata);
84
97
  }
85
98
  /**
86
- * @hidden
99
+ * Defines a callback function used for attaching custom data to the dragTarget.
100
+ * The data will be available in the events of the respective [`DropTarget`]({% slug api_utils_droptargetdirective %}) or [`DropTargetContainer`]({% slug api_utils_droptargetcontainerdirective %}) directives.
101
+ * The current DragTarget HTML element and its `dragTargetId` will be available as arguments.
87
102
  */
103
+ set dragData(fn) {
104
+ if (isDevMode && typeof fn !== 'function') {
105
+ throw new Error(`dragData must be a function, but received ${JSON.stringify(fn)}.`);
106
+ }
107
+ this._dragData = fn;
108
+ }
109
+ get dragData() {
110
+ return this._dragData;
111
+ }
112
+ get hintTemplate() {
113
+ return isPresent(this.hint) && typeof this.hint === 'object' ? this.hint.hintTemplate : null;
114
+ }
88
115
  get nativeElement() {
89
116
  return this.element.nativeElement;
90
117
  }
91
- /**
92
- * @hidden
93
- */
94
118
  get hintElem() {
95
- return this.hint.instance.element.nativeElement;
119
+ return this.hintTemplate && isPresent(this.hintComponent) ? this.hintComponent.instance.element.nativeElement : this.defaultHint;
96
120
  }
97
- /**
98
- * @hidden
99
- */
100
121
  onPointerDown(event) {
101
122
  if (this.dragHandles.length && !this.isDragHandle(event.target)) {
102
123
  return;
@@ -107,127 +128,88 @@ export class DragTargetDirective {
107
128
  this.service.autoScroll = typeof this.autoScroll === 'object' ? this.autoScroll.enabled !== false : this.autoScroll;
108
129
  this.service.scrollableParent = this.getAutoScrollContainer();
109
130
  this.service.autoScrollDirection = typeof this.autoScroll === 'object' ? this.autoScroll.direction : { horizontal: true, vertical: true };
110
- this.ngZone.runOutsideAngular(() => {
111
- this.attachDomHandlers();
112
- });
131
+ this.attachDomHandlers();
113
132
  }
114
- /**
115
- * @hidden
116
- */
117
133
  onPointerMove(event) {
118
134
  event.preventDefault();
119
135
  const action = getAction(event, this.dragTarget);
120
136
  this.service.handleDragAndDrop(action);
121
137
  }
122
- /**
123
- * @hidden
124
- */
125
138
  onPointerUp(event) {
126
139
  event.preventDefault();
127
140
  const action = getAction(event, this.dragTarget);
128
141
  this.service.handleDragAndDrop(action);
129
- this.ngZone.runOutsideAngular(() => {
130
- this.attachDomHandlers();
131
- });
142
+ this.attachDomHandlers();
132
143
  }
133
144
  ngOnInit() {
134
- this.initializeDraggable();
145
+ this.initializeDragTarget();
135
146
  }
136
147
  ngAfterContentInit() {
137
148
  if (isPresent(this.element) || isPresent(this.dragTarget)) {
138
- this.ngZone.runOutsideAngular(() => {
139
- this.attachDomHandlers();
140
- if (!this.dragHandles.length) {
141
- this.renderer.addClass(this.nativeElement, 'k-cursor-pointer');
142
- }
143
- });
149
+ this.attachDomHandlers();
150
+ if (!this.dragHandles.length) {
151
+ this.renderer.addClass(this.nativeElement, 'k-cursor-pointer');
152
+ }
144
153
  }
145
154
  this.service.dragTargets.push(this.dragTarget);
146
155
  }
147
156
  ngOnDestroy() {
148
157
  this.domSubscriptions.forEach(subscription => subscription());
149
158
  }
150
- /**
151
- * @hidden
152
- */
153
159
  handlePress(event) {
154
160
  if (this.dragDelay > 0) {
155
- this.dragTimeout = setTimeout(() => {
161
+ this.dragTimeout = window.setTimeout(() => {
156
162
  this.pressed = true;
157
- this.ngZone.run(() => {
158
- this.dragReady.emit();
159
- });
163
+ this.emitZoneAwareEvent('dragReady', event);
160
164
  }, this.dragDelay);
161
165
  }
162
166
  else {
163
167
  this.pressed = true;
164
168
  }
165
- this.ngZone.run(() => {
166
- const eventArgs = new DragTargetPressEvent({ normalizedEvent: event, hostElement: this.nativeElement });
167
- this.press.emit(eventArgs);
168
- });
169
+ this.scrollableParent = this.dragTarget.element ? getScrollableParent(this.dragTarget.element) : null;
170
+ this.emitZoneAwareEvent('press', event);
169
171
  }
170
- /**
171
- * @hidden
172
- */
173
172
  handleDragStart(event) {
174
173
  if (!this.pressed) {
175
174
  if (this.dragTimeout) {
176
- clearTimeout(this.dragTimeout);
175
+ window.clearTimeout(this.dragTimeout);
177
176
  this.dragTimeout = null;
178
177
  }
179
178
  return;
180
179
  }
181
- this.ngZone.run(() => {
182
- isDragStartPrevented = this.emitEvent('dragStart', { normalizedEvent: event, hostElement: this.nativeElement }).isDefaultPrevented();
183
- });
180
+ isDragStartPrevented = this.emitZoneAwareEvent('dragStart', event).isDefaultPrevented();
184
181
  if (isDragStartPrevented) {
185
182
  return;
186
183
  }
187
- if (isPresent(this.hintTemplate)) {
184
+ if (this.hint) {
188
185
  this.createHint();
189
- if (isPresent(this.hint)) {
186
+ if (this.mode === 'auto') {
190
187
  this.renderer.setStyle(this.nativeElement, 'opacity', '0.7');
191
188
  }
189
+ this.initialPosition = { x: event.offsetX, y: event.offsetY };
190
+ }
191
+ else {
192
+ this.initialPosition = { x: event.clientX - this.position.x, y: event.clientY - this.position.y };
192
193
  }
193
194
  this.dragStarted = this.threshold === 0;
194
195
  this.service.dragTarget = this.dragTarget;
195
196
  this.service.dragTargetDirective = this;
196
- this.initialPosition = { x: event.clientX - this.position.x, y: event.clientY - this.position.y };
197
+ this.service.dragData = this.dragData(this.dragTarget.element, this.dragTargetIdResult);
197
198
  }
198
199
  handleDrag(event) {
199
200
  if (!this.pressed || isDragStartPrevented) {
200
201
  return;
201
202
  }
202
- const elem = this.hint ? this.hintElem : this.nativeElement;
203
- const eventArgsProps = elem === this.nativeElement ? { normalizedEvent: event, hostElement: this.nativeElement } : { normalizedEvent: event, hostElement: this.nativeElement, hintElement: elem };
204
- this.ngZone.run(() => {
205
- isDragPrevented = this.emitEvent('drag', eventArgsProps).isDefaultPrevented();
206
- });
203
+ isDragPrevented = this.emitZoneAwareEvent('drag', event).isDefaultPrevented();
207
204
  if (isDragPrevented) {
208
205
  return;
209
206
  }
210
- if (this.restrictByAxis === 'horizontal') {
211
- this.position = { x: event.clientX - this.initialPosition.x + event.scrollX, y: 0 };
212
- }
213
- else if (this.restrictByAxis === 'vertical') {
214
- this.position = { x: 0, y: event.clientY - this.initialPosition.y + event.scrollY };
207
+ if (this.mode === 'auto') {
208
+ this.performDrag(event);
215
209
  }
216
210
  else {
217
- this.position = { x: event.clientX - this.initialPosition.x + event.scrollX, y: event.clientY - this.initialPosition.y + event.scrollY };
218
- }
219
- const thresholdNotReached = Math.abs(this.position.x) < this.threshold && Math.abs(this.position.y) < this.threshold;
220
- if (!this.dragStarted && thresholdNotReached) {
221
- return;
222
- }
223
- if (!this.dragStarted && this.threshold > 0) {
224
211
  this.dragStarted = true;
225
212
  }
226
- const transform = `translate(${this.position.x}px, ${this.position.y}px)`;
227
- setElementStyles(this.renderer, elem, {
228
- transform: transform,
229
- transition: 'none'
230
- });
231
213
  }
232
214
  handleRelease(event) {
233
215
  if (this.dragTimeout) {
@@ -235,44 +217,35 @@ export class DragTargetDirective {
235
217
  this.dragTimeout = null;
236
218
  this.pressed = false;
237
219
  }
238
- this.service.dragTarget = null;
239
- this.service.dragTargetDirective = null;
240
- this.ngZone.run(() => {
241
- const eventArgs = new DragTargetPressEvent({ normalizedEvent: event, hostElement: this.nativeElement });
242
- this.release.emit(eventArgs);
243
- });
220
+ this.emitZoneAwareEvent('release', event);
244
221
  }
245
222
  handleDragEnd(event) {
246
- if (this.dragTimeout) {
247
- clearTimeout(this.dragTimeout);
248
- this.dragTimeout = null;
249
- this.pressed = false;
223
+ if (this.mode === 'auto') {
224
+ const isDroppedOverParentTarget = isPresent(this.service.dropTarget) && !contains(this.service.dropTarget?.element, this.service.dragTarget?.element, true);
225
+ const elem = this.hint ? this.hintElem : this.nativeElement;
226
+ if (isDroppedOverParentTarget || this.service.dropTargets.length > 0 && isPresent(elem)) {
227
+ this.renderer.removeStyle(elem, 'transform');
228
+ setElementStyles(this.renderer, elem, {
229
+ transition: dragTargetTransition
230
+ });
231
+ this.position = { x: 0, y: 0 };
232
+ }
250
233
  }
251
- const isDroppedOverParentTarget = isPresent(this.service.dropTarget) && !contains(this.service.dropTarget?.element, this.service.dragTarget?.element, true);
252
- const elem = this.hint ? this.hintElem : this.nativeElement;
253
- if (isDroppedOverParentTarget || this.service.dropTargets.length > 0) {
254
- this.renderer.removeStyle(elem, 'transform');
255
- setElementStyles(this.renderer, elem, {
256
- transition: dragTargetTransition
257
- });
258
- this.position = { x: 0, y: 0 };
259
- }
260
- if (isPresent(this.hint)) {
261
- this.renderer.removeStyle(this.nativeElement, 'opacity');
234
+ if (this.hint && isPresent(this.hintElem)) {
262
235
  this.destroyHint();
236
+ if (this.mode === 'auto') {
237
+ this.renderer.removeStyle(this.nativeElement, 'opacity');
238
+ }
263
239
  }
264
240
  this.service.dragTarget = null;
265
241
  this.service.dragTargetDirective = null;
266
242
  if (!this.dragStarted || isDragStartPrevented || isDragPrevented) {
267
243
  return;
268
244
  }
269
- this.ngZone.run(() => {
270
- const eventArgs = new DragTargetDragEndEvent({ normalizedEvent: event, hostElement: this.nativeElement });
271
- this.dragEnd.emit(eventArgs);
272
- });
245
+ this.emitZoneAwareEvent('dragEnd', event);
273
246
  this.dragStarted = false;
274
247
  }
275
- initializeDraggable() {
248
+ initializeDragTarget() {
276
249
  this.dragTarget = {
277
250
  element: this.nativeElement,
278
251
  hint: null,
@@ -284,43 +257,44 @@ export class DragTargetDirective {
284
257
  };
285
258
  }
286
259
  attachDomHandlers() {
287
- if (this.domSubscriptions.length > 0) {
288
- this.domSubscriptions.forEach(subscription => subscription());
289
- }
290
- if (!(isDocumentAvailable() && isPresent(this.element))) {
291
- return;
292
- }
293
- if (this.service.pressed) {
294
- this.onPointerMove = this.onPointerMove.bind(this);
295
- this.onPointerUp = this.onPointerUp.bind(this);
296
- let scrollable = getScrollableParent(this.nativeElement);
297
- this.domSubscriptions = [
298
- this.renderer.listen(document, 'pointermove', this.onPointerMove),
299
- this.renderer.listen(document, 'mousemove', this.onPointerMove),
300
- this.renderer.listen(document, 'touchmove', this.onPointerMove),
301
- this.renderer.listen(document, 'pointerup', this.onPointerUp),
302
- this.renderer.listen(document, 'pointercancel', this.onPointerUp),
303
- this.renderer.listen(document, 'mouseup', this.onPointerUp),
304
- this.renderer.listen(document, 'contextmenu', this.onPointerUp),
305
- this.renderer.listen(document, 'touchend', this.onPointerUp),
306
- this.renderer.listen(document, 'touchcancel', this.onPointerUp)
307
- ];
308
- if (scrollable) {
309
- if (scrollable === document.getElementsByTagName('html')[0]) {
310
- scrollable = document;
260
+ this.ngZone.runOutsideAngular(() => {
261
+ if (this.domSubscriptions.length > 0) {
262
+ this.domSubscriptions.forEach(subscription => subscription());
263
+ }
264
+ if (!(isDocumentAvailable() && isPresent(this.element))) {
265
+ return;
266
+ }
267
+ if (this.service.pressed) {
268
+ this.onPointerMove = this.onPointerMove.bind(this);
269
+ this.onPointerUp = this.onPointerUp.bind(this);
270
+ this.domSubscriptions = [
271
+ this.renderer.listen(document, 'pointermove', this.onPointerMove),
272
+ this.renderer.listen(document, 'mousemove', this.onPointerMove),
273
+ this.renderer.listen(document, 'touchmove', this.onPointerMove),
274
+ this.renderer.listen(document, 'pointerup', this.onPointerUp),
275
+ this.renderer.listen(document, 'pointercancel', this.onPointerUp),
276
+ this.renderer.listen(document, 'mouseup', this.onPointerUp),
277
+ this.renderer.listen(document, 'contextmenu', this.onPointerUp),
278
+ this.renderer.listen(document, 'touchend', this.onPointerUp),
279
+ this.renderer.listen(document, 'touchcancel', this.onPointerUp)
280
+ ];
281
+ if (isPresent(this.scrollableParent)) {
282
+ if (this.scrollableParent === document.getElementsByTagName('html')[0]) {
283
+ this.scrollableParent = window;
284
+ }
285
+ this.domSubscriptions.push(this.renderer.listen(this.scrollableParent, 'scroll', this.onPointerMove));
311
286
  }
312
- this.domSubscriptions.push(this.renderer.listen(scrollable, 'scroll', this.onPointerMove));
313
287
  }
314
- }
315
- else {
316
- this.onPointerDown = this.onPointerDown.bind(this);
317
- const element = this.nativeElement;
318
- this.domSubscriptions = [
319
- this.renderer.listen(element, 'pointerdown', this.onPointerDown),
320
- this.renderer.listen(element, 'mousedown', this.onPointerDown),
321
- this.renderer.listen(element, 'touchstart', this.onPointerDown)
322
- ];
323
- }
288
+ else {
289
+ this.onPointerDown = this.onPointerDown.bind(this);
290
+ const element = this.nativeElement;
291
+ this.domSubscriptions = [
292
+ this.renderer.listen(element, 'pointerdown', this.onPointerDown),
293
+ this.renderer.listen(element, 'mousedown', this.onPointerDown),
294
+ this.renderer.listen(element, 'touchstart', this.onPointerDown)
295
+ ];
296
+ }
297
+ });
324
298
  }
325
299
  isDragHandle(el) {
326
300
  return this.dragHandles.toArray().some(dh => contains(dh.element.nativeElement, el, true));
@@ -332,55 +306,182 @@ export class DragTargetDirective {
332
306
  this.autoScroll.boundaryElementRef.nativeElement : null;
333
307
  }
334
308
  createHint() {
335
- const hintComponent = this.resolver.resolveComponentFactory(HintComponent);
336
- this.hint = this.viewContainer.createComponent(hintComponent);
337
- this.hint.instance.template = this.hintTemplate;
338
- this.hint.instance.directive = this;
339
- this.hint.changeDetectorRef.detectChanges();
340
- this.dragTarget.hint = this.hint.instance.element.nativeElement;
309
+ if (!(isDocumentAvailable() && isPresent(this.element))) {
310
+ return;
311
+ }
312
+ if (isPresent(this.hint) && typeof this.hint === 'object') {
313
+ if (isPresent(this.hint.hintTemplate)) {
314
+ this.createCustomHint();
315
+ }
316
+ else {
317
+ this.createDefaultHint();
318
+ }
319
+ }
320
+ else {
321
+ this.createDefaultHint();
322
+ }
323
+ this.dragTarget.hint = this.hintElem;
324
+ if (typeof this.hint === 'object' && isPresent(this.hint.appendTo)) {
325
+ this.hint.appendTo.element.nativeElement.appendChild(this.hintElem);
326
+ }
327
+ else {
328
+ document.body.appendChild(this.hintElem);
329
+ }
330
+ }
331
+ createDefaultHint() {
332
+ this.defaultHint = this.nativeElement.cloneNode(true);
333
+ if (typeof this.hint === 'object') {
334
+ if (isPresent(this.hint.hintClass)) {
335
+ const hintClasses = parseCSSClassNames(this.hint.hintClass);
336
+ hintClasses.forEach(className => this.renderer.addClass(this.defaultHint, className));
337
+ }
338
+ }
339
+ }
340
+ createCustomHint() {
341
+ if (isPresent(this.hint.appendTo)) {
342
+ this.hintComponent = this.hint.appendTo.createComponent(HintComponent);
343
+ }
344
+ else {
345
+ this.hintComponent = this.viewContainer.createComponent(HintComponent);
346
+ }
347
+ this.hintComponent.instance.template = this.hintTemplate;
348
+ this.hintComponent.instance.directive = this;
349
+ this.hintComponent.changeDetectorRef.detectChanges();
341
350
  }
342
351
  destroyHint() {
343
- this.hint.destroy();
344
- this.hint.changeDetectorRef.detectChanges();
345
- this.hint = null;
352
+ if (isPresent(this.hintTemplate)) {
353
+ this.hintComponent.destroy();
354
+ this.hintComponent.changeDetectorRef.detectChanges();
355
+ this.hintComponent = null;
356
+ }
357
+ else {
358
+ if (typeof this.hint === 'object' && isPresent(this.hint.appendTo)) {
359
+ this.hint.appendTo.element.nativeElement.removeChild(this.defaultHint);
360
+ }
361
+ else {
362
+ document.body.removeChild(this.defaultHint);
363
+ }
364
+ this.defaultHint = null;
365
+ }
346
366
  this.dragTarget.hint = null;
347
367
  }
348
- emitEvent(event, args) {
368
+ emitZoneAwareEvent(event, normalizedEvent) {
369
+ const eventProps = {
370
+ dragTarget: this.nativeElement,
371
+ dragEvent: normalizedEvent
372
+ };
373
+ if (this.hint && isPresent(this.hintElem)) {
374
+ eventProps.hintElement = this.hintElem;
375
+ }
376
+ if (this.dragTargetId && this.dragTargetId !== '') {
377
+ eventProps.dragTargetId = this.dragTargetIdResult;
378
+ }
349
379
  let eventArgs;
350
380
  switch (event) {
381
+ case 'dragReady':
382
+ eventArgs = new DragTargetDragReadyEvent(eventProps);
383
+ break;
384
+ case 'press':
385
+ eventArgs = new DragTargetPressEvent(eventProps);
386
+ break;
351
387
  case 'dragStart':
352
- eventArgs = new DragTargetDragStartEvent(args);
388
+ eventArgs = new DragTargetDragStartEvent(eventProps);
353
389
  break;
354
390
  case 'drag':
355
- eventArgs = new DragTargetDragEvent(args);
391
+ eventArgs = new DragTargetDragEvent(eventProps);
392
+ break;
393
+ case 'release':
394
+ eventArgs = new DragTargetReleaseEvent(eventProps);
395
+ break;
396
+ case 'dragEnd':
397
+ eventArgs = new DragTargetDragEndEvent(eventProps);
356
398
  break;
357
399
  default:
358
400
  break;
359
401
  }
360
- this[event].emit(eventArgs);
402
+ this.ngZone.run(() => {
403
+ this[event].emit(eventArgs);
404
+ });
361
405
  return eventArgs;
362
406
  }
407
+ get dragTargetIdResult() {
408
+ if (this.dragTargetId && this.dragTargetId !== '') {
409
+ return typeof this.dragTargetId === 'string' ? this.dragTargetId : this.dragTargetId(this.dragTarget.element);
410
+ }
411
+ }
412
+ performDrag(event) {
413
+ const elem = this.hint ? this.hintElem : this.nativeElement;
414
+ this.position = this.calculatePosition(elem, event);
415
+ const thresholdNotReached = Math.abs(this.position.x) < this.threshold && Math.abs(this.position.y) < this.threshold;
416
+ if (!this.dragStarted && thresholdNotReached) {
417
+ return;
418
+ }
419
+ if (!this.dragStarted && this.threshold > 0) {
420
+ this.dragStarted = true;
421
+ }
422
+ const styles = this.getStylesPerElement(elem);
423
+ setElementStyles(this.renderer, elem, styles);
424
+ }
425
+ calculatePosition(element, event) {
426
+ let position = null;
427
+ if (element === this.hintElem) {
428
+ position = { x: event.clientX, y: event.clientY };
429
+ }
430
+ else {
431
+ position = { x: event.clientX - this.initialPosition.x + event.scrollX, y: event.clientY - this.initialPosition.y + event.scrollY };
432
+ }
433
+ if (this.restrictByAxis === 'horizontal') {
434
+ position.y = 0;
435
+ }
436
+ else if (this.restrictByAxis === 'vertical') {
437
+ position.x = 0;
438
+ }
439
+ return position;
440
+ }
441
+ getStylesPerElement(element) {
442
+ if (element === this.hintElem) {
443
+ const hintCoordinates = { x: this.position.x - this.initialPosition.x, y: this.position.y - this.initialPosition.y };
444
+ return {
445
+ top: `${hintCoordinates.y}px`,
446
+ left: `${hintCoordinates.x}px`,
447
+ transition: 'none',
448
+ position: 'absolute',
449
+ zIndex: 1999
450
+ };
451
+ }
452
+ else {
453
+ const transform = `translate(${this.position.x}px, ${this.position.y}px)`;
454
+ return {
455
+ transform: transform,
456
+ transition: 'none'
457
+ };
458
+ }
459
+ }
363
460
  }
364
- 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: i1.DragStateService }, { token: i0.ViewContainerRef }, { token: i0.ComponentFactoryResolver }], target: i0.ɵɵFactoryTarget.Directive });
365
- 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 });
461
+ 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: i1.DragStateService }, { token: i0.ViewContainerRef }], target: i0.ɵɵFactoryTarget.Directive });
462
+ 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 });
366
463
  i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragTargetDirective, decorators: [{
367
464
  type: Directive,
368
465
  args: [{
369
466
  selector: '[kendoDragTarget]',
370
467
  exportAs: 'kendoDragTarget'
371
468
  }]
372
- }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }, { type: i1.DragStateService }, { type: i0.ViewContainerRef }, { type: i0.ComponentFactoryResolver }]; }, propDecorators: { hintTemplate: [{
469
+ }], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.Renderer2 }, { type: i0.NgZone }, { type: i1.DragStateService }, { type: i0.ViewContainerRef }]; }, propDecorators: { hint: [{
373
470
  type: Input
374
471
  }], threshold: [{
375
472
  type: Input
376
473
  }], autoScroll: [{
377
474
  type: Input
378
- }], link: [{
475
+ }], dragTargetId: [{
379
476
  type: Input
380
477
  }], dragDelay: [{
381
478
  type: Input
382
479
  }], restrictByAxis: [{
383
480
  type: Input
481
+ }], mode: [{
482
+ type: Input
483
+ }], dragData: [{
484
+ type: Input
384
485
  }], press: [{
385
486
  type: Output
386
487
  }], dragStart: [{
@@ -393,9 +494,6 @@ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImpo
393
494
  type: Output
394
495
  }], dragEnd: [{
395
496
  type: Output
396
- }], touchAction: [{
397
- type: HostBinding,
398
- args: ['style.touch-action']
399
497
  }], dragHandles: [{
400
498
  type: ContentChildren,
401
499
  args: [DragHandleDirective]