vant 3.2.8 → 3.3.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.
Files changed (171) hide show
  1. package/es/address-edit/AddressEdit.js +155 -180
  2. package/es/address-edit/AddressEditDetail.d.ts +10 -9
  3. package/es/address-edit/AddressEditDetail.js +6 -6
  4. package/es/button/Button.js +2 -2
  5. package/es/calendar/CalendarHeader.js +1 -3
  6. package/es/cascader/Cascader.js +10 -2
  7. package/es/checkbox/Checker.js +1 -1
  8. package/es/checkbox/types.d.ts +2 -6
  9. package/es/composables/use-id.d.ts +1 -0
  10. package/es/composables/use-id.js +14 -0
  11. package/es/composables/use-route.d.ts +1 -1
  12. package/es/composables/use-route.js +4 -4
  13. package/es/count-down/CountDown.js +1 -0
  14. package/es/coupon-list/CouponList.js +40 -24
  15. package/es/coupon-list/index.css +1 -1
  16. package/es/coupon-list/index.less +0 -5
  17. package/es/dropdown-item/DropdownItem.js +7 -2
  18. package/es/dropdown-item/types.d.ts +2 -6
  19. package/es/dropdown-menu/DropdownMenu.js +7 -3
  20. package/es/dropdown-menu/types.d.ts +1 -0
  21. package/es/empty/Network.js +22 -34
  22. package/es/field/Field.d.ts +1 -1
  23. package/es/field/Field.js +13 -5
  24. package/es/field/index.d.ts +2 -2
  25. package/es/field/types.d.ts +7 -6
  26. package/es/form/Form.js +2 -2
  27. package/es/image/Image.js +4 -9
  28. package/es/image-preview/ImagePreview.js +3 -4
  29. package/es/index.d.ts +1 -1
  30. package/es/index.js +1 -1
  31. package/es/lazyload/index.d.ts +1 -1
  32. package/es/lazyload/index.js +1 -1
  33. package/es/lazyload/vue-lazyload/index.d.ts +55 -0
  34. package/es/lazyload/vue-lazyload/index.js +46 -0
  35. package/es/lazyload/vue-lazyload/lazy-component.js +53 -0
  36. package/es/lazyload/vue-lazyload/lazy-container.js +98 -0
  37. package/es/lazyload/vue-lazyload/lazy-image.js +115 -0
  38. package/es/lazyload/vue-lazyload/lazy.js +507 -0
  39. package/es/lazyload/vue-lazyload/listener.js +241 -0
  40. package/es/lazyload/vue-lazyload/util.js +183 -0
  41. package/es/list/List.js +3 -1
  42. package/es/number-keyboard/NumberKeyboardKey.js +4 -4
  43. package/es/pagination/Pagination.js +67 -49
  44. package/es/pagination/index.css +1 -1
  45. package/es/pagination/index.less +32 -31
  46. package/es/password-input/PasswordInput.d.ts +1 -1
  47. package/es/password-input/index.d.ts +1 -1
  48. package/es/popover/Popover.js +2 -0
  49. package/es/popup/Popup.d.ts +1 -2
  50. package/es/popup/Popup.js +2 -5
  51. package/es/popup/index.d.ts +1 -2
  52. package/es/rate/Rate.js +5 -3
  53. package/es/search/Search.js +8 -2
  54. package/es/sidebar/Sidebar.js +1 -0
  55. package/es/sidebar-item/SidebarItem.js +4 -1
  56. package/es/slider/Slider.js +5 -3
  57. package/es/stepper/Stepper.js +11 -8
  58. package/es/swipe/Swipe.js +3 -4
  59. package/es/swipe/types.d.ts +1 -3
  60. package/es/switch/Switch.js +1 -0
  61. package/es/switch/index.css +1 -1
  62. package/es/switch/index.less +2 -0
  63. package/es/tab/Tab.js +17 -4
  64. package/es/tab/index.css +1 -1
  65. package/es/tab/index.less +1 -1
  66. package/es/tabbar/Tabbar.d.ts +1 -1
  67. package/es/tabbar/Tabbar.js +10 -10
  68. package/es/tabbar-item/TabbarItem.js +11 -4
  69. package/es/tabs/Tabs.js +10 -5
  70. package/es/tabs/TabsTitle.d.ts +6 -0
  71. package/es/tabs/TabsTitle.js +7 -1
  72. package/es/tabs/types.d.ts +1 -0
  73. package/es/uploader/UploaderPreviewItem.js +4 -1
  74. package/es/uploader/utils.d.ts +2 -2
  75. package/es/uploader/utils.js +2 -2
  76. package/es/utils/dom.d.ts +1 -0
  77. package/es/utils/dom.js +6 -2
  78. package/es/utils/format.js +6 -5
  79. package/es/vue-tsx-shim.d.ts +1 -0
  80. package/lib/address-edit/AddressEdit.js +156 -180
  81. package/lib/address-edit/AddressEditDetail.d.ts +10 -9
  82. package/lib/address-edit/AddressEditDetail.js +6 -6
  83. package/lib/button/Button.js +1 -1
  84. package/lib/calendar/CalendarHeader.js +1 -3
  85. package/lib/cascader/Cascader.js +10 -2
  86. package/lib/checkbox/Checker.js +1 -1
  87. package/lib/checkbox/types.d.ts +2 -6
  88. package/lib/composables/use-id.d.ts +1 -0
  89. package/lib/composables/use-id.js +21 -0
  90. package/lib/composables/use-route.d.ts +1 -1
  91. package/lib/composables/use-route.js +4 -4
  92. package/lib/count-down/CountDown.js +1 -0
  93. package/lib/coupon-list/CouponList.js +39 -22
  94. package/lib/coupon-list/index.css +1 -1
  95. package/lib/coupon-list/index.less +0 -5
  96. package/lib/dropdown-item/DropdownItem.js +7 -2
  97. package/lib/dropdown-item/types.d.ts +2 -6
  98. package/lib/dropdown-menu/DropdownMenu.js +7 -2
  99. package/lib/dropdown-menu/types.d.ts +1 -0
  100. package/lib/empty/Network.js +22 -34
  101. package/lib/field/Field.d.ts +1 -1
  102. package/lib/field/Field.js +14 -5
  103. package/lib/field/index.d.ts +2 -2
  104. package/lib/field/types.d.ts +7 -6
  105. package/lib/form/Form.js +1 -1
  106. package/lib/image/Image.js +4 -9
  107. package/lib/image-preview/ImagePreview.js +1 -2
  108. package/lib/index.css +1 -1
  109. package/lib/index.d.ts +1 -1
  110. package/lib/index.js +1 -1
  111. package/lib/lazyload/index.d.ts +1 -1
  112. package/lib/lazyload/index.js +3 -3
  113. package/lib/lazyload/vue-lazyload/index.d.ts +55 -0
  114. package/lib/lazyload/vue-lazyload/index.js +58 -0
  115. package/lib/lazyload/vue-lazyload/lazy-component.js +62 -0
  116. package/lib/lazyload/vue-lazyload/lazy-container.js +106 -0
  117. package/lib/lazyload/vue-lazyload/lazy-image.js +125 -0
  118. package/lib/lazyload/vue-lazyload/lazy.js +520 -0
  119. package/lib/lazyload/vue-lazyload/listener.js +251 -0
  120. package/lib/lazyload/vue-lazyload/util.js +213 -0
  121. package/lib/list/List.js +3 -1
  122. package/lib/number-keyboard/NumberKeyboardKey.js +3 -3
  123. package/lib/pagination/Pagination.js +65 -47
  124. package/lib/pagination/index.css +1 -1
  125. package/lib/pagination/index.less +32 -31
  126. package/lib/password-input/PasswordInput.d.ts +1 -1
  127. package/lib/password-input/index.d.ts +1 -1
  128. package/lib/popover/Popover.js +2 -0
  129. package/lib/popup/Popup.d.ts +1 -2
  130. package/lib/popup/Popup.js +2 -5
  131. package/lib/popup/index.d.ts +1 -2
  132. package/lib/rate/Rate.js +5 -3
  133. package/lib/search/Search.js +9 -2
  134. package/lib/sidebar/Sidebar.js +1 -0
  135. package/lib/sidebar-item/SidebarItem.js +4 -1
  136. package/lib/slider/Slider.js +5 -3
  137. package/lib/stepper/Stepper.js +11 -8
  138. package/lib/swipe/Swipe.js +1 -2
  139. package/lib/swipe/types.d.ts +1 -3
  140. package/lib/switch/Switch.js +1 -0
  141. package/lib/switch/index.css +1 -1
  142. package/lib/switch/index.less +2 -0
  143. package/lib/tab/Tab.js +19 -4
  144. package/lib/tab/index.css +1 -1
  145. package/lib/tab/index.less +1 -1
  146. package/lib/tabbar/Tabbar.d.ts +1 -1
  147. package/lib/tabbar/Tabbar.js +10 -10
  148. package/lib/tabbar-item/TabbarItem.js +11 -4
  149. package/lib/tabs/Tabs.js +9 -3
  150. package/lib/tabs/TabsTitle.d.ts +6 -0
  151. package/lib/tabs/TabsTitle.js +7 -1
  152. package/lib/tabs/types.d.ts +1 -0
  153. package/lib/uploader/UploaderPreviewItem.js +3 -0
  154. package/lib/uploader/utils.d.ts +2 -2
  155. package/lib/uploader/utils.js +3 -2
  156. package/lib/utils/dom.d.ts +1 -0
  157. package/lib/utils/dom.js +9 -2
  158. package/lib/utils/format.js +7 -5
  159. package/lib/vant.es.js +1086 -1068
  160. package/lib/vant.es.min.js +1086 -1068
  161. package/lib/vant.js +1085 -1067
  162. package/lib/vant.min.js +1 -1
  163. package/lib/vue-tsx-shim.d.ts +1 -0
  164. package/package.json +4 -4
  165. package/vetur/attributes.json +340 -340
  166. package/vetur/tags.json +119 -119
  167. package/vetur/web-types.json +1143 -1143
  168. package/es/composables/use-link-field.d.ts +0 -0
  169. package/es/composables/use-link-field.js +0 -0
  170. package/lib/composables/use-link-field.d.ts +0 -0
  171. package/lib/composables/use-link-field.js +0 -1
