select2.js 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438
  1. 'use strict';
  2. Object.defineProperty(exports, '__esModule', { value: true });
  3. var vue = require('vue');
  4. var index$2 = require('../../tooltip/index.js');
  5. var index$1 = require('../../scrollbar/index.js');
  6. var index = require('../../tag/index.js');
  7. var index$3 = require('../../icon/index.js');
  8. var option = require('./option2.js');
  9. var selectDropdown = require('./select-dropdown.js');
  10. var useSelect = require('./useSelect.js');
  11. var token = require('./token.js');
  12. var options = require('./options.js');
  13. var select = require('./select.js');
  14. var pluginVue_exportHelper = require('../../../_virtual/plugin-vue_export-helper.js');
  15. var index$4 = require('../../../directives/click-outside/index.js');
  16. var event = require('../../../constants/event.js');
  17. var shared = require('@vue/shared');
  18. var index$5 = require('../../../hooks/use-calc-input-width/index.js');
  19. const COMPONENT_NAME = "ElSelect";
  20. const _sfc_main = vue.defineComponent({
  21. name: COMPONENT_NAME,
  22. componentName: COMPONENT_NAME,
  23. components: {
  24. ElSelectMenu: selectDropdown["default"],
  25. ElOption: option["default"],
  26. ElOptions: options["default"],
  27. ElTag: index.ElTag,
  28. ElScrollbar: index$1.ElScrollbar,
  29. ElTooltip: index$2.ElTooltip,
  30. ElIcon: index$3.ElIcon
  31. },
  32. directives: { ClickOutside: index$4["default"] },
  33. props: select.SelectProps,
  34. emits: [
  35. event.UPDATE_MODEL_EVENT,
  36. event.CHANGE_EVENT,
  37. "remove-tag",
  38. "clear",
  39. "visible-change",
  40. "focus",
  41. "blur",
  42. "popup-scroll"
  43. ],
  44. setup(props, { emit }) {
  45. const modelValue = vue.computed(() => {
  46. const { modelValue: rawModelValue, multiple } = props;
  47. const fallback = multiple ? [] : void 0;
  48. if (shared.isArray(rawModelValue)) {
  49. return multiple ? rawModelValue : fallback;
  50. }
  51. return multiple ? fallback : rawModelValue;
  52. });
  53. const _props = vue.reactive({
  54. ...vue.toRefs(props),
  55. modelValue
  56. });
  57. const API = useSelect.useSelect(_props, emit);
  58. const { calculatorRef, inputStyle } = index$5.useCalcInputWidth();
  59. vue.provide(token.selectKey, vue.reactive({
  60. props: _props,
  61. states: API.states,
  62. selectRef: API.selectRef,
  63. optionsArray: API.optionsArray,
  64. setSelected: API.setSelected,
  65. handleOptionSelect: API.handleOptionSelect,
  66. onOptionCreate: API.onOptionCreate,
  67. onOptionDestroy: API.onOptionDestroy
  68. }));
  69. const selectedLabel = vue.computed(() => {
  70. if (!props.multiple) {
  71. return API.states.selectedLabel;
  72. }
  73. return API.states.selected.map((i) => i.currentLabel);
  74. });
  75. return {
  76. ...API,
  77. modelValue,
  78. selectedLabel,
  79. calculatorRef,
  80. inputStyle
  81. };
  82. }
  83. });
  84. function _sfc_render(_ctx, _cache) {
  85. const _component_el_tag = vue.resolveComponent("el-tag");
  86. const _component_el_tooltip = vue.resolveComponent("el-tooltip");
  87. const _component_el_icon = vue.resolveComponent("el-icon");
  88. const _component_el_option = vue.resolveComponent("el-option");
  89. const _component_el_options = vue.resolveComponent("el-options");
  90. const _component_el_scrollbar = vue.resolveComponent("el-scrollbar");
  91. const _component_el_select_menu = vue.resolveComponent("el-select-menu");
  92. const _directive_click_outside = vue.resolveDirective("click-outside");
  93. return vue.withDirectives((vue.openBlock(), vue.createElementBlock("div", {
  94. ref: "selectRef",
  95. class: vue.normalizeClass([_ctx.nsSelect.b(), _ctx.nsSelect.m(_ctx.selectSize)]),
  96. [vue.toHandlerKey(_ctx.mouseEnterEventName)]: ($event) => _ctx.states.inputHovering = true,
  97. onMouseleave: ($event) => _ctx.states.inputHovering = false
  98. }, [
  99. vue.createVNode(_component_el_tooltip, {
  100. ref: "tooltipRef",
  101. visible: _ctx.dropdownMenuVisible,
  102. placement: _ctx.placement,
  103. teleported: _ctx.teleported,
  104. "popper-class": [_ctx.nsSelect.e("popper"), _ctx.popperClass],
  105. "popper-options": _ctx.popperOptions,
  106. "fallback-placements": _ctx.fallbackPlacements,
  107. effect: _ctx.effect,
  108. pure: "",
  109. trigger: "click",
  110. transition: `${_ctx.nsSelect.namespace.value}-zoom-in-top`,
  111. "stop-popper-mouse-event": false,
  112. "gpu-acceleration": false,
  113. persistent: _ctx.persistent,
  114. "append-to": _ctx.appendTo,
  115. "show-arrow": _ctx.showArrow,
  116. offset: _ctx.offset,
  117. onBeforeShow: _ctx.handleMenuEnter,
  118. onHide: ($event) => _ctx.states.isBeforeHide = false
  119. }, {
  120. default: vue.withCtx(() => {
  121. var _a;
  122. return [
  123. vue.createElementVNode("div", {
  124. ref: "wrapperRef",
  125. class: vue.normalizeClass([
  126. _ctx.nsSelect.e("wrapper"),
  127. _ctx.nsSelect.is("focused", _ctx.isFocused),
  128. _ctx.nsSelect.is("hovering", _ctx.states.inputHovering),
  129. _ctx.nsSelect.is("filterable", _ctx.filterable),
  130. _ctx.nsSelect.is("disabled", _ctx.selectDisabled)
  131. ]),
  132. onClick: vue.withModifiers(_ctx.toggleMenu, ["prevent"])
  133. }, [
  134. _ctx.$slots.prefix ? (vue.openBlock(), vue.createElementBlock("div", {
  135. key: 0,
  136. ref: "prefixRef",
  137. class: vue.normalizeClass(_ctx.nsSelect.e("prefix"))
  138. }, [
  139. vue.renderSlot(_ctx.$slots, "prefix")
  140. ], 2)) : vue.createCommentVNode("v-if", true),
  141. vue.createElementVNode("div", {
  142. ref: "selectionRef",
  143. class: vue.normalizeClass([
  144. _ctx.nsSelect.e("selection"),
  145. _ctx.nsSelect.is("near", _ctx.multiple && !_ctx.$slots.prefix && !!_ctx.states.selected.length)
  146. ])
  147. }, [
  148. _ctx.multiple ? vue.renderSlot(_ctx.$slots, "tag", { key: 0 }, () => [
  149. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.showTagList, (item) => {
  150. return vue.openBlock(), vue.createElementBlock("div", {
  151. key: _ctx.getValueKey(item),
  152. class: vue.normalizeClass(_ctx.nsSelect.e("selected-item"))
  153. }, [
  154. vue.createVNode(_component_el_tag, {
  155. closable: !_ctx.selectDisabled && !item.isDisabled,
  156. size: _ctx.collapseTagSize,
  157. type: _ctx.tagType,
  158. effect: _ctx.tagEffect,
  159. "disable-transitions": "",
  160. style: vue.normalizeStyle(_ctx.tagStyle),
  161. onClose: ($event) => _ctx.deleteTag($event, item)
  162. }, {
  163. default: vue.withCtx(() => [
  164. vue.createElementVNode("span", {
  165. class: vue.normalizeClass(_ctx.nsSelect.e("tags-text"))
  166. }, [
  167. vue.renderSlot(_ctx.$slots, "label", {
  168. label: item.currentLabel,
  169. value: item.value
  170. }, () => [
  171. vue.createTextVNode(vue.toDisplayString(item.currentLabel), 1)
  172. ])
  173. ], 2)
  174. ]),
  175. _: 2
  176. }, 1032, ["closable", "size", "type", "effect", "style", "onClose"])
  177. ], 2);
  178. }), 128)),
  179. _ctx.collapseTags && _ctx.states.selected.length > _ctx.maxCollapseTags ? (vue.openBlock(), vue.createBlock(_component_el_tooltip, {
  180. key: 0,
  181. ref: "tagTooltipRef",
  182. disabled: _ctx.dropdownMenuVisible || !_ctx.collapseTagsTooltip,
  183. "fallback-placements": ["bottom", "top", "right", "left"],
  184. effect: _ctx.effect,
  185. placement: "bottom",
  186. teleported: _ctx.teleported
  187. }, {
  188. default: vue.withCtx(() => [
  189. vue.createElementVNode("div", {
  190. ref: "collapseItemRef",
  191. class: vue.normalizeClass(_ctx.nsSelect.e("selected-item"))
  192. }, [
  193. vue.createVNode(_component_el_tag, {
  194. closable: false,
  195. size: _ctx.collapseTagSize,
  196. type: _ctx.tagType,
  197. effect: _ctx.tagEffect,
  198. "disable-transitions": "",
  199. style: vue.normalizeStyle(_ctx.collapseTagStyle)
  200. }, {
  201. default: vue.withCtx(() => [
  202. vue.createElementVNode("span", {
  203. class: vue.normalizeClass(_ctx.nsSelect.e("tags-text"))
  204. }, " + " + vue.toDisplayString(_ctx.states.selected.length - _ctx.maxCollapseTags), 3)
  205. ]),
  206. _: 1
  207. }, 8, ["size", "type", "effect", "style"])
  208. ], 2)
  209. ]),
  210. content: vue.withCtx(() => [
  211. vue.createElementVNode("div", {
  212. ref: "tagMenuRef",
  213. class: vue.normalizeClass(_ctx.nsSelect.e("selection"))
  214. }, [
  215. (vue.openBlock(true), vue.createElementBlock(vue.Fragment, null, vue.renderList(_ctx.collapseTagList, (item) => {
  216. return vue.openBlock(), vue.createElementBlock("div", {
  217. key: _ctx.getValueKey(item),
  218. class: vue.normalizeClass(_ctx.nsSelect.e("selected-item"))
  219. }, [
  220. vue.createVNode(_component_el_tag, {
  221. class: "in-tooltip",
  222. closable: !_ctx.selectDisabled && !item.isDisabled,
  223. size: _ctx.collapseTagSize,
  224. type: _ctx.tagType,
  225. effect: _ctx.tagEffect,
  226. "disable-transitions": "",
  227. onClose: ($event) => _ctx.deleteTag($event, item)
  228. }, {
  229. default: vue.withCtx(() => [
  230. vue.createElementVNode("span", {
  231. class: vue.normalizeClass(_ctx.nsSelect.e("tags-text"))
  232. }, [
  233. vue.renderSlot(_ctx.$slots, "label", {
  234. label: item.currentLabel,
  235. value: item.value
  236. }, () => [
  237. vue.createTextVNode(vue.toDisplayString(item.currentLabel), 1)
  238. ])
  239. ], 2)
  240. ]),
  241. _: 2
  242. }, 1032, ["closable", "size", "type", "effect", "onClose"])
  243. ], 2);
  244. }), 128))
  245. ], 2)
  246. ]),
  247. _: 3
  248. }, 8, ["disabled", "effect", "teleported"])) : vue.createCommentVNode("v-if", true)
  249. ]) : vue.createCommentVNode("v-if", true),
  250. vue.createElementVNode("div", {
  251. class: vue.normalizeClass([
  252. _ctx.nsSelect.e("selected-item"),
  253. _ctx.nsSelect.e("input-wrapper"),
  254. _ctx.nsSelect.is("hidden", !_ctx.filterable)
  255. ])
  256. }, [
  257. vue.withDirectives(vue.createElementVNode("input", {
  258. id: _ctx.inputId,
  259. ref: "inputRef",
  260. "onUpdate:modelValue": ($event) => _ctx.states.inputValue = $event,
  261. type: "text",
  262. name: _ctx.name,
  263. class: vue.normalizeClass([_ctx.nsSelect.e("input"), _ctx.nsSelect.is(_ctx.selectSize)]),
  264. disabled: _ctx.selectDisabled,
  265. autocomplete: _ctx.autocomplete,
  266. style: vue.normalizeStyle(_ctx.inputStyle),
  267. tabindex: _ctx.tabindex,
  268. role: "combobox",
  269. readonly: !_ctx.filterable,
  270. spellcheck: "false",
  271. "aria-activedescendant": ((_a = _ctx.hoverOption) == null ? void 0 : _a.id) || "",
  272. "aria-controls": _ctx.contentId,
  273. "aria-expanded": _ctx.dropdownMenuVisible,
  274. "aria-label": _ctx.ariaLabel,
  275. "aria-autocomplete": "none",
  276. "aria-haspopup": "listbox",
  277. onKeydown: [
  278. vue.withKeys(vue.withModifiers(($event) => _ctx.navigateOptions("next"), ["stop", "prevent"]), ["down"]),
  279. vue.withKeys(vue.withModifiers(($event) => _ctx.navigateOptions("prev"), ["stop", "prevent"]), ["up"]),
  280. vue.withKeys(vue.withModifiers(_ctx.handleEsc, ["stop", "prevent"]), ["esc"]),
  281. vue.withKeys(vue.withModifiers(_ctx.selectOption, ["stop", "prevent"]), ["enter"]),
  282. vue.withKeys(vue.withModifiers(_ctx.deletePrevTag, ["stop"]), ["delete"])
  283. ],
  284. onCompositionstart: _ctx.handleCompositionStart,
  285. onCompositionupdate: _ctx.handleCompositionUpdate,
  286. onCompositionend: _ctx.handleCompositionEnd,
  287. onInput: _ctx.onInput,
  288. onClick: vue.withModifiers(_ctx.toggleMenu, ["stop"])
  289. }, null, 46, ["id", "onUpdate:modelValue", "name", "disabled", "autocomplete", "tabindex", "readonly", "aria-activedescendant", "aria-controls", "aria-expanded", "aria-label", "onKeydown", "onCompositionstart", "onCompositionupdate", "onCompositionend", "onInput", "onClick"]), [
  290. [vue.vModelText, _ctx.states.inputValue]
  291. ]),
  292. _ctx.filterable ? (vue.openBlock(), vue.createElementBlock("span", {
  293. key: 0,
  294. ref: "calculatorRef",
  295. "aria-hidden": "true",
  296. class: vue.normalizeClass(_ctx.nsSelect.e("input-calculator")),
  297. textContent: vue.toDisplayString(_ctx.states.inputValue)
  298. }, null, 10, ["textContent"])) : vue.createCommentVNode("v-if", true)
  299. ], 2),
  300. _ctx.shouldShowPlaceholder ? (vue.openBlock(), vue.createElementBlock("div", {
  301. key: 1,
  302. class: vue.normalizeClass([
  303. _ctx.nsSelect.e("selected-item"),
  304. _ctx.nsSelect.e("placeholder"),
  305. _ctx.nsSelect.is("transparent", !_ctx.hasModelValue || _ctx.expanded && !_ctx.states.inputValue)
  306. ])
  307. }, [
  308. _ctx.hasModelValue ? vue.renderSlot(_ctx.$slots, "label", {
  309. key: 0,
  310. label: _ctx.currentPlaceholder,
  311. value: _ctx.modelValue
  312. }, () => [
  313. vue.createElementVNode("span", null, vue.toDisplayString(_ctx.currentPlaceholder), 1)
  314. ]) : (vue.openBlock(), vue.createElementBlock("span", { key: 1 }, vue.toDisplayString(_ctx.currentPlaceholder), 1))
  315. ], 2)) : vue.createCommentVNode("v-if", true)
  316. ], 2),
  317. vue.createElementVNode("div", {
  318. ref: "suffixRef",
  319. class: vue.normalizeClass(_ctx.nsSelect.e("suffix"))
  320. }, [
  321. _ctx.iconComponent && !_ctx.showClose ? (vue.openBlock(), vue.createBlock(_component_el_icon, {
  322. key: 0,
  323. class: vue.normalizeClass([_ctx.nsSelect.e("caret"), _ctx.nsSelect.e("icon"), _ctx.iconReverse])
  324. }, {
  325. default: vue.withCtx(() => [
  326. (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.iconComponent)))
  327. ]),
  328. _: 1
  329. }, 8, ["class"])) : vue.createCommentVNode("v-if", true),
  330. _ctx.showClose && _ctx.clearIcon ? (vue.openBlock(), vue.createBlock(_component_el_icon, {
  331. key: 1,
  332. class: vue.normalizeClass([
  333. _ctx.nsSelect.e("caret"),
  334. _ctx.nsSelect.e("icon"),
  335. _ctx.nsSelect.e("clear")
  336. ]),
  337. onClick: _ctx.handleClearClick
  338. }, {
  339. default: vue.withCtx(() => [
  340. (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.clearIcon)))
  341. ]),
  342. _: 1
  343. }, 8, ["class", "onClick"])) : vue.createCommentVNode("v-if", true),
  344. _ctx.validateState && _ctx.validateIcon && _ctx.needStatusIcon ? (vue.openBlock(), vue.createBlock(_component_el_icon, {
  345. key: 2,
  346. class: vue.normalizeClass([
  347. _ctx.nsInput.e("icon"),
  348. _ctx.nsInput.e("validateIcon"),
  349. _ctx.nsInput.is("loading", _ctx.validateState === "validating")
  350. ])
  351. }, {
  352. default: vue.withCtx(() => [
  353. (vue.openBlock(), vue.createBlock(vue.resolveDynamicComponent(_ctx.validateIcon)))
  354. ]),
  355. _: 1
  356. }, 8, ["class"])) : vue.createCommentVNode("v-if", true)
  357. ], 2)
  358. ], 10, ["onClick"])
  359. ];
  360. }),
  361. content: vue.withCtx(() => [
  362. vue.createVNode(_component_el_select_menu, { ref: "menuRef" }, {
  363. default: vue.withCtx(() => [
  364. _ctx.$slots.header ? (vue.openBlock(), vue.createElementBlock("div", {
  365. key: 0,
  366. class: vue.normalizeClass(_ctx.nsSelect.be("dropdown", "header")),
  367. onClick: vue.withModifiers(() => {
  368. }, ["stop"])
  369. }, [
  370. vue.renderSlot(_ctx.$slots, "header")
  371. ], 10, ["onClick"])) : vue.createCommentVNode("v-if", true),
  372. vue.withDirectives(vue.createVNode(_component_el_scrollbar, {
  373. id: _ctx.contentId,
  374. ref: "scrollbarRef",
  375. tag: "ul",
  376. "wrap-class": _ctx.nsSelect.be("dropdown", "wrap"),
  377. "view-class": _ctx.nsSelect.be("dropdown", "list"),
  378. class: vue.normalizeClass([_ctx.nsSelect.is("empty", _ctx.filteredOptionsCount === 0)]),
  379. role: "listbox",
  380. "aria-label": _ctx.ariaLabel,
  381. "aria-orientation": "vertical",
  382. onScroll: _ctx.popupScroll
  383. }, {
  384. default: vue.withCtx(() => [
  385. _ctx.showNewOption ? (vue.openBlock(), vue.createBlock(_component_el_option, {
  386. key: 0,
  387. value: _ctx.states.inputValue,
  388. created: true
  389. }, null, 8, ["value"])) : vue.createCommentVNode("v-if", true),
  390. vue.createVNode(_component_el_options, null, {
  391. default: vue.withCtx(() => [
  392. vue.renderSlot(_ctx.$slots, "default")
  393. ]),
  394. _: 3
  395. })
  396. ]),
  397. _: 3
  398. }, 8, ["id", "wrap-class", "view-class", "class", "aria-label", "onScroll"]), [
  399. [vue.vShow, _ctx.states.options.size > 0 && !_ctx.loading]
  400. ]),
  401. _ctx.$slots.loading && _ctx.loading ? (vue.openBlock(), vue.createElementBlock("div", {
  402. key: 1,
  403. class: vue.normalizeClass(_ctx.nsSelect.be("dropdown", "loading"))
  404. }, [
  405. vue.renderSlot(_ctx.$slots, "loading")
  406. ], 2)) : _ctx.loading || _ctx.filteredOptionsCount === 0 ? (vue.openBlock(), vue.createElementBlock("div", {
  407. key: 2,
  408. class: vue.normalizeClass(_ctx.nsSelect.be("dropdown", "empty"))
  409. }, [
  410. vue.renderSlot(_ctx.$slots, "empty", {}, () => [
  411. vue.createElementVNode("span", null, vue.toDisplayString(_ctx.emptyText), 1)
  412. ])
  413. ], 2)) : vue.createCommentVNode("v-if", true),
  414. _ctx.$slots.footer ? (vue.openBlock(), vue.createElementBlock("div", {
  415. key: 3,
  416. class: vue.normalizeClass(_ctx.nsSelect.be("dropdown", "footer")),
  417. onClick: vue.withModifiers(() => {
  418. }, ["stop"])
  419. }, [
  420. vue.renderSlot(_ctx.$slots, "footer")
  421. ], 10, ["onClick"])) : vue.createCommentVNode("v-if", true)
  422. ]),
  423. _: 3
  424. }, 512)
  425. ]),
  426. _: 3
  427. }, 8, ["visible", "placement", "teleported", "popper-class", "popper-options", "fallback-placements", "effect", "transition", "persistent", "append-to", "show-arrow", "offset", "onBeforeShow", "onHide"])
  428. ], 16, ["onMouseleave"])), [
  429. [_directive_click_outside, _ctx.handleClickOutside, _ctx.popperRef]
  430. ]);
  431. }
  432. var Select = /* @__PURE__ */ pluginVue_exportHelper["default"](_sfc_main, [["render", _sfc_render], ["__file", "select.vue"]]);
  433. exports["default"] = Select;
  434. //# sourceMappingURL=select2.js.map