cd016bbc420f4696bce2b50ae3ecf09d1d20b5a986f34909141c82a4d2d63a9de0df0a10363ac31ba3ae62c5a9962a613d8dffa56a9181b3f6f4faee07a836 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663
  1. import { reactive, ref, computed, watch, watchEffect, nextTick, onMounted } from 'vue';
  2. import { castArray, isEqual, get, debounce, findLastIndex } from 'lodash-unified';
  3. import { isIOS, isClient, useResizeObserver } from '@vueuse/core';
  4. import { useLocale } from '../../../hooks/use-locale/index.mjs';
  5. import { useId } from '../../../hooks/use-id/index.mjs';
  6. import { useNamespace } from '../../../hooks/use-namespace/index.mjs';
  7. import { useFormItem, useFormItemInputId } from '../../form/src/hooks/use-form-item.mjs';
  8. import { useEmptyValues } from '../../../hooks/use-empty-values/index.mjs';
  9. import { useComposition } from '../../../hooks/use-composition/index.mjs';
  10. import { useFocusController } from '../../../hooks/use-focus-controller/index.mjs';
  11. import { debugWarn } from '../../../utils/error.mjs';
  12. import { isArray, isFunction, isPlainObject, isObject } from '@vue/shared';
  13. import { ValidateComponentsMap } from '../../../utils/vue/icon.mjs';
  14. import { useFormSize } from '../../form/src/hooks/use-form-common-props.mjs';
  15. import { isUndefined, isNumber } from '../../../utils/types.mjs';
  16. import { EVENT_CODE } from '../../../constants/aria.mjs';
  17. import { UPDATE_MODEL_EVENT, CHANGE_EVENT } from '../../../constants/event.mjs';
  18. import { scrollIntoView } from '../../../utils/dom/scroll.mjs';
  19. import { MINIMUM_INPUT_WIDTH } from '../../../constants/form.mjs';
  20. const useSelect = (props, emit) => {
  21. const { t } = useLocale();
  22. const contentId = useId();
  23. const nsSelect = useNamespace("select");
  24. const nsInput = useNamespace("input");
  25. const states = reactive({
  26. inputValue: "",
  27. options: /* @__PURE__ */ new Map(),
  28. cachedOptions: /* @__PURE__ */ new Map(),
  29. optionValues: [],
  30. selected: [],
  31. selectionWidth: 0,
  32. collapseItemWidth: 0,
  33. selectedLabel: "",
  34. hoveringIndex: -1,
  35. previousQuery: null,
  36. inputHovering: false,
  37. menuVisibleOnFocus: false,
  38. isBeforeHide: false
  39. });
  40. const selectRef = ref();
  41. const selectionRef = ref();
  42. const tooltipRef = ref();
  43. const tagTooltipRef = ref();
  44. const inputRef = ref();
  45. const prefixRef = ref();
  46. const suffixRef = ref();
  47. const menuRef = ref();
  48. const tagMenuRef = ref();
  49. const collapseItemRef = ref();
  50. const scrollbarRef = ref();
  51. const expanded = ref(false);
  52. const hoverOption = ref();
  53. const { form, formItem } = useFormItem();
  54. const { inputId } = useFormItemInputId(props, {
  55. formItemContext: formItem
  56. });
  57. const { valueOnClear, isEmptyValue } = useEmptyValues(props);
  58. const {
  59. isComposing,
  60. handleCompositionStart,
  61. handleCompositionUpdate,
  62. handleCompositionEnd
  63. } = useComposition({
  64. afterComposition: (e) => onInput(e)
  65. });
  66. const selectDisabled = computed(() => props.disabled || !!(form == null ? void 0 : form.disabled));
  67. const { wrapperRef, isFocused, handleBlur } = useFocusController(inputRef, {
  68. disabled: selectDisabled,
  69. afterFocus() {
  70. if (props.automaticDropdown && !expanded.value) {
  71. expanded.value = true;
  72. states.menuVisibleOnFocus = true;
  73. }
  74. },
  75. beforeBlur(event) {
  76. var _a, _b;
  77. return ((_a = tooltipRef.value) == null ? void 0 : _a.isFocusInsideContent(event)) || ((_b = tagTooltipRef.value) == null ? void 0 : _b.isFocusInsideContent(event));
  78. },
  79. afterBlur() {
  80. var _a;
  81. expanded.value = false;
  82. states.menuVisibleOnFocus = false;
  83. if (props.validateEvent) {
  84. (_a = formItem == null ? void 0 : formItem.validate) == null ? void 0 : _a.call(formItem, "blur").catch((err) => debugWarn());
  85. }
  86. }
  87. });
  88. const hasModelValue = computed(() => {
  89. return isArray(props.modelValue) ? props.modelValue.length > 0 : !isEmptyValue(props.modelValue);
  90. });
  91. const needStatusIcon = computed(() => {
  92. var _a;
  93. return (_a = form == null ? void 0 : form.statusIcon) != null ? _a : false;
  94. });
  95. const showClearBtn = computed(() => {
  96. return props.clearable && !selectDisabled.value && hasModelValue.value && (isFocused.value || states.inputHovering);
  97. });
  98. const iconComponent = computed(() => props.remote && props.filterable && !props.remoteShowSuffix ? "" : props.suffixIcon);
  99. const iconReverse = computed(() => nsSelect.is("reverse", !!(iconComponent.value && expanded.value)));
  100. const validateState = computed(() => (formItem == null ? void 0 : formItem.validateState) || "");
  101. const validateIcon = computed(() => validateState.value && ValidateComponentsMap[validateState.value]);
  102. const debounce$1 = computed(() => props.remote ? 300 : 0);
  103. const isRemoteSearchEmpty = computed(() => props.remote && !states.inputValue && states.options.size === 0);
  104. const emptyText = computed(() => {
  105. if (props.loading) {
  106. return props.loadingText || t("el.select.loading");
  107. } else {
  108. if (props.filterable && states.inputValue && states.options.size > 0 && filteredOptionsCount.value === 0) {
  109. return props.noMatchText || t("el.select.noMatch");
  110. }
  111. if (states.options.size === 0) {
  112. return props.noDataText || t("el.select.noData");
  113. }
  114. }
  115. return null;
  116. });
  117. const filteredOptionsCount = computed(() => optionsArray.value.filter((option) => option.visible).length);
  118. const optionsArray = computed(() => {
  119. const list = Array.from(states.options.values());
  120. const newList = [];
  121. states.optionValues.forEach((item) => {
  122. const index = list.findIndex((i) => i.value === item);
  123. if (index > -1) {
  124. newList.push(list[index]);
  125. }
  126. });
  127. return newList.length >= list.length ? newList : list;
  128. });
  129. const cachedOptionsArray = computed(() => Array.from(states.cachedOptions.values()));
  130. const showNewOption = computed(() => {
  131. const hasExistingOption = optionsArray.value.filter((option) => {
  132. return !option.created;
  133. }).some((option) => {
  134. return option.currentLabel === states.inputValue;
  135. });
  136. return props.filterable && props.allowCreate && states.inputValue !== "" && !hasExistingOption;
  137. });
  138. const updateOptions = () => {
  139. if (props.filterable && isFunction(props.filterMethod))
  140. return;
  141. if (props.filterable && props.remote && isFunction(props.remoteMethod))
  142. return;
  143. optionsArray.value.forEach((option) => {
  144. var _a;
  145. (_a = option.updateOption) == null ? void 0 : _a.call(option, states.inputValue);
  146. });
  147. };
  148. const selectSize = useFormSize();
  149. const collapseTagSize = computed(() => ["small"].includes(selectSize.value) ? "small" : "default");
  150. const dropdownMenuVisible = computed({
  151. get() {
  152. return expanded.value && !isRemoteSearchEmpty.value;
  153. },
  154. set(val) {
  155. expanded.value = val;
  156. }
  157. });
  158. const shouldShowPlaceholder = computed(() => {
  159. if (props.multiple && !isUndefined(props.modelValue)) {
  160. return castArray(props.modelValue).length === 0 && !states.inputValue;
  161. }
  162. const value = isArray(props.modelValue) ? props.modelValue[0] : props.modelValue;
  163. return props.filterable || isUndefined(value) ? !states.inputValue : true;
  164. });
  165. const currentPlaceholder = computed(() => {
  166. var _a;
  167. const _placeholder = (_a = props.placeholder) != null ? _a : t("el.select.placeholder");
  168. return props.multiple || !hasModelValue.value ? _placeholder : states.selectedLabel;
  169. });
  170. const mouseEnterEventName = computed(() => isIOS ? null : "mouseenter");
  171. watch(() => props.modelValue, (val, oldVal) => {
  172. if (props.multiple) {
  173. if (props.filterable && !props.reserveKeyword) {
  174. states.inputValue = "";
  175. handleQueryChange("");
  176. }
  177. }
  178. setSelected();
  179. if (!isEqual(val, oldVal) && props.validateEvent) {
  180. formItem == null ? void 0 : formItem.validate("change").catch((err) => debugWarn());
  181. }
  182. }, {
  183. flush: "post",
  184. deep: true
  185. });
  186. watch(() => expanded.value, (val) => {
  187. if (val) {
  188. handleQueryChange(states.inputValue);
  189. } else {
  190. states.inputValue = "";
  191. states.previousQuery = null;
  192. states.isBeforeHide = true;
  193. }
  194. emit("visible-change", val);
  195. });
  196. watch(() => states.options.entries(), () => {
  197. if (!isClient)
  198. return;
  199. setSelected();
  200. if (props.defaultFirstOption && (props.filterable || props.remote) && filteredOptionsCount.value) {
  201. checkDefaultFirstOption();
  202. }
  203. }, {
  204. flush: "post"
  205. });
  206. watch([() => states.hoveringIndex, optionsArray], ([val]) => {
  207. if (isNumber(val) && val > -1) {
  208. hoverOption.value = optionsArray.value[val] || {};
  209. } else {
  210. hoverOption.value = {};
  211. }
  212. optionsArray.value.forEach((option) => {
  213. option.hover = hoverOption.value === option;
  214. });
  215. });
  216. watchEffect(() => {
  217. if (states.isBeforeHide)
  218. return;
  219. updateOptions();
  220. });
  221. const handleQueryChange = (val) => {
  222. if (states.previousQuery === val || isComposing.value) {
  223. return;
  224. }
  225. states.previousQuery = val;
  226. if (props.filterable && isFunction(props.filterMethod)) {
  227. props.filterMethod(val);
  228. } else if (props.filterable && props.remote && isFunction(props.remoteMethod)) {
  229. props.remoteMethod(val);
  230. }
  231. if (props.defaultFirstOption && (props.filterable || props.remote) && filteredOptionsCount.value) {
  232. nextTick(checkDefaultFirstOption);
  233. } else {
  234. nextTick(updateHoveringIndex);
  235. }
  236. };
  237. const checkDefaultFirstOption = () => {
  238. const optionsInDropdown = optionsArray.value.filter((n) => n.visible && !n.disabled && !n.states.groupDisabled);
  239. const userCreatedOption = optionsInDropdown.find((n) => n.created);
  240. const firstOriginOption = optionsInDropdown[0];
  241. const valueList = optionsArray.value.map((item) => item.value);
  242. states.hoveringIndex = getValueIndex(valueList, userCreatedOption || firstOriginOption);
  243. };
  244. const setSelected = () => {
  245. if (!props.multiple) {
  246. const value = isArray(props.modelValue) ? props.modelValue[0] : props.modelValue;
  247. const option = getOption(value);
  248. states.selectedLabel = option.currentLabel;
  249. states.selected = [option];
  250. return;
  251. } else {
  252. states.selectedLabel = "";
  253. }
  254. const result = [];
  255. if (!isUndefined(props.modelValue)) {
  256. castArray(props.modelValue).forEach((value) => {
  257. result.push(getOption(value));
  258. });
  259. }
  260. states.selected = result;
  261. };
  262. const getOption = (value) => {
  263. let option;
  264. const isObjectValue = isPlainObject(value);
  265. for (let i = states.cachedOptions.size - 1; i >= 0; i--) {
  266. const cachedOption = cachedOptionsArray.value[i];
  267. const isEqualValue = isObjectValue ? get(cachedOption.value, props.valueKey) === get(value, props.valueKey) : cachedOption.value === value;
  268. if (isEqualValue) {
  269. option = {
  270. index: optionsArray.value.filter((opt) => !opt.created).indexOf(cachedOption),
  271. value,
  272. currentLabel: cachedOption.currentLabel,
  273. get isDisabled() {
  274. return cachedOption.isDisabled;
  275. }
  276. };
  277. break;
  278. }
  279. }
  280. if (option)
  281. return option;
  282. const label = isObjectValue ? value.label : value != null ? value : "";
  283. const newOption = {
  284. index: -1,
  285. value,
  286. currentLabel: label
  287. };
  288. return newOption;
  289. };
  290. const updateHoveringIndex = () => {
  291. states.hoveringIndex = optionsArray.value.findIndex((item) => states.selected.some((selected) => getValueKey(selected) === getValueKey(item)));
  292. };
  293. const resetSelectionWidth = () => {
  294. states.selectionWidth = Number.parseFloat(window.getComputedStyle(selectionRef.value).width);
  295. };
  296. const resetCollapseItemWidth = () => {
  297. states.collapseItemWidth = collapseItemRef.value.getBoundingClientRect().width;
  298. };
  299. const updateTooltip = () => {
  300. var _a, _b;
  301. (_b = (_a = tooltipRef.value) == null ? void 0 : _a.updatePopper) == null ? void 0 : _b.call(_a);
  302. };
  303. const updateTagTooltip = () => {
  304. var _a, _b;
  305. (_b = (_a = tagTooltipRef.value) == null ? void 0 : _a.updatePopper) == null ? void 0 : _b.call(_a);
  306. };
  307. const onInputChange = () => {
  308. if (states.inputValue.length > 0 && !expanded.value) {
  309. expanded.value = true;
  310. }
  311. handleQueryChange(states.inputValue);
  312. };
  313. const onInput = (event) => {
  314. states.inputValue = event.target.value;
  315. if (props.remote) {
  316. debouncedOnInputChange();
  317. } else {
  318. return onInputChange();
  319. }
  320. };
  321. const debouncedOnInputChange = debounce(() => {
  322. onInputChange();
  323. }, debounce$1.value);
  324. const emitChange = (val) => {
  325. if (!isEqual(props.modelValue, val)) {
  326. emit(CHANGE_EVENT, val);
  327. }
  328. };
  329. const getLastNotDisabledIndex = (value) => findLastIndex(value, (it) => {
  330. const option = states.cachedOptions.get(it);
  331. return option && !option.disabled && !option.states.groupDisabled;
  332. });
  333. const deletePrevTag = (e) => {
  334. if (!props.multiple)
  335. return;
  336. if (e.code === EVENT_CODE.delete)
  337. return;
  338. if (e.target.value.length <= 0) {
  339. const value = castArray(props.modelValue).slice();
  340. const lastNotDisabledIndex = getLastNotDisabledIndex(value);
  341. if (lastNotDisabledIndex < 0)
  342. return;
  343. const removeTagValue = value[lastNotDisabledIndex];
  344. value.splice(lastNotDisabledIndex, 1);
  345. emit(UPDATE_MODEL_EVENT, value);
  346. emitChange(value);
  347. emit("remove-tag", removeTagValue);
  348. }
  349. };
  350. const deleteTag = (event, tag) => {
  351. const index = states.selected.indexOf(tag);
  352. if (index > -1 && !selectDisabled.value) {
  353. const value = castArray(props.modelValue).slice();
  354. value.splice(index, 1);
  355. emit(UPDATE_MODEL_EVENT, value);
  356. emitChange(value);
  357. emit("remove-tag", tag.value);
  358. }
  359. event.stopPropagation();
  360. focus();
  361. };
  362. const deleteSelected = (event) => {
  363. event.stopPropagation();
  364. const value = props.multiple ? [] : valueOnClear.value;
  365. if (props.multiple) {
  366. for (const item of states.selected) {
  367. if (item.isDisabled)
  368. value.push(item.value);
  369. }
  370. }
  371. emit(UPDATE_MODEL_EVENT, value);
  372. emitChange(value);
  373. states.hoveringIndex = -1;
  374. expanded.value = false;
  375. emit("clear");
  376. focus();
  377. };
  378. const handleOptionSelect = (option) => {
  379. var _a;
  380. if (props.multiple) {
  381. const value = castArray((_a = props.modelValue) != null ? _a : []).slice();
  382. const optionIndex = getValueIndex(value, option);
  383. if (optionIndex > -1) {
  384. value.splice(optionIndex, 1);
  385. } else if (props.multipleLimit <= 0 || value.length < props.multipleLimit) {
  386. value.push(option.value);
  387. }
  388. emit(UPDATE_MODEL_EVENT, value);
  389. emitChange(value);
  390. if (option.created) {
  391. handleQueryChange("");
  392. }
  393. if (props.filterable && !props.reserveKeyword) {
  394. states.inputValue = "";
  395. }
  396. } else {
  397. !isEqual(props.modelValue, option.value) && emit(UPDATE_MODEL_EVENT, option.value);
  398. emitChange(option.value);
  399. expanded.value = false;
  400. }
  401. focus();
  402. if (expanded.value)
  403. return;
  404. nextTick(() => {
  405. scrollToOption(option);
  406. });
  407. };
  408. const getValueIndex = (arr, option) => {
  409. if (isUndefined(option))
  410. return -1;
  411. if (!isObject(option.value))
  412. return arr.indexOf(option.value);
  413. return arr.findIndex((item) => {
  414. return isEqual(get(item, props.valueKey), getValueKey(option));
  415. });
  416. };
  417. const scrollToOption = (option) => {
  418. var _a, _b, _c, _d, _e;
  419. const targetOption = isArray(option) ? option[0] : option;
  420. let target = null;
  421. if (targetOption == null ? void 0 : targetOption.value) {
  422. const options = optionsArray.value.filter((item) => item.value === targetOption.value);
  423. if (options.length > 0) {
  424. target = options[0].$el;
  425. }
  426. }
  427. if (tooltipRef.value && target) {
  428. const menu = (_d = (_c = (_b = (_a = tooltipRef.value) == null ? void 0 : _a.popperRef) == null ? void 0 : _b.contentRef) == null ? void 0 : _c.querySelector) == null ? void 0 : _d.call(_c, `.${nsSelect.be("dropdown", "wrap")}`);
  429. if (menu) {
  430. scrollIntoView(menu, target);
  431. }
  432. }
  433. (_e = scrollbarRef.value) == null ? void 0 : _e.handleScroll();
  434. };
  435. const onOptionCreate = (vm) => {
  436. states.options.set(vm.value, vm);
  437. states.cachedOptions.set(vm.value, vm);
  438. };
  439. const onOptionDestroy = (key, vm) => {
  440. if (states.options.get(key) === vm) {
  441. states.options.delete(key);
  442. }
  443. };
  444. const popperRef = computed(() => {
  445. var _a, _b;
  446. return (_b = (_a = tooltipRef.value) == null ? void 0 : _a.popperRef) == null ? void 0 : _b.contentRef;
  447. });
  448. const handleMenuEnter = () => {
  449. states.isBeforeHide = false;
  450. nextTick(() => {
  451. var _a;
  452. (_a = scrollbarRef.value) == null ? void 0 : _a.update();
  453. scrollToOption(states.selected);
  454. });
  455. };
  456. const focus = () => {
  457. var _a;
  458. (_a = inputRef.value) == null ? void 0 : _a.focus();
  459. };
  460. const blur = () => {
  461. var _a;
  462. if (expanded.value) {
  463. expanded.value = false;
  464. nextTick(() => {
  465. var _a2;
  466. return (_a2 = inputRef.value) == null ? void 0 : _a2.blur();
  467. });
  468. return;
  469. }
  470. (_a = inputRef.value) == null ? void 0 : _a.blur();
  471. };
  472. const handleClearClick = (event) => {
  473. deleteSelected(event);
  474. };
  475. const handleClickOutside = (event) => {
  476. expanded.value = false;
  477. if (isFocused.value) {
  478. const _event = new FocusEvent("blur", event);
  479. nextTick(() => handleBlur(_event));
  480. }
  481. };
  482. const handleEsc = () => {
  483. if (states.inputValue.length > 0) {
  484. states.inputValue = "";
  485. } else {
  486. expanded.value = false;
  487. }
  488. };
  489. const toggleMenu = () => {
  490. if (selectDisabled.value)
  491. return;
  492. if (isIOS)
  493. states.inputHovering = true;
  494. if (states.menuVisibleOnFocus) {
  495. states.menuVisibleOnFocus = false;
  496. } else {
  497. expanded.value = !expanded.value;
  498. }
  499. };
  500. const selectOption = () => {
  501. if (!expanded.value) {
  502. toggleMenu();
  503. } else {
  504. const option = optionsArray.value[states.hoveringIndex];
  505. if (option && !option.isDisabled) {
  506. handleOptionSelect(option);
  507. }
  508. }
  509. };
  510. const getValueKey = (item) => {
  511. return isObject(item.value) ? get(item.value, props.valueKey) : item.value;
  512. };
  513. const optionsAllDisabled = computed(() => optionsArray.value.filter((option) => option.visible).every((option) => option.isDisabled));
  514. const showTagList = computed(() => {
  515. if (!props.multiple) {
  516. return [];
  517. }
  518. return props.collapseTags ? states.selected.slice(0, props.maxCollapseTags) : states.selected;
  519. });
  520. const collapseTagList = computed(() => {
  521. if (!props.multiple) {
  522. return [];
  523. }
  524. return props.collapseTags ? states.selected.slice(props.maxCollapseTags) : [];
  525. });
  526. const navigateOptions = (direction) => {
  527. if (!expanded.value) {
  528. expanded.value = true;
  529. return;
  530. }
  531. if (states.options.size === 0 || filteredOptionsCount.value === 0 || isComposing.value)
  532. return;
  533. if (!optionsAllDisabled.value) {
  534. if (direction === "next") {
  535. states.hoveringIndex++;
  536. if (states.hoveringIndex === states.options.size) {
  537. states.hoveringIndex = 0;
  538. }
  539. } else if (direction === "prev") {
  540. states.hoveringIndex--;
  541. if (states.hoveringIndex < 0) {
  542. states.hoveringIndex = states.options.size - 1;
  543. }
  544. }
  545. const option = optionsArray.value[states.hoveringIndex];
  546. if (option.isDisabled || !option.visible) {
  547. navigateOptions(direction);
  548. }
  549. nextTick(() => scrollToOption(hoverOption.value));
  550. }
  551. };
  552. const getGapWidth = () => {
  553. if (!selectionRef.value)
  554. return 0;
  555. const style = window.getComputedStyle(selectionRef.value);
  556. return Number.parseFloat(style.gap || "6px");
  557. };
  558. const tagStyle = computed(() => {
  559. const gapWidth = getGapWidth();
  560. const inputSlotWidth = props.filterable ? gapWidth + MINIMUM_INPUT_WIDTH : 0;
  561. const maxWidth = collapseItemRef.value && props.maxCollapseTags === 1 ? states.selectionWidth - states.collapseItemWidth - gapWidth - inputSlotWidth : states.selectionWidth - inputSlotWidth;
  562. return { maxWidth: `${maxWidth}px` };
  563. });
  564. const collapseTagStyle = computed(() => {
  565. return { maxWidth: `${states.selectionWidth}px` };
  566. });
  567. const popupScroll = (data) => {
  568. emit("popup-scroll", data);
  569. };
  570. useResizeObserver(selectionRef, resetSelectionWidth);
  571. useResizeObserver(wrapperRef, updateTooltip);
  572. useResizeObserver(tagMenuRef, updateTagTooltip);
  573. useResizeObserver(collapseItemRef, resetCollapseItemWidth);
  574. let stop;
  575. watch(() => dropdownMenuVisible.value, (newVal) => {
  576. if (newVal) {
  577. stop = useResizeObserver(menuRef, updateTooltip).stop;
  578. } else {
  579. stop == null ? void 0 : stop();
  580. stop = void 0;
  581. }
  582. });
  583. onMounted(() => {
  584. setSelected();
  585. });
  586. return {
  587. inputId,
  588. contentId,
  589. nsSelect,
  590. nsInput,
  591. states,
  592. isFocused,
  593. expanded,
  594. optionsArray,
  595. hoverOption,
  596. selectSize,
  597. filteredOptionsCount,
  598. updateTooltip,
  599. updateTagTooltip,
  600. debouncedOnInputChange,
  601. onInput,
  602. deletePrevTag,
  603. deleteTag,
  604. deleteSelected,
  605. handleOptionSelect,
  606. scrollToOption,
  607. hasModelValue,
  608. shouldShowPlaceholder,
  609. currentPlaceholder,
  610. mouseEnterEventName,
  611. needStatusIcon,
  612. showClearBtn,
  613. iconComponent,
  614. iconReverse,
  615. validateState,
  616. validateIcon,
  617. showNewOption,
  618. updateOptions,
  619. collapseTagSize,
  620. setSelected,
  621. selectDisabled,
  622. emptyText,
  623. handleCompositionStart,
  624. handleCompositionUpdate,
  625. handleCompositionEnd,
  626. onOptionCreate,
  627. onOptionDestroy,
  628. handleMenuEnter,
  629. focus,
  630. blur,
  631. handleClearClick,
  632. handleClickOutside,
  633. handleEsc,
  634. toggleMenu,
  635. selectOption,
  636. getValueKey,
  637. navigateOptions,
  638. dropdownMenuVisible,
  639. showTagList,
  640. collapseTagList,
  641. popupScroll,
  642. getOption,
  643. tagStyle,
  644. collapseTagStyle,
  645. popperRef,
  646. inputRef,
  647. tooltipRef,
  648. tagTooltipRef,
  649. prefixRef,
  650. suffixRef,
  651. selectRef,
  652. wrapperRef,
  653. selectionRef,
  654. scrollbarRef,
  655. menuRef,
  656. tagMenuRef,
  657. collapseItemRef
  658. };
  659. };
  660. export { useSelect };
  661. //# sourceMappingURL=useSelect.mjs.map