@rolster/react-components 19.7.13 → 19.8.16

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 (46) hide show
  1. package/LICENSE +21 -21
  2. package/dist/cjs/index.cjs +791 -542
  3. package/dist/cjs/index.cjs.map +1 -1
  4. package/dist/es/index.mjs +788 -545
  5. package/dist/es/index.mjs.map +1 -1
  6. package/dist/esm/components/atoms/Label/Label.js.map +1 -1
  7. package/dist/esm/components/molecules/Content/Content.js.map +1 -1
  8. package/dist/esm/components/molecules/FieldListSuggestions/FieldListSuggestions.d.ts +4 -1
  9. package/dist/esm/components/molecules/FieldListSuggestions/FieldListSuggestions.js +7 -2
  10. package/dist/esm/components/molecules/FieldListSuggestions/FieldListSuggestions.js.map +1 -1
  11. package/dist/esm/components/molecules/FieldListSuggestions/SuggestionsPortalController.d.ts +8 -0
  12. package/dist/esm/components/molecules/FieldListSuggestions/SuggestionsPortalController.js +84 -0
  13. package/dist/esm/components/molecules/FieldListSuggestions/SuggestionsPortalController.js.map +1 -0
  14. package/dist/esm/components/organisms/ChooserAutocomplete/ChooserAutocomplete.d.ts +36 -0
  15. package/dist/esm/components/organisms/ChooserAutocomplete/ChooserAutocomplete.js +87 -0
  16. package/dist/esm/components/organisms/ChooserAutocomplete/ChooserAutocomplete.js.map +1 -0
  17. package/dist/esm/components/organisms/ChooserList/ChooserList.d.ts +27 -0
  18. package/dist/esm/components/organisms/ChooserList/ChooserList.js +44 -0
  19. package/dist/esm/components/organisms/ChooserList/ChooserList.js.map +1 -0
  20. package/dist/esm/components/organisms/ChooserSelect/ChooserSelect.d.ts +31 -0
  21. package/dist/esm/components/organisms/ChooserSelect/ChooserSelect.js +38 -0
  22. package/dist/esm/components/organisms/ChooserSelect/ChooserSelect.js.map +1 -0
  23. package/dist/esm/components/organisms/FieldAutocomplete/FieldAutocomplete.js +1 -1
  24. package/dist/esm/components/organisms/FieldAutocomplete/FieldAutocomplete.js.map +1 -1
  25. package/dist/esm/components/organisms/FieldList/FieldList.js +1 -1
  26. package/dist/esm/components/organisms/FieldList/FieldList.js.map +1 -1
  27. package/dist/esm/components/organisms/FieldList/FieldListController.d.ts +1 -0
  28. package/dist/esm/components/organisms/FieldList/FieldListController.js +4 -1
  29. package/dist/esm/components/organisms/FieldList/FieldListController.js.map +1 -1
  30. package/dist/esm/components/organisms/FieldSelect/FieldSelect.js +1 -1
  31. package/dist/esm/components/organisms/FieldSelect/FieldSelect.js.map +1 -1
  32. package/dist/esm/components/organisms/ImageEditor/ImageEditor.js.map +1 -1
  33. package/dist/esm/controllers/DropdownController.js.map +1 -1
  34. package/dist/esm/controllers/ListController.d.ts +1 -0
  35. package/dist/esm/controllers/ListController.js +31 -25
  36. package/dist/esm/controllers/ListController.js.map +1 -1
  37. package/dist/esm/controllers/RelocationOnComponentController.d.ts +4 -4
  38. package/dist/esm/controllers/RelocationOnComponentController.js +34 -32
  39. package/dist/esm/controllers/RelocationOnComponentController.js.map +1 -1
  40. package/dist/esm/controllers/ResizeController.js +5 -7
  41. package/dist/esm/controllers/ResizeController.js.map +1 -1
  42. package/dist/esm/definitions.d.ts +1 -0
  43. package/dist/esm/index.d.ts +3 -0
  44. package/dist/esm/index.js +3 -0
  45. package/dist/esm/index.js.map +1 -1
  46. 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: {}};
@@ -1636,6 +1636,89 @@ const reactI18n = i18n({
1636
1636
  }
1637
1637
  });
1638
1638
 
1639
+ function getScrollableAncestors(element) {
1640
+ const ancestors = [];
1641
+ let parent = element.parentElement;
1642
+ while (parent && parent !== document.body) {
1643
+ const { overflow, overflowX, overflowY } = getComputedStyle(parent);
1644
+ if (/auto|scroll|hidden/.test(`${overflow}${overflowX}${overflowY}`)) {
1645
+ ancestors.push(parent);
1646
+ }
1647
+ parent = parent.parentElement;
1648
+ }
1649
+ return ancestors;
1650
+ }
1651
+ function anchorIsVisible(rect, scrollables) {
1652
+ if (!rect.width || !rect.height) {
1653
+ return false;
1654
+ }
1655
+ let top = 0;
1656
+ let left = 0;
1657
+ let bottom = window.innerHeight;
1658
+ let right = window.innerWidth;
1659
+ for (const scrollable of scrollables) {
1660
+ const scrollableRect = scrollable.getBoundingClientRect();
1661
+ top = Math.max(top, scrollableRect.top);
1662
+ left = Math.max(left, scrollableRect.left);
1663
+ bottom = Math.min(bottom, scrollableRect.bottom);
1664
+ right = Math.min(right, scrollableRect.right);
1665
+ }
1666
+ return (rect.bottom > top &&
1667
+ rect.top < bottom &&
1668
+ rect.right > left &&
1669
+ rect.left < right);
1670
+ }
1671
+ function useSuggestionsPortalController(visible, refAnchor, onHiddenAnchor) {
1672
+ const [mounted, setMounted] = useState(false);
1673
+ const [style, setStyle] = useState();
1674
+ const [theme, setTheme] = useState();
1675
+ useEffect(() => {
1676
+ setMounted(true);
1677
+ }, []);
1678
+ const onAnchorHidden = useEffectEvent(() => {
1679
+ onHiddenAnchor?.();
1680
+ });
1681
+ useEffect(() => {
1682
+ const anchor = refAnchor?.current;
1683
+ if (!mounted || !visible || !anchor) {
1684
+ return;
1685
+ }
1686
+ setTheme((anchor.closest('[rls-theme]')?.getAttribute('rls-theme') ??
1687
+ undefined));
1688
+ const scrollables = getScrollableAncestors(anchor);
1689
+ let frame = 0;
1690
+ function reposition() {
1691
+ if (!anchor) {
1692
+ return;
1693
+ }
1694
+ const rect = anchor.getBoundingClientRect();
1695
+ if (!anchorIsVisible(rect, scrollables)) {
1696
+ onAnchorHidden();
1697
+ return;
1698
+ }
1699
+ setStyle({
1700
+ '--pvt-portal-top': `${rect.bottom}px`,
1701
+ '--pvt-portal-bottom': `${window.innerHeight - rect.top}px`,
1702
+ '--pvt-portal-left': `${rect.left}px`,
1703
+ '--pvt-portal-width': `${rect.width}px`
1704
+ });
1705
+ }
1706
+ function requestReposition() {
1707
+ cancelAnimationFrame(frame);
1708
+ frame = requestAnimationFrame(reposition);
1709
+ }
1710
+ reposition();
1711
+ window.addEventListener('scroll', requestReposition, true);
1712
+ window.addEventListener('resize', requestReposition);
1713
+ return () => {
1714
+ cancelAnimationFrame(frame);
1715
+ window.removeEventListener('scroll', requestReposition, true);
1716
+ window.removeEventListener('resize', requestReposition);
1717
+ };
1718
+ }, [mounted, visible, refAnchor]);
1719
+ return { active: mounted && !!refAnchor, style, theme };
1720
+ }
1721
+
1639
1722
  function RlsFieldListLi({ element, onClickElement, onKeydownElement, render }) {
1640
1723
  const onClick = useMemo(() => {
1641
1724
  return onClickElement(element);
@@ -1645,7 +1728,8 @@ function RlsFieldListLi({ element, onClickElement, onKeydownElement, render }) {
1645
1728
  }, [element, onKeydownElement]);
1646
1729
  return (jsxRuntimeExports.jsx("li", { className: "rls-field-list__element", tabIndex: -1, onClick: onClick, onKeyDown: onKeyDown, children: render(element) }));
1647
1730
  }
1648
- function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher, render, renderEmpty, searchControl, visible, onClickBackdrop, onClickElement, onKeydownElement, refList, rlsTheme }) {
1731
+ function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher, render, renderEmpty, searchControl, visible, onClickBackdrop, onClickElement, onHiddenAnchor, onKeydownElement, refAnchor, refList, refSuggestions, rlsTheme }) {
1732
+ const portal = useSuggestionsPortalController(visible, refAnchor, onHiddenAnchor);
1649
1733
  const [labels, setLabels] = useState({
1650
1734
  listEmptyDescription: reactI18n('listEmptyDescription'),
1651
1735
  listEmptyTitle: reactI18n('listEmptyTitle')
@@ -1661,6 +1745,7 @@ function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher,
1661
1745
  const className = renderClassStatus('rls-field-list__suggestions', {
1662
1746
  disabled,
1663
1747
  higher,
1748
+ portal: portal.active,
1664
1749
  visible
1665
1750
  });
1666
1751
  const onChangePattern = useCallback((event) => {
@@ -1673,7 +1758,8 @@ function RlsFieldListSuggestionsComponent({ elements, action, disabled, higher,
1673
1758
  }
1674
1759
  }, [action?.onClick, action?.keepOpen, onClickBackdrop]);
1675
1760
  const searching = searchControl?.searching ?? false;
1676
- 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 })] }));
1761
+ 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 })] }));
1762
+ return portal.active ? createPortal(suggestions, document.body) : suggestions;
1677
1763
  }
