antd-mobile 5.38.0 → 5.39.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 (134) hide show
  1. package/2x/bundle/antd-mobile.cjs.development.js +278 -237
  2. package/2x/bundle/antd-mobile.cjs.js +7 -7
  3. package/2x/bundle/antd-mobile.es.development.js +279 -238
  4. package/2x/bundle/antd-mobile.es.js +5466 -5430
  5. package/2x/bundle/antd-mobile.umd.development.js +278 -237
  6. package/2x/bundle/antd-mobile.umd.js +7 -7
  7. package/2x/bundle/style.css +17 -2
  8. package/2x/cjs/components/calendar-picker/calendar-picker.d.ts +9 -9
  9. package/2x/cjs/components/calendar-picker-view/calendar-picker-view.d.ts +5 -4
  10. package/2x/cjs/components/calendar-picker-view/calendar-picker-view.js +18 -11
  11. package/2x/cjs/components/date-picker/date-picker-week-utils.js +2 -2
  12. package/2x/cjs/components/ellipsis/ellipsis.css +1 -0
  13. package/2x/cjs/components/ellipsis/ellipsis.d.ts +1 -1
  14. package/2x/cjs/components/ellipsis/ellipsis.js +28 -124
  15. package/2x/cjs/components/ellipsis/useMeasure.d.ts +2 -0
  16. package/2x/cjs/components/ellipsis/useMeasure.js +112 -0
  17. package/2x/cjs/components/ellipsis/~ellipsis.d.ts +15 -0
  18. package/2x/cjs/components/ellipsis/~ellipsis.js +161 -0
  19. package/2x/cjs/components/floating-panel/floating-panel.css +16 -2
  20. package/2x/cjs/components/floating-panel/floating-panel.d.ts +3 -1
  21. package/2x/cjs/components/floating-panel/floating-panel.js +43 -30
  22. package/2x/cjs/components/image-uploader/image-uploader.d.ts +3 -3
  23. package/2x/cjs/components/image-uploader/image-uploader.js +11 -11
  24. package/2x/cjs/components/image-viewer/image-viewer.d.ts +13 -4
  25. package/2x/cjs/components/image-viewer/image-viewer.js +8 -6
  26. package/2x/cjs/components/image-viewer/index.d.ts +4 -1
  27. package/2x/cjs/components/image-viewer/slide.d.ts +5 -1
  28. package/2x/cjs/components/image-viewer/slide.js +10 -5
  29. package/2x/cjs/components/image-viewer/slides.d.ts +4 -1
  30. package/2x/cjs/components/image-viewer/slides.js +14 -12
  31. package/2x/cjs/components/passcode-input/passcode-input.d.ts +7 -5
  32. package/2x/cjs/components/passcode-input/passcode-input.js +7 -6
  33. package/2x/cjs/components/popover/popover.d.ts +2 -2
  34. package/2x/cjs/components/popover/popover.js +11 -11
  35. package/2x/cjs/components/swipe-action/swipe-action.d.ts +3 -1
  36. package/2x/cjs/components/swipe-action/swipe-action.js +25 -23
  37. package/2x/es/components/calendar-picker/calendar-picker.d.ts +9 -9
  38. package/2x/es/components/calendar-picker-view/calendar-picker-view.d.ts +5 -4
  39. package/2x/es/components/calendar-picker-view/calendar-picker-view.js +18 -11
  40. package/2x/es/components/date-picker/date-picker-week-utils.js +2 -2
  41. package/2x/es/components/ellipsis/ellipsis.css +1 -0
  42. package/2x/es/components/ellipsis/ellipsis.d.ts +1 -1
  43. package/2x/es/components/ellipsis/ellipsis.js +28 -122
  44. package/2x/es/components/ellipsis/useMeasure.d.ts +2 -0
  45. package/2x/es/components/ellipsis/useMeasure.js +105 -0
  46. package/2x/es/components/ellipsis/~ellipsis.d.ts +15 -0
  47. package/2x/es/components/ellipsis/~ellipsis.js +151 -0
  48. package/2x/es/components/floating-panel/floating-panel.css +16 -2
  49. package/2x/es/components/floating-panel/floating-panel.d.ts +3 -1
  50. package/2x/es/components/floating-panel/floating-panel.js +31 -19
  51. package/2x/es/components/image-uploader/image-uploader.d.ts +3 -3
  52. package/2x/es/components/image-uploader/image-uploader.js +11 -11
  53. package/2x/es/components/image-viewer/image-viewer.d.ts +13 -4
  54. package/2x/es/components/image-viewer/image-viewer.js +8 -6
  55. package/2x/es/components/image-viewer/index.d.ts +4 -1
  56. package/2x/es/components/image-viewer/slide.d.ts +5 -1
  57. package/2x/es/components/image-viewer/slide.js +11 -6
  58. package/2x/es/components/image-viewer/slides.d.ts +4 -1
  59. package/2x/es/components/image-viewer/slides.js +6 -4
  60. package/2x/es/components/passcode-input/passcode-input.d.ts +7 -5
  61. package/2x/es/components/passcode-input/passcode-input.js +6 -5
  62. package/2x/es/components/popover/popover.d.ts +2 -2
  63. package/2x/es/components/popover/popover.js +10 -10
  64. package/2x/es/components/swipe-action/swipe-action.d.ts +3 -1
  65. package/2x/es/components/swipe-action/swipe-action.js +9 -7
  66. package/2x/package.json +1 -1
  67. package/bundle/antd-mobile.cjs.development.js +278 -237
  68. package/bundle/antd-mobile.cjs.js +7 -7
  69. package/bundle/antd-mobile.compatible.umd.js +1 -1
  70. package/bundle/antd-mobile.es.development.js +279 -238
  71. package/bundle/antd-mobile.es.js +5466 -5430
  72. package/bundle/antd-mobile.umd.development.js +278 -237
  73. package/bundle/antd-mobile.umd.js +7 -7
  74. package/bundle/style.css +1 -1
  75. package/cjs/components/calendar-picker/calendar-picker.d.ts +9 -9
  76. package/cjs/components/calendar-picker-view/calendar-picker-view.d.ts +5 -4
  77. package/cjs/components/calendar-picker-view/calendar-picker-view.js +18 -11
  78. package/cjs/components/date-picker/date-picker-week-utils.js +2 -2
  79. package/cjs/components/ellipsis/ellipsis.css +1 -0
  80. package/cjs/components/ellipsis/ellipsis.d.ts +1 -1
  81. package/cjs/components/ellipsis/ellipsis.js +28 -124
  82. package/cjs/components/ellipsis/useMeasure.d.ts +2 -0
  83. package/cjs/components/ellipsis/useMeasure.js +112 -0
  84. package/cjs/components/ellipsis/~ellipsis.d.ts +15 -0
  85. package/cjs/components/ellipsis/~ellipsis.js +161 -0
  86. package/cjs/components/floating-panel/floating-panel.css +12 -2
  87. package/cjs/components/floating-panel/floating-panel.d.ts +3 -1
  88. package/cjs/components/floating-panel/floating-panel.js +43 -30
  89. package/cjs/components/image-uploader/image-uploader.d.ts +3 -3
  90. package/cjs/components/image-uploader/image-uploader.js +11 -11
  91. package/cjs/components/image-viewer/image-viewer.d.ts +13 -4
  92. package/cjs/components/image-viewer/image-viewer.js +8 -6
  93. package/cjs/components/image-viewer/index.d.ts +4 -1
  94. package/cjs/components/image-viewer/slide.d.ts +5 -1
  95. package/cjs/components/image-viewer/slide.js +10 -5
  96. package/cjs/components/image-viewer/slides.d.ts +4 -1
  97. package/cjs/components/image-viewer/slides.js +14 -12
  98. package/cjs/components/passcode-input/passcode-input.d.ts +7 -5
  99. package/cjs/components/passcode-input/passcode-input.js +7 -6
  100. package/cjs/components/popover/popover.d.ts +2 -2
  101. package/cjs/components/popover/popover.js +11 -11
  102. package/cjs/components/swipe-action/swipe-action.d.ts +3 -1
  103. package/cjs/components/swipe-action/swipe-action.js +25 -23
  104. package/es/components/calendar-picker/calendar-picker.d.ts +9 -9
  105. package/es/components/calendar-picker-view/calendar-picker-view.d.ts +5 -4
  106. package/es/components/calendar-picker-view/calendar-picker-view.js +18 -11
  107. package/es/components/date-picker/date-picker-week-utils.js +2 -2
  108. package/es/components/ellipsis/ellipsis.css +1 -0
  109. package/es/components/ellipsis/ellipsis.d.ts +1 -1
  110. package/es/components/ellipsis/ellipsis.js +28 -122
  111. package/es/components/ellipsis/useMeasure.d.ts +2 -0
  112. package/es/components/ellipsis/useMeasure.js +105 -0
  113. package/es/components/ellipsis/~ellipsis.d.ts +15 -0
  114. package/es/components/ellipsis/~ellipsis.js +151 -0
  115. package/es/components/floating-panel/floating-panel.css +12 -2
  116. package/es/components/floating-panel/floating-panel.d.ts +3 -1
  117. package/es/components/floating-panel/floating-panel.js +31 -19
  118. package/es/components/image-uploader/image-uploader.d.ts +3 -3
  119. package/es/components/image-uploader/image-uploader.js +11 -11
  120. package/es/components/image-viewer/image-viewer.d.ts +13 -4
  121. package/es/components/image-viewer/image-viewer.js +8 -6
  122. package/es/components/image-viewer/index.d.ts +4 -1
  123. package/es/components/image-viewer/slide.d.ts +5 -1
  124. package/es/components/image-viewer/slide.js +11 -6
  125. package/es/components/image-viewer/slides.d.ts +4 -1
  126. package/es/components/image-viewer/slides.js +6 -4
  127. package/es/components/passcode-input/passcode-input.d.ts +7 -5
  128. package/es/components/passcode-input/passcode-input.js +6 -5
  129. package/es/components/popover/popover.d.ts +2 -2
  130. package/es/components/popover/popover.js +10 -10
  131. package/es/components/swipe-action/swipe-action.d.ts +3 -1
  132. package/es/components/swipe-action/swipe-action.js +9 -7
  133. package/package.json +1 -1
  134. package/umd/antd-mobile.js +1 -1
