@nutui/nutui-react 2.5.2 → 2.6.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 (40) hide show
  1. package/CHANGELOG.md +19 -5
  2. package/dist/esm/Form/style/style.css +1 -1
  3. package/dist/esm/Image.js +1 -1
  4. package/dist/esm/ImagePreview/style/style.css +1 -1
  5. package/dist/esm/ImagePreview.js +16 -20
  6. package/dist/esm/Indicator.js +25 -1
  7. package/dist/esm/SideNavBar.js +1 -1
  8. package/dist/esm/SubSideNavBar.js +1 -1
  9. package/dist/esm/Swiper/style/index.js +0 -1
  10. package/dist/esm/Swiper/style/style.css +1 -1
  11. package/dist/esm/Swiper.js +273 -306
  12. package/dist/esm/SwiperItem.js +6 -18
  13. package/dist/esm/context4.js +16 -2
  14. package/dist/esm/use-touch.js +13 -3
  15. package/dist/locales/base.js +1 -1
  16. package/dist/locales/en-US.js +1 -1
  17. package/dist/locales/id-ID.js +1 -1
  18. package/dist/locales/tr-TR.js +1 -1
  19. package/dist/locales/zh-CN.js +1 -1
  20. package/dist/locales/zh-TW.js +1 -1
  21. package/dist/locales/zh-UG.js +1 -1
  22. package/dist/nutui.react.es.js +404 -396
  23. package/dist/nutui.react.umd.js +404 -396
  24. package/dist/packages/form/form.scss +0 -3
  25. package/dist/packages/swiper/swiper.scss +30 -16
  26. package/dist/style.css +1 -1
  27. package/dist/style.mjs +1 -1
  28. package/dist/types/packages/input/input.taro.d.ts +1 -1
  29. package/dist/types/packages/swiper/effects/default.d.ts +11 -0
  30. package/dist/types/packages/swiper/effects/focus.d.ts +21 -0
  31. package/dist/types/packages/swiper/index.d.ts +4 -2
  32. package/dist/types/packages/swiper/swiper.d.ts +24 -43
  33. package/dist/types/packages/swiper/types.d.ts +6 -0
  34. package/dist/types/packages/swiperitem/swiperitem.d.ts +8 -4
  35. package/dist/types/utils/use-ref-state.d.ts +3 -0
  36. package/dist/types/utils/use-touch.d.ts +3 -1
  37. package/package.json +1 -1
  38. package/dist/esm/context5.js +0 -19
  39. package/dist/esm/indicator2.js +0 -28
  40. package/dist/types/packages/picker/doc.en.d.ts +0 -145
@@ -1,333 +1,273 @@
1
- import { _ as __rest } from "./tslib.es6.js";
2
- import React__default, { useRef, useState, useMemo, useEffect } from "react";
1
+ import React__default, { useRef, useState, useEffect, useMemo } from "react";
2
+ import { useDrag } from "@use-gesture/react";
3
+ import { animated, useSpring } from "@react-spring/web";
3
4
  import classNames from "classnames";
4
- import { D as DataContext } from "./context4.js";
5
- import { g as getRect } from "./use-client-rect.js";
6
- import { I as Indicator } from "./indicator2.js";
7
- import { u as useTouch } from "./use-touch.js";
8
- import { r as requestAniFrame } from "./raf.js";
9
- import { useRtl } from "./ConfigProvider.js";
5
+ import Indicator__default from "./Indicator.js";
10
6
  import SwiperItem__default from "./SwiperItem.js";
