zcomponents-ui 1.2.4 → 1.4.0

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.
Files changed (39) hide show
  1. package/README.md +20 -0
  2. package/dist/{index-DC_KVC71.js → index-DJALegom.js} +3 -9
  3. package/dist/index-DJALegom.js.map +1 -0
  4. package/dist/{index-CfSBwowY.js → index-zSB3Isbi.js} +3 -9
  5. package/dist/index-zSB3Isbi.js.map +1 -0
  6. package/dist/index.cjs.js +647 -14
  7. package/dist/index.cjs.js.map +1 -1
  8. package/dist/index.d.ts +142 -6
  9. package/dist/index.esm.js +649 -18
  10. package/dist/index.esm.js.map +1 -1
  11. package/dist/integrations-react-hook-form.d-ChOcioDB.d.ts +266 -0
  12. package/dist/react-hook-form.cjs.js +1 -1
  13. package/dist/react-hook-form.d.ts +4 -265
  14. package/dist/react-hook-form.esm.js +1 -1
  15. package/dist/types/components/ZDrop/integrations/react-hook-form/ZDropField/index.d.ts +3 -12
  16. package/dist/types/components/ZDrop/integrations/react-hook-form/ZDropField/types/zDropFieldTypes.d.ts +12 -0
  17. package/dist/types/components/ZDrop/types/zDropTypes.d.ts +2 -2
  18. package/dist/types/components/ZRange/components/ZRangeIndicator/index.d.ts +3 -0
  19. package/dist/types/components/ZRange/components/ZRangeInputs/index.d.ts +3 -0
  20. package/dist/types/components/ZRange/components/ZRangeLabel/index.d.ts +3 -0
  21. package/dist/types/components/ZRange/components/ZRangeSliderValue/index.d.ts +3 -0
  22. package/dist/types/components/ZRange/components/ZRangeTrack/index.d.ts +3 -0
  23. package/dist/types/components/ZRange/helpers/calculateStepPosition.d.ts +1 -0
  24. package/dist/types/components/ZRange/helpers/checkIsInputSwapAllowed.d.ts +1 -0
  25. package/dist/types/components/ZRange/helpers/convertToUnit.d.ts +6 -0
  26. package/dist/types/components/ZRange/helpers/getCssVariablePxValue.d.ts +1 -0
  27. package/dist/types/components/ZRange/helpers/getFractionDigitsFromStep.d.ts +1 -0
  28. package/dist/types/components/ZRange/helpers/getMinMax.d.ts +4 -0
  29. package/dist/types/components/ZRange/index.d.ts +3 -0
  30. package/dist/types/components/ZRange/integrations/react-hook-form/ZRangeField/index.d.ts +7 -0
  31. package/dist/types/components/ZRange/integrations/react-hook-form/ZRangeField/types/zRangeFieldTypes.d.ts +17 -0
  32. package/dist/types/components/ZRange/rangeValue.d.ts +13 -0
  33. package/dist/types/components/ZRange/types/zRangeTypes.d.ts +103 -0
  34. package/dist/types/index.d.ts +7 -2
  35. package/dist/zcomponents-ui.css +1 -1
  36. package/dist/zcomponents-ui.css.map +1 -1
  37. package/package.json +1 -1
  38. package/dist/index-CfSBwowY.js.map +0 -1
  39. package/dist/index-DC_KVC71.js.map +0 -1
package/dist/index.cjs.js CHANGED
@@ -1,22 +1,22 @@
1
1
  'use strict';
2
2
 
3
- var index = require('./index-CfSBwowY.js');
3
+ var index = require('./index-zSB3Isbi.js');
4
4
  var jsxRuntime = require('react/jsx-runtime');
5
5
  var react = require('react');
6
- require('react-hook-form');
6
+ var reactHookForm = require('react-hook-form');
7
7
 
8
- var styles = {"zd-button":"ZDropButton-module_zd-button__XVZ-w","zd-button__toggle":"ZDropButton-module_zd-button__toggle__0jdWn","zd-button__toggle-title":"ZDropButton-module_zd-button__toggle-title__OaiVF","zd-button__toggle-icon":"ZDropButton-module_zd-button__toggle-icon__G4tnb","zd-button__content":"ZDropButton-module_zd-button__content__FS-6m","zd-button__search":"ZDropButton-module_zd-button__search__6Nbrx","zd-button__search-input-field":"ZDropButton-module_zd-button__search-input-field__K2avH","zd-button__search-input":"ZDropButton-module_zd-button__search-input__1e643","zd-button__search-clear-btn":"ZDropButton-module_zd-button__search-clear-btn__hJo2h","zd-button__search-clear-btn-icon":"ZDropButton-module_zd-button__search-clear-btn-icon__PWwHy","zd-button__list":"ZDropButton-module_zd-button__list__prV7p","zd-button__list-item":"ZDropButton-module_zd-button__list-item__uRK0D","zd-button__list-item--active":"ZDropButton-module_zd-button__list-item--active__oPoZA","zd-button__list-item-icon":"ZDropButton-module_zd-button__list-item-icon__xgqOm","zd-button__list-item-title":"ZDropButton-module_zd-button__list-item-title__RHTpc"};
8
+ var styles$1 = {"zd-button":"ZDropButton-module_zd-button__XVZ-w","zd-button__toggle":"ZDropButton-module_zd-button__toggle__0jdWn","zd-button__toggle-title":"ZDropButton-module_zd-button__toggle-title__OaiVF","zd-button__toggle-icon":"ZDropButton-module_zd-button__toggle-icon__G4tnb","zd-button__content":"ZDropButton-module_zd-button__content__FS-6m","zd-button__search":"ZDropButton-module_zd-button__search__6Nbrx","zd-button__search-input-field":"ZDropButton-module_zd-button__search-input-field__K2avH","zd-button__search-input":"ZDropButton-module_zd-button__search-input__1e643","zd-button__search-clear-btn":"ZDropButton-module_zd-button__search-clear-btn__hJo2h","zd-button__search-clear-btn-icon":"ZDropButton-module_zd-button__search-clear-btn-icon__PWwHy","zd-button__list":"ZDropButton-module_zd-button__list__prV7p","zd-button__list-item":"ZDropButton-module_zd-button__list-item__uRK0D","zd-button__list-item--active":"ZDropButton-module_zd-button__list-item--active__oPoZA","zd-button__list-item-icon":"ZDropButton-module_zd-button__list-item-icon__xgqOm","zd-button__list-item-title":"ZDropButton-module_zd-button__list-item-title__RHTpc"};
9
9
 