@@ -5,23 +5,23 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.Popover = void 0;
7
7
  var _tslib = require("tslib");
8
- var _react = _interopRequireWildcard(require("react"));
8
+ var _dom = require("@floating-ui/dom");
9
+ var _ahooks = require("ahooks");
9
10
  var _classnames = _interopRequireDefault(require("classnames"));
11
+ var _react = _interopRequireWildcard(require("react"));
12
+ var _convertPx = require("../../utils/convert-px");
13
+ var _nativeProps = require("../../utils/native-props");
14
+ var _renderToContainer = require("../../utils/render-to-container");
15
+ var _shouldRender = require("../../utils/should-render");
10
16
  var _usePropsValue = require("../../utils/use-props-value");
11
17
  var _withDefaultProps = require("../../utils/with-default-props");
12
- var _nativeProps = require("../../utils/native-props");
13
18
  var _withStopPropagation = require("../../utils/with-stop-propagation");
14
19
  var _arrow = require("./arrow");
15
- var _renderToContainer = require("../../utils/render-to-container");
16
- var _dom = require("@floating-ui/dom");
17
- var _wrapper = require("./wrapper");
18
- var _shouldRender = require("../../utils/should-render");
19
- var _ahooks = require("ahooks");
20
20
  var _normalizePlacement = require("./normalize-placement");