7
+ const getRefValue = (ref) => {
8
+ return ref.current;
9
+ };
10
+ const useRefState = (param) => {
11
+ const ref = useRef(param);
12
+ const [, setState] = useState(param);
13
+ const updateState = (p) => {
14
+ ref.current = p;
15
+ setState(p);
16
+ };
17
+ return [ref, updateState];
18
+ };
19
+ const getPerSlidePosition$1 = (index, position, loop, count) => {
20
+ const currentPosition = index * 100 + position;
21
+ if (loop) {
22
+ const cycle = count * 100;
23
+ const shift = cycle / 2;
24
+ const nextPosition = (currentPosition + shift) % cycle;
25
+ const shiftedPosition = (nextPosition < 0 ? nextPosition + cycle : nextPosition) - shift;
26
+ return `${shiftedPosition}%`;
27
+ }
28
+ return `${currentPosition}%`;
29
+ };
30
+ const defaultEffect = (args) => {
31
+ return React__default.Children.map(args.children, (child, index) => {
32
+ const { isVertical, getSpringsAxis, loop, count } = args;
33
+ return React__default.createElement(animated.div, { className: "nut-swiper-slide", style: {
34
+ [isVertical ? "y" : "x"]: getSpringsAxis().to((position) => {
35
+ return getPerSlidePosition$1(index, position, loop, count);
36
+ }),
37
+ [isVertical ? "top" : "left"]: `-${index * 100}%`
38
+ } }, child);
39
+ });
40
+ };
41
+ const getPerSlidePosition = (index, position, loop, count) => {
42
+ const currentPosition = index * 100 + position;
43
+ if (loop) {
44
+ const cycle = count * 100;
45
+ const shift = cycle / 2;
46
+ const nextPosition = (currentPosition + shift) % cycle;
47
+ const shiftedPosition = (nextPosition < 0 ? nextPosition + cycle : nextPosition) - shift;
48
+ return `${shiftedPosition}%`;
49
+ }
50
+ return `${currentPosition}%`;
51
+ };
52
+ const focusEffect = (args) => {
53
+ return React__default.Children.map(args.children, (child, index) => {
54
+ const { isVertical, springs, transforms, loop, count, swiperDirection, dragging, current, effect } = args;
55
+ return React__default.createElement(animated.div, { className: "nut-swiper-slide", style: {
56
+ [isVertical ? "y" : "x"]: springs[isVertical ? "y" : "x"].to((position) => {
57
+ return getPerSlidePosition(index, position, loop, count);
58
+ }),
59
+ [isVertical ? "top" : "left"]: `-${index * 100}%`,
60
+ scale: springs.s.to((ss) => {
61
+ const scales = getRefValue(transforms);
62
+ if (!scales)
63
+ return 1;
64
+ const scale = scales[index];
65
+ const currentRefValue = getRefValue(current);
66
+ if (dragging === false)
67
+ ss = 0;
68
+ const ps = ss * scale;
69
+ if (index === currentRefValue) {
70
+ return Math.max(scale - ps, effect.scale);
71
+ }
72
+ if (index === currentRefValue + swiperDirection.current) {
73
+ return Math.min(scale + ps, 1);
74
+ }
75
+ return scale;
76
+ })
77
+ } }, child);
78
+ });
79
+ };
80
+ const useList = (effect, count, current) => {
81
+ const [transforms, setTransforms] = useRefState([]);
82
+ useEffect(() => {
83
+ setTransforms(Array.from({ length: count }).fill(1).map((scale, index) => index !== getRefValue(current) ? scale * (effect ? effect.scale : 1) : scale));
84
+ }, [count]);
85
+ return [transforms, setTransforms];
86
+ };
87
+ const updateTransform = (transforms, setTransforms, effect, page) => {
88
+ setTransforms(getRefValue(transforms).map((s, index) => (
89
+ // eslint-disable-next-line no-nested-ternary
90
+ page === index ? 1 : effect ? effect.scale : 1
91
+ )));
92
+ };
11
93
  const defaultProps = {
12
- duration: 500,
13
- defaultValue: 0,
14
- autoPlay: 0,
15
94
  direction: "horizontal",
16
95
  indicator: false,
17
96
  loop: false,
97
+ duration: 3e3,
98
+ autoPlay: false,
99
+ defaultValue: 0,
18
100
  touchable: true,
19
- preventDefault: true,
20
- stopPropagation: true,
21
- center: false,
22
- className: ""
101
+ effect: void 0
23
102
  };
