@rolster/react-components 19.7.12 → 19.8.15

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 (45) hide show
  1. package/dist/cjs/index.cjs +791 -542
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/es/index.mjs +788 -545
  4. package/dist/es/index.mjs.map +1 -1
  5. package/dist/esm/components/atoms/Label/Label.js.map +1 -1
  6. package/dist/esm/components/molecules/Content/Content.js.map +1 -1
  7. package/dist/esm/components/molecules/FieldListSuggestions/FieldListSuggestions.d.ts +4 -1
  8. package/dist/esm/components/molecules/FieldListSuggestions/FieldListSuggestions.js +7 -2
  9. package/dist/esm/components/molecules/FieldListSuggestions/FieldListSuggestions.js.map +1 -1
  10. package/dist/esm/components/molecules/FieldListSuggestions/SuggestionsPortalController.d.ts +8 -0
  11. package/dist/esm/components/molecules/FieldListSuggestions/SuggestionsPortalController.js +84 -0
  12. package/dist/esm/components/molecules/FieldListSuggestions/SuggestionsPortalController.js.map +1 -0
  13. package/dist/esm/components/organisms/ChooserAutocomplete/ChooserAutocomplete.d.ts +36 -0
  14. package/dist/esm/components/organisms/ChooserAutocomplete/ChooserAutocomplete.js +87 -0
  15. package/dist/esm/components/organisms/ChooserAutocomplete/ChooserAutocomplete.js.map +1 -0
  16. package/dist/esm/components/organisms/ChooserList/ChooserList.d.ts +27 -0
  17. package/dist/esm/components/organisms/ChooserList/ChooserList.js +44 -0
  18. package/dist/esm/components/organisms/ChooserList/ChooserList.js.map +1 -0
  19. package/dist/esm/components/organisms/ChooserSelect/ChooserSelect.d.ts +31 -0
  20. package/dist/esm/components/organisms/ChooserSelect/ChooserSelect.js +38 -0
  21. package/dist/esm/components/organisms/ChooserSelect/ChooserSelect.js.map +1 -0
  22. package/dist/esm/components/organisms/FieldAutocomplete/FieldAutocomplete.js +1 -1
  23. package/dist/esm/components/organisms/FieldAutocomplete/FieldAutocomplete.js.map +1 -1
  24. package/dist/esm/components/organisms/FieldList/FieldList.js +1 -1
  25. package/dist/esm/components/organisms/FieldList/FieldList.js.map +1 -1
  26. package/dist/esm/components/organisms/FieldList/FieldListController.d.ts +1 -0
  27. package/dist/esm/components/organisms/FieldList/FieldListController.js +4 -1
  28. package/dist/esm/components/organisms/FieldList/FieldListController.js.map +1 -1
  29. package/dist/esm/components/organisms/FieldSelect/FieldSelect.js +1 -1
  30. package/dist/esm/components/organisms/FieldSelect/FieldSelect.js.map +1 -1
  31. package/dist/esm/components/organisms/ImageEditor/ImageEditor.js.map +1 -1
  32. package/dist/esm/controllers/DropdownController.js.map +1 -1
  33. package/dist/esm/controllers/ListController.d.ts +1 -0
  34. package/dist/esm/controllers/ListController.js +31 -25
  35. package/dist/esm/controllers/ListController.js.map +1 -1
  36. package/dist/esm/controllers/RelocationOnComponentController.d.ts +4 -4
  37. package/dist/esm/controllers/RelocationOnComponentController.js +34 -32
  38. package/dist/esm/controllers/RelocationOnComponentController.js.map +1 -1
  39. package/dist/esm/controllers/ResizeController.js +5 -7
  40. package/dist/esm/controllers/ResizeController.js.map +1 -1
  41. package/dist/esm/definitions.d.ts +1 -0
  42. package/dist/esm/index.d.ts +3 -0
  43. package/dist/esm/index.js +3 -0
  44. package/dist/esm/index.js.map +1 -1
  45. package/package.json +2 -2
package/dist/es/index.mjs CHANGED
@@ -1,9 +1,9 @@
1
1
  import require$$0, { memo, useMemo, useState, useRef, useCallback, useEffect, useEffectEvent, createContext, useContext } from 'react';
2
2
  import { currencyFormat, BigDecimal, valueIsDefined, SealedPartial } from '@rolster/commons';
3
3
  import { i18n, i18nSubscribe } from '@rolster/i18n';
4
+ import ReactDOM, { createPortal } from 'react-dom';
4
5
  import { PaginationController, verifyDayPicker, createDayPicker, createDayRangePicker, verifyMonthPicker, createMonthPicker, monthLimitTemplate, createYearPicker, verifyYearPicker, ListCollection, navigationListFromInput, navigationListFromElement, createAutocompleteStore, PickerListenerEvent, dateOutRange, verifyDateRange } from '@rolster/components';
5
6
  import { DAY_LABELS, DateRange, normalizeMinTime, assignDayInDate, dateIsBefore, MONTH_NAMES, Month, Time, dateFormatTemplate, assignYearInDate, assignMonthInDate } from '@rolster/dates';
6
- import ReactDOM from 'react-dom';
7
7
  import { useReactControl, useFormControl } from '@rolster/react-forms';
8
8
 
9
9
  var jsxRuntime = {exports: {}};
@@ -1631,6 +1631,89 @@ const reactI18n = i18n({
1631
1631
  }
1632
1632
  });
1633
1633
 
1634
+ function getScrollableAncestors(element) {
1635
+ const ancestors = [];
1636
+ let parent = element.parentElement;
1637
+ while (parent && parent !== document.body) {
1638
+ const { overflow, overflowX, overflowY } = getComputedStyle(parent);
1639
+ if (/auto|scroll|hidden/.test(`${overflow}${overflowX}${overflowY}`)) {
1640
+ ancestors.push(parent);
1641
+ }
1642
+ parent = parent.parentElement;
1643
+ }
1644
+ return ancestors;
1645
+ }
1646
+ function anchorIsVisible(rect, scrollables) {
1647
+ if (!rect.width || !rect.height) {
1648
+ return false;
1649
+ }
1650
+ let top = 0;
1651
+ let left = 0;
1652
+ let bottom = window.innerHeight;
1653
+ let right = window.innerWidth;
1654
+ for (const scrollable of scrollables) {
1655
+ const scrollableRect = scrollable.getBoundingClientRect();
1656
+ top = Math.max(top, scrollableRect.top);
1657
+ left = Math.max(left, scrollableRect.left);
1658
+ bottom = Math.min(bottom, scrollableRect.bottom);
1659
+ right = Math.min(right, scrollableRect.right);
1660
+ }
1661
+ return (rect.bottom > top &&
1662
+ rect.top < bottom &&
1663
+ rect.right > left &&
1664
+ rect.left < right);
1665
+ }
1666
+ function useSuggestionsPortalController(visible, refAnchor, onHiddenAnchor) {
1667
+ const [mounted, setMounted] = useState(false);
1668
+ const [style, setStyle] = useState();
1669
+ const [theme, setTheme] = useState();
1670
+ useEffect(() => {
1671
+ setMounted(true);
1672
+ }, []);
1673
+ const onAnchorHidden = useEffectEvent(() => {
1674
+ onHiddenAnchor?.();
1675
+ });
1676
+ useEffect(() => {
1677
+ const anchor = refAnchor?.current;
1678
+ if (!mounted || !visible || !anchor) {
1679
+ return;
1680
+ }
1681
+ setTheme((anchor.closest('[rls-theme]')?.getAttribute('rls-theme') ??
1682
+ undefined));
1683
+ const scrollables = getScrollableAncestors(anchor);
1684
+ let frame = 0;
1685
+ function reposition() {
1686
+ if (!anchor) {
1687
+ return;
1688
+ }
1689
+ const rect = anchor.getBoundingClientRect();
1690
+ if (!anchorIsVisible(rect, scrollables)) {
1691
+ onAnchorHidden();
1692
+ return;
1693
+ }
1694
+ setStyle({
1695
+ '--pvt-portal-top': `${rect.bottom}px`,
1696
+ '--pvt-portal-bottom': `${window.innerHeight - rect.top}px`,
1697
+ '--pvt-portal-left': `${rect.left}px`,
1698
+ '--pvt-portal-width': `${rect.width}px`
1699
+ });
1700
+ }
1701
+ function requestReposition() {
1702
+ cancelAnimationFrame(frame);
1703
+ frame = requestAnimationFrame(reposition);
1704
+ }
1705
+ reposition();
1706
+ window.addEventListener('scroll', requestReposition, true);
1707
+ window.addEventListener('resize', requestReposition);
1708
+ return () => {
1709
+ cancelAnimationFrame(frame);
1710
+ window.removeEventListener('scroll', requestReposition, true);
1711
+ window.removeEventListener('resize', requestReposition);
1712
+ };
1713
+ }, [mounted, visible, refAnchor]);
1714
+ return { active: mounted && !!refAnchor, style, theme };
1715
+ }
1716
+
1634
1717
  function RlsFieldListLi({ element, onClickElement, onKeydownElement, render }) {
1635
1718
  const onClick = useMemo(() => {
1636
1719
  return onClickElement(element);
@@ -1640,7 +1723,8 @@ function RlsFieldListLi({ element, onClickElement, onKeydownElement, render }) {
1640
1723
  }, [element, onKeydownElement]);
1641
1724
  return (jsxRuntimeExports.jsx("li", { className: "rls-field-list__element", tabIndex: -1, onClick: onClick, onKeyDown: onKeyDown, children: render(element) }));
1642
1725
  }
1643
- function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher, render, renderEmpty, searchControl, visible, onClickBackdrop, onClickElement, onKeydownElement, refList, rlsTheme }) {
1726
+ function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher, render, renderEmpty, searchControl, visible, onClickBackdrop, onClickElement, onHiddenAnchor, onKeydownElement, refAnchor, refList, refSuggestions, rlsTheme }) {
1727
+ const portal = useSuggestionsPortalController(visible, refAnchor, onHiddenAnchor);
1644
1728
  const [labels, setLabels] = useState({
1645
1729
  listEmptyDescription: reactI18n('listEmptyDescription'),
1646
1730
  listEmptyTitle: reactI18n('listEmptyTitle')
@@ -1656,6 +1740,7 @@ function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher,
1656
1740
  const className = renderClassStatus('rls-field-list__suggestions', {
1657
1741
  disabled,
1658
1742
  higher,
1743
+ portal: portal.active,
1659
1744
  visible
1660
1745
  });
1661
1746
  const onChangePattern = useCallback((event) => {
@@ -1668,7 +1753,8 @@ function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher,
1668
1753
  }
1669
1754
  }, [action?.onClick, action?.keepOpen, onClickBackdrop]);
1670
1755
  const searching = searchControl?.searching ?? false;
1671
- return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-field-list__suggestions__body", children: [jsxRuntimeExports.jsxs("ul", { ref: refList, className: "rls-field-list__ul", children: [searchControl && (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__ul__search", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__ul__control", ref: searchControl.refInput, type: "text", placeholder: searchControl.placeholder, value: searchControl.pattern, onChange: onChangePattern, onFocus: searchControl.onFocus, onBlur: searchControl.onBlur, onKeyDown: searchControl.onKeyDown, disabled: disabled || searching }), searchControl.onSearch && (jsxRuntimeExports.jsx("button", { disabled: disabled || searching, onClick: searchControl.onSearch, children: jsxRuntimeExports.jsx(RlsIcon, { value: "search" }) }))] })), searching && jsxRuntimeExports.jsx(RlsProgressBar, { indeterminate: true }), elements.map((element, index) => (jsxRuntimeExports.jsx(RlsFieldListLi, { element: element, onClickElement: onClickElement, onKeydownElement: onKeydownElement, render: render }, index))), !elements.length && (jsxRuntimeExports.jsx("li", { className: "rls-field-list__empty", children: renderEmpty ? (renderEmpty()) : (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__empty__description", children: [jsxRuntimeExports.jsx("span", { className: "rls-label-font-bold rls-truncate", children: labels.listEmptyTitle }), jsxRuntimeExports.jsx("p", { className: "rls-caption-font-regular", children: labels.listEmptyDescription })] })) }))] }), action && (jsxRuntimeExports.jsx("div", { className: "rls-field-list__action", children: jsxRuntimeExports.jsxs("button", { type: "button", disabled: disabled || action.disabled, onClick: onClickAction, children: [action.icon && jsxRuntimeExports.jsx(RlsIcon, { value: action.icon }), jsxRuntimeExports.jsx("span", { className: "rls-field-list__action__description", children: action.description })] }) }))] }), jsxRuntimeExports.jsx("div", { className: "rls-field-list__backdrop", onClick: onClickBackdrop })] }));
1756
+ const suggestions = (jsxRuntimeExports.jsxs("div", { ref: refSuggestions, className: className, style: portal.active ? portal.style : undefined, "rls-theme": rlsTheme ?? portal.theme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-field-list__suggestions__body", children: [jsxRuntimeExports.jsxs("ul", { ref: refList, className: "rls-field-list__ul", children: [searchControl && (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__ul__search", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__ul__control", ref: searchControl.refInput, type: "text", placeholder: searchControl.placeholder, value: searchControl.pattern, onChange: onChangePattern, onFocus: searchControl.onFocus, onBlur: searchControl.onBlur, onKeyDown: searchControl.onKeyDown, disabled: disabled || searching }), searchControl.onSearch && (jsxRuntimeExports.jsx("button", { disabled: disabled || searching, onClick: searchControl.onSearch, children: jsxRuntimeExports.jsx(RlsIcon, { value: "search" }) }))] })), searching && jsxRuntimeExports.jsx(RlsProgressBar, { indeterminate: true }), elements.map((element, index) => (jsxRuntimeExports.jsx(RlsFieldListLi, { element: element, onClickElement: onClickElement, onKeydownElement: onKeydownElement, render: render }, index))), !elements.length && (jsxRuntimeExports.jsx("li", { className: "rls-field-list__empty", children: renderEmpty ? (renderEmpty()) : (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__empty__description", children: [jsxRuntimeExports.jsx("span", { className: "rls-label-font-bold rls-truncate", children: labels.listEmptyTitle }), jsxRuntimeExports.jsx("p", { className: "rls-caption-font-regular", children: labels.listEmptyDescription })] })) }))] }), action && (jsxRuntimeExports.jsx("div", { className: "rls-field-list__action", children: jsxRuntimeExports.jsxs("button", { type: "button", disabled: disabled || action.disabled, onClick: onClickAction, children: [action.icon && jsxRuntimeExports.jsx(RlsIcon, { value: action.icon }), jsxRuntimeExports.jsx("span", { className: "rls-field-list__action__description", children: action.description })] }) }))] }), jsxRuntimeExports.jsx("div", { className: "rls-field-list__backdrop", onClick: onClickBackdrop })] }));
1757
+ return portal.active ? createPortal(suggestions, document.body) : suggestions;
1672
1758
  }
