@quintoandar-tokko/gridimagepicker 1.0.19 → 1.0.25
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/lib/ImageItem.js +37 -5
- package/lib/hooks/useGridImagePicker.js +42 -9
- package/lib/index.js +13 -5
- package/lib/utils/manageListOfItems.js +9 -6
- package/package.json +2 -2
- package/styles/ImageItemSwitch.css +44 -0
package/lib/ImageItem.js
CHANGED
|
@@ -19,6 +19,7 @@ require("../styles/ImageItemBlanket.css");
|
|
|
19
19
|
require("../styles/ImageItemCover.css");
|
|
20
20
|
require("../styles/ImageItemSmallElements.css");
|
|
21
21
|
require("../styles/ImageItemTooltip.css");
|
|
22
|
+
require("../styles/ImageItemSwitch.css");
|
|
22
23
|
function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default": e }; }
|
|
23
24
|
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
25
|
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; }
|
|
@@ -34,6 +35,7 @@ var ImageItem = function ImageItem(_ref) {
|
|
|
34
35
|
handleClick = _ref.handleClick,
|
|
35
36
|
handleUpdateItem = _ref.handleUpdateItem,
|
|
36
37
|
onEdit = _ref.onEdit,
|
|
38
|
+
onSwitchChange = _ref.onSwitchChange,
|
|
37
39
|
status = _ref.status,
|
|
38
40
|
config = _ref.config,
|
|
39
41
|
texts = _ref.texts,
|
|
@@ -46,12 +48,15 @@ var ImageItem = function ImageItem(_ref) {
|
|
|
46
48
|
setNodeRef = _useSortable.setNodeRef,
|
|
47
49
|
transform = _useSortable.transform,
|
|
48
50
|
transition = _useSortable.transition;
|
|
49
|
-
var
|
|
51
|
+
var previousEditedSrc = (0, _react.useRef)(item.editedSrc);
|
|
52
|
+
var isEditedActive = item.isEditedActive;
|
|
53
|
+
var displaySrc = isEditedActive && item.editedSrc ? item.editedSrc : item.src;
|
|
54
|
+
var _useSize = (0, _useSize3["default"])(displaySrc, sizeFetcher),
|
|
50
55
|
_useSize2 = _slicedToArray(_useSize, 3),
|
|
51
56
|
size = _useSize2[0],
|
|
52
57
|
isLoadingSize = _useSize2[1],
|
|
53
58
|
isErrorSize = _useSize2[2];
|
|
54
|
-
var _useAspectRatio = (0, _useAspectRatio3["default"])(
|
|
59
|
+
var _useAspectRatio = (0, _useAspectRatio3["default"])(displaySrc),
|
|
55
60
|
_useAspectRatio2 = _slicedToArray(_useAspectRatio, 5),
|
|
56
61
|
height = _useAspectRatio2[0],
|
|
57
62
|
width = _useAspectRatio2[1],
|
|
@@ -80,9 +85,18 @@ var ImageItem = function ImageItem(_ref) {
|
|
|
80
85
|
var isError = item.sizeError || item.aspectRatioError || item.fetchError;
|
|
81
86
|
var isFizableError = !item.fetchError && onEdit;
|
|
82
87
|
var tooltipErrorText = (0, _getTooltipErrorText.getTooltipErrorText)(item, texts, onEdit);
|
|
83
|
-
var backgroundImage = item.loading || item.fetchError ? '' : "url(".concat(
|
|
88
|
+
var backgroundImage = item.loading || item.fetchError ? '' : "url(".concat(displaySrc, ")");
|
|
84
89
|
var unclickable = !(0, _manageItem.isItemClickable)(item, isMaxSelectableReached, itemsAreReady);
|
|
85
90
|
var disabled = (0, _manageItem.isDisabledCheckbox)(item, isMaxSelectableReached);
|
|
91
|
+
|
|
92
|
+
// On (re)edit, flip back to the edited version and notify; the ref skips mount/re-renders.
|
|
93
|
+
(0, _react.useEffect)(function () {
|
|
94
|
+
if (item.editedSrc === previousEditedSrc.current) return;
|
|
95
|
+
previousEditedSrc.current = item.editedSrc;
|
|
96
|
+
if (item.editedSrc) {
|
|
97
|
+
onSwitchChange === null || onSwitchChange === void 0 || onSwitchChange(item, true);
|
|
98
|
+
}
|
|
99
|
+
}, [item.editedSrc]);
|
|
86
100
|
(0, _react.useEffect)(function () {
|
|
87
101
|
var handleHideTooltip = function handleHideTooltip() {
|
|
88
102
|
setIsTooltipShowable(false);
|
|
@@ -189,9 +203,27 @@ var ImageItem = function ImageItem(_ref) {
|
|
|
189
203
|
}, /*#__PURE__*/_react["default"].createElement(_icons.Icon, {
|
|
190
204
|
icon: "icon-editar",
|
|
191
205
|
className: "imageItemIconEdit"
|
|
192
|
-
}))
|
|
206
|
+
})), /*#__PURE__*/_react["default"].createElement(_box.Box, {
|
|
207
|
+
className: "imageItemSwitch",
|
|
208
|
+
"data-visible": Boolean(item.editedSrc) && itemsAreReady,
|
|
209
|
+
"data-cover": item.position === 1
|
|
210
|
+
}, /*#__PURE__*/_react["default"].createElement(_box.Box, {
|
|
211
|
+
className: "imageItemSwitchOption",
|
|
212
|
+
"data-active": !isEditedActive,
|
|
213
|
+
onClick: function onClick(e) {
|
|
214
|
+
e.stopPropagation();
|
|
215
|
+
onSwitchChange === null || onSwitchChange === void 0 || onSwitchChange(item, false);
|
|
216
|
+
}
|
|
217
|
+
}, texts === null || texts === void 0 ? void 0 : texts.original), /*#__PURE__*/_react["default"].createElement(_box.Box, {
|
|
218
|
+
className: "imageItemSwitchOption",
|
|
219
|
+
"data-active": isEditedActive,
|
|
220
|
+
onClick: function onClick(e) {
|
|
221
|
+
e.stopPropagation();
|
|
222
|
+
onSwitchChange === null || onSwitchChange === void 0 || onSwitchChange(item, true);
|
|
223
|
+
}
|
|
224
|
+
}, texts === null || texts === void 0 ? void 0 : texts.edited))), /*#__PURE__*/_react["default"].createElement(_box.Box, {
|
|
193
225
|
className: "imageItemTooltip",
|
|
194
|
-
"data-showable": isTooltipShowable,
|
|
226
|
+
"data-showable": isTooltipShowable && Boolean(tooltipErrorText),
|
|
195
227
|
__css: {
|
|
196
228
|
left: tooltipPosition.left,
|
|
197
229
|
top: tooltipPosition.top
|
|
@@ -10,13 +10,13 @@ var _sortable = require("@dnd-kit/sortable");
|
|
|
10
10
|
var _manageItem = require("../utils/manageItem");
|
|
11
11
|
var _manageListOfItems = require("../utils/manageListOfItems");
|
|
12
12
|
var _excluded = ["id"];
|
|
13
|
+
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; }
|
|
14
|
+
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; }
|
|
13
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; }
|
|
14
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; }
|
|
15
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; }
|
|
16
18
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
17
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); }
|
|
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
20
|
function _slicedToArray(r, e) { return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest(); }
|
|
21
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
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; } }
|
|
@@ -24,17 +24,18 @@ function _arrayLikeToArray(r, a) { (null == a || a > r.length) && (a = r.length)
|
|
|
24
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
25
|
function _arrayWithHoles(r) { if (Array.isArray(r)) return r; }
|
|
26
26
|
function useGridImagePicker(_ref) {
|
|
27
|
-
var
|
|
27
|
+
var listOfImages = _ref.listOfImages,
|
|
28
28
|
maxSelectablePreferenceByUser = _ref.maxSelectablePreferenceByUser,
|
|
29
29
|
maxSizeInMB = _ref.maxSizeInMB,
|
|
30
30
|
minAspectRatio = _ref.minAspectRatio,
|
|
31
31
|
maxAspectRatio = _ref.maxAspectRatio,
|
|
32
|
-
onChange = _ref.onChange
|
|
32
|
+
onChange = _ref.onChange,
|
|
33
|
+
onSwitchChange = _ref.onSwitchChange;
|
|
33
34
|
var _useState = (0, _react.useState)(false),
|
|
34
35
|
_useState2 = _slicedToArray(_useState, 2),
|
|
35
36
|
isDraggingActive = _useState2[0],
|
|
36
37
|
setIsDraggingActive = _useState2[1];
|
|
37
|
-
var _useState3 = (0, _react.useState)(
|
|
38
|
+
var _useState3 = (0, _react.useState)(listOfImages),
|
|
38
39
|
_useState4 = _slicedToArray(_useState3, 2),
|
|
39
40
|
initialUrlList = _useState4[0],
|
|
40
41
|
setInitialUrlList = _useState4[1];
|
|
@@ -43,22 +44,41 @@ function useGridImagePicker(_ref) {
|
|
|
43
44
|
itemNewUrl = _useState6[0],
|
|
44
45
|
setItemNewUrl = _useState6[1];
|
|
45
46
|
var _useState7 = (0, _react.useState)(function () {
|
|
46
|
-
return (0, _manageListOfItems.getItemsInitialState)(
|
|
47
|
+
return (0, _manageListOfItems.getItemsInitialState)(listOfImages);
|
|
47
48
|
}),
|
|
48
49
|
_useState8 = _slicedToArray(_useState7, 2),
|
|
49
50
|
items = _useState8[0],
|
|
50
51
|
setItems = _useState8[1];
|
|
51
52
|
(0, _react.useEffect)(function () {
|
|
52
|
-
setItemNewUrl((0, _manageListOfItems.getItemChanged)(initialUrlList,
|
|
53
|
-
}, [
|
|
53
|
+
setItemNewUrl((0, _manageListOfItems.getItemChanged)(initialUrlList, listOfImages));
|
|
54
|
+
}, [listOfImages]);
|
|
54
55
|
(0, _react.useEffect)(function () {
|
|
55
56
|
if (!itemNewUrl) return;
|
|
56
57
|
setItems(function (prevItems) {
|
|
57
58
|
return (0, _manageListOfItems.getItemsWithNewUrl)(prevItems, itemNewUrl);
|
|
58
59
|
});
|
|
59
|
-
setInitialUrlList(
|
|
60
|
+
setInitialUrlList(listOfImages);
|
|
60
61
|
setItemNewUrl(null);
|
|
61
62
|
}, [itemNewUrl]);
|
|
63
|
+
|
|
64
|
+
// Sync `editedSrc` from the source list, matched by positional `id` (robust to duplicate `src` and reordering).
|
|
65
|
+
(0, _react.useEffect)(function () {
|
|
66
|
+
setItems(function (prevItems) {
|
|
67
|
+
var hasChanges = false;
|
|
68
|
+
var nextItems = prevItems.map(function (item) {
|
|
69
|
+
var source = listOfImages[item.id - 1];
|
|
70
|
+
if (!source || source.editedSrc === item.editedSrc) return item;
|
|
71
|
+
hasChanges = true;
|
|
72
|
+
// No `editedSrc` means nothing to show as edited (the flip-back lives in ImageItem).
|
|
73
|
+
var isEditedActive = source.editedSrc ? item.isEditedActive : false;
|
|
74
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
75
|
+
editedSrc: source.editedSrc,
|
|
76
|
+
isEditedActive: isEditedActive
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
return hasChanges ? nextItems : prevItems;
|
|
80
|
+
});
|
|
81
|
+
}, [listOfImages]);
|
|
62
82
|
var maxSelectable = Math.min(maxSelectablePreferenceByUser, items.filter(function (item) {
|
|
63
83
|
return !item.sizeError && !item.aspectRatioError && !item.fetchError;
|
|
64
84
|
}).length);
|
|
@@ -115,6 +135,18 @@ function useGridImagePicker(_ref) {
|
|
|
115
135
|
});
|
|
116
136
|
});
|
|
117
137
|
};
|
|
138
|
+
|
|
139
|
+
// Single source of truth for the shown version: stored in `items` (for `onChange`) and reported via `onSwitchChange`.
|
|
140
|
+
var handleSwitchChange = function handleSwitchChange(targetItem, isEditedActive) {
|
|
141
|
+
setItems(function (prevItems) {
|
|
142
|
+
return prevItems.map(function (item) {
|
|
143
|
+
return item.id === targetItem.id ? _objectSpread(_objectSpread({}, item), {}, {
|
|
144
|
+
isEditedActive: isEditedActive
|
|
145
|
+
}) : item;
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
onSwitchChange === null || onSwitchChange === void 0 || onSwitchChange(targetItem, isEditedActive);
|
|
149
|
+
};
|
|
118
150
|
var handleDragStart = function handleDragStart() {
|
|
119
151
|
setIsDraggingActive(true);
|
|
120
152
|
};
|
|
@@ -142,6 +174,7 @@ function useGridImagePicker(_ref) {
|
|
|
142
174
|
methods: {
|
|
143
175
|
handleClickItem: handleClickItem,
|
|
144
176
|
handleUpdateItem: handleUpdateItem,
|
|
177
|
+
handleSwitchChange: handleSwitchChange,
|
|
145
178
|
handleDeselectAll: handleDeselectAll,
|
|
146
179
|
handleSelectAll: handleSelectAll,
|
|
147
180
|
handleDragStart: handleDragStart,
|
package/lib/index.js
CHANGED
|
@@ -16,19 +16,23 @@ function _interopRequireDefault(e) { return e && e.__esModule ? e : { "default":
|
|
|
16
16
|
* A grid-based image picker component with sortable and selectable images.
|
|
17
17
|
*
|
|
18
18
|
* @param {Object} props - The props for GridImagePicker.
|
|
19
|
-
* @param {string
|
|
19
|
+
* @param {Array<{src: string, editedSrc?: string}>} props.listOfImages - Array of image objects to display in the grid.
|
|
20
|
+
* An image is considered editable/edited when it has an `editedSrc`; that enables the Original/Editada switch.
|
|
20
21
|
* @param {number} [props.maxSelectablePreferenceByUser=10] - Maximum number of images that can be selected by the user.
|
|
21
22
|
* Default is 10. This value is a preference; if there are fewer images available than this number, it will adjust accordingly.
|
|
22
23
|
* @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
24
|
* @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
25
|
* @param {number} [props.maxAspectRatio] - Maximum aspect ratio allowed for the images. Images that exceed this ratio will be marked as an error.
|
|
25
26
|
* @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
|
+
* Called with the updated list of items as `(items) => onChange(items)`. Each item exposes `isEditedActive`
|
|
28
|
+
* (whether the edited version is currently being shown); combine it with `editedSrc` to know which version is in use.
|
|
29
|
+
* @param {Function} [props.onSwitchChange] - Optional callback invoked when the Original/Editada switch changes, both on user
|
|
30
|
+
* toggle and on the automatic flip after an image is (re)edited. Called with `(item, isEditedActive)`.
|
|
27
31
|
* @param {Function} [props.sizeFetcher] - Optional fetch function to get the size of the images. Default: (src) => fetch(src)
|
|
28
32
|
* @param {Object} props.texts - Nested texts
|
|
29
33
|
*/
|
|
30
34
|
var GridImagePicker = exports.GridImagePicker = function GridImagePicker(_ref) {
|
|
31
|
-
var
|
|
35
|
+
var listOfImages = _ref.listOfImages,
|
|
32
36
|
_ref$maxSelectablePre = _ref.maxSelectablePreferenceByUser,
|
|
33
37
|
maxSelectablePreferenceByUser = _ref$maxSelectablePre === void 0 ? 10 : _ref$maxSelectablePre,
|
|
34
38
|
_ref$maxSizeInMB = _ref.maxSizeInMB,
|
|
@@ -38,15 +42,17 @@ var GridImagePicker = exports.GridImagePicker = function GridImagePicker(_ref) {
|
|
|
38
42
|
onChange = _ref.onChange,
|
|
39
43
|
_ref$onEdit = _ref.onEdit,
|
|
40
44
|
onEdit = _ref$onEdit === void 0 ? null : _ref$onEdit,
|
|
45
|
+
onSwitchChange = _ref.onSwitchChange,
|
|
41
46
|
texts = _ref.texts,
|
|
42
47
|
sizeFetcher = _ref.sizeFetcher;
|
|
43
48
|
var _useGridImagePicker = (0, _useGridImagePicker2["default"])({
|
|
44
|
-
|
|
49
|
+
listOfImages: listOfImages,
|
|
45
50
|
maxSelectablePreferenceByUser: maxSelectablePreferenceByUser,
|
|
46
51
|
maxSizeInMB: maxSizeInMB,
|
|
47
52
|
minAspectRatio: minAspectRatio,
|
|
48
53
|
maxAspectRatio: maxAspectRatio,
|
|
49
|
-
onChange: onChange
|
|
54
|
+
onChange: onChange,
|
|
55
|
+
onSwitchChange: onSwitchChange
|
|
50
56
|
}),
|
|
51
57
|
attributes = _useGridImagePicker.attributes,
|
|
52
58
|
methods = _useGridImagePicker.methods;
|
|
@@ -55,6 +61,7 @@ var GridImagePicker = exports.GridImagePicker = function GridImagePicker(_ref) {
|
|
|
55
61
|
status = attributes.status;
|
|
56
62
|
var handleClickItem = methods.handleClickItem,
|
|
57
63
|
handleUpdateItem = methods.handleUpdateItem,
|
|
64
|
+
handleSwitchChange = methods.handleSwitchChange,
|
|
58
65
|
handleDeselectAll = methods.handleDeselectAll,
|
|
59
66
|
handleSelectAll = methods.handleSelectAll,
|
|
60
67
|
handleDragStart = methods.handleDragStart,
|
|
@@ -98,6 +105,7 @@ var GridImagePicker = exports.GridImagePicker = function GridImagePicker(_ref) {
|
|
|
98
105
|
config: config,
|
|
99
106
|
handleClick: handleClickItem,
|
|
100
107
|
onEdit: onEdit,
|
|
108
|
+
onSwitchChange: handleSwitchChange,
|
|
101
109
|
handleUpdateItem: handleUpdateItem,
|
|
102
110
|
texts: texts,
|
|
103
111
|
sizeFetcher: sizeFetcher
|
|
@@ -17,11 +17,14 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
|
|
|
17
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
18
|
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : i + ""; }
|
|
19
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(
|
|
21
|
-
var initializedItem =
|
|
20
|
+
var getItemsInitialState = exports.getItemsInitialState = function getItemsInitialState(listOfImages) {
|
|
21
|
+
var initializedItem = listOfImages.map(function (image, index) {
|
|
22
22
|
return {
|
|
23
23
|
id: index + 1,
|
|
24
|
-
src: src,
|
|
24
|
+
src: image.src,
|
|
25
|
+
editedSrc: image.editedSrc,
|
|
26
|
+
// Whether the edited version is shown; only meaningful when there's an `editedSrc`.
|
|
27
|
+
isEditedActive: Boolean(image.editedSrc),
|
|
25
28
|
checked: false,
|
|
26
29
|
position: 0,
|
|
27
30
|
height: 0,
|
|
@@ -180,10 +183,10 @@ var getDeselectAllItems = exports.getDeselectAllItems = function getDeselectAllI
|
|
|
180
183
|
var getItemChanged = exports.getItemChanged = function getItemChanged(originalList, newList) {
|
|
181
184
|
var length = Math.min(originalList.length, newList.length);
|
|
182
185
|
for (var i = 0; i < length; i++) {
|
|
183
|
-
if (originalList[i] !== newList[i]) {
|
|
186
|
+
if (originalList[i].src !== newList[i].src) {
|
|
184
187
|
return {
|
|
185
|
-
oldUrl: originalList[i],
|
|
186
|
-
newUrl: newList[i]
|
|
188
|
+
oldUrl: originalList[i].src,
|
|
189
|
+
newUrl: newList[i].src
|
|
187
190
|
};
|
|
188
191
|
}
|
|
189
192
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@quintoandar-tokko/gridimagepicker",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.25",
|
|
4
4
|
"main": "lib/index.js",
|
|
5
5
|
"module": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -23,5 +23,5 @@
|
|
|
23
23
|
"publishConfig": {
|
|
24
24
|
"access": "public"
|
|
25
25
|
},
|
|
26
|
-
"gitHead": "
|
|
26
|
+
"gitHead": "ff1bd5286d3900060f981d2f8d81f1c074b4f22d"
|
|
27
27
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
.imageItemSwitch {
|
|
2
|
+
align-items: center;
|
|
3
|
+
background-color: #EAF3F6;
|
|
4
|
+
border-radius: 100px;
|
|
5
|
+
bottom: 8px;
|
|
6
|
+
box-shadow: 0 1px 6px rgba(29, 35, 39, 0.20);
|
|
7
|
+
display: none;
|
|
8
|
+
grid-template-columns: repeat(2, 1fr);
|
|
9
|
+
left: 50%;
|
|
10
|
+
max-width: min(110px, 96%);
|
|
11
|
+
padding: 2px;
|
|
12
|
+
pointer-events: auto;
|
|
13
|
+
position: absolute;
|
|
14
|
+
transform: translateX(-50%);
|
|
15
|
+
width: 100%;
|
|
16
|
+
z-index: 2;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
.imageItemSwitch[data-visible="true"] {
|
|
20
|
+
display: grid;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
.imageItemSwitch[data-visible="true"][data-cover="true"] {
|
|
24
|
+
bottom: 28px;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
.imageItemSwitchOption {
|
|
28
|
+
border-radius: 100px;
|
|
29
|
+
color: #1B90D2;
|
|
30
|
+
cursor: pointer;
|
|
31
|
+
font-family: "Nunito Sans", sans-serif;
|
|
32
|
+
font-size: 11px;
|
|
33
|
+
font-weight: 600;
|
|
34
|
+
line-height: 1;
|
|
35
|
+
padding: 2px 6px;
|
|
36
|
+
pointer-events: auto;
|
|
37
|
+
transition: background-color 100ms linear, color 100ms linear;
|
|
38
|
+
white-space: nowrap;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
.imageItemSwitchOption[data-active="true"] {
|
|
42
|
+
background-color: #1B90D2;
|
|
43
|
+
color: #F2F8FA;
|
|
44
|
+
}
|