@@ -0,0 +1,55 @@
1
+ import type { App } from 'vue';
2
+
3
+ declare type ListenEvent =
4
+ | 'scroll'
5
+ | 'wheel'
6
+ | 'mousewheel'
7
+ | 'resize'
8
+ | 'animationend'
9
+ | 'transitionend'
10
+ | 'touchmove';
11
+
12
+ // eslint-disable-next-line
13
+ declare type Callback = (listener: any, options: LazyloadOptions) => void;
14
+
15
+ declare type Filter = {
16
+ webp?: Callback;
17
+ progressive?: Callback;
18
+ };
19
+
20
+ declare type Adapter = {
21
+ error?: Callback;
22
+ loaded?: Callback;
23
+ loading?: Callback;
24
+ };
25
+
26
+ export declare type LazyloadOptions = {
27
+ error?: string;
28
+ filter?: Filter;
29
+ silent?: boolean;
30
+ adapter?: Adapter;
31
+ loading?: string;
32
+ attempt?: number;
33
+ preLoad?: number;
34
+ observer?: boolean;
35
+ lazyImage?: boolean;
36
+ throttleWait?: number;
37
+ listenEvents?: ListenEvent[];
38
+ dispatchEvent?: boolean;
39
+ lazyComponent?: boolean;
40
+ observerOptions?: IntersectionObserverInit;
41
+ };
42
+
43
+ export declare const Lazyload: {
44
+ install(app: App, options?: LazyloadOptions): void;
45
+ };
46
+
47
+ declare module '@vue/runtime-core' {
48
+ interface ComponentCustomProperties {
49
+ $Lazyload: {
50
+ $on: (event: string, handler: Callback) => void;
51
+ $off: (event: string, handler?: Callback) => void;
52
+ $once: (event: string, handler: Callback) => void;
53
+ };
54
+ }
55
+ }
@@ -0,0 +1,46 @@
1
+ /**
2
+ * This is a fork of [vue-lazyload](https://github.com/hilongjw/vue-lazyload) with Vue 3 support.
3
+ */
4
+ import Lazy from './lazy';
5
+ import LazyComponent from './lazy-component';
6
+ import LazyContainer from './lazy-container';
7
+ import LazyImage from './lazy-image';
8
+ export var Lazyload = {
9
+ /*
10
+ * install function
11
+ * @param {App} app
12
+ * @param {object} options lazyload options
13
+ */
14
+ install(app, options) {
15
+ if (options === void 0) {
16
+ options = {};
17
+ }
18
+
19
+ var LazyClass = Lazy();
20
+ var lazy = new LazyClass(options);
21
+ var lazyContainer = new LazyContainer({
22
+ lazy
23
+ });
24
+ app.config.globalProperties.$Lazyload = lazy;
25
+
26
+ if (options.lazyComponent) {
27
+ app.component('LazyComponent', LazyComponent(lazy));
28
+ }
29
+
30
+ if (options.lazyImage) {
31
+ app.component('LazyImage', LazyImage(lazy));
32
+ }
33
+
34
+ app.directive('lazy', {
35
+ beforeMount: lazy.add.bind(lazy),
36
+ updated: lazy.update.bind(lazy),
37
+ unmounted: lazy.remove.bind(lazy)
38
+ });
39
+ app.directive('lazy-container', {
40
+ beforeMount: lazyContainer.bind.bind(lazyContainer),
41
+ updated: lazyContainer.update.bind(lazyContainer),
42
+ unmounted: lazyContainer.unbind.bind(lazyContainer)
43
+ });
44
+ }
45
+
46
+ };
@@ -0,0 +1,53 @@
1
+ import { h } from 'vue';
2
+ import { inBrowser, useRect } from '@vant/use';
3
+ export default (lazy => ({
4
+ props: {
5
+ tag: {
6
+ type: String,
7
+ default: 'div'
8
+ }
9
+ },
10
+ emits: ['show'],
11
+
12
+ render() {
13
+ return h(this.tag, this.show && this.$slots.default ? this.$slots.default() : null);
14
+ },
15
+
16
+ data() {
17
+ return {
18
+ el: null,
19
+ state: {
20
+ loaded: false
21
+ },
22
+ show: false
23
+ };
24
+ },
25
+
26
+ mounted() {
27
+ this.el = this.$el;
28
+ lazy.addLazyBox(this);
29
+ lazy.lazyLoadHandler();
30
+ },
31
+
32
+ beforeUnmount() {
33
+ lazy.removeComponent(this);
34
+ },
35
+
36
+ methods: {
37
+ checkInView() {
38
+ var rect = useRect(this.$el);
39
+ return inBrowser && rect.top < window.innerHeight * lazy.options.preLoad && rect.bottom > 0 && rect.left < window.innerWidth * lazy.options.preLoad && rect.right > 0;
40
+ },
41
+
42
+ load() {
43
+ this.show = true;
44
+ this.state.loaded = true;
45
+ this.$emit('show', this);
46
+ },
47
+
48
+ destroy() {
49
+ return this.$destroy;
50
+ }
51
+
52
+ }
53
+ }));
@@ -0,0 +1,98 @@
1
+ /* eslint-disable max-classes-per-file */
2
+
3
+ /* eslint-disable prefer-object-spread */
4
+ import { remove } from './util';
5
+ var defaultOptions = {
6
+ selector: 'img'
7
+ };
8
+
9
+ class LazyContainer {
10
+ constructor(_ref) {
11
+ var {
12
+ el,
13
+ binding,
14
+ vnode,
15
+ lazy
16
+ } = _ref;
17
+ this.el = null;
18
+ this.vnode = vnode;
19
+ this.binding = binding;
20
+ this.options = {};
21
+ this.lazy = lazy;
22
+ this.queue = [];
23
+ this.update({
24
+ el,
25
+ binding
26
+ });
27
+ }
28
+
29
+ update(_ref2) {
30
+ var {
31
+ el,
32
+ binding
33
+ } = _ref2;
34
+ this.el = el;
35
+ this.options = Object.assign({}, defaultOptions, binding.value);
36
+ var imgs = this.getImgs();
37
+ imgs.forEach(el => {
38
+ this.lazy.add(el, Object.assign({}, this.binding, {
39
+ value: {
40
+ src: 'dataset' in el ? el.dataset.src : el.getAttribute('data-src'),
41
+ error: ('dataset' in el ? el.dataset.error : el.getAttribute('data-error')) || this.options.error,
42
+ loading: ('dataset' in el ? el.dataset.loading : el.getAttribute('data-loading')) || this.options.loading
43
+ }
44
+ }), this.vnode);
45
+ });
46
+ }
47
+
48
+ getImgs() {
49
+ return Array.from(this.el.querySelectorAll(this.options.selector));
50
+ }
51
+
52
+ clear() {
53
+ var imgs = this.getImgs();
54
+ imgs.forEach(el => this.lazy.remove(el));
55
+ this.vnode = null;
56
+ this.binding = null;
57
+ this.lazy = null;
58
+ }
59
+
60
+ }
61
+
62
+ export default class LazyContainerManager {
63
+ constructor(_ref3) {
64
+ var {
65
+ lazy
66
+ } = _ref3;
67
+ this.lazy = lazy;
68
+ this.queue = [];
69
+ }
70
+
71
+ bind(el, binding, vnode) {
72
+ var container = new LazyContainer({
73
+ el,
74
+ binding,
75
+ vnode,
76
+ lazy: this.lazy
77
+ });
78
+ this.queue.push(container);
79
+ }
80
+
81
+ update(el, binding, vnode) {
82
+ var container = this.queue.find(item => item.el === el);
83
+ if (!container) return;
84
+ container.update({
85
+ el,
86
+ binding,
87
+ vnode
88
+ });
89
+ }
90
+
91
+ unbind(el) {
92
+ var container = this.queue.find(item => item.el === el);
93
+ if (!container) return;
94
+ container.clear();
95
+ remove(this.queue, container);
96
+ }
97
+
98
+ }
@@ -0,0 +1,115 @@
1
+ import { useRect } from '@vant/use';
2
+ import { loadImageAsync } from './util';
3
+ import { noop } from '../../utils';
4
+ export default (lazyManager => ({
5
+ props: {
6
+ src: [String, Object],
7
+ tag: {
8
+ type: String,
9
+ default: 'img'
10
+ }
11
+ },
12
+
13
+ render(h) {
14
+ return h(this.tag, {
15
+ attrs: {
16
+ src: this.renderSrc
17
+ }
18
+ }, this.$slots.default);
19
+ },
20
+
21
+ data() {
22
+ return {
23
+ el: null,
24
+ options: {
25
+ src: '',
26
+ error: '',
27
+ loading: '',
28
+ attempt: lazyManager.options.attempt
29
+ },
30
+ state: {
31
+ loaded: false,
32
+ error: false,
33
+ attempt: 0
34
+ },
35
+ renderSrc: ''
36
+ };
37
+ },
38
+
39
+ watch: {
40
+ src() {
41
+ this.init();
42
+ lazyManager.addLazyBox(this);
43
+ lazyManager.lazyLoadHandler();
44
+ }
45
+
46
+ },
47
+
48
+ created() {
49
+ this.init();
50
+ this.renderSrc = this.options.loading;
51
+ },
52
+
53
+ mounted() {
54
+ this.el = this.$el;
55
+ lazyManager.addLazyBox(this);
56
+ lazyManager.lazyLoadHandler();
57
+ },
58
+
59
+ beforeUnmount() {
60
+ lazyManager.removeComponent(this);
61
+ },
62
+
63
+ methods: {
64
+ init() {
65
+ var {
66
+ src,
67
+ loading,
68
+ error
69
+ } = lazyManager.valueFormatter(this.src);
70
+ this.state.loaded = false;
71
+ this.options.src = src;
72
+ this.options.error = error;
73
+ this.options.loading = loading;
74
+ this.renderSrc = this.options.loading;
75
+ },
76
+
77
+ checkInView() {
78
+ var rect = useRect(this.$el);
79
+ return rect.top < window.innerHeight * lazyManager.options.preLoad && rect.bottom > 0 && rect.left < window.innerWidth * lazyManager.options.preLoad && rect.right > 0;
80
+ },
81
+
82
+ load(onFinish) {
83
+ if (onFinish === void 0) {
84
+ onFinish = noop;
85
+ }
86
+
87
+ if (this.state.attempt > this.options.attempt - 1 && this.state.error) {
88
+ if (process.env.NODE_ENV !== 'production' && !lazyManager.options.silent) {
89
+ console.log("[@vant/lazyload] " + this.options.src + " tried too more than " + this.options.attempt + " times");
90
+ }
91
+
92
+ onFinish();
93
+ return;
94
+ }
95
+
96
+ var {
97
+ src
98
+ } = this.options;
99
+ loadImageAsync({
100
+ src
101
+ }, _ref => {
102
+ var {
103
+ src
104
+ } = _ref;
105
+ this.renderSrc = src;
106
+ this.state.loaded = true;
107
+ }, () => {
108
+ this.state.attempt++;
109
+ this.renderSrc = this.options.error;
110
+ this.state.error = true;
111
+ });
112
+ }
113
+
114
+ }
115
+ }));