1673
1759
  const RlsFieldListSuggestions = memo(RlsFieldListSuggestionsComponent);
1674
1760
 
@@ -2370,161 +2456,6 @@ function RlsCardComponent({ children, className, outline, rlsTheme }) {
2370
2456
  }
2371
2457
  const RlsCard = memo(RlsCardComponent);
2372
2458
 
2373
- class ConfirmationResult extends SealedPartial {
2374
- static approved() {
2375
- return new ConfirmationResult('approved');
2376
- }
2377
- static reject() {
2378
- return new ConfirmationResult('reject');
2379
- }
2380
- }
2381
- function RlsConfirmationComponent({ approved, className, content, reject, rlsTheme, subtitle, title, visible }) {
2382
- const classConfirmation = renderClassStatus('rls-confirmation', { visible }, className);
2383
- return (jsxRuntimeExports.jsxs("div", { className: classConfirmation, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__component", children: [jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__header", children: [title && jsxRuntimeExports.jsx("div", { className: "rls-confirmation__title", children: title }), subtitle && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__subtitle", children: subtitle }))] }), jsxRuntimeExports.jsx("div", { className: "rls-confirmation__body", children: content && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__content", children: content })) }), (approved || reject) && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__footer", children: jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__actions", children: [approved && (jsxRuntimeExports.jsx(RlsButton, { identifier: approved.identifier, type: approved.type, onClick: approved.onClick, disabled: approved.disabled, rlsTheme: approved.rlsTheme, children: approved.label })), reject && (jsxRuntimeExports.jsx(RlsButton, { identifier: reject.identifier, type: reject.type, onClick: reject.onClick, disabled: reject.disabled, rlsTheme: reject.rlsTheme, children: reject.label }))] }) }))] }), jsxRuntimeExports.jsx("div", { className: "rls-confirmation__backdrop" })] }));
2384
- }
2385
- const RlsConfirmation = memo(RlsConfirmationComponent);
2386
- const RlsConfirmationBase = RlsConfirmation;
2387
- function useConfirmation() {
2388
- const [config, setConfig] = useState({});
2389
- const [visible, setVisible] = useState(false);
2390
- const configRef = useRef(config);
2391
- configRef.current = config;
2392
- const visibleRef = useRef(visible);
2393
- visibleRef.current = visible;
2394
- const RlsConfirmation = useMemo(() => {
2395
- return function RlsConfirmation(props) {
2396
- return ReactDOM.createPortal(jsxRuntimeExports.jsx(RlsConfirmationBase, { ...props, ...configRef.current, visible: visibleRef.current }), document.body);
2397
- };
2398
- }, []);
2399
- const confirmation = useCallback((options) => {
2400
- return new Promise((resolve) => {
2401
- setConfig({
2402
- ...options,
2403
- approved: {
2404
- label: options.approved?.label ?? reactI18n('confirmationActionApproved'),
2405
- onClick: () => {
2406
- setVisible(false);
2407
- resolve(ConfirmationResult.approved());
2408
- },
2409
- type: options.approved?.type ?? 'raised',
2410
- disabled: options.approved?.disabled,
2411
- identifier: options.approved?.identifier,
2412
- rlsTheme: options.approved?.rlsTheme
2413
- },
2414
- reject: options.reject
2415
- ? {
2416
- label: options.reject.label,
2417
- onClick: () => {
2418
- setVisible(false);
2419
- resolve(ConfirmationResult.reject());
2420
- },
2421
- type: options.reject.type ?? 'flat',
2422
- disabled: options.reject.disabled,
2423
- identifier: options.reject.identifier,
2424
- rlsTheme: options.reject.rlsTheme
2425
- }
2426
- : undefined
2427
- });
2428
- setVisible(true);
2429
- });
2430
- }, []);
2431
- return {
2432
- confirmation,
2433
- RlsConfirmation
2434
- };
2435
- }
2436
-
2437
- function createObserver(options) {
2438
- const { setScrolleable, table } = options;
2439
- const observer = new ResizeObserver(() => {
2440
- const scrollHeight = table.scrollHeight || 0;
2441
- const clientHeight = table.clientHeight || 0;
2442
- setScrolleable(scrollHeight > clientHeight);
2443
- });
2444
- observer.observe(table);
2445
- return observer;
2446
- }
2447
- function useDatatable(table) {
2448
- const [scrolleable, setScrolleable] = useState(false);
2449
- const refTable = useRef(table ? table : null);
2450
- useEffect(() => {
2451
- const observer = refTable.current &&
2452
- createObserver({ setScrolleable, table: refTable.current });
2453
- return () => {
2454
- observer?.disconnect();
2455
- };
2456
- }, []);
2457
- return { refTable, scrolleable };
2458
- }
2459
-
2460
- function RlsDatatableComponent({ children, footer, header, identifier, rlsTheme, resizable, summary, table, toolbar }) {
2461
- const datatable = useDatatable(table);
2462
- const className = renderClassStatus('rls-datatable', {
2463
- resizable,
2464
- scrolleable: resizable && datatable?.scrolleable
2465
- });
2466
- return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [toolbar && jsxRuntimeExports.jsx("div", { className: "rls-datatable__toolbar", children: toolbar }), jsxRuntimeExports.jsx("div", { className: "rls-datatable__table", children: jsxRuntimeExports.jsxs("table", { id: identifier, children: [header && jsxRuntimeExports.jsx("thead", { className: "rls-datatable__head", children: header }), jsxRuntimeExports.jsx("tbody", { ref: datatable?.refTable, className: "rls-datatable__body", children: children })] }) }), summary && jsxRuntimeExports.jsx("div", { className: "rls-datatable__summary", children: summary }), footer && jsxRuntimeExports.jsx("div", { className: "rls-datatable__footer", children: footer })] }));
2467
- }
2468
- const RlsDatatable = memo(RlsDatatableComponent);
2469
- function RlsDatatableHeaderComponent({ children, identifier, rlsTheme }) {
2470
- return (jsxRuntimeExports.jsx("tr", { id: identifier, className: "rls-datatable__header", "rls-theme": rlsTheme, children: children }));
2471
- }
2472
- const RlsDatatableHeader = memo(RlsDatatableHeaderComponent);
2473
- function RlsDatatableTitleComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
2474
- const classNameTitle = renderClassStatus('rls-datatable__title', { actions, control, truncated }, className);
2475
- return (jsxRuntimeExports.jsx("th", { id: identifier, className: classNameTitle, "rls-theme": rlsTheme, children: children }));
2476
- }
2477
- const RlsDatatableTitle = memo(RlsDatatableTitleComponent);
2478
- function RlsDatatableSubheaderComponent({ children, className, identifier, rlsTheme }) {
2479
- const classNameSubheader = renderClassStatus('rls-datatable__subheader', {}, className);
2480
- return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameSubheader, "rls-theme": rlsTheme, children: children }));
2481
- }
2482
- const RlsDatatableSubheader = memo(RlsDatatableSubheaderComponent);
2483
- function RlsDatatableRecordComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
2484
- const classNameRecord = renderClassStatus('rls-datatable__record', { error, info, truncated, success, warning }, className);
2485
- return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameRecord, "rls-theme": rlsTheme, children: children }));
2486
- }
2487
- const RlsDatatableRecord = memo(RlsDatatableRecordComponent);
2488
- function RlsDatatableTotalsComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
2489
- const classNameTotals = renderClassStatus('rls-datatable__totals', { error, info, truncated, success, warning }, className);
2490
- return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameTotals, "rls-theme": rlsTheme, children: children }));
2491
- }
2492
- const RlsDatatableTotals = memo(RlsDatatableTotalsComponent);
2493
- function RlsDatatableCellComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
2494
- const classNameCell = renderClassStatus('rls-datatable__cell', { actions, control, truncated }, className);
2495
- return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameCell, "rls-theme": rlsTheme, children: children }));
2496
- }
2497
- const RlsDatatableCell = memo(RlsDatatableCellComponent);
2498
- function RlsDatatableDataComponent({ actions, children, className, control, identifier, truncated }) {
2499
- const classNameData = renderClassStatus('rls-datatable__data', { actions, control, truncated }, className);
2500
- return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameData, children: children }));
2501
- }
2502
- const RlsDatatableData = memo(RlsDatatableDataComponent);
2503
- function RlsDatatableFloatingComponent({ children, className, identifier, invested, rlsTheme }) {
2504
- const classNameFloating = renderClassStatus('rls-datatable__floating', { invested }, className);
2505
- return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameFloating, "rls-theme": rlsTheme, children: children }));
2506
- }
2507
- const RlsDatatableFloating = memo(RlsDatatableFloatingComponent);
2508
-
2509
- function RlsDropdownComponent({ children, controller, rlsTheme }) {
2510
- const className = renderClassStatus('rls-dropdown', {
2511
- visible: controller.visible
2512
- });
2513
- useEffect(() => {
2514
- function onCloseDropdown({ target }) {
2515
- if (!controller.component.current.contains(target)) {
2516
- controller.close();
2517
- }
2518
- }
2519
- document.addEventListener('click', onCloseDropdown);
2520
- return () => {
2521
- document.removeEventListener('click', onCloseDropdown);
2522
- };
2523
- }, []);
2524
- return (jsxRuntimeExports.jsx("div", { ref: controller.component, className: className, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-dropdown__content", children: children }) }));
2525
- }
2526
- const RlsDropdown = memo(RlsDropdownComponent);
2527
-
2528
2459
  const MAX_LIST_HEIGHT_REM$1 = 90;
2529
2460
  const FALLBACK_REM_SIZE$1 = 16;
2530
2461
  function getRemSize$1() {
@@ -2566,6 +2497,7 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2566
2497
  const refContent = useRef(null);
2567
2498
  const refList = useRef(null);
2568
2499
  const refInput = useRef(null);
2500
+ const refSuggestions = useRef(null);
2569
2501
  const listIsOpen = useRef(false);
2570
2502
  const stableSuggestions = useStableSuggestions(suggestions);
2571
2503
  const collection = useMemo(() => new ListCollection(stableSuggestions, reference), [stableSuggestions, reference]);
@@ -2580,7 +2512,8 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2580
2512
  const valueProtected = useRef(undefined);
2581
2513
  useEffect(() => {
2582
2514
  function onCloseSuggestions({ target }) {
2583
- if (!refContent?.current?.contains(target)) {
2515
+ if (!refContent?.current?.contains(target) &&
2516
+ !refSuggestions?.current?.contains(target)) {
2584
2517
  refreshState((state) => ({ ...state, listIsVisible: false }));
2585
2518
  }
2586
2519
  }
@@ -2597,7 +2530,29 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2597
2530
  formControl?.touch();
2598
2531
  }
2599
2532
  }, [state.listIsVisible]);
2600
- useEffect(() => {
2533
+ const setState = useCallback((state) => {
2534
+ const newState = state.listIsVisible
2535
+ ? {
2536
+ ...state,
2537
+ higher: shouldDisplayHigher$1(refContent.current, refList.current)
2538
+ }
2539
+ : state;
2540
+ refreshState((currentState) => ({ ...currentState, ...newState }));
2541
+ }, []);
2542
+ const setFormValue = useCallback((element, valueIsDefault = false) => {
2543
+ refreshState((state) => ({
2544
+ ...state,
2545
+ value: element?.description || ''
2546
+ }));
2547
+ changeValueInternal.current = true;
2548
+ if (valueIsDefault) {
2549
+ formControl?.setDefaultValue(element?.value);
2550
+ }
2551
+ else {
2552
+ formControl?.setValue(element?.value);
2553
+ }
2554
+ }, [formControl]);
2555
+ const reconcileFormValue = useEffectEvent(() => {
2601
2556
  if (!changeValueInternal.current) {
2602
2557
  if (formControl?.value) {
2603
2558
  const element = collection.find(formControl.value);
@@ -2633,29 +2588,10 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2633
2588
  }
2634
2589
  }
2635
2590
  changeValueInternal.current = false;
2591
+ });
2592
+ useEffect(() => {
2593
+ reconcileFormValue();
2636
2594
  }, [collection, formControl?.value]);
2637
- const setState = useCallback((state) => {
2638
- const newState = state.listIsVisible
2639
- ? {
2640
- ...state,
2641
- higher: shouldDisplayHigher$1(refContent.current, refList.current)
2642
- }
2643
- : state;
2644
- refreshState((currentState) => ({ ...currentState, ...newState }));
2645
- }, []);
2646
- const setFormValue = useCallback((element, valueIsDefault = false) => {
2647
- refreshState((state) => ({
2648
- ...state,
2649
- value: element?.description || ''
2650
- }));
2651
- changeValueInternal.current = true;
2652
- if (valueIsDefault) {
2653
- formControl?.setDefaultValue(element?.value);
2654
- }
2655
- else {
2656
- formControl?.setValue(element?.value);
2657
- }
2658
- }, [formControl]);
2659
2595
  const navigationInput = useCallback((event) => {
2660
2596
  if (state.listIsVisible) {
2661
2597
  const newPosition = navigationListFromInput({
@@ -2684,6 +2620,7 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2684
2620
  refContent,
2685
2621
  refInput,
2686
2622
  refList,
2623
+ refSuggestions,
2687
2624
  setFormValue,
2688
2625
  setState
2689
2626
  }), [state, navigationElement, navigationInput, setFormValue, setState]);
@@ -2845,9 +2782,9 @@ function useFieldAutocomplete(props) {
2845
2782
  ]);
2846
2783
  }
2847
2784
 
2848
- function RlsFieldAutocompleteTemplateComponent(props) {
2785
+ function RlsChooserAutocompleteTemplateComponent(props) {
2849
2786
  const autocomplete = useFieldAutocomplete(props);
2850
- const { render, action, children, formControl, msgErrorDisabled, onSearch, placeholder, rlsTheme, searching } = props;
2787
+ const { render, action, children, formControl, onSearch, rlsTheme, searching } = props;
2851
2788
  const [listInputPlaceholder, setListInputPlaceholder] = useState(reactI18n('listInputPlaceholder'));
2852
2789
  useEffect(() => {
2853
2790
  return i18nSubscribe(() => {
@@ -2860,13 +2797,11 @@ function RlsFieldAutocompleteTemplateComponent(props) {
2860
2797
  const disabled = useMemo(() => {
2861
2798
  return formControl?.disabled || props.disabled;
2862
2799
  }, [formControl?.disabled, props.disabled]);
2863
- const className = renderClassStatus('rls-field-box', {
2800
+ const className = renderClassStatus('rls-chooser', {
2864
2801
  focused: autocomplete.focused && !disabled,
2865
- error: formControl?.wrong,
2866
- disabled,
2867
- readonly: props.readOnly,
2868
- selected: !!autocomplete.value
2869
- }, `rls-field-list rls-field-autocomplete ${props.className ?? ''}`);
2802
+ visible: autocomplete.listIsVisible,
2803
+ disabled
2804
+ }, `rls-chooser-autocomplete ${props.className ?? ''}`);
2870
2805
  const onClickPattern = useCallback(() => {
2871
2806
  onSearch?.(autocomplete.pattern);
2872
2807
  }, [onSearch, autocomplete.pattern]);
@@ -2876,6 +2811,18 @@ function RlsFieldAutocompleteTemplateComponent(props) {
2876
2811
  }
2877
2812
  autocomplete.onKeydownInput(event);
2878
2813
  }, [autocomplete.onKeydownInput, onSearch, autocomplete.pattern]);
2814
+ const onKeydownTrigger = useCallback((event) => {
2815
+ switch (event.code) {
2816
+ case 'Space':
2817
+ case 'Enter':
2818
+ event.preventDefault();
2819
+ autocomplete.onClickControl();
2820
+ break;
2821
+ case 'Escape':
2822
+ autocomplete.onClickBackdrop();
2823
+ break;
2824
+ }
2825
+ }, [autocomplete.onClickControl, autocomplete.onClickBackdrop]);
2879
2826
  const searchControl = useMemo(() => ({
2880
2827
  pattern: autocomplete.pattern,
2881
2828
  placeholder: listInputPlaceholder,
@@ -2898,26 +2845,584 @@ function RlsFieldAutocompleteTemplateComponent(props) {
2898
2845
  onClickPattern,
2899
2846
  onSearch
2900
2847
  ]);
2901
- return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: autocomplete.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__control", readOnly: true, disabled: disabled, placeholder: placeholder, value: autocomplete.value, onClick: autocomplete.onClickControl }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: autocomplete.value ? 'trash-2' : 'arrow-ios-down', onClick: autocomplete.onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: autocomplete.coincidences, visible: autocomplete.listIsVisible, action: action, disabled: disabled, higher: autocomplete.higher, render: render, refList: autocomplete.refList, searchControl: searchControl, onClickElement: autocomplete.onClickElement, onKeydownElement: autocomplete.onKeydownElement, onClickBackdrop: autocomplete.onClickBackdrop })] }));
2902
- }
2903
- const RlsFieldAutocompleteTemplate = memo(RlsFieldAutocompleteTemplateComponent);
2904
- function RlsFieldAutocompleteComponent(props) {
2848
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: autocomplete.refContent, className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-chooser__trigger", role: "combobox", "aria-expanded": autocomplete.listIsVisible, "aria-haspopup": "listbox", "aria-disabled": disabled || undefined, tabIndex: disabled ? -1 : 0, onClick: disabled ? undefined : autocomplete.onClickControl, onKeyDown: disabled ? undefined : onKeydownTrigger, children: typeof children === 'function'
2849
+ ? children({
2850
+ description: autocomplete.value,
2851
+ listIsVisible: autocomplete.listIsVisible,
2852
+ pattern: autocomplete.pattern,
2853
+ value: formControl?.value ?? props.value
2854
+ })
2855
+ : children }), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: autocomplete.coincidences, visible: autocomplete.listIsVisible, action: action, disabled: disabled, higher: autocomplete.higher, render: render, refAnchor: autocomplete.refContent, refList: autocomplete.refList, refSuggestions: autocomplete.refSuggestions, searchControl: searchControl, onClickElement: autocomplete.onClickElement, onKeydownElement: autocomplete.onKeydownElement, onClickBackdrop: autocomplete.onClickBackdrop, onHiddenAnchor: autocomplete.onClickBackdrop })] }));
2856
+ }
2857
+ const RlsChooserAutocompleteTemplate = memo(RlsChooserAutocompleteTemplateComponent);
2858
+ function RlsChooserAutocompleteComponent(props) {
2905
2859
  const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
2906
- return jsxRuntimeExports.jsx(RlsFieldAutocompleteTemplate, { ...props, render: render });
2860
+ return jsxRuntimeExports.jsx(RlsChooserAutocompleteTemplate, { ...props, render: render });
2907
2861
  }
2908
- const RlsFieldAutocomplete = memo(RlsFieldAutocompleteComponent);
2862
+ const RlsChooserAutocomplete = memo(RlsChooserAutocompleteComponent);
2909
2863
 
2910
- function RlsModalComponent({ autoclose, children, className, controller, onBackdrop, visible, rlsTheme }) {
2911
- const classNameModal = renderClassStatus('rls-modal', { visible: controller?.visible ?? visible }, className);
2912
- const onClickBackdrop = useCallback(() => {
2913
- if (autoclose) {
2914
- controller?.close();
2915
- }
2916
- onBackdrop?.();
2917
- }, [autoclose, controller, onBackdrop]);
2918
- 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", onClick: onClickBackdrop })] }), document.body);
2919
- }
2920
- const RlsModal = memo(RlsModalComponent);
2864
+ const MAX_LIST_HEIGHT_REM = 90;
2865
+ const FALLBACK_REM_SIZE = 16;
2866
+ function getRemSize() {
2867
+ if (typeof window === 'undefined') {
2868
+ return FALLBACK_REM_SIZE;
2869
+ }
2870
+ const fontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
2871
+ return fontSize > 0 ? fontSize : FALLBACK_REM_SIZE;
2872
+ }
2873
+ function shouldDisplayHigher(content, list) {
2874
+ if (!content) {
2875
+ return false;
2876
+ }
2877
+ const { top, bottom } = content.getBoundingClientRect();
2878
+ const spaceAbove = top;
2879
+ const spaceBelow = window.innerHeight - bottom;
2880
+ const maxHeight = MAX_LIST_HEIGHT_REM * getRemSize();
2881
+ const desiredHeight = Math.min(list?.scrollHeight || maxHeight, maxHeight);
2882
+ if (spaceBelow >= desiredHeight) {
2883
+ return false;
2884
+ }
2885
+ if (spaceAbove >= desiredHeight) {
2886
+ return true;
2887
+ }
2888
+ return spaceAbove > spaceBelow;
2889
+ }
2890
+ function useFieldList(props) {
2891
+ const { suggestions, disabled } = props;
2892
+ const refContent = useRef(null);
2893
+ const refList = useRef(null);
2894
+ const refSuggestions = useRef(null);
2895
+ const formControl = props.formControl;
2896
+ const [state, setState] = useState({
2897
+ higher: false,
2898
+ listIsVisible: false
2899
+ });
2900
+ const [selected, setSelected] = useState([]);
2901
+ useEffect(() => {
2902
+ function onCloseSuggestions({ target }) {
2903
+ if (!refContent?.current?.contains(target) &&
2904
+ !refSuggestions?.current?.contains(target)) {
2905
+ setState((state) => ({ ...state, listIsVisible: false }));
2906
+ }
2907
+ }
2908
+ document.addEventListener('click', onCloseSuggestions);
2909
+ return () => {
2910
+ document.removeEventListener('click', onCloseSuggestions);
2911
+ };
2912
+ }, []);
2913
+ useEffect(() => {
2914
+ const formValue = formControl?.value;
2915
+ if (formValue !== undefined && formValue !== null && formValue.length) {
2916
+ setSelected(suggestions.filter((state) => formValue.some((value) => state.compareTo(value))));
2917
+ }
2918
+ else {
2919
+ setSelected([]);
2920
+ }
2921
+ }, [formControl?.value, suggestions]);
2922
+ const setListState = useCallback((controllerState) => {
2923
+ setState((state) => {
2924
+ const newState = controllerState.listIsVisible !== undefined
2925
+ ? {
2926
+ ...controllerState,
2927
+ ...(controllerState.listIsVisible
2928
+ ? {
2929
+ higher: shouldDisplayHigher(refContent.current, refList.current)
2930
+ }
2931
+ : {})
2932
+ }
2933
+ : controllerState;
2934
+ return { ...state, ...newState };
2935
+ });
2936
+ }, []);
2937
+ const toggleElement = useCallback((element) => {
2938
+ const alreadySelected = selected.some((state) => state.compareTo(element.value));
2939
+ const newSelected = alreadySelected
2940
+ ? selected.filter((state) => !state.compareTo(element.value))
2941
+ : [...selected, element];
2942
+ const newValues = newSelected.map((state) => state.value);
2943
+ setSelected(newSelected);
2944
+ formControl?.setValue(newValues);
2945
+ props.onValue?.(newValues);
2946
+ }, [selected, formControl, props.onValue]);
2947
+ const isSelected = useCallback((element) => {
2948
+ return selected.some((state) => state.compareTo(element.value));
2949
+ }, [selected]);
2950
+ const onClickInput = useCallback(() => {
2951
+ if (!props.readOnly) {
2952
+ setListState({ listIsVisible: true });
2953
+ }
2954
+ }, [setListState, props.readOnly]);
2955
+ const onClickBackdrop = useCallback(() => {
2956
+ setListState({ listIsVisible: false });
2957
+ }, [setListState]);
2958
+ const onClickAction = useCallback(() => {
2959
+ if (!disabled && !props.readOnly) {
2960
+ setListState({ listIsVisible: !state.listIsVisible });
2961
+ }
2962
+ }, [disabled, props.readOnly, setListState, state.listIsVisible]);
2963
+ const onClickElement = useCallback((element) => {
2964
+ return () => {
2965
+ toggleElement(element);
2966
+ };
2967
+ }, [toggleElement]);
2968
+ const onRemoveElement = useCallback((element) => {
2969
+ return (event) => {
2970
+ event.stopPropagation();
2971
+ const newSelected = selected.filter((state) => !state.compareTo(element.value));
2972
+ const newValues = newSelected.map((state) => state.value);
2973
+ setSelected(newSelected);
2974
+ formControl?.setValue(newValues);
2975
+ props.onValue?.(newValues);
2976
+ };
2977
+ }, [selected, formControl, props.onValue]);
2978
+ const onKeydownElement = useCallback((element) => {
2979
+ return (event) => {
2980
+ if (event.code === 'Enter') {
2981
+ toggleElement(element);
2982
+ }
2983
+ };
2984
+ }, [toggleElement]);
2985
+ return useMemo(() => ({
2986
+ ...state,
2987
+ selected,
2988
+ refContent,
2989
+ refList,
2990
+ refSuggestions,
2991
+ isSelected,
2992
+ onClickAction,
2993
+ onClickBackdrop,
2994
+ onClickElement,
2995
+ onClickInput,
2996
+ onKeydownElement,
2997
+ onRemoveElement
2998
+ }), [
2999
+ state,
3000
+ selected,
3001
+ isSelected,
3002
+ onClickAction,
3003
+ onClickBackdrop,
3004
+ onClickElement,
3005
+ onClickInput,
3006
+ onKeydownElement,
3007
+ onRemoveElement
3008
+ ]);
3009
+ }
3010
+
3011
+ function RlsChooserListTemplateComponent(props) {
3012
+ const fieldList = useFieldList(props);
3013
+ const { render, suggestions, action, children, formControl, rlsTheme } = props;
3014
+ const disabled = useMemo(() => {
3015
+ return formControl?.disabled || props.disabled;
3016
+ }, [formControl?.disabled, props.disabled]);
3017
+ const className = renderClassStatus('rls-chooser', {
3018
+ visible: fieldList.listIsVisible,
3019
+ disabled
3020
+ }, `rls-chooser-list ${props.className ?? ''}`);
3021
+ const onKeydownTrigger = useCallback((event) => {
3022
+ switch (event.code) {
3023
+ case 'Space':
3024
+ case 'Enter':
3025
+ event.preventDefault();
3026
+ fieldList.onClickAction();
3027
+ break;
3028
+ case 'Escape':
3029
+ fieldList.onClickBackdrop();
3030
+ break;
3031
+ }
3032
+ }, [fieldList.onClickAction, fieldList.onClickBackdrop]);
3033
+ const renderWithCheckbox = useCallback((element) => (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__multi__element", children: [jsxRuntimeExports.jsx(RlsCheckBox, { checked: fieldList.isSelected(element) }), render(element)] })), [fieldList.isSelected, render]);
3034
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: fieldList.refContent, className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-chooser__trigger", role: "combobox", "aria-expanded": fieldList.listIsVisible, "aria-haspopup": "listbox", "aria-disabled": disabled || undefined, tabIndex: disabled ? -1 : 0, onClick: disabled ? undefined : fieldList.onClickAction, onKeyDown: disabled ? undefined : onKeydownTrigger, children: typeof children === 'function'
3035
+ ? children({
3036
+ listIsVisible: fieldList.listIsVisible,
3037
+ selected: fieldList.selected
3038
+ })
3039
+ : children }), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: fieldList.listIsVisible, action: action, disabled: disabled, higher: fieldList.higher, render: renderWithCheckbox, refAnchor: fieldList.refContent, refList: fieldList.refList, refSuggestions: fieldList.refSuggestions, onClickElement: fieldList.onClickElement, onKeydownElement: fieldList.onKeydownElement, onClickBackdrop: fieldList.onClickBackdrop, onHiddenAnchor: fieldList.onClickBackdrop })] }));
3040
+ }
3041
+ const RlsChooserListTemplate = memo(RlsChooserListTemplateComponent);
3042
+ function RlsChooserListComponent(props) {
3043
+ const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
3044
+ return jsxRuntimeExports.jsx(RlsChooserListTemplate, { ...props, render: render });
3045
+ }
3046
+ const RlsChooserList = memo(RlsChooserListComponent);
3047
+
3048
+ function useFieldSelect(props) {
3049
+ const controller = useListController(props);
3050
+ useEffect(() => {
3051
+ if (props.disabled) {
3052
+ controller.setState({ focused: false });
3053
+ }
3054
+ }, [props.disabled]);
3055
+ const onFocusInput = useCallback(() => {
3056
+ controller.setState({ focused: true });
3057
+ }, [controller.setState]);
3058
+ const onBlurInput = useCallback(() => {
3059
+ controller.setState({ focused: false });
3060
+ }, [controller.setState]);
3061
+ const onClickInput = useCallback(() => {
3062
+ if (!props.readOnly) {
3063
+ controller.setState({ listIsVisible: true });
3064
+ }
3065
+ }, [controller.setState, props.readOnly]);
3066
+ const onKeydownInput = useCallback((event) => {
3067
+ switch (event.code) {
3068
+ case 'Space':
3069
+ case 'Enter':
3070
+ controller.setState({ listIsVisible: true });
3071
+ break;
3072
+ case 'Escape':
3073
+ case 'Tab':
3074
+ controller.setState({ listIsVisible: false });
3075
+ break;
3076
+ default:
3077
+ controller.navigationInput(event);
3078
+ break;
3079
+ }
3080
+ }, [controller.setState, controller.navigationInput]);
3081
+ const onClickAction = useCallback(() => {
3082
+ const removable = !props.unremovable && !!controller.value;
3083
+ if (removable) {
3084
+ controller.setState({ listIsVisible: false });
3085
+ controller.setFormValue(undefined);
3086
+ props.onValue?.(props.value);
3087
+ }
3088
+ else {
3089
+ const listIsVisible = !controller.listIsVisible;
3090
+ controller.setState({ listIsVisible });
3091
+ if (listIsVisible) {
3092
+ controller.refInput?.current?.focus();
3093
+ }
3094
+ }
3095
+ }, [
3096
+ controller.listIsVisible,
3097
+ controller.value,
3098
+ controller.setState,
3099
+ controller.setFormValue,
3100
+ props.unremovable,
3101
+ props.onValue
3102
+ ]);
3103
+ const onClickBackdrop = useCallback(() => {
3104
+ controller.setState({ listIsVisible: false });
3105
+ }, [controller.setState]);
3106
+ const onChange = useCallback((element) => {
3107
+ if (!props.disabled) {
3108
+ controller.refInput?.current?.focus();
3109
+ }
3110
+ if (props.onSelect) {
3111
+ controller.setState({ listIsVisible: false });
3112
+ if (element.value) {
3113
+ props.onSelect(element.value);
3114
+ }
3115
+ }
3116
+ else {
3117
+ controller.setFormValue(element);
3118
+ controller.setState({ listIsVisible: false });
3119
+ }
3120
+ props.onValue?.(element.value);
3121
+ }, [
3122
+ controller.setState,
3123
+ controller.setFormValue,
3124
+ props.onSelect,
3125
+ props.onValue,
3126
+ props.disabled
3127
+ ]);
3128
+ const onClickElement = useCallback((element) => {
3129
+ return () => {
3130
+ onChange(element);
3131
+ };
3132
+ }, [onChange]);
3133
+ const onKeydownElement = useCallback((element) => {
3134
+ return (event) => {
3135
+ if (event.code === 'Enter') {
3136
+ onChange(element);
3137
+ }
3138
+ else {
3139
+ controller.navigationElement(event);
3140
+ }
3141
+ };
3142
+ }, [onChange, controller.navigationElement]);
3143
+ return useMemo(() => ({
3144
+ ...controller,
3145
+ onBlurInput,
3146
+ onClickAction,
3147
+ onClickBackdrop,
3148
+ onClickInput,
3149
+ onClickElement,
3150
+ onFocusInput,
3151
+ onKeydownElement,
3152
+ onKeydownInput
3153
+ }), [
3154
+ controller,
3155
+ onBlurInput,
3156
+ onClickAction,
3157
+ onClickBackdrop,
3158
+ onClickInput,
3159
+ onClickElement,
3160
+ onFocusInput,
3161
+ onKeydownElement,
3162
+ onKeydownInput
3163
+ ]);
3164
+ }
3165
+
3166
+ function RlsChooserSelectTemplateComponent(props) {
3167
+ const select = useFieldSelect({ ...props, unremovable: true });
3168
+ const { render, suggestions, action, children, formControl, rlsTheme } = props;
3169
+ const disabled = useMemo(() => {
3170
+ return formControl?.disabled || props.disabled;
3171
+ }, [formControl?.disabled, props.disabled]);
3172
+ const className = renderClassStatus('rls-chooser', {
3173
+ focused: select.focused && !disabled,
3174
+ visible: select.listIsVisible,
3175
+ disabled
3176
+ }, `rls-chooser-select ${props.className ?? ''}`);
3177
+ const onKeydownTrigger = useCallback((event) => {
3178
+ if (event.code === 'Space') {
3179
+ event.preventDefault();
3180
+ }
3181
+ select.onKeydownInput(event);
3182
+ }, [select.onKeydownInput]);
3183
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: select.refContent, className: className, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsx("div", { className: "rls-chooser__trigger", role: "combobox", "aria-expanded": select.listIsVisible, "aria-haspopup": "listbox", "aria-disabled": disabled || undefined, tabIndex: disabled ? -1 : 0, onClick: disabled ? undefined : select.onClickAction, onKeyDown: disabled ? undefined : onKeydownTrigger, onFocus: select.onFocusInput, onBlur: select.onBlurInput, children: typeof children === 'function'
3184
+ ? children({
3185
+ description: select.value,
3186
+ listIsVisible: select.listIsVisible,
3187
+ value: formControl?.value ?? props.value
3188
+ })
3189
+ : children }), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: select.listIsVisible, action: action, disabled: disabled, higher: select.higher, render: render, refAnchor: select.refContent, refList: select.refList, refSuggestions: select.refSuggestions, onClickElement: select.onClickElement, onKeydownElement: select.onKeydownElement, onClickBackdrop: select.onClickBackdrop, onHiddenAnchor: select.onClickBackdrop })] }));
3190
+ }
3191
+ const RlsChooserSelectTemplate = memo(RlsChooserSelectTemplateComponent);
3192
+ function RlsChooserSelectComponent(props) {
3193
+ const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
3194
+ return jsxRuntimeExports.jsx(RlsChooserSelectTemplate, { ...props, render: render });
3195
+ }
3196
+ const RlsChooserSelect = memo(RlsChooserSelectComponent);
3197
+
3198
+ class ConfirmationResult extends SealedPartial {
3199
+ static approved() {
3200
+ return new ConfirmationResult('approved');
3201
+ }
3202
+ static reject() {
3203
+ return new ConfirmationResult('reject');
3204
+ }
3205
+ }
3206
+ function RlsConfirmationComponent({ approved, className, content, reject, rlsTheme, subtitle, title, visible }) {
3207
+ const classConfirmation = renderClassStatus('rls-confirmation', { visible }, className);
3208
+ return (jsxRuntimeExports.jsxs("div", { className: classConfirmation, "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__component", children: [jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__header", children: [title && jsxRuntimeExports.jsx("div", { className: "rls-confirmation__title", children: title }), subtitle && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__subtitle", children: subtitle }))] }), jsxRuntimeExports.jsx("div", { className: "rls-confirmation__body", children: content && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__content", children: content })) }), (approved || reject) && (jsxRuntimeExports.jsx("div", { className: "rls-confirmation__footer", children: jsxRuntimeExports.jsxs("div", { className: "rls-confirmation__actions", children: [approved && (jsxRuntimeExports.jsx(RlsButton, { identifier: approved.identifier, type: approved.type, onClick: approved.onClick, disabled: approved.disabled, rlsTheme: approved.rlsTheme, children: approved.label })), reject && (jsxRuntimeExports.jsx(RlsButton, { identifier: reject.identifier, type: reject.type, onClick: reject.onClick, disabled: reject.disabled, rlsTheme: reject.rlsTheme, children: reject.label }))] }) }))] }), jsxRuntimeExports.jsx("div", { className: "rls-confirmation__backdrop" })] }));
3209
+ }
3210
+ const RlsConfirmation = memo(RlsConfirmationComponent);
3211
+ const RlsConfirmationBase = RlsConfirmation;
3212
+ function useConfirmation() {
3213
+ const [config, setConfig] = useState({});
3214
+ const [visible, setVisible] = useState(false);
3215
+ const configRef = useRef(config);
3216
+ configRef.current = config;
3217
+ const visibleRef = useRef(visible);
3218
+ visibleRef.current = visible;
3219
+ const RlsConfirmation = useMemo(() => {
3220
+ return function RlsConfirmation(props) {
3221
+ return ReactDOM.createPortal(jsxRuntimeExports.jsx(RlsConfirmationBase, { ...props, ...configRef.current, visible: visibleRef.current }), document.body);
3222
+ };
3223
+ }, []);
3224
+ const confirmation = useCallback((options) => {
3225
+ return new Promise((resolve) => {
3226
+ setConfig({
3227
+ ...options,
3228
+ approved: {
3229
+ label: options.approved?.label ?? reactI18n('confirmationActionApproved'),
3230
+ onClick: () => {
3231
+ setVisible(false);
3232
+ resolve(ConfirmationResult.approved());
3233
+ },
3234
+ type: options.approved?.type ?? 'raised',
3235
+ disabled: options.approved?.disabled,
3236
+ identifier: options.approved?.identifier,
3237
+ rlsTheme: options.approved?.rlsTheme
3238
+ },
3239
+ reject: options.reject
3240
+ ? {
3241
+ label: options.reject.label,
3242
+ onClick: () => {
3243
+ setVisible(false);
3244
+ resolve(ConfirmationResult.reject());
3245
+ },
3246
+ type: options.reject.type ?? 'flat',
3247
+ disabled: options.reject.disabled,
3248
+ identifier: options.reject.identifier,
3249
+ rlsTheme: options.reject.rlsTheme
3250
+ }
3251
+ : undefined
3252
+ });
3253
+ setVisible(true);
3254
+ });
3255
+ }, []);
3256
+ return {
3257
+ confirmation,
3258
+ RlsConfirmation
3259
+ };
3260
+ }
3261
+
3262
+ function createObserver(options) {
3263
+ const { setScrolleable, table } = options;
3264
+ const observer = new ResizeObserver(() => {
3265
+ const scrollHeight = table.scrollHeight || 0;
3266
+ const clientHeight = table.clientHeight || 0;
3267
+ setScrolleable(scrollHeight > clientHeight);
3268
+ });
3269
+ observer.observe(table);
3270
+ return observer;
3271
+ }
3272
+ function useDatatable(table) {
3273
+ const [scrolleable, setScrolleable] = useState(false);
3274
+ const refTable = useRef(table ? table : null);
3275
+ useEffect(() => {
3276
+ const observer = refTable.current &&
3277
+ createObserver({ setScrolleable, table: refTable.current });
3278
+ return () => {
3279
+ observer?.disconnect();
3280
+ };
3281
+ }, []);
3282
+ return { refTable, scrolleable };
3283
+ }
3284
+
3285
+ function RlsDatatableComponent({ children, footer, header, identifier, rlsTheme, resizable, summary, table, toolbar }) {
3286
+ const datatable = useDatatable(table);
3287
+ const className = renderClassStatus('rls-datatable', {
3288
+ resizable,
3289
+ scrolleable: resizable && datatable?.scrolleable
3290
+ });
3291
+ return (jsxRuntimeExports.jsxs("div", { className: className, "rls-theme": rlsTheme, children: [toolbar && jsxRuntimeExports.jsx("div", { className: "rls-datatable__toolbar", children: toolbar }), jsxRuntimeExports.jsx("div", { className: "rls-datatable__table", children: jsxRuntimeExports.jsxs("table", { id: identifier, children: [header && jsxRuntimeExports.jsx("thead", { className: "rls-datatable__head", children: header }), jsxRuntimeExports.jsx("tbody", { ref: datatable?.refTable, className: "rls-datatable__body", children: children })] }) }), summary && jsxRuntimeExports.jsx("div", { className: "rls-datatable__summary", children: summary }), footer && jsxRuntimeExports.jsx("div", { className: "rls-datatable__footer", children: footer })] }));
3292
+ }
3293
+ const RlsDatatable = memo(RlsDatatableComponent);
3294
+ function RlsDatatableHeaderComponent({ children, identifier, rlsTheme }) {
3295
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: "rls-datatable__header", "rls-theme": rlsTheme, children: children }));
3296
+ }
3297
+ const RlsDatatableHeader = memo(RlsDatatableHeaderComponent);
3298
+ function RlsDatatableTitleComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
3299
+ const classNameTitle = renderClassStatus('rls-datatable__title', { actions, control, truncated }, className);
3300
+ return (jsxRuntimeExports.jsx("th", { id: identifier, className: classNameTitle, "rls-theme": rlsTheme, children: children }));
3301
+ }
3302
+ const RlsDatatableTitle = memo(RlsDatatableTitleComponent);
3303
+ function RlsDatatableSubheaderComponent({ children, className, identifier, rlsTheme }) {
3304
+ const classNameSubheader = renderClassStatus('rls-datatable__subheader', {}, className);
3305
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameSubheader, "rls-theme": rlsTheme, children: children }));
3306
+ }
3307
+ const RlsDatatableSubheader = memo(RlsDatatableSubheaderComponent);
3308
+ function RlsDatatableRecordComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
3309
+ const classNameRecord = renderClassStatus('rls-datatable__record', { error, info, truncated, success, warning }, className);
3310
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameRecord, "rls-theme": rlsTheme, children: children }));
3311
+ }
3312
+ const RlsDatatableRecord = memo(RlsDatatableRecordComponent);
3313
+ function RlsDatatableTotalsComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
3314
+ const classNameTotals = renderClassStatus('rls-datatable__totals', { error, info, truncated, success, warning }, className);
3315
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameTotals, "rls-theme": rlsTheme, children: children }));
3316
+ }
3317
+ const RlsDatatableTotals = memo(RlsDatatableTotalsComponent);
3318
+ function RlsDatatableCellComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
3319
+ const classNameCell = renderClassStatus('rls-datatable__cell', { actions, control, truncated }, className);
3320
+ return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameCell, "rls-theme": rlsTheme, children: children }));
3321
+ }
3322
+ const RlsDatatableCell = memo(RlsDatatableCellComponent);
3323
+ function RlsDatatableDataComponent({ actions, children, className, control, identifier, truncated }) {
3324
+ const classNameData = renderClassStatus('rls-datatable__data', { actions, control, truncated }, className);
3325
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameData, children: children }));
3326
+ }
3327
+ const RlsDatatableData = memo(RlsDatatableDataComponent);
3328
+ function RlsDatatableFloatingComponent({ children, className, identifier, invested, rlsTheme }) {
3329
+ const classNameFloating = renderClassStatus('rls-datatable__floating', { invested }, className);
3330
+ return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameFloating, "rls-theme": rlsTheme, children: children }));
3331
+ }
3332
+ const RlsDatatableFloating = memo(RlsDatatableFloatingComponent);
3333
+
3334
+ function RlsDropdownComponent({ children, controller, rlsTheme }) {
3335
+ const className = renderClassStatus('rls-dropdown', {
3336
+ visible: controller.visible
3337
+ });
3338
+ useEffect(() => {
3339
+ function onCloseDropdown({ target }) {
3340
+ if (!controller.component.current.contains(target)) {
3341
+ controller.close();
3342
+ }
3343
+ }
3344
+ document.addEventListener('click', onCloseDropdown);
3345
+ return () => {
3346
+ document.removeEventListener('click', onCloseDropdown);
3347
+ };
3348
+ }, []);
3349
+ return (jsxRuntimeExports.jsx("div", { ref: controller.component, className: className, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-dropdown__content", children: children }) }));
3350
+ }
3351
+ const RlsDropdown = memo(RlsDropdownComponent);
3352
+
3353
+ function RlsFieldAutocompleteTemplateComponent(props) {
3354
+ const autocomplete = useFieldAutocomplete(props);
3355
+ const { render, action, children, formControl, msgErrorDisabled, onSearch, placeholder, rlsTheme, searching } = props;
3356
+ const [listInputPlaceholder, setListInputPlaceholder] = useState(reactI18n('listInputPlaceholder'));
3357
+ useEffect(() => {
3358
+ return i18nSubscribe(() => {
3359
+ setListInputPlaceholder(reactI18n('listInputPlaceholder'));
3360
+ });
3361
+ }, []);
3362
+ useEffect(() => {
3363
+ props.onInput?.(autocomplete.pattern);
3364
+ }, [autocomplete.pattern, props.onInput]);
3365
+ const disabled = useMemo(() => {
3366
+ return formControl?.disabled || props.disabled;
3367
+ }, [formControl?.disabled, props.disabled]);
3368
+ const className = renderClassStatus('rls-field-box', {
3369
+ focused: autocomplete.focused && !disabled,
3370
+ error: formControl?.wrong,
3371
+ disabled,
3372
+ readonly: props.readOnly,
3373
+ selected: !!autocomplete.value
3374
+ }, `rls-field-list rls-field-autocomplete ${props.className ?? ''}`);
3375
+ const onClickPattern = useCallback(() => {
3376
+ onSearch?.(autocomplete.pattern);
3377
+ }, [onSearch, autocomplete.pattern]);
3378
+ const onKeyDownPattern = useCallback((event) => {
3379
+ if (event.key === 'Enter') {
3380
+ onSearch?.(autocomplete.pattern);
3381
+ }
3382
+ autocomplete.onKeydownInput(event);
3383
+ }, [autocomplete.onKeydownInput, onSearch, autocomplete.pattern]);
3384
+ const searchControl = useMemo(() => ({
3385
+ pattern: autocomplete.pattern,
3386
+ placeholder: listInputPlaceholder,
3387
+ searching,
3388
+ refInput: autocomplete.refInput,
3389
+ onChange: autocomplete.setPattern,
3390
+ onFocus: autocomplete.onFocusInput,
3391
+ onBlur: autocomplete.onBlurInput,
3392
+ onKeyDown: onKeyDownPattern,
3393
+ onSearch: onSearch ? onClickPattern : undefined
3394
+ }), [
3395
+ autocomplete.pattern,
3396
+ autocomplete.refInput,
3397
+ autocomplete.setPattern,
3398
+ autocomplete.onFocusInput,
3399
+ autocomplete.onBlurInput,
3400
+ listInputPlaceholder,
3401
+ searching,
3402
+ onKeyDownPattern,
3403
+ onClickPattern,
3404
+ onSearch
3405
+ ]);
3406
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: autocomplete.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-list__control", readOnly: true, disabled: disabled, placeholder: placeholder, value: autocomplete.value, onClick: autocomplete.onClickControl }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: autocomplete.value ? 'trash-2' : 'arrow-ios-down', onClick: autocomplete.onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: autocomplete.coincidences, visible: autocomplete.listIsVisible, action: action, disabled: disabled, higher: autocomplete.higher, render: render, refAnchor: autocomplete.refContent, refList: autocomplete.refList, refSuggestions: autocomplete.refSuggestions, searchControl: searchControl, onClickElement: autocomplete.onClickElement, onKeydownElement: autocomplete.onKeydownElement, onClickBackdrop: autocomplete.onClickBackdrop, onHiddenAnchor: autocomplete.onClickBackdrop })] }));
3407
+ }
3408
+ const RlsFieldAutocompleteTemplate = memo(RlsFieldAutocompleteTemplateComponent);
3409
+ function RlsFieldAutocompleteComponent(props) {
3410
+ const render = useCallback((element) => (jsxRuntimeExports.jsx(RlsBallot, { className: "rls-field-list__ballot", subtitle: element.subtitle, img: element.img, initials: element.initials, children: jsxRuntimeExports.jsx("span", { children: element.title }) })), []);
3411
+ return jsxRuntimeExports.jsx(RlsFieldAutocompleteTemplate, { ...props, render: render });
3412
+ }
3413
+ const RlsFieldAutocomplete = memo(RlsFieldAutocompleteComponent);
3414
+
3415
+ function RlsModalComponent({ autoclose, children, className, controller, onBackdrop, visible, rlsTheme }) {
3416
+ const classNameModal = renderClassStatus('rls-modal', { visible: controller?.visible ?? visible }, className);
3417
+ const onClickBackdrop = useCallback(() => {
3418
+ if (autoclose) {
3419
+ controller?.close();
3420
+ }
3421
+ onBackdrop?.();
3422
+ }, [autoclose, controller, onBackdrop]);
3423
+ 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", onClick: onClickBackdrop })] }), document.body);
3424
+ }
3425
+ const RlsModal = memo(RlsModalComponent);
2921
3426
 
2922
3427
  function formatTime(value) {
2923
3428
  return String(value).padStart(2, '0');
@@ -3690,192 +4195,48 @@ function RlsFieldDateRangeComponent({ children, date, disabled: disabledProps, f
3690
4195
  const disabled = useMemo(() => {
3691
4196
  return formControl?.disabled || disabledProps;
3692
4197
  }, [formControl?.disabled, disabledProps]);
3693
- const className = renderClassStatus('rls-field-box', {
3694
- disabled,
3695
- readonly: readOnly
3696
- });
3697
- const dateRangeValue = useMemo(() => {
3698
- return formControl ? formControl.value : value;
3699
- }, [formControl?.value, value]);
3700
- const status = useMemo(() => {
3701
- return {
3702
- icon: dateRangeValue ? 'trash-2' : 'calendar',
3703
- valueInput: dateRangeValue ? rangeFormatTemplate(dateRangeValue) : ''
3704
- };
3705
- }, [dateRangeValue]);
3706
- const onClickInput = useCallback(() => {
3707
- if (!readOnly) {
3708
- setModalIsVisible(true);
3709
- }
3710
- }, [readOnly]);
3711
- const onChange = useCallback((value) => {
3712
- setValue(value);
3713
- onValue?.(value);
3714
- }, [onValue]);
3715
- const onClickAction = useCallback(() => {
3716
- if (dateRangeValue) {
3717
- formControl?.setValue(valueInitial);
3718
- formControl?.touch();
3719
- onChange(valueInitial);
3720
- }
3721
- else {
3722
- setModalIsVisible(true);
3723
- }
3724
- }, [dateRangeValue, formControl, valueInitial, onChange]);
3725
- const onCloseModal = useCallback((dateRange) => {
3726
- if (dateRange) {
3727
- onChange(dateRange);
3728
- }
3729
- formControl?.touch();
3730
- setModalIsVisible(false);
3731
- }, [formControl, onChange]);
3732
- return (jsxRuntimeExports.jsxs("div", { id: identifier, className: "rls-field-date-range", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-date-range__control", type: "text", value: status.valueInput, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), !readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: status.icon, onClick: onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }), jsxRuntimeExports.jsx(RlsModalDateRange, { visible: modalIsVisible, formControl: formControl, date: currentDate, disabled: disabled, maxDate: maxDate, minDate: minDate, onClose: onCloseModal, rlsTheme: rlsTheme })] }));
3733
- }
3734
- const RlsFieldDateRange = memo(RlsFieldDateRangeComponent);
3735
-
3736
- const MAX_LIST_HEIGHT_REM = 90;
3737
- const FALLBACK_REM_SIZE = 16;
3738
- function getRemSize() {
3739
- if (typeof window === 'undefined') {
3740
- return FALLBACK_REM_SIZE;
3741
- }
3742
- const fontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
3743
- return fontSize > 0 ? fontSize : FALLBACK_REM_SIZE;
3744
- }
3745
- function shouldDisplayHigher(content, list) {
3746
- if (!content) {
3747
- return false;
3748
- }
3749
- const { top, bottom } = content.getBoundingClientRect();
3750
- const spaceAbove = top;
3751
- const spaceBelow = window.innerHeight - bottom;
3752
- const maxHeight = MAX_LIST_HEIGHT_REM * getRemSize();
3753
- const desiredHeight = Math.min(list?.scrollHeight || maxHeight, maxHeight);
3754
- if (spaceBelow >= desiredHeight) {
3755
- return false;
3756
- }
3757
- if (spaceAbove >= desiredHeight) {
3758
- return true;
3759
- }
3760
- return spaceAbove > spaceBelow;
3761
- }
3762
- function useFieldList(props) {
3763
- const { suggestions, disabled } = props;
3764
- const refContent = useRef(null);
3765
- const refList = useRef(null);
3766
- const formControl = props.formControl;
3767
- const [state, setState] = useState({
3768
- higher: false,
3769
- listIsVisible: false
3770
- });
3771
- const [selected, setSelected] = useState([]);
3772
- useEffect(() => {
3773
- function onCloseSuggestions({ target }) {
3774
- if (!refContent?.current?.contains(target)) {
3775
- setState((state) => ({ ...state, listIsVisible: false }));
3776
- }
3777
- }
3778
- document.addEventListener('click', onCloseSuggestions);
3779
- return () => {
3780
- document.removeEventListener('click', onCloseSuggestions);
4198
+ const className = renderClassStatus('rls-field-box', {
4199
+ disabled,
4200
+ readonly: readOnly
4201
+ });
4202
+ const dateRangeValue = useMemo(() => {
4203
+ return formControl ? formControl.value : value;
4204
+ }, [formControl?.value, value]);
4205
+ const status = useMemo(() => {
4206
+ return {
4207
+ icon: dateRangeValue ? 'trash-2' : 'calendar',
4208
+ valueInput: dateRangeValue ? rangeFormatTemplate(dateRangeValue) : ''
3781
4209
  };
3782
- }, []);
3783
- useEffect(() => {
3784
- const formValue = formControl?.value;
3785
- if (formValue !== undefined && formValue !== null && formValue.length) {
3786
- setSelected(suggestions.filter((state) => formValue.some((value) => state.compareTo(value))));
3787
- }
3788
- else {
3789
- setSelected([]);
3790
- }
3791
- }, [formControl?.value, suggestions]);
3792
- const setListState = useCallback((controllerState) => {
3793
- setState((state) => {
3794
- const newState = controllerState.listIsVisible !== undefined
3795
- ? {
3796
- ...controllerState,
3797
- ...(controllerState.listIsVisible
3798
- ? {
3799
- higher: shouldDisplayHigher(refContent.current, refList.current)
3800
- }
3801
- : {})
3802
- }
3803
- : controllerState;
3804
- return { ...state, ...newState };
3805
- });
3806
- }, []);
3807
- const toggleElement = useCallback((element) => {
3808
- const alreadySelected = selected.some((state) => state.compareTo(element.value));
3809
- const newSelected = alreadySelected
3810
- ? selected.filter((state) => !state.compareTo(element.value))
3811
- : [...selected, element];
3812
- const newValues = newSelected.map((state) => state.value);
3813
- setSelected(newSelected);
3814
- formControl?.setValue(newValues);
3815
- props.onValue?.(newValues);
3816
- }, [selected, formControl, props.onValue]);
3817
- const isSelected = useCallback((element) => {
3818
- return selected.some((state) => state.compareTo(element.value));
3819
- }, [selected]);
4210
+ }, [dateRangeValue]);
3820
4211
  const onClickInput = useCallback(() => {
3821
- if (!props.readOnly) {
3822
- setListState({ listIsVisible: true });
4212
+ if (!readOnly) {
4213
+ setModalIsVisible(true);
3823
4214
  }
3824
- }, [setListState, props.readOnly]);
3825
- const onClickBackdrop = useCallback(() => {
3826
- setListState({ listIsVisible: false });
3827
- }, [setListState]);
4215
+ }, [readOnly]);
4216
+ const onChange = useCallback((value) => {
4217
+ setValue(value);
4218
+ onValue?.(value);
4219
+ }, [onValue]);
3828
4220
  const onClickAction = useCallback(() => {
3829
- if (!disabled && !props.readOnly) {
3830
- setListState({ listIsVisible: !state.listIsVisible });
4221
+ if (dateRangeValue) {
4222
+ formControl?.setValue(valueInitial);
4223
+ formControl?.touch();
4224
+ onChange(valueInitial);
3831
4225
  }
3832
- }, [disabled, props.readOnly, setListState, state.listIsVisible]);
3833
- const onClickElement = useCallback((element) => {
3834
- return () => {
3835
- toggleElement(element);
3836
- };
3837
- }, [toggleElement]);
3838
- const onRemoveElement = useCallback((element) => {
3839
- return (event) => {
3840
- event.stopPropagation();
3841
- const newSelected = selected.filter((state) => !state.compareTo(element.value));
3842
- const newValues = newSelected.map((state) => state.value);
3843
- setSelected(newSelected);
3844
- formControl?.setValue(newValues);
3845
- props.onValue?.(newValues);
3846
- };
3847
- }, [selected, formControl, props.onValue]);
3848
- const onKeydownElement = useCallback((element) => {
3849
- return (event) => {
3850
- if (event.code === 'Enter') {
3851
- toggleElement(element);
3852
- }
3853
- };
3854
- }, [toggleElement]);
3855
- return useMemo(() => ({
3856
- ...state,
3857
- selected,
3858
- refContent,
3859
- refList,
3860
- isSelected,
3861
- onClickAction,
3862
- onClickBackdrop,
3863
- onClickElement,
3864
- onClickInput,
3865
- onKeydownElement,
3866
- onRemoveElement
3867
- }), [
3868
- state,
3869
- selected,
3870
- isSelected,
3871
- onClickAction,
3872
- onClickBackdrop,
3873
- onClickElement,
3874
- onClickInput,
3875
- onKeydownElement,
3876
- onRemoveElement
3877
- ]);
4226
+ else {
4227
+ setModalIsVisible(true);
4228
+ }
4229
+ }, [dateRangeValue, formControl, valueInitial, onChange]);
4230
+ const onCloseModal = useCallback((dateRange) => {
4231
+ if (dateRange) {
4232
+ onChange(dateRange);
4233
+ }
4234
+ formControl?.touch();
4235
+ setModalIsVisible(false);
4236
+ }, [formControl, onChange]);
4237
+ return (jsxRuntimeExports.jsxs("div", { id: identifier, className: "rls-field-date-range", "rls-theme": rlsTheme, children: [jsxRuntimeExports.jsxs("div", { className: className, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { className: "rls-field-date-range__control", type: "text", value: status.valueInput, readOnly: true, placeholder: placeholder, onClick: onClickInput, disabled: disabled }), !readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: status.icon, onClick: onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl }))] }), jsxRuntimeExports.jsx(RlsModalDateRange, { visible: modalIsVisible, formControl: formControl, date: currentDate, disabled: disabled, maxDate: maxDate, minDate: minDate, onClose: onCloseModal, rlsTheme: rlsTheme })] }));
3878
4238
  }
4239
+ const RlsFieldDateRange = memo(RlsFieldDateRangeComponent);
3879
4240
 
3880
4241
  function RlsFieldListInner({ render, suggestions, action, children, formControl, fieldList, msgErrorDisabled, placeholder, rlsTheme, ...props }) {
3881
4242
  const disabled = useMemo(() => {
@@ -3888,7 +4249,7 @@ function RlsFieldListInner({ render, suggestions, action, children, formControl,
3888
4249
  readonly: props.readOnly
3889
4250
  }, `rls-field-list rls-field-list__multi ${props.className ?? ''}`);
3890
4251
  const renderWithCheckbox = useCallback((element) => (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__multi__element", children: [jsxRuntimeExports.jsx(RlsCheckBox, { checked: fieldList.isSelected(element) }), render(element)] })), [fieldList.isSelected, render]);
3891
- return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: fieldList.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("div", { className: "rls-field-list__multi__chips", onClick: disabled ? undefined : fieldList.onClickInput, children: !fieldList.selected.length && placeholder ? (jsxRuntimeExports.jsx("span", { className: "rls-field-list__multi__placeholder", children: placeholder })) : (fieldList.selected.map((item, index) => (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__multi__chip", children: [jsxRuntimeExports.jsx("span", { className: "rls-field-list__multi__chip__description", children: item.description }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx("button", { className: "rls-field-list__multi__chip__remove", onClick: fieldList.onRemoveElement(item), children: jsxRuntimeExports.jsx(RlsIcon, { value: "close" }) }))] }, index)))) }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-down", onClick: fieldList.onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: fieldList.listIsVisible, action: action, disabled: disabled, higher: fieldList.higher, render: renderWithCheckbox, refList: fieldList.refList, onClickElement: fieldList.onClickElement, onKeydownElement: fieldList.onKeydownElement, onClickBackdrop: fieldList.onClickBackdrop })] }));
4252
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: fieldList.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("div", { className: "rls-field-list__multi__chips", onClick: disabled ? undefined : fieldList.onClickInput, children: !fieldList.selected.length && placeholder ? (jsxRuntimeExports.jsx("span", { className: "rls-field-list__multi__placeholder", children: placeholder })) : (fieldList.selected.map((item, index) => (jsxRuntimeExports.jsxs("div", { className: "rls-field-list__multi__chip", children: [jsxRuntimeExports.jsx("span", { className: "rls-field-list__multi__chip__description", children: item.description }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx("button", { className: "rls-field-list__multi__chip__remove", onClick: fieldList.onRemoveElement(item), children: jsxRuntimeExports.jsx(RlsIcon, { value: "close" }) }))] }, index)))) }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: "arrow-ios-down", onClick: fieldList.onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: fieldList.listIsVisible, action: action, disabled: disabled, higher: fieldList.higher, render: renderWithCheckbox, refAnchor: fieldList.refContent, refList: fieldList.refList, refSuggestions: fieldList.refSuggestions, onClickElement: fieldList.onClickElement, onKeydownElement: fieldList.onKeydownElement, onClickBackdrop: fieldList.onClickBackdrop, onHiddenAnchor: fieldList.onClickBackdrop })] }));
3892
4253
  }
