@tradly/asset 1.0.12 → 1.0.14

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 (72) hide show
  1. package/README.md +257 -13
  2. package/dist/components/FileUpload.js +8 -247
  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 -246
  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 +1 -1
  37. package/dist/esm/native/FileUpload.native.js +298 -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 +221 -0
  41. package/dist/esm/native/MediaPopup.native.js +151 -0
  42. package/dist/esm/native/MediaTab.native.js +175 -0
  43. package/dist/esm/native/Pagination.native.js +186 -0
  44. package/dist/esm/native/VideosGallery.native.js +233 -0
  45. package/dist/esm/services/apiService.js +1 -372
  46. package/dist/esm/web/FileUpload.web.js +253 -0
  47. package/dist/esm/web/Icons.web.js +32 -0
  48. package/dist/esm/web/ImagesSkeleton.web.js +14 -0
  49. package/dist/esm/web/MediaGallery.web.js +144 -0
  50. package/dist/esm/web/MediaPopup.web.js +97 -0
  51. package/dist/esm/web/MediaTab.web.js +177 -0
  52. package/dist/esm/web/Pagination.web.js +134 -0
  53. package/dist/esm/web/VideosGallery.web.js +144 -0
  54. package/dist/index.js +2 -2
  55. package/dist/native/FileUpload.native.js +304 -0
  56. package/dist/native/Icons.native.js +59 -0
  57. package/dist/native/ImagesSkeleton.native.js +52 -0
  58. package/dist/native/MediaGallery.native.js +230 -0
  59. package/dist/native/MediaPopup.native.js +158 -0
  60. package/dist/native/MediaTab.native.js +184 -0
  61. package/dist/native/Pagination.native.js +193 -0
  62. package/dist/native/VideosGallery.native.js +241 -0
  63. package/dist/services/apiService.js +2 -372
  64. package/dist/web/FileUpload.web.js +259 -0
  65. package/dist/web/Icons.web.js +39 -0
  66. package/dist/web/ImagesSkeleton.web.js +21 -0
  67. package/dist/web/MediaGallery.web.js +153 -0
  68. package/dist/web/MediaPopup.web.js +104 -0
  69. package/dist/web/MediaTab.web.js +186 -0
  70. package/dist/web/Pagination.web.js +141 -0
  71. package/dist/web/VideosGallery.web.js +153 -0
  72. package/package.json +4 -3
