vant 3.2.7 → 3.3.2

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 (191) hide show
  1. package/es/address-edit/AddressEdit.js +154 -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/Calendar.js +8 -14
  6. package/es/calendar/CalendarHeader.js +1 -3
  7. package/es/calendar/CalendarMonth.js +11 -10
  8. package/es/calendar/types.d.ts +1 -1
  9. package/es/cascader/Cascader.js +17 -5
  10. package/es/checkbox/Checker.js +1 -1
  11. package/es/checkbox/types.d.ts +2 -6
  12. package/es/composables/use-id.d.ts +1 -0
  13. package/es/composables/use-id.js +14 -0
  14. package/es/composables/use-route.d.ts +1 -1
  15. package/es/composables/use-route.js +4 -4
  16. package/es/count-down/CountDown.js +1 -0
  17. package/es/coupon-list/CouponList.js +40 -24
  18. package/es/coupon-list/index.css +1 -1
  19. package/es/coupon-list/index.less +0 -5
  20. package/es/dropdown-item/DropdownItem.js +7 -2
  21. package/es/dropdown-item/types.d.ts +2 -6
  22. package/es/dropdown-menu/DropdownMenu.js +7 -3
  23. package/es/dropdown-menu/types.d.ts +1 -0
  24. package/es/empty/Network.js +22 -34
  25. package/es/field/Field.d.ts +1 -1
  26. package/es/field/Field.js +13 -5
  27. package/es/field/index.d.ts +2 -2
  28. package/es/field/types.d.ts +7 -6
  29. package/es/form/Form.js +2 -2
  30. package/es/image/Image.js +4 -9
  31. package/es/image-preview/ImagePreview.js +3 -4
  32. package/es/index.d.ts +1 -1
  33. package/es/index.js +1 -1
  34. package/es/lazyload/index.d.ts +1 -1
  35. package/es/lazyload/index.js +1 -1
  36. package/es/lazyload/vue-lazyload/index.d.ts +55 -0
  37. package/es/lazyload/vue-lazyload/index.js +46 -0
  38. package/es/lazyload/vue-lazyload/lazy-component.js +53 -0
  39. package/es/lazyload/vue-lazyload/lazy-container.js +98 -0
  40. package/es/lazyload/vue-lazyload/lazy-image.js +115 -0
  41. package/es/lazyload/vue-lazyload/lazy.js +507 -0
  42. package/es/lazyload/vue-lazyload/listener.js +241 -0
  43. package/es/lazyload/vue-lazyload/util.js +183 -0
  44. package/es/list/List.js +3 -1
  45. package/es/nav-bar/NavBar.d.ts +1 -1
  46. package/es/nav-bar/index.d.ts +1 -1
  47. package/es/number-keyboard/NumberKeyboardKey.js +4 -4
  48. package/es/pagination/Pagination.js +67 -49
  49. package/es/pagination/index.css +1 -1
  50. package/es/pagination/index.less +32 -31
  51. package/es/password-input/PasswordInput.d.ts +21 -1
  52. package/es/password-input/PasswordInput.js +10 -9
  53. package/es/password-input/index.d.ts +2 -1
  54. package/es/popover/Popover.js +2 -0
  55. package/es/popup/Popup.d.ts +1 -2
  56. package/es/popup/Popup.js +2 -5
  57. package/es/popup/index.d.ts +1 -2
  58. package/es/progress/Progress.js +2 -2
  59. package/es/rate/Rate.js +5 -3
  60. package/es/search/Search.js +8 -2
  61. package/es/sidebar/Sidebar.js +1 -0
  62. package/es/sidebar-item/SidebarItem.js +4 -1
  63. package/es/slider/Slider.js +5 -3
  64. package/es/stepper/Stepper.js +11 -8
  65. package/es/submit-bar/SubmitBar.d.ts +4 -3
  66. package/es/submit-bar/index.d.ts +3 -2
  67. package/es/swipe/Swipe.js +11 -6
  68. package/es/swipe/types.d.ts +1 -3
  69. package/es/switch/Switch.js +1 -0
  70. package/es/switch/index.css +1 -1
  71. package/es/switch/index.less +2 -0
  72. package/es/tab/Tab.js +18 -5
  73. package/es/tab/index.css +1 -1
  74. package/es/tab/index.less +1 -1
  75. package/es/tabbar/Tabbar.d.ts +1 -1
  76. package/es/tabbar/Tabbar.js +10 -10
  77. package/es/tabbar-item/TabbarItem.js +16 -7
  78. package/es/tabs/Tabs.js +17 -11
  79. package/es/tabs/TabsTitle.d.ts +6 -0
  80. package/es/tabs/TabsTitle.js +7 -1
  81. package/es/tabs/types.d.ts +1 -0
  82. package/es/uploader/UploaderPreviewItem.js +4 -1
  83. package/es/uploader/utils.d.ts +2 -2
  84. package/es/uploader/utils.js +2 -2
  85. package/es/utils/dom.d.ts +1 -0
  86. package/es/utils/dom.js +6 -2
  87. package/es/utils/format.js +6 -5
  88. package/es/vue-tsx-shim.d.ts +1 -0
  89. package/lib/address-edit/AddressEdit.js +155 -180
  90. package/lib/address-edit/AddressEditDetail.d.ts +10 -9
  91. package/lib/address-edit/AddressEditDetail.js +6 -6
  92. package/lib/button/Button.js +1 -1
  93. package/lib/calendar/Calendar.js +8 -14
  94. package/lib/calendar/CalendarHeader.js +1 -3
  95. package/lib/calendar/CalendarMonth.js +11 -10
  96. package/lib/calendar/types.d.ts +1 -1
  97. package/lib/cascader/Cascader.js +17 -5
  98. package/lib/checkbox/Checker.js +1 -1
  99. package/lib/checkbox/types.d.ts +2 -6
  100. package/lib/composables/use-id.d.ts +1 -0
  101. package/lib/composables/use-id.js +21 -0
  102. package/lib/composables/use-route.d.ts +1 -1
  103. package/lib/composables/use-route.js +4 -4
  104. package/lib/count-down/CountDown.js +1 -0
  105. package/lib/coupon-list/CouponList.js +39 -22
  106. package/lib/coupon-list/index.css +1 -1
  107. package/lib/coupon-list/index.less +0 -5
  108. package/lib/dropdown-item/DropdownItem.js +7 -2
  109. package/lib/dropdown-item/types.d.ts +2 -6
  110. package/lib/dropdown-menu/DropdownMenu.js +7 -2
  111. package/lib/dropdown-menu/types.d.ts +1 -0
  112. package/lib/empty/Network.js +22 -34
  113. package/lib/field/Field.d.ts +1 -1
  114. package/lib/field/Field.js +14 -5
  115. package/lib/field/index.d.ts +2 -2
  116. package/lib/field/types.d.ts +7 -6
  117. package/lib/form/Form.js +1 -1
  118. package/lib/image/Image.js +4 -9
  119. package/lib/image-preview/ImagePreview.js +1 -2
  120. package/lib/index.css +1 -1
  121. package/lib/index.d.ts +1 -1
  122. package/lib/index.js +1 -1
  123. package/lib/lazyload/index.d.ts +1 -1
  124. package/lib/lazyload/index.js +3 -3
  125. package/lib/lazyload/vue-lazyload/index.d.ts +55 -0
  126. package/lib/lazyload/vue-lazyload/index.js +58 -0
  127. package/lib/lazyload/vue-lazyload/lazy-component.js +62 -0
  128. package/lib/lazyload/vue-lazyload/lazy-container.js +106 -0
  129. package/lib/lazyload/vue-lazyload/lazy-image.js +125 -0
  130. package/lib/lazyload/vue-lazyload/lazy.js +520 -0
  131. package/lib/lazyload/vue-lazyload/listener.js +251 -0
  132. package/lib/lazyload/vue-lazyload/util.js +213 -0
  133. package/lib/list/List.js +3 -1
  134. package/lib/nav-bar/NavBar.d.ts +1 -1
  135. package/lib/nav-bar/index.d.ts +1 -1
  136. package/lib/number-keyboard/NumberKeyboardKey.js +3 -3
  137. package/lib/pagination/Pagination.js +65 -47
  138. package/lib/pagination/index.css +1 -1
  139. package/lib/pagination/index.less +32 -31
  140. package/lib/password-input/PasswordInput.d.ts +21 -1
  141. package/lib/password-input/PasswordInput.js +10 -9
  142. package/lib/password-input/index.d.ts +2 -1
  143. package/lib/popover/Popover.js +2 -0
  144. package/lib/popup/Popup.d.ts +1 -2
  145. package/lib/popup/Popup.js +2 -5
  146. package/lib/popup/index.d.ts +1 -2
  147. package/lib/progress/Progress.js +2 -2
  148. package/lib/rate/Rate.js +5 -3
  149. package/lib/search/Search.js +9 -2
  150. package/lib/sidebar/Sidebar.js +1 -0
  151. package/lib/sidebar-item/SidebarItem.js +4 -1
  152. package/lib/slider/Slider.js +5 -3
  153. package/lib/stepper/Stepper.js +11 -8
  154. package/lib/submit-bar/SubmitBar.d.ts +4 -3
  155. package/lib/submit-bar/index.d.ts +3 -2
  156. package/lib/swipe/Swipe.js +9 -4
  157. package/lib/swipe/types.d.ts +1 -3
  158. package/lib/switch/Switch.js +1 -0
  159. package/lib/switch/index.css +1 -1
  160. package/lib/switch/index.less +2 -0
  161. package/lib/tab/Tab.js +20 -5
  162. package/lib/tab/index.css +1 -1
  163. package/lib/tab/index.less +1 -1
  164. package/lib/tabbar/Tabbar.d.ts +1 -1
  165. package/lib/tabbar/Tabbar.js +10 -10
  166. package/lib/tabbar-item/TabbarItem.js +16 -7
  167. package/lib/tabs/Tabs.js +16 -9
  168. package/lib/tabs/TabsTitle.d.ts +6 -0
  169. package/lib/tabs/TabsTitle.js +7 -1
  170. package/lib/tabs/types.d.ts +1 -0
  171. package/lib/uploader/UploaderPreviewItem.js +3 -0
  172. package/lib/uploader/utils.d.ts +2 -2
  173. package/lib/uploader/utils.js +3 -2
  174. package/lib/utils/dom.d.ts +1 -0
  175. package/lib/utils/dom.js +9 -2
  176. package/lib/utils/format.js +7 -5
  177. package/lib/vant.cjs.js +14407 -0
  178. package/lib/vant.cjs.min.js +1 -0
  179. package/lib/vant.es.js +1217 -2203
  180. package/lib/vant.es.min.js +1217 -2203
  181. package/lib/vant.js +1349 -1254
  182. package/lib/vant.min.js +1 -1
  183. package/lib/vue-tsx-shim.d.ts +1 -0
  184. package/package.json +27 -13
  185. package/vetur/attributes.json +115 -115
  186. package/vetur/tags.json +35 -35
  187. package/vetur/web-types.json +370 -366
  188. package/es/composables/use-link-field.d.ts +0 -0
  189. package/es/composables/use-link-field.js +0 -0
  190. package/lib/composables/use-link-field.d.ts +0 -0
  191. package/lib/composables/use-link-field.js +0 -1
