@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,177 @@
1
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
2
+ 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."); }
3
+ 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; } }
4
+ 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; }
5
+ 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; } }
6
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
7
+ import React, { useMemo, useState } from 'react';
8
+ import ImagesGallery from './MediaGallery.web';
9
+ import VideosGallery from './VideosGallery.web';
10
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
11
+ function classNames() {
12
+ for (var _len = arguments.length, classes = new Array(_len), _key = 0; _key < _len; _key++) {
13
+ classes[_key] = arguments[_key];
14
+ }
15
+ return classes.filter(Boolean).join(' ');
16
+ }
17
+ var MediaTab = function MediaTab(_ref) {
18
+ var imagePopup = _ref.imagePopup,
19
+ current_data = _ref.current_data,
20
+ update_data = _ref.update_data,
21
+ closePopup = _ref.closePopup,
22
+ options = _ref.options,
23
+ apiService = _ref.apiService,
24
+ onError = _ref.onError,
25
+ className = _ref.className,
26
+ tabListClassName = _ref.tabListClassName,
27
+ tabButtonClassName = _ref.tabButtonClassName,
28
+ tabButtonActiveClassName = _ref.tabButtonActiveClassName,
29
+ tabButtonInactiveClassName = _ref.tabButtonInactiveClassName,
30
+ tabPanelClassName = _ref.tabPanelClassName,
31
+ gridClassName = _ref.gridClassName,
32
+ imageItemClassName = _ref.imageItemClassName,
33
+ videoItemClassName = _ref.videoItemClassName,
34
+ paginationContainerClassName = _ref.paginationContainerClassName;
35
+ // Build a stable list of enabled tabs in order
36
+ var availableTabs = useMemo(function () {
37
+ var tabs = [];
38
+ if (options !== null && options !== void 0 && options.includes('image')) tabs.push('image');
39
+ if (options !== null && options !== void 0 && options.includes('video')) tabs.push('video');
40
+ if (options !== null && options !== void 0 && options.includes('file')) tabs.push('file');
41
+ return tabs;
42
+ }, [options]);
43
+ var _useState = useState(0),
44
+ _useState2 = _slicedToArray(_useState, 2),
45
+ selectedIndex = _useState2[0],
46
+ setSelectedIndex = _useState2[1];
47
+
48
+ // Guard: if no options passed, render nothing
49
+ if (!availableTabs.length) {
50
+ return null;
51
+ }
52
+
53
+ // Default classes with customization support
54
+ var defaultTabGroupClass = 'h-[520px] overflow-y-auto scrollbar-none';
55
+ var defaultTabListClass = 'sticky top-0 z-30 bg-white w-full flex border-b-2 border-gray-200';
56
+ var defaultTabButtonBaseClass = 'rounded-lg py-2.5 px-8 text-base font-medium leading-5 flex flex-col md:flex-row items-center justify-center gap-3 ring-0 focus:outline-none';
57
+ var defaultTabButtonActiveClass = 'relative text-primary after:content-[""] after:h-1 after:w-full after:block after:absolute after:-bottom-0.5 after:bg-primary after:rounded-card';
58
+ var defaultTabButtonInactiveClass = 'text-[#4F4F4F]';
59
+ var defaultTabPanelClass = 'h-full py-4 relative';
60
+ var handleKeyDown = function handleKeyDown(event, index) {
61
+ if (event.key === 'Enter' || event.key === ' ') {
62
+ event.preventDefault();
63
+ setSelectedIndex(index);
64
+ }
65
+ if (event.key === 'ArrowRight') {
66
+ event.preventDefault();
67
+ setSelectedIndex(function (prev) {
68
+ return (prev + 1) % availableTabs.length;
69
+ });
70
+ }
71
+ if (event.key === 'ArrowLeft') {
72
+ event.preventDefault();
73
+ setSelectedIndex(function (prev) {
74
+ return (prev - 1 + availableTabs.length) % availableTabs.length;
75
+ });
76
+ }
77
+ };
78
+ var renderTabLabel = function renderTabLabel(type) {
79
+ if (type === 'image') return 'Images';
80
+ if (type === 'video') return 'Videos';
81
+ if (type === 'file') return 'Files';
82
+ return type;
83
+ };
84
+ var renderPanel = function renderPanel(type) {
85
+ if (type === 'image') {
86
+ return /*#__PURE__*/_jsx(ImagesGallery, {
87
+ imagePopup: imagePopup,
88
+ update_data: update_data,
89
+ current_data: current_data,
90
+ closePopup: closePopup,
91
+ apiService: apiService,
92
+ onError: onError,
93
+ gridClassName: gridClassName,
94
+ imageItemClassName: imageItemClassName,
95
+ paginationContainerClassName: paginationContainerClassName
96
+ });
97
+ }
98
+ if (type === 'video') {
99
+ return /*#__PURE__*/_jsx(VideosGallery, {
100
+ imagePopup: imagePopup,
101
+ update_data: update_data,
102
+ current_data: current_data,
103
+ closePopup: closePopup,
104
+ apiService: apiService,
105
+ onError: onError,
106
+ gridClassName: gridClassName,
107
+ videoItemClassName: videoItemClassName,
108
+ paginationContainerClassName: paginationContainerClassName
109
+ });
110
+ }
111
+ if (type === 'file') {
112
+ // Reuse ImagesGallery for files as in original implementation
113
+ return /*#__PURE__*/_jsx(ImagesGallery, {
114
+ imagePopup: imagePopup,
115
+ update_data: update_data,
116
+ current_data: current_data,
117
+ closePopup: closePopup,
118
+ apiService: apiService,
119
+ onError: onError,
120
+ gridClassName: gridClassName,
121
+ imageItemClassName: imageItemClassName,
122
+ paginationContainerClassName: paginationContainerClassName
123
+ });
124
+ }
125
+ return null;
126
+ };
127
+ return /*#__PURE__*/_jsxs("div", {
128
+ className: className || defaultTabGroupClass,
129
+ children: [/*#__PURE__*/_jsx("div", {
130
+ className: tabListClassName || defaultTabListClass,
131
+ role: "tablist",
132
+ "aria-orientation": "horizontal",
133
+ children: availableTabs.map(function (type, index) {
134
+ var isSelected = index === selectedIndex;
135
+ var baseClass = tabButtonClassName || defaultTabButtonBaseClass;
136
+ var activeClass = tabButtonActiveClassName || defaultTabButtonActiveClass;
137
+ var inactiveClass = tabButtonInactiveClassName || defaultTabButtonInactiveClass;
138
+ var tabClassName = classNames(baseClass, isSelected ? activeClass : inactiveClass);
139
+ var id = type === 'image' ? 'image-tab-button' : type === 'video' ? 'video-tab-button' : 'file-tab-button';
140
+ return /*#__PURE__*/_jsx("button", {
141
+ id: id,
142
+ type: "button",
143
+ role: "tab",
144
+ "aria-selected": isSelected,
145
+ "aria-controls": "".concat(id, "-panel"),
146
+ tabIndex: isSelected ? 0 : -1,
147
+ className: tabClassName,
148
+ onClick: function onClick() {
149
+ return setSelectedIndex(index);
150
+ },
151
+ onKeyDown: function onKeyDown(e) {
152
+ return handleKeyDown(e, index);
153
+ },
154
+ children: /*#__PURE__*/_jsx("span", {
155
+ children: renderTabLabel(type)
156
+ })
157
+ }, type);
158
+ })
159
+ }), /*#__PURE__*/_jsx("div", {
160
+ className: "h-full",
161
+ role: "tabpanel",
162
+ children: availableTabs.map(function (type, index) {
163
+ var isSelected = index === selectedIndex;
164
+ var id = type === 'image' ? 'image-tab-button' : type === 'video' ? 'video-tab-button' : 'file-tab-button';
165
+ return /*#__PURE__*/_jsx("div", {
166
+ id: "".concat(id, "-panel"),
167
+ role: "tabpanel",
168
+ "aria-labelledby": id,
169
+ hidden: !isSelected,
170
+ className: tabPanelClassName || defaultTabPanelClass,
171
+ children: isSelected && renderPanel(type)
172
+ }, type);
173
+ })
174
+ })]
175
+ });
176
+ };
177
+ export default MediaTab;
@@ -0,0 +1,134 @@
1
+ import React from 'react';
2
+ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
3
+ var Pagination = function Pagination(_ref) {
4
+ var className = _ref.className,
5
+ nextPage = _ref.nextPage,
6
+ current_page = _ref.current_page,
7
+ pageCount = _ref.pageCount,
8
+ navClassName = _ref.navClassName,
9
+ previousButtonClassName = _ref.previousButtonClassName,
10
+ nextButtonClassName = _ref.nextButtonClassName,
11
+ pageButtonClassName = _ref.pageButtonClassName,
12
+ pageButtonActiveClassName = _ref.pageButtonActiveClassName,
13
+ ellipsisClassName = _ref.ellipsisClassName;
14
+ var totalPages = Math.ceil(pageCount) || 1;
15
+ var currentPage = current_page || 1;
16
+
17
+ // Generate page numbers to display
18
+ var getPageNumbers = function getPageNumbers() {
19
+ var pages = [];
20
+ var maxVisible = 5;
21
+ var startPage = Math.max(1, currentPage - Math.floor(maxVisible / 2));
22
+ var endPage = Math.min(totalPages, startPage + maxVisible - 1);
23
+ if (endPage - startPage < maxVisible - 1) {
24
+ startPage = Math.max(1, endPage - maxVisible + 1);
25
+ }
26
+
27
+ // Add first page and ellipsis
28
+ if (startPage > 1) {
29
+ pages.push(1);
30
+ if (startPage > 2) {
31
+ pages.push('...');
32
+ }
33
+ }
34
+
35
+ // Add visible pages
36
+ for (var i = startPage; i <= endPage; i++) {
37
+ pages.push(i);
38
+ }
39
+
40
+ // Add ellipsis and last page
41
+ if (endPage < totalPages) {
42
+ if (endPage < totalPages - 1) {
43
+ pages.push('...');
44
+ }
45
+ pages.push(totalPages);
46
+ }
47
+ return pages;
48
+ };
49
+ var handlePageClick = function handlePageClick(page) {
50
+ if (page !== currentPage && page >= 1 && page <= totalPages) {
51
+ nextPage(page);
52
+ }
53
+ };
54
+ var handlePrevious = function handlePrevious() {
55
+ if (currentPage > 1) {
56
+ nextPage(currentPage - 1);
57
+ }
58
+ };
59
+ var handleNext = function handleNext() {
60
+ if (currentPage < totalPages) {
61
+ nextPage(currentPage + 1);
62
+ }
63
+ };
64
+ if (totalPages <= 1) return null;
65
+ var pageNumbers = getPageNumbers();
66
+
67
+ // Default classes with customization support
68
+ var defaultContainerClass = 'flex justify-center';
69
+ var defaultNavClass = 'relative z-0 inline-flex flex-wrap justify-center rounded-md shadow-sm -space-x-px';
70
+ var defaultPreviousButtonClass = 'relative inline-flex items-center px-2 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50';
71
+ var defaultNextButtonClass = 'relative inline-flex items-center px-2 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-500 hover:bg-gray-50';
72
+ var defaultPageButtonClass = 'relative inline-flex items-center px-4 py-2 border bg-white border-gray-300 text-gray-500 hover:bg-gray-50 text-sm font-medium';
73
+ var defaultPageButtonActiveClass = 'z-10 bg-primary border-primary text-white relative inline-flex items-center px-4 py-2 border text-md font-semibold';
74
+ var defaultEllipsisClass = 'relative inline-flex items-center px-4 py-2 border border-gray-300 bg-white text-sm font-medium text-gray-700';
75
+ return /*#__PURE__*/_jsx("div", {
76
+ className: className || defaultContainerClass,
77
+ children: /*#__PURE__*/_jsxs("nav", {
78
+ className: navClassName || defaultNavClass,
79
+ children: [/*#__PURE__*/_jsx("button", {
80
+ onClick: handlePrevious,
81
+ disabled: currentPage === 1,
82
+ className: "".concat(previousButtonClassName || defaultPreviousButtonClass, " ").concat(currentPage === 1 ? 'opacity-50 cursor-not-allowed' : ''),
83
+ "aria-label": "Previous page",
84
+ children: /*#__PURE__*/_jsx("svg", {
85
+ className: "h-5 w-5",
86
+ xmlns: "http://www.w3.org/2000/svg",
87
+ viewBox: "0 0 20 20",
88
+ fill: "currentColor",
89
+ "aria-hidden": "true",
90
+ children: /*#__PURE__*/_jsx("path", {
91
+ fillRule: "evenodd",
92
+ d: "M12.707 5.293a1 1 0 010 1.414L9.414 10l3.293 3.293a1 1 0 01-1.414 1.414l-4-4a1 1 0 010-1.414l4-4a1 1 0 011.414 0z",
93
+ clipRule: "evenodd"
94
+ })
95
+ })
96
+ }), pageNumbers.map(function (page, index) {
97
+ if (page === '...') {
98
+ return /*#__PURE__*/_jsx("span", {
99
+ className: ellipsisClassName || defaultEllipsisClass,
100
+ children: "..."
101
+ }, "ellipsis-".concat(index));
102
+ }
103
+ var isActive = page === currentPage;
104
+ return /*#__PURE__*/_jsx("button", {
105
+ onClick: function onClick() {
106
+ return handlePageClick(page);
107
+ },
108
+ className: isActive ? pageButtonActiveClassName || defaultPageButtonActiveClass : pageButtonClassName || defaultPageButtonClass,
109
+ "aria-label": "Page ".concat(page),
110
+ "aria-current": isActive ? 'page' : undefined,
111
+ children: page
112
+ }, page);
113
+ }), /*#__PURE__*/_jsx("button", {
114
+ onClick: handleNext,
115
+ disabled: currentPage === totalPages,
116
+ className: "".concat(nextButtonClassName || defaultNextButtonClass, " ").concat(currentPage === totalPages ? 'opacity-50 cursor-not-allowed' : ''),
117
+ "aria-label": "Next page",
118
+ children: /*#__PURE__*/_jsx("svg", {
119
+ className: "h-5 w-5",
120
+ xmlns: "http://www.w3.org/2000/svg",
121
+ viewBox: "0 0 20 20",
122
+ fill: "currentColor",
123
+ "aria-hidden": "true",
124
+ children: /*#__PURE__*/_jsx("path", {
125
+ fillRule: "evenodd",
126
+ d: "M7.293 14.707a1 1 0 010-1.414L10.586 10 7.293 6.707a1 1 0 011.414-1.414l4 4a1 1 0 010 1.414l-4 4a1 1 0 01-1.414 0z",
127
+ clipRule: "evenodd"
128
+ })
129
+ })
130
+ })]
131
+ })
132
+ });
133
+ };
134
+ export default Pagination;
@@ -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 VIDEO_MIME_TYPES = ['video/mp4', 'video/quicktime', 'video/x-ms-wmv', 'video/h265', 'video/hevc', 'video/webm'];
17
+ var VideosGallery = function VideosGallery(_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
+ videoItemClassName = _ref.videoItemClassName,
25
+ paginationContainerClassName = _ref.paginationContainerClassName;
26
+ var _useState = useState([]),
27
+ _useState2 = _slicedToArray(_useState, 2),
28
+ videos = _useState2[0],
29
+ setVideos = _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 videos
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: VIDEO_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
+ setVideos(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 videos:', _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 handleVideoClick = function handleVideoClick(video) {
97
+ if (update_data) {
98
+ update_data(video.url || video);
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(180px),1fr))] gap-5';
108
+ var defaultVideoItemClass = 'cursor-pointer w-full h-40 object-contain 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: "video/*",
117
+ title: "Add Video",
118
+ apiService: apiService,
119
+ onUploadError: onError
120
+ }), isLoading ? /*#__PURE__*/_jsx(ImagesSkeleton, {}) : videos === null || videos === void 0 ? void 0 : videos.map(function (video, index) {
121
+ var videoUrl = typeof video === 'string' ? video : video.url;
122
+ var videoKey = video.id || video.url || index;
123
+ return /*#__PURE__*/_jsx("video", {
124
+ onClick: function onClick() {
125
+ return handleVideoClick(video);
126
+ },
127
+ className: videoItemClassName || defaultVideoItemClass,
128
+ controls: true,
129
+ src: videoUrl
130
+ }, videoKey);
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 VideosGallery;
package/dist/index.js CHANGED
@@ -18,7 +18,7 @@ Object.defineProperty(exports, "ImagesGallery", {
18
18
  Object.defineProperty(exports, "MediaApiService", {
19
19
  enumerable: true,
20
20
  get: function get() {
21
- return _apiService.default;
21
+ return _MediaApiService.default;
22
22
  }
23
23
  });
24
24
  Object.defineProperty(exports, "MediaPopup", {
@@ -45,7 +45,7 @@ var _MediaTab = _interopRequireDefault(require("./components/MediaTab"));
45
45
  var _MediaGallery = _interopRequireDefault(require("./components/MediaGallery"));
46
46
  var _VideosGallery = _interopRequireDefault(require("./components/VideosGallery"));
47
47
  var _FileUpload = _interopRequireDefault(require("./components/FileUpload"));
48
- var _apiService = _interopRequireDefault(require("./services/apiService"));
48
+ var _MediaApiService = _interopRequireDefault(require("./core/MediaApiService"));
49
49
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
50
50
  /**
51
51
  * @tradly/asset