autocomplete.js 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779
  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 common_1 = require("@angular/common");
  14. var animations_1 = require("@angular/animations");
  15. var inputtext_1 = require("../inputtext/inputtext");
  16. var button_1 = require("../button/button");
  17. var shared_1 = require("../common/shared");
  18. var domhandler_1 = require("../dom/domhandler");
  19. var objectutils_1 = require("../utils/objectutils");
  20. var forms_1 = require("@angular/forms");
  21. exports.AUTOCOMPLETE_VALUE_ACCESSOR = {
  22. provide: forms_1.NG_VALUE_ACCESSOR,
  23. useExisting: core_1.forwardRef(function () { return AutoComplete; }),
  24. multi: true
  25. };
  26. var AutoComplete = /** @class */ (function () {
  27. function AutoComplete(el, renderer, cd, differs) {
  28. this.el = el;
  29. this.renderer = renderer;
  30. this.cd = cd;
  31. this.differs = differs;
  32. this.minLength = 1;
  33. this.delay = 300;
  34. this.type = 'text';
  35. this.autoZIndex = true;
  36. this.baseZIndex = 0;
  37. this.dropdownIcon = "pi pi-caret-down";
  38. this.unique = true;
  39. this.completeMethod = new core_1.EventEmitter();
  40. this.onSelect = new core_1.EventEmitter();
  41. this.onUnselect = new core_1.EventEmitter();
  42. this.onFocus = new core_1.EventEmitter();
  43. this.onBlur = new core_1.EventEmitter();
  44. this.onDropdownClick = new core_1.EventEmitter();
  45. this.onClear = new core_1.EventEmitter();
  46. this.onKeyUp = new core_1.EventEmitter();
  47. this.scrollHeight = '200px';
  48. this.dropdownMode = 'blank';
  49. this.immutable = true;
  50. this.showTransitionOptions = '225ms ease-out';
  51. this.hideTransitionOptions = '195ms ease-in';
  52. this.autocomplete = 'off';
  53. this.onModelChange = function () { };
  54. this.onModelTouched = function () { };
  55. this.overlayVisible = false;
  56. this.focus = false;
  57. this.inputFieldValue = null;
  58. this.differ = differs.find([]).create(null);
  59. }
  60. Object.defineProperty(AutoComplete.prototype, "suggestions", {
  61. get: function () {
  62. return this._suggestions;
  63. },
  64. set: function (val) {
  65. this._suggestions = val;
  66. if (this.immutable) {
  67. this.handleSuggestionsChange();
  68. }
  69. },
  70. enumerable: true,
  71. configurable: true
  72. });
  73. AutoComplete.prototype.ngDoCheck = function () {
  74. if (!this.immutable) {
  75. var changes = this.differ.diff(this.suggestions);
  76. if (changes) {
  77. this.handleSuggestionsChange();
  78. }
  79. }
  80. };
  81. AutoComplete.prototype.ngAfterViewChecked = function () {
  82. var _this = this;
  83. //Use timeouts as since Angular 4.2, AfterViewChecked is broken and not called after panel is updated
  84. if (this.suggestionsUpdated && this.overlay && this.overlay.offsetParent) {
  85. setTimeout(function () {
  86. if (_this.overlay) {
  87. _this.alignOverlay();
  88. }
  89. }, 1);
  90. this.suggestionsUpdated = false;
  91. }
  92. if (this.highlightOptionChanged) {
  93. setTimeout(function () {
  94. if (_this.overlay) {
  95. var listItem = domhandler_1.DomHandler.findSingle(_this.overlay, 'li.ui-state-highlight');
  96. if (listItem) {
  97. domhandler_1.DomHandler.scrollInView(_this.overlay, listItem);
  98. }
  99. }
  100. }, 1);
  101. this.highlightOptionChanged = false;
  102. }
  103. };
  104. AutoComplete.prototype.handleSuggestionsChange = function () {
  105. if (this._suggestions != null && this.loading) {
  106. this.highlightOption = null;
  107. if (this._suggestions.length) {
  108. this.noResults = false;
  109. this.show();
  110. this.suggestionsUpdated = true;
  111. if (this.autoHighlight) {
  112. this.highlightOption = this._suggestions[0];
  113. }
  114. }
  115. else {
  116. this.noResults = true;
  117. if (this.emptyMessage) {
  118. this.show();
  119. this.suggestionsUpdated = true;
  120. }
  121. else {
  122. this.hide();
  123. }
  124. }
  125. this.loading = false;
  126. }
  127. };
  128. AutoComplete.prototype.ngAfterContentInit = function () {
  129. var _this = this;
  130. this.templates.forEach(function (item) {
  131. switch (item.getType()) {
  132. case 'item':
  133. _this.itemTemplate = item.template;
  134. break;
  135. case 'selectedItem':
  136. _this.selectedItemTemplate = item.template;
  137. break;
  138. default:
  139. _this.itemTemplate = item.template;
  140. break;
  141. }
  142. });
  143. };
  144. AutoComplete.prototype.writeValue = function (value) {
  145. this.value = value;
  146. this.filled = this.value && this.value != '';
  147. this.updateInputField();
  148. };
  149. AutoComplete.prototype.registerOnChange = function (fn) {
  150. this.onModelChange = fn;
  151. };
  152. AutoComplete.prototype.registerOnTouched = function (fn) {
  153. this.onModelTouched = fn;
  154. };
  155. AutoComplete.prototype.setDisabledState = function (val) {
  156. this.disabled = val;
  157. };
  158. AutoComplete.prototype.onInput = function (event) {
  159. var _this = this;
  160. // When an input element with a placeholder is clicked, the onInput event is invoked in IE.
  161. if (!this.inputKeyDown && domhandler_1.DomHandler.isIE()) {
  162. return;
  163. }
  164. if (this.timeout) {
  165. clearTimeout(this.timeout);
  166. }
  167. var value = event.target.value;
  168. if (!this.multiple && !this.forceSelection) {
  169. this.onModelChange(value);
  170. }
  171. if (value.length === 0 && !this.multiple) {
  172. this.hide();
  173. this.onClear.emit(event);
  174. this.onModelChange(value);
  175. }
  176. if (value.length >= this.minLength) {
  177. this.timeout = setTimeout(function () {
  178. _this.search(event, value);
  179. }, this.delay);
  180. }
  181. else {
  182. this.suggestions = null;
  183. this.hide();
  184. }
  185. this.updateFilledState();
  186. this.inputKeyDown = false;
  187. };
  188. AutoComplete.prototype.onInputClick = function (event) {
  189. if (this.documentClickListener) {
  190. this.inputClick = true;
  191. }
  192. };
  193. AutoComplete.prototype.search = function (event, query) {
  194. //allow empty string but not undefined or null
  195. if (query === undefined || query === null) {
  196. return;
  197. }
  198. this.loading = true;
  199. this.completeMethod.emit({
  200. originalEvent: event,
  201. query: query
  202. });
  203. };
  204. AutoComplete.prototype.selectItem = function (option, focus) {
  205. if (focus === void 0) { focus = true; }
  206. if (this.forceSelectionUpdateModelTimeout) {
  207. clearTimeout(this.forceSelectionUpdateModelTimeout);
  208. this.forceSelectionUpdateModelTimeout = null;
  209. }
  210. if (this.multiple) {
  211. this.multiInputEL.nativeElement.value = '';
  212. this.value = this.value || [];
  213. if (!this.isSelected(option) || !this.unique) {
  214. this.value = this.value.concat([option]);
  215. this.onModelChange(this.value);
  216. }
  217. }
  218. else {
  219. this.inputEL.nativeElement.value = this.field ? objectutils_1.ObjectUtils.resolveFieldData(option, this.field) || '' : option;
  220. this.value = option;
  221. this.onModelChange(this.value);
  222. }
  223. this.onSelect.emit(option);
  224. this.updateFilledState();
  225. if (focus) {
  226. this.focusInput();
  227. }
  228. };
  229. AutoComplete.prototype.show = function () {
  230. if (this.multiInputEL || this.inputEL) {
  231. var hasFocus = this.multiple ? document.activeElement == this.multiInputEL.nativeElement : document.activeElement == this.inputEL.nativeElement;
  232. if (!this.overlayVisible && hasFocus) {
  233. this.overlayVisible = true;
  234. }
  235. }
  236. };
  237. AutoComplete.prototype.onOverlayAnimationStart = function (event) {
  238. switch (event.toState) {
  239. case 'visible':
  240. this.overlay = event.element;
  241. this.appendOverlay();
  242. if (this.autoZIndex) {
  243. this.overlay.style.zIndex = String(this.baseZIndex + (++domhandler_1.DomHandler.zindex));
  244. }
  245. this.alignOverlay();
  246. this.bindDocumentClickListener();
  247. this.bindDocumentResizeListener();
  248. break;
  249. case 'void':
  250. this.onOverlayHide();
  251. break;
  252. }
  253. };
  254. AutoComplete.prototype.onOverlayAnimationDone = function (event) {
  255. if (event.toState === 'void') {
  256. this._suggestions = null;
  257. }
  258. };
  259. AutoComplete.prototype.appendOverlay = function () {
  260. if (this.appendTo) {
  261. if (this.appendTo === 'body')
  262. document.body.appendChild(this.overlay);
  263. else
  264. domhandler_1.DomHandler.appendChild(this.overlay, this.appendTo);
  265. this.overlay.style.minWidth = domhandler_1.DomHandler.getWidth(this.el.nativeElement.children[0]) + 'px';
  266. }
  267. };
  268. AutoComplete.prototype.resolveFieldData = function (value) {
  269. return this.field ? objectutils_1.ObjectUtils.resolveFieldData(value, this.field) : value;
  270. };
  271. AutoComplete.prototype.restoreOverlayAppend = function () {
  272. if (this.overlay && this.appendTo) {
  273. this.el.nativeElement.appendChild(this.overlay);
  274. }
  275. };
  276. AutoComplete.prototype.alignOverlay = function () {
  277. if (this.appendTo)
  278. domhandler_1.DomHandler.absolutePosition(this.overlay, (this.multiple ? this.multiContainerEL.nativeElement : this.inputEL.nativeElement));
  279. else
  280. domhandler_1.DomHandler.relativePosition(this.overlay, (this.multiple ? this.multiContainerEL.nativeElement : this.inputEL.nativeElement));
  281. };
  282. AutoComplete.prototype.hide = function () {
  283. this.overlayVisible = false;
  284. };
  285. AutoComplete.prototype.handleDropdownClick = function (event) {
  286. this.focusInput();
  287. var queryValue = this.multiple ? this.multiInputEL.nativeElement.value : this.inputEL.nativeElement.value;
  288. if (this.dropdownMode === 'blank')
  289. this.search(event, '');
  290. else if (this.dropdownMode === 'current')
  291. this.search(event, queryValue);
  292. this.onDropdownClick.emit({
  293. originalEvent: event,
  294. query: queryValue
  295. });
  296. };
  297. AutoComplete.prototype.focusInput = function () {
  298. if (this.multiple)
  299. this.multiInputEL.nativeElement.focus();
  300. else
  301. this.inputEL.nativeElement.focus();
  302. };
  303. AutoComplete.prototype.removeItem = function (item) {
  304. var itemIndex = domhandler_1.DomHandler.index(item);
  305. var removedValue = this.value[itemIndex];
  306. this.value = this.value.filter(function (val, i) { return i != itemIndex; });
  307. this.onModelChange(this.value);
  308. this.updateFilledState();
  309. this.onUnselect.emit(removedValue);
  310. };
  311. AutoComplete.prototype.onKeydown = function (event) {
  312. if (this.overlayVisible) {
  313. var highlightItemIndex = this.findOptionIndex(this.highlightOption);
  314. switch (event.which) {
  315. //down
  316. case 40:
  317. if (highlightItemIndex != -1) {
  318. var nextItemIndex = highlightItemIndex + 1;
  319. if (nextItemIndex != (this.suggestions.length)) {
  320. this.highlightOption = this.suggestions[nextItemIndex];
  321. this.highlightOptionChanged = true;
  322. }
  323. }
  324. else {
  325. this.highlightOption = this.suggestions[0];
  326. }
  327. event.preventDefault();
  328. break;
  329. //up
  330. case 38:
  331. if (highlightItemIndex > 0) {
  332. var prevItemIndex = highlightItemIndex - 1;
  333. this.highlightOption = this.suggestions[prevItemIndex];
  334. this.highlightOptionChanged = true;
  335. }
  336. event.preventDefault();
  337. break;
  338. //enter
  339. case 13:
  340. if (this.highlightOption) {
  341. this.selectItem(this.highlightOption);
  342. this.hide();
  343. }
  344. event.preventDefault();
  345. break;
  346. //escape
  347. case 27:
  348. this.hide();
  349. event.preventDefault();
  350. break;
  351. //tab
  352. case 9:
  353. if (this.highlightOption) {
  354. this.selectItem(this.highlightOption);
  355. }
  356. this.hide();
  357. break;
  358. }
  359. }
  360. else {
  361. if (event.which === 40 && this.suggestions) {
  362. this.search(event, event.target.value);
  363. }
  364. }
  365. if (this.multiple) {
  366. switch (event.which) {
  367. //backspace
  368. case 8:
  369. if (this.value && this.value.length && !this.multiInputEL.nativeElement.value) {
  370. this.value = this.value.slice();
  371. var removedValue = this.value.pop();
  372. this.onModelChange(this.value);
  373. this.updateFilledState();
  374. this.onUnselect.emit(removedValue);
  375. }
  376. break;
  377. }
  378. }
  379. this.inputKeyDown = true;
  380. };
  381. AutoComplete.prototype.onKeyup = function (event) {
  382. this.onKeyUp.emit(event);
  383. };
  384. AutoComplete.prototype.onInputFocus = function (event) {
  385. this.focus = true;
  386. this.onFocus.emit(event);
  387. };
  388. AutoComplete.prototype.onInputBlur = function (event) {
  389. this.focus = false;
  390. this.onModelTouched();
  391. this.onBlur.emit(event);
  392. };
  393. AutoComplete.prototype.onInputChange = function (event) {
  394. var _this = this;
  395. if (this.forceSelection && this.suggestions) {
  396. var valid = false;
  397. var inputValue = event.target.value.trim();
  398. if (this.suggestions) {
  399. var _loop_1 = function (suggestion) {
  400. var itemValue = this_1.field ? objectutils_1.ObjectUtils.resolveFieldData(suggestion, this_1.field) : suggestion;
  401. if (itemValue && inputValue === itemValue.trim()) {
  402. valid = true;
  403. this_1.forceSelectionUpdateModelTimeout = setTimeout(function () {
  404. _this.selectItem(suggestion, false);
  405. }, 250);
  406. return "break";
  407. }
  408. };
  409. var this_1 = this;
  410. for (var _i = 0, _a = this.suggestions; _i < _a.length; _i++) {
  411. var suggestion = _a[_i];
  412. var state_1 = _loop_1(suggestion);
  413. if (state_1 === "break")
  414. break;
  415. }
  416. }
  417. if (!valid) {
  418. if (this.multiple) {
  419. this.multiInputEL.nativeElement.value = '';
  420. }
  421. else {
  422. this.value = null;
  423. this.inputEL.nativeElement.value = '';
  424. }
  425. this.onClear.emit(event);
  426. this.onModelChange(this.value);
  427. }
  428. }
  429. };
  430. AutoComplete.prototype.onInputPaste = function (event) {
  431. this.onKeydown(event);
  432. };
  433. AutoComplete.prototype.isSelected = function (val) {
  434. var selected = false;
  435. if (this.value && this.value.length) {
  436. for (var i = 0; i < this.value.length; i++) {
  437. if (objectutils_1.ObjectUtils.equals(this.value[i], val, this.dataKey)) {
  438. selected = true;
  439. break;
  440. }
  441. }
  442. }
  443. return selected;
  444. };
  445. AutoComplete.prototype.findOptionIndex = function (option) {
  446. var index = -1;
  447. if (this.suggestions) {
  448. for (var i = 0; i < this.suggestions.length; i++) {
  449. if (objectutils_1.ObjectUtils.equals(option, this.suggestions[i])) {
  450. index = i;
  451. break;
  452. }
  453. }
  454. }
  455. return index;
  456. };
  457. AutoComplete.prototype.updateFilledState = function () {
  458. if (this.multiple)
  459. this.filled = (this.value && this.value.length) || (this.multiInputEL && this.multiInputEL.nativeElement && this.multiInputEL.nativeElement.value != '');
  460. else
  461. this.filled = (this.inputFieldValue && this.inputFieldValue != '') || (this.inputEL && this.inputEL.nativeElement && this.inputEL.nativeElement.value != '');
  462. ;
  463. };
  464. AutoComplete.prototype.updateInputField = function () {
  465. var formattedValue = this.value ? (this.field ? objectutils_1.ObjectUtils.resolveFieldData(this.value, this.field) || '' : this.value) : '';
  466. this.inputFieldValue = formattedValue;
  467. if (this.inputEL && this.inputEL.nativeElement) {
  468. this.inputEL.nativeElement.value = formattedValue;
  469. }
  470. this.updateFilledState();
  471. };
  472. AutoComplete.prototype.bindDocumentClickListener = function () {
  473. var _this = this;
  474. if (!this.documentClickListener) {
  475. this.documentClickListener = this.renderer.listen('document', 'click', function (event) {
  476. if (event.which === 3) {
  477. return;
  478. }
  479. if (!_this.inputClick && !_this.isDropdownClick(event)) {
  480. _this.hide();
  481. }
  482. _this.inputClick = false;
  483. _this.cd.markForCheck();
  484. });
  485. }
  486. };
  487. AutoComplete.prototype.isDropdownClick = function (event) {
  488. if (this.dropdown) {
  489. var target = event.target;
  490. return (target === this.dropdownButton.nativeElement || target.parentNode === this.dropdownButton.nativeElement);
  491. }
  492. else {
  493. return false;
  494. }
  495. };
  496. AutoComplete.prototype.unbindDocumentClickListener = function () {
  497. if (this.documentClickListener) {
  498. this.documentClickListener();
  499. this.documentClickListener = null;
  500. }
  501. };
  502. AutoComplete.prototype.bindDocumentResizeListener = function () {
  503. this.documentResizeListener = this.onWindowResize.bind(this);
  504. window.addEventListener('resize', this.documentResizeListener);
  505. };
  506. AutoComplete.prototype.unbindDocumentResizeListener = function () {
  507. if (this.documentResizeListener) {
  508. window.removeEventListener('resize', this.documentResizeListener);
  509. this.documentResizeListener = null;
  510. }
  511. };
  512. AutoComplete.prototype.onWindowResize = function () {
  513. this.hide();
  514. };
  515. AutoComplete.prototype.onOverlayHide = function () {
  516. this.unbindDocumentClickListener();
  517. this.unbindDocumentResizeListener();
  518. this.overlay = null;
  519. };
  520. AutoComplete.prototype.ngOnDestroy = function () {
  521. this.restoreOverlayAppend();
  522. this.onOverlayHide();
  523. };
  524. __decorate([
  525. core_1.Input(),
  526. __metadata("design:type", Number)
  527. ], AutoComplete.prototype, "minLength", void 0);
  528. __decorate([
  529. core_1.Input(),
  530. __metadata("design:type", Number)
  531. ], AutoComplete.prototype, "delay", void 0);
  532. __decorate([
  533. core_1.Input(),
  534. __metadata("design:type", Object)
  535. ], AutoComplete.prototype, "style", void 0);
  536. __decorate([
  537. core_1.Input(),
  538. __metadata("design:type", Object)
  539. ], AutoComplete.prototype, "panelStyle", void 0);
  540. __decorate([
  541. core_1.Input(),
  542. __metadata("design:type", String)
  543. ], AutoComplete.prototype, "styleClass", void 0);
  544. __decorate([
  545. core_1.Input(),
  546. __metadata("design:type", String)
  547. ], AutoComplete.prototype, "panelStyleClass", void 0);
  548. __decorate([
  549. core_1.Input(),
  550. __metadata("design:type", Object)
  551. ], AutoComplete.prototype, "inputStyle", void 0);
  552. __decorate([
  553. core_1.Input(),
  554. __metadata("design:type", String)
  555. ], AutoComplete.prototype, "inputId", void 0);
  556. __decorate([
  557. core_1.Input(),
  558. __metadata("design:type", String)
  559. ], AutoComplete.prototype, "inputStyleClass", void 0);
  560. __decorate([
  561. core_1.Input(),
  562. __metadata("design:type", String)
  563. ], AutoComplete.prototype, "placeholder", void 0);
  564. __decorate([
  565. core_1.Input(),
  566. __metadata("design:type", Boolean)
  567. ], AutoComplete.prototype, "readonly", void 0);
  568. __decorate([
  569. core_1.Input(),
  570. __metadata("design:type", Boolean)
  571. ], AutoComplete.prototype, "disabled", void 0);
  572. __decorate([
  573. core_1.Input(),
  574. __metadata("design:type", Number)
  575. ], AutoComplete.prototype, "maxlength", void 0);
  576. __decorate([
  577. core_1.Input(),
  578. __metadata("design:type", String)
  579. ], AutoComplete.prototype, "name", void 0);
  580. __decorate([
  581. core_1.Input(),
  582. __metadata("design:type", Boolean)
  583. ], AutoComplete.prototype, "required", void 0);
  584. __decorate([
  585. core_1.Input(),
  586. __metadata("design:type", Number)
  587. ], AutoComplete.prototype, "size", void 0);
  588. __decorate([
  589. core_1.Input(),
  590. __metadata("design:type", Object)
  591. ], AutoComplete.prototype, "appendTo", void 0);
  592. __decorate([
  593. core_1.Input(),
  594. __metadata("design:type", Boolean)
  595. ], AutoComplete.prototype, "autoHighlight", void 0);
  596. __decorate([
  597. core_1.Input(),
  598. __metadata("design:type", Boolean)
  599. ], AutoComplete.prototype, "forceSelection", void 0);
  600. __decorate([
  601. core_1.Input(),
  602. __metadata("design:type", String)
  603. ], AutoComplete.prototype, "type", void 0);
  604. __decorate([
  605. core_1.Input(),
  606. __metadata("design:type", Boolean)
  607. ], AutoComplete.prototype, "autoZIndex", void 0);
  608. __decorate([
  609. core_1.Input(),
  610. __metadata("design:type", Number)
  611. ], AutoComplete.prototype, "baseZIndex", void 0);
  612. __decorate([
  613. core_1.Input(),
  614. __metadata("design:type", String)
  615. ], AutoComplete.prototype, "ariaLabel", void 0);
  616. __decorate([
  617. core_1.Input(),
  618. __metadata("design:type", String)
  619. ], AutoComplete.prototype, "ariaLabelledBy", void 0);
  620. __decorate([
  621. core_1.Input(),
  622. __metadata("design:type", String)
  623. ], AutoComplete.prototype, "dropdownIcon", void 0);
  624. __decorate([
  625. core_1.Input(),
  626. __metadata("design:type", Boolean)
  627. ], AutoComplete.prototype, "unique", void 0);
  628. __decorate([
  629. core_1.Output(),
  630. __metadata("design:type", core_1.EventEmitter)
  631. ], AutoComplete.prototype, "completeMethod", void 0);
  632. __decorate([
  633. core_1.Output(),
  634. __metadata("design:type", core_1.EventEmitter)
  635. ], AutoComplete.prototype, "onSelect", void 0);
  636. __decorate([
  637. core_1.Output(),
  638. __metadata("design:type", core_1.EventEmitter)
  639. ], AutoComplete.prototype, "onUnselect", void 0);
  640. __decorate([
  641. core_1.Output(),
  642. __metadata("design:type", core_1.EventEmitter)
  643. ], AutoComplete.prototype, "onFocus", void 0);
  644. __decorate([
  645. core_1.Output(),
  646. __metadata("design:type", core_1.EventEmitter)
  647. ], AutoComplete.prototype, "onBlur", void 0);
  648. __decorate([
  649. core_1.Output(),
  650. __metadata("design:type", core_1.EventEmitter)
  651. ], AutoComplete.prototype, "onDropdownClick", void 0);
  652. __decorate([
  653. core_1.Output(),
  654. __metadata("design:type", core_1.EventEmitter)
  655. ], AutoComplete.prototype, "onClear", void 0);
  656. __decorate([
  657. core_1.Output(),
  658. __metadata("design:type", core_1.EventEmitter)
  659. ], AutoComplete.prototype, "onKeyUp", void 0);
  660. __decorate([
  661. core_1.Input(),
  662. __metadata("design:type", String)
  663. ], AutoComplete.prototype, "field", void 0);
  664. __decorate([
  665. core_1.Input(),
  666. __metadata("design:type", String)
  667. ], AutoComplete.prototype, "scrollHeight", void 0);
  668. __decorate([
  669. core_1.Input(),
  670. __metadata("design:type", Boolean)
  671. ], AutoComplete.prototype, "dropdown", void 0);
  672. __decorate([
  673. core_1.Input(),
  674. __metadata("design:type", String)
  675. ], AutoComplete.prototype, "dropdownMode", void 0);
  676. __decorate([
  677. core_1.Input(),
  678. __metadata("design:type", Boolean)
  679. ], AutoComplete.prototype, "multiple", void 0);
  680. __decorate([
  681. core_1.Input(),
  682. __metadata("design:type", Number)
  683. ], AutoComplete.prototype, "tabindex", void 0);
  684. __decorate([
  685. core_1.Input(),
  686. __metadata("design:type", String)
  687. ], AutoComplete.prototype, "dataKey", void 0);
  688. __decorate([
  689. core_1.Input(),
  690. __metadata("design:type", String)
  691. ], AutoComplete.prototype, "emptyMessage", void 0);
  692. __decorate([
  693. core_1.Input(),
  694. __metadata("design:type", Boolean)
  695. ], AutoComplete.prototype, "immutable", void 0);
  696. __decorate([
  697. core_1.Input(),
  698. __metadata("design:type", String)
  699. ], AutoComplete.prototype, "showTransitionOptions", void 0);
  700. __decorate([
  701. core_1.Input(),
  702. __metadata("design:type", String)
  703. ], AutoComplete.prototype, "hideTransitionOptions", void 0);
  704. __decorate([
  705. core_1.Input(),
  706. __metadata("design:type", Boolean)
  707. ], AutoComplete.prototype, "autofocus", void 0);
  708. __decorate([
  709. core_1.Input(),
  710. __metadata("design:type", String)
  711. ], AutoComplete.prototype, "autocomplete", void 0);
  712. __decorate([
  713. core_1.ViewChild('in', { static: false }),
  714. __metadata("design:type", core_1.ElementRef)
  715. ], AutoComplete.prototype, "inputEL", void 0);
  716. __decorate([
  717. core_1.ViewChild('multiIn', { static: false }),
  718. __metadata("design:type", core_1.ElementRef)
  719. ], AutoComplete.prototype, "multiInputEL", void 0);
  720. __decorate([
  721. core_1.ViewChild('multiContainer', { static: false }),
  722. __metadata("design:type", core_1.ElementRef)
  723. ], AutoComplete.prototype, "multiContainerEL", void 0);
  724. __decorate([
  725. core_1.ViewChild('ddBtn', { static: false }),
  726. __metadata("design:type", core_1.ElementRef)
  727. ], AutoComplete.prototype, "dropdownButton", void 0);
  728. __decorate([
  729. core_1.ContentChildren(shared_1.PrimeTemplate),
  730. __metadata("design:type", core_1.QueryList)
  731. ], AutoComplete.prototype, "templates", void 0);
  732. __decorate([
  733. core_1.Input(),
  734. __metadata("design:type", Array),
  735. __metadata("design:paramtypes", [Array])
  736. ], AutoComplete.prototype, "suggestions", null);
  737. AutoComplete = __decorate([
  738. core_1.Component({
  739. selector: 'p-autoComplete',
  740. template: "\n <span [ngClass]=\"{'ui-autocomplete ui-widget':true,'ui-autocomplete-dd':dropdown,'ui-autocomplete-multiple':multiple}\" [ngStyle]=\"style\" [class]=\"styleClass\">\n <input *ngIf=\"!multiple\" #in [attr.type]=\"type\" [attr.id]=\"inputId\" [ngStyle]=\"inputStyle\" [class]=\"inputStyleClass\" [autocomplete]=\"autocomplete\" [attr.required]=\"required\" [attr.name]=\"name\"\n [ngClass]=\"'ui-inputtext ui-widget ui-state-default ui-corner-all ui-autocomplete-input'\" [value]=\"inputFieldValue\" aria-autocomplete=\"list\" role=\"combobox\" [attr.aria-expanded]=\"overlayVisible\" aria-haspopup=\"true\" [attr.aria-activedescendant]=\"'p-highlighted-option'\"\n (click)=\"onInputClick($event)\" (input)=\"onInput($event)\" (keydown)=\"onKeydown($event)\" (keyup)=\"onKeyup($event)\" [attr.autofocus]=\"autofocus\" (focus)=\"onInputFocus($event)\" (blur)=\"onInputBlur($event)\" (change)=\"onInputChange($event)\" (paste)=\"onInputPaste($event)\"\n [attr.placeholder]=\"placeholder\" [attr.size]=\"size\" [attr.maxlength]=\"maxlength\" [attr.tabindex]=\"tabindex\" [readonly]=\"readonly\" [disabled]=\"disabled\" [attr.aria-label]=\"ariaLabel\" [attr.aria-labelledby]=\"ariaLabelledBy\" [attr.aria-required]=\"required\"\n ><ul *ngIf=\"multiple\" #multiContainer class=\"ui-autocomplete-multiple-container ui-widget ui-inputtext ui-state-default ui-corner-all\" [ngClass]=\"{'ui-state-disabled':disabled,'ui-state-focus':focus}\" (click)=\"multiIn.focus()\">\n <li #token *ngFor=\"let val of value\" class=\"ui-autocomplete-token ui-state-highlight ui-corner-all\">\n <span class=\"ui-autocomplete-token-icon pi pi-fw pi-times\" (click)=\"removeItem(token)\" *ngIf=\"!disabled\"></span>\n <span *ngIf=\"!selectedItemTemplate\" class=\"ui-autocomplete-token-label\">{{resolveFieldData(val)}}</span>\n <ng-container *ngTemplateOutlet=\"selectedItemTemplate; context: {$implicit: val}\"></ng-container>\n </li>\n <li class=\"ui-autocomplete-input-token\">\n <input #multiIn [attr.type]=\"type\" [attr.id]=\"inputId\" [disabled]=\"disabled\" [attr.placeholder]=\"(value&&value.length ? null : placeholder)\" [attr.tabindex]=\"tabindex\" [attr.maxlength]=\"maxlength\" (input)=\"onInput($event)\" (click)=\"onInputClick($event)\"\n (keydown)=\"onKeydown($event)\" [readonly]=\"readonly\" (keyup)=\"onKeyup($event)\" [attr.autofocus]=\"autofocus\" (focus)=\"onInputFocus($event)\" (blur)=\"onInputBlur($event)\" (change)=\"onInputChange($event)\" (paste)=\"onInputPaste($event)\" [autocomplete]=\"autocomplete\"\n [ngStyle]=\"inputStyle\" [class]=\"inputStyleClass\" [attr.aria-label]=\"ariaLabel\" [attr.aria-labelledby]=\"ariaLabelledBy\" [attr.aria-required]=\"required\"\n aria-autocomplete=\"list\" role=\"combobox\" [attr.aria-expanded]=\"overlayVisible\" aria-haspopup=\"true\" [attr.aria-activedescendant]=\"'p-highlighted-option'\">\n </li>\n </ul\n ><i *ngIf=\"loading\" class=\"ui-autocomplete-loader pi pi-spinner pi-spin\"></i><button #ddBtn type=\"button\" pButton [icon]=\"dropdownIcon\" class=\"ui-autocomplete-dropdown\" [disabled]=\"disabled\"\n (click)=\"handleDropdownClick($event)\" *ngIf=\"dropdown\" [attr.tabindex]=\"tabindex\"></button>\n <div #panel *ngIf=\"overlayVisible\" [ngClass]=\"['ui-autocomplete-panel ui-widget ui-widget-content ui-corner-all ui-shadow']\" [style.max-height]=\"scrollHeight\" [ngStyle]=\"panelStyle\" [class]=\"panelStyleClass\"\n [@overlayAnimation]=\"{value: 'visible', params: {showTransitionParams: showTransitionOptions, hideTransitionParams: hideTransitionOptions}}\" (@overlayAnimation.start)=\"onOverlayAnimationStart($event)\" (@overlayAnimation.done)=\"onOverlayAnimationDone($event)\" >\n <ul role=\"listbox\" class=\"ui-autocomplete-items ui-autocomplete-list ui-widget-content ui-widget ui-corner-all ui-helper-reset\">\n <li role=\"option\" *ngFor=\"let option of suggestions; let idx = index\" [ngClass]=\"{'ui-autocomplete-list-item ui-corner-all':true,'ui-state-highlight':(highlightOption==option)}\"\n (mouseenter)=\"highlightOption=option\" (mouseleave)=\"highlightOption=null\" [id]=\"highlightOption == option ? 'p-highlighted-option':''\" (click)=\"selectItem(option)\">\n <span *ngIf=\"!itemTemplate\">{{resolveFieldData(option)}}</span>\n <ng-container *ngTemplateOutlet=\"itemTemplate; context: {$implicit: option, index: idx}\"></ng-container>\n </li>\n <li *ngIf=\"noResults && emptyMessage\" class=\"ui-autocomplete-emptymessage ui-autocomplete-list-item ui-corner-all\">{{emptyMessage}}</li>\n </ul>\n </div>\n </span>\n ",
  741. animations: [
  742. animations_1.trigger('overlayAnimation', [
  743. animations_1.state('void', animations_1.style({
  744. transform: 'translateY(5%)',
  745. opacity: 0
  746. })),
  747. animations_1.state('visible', animations_1.style({
  748. transform: 'translateY(0)',
  749. opacity: 1
  750. })),
  751. animations_1.transition('void => visible', animations_1.animate('{{showTransitionParams}}')),
  752. animations_1.transition('visible => void', animations_1.animate('{{hideTransitionParams}}'))
  753. ])
  754. ],
  755. host: {
  756. '[class.ui-inputwrapper-filled]': 'filled',
  757. '[class.ui-inputwrapper-focus]': 'focus && !disabled'
  758. },
  759. providers: [exports.AUTOCOMPLETE_VALUE_ACCESSOR]
  760. }),
  761. __metadata("design:paramtypes", [core_1.ElementRef, core_1.Renderer2, core_1.ChangeDetectorRef, core_1.IterableDiffers])
  762. ], AutoComplete);
  763. return AutoComplete;
  764. }());
  765. exports.AutoComplete = AutoComplete;
  766. var AutoCompleteModule = /** @class */ (function () {
  767. function AutoCompleteModule() {
  768. }
  769. AutoCompleteModule = __decorate([
  770. core_1.NgModule({
  771. imports: [common_1.CommonModule, inputtext_1.InputTextModule, button_1.ButtonModule, shared_1.SharedModule],
  772. exports: [AutoComplete, shared_1.SharedModule],
  773. declarations: [AutoComplete]
  774. })
  775. ], AutoCompleteModule);
  776. return AutoCompleteModule;
  777. }());
  778. exports.AutoCompleteModule = AutoCompleteModule;
  779. //# sourceMappingURL=autocomplete.js.map