@bigbinary/neeto-image-uploader-frontend 1.5.25 → 1.5.26
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/dist/index.cjs.js +87 -60
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.js +42 -24
- package/dist/index.js.map +1 -1
- package/package.json +13 -12
package/dist/index.js
CHANGED
|
@@ -2,16 +2,24 @@ import React, { useMemo, useRef, useReducer, useEffect, useCallback, forwardRef,
|
|
|
2
2
|
import classnames from 'classnames';
|
|
3
3
|
import { noop as noop$1, keysToCamelCase, findBy, isPresent } from '@bigbinary/neeto-cist';
|
|
4
4
|
import { Delete, LeftArrow, MenuHorizontal } from '@bigbinary/neeto-icons';
|
|
5
|
-
import
|
|
5
|
+
import Button from '@bigbinary/neetoui/Button';
|
|
6
|
+
import Typography from '@bigbinary/neetoui/Typography';
|
|
6
7
|
import { pipe, values, flatten as flatten$1, map, toUpper, join, equals, isNil, isEmpty, mergeRight, mergeLeft, concat, __, inc, mergeDeepRight } from 'ramda';
|
|
7
8
|
import { Trans, useTranslation } from 'react-i18next';
|
|
8
9
|
import { globalProps } from '@bigbinary/neeto-commons-frontend/initializers';
|
|
9
10
|
import i18next, { t as t$1 } from 'i18next';
|
|
11
|
+
import Toastr from '@bigbinary/neetoui/Toastr';
|
|
12
|
+
import Dropdown from '@bigbinary/neetoui/Dropdown';
|
|
13
|
+
import NeetoUIModal from '@bigbinary/neetoui/Modal';
|
|
14
|
+
import Tab from '@bigbinary/neetoui/Tab';
|
|
15
|
+
import Spinner from '@bigbinary/neetoui/Spinner';
|
|
10
16
|
import { useMutationWithInvalidation, useDebounce, useFuncDebounce } from '@bigbinary/neeto-commons-frontend/react-utils';
|
|
11
17
|
import { useMutation, useQuery } from 'react-query';
|
|
12
18
|
import axios from 'axios';
|
|
13
19
|
import { DirectUpload } from '@rails/activestorage';
|
|
14
20
|
import { withEventTargetValue } from '@bigbinary/neeto-commons-frontend/utils';
|
|
21
|
+
import Input from '@bigbinary/neetoui/Input';
|
|
22
|
+
import Switch from '@bigbinary/neetoui/Switch';
|
|
15
23
|
|
|
16
24
|
var e=[],t=[];function n(n,r){if(n&&"undefined"!=typeof document){var a,s=!0===r.prepend?"prepend":"append",d=!0===r.singleTag,i="string"==typeof r.container?document.querySelector(r.container):document.getElementsByTagName("head")[0];if(d){var u=e.indexOf(i);-1===u&&(u=e.push(i)-1,t[u]={}),a=t[u]&&t[u][s]?t[u][s]:t[u][s]=c();}else a=c();65279===n.charCodeAt(0)&&(n=n.substring(1)),a.styleSheet?a.styleSheet.cssText+=n:a.appendChild(document.createTextNode(n));}function c(){var e=document.createElement("style");if(e.setAttribute("type","text/css"),r.attributes)for(var t=Object.keys(r.attributes),n=0;n<t.length;n++)e.setAttribute(t[n],r.attributes[t[n]]);var a="prepend"===s?"afterbegin":"beforeend";return i.insertAdjacentElement(a,e),e}}
|
|
17
25
|
|
|
@@ -3535,17 +3543,18 @@ var useImageControls = function useImageControls(_ref) {
|
|
|
3535
3543
|
}
|
|
3536
3544
|
};
|
|
3537
3545
|
var handleWidthChange = function handleWidthChange(width) {
|
|
3538
|
-
var
|
|
3539
|
-
|
|
3546
|
+
var cropWidth = Number(width);
|
|
3547
|
+
var displayWidth = cropWidth * imageRef.current.width / imageRef.current.naturalWidth;
|
|
3548
|
+
if (displayWidth > 0 && Math.trunc(crop.x) + displayWidth <= imageRef.current.width) {
|
|
3540
3549
|
if (isAspectRatioLocked) {
|
|
3541
|
-
var
|
|
3542
|
-
|
|
3543
|
-
width:
|
|
3544
|
-
height:
|
|
3550
|
+
var displayHeight = displayWidth / (aspectRatio.width / aspectRatio.height);
|
|
3551
|
+
displayHeight + Math.trunc(crop.y) <= imageRef.current.height && setCrop(mergeRight(crop, {
|
|
3552
|
+
width: displayWidth,
|
|
3553
|
+
height: displayHeight
|
|
3545
3554
|
}));
|
|
3546
3555
|
} else {
|
|
3547
3556
|
setCrop(mergeRight(crop, {
|
|
3548
|
-
width:
|
|
3557
|
+
width: displayWidth
|
|
3549
3558
|
}));
|
|
3550
3559
|
}
|
|
3551
3560
|
} else {
|
|
@@ -3553,17 +3562,18 @@ var useImageControls = function useImageControls(_ref) {
|
|
|
3553
3562
|
}
|
|
3554
3563
|
};
|
|
3555
3564
|
var handleHeightChange = function handleHeightChange(height) {
|
|
3556
|
-
var
|
|
3557
|
-
|
|
3565
|
+
var cropHeight = Number(height);
|
|
3566
|
+
var displayHeight = cropHeight * imageRef.current.height / imageRef.current.naturalHeight;
|
|
3567
|
+
if (displayHeight > 0 && Math.trunc(crop.y) + displayHeight <= imageRef.current.height) {
|
|
3558
3568
|
if (isAspectRatioLocked) {
|
|
3559
|
-
var
|
|
3560
|
-
|
|
3561
|
-
height:
|
|
3562
|
-
width:
|
|
3569
|
+
var displayWidth = displayHeight * aspectRatio.width / aspectRatio.height;
|
|
3570
|
+
displayWidth + Math.trunc(crop.x) <= imageRef.current.width && setCrop(mergeRight(crop, {
|
|
3571
|
+
height: displayHeight,
|
|
3572
|
+
width: displayWidth
|
|
3563
3573
|
}));
|
|
3564
3574
|
} else {
|
|
3565
3575
|
setCrop(mergeRight(crop, {
|
|
3566
|
-
height:
|
|
3576
|
+
height: displayHeight
|
|
3567
3577
|
}));
|
|
3568
3578
|
}
|
|
3569
3579
|
} else {
|
|
@@ -3634,11 +3644,19 @@ var Controls = function Controls(_ref) {
|
|
|
3634
3644
|
hideControls = _ref$hideControls === void 0 ? false : _ref$hideControls;
|
|
3635
3645
|
var _useTranslation = useTranslation(),
|
|
3636
3646
|
t = _useTranslation.t;
|
|
3637
|
-
var
|
|
3647
|
+
var getActualCropHeight = function getActualCropHeight(cropHeight) {
|
|
3648
|
+
var _imageRef$current, _imageRef$current2;
|
|
3649
|
+
return cropHeight * (((_imageRef$current = imageRef.current) === null || _imageRef$current === void 0 ? void 0 : _imageRef$current.naturalHeight) / ((_imageRef$current2 = imageRef.current) === null || _imageRef$current2 === void 0 ? void 0 : _imageRef$current2.height));
|
|
3650
|
+
};
|
|
3651
|
+
var getActualCropWidth = function getActualCropWidth(cropHeight) {
|
|
3652
|
+
var _imageRef$current3, _imageRef$current4;
|
|
3653
|
+
return cropHeight * (((_imageRef$current3 = imageRef.current) === null || _imageRef$current3 === void 0 ? void 0 : _imageRef$current3.naturalWidth) / ((_imageRef$current4 = imageRef.current) === null || _imageRef$current4 === void 0 ? void 0 : _imageRef$current4.width));
|
|
3654
|
+
};
|
|
3655
|
+
var _useState = useState(getActualCropHeight(crop.height)),
|
|
3638
3656
|
_useState2 = _slicedToArray$2(_useState, 2),
|
|
3639
3657
|
height = _useState2[0],
|
|
3640
3658
|
setHeight = _useState2[1];
|
|
3641
|
-
var _useState3 = useState(crop.width
|
|
3659
|
+
var _useState3 = useState(getActualCropWidth(crop.width)),
|
|
3642
3660
|
_useState4 = _slicedToArray$2(_useState3, 2),
|
|
3643
3661
|
width = _useState4[0],
|
|
3644
3662
|
setWidth = _useState4[1];
|
|
@@ -3667,8 +3685,8 @@ var Controls = function Controls(_ref) {
|
|
|
3667
3685
|
handleWidthChange(debouncedWidth);
|
|
3668
3686
|
}, [debouncedWidth]);
|
|
3669
3687
|
useEffect(function () {
|
|
3670
|
-
setHeight(crop.height
|
|
3671
|
-
setWidth(crop.width
|
|
3688
|
+
setHeight(getActualCropHeight(crop.height));
|
|
3689
|
+
setWidth(getActualCropWidth(crop.width));
|
|
3672
3690
|
}, [crop]);
|
|
3673
3691
|
return /*#__PURE__*/React.createElement("div", {
|
|
3674
3692
|
className: "flex flex-col p-4 md:w-2/6 "
|
|
@@ -3711,14 +3729,14 @@ var Controls = function Controls(_ref) {
|
|
|
3711
3729
|
disabled: isFullImage,
|
|
3712
3730
|
label: t("neetoImageUploader.labels.width"),
|
|
3713
3731
|
type: "number",
|
|
3714
|
-
value: width,
|
|
3732
|
+
value: Math.round(width),
|
|
3715
3733
|
onChange: withEventTargetValue(setWidth)
|
|
3716
3734
|
}), /*#__PURE__*/React.createElement(Input, {
|
|
3717
3735
|
className: "mt-4 flex-grow-0",
|
|
3718
3736
|
disabled: isFullImage,
|
|
3719
3737
|
label: t("neetoImageUploader.labels.height"),
|
|
3720
3738
|
type: "number",
|
|
3721
|
-
value: height,
|
|
3739
|
+
value: Math.round(height),
|
|
3722
3740
|
onChange: withEventTargetValue(setHeight)
|
|
3723
3741
|
}), /*#__PURE__*/React.createElement(Button, {
|
|
3724
3742
|
className: "mt-6 self-start",
|
|
@@ -5108,7 +5126,7 @@ var Modal = function Modal(_ref) {
|
|
|
5108
5126
|
useEffect(function () {
|
|
5109
5127
|
setActiveTab(TABS[0].key);
|
|
5110
5128
|
}, [isOpen]);
|
|
5111
|
-
return /*#__PURE__*/React.createElement(
|
|
5129
|
+
return /*#__PURE__*/React.createElement(NeetoUIModal, {
|
|
5112
5130
|
isOpen: isOpen,
|
|
5113
5131
|
className: "niu-modal",
|
|
5114
5132
|
size: "large",
|
|
@@ -5131,7 +5149,7 @@ var Modal = function Modal(_ref) {
|
|
|
5131
5149
|
onClick: function onClick(event) {
|
|
5132
5150
|
return event.stopPropagation();
|
|
5133
5151
|
}
|
|
5134
|
-
})), /*#__PURE__*/React.createElement(
|
|
5152
|
+
})), /*#__PURE__*/React.createElement(NeetoUIModal.Header, null, /*#__PURE__*/React.createElement(Typography, {
|
|
5135
5153
|
style: "h2"
|
|
5136
5154
|
}, t("neetoImageUploader.common.imageLibrary"))), /*#__PURE__*/React.createElement("div", {
|
|
5137
5155
|
className: "px-6 py-2"
|
|
@@ -5164,7 +5182,7 @@ var Modal = function Modal(_ref) {
|
|
|
5164
5182
|
setIsUploading: setIsUploading,
|
|
5165
5183
|
setSelectedImage: setSelectedImage,
|
|
5166
5184
|
tab: activeTab
|
|
5167
|
-
}), equals(activeTab, TABS[1].key) && /*#__PURE__*/React.createElement(
|
|
5185
|
+
}), equals(activeTab, TABS[1].key) && /*#__PURE__*/React.createElement(NeetoUIModal.Footer, {
|
|
5168
5186
|
className: "flex items-center justify-center gap-2"
|
|
5169
5187
|
}, /*#__PURE__*/React.createElement(Typography, {
|
|
5170
5188
|
style: "body2"
|