antd-mobile 5.40.0 → 5.41.0-alpha.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 (58) hide show
  1. package/2x/bundle/antd-mobile.cjs.development.js +150 -16
  2. package/2x/bundle/antd-mobile.cjs.js +6 -6
  3. package/2x/bundle/antd-mobile.es.development.js +150 -16
  4. package/2x/bundle/antd-mobile.es.js +3983 -3914
  5. package/2x/bundle/antd-mobile.umd.development.js +150 -16
  6. package/2x/bundle/antd-mobile.umd.js +7 -7
  7. package/2x/bundle/style.css +4 -1
  8. package/2x/cjs/components/date-picker/date-picker-week-utils.js +2 -1
  9. package/2x/cjs/components/ellipsis/ellipsis.d.ts +3 -0
  10. package/2x/cjs/components/ellipsis/ellipsis.js +10 -2
  11. package/2x/cjs/components/swiper/swiper.js +1 -1
  12. package/2x/cjs/components/tabs/tabs.js +45 -13
  13. package/2x/cjs/components/virtual-input/virtual-input.css +4 -1
  14. package/2x/cjs/components/virtual-input/virtual-input.d.ts +6 -0
  15. package/2x/cjs/components/virtual-input/virtual-input.js +105 -8
  16. package/2x/es/components/date-picker/date-picker-week-utils.js +2 -1
  17. package/2x/es/components/ellipsis/ellipsis.d.ts +3 -0
  18. package/2x/es/components/ellipsis/ellipsis.js +10 -2
  19. package/2x/es/components/swiper/swiper.js +1 -1
  20. package/2x/es/components/tabs/tabs.js +44 -12
  21. package/2x/es/components/virtual-input/virtual-input.css +4 -1
  22. package/2x/es/components/virtual-input/virtual-input.d.ts +6 -0
  23. package/2x/es/components/virtual-input/virtual-input.js +105 -8
  24. package/2x/package.json +3 -3
  25. package/bundle/antd-mobile.cjs.development.js +150 -16
  26. package/bundle/antd-mobile.cjs.js +6 -6
  27. package/bundle/antd-mobile.compatible.umd.js +1 -1
  28. package/bundle/antd-mobile.es.development.js +150 -16
  29. package/bundle/antd-mobile.es.js +3983 -3914
  30. package/bundle/antd-mobile.umd.development.js +150 -16
  31. package/bundle/antd-mobile.umd.js +7 -7
  32. package/bundle/style.css +1 -1
  33. package/cjs/components/date-picker/date-picker-week-utils.js +2 -1
  34. package/cjs/components/ellipsis/ellipsis.d.ts +3 -0
  35. package/cjs/components/ellipsis/ellipsis.js +10 -2
  36. package/cjs/components/swiper/swiper.js +1 -1
  37. package/cjs/components/tabs/tabs.js +45 -13
  38. package/cjs/components/virtual-input/virtual-input.css +3 -1
  39. package/cjs/components/virtual-input/virtual-input.d.ts +6 -0
  40. package/cjs/components/virtual-input/virtual-input.js +105 -8
  41. package/es/components/date-picker/date-picker-week-utils.js +2 -1
  42. package/es/components/ellipsis/ellipsis.d.ts +3 -0
  43. package/es/components/ellipsis/ellipsis.js +10 -2
  44. package/es/components/swiper/swiper.js +1 -1
  45. package/es/components/tabs/tabs.js +44 -12
  46. package/es/components/virtual-input/virtual-input.css +3 -1
  47. package/es/components/virtual-input/virtual-input.d.ts +6 -0
  48. package/es/components/virtual-input/virtual-input.js +105 -8
  49. package/package.json +3 -3
  50. package/umd/antd-mobile.js +1 -1
  51. package/2x/cjs/components/ellipsis/~ellipsis.d.ts +0 -15
  52. package/2x/cjs/components/ellipsis/~ellipsis.js +0 -161
  53. package/2x/es/components/ellipsis/~ellipsis.d.ts +0 -15
  54. package/2x/es/components/ellipsis/~ellipsis.js +0 -151
  55. package/cjs/components/ellipsis/~ellipsis.d.ts +0 -15
  56. package/cjs/components/ellipsis/~ellipsis.js +0 -161
  57. package/es/components/ellipsis/~ellipsis.d.ts +0 -15
  58. package/es/components/ellipsis/~ellipsis.js +0 -151
