@quintoandar-tokko/gridimagepicker 1.0.17

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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2019 One Loop
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,201 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _react = _interopRequireWildcard(require("react"));
9
+ var _sortable = require("@dnd-kit/sortable");
10
+ var _utilities = require("@dnd-kit/utilities");
11
+ var _box = require("@quintoandar-tokko/box");
12
+ var _icons = require("@quintoandar-tokko/icons");
13
+ var _useSize3 = _interopRequireDefault(require("./hooks/useSize"));
14
+ var _useAspectRatio3 = _interopRequireDefault(require("./hooks/useAspectRatio"));
15
+ var _getTooltipErrorText = require("./utils/getTooltipErrorText");
16
+ var _manageItem = require("./utils/manageItem");
17
+ require("../styles/ImageItem.css");
18
+ require("../styles/ImageItemBlanket.css");
19
+ require("../styles/ImageItemCover.css");
20
+ require("../styles/ImageItemSmallElements.css");
21
+ require("../styles/ImageItemTooltip.css");
22
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
23
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
24
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { "default": e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n["default"] = e, t && t.set(e, n), n; }
25
+ function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
26
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
27
+ 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."); }
28
+ 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; } }
29
+ 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; }
30
+ 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; } }
31
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
32
+ var ImageItem = function ImageItem(_ref) {
33
+ var item = _ref.item,
34
+ handleClick = _ref.handleClick,
35
+ handleUpdateItem = _ref.handleUpdateItem,
36
+ onEdit = _ref.onEdit,
37
+ status = _ref.status,
38
+ config = _ref.config,
39
+ texts = _ref.texts,
40
+ sizeFetcher = _ref.sizeFetcher;
41
+ var _useSortable = (0, _sortable.useSortable)({
42
+ id: item.id
43
+ }),
44
+ attributes = _useSortable.attributes,
45
+ listeners = _useSortable.listeners,
46
+ setNodeRef = _useSortable.setNodeRef,
47
+ transform = _useSortable.transform,
48
+ transition = _useSortable.transition;
49
+ var _useSize = (0, _useSize3["default"])(item.src, sizeFetcher),
50
+ _useSize2 = _slicedToArray(_useSize, 3),
51
+ size = _useSize2[0],
52
+ isLoadingSize = _useSize2[1],
53
+ isErrorSize = _useSize2[2];
54
+ var _useAspectRatio = (0, _useAspectRatio3["default"])(item.src),
55
+ _useAspectRatio2 = _slicedToArray(_useAspectRatio, 5),
56
+ height = _useAspectRatio2[0],
57
+ width = _useAspectRatio2[1],
58
+ aspectRatio = _useAspectRatio2[2],
59
+ isLoadingAspectRatio = _useAspectRatio2[3],
60
+ isErrorAspectRatio = _useAspectRatio2[4];
61
+ var wrapperRef = (0, _react.useRef)(null);
62
+ var _useState = (0, _react.useState)({
63
+ left: 0,
64
+ top: 0
65
+ }),
66
+ _useState2 = _slicedToArray(_useState, 2),
67
+ tooltipPosition = _useState2[0],
68
+ setTooltipPosition = _useState2[1];
69
+ var _useState3 = (0, _react.useState)(false),
70
+ _useState4 = _slicedToArray(_useState3, 2),
71
+ isTooltipShowable = _useState4[0],
72
+ setIsTooltipShowable = _useState4[1];
73
+ var isDraggingActive = status.isDraggingActive,
74
+ isMaxSelectableReached = status.isMaxSelectableReached,
75
+ itemsAreReady = status.itemsAreReady;
76
+ var maxSizeInMB = config.maxSizeInMB,
77
+ minAspectRatio = config.minAspectRatio,
78
+ maxAspectRatio = config.maxAspectRatio;
79
+ var isLoading = item.loading;
80
+ var isError = item.sizeError || item.aspectRatioError || item.fetchError;
81
+ var isFizableError = !item.fetchError && onEdit;
82
+ var tooltipErrorText = (0, _getTooltipErrorText.getTooltipErrorText)(item, texts, onEdit);
83
+ var backgroundImage = item.loading || item.fetchError ? '' : "url(".concat(item.src, ")");
84
+ var unclickable = !(0, _manageItem.isItemClickable)(item, isMaxSelectableReached, itemsAreReady);
85
+ var disabled = (0, _manageItem.isDisabledCheckbox)(item, isMaxSelectableReached);
86
+ (0, _react.useEffect)(function () {
87
+ var handleHideTooltip = function handleHideTooltip() {
88
+ setIsTooltipShowable(false);
89
+ };
90
+ document.addEventListener('wheel', handleHideTooltip);
91
+ document.addEventListener('scroll', handleHideTooltip);
92
+ return function () {
93
+ document.removeEventListener('wheel', handleHideTooltip);
94
+ document.removeEventListener('scroll', handleHideTooltip);
95
+ };
96
+ }, []);
97
+ (0, _react.useEffect)(function () {
98
+ var id = item.id;
99
+ var sizeError = !isNaN(maxSizeInMB) && size > maxSizeInMB;
100
+ var aspectRatioError = !isNaN(maxAspectRatio) && aspectRatio > maxAspectRatio || !isNaN(minAspectRatio) && aspectRatio < minAspectRatio;
101
+ var fetchError = isErrorSize || isErrorAspectRatio;
102
+ var loading = isLoadingSize || isLoadingAspectRatio;
103
+ handleUpdateItem({
104
+ id: id,
105
+ size: size,
106
+ sizeError: sizeError,
107
+ height: height,
108
+ width: width,
109
+ aspectRatio: aspectRatio,
110
+ aspectRatioError: aspectRatioError,
111
+ fetchError: fetchError,
112
+ loading: loading
113
+ });
114
+ }, [size, isLoadingSize, isErrorSize, aspectRatio, isLoadingAspectRatio, isErrorAspectRatio]);
115
+ var calculateTooltipPosition = function calculateTooltipPosition() {
116
+ var parent = document.querySelector('.gridImagePickerContainer');
117
+ var parentRects = parent.getBoundingClientRect();
118
+ var imageRects = wrapperRef.current.getBoundingClientRect();
119
+ var left = imageRects.left - parentRects.left + imageRects.width / 2;
120
+ var top = imageRects.top - parentRects.top;
121
+ setTooltipPosition({
122
+ left: left,
123
+ top: top
124
+ });
125
+ };
126
+ var handleMouseMove = function handleMouseMove() {
127
+ var shouldShowTooltip = Boolean(tooltipErrorText);
128
+ calculateTooltipPosition();
129
+ setIsTooltipShowable(shouldShowTooltip);
130
+ };
131
+ var handleEdit = function handleEdit(e) {
132
+ e.stopPropagation();
133
+ onEdit(item);
134
+ };
135
+ return /*#__PURE__*/_react["default"].createElement(_box.Box, {
136
+ className: "imageItemOuterWrapper"
137
+ }, /*#__PURE__*/_react["default"].createElement(_box.Box, _extends({
138
+ ref: function ref(node) {
139
+ setNodeRef(node);
140
+ wrapperRef.current = node;
141
+ },
142
+ as: "button",
143
+ className: "imageItemWrapper",
144
+ onClick: function onClick() {
145
+ return isFizableError && isError ? onEdit(item) : handleClick(item);
146
+ },
147
+ onMouseMove: handleMouseMove,
148
+ "data-dragging": isDraggingActive,
149
+ __css: {
150
+ backgroundImage: backgroundImage
151
+ },
152
+ style: {
153
+ transform: _utilities.CSS.Transform.toString(transform),
154
+ transition: transition
155
+ }
156
+ }, attributes, listeners), /*#__PURE__*/_react["default"].createElement(_box.Box, {
157
+ className: "imageItemBlanket",
158
+ "data-light": unclickable,
159
+ "data-dark": item.checked,
160
+ "data-grey": isError
161
+ }), /*#__PURE__*/_react["default"].createElement(_box.Box, {
162
+ className: "imageItemCount",
163
+ "data-visible": item.checked
164
+ }, item.position), /*#__PURE__*/_react["default"].createElement(_box.Box, {
165
+ className: "imageItemCover",
166
+ "data-visible": item.position === 1
167
+ }, /*#__PURE__*/_react["default"].createElement(_box.Box, {
168
+ className: "imageItemCoverText"
169
+ }, " ", texts.cover, " ")), /*#__PURE__*/_react["default"].createElement(_box.Box, {
170
+ className: "imageItemCheckbox",
171
+ "data-active": item.checked,
172
+ "data-disabled": disabled,
173
+ "data-visible": !unclickable
174
+ }, /*#__PURE__*/_react["default"].createElement(_icons.Check, {
175
+ className: "imageItemIconCheck",
176
+ color: "white"
177
+ })), /*#__PURE__*/_react["default"].createElement(_box.Box, {
178
+ className: "imageItemError",
179
+ "data-visible": isError && !isLoading
180
+ }, /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
181
+ icon: "icon-error",
182
+ className: "imageItemIconError"
183
+ })), /*#__PURE__*/_react["default"].createElement(_box.Box, {
184
+ className: "imageItemEdit",
185
+ "data-visible": isFizableError && !isLoading,
186
+ onClick: function onClick(e) {
187
+ return handleEdit(e);
188
+ }
189
+ }, /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
190
+ icon: "icon-editar",
191
+ className: "imageItemIconEdit"
192
+ }))), /*#__PURE__*/_react["default"].createElement(_box.Box, {
193
+ className: "imageItemTooltip",
194
+ "data-showable": isTooltipShowable,
195
+ __css: {
196
+ left: tooltipPosition.left,
197
+ top: tooltipPosition.top
198
+ }
199
+ }, tooltipErrorText));
200
+ };
201
+ var _default = exports["default"] = ImageItem;
@@ -0,0 +1,94 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _react = require("react");
9
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
10
+ 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); }
11
+ 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); }); }; }
12
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
13
+ 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."); }
14
+ 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; } }
15
+ 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; }
16
+ 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; } }
17
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
18
+ function useAspectRatio(src) {
19
+ var _useState = (0, _react.useState)({
20
+ height: 0,
21
+ width: 0,
22
+ aspectRatio: 0,
23
+ loading: true,
24
+ error: false
25
+ }),
26
+ _useState2 = _slicedToArray(_useState, 2),
27
+ data = _useState2[0],
28
+ setData = _useState2[1];
29
+ (0, _react.useEffect)(function () {
30
+ var fetchAspectRatio = /*#__PURE__*/function () {
31
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(src) {
32
+ var img;
33
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
34
+ while (1) switch (_context.prev = _context.next) {
35
+ case 0:
36
+ try {
37
+ setData({
38
+ height: 0,
39
+ width: 0,
40
+ aspectRatio: 0,
41
+ loading: true,
42
+ error: false
43
+ });
44
+ img = new window.Image();
45
+ img.src = src;
46
+ img.onload = function () {
47
+ var height = img.height;
48
+ var width = img.width;
49
+ var aspectRatio = img.width / img.height;
50
+ setData({
51
+ height: height,
52
+ width: width,
53
+ aspectRatio: aspectRatio,
54
+ loading: false,
55
+ error: false
56
+ });
57
+ };
58
+ img.onerror = function (error) {
59
+ console.error(error);
60
+ setData({
61
+ height: 0,
62
+ width: 0,
63
+ aspectRatio: 0,
64
+ loading: false,
65
+ error: true
66
+ });
67
+ };
68
+ } catch (error) {
69
+ console.error(error);
70
+ setData({
71
+ height: 0,
72
+ width: 0,
73
+ aspectRatio: 0,
74
+ loading: false,
75
+ error: true
76
+ });
77
+ }
78
+ case 1:
79
+ case "end":
80
+ return _context.stop();
81
+ }
82
+ }, _callee);
83
+ }));
84
+ return function fetchAspectRatio(_x) {
85
+ return _ref.apply(this, arguments);
86
+ };
87
+ }();
88
+ if (src) {
89
+ fetchAspectRatio(src);
90
+ }
91
+ }, [src]);
92
+ return [data.height, data.width, data.aspectRatio, data.loading, data.error];
93
+ }
94
+ var _default = exports["default"] = useAspectRatio;
@@ -0,0 +1,152 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _react = require("react");
9
+ var _sortable = require("@dnd-kit/sortable");
10
+ var _manageItem = require("../utils/manageItem");
11
+ var _manageListOfItems = require("../utils/manageListOfItems");
12
+ var _excluded = ["id"];
13
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
16
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
17
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
18
+ function _objectWithoutProperties(e, t) { if (null == e) return {}; var o, r, i = _objectWithoutPropertiesLoose(e, t); if (Object.getOwnPropertySymbols) { var s = Object.getOwnPropertySymbols(e); for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]); } return i; }
19
+ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t = {}; for (var n in r) if ({}.hasOwnProperty.call(r, n)) { if (e.includes(n)) continue; t[n] = r[n]; } return t; }
20
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
21
+ 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."); }
22
+ 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; } }
23
+ 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; }
24
+ 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; } }
25
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
26
+ function useGridImagePicker(_ref) {
27
+ var listOfSrc = _ref.listOfSrc,
28
+ maxSelectablePreferenceByUser = _ref.maxSelectablePreferenceByUser,
29
+ maxSizeInMB = _ref.maxSizeInMB,
30
+ minAspectRatio = _ref.minAspectRatio,
31
+ maxAspectRatio = _ref.maxAspectRatio,
32
+ onChange = _ref.onChange;
33
+ var _useState = (0, _react.useState)(false),
34
+ _useState2 = _slicedToArray(_useState, 2),
35
+ isDraggingActive = _useState2[0],
36
+ setIsDraggingActive = _useState2[1];
37
+ var _useState3 = (0, _react.useState)(listOfSrc),
38
+ _useState4 = _slicedToArray(_useState3, 2),
39
+ initialUrlList = _useState4[0],
40
+ setInitialUrlList = _useState4[1];
41
+ var _useState5 = (0, _react.useState)(null),
42
+ _useState6 = _slicedToArray(_useState5, 2),
43
+ itemNewUrl = _useState6[0],
44
+ setItemNewUrl = _useState6[1];
45
+ var _useState7 = (0, _react.useState)(function () {
46
+ return (0, _manageListOfItems.getItemsInitialState)(listOfSrc);
47
+ }),
48
+ _useState8 = _slicedToArray(_useState7, 2),
49
+ items = _useState8[0],
50
+ setItems = _useState8[1];
51
+ (0, _react.useEffect)(function () {
52
+ setItemNewUrl((0, _manageListOfItems.getItemChanged)(initialUrlList, listOfSrc));
53
+ }, [listOfSrc]);
54
+ (0, _react.useEffect)(function () {
55
+ if (!itemNewUrl) return;
56
+ setItems(function (prevItems) {
57
+ return (0, _manageListOfItems.getItemsWithNewUrl)(prevItems, itemNewUrl);
58
+ });
59
+ setInitialUrlList(listOfSrc);
60
+ setItemNewUrl(null);
61
+ }, [itemNewUrl]);
62
+ var maxSelectable = Math.min(maxSelectablePreferenceByUser, items.filter(function (item) {
63
+ return !item.sizeError && !item.aspectRatioError && !item.fetchError;
64
+ }).length);
65
+ var numberOfCheckedItems = items.filter(function (item) {
66
+ return item.checked;
67
+ }).length;
68
+ var isMaxSelectableReached = numberOfCheckedItems >= maxSelectable;
69
+ var itemsAreReady = items.every(function (item) {
70
+ return !item.loading;
71
+ });
72
+ var config = {
73
+ maxSizeInMB: maxSizeInMB,
74
+ minAspectRatio: minAspectRatio,
75
+ maxAspectRatio: maxAspectRatio,
76
+ maxSelectable: maxSelectable
77
+ };
78
+ var status = {
79
+ isDraggingActive: isDraggingActive,
80
+ isMaxSelectableReached: isMaxSelectableReached,
81
+ itemsAreReady: itemsAreReady,
82
+ numberOfCheckedItems: numberOfCheckedItems
83
+ };
84
+ (0, _react.useEffect)(function () {
85
+ if (!onChange) return;
86
+ onChange(items);
87
+ }, [items]);
88
+ (0, _react.useEffect)(function () {
89
+ if (!itemsAreReady) return;
90
+ var updatedItems = (0, _manageListOfItems.fillCheckedItems)(items, maxSelectable);
91
+ setItems(updatedItems);
92
+ }, [itemsAreReady]);
93
+ var handleClickItem = function handleClickItem(targetItem) {
94
+ var isUnclickable = !(0, _manageItem.isItemClickable)(targetItem, isMaxSelectableReached, itemsAreReady);
95
+ if (isUnclickable) return;
96
+ var updatedItems = targetItem.checked ? (0, _manageListOfItems.getUpdatedItemsWithDecrement)(items, targetItem) : (0, _manageListOfItems.getUpdatedItemsWithIncrement)(items, targetItem);
97
+ var refreshedItems = (0, _manageListOfItems.refreshItemsPosition)(updatedItems);
98
+ setItems(refreshedItems);
99
+ };
100
+ var handleSelectAll = function handleSelectAll() {
101
+ var newItems = (0, _manageListOfItems.getSelectAllItems)(items, maxSelectable);
102
+ var refreshedItems = (0, _manageListOfItems.refreshItemsPosition)(newItems);
103
+ setItems(refreshedItems);
104
+ };
105
+ var handleDeselectAll = function handleDeselectAll() {
106
+ var newItems = (0, _manageListOfItems.getDeselectAllItems)(items);
107
+ setItems(newItems);
108
+ };
109
+ var handleUpdateItem = function handleUpdateItem(_ref2) {
110
+ var id = _ref2.id,
111
+ restOfKeys = _objectWithoutProperties(_ref2, _excluded);
112
+ setItems(function (prevItems) {
113
+ return prevItems.map(function (item) {
114
+ return item.id === id ? _objectSpread(_objectSpread({}, item), restOfKeys) : item;
115
+ });
116
+ });
117
+ };
118
+ var handleDragStart = function handleDragStart() {
119
+ setIsDraggingActive(true);
120
+ };
121
+ var handleDragEnd = function handleDragEnd(_ref3) {
122
+ var active = _ref3.active,
123
+ over = _ref3.over;
124
+ setIsDraggingActive(false);
125
+ if (active.id === over.id) return;
126
+ var oldIndex = items.findIndex(function (item) {
127
+ return item.id === active.id;
128
+ });
129
+ var newIndex = items.findIndex(function (item) {
130
+ return item.id === over.id;
131
+ });
132
+ var reorderedItems = (0, _sortable.arrayMove)(items, oldIndex, newIndex);
133
+ var refreshedItems = (0, _manageListOfItems.refreshItemsPosition)(reorderedItems);
134
+ setItems(refreshedItems);
135
+ };
136
+ return {
137
+ attributes: {
138
+ items: items,
139
+ config: config,
140
+ status: status
141
+ },
142
+ methods: {
143
+ handleClickItem: handleClickItem,
144
+ handleUpdateItem: handleUpdateItem,
145
+ handleDeselectAll: handleDeselectAll,
146
+ handleSelectAll: handleSelectAll,
147
+ handleDragStart: handleDragStart,
148
+ handleDragEnd: handleDragEnd
149
+ }
150
+ };
151
+ }
152
+ var _default = exports["default"] = useGridImagePicker;
@@ -0,0 +1,98 @@
1
+ "use strict";
2
+
3
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports["default"] = void 0;
8
+ var _react = require("react");
9
+ function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
10
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length); for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e]; return n; }
13
+ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t["return"] && (u = t["return"](), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
14
+ function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
15
+ function _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator["return"] && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, "catch": function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
16
+ 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); }
17
+ 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); }); }; }
18
+ var defaultFetcher = /*#__PURE__*/function () {
19
+ var _ref = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee(url) {
20
+ return _regeneratorRuntime().wrap(function _callee$(_context) {
21
+ while (1) switch (_context.prev = _context.next) {
22
+ case 0:
23
+ return _context.abrupt("return", window.fetch(url));
24
+ case 1:
25
+ case "end":
26
+ return _context.stop();
27
+ }
28
+ }, _callee);
29
+ }));
30
+ return function defaultFetcher(_x) {
31
+ return _ref.apply(this, arguments);
32
+ };
33
+ }();
34
+ function useSize(src) {
35
+ var sizeFetcher = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : defaultFetcher;
36
+ var _useState = (0, _react.useState)({
37
+ size: 0,
38
+ loading: true,
39
+ error: false
40
+ }),
41
+ _useState2 = _slicedToArray(_useState, 2),
42
+ data = _useState2[0],
43
+ setData = _useState2[1];
44
+ (0, _react.useEffect)(function () {
45
+ var fetchImageSize = /*#__PURE__*/function () {
46
+ var _ref2 = _asyncToGenerator(/*#__PURE__*/_regeneratorRuntime().mark(function _callee2(src) {
47
+ var response, blob, sizeInMegaBytes;
48
+ return _regeneratorRuntime().wrap(function _callee2$(_context2) {
49
+ while (1) switch (_context2.prev = _context2.next) {
50
+ case 0:
51
+ _context2.prev = 0;
52
+ setData({
53
+ size: 0,
54
+ loading: true,
55
+ error: false
56
+ });
57
+ _context2.next = 4;
58
+ return sizeFetcher(src);
59
+ case 4:
60
+ response = _context2.sent;
61
+ _context2.next = 7;
62
+ return response.blob();
63
+ case 7:
64
+ blob = _context2.sent;
65
+ sizeInMegaBytes = blob.size / 1024 / 1024;
66
+ setData({
67
+ size: sizeInMegaBytes,
68
+ loading: false,
69
+ error: false
70
+ });
71
+ _context2.next = 16;
72
+ break;
73
+ case 12:
74
+ _context2.prev = 12;
75
+ _context2.t0 = _context2["catch"](0);
76
+ console.error(_context2.t0);
77
+ setData({
78
+ size: 0,
79
+ loading: false,
80
+ error: true
81
+ });
82
+ case 16:
83
+ case "end":
84
+ return _context2.stop();
85
+ }
86
+ }, _callee2, null, [[0, 12]]);
87
+ }));
88
+ return function fetchImageSize(_x2) {
89
+ return _ref2.apply(this, arguments);
90
+ };
91
+ }();
92
+ if (src) {
93
+ fetchImageSize(src);
94
+ }
95
+ }, [src]);
96
+ return [data.size, data.loading, data.error];
97
+ }
98
+ var _default = exports["default"] = useSize;
package/lib/index.js ADDED
@@ -0,0 +1,107 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = exports.GridImagePicker = void 0;
7
+ var _react = _interopRequireDefault(require("react"));
8
+ var _core = require("@dnd-kit/core");
9
+ var _sortable = require("@dnd-kit/sortable");
10
+ var _box = require("@quintoandar-tokko/box");
11
+ var _ImageItem = _interopRequireDefault(require("./ImageItem"));
12
+ var _useGridImagePicker2 = _interopRequireDefault(require("./hooks/useGridImagePicker"));
13
+ require("../styles/GridImagePicker.css");
14
+ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
15
+ /**
16
+ * A grid-based image picker component with sortable and selectable images.
17
+ *
18
+ * @param {Object} props - The props for GridImagePicker.
19
+ * @param {string[]} props.listOfSrc - Array of image URLs to display in the grid.
20
+ * @param {number} [props.maxSelectablePreferenceByUser=10] - Maximum number of images that can be selected by the user.
21
+ * Default is 10. This value is a preference; if there are fewer images available than this number, it will adjust accordingly.
22
+ * @param {number} [props.maxSizeInMB=8] - Maximum size in megabytes for each image. Default is 8 MB. Images exceeding this limit will be marked as an error.
23
+ * @param {number} [props.minAspectRatio] - Minimum aspect ratio allowed for the images. Images that don't meet this ratio will be marked as an error.
24
+ * @param {number} [props.maxAspectRatio] - Maximum aspect ratio allowed for the images. Images that exceed this ratio will be marked as an error.
25
+ * @param {Function} [props.onChange] - Optional callback function invoked whenever the internal state of images changes.
26
+ * Called with the updated list of items as `(items) => onChange(items)`.
27
+ * @param {Function} [props.sizeFetcher] - Optional fetch function to get the size of the images. Default: (src) => fetch(src)
28
+ * @param {Object} props.texts - Nested texts
29
+ */
30
+ var GridImagePicker = exports.GridImagePicker = function GridImagePicker(_ref) {
31
+ var listOfSrc = _ref.listOfSrc,
32
+ _ref$maxSelectablePre = _ref.maxSelectablePreferenceByUser,
33
+ maxSelectablePreferenceByUser = _ref$maxSelectablePre === void 0 ? 10 : _ref$maxSelectablePre,
34
+ _ref$maxSizeInMB = _ref.maxSizeInMB,
35
+ maxSizeInMB = _ref$maxSizeInMB === void 0 ? 8 : _ref$maxSizeInMB,
36
+ minAspectRatio = _ref.minAspectRatio,
37
+ maxAspectRatio = _ref.maxAspectRatio,
38
+ onChange = _ref.onChange,
39
+ _ref$onEdit = _ref.onEdit,
40
+ onEdit = _ref$onEdit === void 0 ? null : _ref$onEdit,
41
+ texts = _ref.texts,
42
+ sizeFetcher = _ref.sizeFetcher;
43
+ var _useGridImagePicker = (0, _useGridImagePicker2["default"])({
44
+ listOfSrc: listOfSrc,
45
+ maxSelectablePreferenceByUser: maxSelectablePreferenceByUser,
46
+ maxSizeInMB: maxSizeInMB,
47
+ minAspectRatio: minAspectRatio,
48
+ maxAspectRatio: maxAspectRatio,
49
+ onChange: onChange
50
+ }),
51
+ attributes = _useGridImagePicker.attributes,
52
+ methods = _useGridImagePicker.methods;
53
+ var items = attributes.items,
54
+ config = attributes.config,
55
+ status = attributes.status;
56
+ var handleClickItem = methods.handleClickItem,
57
+ handleUpdateItem = methods.handleUpdateItem,
58
+ handleDeselectAll = methods.handleDeselectAll,
59
+ handleSelectAll = methods.handleSelectAll,
60
+ handleDragStart = methods.handleDragStart,
61
+ handleDragEnd = methods.handleDragEnd;
62
+ var sensors = (0, _core.useSensors)((0, _core.useSensor)(_core.MouseSensor, {
63
+ activationConstraint: {
64
+ distance: 10
65
+ }
66
+ }));
67
+ return /*#__PURE__*/_react["default"].createElement(_box.Box, {
68
+ className: "gridImagePickerContainer"
69
+ }, /*#__PURE__*/_react["default"].createElement(_box.Box, {
70
+ className: "gridButtonsWrapper"
71
+ }, /*#__PURE__*/_react["default"].createElement(_box.Box, {
72
+ as: "button",
73
+ className: "gridButton gridButtonSelect",
74
+ onClick: handleSelectAll,
75
+ disabled: status.numberOfCheckedItems === config.maxSelectable || !status.itemsAreReady
76
+ }, "Seleccionar ", status.itemsAreReady ? config.maxSelectable : 0), /*#__PURE__*/_react["default"].createElement(_box.Box, {
77
+ as: "button",
78
+ className: "gridButton gridButtonDeselect",
79
+ onClick: handleDeselectAll,
80
+ disabled: status.numberOfCheckedItems === 0
81
+ }, "Deseleccionar todos")), /*#__PURE__*/_react["default"].createElement(_core.DndContext, {
82
+ sensors: sensors,
83
+ collisionDetection: _core.closestCenter,
84
+ onDragStart: handleDragStart,
85
+ onDragEnd: handleDragEnd,
86
+ autoScroll: false
87
+ }, /*#__PURE__*/_react["default"].createElement(_sortable.SortableContext, {
88
+ items: items,
89
+ strategy: _sortable.rectSortingStrategy
90
+ }, /*#__PURE__*/_react["default"].createElement(_box.Box, {
91
+ as: "section",
92
+ className: "gridImagePicker"
93
+ }, items.map(function (item) {
94
+ return /*#__PURE__*/_react["default"].createElement(_ImageItem["default"], {
95
+ key: item.id,
96
+ item: item,
97
+ status: status,
98
+ config: config,
99
+ handleClick: handleClickItem,
100
+ onEdit: onEdit,
101
+ handleUpdateItem: handleUpdateItem,
102
+ texts: texts,
103
+ sizeFetcher: sizeFetcher
104
+ });
105
+ })))));
106
+ };
107
+ var _default = exports["default"] = GridImagePicker;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.getTooltipErrorText = void 0;
7
+ var tooltipSizeErrorDefaultText = 'The file size exceeds the allowed limit';
8
+ var tooltipAspectRatioErrorDefaultText = 'The aspect ratio of this image is not within the allowed range';
9
+ var tooltipFetchErrorDefaultText = 'The image cannot be loaded';
10
+ var tooltipImageEditionSuggestionText = 'Crop the image to publish it';
11
+ var getTooltipErrorText = exports.getTooltipErrorText = function getTooltipErrorText(item, texts, editable) {
12
+ if (item.fetchError) {
13
+ var _texts$fetchError;
14
+ return (_texts$fetchError = texts.fetchError) !== null && _texts$fetchError !== void 0 ? _texts$fetchError : tooltipFetchErrorDefaultText;
15
+ }
16
+ if (item.sizeError && !editable) {
17
+ var _texts$sizeError;
18
+ return (_texts$sizeError = texts.sizeError) !== null && _texts$sizeError !== void 0 ? _texts$sizeError : tooltipSizeErrorDefaultText;
19
+ }
20
+ if (item.aspectRatioError && !editable) {
21
+ var _texts$aspectRatioErr;
22
+ return (_texts$aspectRatioErr = texts.aspectRatioError) !== null && _texts$aspectRatioErr !== void 0 ? _texts$aspectRatioErr : tooltipAspectRatioErrorDefaultText;
23
+ }
24
+ if ((item.aspectRatioError || item.sizeError) && editable) {
25
+ var _texts$cropImageSugge;
26
+ return (_texts$cropImageSugge = texts.cropImageSuggestion) !== null && _texts$cropImageSugge !== void 0 ? _texts$cropImageSugge : tooltipImageEditionSuggestionText;
27
+ }
28
+ return null;
29
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.isItemClickable = exports.isDisabledCheckbox = void 0;
7
+ var isItemClickable = exports.isItemClickable = function isItemClickable(item, isMaxSelectableReached, itemsAreReady) {
8
+ var loading = item.loading,
9
+ sizeError = item.sizeError,
10
+ fetchError = item.fetchError,
11
+ aspectRatioError = item.aspectRatioError,
12
+ checked = item.checked;
13
+ // easier to corroborate the opposite
14
+ var isUnclickable = loading || sizeError || fetchError || aspectRatioError || !checked && isMaxSelectableReached || !itemsAreReady;
15
+ return !isUnclickable;
16
+ };
17
+ var isDisabledCheckbox = exports.isDisabledCheckbox = function isDisabledCheckbox(item, isMaxSelectableReached) {
18
+ var sizeError = item.sizeError,
19
+ fetchError = item.fetchError,
20
+ aspectRatioError = item.aspectRatioError,
21
+ checked = item.checked;
22
+ var isDisabled = !sizeError && !fetchError && !aspectRatioError && !checked && isMaxSelectableReached;
23
+ return isDisabled;
24
+ };
@@ -0,0 +1,191 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.refreshItemsPosition = exports.getUpdatedItemsWithIncrement = exports.getUpdatedItemsWithDecrement = exports.getSelectAllItems = exports.getItemsWithNewUrl = exports.getItemsInitialState = exports.getItemChanged = exports.getDeselectAllItems = exports.fillCheckedItems = void 0;
7
+ var _manageItem = require("./manageItem");
8
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
9
+ function _toConsumableArray(r) { return _arrayWithoutHoles(r) || _iterableToArray(r) || _unsupportedIterableToArray(r) || _nonIterableSpread(); }
10
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
+ function _unsupportedIterableToArray(r, a) { if (r) { if ("string" == typeof r) return _arrayLikeToArray(r, a); var t = {}.toString.call(r).slice(8, -1); return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0; } }
12
+ function _iterableToArray(r) { if ("undefined" != typeof Symbol && null != r[Symbol.iterator] || null != r["@@iterator"]) return Array.from(r); }
13
+ function _arrayWithoutHoles(r) { if (Array.isArray(r)) return _arrayLikeToArray(r); }
14
+ 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; }
15
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
16
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
17
+ function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
18
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
19
+ function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
20
+ var getItemsInitialState = exports.getItemsInitialState = function getItemsInitialState(listOfSrc) {
21
+ var initializedItem = listOfSrc.map(function (src, index) {
22
+ return {
23
+ id: index + 1,
24
+ src: src,
25
+ checked: false,
26
+ position: 0,
27
+ height: 0,
28
+ width: 0,
29
+ size: 0,
30
+ sizeError: false,
31
+ aspectRatio: 0,
32
+ aspectRatioError: false,
33
+ fetchError: false,
34
+ loading: true
35
+ };
36
+ });
37
+ return initializedItem;
38
+ };
39
+ var getItemsWithNewUrl = exports.getItemsWithNewUrl = function getItemsWithNewUrl(listOfItems, newUrlItem) {
40
+ var oldUrl = newUrlItem.oldUrl,
41
+ newUrl = newUrlItem.newUrl;
42
+ var updatedItems = listOfItems.map(function (item) {
43
+ if (item.src === oldUrl) {
44
+ return _objectSpread(_objectSpread({}, item), {}, {
45
+ src: newUrl,
46
+ hasNewUrl: true
47
+ });
48
+ }
49
+ return _objectSpread(_objectSpread({}, item), {}, {
50
+ hasNewUrl: false
51
+ });
52
+ });
53
+ return updatedItems;
54
+ };
55
+ var getUpdatedItemsWithIncrement = exports.getUpdatedItemsWithIncrement = function getUpdatedItemsWithIncrement(listOfItems, targetItem) {
56
+ var maxPosition = Math.max.apply(Math, _toConsumableArray(listOfItems.map(function (item) {
57
+ return item.position;
58
+ })));
59
+ var newItems = listOfItems.map(function (item) {
60
+ return item.id === targetItem.id ? _objectSpread(_objectSpread({}, targetItem), {}, {
61
+ checked: true,
62
+ position: maxPosition + 1
63
+ }) : item;
64
+ });
65
+ return newItems;
66
+ };
67
+ var getUpdatedItemsWithDecrement = exports.getUpdatedItemsWithDecrement = function getUpdatedItemsWithDecrement(listOfItems, targetItem) {
68
+ var targetItemPosition = targetItem.position;
69
+ var newItems = listOfItems.map(function (item) {
70
+ return item.id === targetItem.id ? _objectSpread(_objectSpread({}, item), {}, {
71
+ checked: false,
72
+ position: 0
73
+ }) : item.position > targetItemPosition ? _objectSpread(_objectSpread({}, item), {}, {
74
+ position: item.position - 1
75
+ }) : item;
76
+ });
77
+ return newItems;
78
+ };
79
+ var fillCheckedItems = exports.fillCheckedItems = function fillCheckedItems(listOfItems, maxSelectable) {
80
+ var items = _toConsumableArray(listOfItems);
81
+ var changed = false;
82
+
83
+ // Obtención de cambios de url y handleo en item afectado
84
+ items = items.map(function (item) {
85
+ if (item.hasNewUrl) {
86
+ changed = true;
87
+
88
+ // Deseleción de items con nueva url
89
+ if (item.checked) {
90
+ return _objectSpread(_objectSpread({}, item), {}, {
91
+ checked: false,
92
+ position: 0,
93
+ hasNewUrl: false
94
+ });
95
+ }
96
+ return _objectSpread(_objectSpread({}, item), {}, {
97
+ hasNewUrl: false
98
+ });
99
+ }
100
+ return item;
101
+ });
102
+
103
+ // Auto check en items cuando no hubo cambio de url
104
+ if (!changed) {
105
+ var updatedItems = [];
106
+ var nextPosition = 1;
107
+ var checkedCount = 0;
108
+ for (var index = 0; index < listOfItems.length; index++) {
109
+ var item = items[index];
110
+ var isSomeError = item.fetchError || item.sizeError || item.aspectRatioError;
111
+ var checked = checkedCount < maxSelectable && !isSomeError;
112
+ var position = 0;
113
+ if (checked) {
114
+ position = nextPosition;
115
+ nextPosition++;
116
+ checkedCount++;
117
+ }
118
+ updatedItems.push(_objectSpread(_objectSpread({}, item), {}, {
119
+ checked: checked,
120
+ position: position
121
+ }));
122
+ }
123
+ return updatedItems;
124
+ }
125
+
126
+ // Reorden de items en estado check cuando hubo cambios de url
127
+ var currentPosition = 1;
128
+ var reorderedItems = items.map(function (item) {
129
+ if (item.checked) {
130
+ return _objectSpread(_objectSpread({}, item), {}, {
131
+ position: currentPosition++
132
+ });
133
+ } else {
134
+ return _objectSpread(_objectSpread({}, item), {}, {
135
+ position: 0
136
+ });
137
+ }
138
+ });
139
+ return reorderedItems;
140
+ };
141
+ var refreshItemsPosition = exports.refreshItemsPosition = function refreshItemsPosition(items) {
142
+ var currentPosition = 1;
143
+ return items.map(function (item) {
144
+ return _objectSpread(_objectSpread({}, item), {}, {
145
+ position: item.checked ? currentPosition++ : 0
146
+ });
147
+ });
148
+ };
149
+ var getSelectAllItems = exports.getSelectAllItems = function getSelectAllItems(listOfItems, maxSelectable) {
150
+ var numberOfItemsAlreadyChecked = listOfItems.filter(function (item) {
151
+ return item.checked;
152
+ }).length;
153
+ var newMaxPosition = Math.max.apply(Math, _toConsumableArray(listOfItems.map(function (item) {
154
+ return item.position;
155
+ }))) + 1;
156
+ var isMaxSelectableReached = numberOfItemsAlreadyChecked >= maxSelectable;
157
+ var newItems = listOfItems.map(function (item) {
158
+ if (item.checked) return item;
159
+ if (isMaxSelectableReached) return item;
160
+ if (!(0, _manageItem.isItemClickable)(item, isMaxSelectableReached, true)) return item;
161
+ var newItem = _objectSpread(_objectSpread({}, item), {}, {
162
+ checked: true,
163
+ position: newMaxPosition
164
+ });
165
+ newMaxPosition++;
166
+ numberOfItemsAlreadyChecked++;
167
+ isMaxSelectableReached = numberOfItemsAlreadyChecked >= maxSelectable;
168
+ return newItem;
169
+ });
170
+ return newItems;
171
+ };
172
+ var getDeselectAllItems = exports.getDeselectAllItems = function getDeselectAllItems(listOfItems) {
173
+ return listOfItems.map(function (item) {
174
+ return _objectSpread(_objectSpread({}, item), {}, {
175
+ checked: false,
176
+ position: 0
177
+ });
178
+ });
179
+ };
180
+ var getItemChanged = exports.getItemChanged = function getItemChanged(originalList, newList) {
181
+ var length = Math.min(originalList.length, newList.length);
182
+ for (var i = 0; i < length; i++) {
183
+ if (originalList[i] !== newList[i]) {
184
+ return {
185
+ oldUrl: originalList[i],
186
+ newUrl: newList[i]
187
+ };
188
+ }
189
+ }
190
+ return null;
191
+ };
package/package.json ADDED
@@ -0,0 +1,27 @@
1
+ {
2
+ "name": "@quintoandar-tokko/gridimagepicker",
3
+ "version": "1.0.17",
4
+ "main": "lib/index.js",
5
+ "module": "src/index.js",
6
+ "files": [
7
+ "lib",
8
+ "styles",
9
+ "hooks",
10
+ "utils"
11
+ ],
12
+ "dependencies": {
13
+ "@dnd-kit/core": "^6.0.8",
14
+ "@dnd-kit/modifiers": "^7.0.0",
15
+ "@dnd-kit/sortable": "^7.0.2",
16
+ "@dnd-kit/utilities": "^3.2.2",
17
+ "@quintoandar-tokko/box": "^1.2.286",
18
+ "@quintoandar-tokko/icons": "^1.2.317"
19
+ },
20
+ "peerDependencies": {
21
+ "react": "^16.8.0"
22
+ },
23
+ "publishConfig": {
24
+ "access": "public"
25
+ },
26
+ "gitHead": "d33e426a17c29e62c8ea591ae6afa96300d55ad9"
27
+ }
@@ -0,0 +1,87 @@
1
+ :root {
2
+ --gap-between-images: 16px;
3
+ }
4
+
5
+ .gridImagePickerContainer {
6
+ display: flex;
7
+ flex-direction: column;
8
+ gap: 16px;
9
+ position: relative;
10
+ }
11
+
12
+ .gridImagePicker {
13
+ display: flex;
14
+ flex-wrap: wrap;
15
+ gap: var(--gap-between-images);
16
+ max-width: 550px;
17
+ min-width: unset !important;
18
+ width: 100%;
19
+ }
20
+
21
+ .gridButtonsWrapper {
22
+ align-items: center;
23
+ display: flex;
24
+ gap: 8px;
25
+ }
26
+
27
+ .gridButton {
28
+ background-color: #FFF;
29
+ border: 1px solid transparent;
30
+ border-radius: 6px;
31
+ cursor: pointer;
32
+ font-family: "Nunito Sans";
33
+ font-size: 12px;
34
+ font-weight: 700;
35
+ line-height: 16px;
36
+ outline: none;
37
+ padding: 8px 12px;
38
+ transition:
39
+ background-color 100ms linear,
40
+ border-color 100ms linear,
41
+ color 100ms linear,
42
+ filter 100ms linear
43
+ ;
44
+ }
45
+
46
+ .gridButtonSelect {
47
+ border-color: #1A4958;
48
+ color: #1A4958;
49
+ }
50
+
51
+ .gridButtonSelect:hover:not(:disabled),
52
+ .gridButtonSelect:active {
53
+ background-color: #1A4958;
54
+ color: white;
55
+ }
56
+
57
+ .gridButtonSelect:focus {
58
+ border-color: #1B90D2;
59
+ color: #1A4958;
60
+ }
61
+
62
+ .gridButtonSelect:disabled {
63
+ border-color: #EAEEF1;
64
+ color: #94A2AB;
65
+ cursor: default;
66
+ }
67
+
68
+ .gridButtonDeselect {
69
+ color: #2E393F;
70
+ }
71
+
72
+ .gridButtonDeselect:hover:not(:disabled) {
73
+ background-color: #EAEEF1;
74
+ color: #2E393F;
75
+ }
76
+
77
+ .gridButtonDeselect:focus-visible:not(:disabled) {
78
+ background-color: #F3F6F8;
79
+ border-color: #1B90D2;
80
+ color: #2E393F;
81
+ }
82
+
83
+ .gridButtonDeselect:disabled {
84
+ background-color: #EAEEF1;
85
+ color: #94A2AB;
86
+ cursor: default;
87
+ }
@@ -0,0 +1,24 @@
1
+ .imageItemWrapper {
2
+ align-items: center;
3
+ background-color: #EAEEF1;
4
+ background-position: center center;
5
+ background-repeat: no-repeat;
6
+ background-size: contain;
7
+ border: none;
8
+ border-radius: 12px;
9
+ cursor: pointer;
10
+ display: flex;
11
+ height: 120px;
12
+ justify-content: center;
13
+ padding: 0;
14
+ position: relative;
15
+ width: 120px;
16
+ }
17
+
18
+ .imageItemWrapper * {
19
+ pointer-events: none;
20
+ }
21
+
22
+ .imageItemWrapper[data-dragging="true"] {
23
+ cursor: grabbing;
24
+ }
@@ -0,0 +1,29 @@
1
+ .imageItemBlanket {
2
+ border: 2px solid transparent;
3
+ border-radius: inherit;
4
+ height: 100%;
5
+ left: 0;
6
+ opacity: 0;
7
+ position: absolute;
8
+ top: 0;
9
+ transition: opacity 100ms linear, background-color 100ms linear, border-color 100ms linear;
10
+ width: 100%
11
+ }
12
+
13
+ .imageItemBlanket[data-light="true"] {
14
+ background-color: rgba(255, 255, 255, 0.5);
15
+ border-color: rgba(255, 255, 255, 0.5);
16
+ opacity: 1;
17
+ }
18
+
19
+ .imageItemBlanket[data-dark="true"] {
20
+ background-color: #1D23274D;
21
+ border-color: #1A4958;
22
+ opacity: 1;
23
+ }
24
+
25
+ .imageItemBlanket[data-grey="true"] {
26
+ background-color: rgba(255, 255, 255, 0.5);
27
+ border-color: transparent;
28
+ opacity: 1;
29
+ }
@@ -0,0 +1,36 @@
1
+ .imageItemCover {
2
+ align-items: flex-end;
3
+ background-color: transparent;
4
+ border: 2px solid transparent;
5
+ border-radius: 9px;
6
+ display: flex;
7
+ height: 100%;
8
+ left: 0;
9
+ opacity: 0;
10
+ position: absolute;
11
+ top: 0;
12
+ transition: opacity 100ms linear;
13
+ width: 100%;
14
+ z-index: 1;
15
+ }
16
+
17
+ .imageItemCover[data-visible="true"] {
18
+ opacity: 1;
19
+ }
20
+
21
+ .imageItemCover[data-visible="true"] .imageItemCoverText {
22
+ color: #FFF;
23
+ }
24
+
25
+ .imageItemCoverText {
26
+ background-color: #1A4958;
27
+ border-radius: 0 0 6px 6px;
28
+ color: transparent;
29
+ font-size: 9px;
30
+ font-weight: 600;
31
+ line-height: 16px;
32
+ padding: 3px 0 5px;
33
+ transition: color 100ms linear 50ms;
34
+ width: 100%;
35
+ z-index: 1;
36
+ }
@@ -0,0 +1,122 @@
1
+ .imageItemCount {
2
+ align-items: center;
3
+ background-color: rgba(255, 255, 255, 0.75);
4
+ border-radius: 50%;
5
+ color: transparent;
6
+ display: flex;
7
+ font-size: 12px;
8
+ font-weight: 600;
9
+ height: 24px;
10
+ justify-content: center;
11
+ left: 8px;
12
+ line-height: 16px;
13
+ opacity: 0;
14
+ position: absolute;
15
+ top: 8px;
16
+ width: 24px;
17
+ z-index: 1;
18
+ }
19
+
20
+ .imageItemCount[data-visible='true'] {
21
+ color: #1d2327;
22
+ opacity: 1;
23
+ }
24
+
25
+ .imageItemCheckboxWrapper {
26
+ align-items: center;
27
+ background-color: #fff;
28
+ border-radius: 3px;
29
+ display: flex;
30
+ height: 16px;
31
+ justify-content: center;
32
+ width: 16px;
33
+ z-index: 1;
34
+ }
35
+
36
+ .imageItemCheckbox {
37
+ align-items: center;
38
+ background-color: #FFF;
39
+ border: 1px solid #C2CCD3;
40
+ border-radius: 3px;
41
+ box-shadow: 0 0 0 1px #FFF;
42
+ display: flex;
43
+ height: 20px;
44
+ justify-content: center;
45
+ opacity: 0;
46
+ padding: 2px;
47
+ position: absolute;
48
+ right: 8px;
49
+ top: 8px;
50
+ transition: background-color 100ms linear;
51
+ width: 20px;
52
+ }
53
+
54
+ .imageItemCheckbox[data-active="true"] {
55
+ background-color: #1B90D2;
56
+ border-color: #1B90D2;
57
+ }
58
+
59
+ .imageItemCheckbox[data-visible="true"] {
60
+ opacity: 1;
61
+ }
62
+
63
+ .imageItemCheckbox[data-disabled="true"] {
64
+ opacity: 0.5;
65
+ background-color: #F3F6F8;
66
+ }
67
+
68
+ .imageItemError {
69
+ align-items: center;
70
+ background-color: #DF1517;
71
+ border-radius: 8px;
72
+ display: flex;
73
+ height: 24px;
74
+ justify-content: center;
75
+ opacity: 0;
76
+ position: absolute;
77
+ right: 8px;
78
+ top: 8px;
79
+ transition: opacity 150ms ease-in;
80
+ width: 24px;
81
+ z-index: 1;
82
+ }
83
+
84
+ .imageItemError[data-visible="true"] {
85
+ opacity: 1;
86
+ }
87
+
88
+ .imageItemIconCheck {
89
+ color: #FFFFFF;
90
+ font-size: 14px;
91
+ min-width: unset!important;
92
+ }
93
+
94
+ .imageItemIconError {
95
+ color: #FFFFFF;
96
+ font-size: 20px;
97
+ min-width: unset !important;
98
+ }
99
+ .imageItemIconEdit {
100
+ font-size: 16px;
101
+ min-width: unset !important;
102
+ }
103
+ .imageItemEdit {
104
+ align-items: center;
105
+ background-color: rgba(255, 255, 255, 0.6);
106
+ border-radius: 8px;
107
+ display: flex;
108
+ height: 24px;
109
+ justify-content: center;
110
+ opacity: 0;
111
+ position: absolute;
112
+ right: 8px;
113
+ top: 36px;
114
+ transition: opacity 150ms ease-in;
115
+ width: 24px;
116
+ pointer-events: auto;
117
+ z-index: 1;
118
+ }
119
+
120
+ .imageItemEdit[data-visible='true'] {
121
+ opacity: 1;
122
+ }
@@ -0,0 +1,29 @@
1
+ .imageItemTooltip {
2
+ background-color: #1D2327;
3
+ border-radius: 4px;
4
+ color: #FFFFFF;
5
+ display: flex;
6
+ font-family: "Nunito Sans";
7
+ font-size: 12px;
8
+ left: 50%;
9
+ line-height: 16px;
10
+ max-width: 240px;
11
+ opacity: 0;
12
+ padding: 4px 8px;
13
+ pointer-events: none;
14
+ position: absolute;
15
+ text-align: left;
16
+ top: 0;
17
+ transform: translate(-50%, -85%);
18
+ transition: opacity 100ms ease-out;
19
+ width: max-content;
20
+ z-index: 2;
21
+ }
22
+
23
+ .imageItemTooltip[data-showable="false"] {
24
+ display: none;
25
+ }
26
+
27
+ .imageItemOuterWrapper:hover .imageItemWrapper[data-dragging="false"] + .imageItemTooltip {
28
+ opacity: 1;
29
+ }