@tradly/asset 1.0.25 → 1.0.27

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)) {
@@ -104,11 +104,13 @@ var FileUpload = function FileUpload(_ref) {
104
104
  if (icons && _typeof(icons) === "object") {
105
105
  var isImage = accept === null || accept === void 0 ? void 0 : accept.includes("image");
106
106
  var isVideo = accept === null || accept === void 0 ? void 0 : accept.includes("video");
107
+ var isFile = (accept === null || accept === void 0 ? void 0 : accept.includes("file")) || !isImage && !isVideo;
107
108
  if (isImage && icons.image) {
108
109
  return icons.image;
109
110
  } else if (isVideo && icons.video) {
110
111
  return icons.video;
111
- } else if (icons.default) {
112
+ } else if ((isFile || !isImage && !isVideo) && icons.default) {
113
+ // Use default icon for file types or when neither image nor video
112
114
  return icons.default;
113
115
  }
114
116
  }
@@ -153,29 +155,104 @@ var FileUpload = function FileUpload(_ref) {
153
155
  }
154
156
 
155
157
  // 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) {
158
+ // Use a comprehensive helper function to determine MIME type from filename
159
+ var getMimeTypeFromFileName = function getMimeTypeFromFileName(name) {
158
160
  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();
161
+ if (!name) return "application/octet-stream";
162
+ var ext = (_name$split$pop = name.split(".").pop()) === null || _name$split$pop === void 0 ? void 0 : _name$split$pop.toLowerCase().trim();
163
+ if (!ext) return "application/octet-stream";
164
+
165
+ // Comprehensive MIME type mapping
161
166
  var mimeMap = {
167
+ // Images
162
168
  jpg: "image/jpeg",
163
169
  jpeg: "image/jpeg",
164
170
  png: "image/png",
165
171
  gif: "image/gif",
166
172
  webp: "image/webp",
173
+ svg: "image/svg+xml",
174
+ bmp: "image/bmp",
175
+ ico: "image/x-icon",
176
+ heic: "image/heic",
177
+ heif: "image/heif",
178
+ tiff: "image/tiff",
179
+ tif: "image/tiff",
180
+ jfif: "image/jpeg",
181
+ avif: "image/avif",
182
+ // Videos
167
183
  mp4: "video/mp4",
168
184
  mov: "video/quicktime",
169
- mp3: "audio/mpeg"
185
+ avi: "video/x-msvideo",
186
+ wmv: "video/x-ms-wmv",
187
+ flv: "video/x-flv",
188
+ mkv: "video/x-matroska",
189
+ webm: "video/webm",
190
+ mpeg: "video/mpeg",
191
+ mpg: "video/mpeg",
192
+ m4v: "video/x-m4v",
193
+ "3gp": "video/3gpp",
194
+ // Audio
195
+ mp3: "audio/mpeg",
196
+ wav: "audio/wav",
197
+ ogg: "audio/ogg",
198
+ m4a: "audio/mp4",
199
+ aac: "audio/aac",
200
+ flac: "audio/flac",
201
+ // Documents
202
+ pdf: "application/pdf",
203
+ doc: "application/msword",
204
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
205
+ xls: "application/vnd.ms-excel",
206
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
207
+ ppt: "application/vnd.ms-powerpoint",
208
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
209
+ // Archives
210
+ zip: "application/zip",
211
+ rar: "application/rar",
212
+ "7z": "application/x-7z-compressed",
213
+ tar: "application/x-tar",
214
+ gz: "application/gzip",
215
+ // Text
216
+ txt: "text/plain",
217
+ html: "text/html",
218
+ htm: "text/html",
219
+ css: "text/css",
220
+ js: "text/javascript",
221
+ json: "application/json",
222
+ xml: "text/xml",
223
+ php: "application/x-php"
170
224
  };
171
- return mimeMap[ext] || "image/jpeg";
225
+ return mimeMap[ext] || "application/octet-stream";
172
226
  };
173
- var mimeType = pickerResult.mimeType || pickerResult.type || getMimeType(fileName, null);
174
- console.log("mimeType", {
175
- fileName: fileName,
176
- mimeType: mimeType,
177
- pickerResult: pickerResult
178
- });
227
+
228
+ // Get MIME type - prioritize picker result, then filename, then default
229
+ var mimeType = pickerResult.mimeType || pickerResult.type;
230
+
231
+ // Clean up MIME type if it exists but is malformed
232
+ if (mimeType) {
233
+ mimeType = mimeType.trim();
234
+ // If it doesn't have a slash, it's not a valid MIME type format
235
+ if (!mimeType.includes("/")) {
236
+ mimeType = null;
237
+ } else {
238
+ // Normalize: lowercase the type part but keep structure
239
+ // e.g., "IMAGE/JPEG" -> "image/jpeg", "Image/Jpeg" -> "image/jpeg"
240
+ var parts = mimeType.split("/");
241
+ if (parts.length === 2) {
242
+ mimeType = "".concat(parts[0].toLowerCase(), "/").concat(parts[1].toLowerCase());
243
+ }
244
+ }
245
+ }
246
+
247
+ // If MIME type is missing or invalid, detect from filename
248
+ if (!mimeType) {
249
+ mimeType = getMimeTypeFromFileName(fileName);
250
+ }
251
+
252
+ // Final validation - ensure MIME type is properly formatted
253
+ if (!mimeType || !mimeType.includes("/")) {
254
+ mimeType = "application/octet-stream";
255
+ }
179
256
  return {
180
257
  uri: uri,
181
258
  name: fileName,
@@ -11,13 +11,13 @@ var ITEM_MARGIN = 4; // Match MediaGallery margin
11
11
  // - Item margins: (NUM_COLUMNS - 1) gaps between items
12
12
  // Each gap = 2 * ITEM_MARGIN (left margin of right item + right margin of left item)
13
13
  // Total: (3 - 1) * 2 * 4 = 16px
14
- var CONTAINER_PADDING = 24; // paddingHorizontal md (12 * 2)
14
+ var CONTAINER_PADDING = 14; // paddingHorizontal md (12 * 2)
15
15
  var GRID_PADDING = 4; // padding 2 on each side (2 * 2)
16
16
  var TOTAL_MARGINS = ITEM_MARGIN * (NUM_COLUMNS - 1) * 2; // 4 * 2 * 2 = 16px
17
17
  var ITEM_SIZE = (SCREEN_WIDTH - CONTAINER_PADDING - GRID_PADDING - TOTAL_MARGINS) / NUM_COLUMNS;
18
18
  var ImagesSkeleton = function ImagesSkeleton(_ref) {
19
19
  var _ref$per_page = _ref.per_page,
20
- per_page = _ref$per_page === void 0 ? 30 : _ref$per_page;
20
+ per_page = _ref$per_page === void 0 ? 20 : _ref$per_page;
21
21
  var skeletonData = Array.from({
22
22
  length: per_page
23
23
  }, function (_, i) {
@@ -109,11 +109,13 @@ var FileUpload = function FileUpload(_ref) {
109
109
  if (icons && _typeof(icons) === "object") {
110
110
  var isImage = accept === null || accept === void 0 ? void 0 : accept.includes("image");
111
111
  var isVideo = accept === null || accept === void 0 ? void 0 : accept.includes("video");
112
+ var isFile = (accept === null || accept === void 0 ? void 0 : accept.includes("file")) || !isImage && !isVideo;
112
113
  if (isImage && icons.image) {
113
114
  return icons.image;
114
115
  } else if (isVideo && icons.video) {
115
116
  return icons.video;
116
- } else if (icons.default) {
117
+ } else if ((isFile || !isImage && !isVideo) && icons.default) {
118
+ // Use default icon for file types or when neither image nor video
117
119
  return icons.default;
118
120
  }
119
121
  }
@@ -158,29 +160,104 @@ var FileUpload = function FileUpload(_ref) {
158
160
  }
159
161
 
160
162
  // 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) {
163
+ // Use a comprehensive helper function to determine MIME type from filename
164
+ var getMimeTypeFromFileName = function getMimeTypeFromFileName(name) {
163
165
  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();
166
+ if (!name) return "application/octet-stream";
167
+ var ext = (_name$split$pop = name.split(".").pop()) === null || _name$split$pop === void 0 ? void 0 : _name$split$pop.toLowerCase().trim();
168
+ if (!ext) return "application/octet-stream";
169
+
170
+ // Comprehensive MIME type mapping
166
171
  var mimeMap = {
172
+ // Images
167
173
  jpg: "image/jpeg",
168
174
  jpeg: "image/jpeg",
169
175
  png: "image/png",
170
176
  gif: "image/gif",
171
177
  webp: "image/webp",
178
+ svg: "image/svg+xml",
179
+ bmp: "image/bmp",
180
+ ico: "image/x-icon",
181
+ heic: "image/heic",
182
+ heif: "image/heif",
183
+ tiff: "image/tiff",
184
+ tif: "image/tiff",
185
+ jfif: "image/jpeg",
186
+ avif: "image/avif",
187
+ // Videos
172
188
  mp4: "video/mp4",
173
189
  mov: "video/quicktime",
174
- mp3: "audio/mpeg"
190
+ avi: "video/x-msvideo",
191
+ wmv: "video/x-ms-wmv",
192
+ flv: "video/x-flv",
193
+ mkv: "video/x-matroska",
194
+ webm: "video/webm",
195
+ mpeg: "video/mpeg",
196
+ mpg: "video/mpeg",
197
+ m4v: "video/x-m4v",
198
+ "3gp": "video/3gpp",
199
+ // Audio
200
+ mp3: "audio/mpeg",
201
+ wav: "audio/wav",
202
+ ogg: "audio/ogg",
203
+ m4a: "audio/mp4",
204
+ aac: "audio/aac",
205
+ flac: "audio/flac",
206
+ // Documents
207
+ pdf: "application/pdf",
208
+ doc: "application/msword",
209
+ docx: "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
210
+ xls: "application/vnd.ms-excel",
211
+ xlsx: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
212
+ ppt: "application/vnd.ms-powerpoint",
213
+ pptx: "application/vnd.openxmlformats-officedocument.presentationml.presentation",
214
+ // Archives
215
+ zip: "application/zip",
216
+ rar: "application/rar",
217
+ "7z": "application/x-7z-compressed",
218
+ tar: "application/x-tar",
219
+ gz: "application/gzip",
220
+ // Text
221
+ txt: "text/plain",
222
+ html: "text/html",
223
+ htm: "text/html",
224
+ css: "text/css",
225
+ js: "text/javascript",
226
+ json: "application/json",
227
+ xml: "text/xml",
228
+ php: "application/x-php"
175
229
  };
176
- return mimeMap[ext] || "image/jpeg";
230
+ return mimeMap[ext] || "application/octet-stream";
177
231
  };
178
- var mimeType = pickerResult.mimeType || pickerResult.type || getMimeType(fileName, null);
179
- console.log("mimeType", {
180
- fileName: fileName,
181
- mimeType: mimeType,
182
- pickerResult: pickerResult
183
- });
232
+
233
+ // Get MIME type - prioritize picker result, then filename, then default
234
+ var mimeType = pickerResult.mimeType || pickerResult.type;
235
+
236
+ // Clean up MIME type if it exists but is malformed
237
+ if (mimeType) {
238
+ mimeType = mimeType.trim();
239
+ // If it doesn't have a slash, it's not a valid MIME type format
240
+ if (!mimeType.includes("/")) {
241
+ mimeType = null;
242
+ } else {
243
+ // Normalize: lowercase the type part but keep structure
244
+ // e.g., "IMAGE/JPEG" -> "image/jpeg", "Image/Jpeg" -> "image/jpeg"
245
+ var parts = mimeType.split("/");
246
+ if (parts.length === 2) {
247
+ mimeType = "".concat(parts[0].toLowerCase(), "/").concat(parts[1].toLowerCase());
248
+ }
249
+ }
250
+ }
251
+
252
+ // If MIME type is missing or invalid, detect from filename
253
+ if (!mimeType) {
254
+ mimeType = getMimeTypeFromFileName(fileName);
255
+ }
256
+
257
+ // Final validation - ensure MIME type is properly formatted
258
+ if (!mimeType || !mimeType.includes("/")) {
259
+ mimeType = "application/octet-stream";
260
+ }
184
261
  return {
185
262
  uri: uri,
186
263
  name: fileName,
@@ -18,13 +18,13 @@ var ITEM_MARGIN = 4; // Match MediaGallery margin
18
18
  // - Item margins: (NUM_COLUMNS - 1) gaps between items
19
19
  // Each gap = 2 * ITEM_MARGIN (left margin of right item + right margin of left item)
20
20
  // Total: (3 - 1) * 2 * 4 = 16px
21
- var CONTAINER_PADDING = 24; // paddingHorizontal md (12 * 2)
21
+ var CONTAINER_PADDING = 14; // paddingHorizontal md (12 * 2)
22
22
  var GRID_PADDING = 4; // padding 2 on each side (2 * 2)
23
23
  var TOTAL_MARGINS = ITEM_MARGIN * (NUM_COLUMNS - 1) * 2; // 4 * 2 * 2 = 16px
24
24
  var ITEM_SIZE = (SCREEN_WIDTH - CONTAINER_PADDING - GRID_PADDING - TOTAL_MARGINS) / NUM_COLUMNS;
25
25
  var ImagesSkeleton = function ImagesSkeleton(_ref) {
26
26
  var _ref$per_page = _ref.per_page,
27
- per_page = _ref$per_page === void 0 ? 30 : _ref$per_page;
27
+ per_page = _ref$per_page === void 0 ? 20 : _ref$per_page;
28
28
  var skeletonData = Array.from({
29
29
  length: per_page
30
30
  }, function (_, i) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tradly/asset",
3
- "version": "1.0.25",
3
+ "version": "1.0.27",
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",