@draftbit/core 48.0.3-fd9d4e.2 → 48.1.1-00500a.2
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/lib/src/components/NumberInput.d.ts +5 -3
- package/lib/src/components/NumberInput.js +13 -3
- package/lib/src/components/NumberInput.js.map +1 -1
- package/lib/src/components/Progress/CircularProgress/CircularProgress.d.ts +6 -0
- package/lib/src/components/Progress/CircularProgress/CircularProgress.js +101 -0
- package/lib/src/components/Progress/CircularProgress/CircularProgress.js.map +1 -0
- package/lib/src/components/Progress/CircularProgress/index.d.ts +6 -0
- package/lib/src/components/Progress/CircularProgress/index.js +14 -0
- package/lib/src/components/Progress/CircularProgress/index.js.map +1 -0
- package/lib/src/components/Progress/IndeterminateProgress.d.ts +7 -0
- package/lib/src/components/Progress/IndeterminateProgress.js +39 -0
- package/lib/src/components/Progress/IndeterminateProgress.js.map +1 -0
- package/lib/src/components/Progress/LinearProgress/LinearProgress.d.ts +6 -0
- package/lib/src/components/Progress/LinearProgress/LinearProgress.js +54 -0
- package/lib/src/components/Progress/LinearProgress/LinearProgress.js.map +1 -0
- package/lib/src/components/Progress/LinearProgress/index.d.ts +6 -0
- package/lib/src/components/Progress/LinearProgress/index.js +14 -0
- package/lib/src/components/Progress/LinearProgress/index.js.map +1 -0
- package/lib/src/components/Progress/ProgressCommon.d.ts +40 -0
- package/lib/src/components/Progress/ProgressCommon.js +2 -0
- package/lib/src/components/Progress/ProgressCommon.js.map +1 -0
- package/lib/src/components/SectionList/SectionHeader.d.ts +15 -0
- package/lib/src/components/SectionList/SectionHeader.js +14 -0
- package/lib/src/components/SectionList/SectionHeader.js.map +1 -0
- package/lib/src/components/SectionList/SectionList.d.ts +20 -0
- package/lib/src/components/SectionList/SectionList.js +95 -0
- package/lib/src/components/SectionList/SectionList.js.map +1 -0
- package/lib/src/components/SectionList/index.d.ts +2 -0
- package/lib/src/components/SectionList/index.js +3 -0
- package/lib/src/components/SectionList/index.js.map +1 -0
- package/lib/src/components/Table/TableCell.d.ts +1 -0
- package/lib/src/components/Table/TableCell.js +4 -2
- package/lib/src/components/Table/TableCell.js.map +1 -1
- package/lib/src/components/Table/TableRow.d.ts +1 -0
- package/lib/src/components/Table/TableRow.js +4 -2
- package/lib/src/components/Table/TableRow.js.map +1 -1
- package/lib/src/components/TextField.d.ts +2 -1
- package/lib/src/components/TextField.js +3 -2
- package/lib/src/components/TextField.js.map +1 -1
- package/lib/src/components/TextInput.d.ts +8 -0
- package/lib/src/components/TextInput.js +15 -0
- package/lib/src/components/TextInput.js.map +1 -0
- package/lib/src/hooks.d.ts +1 -0
- package/lib/src/hooks.js +12 -0
- package/lib/src/hooks.js.map +1 -1
- package/lib/src/index.d.ts +4 -0
- package/lib/src/index.js +4 -0
- package/lib/src/index.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +22 -4
- package/src/components/NumberInput.js +13 -3
- package/src/components/NumberInput.js.map +1 -1
- package/src/components/NumberInput.tsx +34 -5
- package/src/components/Progress/CircularProgress/CircularProgress.js +101 -0
- package/src/components/Progress/CircularProgress/CircularProgress.js.map +1 -0
- package/src/components/Progress/CircularProgress/CircularProgress.tsx +200 -0
- package/src/components/Progress/CircularProgress/index.js +14 -0
- package/src/components/Progress/CircularProgress/index.js.map +1 -0
- package/src/components/Progress/CircularProgress/index.tsx +28 -0
- package/src/components/Progress/IndeterminateProgress.js +39 -0
- package/src/components/Progress/IndeterminateProgress.js.map +1 -0
- package/src/components/Progress/IndeterminateProgress.tsx +74 -0
- package/src/components/Progress/LinearProgress/LinearProgress.js +54 -0
- package/src/components/Progress/LinearProgress/LinearProgress.js.map +1 -0
- package/src/components/Progress/LinearProgress/LinearProgress.tsx +132 -0
- package/src/components/Progress/LinearProgress/index.js +14 -0
- package/src/components/Progress/LinearProgress/index.js.map +1 -0
- package/src/components/Progress/LinearProgress/index.tsx +25 -0
- package/src/components/Progress/ProgressCommon.js +2 -0
- package/src/components/Progress/ProgressCommon.js.map +1 -0
- package/src/components/Progress/ProgressCommon.ts +44 -0
- package/src/components/SectionList/SectionHeader.js +14 -0
- package/src/components/SectionList/SectionHeader.js.map +1 -0
- package/src/components/SectionList/SectionHeader.tsx +37 -0
- package/src/components/SectionList/SectionList.js +95 -0
- package/src/components/SectionList/SectionList.js.map +1 -0
- package/src/components/SectionList/SectionList.tsx +171 -0
- package/src/components/SectionList/index.js +3 -0
- package/src/components/SectionList/index.js.map +1 -0
- package/src/components/SectionList/index.tsx +2 -0
- package/src/components/Table/TableCell.js +4 -2
- package/src/components/Table/TableCell.js.map +1 -1
- package/src/components/Table/TableCell.tsx +8 -2
- package/src/components/Table/TableRow.js +4 -2
- package/src/components/Table/TableRow.js.map +1 -1
- package/src/components/Table/TableRow.tsx +8 -2
- package/src/components/TextField.js +3 -2
- package/src/components/TextField.js.map +1 -1
- package/src/components/TextField.tsx +2 -2
- package/src/components/TextInput.js +15 -0
- package/src/components/TextInput.js.map +1 -0
- package/src/components/TextInput.tsx +35 -0
- package/src/hooks.js +12 -0
- package/src/hooks.js.map +1 -1
- package/src/hooks.ts +16 -0
- package/src/index.js +4 -0
- package/src/index.js.map +1 -1
- package/src/index.tsx +4 -0
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Svg, { Line } from "react-native-svg";
|
|
3
|
+
import Animated, { useAnimatedProps, useSharedValue, withTiming, } from "react-native-reanimated";
|
|
4
|
+
import { DEFAULT_ANIMATION_DURATION, } from "../ProgressCommon";
|
|
5
|
+
export const AnimatedLine = Animated.createAnimatedComponent(Line);
|
|
6
|
+
export const LinearProgress = ({ theme, minimumValue = 0, maximumValue = 100, value = minimumValue, thickness = 10, trackThickness = thickness, color = theme.colors.primary, trackColor = theme.colors.divider, trackOpacity = 1, showTrack = true, animationDuration = DEFAULT_ANIMATION_DURATION, isAnimated = true, lineCap = "round", trackLineCap = lineCap, dashWidth, trackDashWidth, dashGap, trackDashGap, dashOffset, trackDashOffset, customDashArray, trackCustomDashArray, onFullPathWidth, style, testID, }) => {
|
|
7
|
+
const [svgContainerWidth, setSvgContainerWidth] = React.useState(0);
|
|
8
|
+
const dashArray = dashWidth !== undefined
|
|
9
|
+
? `${dashWidth} ${dashGap || dashWidth}`
|
|
10
|
+
: undefined;
|
|
11
|
+
const trackDashArray = trackDashWidth !== undefined
|
|
12
|
+
? `${trackDashWidth} ${trackDashGap || trackDashWidth}`
|
|
13
|
+
: undefined;
|
|
14
|
+
const maxThickness = Math.max(thickness, trackThickness);
|
|
15
|
+
const thicknessOffset = maxThickness / 2; // This offset guarantees nothing is cut off by view bounds
|
|
16
|
+
const progressLineWidth = svgContainerWidth - thicknessOffset;
|
|
17
|
+
const trackProgressLineWidth = svgContainerWidth - thicknessOffset;
|
|
18
|
+
const currentFillPercentage = value / (maximumValue + minimumValue);
|
|
19
|
+
const currentProgressLineWidth = useSharedValue(currentFillPercentage * progressLineWidth);
|
|
20
|
+
const progressLineAnimatedProps = useAnimatedProps(() => {
|
|
21
|
+
const isBelowMinWidth = currentProgressLineWidth.value <= thicknessOffset;
|
|
22
|
+
return {
|
|
23
|
+
x2: Math.min(progressLineWidth, currentProgressLineWidth.value),
|
|
24
|
+
strokeOpacity: isBelowMinWidth ? 0.0 : 1.0,
|
|
25
|
+
};
|
|
26
|
+
});
|
|
27
|
+
React.useEffect(() => {
|
|
28
|
+
currentProgressLineWidth.value = withTiming(progressLineWidth * currentFillPercentage, {
|
|
29
|
+
duration: isAnimated ? animationDuration : 0,
|
|
30
|
+
});
|
|
31
|
+
}, [
|
|
32
|
+
value,
|
|
33
|
+
progressLineWidth,
|
|
34
|
+
currentFillPercentage,
|
|
35
|
+
animationDuration,
|
|
36
|
+
currentProgressLineWidth,
|
|
37
|
+
maximumValue,
|
|
38
|
+
minimumValue,
|
|
39
|
+
isAnimated,
|
|
40
|
+
]);
|
|
41
|
+
return (React.createElement(Svg, { testID: testID !== null && testID !== void 0 ? testID : "linear-progress-component", onLayout: (event) => {
|
|
42
|
+
const width = event.nativeEvent.layout.width;
|
|
43
|
+
setSvgContainerWidth(width);
|
|
44
|
+
onFullPathWidth === null || onFullPathWidth === void 0 ? void 0 : onFullPathWidth(width);
|
|
45
|
+
}, style: [
|
|
46
|
+
{
|
|
47
|
+
height: maxThickness,
|
|
48
|
+
},
|
|
49
|
+
style,
|
|
50
|
+
] },
|
|
51
|
+
showTrack && (React.createElement(Line, { x1: thicknessOffset, y1: thicknessOffset, x2: trackProgressLineWidth, y2: thicknessOffset, stroke: trackColor, strokeWidth: trackThickness, strokeOpacity: trackOpacity, strokeLinecap: trackLineCap, strokeDasharray: trackCustomDashArray || trackDashArray, strokeDashoffset: trackDashOffset })),
|
|
52
|
+
React.createElement(AnimatedLine, { animatedProps: progressLineAnimatedProps, x1: thicknessOffset, y1: thicknessOffset, y2: thicknessOffset, stroke: color, strokeWidth: thickness, strokeLinecap: lineCap, strokeDasharray: customDashArray || dashArray, strokeDashoffset: dashOffset })));
|
|
53
|
+
};
|
|
54
|
+
//# sourceMappingURL=LinearProgress.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"LinearProgress.js","sourceRoot":"","sources":["LinearProgress.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,GAAG,EAAE,EAAE,IAAI,EAAa,MAAM,kBAAkB,CAAC;AACxD,OAAO,QAAQ,EAAE,EACf,gBAAgB,EAChB,cAAc,EACd,UAAU,GACX,MAAM,yBAAyB,CAAC;AACjC,OAAO,EACL,0BAA0B,GAE3B,MAAM,mBAAmB,CAAC;AAE3B,MAAM,CAAC,MAAM,YAAY,GAAG,QAAQ,CAAC,uBAAuB,CAAC,IAAI,CAAC,CAAC;AAEnE,MAAM,CAAC,MAAM,cAAc,GAAiC,CAAC,EAC3D,KAAK,EACL,YAAY,GAAG,CAAC,EAChB,YAAY,GAAG,GAAG,EAClB,KAAK,GAAG,YAAY,EACpB,SAAS,GAAG,E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AE,YAAY,EAC3B,eAAe,EAAE,oBAAoB,IAAI,cAAc,EACvD,gBAAgB,EAAE,eAAe,GACjC,CACH;QACD,oBAAC,YAAY,IACX,aAAa,EAAE,yBAAyB,EACxC,EAAE,EAAE,eAAe,EACnB,EAAE,EAAE,eAAe,EACnB,EAAE,EAAE,eAAe,EACnB,MAAM,EAAE,KAAK,EACb,WAAW,EAAE,SAAS,EACtB,aAAa,EAAE,OAAO,EACtB,eAAe,EAAE,eAAe,IAAI,SAAS,EAC7C,gBAAgB,EAAE,UAAU,GAC5B,CACE,CACP,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import Svg, { Line, LineProps } from "react-native-svg";
|
|
3
|
+
import Animated, {
|
|
4
|
+
useAnimatedProps,
|
|
5
|
+
useSharedValue,
|
|
6
|
+
withTiming,
|
|
7
|
+
} from "react-native-reanimated";
|
|
8
|
+
import {
|
|
9
|
+
DEFAULT_ANIMATION_DURATION,
|
|
10
|
+
ValueProgressProps,
|
|
11
|
+
} from "../ProgressCommon";
|
|
12
|
+
|
|
13
|
+
export const AnimatedLine = Animated.createAnimatedComponent(Line);
|
|
14
|
+
|
|
15
|
+
export const LinearProgress: React.FC<ValueProgressProps> = ({
|
|
16
|
+
theme,
|
|
17
|
+
minimumValue = 0,
|
|
18
|
+
maximumValue = 100,
|
|
19
|
+
value = minimumValue,
|
|
20
|
+
thickness = 10,
|
|
21
|
+
trackThickness = thickness,
|
|
22
|
+
color = theme.colors.primary,
|
|
23
|
+
trackColor = theme.colors.divider,
|
|
24
|
+
trackOpacity = 1,
|
|
25
|
+
showTrack = true,
|
|
26
|
+
animationDuration = DEFAULT_ANIMATION_DURATION,
|
|
27
|
+
isAnimated = true,
|
|
28
|
+
lineCap = "round",
|
|
29
|
+
trackLineCap = lineCap,
|
|
30
|
+
dashWidth,
|
|
31
|
+
trackDashWidth,
|
|
32
|
+
dashGap,
|
|
33
|
+
trackDashGap,
|
|
34
|
+
dashOffset,
|
|
35
|
+
trackDashOffset,
|
|
36
|
+
customDashArray,
|
|
37
|
+
trackCustomDashArray,
|
|
38
|
+
onFullPathWidth,
|
|
39
|
+
style,
|
|
40
|
+
testID,
|
|
41
|
+
}) => {
|
|
42
|
+
const [svgContainerWidth, setSvgContainerWidth] = React.useState(0);
|
|
43
|
+
|
|
44
|
+
const dashArray =
|
|
45
|
+
dashWidth !== undefined
|
|
46
|
+
? `${dashWidth} ${dashGap || dashWidth}`
|
|
47
|
+
: undefined;
|
|
48
|
+
const trackDashArray =
|
|
49
|
+
trackDashWidth !== undefined
|
|
50
|
+
? `${trackDashWidth} ${trackDashGap || trackDashWidth}`
|
|
51
|
+
: undefined;
|
|
52
|
+
|
|
53
|
+
const maxThickness = Math.max(thickness, trackThickness);
|
|
54
|
+
const thicknessOffset = maxThickness / 2; // This offset guarantees nothing is cut off by view bounds
|
|
55
|
+
|
|
56
|
+
const progressLineWidth = svgContainerWidth - thicknessOffset;
|
|
57
|
+
const trackProgressLineWidth = svgContainerWidth - thicknessOffset;
|
|
58
|
+
|
|
59
|
+
const currentFillPercentage = value / (maximumValue + minimumValue);
|
|
60
|
+
const currentProgressLineWidth = useSharedValue(
|
|
61
|
+
currentFillPercentage * progressLineWidth
|
|
62
|
+
);
|
|
63
|
+
|
|
64
|
+
const progressLineAnimatedProps = useAnimatedProps<LineProps>(() => {
|
|
65
|
+
const isBelowMinWidth = currentProgressLineWidth.value <= thicknessOffset;
|
|
66
|
+
return {
|
|
67
|
+
x2: Math.min(progressLineWidth, currentProgressLineWidth.value), //Prevents going beyond the max width
|
|
68
|
+
strokeOpacity: isBelowMinWidth ? 0.0 : 1.0,
|
|
69
|
+
};
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
React.useEffect(() => {
|
|
73
|
+
currentProgressLineWidth.value = withTiming(
|
|
74
|
+
progressLineWidth * currentFillPercentage,
|
|
75
|
+
{
|
|
76
|
+
duration: isAnimated ? animationDuration : 0,
|
|
77
|
+
}
|
|
78
|
+
);
|
|
79
|
+
}, [
|
|
80
|
+
value,
|
|
81
|
+
progressLineWidth,
|
|
82
|
+
currentFillPercentage,
|
|
83
|
+
animationDuration,
|
|
84
|
+
currentProgressLineWidth,
|
|
85
|
+
maximumValue,
|
|
86
|
+
minimumValue,
|
|
87
|
+
isAnimated,
|
|
88
|
+
]);
|
|
89
|
+
|
|
90
|
+
return (
|
|
91
|
+
<Svg
|
|
92
|
+
testID={testID ?? "linear-progress-component"}
|
|
93
|
+
onLayout={(event) => {
|
|
94
|
+
const width = event.nativeEvent.layout.width;
|
|
95
|
+
setSvgContainerWidth(width);
|
|
96
|
+
onFullPathWidth?.(width);
|
|
97
|
+
}}
|
|
98
|
+
style={[
|
|
99
|
+
{
|
|
100
|
+
height: maxThickness,
|
|
101
|
+
},
|
|
102
|
+
style,
|
|
103
|
+
]}
|
|
104
|
+
>
|
|
105
|
+
{showTrack && (
|
|
106
|
+
<Line
|
|
107
|
+
x1={thicknessOffset}
|
|
108
|
+
y1={thicknessOffset}
|
|
109
|
+
x2={trackProgressLineWidth}
|
|
110
|
+
y2={thicknessOffset}
|
|
111
|
+
stroke={trackColor}
|
|
112
|
+
strokeWidth={trackThickness}
|
|
113
|
+
strokeOpacity={trackOpacity}
|
|
114
|
+
strokeLinecap={trackLineCap}
|
|
115
|
+
strokeDasharray={trackCustomDashArray || trackDashArray}
|
|
116
|
+
strokeDashoffset={trackDashOffset}
|
|
117
|
+
/>
|
|
118
|
+
)}
|
|
119
|
+
<AnimatedLine
|
|
120
|
+
animatedProps={progressLineAnimatedProps}
|
|
121
|
+
x1={thicknessOffset}
|
|
122
|
+
y1={thicknessOffset}
|
|
123
|
+
y2={thicknessOffset}
|
|
124
|
+
stroke={color}
|
|
125
|
+
strokeWidth={thickness}
|
|
126
|
+
strokeLinecap={lineCap}
|
|
127
|
+
strokeDasharray={customDashArray || dashArray}
|
|
128
|
+
strokeDashoffset={dashOffset}
|
|
129
|
+
/>
|
|
130
|
+
</Svg>
|
|
131
|
+
);
|
|
132
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import IndeterminateProgress from "../IndeterminateProgress";
|
|
3
|
+
import { LinearProgress as LinearProgressComponent } from "./LinearProgress";
|
|
4
|
+
import { withTheme } from "../../../theming";
|
|
5
|
+
const LinearProgress = (props) => {
|
|
6
|
+
if (props.indeterminate) {
|
|
7
|
+
return (React.createElement(IndeterminateProgress, { ProgressComponent: LinearProgressComponent, ...props }));
|
|
8
|
+
}
|
|
9
|
+
else {
|
|
10
|
+
return React.createElement(LinearProgressComponent, { ...props });
|
|
11
|
+
}
|
|
12
|
+
};
|
|
13
|
+
export default withTheme(LinearProgress);
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,qBAAqB,MAAM,0BAA0B,CAAC;AAK7D,OAAO,EAAE,cAAc,IAAI,uBAAuB,EAAE,MAAM,kBAAkB,CAAC;AAC7E,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,MAAM,cAAc,GAEhB,CAAC,KAAK,EAAE,EAAE;IACZ,IAAI,KAAK,CAAC,aAAa,EAAE;QACvB,OAAO,CACL,oBAAC,qBAAqB,IACpB,iBAAiB,EAAE,uBAAuB,KACtC,KAAK,GACT,CACH,CAAC;KACH;SAAM;QACL,OAAO,oBAAC,uBAAuB,OAAK,KAAK,GAAI,CAAC;KAC/C;AACH,CAAC,CAAC;AAEF,eAAe,SAAS,CAAC,cAAc,CAAC,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import IndeterminateProgress from "../IndeterminateProgress";
|
|
3
|
+
import {
|
|
4
|
+
IndeterminateProgressProps,
|
|
5
|
+
ValueProgressProps,
|
|
6
|
+
} from "../ProgressCommon";
|
|
7
|
+
import { LinearProgress as LinearProgressComponent } from "./LinearProgress";
|
|
8
|
+
import { withTheme } from "../../../theming";
|
|
9
|
+
|
|
10
|
+
const LinearProgress: React.FC<
|
|
11
|
+
ValueProgressProps & IndeterminateProgressProps
|
|
12
|
+
> = (props) => {
|
|
13
|
+
if (props.indeterminate) {
|
|
14
|
+
return (
|
|
15
|
+
<IndeterminateProgress
|
|
16
|
+
ProgressComponent={LinearProgressComponent}
|
|
17
|
+
{...props}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
} else {
|
|
21
|
+
return <LinearProgressComponent {...props} />;
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export default withTheme(LinearProgress);
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProgressCommon.js","sourceRoot":"","sources":["ProgressCommon.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,0BAA0B,GAAG,GAAG,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { StyleProp, ViewStyle } from "react-native";
|
|
2
|
+
import { Theme } from "../../styles/DefaultTheme";
|
|
3
|
+
|
|
4
|
+
type LineCap = "round" | "square";
|
|
5
|
+
|
|
6
|
+
export const DEFAULT_ANIMATION_DURATION = 500;
|
|
7
|
+
|
|
8
|
+
export interface BaseProgressProps {
|
|
9
|
+
thickness?: number;
|
|
10
|
+
trackThickness?: number;
|
|
11
|
+
color?: string;
|
|
12
|
+
trackColor?: string;
|
|
13
|
+
trackOpacity?: number;
|
|
14
|
+
showTrack?: boolean;
|
|
15
|
+
animationDuration?: number;
|
|
16
|
+
isAnimated?: boolean;
|
|
17
|
+
lineCap?: LineCap;
|
|
18
|
+
trackLineCap?: LineCap;
|
|
19
|
+
dashWidth?: string | number;
|
|
20
|
+
trackDashWidth?: string | number;
|
|
21
|
+
dashGap?: string | number;
|
|
22
|
+
trackDashGap?: string | number;
|
|
23
|
+
dashOffset?: string | number;
|
|
24
|
+
trackDashOffset?: string | number;
|
|
25
|
+
customDashArray?: string;
|
|
26
|
+
trackCustomDashArray?: string;
|
|
27
|
+
onFullPathWidth?: (width: number) => void;
|
|
28
|
+
style?: StyleProp<ViewStyle>;
|
|
29
|
+
theme: Theme;
|
|
30
|
+
testID?: string;
|
|
31
|
+
}
|
|
32
|
+
export interface ValueProgressProps extends BaseProgressProps {
|
|
33
|
+
value?: number;
|
|
34
|
+
minimumValue?: number;
|
|
35
|
+
maximumValue?: number;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export interface IndeterminateProgressProps extends BaseProgressProps {
|
|
39
|
+
indeterminate?: boolean;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export interface CircularProgressProps {
|
|
43
|
+
startPosition?: "left" | "top" | "right" | "bottom";
|
|
44
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, Text } from "react-native";
|
|
3
|
+
import { withTheme } from "../../theming";
|
|
4
|
+
const SectionHeader = ({ style, children, }) => React.createElement(View, { style: [style] }, children);
|
|
5
|
+
export const DefaultSectionHeader = withTheme(({ title, theme }) => {
|
|
6
|
+
return (React.createElement(Text, { testID: "default-section-header", style: {
|
|
7
|
+
color: theme.colors.background,
|
|
8
|
+
backgroundColor: theme.colors.primary,
|
|
9
|
+
fontSize: 16,
|
|
10
|
+
padding: 10,
|
|
11
|
+
} }, title));
|
|
12
|
+
});
|
|
13
|
+
export default SectionHeader;
|
|
14
|
+
//# sourceMappingURL=SectionHeader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SectionHeader.js","sourceRoot":"","sources":["SectionHeader.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAwB,IAAI,EAAE,MAAM,cAAc,CAAC;AAChE,OAAO,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAO1C,MAAM,aAAa,GAA0D,CAAC,EAC5E,KAAK,EACL,QAAQ,GACT,EAAE,EAAE,CAAC,oBAAC,IAAI,IAAC,KAAK,EAAE,CAAC,KAAK,CAAC,IAAG,QAAQ,CAAQ,CAAC;AAM9C,MAAM,CAAC,MAAM,oBAAoB,GAAG,SAAS,CAC3C,CAAC,EAAE,KAAK,EAAE,KAAK,EAA6B,EAAE,EAAE;IAC9C,OAAO,CACL,oBAAC,IAAI,IACH,MAAM,EAAC,wBAAwB,EAC/B,KAAK,EAAE;YACL,KAAK,EAAE,KAAK,CAAC,MAAM,CAAC,UAAU;YAC9B,eAAe,EAAE,KAAK,CAAC,MAAM,CAAC,OAAO;YACrC,QAAQ,EAAE,EAAE;YACZ,OAAO,EAAE,EAAE;SACZ,IAEA,KAAK,CACD,CACR,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,aAAa,CAAC"}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { View, StyleProp, ViewStyle, Text } from "react-native";
|
|
3
|
+
import { withTheme } from "../../theming";
|
|
4
|
+
import type { Theme } from "../../styles/DefaultTheme";
|
|
5
|
+
|
|
6
|
+
interface SectionHeaderProps {
|
|
7
|
+
style?: StyleProp<ViewStyle>;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
const SectionHeader: React.FC<React.PropsWithChildren<SectionHeaderProps>> = ({
|
|
11
|
+
style,
|
|
12
|
+
children,
|
|
13
|
+
}) => <View style={[style]}>{children}</View>;
|
|
14
|
+
|
|
15
|
+
interface DefaultSectionHeaderProps {
|
|
16
|
+
title: string;
|
|
17
|
+
theme: Theme;
|
|
18
|
+
}
|
|
19
|
+
export const DefaultSectionHeader = withTheme(
|
|
20
|
+
({ title, theme }: DefaultSectionHeaderProps) => {
|
|
21
|
+
return (
|
|
22
|
+
<Text
|
|
23
|
+
testID="default-section-header"
|
|
24
|
+
style={{
|
|
25
|
+
color: theme.colors.background,
|
|
26
|
+
backgroundColor: theme.colors.primary,
|
|
27
|
+
fontSize: 16,
|
|
28
|
+
padding: 10,
|
|
29
|
+
}}
|
|
30
|
+
>
|
|
31
|
+
{title}
|
|
32
|
+
</Text>
|
|
33
|
+
);
|
|
34
|
+
}
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
export default SectionHeader;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FlashList } from "@shopify/flash-list";
|
|
3
|
+
import { FlatList } from "react-native";
|
|
4
|
+
import SectionHeader, { DefaultSectionHeader } from "./SectionHeader";
|
|
5
|
+
export const DEFAULT_SECTION = "Uncategorized";
|
|
6
|
+
const SectionList = ({ sectionKey, listComponent = "FlatList", data: dataProp, renderItem: renderItemProp, ...rest }) => {
|
|
7
|
+
const data = React.useMemo(() => (dataProp || []), [dataProp]);
|
|
8
|
+
const dataWithSections = React.useMemo(() => {
|
|
9
|
+
var _a;
|
|
10
|
+
const result = [];
|
|
11
|
+
const sectionDataItems = {};
|
|
12
|
+
for (const item of data) {
|
|
13
|
+
const section = ((_a = item[sectionKey]) === null || _a === void 0 ? void 0 : _a.toString()) || DEFAULT_SECTION;
|
|
14
|
+
if (sectionDataItems[section]) {
|
|
15
|
+
sectionDataItems[section].push(item);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
sectionDataItems[section] = [item];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
for (const section in sectionDataItems) {
|
|
22
|
+
result.push({ type: "SECTION_ITEM", title: section });
|
|
23
|
+
const sectionItems = sectionDataItems[section].map((item) => ({ type: "DATA_ITEM", data: item }));
|
|
24
|
+
result.push(...sectionItems);
|
|
25
|
+
}
|
|
26
|
+
return result;
|
|
27
|
+
}, [data, sectionKey]);
|
|
28
|
+
const extractSectionHeader = (element) => {
|
|
29
|
+
if (!element) {
|
|
30
|
+
return null;
|
|
31
|
+
}
|
|
32
|
+
const props = element.props || {};
|
|
33
|
+
const children = React.Children.toArray(props.children).map((child) => child);
|
|
34
|
+
if (element.type === SectionHeader) {
|
|
35
|
+
return element;
|
|
36
|
+
}
|
|
37
|
+
else {
|
|
38
|
+
for (const child of children) {
|
|
39
|
+
if (child.type === SectionHeader) {
|
|
40
|
+
return child;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
return null;
|
|
45
|
+
};
|
|
46
|
+
const extractRemainingNonSectionHeader = (element) => {
|
|
47
|
+
if (!element) {
|
|
48
|
+
return null;
|
|
49
|
+
}
|
|
50
|
+
const props = element.props || {};
|
|
51
|
+
const children = React.Children.toArray(props.children).map((child) => child);
|
|
52
|
+
if (element.type === SectionHeader) {
|
|
53
|
+
return null;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
const newChildren = [];
|
|
57
|
+
for (const child of children) {
|
|
58
|
+
if (child.type !== SectionHeader) {
|
|
59
|
+
newChildren.push(child);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return React.cloneElement(element, {
|
|
63
|
+
...props,
|
|
64
|
+
children: newChildren,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
const renderItem = ({ item, index, }) => {
|
|
69
|
+
switch (item.type) {
|
|
70
|
+
case "SECTION_ITEM": {
|
|
71
|
+
const renderedItem = renderItemProp({
|
|
72
|
+
index,
|
|
73
|
+
section: item.title,
|
|
74
|
+
});
|
|
75
|
+
return (extractSectionHeader(renderedItem) || (React.createElement(DefaultSectionHeader, { title: item.title })));
|
|
76
|
+
}
|
|
77
|
+
case "DATA_ITEM": {
|
|
78
|
+
const renderedItem = renderItemProp({
|
|
79
|
+
item: item.data,
|
|
80
|
+
index,
|
|
81
|
+
section: item.data[sectionKey] || DEFAULT_SECTION,
|
|
82
|
+
});
|
|
83
|
+
return extractRemainingNonSectionHeader(renderedItem);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
};
|
|
87
|
+
switch (listComponent) {
|
|
88
|
+
case "FlatList":
|
|
89
|
+
return (React.createElement(FlatList, { ...rest, data: dataWithSections, renderItem: renderItem }));
|
|
90
|
+
case "FlashList":
|
|
91
|
+
return (React.createElement(FlashList, { ...rest, data: dataWithSections, renderItem: renderItem }));
|
|
92
|
+
}
|
|
93
|
+
};
|
|
94
|
+
export default SectionList;
|
|
95
|
+
//# sourceMappingURL=SectionList.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SectionList.js","sourceRoot":"","sources":["SectionList.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAkB,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAiB,QAAQ,EAAE,MAAM,cAAc,CAAC;AACvD,OAAO,aAAa,EAAE,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAgCtE,MAAM,CAAC,MAAM,eAAe,GAAG,eAAe,CAAC;AAE/C,MAAM,WAAW,GAAG,CAAmC,EACrD,UAAU,EACV,aAAa,GAAG,UAAU,EAC1B,IAAI,EAAE,QAAQ,EACd,UAAU,EAAE,cAAc,EAC1B,GAAG,IAAI,EACoD,EAAE,EAAE;IAC/D,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC,QAAQ,IAAI,EAAE,CAAQ,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEtE,MAAM,gBAAgB,GAAG,KAAK,CAAC,OAAO,CAAC,GAAG,EAAE;;QAC1C,MAAM,MAAM,GAAyB,EAAE,CAAC;QACxC,MAAM,gBAAgB,GAA2B,EAAE,CAAC;QAEpD,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;YACvB,MAAM,OAAO,GAAG,CAAA,MAAA,IAAI,CAAC,UAAU,CAAC,0CAAE,QAAQ,EAAE,KAAI,eAAe,CAAC;YAChE,IAAI,gBAAgB,CAAC,OAAO,CAAC,EAAE;gBA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UAAU,CAAC,IAAI,eAAe;iBAClD,CAAC,CAAC;gBACH,OAAO,gCAAgC,CAAC,YAAY,CAAC,CAAC;aACvD;SACF;IACH,CAAC,CAAC;IAEF,QAAQ,aAAa,EAAE;QACrB,KAAK,UAAU;YACb,OAAO,CACL,oBAAC,QAAQ,OACF,IAA0C,EAC/C,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,UAAU,GACtB,CACH,CAAC;QACJ,KAAK,WAAW;YACd,OAAO,CACL,oBAAC,SAAS,OACH,IAA2C,EAChD,IAAI,EAAE,gBAAgB,EACtB,UAAU,EAAE,UAAU,GACtB,CACH,CAAC;KACL;AACH,CAAC,CAAC;AAEF,eAAe,WAAW,CAAC"}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { FlashListProps, FlashList } from "@shopify/flash-list";
|
|
3
|
+
import { FlatListProps, FlatList } from "react-native";
|
|
4
|
+
import SectionHeader, { DefaultSectionHeader } from "./SectionHeader";
|
|
5
|
+
|
|
6
|
+
type ListComponentType = "FlatList" | "FlashList";
|
|
7
|
+
|
|
8
|
+
interface AdditionalSectionListProps<T> {
|
|
9
|
+
sectionKey: string;
|
|
10
|
+
renderItem: (itemInfo: {
|
|
11
|
+
item?: T;
|
|
12
|
+
index: number;
|
|
13
|
+
section: string;
|
|
14
|
+
}) => JSX.Element;
|
|
15
|
+
listComponent?: ListComponentType;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
type FlatListSectionListProps<T> = Omit<FlatListProps<T>, "renderItem"> &
|
|
19
|
+
AdditionalSectionListProps<T>;
|
|
20
|
+
|
|
21
|
+
type FlashListSectionListProps<T> = Omit<FlashListProps<T>, "renderItem"> &
|
|
22
|
+
AdditionalSectionListProps<T>;
|
|
23
|
+
|
|
24
|
+
interface SectionListDataItem<T> {
|
|
25
|
+
type: "DATA_ITEM";
|
|
26
|
+
data: T;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
interface SectionListSectionItem {
|
|
30
|
+
type: "SECTION_ITEM";
|
|
31
|
+
title: string;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
type SectionListItem<T> = SectionListDataItem<T> | SectionListSectionItem;
|
|
35
|
+
|
|
36
|
+
export const DEFAULT_SECTION = "Uncategorized";
|
|
37
|
+
|
|
38
|
+
const SectionList = <T extends { [key: string]: any }>({
|
|
39
|
+
sectionKey,
|
|
40
|
+
listComponent = "FlatList",
|
|
41
|
+
data: dataProp,
|
|
42
|
+
renderItem: renderItemProp,
|
|
43
|
+
...rest
|
|
44
|
+
}: FlatListSectionListProps<T> | FlashListSectionListProps<T>) => {
|
|
45
|
+
const data = React.useMemo(() => (dataProp || []) as T[], [dataProp]);
|
|
46
|
+
|
|
47
|
+
const dataWithSections = React.useMemo(() => {
|
|
48
|
+
const result: SectionListItem<T>[] = [];
|
|
49
|
+
const sectionDataItems: { [key: string]: T[] } = {};
|
|
50
|
+
|
|
51
|
+
for (const item of data) {
|
|
52
|
+
const section = item[sectionKey]?.toString() || DEFAULT_SECTION;
|
|
53
|
+
if (sectionDataItems[section]) {
|
|
54
|
+
sectionDataItems[section].push(item);
|
|
55
|
+
} else {
|
|
56
|
+
sectionDataItems[section] = [item];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
for (const section in sectionDataItems) {
|
|
61
|
+
result.push({ type: "SECTION_ITEM", title: section });
|
|
62
|
+
const sectionItems: SectionListDataItem<T>[] = sectionDataItems[
|
|
63
|
+
section
|
|
64
|
+
].map((item) => ({ type: "DATA_ITEM", data: item }));
|
|
65
|
+
result.push(...sectionItems);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return result;
|
|
69
|
+
}, [data, sectionKey]);
|
|
70
|
+
|
|
71
|
+
const extractSectionHeader = (
|
|
72
|
+
element: JSX.Element | null
|
|
73
|
+
): JSX.Element | null => {
|
|
74
|
+
if (!element) {
|
|
75
|
+
return null;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const props = element.props || {};
|
|
79
|
+
const children = React.Children.toArray(props.children).map(
|
|
80
|
+
(child) => child as React.ReactElement
|
|
81
|
+
);
|
|
82
|
+
if (element.type === SectionHeader) {
|
|
83
|
+
return element;
|
|
84
|
+
} else {
|
|
85
|
+
for (const child of children) {
|
|
86
|
+
if (child.type === SectionHeader) {
|
|
87
|
+
return child;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return null;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const extractRemainingNonSectionHeader = (
|
|
95
|
+
element: JSX.Element | null
|
|
96
|
+
): JSX.Element | null => {
|
|
97
|
+
if (!element) {
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
const props = element.props || {};
|
|
102
|
+
const children = React.Children.toArray(props.children).map(
|
|
103
|
+
(child) => child as React.ReactElement
|
|
104
|
+
);
|
|
105
|
+
if (element.type === SectionHeader) {
|
|
106
|
+
return null;
|
|
107
|
+
} else {
|
|
108
|
+
const newChildren = [];
|
|
109
|
+
for (const child of children) {
|
|
110
|
+
if (child.type !== SectionHeader) {
|
|
111
|
+
newChildren.push(child);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return React.cloneElement(element, {
|
|
115
|
+
...props,
|
|
116
|
+
children: newChildren,
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
const renderItem = ({
|
|
122
|
+
item,
|
|
123
|
+
index,
|
|
124
|
+
}: {
|
|
125
|
+
item: SectionListItem<T>;
|
|
126
|
+
index: number;
|
|
127
|
+
}) => {
|
|
128
|
+
switch (item.type) {
|
|
129
|
+
case "SECTION_ITEM": {
|
|
130
|
+
const renderedItem = renderItemProp({
|
|
131
|
+
index,
|
|
132
|
+
section: item.title,
|
|
133
|
+
});
|
|
134
|
+
return (
|
|
135
|
+
extractSectionHeader(renderedItem) || (
|
|
136
|
+
<DefaultSectionHeader title={item.title} />
|
|
137
|
+
)
|
|
138
|
+
);
|
|
139
|
+
}
|
|
140
|
+
case "DATA_ITEM": {
|
|
141
|
+
const renderedItem = renderItemProp({
|
|
142
|
+
item: item.data,
|
|
143
|
+
index,
|
|
144
|
+
section: item.data[sectionKey] || DEFAULT_SECTION,
|
|
145
|
+
});
|
|
146
|
+
return extractRemainingNonSectionHeader(renderedItem);
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
switch (listComponent) {
|
|
152
|
+
case "FlatList":
|
|
153
|
+
return (
|
|
154
|
+
<FlatList
|
|
155
|
+
{...(rest as FlatListProps<SectionListItem<T>>)}
|
|
156
|
+
data={dataWithSections}
|
|
157
|
+
renderItem={renderItem}
|
|
158
|
+
/>
|
|
159
|
+
);
|
|
160
|
+
case "FlashList":
|
|
161
|
+
return (
|
|
162
|
+
<FlashList
|
|
163
|
+
{...(rest as FlashListProps<SectionListItem<T>>)}
|
|
164
|
+
data={dataWithSections}
|
|
165
|
+
renderItem={renderItem}
|
|
166
|
+
/>
|
|
167
|
+
);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
export default SectionList;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,eAAe,CAAC;AACvD,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,iBAAiB,CAAC"}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { View, StyleSheet } from "react-native";
|
|
3
3
|
import { generateBorderStyles, TableStyleContext, } from "./TableCommon";
|
|
4
|
-
|
|
4
|
+
import Pressable from "../Pressable";
|
|
5
|
+
const TableCell = ({ borderWidth, borderColor, borderStyle, drawTopBorder = false, drawBottomBorder = false, drawStartBorder = false, drawEndBorder = true, cellVerticalPadding, cellHorizontalPadding, children, onPress, style, }) => {
|
|
5
6
|
const parentContextValue = React.useContext(TableStyleContext);
|
|
6
7
|
const borderViewStyle = generateBorderStyles({
|
|
7
8
|
borderColor: borderColor || parentContextValue.borderColor,
|
|
@@ -12,7 +13,8 @@ const TableCell = ({ borderWidth, borderColor, borderStyle, drawTopBorder = fals
|
|
|
12
13
|
drawStartBorder,
|
|
13
14
|
drawEndBorder,
|
|
14
15
|
});
|
|
15
|
-
|
|
16
|
+
const ContainerComponent = onPress ? Pressable : View;
|
|
17
|
+
return (React.createElement(ContainerComponent, { onPress: onPress, style: [
|
|
16
18
|
styles.cellContainer,
|
|
17
19
|
borderViewStyle,
|
|
18
20
|
{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"TableCell.js","sourceRoot":"","sources":["TableCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAwB,UAAU,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EACL,oBAAoB,EAEpB,iBAAiB,GAClB,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"TableCell.js","sourceRoot":"","sources":["TableCell.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAwB,UAAU,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,EACL,oBAAoB,EAEpB,iBAAiB,GAClB,MAAM,eAAe,CAAC;AACvB,OAAO,SAAS,MAAM,cAAc,CAAC;AAOrC,MAAM,SAAS,GAA6C,CAAC,EAC3D,WAAW,EACX,WAAW,EACX,WAAW,EACX,aAAa,GAAG,KAAK,EACrB,gBAAgB,GAAG,KAAK,EACxB,eAAe,GAAG,KAAK,EACvB,aAAa,GAAG,IAAI,EACpB,mBAAmB,EACnB,qBAAqB,EACrB,QAAQ,EACR,OAAO,EACP,KAAK,GACN,EAAE,EAAE;IACH,MAAM,kBAAkB,G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