@progress/kendo-angular-sortable 5.0.4-dev.202211170813 → 11.0.0-develop.79

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 (43) hide show
  1. package/NOTICE.txt +3 -3
  2. package/binding.directive.d.ts +1 -1
  3. package/data-event-args.interface.d.ts +1 -1
  4. package/data-events.d.ts +1 -1
  5. package/draggable-event.d.ts +1 -1
  6. package/draggable.directive.d.ts +1 -1
  7. package/{esm2015/binding.directive.js → esm2020/binding.directive.mjs} +7 -5
  8. package/{esm2015/data-event-args.interface.js → esm2020/data-event-args.interface.mjs} +1 -1
  9. package/{esm2015/data-events.js → esm2020/data-events.mjs} +1 -1
  10. package/{esm2015/draggable-event.js → esm2020/draggable-event.mjs} +1 -1
  11. package/{esm2015/draggable.directive.js → esm2020/draggable.directive.mjs} +6 -5
  12. package/{esm2015/main.js → esm2020/index.mjs} +1 -1
  13. package/{esm2015/item-template.directive.js → esm2020/item-template.directive.mjs} +8 -8
  14. package/{esm2015/navigate-event.js → esm2020/navigate-event.mjs} +1 -1
  15. package/{esm2015/package-metadata.js → esm2020/package-metadata.mjs} +3 -3
  16. package/{esm2015/preventable-event.js → esm2020/preventable-event.mjs} +1 -1
  17. package/{esm2015/kendo-angular-sortable.js → esm2020/progress-kendo-angular-sortable.mjs} +2 -2
  18. package/{esm2015/sortable-container.js → esm2020/sortable-container.mjs} +4 -4
  19. package/{esm2015/sortable-event-args.interface.js → esm2020/sortable-event-args.interface.mjs} +1 -1
  20. package/{esm2015/sortable-events.js → esm2020/sortable-events.mjs} +1 -1
  21. package/{esm2015/sortable.component.js → esm2020/sortable.component.mjs} +14 -14
  22. package/{esm2015/sortable.module.js → esm2020/sortable.module.mjs} +5 -5
  23. package/{esm2015/sortable.service.js → esm2020/sortable.service.mjs} +5 -5
  24. package/{esm2015/util.js → esm2020/util.mjs} +6 -3
  25. package/fesm2015/{kendo-angular-sortable.js → progress-kendo-angular-sortable.mjs} +42 -40
  26. package/fesm2020/progress-kendo-angular-sortable.mjs +1896 -0
  27. package/{main.d.ts → index.d.ts} +1 -1
  28. package/item-template.directive.d.ts +1 -1
  29. package/navigate-event.d.ts +1 -1
  30. package/package-metadata.d.ts +1 -1
  31. package/package.json +28 -54
  32. package/preventable-event.d.ts +1 -1
  33. package/{kendo-angular-sortable.d.ts → progress-kendo-angular-sortable.d.ts} +2 -2
  34. package/schematics/ngAdd/index.js +1 -5
  35. package/sortable-container.d.ts +1 -1
  36. package/sortable-event-args.interface.d.ts +1 -1
  37. package/sortable-events.d.ts +1 -1
  38. package/sortable.component.d.ts +1 -1
  39. package/sortable.module.d.ts +1 -1
  40. package/sortable.service.d.ts +1 -1
  41. package/util.d.ts +1 -1
  42. package/bundles/kendo-angular-sortable.umd.js +0 -5
  43. package/schematics/ngAdd/index.js.map +0 -1