3893
4254
  function RlsFieldListTemplateComponent(props) {
3894
4255
  const fieldList = useFieldList(props);
@@ -3902,124 +4263,6 @@ function RlsFieldListComponent(props) {
3902
4263
  }
3903
4264
  const RlsFieldList = memo(RlsFieldListComponent);
3904
4265
 
3905
- function useFieldSelect(props) {
3906
- const controller = useListController(props);
3907
- useEffect(() => {
3908
- if (props.disabled) {
3909
- controller.setState({ focused: false });
3910
- }
3911
- }, [props.disabled]);
3912
- const onFocusInput = useCallback(() => {
3913
- controller.setState({ focused: true });
3914
- }, [controller.setState]);
3915
- const onBlurInput = useCallback(() => {
3916
- controller.setState({ focused: false });
3917
- }, [controller.setState]);
3918
- const onClickInput = useCallback(() => {
3919
- if (!props.readOnly) {
3920
- controller.setState({ listIsVisible: true });
3921
- }
3922
- }, [controller.setState, props.readOnly]);
3923
- const onKeydownInput = useCallback((event) => {
3924
- switch (event.code) {
3925
- case 'Space':
3926
- case 'Enter':
3927
- controller.setState({ listIsVisible: true });
3928
- break;
3929
- case 'Escape':
3930
- case 'Tab':
3931
- controller.setState({ listIsVisible: false });
3932
- break;
3933
- default:
3934
- controller.navigationInput(event);
3935
- break;
3936
- }
3937
- }, [controller.setState, controller.navigationInput]);
3938
- const onClickAction = useCallback(() => {
3939
- const removable = !props.unremovable && !!controller.value;
3940
- if (removable) {
3941
- controller.setState({ listIsVisible: false });
3942
- controller.setFormValue(undefined);
3943
- props.onValue?.(props.value);
3944
- }
3945
- else {
3946
- const listIsVisible = !controller.listIsVisible;
3947
- controller.setState({ listIsVisible });
3948
- if (listIsVisible) {
3949
- controller.refInput?.current?.focus();
3950
- }
3951
- }
3952
- }, [
3953
- controller.listIsVisible,
3954
- controller.value,
3955
- controller.setState,
3956
- controller.setFormValue,
3957
- props.unremovable,
3958
- props.onValue
3959
- ]);
3960
- const onClickBackdrop = useCallback(() => {
3961
- controller.setState({ listIsVisible: false });
3962
- }, [controller.setState]);
3963
- const onChange = useCallback((element) => {
3964
- if (!props.disabled) {
3965
- controller.refInput?.current?.focus();
3966
- }
3967
- if (props.onSelect) {
3968
- controller.setState({ listIsVisible: false });
3969
- if (element.value) {
3970
- props.onSelect(element.value);
3971
- }
3972
- }
3973
- else {
3974
- controller.setFormValue(element);
3975
- controller.setState({ listIsVisible: false });
3976
- }
3977
- props.onValue?.(element.value);
3978
- }, [
3979
- controller.setState,
3980
- controller.setFormValue,
3981
- props.onSelect,
3982
- props.onValue,
3983
- props.disabled
3984
- ]);
3985
- const onClickElement = useCallback((element) => {
3986
- return () => {
3987
- onChange(element);
3988
- };
3989
- }, [onChange]);
3990
- const onKeydownElement = useCallback((element) => {
3991
- return (event) => {
3992
- if (event.code === 'Enter') {
3993
- onChange(element);
3994
- }
3995
- else {
3996
- controller.navigationElement(event);
3997
- }
3998
- };
3999
- }, [onChange, controller.navigationElement]);
4000
- return useMemo(() => ({
4001
- ...controller,
4002
- onBlurInput,
4003
- onClickAction,
4004
- onClickBackdrop,
4005
- onClickInput,
4006
- onClickElement,
4007
- onFocusInput,
4008
- onKeydownElement,
4009
- onKeydownInput
4010
- }), [
4011
- controller,
4012
- onBlurInput,
4013
- onClickAction,
4014
- onClickBackdrop,
4015
- onClickInput,
4016
- onClickElement,
4017
- onFocusInput,
4018
- onKeydownElement,
4019
- onKeydownInput
4020
- ]);
4021
- }
4022
-
4023
4266
  function RlsFieldSelectTemplateComponent(props) {
4024
4267
  const select = useFieldSelect(props);
4025
4268
  const { render, suggestions, action, children, formControl, msgErrorDisabled, placeholder, rlsTheme, unremovable } = props;
@@ -4032,7 +4275,7 @@ function RlsFieldSelectTemplateComponent(props) {
4032
4275
  disabled: disabled,
4033
4276
  readonly: props.readOnly
4034
4277
  }, `rls-field-list rls-field-select ${props.className ?? ''}`);
4035
- return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: select.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { ref: select.refInput, className: "rls-field-list__control", readOnly: true, placeholder: placeholder, value: select.value, onFocus: select.onFocusInput, onBlur: select.onBlurInput, onClick: select.onClickInput, onKeyDown: select.onKeydownInput, disabled: disabled }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: !unremovable && !!select.value ? 'close' : 'arrow-ios-down', onClick: select.onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: select.listIsVisible, action: action, disabled: disabled, higher: select.higher, render: render, refList: select.refList, onClickElement: select.onClickElement, onKeydownElement: select.onKeydownElement, onClickBackdrop: select.onClickBackdrop })] }));
4278
+ return (jsxRuntimeExports.jsxs("div", { id: props.identifier, ref: select.refContent, className: className, "rls-theme": rlsTheme, children: [children && jsxRuntimeExports.jsx("span", { className: "rls-field-box__label", children: children }), jsxRuntimeExports.jsx("div", { className: "rls-field-box__component", children: jsxRuntimeExports.jsxs("div", { className: "rls-field-box__body", children: [jsxRuntimeExports.jsx("input", { ref: select.refInput, className: "rls-field-list__control", readOnly: true, placeholder: placeholder, value: select.value, onFocus: select.onFocusInput, onBlur: select.onBlurInput, onClick: select.onClickInput, onKeyDown: select.onKeydownInput, disabled: disabled }), !props.readOnly && !disabled && (jsxRuntimeExports.jsx(RlsButtonIcon, { icon: !unremovable && !!select.value ? 'close' : 'arrow-ios-down', onClick: select.onClickAction }))] }) }), !msgErrorDisabled && (jsxRuntimeExports.jsx(RlsMessageFormError, { className: "rls-field-box__error", formControl: formControl })), jsxRuntimeExports.jsx(RlsFieldListSuggestions, { elements: suggestions, visible: select.listIsVisible, action: action, disabled: disabled, higher: select.higher, render: render, refAnchor: select.refContent, refList: select.refList, refSuggestions: select.refSuggestions, onClickElement: select.onClickElement, onKeydownElement: select.onKeydownElement, onClickBackdrop: select.onClickBackdrop, onHiddenAnchor: select.onClickBackdrop })] }));
4036
4279
  }
