@draftbit/core 46.8.1-b0418d.2 → 46.8.1-d78af9.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/commonjs/components/DeckSwiper/DeckSwiper.js +38 -4
- package/lib/commonjs/components/Picker/Picker.js +9 -8
- package/lib/module/components/DeckSwiper/DeckSwiper.js +38 -4
- package/lib/module/components/Picker/Picker.js +9 -8
- package/lib/typescript/src/components/DeckSwiper/DeckSwiper.d.ts +8 -2
- package/lib/typescript/src/components/DeckSwiper/DeckSwiper.d.ts.map +1 -1
- package/lib/typescript/src/components/DeckSwiper/DeckSwiperCard.d.ts +2 -3
- package/lib/typescript/src/components/DeckSwiper/DeckSwiperCard.d.ts.map +1 -1
- package/lib/typescript/src/components/Picker/Picker.d.ts.map +1 -1
- package/package.json +3 -3
- package/src/components/DeckSwiper/DeckSwiper.js +33 -3
- package/src/components/DeckSwiper/DeckSwiper.tsx +51 -9
- package/src/components/DeckSwiper/DeckSwiperCard.js +1 -1
- package/src/components/DeckSwiper/DeckSwiperCard.tsx +3 -6
- package/src/components/Picker/Picker.js +8 -7
- package/src/components/Picker/Picker.tsx +9 -7
|
@@ -17,13 +17,47 @@ const DeckSwiper = _ref => {
|
|
|
17
17
|
verticalEnabled = true,
|
|
18
18
|
horizontalEnabled = true,
|
|
19
19
|
visibleCardCount = 1,
|
|
20
|
+
data,
|
|
21
|
+
keyExtractor,
|
|
22
|
+
renderItem,
|
|
20
23
|
style,
|
|
21
24
|
children
|
|
22
25
|
} = _ref;
|
|
26
|
+
//Both 'renderItem' and 'data' are optional to allow direct children. But if one is included, both need to be included
|
|
27
|
+
if (data && !renderItem || renderItem && !data) {
|
|
28
|
+
throw new Error("'renderItem' and 'data' need to both be provided to lazily render. Either remove them entirley or include both");
|
|
29
|
+
}
|
|
30
|
+
if (data && renderItem && children) {
|
|
31
|
+
console.warn("'children' of DeckSwiper ignored due to usage of 'data' and 'renderItem'");
|
|
32
|
+
}
|
|
23
33
|
const childrenArray = _react.default.useMemo(() => _react.default.Children.toArray(children), [children]);
|
|
24
34
|
|
|
25
35
|
// an array of indices based on children count
|
|
26
36
|
const cardsFillerData = _react.default.useMemo(() => Array.from(Array(childrenArray.length).keys()), [childrenArray]);
|
|
37
|
+
const cardsData = data || cardsFillerData;
|
|
38
|
+
const renderCard = (card, index) => {
|
|
39
|
+
if (renderItem) {
|
|
40
|
+
return renderItem({
|
|
41
|
+
item: card,
|
|
42
|
+
index
|
|
43
|
+
});
|
|
44
|
+
} else {
|
|
45
|
+
return /*#__PURE__*/_react.default.createElement(_react.default.Fragment, null, childrenArray[index]);
|
|
46
|
+
}
|
|
47
|
+
};
|
|
48
|
+
const renderFirstCard = () => {
|
|
49
|
+
if (cardsData.length) {
|
|
50
|
+
return renderCard(cardsData[0], 0);
|
|
51
|
+
}
|
|
52
|
+
return undefined;
|
|
53
|
+
};
|
|
54
|
+
const cardKeyExtractor = card => {
|
|
55
|
+
if (keyExtractor) {
|
|
56
|
+
return keyExtractor(card);
|
|
57
|
+
} else {
|
|
58
|
+
return card.toString();
|
|
59
|
+
}
|
|
60
|
+
};
|
|
27
61
|
|
|
28
62
|
/**
|
|
29
63
|
* By default react-native-deck-swiper positions everything with absolute position.
|
|
@@ -37,10 +71,10 @@ const DeckSwiper = _ref => {
|
|
|
37
71
|
|
|
38
72
|
return /*#__PURE__*/_react.default.createElement(_reactNative.View, null, /*#__PURE__*/_react.default.createElement(_reactNative.View, {
|
|
39
73
|
style: styles.containerHeightFiller
|
|
40
|
-
},
|
|
41
|
-
cards:
|
|
42
|
-
renderCard:
|
|
43
|
-
keyExtractor:
|
|
74
|
+
}, renderFirstCard()), /*#__PURE__*/_react.default.createElement(_reactNativeDeckSwiper.default, {
|
|
75
|
+
cards: cardsData,
|
|
76
|
+
renderCard: renderCard,
|
|
77
|
+
keyExtractor: cardKeyExtractor,
|
|
44
78
|
containerStyle: _reactNative.StyleSheet.flatten([styles.cardsContainer, style]),
|
|
45
79
|
cardStyle: styles.card,
|
|
46
80
|
onSwiped: onIndexChanged,
|
|
@@ -46,9 +46,6 @@ const isWeb = _reactNative.Platform.OS === "web";
|
|
|
46
46
|
const unstyledColor = "rgba(165, 173, 183, 1)";
|
|
47
47
|
const disabledColor = "rgb(240, 240, 240)";
|
|
48
48
|
const errorColor = "rgba(255, 69, 100, 1)";
|
|
49
|
-
|
|
50
|
-
//Empty string for 'value' is treated as a non-value
|
|
51
|
-
//reason: Draftbit uses empty string as initial value for string state*/
|
|
52
49
|
const Picker = _ref => {
|
|
53
50
|
var _find$label, _find;
|
|
54
51
|
let {
|
|
@@ -79,12 +76,12 @@ const Picker = _ref => {
|
|
|
79
76
|
setPickerVisible(!pickerVisible);
|
|
80
77
|
};
|
|
81
78
|
React.useEffect(() => {
|
|
82
|
-
if (value != null
|
|
79
|
+
if (value != null) {
|
|
83
80
|
setInternalValue(value);
|
|
84
81
|
}
|
|
85
82
|
}, [value]);
|
|
86
83
|
React.useEffect(() => {
|
|
87
|
-
if (defaultValue != null
|
|
84
|
+
if (defaultValue != null) {
|
|
88
85
|
setInternalValue(defaultValue);
|
|
89
86
|
}
|
|
90
87
|
}, [defaultValue]);
|
|
@@ -99,7 +96,11 @@ const Picker = _ref => {
|
|
|
99
96
|
_reactNative.Keyboard.dismiss();
|
|
100
97
|
}
|
|
101
98
|
}, [pickerVisible, autoDismissKeyboard]);
|
|
102
|
-
const
|
|
99
|
+
const normalizedOptions = normalizeOptions(options);
|
|
100
|
+
const pickerOptions = placeholder ? [{
|
|
101
|
+
value: placeholder,
|
|
102
|
+
label: placeholder
|
|
103
|
+
}, ...normalizedOptions] : normalizedOptions;
|
|
103
104
|
const {
|
|
104
105
|
viewStyles,
|
|
105
106
|
textStyles
|
|
@@ -199,10 +200,10 @@ const Picker = _ref => {
|
|
|
199
200
|
} : {})
|
|
200
201
|
};
|
|
201
202
|
const handleValueChange = (newValue, itemIndex) => {
|
|
202
|
-
if (
|
|
203
|
+
if (!placeholder || itemIndex > 0) {
|
|
203
204
|
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newValue, itemIndex);
|
|
204
|
-
setInternalValue(newValue);
|
|
205
205
|
}
|
|
206
|
+
setInternalValue(newValue);
|
|
206
207
|
};
|
|
207
208
|
return (
|
|
208
209
|
/*#__PURE__*/
|
|
@@ -10,13 +10,47 @@ const DeckSwiper = _ref => {
|
|
|
10
10
|
verticalEnabled = true,
|
|
11
11
|
horizontalEnabled = true,
|
|
12
12
|
visibleCardCount = 1,
|
|
13
|
+
data,
|
|
14
|
+
keyExtractor,
|
|
15
|
+
renderItem,
|
|
13
16
|
style,
|
|
14
17
|
children
|
|
15
18
|
} = _ref;
|
|
19
|
+
//Both 'renderItem' and 'data' are optional to allow direct children. But if one is included, both need to be included
|
|
20
|
+
if (data && !renderItem || renderItem && !data) {
|
|
21
|
+
throw new Error("'renderItem' and 'data' need to both be provided to lazily render. Either remove them entirley or include both");
|
|
22
|
+
}
|
|
23
|
+
if (data && renderItem && children) {
|
|
24
|
+
console.warn("'children' of DeckSwiper ignored due to usage of 'data' and 'renderItem'");
|
|
25
|
+
}
|
|
16
26
|
const childrenArray = React.useMemo(() => React.Children.toArray(children), [children]);
|
|
17
27
|
|
|
18
28
|
// an array of indices based on children count
|
|
19
29
|
const cardsFillerData = React.useMemo(() => Array.from(Array(childrenArray.length).keys()), [childrenArray]);
|
|
30
|
+
const cardsData = data || cardsFillerData;
|
|
31
|
+
const renderCard = (card, index) => {
|
|
32
|
+
if (renderItem) {
|
|
33
|
+
return renderItem({
|
|
34
|
+
item: card,
|
|
35
|
+
index
|
|
36
|
+
});
|
|
37
|
+
} else {
|
|
38
|
+
return /*#__PURE__*/React.createElement(React.Fragment, null, childrenArray[index]);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
const renderFirstCard = () => {
|
|
42
|
+
if (cardsData.length) {
|
|
43
|
+
return renderCard(cardsData[0], 0);
|
|
44
|
+
}
|
|
45
|
+
return undefined;
|
|
46
|
+
};
|
|
47
|
+
const cardKeyExtractor = card => {
|
|
48
|
+
if (keyExtractor) {
|
|
49
|
+
return keyExtractor(card);
|
|
50
|
+
} else {
|
|
51
|
+
return card.toString();
|
|
52
|
+
}
|
|
53
|
+
};
|
|
20
54
|
|
|
21
55
|
/**
|
|
22
56
|
* By default react-native-deck-swiper positions everything with absolute position.
|
|
@@ -30,10 +64,10 @@ const DeckSwiper = _ref => {
|
|
|
30
64
|
|
|
31
65
|
return /*#__PURE__*/React.createElement(View, null, /*#__PURE__*/React.createElement(View, {
|
|
32
66
|
style: styles.containerHeightFiller
|
|
33
|
-
},
|
|
34
|
-
cards:
|
|
35
|
-
renderCard:
|
|
36
|
-
keyExtractor:
|
|
67
|
+
}, renderFirstCard()), /*#__PURE__*/React.createElement(DeckSwiperComponent, {
|
|
68
|
+
cards: cardsData,
|
|
69
|
+
renderCard: renderCard,
|
|
70
|
+
keyExtractor: cardKeyExtractor,
|
|
37
71
|
containerStyle: StyleSheet.flatten([styles.cardsContainer, style]),
|
|
38
72
|
cardStyle: styles.card,
|
|
39
73
|
onSwiped: onIndexChanged,
|
|
@@ -37,9 +37,6 @@ const isWeb = Platform.OS === "web";
|
|
|
37
37
|
const unstyledColor = "rgba(165, 173, 183, 1)";
|
|
38
38
|
const disabledColor = "rgb(240, 240, 240)";
|
|
39
39
|
const errorColor = "rgba(255, 69, 100, 1)";
|
|
40
|
-
|
|
41
|
-
//Empty string for 'value' is treated as a non-value
|
|
42
|
-
//reason: Draftbit uses empty string as initial value for string state*/
|
|
43
40
|
const Picker = _ref => {
|
|
44
41
|
var _find$label, _find;
|
|
45
42
|
let {
|
|
@@ -70,12 +67,12 @@ const Picker = _ref => {
|
|
|
70
67
|
setPickerVisible(!pickerVisible);
|
|
71
68
|
};
|
|
72
69
|
React.useEffect(() => {
|
|
73
|
-
if (value != null
|
|
70
|
+
if (value != null) {
|
|
74
71
|
setInternalValue(value);
|
|
75
72
|
}
|
|
76
73
|
}, [value]);
|
|
77
74
|
React.useEffect(() => {
|
|
78
|
-
if (defaultValue != null
|
|
75
|
+
if (defaultValue != null) {
|
|
79
76
|
setInternalValue(defaultValue);
|
|
80
77
|
}
|
|
81
78
|
}, [defaultValue]);
|
|
@@ -90,7 +87,11 @@ const Picker = _ref => {
|
|
|
90
87
|
Keyboard.dismiss();
|
|
91
88
|
}
|
|
92
89
|
}, [pickerVisible, autoDismissKeyboard]);
|
|
93
|
-
const
|
|
90
|
+
const normalizedOptions = normalizeOptions(options);
|
|
91
|
+
const pickerOptions = placeholder ? [{
|
|
92
|
+
value: placeholder,
|
|
93
|
+
label: placeholder
|
|
94
|
+
}, ...normalizedOptions] : normalizedOptions;
|
|
94
95
|
const {
|
|
95
96
|
viewStyles,
|
|
96
97
|
textStyles
|
|
@@ -190,10 +191,10 @@ const Picker = _ref => {
|
|
|
190
191
|
} : {})
|
|
191
192
|
};
|
|
192
193
|
const handleValueChange = (newValue, itemIndex) => {
|
|
193
|
-
if (
|
|
194
|
+
if (!placeholder || itemIndex > 0) {
|
|
194
195
|
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newValue, itemIndex);
|
|
195
|
-
setInternalValue(newValue);
|
|
196
196
|
}
|
|
197
|
+
setInternalValue(newValue);
|
|
197
198
|
};
|
|
198
199
|
return (
|
|
199
200
|
/*#__PURE__*/
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { StyleProp, ViewStyle } from "react-native";
|
|
3
|
-
export interface DeckSwiperProps {
|
|
3
|
+
export interface DeckSwiperProps<T> {
|
|
4
4
|
onIndexChanged?: (index: number) => void;
|
|
5
5
|
onEndReached?: () => void;
|
|
6
6
|
startCardIndex?: number;
|
|
@@ -8,8 +8,14 @@ export interface DeckSwiperProps {
|
|
|
8
8
|
verticalEnabled?: boolean;
|
|
9
9
|
horizontalEnabled?: boolean;
|
|
10
10
|
visibleCardCount?: number;
|
|
11
|
+
data?: Array<T>;
|
|
12
|
+
keyExtractor?: (item: T) => string;
|
|
13
|
+
renderItem?: ({ item, index }: {
|
|
14
|
+
item: T;
|
|
15
|
+
index: number;
|
|
16
|
+
}) => JSX.Element;
|
|
11
17
|
style?: StyleProp<ViewStyle>;
|
|
12
18
|
}
|
|
13
|
-
declare const DeckSwiper:
|
|
19
|
+
declare const DeckSwiper: <T extends object>({ onIndexChanged, onEndReached, startCardIndex, infiniteSwiping, verticalEnabled, horizontalEnabled, visibleCardCount, data, keyExtractor, renderItem, style, children, }: React.PropsWithChildren<DeckSwiperProps<T>>) => JSX.Element;
|
|
14
20
|
export default DeckSwiper;
|
|
15
21
|
//# sourceMappingURL=DeckSwiper.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeckSwiper.d.ts","sourceRoot":"","sources":["../../../../../src/components/DeckSwiper/DeckSwiper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAoB,MAAM,cAAc,CAAC;AAGtE,MAAM,WAAW,eAAe;
|
|
1
|
+
{"version":3,"file":"DeckSwiper.d.ts","sourceRoot":"","sources":["../../../../../src/components/DeckSwiper/DeckSwiper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,SAAS,EAAE,SAAS,EAAoB,MAAM,cAAc,CAAC;AAGtE,MAAM,WAAW,eAAe,CAAC,CAAC;IAChC,cAAc,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACzC,YAAY,CAAC,EAAE,MAAM,IAAI,CAAC;IAC1B,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,gBAAgB,CAAC,EAAE,MAAM,CAAC;IAC1B,IAAI,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC,CAAC;IAChB,YAAY,CAAC,EAAE,CAAC,IAAI,EAAE,CAAC,KAAK,MAAM,CAAC;IACnC,UAAU,CAAC,EAAE,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;QAAE,IAAI,EAAE,CAAC,CAAC;QAAC,KAAK,EAAE,MAAM,CAAA;KAAE,KAAK,GAAG,CAAC,OAAO,CAAC;IAC1E,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;CAC9B;AAED,QAAA,MAAM,UAAU,2PAoGf,CAAC;AAiBF,eAAe,UAAU,CAAC"}
|
|
@@ -3,11 +3,10 @@ import { StyleProp, ViewStyle } from "react-native";
|
|
|
3
3
|
import type { Theme } from "../../styles/DefaultTheme";
|
|
4
4
|
export interface DeckSwiperCardProps {
|
|
5
5
|
style?: StyleProp<ViewStyle>;
|
|
6
|
-
children: React.ReactNode;
|
|
7
6
|
theme: Theme;
|
|
8
7
|
}
|
|
9
|
-
declare const _default: React.ComponentType<import("@draftbit/react-theme-provider").$Without<DeckSwiperCardProps
|
|
8
|
+
declare const _default: React.ComponentType<import("@draftbit/react-theme-provider").$Without<React.PropsWithChildren<DeckSwiperCardProps>, "theme"> & {
|
|
10
9
|
theme?: import("@draftbit/react-theme-provider").$DeepPartial<any> | undefined;
|
|
11
|
-
}> & import("@draftbit/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<DeckSwiperCardProps
|
|
10
|
+
}> & import("@draftbit/react-theme-provider/typings/hoist-non-react-statics").NonReactStatics<React.ComponentType<React.PropsWithChildren<DeckSwiperCardProps>> & React.FC<React.PropsWithChildren<DeckSwiperCardProps>>, {}>;
|
|
12
11
|
export default _default;
|
|
13
12
|
//# sourceMappingURL=DeckSwiperCard.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"DeckSwiperCard.d.ts","sourceRoot":"","sources":["../../../../../src/components/DeckSwiper/DeckSwiperCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAoB,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAGvD,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,
|
|
1
|
+
{"version":3,"file":"DeckSwiperCard.d.ts","sourceRoot":"","sources":["../../../../../src/components/DeckSwiper/DeckSwiperCard.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAoB,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACtE,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAGvD,MAAM,WAAW,mBAAmB;IAClC,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,CAAC;IAC7B,KAAK,EAAE,KAAK,CAAC;CACd;;;;AA6BD,wBAAyC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Picker.d.ts","sourceRoot":"","sources":["../../../../../src/components/Picker/Picker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAKL,SAAS,EACT,SAAS,EAGV,MAAM,cAAc,CAAC;AAStB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAQtD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,oBAAY,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,EAAE,CAAC;IACnC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAC7B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CACxB,CAAC;;;;
|
|
1
|
+
{"version":3,"file":"Picker.d.ts","sourceRoot":"","sources":["../../../../../src/components/Picker/Picker.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,EAKL,SAAS,EACT,SAAS,EAGV,MAAM,cAAc,CAAC;AAStB,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,uBAAuB,CAAC;AAQtD,MAAM,WAAW,YAAY;IAC3B,KAAK,EAAE,MAAM,CAAC;IACd,KAAK,EAAE,MAAM,CAAC;CACf;AAED,oBAAY,WAAW,GAAG;IACxB,KAAK,CAAC,EAAE,GAAG,CAAC;IACZ,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE,SAAS,CAAC,SAAS,CAAC,GAAG;QAAE,MAAM,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACnD,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,YAAY,EAAE,GAAG,MAAM,EAAE,CAAC;IACnC,aAAa,EAAE,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACtD,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,YAAY,CAAC,EAAE,OAAO,GAAG,QAAQ,CAAC;IAClC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,oBAAoB,CAAC,EAAE,MAAM,CAAC;IAC9B,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,IAAI,CAAC,EAAE,OAAO,GAAG,WAAW,CAAC;IAC7B,mBAAmB,CAAC,EAAE,OAAO,CAAC;IAC9B,KAAK,EAAE,KAAK,CAAC;IACb,IAAI,EAAE,QAAQ,CAAC,MAAM,CAAC,CAAC;CACxB,CAAC;;;;AA2aF,wBAAiC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@draftbit/core",
|
|
3
|
-
"version": "46.8.1-
|
|
3
|
+
"version": "46.8.1-d78af9.2+d78af9a",
|
|
4
4
|
"description": "Core (non-native) Components",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"dependencies": {
|
|
42
42
|
"@date-io/date-fns": "^1.3.13",
|
|
43
43
|
"@draftbit/react-theme-provider": "^2.1.1",
|
|
44
|
-
"@draftbit/types": "^46.8.1-
|
|
44
|
+
"@draftbit/types": "^46.8.1-d78af9.2+d78af9a",
|
|
45
45
|
"@material-ui/core": "^4.11.0",
|
|
46
46
|
"@material-ui/pickers": "^3.2.10",
|
|
47
47
|
"@react-native-community/slider": "4.2.3",
|
|
@@ -92,5 +92,5 @@
|
|
|
92
92
|
]
|
|
93
93
|
]
|
|
94
94
|
},
|
|
95
|
-
"gitHead": "
|
|
95
|
+
"gitHead": "d78af9a6345ef51986bcac3f5667917d61582f82"
|
|
96
96
|
}
|
|
@@ -1,10 +1,40 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { StyleSheet, View } from "react-native";
|
|
3
3
|
import DeckSwiperComponent from "react-native-deck-swiper";
|
|
4
|
-
const DeckSwiper = ({ onIndexChanged, onEndReached, startCardIndex = 0, infiniteSwiping = false, verticalEnabled = true, horizontalEnabled = true, visibleCardCount = 1, style, children, }) => {
|
|
4
|
+
const DeckSwiper = ({ onIndexChanged, onEndReached, startCardIndex = 0, infiniteSwiping = false, verticalEnabled = true, horizontalEnabled = true, visibleCardCount = 1, data, keyExtractor, renderItem, style, children, }) => {
|
|
5
|
+
//Both 'renderItem' and 'data' are optional to allow direct children. But if one is included, both need to be included
|
|
6
|
+
if ((data && !renderItem) || (renderItem && !data)) {
|
|
7
|
+
throw new Error("'renderItem' and 'data' need to both be provided to lazily render. Either remove them entirley or include both");
|
|
8
|
+
}
|
|
9
|
+
if (data && renderItem && children) {
|
|
10
|
+
console.warn("'children' of DeckSwiper ignored due to usage of 'data' and 'renderItem'");
|
|
11
|
+
}
|
|
5
12
|
const childrenArray = React.useMemo(() => React.Children.toArray(children), [children]);
|
|
6
13
|
// an array of indices based on children count
|
|
7
14
|
const cardsFillerData = React.useMemo(() => Array.from(Array(childrenArray.length).keys()), [childrenArray]);
|
|
15
|
+
const cardsData = data || cardsFillerData;
|
|
16
|
+
const renderCard = (card, index) => {
|
|
17
|
+
if (renderItem) {
|
|
18
|
+
return renderItem({ item: card, index });
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
return React.createElement(React.Fragment, null, childrenArray[index]);
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const renderFirstCard = () => {
|
|
25
|
+
if (cardsData.length) {
|
|
26
|
+
return renderCard(cardsData[0], 0);
|
|
27
|
+
}
|
|
28
|
+
return undefined;
|
|
29
|
+
};
|
|
30
|
+
const cardKeyExtractor = (card) => {
|
|
31
|
+
if (keyExtractor) {
|
|
32
|
+
return keyExtractor(card);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
return card.toString();
|
|
36
|
+
}
|
|
37
|
+
};
|
|
8
38
|
/**
|
|
9
39
|
* By default react-native-deck-swiper positions everything with absolute position.
|
|
10
40
|
* To overcome this, it is wrapped in a View to be able to add the component in any layout structure.
|
|
@@ -15,8 +45,8 @@ const DeckSwiper = ({ onIndexChanged, onEndReached, startCardIndex = 0, infinite
|
|
|
15
45
|
* This effectivley makes the default height of the container be the height of the first card.
|
|
16
46
|
*/
|
|
17
47
|
return (React.createElement(View, null,
|
|
18
|
-
React.createElement(View, { style: styles.containerHeightFiller },
|
|
19
|
-
React.createElement(DeckSwiperComponent, { cards:
|
|
48
|
+
React.createElement(View, { style: styles.containerHeightFiller }, renderFirstCard()),
|
|
49
|
+
React.createElement(DeckSwiperComponent, { cards: cardsData, renderCard: renderCard, keyExtractor: cardKeyExtractor, containerStyle: StyleSheet.flatten([styles.cardsContainer, style]), cardStyle: styles.card, onSwiped: onIndexChanged, onSwipedAll: onEndReached, cardIndex: startCardIndex, infinite: infiniteSwiping, verticalSwipe: verticalEnabled, horizontalSwipe: horizontalEnabled, showSecondCard: visibleCardCount > 1, stackSize: visibleCardCount, backgroundColor: "transparent", cardVerticalMargin: 0, cardHorizontalMargin: 0 })));
|
|
20
50
|
};
|
|
21
51
|
const styles = StyleSheet.create({
|
|
22
52
|
cardsContainer: {
|
|
@@ -2,7 +2,7 @@ import React from "react";
|
|
|
2
2
|
import { StyleProp, ViewStyle, StyleSheet, View } from "react-native";
|
|
3
3
|
import DeckSwiperComponent from "react-native-deck-swiper";
|
|
4
4
|
|
|
5
|
-
export interface DeckSwiperProps {
|
|
5
|
+
export interface DeckSwiperProps<T> {
|
|
6
6
|
onIndexChanged?: (index: number) => void;
|
|
7
7
|
onEndReached?: () => void;
|
|
8
8
|
startCardIndex?: number;
|
|
@@ -10,10 +10,13 @@ export interface DeckSwiperProps {
|
|
|
10
10
|
verticalEnabled?: boolean;
|
|
11
11
|
horizontalEnabled?: boolean;
|
|
12
12
|
visibleCardCount?: number;
|
|
13
|
+
data?: Array<T>;
|
|
14
|
+
keyExtractor?: (item: T) => string;
|
|
15
|
+
renderItem?: ({ item, index }: { item: T; index: number }) => JSX.Element;
|
|
13
16
|
style?: StyleProp<ViewStyle>;
|
|
14
17
|
}
|
|
15
18
|
|
|
16
|
-
const DeckSwiper
|
|
19
|
+
const DeckSwiper = <T extends object>({
|
|
17
20
|
onIndexChanged,
|
|
18
21
|
onEndReached,
|
|
19
22
|
startCardIndex = 0,
|
|
@@ -21,9 +24,25 @@ const DeckSwiper: React.FC<React.PropsWithChildren<DeckSwiperProps>> = ({
|
|
|
21
24
|
verticalEnabled = true,
|
|
22
25
|
horizontalEnabled = true,
|
|
23
26
|
visibleCardCount = 1,
|
|
27
|
+
data,
|
|
28
|
+
keyExtractor,
|
|
29
|
+
renderItem,
|
|
24
30
|
style,
|
|
25
31
|
children,
|
|
26
|
-
}) => {
|
|
32
|
+
}: React.PropsWithChildren<DeckSwiperProps<T>>) => {
|
|
33
|
+
//Both 'renderItem' and 'data' are optional to allow direct children. But if one is included, both need to be included
|
|
34
|
+
if ((data && !renderItem) || (renderItem && !data)) {
|
|
35
|
+
throw new Error(
|
|
36
|
+
"'renderItem' and 'data' need to both be provided to lazily render. Either remove them entirley or include both"
|
|
37
|
+
);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
if (data && renderItem && children) {
|
|
41
|
+
console.warn(
|
|
42
|
+
"'children' of DeckSwiper ignored due to usage of 'data' and 'renderItem'"
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
27
46
|
const childrenArray = React.useMemo(
|
|
28
47
|
() => React.Children.toArray(children),
|
|
29
48
|
[children]
|
|
@@ -35,6 +54,31 @@ const DeckSwiper: React.FC<React.PropsWithChildren<DeckSwiperProps>> = ({
|
|
|
35
54
|
[childrenArray]
|
|
36
55
|
);
|
|
37
56
|
|
|
57
|
+
const cardsData = data || cardsFillerData;
|
|
58
|
+
|
|
59
|
+
const renderCard = (card: any, index: number): JSX.Element => {
|
|
60
|
+
if (renderItem) {
|
|
61
|
+
return renderItem({ item: card, index });
|
|
62
|
+
} else {
|
|
63
|
+
return <>{childrenArray[index]}</>;
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
const renderFirstCard = (): JSX.Element | undefined => {
|
|
68
|
+
if (cardsData.length) {
|
|
69
|
+
return renderCard(cardsData[0], 0);
|
|
70
|
+
}
|
|
71
|
+
return undefined;
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const cardKeyExtractor = (card: any) => {
|
|
75
|
+
if (keyExtractor) {
|
|
76
|
+
return keyExtractor(card);
|
|
77
|
+
} else {
|
|
78
|
+
return card.toString();
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
38
82
|
/**
|
|
39
83
|
* By default react-native-deck-swiper positions everything with absolute position.
|
|
40
84
|
* To overcome this, it is wrapped in a View to be able to add the component in any layout structure.
|
|
@@ -47,13 +91,11 @@ const DeckSwiper: React.FC<React.PropsWithChildren<DeckSwiperProps>> = ({
|
|
|
47
91
|
|
|
48
92
|
return (
|
|
49
93
|
<View>
|
|
50
|
-
<View style={styles.containerHeightFiller}>
|
|
51
|
-
{childrenArray.length && childrenArray[0]}
|
|
52
|
-
</View>
|
|
94
|
+
<View style={styles.containerHeightFiller}>{renderFirstCard()}</View>
|
|
53
95
|
<DeckSwiperComponent
|
|
54
|
-
cards={
|
|
55
|
-
renderCard={
|
|
56
|
-
keyExtractor={
|
|
96
|
+
cards={cardsData as any[]}
|
|
97
|
+
renderCard={renderCard}
|
|
98
|
+
keyExtractor={cardKeyExtractor}
|
|
57
99
|
containerStyle={
|
|
58
100
|
StyleSheet.flatten([styles.cardsContainer, style]) as
|
|
59
101
|
| object
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import React from "react";
|
|
2
2
|
import { View, StyleSheet } from "react-native";
|
|
3
3
|
import { withTheme } from "../../theming";
|
|
4
|
-
const DeckSwiperCard = ({ style, children, theme
|
|
4
|
+
const DeckSwiperCard = ({ style, children, theme }) => (React.createElement(View, { style: [
|
|
5
5
|
styles.card,
|
|
6
6
|
{
|
|
7
7
|
backgroundColor: theme.colors.background,
|
|
@@ -5,15 +5,12 @@ import { withTheme } from "../../theming";
|
|
|
5
5
|
|
|
6
6
|
export interface DeckSwiperCardProps {
|
|
7
7
|
style?: StyleProp<ViewStyle>;
|
|
8
|
-
children: React.ReactNode;
|
|
9
8
|
theme: Theme;
|
|
10
9
|
}
|
|
11
10
|
|
|
12
|
-
const DeckSwiperCard: React.FC<
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
theme,
|
|
16
|
-
}) => (
|
|
11
|
+
const DeckSwiperCard: React.FC<
|
|
12
|
+
React.PropsWithChildren<DeckSwiperCardProps>
|
|
13
|
+
> = ({ style, children, theme }) => (
|
|
17
14
|
<View
|
|
18
15
|
style={[
|
|
19
16
|
styles.card,
|
|
@@ -36,8 +36,6 @@ const isWeb = Platform.OS === "web";
|
|
|
36
36
|
const unstyledColor = "rgba(165, 173, 183, 1)";
|
|
37
37
|
const disabledColor = "rgb(240, 240, 240)";
|
|
38
38
|
const errorColor = "rgba(255, 69, 100, 1)";
|
|
39
|
-
//Empty string for 'value' is treated as a non-value
|
|
40
|
-
//reason: Draftbit uses empty string as initial value for string state*/
|
|
41
39
|
const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style, placeholder, value, disabled = false, assistiveText, label, iconColor = unstyledColor, iconSize = 24, leftIconMode = "inset", leftIconName, placeholderTextColor = unstyledColor, rightIconName, type = "solid", autoDismissKeyboard = true, }) => {
|
|
42
40
|
var _a, _b;
|
|
43
41
|
const androidPickerRef = React.useRef(undefined);
|
|
@@ -47,12 +45,12 @@ const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style,
|
|
|
47
45
|
setPickerVisible(!pickerVisible);
|
|
48
46
|
};
|
|
49
47
|
React.useEffect(() => {
|
|
50
|
-
if (value != null
|
|
48
|
+
if (value != null) {
|
|
51
49
|
setInternalValue(value);
|
|
52
50
|
}
|
|
53
51
|
}, [value]);
|
|
54
52
|
React.useEffect(() => {
|
|
55
|
-
if (defaultValue != null
|
|
53
|
+
if (defaultValue != null) {
|
|
56
54
|
setInternalValue(defaultValue);
|
|
57
55
|
}
|
|
58
56
|
}, [defaultValue]);
|
|
@@ -67,7 +65,10 @@ const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style,
|
|
|
67
65
|
Keyboard.dismiss();
|
|
68
66
|
}
|
|
69
67
|
}, [pickerVisible, autoDismissKeyboard]);
|
|
70
|
-
const
|
|
68
|
+
const normalizedOptions = normalizeOptions(options);
|
|
69
|
+
const pickerOptions = placeholder
|
|
70
|
+
? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
|
|
71
|
+
: normalizedOptions;
|
|
71
72
|
const { viewStyles, textStyles } = extractStyles(style);
|
|
72
73
|
const additionalBorderStyles = ["backgroundColor"];
|
|
73
74
|
const additionalMarginStyles = [
|
|
@@ -162,10 +163,10 @@ const Picker = ({ error, options = [], onValueChange, defaultValue, Icon, style,
|
|
|
162
163
|
...(disabled ? { color: unstyledColor } : {}),
|
|
163
164
|
};
|
|
164
165
|
const handleValueChange = (newValue, itemIndex) => {
|
|
165
|
-
if (
|
|
166
|
+
if (!placeholder || itemIndex > 0) {
|
|
166
167
|
onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(newValue, itemIndex);
|
|
167
|
-
setInternalValue(newValue);
|
|
168
168
|
}
|
|
169
|
+
setInternalValue(newValue);
|
|
169
170
|
};
|
|
170
171
|
return (
|
|
171
172
|
/* marginsContainer */
|
|
@@ -92,8 +92,6 @@ const unstyledColor = "rgba(165, 173, 183, 1)";
|
|
|
92
92
|
const disabledColor = "rgb(240, 240, 240)";
|
|
93
93
|
const errorColor = "rgba(255, 69, 100, 1)";
|
|
94
94
|
|
|
95
|
-
//Empty string for 'value' is treated as a non-value
|
|
96
|
-
//reason: Draftbit uses empty string as initial value for string state*/
|
|
97
95
|
const Picker: React.FC<PickerProps> = ({
|
|
98
96
|
error,
|
|
99
97
|
options = [],
|
|
@@ -128,13 +126,13 @@ const Picker: React.FC<PickerProps> = ({
|
|
|
128
126
|
};
|
|
129
127
|
|
|
130
128
|
React.useEffect(() => {
|
|
131
|
-
if (value != null
|
|
129
|
+
if (value != null) {
|
|
132
130
|
setInternalValue(value);
|
|
133
131
|
}
|
|
134
132
|
}, [value]);
|
|
135
133
|
|
|
136
134
|
React.useEffect(() => {
|
|
137
|
-
if (defaultValue != null
|
|
135
|
+
if (defaultValue != null) {
|
|
138
136
|
setInternalValue(defaultValue);
|
|
139
137
|
}
|
|
140
138
|
}, [defaultValue]);
|
|
@@ -151,7 +149,11 @@ const Picker: React.FC<PickerProps> = ({
|
|
|
151
149
|
}
|
|
152
150
|
}, [pickerVisible, autoDismissKeyboard]);
|
|
153
151
|
|
|
154
|
-
const
|
|
152
|
+
const normalizedOptions = normalizeOptions(options);
|
|
153
|
+
|
|
154
|
+
const pickerOptions = placeholder
|
|
155
|
+
? [{ value: placeholder, label: placeholder }, ...normalizedOptions]
|
|
156
|
+
: normalizedOptions;
|
|
155
157
|
|
|
156
158
|
const { viewStyles, textStyles } = extractStyles(style);
|
|
157
159
|
|
|
@@ -302,10 +304,10 @@ const Picker: React.FC<PickerProps> = ({
|
|
|
302
304
|
};
|
|
303
305
|
|
|
304
306
|
const handleValueChange = (newValue: string, itemIndex: number) => {
|
|
305
|
-
if (
|
|
307
|
+
if (!placeholder || itemIndex > 0) {
|
|
306
308
|
onValueChange?.(newValue, itemIndex);
|
|
307
|
-
setInternalValue(newValue);
|
|
308
309
|
}
|
|
310
|
+
setInternalValue(newValue);
|
|
309
311
|
};
|
|
310
312
|
|
|
311
313
|
return (
|