aport-tools 4.2.6 → 4.2.8
Sign up to get free protection for your applications and to get access to all the features.
- package/dist/forms/InputAttach.d.ts +10 -0
- package/dist/forms/index.d.ts +1 -0
- package/dist/index.esm.js +202 -26
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +220 -24
- package/dist/index.js.map +1 -1
- package/package.json +4 -1
package/dist/index.js
CHANGED
@@ -1,9 +1,29 @@
|
|
1
|
-
/*! aport-tools v4.2.
|
1
|
+
/*! aport-tools v4.2.8 | ISC */
|
2
2
|
'use strict';
|
3
3
|
|
4
4
|
var React = require('react');
|
5
5
|
var reactNative = require('react-native');
|
6
6
|
var aportThemes = require('aport-themes');
|
7
|
+
var ImagePicker = require('expo-image-picker');
|
8
|
+
|
9
|
+
function _interopNamespaceDefault(e) {
|
10
|
+
var n = Object.create(null);
|
11
|
+
if (e) {
|
12
|
+
Object.keys(e).forEach(function (k) {
|
13
|
+
if (k !== 'default') {
|
14
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
15
|
+
Object.defineProperty(n, k, d.get ? d : {
|
16
|
+
enumerable: true,
|
17
|
+
get: function () { return e[k]; }
|
18
|
+
});
|
19
|
+
}
|
20
|
+
});
|
21
|
+
}
|
22
|
+
n.default = e;
|
23
|
+
return Object.freeze(n);
|
24
|
+
}
|
25
|
+
|
26
|
+
var ImagePicker__namespace = /*#__PURE__*/_interopNamespaceDefault(ImagePicker);
|
7
27
|
|
8
28
|
/******************************************************************************
|
9
29
|
Copyright (c) Microsoft Corporation.
|
@@ -232,23 +252,23 @@ var ErrorList = function ErrorList(_a) {
|
|
232
252
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
233
253
|
var colors = theme.colors;
|
234
254
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
235
|
-
style: styles$
|
255
|
+
style: styles$7.container
|
236
256
|
}, errors.map(function (error, index) {
|
237
257
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
238
258
|
key: index,
|
239
|
-
style: styles$
|
259
|
+
style: styles$7.errorItem
|
240
260
|
}, /*#__PURE__*/React.createElement(Text, {
|
241
|
-
style: [styles$
|
261
|
+
style: [styles$7.bullet, {
|
242
262
|
color: colors.error.hex
|
243
263
|
}]
|
244
264
|
}, "\u2022"), /*#__PURE__*/React.createElement(Text, {
|
245
|
-
style: [styles$
|
265
|
+
style: [styles$7.errorText, {
|
246
266
|
color: colors.error.hex
|
247
267
|
}]
|
248
268
|
}, error));
|
249
269
|
}));
|
250
270
|
};
|
251
|
-
var styles$
|
271
|
+
var styles$7 = reactNative.StyleSheet.create({
|
252
272
|
container: {
|
253
273
|
marginTop: 4
|
254
274
|
},
|
@@ -326,13 +346,13 @@ var Input = function Input(_a) {
|
|
326
346
|
setFormValue(name, formattedText);
|
327
347
|
};
|
328
348
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
329
|
-
style: styles$
|
349
|
+
style: styles$6.container
|
330
350
|
}, /*#__PURE__*/React.createElement(Text, {
|
331
|
-
style: [styles$
|
351
|
+
style: [styles$6.label, {
|
332
352
|
color: colors.text.hex
|
333
353
|
}]
|
334
354
|
}, label), /*#__PURE__*/React.createElement(reactNative.TextInput, __assign({
|
335
|
-
style: [styles$
|
355
|
+
style: [styles$6.input, {
|
336
356
|
backgroundColor: colors.body.hex,
|
337
357
|
borderColor: formErrors[name] ? colors.error.hex : "#CCC",
|
338
358
|
color: colors.text.hex
|
@@ -345,7 +365,7 @@ var Input = function Input(_a) {
|
|
345
365
|
errors: formErrors[name]
|
346
366
|
})));
|
347
367
|
};
|
348
|
-
var styles$
|
368
|
+
var styles$6 = reactNative.StyleSheet.create({
|
349
369
|
container: {
|
350
370
|
marginBottom: 16
|
351
371
|
},
|
@@ -376,11 +396,11 @@ var TextArea = function TextArea(_a) {
|
|
376
396
|
setFormValue(name, text);
|
377
397
|
};
|
378
398
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
379
|
-
style: styles$
|
399
|
+
style: styles$5.container
|
380
400
|
}, /*#__PURE__*/React.createElement(Text, {
|
381
|
-
style: styles$
|
401
|
+
style: styles$5.label
|
382
402
|
}, label), /*#__PURE__*/React.createElement(reactNative.TextInput, __assign({
|
383
|
-
style: [styles$
|
403
|
+
style: [styles$5.textArea, style],
|
384
404
|
value: formValues[name] || '',
|
385
405
|
onChangeText: handleChange,
|
386
406
|
placeholder: label,
|
@@ -393,7 +413,7 @@ var TextArea = function TextArea(_a) {
|
|
393
413
|
errors: formErrors[name]
|
394
414
|
})));
|
395
415
|
};
|
396
|
-
var styles$
|
416
|
+
var styles$5 = reactNative.StyleSheet.create({
|
397
417
|
container: {
|
398
418
|
marginBottom: 16
|
399
419
|
},
|
@@ -422,12 +442,12 @@ var Label = function Label(_a) {
|
|
422
442
|
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
423
443
|
var colors = theme.colors;
|
424
444
|
return /*#__PURE__*/React.createElement(Text, {
|
425
|
-
style: [styles$
|
445
|
+
style: [styles$4.label, style, {
|
426
446
|
color: colors.text.hex
|
427
447
|
}]
|
428
448
|
}, text);
|
429
449
|
};
|
430
|
-
var styles$
|
450
|
+
var styles$4 = reactNative.StyleSheet.create({
|
431
451
|
label: {
|
432
452
|
marginBottom: 4,
|
433
453
|
fontWeight: '500'
|
@@ -540,9 +560,9 @@ var InputList = function InputList(_a) {
|
|
540
560
|
});
|
541
561
|
};
|
542
562
|
return /*#__PURE__*/React.createElement(reactNative.View, {
|
543
|
-
style: [styles$
|
563
|
+
style: [styles$3.container, style]
|
544
564
|
}, /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
|
545
|
-
style: styles$
|
565
|
+
style: styles$3.inputContainer,
|
546
566
|
onPress: toggleDropdown,
|
547
567
|
disabled: disabled
|
548
568
|
}, /*#__PURE__*/React.createElement(reactNative.Text, {
|
@@ -554,10 +574,10 @@ var InputList = function InputList(_a) {
|
|
554
574
|
transparent: true,
|
555
575
|
animationType: "fade"
|
556
576
|
}, /*#__PURE__*/React.createElement(reactNative.Pressable, {
|
557
|
-
style: styles$
|
577
|
+
style: styles$3.overlay,
|
558
578
|
onPress: handleCloseDropdown
|
559
579
|
}), /*#__PURE__*/React.createElement(reactNative.View, {
|
560
|
-
style: [styles$
|
580
|
+
style: [styles$3.dropdownContainer, {
|
561
581
|
backgroundColor: colors.body.hex
|
562
582
|
}]
|
563
583
|
}, /*#__PURE__*/React.createElement(reactNative.FlatList, {
|
@@ -575,7 +595,7 @@ var InputList = function InputList(_a) {
|
|
575
595
|
onPress: function onPress() {
|
576
596
|
return handleSelectOption(item);
|
577
597
|
},
|
578
|
-
style: [styles$
|
598
|
+
style: [styles$3.optionItem, isSelected ? {
|
579
599
|
backgroundColor: colors.primary.hex
|
580
600
|
} : {}, isDisabled ? {
|
581
601
|
backgroundColor: colors.placeHolder.hex
|
@@ -586,18 +606,18 @@ var InputList = function InputList(_a) {
|
|
586
606
|
color: colors.background.hex
|
587
607
|
} : {
|
588
608
|
color: colors.text.hex
|
589
|
-
}, isDisabled ? styles$
|
609
|
+
}, isDisabled ? styles$3.disabledText : {}]
|
590
610
|
}, item.label));
|
591
611
|
},
|
592
612
|
ItemSeparatorComponent: function ItemSeparatorComponent() {
|
593
613
|
return separator ? /*#__PURE__*/React.createElement(reactNative.View, {
|
594
|
-
style: styles$
|
614
|
+
style: styles$3.separator
|
595
615
|
}) : null;
|
596
616
|
},
|
597
617
|
scrollEnabled: !closeOnScroll
|
598
618
|
}))));
|
599
619
|
};
|
600
|
-
var styles$
|
620
|
+
var styles$3 = reactNative.StyleSheet.create({
|
601
621
|
container: {
|
602
622
|
padding: 8
|
603
623
|
},
|
@@ -635,6 +655,181 @@ var styles$2 = reactNative.StyleSheet.create({
|
|
635
655
|
}
|
636
656
|
});
|
637
657
|
|
658
|
+
// src/components/InputAttach.tsx
|
659
|
+
var InputAttach = function InputAttach(_a) {
|
660
|
+
var name = _a.name,
|
661
|
+
_b = _a.type,
|
662
|
+
type = _b === void 0 ? ["png", "jpg", "jpeg"] : _b,
|
663
|
+
_c = _a.amount,
|
664
|
+
amount = _c === void 0 ? 1 : _c,
|
665
|
+
_d = _a.disabled,
|
666
|
+
disabled = _d === void 0 ? false : _d,
|
667
|
+
_e = _a.placeholder,
|
668
|
+
placeholder = _e === void 0 ? "Upload an image" : _e;
|
669
|
+
var _f = useFormContext(),
|
670
|
+
setFormValue = _f.setFormValue;
|
671
|
+
_f.formValues;
|
672
|
+
var errors = _f.errors;
|
673
|
+
var _g = React.useState([]),
|
674
|
+
selectedFiles = _g[0],
|
675
|
+
setSelectedFiles = _g[1];
|
676
|
+
var theme = React.useContext(aportThemes.ThemeContext).theme;
|
677
|
+
var colors = theme.colors;
|
678
|
+
var pickImage = function pickImage() {
|
679
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
680
|
+
var permissionResult, result, selectedAssets, newFiles, invalidFiles, updatedFiles;
|
681
|
+
return __generator(this, function (_a) {
|
682
|
+
switch (_a.label) {
|
683
|
+
case 0:
|
684
|
+
if (disabled) return [2 /*return*/];
|
685
|
+
return [4 /*yield*/, ImagePicker__namespace.requestMediaLibraryPermissionsAsync()];
|
686
|
+
case 1:
|
687
|
+
permissionResult = _a.sent();
|
688
|
+
if (!permissionResult.granted) {
|
689
|
+
reactNative.Alert.alert("Permission Required", "We need access to your photos to upload images.");
|
690
|
+
return [2 /*return*/];
|
691
|
+
}
|
692
|
+
return [4 /*yield*/, ImagePicker__namespace.launchImageLibraryAsync({
|
693
|
+
mediaTypes: ImagePicker__namespace.MediaTypeOptions.Images,
|
694
|
+
allowsMultipleSelection: amount > 1,
|
695
|
+
quality: 1
|
696
|
+
})];
|
697
|
+
case 2:
|
698
|
+
result = _a.sent();
|
699
|
+
if (!result.canceled) {
|
700
|
+
selectedAssets = result.assets || [result];
|
701
|
+
newFiles = selectedAssets.map(function (asset) {
|
702
|
+
return {
|
703
|
+
uri: asset.uri,
|
704
|
+
name: asset.fileName || "unknown.jpg",
|
705
|
+
type: asset.mimeType || "image/jpeg"
|
706
|
+
};
|
707
|
+
});
|
708
|
+
invalidFiles = newFiles.filter(function (file) {
|
709
|
+
return !type.some(function (ext) {
|
710
|
+
return file.name.toLowerCase().endsWith(ext);
|
711
|
+
});
|
712
|
+
});
|
713
|
+
if (invalidFiles.length > 0) {
|
714
|
+
reactNative.Alert.alert("Invalid File Type", "Please upload files of type: ".concat(type.join(", ")));
|
715
|
+
return [2 /*return*/];
|
716
|
+
}
|
717
|
+
// Check max amount
|
718
|
+
if (selectedFiles.length + newFiles.length > amount) {
|
719
|
+
reactNative.Alert.alert("Limit Exceeded", "You can upload up to ".concat(amount, " files."));
|
720
|
+
return [2 /*return*/];
|
721
|
+
}
|
722
|
+
updatedFiles = __spreadArray(__spreadArray([], selectedFiles, true), newFiles, true).slice(0, amount);
|
723
|
+
setSelectedFiles(updatedFiles);
|
724
|
+
setFormValue(name, updatedFiles); // Update form context
|
725
|
+
}
|
726
|
+
return [2 /*return*/];
|
727
|
+
}
|
728
|
+
});
|
729
|
+
});
|
730
|
+
};
|
731
|
+
var removeFile = function removeFile(index) {
|
732
|
+
var updatedFiles = selectedFiles.filter(function (_, i) {
|
733
|
+
return i !== index;
|
734
|
+
});
|
735
|
+
setSelectedFiles(updatedFiles);
|
736
|
+
setFormValue(name, updatedFiles); // Update form context
|
737
|
+
};
|
738
|
+
return /*#__PURE__*/React.createElement(reactNative.View, {
|
739
|
+
style: styles$2.container
|
740
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
741
|
+
style: [styles$2.label, {
|
742
|
+
color: colors.text.hex
|
743
|
+
}]
|
744
|
+
}, placeholder), /*#__PURE__*/React.createElement(reactNative.View, {
|
745
|
+
style: styles$2.fileContainer
|
746
|
+
}, selectedFiles.map(function (file, index) {
|
747
|
+
return /*#__PURE__*/React.createElement(reactNative.View, {
|
748
|
+
key: index,
|
749
|
+
style: styles$2.fileItem
|
750
|
+
}, /*#__PURE__*/React.createElement(reactNative.Image, {
|
751
|
+
source: {
|
752
|
+
uri: file.uri
|
753
|
+
},
|
754
|
+
style: styles$2.imagePreview
|
755
|
+
}), /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
|
756
|
+
onPress: function onPress() {
|
757
|
+
return removeFile(index);
|
758
|
+
},
|
759
|
+
style: [styles$2.removeButton, {
|
760
|
+
backgroundColor: colors.error.hex
|
761
|
+
}]
|
762
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
763
|
+
style: styles$2.removeButtonText
|
764
|
+
}, "X")));
|
765
|
+
}), selectedFiles.length < amount && (/*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
|
766
|
+
onPress: pickImage,
|
767
|
+
style: [styles$2.addButton, {
|
768
|
+
backgroundColor: colors.body.hex
|
769
|
+
}],
|
770
|
+
disabled: disabled
|
771
|
+
}, /*#__PURE__*/React.createElement(Text, {
|
772
|
+
style: [styles$2.addButtonText, {
|
773
|
+
color: colors.placeHolder.hex
|
774
|
+
}]
|
775
|
+
}, "+")))), errors[name] && /*#__PURE__*/React.createElement(Text, {
|
776
|
+
style: [styles$2.error, {
|
777
|
+
color: colors.error.hex
|
778
|
+
}]
|
779
|
+
}, errors[name].join(", ")));
|
780
|
+
};
|
781
|
+
var styles$2 = reactNative.StyleSheet.create({
|
782
|
+
container: {
|
783
|
+
marginVertical: 10
|
784
|
+
},
|
785
|
+
label: {
|
786
|
+
marginBottom: 5
|
787
|
+
},
|
788
|
+
fileContainer: {
|
789
|
+
flexDirection: "row",
|
790
|
+
flexWrap: "wrap",
|
791
|
+
gap: 10
|
792
|
+
},
|
793
|
+
fileItem: {
|
794
|
+
position: "relative",
|
795
|
+
width: 100,
|
796
|
+
height: 100,
|
797
|
+
marginRight: 10
|
798
|
+
},
|
799
|
+
imagePreview: {
|
800
|
+
width: "100%",
|
801
|
+
height: "100%",
|
802
|
+
borderRadius: 5
|
803
|
+
},
|
804
|
+
removeButton: {
|
805
|
+
position: "absolute",
|
806
|
+
top: 0,
|
807
|
+
right: 0,
|
808
|
+
width: 20,
|
809
|
+
height: 20,
|
810
|
+
justifyContent: "center",
|
811
|
+
alignItems: "center",
|
812
|
+
borderRadius: 10
|
813
|
+
},
|
814
|
+
removeButtonText: {
|
815
|
+
color: "#fff",
|
816
|
+
fontWeight: "bold"
|
817
|
+
},
|
818
|
+
addButton: {
|
819
|
+
width: 100,
|
820
|
+
height: 100,
|
821
|
+
justifyContent: "center",
|
822
|
+
alignItems: "center",
|
823
|
+
borderRadius: 5
|
824
|
+
},
|
825
|
+
addButtonText: {
|
826
|
+
fontSize: 24
|
827
|
+
},
|
828
|
+
error: {
|
829
|
+
marginTop: 5
|
830
|
+
}
|
831
|
+
});
|
832
|
+
|
638
833
|
// src/components/Button.tsx
|
639
834
|
/**
|
640
835
|
* Determines the styles based on the button type and whether it is disabled.
|
@@ -818,6 +1013,7 @@ exports.Card = Card;
|
|
818
1013
|
exports.ErrorList = ErrorList;
|
819
1014
|
exports.Form = Form;
|
820
1015
|
exports.Input = Input;
|
1016
|
+
exports.InputAttach = InputAttach;
|
821
1017
|
exports.InputList = InputList;
|
822
1018
|
exports.Label = Label;
|
823
1019
|
exports.Text = Text;
|