vant 2.12.31 → 2.12.34

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/vant.js CHANGED
@@ -2221,8 +2221,12 @@ function getElementTranslateY(element) {
2221
2221
 
2222
2222
  function isOptionDisabled(option) {
2223
2223
  return Object(utils["f" /* isObject */])(option) && option.disabled;
2224
- }
2224
+ } // use standard WheelEvent:
2225
+ // https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent
2226
+
2225
2227
 
2228
+ var supportMousewheel = utils["b" /* inBrowser */] && 'onwheel' in window;
2229
+ var mousewheelTimer = null;
2226
2230
  /* harmony default export */ var PickerColumn = (PickerColumn_createComponent({
2227
2231
  mixins: [TouchMixin],
2228
2232
  props: {
@@ -2258,6 +2262,10 @@ function isOptionDisabled(option) {
2258
2262
  },
2259
2263
  mounted: function mounted() {
2260
2264
  this.bindTouchEvent(this.$el);
2265
+
2266
+ if (supportMousewheel) {
2267
+ event_on(this.$el, 'wheel', this.onMouseWheel, false);
2268
+ }
2261
2269
  },
2262
2270
  destroyed: function destroyed() {
2263
2271
  var children = this.$parent.children;
@@ -2265,6 +2273,10 @@ function isOptionDisabled(option) {
2265
2273
  if (children) {
2266
2274
  children.splice(children.indexOf(this), 1);
2267
2275
  }
2276
+
2277
+ if (supportMousewheel) {
2278
+ off(this.$el, 'wheel');
2279
+ }
2268
2280
  },
2269
2281
  watch: {
2270
2282
  initialOptions: 'setOptions',
@@ -2352,6 +2364,43 @@ function isOptionDisabled(option) {
2352
2364
  _this.moving = false;
2353
2365
  }, 0);
2354
2366
  },
2367
+ onMouseWheel: function onMouseWheel(event) {
2368
+ var _this2 = this;
2369
+
2370
+ if (this.readonly) {
2371
+ return;
2372
+ }
2373
+
2374
+ preventDefault(event, true); // simply combine touchstart and touchmove
2375
+
2376
+ var translateY = getElementTranslateY(this.$refs.wrapper);
2377
+ this.startOffset = Math.min(0, translateY - this.baseOffset);
2378
+ this.momentumOffset = this.startOffset;
2379
+ this.transitionEndTrigger = null; // directly use deltaY, see https://caniuse.com/?search=deltaY
2380
+ // use deltaY to detect direction for not special setting device
2381
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event
2382
+
2383
+ var deltaY = event.deltaY;
2384
+
2385
+ if (this.startOffset === 0 && deltaY < 0) {
2386
+ return;
2387
+ } // get offset
2388
+ // if necessary, can adjust distance value to make scrolling smoother
2389
+
2390
+
2391
+ var distance = -deltaY;
2392
+ this.offset = range(this.startOffset + distance, -(this.count * this.itemHeight), this.itemHeight);
2393
+
2394
+ if (mousewheelTimer) {
2395
+ clearTimeout(mousewheelTimer);
2396
+ }
2397
+
2398
+ mousewheelTimer = setTimeout(function () {
2399
+ _this2.onTouchEnd();
2400
+
2401
+ _this2.touchStartTime = 0;
2402
+ }, MOMENTUM_LIMIT_TIME);
2403
+ },
2355
2404
  onTransitionEnd: function onTransitionEnd() {
2356
2405
  this.stopMomentum();
2357
2406
  },
@@ -2383,17 +2432,17 @@ function isOptionDisabled(option) {
2383
2432
  return option;
2384
2433
  },
2385
2434
  setIndex: function setIndex(index, emitChange) {
2386
- var _this2 = this;
2435
+ var _this3 = this;
2387
2436
 
2388
2437
  index = this.adjustIndex(index) || 0;
2389
2438
  var offset = -index * this.itemHeight;
2390
2439
 
2391
2440
  var trigger = function trigger() {
2392
- if (index !== _this2.currentIndex) {
2393
- _this2.currentIndex = index;
2441
+ if (index !== _this3.currentIndex) {
2442
+ _this3.currentIndex = index;
2394
2443
 
2395
2444
  if (emitChange) {
2396
- _this2.$emit('change', index);
2445
+ _this3.$emit('change', index);
2397
2446
  }
2398
2447
  }
2399
2448
  }; // trigger the change event after transitionend when moving
@@ -2439,7 +2488,7 @@ function isOptionDisabled(option) {
2439
2488
  }
2440
2489
  },
2441
2490
  genOptions: function genOptions() {
2442
- var _this3 = this;
2491
+ var _this4 = this;
2443
2492
 
2444
2493
  var h = this.$createElement;
2445
2494
  var optionStyle = {
@@ -2448,7 +2497,7 @@ function isOptionDisabled(option) {
2448
2497
  return this.options.map(function (option, index) {
2449
2498
  var _domProps;
2450
2499
 
2451
- var text = _this3.getOptionText(option);
2500
+ var text = _this4.getOptionText(option);
2452
2501
 
2453
2502
  var disabled = isOptionDisabled(option);
2454
2503
  var data = {
@@ -2459,19 +2508,19 @@ function isOptionDisabled(option) {
2459
2508
  },
2460
2509
  class: [PickerColumn_bem('item', {
2461
2510
  disabled: disabled,
2462
- selected: index === _this3.currentIndex
2511
+ selected: index === _this4.currentIndex
2463
2512
  })],
2464
2513
  on: {
2465
2514
  click: function click() {
2466
- _this3.onClickItem(index);
2515
+ _this4.onClickItem(index);
2467
2516
  }
2468
2517
  }
2469
2518
  };
2470
2519
  var childData = {
2471
2520
  class: 'van-ellipsis',
2472
- domProps: (_domProps = {}, _domProps[_this3.allowHtml ? 'innerHTML' : 'textContent'] = text, _domProps)
2521
+ domProps: (_domProps = {}, _domProps[_this4.allowHtml ? 'innerHTML' : 'textContent'] = text, _domProps)
2473
2522
  };
2474
- return h("li", helper_default()([{}, data]), [_this3.slots('option', option) || h("div", helper_default()([{}, childData]))]);
2523
+ return h("li", helper_default()([{}, data]), [_this4.slots('option', option) || h("div", helper_default()([{}, childData]))]);
2475
2524
  });
2476
2525
  }
2477
2526
  },
@@ -3751,13 +3800,15 @@ var field_createNamespace = Object(create["a" /* createNamespace */])('field'),
3751
3800
 
3752
3801
  /* istanbul ignore if */
3753
3802
 
3754
- var readonly = this.getProp('readonly');
3755
-
3756
- if (readonly) {
3803
+ if (this.getProp('readonly')) {
3757
3804
  this.blur();
3758
3805
  }
3759
3806
  },
3760
3807
  onBlur: function onBlur(event) {
3808
+ if (this.getProp('readonly')) {
3809
+ return;
3810
+ }
3811
+
3761
3812
  this.focused = false;
3762
3813
  this.updateValue(this.value, 'onBlur');
3763
3814
  this.$emit('blur', event);
@@ -10976,6 +11027,9 @@ var TimePicker_createNamespace = Object(create["a" /* createNamespace */])('time
10976
11027
  this.updateInnerValue();
10977
11028
  this.$nextTick(function () {
10978
11029
  _this2.$nextTick(function () {
11030
+ // https://github.com/youzan/vant/issues/9775
11031
+ _this2.updateInnerValue();
11032
+
10979
11033
  _this2.$emit('change', picker);
10980
11034
  });
10981
11035
  });
@@ -12730,10 +12784,16 @@ var swipe_createNamespace = Object(create["a" /* createNamespace */])('swipe'),
12730
12784
  },
12731
12785
  onTouchMove: function onTouchMove(event) {
12732
12786
  if (!this.touchable || !this.swiping) return;
12733
- this.touchMove(event);
12787
+ this.touchMove(event); // if user starting to touchmove, prevent the event bubbling to
12788
+ // avoid affecting the parent components
12734
12789
 
12735
- if (this.isCorrectDirection) {
12790
+ var shouldPrevent = this.isCorrectDirection || this.offsetY > this.offsetX === this.vertical;
12791
+
12792
+ if (shouldPrevent) {
12736
12793
  preventDefault(event, this.stopPropagation);
12794
+ }
12795
+
12796
+ if (this.isCorrectDirection) {
12737
12797
  this.move({
12738
12798
  offset: this.delta
12739
12799
  });
@@ -14259,7 +14319,7 @@ var notice_bar_createNamespace = Object(create["a" /* createNamespace */])('noti
14259
14319
  mixins: [BindEventMixin(function (bind) {
14260
14320
  // fix cache issues with forwards and back history in safari
14261
14321
  // see: https://guwii.com/cache-issues-with-forwards-and-back-history-in-safari/
14262
- bind(window, 'pageshow', this.start);
14322
+ bind(window, 'pageshow', this.reset);
14263
14323
  })],
14264
14324
  inject: {
14265
14325
  vanPopup: {
@@ -14296,24 +14356,20 @@ var notice_bar_createNamespace = Object(create["a" /* createNamespace */])('noti
14296
14356
  };
14297
14357
  },
14298
14358
  watch: {
14299
- scrollable: 'start',
14359
+ scrollable: 'reset',
14300
14360
  text: {
14301
- handler: 'start',
14361
+ handler: 'reset',
14302
14362
  immediate: true
14303
14363
  }
14304
14364
  },
14305
14365
  created: function created() {
14306
- var _this = this; // https://github.com/youzan/vant/issues/8634
14307
-
14308
-
14366
+ // https://github.com/youzan/vant/issues/8634
14309
14367
  if (this.vanPopup) {
14310
- this.vanPopup.onReopen(function () {
14311
- _this.start();
14312
- });
14368
+ this.vanPopup.onReopen(this.reset);
14313
14369
  }
14314
14370
  },
14315
14371
  activated: function activated() {
14316
- this.start();
14372
+ this.reset();
14317
14373
  },
14318
14374
  methods: {
14319
14375
  onClickIcon: function onClickIcon(event) {
@@ -14323,7 +14379,7 @@ var notice_bar_createNamespace = Object(create["a" /* createNamespace */])('noti
14323
14379
  }
14324
14380
  },
14325
14381
  onTransitionEnd: function onTransitionEnd() {
14326
- var _this2 = this;
14382
+ var _this = this;
14327
14383
 
14328
14384
  this.offset = this.wrapWidth;
14329
14385
  this.duration = 0; // wait for Vue to render offset
@@ -14332,50 +14388,52 @@ var notice_bar_createNamespace = Object(create["a" /* createNamespace */])('noti
14332
14388
  Object(raf["c" /* raf */])(function () {
14333
14389
  // use double raf to ensure animation can start
14334
14390
  Object(raf["b" /* doubleRaf */])(function () {
14335
- _this2.offset = -_this2.contentWidth;
14336
- _this2.duration = (_this2.contentWidth + _this2.wrapWidth) / _this2.speed;
14391
+ _this.offset = -_this.contentWidth;
14392
+ _this.duration = (_this.contentWidth + _this.wrapWidth) / _this.speed;
14337
14393
 
14338
- _this2.$emit('replay');
14394
+ _this.$emit('replay');
14339
14395
  });
14340
14396
  });
14341
14397
  },
14398
+ // not an exposed-api, but may used by some users
14399
+ start: function start() {
14400
+ this.reset();
14401
+ },
14402
+ // @exposed-api
14342
14403
  reset: function reset() {
14404
+ var _this2 = this;
14405
+
14406
+ var delay = Object(utils["c" /* isDef */])(this.delay) ? this.delay * 1000 : 0;
14343
14407
  this.offset = 0;
14344
14408
  this.duration = 0;
14345
14409
  this.wrapWidth = 0;
14346
14410
  this.contentWidth = 0;
14347
- },
14348
- start: function start() {
14349
- var _this3 = this;
14350
-
14351
- var delay = Object(utils["c" /* isDef */])(this.delay) ? this.delay * 1000 : 0;
14352
- this.reset();
14353
14411
  clearTimeout(this.startTimer);
14354
14412
  this.startTimer = setTimeout(function () {
14355
- var _this3$$refs = _this3.$refs,
14356
- wrap = _this3$$refs.wrap,
14357
- content = _this3$$refs.content;
14413
+ var _this2$$refs = _this2.$refs,
14414
+ wrap = _this2$$refs.wrap,
14415
+ content = _this2$$refs.content;
14358
14416
 
14359
- if (!wrap || !content || _this3.scrollable === false) {
14417
+ if (!wrap || !content || _this2.scrollable === false) {
14360
14418
  return;
14361
14419
  }
14362
14420
 
14363
14421
  var wrapWidth = wrap.getBoundingClientRect().width;
14364
14422
  var contentWidth = content.getBoundingClientRect().width;
14365
14423
 
14366
- if (_this3.scrollable || contentWidth > wrapWidth) {
14424
+ if (_this2.scrollable || contentWidth > wrapWidth) {
14367
14425
  Object(raf["b" /* doubleRaf */])(function () {
14368
- _this3.offset = -contentWidth;
14369
- _this3.duration = contentWidth / _this3.speed;
14370
- _this3.wrapWidth = wrapWidth;
14371
- _this3.contentWidth = contentWidth;
14426
+ _this2.offset = -contentWidth;
14427
+ _this2.duration = contentWidth / _this2.speed;
14428
+ _this2.wrapWidth = wrapWidth;
14429
+ _this2.contentWidth = contentWidth;
14372
14430
  });
14373
14431
  }
14374
14432
  }, delay);
14375
14433
  }
14376
14434
  },
14377
14435
  render: function render() {
14378
- var _this4 = this;
14436
+ var _this3 = this;
14379
14437
 
14380
14438
  var h = arguments[0];
14381
14439
  var slots = this.slots,
@@ -14450,7 +14508,7 @@ var notice_bar_createNamespace = Object(create["a" /* createNamespace */])('noti
14450
14508
  "style": barStyle,
14451
14509
  "on": {
14452
14510
  "click": function click(event) {
14453
- _this4.$emit('click', event);
14511
+ _this3.$emit('click', event);
14454
14512
  }
14455
14513
  }
14456
14514
  }, [LeftIcon(), h("div", {
@@ -15616,10 +15674,10 @@ var right = 'right';
15616
15674
  var esm_left = 'left';
15617
15675
  var auto = 'auto';
15618
15676
  var basePlacements = [esm_top, esm_bottom, right, esm_left];
15619
- var esm_start = 'start';
15677
+ var start = 'start';
15620
15678
  var end = 'end';
15621
15679
  var placements = /*#__PURE__*/[].concat(basePlacements, [auto]).reduce(function (acc, placement) {
15622
- return acc.concat([placement, placement + "-" + esm_start, placement + "-" + end]);
15680
+ return acc.concat([placement, placement + "-" + start, placement + "-" + end]);
15623
15681
  }, []); // modifiers that need to read the DOM
15624
15682
 
15625
15683
  var beforeRead = 'beforeRead';
@@ -15872,7 +15930,7 @@ function computeOffsets(_ref) {
15872
15930
  var len = mainAxis === 'y' ? 'height' : 'width';
15873
15931
 
15874
15932
  switch (variation) {
15875
- case esm_start:
15933
+ case start:
15876
15934
  offsets[mainAxis] = offsets[mainAxis] - (reference[len] / 2 - element[len] / 2);
15877
15935
  break;
15878
15936
 
@@ -21671,23 +21729,23 @@ var tabbar_createNamespace = Object(create["a" /* createNamespace */])('tabbar')
21671
21729
  var _this = this;
21672
21730
 
21673
21731
  this.children.forEach(function (item, index) {
21674
- item.active = (item.name || index) === _this.value;
21732
+ item.nameMatched = (item.name || index) === _this.value;
21675
21733
  });
21676
21734
  },
21677
- onChange: function onChange(active) {
21735
+ triggerChange: function triggerChange(active, afterChange) {
21678
21736
  var _this2 = this;
21679
21737
 
21680
- if (active !== this.value) {
21681
- callInterceptor({
21682
- interceptor: this.beforeChange,
21683
- args: [active],
21684
- done: function done() {
21685
- _this2.$emit('input', active);
21738
+ callInterceptor({
21739
+ interceptor: this.beforeChange,
21740
+ args: [active],
21741
+ done: function done() {
21742
+ _this2.$emit('input', active);
21686
21743
 
21687
- _this2.$emit('change', active);
21688
- }
21689
- });
21690
- }
21744
+ _this2.$emit('change', active);
21745
+
21746
+ afterChange();
21747
+ }
21748
+ });
21691
21749
  },
21692
21750
  genTabbar: function genTabbar() {
21693
21751
  var _ref;
@@ -21748,11 +21806,11 @@ var tabbar_item_createNamespace = Object(create["a" /* createNamespace */])('tab
21748
21806
  }),
21749
21807
  data: function data() {
21750
21808
  return {
21751
- active: false
21809
+ nameMatched: false
21752
21810
  };
21753
21811
  },
21754
21812
  computed: {
21755
- routeActive: function routeActive() {
21813
+ routeMatched: function routeMatched() {
21756
21814
  var to = this.to,
21757
21815
  $route = this.$route;
21758
21816
 
@@ -21760,22 +21818,33 @@ var tabbar_item_createNamespace = Object(create["a" /* createNamespace */])('tab
21760
21818
  var config = Object(utils["f" /* isObject */])(to) ? to : {
21761
21819
  path: to
21762
21820
  };
21763
- var pathMatched = config.path === $route.path;
21764
- var nameMatched = Object(utils["c" /* isDef */])(config.name) && config.name === $route.name;
21765
- return pathMatched || nameMatched;
21821
+ return !!$route.matched.find(function (r) {
21822
+ var pathMatched = config.path === r.path;
21823
+ var nameMatched = Object(utils["c" /* isDef */])(config.name) && config.name === r.name;
21824
+ return pathMatched || nameMatched;
21825
+ });
21766
21826
  }
21827
+ },
21828
+ active: function active() {
21829
+ return this.parent.route ? this.routeMatched : this.nameMatched;
21767
21830
  }
21768
21831
  },
21769
21832
  methods: {
21770
21833
  onClick: function onClick(event) {
21771
- this.parent.onChange(this.name || this.index);
21834
+ var _this = this;
21835
+
21836
+ if (!this.active) {
21837
+ this.parent.triggerChange(this.name || this.index, function () {
21838
+ route(_this.$router, _this);
21839
+ });
21840
+ }
21841
+
21772
21842
  this.$emit('click', event);
21773
- route(this.$router, this);
21774
21843
  },
21775
- genIcon: function genIcon(active) {
21844
+ genIcon: function genIcon() {
21776
21845
  var h = this.$createElement;
21777
21846
  var slot = this.slots('icon', {
21778
- active: active
21847
+ active: this.active
21779
21848
  });
21780
21849
 
21781
21850
  if (slot) {
@@ -21796,7 +21865,7 @@ var tabbar_item_createNamespace = Object(create["a" /* createNamespace */])('tab
21796
21865
  var _this$badge;
21797
21866
 
21798
21867
  var h = arguments[0];
21799
- var active = this.parent.route ? this.routeActive : this.active;
21868
+ var active = this.active;
21800
21869
  var color = this.parent[active ? 'activeColor' : 'inactiveColor'];
21801
21870
 
21802
21871
  if (false) {}
@@ -21813,7 +21882,7 @@ var tabbar_item_createNamespace = Object(create["a" /* createNamespace */])('tab
21813
21882
  }
21814
21883
  }, [h("div", {
21815
21884
  "class": tabbar_item_bem('icon')
21816
- }, [this.genIcon(active), h(es_info, {
21885
+ }, [this.genIcon(), h(es_info, {
21817
21886
  "attrs": {
21818
21887
  "dot": this.dot,
21819
21888
  "info": (_this$badge = this.badge) != null ? _this$badge : this.info
@@ -22056,7 +22125,7 @@ TreeSelect.props = {
22056
22125
 
22057
22126
 
22058
22127
 
22059
- var version = '2.12.31';
22128
+ var version = '2.12.34';
22060
22129
 
22061
22130
  function install(Vue) {
22062
22131
  var components = [action_sheet, address_edit, address_list, es_area, badge, es_button, calendar, card, cascader, cell, cell_group, es_checkbox, checkbox_group, circle, col, collapse, collapse_item, contact_card, contact_edit, contact_list, count_down, es_coupon, coupon_cell, coupon_list, datetime_picker, dialog, divider, dropdown_item, dropdown_menu, empty, es_field, es_form, goods_action, goods_action_button, goods_action_icon, grid, grid_item, es_icon, es_image, image_preview, index_anchor, index_bar, es_info, es_list, es_loading, locale["a" /* default */], nav_bar, notice_bar, notify, number_keyboard, es_overlay, pagination, panel, password_input, picker, popover, popup, es_progress, pull_refresh, es_radio, radio_group, es_rate, row, search, share_sheet, sidebar, sidebar_item, skeleton, es_sku, slider, es_step, stepper, steps, es_sticky, submit_bar, swipe, swipe_cell, swipe_item, es_switch, switch_cell, tab, tabbar, tabbar_item, tabs, es_tag, es_toast, tree_select, uploader];