21
- var _convertPx = require("../../utils/convert-px");
22
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
21
+ var _wrapper = require("./wrapper");
23
22
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
24
23
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
24
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
25
25
  const classPrefix = `adm-popover`;
26
26
  const defaultProps = {
27
27
  placement: 'top',
@@ -133,11 +133,11 @@ const Popover = (0, _react.forwardRef)((p, ref) => {
133
133
  }, [targetElement, props.trigger]);
134
134
  (0, _react.useEffect)(() => {
135
135
  const floatingElement = floatingRef.current;
136
- if (!targetElement || !floatingElement) return;
136
+ if (!targetElement || !floatingElement || !visible) return;
137
137
  return (0, _dom.autoUpdate)(targetElement, floatingElement, update, {
138
138
  elementResize: typeof ResizeObserver !== 'undefined'
139
139
  });
140
- }, [targetElement]);
140
+ }, [targetElement, visible]);
141
141
  (0, _ahooks.useClickAway)(() => {
142
142
  if (!props.trigger) return;
143
143
  setVisible(false);
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
1
  import type { ReactNode } from 'react';
2
+ import React from 'react';
3
3
  import { NativeProps } from '../../utils/native-props';
4
4
  import { PropagationEvent } from '../../utils/with-stop-propagation';
5
5
  declare type SideType = 'left' | 'right';
@@ -23,6 +23,7 @@ export declare type SwipeActionProps = {
23
23
  children: ReactNode;
24
24
  stopPropagation?: PropagationEvent[];
25
25
  onActionsReveal?: (side: SideType) => void;
26
+ onClose?: () => void;
26
27
  } & NativeProps<'--background'>;
27
28
  export declare const SwipeAction: React.ForwardRefExoticComponent<{
28
29
  rightActions?: Action[] | undefined;
@@ -33,6 +34,7 @@ export declare const SwipeAction: React.ForwardRefExoticComponent<{
33
34
  children: ReactNode;
34
35
  stopPropagation?: PropagationEvent[] | undefined;
35
36
  onActionsReveal?: ((side: SideType) => void) | undefined;
37
+ onClose?: (() => void) | undefined;
36
38
  } & {
37
39
  className?: string | undefined;
38
40
  style?: (React.CSSProperties & Partial<Record<"--background", string>>) | undefined;
@@ -4,14 +4,14 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.SwipeAction = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _withDefaultProps = require("../../utils/with-default-props");
9
7
  var _web = require("@react-spring/web");
10
- var _react2 = require("@use-gesture/react");
11
- var _button = _interopRequireDefault(require("../button"));
12
- var _nearest = require("../../utils/nearest");
8
+ var _react = require("@use-gesture/react");
9
+ var _react2 = _interopRequireWildcard(require("react"));
13
10
  var _nativeProps = require("../../utils/native-props");
11
+ var _nearest = require("../../utils/nearest");
12
+ var _withDefaultProps = require("../../utils/with-default-props");
14
13
  var _withStopPropagation = require("../../utils/with-stop-propagation");
14
+ var _button = _interopRequireDefault(require("../button"));
15
15
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
16
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
17
17
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
@@ -23,11 +23,11 @@ const defaultProps = {
23
23
  closeOnAction: true,
24
24
  stopPropagation: []
25
25
  };
26
- const SwipeAction = (0, _react.forwardRef)((p, ref) => {
26
+ const SwipeAction = (0, _react2.forwardRef)((p, ref) => {
27
27
  const props = (0, _withDefaultProps.mergeProps)(defaultProps, p);
28
- const rootRef = (0, _react.useRef)(null);
29
- const leftRef = (0, _react.useRef)(null);
30
- const rightRef = (0, _react.useRef)(null);
28
+ const rootRef = (0, _react2.useRef)(null);
29
+ const leftRef = (0, _react2.useRef)(null);
30
+ const rightRef = (0, _react2.useRef)(null);
31
31
  function getWidth(ref) {
32
32
  const element = ref.current;
33
33
  if (!element) return 0;
@@ -48,14 +48,14 @@ const SwipeAction = (0, _react.forwardRef)((p, ref) => {
48
48
  friction: 30
49
49
  }
50
50
  }), []);
51
- const draggingRef = (0, _react.useRef)(false);
52
- const dragCancelRef = (0, _react.useRef)(null);
51
+ const draggingRef = (0, _react2.useRef)(false);
52
+ const dragCancelRef = (0, _react2.useRef)(null);
53
53
  function forceCancelDrag() {
54
54
  var _a;
55
55
  (_a = dragCancelRef.current) === null || _a === void 0 ? void 0 : _a.call(dragCancelRef);
56
56
  draggingRef.current = false;
57
57
  }
58
- const bind = (0, _react2.useDrag)(state => {
58
+ const bind = (0, _react.useDrag)(state => {
59
59
  var _a;
60
60
  dragCancelRef.current = state.cancel;
61
61
  if (!state.intentional) return;
@@ -108,13 +108,15 @@ const SwipeAction = (0, _react.forwardRef)((p, ref) => {
108
108
  },
109
109
  triggerAllEvents: true
110
110
  });
111
- function close() {
111
+ const close = () => {
112
+ var _a;
112
113
  api.start({
113
114
  x: 0
114
115
  });
115
116
  forceCancelDrag();
116
- }
117
- (0, _react.useImperativeHandle)(ref, () => ({
117
+ (_a = props.onClose) === null || _a === void 0 ? void 0 : _a.call(props);
118
+ };
119
+ (0, _react2.useImperativeHandle)(ref, () => ({
118
120
  show: (side = 'right') => {
119
121
  var _a;
120
122
  if (side === 'right') {
@@ -130,7 +132,7 @@ const SwipeAction = (0, _react.forwardRef)((p, ref) => {
130
132
  },
131
133
  close
132
134
  }));
133
- (0, _react.useEffect)(() => {
135
+ (0, _react2.useEffect)(() => {
134
136
  if (!props.closeOnTouchOutside) return;
135
137
  function handle(e) {
136
138
  if (x.get() === 0) {
@@ -149,7 +151,7 @@ const SwipeAction = (0, _react.forwardRef)((p, ref) => {
149
151
  function renderAction(action) {
150
152
  var _a, _b;
151
153
  const color = (_a = action.color) !== null && _a !== void 0 ? _a : 'light';
152
- return _react.default.createElement(_button.default, {
154
+ return _react2.default.createElement(_button.default, {
153
155
  key: action.key,
154
156
  className: `${classPrefix}-action-button`,
155
157
  style: {
@@ -165,7 +167,7 @@ const SwipeAction = (0, _react.forwardRef)((p, ref) => {
165
167
  }
166
168
  }, action.text);
167
169
  }
168
- return (0, _nativeProps.withNativeProps)(props, _react.default.createElement("div", Object.assign({
170
+ return (0, _nativeProps.withNativeProps)(props, _react2.default.createElement("div", Object.assign({
169
171
  className: classPrefix
170
172
  }, bind(), {
171
173
  ref: rootRef,
@@ -175,15 +177,15 @@ const SwipeAction = (0, _react.forwardRef)((p, ref) => {
175
177
  e.preventDefault();
176
178
  }
177
179
  }
178
- }), _react.default.createElement(_web.animated.div, {
180
+ }), _react2.default.createElement(_web.animated.div, {
179
181
  className: `${classPrefix}-track`,
180
182
  style: {
181
183
  x
182
184
  }
183
- }, (0, _withStopPropagation.withStopPropagation)(props.stopPropagation, _react.default.createElement("div", {
185
+ }, (0, _withStopPropagation.withStopPropagation)(props.stopPropagation, _react2.default.createElement("div", {
184
186
  className: `${classPrefix}-actions ${classPrefix}-actions-left`,
185
187
  ref: leftRef
186
- }, props.leftActions.map(renderAction))), _react.default.createElement("div", {
188
+ }, props.leftActions.map(renderAction))), _react2.default.createElement("div", {
187
189
  className: `${classPrefix}-content`,
188
190
  onClickCapture: e => {
189
191
  if (x.goal !== 0) {
@@ -192,11 +194,11 @@ const SwipeAction = (0, _react.forwardRef)((p, ref) => {
192
194
  close();
193
195
  }
194
196
  }
195
- }, _react.default.createElement(_web.animated.div, {
197
+ }, _react2.default.createElement(_web.animated.div, {
196
198
  style: {
197
199
  pointerEvents: x.to(v => v !== 0 && x.goal !== 0 ? 'none' : 'auto')
198
200
  }
199
- }, props.children)), (0, _withStopPropagation.withStopPropagation)(props.stopPropagation, _react.default.createElement("div", {
201
+ }, props.children)), (0, _withStopPropagation.withStopPropagation)(props.stopPropagation, _react2.default.createElement("div", {
200
202
  className: `${classPrefix}-actions ${classPrefix}-actions-right`,
201
203
  ref: rightRef
202
204
  }, props.rightActions.map(renderAction))))));
@@ -27,9 +27,9 @@ export declare const CalendarPicker: React.ForwardRefExoticComponent<(({
27
27
  title?: React.ReactNode;
28
28
  confirmText?: string | undefined;
29
29
  weekStartsOn?: "Monday" | "Sunday" | undefined;
30
- renderTop?: ((date: Date) => React.ReactNode) | undefined;
31
- renderDate?: ((date: Date) => React.ReactNode) | undefined;
32
- renderBottom?: ((date: Date) => React.ReactNode) | undefined;
30
+ renderTop?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
31
+ renderDate?: import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
32
+ renderBottom?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
33
33
  allowClear?: boolean | undefined;
34
34
  max?: Date | undefined;
35
35
  min?: Date | undefined;
@@ -61,9 +61,9 @@ export declare const CalendarPicker: React.ForwardRefExoticComponent<(({
61
61
  title?: React.ReactNode;
62
62
  confirmText?: string | undefined;
63
63
  weekStartsOn?: "Monday" | "Sunday" | undefined;
64
- renderTop?: ((date: Date) => React.ReactNode) | undefined;
65
- renderDate?: ((date: Date) => React.ReactNode) | undefined;
66
- renderBottom?: ((date: Date) => React.ReactNode) | undefined;
64
+ renderTop?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
65
+ renderDate?: import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
66
+ renderBottom?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
67
67
  allowClear?: boolean | undefined;
68
68
  max?: Date | undefined;
69
69
  min?: Date | undefined;
@@ -95,9 +95,9 @@ export declare const CalendarPicker: React.ForwardRefExoticComponent<(({
95
95
  title?: React.ReactNode;
96
96
  confirmText?: string | undefined;
97
97
  weekStartsOn?: "Monday" | "Sunday" | undefined;
98
- renderTop?: ((date: Date) => React.ReactNode) | undefined;
99
- renderDate?: ((date: Date) => React.ReactNode) | undefined;
100
- renderBottom?: ((date: Date) => React.ReactNode) | undefined;
98
+ renderTop?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
99
+ renderDate?: import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
100
+ renderBottom?: false | import("../calendar-picker-view/calendar-picker-view").CalendarPickerViewColumRender | undefined;
101
101
  allowClear?: boolean | undefined;
102
102
  max?: Date | undefined;
103
103
  min?: Date | undefined;
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { ReactNode } from 'react';
2
2
  import { NativeProps } from '../../utils/native-props';
3
3
  import { DateRange, Page } from './convert';
4
4
  export declare const Context: React.Context<{
@@ -9,13 +9,14 @@ export declare type CalendarPickerViewRef = {
9
9
  jumpToToday: () => void;
10
10
  getDateRange: () => DateRange;
11
11
  };
12
+ export declare type CalendarPickerViewColumRender = (date: Date) => ReactNode;
12
13
  export declare type CalendarPickerViewProps = {
13
14
  title?: React.ReactNode | false;
14
15
  confirmText?: string;
15
16
  weekStartsOn?: 'Monday' | 'Sunday';
16
- renderTop?: (date: Date) => React.ReactNode;
17
- renderDate?: (date: Date) => React.ReactNode;
18
- renderBottom?: (date: Date) => React.ReactNode;
17
+ renderTop?: CalendarPickerViewColumRender | false;
18
+ renderDate?: CalendarPickerViewColumRender;
19
+ renderBottom?: CalendarPickerViewColumRender | false;
19
20
  allowClear?: boolean;
20
21
  max?: Date;
21
22
  min?: Date;
@@ -135,7 +135,6 @@ export const CalendarPickerView = forwardRef((p, ref) => {
135
135
  })), React.createElement("div", {
136
136
  className: `${classPrefix}-cells`
137
137
  }, presetEmptyCells, Array(monthIterator.daysInMonth()).fill(null).map((_, index) => {
138
- var _a;
139
138
  const d = monthIterator.date(index + 1);
140
139
  let isSelect = false;
141
140
  let isBegin = false;
@@ -155,21 +154,33 @@ export const CalendarPickerView = forwardRef((p, ref) => {
155
154
  const disabled = props.shouldDisableDate ? props.shouldDisableDate(d.toDate()) : maxDay && d.isAfter(maxDay, 'day') || minDay && d.isBefore(minDay, 'day');
156
155
  const renderTop = () => {
157
156
  var _a;
157
+ if (props.renderTop === false) return null;
158
+ const contentWrapper = content => React.createElement("div", {
159
+ className: `${classPrefix}-cell-top`
160
+ }, content);
158
161
  const top = (_a = props.renderTop) === null || _a === void 0 ? void 0 : _a.call(props, d.toDate());
159
162
  if (top) {
160
- return top;
163
+ return contentWrapper(top);
161
164
  }
162
165
  if (props.selectionMode === 'range') {
163
166
  if (isBegin) {
164
- return locale.Calendar.start;
167
+ return contentWrapper(locale.Calendar.start);
165
168
  }
166
169
  if (isEnd) {
167
- return locale.Calendar.end;
170
+ return contentWrapper(locale.Calendar.end);
168
171
  }
169
172
  }
170
173
  if (d.isSame(today, 'day') && !isSelect) {
171
- return locale.Calendar.today;
174
+ return contentWrapper(locale.Calendar.today);
172
175
  }
176
+ return contentWrapper(null);
177
+ };
178
+ const renderBottom = () => {
179
+ var _a;
180
+ if (props.renderBottom === false) return null;
181
+ return React.createElement("div", {
182
+ className: `${classPrefix}-cell-bottom`
183
+ }, (_a = props.renderBottom) === null || _a === void 0 ? void 0 : _a.call(props, d.toDate()));
173
184
  };
174
185
  return React.createElement("div", {
175
186
  key: d.valueOf(),
@@ -219,13 +230,9 @@ export const CalendarPickerView = forwardRef((p, ref) => {
219
230
  }
220
231
  }
221
232
  }
222
- }, React.createElement("div", {
223
- className: `${classPrefix}-cell-top`
224
- }, renderTop()), React.createElement("div", {
233
+ }, renderTop(), React.createElement("div", {
225
234
  className: `${classPrefix}-cell-date`
226
- }, props.renderDate ? props.renderDate(d.toDate()) : d.date()), React.createElement("div", {
227
- className: `${classPrefix}-cell-bottom`
228
- }, (_a = props.renderBottom) === null || _a === void 0 ? void 0 : _a.call(props, d.toDate())));
235
+ }, props.renderDate ? props.renderDate(d.toDate()) : d.date()), renderBottom());
229
236
  }))));
230
237
  monthIterator = monthIterator.add(1, 'month');
231
238
  }
@@ -1,7 +1,7 @@
1
1
  import dayjs from 'dayjs';
2
+ import isLeapYear from 'dayjs/plugin/isLeapYear';
2
3
  import isoWeek from 'dayjs/plugin/isoWeek';
3
4
  import isoWeeksInYear from 'dayjs/plugin/isoWeeksInYear';
4
- import isLeapYear from 'dayjs/plugin/isLeapYear';
5
5
  dayjs.extend(isoWeek);
6
6
  dayjs.extend(isoWeeksInYear);
7
7
  dayjs.extend(isLeapYear);
@@ -84,6 +84,6 @@ export function convertStringArrayToDate(value) {
84
84
  const yearString = (_a = value[0]) !== null && _a !== void 0 ? _a : '1900';
85
85
  const weekString = (_b = value[1]) !== null && _b !== void 0 ? _b : '1';
86
86
  const weekdayString = (_c = value[2]) !== null && _c !== void 0 ? _c : '1';
87
- const day = dayjs().year(parseInt(yearString)).isoWeek(parseInt(weekString)).isoWeekday(parseInt(weekdayString)).hour(0).minute(0).second(0);
87
+ const day = dayjs(`${parseInt(yearString)}-01-01`).isoWeek(parseInt(weekString)).isoWeekday(parseInt(weekdayString)).hour(0).minute(0).second(0);
88
88
  return day.toDate();
89
89
  }
@@ -1,4 +1,5 @@
1
1
  .adm-ellipsis {
2
2
  overflow: hidden;
3
3
  line-height: 1.5;
4
+ word-break: break-word;
4
5
  }
@@ -1,5 +1,5 @@
1
- import React from 'react';
2
1
  import type { FC, ReactNode } from 'react';
2
+ import React from 'react';
3
3
  import { NativeProps } from '../../utils/native-props';
4
4
  import { PropagationEvent } from '../../utils/with-stop-propagation';
5
5
  export declare type EllipsisProps = {
@@ -1,10 +1,9 @@
1
- import React, { useMemo, useRef, useState } from 'react';
2
- import runes from 'runes2';
3
- import { mergeProps } from '../../utils/with-default-props';
1
+ import React from 'react';
4
2
  import { withNativeProps } from '../../utils/native-props';
5
3
  import { useResizeEffect } from '../../utils/use-resize-effect';
6
- import { useIsomorphicLayoutEffect } from 'ahooks';
4
+ import { mergeProps } from '../../utils/with-default-props';
7
5
  import { withStopPropagation } from '../../utils/with-stop-propagation';
6
+ import useMeasure from './useMeasure';
8
7
  const classPrefix = `adm-ellipsis`;
9
8
  const defaultProps = {
10
9
  direction: 'end',
@@ -18,134 +17,41 @@ const defaultProps = {
18
17
  };
19
18
  export const Ellipsis = p => {
20
19
  const props = mergeProps(defaultProps, p);
21
- const rootRef = useRef(null);
22
- const expandElRef = useRef(null);
23
- const collapseElRef = useRef(null);
24
- const [ellipsised, setEllipsised] = useState({});
25
- const [expanded, setExpanded] = useState(props.defaultExpanded);
26
- const [exceeded, setExceeded] = useState(false);
27
- const chars = useMemo(() => runes(props.content), [props.content]);
28
- function getSubString(start, end) {
29
- return chars.slice(start, end).join('');
30
- }
31
- function calcEllipsised() {
32
- var _a, _b;
33
- const root = rootRef.current;
34
- if (!root) return;
35
- const originDisplay = root.style.display;
36
- root.style.display = 'block';
37
- const originStyle = window.getComputedStyle(root);
38
- const container = document.createElement('div');
39
- const styleNames = Array.prototype.slice.apply(originStyle);
40
- styleNames.forEach(name => {
41
- container.style.setProperty(name, originStyle.getPropertyValue(name));
42
- });
43
- root.style.display = originDisplay;
44
- container.style.height = 'auto';
45
- container.style.minHeight = 'auto';
46
- container.style.maxHeight = 'auto';
47
- container.style.textOverflow = 'clip';
48
- container.style.webkitLineClamp = 'unset';
49
- container.style.display = 'block';
50
- const lineHeight = pxToNumber(originStyle.lineHeight);
51
- const maxHeight = Math.floor(lineHeight * (props.rows + 0.5) + pxToNumber(originStyle.paddingTop) + pxToNumber(originStyle.paddingBottom));
52
- container.innerText = props.content;
53
- document.body.appendChild(container);
54
- if (container.offsetHeight <= maxHeight) {
55
- setExceeded(false);
56
- } else {
57
- setExceeded(true);
58
- const end = props.content.length;
59
- const collapseEl = typeof props.collapseText === 'string' ? props.collapseText : (_a = collapseElRef.current) === null || _a === void 0 ? void 0 : _a.innerHTML;
60
- const expandEl = typeof props.expandText === 'string' ? props.expandText : (_b = expandElRef.current) === null || _b === void 0 ? void 0 : _b.innerHTML;
61
- const actionText = expanded ? collapseEl : expandEl;
62
- function check(left, right) {
63
- if (right - left <= 1) {
64
- if (props.direction === 'end') {
65
- return {
66
- leading: getSubString(0, left) + '...'
67
- };
68
- } else {
69
- return {
70
- tailing: '...' + getSubString(right, end)
71
- };
72
- }
73
- }
74
- const middle = Math.round((left + right) / 2);
75
- if (props.direction === 'end') {
76
- container.innerHTML = getSubString(0, middle) + '...' + actionText;
77
- } else {
78
- container.innerHTML = actionText + '...' + getSubString(middle, end);
79
- }
80
- if (container.offsetHeight <= maxHeight) {
81
- if (props.direction === 'end') {
82
- return check(middle, right);
83
- } else {
84
- return check(left, middle);
85
- }
86
- } else {
87
- if (props.direction === 'end') {
88
- return check(left, middle);
89
- } else {
90
- return check(middle, right);
91
- }
92
- }
93
- }
94
- function checkMiddle(leftPart, rightPart) {
95
- if (leftPart[1] - leftPart[0] <= 1 && rightPart[1] - rightPart[0] <= 1) {
96
- return {
97
- leading: getSubString(0, leftPart[0]) + '...',
98
- tailing: '...' + getSubString(rightPart[1], end)
99
- };
100
- }
101
- const leftPartMiddle = Math.floor((leftPart[0] + leftPart[1]) / 2);
102
- const rightPartMiddle = Math.ceil((rightPart[0] + rightPart[1]) / 2);
103
- container.innerHTML = getSubString(0, leftPartMiddle) + '...' + actionText + '...' + getSubString(rightPartMiddle, end);
104
- if (container.offsetHeight <= maxHeight) {
105
- return checkMiddle([leftPartMiddle, leftPart[1]], [rightPart[0], rightPartMiddle]);
106
- } else {
107
- return checkMiddle([leftPart[0], leftPartMiddle], [rightPartMiddle, rightPart[1]]);
108
- }
109
- }
110
- const middle = Math.floor((0 + end) / 2);
111
- const ellipsised = props.direction === 'middle' ? checkMiddle([0, middle], [middle, end]) : check(0, end);
112
- setEllipsised(ellipsised);
113
- }
114
- document.body.removeChild(container);
115
- }
116
- useResizeEffect(calcEllipsised, rootRef);
117
- useIsomorphicLayoutEffect(() => {
118
- calcEllipsised();
119
- }, [props.content, props.direction, props.rows, props.expandText, props.collapseText]);
120
- const expandActionElement = !!props.expandText && withStopPropagation(props.stopPropagationForActionButtons, React.createElement("a", {
121
- ref: expandElRef,
20
+ const {
21
+ content,
22
+ direction,
23
+ rows,
24
+ expandText,
25
+ collapseText,
26
+ stopPropagationForActionButtons,
27
+ onContentClick,
28
+ defaultExpanded
29
+ } = props;
30
+ // ============================ Refs ============================
31
+ const rootRef = React.useRef(null);
32
+ // ========================== Expanded ==========================
33
+ const [expanded, setExpanded] = React.useState(defaultExpanded);
34
+ const expandNode = expandText ? withStopPropagation(stopPropagationForActionButtons, React.createElement("a", {
122
35
  onClick: () => {
123
36
  setExpanded(true);
124
37
  }
125
- }, props.expandText));
126
- const collapseActionElement = !!props.collapseText && withStopPropagation(props.stopPropagationForActionButtons, React.createElement("a", {
127
- ref: collapseElRef,
38
+ }, expandText)) : null;
39
+ const collapseNode = collapseText ? withStopPropagation(stopPropagationForActionButtons, React.createElement("a", {
128
40
  onClick: () => {
129
41
  setExpanded(false);
130
42
  }
131
- }, props.collapseText));
132
- const renderContent = () => {
133
- if (!exceeded) return props.content;
134
- if (expanded) return React.createElement(React.Fragment, null, props.content, collapseActionElement);
135
- return React.createElement(React.Fragment, null, ellipsised.leading, expandActionElement, ellipsised.tailing);
136
- };
43
+ }, collapseText)) : null;
44
+ // ========================== Ellipsis ==========================
45
+ const [measureNodes, forceResize] = useMeasure(rootRef, content, rows, direction, expanded, expandNode, collapseNode);
46
+ useResizeEffect(forceResize, rootRef);
47
+ // =========================== Render ===========================
137
48
  return withNativeProps(props, React.createElement("div", {
138
49
  ref: rootRef,
139
50
  className: classPrefix,
140
51
  onClick: e => {
141
52
  if (e.target === e.currentTarget) {
142
- props.onContentClick(e);
53
+ onContentClick(e);
143
54
  }
144
55
  }
145
- }, renderContent()));
146
- };
147
- function pxToNumber(value) {
148
- if (!value) return 0;
149
- const match = value.match(/^\d*(\.\d*)?/);
150
- return match ? Number(match[0]) : 0;
151
- }
56
+ }, measureNodes));
57
+ };
@@ -0,0 +1,2 @@
1
+ import React from 'react';
2
+ export default function useMeasure(containerRef: React.RefObject<HTMLDivElement>, content: string, rows: number, direction: 'start' | 'end' | 'middle', expanded: boolean, expandNode: React.ReactElement | null, collapseNode: React.ReactElement | null): readonly [React.JSX.Element, () => void];
@@ -0,0 +1,105 @@
1
+ import { useEvent } from 'rc-util';
2
+ import React from 'react';
3
+ import { unstable_batchedUpdates } from 'react-dom';
4
+ import runes from 'runes2';
5
+ const ELLIPSIS_TEXT = '...';
6
+ const measureStyle = {
7
+ visibility: 'hidden',
8
+ whiteSpace: 'inherit',
9
+ lineHeight: 'inherit',
10
+ fontSize: 'inherit'
11
+ };
12
+ export default function useMeasure(containerRef, content, rows, direction, expanded, expandNode, collapseNode) {
13
+ const contentChars = React.useMemo(() => runes(content), [content]);
14
+ const [maxHeight, setMaxHeight] = React.useState(0);
15
+ const [walkingIndexes, setWalkingIndexes] = React.useState([0, 0]);
16
+ const midIndex = Math.ceil((walkingIndexes[0] + walkingIndexes[1]) / 2);
17
+ const [status, setStatus] = React.useState(100 /* STABLE_NO_ELLIPSIS */);
18
+ // ============================ Refs ============================
19
+ const singleRowMeasureRef = React.useRef(null);
20
+ const fullMeasureRef = React.useRef(null);
21
+ const midMeasureRef = React.useRef(null);
22
+ const startMeasure = useEvent(() => {
23
+ // use batch update to avoid async update trigger 2 render
24
+ unstable_batchedUpdates(() => {
25
+ setStatus(1 /* PREPARE */);
26
+ setWalkingIndexes([0, direction === 'middle' ? Math.ceil(contentChars.length / 2) : contentChars.length]);
27
+ });
28
+ });
29
+ // Initialize
30
+ React.useLayoutEffect(() => {
31
+ startMeasure();
32
+ }, [contentChars, rows]);
33
+ // Measure element height
34
+ React.useLayoutEffect(() => {
35
+ var _a, _b;
36
+ if (status === 1 /* PREPARE */) {
37
+ const fullMeasureHeight = ((_a = fullMeasureRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
38
+ const singleRowMeasureHeight = ((_b = singleRowMeasureRef.current) === null || _b === void 0 ? void 0 : _b.offsetHeight) || 0;
39
+ const rowMeasureHeight = singleRowMeasureHeight * (rows + 0.5);
40
+ if (fullMeasureHeight <= rowMeasureHeight) {
41
+ setStatus(100 /* STABLE_NO_ELLIPSIS */);
42
+ } else {
43
+ setMaxHeight(rowMeasureHeight);
44
+ setStatus(2 /* MEASURE_WALKING */);
45
+ }
46
+ }
47
+ }, [status]);
48
+ // Walking measure
49
+ React.useLayoutEffect(() => {
50
+ var _a;
51
+ if (status === 2 /* MEASURE_WALKING */) {
52
+ const diff = walkingIndexes[1] - walkingIndexes[0];
53
+ const midHeight = ((_a = midMeasureRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) || 0;
54
+ if (diff > 1) {
55
+ if (midHeight > maxHeight) {
56
+ setWalkingIndexes([walkingIndexes[0], midIndex]);
57
+ } else {
58
+ setWalkingIndexes([midIndex, walkingIndexes[1]]);
59
+ }
60
+ } else {
61
+ if (midHeight > maxHeight) {
62
+ setWalkingIndexes([walkingIndexes[0], walkingIndexes[0]]);
63
+ } else {
64
+ setWalkingIndexes([walkingIndexes[1], walkingIndexes[1]]);
65
+ }
66
+ setStatus(99 /* STABLE_ELLIPSIS */);
67
+ }
68
+ }
69
+ }, [status, walkingIndexes]);
70
+ // =========================== Render ===========================
71
+ /** Render by cut index */
72
+ const renderContent = index => {
73
+ const prefixContent = contentChars.slice(0, index);
74
+ const suffixContent = contentChars.slice(contentChars.length - index);
75
+ return React.createElement(React.Fragment, null, direction === 'start' && React.createElement(React.Fragment, null, expandNode, ELLIPSIS_TEXT), direction !== 'start' && prefixContent.join(''), direction === 'middle' && React.createElement(React.Fragment, null, ELLIPSIS_TEXT, expandNode, ELLIPSIS_TEXT), direction !== 'end' && suffixContent.join(''), direction === 'end' && React.createElement(React.Fragment, null, ELLIPSIS_TEXT, expandNode));
76
+ };
77
+ const finalContent = React.useMemo(() => {
78
+ if (expanded || status === 100 /* STABLE_NO_ELLIPSIS */) {
79
+ return React.createElement(React.Fragment, {
80
+ key: 'display'
81
+ }, content, status === 99 /* STABLE_ELLIPSIS */ && collapseNode);
82
+ }
83
+ if (status === 99 /* STABLE_ELLIPSIS */) {
84
+ return renderContent(midIndex);
85
+ }
86
+ return null;
87
+ }, [expanded, status, content, collapseNode, midIndex]);
88
+ const allNodes = React.createElement(React.Fragment, null, status === 1 /* PREPARE */ && React.createElement("div", {
89
+ key: 'full',
90
+ "aria-hidden": true,
91
+ ref: fullMeasureRef,
92
+ style: measureStyle
93
+ }, content, expandNode), status === 1 /* PREPARE */ && React.createElement("div", {
94
+ key: 'stable',
95
+ "aria-hidden": true,
96
+ ref: singleRowMeasureRef,
97
+ style: measureStyle
98
+ }, '\u00A0'), status === 2 /* MEASURE_WALKING */ && React.createElement("div", {
99
+ key: 'walking-mid',
100
+ "aria-hidden": true,
101
+ ref: midMeasureRef,
102
+ style: measureStyle
103
+ }, renderContent(midIndex)), finalContent);
104
+ return [allNodes, startMeasure];
105
+ }