antd-mobile 5.33.2 → 5.34.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 (39) hide show
  1. package/2x/bundle/antd-mobile.cjs.development.js +1355 -1611
  2. package/2x/bundle/antd-mobile.cjs.js +7 -15
  3. package/2x/bundle/antd-mobile.es.development.js +350 -606
  4. package/2x/bundle/antd-mobile.es.js +8349 -8537
  5. package/2x/bundle/antd-mobile.umd.development.js +1355 -1611
  6. package/2x/bundle/antd-mobile.umd.js +7 -15
  7. package/2x/bundle/style.css +2 -1
  8. package/2x/cjs/components/stepper/stepper.js +2 -2
  9. package/2x/cjs/components/swiper/index.d.ts +3 -2
  10. package/2x/cjs/components/swiper/swiper.css +2 -1
  11. package/2x/cjs/components/swiper/swiper.d.ts +18 -4
  12. package/2x/cjs/components/swiper/swiper.js +98 -53
  13. package/2x/es/components/stepper/stepper.js +1 -1
  14. package/2x/es/components/swiper/index.d.ts +3 -2
  15. package/2x/es/components/swiper/swiper.css +2 -1
  16. package/2x/es/components/swiper/swiper.d.ts +18 -4
  17. package/2x/es/components/swiper/swiper.js +98 -53
  18. package/2x/package.json +2 -2
  19. package/bundle/antd-mobile.cjs.development.js +1355 -1611
  20. package/bundle/antd-mobile.cjs.js +7 -15
  21. package/bundle/antd-mobile.compatible.umd.js +1 -1
  22. package/bundle/antd-mobile.es.development.js +350 -606
  23. package/bundle/antd-mobile.es.js +8349 -8537
  24. package/bundle/antd-mobile.umd.development.js +1355 -1611
  25. package/bundle/antd-mobile.umd.js +7 -15
  26. package/bundle/style.css +1 -1
  27. package/cjs/components/stepper/stepper.js +2 -2
  28. package/cjs/components/swiper/index.d.ts +3 -2
  29. package/cjs/components/swiper/swiper.css +2 -1
  30. package/cjs/components/swiper/swiper.d.ts +18 -4
  31. package/cjs/components/swiper/swiper.js +98 -53
  32. package/es/components/stepper/stepper.js +1 -1
  33. package/es/components/swiper/index.d.ts +3 -2
  34. package/es/components/swiper/swiper.css +2 -1
  35. package/es/components/swiper/swiper.d.ts +18 -4
  36. package/es/components/swiper/swiper.js +98 -53
  37. package/package.json +2 -2
  38. package/umd/antd-mobile.js +1 -1
  39. package/umd/antd-mobile.js.LICENSE.txt +0 -9
