@rolster/react-components 19.8.18 → 19.8.20

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.
@@ -1981,7 +1981,7 @@ function RlsNavbarMenuComponent({ options, onOption }) {
1981
1981
  }
1982
1982
  const RlsNavbarMenu = require$$0.memo(RlsNavbarMenuComponent);
1983
1983
 
1984
- function PageButton({ page, onSelect }) {
1984
+ function RlsPaginationButton({ page, onSelect }) {
1985
1985
  const className = renderClassStatus('rls-pagination__page', {
1986
1986
  active: page.active
1987
1987
  });
@@ -2035,7 +2035,7 @@ function RlsPaginationComponent({ suggestions, count, filter, onPagination, posi
2035
2035
  const goLastPagination = require$$0.useCallback(() => {
2036
2036
  refreshPagination(controller.current?.goLastPage());
2037
2037
  }, [refreshPagination]);
2038
- return (jsxRuntimeExports.jsxs("div", { className: "rls-pagination", children: [jsxRuntimeExports.jsxs("div", { className: "rls-pagination__actions", children: [jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goFirstPagination, disabled: template?.firstPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrowhead-left" }) }), jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goPreviousPagination, disabled: template?.firstPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrow-ios-left" }) })] }), jsxRuntimeExports.jsxs("div", { className: "rls-pagination__body", children: [jsxRuntimeExports.jsx("div", { className: "rls-pagination__pages", children: template?.pages.map((page) => (jsxRuntimeExports.jsx(PageButton, { page: page, onSelect: goToPagination }, page.value))) }), jsxRuntimeExports.jsx("div", { className: "rls-pagination__description", children: template?.description }), jsxRuntimeExports.jsx("span", { className: "rls-pagination__count", children: suggestions.length })] }), jsxRuntimeExports.jsxs("div", { className: "rls-pagination__actions", children: [jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goNextPagination, disabled: template?.lastPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrow-ios-right" }) }), jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goLastPagination, disabled: template?.lastPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrowhead-right" }) })] })] }));
2038
+ return (jsxRuntimeExports.jsxs("div", { className: "rls-pagination", children: [jsxRuntimeExports.jsxs("div", { className: "rls-pagination__actions", children: [jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goFirstPagination, disabled: template?.firstPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrowhead-left" }) }), jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goPreviousPagination, disabled: template?.firstPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrow-ios-left" }) })] }), jsxRuntimeExports.jsxs("div", { className: "rls-pagination__body", children: [jsxRuntimeExports.jsx("div", { className: "rls-pagination__pages", children: template?.pages.map((page) => (jsxRuntimeExports.jsx(RlsPaginationButton, { page: page, onSelect: goToPagination }, page.value))) }), jsxRuntimeExports.jsx("div", { className: "rls-pagination__description", children: template?.description }), jsxRuntimeExports.jsx("span", { className: "rls-pagination__count", children: suggestions.length })] }), jsxRuntimeExports.jsxs("div", { className: "rls-pagination__actions", children: [jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goNextPagination, disabled: template?.lastPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrow-ios-right" }) }), jsxRuntimeExports.jsx("button", { className: "rls-pagination__action", onClick: goLastPagination, disabled: template?.lastPage, children: jsxRuntimeExports.jsx(RlsIcon, { value: "arrowhead-right" }) })] })] }));
2039
2039
  }
2040
2040
  const RlsPagination = require$$0.memo(RlsPaginationComponent);
2041
2041
 
@@ -2376,57 +2376,183 @@ function RlsPickerYearComponent({ date, disabled, formControl, maxDate, minDate,
2376
2376
  }
2377
2377
  const RlsPickerYear = require$$0.memo(RlsPickerYearComponent);
2378
2378
 
2379
- function calculateInitialValue(value, minValue, maxValue) {
2380
- return minValue > value ? minValue : maxValue < value ? maxValue : value;
2379
+ const RATE_MIN = 0;
2380
+ const RATE_MAX = 100;
2381
+ const PRECISION = 12;
2382
+ function clampNumber(value, minValue, maxValue) {
2383
+ if (minValue > maxValue) {
2384
+ return minValue;
2385
+ }
2386
+ return Math.min(Math.max(value, minValue), maxValue);
2387
+ }
2388
+ function normalizeSliderValue(value, minValue, maxValue, step) {
2389
+ const valueClamped = clampNumber(value, minValue, maxValue);
2390
+ if (!step || step <= 0) {
2391
+ return valueClamped;
2392
+ }
2393
+ if (valueClamped <= minValue) {
2394
+ return minValue;
2395
+ }
2396
+ if (valueClamped >= maxValue) {
2397
+ return maxValue;
2398
+ }
2399
+ const steps = Math.round((valueClamped - minValue) / step);
2400
+ const valueStepped = parseFloat((minValue + steps * step).toPrecision(PRECISION));
2401
+ return clampNumber(valueStepped, minValue, maxValue);
2402
+ }
2403
+ function sliderValueToRate(value, minValue, maxValue) {
2404
+ const range = maxValue - minValue;
2405
+ if (range <= 0) {
2406
+ return RATE_MIN;
2407
+ }
2408
+ return clampNumber(((value - minValue) / range) * RATE_MAX, RATE_MIN, RATE_MAX);
2381
2409
  }
2382
- function calculateInitialRate(value, minValue, maxValue) {
2383
- const rateMax = maxValue - minValue;
2384
- const rateValue = value - minValue;
2385
- return Math.ceil((rateValue / rateMax) * 100);
2410
+ function sliderRateToValue(rate, minValue, maxValue, step) {
2411
+ const range = maxValue - minValue;
2412
+ const rateClamped = clampNumber(rate, RATE_MIN, RATE_MAX);
2413
+ return normalizeSliderValue(minValue + (range * rateClamped) / RATE_MAX, minValue, maxValue, step);
2386
2414
  }
2387
- function RlsSliderComponent({ children, className, disabled, formControl, identifier, maxValue, minValue, onValue, prefixIcon, rlsTheme, value }) {
2415
+
2416
+ const DEFAULT_STEP = 1;
2417
+ const PAGE_STEP_DIVISOR = 10;
2418
+ function RlsSliderComponent({ children, className, disabled, formControl, identifier, maxValue, minValue, onValue, prefixIcon, rlsTheme, step, value }) {
2388
2419
  const minValueSlider = require$$0.useMemo(() => {
2389
2420
  return minValue ?? 0;
2390
2421
  }, [minValue]);
2391
2422
  const maxValueSlider = require$$0.useMemo(() => {
2392
2423
  return maxValue ?? 100;
2393
2424
  }, [maxValue]);
2394
- const [valueSlider, setValue] = require$$0.useState(calculateInitialValue(formControl?.value ?? value ?? 0, minValueSlider, maxValueSlider));
2395
- const [rate, setRate] = require$$0.useState(calculateInitialRate(valueSlider, minValueSlider, maxValueSlider));
2396
- const refComponent = require$$0.useRef(null);
2425
+ const stepSlider = require$$0.useMemo(() => {
2426
+ return step && step > 0 ? step : DEFAULT_STEP;
2427
+ }, [step]);
2428
+ const [valueSlider, setValueSlider] = require$$0.useState(() => {
2429
+ return normalizeSliderValue(formControl?.value ?? value ?? 0, minValueSlider, maxValueSlider, stepSlider);
2430
+ });
2431
+ const [dragging, setDragging] = require$$0.useState(false);
2397
2432
  const refTrack = require$$0.useRef(null);
2398
- const refTrackOn = require$$0.useRef(null);
2399
2433
  const refThumb = require$$0.useRef(null);
2434
+ const refValue = require$$0.useRef(valueSlider);
2435
+ const refValueExternal = require$$0.useRef(formControl?.value ?? value);
2436
+ const labelId = require$$0.useId();
2437
+ const rate = require$$0.useMemo(() => {
2438
+ return sliderValueToRate(valueSlider, minValueSlider, maxValueSlider);
2439
+ }, [valueSlider, minValueSlider, maxValueSlider]);
2400
2440
  const classNameSlider = renderClassStatus('rls-slider', {
2401
2441
  complet: valueSlider === maxValueSlider,
2402
2442
  disabled: disabled,
2443
+ dragging: dragging,
2403
2444
  empty: valueSlider === minValueSlider
2404
2445
  }, className);
2446
+ const commitValue = require$$0.useCallback((valueNext) => {
2447
+ if (refValue.current === valueNext) {
2448
+ return;
2449
+ }
2450
+ refValue.current = valueNext;
2451
+ setValueSlider(valueNext);
2452
+ formControl?.setValue(valueNext);
2453
+ onValue?.(valueNext);
2454
+ }, [formControl, onValue]);
2455
+ const commitRate = require$$0.useCallback((rateNext) => {
2456
+ commitValue(sliderRateToValue(rateNext, minValueSlider, maxValueSlider, stepSlider));
2457
+ }, [commitValue, minValueSlider, maxValueSlider, stepSlider]);
2458
+ const calculateRateFromClientX = require$$0.useCallback((clientX) => {
2459
+ const { left, width } = refTrack.current.getBoundingClientRect();
2460
+ return width > 0 ? ((clientX - left) / width) * 100 : 0;
2461
+ }, []);
2462
+ const onPointerDown = require$$0.useCallback((event) => {
2463
+ if (disabled) {
2464
+ return;
2465
+ }
2466
+ event.preventDefault();
2467
+ refThumb.current.focus();
2468
+ setDragging(true);
2469
+ commitRate(calculateRateFromClientX(event.clientX));
2470
+ }, [disabled, commitRate, calculateRateFromClientX]);
2471
+ const calculateValueFromKey = require$$0.useCallback((key) => {
2472
+ const pageStep = Math.max(stepSlider, (maxValueSlider - minValueSlider) / PAGE_STEP_DIVISOR);
2473
+ switch (key) {
2474
+ case 'ArrowRight':
2475
+ case 'ArrowUp':
2476
+ return refValue.current + stepSlider;
2477
+ case 'ArrowLeft':
2478
+ case 'ArrowDown':
2479
+ return refValue.current - stepSlider;
2480
+ case 'PageUp':
2481
+ return refValue.current + pageStep;
2482
+ case 'PageDown':
2483
+ return refValue.current - pageStep;
2484
+ case 'Home':
2485
+ return minValueSlider;
2486
+ case 'End':
2487
+ return maxValueSlider;
2488
+ default:
2489
+ return undefined;
2490
+ }
2491
+ }, [stepSlider, minValueSlider, maxValueSlider]);
2492
+ const onKeyDown = require$$0.useCallback((event) => {
2493
+ if (disabled) {
2494
+ return;
2495
+ }
2496
+ const valueNext = calculateValueFromKey(event.key);
2497
+ if (valueNext === undefined) {
2498
+ return;
2499
+ }
2500
+ event.preventDefault();
2501
+ commitValue(normalizeSliderValue(valueNext, minValueSlider, maxValueSlider, stepSlider));
2502
+ }, [
2503
+ disabled,
2504
+ calculateValueFromKey,
2505
+ commitValue,
2506
+ minValueSlider,
2507
+ maxValueSlider,
2508
+ stepSlider
2509
+ ]);
2510
+ require$$0.useEffect(() => {
2511
+ if (!dragging) {
2512
+ return;
2513
+ }
2514
+ const onPointerMove = (event) => {
2515
+ commitRate(calculateRateFromClientX(event.clientX));
2516
+ };
2517
+ const onPointerRelease = () => {
2518
+ setDragging(false);
2519
+ };
2520
+ window.addEventListener('pointermove', onPointerMove);
2521
+ window.addEventListener('pointerup', onPointerRelease);
2522
+ window.addEventListener('pointercancel', onPointerRelease);
2523
+ return () => {
2524
+ window.removeEventListener('pointermove', onPointerMove);
2525
+ window.removeEventListener('pointerup', onPointerRelease);
2526
+ window.removeEventListener('pointercancel', onPointerRelease);
2527
+ };
2528
+ }, [dragging, commitRate, calculateRateFromClientX]);
2405
2529
  require$$0.useEffect(() => {
2406
2530
  const valueInitial = formControl?.value ?? value ?? 0;
2407
- refThumb.current.style.left = `${rate}%`;
2408
- refTrackOn.current.style.width = `${rate}%`;
2409
- if (valueInitial !== valueSlider) {
2410
- formControl?.setValue(valueSlider);
2411
- onValue?.(valueSlider);
2531
+ if (valueInitial !== refValue.current) {
2532
+ formControl?.setValue(refValue.current);
2533
+ onValue?.(refValue.current);
2412
2534
  }
2413
2535
  }, []);
2414
- const calculateValueWithRate = require$$0.useCallback((rate) => {
2415
- const value = Math.ceil(((maxValueSlider - minValueSlider) * rate) / 100);
2416
- refThumb.current.style.left = `${rate}%`;
2417
- refTrackOn.current.style.width = `${rate}%`;
2418
- const sliderValue = value + minValueSlider;
2419
- setRate(rate);
2420
- setValue(sliderValue);
2421
- formControl?.setValue(sliderValue);
2422
- onValue?.(sliderValue);
2423
- }, [minValueSlider, maxValueSlider, formControl, onValue]);
2424
- const onClickTrack = require$$0.useCallback((event) => {
2425
- const { left, width } = refTrack.current.getBoundingClientRect();
2426
- const rate = Math.ceil(((event.clientX - left) / width) * 100);
2427
- calculateValueWithRate(rate);
2428
- }, [minValueSlider, maxValueSlider]);
2429
- return (jsxRuntimeExports.jsxs("div", { id: identifier, className: classNameSlider, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-slider__label", children: children }), jsxRuntimeExports.jsxs("div", { className: "rls-slider__body", children: [prefixIcon && jsxRuntimeExports.jsx(RlsIcon, { value: 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, "%"] })] })] })] }));
2536
+ require$$0.useEffect(() => {
2537
+ const valueExternal = formControl?.value ?? value;
2538
+ if (valueExternal === undefined ||
2539
+ valueExternal === refValueExternal.current) {
2540
+ return;
2541
+ }
2542
+ refValueExternal.current = valueExternal;
2543
+ commitValue(normalizeSliderValue(valueExternal, minValueSlider, maxValueSlider, stepSlider));
2544
+ }, [
2545
+ value,
2546
+ formControl?.value,
2547
+ commitValue,
2548
+ minValueSlider,
2549
+ maxValueSlider,
2550
+ stepSlider
2551
+ ]);
2552
+ require$$0.useEffect(() => {
2553
+ commitValue(normalizeSliderValue(refValue.current, minValueSlider, maxValueSlider, stepSlider));
2554
+ }, [commitValue, minValueSlider, maxValueSlider, stepSlider]);
2555
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: classNameSlider, "rls-theme": rlsTheme, children: [children && (jsxRuntimeExports.jsx("span", { id: labelId, className: "rls-slider__label", children: children })), jsxRuntimeExports.jsxs("div", { className: "rls-slider__body", children: [prefixIcon && jsxRuntimeExports.jsx(RlsIcon, { value: prefixIcon }), jsxRuntimeExports.jsxs("div", { className: "rls-slider__component", onPointerDown: onPointerDown, children: [jsxRuntimeExports.jsx("div", { ref: refTrack, className: "rls-slider__track", children: jsxRuntimeExports.jsx("div", { className: "rls-slider__track__on", style: { width: `${rate}%` } }) }), jsxRuntimeExports.jsx("div", { ref: refThumb, className: "rls-slider__thumb", style: { left: `${rate}%` }, role: "slider", tabIndex: disabled ? -1 : 0, "aria-orientation": "horizontal", "aria-valuemin": minValueSlider, "aria-valuemax": maxValueSlider, "aria-valuenow": valueSlider, "aria-disabled": disabled || undefined, "aria-labelledby": children ? labelId : undefined, onKeyDown: onKeyDown, children: valueSlider })] })] })] }));
2430
2556
  }
2431
2557
  const RlsSlider = require$$0.memo(RlsSliderComponent);
2432
2558
 
@@ -4643,11 +4769,17 @@ function RlsImageEditorComponent(props) {
4643
4769
  useResize({ refElement: refImage, onResize: onResizeElement });
4644
4770
  const onCropImage = require$$0.useCallback(() => {
4645
4771
  const cropProps = getCropProperties();
4646
- const width = props.maxWidth || cropProps.width;
4647
- const height = width * getRatioFactor(ratio);
4772
+ const width = Math.round(props.maxWidth
4773
+ ? Math.min(props.maxWidth, cropProps.width)
4774
+ : cropProps.width);
4775
+ const height = Math.round(width * getRatioFactor(ratio));
4648
4776
  refPicture.current.width = width;
4649
4777
  refPicture.current.height = height;
4650
4778
  const context = refPicture.current.getContext('2d');
4779
+ if (context) {
4780
+ context.imageSmoothingEnabled = true;
4781
+ context.imageSmoothingQuality = 'high';
4782
+ }
4651
4783
  context?.drawImage(refCanvas.current, cropProps.left, cropProps.top, cropProps.width, cropProps.height, 0, 0, width, height);
4652
4784
  refPicture.current.toBlob((blob) => {
4653
4785
  if (blob) {