@progress/kendo-angular-sortable 4.0.6 → 5.0.0-dev.202204191145

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