1678
1764
  const RlsFieldListSuggestions = memo(RlsFieldListSuggestionsComponent);
1679
1765
 
@@ -2375,161 +2461,6 @@ function RlsCardComponent({ children, className, outline, rlsTheme }) {
2375
2461
  }
2376
2462
  const RlsCard = memo(RlsCardComponent);
2377
2463
 
2378
- class ConfirmationResult extends SealedPartial {
2379
- static approved() {
2380
- return new ConfirmationResult('approved');
2381
- }
2382
- static reject() {
2383
- return new ConfirmationResult('reject');
2384
- }
2385
- }
2386
- function RlsConfirmationComponent({ approved, className, content, reject, rlsTheme, subtitle, title, visible }) {
2387
- const classConfirmation = renderClassStatus('rls-confirmation', { visible }, className);
2388
- 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" })] }));
2389
- }
2390
- const RlsConfirmation = memo(RlsConfirmationComponent);
2391
- const RlsConfirmationBase = RlsConfirmation;
2392
- function useConfirmation() {
2393
- const [config, setConfig] = useState({});
2394
- const [visible, setVisible] = useState(false);
2395
- const configRef = useRef(config);
2396
- configRef.current = config;
2397
- const visibleRef = useRef(visible);
2398
- visibleRef.current = visible;
2399
- const RlsConfirmation = useMemo(() => {
2400
- return function RlsConfirmation(props) {
2401
- return ReactDOM.createPortal(jsxRuntimeExports.jsx(RlsConfirmationBase, { ...props, ...configRef.current, visible: visibleRef.current }), document.body);
2402
- };
2403
- }, []);
2404
- const confirmation = useCallback((options) => {
2405
- return new Promise((resolve) => {
2406
- setConfig({
2407
- ...options,
2408
- approved: {
2409
- label: options.approved?.label ?? reactI18n('confirmationActionApproved'),
2410
- onClick: () => {
2411
- setVisible(false);
2412
- resolve(ConfirmationResult.approved());
2413
- },
2414
- type: options.approved?.type ?? 'raised',
2415
- disabled: options.approved?.disabled,
2416
- identifier: options.approved?.identifier,
2417
- rlsTheme: options.approved?.rlsTheme
2418
- },
2419
- reject: options.reject
2420
- ? {
2421
- label: options.reject.label,
2422
- onClick: () => {
2423
- setVisible(false);
2424
- resolve(ConfirmationResult.reject());
2425
- },
2426
- type: options.reject.type ?? 'flat',
2427
- disabled: options.reject.disabled,
2428
- identifier: options.reject.identifier,
2429
- rlsTheme: options.reject.rlsTheme
2430
- }
2431
- : undefined
2432
- });
2433
- setVisible(true);
2434
- });
2435
- }, []);
2436
- return {
2437
- confirmation,
2438
- RlsConfirmation
2439
- };
2440
- }
2441
-
2442
- function createObserver(options) {
2443
- const { setScrolleable, table } = options;
2444
- const observer = new ResizeObserver(() => {
2445
- const scrollHeight = table.scrollHeight || 0;
2446
- const clientHeight = table.clientHeight || 0;
2447
- setScrolleable(scrollHeight > clientHeight);
2448
- });
2449
- observer.observe(table);
2450
- return observer;
2451
- }
2452
- function useDatatable(table) {
2453
- const [scrolleable, setScrolleable] = useState(false);
2454
- const refTable = useRef(table ? table : null);
2455
- useEffect(() => {
2456
- const observer = refTable.current &&
2457
- createObserver({ setScrolleable, table: refTable.current });
2458
- return () => {
2459
- observer?.disconnect();
2460
- };
2461
- }, []);
2462
- return { refTable, scrolleable };
2463
- }
2464
-
2465
- function RlsDatatableComponent({ children, footer, header, identifier, rlsTheme, resizable, summary, table, toolbar }) {
2466
- const datatable = useDatatable(table);
2467
- const className = renderClassStatus('rls-datatable', {
2468
- resizable,
2469
- scrolleable: resizable && datatable?.scrolleable
2470
- });
2471
- 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 })] }));
2472
- }
2473
- const RlsDatatable = memo(RlsDatatableComponent);
2474
- function RlsDatatableHeaderComponent({ children, identifier, rlsTheme }) {
2475
- return (jsxRuntimeExports.jsx("tr", { id: identifier, className: "rls-datatable__header", "rls-theme": rlsTheme, children: children }));
2476
- }
2477
- const RlsDatatableHeader = memo(RlsDatatableHeaderComponent);
2478
- function RlsDatatableTitleComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
2479
- const classNameTitle = renderClassStatus('rls-datatable__title', { actions, control, truncated }, className);
2480
- return (jsxRuntimeExports.jsx("th", { id: identifier, className: classNameTitle, "rls-theme": rlsTheme, children: children }));
2481
- }
2482
- const RlsDatatableTitle = memo(RlsDatatableTitleComponent);
2483
- function RlsDatatableSubheaderComponent({ children, className, identifier, rlsTheme }) {
2484
- const classNameSubheader = renderClassStatus('rls-datatable__subheader', {}, className);
2485
- return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameSubheader, "rls-theme": rlsTheme, children: children }));
2486
- }
2487
- const RlsDatatableSubheader = memo(RlsDatatableSubheaderComponent);
2488
- function RlsDatatableRecordComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
2489
- const classNameRecord = renderClassStatus('rls-datatable__record', { error, info, truncated, success, warning }, className);
2490
- return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameRecord, "rls-theme": rlsTheme, children: children }));
2491
- }
2492
- const RlsDatatableRecord = memo(RlsDatatableRecordComponent);
2493
- function RlsDatatableTotalsComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
2494
- const classNameTotals = renderClassStatus('rls-datatable__totals', { error, info, truncated, success, warning }, className);
2495
- return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameTotals, "rls-theme": rlsTheme, children: children }));
2496
- }
2497
- const RlsDatatableTotals = memo(RlsDatatableTotalsComponent);
2498
- function RlsDatatableCellComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
2499
- const classNameCell = renderClassStatus('rls-datatable__cell', { actions, control, truncated }, className);
2500
- return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameCell, "rls-theme": rlsTheme, children: children }));
2501
- }
2502
- const RlsDatatableCell = memo(RlsDatatableCellComponent);
2503
- function RlsDatatableDataComponent({ actions, children, className, control, identifier, truncated }) {
2504
- const classNameData = renderClassStatus('rls-datatable__data', { actions, control, truncated }, className);
2505
- return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameData, children: children }));
2506
- }
2507
- const RlsDatatableData = memo(RlsDatatableDataComponent);
2508
- function RlsDatatableFloatingComponent({ children, className, identifier, invested, rlsTheme }) {
2509
- const classNameFloating = renderClassStatus('rls-datatable__floating', { invested }, className);
2510
- return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameFloating, "rls-theme": rlsTheme, children: children }));
2511
- }
2512
- const RlsDatatableFloating = memo(RlsDatatableFloatingComponent);
2513
-
2514
- function RlsDropdownComponent({ children, controller, rlsTheme }) {
2515
- const className = renderClassStatus('rls-dropdown', {
2516
- visible: controller.visible
2517
- });
2518
- useEffect(() => {
2519
- function onCloseDropdown({ target }) {
2520
- if (!controller.component.current.contains(target)) {
2521
- controller.close();
2522
- }
2523
- }
2524
- document.addEventListener('click', onCloseDropdown);
2525
- return () => {
2526
- document.removeEventListener('click', onCloseDropdown);
2527
- };
2528
- }, []);
2529
- return (jsxRuntimeExports.jsx("div", { ref: controller.component, className: className, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-dropdown__content", children: children }) }));
2530
- }
2531
- const RlsDropdown = memo(RlsDropdownComponent);
2532
-
2533
2464
  const MAX_LIST_HEIGHT_REM$1 = 90;
2534
2465
  const FALLBACK_REM_SIZE$1 = 16;
2535
2466
  function getRemSize$1() {
@@ -2571,6 +2502,7 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2571
2502
  const refContent = useRef(null);
2572
2503
  const refList = useRef(null);
2573
2504
  const refInput = useRef(null);
2505
+ const refSuggestions = useRef(null);
2574
2506
  const listIsOpen = useRef(false);
2575
2507
  const stableSuggestions = useStableSuggestions(suggestions);
2576
2508
  const collection = useMemo(() => new ListCollection(stableSuggestions, reference), [stableSuggestions, reference]);
@@ -2585,7 +2517,8 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2585
2517
  const valueProtected = useRef(undefined);
2586
2518
  useEffect(() => {
2587
2519
  function onCloseSuggestions({ target }) {
2588
- if (!refContent?.current?.contains(target)) {
2520
+ if (!refContent?.current?.contains(target) &&
2521
+ !refSuggestions?.current?.contains(target)) {
2589
2522
  refreshState((state) => ({ ...state, listIsVisible: false }));
2590
2523
  }
2591
2524
  }
@@ -2602,7 +2535,29 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2602
2535
  formControl?.touch();
2603
2536
  }
2604
2537
  }, [state.listIsVisible]);
2605
- useEffect(() => {
2538
+ const setState = useCallback((state) => {
2539
+ const newState = state.listIsVisible
2540
+ ? {
2541
+ ...state,
2542
+ higher: shouldDisplayHigher$1(refContent.current, refList.current)
2543
+ }
2544
+ : state;
2545
+ refreshState((currentState) => ({ ...currentState, ...newState }));
2546
+ }, []);
2547
+ const setFormValue = useCallback((element, valueIsDefault = false) => {
2548
+ refreshState((state) => ({
2549
+ ...state,
2550
+ value: element?.description || ''
2551
+ }));
2552
+ changeValueInternal.current = true;
2553
+ if (valueIsDefault) {
2554
+ formControl?.setDefaultValue(element?.value);
2555
+ }
2556
+ else {
2557
+ formControl?.setValue(element?.value);
2558
+ }
2559
+ }, [formControl]);
2560
+ const reconcileFormValue = useEffectEvent(() => {
2606
2561
  if (!changeValueInternal.current) {
2607
2562
  if (formControl?.value) {
2608
2563
  const element = collection.find(formControl.value);
@@ -2638,29 +2593,10 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2638
2593
  }
2639
2594
  }
2640
2595
  changeValueInternal.current = false;
2596
+ });
2597
+ useEffect(() => {
2598
+ reconcileFormValue();
2641
2599
  }, [collection, formControl?.value]);
2642
- const setState = useCallback((state) => {
2643
- const newState = state.listIsVisible
2644
- ? {
2645
- ...state,
2646
- higher: shouldDisplayHigher$1(refContent.current, refList.current)
2647
- }
2648
- : state;
2649
- refreshState((currentState) => ({ ...currentState, ...newState }));
2650
- }, []);
2651
- const setFormValue = useCallback((element, valueIsDefault = false) => {
2652
- refreshState((state) => ({
2653
- ...state,
2654
- value: element?.description || ''
2655
- }));
2656
- changeValueInternal.current = true;
2657
- if (valueIsDefault) {
2658
- formControl?.setDefaultValue(element?.value);
2659
- }
2660
- else {
2661
- formControl?.setValue(element?.value);
2662
- }
2663
- }, [formControl]);
2664
2600
  const navigationInput = useCallback((event) => {
2665
2601
  if (state.listIsVisible) {
2666
2602
  const newPosition = navigationListFromInput({
@@ -2689,6 +2625,7 @@ function useListController({ suggestions, automatic, formControl, reference }) {
2689
2625
  refContent,
2690
2626
  refInput,
2691
2627
  refList,
2628
+ refSuggestions,
2692
2629
  setFormValue,
2693
2630
  setState
2694
2631
  }), [state, navigationElement, navigationInput, setFormValue, setState]);
@@ -2850,9 +2787,9 @@ function useFieldAutocomplete(props) {
2850
2787
  ]);
2851
2788
  }
2852
2789
 
2853
- function RlsFieldAutocompleteTemplateComponent(props) {
2790
+ function RlsChooserAutocompleteTemplateComponent(props) {
2854
2791
  const autocomplete = useFieldAutocomplete(props);
2855
- const { render, action, children, formControl, msgErrorDisabled, onSearch, placeholder, rlsTheme, searching } = props;
2792
+ const { render, action, children, formControl, onSearch, rlsTheme, searching } = props;
2856
2793
  const [listInputPlaceholder, setListInputPlaceholder] = useState(reactI18n('listInputPlaceholder'));
2857
2794
  useEffect(() => {
2858
2795
  return i18nSubscribe(() => {
@@ -2865,13 +2802,11 @@ function RlsFieldAutocompleteTemplateComponent(props) {
2865
2802
  const disabled = useMemo(() => {
2866
2803
  return formControl?.disabled || props.disabled;
2867
2804
  }, [formControl?.disabled, props.disabled]);
2868
- const className = renderClassStatus('rls-field-box', {
2805
+ const className = renderClassStatus('rls-chooser', {
2869
2806
  focused: autocomplete.focused && !disabled,
2870
- error: formControl?.wrong,
2871
- disabled,
2872
- readonly: props.readOnly,
2873
- selected: !!autocomplete.value
2874
- }, `rls-field-list rls-field-autocomplete ${props.className ?? ''}`);
2807
+ visible: autocomplete.listIsVisible,
2808
+ disabled
2809
+ }, `rls-chooser-autocomplete ${props.className ?? ''}`);
2875
2810
  const onClickPattern = useCallback(() => {
2876
2811
  onSearch?.(autocomplete.pattern);
2877
2812
  }, [onSearch, autocomplete.pattern]);
@@ -2881,6 +2816,18 @@ function RlsFieldAutocompleteTemplateComponent(props) {
2881
2816
  }
2882
2817
  autocomplete.onKeydownInput(event);
2883
2818
  }, [autocomplete.onKeydownInput, onSearch, autocomplete.pattern]);
2819
+ const onKeydownTrigger = useCallback((event) => {
2820
+ switch (event.code) {
2821
+ case 'Space':
2822
+ case 'Enter':
2823
+ event.preventDefault();
2824
+ autocomplete.onClickControl();
2825
+ break;
2826
+ case 'Escape':
2827
+ autocomplete.onClickBackdrop();
2828
+ break;
2829
+ }
2830
+ }, [autocomplete.onClickControl, autocomplete.onClickBackdrop]);
2884
2831
  const searchControl = useMemo(() => ({
2885
2832
  pattern: autocomplete.pattern,
2886
2833
  placeholder: listInputPlaceholder,
@@ -2903,26 +2850,584 @@ function RlsFieldAutocompleteTemplateComponent(props) {
2903
2850
  onClickPattern,
2904
2851
  onSearch
2905
2852
  ]);
2906
- 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 })] }));
2907
- }
2908
- const RlsFieldAutocompleteTemplate = memo(RlsFieldAutocompleteTemplateComponent);
2909
- function RlsFieldAutocompleteComponent(props) {
2853
+ 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'
2854
+ ? children({
2855
+ description: autocomplete.value,
2856
+ listIsVisible: autocomplete.listIsVisible,
2857
+ pattern: autocomplete.pattern,
2858
+ value: formControl?.value ?? props.value
2859
+ })
2860
+ : 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 })] }));
2861
+ }
2862
+ const RlsChooserAutocompleteTemplate = memo(RlsChooserAutocompleteTemplateComponent);
2863
+ function RlsChooserAutocompleteComponent(props) {
2910
2864
  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 }) })), []);