10
10
  const ButtonDropdownToggle = (props) => {
11
11
  const { title, toggleIcon, toggleClassName, children, onButtonToggleClick } = props;
12
- const toggleClasses = index.classNames(styles["zd-button__toggle"], toggleClassName);
12
+ const toggleClasses = index.classNames(styles$1["zd-button__toggle"], toggleClassName);
13
13
  const onToggleClick = (e) => {
14
14
  onButtonToggleClick();
15
15
  };
16
16
  const onToggleMouseLeave = (e) => {
17
17
  e.currentTarget.blur();
18
18
  };
19
- return (jsxRuntime.jsxs("button", { className: toggleClasses, onMouseLeave: onToggleMouseLeave, onClick: onToggleClick, children: [toggleIcon && (jsxRuntime.jsx("div", { className: styles["zd-button__toggle-icon"], children: toggleIcon })), title && (jsxRuntime.jsx("span", { className: styles["zd-button__toggle-title"], children: title })), children] }));
19
+ return (jsxRuntime.jsxs("button", { className: toggleClasses, onMouseLeave: onToggleMouseLeave, onClick: onToggleClick, children: [toggleIcon && (jsxRuntime.jsx("div", { className: styles$1["zd-button__toggle-icon"], children: toggleIcon })), title && (jsxRuntime.jsx("span", { className: styles$1["zd-button__toggle-title"], children: title })), children] }));
20
20
  };
21
21
 
22
22
  const ZDropButtonContent = (props) => {
@@ -141,19 +141,19 @@ const ZDropButtonContent = (props) => {
141
141
  if (!isOpen) {
142
142
  return null;
143
143
  }
144
- return (jsxRuntime.jsx("div", { className: styles["zd-button__content"], style: positionStyles, ref: contentRef, children: children }));
144
+ return (jsxRuntime.jsx("div", { className: styles$1["zd-button__content"], style: positionStyles, ref: contentRef, children: children }));
145
145
  };
146
146
 
147
147
  const ZDropButtonList = (props) => {
148
148
  const { children } = props;
149
- return jsxRuntime.jsx("ul", { className: styles["zd-button__list"], children: children });
149
+ return jsxRuntime.jsx("ul", { className: styles$1["zd-button__list"], children: children });
150
150
  };
151
151
 
152
152
  const ZDropButtonListItem = (props) => {
153
153
  const { index: index$1, title, Icon, urlPath, className, linkAs: LinkTag = "a", isActive = false, children, } = props;
154
154
  const { addToRefs, optionsRef, onItemSelect, searchInputRef } = react.useContext(ZDropButtonContext);
155
- const itemContainerClasses = (isActive) => index.classNames(styles["zd-button__list-item"], {
156
- [styles["zd-button__list-item--active"]]: !urlPath && isActive,
155
+ const itemContainerClasses = (isActive) => index.classNames(styles$1["zd-button__list-item"], {
156
+ [styles$1["zd-button__list-item--active"]]: !urlPath && isActive,
157
157
  }, className);
158
158
  const onItemClick = (e) => {
159
159
  if (!urlPath) {
@@ -217,15 +217,15 @@ const ZDropButtonListItem = (props) => {
217
217
  };
218
218
  const ItemTypeComponent = urlPath ? LinkTag : "div";
219
219
  return (jsxRuntime.jsx("li", { children: jsxRuntime.jsxs(ItemTypeComponent, { ref: (el) => addToRefs === null || addToRefs === void 0 ? void 0 : addToRefs(el, index$1), className: itemContainerClasses(isActive), tabIndex: 0, onClick: onItemClick, onMouseEnter: onItemMouseEnter, onMouseLeave: onItemMouseLeave, onKeyDown: onItemKeyDown, ...(urlPath &&
220
- (LinkTag === "a" ? { href: urlPath } : { to: urlPath })), children: [Icon && (jsxRuntime.jsx("div", { className: styles["zd-button__list-item-icon"], children: Icon })), jsxRuntime.jsx("span", { className: styles["zd-button__list-item-title"], children: title }), children] }) }));
220
+ (LinkTag === "a" ? { href: urlPath } : { to: urlPath })), children: [Icon && (jsxRuntime.jsx("div", { className: styles$1["zd-button__list-item-icon"], children: Icon })), jsxRuntime.jsx("span", { className: styles$1["zd-button__list-item-title"], children: title }), children] }) }));
221
221
  };
222
222
 
223
223
  const ZDropButtonSearch = (props) => {
224
224
  const { placeholder, searchIcon, clearIcon, searchClassName, shouldFocusOnOpen = false, } = props;
225
225
  const { onSearch, searchInputRef, optionsRef, isOpen } = react.useContext(ZDropButtonContext);
226
226
  const [isSearchActive, setIsSearchActive] = react.useState(false);
227
- const searchFormClasses = index.classNames(styles["zd-button__search"]);
228
- const searchInputFieldClasses = index.classNames(styles["zd-button__search-input-field"], { active: isSearchActive }, searchClassName);
227
+ const searchFormClasses = index.classNames(styles$1["zd-button__search"]);
228
+ const searchInputFieldClasses = index.classNames(styles$1["zd-button__search-input-field"], { active: isSearchActive }, searchClassName);
229
229
  const onInputChange = (e) => {
230
230
  onSearch === null || onSearch === void 0 ? void 0 : onSearch(e);
231
231
  };
@@ -269,7 +269,7 @@ const ZDropButtonSearch = (props) => {
269
269
  searchInputRef.current.focus();
270
270
  }
271
271
  }, []);
272
- return (jsxRuntime.jsx("form", { className: searchFormClasses, onMouseEnter: onSearchMouseEnter, onMouseLeave: onSearchMouseLeave, onKeyDown: onSearchKeyDown, children: jsxRuntime.jsxs("div", { className: searchInputFieldClasses, children: [searchIcon && jsxRuntime.jsx("div", { children: searchIcon }), jsxRuntime.jsx("input", { className: styles["zd-button__search-input"], onChange: onInputChange, ref: searchInputRef, placeholder: placeholder }), jsxRuntime.jsx("button", { className: styles["zd-button__search-clear-btn"], type: "button", onClick: onClearClick, children: clearIcon || (jsxRuntime.jsx("span", { className: styles["zd-button__search-clear-btn-icon"] })) })] }) }));
272
+ return (jsxRuntime.jsx("form", { className: searchFormClasses, onMouseEnter: onSearchMouseEnter, onMouseLeave: onSearchMouseLeave, onKeyDown: onSearchKeyDown, children: jsxRuntime.jsxs("div", { className: searchInputFieldClasses, children: [searchIcon && jsxRuntime.jsx("div", { children: searchIcon }), jsxRuntime.jsx("input", { className: styles$1["zd-button__search-input"], onChange: onInputChange, ref: searchInputRef, placeholder: placeholder }), jsxRuntime.jsx("button", { className: styles$1["zd-button__search-clear-btn"], type: "button", onClick: onClearClick, children: clearIcon || (jsxRuntime.jsx("span", { className: styles$1["zd-button__search-clear-btn-icon"] })) })] }) }));
273
273
  };
