@tradly/asset 1.0.13 → 1.0.15

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.
Files changed (76) hide show
  1. package/README.md +414 -13
  2. package/dist/components/FileUpload.js +8 -254
  3. package/dist/components/FileUpload.native.js +13 -0
  4. package/dist/components/Icons.js +10 -33
  5. package/dist/components/Icons.native.js +16 -0
  6. package/dist/components/ImagesSkeleton.js +7 -15
  7. package/dist/components/ImagesSkeleton.native.js +13 -0
  8. package/dist/components/MediaGallery.js +8 -148
  9. package/dist/components/MediaGallery.native.js +13 -0
  10. package/dist/components/MediaPopup.js +8 -99
  11. package/dist/components/MediaPopup.native.js +13 -0
  12. package/dist/components/MediaTab.js +7 -180
  13. package/dist/components/MediaTab.native.js +13 -0
  14. package/dist/components/Pagination.js +8 -136
  15. package/dist/components/Pagination.native.js +13 -0
  16. package/dist/components/VideosGallery.js +8 -148
  17. package/dist/components/VideosGallery.native.js +13 -0
  18. package/dist/core/MediaApiService.js +396 -0
  19. package/dist/esm/components/FileUpload.js +1 -253
  20. package/dist/esm/components/FileUpload.native.js +1 -0
  21. package/dist/esm/components/Icons.js +1 -32
  22. package/dist/esm/components/Icons.native.js +1 -0
  23. package/dist/esm/components/ImagesSkeleton.js +1 -14
  24. package/dist/esm/components/ImagesSkeleton.native.js +1 -0
  25. package/dist/esm/components/MediaGallery.js +1 -144
  26. package/dist/esm/components/MediaGallery.native.js +1 -0
  27. package/dist/esm/components/MediaPopup.js +1 -97
  28. package/dist/esm/components/MediaPopup.native.js +1 -0
  29. package/dist/esm/components/MediaTab.js +1 -177
  30. package/dist/esm/components/MediaTab.native.js +1 -0
  31. package/dist/esm/components/Pagination.js +1 -134
  32. package/dist/esm/components/Pagination.native.js +1 -0
  33. package/dist/esm/components/VideosGallery.js +1 -144
  34. package/dist/esm/components/VideosGallery.native.js +1 -0
  35. package/dist/esm/core/MediaApiService.js +390 -0
  36. package/dist/esm/index.js +4 -1
  37. package/dist/esm/native/FileUpload.native.js +310 -0
  38. package/dist/esm/native/Icons.native.js +51 -0
  39. package/dist/esm/native/ImagesSkeleton.native.js +45 -0
  40. package/dist/esm/native/MediaGallery.native.js +228 -0
  41. package/dist/esm/native/MediaPopup.native.js +170 -0
  42. package/dist/esm/native/MediaTab.native.js +192 -0
  43. package/dist/esm/native/Pagination.native.js +210 -0
  44. package/dist/esm/native/THEME_EXAMPLE.js +112 -0
  45. package/dist/esm/native/VideosGallery.native.js +240 -0
  46. package/dist/esm/native/theme.js +167 -0
  47. package/dist/esm/services/apiService.js +1 -372
  48. package/dist/esm/web/FileUpload.web.js +253 -0
  49. package/dist/esm/web/Icons.web.js +32 -0
  50. package/dist/esm/web/ImagesSkeleton.web.js +14 -0
  51. package/dist/esm/web/MediaGallery.web.js +144 -0
  52. package/dist/esm/web/MediaPopup.web.js +97 -0
  53. package/dist/esm/web/MediaTab.web.js +177 -0
  54. package/dist/esm/web/Pagination.web.js +134 -0
  55. package/dist/esm/web/VideosGallery.web.js +144 -0
  56. package/dist/index.js +16 -2
  57. package/dist/native/FileUpload.native.js +316 -0
  58. package/dist/native/Icons.native.js +59 -0
  59. package/dist/native/ImagesSkeleton.native.js +52 -0
  60. package/dist/native/MediaGallery.native.js +237 -0
  61. package/dist/native/MediaPopup.native.js +177 -0
  62. package/dist/native/MediaTab.native.js +201 -0
  63. package/dist/native/Pagination.native.js +217 -0
  64. package/dist/native/THEME_EXAMPLE.js +117 -0
  65. package/dist/native/VideosGallery.native.js +248 -0
  66. package/dist/native/theme.js +173 -0
  67. package/dist/services/apiService.js +2 -372
  68. package/dist/web/FileUpload.web.js +259 -0
  69. package/dist/web/Icons.web.js +39 -0
  70. package/dist/web/ImagesSkeleton.web.js +21 -0
  71. package/dist/web/MediaGallery.web.js +153 -0
  72. package/dist/web/MediaPopup.web.js +104 -0
  73. package/dist/web/MediaTab.web.js +186 -0
  74. package/dist/web/Pagination.web.js +141 -0
  75. package/dist/web/VideosGallery.web.js +153 -0
  76. package/package.json +3 -2
