6090f94e6d465a74ef8f02d63f4762230d56457399c95046727dc68c88218f7fe0c13c5162838c717ee65bdb7eed0d2900e29d0daea9c24aa69476b1baed16 22 KB

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