@progress/kendo-angular-listbox 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE.md +11 -0
- package/NOTICE.txt +654 -0
- package/README.md +31 -0
- package/dist/cdn/js/kendo-angular-listbox.js +20 -0
- package/dist/cdn/main.js +5 -0
- package/dist/es/constants.js +65 -0
- package/dist/es/data-binding.directive.js +145 -0
- package/dist/es/index.js +11 -0
- package/dist/es/item-selectable.directive.js +49 -0
- package/dist/es/item-template.directive.js +38 -0
- package/dist/es/listbox.component.js +196 -0
- package/dist/es/listbox.module.js +28 -0
- package/dist/es/main.js +7 -0
- package/dist/es/package-metadata.js +15 -0
- package/dist/es/selection.service.js +30 -0
- package/dist/es/size.js +4 -0
- package/dist/es/toolbar.js +4 -0
- package/dist/es/util.js +38 -0
- package/dist/es2015/constants.d.ts +25 -0
- package/dist/es2015/constants.js +65 -0
- package/dist/es2015/data-binding.directive.d.ts +36 -0
- package/dist/es2015/data-binding.directive.js +140 -0
- package/dist/es2015/index.d.ts +11 -0
- package/dist/es2015/index.js +11 -0
- package/dist/es2015/index.metadata.json +1 -0
- package/dist/es2015/item-selectable.directive.d.ts +15 -0
- package/dist/es2015/item-selectable.directive.js +44 -0
- package/dist/es2015/item-template.directive.d.ts +28 -0
- package/dist/es2015/item-template.directive.js +37 -0
- package/dist/es2015/listbox.component.d.ts +93 -0
- package/dist/es2015/listbox.component.js +216 -0
- package/dist/es2015/listbox.module.d.ts +9 -0
- package/dist/es2015/listbox.module.js +25 -0
- package/dist/es2015/main.d.ts +12 -0
- package/dist/es2015/main.js +7 -0
- package/dist/es2015/package-metadata.d.ts +9 -0
- package/dist/es2015/package-metadata.js +15 -0
- package/dist/es2015/selection.service.d.ts +21 -0
- package/dist/es2015/selection.service.js +32 -0
- package/dist/es2015/size.d.ts +13 -0
- package/dist/es2015/size.js +4 -0
- package/dist/es2015/toolbar.d.ts +42 -0
- package/dist/es2015/toolbar.js +4 -0
- package/dist/es2015/util.d.ts +31 -0
- package/dist/es2015/util.js +38 -0
- package/dist/fesm2015/index.js +565 -0
- package/dist/fesm5/index.js +557 -0
- package/dist/npm/constants.js +67 -0
- package/dist/npm/data-binding.directive.js +147 -0
- package/dist/npm/index.js +17 -0
- package/dist/npm/item-selectable.directive.js +51 -0
- package/dist/npm/item-template.directive.js +40 -0
- package/dist/npm/listbox.component.js +198 -0
- package/dist/npm/listbox.module.js +30 -0
- package/dist/npm/main.js +12 -0
- package/dist/npm/package-metadata.js +17 -0
- package/dist/npm/selection.service.js +32 -0
- package/dist/npm/size.js +6 -0
- package/dist/npm/toolbar.js +6 -0
- package/dist/npm/util.js +40 -0
- package/dist/systemjs/kendo-angular-listbox.js +5 -0
- package/package.json +153 -0
- package/schematics/collection.json +12 -0
- package/schematics/ngAdd/index.js +18 -0
- package/schematics/ngAdd/index.js.map +1 -0
- package/schematics/ngAdd/schema.json +28 -0
|
@@ -0,0 +1,565 @@
|
|
|
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 } from 'tslib';
|
|
6
|
+
import { EventEmitter, Injectable, Directive, TemplateRef, isDevMode, HostBinding, ContentChild, Input, Output, Component, Renderer2, ElementRef, HostListener, NgModule } from '@angular/core';
|
|
7
|
+
import { validatePackage } from '@progress/kendo-licensing';
|
|
8
|
+
import { Subscription } from 'rxjs';
|
|
9
|
+
import { getter } from '@progress/kendo-common';
|
|
10
|
+
import { isChanged } from '@progress/kendo-angular-common';
|
|
11
|
+
import { ButtonsModule } from '@progress/kendo-angular-buttons';
|
|
12
|
+
import { CommonModule } from '@angular/common';
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @hidden
|
|
16
|
+
*/
|
|
17
|
+
const packageMetadata = {
|
|
18
|
+
name: '@progress/kendo-angular-listbox',
|
|
19
|
+
productName: 'Kendo UI for Angular',
|
|
20
|
+
productCodes: ['KENDOUIANGULAR', 'KENDOUICOMPLETE'],
|
|
21
|
+
publishDate: 1649835747,
|
|
22
|
+
version: '',
|
|
23
|
+
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'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* @hidden
|
|
28
|
+
*/
|
|
29
|
+
let ListBoxSelectionService = class ListBoxSelectionService {
|
|
30
|
+
/**
|
|
31
|
+
* @hidden
|
|
32
|
+
*/
|
|
33
|
+
constructor() {
|
|
34
|
+
this.onSelect = new EventEmitter();
|
|
35
|
+
this.selectedIndex = null;
|
|
36
|
+
}
|
|
37
|
+
select(index) {
|
|
38
|
+
this.selectedIndex = index;
|
|
39
|
+
this.onSelect.next({ index: this.selectedIndex });
|
|
40
|
+
}
|
|
41
|
+
isSelected(index) {
|
|
42
|
+
return index === this.selectedIndex;
|
|
43
|
+
}
|
|
44
|
+
clearSelection() {
|
|
45
|
+
this.selectedIndex = null;
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
ListBoxSelectionService = __decorate([
|
|
49
|
+
Injectable()
|
|
50
|
+
], ListBoxSelectionService);
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Renders the ListBox item content. To define the item template, nest an `<ng-template>` tag
|
|
54
|
+
* with the `kendoListBoxItemTemplate` directive inside the `<kendo-listbox>` tag. The template context is
|
|
55
|
+
* set to the current data item.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```ts
|
|
59
|
+
* _@Component({
|
|
60
|
+
* selector: 'my-app',
|
|
61
|
+
* template: `
|
|
62
|
+
* <kendo-listbox [data]="listBoxItems">
|
|
63
|
+
* <ng-template kendoListBoxItemTemplate let-dataItem>
|
|
64
|
+
* <span>{{ dataItem }} item</span>
|
|
65
|
+
* </ng-template>
|
|
66
|
+
* </kendo-listbox>
|
|
67
|
+
* `
|
|
68
|
+
* })
|
|
69
|
+
* ```
|
|
70
|
+
*/
|
|
71
|
+
let ItemTemplateDirective = class ItemTemplateDirective {
|
|
72
|
+
constructor(templateRef) {
|
|
73
|
+
this.templateRef = templateRef;
|
|
74
|
+
}
|
|
75
|
+
};
|
|
76
|
+
ItemTemplateDirective = __decorate([
|
|
77
|
+
Directive({
|
|
78
|
+
selector: '[kendoListBoxItemTemplate]'
|
|
79
|
+
}),
|
|
80
|
+
__metadata("design:paramtypes", [TemplateRef])
|
|
81
|
+
], ItemTemplateDirective);
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @hidden
|
|
85
|
+
*/
|
|
86
|
+
const DEFAULT_TOOLBAR_POSITION = 'right';
|
|
87
|
+
/**
|
|
88
|
+
* @hidden
|
|
89
|
+
*/
|
|
90
|
+
const allTools = [
|
|
91
|
+
{
|
|
92
|
+
name: 'moveUp',
|
|
93
|
+
label: 'Move Up',
|
|
94
|
+
icon: 'arrow-n'
|
|
95
|
+
},
|
|
96
|
+
{
|
|
97
|
+
name: 'moveDown',
|
|
98
|
+
label: 'Move Down',
|
|
99
|
+
icon: 'arrow-s'
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'transferTo',
|
|
103
|
+
label: 'Transfer From',
|
|
104
|
+
icon: 'arrow-w'
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'transferFrom',
|
|
108
|
+
label: 'Transfer To',
|
|
109
|
+
icon: 'arrow-e'
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'transferAllTo',
|
|
113
|
+
label: 'Transfer All To',
|
|
114
|
+
icon: 'arrow-double-60-right'
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: 'transferAllFrom',
|
|
118
|
+
label: 'Transfer All From',
|
|
119
|
+
icon: 'arrow-double-60-left'
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
name: 'remove',
|
|
123
|
+
label: 'Remove',
|
|
124
|
+
icon: 'x'
|
|
125
|
+
}
|
|
126
|
+
];
|
|
127
|
+
/**
|
|
128
|
+
* @hidden
|
|
129
|
+
*/
|
|
130
|
+
const sizeClassMap = {
|
|
131
|
+
small: 'sm',
|
|
132
|
+
medium: 'md',
|
|
133
|
+
large: 'lg'
|
|
134
|
+
};
|
|
135
|
+
/**
|
|
136
|
+
* @hidden
|
|
137
|
+
*/
|
|
138
|
+
const toolbarClasses = {
|
|
139
|
+
left: 'k-listbox-toolbar-left',
|
|
140
|
+
right: 'k-listbox-toolbar-right',
|
|
141
|
+
top: 'k-listbox-toolbar-top',
|
|
142
|
+
bottom: 'k-listbox-toolbar-bottom'
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
/**
|
|
146
|
+
* @hidden
|
|
147
|
+
*/
|
|
148
|
+
const isPresent = (value) => value !== null && value !== undefined;
|
|
149
|
+
/**
|
|
150
|
+
* @hidden
|
|
151
|
+
*/
|
|
152
|
+
const isObject = (value) => isPresent(value) && typeof value === 'object';
|
|
153
|
+
/**
|
|
154
|
+
* @hidden
|
|
155
|
+
*/
|
|
156
|
+
const fieldAccessor = (dataItem, field) => {
|
|
157
|
+
if (!isPresent(dataItem)) {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
if (!isPresent(field) || !isObject(dataItem)) {
|
|
161
|
+
return dataItem;
|
|
162
|
+
}
|
|
163
|
+
// creates a field accessor supporting nested fields processing
|
|
164
|
+
const valueFrom = getter(field);
|
|
165
|
+
return valueFrom(dataItem);
|
|
166
|
+
};
|
|
167
|
+
/**
|
|
168
|
+
* @hidden
|
|
169
|
+
*/
|
|
170
|
+
const defaultItemDisabled = () => false;
|
|
171
|
+
/**
|
|
172
|
+
* @hidden
|
|
173
|
+
*/
|
|
174
|
+
const getTools = (names) => {
|
|
175
|
+
return names.map(tool => allTools.find(meta => meta.name === tool));
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Represents the [Kendo UI ListBox component for Angular]({% slug overview_listbox %}).
|
|
180
|
+
*/
|
|
181
|
+
let ListBoxComponent = class ListBoxComponent {
|
|
182
|
+
constructor(selectionService, renderer, hostElement) {
|
|
183
|
+
this.selectionService = selectionService;
|
|
184
|
+
this.renderer = renderer;
|
|
185
|
+
this.hostElement = hostElement;
|
|
186
|
+
/**
|
|
187
|
+
* @hidden
|
|
188
|
+
*/
|
|
189
|
+
this.listboxClassName = true;
|
|
190
|
+
/**
|
|
191
|
+
* The data which will be displayed by the ListBox.
|
|
192
|
+
*/
|
|
193
|
+
this.data = [];
|
|
194
|
+
/**
|
|
195
|
+
* Sets the size of the component.
|
|
196
|
+
*
|
|
197
|
+
* The possible values are:
|
|
198
|
+
* - `'small'`
|
|
199
|
+
* - `'medium'` (default)
|
|
200
|
+
* - `'large'`
|
|
201
|
+
*/
|
|
202
|
+
this.size = 'medium';
|
|
203
|
+
/**
|
|
204
|
+
* A function which determines if a specific item is disabled.
|
|
205
|
+
*/
|
|
206
|
+
this.itemDisabled = defaultItemDisabled;
|
|
207
|
+
/**
|
|
208
|
+
* Fires when the user selects a different ListBox item. Also fires when a node is moved, since that also changes its index.
|
|
209
|
+
*/
|
|
210
|
+
this.selectionChange = new EventEmitter();
|
|
211
|
+
/**
|
|
212
|
+
* Fires when the user clicks a ListBox item.
|
|
213
|
+
*/
|
|
214
|
+
this.actionClick = new EventEmitter();
|
|
215
|
+
/**
|
|
216
|
+
* @hidden
|
|
217
|
+
*/
|
|
218
|
+
this.selectedTools = allTools;
|
|
219
|
+
this.sub = new Subscription();
|
|
220
|
+
validatePackage(packageMetadata);
|
|
221
|
+
this.setToolbarClass(DEFAULT_TOOLBAR_POSITION);
|
|
222
|
+
this.sub.add(this.selectionService.onSelect.subscribe((e) => {
|
|
223
|
+
this.selectionChange.next(e);
|
|
224
|
+
}));
|
|
225
|
+
}
|
|
226
|
+
/**
|
|
227
|
+
* Sets whether a toolbar should be displayed with the ListBox, as well as what tools and position should be used.
|
|
228
|
+
*/
|
|
229
|
+
set toolbar(config) {
|
|
230
|
+
let position = DEFAULT_TOOLBAR_POSITION;
|
|
231
|
+
if (typeof config === 'boolean') {
|
|
232
|
+
this.selectedTools = config ? allTools : [];
|
|
233
|
+
}
|
|
234
|
+
else {
|
|
235
|
+
this.selectedTools = config.tools ? getTools(config.tools) : allTools;
|
|
236
|
+
if (config.position) {
|
|
237
|
+
position = config.position;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
this.setToolbarClass(position);
|
|
241
|
+
}
|
|
242
|
+
/**
|
|
243
|
+
* @hidden
|
|
244
|
+
*/
|
|
245
|
+
get listClasses() {
|
|
246
|
+
return `k-list k-list-${sizeClassMap[this.size]}`;
|
|
247
|
+
}
|
|
248
|
+
/**
|
|
249
|
+
* @hidden
|
|
250
|
+
*/
|
|
251
|
+
ngOnDestroy() {
|
|
252
|
+
this.sub.unsubscribe();
|
|
253
|
+
}
|
|
254
|
+
/**
|
|
255
|
+
* @hidden
|
|
256
|
+
*/
|
|
257
|
+
performAction(actionName) {
|
|
258
|
+
this.actionClick.next(actionName);
|
|
259
|
+
}
|
|
260
|
+
/**
|
|
261
|
+
* Programmatically selects a ListBox node.
|
|
262
|
+
*/
|
|
263
|
+
selectItem(index) {
|
|
264
|
+
this.selectionService.selectedIndex = index;
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Programmatically clears the ListBox selection.
|
|
268
|
+
*/
|
|
269
|
+
clearSelection() {
|
|
270
|
+
this.selectionService.clearSelection();
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* The index of the currently selected item in the ListBox.
|
|
274
|
+
*/
|
|
275
|
+
get selectedIndex() {
|
|
276
|
+
return this.selectionService.selectedIndex;
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* @hidden
|
|
280
|
+
*/
|
|
281
|
+
getText(dataItem) {
|
|
282
|
+
if (typeof dataItem !== 'string' && !this.textField && isDevMode()) {
|
|
283
|
+
throw new Error('Missing textField input. When passing an array of objects as data, please set the textField input of the ListBox accordingly.');
|
|
284
|
+
}
|
|
285
|
+
return fieldAccessor(dataItem, this.textField);
|
|
286
|
+
}
|
|
287
|
+
setToolbarClass(pos) {
|
|
288
|
+
Object.keys(toolbarClasses).forEach((className) => {
|
|
289
|
+
if (pos === className) {
|
|
290
|
+
this.renderer.addClass(this.hostElement.nativeElement, toolbarClasses[className]);
|
|
291
|
+
}
|
|
292
|
+
else {
|
|
293
|
+
this.renderer.removeClass(this.hostElement.nativeElement, toolbarClasses[className]);
|
|
294
|
+
}
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
};
|
|
298
|
+
__decorate([
|
|
299
|
+
HostBinding('class.k-listbox'),
|
|
300
|
+
__metadata("design:type", Boolean)
|
|
301
|
+
], ListBoxComponent.prototype, "listboxClassName", void 0);
|
|
302
|
+
__decorate([
|
|
303
|
+
ContentChild(ItemTemplateDirective, { static: false }),
|
|
304
|
+
__metadata("design:type", ItemTemplateDirective)
|
|
305
|
+
], ListBoxComponent.prototype, "itemTemplate", void 0);
|
|
306
|
+
__decorate([
|
|
307
|
+
Input(),
|
|
308
|
+
__metadata("design:type", String)
|
|
309
|
+
], ListBoxComponent.prototype, "textField", void 0);
|
|
310
|
+
__decorate([
|
|
311
|
+
Input(),
|
|
312
|
+
__metadata("design:type", Array)
|
|
313
|
+
], ListBoxComponent.prototype, "data", void 0);
|
|
314
|
+
__decorate([
|
|
315
|
+
Input(),
|
|
316
|
+
__metadata("design:type", String)
|
|
317
|
+
], ListBoxComponent.prototype, "size", void 0);
|
|
318
|
+
__decorate([
|
|
319
|
+
Input(),
|
|
320
|
+
__metadata("design:type", Object),
|
|
321
|
+
__metadata("design:paramtypes", [Object])
|
|
322
|
+
], ListBoxComponent.prototype, "toolbar", null);
|
|
323
|
+
__decorate([
|
|
324
|
+
Input(),
|
|
325
|
+
__metadata("design:type", Function)
|
|
326
|
+
], ListBoxComponent.prototype, "itemDisabled", void 0);
|
|
327
|
+
__decorate([
|
|
328
|
+
Output(),
|
|
329
|
+
__metadata("design:type", EventEmitter)
|
|
330
|
+
], ListBoxComponent.prototype, "selectionChange", void 0);
|
|
331
|
+
__decorate([
|
|
332
|
+
Output(),
|
|
333
|
+
__metadata("design:type", EventEmitter)
|
|
334
|
+
], ListBoxComponent.prototype, "actionClick", void 0);
|
|
335
|
+
ListBoxComponent = __decorate([
|
|
336
|
+
Component({
|
|
337
|
+
selector: 'kendo-listbox',
|
|
338
|
+
providers: [ListBoxSelectionService],
|
|
339
|
+
template: `
|
|
340
|
+
<div class="k-listbox-toolbar" *ngIf="selectedTools.length > 0">
|
|
341
|
+
<ul class="k-reset">
|
|
342
|
+
<li *ngFor="let tool of selectedTools">
|
|
343
|
+
<button kendoButton [icon]="tool.icon" (click)="performAction(tool.name)"></button>
|
|
344
|
+
</li>
|
|
345
|
+
|
|
346
|
+
<!-- react moving items has a smoother removal of the style: https://www.telerik.com/kendo-react-ui/components/listbox/ -->
|
|
347
|
+
</ul>
|
|
348
|
+
</div>
|
|
349
|
+
<div class="k-list-scroller k-selectable">
|
|
350
|
+
<div class="{{ listClasses }}">
|
|
351
|
+
<div class="k-list-content">
|
|
352
|
+
<ul class="k-list-ul">
|
|
353
|
+
<li
|
|
354
|
+
class="k-list-item"
|
|
355
|
+
*ngFor="let item of data; let i = index;"
|
|
356
|
+
kendoListBoxItemSelectable
|
|
357
|
+
[index]="i"
|
|
358
|
+
[class.k-disabled]="itemDisabled(item)"
|
|
359
|
+
>
|
|
360
|
+
<ng-template *ngIf="itemTemplate; else defaultItemTemplate"
|
|
361
|
+
[templateContext]="{
|
|
362
|
+
templateRef: itemTemplate.templateRef,
|
|
363
|
+
$implicit: item
|
|
364
|
+
}">
|
|
365
|
+
</ng-template>
|
|
366
|
+
<ng-template #defaultItemTemplate>
|
|
367
|
+
<span class="k-list-item-text">{{ getText(item) }}</span>
|
|
368
|
+
</ng-template>
|
|
369
|
+
</li>
|
|
370
|
+
</ul>
|
|
371
|
+
</div>
|
|
372
|
+
</div>
|
|
373
|
+
</div>
|
|
374
|
+
`
|
|
375
|
+
}),
|
|
376
|
+
__metadata("design:paramtypes", [ListBoxSelectionService,
|
|
377
|
+
Renderer2,
|
|
378
|
+
ElementRef])
|
|
379
|
+
], ListBoxComponent);
|
|
380
|
+
|
|
381
|
+
/**
|
|
382
|
+
* A directive which manages the functoinality of the ListBox tools out of the box, and modifies the provided data accordingly.
|
|
383
|
+
*/
|
|
384
|
+
let DataBindingDirective = class DataBindingDirective {
|
|
385
|
+
constructor(listbox) {
|
|
386
|
+
this.listbox = listbox;
|
|
387
|
+
/**
|
|
388
|
+
* @hidden
|
|
389
|
+
*/
|
|
390
|
+
this.data = [];
|
|
391
|
+
this.sub = new Subscription();
|
|
392
|
+
this.selectedBox = this.listbox;
|
|
393
|
+
this.sub.add(this.listbox.actionClick.subscribe((actionName) => {
|
|
394
|
+
switch (actionName) {
|
|
395
|
+
case 'moveUp': {
|
|
396
|
+
this.moveVertically('up');
|
|
397
|
+
break;
|
|
398
|
+
}
|
|
399
|
+
case 'moveDown': {
|
|
400
|
+
this.moveVertically('down');
|
|
401
|
+
break;
|
|
402
|
+
}
|
|
403
|
+
case 'transferTo': {
|
|
404
|
+
this.transferItem(this.connectedWith, this.listbox);
|
|
405
|
+
break;
|
|
406
|
+
}
|
|
407
|
+
case 'transferFrom': {
|
|
408
|
+
this.transferItem(this.listbox, this.connectedWith);
|
|
409
|
+
break;
|
|
410
|
+
}
|
|
411
|
+
case 'transferAllTo': {
|
|
412
|
+
this.transferAll(this.listbox, this.connectedWith);
|
|
413
|
+
break;
|
|
414
|
+
}
|
|
415
|
+
case 'transferAllFrom': {
|
|
416
|
+
this.transferAll(this.connectedWith, this.listbox);
|
|
417
|
+
break;
|
|
418
|
+
}
|
|
419
|
+
case 'remove': {
|
|
420
|
+
this.removeItem();
|
|
421
|
+
break;
|
|
422
|
+
}
|
|
423
|
+
default: {
|
|
424
|
+
break;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
}));
|
|
428
|
+
}
|
|
429
|
+
/**
|
|
430
|
+
* @hidden
|
|
431
|
+
*/
|
|
432
|
+
ngOnChanges(changes) {
|
|
433
|
+
if (isChanged('connectedWith', changes, false)) {
|
|
434
|
+
this.sub.add(this.listbox.selectionChange.subscribe(() => {
|
|
435
|
+
this.selectedBox = this.listbox;
|
|
436
|
+
this.connectedWith.clearSelection();
|
|
437
|
+
}));
|
|
438
|
+
this.sub.add(this.connectedWith.selectionChange.subscribe(() => {
|
|
439
|
+
this.selectedBox = this.connectedWith;
|
|
440
|
+
this.listbox.clearSelection();
|
|
441
|
+
}));
|
|
442
|
+
}
|
|
443
|
+
if (isChanged('data', changes, true)) {
|
|
444
|
+
this.listbox.data = changes.data.currentValue;
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
/**
|
|
448
|
+
* @hidden
|
|
449
|
+
*/
|
|
450
|
+
ngOnDestroy() {
|
|
451
|
+
this.sub.unsubscribe();
|
|
452
|
+
}
|
|
453
|
+
moveVertically(dir) {
|
|
454
|
+
const index = this.selectedBox.selectedIndex;
|
|
455
|
+
if (!isPresent(index)) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const topReached = dir === 'up' && index <= 0;
|
|
459
|
+
const bottomReached = dir === 'down' && index >= this.selectedBox.data.length - 1;
|
|
460
|
+
if (topReached || bottomReached) {
|
|
461
|
+
return;
|
|
462
|
+
}
|
|
463
|
+
const newIndex = dir === 'up' ? index - 1 : index + 1;
|
|
464
|
+
// ES6 Destructuring swap
|
|
465
|
+
[this.selectedBox.data[newIndex], this.selectedBox.data[index]] = [this.selectedBox.data[index], this.selectedBox.data[newIndex]];
|
|
466
|
+
this.selectedBox.selectionService.select(newIndex);
|
|
467
|
+
}
|
|
468
|
+
removeItem() {
|
|
469
|
+
const index = this.selectedBox.selectedIndex;
|
|
470
|
+
if (!isPresent(index)) {
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
this.selectedBox.data.splice(index, 1);
|
|
474
|
+
this.selectedBox.selectionService.clearSelection();
|
|
475
|
+
}
|
|
476
|
+
transferItem(source, target) {
|
|
477
|
+
const item = source && source.data[source.selectedIndex];
|
|
478
|
+
if (!item || !target || !source) {
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
target.data.push(item);
|
|
482
|
+
source.data.splice(source.selectedIndex, 1);
|
|
483
|
+
source.clearSelection();
|
|
484
|
+
target.selectItem(target.data.length - 1);
|
|
485
|
+
this.selectedBox = target;
|
|
486
|
+
}
|
|
487
|
+
transferAll(source, target) {
|
|
488
|
+
if (!target || !source) {
|
|
489
|
+
return;
|
|
490
|
+
}
|
|
491
|
+
target.data.splice(target.data.length, 0, ...source.data.splice(0, source.data.length));
|
|
492
|
+
target.selectItem(target.data.length - 1);
|
|
493
|
+
this.selectedBox = target;
|
|
494
|
+
}
|
|
495
|
+
};
|
|
496
|
+
__decorate([
|
|
497
|
+
Input('kendoListBoxDataBinding'),
|
|
498
|
+
__metadata("design:type", Array)
|
|
499
|
+
], DataBindingDirective.prototype, "data", void 0);
|
|
500
|
+
__decorate([
|
|
501
|
+
Input(),
|
|
502
|
+
__metadata("design:type", ListBoxComponent)
|
|
503
|
+
], DataBindingDirective.prototype, "connectedWith", void 0);
|
|
504
|
+
DataBindingDirective = __decorate([
|
|
505
|
+
Directive({
|
|
506
|
+
selector: '[kendoListBoxDataBinding]'
|
|
507
|
+
}),
|
|
508
|
+
__metadata("design:paramtypes", [ListBoxComponent])
|
|
509
|
+
], DataBindingDirective);
|
|
510
|
+
|
|
511
|
+
/**
|
|
512
|
+
* @hidden
|
|
513
|
+
*/
|
|
514
|
+
let ItemSelectableDirective = class ItemSelectableDirective {
|
|
515
|
+
constructor(selectionService) {
|
|
516
|
+
this.selectionService = selectionService;
|
|
517
|
+
}
|
|
518
|
+
get selectedClassName() {
|
|
519
|
+
return this.selectionService.isSelected(this.index);
|
|
520
|
+
}
|
|
521
|
+
onClick(event) {
|
|
522
|
+
event.stopPropagation();
|
|
523
|
+
this.selectionService.select(this.index);
|
|
524
|
+
}
|
|
525
|
+
};
|
|
526
|
+
__decorate([
|
|
527
|
+
Input(),
|
|
528
|
+
__metadata("design:type", Number)
|
|
529
|
+
], ItemSelectableDirective.prototype, "index", void 0);
|
|
530
|
+
__decorate([
|
|
531
|
+
HostBinding('class.k-selected'),
|
|
532
|
+
__metadata("design:type", Boolean),
|
|
533
|
+
__metadata("design:paramtypes", [])
|
|
534
|
+
], ItemSelectableDirective.prototype, "selectedClassName", null);
|
|
535
|
+
__decorate([
|
|
536
|
+
HostListener('click', ['$event']),
|
|
537
|
+
__metadata("design:type", Function),
|
|
538
|
+
__metadata("design:paramtypes", [Object]),
|
|
539
|
+
__metadata("design:returntype", void 0)
|
|
540
|
+
], ItemSelectableDirective.prototype, "onClick", null);
|
|
541
|
+
ItemSelectableDirective = __decorate([
|
|
542
|
+
Directive({
|
|
543
|
+
selector: '[kendoListBoxItemSelectable]'
|
|
544
|
+
}),
|
|
545
|
+
__metadata("design:paramtypes", [ListBoxSelectionService])
|
|
546
|
+
], ItemSelectableDirective);
|
|
547
|
+
|
|
548
|
+
/**
|
|
549
|
+
* Represents the [NgModule](https://angular.io/api/core/NgModule) definition for the ListBox component.
|
|
550
|
+
*/
|
|
551
|
+
let ListBoxModule = class ListBoxModule {
|
|
552
|
+
};
|
|
553
|
+
ListBoxModule = __decorate([
|
|
554
|
+
NgModule({
|
|
555
|
+
imports: [ButtonsModule, CommonModule],
|
|
556
|
+
declarations: [ListBoxComponent, ItemTemplateDirective, ItemSelectableDirective, DataBindingDirective],
|
|
557
|
+
exports: [ListBoxComponent, ItemTemplateDirective, ItemSelectableDirective, DataBindingDirective]
|
|
558
|
+
})
|
|
559
|
+
], ListBoxModule);
|
|
560
|
+
|
|
561
|
+
/**
|
|
562
|
+
* Generated bundle index. Do not edit.
|
|
563
|
+
*/
|
|
564
|
+
|
|
565
|
+
export { ItemSelectableDirective, ItemTemplateDirective, ListBoxSelectionService, ListBoxComponent, DataBindingDirective, ListBoxModule };
|