@tradly/asset 1.0.24 → 1.0.26

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.
@@ -298,7 +298,13 @@ var MediaApiService = /*#__PURE__*/function () {
298
298
  name: file.name.replace(/\s/g, "-"),
299
299
  type: file.type
300
300
  };
301
- }); // Prepare headers
301
+ });
302
+ console.log("fileData", {
303
+ files: files,
304
+ fileData: fileData
305
+ });
306
+
307
+ // Prepare headers
302
308
  headers = {
303
309
  "Content-Type": "application/json",
304
310
  "X-Auth-Key": auth_key // Capital X for Tradly API
@@ -394,15 +400,10 @@ var MediaApiService = /*#__PURE__*/function () {
394
400
  break;
395
401
  }
396
402
  _context5.p = 3;
397
- console.log("upload_full_files", upload_full_files);
398
- // Step 1: Get signed URLs from API
399
403
  _context5.n = 4;
400
404
  return this.getS3SignedUrls(upload_full_files, auth_key);
401
405
  case 4:
402
406
  responseFiles = _context5.v;
403
- console.log("responseFiles", responseFiles);
404
-
405
- // Step 2: Upload each file to S3
406
407
  index = 0;
407
408
  case 5:
408
409
  if (!(index < responseFiles.length)) {
@@ -292,7 +292,13 @@ var MediaApiService = /*#__PURE__*/function () {
292
292
  name: file.name.replace(/\s/g, "-"),
293
293
  type: file.type
294
294
  };
295
- }); // Prepare headers
295
+ });
296
+ console.log("fileData", {
297
+ files: files,
298
+ fileData: fileData
299
+ });
300
+
301
+ // Prepare headers
296
302
  headers = {
297
303
  "Content-Type": "application/json",
298
304
  "X-Auth-Key": auth_key // Capital X for Tradly API
@@ -388,15 +394,10 @@ var MediaApiService = /*#__PURE__*/function () {
388
394
  break;
389
395
  }
390
396
  _context5.p = 3;
391
- console.log("upload_full_files", upload_full_files);
392
- // Step 1: Get signed URLs from API
393
397
  _context5.n = 4;
394
398
  return this.getS3SignedUrls(upload_full_files, auth_key);
395
399
  case 4:
396
400
  responseFiles = _context5.v;
397
- console.log("responseFiles", responseFiles);
398
-
399
- // Step 2: Upload each file to S3
400
401
  index = 0;
401
402
  case 5:
402
403
  if (!(index < responseFiles.length)) {
@@ -153,24 +153,109 @@ var FileUpload = function FileUpload(_ref) {
153
153
  }
154
154
 
155
155
  // Extract MIME type (handle different property names)
156
- // Use a helper function to determine MIME type from filename if needed
157
- var getMimeType = function getMimeType(name, fallbackType) {
156
+ // Use a comprehensive helper function to determine MIME type from filename
157
+ var getMimeTypeFromFileName = function getMimeTypeFromFileName(name) {
158
158
  var _name$split$pop;
159
- if (fallbackType) return fallbackType;
160
- var ext = (_name$split$pop = name.split(".").pop()) === null || _name$split$pop === void 0 ? void 0 : _name$split$pop.toLowerCase();
159
+ if (!name) return "application/octet-stream";
160
+ var ext = (_name$split$pop = name.split(".").pop()) === null || _name$split$pop === void 0 ? void 0 : _name$split$pop.toLowerCase().trim();
161
+ if (!ext) return "application/octet-stream";
162
+
163
+ // Comprehensive MIME type mapping
161
164
  var mimeMap = {
165
+ // Images
162
166
  jpg: "image/jpeg",
163
167
  jpeg: "image/jpeg",
164
168
  png: "image/png",
165
169
  gif: "image/gif",
166
170
  webp: "image/webp",
171
+ svg: "image/svg+xml",
172
+ bmp: "image/bmp",
173
+ ico: "image/x-icon",
174
+ heic: "image/heic",
175
+ heif: "image/heif",
176
+ tiff: "image/tiff",
177
+ tif: "image/tiff",
178
+ jfif: "image/jpeg",
179
+ avif: "image/avif",
180
+ // Videos
167
181
  mp4: "video/mp4",
168
182
  mov: "video/quicktime",
169
- mp3: "audio/mpeg"
183
+ avi: "video/x-msvideo",
184
+ wmv: "video/x-ms-wmv",
185
+ flv: "video/x-flv",
186
+ mkv: "video/x-matroska",
187
+ webm: "video/webm",
188
+ mpeg: "video/mpeg",
189
+ mpg: "video/mpeg",
190
+ m4v: "video/x-m4v",
191
+ "3gp": "video/3gpp",
192
+ // Audio
193
+ mp3: "audio/mpeg",
194
+ wav: "audio/wav",
195
+ ogg: "audio/ogg",
196
+ m4a: "audio/mp4",
197
+ aac: "audio/aac",
198
+ flac: "audio/flac",
199
+ // Documents
200
+ pdf: "application/pdf",
201
+ doc: "application/msword",
202
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
203
+ xls: "application/vnd.ms-excel",
204
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
205
+ ppt: "application/vnd.ms-powerpoint",
206
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
207
+ // Archives
208
+ zip: "application/zip",
209
+ rar: "application/rar",
210
+ "7z": "application/x-7z-compressed",
211
+ tar: "application/x-tar",
212
+ gz: "application/gzip",
213
+ // Text
214
+ txt: "text/plain",
215
+ html: "text/html",
216
+ htm: "text/html",
217
+ css: "text/css",
218
+ js: "text/javascript",
219
+ json: "application/json",
220
+ xml: "text/xml",
221
+ php: "application/x-php"
170
222
  };
171
- return mimeMap[ext] || "image/jpeg";
223
+ return mimeMap[ext] || "application/octet-stream";
172
224
  };
173
- var mimeType = pickerResult.mimeType || pickerResult.type || getMimeType(fileName, null);
225
+
226
+ // Get MIME type - prioritize picker result, then filename, then default
227
+ var mimeType = pickerResult.mimeType || pickerResult.type;
228
+
229
+ // Clean up MIME type if it exists but is malformed
230
+ if (mimeType) {
231
+ mimeType = mimeType.trim();
232
+ // If it doesn't have a slash, it's not a valid MIME type format
233
+ if (!mimeType.includes("/")) {
234
+ mimeType = null;
235
+ } else {
236
+ // Normalize: lowercase the type part but keep structure
237
+ // e.g., "IMAGE/JPEG" -> "image/jpeg", "Image/Jpeg" -> "image/jpeg"
238
+ var parts = mimeType.split("/");
239
+ if (parts.length === 2) {
240
+ mimeType = "".concat(parts[0].toLowerCase(), "/").concat(parts[1].toLowerCase());
241
+ }
242
+ }
243
+ }
244
+
245
+ // If MIME type is missing or invalid, detect from filename
246
+ if (!mimeType) {
247
+ mimeType = getMimeTypeFromFileName(fileName);
248
+ }
249
+
250
+ // Final validation - ensure MIME type is properly formatted
251
+ if (!mimeType || !mimeType.includes("/")) {
252
+ mimeType = "application/octet-stream";
253
+ }
254
+ console.log("mimeType", {
255
+ uri: uri,
256
+ name: fileName,
257
+ type: mimeType
258
+ });
174
259
  return {
175
260
  uri: uri,
176
261
  name: fileName,
@@ -1,24 +1,32 @@
1
1
  import React from "react";
2
- import { View, StyleSheet, Dimensions, ActivityIndicator } from "react-native";
2
+ import { View, StyleSheet, Dimensions, ActivityIndicator, FlatList } from "react-native";
3
3
  import { jsx as _jsx } from "react/jsx-runtime";
4
4
  var _Dimensions$get = Dimensions.get("window"),
5
5
  SCREEN_WIDTH = _Dimensions$get.width;
6
6
  var NUM_COLUMNS = 3;
7
7
  var ITEM_MARGIN = 4; // Match MediaGallery margin
8
- // Calculate item size accounting for:
8
+ // Calculate item size - must match MediaGallery exactly
9
9
  // - Container padding (md = 12px on each side = 24px total)
10
10
  // - Grid padding (2px on each side = 4px total)
11
- // - Item margins between items (4px * 2 gaps = 8px total)
12
- var CONTAINER_PADDING = 20; // paddingHorizontal md (12 * 2)
11
+ // - Item margins: (NUM_COLUMNS - 1) gaps between items
12
+ // Each gap = 2 * ITEM_MARGIN (left margin of right item + right margin of left item)
13
+ // Total: (3 - 1) * 2 * 4 = 16px
14
+ var CONTAINER_PADDING = 14; // paddingHorizontal md (12 * 2)
13
15
  var GRID_PADDING = 4; // padding 2 on each side (2 * 2)
14
- var TOTAL_MARGINS = ITEM_MARGIN * (NUM_COLUMNS - 1) * 2; // margins between items (4px * 2 gaps = 8px)
16
+ var TOTAL_MARGINS = ITEM_MARGIN * (NUM_COLUMNS - 1) * 2; // 4 * 2 * 2 = 16px
15
17
  var ITEM_SIZE = (SCREEN_WIDTH - CONTAINER_PADDING - GRID_PADDING - TOTAL_MARGINS) / NUM_COLUMNS;
16
18
  var ImagesSkeleton = function ImagesSkeleton(_ref) {
17
19
  var _ref$per_page = _ref.per_page,
18
- per_page = _ref$per_page === void 0 ? 30 : _ref$per_page;
19
- var skeletonItems = [];
20
- for (var i = 0; i < per_page; i++) {
21
- skeletonItems.push(/*#__PURE__*/_jsx(View, {
20
+ per_page = _ref$per_page === void 0 ? 20 : _ref$per_page;
21
+ var skeletonData = Array.from({
22
+ length: per_page
23
+ }, function (_, i) {
24
+ return {
25
+ id: i
26
+ };
27
+ });
28
+ var renderItem = function renderItem() {
29
+ return /*#__PURE__*/_jsx(View, {
22
30
  style: [styles.skeletonItem, {
23
31
  width: ITEM_SIZE,
24
32
  height: ITEM_SIZE,
@@ -28,17 +36,21 @@ var ImagesSkeleton = function ImagesSkeleton(_ref) {
28
36
  size: "small",
29
37
  color: "#3B3269"
30
38
  })
31
- }, i));
32
- }
33
- return /*#__PURE__*/_jsx(View, {
34
- style: styles.container,
35
- children: skeletonItems
39
+ });
40
+ };
41
+ return /*#__PURE__*/_jsx(FlatList, {
42
+ data: skeletonData,
43
+ renderItem: renderItem,
44
+ keyExtractor: function keyExtractor(item) {
45
+ return "skeleton-".concat(item.id);
46
+ },
47
+ numColumns: NUM_COLUMNS,
48
+ contentContainerStyle: styles.grid,
49
+ showsVerticalScrollIndicator: false
36
50
  });
37
51
  };
38
52
  var styles = StyleSheet.create({
39
- container: {
40
- flexDirection: "row",
41
- flexWrap: "wrap",
53
+ grid: {
42
54
  padding: 2 // Match MediaGallery grid padding
43
55
  },
44
56
  skeletonItem: {
@@ -158,24 +158,109 @@ var FileUpload = function FileUpload(_ref) {
158
158
  }
159
159
 
160
160
  // Extract MIME type (handle different property names)
161
- // Use a helper function to determine MIME type from filename if needed
162
- var getMimeType = function getMimeType(name, fallbackType) {
161
+ // Use a comprehensive helper function to determine MIME type from filename
162
+ var getMimeTypeFromFileName = function getMimeTypeFromFileName(name) {
163
163
  var _name$split$pop;
164
- if (fallbackType) return fallbackType;
165
- var ext = (_name$split$pop = name.split(".").pop()) === null || _name$split$pop === void 0 ? void 0 : _name$split$pop.toLowerCase();
164
+ if (!name) return "application/octet-stream";
165
+ var ext = (_name$split$pop = name.split(".").pop()) === null || _name$split$pop === void 0 ? void 0 : _name$split$pop.toLowerCase().trim();
166
+ if (!ext) return "application/octet-stream";
167
+
168
+ // Comprehensive MIME type mapping
166
169
  var mimeMap = {
170
+ // Images
167
171
  jpg: "image/jpeg",
168
172
  jpeg: "image/jpeg",
169
173
  png: "image/png",
170
174
  gif: "image/gif",
171
175
  webp: "image/webp",
176
+ svg: "image/svg+xml",
177
+ bmp: "image/bmp",
178
+ ico: "image/x-icon",
179
+ heic: "image/heic",
180
+ heif: "image/heif",
181
+ tiff: "image/tiff",
182
+ tif: "image/tiff",
183
+ jfif: "image/jpeg",
184
+ avif: "image/avif",
185
+ // Videos
172
186
  mp4: "video/mp4",
173
187
  mov: "video/quicktime",
174
- mp3: "audio/mpeg"
188
+ avi: "video/x-msvideo",
189
+ wmv: "video/x-ms-wmv",
190
+ flv: "video/x-flv",
191
+ mkv: "video/x-matroska",
192
+ webm: "video/webm",
193
+ mpeg: "video/mpeg",
194
+ mpg: "video/mpeg",
195
+ m4v: "video/x-m4v",
196
+ "3gp": "video/3gpp",
197
+ // Audio
198
+ mp3: "audio/mpeg",
199
+ wav: "audio/wav",
200
+ ogg: "audio/ogg",
201
+ m4a: "audio/mp4",
202
+ aac: "audio/aac",
203
+ flac: "audio/flac",
204
+ // Documents
205
+ pdf: "application/pdf",
206
+ doc: "application/msword",
207
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
208
+ xls: "application/vnd.ms-excel",
209
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
210
+ ppt: "application/vnd.ms-powerpoint",
211
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
212
+ // Archives
213
+ zip: "application/zip",
214
+ rar: "application/rar",
215
+ "7z": "application/x-7z-compressed",
216
+ tar: "application/x-tar",
217
+ gz: "application/gzip",
218
+ // Text
219
+ txt: "text/plain",
220
+ html: "text/html",
221
+ htm: "text/html",
222
+ css: "text/css",
223
+ js: "text/javascript",
224
+ json: "application/json",
225
+ xml: "text/xml",
226
+ php: "application/x-php"
175
227
  };
176
- return mimeMap[ext] || "image/jpeg";
228
+ return mimeMap[ext] || "application/octet-stream";
177
229
  };
178
- var mimeType = pickerResult.mimeType || pickerResult.type || getMimeType(fileName, null);
230
+
231
+ // Get MIME type - prioritize picker result, then filename, then default
232
+ var mimeType = pickerResult.mimeType || pickerResult.type;
233
+
234
+ // Clean up MIME type if it exists but is malformed
235
+ if (mimeType) {
236
+ mimeType = mimeType.trim();
237
+ // If it doesn't have a slash, it's not a valid MIME type format
238
+ if (!mimeType.includes("/")) {
239
+ mimeType = null;
240
+ } else {
241
+ // Normalize: lowercase the type part but keep structure
242
+ // e.g., "IMAGE/JPEG" -> "image/jpeg", "Image/Jpeg" -> "image/jpeg"
243
+ var parts = mimeType.split("/");
244
+ if (parts.length === 2) {
245
+ mimeType = "".concat(parts[0].toLowerCase(), "/").concat(parts[1].toLowerCase());
246
+ }
247
+ }
248
+ }
249
+
250
+ // If MIME type is missing or invalid, detect from filename
251
+ if (!mimeType) {
252
+ mimeType = getMimeTypeFromFileName(fileName);
253
+ }
254
+
255
+ // Final validation - ensure MIME type is properly formatted
256
+ if (!mimeType || !mimeType.includes("/")) {
257
+ mimeType = "application/octet-stream";
258
+ }
259
+ console.log("mimeType", {
260
+ uri: uri,
261
+ name: fileName,
262
+ type: mimeType
263
+ });
179
264
  return {
180
265
  uri: uri,
181
266
  name: fileName,
@@ -12,20 +12,28 @@ var _Dimensions$get = _reactNative.Dimensions.get("window"),
12
12
  SCREEN_WIDTH = _Dimensions$get.width;
13
13
  var NUM_COLUMNS = 3;
14
14
  var ITEM_MARGIN = 4; // Match MediaGallery margin
15
- // Calculate item size accounting for:
15
+ // Calculate item size - must match MediaGallery exactly
16
16
  // - Container padding (md = 12px on each side = 24px total)
17
17
  // - Grid padding (2px on each side = 4px total)
18
- // - Item margins between items (4px * 2 gaps = 8px total)
19
- var CONTAINER_PADDING = 20; // paddingHorizontal md (12 * 2)
18
+ // - Item margins: (NUM_COLUMNS - 1) gaps between items
19
+ // Each gap = 2 * ITEM_MARGIN (left margin of right item + right margin of left item)
20
+ // Total: (3 - 1) * 2 * 4 = 16px
21
+ var CONTAINER_PADDING = 14; // paddingHorizontal md (12 * 2)
20
22
  var GRID_PADDING = 4; // padding 2 on each side (2 * 2)
21
- var TOTAL_MARGINS = ITEM_MARGIN * (NUM_COLUMNS - 1) * 2; // margins between items (4px * 2 gaps = 8px)
23
+ var TOTAL_MARGINS = ITEM_MARGIN * (NUM_COLUMNS - 1) * 2; // 4 * 2 * 2 = 16px
22
24
  var ITEM_SIZE = (SCREEN_WIDTH - CONTAINER_PADDING - GRID_PADDING - TOTAL_MARGINS) / NUM_COLUMNS;
23
25
  var ImagesSkeleton = function ImagesSkeleton(_ref) {
24
26
  var _ref$per_page = _ref.per_page,
25
- per_page = _ref$per_page === void 0 ? 30 : _ref$per_page;
26
- var skeletonItems = [];
27
- for (var i = 0; i < per_page; i++) {
28
- skeletonItems.push(/*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
27
+ per_page = _ref$per_page === void 0 ? 20 : _ref$per_page;
28
+ var skeletonData = Array.from({
29
+ length: per_page
30
+ }, function (_, i) {
31
+ return {
32
+ id: i
33
+ };
34
+ });
35
+ var renderItem = function renderItem() {
36
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
29
37
  style: [styles.skeletonItem, {
30
38
  width: ITEM_SIZE,
31
39
  height: ITEM_SIZE,
@@ -35,17 +43,21 @@ var ImagesSkeleton = function ImagesSkeleton(_ref) {
35
43
  size: "small",
36
44
  color: "#3B3269"
37
45
  })
38
- }, i));
39
- }
40
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.View, {
41
- style: styles.container,
42
- children: skeletonItems
46
+ });
47
+ };
48
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactNative.FlatList, {
49
+ data: skeletonData,
50
+ renderItem: renderItem,
51
+ keyExtractor: function keyExtractor(item) {
52
+ return "skeleton-".concat(item.id);
53
+ },
54
+ numColumns: NUM_COLUMNS,
55
+ contentContainerStyle: styles.grid,
56
+ showsVerticalScrollIndicator: false
43
57
  });
44
58
  };
45
59
  var styles = _reactNative.StyleSheet.create({
46
- container: {
47
- flexDirection: "row",
48
- flexWrap: "wrap",
60
+ grid: {
49
61
  padding: 2 // Match MediaGallery grid padding
50
62
  },
51
63
  skeletonItem: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradly/asset",
3
- "version": "1.0.24",
3
+ "version": "1.0.26",
4
4
  "description": "A reusable media gallery component for uploading and selecting images, videos, and files with Tradly authentication",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/esm/index.js",