vant 4.0.1 → 4.0.3

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
@@ -795,6 +795,7 @@
795
795
  }
796
796
  });
797
797
  onPopupReopen(() => vue.nextTick(setHeight));
798
+ vue.watch([windowWidth, windowHeight], setHeight);
798
799
  return height2;
799
800
  };
800
801
  function usePlaceholder(contentRef, bem2) {
@@ -3836,11 +3837,16 @@
3836
3837
  }
3837
3838
  };
3838
3839
  const renderTitle = () => {
3840
+ var _a;
3839
3841
  if (slots.title || isDef(props.title)) {
3842
+ const titleSlot = (_a = slots.title) == null ? void 0 : _a.call(slots);
3843
+ if (Array.isArray(titleSlot) && titleSlot.length === 0) {
3844
+ return;
3845
+ }
3840
3846
  return vue.createVNode("div", {
3841
3847
  "class": [bem$1a("title"), props.titleClass],
3842
3848
  "style": props.titleStyle
3843
- }, [slots.title ? slots.title() : vue.createVNode("span", null, [props.title]), renderLabel()]);
3849
+ }, [titleSlot || vue.createVNode("span", null, [props.title]), renderLabel()]);
3844
3850
  }
3845
3851
  };
3846
3852
  const renderValue = () => {
@@ -4334,7 +4340,9 @@
4334
4340
  return value;
4335
4341
  };
4336
4342
  const updateValue = (value, trigger = "onChange") => {
4343
+ const originalValue = value;
4337
4344
  value = limitValueLength(value);
4345
+ const isExceedLimit = value !== originalValue;
4338
4346
  if (props.type === "number" || props.type === "digit") {
4339
4347
  const isNumber = props.type === "number";
4340
4348
  value = formatNumber(value, isNumber, isNumber);
@@ -4343,13 +4351,15 @@
4343
4351
  value = props.formatter(value);
4344
4352
  }
4345
4353
  if (inputRef.value && inputRef.value.value !== value) {
4346
- const {
4347
- selectionStart,
4348
- selectionEnd
4349
- } = inputRef.value;
4350
- inputRef.value.value = value;
4351
- if (state.focused) {
4352
- inputRef.value.setSelectionRange(selectionStart, selectionEnd);
4354
+ if (state.focused && isExceedLimit) {
4355
+ const {
4356
+ selectionStart,
4357
+ selectionEnd
4358
+ } = inputRef.value;
4359
+ inputRef.value.value = value;
4360
+ inputRef.value.setSelectionRange(selectionStart - 1, selectionEnd - 1);
4361
+ } else {
4362
+ inputRef.value.value = value;
4353
4363
  }
4354
4364
  }
4355
4365
  if (value !== props.modelValue) {
@@ -4574,9 +4584,14 @@
4574
4584
  return () => {
4575
4585
  const disabled = getProp("disabled");
4576
4586
  const labelAlign = getProp("labelAlign");
4577
- const Label = renderLabel();
4578
4587
  const LeftIcon = renderLeftIcon();
4579
- const renderTitle = () => labelAlign === "top" ? [LeftIcon, Label] : Label;
4588
+ const renderTitle = () => {
4589
+ const Label = renderLabel();
4590
+ if (labelAlign === "top") {
4591
+ return [LeftIcon, Label].filter(Boolean);
4592
+ }
4593
+ return Label || [];
4594
+ };
4580
4595
  return vue.createVNode(Cell, {
4581
4596
  "size": props.size,
4582
4597
  "class": bem$18({
@@ -4596,7 +4611,7 @@
4596
4611
  "arrowDirection": props.arrowDirection
4597
4612
  }, {
4598
4613
  icon: LeftIcon && labelAlign !== "top" ? () => LeftIcon : null,
4599
- title: Label || labelAlign === "top" ? renderTitle : null,
4614
+ title: renderTitle,
4600
4615
  value: renderFieldBody,
4601
4616
  extra: slots.extra
4602
4617
  });
@@ -6857,8 +6872,10 @@
6857
6872
  loading.value = true;
6858
6873
  });
6859
6874
  const onLoad = (event) => {
6860
- loading.value = false;
6861
- emit("load", event);
6875
+ if (loading.value) {
6876
+ loading.value = false;
6877
+ emit("load", event);
6878
+ }
6862
6879
  };
6863
6880
  const onError = (event) => {
6864
6881
  error.value = true;
@@ -6906,6 +6923,7 @@
6906
6923
  }, attrs), null), [[vue.resolveDirective("lazy"), props.src]]);
6907
6924
  }
6908
6925
  return vue.createVNode("img", vue.mergeProps({
6926
+ "ref": imageRef,
6909
6927
  "src": props.src,
6910
6928
  "onLoad": onLoad,
6911
6929
  "onError": onError
@@ -6940,6 +6958,14 @@
6940
6958
  $Lazyload.$off("error", onLazyLoadError);
6941
6959
  });
6942
6960
  }
6961
+ vue.onMounted(() => {
6962
+ vue.nextTick(() => {
6963
+ var _a;
6964
+ if ((_a = imageRef.value) == null ? void 0 : _a.complete) {
6965
+ onLoad();
6966
+ }
6967
+ });
6968
+ });
6943
6969
  return () => {
6944
6970
  var _a;
6945
6971
  return vue.createVNode("div", {
@@ -16027,7 +16053,7 @@
16027
16053
  });
16028
16054
  }
16029
16055
  };
16030
- const version = "4.0.1";
16056
+ const version = "4.0.3";
16031
16057
  function install(app) {
16032
16058
  const components = [
16033
16059
  ActionBar,