@@ -0,0 +1,310 @@
1
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
2
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
3
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
4
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
5
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
6
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
7
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
8
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
9
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
11
+ import React, { useState } from "react";
12
+ import { View, Text, TouchableOpacity, StyleSheet, Alert, ActivityIndicator } from "react-native";
13
+ import { CameraIcon } from "./Icons.native";
14
+ import { defaultTheme } from "./theme";
15
+
16
+ /**
17
+ * FileUpload component for React Native
18
+ *
19
+ * USAGE EXAMPLES:
20
+ *
21
+ * 1. Using react-native-image-picker:
22
+ * import { launchImageLibrary } from 'react-native-image-picker'
23
+ *
24
+ * <MediaPopup
25
+ * picker={(options) => {
26
+ * return new Promise((resolve) => {
27
+ * launchImageLibrary(options, (response) => {
28
+ * resolve(response.assets || [])
29
+ * })
30
+ * })
31
+ * }}
32
+ * ...
33
+ * />
34
+ *
35
+ * 2. Using expo-image-picker:
36
+ * import * as ImagePicker from 'expo-image-picker'
37
+ *
38
+ * <MediaPopup
39
+ * picker={async (options) => {
40
+ * const result = await ImagePicker.launchImageLibraryAsync({
41
+ * mediaTypes: options.mediaType === 'photo' ? ImagePicker.MediaTypeOptions.Images
42
+ * : options.mediaType === 'video' ? ImagePicker.MediaTypeOptions.Videos
43
+ * : ImagePicker.MediaTypeOptions.All,
44
+ * allowsMultipleSelection: options.allowsMultiple,
45
+ * quality: options.quality,
46
+ * })
47
+ * return result.assets || []
48
+ * }}
49
+ * ...
50
+ * />
51
+ *
52
+ * 3. Custom picker options:
53
+ * <MediaPopup
54
+ * picker={...}
55
+ * pickerOptions={(accept) => ({
56
+ * mediaType: accept?.includes('image') ? 'photo' : 'video',
57
+ * quality: 0.9,
58
+ * allowsMultiple: true,
59
+ * // Add any other options your picker library supports
60
+ * })}
61
+ * ...
62
+ * />
63
+ *
64
+ * @param {Function} picker - REQUIRED: Your file picker function
65
+ * Should accept options and return a promise that resolves with an array of file objects
66
+ * Each file object should have: { uri, type/mimeType, fileName/name }
67
+ *
68
+ * @param {Function} pickerOptions - Optional: Function to generate picker options based on accept type
69
+ * Default: { mediaType: 'photo' | 'video' | 'mixed', quality: 0.8, allowsMultiple: true }
70
+ */
71
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
72
+ var FileUpload = function FileUpload(_ref) {
73
+ var loadMedia = _ref.loadMedia,
74
+ accept = _ref.accept,
75
+ title = _ref.title,
76
+ apiService = _ref.apiService,
77
+ onUploadStart = _ref.onUploadStart,
78
+ onUploadComplete = _ref.onUploadComplete,
79
+ onUploadError = _ref.onUploadError,
80
+ picker = _ref.picker,
81
+ pickerOptions = _ref.pickerOptions,
82
+ _ref$theme = _ref.theme,
83
+ theme = _ref$theme === void 0 ? defaultTheme : _ref$theme,
84
+ containerStyle = _ref.containerStyle,
85
+ buttonStyle = _ref.buttonStyle,
86
+ iconContainerStyle = _ref.iconContainerStyle,
87
+ titleStyle = _ref.titleStyle,
88
+ loadingStyle = _ref.loadingStyle;
89
+ var _useState = useState(false),
90
+ _useState2 = _slicedToArray(_useState, 2),
91
+ isLoading = _useState2[0],
92
+ setISLoading = _useState2[1];
93
+ var _useState3 = useState(0),
94
+ _useState4 = _slicedToArray(_useState3, 2),
95
+ uploadProgress = _useState4[0],
96
+ setUploadProgress = _useState4[1];
97
+
98
+ // Convert file picker result to File-like object for apiService
99
+ var convertToFile = function convertToFile(pickerResult) {
100
+ // Picker typically returns: { uri, type, fileName, fileSize, width, height }
101
+ // We need to create a File-like object that apiService.uploadMedia expects
102
+ // For React Native, we'll use the URI directly and let uploadMedia handle it
103
+
104
+ return {
105
+ uri: pickerResult.uri,
106
+ name: pickerResult.fileName || pickerResult.uri.split("/").pop() || "image.jpg",
107
+ type: pickerResult.type || pickerResult.mimeType || "image/jpeg",
108
+ // Keep original picker result for potential use
109
+ _pickerResult: pickerResult
110
+ };
111
+ };
112
+ var uploadFiles = /*#__PURE__*/function () {
113
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fileList) {
114
+ var filesToUpload, uploadedUrls, _t;
115
+ return _regenerator().w(function (_context) {
116
+ while (1) switch (_context.p = _context.n) {
117
+ case 0:
118
+ if (onUploadStart) {
119
+ onUploadStart(fileList);
120
+ }
121
+ setISLoading(true);
122
+ setUploadProgress(0);
123
+ _context.p = 1;
124
+ // Convert picker results to File-like objects
125
+ filesToUpload = fileList.map(convertToFile); // Use the API service to upload files
126
+ // Note: uploadMedia will need to handle React Native file URIs
127
+ _context.n = 2;
128
+ return apiService.uploadMedia(filesToUpload, apiService.authKey);
129
+ case 2:
130
+ uploadedUrls = _context.v;
131
+ if (onUploadComplete) {
132
+ onUploadComplete(uploadedUrls);
133
+ }
134
+ setUploadProgress(0);
135
+ if (loadMedia) {
136
+ loadMedia();
137
+ }
138
+ _context.n = 4;
139
+ break;
140
+ case 3:
141
+ _context.p = 3;
142
+ _t = _context.v;
143
+ console.error("Upload error:", _t);
144
+ if (onUploadError) {
145
+ onUploadError(_t);
146
+ }
147
+ Alert.alert("Upload Error", _t.message || "Failed to upload file");
148
+ case 4:
149
+ _context.p = 4;
150
+ setISLoading(false);
151
+ return _context.f(4);
152
+ case 5:
153
+ return _context.a(2);
154
+ }
155
+ }, _callee, null, [[1, 3, 4, 5]]);
156
+ }));
157
+ return function uploadFiles(_x) {
158
+ return _ref2.apply(this, arguments);
159
+ };
160
+ }();
161
+ var handlePickFile = /*#__PURE__*/function () {
162
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2() {
163
+ var options, isImage, isVideo, result, assets, _error$message, _t2;
164
+ return _regenerator().w(function (_context2) {
165
+ while (1) switch (_context2.p = _context2.n) {
166
+ case 0:
167
+ if (picker) {
168
+ _context2.n = 1;
169
+ break;
170
+ }
171
+ Alert.alert("File Picker Not Configured", "Please provide a picker function prop. See FileUpload.native.jsx documentation for examples.", [{
172
+ text: "OK"
173
+ }]);
174
+ return _context2.a(2);
175
+ case 1:
176
+ _context2.p = 1;
177
+ // Generate picker options based on accept type
178
+
179
+ if (pickerOptions && typeof pickerOptions === "function") {
180
+ options = pickerOptions(accept);
181
+ } else {
182
+ // Default options
183
+ isImage = accept === null || accept === void 0 ? void 0 : accept.includes("image");
184
+ isVideo = accept === null || accept === void 0 ? void 0 : accept.includes("video");
185
+ options = {
186
+ mediaType: isImage ? "photo" : isVideo ? "video" : "mixed",
187
+ quality: 0.8,
188
+ allowsMultiple: true
189
+ };
190
+ }
191
+
192
+ // Call the picker function provided by the app
193
+ _context2.n = 2;
194
+ return picker(options);
195
+ case 2:
196
+ result = _context2.v;
197
+ // Handle different picker response formats
198
+ // react-native-image-picker: { assets: [...] }
199
+ // expo-image-picker: { assets: [...] }
200
+ // Custom: could be array directly or { assets: [...] }
201
+ assets = Array.isArray(result) ? result : (result === null || result === void 0 ? void 0 : result.assets) || result || [];
202
+ if (!(assets && assets.length > 0)) {
203
+ _context2.n = 3;
204
+ break;
205
+ }
206
+ _context2.n = 3;
207
+ return uploadFiles(assets);
208
+ case 3:
209
+ _context2.n = 6;
210
+ break;
211
+ case 4:
212
+ _context2.p = 4;
213
+ _t2 = _context2.v;
214
+ console.error("Error picking file:", _t2);
215
+ if (!(_t2.code === "E_PICKER_CANCELLED" || (_error$message = _t2.message) !== null && _error$message !== void 0 && _error$message.includes("cancel"))) {
216
+ _context2.n = 5;
217
+ break;
218
+ }
219
+ return _context2.a(2);
220
+ case 5:
221
+ Alert.alert("Error", _t2.message || "Failed to pick file");
222
+ case 6:
223
+ return _context2.a(2);
224
+ }
225
+ }, _callee2, null, [[1, 4]]);
226
+ }));
227
+ return function handlePickFile() {
228
+ return _ref3.apply(this, arguments);
229
+ };
230
+ }();
231
+ if (isLoading) {
232
+ return /*#__PURE__*/_jsxs(View, {
233
+ style: [styles.loadingContainer, {
234
+ backgroundColor: theme.colors.loadingBackground,
235
+ borderRadius: theme.radius.md
236
+ }, loadingStyle],
237
+ children: [/*#__PURE__*/_jsx(ActivityIndicator, {
238
+ size: "small",
239
+ color: theme.colors.primary
240
+ }), /*#__PURE__*/_jsx(Text, {
241
+ style: [styles.loadingText, {
242
+ color: theme.colors.loadingText,
243
+ marginTop: theme.spacing.sm
244
+ }],
245
+ children: "Uploading..."
246
+ })]
247
+ });
248
+ }
249
+ return /*#__PURE__*/_jsx(View, {
250
+ style: [styles.container, containerStyle],
251
+ children: /*#__PURE__*/_jsxs(TouchableOpacity, {
252
+ onPress: handlePickFile,
253
+ style: [styles.button, {
254
+ borderColor: theme.colors.uploadBorder,
255
+ backgroundColor: theme.colors.uploadBackground,
256
+ borderRadius: theme.radius.md
257
+ }, buttonStyle],
258
+ disabled: isLoading,
259
+ children: [/*#__PURE__*/_jsx(View, {
260
+ style: [styles.iconContainer, {
261
+ backgroundColor: theme.colors.uploadIconBackground,
262
+ borderRadius: theme.radius.xl,
263
+ marginBottom: theme.spacing.sm,
264
+ padding: theme.spacing.md
265
+ }, iconContainerStyle],
266
+ children: /*#__PURE__*/_jsx(CameraIcon, {})
267
+ }), /*#__PURE__*/_jsx(Text, {
268
+ style: [styles.title, {
269
+ color: theme.colors.uploadText,
270
+ marginTop: theme.spacing.sm,
271
+ fontSize: theme.typography.caption.fontSize
272
+ }, titleStyle],
273
+ children: title
274
+ })]
275
+ })
276
+ });
277
+ };
278
+ var styles = StyleSheet.create({
279
+ container: {
280
+ width: "100%",
281
+ height: 160
282
+ },
283
+ button: {
284
+ width: "100%",
285
+ height: "100%",
286
+ flexDirection: "column",
287
+ justifyContent: "center",
288
+ alignItems: "center",
289
+ borderWidth: 1,
290
+ borderStyle: "dashed"
291
+ // Colors applied via theme
292
+ },
293
+ iconContainer: {
294
+ // Colors and spacing applied via theme
295
+ },
296
+ title: {
297
+ // Colors and typography applied via theme
298
+ },
299
+ loadingContainer: {
300
+ width: "100%",
301
+ height: 160,
302
+ justifyContent: "center",
303
+ alignItems: "center"
304
+ // Colors applied via theme
305
+ },
306
+ loadingText: {
307
+ // Colors applied via theme
308
+ }
309
+ });
310
+ export default FileUpload;
@@ -0,0 +1,51 @@
1
+ import React from 'react';
2
+ import { View, Text, StyleSheet } from 'react-native';
3
+ // Note: For better icons, you can use react-native-svg or react-native-vector-icons
4
+ // This is a simple implementation using Text/View
5
+ import { jsx as _jsx } from "react/jsx-runtime";
6
+ export var CloseIcon = function CloseIcon(_ref) {
7
+ var _ref$size = _ref.size,
8
+ size = _ref$size === void 0 ? 32 : _ref$size,
9
+ _ref$color = _ref.color,
10
+ color = _ref$color === void 0 ? '#000000' : _ref$color;
11
+ return /*#__PURE__*/_jsx(View, {
12
+ style: [styles.closeIcon, {
13
+ width: size,
14
+ height: size
15
+ }],
16
+ children: /*#__PURE__*/_jsx(Text, {
17
+ style: [styles.closeIconText, {
18
+ color: color,
19
+ fontSize: size * 0.6
20
+ }],
21
+ children: "\u2715"
22
+ })
23
+ });
24
+ };
25
+ export var CameraIcon = function CameraIcon() {
26
+ return /*#__PURE__*/_jsx(View, {
27
+ style: styles.cameraIcon,
28
+ children: /*#__PURE__*/_jsx(Text, {
29
+ style: styles.cameraIconText,
30
+ children: "\uD83D\uDCF7"
31
+ })
32
+ });
33
+ };
34
+ var styles = StyleSheet.create({
35
+ closeIcon: {
36
+ justifyContent: 'center',
37
+ alignItems: 'center'
38
+ },
39
+ closeIconText: {
40
+ fontWeight: 'bold'
41
+ },
42
+ cameraIcon: {
43
+ width: 22,
44
+ height: 18,
45
+ justifyContent: 'center',
46
+ alignItems: 'center'
47
+ },
48
+ cameraIconText: {
49
+ fontSize: 18
50
+ }
51
+ });
@@ -0,0 +1,45 @@
1
+ import React from 'react';
2
+ import { View, StyleSheet, Dimensions, ActivityIndicator } from 'react-native';
3
+ import { jsx as _jsx } from "react/jsx-runtime";
4
+ var _Dimensions$get = Dimensions.get('window'),
5
+ SCREEN_WIDTH = _Dimensions$get.width;
6
+ var NUM_COLUMNS = 3;
7
+ var ITEM_MARGIN = 8;
8
+ var ITEM_SIZE = (SCREEN_WIDTH - 40 - ITEM_MARGIN * (NUM_COLUMNS - 1) * 2) / NUM_COLUMNS;
9
+ var ImagesSkeleton = function ImagesSkeleton(_ref) {
10
+ var _ref$per_page = _ref.per_page,
11
+ per_page = _ref$per_page === void 0 ? 30 : _ref$per_page;
12
+ var skeletonItems = [];
13
+ for (var i = 0; i < per_page; i++) {
14
+ skeletonItems.push(/*#__PURE__*/_jsx(View, {
15
+ style: [styles.skeletonItem, {
16
+ width: ITEM_SIZE,
17
+ height: ITEM_SIZE,
18
+ margin: ITEM_MARGIN
19
+ }],
20
+ children: /*#__PURE__*/_jsx(ActivityIndicator, {
21
+ size: "small",
22
+ color: "#3B3269"
23
+ })
24
+ }, i));
25
+ }
26
+ return /*#__PURE__*/_jsx(View, {
27
+ style: styles.container,
28
+ children: skeletonItems
29
+ });
30
+ };
31
+ var styles = StyleSheet.create({
32
+ container: {
33
+ flexDirection: 'row',
34
+ flexWrap: 'wrap',
35
+ padding: 4
36
+ },
37
+ skeletonItem: {
38
+ backgroundColor: '#E5E5E5',
39
+ borderRadius: 8,
40
+ justifyContent: 'center',
41
+ alignItems: 'center',
42
+ opacity: 0.3
43
+ }
44
+ });
45
+ export default ImagesSkeleton;
@@ -0,0 +1,228 @@
1
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
4
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
5
+ function _regenerator() { /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/babel/babel/blob/main/packages/babel-helpers/LICENSE */ var e, t, r = "function" == typeof Symbol ? Symbol : {}, n = r.iterator || "@@iterator", o = r.toStringTag || "@@toStringTag"; function i(r, n, o, i) { var c = n && n.prototype instanceof Generator ? n : Generator, u = Object.create(c.prototype); return _regeneratorDefine2(u, "_invoke", function (r, n, o) { var i, c, u, f = 0, p = o || [], y = !1, G = { p: 0, n: 0, v: e, a: d, f: d.bind(e, 4), d: function d(t, r) { return i = t, c = 0, u = e, G.n = r, a; } }; function d(r, n) { for (c = r, u = n, t = 0; !y && f && !o && t < p.length; t++) { var o, i = p[t], d = G.p, l = i[2]; r > 3 ? (o = l === n) && (u = i[(c = i[4]) ? 5 : (c = 3, 3)], i[4] = i[5] = e) : i[0] <= d && ((o = r < 2 && d < i[1]) ? (c = 0, G.v = n, G.n = i[1]) : d < l && (o = r < 3 || i[0] > n || n > l) && (i[4] = r, i[5] = n, G.n = l, c = 0)); } if (o || r > 1) return a; throw y = !0, n; } return function (o, p, l) { if (f > 1) throw TypeError("Generator is already running"); for (y && 1 === p && d(p, l), c = p, u = l; (t = c < 2 ? e : u) || !y;) { i || (c ? c < 3 ? (c > 1 && (G.n = -1), d(c, u)) : G.n = u : G.v = u); try { if (f = 2, i) { if (c || (o = "next"), t = i[o]) { if (!(t = t.call(i, u))) throw TypeError("iterator result is not an object"); if (!t.done) return t; u = t.value, c < 2 && (c = 0); } else 1 === c && (t = i.return) && t.call(i), c < 2 && (u = TypeError("The iterator does not provide a '" + o + "' method"), c = 1); i = e; } else if ((t = (y = G.n < 0) ? u : r.call(n, G)) !== a) break; } catch (t) { i = e, c = 1, u = t; } finally { f = 1; } } return { value: t, done: y }; }; }(r, o, i), !0), u; } var a = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} t = Object.getPrototypeOf; var c = [][n] ? t(t([][n]())) : (_regeneratorDefine2(t = {}, n, function () { return this; }), t), u = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(c); function f(e) { return Object.setPrototypeOf ? Object.setPrototypeOf(e, GeneratorFunctionPrototype) : (e.__proto__ = GeneratorFunctionPrototype, _regeneratorDefine2(e, o, "GeneratorFunction")), e.prototype = Object.create(u), e; } return GeneratorFunction.prototype = GeneratorFunctionPrototype, _regeneratorDefine2(u, "constructor", GeneratorFunctionPrototype), _regeneratorDefine2(GeneratorFunctionPrototype, "constructor", GeneratorFunction), GeneratorFunction.displayName = "GeneratorFunction", _regeneratorDefine2(GeneratorFunctionPrototype, o, "GeneratorFunction"), _regeneratorDefine2(u), _regeneratorDefine2(u, o, "Generator"), _regeneratorDefine2(u, n, function () { return this; }), _regeneratorDefine2(u, "toString", function () { return "[object Generator]"; }), (_regenerator = function _regenerator() { return { w: i, m: f }; })(); }
6
+ function _regeneratorDefine2(e, r, n, t) { var i = Object.defineProperty; try { i({}, "", {}); } catch (e) { i = 0; } _regeneratorDefine2 = function _regeneratorDefine(e, r, n, t) { function o(r, n) { _regeneratorDefine2(e, r, function (e) { return this._invoke(r, n, e); }); } r ? i ? i(e, r, { value: n, enumerable: !t, configurable: !t, writable: !t }) : e[r] = n : (o("next", 0), o("throw", 1), o("return", 2)); }, _regeneratorDefine2(e, r, n, t); }
7
+ function asyncGeneratorStep(n, t, e, r, o, a, c) { try { var i = n[a](c), u = i.value; } catch (n) { return void e(n); } i.done ? t(u) : Promise.resolve(u).then(r, o); }
8
+ function _asyncToGenerator(n) { return function () { var t = this, e = arguments; return new Promise(function (r, o) { var a = n.apply(t, e); function _next(n) { asyncGeneratorStep(a, r, o, _next, _throw, "next", n); } function _throw(n) { asyncGeneratorStep(a, r, o, _next, _throw, "throw", n); } _next(void 0); }); }; }
9
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
14
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
15
+ import React, { useState, useEffect } from 'react';
16
+ import { View, FlatList, Image, TouchableOpacity, StyleSheet, Dimensions } from 'react-native';
17
+ import FileUpload from './FileUpload.native';
18
+ import ImagesSkeleton from './ImagesSkeleton.native';
19
+ import Pagination from './Pagination.native';
20
+ import { defaultTheme } from './theme';
21
+ import { jsx as _jsx } from "react/jsx-runtime";
22
+ var _Dimensions$get = Dimensions.get('window'),
23
+ SCREEN_WIDTH = _Dimensions$get.width;
24
+ var NUM_COLUMNS = 3;
25
+ var ITEM_MARGIN = 8;
26
+ var ITEM_SIZE = (SCREEN_WIDTH - 40 - ITEM_MARGIN * (NUM_COLUMNS - 1) * 2) / NUM_COLUMNS; // 40 = padding, adjust for margins
27
+
28
+ var IMAGE_MIME_TYPES = ['image/png', 'image/jpeg', 'image/webp', 'image/svg+xml', 'image/gif', 'image/avif', 'image/x-icon', 'image/vnd.microsoft.icon', 'image/heic', 'image/heif'];
29
+ var ImagesGallery = function ImagesGallery(_ref) {
30
+ var update_data = _ref.update_data,
31
+ closePopup = _ref.closePopup,
32
+ apiService = _ref.apiService,
33
+ onError = _ref.onError,
34
+ picker = _ref.picker,
35
+ pickerOptions = _ref.pickerOptions,
36
+ _ref$theme = _ref.theme,
37
+ theme = _ref$theme === void 0 ? defaultTheme : _ref$theme,
38
+ containerStyle = _ref.containerStyle,
39
+ gridStyle = _ref.gridStyle,
40
+ imageItemStyle = _ref.imageItemStyle,
41
+ paginationContainerStyle = _ref.paginationContainerStyle;
42
+ var _useState = useState([]),
43
+ _useState2 = _slicedToArray(_useState, 2),
44
+ images = _useState2[0],
45
+ setImages = _useState2[1];
46
+ var _useState3 = useState(0),
47
+ _useState4 = _slicedToArray(_useState3, 2),
48
+ total_count = _useState4[0],
49
+ setTotalCount = _useState4[1];
50
+ var _useState5 = useState(1),
51
+ _useState6 = _slicedToArray(_useState5, 2),
52
+ currentPage = _useState6[0],
53
+ setCurrentPage = _useState6[1];
54
+ var _useState7 = useState(false),
55
+ _useState8 = _slicedToArray(_useState7, 2),
56
+ isLoading = _useState8[0],
57
+ setISLoading = _useState8[1];
58
+
59
+ // Fetch images
60
+ useEffect(function () {
61
+ loadMedia();
62
+ }, []);
63
+ var loadMedia = /*#__PURE__*/function () {
64
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
65
+ var page_number,
66
+ _response$data,
67
+ _response$data2,
68
+ response,
69
+ mediaData,
70
+ count,
71
+ _args = arguments,
72
+ _t;
73
+ return _regenerator().w(function (_context) {
74
+ while (1) switch (_context.p = _context.n) {
75
+ case 0:
76
+ page_number = _args.length > 0 && _args[0] !== undefined ? _args[0] : 1;
77
+ _context.p = 1;
78
+ _context.n = 2;
79
+ return apiService.fetchMedia({
80
+ mimeTypes: IMAGE_MIME_TYPES,
81
+ page: page_number,
82
+ setISLoading: setISLoading,
83
+ isLoading: isLoading
84
+ });
85
+ case 2:
86
+ response = _context.v;
87
+ // Handle different response formats
88
+ mediaData = (response === null || response === void 0 ? void 0 : response.media) || (response === null || response === void 0 || (_response$data = response.data) === null || _response$data === void 0 ? void 0 : _response$data.media) || (response === null || response === void 0 ? void 0 : response.data) || response || [];
89
+ count = (response === null || response === void 0 ? void 0 : response.count) || (response === null || response === void 0 || (_response$data2 = response.data) === null || _response$data2 === void 0 ? void 0 : _response$data2.count) || (response === null || response === void 0 ? void 0 : response.total) || 0;
90
+ setImages(Array.isArray(mediaData) ? mediaData : []);
91
+ setTotalCount(count);
92
+ setCurrentPage(page_number);
93
+ _context.n = 4;
94
+ break;
95
+ case 3:
96
+ _context.p = 3;
97
+ _t = _context.v;
98
+ console.error('Error loading media:', _t);
99
+ if (onError) {
100
+ onError(_t);
101
+ }
102
+ case 4:
103
+ return _context.a(2);
104
+ }
105
+ }, _callee, null, [[1, 3]]);
106
+ }));
107
+ return function loadMedia() {
108
+ return _ref2.apply(this, arguments);
109
+ };
110
+ }();
111
+ var handleImageClick = function handleImageClick(image) {
112
+ if (update_data) {
113
+ update_data(image.url || image);
114
+ }
115
+ if (closePopup) {
116
+ closePopup();
117
+ }
118
+ };
119
+ var renderItem = function renderItem(_ref3) {
120
+ var item = _ref3.item,
121
+ index = _ref3.index;
122
+ // First item is the upload button
123
+ if (index === 0) {
124
+ return /*#__PURE__*/_jsx(View, {
125
+ style: [styles.uploadContainer, {
126
+ width: ITEM_SIZE,
127
+ height: ITEM_SIZE
128
+ }],
129
+ children: /*#__PURE__*/_jsx(FileUpload, {
130
+ loadMedia: loadMedia,
131
+ accept: "image/*",
132
+ title: "Add Image",
133
+ apiService: apiService,
134
+ onUploadError: onError,
135
+ picker: picker,
136
+ pickerOptions: pickerOptions,
137
+ theme: theme
138
+ })
139
+ });
140
+ }
141
+ var image = images[index - 1];
142
+ var imageUrl = typeof image === 'string' ? image : image.url;
143
+ var imageKey = image.id || image.url || index;
144
+ return /*#__PURE__*/_jsx(TouchableOpacity, {
145
+ onPress: function onPress() {
146
+ return handleImageClick(image);
147
+ },
148
+ style: [styles.imageItem, {
149
+ width: ITEM_SIZE,
150
+ height: ITEM_SIZE,
151
+ backgroundColor: theme.colors.itemBackground,
152
+ shadowColor: theme.colors.itemShadow
153
+ }, imageItemStyle],
154
+ children: /*#__PURE__*/_jsx(Image, {
155
+ source: {
156
+ uri: imageUrl
157
+ },
158
+ style: styles.image,
159
+ resizeMode: "cover"
160
+ })
161
+ });
162
+ };
163
+ var data = isLoading ? [] : [{
164
+ type: 'upload'
165
+ }].concat(_toConsumableArray(images));
166
+ return /*#__PURE__*/_jsx(View, {
167
+ style: [styles.container, containerStyle],
168
+ children: isLoading ? /*#__PURE__*/_jsx(ImagesSkeleton, {}) : /*#__PURE__*/_jsx(FlatList, {
169
+ data: data,
170
+ renderItem: renderItem,
171
+ keyExtractor: function keyExtractor(item, index) {
172
+ if (index === 0) return 'upload';
173
+ var image = images[index - 1];
174
+ return image.id || image.url || "image-".concat(index);
175
+ },
176
+ numColumns: NUM_COLUMNS,
177
+ contentContainerStyle: [styles.grid, gridStyle],
178
+ showsVerticalScrollIndicator: false,
179
+ ListFooterComponent: total_count > 0 ? /*#__PURE__*/_jsx(View, {
180
+ style: [styles.paginationContainer, {
181
+ backgroundColor: theme.colors.paginationBackground,
182
+ paddingVertical: theme.spacing.lg,
183
+ paddingHorizontal: theme.spacing.sm,
184
+ marginTop: theme.spacing.sm
185
+ }, paginationContainerStyle],
186
+ children: /*#__PURE__*/_jsx(Pagination, {
187
+ nextPage: function nextPage(value) {
188
+ return loadMedia(value);
189
+ },
190
+ pageCount: Math.ceil(total_count / 30),
191
+ current_page: currentPage,
192
+ theme: theme
193
+ })
194
+ }) : null
195
+ })
196
+ });
197
+ };
198
+ var styles = StyleSheet.create({
199
+ container: {
200
+ flex: 1
201
+ },
202
+ grid: {
203
+ padding: 4
204
+ },
205
+ uploadContainer: {
206
+ margin: ITEM_MARGIN
207
+ },
208
+ imageItem: {
209
+ margin: ITEM_MARGIN,
210
+ borderRadius: 8,
211
+ overflow: 'hidden',
212
+ shadowOffset: {
213
+ width: 0,
214
+ height: 2
215
+ },
216
+ shadowOpacity: 0.1,
217
+ shadowRadius: 3.84,
218
+ elevation: 5
219
+ },
220
+ image: {
221
+ width: '100%',
222
+ height: '100%'
223
+ },
224
+ paginationContainer: {
225
+ // Styles applied via theme
226
+ }
227
+ });
228
+ export default ImagesGallery;