@arco-design/mobile-react 2.21.3 → 2.22.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 (63) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.en-US.md +2 -2
  3. package/README.md +2 -2
  4. package/cjs/_helpers/index.d.ts +1 -0
  5. package/cjs/_helpers/index.js +9 -0
  6. package/cjs/_helpers/react-dom.d.ts +13 -0
  7. package/cjs/_helpers/react-dom.js +65 -0
  8. package/cjs/_helpers/render.d.ts +10 -0
  9. package/cjs/_helpers/render.js +40 -0
  10. package/cjs/action-sheet/index.d.ts +1 -1
  11. package/cjs/image-picker/index.js +0 -1
  12. package/cjs/image-preview/index.d.ts +2 -10
  13. package/cjs/image-preview/methods.js +4 -11
  14. package/cjs/masking/index.d.ts +10 -0
  15. package/cjs/masking/methods.js +4 -11
  16. package/cjs/notify/methods.js +6 -9
  17. package/cjs/popover/hooks/useEvent.js +6 -6
  18. package/cjs/swipe-action/index.js +21 -3
  19. package/cjs/tabs/index.js +5 -2
  20. package/cjs/tabs/tab-cell.js +4 -3
  21. package/cjs/tabs/type.d.ts +11 -0
  22. package/cjs/toast/methods.js +9 -12
  23. package/dist/index.js +167 -72
  24. package/dist/index.min.js +3 -3
  25. package/esm/_helpers/index.d.ts +1 -0
  26. package/esm/_helpers/index.js +1 -0
  27. package/esm/_helpers/react-dom.d.ts +13 -0
  28. package/esm/_helpers/react-dom.js +57 -0
  29. package/esm/_helpers/render.d.ts +10 -0
  30. package/esm/_helpers/render.js +29 -0
  31. package/esm/action-sheet/index.d.ts +1 -1
  32. package/esm/image-picker/index.js +0 -1
  33. package/esm/image-preview/index.d.ts +2 -10
  34. package/esm/image-preview/methods.js +3 -9
  35. package/esm/masking/index.d.ts +10 -0
  36. package/esm/masking/methods.js +3 -9
  37. package/esm/notify/methods.js +6 -7
  38. package/esm/popover/hooks/useEvent.js +6 -6
  39. package/esm/swipe-action/index.js +21 -3
  40. package/esm/tabs/index.js +5 -2
  41. package/esm/tabs/tab-cell.js +4 -3
  42. package/esm/tabs/type.d.ts +11 -0
  43. package/esm/toast/methods.js +8 -9
  44. package/package.json +3 -3
  45. package/umd/_helpers/index.d.ts +1 -0
  46. package/umd/_helpers/index.js +10 -4
  47. package/umd/_helpers/react-dom.d.ts +13 -0
  48. package/umd/_helpers/react-dom.js +78 -0
  49. package/umd/_helpers/render.d.ts +10 -0
  50. package/umd/_helpers/render.js +51 -0
  51. package/umd/action-sheet/index.d.ts +1 -1
  52. package/umd/image-picker/index.js +0 -1
  53. package/umd/image-preview/index.d.ts +2 -10
  54. package/umd/image-preview/methods.js +6 -13
  55. package/umd/masking/index.d.ts +10 -0
  56. package/umd/masking/methods.js +6 -13
  57. package/umd/notify/methods.js +9 -12
  58. package/umd/popover/hooks/useEvent.js +6 -6
  59. package/umd/swipe-action/index.js +21 -3
  60. package/umd/tabs/index.js +5 -2
  61. package/umd/tabs/tab-cell.js +4 -3
  62. package/umd/tabs/type.d.ts +11 -0
  63. package/umd/toast/methods.js +11 -14
package/dist/index.js CHANGED
@@ -60,7 +60,7 @@
60
60
  function isArray(obj) {
61
61
  return opt.call(obj) === '[object Array]';
62
62
  }