2911
- return jsxRuntimeExports.jsx(RlsFieldAutocompleteTemplate, { ...props, render: render });
2865
+ return jsxRuntimeExports.jsx(RlsChooserAutocompleteTemplate, { ...props, render: render });
2912
2866
  }
2913
- const RlsFieldAutocomplete = memo(RlsFieldAutocompleteComponent);
2867
+ const RlsChooserAutocomplete = memo(RlsChooserAutocompleteComponent);
2914
2868
 
2915
- function RlsModalComponent({ autoclose, children, className, controller, onBackdrop, visible, rlsTheme }) {
2916
- const classNameModal = renderClassStatus('rls-modal', { visible: controller?.visible ?? visible }, className);
2917
- const onClickBackdrop = useCallback(() => {
2918
- if (autoclose) {
2919
- controller?.close();
2920
- }
2921
- onBackdrop?.();
2922
- }, [autoclose, controller, onBackdrop]);
2923
- 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);
2924
- }
2925
- const RlsModal = memo(RlsModalComponent);
2869
+ const MAX_LIST_HEIGHT_REM = 90;
2870
+ const FALLBACK_REM_SIZE = 16;
2871
+ function getRemSize() {
2872
+ if (typeof window === 'undefined') {
2873
+ return FALLBACK_REM_SIZE;
2874
+ }
2875
+ const fontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
2876
+ return fontSize > 0 ? fontSize : FALLBACK_REM_SIZE;
2877
+ }
2878
+ function shouldDisplayHigher(content, list) {
2879
+ if (!content) {
2880
+ return false;
2881
+ }
2882
+ const { top, bottom } = content.getBoundingClientRect();
2883
+ const spaceAbove = top;
2884
+ const spaceBelow = window.innerHeight - bottom;
2885
+ const maxHeight = MAX_LIST_HEIGHT_REM * getRemSize();
2886
+ const desiredHeight = Math.min(list?.scrollHeight || maxHeight, maxHeight);
2887
+ if (spaceBelow >= desiredHeight) {
2888
+ return false;
2889
+ }
2890
+ if (spaceAbove >= desiredHeight) {
2891
+ return true;
2892
+ }
2893
+ return spaceAbove > spaceBelow;
2894
+ }
2895
+ function useFieldList(props) {
2896
+ const { suggestions, disabled } = props;
2897
+ const refContent = useRef(null);
2898
+ const refList = useRef(null);
2899
+ const refSuggestions = useRef(null);
2900
+ const formControl = props.formControl;
2901
+ const [state, setState] = useState({
2902
+ higher: false,
2903
+ listIsVisible: false
2904
+ });
2905
+ const [selected, setSelected] = useState([]);
2906
+ useEffect(() => {
2907
+ function onCloseSuggestions({ target }) {
2908
+ if (!refContent?.current?.contains(target) &&
2909
+ !refSuggestions?.current?.contains(target)) {
2910
+ setState((state) => ({ ...state, listIsVisible: false }));
2911
+ }
2912
+ }
2913
+ document.addEventListener('click', onCloseSuggestions);
2914
+ return () => {
2915
+ document.removeEventListener('click', onCloseSuggestions);
2916
+ };
2917
+ }, []);
2918
+ useEffect(() => {
2919
+ const formValue = formControl?.value;
2920
+ if (formValue !== undefined && formValue !== null && formValue.length) {
2921
+ setSelected(suggestions.filter((state) => formValue.some((value) => state.compareTo(value))));
2922
+ }
2923
+ else {
2924
+ setSelected([]);
2925
+ }
2926
+ }, [formControl?.value, suggestions]);
2927
+ const setListState = useCallback((controllerState) => {
2928
+ setState((state) => {
2929
+ const newState = controllerState.listIsVisible !== undefined
2930
+ ? {
2931
+ ...controllerState,
2932
+ ...(controllerState.listIsVisible
2933
+ ? {
2934
+ higher: shouldDisplayHigher(refContent.current, refList.current)
2935
+ }
2936
+ : {})
2937
+ }
2938
+ : controllerState;
2939
+ return { ...state, ...newState };
2940
+ });
2941
+ }, []);
2942
+ const toggleElement = useCallback((element) => {
2943
+ const alreadySelected = selected.some((state) => state.compareTo(element.value));
2944
+ const newSelected = alreadySelected
2945
+ ? selected.filter((state) => !state.compareTo(element.value))
2946
+ : [...selected, element];
2947
+ const newValues = newSelected.map((state) => state.value);
2948
+ setSelected(newSelected);
2949
+ formControl?.setValue(newValues);
2950
+ props.onValue?.(newValues);
2951
+ }, [selected, formControl, props.onValue]);
2952
+ const isSelected = useCallback((element) => {
2953
+ return selected.some((state) => state.compareTo(element.value));
2954
+ }, [selected]);
2955
+ const onClickInput = useCallback(() => {
2956
+ if (!props.readOnly) {
2957
+ setListState({ listIsVisible: true });
2958
+ }
2959
+ }, [setListState, props.readOnly]);
2960
+ const onClickBackdrop = useCallback(() => {
2961
+ setListState({ listIsVisible: false });
2962
+ }, [setListState]);
2963
+ const onClickAction = useCallback(() => {
2964
+ if (!disabled && !props.readOnly) {
2965
+ setListState({ listIsVisible: !state.listIsVisible });
2966
+ }
2967
+ }, [disabled, props.readOnly, setListState, state.listIsVisible]);
2968
+ const onClickElement = useCallback((element) => {
2969
+ return () => {
2970
+ toggleElement(element);
2971
+ };
2972
+ }, [toggleElement]);
2973
+ const onRemoveElement = useCallback((element) => {
2974
+ return (event) => {
2975
+ event.stopPropagation();
2976
+ const newSelected = selected.filter((state) => !state.compareTo(element.value));
2977
+ const newValues = newSelected.map((state) => state.value);
2978
+ setSelected(newSelected);
2979
+ formControl?.setValue(newValues);
2980
+ props.onValue?.(newValues);
2981
+ };
2982
+ }, [selected, formControl, props.onValue]);
2983
+ const onKeydownElement = useCallback((element) => {
2984
+ return (event) => {
2985
+ if (event.code === 'Enter') {
2986
+ toggleElement(element);
2987
+ }
2988
+ };
2989
+ }, [toggleElement]);
2990
+ return useMemo(() => ({
2991
+ ...state,
2992
+ selected,
2993
+ refContent,
2994
+ refList,
2995
+ refSuggestions,
2996
+ isSelected,
2997
+ onClickAction,
2998
+ onClickBackdrop,
2999
+ onClickElement,
3000
+ onClickInput,
3001
+ onKeydownElement,
3002
+ onRemoveElement
3003
+ }), [
3004
+ state,
3005
+ selected,
3006
+ isSelected,
3007
+ onClickAction,
3008
+ onClickBackdrop,
3009
+ onClickElement,
3010
+ onClickInput,
3011
+ onKeydownElement,
3012
+ onRemoveElement
3013
+ ]);
3014
+ }
3015
+
3016
+ function RlsChooserListTemplateComponent(props) {
3017
+ const fieldList = useFieldList(props);
3018
+ const { render, suggestions, action, children, formControl, rlsTheme } = props;
3019
+ const disabled = useMemo(() => {
3020
+ return formControl?.disabled || props.disabled;
3021
+ }, [formControl?.disabled, props.disabled]);
3022
+ const className = renderClassStatus('rls-chooser', {
3023
+ visible: fieldList.listIsVisible,
3024
+ disabled
3025
+ }, `rls-chooser-list ${props.className ?? ''}`);
3026
+ const onKeydownTrigger = useCallback((event) => {
3027
+ switch (event.code) {
3028
+ case 'Space':
3029
+ case 'Enter':
3030
+ event.preventDefault();
3031
+ fieldList.onClickAction();
3032
+ break;
3033
+ case 'Escape':
3034
+ fieldList.onClickBackdrop();
3035
+ break;
3036
+ }
3037
+ }, [fieldList.onClickAction, fieldList.onClickBackdrop]);
3038
+ 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]);
3039
+ 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'
3040
+ ? children({
3041
+ listIsVisible: fieldList.listIsVisible,
3042
+ selected: fieldList.selected
3043
+ })
3044
+ : 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 })] }));
3045
+ }
3046
+ const RlsChooserListTemplate = memo(RlsChooserListTemplateComponent);
3047
+ function RlsChooserListComponent(props) {
3048
+ 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 }) })), []);
3049
+ return jsxRuntimeExports.jsx(RlsChooserListTemplate, { ...props, render: render });
3050
+ }
3051
+ const RlsChooserList = memo(RlsChooserListComponent);
3052
+
3053
+ function useFieldSelect(props) {
3054
+ const controller = useListController(props);
3055
+ useEffect(() => {
3056
+ if (props.disabled) {
3057
+ controller.setState({ focused: false });
3058
+ }
3059
+ }, [props.disabled]);
3060
+ const onFocusInput = useCallback(() => {
3061
+ controller.setState({ focused: true });
3062
+ }, [controller.setState]);
3063
+ const onBlurInput = useCallback(() => {
3064
+ controller.setState({ focused: false });
3065
+ }, [controller.setState]);
3066
+ const onClickInput = useCallback(() => {
3067
+ if (!props.readOnly) {
3068
+ controller.setState({ listIsVisible: true });
3069
+ }
3070
+ }, [controller.setState, props.readOnly]);
3071
+ const onKeydownInput = useCallback((event) => {
3072
+ switch (event.code) {
3073
+ case 'Space':
3074
+ case 'Enter':
3075
+ controller.setState({ listIsVisible: true });
3076
+ break;
3077
+ case 'Escape':
3078
+ case 'Tab':
3079
+ controller.setState({ listIsVisible: false });
3080
+ break;
3081
+ default:
3082
+ controller.navigationInput(event);
3083
+ break;
3084
+ }
3085
+ }, [controller.setState, controller.navigationInput]);
3086
+ const onClickAction = useCallback(() => {
3087
+ const removable = !props.unremovable && !!controller.value;
3088
+ if (removable) {
3089
+ controller.setState({ listIsVisible: false });
3090
+ controller.setFormValue(undefined);
3091
+ props.onValue?.(props.value);
3092
+ }
3093
+ else {
3094
+ const listIsVisible = !controller.listIsVisible;
3095
+ controller.setState({ listIsVisible });
3096
+ if (listIsVisible) {
3097
+ controller.refInput?.current?.focus();
3098
+ }
3099
+ }
3100
+ }, [
3101
+ controller.listIsVisible,
3102
+ controller.value,
3103
+ controller.setState,
3104
+ controller.setFormValue,
3105
+ props.unremovable,
3106
+ props.onValue
3107
+ ]);
3108
+ const onClickBackdrop = useCallback(() => {
3109
+ controller.setState({ listIsVisible: false });
3110
+ }, [controller.setState]);
3111
+ const onChange = useCallback((element) => {
3112
+ if (!props.disabled) {
3113
+ controller.refInput?.current?.focus();
3114
+ }
3115
+ if (props.onSelect) {
3116
+ controller.setState({ listIsVisible: false });
3117
+ if (element.value) {
3118
+ props.onSelect(element.value);
3119
+ }
3120
+ }
3121
+ else {
3122
+ controller.setFormValue(element);
3123
+ controller.setState({ listIsVisible: false });
3124
+ }
3125
+ props.onValue?.(element.value);
3126
+ }, [
3127
+ controller.setState,
3128
+ controller.setFormValue,
3129
+ props.onSelect,
3130
+ props.onValue,
3131
+ props.disabled
3132
+ ]);
3133
+ const onClickElement = useCallback((element) => {
3134
+ return () => {
3135
+ onChange(element);
3136
+ };
3137
+ }, [onChange]);
3138
+ const onKeydownElement = useCallback((element) => {
3139
+ return (event) => {
3140
+ if (event.code === 'Enter') {
3141
+ onChange(element);
3142
+ }
3143
+ else {
3144
+ controller.navigationElement(event);
3145
+ }
3146
+ };
3147
+ }, [onChange, controller.navigationElement]);
3148
+ return useMemo(() => ({
3149
+ ...controller,
3150
+ onBlurInput,
3151
+ onClickAction,
3152
+ onClickBackdrop,
3153
+ onClickInput,
3154
+ onClickElement,
3155
+ onFocusInput,
3156
+ onKeydownElement,
3157
+ onKeydownInput
3158
+ }), [
3159
+ controller,
3160
+ onBlurInput,
3161
+ onClickAction,
3162
+ onClickBackdrop,
3163
+ onClickInput,
3164
+ onClickElement,
3165
+ onFocusInput,
3166
+ onKeydownElement,
3167
+ onKeydownInput
3168
+ ]);
3169
+ }
3170
+
3171
+ function RlsChooserSelectTemplateComponent(props) {
3172
+ const select = useFieldSelect({ ...props, unremovable: true });
3173
+ const { render, suggestions, action, children, formControl, rlsTheme } = props;
3174
+ const disabled = useMemo(() => {
3175
+ return formControl?.disabled || props.disabled;
3176
+ }, [formControl?.disabled, props.disabled]);
3177
+ const className = renderClassStatus('rls-chooser', {
3178
+ focused: select.focused && !disabled,
3179
+ visible: select.listIsVisible,
3180
+ disabled
3181
+ }, `rls-chooser-select ${props.className ?? ''}`);
3182
+ const onKeydownTrigger = useCallback((event) => {
3183
+ if (event.code === 'Space') {
3184
+ event.preventDefault();
3185
+ }
3186
+ select.onKeydownInput(event);
3187
+ }, [select.onKeydownInput]);
3188
+ 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'
3189
+ ? children({
3190
+ description: select.value,
3191
+ listIsVisible: select.listIsVisible,
3192
+ value: formControl?.value ?? props.value
3193
+ })
3194
+ : 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 })] }));
3195
+ }
3196
+ const RlsChooserSelectTemplate = memo(RlsChooserSelectTemplateComponent);
3197
+ function RlsChooserSelectComponent(props) {
3198
+ 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 }) })), []);
3199
+ return jsxRuntimeExports.jsx(RlsChooserSelectTemplate, { ...props, render: render });
3200
+ }
3201
+ const RlsChooserSelect = memo(RlsChooserSelectComponent);
3202
+
3203
+ class ConfirmationResult extends SealedPartial {
3204
+ static approved() {
3205
+ return new ConfirmationResult('approved');
3206
+ }
3207
+ static reject() {
3208
+ return new ConfirmationResult('reject');
3209
+ }
3210
+ }
3211
+ function RlsConfirmationComponent({ approved, className, content, reject, rlsTheme, subtitle, title, visible }) {
3212
+ const classConfirmation = renderClassStatus('rls-confirmation', { visible }, className);
3213
+ 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" })] }));
3214
+ }
3215
+ const RlsConfirmation = memo(RlsConfirmationComponent);
3216
+ const RlsConfirmationBase = RlsConfirmation;
3217
+ function useConfirmation() {
3218
+ const [config, setConfig] = useState({});
3219
+ const [visible, setVisible] = useState(false);
3220
+ const configRef = useRef(config);
3221
+ configRef.current = config;
3222
+ const visibleRef = useRef(visible);
3223
+ visibleRef.current = visible;
3224
+ const RlsConfirmation = useMemo(() => {
3225
+ return function RlsConfirmation(props) {
3226
+ return ReactDOM.createPortal(jsxRuntimeExports.jsx(RlsConfirmationBase, { ...props, ...configRef.current, visible: visibleRef.current }), document.body);
3227
+ };
3228
+ }, []);
3229
+ const confirmation = useCallback((options) => {
3230
+ return new Promise((resolve) => {
3231
+ setConfig({
3232
+ ...options,
3233
+ approved: {
3234
+ label: options.approved?.label ?? reactI18n('confirmationActionApproved'),
3235
+ onClick: () => {
3236
+ setVisible(false);
3237
+ resolve(ConfirmationResult.approved());
3238
+ },
3239
+ type: options.approved?.type ?? 'raised',
3240
+ disabled: options.approved?.disabled,
3241
+ identifier: options.approved?.identifier,
3242
+ rlsTheme: options.approved?.rlsTheme
3243
+ },
3244
+ reject: options.reject
3245
+ ? {
3246
+ label: options.reject.label,
3247
+ onClick: () => {
3248
+ setVisible(false);
3249
+ resolve(ConfirmationResult.reject());
3250
+ },
3251
+ type: options.reject.type ?? 'flat',
3252
+ disabled: options.reject.disabled,
3253
+ identifier: options.reject.identifier,
3254
+ rlsTheme: options.reject.rlsTheme
3255
+ }
3256
+ : undefined
3257
+ });
3258
+ setVisible(true);
3259
+ });
3260
+ }, []);
3261
+ return {
3262
+ confirmation,
3263
+ RlsConfirmation
3264
+ };
3265
+ }
3266
+
3267
+ function createObserver(options) {
3268
+ const { setScrolleable, table } = options;
3269
+ const observer = new ResizeObserver(() => {
3270
+ const scrollHeight = table.scrollHeight || 0;
3271
+ const clientHeight = table.clientHeight || 0;
3272
+ setScrolleable(scrollHeight > clientHeight);
3273
+ });
3274
+ observer.observe(table);
3275
+ return observer;
3276
+ }
3277
+ function useDatatable(table) {
3278
+ const [scrolleable, setScrolleable] = useState(false);
3279
+ const refTable = useRef(table ? table : null);
3280
+ useEffect(() => {
3281
+ const observer = refTable.current &&
3282
+ createObserver({ setScrolleable, table: refTable.current });
3283
+ return () => {
3284
+ observer?.disconnect();
3285
+ };
3286
+ }, []);
3287
+ return { refTable, scrolleable };
3288
+ }
3289
+
3290
+ function RlsDatatableComponent({ children, footer, header, identifier, rlsTheme, resizable, summary, table, toolbar }) {
3291
+ const datatable = useDatatable(table);
3292
+ const className = renderClassStatus('rls-datatable', {
3293
+ resizable,
3294
+ scrolleable: resizable && datatable?.scrolleable
3295
+ });
3296
+ 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 })] }));
3297
+ }
3298
+ const RlsDatatable = memo(RlsDatatableComponent);
3299
+ function RlsDatatableHeaderComponent({ children, identifier, rlsTheme }) {
3300
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: "rls-datatable__header", "rls-theme": rlsTheme, children: children }));
3301
+ }
3302
+ const RlsDatatableHeader = memo(RlsDatatableHeaderComponent);
3303
+ function RlsDatatableTitleComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
3304
+ const classNameTitle = renderClassStatus('rls-datatable__title', { actions, control, truncated }, className);
3305
+ return (jsxRuntimeExports.jsx("th", { id: identifier, className: classNameTitle, "rls-theme": rlsTheme, children: children }));
3306
+ }
3307
+ const RlsDatatableTitle = memo(RlsDatatableTitleComponent);
3308
+ function RlsDatatableSubheaderComponent({ children, className, identifier, rlsTheme }) {
3309
+ const classNameSubheader = renderClassStatus('rls-datatable__subheader', {}, className);
3310
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameSubheader, "rls-theme": rlsTheme, children: children }));
3311
+ }
3312
+ const RlsDatatableSubheader = memo(RlsDatatableSubheaderComponent);
3313
+ function RlsDatatableRecordComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
3314
+ const classNameRecord = renderClassStatus('rls-datatable__record', { error, info, truncated, success, warning }, className);
3315
+ return (jsxRuntimeExports.jsx("tr", { id: identifier, className: classNameRecord, "rls-theme": rlsTheme, children: children }));
3316
+ }
3317
+ const RlsDatatableRecord = memo(RlsDatatableRecordComponent);
3318
+ function RlsDatatableTotalsComponent({ children, className, error, identifier, info, rlsTheme, success, truncated, warning }) {
3319
+ const classNameTotals = renderClassStatus('rls-datatable__totals', { error, info, truncated, success, warning }, className);
3320
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameTotals, "rls-theme": rlsTheme, children: children }));
3321
+ }
3322
+ const RlsDatatableTotals = memo(RlsDatatableTotalsComponent);
3323
+ function RlsDatatableCellComponent({ actions, children, className, control, identifier, rlsTheme, truncated }) {
3324
+ const classNameCell = renderClassStatus('rls-datatable__cell', { actions, control, truncated }, className);
3325
+ return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameCell, "rls-theme": rlsTheme, children: children }));
3326
+ }
3327
+ const RlsDatatableCell = memo(RlsDatatableCellComponent);
3328
+ function RlsDatatableDataComponent({ actions, children, className, control, identifier, truncated }) {
3329
+ const classNameData = renderClassStatus('rls-datatable__data', { actions, control, truncated }, className);
3330
+ return (jsxRuntimeExports.jsx("div", { id: identifier, className: classNameData, children: children }));
3331
+ }
3332
+ const RlsDatatableData = memo(RlsDatatableDataComponent);
3333
+ function RlsDatatableFloatingComponent({ children, className, identifier, invested, rlsTheme }) {
3334
+ const classNameFloating = renderClassStatus('rls-datatable__floating', { invested }, className);
3335
+ return (jsxRuntimeExports.jsx("td", { id: identifier, className: classNameFloating, "rls-theme": rlsTheme, children: children }));
3336
+ }
3337
+ const RlsDatatableFloating = memo(RlsDatatableFloatingComponent);
3338
+
3339
+ function RlsDropdownComponent({ children, controller, rlsTheme }) {
3340
+ const className = renderClassStatus('rls-dropdown', {
3341
+ visible: controller.visible
3342
+ });
3343
+ useEffect(() => {
3344
+ function onCloseDropdown({ target }) {
3345
+ if (!controller.component.current.contains(target)) {
3346
+ controller.close();
3347
+ }
3348
+ }
3349
+ document.addEventListener('click', onCloseDropdown);
3350
+ return () => {
3351
+ document.removeEventListener('click', onCloseDropdown);
3352
+ };
3353
+ }, []);
3354
+ return (jsxRuntimeExports.jsx("div", { ref: controller.component, className: className, "rls-theme": rlsTheme, children: jsxRuntimeExports.jsx("div", { className: "rls-dropdown__content", children: children }) }));
3355
+ }
3356
+ const RlsDropdown = memo(RlsDropdownComponent);
3357
+
3358
+ function RlsFieldAutocompleteTemplateComponent(props) {
3359
+ const autocomplete = useFieldAutocomplete(props);
3360
+ const { render, action, children, formControl, msgErrorDisabled, onSearch, placeholder, rlsTheme, searching } = props;
3361
+ const [listInputPlaceholder, setListInputPlaceholder] = useState(reactI18n('listInputPlaceholder'));
3362
+ useEffect(() => {
3363
+ return i18nSubscribe(() => {
3364
+ setListInputPlaceholder(reactI18n('listInputPlaceholder'));
3365
+ });
3366
+ }, []);
3367
+ useEffect(() => {
3368
+ props.onInput?.(autocomplete.pattern);
3369
+ }, [autocomplete.pattern, props.onInput]);
3370
+ const disabled = useMemo(() => {
3371
+ return formControl?.disabled || props.disabled;
3372
+ }, [formControl?.disabled, props.disabled]);
3373
+ const className = renderClassStatus('rls-field-box', {
3374
+ focused: autocomplete.focused && !disabled,
3375
+ error: formControl?.wrong,
3376
+ disabled,
3377
+ readonly: props.readOnly,
3378
+ selected: !!autocomplete.value
3379
+ }, `rls-field-list rls-field-autocomplete ${props.className ?? ''}`);
3380
+ const onClickPattern = useCallback(() => {
3381
+ onSearch?.(autocomplete.pattern);
3382
+ }, [onSearch, autocomplete.pattern]);
3383
+ const onKeyDownPattern = useCallback((event) => {
3384
+ if (event.key === 'Enter') {
3385
+ onSearch?.(autocomplete.pattern);
3386
+ }
3387
+ autocomplete.onKeydownInput(event);
3388
+ }, [autocomplete.onKeydownInput, onSearch, autocomplete.pattern]);
3389
+ const searchControl = useMemo(() => ({
3390
+ pattern: autocomplete.pattern,
3391
+ placeholder: listInputPlaceholder,
3392
+ searching,
3393
+ refInput: autocomplete.refInput,
3394
+ onChange: autocomplete.setPattern,
3395
+ onFocus: autocomplete.onFocusInput,
3396
+ onBlur: autocomplete.onBlurInput,
3397
+ onKeyDown: onKeyDownPattern,
3398
+ onSearch: onSearch ? onClickPattern : undefined
3399
+ }), [
3400
+ autocomplete.pattern,
3401
+ autocomplete.refInput,
3402
+ autocomplete.setPattern,
3403
+ autocomplete.onFocusInput,
3404
+ autocomplete.onBlurInput,
3405
+ listInputPlaceholder,
3406
+ searching,
3407
+ onKeyDownPattern,
3408
+ onClickPattern,
3409
+ onSearch
3410
+ ]);
3411
+ 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 })] }));
3412
+ }
3413
+ const RlsFieldAutocompleteTemplate = memo(RlsFieldAutocompleteTemplateComponent);
3414
+ function RlsFieldAutocompleteComponent(props) {
3415
+ 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 }) })), []);
3416
+ return jsxRuntimeExports.jsx(RlsFieldAutocompleteTemplate, { ...props, render: render });
3417
+ }
3418
+ const RlsFieldAutocomplete = memo(RlsFieldAutocompleteComponent);
3419
+
3420
+ function RlsModalComponent({ autoclose, children, className, controller, onBackdrop, visible, rlsTheme }) {
3421
+ const classNameModal = renderClassStatus('rls-modal', { visible: controller?.visible ?? visible }, className);
3422
+ const onClickBackdrop = useCallback(() => {
3423
+ if (autoclose) {
3424
+ controller?.close();
3425
+ }
3426
+ onBackdrop?.();
3427
+ }, [autoclose, controller, onBackdrop]);
3428
+ 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);
3429
+ }
3430
+ const RlsModal = memo(RlsModalComponent);
2926
3431
 
