vant 2.12.30 → 2.12.34-beta.0

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/index.js CHANGED
@@ -361,7 +361,7 @@ exports.TreeSelect = _treeSelect.default;
361
361
  var _uploader = _interopRequireDefault(require("./uploader"));
362
362
 
363
363
  exports.Uploader = _uploader.default;
364
- var version = '2.12.30';
364
+ var version = '2.12.34-beta.0';
365
365
  exports.version = version;
366
366
 
367
367
  function install(Vue) {
@@ -21,7 +21,7 @@ var _default = createComponent({
21
21
  mixins: [(0, _bindEvent.BindEventMixin)(function (bind) {
22
22
  // fix cache issues with forwards and back history in safari
23
23
  // see: https://guwii.com/cache-issues-with-forwards-and-back-history-in-safari/
24
- bind(window, 'pageshow', this.start);
24
+ bind(window, 'pageshow', this.reset);
25
25
  })],
26
26
  inject: {
27
27
  vanPopup: {
@@ -58,24 +58,20 @@ var _default = createComponent({
58
58
  };
59
59
  },
60
60
  watch: {
61
- scrollable: 'start',
61
+ scrollable: 'reset',
62
62
  text: {
63
- handler: 'start',
63
+ handler: 'reset',
64
64
  immediate: true
65
65
  }
66
66
  },
67
67
  created: function created() {
68
- var _this = this;
69
-
70
68
  // https://github.com/youzan/vant/issues/8634
71
69
  if (this.vanPopup) {
72
- this.vanPopup.onReopen(function () {
73
- _this.start();
74
- });
70
+ this.vanPopup.onReopen(this.reset);
75
71
  }
76
72
  },
77
73
  activated: function activated() {
78
- this.start();
74
+ this.reset();
79
75
  },
80
76
  methods: {
81
77
  onClickIcon: function onClickIcon(event) {
@@ -85,7 +81,7 @@ var _default = createComponent({
85
81
  }
86
82
  },
87
83
  onTransitionEnd: function onTransitionEnd() {
88
- var _this2 = this;
84
+ var _this = this;
89
85
 
90
86
  this.offset = this.wrapWidth;
91
87
  this.duration = 0; // wait for Vue to render offset
@@ -94,50 +90,52 @@ var _default = createComponent({
94
90
  (0, _raf.raf)(function () {
95
91
  // use double raf to ensure animation can start
96
92
  (0, _raf.doubleRaf)(function () {
97
- _this2.offset = -_this2.contentWidth;
98
- _this2.duration = (_this2.contentWidth + _this2.wrapWidth) / _this2.speed;
93
+ _this.offset = -_this.contentWidth;
94
+ _this.duration = (_this.contentWidth + _this.wrapWidth) / _this.speed;
99
95
 
100
- _this2.$emit('replay');
96
+ _this.$emit('replay');
101
97
  });
102
98
  });
103
99
  },
100
+ // not an exposed-api, but may used by some users
101
+ start: function start() {
102
+ this.reset();
103
+ },
104
+ // @exposed-api
104
105
  reset: function reset() {
106
+ var _this2 = this;
107
+
108
+ var delay = (0, _utils.isDef)(this.delay) ? this.delay * 1000 : 0;
105
109
  this.offset = 0;
106
110
  this.duration = 0;
107
111
  this.wrapWidth = 0;
108
112
  this.contentWidth = 0;
109
- },
110
- start: function start() {
111
- var _this3 = this;
112
-
113
- var delay = (0, _utils.isDef)(this.delay) ? this.delay * 1000 : 0;
114
- this.reset();
115
113
  clearTimeout(this.startTimer);
116
114
  this.startTimer = setTimeout(function () {
117
- var _this3$$refs = _this3.$refs,
118
- wrap = _this3$$refs.wrap,
119
- content = _this3$$refs.content;
115
+ var _this2$$refs = _this2.$refs,
116
+ wrap = _this2$$refs.wrap,
117
+ content = _this2$$refs.content;
120
118
 
121
- if (!wrap || !content || _this3.scrollable === false) {
119
+ if (!wrap || !content || _this2.scrollable === false) {
122
120
  return;
123
121
  }
124
122
 
125
123
  var wrapWidth = wrap.getBoundingClientRect().width;
126
124
  var contentWidth = content.getBoundingClientRect().width;
127
125
 
128
- if (_this3.scrollable || contentWidth > wrapWidth) {
126
+ if (_this2.scrollable || contentWidth > wrapWidth) {
129
127
  (0, _raf.doubleRaf)(function () {
130
- _this3.offset = -contentWidth;
131
- _this3.duration = contentWidth / _this3.speed;
132
- _this3.wrapWidth = wrapWidth;
133
- _this3.contentWidth = contentWidth;
128
+ _this2.offset = -contentWidth;
129
+ _this2.duration = contentWidth / _this2.speed;
130
+ _this2.wrapWidth = wrapWidth;
131
+ _this2.contentWidth = contentWidth;
134
132
  });
135
133
  }
136
134
  }, delay);
137
135
  }
138
136
  },
139
137
  render: function render() {
140
- var _this4 = this;
138
+ var _this3 = this;
141
139
 
142
140
  var h = arguments[0];
143
141
  var slots = this.slots,
@@ -212,7 +210,7 @@ var _default = createComponent({
212
210
  "style": barStyle,
213
211
  "on": {
214
212
  "click": function click(event) {
215
- _this4.$emit('click', event);
213
+ _this3.$emit('click', event);
216
214
  }
217
215
  }
218
216
  }, [LeftIcon(), h("div", {
@@ -3,7 +3,7 @@
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
4
 
5
5
  exports.__esModule = true;
6
- exports.default = void 0;
6
+ exports.default = exports.MOMENTUM_LIMIT_DISTANCE = exports.MOMENTUM_LIMIT_TIME = void 0;
7
7
 
8
8
  var _babelHelperVueJsxMergeProps = _interopRequireDefault(require("@vue/babel-helper-vue-jsx-merge-props"));
9
9
 
@@ -22,7 +22,9 @@ var DEFAULT_DURATION = 200; // 惯性滑动思路:
22
22
  // 距离大于 `MOMENTUM_LIMIT_DISTANCE` 时,执行惯性滑动
23
23
 
24
24
  var MOMENTUM_LIMIT_TIME = 300;
25
+ exports.MOMENTUM_LIMIT_TIME = MOMENTUM_LIMIT_TIME;
25
26
  var MOMENTUM_LIMIT_DISTANCE = 15;
27
+ exports.MOMENTUM_LIMIT_DISTANCE = MOMENTUM_LIMIT_DISTANCE;
26
28
 
27
29
  var _createNamespace = (0, _utils.createNamespace)('picker-column'),
28
30
  createComponent = _createNamespace[0],
@@ -37,7 +39,12 @@ function getElementTranslateY(element) {
37
39
 
38
40
  function isOptionDisabled(option) {
39
41
  return (0, _utils.isObject)(option) && option.disabled;
40
- }
42
+ } // use standard WheelEvent:
43
+ // https://developer.mozilla.org/en-US/docs/Web/API/WheelEvent
44
+
45
+
46
+ var supportMousewheel = _utils.inBrowser && 'onwheel' in window;
47
+ var mousewheelTimer = null;
41
48
 
42
49
  var _default2 = createComponent({
43
50
  mixins: [_touch.TouchMixin],
@@ -74,6 +81,10 @@ var _default2 = createComponent({
74
81
  },
75
82
  mounted: function mounted() {
76
83
  this.bindTouchEvent(this.$el);
84
+
85
+ if (supportMousewheel) {
86
+ (0, _event.on)(this.$el, 'wheel', this.onMouseWheel, false);
87
+ }
77
88
  },
78
89
  destroyed: function destroyed() {
79
90
  var children = this.$parent.children;
@@ -81,6 +92,10 @@ var _default2 = createComponent({
81
92
  if (children) {
82
93
  children.splice(children.indexOf(this), 1);
83
94
  }
95
+
96
+ if (supportMousewheel) {
97
+ (0, _event.off)(this.$el, 'wheel');
98
+ }
84
99
  },
85
100
  watch: {
86
101
  initialOptions: 'setOptions',
@@ -168,6 +183,43 @@ var _default2 = createComponent({
168
183
  _this.moving = false;
169
184
  }, 0);
170
185
  },
186
+ onMouseWheel: function onMouseWheel(event) {
187
+ var _this2 = this;
188
+
189
+ if (this.readonly) {
190
+ return;
191
+ }
192
+
193
+ (0, _event.preventDefault)(event, true); // simply combine touchstart and touchmove
194
+
195
+ var translateY = getElementTranslateY(this.$refs.wrapper);
196
+ this.startOffset = Math.min(0, translateY - this.baseOffset);
197
+ this.momentumOffset = this.startOffset;
198
+ this.transitionEndTrigger = null; // directly use deltaY, see https://caniuse.com/?search=deltaY
199
+ // use deltaY to detect direction for not special setting device
200
+ // https://developer.mozilla.org/en-US/docs/Web/API/Element/wheel_event
201
+
202
+ var deltaY = event.deltaY;
203
+
204
+ if (this.startOffset === 0 && deltaY < 0) {
205
+ return;
206
+ } // get offset
207
+ // if necessary, can adjust distance value to make scrolling smoother
208
+
209
+
210
+ var distance = -deltaY;
211
+ this.offset = (0, _number.range)(this.startOffset + distance, -(this.count * this.itemHeight), this.itemHeight);
212
+
213
+ if (mousewheelTimer) {
214
+ clearTimeout(mousewheelTimer);
215
+ }
216
+
217
+ mousewheelTimer = setTimeout(function () {
218
+ _this2.onTouchEnd();
219
+
220
+ _this2.touchStartTime = 0;
221
+ }, MOMENTUM_LIMIT_TIME);
222
+ },
171
223
  onTransitionEnd: function onTransitionEnd() {
172
224
  this.stopMomentum();
173
225
  },
@@ -199,17 +251,17 @@ var _default2 = createComponent({
199
251
  return option;
200
252
  },
201
253
  setIndex: function setIndex(index, emitChange) {
202
- var _this2 = this;
254
+ var _this3 = this;
203
255
 
204
256
  index = this.adjustIndex(index) || 0;
205
257
  var offset = -index * this.itemHeight;
206
258
 
207
259
  var trigger = function trigger() {
208
- if (index !== _this2.currentIndex) {
209
- _this2.currentIndex = index;
260
+ if (index !== _this3.currentIndex) {
261
+ _this3.currentIndex = index;
210
262
 
211
263
  if (emitChange) {
212
- _this2.$emit('change', index);
264
+ _this3.$emit('change', index);
213
265
  }
214
266
  }
215
267
  }; // trigger the change event after transitionend when moving
@@ -255,7 +307,7 @@ var _default2 = createComponent({
255
307
  }
256
308
  },
257
309
  genOptions: function genOptions() {
258
- var _this3 = this;
310
+ var _this4 = this;
259
311
 
260
312
  var h = this.$createElement;
261
313
  var optionStyle = {
@@ -264,7 +316,7 @@ var _default2 = createComponent({
264
316
  return this.options.map(function (option, index) {
265
317
  var _domProps;
266
318
 
267
- var text = _this3.getOptionText(option);
319
+ var text = _this4.getOptionText(option);
268
320
 
269
321
  var disabled = isOptionDisabled(option);
270
322
  var data = {
@@ -275,19 +327,19 @@ var _default2 = createComponent({
275
327
  },
276
328
  class: [bem('item', {
277
329
  disabled: disabled,
278
- selected: index === _this3.currentIndex
330
+ selected: index === _this4.currentIndex
279
331
  })],
280
332
  on: {
281
333
  click: function click() {
282
- _this3.onClickItem(index);
334
+ _this4.onClickItem(index);
283
335
  }
284
336
  }
285
337
  };
286
338
  var childData = {
287
339
  class: 'van-ellipsis',
288
- domProps: (_domProps = {}, _domProps[_this3.allowHtml ? 'innerHTML' : 'textContent'] = text, _domProps)
340
+ domProps: (_domProps = {}, _domProps[_this4.allowHtml ? 'innerHTML' : 'textContent'] = text, _domProps)
289
341
  };
290
- return h("li", (0, _babelHelperVueJsxMergeProps.default)([{}, data]), [_this3.slots('option', option) || h("div", (0, _babelHelperVueJsxMergeProps.default)([{}, childData]))]);
342
+ return h("li", (0, _babelHelperVueJsxMergeProps.default)([{}, data]), [_this4.slots('option', option) || h("div", (0, _babelHelperVueJsxMergeProps.default)([{}, childData]))]);
291
343
  });
292
344
  }
293
345
  },
@@ -5,11 +5,17 @@ exports.default = void 0;
5
5
 
6
6
  var _utils = require("../utils");
7
7
 
8
+ var _bindEvent = require("../mixins/bind-event");
9
+
8
10
  var _createNamespace = (0, _utils.createNamespace)('progress'),
9
11
  createComponent = _createNamespace[0],
10
12
  bem = _createNamespace[1];
11
13
 
12
14
  var _default = createComponent({
15
+ mixins: [(0, _bindEvent.BindEventMixin)(function (bind) {
16
+ bind(window, 'resize', this.resize, true);
17
+ bind(window, 'orientationchange', this.resize, true);
18
+ })],
13
19
  props: {
14
20
  color: String,
15
21
  inactive: Boolean,
@@ -193,10 +193,16 @@ var _default = createComponent({
193
193
  },
194
194
  onTouchMove: function onTouchMove(event) {
195
195
  if (!this.touchable || !this.swiping) return;
196
- this.touchMove(event);
196
+ this.touchMove(event); // if user starting to touchmove, prevent the event bubbling to
197
+ // avoid affecting the parent components
197
198
 
198
- if (this.isCorrectDirection) {
199
+ var shouldPrevent = this.isCorrectDirection || this.offsetY > this.offsetX === this.vertical;
200
+
201
+ if (shouldPrevent) {
199
202
  (0, _event.preventDefault)(event, this.stopPropagation);
203
+ }
204
+
205
+ if (this.isCorrectDirection) {
200
206
  this.move({
201
207
  offset: this.delta
202
208
  });
@@ -1 +1 @@
1
- .van-switch{position:relative;display:inline-block;box-sizing:content-box;width:2em;height:1em;font-size:30px;background-color:#fff;border:1px solid rgba(0,0,0,.1);border-radius:1em;cursor:pointer;-webkit-transition:background-color .3s;transition:background-color .3s}.van-switch__node{position:absolute;top:0;left:0;width:1em;height:1em;background-color:#fff;border-radius:100%;box-shadow:0 3px 1px 0 rgba(0,0,0,.05),0 2px 2px 0 rgba(0,0,0,.1),0 3px 3px 0 rgba(0,0,0,.05);-webkit-transition:-webkit-transform .3s cubic-bezier(.3,1.05,.4,1.05);transition:-webkit-transform .3s cubic-bezier(.3,1.05,.4,1.05);transition:transform .3s cubic-bezier(.3,1.05,.4,1.05);transition:transform .3s cubic-bezier(.3,1.05,.4,1.05),-webkit-transform .3s cubic-bezier(.3,1.05,.4,1.05)}.van-switch__loading{top:25%;left:25%;width:50%;height:50%;line-height:1}.van-switch--on{background-color:#1989fa}.van-switch--on .van-switch__node{-webkit-transform:translateX(1em);transform:translateX(1em)}.van-switch--on .van-switch__loading{color:#1989fa}.van-switch--disabled{cursor:not-allowed;opacity:.5}.van-switch--loading{cursor:default}
1
+ .van-switch{position:relative;display:inline-block;box-sizing:content-box;width:2em;height:1em;font-size:30px;background-color:#fff;border:1px solid rgba(0,0,0,.1);border-radius:1em;cursor:pointer;-webkit-transition:background-color .3s;transition:background-color .3s}.van-switch__node{position:absolute;top:0;left:0;width:1em;height:1em;font-size:inherit;background-color:#fff;border-radius:100%;box-shadow:0 3px 1px 0 rgba(0,0,0,.05),0 2px 2px 0 rgba(0,0,0,.1),0 3px 3px 0 rgba(0,0,0,.05);-webkit-transition:-webkit-transform .3s cubic-bezier(.3,1.05,.4,1.05);transition:-webkit-transform .3s cubic-bezier(.3,1.05,.4,1.05);transition:transform .3s cubic-bezier(.3,1.05,.4,1.05);transition:transform .3s cubic-bezier(.3,1.05,.4,1.05),-webkit-transform .3s cubic-bezier(.3,1.05,.4,1.05)}.van-switch__loading{top:25%;left:25%;width:50%;height:50%;line-height:1}.van-switch--on{background-color:#1989fa}.van-switch--on .van-switch__node{-webkit-transform:translateX(1em);transform:translateX(1em)}.van-switch--on .van-switch__loading{color:#1989fa}.van-switch--disabled{cursor:not-allowed;opacity:.5}.van-switch--loading{cursor:default}
@@ -19,6 +19,8 @@
19
19
  left: 0;
20
20
  width: @switch-node-size;
21
21
  height: @switch-node-size;
22
+ // https://github.com/youzan/vant/issues/9839
23
+ font-size: inherit;
22
24
  background-color: @switch-node-background-color;
23
25
  border-radius: 100%;
24
26
  box-shadow: @switch-node-box-shadow;
@@ -70,23 +70,23 @@ var _default = createComponent({
70
70
  var _this = this;
71
71
 
72
72
  this.children.forEach(function (item, index) {
73
- item.active = (item.name || index) === _this.value;
73
+ item.nameMatched = (item.name || index) === _this.value;
74
74
  });
75
75
  },
76
- onChange: function onChange(active) {
76
+ triggerChange: function triggerChange(active, afterChange) {
77
77
  var _this2 = this;
78
78
 
79
- if (active !== this.value) {
80
- (0, _interceptor.callInterceptor)({
81
- interceptor: this.beforeChange,
82
- args: [active],
83
- done: function done() {
84
- _this2.$emit('input', active);
85
-
86
- _this2.$emit('change', active);
87
- }
88
- });
89
- }
79
+ (0, _interceptor.callInterceptor)({
80
+ interceptor: this.beforeChange,
81
+ args: [active],
82
+ done: function done() {
83
+ _this2.$emit('input', active);
84
+
85
+ _this2.$emit('change', active);
86
+
87
+ afterChange();
88
+ }
89
+ });
90
90
  },
91
91
  genTabbar: function genTabbar() {
92
92
  var _ref;
@@ -37,11 +37,11 @@ var _default = createComponent({
37
37
  }),
38
38
  data: function data() {
39
39
  return {
40
- active: false
40
+ nameMatched: false
41
41
  };
42
42
  },
43
43
  computed: {
44
- routeActive: function routeActive() {
44
+ routeMatched: function routeMatched() {
45
45
  var to = this.to,
46
46
  $route = this.$route;
47
47
 
@@ -49,22 +49,33 @@ var _default = createComponent({
49
49
  var config = (0, _utils.isObject)(to) ? to : {
50
50
  path: to
51
51
  };
52
- var pathMatched = config.path === $route.path;
53
- var nameMatched = (0, _utils.isDef)(config.name) && config.name === $route.name;
54
- return pathMatched || nameMatched;
52
+ return !!$route.matched.find(function (r) {
53
+ var pathMatched = config.path === r.path;
54
+ var nameMatched = (0, _utils.isDef)(config.name) && config.name === r.name;
55
+ return pathMatched || nameMatched;
56
+ });
55
57
  }
58
+ },
59
+ active: function active() {
60
+ return this.parent.route ? this.routeMatched : this.nameMatched;
56
61
  }
57
62
  },
58
63
  methods: {
59
64
  onClick: function onClick(event) {
60
- this.parent.onChange(this.name || this.index);
65
+ var _this = this;
66
+
67
+ if (!this.active) {
68
+ this.parent.triggerChange(this.name || this.index, function () {
69
+ (0, _router.route)(_this.$router, _this);
70
+ });
71
+ }
72
+
61
73
  this.$emit('click', event);
62
- (0, _router.route)(this.$router, this);
63
74
  },
64
- genIcon: function genIcon(active) {
75
+ genIcon: function genIcon() {
65
76
  var h = this.$createElement;
66
77
  var slot = this.slots('icon', {
67
- active: active
78
+ active: this.active
68
79
  });
69
80
 
70
81
  if (slot) {
@@ -85,7 +96,7 @@ var _default = createComponent({
85
96
  var _this$badge;
86
97
 
87
98
  var h = arguments[0];
88
- var active = this.parent.route ? this.routeActive : this.active;
99
+ var active = this.active;
89
100
  var color = this.parent[active ? 'activeColor' : 'inactiveColor'];
90
101
 
91
102
  if (process.env.NODE_ENV === 'development' && this.info) {
@@ -104,7 +115,7 @@ var _default = createComponent({
104
115
  }
105
116
  }, [h("div", {
106
117
  "class": bem('icon')
107
- }, [this.genIcon(active), h(_info.default, {
118
+ }, [this.genIcon(), h(_info.default, {
108
119
  "attrs": {
109
120
  "dot": this.dot,
110
121
  "info": (_this$badge = this.badge) != null ? _this$badge : this.info