@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 CHANGED
@@ -3332,7 +3332,7 @@ function simpleThreeRule(value1, value2, proportion) {
3332
3332
  return (value2 * proportion) / value1;
3333
3333
  }
3334
3334
  function RlsImageEditor(props) {
3335
- const [selection, setSelection] = require$$0.useState(props.rateSelection ?? 60);
3335
+ const [selection, setSelection] = require$$0.useState(props.selection ?? 60);
3336
3336
  const [labels, setLabels] = require$$0.useState({
3337
3337
  actionRestore: reactI18n('editorImageActionRestore'),
3338
3338
  actionSelect: reactI18n('editorImageActionSelect')
@@ -3348,6 +3348,9 @@ function RlsImageEditor(props) {
3348
3348
  const refPicture = require$$0.useRef(null);
3349
3349
  const image = require$$0.useRef(new Image());
3350
3350
  const originalImage = require$$0.useRef();
3351
+ const ratio = require$$0.useMemo(() => {
3352
+ return props.ratio || '1:1';
3353
+ }, [props.ratio]);
3351
3354
  const getCropProperties = require$$0.useCallback(() => {
3352
3355
  return {
3353
3356
  height: simpleThreeRule(refImage.current.offsetHeight, image.current.height, refSelection.current.offsetHeight),
@@ -3373,7 +3376,7 @@ function RlsImageEditor(props) {
3373
3376
  refOverlayLeft.current.style.width = `calc(${left}px)`;
3374
3377
  }, []);
3375
3378
  const refreshSelectionFromWidth = require$$0.useCallback((rateSelection) => {
3376
- const ratioFactor = getRatioFactor(props.ratio || '1:1');
3379
+ const ratioFactor = getRatioFactor(ratio);
3377
3380
  const _ratio = rateSelection * ratioFactor;
3378
3381
  const offsetWidth = refImage.current?.offsetWidth || 0;
3379
3382
  const offsetHeight = refImage.current?.offsetHeight || 0;
@@ -3384,10 +3387,10 @@ function RlsImageEditor(props) {
3384
3387
  width = height / ratioFactor;
3385
3388
  }
3386
3389
  return { height, width };
3387
- }, [props.ratio]);
3390
+ }, [ratio]);
3388
3391
  const refreshSelectionFromHeight = require$$0.useCallback((rateSelection) => {
3389
- const ratioFactor = getRatioFactor(props.ratio || '1:1');
3390
- const _ratio = rateSelection * ratioFactor;
3392
+ const ratioFactor = getRatioFactor(ratio);
3393
+ const _ratio = rateSelection / ratioFactor;
3391
3394
  const offsetWidth = refImage.current?.offsetWidth || 0;
3392
3395
  const offsetHeight = refImage.current?.offsetHeight || 0;
3393
3396
  let height = (offsetHeight * rateSelection) / 100;
@@ -3397,7 +3400,7 @@ function RlsImageEditor(props) {
3397
3400
  height = width / ratioFactor;
3398
3401
  }
3399
3402
  return { height, width };
3400
- }, [props.ratio]);
3403
+ }, [ratio]);
3401
3404
  const refreshSelectionStyle = require$$0.useCallback((rateSelection) => {
3402
3405
  if (image.current.width > 0 && image.current.height > 0) {
3403
3406
  const { height, width } = image.current.width >= image.current.height
@@ -3417,7 +3420,7 @@ function RlsImageEditor(props) {
3417
3420
  }
3418
3421
  refreshOverlaysStyle();
3419
3422
  }
3420
- }, [props.ratio]);
3423
+ }, [ratio]);
3421
3424
  const setImageStyle = require$$0.useCallback((width, height) => {
3422
3425
  refImage.current.style.width = width;
3423
3426
  refImage.current.style.height = height;
@@ -3478,8 +3481,8 @@ function RlsImageEditor(props) {
3478
3481
  useResize({ refElement: refImage, onResize: onResizeElement });
3479
3482
  const onCropImage = require$$0.useCallback(() => {
3480
3483
  const cropProps = getCropProperties();
3481
- const width = props.imgWidth || cropProps.width;
3482
- const height = width * getRatioFactor(props.ratio || '1:1');
3484
+ const width = props.maxWidth || cropProps.width;
3485
+ const height = width * getRatioFactor(ratio);
3483
3486
  refPicture.current.width = width;
3484
3487
  refPicture.current.height = height;
3485
3488
  const context = refPicture.current.getContext('2d');
@@ -3497,14 +3500,14 @@ function RlsImageEditor(props) {
3497
3500
  props.formControl?.setValue(value);
3498
3501
  };
3499
3502
  }
3500
- }, props.mimeType || 'image/jpeg', props.imgQuality || 1);
3503
+ }, props.mimeType || 'image/jpeg', props.quality || 1);
3501
3504
  }, [
3502
- props.ratio,
3505
+ ratio,
3503
3506
  props.mimeType,
3504
3507
  props.onValue,
3505
3508
  props.formControl,
3506
- props.imgWidth,
3507
- props.imgQuality
3509
+ props.maxWidth,
3510
+ props.quality
3508
3511
  ]);
3509
3512
  const onRestore = require$$0.useCallback(() => {
3510
3513
  const context = refCanvas.current.getContext('2d');
@@ -3566,13 +3569,14 @@ function useImageEditorController(options) {
3566
3569
  setSrcEditor(undefined);
3567
3570
  }, []);
3568
3571
  const RlsImageEditorChooser = require$$0.useMemo(() => {
3569
- return (srcEditor && (jsxRuntimeExports.jsx(RlsImageEditorModal, { src: srcEditor, formControl: options.formControl, imgWidth: options.imgWidth, imgQuality: options.imgQuality, onValue: onEditorValue, visible: true, children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", rlsTheme: "danger", onClick: onCancel, disabled: options.disabled, children: labels.actionCancel }) })));
3572
+ 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 }) })));
3570
3573
  }, [
3571
3574
  srcEditor,
3572
3575
  labels,
3573
3576
  options.formControl,
3574
- options.imgWidth,
3575
- options.imgQuality,
3577
+ options.maxWidth,
3578
+ options.quality,
3579
+ options.ratio,
3576
3580
  options.disabled,
3577
3581
  onEditorValue,
3578
3582
  onCancel
@@ -3589,17 +3593,11 @@ function RlsImageChooser(props) {
3589
3593
  setSrc(image.base64);
3590
3594
  props.onValue && props.onValue(image);
3591
3595
  }, [props.onValue]);
3592
- const { RlsImageEditorChooser, onImageChooser } = useImageEditorController({
3593
- disabled: props.disabled,
3594
- formControl: props.formControl,
3595
- imgQuality: props.imgQuality,
3596
- imgWidth: props.imgWidth,
3597
- onValue
3598
- });
3596
+ const controller = useImageEditorController({ ...props, onValue });
3599
3597
  require$$0.useEffect(() => {
3600
3598
  props.src && setSrc(props.src);
3601
3599
  }, [props.src]);
3602
- 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] }));
3600
+ 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] }));
3603
3601
  }
3604
3602
 
3605
3603
  const DURATION_ANIMATION = 240;