@@ -34,37 +34,52 @@ const defaultProps = {
34
34
  let currentUid;
35
35
  export const Swiper = forwardRef(staged((p, ref) => {
36
36
  const props = mergeProps(defaultProps, p);
37
+ const {
38
+ direction,
39
+ total,
40
+ children,
41
+ indicator
42
+ } = props;
37
43
  const [uid] = useState({});
38
44
  const timeoutRef = useRef(null);
39
- const isVertical = props.direction === 'vertical';
45
+ const isVertical = direction === 'vertical';
40
46
  const slideRatio = props.slideSize / 100;
41
47
  const offsetRatio = props.trackOffset / 100;
42
48
  const {
43
49
  validChildren,
44
- count
50
+ count,
51
+ renderChildren
45
52
  } = useMemo(() => {
46
53
  let count = 0;
47
- const validChildren = React.Children.map(props.children, child => {
48
- if (!React.isValidElement(child)) return null;
49
- if (child.type !== SwiperItem) {
50
- devWarning('Swiper', 'The children of `Swiper` must be `Swiper.Item` components.');
51
- return null;
52
- }
53
- count++;
54
- return child;
55
- });
54
+ let renderChildren = undefined;
55
+ let validChildren = undefined;
56
+ if (typeof children === 'function') {
57
+ renderChildren = children;
58
+ } else {
59
+ validChildren = React.Children.map(children, child => {
60
+ if (!React.isValidElement(child)) return null;
61
+ if (child.type !== SwiperItem) {
62
+ devWarning('Swiper', 'The children of `Swiper` must be `Swiper.Item` components.');
63
+ return null;
64
+ }
65
+ count++;
66
+ return child;
67
+ });
68
+ }
56
69
  return {
70
+ renderChildren,
57
71
  validChildren,
58
72
  count
59
73
  };
60
- }, [props.children]);
61
- if (count === 0 || !validChildren) {
74
+ }, [children]);
75
+ const mergedTotal = total !== null && total !== void 0 ? total : count;
76
+ if (mergedTotal === 0 || !validChildren && !renderChildren) {
62
77
  devWarning('Swiper', '`Swiper` needs at least one child.');
63
78
  return null;
64
79
  }
65
80
  return () => {
66
81
  let loop = props.loop;
67
- if (slideRatio * (count - 1) < 1) {
82
+ if (slideRatio * (mergedTotal - 1) < 1) {
68
83
  loop = false;
69
84
  }
70
85
  const trackRef = useRef(null);
@@ -78,7 +93,7 @@ export const Swiper = forwardRef(staged((p, ref) => {
78
93
  const [dragging, setDragging, draggingRef] = useRefState(false);
79
94
  function boundIndex(current) {
80
95
  let min = 0;
81
- let max = count - 1;
96
+ let max = mergedTotal - 1;
82
97
  if (props.stuckAtBoundary) {
83
98
  min += offsetRatio / slideRatio;
84
99
  max -= (1 - slideRatio - offsetRatio) / slideRatio;
@@ -97,7 +112,7 @@ export const Swiper = forwardRef(staged((p, ref) => {
97
112
  if (draggingRef.current) return;
98
113
  if (!loop) return;
99
114
  const rawX = position.get();
100
- const totalWidth = 100 * count;
115
+ const totalWidth = 100 * mergedTotal;
101
116
  const standardPosition = modulus(rawX, totalWidth);
102
117
  if (standardPosition === rawX) return;
103
118
  api.start({
@@ -105,7 +120,7 @@ export const Swiper = forwardRef(staged((p, ref) => {
105
120
  immediate: true
106
121
  });
107
122
  }
108
- }), [count]);
123
+ }), [mergedTotal]);
109
124
  const dragCancelRef = useRef(null);
110
125
  function forceCancelDrag() {
111
126
  var _a;
@@ -152,7 +167,7 @@ export const Swiper = forwardRef(staged((p, ref) => {
152
167
  if (loop) return {};
153
168
  const slidePixels = getSlidePixels();
154
169
  const lowerBound = boundIndex(0) * slidePixels;
155
- const upperBound = boundIndex(count - 1) * slidePixels;
170
+ const upperBound = boundIndex(mergedTotal - 1) * slidePixels;
156
171
  return isVertical ? {
157
172
  top: lowerBound,
158
173
  bottom: upperBound
@@ -171,7 +186,7 @@ export const Swiper = forwardRef(staged((p, ref) => {
171
186
  function swipeTo(index, immediate = false) {
172
187
  var _a;
173
188
  const roundedIndex = Math.round(index);
174
- const targetIndex = loop ? modulus(roundedIndex, count) : bound(roundedIndex, 0, count - 1);
189
+ const targetIndex = loop ? modulus(roundedIndex, mergedTotal) : bound(roundedIndex, 0, mergedTotal - 1);
175
190
  if (targetIndex !== getCurrent()) {
176
191
  (_a = props.onIndexChange) === null || _a === void 0 ? void 0 : _a.call(props, targetIndex);
177
192
  }
@@ -193,7 +208,7 @@ export const Swiper = forwardRef(staged((p, ref) => {
193
208
  swipePrev
194
209
  }));
195
210
  useIsomorphicLayoutEffect(() => {
196
- const maxIndex = validChildren.length - 1;
211
+ const maxIndex = mergedTotal - 1;
197
212
  if (current > maxIndex) {
198
213
  swipeTo(maxIndex, true);
199
214
  }
@@ -214,43 +229,67 @@ export const Swiper = forwardRef(staged((p, ref) => {
214
229
  return () => {
215
230
  if (timeoutRef.current) window.clearTimeout(timeoutRef.current);
216
231
  };
217
- }, [autoplay, autoplayInterval, dragging, count]);
232
+ }, [autoplay, autoplayInterval, dragging, mergedTotal]);
233
+ // ============================== Render ==============================
234
+ // Render Item
235
+ function renderItem(index, child) {
236
+ let itemStyle = {};
237
+ if (loop) {
238
+ itemStyle = {
239
+ [isVertical ? 'y' : 'x']: position.to(position => {
240
+ let finalPosition = -position + index * 100;
241
+ const totalWidth = mergedTotal * 100;
242
+ const flagWidth = totalWidth / 2;
243
+ finalPosition = modulus(finalPosition + flagWidth, totalWidth) - flagWidth;
244
+ return `${finalPosition}%`;
245
+ }),
246
+ [isVertical ? 'top' : 'left']: `-${index * 100}%`
247
+ };
248
+ }
249
+ return React.createElement(animated.div, {
250
+ className: classNames(`${classPrefix}-slide`, {
251
+ [`${classPrefix}-slide-active`]: current === index
252
+ }),
253
+ style: itemStyle,
254
+ key: index
255
+ }, child);
256
+ }
257
+ function renderItems() {
258
+ if (renderChildren && total) {
259
+ const offsetCount = 2;
260
+ const startIndex = Math.max(current - offsetCount, 0);
261
+ const endIndex = Math.min(current + offsetCount, total - 1);
262
+ const items = [];
263
+ for (let index = startIndex; index <= endIndex; index += 1) {
264
+ items.push(renderItem(index, renderChildren(index)));
265
+ }
266
+ return React.createElement(React.Fragment, null, React.createElement("div", {
267
+ className: `${classPrefix}-slide-placeholder`,
268
+ style: {
269
+ width: `${startIndex * 100}%`
270
+ }
271
+ }), items);
272
+ }
273
+ return React.Children.map(validChildren, (child, index) => {
274
+ return renderItem(index, child);
275
+ });
276
+ }
277
+ // Render Track Inner
218
278
  function renderTrackInner() {
219
279
  if (loop) {
220
280
  return React.createElement("div", {
221
281
  className: `${classPrefix}-track-inner`
222
- }, React.Children.map(validChildren, (child, index) => {
223
- return React.createElement(animated.div, {
224
- className: classNames(`${classPrefix}-slide`, {
225
- [`${classPrefix}-slide-active`]: current === index
226
- }),
227
- style: {
228
- [isVertical ? 'y' : 'x']: position.to(position => {
229
- let finalPosition = -position + index * 100;
230
- const totalWidth = count * 100;
231
- const flagWidth = totalWidth / 2;
232
- finalPosition = modulus(finalPosition + flagWidth, totalWidth) - flagWidth;
233
- return `${finalPosition}%`;
234
- }),
235
- [isVertical ? 'top' : 'left']: `-${index * 100}%`
236
- }
237
- }, child);
238
- }));
282
+ }, renderItems());
239
283
  } else {
240
284
  return React.createElement(animated.div, {
241
285
  className: `${classPrefix}-track-inner`,
242
286
  style: {
243
287
  [isVertical ? 'y' : 'x']: position.to(position => `${-position}%`)
244
288
  }
245
- }, React.Children.map(validChildren, (child, index) => {
246
- return React.createElement("div", {
247
- className: classNames(`${classPrefix}-slide`, {
248
- [`${classPrefix}-slide-active`]: current === index
249
- })
250
- }, child);
251
- }));
289
+ }, renderItems());
252
290
  }
253
291
  }
292
+ // Render
254
293
  const style = {
255
294
  '--slide-size': `${props.slideSize}%`,
256
295
  '--track-offset': `${props.trackOffset}%`
@@ -264,8 +303,20 @@ export const Swiper = forwardRef(staged((p, ref) => {
264
303
  };
265
304
  }
266
305
  const mergedProps = mergeFuncProps(dragProps, stopPropagationProps);
306
+ let indicatorNode = null;
307
+ if (typeof indicator === 'function') {
308
+ indicatorNode = indicator(mergedTotal, current);
309
+ } else if (indicator !== false) {
310
+ indicatorNode = React.createElement("div", {
311
+ className: `${classPrefix}-indicator`
312
+ }, React.createElement(PageIndicator, Object.assign({}, props.indicatorProps, {
313
+ total: mergedTotal,
314
+ current: current,
315
+ direction: direction
316
+ })));
317
+ }
267
318
  return withNativeProps(props, React.createElement("div", {
268
- className: classNames(classPrefix, `${classPrefix}-${props.direction}`),
319
+ className: classNames(classPrefix, `${classPrefix}-${direction}`),
269
320
  style: style
270
321
  }, React.createElement("div", Object.assign({
271
322
  ref: trackRef,
@@ -278,13 +329,7 @@ export const Swiper = forwardRef(staged((p, ref) => {
278
329
  }
279
330
  forceCancelDrag();
280
331
  }
281
- }, mergedProps), renderTrackInner()), props.indicator === undefined ? React.createElement("div", {
282
- className: `${classPrefix}-indicator`
283
- }, React.createElement(PageIndicator, Object.assign({}, props.indicatorProps, {
284
- total: count,
285
- current: current,
286
- direction: props.direction
287
- }))) : props.indicator(count, current)));
332
+ }, mergedProps), renderTrackInner()), indicatorNode));
288
333
  };
289
334
  }));
290
335
  function modulus(value, division) {
package/2x/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "antd-mobile",
3
- "version": "5.33.2",
3
+ "version": "5.34.0",
4
4
  "license": "MIT",
5
5
  "dependencies": {
6
6
  "@floating-ui/dom": "^1.4.2",
@@ -14,7 +14,7 @@
14
14
  "dayjs": "^1.11.7",
15
15
  "lodash": "^4.17.21",
16
16
  "rc-field-form": "~1.27.4",
17
- "rc-util": "^5.30.0",
17
+ "rc-util": "^5.38.1",
18
18
  "react-is": "^18.2.0",
19
19
  "runes2": "^1.1.2",
20
20
  "staged-components": "^1.1.3",