1 | (function (global, factory) {
|
2 | typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('@angular/animations'), require('@angular/common'), require('primeng/dom'), require('primeng/utils'), require('primeng/api'), require('@angular/forms'), require('@angular/cdk/scrolling'), require('primeng/tooltip')) :
|
3 | typeof define === 'function' && define.amd ? define('primeng/multiselect', ['exports', '@angular/core', '@angular/animations', '@angular/common', 'primeng/dom', 'primeng/utils', 'primeng/api', '@angular/forms', '@angular/cdk/scrolling', 'primeng/tooltip'], factory) :
|
4 | (global = global || self, factory((global.primeng = global.primeng || {}, global.primeng.multiselect = {}), global.ng.core, global.ng.animations, global.ng.common, global.primeng.dom, global.primeng.utils, global.primeng.api, global.ng.forms, global.ng.cdk.scrolling, global.primeng.tooltip));
|
5 | }(this, (function (exports, core, animations, common, dom, utils, api, forms, scrolling, tooltip) { 'use strict';
|
6 |
|
7 | var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
|
8 | var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
9 | if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
10 | else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
|
11 | return c > 3 && r && Object.defineProperty(target, key, r), r;
|
12 | };
|
13 | var __read = (this && this.__read) || function (o, n) {
|
14 | var m = typeof Symbol === "function" && o[Symbol.iterator];
|
15 | if (!m) return o;
|
16 | var i = m.call(o), r, ar = [], e;
|
17 | try {
|
18 | while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
|
19 | }
|
20 | catch (error) { e = { error: error }; }
|
21 | finally {
|
22 | try {
|
23 | if (r && !r.done && (m = i["return"])) m.call(i);
|
24 | }
|
25 | finally { if (e) throw e.error; }
|
26 | }
|
27 | return ar;
|
28 | };
|
29 | var __spread = (this && this.__spread) || function () {
|
30 | for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i]));
|
31 | return ar;
|
32 | };
|
33 | var __values = (this && this.__values) || function(o) {
|
34 | var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
35 | if (m) return m.call(o);
|
36 | if (o && typeof o.length === "number") return {
|
37 | next: function () {
|
38 | if (o && i >= o.length) o = void 0;
|
39 | return { value: o && o[i++], done: !o };
|
40 | }
|
41 | };
|
42 | throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
43 | };
|
44 | var MULTISELECT_VALUE_ACCESSOR = {
|
45 | provide: forms.NG_VALUE_ACCESSOR,
|
46 | useExisting: core.forwardRef(function () { return MultiSelect; }),
|
47 | multi: true
|
48 | };
|
49 | var MultiSelectItem = (function () {
|
50 | function MultiSelectItem() {
|
51 | this.onClick = new core.EventEmitter();
|
52 | this.onKeydown = new core.EventEmitter();
|
53 | }
|
54 | MultiSelectItem.prototype.onOptionClick = function (event) {
|
55 | this.onClick.emit({
|
56 | originalEvent: event,
|
57 | option: this.option
|
58 | });
|
59 | };
|
60 | MultiSelectItem.prototype.onOptionKeydown = function (event) {
|
61 | this.onKeydown.emit({
|
62 | originalEvent: event,
|
63 | option: this.option
|
64 | });
|
65 | };
|
66 | __decorate([
|
67 | core.Input()
|
68 | ], MultiSelectItem.prototype, "option", void 0);
|
69 | __decorate([
|
70 | core.Input()
|
71 | ], MultiSelectItem.prototype, "selected", void 0);
|
72 | __decorate([
|
73 | core.Input()
|
74 | ], MultiSelectItem.prototype, "disabled", void 0);
|
75 | __decorate([
|
76 | core.Input()
|
77 | ], MultiSelectItem.prototype, "visible", void 0);
|
78 | __decorate([
|
79 | core.Input()
|
80 | ], MultiSelectItem.prototype, "itemSize", void 0);
|
81 | __decorate([
|
82 | core.Input()
|
83 | ], MultiSelectItem.prototype, "template", void 0);
|
84 | __decorate([
|
85 | core.Input()
|
86 | ], MultiSelectItem.prototype, "maxSelectionLimitReached", void 0);
|
87 | __decorate([
|
88 | core.Output()
|
89 | ], MultiSelectItem.prototype, "onClick", void 0);
|
90 | __decorate([
|
91 | core.Output()
|
92 | ], MultiSelectItem.prototype, "onKeydown", void 0);
|
93 | MultiSelectItem = __decorate([
|
94 | core.Component({
|
95 | selector: 'p-multiSelectItem',
|
96 | template: "\n <li class=\"ui-multiselect-item ui-corner-all\" (click)=\"onOptionClick($event)\" (keydown)=\"onOptionKeydown($event)\" [attr.aria-label]=\"option.label\"\n [style.display]=\"visible ? 'block' : 'none'\" [attr.tabindex]=\"option.disabled ? null : '0'\" [ngStyle]=\"{'height': itemSize + 'px'}\"\n [ngClass]=\"{'ui-state-highlight': selected, 'ui-state-disabled': (option.disabled || (maxSelectionLimitReached && !selected))}\">\n <div class=\"ui-chkbox ui-widget\">\n <div class=\"ui-chkbox-box ui-widget ui-corner-all ui-state-default\"\n [ngClass]=\"{'ui-state-active': selected}\">\n <span class=\"ui-chkbox-icon ui-clickable\" [ngClass]=\"{'pi pi-check': selected}\"></span>\n </div>\n </div>\n <span *ngIf=\"!template\">{{option.label}}</span>\n <ng-container *ngTemplateOutlet=\"template; context: {$implicit: option}\"></ng-container>\n </li>\n "
|
97 | })
|
98 | ], MultiSelectItem);
|
99 | return MultiSelectItem;
|
100 | }());
|
101 | var MultiSelect = (function () {
|
102 | function MultiSelect(el, renderer, cd) {
|
103 | this.el = el;
|
104 | this.renderer = renderer;
|
105 | this.cd = cd;
|
106 | this.scrollHeight = '200px';
|
107 | this._defaultLabel = 'Choose';
|
108 | this.filter = true;
|
109 | this.displaySelectedLabel = true;
|
110 | this.maxSelectedLabels = 3;
|
111 | this.selectedItemsLabel = '{0} items selected';
|
112 | this.showToggleAll = true;
|
113 | this.emptyFilterMessage = 'No results found';
|
114 | this.resetFilterOnHide = false;
|
115 | this.dropdownIcon = 'pi pi-chevron-down';
|
116 | this.showHeader = true;
|
117 | this.autoZIndex = true;
|
118 | this.baseZIndex = 0;
|
119 | this.filterBy = 'label';
|
120 | this.showTransitionOptions = '225ms ease-out';
|
121 | this.hideTransitionOptions = '195ms ease-in';
|
122 | this.filterMatchMode = "contains";
|
123 | this.tooltip = '';
|
124 | this.tooltipPosition = 'right';
|
125 | this.tooltipPositionStyle = 'absolute';
|
126 | this.autofocusFilter = true;
|
127 | this.onChange = new core.EventEmitter();
|
128 | this.onFocus = new core.EventEmitter();
|
129 | this.onBlur = new core.EventEmitter();
|
130 | this.onClick = new core.EventEmitter();
|
131 | this.onPanelShow = new core.EventEmitter();
|
132 | this.onPanelHide = new core.EventEmitter();
|
133 | this.onModelChange = function () { };
|
134 | this.onModelTouched = function () { };
|
135 | this.disabledSelectedOptions = [];
|
136 | }
|
137 | Object.defineProperty(MultiSelect.prototype, "defaultLabel", {
|
138 | get: function () {
|
139 | return this._defaultLabel;
|
140 | },
|
141 | set: function (val) {
|
142 | this._defaultLabel = val;
|
143 | this.updateLabel();
|
144 | },
|
145 | enumerable: true,
|
146 | configurable: true
|
147 | });
|
148 | Object.defineProperty(MultiSelect.prototype, "options", {
|
149 | get: function () {
|
150 | return this._options;
|
151 | },
|
152 | set: function (val) {
|
153 | var opts = this.optionLabel ? utils.ObjectUtils.generateSelectItems(val, this.optionLabel) : val;
|
154 | this.visibleOptions = opts;
|
155 | this._options = opts;
|
156 | this.updateLabel();
|
157 | if (this.filterValue && this.filterValue.length) {
|
158 | this.activateFilter();
|
159 | }
|
160 | },
|
161 | enumerable: true,
|
162 | configurable: true
|
163 | });
|
164 | MultiSelect.prototype.ngOnInit = function () {
|
165 | this.updateLabel();
|
166 | };
|
167 | MultiSelect.prototype.ngAfterContentInit = function () {
|
168 | var _this = this;
|
169 | this.templates.forEach(function (item) {
|
170 | switch (item.getType()) {
|
171 | case 'item':
|
172 | _this.itemTemplate = item.template;
|
173 | break;
|
174 | case 'selectedItems':
|
175 | _this.selectedItemsTemplate = item.template;
|
176 | break;
|
177 | default:
|
178 | _this.itemTemplate = item.template;
|
179 | break;
|
180 | }
|
181 | });
|
182 | };
|
183 | MultiSelect.prototype.ngAfterViewInit = function () {
|
184 | if (this.overlayVisible) {
|
185 | this.show();
|
186 | }
|
187 | };
|
188 | MultiSelect.prototype.ngAfterViewChecked = function () {
|
189 | if (this.filtered) {
|
190 | this.alignOverlay();
|
191 | this.filtered = false;
|
192 | }
|
193 | };
|
194 | MultiSelect.prototype.writeValue = function (value) {
|
195 | this.value = value;
|
196 | this.updateLabel();
|
197 | this.updateFilledState();
|
198 | this.setDisabledSelectedOptions();
|
199 | this.checkSelectionLimit();
|
200 | this.cd.markForCheck();
|
201 | };
|
202 | MultiSelect.prototype.checkSelectionLimit = function () {
|
203 | if (this.selectionLimit && (this.value && this.value.length === this.selectionLimit)) {
|
204 | this.maxSelectionLimitReached = true;
|
205 | }
|
206 | else {
|
207 | this.maxSelectionLimitReached = false;
|
208 | }
|
209 | };
|
210 | MultiSelect.prototype.updateFilledState = function () {
|
211 | this.filled = (this.value && this.value.length > 0);
|
212 | };
|
213 | MultiSelect.prototype.registerOnChange = function (fn) {
|
214 | this.onModelChange = fn;
|
215 | };
|
216 | MultiSelect.prototype.registerOnTouched = function (fn) {
|
217 | this.onModelTouched = fn;
|
218 | };
|
219 | MultiSelect.prototype.setDisabledState = function (val) {
|
220 | this.disabled = val;
|
221 | };
|
222 | MultiSelect.prototype.onOptionClick = function (event) {
|
223 | var option = event.option;
|
224 | if (option.disabled) {
|
225 | return;
|
226 | }
|
227 | var optionValue = option.value;
|
228 | var selectionIndex = this.findSelectionIndex(optionValue);
|
229 | if (selectionIndex != -1) {
|
230 | this.value = this.value.filter(function (val, i) { return i != selectionIndex; });
|
231 | if (this.selectionLimit) {
|
232 | this.maxSelectionLimitReached = false;
|
233 | }
|
234 | }
|
235 | else {
|
236 | if (!this.selectionLimit || (!this.value || this.value.length < this.selectionLimit)) {
|
237 | this.value = __spread(this.value || [], [optionValue]);
|
238 | }
|
239 | this.checkSelectionLimit();
|
240 | }
|
241 | this.onModelChange(this.value);
|
242 | this.onChange.emit({ originalEvent: event.originalEvent, value: this.value, itemValue: optionValue });
|
243 | this.updateLabel();
|
244 | this.updateFilledState();
|
245 | };
|
246 | MultiSelect.prototype.isSelected = function (value) {
|
247 | return this.findSelectionIndex(value) != -1;
|
248 | };
|
249 | MultiSelect.prototype.findSelectionIndex = function (val) {
|
250 | var index = -1;
|
251 | if (this.value) {
|
252 | for (var i = 0; i < this.value.length; i++) {
|
253 | if (utils.ObjectUtils.equals(this.value[i], val, this.dataKey)) {
|
254 | index = i;
|
255 | break;
|
256 | }
|
257 | }
|
258 | }
|
259 | return index;
|
260 | };
|
261 | MultiSelect.prototype.toggleAll = function (event) {
|
262 | if (this.isAllChecked()) {
|
263 | if (this.disabledSelectedOptions && this.disabledSelectedOptions.length > 0) {
|
264 | var value = [];
|
265 | value = __spread(this.disabledSelectedOptions);
|
266 | this.value = value;
|
267 | }
|
268 | else {
|
269 | this.value = [];
|
270 | }
|
271 | }
|
272 | else {
|
273 | var opts = this.getVisibleOptions();
|
274 | if (opts) {
|
275 | var value = [];
|
276 | if (this.disabledSelectedOptions && this.disabledSelectedOptions.length > 0) {
|
277 | value = __spread(this.disabledSelectedOptions);
|
278 | }
|
279 | for (var i = 0; i < opts.length; i++) {
|
280 | var option = opts[i];
|
281 | if (!option.disabled) {
|
282 | value.push(opts[i].value);
|
283 | }
|
284 | }
|
285 | this.value = value;
|
286 | }
|
287 | }
|
288 | this.onModelChange(this.value);
|
289 | this.onChange.emit({ originalEvent: event, value: this.value });
|
290 | this.updateFilledState();
|
291 | this.updateLabel();
|
292 | };
|
293 | MultiSelect.prototype.isAllChecked = function () {
|
294 | if (this.filterValue && this.filterValue.trim().length) {
|
295 | return this.value && this.visibleOptions && this.visibleOptions.length && this.isAllVisibleOptionsChecked();
|
296 | }
|
297 | else {
|
298 | var optionCount = this.getEnabledOptionCount();
|
299 | var disabledSelectedOptionCount = this.disabledSelectedOptions.length;
|
300 | return this.value && this.options && (this.value.length > 0 && this.value.length == optionCount + disabledSelectedOptionCount);
|
301 | }
|
302 | };
|
303 | MultiSelect.prototype.isAllVisibleOptionsChecked = function () {
|
304 | var e_1, _a;
|
305 | if (!this.visibleOptions || this.visibleOptions.length === 0) {
|
306 | return false;
|
307 | }
|
308 | else {
|
309 | try {
|
310 | for (var _b = __values(this.visibleOptions), _c = _b.next(); !_c.done; _c = _b.next()) {
|
311 | var option = _c.value;
|
312 | if (!this.isSelected(option.value)) {
|
313 | return false;
|
314 | }
|
315 | }
|
316 | }
|
317 | catch (e_1_1) { e_1 = { error: e_1_1 }; }
|
318 | finally {
|
319 | try {
|
320 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
321 | }
|
322 | finally { if (e_1) throw e_1.error; }
|
323 | }
|
324 | return true;
|
325 | }
|
326 | };
|
327 | MultiSelect.prototype.getEnabledOptionCount = function () {
|
328 | var e_2, _a;
|
329 | if (this.options) {
|
330 | var count = 0;
|
331 | try {
|
332 | for (var _b = __values(this.options), _c = _b.next(); !_c.done; _c = _b.next()) {
|
333 | var opt = _c.value;
|
334 | if (!opt.disabled) {
|
335 | count++;
|
336 | }
|
337 | }
|
338 | }
|
339 | catch (e_2_1) { e_2 = { error: e_2_1 }; }
|
340 | finally {
|
341 | try {
|
342 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
343 | }
|
344 | finally { if (e_2) throw e_2.error; }
|
345 | }
|
346 | return count;
|
347 | }
|
348 | else {
|
349 | return 0;
|
350 | }
|
351 | };
|
352 | MultiSelect.prototype.setDisabledSelectedOptions = function () {
|
353 | var e_3, _a;
|
354 | if (this.options) {
|
355 | this.disabledSelectedOptions = [];
|
356 | if (this.value) {
|
357 | try {
|
358 | for (var _b = __values(this.options), _c = _b.next(); !_c.done; _c = _b.next()) {
|
359 | var opt = _c.value;
|
360 | if (opt.disabled && this.isSelected(opt.value)) {
|
361 | this.disabledSelectedOptions.push(opt.value);
|
362 | }
|
363 | }
|
364 | }
|
365 | catch (e_3_1) { e_3 = { error: e_3_1 }; }
|
366 | finally {
|
367 | try {
|
368 | if (_c && !_c.done && (_a = _b.return)) _a.call(_b);
|
369 | }
|
370 | finally { if (e_3) throw e_3.error; }
|
371 | }
|
372 | }
|
373 | }
|
374 | };
|
375 | MultiSelect.prototype.show = function () {
|
376 | if (!this.overlayVisible) {
|
377 | this.overlayVisible = true;
|
378 | }
|
379 | };
|
380 | MultiSelect.prototype.onOverlayAnimationStart = function (event) {
|
381 | switch (event.toState) {
|
382 | case 'visible':
|
383 | this.overlay = event.element;
|
384 | this.appendOverlay();
|
385 | if (this.autoZIndex) {
|
386 | this.overlay.style.zIndex = String(this.baseZIndex + (++dom.DomHandler.zindex));
|
387 | }
|
388 | this.alignOverlay();
|
389 | this.bindDocumentClickListener();
|
390 | this.bindDocumentResizeListener();
|
391 | if (this.filterInputChild && this.filterInputChild.nativeElement) {
|
392 | this.preventModelTouched = true;
|
393 | if (this.autofocusFilter) {
|
394 | this.filterInputChild.nativeElement.focus();
|
395 | }
|
396 | }
|
397 | this.onPanelShow.emit();
|
398 | break;
|
399 | case 'void':
|
400 | this.onOverlayHide();
|
401 | break;
|
402 | }
|
403 | };
|
404 | MultiSelect.prototype.appendOverlay = function () {
|
405 | if (this.appendTo) {
|
406 | if (this.appendTo === 'body')
|
407 | document.body.appendChild(this.overlay);
|
408 | else
|
409 | dom.DomHandler.appendChild(this.overlay, this.appendTo);
|
410 | if (!this.overlay.style.minWidth) {
|
411 | this.overlay.style.minWidth = dom.DomHandler.getWidth(this.containerViewChild.nativeElement) + 'px';
|
412 | }
|
413 | }
|
414 | };
|
415 | MultiSelect.prototype.restoreOverlayAppend = function () {
|
416 | if (this.overlay && this.appendTo) {
|
417 | this.el.nativeElement.appendChild(this.overlay);
|
418 | }
|
419 | };
|
420 | MultiSelect.prototype.alignOverlay = function () {
|
421 | if (this.overlay) {
|
422 | if (this.appendTo)
|
423 | dom.DomHandler.absolutePosition(this.overlay, this.containerViewChild.nativeElement);
|
424 | else
|
425 | dom.DomHandler.relativePosition(this.overlay, this.containerViewChild.nativeElement);
|
426 | }
|
427 | };
|
428 | MultiSelect.prototype.hide = function () {
|
429 | this.overlayVisible = false;
|
430 | this.unbindDocumentClickListener();
|
431 | if (this.resetFilterOnHide) {
|
432 | this.filterInputChild.nativeElement.value = '';
|
433 | this.onFilter();
|
434 | }
|
435 | this.onPanelHide.emit();
|
436 | };
|
437 | MultiSelect.prototype.close = function (event) {
|
438 | this.hide();
|
439 | event.preventDefault();
|
440 | event.stopPropagation();
|
441 | };
|
442 | MultiSelect.prototype.onMouseclick = function (event, input) {
|
443 | if (this.disabled || this.readonly) {
|
444 | return;
|
445 | }
|
446 | this.onClick.emit(event);
|
447 | if (!this.panelClick) {
|
448 | if (this.overlayVisible) {
|
449 | this.hide();
|
450 | }
|
451 | else {
|
452 | input.focus();
|
453 | this.show();
|
454 | }
|
455 | }
|
456 | this.selfClick = true;
|
457 | };
|
458 | MultiSelect.prototype.onInputFocus = function (event) {
|
459 | this.focus = true;
|
460 | this.onFocus.emit({ originalEvent: event });
|
461 | };
|
462 | MultiSelect.prototype.onInputBlur = function (event) {
|
463 | this.focus = false;
|
464 | this.onBlur.emit({ originalEvent: event });
|
465 | if (!this.preventModelTouched) {
|
466 | this.onModelTouched();
|
467 | }
|
468 | this.preventModelTouched = false;
|
469 | };
|
470 | MultiSelect.prototype.onOptionKeydown = function (event) {
|
471 | if (this.readonly) {
|
472 | return;
|
473 | }
|
474 | switch (event.originalEvent.which) {
|
475 |
|
476 | case 40:
|
477 | var nextItem = this.findNextItem(event.originalEvent.target.parentElement);
|
478 | if (nextItem) {
|
479 | nextItem.focus();
|
480 | }
|
481 | event.originalEvent.preventDefault();
|
482 | break;
|
483 |
|
484 | case 38:
|
485 | var prevItem = this.findPrevItem(event.originalEvent.target.parentElement);
|
486 | if (prevItem) {
|
487 | prevItem.focus();
|
488 | }
|
489 | event.originalEvent.preventDefault();
|
490 | break;
|
491 |
|
492 | case 13:
|
493 | this.onOptionClick(event);
|
494 | event.originalEvent.preventDefault();
|
495 | break;
|
496 | }
|
497 | };
|
498 | MultiSelect.prototype.findNextItem = function (item) {
|
499 | var nextItem = item.nextElementSibling;
|
500 | if (nextItem)
|
501 | return dom.DomHandler.hasClass(nextItem.children[0], 'ui-state-disabled') || dom.DomHandler.isHidden(nextItem.children[0]) ? this.findNextItem(nextItem) : nextItem.children[0];
|
502 | else
|
503 | return null;
|
504 | };
|
505 | MultiSelect.prototype.findPrevItem = function (item) {
|
506 | var prevItem = item.previousElementSibling;
|
507 | if (prevItem)
|
508 | return dom.DomHandler.hasClass(prevItem.children[0], 'ui-state-disabled') || dom.DomHandler.isHidden(prevItem.children[0]) ? this.findPrevItem(prevItem) : prevItem.children[0];
|
509 | else
|
510 | return null;
|
511 | };
|
512 | MultiSelect.prototype.onKeydown = function (event) {
|
513 | switch (event.which) {
|
514 |
|
515 | case 40:
|
516 | if (!this.overlayVisible && event.altKey) {
|
517 | this.show();
|
518 | event.preventDefault();
|
519 | }
|
520 | break;
|
521 |
|
522 | case 32:
|
523 | if (!this.overlayVisible) {
|
524 | this.show();
|
525 | event.preventDefault();
|
526 | }
|
527 | break;
|
528 |
|
529 | case 27:
|
530 | this.hide();
|
531 | break;
|
532 | }
|
533 | };
|
534 | MultiSelect.prototype.updateLabel = function () {
|
535 | if (this.value && this.options && this.value.length && this.displaySelectedLabel) {
|
536 | var label = '';
|
537 | for (var i = 0; i < this.value.length; i++) {
|
538 | var itemLabel = this.findLabelByValue(this.value[i]);
|
539 | if (itemLabel) {
|
540 | if (label.length > 0) {
|
541 | label = label + ', ';
|
542 | }
|
543 | label = label + itemLabel;
|
544 | }
|
545 | }
|
546 | if (this.value.length <= this.maxSelectedLabels) {
|
547 | this.valuesAsString = label;
|
548 | }
|
549 | else {
|
550 | var pattern = /{(.*?)}/;
|
551 | if (pattern.test(this.selectedItemsLabel)) {
|
552 | this.valuesAsString = this.selectedItemsLabel.replace(this.selectedItemsLabel.match(pattern)[0], this.value.length + '');
|
553 | }
|
554 | else {
|
555 | this.valuesAsString = this.selectedItemsLabel;
|
556 | }
|
557 | }
|
558 | }
|
559 | else {
|
560 | this.valuesAsString = this.defaultLabel;
|
561 | }
|
562 | };
|
563 | MultiSelect.prototype.findLabelByValue = function (val) {
|
564 | var label = null;
|
565 | for (var i = 0; i < this.options.length; i++) {
|
566 | var option = this.options[i];
|
567 | if (val == null && option.value == null || utils.ObjectUtils.equals(val, option.value, this.dataKey)) {
|
568 | label = option.label;
|
569 | break;
|
570 | }
|
571 | }
|
572 | return label;
|
573 | };
|
574 | MultiSelect.prototype.onFilter = function () {
|
575 | var inputValue = this.filterInputChild.nativeElement.value;
|
576 | if (inputValue && inputValue.length) {
|
577 | this.filterValue = inputValue;
|
578 | this.activateFilter();
|
579 | }
|
580 | else {
|
581 | this.filterValue = null;
|
582 | this.visibleOptions = this.options;
|
583 | this.filtered = false;
|
584 | }
|
585 | };
|
586 | MultiSelect.prototype.activateFilter = function () {
|
587 | if (this.options && this.options.length) {
|
588 | var searchFields = this.filterBy.split(',');
|
589 | this.visibleOptions = utils.FilterUtils.filter(this.options, searchFields, this.filterValue, this.filterMatchMode, this.filterLocale);
|
590 | this.filtered = true;
|
591 | }
|
592 | };
|
593 | MultiSelect.prototype.isItemVisible = function (option) {
|
594 | if (this.filterValue && this.filterValue.trim().length) {
|
595 | for (var i = 0; i < this.visibleOptions.length; i++) {
|
596 | if (this.visibleOptions[i].value == option.value) {
|
597 | return true;
|
598 | }
|
599 | }
|
600 | }
|
601 | else {
|
602 | return true;
|
603 | }
|
604 | };
|
605 | MultiSelect.prototype.getVisibleOptions = function () {
|
606 | return this.visibleOptions || this.options;
|
607 | };
|
608 | MultiSelect.prototype.onHeaderCheckboxFocus = function () {
|
609 | this.headerCheckboxFocus = true;
|
610 | };
|
611 | MultiSelect.prototype.onHeaderCheckboxBlur = function () {
|
612 | this.headerCheckboxFocus = false;
|
613 | };
|
614 | MultiSelect.prototype.bindDocumentClickListener = function () {
|
615 | var _this = this;
|
616 | if (!this.documentClickListener) {
|
617 | this.documentClickListener = this.renderer.listen('document', 'click', function () {
|
618 | if (!_this.selfClick && !_this.panelClick && _this.overlayVisible) {
|
619 | _this.hide();
|
620 | }
|
621 | _this.selfClick = false;
|
622 | _this.panelClick = false;
|
623 | _this.cd.markForCheck();
|
624 | });
|
625 | }
|
626 | };
|
627 | MultiSelect.prototype.unbindDocumentClickListener = function () {
|
628 | if (this.documentClickListener) {
|
629 | this.documentClickListener();
|
630 | this.documentClickListener = null;
|
631 | }
|
632 | };
|
633 | MultiSelect.prototype.bindDocumentResizeListener = function () {
|
634 | this.documentResizeListener = this.onWindowResize.bind(this);
|
635 | window.addEventListener('resize', this.documentResizeListener);
|
636 | };
|
637 | MultiSelect.prototype.unbindDocumentResizeListener = function () {
|
638 | if (this.documentResizeListener) {
|
639 | window.removeEventListener('resize', this.documentResizeListener);
|
640 | this.documentResizeListener = null;
|
641 | }
|
642 | };
|
643 | MultiSelect.prototype.onWindowResize = function () {
|
644 | if (!dom.DomHandler.isAndroid()) {
|
645 | this.hide();
|
646 | }
|
647 | };
|
648 | MultiSelect.prototype.onOverlayHide = function () {
|
649 | this.unbindDocumentClickListener();
|
650 | this.unbindDocumentResizeListener();
|
651 | this.overlay = null;
|
652 | this.onModelTouched();
|
653 | };
|
654 | MultiSelect.prototype.ngOnDestroy = function () {
|
655 | this.restoreOverlayAppend();
|
656 | this.onOverlayHide();
|
657 | };
|
658 | MultiSelect.ctorParameters = function () { return [
|
659 | { type: core.ElementRef },
|
660 | { type: core.Renderer2 },
|
661 | { type: core.ChangeDetectorRef }
|
662 | ]; };
|
663 | __decorate([
|
664 | core.Input()
|
665 | ], MultiSelect.prototype, "scrollHeight", void 0);
|
666 | __decorate([
|
667 | core.Input()
|
668 | ], MultiSelect.prototype, "defaultLabel", null);
|
669 | __decorate([
|
670 | core.Input()
|
671 | ], MultiSelect.prototype, "style", void 0);
|
672 | __decorate([
|
673 | core.Input()
|
674 | ], MultiSelect.prototype, "styleClass", void 0);
|
675 | __decorate([
|
676 | core.Input()
|
677 | ], MultiSelect.prototype, "panelStyle", void 0);
|
678 | __decorate([
|
679 | core.Input()
|
680 | ], MultiSelect.prototype, "panelStyleClass", void 0);
|
681 | __decorate([
|
682 | core.Input()
|
683 | ], MultiSelect.prototype, "inputId", void 0);
|
684 | __decorate([
|
685 | core.Input()
|
686 | ], MultiSelect.prototype, "disabled", void 0);
|
687 | __decorate([
|
688 | core.Input()
|
689 | ], MultiSelect.prototype, "readonly", void 0);
|
690 | __decorate([
|
691 | core.Input()
|
692 | ], MultiSelect.prototype, "filter", void 0);
|
693 | __decorate([
|
694 | core.Input()
|
695 | ], MultiSelect.prototype, "filterPlaceHolder", void 0);
|
696 | __decorate([
|
697 | core.Input()
|
698 | ], MultiSelect.prototype, "filterLocale", void 0);
|
699 | __decorate([
|
700 | core.Input()
|
701 | ], MultiSelect.prototype, "overlayVisible", void 0);
|
702 | __decorate([
|
703 | core.Input()
|
704 | ], MultiSelect.prototype, "tabindex", void 0);
|
705 | __decorate([
|
706 | core.Input()
|
707 | ], MultiSelect.prototype, "appendTo", void 0);
|
708 | __decorate([
|
709 | core.Input()
|
710 | ], MultiSelect.prototype, "dataKey", void 0);
|
711 | __decorate([
|
712 | core.Input()
|
713 | ], MultiSelect.prototype, "name", void 0);
|
714 | __decorate([
|
715 | core.Input()
|
716 | ], MultiSelect.prototype, "ariaLabelledBy", void 0);
|
717 | __decorate([
|
718 | core.Input()
|
719 | ], MultiSelect.prototype, "displaySelectedLabel", void 0);
|
720 | __decorate([
|
721 | core.Input()
|
722 | ], MultiSelect.prototype, "maxSelectedLabels", void 0);
|
723 | __decorate([
|
724 | core.Input()
|
725 | ], MultiSelect.prototype, "selectionLimit", void 0);
|
726 | __decorate([
|
727 | core.Input()
|
728 | ], MultiSelect.prototype, "selectedItemsLabel", void 0);
|
729 | __decorate([
|
730 | core.Input()
|
731 | ], MultiSelect.prototype, "showToggleAll", void 0);
|
732 | __decorate([
|
733 | core.Input()
|
734 | ], MultiSelect.prototype, "emptyFilterMessage", void 0);
|
735 | __decorate([
|
736 | core.Input()
|
737 | ], MultiSelect.prototype, "resetFilterOnHide", void 0);
|
738 | __decorate([
|
739 | core.Input()
|
740 | ], MultiSelect.prototype, "dropdownIcon", void 0);
|
741 | __decorate([
|
742 | core.Input()
|
743 | ], MultiSelect.prototype, "optionLabel", void 0);
|
744 | __decorate([
|
745 | core.Input()
|
746 | ], MultiSelect.prototype, "showHeader", void 0);
|
747 | __decorate([
|
748 | core.Input()
|
749 | ], MultiSelect.prototype, "autoZIndex", void 0);
|
750 | __decorate([
|
751 | core.Input()
|
752 | ], MultiSelect.prototype, "baseZIndex", void 0);
|
753 | __decorate([
|
754 | core.Input()
|
755 | ], MultiSelect.prototype, "filterBy", void 0);
|
756 | __decorate([
|
757 | core.Input()
|
758 | ], MultiSelect.prototype, "virtualScroll", void 0);
|
759 | __decorate([
|
760 | core.Input()
|
761 | ], MultiSelect.prototype, "itemSize", void 0);
|
762 | __decorate([
|
763 | core.Input()
|
764 | ], MultiSelect.prototype, "showTransitionOptions", void 0);
|
765 | __decorate([
|
766 | core.Input()
|
767 | ], MultiSelect.prototype, "hideTransitionOptions", void 0);
|
768 | __decorate([
|
769 | core.Input()
|
770 | ], MultiSelect.prototype, "ariaFilterLabel", void 0);
|
771 | __decorate([
|
772 | core.Input()
|
773 | ], MultiSelect.prototype, "filterMatchMode", void 0);
|
774 | __decorate([
|
775 | core.Input()
|
776 | ], MultiSelect.prototype, "tooltip", void 0);
|
777 | __decorate([
|
778 | core.Input()
|
779 | ], MultiSelect.prototype, "tooltipPosition", void 0);
|
780 | __decorate([
|
781 | core.Input()
|
782 | ], MultiSelect.prototype, "tooltipPositionStyle", void 0);
|
783 | __decorate([
|
784 | core.Input()
|
785 | ], MultiSelect.prototype, "tooltipStyleClass", void 0);
|
786 | __decorate([
|
787 | core.Input()
|
788 | ], MultiSelect.prototype, "autofocusFilter", void 0);
|
789 | __decorate([
|
790 | core.ViewChild('container')
|
791 | ], MultiSelect.prototype, "containerViewChild", void 0);
|
792 | __decorate([
|
793 | core.ViewChild('filterInput')
|
794 | ], MultiSelect.prototype, "filterInputChild", void 0);
|
795 | __decorate([
|
796 | core.ContentChild(api.Footer)
|
797 | ], MultiSelect.prototype, "footerFacet", void 0);
|
798 | __decorate([
|
799 | core.ContentChild(api.Header)
|
800 | ], MultiSelect.prototype, "headerFacet", void 0);
|
801 | __decorate([
|
802 | core.ContentChildren(api.PrimeTemplate)
|
803 | ], MultiSelect.prototype, "templates", void 0);
|
804 | __decorate([
|
805 | core.Output()
|
806 | ], MultiSelect.prototype, "onChange", void 0);
|
807 | __decorate([
|
808 | core.Output()
|
809 | ], MultiSelect.prototype, "onFocus", void 0);
|
810 | __decorate([
|
811 | core.Output()
|
812 | ], MultiSelect.prototype, "onBlur", void 0);
|
813 | __decorate([
|
814 | core.Output()
|
815 | ], MultiSelect.prototype, "onClick", void 0);
|
816 | __decorate([
|
817 | core.Output()
|
818 | ], MultiSelect.prototype, "onPanelShow", void 0);
|
819 | __decorate([
|
820 | core.Output()
|
821 | ], MultiSelect.prototype, "onPanelHide", void 0);
|
822 | __decorate([
|
823 | core.Input()
|
824 | ], MultiSelect.prototype, "options", null);
|
825 | MultiSelect = __decorate([
|
826 | core.Component({
|
827 | selector: 'p-multiSelect',
|
828 | template: "\n <div #container [ngClass]=\"{'ui-multiselect ui-widget ui-state-default ui-corner-all':true,'ui-multiselect-open':overlayVisible,'ui-state-focus':focus,'ui-state-disabled': disabled}\" [ngStyle]=\"style\" [class]=\"styleClass\"\n (click)=\"onMouseclick($event,in)\">\n <div class=\"ui-helper-hidden-accessible\">\n <input #in type=\"text\" readonly=\"readonly\" [attr.id]=\"inputId\" [attr.name]=\"name\" (focus)=\"onInputFocus($event)\" (blur)=\"onInputBlur($event)\"\n [disabled]=\"disabled\" [attr.tabindex]=\"tabindex\" (keydown)=\"onKeydown($event)\" aria-haspopup=\"listbox\" [attr.aria-expanded]=\"overlayVisible\"\n [attr.aria-labelledby]=\"ariaLabelledBy\" role=\"listbox\">\n </div>\n <div class=\"ui-multiselect-label-container\" [pTooltip]=\"tooltip\" [tooltipPosition]=\"tooltipPosition\" [positionStyle]=\"tooltipPositionStyle\" [tooltipStyleClass]=\"tooltipStyleClass\">\n <span class=\"ui-multiselect-label ui-corner-all\">\n <ng-container *ngIf=\"!selectedItemsTemplate\">{{valuesAsString}}</ng-container>\n <ng-container *ngTemplateOutlet=\"selectedItemsTemplate; context: {$implicit: value}\"></ng-container>\n </span>\n </div>\n <div [ngClass]=\"{'ui-multiselect-trigger ui-state-default ui-corner-right':true}\">\n <span class=\"ui-multiselect-trigger-icon ui-clickable\" [ngClass]=\"dropdownIcon\"></span>\n </div>\n <div *ngIf=\"overlayVisible\" [ngClass]=\"['ui-multiselect-panel ui-widget ui-widget-content ui-corner-all ui-shadow']\" [@overlayAnimation]=\"{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}\" (@overlayAnimation.start)=\"onOverlayAnimationStart($event)\"\n [ngStyle]=\"panelStyle\" [class]=\"panelStyleClass\" (click)=\"panelClick=true\" (keydown)=\"onKeydown($event)\">\n <div class=\"ui-widget-header ui-corner-all ui-multiselect-header ui-helper-clearfix\" [ngClass]=\"{'ui-multiselect-header-no-toggleall': !showToggleAll}\" *ngIf=\"showHeader\">\n <ng-content select=\"p-header\"></ng-content>\n <div class=\"ui-chkbox ui-widget\" *ngIf=\"showToggleAll && !selectionLimit\">\n <div class=\"ui-helper-hidden-accessible\">\n <input type=\"checkbox\" readonly=\"readonly\" [checked]=\"isAllChecked()\" (focus)=\"onHeaderCheckboxFocus()\" (blur)=\"onHeaderCheckboxBlur()\" (keydown.space)=\"toggleAll($event)\">\n </div>\n <div class=\"ui-chkbox-box ui-widget ui-corner-all ui-state-default\" role=\"checkbox\" [attr.aria-checked]=\"isAllChecked()\" [ngClass]=\"{'ui-state-active':isAllChecked(), 'ui-state-focus': headerCheckboxFocus}\" (click)=\"toggleAll($event)\">\n <span class=\"ui-chkbox-icon ui-clickable\" [ngClass]=\"{'pi pi-check':isAllChecked()}\"></span>\n </div>\n </div>\n <div class=\"ui-multiselect-filter-container\" *ngIf=\"filter\">\n <input #filterInput type=\"text\" role=\"textbox\" [value]=\"filterValue||''\" (input)=\"onFilter()\" class=\"ui-inputtext ui-widget ui-state-default ui-corner-all\" [attr.placeholder]=\"filterPlaceHolder\" [attr.aria-label]=\"ariaFilterLabel\">\n <span class=\"ui-multiselect-filter-icon pi pi-search\"></span>\n </div>\n <a class=\"ui-multiselect-close ui-corner-all\" tabindex=\"0\" (click)=\"close($event)\" (keydown.enter)=\"close($event)\">\n <span class=\"pi pi-times\"></span>\n </a>\n </div>\n <div class=\"ui-multiselect-items-wrapper\" [style.max-height]=\"virtualScroll ? 'auto' : (scrollHeight||'auto')\">\n <ul class=\"ui-multiselect-items ui-multiselect-list ui-widget-content ui-widget ui-corner-all ui-helper-reset\" role=\"listbox\" aria-multiselectable=\"true\">\n <ng-container *ngIf=\"!virtualScroll; else virtualScrollList\">\n <ng-template ngFor let-option let-i=\"index\" [ngForOf]=\"options\">\n <p-multiSelectItem [option]=\"option\" [selected]=\"isSelected(option.value)\" (onClick)=\"onOptionClick($event)\" (onKeydown)=\"onOptionKeydown($event)\"\n [maxSelectionLimitReached]=\"maxSelectionLimitReached\" [visible]=\"isItemVisible(option)\" [template]=\"itemTemplate\"></p-multiSelectItem>\n </ng-template>\n </ng-container>\n <ng-template #virtualScrollList>\n <cdk-virtual-scroll-viewport #viewport [ngStyle]=\"{'height': scrollHeight}\" [itemSize]=\"itemSize\" *ngIf=\"virtualScroll && visibleOptions && visibleOptions.length\">\n <ng-container *cdkVirtualFor=\"let option of visibleOptions; let i = index; let c = count; let f = first; let l = last; let e = even; let o = odd\">\n <p-multiSelectItem [option]=\"option\" [selected]=\"isSelected(option.value)\" (onClick)=\"onOptionClick($event)\" (onKeydown)=\"onOptionKeydown($event)\"\n [maxSelectionLimitReached]=\"maxSelectionLimitReached\" [visible]=\"isItemVisible(option)\" [template]=\"itemTemplate\" [itemSize]=\"itemSize\"></p-multiSelectItem>\n </ng-container>\n </cdk-virtual-scroll-viewport>\n </ng-template>\n <li *ngIf=\"filter && visibleOptions && visibleOptions.length === 0\" class=\"ui-multiselect-empty-message\">{{emptyFilterMessage}}</li>\n </ul>\n </div>\n <div class=\"ui-multiselect-footer ui-widget-content\" *ngIf=\"footerFacet\">\n <ng-content select=\"p-footer\"></ng-content>\n </div>\n </div>\n </div>\n ",
|
829 | animations: [
|
830 | animations.trigger('overlayAnimation', [
|
831 | animations.state('void', animations.style({
|
832 | transform: 'translateY(5%)',
|
833 | opacity: 0
|
834 | })),
|
835 | animations.state('visible', animations.style({
|
836 | transform: 'translateY(0)',
|
837 | opacity: 1
|
838 | })),
|
839 | animations.transition('void => visible', animations.animate('{{showTransitionParams}}')),
|
840 | animations.transition('visible => void', animations.animate('{{hideTransitionParams}}'))
|
841 | ])
|
842 | ],
|
843 | host: {
|
844 | '[class.ui-inputwrapper-filled]': 'filled',
|
845 | '[class.ui-inputwrapper-focus]': 'focus'
|
846 | },
|
847 | providers: [MULTISELECT_VALUE_ACCESSOR],
|
848 | changeDetection: core.ChangeDetectionStrategy.Default
|
849 | })
|
850 | ], MultiSelect);
|
851 | return MultiSelect;
|
852 | }());
|
853 | var MultiSelectModule = (function () {
|
854 | function MultiSelectModule() {
|
855 | }
|
856 | MultiSelectModule = __decorate([
|
857 | core.NgModule({
|
858 | imports: [common.CommonModule, api.SharedModule, scrolling.ScrollingModule, tooltip.TooltipModule],
|
859 | exports: [MultiSelect, api.SharedModule, scrolling.ScrollingModule],
|
860 | declarations: [MultiSelect, MultiSelectItem]
|
861 | })
|
862 | ], MultiSelectModule);
|
863 | return MultiSelectModule;
|
864 | }());
|
865 |
|
866 | exports.MULTISELECT_VALUE_ACCESSOR = MULTISELECT_VALUE_ACCESSOR;
|
867 | exports.MultiSelect = MultiSelect;
|
868 | exports.MultiSelectItem = MultiSelectItem;
|
869 | exports.MultiSelectModule = MultiSelectModule;
|
870 |
|
871 | Object.defineProperty(exports, '__esModule', { value: true });
|
872 |
|
873 | })));
|
874 |
|