Ohm-Management - Projektarbeit B-ME
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

VSelect.js 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };
  2. function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
  3. // Styles
  4. import '../../../src/stylus/components/_text-fields.styl';
  5. import '../../../src/stylus/components/_select.styl';
  6. // Components
  7. import VChip from '../VChip';
  8. import VMenu from '../VMenu';
  9. import VSelectList from './VSelectList';
  10. // Extensions
  11. import VTextField from '../VTextField/VTextField';
  12. // Mixins
  13. import Comparable from '../../mixins/comparable';
  14. import Filterable from '../../mixins/filterable';
  15. // Directives
  16. import ClickOutside from '../../directives/click-outside';
  17. // Helpers
  18. import { camelize, getPropertyFromItem, keyCodes } from '../../util/helpers';
  19. import { consoleError, consoleWarn } from '../../util/console';
  20. export var defaultMenuProps = {
  21. closeOnClick: false,
  22. closeOnContentClick: false,
  23. openOnClick: false,
  24. maxHeight: 300
  25. };
  26. /* @vue/component */
  27. export default VTextField.extend({
  28. name: 'v-select',
  29. directives: {
  30. ClickOutside: ClickOutside
  31. },
  32. mixins: [Comparable, Filterable],
  33. props: {
  34. appendIcon: {
  35. type: String,
  36. default: '$vuetify.icons.dropdown'
  37. },
  38. appendIconCb: Function,
  39. attach: {
  40. type: null,
  41. default: false
  42. },
  43. browserAutocomplete: {
  44. type: String,
  45. default: 'on'
  46. },
  47. cacheItems: Boolean,
  48. chips: Boolean,
  49. clearable: Boolean,
  50. deletableChips: Boolean,
  51. dense: Boolean,
  52. hideSelected: Boolean,
  53. items: {
  54. type: Array,
  55. default: function _default() {
  56. return [];
  57. }
  58. },
  59. itemAvatar: {
  60. type: [String, Array, Function],
  61. default: 'avatar'
  62. },
  63. itemDisabled: {
  64. type: [String, Array, Function],
  65. default: 'disabled'
  66. },
  67. itemText: {
  68. type: [String, Array, Function],
  69. default: 'text'
  70. },
  71. itemValue: {
  72. type: [String, Array, Function],
  73. default: 'value'
  74. },
  75. menuProps: {
  76. type: [String, Array, Object],
  77. default: function _default() {
  78. return defaultMenuProps;
  79. }
  80. },
  81. multiple: Boolean,
  82. openOnClear: Boolean,
  83. returnObject: Boolean,
  84. searchInput: {
  85. default: null
  86. },
  87. smallChips: Boolean
  88. },
  89. data: function data(vm) {
  90. return {
  91. attrsInput: { role: 'combobox' },
  92. cachedItems: vm.cacheItems ? vm.items : [],
  93. content: null,
  94. isBooted: false,
  95. isMenuActive: false,
  96. lastItem: 20,
  97. // As long as a value is defined, show it
  98. // Otherwise, check if multiple
  99. // to determine which default to provide
  100. lazyValue: vm.value !== undefined ? vm.value : vm.multiple ? [] : undefined,
  101. selectedIndex: -1,
  102. selectedItems: [],
  103. keyboardLookupPrefix: '',
  104. keyboardLookupLastTime: 0
  105. };
  106. },
  107. computed: {
  108. /* All items that the select has */
  109. allItems: function allItems() {
  110. return this.filterDuplicates(this.cachedItems.concat(this.items));
  111. },
  112. classes: function classes() {
  113. return Object.assign({}, VTextField.options.computed.classes.call(this), {
  114. 'v-select': true,
  115. 'v-select--chips': this.hasChips,
  116. 'v-select--chips--small': this.smallChips,
  117. 'v-select--is-menu-active': this.isMenuActive
  118. });
  119. },
  120. /* Used by other components to overwrite */
  121. computedItems: function computedItems() {
  122. return this.allItems;
  123. },
  124. counterValue: function counterValue() {
  125. return this.multiple ? this.selectedItems.length : (this.getText(this.selectedItems[0]) || '').toString().length;
  126. },
  127. directives: function directives() {
  128. return this.isFocused ? [{
  129. name: 'click-outside',
  130. value: this.blur,
  131. args: {
  132. closeConditional: this.closeConditional
  133. }
  134. }] : undefined;
  135. },
  136. dynamicHeight: function dynamicHeight() {
  137. return 'auto';
  138. },
  139. hasChips: function hasChips() {
  140. return this.chips || this.smallChips;
  141. },
  142. hasSlot: function hasSlot() {
  143. return Boolean(this.hasChips || this.$scopedSlots.selection);
  144. },
  145. isDirty: function isDirty() {
  146. return this.selectedItems.length > 0;
  147. },
  148. listData: function listData() {
  149. var scopeId = this.$vnode && this.$vnode.context.$options._scopeId;
  150. return {
  151. attrs: scopeId ? _defineProperty({}, scopeId, true) : null,
  152. props: {
  153. action: this.multiple && !this.isHidingSelected,
  154. color: this.color,
  155. dense: this.dense,
  156. hideSelected: this.hideSelected,
  157. items: this.virtualizedItems,
  158. noDataText: this.$vuetify.t(this.noDataText),
  159. selectedItems: this.selectedItems,
  160. itemAvatar: this.itemAvatar,
  161. itemDisabled: this.itemDisabled,
  162. itemValue: this.itemValue,
  163. itemText: this.itemText
  164. },
  165. on: {
  166. select: this.selectItem
  167. },
  168. scopedSlots: {
  169. item: this.$scopedSlots.item
  170. }
  171. };
  172. },
  173. staticList: function staticList() {
  174. if (this.$slots['no-data'] || this.$slots['prepend-item'] || this.$slots['append-item']) {
  175. consoleError('assert: staticList should not be called if slots are used');
  176. }
  177. return this.$createElement(VSelectList, this.listData);
  178. },
  179. virtualizedItems: function virtualizedItems() {
  180. return this.$_menuProps.auto ? this.computedItems : this.computedItems.slice(0, this.lastItem);
  181. },
  182. menuCanShow: function menuCanShow() {
  183. return true;
  184. },
  185. $_menuProps: function $_menuProps() {
  186. var normalisedProps = void 0;
  187. normalisedProps = typeof this.menuProps === 'string' ? this.menuProps.split(',') : this.menuProps;
  188. if (Array.isArray(normalisedProps)) {
  189. normalisedProps = normalisedProps.reduce(function (acc, p) {
  190. acc[p.trim()] = true;
  191. return acc;
  192. }, {});
  193. }
  194. return _extends({}, defaultMenuProps, {
  195. value: this.menuCanShow && this.isMenuActive,
  196. nudgeBottom: this.nudgeBottom ? this.nudgeBottom : normalisedProps.offsetY ? 1 : 0
  197. }, normalisedProps);
  198. }
  199. },
  200. watch: {
  201. internalValue: function internalValue(val) {
  202. this.initialValue = val;
  203. this.setSelectedItems();
  204. },
  205. isBooted: function isBooted() {
  206. var _this = this;
  207. this.$nextTick(function () {
  208. if (_this.content && _this.content.addEventListener) {
  209. _this.content.addEventListener('scroll', _this.onScroll, false);
  210. }
  211. });
  212. },
  213. isMenuActive: function isMenuActive(val) {
  214. if (!val) return;
  215. this.isBooted = true;
  216. },
  217. items: {
  218. immediate: true,
  219. handler: function handler(val) {
  220. if (this.cacheItems) {
  221. this.cachedItems = this.filterDuplicates(this.cachedItems.concat(val));
  222. }
  223. this.setSelectedItems();
  224. }
  225. }
  226. },
  227. mounted: function mounted() {
  228. this.content = this.$refs.menu && this.$refs.menu.$refs.content;
  229. },
  230. methods: {
  231. /** @public */
  232. blur: function blur(e) {
  233. this.isMenuActive = false;
  234. this.isFocused = false;
  235. this.$refs.input && this.$refs.input.blur();
  236. this.selectedIndex = -1;
  237. this.onBlur(e);
  238. },
  239. /** @public */
  240. activateMenu: function activateMenu() {
  241. this.isMenuActive = true;
  242. },
  243. clearableCallback: function clearableCallback() {
  244. var _this2 = this;
  245. this.setValue(this.multiple ? [] : undefined);
  246. this.$nextTick(function () {
  247. return _this2.$refs.input.focus();
  248. });
  249. if (this.openOnClear) this.isMenuActive = true;
  250. },
  251. closeConditional: function closeConditional(e) {
  252. return (
  253. // Click originates from outside the menu content
  254. !!this.content && !this.content.contains(e.target) &&
  255. // Click originates from outside the element
  256. !!this.$el && !this.$el.contains(e.target) && e.target !== this.$el
  257. );
  258. },
  259. filterDuplicates: function filterDuplicates(arr) {
  260. var uniqueValues = new Map();
  261. for (var index = 0; index < arr.length; ++index) {
  262. var item = arr[index];
  263. var val = this.getValue(item);
  264. // TODO: comparator
  265. !uniqueValues.has(val) && uniqueValues.set(val, item);
  266. }
  267. return Array.from(uniqueValues.values());
  268. },
  269. findExistingIndex: function findExistingIndex(item) {
  270. var _this3 = this;
  271. var itemValue = this.getValue(item);
  272. return (this.internalValue || []).findIndex(function (i) {
  273. return _this3.valueComparator(_this3.getValue(i), itemValue);
  274. });
  275. },
  276. genChipSelection: function genChipSelection(item, index) {
  277. var _this4 = this;
  278. var isDisabled = this.disabled || this.readonly || this.getDisabled(item);
  279. return this.$createElement(VChip, {
  280. staticClass: 'v-chip--select-multi',
  281. attrs: { tabindex: -1 },
  282. props: {
  283. close: this.deletableChips && !isDisabled,
  284. disabled: isDisabled,
  285. selected: index === this.selectedIndex,
  286. small: this.smallChips
  287. },
  288. on: {
  289. click: function click(e) {
  290. if (isDisabled) return;
  291. e.stopPropagation();
  292. _this4.selectedIndex = index;
  293. },
  294. input: function input() {
  295. return _this4.onChipInput(item);
  296. }
  297. },
  298. key: this.getValue(item)
  299. }, this.getText(item));
  300. },
  301. genCommaSelection: function genCommaSelection(item, index, last) {
  302. // Item may be an object
  303. // TODO: Remove JSON.stringify
  304. var key = JSON.stringify(this.getValue(item));
  305. var color = index === this.selectedIndex && this.color;
  306. var isDisabled = this.disabled || this.getDisabled(item);
  307. return this.$createElement('div', this.setTextColor(color, {
  308. staticClass: 'v-select__selection v-select__selection--comma',
  309. 'class': {
  310. 'v-select__selection--disabled': isDisabled
  311. },
  312. key: key
  313. }), '' + this.getText(item) + (last ? '' : ', '));
  314. },
  315. genDefaultSlot: function genDefaultSlot() {
  316. var selections = this.genSelections();
  317. var input = this.genInput();
  318. // If the return is an empty array
  319. // push the input
  320. if (Array.isArray(selections)) {
  321. selections.push(input);
  322. // Otherwise push it into children
  323. } else {
  324. selections.children = selections.children || [];
  325. selections.children.push(input);
  326. }
  327. return [this.$createElement('div', {
  328. staticClass: 'v-select__slot',
  329. directives: this.directives
  330. }, [this.genLabel(), this.prefix ? this.genAffix('prefix') : null, selections, this.suffix ? this.genAffix('suffix') : null, this.genClearIcon(), this.genIconSlot()]), this.genMenu(), this.genProgress()];
  331. },
  332. genInput: function genInput() {
  333. var input = VTextField.options.methods.genInput.call(this);
  334. input.data.domProps.value = null;
  335. input.data.attrs.readonly = true;
  336. input.data.attrs['aria-readonly'] = String(this.readonly);
  337. input.data.on.keypress = this.onKeyPress;
  338. return input;
  339. },
  340. genList: function genList() {
  341. // If there's no slots, we can use a cached VNode to improve performance
  342. if (this.$slots['no-data'] || this.$slots['prepend-item'] || this.$slots['append-item']) {
  343. return this.genListWithSlot();
  344. } else {
  345. return this.staticList;
  346. }
  347. },
  348. genListWithSlot: function genListWithSlot() {
  349. var _this5 = this;
  350. var slots = ['prepend-item', 'no-data', 'append-item'].filter(function (slotName) {
  351. return _this5.$slots[slotName];
  352. }).map(function (slotName) {
  353. return _this5.$createElement('template', {
  354. slot: slotName
  355. }, _this5.$slots[slotName]);
  356. });
  357. // Requires destructuring due to Vue
  358. // modifying the `on` property when passed
  359. // as a referenced object
  360. return this.$createElement(VSelectList, _extends({}, this.listData), slots);
  361. },
  362. genMenu: function genMenu() {
  363. var _this6 = this;
  364. var props = this.$_menuProps;
  365. props.activator = this.$refs['input-slot'];
  366. // Deprecate using menu props directly
  367. // TODO: remove (2.0)
  368. var inheritedProps = Object.keys(VMenu.options.props);
  369. var deprecatedProps = Object.keys(this.$attrs).reduce(function (acc, attr) {
  370. if (inheritedProps.includes(camelize(attr))) acc.push(attr);
  371. return acc;
  372. }, []);
  373. var _iteratorNormalCompletion = true;
  374. var _didIteratorError = false;
  375. var _iteratorError = undefined;
  376. try {
  377. for (var _iterator = deprecatedProps[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) {
  378. var prop = _step.value;
  379. props[camelize(prop)] = this.$attrs[prop];
  380. }
  381. } catch (err) {
  382. _didIteratorError = true;
  383. _iteratorError = err;
  384. } finally {
  385. try {
  386. if (!_iteratorNormalCompletion && _iterator.return) {
  387. _iterator.return();
  388. }
  389. } finally {
  390. if (_didIteratorError) {
  391. throw _iteratorError;
  392. }
  393. }
  394. }
  395. if (process.env.NODE_ENV !== 'production') {
  396. if (deprecatedProps.length) {
  397. var multiple = deprecatedProps.length > 1;
  398. var replacement = deprecatedProps.reduce(function (acc, p) {
  399. acc[camelize(p)] = _this6.$attrs[p];
  400. return acc;
  401. }, {});
  402. var _props = deprecatedProps.map(function (p) {
  403. return '\'' + p + '\'';
  404. }).join(', ');
  405. var separator = multiple ? '\n' : '\'';
  406. var onlyBools = Object.keys(replacement).every(function (prop) {
  407. var propType = VMenu.options.props[prop];
  408. var value = replacement[prop];
  409. return value === true || (propType.type || propType) === Boolean && value === '';
  410. });
  411. if (onlyBools) {
  412. replacement = Object.keys(replacement).join(', ');
  413. } else {
  414. replacement = JSON.stringify(replacement, null, multiple ? 2 : 0).replace(/"([^(")"]+)":/g, '$1:').replace(/"/g, '\'');
  415. }
  416. consoleWarn(_props + ' ' + (multiple ? 'are' : 'is') + ' deprecated, use ' + ('' + separator + (onlyBools ? '' : ':') + 'menu-props="' + replacement + '"' + separator + ' instead'), this);
  417. }
  418. }
  419. // Attach to root el so that
  420. // menu covers prepend/append icons
  421. if (
  422. // TODO: make this a computed property or helper or something
  423. this.attach === '' || // If used as a boolean prop (<v-menu attach>)
  424. this.attach === true || // If bound to a boolean (<v-menu :attach="true">)
  425. this.attach === 'attach' // If bound as boolean prop in pug (v-menu(attach))
  426. ) {
  427. props.attach = this.$el;
  428. } else {
  429. props.attach = this.attach;
  430. }
  431. return this.$createElement(VMenu, {
  432. props: props,
  433. on: {
  434. input: function input(val) {
  435. _this6.isMenuActive = val;
  436. _this6.isFocused = val;
  437. }
  438. },
  439. ref: 'menu'
  440. }, [this.genList()]);
  441. },
  442. genSelections: function genSelections() {
  443. var length = this.selectedItems.length;
  444. var children = new Array(length);
  445. var genSelection = void 0;
  446. if (this.$scopedSlots.selection) {
  447. genSelection = this.genSlotSelection;
  448. } else if (this.hasChips) {
  449. genSelection = this.genChipSelection;
  450. } else {
  451. genSelection = this.genCommaSelection;
  452. }
  453. while (length--) {
  454. children[length] = genSelection(this.selectedItems[length], length, length === children.length - 1);
  455. }
  456. return this.$createElement('div', {
  457. staticClass: 'v-select__selections'
  458. }, children);
  459. },
  460. genSlotSelection: function genSlotSelection(item, index) {
  461. return this.$scopedSlots.selection({
  462. parent: this,
  463. item: item,
  464. index: index,
  465. selected: index === this.selectedIndex,
  466. disabled: this.disabled || this.readonly
  467. });
  468. },
  469. getMenuIndex: function getMenuIndex() {
  470. return this.$refs.menu ? this.$refs.menu.listIndex : -1;
  471. },
  472. getDisabled: function getDisabled(item) {
  473. return getPropertyFromItem(item, this.itemDisabled, false);
  474. },
  475. getText: function getText(item) {
  476. return getPropertyFromItem(item, this.itemText, item);
  477. },
  478. getValue: function getValue(item) {
  479. return getPropertyFromItem(item, this.itemValue, this.getText(item));
  480. },
  481. onBlur: function onBlur(e) {
  482. this.$emit('blur', e);
  483. },
  484. onChipInput: function onChipInput(item) {
  485. if (this.multiple) this.selectItem(item);else this.setValue(null);
  486. // If all items have been deleted,
  487. // open `v-menu`
  488. if (this.selectedItems.length === 0) {
  489. this.isMenuActive = true;
  490. } else {
  491. this.isMenuActive = false;
  492. }
  493. this.selectedIndex = -1;
  494. },
  495. onClick: function onClick() {
  496. if (this.isDisabled) return;
  497. this.isMenuActive = true;
  498. if (!this.isFocused) {
  499. this.isFocused = true;
  500. this.$emit('focus');
  501. }
  502. },
  503. onEnterDown: function onEnterDown() {
  504. this.onBlur();
  505. },
  506. onEscDown: function onEscDown(e) {
  507. e.preventDefault();
  508. if (this.isMenuActive) {
  509. e.stopPropagation();
  510. this.isMenuActive = false;
  511. }
  512. },
  513. onKeyPress: function onKeyPress(e) {
  514. var _this7 = this;
  515. if (this.multiple) return;
  516. var KEYBOARD_LOOKUP_THRESHOLD = 1000; // milliseconds
  517. var now = performance.now();
  518. if (now - this.keyboardLookupLastTime > KEYBOARD_LOOKUP_THRESHOLD) {
  519. this.keyboardLookupPrefix = '';
  520. }
  521. this.keyboardLookupPrefix += e.key.toLowerCase();
  522. this.keyboardLookupLastTime = now;
  523. var index = this.allItems.findIndex(function (item) {
  524. return _this7.getText(item).toLowerCase().startsWith(_this7.keyboardLookupPrefix);
  525. });
  526. var item = this.allItems[index];
  527. if (index !== -1) {
  528. this.setValue(this.returnObject ? item : this.getValue(item));
  529. setTimeout(function () {
  530. return _this7.setMenuIndex(index);
  531. });
  532. }
  533. },
  534. onKeyDown: function onKeyDown(e) {
  535. var keyCode = e.keyCode;
  536. // If enter, space, up, or down is pressed, open menu
  537. if (!this.readonly && !this.isMenuActive && [keyCodes.enter, keyCodes.space, keyCodes.up, keyCodes.down].includes(keyCode)) this.activateMenu();
  538. if (this.isMenuActive && this.$refs.menu) this.$refs.menu.changeListIndex(e);
  539. // This should do something different
  540. if (keyCode === keyCodes.enter) return this.onEnterDown(e);
  541. // If escape deactivate the menu
  542. if (keyCode === keyCodes.esc) return this.onEscDown(e);
  543. // If tab - select item or close menu
  544. if (keyCode === keyCodes.tab) return this.onTabDown(e);
  545. },
  546. onMouseUp: function onMouseUp(e) {
  547. var _this8 = this;
  548. if (this.hasMouseDown) {
  549. var appendInner = this.$refs['append-inner'];
  550. // If append inner is present
  551. // and the target is itself
  552. // or inside, toggle menu
  553. if (this.isMenuActive && appendInner && (appendInner === e.target || appendInner.contains(e.target))) {
  554. this.$nextTick(function () {
  555. return _this8.isMenuActive = !_this8.isMenuActive;
  556. });
  557. // If user is clicking in the container
  558. // and field is enclosed, activate it
  559. } else if (this.isEnclosed && !this.isDisabled) {
  560. this.isMenuActive = true;
  561. }
  562. }
  563. VTextField.options.methods.onMouseUp.call(this, e);
  564. },
  565. onScroll: function onScroll() {
  566. var _this9 = this;
  567. if (!this.isMenuActive) {
  568. requestAnimationFrame(function () {
  569. return _this9.content.scrollTop = 0;
  570. });
  571. } else {
  572. if (this.lastItem >= this.computedItems.length) return;
  573. var showMoreItems = this.content.scrollHeight - (this.content.scrollTop + this.content.clientHeight) < 200;
  574. if (showMoreItems) {
  575. this.lastItem += 20;
  576. }
  577. }
  578. },
  579. onTabDown: function onTabDown(e) {
  580. var menuIndex = this.getMenuIndex();
  581. var listTile = this.$refs.menu.tiles[menuIndex];
  582. // An item that is selected by
  583. // menu-index should toggled
  584. if (listTile && listTile.className.indexOf('v-list__tile--highlighted') > -1 && this.isMenuActive && menuIndex > -1) {
  585. e.preventDefault();
  586. e.stopPropagation();
  587. listTile.click();
  588. } else {
  589. // If we make it here,
  590. // the user has no selected indexes
  591. // and is probably tabbing out
  592. this.blur(e);
  593. }
  594. },
  595. selectItem: function selectItem(item) {
  596. var _this10 = this;
  597. if (!this.multiple) {
  598. this.setValue(this.returnObject ? item : this.getValue(item));
  599. this.isMenuActive = false;
  600. } else {
  601. var internalValue = (this.internalValue || []).slice();
  602. var i = this.findExistingIndex(item);
  603. i !== -1 ? internalValue.splice(i, 1) : internalValue.push(item);
  604. this.setValue(internalValue.map(function (i) {
  605. return _this10.returnObject ? i : _this10.getValue(i);
  606. }));
  607. // When selecting multiple
  608. // adjust menu after each
  609. // selection
  610. this.$nextTick(function () {
  611. _this10.$refs.menu && _this10.$refs.menu.updateDimensions();
  612. });
  613. }
  614. },
  615. setMenuIndex: function setMenuIndex(index) {
  616. this.$refs.menu && (this.$refs.menu.listIndex = index);
  617. },
  618. setSelectedItems: function setSelectedItems() {
  619. var _this11 = this;
  620. var selectedItems = [];
  621. var values = !this.multiple || !Array.isArray(this.internalValue) ? [this.internalValue] : this.internalValue;
  622. var _loop = function _loop(value) {
  623. var index = _this11.allItems.findIndex(function (v) {
  624. return _this11.valueComparator(_this11.getValue(v), _this11.getValue(value));
  625. });
  626. if (index > -1) {
  627. selectedItems.push(_this11.allItems[index]);
  628. }
  629. };
  630. var _iteratorNormalCompletion2 = true;
  631. var _didIteratorError2 = false;
  632. var _iteratorError2 = undefined;
  633. try {
  634. for (var _iterator2 = values[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) {
  635. var value = _step2.value;
  636. _loop(value);
  637. }
  638. } catch (err) {
  639. _didIteratorError2 = true;
  640. _iteratorError2 = err;
  641. } finally {
  642. try {
  643. if (!_iteratorNormalCompletion2 && _iterator2.return) {
  644. _iterator2.return();
  645. }
  646. } finally {
  647. if (_didIteratorError2) {
  648. throw _iteratorError2;
  649. }
  650. }
  651. }
  652. this.selectedItems = selectedItems;
  653. },
  654. setValue: function setValue(value) {
  655. var oldValue = this.internalValue;
  656. this.internalValue = value;
  657. value !== oldValue && this.$emit('change', value);
  658. }
  659. }
  660. });
  661. //# sourceMappingURL=VSelect.js.map