@@ -0,0 +1,1896 @@
1
+ /**-----------------------------------------------------------------------------------------
2
+ * Copyright © 2022 Progress Software Corporation. All rights reserved.
3
+ * Licensed under commercial license. See LICENSE.md in the project root for more information
4
+ *-------------------------------------------------------------------------------------------*/
5
+ import * as i0 from '@angular/core';
6
+ import { Injectable, Directive, Input, HostBinding, EventEmitter, forwardRef, TemplateRef, Component, ContentChildren, ViewChildren, ViewChild, Output, NgModule } from '@angular/core';
7
+ import { Subject, merge } from 'rxjs';
8
+ import { isDocumentAvailable, isChanged } from '@progress/kendo-angular-common';
9
+ import { filter, tap, take, switchMap } from 'rxjs/operators';
10
+ import * as i1 from '@progress/kendo-angular-l10n';
11
+ import { LocalizationService, L10N_PREFIX } from '@progress/kendo-angular-l10n';
12
+ import { validatePackage } from '@progress/kendo-licensing';
13
+ import { Draggable } from '@progress/kendo-draggable';
14
+ import * as i3 from '@angular/common';
15
+ import { CommonModule } from '@angular/common';
16
+
17
+ const NODE_NAME_PREDICATES = {};
18
+ const NODE_ATTR_PREDICATES = {};
19
+ const focusableRegex = /^(?:a|input|select|option|textarea|button|object)$/i;
20
+ /**
21
+ * @hidden
22
+ */
23
+ const matchesNodeName = (nodeName) => {
24
+ if (!NODE_NAME_PREDICATES[nodeName]) {
25
+ NODE_NAME_PREDICATES[nodeName] = (element) => String(element.nodeName).toLowerCase() === nodeName.toLowerCase();
26
+ }
27
+ return NODE_NAME_PREDICATES[nodeName];
28
+ };
29
+ /**
30
+ * @hidden
31
+ */
32
+ const matchesNodeAttr = (nodeAttr) => {
33
+ if (!NODE_ATTR_PREDICATES[nodeAttr]) {
34
+ NODE_ATTR_PREDICATES[nodeAttr] = (element) => element.hasAttribute ? element.hasAttribute(nodeAttr) : false;
35
+ }
36
+ return NODE_ATTR_PREDICATES[nodeAttr];
37
+ };
38
+ /**
39
+ * @hidden
40
+ */
41
+ const closest = (node, predicate) => {
42
+ while (node && !predicate(node)) {
43
+ node = node.parentNode;
44
+ }
45
+ return node;
46
+ };
47
+ /**
48
+ * Returns an object specifiying whether there is a DraggableDirective under the cursor.
49
+ * @hidden
50
+ */
51
+ const draggableFromPoint = (x, y) => {
52
+ if (!isDocumentAvailable()) {
53
+ return;
54
+ }
55
+ const el = document.elementFromPoint(x, y);
56
+ if (!el) {
57
+ return;
58
+ }
59
+ const isDraggable = el.hasAttribute("kendoDraggable");
60
+ const isChild = closest(el, matchesNodeAttr("kendoDraggable")) !== null;
61
+ const parentDraggable = closest(el, matchesNodeAttr("kendoDraggable"));
62
+ const index = parentDraggable ? parseInt(parentDraggable.getAttribute("data-sortable-index"), 10) : -1;
63
+ return {
64
+ element: el,
65
+ index: index,
66
+ isDraggable: isDraggable,
67
+ isDraggableChild: isChild,
68
+ parentDraggable: parentDraggable,
69
+ rect: el.getBoundingClientRect()
70
+ };
71
+ };
72
+ /**
73
+ * Returns the DraggableDirective under the cursor.
74
+ * @hidden
75
+ */
76
+ const draggableFromEvent = (event, sortable) => {
77
+ let target;
78
+ if (event.changedTouches) {
79
+ const touch = event.changedTouches[0];
80
+ target = draggableFromPoint(touch.clientX, touch.clientY);
81
+ }
82
+ else {
83
+ target = draggableFromPoint(event.clientX, event.clientY);
84
+ }
85
+ // TODO: refactor sortable. Add draggable getter
86
+ return sortable.draggables.toArray()[target ? target.index : -1];
87
+ };
88
+ /**
89
+ * @hidden
90
+ */
91
+ const isFocusable = (element) => {
92
+ if (element.tagName) {
93
+ const tagName = element.tagName.toLowerCase();
94
+ const tabIndex = element.getAttribute('tabIndex');
95
+ const skipTab = tabIndex === '-1';
96
+ let focusable = tabIndex !== null && !skipTab;
97
+ if (focusableRegex.test(tagName)) {
98
+ focusable = !element.disabled && !skipTab;
99
+ }
100
+ return focusable;
101
+ }
102
+ return false;
103
+ };
104
+ const toClassList = (classNames) => String(classNames).trim().split(' ');
105
+ /**
106
+ * @hidden
107
+ */
108
+ const hasClasses = (element, classNames) => {
109
+ const namesList = toClassList(classNames);
110
+ return Boolean(toClassList(element.className).find((className) => namesList.indexOf(className) >= 0));
111
+ };
112
+ const isSortable = matchesNodeName('kendo-sortable');
113
+ /**
114
+ * @hidden
115
+ */
116
+ const widgetTarget = (target) => {
117
+ const element = closest(target, node => hasClasses(node, 'k-widget') || isSortable(node));
118
+ return element && !isSortable(element);
119
+ };
120
+ const hasRelativeStackingContext = () => {
121
+ if (!isDocumentAvailable()) {
122
+ return false;
123
+ }
124
+ const top = 10;
125
+ const parent = document.createElement("div");
126
+ parent.style.transform = "matrix(10, 0, 0, 10, 0, 0)";
127
+ const innerDiv = document.createElement('div');
128
+ innerDiv.style.position = 'fixed';
129
+ innerDiv.style.top = `${top}px;`;
130
+ parent.appendChild(innerDiv);
131
+ document.body.appendChild(parent);
132
+ const isDifferent = parent.children[0].getBoundingClientRect().top !== top;
133
+ document.body.removeChild(parent);
134
+ return isDifferent;
135
+ };
136
+ const HAS_RELATIVE_STACKING_CONTEXT = hasRelativeStackingContext();
137
+ /**
138
+ * @hidden
139
+ */
140
+ const relativeContextElement = (element) => {
141
+ if (!element || !HAS_RELATIVE_STACKING_CONTEXT) {
142
+ return null;
143
+ }
144
+ let node = element.parentElement;
145
+ while (node) {
146
+ if (window.getComputedStyle(node).transform !== 'none') {
147
+ return node;
148
+ }
149
+ node = node.parentElement;
150
+ }
151
+ };
152
+
153
+ /**
154
+ * @hidden
155
+ */
156
+ const packageMetadata = {
157
+ name: '@progress/kendo-angular-sortable',
158
+ productName: 'Kendo UI for Angular',
159
+ productCodes: ['KENDOUIANGULAR', 'KENDOUICOMPLETE'],
160
+ publishDate: 1672320723,
161
+ version: '',
162
+ licensingDocsUrl: 'https://www.telerik.com/kendo-angular-ui/my-license/'
163
+ };
164
+
165
+ const allowDrag = (e) => {
166
+ const target = e.originalEvent.target;
167
+ return target.hasAttribute('data-sortable-item') || !(isFocusable(target) || widgetTarget(target));
168
+ };
169
+ /**
170
+ * The service that provides the drag-and-drop functionality for
171
+ * transferring items between Sortable components within the same page.
172
+ *
173
+ */
174
+ class SortableService {
175
+ constructor(ngZone) {
176
+ this.ngZone = ngZone;
177
+ /**
178
+ * Specifies the Draggable item that is currently being moved.
179
+ */
180
+ this.activeDraggable = null;
181
+ /**
182
+ * Specifies the Draggable item from which the dragging started.
183
+ */
184
+ this.originDraggable = null;
185
+ /**
186
+ * @hidden
187
+ */
188
+ this.targetSortable = null;
189
+ /**
190
+ * Specifies the Draggable item that last emitted an event.
191
+ */
192
+ this.lastDraggable = null;
193
+ /**
194
+ * @hidden
195
+ */
196
+ this.onPressSubject = new Subject();
197
+ /**
198
+ * @hidden
199
+ */
200
+ this.onDragSubject = new Subject();
201
+ /**
202
+ * @hidden
203
+ */
204
+ this.onReleaseSubject = new Subject();
205
+ this.source = null;
206
+ this._target = null;
207
+ this.sortableCounter = 0;
208
+ this.sortableRegister = {};
209
+ if (!isDocumentAvailable()) {
210
+ return;
211
+ }
212
+ this.subscriptions = this.onPressSubject.pipe(filter(allowDrag), tap(press => {
213
+ this.targetSortable = this.getSortableComponentFromTouch(press);
214
+ }), filter(_ => Boolean(this.targetSortable)), tap(press => {
215
+ this.onReleaseSubject.pipe(take(1)).subscribe(event => this.release(event));
216
+ this.pressArgs = press;
217
+ if (press.isTouch) {
218
+ press.originalEvent.preventDefault();
219
+ }
220
+ }), switchMap(_drag => this.onDragSubject.pipe(filter(_ => Boolean(this.targetSortable)), //stop further events if dragStart is prevented
221
+ tap((e) => this.drag(e))))).subscribe();
222
+ }
223
+ /**
224
+ * Specifies the `SortableComponent` instance under the currently dragged item.
225
+ */
226
+ set target(target) {
227
+ this._target = target;
228
+ }
229
+ get target() {
230
+ return this._target;
231
+ }
232
+ /**
233
+ * @hidden
234
+ */
235
+ onPress(e) {
236
+ this.onPressSubject.next(e);
237
+ }
238
+ /**
239
+ * @hidden
240
+ */
241
+ onDrag(e) {
242
+ this.onDragSubject.next(e);
243
+ }
244
+ /**
245
+ * @hidden
246
+ */
247
+ onRelease(e) {
248
+ this.onReleaseSubject.next(e);
249
+ }
250
+ /**
251
+ * @hidden
252
+ */
253
+ ngOnDestroy() {
254
+ if (this.subscriptions) {
255
+ this.subscriptions.unsubscribe();
256
+ }
257
+ }
258
+ /**
259
+ * Registers a `SortableComponent` with which the service operates.
260
+ *
261
+ * @param sortableComponent - The `SortableComponent`.
262
+ * @return - The unique key that the current `SortableComponent` gets when registered.
263
+ */
264
+ registerComponent(sortableComponent) {
265
+ const id = this.sortableCounter.toString();
266
+ this.sortableRegister[id] = sortableComponent;
267
+ this.sortableCounter++;
268
+ return id;
269
+ }
270
+ /**
271
+ * Removes a `SortableComponent` from the registered `SortableComponents` with which the service operates.
272
+ *
273
+ * @param key - The key of the `SortableComponent` which will be removed from the register.
274
+ * Obtained when `registerComponent` is called.
275
+ */
276
+ unregisterComponent(key) {
277
+ this.sortableRegister[key] = null;
278
+ }
279
+ /**
280
+ * Sets the `SortableComponent` as a source component. When dragging an item from one Sortable to another,
281
+ * the source component is the one from which the item originates.
282
+ *
283
+ * @param sortable - The `SortableComponent`.
284
+ */
285
+ setSource(sortable) {
286
+ this.source = sortable;
287
+ }
288
+ /**
289
+ * Returns the source `SortableComponent` from which
290
+ * an item is dragged to other Sortable components.
291
+ *
292
+ * @return - The `SourceComponent`.
293
+ */
294
+ getSource() {
295
+ return this.source;
296
+ }
297
+ /**
298
+ * The method that finds the `SortableComponent` which is registered to
299
+ * the `SortableService` by using the arguments of the `touch` event.
300
+ *
301
+ * @param touch - A Touch-Object of the `Touch` type interface.
302
+ * Represents a single contact point (finger or stylus)
303
+ * on a touch-sensitive device (touchscreen or trackpad).
304
+ *
305
+ * @return { component: SortableComponent, index: number } - An object
306
+ * where the component is the `SortableComponent` that owns the item
307
+ * and the index is the index of the touched item.
308
+ */
309
+ getSortableComponentFromTouch(touch) {
310
+ if (!isDocumentAvailable()) {
311
+ return { component: undefined, index: undefined };
312
+ }
313
+ let realTarget = document.elementFromPoint(touch.clientX, touch.clientY);
314
+ while (realTarget) {
315
+ const id = realTarget.getAttribute('data-sortable-id');
316
+ const index = realTarget.getAttribute('data-sortable-index');
317
+ if (id) {
318
+ const targetSortable = this.sortableRegister[id];
319
+ if (targetSortable) {
320
+ return { component: targetSortable, index: parseInt(index, 10) };
321
+ }
322
+ }
323
+ realTarget = realTarget.parentElement;
324
+ }
325
+ }
326
+ start() {
327
+ const pressArgs = this.pressArgs;
328
+ if (pressArgs) {
329
+ this.pressArgs = null;
330
+ const startTarget = draggableFromEvent(pressArgs, this.targetSortable.component);
331
+ if (this.targetSortable.component.startDrag({ target: startTarget, originalEvent: pressArgs })) {
332
+ this.targetSortable = null;
333
+ return true;
334
+ }
335
+ }
336
+ }
337
+ release(event) {
338
+ if (this.source) {
339
+ this.ngZone.run(() => {
340
+ if (this.targetSortable) {
341
+ const dropTarget = draggableFromEvent(event, this.targetSortable.component);
342
+ this.source.endDrag({ target: dropTarget, originalEvent: event });
343
+ }
344
+ this.source.positionHintFromEvent(null);
345
+ this.source.markForCheck();
346
+ });
347
+ }
348
+ this.targetSortable = null;
349
+ this.pressArgs = null;
350
+ }
351
+ drag(event) {
352
+ this.ngZone.run(() => {
353
+ if (this.start()) {
354
+ return;
355
+ }
356
+ this.source.positionHintFromEvent(event);
357
+ const sortable = this.getSortableComponentFromTouch(event);
358
+ if (!sortable || sortable && sortable.component !== this.target) {
359
+ if (this.target) {
360
+ this.target.leave({ target: undefined, originalEvent: event });
361
+ }
362
+ else if (this.source !== this.target) {
363
+ this.source.leave({ target: undefined, originalEvent: event });
364
+ }
365
+ }
366
+ if (sortable && sortable.component) {
367
+ const draggable = draggableFromEvent(event, sortable.component);
368
+ sortable.component.drag({ target: draggable, originalEvent: event });
369
+ }
370
+ this.source.markForCheck();
371
+ });
372
+ }
373
+ }
374
+ SortableService.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableService, deps: [{ token: i0.NgZone }], target: i0.ɵɵFactoryTarget.Injectable });
375
+ SortableService.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableService });
376
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableService, decorators: [{
377
+ type: Injectable
378
+ }], ctorParameters: function () { return [{ type: i0.NgZone }]; } });
379
+
380
+ /**
381
+ * @hidden
382
+ */
383
+ class SortableContainer {
384
+ }
385
+ SortableContainer.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableContainer, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
386
+ SortableContainer.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableContainer });
387
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableContainer, decorators: [{
388
+ type: Injectable
389
+ }] });
390
+
391
+ /**
392
+ * @hidden
393
+ */
394
+ class DraggableDirective {
395
+ constructor(parent, el, renderer) {
396
+ this.parent = parent;
397
+ this.el = el;
398
+ this.renderer = renderer;
399
+ }
400
+ set hidden(value) {
401
+ this._hidden = value;
402
+ this.updateDisplayStyle();
403
+ }
404
+ ;
405
+ get hidden() {
406
+ return this._hidden;
407
+ }
408
+ get _focused() {
409
+ return this.disabled ? false : (this.index === this.parent.activeIndex);
410
+ }
411
+ get _disabled() {
412
+ return this.disabled;
413
+ }
414
+ get display() {
415
+ return this.hidden ? "none" : this._display;
416
+ }
417
+ set display(display) {
418
+ this._display = display;
419
+ this.updateDisplayStyle();
420
+ }
421
+ ngOnInit() {
422
+ const nativeElement = this.el.nativeElement;
423
+ this.display = nativeElement.style.display;
424
+ if (nativeElement) { // Remove the inline styles after a few releases of the themes with the style.
425
+ this.renderer.setStyle(nativeElement, 'user-select', 'none');
426
+ this.renderer.setStyle(nativeElement, '-ms-user-select', 'none');
427
+ this.renderer.setStyle(nativeElement, '-moz-user-select', 'none');
428
+ this.renderer.setStyle(nativeElement, '-webkit-user-select', 'none');
429
+ }
430
+ }
431
+ updateDisplayStyle() {
432
+ this.renderer.setStyle(this.el.nativeElement, 'display', this.display);
433
+ }
434
+ }
435
+ DraggableDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: DraggableDirective, deps: [{ token: SortableContainer }, { token: i0.ElementRef }, { token: i0.Renderer2 }], target: i0.ɵɵFactoryTarget.Directive });
436
+ DraggableDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.11", type: DraggableDirective, selector: "[kendoDraggable]", inputs: { index: "index", disabled: "disabled", hidden: "hidden" }, host: { properties: { "class.k-focus": "this._focused", "attr.aria-disabled": "this._disabled" } }, ngImport: i0 });
437
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: DraggableDirective, decorators: [{
438
+ type: Directive,
439
+ args: [{
440
+ selector: '[kendoDraggable]'
441
+ }]
442
+ }], ctorParameters: function () { return [{ type: SortableContainer }, { type: i0.ElementRef }, { type: i0.Renderer2 }]; }, propDecorators: { index: [{
443
+ type: Input
444
+ }], disabled: [{
445
+ type: Input
446
+ }], hidden: [{
447
+ type: Input
448
+ }], _focused: [{
449
+ type: HostBinding,
450
+ args: ['class.k-focus']
451
+ }], _disabled: [{
452
+ type: HostBinding,
453
+ args: ['attr.aria-disabled']
454
+ }] } });
455
+
456
+ //TODO: RENAME FILE AND UPDATE EXPORTS AND MODULES
457
+ /**
458
+ * @hidden
459
+ */
460
+ class ItemTemplateDirective {
461
+ constructor(templateRef) {
462
+ this.templateRef = templateRef;
463
+ }
464
+ }
465
+ ItemTemplateDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: ItemTemplateDirective, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
466
+ ItemTemplateDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.11", type: ItemTemplateDirective, selector: "[kendoSortableItemTemplate]", ngImport: i0 });
467
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: ItemTemplateDirective, decorators: [{
468
+ type: Directive,
469
+ args: [{
470
+ selector: '[kendoSortableItemTemplate]'
471
+ }]
472
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; } });
473
+ /**
474
+ * @hidden
475
+ */
476
+ class PlaceholderTemplateDirective {
477
+ constructor(templateRef) {
478
+ this.templateRef = templateRef;
479
+ }
480
+ }
481
+ PlaceholderTemplateDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PlaceholderTemplateDirective, deps: [{ token: i0.TemplateRef }], target: i0.ɵɵFactoryTarget.Directive });
482
+ PlaceholderTemplateDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.11", type: PlaceholderTemplateDirective, selector: "[kendoSortablePlaceholderTemplate]", ngImport: i0 });
483
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: PlaceholderTemplateDirective, decorators: [{
484
+ type: Directive,
485
+ args: [{
486
+ selector: '[kendoSortablePlaceholderTemplate]'
487
+ }]
488
+ }], ctorParameters: function () { return [{ type: i0.TemplateRef }]; } });
489
+
490
+ /**
491
+ * Defines an event whose default action can be prevented
492
+ * by calling the `preventDefault` method.
493
+ *
494
+ * @hidden
495
+ */
496
+ class PreventableEvent {
497
+ constructor() {
498
+ this.prevented = false;
499
+ }
500
+ /**
501
+ * Prevents the default action for a specified event.
502
+ * In this way, the source component suppresses
503
+ * the built-in behavior that follows the event.
504
+ */
505
+ preventDefault() {
506
+ this.prevented = true;
507
+ }
508
+ /**
509
+ * If the event was prevented
510
+ * by any of its subscribers, returns `true`.
511
+ *
512
+ * @returns `true` if the default action was prevented. Otherwise, returns `false`.
513
+ */
514
+ isDefaultPrevented() {
515
+ return this.prevented;
516
+ }
517
+ }
518
+
519
+ /**
520
+ * The `navigate` event is emitted when using the keyboard arrows.
521
+ */
522
+ class NavigateEvent extends PreventableEvent {
523
+ /**
524
+ * @hidden
525
+ */
526
+ constructor(options) {
527
+ super();
528
+ Object.assign(this, options);
529
+ }
530
+ }
531
+
532
+ /**
533
+ * The arguments for the `DraggableDirective` events.
534
+ * @hidden
535
+ */
536
+ class DraggableEvent extends PreventableEvent {
537
+ /**
538
+ * @hidden
539
+ */
540
+ constructor(options) {
541
+ super();
542
+ Object.assign(this, options);
543
+ }
544
+ }
545
+
546
+ /**
547
+ * Arguments for the `dragStart` event.
548
+ */
549
+ class DragStartEvent extends PreventableEvent {
550
+ /**
551
+ * @hidden
552
+ */
553
+ constructor(options) {
554
+ super();
555
+ Object.assign(this, options);
556
+ }
557
+ }
558
+ /**
559
+ * Arguments for the `dragOver` event.
560
+ */
561
+ class DragOverEvent extends DragStartEvent {
562
+ /**
563
+ * @hidden
564
+ */
565
+ constructor(options) {
566
+ super(options);
567
+ Object.assign(this, options);
568
+ }
569
+ }
570
+ /**
571
+ * Arguments for the `dragEnd` event.
572
+ */
573
+ class DragEndEvent extends DragOverEvent {
574
+ /**
575
+ * @hidden
576
+ */
577
+ constructor(options) {
578
+ super(options);
579
+ Object.assign(this, options);
580
+ }
581
+ }
582
+
583
+ /**
584
+ * Represents the [Kendo UI Sortable component for Angular]({% slug overview_sortable %}).
585
+ *
586
+ * {% meta height:430 %}
587
+ * {% embed_file sortable-api/app.component.ts %}
588
+ * {% embed_file shared/app.module.ts preview %}
589
+ * {% embed_file shared/main.ts hidden %}
590
+ * {% endmeta %}
591
+ */
592
+ /**
593
+ * Represents the Kendo UI Sortable component for Angular.
594
+ */
595
+ class SortableComponent {
596
+ constructor(ngZone, localization, changeDetector, wrapper, sortableService) {
597
+ this.ngZone = ngZone;
598
+ this.localization = localization;
599
+ this.changeDetector = changeDetector;
600
+ /**
601
+ * Specifies the tab index of the Sortable component.
602
+ */
603
+ this.tabIndex = null;
604
+ /**
605
+ * Enables or disables the [keyboard navigation]({% slug keyboard_navigation_sortable %}).
606
+ * The default value is `false`.
607
+ */
608
+ this.navigable = false;
609
+ /**
610
+ * Enables or disables the built-in animations.
611
+ * The default value is `false`.
612
+ */
613
+ this.animation = false;
614
+ /**
615
+ * Sets an array of integers, which represent the indexes of the disabled items from the data array
616
+ * ([see example]({% slug items_sortable %}#toc-disabled-items)).
617
+ */
618
+ this.disabledIndexes = [];
619
+ /**
620
+ * Sets a string that represents the name of the zone to which the Sortable belongs
621
+ * ([see example]({% slug items_sortable %}#toc-transfer-of-items)). Items can be transferred
622
+ * between Sortables which belong to the same zone.
623
+ */
624
+ this.zone = undefined;
625
+ /**
626
+ * Defines the zones from which items can be transferred onto the current Sortable component
627
+ * ([see example]({% slug items_sortable %}#toc-transfer-of-items)). If the `acceptZones` property
628
+ * of the target Sortable is set, allows you to transfer items between Sortables which belong
629
+ * to different zones.
630
+ */
631
+ this.acceptZones = undefined;
632
+ /**
633
+ * Represents the CSS styles which are applied to each Sortable item.
634
+ *
635
+ * @example
636
+ * ```ts
637
+ * import { Component } from '@angular/core';
638
+ * import { SortableModule } from '@progress/kendo-angular-sortable';
639
+ *
640
+ * _@Component({
641
+ * selector: 'my-app',
642
+ * template: `
643
+ * <kendo-sortable
644
+ * [data]="['1','2','3','4','5','6','7']"
645
+ * [itemStyle] ="{
646
+ * 'display': 'inline-block',
647
+ * 'background-color': '#51A0ED',
648
+ * 'height':'50px',
649
+ * 'width':'50px',
650
+ * 'margin':'3px',
651
+ * 'cursor':'move'
652
+ * }"
653
+ * >
654
+ * </kendo-sortable>
655
+ * `
656
+ * })
657
+ * export class AppComponent {
658
+ * }
659
+ * ```
660
+ */
661
+ this.itemStyle = {};
662
+ /**
663
+ * Defines the CSS styles applied to an empty item ([see example]({% slug templates_sortable %})).
664
+ */
665
+ this.emptyItemStyle = undefined;
666
+ /**
667
+ * Defines the CSS styles which are applied to the currently dragged item ([see example]({% slug templates_sortable %})).
668
+ */
669
+ this.activeItemStyle = undefined;
670
+ /**
671
+ * Defines the CSS styles which are applied to all disabled items.
672
+ */
673
+ this.disabledItemStyle = undefined;
674
+ /**
675
+ * Defines the class which is applied to each Sortable item.
676
+ */
677
+ this.itemClass = "";
678
+ /**
679
+ * Defines the class which is applied to the active Sortable item.
680
+ */
681
+ this.activeItemClass = null;
682
+ /**
683
+ * Defines the class which is applied to the empty item when the Sortable has empty data.
684
+ */
685
+ this.emptyItemClass = null;
686
+ /**
687
+ * Defines the class which is applied to each disabled Sortable item.
688
+ */
689
+ this.disabledItemClass = null;
690
+ /**
691
+ * Sets the text message that will be displayed when the Sortable has no items.
692
+ *
693
+ * @example
694
+ * ```ts
695
+ * import { Component } from '@angular/core';
696
+ * import { SortableModule } from '@progress/kendo-angular-sortable';
697
+ *
698
+ * _@Component({
699
+ * selector: 'my-app',
700
+ * template: `
701
+ * <kendo-sortable [data]="[]"
702
+ * [emptyText]="'No items - custom message and styles'"
703
+ * [emptyItemStyle] = "{'height': '40px', 'width':'400px', 'border': '2px dashed black'}" >
704
+ * </kendo-sortable>
705
+ * `
706
+ * })
707
+ * export class AppComponent { }
708
+ * ```
709
+ */
710
+ this.emptyText = "Empty";
711
+ /**
712
+ * @hidden
713
+ */
714
+ this.defaultTemplateRef = null;
715
+ /**
716
+ * Defines the template that will be used for rendering the items.
717
+ * @hidden
718
+ */
719
+ this.itemTemplateDirectiveRef = null;
720
+ /**
721
+ * Defines the template that will be used for rendering the placeholder.
722
+ * @hidden
723
+ */
724
+ this.placeholderTemplateDirectiveRef = null;
725
+ this.itemWrappers = null;
726
+ /**
727
+ * Fires when the dragging of an item is started.
728
+ */
729
+ this.dragStart = new EventEmitter();
730
+ /**
731
+ * Fires when the dragging of an item is completed.
732
+ */
733
+ this.dragEnd = new EventEmitter();
734
+ /**
735
+ * Fires while the dragging of an item is in progress.
736
+ */
737
+ this.dragOver = new EventEmitter();
738
+ /**
739
+ * Fires when dragging an item outside of the component.
740
+ */
741
+ this.dragLeave = new EventEmitter();
742
+ /**
743
+ * Fires while the moving an item from one position to another.
744
+ */
745
+ this.dataMove = new EventEmitter();
746
+ /**
747
+ * Fires when a new item is added to the Sortable.
748
+ */
749
+ this.dataAdd = new EventEmitter();
750
+ /**
751
+ * Fires when an item is removed from the Sortable.
752
+ */
753
+ this.dataRemove = new EventEmitter();
754
+ /**
755
+ * Fires when navigating using the keyboard.
756
+ */
757
+ this.navigate = new EventEmitter();
758
+ /**
759
+ * The index of the currently focused item.
760
+ * If no item is focused, set to `-1`.
761
+ */
762
+ this.activeIndex = -1;
763
+ /**
764
+ * Flag indicating if the component is currently playing animations.
765
+ * @hidden
766
+ */
767
+ this.animating = false;
768
+ /**
769
+ * The index of the currently dragged item.
770
+ */
771
+ this.dragIndex = -1;
772
+ /**
773
+ * The index of the item above which the dragged item is.
774
+ */
775
+ this.dragOverIndex = -1;
776
+ this.onDragStartSubject = new Subject();
777
+ this.onDragOverSubject = new Subject();
778
+ this.onDragLeaveSubject = new Subject();
779
+ this.onDragEndSubject = new Subject();
780
+ /**
781
+ * The location of the hint indicator when dragging on mobile devices.
782
+ */
783
+ this.hintLocation = null;
784
+ this._localData = [];
785
+ this.animationDuration = 300;
786
+ this.afterKeyPress = false;
787
+ this.sortableService = null;
788
+ this._hideActiveItem = false;
789
+ validatePackage(packageMetadata);
790
+ this.wrapper = wrapper.nativeElement;
791
+ this.direction = localization.rtl ? 'rtl' : 'ltr';
792
+ this.sortableService = sortableService;
793
+ this.subscribeEvents();
794
+ }
795
+ /**
796
+ * Sets an array of any data that is used as a data source for the Sortable.
797
+ * {% meta height:430 %}
798
+ * {% embed_file sortable-palettes/app.component.ts %}
799
+ * {% embed_file shared/app.module.ts %}
800
+ * {% embed_file shared/main.ts hidden %}
801
+ * {% endmeta %}
802
+ */
803
+ set data(data) {
804
+ this._data = data;
805
+ //Cache each _data item instance locally to avoid repaint due to the ngTemplateOutletContext (generated by itemData)
806
+ //This prevents destroying the kendoDraggable instance, which otherwise leads to losing the dragEnd event
807
+ //due to non-exisitng HTML element
808
+ this.cacheData();
809
+ }
810
+ get data() {
811
+ return this._data;
812
+ }
813
+ /**
814
+ * @hidden
815
+ *
816
+ * A misspelled alias for `navigable`.
817
+ */
818
+ set navigatable(value) {
819
+ this.navigable = value;
820
+ }
821
+ get touchAction() {
822
+ return "none";
823
+ }
824
+ get dir() {
825
+ return this.direction;
826
+ }
827
+ setItemData(data, i) {
828
+ this._localData[i].item = data.item;
829
+ this._localData[i].index = data.index;
830
+ this._localData[i].hidden = data.hidden;
831
+ }
832
+ /**
833
+ * @hidden
834
+ */
835
+ itemTemplate(index) {
836
+ let template = this.itemTemplateRef;
837
+ if (index === this.dragOverIndex) {
838
+ template = this.placeholderTemplateRef;
839
+ }
840
+ else if (index === this.dragIndex) {
841
+ template = this.itemTemplateRef;
842
+ }
843
+ return template;
844
+ }
845
+ ngOnInit() {
846
+ if (!this.data) {
847
+ this.data = [];
848
+ }
849
+ this.id = this.sortableService.registerComponent(this);
850
+ this.dragIndex = -1;
851
+ const display = "display";
852
+ if (this.activeItemStyle && !this.activeItemStyle[display]) {
853
+ this.activeItemStyle[display] = "";
854
+ }
855
+ if (!this.itemStyle[display]) {
856
+ this.itemStyle[display] = "";
857
+ }
858
+ if (this.wrapper) {
859
+ this.draggable = new Draggable({
860
+ press: (e) => this.sortableService.onPress(e),
861
+ drag: (e) => this.sortableService.onDrag(e),
862
+ release: (e) => this.sortableService.onRelease(e)
863
+ });
864
+ this.ngZone.runOutsideAngular(() => {
865
+ this.draggable.bindTo(this.wrapper);
866
+ });
867
+ }
868
+ }
869
+ ngOnChanges(changes) {
870
+ if (this.data && isChanged('disabledIndexes', changes, false)) {
871
+ this.cacheData();
872
+ }
873
+ }
874
+ ngOnDestroy() {
875
+ this.unsubscribeEvents();
876
+ this.sortableService.unregisterComponent(this.id);
877
+ if (this.draggable) {
878
+ this.draggable.destroy();
879
+ }
880
+ }
881
+ ngAfterContentInit() {
882
+ this.itemTemplateRef = this.itemTemplateDirectiveRef.first || this.defaultTemplateRef.first;
883
+ this.placeholderTemplateRef = this.placeholderTemplateDirectiveRef.first || this.defaultTemplateRef.first;
884
+ }
885
+ ngAfterViewChecked() {
886
+ if (this.afterKeyPress) {
887
+ if (this.itemWrappers) {
888
+ const elems = this.itemWrappers.toArray();
889
+ if (elems && elems.length > 0 && this.activeIndex > -1) {
890
+ elems[this.activeIndex].nativeElement.focus();
891
+ }
892
+ }
893
+ this.afterKeyPress = false;
894
+ }
895
+ }
896
+ /**
897
+ * @hidden
898
+ */
899
+ updateCacheIndices() {
900
+ this._localData.forEach((item, index) => {
901
+ item.index = index;
902
+ });
903
+ }
904
+ /**
905
+ * @hidden
906
+ */
907
+ cacheData() {
908
+ this._localData = [];
909
+ this._data.forEach((item, index) => {
910
+ this._localData.push({ item: item, active: false, disabled: !this.itemEnabled(index), index: index, hidden: false });
911
+ });
912
+ }
913
+ /**
914
+ * @hidden
915
+ */
916
+ startDrag(event) {
917
+ const startEvent = new DraggableEvent(event);
918
+ this.onDragStartSubject.next(startEvent);
919
+ const prevented = startEvent.isDefaultPrevented();
920
+ if (!prevented) {
921
+ this.offsetParent = relativeContextElement(this.wrapper);
922
+ }
923
+ return prevented;
924
+ }
925
+ /**
926
+ * @hidden
927
+ */
928
+ drag(event) {
929
+ const dragEvent = new DraggableEvent(event);
930
+ this.onDragOverSubject.next(dragEvent);
931
+ return dragEvent.isDefaultPrevented();
932
+ }
933
+ /**
934
+ * @hidden
935
+ */
936
+ leave(event) {
937
+ const leaveEvent = new DraggableEvent(event);
938
+ this.onDragLeaveSubject.next(leaveEvent);
939
+ return leaveEvent.isDefaultPrevented();
940
+ }
941
+ /**
942
+ * @hidden
943
+ */
944
+ endDrag(event) {
945
+ const endEvent = new DraggableEvent(event);
946
+ this.onDragEndSubject.next(endEvent);
947
+ return endEvent.isDefaultPrevented();
948
+ }
949
+ /**
950
+ * @hidden
951
+ */
952
+ hintVisible() {
953
+ return this.dragIndex >= 0 && this.hintLocation && this === this.sortableService.getSource();
954
+ }
955
+ /**
956
+ * @hidden
957
+ */
958
+ currentItemStyle(index) {
959
+ if (index === -1) {
960
+ return this.emptyItemStyle ? this.emptyItemStyle : this.itemStyle;
961
+ }
962
+ if (!this.itemEnabled(index) && this.disabledItemStyle) {
963
+ return this.disabledItemStyle;
964
+ }
965
+ if (index === this.dragIndex || (this.dragIndex === -1 && index === this.activeIndex)) {
966
+ if (this.hideActiveItem) {
967
+ return { "display": "none" };
968
+ }
969
+ if (this.activeItemStyle) {
970
+ return this.activeItemStyle;
971
+ }
972
+ }
973
+ return this.itemStyle;
974
+ }
975
+ /**
976
+ * @hidden
977
+ */
978
+ currentItemClass(index) {
979
+ if (index === -1) {
980
+ return this.emptyItemClass ? this.emptyItemClass : this.itemClass;
981
+ }
982
+ if (!this.itemEnabled(index) && this.disabledItemClass) {
983
+ return this.disabledItemClass;
984
+ }
985
+ if ((index === this.dragIndex || this.dragIndex === -1 && index === this.activeIndex) && this.activeItemClass) {
986
+ return this.activeItemClass;
987
+ }
988
+ return this.itemClass;
989
+ }
990
+ /**
991
+ * @hidden
992
+ */
993
+ hintStyle() {
994
+ const position = {
995
+ "left": this.hintLocation.x + 10 + "px",
996
+ "position": "fixed",
997
+ "top": this.hintLocation.y + 10 + "px"
998
+ };
999
+ const style = {};
1000
+ Object.assign(style, this.currentItemStyle(this.dragIndex), position);
1001
+ return style;
1002
+ }
1003
+ /**
1004
+ * @hidden
1005
+ */
1006
+ itemEnabled(index) {
1007
+ return this.disabledIndexes.indexOf(index) === -1;
1008
+ }
1009
+ /**
1010
+ * @hidden
1011
+ */
1012
+ acceptDragFrom(sortableComponent) {
1013
+ if (this.acceptZones === undefined) {
1014
+ return (this.zone === sortableComponent.zone);
1015
+ }
1016
+ else if (sortableComponent.zone !== undefined) {
1017
+ return (this.acceptZones.indexOf(sortableComponent.zone) !== -1);
1018
+ }
1019
+ return false;
1020
+ }
1021
+ /**
1022
+ * @hidden
1023
+ */
1024
+ ariaDropEffect(index) {
1025
+ return this.itemEnabled(index) ? "move" : "none";
1026
+ }
1027
+ /**
1028
+ * @hidden
1029
+ */
1030
+ focusHandler(index) {
1031
+ if (this.navigable) {
1032
+ this.activeIndex = index;
1033
+ }
1034
+ }
1035
+ /**
1036
+ * @hidden
1037
+ */
1038
+ blurHandler() {
1039
+ if (this.navigable && !this.afterKeyPress) {
1040
+ this.activeIndex = -1;
1041
+ }
1042
+ }
1043
+ /**
1044
+ * @hidden
1045
+ */
1046
+ keydownHandler(event) {
1047
+ const code = event.keyCode;
1048
+ const navigate = this.navigable && code >= 37 && code <= 40;
1049
+ const hasFocus = this.activeIndex !== -1;
1050
+ if (!navigate || !hasFocus) {
1051
+ return;
1052
+ }
1053
+ const leftKey = this.direction === 'rtl' ? 39 : 37;
1054
+ const dir = code === 38 || code === leftKey ? -1 : 1;
1055
+ const limit = this.data.length - 1;
1056
+ let targetIndex = this.activeIndex + dir;
1057
+ while (!this.itemEnabled(targetIndex) && targetIndex <= limit) {
1058
+ targetIndex += dir;
1059
+ }
1060
+ targetIndex = Math.min(Math.max(targetIndex, 0), limit);
1061
+ if (!this.itemEnabled(targetIndex)) {
1062
+ return;
1063
+ }
1064
+ if (navigate) {
1065
+ const ctrl = event.ctrlKey || event.metaKey;
1066
+ const navigateEvent = new NavigateEvent({ index: targetIndex, oldIndex: this.activeIndex, ctrlKey: ctrl });
1067
+ this.navigate.emit(navigateEvent);
1068
+ if (!navigateEvent.isDefaultPrevented()) {
1069
+ this.activeIndex = targetIndex;
1070
+ }
1071
+ this.dragIndex = -1;
1072
+ this.dragOverIndex = -1;
1073
+ }
1074
+ event.stopPropagation();
1075
+ event.preventDefault();
1076
+ this.afterKeyPress = true;
1077
+ }
1078
+ /**
1079
+ * Removes the currently active item from the Data collection that the Sortable uses.
1080
+ */
1081
+ removeDataItem(index) {
1082
+ this.dragIndex = -1;
1083
+ this.dragOverIndex = -1;
1084
+ this._localData.splice(index, 1);
1085
+ this.data.splice(index, 1);
1086
+ this.updateCacheIndices();
1087
+ }
1088
+ /**
1089
+ * Sets a Boolean value that indicates whether the item will be hidden or not.
1090
+ * @hidden
1091
+ */
1092
+ hideItem(index, hidden = true) {
1093
+ this._localData[index].hidden = hidden;
1094
+ }
1095
+ /**
1096
+ * Sets a Boolean value that indicates whether the currently dragged item will be hidden.
1097
+ */
1098
+ set hideActiveItem(value) {
1099
+ this.activeIndex = -1;
1100
+ this._hideActiveItem = value;
1101
+ }
1102
+ /**
1103
+ * If the currently dragged item is hidden, returns `true`.
1104
+ * If the currently dragged item is visible, returns `false`.
1105
+ */
1106
+ get hideActiveItem() {
1107
+ return this._hideActiveItem;
1108
+ }
1109
+ /**
1110
+ * Clears the active item.
1111
+ * An active item is the item which becomes focused when the user navigates with the keyboard.
1112
+ */
1113
+ clearActiveItem() {
1114
+ if (this.navigable) {
1115
+ this.fixFocus();
1116
+ }
1117
+ else {
1118
+ this.activeIndex = -1;
1119
+ }
1120
+ this.dragIndex = -1;
1121
+ }
1122
+ /**
1123
+ * Returns the currently active item when the user navigates with the keyboard.
1124
+ * @return - The data item which is currently active.
1125
+ */
1126
+ getActiveItem() {
1127
+ if (this.data && this.dragIndex >= 0 && this.dragIndex < this.data.length) {
1128
+ return this.data[this.dragIndex];
1129
+ }
1130
+ }
1131
+ /**
1132
+ * Adds a new data item to a particular index.
1133
+ * @param dataItem - The data item.
1134
+ * @param index - The index at which the data item is inserted.
1135
+ */
1136
+ addDataItem(dataItem, index) {
1137
+ const originDraggable = this.sortableService.originDraggable;
1138
+ if (originDraggable && originDraggable.parent === this) {
1139
+ const animation = this.animation;
1140
+ this.hideItem(originDraggable.index, false);
1141
+ this.animation = false;
1142
+ this.moveItem(originDraggable.index, index);
1143
+ this.animation = animation;
1144
+ }
1145
+ else {
1146
+ this.data.splice(index, 0, dataItem);
1147
+ this._localData.splice(index, 0, { item: dataItem, active: false, disabled: !this.itemEnabled(index), index: index, hidden: false });
1148
+ this.updateCacheIndices();
1149
+ }
1150
+ this.dragIndex = index;
1151
+ this.dragOverIndex = index;
1152
+ this.ngZone.onStable.pipe(take(1)).subscribe(() => {
1153
+ this.sortableService.target = this;
1154
+ this.sortableService.setSource(this);
1155
+ this.sortableService.activeDraggable = this.draggables.toArray()[index];
1156
+ this.sortableService.lastDraggable = null;
1157
+ });
1158
+ }
1159
+ /**
1160
+ * Moves data item to a particular index.
1161
+ * @param fromIndex - The data item's index.
1162
+ * @param toIndex - The index which the data item should be moved to. Item currently sitting at that index is pushed back one position.
1163
+ */
1164
+ moveItem(fromIndex, toIndex) {
1165
+ if (toIndex === fromIndex) {
1166
+ return;
1167
+ }
1168
+ let dragIndex = fromIndex;
1169
+ const d = toIndex > dragIndex ? 1 : -1;
1170
+ const originalIndexAnimate = dragIndex;
1171
+ const toAnimate = [];
1172
+ let prevIndex = dragIndex;
1173
+ let tmp;
1174
+ while (dragIndex !== toIndex) {
1175
+ dragIndex += d;
1176
+ if (this.itemEnabled(dragIndex) || dragIndex === toIndex) {
1177
+ if (this.animation) {
1178
+ toAnimate.push({ next: dragIndex, prev: prevIndex });
1179
+ }
1180
+ tmp = this._localData[prevIndex].index;
1181
+ this._localData[prevIndex].index = this._localData[dragIndex].index;
1182
+ this._localData[dragIndex].index = tmp;
1183
+ tmp = this._localData[prevIndex];
1184
+ this._localData[prevIndex] = this._localData[dragIndex];
1185
+ this._localData[dragIndex] = tmp;
1186
+ tmp = this.data[prevIndex];
1187
+ this.data[prevIndex] = this.data[dragIndex];
1188
+ this.data[dragIndex] = tmp;
1189
+ prevIndex = dragIndex;
1190
+ }
1191
+ }
1192
+ this.dragIndex = dragIndex;
1193
+ this.dragOverIndex = dragIndex;
1194
+ this.activeIndex = dragIndex;
1195
+ if (this.animation) {
1196
+ setTimeout(() => {
1197
+ toAnimate.push({ next: originalIndexAnimate, prev: dragIndex });
1198
+ this.animating = true;
1199
+ this.animate(toAnimate);
1200
+ });
1201
+ }
1202
+ this.ngZone.onStable.pipe(take(1)).subscribe(() => {
1203
+ this.sortableService.activeDraggable = this.draggables.toArray()[dragIndex];
1204
+ this.sortableService.lastDraggable = null;
1205
+ });
1206
+ }
1207
+ /**
1208
+ * @hidden
1209
+ */
1210
+ animate(draggables) {
1211
+ const itemArray = this.itemWrappers.toArray();
1212
+ const prevClientRect = [];
1213
+ const nextClientRect = [];
1214
+ clearTimeout(this._animating);
1215
+ for (let i = 0; i < draggables.length; i++) {
1216
+ prevClientRect.push(itemArray[draggables[i].prev].nativeElement.getBoundingClientRect());
1217
+ nextClientRect.push(itemArray[draggables[i].next].nativeElement.getBoundingClientRect());
1218
+ }
1219
+ for (let i = 0; i < draggables.length; i++) {
1220
+ const nextIndex = draggables[i].prev;
1221
+ const targetRect = nextClientRect[i];
1222
+ const currentRect = prevClientRect[i];
1223
+ const target = itemArray[nextIndex].nativeElement;
1224
+ this.applyAnimationStyle(target, 'transition', 'none');
1225
+ this.applyAnimationStyle(target, 'transform', 'translate3d('
1226
+ + (targetRect.left - currentRect.left).toString() + 'px,'
1227
+ + (targetRect.top - currentRect.top).toString() + 'px,0)');
1228
+ this.reflow(target);
1229
+ }
1230
+ for (let i = 0; i < draggables.length; i++) {
1231
+ const nextIndex = draggables[i].prev;
1232
+ const target = itemArray[nextIndex].nativeElement;
1233
+ this.applyAnimationStyle(target, 'transition', 'all ' + this.animationDuration + 'ms');
1234
+ this.applyAnimationStyle(target, 'transform', 'translate3d(0,0,0)');
1235
+ clearTimeout(target.animated);
1236
+ target.animated = setTimeout(() => {
1237
+ this.applyAnimationStyle(target, 'transition', '');
1238
+ this.applyAnimationStyle(target, 'transform', '');
1239
+ target.animated = false;
1240
+ }, this.animationDuration);
1241
+ }
1242
+ this._animating = setTimeout(() => {
1243
+ this.animating = false;
1244
+ }, this.animationDuration);
1245
+ }
1246
+ /**
1247
+ * @hidden
1248
+ */
1249
+ positionHintFromEvent(event) {
1250
+ const offset = this.parentOffset();
1251
+ this.hintLocation = event ? { x: event.clientX - offset.left, y: event.clientY - offset.top } : null;
1252
+ }
1253
+ /**
1254
+ * @hidden
1255
+ */
1256
+ parentOffset() {
1257
+ const offsetParent = this.offsetParent;
1258
+ if (offsetParent) {
1259
+ const rect = offsetParent.getBoundingClientRect();
1260
+ return {
1261
+ left: rect.left - offsetParent.scrollLeft,
1262
+ top: rect.top - offsetParent.scrollTop
1263
+ };
1264
+ }
1265
+ return { left: 0, top: 0 };
1266
+ }
1267
+ /**
1268
+ * @hidden
1269
+ */
1270
+ markForCheck() {
1271
+ this.changeDetector.markForCheck();
1272
+ }
1273
+ /**
1274
+ * @hidden
1275
+ */
1276
+ reflow(element) {
1277
+ return element.offsetWidth;
1278
+ }
1279
+ /**
1280
+ * @hidden
1281
+ */
1282
+ applyAnimationStyle(el, prop, val) {
1283
+ const style = el && el.style;
1284
+ if (style) {
1285
+ if (!(prop in style)) {
1286
+ prop = '-webkit-' + prop;
1287
+ }
1288
+ style[prop] = val;
1289
+ }
1290
+ }
1291
+ subscribeEvents() {
1292
+ this.localizationChangeSubscription = this.localization
1293
+ .changes
1294
+ .subscribe(({ rtl }) => this.direction = rtl ? 'rtl' : 'ltr');
1295
+ this.dragStartSubscription = this.onDragStartSubject
1296
+ .subscribe((event) => {
1297
+ this.sortableService.originDraggable = event.target;
1298
+ this.sortableService.originIndex = event.target.index;
1299
+ this.sortableService.activeDraggable = event.target;
1300
+ this.sortableService.lastDraggable = event.target;
1301
+ this.sortableService.target = this;
1302
+ this.sortableService.setSource(this);
1303
+ const dragStartEvent = new DragStartEvent({ index: event.target.index });
1304
+ this.dragStart.emit(dragStartEvent);
1305
+ if (dragStartEvent.isDefaultPrevented()) {
1306
+ event.preventDefault();
1307
+ }
1308
+ else {
1309
+ if (!event.target.disabled) {
1310
+ if (this.sortableService.target) {
1311
+ this.sortableService.target.dragOverIndex = -1;
1312
+ this.sortableService.target.dragIndex = -1;
1313
+ }
1314
+ this.dragOverIndex = event.target.index;
1315
+ this.dragIndex = event.target.index;
1316
+ }
1317
+ }
1318
+ });
1319
+ this.dragOverSubscription = this.onDragOverSubject.pipe(filter(event => event.target && event.target.el.nativeElement.style.transition.length === 0), filter(() => {
1320
+ // Drag started from a disabled item
1321
+ return this.sortableService.originDraggable && !this.sortableService.originDraggable.disabled;
1322
+ }), filter(() => {
1323
+ return this.sortableService && this.acceptDragFrom(this.sortableService.getSource());
1324
+ }), filter((event) => {
1325
+ return event.target !== this.sortableService.lastDraggable;
1326
+ }))
1327
+ .subscribe((event) => {
1328
+ this.sortableService.lastDraggable = event.target;
1329
+ const originDraggable = this.sortableService.originDraggable;
1330
+ let targetIndex = event.target.index;
1331
+ if (originDraggable.hidden && originDraggable.parent === this) {
1332
+ if (originDraggable.index < event.target.index) {
1333
+ targetIndex = event.target.index - 1;
1334
+ }
1335
+ }
1336
+ this.sortableService.target = this;
1337
+ const oldIndex = this.sortableService.activeDraggable ? this.sortableService.activeDraggable.index : 0;
1338
+ const dragOverEvent = new DragOverEvent({ index: targetIndex, oldIndex: oldIndex });
1339
+ this.dragOver.emit(dragOverEvent);
1340
+ if (!dragOverEvent.isDefaultPrevented() && event.target && event.target.index >= 0) {
1341
+ this.dragOverIndex = event.target.index;
1342
+ this.placeHolderItemData(event.target);
1343
+ }
1344
+ });
1345
+ this.dragEndSubscription = this.onDragEndSubject
1346
+ .subscribe((event) => {
1347
+ const source = this.sortableService.getSource();
1348
+ if (!source) {
1349
+ return;
1350
+ }
1351
+ const target = this.sortableService.target;
1352
+ const index = event.target ? event.target.index : -1;
1353
+ const oldIndex = this.sortableService.originDraggable ? this.sortableService.originIndex : -1;
1354
+ this.hintLocation = null;
1355
+ const dragEndEvent = new DragEndEvent({ index: index, oldIndex: oldIndex });
1356
+ this.dragEnd.emit(dragEndEvent);
1357
+ if (!dragEndEvent.isDefaultPrevented()) {
1358
+ source.dragIndex = -1;
1359
+ source.dragOverIndex = -1;
1360
+ source.activeIndex = -1;
1361
+ if (target && target !== source) {
1362
+ target.dragIndex = -1;
1363
+ target.dragOverIndex = -1;
1364
+ }
1365
+ setTimeout(() => {
1366
+ this.sortableService.activeDraggable = null;
1367
+ this.sortableService.lastDraggable = null;
1368
+ this.sortableService.originDraggable = null;
1369
+ this.sortableService.target = null;
1370
+ this.sortableService.setSource(null);
1371
+ });
1372
+ }
1373
+ });
1374
+ this.dragLeaveSubscription = this.onDragLeaveSubject.pipe(filter((e) => {
1375
+ if (!isDocumentAvailable()) {
1376
+ return false;
1377
+ }
1378
+ return this.wrapper !== document.elementFromPoint(e.originalEvent.pageX, e.originalEvent.pageY);
1379
+ }), filter((_e) => {
1380
+ return !this.animating;
1381
+ }), filter(_ => this.sortableService.target && this.sortableService.target.dragOverIndex > -1))
1382
+ .subscribe(() => {
1383
+ this.dragLeave.emit({ index: this.sortableService.originDraggable.index });
1384
+ this.sortableService.lastDraggable = null;
1385
+ this.dragOverIndex = -1;
1386
+ this.sortableService.target = null;
1387
+ });
1388
+ }
1389
+ unsubscribeEvents() {
1390
+ if (this.localizationChangeSubscription) {
1391
+ this.localizationChangeSubscription.unsubscribe();
1392
+ }
1393
+ this.dragStartSubscription.unsubscribe();
1394
+ this.dragOverSubscription.unsubscribe();
1395
+ this.dragEndSubscription.unsubscribe();
1396
+ this.dragLeaveSubscription.unsubscribe();
1397
+ }
1398
+ placeHolderItemData(draggable) {
1399
+ if (draggable.disabled) {
1400
+ return;
1401
+ }
1402
+ const target = this.sortableService.target;
1403
+ const source = this.sortableService.getSource();
1404
+ const originalData = Object.assign({}, this._localData[draggable.index]);
1405
+ const newData = source._localData[source.dragIndex];
1406
+ this.setItemData(newData, draggable.index);
1407
+ const endSub = source.onDragEndSubject.pipe(take(1)).subscribe(() => {
1408
+ this.setItemData(originalData, draggable.index);
1409
+ });
1410
+ const leaveSub = target.onDragLeaveSubject.pipe(take(1)).subscribe(() => {
1411
+ this.setItemData(originalData, draggable.index);
1412
+ });
1413
+ const overSub = merge(this.onDragOverSubject.pipe(filter(() => {
1414
+ return draggable.index !== this.dragOverIndex;
1415
+ })), this.onDragLeaveSubject).subscribe(() => {
1416
+ this.setItemData(originalData, draggable.index);
1417
+ endSub.unsubscribe();
1418
+ overSub.unsubscribe();
1419
+ leaveSub.unsubscribe();
1420
+ });
1421
+ }
1422
+ fixFocus() {
1423
+ if (this.itemWrappers) {
1424
+ const itemArray = this.itemWrappers.toArray();
1425
+ if (this.dragIndex > -1 && itemArray && itemArray.length > 0) {
1426
+ itemArray[this.dragIndex].nativeElement.focus();
1427
+ this.activeIndex = this.dragIndex;
1428
+ }
1429
+ }
1430
+ }
1431
+ }
1432
+ SortableComponent.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableComponent, deps: [{ token: i0.NgZone }, { token: i1.LocalizationService }, { token: i0.ChangeDetectorRef }, { token: i0.ElementRef }, { token: SortableService }], target: i0.ɵɵFactoryTarget.Component });
1433
+ SortableComponent.ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "12.0.0", version: "13.3.11", type: SortableComponent, selector: "kendo-sortable", inputs: { tabIndex: "tabIndex", data: "data", navigable: "navigable", navigatable: "navigatable", animation: "animation", disabledIndexes: "disabledIndexes", zone: "zone", acceptZones: "acceptZones", itemStyle: "itemStyle", emptyItemStyle: "emptyItemStyle", activeItemStyle: "activeItemStyle", disabledItemStyle: "disabledItemStyle", itemClass: "itemClass", activeItemClass: "activeItemClass", emptyItemClass: "emptyItemClass", disabledItemClass: "disabledItemClass", emptyText: "emptyText", activeIndex: "activeIndex" }, outputs: { dragStart: "dragStart", dragEnd: "dragEnd", dragOver: "dragOver", dragLeave: "dragLeave", dataMove: "dataMove", dataAdd: "dataAdd", dataRemove: "dataRemove", navigate: "navigate" }, host: { properties: { "style.touch-action": "this.touchAction", "attr.dir": "this.dir" } }, providers: [
1434
+ LocalizationService,
1435
+ {
1436
+ provide: L10N_PREFIX,
1437
+ useValue: 'kendo.sortable'
1438
+ },
1439
+ {
1440
+ provide: SortableContainer,
1441
+ useExisting: forwardRef(() => SortableComponent)
1442
+ }
1443
+ ], queries: [{ propertyName: "defaultTemplateRef", predicate: TemplateRef }, { propertyName: "itemTemplateDirectiveRef", predicate: ItemTemplateDirective, read: TemplateRef }, { propertyName: "placeholderTemplateDirectiveRef", predicate: PlaceholderTemplateDirective, read: TemplateRef }], viewQueries: [{ propertyName: "noDataContainer", first: true, predicate: ["noDataRef"], descendants: true }, { propertyName: "hint", first: true, predicate: ["hint"], descendants: true }, { propertyName: "itemWrappers", predicate: ["itemWrapper"], descendants: true }, { propertyName: "draggables", predicate: DraggableDirective, descendants: true }], exportAs: ["kendoSortable"], usesOnChanges: true, ngImport: i0, template: `
1444
+ <div #itemWrapper *ngFor="let item of _localData;let i=index"
1445
+ kendoDraggable
1446
+ [attr.tabIndex]="itemEnabled(i)?(navigable?tabIndex||0:tabIndex):null"
1447
+ [attr.aria-grabbed]="i===dragIndex"
1448
+ [attr.aria-dropeffect]="ariaDropEffect(i)"
1449
+ [attr.data-sortable-item] = "true"
1450
+ [attr.data-sortable-index]="i"
1451
+ [attr.data-sortable-id]="id"
1452
+ [index]="i"
1453
+ [hidden]="item.hidden"
1454
+ [disabled]="!itemEnabled(i)"
1455
+ [ngClass]="currentItemClass(i)"
1456
+ [ngStyle]="currentItemStyle(i)"
1457
+
1458
+ (focus)="focusHandler(i)"
1459
+ (blur)="blurHandler()"
1460
+ (keydown)="keydownHandler($event)"
1461
+ >
1462
+ <ng-container *ngIf="itemTemplateRef"
1463
+ [ngTemplateOutlet]="itemTemplate(i)"
1464
+ [ngTemplateOutletContext]="item">
1465
+ </ng-container>
1466
+ <ng-container *ngIf="!itemTemplateRef">{{item.item}}</ng-container>
1467
+ </div>
1468
+
1469
+ <ng-container #noDataRef *ngIf="!_data.length || _localData.length === 1 && _localData[0].hidden">
1470
+ <div
1471
+ kendoDraggable
1472
+ [index]="0"
1473
+ [disabled]="true"
1474
+ [attr.data-sortable-id]="id"
1475
+ [attr.data-sortable-index]="0"
1476
+ [ngStyle]="currentItemStyle(-1)"
1477
+ [ngClass]="currentItemClass(-1)"
1478
+ >{{emptyText}}</div>
1479
+ </ng-container>
1480
+ <div *ngIf="hintVisible()" [ngStyle]="hintStyle()" [ngClass]="currentItemClass(dragIndex)">
1481
+ <ng-container *ngIf="itemTemplateRef"
1482
+ [ngTemplateOutlet]="itemTemplateRef"
1483
+ [ngTemplateOutletContext]="{item: _localData[dragIndex].item}">
1484
+ </ng-container>
1485
+ <ng-container *ngIf="!itemTemplateRef">{{_localData[dragIndex].item}}</ng-container>
1486
+ </div>
1487
+ `, isInline: true, directives: [{ type: i3.NgForOf, selector: "[ngFor][ngForOf]", inputs: ["ngForOf", "ngForTrackBy", "ngForTemplate"] }, { type: DraggableDirective, selector: "[kendoDraggable]", inputs: ["index", "disabled", "hidden"] }, { type: i3.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }, { type: i3.NgStyle, selector: "[ngStyle]", inputs: ["ngStyle"] }, { type: i3.NgIf, selector: "[ngIf]", inputs: ["ngIf", "ngIfThen", "ngIfElse"] }, { type: i3.NgTemplateOutlet, selector: "[ngTemplateOutlet]", inputs: ["ngTemplateOutletContext", "ngTemplateOutlet"] }] });
1488
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableComponent, decorators: [{
1489
+ type: Component,
1490
+ args: [{
1491
+ exportAs: 'kendoSortable',
1492
+ providers: [
1493
+ LocalizationService,
1494
+ {
1495
+ provide: L10N_PREFIX,
1496
+ useValue: 'kendo.sortable'
1497
+ },
1498
+ {
1499
+ provide: SortableContainer,
1500
+ useExisting: forwardRef(() => SortableComponent)
1501
+ }
1502
+ ],
1503
+ selector: 'kendo-sortable',
1504
+ template: `
1505
+ <div #itemWrapper *ngFor="let item of _localData;let i=index"
1506
+ kendoDraggable
1507
+ [attr.tabIndex]="itemEnabled(i)?(navigable?tabIndex||0:tabIndex):null"
1508
+ [attr.aria-grabbed]="i===dragIndex"
1509
+ [attr.aria-dropeffect]="ariaDropEffect(i)"
1510
+ [attr.data-sortable-item] = "true"
1511
+ [attr.data-sortable-index]="i"
1512
+ [attr.data-sortable-id]="id"
1513
+ [index]="i"
1514
+ [hidden]="item.hidden"
1515
+ [disabled]="!itemEnabled(i)"
1516
+ [ngClass]="currentItemClass(i)"
1517
+ [ngStyle]="currentItemStyle(i)"
1518
+
1519
+ (focus)="focusHandler(i)"
1520
+ (blur)="blurHandler()"
1521
+ (keydown)="keydownHandler($event)"
1522
+ >
1523
+ <ng-container *ngIf="itemTemplateRef"
1524
+ [ngTemplateOutlet]="itemTemplate(i)"
1525
+ [ngTemplateOutletContext]="item">
1526
+ </ng-container>
1527
+ <ng-container *ngIf="!itemTemplateRef">{{item.item}}</ng-container>
1528
+ </div>
1529
+
1530
+ <ng-container #noDataRef *ngIf="!_data.length || _localData.length === 1 && _localData[0].hidden">
1531
+ <div
1532
+ kendoDraggable
1533
+ [index]="0"
1534
+ [disabled]="true"
1535
+ [attr.data-sortable-id]="id"
1536
+ [attr.data-sortable-index]="0"
1537
+ [ngStyle]="currentItemStyle(-1)"
1538
+ [ngClass]="currentItemClass(-1)"
1539
+ >{{emptyText}}</div>
1540
+ </ng-container>
1541
+ <div *ngIf="hintVisible()" [ngStyle]="hintStyle()" [ngClass]="currentItemClass(dragIndex)">
1542
+ <ng-container *ngIf="itemTemplateRef"
1543
+ [ngTemplateOutlet]="itemTemplateRef"
1544
+ [ngTemplateOutletContext]="{item: _localData[dragIndex].item}">
1545
+ </ng-container>
1546
+ <ng-container *ngIf="!itemTemplateRef">{{_localData[dragIndex].item}}</ng-container>
1547
+ </div>
1548
+ `
1549
+ }]
1550
+ }], ctorParameters: function () { return [{ type: i0.NgZone }, { type: i1.LocalizationService }, { type: i0.ChangeDetectorRef }, { type: i0.ElementRef }, { type: SortableService }]; }, propDecorators: { tabIndex: [{
1551
+ type: Input
1552
+ }], data: [{
1553
+ type: Input
1554
+ }], navigable: [{
1555
+ type: Input
1556
+ }], navigatable: [{
1557
+ type: Input
1558
+ }], animation: [{
1559
+ type: Input
1560
+ }], disabledIndexes: [{
1561
+ type: Input
1562
+ }], zone: [{
1563
+ type: Input
1564
+ }], acceptZones: [{
1565
+ type: Input
1566
+ }], itemStyle: [{
1567
+ type: Input
1568
+ }], emptyItemStyle: [{
1569
+ type: Input
1570
+ }], activeItemStyle: [{
1571
+ type: Input
1572
+ }], disabledItemStyle: [{
1573
+ type: Input
1574
+ }], itemClass: [{
1575
+ type: Input
1576
+ }], activeItemClass: [{
1577
+ type: Input
1578
+ }], emptyItemClass: [{
1579
+ type: Input
1580
+ }], disabledItemClass: [{
1581
+ type: Input
1582
+ }], emptyText: [{
1583
+ type: Input
1584
+ }], defaultTemplateRef: [{
1585
+ type: ContentChildren,
1586
+ args: [TemplateRef, { descendants: false }]
1587
+ }], itemTemplateDirectiveRef: [{
1588
+ type: ContentChildren,
1589
+ args: [ItemTemplateDirective, { read: TemplateRef, descendants: false }]
1590
+ }], placeholderTemplateDirectiveRef: [{
1591
+ type: ContentChildren,
1592
+ args: [PlaceholderTemplateDirective, { read: TemplateRef, descendants: false }]
1593
+ }], itemWrappers: [{
1594
+ type: ViewChildren,
1595
+ args: ['itemWrapper']
1596
+ }], draggables: [{
1597
+ type: ViewChildren,
1598
+ args: [DraggableDirective]
1599
+ }], noDataContainer: [{
1600
+ type: ViewChild,
1601
+ args: ['noDataRef', { static: false }]
1602
+ }], hint: [{
1603
+ type: ViewChild,
1604
+ args: ['hint', { static: false }]
1605
+ }], dragStart: [{
1606
+ type: Output
1607
+ }], dragEnd: [{
1608
+ type: Output
1609
+ }], dragOver: [{
1610
+ type: Output
1611
+ }], dragLeave: [{
1612
+ type: Output
1613
+ }], dataMove: [{
1614
+ type: Output
1615
+ }], dataAdd: [{
1616
+ type: Output
1617
+ }], dataRemove: [{
1618
+ type: Output
1619
+ }], navigate: [{
1620
+ type: Output
1621
+ }], activeIndex: [{
1622
+ type: Input
1623
+ }], touchAction: [{
1624
+ type: HostBinding,
1625
+ args: ['style.touch-action']
1626
+ }], dir: [{
1627
+ type: HostBinding,
1628
+ args: ['attr.dir']
1629
+ }] } });
1630
+
1631
+ /**
1632
+ * The arguments for the `SortableComponent` `dataAdd` event.
1633
+ */
1634
+ class DataAddEvent extends PreventableEvent {
1635
+ /**
1636
+ * @hidden
1637
+ */
1638
+ constructor(options) {
1639
+ super();
1640
+ Object.assign(this, options);
1641
+ }
1642
+ }
1643
+ /**
1644
+ * The arguments for the `SortableComponent` `dataRemove` event.
1645
+ */
1646
+ class DataRemoveEvent extends PreventableEvent {
1647
+ /**
1648
+ * @hidden
1649
+ */
1650
+ constructor(options) {
1651
+ super();
1652
+ Object.assign(this, options);
1653
+ }
1654
+ }
1655
+ /**
1656
+ * The arguments for the `SortableComponent` `dataMove` event.
1657
+ */
1658
+ class DataMoveEvent extends PreventableEvent {
1659
+ /**
1660
+ * @hidden
1661
+ */
1662
+ constructor(options) {
1663
+ super();
1664
+ Object.assign(this, options);
1665
+ }
1666
+ }
1667
+
1668
+ /**
1669
+ * A Directive which handles the most common scenarios such reordering and moving items between Sortables, thus minimizng boilerplate code.
1670
+ * This is achieved by subscribing to the Sortable's events and handling them using the API methods it provides.
1671
+ */
1672
+ class SortableBindingDirective {
1673
+ constructor(sortable, sortableService) {
1674
+ this.sortable = sortable;
1675
+ this.sortableService = sortableService;
1676
+ this.sortableService = sortableService;
1677
+ }
1678
+ /**
1679
+ * Sets a data-bound array that is used as a data source for the Sortable.
1680
+ *
1681
+ * {% meta height:430 %}
1682
+ * {% embed_file overview/app.component.ts %}
1683
+ * {% embed_file shared/app.module.ts %}
1684
+ * {% embed_file shared/main.ts hidden %}
1685
+ * {% endmeta %}
1686
+ *
1687
+ */
1688
+ set data(data) {
1689
+ this.sortable.data = data;
1690
+ }
1691
+ nextEnabledIndex(index, sortable) {
1692
+ for (let i = index; i <= sortable.data.length; i++) {
1693
+ if (sortable.itemEnabled(i)) {
1694
+ return i;
1695
+ }
1696
+ }
1697
+ }
1698
+ addItem(event, sortable) {
1699
+ let index = event.index;
1700
+ const dataItem = this.sortableService.getSource().data[event.oldIndex];
1701
+ const addEvent = new DataAddEvent({ index: index, dataItem: dataItem });
1702
+ sortable.dataAdd.emit(addEvent);
1703
+ if (!addEvent.isDefaultPrevented()) {
1704
+ if (index === sortable.itemWrappers.length - 1 && !sortable.noDataContainer) {
1705
+ index++;
1706
+ }
1707
+ sortable.addDataItem(dataItem, index);
1708
+ }
1709
+ return !addEvent.isDefaultPrevented();
1710
+ }
1711
+ removeItem(event, sortable) {
1712
+ const originDraggable = this.sortableService.originDraggable;
1713
+ const removeEvent = new DataRemoveEvent({ index: event.oldIndex, dataItem: sortable.data[event.oldIndex] });
1714
+ sortable.dataRemove.emit(removeEvent);
1715
+ if (!removeEvent.isDefaultPrevented()) {
1716
+ if (originDraggable && originDraggable.parent === sortable) {
1717
+ sortable.hideItem(event.oldIndex, true);
1718
+ }
1719
+ else {
1720
+ sortable.removeDataItem(event.oldIndex);
1721
+ }
1722
+ }
1723
+ return !removeEvent.isDefaultPrevented();
1724
+ }
1725
+ moveItem(event, sortable) {
1726
+ if (event.index === event.oldIndex) {
1727
+ return false;
1728
+ }
1729
+ const moveEvent = new DataMoveEvent({
1730
+ dataItem: sortable.data[event.oldIndex],
1731
+ index: event.index,
1732
+ oldIndex: event.oldIndex
1733
+ });
1734
+ sortable.dataMove.emit(moveEvent);
1735
+ if (!moveEvent.isDefaultPrevented()) {
1736
+ sortable.moveItem(event.oldIndex, event.index);
1737
+ }
1738
+ return !moveEvent.isDefaultPrevented();
1739
+ }
1740
+ /**
1741
+ * Removes the Draggable item from which the drag started.
1742
+ * @hidden
1743
+ */
1744
+ removeOriginDraggable() {
1745
+ if (this.removeHiddenSubscription) {
1746
+ this.removeHiddenSubscription.unsubscribe();
1747
+ }
1748
+ this.removeHiddenSubscription = this.sortableService.onReleaseSubject.pipe(take(1), filter(_ => this.sortableService.originDraggable !== null && this.sortableService.originDraggable.hidden)).subscribe((e) => {
1749
+ const originDraggable = this.sortableService.originDraggable;
1750
+ const newSource = this.sortableService.getSource();
1751
+ if (originDraggable.parent !== this.sortableService.target) {
1752
+ const isTargetDraggable = e.target ? (e.target.isDraggable || e.target.isDraggableChild) : false;
1753
+ if (isTargetDraggable || originDraggable.parent !== newSource) {
1754
+ if (originDraggable.parent !== this.sortableService.target) {
1755
+ originDraggable.parent.removeDataItem(originDraggable.index);
1756
+ }
1757
+ }
1758
+ this.sortableService.originDraggable = null;
1759
+ }
1760
+ });
1761
+ }
1762
+ onDragOver(event) {
1763
+ const source = this.sortableService.getSource();
1764
+ const target = this.sortableService.target;
1765
+ const targetDraggables = target.draggables.toArray();
1766
+ if (event.isDefaultPrevented()) {
1767
+ return;
1768
+ }
1769
+ event.preventDefault();
1770
+ if (target === source) {
1771
+ // Skip moveItem if target is the draggable after which item was just added
1772
+ // Ensures item added to the end stays there until further user action
1773
+ if (targetDraggables[event.index] !== this.lastTarget) {
1774
+ this.moveItem(event, target);
1775
+ }
1776
+ this.lastTarget = undefined;
1777
+ }
1778
+ else {
1779
+ if (!target.itemEnabled(event.index)) {
1780
+ event.index = this.nextEnabledIndex(event.index, target);
1781
+ }
1782
+ //Add to target and remove from source
1783
+ if (this.addItem(event, target) && this.removeItem(event, source)) {
1784
+ this.lastTarget = target.draggables.toArray()[event.index];
1785
+ this.removeOriginDraggable();
1786
+ target.activeIndex = event.index;
1787
+ source.activeIndex = -1;
1788
+ }
1789
+ }
1790
+ }
1791
+ onNavigate(event) {
1792
+ if (event.ctrlKey) {
1793
+ const moveEvent = new DataMoveEvent({
1794
+ dataItem: this.sortable.data[event.oldIndex],
1795
+ index: event.index,
1796
+ oldIndex: event.oldIndex
1797
+ });
1798
+ this.sortable.dataMove.emit(moveEvent);
1799
+ if (!moveEvent.isDefaultPrevented()) {
1800
+ this.sortable.moveItem(event.oldIndex, event.index);
1801
+ }
1802
+ }
1803
+ else {
1804
+ this.sortable.activeIndex = event.index;
1805
+ }
1806
+ }
1807
+ ngOnInit() {
1808
+ this.dragOverSubscription = this.sortable.dragOver.subscribe(this.onDragOver.bind(this));
1809
+ this.navigateSubscription = this.sortable.navigate.subscribe(this.onNavigate.bind(this));
1810
+ }
1811
+ ngOnDestroy() {
1812
+ this.dragOverSubscription.unsubscribe();
1813
+ this.navigateSubscription.unsubscribe();
1814
+ if (this.removeHiddenSubscription) {
1815
+ this.removeHiddenSubscription.unsubscribe();
1816
+ }
1817
+ }
1818
+ }
1819
+ SortableBindingDirective.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableBindingDirective, deps: [{ token: SortableComponent }, { token: SortableService }], target: i0.ɵɵFactoryTarget.Directive });
1820
+ SortableBindingDirective.ɵdir = i0.ɵɵngDeclareDirective({ minVersion: "12.0.0", version: "13.3.11", type: SortableBindingDirective, selector: "[kendoSortableBinding]", inputs: { data: ["kendoSortableBinding", "data"] }, ngImport: i0 });
1821
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableBindingDirective, decorators: [{
1822
+ type: Directive,
1823
+ args: [{
1824
+ selector: '[kendoSortableBinding]'
1825
+ }]
1826
+ }], ctorParameters: function () { return [{ type: SortableComponent }, { type: SortableService }]; }, propDecorators: { data: [{
1827
+ type: Input,
1828
+ args: ["kendoSortableBinding"]
1829
+ }] } });
1830
+
1831
+ const COMPONENT_DIRECTIVES = [
1832
+ SortableComponent,
1833
+ DraggableDirective,
1834
+ PlaceholderTemplateDirective,
1835
+ ItemTemplateDirective,
1836
+ SortableBindingDirective
1837
+ ];
1838
+ /**
1839
+ *
1840
+ * Represents the [`NgModule`](link:site.data.urls.angular['ngmoduleapi'])
1841
+ * definition for the Sortable component.
1842
+ *
1843
+ * @example
1844
+ *
1845
+ * ```ts-no-run
1846
+ * import { NgModule } from '@angular/core';
1847
+ * import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
1848
+ *
1849
+ * // Import the Sortable module
1850
+ * import { SortableModule } from '@progress/kendo-angular-sortable';
1851
+ *
1852
+ * // Import the app component
1853
+ * import { AppComponent } from './app.component';
1854
+ *
1855
+ * // Define the app module
1856
+ * _@NgModule({
1857
+ * declarations: [AppComponent],
1858
+ * imports: [BrowserModule, SortableModule],
1859
+ * bootstrap: [AppComponent]
1860
+ * })
1861
+ * export class AppModule {}
1862
+ *
1863
+ * // Compile and launch the module
1864
+ * platformBrowserDynamic().bootstrapModule(AppModule);
1865
+ *
1866
+ * ```
1867
+ */
1868
+ class SortableModule {
1869
+ }
1870
+ SortableModule.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableModule, deps: [], target: i0.ɵɵFactoryTarget.NgModule });
1871
+ SortableModule.ɵmod = i0.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableModule, declarations: [SortableComponent,
1872
+ DraggableDirective,
1873
+ PlaceholderTemplateDirective,
1874
+ ItemTemplateDirective,
1875
+ SortableBindingDirective], imports: [CommonModule], exports: [SortableComponent,
1876
+ DraggableDirective,
1877
+ PlaceholderTemplateDirective,
1878
+ ItemTemplateDirective,
1879
+ SortableBindingDirective] });
1880
+ SortableModule.ɵinj = i0.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableModule, providers: [SortableService], imports: [[CommonModule]] });
1881
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "13.3.11", ngImport: i0, type: SortableModule, decorators: [{
1882
+ type: NgModule,
1883
+ args: [{
1884
+ declarations: [COMPONENT_DIRECTIVES],
1885
+ exports: [COMPONENT_DIRECTIVES],
1886
+ imports: [CommonModule],
1887
+ providers: [SortableService]
1888
+ }]
1889
+ }] });
1890
+
1891
+ /**
1892
+ * Generated bundle index. Do not edit.
1893
+ */
1894
+
1895
+ export { DataMoveEvent, DragEndEvent, DragOverEvent, DragStartEvent, DraggableDirective, DraggableEvent, ItemTemplateDirective, NavigateEvent, PlaceholderTemplateDirective, PreventableEvent, SortableBindingDirective, SortableComponent, SortableContainer, SortableModule, SortableService };
1896
+