@syncfusion/ej2-lists 30.1.37 → 30.1.42
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +2 -0
- package/dist/ej2-lists.min.js +2 -2
- package/dist/ej2-lists.umd.min.js +2 -2
- package/dist/ej2-lists.umd.min.js.map +1 -1
- package/dist/es6/ej2-lists.es2015.js +8 -1
- package/dist/es6/ej2-lists.es2015.js.map +1 -1
- package/dist/es6/ej2-lists.es5.js +8 -1
- package/dist/es6/ej2-lists.es5.js.map +1 -1
- package/dist/global/ej2-lists.min.js +2 -2
- package/dist/global/ej2-lists.min.js.map +1 -1
- package/dist/global/index.d.ts +1 -1
- package/package.json +11 -54
- package/src/list-view/list-view.d.ts +1 -0
- package/src/list-view/list-view.js +8 -1
- package/styles/bootstrap5.3-lite.css +4 -0
- package/styles/bootstrap5.3.css +4 -0
- package/styles/list-view/_theme.scss +1 -1
- package/styles/list-view/bootstrap5.3.css +4 -0
- package/dist/ts/common/index.d.ts +0 -4
- package/dist/ts/common/index.ts +0 -4
- package/dist/ts/common/list-base.d.ts +0 -415
- package/dist/ts/common/list-base.ts +0 -1362
- package/dist/ts/component.d.ts +0 -4
- package/dist/ts/component.ts +0 -4
- package/dist/ts/index.d.ts +0 -6
- package/dist/ts/index.ts +0 -6
- package/dist/ts/list-view/index.d.ts +0 -6
- package/dist/ts/list-view/index.ts +0 -6
- package/dist/ts/list-view/list-view-model.d.ts +0 -324
- package/dist/ts/list-view/list-view.d.ts +0 -844
- package/dist/ts/list-view/list-view.ts +0 -2732
- package/dist/ts/list-view/virtualization.d.ts +0 -97
- package/dist/ts/list-view/virtualization.ts +0 -947
- package/dist/ts/sortable/index.d.ts +0 -5
- package/dist/ts/sortable/index.ts +0 -5
- package/dist/ts/sortable/sortable-model.d.ts +0 -80
- package/dist/ts/sortable/sortable.d.ts +0 -146
- package/dist/ts/sortable/sortable.ts +0 -483
|
@@ -1,483 +0,0 @@
|
|
|
1
|
-
import { Base, Event, getUniqueID, NotifyPropertyChanges, INotifyPropertyChanged, Property, detach, Browser } from '@syncfusion/ej2-base';
|
|
2
|
-
import { closest, Draggable, DragPosition, MouseEventArgs, remove, compareElementParent } from '@syncfusion/ej2-base';
|
|
3
|
-
import { addClass, isNullOrUndefined, getComponent, isBlazor, BlazorDragEventArgs, EventHandler } from '@syncfusion/ej2-base';
|
|
4
|
-
import { SortableModel } from './sortable-model';
|
|
5
|
-
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
/**
|
|
8
|
-
* Sortable Module provides support to enable sortable functionality in Dom Elements.
|
|
9
|
-
* ```html
|
|
10
|
-
* <div id="sortable">
|
|
11
|
-
* <div>Item 1</div>
|
|
12
|
-
* <div>Item 2</div>
|
|
13
|
-
* <div>Item 3</div>
|
|
14
|
-
* <div>Item 4</div>
|
|
15
|
-
* <div>Item 5</div>
|
|
16
|
-
* </div>
|
|
17
|
-
* ```
|
|
18
|
-
* ```typescript
|
|
19
|
-
* let ele: HTMLElement = document.getElementById('sortable');
|
|
20
|
-
* let sortObj: Sortable = new Sortable(ele, {});
|
|
21
|
-
* ```
|
|
22
|
-
*/
|
|
23
|
-
@NotifyPropertyChanges
|
|
24
|
-
export class Sortable extends Base<HTMLElement> implements INotifyPropertyChanged {
|
|
25
|
-
private target: HTMLElement;
|
|
26
|
-
private curTarget: HTMLElement;
|
|
27
|
-
private placeHolderElement: HTMLElement;
|
|
28
|
-
/**
|
|
29
|
-
* It is used to enable or disable the built-in animations. The default value is `false`
|
|
30
|
-
*
|
|
31
|
-
* @default false
|
|
32
|
-
*/
|
|
33
|
-
|
|
34
|
-
@Property(false)
|
|
35
|
-
public enableAnimation: boolean;
|
|
36
|
-
/**
|
|
37
|
-
* Specifies the sortable item class.
|
|
38
|
-
*
|
|
39
|
-
* @default null
|
|
40
|
-
*/
|
|
41
|
-
@Property(null)
|
|
42
|
-
public itemClass: string;
|
|
43
|
-
/**
|
|
44
|
-
* Defines the scope value to group sets of sortable libraries.
|
|
45
|
-
* More than one Sortable with same scope allows to transfer elements between different sortable libraries which has same scope value.
|
|
46
|
-
*/
|
|
47
|
-
@Property(null)
|
|
48
|
-
public scope: string;
|
|
49
|
-
/**
|
|
50
|
-
* Defines the callback function for customizing the cloned element.
|
|
51
|
-
*/
|
|
52
|
-
@Property()
|
|
53
|
-
public helper: (Element: object) => HTMLElement;
|
|
54
|
-
/**
|
|
55
|
-
* Defines the callback function for customizing the placeHolder element.
|
|
56
|
-
*/
|
|
57
|
-
@Property()
|
|
58
|
-
public placeHolder: (Element: object) => HTMLElement;
|
|
59
|
-
/**
|
|
60
|
-
* Specifies the callback function for drag event.
|
|
61
|
-
*
|
|
62
|
-
* @event 'object'
|
|
63
|
-
*/
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
@Event()
|
|
67
|
-
public drag: (e: any) => void;
|
|
68
|
-
/**
|
|
69
|
-
* Specifies the callback function for beforeDragStart event.
|
|
70
|
-
*
|
|
71
|
-
* @event 'object'
|
|
72
|
-
*/
|
|
73
|
-
|
|
74
|
-
@Event()
|
|
75
|
-
public beforeDragStart: (e: any) => void;
|
|
76
|
-
/**
|
|
77
|
-
* Specifies the callback function for dragStart event.
|
|
78
|
-
*
|
|
79
|
-
* @event 'object'
|
|
80
|
-
*/
|
|
81
|
-
|
|
82
|
-
@Event()
|
|
83
|
-
public dragStart: (e: any) => void;
|
|
84
|
-
/**
|
|
85
|
-
* Specifies the callback function for beforeDrop event.
|
|
86
|
-
*
|
|
87
|
-
* @event 'object'
|
|
88
|
-
*/
|
|
89
|
-
|
|
90
|
-
@Event()
|
|
91
|
-
public beforeDrop: (e: any) => void;
|
|
92
|
-
/**
|
|
93
|
-
* Specifies the callback function for drop event.
|
|
94
|
-
*
|
|
95
|
-
* @event 'object'
|
|
96
|
-
*/
|
|
97
|
-
|
|
98
|
-
@Event()
|
|
99
|
-
public drop: (e: any) => void;
|
|
100
|
-
constructor(element: HTMLElement, options?: SortableModel) {
|
|
101
|
-
super(options, element);
|
|
102
|
-
this.bind();
|
|
103
|
-
}
|
|
104
|
-
protected bind(): void {
|
|
105
|
-
if (!this.element.id) {
|
|
106
|
-
this.element.id = getUniqueID('sortable');
|
|
107
|
-
}
|
|
108
|
-
if (!this.itemClass) {
|
|
109
|
-
this.itemClass = 'e-sort-item';
|
|
110
|
-
this.dataBind();
|
|
111
|
-
}
|
|
112
|
-
this.initializeDraggable();
|
|
113
|
-
}
|
|
114
|
-
private initializeDraggable(): void {
|
|
115
|
-
new Draggable(this.element, {
|
|
116
|
-
helper: this.getHelper,
|
|
117
|
-
dragStart: this.onDragStart,
|
|
118
|
-
drag: this.onDrag,
|
|
119
|
-
dragStop: this.onDragStop,
|
|
120
|
-
dragTarget: `.${this.itemClass}`,
|
|
121
|
-
enableTapHold: true,
|
|
122
|
-
tapHoldThreshold: 200,
|
|
123
|
-
queryPositionInfo: this.queryPositionInfo,
|
|
124
|
-
distance: 1
|
|
125
|
-
});
|
|
126
|
-
this.wireEvents();
|
|
127
|
-
}
|
|
128
|
-
private wireEvents(): void {
|
|
129
|
-
const wrapper: Element = this.element;
|
|
130
|
-
EventHandler.add(wrapper, 'keydown', this.keyDownHandler, this);
|
|
131
|
-
}
|
|
132
|
-
private unwireEvents(): void {
|
|
133
|
-
const wrapper: Element = this.element;
|
|
134
|
-
EventHandler.remove(wrapper, 'keydown', this.keyDownHandler);
|
|
135
|
-
}
|
|
136
|
-
private keyDownHandler(e: KeyboardEvent): void {
|
|
137
|
-
if (e.keyCode === 27) {
|
|
138
|
-
const dragStop: Draggable = getComponent(this.element, 'draggable');
|
|
139
|
-
if (dragStop) {
|
|
140
|
-
dragStop.intDestroy(null);
|
|
141
|
-
}
|
|
142
|
-
const dragWrapper: Element = document.getElementsByClassName('e-sortableclone')[0];
|
|
143
|
-
if (dragWrapper) {
|
|
144
|
-
dragWrapper.remove();
|
|
145
|
-
}
|
|
146
|
-
const dragPlaceholder: Element = document.getElementsByClassName('e-sortable-placeholder')[0];
|
|
147
|
-
if (dragPlaceholder) {
|
|
148
|
-
dragPlaceholder.remove();
|
|
149
|
-
}
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
private getPlaceHolder(target: HTMLElement, instance: Sortable): HTMLElement {
|
|
154
|
-
if (instance.placeHolder) {
|
|
155
|
-
const placeHolderElement: HTMLElement = instance.placeHolder(
|
|
156
|
-
{ element: instance.element, grabbedElement: this.target, target: target });
|
|
157
|
-
placeHolderElement.classList.add('e-sortable-placeholder');
|
|
158
|
-
return placeHolderElement;
|
|
159
|
-
}
|
|
160
|
-
return null;
|
|
161
|
-
}
|
|
162
|
-
|
|
163
|
-
private getHelper: Function = (e: { sender: MouseEventArgs, element: HTMLElement }) => {
|
|
164
|
-
const target: HTMLElement = this.getSortableElement(e.sender.target as HTMLElement);
|
|
165
|
-
if (!this.isValidTarget(target as Element, this)) {
|
|
166
|
-
return false;
|
|
167
|
-
}
|
|
168
|
-
let element: HTMLElement;
|
|
169
|
-
if (this.helper) {
|
|
170
|
-
element = this.helper({ sender: target, element: e.element });
|
|
171
|
-
} else {
|
|
172
|
-
element = target.cloneNode(true) as HTMLElement;
|
|
173
|
-
element.style.width = `${target.offsetWidth}px`; element.style.height = `${target.offsetHeight}px`;
|
|
174
|
-
}
|
|
175
|
-
addClass([element], ['e-sortableclone']);
|
|
176
|
-
document.body.appendChild(element);
|
|
177
|
-
return element;
|
|
178
|
-
}
|
|
179
|
-
private isValidTarget(target: Element, instance: Sortable): boolean {
|
|
180
|
-
return target && compareElementParent(target, instance.element) && target.classList.contains(instance.itemClass) &&
|
|
181
|
-
!target.classList.contains('e-disabled');
|
|
182
|
-
}
|
|
183
|
-
private onDrag: Function = (e: { target: HTMLElement, event: MouseEventArgs }) => {
|
|
184
|
-
if (!e.target) { return; }
|
|
185
|
-
this.trigger('drag', { event: e.event, element: this.element, target: e.target });
|
|
186
|
-
let newInst: Sortable = this.getSortableInstance(e.target); let target: HTMLElement = this.getSortableElement(e.target, newInst);
|
|
187
|
-
if ((this.isValidTarget(target, newInst) || (e.target && typeof e.target.className === 'string' && e.target.className.indexOf('e-list-group-item') > -1)) && (this.curTarget !== target ||
|
|
188
|
-
!isNullOrUndefined(newInst.placeHolder)) && (newInst.placeHolderElement ? newInst.placeHolderElement !== e.target : true)) {
|
|
189
|
-
if (e.target.classList.contains('e-list-group-item')) {
|
|
190
|
-
target = e.target;
|
|
191
|
-
}
|
|
192
|
-
this.curTarget = target;
|
|
193
|
-
if (this.target === target) { return; }
|
|
194
|
-
let oldIdx: number = this.getIndex(newInst.placeHolderElement, newInst);
|
|
195
|
-
const placeHolder: HTMLElement = this.getPlaceHolder(target, newInst);
|
|
196
|
-
let newIdx: number;
|
|
197
|
-
if (placeHolder) {
|
|
198
|
-
oldIdx = isNullOrUndefined(oldIdx) ? this.getIndex(this.target) : oldIdx;
|
|
199
|
-
newIdx = this.getIndex(target, newInst, e.event);
|
|
200
|
-
const isPlaceHolderPresent: boolean = this.isPlaceHolderPresent(newInst);
|
|
201
|
-
if (isPlaceHolderPresent && oldIdx === newIdx) { return; }
|
|
202
|
-
if (isPlaceHolderPresent) { this.removePlaceHolder(newInst); }
|
|
203
|
-
newInst.placeHolderElement = placeHolder;
|
|
204
|
-
if (e.target && typeof e.target.className === 'string' && e.target.className.indexOf('e-list-group-item') > -1) {
|
|
205
|
-
newInst.element.insertBefore(newInst.placeHolderElement, newInst.element.children[newIdx as number]);
|
|
206
|
-
} else if (newInst.element !== this.element && newIdx === newInst.element.childElementCount) {
|
|
207
|
-
newInst.element.appendChild(newInst.placeHolderElement);
|
|
208
|
-
} else {
|
|
209
|
-
newInst.element.insertBefore(newInst.placeHolderElement, newInst.element.children[newIdx as number]);
|
|
210
|
-
}
|
|
211
|
-
} else {
|
|
212
|
-
oldIdx = isNullOrUndefined(oldIdx) ? this.getIndex(this.target) :
|
|
213
|
-
this.getIndex(target, newInst) < oldIdx || !oldIdx ? oldIdx : oldIdx - 1;
|
|
214
|
-
newIdx = this.getIndex(target, newInst);
|
|
215
|
-
const idx: number = newInst.element !== this.element ? newIdx : oldIdx < newIdx ? newIdx + 1 : newIdx;
|
|
216
|
-
this.updateItemClass(newInst);
|
|
217
|
-
newInst.element.insertBefore(this.target, newInst.element.children[idx as number]);
|
|
218
|
-
this.curTarget = this.target;
|
|
219
|
-
this.trigger('drop', {
|
|
220
|
-
droppedElement: this.target, element: newInst.element, previousIndex: oldIdx, currentIndex: newIdx,
|
|
221
|
-
target: e.target, helper: document.getElementsByClassName('e-sortableclone')[0], event: e.event, scope: this.scope
|
|
222
|
-
});
|
|
223
|
-
}
|
|
224
|
-
} else if (this.curTarget !== this.target && this.scope && this.curTarget !== target && !isNullOrUndefined(newInst.placeHolder)) {
|
|
225
|
-
this.removePlaceHolder(this.getSortableInstance(this.curTarget));
|
|
226
|
-
this.curTarget = this.target;
|
|
227
|
-
}
|
|
228
|
-
newInst = this.getSortableInstance(this.curTarget);
|
|
229
|
-
if (isNullOrUndefined(target) && e.target !== newInst.placeHolderElement) {
|
|
230
|
-
if (this.isPlaceHolderPresent(newInst)) { this.removePlaceHolder(newInst); }
|
|
231
|
-
} else {
|
|
232
|
-
const placeHolders: Element[] = [].slice.call(document.getElementsByClassName('e-sortable-placeholder')); let inst: Sortable;
|
|
233
|
-
placeHolders.forEach((placeHolder: Element) => {
|
|
234
|
-
inst = this.getSortableInstance(placeHolder);
|
|
235
|
-
if (inst.element && inst !== newInst) { this.removePlaceHolder(inst); }
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
private removePlaceHolder(instance: Sortable): void {
|
|
240
|
-
remove(instance.placeHolderElement);
|
|
241
|
-
instance.placeHolderElement = null;
|
|
242
|
-
}
|
|
243
|
-
private updateItemClass(instance: Sortable): void {
|
|
244
|
-
if (this !== instance) {
|
|
245
|
-
this.target.classList.remove(this.itemClass);
|
|
246
|
-
this.target.classList.add(instance.itemClass);
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
private getSortableInstance(element: Element): Sortable {
|
|
250
|
-
element = closest(element, `.e-${this.getModuleName()}`);
|
|
251
|
-
if (element) {
|
|
252
|
-
const inst: Sortable = getComponent(element as HTMLElement, Sortable) as Sortable;
|
|
253
|
-
return inst.scope && this.scope && inst.scope === this.scope ? inst : this;
|
|
254
|
-
} else {
|
|
255
|
-
return this;
|
|
256
|
-
}
|
|
257
|
-
}
|
|
258
|
-
private getIndex(target: Element, instance: Sortable = this, e?: MouseEventArgs): number {
|
|
259
|
-
let idx: number; let placeHolderPresent: boolean;
|
|
260
|
-
[].slice.call(instance.element.children).forEach((element: HTMLElement, index: number): void => {
|
|
261
|
-
if (element.classList.contains('e-sortable-placeholder')) { placeHolderPresent = true; }
|
|
262
|
-
if (element === target) {
|
|
263
|
-
idx = index;
|
|
264
|
-
if (!isNullOrUndefined(e)) {
|
|
265
|
-
if (placeHolderPresent) { idx -= 1; }
|
|
266
|
-
const offset: ClientRect = target.getBoundingClientRect();
|
|
267
|
-
const clientY: number = offset.bottom - ((offset.bottom - offset.top) / 2);
|
|
268
|
-
const cltY: number = e.changedTouches ? e.changedTouches[0].clientY : e.clientY;
|
|
269
|
-
idx = cltY <= clientY ? idx : idx + 1;
|
|
270
|
-
}
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
});
|
|
274
|
-
return idx;
|
|
275
|
-
}
|
|
276
|
-
private getSortableElement(element: HTMLElement, instance: Sortable = this): HTMLElement {
|
|
277
|
-
return closest(element, `.${instance.itemClass}`) as HTMLElement;
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
private onDragStart: Function = (e: { target: HTMLElement, event: MouseEventArgs, helper: Element } & BlazorDragEventArgs) => {
|
|
281
|
-
this.target = this.getSortableElement(e.target);
|
|
282
|
-
if (isNullOrUndefined(this.target) && closest(this.element, '.e-listbox-container') && Browser.isDevice) {
|
|
283
|
-
detach(e.dragElement);
|
|
284
|
-
(getComponent(this.element, 'draggable') as any).intDestroy(e.event);
|
|
285
|
-
return;
|
|
286
|
-
}
|
|
287
|
-
let cancelDrag: boolean = false;
|
|
288
|
-
this.target.classList.add('e-grabbed');
|
|
289
|
-
this.curTarget = this.target;
|
|
290
|
-
e.helper = document.getElementsByClassName('e-sortableclone')[0];
|
|
291
|
-
const args: object = { cancel: false, element: this.element, target: this.target };
|
|
292
|
-
this.trigger('beforeDragStart', args, (observedArgs: BeforeDragEventArgs) => {
|
|
293
|
-
if (observedArgs.cancel) {
|
|
294
|
-
cancelDrag = observedArgs.cancel;
|
|
295
|
-
this.onDragStop(e);
|
|
296
|
-
}
|
|
297
|
-
});
|
|
298
|
-
if (cancelDrag) {
|
|
299
|
-
return;
|
|
300
|
-
}
|
|
301
|
-
if (isBlazor) {
|
|
302
|
-
this.trigger('dragStart', {
|
|
303
|
-
event: e.event, element: this.element, target: this.target,
|
|
304
|
-
bindEvents: e.bindEvents, dragElement: e.dragElement
|
|
305
|
-
});
|
|
306
|
-
} else {
|
|
307
|
-
this.trigger('dragStart', { event: e.event, element: this.element, target: this.target });
|
|
308
|
-
}
|
|
309
|
-
}
|
|
310
|
-
private queryPositionInfo(value: DragPosition): DragPosition {
|
|
311
|
-
value.left = scrollX ? `${parseFloat(value.left) - scrollX}px` : value.left;
|
|
312
|
-
value.top = scrollY ? `${parseFloat(value.top) - scrollY}px` : value.top;
|
|
313
|
-
return value;
|
|
314
|
-
}
|
|
315
|
-
private isPlaceHolderPresent(instance: Sortable): boolean {
|
|
316
|
-
return instance.placeHolderElement && !!closest(instance.placeHolderElement, `#${instance.element.id}`);
|
|
317
|
-
}
|
|
318
|
-
|
|
319
|
-
private onDragStop: Function = (e: { target: HTMLElement, event: MouseEvent & TouchEvent, helper: Element }) => {
|
|
320
|
-
let dropInst: Sortable = this.getSortableInstance(this.curTarget); let prevIdx: number; let curIdx: number; let handled: boolean;
|
|
321
|
-
prevIdx = this.getIndex(this.target);
|
|
322
|
-
const isPlaceHolderPresent: boolean = this.isPlaceHolderPresent(dropInst);
|
|
323
|
-
if (isPlaceHolderPresent) {
|
|
324
|
-
const curIdx: number = this.getIndex(dropInst.placeHolderElement, dropInst);
|
|
325
|
-
prevIdx = this === dropInst && (prevIdx - curIdx) >= 1 ? prevIdx - 1 : prevIdx;
|
|
326
|
-
const args: DropEventArgs = {
|
|
327
|
-
previousIndex: prevIdx, currentIndex: curIdx, target: e.target, droppedElement: this.target,
|
|
328
|
-
helper: e.helper, cancel: false, handled: false
|
|
329
|
-
};
|
|
330
|
-
this.trigger('beforeDrop', args, (observedArgs: DropEventArgs) => {
|
|
331
|
-
if (!observedArgs.cancel) {
|
|
332
|
-
handled = observedArgs.handled;
|
|
333
|
-
this.updateItemClass(dropInst);
|
|
334
|
-
if (observedArgs.handled) {
|
|
335
|
-
const ele: Node = this.target.cloneNode(true);
|
|
336
|
-
this.target.classList.remove('e-grabbed');
|
|
337
|
-
this.target = ele as HTMLElement;
|
|
338
|
-
}
|
|
339
|
-
dropInst.element.insertBefore(this.target, dropInst.placeHolderElement);
|
|
340
|
-
const curIdx: number = this.getIndex(this.target, dropInst);
|
|
341
|
-
if (observedArgs.currentIndex > observedArgs.previousIndex) {
|
|
342
|
-
prevIdx = this === dropInst && (prevIdx - curIdx) >= 1 ? prevIdx - 1 : prevIdx;
|
|
343
|
-
}
|
|
344
|
-
this.trigger('drop', {
|
|
345
|
-
event: e.event, element: dropInst.element, previousIndex: prevIdx, currentIndex: curIdx,
|
|
346
|
-
target: e.target, helper: e.helper, droppedElement: this.target, scopeName: this.scope, handled: handled
|
|
347
|
-
});
|
|
348
|
-
}
|
|
349
|
-
this.removePlaceHolder(dropInst);
|
|
350
|
-
});
|
|
351
|
-
}
|
|
352
|
-
dropInst = this.getSortableInstance(e.target);
|
|
353
|
-
curIdx = dropInst.element.childElementCount;
|
|
354
|
-
prevIdx = this.getIndex(this.target);
|
|
355
|
-
if (dropInst.element.querySelector('.e-list-nrt')) {
|
|
356
|
-
curIdx = curIdx - 1;
|
|
357
|
-
}
|
|
358
|
-
if (this.curTarget === this.target && e.target === this.curTarget) {
|
|
359
|
-
curIdx = prevIdx;
|
|
360
|
-
}
|
|
361
|
-
if (dropInst.element === e.target || (!isPlaceHolderPresent && this.curTarget === this.target)) {
|
|
362
|
-
const beforeDropArgs: DropEventArgs = {
|
|
363
|
-
previousIndex: prevIdx, currentIndex: curIdx,
|
|
364
|
-
target: e.target, droppedElement: this.target, helper: e.helper, cancel: false
|
|
365
|
-
};
|
|
366
|
-
this.trigger('beforeDrop', beforeDropArgs, (observedArgs: DropEventArgs) => {
|
|
367
|
-
if ((dropInst.element === e.target || (typeof e.target.className === 'string' && e.target.className.indexOf('e-list-nrt') > -1) || (typeof e.target.className === 'string' && e.target.className.indexOf('e-list-nr-template') > -1)
|
|
368
|
-
|| e.target.closest('.e-list-nr-template')) && !observedArgs.cancel) {
|
|
369
|
-
this.updateItemClass(dropInst);
|
|
370
|
-
dropInst.element.appendChild(this.target);
|
|
371
|
-
this.trigger('drop', {
|
|
372
|
-
event: e.event, element: dropInst.element, previousIndex: prevIdx, currentIndex: curIdx,
|
|
373
|
-
target: e.target, helper: e.helper, droppedElement: this.target, scopeName: this.scope
|
|
374
|
-
});
|
|
375
|
-
}
|
|
376
|
-
});
|
|
377
|
-
}
|
|
378
|
-
this.target.classList.remove('e-grabbed');
|
|
379
|
-
this.target = null;
|
|
380
|
-
this.curTarget = null;
|
|
381
|
-
remove(e.helper);
|
|
382
|
-
(getComponent(this.element, 'draggable') as Draggable).intDestroy(e.event);
|
|
383
|
-
}
|
|
384
|
-
/**
|
|
385
|
-
* It is used to sort array of elements from source element to destination element.
|
|
386
|
-
*
|
|
387
|
-
* @param destination - Defines the destination element to which the sortable elements needs to be appended.
|
|
388
|
-
*
|
|
389
|
-
* If it is null, then the Sortable library element will be considered as destination.
|
|
390
|
-
* @param targetIndexes - Specifies the sortable elements indexes which needs to be sorted.
|
|
391
|
-
* @param insertBefore - Specifies the index before which the sortable elements needs to be appended.
|
|
392
|
-
* If it is null, elements will be appended as last child.
|
|
393
|
-
* @function moveTo
|
|
394
|
-
* @returns {void}
|
|
395
|
-
*/
|
|
396
|
-
|
|
397
|
-
public moveTo(destination?: HTMLElement, targetIndexes?: number[], insertBefore?: number): void {
|
|
398
|
-
moveTo(this.element, destination, targetIndexes, insertBefore);
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
/**
|
|
402
|
-
* It is used to destroy the Sortable library.
|
|
403
|
-
*/
|
|
404
|
-
|
|
405
|
-
public destroy(): void {
|
|
406
|
-
this.unwireEvents();
|
|
407
|
-
if (this.itemClass === 'e-sort-item') { this.itemClass = null; this.dataBind(); }
|
|
408
|
-
(getComponent(this.element, Draggable) as Draggable).destroy();
|
|
409
|
-
super.destroy();
|
|
410
|
-
}
|
|
411
|
-
public getModuleName(): string {
|
|
412
|
-
return 'sortable';
|
|
413
|
-
}
|
|
414
|
-
public onPropertyChanged(newProp: SortableModel, oldProp: SortableModel): void {
|
|
415
|
-
for (const prop of Object.keys(newProp)) {
|
|
416
|
-
switch (prop) {
|
|
417
|
-
case 'itemClass':
|
|
418
|
-
[].slice.call(this.element.children).forEach((element: HTMLElement): void => {
|
|
419
|
-
if (element.classList.contains(oldProp.itemClass)) {
|
|
420
|
-
element.classList.remove(oldProp.itemClass);
|
|
421
|
-
}
|
|
422
|
-
if (newProp.itemClass) {
|
|
423
|
-
element.classList.add(newProp.itemClass);
|
|
424
|
-
}
|
|
425
|
-
});
|
|
426
|
-
break;
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* It is used to sort array of elements from source element to destination element.
|
|
434
|
-
*
|
|
435
|
-
* @param {HTMLElement} from - The source element from which to move elements.
|
|
436
|
-
* @param {HTMLElement} [to=from] - The destination element to which to move elements. Defaults to the source element.
|
|
437
|
-
* @param {number[]} [targetIndexes] - The indexes of elements to move. If not provided, all children of the source element will be moved.
|
|
438
|
-
* @param {number} [insertBefore] - The index before which to insert the moved elements in the destination element. If not provided, elements will be appended to the end of the destination element.
|
|
439
|
-
* @returns {void}
|
|
440
|
-
* @private
|
|
441
|
-
*/
|
|
442
|
-
export function moveTo(from: HTMLElement, to?: HTMLElement, targetIndexes?: number[], insertBefore?: number): void {
|
|
443
|
-
let targetElements: Element[] = [];
|
|
444
|
-
if (!to) { to = from; }
|
|
445
|
-
if (targetIndexes && targetIndexes.length) {
|
|
446
|
-
targetIndexes.forEach((index: number): void => {
|
|
447
|
-
targetElements.push(from.children[index as number]);
|
|
448
|
-
});
|
|
449
|
-
} else {
|
|
450
|
-
targetElements = [].slice.call(from.children);
|
|
451
|
-
}
|
|
452
|
-
if (isNullOrUndefined(insertBefore)) {
|
|
453
|
-
targetElements.forEach((target: Element): void => {
|
|
454
|
-
to.appendChild(target);
|
|
455
|
-
});
|
|
456
|
-
} else {
|
|
457
|
-
const insertElement: HTMLElement = to.children[insertBefore as number] as HTMLElement;
|
|
458
|
-
targetElements.forEach((target: Element): void => {
|
|
459
|
-
to.insertBefore(target, insertElement);
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
}
|
|
463
|
-
|
|
464
|
-
/**
|
|
465
|
-
* An interface that holds item drop event arguments
|
|
466
|
-
*/
|
|
467
|
-
export interface DropEventArgs {
|
|
468
|
-
previousIndex: number;
|
|
469
|
-
currentIndex: number;
|
|
470
|
-
droppedElement: Element;
|
|
471
|
-
target: Element;
|
|
472
|
-
helper: Element;
|
|
473
|
-
cancel?: boolean;
|
|
474
|
-
handled?: boolean;
|
|
475
|
-
}
|
|
476
|
-
|
|
477
|
-
/**
|
|
478
|
-
* An interface that holds item before drag event arguments
|
|
479
|
-
*/
|
|
480
|
-
export interface BeforeDragEventArgs {
|
|
481
|
-
cancel?: boolean;
|
|
482
|
-
target: Element;
|
|
483
|
-
}
|