vant 4.0.2 → 4.0.4

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.es.js CHANGED
@@ -3477,11 +3477,16 @@ var stdin_default$1l = defineComponent({
3477
3477
  }
3478
3478
  };
3479
3479
  const renderTitle = () => {
3480
+ var _a;
3480
3481
  if (slots.title || isDef(props.title)) {
3482
+ const titleSlot = (_a = slots.title) == null ? void 0 : _a.call(slots);
3483
+ if (Array.isArray(titleSlot) && titleSlot.length === 0) {
3484
+ return;
3485
+ }
3481
3486
  return createVNode("div", {
3482
3487
  "class": [bem$1a("title"), props.titleClass],
3483
3488
  "style": props.titleStyle
3484
- }, [slots.title ? slots.title() : createVNode("span", null, [props.title]), renderLabel()]);
3489
+ }, [titleSlot || createVNode("span", null, [props.title]), renderLabel()]);
3485
3490
  }
3486
3491
  };
3487
3492
  const renderValue = () => {
@@ -3962,6 +3967,7 @@ var stdin_default$1j = defineComponent({
3962
3967
  }
3963
3968
  };
3964
3969
  const limitValueLength = (value) => {
3970
+ var _a;
3965
3971
  const {
3966
3972
  maxlength
3967
3973
  } = props;
@@ -3970,6 +3976,13 @@ var stdin_default$1j = defineComponent({
3970
3976
  if (modelValue && getStringLength(modelValue) === +maxlength) {
3971
3977
  return modelValue;
3972
3978
  }
3979
+ const selectionEnd = (_a = inputRef.value) == null ? void 0 : _a.selectionEnd;
3980
+ if (state.focused && selectionEnd) {
3981
+ const valueArr = [...value];
3982
+ const exceededLength = valueArr.length - +maxlength;
3983
+ valueArr.splice(selectionEnd - exceededLength, exceededLength);
3984
+ return valueArr.join("");
3985
+ }
3973
3986
  return cutString(value, +maxlength);
3974
3987
  }
3975
3988
  return value;
@@ -3977,22 +3990,47 @@ var stdin_default$1j = defineComponent({
3977
3990
  const updateValue = (value, trigger = "onChange") => {
3978
3991
  const originalValue = value;
3979
3992
  value = limitValueLength(value);
3980
- const isExceedLimit = value !== originalValue;
3993
+ const limitDiffLen = getStringLength(originalValue) - getStringLength(value);
3981
3994
  if (props.type === "number" || props.type === "digit") {
3982
3995
  const isNumber = props.type === "number";
3983
3996
  value = formatNumber(value, isNumber, isNumber);
3984
3997
  }
3998
+ let formatterDiffLen = 0;
3985
3999
  if (props.formatter && trigger === props.formatTrigger) {
3986
- value = props.formatter(value);
4000
+ const {
4001
+ formatter,
4002
+ maxlength
4003
+ } = props;
4004
+ value = formatter(value);
4005
+ if (isDef(maxlength) && getStringLength(value) > maxlength) {
4006
+ value = cutString(value, +maxlength);
4007
+ }
4008
+ if (inputRef.value && state.focused) {
4009
+ const {
4010
+ selectionEnd
4011
+ } = inputRef.value;
4012
+ const bcoVal = cutString(originalValue, selectionEnd);
4013
+ formatterDiffLen = getStringLength(formatter(bcoVal)) - getStringLength(bcoVal);
4014
+ }
3987
4015
  }
3988
4016
  if (inputRef.value && inputRef.value.value !== value) {
3989
- if (state.focused && isExceedLimit) {
3990
- const {
4017
+ if (state.focused) {
4018
+ let {
3991
4019
  selectionStart,
3992
4020
  selectionEnd
3993
4021
  } = inputRef.value;
3994
4022
  inputRef.value.value = value;
3995
- inputRef.value.setSelectionRange(selectionStart - 1, selectionEnd - 1);
4023
+ if (isDef(selectionStart) && isDef(selectionEnd)) {
4024
+ const valueLen = getStringLength(value);
4025
+ if (limitDiffLen) {
4026
+ selectionStart -= limitDiffLen;
4027
+ selectionEnd -= limitDiffLen;
4028
+ } else if (formatterDiffLen) {
4029
+ selectionStart += formatterDiffLen;
4030
+ selectionEnd += formatterDiffLen;
4031
+ }
4032
+ inputRef.value.setSelectionRange(Math.min(selectionStart, valueLen), Math.min(selectionEnd, valueLen));
4033
+ }
3996
4034
  } else {
3997
4035
  inputRef.value.value = value;
3998
4036
  }
@@ -4219,9 +4257,14 @@ var stdin_default$1j = defineComponent({
4219
4257
  return () => {
4220
4258
  const disabled = getProp("disabled");
4221
4259
  const labelAlign = getProp("labelAlign");
4222
- const Label = renderLabel();
4223
4260
  const LeftIcon = renderLeftIcon();
4224
- const renderTitle = () => labelAlign === "top" ? [LeftIcon, Label] : Label;
4261
+ const renderTitle = () => {
4262
+ const Label = renderLabel();
4263
+ if (labelAlign === "top") {
4264
+ return [LeftIcon, Label].filter(Boolean);
4265
+ }
4266
+ return Label || [];
4267
+ };
4225
4268
  return createVNode(Cell, {
4226
4269
  "size": props.size,
4227
4270
  "class": bem$18({
@@ -4241,7 +4284,7 @@ var stdin_default$1j = defineComponent({
4241
4284
  "arrowDirection": props.arrowDirection
4242
4285
  }, {
4243
4286
  icon: LeftIcon && labelAlign !== "top" ? () => LeftIcon : null,
4244
- title: Label || labelAlign === "top" ? renderTitle : null,
4287
+ title: renderTitle,
4245
4288
  value: renderFieldBody,
4246
4289
  extra: slots.extra
4247
4290
  });
@@ -6510,6 +6553,14 @@ var stdin_default$13 = defineComponent({
6510
6553
  emit("load", event);
6511
6554
  }
6512
6555
  };
6556
+ const triggerLoad = () => {
6557
+ const loadEvent = new Event("load");
6558
+ Object.defineProperty(loadEvent, "target", {
6559
+ value: imageRef.value,
6560
+ enumerable: true
6561
+ });
6562
+ onLoad(loadEvent);
6563
+ };
6513
6564
  const onError = (event) => {
6514
6565
  error.value = true;
6515
6566
  loading.value = false;
@@ -6567,7 +6618,7 @@ var stdin_default$13 = defineComponent({
6567
6618
  }) => {
6568
6619
  const check = () => {
6569
6620
  if (el === imageRef.value && loading.value) {
6570
- onLoad();
6621
+ triggerLoad();
6571
6622
  }
6572
6623
  };
6573
6624
  if (imageRef.value) {
@@ -6592,10 +6643,12 @@ var stdin_default$13 = defineComponent({
6592
6643
  });
6593
6644
  }
6594
6645
  onMounted(() => {
6595
- var _a;
6596
- if ((_a = imageRef.value) == null ? void 0 : _a.complete) {
6597
- onLoad();
6598
- }
6646
+ nextTick(() => {
6647
+ var _a;
6648
+ if ((_a = imageRef.value) == null ? void 0 : _a.complete) {
6649
+ triggerLoad();
6650
+ }
6651
+ });
6599
6652
  });
6600
6653
  return () => {
6601
6654
  var _a;
@@ -14833,7 +14886,7 @@ const Lazyload = {
14833
14886
  });
14834
14887
  }
14835
14888
  };
14836
- const version = "4.0.2";
14889
+ const version = "4.0.4";
14837
14890
  function install(app) {
14838
14891
  const components = [
14839
14892
  ActionBar,
package/lib/vant.js CHANGED
@@ -3837,11 +3837,16 @@
3837
3837
  }
3838
3838
  };
3839
3839
  const renderTitle = () => {
3840
+ var _a;
3840
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
+ }
3841
3846
  return vue.createVNode("div", {
3842
3847
  "class": [bem$1a("title"), props.titleClass],
3843
3848
  "style": props.titleStyle
3844
- }, [slots.title ? slots.title() : vue.createVNode("span", null, [props.title]), renderLabel()]);
3849
+ }, [titleSlot || vue.createVNode("span", null, [props.title]), renderLabel()]);
3845
3850
  }
3846
3851
  };
3847
3852
  const renderValue = () => {
@@ -4322,6 +4327,7 @@
4322
4327
  }
4323
4328
  };
4324
4329
  const limitValueLength = (value) => {
4330
+ var _a;
4325
4331
  const {
4326
4332
  maxlength
4327
4333
  } = props;
@@ -4330,6 +4336,13 @@
4330
4336
  if (modelValue && getStringLength(modelValue) === +maxlength) {
4331
4337
  return modelValue;
4332
4338
  }
4339
+ const selectionEnd = (_a = inputRef.value) == null ? void 0 : _a.selectionEnd;
4340
+ if (state.focused && selectionEnd) {
4341
+ const valueArr = [...value];
4342
+ const exceededLength = valueArr.length - +maxlength;
4343
+ valueArr.splice(selectionEnd - exceededLength, exceededLength);
4344
+ return valueArr.join("");
4345
+ }
4333
4346
  return cutString(value, +maxlength);
4334
4347
  }
4335
4348
  return value;
@@ -4337,22 +4350,47 @@
4337
4350
  const updateValue = (value, trigger = "onChange") => {
4338
4351
  const originalValue = value;
4339
4352
  value = limitValueLength(value);
4340
- const isExceedLimit = value !== originalValue;
4353
+ const limitDiffLen = getStringLength(originalValue) - getStringLength(value);
4341
4354
  if (props.type === "number" || props.type === "digit") {
4342
4355
  const isNumber = props.type === "number";
4343
4356
  value = formatNumber(value, isNumber, isNumber);
4344
4357
  }
4358
+ let formatterDiffLen = 0;
4345
4359
  if (props.formatter && trigger === props.formatTrigger) {
4346
- value = props.formatter(value);
4360
+ const {
4361
+ formatter,
4362
+ maxlength
4363
+ } = props;
4364
+ value = formatter(value);
4365
+ if (isDef(maxlength) && getStringLength(value) > maxlength) {
4366
+ value = cutString(value, +maxlength);
4367
+ }
4368
+ if (inputRef.value && state.focused) {
4369
+ const {
4370
+ selectionEnd
4371
+ } = inputRef.value;
4372
+ const bcoVal = cutString(originalValue, selectionEnd);
4373
+ formatterDiffLen = getStringLength(formatter(bcoVal)) - getStringLength(bcoVal);
4374
+ }
4347
4375
  }
4348
4376
  if (inputRef.value && inputRef.value.value !== value) {
4349
- if (state.focused && isExceedLimit) {
4350
- const {
4377
+ if (state.focused) {
4378
+ let {
4351
4379
  selectionStart,
4352
4380
  selectionEnd
4353
4381
  } = inputRef.value;
4354
4382
  inputRef.value.value = value;
4355
- inputRef.value.setSelectionRange(selectionStart - 1, selectionEnd - 1);
4383
+ if (isDef(selectionStart) && isDef(selectionEnd)) {
4384
+ const valueLen = getStringLength(value);
4385
+ if (limitDiffLen) {
4386
+ selectionStart -= limitDiffLen;
4387
+ selectionEnd -= limitDiffLen;
4388
+ } else if (formatterDiffLen) {
4389
+ selectionStart += formatterDiffLen;
4390
+ selectionEnd += formatterDiffLen;
4391
+ }
4392
+ inputRef.value.setSelectionRange(Math.min(selectionStart, valueLen), Math.min(selectionEnd, valueLen));
4393
+ }
4356
4394
  } else {
4357
4395
  inputRef.value.value = value;
4358
4396
  }
@@ -4579,9 +4617,14 @@
4579
4617
  return () => {
4580
4618
  const disabled = getProp("disabled");
4581
4619
  const labelAlign = getProp("labelAlign");
4582
- const Label = renderLabel();
4583
4620
  const LeftIcon = renderLeftIcon();
4584
- const renderTitle = () => labelAlign === "top" ? [LeftIcon, Label] : Label;
4621
+ const renderTitle = () => {
4622
+ const Label = renderLabel();
4623
+ if (labelAlign === "top") {
4624
+ return [LeftIcon, Label].filter(Boolean);
4625
+ }
4626
+ return Label || [];
4627
+ };
4585
4628
  return vue.createVNode(Cell, {
4586
4629
  "size": props.size,
4587
4630
  "class": bem$18({
@@ -4601,7 +4644,7 @@
4601
4644
  "arrowDirection": props.arrowDirection
4602
4645
  }, {
4603
4646
  icon: LeftIcon && labelAlign !== "top" ? () => LeftIcon : null,
4604
- title: Label || labelAlign === "top" ? renderTitle : null,
4647
+ title: renderTitle,
4605
4648
  value: renderFieldBody,
4606
4649
  extra: slots.extra
4607
4650
  });
@@ -6867,6 +6910,14 @@
6867
6910
  emit("load", event);
6868
6911
  }
6869
6912
  };
6913
+ const triggerLoad = () => {
6914
+ const loadEvent = new Event("load");
6915
+ Object.defineProperty(loadEvent, "target", {
6916
+ value: imageRef.value,
6917
+ enumerable: true
6918
+ });
6919
+ onLoad(loadEvent);
6920
+ };
6870
6921
  const onError = (event) => {
6871
6922
  error.value = true;
6872
6923
  loading.value = false;
@@ -6924,7 +6975,7 @@
6924
6975
  }) => {
6925
6976
  const check = () => {
6926
6977
  if (el === imageRef.value && loading.value) {
6927
- onLoad();
6978
+ triggerLoad();
6928
6979
  }
6929
6980
  };
6930
6981
  if (imageRef.value) {
@@ -6949,10 +7000,12 @@
6949
7000
  });
6950
7001
  }
6951
7002
  vue.onMounted(() => {
6952
- var _a;
6953
- if ((_a = imageRef.value) == null ? void 0 : _a.complete) {
6954
- onLoad();
6955
- }
7003
+ vue.nextTick(() => {
7004
+ var _a;
7005
+ if ((_a = imageRef.value) == null ? void 0 : _a.complete) {
7006
+ triggerLoad();
7007
+ }
7008
+ });
6956
7009
  });
6957
7010
  return () => {
6958
7011
  var _a;
@@ -16041,7 +16094,7 @@
16041
16094
  });
16042
16095
  }
16043
16096
  };
16044
- const version = "4.0.2";
16097
+ const version = "4.0.4";
16045
16098
  function install(app) {
16046
16099
  const components = [
16047
16100
  ActionBar,