@rolster/react-components 18.23.5 → 18.23.7
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/cjs/index.js +22 -24
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/index.js +22 -24
- package/dist/es/index.js.map +1 -1
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.d.ts +5 -2
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.js +2 -8
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.js.map +1 -1
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.d.ts +3 -3
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.js +17 -14
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.js.map +1 -1
- package/dist/esm/components/organisms/ImageEditorModal/ImageEditorModal.d.ts +3 -3
- package/dist/esm/controllers/ImageEditorController.d.ts +6 -3
- package/dist/esm/controllers/ImageEditorController.js +4 -3
- package/dist/esm/controllers/ImageEditorController.js.map +1 -1
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -3330,7 +3330,7 @@ function simpleThreeRule(value1, value2, proportion) {
|
|
|
3330
3330
|
return (value2 * proportion) / value1;
|
|
3331
3331
|
}
|
|
3332
3332
|
function RlsImageEditor(props) {
|
|
3333
|
-
const [selection, setSelection] = useState(props.
|
|
3333
|
+
const [selection, setSelection] = useState(props.selection ?? 60);
|
|
3334
3334
|
const [labels, setLabels] = useState({
|
|
3335
3335
|
actionRestore: reactI18n('editorImageActionRestore'),
|
|
3336
3336
|
actionSelect: reactI18n('editorImageActionSelect')
|
|
@@ -3346,6 +3346,9 @@ function RlsImageEditor(props) {
|
|
|
3346
3346
|
const refPicture = useRef(null);
|
|
3347
3347
|
const image = useRef(new Image());
|
|
3348
3348
|
const originalImage = useRef();
|
|
3349
|
+
const ratio = useMemo(() => {
|
|
3350
|
+
return props.ratio || '1:1';
|
|
3351
|
+
}, [props.ratio]);
|
|
3349
3352
|
const getCropProperties = useCallback(() => {
|
|
3350
3353
|
return {
|
|
3351
3354
|
height: simpleThreeRule(refImage.current.offsetHeight, image.current.height, refSelection.current.offsetHeight),
|
|
@@ -3371,7 +3374,7 @@ function RlsImageEditor(props) {
|
|
|
3371
3374
|
refOverlayLeft.current.style.width = `calc(${left}px)`;
|
|
3372
3375
|
}, []);
|
|
3373
3376
|
const refreshSelectionFromWidth = useCallback((rateSelection) => {
|
|
3374
|
-
const ratioFactor = getRatioFactor(
|
|
3377
|
+
const ratioFactor = getRatioFactor(ratio);
|
|
3375
3378
|
const _ratio = rateSelection * ratioFactor;
|
|
3376
3379
|
const offsetWidth = refImage.current?.offsetWidth || 0;
|
|
3377
3380
|
const offsetHeight = refImage.current?.offsetHeight || 0;
|
|
@@ -3382,10 +3385,10 @@ function RlsImageEditor(props) {
|
|
|
3382
3385
|
width = height / ratioFactor;
|
|
3383
3386
|
}
|
|
3384
3387
|
return { height, width };
|
|
3385
|
-
}, [
|
|
3388
|
+
}, [ratio]);
|
|
3386
3389
|
const refreshSelectionFromHeight = useCallback((rateSelection) => {
|
|
3387
|
-
const ratioFactor = getRatioFactor(
|
|
3388
|
-
const _ratio = rateSelection
|
|
3390
|
+
const ratioFactor = getRatioFactor(ratio);
|
|
3391
|
+
const _ratio = rateSelection / ratioFactor;
|
|
3389
3392
|
const offsetWidth = refImage.current?.offsetWidth || 0;
|
|
3390
3393
|
const offsetHeight = refImage.current?.offsetHeight || 0;
|
|
3391
3394
|
let height = (offsetHeight * rateSelection) / 100;
|
|
@@ -3395,7 +3398,7 @@ function RlsImageEditor(props) {
|
|
|
3395
3398
|
height = width / ratioFactor;
|
|
3396
3399
|
}
|
|
3397
3400
|
return { height, width };
|
|
3398
|
-
}, [
|
|
3401
|
+
}, [ratio]);
|
|
3399
3402
|
const refreshSelectionStyle = useCallback((rateSelection) => {
|
|
3400
3403
|
if (image.current.width > 0 && image.current.height > 0) {
|
|
3401
3404
|
const { height, width } = image.current.width >= image.current.height
|
|
@@ -3415,7 +3418,7 @@ function RlsImageEditor(props) {
|
|
|
3415
3418
|
}
|
|
3416
3419
|
refreshOverlaysStyle();
|
|
3417
3420
|
}
|
|
3418
|
-
}, [
|
|
3421
|
+
}, [ratio]);
|
|
3419
3422
|
const setImageStyle = useCallback((width, height) => {
|
|
3420
3423
|
refImage.current.style.width = width;
|
|
3421
3424
|
refImage.current.style.height = height;
|
|
@@ -3476,8 +3479,8 @@ function RlsImageEditor(props) {
|
|
|
3476
3479
|
useResize({ refElement: refImage, onResize: onResizeElement });
|
|
3477
3480
|
const onCropImage = useCallback(() => {
|
|
3478
3481
|
const cropProps = getCropProperties();
|
|
3479
|
-
const width = props.
|
|
3480
|
-
const height = width * getRatioFactor(
|
|
3482
|
+
const width = props.maxWidth || cropProps.width;
|
|
3483
|
+
const height = width * getRatioFactor(ratio);
|
|
3481
3484
|
refPicture.current.width = width;
|
|
3482
3485
|
refPicture.current.height = height;
|
|
3483
3486
|
const context = refPicture.current.getContext('2d');
|
|
@@ -3495,14 +3498,14 @@ function RlsImageEditor(props) {
|
|
|
3495
3498
|
props.formControl?.setValue(value);
|
|
3496
3499
|
};
|
|
3497
3500
|
}
|
|
3498
|
-
}, props.mimeType || 'image/jpeg', props.
|
|
3501
|
+
}, props.mimeType || 'image/jpeg', props.quality || 1);
|
|
3499
3502
|
}, [
|
|
3500
|
-
|
|
3503
|
+
ratio,
|
|
3501
3504
|
props.mimeType,
|
|
3502
3505
|
props.onValue,
|
|
3503
3506
|
props.formControl,
|
|
3504
|
-
props.
|
|
3505
|
-
props.
|
|
3507
|
+
props.maxWidth,
|
|
3508
|
+
props.quality
|
|
3506
3509
|
]);
|
|
3507
3510
|
const onRestore = useCallback(() => {
|
|
3508
3511
|
const context = refCanvas.current.getContext('2d');
|
|
@@ -3564,13 +3567,14 @@ function useImageEditorController(options) {
|
|
|
3564
3567
|
setSrcEditor(undefined);
|
|
3565
3568
|
}, []);
|
|
3566
3569
|
const RlsImageEditorChooser = useMemo(() => {
|
|
3567
|
-
return (srcEditor && (jsxRuntimeExports.jsx(RlsImageEditorModal, { src: srcEditor, formControl: options.formControl,
|
|
3570
|
+
return (srcEditor && (jsxRuntimeExports.jsx(RlsImageEditorModal, { visible: true, src: srcEditor, formControl: options.formControl, maxWidth: options.maxWidth, quality: options.quality, ratio: options.ratio, selection: options.selection, onValue: onEditorValue, children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", rlsTheme: "danger", onClick: onCancel, disabled: options.disabled, children: labels.actionCancel }) })));
|
|
3568
3571
|
}, [
|
|
3569
3572
|
srcEditor,
|
|
3570
3573
|
labels,
|
|
3571
3574
|
options.formControl,
|
|
3572
|
-
options.
|
|
3573
|
-
options.
|
|
3575
|
+
options.maxWidth,
|
|
3576
|
+
options.quality,
|
|
3577
|
+
options.ratio,
|
|
3574
3578
|
options.disabled,
|
|
3575
3579
|
onEditorValue,
|
|
3576
3580
|
onCancel
|
|
@@ -3587,17 +3591,11 @@ function RlsImageChooser(props) {
|
|
|
3587
3591
|
setSrc(image.base64);
|
|
3588
3592
|
props.onValue && props.onValue(image);
|
|
3589
3593
|
}, [props.onValue]);
|
|
3590
|
-
const {
|
|
3591
|
-
disabled: props.disabled,
|
|
3592
|
-
formControl: props.formControl,
|
|
3593
|
-
imgQuality: props.imgQuality,
|
|
3594
|
-
imgWidth: props.imgWidth,
|
|
3595
|
-
onValue
|
|
3596
|
-
});
|
|
3594
|
+
const controller = useImageEditorController({ ...props, onValue });
|
|
3597
3595
|
useEffect(() => {
|
|
3598
3596
|
props.src && setSrc(props.src);
|
|
3599
3597
|
}, [props.src]);
|
|
3600
|
-
return (jsxRuntimeExports.jsxs("div", { className: "rls-image-chooser", children: [jsxRuntimeExports.jsx("div", { className: "rls-image-chooser__avatar", onClick: onImageChooser, children: src && jsxRuntimeExports.jsx("img", { src: src }) }), RlsImageEditorChooser] }));
|
|
3598
|
+
return (jsxRuntimeExports.jsxs("div", { className: "rls-image-chooser", children: [jsxRuntimeExports.jsx("div", { className: "rls-image-chooser__avatar", onClick: controller.onImageChooser, children: src && jsxRuntimeExports.jsx("img", { src: src }) }), controller.RlsImageEditorChooser] }));
|
|
3601
3599
|
}
|
|
3602
3600
|
|
|
3603
3601
|
const DURATION_ANIMATION = 240;
|