4037
4280
  const RlsFieldSelectTemplate = memo(RlsFieldSelectTemplateComponent);
4038
4281
  function RlsFieldSelectComponent(props) {
@@ -4047,54 +4290,56 @@ function RlsFormNavigationComponent({ children, className, controller, visible,
4047
4290
  }
4048
4291
  const RlsFormNavigation = memo(RlsFormNavigationComponent);
4049
4292
 
4050
- function useRelocationOnComponent({ container, element, onDrag }) {
4293
+ function useRelocationOnComponent({ container: containerRef, element: elementRef, onDrag }) {
4051
4294
  const position = useRef({ x: 0, y: 0 });
4052
4295
  const dragOffset = useRef({ x: 0, y: 0 });
4053
4296
  const dragging = useRef(false);
4054
- const getClientX = useCallback((positionX) => {
4297
+ function getClientX(positionX) {
4055
4298
  let clientX = position.current.x + positionX - dragOffset.current.x;
4056
4299
  if (clientX < 0) {
4057
4300
  clientX = 0;
4058
4301
  }
4059
4302
  else {
4060
- const width = clientX + element.current.offsetWidth;
4061
- if (width > container.current.offsetWidth) {
4062
- clientX = container.current.offsetWidth - element.current.offsetWidth;
4303
+ const width = clientX + elementRef.current.offsetWidth;
4304
+ if (width > containerRef.current.offsetWidth) {
4305
+ clientX =
4306
+ containerRef.current.offsetWidth - elementRef.current.offsetWidth;
4063
4307
  }
4064
4308
  }
4065
4309
  return clientX;
4066
- }, []);
4067
- const getClientY = useCallback((positionY) => {
4310
+ }
4311
+ function getClientY(positionY) {
4068
4312
  let clientY = position.current.y + positionY - dragOffset.current.y;
4069
4313
  if (clientY < 0) {
4070
4314
  clientY = 0;
4071
4315
  }
4072
4316
  else {
4073
- const height = clientY + element.current.offsetHeight;
4074
- if (height > container.current.offsetHeight) {
4075
- clientY = container.current.offsetHeight - element.current.offsetHeight;
4317
+ const height = clientY + elementRef.current.offsetHeight;
4318
+ if (height > containerRef.current.offsetHeight) {
4319
+ clientY =
4320
+ containerRef.current.offsetHeight - elementRef.current.offsetHeight;
4076
4321
  }
4077
4322
  }
4078
4323
  return clientY;
4079
- }, []);
4080
- const start = useCallback((positionX, positionY) => {
4324
+ }
4325
+ const start = useEffectEvent((positionX, positionY) => {
4081
4326
  dragOffset.current = {
4082
4327
  x: positionX,
4083
4328
  y: positionY
4084
4329
  };
4085
4330
  position.current = {
4086
- x: element.current.offsetLeft,
4087
- y: element.current.offsetTop
4331
+ x: elementRef.current.offsetLeft,
4332
+ y: elementRef.current.offsetTop
4088
4333
  };
4089
4334
  dragging.current = true;
4090
- }, []);
4091
- const relocation = useCallback((positionX, positionY) => {
4335
+ });
4336
+ const relocation = useEffectEvent((positionX, positionY) => {
4092
4337
  const clientX = getClientX(positionX);
4093
4338
  const clientY = getClientY(positionY);
4094
- element.current.style.top = `${clientY}px`;
4095
- element.current.style.left = `${clientX}px`;
4339
+ elementRef.current.style.top = `${clientY}px`;
4340
+ elementRef.current.style.left = `${clientX}px`;
4096
4341
  onDrag?.();
4097
- }, []);
4342
+ });
4098
4343
  useEffect(() => {
4099
4344
  const mousedown = (event) => {
4100
4345
  start(event.clientX, event.clientY);
@@ -4122,30 +4367,28 @@ function useRelocationOnComponent({ container, element, onDrag }) {
4122
4367
  const touchend = () => {
4123
4368
  dragging.current = false;
4124
4369
  };
4125
- element.current.addEventListener('mousedown', mousedown);
4126
- element.current.addEventListener('mousemove', mousemove);
4127
- element.current.addEventListener('mouseup', mouseup);
4128
- element.current.addEventListener('touchstart', touchstart);
4129
- element.current.addEventListener('touchmove', touchmove);
4130
- element.current.addEventListener('touchend', touchend);
4370
+ elementRef.current.addEventListener('mousedown', mousedown);
4371
+ elementRef.current.addEventListener('mousemove', mousemove);
4372
+ elementRef.current.addEventListener('mouseup', mouseup);
4373
+ elementRef.current.addEventListener('touchstart', touchstart);
4374
+ elementRef.current.addEventListener('touchmove', touchmove);
4375
+ elementRef.current.addEventListener('touchend', touchend);
4131
4376
  return () => {
4132
- element.current?.removeEventListener('mousedown', mousedown);
4133
- element.current?.removeEventListener('mousemove', mousemove);
4134
- element.current?.removeEventListener('mouseup', mouseup);
4135
- element.current?.removeEventListener('touchstart', touchstart);
4136
- element.current?.removeEventListener('touchmove', touchmove);
4137
- element.current?.removeEventListener('touchend', touchend);
4377
+ elementRef.current?.removeEventListener('mousedown', mousedown);
4378
+ elementRef.current?.removeEventListener('mousemove', mousemove);
4379
+ elementRef.current?.removeEventListener('mouseup', mouseup);
4380
+ elementRef.current?.removeEventListener('touchstart', touchstart);
4381
+ elementRef.current?.removeEventListener('touchmove', touchmove);
4382
+ elementRef.current?.removeEventListener('touchend', touchend);
4138
4383
  };
4139
4384
  }, []);
4140
4385
  }
4141
4386
 
4142
4387
  function useResize({ refElement, onResize }) {
4143
4388
  const dimension = useRef({ height: 0, width: 0 });
4144
- const onResizeRef = useRef(onResize);
4145
- onResizeRef.current = onResize;
4146
- const observer = useCallback((entries) => {
4389
+ const observer = useEffectEvent((entries) => {
4147
4390
  const { height, width } = entries[0].contentRect;
4148
- onResizeRef.current?.({
4391
+ onResize?.({
4149
4392
  current: dimension.current,
4150
4393
  dimension: {
4151
4394
  height,
@@ -4153,13 +4396,13 @@ function useResize({ refElement, onResize }) {
4153
4396
  }
4154
4397
  });
4155
4398
  dimension.current = { height, width };
4156
- }, []);
4399
+ });
4157
4400
  useEffect(() => {
4158
4401
  dimension.current = {
4159
4402
  height: refElement.current.offsetHeight,
4160
4403
  width: refElement.current.offsetWidth
4161
4404
  };
4162
- const resizeObserver = new ResizeObserver(observer);
4405
+ const resizeObserver = new ResizeObserver((entries) => observer(entries));
4163
4406
  resizeObserver.observe(refElement.current);
4164
4407
  return () => {
4165
4408
  resizeObserver.disconnect();
@@ -4824,5 +5067,5 @@ function toggleAppTheme() {
4824
5067
  return theme;
4825
5068
  }
4826
5069
 
4827
- export { ConfirmationResult, DEFAULT_COLOR, RlsAccordion, RlsAlert, RlsAmount, RlsApplication, RlsAreaText, RlsAvatar, RlsBadge, RlsBallot, RlsBody, RlsBottomSheet, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonIcon, RlsButtonOption, RlsButtonProgress, RlsButtonStepper, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsConfirmation, RlsContent, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableFloating, RlsDatatableHeader, RlsDatatableRecord, RlsDatatableSubheader, RlsDatatableTitle, RlsDatatableTotals, RlsDropdown, RlsFieldArea, RlsFieldAutocomplete, RlsFieldAutocompleteTemplate, RlsFieldClock, RlsFieldColor, RlsFieldDate, RlsFieldDateRange, RlsFieldDecimal, RlsFieldFile, RlsFieldList, RlsFieldListSuggestions, RlsFieldListTemplate, RlsFieldMoney, RlsFieldNumber, RlsFieldPassword, RlsFieldPercentage, RlsFieldReadonly, RlsFieldSelect, RlsFieldSelectTemplate, RlsFieldText, RlsFormNavigation, RlsIcon, RlsImage, RlsImageChooser, RlsImageEditor, RlsInput, RlsInputCounter, RlsInputDecimal, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputPercentage, RlsInputSearch, RlsInputText, RlsLabel, RlsLabelCheckBox, RlsLabelRadioButton, RlsLabelSwitch, RlsLed, RlsMessageEmpty, RlsMessageFormError, RlsMessageIcon, RlsModal, RlsModalClock, RlsModalDate, RlsModalDateRange, RlsModalSheet, RlsNavbar, RlsNavbarMenu, RlsPagination, RlsPickerClock, RlsPickerColor, RlsPickerDate, RlsPickerDateRange, RlsPickerDay, RlsPickerDayRange, RlsPickerMonth, RlsPickerSelectorTitle, RlsPickerYear, RlsPoster, RlsProgressBar, RlsProgressCircular, RlsRadioButton, RlsSkeleton, RlsSkeletonText, RlsSlider, RlsSnackbar, RlsSpinner, RlsSwitch, RlsSwitchControl, RlsTabs, RlsTabularText, RlsToolbar, calculateImgDimension, generateThemePalette, getAppTheme, hexIsValid, hexToHsl, hexToHsv, hexToRgb, hslToHex, hsvToHex, hsvToRgb, normalizeHex, rangeFormatTemplate, renderClassStatus, rgbToHex, rgbToHsl, rgbToHsv, setAppTheme, setDesignSystem, setErrorsI18n, setThemeColor, toggleAppTheme, useConfirmation, useDatatable, useDesingSystemController, useDropdownController, useFieldAutocomplete, useFieldList, useFieldSelect, useFormSingleSelectionController, useFormToggleController, useImageEditorController, useListController, useNotifications, usePortalController, useRelocationOnComponent, useResize, useRlsContext, useSnackbar, useTabsController };
5070
+ export { ConfirmationResult, DEFAULT_COLOR, RlsAccordion, RlsAlert, RlsAmount, RlsApplication, RlsAreaText, RlsAvatar, RlsBadge, RlsBallot, RlsBody, RlsBottomSheet, RlsBreadcrumb, RlsButton, RlsButtonAction, RlsButtonIcon, RlsButtonOption, RlsButtonProgress, RlsButtonStepper, RlsButtonToggle, RlsCard, RlsCheckBox, RlsCheckBoxControl, RlsChooserAutocomplete, RlsChooserAutocompleteTemplate, RlsChooserList, RlsChooserListTemplate, RlsChooserSelect, RlsChooserSelectTemplate, RlsConfirmation, RlsContent, RlsContext, RlsDatatable, RlsDatatableCell, RlsDatatableData, RlsDatatableFloating, RlsDatatableHeader, RlsDatatableRecord, RlsDatatableSubheader, RlsDatatableTitle, RlsDatatableTotals, RlsDropdown, RlsFieldArea, RlsFieldAutocomplete, RlsFieldAutocompleteTemplate, RlsFieldClock, RlsFieldColor, RlsFieldDate, RlsFieldDateRange, RlsFieldDecimal, RlsFieldFile, RlsFieldList, RlsFieldListSuggestions, RlsFieldListTemplate, RlsFieldMoney, RlsFieldNumber, RlsFieldPassword, RlsFieldPercentage, RlsFieldReadonly, RlsFieldSelect, RlsFieldSelectTemplate, RlsFieldText, RlsFormNavigation, RlsIcon, RlsImage, RlsImageChooser, RlsImageEditor, RlsInput, RlsInputCounter, RlsInputDecimal, RlsInputMoney, RlsInputNumber, RlsInputPassword, RlsInputPercentage, RlsInputSearch, RlsInputText, RlsLabel, RlsLabelCheckBox, RlsLabelRadioButton, RlsLabelSwitch, RlsLed, RlsMessageEmpty, RlsMessageFormError, RlsMessageIcon, RlsModal, RlsModalClock, RlsModalDate, RlsModalDateRange, RlsModalSheet, RlsNavbar, RlsNavbarMenu, RlsPagination, RlsPickerClock, RlsPickerColor, RlsPickerDate, RlsPickerDateRange, RlsPickerDay, RlsPickerDayRange, RlsPickerMonth, RlsPickerSelectorTitle, RlsPickerYear, RlsPoster, RlsProgressBar, RlsProgressCircular, RlsRadioButton, RlsSkeleton, RlsSkeletonText, RlsSlider, RlsSnackbar, RlsSpinner, RlsSwitch, RlsSwitchControl, RlsTabs, RlsTabularText, RlsToolbar, calculateImgDimension, generateThemePalette, getAppTheme, hexIsValid, hexToHsl, hexToHsv, hexToRgb, hslToHex, hsvToHex, hsvToRgb, normalizeHex, rangeFormatTemplate, renderClassStatus, rgbToHex, rgbToHsl, rgbToHsv, setAppTheme, setDesignSystem, setErrorsI18n, setThemeColor, toggleAppTheme, useConfirmation, useDatatable, useDesingSystemController, useDropdownController, useFieldAutocomplete, useFieldList, useFieldSelect, useFormSingleSelectionController, useFormToggleController, useImageEditorController, useListController, useNotifications, usePortalController, useRelocationOnComponent, useResize, useRlsContext, useSnackbar, useTabsController };
4828
5071
  //# sourceMappingURL=index.mjs.map