2927
3432
  function formatTime(value) {
2928
3433
  return String(value).padStart(2, '0');
@@ -3695,192 +4200,48 @@ function RlsFieldDateRangeComponent({ children, date, disabled: disabledProps, f
3695
4200
  const disabled = useMemo(() => {
3696
4201
  return formControl?.disabled || disabledProps;
3697
4202
  }, [formControl?.disabled, disabledProps]);
3698
- const className = renderClassStatus('rls-field-box', {
3699
- disabled,
3700
- readonly: readOnly
3701
- });
3702
- const dateRangeValue = useMemo(() => {
3703
- return formControl ? formControl.value : value;
3704
- }, [formControl?.value, value]);
3705
- const status = useMemo(() => {
3706
- return {
3707
- icon: dateRangeValue ? 'trash-2' : 'calendar',
3708
- valueInput: dateRangeValue ? rangeFormatTemplate(dateRangeValue) : ''
3709
- };
3710
- }, [dateRangeValue]);
3711
- const onClickInput = useCallback(() => {
3712
- if (!readOnly) {
3713
- setModalIsVisible(true);
3714
- }
3715
- }, [readOnly]);
3716
- const onChange = useCallback((value) => {
3717
- setValue(value);
3718
- onValue?.(value);
3719
- }, [onValue]);
3720
- const onClickAction = useCallback(() => {
3721
- if (dateRangeValue) {
3722
- formControl?.setValue(valueInitial);
3723
- formControl?.touch();
3724
- onChange(valueInitial);
3725
- }
3726
- else {
3727
- setModalIsVisible(true);
3728
- }
3729
- }, [dateRangeValue, formControl, valueInitial, onChange]);
3730
- const onCloseModal = useCallback((dateRange) => {
3731
- if (dateRange) {
3732
- onChange(dateRange);
3733
- }
3734
- formControl?.touch();
3735
- setModalIsVisible(false);
3736
- }, [formControl, onChange]);
3737
- 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 })] }));
3738
- }
3739
- const RlsFieldDateRange = memo(RlsFieldDateRangeComponent);
3740
-
3741
- const MAX_LIST_HEIGHT_REM = 90;
3742
- const FALLBACK_REM_SIZE = 16;
3743
- function getRemSize() {
3744
- if (typeof window === 'undefined') {
3745
- return FALLBACK_REM_SIZE;
3746
- }
3747
- const fontSize = parseFloat(getComputedStyle(document.documentElement).fontSize);
3748
- return fontSize > 0 ? fontSize : FALLBACK_REM_SIZE;
3749
- }
3750
- function shouldDisplayHigher(content, list) {
3751
- if (!content) {
3752
- return false;
3753
- }
3754
- const { top, bottom } = content.getBoundingClientRect();
3755
- const spaceAbove = top;
3756
- const spaceBelow = window.innerHeight - bottom;
3757
- const maxHeight = MAX_LIST_HEIGHT_REM * getRemSize();
3758
- const desiredHeight = Math.min(list?.scrollHeight || maxHeight, maxHeight);
3759
- if (spaceBelow >= desiredHeight) {
3760
- return false;
3761
- }
3762
- if (spaceAbove >= desiredHeight) {
3763
- return true;
3764
- }
3765
- return spaceAbove > spaceBelow;
3766
- }
3767
- function useFieldList(props) {
3768
- const { suggestions, disabled } = props;
3769
- const refContent = useRef(null);
3770
- const refList = useRef(null);
3771
- const formControl = props.formControl;
3772
- const [state, setState] = useState({
3773
- higher: false,
3774
- listIsVisible: false
3775
- });
3776
- const [selected, setSelected] = useState([]);
3777
- useEffect(() => {
3778
- function onCloseSuggestions({ target }) {
3779
- if (!refContent?.current?.contains(target)) {
3780
- setState((state) => ({ ...state, listIsVisible: false }));
3781
- }
3782
- }
3783
- document.addEventListener('click', onCloseSuggestions);
3784
- return () => {
3785
- document.removeEventListener('click', onCloseSuggestions);
4203
+ const className = renderClassStatus('rls-field-box', {
4204
+ disabled,
4205
+ readonly: readOnly
4206
+ });
4207
+ const dateRangeValue = useMemo(() => {
4208
+ return formControl ? formControl.value : value;
4209
+ }, [formControl?.value, value]);
4210
+ const status = useMemo(() => {
4211
+ return {
4212
+ icon: dateRangeValue ? 'trash-2' : 'calendar',
4213
+ valueInput: dateRangeValue ? rangeFormatTemplate(dateRangeValue) : ''
3786
4214
  };
3787
- }, []);
3788
- useEffect(() => {
3789
- const formValue = formControl?.value;
3790
- if (formValue !== undefined && formValue !== null && formValue.length) {
3791
- setSelected(suggestions.filter((state) => formValue.some((value) => state.compareTo(value))));
3792
- }
3793
- else {
3794
- setSelected([]);
3795
- }
3796
- }, [formControl?.value, suggestions]);
3797
- const setListState = useCallback((controllerState) => {
3798
- setState((state) => {
3799
- const newState = controllerState.listIsVisible !== undefined
3800
- ? {
3801
- ...controllerState,
3802
- ...(controllerState.listIsVisible
3803
- ? {
3804
- higher: shouldDisplayHigher(refContent.current, refList.current)
3805
- }
3806
- : {})
3807
- }
3808
- : controllerState;
3809
- return { ...state, ...newState };
3810
- });
3811
- }, []);
3812
- const toggleElement = useCallback((element) => {
3813
- const alreadySelected = selected.some((state) => state.compareTo(element.value));
3814
- const newSelected = alreadySelected
3815
- ? selected.filter((state) => !state.compareTo(element.value))
3816
- : [...selected, element];
3817
- const newValues = newSelected.map((state) => state.value);
3818
- setSelected(newSelected);
3819
- formControl?.setValue(newValues);
3820
- props.onValue?.(newValues);
3821
- }, [selected, formControl, props.onValue]);
3822
- const isSelected = useCallback((element) => {
3823
- return selected.some((state) => state.compareTo(element.value));
3824
- }, [selected]);
4215
+ }, [dateRangeValue]);
3825
4216
  const onClickInput = useCallback(() => {
3826
- if (!props.readOnly) {
3827
- setListState({ listIsVisible: true });
4217
+ if (!readOnly) {
4218
+ setModalIsVisible(true);
3828
4219
  }
3829
- }, [setListState, props.readOnly]);
3830
- const onClickBackdrop = useCallback(() => {
3831
- setListState({ listIsVisible: false });
3832
- }, [setListState]);
4220
+ }, [readOnly]);
4221
+ const onChange = useCallback((value) => {
4222
+ setValue(value);
4223
+ onValue?.(value);
4224
+ }, [onValue]);
3833
4225
  const onClickAction = useCallback(() => {
3834
- if (!disabled && !props.readOnly) {
3835
- setListState({ listIsVisible: !state.listIsVisible });
4226
+ if (dateRangeValue) {
4227
+ formControl?.setValue(valueInitial);
4228
+ formControl?.touch();
4229
+ onChange(valueInitial);
3836
4230
  }
3837
- }, [disabled, props.readOnly, setListState, state.listIsVisible]);
3838
- const onClickElement = useCallback((element) => {
3839
- return () => {
3840
- toggleElement(element);
3841
- };
3842
- }, [toggleElement]);
3843
- const onRemoveElement = useCallback((element) => {
3844
- return (event) => {
3845
- event.stopPropagation();
3846
- const newSelected = selected.filter((state) => !state.compareTo(element.value));
3847
- const newValues = newSelected.map((state) => state.value);
3848
- setSelected(newSelected);
3849
- formControl?.setValue(newValues);
3850
- props.onValue?.(newValues);
3851
- };
3852
- }, [selected, formControl, props.onValue]);
3853
- const onKeydownElement = useCallback((element) => {
3854
- return (event) => {
3855
- if (event.code === 'Enter') {
3856
- toggleElement(element);
3857
- }
3858
- };
3859
- }, [toggleElement]);
3860
- return useMemo(() => ({
3861
- ...state,
3862
- selected,
3863
- refContent,
3864
- refList,
3865
- isSelected,
3866
- onClickAction,
3867
- onClickBackdrop,
3868
- onClickElement,
3869
- onClickInput,
3870
- onKeydownElement,
3871
- onRemoveElement
3872
- }), [
3873
- state,
3874
- selected,
3875
- isSelected,
3876
- onClickAction,
3877
- onClickBackdrop,
3878
- onClickElement,
3879
- onClickInput,
3880
- onKeydownElement,
3881
- onRemoveElement
3882
- ]);
4231
+ else {
4232
+ setModalIsVisible(true);
4233
+ }
4234
+ }, [dateRangeValue, formControl, valueInitial, onChange]);
4235
+ const onCloseModal = useCallback((dateRange) => {
4236
+ if (dateRange) {
4237
+ onChange(dateRange);
4238
+ }
4239
+ formControl?.touch();
4240
+ setModalIsVisible(false);
4241
+ }, [formControl, onChange]);
4242
+ 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 })] }));
3883
4243
  }