24
103
  const Swiper = React__default.forwardRef((props, ref) => {
25
- const rtl = useRtl();
26
- const mergedProps = Object.assign(Object.assign({}, defaultProps), props);
27
- const { children, direction, className, onChange, defaultValue, indicator, touchable, preventDefault, stopPropagation, autoPlay, center } = mergedProps, rest = __rest(mergedProps, ["children", "direction", "className", "onChange", "defaultValue", "indicator", "touchable", "preventDefault", "stopPropagation", "autoPlay", "center"]);
28
- const container = useRef(null);
29
- const innerRef = useRef(null);
30
- const swiperRef = useRef({
31
- moving: false,
32
- autoplayTimer: null,
33
- width: 0,
34
- height: 0,
35
- offset: 0,
36
- size: 0
37
- });
38
- const touch = useTouch();
104
+ const classPrefix = "nut-swiper";
105
+ const { children, direction, indicator, loop, effect, autoPlay, touchable, defaultValue, duration, style, className } = Object.assign(Object.assign({}, defaultProps), props);
39
106
  const isVertical = direction === "vertical";
40
- const [rect, setRect] = useState(null);
41
- let [active, setActive] = useState(0);
42
- const [width, setWidth] = useState(0);
43
- const [height, setHeight] = useState(0);
44
- const [offset, setOffset] = useState(0);
45
- const [childOffset, setChildOffset] = useState([]);
46
- const [ready, setReady] = useState(false);
47
- let size = isVertical ? height : width;
48
- const { swiperItems, swiperItemCount } = useMemo(() => {
49
- let count = 0;
50
- const swiperItems2 = React__default.Children.map(props.children, (child) => {
51
- if (!React__default.isValidElement(child))
52
- return null;
53
- count++;
54
- return child;
107
+ const count = useMemo(() => {
108
+ let c = 0;
109
+ React__default.Children.map(children, (child, index) => {
110
+ c += 1;
55
111
  });
56
- return {
57
- swiperItems: swiperItems2,
58
- swiperItemCount: count
59
- };
60
- }, [props.children]);
61
- let trackSize = swiperItemCount * Number(size);
62
- const parent = {
63
- propSwiper: mergedProps,
64
- size
65
- };
66
- const minOffset = (() => {
67
- if (rect) {
68
- const base = isVertical ? rect.height : rect.width;
69
- return base - Number(size) * swiperItemCount;
112
+ return c;
113
+ }, [children]);
114
+ const getSlideSize = () => {
115
+ if (props.slideSize)
116
+ return props.slideSize;
117
+ if (stageRef.current) {
118
+ if (isVertical)
119
+ return stageRef.current.offsetHeight;
120
+ return stageRef.current.offsetWidth;
70
121
  }
71
122
  return 0;
72
- })();
73
- const stopAutoPlay = () => {
74
- clearTimeout(swiperRef.current.autoplayTimer);
75
- swiperRef.current.autoplayTimer = null;
76
123
  };
77
- const startPlay = () => {
78
- if (Number(mergedProps.autoPlay) <= 0 || swiperItemCount <= 1)
79
- return;
80
- stopAutoPlay();
81
- swiperRef.current.autoplayTimer = setTimeout(() => {
82
- next();
83
- startPlay();
84
- }, Number(mergedProps.autoPlay));
124
+ const getSwiperSize = () => {
125
+ if (swiperRef.current) {
126
+ if (isVertical)
127
+ return swiperRef.current.offsetHeight;
128
+ return swiperRef.current.offsetWidth;
129
+ }
130
+ return 0;
85
131
  };
86
- const resetPosition = () => {
87
- swiperRef.current.moving = true;
88
- if (active <= -1) {
89
- move({ pace: swiperItemCount });
132
+ const bound = (v, min, max) => {
133
+ if (min !== void 0) {
134
+ v = Math.max(v, min);
90
135
  }
91
- if (active >= swiperItemCount) {
92
- move({ pace: -swiperItemCount });
136
+ if (max !== void 0) {
137
+ v = Math.min(v, max);
93
138
  }
139
+ return v;
94
140
  };
95
- const prev = () => {
96
- resetPosition();
97
- touch.reset();
98
- requestAniFrame(() => {
99
- requestAniFrame(() => {
100
- swiperRef.current.moving = false;
101
- move({
102
- pace: -1,
103
- isEmit: true
104
- });
105
- });
141
+ const timeoutRef = useRef(null);
142
+ const [dragging, setDragging] = useState(false);
143
+ const [current, setCurrent] = useRefState(defaultValue);
144
+ const stageRef = useRef(null);
145
+ const swiperRef = useRef(null);
146
+ const [springs, api] = useSpring(() => ({
147
+ x: !isVertical ? current.current * 100 * -1 : 0,
148
+ y: isVertical ? current.current * 100 * -1 : 0,
149
+ s: 0,
150
+ reset: () => {
151
+ },
152
+ config: { tension: 200, friction: 30 }
153
+ }));
154
+ useEffect(() => {
155
+ api.start({
156
+ [isVertical ? "y" : "x"]: boundIndex(current.current) * -1 * 100,
157
+ immediate: true
106
158
  });
159
+ }, [swiperRef.current]);
160
+ const swiperDirection = useRef(1);
161
+ const [transforms, setTransforms] = useList(effect, count, current);
162
+ const runTimeSwiper = () => {
163
+ const durationNumber = typeof duration === "string" ? parseInt(duration) : duration;
164
+ const d = typeof autoPlay === "number" ? autoPlay : durationNumber;
165
+ timeoutRef.current = window.setTimeout(() => {
166
+ next();
167
+ runTimeSwiper();
168
+ }, d);
107
169
  };
108
- const next = () => {
109
- resetPosition();
110
- touch.reset();
111
- requestAniFrame(() => {
112
- requestAniFrame(() => {
113
- swiperRef.current.moving = false;
114
- move({
115
- pace: 1,
116
- isEmit: true
117
- });
118
- });
170
+ useEffect(() => {
171
+ if (!autoPlay || dragging)
172
+ return;
173
+ runTimeSwiper();
174
+ return () => {
175
+ if (timeoutRef.current)
176
+ window.clearTimeout(timeoutRef.current);
177
+ };
178
+ }, [autoPlay, duration, dragging, count]);
179
+ function boundIndex(current2) {
180
+ const min = 0;
181
+ const max = count - 1;
182
+ if (current2 === max && !loop && props.slideSize) {
183
+ const slideSize = props.slideSize;
184
+ const swiperSize = getSwiperSize();
185
+ const ratio = (swiperSize - slideSize) / slideSize;
186
+ return bound(current2, min, max - ratio);
187
+ }
188
+ return current2;
189
+ }
190
+ const to = (index, immediate = false) => {
191
+ var _a;
192
+ let targetIndex = bound(index, 0, count - 1);
193
+ if (loop) {
194
+ const cycleIndex = index % count;
195
+ targetIndex = cycleIndex < 0 ? cycleIndex + count : cycleIndex;
196
+ }
197
+ setCurrent(targetIndex);
198
+ (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, targetIndex);
199
+ if (effect) {
200
+ updateTransform(transforms, setTransforms, effect, targetIndex);
201
+ }
202
+ api.start({
203
+ // 这里需要统一成百分比
204
+ [isVertical ? "y" : "x"]: (loop ? -index : boundIndex(targetIndex) * -1) * 100,
205
+ s: 0,
206
+ immediate
119
207
  });
120
208
  };
121
- const to = (index) => {
122
- resetPosition();
123
- touch.reset();
124
- requestAniFrame(() => {
125
- requestAniFrame(() => {
126
- swiperRef.current.moving = false;
127
- let targetIndex;
128
- if (props.loop && swiperItemCount === index) {
129
- targetIndex = active === 0 ? 0 : index;
130
- } else {
131
- targetIndex = index % swiperItemCount;
132
- }
133
- move({
134
- pace: targetIndex - active,
135
- isEmit: true
136
- });
137
- });
138
- });
209
+ const getSpringsAxis = () => {
210
+ return springs[isVertical ? "y" : "x"];
139
211
  };
140
- const resize = () => {
141
- init(active);
212
+ const next = () => {
213
+ to(Math.round(-getSpringsAxis().get() / 100) + 1);
142
214
  };
143
- const move = ({ pace = 0, offset: offset2 = 0, isEmit = false, movingStatus = false }) => {
144
- var _a;
145
- if (swiperItemCount <= 1)
146
- return;
147
- const targetActive = getActive(pace);
148
- const targetOffset = getOffset(targetActive, offset2);
149
- if (props.loop) {
150
- if (Array.isArray(children) && children[0] && targetOffset !== minOffset) {
151
- const rightBound = targetOffset < minOffset;
152
- childOffset[0] = rightBound ? trackSize : 0;
153
- }
154
- if (Array.isArray(children) && children[swiperItemCount - 1] && targetOffset !== 0) {
155
- const leftBound = targetOffset > 0;
156
- childOffset[swiperItemCount - 1] = leftBound ? -trackSize : 0;
157
- }
158
- setChildOffset(childOffset);
159
- }
160
- if (isEmit && active !== targetActive) {
161
- (_a = props.onChange) === null || _a === void 0 ? void 0 : _a.call(props, (targetActive + swiperItemCount) % swiperItemCount);
162
- }
163
- active = targetActive;
164
- setActive(targetActive);
165
- setOffset(targetOffset);
166
- getStyle(targetOffset);
215
+ const prev = () => {
216
+ to(Math.round(-getSpringsAxis().get() / 100) - 1);
167
217
  };
168
218
  React__default.useImperativeHandle(ref, () => ({
169
219
  to,
170
220
  next,
171
- prev,
172
- resize
221
+ prev
173
222
  }));
174
- const getActive = (pace) => {
175
- if (pace) {
176
- const _active = active + pace;
177
- if (props.loop) {
178
- return range(_active, -1, swiperItemCount);
179
- }
180
- return range(_active, 0, swiperItemCount - 1);
181
- }
182
- return active;
183
- };
184
- const getOffset = (active2, offset2 = 0) => {
185
- let currentPosition = active2 * Number(size);
186
- if (!props.loop) {
187
- currentPosition = Math.min(currentPosition, -minOffset);
188
- }
189
- let targetOffset = offset2 - currentPosition;
190
- if (!props.loop) {
191
- targetOffset = range(targetOffset, minOffset, 0);
192
- }
193
- return targetOffset;
194
- };
195
- const range = (num, min, max) => {
196
- return Math.min(Math.max(num, min), max);
197
- };
198
- const classPrefix = "nut-swiper";
199
- const contentClass = classNames({
200
- [`${classPrefix}-inner`]: true,
201
- [`${classPrefix}-vertical`]: isVertical
202
- });
203
- const getStyle = (moveOffset = offset) => {
204
- const target = innerRef.current;
205
- if (!target)
206
- return;
207
- let _offset = 0;
208
- if (!center) {
209
- _offset = moveOffset;
223
+ const bind = useDrag((state) => {
224
+ const axis = Number(isVertical);
225
+ const slideSize = getSlideSize();
226
+ const offset = state.offset[axis];
227
+ setDragging(!!state.dragging);
228
+ const distance = state.distance[axis];
229
+ swiperDirection.current = state.direction[axis];
230
+ if (state.last) {
231
+ const swipeDirection = state.direction[axis];
232
+ const velocity = state.velocity[axis];
233
+ const minIndex = Math.floor(offset / slideSize);
234
+ const maxIndex = minIndex + 1;
235
+ const index = Math.round((offset + velocity * 2e3 * swipeDirection) / slideSize);
236
+ to(bound(index, minIndex, maxIndex));
210
237
  } else {
211
- const _size = isVertical ? height : width;
212
- const val = isVertical ? rect.height - _size : rect.width - _size;
213
- _offset = moveOffset + (active === swiperItemCount - 1 && !props.loop ? -val / 2 : val / 2);
214
- }
215
- target.style.transitionDuration = `${swiperRef.current.moving ? 0 : props.duration}ms`;
216
- target.style[isVertical ? "height" : "width"] = `${Number(size) * swiperItemCount}px`;
217
- target.style[isVertical ? "width" : "height"] = `${isVertical ? width : height}px`;
218
- target.style.transform = `translate3D${!isVertical ? `(${rtl ? -_offset : _offset}px,0,0)` : `(0,${_offset}px,0)`}`;
219
- };
220
- const onTouchStart = (e) => {
221
- if (!props.touchable)
222
- return;
223
- touch.start(e);
224
- stopAutoPlay();
225
- resetPosition();
226
- };
227
- const onTouchMove = (e) => {
228
- if (props.preventDefault)
229
- e.preventDefault();
230
- if (props.stopPropagation)
231
- e.stopPropagation();
232
- if (props.touchable && swiperRef.current.moving) {
233
- touch.move(e);
234
- if (touch.direction.current === props.direction) {
235
- move({
236
- offset: touch.delta.current
237
- });
238
- }
239
- }
240
- };
241
- const onTouchEnd = (e) => {
242
- if (!props.touchable || !swiperRef.current.moving)
243
- return;
244
- const speed = touch.delta.current / (Date.now() - touch.touchTime.current);
245
- const isShouldMove = Math.abs(speed) > 0.3 || Math.abs(touch.delta.current) > Number((size / 2).toFixed(2));
246
- swiperRef.current.moving = false;
247
- if (isShouldMove && touch.direction.current === props.direction) {
248
- let pace = 0;
249
- const offset2 = touch.isVertical() ? touch.offsetY : touch.offsetX;
250
- if (props.loop) {
251
- if (offset2.current > 0) {
252
- pace = touch.delta.current > 0 ? -1 : 1;
253
- }
254
- } else {
255
- pace = -Math[touch.delta.current > 0 ? "ceil" : "floor"](touch.delta.current / size);
256
- }
257
- move({
258
- pace,
259
- isEmit: true
238
+ api.start({
239
+ [isVertical ? "y" : "x"]: -(offset / slideSize * 100),
240
+ s: distance / slideSize,
241
+ immediate: true
260
242
  });
261
- } else if (touch.delta.current) {
262
- move({ pace: 0 });
263
- } else {
264
- getStyle();
265
- }
266
- startPlay();
267
- };
268
- const getItemStyle = (index) => {
269
- const style = {};
270
- if (size) {
271
- style[direction === "horizontal" ? "width" : "height"] = `${size}px`;
272
- }
273
- const offset2 = childOffset[index];
274
- if (offset2) {
275
- style.transform = `translate3D${direction === "horizontal" ? `(${rtl ? -offset2 : offset2}px,0,0)` : `(0,${offset2}px,0)`}`;
276
- }
277
- return style;
278
- };
279
- const init = (index) => {
280
- const rect2 = getRect(container === null || container === void 0 ? void 0 : container.current);
281
- const currentIndex = Math.max(Math.min(swiperItemCount - 1, index || Number(mergedProps.defaultValue)), 0);
282
- const width2 = Number(mergedProps.width) || rect2.width;
283
- const height2 = Number(mergedProps.height) || rect2.height;
284
- size = isVertical ? height2 : width2;
285
- trackSize = swiperItemCount * Number(size);
286
- const targetOffset = getOffset(currentIndex);
287
- swiperRef.current.moving = true;
288
- if (ready) {
289
- swiperRef.current.moving = false;
290
243
  }
291
- setRect(rect2);
292
- setActive(currentIndex);
293
- setWidth(width2);
294
- setHeight(height2);
295
- setOffset(targetOffset);
296
- setReady(true);
297
- };
298
- useEffect(() => {
299
- if (ready) {
300
- getStyle();
301
- }
302
- }, [isVertical, width, height, offset, ready]);
303
- useEffect(() => {
304
- if (ready) {
305
- stopAutoPlay();
306
- startPlay();
244
+ }, {
245
+ enabled: touchable,
246
+ transform: ([x, y]) => [-x, -y],
247
+ from: () => {
248
+ const slideSize = getSlideSize();
249
+ const x = springs.x.get() / 100 * slideSize;
250
+ const y = springs.y.get() / 100 * slideSize;
251
+ return [-x, -y];
252
+ },
253
+ triggerAllEvents: true,
254
+ bounds: () => {
255
+ if (loop)
256
+ return {};
257
+ const slideSize = getSlideSize();
258
+ getSwiperSize();
259
+ if (isVertical) {
260
+ return { top: 0, bottom: (count - 1) * slideSize };
261
+ }
262
+ return { left: 0, right: (count - 1) * slideSize };
263
+ },
264
+ preventDefault: true,
265
+ rubberband: true,
266
+ axis: isVertical ? "y" : "x",
267
+ pointer: {
268
+ touch: true
307
269
  }
308
- return () => setReady(false);
309
- }, [ready]);
310
- useEffect(() => {
311
- const events = [
312
- { name: "touchstart", e: onTouchStart },
313
- { name: "touchmove", e: onTouchMove },
314
- { name: "touchend", e: onTouchEnd }
315
- ];
316
- events.forEach((item) => {
317
- var _a;
318
- (_a = container.current) === null || _a === void 0 ? void 0 : _a.addEventListener(item.name, item.e, false);
319
- });
320
- return () => {
321
- events.forEach((item) => {
322
- var _a;
323
- (_a = container.current) === null || _a === void 0 ? void 0 : _a.removeEventListener(item.name, item.e, false);
324
- });
325
- };
326
270
  });
327
- useEffect(() => init(), [props.defaultValue]);
328
- useEffect(() => {
329
- return () => stopAutoPlay();
330
- }, []);
331
271
  const renderIndicator = () => {
332
272
  if (React__default.isValidElement(indicator))
333
273
  return indicator;
@@ -337,20 +277,47 @@ const Swiper = React__default.forwardRef((props, ref) => {
337
277
  "div",
338
278
  { className: classNames({
339
279
  [`${classPrefix}-indicator`]: true,
340
- [`${classPrefix}-indicator-vertical`]: isVertical
280
+ [`${classPrefix}-indicator-vertical`]: isVertical,
281
+ [`${classPrefix}-indicator-horizontal`]: !isVertical
341
282
  }) },
342
- React__default.createElement(Indicator, { current: (active + swiperItemCount) % swiperItemCount, total: swiperItems === null || swiperItems === void 0 ? void 0 : swiperItems.length, direction })
283
+ React__default.createElement(Indicator__default, { current: getRefValue(current), total: count, direction })
343
284
  );
344
285
  };
286
+ const renderEffect = () => {
287
+ if (!effect)
288
+ return defaultEffect({
289
+ children,
290
+ getSpringsAxis,
291
+ loop,
292
+ count,
293
+ isVertical
294
+ });
295
+ if (effect && effect.name === "focus") {
296
+ return focusEffect({
297
+ children,
298
+ springs,
299
+ loop,
300
+ count,
301
+ isVertical,
302
+ effect,
303
+ current,
304
+ swiperDirection,
305
+ dragging,
306
+ transforms
307
+ });
308
+ }
309
+ };
310
+ const renderSlides = () => {
311
+ return React__default.createElement("div", { ref: stageRef, className: classNames("nut-swiper-inner", {
312
+ "nut-swiper-inner-vertical": isVertical,
313
+ "nut-swiper-inner-horizontal": !isVertical
314
+ }), style: Object.assign({}, props.slideSize ? { [isVertical ? "height" : "width"]: `${props.slideSize}px` } : {}) }, renderEffect());
315
+ };
345
316
  return React__default.createElement(
346
- DataContext.Provider,
347
- { value: parent },
348
- React__default.createElement(
349
- "div",
350
- Object.assign({ className: classNames(classPrefix, className), ref: container }, rest),
351
- React__default.createElement("div", { className: contentClass, ref: innerRef }, React__default.Children.map(swiperItems, (child, index) => React__default.createElement("div", { className: `${classPrefix}-item-wrapper`, style: getItemStyle(index), key: index }, child))),
352
- renderIndicator()
353
- )
317
+ "div",
318
+ Object.assign({ className: classNames("nut-swiper", className), style, ref: swiperRef }, bind()),
319
+ renderSlides(),
320
+ renderIndicator()
354
321
  );
355
322
  });
356
323
  Swiper.defaultProps = defaultProps;
@@ -1,26 +1,14 @@
1
- import React__default, { useContext } from "react";
1
+ import React__default from "react";
2
2
  import classNames from "classnames";
3
- import { D as DataContext } from "./context4.js";
4
3
  const defaultProps = {
5
- direction: "horizontal"
4
+ onClick: (e) => void 0
6
5
  };
7
- const SwiperItem = React__default.forwardRef((props, ref) => {
6
+ const SwiperItem = (props) => {
8
7
  const classPrefix = "nut-swiper-item";
9
- const _props = Object.assign(Object.assign({}, defaultProps), props);
10
- const { className, style, children, direction, size } = _props;
11
- const parent = useContext(DataContext);
8
+ const { className, style, children } = Object.assign(Object.assign({}, defaultProps), props);
12
9
  const classes = classNames(classPrefix, className);
13
- const getStyle = () => {
14
- const style2 = {};
15
- const _direction = (parent === null || parent === void 0 ? void 0 : parent.propSwiper.direction) || direction;
16
- const _size = (parent === null || parent === void 0 ? void 0 : parent.size) || size;
17
- if (_size) {
18
- style2[_direction === "horizontal" ? "width" : "height"] = `${_size}px`;
19
- }
20
- return style2;
21
- };
22
- return React__default.createElement("div", { className: classes, style: Object.assign(Object.assign({}, style), getStyle()) }, children);
23
- });
10
+ return React__default.createElement("div", { className: classes, onClick: props.onClick, style }, children);
11
+ };
24
12
  SwiperItem.defaultProps = defaultProps;
25
13
  SwiperItem.displayName = "NutSwiperItem";
26
14
  export {
@@ -1,5 +1,19 @@
1
1
  import { createContext } from "react";
2
- const DataContext = createContext({});
2
+ const handleClick = (e) => {
3
+ e.stopPropagation();
4
+ const isIcon = e.target.className.includes("arrow-icon");
5
+ const isTitle = e.target.className.includes("-title") || isIcon;
6
+ const currentClass = e.currentTarget.className;
7
+ const isShow = currentClass.includes("sidenavbar-show");
8
+ const arrowIcon = e.currentTarget.querySelector(".arrow-icon");
9
+ const iconClass = arrowIcon.className;
10
+ if (isTitle) {
11
+ e.currentTarget.className = isShow ? currentClass.replace("sidenavbar-show", "sidenavbar-hide") : currentClass.replace("sidenavbar-hide", "sidenavbar-show");
12
+ arrowIcon.className = isShow ? iconClass.replace("arrow-down", "arrow-up") : iconClass.replace("arrow-up", "arrow-down");
13
+ }
14
+ };
15
+ const OffsetContext = createContext(20);
3
16
  export {
4
- DataContext as D
17
+ OffsetContext as O,
18
+ handleClick as h
5
19
  };