@@ -0,0 +1,253 @@
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 { CameraIcon } from './Icons.web';
13
+
14
+ // Helper: compress image on the client before upload
15
+ // - Downscale to fit within maxWidth/maxHeight.
16
+ // - Convert raster images (JPEG/PNG, etc.) to WebP for better compression.
17
+ // - Skip SVG (vector) to avoid degradation.
18
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
19
+ var compressImage = function compressImage(file) {
20
+ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {},
21
+ _ref$maxWidth = _ref.maxWidth,
22
+ maxWidth = _ref$maxWidth === void 0 ? 1600 : _ref$maxWidth,
23
+ _ref$maxHeight = _ref.maxHeight,
24
+ maxHeight = _ref$maxHeight === void 0 ? 1600 : _ref$maxHeight,
25
+ _ref$quality = _ref.quality,
26
+ quality = _ref$quality === void 0 ? 1 : _ref$quality,
27
+ _ref$convertToWebp = _ref.convertToWebp,
28
+ convertToWebp = _ref$convertToWebp === void 0 ? true : _ref$convertToWebp;
29
+ return new Promise(function (resolve) {
30
+ // Non-image or SVG: skip compression to avoid losing vector quality
31
+ if (!file.type.startsWith('image/') || file.type === 'image/svg+xml') {
32
+ resolve(file);
33
+ return;
34
+ }
35
+ var img = new Image();
36
+ img.onload = function () {
37
+ var width = img.width,
38
+ height = img.height;
39
+
40
+ // If the image is already small, keep it as-is
41
+ if (width <= maxWidth && height <= maxHeight) {
42
+ resolve(file);
43
+ return;
44
+ }
45
+ var scale = Math.min(maxWidth / width, maxHeight / height);
46
+ var targetWidth = Math.round(width * scale);
47
+ var targetHeight = Math.round(height * scale);
48
+ var canvas = document.createElement('canvas');
49
+ canvas.width = targetWidth;
50
+ canvas.height = targetHeight;
51
+ var ctx = canvas.getContext('2d');
52
+ if (!ctx) {
53
+ resolve(file);
54
+ return;
55
+ }
56
+ ctx.drawImage(img, 0, 0, targetWidth, targetHeight);
57
+
58
+ // Prefer WebP for raster images to reduce size (where supported)
59
+ // Keep original type for GIF to avoid breaking animation.
60
+ var isRaster = file.type === 'image/jpeg' || file.type === 'image/jpg' || file.type === 'image/png' || file.type === 'image/webp' || file.type === 'image/heic' || file.type === 'image/heif';
61
+ var targetType = convertToWebp && isRaster && file.type !== 'image/gif' ? 'image/webp' : file.type;
62
+ canvas.toBlob(function (blob) {
63
+ if (!blob) {
64
+ resolve(file);
65
+ return;
66
+ }
67
+
68
+ // If we converted to WebP, normalize extension in the file name
69
+ var newName = file.name;
70
+ if (targetType === 'image/webp') {
71
+ var dotIndex = file.name.lastIndexOf('.');
72
+ newName = dotIndex > 0 ? "".concat(file.name.slice(0, dotIndex), ".webp") : "".concat(file.name, ".webp");
73
+ }
74
+ var compressedFile = new File([blob], newName, {
75
+ type: targetType,
76
+ lastModified: Date.now()
77
+ });
78
+ resolve(compressedFile);
79
+ }, targetType, quality);
80
+ };
81
+ img.onerror = function () {
82
+ resolve(file);
83
+ };
84
+ var reader = new FileReader();
85
+ reader.onload = function (event) {
86
+ var _event$target;
87
+ img.src = (_event$target = event.target) === null || _event$target === void 0 ? void 0 : _event$target.result;
88
+ };
89
+ reader.onerror = function () {
90
+ return resolve(file);
91
+ };
92
+ reader.readAsDataURL(file);
93
+ });
94
+ };
95
+ var FileUpload = function FileUpload(_ref2) {
96
+ var loadMedia = _ref2.loadMedia,
97
+ accept = _ref2.accept,
98
+ title = _ref2.title,
99
+ apiService = _ref2.apiService,
100
+ onUploadStart = _ref2.onUploadStart,
101
+ onUploadComplete = _ref2.onUploadComplete,
102
+ onUploadError = _ref2.onUploadError,
103
+ className = _ref2.className,
104
+ buttonClassName = _ref2.buttonClassName,
105
+ iconContainerClassName = _ref2.iconContainerClassName,
106
+ titleClassName = _ref2.titleClassName,
107
+ loadingClassName = _ref2.loadingClassName;
108
+ var _useState = useState([]),
109
+ _useState2 = _slicedToArray(_useState, 2),
110
+ files = _useState2[0],
111
+ setFiles = _useState2[1];
112
+ var _useState3 = useState(false),
113
+ _useState4 = _slicedToArray(_useState3, 2),
114
+ isLoading = _useState4[0],
115
+ setISLoading = _useState4[1];
116
+ var _useState5 = useState(0),
117
+ _useState6 = _slicedToArray(_useState5, 2),
118
+ length = _useState6[0],
119
+ setLength = _useState6[1];
120
+
121
+ // Upload files
122
+ var uploadFiles = /*#__PURE__*/function () {
123
+ var _ref3 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee(fileList) {
124
+ var filesToUpload, uploadedUrls, _t;
125
+ return _regenerator().w(function (_context) {
126
+ while (1) switch (_context.p = _context.n) {
127
+ case 0:
128
+ if (onUploadStart) {
129
+ onUploadStart(fileList);
130
+ }
131
+ setISLoading(true);
132
+ setLength(fileList.length);
133
+ _context.p = 1;
134
+ filesToUpload = fileList; // For image uploads, compress on the client before sending
135
+ if (!(accept && accept.includes('image'))) {
136
+ _context.n = 3;
137
+ break;
138
+ }
139
+ _context.n = 2;
140
+ return Promise.all(fileList.map(function (file) {
141
+ return compressImage(file, {
142
+ maxWidth: 1600,
143
+ maxHeight: 1600,
144
+ quality: 0.95,
145
+ convertToWebp: true
146
+ });
147
+ }));
148
+ case 2:
149
+ filesToUpload = _context.v;
150
+ case 3:
151
+ _context.n = 4;
152
+ return apiService.uploadMedia(filesToUpload, apiService.authKey);
153
+ case 4:
154
+ uploadedUrls = _context.v;
155
+ if (onUploadComplete) {
156
+ onUploadComplete(uploadedUrls);
157
+ }
158
+ setLength(0);
159
+ if (loadMedia) {
160
+ loadMedia();
161
+ }
162
+ _context.n = 6;
163
+ break;
164
+ case 5:
165
+ _context.p = 5;
166
+ _t = _context.v;
167
+ console.error('Upload error:', _t);
168
+ if (onUploadError) {
169
+ onUploadError(_t);
170
+ }
171
+ case 6:
172
+ _context.p = 6;
173
+ setISLoading(false);
174
+ return _context.f(6);
175
+ case 7:
176
+ return _context.a(2);
177
+ }
178
+ }, _callee, null, [[1, 5, 6, 7]]);
179
+ }));
180
+ return function uploadFiles(_x) {
181
+ return _ref3.apply(this, arguments);
182
+ };
183
+ }();
184
+
185
+ // Default classes with customization support
186
+ var defaultContainerClass = 'min-w-40 h-40';
187
+ var defaultButtonClass = 'w-full h-full flex flex-col justify-center items-center text-sm border border-primary border-dashed rounded-lg hover:bg-gray-50 transition-colors';
188
+ var defaultIconContainerClass = 'p-[10px] bg-primary rounded-full';
189
+ var defaultTitleClass = 'mt-2';
190
+ var defaultLoadingClass = 'flex items-center justify-center h-40 bg-gray-200 rounded-lg shadow-md animate-pulse';
191
+ return /*#__PURE__*/_jsxs(_Fragment, {
192
+ children: [/*#__PURE__*/_jsxs("div", {
193
+ className: className || defaultContainerClass,
194
+ children: [/*#__PURE__*/_jsx("input", {
195
+ required: true,
196
+ id: "media_select_".concat(files === null || files === void 0 ? void 0 : files.length),
197
+ type: "file",
198
+ className: "hidden",
199
+ accept: accept,
200
+ placeholder: "",
201
+ onChange: (/*#__PURE__*/function () {
202
+ var _ref4 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee2(e) {
203
+ var all_files;
204
+ return _regenerator().w(function (_context2) {
205
+ while (1) switch (_context2.n) {
206
+ case 0:
207
+ e.stopPropagation();
208
+ all_files = Array.from(e.target.files || []);
209
+ if (!((all_files === null || all_files === void 0 ? void 0 : all_files.length) > 0)) {
210
+ _context2.n = 1;
211
+ break;
212
+ }
213
+ _context2.n = 1;
214
+ return uploadFiles(all_files);
215
+ case 1:
216
+ // Reset input
217
+ e.target.value = '';
218
+ case 2:
219
+ return _context2.a(2);
220
+ }
221
+ }, _callee2);
222
+ }));
223
+ return function (_x2) {
224
+ return _ref4.apply(this, arguments);
225
+ };
226
+ }()),
227
+ multiple: true
228
+ }), /*#__PURE__*/_jsxs("button", {
229
+ type: "button",
230
+ className: buttonClassName || defaultButtonClass,
231
+ onClick: function onClick() {
232
+ return document.getElementById("media_select_".concat(files === null || files === void 0 ? void 0 : files.length)).click();
233
+ },
234
+ disabled: isLoading,
235
+ children: [/*#__PURE__*/_jsx("span", {
236
+ className: iconContainerClassName || defaultIconContainerClass,
237
+ children: /*#__PURE__*/_jsx(CameraIcon, {})
238
+ }), /*#__PURE__*/_jsx("span", {
239
+ className: titleClassName || defaultTitleClass,
240
+ children: title
241
+ })]
242
+ })]
243
+ }), isLoading && Array.from({
244
+ length: length
245
+ }).map(function (_, index) {
246
+ return /*#__PURE__*/_jsxs("div", {
247
+ className: loadingClassName || defaultLoadingClass,
248
+ children: ["File Uploading... ", index + 1, "/", length]
249
+ }, index);
250
+ })]
251
+ });
252
+ };
253
+ export default FileUpload;
@@ -0,0 +1,32 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ export var CloseIcon = function CloseIcon(_ref) {
4
+ var _ref$className = _ref.className,
5
+ className = _ref$className === void 0 ? 'w-8 h-8' : _ref$className;
6
+ return /*#__PURE__*/_jsx("svg", {
7
+ xmlns: "http://www.w3.org/2000/svg",
8
+ fill: "none",
9
+ viewBox: "0 0 24 24",
10
+ strokeWidth: "1.5",
11
+ stroke: "currentColor",
12
+ className: className,
13
+ children: /*#__PURE__*/_jsx("path", {
14
+ strokeLinecap: "round",
15
+ strokeLinejoin: "round",
16
+ d: "M6 18L18 6M6 6l12 12"
17
+ })
18
+ });
19
+ };
20
+ export var CameraIcon = function CameraIcon() {
21
+ return /*#__PURE__*/_jsx("svg", {
22
+ width: "22",
23
+ height: "18",
24
+ viewBox: "0 0 22 20",
25
+ fill: "none",
26
+ xmlns: "http://www.w3.org/2000/svg",
27
+ children: /*#__PURE__*/_jsx("path", {
28
+ d: "M7.75033 0.166672L5.76783 2.33334H2.33366C1.14199 2.33334 0.166992 3.30834 0.166992 4.50001V17.5C0.166992 18.6917 1.14199 19.6667 2.33366 19.6667H19.667C20.8587 19.6667 21.8337 18.6917 21.8337 17.5V4.50001C21.8337 3.30834 20.8587 2.33334 19.667 2.33334H16.2328L14.2503 0.166672H7.75033ZM11.0003 16.4167C8.01033 16.4167 5.58366 13.99 5.58366 11C5.58366 8.01001 8.01033 5.58334 11.0003 5.58334C13.9903 5.58334 16.417 8.01001 16.417 11C16.417 13.99 13.9903 16.4167 11.0003 16.4167Z",
29
+ fill: "white"
30
+ })
31
+ });
32
+ };
@@ -0,0 +1,14 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ var ImagesSkeleton = function ImagesSkeleton(_ref) {
4
+ var _ref$per_page = _ref.per_page,
5
+ per_page = _ref$per_page === void 0 ? 30 : _ref$per_page;
6
+ var gridItems = [];
7
+ for (var i = 0; i < per_page; i++) {
8
+ gridItems.push(/*#__PURE__*/_jsx("div", {
9
+ className: "w-full min-h-[160px] bg-[#3B3269] bg-opacity-[20%] rounded-card animate-pulse"
10
+ }, i));
11
+ }
12
+ return gridItems;
13
+ };
14
+ export default ImagesSkeleton;
@@ -0,0 +1,144 @@
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, useEffect } from 'react';
12
+ import FileUpload from './FileUpload.web';
13
+ import ImagesSkeleton from './ImagesSkeleton.web';
14
+ import Pagination from './Pagination.web';
15
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
16
+ 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'];
17
+ var ImagesGallery = function ImagesGallery(_ref) {
18
+ var update_data = _ref.update_data,
19
+ closePopup = _ref.closePopup,
20
+ apiService = _ref.apiService,
21
+ onError = _ref.onError,
22
+ className = _ref.className,
23
+ gridClassName = _ref.gridClassName,
24
+ imageItemClassName = _ref.imageItemClassName,
25
+ paginationContainerClassName = _ref.paginationContainerClassName;
26
+ var _useState = useState([]),
27
+ _useState2 = _slicedToArray(_useState, 2),
28
+ images = _useState2[0],
29
+ setImages = _useState2[1];
30
+ var _useState3 = useState(0),
31
+ _useState4 = _slicedToArray(_useState3, 2),
32
+ total_count = _useState4[0],
33
+ setTotalCount = _useState4[1];
34
+ var _useState5 = useState(1),
35
+ _useState6 = _slicedToArray(_useState5, 2),
36
+ currentPage = _useState6[0],
37
+ setCurrentPage = _useState6[1];
38
+ var _useState7 = useState(false),
39
+ _useState8 = _slicedToArray(_useState7, 2),
40
+ isLoading = _useState8[0],
41
+ setISLoading = _useState8[1];
42
+
43
+ // Fetch images
44
+ useEffect(function () {
45
+ loadMedia();
46
+ }, []);
47
+ var loadMedia = /*#__PURE__*/function () {
48
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regenerator().m(function _callee() {
49
+ var page_number,
50
+ _response$data,
51
+ _response$data2,
52
+ response,
53
+ mediaData,
54
+ count,
55
+ _args = arguments,
56
+ _t;
57
+ return _regenerator().w(function (_context) {
58
+ while (1) switch (_context.p = _context.n) {
59
+ case 0:
60
+ page_number = _args.length > 0 && _args[0] !== undefined ? _args[0] : 1;
61
+ _context.p = 1;
62
+ _context.n = 2;
63
+ return apiService.fetchMedia({
64
+ mimeTypes: IMAGE_MIME_TYPES,
65
+ page: page_number,
66
+ setISLoading: setISLoading,
67
+ isLoading: isLoading
68
+ });
69
+ case 2:
70
+ response = _context.v;
71
+ // Handle different response formats
72
+ // Response might be: { media: [...], count: ... } or { data: { media: [...], count: ... } } or directly [...]
73
+ 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 || [];
74
+ 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;
75
+ setImages(Array.isArray(mediaData) ? mediaData : []);
76
+ setTotalCount(count);
77
+ setCurrentPage(page_number);
78
+ _context.n = 4;
79
+ break;
80
+ case 3:
81
+ _context.p = 3;
82
+ _t = _context.v;
83
+ console.error('Error loading media:', _t);
84
+ if (onError) {
85
+ onError(_t);
86
+ }
87
+ case 4:
88
+ return _context.a(2);
89
+ }
90
+ }, _callee, null, [[1, 3]]);
91
+ }));
92
+ return function loadMedia() {
93
+ return _ref2.apply(this, arguments);
94
+ };
95
+ }();
96
+ var handleImageClick = function handleImageClick(image) {
97
+ if (update_data) {
98
+ update_data(image.url || image);
99
+ }
100
+ if (closePopup) {
101
+ closePopup();
102
+ }
103
+ };
104
+
105
+ // Default classes with customization support
106
+ var defaultContainerClass = 'h-full flex flex-col justify-between';
107
+ var defaultGridClass = 'grid grid-cols-[repeat(auto-fill,minmax(calc(160px),1fr))] gap-5';
108
+ var defaultImageItemClass = 'cursor-pointer w-full h-40 object-contain p-3 overflow-hidden bg-white rounded-md shadow-md hover:shadow-lg transition-shadow';
109
+ var defaultPaginationContainerClass = 'mb-4 bg-gray-100/90 p-4 sticky bottom-0';
110
+ return /*#__PURE__*/_jsxs("div", {
111
+ className: className || defaultContainerClass,
112
+ children: [/*#__PURE__*/_jsxs("div", {
113
+ className: gridClassName || defaultGridClass,
114
+ children: [/*#__PURE__*/_jsx(FileUpload, {
115
+ loadMedia: loadMedia,
116
+ accept: "image/*",
117
+ title: "Add Image",
118
+ apiService: apiService,
119
+ onUploadError: onError
120
+ }), isLoading ? /*#__PURE__*/_jsx(ImagesSkeleton, {}) : images === null || images === void 0 ? void 0 : images.map(function (image, index) {
121
+ var imageUrl = typeof image === 'string' ? image : image.url;
122
+ var imageKey = image.id || image.url || index;
123
+ return /*#__PURE__*/_jsx("img", {
124
+ onClick: function onClick() {
125
+ return handleImageClick(image);
126
+ },
127
+ className: imageItemClassName || defaultImageItemClass,
128
+ src: imageUrl,
129
+ alt: image.name || 'Media item'
130
+ }, imageKey);
131
+ })]
132
+ }), /*#__PURE__*/_jsx("div", {
133
+ className: paginationContainerClassName || defaultPaginationContainerClass,
134
+ children: total_count > 0 && /*#__PURE__*/_jsx(Pagination, {
135
+ nextPage: function nextPage(value) {
136
+ return loadMedia(value);
137
+ },
138
+ pageCount: Math.ceil(total_count / 30),
139
+ current_page: currentPage
140
+ })
141
+ })]
142
+ });
143
+ };
144
+ export default ImagesGallery;
@@ -0,0 +1,97 @@
1
+ import React from 'react';
2
+ import { createPortal } from 'react-dom';
3
+ import MediaTab from '../components/MediaTab';
4
+ import { CloseIcon } from './Icons';
5
+ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
6
+ var MediaPopup = function MediaPopup(_ref) {
7
+ var isOpen = _ref.isOpen,
8
+ onClose = _ref.onClose,
9
+ onSelect = _ref.onSelect,
10
+ currentData = _ref.currentData,
11
+ _ref$options = _ref.options,
12
+ options = _ref$options === void 0 ? ['image'] : _ref$options,
13
+ apiService = _ref.apiService,
14
+ onError = _ref.onError,
15
+ _ref$title = _ref.title,
16
+ title = _ref$title === void 0 ? 'Media Gallery' : _ref$title,
17
+ className = _ref.className,
18
+ overlayClassName = _ref.overlayClassName,
19
+ containerClassName = _ref.containerClassName,
20
+ headerClassName = _ref.headerClassName,
21
+ titleClassName = _ref.titleClassName,
22
+ closeButtonClassName = _ref.closeButtonClassName,
23
+ tabListClassName = _ref.tabListClassName,
24
+ tabButtonClassName = _ref.tabButtonClassName,
25
+ tabButtonActiveClassName = _ref.tabButtonActiveClassName,
26
+ tabButtonInactiveClassName = _ref.tabButtonInactiveClassName,
27
+ tabPanelClassName = _ref.tabPanelClassName,
28
+ gridClassName = _ref.gridClassName,
29
+ imageItemClassName = _ref.imageItemClassName,
30
+ videoItemClassName = _ref.videoItemClassName,
31
+ paginationContainerClassName = _ref.paginationContainerClassName;
32
+ if (!isOpen) return null;
33
+ var handleUpdate = function handleUpdate(data) {
34
+ if (onSelect) {
35
+ onSelect(data);
36
+ }
37
+ };
38
+ var handleClose = function handleClose() {
39
+ if (onClose) {
40
+ onClose();
41
+ }
42
+ };
43
+
44
+ // Default classes with customization support
45
+ var defaultOverlayClass = 'fixed inset-0 w-screen h-screen bg-black opacity-10';
46
+ var defaultContainerClass = 'origin-top-right z-[9999] absolute inset-0 max-w-3xl mx-auto my-auto min-h-[200px] h-[600px] bg-white rounded shadow-inner cursor-auto p-6';
47
+ var defaultHeaderClass = 'flex items-center justify-between gap-4';
48
+ var defaultTitleClass = 'text-[#000] font-bold text-2xl';
49
+ var defaultCloseButtonClass = 'bg-transparent rounded-full hover:bg-gray-100 p-1 transition-colors';
50
+ return /*#__PURE__*/createPortal(/*#__PURE__*/_jsxs(_Fragment, {
51
+ children: [/*#__PURE__*/_jsx("div", {
52
+ className: overlayClassName || defaultOverlayClass,
53
+ style: {
54
+ zIndex: 9998
55
+ },
56
+ onClick: handleClose
57
+ }), /*#__PURE__*/_jsxs("div", {
58
+ className: containerClassName || defaultContainerClass,
59
+ style: {
60
+ zIndex: 9999
61
+ },
62
+ children: [/*#__PURE__*/_jsxs("div", {
63
+ className: headerClassName || defaultHeaderClass,
64
+ children: [/*#__PURE__*/_jsx("p", {
65
+ className: titleClassName || defaultTitleClass,
66
+ children: title
67
+ }), /*#__PURE__*/_jsx("button", {
68
+ className: closeButtonClassName || defaultCloseButtonClass,
69
+ type: "button",
70
+ onClick: handleClose,
71
+ "aria-label": "Close",
72
+ children: /*#__PURE__*/_jsx(CloseIcon, {})
73
+ })]
74
+ }), /*#__PURE__*/_jsx(MediaTab, {
75
+ imagePopup: isOpen,
76
+ update_data: handleUpdate,
77
+ current_data: currentData,
78
+ closePopup: handleClose,
79
+ options: options,
80
+ apiService: apiService,
81
+ onError: onError
82
+ // Pass styling props through
83
+ ,
84
+ tabListClassName: tabListClassName,
85
+ tabButtonClassName: tabButtonClassName,
86
+ tabButtonActiveClassName: tabButtonActiveClassName,
87
+ tabButtonInactiveClassName: tabButtonInactiveClassName,
88
+ tabPanelClassName: tabPanelClassName,
89
+ gridClassName: gridClassName,
90
+ imageItemClassName: imageItemClassName,
91
+ videoItemClassName: videoItemClassName,
92
+ paginationContainerClassName: paginationContainerClassName
93
+ })]
94
+ })]
95
+ }), document.body);
96
+ };
97
+ export default MediaPopup;