UNPKG

primevue

Version:

PrimeVue is a premium UI library for Vue featuring a rich set of 90+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with PrimeBlock, wh

1,270 lines (1,263 loc) 62 kB
import ChevronDown from '@primeicons/vue/chevron-down'; import Spinner from '@primeicons/vue/spinner'; import Times from '@primeicons/vue/times'; import { cn } from '@primeuix/utils'; import { findSingle, focus, isTouchDevice, relativePosition, getOuterWidth, absolutePosition, addStyle } from '@primeuix/utils/dom'; import { isNotEmpty, findLastIndex, equals, isEmpty, resolveFieldData } from '@primeuix/utils/object'; import { ZIndex } from '@primeuix/utils/zindex'; import { ConnectedOverlayScrollHandler } from '@primevue/core/utils'; import Chip from 'primevue/chip'; import InputText from 'primevue/inputtext'; import OverlayEventBus from 'primevue/overlayeventbus'; import Portal from 'primevue/portal'; import Ripple from 'primevue/ripple'; import VirtualScroller from 'primevue/virtualscroller'; import BaseInput from '@primevue/core/baseinput'; import AutoCompleteStyle from 'primevue/autocomplete/style'; import { resolveComponent, resolveDirective, openBlock, createElementBlock, mergeProps, createBlock, createCommentVNode, renderSlot, normalizeClass, createVNode, Fragment, renderList, withCtx, createElementVNode, resolveDynamicComponent, toDisplayString, Transition, createSlots, createTextVNode, withDirectives } from 'vue'; var script$1 = { name: 'BaseAutoComplete', "extends": BaseInput, props: { suggestions: { type: Array, "default": null }, optionLabel: null, optionDisabled: null, optionGroupLabel: null, optionGroupChildren: null, scrollHeight: { type: String, "default": '14rem' }, dropdown: { type: Boolean, "default": false }, dropdownMode: { type: String, "default": 'blank' }, /** * @deprecated since v5.0. Use the InputTags component instead. */ multiple: { type: Boolean, "default": false }, loading: { type: Boolean, "default": false }, placeholder: { type: String, "default": null }, dataKey: { type: String, "default": null }, minLength: { type: Number, "default": 1 }, delay: { type: Number, "default": 300 }, appendTo: { type: [String, Object], "default": 'body' }, forceSelection: { type: Boolean, "default": false }, completeOnFocus: { type: Boolean, "default": false }, showClear: { type: Boolean, "default": false }, inputId: { type: String, "default": null }, inputStyle: { type: Object, "default": null }, inputClass: { type: [String, Object], "default": null }, inputProps: { type: null, "default": null }, panelStyle: { type: Object, "default": null }, panelClass: { type: [String, Object], "default": null }, overlayStyle: { type: Object, "default": null }, overlayClass: { type: [String, Object], "default": null }, dropdownIcon: { type: String, "default": null }, dropdownClass: { type: [String, Object], "default": null }, loader: { type: String, "default": null }, chipIcon: { type: String, "default": null }, virtualScrollerOptions: { type: Object, "default": null }, autoOptionFocus: { type: Boolean, "default": false }, selectOnFocus: { type: Boolean, "default": false }, focusOnHover: { type: Boolean, "default": true }, searchLocale: { type: String, "default": undefined }, searchMessage: { type: String, "default": null }, selectionMessage: { type: String, "default": null }, emptySelectionMessage: { type: String, "default": null }, emptySearchMessage: { type: String, "default": null }, showEmptyMessage: { type: Boolean, "default": true }, tabindex: { type: Number, "default": 0 }, typeahead: { type: Boolean, "default": true }, ariaLabel: { type: String, "default": null }, ariaLabelledby: { type: String, "default": null } }, style: AutoCompleteStyle, provide: function provide() { return { $pcAutoComplete: this, $parentInstance: this }; } }; function _defineProperty$1(e, r, t) { return (r = _toPropertyKey$1(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; } function _toPropertyKey$1(t) { var i = _toPrimitive$1(t, "string"); return "symbol" == _typeof$1(i) ? i : i + ""; } function _toPrimitive$1(t, r) { if ("object" != _typeof$1(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof$1(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } function _typeof$1(o) { "@babel/helpers - typeof"; return _typeof$1 = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof$1(o); } function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); } function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } } function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); } function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); } function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; } var script = { name: 'AutoComplete', "extends": script$1, inheritAttrs: false, emits: ['change', 'focus', 'blur', 'option-select', 'option-unselect', 'dropdown-click', 'clear', 'complete', 'before-show', 'before-hide', 'show', 'hide', 'keydown', 'paste'], inject: { $pcFluid: { "default": null } }, outsideClickListener: null, resizeListener: null, scrollHandler: null, overlay: null, virtualScroller: null, searchTimeout: null, dirty: false, startRangeIndex: -1, data: function data() { return { clicked: false, focused: false, focusedOptionIndex: -1, focusedMultipleOptionIndex: -1, overlayVisible: false, searching: false }; }, watch: { suggestions: function suggestions() { if (this.searching) { this.show(); this.focusedOptionIndex = this.overlayVisible && this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : -1; this.searching = false; !this.showEmptyMessage && this.visibleOptions.length === 0 && this.hide(); } this.autoUpdateModel(); } }, mounted: function mounted() { this.autoUpdateModel(); }, updated: function updated() { if (this.overlayVisible) { this.alignOverlay(); } }, beforeUnmount: function beforeUnmount() { this.unbindOutsideClickListener(); this.unbindResizeListener(); if (this.scrollHandler) { this.scrollHandler.destroy(); this.scrollHandler = null; } if (this.overlay) { ZIndex.clear(this.overlay); this.overlay = null; } }, methods: { getOptionIndex: function getOptionIndex(index, fn) { return this.virtualScrollerDisabled ? index : fn && fn(index)['index']; }, getOptionLabel: function getOptionLabel(option) { return this.optionLabel ? resolveFieldData(option, this.optionLabel) : option; }, getOptionValue: function getOptionValue(option) { return option; // TODO: The 'optionValue' properties can be added. }, getOptionRenderKey: function getOptionRenderKey(option, index) { return (this.dataKey ? resolveFieldData(option, this.dataKey) : this.getOptionLabel(option)) + '_' + index; }, getPTOptions: function getPTOptions(option, itemOptions, index, key) { return this.ptm(key, { context: { option: option, index: index, selected: this.isSelected(option), focused: this.focusedOptionIndex === this.getOptionIndex(index, itemOptions), disabled: this.isOptionDisabled(option) } }); }, isOptionDisabled: function isOptionDisabled(option) { return this.optionDisabled ? resolveFieldData(option, this.optionDisabled) : false; }, isOptionGroup: function isOptionGroup(option) { return this.optionGroupLabel && option.optionGroup && option.group; }, getOptionGroupLabel: function getOptionGroupLabel(optionGroup) { return resolveFieldData(optionGroup, this.optionGroupLabel); }, getOptionGroupChildren: function getOptionGroupChildren(optionGroup) { return resolveFieldData(optionGroup, this.optionGroupChildren); }, getAriaPosInset: function getAriaPosInset(index) { var _this = this; return (this.optionGroupLabel ? index - this.visibleOptions.slice(0, index).filter(function (option) { return _this.isOptionGroup(option); }).length : index) + 1; }, show: function show(isFocus) { this.$emit('before-show'); this.dirty = true; this.overlayVisible = true; this.focusedOptionIndex = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : -1; isFocus && focus(this.multiple ? this.$refs.focusInput : this.$refs.focusInput.$el); }, hide: function hide(isFocus) { var _this2 = this; var _hide = function _hide() { var _this2$$refs$focusInp; _this2.$emit('before-hide'); _this2.dirty = isFocus; _this2.overlayVisible = false; _this2.clicked = false; _this2.focusedOptionIndex = -1; isFocus && focus(_this2.multiple ? _this2.$refs.focusInput : (_this2$$refs$focusInp = _this2.$refs.focusInput) === null || _this2$$refs$focusInp === void 0 ? void 0 : _this2$$refs$focusInp.$el); }; setTimeout(function () { _hide(); }, 0); // For ScreenReaders }, onFocus: function onFocus(event) { if (this.disabled) { // For ScreenReaders return; } if (!this.dirty && this.completeOnFocus) { this.search(event, event.target.value, 'focus'); } this.dirty = true; this.focused = true; if (this.overlayVisible) { this.focusedOptionIndex = this.focusedOptionIndex !== -1 ? this.focusedOptionIndex : this.overlayVisible && this.autoOptionFocus ? this.findFirstFocusedOptionIndex() : -1; this.scrollInView(this.focusedOptionIndex); } this.$emit('focus', event); }, onBlur: function onBlur(event) { var _this$formField$onBlu, _this$formField; this.dirty = false; this.focused = false; this.focusedOptionIndex = -1; this.$emit('blur', event); (_this$formField$onBlu = (_this$formField = this.formField).onBlur) === null || _this$formField$onBlu === void 0 || _this$formField$onBlu.call(_this$formField); }, onPaste: function onPaste(event) { this.$emit('paste', event); }, onKeyDown: function onKeyDown(event) { if (this.disabled) { event.preventDefault(); return; } this.$emit('keydown', event); switch (event.code) { case 'ArrowDown': this.onArrowDownKey(event); break; case 'ArrowUp': this.onArrowUpKey(event); break; case 'ArrowLeft': this.onArrowLeftKey(event); break; case 'ArrowRight': this.onArrowRightKey(event); break; case 'Home': this.onHomeKey(event); break; case 'End': this.onEndKey(event); break; case 'PageDown': this.onPageDownKey(event); break; case 'PageUp': this.onPageUpKey(event); break; case 'Enter': case 'NumpadEnter': this.onEnterKey(event); break; case 'Space': this.onSpaceKey(event); break; case 'Escape': this.onEscapeKey(event); if (this.overlayVisible) { event.stopPropagation(); } break; case 'Tab': this.onTabKey(event); break; case 'ShiftLeft': case 'ShiftRight': this.onShiftKey(event); break; case 'Backspace': this.onBackspaceKey(event); break; } this.clicked = false; }, onInput: function onInput(event) { var _this3 = this; if (this.typeahead) { if (this.searchTimeout) { clearTimeout(this.searchTimeout); } var query = event.target.value; if (!this.multiple) { this.updateModel(event, query); } if (query.length === 0) { this.searching = false; this.hide(); this.$emit('clear'); } else { if (query.length >= this.minLength) { this.focusedOptionIndex = -1; this.searchTimeout = setTimeout(function () { _this3.search(event, query, 'input'); }, this.delay); } else { this.searching = false; this.hide(); } } } }, onChange: function onChange(event) { var _this4 = this; if (this.forceSelection) { var valid = false; // when forceSelection is on, prevent called twice onOptionSelect() if (this.visibleOptions && !this.multiple) { var _this$$refs$focusInpu; var value = this.multiple ? this.$refs.focusInput.value : (_this$$refs$focusInpu = this.$refs.focusInput) === null || _this$$refs$focusInpu === void 0 || (_this$$refs$focusInpu = _this$$refs$focusInpu.$el) === null || _this$$refs$focusInpu === void 0 ? void 0 : _this$$refs$focusInpu.value; var matchedValue = this.visibleOptions.find(function (option) { return _this4.isOptionMatched(option, value || ''); }); if (matchedValue !== undefined) { valid = true; !this.isSelected(matchedValue) && this.onOptionSelect(event, matchedValue); } } if (!valid) { if (this.multiple) { this.$refs.focusInput.value = ''; } else { var _this$$refs$focusInpu2; var inputEl = (_this$$refs$focusInpu2 = this.$refs.focusInput) === null || _this$$refs$focusInpu2 === void 0 ? void 0 : _this$$refs$focusInpu2.$el; inputEl && (inputEl.value = ''); } this.$emit('clear'); !this.multiple && this.updateModel(event, null); } } }, onMultipleContainerFocus: function onMultipleContainerFocus() { if (this.disabled) { // For ScreenReaders return; } this.focused = true; }, onMultipleContainerBlur: function onMultipleContainerBlur() { this.focusedMultipleOptionIndex = -1; this.focused = false; }, onMultipleContainerKeyDown: function onMultipleContainerKeyDown(event) { if (this.disabled) { event.preventDefault(); return; } switch (event.code) { case 'ArrowLeft': this.onArrowLeftKeyOnMultiple(event); break; case 'ArrowRight': this.onArrowRightKeyOnMultiple(event); break; case 'Backspace': this.onBackspaceKeyOnMultiple(event); break; } }, onContainerClick: function onContainerClick(event) { this.clicked = true; if (this.disabled || this.searching || this.loading || this.isDropdownClicked(event)) { return; } if (!this.overlay || !this.overlay.contains(event.target)) { focus(this.multiple ? this.$refs.focusInput : this.$refs.focusInput.$el); } }, onDropdownClick: function onDropdownClick(event) { var query = undefined; if (this.overlayVisible) { this.hide(true); } else { var target = this.multiple ? this.$refs.focusInput : this.$refs.focusInput.$el; focus(target); query = target.value; if (this.dropdownMode === 'blank') this.search(event, '', 'dropdown');else if (this.dropdownMode === 'current') this.search(event, query, 'dropdown'); } this.$emit('dropdown-click', { originalEvent: event, query: query }); }, onOptionSelect: function onOptionSelect(event, option) { var isHide = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true; var value = this.getOptionValue(option); if (this.multiple) { this.$refs.focusInput.value = ''; if (!this.isSelected(option)) { this.updateModel(event, [].concat(_toConsumableArray(this.d_value || []), [value])); } } else { this.updateModel(event, value); } this.$emit('option-select', { originalEvent: event, value: option }); isHide && this.hide(true); }, onOptionMouseMove: function onOptionMouseMove(event, index) { if (this.focusOnHover) { this.changeFocusedOptionIndex(event, index); } }, onOptionSelectRange: function onOptionSelectRange(event) { var _this5 = this; var start = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : -1; var end = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : -1; start === -1 && (start = this.findNearestSelectedOptionIndex(end, true)); end === -1 && (end = this.findNearestSelectedOptionIndex(start)); if (start !== -1 && end !== -1) { var rangeStart = Math.min(start, end); var rangeEnd = Math.max(start, end); var value = this.visibleOptions.slice(rangeStart, rangeEnd + 1).filter(function (option) { return _this5.isValidOption(option); }).filter(function (option) { return !_this5.isSelected(option); }).map(function (option) { return _this5.getOptionValue(option); }); this.updateModel(event, [].concat(_toConsumableArray(this.d_value || []), _toConsumableArray(value))); } }, onClearClick: function onClearClick(event) { this.updateModel(event, null); this.overlayVisible && this.hide(true); this.$emit('clear'); }, onOverlayClick: function onOverlayClick(event) { OverlayEventBus.emit('overlay-click', { originalEvent: event, target: this.$el }); }, onOverlayKeyDown: function onOverlayKeyDown(event) { switch (event.code) { case 'Escape': this.onEscapeKey(event); break; } }, onArrowDownKey: function onArrowDownKey(event) { if (!this.overlayVisible) { return; } var optionIndex = this.focusedOptionIndex !== -1 ? this.findNextOptionIndex(this.focusedOptionIndex) : this.clicked ? this.findFirstOptionIndex() : this.findFirstFocusedOptionIndex(); if (this.multiple && event.shiftKey) { this.onOptionSelectRange(event, this.startRangeIndex, optionIndex); } this.changeFocusedOptionIndex(event, optionIndex); event.preventDefault(); }, onArrowUpKey: function onArrowUpKey(event) { if (!this.overlayVisible) { return; } if (event.altKey) { if (this.focusedOptionIndex !== -1) { this.onOptionSelect(event, this.visibleOptions[this.focusedOptionIndex]); } this.overlayVisible && this.hide(); event.preventDefault(); } else { var optionIndex = this.focusedOptionIndex !== -1 ? this.findPrevOptionIndex(this.focusedOptionIndex) : this.clicked ? this.findLastOptionIndex() : this.findLastFocusedOptionIndex(); if (this.multiple && event.shiftKey) { this.onOptionSelectRange(event, optionIndex, this.startRangeIndex); } this.changeFocusedOptionIndex(event, optionIndex); event.preventDefault(); } }, onArrowLeftKey: function onArrowLeftKey(event) { var target = event.currentTarget; this.focusedOptionIndex = -1; if (this.multiple) { if (isEmpty(target.value) && this.$filled) { focus(this.$refs.multiContainer); this.focusedMultipleOptionIndex = this.d_value.length; } else { event.stopPropagation(); // To prevent onArrowLeftKeyOnMultiple method } } }, onArrowRightKey: function onArrowRightKey(event) { this.focusedOptionIndex = -1; this.multiple && event.stopPropagation(); // To prevent onArrowRightKeyOnMultiple method }, onHomeKey: function onHomeKey(event) { var currentTarget = event.currentTarget; var len = currentTarget.value.length; var metaKey = event.metaKey || event.ctrlKey; var optionIndex = this.findFirstOptionIndex(); if (this.multiple && event.shiftKey && metaKey) { this.onOptionSelectRange(event, optionIndex, this.startRangeIndex); } currentTarget.setSelectionRange(0, event.shiftKey ? len : 0); this.focusedOptionIndex = -1; event.preventDefault(); }, onEndKey: function onEndKey(event) { var currentTarget = event.currentTarget; var len = currentTarget.value.length; var metaKey = event.metaKey || event.ctrlKey; var optionIndex = this.findLastOptionIndex(); if (this.multiple && event.shiftKey && metaKey) { this.onOptionSelectRange(event, this.startRangeIndex, optionIndex); } currentTarget.setSelectionRange(event.shiftKey ? 0 : len, len); this.focusedOptionIndex = -1; event.preventDefault(); }, onPageUpKey: function onPageUpKey(event) { this.scrollInView(0); event.preventDefault(); }, onPageDownKey: function onPageDownKey(event) { this.scrollInView(this.visibleOptions.length - 1); event.preventDefault(); }, onEnterKey: function onEnterKey(event) { if (!this.typeahead) { if (this.multiple) { if (event.target.value.trim()) { this.updateModel(event, [].concat(_toConsumableArray(this.d_value || []), [event.target.value.trim()])); this.$refs.focusInput.value = ''; // Only consume Enter when a value was actually added; an empty input must let // Enter bubble so the surrounding form can submit. event.preventDefault(); } } } else { if (!this.overlayVisible) { this.focusedOptionIndex = -1; // reset this.onArrowDownKey(event); } else { if (this.focusedOptionIndex !== -1) { if (this.multiple && event.shiftKey) { this.onOptionSelectRange(event, this.focusedOptionIndex); } else { this.onOptionSelect(event, this.visibleOptions[this.focusedOptionIndex]); } event.preventDefault(); } this.hide(); } } }, onSpaceKey: function onSpaceKey(event) { if (!this.autoOptionFocus && this.focusedOptionIndex !== -1) { this.onEnterKey(event); } }, onEscapeKey: function onEscapeKey(event) { this.overlayVisible && this.hide(true); event.preventDefault(); }, onTabKey: function onTabKey(event) { if (this.focusedOptionIndex !== -1) { this.onOptionSelect(event, this.visibleOptions[this.focusedOptionIndex]); } this.overlayVisible && this.hide(); }, onShiftKey: function onShiftKey() { this.startRangeIndex = this.focusedOptionIndex; }, onBackspaceKey: function onBackspaceKey(event) { if (this.multiple) { if (isNotEmpty(this.d_value) && !this.$refs.focusInput.value) { var removedValue = this.d_value[this.d_value.length - 1]; var newValue = this.d_value.slice(0, -1); this.writeValue(newValue, event); this.$emit('option-unselect', { originalEvent: event, value: removedValue }); } event.stopPropagation(); // To prevent onBackspaceKeyOnMultiple method } }, onArrowLeftKeyOnMultiple: function onArrowLeftKeyOnMultiple() { this.focusedMultipleOptionIndex = this.focusedMultipleOptionIndex < 1 ? 0 : this.focusedMultipleOptionIndex - 1; }, onArrowRightKeyOnMultiple: function onArrowRightKeyOnMultiple() { this.focusedMultipleOptionIndex++; if (this.focusedMultipleOptionIndex > this.d_value.length - 1) { this.focusedMultipleOptionIndex = -1; focus(this.$refs.focusInput); } }, onBackspaceKeyOnMultiple: function onBackspaceKeyOnMultiple(event) { if (this.focusedMultipleOptionIndex !== -1) { this.removeOption(event, this.focusedMultipleOptionIndex); } }, onOverlayEnter: function onOverlayEnter(el) { ZIndex.set('overlay', el, this.$primevue.config.zIndex.overlay); addStyle(el, { position: 'absolute', top: '0' }); this.alignOverlay(); // Issue: #7508 this.$attrSelector && el.setAttribute(this.$attrSelector, ''); }, onOverlayAfterEnter: function onOverlayAfterEnter() { this.bindOutsideClickListener(); this.bindScrollListener(); this.bindResizeListener(); this.$emit('show'); }, onOverlayLeave: function onOverlayLeave(el) { el.style.pointerEvents = 'none'; this.unbindOutsideClickListener(); this.unbindScrollListener(); this.unbindResizeListener(); this.$emit('hide'); this.overlay = null; }, onOverlayAfterLeave: function onOverlayAfterLeave(el) { ZIndex.clear(el); }, alignOverlay: function alignOverlay() { var _parent$dataset; // When AC is nested inside an InputTags, align the overlay to InputTags' root so the panel // spans the visible field width instead of AC's narrower flex space when chips share the row. var own = this.$refs.container; var parent = own === null || own === void 0 ? void 0 : own.parentElement; var target = (parent === null || parent === void 0 || (_parent$dataset = parent.dataset) === null || _parent$dataset === void 0 ? void 0 : _parent$dataset.pcName) === 'inputtags' ? parent : own; if (this.appendTo === 'self') { relativePosition(this.overlay, target); } else { this.overlay.style.minWidth = getOuterWidth(target) + 'px'; absolutePosition(this.overlay, target); } }, bindOutsideClickListener: function bindOutsideClickListener() { var _this6 = this; if (!this.outsideClickListener) { this.outsideClickListener = function (event) { if (_this6.overlayVisible && _this6.overlay && _this6.isOutsideClicked(event)) { _this6.hide(); } }; document.addEventListener('click', this.outsideClickListener, true); } }, unbindOutsideClickListener: function unbindOutsideClickListener() { if (this.outsideClickListener) { document.removeEventListener('click', this.outsideClickListener, true); this.outsideClickListener = null; } }, bindScrollListener: function bindScrollListener() { var _this7 = this; if (!this.scrollHandler) { this.scrollHandler = new ConnectedOverlayScrollHandler(this.$refs.container, function () { if (_this7.overlayVisible) { _this7.hide(); } }); } this.scrollHandler.bindScrollListener(); }, unbindScrollListener: function unbindScrollListener() { if (this.scrollHandler) { this.scrollHandler.unbindScrollListener(); } }, bindResizeListener: function bindResizeListener() { var _this8 = this; if (!this.resizeListener) { this.resizeListener = function () { if (_this8.overlayVisible && !isTouchDevice()) { _this8.hide(); } }; window.addEventListener('resize', this.resizeListener); } }, unbindResizeListener: function unbindResizeListener() { if (this.resizeListener) { window.removeEventListener('resize', this.resizeListener); this.resizeListener = null; } }, isOutsideClicked: function isOutsideClicked(event) { return !this.overlay.contains(event.target) && !this.isInputClicked(event) && !this.isDropdownClicked(event); }, isInputClicked: function isInputClicked(event) { var _parent$dataset2; var own = this.$refs.container; var parent = own === null || own === void 0 ? void 0 : own.parentElement; var target = (parent === null || parent === void 0 || (_parent$dataset2 = parent.dataset) === null || _parent$dataset2 === void 0 ? void 0 : _parent$dataset2.pcName) === 'inputtags' ? parent : own; return target ? event.target === target || target.contains(event.target) : false; }, isDropdownClicked: function isDropdownClicked(event) { return this.$refs.dropdownButton ? event.target === this.$refs.dropdownButton || this.$refs.dropdownButton.contains(event.target) : false; }, isOptionMatched: function isOptionMatched(option, value) { var _this$getOptionLabel; return this.isValidOption(option) && ((_this$getOptionLabel = this.getOptionLabel(option)) === null || _this$getOptionLabel === void 0 ? void 0 : _this$getOptionLabel.toLocaleLowerCase(this.searchLocale)) === value.toLocaleLowerCase(this.searchLocale); }, isValidOption: function isValidOption(option) { return isNotEmpty(option) && !(this.isOptionDisabled(option) || this.isOptionGroup(option)); }, isValidSelectedOption: function isValidSelectedOption(option) { return this.isValidOption(option) && this.isSelected(option); }, isEquals: function isEquals(value1, value2) { return equals(value1, value2, this.equalityKey); }, isSelected: function isSelected(option) { var _this9 = this; var optionValue = this.getOptionValue(option); return this.multiple ? (this.d_value || []).some(function (value) { return _this9.isEquals(value, optionValue); }) : this.isEquals(this.d_value, this.getOptionValue(option)); }, findFirstOptionIndex: function findFirstOptionIndex() { var _this0 = this; return this.visibleOptions.findIndex(function (option) { return _this0.isValidOption(option); }); }, findLastOptionIndex: function findLastOptionIndex() { var _this1 = this; return findLastIndex(this.visibleOptions, function (option) { return _this1.isValidOption(option); }); }, findNextOptionIndex: function findNextOptionIndex(index) { var _this10 = this; var matchedOptionIndex = index < this.visibleOptions.length - 1 ? this.visibleOptions.slice(index + 1).findIndex(function (option) { return _this10.isValidOption(option); }) : -1; return matchedOptionIndex > -1 ? matchedOptionIndex + index + 1 : index; }, findPrevOptionIndex: function findPrevOptionIndex(index) { var _this11 = this; var matchedOptionIndex = index > 0 ? findLastIndex(this.visibleOptions.slice(0, index), function (option) { return _this11.isValidOption(option); }) : -1; return matchedOptionIndex > -1 ? matchedOptionIndex : index; }, findSelectedOptionIndex: function findSelectedOptionIndex() { var _this12 = this; return this.$filled ? this.visibleOptions.findIndex(function (option) { return _this12.isValidSelectedOption(option); }) : -1; }, findFirstFocusedOptionIndex: function findFirstFocusedOptionIndex() { var selectedIndex = this.findSelectedOptionIndex(); return selectedIndex < 0 ? this.findFirstOptionIndex() : selectedIndex; }, findLastFocusedOptionIndex: function findLastFocusedOptionIndex() { var selectedIndex = this.findSelectedOptionIndex(); return selectedIndex < 0 ? this.findLastOptionIndex() : selectedIndex; }, search: function search(event, query, source) { var _this13 = this; //allow empty string but not undefined or null if (query === undefined || query === null) { return; } //do not search blank values on input change if (source === 'input' && query.trim().length === 0) { return; } this.searching = true; this.$emit('complete', { originalEvent: event, query: query }); // Fallback: when the parent does not change the `suggestions` reference (same query / cached computed), // the watcher won't fire and `searching` stays true forever. Two RAFs let the parent commit any sync/async // updates first; if we are still flagged as searching, force-open the overlay with current suggestions. requestAnimationFrame(function () { requestAnimationFrame(function () { if (_this13.searching) { _this13.searching = false; if (_this13.showEmptyMessage || _this13.visibleOptions.length > 0) { _this13.show(); _this13.focusedOptionIndex = _this13.overlayVisible && _this13.autoOptionFocus ? _this13.findFirstFocusedOptionIndex() : -1; } } }); }); }, removeOption: function removeOption(event, index) { var _this14 = this; var removedOption = this.d_value[index]; var value = this.d_value.filter(function (_, i) { return i !== index; }).map(function (option) { return _this14.getOptionValue(option); }); this.updateModel(event, value); this.$emit('option-unselect', { originalEvent: event, value: removedOption }); this.dirty = true; focus(this.multiple ? this.$refs.focusInput : this.$refs.focusInput.$el); }, changeFocusedOptionIndex: function changeFocusedOptionIndex(event, index) { if (this.focusedOptionIndex !== index) { this.focusedOptionIndex = index; this.scrollInView(); if (this.selectOnFocus) { this.onOptionSelect(event, this.visibleOptions[index], false); } } }, scrollInView: function scrollInView() { var _this15 = this; var index = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : -1; this.$nextTick(function () { var id = index !== -1 ? "".concat(_this15.$id, "_").concat(index) : _this15.focusedOptionId; var element = findSingle(_this15.list, "li[id=\"".concat(id, "\"]")); if (element) { element.scrollIntoView && element.scrollIntoView({ block: 'nearest', inline: 'start' }); } else if (!_this15.virtualScrollerDisabled) { _this15.virtualScroller && _this15.virtualScroller.scrollToIndex(index !== -1 ? index : _this15.focusedOptionIndex); } }); }, autoUpdateModel: function autoUpdateModel() { if (this.selectOnFocus && this.autoOptionFocus && !this.$filled) { this.focusedOptionIndex = this.findFirstFocusedOptionIndex(); this.onOptionSelect(null, this.visibleOptions[this.focusedOptionIndex], false); } }, updateModel: function updateModel(event, value) { this.writeValue(value, event); this.$emit('change', { originalEvent: event, value: value }); }, flatOptions: function flatOptions(options) { var _this16 = this; return (options || []).reduce(function (result, option, index) { result.push({ optionGroup: option, group: true, index: index }); var optionGroupChildren = _this16.getOptionGroupChildren(option); optionGroupChildren && optionGroupChildren.forEach(function (o) { return result.push(o); }); return result; }, []); }, overlayRef: function overlayRef(el) { this.overlay = el; }, listRef: function listRef(el, contentRef) { this.list = el; contentRef && contentRef(el); // For VirtualScroller }, virtualScrollerRef: function virtualScrollerRef(el) { this.virtualScroller = el; }, findNextSelectedOptionIndex: function findNextSelectedOptionIndex(index) { var _this17 = this; var matchedOptionIndex = this.$filled && index < this.visibleOptions.length - 1 ? this.visibleOptions.slice(index + 1).findIndex(function (option) { return _this17.isValidSelectedOption(option); }) : -1; return matchedOptionIndex > -1 ? matchedOptionIndex + index + 1 : -1; }, findPrevSelectedOptionIndex: function findPrevSelectedOptionIndex(index) { var _this18 = this; var matchedOptionIndex = this.$filled && index > 0 ? findLastIndex(this.visibleOptions.slice(0, index), function (option) { return _this18.isValidSelectedOption(option); }) : -1; return matchedOptionIndex > -1 ? matchedOptionIndex : -1; }, findNearestSelectedOptionIndex: function findNearestSelectedOptionIndex(index) { var firstCheckUp = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var matchedOptionIndex = -1; if (this.$filled) { if (firstCheckUp) { matchedOptionIndex = this.findPrevSelectedOptionIndex(index); matchedOptionIndex = matchedOptionIndex === -1 ? this.findNextSelectedOptionIndex(index) : matchedOptionIndex; } else { matchedOptionIndex = this.findNextSelectedOptionIndex(index); matchedOptionIndex = matchedOptionIndex === -1 ? this.findPrevSelectedOptionIndex(index) : matchedOptionIndex; } } return matchedOptionIndex > -1 ? matchedOptionIndex : index; } }, computed: { visibleOptions: function visibleOptions() { return this.optionGroupLabel ? this.flatOptions(this.suggestions) : this.suggestions || []; }, inputValue: function inputValue() { if (this.$filled) { if (_typeof$1(this.d_value) === 'object') { var label = this.getOptionLabel(this.d_value); return label != null ? label : this.d_value; } else { return this.d_value; } } else { return ''; } }, equalityKey: function equalityKey() { // @todo: The 'optionValue' properties can be added. return this.dataKey; }, searchResultMessageText: function searchResultMessageText() { return isNotEmpty(this.visibleOptions) && this.overlayVisible ? this.searchMessageText.replaceAll('{0}', this.visibleOptions.length) : this.emptySearchMessageText; }, searchMessageText: function searchMessageText() { return this.searchMessage || this.$primevue.config.locale.searchMessage || ''; }, emptySearchMessageText: function emptySearchMessageText() { return this.emptySearchMessage || this.$primevue.config.locale.emptySearchMessage || ''; }, selectionMessageText: function selectionMessageText() { return this.selectionMessage || this.$primevue.config.locale.selectionMessage || ''; }, emptySelectionMessageText: function emptySelectionMessageText() { return this.emptySelectionMessage || this.$primevue.config.locale.emptySelectionMessage || ''; }, selectedMessageText: function selectedMessageText() { return this.$filled ? this.selectionMessageText.replaceAll('{0}', this.multiple ? this.d_value.length : '1') : this.emptySelectionMessageText; }, listAriaLabel: function listAriaLabel() { return this.$primevue.config.locale.aria ? this.$primevue.config.locale.aria.listLabel : undefined; }, focusedOptionId: function focusedOptionId() { return this.focusedOptionIndex !== -1 ? "".concat(this.$id, "_").concat(this.focusedOptionIndex) : null; }, focusedMultipleOptionId: function focusedMultipleOptionId() { return this.focusedMultipleOptionIndex !== -1 ? "".concat(this.$id, "_multiple_option_").concat(this.focusedMultipleOptionIndex) : null; }, isClearIconVisible: function isClearIconVisible() { return this.showClear && this.$filled && !this.disabled && !this.loading; }, ariaSetSize: function ariaSetSize() { var _this19 = this; return this.visibleOptions.filter(function (option) { return !_this19.isOptionGroup(option); }).length; }, virtualScrollerDisabled: function virtualScrollerDisabled() { return !this.virtualScrollerOptions; }, panelId: function panelId() { return this.$id + '_panel'; }, containerDataP: function containerDataP() { return cn({ fluid: this.$fluid }); }, overlayDataP: function overlayDataP() { return cn(_defineProperty$1({}, 'portal-' + this.appendTo, 'portal-' + this.appendTo)); }, inputMultipleDataP: function inputMultipleDataP() { return cn(_defineProperty$1({ invalid: this.$invalid, disabled: this.disabled, focus: this.focused, fluid: this.$fluid, filled: this.$variant === 'filled', empty: !this.$filled }, this.size, this.size)); } }, components: { InputText: InputText, VirtualScroller: VirtualScroller, Portal: Portal, Chip: Chip, ChevronDown: ChevronDown, Spinner: Spinner, Times: Times }, directives: { ripple: Ripple } }; function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); } function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; } function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), true).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; } function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: true, configurable: true, writable: true }) : e[r] = t, e; } function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; } function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); } var _hoisted_1 = ["data-p"]; var _hoisted_2 = ["aria-activedescendant", "data-p-has-dropdown", "data-p"]; var _hoisted_3 = ["id", "aria-label", "aria-setsize", "aria-posinset"]; var _hoisted_4 = ["id", "placeholder", "tabindex", "disabled", "aria-label", "aria-labelledby", "aria-expanded", "aria-controls", "aria-activedescendant", "aria-invalid"]; var _hoisted_5 = ["data-p-has-dropdown"]; var _hoisted_6 = ["disabled", "aria-expanded", "aria-controls"]; var _hoisted_7 = ["id", "data-p"]; var _hoisted_8 = ["id", "aria-label"]; var _hoisted_9 = ["id"]; var _hoisted_10 = ["id", "aria-label", "aria-selected", "aria-disabled", "aria-setsize", "aria-posinset", "onClick", "onMousemove", "data-p-selected", "data-p-focused", "data-p-disabled"]; function render(_ctx, _cache, $props, $setup, $data, $options) { var _component_InputText = resolveComponent("InputText"); var _component_Times = resolveComponent("Times"); var _component_Chip = resolveComponent("Chip"); var _component_Spinner = resolveComponent("Spinner"); var _component_VirtualScroller = resolveComponent("VirtualScroller"); var _component_Portal = resolveComponent("Portal"); var _directive_ripple = resolveDirective("ripple"); return openBlock(), createElementBlock("div", mergeProps({ ref: "container", "class": _ctx.cx('root'), style: _ctx.sx('root'), onClick: _cache[12] || (_cache[12] = function () { return $options.onContainerClick && $options.onContainerClick.apply($options, arguments); }), "data-p": $options.containerDataP }, _ctx.ptmi('root')), [!_ctx.multiple ? (openBlock(), createBlock(_component_InputText, mergeProps({ key: 0, ref: "focusInput", id: _ctx.inputId, type: "text", name: _ctx.$formName, formControl: { novalidate: true }, "class": [_ctx.cx('pcInputText'), _ctx.inputClass], style: _ctx.inputStyle, defaultValue: $options.inputValue, placeholder: _ctx.placeholder, tabindex: !_ctx.disabled ? _ctx.tabindex : -1, fluid: _ctx.$fluid, disabled: _ctx.disabled, size: _ctx.size, invalid: _ctx.$invalid, variant: _ctx.variant, autocomplete: "off", role: "combobox", "aria-label": _ctx.ariaLabel, "aria-labelledby": _ctx.ariaLabelledby, "aria-haspopup": "listbox", "aria-autocomplete": "list", "aria-expanded": $data.overlayVisible, "aria-controls": $data.overlayVisible ? $options.panelId : undefined, "aria-activedescendant": $data.focused ? $options.focusedOptionId : undefined, onFocus: $options.onFocus, onBlur: $options.onBlur, onKeydown: $options.onKeyDown, onInput: $options.onInput, onChange: $options.onChange, onPaste: $options.onPaste, unstyled: _ctx.unstyled, "data-p-has-dropdown": _ctx.dropdown }, _ctx.inputProps, { pt: _ctx.ptm('pcInputText') }), null, 16, ["id", "name", "class", "style", "defaultValue", "placeholder", "tabindex", "fluid", "disabled", "size", "invalid", "variant", "aria-label", "aria-labelledby", "aria-expanded", "aria-controls", "aria-activedescendant", "onFocus", "onBlur", "onKeydown", "onInput", "onChange", "onPaste", "unstyled", "data-p-has-dropdown", "pt"])) : createCommentVNode("", true), $options.isClearIconVisible ? renderSlot(_ctx.$slots, "clearicon", { key: 1, "class": normalizeClass(_ctx.cx('clearIcon')), clearCallback: $options.onClearClick }, function () { return [createVNode(_component_Times, mergeProps({ "class": [_ctx.cx('clearIcon')], onClick: $options.onClearClick }, _ctx.ptm('clearIcon')), null, 16, ["class", "onClick"])]; }) : createCommentVNode("", true), _ctx.multiple ? (openBlock(), createElementBlock("ul", mergeProps({ key: 2, ref: "multiContainer", "class": _ctx.cx('inputMultiple'), tabindex: "-1", role: "listbox", "aria-orientation": "horizontal", "aria-activedescendant": $data.focused ? $options.focusedMultipleOptionId : undefined, onFocus: _cache[6] || (_cache[6] = function () { return $options.onMultipleContainerFocus && $options.onMultipleContainerFocus.apply($options, arguments); }), onBlur: _cache[7] || (_cache[7] = function () { return $options.onMultipleContainerBlur && $options.onMultipleContainerBlur.apply($options, arguments); }), onKeydown: _cache[8] || (_cache[8] = function () { return $options.onMultipleContainerKeyDown && $options.onMultipleContainerKeyDown.apply($options, arguments); }), "data-p-has-dropdown": _ctx.dropdown, "data-p": $options.inputMultipleDataP }, _ctx.ptm('inputMultiple')), [(openBlock(true), createElementBlock(Fragment, null, renderList(_ctx.d_value, function (option, i) { return openBlock(), createElementBlock("li", mergeProps({ key: "".concat(i, "_").concat($options.getOptionLabel(option)), id: _ctx.$id + '_multiple_option_' + i, "class": _ctx.cx('chipItem', { i: i }), role: "option", "aria-label": $options.getOptionLabel(option), "aria-selected": true, "aria-setsize": _ctx.d_value.length, "aria-posinset": i + 1 }, { ref_for: true }, _ctx.ptm('chipItem')), [renderSlot(_ctx.$slots, "chip", mergeProps({ "class": _ctx.cx('pcChip'), value: option, index: i, removeCallback: function removeCallback(event) { return $options.removeOption(event, i); } }, { ref_for: true }, _ctx.ptm('pcChip')), function () { return [createVNode(_component_Chip, { "class": normalizeClass(_ctx.cx('pcChip')), label: $options.getOptionLabel(option), removeIcon: _ctx.chipIcon, removable: "", unstyled: _ctx.unstyled, onRemove: function onRemove($event) { return $options.removeOption($event, i); }, "data-p-focused": $data.focusedMultipleOptionIndex === i, pt: _ctx.ptm('pcCh