274
274
 
275
275
  const ZDropButtonContext = react.createContext({});
@@ -279,7 +279,7 @@ const ZDropButton = (props) => {
279
279
  const optionsRef = react.useRef([]);
280
280
  const searchInputRef = react.useRef(null);
281
281
  const [isOpen, setIsOpen] = react.useState(false);
282
- const buttonContainerClasses = index.classNames(styles["zd-button"], className);
282
+ const buttonContainerClasses = index.classNames(styles$1["zd-button"], className);
283
283
  const addToRefs = (element, index) => {
284
284
  return (optionsRef.current[index] = element);
285
285
  };
@@ -318,7 +318,640 @@ ZDropButton.List = ZDropButtonList;
318
318
  ZDropButton.Item = ZDropButtonListItem;
319
319
  ZDropButton.Search = ZDropButtonSearch;
320
320
 
321
+ const thumbInteractArea = 24;
322
+ const checkIsInputSwapAllowed = (activeIndex, comparedIndex, clientPosition, valuePosition) => {
323
+ return (activeIndex === comparedIndex &&
324
+ clientPosition !== null &&
325
+ clientPosition !== undefined &&
326
+ clientPosition < valuePosition + thumbInteractArea &&
327
+ clientPosition > valuePosition - thumbInteractArea);
328
+ };
329
+
330
+ const getMinMax = (firstValue, secondValue) => {
331
+ const min = firstValue < secondValue ? firstValue : secondValue;
332
+ const max = firstValue > secondValue ? firstValue : secondValue;
333
+ return { min, max };
334
+ };
335
+
336
+ // import { UnitList } from "../types/zRangeTypes";
337
+ const convertToUnit = (rawValue, units = [], unitDivisors = [], isIndicatorUnitHidden = false, scaleFn = (x) => x) => {
338
+ var _a, _b;
339
+ if (!units.length)
340
+ return String(rawValue);
341
+ if (!Number.isFinite(rawValue))
342
+ return String(rawValue);
343
+ const scaled = scaleFn(rawValue);
344
+ const sign = scaled < 0 ? "-" : "";
345
+ const value = Math.abs(scaled);
346
+ const divisors = unitDivisors
347
+ .slice(0, units.length)
348
+ .map((d) => (d > 0 ? d : 1));
349
+ if (!divisors.length) {
350
+ return `${sign}${value.toFixed(units[0].fractionDigits)} ${units[0].unit}`;
351
+ }
352
+ let idx = 0;
353
+ for (let i = 0; i < units.length; i++) {
354
+ const d = (_a = divisors[i]) !== null && _a !== void 0 ? _a : 1;
355
+ if (value >= d)
356
+ idx = i;
357
+ }
358
+ const d = (_b = divisors[idx]) !== null && _b !== void 0 ? _b : 1;
359
+ const converted = value / d;
360
+ if (isIndicatorUnitHidden) {
361
+ return `${sign}${converted.toFixed(units[idx].fractionDigits)}`;
362
+ }
363
+ return `${sign}${converted.toFixed(units[idx].fractionDigits)} ${units[idx].unit}`;
364
+ };
365
+
366
+ const calculateStepPosition = (currentValue, element, min, max) => {
367
+ if (!element) {
368
+ return 0;
369
+ }
370
+ return ((currentValue - min) * element.clientWidth) / (max - min);
371
+ };
372
+
373
+ class ZRangeValue {
374
+ constructor(min, max, unitDivisors, unitList, scale) {
375
+ this.min = min;
376
+ this.max = max;
377
+ this.unitDivisors = unitDivisors;
378
+ this.unitList = unitList;
379
+ this.scale = scale;
380
+ this.min.getPosition = this.getMinPosition.bind(this);
381
+ this.max.getPosition = this.getMaxPosition.bind(this);
382
+ }
383
+ getMinPosition() {
384
+ return calculateStepPosition(this.min.value, this.min.inputRef.current, this.min.initialValue, this.max.initialValue);
385
+ }
386
+ getMaxPosition() {
387
+ return calculateStepPosition(this.max.value, this.max.inputRef.current, this.min.initialValue, this.max.initialValue);
388
+ }
389
+ getRangeMiddle() {
390
+ return (this.max.value - this.min.value) / 2;
391
+ }
392
+ getValueLabel(forValue) {
393
+ const value = getMinMax(this.min.value, this.max.value)[forValue];
394
+ const valueLabel = this.scale ? this.scale(value) : value;
395
+ return this.unitList
396
+ ? convertToUnit(valueLabel, this.unitList, this.unitDivisors).toString()
397
+ : `${valueLabel}`;
398
+ }
399
+ }
400
+
401
+ var styles = {"zr":"ZRange-module_zr__zQajG","zr__container":"ZRange-module_zr__container__XLdRx","zr__label":"ZRange-module_zr__label__eddhI","zr__value-indicator-icon":"ZRange-module_zr__value-indicator-icon__iCqcS","zr__inputs-wrapper":"ZRange-module_zr__inputs-wrapper__yzQxk","zr__slider":"ZRange-module_zr__slider__pD1kE","zr__slider-track":"ZRange-module_zr__slider-track__sZvOt","zr__slider-track-selected-range":"ZRange-module_zr__slider-track-selected-range__lXJE1","zr__slider-values-wrapper":"ZRange-module_zr__slider-values-wrapper__vxSnT","zr__slider-value":"ZRange-module_zr__slider-value__W9jMF","zr__slider-first-value":"ZRange-module_zr__slider-first-value__e7Ik6","zr__error-message":"ZRange-module_zr__error-message__QMDqT"};
402
+
403
+ const getCssVariablePxValue = (element, cssVariableName, fallbackPx) => {
404
+ const rawValue = getComputedStyle(element)
405
+ .getPropertyValue(cssVariableName)
406
+ .trim();
407
+ const parsedPx = parseFloat(rawValue);
408
+ return Number.isFinite(parsedPx) ? parsedPx : fallbackPx;
409
+ };
410
+
411
+ const ZRangeSliderValue = (props) => {
412
+ const { value, icon, sliderValueClassName } = props;
413
+ const thumbClasses = index.classNames(styles["zr__slider-value"], styles["zr__slider-first-value"], sliderValueClassName);
414
+ return (jsxRuntime.jsxs("div", { className: thumbClasses, children: [icon && jsxRuntime.jsx("span", { children: icon }), jsxRuntime.jsx("span", { children: value })] }));
415
+ };
416
+
417
+ const indicatorTopGap = 2; // px
418
+ const ZRangeIndicator = (props) => {
419
+ const { valueIndicatorRef, indicatorStyles, indicatorValue, rangeTrackRef, inputElement, scaleFunction, unitList, unitDivisors, scale, icon, iconKey, isHighlighted, isIndicatorUnitHidden = false, } = props;
420
+ const [valueIndicatorStyles, setValueIndicatorStyles] = react.useState({});
421
+ const indicatorClasses = index.classNames("zr__value-indicator", {
422
+ "zr__value-indicator--active": typeof indicatorValue === "number" && isHighlighted,
423
+ }, indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicator, {
424
+ ...((indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorMin)
425
+ ? { [indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorMin]: iconKey === "min" }
426
+ : {}),
427
+ ...((indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorMax)
428
+ ? { [indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorMax]: iconKey === "max" }
429
+ : {}),
430
+ });
431
+ const indicatorIconClasses = index.classNames(styles["zr__value-indicator-icon"], indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorIcon);
432
+ const indicatorValueClasses = index.classNames("zr__value-indicator-value", indicatorStyles === null || indicatorStyles === void 0 ? void 0 : indicatorStyles.indicatorValue);
433
+ react.useLayoutEffect(() => {
434
+ var _a;
435
+ if (((_a = rangeTrackRef === null || rangeTrackRef === void 0 ? void 0 : rangeTrackRef.current) === null || _a === void 0 ? void 0 : _a.offsetHeight) && inputElement) {
436
+ setValueIndicatorStyles({
437
+ bottom: `${rangeTrackRef.current.offsetHeight +
438
+ getCssVariablePxValue(inputElement, "--thumb-size", 16) / 2 +
439
+ indicatorTopGap}px`,
440
+ });
441
+ }
442
+ }, [indicatorValue, valueIndicatorRef, rangeTrackRef]);
443
+ return (jsxRuntime.jsxs("div", { ref: valueIndicatorRef, style: valueIndicatorStyles, className: indicatorClasses, children: [icon != null && typeof indicatorValue === "number" && (jsxRuntime.jsx("div", { className: indicatorIconClasses, children: icon }, iconKey !== null && iconKey !== void 0 ? iconKey : "indicator-icon")), typeof indicatorValue === "number" && (jsxRuntime.jsx("span", { className: indicatorValueClasses, children: convertToUnit(scale ? scaleFunction(indicatorValue) : indicatorValue, unitList, unitDivisors, isIndicatorUnitHidden) }))] }));
444
+ };
445
+
446
+ const ZRangeTrack = (props) => {
447
+ const { rangeTrackRef, selectedRangeRef, selectedRangeStyle, trackStyles } = props;
448
+ const { trackContainer, trackRange, trackSelected } = trackStyles;
449
+ const trackClasses = index.classNames(styles["zr__slider"], trackContainer);
450
+ const rangeClasses = index.classNames(styles["zr__slider-track"], trackRange);
451
+ const selectedRangeClasses = index.classNames(styles["zr__slider-track-selected-range"], trackSelected);
452
+ return (jsxRuntime.jsxs("div", { className: trackClasses, children: [jsxRuntime.jsx("div", { ref: rangeTrackRef, className: rangeClasses }), jsxRuntime.jsx("div", { ref: selectedRangeRef, className: selectedRangeClasses, style: selectedRangeStyle })] }));
453
+ };
454
+
455
+ const ZRangeInputs = (props) => {
456
+ const { rangeValue, min, max, step, inputMinClasses, inputMaxClasses, onInputChange, onMouseDown, onTouchStart, onMouseMove, onTouchMove, onMouseUp, onTouchEnd, } = props;
457
+ return (jsxRuntime.jsxs("div", { className: styles["zr__inputs-wrapper"], children: [jsxRuntime.jsx("input", { ref: rangeValue.min.inputRef, name: "0", type: "range", min: min, max: max, step: typeof step === "number" ? step : "any", value: rangeValue.min.value, className: inputMinClasses, onInput: onInputChange, onMouseDown: onMouseDown, onTouchStart: onTouchStart, onMouseMove: onMouseMove, onTouchMove: onTouchMove, onMouseUp: onMouseUp, onTouchEnd: onTouchEnd }), jsxRuntime.jsx("input", { ref: rangeValue.max.inputRef, name: "1", type: "range", min: min, max: max, step: typeof step === "number" ? step : "any", value: rangeValue.max.value, className: inputMaxClasses, onInput: onInputChange, onMouseDown: onMouseDown, onTouchStart: onTouchStart, onMouseMove: onMouseMove, onTouchMove: onTouchMove, onMouseUp: onMouseUp, onTouchEnd: onTouchEnd })] }));
458
+ };
459
+
460
+ const ZRangeLabel = (props) => {
461
+ const { label, labelClassName } = props;
462
+ const labelClasses = index.classNames(styles["zr__label"], labelClassName);
463
+ return jsxRuntime.jsx("div", { className: labelClasses, children: label });
464
+ };
465
+
466
+ const getFractionDigitsFromStep = (step) => {
467
+ if (!Number.isFinite(step)) {
468
+ return 0;
469
+ }
470
+ const stepAsString = String(step);
471
+ const scientificNotationMatch = stepAsString.match(/e-(\d+)/i);
472
+ if (scientificNotationMatch) {
473
+ return Number(scientificNotationMatch[1]);
474
+ }
475
+ const dot = stepAsString.indexOf(".");
476
+ return dot >= 0 ? stepAsString.length - dot - 1 : 0;
477
+ };
478
+
479
+ const clamp01 = (v) => Math.min(1, Math.max(0, v));
480
+ const clamp = (v, lo, hi) => Math.min(hi, Math.max(lo, v));
481
+ const normalizeToStep = (value, step) => {
482
+ const digits = getFractionDigitsFromStep(step);
483
+ return Number(value.toFixed(digits));
484
+ };
485
+ const ZRange = (props) => {
486
+ var _a;
487
+ const { value, name, min, max, step, scale, unitDivisors, unitList, label, onSelect, onChange, icons, stylesClasses, isIndicatorUnitHidden, } = props;
488
+ const scaleFunction = (x) =>
489
+ // eslint-disable-next-line no-new-func
490
+ scale ? new Function("x", `return ${scale}`)(x) : x;
491
+ const containerRef = react.useRef(null);
492
+ const rangeTrackRef = react.useRef(null);
493
+ const selectedRangeRef = react.useRef(null);
494
+ const valueIndicatorRef = react.useRef(null);
495
+ const thumbOffsetRef = react.useRef({ 0: 0, 1: 0 });
496
+ const [indicatorValue, setIndicatorValue] = react.useState(undefined);
497
+ const [activeInputIndex, setActiveInputIndex] = react.useState(0);
498
+ const [rangeValue, setRangeValue] = react.useState(new ZRangeValue({
499
+ value: typeof (value === null || value === void 0 ? void 0 : value.min) === "number" ? value.min : min,
500
+ initialValue: min,
501
+ inputRef: react.useRef(null),
502
+ }, {
503
+ value: typeof (value === null || value === void 0 ? void 0 : value.max) === "number" ? value.max : max,
504
+ initialValue: max,
505
+ inputRef: react.useRef(null),
506
+ }, unitDivisors, unitList, scaleFunction));
507
+ const [clientPositionX, setClientPositionX] = react.useState(null);
508
+ const [isMoving, setIsMoving] = react.useState(false);
509
+ const [isHighlighted, setIsHighlighted] = react.useState(false);
510
+ const [selectedRangeStyle, setSelectedRangeStyle] = react.useState({
511
+ width: 0,
512
+ left: 0,
513
+ right: 0,
514
+ });
515
+ const stepValue = typeof step === "number" && step > 0 ? step : 1;
516
+ const maxForInput = min + Math.ceil((max - min) / stepValue) * stepValue;
517
+ const mapValueToInputRange = (domainValue) => domainValue >= max ? maxForInput : domainValue;
518
+ const mapInputRangeToValue = (inputValue) => Math.min(inputValue, max);
519
+ const rangeValueForInput = react.useMemo(() => {
520
+ return new ZRangeValue({
521
+ ...rangeValue.min,
522
+ value: mapValueToInputRange(rangeValue.min.value),
523
+ initialValue: min,
524
+ inputRef: rangeValue.min.inputRef,
525
+ }, {
526
+ ...rangeValue.max,
527
+ value: mapValueToInputRange(rangeValue.max.value),
528
+ initialValue: maxForInput,
529
+ inputRef: rangeValue.max.inputRef,
530
+ }, unitDivisors, unitList, scaleFunction);
531
+ // eslint-disable-next-line react-hooks/exhaustive-deps
532
+ }, [
533
+ rangeValue.min.value,
534
+ rangeValue.max.value,
535
+ min,
536
+ max,
537
+ maxForInput,
538
+ stepValue,
539
+ unitDivisors,
540
+ unitList,
541
+ scale,
542
+ ]);
543
+ const containerClasses = index.classNames(styles["zr__container"], stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.container);
544
+ const inputMinClasses = index.classNames("zr__input", "zr__input-first", {
545
+ "zr__input--active": activeInputIndex === 0 && isHighlighted,
546
+ }, stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.input, activeInputIndex === 0 && isHighlighted && (stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.inputActive)
547
+ ? stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.inputActive
548
+ : "");
549
+ const inputMaxClasses = index.classNames("zr__input", "zr__input-second", { "zr__input--active": activeInputIndex === 1 && isHighlighted }, stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.input, activeInputIndex === 1 && isHighlighted && (stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.inputActive)
550
+ ? stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.inputActive
551
+ : "");
552
+ react.useEffect(() => {
553
+ if (!value)
554
+ return;
555
+ const nextMin = clamp(value.min, min, max);
556
+ const nextMax = clamp(value.max, min, max);
557
+ const nextRangeValue = new ZRangeValue({
558
+ ...rangeValue.min,
559
+ value: nextMin,
560
+ initialValue: min,
561
+ inputRef: rangeValue.min.inputRef,
562
+ }, {
563
+ ...rangeValue.max,
564
+ value: nextMax,
565
+ initialValue: max,
566
+ inputRef: rangeValue.max.inputRef,
567
+ }, unitDivisors, unitList, scaleFunction);
568
+ setRangeValue(nextRangeValue);
569
+ setIndicatorValue(undefined);
570
+ thumbOffsetRef.current[0] = 0;
571
+ thumbOffsetRef.current[1] = 0;
572
+ requestAnimationFrame(() => {
573
+ const val = activeInputIndex === 0 ? nextMin : nextMax;
574
+ setRangeValuePosition(val);
575
+ });
576
+ // eslint-disable-next-line react-hooks/exhaustive-deps
577
+ }, [value === null || value === void 0 ? void 0 : value.min, value === null || value === void 0 ? void 0 : value.max, min, max]);
578
+ const getThumbCenterXInContainer = (input, currentValueReal, containerEl) => {
579
+ const currentValue = mapValueToInputRange(currentValueReal);
580
+ const thumbTravelRatio = clamp01((currentValue - min) / (maxForInput - min));
581
+ const inputRect = input.getBoundingClientRect();
582
+ const containerRect = containerEl.getBoundingClientRect();
583
+ const thumbSize = getCssVariablePxValue(input, "--thumb-size", 16);
584
+ const usable = inputRect.width - thumbSize;
585
+ const thumbCenterXInInput = thumbSize / 2 + usable * thumbTravelRatio;
586
+ const inputLeftInContainer = inputRect.left - containerRect.left;
587
+ return inputLeftInContainer + thumbCenterXInInput;
588
+ };
589
+ const setRangeValuePosition = (currentValueReal, inputIndex = activeInputIndex) => {
590
+ var _a;
591
+ const indicator = valueIndicatorRef.current;
592
+ const container = containerRef.current;
593
+ const input = (_a = (inputIndex === 0
594
+ ? rangeValue.min.inputRef.current
595
+ : rangeValue.max.inputRef.current)) !== null && _a !== void 0 ? _a : rangeValue.min.inputRef.current;
596
+ if (!indicator || !container || !input)
597
+ return;
598
+ const distanceLeft = getThumbCenterXInContainer(input, currentValueReal, container);
599
+ indicator.style.left = `${Math.round(distanceLeft)}px`;
600
+ indicator.style.transform = `translateX(-50%)`;
601
+ };
602
+ const updateRangeValues = (currentValueReal, inputIndex) => {
603
+ const normalizedValue = normalizeToStep(currentValueReal, stepValue);
604
+ const updatedRangeValue = new ZRangeValue({
605
+ ...(inputIndex === 0
606
+ ? { ...rangeValue.min, value: normalizedValue }
607
+ : rangeValue.min),
608
+ }, {
609
+ ...(inputIndex === 0
610
+ ? rangeValue.max
611
+ : { ...rangeValue.max, value: normalizedValue }),
612
+ }, rangeValue.unitDivisors, rangeValue.unitList, rangeValue.scale);
613
+ setRangeValue(updatedRangeValue);
614
+ setIndicatorValue(normalizedValue);
615
+ if (!onChange)
616
+ return;
617
+ const { min: currentMin, max: currentMax } = getMinMax(updatedRangeValue.min.value, updatedRangeValue.max.value);
618
+ onChange({
619
+ ...updatedRangeValue,
620
+ min: { ...updatedRangeValue.min, value: currentMin },
621
+ max: { ...updatedRangeValue.max, value: currentMax },
622
+ }, name);
623
+ };
624
+ const onInputChange = (e) => {
625
+ if (!rangeTrackRef.current ||
626
+ !rangeValue.min.inputRef.current ||
627
+ !rangeValue.max.inputRef.current) {
628
+ return;
629
+ }
630
+ const rawValue = mapInputRangeToValue(Number(e.target.value));
631
+ const snappedValue = Math.round((rawValue - min) / stepValue) * stepValue + min;
632
+ const currentValue = clamp(snappedValue, min, max);
633
+ const rangeTrackRect = rangeTrackRef.current.getBoundingClientRect();
634
+ const clientPositionOnTrack = clientPositionX != null ? clientPositionX - rangeTrackRect.left : null;
635
+ const minValueStepPosition = rangeValue.getMinPosition();
636
+ const maxValueStepPosition = rangeValue.getMaxPosition();
637
+ if (checkIsInputSwapAllowed(activeInputIndex, 0, clientPositionOnTrack, maxValueStepPosition)) {
638
+ return;
639
+ }
640
+ if (checkIsInputSwapAllowed(activeInputIndex, 1, clientPositionOnTrack, minValueStepPosition)) {
641
+ return;
642
+ }
643
+ const { min: currentMin, max: currentMax } = getMinMax(rangeValue.min.value, rangeValue.max.value);
644
+ const rangeMiddle = (currentMax - currentMin) / 2;
645
+ if (rangeValue.max.value > rangeValue.min.value) {
646
+ if (currentValue < currentMin + rangeMiddle) {
647
+ setActiveInputIndex(0);
648
+ setRangeValuePosition(currentValue);
649
+ updateRangeValues(currentValue, 0);
650
+ return;
651
+ }
652
+ if (currentValue > currentMin + rangeMiddle) {
653
+ setActiveInputIndex(1);
654
+ setRangeValuePosition(currentValue);
655
+ updateRangeValues(currentValue, 1);
656
+ return;
657
+ }
658
+ }
659
+ if (rangeValue.min.value > rangeValue.max.value) {
660
+ if (currentValue < currentMin + rangeMiddle) {
661
+ setActiveInputIndex(1);
662
+ setRangeValuePosition(currentValue);
663
+ updateRangeValues(currentValue, 1);
664
+ return;
665
+ }
666
+ if (currentValue > currentMin + rangeMiddle) {
667
+ setActiveInputIndex(0);
668
+ setRangeValuePosition(currentValue);
669
+ updateRangeValues(currentValue, 0);
670
+ return;
671
+ }
672
+ }
673
+ setRangeValuePosition(currentValue);
674
+ updateRangeValues(currentValue, activeInputIndex);
675
+ };
676
+ const onMoveStart = (e) => {
677
+ setIsMoving(true);
678
+ setIsHighlighted(true);
679
+ const clientX = "clientX" in e ? e.clientX : e.touches[0].clientX;
680
+ setClientPositionX(clientX);
681
+ const container = containerRef.current;
682
+ const input = activeInputIndex === 0
683
+ ? rangeValue.min.inputRef.current
684
+ : rangeValue.max.inputRef.current;
685
+ if (container && input) {
686
+ const containerRect = container.getBoundingClientRect();
687
+ const pointerXInContainer = clientX - containerRect.left;
688
+ const currentValReal = activeInputIndex === 0 ? rangeValue.min.value : rangeValue.max.value;
689
+ const thumbXInContainer = getThumbCenterXInContainer(input, currentValReal, container);
690
+ const thumbSize = getCssVariablePxValue(input, "--thumb-size", 16);
691
+ const dist = Math.abs(pointerXInContainer - thumbXInContainer);
692
+ thumbOffsetRef.current[activeInputIndex] =
693
+ dist <= thumbSize / 2 ? pointerXInContainer - thumbXInContainer : 0;
694
+ }
695
+ if (!rangeTrackRef.current ||
696
+ !rangeValue.min.inputRef.current ||
697
+ !rangeValue.max.inputRef.current) {
698
+ return;
699
+ }
700
+ const rangeTrackRect = rangeTrackRef.current.getBoundingClientRect();
701
+ const clientPositionOnTrack = clientX - rangeTrackRect.left;
702
+ const minValueStepPosition = rangeValue.getMinPosition();
703
+ const maxValueStepPosition = rangeValue.getMaxPosition();
704
+ if (checkIsInputSwapAllowed(activeInputIndex, 0, clientPositionOnTrack, maxValueStepPosition)) {
705
+ setActiveInputIndex(1);
706
+ thumbOffsetRef.current[1] = 0;
707
+ setRangeValuePosition(rangeValue.max.value, 1);
708
+ updateRangeValues(rangeValue.max.value, 1);
709
+ }
710
+ if (checkIsInputSwapAllowed(activeInputIndex, 1, clientPositionOnTrack, minValueStepPosition)) {
711
+ setActiveInputIndex(0);
712
+ thumbOffsetRef.current[0] = 0;
713
+ setRangeValuePosition(rangeValue.min.value);
714
+ updateRangeValues(rangeValue.min.value, 0);
715
+ }
716
+ };
717
+ const onMove = (e) => {
718
+ var _a, _b;
719
+ if (!isMoving)
720
+ return;
721
+ e.preventDefault();
722
+ e.stopPropagation();
723
+ const currentPositionX = "clientX" in e ? e.clientX : (_b = (_a = e.touches) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.clientX;
724
+ const element = activeInputIndex === 0
725
+ ? rangeValue.min.inputRef
726
+ : rangeValue.max.inputRef;
727
+ if (!(element.current && currentPositionX != null))
728
+ return;
729
+ const slider = element.current;
730
+ const sliderRect = slider.getBoundingClientRect();
731
+ const offsetX = currentPositionX -
732
+ sliderRect.left -
733
+ thumbOffsetRef.current[activeInputIndex];
734
+ const thumbSize = getCssVariablePxValue(slider, "--thumb-size", 16);
735
+ const usable = Math.max(1, sliderRect.width - thumbSize);
736
+ const posOnUsable = clamp(offsetX - thumbSize / 2, 0, usable);
737
+ const ratio = posOnUsable / usable;
738
+ const rawValue = min + ratio * (maxForInput - min);
739
+ const roundedValue = Math.round((rawValue - min) / stepValue) * stepValue + min;
740
+ const limitedInputValue = clamp(roundedValue, min, maxForInput);
741
+ const limitedRealValue = mapInputRangeToValue(limitedInputValue);
742
+ setRangeValuePosition(limitedRealValue, activeInputIndex);
743
+ updateRangeValues(limitedRealValue, activeInputIndex);
744
+ };
745
+ const onMoveStop = (e) => {
746
+ var _a, _b, _c;
747
+ setIsMoving(false);
748
+ setIsHighlighted(false);
749
+ if (!((_a = e === null || e === void 0 ? void 0 : e.target) === null || _a === void 0 ? void 0 : _a.value) &&
750
+ rangeValue.min.inputRef.current &&
751
+ rangeValue.max.inputRef.current) {
752
+ const firstValue = activeInputIndex === 0
753
+ ? mapInputRangeToValue(Number((_b = rangeValue.min.inputRef.current) === null || _b === void 0 ? void 0 : _b.value))
754
+ : rangeValue.min.value;
755
+ const secondValue = activeInputIndex === 1
756
+ ? mapInputRangeToValue(Number((_c = rangeValue.max.inputRef.current) === null || _c === void 0 ? void 0 : _c.value))
757
+ : rangeValue.max.value;
758
+ const { min: lastMin, max: lastMax } = getMinMax(firstValue, secondValue);
759
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect({
760
+ ...rangeValue,
761
+ min: { ...rangeValue.min, value: lastMin },
762
+ max: { ...rangeValue.max, value: lastMax },
763
+ }, name);
764
+ updateRangeValues(activeInputIndex === 0 ? lastMin : lastMax, activeInputIndex);
765
+ return;
766
+ }
767
+ const targetValueReal = mapInputRangeToValue(Number(e.target.value));
768
+ const { min: currentMin, max: currentMax } = getMinMax(e.target.name === "0"
769
+ ? targetValueReal
770
+ : rangeValue.min.value, e.target.name === "0"
771
+ ? rangeValue.max.value
772
+ : targetValueReal);
773
+ onSelect === null || onSelect === void 0 ? void 0 : onSelect({
774
+ ...rangeValue,
775
+ min: { ...rangeValue.min, value: currentMin },
776
+ max: { ...rangeValue.max, value: currentMax },
777
+ }, name);
778
+ };
779
+ const onMoveEnd = (e) => {
780
+ onMoveStop(e);
781
+ e.stopPropagation();
782
+ };
783
+ react.useEffect(() => {
784
+ if (!isMoving)
785
+ return;
786
+ const handleTouchEnd = () => {
787
+ setIsMoving(false);
788
+ setIsHighlighted(false);
789
+ };
790
+ document.addEventListener("touchend", handleTouchEnd);
791
+ return () => document.removeEventListener("touchend", handleTouchEnd);
792
+ }, [isMoving]);
793
+ react.useEffect(() => {
794
+ if (!isMoving)
795
+ return;
796
+ const handleMouseUp = () => {
797
+ setIsMoving(false);
798
+ setIsHighlighted(false);
799
+ };
800
+ document.addEventListener("mouseup", handleMouseUp);
801
+ return () => document.removeEventListener("mouseup", handleMouseUp);
802
+ }, [isMoving]);
803
+ const calculateSelectedRangeStyle = () => {
804
+ if (!rangeTrackRef.current)
805
+ return;
806
+ const innerWidth = rangeTrackRef.current.clientWidth;
807
+ const { min: valueMinReal, max: valueMaxReal } = getMinMax(rangeValue.min.value, rangeValue.max.value);
808
+ const valueMin = mapValueToInputRange(valueMinReal);
809
+ const valueMax = mapValueToInputRange(valueMaxReal);
810
+ const ratioMin = clamp01((valueMin - min) / (maxForInput - min));
811
+ const ratioMax = clamp01((valueMax - min) / (maxForInput - min));
812
+ const leftPx = innerWidth * ratioMin;
813
+ const rightPx = innerWidth * ratioMax;
814
+ setSelectedRangeStyle({
815
+ left: `${leftPx}px`,
816
+ width: `${Math.max(0, rightPx - leftPx)}px`,
817
+ });
818
+ };
819
+ react.useEffect(() => {
820
+ calculateSelectedRangeStyle();
821
+ // eslint-disable-next-line react-hooks/exhaustive-deps
822
+ }, [
823
+ rangeValue.min.value,
824
+ rangeValue.max.value,
825
+ min,
826
+ max,
827
+ stepValue,
828
+ maxForInput,
829
+ ]);
830
+ react.useEffect(() => {
831
+ setRangeValuePosition(activeInputIndex === 0 ? rangeValue.min.value : rangeValue.max.value);
832
+ // eslint-disable-next-line react-hooks/exhaustive-deps
833
+ }, []);
834
+ react.useLayoutEffect(() => {
835
+ const track = rangeTrackRef.current;
836
+ if (!track)
837
+ return;
838
+ let rafId = null;
839
+ const updateValue = () => {
840
+ calculateSelectedRangeStyle();
841
+ const updatedValue = typeof indicatorValue === "number"
842
+ ? indicatorValue
843
+ : activeInputIndex === 0
844
+ ? rangeValue.min.value
845
+ : rangeValue.max.value;
846
+ setRangeValuePosition(updatedValue);
847
+ };
848
+ const updateSchedule = () => {
849
+ if (rafId !== null)
850
+ return;
851
+ rafId = requestAnimationFrame(() => {
852
+ rafId = null;
853
+ updateValue();
854
+ });
855
+ };
856
+ updateSchedule();
857
+ const observer = new ResizeObserver(updateSchedule);
858
+ observer.observe(track);
859
+ window.addEventListener("resize", updateSchedule);
860
+ return () => {
861
+ observer.disconnect();
862
+ window.removeEventListener("resize", updateSchedule);
863
+ if (rafId !== null)
864
+ cancelAnimationFrame(rafId);
865
+ };
866
+ }, [
867
+ min,
868
+ max,
869
+ stepValue,
870
+ maxForInput,
871
+ indicatorValue,
872
+ activeInputIndex,
873
+ rangeValue.min.value,
874
+ rangeValue.max.value,
875
+ ]);
876
+ const lowValue = Math.min(rangeValue.min.value, rangeValue.max.value);
877
+ const indicatorIsMin = typeof indicatorValue === "number" ? indicatorValue === lowValue : false;
878
+ const indicatorIcon = (icons === null || icons === void 0 ? void 0 : icons.indicatorMin) && (icons === null || icons === void 0 ? void 0 : icons.indicatorMax)
879
+ ? indicatorIsMin
880
+ ? icons.indicatorMin
881
+ : icons.indicatorMax
882
+ : undefined;
883
+ const indicatorIconKey = indicatorIsMin ? "min" : "max";
884
+ return (jsxRuntime.jsxs("div", { className: containerClasses, children: [label && (jsxRuntime.jsx(ZRangeLabel, { label: label, labelClassName: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.label })), jsxRuntime.jsxs("div", { ref: containerRef, className: styles["zr"], children: [jsxRuntime.jsx(ZRangeInputs, { rangeValue: rangeValueForInput, min: min, max: maxForInput, step: stepValue, inputMinClasses: inputMinClasses, inputMaxClasses: inputMaxClasses, onInputChange: onInputChange, onMouseDown: onMoveStart, onTouchStart: onMoveStart, onMouseMove: onMove, onTouchMove: onMove, onMouseUp: onMoveEnd, onTouchEnd: onMoveEnd }), jsxRuntime.jsx(ZRangeTrack, { rangeTrackRef: rangeTrackRef, selectedRangeRef: selectedRangeRef, selectedRangeStyle: selectedRangeStyle, trackStyles: {
885
+ trackContainer: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.trackContainer,
886
+ trackRange: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.trackRange,
887
+ trackSelected: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.trackSelected,
888
+ } }), jsxRuntime.jsx(ZRangeIndicator, { valueIndicatorRef: valueIndicatorRef, indicatorStyles: {
889
+ indicator: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicator,
890
+ indicatorMin: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicatorMin,
891
+ indicatorMax: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicatorMax,
892
+ indicatorValue: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicatorValue,
893
+ indicatorIcon: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.indicatorIcon,
894
+ }, indicatorValue: indicatorValue, rangeTrackRef: rangeTrackRef, inputElement: activeInputIndex === 0
895
+ ? rangeValue.min.inputRef.current
896
+ : (_a = rangeValue.max.inputRef.current) !== null && _a !== void 0 ? _a : rangeValue.min.inputRef.current, scaleFunction: scaleFunction, unitList: unitList, unitDivisors: unitDivisors, scale: scale, icon: indicatorIcon, iconKey: indicatorIconKey, isHighlighted: isHighlighted, isIndicatorUnitHidden: isIndicatorUnitHidden })] }), jsxRuntime.jsxs("div", { className: styles["zr__slider-values-wrapper"], children: [jsxRuntime.jsx(ZRangeSliderValue, { sliderValueClassName: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.sliderValue, value: rangeValue.getValueLabel("min"), icon: icons === null || icons === void 0 ? void 0 : icons.thumbMin }), jsxRuntime.jsx(ZRangeSliderValue, { sliderValueClassName: stylesClasses === null || stylesClasses === void 0 ? void 0 : stylesClasses.sliderValue, value: rangeValue.getValueLabel("max"), icon: icons === null || icons === void 0 ? void 0 : icons.thumbMax })] })] }));
897
+ };
898
+
899
+ const isRangeRangeValue = (value) => value &&
900
+ typeof value === "object" &&
901
+ typeof value.min === "number" &&
902
+ typeof value.max === "number";
903
+ const toFormRangeValue = (componentValue, fallback) => {
904
+ var _a, _b;
905
+ const v = componentValue;
906
+ return {
907
+ min: typeof ((_a = v === null || v === void 0 ? void 0 : v.min) === null || _a === void 0 ? void 0 : _a.value) === "number" ? v.min.value : fallback.min,
908
+ max: typeof ((_b = v === null || v === void 0 ? void 0 : v.max) === null || _b === void 0 ? void 0 : _b.value) === "number" ? v.max.value : fallback.max,
909
+ };
910
+ };
911
+ const getErrorMessage = (error) => {
912
+ if (!error || typeof error !== "object")
913
+ return undefined;
914
+ const maybe = error;
915
+ return typeof maybe.message === "string" ? maybe.message : undefined;
916
+ };
917
+ const ZRangeField = (props) => {
918
+ const { control, name, rules, defaultValue, shouldUnregister, onValueChange, onValueSelect, hideError, errorClassName, errorRenderer, min, max, commitMode = "select", ...rest } = props;
919
+ const errorMessageClasses = index.classNames(styles["zr__error-message"], errorClassName);
920
+ const fallback = defaultValue !== null && defaultValue !== void 0 ? defaultValue : { min, max };
921
+ const { field, fieldState } = reactHookForm.useController({
922
+ name,
923
+ control,
924
+ rules,
925
+ shouldUnregister,
926
+ defaultValue: (defaultValue !== null && defaultValue !== void 0 ? defaultValue : fallback),
927
+ });
928
+ // UWAGA: value do ZRange pochodzi TYLKO z RHF (albo fallback),
929
+ // a RHF aktualizujemy na końcu (onSelect) — więc podczas dragowania value jest stabilne.
930
+ const formValue = isRangeRangeValue(field.value)
931
+ ? field.value
932
+ : fallback;
933
+ const errorMessage = getErrorMessage(fieldState.error);
934
+ const handleRangeChange = (componentValue, fieldName) => {
935
+ const nextFormValue = toFormRangeValue(componentValue, fallback);
936
+ // Live update tylko jeśli ktoś tego chce
937
+ if (commitMode === "change") {
938
+ field.onChange(nextFormValue);
939
+ }
940
+ onValueChange === null || onValueChange === void 0 ? void 0 : onValueChange(nextFormValue, fieldName);
941
+ };
942
+ const handleRangeSelect = (componentValue, fieldName) => {
943
+ const nextFormValue = toFormRangeValue(componentValue, fallback);
944
+ // Commit dopiero na końcu => brak resetów w trakcie dragowania
945
+ field.onChange(nextFormValue);
946
+ field.onBlur();
947
+ onValueSelect === null || onValueSelect === void 0 ? void 0 : onValueSelect(nextFormValue, fieldName);
948
+ };
949
+ return (jsxRuntime.jsxs("div", { children: [jsxRuntime.jsx(ZRange, { name: name, min: min, max: max, value: formValue, onChange: handleRangeChange, onSelect: handleRangeSelect, ...rest }), !hideError && errorMessage ? (errorRenderer ? (jsxRuntime.jsx(jsxRuntime.Fragment, { children: errorRenderer(errorMessage) })) : (jsxRuntime.jsx("div", { className: errorMessageClasses, children: errorMessage }))) : null] }));
950
+ };
951
+
321
952
  exports.ZDrop = index.ZDrop;
322
953
  exports.ZDropField = index.ZDropField;
323
954
  exports.ZDropButton = ZDropButton;
955
+ exports.ZRange = ZRange;
956
+ exports.ZRangeField = ZRangeField;
324
957
  //# sourceMappingURL=index.cjs.js.map