4244
+ const RlsFieldDateRange = memo(RlsFieldDateRangeComponent);
3884
4245
 
3885
4246
  function RlsFieldListInner({ render, suggestions, action, children, formControl, fieldList, msgErrorDisabled, placeholder, rlsTheme, ...props }) {
3886
4247
  const disabled = useMemo(() => {
@@ -3893,7 +4254,7 @@ function RlsFieldListInner({ render, suggestions, action, children, formControl,
3893
4254
  readonly: props.readOnly
3894
4255
  }, `rls-field-list rls-field-list__multi ${props.className ?? ''}`);
3895
4256
  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]);
3896
- 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 })] }));
4257
+ 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 })] }));
3897
4258
  }
3898
4259
  function RlsFieldListTemplateComponent(props) {
3899
4260
  const fieldList = useFieldList(props);
@@ -3907,124 +4268,6 @@ function RlsFieldListComponent(props) {
3907
4268
  }
3908
4269
  const RlsFieldList = memo(RlsFieldListComponent);
3909
4270
 
3910
- function useFieldSelect(props) {
3911
- const controller = useListController(props);
3912
- useEffect(() => {
3913
- if (props.disabled) {
3914
- controller.setState({ focused: false });
3915
- }
3916
- }, [props.disabled]);
3917
- const onFocusInput = useCallback(() => {
3918
- controller.setState({ focused: true });
3919
- }, [controller.setState]);
3920
- const onBlurInput = useCallback(() => {
3921
- controller.setState({ focused: false });
3922
- }, [controller.setState]);
3923
- const onClickInput = useCallback(() => {
3924
- if (!props.readOnly) {
3925
- controller.setState({ listIsVisible: true });
3926
- }
3927
- }, [controller.setState, props.readOnly]);
3928
- const onKeydownInput = useCallback((event) => {
3929
- switch (event.code) {
3930
- case 'Space':
3931
- case 'Enter':
3932
- controller.setState({ listIsVisible: true });
3933
- break;
3934
- case 'Escape':
3935
- case 'Tab':
3936
- controller.setState({ listIsVisible: false });
3937
- break;
3938
- default:
3939
- controller.navigationInput(event);
3940
- break;
3941
- }
3942
- }, [controller.setState, controller.navigationInput]);
3943
- const onClickAction = useCallback(() => {
3944
- const removable = !props.unremovable && !!controller.value;
3945
- if (removable) {
3946
- controller.setState({ listIsVisible: false });
3947
- controller.setFormValue(undefined);
3948
- props.onValue?.(props.value);
3949
- }
3950
- else {
3951
- const listIsVisible = !controller.listIsVisible;
3952
- controller.setState({ listIsVisible });
3953
- if (listIsVisible) {
3954
- controller.refInput?.current?.focus();
3955
- }
3956
- }
3957
- }, [
3958
- controller.listIsVisible,
3959
- controller.value,
3960
- controller.setState,
3961
- controller.setFormValue,
3962
- props.unremovable,
3963
- props.onValue
3964
- ]);
3965
- const onClickBackdrop = useCallback(() => {
3966
- controller.setState({ listIsVisible: false });
3967
- }, [controller.setState]);
3968
- const onChange = useCallback((element) => {
3969
- if (!props.disabled) {
3970
- controller.refInput?.current?.focus();
3971
- }
3972
- if (props.onSelect) {
3973
- controller.setState({ listIsVisible: false });
3974
- if (element.value) {
3975
- props.onSelect(element.value);
3976
- }
3977
- }
3978
- else {
3979
- controller.setFormValue(element);
3980
- controller.setState({ listIsVisible: false });
3981
- }
3982
- props.onValue?.(element.value);
3983
- }, [
3984
- controller.setState,
3985
- controller.setFormValue,
3986
- props.onSelect,
3987
- props.onValue,
3988
- props.disabled
3989
- ]);
3990
- const onClickElement = useCallback((element) => {
3991
- return () => {
3992
- onChange(element);
3993
- };
3994
- }, [onChange]);
3995
- const onKeydownElement = useCallback((element) => {
3996
- return (event) => {
3997
- if (event.code === 'Enter') {
3998
- onChange(element);
3999
- }
4000
- else {
4001
- controller.navigationElement(event);
4002
- }
4003
- };
4004
- }, [onChange, controller.navigationElement]);
4005
- return useMemo(() => ({
4006
- ...controller,
4007
- onBlurInput,
4008
- onClickAction,
4009
- onClickBackdrop,
4010
- onClickInput,
4011
- onClickElement,
4012
- onFocusInput,
4013
- onKeydownElement,
4014
- onKeydownInput
4015
- }), [
4016
- controller,
4017
- onBlurInput,
4018
- onClickAction,
4019
- onClickBackdrop,
4020
- onClickInput,
4021
- onClickElement,
4022
- onFocusInput,
4023
- onKeydownElement,
4024
- onKeydownInput
4025
- ]);
4026
- }
4027
-
4028
4271
  function RlsFieldSelectTemplateComponent(props) {
4029
4272
  const select = useFieldSelect(props);
4030
4273
  const { render, suggestions, action, children, formControl, msgErrorDisabled, placeholder, rlsTheme, unremovable } = props;
@@ -4037,7 +4280,7 @@ function RlsFieldSelectTemplateComponent(props) {
4037
4280
  disabled: disabled,
4038
4281
  readonly: props.readOnly
4039
4282
  }, `rls-field-list rls-field-select ${props.className ?? ''}`);
4040
- 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 })] }));
4283
+ 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 })] }));
4041
4284
  }