63
- function isObject$1(obj) {
63
+ function isObject$2(obj) {
64
64
  return opt.call(obj) === '[object Object]';
65
65
  }
66
66
  function isString(obj) {
@@ -91,7 +91,7 @@
91
91
  classNames.push(v);
92
92
  } else if (isArray(v)) {
93
93
  classNames = classNames.concat(v);
94
- } else if (isObject$1(v)) {
94
+ } else if (isObject$2(v)) {
95
95
  Object.keys(v).forEach(function (k) {
96
96
  if (v[k]) {
97
97
  classNames.push(k);
@@ -2494,6 +2494,64 @@
2494
2494
  };
2495
2495
  }
2496
2496
 
2497
+ var _a;
2498
+
2499
+ function isObject$1(obj) {
2500
+ return Object.prototype.toString.call(obj) === '[object Object]';
2501
+ }
2502
+
2503
+ var __SECRET_INTERNALS__ = '__SECRET_INTERNALS_DO_NOT_USE_OR_YOU_WILL_BE_FIRED';
2504
+ var CopyReactDOM = ReactDOM__default["default"];
2505
+ var copyRender;
2506
+ var isReact18 = Number((_a = CopyReactDOM.version) === null || _a === void 0 ? void 0 : _a.split('.')[0]) > 17;
2507
+
2508
+ var updateUsingClientEntryPoint = function updateUsingClientEntryPoint(skipWarning) {
2509
+ // https://github.com/facebook/react/blob/17806594cc28284fe195f918e8d77de3516848ec/packages/react-dom/npm/client.js#L10
2510
+ // Avoid console warning
2511
+ if (isObject$1(CopyReactDOM[__SECRET_INTERNALS__])) {
2512
+ CopyReactDOM[__SECRET_INTERNALS__].usingClientEntryPoint = skipWarning;
2513
+ }
2514
+ };
2515
+
2516
+ var createRoot;
2517
+
2518
+ try {
2519
+ createRoot = CopyReactDOM.createRoot;
2520
+ } catch (_) {}
2521
+
2522
+ if (isReact18 && createRoot) {
2523
+ copyRender = function copyRender(app, container) {
2524
+ updateUsingClientEntryPoint(true);
2525
+ var root = createRoot(container);
2526
+ updateUsingClientEntryPoint(false);
2527
+ root.render(app);
2528
+
2529
+ root._unmount = function () {
2530
+ setTimeout(function () {
2531
+ var _a;
2532
+
2533
+ (_a = root === null || root === void 0 ? void 0 : root.unmount) === null || _a === void 0 ? void 0 : _a.call(root);
2534
+ });
2535
+ };
2536
+
2537
+ return root;
2538
+ };
2539
+ } else {
2540
+ copyRender = function copyRender(app, container) {
2541
+ CopyReactDOM.render(app, container);
2542
+ return {
2543
+ render: function render(comment) {
2544
+ CopyReactDOM.render(comment, container);
2545
+ },
2546
+ _unmount: function _unmount() {
2547
+ CopyReactDOM.unmountComponentAtNode(container);
2548
+ }
2549
+ };
2550
+ };
2551
+ }
2552
+
2553
+ var render = copyRender;
2554
+
2497
2555
  function getStyleWithVendor(style) {
2498
2556
  var allowReg = /(transform|transition|animation)/i;
2499
2557
  var newStyle = Object.keys(style).reduce(function (acc, key) {
@@ -2515,6 +2573,36 @@
2515
2573
  return value === void 0 ? defaultValue : value;
2516
2574
  };
2517
2575
 
2576
+ var ReactDOMRender =
2577
+ /** @class */
2578
+ function () {
2579
+ function ReactDOMRender(app, container) {
2580
+ var _this = this;
2581
+
2582
+ this.render = function (props) {
2583
+ var CustomApp = _this.app;
2584
+
2585
+ if (_this.root) {
2586
+ _this.root.render( /*#__PURE__*/React__default["default"].createElement(CustomApp, __assign({}, props)));
2587
+ } else {
2588
+ _this.root = render( /*#__PURE__*/React__default["default"].createElement(CustomApp, __assign({}, props)), _this.container);
2589
+ }
2590
+ };
2591
+
2592
+ this.unmount = function () {
2593
+ var _a;
2594
+
2595
+ (_a = _this.root) === null || _a === void 0 ? void 0 : _a._unmount();
2596
+ _this.root = undefined;
2597
+ };
2598
+
2599
+ this.app = app;
2600
+ this.container = container;
2601
+ }
2602
+
2603
+ return ReactDOMRender;
2604
+ }();
2605
+
2518
2606
  function getOpenMethod(Component, containerId, normalize) {
2519
2607
  if (normalize === void 0) {
2520
2608
  normalize = function normalize(config) {
@@ -2536,14 +2624,7 @@
2536
2624
  var id = "_" + (containerId || 'ARCO_MASKING') + "_DIV_" + (config.key || '') + "_";
2537
2625
  var div = appendElementById(id, baseProps.getContainer).child;
2538
2626
  var leaving = false;
2539
-
2540
- function render(props) {
2541
- ReactDOM__default["default"].render( /*#__PURE__*/React__default["default"].createElement(Component, __assign({}, props, {
2542
- getContainer: function getContainer() {
2543
- return div;
2544
- }
2545
- })), div);
2546
- }
2627
+ var render = new ReactDOMRender(Component, div).render;
2547
2628
 
2548
2629
  function update(newConfig) {
2549
2630
  dynamicProps = __assign(__assign({}, dynamicProps), normalize(newConfig));
@@ -5203,16 +5284,16 @@
5203
5284
  var div = document.createElement('div');
5204
5285
  document.body.appendChild(div);
5205
5286
 
5206
- function render(props) {
5207
- ReactDOM__default["default"].render( /*#__PURE__*/React__default["default"].createElement(Component, __assign({}, props)), div);
5208
- }
5287
+ var _a = new ReactDOMRender(Component, div),
5288
+ render = _a.render,
5289
+ unmount = _a.unmount;
5209
5290
 
5210
- function destory() {
5291
+ function destroy() {
5211
5292
  var onClose = config.onClose;
5212
5293
  onClose && onClose();
5213
- var unmountResult = ReactDOM__default["default"].unmountComponentAtNode(div);
5294
+ unmount();
5214
5295
 
5215
- if (unmountResult && div.parentNode) {
5296
+ if (div.parentNode) {
5216
5297
  div.parentNode.removeChild(div);
5217
5298
  }
5218
5299
  }
@@ -5222,7 +5303,7 @@
5222
5303
  getContainer: function getContainer() {
5223
5304
  return div;
5224
5305
  },
5225
- onClose: destory,
5306
+ onClose: destroy,
5226
5307
  visible: false
5227
5308
  });
5228
5309
 
@@ -6788,7 +6869,8 @@
6788
6869
  renderTabBarInner = props.renderTabBarInner,
6789
6870
  tabBarStyle = props.tabBarStyle,
6790
6871
  tabBarClass = props.tabBarClass,
6791
- translateZ = props.translateZ;
6872
+ translateZ = props.translateZ,
6873
+ tabBarStopPropagation = props.tabBarStopPropagation;
6792
6874
  var prefix = prefixCls + "-tab-cell";
6793
6875
  var domRef = React.useRef(null);
6794
6876
  var underlineRef = React.useRef(null);
@@ -6880,13 +6962,13 @@
6880
6962
  return e.stopPropagation();
6881
6963
  };
6882
6964
 
6883
- if (isVertical && hasOverflow && domRef.current) {
6965
+ if (isVertical && hasOverflow && domRef.current && tabBarStopPropagation) {
6884
6966
  domRef.current.addEventListener('touchstart', stopFunc);
6885
6967
  domRef.current.addEventListener('touchmove', stopFunc);
6886
6968
  }
6887
6969
 
6888
6970
  return function () {
6889
- if (isVertical && hasOverflow && domRef.current) {
6971
+ if (isVertical && hasOverflow && domRef.current && tabBarStopPropagation) {
6890
6972
  domRef.current.removeEventListener('touchstart', stopFunc);
6891
6973
  domRef.current.removeEventListener('touchmove', stopFunc);
6892
6974
  }
@@ -7929,44 +8011,46 @@
7929
8011
  _4 = props.translateZ,
7930
8012
  translateZ = _4 === void 0 ? true : _4,
7931
8013
  fullScreen = props.fullScreen,
7932
- autoHeight = props.autoHeight;
8014
+ autoHeight = props.autoHeight,
8015
+ _5 = props.tabBarStopPropagation,
8016
+ tabBarStopPropagation = _5 === void 0 ? true : _5;
7933
8017
  var domRef = React.useRef(null);
7934
8018
  var cellRef = React.useRef(null);
7935
8019
  var paneRef = React.useRef(null);
7936
8020
 
7937
- var _5 = React.useState(defaultActiveTab),
7938
- innerIndex = _5[0],
7939
- setInnerIndex = _5[1];
7940
-
7941
- var _6 = React.useState(0),
7942
- jumpingDis = _6[0],
7943
- setJumpingDis = _6[1];
8021
+ var _6 = React.useState(defaultActiveTab),
8022
+ innerIndex = _6[0],
8023
+ setInnerIndex = _6[1];
7944
8024
 
7945
8025
  var _7 = React.useState(0),
7946
- wrapWidth = _7[0],
7947
- setWrapWidth = _7[1];
8026
+ jumpingDis = _7[0],
8027
+ setJumpingDis = _7[1];
7948
8028
 
7949
8029
  var _8 = React.useState(0),
7950
- wrapHeight = _8[0],
7951
- setWrapHeight = _8[1];
8030
+ wrapWidth = _8[0],
8031
+ setWrapWidth = _8[1];
7952
8032
 
7953
- var _9 = React.useState(false),
7954
- cellTrans = _9[0],
7955
- setCellTrans = _9[1];
8033
+ var _9 = React.useState(0),
8034
+ wrapHeight = _9[0],
8035
+ setWrapHeight = _9[1];
7956
8036
 
7957
8037
  var _10 = React.useState(false),
7958
- paneTrans = _10[0],
7959
- setPaneTrans = _10[1];
8038
+ cellTrans = _10[0],
8039
+ setCellTrans = _10[1];
8040
+
8041
+ var _11 = React.useState(false),
8042
+ paneTrans = _11[0],
8043
+ setPaneTrans = _11[1];
7960
8044
 
7961
- var _11 = useRefState(activeTab === void 0 ? innerIndex : activeTab),
7962
- activeIndex = _11[0],
7963
- activeIndexRef = _11[1],
7964
- setActiveIndex = _11[2];
8045
+ var _12 = useRefState(activeTab === void 0 ? innerIndex : activeTab),
8046
+ activeIndex = _12[0],
8047
+ activeIndexRef = _12[1],
8048
+ setActiveIndex = _12[2];
7965
8049
 
7966
- var _12 = useRefState(0),
7967
- distance = _12[0],
7968
- distanceRef = _12[1],
7969
- setDistance = _12[2];
8050
+ var _13 = useRefState(0),
8051
+ distance = _13[0],
8052
+ distanceRef = _13[1],
8053
+ setDistance = _13[2];
7970
8054
 
7971
8055
  var posAdjustingRef = React.useRef(false);
7972
8056
  var touchStartedRef = React.useRef(false);
@@ -8282,7 +8366,8 @@
8282
8366
  renderTabBarItem: renderTabBarItem,
8283
8367
  renderTabBarInner: renderTabBarInner,
8284
8368
  tabBarStyle: tabBarStyle,
8285
- tabBarClass: tabBarClass
8369
+ tabBarClass: tabBarClass,
8370
+ tabBarStopPropagation: tabBarStopPropagation
8286
8371
  }, commonProps);
8287
8372
 
8288
8373
  var CellComp = /*#__PURE__*/React__default["default"].createElement(TabCell, __assign({}, cellProps));
@@ -14462,7 +14547,6 @@
14462
14547
  var timeOutEvent;
14463
14548
 
14464
14549
  var handleTouchStart = function handleTouchStart(e, image, index) {
14465
- e.preventDefault();
14466
14550
  timeOutEvent = setTimeout(function () {
14467
14551
  timeOutEvent = 0;
14468
14552
  onLongPress === null || onLongPress === void 0 ? void 0 : onLongPress(e, image, index);
@@ -16768,14 +16852,7 @@
16768
16852
  var id = "_ARCO_IMAGE_PREVIEW_DIV_" + (baseProps.key || '') + "_";
16769
16853
  var div = appendElementById(id, baseProps.getContainer).child;
16770
16854
  var leaving = false;
16771
-
16772
- function render(props) {
16773
- ReactDOM__default["default"].render( /*#__PURE__*/React__default["default"].createElement(Component, __assign({}, props, {
16774
- getContainer: function getContainer() {
16775
- return div;
16776
- }
16777
- })), div);
16778
- }
16855
+ var render = new ReactDOMRender(Component, div).render;
16779
16856
 
16780
16857
  function update(newConfig) {
16781
16858
  dynamicProps = __assign(__assign({}, dynamicProps), newConfig || {});
@@ -18640,16 +18717,16 @@
18640
18717
  document.body.appendChild(div);
18641
18718
  }
18642
18719
 
18643
- function render(props) {
18644
- ReactDOM__default["default"].render( /*#__PURE__*/React__default["default"].createElement(Component, __assign({}, props)), div);
18645
- }
18720
+ var _a = new ReactDOMRender(Component, div),
18721
+ render = _a.render,
18722
+ unmount = _a.unmount;
18646
18723
 
18647
18724
  function destroy() {
18648
18725
  var onClose = config.onClose;
18649
18726
  onClose && onClose();
18650
- var unmountResult = ReactDOM__default["default"].unmountComponentAtNode(div);
18727
+ unmount();
18651
18728
 
18652
- if (unmountResult && div.parentNode) {
18729
+ if (div.parentNode) {
18653
18730
  div.parentNode.removeChild(div);
18654
18731
  }
18655
18732
  }
@@ -19391,10 +19468,10 @@
19391
19468
  setDirectionState = _k[2];
19392
19469
 
19393
19470
  var getOffset = React.useCallback(function (dir) {
19394
- return getDefaultValue(isObject$1(edgeOffset) ? edgeOffset[dir] : edgeOffset, defaultEdgeOffset[dir]);
19471
+ return getDefaultValue(isObject$2(edgeOffset) ? edgeOffset[dir] : edgeOffset, defaultEdgeOffset[dir]);
19395
19472
  }, [edgeOffset]);
19396
19473
  var getAutoDirection = React.useCallback(function (dir) {
19397
- return getDefaultValue(isObject$1(useAutoDirection) ? useAutoDirection[dir] : useAutoDirection, defaultAutoDirection);
19474
+ return getDefaultValue(isObject$2(useAutoDirection) ? useAutoDirection[dir] : useAutoDirection, defaultAutoDirection);
19398
19475
  }, [useAutoDirection]);
19399
19476
  React.useEffect(function () {
19400
19477
  setDirectionState(direction);
@@ -19836,12 +19913,13 @@
19836
19913
  var closeTimer = React.useRef(0);
19837
19914
  /** 垂直方向自适应 */
19838
19915
 
19839
- var autoVerticalDirection = getDefaultValue(isObject$1(useAutoDirection) ? useAutoDirection.vertical : useAutoDirection, defaultAutoDirection);
19916
+ var autoVerticalDirection = getDefaultValue(isObject$2(useAutoDirection) ? useAutoDirection.vertical : useAutoDirection, defaultAutoDirection);
19840
19917
 
19841
19918
  var popoverDisappear = function popoverDisappear() {
19842
19919
  onVisibleChange(false);
19843
19920
  window.clearTimeout(closeTimer.current);
19844
19921
  closeTimer.current = 0;
19922
+ mayRemoveEventListenerOnBody();
19845
19923
  };
19846
19924
 
19847
19925
  var throttleHandleVerticalScroll = React.useMemo(function () {
@@ -19861,7 +19939,7 @@
19861
19939
  };
19862
19940
  }, [throttleHandleVerticalScroll, getVerticalScrollContainer, autoVerticalDirection, visibleRef]);
19863
19941
  var mayRemoveEventListenerOnBody = React.useCallback(function () {
19864
- document.body.removeEventListener('click', handleClickBody);
19942
+ document.body.removeEventListener('click', handleClickBody, true);
19865
19943
  document.body.removeEventListener('touchstart', handleTouchBody);
19866
19944
  var el = getVerticalScrollContainer();
19867
19945
 
@@ -19876,7 +19954,6 @@
19876
19954
 
19877
19955
 
19878
19956
  if (!isContains(wrapperRef.current, e.target) && !isContains(((_a = popoverInnerRef.current) === null || _a === void 0 ? void 0 : _a.dom) || null, e.target)) {
19879
- // TODO: 这里仅阻止了react事件,react 18 将不再在document上挂事件,这里的stop会失效
19880
19957
  if (preventBodyClick) {
19881
19958
  e.stopPropagation();
19882
19959
  e.preventDefault();
@@ -19902,13 +19979,13 @@
19902
19979
  var handle = function handle(e) {
19903
19980
  e.stopPropagation();
19904
19981
  e.preventDefault();
19905
- document.body.removeEventListener('click', handle);
19982
+ document.body.removeEventListener('click', handle, true);
19906
19983
  clearTimeout(preventRecentClickTimer);
19907
19984
  };
19908
19985
 
19909
- document.body.addEventListener('click', handle);
19986
+ document.body.addEventListener('click', handle, true);
19910
19987
  preventRecentClickTimer = window.setTimeout(function () {
19911
- document.body.removeEventListener('click', handle);
19988
+ document.body.removeEventListener('click', handle, true);
19912
19989
  }, 500);
19913
19990
  };
19914
19991
 
@@ -19951,7 +20028,7 @@
19951
20028
  var el = getVerticalScrollContainer();
19952
20029
  el && el.addEventListener('scroll', handleScrollBody);
19953
20030
  } else if (clickOtherToClose) {
19954
- document.body.addEventListener('click', handleClickBody);
20031
+ document.body.addEventListener('click', handleClickBody, true);
19955
20032
  }
19956
20033
  };
19957
20034
  /**
@@ -23092,6 +23169,7 @@
23092
23169
 
23093
23170
  var dampRateRef = useLatestRef(dampRate);
23094
23171
  var forbidClick = React.useRef(false);
23172
+ var scrollingRef = React.useRef(null);
23095
23173
 
23096
23174
  var _j = useRefState(false),
23097
23175
  moving = _j[0],
@@ -23106,6 +23184,7 @@
23106
23184
  var prefixCls = React.useContext(GlobalContext).prefixCls;
23107
23185
  var startRef = React.useRef(0);
23108
23186
  var startX = React.useRef(0);
23187
+ var startY = React.useRef(0);
23109
23188
  var slideX = React.useRef(0);
23110
23189
  var isLayer = openStyleType === 'layer';
23111
23190
  var transitionStyle = React.useMemo(function () {
@@ -23116,6 +23195,7 @@
23116
23195
 
23117
23196
  function resetMoveData() {
23118
23197
  startX.current = 0;
23198
+ startY.current = 0;
23119
23199
  slideX.current = 0;
23120
23200
  }
23121
23201
 
@@ -23127,19 +23207,34 @@
23127
23207
  function touchstart(e) {
23128
23208
  startRef.current = offsetRef.current;
23129
23209
  resetMoveData();
23210
+ scrollingRef.current = null;
23130
23211
  startX.current = e.touches[0].pageX;
23212
+ startY.current = e.touches[0].pageY;
23131
23213
  }
23132
23214
 
23133
23215
  function touchmove(e) {
23134
- e.preventDefault();
23135
- slideX.current = e.touches[0].pageX - startX.current;
23216
+ var x = e.changedTouches[0].pageX - startX.current;
23217
+ var y = e.changedTouches[0].pageY - startY.current;
23218
+
23219
+ if (scrollingRef.current === null) {
23220
+ scrollingRef.current = Math.abs(x) < Math.abs(y);
23221
+ }
23222
+
23223
+ if (scrollingRef.current) {
23224
+ setMoving(false);
23225
+ setOffset(0);
23226
+ return;
23227
+ }
23228
+
23229
+ e.cancelable && e.preventDefault();
23230
+ slideX.current = x;
23136
23231
  forbidClick.current = true;
23137
23232
  setMoving(true);
23138
23233
  setOffset(getMenuCurrentWidth(slideX.current + startRef.current, -rightMenuWidthRef.current, leftMenuWidthRef.current));
23139
23234
  }
23140
23235
 
23141
23236
  function touchend() {
23142
- if (movingRef.current) {
23237
+ if (movingRef.current && !scrollingRef.current) {
23143
23238
  var currentMenu = offsetRef.current > 0 ? 'left' : 'right';
23144
23239
  changeMenu(currentMenu);
23145
23240
  setMoving(false);