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/index.js
CHANGED
@@ -1,9 +1,29 @@
|
|
1
|
-
/*! aport-tools v4.2.
|
1
|
+
/*! aport-tools v4.2.7 | 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,175 @@ 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 pickImage = function pickImage() {
|
677
|
+
return __awaiter(void 0, void 0, void 0, function () {
|
678
|
+
var permissionResult, result, selectedAssets, newFiles, invalidFiles, updatedFiles;
|
679
|
+
return __generator(this, function (_a) {
|
680
|
+
switch (_a.label) {
|
681
|
+
case 0:
|
682
|
+
if (disabled) return [2 /*return*/];
|
683
|
+
return [4 /*yield*/, ImagePicker__namespace.requestMediaLibraryPermissionsAsync()];
|
684
|
+
case 1:
|
685
|
+
permissionResult = _a.sent();
|
686
|
+
if (!permissionResult.granted) {
|
687
|
+
reactNative.Alert.alert("Permission Required", "We need access to your photos to upload images.");
|
688
|
+
return [2 /*return*/];
|
689
|
+
}
|
690
|
+
return [4 /*yield*/, ImagePicker__namespace.launchImageLibraryAsync({
|
691
|
+
mediaTypes: ImagePicker__namespace.MediaTypeOptions.Images,
|
692
|
+
allowsMultipleSelection: amount > 1,
|
693
|
+
quality: 1
|
694
|
+
})];
|
695
|
+
case 2:
|
696
|
+
result = _a.sent();
|
697
|
+
if (!result.canceled) {
|
698
|
+
selectedAssets = result.assets || [result];
|
699
|
+
newFiles = selectedAssets.map(function (asset) {
|
700
|
+
return {
|
701
|
+
uri: asset.uri,
|
702
|
+
name: asset.fileName || "unknown.jpg",
|
703
|
+
type: asset.mimeType || "image/jpeg"
|
704
|
+
};
|
705
|
+
});
|
706
|
+
invalidFiles = newFiles.filter(function (file) {
|
707
|
+
return !type.some(function (ext) {
|
708
|
+
return file.name.toLowerCase().endsWith(ext);
|
709
|
+
});
|
710
|
+
});
|
711
|
+
if (invalidFiles.length > 0) {
|
712
|
+
reactNative.Alert.alert("Invalid File Type", "Please upload files of type: ".concat(type.join(", ")));
|
713
|
+
return [2 /*return*/];
|
714
|
+
}
|
715
|
+
// Check max amount
|
716
|
+
if (selectedFiles.length + newFiles.length > amount) {
|
717
|
+
reactNative.Alert.alert("Limit Exceeded", "You can upload up to ".concat(amount, " files."));
|
718
|
+
return [2 /*return*/];
|
719
|
+
}
|
720
|
+
updatedFiles = __spreadArray(__spreadArray([], selectedFiles, true), newFiles, true).slice(0, amount);
|
721
|
+
setSelectedFiles(updatedFiles);
|
722
|
+
setFormValue(name, updatedFiles); // Update form context
|
723
|
+
}
|
724
|
+
return [2 /*return*/];
|
725
|
+
}
|
726
|
+
});
|
727
|
+
});
|
728
|
+
};
|
729
|
+
var removeFile = function removeFile(index) {
|
730
|
+
var updatedFiles = selectedFiles.filter(function (_, i) {
|
731
|
+
return i !== index;
|
732
|
+
});
|
733
|
+
setSelectedFiles(updatedFiles);
|
734
|
+
setFormValue(name, updatedFiles); // Update form context
|
735
|
+
};
|
736
|
+
return /*#__PURE__*/React.createElement(reactNative.View, {
|
737
|
+
style: styles$2.container
|
738
|
+
}, /*#__PURE__*/React.createElement(reactNative.Text, {
|
739
|
+
style: styles$2.label
|
740
|
+
}, placeholder), /*#__PURE__*/React.createElement(reactNative.View, {
|
741
|
+
style: styles$2.fileContainer
|
742
|
+
}, selectedFiles.map(function (file, index) {
|
743
|
+
return /*#__PURE__*/React.createElement(reactNative.View, {
|
744
|
+
key: index,
|
745
|
+
style: styles$2.fileItem
|
746
|
+
}, /*#__PURE__*/React.createElement(reactNative.Image, {
|
747
|
+
source: {
|
748
|
+
uri: file.uri
|
749
|
+
},
|
750
|
+
style: styles$2.imagePreview
|
751
|
+
}), /*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
|
752
|
+
onPress: function onPress() {
|
753
|
+
return removeFile(index);
|
754
|
+
},
|
755
|
+
style: styles$2.removeButton
|
756
|
+
}, /*#__PURE__*/React.createElement(reactNative.Text, {
|
757
|
+
style: styles$2.removeButtonText
|
758
|
+
}, "X")));
|
759
|
+
}), selectedFiles.length < amount && (/*#__PURE__*/React.createElement(reactNative.TouchableOpacity, {
|
760
|
+
onPress: pickImage,
|
761
|
+
style: styles$2.addButton,
|
762
|
+
disabled: disabled
|
763
|
+
}, /*#__PURE__*/React.createElement(reactNative.Text, {
|
764
|
+
style: styles$2.addButtonText
|
765
|
+
}, "+")))), errors[name] && /*#__PURE__*/React.createElement(reactNative.Text, {
|
766
|
+
style: styles$2.error
|
767
|
+
}, errors[name].join(", ")));
|
768
|
+
};
|
769
|
+
var styles$2 = reactNative.StyleSheet.create({
|
770
|
+
container: {
|
771
|
+
marginVertical: 10
|
772
|
+
},
|
773
|
+
label: {
|
774
|
+
fontSize: 16,
|
775
|
+
marginBottom: 5,
|
776
|
+
color: "#333"
|
777
|
+
},
|
778
|
+
fileContainer: {
|
779
|
+
flexDirection: "row",
|
780
|
+
flexWrap: "wrap",
|
781
|
+
gap: 10
|
782
|
+
},
|
783
|
+
fileItem: {
|
784
|
+
position: "relative",
|
785
|
+
width: 100,
|
786
|
+
height: 100,
|
787
|
+
marginRight: 10
|
788
|
+
},
|
789
|
+
imagePreview: {
|
790
|
+
width: "100%",
|
791
|
+
height: "100%",
|
792
|
+
borderRadius: 5
|
793
|
+
},
|
794
|
+
removeButton: {
|
795
|
+
position: "absolute",
|
796
|
+
top: 0,
|
797
|
+
right: 0,
|
798
|
+
backgroundColor: "red",
|
799
|
+
width: 20,
|
800
|
+
height: 20,
|
801
|
+
justifyContent: "center",
|
802
|
+
alignItems: "center",
|
803
|
+
borderRadius: 10
|
804
|
+
},
|
805
|
+
removeButtonText: {
|
806
|
+
color: "#fff",
|
807
|
+
fontWeight: "bold"
|
808
|
+
},
|
809
|
+
addButton: {
|
810
|
+
width: 100,
|
811
|
+
height: 100,
|
812
|
+
justifyContent: "center",
|
813
|
+
alignItems: "center",
|
814
|
+
backgroundColor: "#f0f0f0",
|
815
|
+
borderRadius: 5
|
816
|
+
},
|
817
|
+
addButtonText: {
|
818
|
+
fontSize: 24,
|
819
|
+
color: "#aaa"
|
820
|
+
},
|
821
|
+
error: {
|
822
|
+
color: "red",
|
823
|
+
marginTop: 5
|
824
|
+
}
|
825
|
+
});
|
826
|
+
|
638
827
|
// src/components/Button.tsx
|
639
828
|
/**
|
640
829
|
* Determines the styles based on the button type and whether it is disabled.
|
@@ -818,6 +1007,7 @@ exports.Card = Card;
|
|
818
1007
|
exports.ErrorList = ErrorList;
|
819
1008
|
exports.Form = Form;
|
820
1009
|
exports.Input = Input;
|
1010
|
+
exports.InputAttach = InputAttach;
|
821
1011
|
exports.InputList = InputList;
|
822
1012
|
exports.Label = Label;
|
823
1013
|
exports.Text = Text;
|