aport-tools 4.2.6 → 4.2.7
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/dist/forms/InputAttach.d.ts +10 -0
- package/dist/forms/index.d.ts +1 -0
- package/dist/index.esm.js +196 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +214 -24
- package/dist/index.js.map +1 -1
- package/package.json +6 -2
package/dist/forms/index.d.ts
CHANGED
package/dist/index.esm.js
CHANGED
@@ -1,7 +1,8 @@
|
|
1
|
-
/*! aport-tools v4.2.
|
1
|
+
/*! aport-tools v4.2.7 | ISC */
|
2
2
|
import React, { useContext, useState, createContext, useCallback, useMemo } from 'react';
|
3
|
-
import { StyleSheet, Text as Text$1, View, TextInput, TouchableOpacity, Modal, Pressable, FlatList, Keyboard, ActivityIndicator, Platform } from 'react-native';
|
3
|
+
import { StyleSheet, Text as Text$1, View, TextInput, TouchableOpacity, Modal, Pressable, FlatList, Keyboard, Image, Alert, ActivityIndicator, Platform } from 'react-native';
|
4
4
|
import { ThemeContext } from 'aport-themes';
|
5
|
+
import * as ImagePicker from 'expo-image-picker';
|
5
6
|
|
6
7
|
/******************************************************************************
|
7
8
|
Copyright (c) Microsoft Corporation.
|
@@ -230,23 +231,23 @@ var ErrorList = function ErrorList(_a) {
|
|
230
231
|
var theme = useContext(ThemeContext).theme;
|
231
232
|
var colors = theme.colors;
|
232
233
|
return /*#__PURE__*/React.createElement(View, {
|
233
|
-
style: styles$
|
234
|
+
style: styles$7.container
|
234
235
|
}, errors.map(function (error, index) {
|
235
236
|
return /*#__PURE__*/React.createElement(View, {
|
236
237
|
key: index,
|
237
|
-
style: styles$
|
238
|
+
style: styles$7.errorItem
|
238
239
|
}, /*#__PURE__*/React.createElement(Text, {
|
239
|
-
style: [styles$
|
240
|
+
style: [styles$7.bullet, {
|
240
241
|
color: colors.error.hex
|
241
242
|
}]
|
242
243
|
}, "\u2022"), /*#__PURE__*/React.createElement(Text, {
|
243
|
-
style: [styles$
|
244
|
+
style: [styles$7.errorText, {
|
244
245
|
color: colors.error.hex
|
245
246
|
}]
|
246
247
|
}, error));
|
247
248
|
}));
|
248
249
|
};
|
249
|
-
var styles$
|
250
|
+
var styles$7 = StyleSheet.create({
|
250
251
|
container: {
|
251
252
|
marginTop: 4
|
252
253
|
},
|
@@ -324,13 +325,13 @@ var Input = function Input(_a) {
|
|
324
325
|
setFormValue(name, formattedText);
|
325
326
|
};
|
326
327
|
return /*#__PURE__*/React.createElement(View, {
|
327
|
-
style: styles$
|
328
|
+
style: styles$6.container
|
328
329
|
}, /*#__PURE__*/React.createElement(Text, {
|
329
|
-
style: [styles$
|
330
|
+
style: [styles$6.label, {
|
330
331
|
color: colors.text.hex
|
331
332
|
}]
|
332
333
|
}, label), /*#__PURE__*/React.createElement(TextInput, __assign({
|
333
|
-
style: [styles$
|
334
|
+
style: [styles$6.input, {
|
334
335
|
backgroundColor: colors.body.hex,
|
335
336
|
borderColor: formErrors[name] ? colors.error.hex : "#CCC",
|
336
337
|
color: colors.text.hex
|
@@ -343,7 +344,7 @@ var Input = function Input(_a) {
|
|
343
344
|
errors: formErrors[name]
|
344
345
|
})));
|
345
346
|
};
|
346
|
-
var styles$
|
347
|
+
var styles$6 = StyleSheet.create({
|
347
348
|
container: {
|
348
349
|
marginBottom: 16
|
349
350
|
},
|
@@ -374,11 +375,11 @@ var TextArea = function TextArea(_a) {
|
|
374
375
|
setFormValue(name, text);
|
375
376
|
};
|
376
377
|
return /*#__PURE__*/React.createElement(View, {
|
377
|
-
style: styles$
|
378
|
+
style: styles$5.container
|
378
379
|
}, /*#__PURE__*/React.createElement(Text, {
|
379
|
-
style: styles$
|
380
|
+
style: styles$5.label
|
380
381
|
}, label), /*#__PURE__*/React.createElement(TextInput, __assign({
|
381
|
-
style: [styles$
|
382
|
+
style: [styles$5.textArea, style],
|
382
383
|
value: formValues[name] || '',
|
383
384
|
onChangeText: handleChange,
|
384
385
|
placeholder: label,
|
@@ -391,7 +392,7 @@ var TextArea = function TextArea(_a) {
|
|
391
392
|
errors: formErrors[name]
|
392
393
|
})));
|
393
394
|
};
|
394
|
-
var styles$
|
395
|
+
var styles$5 = StyleSheet.create({
|
395
396
|
container: {
|
396
397
|
marginBottom: 16
|
397
398
|
},
|
@@ -420,12 +421,12 @@ var Label = function Label(_a) {
|
|
420
421
|
var theme = useContext(ThemeContext).theme;
|
421
422
|
var colors = theme.colors;
|
422
423
|
return /*#__PURE__*/React.createElement(Text, {
|
423
|
-
style: [styles$
|
424
|
+
style: [styles$4.label, style, {
|
424
425
|
color: colors.text.hex
|
425
426
|
}]
|
426
427
|
}, text);
|
427
428
|
};
|
428
|
-
var styles$
|
429
|
+
var styles$4 = StyleSheet.create({
|
429
430
|
label: {
|
430
431
|
marginBottom: 4,
|
431
432
|
fontWeight: '500'
|
@@ -538,9 +539,9 @@ var InputList = function InputList(_a) {
|
|
538
539
|
});
|
539
540
|
};
|
540
541
|
return /*#__PURE__*/React.createElement(View, {
|
541
|
-
style: [styles$
|
542
|
+
style: [styles$3.container, style]
|
542
543
|
}, /*#__PURE__*/React.createElement(TouchableOpacity, {
|
543
|
-
style: styles$
|
544
|
+
style: styles$3.inputContainer,
|
544
545
|
onPress: toggleDropdown,
|
545
546
|
disabled: disabled
|
546
547
|
}, /*#__PURE__*/React.createElement(Text$1, {
|
@@ -552,10 +553,10 @@ var InputList = function InputList(_a) {
|
|
552
553
|
transparent: true,
|
553
554
|
animationType: "fade"
|
554
555
|
}, /*#__PURE__*/React.createElement(Pressable, {
|
555
|
-
style: styles$
|
556
|
+
style: styles$3.overlay,
|
556
557
|
onPress: handleCloseDropdown
|
557
558
|
}), /*#__PURE__*/React.createElement(View, {
|
558
|
-
style: [styles$
|
559
|
+
style: [styles$3.dropdownContainer, {
|
559
560
|
backgroundColor: colors.body.hex
|
560
561
|
}]
|
561
562
|
}, /*#__PURE__*/React.createElement(FlatList, {
|
@@ -573,7 +574,7 @@ var InputList = function InputList(_a) {
|
|
573
574
|
onPress: function onPress() {
|
574
575
|
return handleSelectOption(item);
|
575
576
|
},
|
576
|
-
style: [styles$
|
577
|
+
style: [styles$3.optionItem, isSelected ? {
|
577
578
|
backgroundColor: colors.primary.hex
|
578
579
|
} : {}, isDisabled ? {
|
579
580
|
backgroundColor: colors.placeHolder.hex
|
@@ -584,18 +585,18 @@ var InputList = function InputList(_a) {
|
|
584
585
|
color: colors.background.hex
|
585
586
|
} : {
|
586
587
|
color: colors.text.hex
|
587
|
-
}, isDisabled ? styles$
|
588
|
+
}, isDisabled ? styles$3.disabledText : {}]
|
588
589
|
}, item.label));
|
589
590
|
},
|
590
591
|
ItemSeparatorComponent: function ItemSeparatorComponent() {
|
591
592
|
return separator ? /*#__PURE__*/React.createElement(View, {
|
592
|
-
style: styles$
|
593
|
+
style: styles$3.separator
|
593
594
|
}) : null;
|
594
595
|
},
|
595
596
|
scrollEnabled: !closeOnScroll
|
596
597
|
}))));
|
597
598
|
};
|
598
|
-
var styles$
|
599
|
+
var styles$3 = StyleSheet.create({
|
599
600
|
container: {
|
600
601
|
padding: 8
|
601
602
|
},
|
@@ -633,6 +634,175 @@ var styles$2 = StyleSheet.create({
|
|
633
634
|
}
|
634
635
|
});
|
635
636
|
|
637
|
+
// src/components/InputAttach.tsx
|
638
|
+
var InputAttach = function InputAttach(_a) {
|
639
|
+
var name = _a.name,
|
640
|
+
_b = _a.type,
|
641
|
+
type = _b === void 0 ? ["png", "jpg", "jpeg"] : _b,
|
642
|
+
_c = _a.amount,
|
643
|
+
amount = _c === void 0 ? 1 : _c,
|
644
|
+
_d = _a.disabled,
|
645
|
+
disabled = _d === void 0 ? false : _d,
|
646
|
+
_e = _a.placeholder,
|
647
|
+
placeholder = _e === void 0 ? "Upload an image" : _e;
|
648
|
+
var _f = useFormContext(),
|
649
|
+
setFormValue = _f.setFormValue;
|
650
|
+
_f.formValues;
|
651
|
+
var errors = _f.errors;
|
652
|
+
var _g = useState([]),
|
653
|
+
selectedFiles = _g[0],
|
654
|
+
setSelectedFiles = _g[1];
|
655
|
+
var pickImage = function pickImage() {
|
656
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
657
|
+
var permissionResult, result, selectedAssets, newFiles, invalidFiles, updatedFiles;
|
658
|
+
return __generator(this, function (_a) {
|
659
|
+
switch (_a.label) {
|
660
|
+
case 0:
|
661
|
+
if (disabled) return [2 /*return*/];
|
662
|
+
return [4 /*yield*/, ImagePicker.requestMediaLibraryPermissionsAsync()];
|
663
|
+
case 1:
|
664
|
+
permissionResult = _a.sent();
|
665
|
+
if (!permissionResult.granted) {
|
666
|
+
Alert.alert("Permission Required", "We need access to your photos to upload images.");
|
667
|
+
return [2 /*return*/];
|
668
|
+
}
|
669
|
+
return [4 /*yield*/, ImagePicker.launchImageLibraryAsync({
|
670
|
+
mediaTypes: ImagePicker.MediaTypeOptions.Images,
|
671
|
+
allowsMultipleSelection: amount > 1,
|
672
|
+
quality: 1
|
673
|
+
})];
|
674
|
+
case 2:
|
675
|
+
result = _a.sent();
|
676
|
+
if (!result.canceled) {
|
677
|
+
selectedAssets = result.assets || [result];
|
678
|
+
newFiles = selectedAssets.map(function (asset) {
|
679
|
+
return {
|
680
|
+
uri: asset.uri,
|
681
|
+
name: asset.fileName || "unknown.jpg",
|
682
|
+
type: asset.mimeType || "image/jpeg"
|
683
|
+
};
|
684
|
+
});
|
685
|
+
invalidFiles = newFiles.filter(function (file) {
|
686
|
+
return !type.some(function (ext) {
|
687
|
+
return file.name.toLowerCase().endsWith(ext);
|
688
|
+
});
|
689
|
+
});
|
690
|
+
if (invalidFiles.length > 0) {
|
691
|
+
Alert.alert("Invalid File Type", "Please upload files of type: ".concat(type.join(", ")));
|
692
|
+
return [2 /*return*/];
|
693
|
+
}
|
694
|
+
// Check max amount
|
695
|
+
if (selectedFiles.length + newFiles.length > amount) {
|
696
|
+
Alert.alert("Limit Exceeded", "You can upload up to ".concat(amount, " files."));
|
697
|
+
return [2 /*return*/];
|
698
|
+
}
|
699
|
+
updatedFiles = __spreadArray(__spreadArray([], selectedFiles, true), newFiles, true).slice(0, amount);
|
700
|
+
setSelectedFiles(updatedFiles);
|
701
|
+
setFormValue(name, updatedFiles); // Update form context
|
702
|
+
}
|
703
|
+
return [2 /*return*/];
|
704
|
+
}
|
705
|
+
});
|
706
|
+
});
|
707
|
+
};
|
708
|
+
var removeFile = function removeFile(index) {
|
709
|
+
var updatedFiles = selectedFiles.filter(function (_, i) {
|
710
|
+
return i !== index;
|
711
|
+
});
|
712
|
+
setSelectedFiles(updatedFiles);
|
713
|
+
setFormValue(name, updatedFiles); // Update form context
|
714
|
+
};
|
715
|
+
return /*#__PURE__*/React.createElement(View, {
|
716
|
+
style: styles$2.container
|
717
|
+
}, /*#__PURE__*/React.createElement(Text$1, {
|
718
|
+
style: styles$2.label
|
719
|
+
}, placeholder), /*#__PURE__*/React.createElement(View, {
|
720
|
+
style: styles$2.fileContainer
|
721
|
+
}, selectedFiles.map(function (file, index) {
|
722
|
+
return /*#__PURE__*/React.createElement(View, {
|
723
|
+
key: index,
|
724
|
+
style: styles$2.fileItem
|
725
|
+
}, /*#__PURE__*/React.createElement(Image, {
|
726
|
+
source: {
|
727
|
+
uri: file.uri
|
728
|
+
},
|
729
|
+
style: styles$2.imagePreview
|
730
|
+
}), /*#__PURE__*/React.createElement(TouchableOpacity, {
|
731
|
+
onPress: function onPress() {
|
732
|
+
return removeFile(index);
|
733
|
+
},
|
734
|
+
style: styles$2.removeButton
|
735
|
+
}, /*#__PURE__*/React.createElement(Text$1, {
|
736
|
+
style: styles$2.removeButtonText
|
737
|
+
}, "X")));
|
738
|
+
}), selectedFiles.length < amount && (/*#__PURE__*/React.createElement(TouchableOpacity, {
|
739
|
+
onPress: pickImage,
|
740
|
+
style: styles$2.addButton,
|
741
|
+
disabled: disabled
|
742
|
+
}, /*#__PURE__*/React.createElement(Text$1, {
|
743
|
+
style: styles$2.addButtonText
|
744
|
+
}, "+")))), errors[name] && /*#__PURE__*/React.createElement(Text$1, {
|
745
|
+
style: styles$2.error
|
746
|
+
}, errors[name].join(", ")));
|
747
|
+
};
|
748
|
+
var styles$2 = StyleSheet.create({
|
749
|
+
container: {
|
750
|
+
marginVertical: 10
|
751
|
+
},
|
752
|
+
label: {
|
753
|
+
fontSize: 16,
|
754
|
+
marginBottom: 5,
|
755
|
+
color: "#333"
|
756
|
+
},
|
757
|
+
fileContainer: {
|
758
|
+
flexDirection: "row",
|
759
|
+
flexWrap: "wrap",
|
760
|
+
gap: 10
|
761
|
+
},
|
762
|
+
fileItem: {
|
763
|
+
position: "relative",
|
764
|
+
width: 100,
|
765
|
+
height: 100,
|
766
|
+
marginRight: 10
|
767
|
+
},
|
768
|
+
imagePreview: {
|
769
|
+
width: "100%",
|
770
|
+
height: "100%",
|
771
|
+
borderRadius: 5
|
772
|
+
},
|
773
|
+
removeButton: {
|
774
|
+
position: "absolute",
|
775
|
+
top: 0,
|
776
|
+
right: 0,
|
777
|
+
backgroundColor: "red",
|
778
|
+
width: 20,
|
779
|
+
height: 20,
|
780
|
+
justifyContent: "center",
|
781
|
+
alignItems: "center",
|
782
|
+
borderRadius: 10
|
783
|
+
},
|
784
|
+
removeButtonText: {
|
785
|
+
color: "#fff",
|
786
|
+
fontWeight: "bold"
|
787
|
+
},
|
788
|
+
addButton: {
|
789
|
+
width: 100,
|
790
|
+
height: 100,
|
791
|
+
justifyContent: "center",
|
792
|
+
alignItems: "center",
|
793
|
+
backgroundColor: "#f0f0f0",
|
794
|
+
borderRadius: 5
|
795
|
+
},
|
796
|
+
addButtonText: {
|
797
|
+
fontSize: 24,
|
798
|
+
color: "#aaa"
|
799
|
+
},
|
800
|
+
error: {
|
801
|
+
color: "red",
|
802
|
+
marginTop: 5
|
803
|
+
}
|
804
|
+
});
|
805
|
+
|
636
806
|
// src/components/Button.tsx
|
637
807
|
/**
|
638
808
|
* Determines the styles based on the button type and whether it is disabled.
|
@@ -811,5 +981,5 @@ var styles = StyleSheet.create({
|
|
811
981
|
}
|
812
982
|
});
|
813
983
|
|
814
|
-
export { Button, Card, ErrorList, Form, Input, InputList, Label, Text, TextArea, useFormContext };
|
984
|
+
export { Button, Card, ErrorList, Form, Input, InputAttach, InputList, Label, Text, TextArea, useFormContext };
|
815
985
|
//# sourceMappingURL=index.esm.js.map
|