@@ -13,13 +13,16 @@ export declare type FieldValidateError = {
13
13
  name?: string;
14
14
  message: string;
15
15
  };
16
+ export declare type FieldRuleMessage = string | ((value: any, rule: FieldRule) => string);
17
+ export declare type FieldRuleValidator = (value: any, rule: FieldRule) => boolean | string | Promise<boolean | string>;
18
+ export declare type FiledRuleFormatter = (value: any, rule: FieldRule) => string;
16
19
  export declare type FieldRule = {
17
20
  pattern?: RegExp;
18
21
  trigger?: FieldValidateTrigger;
19
- message?: string | ((value: any, rule: FieldRule) => string);
22
+ message?: FieldRuleMessage;
20
23
  required?: boolean;
21
- validator?: (value: any, rule: FieldRule) => boolean | string | Promise<boolean | string>;
22
- formatter?: (value: any, rule: FieldRule) => string;
24
+ validator?: FieldRuleValidator;
25
+ formatter?: FiledRuleFormatter;
23
26
  };
24
27
  export declare type FieldFormSharedProps = 'colon' | 'disabled' | 'readonly' | 'labelWidth' | 'labelAlign' | 'inputAlign' | 'errorMessageAlign';
25
28
  export declare type FieldExpose = {
@@ -27,9 +30,7 @@ export declare type FieldExpose = {
27
30
  focus: () => void | undefined;
28
31
  validate: (rules?: FieldRule[] | undefined) => Promise<void | FieldValidateError>;
29
32
  resetValidation: () => void;
30
- /**
31
- * @private
32
- */
33
+ /** @private */
33
34
  formValue: ComputedRef<unknown>;
34
35
  };
35
36
  export declare type FieldInstance = ComponentPublicInstance<FieldProps, FieldExpose>;
package/es/form/Form.js CHANGED
@@ -1,7 +1,7 @@
1
1
  import { createVNode as _createVNode } from "vue";
2
2
  import { defineComponent } from 'vue'; // Utils
3
3
 
4
- import { FORM_KEY, truthProp, numericProp, makeStringProp, createNamespace } from '../utils'; // Composables
4
+ import { FORM_KEY, truthProp, numericProp, preventDefault, makeStringProp, createNamespace } from '../utils'; // Composables
5
5
 
6
6
  import { useChildren } from '@vant/use';
7
7
  import { useExpose } from '../composables/use-expose'; // Types
@@ -146,7 +146,7 @@ export default defineComponent({
146
146
  };
147
147
 
148
148
  var onSubmit = event => {
149
- event.preventDefault();
149
+ preventDefault(event);
150
150
  submit();
151
151
  };
152
152
 
package/es/image/Image.js CHANGED
@@ -38,15 +38,10 @@ export default defineComponent({
38
38
  $Lazyload
39
39
  } = getCurrentInstance().proxy;
40
40
  var style = computed(() => {
41
- var style = {};
42
-
43
- if (isDef(props.width)) {
44
- style.width = addUnit(props.width);
45
- }
46
-
47
- if (isDef(props.height)) {
48
- style.height = addUnit(props.height);
49
- }
41
+ var style = {
42
+ width: addUnit(props.width),
43
+ height: addUnit(props.height)
44
+ };
50
45
 
51
46
  if (isDef(props.radius)) {
52
47
  style.overflow = 'hidden';
@@ -1,9 +1,9 @@
1
1
  import { mergeProps as _mergeProps, createVNode as _createVNode } from "vue";
2
2
  import { ref, watch, nextTick, reactive, onMounted, defineComponent } from 'vue'; // Utils
3
3
 
4
- import { pick, truthProp, unknownProp, makeArrayProp, makeStringProp, makeNumericProp, callInterceptor, createNamespace, HAPTICS_FEEDBACK } from '../utils'; // Composables
4
+ import { pick, truthProp, unknownProp, windowWidth, windowHeight, makeArrayProp, makeStringProp, makeNumericProp, callInterceptor, createNamespace, HAPTICS_FEEDBACK } from '../utils'; // Composables
5
5
 
6
- import { useRect, useWindowSize } from '@vant/use';
6
+ import { useRect } from '@vant/use';
7
7
  import { useExpose } from '../composables/use-expose'; // Components
8
8
 
9
9
  import { Icon } from '../icon';
@@ -44,7 +44,6 @@ export default defineComponent({
44
44
  slots
45
45
  } = _ref;
46
46
  var swipeRef = ref();
47
- var windowSize = useWindowSize();
48
47
  var state = reactive({
49
48
  active: 0,
50
49
  rootWidth: 0,
@@ -143,7 +142,7 @@ export default defineComponent({
143
142
  swipeTo
144
143
  });
145
144
  onMounted(resize);
146
- watch([windowSize.width, windowSize.height], resize);
145
+ watch([windowWidth, windowHeight], resize);
147
146
  watch(() => props.startPosition, value => setActive(+value));
148
147
  watch(() => props.show, value => {
149
148
  var {
package/es/index.d.ts CHANGED
@@ -90,4 +90,4 @@ declare namespace _default {
90
90
  }
91
91
  export default _default;
92
92
  export function install(app: any): void;
93
- export const version: "3.2.7";
93
+ export const version: "3.3.2";
package/es/index.js CHANGED
@@ -84,7 +84,7 @@ import { Tag } from './tag';
84
84
  import { Toast } from './toast';
85
85
  import { TreeSelect } from './tree-select';
86
86
  import { Uploader } from './uploader';
87
- var version = '3.2.7';
87
+ var version = '3.3.2';
88
88
 
89
89
  function install(app) {
90
90
  var components = [ActionBar, ActionBarButton, ActionBarIcon, ActionSheet, AddressEdit, AddressList, Area, Badge, Button, Calendar, Card, Cascader, Cell, CellGroup, Checkbox, CheckboxGroup, Circle, Col, Collapse, CollapseItem, ConfigProvider, ContactCard, ContactEdit, ContactList, CountDown, Coupon, CouponCell, CouponList, DatetimePicker, Dialog, Divider, DropdownItem, DropdownMenu, Empty, Field, Form, Grid, GridItem, Icon, Image, ImagePreview, IndexAnchor, IndexBar, List, Loading, Locale, NavBar, NoticeBar, Notify, NumberKeyboard, Overlay, Pagination, PasswordInput, Picker, Popover, Popup, Progress, PullRefresh, Radio, RadioGroup, Rate, Row, Search, ShareSheet, Sidebar, SidebarItem, Skeleton, Slider, Step, Stepper, Steps, Sticky, SubmitBar, Swipe, SwipeCell, SwipeItem, Switch, Tab, Tabbar, TabbarItem, Tabs, Tag, Toast, TreeSelect, Uploader];
@@ -1,3 +1,3 @@
1
- import { Lazyload } from '@vant/lazyload';
1
+ import { Lazyload } from './vue-lazyload';
2
2
  export default Lazyload;
3
3
  export { Lazyload };
@@ -1,3 +1,3 @@
1
- import { Lazyload } from '@vant/lazyload';
1
+ import { Lazyload } from './vue-lazyload';
2
2
  export default Lazyload;
3
3
  export { Lazyload };
@@ -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
+ }));