@@ -12232,6 +12232,7 @@ const Tabs$1 = (p) => {
12232
12232
  const props = mergeProps(defaultProps$S, p);
12233
12233
  const tabListContainerRef = useRef(null);
12234
12234
  const activeLineRef = useRef(null);
12235
+ const tabRefs = useRef({});
12235
12236
  const keyToIndexRecord = {};
12236
12237
  let firstActiveKey = null;
12237
12238
  const panes = [];
@@ -12371,7 +12372,7 @@ const Tabs$1 = (p) => {
12371
12372
  });
12372
12373
  const {
12373
12374
  run: updateMask
12374
- } = useThrottleFn((immediate = false) => {
12375
+ } = useThrottleFn((immediate) => {
12375
12376
  const container = tabListContainerRef.current;
12376
12377
  if (!container)
12377
12378
  return;
@@ -12398,6 +12399,35 @@ const Tabs$1 = (p) => {
12398
12399
  useIsomorphicLayoutEffect$3(() => {
12399
12400
  updateMask(true);
12400
12401
  }, []);
12402
+ const handleKeyDown = (e2) => {
12403
+ const keys2 = Object.keys(keyToIndexRecord);
12404
+ const currentIndex = keyToIndexRecord[activeKey];
12405
+ const isNext = isRTL2 ? e2.key === "ArrowLeft" : e2.key === "ArrowRight";
12406
+ const isPrev = isRTL2 ? e2.key === "ArrowRight" : e2.key === "ArrowLeft";
12407
+ const offsetDirection = isNext ? 1 : -1;
12408
+ const findNextEnabledTab = (startIndex, direction) => {
12409
+ const length = keys2.length;
12410
+ for (let i2 = 0; i2 < length; i2++) {
12411
+ const index2 = (startIndex + direction * (i2 + 1) + length) % length;
12412
+ const key = keys2[index2];
12413
+ const pane = panes.find((p2) => p2.key === key);
12414
+ if (!(pane === null || pane === void 0 ? void 0 : pane.props.disabled))
12415
+ return key;
12416
+ }
12417
+ return keys2[startIndex];
12418
+ };
12419
+ const currentKey = findNextEnabledTab(currentIndex, offsetDirection);
12420
+ if (isNext || isPrev) {
12421
+ e2.preventDefault();
12422
+ setActiveKey(currentKey);
12423
+ }
12424
+ };
12425
+ useEffect(() => {
12426
+ var _a2;
12427
+ if (activeKey && tabRefs.current[activeKey]) {
12428
+ (_a2 = tabRefs.current[activeKey]) === null || _a2 === void 0 ? void 0 : _a2.focus();
12429
+ }
12430
+ }, [activeKey]);
12401
12431
  return withNativeProps(props, React__default.createElement("div", {
12402
12432
  className: classPrefix$15,
12403
12433
  style: {
@@ -12420,6 +12450,7 @@ const Tabs$1 = (p) => {
12420
12450
  ref: tabListContainerRef,
12421
12451
  scrollLeft,
12422
12452
  onScroll: updateMask,
12453
+ onKeyDown: handleKeyDown,
12423
12454
  role: "tablist"
12424
12455
  }, React__default.createElement(animated.div, {
12425
12456
  ref: activeLineRef,
@@ -12434,6 +12465,10 @@ const Tabs$1 = (p) => {
12434
12465
  [`${classPrefix$15}-tab-wrapper-stretch`]: props.stretch
12435
12466
  })
12436
12467
  }, React__default.createElement("div", {
12468
+ role: "tab",
12469
+ "aria-selected": pane.key === activeKey,
12470
+ tabIndex: pane.key === activeKey ? 0 : -1,
12471
+ ref: (el) => tabRefs.current[pane.key] = el,
12437
12472
  onClick: () => {
12438
12473
  const {
12439
12474
  key
@@ -12448,9 +12483,7 @@ const Tabs$1 = (p) => {
12448
12483
  className: classNames(`${classPrefix$15}-tab`, {
12449
12484
  [`${classPrefix$15}-tab-active`]: pane.key === activeKey,
12450
12485
  [`${classPrefix$15}-tab-disabled`]: pane.props.disabled
12451
- }),
12452
- role: "tab",
12453
- "aria-selected": pane.key === activeKey
12486
+ })
12454
12487
  }, pane.props.title)))))), panes.map((pane) => {
12455
12488
  if (pane.props.children === void 0) {
12456
12489
  return null;
@@ -13838,7 +13871,7 @@ function convertStringArrayToDate$1(value) {
13838
13871
  const yearString = (_a = value[0]) !== null && _a !== void 0 ? _a : "1900";
13839
13872
  const weekString = (_b = value[1]) !== null && _b !== void 0 ? _b : "1";
13840
13873
  const weekdayString = (_c = value[2]) !== null && _c !== void 0 ? _c : "1";
13841
- const day = dayjs(`${parseInt(yearString)}-01-01`).isoWeek(parseInt(weekString)).isoWeekday(parseInt(weekdayString)).hour(0).minute(0).second(0);
13874
+ const day = dayjs(`${parseInt(yearString)}-01-04`).isoWeek(parseInt(weekString)).isoWeekday(parseInt(weekdayString)).hour(0).minute(0).second(0);
13842
13875
  return day.toDate();
13843
13876
  }
13844
13877
  const precisionLengthRecord = {
@@ -14565,13 +14598,21 @@ const Ellipsis = (p) => {
14565
14598
  const rootRef = React__default.useRef(null);
14566
14599
  const [expanded, setExpanded] = React__default.useState(defaultExpanded);
14567
14600
  const expandNode = expandText ? withStopPropagation(stopPropagationForActionButtons, React__default.createElement("a", {
14568
- onClick: () => {
14601
+ onClick: (e2) => {
14602
+ var _a;
14569
14603
  setExpanded(true);
14604
+ (_a = props.onExpand) === null || _a === void 0 ? void 0 : _a.call(props, true, {
14605
+ event: e2
14606
+ });
14570
14607
  }
14571
14608
  }, expandText)) : null;
14572
14609
  const collapseNode = collapseText ? withStopPropagation(stopPropagationForActionButtons, React__default.createElement("a", {
14573
- onClick: () => {
14610
+ onClick: (e2) => {
14611
+ var _a;
14574
14612
  setExpanded(false);
14613
+ (_a = props.onExpand) === null || _a === void 0 ? void 0 : _a.call(props, false, {
14614
+ event: e2
14615
+ });
14575
14616
  }
14576
14617
  }, collapseText)) : null;
14577
14618
  const [measureNodes, forceResize] = useMeasure(rootRef, content, rows, direction, expanded, expandNode, collapseNode);
@@ -26588,7 +26629,7 @@ const Swiper = forwardRef(staged_1((p, ref2) => {
26588
26629
  return React__default.createElement(React__default.Fragment, null, React__default.createElement("div", {
26589
26630
  className: `${classPrefix$a}-slide-placeholder`,
26590
26631
  style: {
26591
- width: `${startIndex * 100}%`
26632
+ [isVertical ? "height" : "width"]: `${startIndex * 100}%`
26592
26633
  }
26593
26634
  }), items);
26594
26635
  }
@@ -27459,7 +27500,10 @@ const index = attachPropertiesToComponent(TreeSelect, {
27459
27500
  });
27460
27501
  const classPrefix$2 = "adm-virtual-input";
27461
27502
  const defaultProps$2 = {
27462
- defaultValue: ""
27503
+ defaultValue: "",
27504
+ cursor: {
27505
+ movable: false
27506
+ }
27463
27507
  };
27464
27508
  const VirtualInput = forwardRef((props, ref2) => {
27465
27509
  const {
@@ -27472,6 +27516,13 @@ const VirtualInput = forwardRef((props, ref2) => {
27472
27516
  const contentRef = useRef(null);
27473
27517
  const [hasFocus, setHasFocus] = useState(false);
27474
27518
  const [caretPosition, setCaretPosition] = useState(value.length);
27519
+ const keyboardDataRef = useRef({});
27520
+ const touchDataRef = useRef();
27521
+ const charRef = useRef(null);
27522
+ const charWidthRef = useRef(0);
27523
+ const caretRef = useRef(null);
27524
+ const [isCaretDragging, setIsCaretDragging] = useState(false);
27525
+ const touchMoveTimeoutRef = useRef();
27475
27526
  const clearIcon = mergeProp(React__default.createElement(CloseCircleFill, null), componentConfig.clearIcon, props.clearIcon);
27476
27527
  function scrollToEnd() {
27477
27528
  const root2 = rootRef.current;
@@ -27485,6 +27536,22 @@ const VirtualInput = forwardRef((props, ref2) => {
27485
27536
  return;
27486
27537
  content.scrollLeft = content.clientWidth;
27487
27538
  }
27539
+ useEffect(() => {
27540
+ if (charRef.current) {
27541
+ charWidthRef.current = charRef.current.getBoundingClientRect().width;
27542
+ }
27543
+ }, [value]);
27544
+ useEffect(() => {
27545
+ if (value === keyboardDataRef.current.newValue) {
27546
+ if (keyboardDataRef.current.mode === "input") {
27547
+ setCaretPosition((c) => c + 1);
27548
+ } else if (keyboardDataRef.current.mode === "delete") {
27549
+ setCaretPosition((c) => c - 1);
27550
+ }
27551
+ } else {
27552
+ setCaretPosition(value.length);
27553
+ }
27554
+ }, [value]);
27488
27555
  useIsomorphicLayoutEffect$3(() => {
27489
27556
  scrollToEnd();
27490
27557
  }, [value]);
@@ -27518,8 +27585,11 @@ const VirtualInput = forwardRef((props, ref2) => {
27518
27585
  onInput: (v) => {
27519
27586
  var _a, _b;
27520
27587
  const newValue = value.substring(0, caretPosition) + v + value.substring(caretPosition);
27588
+ keyboardDataRef.current = {
27589
+ newValue,
27590
+ mode: "input"
27591
+ };
27521
27592
  setValue(newValue);
27522
- setCaretPosition((c) => c + 1);
27523
27593
  (_b = (_a = keyboard.props).onInput) === null || _b === void 0 ? void 0 : _b.call(_a, v);
27524
27594
  },
27525
27595
  onDelete: () => {
@@ -27527,8 +27597,11 @@ const VirtualInput = forwardRef((props, ref2) => {
27527
27597
  if (caretPosition === 0)
27528
27598
  return;
27529
27599
  const newValue = value.substring(0, caretPosition - 1) + value.substring(caretPosition);
27600
+ keyboardDataRef.current = {
27601
+ newValue,
27602
+ mode: "delete"
27603
+ };
27530
27604
  setValue(newValue);
27531
- setCaretPosition(caretPosition - 1);
27532
27605
  (_b = (_a = keyboard.props).onDelete) === null || _b === void 0 ? void 0 : _b.call(_a);
27533
27606
  },
27534
27607
  visible: hasFocus,
@@ -27545,21 +27618,78 @@ const VirtualInput = forwardRef((props, ref2) => {
27545
27618
  getContainer: null
27546
27619
  });
27547
27620
  const setCaretPositionToEnd = () => {
27548
- setCaretPosition(value.length);
27621
+ var _a, _b;
27622
+ if (caretPosition !== value.length) {
27623
+ setCaretPosition(value.length);
27624
+ (_b = (_a = mergedProps.cursor) === null || _a === void 0 ? void 0 : _a.onMove) === null || _b === void 0 ? void 0 : _b.call(_a, value.length);
27625
+ }
27549
27626
  };
27550
27627
  const changeCaretPosition = (index2) => (e2) => {
27628
+ var _a, _b, _c;
27629
+ if (mergedProps.disabled || !((_a = mergedProps.cursor) === null || _a === void 0 ? void 0 : _a.movable))
27630
+ return;
27551
27631
  e2.stopPropagation();
27552
27632
  const rect = e2.target.getBoundingClientRect();
27553
27633
  const midX = rect.left + rect.width / 2;
27554
27634
  const clickX = e2.clientX;
27555
27635
  const isRight = clickX > midX;
27556
- setCaretPosition(isRight ? index2 + 1 : index2);
27636
+ const newCaretPosition = isRight ? index2 + 1 : index2;
27637
+ setCaretPosition(newCaretPosition);
27638
+ (_c = (_b = mergedProps.cursor) === null || _b === void 0 ? void 0 : _b.onMove) === null || _c === void 0 ? void 0 : _c.call(_b, newCaretPosition);
27639
+ };
27640
+ const handleTouchStart = (e2) => {
27641
+ var _a;
27642
+ if (mergedProps.disabled || !((_a = mergedProps.cursor) === null || _a === void 0 ? void 0 : _a.movable))
27643
+ return;
27644
+ if (!caretRef.current)
27645
+ return;
27646
+ const touch = e2.touches[0];
27647
+ const caretRect = caretRef.current.getBoundingClientRect();
27648
+ const distance = Math.abs(touch.clientX - (caretRect.left + caretRect.width / 2));
27649
+ if (distance < 20) {
27650
+ touchDataRef.current = {
27651
+ startX: touch.clientX,
27652
+ startCaretPosition: caretPosition
27653
+ };
27654
+ } else {
27655
+ touchDataRef.current = null;
27656
+ }
27657
+ };
27658
+ const handleTouchMove = (e2) => {
27659
+ var _a, _b, _c;
27660
+ if (!touchDataRef.current || !((_a = mergedProps.cursor) === null || _a === void 0 ? void 0 : _a.movable))
27661
+ return;
27662
+ setIsCaretDragging(true);
27663
+ const touch = e2.touches[0];
27664
+ const deltaX = touch.clientX - touchDataRef.current.startX;
27665
+ const charWidth = charWidthRef.current;
27666
+ const moveChars = Math.round(deltaX / charWidth);
27667
+ let newCaretPosition = touchDataRef.current.startCaretPosition + moveChars;
27668
+ newCaretPosition = Math.max(0, Math.min(newCaretPosition, value.length));
27669
+ setCaretPosition(newCaretPosition);
27670
+ (_c = (_b = mergedProps.cursor) === null || _b === void 0 ? void 0 : _b.onMove) === null || _c === void 0 ? void 0 : _c.call(_b, newCaretPosition);
27671
+ if (touchMoveTimeoutRef.current) {
27672
+ clearTimeout(touchMoveTimeoutRef.current);
27673
+ }
27674
+ touchMoveTimeoutRef.current = setTimeout(() => {
27675
+ setIsCaretDragging(false);
27676
+ touchMoveTimeoutRef.current = null;
27677
+ }, 500);
27678
+ };
27679
+ const handleTouchEnd = () => {
27680
+ touchDataRef.current = null;
27681
+ setIsCaretDragging(false);
27682
+ if (touchMoveTimeoutRef.current) {
27683
+ clearTimeout(touchMoveTimeoutRef.current);
27684
+ touchMoveTimeoutRef.current = null;
27685
+ }
27557
27686
  };
27558
27687
  const chars = (value + "").split("");
27559
27688
  return withNativeProps(mergedProps, React__default.createElement("div", {
27560
27689
  ref: rootRef,
27561
27690
  className: classNames(classPrefix$2, {
27562
- [`${classPrefix$2}-disabled`]: mergedProps.disabled
27691
+ [`${classPrefix$2}-disabled`]: mergedProps.disabled,
27692
+ [`${classPrefix$2}-caret-dragging`]: isCaretDragging
27563
27693
  }),
27564
27694
  tabIndex: mergedProps.disabled ? void 0 : 0,
27565
27695
  role: "textbox",
@@ -27571,13 +27701,18 @@ const VirtualInput = forwardRef((props, ref2) => {
27571
27701
  ref: contentRef,
27572
27702
  "aria-disabled": mergedProps.disabled,
27573
27703
  "aria-label": mergedProps.placeholder,
27574
- onClick: setCaretPositionToEnd
27704
+ onClick: setCaretPositionToEnd,
27705
+ onTouchStart: handleTouchStart,
27706
+ onTouchMove: handleTouchMove,
27707
+ onTouchEnd: handleTouchEnd
27575
27708
  }, chars.slice(0, caretPosition).map((i2, index2) => React__default.createElement("span", {
27709
+ ref: index2 === 0 ? charRef : void 0,
27576
27710
  key: index2,
27577
27711
  onClick: changeCaretPosition(index2)
27578
27712
  }, i2)), React__default.createElement("div", {
27579
27713
  className: `${classPrefix$2}-caret-container`
27580
27714
  }, hasFocus && React__default.createElement("div", {
27715
+ ref: caretRef,
27581
27716
  className: `${classPrefix$2}-caret`
27582
27717
  })), chars.slice(caretPosition).map((i2, index2) => React__default.createElement("span", {
27583
27718
  key: index2,
@@ -27588,7 +27723,6 @@ const VirtualInput = forwardRef((props, ref2) => {
27588
27723
  var _a;
27589
27724
  e2.stopPropagation();
27590
27725
  setValue("");
27591
- setCaretPosition(0);
27592
27726
  (_a = mergedProps.onClear) === null || _a === void 0 ? void 0 : _a.call(mergedProps);
27593
27727
  },
27594
27728
  role: "button",