4042
4285
  const RlsFieldSelectTemplate = memo(RlsFieldSelectTemplateComponent);
4043
4286
  function RlsFieldSelectComponent(props) {
@@ -4052,54 +4295,56 @@ function RlsFormNavigationComponent({ children, className, controller, visible,
4052
4295
  }
4053
4296
  const RlsFormNavigation = memo(RlsFormNavigationComponent);
4054
4297
 
4055
- function useRelocationOnComponent({ container, element, onDrag }) {
4298
+ function useRelocationOnComponent({ container: containerRef, element: elementRef, onDrag }) {
4056
4299
  const position = useRef({ x: 0, y: 0 });
4057
4300
  const dragOffset = useRef({ x: 0, y: 0 });
4058
4301
  const dragging = useRef(false);
4059
- const getClientX = useCallback((positionX) => {
4302
+ function getClientX(positionX) {
4060
4303
  let clientX = position.current.x + positionX - dragOffset.current.x;
4061
4304
  if (clientX < 0) {
4062
4305
  clientX = 0;
4063
4306
  }
4064
4307
  else {
4065
- const width = clientX + element.current.offsetWidth;
4066
- if (width > container.current.offsetWidth) {
4067
- clientX = container.current.offsetWidth - element.current.offsetWidth;
4308
+ const width = clientX + elementRef.current.offsetWidth;
4309
+ if (width > containerRef.current.offsetWidth) {
4310
+ clientX =
4311
+ containerRef.current.offsetWidth - elementRef.current.offsetWidth;
4068
4312
  }
4069
4313
  }
4070
4314
  return clientX;
4071
- }, []);
4072
- const getClientY = useCallback((positionY) => {
4315
+ }
4316
+ function getClientY(positionY) {
4073
4317
  let clientY = position.current.y + positionY - dragOffset.current.y;
4074
4318
  if (clientY < 0) {
4075
4319
  clientY = 0;
4076
4320
  }
4077
4321
  else {
4078
- const height = clientY + element.current.offsetHeight;
4079
- if (height > container.current.offsetHeight) {
4080
- clientY = container.current.offsetHeight - element.current.offsetHeight;
4322
+ const height = clientY + elementRef.current.offsetHeight;
4323
+ if (height > containerRef.current.offsetHeight) {
4324
+ clientY =
4325
+ containerRef.current.offsetHeight - elementRef.current.offsetHeight;
4081
4326
  }
4082
4327
  }
4083
4328
  return clientY;
4084
- }, []);
4085
- const start = useCallback((positionX, positionY) => {
4329
+ }
4330
+ const start = useEffectEvent((positionX, positionY) => {
4086
4331
  dragOffset.current = {
4087
4332
  x: positionX,
4088
4333
  y: positionY
4089
4334
  };
4090
4335
  position.current = {
4091
- x: element.current.offsetLeft,
4092
- y: element.current.offsetTop
4336
+ x: elementRef.current.offsetLeft,
4337
+ y: elementRef.current.offsetTop
4093
4338
  };
4094
4339
  dragging.current = true;
4095
- }, []);
4096
- const relocation = useCallback((positionX, positionY) => {
4340
+ });
4341
+ const relocation = useEffectEvent((positionX, positionY) => {
4097
4342
  const clientX = getClientX(positionX);
4098
4343
  const clientY = getClientY(positionY);
4099
- element.current.style.top = `${clientY}px`;
4100
- element.current.style.left = `${clientX}px`;
4344
+ elementRef.current.style.top = `${clientY}px`;
4345
+ elementRef.current.style.left = `${clientX}px`;
4101
4346
  onDrag?.();
4102
- }, []);
4347
+ });
4103
4348
  useEffect(() => {
4104
4349
  const mousedown = (event) => {
4105
4350
  start(event.clientX, event.clientY);
@@ -4127,30 +4372,28 @@ function useRelocationOnComponent({ container, element, onDrag }) {
4127
4372
  const touchend = () => {
4128
4373
  dragging.current = false;
4129
4374
  };
4130
- element.current.addEventListener('mousedown', mousedown);
4131
- element.current.addEventListener('mousemove', mousemove);
4132
- element.current.addEventListener('mouseup', mouseup);
4133
- element.current.addEventListener('touchstart', touchstart);
4134
- element.current.addEventListener('touchmove', touchmove);
4135
- element.current.addEventListener('touchend', touchend);
4375
+ elementRef.current.addEventListener('mousedown', mousedown);
4376
+ elementRef.current.addEventListener('mousemove', mousemove);
4377
+ elementRef.current.addEventListener('mouseup', mouseup);
4378
+ elementRef.current.addEventListener('touchstart', touchstart);
4379
+ elementRef.current.addEventListener('touchmove', touchmove);
4380
+ elementRef.current.addEventListener('touchend', touchend);
4136
4381
  return () => {
4137
- element.current?.removeEventListener('mousedown', mousedown);
4138
- element.current?.removeEventListener('mousemove', mousemove);
4139
- element.current?.removeEventListener('mouseup', mouseup);
4140
- element.current?.removeEventListener('touchstart', touchstart);
4141
- element.current?.removeEventListener('touchmove', touchmove);
4142
- element.current?.removeEventListener('touchend', touchend);
4382
+ elementRef.current?.removeEventListener('mousedown', mousedown);
4383
+ elementRef.current?.removeEventListener('mousemove', mousemove);
4384
+ elementRef.current?.removeEventListener('mouseup', mouseup);
4385
+ elementRef.current?.removeEventListener('touchstart', touchstart);
4386
+ elementRef.current?.removeEventListener('touchmove', touchmove);
4387
+ elementRef.current?.removeEventListener('touchend', touchend);
4143
4388
  };
4144
4389
  }, []);
4145
4390
  }
4146
4391
 
4147
4392
  function useResize({ refElement, onResize }) {
4148
4393
  const dimension = useRef({ height: 0, width: 0 });
4149
- const onResizeRef = useRef(onResize);
4150
- onResizeRef.current = onResize;
4151
- const observer = useCallback((entries) => {
4394
+ const observer = useEffectEvent((entries) => {
4152
4395
  const { height, width } = entries[0].contentRect;
4153
- onResizeRef.current?.({
4396
+ onResize?.({
4154
4397
  current: dimension.current,
4155
4398
  dimension: {
4156
4399
  height,
@@ -4158,13 +4401,13 @@ function useResize({ refElement, onResize }) {
4158
4401
  }
4159
4402
  });
4160
4403
  dimension.current = { height, width };
4161
- }, []);
4404
+ });
4162
4405
  useEffect(() => {
4163
4406
  dimension.current = {
4164
4407
  height: refElement.current.offsetHeight,
4165
4408
  width: refElement.current.offsetWidth
4166
4409
  };
4167
- const resizeObserver = new ResizeObserver(observer);
4410
+ const resizeObserver = new ResizeObserver((entries) => observer(entries));
4168
4411
  resizeObserver.observe(refElement.current);
4169
4412
  return () => {
4170
4413
  resizeObserver.disconnect();
@@ -4829,5 +5072,5 @@ function toggleAppTheme() {
4829
5072
  return theme;
4830
5073
  }
4831
5074
 
4832
- 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, RlsHoverSwap, 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 };
5075
+ 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, RlsHoverSwap, 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 };
4833
5076
  //# sourceMappingURL=index.mjs.map