@progress/kendo-angular-utils 12.0.0-develop.1 → 12.0.0-develop.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/drag-and-drop/drag-state.service.d.ts +4 -0
- package/drag-and-drop/draghandle.directive.d.ts +1 -0
- package/drag-and-drop/dragtarget-container.directive.d.ts +164 -0
- package/drag-and-drop/dragtarget.directive.d.ts +45 -42
- package/drag-and-drop/droptarget-container.directive.d.ts +89 -0
- package/drag-and-drop/droptarget.directive.d.ts +7 -18
- package/drag-and-drop/events/drag-target/drag-event.d.ts +23 -5
- package/drag-and-drop/events/drag-target/dragready-event.d.ts +30 -0
- package/drag-and-drop/events/drag-target/end-event.d.ts +22 -4
- package/drag-and-drop/events/drag-target/index.d.ts +2 -0
- package/drag-and-drop/events/drag-target/press-event.d.ts +23 -5
- package/drag-and-drop/events/drag-target/release-event.d.ts +40 -0
- package/drag-and-drop/events/drag-target/start-event.d.ts +22 -4
- package/drag-and-drop/events/drop-target-event.d.ts +48 -0
- package/drag-and-drop/events/index.d.ts +6 -0
- package/drag-and-drop/hint.component.d.ts +3 -4
- package/{esm2020/drag-and-drop/events/drop-target/drop-event.mjs → drag-and-drop/models/drag-mode.d.ts} +2 -9
- package/drag-and-drop/models/functions.d.ts +17 -0
- package/drag-and-drop/models/hint-settings.d.ts +22 -0
- package/drag-and-drop/models/index.d.ts +4 -2
- package/drag-and-drop/util.d.ts +22 -2
- package/drag-and-drop.module.d.ts +5 -3
- package/esm2020/drag-and-drop/drag-state.service.mjs +2 -0
- package/esm2020/drag-and-drop/draghandle.directive.mjs +1 -0
- package/esm2020/drag-and-drop/dragtarget-container.directive.mjs +621 -0
- package/esm2020/drag-and-drop/dragtarget.directive.mjs +260 -162
- package/esm2020/drag-and-drop/droptarget-container.directive.mjs +224 -0
- package/esm2020/drag-and-drop/droptarget.directive.mjs +25 -43
- package/esm2020/drag-and-drop/events/drag-target/drag-event.mjs +15 -1
- package/esm2020/drag-and-drop/events/{drop-target/enter-event.mjs → drag-target/dragready-event.mjs} +2 -2
- package/esm2020/drag-and-drop/events/drag-target/end-event.mjs +15 -1
- package/esm2020/drag-and-drop/events/drag-target/index.mjs +2 -0
- package/esm2020/drag-and-drop/events/drag-target/press-event.mjs +15 -1
- package/esm2020/drag-and-drop/events/{drop-target/leave-event.mjs → drag-target/release-event.mjs} +16 -2
- package/esm2020/drag-and-drop/events/drag-target/start-event.mjs +15 -1
- package/esm2020/drag-and-drop/events/drop-target-event.mjs +29 -0
- package/esm2020/drag-and-drop/events/index.mjs +6 -0
- package/esm2020/drag-and-drop/hint.component.mjs +9 -20
- package/esm2020/drag-and-drop/models/functions.mjs +5 -0
- package/esm2020/drag-and-drop/models/hint-settings.mjs +5 -0
- package/esm2020/drag-and-drop/util.mjs +73 -5
- package/esm2020/drag-and-drop.module.mjs +8 -0
- package/esm2020/index.mjs +4 -1
- package/esm2020/package-metadata.mjs +2 -2
- package/fesm2015/progress-kendo-angular-utils.mjs +1346 -307
- package/fesm2020/progress-kendo-angular-utils.mjs +1349 -313
- package/index.d.ts +4 -2
- package/package.json +3 -3
- package/drag-and-drop/events/drop-target/drop-event.d.ts +0 -22
- package/drag-and-drop/events/drop-target/enter-event.d.ts +0 -22
- package/drag-and-drop/events/drop-target/index.d.ts +0 -8
- package/drag-and-drop/events/drop-target/leave-event.d.ts +0 -22
- package/drag-and-drop/events/drop-target/over-event.d.ts +0 -22
- package/drag-and-drop/models/allowed-target.d.ts +0 -16
- package/esm2020/drag-and-drop/events/drop-target/index.mjs +0 -8
- package/esm2020/drag-and-drop/events/drop-target/over-event.mjs +0 -15
- /package/drag-and-drop/models/{dragaxis.d.ts → drag-axis.d.ts} +0 -0
- /package/esm2020/drag-and-drop/models/{allowed-target.mjs → drag-axis.mjs} +0 -0
- /package/esm2020/drag-and-drop/models/{dragaxis.mjs → drag-mode.mjs} +0 -0
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
/**-----------------------------------------------------------------------------------------
|
|
2
|
+
* Copyright © 2023 Progress Software Corporation. All rights reserved.
|
|
3
|
+
* Licensed under commercial license. See LICENSE.md in the project root for more information
|
|
4
|
+
*-------------------------------------------------------------------------------------------*/
|
|
5
|
+
import { ChangeDetectorRef, Directive, ElementRef, EventEmitter, Input, isDevMode, NgZone, Output, Renderer2, ViewContainerRef } from '@angular/core';
|
|
6
|
+
import { validatePackage } from '@progress/kendo-licensing';
|
|
7
|
+
import { fromEvent, merge } from 'rxjs';
|
|
8
|
+
import { packageMetadata } from '../package-metadata';
|
|
9
|
+
import { filter } from 'rxjs/operators';
|
|
10
|
+
import { closestBySelector, allPointerDownEvents, allPointerMoveEvents, allPointerUpEvents, getAction, isPresent, setElementStyles, dragTargetTransition } from './util';
|
|
11
|
+
import { getScrollableParent } from '@progress/kendo-draggable-common';
|
|
12
|
+
import { DragStateService } from './drag-state.service';
|
|
13
|
+
import { contains, isDocumentAvailable, parseCSSClassNames } from '@progress/kendo-angular-common';
|
|
14
|
+
import { HintComponent } from './hint.component';
|
|
15
|
+
import { DragTargetDragEndEvent, DragTargetDragEvent, DragTargetDragReadyEvent, DragTargetDragStartEvent, DragTargetPressEvent, DragTargetReleaseEvent } from './events/drag-target';
|
|
16
|
+
import * as i0 from "@angular/core";
|
|
17
|
+
import * as i1 from "./drag-state.service";
|
|
18
|
+
let isDragStartPrevented = false;
|
|
19
|
+
let isDragPrevented = false;
|
|
20
|
+
/**
|
|
21
|
+
* Represents the [Kendo UI DragTargetContainer directive for Angular]({% slug api_utils_dragtargetcontainerdirective %}).
|
|
22
|
+
* Used to configure multiple elements as draggable.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```ts-no-run
|
|
26
|
+
* <ul kendoDragTargetContainer dragTargetFilter=".my-draggable">
|
|
27
|
+
* <li class="my-draggable">foo</li>
|
|
28
|
+
* </ul>
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export class DragTargetContainerDirective {
|
|
32
|
+
constructor(wrapper, ngZone, renderer, service, viewContainer, cdr) {
|
|
33
|
+
this.wrapper = wrapper;
|
|
34
|
+
this.ngZone = ngZone;
|
|
35
|
+
this.renderer = renderer;
|
|
36
|
+
this.service = service;
|
|
37
|
+
this.viewContainer = viewContainer;
|
|
38
|
+
this.cdr = cdr;
|
|
39
|
+
/**
|
|
40
|
+
* 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 %})).
|
|
41
|
+
*
|
|
42
|
+
* @default false
|
|
43
|
+
*/
|
|
44
|
+
this.hint = false;
|
|
45
|
+
/**
|
|
46
|
+
* Defines the delay in milliseconds after which the drag will begin ([see example]({% slug drag_target_container_delay %})).
|
|
47
|
+
*
|
|
48
|
+
* @default 0
|
|
49
|
+
*/
|
|
50
|
+
this.dragDelay = 0;
|
|
51
|
+
/**
|
|
52
|
+
* The number of pixels the pointer moves in any direction before the dragging starts ([see example]({% slug drag_target_container_minimum_distance %})).
|
|
53
|
+
*
|
|
54
|
+
* @default 0
|
|
55
|
+
*/
|
|
56
|
+
this.threshold = 0;
|
|
57
|
+
/**
|
|
58
|
+
* Specifies whether the default dragging behavior will be performed or the developer will manually handle the drag action.
|
|
59
|
+
*
|
|
60
|
+
* @default 'auto'
|
|
61
|
+
*/
|
|
62
|
+
this.mode = 'auto';
|
|
63
|
+
/**
|
|
64
|
+
* Fires when a DragTarget's `dragDelay` has passed and the user is able to drag the element.
|
|
65
|
+
*/
|
|
66
|
+
this.dragReady = new EventEmitter();
|
|
67
|
+
/**
|
|
68
|
+
* Fires when the user presses a DragTarget element.
|
|
69
|
+
*/
|
|
70
|
+
this.press = new EventEmitter();
|
|
71
|
+
/**
|
|
72
|
+
* Fires when the dragging of a DragTarget element begins.
|
|
73
|
+
*/
|
|
74
|
+
this.dragStart = new EventEmitter();
|
|
75
|
+
/**
|
|
76
|
+
* Fires while the user drags a DragTarget element.
|
|
77
|
+
*/
|
|
78
|
+
this.drag = new EventEmitter();
|
|
79
|
+
/**
|
|
80
|
+
* Fires when the user releases a DragTarget element after being pressed.
|
|
81
|
+
*/
|
|
82
|
+
this.release = new EventEmitter();
|
|
83
|
+
/**
|
|
84
|
+
* Fires when the dragging of a DragTarget ends and the element is released.
|
|
85
|
+
*/
|
|
86
|
+
this.dragEnd = new EventEmitter();
|
|
87
|
+
this.currentDragTarget = null;
|
|
88
|
+
this.dragTimeout = null;
|
|
89
|
+
this.pressed = false;
|
|
90
|
+
this.dragStarted = false;
|
|
91
|
+
this.hintComponent = null;
|
|
92
|
+
this.defaultHint = null;
|
|
93
|
+
this.currentDragTargetElement = null;
|
|
94
|
+
this.scrollableParent = null;
|
|
95
|
+
this.previousDragTargets = [];
|
|
96
|
+
this.initialPosition = { x: 0, y: 0 };
|
|
97
|
+
this.position = { x: 0, y: 0 };
|
|
98
|
+
this.positionsMap = new Map();
|
|
99
|
+
this._dragTargetFilter = null;
|
|
100
|
+
this._dragDisabled = false;
|
|
101
|
+
this._dragData = () => null;
|
|
102
|
+
this._dragTargetId = () => null;
|
|
103
|
+
validatePackage(packageMetadata);
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Specifies a selector for elements within a container which will be configured as draggable
|
|
107
|
+
* ([see example]({% slug drag_target_container %})). The possible values include any
|
|
108
|
+
* DOM `selector`.
|
|
109
|
+
*/
|
|
110
|
+
set dragTargetFilter(value) {
|
|
111
|
+
this._dragTargetFilter = value;
|
|
112
|
+
if (!this.dragDisabled) {
|
|
113
|
+
this.initializeDragTargets();
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
get dragTargetFilter() {
|
|
117
|
+
return this._dragTargetFilter;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Defines a unique identifier for each drag target.
|
|
121
|
+
* It exposes the current DragTarget HTML element and its index in the collection of drag targets as arguments.
|
|
122
|
+
*/
|
|
123
|
+
set dragTargetId(fn) {
|
|
124
|
+
if (isDevMode && typeof fn !== 'function') {
|
|
125
|
+
throw new Error(`dragTargetId must be a function, but received ${JSON.stringify(fn)}.`);
|
|
126
|
+
}
|
|
127
|
+
this._dragTargetId = fn;
|
|
128
|
+
}
|
|
129
|
+
get dragTargetId() {
|
|
130
|
+
return this._dragTargetId;
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* Defines a callback function which returns custom data passed to the DropTarget events.
|
|
134
|
+
* It exposes the current DragTarget HTML element, its `dragTargetId` and its index in the collection of drag targets as arguments.
|
|
135
|
+
*/
|
|
136
|
+
set dragData(fn) {
|
|
137
|
+
if (isDevMode && typeof fn !== 'function') {
|
|
138
|
+
throw new Error(`dragData must be a function, but received ${JSON.stringify(fn)}.`);
|
|
139
|
+
}
|
|
140
|
+
this._dragData = fn;
|
|
141
|
+
}
|
|
142
|
+
get dragData() {
|
|
143
|
+
return this._dragData;
|
|
144
|
+
}
|
|
145
|
+
/**
|
|
146
|
+
* If set to true, the dragging of DragTargets within the container will be disabled.
|
|
147
|
+
*
|
|
148
|
+
* @default false
|
|
149
|
+
*/
|
|
150
|
+
set dragDisabled(value) {
|
|
151
|
+
this._dragDisabled = value;
|
|
152
|
+
if (value) {
|
|
153
|
+
this.clearPreviousTargets();
|
|
154
|
+
this.unsubscribe();
|
|
155
|
+
if (isPresent(this.hintElem)) {
|
|
156
|
+
this.destroyHint();
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
else {
|
|
160
|
+
if (isPresent(this.wrapper) || isPresent(this.currentDragTarget)) {
|
|
161
|
+
this.subscribe();
|
|
162
|
+
}
|
|
163
|
+
this.initializeDragTargets();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
get dragDisabled() {
|
|
167
|
+
return this._dragDisabled;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Used for notifying the DragTargetContainer that its content has changed.
|
|
171
|
+
*/
|
|
172
|
+
notify() {
|
|
173
|
+
this.cdr.detectChanges();
|
|
174
|
+
this.initializeDragTargets();
|
|
175
|
+
}
|
|
176
|
+
get allDragTargets() {
|
|
177
|
+
return this.queryHost(this.dragTargetFilter);
|
|
178
|
+
}
|
|
179
|
+
get dragHandles() {
|
|
180
|
+
return this.queryHost(this.dragHandle);
|
|
181
|
+
}
|
|
182
|
+
get hintTemplate() {
|
|
183
|
+
return isPresent(this.hint) && typeof this.hint === 'object' ? this.hint.hintTemplate : null;
|
|
184
|
+
}
|
|
185
|
+
ngAfterViewInit() {
|
|
186
|
+
const isTargetPresent = isPresent(this.wrapper) || isPresent(this.currentDragTarget);
|
|
187
|
+
if (!this.dragDisabled && isTargetPresent) {
|
|
188
|
+
this.subscribe();
|
|
189
|
+
}
|
|
190
|
+
!this.dragDisabled && this.initializeDragTargets();
|
|
191
|
+
}
|
|
192
|
+
onPointerDown(event) {
|
|
193
|
+
if (isPresent(this.dragHandles) && this.dragHandles.length && !this.isDragHandle(event.target)) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
const action = getAction(event, this.currentDragTarget);
|
|
197
|
+
this.service.handleDragAndDrop(action);
|
|
198
|
+
this.subscribe();
|
|
199
|
+
}
|
|
200
|
+
onPointerMove(event) {
|
|
201
|
+
event.preventDefault();
|
|
202
|
+
const action = getAction(event, this.currentDragTarget);
|
|
203
|
+
this.service.handleDragAndDrop(action);
|
|
204
|
+
}
|
|
205
|
+
onPointerUp(event) {
|
|
206
|
+
event.preventDefault();
|
|
207
|
+
const action = getAction(event, this.currentDragTarget);
|
|
208
|
+
this.service.handleDragAndDrop(action);
|
|
209
|
+
this.ngZone.runOutsideAngular(() => {
|
|
210
|
+
this.subscribe();
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
handlePress(event) {
|
|
214
|
+
if (this.dragDelay > 0) {
|
|
215
|
+
this.dragTimeout = window.setTimeout(() => {
|
|
216
|
+
this.pressed = true;
|
|
217
|
+
this.emitZoneAwareEvent('dragReady', event);
|
|
218
|
+
}, this.dragDelay);
|
|
219
|
+
}
|
|
220
|
+
else {
|
|
221
|
+
this.pressed = true;
|
|
222
|
+
}
|
|
223
|
+
const eventTarget = event.originalEvent.target;
|
|
224
|
+
this.currentDragTargetElement = closestBySelector(eventTarget, this.dragTargetFilter);
|
|
225
|
+
this.currentDragTarget.element = this.currentDragTargetElement;
|
|
226
|
+
this.service.dragIndex = this.getDragIndex();
|
|
227
|
+
this.scrollableParent = this.hintTemplate ? document.body : this.currentDragTargetElement ? getScrollableParent(this.currentDragTargetElement) : null;
|
|
228
|
+
this.emitZoneAwareEvent('press', event);
|
|
229
|
+
}
|
|
230
|
+
handleDragStart(event) {
|
|
231
|
+
if (!this.pressed) {
|
|
232
|
+
if (this.dragTimeout) {
|
|
233
|
+
window.clearTimeout(this.dragTimeout);
|
|
234
|
+
this.dragTimeout = null;
|
|
235
|
+
}
|
|
236
|
+
return;
|
|
237
|
+
}
|
|
238
|
+
isDragStartPrevented = this.emitZoneAwareEvent('dragStart', event).isDefaultPrevented();
|
|
239
|
+
if (isDragStartPrevented) {
|
|
240
|
+
return;
|
|
241
|
+
}
|
|
242
|
+
this.position = this.positionsMap.has(this.currentDragTargetElement) ? this.positionsMap.get(this.currentDragTargetElement) : { x: 0, y: 0 };
|
|
243
|
+
if (this.hint) {
|
|
244
|
+
this.createHint();
|
|
245
|
+
if (this.mode === 'auto') {
|
|
246
|
+
this.renderer.setStyle(this.currentDragTargetElement, 'opacity', '0.7');
|
|
247
|
+
}
|
|
248
|
+
}
|
|
249
|
+
else {
|
|
250
|
+
this.initialPosition = { x: event.clientX - this.position.x, y: event.clientY - this.position.y };
|
|
251
|
+
}
|
|
252
|
+
this.emitZoneAwareEvent('dragStart', event);
|
|
253
|
+
this.dragStarted = this.threshold === 0;
|
|
254
|
+
this.service.dragTarget = this.currentDragTarget;
|
|
255
|
+
this.service.dragTargetId = this.dragTargetId(this.currentDragTargetElement, this.service.dragIndex);
|
|
256
|
+
this.service.dragData = this.dragData(this.currentDragTargetElement, this.service.dragTargetId, this.service.dragIndex);
|
|
257
|
+
}
|
|
258
|
+
handleDrag(event) {
|
|
259
|
+
if (!this.pressed || isDragStartPrevented) {
|
|
260
|
+
return;
|
|
261
|
+
}
|
|
262
|
+
isDragPrevented = this.emitZoneAwareEvent('drag', event).isDefaultPrevented();
|
|
263
|
+
if (isDragPrevented) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (this.mode === 'auto') {
|
|
267
|
+
this.performDrag(event);
|
|
268
|
+
}
|
|
269
|
+
else {
|
|
270
|
+
this.dragStarted = true;
|
|
271
|
+
}
|
|
272
|
+
this.dragStarted && this.emitZoneAwareEvent('drag', event);
|
|
273
|
+
}
|
|
274
|
+
handleRelease(event) {
|
|
275
|
+
if (this.dragStarted) {
|
|
276
|
+
this.positionsMap.set(this.currentDragTargetElement, this.position);
|
|
277
|
+
}
|
|
278
|
+
if (this.dragTimeout) {
|
|
279
|
+
clearTimeout(this.dragTimeout);
|
|
280
|
+
this.dragTimeout = null;
|
|
281
|
+
this.pressed = false;
|
|
282
|
+
}
|
|
283
|
+
this.emitZoneAwareEvent('release', event);
|
|
284
|
+
}
|
|
285
|
+
handleDragEnd(event) {
|
|
286
|
+
if (!this.dragStarted) {
|
|
287
|
+
return;
|
|
288
|
+
}
|
|
289
|
+
if (this.mode === 'auto') {
|
|
290
|
+
const isDroppedOverParentTarget = isPresent(this.service.dropTarget) && !contains(this.service.dropTarget?.element, this.service.dragTarget?.element, true);
|
|
291
|
+
const elem = this.hint ? this.hintElem : this.currentDragTargetElement;
|
|
292
|
+
if (isDroppedOverParentTarget || this.service.dropTargets.length > 0 && isPresent(elem)) {
|
|
293
|
+
this.renderer.removeStyle(elem, 'transform');
|
|
294
|
+
setElementStyles(this.renderer, elem, {
|
|
295
|
+
transition: dragTargetTransition
|
|
296
|
+
});
|
|
297
|
+
this.positionsMap.delete(this.currentDragTargetElement);
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
if (this.hint && isPresent(this.hintElem)) {
|
|
301
|
+
this.destroyHint();
|
|
302
|
+
if (this.mode === 'auto') {
|
|
303
|
+
this.renderer.removeStyle(this.currentDragTargetElement, 'opacity');
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
this.service.dragTarget = null;
|
|
307
|
+
this.service.dragIndex = null;
|
|
308
|
+
this.currentDragTarget.element = null;
|
|
309
|
+
this.emitZoneAwareEvent('dragEnd', event);
|
|
310
|
+
if (isDragStartPrevented || isDragPrevented) {
|
|
311
|
+
return;
|
|
312
|
+
}
|
|
313
|
+
this.dragStarted = false;
|
|
314
|
+
}
|
|
315
|
+
get nativeElement() {
|
|
316
|
+
return this.wrapper.nativeElement;
|
|
317
|
+
}
|
|
318
|
+
get hintElem() {
|
|
319
|
+
return this.hintTemplate && isPresent(this.hintComponent) ? this.hintComponent.instance.element.nativeElement : this.defaultHint;
|
|
320
|
+
}
|
|
321
|
+
unsubscribe() {
|
|
322
|
+
if (this.pointerDownSubscription) {
|
|
323
|
+
this.pointerDownSubscription.unsubscribe();
|
|
324
|
+
}
|
|
325
|
+
if (this.pointerMoveSubscription) {
|
|
326
|
+
this.pointerMoveSubscription.unsubscribe();
|
|
327
|
+
}
|
|
328
|
+
if (this.pointerUpSubscription) {
|
|
329
|
+
this.pointerUpSubscription.unsubscribe();
|
|
330
|
+
}
|
|
331
|
+
if (this.scrollSubscription) {
|
|
332
|
+
this.scrollSubscription.unsubscribe();
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
subscribe() {
|
|
336
|
+
this.ngZone.runOutsideAngular(() => {
|
|
337
|
+
this.unsubscribe();
|
|
338
|
+
if (!(isDocumentAvailable() && isPresent(this.wrapper))) {
|
|
339
|
+
return;
|
|
340
|
+
}
|
|
341
|
+
const element = this.nativeElement;
|
|
342
|
+
if (this.service.pressed) {
|
|
343
|
+
const pointerMoveStreams = allPointerMoveEvents.map((ev) => fromEvent(document, ev));
|
|
344
|
+
const pointerUpStreams = allPointerUpEvents.map((ev) => fromEvent(document, ev));
|
|
345
|
+
this.pointerMoveSubscription = merge(...pointerMoveStreams)
|
|
346
|
+
.pipe(filter(() => this.dragTargetFilter !== ''))
|
|
347
|
+
.subscribe(e => this.onPointerMove(e));
|
|
348
|
+
this.pointerUpSubscription = merge(...pointerUpStreams)
|
|
349
|
+
.subscribe(e => this.onPointerUp(e));
|
|
350
|
+
if (isPresent(this.scrollableParent)) {
|
|
351
|
+
this.scrollSubscription = fromEvent(this.scrollableParent, 'scroll')
|
|
352
|
+
.subscribe(e => this.onPointerMove(e));
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
else {
|
|
356
|
+
const pointerDownStreams = allPointerDownEvents.map((ev) => fromEvent(element, ev));
|
|
357
|
+
this.pointerDownSubscription = merge(...pointerDownStreams)
|
|
358
|
+
.pipe(filter(() => this.dragTargetFilter !== ''))
|
|
359
|
+
.subscribe((e) => {
|
|
360
|
+
const filterElement = closestBySelector(e.target, this.dragTargetFilter);
|
|
361
|
+
if (filterElement) {
|
|
362
|
+
this.onPointerDown(e);
|
|
363
|
+
}
|
|
364
|
+
});
|
|
365
|
+
}
|
|
366
|
+
});
|
|
367
|
+
}
|
|
368
|
+
emitZoneAwareEvent(event, normalizedEvent) {
|
|
369
|
+
const eventProps = {
|
|
370
|
+
dragTarget: this.currentDragTargetElement,
|
|
371
|
+
dragEvent: normalizedEvent,
|
|
372
|
+
dragTargetIndex: this.service.dragIndex,
|
|
373
|
+
dragTargetId: this.dragTargetId(this.currentDragTargetElement, this.service.dragIndex)
|
|
374
|
+
};
|
|
375
|
+
if (this.hint && isPresent(this.hintElem)) {
|
|
376
|
+
eventProps.hintElement = this.hintElem;
|
|
377
|
+
}
|
|
378
|
+
let eventArgs;
|
|
379
|
+
switch (event) {
|
|
380
|
+
case 'dragReady':
|
|
381
|
+
eventArgs = new DragTargetDragReadyEvent(eventProps);
|
|
382
|
+
break;
|
|
383
|
+
case 'press':
|
|
384
|
+
eventArgs = new DragTargetPressEvent(eventProps);
|
|
385
|
+
break;
|
|
386
|
+
case 'dragStart':
|
|
387
|
+
eventArgs = new DragTargetDragStartEvent(eventProps);
|
|
388
|
+
break;
|
|
389
|
+
case 'drag':
|
|
390
|
+
eventArgs = new DragTargetDragEvent(eventProps);
|
|
391
|
+
break;
|
|
392
|
+
case 'release':
|
|
393
|
+
eventArgs = new DragTargetReleaseEvent(eventProps);
|
|
394
|
+
break;
|
|
395
|
+
case 'dragEnd':
|
|
396
|
+
eventArgs = new DragTargetDragEndEvent(eventProps);
|
|
397
|
+
break;
|
|
398
|
+
default:
|
|
399
|
+
break;
|
|
400
|
+
}
|
|
401
|
+
this.ngZone.run(() => {
|
|
402
|
+
this[event].emit(eventArgs);
|
|
403
|
+
});
|
|
404
|
+
return eventArgs;
|
|
405
|
+
}
|
|
406
|
+
createHint() {
|
|
407
|
+
if (!(isDocumentAvailable() && isPresent(this.wrapper))) {
|
|
408
|
+
return;
|
|
409
|
+
}
|
|
410
|
+
if (isPresent(this.hint) && typeof this.hint === 'object') {
|
|
411
|
+
if (isPresent(this.hint.hintTemplate)) {
|
|
412
|
+
this.createCustomHint();
|
|
413
|
+
}
|
|
414
|
+
else {
|
|
415
|
+
this.createDefaultHint();
|
|
416
|
+
}
|
|
417
|
+
}
|
|
418
|
+
else {
|
|
419
|
+
this.createDefaultHint();
|
|
420
|
+
}
|
|
421
|
+
this.currentDragTarget.hint = this.hintElem;
|
|
422
|
+
if (typeof this.hint === 'object' && isPresent(this.hint.appendTo)) {
|
|
423
|
+
this.hint.appendTo.element.nativeElement.appendChild(this.hintElem);
|
|
424
|
+
}
|
|
425
|
+
else {
|
|
426
|
+
document.body.appendChild(this.hintElem);
|
|
427
|
+
}
|
|
428
|
+
}
|
|
429
|
+
createDefaultHint() {
|
|
430
|
+
this.defaultHint = this.currentDragTargetElement.cloneNode(true);
|
|
431
|
+
if (typeof this.hint === 'object') {
|
|
432
|
+
if (isPresent(this.hint.hintClass)) {
|
|
433
|
+
const hintClasses = parseCSSClassNames(this.hint.hintClass);
|
|
434
|
+
hintClasses.forEach(className => this.renderer.addClass(this.defaultHint, className));
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
}
|
|
438
|
+
createCustomHint() {
|
|
439
|
+
if (isPresent(this.hint.appendTo)) {
|
|
440
|
+
this.hintComponent = this.hint.appendTo.createComponent(HintComponent);
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
this.hintComponent = this.viewContainer.createComponent(HintComponent);
|
|
444
|
+
}
|
|
445
|
+
this.hintComponent.instance.template = this.hintTemplate;
|
|
446
|
+
this.hintComponent.instance.directive = this;
|
|
447
|
+
this.hintComponent.instance.targetIndex = this.service.dragIndex;
|
|
448
|
+
this.hintComponent.instance.contextData = this.dragData(this.currentDragTargetElement, this.service.dragIndex);
|
|
449
|
+
this.hintComponent.changeDetectorRef.detectChanges();
|
|
450
|
+
}
|
|
451
|
+
destroyHint() {
|
|
452
|
+
if (isPresent(this.hintTemplate)) {
|
|
453
|
+
this.hintComponent.destroy();
|
|
454
|
+
this.hintComponent.changeDetectorRef.detectChanges();
|
|
455
|
+
this.hintComponent = null;
|
|
456
|
+
}
|
|
457
|
+
else {
|
|
458
|
+
document.body.removeChild(this.defaultHint);
|
|
459
|
+
this.defaultHint = null;
|
|
460
|
+
}
|
|
461
|
+
this.currentDragTarget.hint = null;
|
|
462
|
+
}
|
|
463
|
+
getDragIndex() {
|
|
464
|
+
return this.allDragTargets.indexOf(this.currentDragTargetElement);
|
|
465
|
+
}
|
|
466
|
+
initializeDragTargets() {
|
|
467
|
+
if (!isPresent(this.allDragTargets)) {
|
|
468
|
+
if (this.previousDragTargets.length > 0) {
|
|
469
|
+
this.clearPreviousTargets();
|
|
470
|
+
}
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
this.allDragTargets.forEach(dragTargetEl => {
|
|
474
|
+
const isDragTargetInitialized = this.service.dragTargets.find(dt => dt.element === dragTargetEl);
|
|
475
|
+
if (!isDragTargetInitialized) {
|
|
476
|
+
this.service.dragTargets.push({
|
|
477
|
+
element: dragTargetEl,
|
|
478
|
+
hint: null,
|
|
479
|
+
onPress: this.handlePress.bind(this),
|
|
480
|
+
onRelease: this.handleRelease.bind(this),
|
|
481
|
+
onDragStart: this.handleDragStart.bind(this),
|
|
482
|
+
onDrag: this.handleDrag.bind(this),
|
|
483
|
+
onDragEnd: this.handleDragEnd.bind(this)
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
});
|
|
487
|
+
if (this.previousDragTargets.length > 0) {
|
|
488
|
+
const dragTargetsToRemove = this.previousDragTargets.filter(dt => !this.allDragTargets.includes(dt));
|
|
489
|
+
dragTargetsToRemove.forEach(dragTarget => {
|
|
490
|
+
const idx = this.service.dragTargets.findIndex(serviceDragTarget => serviceDragTarget.element === dragTarget);
|
|
491
|
+
if (idx > -1) {
|
|
492
|
+
this.service.dragTargets.splice(idx, 1);
|
|
493
|
+
}
|
|
494
|
+
});
|
|
495
|
+
}
|
|
496
|
+
this.previousDragTargets = this.allDragTargets;
|
|
497
|
+
this.currentDragTarget = {
|
|
498
|
+
element: null,
|
|
499
|
+
hint: null,
|
|
500
|
+
onPress: this.handlePress.bind(this),
|
|
501
|
+
onRelease: this.handleRelease.bind(this),
|
|
502
|
+
onDragStart: this.handleDragStart.bind(this),
|
|
503
|
+
onDrag: this.handleDrag.bind(this),
|
|
504
|
+
onDragEnd: this.handleDragEnd.bind(this)
|
|
505
|
+
};
|
|
506
|
+
this.setCursorStyle();
|
|
507
|
+
}
|
|
508
|
+
isDragHandle(el) {
|
|
509
|
+
return this.dragHandles.some(dh => contains(dh, el, true));
|
|
510
|
+
}
|
|
511
|
+
setCursorStyle() {
|
|
512
|
+
if (!isDocumentAvailable()) {
|
|
513
|
+
return;
|
|
514
|
+
}
|
|
515
|
+
if (isPresent(this.dragHandles) && this.dragHandles.length > 0) {
|
|
516
|
+
this.dragHandles.forEach(handle => {
|
|
517
|
+
this.renderer.addClass(handle, 'k-cursor-pointer');
|
|
518
|
+
});
|
|
519
|
+
}
|
|
520
|
+
else {
|
|
521
|
+
this.allDragTargets.forEach(target => {
|
|
522
|
+
this.renderer.addClass(target, 'k-cursor-pointer');
|
|
523
|
+
});
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
queryHost(selector) {
|
|
527
|
+
if (isPresent(selector) && selector !== "") {
|
|
528
|
+
return Array.from(this.nativeElement.querySelectorAll(selector));
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
clearPreviousTargets() {
|
|
532
|
+
this.previousDragTargets.forEach(dragTarget => {
|
|
533
|
+
const idx = this.service.dragTargets.findIndex(serviceDragTarget => serviceDragTarget.element === dragTarget);
|
|
534
|
+
if (idx > -1) {
|
|
535
|
+
this.service.dragTargets.splice(idx, 1);
|
|
536
|
+
}
|
|
537
|
+
});
|
|
538
|
+
this.previousDragTargets = [];
|
|
539
|
+
}
|
|
540
|
+
performDrag(event) {
|
|
541
|
+
const elem = this.hint ? this.hintElem : this.currentDragTargetElement;
|
|
542
|
+
this.position = this.calculatePosition(elem, event);
|
|
543
|
+
const thresholdNotReached = Math.abs(this.position.x) < this.threshold && Math.abs(this.position.y) < this.threshold;
|
|
544
|
+
if (!this.dragStarted && thresholdNotReached) {
|
|
545
|
+
return;
|
|
546
|
+
}
|
|
547
|
+
if (!this.dragStarted && this.threshold > 0) {
|
|
548
|
+
this.dragStarted = true;
|
|
549
|
+
}
|
|
550
|
+
const styles = this.getStylesPerElement(elem);
|
|
551
|
+
setElementStyles(this.renderer, elem, styles);
|
|
552
|
+
}
|
|
553
|
+
calculatePosition(element, event) {
|
|
554
|
+
let position = null;
|
|
555
|
+
if (element === this.hintElem) {
|
|
556
|
+
position = { x: event.clientX, y: event.clientY };
|
|
557
|
+
}
|
|
558
|
+
else {
|
|
559
|
+
position = { x: event.clientX - this.initialPosition.x + event.scrollX, y: event.clientY - this.initialPosition.y + event.scrollY };
|
|
560
|
+
}
|
|
561
|
+
return position;
|
|
562
|
+
}
|
|
563
|
+
getStylesPerElement(element) {
|
|
564
|
+
if (element === this.hintElem) {
|
|
565
|
+
const hintCoordinates = { x: this.position.x - this.initialPosition.x, y: this.position.y - this.initialPosition.y };
|
|
566
|
+
return {
|
|
567
|
+
top: `${hintCoordinates.y}px`,
|
|
568
|
+
left: `${hintCoordinates.x}px`,
|
|
569
|
+
transition: 'none',
|
|
570
|
+
position: 'absolute',
|
|
571
|
+
zIndex: 1999
|
|
572
|
+
};
|
|
573
|
+
}
|
|
574
|
+
else {
|
|
575
|
+
const transform = `translate(${this.position.x}px, ${this.position.y}px)`;
|
|
576
|
+
return {
|
|
577
|
+
transform: transform,
|
|
578
|
+
transition: 'none'
|
|
579
|
+
};
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
}
|
|
583
|
+
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: i1.DragStateService }, { token: i0.ViewContainerRef }, { token: i0.ChangeDetectorRef }], target: i0.ɵɵFactoryTarget.Directive });
|
|
584
|
+
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 });
|
|
585
|
+
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.12", ngImport: i0, type: DragTargetContainerDirective, decorators: [{
|
|
586
|
+
type: Directive,
|
|
587
|
+
args: [{
|
|
588
|
+
selector: '[kendoDragTargetContainer]',
|
|
589
|
+
exportAs: 'kendoDragTargetContainer'
|
|
590
|
+
}]
|
|
591
|
+
}], ctorParameters: function () { return [{ type: i0.ElementRef }, { type: i0.NgZone }, { type: i0.Renderer2 }, { type: i1.DragStateService }, { type: i0.ViewContainerRef }, { type: i0.ChangeDetectorRef }]; }, propDecorators: { hint: [{
|
|
592
|
+
type: Input
|
|
593
|
+
}], dragTargetFilter: [{
|
|
594
|
+
type: Input
|
|
595
|
+
}], dragHandle: [{
|
|
596
|
+
type: Input
|
|
597
|
+
}], dragDelay: [{
|
|
598
|
+
type: Input
|
|
599
|
+
}], threshold: [{
|
|
600
|
+
type: Input
|
|
601
|
+
}], dragTargetId: [{
|
|
602
|
+
type: Input
|
|
603
|
+
}], dragData: [{
|
|
604
|
+
type: Input
|
|
605
|
+
}], dragDisabled: [{
|
|
606
|
+
type: Input
|
|
607
|
+
}], mode: [{
|
|
608
|
+
type: Input
|
|
609
|
+
}], dragReady: [{
|
|
610
|
+
type: Output
|
|
611
|
+
}], press: [{
|
|
612
|
+
type: Output
|
|
613
|
+
}], dragStart: [{
|
|
614
|
+
type: Output
|
|
615
|
+
}], drag: [{
|
|
616
|
+
type: Output
|
|
617
|
+
}], release: [{
|
|
618
|
+
type: Output
|
|
619
|
+
}], dragEnd: [{
|
|
620
|
+
type: Output
|
|
621
|
+
}] } });
|