multiselect.js 38 KB

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