@rific/scroll-view 0.1.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.
- package/README.md +319 -0
- package/dist/index.d.mts +210 -0
- package/dist/index.d.ts +210 -0
- package/dist/index.js +2760 -0
- package/dist/index.mjs +2709 -0
- package/package.json +105 -0
- package/src/CustomList.tsx +127 -0
- package/src/FlatList.tsx +139 -0
- package/src/PullSearch.tsx +99 -0
- package/src/ScrollView.tsx +89 -0
- package/src/ScrollViewContext.ts +50 -0
- package/src/ScrollViewFooter.tsx +48 -0
- package/src/ScrollViewHeader.tsx +159 -0
- package/src/ScrollViewProvider.tsx +62 -0
- package/src/ScrollViewSettingsContext.ts +27 -0
- package/src/ScrollViewSettingsProvider.tsx +31 -0
- package/src/SectionList.tsx +195 -0
- package/src/__mocks__/auto-paper.ts +8 -0
- package/src/__mocks__/flash-list.ts +20 -0
- package/src/__mocks__/react-native-gesture-handler.ts +13 -0
- package/src/__mocks__/react-native-keyboard-controller.ts +11 -0
- package/src/__mocks__/react-native-paper.ts +22 -0
- package/src/__mocks__/react-native-reanimated.ts +30 -0
- package/src/__mocks__/react-native-safe-area-context.ts +2 -0
- package/src/__mocks__/react-native.ts +30 -0
- package/src/__tests__/CustomList.test.tsx +61 -0
- package/src/__tests__/FlatList.test.tsx +52 -0
- package/src/__tests__/PullSearch.test.tsx +38 -0
- package/src/__tests__/ScrollView.test.tsx +23 -0
- package/src/__tests__/ScrollViewHeader.test.tsx +28 -0
- package/src/__tests__/ScrollViewProvider.test.tsx +65 -0
- package/src/__tests__/SectionList.test.tsx +88 -0
- package/src/index.ts +26 -0
- package/src/internal/FAB.tsx +6 -0
- package/src/internal/HorizontalDots.tsx +99 -0
- package/src/internal/RefreshControl.tsx +5 -0
- package/src/internal/ScrollViewChip.tsx +22 -0
- package/src/internal/useScrollHandler.ts +101 -0
- package/src/internal/useScrollList.ts +64 -0
- package/src/internal/useStickyHeaders.ts +149 -0
- package/src/out.txt +61 -0
- package/src/redux/scrollViewSlice.ts +14 -0
- package/src/useKeyboardInset.ts +21 -0
- package/src/useScrollInit.ts +112 -0
- package/src/useScrollView.ts +8 -0
- package/src/useScrollViewSettings.ts +5 -0
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,2709 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
3
|
+
var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
|
|
4
|
+
|
|
5
|
+
// src/CustomList.tsx
|
|
6
|
+
import { memo, useCallback as useCallback2, useMemo as useMemo2, useRef as useRef2 } from "react";
|
|
7
|
+
import { Dimensions, View } from "react-native";
|
|
8
|
+
import { Gesture, GestureDetector } from "react-native-gesture-handler";
|
|
9
|
+
|
|
10
|
+
// src/internal/RefreshControl.tsx
|
|
11
|
+
import { RefreshControl as RNRefreshControl } from "react-native";
|
|
12
|
+
import { jsx } from "react/jsx-runtime";
|
|
13
|
+
var RefreshControl = (props) => /* @__PURE__ */ jsx(RNRefreshControl, { refreshing: false, ...props });
|
|
14
|
+
|
|
15
|
+
// src/internal/ScrollViewChip.tsx
|
|
16
|
+
import { StyleSheet } from "react-native";
|
|
17
|
+
import { Chip } from "react-native-paper";
|
|
18
|
+
import Animated from "react-native-reanimated";
|
|
19
|
+
import { jsx as jsx2 } from "react/jsx-runtime";
|
|
20
|
+
var ScrollViewChip = ({ isHorizontal, onPress, style }) => /* @__PURE__ */ jsx2(Animated.View, { style: [styles.chip, style], children: /* @__PURE__ */ jsx2(Chip, { compact: true, icon: isHorizontal ? "chevron-left" : "chevron-up", onPress, style: styles.chipInner, children: isHorizontal ? "Start" : "Top" }) });
|
|
21
|
+
var styles = StyleSheet.create({
|
|
22
|
+
chip: { alignItems: "center", left: 0, position: "absolute", right: 0, zIndex: 3 },
|
|
23
|
+
chipInner: { elevation: 2, shadowColor: "#000", shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.15, shadowRadius: 2 }
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
// src/internal/useScrollHandler.ts
|
|
27
|
+
import { useContext } from "react";
|
|
28
|
+
import { runOnJS, useAnimatedScrollHandler, useSharedValue, withTiming } from "react-native-reanimated";
|
|
29
|
+
|
|
30
|
+
// src/ScrollViewContext.ts
|
|
31
|
+
import { createContext } from "react";
|
|
32
|
+
var ScrollViewContext = createContext({
|
|
33
|
+
blur: true,
|
|
34
|
+
footerHeight: 0,
|
|
35
|
+
footerHeightShared: null,
|
|
36
|
+
footerFixed: false,
|
|
37
|
+
footerOffset: null,
|
|
38
|
+
headerHeight: 0,
|
|
39
|
+
headerHeightShared: null,
|
|
40
|
+
headerFixed: false,
|
|
41
|
+
headerOffset: null,
|
|
42
|
+
progress: null,
|
|
43
|
+
progressing: false,
|
|
44
|
+
pullSearchHeightShared: null,
|
|
45
|
+
scrollHeight: 0,
|
|
46
|
+
scrollPosition: null,
|
|
47
|
+
setFooterHeight: () => {
|
|
48
|
+
},
|
|
49
|
+
setHeaderHeight: () => {
|
|
50
|
+
},
|
|
51
|
+
setProgress: () => {
|
|
52
|
+
},
|
|
53
|
+
setProgressing: () => {
|
|
54
|
+
},
|
|
55
|
+
snapBackFooterShared: null,
|
|
56
|
+
snapBackHeaderShared: null,
|
|
57
|
+
tabBarHeight: 60
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// src/internal/useScrollHandler.ts
|
|
61
|
+
function useScrollHandler({ chipHidden, footerFixed, headerFixed, isHorizontal, onPullSearchZoneEnter }) {
|
|
62
|
+
const { footerHeightShared, footerOffset, headerHeightShared, headerOffset, pullSearchHeightShared, scrollPosition, snapBackFooterShared, snapBackHeaderShared } = useContext(ScrollViewContext);
|
|
63
|
+
const snapUpAccum = useSharedValue(0);
|
|
64
|
+
const fromBottomBounce = useSharedValue(false);
|
|
65
|
+
const isMomentum = useSharedValue(false);
|
|
66
|
+
const momentumPullSearchFired = useSharedValue(false);
|
|
67
|
+
return useAnimatedScrollHandler(
|
|
68
|
+
{
|
|
69
|
+
onScroll: ({ contentOffset: { x, y }, contentSize: { height: contentHeight }, layoutMeasurement: { height: layoutHeight } }) => {
|
|
70
|
+
"worklet";
|
|
71
|
+
if (isHorizontal) {
|
|
72
|
+
scrollPosition.value = x;
|
|
73
|
+
chipHidden.value = x < 100 ? 1 : 0;
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
const delta = y - scrollPosition.value;
|
|
77
|
+
scrollPosition.value = y;
|
|
78
|
+
chipHidden.value = y < 100 ? 1 : 0;
|
|
79
|
+
const maxScroll = contentHeight - layoutHeight;
|
|
80
|
+
if (maxScroll > 0 && y >= maxScroll) {
|
|
81
|
+
fromBottomBounce.value = true;
|
|
82
|
+
snapUpAccum.value = 0;
|
|
83
|
+
} else if (fromBottomBounce.value) {
|
|
84
|
+
fromBottomBounce.value = false;
|
|
85
|
+
}
|
|
86
|
+
if (isMomentum.value && pullSearchHeightShared.value > 0 && !momentumPullSearchFired.value) {
|
|
87
|
+
const hideY = -headerHeightShared.value + pullSearchHeightShared.value;
|
|
88
|
+
if (y < hideY) {
|
|
89
|
+
momentumPullSearchFired.value = true;
|
|
90
|
+
if (onPullSearchZoneEnter) runOnJS(onPullSearchZoneEnter)();
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
const snapHeader = snapBackHeaderShared.value && !headerFixed;
|
|
94
|
+
const snapFooter = snapBackFooterShared.value && !footerFixed;
|
|
95
|
+
if (snapHeader || snapFooter) {
|
|
96
|
+
if (y <= -headerHeightShared.value) {
|
|
97
|
+
snapUpAccum.value = 0;
|
|
98
|
+
if (snapHeader) headerOffset.value = 0;
|
|
99
|
+
if (snapFooter) footerOffset.value = 0;
|
|
100
|
+
} else if (delta > 0) {
|
|
101
|
+
snapUpAccum.value = 0;
|
|
102
|
+
if (y >= -headerHeightShared.value + pullSearchHeightShared.value) {
|
|
103
|
+
if (snapHeader) headerOffset.value = Math.max(-headerHeightShared.value, Math.min(0, headerOffset.value - delta));
|
|
104
|
+
if (snapFooter) footerOffset.value = Math.max(0, Math.min(footerHeightShared.value, footerOffset.value + delta));
|
|
105
|
+
}
|
|
106
|
+
} else if (delta < 0 && !fromBottomBounce.value) {
|
|
107
|
+
if (y >= -headerHeightShared.value + pullSearchHeightShared.value) snapUpAccum.value -= delta;
|
|
108
|
+
if (snapUpAccum.value >= 10) {
|
|
109
|
+
snapUpAccum.value = 999;
|
|
110
|
+
if (snapHeader) headerOffset.value = withTiming(0, { duration: 200 });
|
|
111
|
+
if (snapFooter) footerOffset.value = withTiming(0, { duration: 200 });
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
onBeginDrag: () => {
|
|
117
|
+
"worklet";
|
|
118
|
+
isMomentum.value = false;
|
|
119
|
+
momentumPullSearchFired.value = false;
|
|
120
|
+
fromBottomBounce.value = false;
|
|
121
|
+
snapUpAccum.value = 0;
|
|
122
|
+
},
|
|
123
|
+
onMomentumBegin: () => {
|
|
124
|
+
"worklet";
|
|
125
|
+
isMomentum.value = true;
|
|
126
|
+
momentumPullSearchFired.value = false;
|
|
127
|
+
},
|
|
128
|
+
onEndDrag: ({ contentOffset: { y }, contentSize: { height: contentHeight }, layoutMeasurement: { height: layoutHeight } }) => {
|
|
129
|
+
"worklet";
|
|
130
|
+
if (isHorizontal) return;
|
|
131
|
+
if (y >= contentHeight - layoutHeight - 10) {
|
|
132
|
+
fromBottomBounce.value = true;
|
|
133
|
+
snapUpAccum.value = 0;
|
|
134
|
+
}
|
|
135
|
+
},
|
|
136
|
+
onMomentumEnd: () => {
|
|
137
|
+
"worklet";
|
|
138
|
+
isMomentum.value = false;
|
|
139
|
+
momentumPullSearchFired.value = false;
|
|
140
|
+
fromBottomBounce.value = false;
|
|
141
|
+
snapUpAccum.value = 0;
|
|
142
|
+
}
|
|
143
|
+
},
|
|
144
|
+
[headerFixed, footerFixed, isHorizontal, onPullSearchZoneEnter]
|
|
145
|
+
);
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
// src/internal/useScrollList.ts
|
|
149
|
+
import { useContext as useContext2, useEffect, useMemo } from "react";
|
|
150
|
+
import { StyleSheet as StyleSheet2 } from "react-native";
|
|
151
|
+
import { useAnimatedStyle, useSharedValue as useSharedValue2, withTiming as withTiming2 } from "react-native-reanimated";
|
|
152
|
+
import { useSafeAreaInsets } from "react-native-safe-area-context";
|
|
153
|
+
|
|
154
|
+
// src/useKeyboardInset.ts
|
|
155
|
+
import { useState } from "react";
|
|
156
|
+
import { useKeyboardHandler } from "react-native-keyboard-controller";
|
|
157
|
+
import { runOnJS as runOnJS2 } from "react-native-reanimated";
|
|
158
|
+
var useKeyboardInset = () => {
|
|
159
|
+
const [keyboardHeight, setKeyboardHeight] = useState(0);
|
|
160
|
+
useKeyboardHandler(
|
|
161
|
+
{
|
|
162
|
+
onMove: (e) => {
|
|
163
|
+
"worklet";
|
|
164
|
+
runOnJS2(setKeyboardHeight)(e.height);
|
|
165
|
+
},
|
|
166
|
+
onEnd: (e) => {
|
|
167
|
+
"worklet";
|
|
168
|
+
runOnJS2(setKeyboardHeight)(e.height);
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
[]
|
|
172
|
+
);
|
|
173
|
+
return keyboardHeight;
|
|
174
|
+
};
|
|
175
|
+
|
|
176
|
+
// src/internal/useScrollList.ts
|
|
177
|
+
var CHIP_SLIDE = 48;
|
|
178
|
+
function useScrollList({ footerFixed: footerFixedProp, headerFixed: headerFixedProp, isHorizontal, keyboardAware, pullSearchHeight, style } = {}) {
|
|
179
|
+
const insets = useSafeAreaInsets();
|
|
180
|
+
const keyboardHeight = useKeyboardInset();
|
|
181
|
+
const { footerHeight, footerFixed: contextFooterFixed, headerHeight, headerFixed: contextHeaderFixed, headerOffset, pullSearchHeightShared, scrollPosition, snapBackHeaderShared } = useContext2(ScrollViewContext);
|
|
182
|
+
const headerFixed = isHorizontal ? true : headerFixedProp ?? contextHeaderFixed;
|
|
183
|
+
const footerFixed = isHorizontal ? true : footerFixedProp ?? contextFooterFixed;
|
|
184
|
+
useEffect(() => {
|
|
185
|
+
pullSearchHeightShared.value = pullSearchHeight ?? 0;
|
|
186
|
+
}, [pullSearchHeight, pullSearchHeightShared]);
|
|
187
|
+
const containerStyle = useMemo(() => headerHeight === 0 ? [{ flex: 1 }, style] : [StyleSheet2.absoluteFill, style], [headerHeight, style]);
|
|
188
|
+
const contentInset = useMemo(() => ({ bottom: (footerFixed ? footerHeight || insets.bottom : insets.bottom) + (keyboardAware ? keyboardHeight : 0), top: headerHeight }), [footerFixed, footerHeight, insets.bottom, headerHeight, keyboardAware, keyboardHeight]);
|
|
189
|
+
const contentOffset = useMemo(() => ({ x: 0, y: -contentInset.top }), [contentInset.top]);
|
|
190
|
+
const chipHidden = useSharedValue2(1);
|
|
191
|
+
const chipStyle = useAnimatedStyle(() => {
|
|
192
|
+
const pointerEvents = chipHidden.value ? "none" : "box-none";
|
|
193
|
+
if (isHorizontal) {
|
|
194
|
+
return {
|
|
195
|
+
opacity: chipHidden.value ? withTiming2(0) : withTiming2(1),
|
|
196
|
+
pointerEvents,
|
|
197
|
+
top: Math.max(headerHeight, insets.top) + 4,
|
|
198
|
+
transform: [{ translateX: chipHidden.value ? withTiming2(-CHIP_SLIDE) : withTiming2(0) }]
|
|
199
|
+
};
|
|
200
|
+
}
|
|
201
|
+
const slide = headerFixed ? 0 : snapBackHeaderShared.value ? -headerOffset.value : Math.max(0, scrollPosition.value + headerHeight - pullSearchHeightShared.value);
|
|
202
|
+
const top = Math.max(headerHeight - slide, insets.top) + 4;
|
|
203
|
+
return {
|
|
204
|
+
opacity: chipHidden.value ? withTiming2(0) : withTiming2(1),
|
|
205
|
+
pointerEvents,
|
|
206
|
+
top,
|
|
207
|
+
transform: [{ translateY: chipHidden.value ? withTiming2(-CHIP_SLIDE) : withTiming2(0) }]
|
|
208
|
+
};
|
|
209
|
+
}, [isHorizontal, headerFixed, headerHeight, insets.top]);
|
|
210
|
+
return { chipHidden, chipStyle, containerStyle, contentInset, contentOffset, footerFixed, headerFixed, headerHeight, insets, isHorizontal: isHorizontal ?? false };
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
// src/useScrollInit.ts
|
|
214
|
+
import { createElement, useCallback, useContext as useContext3, useEffect as useEffect2, useLayoutEffect, useRef, useState as useState2 } from "react";
|
|
215
|
+
function useScrollInit({ listHeaderComponent, onMomentumScrollEnd: externalMomentumScrollEnd, onRefresh, onScrollBeginDrag: externalScrollBeginDrag, onScrollEndDrag: externalScrollEndDrag, pullSearchHeight, scrollTo }) {
|
|
216
|
+
const { headerHeight, scrollPosition, setProgressing } = useContext3(ScrollViewContext);
|
|
217
|
+
const hasPullSearch = pullSearchHeight !== void 0;
|
|
218
|
+
const [phase, setPhase] = useState2(hasPullSearch ? "measuring" : "ready");
|
|
219
|
+
const [refreshing, setRefreshing] = useState2(false);
|
|
220
|
+
const dragStartY = useRef(null);
|
|
221
|
+
const deliberatelyOpened = useRef(false);
|
|
222
|
+
useEffect2(() => {
|
|
223
|
+
if (phase === "ready" || !headerHeight || !pullSearchHeight) return;
|
|
224
|
+
scrollPosition.value = -headerHeight + pullSearchHeight;
|
|
225
|
+
setPhase("ready");
|
|
226
|
+
}, [phase, headerHeight, pullSearchHeight, scrollPosition]);
|
|
227
|
+
const headerInitialized = useRef(false);
|
|
228
|
+
useLayoutEffect(() => {
|
|
229
|
+
if (!headerHeight || headerInitialized.current) return;
|
|
230
|
+
headerInitialized.current = true;
|
|
231
|
+
scrollPosition.value = -headerHeight;
|
|
232
|
+
scrollTo(-headerHeight, false);
|
|
233
|
+
}, [headerHeight, scrollPosition, scrollTo]);
|
|
234
|
+
const pullSearchInitialized = useRef(false);
|
|
235
|
+
useLayoutEffect(() => {
|
|
236
|
+
if (!hasPullSearch || phase !== "ready" || pullSearchInitialized.current || !headerHeight || !pullSearchHeight) return;
|
|
237
|
+
pullSearchInitialized.current = true;
|
|
238
|
+
scrollPosition.value = -headerHeight + pullSearchHeight;
|
|
239
|
+
scrollTo(-headerHeight + pullSearchHeight, false);
|
|
240
|
+
}, [hasPullSearch, phase, headerHeight, pullSearchHeight, scrollPosition, scrollTo]);
|
|
241
|
+
useEffect2(() => {
|
|
242
|
+
if (pullSearchHeight) setProgressing(refreshing);
|
|
243
|
+
}, [pullSearchHeight, refreshing, setProgressing]);
|
|
244
|
+
const handleScrollBeginDrag = useCallback(
|
|
245
|
+
(e) => {
|
|
246
|
+
deliberatelyOpened.current = false;
|
|
247
|
+
if (pullSearchHeight) dragStartY.current = e.nativeEvent.contentOffset.y;
|
|
248
|
+
externalScrollBeginDrag?.(e);
|
|
249
|
+
},
|
|
250
|
+
[externalScrollBeginDrag, pullSearchHeight]
|
|
251
|
+
);
|
|
252
|
+
const handleScrollEndDrag = useCallback(
|
|
253
|
+
(e) => {
|
|
254
|
+
if (pullSearchHeight && headerHeight) {
|
|
255
|
+
const y = e.nativeEvent.contentOffset.y;
|
|
256
|
+
const showY = -headerHeight;
|
|
257
|
+
const hideY = -headerHeight + pullSearchHeight;
|
|
258
|
+
const pulledDown = (dragStartY.current ?? hideY) <= hideY;
|
|
259
|
+
dragStartY.current = null;
|
|
260
|
+
if (pulledDown && y <= showY + pullSearchHeight * 0.5) {
|
|
261
|
+
deliberatelyOpened.current = true;
|
|
262
|
+
if (y <= showY && !refreshing && onRefresh) {
|
|
263
|
+
setRefreshing(true);
|
|
264
|
+
Promise.resolve(onRefresh()).finally(() => setRefreshing(false));
|
|
265
|
+
}
|
|
266
|
+
scrollTo(showY, true);
|
|
267
|
+
} else if (y < hideY) {
|
|
268
|
+
scrollTo(hideY, true);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
externalScrollEndDrag?.(e);
|
|
272
|
+
},
|
|
273
|
+
[externalScrollEndDrag, headerHeight, onRefresh, pullSearchHeight, refreshing, scrollTo]
|
|
274
|
+
);
|
|
275
|
+
const handleMomentumScrollEnd = useCallback(
|
|
276
|
+
(e) => {
|
|
277
|
+
if (pullSearchHeight && headerHeight && !deliberatelyOpened.current && !refreshing) {
|
|
278
|
+
const y = e.nativeEvent.contentOffset.y;
|
|
279
|
+
const hideY = -headerHeight + pullSearchHeight;
|
|
280
|
+
if (y < hideY - 1) scrollTo(hideY, true);
|
|
281
|
+
}
|
|
282
|
+
deliberatelyOpened.current = false;
|
|
283
|
+
externalMomentumScrollEnd?.(e);
|
|
284
|
+
},
|
|
285
|
+
[externalMomentumScrollEnd, headerHeight, pullSearchHeight, refreshing, scrollTo]
|
|
286
|
+
);
|
|
287
|
+
const activeListHeader = hasPullSearch && phase === "measuring" ? null : listHeaderComponent;
|
|
288
|
+
const hiddenHeader = phase === "measuring" && listHeaderComponent != null ? typeof listHeaderComponent === "function" ? createElement(listHeaderComponent) : listHeaderComponent : null;
|
|
289
|
+
return { activeListHeader, handleMomentumScrollEnd, handleScrollBeginDrag, handleScrollEndDrag, hiddenHeader, pullSearchMinHeight: pullSearchHeight ?? 0 };
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
// src/CustomList.tsx
|
|
293
|
+
import { Fragment, jsx as jsx3, jsxs } from "react/jsx-runtime";
|
|
294
|
+
var CustomListInner = ({ component: List, renderFilters, footerFixed: footerFixedProp, gesture, headerFixed: headerFixedProp, keyboardAware, onMomentumScrollEnd: externalMomentumScrollEnd, onRefresh, onScrollBeginDrag: externalScrollBeginDrag, onScrollEndDrag: externalScrollEndDrag, pullSearchHeight, scrollRef, style, ...props }) => {
|
|
295
|
+
const { ListHeaderComponent: listHeaderComponent, contentContainerStyle: externalContentContainerStyle, ...restProps } = props;
|
|
296
|
+
const { chipHidden, chipStyle, containerStyle, contentInset, contentOffset, footerFixed, headerFixed } = useScrollList({ footerFixed: footerFixedProp, headerFixed: headerFixedProp, keyboardAware, pullSearchHeight, style });
|
|
297
|
+
const scrollViewInternal = useRef2(null);
|
|
298
|
+
const handleRef = useCallback2(
|
|
299
|
+
(el) => {
|
|
300
|
+
scrollViewInternal.current = el;
|
|
301
|
+
if (scrollRef) scrollRef.current = el;
|
|
302
|
+
},
|
|
303
|
+
[scrollRef]
|
|
304
|
+
);
|
|
305
|
+
const scrollTo = useCallback2((offset, animated) => {
|
|
306
|
+
scrollViewInternal.current?.scrollToOffset({ offset, animated });
|
|
307
|
+
}, []);
|
|
308
|
+
const {
|
|
309
|
+
activeListHeader: pullSearchHeader,
|
|
310
|
+
handleMomentumScrollEnd,
|
|
311
|
+
handleScrollBeginDrag,
|
|
312
|
+
handleScrollEndDrag,
|
|
313
|
+
hiddenHeader,
|
|
314
|
+
pullSearchMinHeight
|
|
315
|
+
} = useScrollInit({
|
|
316
|
+
listHeaderComponent,
|
|
317
|
+
onMomentumScrollEnd: externalMomentumScrollEnd,
|
|
318
|
+
onRefresh: pullSearchHeight ? onRefresh : void 0,
|
|
319
|
+
onScrollBeginDrag: externalScrollBeginDrag,
|
|
320
|
+
onScrollEndDrag: externalScrollEndDrag,
|
|
321
|
+
pullSearchHeight,
|
|
322
|
+
scrollTo
|
|
323
|
+
});
|
|
324
|
+
const activeListHeader = useMemo2(() => {
|
|
325
|
+
if (!renderFilters) return pullSearchHeader;
|
|
326
|
+
const Inner = pullSearchHeader;
|
|
327
|
+
return () => /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
328
|
+
Inner ? typeof Inner === "function" ? /* @__PURE__ */ jsx3(Inner, {}) : Inner : null,
|
|
329
|
+
renderFilters
|
|
330
|
+
] });
|
|
331
|
+
}, [pullSearchHeader, renderFilters]);
|
|
332
|
+
const contentContainerStyle = useMemo2(() => [{ minHeight: Dimensions.get("window").height - contentInset.top - contentInset.bottom + pullSearchMinHeight }, externalContentContainerStyle], [contentInset.bottom, contentInset.top, externalContentContainerStyle, pullSearchMinHeight]);
|
|
333
|
+
const onPullSearchZoneEnter = useCallback2(() => {
|
|
334
|
+
if (!pullSearchHeight) return;
|
|
335
|
+
scrollViewInternal.current?.scrollToOffset({ offset: -contentInset.top + pullSearchHeight, animated: true });
|
|
336
|
+
}, [contentInset.top, pullSearchHeight]);
|
|
337
|
+
const onScroll = useScrollHandler({ chipHidden, footerFixed, headerFixed, onPullSearchZoneEnter: pullSearchHeight ? onPullSearchZoneEnter : void 0 });
|
|
338
|
+
const handleScrollToTop = useCallback2(() => {
|
|
339
|
+
const offset = pullSearchHeight ? -contentInset.top + pullSearchHeight : -contentInset.top;
|
|
340
|
+
scrollViewInternal.current?.scrollToOffset({ offset, animated: true });
|
|
341
|
+
}, [contentInset.top, pullSearchHeight]);
|
|
342
|
+
const refreshControl = useMemo2(() => /* @__PURE__ */ jsx3(RefreshControl, {}), []);
|
|
343
|
+
const nativeGesture = useMemo2(() => Gesture.Native(), []);
|
|
344
|
+
const combinedGesture = useMemo2(() => gesture !== void 0 ? Gesture.Simultaneous(gesture, nativeGesture) : nativeGesture, [gesture, nativeGesture]);
|
|
345
|
+
const detectorGesture = gesture !== void 0 ? combinedGesture : void 0;
|
|
346
|
+
const TypedList = List;
|
|
347
|
+
const content = /* @__PURE__ */ jsxs(View, { style: containerStyle, children: [
|
|
348
|
+
/* @__PURE__ */ jsx3(TypedList, { ...restProps, contentContainerStyle, contentInset, contentOffset, ListHeaderComponent: activeListHeader, onMomentumScrollEnd: handleMomentumScrollEnd, onScroll, onScrollBeginDrag: handleScrollBeginDrag, onScrollEndDrag: handleScrollEndDrag, ref: handleRef, refreshControl, scrollEventThrottle: 16 }),
|
|
349
|
+
hiddenHeader && /* @__PURE__ */ jsx3(View, { pointerEvents: "none", style: styles2.measureContainer, children: hiddenHeader }),
|
|
350
|
+
/* @__PURE__ */ jsx3(ScrollViewChip, { onPress: handleScrollToTop, style: chipStyle })
|
|
351
|
+
] });
|
|
352
|
+
return detectorGesture ? /* @__PURE__ */ jsx3(GestureDetector, { gesture: detectorGesture, children: content }) : content;
|
|
353
|
+
};
|
|
354
|
+
var styles2 = { measureContainer: { left: 0, opacity: 0, position: "absolute", right: 0, top: -9999 } };
|
|
355
|
+
var CustomList = memo(CustomListInner);
|
|
356
|
+
|
|
357
|
+
// src/FlatList.tsx
|
|
358
|
+
import { memo as memo2, useCallback as useCallback3, useMemo as useMemo3, useRef as useRef3 } from "react";
|
|
359
|
+
import { Dimensions as Dimensions2, View as View3 } from "react-native";
|
|
360
|
+
import { Gesture as Gesture2, GestureDetector as GestureDetector2 } from "react-native-gesture-handler";
|
|
361
|
+
import Animated3 from "react-native-reanimated";
|
|
362
|
+
|
|
363
|
+
// src/internal/HorizontalDots.tsx
|
|
364
|
+
import { BlurView } from "@rific/auto-paper";
|
|
365
|
+
import { useContext as useContext4 } from "react";
|
|
366
|
+
import { StyleSheet as StyleSheet3, useWindowDimensions, View as View2 } from "react-native";
|
|
367
|
+
import { useTheme } from "react-native-paper";
|
|
368
|
+
import Animated2, { interpolateColor, useAnimatedStyle as useAnimatedStyle2 } from "react-native-reanimated";
|
|
369
|
+
import { useSafeAreaInsets as useSafeAreaInsets2 } from "react-native-safe-area-context";
|
|
370
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
|
371
|
+
var DOT_FULL = 8;
|
|
372
|
+
var DOT_SMALL = 3;
|
|
373
|
+
var DOT_GAP = 6;
|
|
374
|
+
var DOT_STEP = DOT_FULL + DOT_GAP;
|
|
375
|
+
var CLIP_COUNT = 5;
|
|
376
|
+
var CLIP_WIDTH = CLIP_COUNT * DOT_STEP - DOT_GAP;
|
|
377
|
+
var PILL_PAD_H = 10;
|
|
378
|
+
var PILL_PAD_V = 6;
|
|
379
|
+
var PILL_HEIGHT = DOT_FULL + PILL_PAD_V * 2;
|
|
380
|
+
var PILL_RADIUS = PILL_HEIGHT / 2;
|
|
381
|
+
var PILL_WIDTH = CLIP_WIDTH + PILL_PAD_H * 2;
|
|
382
|
+
var Dot = ({ activeColor, index, inactiveColor, pageWidth, scrollPosition }) => {
|
|
383
|
+
const circleStyle = useAnimatedStyle2(() => {
|
|
384
|
+
const page = scrollPosition.value / pageWidth;
|
|
385
|
+
const distance = Math.abs(index - page);
|
|
386
|
+
const t = Math.max(0, Math.min((distance - 0.5) / 2, 1));
|
|
387
|
+
const size = DOT_FULL + (DOT_SMALL - DOT_FULL) * t;
|
|
388
|
+
const backgroundColor = interpolateColor(t, [0, 1], [activeColor, inactiveColor]);
|
|
389
|
+
return { backgroundColor, borderRadius: size / 2, height: size, width: size };
|
|
390
|
+
});
|
|
391
|
+
return /* @__PURE__ */ jsx4(View2, { style: styles3.dotContainer, children: /* @__PURE__ */ jsx4(Animated2.View, { style: circleStyle }) });
|
|
392
|
+
};
|
|
393
|
+
var HorizontalDots = ({ total }) => {
|
|
394
|
+
const { blur, footerHeightShared, scrollPosition } = useContext4(ScrollViewContext);
|
|
395
|
+
const { width } = useWindowDimensions();
|
|
396
|
+
const insets = useSafeAreaInsets2();
|
|
397
|
+
const theme = useTheme();
|
|
398
|
+
const insetsBottom = insets.bottom;
|
|
399
|
+
const activeColor = theme.colors.primary;
|
|
400
|
+
const inactiveColor = theme.colors.outlineVariant;
|
|
401
|
+
const pillContainerStyle = useAnimatedStyle2(() => ({
|
|
402
|
+
bottom: Math.max(footerHeightShared.value, insetsBottom) + 8
|
|
403
|
+
}));
|
|
404
|
+
const rowStyle = useAnimatedStyle2(() => {
|
|
405
|
+
const page = scrollPosition.value / width;
|
|
406
|
+
const maxOffset = Math.max(0, (total - CLIP_COUNT) * DOT_STEP);
|
|
407
|
+
const offset = Math.max(0, Math.min((page - (CLIP_COUNT - 1) / 2) * DOT_STEP, maxOffset));
|
|
408
|
+
return { transform: [{ translateX: -offset }] };
|
|
409
|
+
});
|
|
410
|
+
return /* @__PURE__ */ jsx4(Animated2.View, { pointerEvents: "none", style: [styles3.pillContainer, pillContainerStyle], children: /* @__PURE__ */ jsxs2(View2, { style: styles3.pill, children: [
|
|
411
|
+
/* @__PURE__ */ jsx4(BlurView, { blur, style: StyleSheet3.absoluteFill }),
|
|
412
|
+
/* @__PURE__ */ jsx4(View2, { style: styles3.dotsClip, children: /* @__PURE__ */ jsx4(Animated2.View, { style: [styles3.dotsRow, rowStyle], children: Array.from({ length: total }).map((_, i) => /* @__PURE__ */ jsx4(Dot, { activeColor, index: i, inactiveColor, pageWidth: width, scrollPosition }, i)) }) })
|
|
413
|
+
] }) });
|
|
414
|
+
};
|
|
415
|
+
var styles3 = StyleSheet3.create({
|
|
416
|
+
dotContainer: { alignItems: "center", height: DOT_FULL, justifyContent: "center", width: DOT_FULL },
|
|
417
|
+
dotsClip: { overflow: "hidden", width: CLIP_WIDTH },
|
|
418
|
+
dotsRow: { flexDirection: "row", gap: DOT_GAP },
|
|
419
|
+
pill: {
|
|
420
|
+
alignItems: "center",
|
|
421
|
+
borderRadius: PILL_RADIUS,
|
|
422
|
+
height: PILL_HEIGHT,
|
|
423
|
+
justifyContent: "center",
|
|
424
|
+
overflow: "hidden",
|
|
425
|
+
width: PILL_WIDTH
|
|
426
|
+
},
|
|
427
|
+
pillContainer: { alignItems: "center", left: 0, position: "absolute", right: 0, zIndex: 3 }
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
// src/FlatList.tsx
|
|
431
|
+
import { Fragment as Fragment2, jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
|
|
432
|
+
var FlatListInner = ({ contentContainerStyle: externalContentContainerStyle, data, initialNumToRender = 20, maxToRenderPerBatch = 50, renderFilters, footerFixed: footerFixedProp, gesture, headerFixed: headerFixedProp, horizontal, keyboardAware, ListHeaderComponent: externalListHeaderComponent, onMomentumScrollEnd: externalMomentumScrollEnd, onRefresh, onScrollBeginDrag: externalScrollBeginDrag, onScrollEndDrag: externalScrollEndDrag, pagingEnabled, pullSearchHeight, removeClippedSubviews = false, showsHorizontalScrollIndicator, showsVerticalScrollIndicator, style, onContentSizeChange, ref: externalRef, windowSize = 100, ...props }) => {
|
|
433
|
+
const scrollView = useRef3(null);
|
|
434
|
+
const isHorizontal = horizontal === true;
|
|
435
|
+
const showDots = isHorizontal && pagingEnabled === true && (data?.length ?? 0) > 1;
|
|
436
|
+
const { chipHidden, chipStyle, containerStyle, contentInset, contentOffset, footerFixed, headerFixed } = useScrollList({ footerFixed: footerFixedProp, headerFixed: headerFixedProp, isHorizontal, keyboardAware, pullSearchHeight, style });
|
|
437
|
+
const scrollTo = useCallback3((offset, animated) => {
|
|
438
|
+
scrollView.current?.scrollToOffset({ offset, animated });
|
|
439
|
+
}, []);
|
|
440
|
+
const {
|
|
441
|
+
activeListHeader: pullSearchHeader,
|
|
442
|
+
handleMomentumScrollEnd,
|
|
443
|
+
handleScrollBeginDrag,
|
|
444
|
+
handleScrollEndDrag,
|
|
445
|
+
hiddenHeader,
|
|
446
|
+
pullSearchMinHeight
|
|
447
|
+
} = useScrollInit({
|
|
448
|
+
listHeaderComponent: externalListHeaderComponent,
|
|
449
|
+
onMomentumScrollEnd: externalMomentumScrollEnd,
|
|
450
|
+
onRefresh: pullSearchHeight ? onRefresh : void 0,
|
|
451
|
+
onScrollBeginDrag: externalScrollBeginDrag,
|
|
452
|
+
onScrollEndDrag: externalScrollEndDrag,
|
|
453
|
+
pullSearchHeight,
|
|
454
|
+
scrollTo
|
|
455
|
+
});
|
|
456
|
+
const activeListHeader = useMemo3(() => {
|
|
457
|
+
if (!renderFilters) return pullSearchHeader;
|
|
458
|
+
const Inner = pullSearchHeader;
|
|
459
|
+
return () => /* @__PURE__ */ jsxs3(Fragment2, { children: [
|
|
460
|
+
Inner ? typeof Inner === "function" ? /* @__PURE__ */ jsx5(Inner, {}) : Inner : null,
|
|
461
|
+
renderFilters
|
|
462
|
+
] });
|
|
463
|
+
}, [pullSearchHeader, renderFilters]);
|
|
464
|
+
const contentContainerStyle = useMemo3(() => isHorizontal ? externalContentContainerStyle : [{ minHeight: Dimensions2.get("window").height - contentInset.top - contentInset.bottom + pullSearchMinHeight }, externalContentContainerStyle], [isHorizontal, contentInset.bottom, contentInset.top, externalContentContainerStyle, pullSearchMinHeight]);
|
|
465
|
+
const onPullSearchZoneEnter = useCallback3(() => {
|
|
466
|
+
if (!pullSearchHeight) return;
|
|
467
|
+
scrollView.current?.scrollToOffset({ offset: -contentInset.top + pullSearchHeight, animated: true });
|
|
468
|
+
}, [contentInset.top, pullSearchHeight]);
|
|
469
|
+
const handleScroll = useScrollHandler({ chipHidden, footerFixed, headerFixed, isHorizontal, onPullSearchZoneEnter: pullSearchHeight ? onPullSearchZoneEnter : void 0 });
|
|
470
|
+
const handleScrollToTop = useCallback3(() => {
|
|
471
|
+
if (isHorizontal) {
|
|
472
|
+
scrollView.current?.scrollToOffset({ offset: 0, animated: true });
|
|
473
|
+
return;
|
|
474
|
+
}
|
|
475
|
+
const offset = pullSearchHeight ? -contentInset.top + pullSearchHeight : -contentInset.top;
|
|
476
|
+
scrollView.current?.scrollToOffset({ offset, animated: true });
|
|
477
|
+
}, [isHorizontal, contentInset.top, pullSearchHeight]);
|
|
478
|
+
const handleContentSizeChange = useCallback3(
|
|
479
|
+
(w, h) => {
|
|
480
|
+
if (onContentSizeChange) onContentSizeChange(w, h);
|
|
481
|
+
},
|
|
482
|
+
[onContentSizeChange]
|
|
483
|
+
);
|
|
484
|
+
const refreshControl = useMemo3(() => /* @__PURE__ */ jsx5(RefreshControl, {}), []);
|
|
485
|
+
const nativeGesture = useMemo3(() => Gesture2.Native(), []);
|
|
486
|
+
const combinedGesture = useMemo3(() => gesture !== void 0 ? Gesture2.Simultaneous(gesture, nativeGesture) : nativeGesture, [gesture, nativeGesture]);
|
|
487
|
+
const detectorGesture = gesture !== void 0 ? combinedGesture : void 0;
|
|
488
|
+
const content = /* @__PURE__ */ jsxs3(View3, { style: containerStyle, children: [
|
|
489
|
+
/* @__PURE__ */ jsx5(
|
|
490
|
+
Animated3.FlatList,
|
|
491
|
+
{
|
|
492
|
+
...props,
|
|
493
|
+
contentContainerStyle,
|
|
494
|
+
contentInset,
|
|
495
|
+
contentOffset,
|
|
496
|
+
data,
|
|
497
|
+
horizontal: isHorizontal,
|
|
498
|
+
initialNumToRender,
|
|
499
|
+
ListHeaderComponent: activeListHeader,
|
|
500
|
+
maxToRenderPerBatch,
|
|
501
|
+
onContentSizeChange: handleContentSizeChange,
|
|
502
|
+
onMomentumScrollEnd: handleMomentumScrollEnd,
|
|
503
|
+
onScroll: handleScroll,
|
|
504
|
+
onScrollBeginDrag: handleScrollBeginDrag,
|
|
505
|
+
onScrollEndDrag: handleScrollEndDrag,
|
|
506
|
+
pagingEnabled,
|
|
507
|
+
ref: (el) => {
|
|
508
|
+
if (externalRef) externalRef.current = el;
|
|
509
|
+
scrollView.current = el;
|
|
510
|
+
},
|
|
511
|
+
refreshControl,
|
|
512
|
+
removeClippedSubviews,
|
|
513
|
+
scrollEventThrottle: 16,
|
|
514
|
+
showsHorizontalScrollIndicator: showsHorizontalScrollIndicator ?? isHorizontal,
|
|
515
|
+
showsVerticalScrollIndicator: showsVerticalScrollIndicator ?? !isHorizontal,
|
|
516
|
+
windowSize
|
|
517
|
+
}
|
|
518
|
+
),
|
|
519
|
+
hiddenHeader && /* @__PURE__ */ jsx5(View3, { pointerEvents: "none", style: styles4.measureContainer, children: hiddenHeader }),
|
|
520
|
+
/* @__PURE__ */ jsx5(ScrollViewChip, { isHorizontal, onPress: handleScrollToTop, style: chipStyle }),
|
|
521
|
+
showDots && /* @__PURE__ */ jsx5(HorizontalDots, { total: data?.length ?? 0 })
|
|
522
|
+
] });
|
|
523
|
+
return detectorGesture ? /* @__PURE__ */ jsx5(GestureDetector2, { gesture: detectorGesture, children: content }) : content;
|
|
524
|
+
};
|
|
525
|
+
var styles4 = { measureContainer: { left: 0, opacity: 0, position: "absolute", right: 0, top: -9999 } };
|
|
526
|
+
var FlatList = memo2(FlatListInner);
|
|
527
|
+
|
|
528
|
+
// src/PullSearch.tsx
|
|
529
|
+
import { forwardRef, useCallback as useCallback4, useContext as useContext5, useEffect as useEffect3, useImperativeHandle, useRef as useRef4, useState as useState3 } from "react";
|
|
530
|
+
import { StyleSheet as StyleSheet4 } from "react-native";
|
|
531
|
+
import { Searchbar, useTheme as useTheme2 } from "react-native-paper";
|
|
532
|
+
import Animated4, { Extrapolation, interpolate, runOnJS as runOnJS3, useAnimatedReaction, useAnimatedStyle as useAnimatedStyle3 } from "react-native-reanimated";
|
|
533
|
+
import { jsx as jsx6 } from "react/jsx-runtime";
|
|
534
|
+
var PullSearch = forwardRef(function PullSearch2({ debounce, onChangeText, onHeightChange, placeholder, value: propValue }, ref) {
|
|
535
|
+
const { headerHeight, scrollPosition } = useContext5(ScrollViewContext);
|
|
536
|
+
const theme = useTheme2();
|
|
537
|
+
const inputRef = useRef4(null);
|
|
538
|
+
const [barHeight, setBarHeight] = useState3(0);
|
|
539
|
+
const [value, setValue] = useState3(propValue ?? "");
|
|
540
|
+
const prevPropValueRef = useRef4(propValue);
|
|
541
|
+
useEffect3(() => {
|
|
542
|
+
if (prevPropValueRef.current === propValue) return;
|
|
543
|
+
prevPropValueRef.current = propValue;
|
|
544
|
+
setValue(propValue ?? "");
|
|
545
|
+
}, [propValue]);
|
|
546
|
+
useImperativeHandle(ref, () => ({
|
|
547
|
+
blur: () => inputRef.current?.blur(),
|
|
548
|
+
focus: () => inputRef.current?.focus()
|
|
549
|
+
}));
|
|
550
|
+
const blurInput = useCallback4(() => inputRef.current?.blur(), []);
|
|
551
|
+
useAnimatedReaction(
|
|
552
|
+
() => {
|
|
553
|
+
if (barHeight === 0) return false;
|
|
554
|
+
return scrollPosition.value >= -headerHeight + barHeight;
|
|
555
|
+
},
|
|
556
|
+
(isHidden, wasHidden) => {
|
|
557
|
+
if (isHidden && !wasHidden) runOnJS3(blurInput)();
|
|
558
|
+
},
|
|
559
|
+
[barHeight, headerHeight, blurInput]
|
|
560
|
+
);
|
|
561
|
+
const handleClear = useCallback4(() => {
|
|
562
|
+
setValue("");
|
|
563
|
+
onChangeText("");
|
|
564
|
+
}, [onChangeText]);
|
|
565
|
+
const handleLayout = useCallback4(
|
|
566
|
+
({
|
|
567
|
+
nativeEvent: {
|
|
568
|
+
layout: { height }
|
|
569
|
+
}
|
|
570
|
+
}) => {
|
|
571
|
+
setBarHeight(height);
|
|
572
|
+
onHeightChange(height);
|
|
573
|
+
},
|
|
574
|
+
[onHeightChange]
|
|
575
|
+
);
|
|
576
|
+
useEffect3(() => {
|
|
577
|
+
const normalizedValue = value.trim();
|
|
578
|
+
if (debounce) {
|
|
579
|
+
const timeout = setTimeout(() => onChangeText(normalizedValue), 500);
|
|
580
|
+
return () => clearTimeout(timeout);
|
|
581
|
+
}
|
|
582
|
+
onChangeText(normalizedValue);
|
|
583
|
+
}, [debounce, onChangeText, value]);
|
|
584
|
+
const animatedStyle = useAnimatedStyle3(() => {
|
|
585
|
+
if (barHeight === 0) return { opacity: 0 };
|
|
586
|
+
const showY = -headerHeight;
|
|
587
|
+
const hideY = -headerHeight + barHeight;
|
|
588
|
+
return { opacity: interpolate(scrollPosition.value, [showY, hideY], [1, 0], Extrapolation.CLAMP) };
|
|
589
|
+
}, [barHeight, headerHeight]);
|
|
590
|
+
return /* @__PURE__ */ jsx6(Animated4.View, { onLayout: handleLayout, style: [styles5.container, animatedStyle], children: /* @__PURE__ */ jsx6(Searchbar, { autoCorrect: false, onChangeText: (text) => setValue((text || "").trimStart()), onClearIconPress: handleClear, placeholder, placeholderTextColor: theme.colors.onSurfaceVariant, ref: inputRef, spellCheck: false, style: styles5.input, value }) });
|
|
591
|
+
});
|
|
592
|
+
var styles5 = StyleSheet4.create({
|
|
593
|
+
container: { paddingVertical: 8 },
|
|
594
|
+
input: { margin: 0 }
|
|
595
|
+
});
|
|
596
|
+
|
|
597
|
+
// node_modules/redux/dist/redux.mjs
|
|
598
|
+
var randomString = () => Math.random().toString(36).substring(7).split("").join(".");
|
|
599
|
+
var ActionTypes = {
|
|
600
|
+
INIT: `@@redux/INIT${/* @__PURE__ */ randomString()}`,
|
|
601
|
+
REPLACE: `@@redux/REPLACE${/* @__PURE__ */ randomString()}`,
|
|
602
|
+
PROBE_UNKNOWN_ACTION: () => `@@redux/PROBE_UNKNOWN_ACTION${randomString()}`
|
|
603
|
+
};
|
|
604
|
+
function isPlainObject(obj) {
|
|
605
|
+
if (typeof obj !== "object" || obj === null)
|
|
606
|
+
return false;
|
|
607
|
+
let proto = obj;
|
|
608
|
+
while (Object.getPrototypeOf(proto) !== null) {
|
|
609
|
+
proto = Object.getPrototypeOf(proto);
|
|
610
|
+
}
|
|
611
|
+
return Object.getPrototypeOf(obj) === proto || Object.getPrototypeOf(obj) === null;
|
|
612
|
+
}
|
|
613
|
+
function compose(...funcs) {
|
|
614
|
+
if (funcs.length === 0) {
|
|
615
|
+
return (arg) => arg;
|
|
616
|
+
}
|
|
617
|
+
if (funcs.length === 1) {
|
|
618
|
+
return funcs[0];
|
|
619
|
+
}
|
|
620
|
+
return funcs.reduce((a, b) => (...args) => a(b(...args)));
|
|
621
|
+
}
|
|
622
|
+
function isAction(action) {
|
|
623
|
+
return isPlainObject(action) && "type" in action && typeof action.type === "string";
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// node_modules/immer/dist/immer.mjs
|
|
627
|
+
var NOTHING = /* @__PURE__ */ Symbol.for("immer-nothing");
|
|
628
|
+
var DRAFTABLE = /* @__PURE__ */ Symbol.for("immer-draftable");
|
|
629
|
+
var DRAFT_STATE = /* @__PURE__ */ Symbol.for("immer-state");
|
|
630
|
+
var errors = process.env.NODE_ENV !== "production" ? [
|
|
631
|
+
// All error codes, starting by 0:
|
|
632
|
+
function(plugin) {
|
|
633
|
+
return `The plugin for '${plugin}' has not been loaded into Immer. To enable the plugin, import and call \`enable${plugin}()\` when initializing your application.`;
|
|
634
|
+
},
|
|
635
|
+
function(thing) {
|
|
636
|
+
return `produce can only be called on things that are draftable: plain objects, arrays, Map, Set or classes that are marked with '[immerable]: true'. Got '${thing}'`;
|
|
637
|
+
},
|
|
638
|
+
"This object has been frozen and should not be mutated",
|
|
639
|
+
function(data) {
|
|
640
|
+
return "Cannot use a proxy that has been revoked. Did you pass an object from inside an immer function to an async process? " + data;
|
|
641
|
+
},
|
|
642
|
+
"An immer producer returned a new value *and* modified its draft. Either return a new value *or* modify the draft.",
|
|
643
|
+
"Immer forbids circular references",
|
|
644
|
+
"The first or second argument to `produce` must be a function",
|
|
645
|
+
"The third argument to `produce` must be a function or undefined",
|
|
646
|
+
"First argument to `createDraft` must be a plain object, an array, or an immerable object",
|
|
647
|
+
"First argument to `finishDraft` must be a draft returned by `createDraft`",
|
|
648
|
+
function(thing) {
|
|
649
|
+
return `'current' expects a draft, got: ${thing}`;
|
|
650
|
+
},
|
|
651
|
+
"Object.defineProperty() cannot be used on an Immer draft",
|
|
652
|
+
"Object.setPrototypeOf() cannot be used on an Immer draft",
|
|
653
|
+
"Immer only supports deleting array indices",
|
|
654
|
+
"Immer only supports setting array indices and the 'length' property",
|
|
655
|
+
function(thing) {
|
|
656
|
+
return `'original' expects a draft, got: ${thing}`;
|
|
657
|
+
}
|
|
658
|
+
// Note: if more errors are added, the errorOffset in Patches.ts should be increased
|
|
659
|
+
// See Patches.ts for additional errors
|
|
660
|
+
] : [];
|
|
661
|
+
function die(error, ...args) {
|
|
662
|
+
if (process.env.NODE_ENV !== "production") {
|
|
663
|
+
const e = errors[error];
|
|
664
|
+
const msg = isFunction(e) ? e.apply(null, args) : e;
|
|
665
|
+
throw new Error(`[Immer] ${msg}`);
|
|
666
|
+
}
|
|
667
|
+
throw new Error(
|
|
668
|
+
`[Immer] minified error nr: ${error}. Full error at: https://bit.ly/3cXEKWf`
|
|
669
|
+
);
|
|
670
|
+
}
|
|
671
|
+
var O = Object;
|
|
672
|
+
var getPrototypeOf = O.getPrototypeOf;
|
|
673
|
+
var CONSTRUCTOR = "constructor";
|
|
674
|
+
var PROTOTYPE = "prototype";
|
|
675
|
+
var CONFIGURABLE = "configurable";
|
|
676
|
+
var ENUMERABLE = "enumerable";
|
|
677
|
+
var WRITABLE = "writable";
|
|
678
|
+
var VALUE = "value";
|
|
679
|
+
var isDraft = (value) => !!value && !!value[DRAFT_STATE];
|
|
680
|
+
function isDraftable(value) {
|
|
681
|
+
if (!value)
|
|
682
|
+
return false;
|
|
683
|
+
return isPlainObject2(value) || isArray(value) || !!value[DRAFTABLE] || !!value[CONSTRUCTOR]?.[DRAFTABLE] || isMap(value) || isSet(value);
|
|
684
|
+
}
|
|
685
|
+
var objectCtorString = O[PROTOTYPE][CONSTRUCTOR].toString();
|
|
686
|
+
var cachedCtorStrings = /* @__PURE__ */ new WeakMap();
|
|
687
|
+
function isPlainObject2(value) {
|
|
688
|
+
if (!value || !isObjectish(value))
|
|
689
|
+
return false;
|
|
690
|
+
const proto = getPrototypeOf(value);
|
|
691
|
+
if (proto === null || proto === O[PROTOTYPE])
|
|
692
|
+
return true;
|
|
693
|
+
const Ctor = O.hasOwnProperty.call(proto, CONSTRUCTOR) && proto[CONSTRUCTOR];
|
|
694
|
+
if (Ctor === Object)
|
|
695
|
+
return true;
|
|
696
|
+
if (!isFunction(Ctor))
|
|
697
|
+
return false;
|
|
698
|
+
let ctorString = cachedCtorStrings.get(Ctor);
|
|
699
|
+
if (ctorString === void 0) {
|
|
700
|
+
ctorString = Function.toString.call(Ctor);
|
|
701
|
+
cachedCtorStrings.set(Ctor, ctorString);
|
|
702
|
+
}
|
|
703
|
+
return ctorString === objectCtorString;
|
|
704
|
+
}
|
|
705
|
+
function each(obj, iter, strict = true) {
|
|
706
|
+
if (getArchtype(obj) === 0) {
|
|
707
|
+
const keys = strict ? Reflect.ownKeys(obj) : O.keys(obj);
|
|
708
|
+
keys.forEach((key) => {
|
|
709
|
+
iter(key, obj[key], obj);
|
|
710
|
+
});
|
|
711
|
+
} else {
|
|
712
|
+
obj.forEach((entry, index) => iter(index, entry, obj));
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
function getArchtype(thing) {
|
|
716
|
+
const state = thing[DRAFT_STATE];
|
|
717
|
+
return state ? state.type_ : isArray(thing) ? 1 : isMap(thing) ? 2 : isSet(thing) ? 3 : 0;
|
|
718
|
+
}
|
|
719
|
+
var has = (thing, prop, type = getArchtype(thing)) => type === 2 ? thing.has(prop) : O[PROTOTYPE].hasOwnProperty.call(thing, prop);
|
|
720
|
+
var get = (thing, prop, type = getArchtype(thing)) => (
|
|
721
|
+
// @ts-ignore
|
|
722
|
+
type === 2 ? thing.get(prop) : thing[prop]
|
|
723
|
+
);
|
|
724
|
+
var set = (thing, propOrOldValue, value, type = getArchtype(thing)) => {
|
|
725
|
+
if (type === 2)
|
|
726
|
+
thing.set(propOrOldValue, value);
|
|
727
|
+
else if (type === 3) {
|
|
728
|
+
thing.add(value);
|
|
729
|
+
} else
|
|
730
|
+
thing[propOrOldValue] = value;
|
|
731
|
+
};
|
|
732
|
+
function is(x, y) {
|
|
733
|
+
if (x === y) {
|
|
734
|
+
return x !== 0 || 1 / x === 1 / y;
|
|
735
|
+
} else {
|
|
736
|
+
return x !== x && y !== y;
|
|
737
|
+
}
|
|
738
|
+
}
|
|
739
|
+
var isArray = Array.isArray;
|
|
740
|
+
var isMap = (target) => target instanceof Map;
|
|
741
|
+
var isSet = (target) => target instanceof Set;
|
|
742
|
+
var isObjectish = (target) => typeof target === "object";
|
|
743
|
+
var isFunction = (target) => typeof target === "function";
|
|
744
|
+
var isBoolean = (target) => typeof target === "boolean";
|
|
745
|
+
function isArrayIndex(value) {
|
|
746
|
+
const n = +value;
|
|
747
|
+
return Number.isInteger(n) && String(n) === value;
|
|
748
|
+
}
|
|
749
|
+
var latest = (state) => state.copy_ || state.base_;
|
|
750
|
+
var getFinalValue = (state) => state.modified_ ? state.copy_ : state.base_;
|
|
751
|
+
function shallowCopy(base, strict) {
|
|
752
|
+
if (isMap(base)) {
|
|
753
|
+
return new Map(base);
|
|
754
|
+
}
|
|
755
|
+
if (isSet(base)) {
|
|
756
|
+
return new Set(base);
|
|
757
|
+
}
|
|
758
|
+
if (isArray(base))
|
|
759
|
+
return Array[PROTOTYPE].slice.call(base);
|
|
760
|
+
const isPlain = isPlainObject2(base);
|
|
761
|
+
if (strict === true || strict === "class_only" && !isPlain) {
|
|
762
|
+
const descriptors = O.getOwnPropertyDescriptors(base);
|
|
763
|
+
delete descriptors[DRAFT_STATE];
|
|
764
|
+
let keys = Reflect.ownKeys(descriptors);
|
|
765
|
+
for (let i = 0; i < keys.length; i++) {
|
|
766
|
+
const key = keys[i];
|
|
767
|
+
const desc = descriptors[key];
|
|
768
|
+
if (desc[WRITABLE] === false) {
|
|
769
|
+
desc[WRITABLE] = true;
|
|
770
|
+
desc[CONFIGURABLE] = true;
|
|
771
|
+
}
|
|
772
|
+
if (desc.get || desc.set)
|
|
773
|
+
descriptors[key] = {
|
|
774
|
+
[CONFIGURABLE]: true,
|
|
775
|
+
[WRITABLE]: true,
|
|
776
|
+
// could live with !!desc.set as well here...
|
|
777
|
+
[ENUMERABLE]: desc[ENUMERABLE],
|
|
778
|
+
[VALUE]: base[key]
|
|
779
|
+
};
|
|
780
|
+
}
|
|
781
|
+
return O.create(getPrototypeOf(base), descriptors);
|
|
782
|
+
} else {
|
|
783
|
+
const proto = getPrototypeOf(base);
|
|
784
|
+
if (proto !== null && isPlain) {
|
|
785
|
+
return { ...base };
|
|
786
|
+
}
|
|
787
|
+
const obj = O.create(proto);
|
|
788
|
+
return O.assign(obj, base);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
791
|
+
function freeze(obj, deep = false) {
|
|
792
|
+
if (isFrozen(obj) || isDraft(obj) || !isDraftable(obj))
|
|
793
|
+
return obj;
|
|
794
|
+
if (getArchtype(obj) > 1) {
|
|
795
|
+
O.defineProperties(obj, {
|
|
796
|
+
set: dontMutateMethodOverride,
|
|
797
|
+
add: dontMutateMethodOverride,
|
|
798
|
+
clear: dontMutateMethodOverride,
|
|
799
|
+
delete: dontMutateMethodOverride
|
|
800
|
+
});
|
|
801
|
+
}
|
|
802
|
+
O.freeze(obj);
|
|
803
|
+
if (deep)
|
|
804
|
+
each(
|
|
805
|
+
obj,
|
|
806
|
+
(_key, value) => {
|
|
807
|
+
freeze(value, true);
|
|
808
|
+
},
|
|
809
|
+
false
|
|
810
|
+
);
|
|
811
|
+
return obj;
|
|
812
|
+
}
|
|
813
|
+
function dontMutateFrozenCollections() {
|
|
814
|
+
die(2);
|
|
815
|
+
}
|
|
816
|
+
var dontMutateMethodOverride = {
|
|
817
|
+
[VALUE]: dontMutateFrozenCollections
|
|
818
|
+
};
|
|
819
|
+
function isFrozen(obj) {
|
|
820
|
+
if (obj === null || !isObjectish(obj))
|
|
821
|
+
return true;
|
|
822
|
+
return O.isFrozen(obj);
|
|
823
|
+
}
|
|
824
|
+
var PluginMapSet = "MapSet";
|
|
825
|
+
var PluginPatches = "Patches";
|
|
826
|
+
var PluginArrayMethods = "ArrayMethods";
|
|
827
|
+
var plugins = {};
|
|
828
|
+
function getPlugin(pluginKey) {
|
|
829
|
+
const plugin = plugins[pluginKey];
|
|
830
|
+
if (!plugin) {
|
|
831
|
+
die(0, pluginKey);
|
|
832
|
+
}
|
|
833
|
+
return plugin;
|
|
834
|
+
}
|
|
835
|
+
var isPluginLoaded = (pluginKey) => !!plugins[pluginKey];
|
|
836
|
+
var currentScope;
|
|
837
|
+
var getCurrentScope = () => currentScope;
|
|
838
|
+
var createScope = (parent_, immer_) => ({
|
|
839
|
+
drafts_: [],
|
|
840
|
+
parent_,
|
|
841
|
+
immer_,
|
|
842
|
+
// Whenever the modified draft contains a draft from another scope, we
|
|
843
|
+
// need to prevent auto-freezing so the unowned draft can be finalized.
|
|
844
|
+
canAutoFreeze_: true,
|
|
845
|
+
unfinalizedDrafts_: 0,
|
|
846
|
+
handledSet_: /* @__PURE__ */ new Set(),
|
|
847
|
+
processedForPatches_: /* @__PURE__ */ new Set(),
|
|
848
|
+
mapSetPlugin_: isPluginLoaded(PluginMapSet) ? getPlugin(PluginMapSet) : void 0,
|
|
849
|
+
arrayMethodsPlugin_: isPluginLoaded(PluginArrayMethods) ? getPlugin(PluginArrayMethods) : void 0
|
|
850
|
+
});
|
|
851
|
+
function usePatchesInScope(scope, patchListener) {
|
|
852
|
+
if (patchListener) {
|
|
853
|
+
scope.patchPlugin_ = getPlugin(PluginPatches);
|
|
854
|
+
scope.patches_ = [];
|
|
855
|
+
scope.inversePatches_ = [];
|
|
856
|
+
scope.patchListener_ = patchListener;
|
|
857
|
+
}
|
|
858
|
+
}
|
|
859
|
+
function revokeScope(scope) {
|
|
860
|
+
leaveScope(scope);
|
|
861
|
+
scope.drafts_.forEach(revokeDraft);
|
|
862
|
+
scope.drafts_ = null;
|
|
863
|
+
}
|
|
864
|
+
function leaveScope(scope) {
|
|
865
|
+
if (scope === currentScope) {
|
|
866
|
+
currentScope = scope.parent_;
|
|
867
|
+
}
|
|
868
|
+
}
|
|
869
|
+
var enterScope = (immer2) => currentScope = createScope(currentScope, immer2);
|
|
870
|
+
function revokeDraft(draft) {
|
|
871
|
+
const state = draft[DRAFT_STATE];
|
|
872
|
+
if (state.type_ === 0 || state.type_ === 1)
|
|
873
|
+
state.revoke_();
|
|
874
|
+
else
|
|
875
|
+
state.revoked_ = true;
|
|
876
|
+
}
|
|
877
|
+
function processResult(result, scope) {
|
|
878
|
+
scope.unfinalizedDrafts_ = scope.drafts_.length;
|
|
879
|
+
const baseDraft = scope.drafts_[0];
|
|
880
|
+
const isReplaced = result !== void 0 && result !== baseDraft;
|
|
881
|
+
if (isReplaced) {
|
|
882
|
+
if (baseDraft[DRAFT_STATE].modified_) {
|
|
883
|
+
revokeScope(scope);
|
|
884
|
+
die(4);
|
|
885
|
+
}
|
|
886
|
+
if (isDraftable(result)) {
|
|
887
|
+
result = finalize(scope, result);
|
|
888
|
+
}
|
|
889
|
+
const { patchPlugin_ } = scope;
|
|
890
|
+
if (patchPlugin_) {
|
|
891
|
+
patchPlugin_.generateReplacementPatches_(
|
|
892
|
+
baseDraft[DRAFT_STATE].base_,
|
|
893
|
+
result,
|
|
894
|
+
scope
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
} else {
|
|
898
|
+
result = finalize(scope, baseDraft);
|
|
899
|
+
}
|
|
900
|
+
maybeFreeze(scope, result, true);
|
|
901
|
+
revokeScope(scope);
|
|
902
|
+
if (scope.patches_) {
|
|
903
|
+
scope.patchListener_(scope.patches_, scope.inversePatches_);
|
|
904
|
+
}
|
|
905
|
+
return result !== NOTHING ? result : void 0;
|
|
906
|
+
}
|
|
907
|
+
function finalize(rootScope, value) {
|
|
908
|
+
if (isFrozen(value))
|
|
909
|
+
return value;
|
|
910
|
+
const state = value[DRAFT_STATE];
|
|
911
|
+
if (!state) {
|
|
912
|
+
const finalValue = handleValue(value, rootScope.handledSet_, rootScope);
|
|
913
|
+
return finalValue;
|
|
914
|
+
}
|
|
915
|
+
if (!isSameScope(state, rootScope)) {
|
|
916
|
+
return value;
|
|
917
|
+
}
|
|
918
|
+
if (!state.modified_) {
|
|
919
|
+
return state.base_;
|
|
920
|
+
}
|
|
921
|
+
if (!state.finalized_) {
|
|
922
|
+
const { callbacks_ } = state;
|
|
923
|
+
if (callbacks_) {
|
|
924
|
+
while (callbacks_.length > 0) {
|
|
925
|
+
const callback = callbacks_.pop();
|
|
926
|
+
callback(rootScope);
|
|
927
|
+
}
|
|
928
|
+
}
|
|
929
|
+
generatePatchesAndFinalize(state, rootScope);
|
|
930
|
+
}
|
|
931
|
+
return state.copy_;
|
|
932
|
+
}
|
|
933
|
+
function maybeFreeze(scope, value, deep = false) {
|
|
934
|
+
if (!scope.parent_ && scope.immer_.autoFreeze_ && scope.canAutoFreeze_) {
|
|
935
|
+
freeze(value, deep);
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
function markStateFinalized(state) {
|
|
939
|
+
state.finalized_ = true;
|
|
940
|
+
state.scope_.unfinalizedDrafts_--;
|
|
941
|
+
}
|
|
942
|
+
var isSameScope = (state, rootScope) => state.scope_ === rootScope;
|
|
943
|
+
var EMPTY_LOCATIONS_RESULT = [];
|
|
944
|
+
function updateDraftInParent(parent, draftValue, finalizedValue, originalKey) {
|
|
945
|
+
const parentCopy = latest(parent);
|
|
946
|
+
const parentType = parent.type_;
|
|
947
|
+
if (originalKey !== void 0) {
|
|
948
|
+
const currentValue = get(parentCopy, originalKey, parentType);
|
|
949
|
+
if (currentValue === draftValue) {
|
|
950
|
+
set(parentCopy, originalKey, finalizedValue, parentType);
|
|
951
|
+
return;
|
|
952
|
+
}
|
|
953
|
+
}
|
|
954
|
+
if (!parent.draftLocations_) {
|
|
955
|
+
const draftLocations = parent.draftLocations_ = /* @__PURE__ */ new Map();
|
|
956
|
+
each(parentCopy, (key, value) => {
|
|
957
|
+
if (isDraft(value)) {
|
|
958
|
+
const keys = draftLocations.get(value) || [];
|
|
959
|
+
keys.push(key);
|
|
960
|
+
draftLocations.set(value, keys);
|
|
961
|
+
}
|
|
962
|
+
});
|
|
963
|
+
}
|
|
964
|
+
const locations = parent.draftLocations_.get(draftValue) ?? EMPTY_LOCATIONS_RESULT;
|
|
965
|
+
for (const location of locations) {
|
|
966
|
+
set(parentCopy, location, finalizedValue, parentType);
|
|
967
|
+
}
|
|
968
|
+
}
|
|
969
|
+
function registerChildFinalizationCallback(parent, child, key) {
|
|
970
|
+
parent.callbacks_.push(function childCleanup(rootScope) {
|
|
971
|
+
const state = child;
|
|
972
|
+
if (!state || !isSameScope(state, rootScope)) {
|
|
973
|
+
return;
|
|
974
|
+
}
|
|
975
|
+
rootScope.mapSetPlugin_?.fixSetContents(state);
|
|
976
|
+
const finalizedValue = getFinalValue(state);
|
|
977
|
+
updateDraftInParent(parent, state.draft_ ?? state, finalizedValue, key);
|
|
978
|
+
generatePatchesAndFinalize(state, rootScope);
|
|
979
|
+
});
|
|
980
|
+
}
|
|
981
|
+
function generatePatchesAndFinalize(state, rootScope) {
|
|
982
|
+
const shouldFinalize = state.modified_ && !state.finalized_ && (state.type_ === 3 || state.type_ === 1 && state.allIndicesReassigned_ || (state.assigned_?.size ?? 0) > 0);
|
|
983
|
+
if (shouldFinalize) {
|
|
984
|
+
const { patchPlugin_ } = rootScope;
|
|
985
|
+
if (patchPlugin_) {
|
|
986
|
+
const basePath = patchPlugin_.getPath(state);
|
|
987
|
+
if (basePath) {
|
|
988
|
+
patchPlugin_.generatePatches_(state, basePath, rootScope);
|
|
989
|
+
}
|
|
990
|
+
}
|
|
991
|
+
markStateFinalized(state);
|
|
992
|
+
}
|
|
993
|
+
}
|
|
994
|
+
function handleCrossReference(target, key, value) {
|
|
995
|
+
const { scope_ } = target;
|
|
996
|
+
if (isDraft(value)) {
|
|
997
|
+
const state = value[DRAFT_STATE];
|
|
998
|
+
if (isSameScope(state, scope_)) {
|
|
999
|
+
state.callbacks_.push(function crossReferenceCleanup() {
|
|
1000
|
+
prepareCopy(target);
|
|
1001
|
+
const finalizedValue = getFinalValue(state);
|
|
1002
|
+
updateDraftInParent(target, value, finalizedValue, key);
|
|
1003
|
+
});
|
|
1004
|
+
}
|
|
1005
|
+
} else if (isDraftable(value)) {
|
|
1006
|
+
target.callbacks_.push(function nestedDraftCleanup() {
|
|
1007
|
+
const targetCopy = latest(target);
|
|
1008
|
+
if (target.type_ === 3) {
|
|
1009
|
+
if (targetCopy.has(value)) {
|
|
1010
|
+
handleValue(value, scope_.handledSet_, scope_);
|
|
1011
|
+
}
|
|
1012
|
+
} else {
|
|
1013
|
+
if (get(targetCopy, key, target.type_) === value) {
|
|
1014
|
+
if (scope_.drafts_.length > 1 && (target.assigned_.get(key) ?? false) === true && target.copy_) {
|
|
1015
|
+
handleValue(
|
|
1016
|
+
get(target.copy_, key, target.type_),
|
|
1017
|
+
scope_.handledSet_,
|
|
1018
|
+
scope_
|
|
1019
|
+
);
|
|
1020
|
+
}
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
});
|
|
1024
|
+
}
|
|
1025
|
+
}
|
|
1026
|
+
function handleValue(target, handledSet, rootScope) {
|
|
1027
|
+
if (!rootScope.immer_.autoFreeze_ && rootScope.unfinalizedDrafts_ < 1) {
|
|
1028
|
+
return target;
|
|
1029
|
+
}
|
|
1030
|
+
if (isDraft(target) || handledSet.has(target) || !isDraftable(target) || isFrozen(target)) {
|
|
1031
|
+
return target;
|
|
1032
|
+
}
|
|
1033
|
+
handledSet.add(target);
|
|
1034
|
+
each(target, (key, value) => {
|
|
1035
|
+
if (isDraft(value)) {
|
|
1036
|
+
const state = value[DRAFT_STATE];
|
|
1037
|
+
if (isSameScope(state, rootScope)) {
|
|
1038
|
+
const updatedValue = getFinalValue(state);
|
|
1039
|
+
set(target, key, updatedValue, target.type_);
|
|
1040
|
+
markStateFinalized(state);
|
|
1041
|
+
}
|
|
1042
|
+
} else if (isDraftable(value)) {
|
|
1043
|
+
handleValue(value, handledSet, rootScope);
|
|
1044
|
+
}
|
|
1045
|
+
});
|
|
1046
|
+
return target;
|
|
1047
|
+
}
|
|
1048
|
+
function createProxyProxy(base, parent) {
|
|
1049
|
+
const baseIsArray = isArray(base);
|
|
1050
|
+
const state = {
|
|
1051
|
+
type_: baseIsArray ? 1 : 0,
|
|
1052
|
+
// Track which produce call this is associated with.
|
|
1053
|
+
scope_: parent ? parent.scope_ : getCurrentScope(),
|
|
1054
|
+
// True for both shallow and deep changes.
|
|
1055
|
+
modified_: false,
|
|
1056
|
+
// Used during finalization.
|
|
1057
|
+
finalized_: false,
|
|
1058
|
+
// Track which properties have been assigned (true) or deleted (false).
|
|
1059
|
+
// actually instantiated in `prepareCopy()`
|
|
1060
|
+
assigned_: void 0,
|
|
1061
|
+
// The parent draft state.
|
|
1062
|
+
parent_: parent,
|
|
1063
|
+
// The base state.
|
|
1064
|
+
base_: base,
|
|
1065
|
+
// The base proxy.
|
|
1066
|
+
draft_: null,
|
|
1067
|
+
// set below
|
|
1068
|
+
// The base copy with any updated values.
|
|
1069
|
+
copy_: null,
|
|
1070
|
+
// Called by the `produce` function.
|
|
1071
|
+
revoke_: null,
|
|
1072
|
+
isManual_: false,
|
|
1073
|
+
// `callbacks` actually gets assigned in `createProxy`
|
|
1074
|
+
callbacks_: void 0
|
|
1075
|
+
};
|
|
1076
|
+
let target = state;
|
|
1077
|
+
let traps = objectTraps;
|
|
1078
|
+
if (baseIsArray) {
|
|
1079
|
+
target = [state];
|
|
1080
|
+
traps = arrayTraps;
|
|
1081
|
+
}
|
|
1082
|
+
const { revoke, proxy } = Proxy.revocable(target, traps);
|
|
1083
|
+
state.draft_ = proxy;
|
|
1084
|
+
state.revoke_ = revoke;
|
|
1085
|
+
return [proxy, state];
|
|
1086
|
+
}
|
|
1087
|
+
var objectTraps = {
|
|
1088
|
+
get(state, prop) {
|
|
1089
|
+
if (prop === DRAFT_STATE)
|
|
1090
|
+
return state;
|
|
1091
|
+
let arrayPlugin = state.scope_.arrayMethodsPlugin_;
|
|
1092
|
+
const isArrayWithStringProp = state.type_ === 1 && typeof prop === "string";
|
|
1093
|
+
if (isArrayWithStringProp) {
|
|
1094
|
+
if (arrayPlugin?.isArrayOperationMethod(prop)) {
|
|
1095
|
+
return arrayPlugin.createMethodInterceptor(state, prop);
|
|
1096
|
+
}
|
|
1097
|
+
}
|
|
1098
|
+
const source = latest(state);
|
|
1099
|
+
if (!has(source, prop, state.type_)) {
|
|
1100
|
+
return readPropFromProto(state, source, prop);
|
|
1101
|
+
}
|
|
1102
|
+
const value = source[prop];
|
|
1103
|
+
if (state.finalized_ || !isDraftable(value)) {
|
|
1104
|
+
return value;
|
|
1105
|
+
}
|
|
1106
|
+
if (isArrayWithStringProp && state.operationMethod && arrayPlugin?.isMutatingArrayMethod(
|
|
1107
|
+
state.operationMethod
|
|
1108
|
+
) && isArrayIndex(prop)) {
|
|
1109
|
+
return value;
|
|
1110
|
+
}
|
|
1111
|
+
if (value === peek(state.base_, prop)) {
|
|
1112
|
+
prepareCopy(state);
|
|
1113
|
+
const childKey = state.type_ === 1 ? +prop : prop;
|
|
1114
|
+
const childDraft = createProxy(state.scope_, value, state, childKey);
|
|
1115
|
+
return state.copy_[childKey] = childDraft;
|
|
1116
|
+
}
|
|
1117
|
+
return value;
|
|
1118
|
+
},
|
|
1119
|
+
has(state, prop) {
|
|
1120
|
+
return prop in latest(state);
|
|
1121
|
+
},
|
|
1122
|
+
ownKeys(state) {
|
|
1123
|
+
return Reflect.ownKeys(latest(state));
|
|
1124
|
+
},
|
|
1125
|
+
set(state, prop, value) {
|
|
1126
|
+
const desc = getDescriptorFromProto(latest(state), prop);
|
|
1127
|
+
if (desc?.set) {
|
|
1128
|
+
desc.set.call(state.draft_, value);
|
|
1129
|
+
return true;
|
|
1130
|
+
}
|
|
1131
|
+
if (!state.modified_) {
|
|
1132
|
+
const current2 = peek(latest(state), prop);
|
|
1133
|
+
const currentState = current2?.[DRAFT_STATE];
|
|
1134
|
+
if (currentState && currentState.base_ === value) {
|
|
1135
|
+
state.copy_[prop] = value;
|
|
1136
|
+
state.assigned_.set(prop, false);
|
|
1137
|
+
return true;
|
|
1138
|
+
}
|
|
1139
|
+
if (is(value, current2) && (value !== void 0 || has(state.base_, prop, state.type_)))
|
|
1140
|
+
return true;
|
|
1141
|
+
prepareCopy(state);
|
|
1142
|
+
markChanged(state);
|
|
1143
|
+
}
|
|
1144
|
+
if (state.copy_[prop] === value && // special case: handle new props with value 'undefined'
|
|
1145
|
+
(value !== void 0 || prop in state.copy_) || // special case: NaN
|
|
1146
|
+
Number.isNaN(value) && Number.isNaN(state.copy_[prop]))
|
|
1147
|
+
return true;
|
|
1148
|
+
state.copy_[prop] = value;
|
|
1149
|
+
state.assigned_.set(prop, true);
|
|
1150
|
+
handleCrossReference(state, prop, value);
|
|
1151
|
+
return true;
|
|
1152
|
+
},
|
|
1153
|
+
deleteProperty(state, prop) {
|
|
1154
|
+
prepareCopy(state);
|
|
1155
|
+
if (peek(state.base_, prop) !== void 0 || prop in state.base_) {
|
|
1156
|
+
state.assigned_.set(prop, false);
|
|
1157
|
+
markChanged(state);
|
|
1158
|
+
} else {
|
|
1159
|
+
state.assigned_.delete(prop);
|
|
1160
|
+
}
|
|
1161
|
+
if (state.copy_) {
|
|
1162
|
+
delete state.copy_[prop];
|
|
1163
|
+
}
|
|
1164
|
+
return true;
|
|
1165
|
+
},
|
|
1166
|
+
// Note: We never coerce `desc.value` into an Immer draft, because we can't make
|
|
1167
|
+
// the same guarantee in ES5 mode.
|
|
1168
|
+
getOwnPropertyDescriptor(state, prop) {
|
|
1169
|
+
const owner = latest(state);
|
|
1170
|
+
const desc = Reflect.getOwnPropertyDescriptor(owner, prop);
|
|
1171
|
+
if (!desc)
|
|
1172
|
+
return desc;
|
|
1173
|
+
return {
|
|
1174
|
+
[WRITABLE]: true,
|
|
1175
|
+
[CONFIGURABLE]: state.type_ !== 1 || prop !== "length",
|
|
1176
|
+
[ENUMERABLE]: desc[ENUMERABLE],
|
|
1177
|
+
[VALUE]: owner[prop]
|
|
1178
|
+
};
|
|
1179
|
+
},
|
|
1180
|
+
defineProperty() {
|
|
1181
|
+
die(11);
|
|
1182
|
+
},
|
|
1183
|
+
getPrototypeOf(state) {
|
|
1184
|
+
return getPrototypeOf(state.base_);
|
|
1185
|
+
},
|
|
1186
|
+
setPrototypeOf() {
|
|
1187
|
+
die(12);
|
|
1188
|
+
}
|
|
1189
|
+
};
|
|
1190
|
+
var arrayTraps = {};
|
|
1191
|
+
for (let key in objectTraps) {
|
|
1192
|
+
let fn = objectTraps[key];
|
|
1193
|
+
arrayTraps[key] = function() {
|
|
1194
|
+
const args = arguments;
|
|
1195
|
+
args[0] = args[0][0];
|
|
1196
|
+
return fn.apply(this, args);
|
|
1197
|
+
};
|
|
1198
|
+
}
|
|
1199
|
+
arrayTraps.deleteProperty = function(state, prop) {
|
|
1200
|
+
if (process.env.NODE_ENV !== "production" && isNaN(parseInt(prop)))
|
|
1201
|
+
die(13);
|
|
1202
|
+
return arrayTraps.set.call(this, state, prop, void 0);
|
|
1203
|
+
};
|
|
1204
|
+
arrayTraps.set = function(state, prop, value) {
|
|
1205
|
+
if (process.env.NODE_ENV !== "production" && prop !== "length" && isNaN(parseInt(prop)))
|
|
1206
|
+
die(14);
|
|
1207
|
+
return objectTraps.set.call(this, state[0], prop, value, state[0]);
|
|
1208
|
+
};
|
|
1209
|
+
function peek(draft, prop) {
|
|
1210
|
+
const state = draft[DRAFT_STATE];
|
|
1211
|
+
const source = state ? latest(state) : draft;
|
|
1212
|
+
return source[prop];
|
|
1213
|
+
}
|
|
1214
|
+
function readPropFromProto(state, source, prop) {
|
|
1215
|
+
const desc = getDescriptorFromProto(source, prop);
|
|
1216
|
+
return desc ? VALUE in desc ? desc[VALUE] : (
|
|
1217
|
+
// This is a very special case, if the prop is a getter defined by the
|
|
1218
|
+
// prototype, we should invoke it with the draft as context!
|
|
1219
|
+
desc.get?.call(state.draft_)
|
|
1220
|
+
) : void 0;
|
|
1221
|
+
}
|
|
1222
|
+
function getDescriptorFromProto(source, prop) {
|
|
1223
|
+
if (!(prop in source))
|
|
1224
|
+
return void 0;
|
|
1225
|
+
let proto = getPrototypeOf(source);
|
|
1226
|
+
while (proto) {
|
|
1227
|
+
const desc = Object.getOwnPropertyDescriptor(proto, prop);
|
|
1228
|
+
if (desc)
|
|
1229
|
+
return desc;
|
|
1230
|
+
proto = getPrototypeOf(proto);
|
|
1231
|
+
}
|
|
1232
|
+
return void 0;
|
|
1233
|
+
}
|
|
1234
|
+
function markChanged(state) {
|
|
1235
|
+
if (!state.modified_) {
|
|
1236
|
+
state.modified_ = true;
|
|
1237
|
+
if (state.parent_) {
|
|
1238
|
+
markChanged(state.parent_);
|
|
1239
|
+
}
|
|
1240
|
+
}
|
|
1241
|
+
}
|
|
1242
|
+
function prepareCopy(state) {
|
|
1243
|
+
if (!state.copy_) {
|
|
1244
|
+
state.assigned_ = /* @__PURE__ */ new Map();
|
|
1245
|
+
state.copy_ = shallowCopy(
|
|
1246
|
+
state.base_,
|
|
1247
|
+
state.scope_.immer_.useStrictShallowCopy_
|
|
1248
|
+
);
|
|
1249
|
+
}
|
|
1250
|
+
}
|
|
1251
|
+
var Immer2 = class {
|
|
1252
|
+
constructor(config) {
|
|
1253
|
+
this.autoFreeze_ = true;
|
|
1254
|
+
this.useStrictShallowCopy_ = false;
|
|
1255
|
+
this.useStrictIteration_ = false;
|
|
1256
|
+
this.produce = (base, recipe, patchListener) => {
|
|
1257
|
+
if (isFunction(base) && !isFunction(recipe)) {
|
|
1258
|
+
const defaultBase = recipe;
|
|
1259
|
+
recipe = base;
|
|
1260
|
+
const self = this;
|
|
1261
|
+
return function curriedProduce(base2 = defaultBase, ...args) {
|
|
1262
|
+
return self.produce(base2, (draft) => recipe.call(this, draft, ...args));
|
|
1263
|
+
};
|
|
1264
|
+
}
|
|
1265
|
+
if (!isFunction(recipe))
|
|
1266
|
+
die(6);
|
|
1267
|
+
if (patchListener !== void 0 && !isFunction(patchListener))
|
|
1268
|
+
die(7);
|
|
1269
|
+
let result;
|
|
1270
|
+
if (isDraftable(base)) {
|
|
1271
|
+
const scope = enterScope(this);
|
|
1272
|
+
const proxy = createProxy(scope, base, void 0);
|
|
1273
|
+
let hasError = true;
|
|
1274
|
+
try {
|
|
1275
|
+
result = recipe(proxy);
|
|
1276
|
+
hasError = false;
|
|
1277
|
+
} finally {
|
|
1278
|
+
if (hasError)
|
|
1279
|
+
revokeScope(scope);
|
|
1280
|
+
else
|
|
1281
|
+
leaveScope(scope);
|
|
1282
|
+
}
|
|
1283
|
+
usePatchesInScope(scope, patchListener);
|
|
1284
|
+
return processResult(result, scope);
|
|
1285
|
+
} else if (!base || !isObjectish(base)) {
|
|
1286
|
+
result = recipe(base);
|
|
1287
|
+
if (result === void 0)
|
|
1288
|
+
result = base;
|
|
1289
|
+
if (result === NOTHING)
|
|
1290
|
+
result = void 0;
|
|
1291
|
+
if (this.autoFreeze_)
|
|
1292
|
+
freeze(result, true);
|
|
1293
|
+
if (patchListener) {
|
|
1294
|
+
const p = [];
|
|
1295
|
+
const ip = [];
|
|
1296
|
+
getPlugin(PluginPatches).generateReplacementPatches_(base, result, {
|
|
1297
|
+
patches_: p,
|
|
1298
|
+
inversePatches_: ip
|
|
1299
|
+
});
|
|
1300
|
+
patchListener(p, ip);
|
|
1301
|
+
}
|
|
1302
|
+
return result;
|
|
1303
|
+
} else
|
|
1304
|
+
die(1, base);
|
|
1305
|
+
};
|
|
1306
|
+
this.produceWithPatches = (base, recipe) => {
|
|
1307
|
+
if (isFunction(base)) {
|
|
1308
|
+
return (state, ...args) => this.produceWithPatches(state, (draft) => base(draft, ...args));
|
|
1309
|
+
}
|
|
1310
|
+
let patches, inversePatches;
|
|
1311
|
+
const result = this.produce(base, recipe, (p, ip) => {
|
|
1312
|
+
patches = p;
|
|
1313
|
+
inversePatches = ip;
|
|
1314
|
+
});
|
|
1315
|
+
return [result, patches, inversePatches];
|
|
1316
|
+
};
|
|
1317
|
+
if (isBoolean(config?.autoFreeze))
|
|
1318
|
+
this.setAutoFreeze(config.autoFreeze);
|
|
1319
|
+
if (isBoolean(config?.useStrictShallowCopy))
|
|
1320
|
+
this.setUseStrictShallowCopy(config.useStrictShallowCopy);
|
|
1321
|
+
if (isBoolean(config?.useStrictIteration))
|
|
1322
|
+
this.setUseStrictIteration(config.useStrictIteration);
|
|
1323
|
+
}
|
|
1324
|
+
createDraft(base) {
|
|
1325
|
+
if (!isDraftable(base))
|
|
1326
|
+
die(8);
|
|
1327
|
+
if (isDraft(base))
|
|
1328
|
+
base = current(base);
|
|
1329
|
+
const scope = enterScope(this);
|
|
1330
|
+
const proxy = createProxy(scope, base, void 0);
|
|
1331
|
+
proxy[DRAFT_STATE].isManual_ = true;
|
|
1332
|
+
leaveScope(scope);
|
|
1333
|
+
return proxy;
|
|
1334
|
+
}
|
|
1335
|
+
finishDraft(draft, patchListener) {
|
|
1336
|
+
const state = draft && draft[DRAFT_STATE];
|
|
1337
|
+
if (!state || !state.isManual_)
|
|
1338
|
+
die(9);
|
|
1339
|
+
const { scope_: scope } = state;
|
|
1340
|
+
usePatchesInScope(scope, patchListener);
|
|
1341
|
+
return processResult(void 0, scope);
|
|
1342
|
+
}
|
|
1343
|
+
/**
|
|
1344
|
+
* Pass true to automatically freeze all copies created by Immer.
|
|
1345
|
+
*
|
|
1346
|
+
* By default, auto-freezing is enabled.
|
|
1347
|
+
*/
|
|
1348
|
+
setAutoFreeze(value) {
|
|
1349
|
+
this.autoFreeze_ = value;
|
|
1350
|
+
}
|
|
1351
|
+
/**
|
|
1352
|
+
* Pass true to enable strict shallow copy.
|
|
1353
|
+
*
|
|
1354
|
+
* By default, immer does not copy the object descriptors such as getter, setter and non-enumrable properties.
|
|
1355
|
+
*/
|
|
1356
|
+
setUseStrictShallowCopy(value) {
|
|
1357
|
+
this.useStrictShallowCopy_ = value;
|
|
1358
|
+
}
|
|
1359
|
+
/**
|
|
1360
|
+
* Pass false to use faster iteration that skips non-enumerable properties
|
|
1361
|
+
* but still handles symbols for compatibility.
|
|
1362
|
+
*
|
|
1363
|
+
* By default, strict iteration is enabled (includes all own properties).
|
|
1364
|
+
*/
|
|
1365
|
+
setUseStrictIteration(value) {
|
|
1366
|
+
this.useStrictIteration_ = value;
|
|
1367
|
+
}
|
|
1368
|
+
shouldUseStrictIteration() {
|
|
1369
|
+
return this.useStrictIteration_;
|
|
1370
|
+
}
|
|
1371
|
+
applyPatches(base, patches) {
|
|
1372
|
+
let i;
|
|
1373
|
+
for (i = patches.length - 1; i >= 0; i--) {
|
|
1374
|
+
const patch = patches[i];
|
|
1375
|
+
if (patch.path.length === 0 && patch.op === "replace") {
|
|
1376
|
+
base = patch.value;
|
|
1377
|
+
break;
|
|
1378
|
+
}
|
|
1379
|
+
}
|
|
1380
|
+
if (i > -1) {
|
|
1381
|
+
patches = patches.slice(i + 1);
|
|
1382
|
+
}
|
|
1383
|
+
const applyPatchesImpl = getPlugin(PluginPatches).applyPatches_;
|
|
1384
|
+
if (isDraft(base)) {
|
|
1385
|
+
return applyPatchesImpl(base, patches);
|
|
1386
|
+
}
|
|
1387
|
+
return this.produce(
|
|
1388
|
+
base,
|
|
1389
|
+
(draft) => applyPatchesImpl(draft, patches)
|
|
1390
|
+
);
|
|
1391
|
+
}
|
|
1392
|
+
};
|
|
1393
|
+
function createProxy(rootScope, value, parent, key) {
|
|
1394
|
+
const [draft, state] = isMap(value) ? getPlugin(PluginMapSet).proxyMap_(value, parent) : isSet(value) ? getPlugin(PluginMapSet).proxySet_(value, parent) : createProxyProxy(value, parent);
|
|
1395
|
+
const scope = parent?.scope_ ?? getCurrentScope();
|
|
1396
|
+
scope.drafts_.push(draft);
|
|
1397
|
+
state.callbacks_ = parent?.callbacks_ ?? [];
|
|
1398
|
+
state.key_ = key;
|
|
1399
|
+
if (parent && key !== void 0) {
|
|
1400
|
+
registerChildFinalizationCallback(parent, state, key);
|
|
1401
|
+
} else {
|
|
1402
|
+
state.callbacks_.push(function rootDraftCleanup(rootScope2) {
|
|
1403
|
+
rootScope2.mapSetPlugin_?.fixSetContents(state);
|
|
1404
|
+
const { patchPlugin_ } = rootScope2;
|
|
1405
|
+
if (state.modified_ && patchPlugin_) {
|
|
1406
|
+
patchPlugin_.generatePatches_(state, [], rootScope2);
|
|
1407
|
+
}
|
|
1408
|
+
});
|
|
1409
|
+
}
|
|
1410
|
+
return draft;
|
|
1411
|
+
}
|
|
1412
|
+
function current(value) {
|
|
1413
|
+
if (!isDraft(value))
|
|
1414
|
+
die(10, value);
|
|
1415
|
+
return currentImpl(value);
|
|
1416
|
+
}
|
|
1417
|
+
function currentImpl(value) {
|
|
1418
|
+
if (!isDraftable(value) || isFrozen(value))
|
|
1419
|
+
return value;
|
|
1420
|
+
const state = value[DRAFT_STATE];
|
|
1421
|
+
let copy;
|
|
1422
|
+
let strict = true;
|
|
1423
|
+
if (state) {
|
|
1424
|
+
if (!state.modified_)
|
|
1425
|
+
return state.base_;
|
|
1426
|
+
state.finalized_ = true;
|
|
1427
|
+
copy = shallowCopy(value, state.scope_.immer_.useStrictShallowCopy_);
|
|
1428
|
+
strict = state.scope_.immer_.shouldUseStrictIteration();
|
|
1429
|
+
} else {
|
|
1430
|
+
copy = shallowCopy(value, true);
|
|
1431
|
+
}
|
|
1432
|
+
each(
|
|
1433
|
+
copy,
|
|
1434
|
+
(key, childValue) => {
|
|
1435
|
+
set(copy, key, currentImpl(childValue));
|
|
1436
|
+
},
|
|
1437
|
+
strict
|
|
1438
|
+
);
|
|
1439
|
+
if (state) {
|
|
1440
|
+
state.finalized_ = false;
|
|
1441
|
+
}
|
|
1442
|
+
return copy;
|
|
1443
|
+
}
|
|
1444
|
+
var immer = new Immer2();
|
|
1445
|
+
var produce = immer.produce;
|
|
1446
|
+
|
|
1447
|
+
// node_modules/@reduxjs/toolkit/dist/redux-toolkit.modern.mjs
|
|
1448
|
+
var composeWithDevTools = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ ? window.__REDUX_DEVTOOLS_EXTENSION_COMPOSE__ : function() {
|
|
1449
|
+
if (arguments.length === 0) return void 0;
|
|
1450
|
+
if (typeof arguments[0] === "object") return compose;
|
|
1451
|
+
return compose.apply(null, arguments);
|
|
1452
|
+
};
|
|
1453
|
+
var devToolsEnhancer = typeof window !== "undefined" && window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ : function() {
|
|
1454
|
+
return function(noop3) {
|
|
1455
|
+
return noop3;
|
|
1456
|
+
};
|
|
1457
|
+
};
|
|
1458
|
+
var hasMatchFunction = (v) => {
|
|
1459
|
+
return v && typeof v.match === "function";
|
|
1460
|
+
};
|
|
1461
|
+
function createAction(type, prepareAction) {
|
|
1462
|
+
function actionCreator(...args) {
|
|
1463
|
+
if (prepareAction) {
|
|
1464
|
+
let prepared = prepareAction(...args);
|
|
1465
|
+
if (!prepared) {
|
|
1466
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(0) : "prepareAction did not return an object");
|
|
1467
|
+
}
|
|
1468
|
+
return {
|
|
1469
|
+
type,
|
|
1470
|
+
payload: prepared.payload,
|
|
1471
|
+
..."meta" in prepared && {
|
|
1472
|
+
meta: prepared.meta
|
|
1473
|
+
},
|
|
1474
|
+
..."error" in prepared && {
|
|
1475
|
+
error: prepared.error
|
|
1476
|
+
}
|
|
1477
|
+
};
|
|
1478
|
+
}
|
|
1479
|
+
return {
|
|
1480
|
+
type,
|
|
1481
|
+
payload: args[0]
|
|
1482
|
+
};
|
|
1483
|
+
}
|
|
1484
|
+
actionCreator.toString = () => `${type}`;
|
|
1485
|
+
actionCreator.type = type;
|
|
1486
|
+
actionCreator.match = (action) => isAction(action) && action.type === type;
|
|
1487
|
+
return actionCreator;
|
|
1488
|
+
}
|
|
1489
|
+
function freezeDraftable(val) {
|
|
1490
|
+
return isDraftable(val) ? produce(val, () => {
|
|
1491
|
+
}) : val;
|
|
1492
|
+
}
|
|
1493
|
+
function getOrInsertComputed(map, key, compute) {
|
|
1494
|
+
if (map.has(key)) return map.get(key);
|
|
1495
|
+
return map.set(key, compute(key)).get(key);
|
|
1496
|
+
}
|
|
1497
|
+
function executeReducerBuilderCallback(builderCallback) {
|
|
1498
|
+
const actionsMap = {};
|
|
1499
|
+
const actionMatchers = [];
|
|
1500
|
+
let defaultCaseReducer;
|
|
1501
|
+
const builder = {
|
|
1502
|
+
addCase(typeOrActionCreator, reducer) {
|
|
1503
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1504
|
+
if (actionMatchers.length > 0) {
|
|
1505
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(26) : "`builder.addCase` should only be called before calling `builder.addMatcher`");
|
|
1506
|
+
}
|
|
1507
|
+
if (defaultCaseReducer) {
|
|
1508
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(27) : "`builder.addCase` should only be called before calling `builder.addDefaultCase`");
|
|
1509
|
+
}
|
|
1510
|
+
}
|
|
1511
|
+
const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
|
1512
|
+
if (!type) {
|
|
1513
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(28) : "`builder.addCase` cannot be called with an empty action type");
|
|
1514
|
+
}
|
|
1515
|
+
if (type in actionsMap) {
|
|
1516
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(29) : `\`builder.addCase\` cannot be called with two reducers for the same action type '${type}'`);
|
|
1517
|
+
}
|
|
1518
|
+
actionsMap[type] = reducer;
|
|
1519
|
+
return builder;
|
|
1520
|
+
},
|
|
1521
|
+
addAsyncThunk(asyncThunk, reducers) {
|
|
1522
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1523
|
+
if (defaultCaseReducer) {
|
|
1524
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(43) : "`builder.addAsyncThunk` should only be called before calling `builder.addDefaultCase`");
|
|
1525
|
+
}
|
|
1526
|
+
}
|
|
1527
|
+
if (reducers.pending) actionsMap[asyncThunk.pending.type] = reducers.pending;
|
|
1528
|
+
if (reducers.rejected) actionsMap[asyncThunk.rejected.type] = reducers.rejected;
|
|
1529
|
+
if (reducers.fulfilled) actionsMap[asyncThunk.fulfilled.type] = reducers.fulfilled;
|
|
1530
|
+
if (reducers.settled) actionMatchers.push({
|
|
1531
|
+
matcher: asyncThunk.settled,
|
|
1532
|
+
reducer: reducers.settled
|
|
1533
|
+
});
|
|
1534
|
+
return builder;
|
|
1535
|
+
},
|
|
1536
|
+
addMatcher(matcher, reducer) {
|
|
1537
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1538
|
+
if (defaultCaseReducer) {
|
|
1539
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(30) : "`builder.addMatcher` should only be called before calling `builder.addDefaultCase`");
|
|
1540
|
+
}
|
|
1541
|
+
}
|
|
1542
|
+
actionMatchers.push({
|
|
1543
|
+
matcher,
|
|
1544
|
+
reducer
|
|
1545
|
+
});
|
|
1546
|
+
return builder;
|
|
1547
|
+
},
|
|
1548
|
+
addDefaultCase(reducer) {
|
|
1549
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1550
|
+
if (defaultCaseReducer) {
|
|
1551
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(31) : "`builder.addDefaultCase` can only be called once");
|
|
1552
|
+
}
|
|
1553
|
+
}
|
|
1554
|
+
defaultCaseReducer = reducer;
|
|
1555
|
+
return builder;
|
|
1556
|
+
}
|
|
1557
|
+
};
|
|
1558
|
+
builderCallback(builder);
|
|
1559
|
+
return [actionsMap, actionMatchers, defaultCaseReducer];
|
|
1560
|
+
}
|
|
1561
|
+
function isStateFunction(x) {
|
|
1562
|
+
return typeof x === "function";
|
|
1563
|
+
}
|
|
1564
|
+
function createReducer(initialState, mapOrBuilderCallback) {
|
|
1565
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1566
|
+
if (typeof mapOrBuilderCallback === "object") {
|
|
1567
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(8) : "The object notation for `createReducer` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createReducer");
|
|
1568
|
+
}
|
|
1569
|
+
}
|
|
1570
|
+
let [actionsMap, finalActionMatchers, finalDefaultCaseReducer] = executeReducerBuilderCallback(mapOrBuilderCallback);
|
|
1571
|
+
let getInitialState;
|
|
1572
|
+
if (isStateFunction(initialState)) {
|
|
1573
|
+
getInitialState = () => freezeDraftable(initialState());
|
|
1574
|
+
} else {
|
|
1575
|
+
const frozenInitialState = freezeDraftable(initialState);
|
|
1576
|
+
getInitialState = () => frozenInitialState;
|
|
1577
|
+
}
|
|
1578
|
+
function reducer(state = getInitialState(), action) {
|
|
1579
|
+
let caseReducers = [actionsMap[action.type], ...finalActionMatchers.filter(({
|
|
1580
|
+
matcher
|
|
1581
|
+
}) => matcher(action)).map(({
|
|
1582
|
+
reducer: reducer2
|
|
1583
|
+
}) => reducer2)];
|
|
1584
|
+
if (caseReducers.filter((cr) => !!cr).length === 0) {
|
|
1585
|
+
caseReducers = [finalDefaultCaseReducer];
|
|
1586
|
+
}
|
|
1587
|
+
return caseReducers.reduce((previousState, caseReducer) => {
|
|
1588
|
+
if (caseReducer) {
|
|
1589
|
+
if (isDraft(previousState)) {
|
|
1590
|
+
const draft = previousState;
|
|
1591
|
+
const result = caseReducer(draft, action);
|
|
1592
|
+
if (result === void 0) {
|
|
1593
|
+
return previousState;
|
|
1594
|
+
}
|
|
1595
|
+
return result;
|
|
1596
|
+
} else if (!isDraftable(previousState)) {
|
|
1597
|
+
const result = caseReducer(previousState, action);
|
|
1598
|
+
if (result === void 0) {
|
|
1599
|
+
if (previousState === null) {
|
|
1600
|
+
return previousState;
|
|
1601
|
+
}
|
|
1602
|
+
throw Error("A case reducer on a non-draftable value must not return undefined");
|
|
1603
|
+
}
|
|
1604
|
+
return result;
|
|
1605
|
+
} else {
|
|
1606
|
+
return produce(previousState, (draft) => {
|
|
1607
|
+
return caseReducer(draft, action);
|
|
1608
|
+
});
|
|
1609
|
+
}
|
|
1610
|
+
}
|
|
1611
|
+
return previousState;
|
|
1612
|
+
}, state);
|
|
1613
|
+
}
|
|
1614
|
+
reducer.getInitialState = getInitialState;
|
|
1615
|
+
return reducer;
|
|
1616
|
+
}
|
|
1617
|
+
var matches = (matcher, action) => {
|
|
1618
|
+
if (hasMatchFunction(matcher)) {
|
|
1619
|
+
return matcher.match(action);
|
|
1620
|
+
} else {
|
|
1621
|
+
return matcher(action);
|
|
1622
|
+
}
|
|
1623
|
+
};
|
|
1624
|
+
function isAnyOf(...matchers) {
|
|
1625
|
+
return (action) => {
|
|
1626
|
+
return matchers.some((matcher) => matches(matcher, action));
|
|
1627
|
+
};
|
|
1628
|
+
}
|
|
1629
|
+
var urlAlphabet = "ModuleSymbhasOwnPr-0123456789ABCDEFGHNRVfgctiUvz_KqYTJkLxpZXIjQW";
|
|
1630
|
+
var nanoid = (size = 21) => {
|
|
1631
|
+
let id = "";
|
|
1632
|
+
let i = size;
|
|
1633
|
+
while (i--) {
|
|
1634
|
+
id += urlAlphabet[Math.random() * 64 | 0];
|
|
1635
|
+
}
|
|
1636
|
+
return id;
|
|
1637
|
+
};
|
|
1638
|
+
var commonProperties = ["name", "message", "stack", "code"];
|
|
1639
|
+
var RejectWithValue = class {
|
|
1640
|
+
constructor(payload, meta) {
|
|
1641
|
+
__publicField(this, "payload");
|
|
1642
|
+
__publicField(this, "meta");
|
|
1643
|
+
/*
|
|
1644
|
+
type-only property to distinguish between RejectWithValue and FulfillWithMeta
|
|
1645
|
+
does not exist at runtime
|
|
1646
|
+
*/
|
|
1647
|
+
__publicField(this, "_type");
|
|
1648
|
+
this.payload = payload;
|
|
1649
|
+
this.meta = meta;
|
|
1650
|
+
}
|
|
1651
|
+
};
|
|
1652
|
+
var FulfillWithMeta = class {
|
|
1653
|
+
constructor(payload, meta) {
|
|
1654
|
+
__publicField(this, "payload");
|
|
1655
|
+
__publicField(this, "meta");
|
|
1656
|
+
/*
|
|
1657
|
+
type-only property to distinguish between RejectWithValue and FulfillWithMeta
|
|
1658
|
+
does not exist at runtime
|
|
1659
|
+
*/
|
|
1660
|
+
__publicField(this, "_type");
|
|
1661
|
+
this.payload = payload;
|
|
1662
|
+
this.meta = meta;
|
|
1663
|
+
}
|
|
1664
|
+
};
|
|
1665
|
+
var miniSerializeError = (value) => {
|
|
1666
|
+
if (typeof value === "object" && value !== null) {
|
|
1667
|
+
const simpleError = {};
|
|
1668
|
+
for (const property of commonProperties) {
|
|
1669
|
+
if (typeof value[property] === "string") {
|
|
1670
|
+
simpleError[property] = value[property];
|
|
1671
|
+
}
|
|
1672
|
+
}
|
|
1673
|
+
return simpleError;
|
|
1674
|
+
}
|
|
1675
|
+
return {
|
|
1676
|
+
message: String(value)
|
|
1677
|
+
};
|
|
1678
|
+
};
|
|
1679
|
+
var externalAbortMessage = "External signal was aborted";
|
|
1680
|
+
var createAsyncThunk = /* @__PURE__ */ (() => {
|
|
1681
|
+
function createAsyncThunk2(typePrefix, payloadCreator, options) {
|
|
1682
|
+
const fulfilled = createAction(typePrefix + "/fulfilled", (payload, requestId, arg, meta) => ({
|
|
1683
|
+
payload,
|
|
1684
|
+
meta: {
|
|
1685
|
+
...meta || {},
|
|
1686
|
+
arg,
|
|
1687
|
+
requestId,
|
|
1688
|
+
requestStatus: "fulfilled"
|
|
1689
|
+
}
|
|
1690
|
+
}));
|
|
1691
|
+
const pending = createAction(typePrefix + "/pending", (requestId, arg, meta) => ({
|
|
1692
|
+
payload: void 0,
|
|
1693
|
+
meta: {
|
|
1694
|
+
...meta || {},
|
|
1695
|
+
arg,
|
|
1696
|
+
requestId,
|
|
1697
|
+
requestStatus: "pending"
|
|
1698
|
+
}
|
|
1699
|
+
}));
|
|
1700
|
+
const rejected = createAction(typePrefix + "/rejected", (error, requestId, arg, payload, meta) => ({
|
|
1701
|
+
payload,
|
|
1702
|
+
error: (options && options.serializeError || miniSerializeError)(error || "Rejected"),
|
|
1703
|
+
meta: {
|
|
1704
|
+
...meta || {},
|
|
1705
|
+
arg,
|
|
1706
|
+
requestId,
|
|
1707
|
+
rejectedWithValue: !!payload,
|
|
1708
|
+
requestStatus: "rejected",
|
|
1709
|
+
aborted: error?.name === "AbortError",
|
|
1710
|
+
condition: error?.name === "ConditionError"
|
|
1711
|
+
}
|
|
1712
|
+
}));
|
|
1713
|
+
function actionCreator(arg, {
|
|
1714
|
+
signal
|
|
1715
|
+
} = {}) {
|
|
1716
|
+
return (dispatch, getState, extra) => {
|
|
1717
|
+
const requestId = options?.idGenerator ? options.idGenerator(arg) : nanoid();
|
|
1718
|
+
const abortController = new AbortController();
|
|
1719
|
+
let abortHandler;
|
|
1720
|
+
let abortReason;
|
|
1721
|
+
function abort(reason) {
|
|
1722
|
+
abortReason = reason;
|
|
1723
|
+
abortController.abort();
|
|
1724
|
+
}
|
|
1725
|
+
if (signal) {
|
|
1726
|
+
if (signal.aborted) {
|
|
1727
|
+
abort(externalAbortMessage);
|
|
1728
|
+
} else {
|
|
1729
|
+
signal.addEventListener("abort", () => abort(externalAbortMessage), {
|
|
1730
|
+
once: true
|
|
1731
|
+
});
|
|
1732
|
+
}
|
|
1733
|
+
}
|
|
1734
|
+
const promise = (async function() {
|
|
1735
|
+
let finalAction;
|
|
1736
|
+
try {
|
|
1737
|
+
let conditionResult = options?.condition?.(arg, {
|
|
1738
|
+
getState,
|
|
1739
|
+
extra
|
|
1740
|
+
});
|
|
1741
|
+
if (isThenable(conditionResult)) {
|
|
1742
|
+
conditionResult = await conditionResult;
|
|
1743
|
+
}
|
|
1744
|
+
if (conditionResult === false || abortController.signal.aborted) {
|
|
1745
|
+
throw {
|
|
1746
|
+
name: "ConditionError",
|
|
1747
|
+
message: "Aborted due to condition callback returning false."
|
|
1748
|
+
};
|
|
1749
|
+
}
|
|
1750
|
+
const abortedPromise = new Promise((_, reject) => {
|
|
1751
|
+
abortHandler = () => {
|
|
1752
|
+
reject({
|
|
1753
|
+
name: "AbortError",
|
|
1754
|
+
message: abortReason || "Aborted"
|
|
1755
|
+
});
|
|
1756
|
+
};
|
|
1757
|
+
abortController.signal.addEventListener("abort", abortHandler, {
|
|
1758
|
+
once: true
|
|
1759
|
+
});
|
|
1760
|
+
});
|
|
1761
|
+
dispatch(pending(requestId, arg, options?.getPendingMeta?.({
|
|
1762
|
+
requestId,
|
|
1763
|
+
arg
|
|
1764
|
+
}, {
|
|
1765
|
+
getState,
|
|
1766
|
+
extra
|
|
1767
|
+
})));
|
|
1768
|
+
finalAction = await Promise.race([abortedPromise, Promise.resolve(payloadCreator(arg, {
|
|
1769
|
+
dispatch,
|
|
1770
|
+
getState,
|
|
1771
|
+
extra,
|
|
1772
|
+
requestId,
|
|
1773
|
+
signal: abortController.signal,
|
|
1774
|
+
abort,
|
|
1775
|
+
rejectWithValue: ((value, meta) => {
|
|
1776
|
+
return new RejectWithValue(value, meta);
|
|
1777
|
+
}),
|
|
1778
|
+
fulfillWithValue: ((value, meta) => {
|
|
1779
|
+
return new FulfillWithMeta(value, meta);
|
|
1780
|
+
})
|
|
1781
|
+
})).then((result) => {
|
|
1782
|
+
if (result instanceof RejectWithValue) {
|
|
1783
|
+
throw result;
|
|
1784
|
+
}
|
|
1785
|
+
if (result instanceof FulfillWithMeta) {
|
|
1786
|
+
return fulfilled(result.payload, requestId, arg, result.meta);
|
|
1787
|
+
}
|
|
1788
|
+
return fulfilled(result, requestId, arg);
|
|
1789
|
+
})]);
|
|
1790
|
+
} catch (err) {
|
|
1791
|
+
finalAction = err instanceof RejectWithValue ? rejected(null, requestId, arg, err.payload, err.meta) : rejected(err, requestId, arg);
|
|
1792
|
+
} finally {
|
|
1793
|
+
if (abortHandler) {
|
|
1794
|
+
abortController.signal.removeEventListener("abort", abortHandler);
|
|
1795
|
+
}
|
|
1796
|
+
}
|
|
1797
|
+
const skipDispatch = options && !options.dispatchConditionRejection && rejected.match(finalAction) && finalAction.meta.condition;
|
|
1798
|
+
if (!skipDispatch) {
|
|
1799
|
+
dispatch(finalAction);
|
|
1800
|
+
}
|
|
1801
|
+
return finalAction;
|
|
1802
|
+
})();
|
|
1803
|
+
return Object.assign(promise, {
|
|
1804
|
+
abort,
|
|
1805
|
+
requestId,
|
|
1806
|
+
arg,
|
|
1807
|
+
unwrap() {
|
|
1808
|
+
return promise.then(unwrapResult);
|
|
1809
|
+
}
|
|
1810
|
+
});
|
|
1811
|
+
};
|
|
1812
|
+
}
|
|
1813
|
+
return Object.assign(actionCreator, {
|
|
1814
|
+
pending,
|
|
1815
|
+
rejected,
|
|
1816
|
+
fulfilled,
|
|
1817
|
+
settled: isAnyOf(rejected, fulfilled),
|
|
1818
|
+
typePrefix
|
|
1819
|
+
});
|
|
1820
|
+
}
|
|
1821
|
+
createAsyncThunk2.withTypes = () => createAsyncThunk2;
|
|
1822
|
+
return createAsyncThunk2;
|
|
1823
|
+
})();
|
|
1824
|
+
function unwrapResult(action) {
|
|
1825
|
+
if (action.meta && action.meta.rejectedWithValue) {
|
|
1826
|
+
throw action.payload;
|
|
1827
|
+
}
|
|
1828
|
+
if (action.error) {
|
|
1829
|
+
throw action.error;
|
|
1830
|
+
}
|
|
1831
|
+
return action.payload;
|
|
1832
|
+
}
|
|
1833
|
+
function isThenable(value) {
|
|
1834
|
+
return value !== null && typeof value === "object" && typeof value.then === "function";
|
|
1835
|
+
}
|
|
1836
|
+
var asyncThunkSymbol = /* @__PURE__ */ Symbol.for("rtk-slice-createasyncthunk");
|
|
1837
|
+
var asyncThunkCreator = {
|
|
1838
|
+
[asyncThunkSymbol]: createAsyncThunk
|
|
1839
|
+
};
|
|
1840
|
+
function getType(slice2, actionKey) {
|
|
1841
|
+
return `${slice2}/${actionKey}`;
|
|
1842
|
+
}
|
|
1843
|
+
function buildCreateSlice({
|
|
1844
|
+
creators
|
|
1845
|
+
} = {}) {
|
|
1846
|
+
const cAT = creators?.asyncThunk?.[asyncThunkSymbol];
|
|
1847
|
+
return function createSlice2(options) {
|
|
1848
|
+
const {
|
|
1849
|
+
name,
|
|
1850
|
+
reducerPath = name
|
|
1851
|
+
} = options;
|
|
1852
|
+
if (!name) {
|
|
1853
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(11) : "`name` is a required option for createSlice");
|
|
1854
|
+
}
|
|
1855
|
+
if (typeof process !== "undefined" && process.env.NODE_ENV === "development") {
|
|
1856
|
+
if (options.initialState === void 0) {
|
|
1857
|
+
console.error("You must provide an `initialState` value that is not `undefined`. You may have misspelled `initialState`");
|
|
1858
|
+
}
|
|
1859
|
+
}
|
|
1860
|
+
const reducers = (typeof options.reducers === "function" ? options.reducers(buildReducerCreators()) : options.reducers) || {};
|
|
1861
|
+
const reducerNames = Object.keys(reducers);
|
|
1862
|
+
const context = {
|
|
1863
|
+
sliceCaseReducersByName: {},
|
|
1864
|
+
sliceCaseReducersByType: {},
|
|
1865
|
+
actionCreators: {},
|
|
1866
|
+
sliceMatchers: []
|
|
1867
|
+
};
|
|
1868
|
+
const contextMethods = {
|
|
1869
|
+
addCase(typeOrActionCreator, reducer2) {
|
|
1870
|
+
const type = typeof typeOrActionCreator === "string" ? typeOrActionCreator : typeOrActionCreator.type;
|
|
1871
|
+
if (!type) {
|
|
1872
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(12) : "`context.addCase` cannot be called with an empty action type");
|
|
1873
|
+
}
|
|
1874
|
+
if (type in context.sliceCaseReducersByType) {
|
|
1875
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(13) : "`context.addCase` cannot be called with two reducers for the same action type: " + type);
|
|
1876
|
+
}
|
|
1877
|
+
context.sliceCaseReducersByType[type] = reducer2;
|
|
1878
|
+
return contextMethods;
|
|
1879
|
+
},
|
|
1880
|
+
addMatcher(matcher, reducer2) {
|
|
1881
|
+
context.sliceMatchers.push({
|
|
1882
|
+
matcher,
|
|
1883
|
+
reducer: reducer2
|
|
1884
|
+
});
|
|
1885
|
+
return contextMethods;
|
|
1886
|
+
},
|
|
1887
|
+
exposeAction(name2, actionCreator) {
|
|
1888
|
+
context.actionCreators[name2] = actionCreator;
|
|
1889
|
+
return contextMethods;
|
|
1890
|
+
},
|
|
1891
|
+
exposeCaseReducer(name2, reducer2) {
|
|
1892
|
+
context.sliceCaseReducersByName[name2] = reducer2;
|
|
1893
|
+
return contextMethods;
|
|
1894
|
+
}
|
|
1895
|
+
};
|
|
1896
|
+
reducerNames.forEach((reducerName) => {
|
|
1897
|
+
const reducerDefinition = reducers[reducerName];
|
|
1898
|
+
const reducerDetails = {
|
|
1899
|
+
reducerName,
|
|
1900
|
+
type: getType(name, reducerName),
|
|
1901
|
+
createNotation: typeof options.reducers === "function"
|
|
1902
|
+
};
|
|
1903
|
+
if (isAsyncThunkSliceReducerDefinition(reducerDefinition)) {
|
|
1904
|
+
handleThunkCaseReducerDefinition(reducerDetails, reducerDefinition, contextMethods, cAT);
|
|
1905
|
+
} else {
|
|
1906
|
+
handleNormalReducerDefinition(reducerDetails, reducerDefinition, contextMethods);
|
|
1907
|
+
}
|
|
1908
|
+
});
|
|
1909
|
+
function buildReducer() {
|
|
1910
|
+
if (process.env.NODE_ENV !== "production") {
|
|
1911
|
+
if (typeof options.extraReducers === "object") {
|
|
1912
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(14) : "The object notation for `createSlice.extraReducers` has been removed. Please use the 'builder callback' notation instead: https://redux-toolkit.js.org/api/createSlice");
|
|
1913
|
+
}
|
|
1914
|
+
}
|
|
1915
|
+
const [extraReducers = {}, actionMatchers = [], defaultCaseReducer = void 0] = typeof options.extraReducers === "function" ? executeReducerBuilderCallback(options.extraReducers) : [options.extraReducers];
|
|
1916
|
+
const finalCaseReducers = {
|
|
1917
|
+
...extraReducers,
|
|
1918
|
+
...context.sliceCaseReducersByType
|
|
1919
|
+
};
|
|
1920
|
+
return createReducer(options.initialState, (builder) => {
|
|
1921
|
+
for (let key in finalCaseReducers) {
|
|
1922
|
+
builder.addCase(key, finalCaseReducers[key]);
|
|
1923
|
+
}
|
|
1924
|
+
for (let sM of context.sliceMatchers) {
|
|
1925
|
+
builder.addMatcher(sM.matcher, sM.reducer);
|
|
1926
|
+
}
|
|
1927
|
+
for (let m of actionMatchers) {
|
|
1928
|
+
builder.addMatcher(m.matcher, m.reducer);
|
|
1929
|
+
}
|
|
1930
|
+
if (defaultCaseReducer) {
|
|
1931
|
+
builder.addDefaultCase(defaultCaseReducer);
|
|
1932
|
+
}
|
|
1933
|
+
});
|
|
1934
|
+
}
|
|
1935
|
+
const selectSelf = (state) => state;
|
|
1936
|
+
const injectedSelectorCache = /* @__PURE__ */ new Map();
|
|
1937
|
+
const injectedStateCache = /* @__PURE__ */ new WeakMap();
|
|
1938
|
+
let _reducer;
|
|
1939
|
+
function reducer(state, action) {
|
|
1940
|
+
if (!_reducer) _reducer = buildReducer();
|
|
1941
|
+
return _reducer(state, action);
|
|
1942
|
+
}
|
|
1943
|
+
function getInitialState() {
|
|
1944
|
+
if (!_reducer) _reducer = buildReducer();
|
|
1945
|
+
return _reducer.getInitialState();
|
|
1946
|
+
}
|
|
1947
|
+
function makeSelectorProps(reducerPath2, injected = false) {
|
|
1948
|
+
function selectSlice(state) {
|
|
1949
|
+
let sliceState = state[reducerPath2];
|
|
1950
|
+
if (typeof sliceState === "undefined") {
|
|
1951
|
+
if (injected) {
|
|
1952
|
+
sliceState = getOrInsertComputed(injectedStateCache, selectSlice, getInitialState);
|
|
1953
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
1954
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(15) : "selectSlice returned undefined for an uninjected slice reducer");
|
|
1955
|
+
}
|
|
1956
|
+
}
|
|
1957
|
+
return sliceState;
|
|
1958
|
+
}
|
|
1959
|
+
function getSelectors(selectState = selectSelf) {
|
|
1960
|
+
const selectorCache = getOrInsertComputed(injectedSelectorCache, injected, () => /* @__PURE__ */ new WeakMap());
|
|
1961
|
+
return getOrInsertComputed(selectorCache, selectState, () => {
|
|
1962
|
+
const map = {};
|
|
1963
|
+
for (const [name2, selector] of Object.entries(options.selectors ?? {})) {
|
|
1964
|
+
map[name2] = wrapSelector(selector, selectState, () => getOrInsertComputed(injectedStateCache, selectState, getInitialState), injected);
|
|
1965
|
+
}
|
|
1966
|
+
return map;
|
|
1967
|
+
});
|
|
1968
|
+
}
|
|
1969
|
+
return {
|
|
1970
|
+
reducerPath: reducerPath2,
|
|
1971
|
+
getSelectors,
|
|
1972
|
+
get selectors() {
|
|
1973
|
+
return getSelectors(selectSlice);
|
|
1974
|
+
},
|
|
1975
|
+
selectSlice
|
|
1976
|
+
};
|
|
1977
|
+
}
|
|
1978
|
+
const slice2 = {
|
|
1979
|
+
name,
|
|
1980
|
+
reducer,
|
|
1981
|
+
actions: context.actionCreators,
|
|
1982
|
+
caseReducers: context.sliceCaseReducersByName,
|
|
1983
|
+
getInitialState,
|
|
1984
|
+
...makeSelectorProps(reducerPath),
|
|
1985
|
+
injectInto(injectable, {
|
|
1986
|
+
reducerPath: pathOpt,
|
|
1987
|
+
...config
|
|
1988
|
+
} = {}) {
|
|
1989
|
+
const newReducerPath = pathOpt ?? reducerPath;
|
|
1990
|
+
injectable.inject({
|
|
1991
|
+
reducerPath: newReducerPath,
|
|
1992
|
+
reducer
|
|
1993
|
+
}, config);
|
|
1994
|
+
return {
|
|
1995
|
+
...slice2,
|
|
1996
|
+
...makeSelectorProps(newReducerPath, true)
|
|
1997
|
+
};
|
|
1998
|
+
}
|
|
1999
|
+
};
|
|
2000
|
+
return slice2;
|
|
2001
|
+
};
|
|
2002
|
+
}
|
|
2003
|
+
function wrapSelector(selector, selectState, getInitialState, injected) {
|
|
2004
|
+
function wrapper(rootState, ...args) {
|
|
2005
|
+
let sliceState = selectState(rootState);
|
|
2006
|
+
if (typeof sliceState === "undefined") {
|
|
2007
|
+
if (injected) {
|
|
2008
|
+
sliceState = getInitialState();
|
|
2009
|
+
} else if (process.env.NODE_ENV !== "production") {
|
|
2010
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(16) : "selectState returned undefined for an uninjected slice reducer");
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
return selector(sliceState, ...args);
|
|
2014
|
+
}
|
|
2015
|
+
wrapper.unwrapped = selector;
|
|
2016
|
+
return wrapper;
|
|
2017
|
+
}
|
|
2018
|
+
var createSlice = /* @__PURE__ */ buildCreateSlice();
|
|
2019
|
+
function buildReducerCreators() {
|
|
2020
|
+
function asyncThunk(payloadCreator, config) {
|
|
2021
|
+
return {
|
|
2022
|
+
_reducerDefinitionType: "asyncThunk",
|
|
2023
|
+
payloadCreator,
|
|
2024
|
+
...config
|
|
2025
|
+
};
|
|
2026
|
+
}
|
|
2027
|
+
asyncThunk.withTypes = () => asyncThunk;
|
|
2028
|
+
return {
|
|
2029
|
+
reducer(caseReducer) {
|
|
2030
|
+
return Object.assign({
|
|
2031
|
+
// hack so the wrapping function has the same name as the original
|
|
2032
|
+
// we need to create a wrapper so the `reducerDefinitionType` is not assigned to the original
|
|
2033
|
+
[caseReducer.name](...args) {
|
|
2034
|
+
return caseReducer(...args);
|
|
2035
|
+
}
|
|
2036
|
+
}[caseReducer.name], {
|
|
2037
|
+
_reducerDefinitionType: "reducer"
|
|
2038
|
+
/* reducer */
|
|
2039
|
+
});
|
|
2040
|
+
},
|
|
2041
|
+
preparedReducer(prepare, reducer) {
|
|
2042
|
+
return {
|
|
2043
|
+
_reducerDefinitionType: "reducerWithPrepare",
|
|
2044
|
+
prepare,
|
|
2045
|
+
reducer
|
|
2046
|
+
};
|
|
2047
|
+
},
|
|
2048
|
+
asyncThunk
|
|
2049
|
+
};
|
|
2050
|
+
}
|
|
2051
|
+
function handleNormalReducerDefinition({
|
|
2052
|
+
type,
|
|
2053
|
+
reducerName,
|
|
2054
|
+
createNotation
|
|
2055
|
+
}, maybeReducerWithPrepare, context) {
|
|
2056
|
+
let caseReducer;
|
|
2057
|
+
let prepareCallback;
|
|
2058
|
+
if ("reducer" in maybeReducerWithPrepare) {
|
|
2059
|
+
if (createNotation && !isCaseReducerWithPrepareDefinition(maybeReducerWithPrepare)) {
|
|
2060
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(17) : "Please use the `create.preparedReducer` notation for prepared action creators with the `create` notation.");
|
|
2061
|
+
}
|
|
2062
|
+
caseReducer = maybeReducerWithPrepare.reducer;
|
|
2063
|
+
prepareCallback = maybeReducerWithPrepare.prepare;
|
|
2064
|
+
} else {
|
|
2065
|
+
caseReducer = maybeReducerWithPrepare;
|
|
2066
|
+
}
|
|
2067
|
+
context.addCase(type, caseReducer).exposeCaseReducer(reducerName, caseReducer).exposeAction(reducerName, prepareCallback ? createAction(type, prepareCallback) : createAction(type));
|
|
2068
|
+
}
|
|
2069
|
+
function isAsyncThunkSliceReducerDefinition(reducerDefinition) {
|
|
2070
|
+
return reducerDefinition._reducerDefinitionType === "asyncThunk";
|
|
2071
|
+
}
|
|
2072
|
+
function isCaseReducerWithPrepareDefinition(reducerDefinition) {
|
|
2073
|
+
return reducerDefinition._reducerDefinitionType === "reducerWithPrepare";
|
|
2074
|
+
}
|
|
2075
|
+
function handleThunkCaseReducerDefinition({
|
|
2076
|
+
type,
|
|
2077
|
+
reducerName
|
|
2078
|
+
}, reducerDefinition, context, cAT) {
|
|
2079
|
+
if (!cAT) {
|
|
2080
|
+
throw new Error(process.env.NODE_ENV === "production" ? formatProdErrorMessage(18) : "Cannot use `create.asyncThunk` in the built-in `createSlice`. Use `buildCreateSlice({ creators: { asyncThunk: asyncThunkCreator } })` to create a customised version of `createSlice`.");
|
|
2081
|
+
}
|
|
2082
|
+
const {
|
|
2083
|
+
payloadCreator,
|
|
2084
|
+
fulfilled,
|
|
2085
|
+
pending,
|
|
2086
|
+
rejected,
|
|
2087
|
+
settled,
|
|
2088
|
+
options
|
|
2089
|
+
} = reducerDefinition;
|
|
2090
|
+
const thunk = cAT(type, payloadCreator, options);
|
|
2091
|
+
context.exposeAction(reducerName, thunk);
|
|
2092
|
+
if (fulfilled) {
|
|
2093
|
+
context.addCase(thunk.fulfilled, fulfilled);
|
|
2094
|
+
}
|
|
2095
|
+
if (pending) {
|
|
2096
|
+
context.addCase(thunk.pending, pending);
|
|
2097
|
+
}
|
|
2098
|
+
if (rejected) {
|
|
2099
|
+
context.addCase(thunk.rejected, rejected);
|
|
2100
|
+
}
|
|
2101
|
+
if (settled) {
|
|
2102
|
+
context.addMatcher(thunk.settled, settled);
|
|
2103
|
+
}
|
|
2104
|
+
context.exposeCaseReducer(reducerName, {
|
|
2105
|
+
fulfilled: fulfilled || noop,
|
|
2106
|
+
pending: pending || noop,
|
|
2107
|
+
rejected: rejected || noop,
|
|
2108
|
+
settled: settled || noop
|
|
2109
|
+
});
|
|
2110
|
+
}
|
|
2111
|
+
function noop() {
|
|
2112
|
+
}
|
|
2113
|
+
var listener = "listener";
|
|
2114
|
+
var completed = "completed";
|
|
2115
|
+
var cancelled = "cancelled";
|
|
2116
|
+
var taskCancelled = `task-${cancelled}`;
|
|
2117
|
+
var taskCompleted = `task-${completed}`;
|
|
2118
|
+
var listenerCancelled = `${listener}-${cancelled}`;
|
|
2119
|
+
var listenerCompleted = `${listener}-${completed}`;
|
|
2120
|
+
var {
|
|
2121
|
+
assign
|
|
2122
|
+
} = Object;
|
|
2123
|
+
var alm = "listenerMiddleware";
|
|
2124
|
+
var addListener = /* @__PURE__ */ assign(/* @__PURE__ */ createAction(`${alm}/add`), {
|
|
2125
|
+
withTypes: () => addListener
|
|
2126
|
+
});
|
|
2127
|
+
var clearAllListeners = /* @__PURE__ */ createAction(`${alm}/removeAll`);
|
|
2128
|
+
var removeListener = /* @__PURE__ */ assign(/* @__PURE__ */ createAction(`${alm}/remove`), {
|
|
2129
|
+
withTypes: () => removeListener
|
|
2130
|
+
});
|
|
2131
|
+
function formatProdErrorMessage(code) {
|
|
2132
|
+
return `Minified Redux Toolkit error #${code}; visit https://redux-toolkit.js.org/Errors?code=${code} for the full message or use the non-minified dev environment for full errors. `;
|
|
2133
|
+
}
|
|
2134
|
+
|
|
2135
|
+
// src/ScrollViewSettingsContext.ts
|
|
2136
|
+
import { createContext as createContext2 } from "react";
|
|
2137
|
+
var defaultScrollViewSettings = {
|
|
2138
|
+
backActionFixed: true,
|
|
2139
|
+
footerFixed: false,
|
|
2140
|
+
headerFixed: false,
|
|
2141
|
+
snapBack: false
|
|
2142
|
+
};
|
|
2143
|
+
var ScrollViewSettingsContext = createContext2({
|
|
2144
|
+
settings: defaultScrollViewSettings,
|
|
2145
|
+
set: () => {
|
|
2146
|
+
}
|
|
2147
|
+
});
|
|
2148
|
+
|
|
2149
|
+
// src/redux/scrollViewSlice.ts
|
|
2150
|
+
var slice = createSlice({
|
|
2151
|
+
name: "scrollView",
|
|
2152
|
+
initialState: defaultScrollViewSettings,
|
|
2153
|
+
reducers: {
|
|
2154
|
+
initialize: (_state, action) => action.payload
|
|
2155
|
+
}
|
|
2156
|
+
});
|
|
2157
|
+
var scrollViewActions = slice.actions;
|
|
2158
|
+
var scrollViewReducer = slice.reducer;
|
|
2159
|
+
|
|
2160
|
+
// src/ScrollView.tsx
|
|
2161
|
+
import { memo as memo3, useCallback as useCallback5, useMemo as useMemo4, useRef as useRef5 } from "react";
|
|
2162
|
+
import { View as View4 } from "react-native";
|
|
2163
|
+
import { Gesture as Gesture3, GestureDetector as GestureDetector3 } from "react-native-gesture-handler";
|
|
2164
|
+
import Animated5 from "react-native-reanimated";
|
|
2165
|
+
import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
|
|
2166
|
+
var ScrollViewInner = ({ children, footerFixed: footerFixedProp, gesture, headerFixed: headerFixedProp, horizontal, keyboardAware, onMomentumScrollEnd: externalMomentumScrollEnd, onRefresh, onScrollBeginDrag: externalScrollBeginDrag, onScrollEndDrag: externalScrollEndDrag, pullSearchHeight, refreshing, style, ...props }) => {
|
|
2167
|
+
const scrollView = useRef5(null);
|
|
2168
|
+
const isHorizontal = horizontal === true;
|
|
2169
|
+
const { chipHidden, chipStyle, containerStyle, contentInset, contentOffset, footerFixed, headerFixed } = useScrollList({ footerFixed: footerFixedProp, headerFixed: headerFixedProp, isHorizontal, keyboardAware, pullSearchHeight, style });
|
|
2170
|
+
const scrollTo = useCallback5((offset, animated) => {
|
|
2171
|
+
scrollView.current?.scrollTo({ y: offset, animated });
|
|
2172
|
+
}, []);
|
|
2173
|
+
const { handleMomentumScrollEnd, handleScrollBeginDrag, handleScrollEndDrag } = useScrollInit({
|
|
2174
|
+
onMomentumScrollEnd: externalMomentumScrollEnd,
|
|
2175
|
+
onScrollBeginDrag: externalScrollBeginDrag,
|
|
2176
|
+
onScrollEndDrag: externalScrollEndDrag,
|
|
2177
|
+
pullSearchHeight,
|
|
2178
|
+
scrollTo
|
|
2179
|
+
});
|
|
2180
|
+
const onPullSearchZoneEnter = useCallback5(() => {
|
|
2181
|
+
if (!pullSearchHeight) return;
|
|
2182
|
+
scrollTo(-contentInset.top + pullSearchHeight, true);
|
|
2183
|
+
}, [contentInset.top, pullSearchHeight, scrollTo]);
|
|
2184
|
+
const handleScroll = useScrollHandler({ chipHidden, footerFixed, headerFixed, isHorizontal, onPullSearchZoneEnter: pullSearchHeight ? onPullSearchZoneEnter : void 0 });
|
|
2185
|
+
const handleScrollToTop = useCallback5(() => {
|
|
2186
|
+
if (isHorizontal) {
|
|
2187
|
+
scrollView.current?.scrollTo({ x: 0, animated: true });
|
|
2188
|
+
return;
|
|
2189
|
+
}
|
|
2190
|
+
const offset = pullSearchHeight ? -contentInset.top + pullSearchHeight : -contentInset.top;
|
|
2191
|
+
scrollView.current?.scrollTo({ y: offset, animated: true });
|
|
2192
|
+
}, [isHorizontal, contentInset.top, pullSearchHeight]);
|
|
2193
|
+
const refreshControl = useMemo4(() => onRefresh ? /* @__PURE__ */ jsx7(RefreshControl, { onRefresh, refreshing: refreshing ?? false }) : /* @__PURE__ */ jsx7(RefreshControl, {}), [onRefresh, refreshing]);
|
|
2194
|
+
const nativeGesture = useMemo4(() => Gesture3.Native(), []);
|
|
2195
|
+
const combinedGesture = useMemo4(() => gesture !== void 0 ? Gesture3.Simultaneous(gesture, nativeGesture) : nativeGesture, [gesture, nativeGesture]);
|
|
2196
|
+
const detectorGesture = gesture !== void 0 ? combinedGesture : void 0;
|
|
2197
|
+
const content = /* @__PURE__ */ jsxs4(View4, { style: containerStyle, children: [
|
|
2198
|
+
/* @__PURE__ */ jsx7(
|
|
2199
|
+
Animated5.ScrollView,
|
|
2200
|
+
{
|
|
2201
|
+
...props,
|
|
2202
|
+
contentInset,
|
|
2203
|
+
contentOffset,
|
|
2204
|
+
onMomentumScrollEnd: handleMomentumScrollEnd,
|
|
2205
|
+
onScroll: handleScroll,
|
|
2206
|
+
onScrollBeginDrag: handleScrollBeginDrag,
|
|
2207
|
+
onScrollEndDrag: handleScrollEndDrag,
|
|
2208
|
+
ref: (el) => {
|
|
2209
|
+
if (props.ref) props.ref.current = el;
|
|
2210
|
+
scrollView.current = el;
|
|
2211
|
+
},
|
|
2212
|
+
refreshControl,
|
|
2213
|
+
scrollEventThrottle: 16,
|
|
2214
|
+
children
|
|
2215
|
+
}
|
|
2216
|
+
),
|
|
2217
|
+
/* @__PURE__ */ jsx7(ScrollViewChip, { isHorizontal, onPress: handleScrollToTop, style: chipStyle })
|
|
2218
|
+
] });
|
|
2219
|
+
return detectorGesture ? /* @__PURE__ */ jsx7(GestureDetector3, { gesture: detectorGesture, children: content }) : content;
|
|
2220
|
+
};
|
|
2221
|
+
var ScrollView = memo3(ScrollViewInner);
|
|
2222
|
+
|
|
2223
|
+
// src/ScrollViewFooter.tsx
|
|
2224
|
+
import { BlurView as BlurView2 } from "@rific/auto-paper";
|
|
2225
|
+
import { useContext as useContext6, useEffect as useEffect4 } from "react";
|
|
2226
|
+
import { StyleSheet as StyleSheet5, View as View5 } from "react-native";
|
|
2227
|
+
import Animated6, { useAnimatedStyle as useAnimatedStyle4 } from "react-native-reanimated";
|
|
2228
|
+
import { useSafeAreaInsets as useSafeAreaInsets3 } from "react-native-safe-area-context";
|
|
2229
|
+
import { jsx as jsx8, jsxs as jsxs5 } from "react/jsx-runtime";
|
|
2230
|
+
var ScrollViewFooter = ({ children, style }) => {
|
|
2231
|
+
const { blur, footerHeight, footerFixed, footerOffset, headerHeightShared, pullSearchHeightShared, scrollPosition, setFooterHeight, snapBackFooterShared } = useContext6(ScrollViewContext);
|
|
2232
|
+
const insets = useSafeAreaInsets3();
|
|
2233
|
+
useEffect4(
|
|
2234
|
+
() => () => {
|
|
2235
|
+
setFooterHeight(0);
|
|
2236
|
+
},
|
|
2237
|
+
[setFooterHeight]
|
|
2238
|
+
);
|
|
2239
|
+
const handleLayout = ({
|
|
2240
|
+
nativeEvent: {
|
|
2241
|
+
layout: { height }
|
|
2242
|
+
}
|
|
2243
|
+
}) => {
|
|
2244
|
+
if (footerHeight !== height) setFooterHeight(height);
|
|
2245
|
+
};
|
|
2246
|
+
const footerStyle = useAnimatedStyle4(() => {
|
|
2247
|
+
if (footerFixed) return { transform: [{ translateY: 0 }] };
|
|
2248
|
+
if (snapBackFooterShared.value) return { transform: [{ translateY: footerOffset.value }] };
|
|
2249
|
+
const effective = scrollPosition.value + headerHeightShared.value - pullSearchHeightShared.value;
|
|
2250
|
+
if (effective <= 0) return { transform: [{ translateY: 0 }] };
|
|
2251
|
+
return { transform: [{ translateY: Math.min(effective, footerHeight) }] };
|
|
2252
|
+
}, [footerHeight, footerFixed]);
|
|
2253
|
+
return /* @__PURE__ */ jsxs5(Animated6.View, { onLayout: handleLayout, pointerEvents: "box-none", style: [styles6.footer, footerStyle], children: [
|
|
2254
|
+
footerHeight > 0 && /* @__PURE__ */ jsx8(BlurView2, { blur, style: StyleSheet5.absoluteFill }),
|
|
2255
|
+
/* @__PURE__ */ jsx8(View5, { style: [styles6.row, { paddingBottom: insets.bottom }, style], children })
|
|
2256
|
+
] });
|
|
2257
|
+
};
|
|
2258
|
+
var styles6 = StyleSheet5.create({
|
|
2259
|
+
footer: { bottom: 0, left: 0, position: "absolute", right: 0, zIndex: 2 },
|
|
2260
|
+
row: { alignItems: "center", flexDirection: "row", zIndex: 1 }
|
|
2261
|
+
});
|
|
2262
|
+
|
|
2263
|
+
// src/ScrollViewHeader.tsx
|
|
2264
|
+
import { BlurView as BlurView3 } from "@rific/auto-paper";
|
|
2265
|
+
import { useContext as useContext7 } from "react";
|
|
2266
|
+
import { StyleSheet as StyleSheet6, Text, View as View6 } from "react-native";
|
|
2267
|
+
import { Appbar, ProgressBar, Surface, useTheme as useTheme3 } from "react-native-paper";
|
|
2268
|
+
import Animated7, { useAnimatedStyle as useAnimatedStyle5 } from "react-native-reanimated";
|
|
2269
|
+
import { useSafeAreaInsets as useSafeAreaInsets4 } from "react-native-safe-area-context";
|
|
2270
|
+
import { Fragment as Fragment3, jsx as jsx9, jsxs as jsxs6 } from "react/jsx-runtime";
|
|
2271
|
+
var ActionBg = ({ blur, style }) => blur ? /* @__PURE__ */ jsx9(View6, { style: [StyleSheet6.absoluteFill, styles7.actionBg, style], children: /* @__PURE__ */ jsx9(BlurView3, { blur: true, style: StyleSheet6.absoluteFill }) }) : /* @__PURE__ */ jsx9(View6, { style: [StyleSheet6.absoluteFill, styles7.actionBg, style], pointerEvents: "none", children: /* @__PURE__ */ jsx9(Surface, { style: StyleSheet6.absoluteFill, elevation: 1, children: null }) });
|
|
2272
|
+
var ScrollViewHeader = ({ actionSize = 48, actionStyle, backAction, backActionFixed, caption, centerContent, children, iconSize, style, title, topInset = true, trailingAction, trailingActionFixed = true }) => {
|
|
2273
|
+
const { blur, headerHeight, headerFixed, headerOffset, progress, progressing, pullSearchHeightShared, scrollPosition, setHeaderHeight, snapBackHeaderShared } = useContext7(ScrollViewContext);
|
|
2274
|
+
const { settings } = useContext7(ScrollViewSettingsContext);
|
|
2275
|
+
const effectiveBackActionFixed = backActionFixed ?? settings.backActionFixed;
|
|
2276
|
+
const insets = useSafeAreaInsets4();
|
|
2277
|
+
const theme = useTheme3();
|
|
2278
|
+
const top = topInset ? insets.top : 0;
|
|
2279
|
+
const handleLayout = ({
|
|
2280
|
+
nativeEvent: {
|
|
2281
|
+
layout: { height }
|
|
2282
|
+
}
|
|
2283
|
+
}) => {
|
|
2284
|
+
if (headerHeight !== height) setHeaderHeight(height);
|
|
2285
|
+
};
|
|
2286
|
+
const translateStyle = useAnimatedStyle5(() => {
|
|
2287
|
+
if (headerFixed) return { transform: [{ translateY: 0 }] };
|
|
2288
|
+
if (snapBackHeaderShared.value) return { transform: [{ translateY: headerOffset.value }] };
|
|
2289
|
+
const effective = scrollPosition.value + headerHeight - pullSearchHeightShared.value;
|
|
2290
|
+
if (effective <= 0) return { transform: [{ translateY: 0 }] };
|
|
2291
|
+
return { transform: [{ translateY: -effective }] };
|
|
2292
|
+
}, [headerFixed, headerHeight]);
|
|
2293
|
+
const blurStyle = useAnimatedStyle5(() => {
|
|
2294
|
+
if (!headerHeight) return { height: 0 };
|
|
2295
|
+
if (headerFixed) return { height: headerHeight };
|
|
2296
|
+
const translateY = snapBackHeaderShared.value ? headerOffset.value : -Math.max(0, scrollPosition.value + headerHeight - pullSearchHeightShared.value);
|
|
2297
|
+
return { height: Math.max(headerHeight + translateY, top) };
|
|
2298
|
+
}, [headerFixed, headerHeight, top]);
|
|
2299
|
+
const progressStyle = useAnimatedStyle5(() => {
|
|
2300
|
+
if (headerFixed) return { top: headerHeight };
|
|
2301
|
+
const slide = snapBackHeaderShared.value ? -headerOffset.value : Math.max(0, scrollPosition.value + headerHeight - pullSearchHeightShared.value);
|
|
2302
|
+
return { top: Math.max(headerHeight - slide, top) };
|
|
2303
|
+
}, [headerFixed, headerHeight, top]);
|
|
2304
|
+
const actionMargin = 4;
|
|
2305
|
+
const contentMinHeight = actionSize + 2 * actionMargin;
|
|
2306
|
+
const actionTop = top + actionMargin;
|
|
2307
|
+
const buttonStyle = { borderRadius: actionSize, height: actionSize, margin: 0, width: actionSize };
|
|
2308
|
+
const actionShadow = { borderRadius: actionSize / 2, elevation: 2, shadowColor: "#000", shadowOffset: { width: 0, height: 1 }, shadowOpacity: 0.15, shadowRadius: 2 };
|
|
2309
|
+
const leadingStyle = { alignItems: "center", height: actionSize, justifyContent: "center", left: actionMargin, position: "absolute", top: actionTop, width: actionSize, zIndex: 3, ...actionShadow };
|
|
2310
|
+
const trailingStyle = { alignItems: "center", height: actionSize, justifyContent: "center", position: "absolute", right: actionMargin, top: actionTop, width: actionSize, zIndex: 3, ...actionShadow };
|
|
2311
|
+
return /* @__PURE__ */ jsxs6(Fragment3, { children: [
|
|
2312
|
+
/* @__PURE__ */ jsx9(Animated7.View, { pointerEvents: "none", style: [styles7.blur, blurStyle], children: headerHeight > 0 && /* @__PURE__ */ jsx9(BlurView3, { blur, style: [styles7.blurInner, { height: headerHeight }] }) }),
|
|
2313
|
+
/* @__PURE__ */ jsxs6(Animated7.View, { onLayout: handleLayout, pointerEvents: "box-none", style: [headerHeight === 0 ? styles7.headerInit : styles7.header, translateStyle], children: [
|
|
2314
|
+
/* @__PURE__ */ jsx9(View6, { style: [{ paddingTop: top }, style], children: /* @__PURE__ */ jsxs6(View6, { style: [styles7.content, { minHeight: contentMinHeight }], children: [
|
|
2315
|
+
/* @__PURE__ */ jsx9(View6, { style: styles7.side }),
|
|
2316
|
+
/* @__PURE__ */ jsx9(View6, { style: styles7.spacer }),
|
|
2317
|
+
/* @__PURE__ */ jsx9(View6, { style: styles7.side, children }),
|
|
2318
|
+
(centerContent || title || caption) && /* @__PURE__ */ jsx9(View6, { style: [StyleSheet6.absoluteFill, styles7.titleContainer], pointerEvents: centerContent ? "box-none" : "none", children: centerContent ?? /* @__PURE__ */ jsxs6(Fragment3, { children: [
|
|
2319
|
+
title && /* @__PURE__ */ jsx9(Text, { numberOfLines: 1, style: [styles7.title, { color: theme.colors.onSurface }], children: title }),
|
|
2320
|
+
caption && /* @__PURE__ */ jsx9(Text, { numberOfLines: 1, style: [styles7.caption, { color: theme.colors.onSurfaceVariant }], children: caption })
|
|
2321
|
+
] }) })
|
|
2322
|
+
] }) }),
|
|
2323
|
+
!blur && /* @__PURE__ */ jsx9(View6, { style: [styles7.divider, { backgroundColor: theme.colors.outlineVariant }] })
|
|
2324
|
+
] }),
|
|
2325
|
+
/* @__PURE__ */ jsx9(Animated7.View, { pointerEvents: "none", style: [styles7.progress, progressStyle], children: /* @__PURE__ */ jsx9(ProgressBar, { indeterminate: progress === null, visible: progressing, progress: progress ?? void 0 }) }),
|
|
2326
|
+
backAction && (effectiveBackActionFixed ? /* @__PURE__ */ jsxs6(Animated7.View, { style: leadingStyle, children: [
|
|
2327
|
+
/* @__PURE__ */ jsx9(ActionBg, { blur, style: actionStyle }),
|
|
2328
|
+
/* @__PURE__ */ jsx9(Appbar.BackAction, { onPress: backAction, size: iconSize ?? actionSize / 2, style: buttonStyle })
|
|
2329
|
+
] }) : /* @__PURE__ */ jsxs6(Animated7.View, { style: [leadingStyle, translateStyle], children: [
|
|
2330
|
+
/* @__PURE__ */ jsx9(ActionBg, { blur, style: actionStyle }),
|
|
2331
|
+
/* @__PURE__ */ jsx9(Appbar.BackAction, { onPress: backAction, size: iconSize ?? actionSize / 2, style: buttonStyle })
|
|
2332
|
+
] })),
|
|
2333
|
+
trailingAction && (trailingActionFixed ? /* @__PURE__ */ jsxs6(View6, { style: trailingStyle, children: [
|
|
2334
|
+
/* @__PURE__ */ jsx9(ActionBg, { blur, style: actionStyle }),
|
|
2335
|
+
trailingAction
|
|
2336
|
+
] }) : /* @__PURE__ */ jsxs6(Animated7.View, { style: [trailingStyle, translateStyle], children: [
|
|
2337
|
+
/* @__PURE__ */ jsx9(ActionBg, { blur, style: actionStyle }),
|
|
2338
|
+
trailingAction
|
|
2339
|
+
] }))
|
|
2340
|
+
] });
|
|
2341
|
+
};
|
|
2342
|
+
var styles7 = StyleSheet6.create({
|
|
2343
|
+
actionBg: { borderRadius: 100, overflow: "hidden" },
|
|
2344
|
+
divider: { bottom: 0, height: StyleSheet6.hairlineWidth, left: 0, position: "absolute", right: 0 },
|
|
2345
|
+
caption: { fontSize: 12, fontWeight: "400", textAlign: "center" },
|
|
2346
|
+
content: { alignItems: "center", flexDirection: "row", width: "100%" },
|
|
2347
|
+
blur: { left: 0, overflow: "hidden", position: "absolute", right: 0, top: 0, zIndex: 2 },
|
|
2348
|
+
blurInner: { left: 0, position: "absolute", right: 0, top: 0 },
|
|
2349
|
+
header: { left: 0, overflow: "hidden", position: "absolute", right: 0, top: 0, zIndex: 2 },
|
|
2350
|
+
headerInit: { left: 0, overflow: "hidden", right: 0, zIndex: 2 },
|
|
2351
|
+
progress: { left: 0, position: "absolute", right: 0, zIndex: 3 },
|
|
2352
|
+
side: { alignItems: "center", flexDirection: "row" },
|
|
2353
|
+
spacer: { flex: 1 },
|
|
2354
|
+
title: { fontSize: 20, fontWeight: "400", textAlign: "center" },
|
|
2355
|
+
titleContainer: { alignItems: "center", justifyContent: "center" }
|
|
2356
|
+
});
|
|
2357
|
+
|
|
2358
|
+
// src/ScrollViewProvider.tsx
|
|
2359
|
+
import { useBlur } from "@rific/auto-paper";
|
|
2360
|
+
import { useCallback as useCallback6, useContext as useContext8, useEffect as useEffect5, useMemo as useMemo5, useState as useState4 } from "react";
|
|
2361
|
+
import { Dimensions as Dimensions3 } from "react-native";
|
|
2362
|
+
import { useSharedValue as useSharedValue3 } from "react-native-reanimated";
|
|
2363
|
+
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
2364
|
+
var ScrollViewProvider = ({ blur, children, fixed = false, footerFixed, headerFixed, snapBack, snapBackFooter, snapBackHeader, tabBarHeight = 60 }) => {
|
|
2365
|
+
const { settings } = useContext8(ScrollViewSettingsContext);
|
|
2366
|
+
const effectiveBlur = useBlur(blur);
|
|
2367
|
+
const effectiveSnapBack = snapBack ?? settings.snapBack;
|
|
2368
|
+
const effectiveSnapBackHeader = snapBackHeader ?? settings.snapBackHeader;
|
|
2369
|
+
const effectiveSnapBackFooter = snapBackFooter ?? settings.snapBackFooter;
|
|
2370
|
+
const [headerHeight, setHeaderHeightState] = useState4(0);
|
|
2371
|
+
const [footerHeight, setFooterHeightState] = useState4(0);
|
|
2372
|
+
const [progress, setProgress] = useState4(null);
|
|
2373
|
+
const [progressing, setProgressing] = useState4(false);
|
|
2374
|
+
const scrollPosition = useSharedValue3(0);
|
|
2375
|
+
const headerHeightShared = useSharedValue3(0);
|
|
2376
|
+
const footerHeightShared = useSharedValue3(0);
|
|
2377
|
+
const headerOffset = useSharedValue3(0);
|
|
2378
|
+
const footerOffset = useSharedValue3(0);
|
|
2379
|
+
const pullSearchHeightShared = useSharedValue3(0);
|
|
2380
|
+
const snapBackHeaderShared = useSharedValue3(false);
|
|
2381
|
+
const snapBackFooterShared = useSharedValue3(false);
|
|
2382
|
+
useEffect5(() => {
|
|
2383
|
+
snapBackHeaderShared.value = effectiveSnapBackHeader ?? effectiveSnapBack;
|
|
2384
|
+
snapBackFooterShared.value = effectiveSnapBackFooter ?? effectiveSnapBack;
|
|
2385
|
+
}, [effectiveSnapBack, effectiveSnapBackFooter, effectiveSnapBackHeader, snapBackFooterShared, snapBackHeaderShared]);
|
|
2386
|
+
const setHeaderHeight = useCallback6(
|
|
2387
|
+
(h) => {
|
|
2388
|
+
setHeaderHeightState(h);
|
|
2389
|
+
headerHeightShared.value = h;
|
|
2390
|
+
},
|
|
2391
|
+
[headerHeightShared]
|
|
2392
|
+
);
|
|
2393
|
+
const setFooterHeight = useCallback6(
|
|
2394
|
+
(h) => {
|
|
2395
|
+
setFooterHeightState(h);
|
|
2396
|
+
footerHeightShared.value = h;
|
|
2397
|
+
},
|
|
2398
|
+
[footerHeightShared]
|
|
2399
|
+
);
|
|
2400
|
+
const scrollHeight = useMemo5(() => Dimensions3.get("window").height - headerHeight - footerHeight, [headerHeight, footerHeight]);
|
|
2401
|
+
const effectiveHeaderFixed = fixed || (headerFixed ?? settings.headerFixed);
|
|
2402
|
+
const effectiveFooterFixed = fixed || (footerFixed ?? settings.footerFixed);
|
|
2403
|
+
const value = useMemo5(() => ({ blur: effectiveBlur, footerHeight, footerHeightShared, footerFixed: effectiveFooterFixed, footerOffset, headerHeight, headerHeightShared, headerFixed: effectiveHeaderFixed, headerOffset, progress, pullSearchHeightShared, progressing, scrollHeight, scrollPosition, setFooterHeight, setHeaderHeight, setProgress, setProgressing, snapBackFooterShared, snapBackHeaderShared, tabBarHeight }), [effectiveBlur, effectiveFooterFixed, effectiveHeaderFixed, footerHeight, footerHeightShared, footerOffset, headerHeight, headerHeightShared, headerOffset, progress, pullSearchHeightShared, progressing, scrollHeight, scrollPosition, setFooterHeight, setHeaderHeight, snapBackFooterShared, snapBackHeaderShared, tabBarHeight]);
|
|
2404
|
+
return /* @__PURE__ */ jsx10(ScrollViewContext.Provider, { value, children });
|
|
2405
|
+
};
|
|
2406
|
+
|
|
2407
|
+
// src/ScrollViewSettingsProvider.tsx
|
|
2408
|
+
import { useCallback as useCallback7, useMemo as useMemo6, useState as useState5 } from "react";
|
|
2409
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
|
2410
|
+
var ScrollViewSettingsProvider = ({ children, onChange, value }) => {
|
|
2411
|
+
const [settings, setSettings] = useState5(() => ({
|
|
2412
|
+
...defaultScrollViewSettings,
|
|
2413
|
+
...value
|
|
2414
|
+
}));
|
|
2415
|
+
const set2 = useCallback7(
|
|
2416
|
+
(patch) => {
|
|
2417
|
+
setSettings((prev) => {
|
|
2418
|
+
const next = { ...prev, ...patch };
|
|
2419
|
+
onChange?.(next);
|
|
2420
|
+
return next;
|
|
2421
|
+
});
|
|
2422
|
+
},
|
|
2423
|
+
[onChange]
|
|
2424
|
+
);
|
|
2425
|
+
const ctx = useMemo6(() => ({ settings, set: set2 }), [settings, set2]);
|
|
2426
|
+
return /* @__PURE__ */ jsx11(ScrollViewSettingsContext.Provider, { value: ctx, children });
|
|
2427
|
+
};
|
|
2428
|
+
|
|
2429
|
+
// src/SectionList.tsx
|
|
2430
|
+
import { memo as memo4, useCallback as useCallback9, useEffect as useEffect6, useLayoutEffect as useLayoutEffect3, useMemo as useMemo7, useRef as useRef7 } from "react";
|
|
2431
|
+
import { Dimensions as Dimensions4, SectionList as RNSectionList, View as View7 } from "react-native";
|
|
2432
|
+
import { Gesture as Gesture4, GestureDetector as GestureDetector4 } from "react-native-gesture-handler";
|
|
2433
|
+
import Animated8, { createAnimatedComponent } from "react-native-reanimated";
|
|
2434
|
+
|
|
2435
|
+
// src/internal/useStickyHeaders.ts
|
|
2436
|
+
import { useCallback as useCallback8, useContext as useContext9, useLayoutEffect as useLayoutEffect2, useRef as useRef6, useState as useState6 } from "react";
|
|
2437
|
+
import { runOnJS as runOnJS4, useAnimatedReaction as useAnimatedReaction2, useAnimatedStyle as useAnimatedStyle6, useSharedValue as useSharedValue4 } from "react-native-reanimated";
|
|
2438
|
+
import { useSafeAreaInsets as useSafeAreaInsets5 } from "react-native-safe-area-context";
|
|
2439
|
+
function useStickyHeaders(headerFixed, enabled) {
|
|
2440
|
+
const { headerHeightShared, headerOffset, pullSearchHeightShared, scrollPosition, snapBackHeaderShared } = useContext9(ScrollViewContext);
|
|
2441
|
+
const insetsTop = useSafeAreaInsets5().top;
|
|
2442
|
+
const sectionYPositions = useSharedValue4([]);
|
|
2443
|
+
const sectionHeights = useSharedValue4([]);
|
|
2444
|
+
const [activeIndex, setActiveIndex] = useState6(-1);
|
|
2445
|
+
const contentIndexShared = useSharedValue4(-1);
|
|
2446
|
+
useLayoutEffect2(() => {
|
|
2447
|
+
contentIndexShared.value = activeIndex;
|
|
2448
|
+
}, [activeIndex, contentIndexShared]);
|
|
2449
|
+
const positionsCache = useRef6([]);
|
|
2450
|
+
const heightsCache = useRef6([]);
|
|
2451
|
+
useAnimatedReaction2(
|
|
2452
|
+
() => {
|
|
2453
|
+
if (!enabled) return -1;
|
|
2454
|
+
const positions = sectionYPositions.value;
|
|
2455
|
+
if (positions.length === 0) return -1;
|
|
2456
|
+
const hHeight = headerHeightShared.value;
|
|
2457
|
+
const scrollPos = scrollPosition.value;
|
|
2458
|
+
let stickyTop;
|
|
2459
|
+
if (headerFixed) {
|
|
2460
|
+
stickyTop = hHeight;
|
|
2461
|
+
} else if (snapBackHeaderShared.value) {
|
|
2462
|
+
stickyTop = Math.max(insetsTop, hHeight + headerOffset.value);
|
|
2463
|
+
} else {
|
|
2464
|
+
const effective = scrollPos + hHeight - pullSearchHeightShared.value;
|
|
2465
|
+
stickyTop = effective <= 0 ? hHeight : Math.max(insetsTop, hHeight - effective);
|
|
2466
|
+
}
|
|
2467
|
+
const threshold = scrollPos + stickyTop;
|
|
2468
|
+
let active = -1;
|
|
2469
|
+
for (let i = 0; i < positions.length; i++) {
|
|
2470
|
+
if (positions[i] >= 0 && positions[i] < threshold) active = i;
|
|
2471
|
+
else if (positions[i] >= 0) break;
|
|
2472
|
+
}
|
|
2473
|
+
return active;
|
|
2474
|
+
},
|
|
2475
|
+
(curr, prev) => {
|
|
2476
|
+
if (curr !== prev) runOnJS4(setActiveIndex)(curr);
|
|
2477
|
+
},
|
|
2478
|
+
[enabled, headerFixed, insetsTop]
|
|
2479
|
+
);
|
|
2480
|
+
const clipStyle = useAnimatedStyle6(() => {
|
|
2481
|
+
const hHeight = headerHeightShared.value;
|
|
2482
|
+
const scrollPos = scrollPosition.value;
|
|
2483
|
+
let stickyTop;
|
|
2484
|
+
if (!enabled || headerFixed) {
|
|
2485
|
+
stickyTop = hHeight;
|
|
2486
|
+
} else if (snapBackHeaderShared.value) {
|
|
2487
|
+
stickyTop = Math.max(insetsTop, hHeight + headerOffset.value);
|
|
2488
|
+
} else {
|
|
2489
|
+
const effective = scrollPos + hHeight - pullSearchHeightShared.value;
|
|
2490
|
+
stickyTop = effective <= 0 ? hHeight : Math.max(insetsTop, hHeight - effective);
|
|
2491
|
+
}
|
|
2492
|
+
return { top: stickyTop };
|
|
2493
|
+
}, [enabled, headerFixed, insetsTop]);
|
|
2494
|
+
const overlayStyle = useAnimatedStyle6(() => {
|
|
2495
|
+
const hidden = { opacity: 0, top: 0, transform: [{ translateY: 0 }] };
|
|
2496
|
+
if (!enabled) return hidden;
|
|
2497
|
+
const index = contentIndexShared.value;
|
|
2498
|
+
const positions = sectionYPositions.value;
|
|
2499
|
+
if (index < 0 || index >= positions.length) return hidden;
|
|
2500
|
+
const hHeight = headerHeightShared.value;
|
|
2501
|
+
const scrollPos = scrollPosition.value;
|
|
2502
|
+
let stickyTop;
|
|
2503
|
+
if (headerFixed) {
|
|
2504
|
+
stickyTop = hHeight;
|
|
2505
|
+
} else if (snapBackHeaderShared.value) {
|
|
2506
|
+
stickyTop = Math.max(insetsTop, hHeight + headerOffset.value);
|
|
2507
|
+
} else {
|
|
2508
|
+
const effective = scrollPos + hHeight - pullSearchHeightShared.value;
|
|
2509
|
+
stickyTop = effective <= 0 ? hHeight : Math.max(insetsTop, hHeight - effective);
|
|
2510
|
+
}
|
|
2511
|
+
if (positions[index] - scrollPos >= stickyTop) return hidden;
|
|
2512
|
+
const currentHeight = Math.max(0, sectionHeights.value[index] ?? 0);
|
|
2513
|
+
const nextIndex = index + 1;
|
|
2514
|
+
let translateY = 0;
|
|
2515
|
+
if (currentHeight > 0 && nextIndex < positions.length && positions[nextIndex] >= 0) {
|
|
2516
|
+
const nextScreenY = positions[nextIndex] - scrollPos;
|
|
2517
|
+
const pushThreshold = stickyTop + currentHeight;
|
|
2518
|
+
if (nextScreenY < pushThreshold) translateY = nextScreenY - pushThreshold;
|
|
2519
|
+
}
|
|
2520
|
+
return { opacity: 1, top: 0, transform: [{ translateY }] };
|
|
2521
|
+
}, [enabled, headerFixed, insetsTop]);
|
|
2522
|
+
const measureHeader = useCallback8(
|
|
2523
|
+
(index, pageY, height) => {
|
|
2524
|
+
const contentY = pageY + scrollPosition.value;
|
|
2525
|
+
positionsCache.current[index] = contentY;
|
|
2526
|
+
sectionYPositions.value = positionsCache.current.slice();
|
|
2527
|
+
heightsCache.current[index] = height;
|
|
2528
|
+
sectionHeights.value = heightsCache.current.slice();
|
|
2529
|
+
},
|
|
2530
|
+
[scrollPosition, sectionHeights, sectionYPositions]
|
|
2531
|
+
);
|
|
2532
|
+
const resetPositions = useCallback8(
|
|
2533
|
+
(count) => {
|
|
2534
|
+
positionsCache.current = Array.from({ length: count }, () => -1);
|
|
2535
|
+
sectionYPositions.value = positionsCache.current.slice();
|
|
2536
|
+
heightsCache.current = Array.from({ length: count }, () => -1);
|
|
2537
|
+
sectionHeights.value = heightsCache.current.slice();
|
|
2538
|
+
},
|
|
2539
|
+
[sectionHeights, sectionYPositions]
|
|
2540
|
+
);
|
|
2541
|
+
return { activeIndex, clipStyle, measureHeader, overlayStyle, resetPositions };
|
|
2542
|
+
}
|
|
2543
|
+
|
|
2544
|
+
// src/SectionList.tsx
|
|
2545
|
+
import { Fragment as Fragment4, jsx as jsx12, jsxs as jsxs7 } from "react/jsx-runtime";
|
|
2546
|
+
var AnimatedSectionList = createAnimatedComponent(RNSectionList);
|
|
2547
|
+
var SectionListInner = ({ contentContainerStyle: externalContentContainerStyle, initialNumToRender = 20, maxToRenderPerBatch = 50, renderFilters, footerFixed: footerFixedProp, gesture, headerFixed: headerFixedProp, keyboardAware, ListHeaderComponent: externalListHeaderComponent, onMomentumScrollEnd: externalMomentumScrollEnd, onRefresh, onContentSizeChange, onScrollBeginDrag: externalScrollBeginDrag, onScrollEndDrag: externalScrollEndDrag, pullSearchHeight, refreshing, removeClippedSubviews = false, sections, showsVerticalScrollIndicator, style, ref: externalRef, windowSize = 100, ...props }) => {
|
|
2548
|
+
const scrollView = useRef7(null);
|
|
2549
|
+
const { stickySectionHeadersEnabled = true, renderSectionHeader, ...passThroughProps } = props;
|
|
2550
|
+
const { chipHidden, chipStyle, containerStyle, contentInset, contentOffset, footerFixed, headerFixed, headerHeight } = useScrollList({ footerFixed: footerFixedProp, headerFixed: headerFixedProp, keyboardAware, pullSearchHeight, style });
|
|
2551
|
+
const usesCustomSticky = stickySectionHeadersEnabled && renderSectionHeader != null;
|
|
2552
|
+
const { activeIndex, clipStyle, measureHeader, overlayStyle, resetPositions } = useStickyHeaders(headerFixed, usesCustomSticky);
|
|
2553
|
+
useLayoutEffect3(() => {
|
|
2554
|
+
if (usesCustomSticky) resetPositions(sections.length);
|
|
2555
|
+
}, [sections, usesCustomSticky, resetPositions, headerHeight]);
|
|
2556
|
+
const sectionViewRefs = useRef7(/* @__PURE__ */ new Map());
|
|
2557
|
+
const wrappedRenderSectionHeader = useMemo7(() => {
|
|
2558
|
+
if (!usesCustomSticky) return renderSectionHeader ?? void 0;
|
|
2559
|
+
return (info) => {
|
|
2560
|
+
const idx = sections.findIndex((s) => s === info.section);
|
|
2561
|
+
return /* @__PURE__ */ jsx12(
|
|
2562
|
+
View7,
|
|
2563
|
+
{
|
|
2564
|
+
ref: (el) => {
|
|
2565
|
+
sectionViewRefs.current.set(idx, el);
|
|
2566
|
+
},
|
|
2567
|
+
onLayout: () => {
|
|
2568
|
+
const el = sectionViewRefs.current.get(idx);
|
|
2569
|
+
el?.measure((_x, _y, _w, h, _px, pageY) => {
|
|
2570
|
+
if (idx >= 0 && sectionViewRefs.current.get(idx) === el) measureHeader(idx, pageY, h);
|
|
2571
|
+
});
|
|
2572
|
+
},
|
|
2573
|
+
children: renderSectionHeader(info)
|
|
2574
|
+
}
|
|
2575
|
+
);
|
|
2576
|
+
};
|
|
2577
|
+
}, [usesCustomSticky, renderSectionHeader, sections, measureHeader]);
|
|
2578
|
+
const scrollTo = useCallback9((offset, animated) => {
|
|
2579
|
+
scrollView.current?.getScrollResponder()?.scrollTo({ y: offset, animated });
|
|
2580
|
+
}, []);
|
|
2581
|
+
const {
|
|
2582
|
+
activeListHeader: pullSearchHeader,
|
|
2583
|
+
handleMomentumScrollEnd,
|
|
2584
|
+
handleScrollBeginDrag,
|
|
2585
|
+
handleScrollEndDrag,
|
|
2586
|
+
hiddenHeader,
|
|
2587
|
+
pullSearchMinHeight
|
|
2588
|
+
} = useScrollInit({
|
|
2589
|
+
listHeaderComponent: externalListHeaderComponent,
|
|
2590
|
+
onMomentumScrollEnd: externalMomentumScrollEnd,
|
|
2591
|
+
onScrollBeginDrag: externalScrollBeginDrag,
|
|
2592
|
+
onScrollEndDrag: externalScrollEndDrag,
|
|
2593
|
+
pullSearchHeight,
|
|
2594
|
+
scrollTo
|
|
2595
|
+
});
|
|
2596
|
+
const activeListHeader = useMemo7(() => {
|
|
2597
|
+
if (!renderFilters) return pullSearchHeader;
|
|
2598
|
+
const Inner = pullSearchHeader;
|
|
2599
|
+
return () => /* @__PURE__ */ jsxs7(Fragment4, { children: [
|
|
2600
|
+
Inner ? typeof Inner === "function" ? /* @__PURE__ */ jsx12(Inner, {}) : Inner : null,
|
|
2601
|
+
renderFilters
|
|
2602
|
+
] });
|
|
2603
|
+
}, [pullSearchHeader, renderFilters]);
|
|
2604
|
+
const pullSearchSettled = useRef7(false);
|
|
2605
|
+
useEffect6(() => {
|
|
2606
|
+
if (!usesCustomSticky || activeListHeader == null || pullSearchSettled.current) return;
|
|
2607
|
+
pullSearchSettled.current = true;
|
|
2608
|
+
const handle = requestAnimationFrame(() => {
|
|
2609
|
+
sectionViewRefs.current.forEach((el, idx) => {
|
|
2610
|
+
el?.measure((_x, _y, _w, h, _px, pageY) => {
|
|
2611
|
+
if (sectionViewRefs.current.get(idx) === el) measureHeader(idx, pageY, h);
|
|
2612
|
+
});
|
|
2613
|
+
});
|
|
2614
|
+
});
|
|
2615
|
+
return () => cancelAnimationFrame(handle);
|
|
2616
|
+
}, [activeListHeader, usesCustomSticky, measureHeader]);
|
|
2617
|
+
const contentContainerStyle = useMemo7(() => [{ minHeight: Dimensions4.get("window").height - contentInset.top - contentInset.bottom + pullSearchMinHeight }, externalContentContainerStyle], [contentInset.bottom, contentInset.top, externalContentContainerStyle, pullSearchMinHeight]);
|
|
2618
|
+
const onPullSearchZoneEnter = useCallback9(() => {
|
|
2619
|
+
if (!pullSearchHeight) return;
|
|
2620
|
+
scrollTo(-contentInset.top + pullSearchHeight, true);
|
|
2621
|
+
}, [contentInset.top, pullSearchHeight, scrollTo]);
|
|
2622
|
+
const handleScroll = useScrollHandler({ chipHidden, footerFixed, headerFixed, onPullSearchZoneEnter: pullSearchHeight ? onPullSearchZoneEnter : void 0 });
|
|
2623
|
+
const handleScrollToTop = useCallback9(() => {
|
|
2624
|
+
const offset = pullSearchHeight ? -contentInset.top + pullSearchHeight : -contentInset.top;
|
|
2625
|
+
scrollView.current?.getScrollResponder()?.scrollTo({ y: offset, animated: true });
|
|
2626
|
+
}, [contentInset.top, pullSearchHeight]);
|
|
2627
|
+
const handleContentSizeChange = useCallback9(
|
|
2628
|
+
(w, h) => {
|
|
2629
|
+
if (onContentSizeChange) onContentSizeChange(w, h);
|
|
2630
|
+
},
|
|
2631
|
+
[onContentSizeChange]
|
|
2632
|
+
);
|
|
2633
|
+
const refreshControl = useMemo7(() => onRefresh ? /* @__PURE__ */ jsx12(RefreshControl, { onRefresh, refreshing: refreshing ?? false }) : /* @__PURE__ */ jsx12(RefreshControl, {}), [onRefresh, refreshing]);
|
|
2634
|
+
const nativeGesture = useMemo7(() => Gesture4.Native(), []);
|
|
2635
|
+
const combinedGesture = useMemo7(() => gesture !== void 0 ? Gesture4.Simultaneous(gesture, nativeGesture) : nativeGesture, [gesture, nativeGesture]);
|
|
2636
|
+
const detectorGesture = gesture !== void 0 ? combinedGesture : void 0;
|
|
2637
|
+
const content = /* @__PURE__ */ jsxs7(View7, { style: containerStyle, children: [
|
|
2638
|
+
/* @__PURE__ */ jsx12(
|
|
2639
|
+
AnimatedSectionList,
|
|
2640
|
+
{
|
|
2641
|
+
...passThroughProps,
|
|
2642
|
+
contentContainerStyle,
|
|
2643
|
+
contentInset,
|
|
2644
|
+
contentOffset,
|
|
2645
|
+
initialNumToRender,
|
|
2646
|
+
ListHeaderComponent: activeListHeader,
|
|
2647
|
+
maxToRenderPerBatch,
|
|
2648
|
+
onContentSizeChange: handleContentSizeChange,
|
|
2649
|
+
onMomentumScrollEnd: handleMomentumScrollEnd,
|
|
2650
|
+
onScroll: handleScroll,
|
|
2651
|
+
onScrollBeginDrag: handleScrollBeginDrag,
|
|
2652
|
+
onScrollEndDrag: handleScrollEndDrag,
|
|
2653
|
+
ref: (el) => {
|
|
2654
|
+
if (externalRef) externalRef.current = el;
|
|
2655
|
+
scrollView.current = el;
|
|
2656
|
+
},
|
|
2657
|
+
refreshControl,
|
|
2658
|
+
removeClippedSubviews,
|
|
2659
|
+
renderSectionHeader: wrappedRenderSectionHeader,
|
|
2660
|
+
scrollEventThrottle: 16,
|
|
2661
|
+
sections,
|
|
2662
|
+
showsVerticalScrollIndicator: showsVerticalScrollIndicator ?? true,
|
|
2663
|
+
stickySectionHeadersEnabled: false,
|
|
2664
|
+
windowSize
|
|
2665
|
+
},
|
|
2666
|
+
headerHeight > 0 ? 1 : 0
|
|
2667
|
+
),
|
|
2668
|
+
hiddenHeader && /* @__PURE__ */ jsx12(View7, { pointerEvents: "none", style: styles8.measureContainer, children: hiddenHeader }),
|
|
2669
|
+
/* @__PURE__ */ jsx12(ScrollViewChip, { onPress: handleScrollToTop, style: chipStyle }),
|
|
2670
|
+
usesCustomSticky && /* @__PURE__ */ jsx12(Animated8.View, { pointerEvents: "none", style: [styles8.stickyClip, clipStyle], children: activeIndex >= 0 && activeIndex < sections.length && /* @__PURE__ */ jsx12(Animated8.View, { style: [styles8.stickyOverlay, overlayStyle], children: renderSectionHeader({ section: sections[activeIndex] }) }) })
|
|
2671
|
+
] });
|
|
2672
|
+
return detectorGesture ? /* @__PURE__ */ jsx12(GestureDetector4, { gesture: detectorGesture, children: content }) : content;
|
|
2673
|
+
};
|
|
2674
|
+
var styles8 = {
|
|
2675
|
+
measureContainer: { left: 0, opacity: 0, position: "absolute", right: 0, top: -9999 },
|
|
2676
|
+
stickyClip: { bottom: 0, left: 0, overflow: "hidden", position: "absolute", right: 0, zIndex: 2 },
|
|
2677
|
+
stickyOverlay: { left: 0, position: "absolute", right: 0 }
|
|
2678
|
+
};
|
|
2679
|
+
var SectionList = memo4(SectionListInner);
|
|
2680
|
+
|
|
2681
|
+
// src/useScrollView.ts
|
|
2682
|
+
import { useContext as useContext10 } from "react";
|
|
2683
|
+
var useScrollView = () => {
|
|
2684
|
+
const { progress, progressing, scrollHeight, scrollPosition, setProgress, setProgressing } = useContext10(ScrollViewContext);
|
|
2685
|
+
return { progress, progressing, scrollHeight, scrollPosition, setProgress, setProgressing };
|
|
2686
|
+
};
|
|
2687
|
+
|
|
2688
|
+
// src/useScrollViewSettings.ts
|
|
2689
|
+
import { useContext as useContext11 } from "react";
|
|
2690
|
+
var useScrollViewSettings = () => useContext11(ScrollViewSettingsContext);
|
|
2691
|
+
export {
|
|
2692
|
+
CustomList,
|
|
2693
|
+
FlatList,
|
|
2694
|
+
PullSearch,
|
|
2695
|
+
ScrollView,
|
|
2696
|
+
ScrollViewContext,
|
|
2697
|
+
ScrollViewFooter,
|
|
2698
|
+
ScrollViewHeader,
|
|
2699
|
+
ScrollViewProvider,
|
|
2700
|
+
ScrollViewSettingsContext,
|
|
2701
|
+
ScrollViewSettingsProvider,
|
|
2702
|
+
SectionList,
|
|
2703
|
+
defaultScrollViewSettings,
|
|
2704
|
+
scrollViewActions,
|
|
2705
|
+
scrollViewReducer,
|
|
2706
|
+
useKeyboardInset,
|
|
2707
|
+
useScrollView,
|
|
2708
|
+
useScrollViewSettings
|
|
2709
|
+
};
|