@rolster/react-components 18.21.46 → 18.22.1
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/assets/{index-CaA_sxmM.css → index-B9-Brjbd.css} +197 -1
- package/dist/cjs/index.js +444 -5
- package/dist/cjs/index.js.map +1 -1
- package/dist/es/assets/{index-CaA_sxmM.css → index-B9-Brjbd.css} +197 -1
- package/dist/es/index.js +440 -6
- package/dist/es/index.js.map +1 -1
- package/dist/esm/components/molecules/Slider/Slider.css +60 -0
- package/dist/esm/components/molecules/Slider/Slider.css.map +1 -0
- package/dist/esm/components/molecules/Slider/Slider.d.ts +14 -0
- package/dist/esm/components/molecules/Slider/Slider.js +60 -0
- package/dist/esm/components/molecules/Slider/Slider.js.map +1 -0
- package/dist/esm/components/molecules/index.d.ts +1 -0
- package/dist/esm/components/molecules/index.js +1 -0
- package/dist/esm/components/molecules/index.js.map +1 -1
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.css +36 -0
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.css.map +1 -0
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.d.ts +12 -0
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.js +62 -0
- package/dist/esm/components/organisms/ImageChooser/ImageChooser.js.map +1 -0
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.css +97 -0
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.css.map +1 -0
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.d.ts +21 -0
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.js +207 -0
- package/dist/esm/components/organisms/ImageEditor/ImageEditor.js.map +1 -0
- package/dist/esm/components/organisms/Modal/Modal.css +1 -1
- package/dist/esm/components/organisms/Modal/Modal.css.map +1 -1
- package/dist/esm/components/organisms/Modal/Modal.d.ts +2 -1
- package/dist/esm/components/organisms/Modal/Modal.js +5 -5
- package/dist/esm/components/organisms/Modal/Modal.js.map +1 -1
- package/dist/esm/components/organisms/index.d.ts +2 -0
- package/dist/esm/components/organisms/index.js +2 -0
- package/dist/esm/components/organisms/index.js.map +1 -1
- package/dist/esm/controllers/RelocationOnComponentController.d.ts +8 -0
- package/dist/esm/controllers/RelocationOnComponentController.js +93 -0
- package/dist/esm/controllers/RelocationOnComponentController.js.map +1 -0
- package/dist/esm/controllers/ResizeController.d.ts +15 -0
- package/dist/esm/controllers/ResizeController.js +29 -0
- package/dist/esm/controllers/ResizeController.js.map +1 -0
- package/dist/esm/controllers/index.d.ts +2 -0
- package/dist/esm/controllers/index.js +2 -0
- package/dist/esm/controllers/index.js.map +1 -1
- package/dist/esm/i18n.d.ts +3 -0
- package/dist/esm/i18n.js +6 -0
- package/dist/esm/i18n.js.map +1 -1
- package/package.json +1 -1
package/dist/es/index.js
CHANGED
|
@@ -2279,6 +2279,61 @@ function RlsPickerYear({ date: _date, disabled, formControl, maxDate, minDate, o
|
|
|
2279
2279
|
return (jsxRuntimeExports.jsxs("div", { className: "rls-picker-year", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-picker-year__header", children: [jsxRuntimeExports.jsx("div", { className: "rls-picker-year__action rls-picker-year__action--prev", children: jsxRuntimeExports.jsx(RlsButtonAction, { icon: "arrow-ios-left", onClick: onClickPrev, disabled: !template.canPrevious || disabled }) }), jsxRuntimeExports.jsxs("label", { className: "rls-title-bold", children: [template.minRange, " - ", template.maxRange] }), jsxRuntimeExports.jsx("div", { className: "rls-picker-year__action rls-picker-year__action--next", children: jsxRuntimeExports.jsx(RlsButtonAction, { icon: "arrow-ios-right", onClick: onClickNext, disabled: !template.canNext || disabled }) })] }), jsxRuntimeExports.jsx("div", { className: "rls-picker-year__component", children: component })] }));
|
|
2280
2280
|
}
|
|
2281
2281
|
|
|
2282
|
+
function calculateInitialValue(value, minValue, maxValue) {
|
|
2283
|
+
return minValue > value ? minValue : maxValue < value ? maxValue : value;
|
|
2284
|
+
}
|
|
2285
|
+
function calculateInitialRate(value, minValue, maxValue) {
|
|
2286
|
+
const rateMax = maxValue - minValue;
|
|
2287
|
+
const rateValue = value - minValue;
|
|
2288
|
+
return Math.ceil((rateValue / rateMax) * 100);
|
|
2289
|
+
}
|
|
2290
|
+
function RlsSlider(props) {
|
|
2291
|
+
const minValue = useMemo(() => {
|
|
2292
|
+
return props.minValue ?? 0;
|
|
2293
|
+
}, [props.minValue]);
|
|
2294
|
+
const maxValue = useMemo(() => {
|
|
2295
|
+
return props.maxValue ?? 100;
|
|
2296
|
+
}, [props.maxValue]);
|
|
2297
|
+
const [value, setValue] = useState(calculateInitialValue(props.formControl?.value ?? props.value ?? 0, minValue, maxValue));
|
|
2298
|
+
const [rate, setRate] = useState(calculateInitialRate(value, minValue, maxValue));
|
|
2299
|
+
const refComponent = useRef(null);
|
|
2300
|
+
const refTrack = useRef(null);
|
|
2301
|
+
const refTrackOn = useRef(null);
|
|
2302
|
+
const refThumb = useRef(null);
|
|
2303
|
+
const className = useMemo(() => {
|
|
2304
|
+
return renderClassStatus('rls-slider', {
|
|
2305
|
+
complet: value === maxValue,
|
|
2306
|
+
disabled: props.disabled,
|
|
2307
|
+
empty: value === minValue
|
|
2308
|
+
});
|
|
2309
|
+
}, [value, minValue, maxValue, props.disabled]);
|
|
2310
|
+
useEffect(() => {
|
|
2311
|
+
const valueInitial = props.formControl?.value ?? props.value ?? 0;
|
|
2312
|
+
refThumb.current.style.left = `${rate}%`;
|
|
2313
|
+
refTrackOn.current.style.width = `${rate}%`;
|
|
2314
|
+
if (valueInitial !== value) {
|
|
2315
|
+
props.formControl?.setValue(value);
|
|
2316
|
+
props.onValue && props.onValue(value);
|
|
2317
|
+
}
|
|
2318
|
+
}, []);
|
|
2319
|
+
const calculateValueWithRate = useCallback((rate) => {
|
|
2320
|
+
const value = Math.ceil(((maxValue - minValue) * rate) / 100);
|
|
2321
|
+
refThumb.current.style.left = `${rate}%`;
|
|
2322
|
+
refTrackOn.current.style.width = `${rate}%`;
|
|
2323
|
+
const sliderValue = value + minValue;
|
|
2324
|
+
setRate(rate);
|
|
2325
|
+
setValue(sliderValue);
|
|
2326
|
+
props.formControl?.setValue(sliderValue);
|
|
2327
|
+
props.onValue && props.onValue(sliderValue);
|
|
2328
|
+
}, [minValue, maxValue, props.formControl, props.onValue]);
|
|
2329
|
+
const onClickTrack = useCallback((event) => {
|
|
2330
|
+
const { left, width } = refTrack.current.getBoundingClientRect();
|
|
2331
|
+
const rate = Math.ceil(((event.clientX - left) / width) * 100);
|
|
2332
|
+
calculateValueWithRate(rate);
|
|
2333
|
+
}, [minValue, maxValue]);
|
|
2334
|
+
return (jsxRuntimeExports.jsxs("div", { className: className, children: [props.children && (jsxRuntimeExports.jsx("span", { className: "rls-slider__label", children: props.children })), jsxRuntimeExports.jsxs("div", { className: "rls-slider__body", children: [props.prefixIcon && jsxRuntimeExports.jsx(RlsIcon, { value: props.prefixIcon }), jsxRuntimeExports.jsxs("div", { ref: refComponent, className: "rls-slider__component", children: [jsxRuntimeExports.jsx("div", { ref: refTrack, className: "rls-slider__track", onClick: onClickTrack, children: jsxRuntimeExports.jsx("div", { ref: refTrackOn, className: "rls-slider__track__on" }) }), jsxRuntimeExports.jsxs("div", { ref: refThumb, className: "rls-slider__thumb", children: [rate, "%"] })] })] })] }));
|
|
2335
|
+
}
|
|
2336
|
+
|
|
2282
2337
|
function RlsToolbar({ actions, children, subtitle }) {
|
|
2283
2338
|
return (jsxRuntimeExports.jsxs("div", { className: "rls-toolbar", children: [jsxRuntimeExports.jsxs("div", { className: "rls-toolbar__description", children: [children && jsxRuntimeExports.jsx("label", { className: "rls-toolbar__title", children: children }), subtitle && (jsxRuntimeExports.jsx("label", { className: "rls-toolbar__subtitle smalltext-semibold", children: subtitle }))] }), actions && (jsxRuntimeExports.jsx("div", { className: "rls-toolbar__actions", children: actions.map((action, index) => (jsxRuntimeExports.jsx("div", { children: action }, index))) }))] }));
|
|
2284
2339
|
}
|
|
@@ -2296,6 +2351,9 @@ const reactI18n = i18n({
|
|
|
2296
2351
|
dateActionCancel: 'Cancelar',
|
|
2297
2352
|
dateActionSelect: 'Establecer',
|
|
2298
2353
|
dateActionToday: 'Hoy',
|
|
2354
|
+
chooserImageActionCancel: 'Cancelar',
|
|
2355
|
+
editorImageActionRestore: 'Restaurar',
|
|
2356
|
+
editorImageActionSelect: 'Seleccionar',
|
|
2299
2357
|
listEmptyDescription: 'Lo sentimos, en el momento no hay elementos en el listado',
|
|
2300
2358
|
listEmptyTitle: 'Selección no disponible',
|
|
2301
2359
|
listInputPlaceholder: 'Escriba palabre clave para filtrar...'
|
|
@@ -2305,6 +2363,9 @@ const reactI18n = i18n({
|
|
|
2305
2363
|
dateActionCancel: 'Cancel',
|
|
2306
2364
|
dateActionSelect: 'Select',
|
|
2307
2365
|
dateActionToday: 'Today',
|
|
2366
|
+
chooserImageActionCancel: 'Cancel',
|
|
2367
|
+
editorImageActionRestore: 'Restore',
|
|
2368
|
+
editorImageActionSelect: 'Select',
|
|
2308
2369
|
listEmptyDescription: 'Sorry, there are currently no items in the list',
|
|
2309
2370
|
listEmptyTitle: 'Selection not available',
|
|
2310
2371
|
listInputPlaceholder: 'Enter keyword to filter...'
|
|
@@ -2560,6 +2621,126 @@ function useListController(props) {
|
|
|
2560
2621
|
};
|
|
2561
2622
|
}
|
|
2562
2623
|
|
|
2624
|
+
function useRelocationOnComponent({ container, element, onDrag }) {
|
|
2625
|
+
const position = useRef({ x: 0, y: 0 });
|
|
2626
|
+
const dragOffset = useRef({ x: 0, y: 0 });
|
|
2627
|
+
const dragging = useRef(false);
|
|
2628
|
+
const getClientX = useCallback((positionX) => {
|
|
2629
|
+
let clientX = position.current.x + positionX - dragOffset.current.x;
|
|
2630
|
+
if (clientX < 0) {
|
|
2631
|
+
clientX = 0;
|
|
2632
|
+
}
|
|
2633
|
+
else {
|
|
2634
|
+
const width = clientX + element.current.offsetWidth;
|
|
2635
|
+
if (width > container.current.offsetWidth) {
|
|
2636
|
+
clientX = container.current.offsetWidth - element.current.offsetWidth;
|
|
2637
|
+
}
|
|
2638
|
+
}
|
|
2639
|
+
return clientX;
|
|
2640
|
+
}, []);
|
|
2641
|
+
const getClientY = useCallback((positionY) => {
|
|
2642
|
+
let clientY = position.current.y + positionY - dragOffset.current.y;
|
|
2643
|
+
if (clientY < 0) {
|
|
2644
|
+
clientY = 0;
|
|
2645
|
+
}
|
|
2646
|
+
else {
|
|
2647
|
+
const height = clientY + element.current.offsetHeight;
|
|
2648
|
+
if (height > container.current.offsetHeight) {
|
|
2649
|
+
clientY = container.current.offsetHeight - element.current.offsetHeight;
|
|
2650
|
+
}
|
|
2651
|
+
}
|
|
2652
|
+
return clientY;
|
|
2653
|
+
}, []);
|
|
2654
|
+
const start = useCallback((positionX, positionY) => {
|
|
2655
|
+
dragOffset.current = {
|
|
2656
|
+
x: positionX,
|
|
2657
|
+
y: positionY
|
|
2658
|
+
};
|
|
2659
|
+
position.current = {
|
|
2660
|
+
x: element.current.offsetLeft,
|
|
2661
|
+
y: element.current.offsetTop
|
|
2662
|
+
};
|
|
2663
|
+
dragging.current = true;
|
|
2664
|
+
}, []);
|
|
2665
|
+
const relocation = useCallback((positionX, positionY) => {
|
|
2666
|
+
const clientX = getClientX(positionX);
|
|
2667
|
+
const clientY = getClientY(positionY);
|
|
2668
|
+
element.current.style.top = `${clientY}px`;
|
|
2669
|
+
element.current.style.left = `${clientX}px`;
|
|
2670
|
+
onDrag && onDrag();
|
|
2671
|
+
}, []);
|
|
2672
|
+
useEffect(() => {
|
|
2673
|
+
const mousedown = (event) => {
|
|
2674
|
+
start(event.clientX, event.clientY);
|
|
2675
|
+
};
|
|
2676
|
+
const mousemove = (event) => {
|
|
2677
|
+
if (dragging.current) {
|
|
2678
|
+
relocation(event.clientX, event.clientY);
|
|
2679
|
+
event.preventDefault();
|
|
2680
|
+
}
|
|
2681
|
+
};
|
|
2682
|
+
const mouseup = () => {
|
|
2683
|
+
dragging.current = false;
|
|
2684
|
+
};
|
|
2685
|
+
const touchstart = (event) => {
|
|
2686
|
+
if (event.touches[0]) {
|
|
2687
|
+
start(event.touches[0].clientX, event.touches[0].clientY);
|
|
2688
|
+
}
|
|
2689
|
+
};
|
|
2690
|
+
const touchmove = (event) => {
|
|
2691
|
+
if (event.touches[0] && dragging.current) {
|
|
2692
|
+
relocation(event.touches[0].clientX, event.touches[0].clientY);
|
|
2693
|
+
event.preventDefault();
|
|
2694
|
+
}
|
|
2695
|
+
};
|
|
2696
|
+
const touchend = () => {
|
|
2697
|
+
dragging.current = false;
|
|
2698
|
+
};
|
|
2699
|
+
element.current.addEventListener('mousedown', mousedown);
|
|
2700
|
+
element.current.addEventListener('mousemove', mousemove);
|
|
2701
|
+
element.current.addEventListener('mouseup', mouseup);
|
|
2702
|
+
element.current.addEventListener('touchstart', touchstart);
|
|
2703
|
+
element.current.addEventListener('touchmove', touchmove);
|
|
2704
|
+
element.current.addEventListener('touchend', touchend);
|
|
2705
|
+
return () => {
|
|
2706
|
+
element.current?.removeEventListener('mousedown', mousedown);
|
|
2707
|
+
element.current?.removeEventListener('mousemove', mousemove);
|
|
2708
|
+
element.current?.removeEventListener('mouseup', mouseup);
|
|
2709
|
+
element.current?.removeEventListener('touchstart', touchstart);
|
|
2710
|
+
element.current?.removeEventListener('touchmove', touchmove);
|
|
2711
|
+
element.current?.removeEventListener('touchend', touchend);
|
|
2712
|
+
};
|
|
2713
|
+
}, []);
|
|
2714
|
+
}
|
|
2715
|
+
|
|
2716
|
+
function useResize(props) {
|
|
2717
|
+
const { refElement, onResize } = props;
|
|
2718
|
+
const dimension = useRef({ height: 0, width: 0 });
|
|
2719
|
+
const observer = useCallback((entries) => {
|
|
2720
|
+
const { height, width } = entries[0].contentRect;
|
|
2721
|
+
onResize &&
|
|
2722
|
+
onResize({
|
|
2723
|
+
current: dimension.current,
|
|
2724
|
+
dimension: {
|
|
2725
|
+
height,
|
|
2726
|
+
width
|
|
2727
|
+
}
|
|
2728
|
+
});
|
|
2729
|
+
dimension.current = { height, width };
|
|
2730
|
+
}, []);
|
|
2731
|
+
useEffect(() => {
|
|
2732
|
+
dimension.current = {
|
|
2733
|
+
height: refElement.current.offsetHeight,
|
|
2734
|
+
width: refElement.current.offsetWidth
|
|
2735
|
+
};
|
|
2736
|
+
const resizeObserver = new ResizeObserver(observer);
|
|
2737
|
+
resizeObserver.observe(refElement.current);
|
|
2738
|
+
return () => {
|
|
2739
|
+
resizeObserver.disconnect();
|
|
2740
|
+
};
|
|
2741
|
+
}, []);
|
|
2742
|
+
}
|
|
2743
|
+
|
|
2563
2744
|
const DURATION_ANIMATION$1 = 240;
|
|
2564
2745
|
const MAX_ELEMENTS = 6;
|
|
2565
2746
|
function useFieldAutocomplete(props) {
|
|
@@ -2739,11 +2920,11 @@ function RlsFieldAutocomplete(props) {
|
|
|
2739
2920
|
return jsxRuntimeExports.jsx(RlsFieldAutocompleteTemplate, { ...props, render: render });
|
|
2740
2921
|
}
|
|
2741
2922
|
|
|
2742
|
-
function RlsModal({ children, overflow, visible, rlsTheme }) {
|
|
2743
|
-
const
|
|
2744
|
-
return renderClassStatus('rls-modal', { overflow, visible });
|
|
2745
|
-
}, [overflow, visible]);
|
|
2746
|
-
return ReactDOM.createPortal(jsxRuntimeExports.jsxs("div", { className:
|
|
2923
|
+
function RlsModal({ children, className, overflow, visible, rlsTheme }) {
|
|
2924
|
+
const classNameModal = useMemo(() => {
|
|
2925
|
+
return renderClassStatus('rls-modal', { overflow, visible }, className);
|
|
2926
|
+
}, [className, overflow, visible]);
|
|
2927
|
+
return ReactDOM.createPortal(jsxRuntimeExports.jsxs("div", { className: classNameModal, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-modal__component", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-modal__backdrop" })] }), document.body);
|
|
2747
2928
|
}
|
|
2748
2929
|
|
|
2749
2930
|
const formatTitle = '{dw}, {mx} {dd} de {aa}';
|
|
@@ -3134,6 +3315,259 @@ function RlsFormNavigation({ children, visible, rlsTheme }) {
|
|
|
3134
3315
|
return (jsxRuntimeExports.jsx("div", { className: className, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-form-navigation__body", children: children }) }));
|
|
3135
3316
|
}
|
|
3136
3317
|
|
|
3318
|
+
function getRatioFactor(ratio) {
|
|
3319
|
+
switch (ratio) {
|
|
3320
|
+
case '16:9':
|
|
3321
|
+
return 9 / 16;
|
|
3322
|
+
case '8:5':
|
|
3323
|
+
return 5 / 8;
|
|
3324
|
+
case '4:3':
|
|
3325
|
+
return 3 / 4;
|
|
3326
|
+
case '3:4':
|
|
3327
|
+
return 4 / 3;
|
|
3328
|
+
case '3:2':
|
|
3329
|
+
return 2 / 3;
|
|
3330
|
+
default:
|
|
3331
|
+
return 1;
|
|
3332
|
+
}
|
|
3333
|
+
}
|
|
3334
|
+
function simpleThreeRule(value1, value2, proportion) {
|
|
3335
|
+
return (value2 * proportion) / value1;
|
|
3336
|
+
}
|
|
3337
|
+
function RlsImageEditor(props) {
|
|
3338
|
+
const [selection, setSelection] = useState(props.rateSelection ?? 60);
|
|
3339
|
+
const [labels, setLabels] = useState({
|
|
3340
|
+
actionRestore: reactI18n('editorImageActionRestore'),
|
|
3341
|
+
actionSelect: reactI18n('editorImageActionSelect')
|
|
3342
|
+
});
|
|
3343
|
+
const refBody = useRef(null);
|
|
3344
|
+
const refImage = useRef(null);
|
|
3345
|
+
const refSelection = useRef(null);
|
|
3346
|
+
const refOverlayTop = useRef(null);
|
|
3347
|
+
const refOverlayBottom = useRef(null);
|
|
3348
|
+
const refOverlayLeft = useRef(null);
|
|
3349
|
+
const refOverlayRight = useRef(null);
|
|
3350
|
+
const refCanvas = useRef(null);
|
|
3351
|
+
const refPicture = useRef(null);
|
|
3352
|
+
const image = useRef(new Image());
|
|
3353
|
+
const originalImage = useRef();
|
|
3354
|
+
const getCropProperties = useCallback(() => {
|
|
3355
|
+
return {
|
|
3356
|
+
height: simpleThreeRule(refImage.current.offsetHeight, image.current.height, refSelection.current.offsetHeight),
|
|
3357
|
+
left: simpleThreeRule(refImage.current.offsetWidth, image.current.width, refSelection.current.offsetLeft),
|
|
3358
|
+
top: simpleThreeRule(refImage.current.offsetHeight, image.current.height, refSelection.current.offsetTop),
|
|
3359
|
+
width: simpleThreeRule(refImage.current.offsetWidth, image.current.width, refSelection.current.offsetWidth)
|
|
3360
|
+
};
|
|
3361
|
+
}, []);
|
|
3362
|
+
const refreshOverlaysStyle = useCallback(() => {
|
|
3363
|
+
const width = refSelection.current.offsetWidth;
|
|
3364
|
+
const height = refSelection.current.offsetHeight;
|
|
3365
|
+
const top = refSelection.current.offsetTop;
|
|
3366
|
+
const left = refSelection.current.offsetLeft;
|
|
3367
|
+
refOverlayTop.current.style.width = `${width}px`;
|
|
3368
|
+
refOverlayTop.current.style.bottom = `calc(100% - ${top}px)`;
|
|
3369
|
+
refOverlayTop.current.style.left = `${left}px`;
|
|
3370
|
+
refOverlayRight.current.style.left = `calc(${width + left}px)`;
|
|
3371
|
+
refOverlayRight.current.style.width = `calc(100% - ${width + left}px)`;
|
|
3372
|
+
refOverlayBottom.current.style.width = `${width}px`;
|
|
3373
|
+
refOverlayBottom.current.style.top = `calc(${height + top}px)`;
|
|
3374
|
+
refOverlayBottom.current.style.left = `${left}px`;
|
|
3375
|
+
refOverlayLeft.current.style.right = `calc(100% - ${left}px)`;
|
|
3376
|
+
refOverlayLeft.current.style.width = `calc(${left}px)`;
|
|
3377
|
+
}, []);
|
|
3378
|
+
const refreshSelectionFromWidth = useCallback((rateSelection) => {
|
|
3379
|
+
const _ratio = rateSelection * getRatioFactor(props.ratio || '1:1');
|
|
3380
|
+
let width = (refImage.current.offsetWidth * rateSelection) / 100;
|
|
3381
|
+
let height = (refImage.current.offsetWidth * _ratio) / 100;
|
|
3382
|
+
if (height > refImage.current.offsetHeight) {
|
|
3383
|
+
height = refImage.current.offsetHeight;
|
|
3384
|
+
width =
|
|
3385
|
+
(height * refImage.current.offsetHeight) /
|
|
3386
|
+
refImage.current.offsetHeight;
|
|
3387
|
+
}
|
|
3388
|
+
return { height, width };
|
|
3389
|
+
}, [props.ratio]);
|
|
3390
|
+
const refreshSelectionFromHeight = useCallback((rateSelection) => {
|
|
3391
|
+
const _ratio = rateSelection * getRatioFactor(props.ratio || '1:1');
|
|
3392
|
+
let height = (refImage.current.offsetHeight * rateSelection) / 100;
|
|
3393
|
+
let width = (refImage.current.offsetHeight * _ratio) / 100;
|
|
3394
|
+
if (width > refImage.current.offsetWidth) {
|
|
3395
|
+
width = refImage.current.offsetWidth;
|
|
3396
|
+
height =
|
|
3397
|
+
(width * refImage.current.offsetWidth) / refImage.current.offsetWidth;
|
|
3398
|
+
}
|
|
3399
|
+
return { height, width };
|
|
3400
|
+
}, [props.ratio]);
|
|
3401
|
+
const refreshSelectionStyle = useCallback((rateSelection) => {
|
|
3402
|
+
if (image.current.width > 0 && image.current.height > 0) {
|
|
3403
|
+
const { height, width } = image.current.width >= image.current.height
|
|
3404
|
+
? refreshSelectionFromHeight(rateSelection)
|
|
3405
|
+
: refreshSelectionFromWidth(rateSelection);
|
|
3406
|
+
refSelection.current.style.width = `${width}px`;
|
|
3407
|
+
refSelection.current.style.height = `${height}px`;
|
|
3408
|
+
if (refSelection.current.offsetLeft + width >
|
|
3409
|
+
refImage.current.offsetWidth) {
|
|
3410
|
+
const selectionLeft = refImage.current.offsetWidth - width;
|
|
3411
|
+
refSelection.current.style.left = `${selectionLeft}px`;
|
|
3412
|
+
}
|
|
3413
|
+
if (refSelection.current.offsetTop + height >
|
|
3414
|
+
refImage.current.offsetHeight) {
|
|
3415
|
+
const selectionTop = refImage.current.offsetHeight - height;
|
|
3416
|
+
refSelection.current.style.top = `${selectionTop}px`;
|
|
3417
|
+
}
|
|
3418
|
+
refreshOverlaysStyle();
|
|
3419
|
+
}
|
|
3420
|
+
}, [props.ratio]);
|
|
3421
|
+
const setImageStyle = useCallback((width, height) => {
|
|
3422
|
+
refImage.current.style.width = width;
|
|
3423
|
+
refImage.current.style.height = height;
|
|
3424
|
+
refCanvas.current.style.width = width;
|
|
3425
|
+
refCanvas.current.style.height = height;
|
|
3426
|
+
}, []);
|
|
3427
|
+
const refreshImageStyle = useCallback(() => {
|
|
3428
|
+
if (image.current.width <= 0 || image.current.height <= 0) {
|
|
3429
|
+
return setImageStyle('0%', '0%');
|
|
3430
|
+
}
|
|
3431
|
+
const height = (refBody.current.offsetWidth * image.current.height) /
|
|
3432
|
+
image.current.width;
|
|
3433
|
+
if (height <= refBody.current.offsetHeight) {
|
|
3434
|
+
return setImageStyle('100%', `${height}px`);
|
|
3435
|
+
}
|
|
3436
|
+
const width = (refBody.current.offsetHeight * image.current.width) /
|
|
3437
|
+
image.current.height;
|
|
3438
|
+
return setImageStyle(`${width}px`, '100%');
|
|
3439
|
+
}, []);
|
|
3440
|
+
useEffect(() => {
|
|
3441
|
+
image.current.onload = () => {
|
|
3442
|
+
const context = refCanvas.current.getContext('2d', {
|
|
3443
|
+
willReadFrequently: true
|
|
3444
|
+
});
|
|
3445
|
+
refCanvas.current.width = image.current.width;
|
|
3446
|
+
refCanvas.current.height = image.current.height;
|
|
3447
|
+
context?.drawImage(image.current, 0, 0, image.current.width, image.current.height);
|
|
3448
|
+
originalImage.current = context?.getImageData(0, 0, refCanvas.current.width, refCanvas.current.height);
|
|
3449
|
+
refreshImageStyle();
|
|
3450
|
+
refreshSelectionStyle(selection);
|
|
3451
|
+
};
|
|
3452
|
+
const unsubscription = i18nSubscribe(() => {
|
|
3453
|
+
setLabels({
|
|
3454
|
+
actionRestore: reactI18n('editorImageActionRestore'),
|
|
3455
|
+
actionSelect: reactI18n('editorImageActionSelect')
|
|
3456
|
+
});
|
|
3457
|
+
});
|
|
3458
|
+
window.addEventListener('resize', refreshImageStyle);
|
|
3459
|
+
return () => {
|
|
3460
|
+
window.removeEventListener('resize', refreshImageStyle);
|
|
3461
|
+
unsubscription();
|
|
3462
|
+
};
|
|
3463
|
+
}, []);
|
|
3464
|
+
useEffect(() => {
|
|
3465
|
+
image.current.src = props.src || '';
|
|
3466
|
+
}, [props.src]);
|
|
3467
|
+
useEffect(() => {
|
|
3468
|
+
refreshSelectionStyle(selection);
|
|
3469
|
+
}, [selection]);
|
|
3470
|
+
const onResizeElement = useCallback(() => {
|
|
3471
|
+
refreshSelectionStyle(selection);
|
|
3472
|
+
}, [selection]);
|
|
3473
|
+
useRelocationOnComponent({
|
|
3474
|
+
container: refImage,
|
|
3475
|
+
element: refSelection,
|
|
3476
|
+
onDrag: refreshOverlaysStyle
|
|
3477
|
+
});
|
|
3478
|
+
useResize({ refElement: refImage, onResize: onResizeElement });
|
|
3479
|
+
const onCropImage = useCallback(() => {
|
|
3480
|
+
const cropProps = getCropProperties();
|
|
3481
|
+
const width = props.imgWidth || cropProps.width;
|
|
3482
|
+
const height = width * getRatioFactor(props.ratio || '1:1');
|
|
3483
|
+
refPicture.current.width = width;
|
|
3484
|
+
refPicture.current.height = height;
|
|
3485
|
+
const context = refPicture.current.getContext('2d');
|
|
3486
|
+
context?.drawImage(refCanvas.current, cropProps.left, cropProps.top, cropProps.width, cropProps.height, 0, 0, width, height);
|
|
3487
|
+
refPicture.current.toBlob((blob) => {
|
|
3488
|
+
if (blob) {
|
|
3489
|
+
const reader = new FileReader();
|
|
3490
|
+
reader.readAsDataURL(blob);
|
|
3491
|
+
reader.onloadend = function () {
|
|
3492
|
+
const value = {
|
|
3493
|
+
base64: reader.result,
|
|
3494
|
+
blob
|
|
3495
|
+
};
|
|
3496
|
+
props.onValue && props.onValue(value);
|
|
3497
|
+
props.formControl?.setValue(value);
|
|
3498
|
+
};
|
|
3499
|
+
}
|
|
3500
|
+
}, props.mimeType || 'image/jpeg', 1);
|
|
3501
|
+
}, [
|
|
3502
|
+
props.ratio,
|
|
3503
|
+
props.mimeType,
|
|
3504
|
+
props.onValue,
|
|
3505
|
+
props.formControl,
|
|
3506
|
+
props.imgWidth
|
|
3507
|
+
]);
|
|
3508
|
+
const onRestore = useCallback(() => {
|
|
3509
|
+
const context = refCanvas.current.getContext('2d');
|
|
3510
|
+
if (originalImage.current) {
|
|
3511
|
+
context?.putImageData(originalImage.current, 0, 0);
|
|
3512
|
+
}
|
|
3513
|
+
}, []);
|
|
3514
|
+
return (jsxRuntimeExports.jsxs("div", { className: "rls-image-editor", children: [jsxRuntimeExports.jsx("div", { ref: refBody, className: "rls-image-editor__body", children: jsxRuntimeExports.jsxs("div", { ref: refImage, className: "rls-image-editor__body__image", children: [jsxRuntimeExports.jsx("div", { ref: refSelection, className: "rls-image-editor__body__selection" }), jsxRuntimeExports.jsx("div", { ref: refOverlayTop, className: "rls-image-editor__body__overlay--top" }), jsxRuntimeExports.jsx("div", { ref: refOverlayRight, className: "rls-image-editor__body__overlay--right" }), jsxRuntimeExports.jsx("div", { ref: refOverlayBottom, className: "rls-image-editor__body__overlay--bottom" }), jsxRuntimeExports.jsx("div", { ref: refOverlayLeft, className: "rls-image-editor__body__overlay--left" }), jsxRuntimeExports.jsx("canvas", { ref: refCanvas })] }) }), jsxRuntimeExports.jsxs("div", { className: "rls-image-editor__footer", children: [jsxRuntimeExports.jsx("div", { className: "rls-image-editor__sliders", children: jsxRuntimeExports.jsx(RlsSlider, { prefixIcon: "external-link", value: selection, minValue: 50, maxValue: 100, onValue: setSelection, disabled: props.disabled }) }), jsxRuntimeExports.jsxs("div", { className: "rls-image-editor__actions", children: [props.children, jsxRuntimeExports.jsx(RlsButton, { type: "classic", prefixIcon: "refresh", onClick: onRestore, disabled: props.disabled, children: labels.actionRestore }), jsxRuntimeExports.jsx(RlsButton, { type: "raised", prefixIcon: "crop", onClick: onCropImage, disabled: props.disabled, children: labels.actionSelect })] })] }), jsxRuntimeExports.jsx("canvas", { ref: refPicture })] }));
|
|
3515
|
+
}
|
|
3516
|
+
|
|
3517
|
+
const mimeTypeSupports = [
|
|
3518
|
+
'image/png',
|
|
3519
|
+
'image/jpg',
|
|
3520
|
+
'image/jpeg',
|
|
3521
|
+
'image/bmp',
|
|
3522
|
+
'image/webp',
|
|
3523
|
+
'image/gif',
|
|
3524
|
+
'image/svg+xml'
|
|
3525
|
+
];
|
|
3526
|
+
function RlsImageChooser(props) {
|
|
3527
|
+
const refInput = useRef(null);
|
|
3528
|
+
const [labels, setLabels] = useState({
|
|
3529
|
+
actionCancel: reactI18n('chooserImageActionCancel')
|
|
3530
|
+
});
|
|
3531
|
+
const [src, setSrc] = useState();
|
|
3532
|
+
const [srcEditor, setSrcEditor] = useState();
|
|
3533
|
+
const onSelect = useCallback(() => {
|
|
3534
|
+
refInput.current.click();
|
|
3535
|
+
}, []);
|
|
3536
|
+
const processImage = useCallback((file) => {
|
|
3537
|
+
const reader = new FileReader();
|
|
3538
|
+
reader.onload = function () {
|
|
3539
|
+
setSrcEditor(reader.result);
|
|
3540
|
+
refInput.current.value = '';
|
|
3541
|
+
};
|
|
3542
|
+
reader.readAsDataURL(file);
|
|
3543
|
+
}, []);
|
|
3544
|
+
useEffect(() => {
|
|
3545
|
+
refInput.current.onchange = () => {
|
|
3546
|
+
if (refInput.current.files &&
|
|
3547
|
+
mimeTypeSupports.includes(refInput.current.files[0].type)) {
|
|
3548
|
+
processImage(refInput.current.files[0]);
|
|
3549
|
+
}
|
|
3550
|
+
};
|
|
3551
|
+
return i18nSubscribe(() => {
|
|
3552
|
+
setLabels({
|
|
3553
|
+
actionCancel: reactI18n('chooserImageActionCancel')
|
|
3554
|
+
});
|
|
3555
|
+
});
|
|
3556
|
+
}, []);
|
|
3557
|
+
useEffect(() => {
|
|
3558
|
+
props.src && setSrc(props.src);
|
|
3559
|
+
}, [props.src]);
|
|
3560
|
+
const onEditorValue = useCallback((image) => {
|
|
3561
|
+
setSrc(image.base64);
|
|
3562
|
+
setSrcEditor(undefined);
|
|
3563
|
+
props.onValue && props.onValue(image);
|
|
3564
|
+
}, [props.onValue]);
|
|
3565
|
+
const onCancel = useCallback(() => {
|
|
3566
|
+
setSrcEditor(undefined);
|
|
3567
|
+
}, []);
|
|
3568
|
+
return (jsxRuntimeExports.jsxs("div", { className: "rls-image-chooser", children: [jsxRuntimeExports.jsx("div", { className: "rls-image-chooser__avatar", onClick: onSelect, children: src && jsxRuntimeExports.jsx("img", { src: src }) }), srcEditor && (jsxRuntimeExports.jsx(RlsModal, { className: "rls-image-chooser__modal", visible: true, children: jsxRuntimeExports.jsx(RlsImageEditor, { src: srcEditor, formControl: props.formControl, imgWidth: props.imgWidth, onValue: onEditorValue, children: jsxRuntimeExports.jsx(RlsButton, { type: "flat", rlsTheme: "danger", onClick: onCancel, disabled: props.disabled, children: labels.actionCancel }) }) })), jsxRuntimeExports.jsx("input", { ref: refInput, type: "file", disabled: props.disabled })] }));
|
|
3569
|
+
}
|
|
3570
|
+
|
|
3137
3571
|
const DURATION_ANIMATION = 240;
|
|
3138
3572
|
const DURATION_CHAR = 75;
|
|
3139
3573
|
const DURATION_MAX = 9000;
|
|
@@ -3220,5 +3654,5 @@ function RlsApplication({ children }) {
|
|
|
3220
3654
|
}, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children, RlsSnackbar] }), RlsConfirmation] }));
|
|
3221
3655
|
}
|
|
3222
3656
|
|
|
3223
|
-
export { ConfirmationResult, RlsAlert, RlsAmount, RlsApplication, RlsAvatar, RlsBadge, RlsBallot, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonProgress, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsConfirmation, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableFloating, RlsDatatableHeader, RlsDatatableRecord, RlsDatatableSubheader, RlsDatatableTitle, RlsDatatableTotals, RlsFieldAutocomplete, RlsFieldAutocompleteTemplate, RlsFieldDate, RlsFieldDateRange, RlsFieldMoney, RlsFieldNumber, RlsFieldPassword, RlsFieldReadonly, RlsFieldSelect, RlsFieldSelectTemplate, RlsFieldText, RlsFormNavigation, RlsIcon, RlsInput, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputSearch, RlsInputText, RlsLabel, RlsLabelCheckBox, RlsLabelRadioButton, RlsLabelSwitch, RlsMessageFormError, RlsMessageIcon, RlsModal, RlsPagination, RlsPickerDate, RlsPickerDateRange, RlsPickerDay, RlsPickerDayRange, RlsPickerMonth, RlsPickerSelectorTitle, RlsPickerYear, RlsPoster, RlsProgressBar, RlsProgressCircular, RlsRadioButton, RlsSkeleton, RlsSkeletonText, RlsSnackbar, RlsSwitch, RlsSwitchControl, RlsTabularText, RlsToolbar, rangeFormatTemplate, renderClassStatus, setErrorsI18n, useConfirmation, useDatatable, useFieldAutocomplete, useFieldSelect, useListController, useSnackbar };
|
|
3657
|
+
export { ConfirmationResult, RlsAlert, RlsAmount, RlsApplication, RlsAvatar, RlsBadge, RlsBallot, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonProgress, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsConfirmation, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableFloating, RlsDatatableHeader, RlsDatatableRecord, RlsDatatableSubheader, RlsDatatableTitle, RlsDatatableTotals, RlsFieldAutocomplete, RlsFieldAutocompleteTemplate, RlsFieldDate, RlsFieldDateRange, RlsFieldMoney, RlsFieldNumber, RlsFieldPassword, RlsFieldReadonly, RlsFieldSelect, RlsFieldSelectTemplate, RlsFieldText, RlsFormNavigation, RlsIcon, RlsImageChooser, RlsImageEditor, RlsInput, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputSearch, RlsInputText, RlsLabel, RlsLabelCheckBox, RlsLabelRadioButton, RlsLabelSwitch, RlsMessageFormError, RlsMessageIcon, RlsModal, RlsPagination, RlsPickerDate, RlsPickerDateRange, RlsPickerDay, RlsPickerDayRange, RlsPickerMonth, RlsPickerSelectorTitle, RlsPickerYear, RlsPoster, RlsProgressBar, RlsProgressCircular, RlsRadioButton, RlsSkeleton, RlsSkeletonText, RlsSlider, RlsSnackbar, RlsSwitch, RlsSwitchControl, RlsTabularText, RlsToolbar, rangeFormatTemplate, renderClassStatus, setErrorsI18n, useConfirmation, useDatatable, useFieldAutocomplete, useFieldSelect, useListController, useRelocationOnComponent, useResize, useSnackbar };
|
|
3224
3658
|
//# sourceMappingURL=index.js.map
|